refactor(core): move clipboard text helpers into text/ domain

- Move clipboard-text-outlines.ts → text/opentype.ts
- Move kiwi/serialize-clipboard-v4.ts → text/clipboard-derived-text.ts
- Delete types-opentype.d.ts in favor of @types/opentype.js
- Add opentype.js to core package dependencies
- Add Vite alias for opentype.js ESM resolution
- Update all imports across core, kiwi, clipboard, and tests
This commit is contained in:
Danila Poyarkov 2026-04-08 20:45:43 +03:00
parent a20d170956
commit 92efd70c62
9 changed files with 17 additions and 39 deletions

View file

@ -88,7 +88,7 @@
},
"packages/cli": {
"name": "@open-pencil/cli",
"version": "0.10.0",
"version": "0.11.3",
"bin": {
"openpencil": "./src/index.ts",
},
@ -104,7 +104,7 @@
},
"packages/core": {
"name": "@open-pencil/core",
"version": "0.10.0",
"version": "0.11.3",
"dependencies": {
"@iconify/utils": "^3.1.0",
"canvaskit-wasm": "^0.40.0",
@ -115,6 +115,7 @@
"fontoxpath": "^3.34.0",
"fzstd": "^0.1.1",
"nanoevents": "^9.1.0",
"opentype.js": "^1.3.4",
"sucrase": "^3.35.1",
"svgpath": "^2.6.0",
"yoga-layout": "npm:@open-pencil/yoga-layout@3.3.0-grid.2",
@ -122,6 +123,7 @@
"devDependencies": {
"@types/culori": "^4.0.1",
"@types/diff": "^8.0.0",
"@types/opentype.js": "^1.3.9",
"typescript": "~5.8.3",
},
},
@ -137,7 +139,7 @@
},
"packages/mcp": {
"name": "@open-pencil/mcp",
"version": "0.8.0",
"version": "0.11.3",
"bin": {
"openpencil-mcp": "./dist/index.js",
},
@ -156,7 +158,7 @@
},
"packages/vue": {
"name": "@open-pencil/vue",
"version": "0.10.0",
"version": "0.11.3",
"dependencies": {
"@nanostores/i18n": "^1.2.2",
"@nanostores/vue": "^1.1.0",

View file

@ -300,6 +300,7 @@
"fontoxpath": "^3.34.0",
"fzstd": "^0.1.1",
"nanoevents": "^9.1.0",
"opentype.js": "^1.3.4",
"sucrase": "^3.35.1",
"svgpath": "^2.6.0",
"yoga-layout": "npm:@open-pencil/yoga-layout@3.3.0-grid.2"
@ -307,6 +308,7 @@
"devDependencies": {
"@types/culori": "^4.0.1",
"@types/diff": "^8.0.0",
"@types/opentype.js": "^1.3.9",
"typescript": "~5.8.3"
}
}

View file

@ -13,7 +13,7 @@ import {
makeCanvasNodeChange,
buildFontDigestMap
} from './kiwi/serialize'
import { buildDerivedTextDataV4 } from './kiwi/serialize-clipboard-v4'
import { buildDerivedTextDataV4 } from './text/clipboard-derived-text'
import { randomInt } from './random'
import type { NodeChange as KiwiNodeChange } from './kiwi/codec'

View file

@ -294,7 +294,7 @@ export {
fractionalPosition,
mapToFigmaType
} from './kiwi/serialize'
export { buildDerivedTextDataV4 } from './kiwi/serialize-clipboard-v4'
export { buildDerivedTextDataV4 } from './text/clipboard-derived-text'
export {
createElement,
@ -341,7 +341,7 @@ export {
type TextPictureBuilder,
type OpenPencilClipboardData
} from './clipboard'
export { probeGlyphOutlineCommands, type GlyphOutlineProbe } from './clipboard-text-outlines'
export { probeGlyphOutlineCommands, type GlyphOutlineProbe } from './text/opentype'
export { readPenFile, parsePenFile } from './io/formats/pen'

View file

@ -2,7 +2,7 @@ export const FIG_KIWI_DEFAULT_VERSION = 101
import { deflateSync, inflateSync } from 'fflate'
import { getGlyphOutlineCommandsSync } from '../clipboard-text-outlines'
import { getGlyphOutlineCommandsSync } from '../text/opentype'
import { getLoadedFontData, normalizeFontFamily, weightToStyle } from '../text/fonts'
import { encodeVectorNetworkBlob, buildStyleOverrideTable } from '../vector'
import { stringToGuid, VARIABLE_BINDING_FIELDS } from './convert'

View file

@ -1,8 +1,8 @@
import { getGlyphOutlineCommandsSync } from '../clipboard-text-outlines'
import { normalizeFontFamily, weightToStyle } from '../text/fonts'
import { normalizeFontFamily, weightToStyle } from './fonts'
import { getGlyphOutlineCommandsSync } from './opentype'
import type { SceneNode } from '../scene-graph'
import type { NodeChange } from './codec'
import type { NodeChange } from '../kiwi/codec'
export interface ShapedClipboardText {
lineHeight: number

View file

@ -1,6 +1,6 @@
import * as OpenTypeSync from 'opentype.js'
import { getLoadedFontData } from './text/fonts'
import { getLoadedFontData } from './fonts'
interface OutlineCommand {
type: string

View file

@ -1,27 +0,0 @@
declare module 'opentype.js' {
export interface OpenTypePathCommand {
type: string
x?: number
y?: number
x1?: number
y1?: number
x2?: number
y2?: number
}
export interface OpenTypeGlyphPath {
commands: OpenTypePathCommand[]
}
export interface OpenTypeGlyph {
path: OpenTypeGlyphPath
getPath(x: number, y: number, fontSize: number): OpenTypeGlyphPath
}
export interface OpenTypeFont {
unitsPerEm: number
stringToGlyphs(text: string): OpenTypeGlyph[]
}
export function parse(buffer: ArrayBuffer): OpenTypeFont
}

View file

@ -24,6 +24,7 @@ export default defineConfig(async ({ command }) => ({
'@': resolve(__dirname, 'src'),
'@open-pencil/vue': resolve(__dirname, 'packages/vue/src'),
'@open-pencil/core': resolve(__dirname, 'packages/core/src'),
'opentype.js': resolve(__dirname, 'node_modules/opentype.js/dist/opentype.module.js'),
// vue-stream-markdown eagerly loads mermaid/beautiful-mermaid as optional peer deps.
// Alias to empty shims to avoid runtime errors and reduce bundle size.
mermaid: resolve(__dirname, 'src/shims/mermaid.ts'),