@pairdraw/scene-graph 0.19.1 → 0.20.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/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/spec.d.ts +6 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +62 -5
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/canvas-layout.js +66 -0
- package/dist/canvas-layout.js.map +1 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- 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/coordinate.js +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/text.d.ts +22 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +81 -1
- package/dist/css/text.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 +93 -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/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/graph.d.ts +8 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +36 -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/group-bounds.d.ts +4 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +11 -1
- package/dist/group-bounds.js.map +1 -1
- 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 +33 -178
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- 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 +1 -1
- package/dist/instances/index.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/node-defaults.d.ts +21 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +63 -50
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +75 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +18 -1
- package/dist/plugin-data/fields.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/resize.d.ts.map +1 -1
- package/dist/resize.js +3 -6
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +28 -4
- package/dist/scaling/node.js.map +1 -1
- package/dist/shared-styles.d.ts +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- package/dist/shared-styles.js.map +1 -1
- package/dist/text/path.js +11 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.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/copied.d.ts +14 -0
- package/dist/transfer/copied.d.ts.map +1 -0
- package/dist/transfer/copied.js +52 -0
- package/dist/transfer/copied.js.map +1 -0
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +2 -1
- package/dist/transfer/nodes.js +7 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +104 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +6 -0
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +13 -0
- package/dist/undo.js.map +1 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js.map +1 -1
- 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/behaviours/spec.ts +94 -4
- package/src/canvas-layout.ts +76 -0
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +12 -1
- package/src/css/text.ts +86 -0
- 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 +101 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/generated/shape-with-text.ts +28 -2
- package/src/graph.ts +48 -6
- package/src/grid-values.ts +47 -0
- package/src/group-bounds.ts +13 -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 +78 -291
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +1 -0
- package/src/node-defaults.ts +71 -52
- package/src/plugin-data/fields.ts +18 -1
- package/src/preview.ts +2 -0
- package/src/resize.ts +3 -14
- package/src/scaling/node.ts +34 -5
- package/src/shared-styles.ts +8 -0
- package/src/text/path.ts +14 -0
- package/src/text/picture.ts +5 -2
- 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/copied.ts +72 -0
- package/src/transfer/index.ts +1 -0
- package/src/transfer/nodes.ts +10 -0
- package/src/types.ts +117 -14
- package/src/undo.ts +11 -0
- package/src/variables/index.ts +1 -4
- 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;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,IAAI,EAAE,YACJ,KAAK,aAAa,EAAE,WAAW,KAAK,WAAW;EAC7C,UAAU,EAAE,GAAG,MAAM,S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AG,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,IAAI,EAAE,YACJ,KAAK,aAAa,EAAE,WAAW,KAAK,WAAW;EAC7C,UAAU,EAAE,GAAG,MAAM,SAAS;EAC9B,OAAO,EAAE,GAAG,MAAM,MAAM;CAC1B,EAAE;CAEJ,IAAI,EAAE,gBAAgB,KAAK,iBAAiB,EAAE,GAAG,EAAE,eAAe;CAClE,IAAI,EAAE,SAAS,KAAK,UAAU,EAAE,GAAG,EAAE,QAAQ;CAC7C,IAA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iB,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 { 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, 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 { parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight } from "./text.js";
|
|
7
|
-
export { parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, 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/text.d.ts
CHANGED
|
@@ -6,6 +6,27 @@ import { TextLength } from "../types.js";
|
|
|
6
6
|
* of the family, so a name list such as draw.io's keeps `O'Reilly`. Null for an empty list.
|
|
7
7
|
*/
|
|
8
8
|
declare function parseCSSFontFamily(value: string | undefined): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Every family of a CSS `font-family` list, in order, without quotes and escapes. A quoted family
|
|
11
|
+
* is one name; an unquoted one joins its words with single spaces.
|
|
12
|
+
*/
|
|
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;
|
|
9
30
|
/**
|
|
10
31
|
* A CSS `line-height` as a text length: a unitless multiple, `em`, or a percent follows the font size,
|
|
11
32
|
* as a percent does in Figma; pixels stay pixels; `normal` is automatic, a null. Undefined for a
|
|
@@ -18,5 +39,5 @@ declare function parseCSSLineHeight(value: string | undefined): TextLength | nul
|
|
|
18
39
|
*/
|
|
19
40
|
declare function parseCSSLetterSpacing(value: string | undefined): TextLength | undefined;
|
|
20
41
|
//#endregion
|
|
21
|
-
export { parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
42
|
+
export { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, GenericFontClass, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
22
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";
|
|
@@ -32,6 +33,85 @@ function parseCSSFontFamily(value) {
|
|
|
32
33
|
if (quote === "\"" || quote === "'") return decodeCSSEscapes(text.slice(1, unescapedIndexOf(text, quote, 1))) || null;
|
|
33
34
|
return decodeCSSEscapes(text.slice(0, unescapedIndexOf(text, ",", 0))).trim().replace(/\s+/gu, " ") || null;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Every family of a CSS `font-family` list, in order, without quotes and escapes. A quoted family
|
|
38
|
+
* is one name; an unquoted one joins its words with single spaces.
|
|
39
|
+
*/
|
|
40
|
+
function parseCSSFontFamilies(value) {
|
|
41
|
+
const text = value?.trim();
|
|
42
|
+
if (!text) return [];
|
|
43
|
+
const families = [];
|
|
44
|
+
let current = [];
|
|
45
|
+
for (const node of valueParser(text).nodes) if (node.type === "div" && node.value === ",") {
|
|
46
|
+
families.push(valueParser.stringify(current));
|
|
47
|
+
current = [];
|
|
48
|
+
} else current.push(node);
|
|
49
|
+
families.push(valueParser.stringify(current));
|
|
50
|
+
return families.flatMap((family) => {
|
|
51
|
+
const parsed = parseCSSFontFamily(family);
|
|
52
|
+
return parsed ? [parsed] : [];
|
|
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
|
+
}
|
|
35
115
|
/** A CSS dimension's number and lowercase unit, or null. */
|
|
36
116
|
function dimension(value) {
|
|
37
117
|
const parsed = valueParser.unit(value);
|
|
@@ -71,6 +151,6 @@ function parseCSSLetterSpacing(value) {
|
|
|
71
151
|
return pixels === null ? void 0 : pixelLength(pixels);
|
|
72
152
|
}
|
|
73
153
|
//#endregion
|
|
74
|
-
export { parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
154
|
+
export { GENERIC_FONT_FAMILIES, GENERIC_FONT_FAMILIES_BY_CLASS, GENERIC_FONT_FAMILY_CLASS, genericFontFamilyClass, isGenericFontFamily, parseCSSFontFamilies, parseCSSFontFamily, parseCSSLetterSpacing, parseCSSLineHeight };
|
|
75
155
|
|
|
76
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/** 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,MA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K,OAAO,cAAc,OAAO,MAAM;CAC5D,MAAM,SAAS,eAAe,OAAO;CACrC,OAAO,WAAW,OAAO,KAAA,IAAY,YAAY,MAAM;AACzD;;;;;AAMA,SAAgB,sBAAsB,OAAmD;CACvF,MAAM,UAAU,OAAO,KAAK;CAC5B,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,YAAY,UAAU,OAAO,YAAY,CAAC;CAC9C,MAAM,SAAS,UAAU,OAAO;CAChC,IAAI,QAAQ,SAAS,MAAM,OAAO,cAAc,OAAO,SAAS,GAAG;CACnE,MAAM,SAAS,eAAe,OAAO;CACrC,OAAO,WAAW,OAAO,KAAA,IAAY,YAAY,MAAM;AACzD"}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/design-memory/model.ts"],"sourcesContent":["import { tryParseColor, colorToHex } from '../color'\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport { randomHex } from '../random'\nimport type { PluginDataEntry } from '../types'\nimport {\n DESIGN_MEMORY_LIMITS,\n type DesignDecisionAuthor,\n type DesignMemory,\n type DesignMemoryGroup\n} from './schema'\n\nconst { designMemory } = PAIRDRAW_PLUGIN_DATA\n\nconst GROUP_LIMITS = {\n colors: DESIGN_MEMORY_LIMITS.colors,\n fonts: DESIGN_MEMORY_LIMITS.fonts,\n fontSizes: DESIGN_MEMORY_LIMITS.numbers,\n spacing: DESIGN_MEMORY_LIMITS.numbers,\n radius: DESIGN_MEMORY_LIMITS.numbers\n} as const satisfies Record<DesignMemoryGroup, number>\n\n/**\n * A new memory: every group allows the document's own variables and styles. Off-system colors\n * and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.\n */\nexport function createDesignMemory(): DesignMemory {\n return {\n version: 1,\n colors: { fromSystem: true, values: [], enforce: 'refuse' },\n fonts: { fromSystem: true, values: [], enforce: 'refuse' },\n fontSizes: { fromSystem: true, values: [], enforce: 'warn' },\n spacing: { fromSystem: true, values: [], enforce: 'warn' },\n radius: { fromSystem: true, values: [], enforce: 'warn' },\n decisions: [],\n examples: []\n }\n}\n\n/** The document's memory, or null when it has none or it is unreadable. */\nexport function readDesignMemory(graph: SceneGraph): DesignMemory | null {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, designMemory) ?? null\n}\n\nconst MEMORIES = new WeakMap<\n SceneGraph,\n { entries: readonly PluginDataEntry[] | undefined; memory: DesignMemory | null }\n>()\n\n/**\n * The document's memory, read once per state of its document node: an edit replaces the node's\n * plugin data, so a check on every agent call parses nothing new.\n */\nexport function cachedDesignMemory(graph: SceneGraph): DesignMemory | null {\n const entries = graph.getNode(graph.rootId)?.pluginData\n const known = MEMORIES.get(graph)\n if (known && known.entries === entries) return known.memory\n const memory = readDesignMemory(graph)\n MEMORIES.set(graph, { entries, memory })\n return memory\n}\n\n/** Stores the memory on the document node as an undoable change; `null` removes it. */\nexport function writeDesignMemory(graph: SceneGraph, memory: DesignMemory | null): void {\n const root = graph.getNode(graph.rootId)\n if (!root) return\n graph.updateNode(root.id, {\n pluginData: withPluginData(root.pluginData, designMemory, memory ?? undefined)\n })\n}\n\n/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */\nexport function normalizeDesignValue(\n group: DesignMemoryGroup,\n value: string | number\n): string | number | null {\n if (group === 'colors') {\n const color = typeof value === 'string' ? tryParseColor(value.trim()) : null\n return color ? colorToHex(color) : null\n }\n if (group === 'fonts') {\n const family = typeof value === 'string' ? value.trim() : ''\n return family && family.length <= DESIGN_MEMORY_LIMITS.fontLength ? family : null\n }\n const number = typeof value === 'number' ? value : Number(value)\n if (!Number.isFinite(number)) return null\n // A text has a size; spacing and radii may be zero.\n return number > 0 || (number === 0 && group !== 'fontSizes') ? number : null\n}\n\n/**\n * The memory with `value` allowed in `group`, once; a value the group cannot read, or one past\n * its limit, leaves it as it was.\n */\nexport function allowDesignValue(\n memory: DesignMemory,\n group: DesignMemoryGroup,\n value: string | number\n): DesignMemory {\n const normalized = normalizeDesignValue(group, value)\n const values: readonly (string | number)[] = memory[group].values\n if (normalized === null || values.includes(normalized) || values.length >= GROUP_LIMITS[group])\n return memory\n return { ...memory, [group]: { ...memory[group], values: [...values, normalized] } }\n}\n\n/** The memory with `value` no longer allowed in `group` by itself. */\nexport function disallowDesignValue(\n memory: DesignMemory,\n group: DesignMemoryGroup,\n value: string | number\n): DesignMemory {\n const values: readonly (string | number)[] = memory[group].values\n return {\n ...memory,\n [group]: { ...memory[group], values: values.filter((item) => item !== value) }\n }\n}\n\n/** The memory with a decision added last; blank text or a full list leaves it as it was. */\nexport function addDesignDecision(\n memory: DesignMemory,\n text: string,\n author: DesignDecisionAuthor\n): DesignMemory {\n const trimmed = text.trim().slice(0, DESIGN_MEMORY_LIMITS.decisionLength).trim()\n if (!trimmed || memory.decisions.length >= DESIGN_MEMORY_LIMITS.decisions) return memory\n return {\n ...memory,\n decisions: [...memory.decisions, { id: randomHex(8), text: trimmed, author }]\n }\n}\n\n/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */\nexport function pinDesignExample(memory: DesignMemory, nodeId: string): DesignMemory {\n if (\n memory.examples.some((example) => example.nodeId === nodeId) ||\n memory.examples.length >= DESIGN_MEMORY_LIMITS.examples\n )\n return memory\n return { ...memory, examples: [...memory.examples, { nodeId }] }\n}\n"],"mappings":";;;;;;AAaA,MAAM,EAAE,iBAAiB;AAEzB,MAAM,eAAe;CACnB,QAAQ,qBAAqB;CAC7B,OAAO,qBAAqB;CAC5B,WAAW,qBAAqB;CAChC,SAAS,qBAAqB;CAC9B,QAAQ,qBAAqB;AAC/B;;;;;AAMA,SAAgB,qBAAmC;CACjD,OAAO;EACL,SAAS;EACT,QAAQ;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAS;EAC1D,OAAO;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAS;EACzD,WAAW;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EAC3D,SAAS;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EACzD,QAAQ;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EACxD,WAAW,CAAC;EACZ,UAAU,CAAC;CACb;AACF;;AAGA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,eAAe,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,YA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AE,GAAG,OAAO;GAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;EAAE;CAAE;AACrF;;AAGA,SAAgB,oBACd,QACA,OACA,OACc;CACd,MAAM,SAAuC,OAAO,MAAM,CAAC;CAC3D,OAAO;EACL,GAAG;GACF,QAAQ;GAAE,GAAG,OAAO;GAAQ,QAAQ,OAAO,QAAQ,SAAS,SAAS,KAAK;EAAE;CAC/E;AACF;;AAGA,SAAgB,kBACd,QACA,MACA,QACc;CACd,MAAM,UAAU,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,qBAAqB,cAAc,CAAC,CAAC,KAAK;CAC/E,IAAI,CAAC,WAAW,OAAO,UAAU,UAAU,qBAAqB,WAAW,OAAO;CAClF,OAAO;EACL,GAAG;EACH,WAAW,CAAC,GAAG,OAAO,WAAW;GAAE,IAAI,UAAU,CAAC;GAAG,MAAM;GAAS;EAAO,CAAC;CAC9E;AACF;;AAGA,SAAgB,iBAAiB,QAAsB,QAA8B;CACnF,IACE,OAAO,SAAS,MAAM,YAAY,QAAQ,WAAW,MAAM,KAC3D,OAAO,SAAS,UAAU,qBAAqB,UAE/C,OAAO;CACT,OAAO;EAAE,GAAG;EAAQ,UAAU,CAAC,GAAG,OAAO,UAAU,EAAE,OAAO,CAAC;CAAE;AACjE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/design-memory/schema.d.ts
|
|
3
|
+
/** How many values, decisions and examples one document's memory keeps. */
|
|
4
|
+
declare const DESIGN_MEMORY_LIMITS: {
|
|
5
|
+
readonly colors: 128;
|
|
6
|
+
readonly fonts: 16;
|
|
7
|
+
readonly numbers: 32;
|
|
8
|
+
readonly decisions: 40;
|
|
9
|
+
readonly decisionLength: 400;
|
|
10
|
+
readonly examples: 12;
|
|
11
|
+
readonly fontLength: 100;
|
|
12
|
+
};
|
|
13
|
+
/** The kinds of value a memory allows, each with its own list and enforcement. */
|
|
14
|
+
declare const DESIGN_MEMORY_GROUPS: readonly ["colors", "fonts", "fontSizes", "spacing", "radius"];
|
|
15
|
+
type DesignMemoryGroup = (typeof DESIGN_MEMORY_GROUPS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* What happens to an agent's edit that uses a value the memory does not allow: it is undone and
|
|
18
|
+
* the agent told the allowed values, it goes through with a warning, or nothing is checked.
|
|
19
|
+
* People's own edits are never refused; lint lists them.
|
|
20
|
+
*/
|
|
21
|
+
declare const DESIGN_MEMORY_ENFORCEMENTS: readonly ["refuse", "warn", "off"];
|
|
22
|
+
type DesignMemoryEnforcement = (typeof DESIGN_MEMORY_ENFORCEMENTS)[number];
|
|
23
|
+
declare const DESIGN_DECISION_AUTHORS: readonly ["person", "agent"];
|
|
24
|
+
type DesignDecisionAuthor = (typeof DESIGN_DECISION_AUTHORS)[number];
|
|
25
|
+
/**
|
|
26
|
+
* A document's design rules for agents: the values its designs may use, decisions written down
|
|
27
|
+
* about them, and frames pinned as examples to follow.
|
|
28
|
+
*/
|
|
29
|
+
declare const designMemorySchema: v.ObjectSchema<{
|
|
30
|
+
readonly version: v.LiteralSchema<1, undefined>;
|
|
31
|
+
readonly colors: v.ObjectSchema<{
|
|
32
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
33
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, string>, undefined>, v.MaxLengthAction<string[], number, undefined>]>;
|
|
34
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
35
|
+
}, undefined>;
|
|
36
|
+
readonly fonts: v.ObjectSchema<{
|
|
37
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
38
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, string>, undefined>, v.MaxLengthAction<string[], number, undefined>]>;
|
|
39
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
readonly fontSizes: v.ObjectSchema<{
|
|
42
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
43
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
44
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
45
|
+
}, undefined>;
|
|
46
|
+
readonly spacing: v.ObjectSchema<{
|
|
47
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
48
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
49
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
50
|
+
}, undefined>;
|
|
51
|
+
readonly radius: v.ObjectSchema<{
|
|
52
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
53
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
54
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
55
|
+
}, undefined>;
|
|
56
|
+
readonly decisions: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
57
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
58
|
+
readonly text: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 400, undefined>]>;
|
|
59
|
+
readonly author: v.PicklistSchema<readonly ["person", "agent"], undefined>;
|
|
60
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
61
|
+
id: string;
|
|
62
|
+
text: string;
|
|
63
|
+
author: "person" | "agent";
|
|
64
|
+
}[], 40, undefined>]>;
|
|
65
|
+
readonly examples: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
66
|
+
readonly nodeId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
67
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
68
|
+
nodeId: string;
|
|
69
|
+
}[], 12, undefined>]>;
|
|
70
|
+
}, undefined>;
|
|
71
|
+
type DesignMemory = v.InferOutput<typeof designMemorySchema>;
|
|
72
|
+
type DesignDecision = DesignMemory['decisions'][number];
|
|
73
|
+
type DesignExample = DesignMemory['examples'][number];
|
|
74
|
+
//#endregion
|
|
75
|
+
export { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, DesignDecision, DesignDecisionAuthor, DesignExample, DesignMemory, DesignMemoryEnforcement, DesignMemoryGroup, designMemorySchema };
|
|
76
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/design-memory/schema.ts"],"mappings":";;;cAGa;;;;;;;;;;cAWA;KACD,4BAA4B;;;;;;cAO3B;KACD,kCAAkC;cAEjC;KACD,+BAA+B;;;;;cA4C9B,oBAAkB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAWnB,eAAe,EAAE,mBAAmB;KACpC,iBAAiB;KACjB,gBAAgB"}
|