@pairdraw/scene-graph 0.20.0 → 0.21.1
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/properties.d.ts.map +1 -1
- package/dist/components/properties.js +7 -7
- package/dist/components/properties.js.map +1 -1
- 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/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/empty-values.js +9 -0
- package/dist/empty-values.js.map +1 -1
- package/dist/graph.d.ts +4 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +11 -2
- package/dist/graph.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/index.d.ts.map +1 -1
- package/dist/instances/index.js +12 -11
- 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/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.js +2 -2
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +15 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +15 -23
- 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/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/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 +34 -2
- 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/package.json +1 -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/css/shadows.ts +8 -5
- package/src/css/values.ts +12 -5
- package/src/empty-values.ts +16 -0
- package/src/graph.ts +13 -1
- package/src/images.ts +27 -3
- package/src/instances/copies.ts +2 -1
- package/src/instances/index.ts +19 -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 +2 -2
- package/src/plugin-data/fields.ts +16 -31
- package/src/plugin-data/index.ts +1 -0
- package/src/plugin-data/schema.ts +30 -0
- 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/transfer/variables.ts +2 -1
- package/src/types.ts +30 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n// Child cloning and property synchronization shared by instance creation, swap, and sync.\nimport { pick } from 'es-toolkit/object'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from '../copy'\nimport type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { scaleNodeChanges } from '../scaling/node'\nimport { ownsSlotContent, slotPropertyId } from '../slots/frames'\nimport {\n STROKE_LINE_FIELDS,\n STROKE_LINE_KEYS,\n strokeLine,\n type StrokeLines,\n withStrokeLines\n} from '../strokes'\nimport type { SceneNode } from '../types'\nimport { resolvedNumericBindings } from '../variables/bindings'\nimport { isNumericVariableBindingField, paintBindingTarget } from '../variables/fields'\nimport {\n applyBoundPaintColorsIn,\n copyAppliedBoundPaints,\n keepCopyBoundPaints\n} from '../variables/paints'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'\nimport { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'\nimport {\n createInstanceSyncContext,\n hasUnplacedCopiesBelow,\n restoreRemovedCopy,\n unplacedCopy,\n type InstanceSyncContext\n} from './copies'\nimport { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'\nimport { ownsSelfFillField, sourceWithEffectiveFill } from './main-component'\nimport { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => {\n if (fields.has(field)) return true\n // Paints an instance set itself own their bindings too, bound or not.\n const binding = overriddenBindingField(field)\n if (binding === null) return false\n const paint = paintBindingTarget(binding)\n return paint !== null && fields.has(paint.list)\n }\n}\n\nexport function syncBindingFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n if (protectedField('boundVariables')) return\n const bindings = { ...source.boundVariables }\n const scales = { ...source.variableBindingScales }\n for (const field of new Set([\n ...Object.keys(source.boundVariables),\n ...Object.keys(target.boundVariables),\n ...Object.keys(target.variableBindingScales)\n ])) {\n if (!protectedField(bindingOverrideField(field))) continue\n if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)\n else bindings[field] = target.boundVariables[field]\n if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)\n else scales[field] = target.variableBindingScales[field]\n }\n updates.boundVariables = bindings\n updates.variableBindingScales = scales\n}\n\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n const scaled = scaleNodeChanges(source, factor, true)\n return {\n ...source,\n ...scaled,\n ...scaleVariableBindingUnits(source, factor, scaled.styleRuns)\n }\n}\n\ninterface SyncedFieldsInput {\n compParent: SceneNode\n instParent: SceneNode\n /** The component's coordinates in the copy's. */\n factor: number\n /** Fields the copy keeps: overridden, bound, or driven by a property. */\n skip: (key: string) => boolean\n}\n\n/** The fields a copy takes from its component's layer, placed in the copy's parent. */\nfunction copySyncedFields(\n updates: Partial<SceneNode>,\n copy: SceneNode,\n source: SceneNode,\n { compParent, instParent, factor, skip }: SyncedFieldsInput\n): SyncedPlacement {\n // In an auto layout flow the layout places the copy, as it placed the component's layer.\n const placedByLayout = instParent.layoutMode !== 'NONE' && source.layoutPositioning !== 'ABSOLUTE'\n const placed = placedByLayout\n ? source\n : placedByConstraints(source, compParent, instParent, factor)\n for (const key of INSTANCE_SYNC_FIELDS) {\n // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n /** A field the copy keeps as its own, which the sync leaves as it is. */\n kept: (field: string) => boolean = () => false\n): void {\n resolveBoundNumbersInPlace(graph, target, updates, kept)\n if (updates.fills || updates.strokes || updates.boundVariables) {\n applySyncedModes(graph, target, updates)\n keepCopyBoundPaints(graph, target, updates)\n }\n // After the copy's own bound paints, which can bring its strokes into the write.\n applySyncedStrokeLines(graph, target, updates, kept)\n const changed = Object.fromEntries(\n Object.entries(updates).filter(\n ([key, value]) => !isEqual(target[key as keyof SceneNode], value)\n )\n ) as Partial<SceneNode>\n if (changed.fills && updates.fillStyleId !== undefined) changed.fillStyleId = updates.fillStyleId\n if (Object.keys(changed).length) graph.updateNode(target.id, changed)\n}\n\n/**\n * A bound number the sync writes takes the value it resolves to where the copy sits, not the\n * one its component holds: an instance that sets another mode, or sits in one that does, shows\n * that mode's value, as Figma draws it. A field the sync leaves alone, such as one an instance\n * overrides, keeps its own value.\n */\nfunction resolveBoundNumbersInPlace(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean\n): void {\n const bound = updates.boundVariables ?? target.boundVariables\n // The fields the sync writes, and the ones it binds anew, which keep an equal value only in\n // the component's mode.\n const rebound = updates.boundVariables\n ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field])\n : []\n const synced = uniq([...Object.keys(updates), ...rebound]).filter(\n (field) => isNumericVariableBindingField(field) && bound[field] && !kept(field)\n )\n if (synced.length === 0) return\n applySyncedModes(graph, target, updates)\n const resolved = resolvedNumericBindings(graph, { ...target, ...updates })\n Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))\n}\n\n/** The modes the copy takes in this sync decide what its bindings resolve to. */\nfunction applySyncedModes(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void {\n if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))\n graph.updateNode(target.id, { variableModes: updates.variableModes })\n}\n\n/**\n * Strokes a sync or swap gives a copy draw with the copy's own line fields: the weight,\n * alignment, cap, join, or dash it overrides, and a bound weight resolved in its modes. Figma\n * keeps a stroke weight override when the component's color changes (live).\n */\nexport function applySyncedStrokeLines(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean\n): void {\n const strokes = updates.strokes\n const first = strokes?.at(0)\n if (!strokes || !first) return\n const boundWeight = kept('strokeWeight')\n ? undefined\n : (updates.boundVariables ?? target.boundVariables).strokeWeight\n const weightScale =\n (updates.variableBindingScales ?? target.variableBindingScales).strokeWeight ?? 1\n const resolvedWeight = boundWeight\n ? graph.resolveNumberVariableForNode(target.id, boundWeight, 'active')\n : undefined\n const lines: StrokeLines = {}\n let set = false\n for (const key of STROKE_LINE_KEYS) {\n const field = STROKE_LINE_FIELDS[key]\n const own = kept(field)\n // A bound weight takes the value it resolves to where the copy sits, not its component's.\n const synced = own ? target[field] : updates[field]\n const value =\n field === 'strokeWeight' && resolvedWeight !== undefined\n ? resolvedWeight * weightScale\n : synced\n if (value === undefined) continue\n // A field the copy overrides holds for every stroke; the component's own values keep its\n // strokes' differences unless a binding resolved the first one apart.\n const differs = own\n ? strokes.some((stroke) => !isEqual(value, strokeLine(stroke, key)))\n : !isEqual(value, strokeLine(first, key))\n if (!differs) continue\n Reflect.set(lines, key, value)\n set = true\n }\n if (set) updates.strokes = withStrokeLines(strokes, lines)\n}\n\nfunction cloneChildInCoordinates(\n graph: SceneGraph,\n src: SceneNode,\n sourceParent: SceneNode,\n targetParent: SceneNode,\n mode: NodeCloneMode = 'deep'\n): SceneNode {\n const componentScale =\n (src.componentScale * targetParent.componentScale) / sourceParent.componentScale\n const clone = graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\n copyAppliedBoundPaints(src, clone)\n return clone\n}\n\nexport function cloneChildrenWithMapping(\n graph: SceneGraph,\n sourceParentId: string,\n destParentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n // A cyclic component, such as an instance of an ancestor, would clone itself without end.\n if (sourceParentId === destParentId || graph.isDescendant(destParentId, sourceParentId)) return\n\n const sourceParent = graph.nodes.get(sourceParentId)\n const targetParent = graph.nodes.get(destParentId)\n if (!sourceParent || !targetParent) return\n\n for (const childId of sourceParent.childIds) {\n const src = graph.nodes.get(childId)\n if (!src) continue\n\n const clone = cloneChildInCoordinates(graph, src, sourceParent, targetParent, mode)\n\n if (src.childIds.length > 0) {\n cloneChildrenWithMapping(graph, childId, clone.id, mode)\n }\n }\n}\n\nexport function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {\n const fields: Set<string>[] = []\n let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (parent) {\n if (parent.type === 'INSTANCE') {\n fields.push(new Set(parent.instanceOverrides.descendants.get(node.id)?.keys()))\n }\n parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined\n }\n return fields\n}\n\nfunction childBindingProtection(\n graph: SceneGraph,\n child: SceneNode,\n overrides: InstanceOverrideState\n) {\n const fields = enclosingInstanceOverrideFields(graph, child)\n fields.push(new Set(overrides.descendants.get(child.id)?.keys()))\n const protectedField = bindingProtection(fields)\n return (field: string) => protectedField(field) || ownsSelfFillField(child, field)\n}\n\n/** Links a copy to the component layer it matched, reporting each changed node and its owner. */\nfunction linkMatchedChild(\n graph: SceneGraph,\n context: InstanceSyncContext,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n const { overrides } = context\n const recorded = hasNodeInstanceOverride(\n overrides,\n instParentId,\n instChild.id,\n 'sourceComponentId'\n )\n if (instChild.type === 'INSTANCE' || recorded) {\n const owner = graph.nodes.get(context.instanceId)\n graph.willChangeNode(owner)\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n if (owner) graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n }\n if (instChild.type !== 'INSTANCE') graph.updateNode(instChild.id, { componentId: compChildId })\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n context: InstanceSyncContext,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()\n const remainingCandidateCount = new Map<SceneNode['type'], number>()\n const unmatchedComponentCount = new Map<SceneNode['type'], number>()\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const child = graph.nodes.get(compChildId)\n if (child) {\n unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)\n }\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || usedInstChildIds.has(child.id)) continue\n remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)\n let byName = fallbackByType.get(child.type)\n if (!byName) {\n byName = new Map()\n fallbackByType.set(child.type, byName)\n }\n const queue = byName.get(child.name)\n if (queue) queue.push(child)\n else byName.set(child.name, [child])\n }\n\n // Match by name and type with FIFO queues to preserve sibling order in linear time.\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const compChild = graph.nodes.get(compChildId)\n if (!compChild) continue\n const candidatesByName = fallbackByType.get(compChild.type)\n const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0\n if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue\n const match = candidatesByName?.get(compChild.name)?.shift()\n if (!match) continue\n remainingCandidateCount.set(compChild.type, candidateCount - 1)\n instChildMap.set(compChildId, match)\n usedInstChildIds.add(match.id)\n linkMatchedChild(graph, context, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState,\n matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n // The first copy of a layer keeps it; a duplicate stays unmatched for the sync to remove.\n if (instChildMap.has(mappedComponentId)) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n applyBoundPaintColorsIn(graph, clone.id)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n context,\n instChildMap,\n usedInstChildIds\n )\n\n placeMissingChildren(graph, compParent, instParent, instChildMap, usedInstChildIds, context)\n\n // Pass 4: Synchronize properties and recurse\n for (const compChildId of compParent.childIds) {\n const compChild = graph.nodes.get(compChildId)\n const instChild = instChildMap.get(compChildId)\n if (!compChild || !instChild) continue\n // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept = (key: string) =>\n driven.has(key) || isProtectedSyncField(instChild, key, protectedField)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: kept\n })\n Object.assign(updates, assignedFieldValues(graph, instChild, compChild))\n keepOwnContentSize(graph, updates, instChild, source, placement)\n updateSyncedProps(graph, instChild, updates, kept)\n\n if (\n compChild.childIds.length > 0 &&\n !hasNodeInstanceOverride(overrides, instParentId, instChild.id, 'componentId') &&\n // The component's frame is the authority on which slot this is; instance copies of\n // its bindings are not synced.\n !ownsSlotContent(graph, instChild, slotPropertyId(compChild))\n ) {\n syncChildren(graph, compChildId, instChild.id, overrides, context)\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO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aAAa,IAAI,WAAW;EAC9C,IAAI,CAAC,aAAa,CAAC,WAAW;EAG9B,IAAI,gBAAgB,OAAO,UAAU,EAAE,MAAM,KAAA,GAAW;EAExD,MAAM,iBAAiB,uBAAuB,OAAO,WAAW,SAAS;EACzE,MAAM,SAAS,qBAAqB,OAAO,WAAW,SAAS;EAC/D,MAAM,QAAQ,QACZ,OAAO,IAAI,GAAG,KAAK,qBAAqB,WAAW,KAAK,cAAc;EACxE,MAAM,iBACH,UAAU,iBAAiB,WAAW,iBAAkB,WAAW;EAEtE,MAAM,SAAS,0BADS,wBAAwB,OAAO,WAAW,SACX,GAAG,cAAc;EAGxE,MAAM,UAA8B;GAClC;GACA,6BAA6B,gBAAgB,UAAU,2BAA2B;EACpF;EACA,kBAAkB,WAAW,QAAQ,SAAS,cAAc;EAC5D,uBACE,WACA,QACA,UACC,UAAU,OAAO,IAAI,KAAK,KAAK,eAAe,KAAK,CACtD;EACA,MAAM,YAAY,iBAAiB,SAAS,WAAW,QAAQ;GAC7D;GACA;GACA,QAAQ,iBAAiB,UAAU;GACnC,MAAM;EACR,CAAC;EACD,OAAO,OAAO,SAAS,oBAAoB,OAAO,WAAW,SAAS,CAAC;EACvE,mBAAmB,OAAO,SAAS,WAAW,QAAQ,SAAS;EAC/D,kBAAkB,OAAO,WAAW,SAAS,IAAI;EAEjD,IACE,UAAU,SAAS,SAAS,KAC5B,CAACA,oBAAwB,WAAW,cAAc,UAAU,IAAI,aAAa,KAG7E,CAAC,gBAAgB,OAAO,WAAW,eAAe,SAAS,CAAC,GAE5D,aAAa,OAAO,aAAa,UAAU,IAAI,WAAW,OAAO;CAErE;CAGA,qBACE,OACA,YACA,cACA,WAAW,UACX,WACA,YACF;AACF"}
|
|
1
|
+
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n// Child cloning and property synchronization shared by instance creation, swap, and sync.\nimport { pick } from 'es-toolkit/object'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from '../copy'\nimport type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { scaleNodeChanges } from '../scaling/node'\nimport { ownsSlotContent, slotPropertyId } from '../slots/frames'\nimport {\n STROKE_LINE_FIELDS,\n STROKE_LINE_KEYS,\n strokeLine,\n type StrokeLines,\n withStrokeLines\n} from '../strokes'\nimport type { SceneNode } from '../types'\nimport { resolvedNumericBindings } from '../variables/bindings'\nimport { isNumericVariableBindingField, paintBindingTarget } from '../variables/fields'\nimport {\n applyBoundPaintColorsIn,\n copyAppliedBoundPaints,\n keepCopyBoundPaints\n} from '../variables/paints'\nimport { createVariableResolver, type VariableResolver } from '../variables/resolver'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'\nimport { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'\nimport {\n createInstanceSyncContext,\n hasUnplacedCopiesBelow,\n restoreRemovedCopy,\n unplacedCopy,\n type InstanceSyncContext\n} from './copies'\nimport { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'\nimport { ownsSelfFillField, sourceWithEffectiveFill } from './main-component'\nimport { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => {\n if (fields.has(field)) return true\n // Paints an instance set itself own their bindings too, bound or not.\n const binding = overriddenBindingField(field)\n if (binding === null) return false\n const paint = paintBindingTarget(binding)\n return paint !== null && fields.has(paint.list)\n }\n}\n\nexport function syncBindingFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n if (protectedField('boundVariables')) return\n const bindings = { ...source.boundVariables }\n const scales = { ...source.variableBindingScales }\n for (const field of new Set([\n ...Object.keys(source.boundVariables),\n ...Object.keys(target.boundVariables),\n ...Object.keys(target.variableBindingScales)\n ])) {\n if (!protectedField(bindingOverrideField(field))) continue\n if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)\n else bindings[field] = target.boundVariables[field]\n if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)\n else scales[field] = target.variableBindingScales[field]\n }\n updates.boundVariables = bindings\n updates.variableBindingScales = scales\n}\n\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n const scaled = scaleNodeChanges(source, factor, true)\n return {\n ...source,\n ...scaled,\n ...scaleVariableBindingUnits(source, factor, scaled.styleRuns)\n }\n}\n\ninterface SyncedFieldsInput {\n compParent: SceneNode\n instParent: SceneNode\n /** The component's coordinates in the copy's. */\n factor: number\n /** Fields the copy keeps: overridden, bound, or driven by a property. */\n skip: (key: string) => boolean\n}\n\n/** The fields a copy takes from its component's layer, placed in the copy's parent. */\nfunction copySyncedFields(\n updates: Partial<SceneNode>,\n copy: SceneNode,\n source: SceneNode,\n { compParent, instParent, factor, skip }: SyncedFieldsInput\n): SyncedPlacement {\n // In an auto layout flow the layout places the copy, as it placed the component's layer.\n const placedByLayout = instParent.layoutMode !== 'NONE' && source.layoutPositioning !== 'ABSOLUTE'\n const placed = placedByLayout\n ? source\n : placedByConstraints(source, compParent, instParent, factor)\n for (const key of INSTANCE_SYNC_FIELDS) {\n // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n /** A field the copy keeps as its own, which the sync leaves as it is. */\n kept: (field: string) => boolean = () => false\n): void {\n const resolver = createVariableResolver(graph)\n resolveBoundNumbersInPlace(graph, target, updates, kept, resolver)\n if (updates.fills || updates.strokes || updates.boundVariables) {\n applySyncedModes(graph, target, updates)\n keepCopyBoundPaints(graph, target, updates, resolver)\n }\n // After the copy's own bound paints, which can bring its strokes into the write.\n applySyncedStrokeLines(graph, target, updates, kept, resolver)\n const changed = Object.fromEntries(\n Object.entries(updates).filter(\n ([key, value]) => !isEqual(target[key as keyof SceneNode], value)\n )\n ) as Partial<SceneNode>\n if (changed.fills && updates.fillStyleId !== undefined) changed.fillStyleId = updates.fillStyleId\n if (Object.keys(changed).length) graph.updateNode(target.id, changed)\n}\n\n/**\n * A bound number the sync writes takes the value it resolves to where the copy sits, not the\n * one its component holds: an instance that sets another mode, or sits in one that does, shows\n * that mode's value, as Figma draws it. A field the sync leaves alone, such as one an instance\n * overrides, keeps its own value.\n */\nfunction resolveBoundNumbersInPlace(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean,\n resolver: VariableResolver\n): void {\n const bound = updates.boundVariables ?? target.boundVariables\n // The fields the sync writes, and the ones it binds anew, which keep an equal value only in\n // the component's mode.\n const rebound = updates.boundVariables\n ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field])\n : []\n const synced = uniq([...Object.keys(updates), ...rebound]).filter(\n (field) => isNumericVariableBindingField(field) && bound[field] && !kept(field)\n )\n if (synced.length === 0) return\n applySyncedModes(graph, target, updates)\n const resolved = resolvedNumericBindings(graph, { ...target, ...updates }, 'active', resolver)\n Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))\n}\n\n/** The modes the copy takes in this sync decide what its bindings resolve to. */\nfunction applySyncedModes(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void {\n if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))\n graph.updateNode(target.id, { variableModes: updates.variableModes })\n}\n\n/**\n * Strokes a sync or swap gives a copy draw with the copy's own line fields: the weight,\n * alignment, cap, join, or dash it overrides, and a bound weight resolved in its modes. Figma\n * keeps a stroke weight override when the component's color changes (live).\n */\nexport function applySyncedStrokeLines(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean,\n resolver: VariableResolver = createVariableResolver(graph)\n): void {\n const strokes = updates.strokes\n const first = strokes?.at(0)\n if (!strokes || !first) return\n const boundWeight = kept('strokeWeight')\n ? undefined\n : (updates.boundVariables ?? target.boundVariables).strokeWeight\n const weightScale =\n (updates.variableBindingScales ?? target.variableBindingScales).strokeWeight ?? 1\n const resolvedWeight = boundWeight\n ? resolver.forNode(target.id, 'active').number(boundWeight)\n : undefined\n const lines: StrokeLines = {}\n let set = false\n for (const key of STROKE_LINE_KEYS) {\n const field = STROKE_LINE_FIELDS[key]\n const own = kept(field)\n // A bound weight takes the value it resolves to where the copy sits, not its component's.\n const synced = own ? target[field] : updates[field]\n const value =\n field === 'strokeWeight' && resolvedWeight !== undefined\n ? resolvedWeight * weightScale\n : synced\n if (value === undefined) continue\n // A field the copy overrides holds for every stroke; the component's own values keep its\n // strokes' differences unless a binding resolved the first one apart.\n const differs = own\n ? strokes.some((stroke) => !isEqual(value, strokeLine(stroke, key)))\n : !isEqual(value, strokeLine(first, key))\n if (!differs) continue\n Reflect.set(lines, key, value)\n set = true\n }\n if (set) updates.strokes = withStrokeLines(strokes, lines)\n}\n\nfunction cloneChildInCoordinates(\n graph: SceneGraph,\n src: SceneNode,\n sourceParent: SceneNode,\n targetParent: SceneNode,\n mode: NodeCloneMode = 'deep'\n): SceneNode {\n const componentScale =\n (src.componentScale * targetParent.componentScale) / sourceParent.componentScale\n const clone = graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\n copyAppliedBoundPaints(src, clone)\n return clone\n}\n\nexport function cloneChildrenWithMapping(\n graph: SceneGraph,\n sourceParentId: string,\n destParentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n // A cyclic component, such as an instance of an ancestor, would clone itself without end.\n if (sourceParentId === destParentId || graph.isDescendant(destParentId, sourceParentId)) return\n\n const sourceParent = graph.nodes.get(sourceParentId)\n const targetParent = graph.nodes.get(destParentId)\n if (!sourceParent || !targetParent) return\n\n for (const childId of sourceParent.childIds) {\n const src = graph.nodes.get(childId)\n if (!src) continue\n\n const clone = cloneChildInCoordinates(graph, src, sourceParent, targetParent, mode)\n\n if (src.childIds.length > 0) {\n cloneChildrenWithMapping(graph, childId, clone.id, mode)\n }\n }\n}\n\nexport function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {\n const fields: Set<string>[] = []\n let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (parent) {\n if (parent.type === 'INSTANCE') {\n fields.push(new Set(parent.instanceOverrides.descendants.get(node.id)?.keys()))\n }\n parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined\n }\n return fields\n}\n\nfunction childBindingProtection(\n graph: SceneGraph,\n child: SceneNode,\n overrides: InstanceOverrideState\n) {\n const fields = enclosingInstanceOverrideFields(graph, child)\n fields.push(new Set(overrides.descendants.get(child.id)?.keys()))\n const protectedField = bindingProtection(fields)\n return (field: string) => protectedField(field) || ownsSelfFillField(child, field)\n}\n\n/** Links a copy to the component layer it matched, reporting each changed node and its owner. */\nfunction linkMatchedChild(\n graph: SceneGraph,\n context: InstanceSyncContext,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n const { overrides } = context\n const recorded = hasNodeInstanceOverride(\n overrides,\n instParentId,\n instChild.id,\n 'sourceComponentId'\n )\n if (instChild.type === 'INSTANCE' || recorded) {\n const owner = graph.nodes.get(context.instanceId)\n graph.willChangeNode(owner)\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n if (owner) graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n }\n if (instChild.type !== 'INSTANCE') graph.updateNode(instChild.id, { componentId: compChildId })\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n context: InstanceSyncContext,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()\n const remainingCandidateCount = new Map<SceneNode['type'], number>()\n const unmatchedComponentCount = new Map<SceneNode['type'], number>()\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const child = graph.nodes.get(compChildId)\n if (child) {\n unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)\n }\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || usedInstChildIds.has(child.id)) continue\n remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)\n let byName = fallbackByType.get(child.type)\n if (!byName) {\n byName = new Map()\n fallbackByType.set(child.type, byName)\n }\n const queue = byName.get(child.name)\n if (queue) queue.push(child)\n else byName.set(child.name, [child])\n }\n\n // Match by name and type with FIFO queues to preserve sibling order in linear time.\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const compChild = graph.nodes.get(compChildId)\n if (!compChild) continue\n const candidatesByName = fallbackByType.get(compChild.type)\n const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0\n if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue\n const match = candidatesByName?.get(compChild.name)?.shift()\n if (!match) continue\n remainingCandidateCount.set(compChild.type, candidateCount - 1)\n instChildMap.set(compChildId, match)\n usedInstChildIds.add(match.id)\n linkMatchedChild(graph, context, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState,\n matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n // The first copy of a layer keeps it; a duplicate stays unmatched for the sync to remove.\n if (instChildMap.has(mappedComponentId)) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n applyBoundPaintColorsIn(graph, clone.id)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n context,\n instChildMap,\n usedInstChildIds\n )\n\n placeMissingChildren(graph, compParent, instParent, instChildMap, usedInstChildIds, context)\n\n // Pass 4: Synchronize properties and recurse\n for (const compChildId of compParent.childIds) {\n const compChild = graph.nodes.get(compChildId)\n const instChild = instChildMap.get(compChildId)\n if (!compChild || !instChild) continue\n // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept = (key: string) =>\n driven.has(key) || isProtectedSyncField(instChild, key, protectedField)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: kept\n })\n Object.assign(updates, assignedFieldValues(graph, instChild, compChild))\n keepOwnContentSize(graph, updates, instChild, source, placement)\n updateSyncedProps(graph, instChild, updates, kept)\n\n if (\n compChild.childIds.length > 0 &&\n !hasNodeInstanceOverride(overrides, instParentId, instChild.id, 'componentId') &&\n // The component's frame is the authority on which slot this is; instance copies of\n // its bindings are not synced.\n !ownsSlotContent(graph, instChild, slotPropertyId(compChild))\n ) {\n syncChildren(graph, compChildId, instChild.id, overrides, context)\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO,OAAO;AAChB;AAEA,SAAgB,SACd,QACA,QACA,KACM;CACN,IAAI,QAAQ,SAC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
|
import { normalizeEffects } from "./effects.js";
|
|
3
|
+
import { EMPTY_INSTANCE_OVERRIDES } from "./instances/overrides.js";
|
|
3
4
|
import { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from "./empty-values.js";
|
|
4
|
-
import { createInstanceOverrideState } from "./instances/overrides.js";
|
|
5
5
|
import { NO_LETTER_SPACING } from "./text/lengths.js";
|
|
6
6
|
//#region src/node-defaults.ts
|
|
7
7
|
function createDefaultSourceMetadata() {
|
|
@@ -205,7 +205,7 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
205
205
|
shapeUserHeight: 0,
|
|
206
206
|
shapeTruncates: false,
|
|
207
207
|
componentId: null,
|
|
208
|
-
instanceOverrides:
|
|
208
|
+
instanceOverrides: EMPTY_INSTANCE_OVERRIDES,
|
|
209
209
|
componentPropertyDefinitions: EMPTY_LIST,
|
|
210
210
|
componentPropertyReferences: EMPTY_LIST,
|
|
211
211
|
componentPropertyAssignments: EMPTY_RECORD,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from './empty-values'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: EMPTY_LIST,\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: EMPTY_RECORD,\n layout: null,\n symbolOverrides: EMPTY_LIST,\n componentPropAssignments: EMPTY_LIST,\n derivedSymbolData: EMPTY_LIST,\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n },\n drawio: null\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/**\n * The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words\n * of a compound type apart, so a shape with text is a \"Shape with text\".\n */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\n/**\n * The name Figma gives a layer that follows its text: the characters trimmed, on one line, and\n * the type's own name while they hold nothing.\n */\nexport function textLayerName(type: NodeType, text: string): string {\n const lines = text\n .split(/\\r\\n|\\r|\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '')\n return lines.join(' ') || defaultNodeName(type)\n}\n\n/**\n * The fields auto layout sets on the frame that holds it, with the value each holds when no frame\n * lays anything out. A page holds layers; it is not one, so none of these apply to it and a page\n * that took them would place its layers by a container nobody can see.\n */\nexport const FRAME_LAYOUT_DEFAULTS = {\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0\n} as const satisfies Partial<SceneNode>\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n const defaults = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT'\n ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }]\n : EMPTY_LIST,\n strokes: EMPTY_LIST,\n effects: EMPTY_LIST,\n layoutGrids: EMPTY_LIST,\n guides: EMPTY_LIST,\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n overflowDirection: 'NONE',\n scrollBehavior: 'SCROLLS',\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n ...FRAME_LAYOUT_DEFAULTS,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: EMPTY_LIST,\n strokeGeometry: EMPTY_LIST,\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: EMPTY_LIST,\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: EMPTY_LIST,\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: EMPTY_LIST,\n fontVariations: EMPTY_LIST,\n opticalSizeFromFontSize: true,\n fontFeatures: EMPTY_LIST,\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: EMPTY_LIST,\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: EMPTY_LIST,\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: EMPTY_LIST,\n gridTemplateRows: EMPTY_LIST,\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: EMPTY_LIST,\n componentPropertyReferences: EMPTY_LIST,\n componentPropertyAssignments: EMPTY_RECORD,\n componentPropertyValues: EMPTY_RECORD,\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: EMPTY_LIST,\n variantPropSpecs: EMPTY_LIST,\n boundVariables: EMPTY_RECORD,\n variableBindingScales: EMPTY_RECORD,\n variableAssignmentScales: EMPTY_RECORD,\n componentScale: 1,\n variableModes: EMPTY_RECORD,\n exportSettings: EMPTY_LIST,\n status: null,\n pluginData: EMPTY_LIST,\n pluginRelaunchData: EMPTY_LIST,\n prototypeReactions: EMPTY_LIST,\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n const node: SceneNode = { ...defaults, ...overrides }\n node.effects = normalizeEffects(node.effects)\n shareEmptyNodeValues(node, Object.keys(overrides))\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'IN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;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from './empty-values'\nimport { EMPTY_INSTANCE_OVERRIDES } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: EMPTY_LIST,\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: EMPTY_RECORD,\n layout: null,\n symbolOverrides: EMPTY_LIST,\n componentPropAssignments: EMPTY_LIST,\n derivedSymbolData: EMPTY_LIST,\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n },\n drawio: null\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/**\n * The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words\n * of a compound type apart, so a shape with text is a \"Shape with text\".\n */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\n/**\n * The name Figma gives a layer that follows its text: the characters trimmed, on one line, and\n * the type's own name while they hold nothing.\n */\nexport function textLayerName(type: NodeType, text: string): string {\n const lines = text\n .split(/\\r\\n|\\r|\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '')\n return lines.join(' ') || defaultNodeName(type)\n}\n\n/**\n * The fields auto layout sets on the frame that holds it, with the value each holds when no frame\n * lays anything out. A page holds layers; it is not one, so none of these apply to it and a page\n * that took them would place its layers by a container nobody can see.\n */\nexport const FRAME_LAYOUT_DEFAULTS = {\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0\n} as const satisfies Partial<SceneNode>\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n const defaults = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT'\n ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }]\n : EMPTY_LIST,\n strokes: EMPTY_LIST,\n effects: EMPTY_LIST,\n layoutGrids: EMPTY_LIST,\n guides: EMPTY_LIST,\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n overflowDirection: 'NONE',\n scrollBehavior: 'SCROLLS',\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n ...FRAME_LAYOUT_DEFAULTS,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: EMPTY_LIST,\n strokeGeometry: EMPTY_LIST,\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: EMPTY_LIST,\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: EMPTY_LIST,\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: EMPTY_LIST,\n fontVariations: EMPTY_LIST,\n opticalSizeFromFontSize: true,\n fontFeatures: EMPTY_LIST,\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: EMPTY_LIST,\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: EMPTY_LIST,\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: EMPTY_LIST,\n gridTemplateRows: EMPTY_LIST,\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: EMPTY_INSTANCE_OVERRIDES,\n componentPropertyDefinitions: EMPTY_LIST,\n componentPropertyReferences: EMPTY_LIST,\n componentPropertyAssignments: EMPTY_RECORD,\n componentPropertyValues: EMPTY_RECORD,\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: EMPTY_LIST,\n variantPropSpecs: EMPTY_LIST,\n boundVariables: EMPTY_RECORD,\n variableBindingScales: EMPTY_RECORD,\n variableAssignmentScales: EMPTY_RECORD,\n componentScale: 1,\n variableModes: EMPTY_RECORD,\n exportSettings: EMPTY_LIST,\n status: null,\n pluginData: EMPTY_LIST,\n pluginRelaunchData: EMPTY_LIST,\n prototypeReactions: EMPTY_LIST,\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n const node: SceneNode = { ...defaults, ...overrides }\n node.effects = normalizeEffects(node.effects)\n shareEmptyNodeValues(node, Object.keys(overrides))\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;;;AAYA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc;EACd,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe;GACf,QAAQ;GACR,iBAAiB;GACjB,0BAA0B;GAC1B,mBAAmB;GACnB,gCAAgC;GAChC,oBAAoB;EACtB;EACA,QAAQ;CACV;AACF;;AAUA,SAAgB,mBAAmB,MAA0C;CAC3E,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO;CACjD,OAAO,SAAS,SAAS,YAAY;AACvC;;;;;AAMA,SAAgB,kBACd,MACwD;CACxD,MAAM,QAAQ,KAAK,QAAQ,GAAG,CAAC;CAC/B,OAAO;EAAE,QAAQ,OAAO,UAAU,KAAK;EAAc,OAAO,OAAO,SAAS,KAAK;CAAY;AAC/F;;;;;AAMA,SAAgB,gBAAgB,MAAwB;CACtD,MAAM,Q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AAe;EACf,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,uBAAuB;EACvB,0BAA0B;EAC1B,gBAAgB;EAChB,eAAe;EACf,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ,oBAAoB;EACpB,oBAAoB;EACpB,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAEmB,GAAG;CAAU;CACpD,KAAK,UAAU,iBAAiB,KAAK,OAAO;CAC5C,qBAAqB,MAAM,OAAO,KAAK,SAAS,CAAC;CACjD,OAAO;AACT;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -61,6 +61,14 @@ declare const PAIRDRAW_PLUGIN_DATA: {
|
|
|
61
61
|
textPathBox: PluginDataField<Rect>;
|
|
62
62
|
/** The library asset a node was inserted from. */
|
|
63
63
|
librarySource: PluginDataField<LibraryAssetSource>;
|
|
64
|
+
/**
|
|
65
|
+
* Where a layer of a pasted component came from: the copying document's root id and the node's id
|
|
66
|
+
* there. A later paste of the same snapshot into that document reuses the component it made.
|
|
67
|
+
*/
|
|
68
|
+
clipboardOrigin: PluginDataField<{
|
|
69
|
+
documentId: string;
|
|
70
|
+
nodeId: string;
|
|
71
|
+
}>;
|
|
64
72
|
/**
|
|
65
73
|
* The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the
|
|
66
74
|
* root keeps it across a save as every layer keeps its GUID.
|
|
@@ -70,6 +78,13 @@ declare const PAIRDRAW_PLUGIN_DATA: {
|
|
|
70
78
|
enabledLibraries: PluginDataField<EnabledLibraryBinding[]>;
|
|
71
79
|
/** The library this document publishes as, on the DOCUMENT node. */
|
|
72
80
|
sourceLibraryPublication: PluginDataField<SourceLibraryPublication>;
|
|
81
|
+
/**
|
|
82
|
+
* The `.pen` documents this document imports, by alias and relative path, on the DOCUMENT node.
|
|
83
|
+
* A `.pen` file names them in its own `imports`, so a save writes them back from here.
|
|
84
|
+
*/
|
|
85
|
+
penImports: PluginDataField<{
|
|
86
|
+
[x: string]: string;
|
|
87
|
+
}>;
|
|
73
88
|
/** Canvas comment threads, deleted ones included, on the DOCUMENT node. */
|
|
74
89
|
comments: PluginDataField<CommentThread[]>;
|
|
75
90
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;;;;;;UAyGiB;EACf;EACA;;;UAWe;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;UA0B7B;EACf;EACA;EACA;EACA;EACA;IAAU,UAAU;IAAQ,OAAO;;;;;;;;cAoCxB;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoHG,kBAAkB,kBAAkB,oBAAoB"}
|
|
@@ -14,7 +14,7 @@ import { nodeStatusSchema, statusWorkflowSchema } from "../statuses/schema.js";
|
|
|
14
14
|
import { tokenSourcesSchema } from "../token-sources/schema.js";
|
|
15
15
|
import { MODE_ATTRIBUTE_PATTERN, TOKEN_UNITS } from "../types.js";
|
|
16
16
|
import { variationSetSchema, variationStandInSchema } from "../variations/schema.js";
|
|
17
|
-
import { webCitationSchema } from "./schema.js";
|
|
17
|
+
import { enabledLibrariesSchema, sourceLibraryPublicationSchema, webCitationSchema } from "./schema.js";
|
|
18
18
|
import * as v from "valibot";
|
|
19
19
|
//#region src/plugin-data/fields.ts
|
|
20
20
|
const DIRECTIONS = [
|
|
@@ -40,6 +40,10 @@ const exportSettingsSchema = v.array(v.pipe(v.object({
|
|
|
40
40
|
format,
|
|
41
41
|
...quality === void 0 ? {} : { quality: clampExportQuality(quality) }
|
|
42
42
|
}))));
|
|
43
|
+
const clipboardOriginSchema = v.object({
|
|
44
|
+
documentId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),
|
|
45
|
+
nodeId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))
|
|
46
|
+
});
|
|
43
47
|
const librarySourceSchema = v.pipe(v.object({
|
|
44
48
|
identity: v.object({
|
|
45
49
|
libraryId: v.string(),
|
|
@@ -53,22 +57,6 @@ const librarySourceSchema = v.pipe(v.object({
|
|
|
53
57
|
sourceNodeId: typeof sourceNodeId === "string" ? sourceNodeId : null,
|
|
54
58
|
readOnly: readOnly === true
|
|
55
59
|
})));
|
|
56
|
-
const enabledLibrarySchema = v.object({
|
|
57
|
-
libraryId: v.string(),
|
|
58
|
-
revisionId: v.string(),
|
|
59
|
-
enabled: v.optional(v.unknown())
|
|
60
|
-
});
|
|
61
|
-
/** Invalid entries are skipped one by one, so one bad binding keeps the others. */
|
|
62
|
-
const enabledLibrariesSchema = v.pipe(v.array(v.unknown()), v.transform((items) => items.flatMap((item) => {
|
|
63
|
-
const parsed = v.safeParse(enabledLibrarySchema, item);
|
|
64
|
-
if (!parsed.success) return [];
|
|
65
|
-
const { libraryId, revisionId, enabled } = parsed.output;
|
|
66
|
-
return [{
|
|
67
|
-
libraryId,
|
|
68
|
-
revisionId,
|
|
69
|
-
enabled: enabled === true
|
|
70
|
-
}];
|
|
71
|
-
})));
|
|
72
60
|
const cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1e3));
|
|
73
61
|
const replacedLayersSchema = v.array(v.object({
|
|
74
62
|
path: v.pipe(v.array(v.pipe(v.string(), v.regex(/^\d+:\d+$/))), v.minLength(1)),
|
|
@@ -123,12 +111,6 @@ const meshFillsSchema = v.pipe(v.array(v.unknown()), v.transform((items) => item
|
|
|
123
111
|
points
|
|
124
112
|
}];
|
|
125
113
|
})));
|
|
126
|
-
const sourceLibraryPublicationSchema = v.object({
|
|
127
|
-
libraryId: v.string(),
|
|
128
|
-
revisionId: v.string(),
|
|
129
|
-
name: v.string(),
|
|
130
|
-
catalogSource: v.optional(v.string())
|
|
131
|
-
});
|
|
132
114
|
/**
|
|
133
115
|
* Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's
|
|
134
116
|
* format has no field for. Add a key here, never as a string elsewhere, so reading and writing
|
|
@@ -156,6 +138,11 @@ const PAIRDRAW_PLUGIN_DATA = {
|
|
|
156
138
|
/** The library asset a node was inserted from. */
|
|
157
139
|
librarySource: jsonPluginDataField("librarySource", "bookkeeping", librarySourceSchema),
|
|
158
140
|
/**
|
|
141
|
+
* Where a layer of a pasted component came from: the copying document's root id and the node's id
|
|
142
|
+
* there. A later paste of the same snapshot into that document reuses the component it made.
|
|
143
|
+
*/
|
|
144
|
+
clipboardOrigin: jsonPluginDataField("clipboardOrigin", "bookkeeping", clipboardOriginSchema),
|
|
145
|
+
/**
|
|
159
146
|
* The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the
|
|
160
147
|
* root keeps it across a save as every layer keeps its GUID.
|
|
161
148
|
*/
|
|
@@ -164,6 +151,11 @@ const PAIRDRAW_PLUGIN_DATA = {
|
|
|
164
151
|
enabledLibraries: jsonPluginDataField("enabledLibraries", "bookkeeping", enabledLibrariesSchema),
|
|
165
152
|
/** The library this document publishes as, on the DOCUMENT node. */
|
|
166
153
|
sourceLibraryPublication: jsonPluginDataField("sourceLibraryPublication", "bookkeeping", sourceLibraryPublicationSchema),
|
|
154
|
+
/**
|
|
155
|
+
* The `.pen` documents this document imports, by alias and relative path, on the DOCUMENT node.
|
|
156
|
+
* A `.pen` file names them in its own `imports`, so a save writes them back from here.
|
|
157
|
+
*/
|
|
158
|
+
penImports: jsonPluginDataField("penImports", "bookkeeping", v.record(v.string(), v.string())),
|
|
167
159
|
/** Canvas comment threads, deleted ones included, on the DOCUMENT node. */
|
|
168
160
|
comments: jsonPluginDataField("comments", "bookkeeping", commentThreadsSchema),
|
|
169
161
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { agentNotesSchema } from '../agent-notes/schema'\nimport { behaviourSchema } from '../behaviours/schema'\nimport { browserNodeSchema } from '../browser-node/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { designMemorySchema } from '../design-memory/schema'\nimport { clampExportQuality, isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Color, Rect, Vector } from '../primitives'\nimport { scriptNodeSchema } from '../script/schema'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport { tokenSourcesSchema } from '../token-sources/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport { variationSetSchema, variationStandInSchema } from '../variations/schema'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\nimport { webCitationSchema } from './schema'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n quality: v.optional(v.pipe(v.number(), v.finite()))\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform(({ scale, format, quality }) => ({\n scale: clampExportScale(scale),\n format,\n ...(quality === undefined ? {} : { quality: clampExportQuality(quality) })\n }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/**\n * A layer an instance shows in place of one of its component's layers, which Figma has no\n * override for: the GUID path of the component layer it replaces, as an override's `guidPath`\n * spells it, and the replacement's own records as a Base64 Kiwi `NODE_CHANGES` message.\n */\nexport interface StoredReplacedLayer {\n path: string[]\n records: string\n}\n\nconst replacedLayersSchema: v.GenericSchema<unknown, StoredReplacedLayer[]> = v.array(\n v.object({\n path: v.pipe(v.array(v.pipe(v.string(), v.regex(/^\\d+:\\d+$/))), v.minLength(1)),\n records: v.pipe(v.string(), v.nonEmpty())\n })\n)\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\n/** A mesh paint Figma's format has no type for, stored beside its solid fallback paint. */\nexport interface StoredMeshFill {\n kind: 'fill' | 'stroke'\n index: number\n columns: number\n rows: number\n points: { position: Vector; color: Color }[]\n}\n\n/** Invalid entries are skipped one by one, so one bad mesh keeps the others. */\nconst meshFillsSchema: v.GenericSchema<unknown, StoredMeshFill[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(\n v.object({\n kind: v.picklist(['fill', 'stroke']),\n index: v.pipe(v.number(), v.integer(), v.minValue(0)),\n columns: v.pipe(v.number(), v.integer(), v.minValue(1)),\n rows: v.pipe(v.number(), v.integer(), v.minValue(1)),\n points: v.array(\n v.object({\n position: v.object({ x: v.number(), y: v.number() }),\n color: v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })\n })\n )\n }),\n item\n )\n if (!parsed.success) return []\n const { kind, index, columns, rows, points } = parsed.output\n if (points.length !== (columns + 1) * (rows + 1)) return []\n return [{ kind, index, columns, rows, points }]\n })\n )\n)\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const PAIRDRAW_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /**\n * A primary axis alignment Figma has no mode for, on auto-layout frames; the record keeps\n * Figma's space between, and a frame whose record says otherwise was changed in Figma.\n */\n primaryAxisAlign: textPluginDataField('primaryAxisAlign', 'format', ['SPACE_AROUND']),\n /** Marks a component set Figma would read as a plain frame, and a script node Figma has no type for. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET', 'SCRIPT']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** Layers an instance shows in place of its component's, on the instance's own record. */\n replacedLayers: jsonPluginDataField('replacedLayers', 'format', replacedLayersSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** The code the document's variables are linked to, on the DOCUMENT node. */\n tokenSources: jsonPluginDataField('tokenSources', 'bookkeeping', tokenSourcesSchema),\n /** The design rules agents follow in the document, on the DOCUMENT node. */\n designMemory: jsonPluginDataField('designMemory', 'bookkeeping', designMemorySchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema),\n /** A script node's source and its `@input` values, on the SCRIPT node. */\n script: jsonPluginDataField('script', 'content', scriptNodeSchema),\n /** One entry per mesh paint, beside the solid fallback its record carries. */\n meshFills: jsonPluginDataField('meshFills', 'format', meshFillsSchema),\n /** Notes a person left on a layer for agents: what it means or does, and a request about it. */\n agentNotes: jsonPluginDataField('agentNotes', 'content', agentNotesSchema),\n /** A page a sticky cites: its URL, title, quote, and the time the page was read. */\n webCitation: jsonPluginDataField('webCitation', 'content', webCitationSchema),\n /**\n * A snapshot of one page: its address, viewport, and when it was refreshed. The picture is\n * the layer's image fill. An address that is not an http or https page does not decode.\n */\n browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema),\n /**\n * On a section, that its children are variations of another layer: which one, and how that\n * layer looked when they were made. A copy of the section is an ordinary section.\n */\n variationSet: jsonPluginDataField('variationSet', 'bookkeeping', variationSetSchema),\n /**\n * On a layer of a version, the main component or component set of the original it stands in\n * for, so a pick keeps that component rather than pairing it by name.\n */\n variationStandIn: jsonPluginDataField('variationStandIn', 'bookkeeping', variationStandInSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')\n\n/**\n * A node's plugin data that is part of its content, in a stable order: Pairdraw's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,UAAqC,OAAO,MAAM,OAAO,QAC5D,CACF,CACF,CACF;;AAGA,MAAM,uBAAkE,EAAE,MACxE,EAAE,KACA,EAAE,OAAO;CACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACpC,QAAQ,EAAE,OAAuB,gBAAg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AO,OAAO,oBAAoB,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,SAAS;;;;;;AAOlG,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { agentNotesSchema } from '../agent-notes/schema'\nimport { behaviourSchema } from '../behaviours/schema'\nimport { browserNodeSchema } from '../browser-node/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { designMemorySchema } from '../design-memory/schema'\nimport { clampExportQuality, isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Color, Rect, Vector } from '../primitives'\nimport { scriptNodeSchema } from '../script/schema'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport { tokenSourcesSchema } from '../token-sources/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport { variationSetSchema, variationStandInSchema } from '../variations/schema'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\nimport { enabledLibrariesSchema, sourceLibraryPublicationSchema, webCitationSchema } from './schema'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n quality: v.optional(v.pipe(v.number(), v.finite()))\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform(({ scale, format, quality }) => ({\n scale: clampExportScale(scale),\n format,\n ...(quality === undefined ? {} : { quality: clampExportQuality(quality) })\n }))\n )\n)\n\nconst clipboardOriginSchema = v.object({\n documentId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),\n nodeId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n})\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/**\n * A layer an instance shows in place of one of its component's layers, which Figma has no\n * override for: the GUID path of the component layer it replaces, as an override's `guidPath`\n * spells it, and the replacement's own records as a Base64 Kiwi `NODE_CHANGES` message.\n */\nexport interface StoredReplacedLayer {\n path: string[]\n records: string\n}\n\nconst replacedLayersSchema: v.GenericSchema<unknown, StoredReplacedLayer[]> = v.array(\n v.object({\n path: v.pipe(v.array(v.pipe(v.string(), v.regex(/^\\d+:\\d+$/))), v.minLength(1)),\n records: v.pipe(v.string(), v.nonEmpty())\n })\n)\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\n/** A mesh paint Figma's format has no type for, stored beside its solid fallback paint. */\nexport interface StoredMeshFill {\n kind: 'fill' | 'stroke'\n index: number\n columns: number\n rows: number\n points: { position: Vector; color: Color }[]\n}\n\n/** Invalid entries are skipped one by one, so one bad mesh keeps the others. */\nconst meshFillsSchema: v.GenericSchema<unknown, StoredMeshFill[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(\n v.object({\n kind: v.picklist(['fill', 'stroke']),\n index: v.pipe(v.number(), v.integer(), v.minValue(0)),\n columns: v.pipe(v.number(), v.integer(), v.minValue(1)),\n rows: v.pipe(v.number(), v.integer(), v.minValue(1)),\n points: v.array(\n v.object({\n position: v.object({ x: v.number(), y: v.number() }),\n color: v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })\n })\n )\n }),\n item\n )\n if (!parsed.success) return []\n const { kind, index, columns, rows, points } = parsed.output\n if (points.length !== (columns + 1) * (rows + 1)) return []\n return [{ kind, index, columns, rows, points }]\n })\n )\n)\n\n/**\n * Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const PAIRDRAW_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /**\n * A primary axis alignment Figma has no mode for, on auto-layout frames; the record keeps\n * Figma's space between, and a frame whose record says otherwise was changed in Figma.\n */\n primaryAxisAlign: textPluginDataField('primaryAxisAlign', 'format', ['SPACE_AROUND']),\n /** Marks a component set Figma would read as a plain frame, and a script node Figma has no type for. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET', 'SCRIPT']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** Layers an instance shows in place of its component's, on the instance's own record. */\n replacedLayers: jsonPluginDataField('replacedLayers', 'format', replacedLayersSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /**\n * Where a layer of a pasted component came from: the copying document's root id and the node's id\n * there. A later paste of the same snapshot into that document reuses the component it made.\n */\n clipboardOrigin: jsonPluginDataField('clipboardOrigin', 'bookkeeping', clipboardOriginSchema),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /**\n * The `.pen` documents this document imports, by alias and relative path, on the DOCUMENT node.\n * A `.pen` file names them in its own `imports`, so a save writes them back from here.\n */\n penImports: jsonPluginDataField('penImports', 'bookkeeping', v.record(v.string(), v.string())),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** The code the document's variables are linked to, on the DOCUMENT node. */\n tokenSources: jsonPluginDataField('tokenSources', 'bookkeeping', tokenSourcesSchema),\n /** The design rules agents follow in the document, on the DOCUMENT node. */\n designMemory: jsonPluginDataField('designMemory', 'bookkeeping', designMemorySchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema),\n /** A script node's source and its `@input` values, on the SCRIPT node. */\n script: jsonPluginDataField('script', 'content', scriptNodeSchema),\n /** One entry per mesh paint, beside the solid fallback its record carries. */\n meshFills: jsonPluginDataField('meshFills', 'format', meshFillsSchema),\n /** Notes a person left on a layer for agents: what it means or does, and a request about it. */\n agentNotes: jsonPluginDataField('agentNotes', 'content', agentNotesSchema),\n /** A page a sticky cites: its URL, title, quote, and the time the page was read. */\n webCitation: jsonPluginDataField('webCitation', 'content', webCitationSchema),\n /**\n * A snapshot of one page: its address, viewport, and when it was refreshed. The picture is\n * the layer's image fill. An address that is not an http or https page does not decode.\n */\n browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema),\n /**\n * On a section, that its children are variations of another layer: which one, and how that\n * layer looked when they were made. A copy of the section is an ordinary section.\n */\n variationSet: jsonPluginDataField('variationSet', 'bookkeeping', variationSetSchema),\n /**\n * On a layer of a version, the main component or component set of the original it stands in\n * for, so a pick keeps that component rather than pairing it by name.\n */\n variationStandIn: jsonPluginDataField('variationStandIn', 'bookkeeping', variationStandInSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')\n\n/**\n * A node's plugin data that is part of its content, in a stable order: Pairdraw's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,UAAqC,OAAO,MAAM,OAAO,QAC5D,CACF,CACF,CACF;;AAGA,MAAM,uBAAkE,EAAE,MACxE,EAAE,KACA,EAAE,OAAO;CACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACpC,QAAQ,EAAE,OAAuB,gBAAgB;CACjD,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC,GAED,EAAE,WAAW,EAAE,OAAO,QAAQ,eAAe;CAC3C,OAAO,iBAAiB,KAAK;CAC7B;CACA,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,mBAAmB,OAAO,EAAE;AAC1E,EAAE,CACJ,CACF;AAEA,MAAM,wBAAwB,EAAE,OAAO;CACrC,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,EAA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O,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,GAAG,EAAE,MAAM,sBAAsB,CAAC,CAChF;;CAEA,OAAO,oBAAoB,SAAS,WAAW,WAAW;;CAE1D,WAAW,oBAAoB,aAAa,WAAW,eAAe;;CAEtE,MAAM,oBAAoB,QAAQ,WAAW,UAAU;;CAEvD,UAAU,oBAAoB,YAAY,WAAW,cAAc;;CAEnE,QAAQ,oBAAoB,UAAU,WAAW,iBAAiB;;CAElE,QAAQ,oBAAoB,UAAU,WAAW,gBAAgB;;CAEjE,WAAW,oBAAoB,aAAa,UAAU,eAAe;;CAErE,YAAY,oBAAoB,cAAc,WAAW,gBAAgB;;CAEzE,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;;;;;CAK5E,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;;;;;CAK5E,cAAc,oBAAoB,gBAAgB,eAAe,kBAAkB;;;;;CAKnF,kBAAkB,oBAAoB,oBAAoB,eAAe,sBAAsB;AACjG;AAEA,MAAM,cAAc,OAAO,OAAO,oBAAoB,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,SAAS;;;;;;AAOlG,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PAIRDRAW_PLUGIN_ID, PluginDataField, PluginDataKey, PluginDataRole, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, textPluginDataField, withAllPluginData, withPluginData, withoutPluginData } from "./field.js";
|
|
2
2
|
import { PAIRDRAW_PLUGIN_DATA, StoredMeshFill, StoredReplacedLayer, StoredToken, contentPluginData } from "./fields.js";
|
|
3
|
-
import { CITATION_QUOTE_LIMIT, WebCitation } from "./schema.js";
|
|
3
|
+
import { CITATION_QUOTE_LIMIT, WebCitation, enabledLibrariesSchema, sourceLibraryPublicationSchema } from "./schema.js";
|
|
4
4
|
import { readWebCitation, withWebCitation } from "./citation.js";
|
|
5
|
-
export { CITATION_QUOTE_LIMIT, PAIRDRAW_PLUGIN_DATA, PAIRDRAW_PLUGIN_ID, PluginDataField, PluginDataKey, PluginDataRole, StoredMeshFill, StoredReplacedLayer, StoredToken, type WebCitation, contentPluginData, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, readWebCitation, textPluginDataField, withAllPluginData, withPluginData, withWebCitation, withoutPluginData };
|
|
5
|
+
export { CITATION_QUOTE_LIMIT, PAIRDRAW_PLUGIN_DATA, PAIRDRAW_PLUGIN_ID, PluginDataField, PluginDataKey, PluginDataRole, StoredMeshFill, StoredReplacedLayer, StoredToken, type WebCitation, contentPluginData, enabledLibrariesSchema, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, readWebCitation, sourceLibraryPublicationSchema, textPluginDataField, withAllPluginData, withPluginData, withWebCitation, withoutPluginData };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PAIRDRAW_PLUGIN_ID, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, textPluginDataField, withAllPluginData, withPluginData, withoutPluginData } from "./field.js";
|
|
2
|
-
import { CITATION_QUOTE_LIMIT } from "./schema.js";
|
|
2
|
+
import { CITATION_QUOTE_LIMIT, enabledLibrariesSchema, sourceLibraryPublicationSchema } from "./schema.js";
|
|
3
3
|
import { PAIRDRAW_PLUGIN_DATA, contentPluginData } from "./fields.js";
|
|
4
4
|
import { readWebCitation, withWebCitation } from "./citation.js";
|
|
5
|
-
export { CITATION_QUOTE_LIMIT, PAIRDRAW_PLUGIN_DATA, PAIRDRAW_PLUGIN_ID, contentPluginData, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, readWebCitation, textPluginDataField, withAllPluginData, withPluginData, withWebCitation, withoutPluginData };
|
|
5
|
+
export { CITATION_QUOTE_LIMIT, PAIRDRAW_PLUGIN_DATA, PAIRDRAW_PLUGIN_ID, contentPluginData, enabledLibrariesSchema, hasPluginData, isPluginDataEntry, jsonPluginDataField, pluginDataEntry, readAllPluginData, readPluginData, readWebCitation, sourceLibraryPublicationSchema, textPluginDataField, withAllPluginData, withPluginData, withWebCitation, withoutPluginData };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EnabledLibraryBinding, SourceLibraryPublication } from "../types.js";
|
|
1
2
|
import * as v from "valibot";
|
|
2
3
|
//#region src/plugin-data/schema.d.ts
|
|
3
4
|
/** A quote kept on a sticky. A longer passage is cut before it is stored. */
|
|
@@ -13,6 +14,10 @@ declare const webCitationSchema: v.ObjectSchema<{
|
|
|
13
14
|
readonly readAt: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>;
|
|
14
15
|
}, undefined>;
|
|
15
16
|
type WebCitation = v.InferOutput<typeof webCitationSchema>;
|
|
17
|
+
/** One library a document switched on; invalid entries are skipped one by one. */
|
|
18
|
+
declare const enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]>;
|
|
19
|
+
/** The library a document publishes as: its identity, its revision, and where it was published. */
|
|
20
|
+
declare const sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication>;
|
|
16
21
|
//#endregion
|
|
17
|
-
export { CITATION_QUOTE_LIMIT, WebCitation, webCitationSchema };
|
|
22
|
+
export { CITATION_QUOTE_LIMIT, WebCitation, enabledLibrariesSchema, sourceLibraryPublicationSchema, webCitationSchema };
|
|
18
23
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/plugin-data/schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/plugin-data/schema.ts"],"mappings":";;;;cAKa;;;;;cAmBA,mBAAiB,EAAA;;;;;;KAYlB,cAAc,EAAE,mBAAmB;;cASlC,wBAAwB,EAAE,uBAAuB;;cAajD,gCAAgC,EAAE,uBAAuB"}
|
|
@@ -23,7 +23,30 @@ const webCitationSchema = v.object({
|
|
|
23
23
|
quote: v.pipe(v.string(), v.trim(), v.maxLength(CITATION_QUOTE_LIMIT)),
|
|
24
24
|
readAt: v.pipe(v.string(), v.isoTimestamp())
|
|
25
25
|
});
|
|
26
|
+
const enabledLibrarySchema = v.object({
|
|
27
|
+
libraryId: v.string(),
|
|
28
|
+
revisionId: v.string(),
|
|
29
|
+
enabled: v.optional(v.unknown())
|
|
30
|
+
});
|
|
31
|
+
/** One library a document switched on; invalid entries are skipped one by one. */
|
|
32
|
+
const enabledLibrariesSchema = v.pipe(v.array(v.unknown()), v.transform((items) => items.flatMap((item) => {
|
|
33
|
+
const parsed = v.safeParse(enabledLibrarySchema, item);
|
|
34
|
+
if (!parsed.success) return [];
|
|
35
|
+
const { libraryId, revisionId, enabled } = parsed.output;
|
|
36
|
+
return [{
|
|
37
|
+
libraryId,
|
|
38
|
+
revisionId,
|
|
39
|
+
enabled: enabled === true
|
|
40
|
+
}];
|
|
41
|
+
})));
|
|
42
|
+
/** The library a document publishes as: its identity, its revision, and where it was published. */
|
|
43
|
+
const sourceLibraryPublicationSchema = v.object({
|
|
44
|
+
libraryId: v.string(),
|
|
45
|
+
revisionId: v.string(),
|
|
46
|
+
name: v.string(),
|
|
47
|
+
catalogSource: v.optional(v.string())
|
|
48
|
+
});
|
|
26
49
|
//#endregion
|
|
27
|
-
export { CITATION_QUOTE_LIMIT, webCitationSchema };
|
|
50
|
+
export { CITATION_QUOTE_LIMIT, enabledLibrariesSchema, sourceLibraryPublicationSchema, webCitationSchema };
|
|
28
51
|
|
|
29
52
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/plugin-data/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/** A quote kept on a sticky. A longer passage is cut before it is stored. */\nexport const CITATION_QUOTE_LIMIT = 2_000\n\nconst CITATION_URL_LIMIT = 2_048\nconst CITATION_TITLE_LIMIT = 300\n\n/** An http or https page with a host. Other schemes are not citations. */\nfunction isCitedPage(value: string): boolean {\n try {\n const url = new URL(value)\n return (url.protocol === 'http:' || url.protocol === 'https:') && url.hostname !== ''\n } catch {\n return false\n }\n}\n\n/**\n * A page a sticky cites: where it was read, what it was called, the words taken from it, and\n * when. The quote is characters from the page, kept as text.\n */\nexport const webCitationSchema = v.object({\n url: v.pipe(\n v.string(),\n v.trim(),\n v.maxLength(CITATION_URL_LIMIT),\n v.check(isCitedPage, 'A citation names an http or https page.')\n ),\n title: v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(CITATION_TITLE_LIMIT)),\n quote: v.pipe(v.string(), v.trim(), v.maxLength(CITATION_QUOTE_LIMIT)),\n readAt: v.pipe(v.string(), v.isoTimestamp())\n})\n\nexport type WebCitation = v.InferOutput<typeof webCitationSchema>\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/plugin-data/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { EnabledLibraryBinding, SourceLibraryPublication } from '../types'\n\n/** A quote kept on a sticky. A longer passage is cut before it is stored. */\nexport const CITATION_QUOTE_LIMIT = 2_000\n\nconst CITATION_URL_LIMIT = 2_048\nconst CITATION_TITLE_LIMIT = 300\n\n/** An http or https page with a host. Other schemes are not citations. */\nfunction isCitedPage(value: string): boolean {\n try {\n const url = new URL(value)\n return (url.protocol === 'http:' || url.protocol === 'https:') && url.hostname !== ''\n } catch {\n return false\n }\n}\n\n/**\n * A page a sticky cites: where it was read, what it was called, the words taken from it, and\n * when. The quote is characters from the page, kept as text.\n */\nexport const webCitationSchema = v.object({\n url: v.pipe(\n v.string(),\n v.trim(),\n v.maxLength(CITATION_URL_LIMIT),\n v.check(isCitedPage, 'A citation names an http or https page.')\n ),\n title: v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(CITATION_TITLE_LIMIT)),\n quote: v.pipe(v.string(), v.trim(), v.maxLength(CITATION_QUOTE_LIMIT)),\n readAt: v.pipe(v.string(), v.isoTimestamp())\n})\n\nexport type WebCitation = v.InferOutput<typeof webCitationSchema>\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** One library a document switched on; invalid entries are skipped one by one. */\nexport const enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n/** The library a document publishes as: its identity, its revision, and where it was published. */\nexport const sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> =\n v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n })\n"],"mappings":";;;AAKA,MAAa,uBAAuB;AAEpC,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;;AAG7B,SAAS,YAAY,OAAwB;CAC3C,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;EACzB,QAAQ,IAAI,aAAa,WAAW,IAAI,aAAa,aAAa,IAAI,aAAa;CACrF,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,MAAa,oBAAoB,EAAE,OAAO;CACxC,KAAK,EAAE,KACL,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,kBAAkB,GAC9B,EAAE,MAAM,aAAa,yCAAyC,CAChE;CACA,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,SAAS,GAAG,EAAE,UAAU,oBAAoB,CAAC;CACnF,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,oBAAoB,CAAC;CACrE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,aAAa,CAAC;AAC7C,CAAC;AAID,MAAM,uBAAuB,EAAE,OAAO;CACpC,WAAW,EAAE,OAAO;CACpB,YAAY,EAAE,OAAO;CACrB,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACjC,CAAC;;AAGD,MAAa,yBAA4E,EAAE,KACzF,EAAE,MAAM,EAAE,QAAQ,CAAC,GACnB,EAAE,WAAW,UACX,MAAM,SAAS,SAAS;CACtB,MAAM,SAAS,EAAE,UAAU,sBAAsB,IAAI;CACrD,IAAI,CAAC,OAAO,SAAS,OAAO,CAAC;CAC7B,MAAM,EAAE,WAAW,YAAY,YAAY,OAAO;CAClD,OAAO,CAAC;EAAE;EAAW;EAAY,SAAS,YAAY;CAAK,CAAC;AAC9D,CAAC,CACH,CACF;;AAGA,MAAa,iCACX,EAAE,OAAO;CACP,WAAW,EAAE,OAAO;CACpB,YAAY,EAAE,OAAO;CACrB,MAAM,EAAE,OAAO;CACf,eAAe,EAAE,SAAS,EAAE,OAAO,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ShaderPreset } from "./schema.js";
|
|
2
|
+
//#region src/shaders/animation.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What the library says of an effect's motion: whether it is driven by time, and whether a
|
|
5
|
+
* `speed` prop of its own decides how fast it moves.
|
|
6
|
+
*/
|
|
7
|
+
interface ShaderEffectMotion {
|
|
8
|
+
animates: boolean;
|
|
9
|
+
speed: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** What the caller knows of an effect's motion, or undefined for an effect it does not know yet. */
|
|
12
|
+
type ShaderMotion = (type: string) => ShaderEffectMotion | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `preset` changes between frames: any of its effects animates. A preset of still
|
|
15
|
+
* effects, or one whose animated effects are all at `speed: 0`, draws one picture forever and
|
|
16
|
+
* does not need a player.
|
|
17
|
+
*/
|
|
18
|
+
declare function presetAnimates(preset: ShaderPreset, motion: ShaderMotion): boolean;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ShaderEffectMotion, ShaderMotion, presetAnimates };
|
|
21
|
+
//# sourceMappingURL=animation.d.ts.map
|