@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.2
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/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +176 -5
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +13 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +58 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +9 -15
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +30 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +63 -131
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +1 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +15 -3
- package/dist/graph.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +42 -29
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +36 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +84 -32
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +2 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +19 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/scaling/tree.js +1 -1
- package/dist/shared-styles.d.ts +14 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +63 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +2 -0
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/index.js +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +27 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +28 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +104 -14
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/index.d.ts +3 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +23 -8
- package/dist/variables/index.js.map +1 -1
- package/package.json +7 -1
- package/src/arrow-caps.ts +2 -5
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +251 -4
- package/src/components/properties.ts +92 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/copy.ts +9 -15
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +1 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +78 -198
- package/src/graph.ts +27 -3
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +67 -54
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +58 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/swap.ts +451 -0
- package/src/instances/sync.ts +141 -42
- package/src/node-defaults.ts +2 -1
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/shared-styles.ts +82 -1
- package/src/slots/content.ts +2 -0
- package/src/slots/frames.ts +9 -7
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +28 -0
- package/src/variables/bindings.ts +125 -14
- package/src/variables/fields.ts +46 -1
- package/src/variables/index.ts +35 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["// Child cloning and property synchronization shared by instance creation, swap, and sync.\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 type { SceneNode } from '../types'\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 {\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 { 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) => fields.has(field)\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\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 return {\n ...source,\n ...scaleNodeChanges(source, factor, true),\n ...scaleVariableBindingUnits(source, factor)\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 if (key === 'boundVariables') 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): void {\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\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 return graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\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\nfunction linkMatchedChild(\n overrides: InstanceOverrideState,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n if (instChild.type === 'INSTANCE') {\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n } else {\n instChild.componentId = compChildId\n }\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\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(overrides, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState\n): void {\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 = 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/** Children already linked to a component child by sourceComponentId or componentId. */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n compChildIdSet: ReadonlySet<string>,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\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 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 const compChildIdSet = new Set(compParent.childIds)\n\n // Pass 1: Direct matching via sourceComponentId or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n compChildIdSet,\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 overrides,\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\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\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 const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: (key) => driven.has(key) || isProtectedSyncField(instChild, key, protectedField)\n })\n Object.assign(updates, assignedFieldValues(graph, instChild, compChild))\n keepOwnContentSize(graph, updates, instChild, source, placement)\n updateSyncedProps(graph, instChild, updates)\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(graph, instParent, instParentId, compParent.childIds, overrides)\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO,OAAO;AAChB;AAEA,SAAgB,SACd,QACA,QACA,KACM;CACN,IAAI,QAAQ,SACV,aAAa,QAAQ,KAAK,UAAU,OAAO,KAAK,CAAC;MAC5C,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,aACjB,aAAa,QAAQ,KAAK,cAAc,OAAO,SAAS,CAAC;MACpD,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,WAAW;EAE9B,MAAM,iBAAiB,uBAAuB,OAAO,WAAW,SAAS;EACzE,MAAM,SAAS,qBAAqB,OAAO,WAAW,SAAS;EAC/D,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,MAAM,YAAY,iBAAiB,SAAS,WAAW,QAAQ;GAC7D;GACA;GACA,QAAQ,iBAAiB,UAAU;GACnC,OAAO,QAAQ,OAAO,IAAI,GAAG,KAAK,qBAAqB,WAAW,KAAK,cAAc;EACvF,CAAC;EACD,OAAO,OAAO,SAAS,oBAAoB,OAAO,WAAW,SAAS,CAAC;EACvE,mBAAmB,OAAO,SAAS,WAAW,QAAQ,SAAS;EAC/D,kBAAkB,OAAO,WAAW,OAAO;EAE3C,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,qBAAqB,OAAO,YAAY,cAAc,WAAW,UAAU,SAAS;AACtF"}
|
|
1
|
+
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["// Child cloning and property synchronization shared by instance creation, swap, and sync.\nimport { uniq } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, 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 type { SceneNode } from '../types'\nimport { resolvedNumericBindings } from '../variables/bindings'\nimport { effectBindingTarget, isNumericVariableBindingField } from '../variables/fields'\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 {\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 { 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 if (key === 'booleanOperation') {\n setSceneProp(target, key, source.booleanOperation ?? 'UNION')\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 // Effects an instance set itself own their bindings too, bound or not, as its fills do.\n const binding = overriddenBindingField(field)\n return binding !== null && fields.has('effects') && effectBindingTarget(binding) !== null\n }\n}\n\nfunction isUnbound(node: SceneNode): boolean {\n return isEmptyObject(node.boundVariables) && isEmptyObject(node.variableBindingScales)\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') || (isUnbound(source) && isUnbound(target))) {\n return\n }\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\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 return {\n ...source,\n ...scaleNodeChanges(source, factor, true),\n ...scaleVariableBindingUnits(source, factor)\n }\n}\n\nconst SYNCED_FIELDS = INSTANCE_SYNC_FIELDS.filter((key) => key !== 'boundVariables').map((key) => ({\n key,\n owner: INSTANCE_SYNC_FIELD_OWNERS[key],\n placement: PLACEMENT_FIELDS.has(key),\n position: key === 'x' || key === 'y'\n}))\n\nexport const NOTHING_PROTECTED = (_field: string): boolean => false\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, owner, placement, position } of SYNCED_FIELDS) {\n if ((placedByLayout && position) || skip(key) || (owner && skip(owner))) {\n continue\n }\n const from = placement ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (copy[key] === from[key] || isEqual(copy[key], from[key])) {\n continue\n }\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 let changed: Partial<SceneNode> | undefined\n for (const key of Object.keys(updates)) {\n const current = target[key as keyof SceneNode]\n const value = updates[key as keyof SceneNode]\n if (current !== value && !isEqual(current, value)) {\n changed ??= {}\n Reflect.set(changed, key, value)\n }\n }\n if (!changed) {\n return\n }\n if (changed.fills && updates.fillStyleId !== undefined) {\n changed.fillStyleId = updates.fillStyleId\n }\n 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 // The modes the copy takes in this sync decide what its bindings resolve to.\n if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))\n graph.updateNode(target.id, { variableModes: updates.variableModes })\n const resolved = resolvedNumericBindings(graph, { ...target, ...updates })\n Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))\n}\n\nexport function 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 return graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\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 if (child.instanceOverrides.self.size === 0 && fields.every((scope) => scope.size === 0)) {\n return NOTHING_PROTECTED\n }\n const protectedField = bindingProtection(fields)\n return (field: string) => protectedField(field) || ownsSelfFillField(child, field)\n}\n\nfunction linkMatchedChild(\n overrides: InstanceOverrideState,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n if (instChild.type === 'INSTANCE') {\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n } else {\n instChild.componentId = compChildId\n }\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\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(overrides, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState\n): void {\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 = 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\nexport interface MatchedCopy {\n compParent: SceneNode\n instParent: SceneNode\n compChild: SceneNode\n instChild: SceneNode\n}\n\nexport function syncCopy(\n graph: SceneGraph,\n { compParent, instParent, compChild, instChild }: MatchedCopy,\n protectedField: (field: string) => boolean,\n linkedLayerId?: string\n): void {\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept =\n driven.size === 0 && protectedField === NOTHING_PROTECTED\n ? NOTHING_PROTECTED\n : (key: string) => 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 if (instChild.componentScale !== componentScale) {\n updates.componentScale = componentScale\n }\n if (!isEqual(instChild.componentPropertyReferences, compChild.componentPropertyReferences)) {\n updates.componentPropertyReferences = structuredClone(compChild.componentPropertyReferences)\n }\n if (linkedLayerId !== undefined) {\n updates.componentId = linkedLayerId\n }\n syncBindingFields(instChild, source, updates, protectedField)\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\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/** Children already linked to a component child by sourceComponentId or componentId. */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n compChildIdSet: ReadonlySet<string>,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\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 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 const compChildIdSet = new Set(compParent.childIds)\n\n // Pass 1: Direct matching via sourceComponentId or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n compChildIdSet,\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 overrides,\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\n syncCopy(\n graph,\n { compParent, instParent, compChild, instChild },\n childBindingProtection(graph, instChild, overrides)\n )\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(graph, instParent, instParentId, compParent.childIds, over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3F,KAAK,MAAM,eAAe,WAAW,UAAU;EAC7C,MAAM,YAAY,MAAM,MAAM,IAAI,WAAW;EAC7C,MAAM,YAAY,aAAa,IAAI,WAAW;EAC9C,IAAI,CAAC,aAAa,CAAC,WAAW;EAE9B,SACE,OACA;GAAE;GAAY;GAAY;GAAW;EAAU,GAC/C,uBAAuB,OAAO,WAAW,SAAS,CACpD;EAEA,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,qBAAqB,OAAO,YAAY,cAAc,WAAW,UAAU,SAAS;AACtF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAUgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;iBAKQ,kBACd,0BACA,MAAM,UACN,YAAW,QAAQ,aAClB;;
|
|
1
|
+
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAUgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;iBAKQ,kBACd,0BACA,MAAM,UACN,YAAW,QAAQ,aAClB;;cAkLU,wBAAwB,YAAY;;cAMpC,mBAAmB,YAAY;;cAS/B,uBAAuB,YAAY;iBAShC,iBAAiB,MAAM,KAAK;cAI/B,iBAAe,IAAA"}
|
package/dist/node-defaults.js
CHANGED
|
@@ -172,7 +172,7 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
172
172
|
textTruncation: "DISABLED",
|
|
173
173
|
autoRename: true,
|
|
174
174
|
pointCount: 5,
|
|
175
|
-
starInnerRadius: .
|
|
175
|
+
starInnerRadius: (3 - Math.sqrt(5)) / 2,
|
|
176
176
|
shapeWithTextType: "SQUARE",
|
|
177
177
|
shapeUserHeight: 0,
|
|
178
178
|
shapeTruncates: false,
|
|
@@ -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 { 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: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\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\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n return {\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' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\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 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 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 blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\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: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\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: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\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: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\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 ...overrides\n } satisfies CompleteNodeFields\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\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\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":";;;;AAUA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BAA0B,CAAC;GAC3B,mBAAmB,CAAC;GACpB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a;EACb,qBAAqB;EACrB,kBAAkB;EAClB,eAAe;EACf,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa,CAAC;EACd,kBAAkB,CAAC;EACnB,gBAAgB,CAAC;EACjB,uBAAuB,CAAC;EACxB,0BAA0B,CAAC;EAC3B,gBAAgB;EAChB,eAAe,CAAC;EAChB,gBAAgB,CAAC;EACjB,QAAQ;EACR,YAAY,CAAC;EACb,oBAAoB,CAAC;EACrB,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAClB,GAAG;CACL;AACF;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,wCAA+C,IAAI,IAAc;CAC5E;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;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 { 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: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\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\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n return {\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' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\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 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 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 blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\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: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\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 // Figma's: the golden-ratio star, whose inner points line up with its outer ones.\n starInnerRadius: (3 - Math.sqrt(5)) / 2,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\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: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\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 ...overrides\n } satisfies CompleteNodeFields\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\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\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":";;;;AAUA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BAA0B,CAAC;GAC3B,mBAAmB,CAAC;GACpB,gCAAgC;GAChC,oBAAoB;EACtB;CACF;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;AAEA,SAAgB,kBACd,YACA,MACA,YAAgC,CAAC,GACtB;CACX,OAAO;EACL,IAAI,WAAW;EACf;EACA,MAAM,KAAK,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY;EACjD,UAAU;EACV,UAAU,CAAC;EACX,GAAG;EACH,GAAG;EACH,OAAO;EACP,QA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Aa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,wCAA+C,IAAI,IAAc;CAC5E;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Vector } from "../primitives/index.js";
|
|
2
|
+
import { VectorNetwork } from "../types.js";
|
|
3
|
+
//#region src/outline/flatten.d.ts
|
|
4
|
+
/** Points along a vector network segment, from its start to its end, in network coordinates. */
|
|
5
|
+
declare function segmentPoints(network: VectorNetwork, index: number, tolerance: number): Vector[] | null;
|
|
6
|
+
/**
|
|
7
|
+
* A loop's points in the order it is walked. Segments in a loop can be stored either way round,
|
|
8
|
+
* so each is followed from the vertex the previous one ended on.
|
|
9
|
+
*/
|
|
10
|
+
declare function loopPoints(network: VectorNetwork, loop: number[], tolerance: number): Vector[];
|
|
11
|
+
/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */
|
|
12
|
+
declare function blobContours(blob: Uint8Array, tolerance: number): Vector[][];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { blobContours, loopPoints, segmentPoints };
|
|
15
|
+
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","names":[],"sources":["../../src/outline/flatten.ts"],"mappings":";;;;iBAoCgB,cACd,SAAS,eACT,eACA,oBACC;;;;;iBAoBa,WAAW,SAAS,eAAe,gBAAgB,oBAAoB;;iBA2CvE,aAAa,MAAM,YAAY,oBAAoB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { cubicPoint } from "../cubic.js";
|
|
2
|
+
import { GeometryCommand, readGeometryBlob } from "../geometry.js";
|
|
3
|
+
//#region src/outline/flatten.ts
|
|
4
|
+
/**
|
|
5
|
+
* Keeps a huge curve at a tiny tolerance from flattening into an unbounded number of points, while
|
|
6
|
+
* leaving room for the largest arcs at the maximum zoom: a 100,000-unit circle at 25,600% needs
|
|
7
|
+
* about 12,000 steps to stay within the click pad.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_CURVE_STEPS = 65536;
|
|
10
|
+
/**
|
|
11
|
+
* Steps that keep a cubic's polyline within `tolerance` of it: equal steps in t stray at most
|
|
12
|
+
* M / (8n²) from a curve whose second derivative is at most M, and for a cubic
|
|
13
|
+
* M ≤ 6 · max(|p0 − 2p1 + p2|, |p1 − 2p2 + p3|).
|
|
14
|
+
*/
|
|
15
|
+
function curveSteps(p0, p1, p2, p3, tolerance) {
|
|
16
|
+
const bend = Math.max(Math.hypot(p0.x - 2 * p1.x + p2.x, p0.y - 2 * p1.y + p2.y), Math.hypot(p1.x - 2 * p2.x + p3.x, p1.y - 2 * p2.y + p3.y));
|
|
17
|
+
const steps = Math.ceil(Math.sqrt(6 * bend / (8 * tolerance)));
|
|
18
|
+
return Math.min(MAX_CURVE_STEPS, Math.max(1, steps));
|
|
19
|
+
}
|
|
20
|
+
/** Points along a cubic after its start, within `tolerance` of it, ending on `p3`. */
|
|
21
|
+
function cubicPoints(p0, p1, p2, p3, tolerance) {
|
|
22
|
+
const steps = curveSteps(p0, p1, p2, p3, tolerance);
|
|
23
|
+
const points = [];
|
|
24
|
+
for (let step = 1; step <= steps; step++) points.push(cubicPoint(p0, p1, p2, p3, step / steps));
|
|
25
|
+
return points;
|
|
26
|
+
}
|
|
27
|
+
/** Points along a vector network segment, from its start to its end, in network coordinates. */
|
|
28
|
+
function segmentPoints(network, index, tolerance) {
|
|
29
|
+
if (!Number.isInteger(index) || index < 0) return null;
|
|
30
|
+
const segment = network.segments.at(index);
|
|
31
|
+
if (!segment || segment.start < 0 || segment.end < 0) return null;
|
|
32
|
+
const p0 = network.vertices.at(segment.start);
|
|
33
|
+
const p3 = network.vertices.at(segment.end);
|
|
34
|
+
if (!p0 || !p3) return null;
|
|
35
|
+
const { tangentStart: a, tangentEnd: b } = segment;
|
|
36
|
+
if (a.x === 0 && a.y === 0 && b.x === 0 && b.y === 0) return [p0, p3];
|
|
37
|
+
return [p0, ...cubicPoints(p0, {
|
|
38
|
+
x: p0.x + a.x,
|
|
39
|
+
y: p0.y + a.y
|
|
40
|
+
}, {
|
|
41
|
+
x: p3.x + b.x,
|
|
42
|
+
y: p3.y + b.y
|
|
43
|
+
}, p3, tolerance)];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A loop's points in the order it is walked. Segments in a loop can be stored either way round,
|
|
47
|
+
* so each is followed from the vertex the previous one ended on.
|
|
48
|
+
*/
|
|
49
|
+
function loopPoints(network, loop, tolerance) {
|
|
50
|
+
const { segments } = network;
|
|
51
|
+
const first = segments.at(loop[0] ?? -1);
|
|
52
|
+
const second = segments.at(loop[1] ?? -1);
|
|
53
|
+
if (!first) return [];
|
|
54
|
+
let current = !second || first.end === second.start || first.end === second.end ? first.start : first.end;
|
|
55
|
+
const points = [];
|
|
56
|
+
for (const index of loop) {
|
|
57
|
+
const segment = segments.at(index);
|
|
58
|
+
const along = segmentPoints(network, index, tolerance);
|
|
59
|
+
if (!segment || !along) continue;
|
|
60
|
+
const forward = segment.start === current;
|
|
61
|
+
points.push(...forward ? along : along.toReversed());
|
|
62
|
+
current = forward ? segment.end : segment.start;
|
|
63
|
+
}
|
|
64
|
+
return points;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The network's segments joined into runs, a run continuing while each segment starts where the
|
|
68
|
+
* last ended, as a path draws them one after another.
|
|
69
|
+
*/
|
|
70
|
+
function segmentRuns(network, tolerance) {
|
|
71
|
+
const runs = [];
|
|
72
|
+
let run = [];
|
|
73
|
+
let end = -1;
|
|
74
|
+
for (const [index, segment] of network.segments.entries()) {
|
|
75
|
+
const along = segmentPoints(network, index, tolerance);
|
|
76
|
+
if (!along) continue;
|
|
77
|
+
if (segment.start === end && run.length > 0) run.push(...along.slice(1));
|
|
78
|
+
else {
|
|
79
|
+
if (run.length > 1) runs.push(run);
|
|
80
|
+
run = along;
|
|
81
|
+
}
|
|
82
|
+
end = segment.end;
|
|
83
|
+
}
|
|
84
|
+
if (run.length > 1) runs.push(run);
|
|
85
|
+
return runs;
|
|
86
|
+
}
|
|
87
|
+
/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */
|
|
88
|
+
function blobContours(blob, tolerance) {
|
|
89
|
+
const contours = [];
|
|
90
|
+
let contour = [];
|
|
91
|
+
const flush = () => {
|
|
92
|
+
if (contour.length > 1) contours.push(contour);
|
|
93
|
+
contour = [];
|
|
94
|
+
};
|
|
95
|
+
readGeometryBlob(blob, (command, c) => {
|
|
96
|
+
if (command === GeometryCommand.CLOSE) return flush();
|
|
97
|
+
if (command === GeometryCommand.MOVE) {
|
|
98
|
+
flush();
|
|
99
|
+
contour.push({
|
|
100
|
+
x: c[0],
|
|
101
|
+
y: c[1]
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const end = {
|
|
106
|
+
x: c[c.length - 2],
|
|
107
|
+
y: c[c.length - 1]
|
|
108
|
+
};
|
|
109
|
+
const last = contour.at(-1);
|
|
110
|
+
if (!last || command === GeometryCommand.LINE) contour.push(end);
|
|
111
|
+
else if (command === GeometryCommand.QUAD) {
|
|
112
|
+
const q = {
|
|
113
|
+
x: c[0],
|
|
114
|
+
y: c[1]
|
|
115
|
+
};
|
|
116
|
+
const c1 = {
|
|
117
|
+
x: last.x + 2 / 3 * (q.x - last.x),
|
|
118
|
+
y: last.y + 2 / 3 * (q.y - last.y)
|
|
119
|
+
};
|
|
120
|
+
const c2 = {
|
|
121
|
+
x: end.x + 2 / 3 * (q.x - end.x),
|
|
122
|
+
y: end.y + 2 / 3 * (q.y - end.y)
|
|
123
|
+
};
|
|
124
|
+
contour.push(...cubicPoints(last, c1, c2, end, tolerance));
|
|
125
|
+
} else contour.push(...cubicPoints(last, {
|
|
126
|
+
x: c[0],
|
|
127
|
+
y: c[1]
|
|
128
|
+
}, {
|
|
129
|
+
x: c[2],
|
|
130
|
+
y: c[3]
|
|
131
|
+
}, end, tolerance));
|
|
132
|
+
});
|
|
133
|
+
flush();
|
|
134
|
+
return contours;
|
|
135
|
+
}
|
|
136
|
+
/** The contours of polygon outline commands, curves flattened to within `tolerance`. */
|
|
137
|
+
function commandContours(commands, tolerance) {
|
|
138
|
+
const contours = [];
|
|
139
|
+
let contour = [];
|
|
140
|
+
for (const command of commands) {
|
|
141
|
+
if (command.type === "Z" || command.type === "M") {
|
|
142
|
+
if (contour.length > 1) contours.push(contour);
|
|
143
|
+
contour = command.type === "M" ? [{
|
|
144
|
+
x: command.x,
|
|
145
|
+
y: command.y
|
|
146
|
+
}] : [];
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const last = contour.at(-1) ?? {
|
|
150
|
+
x: 0,
|
|
151
|
+
y: 0
|
|
152
|
+
};
|
|
153
|
+
if (command.type !== "C") contour.push({
|
|
154
|
+
x: command.x,
|
|
155
|
+
y: command.y
|
|
156
|
+
});
|
|
157
|
+
else contour.push(...cubicPoints(last, {
|
|
158
|
+
x: command.x1,
|
|
159
|
+
y: command.y1
|
|
160
|
+
}, {
|
|
161
|
+
x: command.x2,
|
|
162
|
+
y: command.y2
|
|
163
|
+
}, {
|
|
164
|
+
x: command.x,
|
|
165
|
+
y: command.y
|
|
166
|
+
}, tolerance));
|
|
167
|
+
}
|
|
168
|
+
if (contour.length > 1) contours.push(contour);
|
|
169
|
+
return contours;
|
|
170
|
+
}
|
|
171
|
+
/** Points around an ellipse arc from `start` to `end` radians, at most `tolerance` off it. */
|
|
172
|
+
function arcPoints(cx, cy, rx, ry, start, end, tolerance) {
|
|
173
|
+
const radius = Math.max(rx, ry);
|
|
174
|
+
const step = radius > tolerance ? 2 * Math.acos(Math.max(-1, 1 - tolerance / radius)) : Math.PI / 2;
|
|
175
|
+
const steps = Math.min(MAX_CURVE_STEPS, Math.max(1, Math.ceil(Math.abs(end - start) / Math.max(step, .001))));
|
|
176
|
+
const points = [];
|
|
177
|
+
for (let i = 0; i <= steps; i++) {
|
|
178
|
+
const angle = start + (end - start) * i / steps;
|
|
179
|
+
points.push({
|
|
180
|
+
x: cx + rx * Math.cos(angle),
|
|
181
|
+
y: cy + ry * Math.sin(angle)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return points;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
export { arcPoints, blobContours, commandContours, loopPoints, segmentPoints, segmentRuns };
|
|
188
|
+
|
|
189
|
+
//# sourceMappingURL=flatten.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.js","names":[],"sources":["../../src/outline/flatten.ts"],"sourcesContent":["import { cubicPoint } from '../cubic'\nimport { GeometryCommand, readGeometryBlob } from '../geometry'\nimport type { PolygonOutlineCommand } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { VectorNetwork } from '../types'\n\n/**\n * Keeps a huge curve at a tiny tolerance from flattening into an unbounded number of points, while\n * leaving room for the largest arcs at the maximum zoom: a 100,000-unit circle at 25,600% needs\n * about 12,000 steps to stay within the click pad.\n */\nconst MAX_CURVE_STEPS = 65_536\n\n/**\n * Steps that keep a cubic's polyline within `tolerance` of it: equal steps in t stray at most\n * M / (8n²) from a curve whose second derivative is at most M, and for a cubic\n * M ≤ 6 · max(|p0 − 2p1 + p2|, |p1 − 2p2 + p3|).\n */\nfunction curveSteps(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): number {\n const bend = Math.max(\n Math.hypot(p0.x - 2 * p1.x + p2.x, p0.y - 2 * p1.y + p2.y),\n Math.hypot(p1.x - 2 * p2.x + p3.x, p1.y - 2 * p2.y + p3.y)\n )\n const steps = Math.ceil(Math.sqrt((6 * bend) / (8 * tolerance)))\n return Math.min(MAX_CURVE_STEPS, Math.max(1, steps))\n}\n\n/** Points along a cubic after its start, within `tolerance` of it, ending on `p3`. */\nfunction cubicPoints(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): Vector[] {\n const steps = curveSteps(p0, p1, p2, p3, tolerance)\n const points: Vector[] = []\n for (let step = 1; step <= steps; step++) points.push(cubicPoint(p0, p1, p2, p3, step / steps))\n return points\n}\n\n/** Points along a vector network segment, from its start to its end, in network coordinates. */\nexport function segmentPoints(\n network: VectorNetwork,\n index: number,\n tolerance: number\n): Vector[] | null {\n // `at` counts a negative index from the end and truncates a fraction; a loop naming either\n // refers to no segment.\n if (!Number.isInteger(index) || index < 0) return null\n const segment = network.segments.at(index)\n if (!segment || segment.start < 0 || segment.end < 0) return null\n const p0 = network.vertices.at(segment.start)\n const p3 = network.vertices.at(segment.end)\n if (!p0 || !p3) return null\n const { tangentStart: a, tangentEnd: b } = segment\n if (a.x === 0 && a.y === 0 && b.x === 0 && b.y === 0) return [p0, p3]\n const p1 = { x: p0.x + a.x, y: p0.y + a.y }\n const p2 = { x: p3.x + b.x, y: p3.y + b.y }\n return [p0, ...cubicPoints(p0, p1, p2, p3, tolerance)]\n}\n\n/**\n * A loop's points in the order it is walked. Segments in a loop can be stored either way round,\n * so each is followed from the vertex the previous one ended on.\n */\nexport function loopPoints(network: VectorNetwork, loop: number[], tolerance: number): Vector[] {\n const { segments } = network\n const first = segments.at(loop[0] ?? -1)\n const second = segments.at(loop[1] ?? -1)\n if (!first) return []\n // Walk the first segment toward the vertex it shares with the next one.\n const firstForward = !second || first.end === second.start || first.end === second.end\n let current = firstForward ? first.start : first.end\n const points: Vector[] = []\n for (const index of loop) {\n const segment = segments.at(index)\n const along = segmentPoints(network, index, tolerance)\n if (!segment || !along) continue\n const forward = segment.start === current\n points.push(...(forward ? along : along.toReversed()))\n current = forward ? segment.end : segment.start\n }\n return points\n}\n\n/**\n * The network's segments joined into runs, a run continuing while each segment starts where the\n * last ended, as a path draws them one after another.\n */\nexport function segmentRuns(network: VectorNetwork, tolerance: number): Vector[][] {\n const runs: Vector[][] = []\n let run: Vector[] = []\n let end = -1\n for (const [index, segment] of network.segments.entries()) {\n const along = segmentPoints(network, index, tolerance)\n if (!along) continue\n if (segment.start === end && run.length > 0) run.push(...along.slice(1))\n else {\n if (run.length > 1) runs.push(run)\n run = along\n }\n end = segment.end\n }\n if (run.length > 1) runs.push(run)\n return runs\n}\n\n/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */\nexport function blobContours(blob: Uint8Array, tolerance: number): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n const flush = () => {\n if (contour.length > 1) contours.push(contour)\n contour = []\n }\n readGeometryBlob(blob, (command, c) => {\n if (command === GeometryCommand.CLOSE) return flush()\n if (command === GeometryCommand.MOVE) {\n flush()\n contour.push({ x: c[0], y: c[1] })\n return\n }\n const end = { x: c[c.length - 2], y: c[c.length - 1] }\n const last = contour.at(-1)\n if (!last || command === GeometryCommand.LINE) {\n contour.push(end)\n } else if (command === GeometryCommand.QUAD) {\n // A quadratic as the cubic with the same curve.\n const q = { x: c[0], y: c[1] }\n const c1 = { x: last.x + (2 / 3) * (q.x - last.x), y: last.y + (2 / 3) * (q.y - last.y) }\n const c2 = { x: end.x + (2 / 3) * (q.x - end.x), y: end.y + (2 / 3) * (q.y - end.y) }\n contour.push(...cubicPoints(last, c1, c2, end, tolerance))\n } else {\n contour.push(...cubicPoints(last, { x: c[0], y: c[1] }, { x: c[2], y: c[3] }, end, tolerance))\n }\n })\n flush()\n return contours\n}\n\n/** The contours of polygon outline commands, curves flattened to within `tolerance`. */\nexport function commandContours(\n commands: readonly PolygonOutlineCommand[],\n tolerance: number\n): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n for (const command of commands) {\n if (command.type === 'Z' || command.type === 'M') {\n if (contour.length > 1) contours.push(contour)\n contour = command.type === 'M' ? [{ x: command.x, y: command.y }] : []\n continue\n }\n const last = contour.at(-1) ?? { x: 0, y: 0 }\n if (command.type !== 'C') contour.push({ x: command.x, y: command.y })\n else\n contour.push(\n ...cubicPoints(\n last,\n { x: command.x1, y: command.y1 },\n { x: command.x2, y: command.y2 },\n { x: command.x, y: command.y },\n tolerance\n )\n )\n }\n if (contour.length > 1) contours.push(contour)\n return contours\n}\n\n/** Points around an ellipse arc from `start` to `end` radians, at most `tolerance` off it. */\nexport function arcPoints(\n cx: number,\n cy: number,\n rx: number,\n ry: number,\n start: number,\n end: number,\n tolerance: number\n): Vector[] {\n const radius = Math.max(rx, ry)\n // A chord over angle θ strays r(1 − cos(θ/2)) from the arc.\n const step =\n radius > tolerance ? 2 * Math.acos(Math.max(-1, 1 - tolerance / radius)) : Math.PI / 2\n const steps = Math.min(\n MAX_CURVE_STEPS,\n Math.max(1, Math.ceil(Math.abs(end - start) / Math.max(step, 1e-3)))\n )\n const points: Vector[] = []\n for (let i = 0; i <= steps; i++) {\n const angle = start + ((end - start) * i) / steps\n points.push({ x: cx + rx * Math.cos(angle), y: cy + ry * Math.sin(angle) })\n }\n return points\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,kBAAkB;;;;;;AAOxB,SAAS,WAAW,IAAY,IAAY,IAAY,IAAY,WAA2B;CAC7F,MAAM,OAAO,KAAK,IAChB,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,GACzD,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,CAC3D;CACA,MAAM,QAAQ,KAAK,KAAK,KAAK,KAAM,IAAI,QAAS,IAAI,UAAU,CAAC;CAC/D,OAAO,KAAK,IAAI,iBAAiB,KAAK,IAAI,GAAG,KAAK,CAAC;AACrD;;AAGA,SAAS,YAAY,IAAY,IAAY,IAAY,IAAY,WAA6B;CAChG,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,IAAI,SAAS;CAClD,MAAM,SA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AG,QAAQ;GAAI,GAAG,QAAQ;EAAG,GAC/B;GAAE,GAAG,QAAQ;GAAI,GAAG,QAAQ;EAAG,GAC/B;GAAE,GAAG,QAAQ;GAAG,GAAG,QAAQ;EAAE,GAC7B,SACF,CACF;CACJ;CACA,IAAI,QAAQ,SAAS,GAAG,SAAS,KAAK,OAAO;CAC7C,OAAO;AACT;;AAGA,SAAgB,UACd,IACA,IACA,IACA,IACA,OACA,KACA,WACU;CACV,MAAM,SAAS,KAAK,IAAI,IAAI,EAAE;CAE9B,MAAM,OACJ,SAAS,YAAY,IAAI,KAAK,KAAK,KAAK,IAAI,IAAI,IAAI,YAAY,MAAM,CAAC,IAAI,KAAK,KAAK;CACvF,MAAM,QAAQ,KAAK,IACjB,iBACA,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,CAAC,CAAC,CACrE;CACA,MAAM,SAAmB,CAAC;CAC1B,KAAK,IAAI,IAAI,GAAG,KAAK,OAAO,KAAK;EAC/B,MAAM,QAAQ,SAAU,MAAM,SAAS,IAAK;EAC5C,OAAO,KAAK;GAAE,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK;GAAG,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK;EAAE,CAAC;CAC5E;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { arrowLinesSegments, circleCapRadius, collectArrowEndpoints, diamondCapPoints, equilateralArrowPoints, triangleCapPoints } from "../arrow-caps.js";
|
|
2
|
+
import { containsByWinding, distanceToLines, distanceToSegment } from "./point.js";
|
|
3
|
+
//#region src/outline/heads.ts
|
|
4
|
+
/** The outline of each filled head with corners, at an end pointing along `angle`. */
|
|
5
|
+
const HEAD_OUTLINES = {
|
|
6
|
+
ARROW_EQUILATERAL: equilateralArrowPoints,
|
|
7
|
+
TRIANGLE_FILLED: triangleCapPoints,
|
|
8
|
+
DIAMOND_FILLED: diamondCapPoints
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Whether the point lands on an arrow head drawn at the open ends of `network`, in its own
|
|
12
|
+
* coordinates, within `pad`: inside a filled head or near its outline, or near a line arrow's
|
|
13
|
+
* wings, which are stroked at the line's weight.
|
|
14
|
+
*/
|
|
15
|
+
function hitsArrowHeads(network, cap, weight, point, pad) {
|
|
16
|
+
for (const { x, y, angle, cap: head } of collectArrowEndpoints(network, cap)) {
|
|
17
|
+
if (head === "CIRCLE_FILLED") {
|
|
18
|
+
if (Math.hypot(point.x - x, point.y - y) <= circleCapRadius(weight) + pad) return true;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (head === "ARROW_LINES") {
|
|
22
|
+
if (arrowLinesSegments(x, y, angle, weight).some((wing) => distanceToSegment(point, wing.from, wing.to) <= weight / 2 + pad)) return true;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const outline = HEAD_OUTLINES[head](x, y, angle, weight);
|
|
26
|
+
if (containsByWinding([outline], "NONZERO", point)) return true;
|
|
27
|
+
if (distanceToLines([[...outline, outline[0]]], point) <= pad) return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { hitsArrowHeads };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=heads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heads.js","names":[],"sources":["../../src/outline/heads.ts"],"sourcesContent":["import {\n arrowLinesSegments,\n circleCapRadius,\n collectArrowEndpoints,\n diamondCapPoints,\n equilateralArrowPoints,\n triangleCapPoints\n} from '../arrow-caps'\nimport type { Vector } from '../primitives'\nimport type { StrokeCap, VectorNetwork } from '../types'\nimport { containsByWinding, distanceToLines, distanceToSegment } from './point'\n\n/** The outline of each filled head with corners, at an end pointing along `angle`. */\nconst HEAD_OUTLINES: Record<\n 'ARROW_EQUILATERAL' | 'TRIANGLE_FILLED' | 'DIAMOND_FILLED',\n (x: number, y: number, angle: number, weight: number) => Vector[]\n> = {\n ARROW_EQUILATERAL: equilateralArrowPoints,\n TRIANGLE_FILLED: triangleCapPoints,\n DIAMOND_FILLED: diamondCapPoints\n}\n\n/**\n * Whether the point lands on an arrow head drawn at the open ends of `network`, in its own\n * coordinates, within `pad`: inside a filled head or near its outline, or near a line arrow's\n * wings, which are stroked at the line's weight.\n */\nexport function hitsArrowHeads(\n network: VectorNetwork,\n cap: StrokeCap,\n weight: number,\n point: Vector,\n pad: number\n): boolean {\n for (const { x, y, angle, cap: head } of collectArrowEndpoints(network, cap)) {\n if (head === 'CIRCLE_FILLED') {\n if (Math.hypot(point.x - x, point.y - y) <= circleCapRadius(weight) + pad) return true\n continue\n }\n if (head === 'ARROW_LINES') {\n const wings = arrowLinesSegments(x, y, angle, weight)\n if (wings.some((wing) => distanceToSegment(point, wing.from, wing.to) <= weight / 2 + pad)) {\n return true\n }\n continue\n }\n const outline = HEAD_OUTLINES[head](x, y, angle, weight)\n if (containsByWinding([outline], 'NONZERO', point)) return true\n if (distanceToLines([[...outline, outline[0]]], point) <= pad) return true\n }\n return false\n}\n"],"mappings":";;;;AAaA,MAAM,gBAGF;CACF,mBAAmB;CACnB,iBAAiB;CACjB,gBAAgB;AAClB;;;;;;AAOA,SAAgB,eACd,SACA,KACA,QACA,OACA,KACS;CACT,KAAK,MAAM,EAAE,GAAG,GAAG,OAAO,KAAK,UAAU,sBAAsB,SAAS,GAAG,GAAG;EAC5E,IAAI,SAAS,iBAAiB;GAC5B,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,gBAAgB,MAAM,IAAI,KAAK,OAAO;GAClF;EACF;EACA,IAAI,SAAS,eAAe;GAE1B,IADc,mBAAmB,GAAG,GAAG,OAAO,MACtC,CAAC,CAAC,MAAM,SAAS,kBAAkB,OAAO,KAAK,MAAM,KAAK,EAAE,KAAK,SAAS,IAAI,GAAG,GACvF,OAAO;GAET;EACF;EACA,MAAM,UAAU,cAAc,KAAK,CAAC,GAAG,GAAG,OAAO,MAAM;EACvD,IAAI,kBAAkB,CAAC,OAAO,GAAG,WAAW,KAAK,GAAG,OAAO;EAC3D,IAAI,gBAAgB,CAAC,CAAC,GAAG,SAAS,QAAQ,EAAE,CAAC,GAAG,KAAK,KAAK,KAAK,OAAO;CACxE;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { Fill, SceneNode } from "../types.js";
|
|
3
|
+
//#region src/outline/hit.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether a paint makes its layer clickable, as in Figma: a visible paint that shows something.
|
|
6
|
+
* A paint at 0% opacity, or a gradient whose stops are all transparent, does not; 1% does, and
|
|
7
|
+
* the layer's own opacity does not matter.
|
|
8
|
+
*/
|
|
9
|
+
declare function isHitPaint(paint: Fill): boolean;
|
|
10
|
+
/** The farthest a layer's clickable strokes reach outside its box, in its own units. */
|
|
11
|
+
declare function strokeReach(node: SceneNode): number;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a click at the canvas point lands on the shape, as in Figma: inside the area a
|
|
14
|
+
* clickable fill covers, or on the band a clickable stroke draws, either grown by `pad` canvas
|
|
15
|
+
* units. A shape whose paints show nothing is never hit. Null for a layer without an outline to
|
|
16
|
+
* test, which is hit by its box.
|
|
17
|
+
*/
|
|
18
|
+
declare function hitsShape(graph: SceneGraph, node: SceneNode, px: number, py: number, pad?: number): boolean | null;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { hitsShape, isHitPaint, strokeReach };
|
|
21
|
+
//# sourceMappingURL=hit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit.d.ts","names":[],"sources":["../../src/outline/hit.ts"],"mappings":";;;;;;;;iBAuBgB,WAAW,OAAO;;iBAyBlB,YAAY,MAAM;;;;;;;iBAmTlB,UACd,OAAO,YACP,MAAM,WACN,YACA,YACA"}
|