@pairdraw/scene-graph 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/checkpoint.d.ts.map +1 -1
  2. package/dist/checkpoint.js +8 -3
  3. package/dist/checkpoint.js.map +1 -1
  4. package/dist/color/index.d.ts.map +1 -1
  5. package/dist/color/index.js +3 -3
  6. package/dist/color/index.js.map +1 -1
  7. package/dist/color/management.d.ts.map +1 -1
  8. package/dist/color/management.js +4 -2
  9. package/dist/color/management.js.map +1 -1
  10. package/dist/coordinate.d.ts.map +1 -1
  11. package/dist/coordinate.js +3 -1
  12. package/dist/coordinate.js.map +1 -1
  13. package/dist/copy.d.ts.map +1 -1
  14. package/dist/copy.js +1 -0
  15. package/dist/copy.js.map +1 -1
  16. package/dist/css/values.d.ts.map +1 -1
  17. package/dist/css/values.js +2 -2
  18. package/dist/css/values.js.map +1 -1
  19. package/dist/geometry.d.ts +14 -7
  20. package/dist/geometry.d.ts.map +1 -1
  21. package/dist/geometry.js +130 -26
  22. package/dist/geometry.js.map +1 -1
  23. package/dist/graph.d.ts.map +1 -1
  24. package/dist/graph.js +7 -3
  25. package/dist/graph.js.map +1 -1
  26. package/dist/hit-test.d.ts.map +1 -1
  27. package/dist/hit-test.js +100 -8
  28. package/dist/hit-test.js.map +1 -1
  29. package/dist/instances/content-size.js +1 -1
  30. package/dist/instances/index.d.ts.map +1 -1
  31. package/dist/instances/index.js +4 -1
  32. package/dist/instances/index.js.map +1 -1
  33. package/dist/instances/sync.js +4 -3
  34. package/dist/instances/sync.js.map +1 -1
  35. package/dist/layout/index.js +1 -1
  36. package/dist/resize.d.ts +4 -1
  37. package/dist/resize.d.ts.map +1 -1
  38. package/dist/resize.js +18 -12
  39. package/dist/resize.js.map +1 -1
  40. package/dist/scaling/node.d.ts.map +1 -1
  41. package/dist/scaling/node.js +3 -1
  42. package/dist/scaling/node.js.map +1 -1
  43. package/dist/scaling/tree.d.ts.map +1 -1
  44. package/dist/scaling/tree.js +8 -5
  45. package/dist/scaling/tree.js.map +1 -1
  46. package/dist/slots/authoring.js +3 -6
  47. package/dist/slots/authoring.js.map +1 -1
  48. package/dist/slots/content.d.ts.map +1 -1
  49. package/dist/slots/content.js +15 -25
  50. package/dist/slots/content.js.map +1 -1
  51. package/dist/slots/frames.js +1 -2
  52. package/dist/slots/frames.js.map +1 -1
  53. package/dist/snap.d.ts.map +1 -1
  54. package/dist/snap.js +12 -4
  55. package/dist/snap.js.map +1 -1
  56. package/dist/types.d.ts +5 -0
  57. package/dist/types.d.ts.map +1 -1
  58. package/dist/types.js.map +1 -1
  59. package/dist/undo.d.ts +2 -1
  60. package/dist/undo.d.ts.map +1 -1
  61. package/dist/undo.js +3 -2
  62. package/dist/undo.js.map +1 -1
  63. package/dist/variables/bindings.d.ts +2 -1
  64. package/dist/variables/bindings.d.ts.map +1 -1
  65. package/dist/variables/bindings.js +6 -2
  66. package/dist/variables/bindings.js.map +1 -1
  67. package/dist/variables/index.d.ts +2 -1
  68. package/dist/variables/index.d.ts.map +1 -1
  69. package/dist/variables/index.js +23 -5
  70. package/dist/variables/index.js.map +1 -1
  71. package/dist/variables/units.d.ts +31 -0
  72. package/dist/variables/units.d.ts.map +1 -0
  73. package/dist/variables/units.js +79 -4
  74. package/dist/variables/units.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/checkpoint.ts +8 -2
  77. package/src/color/index.ts +3 -6
  78. package/src/color/management.ts +8 -2
  79. package/src/coordinate.ts +4 -1
  80. package/src/copy.ts +2 -0
  81. package/src/css/values.ts +3 -2
  82. package/src/geometry.ts +147 -24
  83. package/src/graph.ts +9 -3
  84. package/src/hit-test.ts +138 -16
  85. package/src/instances/index.ts +5 -1
  86. package/src/instances/sync.ts +5 -3
  87. package/src/resize.ts +40 -20
  88. package/src/scaling/node.ts +3 -1
  89. package/src/scaling/tree.ts +3 -2
  90. package/src/slots/authoring.ts +7 -7
  91. package/src/slots/content.ts +13 -19
  92. package/src/slots/frames.ts +3 -3
  93. package/src/snap.ts +14 -4
  94. package/src/types.ts +5 -0
  95. package/src/undo.ts +3 -2
  96. package/src/variables/bindings.ts +6 -2
  97. package/src/variables/index.ts +29 -6
  98. package/src/variables/units.ts +97 -4
@@ -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 { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => 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\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n 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 // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>\n): 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 matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n if (replacements.has(instChildMap.get(mappedComponentId)?.id ?? '')) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n 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 // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: (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(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO,OAAO;AAChB;AAEA,SAAgB,SACd,QACA,QACA,KACM;CACN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IAAI,WAAW;EAC9C,IAAI,CAAC,aAAa,CAAC,WAAW;EAG9B,IAAI,gBAAgB,OAAO,UAAU,EAAE,MAAM,KAAA,GAAW;EAExD,MAAM,iBAAiB,uBAAuB,OAAO,WAAW,SAAS;EACzE,MAAM,SAAS,qBAAqB,OAAO,WAAW,SAAS;EAC/D,MAAM,iBACH,UAAU,iBAAiB,WAAW,iBAAkB,WAAW;EAEtE,MAAM,SAAS,0BADS,wBAAwB,OAAO,WAAW,SACX,GAAG,cAAc;EAGxE,MAAM,UAA8B;GAClC;GACA,6BAA6B,gBAAgB,UAAU,2BAA2B;EACpF;EACA,kBAAkB,WAAW,QAAQ,SAAS,cAAc;EAC5D,uBACE,WACA,QACA,UACC,UAAU,OAAO,IAAI,KAAK,KAAK,eAAe,KAAK,CACtD;EACA,MAAM,YAAY,iBAAiB,SAAS,WAAW,QAAQ;GAC7D;GACA;GACA,QAAQ,iBAAiB,UAAU;GACnC,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,qBACE,OACA,YACA,cACA,WAAW,UACX,WACA,YACF;AACF"}
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 { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => 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\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n const scaled = scaleNodeChanges(source, factor, true)\n return {\n ...source,\n ...scaled,\n ...scaleVariableBindingUnits(source, factor, scaled.styleRuns)\n }\n}\n\ninterface SyncedFieldsInput {\n compParent: SceneNode\n instParent: SceneNode\n /** The component's coordinates in the copy's. */\n factor: number\n /** Fields the copy keeps: overridden, bound, or driven by a property. */\n skip: (key: string) => boolean\n}\n\n/** The fields a copy takes from its component's layer, placed in the copy's parent. */\nfunction copySyncedFields(\n updates: Partial<SceneNode>,\n copy: SceneNode,\n source: SceneNode,\n { compParent, instParent, factor, skip }: SyncedFieldsInput\n): SyncedPlacement {\n // In an auto layout flow the layout places the copy, as it placed the component's layer.\n const placedByLayout = instParent.layoutMode !== 'NONE' && source.layoutPositioning !== 'ABSOLUTE'\n const placed = placedByLayout\n ? source\n : placedByConstraints(source, compParent, instParent, factor)\n for (const key of INSTANCE_SYNC_FIELDS) {\n // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>\n): 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 matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n // The first copy of a layer keeps it; a duplicate stays unmatched for the sync to remove.\n if (instChildMap.has(mappedComponentId)) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n 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 // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: (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(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,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,IAAI,QAAQ,kBAAkB;EAEnC,aAAa,QAAQ,KAAK,EAAE,G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AClC;GACA,6BAA6B,gBAAgB,UAAU,2BAA2B;EACpF;EACA,kBAAkB,WAAW,QAAQ,SAAS,cAAc;EAC5D,uBACE,WACA,QACA,UACC,UAAU,OAAO,IAAI,KAAK,KAAK,eAAe,KAAK,CACtD;EACA,MAAM,YAAY,iBAAiB,SAAS,WAAW,QAAQ;GAC7D;GACA;GACA,QAAQ,iBAAiB,UAAU;GACnC,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,qBACE,OACA,YACA,cACA,WAAW,UACX,WACA,YACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
2
1
  import { aspectRatioLockEditable, enforcedAspectRatio, lockedAspectRatioTarget, recapturedAspectRatio, sizeKeepingAspectRatio } from "./aspect-ratio.js";
2
+ import { autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
3
3
  import { paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign } from "./keywords.js";
4
4
  import { AUTO_LAYOUT_GRID_COUNT, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections } from "./guides.js";
5
5
  export { AUTO_LAYOUT_GRID_COUNT, aspectRatioLockEditable, autoLayoutSizingFields, enforcedAspectRatio, fillSizingFields, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
package/dist/resize.d.ts CHANGED
@@ -34,8 +34,11 @@ declare function createResizeSnapshot(node: SceneNode): ResizeSnapshot;
34
34
  * OUTSIDE outlines look massively thick (DomeSticker resize bug).
35
35
  */
36
36
  declare function scaledGeometryChanges(orig: Pick<ResizeSnapshot, 'type' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>, origWidth: number, origHeight: number, width: number, height: number): Partial<SceneNode>;
37
+ type PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>;
38
+ /** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */
39
+ declare function scaledPathTextChanges(orig: PathTextFields, sx: number, sy: number): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'>;
37
40
  declare function collectResizeDescendants(graph: ResizeGraph, rootId: string): Map<string, ResizeSnapshot> | null;
38
41
  declare function computeConstrainedResizeChanges(graph: ResizeGraph, rootId: string, rootBefore: Pick<Rect, 'width' | 'height'>, rootAfter: Pick<Rect, 'width' | 'height'>, originals: ReadonlyMap<string, ResizeSnapshot>): Map<string, Partial<SceneNode>>;
39
42
  //#endregion
40
- export { ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
43
+ export { ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges };
41
44
  //# sourceMappingURL=resize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAkBY,iBAAiB,KAC3B;UAeQ;EACR,QAAQ,aAAa;;;iBA8CP,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;iBAyBa,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;;;;;;;;iBAuCa,2BACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAgBa,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBAIa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA8Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAkDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;iBAqDK,yBACd,OAAO,aACP,iBACC,YAAY;iBAoBC,gCACd,OAAO,aACP,gBACA,YAAY,KAAK,2BACjB,WAAW,KAAK,2BAChB,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
1
+ {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAkBY,iBAAiB,KAC3B;UAeQ;EACR,QAAQ,aAAa;;;iBA8CP,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;iBAyBa,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;;;;;;;;iBAuCa,2BACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAgBa,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBAIa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA8Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAkDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;KAmCN,iBAAiB,KAAK;;iBAeX,sBACd,MAAM,gBACN,YACA,aACC,KAAK,QAAQ;iBAmBA,yBACd,OAAO,aACP,iBACC,YAAY;iBAoBC,gCACd,OAAO,aACP,gBACA,YAAY,KAAK,2BACjB,WAAW,KAAK,2BAChB,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
package/dist/resize.js CHANGED
@@ -225,18 +225,24 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
225
225
  if (orig.fillGeometry.length > 0) changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy);
226
226
  const outlineOnly = orig.type === "TEXT" || orig.type === "VECTOR" && !hasPath(orig);
227
227
  if (orig.strokeGeometry.length > 0) changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : [];
228
+ Object.assign(changes, scaledPathTextChanges(orig, sx, sy));
229
+ if (orig.strokes.length > 0 && isScaledPathText(orig)) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
230
+ return changes;
231
+ }
232
+ function isScaledPathText(orig) {
228
233
  const glyphs = orig.derivedTextGlyphs ?? [];
229
- const pathText = !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
230
- if (glyphs.length > 0 && pathText) {
231
- changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy);
232
- if (orig.textPathBox) changes.textPathBox = {
233
- x: orig.textPathBox.x * sx,
234
- y: orig.textPathBox.y * sy,
235
- width: orig.textPathBox.width * sx,
236
- height: orig.textPathBox.height * sy
237
- };
238
- }
239
- if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
234
+ return glyphs.length > 0 && (!!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0));
235
+ }
236
+ /** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */
237
+ function scaledPathTextChanges(orig, sx, sy) {
238
+ if (!isScaledPathText(orig)) return {};
239
+ const changes = { derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy) };
240
+ if (orig.textPathBox) changes.textPathBox = {
241
+ x: orig.textPathBox.x * sx,
242
+ y: orig.textPathBox.y * sy,
243
+ width: orig.textPathBox.width * sx,
244
+ height: orig.textPathBox.height * sy
245
+ };
240
246
  return changes;
241
247
  }
242
248
  function collectResizeDescendants(graph, rootId) {
@@ -283,6 +289,6 @@ function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, o
283
289
  return changes;
284
290
  }
285
291
  //#endregion
286
- export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
292
+ export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges };
287
293
 
288
294
  //# sourceMappingURL=resize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = parentAfter - parentBefore\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') return { position: position + delta / 2, size }\n if (constraint === 'STRETCH') return { position, size: Math.max(1, size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: Math.max(1, size * scale) }\n }\n return { position, size }\n}\n\ntype AxisPlacement = { position: number; size: number }\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal)\n let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical)\n ;({ x, y } = keepLockedRatio(x, y, horizontal, vertical, aspectRatio))\n return {\n x: Math.round(x.position),\n y: Math.round(y.position),\n width: Math.round(x.size),\n height: Math.round(y.size)\n }\n}\n\nfunction layoutConstrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') return { position, size: Math.abs(size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: Math.round(position * scale * 128) / 128, size: size * scale }\n }\n return { position, size }\n}\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not\n * rounded, so applying a run of changes one at a time lands where applying them at once does.\n */\nexport function layoutConstrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n const placed = keepLockedRatio(\n layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n return {\n x: placed.x.position,\n y: placed.y.position,\n width: placed.x.size,\n height: placed.y.size\n }\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const glyphs = orig.derivedTextGlyphs ?? []\n const pathText =\n !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n if (glyphs.length > 0 && pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const childChanges: Partial<SceneNode> = {\n ...rect,\n ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? rect : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"mappings":";;;;AAsCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBACP,UACA,MACA,cACA,aACA,YACoC;CACpC,MAAM,QAAQ,cAAc;CAC5B,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,WAAW,QAAQ;EAAG;CAAK;CAC3E,IAAI,eAAe,WAAW,OAAO;EAAE;EAAU,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;CAAE;CACjF,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;EAAE;CACvE;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAIA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO,CAAC;;AAGtF,SAAS,eACP,QACA,MACA,YACe;CACf,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,OAAO,WAAW,OAAO,OAAO;EAAM;CAAK;CACxF,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,OAAO,YAAY,OAAO,OAAO,QAAQ;EAAG;CAAK;CACjG,OAAO;EAAE,UAAU,OAAO;EAAU;CAAK;AAC3C;;AAGA,SAAgB,iBACd,QACA,MACA,YACA,UACM;CACN,MAAM,IAAI,eAAe;EAAE,UAAU,OAAO;EAAG,MAAM,OAAO;CAAM,GAAG,KAAK,OAAO,UAAU;CAC3F,MAAM,IAAI,eAAe;EAAE,UAAU,OAAO;EAAG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ACrC,IAAI,CAAC,QAAQ;EACb,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,OAAO;GACZ,UAAU,IAAI,SAAS,qBAAqB,KAAK,CAAC;GAClD,QAAQ,OAAO;EACjB;CACF;CAEA,QAAQ,MAAM;CACd,OAAO,UAAU,OAAO,IAAI,YAAY;AAC1C;AAEA,SAAgB,gCACd,OACA,QACA,YACA,WACA,WACiC;CACjC,MAAM,0BAAU,IAAI,IAAgC;CAEpD,MAAM,WACJ,UACA,cACA,gBACG;EACH,MAAM,SAAS,MAAM,QAAQ,QAAQ;EACrC,IAAI,CAAC,QAAQ;EACb,MAAM,iBAAiB,OAAO,SAAS,WAAW,OAAO,SAAS;EAClE,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,WAAW,UAAU,IAAI,OAAO;GACtC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,YAAY,CAAC,OAAO;GAEzB,IADiB,OAAO,eAAe,UAAU,MAAM,sBAAsB,YAC/D;IACZ,QAAQ,SAAS,UAAU,KAAK;IAChC;GACF;GACA,MAAM,OAAO,iBACT,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B;GACJ,MAAM,eAAmC;IACvC,GAAG;IACH,GAAG,sBAAsB,UAAU,SAAS,OAAO,SAAS,QAAQ,KAAK,OAAO,KAAK,MAAM;GAC7F;GACA,QAAQ,IAAI,SAAS,YAAY;GAEjC,QAAQ,SAAS,UAAU,MAAM,eAAe,SAAS,OAAO,KAAK;EACvE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
1
+ {"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\nimport { cloneVectorNetwork } from './vector-network'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = parentAfter - parentBefore\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') return { position: position + delta / 2, size }\n if (constraint === 'STRETCH') return { position, size: Math.max(1, size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: Math.max(1, size * scale) }\n }\n return { position, size }\n}\n\ntype AxisPlacement = { position: number; size: number }\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal)\n let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical)\n ;({ x, y } = keepLockedRatio(x, y, horizontal, vertical, aspectRatio))\n return {\n x: Math.round(x.position),\n y: Math.round(y.position),\n width: Math.round(x.size),\n height: Math.round(y.size)\n }\n}\n\nfunction layoutConstrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') return { position, size: Math.abs(size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: Math.round(position * scale * 128) / 128, size: size * scale }\n }\n return { position, size }\n}\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not\n * rounded, so applying a run of changes one at a time lands where applying them at once does.\n */\nexport function layoutConstrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n const placed = keepLockedRatio(\n layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n return {\n x: placed.x.position,\n y: placed.y.position,\n width: placed.x.size,\n height: placed.y.size\n }\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n Object.assign(changes, scaledPathTextChanges(orig, sx, sy))\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && isScaledPathText(orig)) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\ntype PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n\n// Path text scales with its path, including baked path text that kept only rotated glyphs;\n// other text reflows in the new box, so its glyphs are dropped.\nfunction isScaledPathText(orig: PathTextFields): boolean {\n const glyphs = orig.derivedTextGlyphs ?? []\n return (\n glyphs.length > 0 &&\n (!!orig.textPathData ||\n !!orig.textPathBox ||\n glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0))\n )\n}\n\n/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */\nexport function scaledPathTextChanges(\n orig: PathTextFields,\n sx: number,\n sy: number\n): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> {\n if (!isScaledPathText(orig)) return {}\n const changes: Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> = {\n derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy)\n }\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const childChanges: Partial<SceneNode> = {\n ...rect,\n ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? rect : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"mappings":";;;;AAsCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBACP,UACA,MACA,cACA,aACA,YACoC;CACpC,MAAM,QAAQ,cAAc;CAC5B,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,WAAW,QAAQ;EAAG;CAAK;CAC3E,IAAI,eAAe,WAAW,OAAO;EAAE;EAAU,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;CAAE;CACjF,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;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MAAM,WAAW,UAAU,IAAI,OAAO;GACtC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,YAAY,CAAC,OAAO;GAEzB,IADiB,OAAO,eAAe,UAAU,MAAM,sBAAsB,YAC/D;IACZ,QAAQ,SAAS,UAAU,KAAK;IAChC;GACF;GACA,MAAM,OAAO,iBACT,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B;GACJ,MAAM,eAAmC;IACvC,GAAG;IACH,GAAG,sBAAsB,UAAU,SAAS,OAAO,SAAS,QAAQ,KAAK,OAAO,KAAK,MAAM;GAC7F;GACA,QAAQ,IAAI,SAAS,YAAY;GAEjC,QAAQ,SAAS,UAAU,MAAM,eAAe,SAAS,OAAO,KAAK;EACvE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAiHgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
1
+ {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAkHgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
@@ -1,6 +1,7 @@
1
1
  import { scaledTextLength } from "../text/lengths.js";
2
2
  import { cloneVectorNetwork } from "../vector-network.js";
3
3
  import { scaleGeometryPaths } from "../copy.js";
4
+ import { scaledPathTextChanges } from "../resize.js";
4
5
  import { TEXT_PARAGRAPH_SPACING_FIELDS } from "../text/paragraphs.js";
5
6
  //#region src/scaling/node.ts
6
7
  function scaledOptional(value, scale) {
@@ -141,7 +142,8 @@ function scaleNodeChanges(node, scale, scalePosition) {
141
142
  layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),
142
143
  vectorNetwork: scaledVectorNetwork(node, scale),
143
144
  fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
144
- strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)
145
+ strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),
146
+ ...scaledPathTextChanges(node, scale, scale)
145
147
  };
146
148
  }
147
149
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own; only a shadow's measures follow the layer.\n if (copy.type === 'SHADER') return copy\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)\n }\n}\n"],"mappings":";;;;;AAeA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,WAAW;EAC7B,MAAM,OAAO,gBAAgB,MAAM;EAEnC,IAAI,KAAK,SAAS,UAAU,OAAO;EACnC,KAAK,SAAS;GAAE,GAAG,KAAK,OAAO,IAAI;GAAO,GAAG,KAAK,OAAO,IAAI;EAAM;EACnE,KAAK,UAAU;EACf,KAAK,UAAU;EACf,OAAO;CACT,CAAC;AACH;AAEA,SAAS,YAAY,OAAwB,OAAuB;CAClE,OAAO,MAAM,KAAK,UAAU;EAC1B,GAAG,gBAAgB,IAAI;EACvB,OAAO,KAAK,SAAS,OAAO,KAAA,IAAY,KAAK,QAAQ;EACrD,SAAS,KAAK,WAAW,OAAO,KAAA,IAAY,KAAK,UAAU;EAC3D,gBAAgB,KAAK,iBACjB;GAAE,GAAG,KAAK,eAAe,IAAI;GAAO,GAAG,KAAK,eAAe,IAAI;EAAM,IACrE,KAAA;EACJ,WAAW,KAAK,YACZ;GAAE,GAAG,KAAK,UAAU,IAAI;GAAO,GAAG,KAAK,UAAU,IAAI;EAAM,IAC3D,KAAA;CACN,EAAE;AACJ;AAEA,SAAS,gBAAgB,WAAgC,OAA2B;CAClF,OAAO,UAAU,KAAK,SAAS;EAC7B,GAAG,gBAAgB,GAAG;EACtB,OAAO;GACL,GAAG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AiB,KAAK,kBAAkB,KAAK;EAC/D,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;CACtE;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { scaleGeometryPaths } from '../copy'\nimport { scaledPathTextChanges } from '../resize'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own; only a shadow's measures follow the layer.\n if (copy.type === 'SHADER') return copy\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),\n ...scaledPathTextChanges(node, scale, scale)\n }\n}\n"],"mappings":";;;;;;AAgBA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,WAAW;EAC7B,MAAM,OAAO,gBAAgB,MAAM;EAEnC,IAAI,KAAK,SAAS,UAAU,OAAO;EACnC,KAAK,SAAS;GAAE,GAAG,KAAK,OAAO,IAAI;GAAO,GAAG,KAAK,OAAO,IAAI;EAAM;EACnE,KAAK,UAAU;EACf,KAAK,UAAU;EACf,OAAO;CACT,CAAC;AACH;AAEA,SAAS,YAAY,OAAwB,OAAuB;CAClE,OAAO,MAAM,KAAK,UAAU;EAC1B,GAAG,gBAAgB,IAAI;EACvB,OAAO,KAAK,SAAS,OAAO,KAAA,IAAY,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BAAgB,OAAO,YAAY,gBAAgB"}
1
+ {"version":3,"file":"tree.d.ts","names":[],"sources":["../../src/scaling/tree.ts"],"mappings":";;;;cAOa;;iBAmBG,aAAa,MAAM,KAAK;;iBAKxB,eAAe,OAAO,YAAY,MAAM,YAAY;;;;;;iBAmBpD,uBACd,OAAO,YACP,gBAAgB,aAChB,gBACA,gBACC,YAAY,QAAQ;;iBAgBP,oBAAoB;;iBAMpB,gBAAgB,OAAO,YAAY,gBAAgB"}
@@ -45,11 +45,14 @@ function rescaleSubtree(graph, root) {
45
45
  */
46
46
  function rescaleNodeTreeChanges(graph, nodes, rootId, scale) {
47
47
  const changes = /* @__PURE__ */ new Map();
48
- for (const node of nodes) changes.set(node.id, {
49
- ...scaleNodeChanges(node, scale, node.id !== rootId),
50
- ...scaleVariableBindingUnits(node, scale),
51
- componentScale: findInstanceAncestor(graph, node.id) ? node.componentScale * scale : node.componentScale
52
- });
48
+ for (const node of nodes) {
49
+ const scaled = scaleNodeChanges(node, scale, node.id !== rootId);
50
+ changes.set(node.id, {
51
+ ...scaled,
52
+ ...scaleVariableBindingUnits(node, scale, scaled.styleRuns),
53
+ componentScale: findInstanceAncestor(graph, node.id) ? node.componentScale * scale : node.componentScale
54
+ });
55
+ }
53
56
  return changes;
54
57
  }
55
58
  /** Throws unless `scale` is a factor a layer can be scaled by. */
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","names":[],"sources":["../../src/scaling/tree.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { scaleNodeChanges } from './node'\n\n/** The smallest factor a layer scales by, so it never folds away. */\nexport const MIN_RESCALE = 0.01\nconst RESCALABLE_NODE_TYPES = new Set<SceneNode['type']>([\n 'BOOLEAN_OPERATION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'ELLIPSE',\n 'FRAME',\n 'GROUP',\n 'INSTANCE',\n 'LINE',\n 'POLYGON',\n 'RECTANGLE',\n 'STAR',\n 'STICKY',\n 'TEXT',\n 'VECTOR'\n])\n\n/** Whether a layer scales with its contents, as Figma's Scale tool and `rescale()` allow. */\nexport function isRescalable(node: Pick<SceneNode, 'type'>): boolean {\n return RESCALABLE_NODE_TYPES.has(node.type)\n}\n\n/** A layer and every layer below it, root first, as the graph holds them now. */\nexport function rescaleSubtree(graph: SceneGraph, root: SceneNode): SceneNode[] {\n const nodes: SceneNode[] = [root]\n const collect = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n nodes.push(child)\n collect(child)\n }\n }\n collect(root)\n return nodes\n}\n\n/**\n * What scaling `nodes`, a subtree as `rescaleSubtree` lists it, by `scale` changes in each layer,\n * keeping the root's top-left; read from the given copies, so a preview can scale again from the\n * layers as they were.\n */\nexport function rescaleNodeTreeChanges(\n graph: SceneGraph,\n nodes: readonly SceneNode[],\n rootId: string,\n scale: number\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n for (const node of nodes) {\n changes.set(node.id, {\n ...scaleNodeChanges(node, scale, node.id !== rootId),\n ...scaleVariableBindingUnits(node, scale),\n componentScale: findInstanceAncestor(graph, node.id)\n ? node.componentScale * scale\n : node.componentScale\n })\n }\n return changes\n}\n\n/** Throws unless `scale` is a factor a layer can be scaled by. */\nexport function assertRescaleFactor(scale: number): void {\n if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')\n if (scale < MIN_RESCALE) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`)\n}\n\n/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */\nexport function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void {\n assertRescaleFactor(scale)\n const root = graph.getNode(rootId)\n if (!root || !isRescalable(root)) throw new Error('rescale() is not supported on this node')\n const nodes = rescaleSubtree(graph, root)\n for (const [id, changes] of rescaleNodeTreeChanges(graph, nodes, rootId, scale)) {\n graph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,MAAM,CAAC,IAAI,YAAY,uBAAuB,OAAO,OAAO,QAAQ,KAAK,GAC5E,MAAM,WAAW,IAAI,OAAO;AAEhC"}
1
+ {"version":3,"file":"tree.js","names":[],"sources":["../../src/scaling/tree.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { scaleNodeChanges } from './node'\n\n/** The smallest factor a layer scales by, so it never folds away. */\nexport const MIN_RESCALE = 0.01\nconst RESCALABLE_NODE_TYPES = new Set<SceneNode['type']>([\n 'BOOLEAN_OPERATION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'ELLIPSE',\n 'FRAME',\n 'GROUP',\n 'INSTANCE',\n 'LINE',\n 'POLYGON',\n 'RECTANGLE',\n 'STAR',\n 'STICKY',\n 'TEXT',\n 'VECTOR'\n])\n\n/** Whether a layer scales with its contents, as Figma's Scale tool and `rescale()` allow. */\nexport function isRescalable(node: Pick<SceneNode, 'type'>): boolean {\n return RESCALABLE_NODE_TYPES.has(node.type)\n}\n\n/** A layer and every layer below it, root first, as the graph holds them now. */\nexport function rescaleSubtree(graph: SceneGraph, root: SceneNode): SceneNode[] {\n const nodes: SceneNode[] = [root]\n const collect = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n nodes.push(child)\n collect(child)\n }\n }\n collect(root)\n return nodes\n}\n\n/**\n * What scaling `nodes`, a subtree as `rescaleSubtree` lists it, by `scale` changes in each layer,\n * keeping the root's top-left; read from the given copies, so a preview can scale again from the\n * layers as they were.\n */\nexport function rescaleNodeTreeChanges(\n graph: SceneGraph,\n nodes: readonly SceneNode[],\n rootId: string,\n scale: number\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n for (const node of nodes) {\n const scaled = scaleNodeChanges(node, scale, node.id !== rootId)\n changes.set(node.id, {\n ...scaled,\n ...scaleVariableBindingUnits(node, scale, scaled.styleRuns),\n componentScale: findInstanceAncestor(graph, node.id)\n ? node.componentScale * scale\n : node.componentScale\n })\n }\n return changes\n}\n\n/** Throws unless `scale` is a factor a layer can be scaled by. */\nexport function assertRescaleFactor(scale: number): void {\n if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')\n if (scale < MIN_RESCALE) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`)\n}\n\n/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */\nexport function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void {\n assertRescaleFactor(scale)\n const root = graph.getNode(rootId)\n if (!root || !isRescalable(root)) throw new Error('rescale() is not supported on this node')\n const nodes = rescaleSubtree(graph, root)\n for (const [id, changes] of rescaleNodeTreeChanges(graph, nodes, rootId, scale)) {\n graph.updateNode(id, changes)\n }\n}\n"],"mappings":";;;;;AAOA,MAAa,cAAc;AAC3B,MAAM,wCAAwB,IAAI,IAAuB;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,aAAa,MAAwC;CACnE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;;AAGA,SAAgB,eAAe,OAAmB,MAA8B;CAC9E,MAAM,QAAqB,CAAC,IAAI;CAChC,MAAM,WAAW,SAA0B;EACzC,KAAK,MAAM,WAAW,KAAK,UAAU;GACnC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,OAAO;GACZ,MAAM,KAAK,KAAK;GAChB,QAAQ,KAAK;EACf;CACF;CACA,QAAQ,IAAI;CACZ,OAAO;AACT;;;;;;AAOA,SAAgB,uBACd,OACA,OACA,QACA,OACiC;CACjC,MAAM,0BAAU,IAAI,IAAgC;CACpD,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,SAAS,iBAAiB,MAAM,OAAO,KAAK,OAAO,MAAM;EAC/D,QAAQ,IAAI,KAAK,IAAI;GACnB,GAAG;GACH,GAAG,0BAA0B,MAAM,OAAO,OAAO,SAAS;GAC1D,gBAAgB,qBAAqB,OAAO,KAAK,EAAE,IAC/C,KAAK,iBAAiB,QACtB,KAAK;EACX,CAAC;CACH;CACA,OAAO;AACT;;AAGA,SAAgB,oBAAoB,OAAqB;CACvD,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,+BAA+B;CAChF,IAAI,QAAA,KAAqB,MAAM,IAAI,WAAW,0BAA0B,aAAa;AACvF;;AAGA,SAAgB,gBAAgB,OAAmB,QAAgB,OAAqB;CACtF,oBAAoB,KAAK;CACzB,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,MAAM,IAAI,MAAM,yCAAyC;CAC3F,MAAM,QAAQ,eAAe,OAAO,IAAI;CACxC,KAAK,MAAM,CAAC,IAAI,YAAY,uBAAuB,OAAO,OAAO,QAAQ,KAAK,GAC5E,MAAM,WAAW,IAAI,OAAO;AAEhC"}
@@ -12,12 +12,9 @@ const DEFAULT_SLOT_SETTINGS = {
12
12
  * instance are not authored there, so a layer under an instance has none.
13
13
  */
14
14
  function slotOwner(graph, node) {
15
- let current = node.parentId ? graph.getNode(node.parentId) : void 0;
16
- while (current && current.type !== "CANVAS") {
17
- if (current.type === "COMPONENT") return current;
18
- if (current.type === "INSTANCE") return void 0;
19
- current = current.parentId ? graph.getNode(current.parentId) : void 0;
20
- }
15
+ if (!node.parentId) return void 0;
16
+ const owner = graph.closest(node.parentId, (current) => current.type === "COMPONENT" || current.type === "INSTANCE" || current.type === "CANVAS");
17
+ return owner?.type === "COMPONENT" ? owner : void 0;
21
18
  }
22
19
  /** Whether a frame inside a main component can become a slot. */
23
20
  function canCreateSlot(graph, node) {
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { numberedName } from '../naming'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to, which defines the slots inside it. Layers of an\n * instance are not authored there, so a layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = node.parentId ? graph.getNode(node.parentId) : undefined\n while (current && current.type !== 'CANVAS') {\n if (current.type === 'COMPONENT') return current\n if (current.type === 'INSTANCE') return undefined\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n return numberedName(\n base,\n owner.componentPropertyDefinitions.map((definition) => definition.name)\n )\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;;AAMA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;AAMA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,UAAU,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,WAAW,QAAQ,SAAS,UAAU;EAC3C,IAAI,QAAQ,SAAS,aAAa,OAAO;EACzC,IAAI,QAAQ,SAAS,YAAY,OAAO,KAAA;EACxC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ,QAAQ,IAAI,KAAA;CACjE;AAEF;;AAGA,SAAgB,cAAc,OAAmB,MAA0B;CACzE,OAAO,KAAK,SAAS,WAAW,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,UAAU,OAAO,IAAI;AAClF;AAEA,SAAS,eAAe,OAAkB,MAAsB;CAC9D,OAAO,aACL,MACA,MAAM,6BAA6B,KAAK,eAAe,WAAW,IAAI,CACxE;AACF;;;;;;AAOA,SAAgB,mBACd,OACA,SACA,IACoC;CACpC,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,QAAQ,SAAS,cAAc,OAAO,KAAK,IAAI,UAAU,OAAO,KAAK,IAAI,KAAA;CAC/E,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO;CAC7B,MAAM,aAA0C;EAC9C;EACA,MAAM,eAAe,OAAO,MAAM,KAAK,KAAK,KAAK,MAAM;EACvD,MAAM;EACN,cAAc;EACd,iBAAiB,CAAC;EAClB,cAAc,EAAE,GAAG,sBAAsB;CAC3C;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,CAAC,GAAG,MAAM,8BAA8B,UAAU,EAClF,CAAC;CACD,MAAM,WAAW,MAAM,IAAI,EACzB,6BAA6B,CAC3B,GAAG,MAAM,6BACT;EAAE,YAAY;EAAI,OAAO;CAAe,CAC1C,EACF,CAAC;CACD,OAAO;AACT;;AAQA,SAAgB,mBACd,OACA,SACA,YACA,OACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,UAAU,OAAO,6BAA6B,MACjD,eAAe,WAAW,OAAO,cAAc,WAAW,SAAS,MACtE;CACA,IAAI,CAAC,SAAS,CAAC,SAAS,OAAO;CAC/B,MAAM,EAAE,cAAc,GAAG,WAAW;CACpC,MAAM,OAAoC;EACxC,GAAG;EACH,GAAG;EACH,cAAc;GAAE,GAAG;GAAuB,GAAG,QAAQ;GAAc,GAAG;EAAa;CACrF;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,KAAK,eACpE,WAAW,OAAO,aAAa,OAAO,UACxC,EACF,CAAC;CACD,OAAO;AACT"}
1
+ {"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { numberedName } from '../naming'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to, which defines the slots inside it. Layers of an\n * instance are not authored there, so a layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n if (!node.parentId) return undefined\n const owner = graph.closest(\n node.parentId,\n (current) =>\n current.type === 'COMPONENT' || current.type === 'INSTANCE' || current.type === 'CANVAS'\n )\n return owner?.type === 'COMPONENT' ? owner : undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n return numberedName(\n base,\n owner.componentPropertyDefinitions.map((definition) => definition.name)\n )\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;;AAMA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;AAMA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,CAAC,KAAK,UAAU,OAAO,KAAA;CAC3B,MAAM,QAAQ,MAAM,QAClB,KAAK,WACJ,YACC,QAAQ,SAAS,eAAe,QAAQ,SAAS,cAAc,QAAQ,SAAS,QACpF;CACA,OAAO,OAAO,SAAS,cAAc,QAAQ,KAAA;AAC/C;;AAGA,SAAgB,cAAc,OAAmB,MAA0B;CACzE,OAAO,KAAK,SAAS,WAAW,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,UAAU,OAAO,IAAI;AAClF;AAEA,SAAS,eAAe,OAAkB,MAAsB;CAC9D,OAAO,aACL,MACA,MAAM,6BAA6B,KAAK,eAAe,WAAW,IAAI,CACxE;AACF;;;;;;AAOA,SAAgB,mBACd,OACA,SACA,IACoC;CACpC,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,QAAQ,SAAS,cAAc,OAAO,KAAK,IAAI,UAAU,OAAO,KAAK,IAAI,KAAA;CAC/E,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO;CAC7B,MAAM,aAA0C;EAC9C;EACA,MAAM,eAAe,OAAO,MAAM,KAAK,KAAK,KAAK,MAAM;EACvD,MAAM;EACN,cAAc;EACd,iBAAiB,CAAC;EAClB,cAAc,EAAE,GAAG,sBAAsB;CAC3C;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,CAAC,GAAG,MAAM,8BAA8B,UAAU,EAClF,CAAC;CACD,MAAM,WAAW,MAAM,IAAI,EACzB,6BAA6B,CAC3B,GAAG,MAAM,6BACT;EAAE,YAAY;EAAI,OAAO;CAAe,CAC1C,EACF,CAAC;CACD,OAAO;AACT;;AAQA,SAAgB,mBACd,OACA,SACA,YACA,OACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,UAAU,OAAO,6BAA6B,MACjD,eAAe,WAAW,OAAO,cAAc,WAAW,SAAS,MACtE;CACA,IAAI,CAAC,SAAS,CAAC,SAAS,OAAO;CAC/B,MAAM,EAAE,cAAc,GAAG,WAAW;CACpC,MAAM,OAAoC;EACxC,GAAG;EACH,GAAG;EACH,cAAc;GAAE,GAAG;GAAuB,GAAG,QAAQ;GAAc,GAAG;EAAa;CACrF;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,KAAK,eACpE,WAAW,OAAO,aAAa,OAAO,UACxC,EACF,CAAC;CACD,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAcY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAYb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAmChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAwCd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAYd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
1
+ {"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAcY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAQb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAiChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAwCd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAYd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
@@ -3,34 +3,24 @@ import { isGeneratedFrame } from "../generated/index.js";
3
3
  import { ownsSlotContent, slotPropertyId } from "./frames.js";
4
4
  import { cloneChildrenWithMapping } from "../instances/sync.js";
5
5
  //#region src/slots/content.ts
6
- function parentOf(graph, node) {
7
- return node.parentId ? graph.nodes.get(node.parentId) : void 0;
8
- }
9
6
  function nearestInstance(graph, node) {
10
- let current = parentOf(graph, node);
11
- while (current && current.type !== "INSTANCE") current = parentOf(graph, current);
12
- return current;
7
+ return node.parentId ? graph.closest(node.parentId, (current) => current.type === "INSTANCE") : void 0;
13
8
  }
14
9
  function slotScope(graph, parentId) {
15
- let current = graph.nodes.get(parentId);
16
- while (current) {
17
- const propertyId = slotPropertyId(current);
18
- if (propertyId) {
19
- const instance = nearestInstance(graph, current);
20
- return instance ? {
21
- kind: "slot",
22
- frame: current,
23
- instance,
24
- propertyId
25
- } : { kind: "free" };
26
- }
27
- if (current.type === "INSTANCE" || isGeneratedFrame(current)) return {
28
- kind: "locked",
29
- owner: current
30
- };
31
- current = parentOf(graph, current);
32
- }
33
- return { kind: "free" };
10
+ const owner = graph.closest(parentId, (current) => !!slotPropertyId(current) || current.type === "INSTANCE" || isGeneratedFrame(current));
11
+ if (!owner) return { kind: "free" };
12
+ const propertyId = slotPropertyId(owner);
13
+ if (!propertyId) return {
14
+ kind: "locked",
15
+ owner
16
+ };
17
+ const instance = nearestInstance(graph, owner);
18
+ return instance ? {
19
+ kind: "slot",
20
+ frame: owner,
21
+ instance,
22
+ propertyId
23
+ } : { kind: "free" };
34
24
  }
35
25
  /** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */
36
26
  function descendants(graph, node, enterInstances) {