@pairdraw/scene-graph 0.19.2 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/index.d.ts +28 -7
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +40 -15
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +19 -6
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +56 -1
- package/dist/color/management.js.map +1 -1
- package/dist/color/profile.d.ts +32 -0
- package/dist/color/profile.d.ts.map +1 -0
- package/dist/color/profile.js +140 -0
- package/dist/color/profile.js.map +1 -0
- package/dist/comments/index.d.ts +2 -2
- package/dist/comments/index.js +2 -2
- package/dist/comments/merge.d.ts.map +1 -1
- package/dist/comments/merge.js +1 -0
- package/dist/comments/merge.js.map +1 -1
- package/dist/comments/schema.d.ts +3 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +19 -2
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +3 -1
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +2 -1
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +7 -7
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +12 -1
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +30 -1
- package/dist/components/variants.js.map +1 -1
- package/dist/constants.d.ts +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +94 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/shadows.d.ts +2 -2
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +4 -4
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/text.d.ts +17 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +62 -1
- package/dist/css/text.js.map +1 -1
- package/dist/css/values.d.ts +7 -2
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +8 -4
- package/dist/css/values.js.map +1 -1
- package/dist/design-memory/index.d.ts +3 -0
- package/dist/design-memory/index.js +3 -0
- package/dist/design-memory/model.d.ts +33 -0
- package/dist/design-memory/model.d.ts.map +1 -0
- package/dist/design-memory/model.js +142 -0
- package/dist/design-memory/model.js.map +1 -0
- package/dist/design-memory/schema.d.ts +76 -0
- package/dist/design-memory/schema.d.ts.map +1 -0
- package/dist/design-memory/schema.js +72 -0
- package/dist/design-memory/schema.js.map +1 -0
- package/dist/effects.d.ts +7 -4
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +9 -4
- package/dist/effects.js.map +1 -1
- package/dist/empty-values.js +102 -0
- package/dist/empty-values.js.map +1 -0
- package/dist/fields/components.d.ts +9 -0
- package/dist/fields/components.d.ts.map +1 -0
- package/dist/fields/components.js +24 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/index.d.ts +3 -2
- package/dist/fields/index.js +3 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +10 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/graph.d.ts +12 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +39 -7
- package/dist/graph.js.map +1 -1
- package/dist/grid-values.d.ts +10 -0
- package/dist/grid-values.d.ts.map +1 -0
- package/dist/grid-values.js +53 -0
- package/dist/grid-values.js.map +1 -0
- package/dist/hit-test/drop.d.ts +20 -0
- package/dist/hit-test/drop.d.ts.map +1 -0
- package/dist/hit-test/drop.js +54 -0
- package/dist/hit-test/drop.js.map +1 -0
- package/dist/hit-test/geometry.js +86 -0
- package/dist/hit-test/geometry.js.map +1 -0
- package/dist/hit-test/masks.d.ts +14 -0
- package/dist/hit-test/masks.d.ts.map +1 -0
- package/dist/hit-test/masks.js +41 -0
- package/dist/hit-test/masks.js.map +1 -0
- package/dist/hit-test/paint.d.ts +6 -0
- package/dist/hit-test/paint.d.ts.map +1 -0
- package/dist/hit-test/paint.js +19 -0
- package/dist/hit-test/paint.js.map +1 -0
- package/dist/hit-test.d.ts +4 -15
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +5 -173
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +3 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +18 -2
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/copies.js +2 -1
- package/dist/instances/copies.js.map +1 -1
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +2 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +13 -12
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +15 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +37 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/source-walk.d.ts +12 -0
- package/dist/instances/source-walk.d.ts.map +1 -0
- package/dist/instances/swap-overrides.js +3 -3
- package/dist/instances/swap-overrides.js.map +1 -1
- package/dist/instances/sync.js +9 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +43 -38
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +90 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +33 -24
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/plugin-data/index.d.ts +2 -2
- package/dist/plugin-data/index.js +2 -2
- package/dist/plugin-data/schema.d.ts +6 -1
- package/dist/plugin-data/schema.d.ts.map +1 -1
- package/dist/plugin-data/schema.js +24 -1
- package/dist/plugin-data/schema.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/animation.d.ts +21 -0
- package/dist/shaders/animation.d.ts.map +1 -0
- package/dist/shaders/animation.js +25 -0
- package/dist/shaders/animation.js.map +1 -0
- package/dist/shaders/index.d.ts +2 -1
- package/dist/shaders/index.js +2 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -4
- package/dist/slots/content.js.map +1 -1
- package/dist/statuses/index.d.ts +2 -2
- package/dist/statuses/index.js +2 -2
- package/dist/statuses/workflow.d.ts +3 -1
- package/dist/statuses/workflow.d.ts.map +1 -1
- package/dist/statuses/workflow.js +6 -2
- package/dist/statuses/workflow.js.map +1 -1
- package/dist/token-sources/document.d.ts +26 -0
- package/dist/token-sources/document.d.ts.map +1 -0
- package/dist/token-sources/document.js +80 -0
- package/dist/token-sources/document.js.map +1 -0
- package/dist/token-sources/index.d.ts +3 -0
- package/dist/token-sources/index.js +3 -0
- package/dist/token-sources/schema.d.ts +43 -0
- package/dist/token-sources/schema.d.ts.map +1 -0
- package/dist/token-sources/schema.js +50 -0
- package/dist/token-sources/schema.js.map +1 -0
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +1 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +135 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +6 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +24 -16
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +12 -6
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/index.d.ts +14 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +38 -10
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +9 -8
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +35 -26
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolver.d.ts +45 -0
- package/dist/variables/resolver.d.ts.map +1 -0
- package/dist/variables/resolver.js +106 -0
- package/dist/variables/resolver.js.map +1 -0
- package/dist/variations/copy.d.ts +16 -0
- package/dist/variations/copy.d.ts.map +1 -0
- package/dist/variations/copy.js +78 -0
- package/dist/variations/copy.js.map +1 -0
- package/dist/variations/index.d.ts +6 -0
- package/dist/variations/index.js +6 -0
- package/dist/variations/match.d.ts +23 -0
- package/dist/variations/match.d.ts.map +1 -0
- package/dist/variations/match.js +80 -0
- package/dist/variations/match.js.map +1 -0
- package/dist/variations/model.d.ts +39 -0
- package/dist/variations/model.d.ts.map +1 -0
- package/dist/variations/model.js +90 -0
- package/dist/variations/model.js.map +1 -0
- package/dist/variations/pick.d.ts +43 -0
- package/dist/variations/pick.d.ts.map +1 -0
- package/dist/variations/pick.js +211 -0
- package/dist/variations/pick.js.map +1 -0
- package/dist/variations/schema.d.ts +27 -0
- package/dist/variations/schema.d.ts.map +1 -0
- package/dist/variations/schema.js +27 -0
- package/dist/variations/schema.js.map +1 -0
- package/package.json +21 -1
- package/src/color/index.ts +43 -9
- package/src/color/management.ts +54 -1
- package/src/color/profile.ts +131 -0
- package/src/comments/merge.ts +3 -0
- package/src/comments/schema.ts +32 -2
- package/src/comments/threads.ts +5 -2
- package/src/components/properties.ts +13 -7
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +7 -1
- package/src/css/shadows.ts +8 -5
- package/src/css/text.ts +62 -0
- package/src/css/values.ts +12 -5
- package/src/design-memory/index.ts +2 -0
- package/src/design-memory/model.ts +143 -0
- package/src/design-memory/schema.ts +84 -0
- package/src/effects.ts +16 -7
- package/src/empty-values.ts +117 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/graph.ts +50 -6
- package/src/grid-values.ts +47 -0
- package/src/hit-test/drop.ts +90 -0
- package/src/hit-test/geometry.ts +131 -0
- package/src/hit-test/masks.ts +57 -0
- package/src/hit-test/paint.ts +24 -0
- package/src/hit-test.ts +8 -277
- package/src/images.ts +27 -3
- package/src/instances/copies.ts +2 -1
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +20 -11
- package/src/instances/overrides.ts +49 -0
- package/src/instances/swap-overrides.ts +3 -2
- package/src/instances/sync.ts +11 -7
- package/src/node-defaults.ts +51 -41
- package/src/plugin-data/fields.ts +34 -32
- package/src/plugin-data/index.ts +1 -0
- package/src/plugin-data/schema.ts +30 -0
- package/src/preview.ts +2 -0
- package/src/scaling/node.ts +7 -2
- package/src/shaders/animation.ts +39 -0
- package/src/shaders/index.ts +1 -0
- package/src/slots/content.ts +8 -4
- package/src/statuses/workflow.ts +6 -4
- package/src/token-sources/document.ts +104 -0
- package/src/token-sources/index.ts +2 -0
- package/src/token-sources/schema.ts +59 -0
- package/src/transfer/variables.ts +2 -1
- package/src/types.ts +145 -14
- package/src/variables/bindings.ts +35 -18
- package/src/variables/formula/index.ts +19 -18
- package/src/variables/index.ts +49 -10
- package/src/variables/paints.ts +64 -29
- package/src/variables/resolver.ts +178 -0
- package/src/variations/copy.ts +89 -0
- package/src/variations/index.ts +5 -0
- package/src/variations/match.ts +100 -0
- package/src/variations/model.ts +132 -0
- package/src/variations/pick.ts +293 -0
- package/src/variations/schema.ts +29 -0
package/dist/copy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.js","names":[],"sources":["../src/copy.ts"],"sourcesContent":["/**\n * Typed shallow-copy helpers for Fill, Stroke, Effect, and StyleRun.\n *\n * These replace `structuredClone` for known scene-graph array types,\n * avoiding the ~24× overhead of the generic deep-clone algorithm.\n * Each helper spreads the top-level object and any nested objects\n * (color, offset, gradientStops, dashPattern, style) to ensure\n * no shared references between source and copy.\n */\n\nimport { normalizeEffects } from './effects'\nimport { geometryCommandCoordCount } from './geometry'\nimport { cloneInstanceOverrideState } from './instances/overrides'\nimport { createDefaultSourceMetadata } from './node-defaults'\nimport type {\n ArcData,\n ComponentPropertyDefinition,\n ConnectorEndpoint,\n Effect,\n DerivedTextGlyph,\n Fill,\n GeometryPath,\n GradientStop,\n LayoutGrid,\n SceneNode,\n Stroke,\n StyleRun\n} from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n// --- Individual copy functions ---\n\n/** Generic over the paint shape so a stroke keeps its own fields while the paint deep-copies. */\nexport function copyFill<T extends Fill>(f: T): T {\n const copy: T = { ...f, color: { ...f.color } }\n if (f.gradientStops) copy.gradientStops = f.gradientStops.map(copyGradientStop)\n if (f.gradientTransform) copy.gradientTransform = { ...f.gradientTransform }\n if (f.meshPoints) {\n copy.meshPoints = f.meshPoints.map((point) => ({\n position: { ...point.position },\n color: { ...point.color }\n }))\n }\n if (f.patternSpacing) copy.patternSpacing = { ...f.patternSpacing }\n if (f.filters) copy.filters = { ...f.filters }\n if (f.noiseSize) copy.noiseSize = { ...f.noiseSize }\n return copy\n}\n\nexport function copyStroke(s: Stroke): Stroke {\n const copy = copyFill(s)\n if (s.dashPattern) {\n copy.dashPattern = [...s.dashPattern]\n }\n return copy\n}\n\nexport function copyEffect(e: Effect): Effect {\n if (e.type === 'SHADER') return structuredClone(e)\n const normalized = normalizeEffects([e])[0] ?? e\n if (normalized.type === 'SHADER') return structuredClone(normalized)\n return {\n ...normalized,\n color: { ...normalized.color },\n offset: { ...normalized.offset }\n }\n}\n\nexport function copyStyleRun(r: StyleRun): StyleRun {\n const copy: StyleRun = {\n ...r,\n style: {\n ...r.style,\n fills: r.style.fills ? r.style.fills.map(copyFill) : undefined,\n textDecorationFills: r.style.textDecorationFills\n ? r.style.textDecorationFills.map(copyFill)\n : undefined,\n fontVariations: r.style.fontVariations\n ? r.style.fontVariations.map((v) => ({ ...v }))\n : undefined,\n fontFeatures: r.style.fontFeatures ? r.style.fontFeatures.map((v) => ({ ...v })) : undefined\n }\n }\n if (r.style.hyperlink) copy.style.hyperlink = { ...r.style.hyperlink }\n if (r.style.lineHeight) copy.style.lineHeight = { ...r.style.lineHeight }\n if (r.style.letterSpacing) copy.style.letterSpacing = { ...r.style.letterSpacing }\n if (r.style.boundVariables) copy.style.boundVariables = { ...r.style.boundVariables }\n if (r.style.variableBindingScales)\n copy.style.variableBindingScales = { ...r.style.variableBindingScales }\n return copy\n}\n\n// --- Array copy functions ---\n\nconst internalCopySources = new WeakMap<object, object>()\n\n/** Record immutable lineage for an internal deep copy without sharing mutable values. */\nexport function markCopySource<T extends object>(source: T, copy: T): T {\n internalCopySources.set(copy, internalCopySources.get(source) ?? source)\n return copy\n}\n\n/** Compare internal deep copies in O(1) without traversing large paint or text payloads. */\nexport function hasSameCopySource(left: object, right: object): boolean {\n if (left === right) return true\n return (internalCopySources.get(left) ?? left) === (internalCopySources.get(right) ?? right)\n}\n\nexport function copyFills(fills: Fill[]): Fill[] {\n return fills.map(copyFill)\n}\n\nexport function copyStrokes(strokes: Stroke[]): Stroke[] {\n return strokes.map(copyStroke)\n}\n\nexport function copyEffects(effects: Effect[]): Effect[] {\n return effects.map(copyEffect)\n}\n\nexport function copyLayoutGrids(grids: LayoutGrid[]): LayoutGrid[] {\n return grids.map((grid) => ({ ...grid, color: grid.color ? { ...grid.color } : undefined }))\n}\n\nexport function copyStyleRuns(runs: StyleRun[]): StyleRun[] {\n return runs.map(copyStyleRun)\n}\n\n/** Keep path-level fills across copy/scale/transform (resize snapshots). */\nfunction withPathPaintMeta(path: GeometryPath, commandsBlob: Uint8Array): GeometryPath {\n return {\n windingRule: path.windingRule,\n commandsBlob,\n ...(path.fills ? { fills: copyFills(path.fills) } : {})\n }\n}\n\nexport function copyGeometryPaths(paths: GeometryPath[]): GeometryPath[] {\n return paths.map((p) => withPathPaintMeta(p, p.commandsBlob.slice()))\n}\n\n/**\n * Affine-transform every coordinate pair in a path command blob (returns a\n * copy): (x, y) → (m00·x + m01·y + tx, m10·x + m11·y + ty).\n * Command layout: 1=move/2=line (1 pair), 3=quad (2 pairs), 4=cubic (3 pairs)\n * — font-glyph blobs are quad-heavy, so skipping command 3 desyncs the walk.\n */\nexport function transformGeometryBlob(\n blob: Uint8Array,\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): Uint8Array {\n const out = blob.slice()\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength)\n let offset = 0\n while (offset < out.length) {\n const command = out[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > out.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n dv.setFloat32(offset, m00 * x + m01 * y + tx, true)\n dv.setFloat32(offset + 4, m10 * x + m11 * y + ty, true)\n offset += 8\n }\n }\n return out\n}\n\nexport function transformGeometryPaths(\n paths: GeometryPath[],\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): GeometryPath[] {\n return paths.map((g) =>\n withPathPaintMeta(g, transformGeometryBlob(g.commandsBlob, m00, m01, m10, m11, tx, ty))\n )\n}\n\n/**\n * Scale path command blob coordinates by (sx, sy).\n * Identity scale returns a deep copy (same as copyGeometryPaths).\n */\nexport function scaleGeometryPaths(paths: GeometryPath[], sx: number, sy: number): GeometryPath[] {\n if (sx === 1 && sy === 1) return copyGeometryPaths(paths)\n return transformGeometryPaths(paths, sx, 0, 0, sy)\n}\n\n// --- Internal helpers ---\n\n/** Copy an optional array: non-empty → mapped, empty → [], undefined → undefined. */\nfunction copyOpt<T, U>(arr: T[] | undefined, fn: (arr: T[]) => U[]): U[] | undefined {\n if (arr === undefined) return undefined\n return arr.length > 0 ? fn(arr) : []\n}\n\nfunction copyGradientStop(gs: GradientStop): GradientStop {\n return { color: { ...gs.color }, position: gs.position }\n}\n\nfunction copySpread<T extends object>(arr: T[] | undefined): T[] {\n return arr?.map((item) => ({ ...item })) ?? []\n}\n\nfunction copyPropertyDefs(\n defs: ComponentPropertyDefinition[] | undefined\n): ComponentPropertyDefinition[] {\n return (\n defs?.map((d) => ({\n ...d,\n variantOptions: d.variantOptions ? [...d.variantOptions] : undefined,\n preferredValues: d.preferredValues ? [...d.preferredValues] : undefined,\n slotSettings: d.slotSettings ? { ...d.slotSettings } : undefined\n })) ?? []\n )\n}\n\n/** Deep-copy path-text glyphs (fresh commandsBlob buffers). */\nexport function copyDerivedGlyphs(glyphs: DerivedTextGlyph[] | null): DerivedTextGlyph[] | null {\n return glyphs\n ? glyphs.map((g) => ({\n ...g,\n commandsBlob: new Uint8Array(g.commandsBlob),\n ...(g.emojiCodePoints ? { emojiCodePoints: [...g.emojiCodePoints] } : {})\n }))\n : null\n}\n\n// --- Complex structure copy functions ---\n// These replace structuredClone for known types, avoiding its ~24× overhead.\n\nexport function copyConnectorEndpoint(endpoint: ConnectorEndpoint): ConnectorEndpoint {\n return { ...endpoint, position: { ...endpoint.position } }\n}\n\nfunction copyArcData(a: ArcData): ArcData {\n return { startingAngle: a.startingAngle, endingAngle: a.endingAngle, innerRadius: a.innerRadius }\n}\n\n// --- Deep-copy clone props ---\n\n/**\n * Build the init props for a deep-copy clone of `src`.\n * Shares logic between SceneGraph.cloneTree and instance child cloning.\n * Explicitly deep-copies all mutable object/array fields that `...rest`\n * would otherwise share by reference. When adding a mutable SceneNode field,\n * add its copy behavior here or document why sharing is intentional.\n */\nexport type NodeCloneMode = 'deep' | 'fig-import'\n\n/** A text's line height and letter spacing, copied so a clone never shares them. */\nfunction copyTextLengths(src: SceneNode): Pick<SceneNode, 'lineHeight' | 'letterSpacing'> {\n return {\n lineHeight: src.lineHeight && { ...src.lineHeight },\n letterSpacing: { ...src.letterSpacing }\n }\n}\n\nexport function cloneNodeProps(\n src: SceneNode,\n componentId: string | null,\n mode: NodeCloneMode = 'deep'\n): Partial<SceneNode> {\n const { id: _, parentId: _p, childIds: _c, ...rest } = src\n if (mode === 'fig-import') {\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n source: createDefaultSourceMetadata(),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n\n componentPropertyValues: { ...src.componentPropertyValues }\n }\n }\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n fills: copyOpt(src.fills, (value) => markCopySource(value, copyFills(value))),\n\n strokes: copyOpt(src.strokes, (value) => markCopySource(value, copyStrokes(value))),\n effects: copyOpt(src.effects, (value) => markCopySource(value, copyEffects(value))),\n layoutGrids: copyOpt(src.layoutGrids, copyLayoutGrids),\n guides: copyOpt(src.guides, (guides) => guides.map((guide) => ({ ...guide }))),\n styleRuns: copyOpt(src.styleRuns, (value) => markCopySource(value, copyStyleRuns(value))),\n // Generated instance descendants have no independent Figma provenance. Retaining the source\n // component's opaque raw payload here duplicates megabytes of metadata per instance.\n source: componentId === null ? structuredClone(src.source) : createDefaultSourceMetadata(),\n dashPattern: copyOpt(src.dashPattern, (a) => [...a]),\n fontVariations: copyOpt(src.fontVariations, (a) => a.map((v) => ({ ...v }))),\n ...copyTextLengths(src),\n fontFeatures: copyOpt(src.fontFeatures, (a) => a.map((v) => ({ ...v }))),\n textParagraphs: copyOpt(src.textParagraphs, (a) => a.map((v) => ({ ...v }))),\n textDecorationFills: copyOpt(src.textDecorationFills, copyFills),\n fillGeometry: copyOpt(src.fillGeometry, copyGeometryPaths),\n strokeGeometry: copyOpt(src.strokeGeometry, copyGeometryPaths),\n gridTemplateColumns: copySpread(src.gridTemplateColumns),\n gridTemplateRows: copySpread(src.gridTemplateRows),\n componentPropertyDefinitions: copyPropertyDefs(src.componentPropertyDefinitions),\n componentPropertyReferences: copySpread(src.componentPropertyReferences),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n symbolLinks: copySpread(src.symbolLinks),\n variantPropSpecs: copySpread(src.variantPropSpecs),\n pluginData: copySpread(src.pluginData),\n pluginRelaunchData: copySpread(src.pluginRelaunchData),\n prototypeReactions: src.prototypeReactions.map((reaction) => structuredClone(reaction)),\n exportSettings: copySpread(src.exportSettings),\n // Generated instance descendants have no status of their own.\n status: componentId === null ? src.status : null,\n componentPropertyValues: { ...src.componentPropertyValues },\n derivedLayout: src.derivedLayout ? { ...src.derivedLayout } : null,\n arcData: src.arcData ? copyArcData(src.arcData) : null,\n vectorNetwork: src.vectorNetwork ? cloneVectorNetwork(src.vectorNetwork) : null,\n textPicture: src.textPicture ? new Uint8Array(src.textPicture) : null,\n derivedTextGlyphs: src.derivedTextGlyphs\n ? markCopySource(src.derivedTextGlyphs, copyDerivedGlyphs(src.derivedTextGlyphs) ?? [])\n : null,\n textPathData: src.textPathData ? structuredClone(src.textPathData) : null,\n textPathBox: src.textPathBox ? { ...src.textPathBox } : null,\n gridPosition: src.gridPosition ? { ...src.gridPosition } : null,\n targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null,\n connectorStart: src.connectorStart ? copyConnectorEndpoint(src.connectorStart) : null,\n connectorEnd: src.connectorEnd ? copyConnectorEndpoint(src.connectorEnd) : null,\n connectorControlPoints: structuredClone(src.connectorControlPoints),\n connectorCurveHandles: structuredClone(src.connectorCurveHandles),\n connectorLabelPosition: src.connectorLabelPosition ? { ...src.connectorLabelPosition } : null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiCA,SAAgB,SAAyB,GAAS;CAChD,MAAM,OAAU;EAA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AAa,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,IAAI;EACjE,mBAAmB,IAAI,oBACnB,eAAe,IAAI,mBAAmB,kBAAkB,IAAI,iBAAiB,KAAK,CAAC,CAAC,IACpF;EACJ,cAAc,IAAI,eAAe,gBAAgB,IAAI,YAAY,IAAI;EACrE,aAAa,IAAI,cAAc,EAAE,GAAG,IAAI,YAAY,IAAI;EACxD,cAAc,IAAI,eAAe,EAAE,GAAG,IAAI,aAAa,IAAI;EAC3D,mBAAmB,IAAI,oBAAoB,EAAE,GAAG,IAAI,kBAAkB,IAAI;EAC1E,gBAAgB,IAAI,iBAAiB,sBAAsB,IAAI,cAAc,IAAI;EACjF,cAAc,IAAI,eAAe,sBAAsB,IAAI,YAAY,IAAI;EAC3E,wBAAwB,gBAAgB,IAAI,sBAAsB;EAClE,uBAAuB,gBAAgB,IAAI,qBAAqB;EAChE,wBAAwB,IAAI,yBAAyB,EAAE,GAAG,IAAI,uBAAuB,IAAI;CAC3F;AACF"}
|
|
1
|
+
{"version":3,"file":"copy.js","names":[],"sources":["../src/copy.ts"],"sourcesContent":["/**\n * Typed shallow-copy helpers for Fill, Stroke, Effect, and StyleRun.\n *\n * These replace `structuredClone` for known scene-graph array types,\n * avoiding the ~24× overhead of the generic deep-clone algorithm.\n * Each helper spreads the top-level object and any nested objects\n * (color, offset, gradientStops, dashPattern, style) to ensure\n * no shared references between source and copy.\n */\n\nimport { normalizeEffects } from './effects'\nimport { geometryCommandCoordCount } from './geometry'\nimport { cloneInstanceOverrideState } from './instances/overrides'\nimport { createDefaultSourceMetadata } from './node-defaults'\nimport type {\n ArcData,\n ComponentPropertyDefinition,\n ConnectorEndpoint,\n Effect,\n DerivedTextGlyph,\n Fill,\n GeometryPath,\n GradientStop,\n LayoutGrid,\n SceneNode,\n Stroke,\n StyleRun\n} from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n// --- Individual copy functions ---\n\n/** Generic over the paint shape so a stroke keeps its own fields while the paint deep-copies. */\nexport function copyFill<T extends Fill>(f: T): T {\n const copy: T = { ...f, color: { ...f.color } }\n if (f.gradientStops) copy.gradientStops = f.gradientStops.map(copyGradientStop)\n if (f.gradientTransform) copy.gradientTransform = { ...f.gradientTransform }\n if (f.meshPoints) {\n copy.meshPoints = f.meshPoints.map((point) => ({\n position: { ...point.position },\n color: { ...point.color }\n }))\n }\n if (f.patternSpacing) copy.patternSpacing = { ...f.patternSpacing }\n if (f.filters) copy.filters = { ...f.filters }\n if (f.noiseSize) copy.noiseSize = { ...f.noiseSize }\n return copy\n}\n\nexport function copyStroke(s: Stroke): Stroke {\n const copy = copyFill(s)\n if (s.dashPattern) {\n copy.dashPattern = [...s.dashPattern]\n }\n return copy\n}\n\nexport function copyEffect(e: Effect): Effect {\n const normalized = normalizeEffects([e])[0] ?? e\n if (normalized.type === 'SHADER') return structuredClone(normalized)\n if (normalized.type === 'NOISE') {\n return {\n ...normalized,\n color: { ...normalized.color },\n noise: {\n ...normalized.noise,\n noiseSize: { ...normalized.noise.noiseSize },\n secondaryColor: normalized.noise.secondaryColor\n ? { ...normalized.noise.secondaryColor }\n : undefined\n }\n }\n }\n if (normalized.type === 'TEXTURE') {\n return {\n ...normalized,\n color: { ...normalized.color },\n texture: { ...normalized.texture, noiseSize: { ...normalized.texture.noiseSize } }\n }\n }\n return {\n ...normalized,\n color: { ...normalized.color },\n offset: { ...normalized.offset }\n }\n}\n\nexport function copyStyleRun(r: StyleRun): StyleRun {\n const copy: StyleRun = {\n ...r,\n style: {\n ...r.style,\n fills: r.style.fills ? r.style.fills.map(copyFill) : undefined,\n textDecorationFills: r.style.textDecorationFills\n ? r.style.textDecorationFills.map(copyFill)\n : undefined,\n fontVariations: r.style.fontVariations\n ? r.style.fontVariations.map((v) => ({ ...v }))\n : undefined,\n fontFeatures: r.style.fontFeatures ? r.style.fontFeatures.map((v) => ({ ...v })) : undefined\n }\n }\n if (r.style.hyperlink) copy.style.hyperlink = { ...r.style.hyperlink }\n if (r.style.lineHeight) copy.style.lineHeight = { ...r.style.lineHeight }\n if (r.style.letterSpacing) copy.style.letterSpacing = { ...r.style.letterSpacing }\n if (r.style.boundVariables) copy.style.boundVariables = { ...r.style.boundVariables }\n if (r.style.variableBindingScales)\n copy.style.variableBindingScales = { ...r.style.variableBindingScales }\n return copy\n}\n\n// --- Array copy functions ---\n\nconst internalCopySources = new WeakMap<object, object>()\n\n/** Record immutable lineage for an internal deep copy without sharing mutable values. */\nexport function markCopySource<T extends object>(source: T, copy: T): T {\n internalCopySources.set(copy, internalCopySources.get(source) ?? source)\n return copy\n}\n\n/** Compare internal deep copies in O(1) without traversing large paint or text payloads. */\nexport function hasSameCopySource(left: object, right: object): boolean {\n if (left === right) return true\n return (internalCopySources.get(left) ?? left) === (internalCopySources.get(right) ?? right)\n}\n\nexport function copyFills(fills: Fill[]): Fill[] {\n return fills.map(copyFill)\n}\n\nexport function copyStrokes(strokes: Stroke[]): Stroke[] {\n return strokes.map(copyStroke)\n}\n\nexport function copyEffects(effects: Effect[]): Effect[] {\n return effects.map(copyEffect)\n}\n\nexport function copyLayoutGrids(grids: LayoutGrid[]): LayoutGrid[] {\n return grids.map((grid) => ({ ...grid, color: grid.color ? { ...grid.color } : undefined }))\n}\n\nexport function copyStyleRuns(runs: StyleRun[]): StyleRun[] {\n return runs.map(copyStyleRun)\n}\n\n/** Keep path-level fills across copy/scale/transform (resize snapshots). */\nfunction withPathPaintMeta(path: GeometryPath, commandsBlob: Uint8Array): GeometryPath {\n return {\n windingRule: path.windingRule,\n commandsBlob,\n ...(path.fills ? { fills: copyFills(path.fills) } : {})\n }\n}\n\nexport function copyGeometryPaths(paths: GeometryPath[]): GeometryPath[] {\n return paths.map((p) => withPathPaintMeta(p, p.commandsBlob.slice()))\n}\n\n/**\n * Affine-transform every coordinate pair in a path command blob (returns a\n * copy): (x, y) → (m00·x + m01·y + tx, m10·x + m11·y + ty).\n * Command layout: 1=move/2=line (1 pair), 3=quad (2 pairs), 4=cubic (3 pairs)\n * — font-glyph blobs are quad-heavy, so skipping command 3 desyncs the walk.\n */\nexport function transformGeometryBlob(\n blob: Uint8Array,\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): Uint8Array {\n const out = blob.slice()\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength)\n let offset = 0\n while (offset < out.length) {\n const command = out[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > out.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n dv.setFloat32(offset, m00 * x + m01 * y + tx, true)\n dv.setFloat32(offset + 4, m10 * x + m11 * y + ty, true)\n offset += 8\n }\n }\n return out\n}\n\nexport function transformGeometryPaths(\n paths: GeometryPath[],\n m00: number,\n m01: number,\n m10: number,\n m11: number,\n tx = 0,\n ty = 0\n): GeometryPath[] {\n return paths.map((g) =>\n withPathPaintMeta(g, transformGeometryBlob(g.commandsBlob, m00, m01, m10, m11, tx, ty))\n )\n}\n\n/**\n * Scale path command blob coordinates by (sx, sy).\n * Identity scale returns a deep copy (same as copyGeometryPaths).\n */\nexport function scaleGeometryPaths(paths: GeometryPath[], sx: number, sy: number): GeometryPath[] {\n if (sx === 1 && sy === 1) return copyGeometryPaths(paths)\n return transformGeometryPaths(paths, sx, 0, 0, sy)\n}\n\n// --- Internal helpers ---\n\n/** Copy an optional array: non-empty → mapped, empty → [], undefined → undefined. */\nfunction copyOpt<T, U>(arr: T[] | undefined, fn: (arr: T[]) => U[]): U[] | undefined {\n if (arr === undefined) return undefined\n return arr.length > 0 ? fn(arr) : []\n}\n\nfunction copyGradientStop(gs: GradientStop): GradientStop {\n return { color: { ...gs.color }, position: gs.position }\n}\n\nfunction copySpread<T extends object>(arr: T[] | undefined): T[] {\n return arr?.map((item) => ({ ...item })) ?? []\n}\n\nfunction copyPropertyDefs(\n defs: ComponentPropertyDefinition[] | undefined\n): ComponentPropertyDefinition[] {\n return (\n defs?.map((d) => ({\n ...d,\n variantOptions: d.variantOptions ? [...d.variantOptions] : undefined,\n preferredValues: d.preferredValues ? [...d.preferredValues] : undefined,\n slotSettings: d.slotSettings ? { ...d.slotSettings } : undefined\n })) ?? []\n )\n}\n\n/** Deep-copy path-text glyphs (fresh commandsBlob buffers). */\nexport function copyDerivedGlyphs(glyphs: DerivedTextGlyph[] | null): DerivedTextGlyph[] | null {\n return glyphs\n ? glyphs.map((g) => ({\n ...g,\n commandsBlob: new Uint8Array(g.commandsBlob),\n ...(g.emojiCodePoints ? { emojiCodePoints: [...g.emojiCodePoints] } : {})\n }))\n : null\n}\n\n// --- Complex structure copy functions ---\n// These replace structuredClone for known types, avoiding its ~24× overhead.\n\nexport function copyConnectorEndpoint(endpoint: ConnectorEndpoint): ConnectorEndpoint {\n return { ...endpoint, position: { ...endpoint.position } }\n}\n\nfunction copyArcData(a: ArcData): ArcData {\n return { startingAngle: a.startingAngle, endingAngle: a.endingAngle, innerRadius: a.innerRadius }\n}\n\n// --- Deep-copy clone props ---\n\n/**\n * Build the init props for a deep-copy clone of `src`.\n * Shares logic between SceneGraph.cloneTree and instance child cloning.\n * Explicitly deep-copies all mutable object/array fields that `...rest`\n * would otherwise share by reference. When adding a mutable SceneNode field,\n * add its copy behavior here or document why sharing is intentional.\n */\nexport type NodeCloneMode = 'deep' | 'fig-import'\n\n/** A text's line height and letter spacing, copied so a clone never shares them. */\nfunction copyTextLengths(src: SceneNode): Pick<SceneNode, 'lineHeight' | 'letterSpacing'> {\n return {\n lineHeight: src.lineHeight && { ...src.lineHeight },\n letterSpacing: { ...src.letterSpacing }\n }\n}\n\nexport function cloneNodeProps(\n src: SceneNode,\n componentId: string | null,\n mode: NodeCloneMode = 'deep'\n): Partial<SceneNode> {\n const { id: _, parentId: _p, childIds: _c, ...rest } = src\n if (mode === 'fig-import') {\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n source: createDefaultSourceMetadata(),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n\n componentPropertyValues: { ...src.componentPropertyValues }\n }\n }\n return {\n ...rest,\n ...(componentId !== null ? { componentId } : {}),\n boundVariables: { ...src.boundVariables },\n variableBindingScales: { ...src.variableBindingScales },\n variableAssignmentScales: { ...src.variableAssignmentScales },\n variableModes: { ...src.variableModes },\n instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),\n fills: copyOpt(src.fills, (value) => markCopySource(value, copyFills(value))),\n\n strokes: copyOpt(src.strokes, (value) => markCopySource(value, copyStrokes(value))),\n effects: copyOpt(src.effects, (value) => markCopySource(value, copyEffects(value))),\n layoutGrids: copyOpt(src.layoutGrids, copyLayoutGrids),\n guides: copyOpt(src.guides, (guides) => guides.map((guide) => ({ ...guide }))),\n styleRuns: copyOpt(src.styleRuns, (value) => markCopySource(value, copyStyleRuns(value))),\n // Generated instance descendants have no independent Figma provenance. Retaining the source\n // component's opaque raw payload here duplicates megabytes of metadata per instance.\n source: componentId === null ? structuredClone(src.source) : createDefaultSourceMetadata(),\n dashPattern: copyOpt(src.dashPattern, (a) => [...a]),\n fontVariations: copyOpt(src.fontVariations, (a) => a.map((v) => ({ ...v }))),\n ...copyTextLengths(src),\n fontFeatures: copyOpt(src.fontFeatures, (a) => a.map((v) => ({ ...v }))),\n textParagraphs: copyOpt(src.textParagraphs, (a) => a.map((v) => ({ ...v }))),\n textDecorationFills: copyOpt(src.textDecorationFills, copyFills),\n fillGeometry: copyOpt(src.fillGeometry, copyGeometryPaths),\n strokeGeometry: copyOpt(src.strokeGeometry, copyGeometryPaths),\n gridTemplateColumns: copySpread(src.gridTemplateColumns),\n gridTemplateRows: copySpread(src.gridTemplateRows),\n componentPropertyDefinitions: copyPropertyDefs(src.componentPropertyDefinitions),\n componentPropertyReferences: copySpread(src.componentPropertyReferences),\n componentPropertyAssignments: { ...src.componentPropertyAssignments },\n symbolLinks: copySpread(src.symbolLinks),\n variantPropSpecs: copySpread(src.variantPropSpecs),\n pluginData: copySpread(src.pluginData),\n pluginRelaunchData: copySpread(src.pluginRelaunchData),\n prototypeReactions: src.prototypeReactions.map((reaction) => structuredClone(reaction)),\n exportSettings: copySpread(src.exportSettings),\n // Generated instance descendants have no status of their own.\n status: componentId === null ? src.status : null,\n componentPropertyValues: { ...src.componentPropertyValues },\n derivedLayout: src.derivedLayout ? { ...src.derivedLayout } : null,\n arcData: src.arcData ? copyArcData(src.arcData) : null,\n vectorNetwork: src.vectorNetwork ? cloneVectorNetwork(src.vectorNetwork) : null,\n textPicture: src.textPicture ? new Uint8Array(src.textPicture) : null,\n derivedTextGlyphs: src.derivedTextGlyphs\n ? markCopySource(src.derivedTextGlyphs, copyDerivedGlyphs(src.derivedTextGlyphs) ?? [])\n : null,\n textPathData: src.textPathData ? structuredClone(src.textPathData) : null,\n textPathBox: src.textPathBox ? { ...src.textPathBox } : null,\n gridPosition: src.gridPosition ? { ...src.gridPosition } : null,\n targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null,\n connectorStart: src.connectorStart ? copyConnectorEndpoint(src.connectorStart) : null,\n connectorEnd: src.connectorEnd ? copyConnectorEndpoint(src.connectorEnd) : null,\n connectorControlPoints: structuredClone(src.connectorControlPoints),\n connectorCurveHandles: structuredClone(src.connectorCurveHandles),\n connectorLabelPosition: src.connectorLabelPosition ? { ...src.connectorLabelPosition } : null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiCA,SAAgB,SAAyB,GAAS;CAChD,MAAM,OAAU;EAAE,GAAG;EAAG,OAAO,EAAE,GAAG,EAAE,MAAM;CAAE;CAC9C,IAAI,EAAE,eAAe,KAAK,gBAAgB,EAAE,cAAc,IAAI,gBAAgB;CAC9E,IAAI,EAAE,mBAAmB,KAAK,oBAAoB,EAAE,GAAG,EAAE,kBAAkB;CAC3E,I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1D,eAAe,IAAI,gBAAgB,EAAE,GAAG,IAAI,cAAc,IAAI;EAC9D,SAAS,IAAI,UAAU,YAAY,IAAI,OAAO,IAAI;EAClD,eAAe,IAAI,gBAAgB,mBAAmB,IAAI,aAAa,IAAI;EAC3E,aAAa,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,IAAI;EACjE,mBAAmB,IAAI,oBACnB,eAAe,IAAI,mBAAmB,kBAAkB,IAAI,iBAAiB,KAAK,CAAC,CAAC,IACpF;EACJ,cAAc,IAAI,eAAe,gBAAgB,IAAI,YAAY,IAAI;EACrE,aAAa,IAAI,cAAc,EAAE,GAAG,IAAI,YAAY,IAAI;EACxD,cAAc,IAAI,eAAe,EAAE,GAAG,IAAI,aAAa,IAAI;EAC3D,mBAAmB,IAAI,oBAAoB,EAAE,GAAG,IAAI,kBAAkB,IAAI;EAC1E,gBAAgB,IAAI,iBAAiB,sBAAsB,IAAI,cAAc,IAAI;EACjF,cAAc,IAAI,eAAe,sBAAsB,IAAI,YAAY,IAAI;EAC3E,wBAAwB,gBAAgB,IAAI,sBAAsB;EAClE,uBAAuB,gBAAgB,IAAI,qBAAqB;EAChE,wBAAwB,IAAI,yBAAyB,EAAE,GAAG,IAAI,uBAAuB,IAAI;CAC3F;AACF"}
|
package/dist/css/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { parseCSSGridTracks } from "./grid.js";
|
|
|
2
2
|
import { CSSBackgroundLayer, parseCSSBackgroundImages } from "./gradient.js";
|
|
3
3
|
import { parseCSSAlignItems, parseCSSAlignSelf, parseCSSFlexDirection, parseCSSJustifyContent } from "./layout.js";
|
|
4
4
|
import { parseCSSShadows } from "./shadows.js";
|
|
5
|
-
import { parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight } from "./text.js";
|
|
5
|
+
import { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, GenericFontClass, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight } from "./text.js";
|
|
6
6
|
import { parseCSSColor, parseCSSNumber, splitCSSValue } from "./values.js";
|
|
7
|
-
export { type CSSBackgroundLayer, parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSGridTracks, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows, splitCSSValue };
|
|
7
|
+
export { type CSSBackgroundLayer, GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, type GenericFontClass, genericFontFamilyClass, isGenericFontFamily, parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSGridTracks, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows, splitCSSValue };
|
package/dist/css/index.js
CHANGED
|
@@ -3,5 +3,5 @@ import { parseCSSGridTracks } from "./grid.js";
|
|
|
3
3
|
import { parseCSSBackgroundImages } from "./gradient.js";
|
|
4
4
|
import { parseCSSAlignItems, parseCSSAlignSelf, parseCSSFlexDirection, parseCSSJustifyContent } from "./layout.js";
|
|
5
5
|
import { parseCSSShadows } from "./shadows.js";
|
|
6
|
-
import { parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight } from "./text.js";
|
|
7
|
-
export { parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSGridTracks, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows, splitCSSValue };
|
|
6
|
+
import { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight } from "./text.js";
|
|
7
|
+
export { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, genericFontFamilyClass, isGenericFontFamily, parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSGridTracks, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows, splitCSSValue };
|
package/dist/css/shadows.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Effect } from "../types.js";
|
|
1
|
+
import { DocumentColorSpace, Effect } from "../types.js";
|
|
2
2
|
//#region src/css/shadows.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The shadows of a CSS `box-shadow` or `text-shadow` list, such as
|
|
5
5
|
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.
|
|
6
6
|
*/
|
|
7
|
-
declare function parseCSSShadows(value: string | undefined): Effect[];
|
|
7
|
+
declare function parseCSSShadows(value: string | undefined, profile?: DocumentColorSpace): Effect[];
|
|
8
8
|
//#endregion
|
|
9
9
|
export { parseCSSShadows };
|
|
10
10
|
//# sourceMappingURL=shadows.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.d.ts","names":[],"sources":["../../src/css/shadows.ts"],"mappings":";;;;;;iBAgDgB,
|
|
1
|
+
{"version":3,"file":"shadows.d.ts","names":[],"sources":["../../src/css/shadows.ts"],"mappings":";;;;;;iBAgDgB,gBACd,2BACA,UAAS,qBACR"}
|
package/dist/css/shadows.js
CHANGED
|
@@ -7,7 +7,7 @@ import valueParser from "postcss-value-parser";
|
|
|
7
7
|
* One layer: `inset`, two to four lengths, and a color in any order. Without a color it is
|
|
8
8
|
* black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.
|
|
9
9
|
*/
|
|
10
|
-
function shadowOf(nodes) {
|
|
10
|
+
function shadowOf(nodes, profile) {
|
|
11
11
|
let inset = false;
|
|
12
12
|
let color = null;
|
|
13
13
|
const lengths = [];
|
|
@@ -21,7 +21,7 @@ function shadowOf(nodes) {
|
|
|
21
21
|
lengths.push(length);
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
-
const parsed = tryParseColor(valueParser.stringify(node));
|
|
24
|
+
const parsed = tryParseColor(valueParser.stringify(node), profile);
|
|
25
25
|
if (!parsed || color) return [];
|
|
26
26
|
color = parsed;
|
|
27
27
|
}
|
|
@@ -43,9 +43,9 @@ function shadowOf(nodes) {
|
|
|
43
43
|
* The shadows of a CSS `box-shadow` or `text-shadow` list, such as
|
|
44
44
|
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.
|
|
45
45
|
*/
|
|
46
|
-
function parseCSSShadows(value) {
|
|
46
|
+
function parseCSSShadows(value, profile = "srgb") {
|
|
47
47
|
if (!value) return [];
|
|
48
|
-
return cssLayers(valueParser(value).nodes).flatMap(shadowOf);
|
|
48
|
+
return cssLayers(valueParser(value).nodes).flatMap((nodes) => shadowOf(nodes, profile));
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
51
|
export { parseCSSShadows };
|
package/dist/css/shadows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/css/shadows.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Effect } from '../types'\nimport { cssLayers, parseCSSNumber } from './values'\n\n/**\n * One layer: `inset`, two to four lengths, and a color in any order. Without a color it is\n * black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.\n */\nfunction shadowOf(nodes: Node[]): Effect[] {\n let inset = false\n let color: Color | null = null\n const lengths: number[] = []\n for (const node of nodes) {\n if (node.type === 'word' && node.value.toLowerCase() === 'inset') {\n inset = true\n continue\n }\n const length = node.type === 'word' ? parseCSSNumber(node.value) : null\n if (length !== null) {\n lengths.push(length)\n continue\n }\n const parsed = tryParseColor(valueParser.stringify(node))\n if (!parsed || color) return []\n color = parsed\n }\n if (lengths.length < 2 || lengths.length > 4 || color?.a === 0) return []\n const [x = 0, y = 0, radius = 0, spread = 0] = lengths\n return [\n {\n type: inset ? 'INNER_SHADOW' : 'DROP_SHADOW',\n color: color ?? { ...BLACK },\n offset: { x, y },\n radius,\n spread,\n visible: true\n }\n ]\n}\n\n/**\n * The shadows of a CSS `box-shadow` or `text-shadow` list, such as\n * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.\n */\nexport function parseCSSShadows(value: string | undefined): Effect[] {\n if (!value) return []\n return cssLayers(valueParser(value).nodes).flatMap(shadowOf)\n}\n"],"mappings":";;;;;;;;;AAYA,SAAS,SAAS,
|
|
1
|
+
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/css/shadows.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace, Effect } from '../types'\nimport { cssLayers, parseCSSNumber } from './values'\n\n/**\n * One layer: `inset`, two to four lengths, and a color in any order. Without a color it is\n * black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.\n */\nfunction shadowOf(nodes: Node[], profile: DocumentColorSpace): Effect[] {\n let inset = false\n let color: Color | null = null\n const lengths: number[] = []\n for (const node of nodes) {\n if (node.type === 'word' && node.value.toLowerCase() === 'inset') {\n inset = true\n continue\n }\n const length = node.type === 'word' ? parseCSSNumber(node.value) : null\n if (length !== null) {\n lengths.push(length)\n continue\n }\n const parsed = tryParseColor(valueParser.stringify(node), profile)\n if (!parsed || color) return []\n color = parsed\n }\n if (lengths.length < 2 || lengths.length > 4 || color?.a === 0) return []\n const [x = 0, y = 0, radius = 0, spread = 0] = lengths\n return [\n {\n type: inset ? 'INNER_SHADOW' : 'DROP_SHADOW',\n color: color ?? { ...BLACK },\n offset: { x, y },\n radius,\n spread,\n visible: true\n }\n ]\n}\n\n/**\n * The shadows of a CSS `box-shadow` or `text-shadow` list, such as\n * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.\n */\nexport function parseCSSShadows(\n value: string | undefined,\n profile: DocumentColorSpace = 'srgb'\n): Effect[] {\n if (!value) return []\n return cssLayers(valueParser(value).nodes).flatMap((nodes) => shadowOf(nodes, profile))\n}\n"],"mappings":";;;;;;;;;AAYA,SAAS,SAAS,OAAe,SAAuC;CACtE,IAAI,QAAQ;CACZ,IAAI,QAAsB;CAC1B,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,UAAU,KAAK,MAAM,YAAY,MAAM,SAAS;GAChE,QAAQ;GACR;EACF;EACA,MAAM,SAAS,KAAK,SAAS,SAAS,eAAe,KAAK,KAAK,IAAI;EACnE,IAAI,WAAW,MAAM;GACnB,QAAQ,KAAK,MAAM;GACnB;EACF;EACA,MAAM,SAAS,cAAc,YAAY,UAAU,IAAI,GAAG,OAAO;EACjE,IAAI,CAAC,UAAU,OAAO,OAAO,CAAC;EAC9B,QAAQ;CACV;CACA,IAAI,QAAQ,SAAS,KAAK,QAAQ,SAAS,KAAK,OAAO,MAAM,GAAG,OAAO,CAAC;CACxE,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,KAAK;CAC/C,OAAO,CACL;EACE,MAAM,QAAQ,iBAAiB;EAC/B,OAAO,SAAS,EAAE,GAAG,MAAM;EAC3B,QAAQ;GAAE;GAAG;EAAE;EACf;EACA;EACA,SAAS;CACX,CACF;AACF;;;;;AAMA,SAAgB,gBACd,OACA,UAA8B,QACpB;CACV,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,OAAO,UAAU,YAAY,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,SAAS,OAAO,OAAO,CAAC;AACxF"}
|
package/dist/css/text.d.ts
CHANGED
|
@@ -11,6 +11,22 @@ declare function parseCSSFontFamily(value: string | undefined): string | null;
|
|
|
11
11
|
* is one name; an unquoted one joins its words with single spaces.
|
|
12
12
|
*/
|
|
13
13
|
declare function parseCSSFontFamilies(value: string | undefined): string[];
|
|
14
|
+
/** CSS generic `font-family` keywords: names no font provider serves, drawn by a concrete face instead. */
|
|
15
|
+
declare const GENERIC_FONT_FAMILIES: ReadonlySet<string>;
|
|
16
|
+
/** Whether `family` is a CSS generic keyword rather than a face a provider or the host can load. */
|
|
17
|
+
declare function isGenericFontFamily(family: string): boolean;
|
|
18
|
+
/** The class a CSS generic keyword stands for, when a concrete face of it can draw the text. */
|
|
19
|
+
type GenericFontClass = 'sans-serif' | 'serif' | 'monospace';
|
|
20
|
+
/** CSS generic keywords, by the concrete face class they stand for. */
|
|
21
|
+
declare const GENERIC_FONT_FAMILY_CLASS: Readonly<Record<string, GenericFontClass>>;
|
|
22
|
+
/** Known system faces of each generic class, best first. The app bundles Inter for sans-serif. */
|
|
23
|
+
declare const GENERIC_FONT_FAMILIES_BY_CLASS: {
|
|
24
|
+
readonly 'sans-serif': readonly ["Inter"];
|
|
25
|
+
readonly serif: readonly ["Georgia", "Times New Roman", "Times", "DejaVu Serif", "Liberation Serif", "Noto Serif"];
|
|
26
|
+
readonly monospace: readonly ["Menlo", "SF Mono", "Consolas", "Courier New", "DejaVu Sans Mono", "Liberation Mono", "Noto Sans Mono", "Ubuntu Mono"];
|
|
27
|
+
};
|
|
28
|
+
/** The concrete face class `family` stands for, or null when its name is no CSS generic keyword. */
|
|
29
|
+
declare function genericFontFamilyClass(family: string): GenericFontClass | null;
|
|
14
30
|
/**
|
|
15
31
|
* A CSS `line-height` as a text length: a unitless multiple, `em`, or a percent follows the font size,
|
|
16
32
|
* as a percent does in Figma; pixels stay pixels; `normal` is automatic, a null. Undefined for a
|
|
@@ -23,5 +39,5 @@ declare function parseCSSLineHeight(value: string | undefined): TextLength | nul
|
|
|
23
39
|
*/
|
|
24
40
|
declare function parseCSSLetterSpacing(value: string | undefined): TextLength | undefined;
|
|
25
41
|
//#endregion
|
|
26
|
-
export { parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
42
|
+
export { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, GenericFontClass, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
27
43
|
//# sourceMappingURL=text.d.ts.map
|
package/dist/css/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","names":[],"sources":["../../src/css/text.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"text.d.ts","names":[],"sources":["../../src/css/text.ts"],"mappings":";;;;;;;iBAqCgB,mBAAmB;;;;;iBAenB,qBAAqB;;cAqBxB,uBAAuB;;iBAmBpB,oBAAoB;;KAKxB;;cAGC,2BAA2B,SAAS,eAAe;;cAanD;;;;;;iBAgBG,uBAAuB,iBAAiB;;;;;;iBAiBxC,mBAAmB,4BAA4B;;;;;iBAe/C,sBAAsB,4BAA4B"}
|
package/dist/css/text.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_FONT_FAMILY } from "../constants.js";
|
|
1
2
|
import { percentLength, pixelLength } from "../text/lengths.js";
|
|
2
3
|
import { parseCSSNumber } from "./values.js";
|
|
3
4
|
import valueParser from "postcss-value-parser";
|
|
@@ -51,6 +52,66 @@ function parseCSSFontFamilies(value) {
|
|
|
51
52
|
return parsed ? [parsed] : [];
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
/** CSS generic `font-family` keywords: names no font provider serves, drawn by a concrete face instead. */
|
|
56
|
+
const GENERIC_FONT_FAMILIES = /* @__PURE__ */ new Set([
|
|
57
|
+
"serif",
|
|
58
|
+
"sans-serif",
|
|
59
|
+
"monospace",
|
|
60
|
+
"cursive",
|
|
61
|
+
"fantasy",
|
|
62
|
+
"system-ui",
|
|
63
|
+
"ui-serif",
|
|
64
|
+
"ui-sans-serif",
|
|
65
|
+
"ui-monospace",
|
|
66
|
+
"ui-rounded",
|
|
67
|
+
"-apple-system",
|
|
68
|
+
"blinkmacsystemfont",
|
|
69
|
+
"math",
|
|
70
|
+
"emoji",
|
|
71
|
+
"fangsong"
|
|
72
|
+
]);
|
|
73
|
+
/** Whether `family` is a CSS generic keyword rather than a face a provider or the host can load. */
|
|
74
|
+
function isGenericFontFamily(family) {
|
|
75
|
+
return GENERIC_FONT_FAMILIES.has(family.trim().toLowerCase());
|
|
76
|
+
}
|
|
77
|
+
/** CSS generic keywords, by the concrete face class they stand for. */
|
|
78
|
+
const GENERIC_FONT_FAMILY_CLASS = {
|
|
79
|
+
"sans-serif": "sans-serif",
|
|
80
|
+
"ui-sans-serif": "sans-serif",
|
|
81
|
+
"system-ui": "sans-serif",
|
|
82
|
+
"-apple-system": "sans-serif",
|
|
83
|
+
blinkmacsystemfont: "sans-serif",
|
|
84
|
+
serif: "serif",
|
|
85
|
+
"ui-serif": "serif",
|
|
86
|
+
monospace: "monospace",
|
|
87
|
+
"ui-monospace": "monospace"
|
|
88
|
+
};
|
|
89
|
+
/** Known system faces of each generic class, best first. The app bundles Inter for sans-serif. */
|
|
90
|
+
const GENERIC_FONT_FAMILIES_BY_CLASS = {
|
|
91
|
+
"sans-serif": [DEFAULT_FONT_FAMILY],
|
|
92
|
+
serif: [
|
|
93
|
+
"Georgia",
|
|
94
|
+
"Times New Roman",
|
|
95
|
+
"Times",
|
|
96
|
+
"DejaVu Serif",
|
|
97
|
+
"Liberation Serif",
|
|
98
|
+
"Noto Serif"
|
|
99
|
+
],
|
|
100
|
+
monospace: [
|
|
101
|
+
"Menlo",
|
|
102
|
+
"SF Mono",
|
|
103
|
+
"Consolas",
|
|
104
|
+
"Courier New",
|
|
105
|
+
"DejaVu Sans Mono",
|
|
106
|
+
"Liberation Mono",
|
|
107
|
+
"Noto Sans Mono",
|
|
108
|
+
"Ubuntu Mono"
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
/** The concrete face class `family` stands for, or null when its name is no CSS generic keyword. */
|
|
112
|
+
function genericFontFamilyClass(family) {
|
|
113
|
+
return GENERIC_FONT_FAMILY_CLASS[family.trim().toLowerCase()] ?? null;
|
|
114
|
+
}
|
|
54
115
|
/** A CSS dimension's number and lowercase unit, or null. */
|
|
55
116
|
function dimension(value) {
|
|
56
117
|
const parsed = valueParser.unit(value);
|
|
@@ -90,6 +151,6 @@ function parseCSSLetterSpacing(value) {
|
|
|
90
151
|
return pixels === null ? void 0 : pixelLength(pixels);
|
|
91
152
|
}
|
|
92
153
|
//#endregion
|
|
93
|
-
export { parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
154
|
+
export { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
94
155
|
|
|
95
156
|
//# sourceMappingURL=text.js.map
|
package/dist/css/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":[],"sources":["../../src/css/text.ts"],"sourcesContent":["import valueParser from 'postcss-value-parser'\n\nimport { percentLength, pixelLength } from '../text/lengths'\nimport type { TextLength } from '../types'\nimport { parseCSSNumber } from './values'\n\n/** A CSS escape: hex digits and one optional whitespace, an escaped line break, or any one character. */\nconst CSS_ESCAPE = /\\\\(?:([0-9a-fA-F]{1,6})(?:\\r\\n|[ \\t\\n\\r\\f])?|(?:\\r\\n|[\\n\\r\\f])|([\\s\\S]))?/gu\n\n/** The largest Unicode code point. */\nconst MAX_CODE_POINT = 0x10ffff\n\n/** Text with its CSS escapes decoded; an escaped line break continues the line. */\nfunction decodeCSSEscapes(text: string): string {\n return text.replace(CSS_ESCAPE, (_escape, hex: string | undefined, char: string | undefined) => {\n if (hex === undefined) return char ?? ''\n const codePoint = Number.parseInt(hex, 16)\n const surrogate = codePoint >= 0xd800 && codePoint <= 0xdfff\n return codePoint === 0 || surrogate || codePoint > MAX_CODE_POINT\n ? '\\uFFFD'\n : String.fromCodePoint(codePoint)\n })\n}\n\n/** The index of the first unescaped `stop` character from `from`, or the text's length. */\nfunction unescapedIndexOf(text: string, stop: string, from: number): number {\n let index = from\n while (index < text.length && text[index] !== stop) index += text[index] === '\\\\' ? 2 : 1\n return index\n}\n\n/**\n * The first family of a CSS `font-family` list, without its quotes and escapes. A family is a quoted\n * string or unquoted words, which join with single spaces; a quote opens a string only at the start\n * of the family, so a name list such as draw.io's keeps `O'Reilly`. Null for an empty list.\n */\nexport function parseCSSFontFamily(value: string | undefined): string | null {\n const text = value?.trimStart()\n if (!text) return null\n const quote = text[0]\n if (quote === '\"' || quote === \"'\") {\n return decodeCSSEscapes(text.slice(1, unescapedIndexOf(text, quote, 1))) || null\n }\n const words = decodeCSSEscapes(text.slice(0, unescapedIndexOf(text, ',', 0)))\n return words.trim().replace(/\\s+/gu, ' ') || null\n}\n\n/**\n * Every family of a CSS `font-family` list, in order, without quotes and escapes. A quoted family\n * is one name; an unquoted one joins its words with single spaces.\n */\nexport function parseCSSFontFamilies(value: string | undefined): string[] {\n const text = value?.trim()\n if (!text) return []\n const families: string[] = []\n let current: valueParser.Node[] = []\n for (const node of valueParser(text).nodes) {\n if (node.type === 'div' && node.value === ',') {\n families.push(valueParser.stringify(current))\n current = []\n } else {\n current.push(node)\n }\n }\n families.push(valueParser.stringify(current))\n return families.flatMap((family) => {\n const parsed = parseCSSFontFamily(family)\n return parsed ? [parsed] : []\n })\n}\n\n/** A CSS dimension's number and lowercase unit, or null. */\nfunction dimension(value: string): { number: number; unit: string } | null {\n const parsed = valueParser.unit(value)\n if (!parsed) return null\n const number = Number(parsed.number)\n return Number.isFinite(number) ? { number, unit: parsed.unit.toLowerCase() } : null\n}\n\n/**\n * A CSS `line-height` as a text length: a unitless multiple, `em`, or a percent follows the font size,\n * as a percent does in Figma; pixels stay pixels; `normal` is automatic, a null. Undefined for a\n * value it cannot read.\n */\nexport function parseCSSLineHeight(value: string | undefined): TextLength | null | undefined {\n const trimmed = value?.trim()\n if (!trimmed) return undefined\n if (trimmed === 'normal') return null\n const parsed = dimension(trimmed)\n if (parsed?.unit === '' || parsed?.unit === 'em') return percentLength(parsed.number * 100)\n if (parsed?.unit === '%') return percentLength(parsed.number)\n const pixels = parseCSSNumber(trimmed)\n return pixels === null ? undefined : pixelLength(pixels)\n}\n\n/**\n * A CSS `letter-spacing` as a text length: `em` is a percent of the font size, pixels stay pixels,\n * and `normal` is none. Undefined for a value it cannot read.\n */\nexport function parseCSSLetterSpacing(value: string | undefined): TextLength | undefined {\n const trimmed = value?.trim()\n if (!trimmed) return undefined\n if (trimmed === 'normal') return pixelLength(0)\n const parsed = dimension(trimmed)\n if (parsed?.unit === 'em') return percentLength(parsed.number * 100)\n const pixels = parseCSSNumber(trimmed)\n return pixels === null ? undefined : pixelLength(pixels)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.js","names":[],"sources":["../../src/css/text.ts"],"sourcesContent":["import valueParser from 'postcss-value-parser'\n\nimport { DEFAULT_FONT_FAMILY } from '../constants'\nimport { percentLength, pixelLength } from '../text/lengths'\nimport type { TextLength } from '../types'\nimport { parseCSSNumber } from './values'\n\n/** A CSS escape: hex digits and one optional whitespace, an escaped line break, or any one character. */\nconst CSS_ESCAPE = /\\\\(?:([0-9a-fA-F]{1,6})(?:\\r\\n|[ \\t\\n\\r\\f])?|(?:\\r\\n|[\\n\\r\\f])|([\\s\\S]))?/gu\n\n/** The largest Unicode code point. */\nconst MAX_CODE_POINT = 0x10ffff\n\n/** Text with its CSS escapes decoded; an escaped line break continues the line. */\nfunction decodeCSSEscapes(text: string): string {\n return text.replace(CSS_ESCAPE, (_escape, hex: string | undefined, char: string | undefined) => {\n if (hex === undefined) return char ?? ''\n const codePoint = Number.parseInt(hex, 16)\n const surrogate = codePoint >= 0xd800 && codePoint <= 0xdfff\n return codePoint === 0 || surrogate || codePoint > MAX_CODE_POINT\n ? '\\uFFFD'\n : String.fromCodePoint(codePoint)\n })\n}\n\n/** The index of the first unescaped `stop` character from `from`, or the text's length. */\nfunction unescapedIndexOf(text: string, stop: string, from: number): number {\n let index = from\n while (index < text.length && text[index] !== stop) index += text[index] === '\\\\' ? 2 : 1\n return index\n}\n\n/**\n * The first family of a CSS `font-family` list, without its quotes and escapes. A family is a quoted\n * string or unquoted words, which join with single spaces; a quote opens a string only at the start\n * of the family, so a name list such as draw.io's keeps `O'Reilly`. Null for an empty list.\n */\nexport function parseCSSFontFamily(value: string | undefined): string | null {\n const text = value?.trimStart()\n if (!text) return null\n const quote = text[0]\n if (quote === '\"' || quote === \"'\") {\n return decodeCSSEscapes(text.slice(1, unescapedIndexOf(text, quote, 1))) || null\n }\n const words = decodeCSSEscapes(text.slice(0, unescapedIndexOf(text, ',', 0)))\n return words.trim().replace(/\\s+/gu, ' ') || null\n}\n\n/**\n * Every family of a CSS `font-family` list, in order, without quotes and escapes. A quoted family\n * is one name; an unquoted one joins its words with single spaces.\n */\nexport function parseCSSFontFamilies(value: string | undefined): string[] {\n const text = value?.trim()\n if (!text) return []\n const families: string[] = []\n let current: valueParser.Node[] = []\n for (const node of valueParser(text).nodes) {\n if (node.type === 'div' && node.value === ',') {\n families.push(valueParser.stringify(current))\n current = []\n } else {\n current.push(node)\n }\n }\n families.push(valueParser.stringify(current))\n return families.flatMap((family) => {\n const parsed = parseCSSFontFamily(family)\n return parsed ? [parsed] : []\n })\n}\n\n/** CSS generic `font-family` keywords: names no font provider serves, drawn by a concrete face instead. */\nexport const GENERIC_FONT_FAMILIES: ReadonlySet<string> = new Set([\n 'serif',\n 'sans-serif',\n 'monospace',\n 'cursive',\n 'fantasy',\n 'system-ui',\n 'ui-serif',\n 'ui-sans-serif',\n 'ui-monospace',\n 'ui-rounded',\n '-apple-system',\n 'blinkmacsystemfont',\n 'math',\n 'emoji',\n 'fangsong'\n])\n\n/** Whether `family` is a CSS generic keyword rather than a face a provider or the host can load. */\nexport function isGenericFontFamily(family: string): boolean {\n return GENERIC_FONT_FAMILIES.has(family.trim().toLowerCase())\n}\n\n/** The class a CSS generic keyword stands for, when a concrete face of it can draw the text. */\nexport type GenericFontClass = 'sans-serif' | 'serif' | 'monospace'\n\n/** CSS generic keywords, by the concrete face class they stand for. */\nexport const GENERIC_FONT_FAMILY_CLASS: Readonly<Record<string, GenericFontClass>> = {\n 'sans-serif': 'sans-serif',\n 'ui-sans-serif': 'sans-serif',\n 'system-ui': 'sans-serif',\n '-apple-system': 'sans-serif',\n blinkmacsystemfont: 'sans-serif',\n serif: 'serif',\n 'ui-serif': 'serif',\n monospace: 'monospace',\n 'ui-monospace': 'monospace'\n}\n\n/** Known system faces of each generic class, best first. The app bundles Inter for sans-serif. */\nexport const GENERIC_FONT_FAMILIES_BY_CLASS = {\n 'sans-serif': [DEFAULT_FONT_FAMILY],\n serif: ['Georgia', 'Times New Roman', 'Times', 'DejaVu Serif', 'Liberation Serif', 'Noto Serif'],\n monospace: [\n 'Menlo',\n 'SF Mono',\n 'Consolas',\n 'Courier New',\n 'DejaVu Sans Mono',\n 'Liberation Mono',\n 'Noto Sans Mono',\n 'Ubuntu Mono'\n ]\n} as const satisfies Record<GenericFontClass, readonly string[]>\n\n/** The concrete face class `family` stands for, or null when its name is no CSS generic keyword. */\nexport function genericFontFamilyClass(family: string): GenericFontClass | null {\n return GENERIC_FONT_FAMILY_CLASS[family.trim().toLowerCase()] ?? null\n}\n\n/** A CSS dimension's number and lowercase unit, or null. */\nfunction dimension(value: string): { number: number; unit: string } | null {\n const parsed = valueParser.unit(value)\n if (!parsed) return null\n const number = Number(parsed.number)\n return Number.isFinite(number) ? { number, unit: parsed.unit.toLowerCase() } : null\n}\n\n/**\n * A CSS `line-height` as a text length: a unitless multiple, `em`, or a percent follows the font size,\n * as a percent does in Figma; pixels stay pixels; `normal` is automatic, a null. Undefined for a\n * value it cannot read.\n */\nexport function parseCSSLineHeight(value: string | undefined): TextLength | null | undefined {\n const trimmed = value?.trim()\n if (!trimmed) return undefined\n if (trimmed === 'normal') return null\n const parsed = dimension(trimmed)\n if (parsed?.unit === '' || parsed?.unit === 'em') return percentLength(parsed.number * 100)\n if (parsed?.unit === '%') return percentLength(parsed.number)\n const pixels = parseCSSNumber(trimmed)\n return pixels === null ? undefined : pixelLength(pixels)\n}\n\n/**\n * A CSS `letter-spacing` as a text length: `em` is a percent of the font size, pixels stay pixels,\n * and `normal` is none. Undefined for a value it cannot read.\n */\nexport function parseCSSLetterSpacing(value: string | undefined): TextLength | undefined {\n const trimmed = value?.trim()\n if (!trimmed) return undefined\n if (trimmed === 'normal') return pixelLength(0)\n const parsed = dimension(trimmed)\n if (parsed?.unit === 'em') return percentLength(parsed.number * 100)\n const pixels = parseCSSNumber(trimmed)\n return pixels === null ? undefined : pixelLength(pixels)\n}\n"],"mappings":";;;;;;AAQA,MAAM,aAAa;;AAGnB,MAAM,iBAAiB;;AAGvB,SAAS,iBAAiB,MAAsB;CAC9C,OAAO,KAAK,QAAQ,aAAa,SAAS,KAAyB,SAA6B;EAC9F,IAAI,QAAQ,KAAA,GAAW,OAAO,QAAQ;EACtC,MAAM,YAAY,OAAO,SAAS,KAAK,EAAE;EAEzC,OAAO,cAAc,KADH,aAAa,SAAU,aAAa,SACf,YAAY,iBAC/C,MACA,OAAO,cAAc,SAAS;CACpC,C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AI,QAAQ,SAAS,MAAM,OAAO,cAAc,OAAO,SAAS,GAAG;CACnE,MAAM,SAAS,eAAe,OAAO;CACrC,OAAO,WAAW,OAAO,KAAA,IAAY,YAAY,MAAM;AACzD"}
|
package/dist/css/values.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Color } from "../primitives/index.js";
|
|
2
|
+
import { DocumentColorSpace } from "../types.js";
|
|
2
3
|
//#region src/css/values.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* A CSS number in pixels: unitless, `px`, or `rem`. Null for `auto`, for units that depend on
|
|
5
6
|
* what the value applies to (`%`, `em`, `vh`), and for anything that is not a number.
|
|
6
7
|
*/
|
|
7
8
|
declare function parseCSSNumber(value: string | undefined): number | null;
|
|
8
|
-
/**
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A CSS color that paints something, as components in `profile`; null for an invalid or fully
|
|
11
|
+
* transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller
|
|
12
|
+
* reading markup into a document passes the document's profile.
|
|
13
|
+
*/
|
|
14
|
+
declare function parseCSSColor(value: string | undefined, profile?: DocumentColorSpace): Color | null;
|
|
10
15
|
/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
|
|
11
16
|
declare function splitCSSValue(value: string): string[];
|
|
12
17
|
//#endregion
|
package/dist/css/values.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.d.ts","names":[],"sources":["../../src/css/values.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"values.d.ts","names":[],"sources":["../../src/css/values.ts"],"mappings":";;;;;;;iBAagB,eAAe;;;;;;iBAsBf,cACd,2BACA,UAAS,qBACR;;iBAOa,cAAc"}
|
package/dist/css/values.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tryParseColor } from "../color/index.js";
|
|
2
2
|
import valueParser from "postcss-value-parser";
|
|
3
3
|
//#region src/css/values.ts
|
|
4
4
|
/** Pixels in a rem, as browsers use by default. */
|
|
@@ -20,10 +20,14 @@ function parseCSSNumber(value) {
|
|
|
20
20
|
default: return null;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A CSS color that paints something, as components in `profile`; null for an invalid or fully
|
|
25
|
+
* transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller
|
|
26
|
+
* reading markup into a document passes the document's profile.
|
|
27
|
+
*/
|
|
28
|
+
function parseCSSColor(value, profile = "srgb") {
|
|
25
29
|
if (!value) return null;
|
|
26
|
-
const color =
|
|
30
|
+
const color = tryParseColor(value.trim(), profile);
|
|
27
31
|
return color && color.a > 0 ? color : null;
|
|
28
32
|
}
|
|
29
33
|
/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
|
package/dist/css/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","names":[],"sources":["../../src/css/values.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport {
|
|
1
|
+
{"version":3,"file":"values.js","names":[],"sources":["../../src/css/values.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace } from '../types'\n\n/** Pixels in a rem, as browsers use by default. */\nconst ROOT_FONT_SIZE = 16\n\n/**\n * A CSS number in pixels: unitless, `px`, or `rem`. Null for `auto`, for units that depend on\n * what the value applies to (`%`, `em`, `vh`), and for anything that is not a number.\n */\nexport function parseCSSNumber(value: string | undefined): number | null {\n if (!value) return null\n const dimension = valueParser.unit(value.trim())\n if (!dimension) return null\n const number = Number(dimension.number)\n if (!Number.isFinite(number)) return null\n switch (dimension.unit.toLowerCase()) {\n case '':\n case 'px':\n return number\n case 'rem':\n return number * ROOT_FONT_SIZE\n default:\n return null\n }\n}\n\n/**\n * A CSS color that paints something, as components in `profile`; null for an invalid or fully\n * transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller\n * reading markup into a document passes the document's profile.\n */\nexport function parseCSSColor(\n value: string | undefined,\n profile: DocumentColorSpace = 'srgb'\n): Color | null {\n if (!value) return null\n const color = tryParseColor(value.trim(), profile)\n return color && color.a > 0 ? color : null\n}\n\n/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */\nexport function splitCSSValue(value: string): string[] {\n return valueParser(value)\n .nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')\n .map((node) => valueParser.stringify(node))\n}\n\n/** The layers of a CSS value list, split at its top-level commas, spaces and comments dropped. */\nexport function cssLayers(nodes: Node[]): Node[][] {\n const layers: Node[][] = []\n let current: Node[] = []\n for (const node of nodes) {\n if (node.type === 'div' && node.value === ',') {\n layers.push(current)\n current = []\n } else if (node.type !== 'space' && node.type !== 'comment') {\n current.push(node)\n }\n }\n layers.push(current)\n return layers\n}\n\n/** A word's finite number and lowercased unit, or null for anything that is not a dimension. */\nexport function cssDimension(node: Node | undefined): { value: number; unit: string } | null {\n if (node?.type !== 'word') return null\n const dimension = valueParser.unit(node.value)\n if (!dimension) return null\n const value = Number(dimension.number)\n if (!Number.isFinite(value)) return null\n return { value, unit: dimension.unit.toLowerCase() }\n}\n"],"mappings":";;;;AAOA,MAAM,iBAAiB;;;;;AAMvB,SAAgB,eAAe,OAA0C;CACvE,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,YAAY,YAAY,KAAK,MAAM,KAAK,CAAC;CAC/C,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,SAAS,OAAO,UAAU,MAAM;CACtC,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,OAAO;CACrC,QAAQ,UAAU,KAAK,YAAY,GAAnC;EACE,KAAK;EACL,KAAK,MACH,OAAO;EACT,KAAK,OACH,OAAO,SAAS;EAClB,SACE,OAAO;CACX;AACF;;;;;;AAOA,SAAgB,cACd,OACA,UAA8B,QAChB;CACd,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,QAAQ,cAAc,MAAM,KAAK,GAAG,OAAO;CACjD,OAAO,SAAS,MAAM,IAAI,IAAI,QAAQ;AACxC;;AAGA,SAAgB,cAAc,OAAyB;CACrD,OAAO,YAAY,KAAK,CAAC,CACtB,MAAM,QAAQ,SAAS,KAAK,SAAS,WAAW,KAAK,SAAS,SAAS,CAAC,CACxE,KAAK,SAAS,YAAY,UAAU,IAAI,CAAC;AAC9C;;AAGA,SAAgB,UAAU,OAAyB;CACjD,MAAM,SAAmB,CAAC;CAC1B,IAAI,UAAkB,CAAC;CACvB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,SAAS,SAAS,KAAK,UAAU,KAAK;EAC7C,OAAO,KAAK,OAAO;EACnB,UAAU,CAAC;CACb,OAAO,IAAI,KAAK,SAAS,WAAW,KAAK,SAAS,WAChD,QAAQ,KAAK,IAAI;CAGrB,OAAO,KAAK,OAAO;CACnB,OAAO;AACT;;AAGA,SAAgB,aAAa,MAAgE;CAC3F,IAAI,MAAM,SAAS,QAAQ,OAAO;CAClC,MAAM,YAAY,YAAY,KAAK,KAAK,KAAK;CAC7C,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,QAAQ,OAAO,UAAU,MAAM;CACrC,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,OAAO;EAAE;EAAO,MAAM,UAAU,KAAK,YAAY;CAAE;AACrD"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, DesignDecision, DesignDecisionAuthor, DesignExample, DesignMemory, DesignMemoryEnforcement, DesignMemoryGroup, designMemorySchema } from "./schema.js";
|
|
2
|
+
import { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory } from "./model.js";
|
|
3
|
+
export { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, DesignDecision, DesignDecisionAuthor, DesignExample, DesignMemory, DesignMemoryEnforcement, DesignMemoryGroup, addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, designMemorySchema, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, designMemorySchema } from "./schema.js";
|
|
2
|
+
import { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory } from "./model.js";
|
|
3
|
+
export { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, designMemorySchema, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { DesignDecisionAuthor, DesignMemory, DesignMemoryGroup } from "./schema.js";
|
|
3
|
+
//#region src/design-memory/model.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A new memory: every group allows the document's own variables and styles. Off-system colors
|
|
6
|
+
* and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.
|
|
7
|
+
*/
|
|
8
|
+
declare function createDesignMemory(): DesignMemory;
|
|
9
|
+
/** The document's memory, or null when it has none or it is unreadable. */
|
|
10
|
+
declare function readDesignMemory(graph: SceneGraph): DesignMemory | null;
|
|
11
|
+
/**
|
|
12
|
+
* The document's memory, read once per state of its document node: an edit replaces the node's
|
|
13
|
+
* plugin data, so a check on every agent call parses nothing new.
|
|
14
|
+
*/
|
|
15
|
+
declare function cachedDesignMemory(graph: SceneGraph): DesignMemory | null;
|
|
16
|
+
/** Stores the memory on the document node as an undoable change; `null` removes it. */
|
|
17
|
+
declare function writeDesignMemory(graph: SceneGraph, memory: DesignMemory | null): void;
|
|
18
|
+
/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */
|
|
19
|
+
declare function normalizeDesignValue(group: DesignMemoryGroup, value: string | number): string | number | null;
|
|
20
|
+
/**
|
|
21
|
+
* The memory with `value` allowed in `group`, once; a value the group cannot read, or one past
|
|
22
|
+
* its limit, leaves it as it was.
|
|
23
|
+
*/
|
|
24
|
+
declare function allowDesignValue(memory: DesignMemory, group: DesignMemoryGroup, value: string | number): DesignMemory;
|
|
25
|
+
/** The memory with `value` no longer allowed in `group` by itself. */
|
|
26
|
+
declare function disallowDesignValue(memory: DesignMemory, group: DesignMemoryGroup, value: string | number): DesignMemory;
|
|
27
|
+
/** The memory with a decision added last; blank text or a full list leaves it as it was. */
|
|
28
|
+
declare function addDesignDecision(memory: DesignMemory, text: string, author: DesignDecisionAuthor): DesignMemory;
|
|
29
|
+
/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */
|
|
30
|
+
declare function pinDesignExample(memory: DesignMemory, nodeId: string): DesignMemory;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
33
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/design-memory/model.ts"],"mappings":";;;;;;;iBA2BgB,sBAAsB;;iBActB,iBAAiB,OAAO,aAAa;;;;;iBAarC,mBAAmB,OAAO,aAAa;;iBAUvC,kBAAkB,OAAO,YAAY,QAAQ;;iBAS7C,qBACd,OAAO,mBACP;;;;;iBAoBc,iBACd,QAAQ,cACR,OAAO,mBACP,yBACC;;iBASa,oBACd,QAAQ,cACR,OAAO,mBACP,yBACC;;iBASa,kBACd,QAAQ,cACR,cACA,QAAQ,uBACP;;iBAUa,iBAAiB,QAAQ,cAAc,iBAAiB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { randomHex } from "../random.js";
|
|
2
|
+
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
3
|
+
import { DESIGN_MEMORY_LIMITS } from "./schema.js";
|
|
4
|
+
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
5
|
+
import { colorToHex, tryParseColor } from "../color/index.js";
|
|
6
|
+
//#region src/design-memory/model.ts
|
|
7
|
+
const { designMemory } = PAIRDRAW_PLUGIN_DATA;
|
|
8
|
+
const GROUP_LIMITS = {
|
|
9
|
+
colors: DESIGN_MEMORY_LIMITS.colors,
|
|
10
|
+
fonts: DESIGN_MEMORY_LIMITS.fonts,
|
|
11
|
+
fontSizes: DESIGN_MEMORY_LIMITS.numbers,
|
|
12
|
+
spacing: DESIGN_MEMORY_LIMITS.numbers,
|
|
13
|
+
radius: DESIGN_MEMORY_LIMITS.numbers
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A new memory: every group allows the document's own variables and styles. Off-system colors
|
|
17
|
+
* and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.
|
|
18
|
+
*/
|
|
19
|
+
function createDesignMemory() {
|
|
20
|
+
return {
|
|
21
|
+
version: 1,
|
|
22
|
+
colors: {
|
|
23
|
+
fromSystem: true,
|
|
24
|
+
values: [],
|
|
25
|
+
enforce: "refuse"
|
|
26
|
+
},
|
|
27
|
+
fonts: {
|
|
28
|
+
fromSystem: true,
|
|
29
|
+
values: [],
|
|
30
|
+
enforce: "refuse"
|
|
31
|
+
},
|
|
32
|
+
fontSizes: {
|
|
33
|
+
fromSystem: true,
|
|
34
|
+
values: [],
|
|
35
|
+
enforce: "warn"
|
|
36
|
+
},
|
|
37
|
+
spacing: {
|
|
38
|
+
fromSystem: true,
|
|
39
|
+
values: [],
|
|
40
|
+
enforce: "warn"
|
|
41
|
+
},
|
|
42
|
+
radius: {
|
|
43
|
+
fromSystem: true,
|
|
44
|
+
values: [],
|
|
45
|
+
enforce: "warn"
|
|
46
|
+
},
|
|
47
|
+
decisions: [],
|
|
48
|
+
examples: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** The document's memory, or null when it has none or it is unreadable. */
|
|
52
|
+
function readDesignMemory(graph) {
|
|
53
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, designMemory) ?? null;
|
|
54
|
+
}
|
|
55
|
+
const MEMORIES = /* @__PURE__ */ new WeakMap();
|
|
56
|
+
/**
|
|
57
|
+
* The document's memory, read once per state of its document node: an edit replaces the node's
|
|
58
|
+
* plugin data, so a check on every agent call parses nothing new.
|
|
59
|
+
*/
|
|
60
|
+
function cachedDesignMemory(graph) {
|
|
61
|
+
const entries = graph.getNode(graph.rootId)?.pluginData;
|
|
62
|
+
const known = MEMORIES.get(graph);
|
|
63
|
+
if (known && known.entries === entries) return known.memory;
|
|
64
|
+
const memory = readDesignMemory(graph);
|
|
65
|
+
MEMORIES.set(graph, {
|
|
66
|
+
entries,
|
|
67
|
+
memory
|
|
68
|
+
});
|
|
69
|
+
return memory;
|
|
70
|
+
}
|
|
71
|
+
/** Stores the memory on the document node as an undoable change; `null` removes it. */
|
|
72
|
+
function writeDesignMemory(graph, memory) {
|
|
73
|
+
const root = graph.getNode(graph.rootId);
|
|
74
|
+
if (!root) return;
|
|
75
|
+
graph.updateNode(root.id, { pluginData: withPluginData(root.pluginData, designMemory, memory ?? void 0) });
|
|
76
|
+
}
|
|
77
|
+
/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */
|
|
78
|
+
function normalizeDesignValue(group, value) {
|
|
79
|
+
if (group === "colors") {
|
|
80
|
+
const color = typeof value === "string" ? tryParseColor(value.trim()) : null;
|
|
81
|
+
return color ? colorToHex(color) : null;
|
|
82
|
+
}
|
|
83
|
+
if (group === "fonts") {
|
|
84
|
+
const family = typeof value === "string" ? value.trim() : "";
|
|
85
|
+
return family && family.length <= DESIGN_MEMORY_LIMITS.fontLength ? family : null;
|
|
86
|
+
}
|
|
87
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
88
|
+
if (!Number.isFinite(number)) return null;
|
|
89
|
+
return number > 0 || number === 0 && group !== "fontSizes" ? number : null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The memory with `value` allowed in `group`, once; a value the group cannot read, or one past
|
|
93
|
+
* its limit, leaves it as it was.
|
|
94
|
+
*/
|
|
95
|
+
function allowDesignValue(memory, group, value) {
|
|
96
|
+
const normalized = normalizeDesignValue(group, value);
|
|
97
|
+
const values = memory[group].values;
|
|
98
|
+
if (normalized === null || values.includes(normalized) || values.length >= GROUP_LIMITS[group]) return memory;
|
|
99
|
+
return {
|
|
100
|
+
...memory,
|
|
101
|
+
[group]: {
|
|
102
|
+
...memory[group],
|
|
103
|
+
values: [...values, normalized]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** The memory with `value` no longer allowed in `group` by itself. */
|
|
108
|
+
function disallowDesignValue(memory, group, value) {
|
|
109
|
+
const values = memory[group].values;
|
|
110
|
+
return {
|
|
111
|
+
...memory,
|
|
112
|
+
[group]: {
|
|
113
|
+
...memory[group],
|
|
114
|
+
values: values.filter((item) => item !== value)
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The memory with a decision added last; blank text or a full list leaves it as it was. */
|
|
119
|
+
function addDesignDecision(memory, text, author) {
|
|
120
|
+
const trimmed = text.trim().slice(0, DESIGN_MEMORY_LIMITS.decisionLength).trim();
|
|
121
|
+
if (!trimmed || memory.decisions.length >= DESIGN_MEMORY_LIMITS.decisions) return memory;
|
|
122
|
+
return {
|
|
123
|
+
...memory,
|
|
124
|
+
decisions: [...memory.decisions, {
|
|
125
|
+
id: randomHex(8),
|
|
126
|
+
text: trimmed,
|
|
127
|
+
author
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */
|
|
132
|
+
function pinDesignExample(memory, nodeId) {
|
|
133
|
+
if (memory.examples.some((example) => example.nodeId === nodeId) || memory.examples.length >= DESIGN_MEMORY_LIMITS.examples) return memory;
|
|
134
|
+
return {
|
|
135
|
+
...memory,
|
|
136
|
+
examples: [...memory.examples, { nodeId }]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=model.js.map
|