@pairdraw/scene-graph 0.16.2 → 0.18.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 (111) 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 +7 -3
  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/effects.d.ts +16 -0
  20. package/dist/effects.d.ts.map +1 -0
  21. package/dist/effects.js +78 -0
  22. package/dist/effects.js.map +1 -0
  23. package/dist/geometry.d.ts +14 -7
  24. package/dist/geometry.d.ts.map +1 -1
  25. package/dist/geometry.js +130 -26
  26. package/dist/geometry.js.map +1 -1
  27. package/dist/graph.d.ts.map +1 -1
  28. package/dist/graph.js +12 -3
  29. package/dist/graph.js.map +1 -1
  30. package/dist/hit-test.d.ts.map +1 -1
  31. package/dist/hit-test.js +100 -8
  32. package/dist/hit-test.js.map +1 -1
  33. package/dist/instances/content-size.js +1 -1
  34. package/dist/instances/index.d.ts.map +1 -1
  35. package/dist/instances/index.js +4 -1
  36. package/dist/instances/index.js.map +1 -1
  37. package/dist/instances/sync.js +4 -3
  38. package/dist/instances/sync.js.map +1 -1
  39. package/dist/layout/index.js +1 -1
  40. package/dist/node-defaults.d.ts.map +1 -1
  41. package/dist/node-defaults.js +4 -1
  42. package/dist/node-defaults.js.map +1 -1
  43. package/dist/preview.d.ts.map +1 -1
  44. package/dist/preview.js +5 -0
  45. package/dist/preview.js.map +1 -1
  46. package/dist/resize.d.ts +4 -1
  47. package/dist/resize.d.ts.map +1 -1
  48. package/dist/resize.js +18 -12
  49. package/dist/resize.js.map +1 -1
  50. package/dist/scaling/node.d.ts.map +1 -1
  51. package/dist/scaling/node.js +3 -1
  52. package/dist/scaling/node.js.map +1 -1
  53. package/dist/scaling/tree.d.ts.map +1 -1
  54. package/dist/scaling/tree.js +8 -5
  55. package/dist/scaling/tree.js.map +1 -1
  56. package/dist/slots/authoring.js +3 -6
  57. package/dist/slots/authoring.js.map +1 -1
  58. package/dist/slots/content.d.ts.map +1 -1
  59. package/dist/slots/content.js +15 -25
  60. package/dist/slots/content.js.map +1 -1
  61. package/dist/slots/frames.js +1 -2
  62. package/dist/slots/frames.js.map +1 -1
  63. package/dist/snap.d.ts.map +1 -1
  64. package/dist/snap.js +12 -4
  65. package/dist/snap.js.map +1 -1
  66. package/dist/types.d.ts +5 -0
  67. package/dist/types.d.ts.map +1 -1
  68. package/dist/types.js.map +1 -1
  69. package/dist/undo.d.ts +2 -1
  70. package/dist/undo.d.ts.map +1 -1
  71. package/dist/undo.js +3 -2
  72. package/dist/undo.js.map +1 -1
  73. package/dist/variables/bindings.d.ts +2 -1
  74. package/dist/variables/bindings.d.ts.map +1 -1
  75. package/dist/variables/bindings.js +6 -2
  76. package/dist/variables/bindings.js.map +1 -1
  77. package/dist/variables/index.d.ts +2 -1
  78. package/dist/variables/index.d.ts.map +1 -1
  79. package/dist/variables/index.js +37 -7
  80. package/dist/variables/index.js.map +1 -1
  81. package/dist/variables/units.d.ts +31 -0
  82. package/dist/variables/units.d.ts.map +1 -0
  83. package/dist/variables/units.js +79 -4
  84. package/dist/variables/units.js.map +1 -1
  85. package/package.json +6 -1
  86. package/src/checkpoint.ts +8 -2
  87. package/src/color/index.ts +4 -6
  88. package/src/color/management.ts +8 -2
  89. package/src/coordinate.ts +4 -1
  90. package/src/copy.ts +8 -3
  91. package/src/css/values.ts +3 -2
  92. package/src/effects.ts +76 -0
  93. package/src/geometry.ts +147 -24
  94. package/src/graph.ts +13 -3
  95. package/src/hit-test.ts +138 -16
  96. package/src/instances/index.ts +5 -1
  97. package/src/instances/sync.ts +5 -3
  98. package/src/node-defaults.ts +4 -1
  99. package/src/preview.ts +4 -0
  100. package/src/resize.ts +40 -20
  101. package/src/scaling/node.ts +3 -1
  102. package/src/scaling/tree.ts +3 -2
  103. package/src/slots/authoring.ts +7 -7
  104. package/src/slots/content.ts +13 -19
  105. package/src/slots/frames.ts +3 -3
  106. package/src/snap.ts +14 -4
  107. package/src/types.ts +5 -0
  108. package/src/undo.ts +3 -2
  109. package/src/variables/bindings.ts +6 -2
  110. package/src/variables/index.ts +49 -8
  111. package/src/variables/units.ts +97 -4
package/dist/graph.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"graph.js","names":["Variables.createVariable","Variables.createCollection","Variables.createMode","Variables.getActiveModeId","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy } from 'es-toolkit/object'\nimport { isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { bindNodeEvents } from './events'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { invalidateTextCaches } from './text/picture'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport type { VariableModeFallback } from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope = 'preview' | 'sourceMetadata' | 'importedState' | 'layout' | 'derivedLayout'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n activeMode = new Map<string, string>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node it is about\n * to change, so a recorder can keep the node as it was. Unlike node events these are never\n * buffered. Graph methods report the nodes they change; code that writes into a node directly\n * reports it with `willChangeNode` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n /**\n * Mints IDs from this graph's generator for variables, collections, and modes built outside\n * it, such as a paste's: none is in use, and none repeats one this minter gave.\n */\n entityIdMinter(): () => string {\n const issued = new Set<string>()\n return () => this.generateEntityId(issued)\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getActiveModeId(collectionId: string): string {\n return Variables.getActiveModeId(this, collectionId)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n setActiveMode(collectionId: string, modeId: string): void {\n Variables.setActiveMode(this, collectionId, modeId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveNumberVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveStringVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId, fallback)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n /**\n * The index lists instances by component, so a change of either, such as undoing a detach that\n * turns a frame back into an instance, moves the layer in it.\n */\n private reindexInstance(node: SceneNode, changes: Partial<SceneNode>): void {\n const indexedBefore = node.type === 'INSTANCE' ? node.componentId : null\n const componentAfter =\n 'componentId' in changes ? (changes.componentId ?? null) : node.componentId\n const indexedAfter = (changes.type ?? node.type) === 'INSTANCE' ? componentAfter : null\n if (indexedBefore === indexedAfter) return\n if (indexedBefore) this.unindexInstance(indexedBefore, node.id)\n if (indexedAfter) this.indexInstance(indexedAfter, node.id)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n const parent = this.nodes.get(parentId)\n this.willChangeNode(parent)\n parent?.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n const parent = parentId ? this.nodes.get(parentId) : undefined\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.sizedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /** A size set from outside layout, with what it also sets on a generated frame. */\n private sizedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n this.reindexInstance(node, changes)\n if (node.type === 'TEXT') invalidateTextCaches(node, changes)\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, Object.keys(changes))\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, pad)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string): boolean {\n return HitTest.isOpenContainer(this, nodeId)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const copies = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, copies)\n // A copied instance records the overrides of its own layers, which are the cloned ones.\n Instances.retargetCopiedOverrides(this, copies)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n copies: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n copies.set(src.id, clone.id)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, copies)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n for (const childId of parent.childIds) {\n const child = this.nodes.get(childId)\n if (!child) continue\n result.push({ node: child, depth })\n if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1))\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAa,aAAb,MAAwB;CA+BO;CA9B7B,wBAAQ,IAAI,IAAuB;CACnC,yBAAS,IAAI,IAAwB;CACrC,4BAAY,IAAI,IAAsB;CACtC,sCAAsB,IAAI,IAAgC;CAC1D,6BAAa,IAAI,IAAoB;CACrC;CACA,iBAAgC;;CAEhC,oBAAuC;CACvC,qBAAyC;CACzC,eAA6B;CAC7B,mCAAmB,IAAI,IAAmC;CAC1D,UAAmB,IAAI,qBAAqB;CAC5C,8BAAsB,IAAI,IAAoB;CAC9C,cAA2D;EACzD,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,QAAQ;EACR,eAAe;CACjB;CACA,mBAAkD,CAAC;CACnD,kCAAmC,IAAI,IAAwB;CAC/D;CACA,eAA4C;CAC5C,yBAAyB;CACzB,gCAAgB,IAAI,IAAyB;;CAE7C,+BAAe,IAAI,IAAY;CAE/B,YAAY,cAA6C,YAAY;EAAxC,KAAA,cAAA;EAC3B,MAAM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version":3,"file":"graph.js","names":["Variables.createVariable","Variables.createCollection","Variables.createMode","Variables.getActiveModeId","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy } from 'es-toolkit/object'\nimport { isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { normalizeEffects } from './effects'\nimport { bindNodeEvents } from './events'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { invalidateTextCaches } from './text/picture'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport type { VariableModeFallback } from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope = 'preview' | 'sourceMetadata' | 'importedState' | 'layout' | 'derivedLayout'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n activeMode = new Map<string, string>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node it is about\n * to change, so a recorder can keep the node as it was. Unlike node events these are never\n * buffered. Graph methods report the nodes they change; code that writes into a node directly\n * reports it with `willChangeNode` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n /**\n * Mints IDs from this graph's generator for variables, collections, and modes built outside\n * it, such as a paste's: none is in use, and none repeats one this minter gave.\n */\n entityIdMinter(): () => string {\n const issued = new Set<string>()\n return () => this.generateEntityId(issued)\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getActiveModeId(collectionId: string): string {\n return Variables.getActiveModeId(this, collectionId)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n setActiveMode(collectionId: string, modeId: string): void {\n Variables.setActiveMode(this, collectionId, modeId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveNumberVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveStringVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId, fallback)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n /**\n * The index lists instances by component, so a change of either, such as undoing a detach that\n * turns a frame back into an instance, moves the layer in it.\n */\n private reindexInstance(node: SceneNode, changes: Partial<SceneNode>): void {\n const indexedBefore = node.type === 'INSTANCE' ? node.componentId : null\n const componentAfter =\n 'componentId' in changes ? (changes.componentId ?? null) : node.componentId\n const indexedAfter = (changes.type ?? node.type) === 'INSTANCE' ? componentAfter : null\n if (indexedBefore === indexedAfter) return\n if (indexedBefore) this.unindexInstance(indexedBefore, node.id)\n if (indexedAfter) this.indexInstance(indexedAfter, node.id)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const parent = this.nodes.get(parentId)\n if (!parent) throw new Error(`Parent \"${parentId}\" does not exist`)\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n this.willChangeNode(parent)\n parent.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n // A caller restoring or importing a layer must know it brings a new one: replacing a layer\n // that already has the ID would drop it, and its children, from the document.\n if (this.nodes.has(id)) throw new Error(`Node \"${id}\" already exists`)\n if (parentId === id) throw new Error(`Node \"${id}\" cannot be its own parent`)\n const parent = parentId === null ? undefined : this.nodes.get(parentId)\n if (parentId !== null && !parent) throw new Error(`Parent \"${parentId}\" does not exist`)\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.sizedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /** A size set from outside layout, with what it also sets on a generated frame. */\n private sizedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n this.reindexInstance(node, changes)\n if (node.type === 'TEXT') invalidateTextCaches(node, changes)\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, Object.keys(changes))\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n if (changes.effects) {\n changes = { ...changes, effects: normalizeEffects(changes.effects) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, pad)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string): boolean {\n return HitTest.isOpenContainer(this, nodeId)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const copies = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, copies)\n // A copied instance records the overrides of its own layers, which are the cloned ones.\n Instances.retargetCopiedOverrides(this, copies)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n copies: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n copies.set(src.id, clone.id)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, copies)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n for (const childId of parent.childIds) {\n const child = this.nodes.get(childId)\n if (!child) continue\n result.push({ node: child, depth })\n if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1))\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,aAAb,MAAwB;CA+BO;CA9B7B,wBAAQ,IAAI,IAAuB;CACnC,yBAAS,IAAI,IAAwB;CACrC,4BAAY,IAAI,IAAsB;CACtC,sCAAsB,IAAI,IAAgC;CAC1D,6BAAa,IAAI,IAAoB;CACrC;CACA,iBAAgC;;CAEhC,oBAAuC;CACvC,qBAAyC;CACzC,eAA6B;CAC7B,mCAAmB,IAAI,IAAmC;CAC1D,UAAmB,IAAI,qBAAqB;CAC5C,8BAAsB,IAAI,IAAoB;CAC9C,cAA2D;EACzD,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,QAAQ;EACR,eAAe;CACjB;CACA,mBAAkD,CAAC;CACnD,kCAAmC,IAAI,IAAwB;CAC/D;CACA,eAA4C;CAC5C,yBAAyB;CACzB,gCAAgB,IAAI,IAAyB;;CAE7C,+BAAe,IAAI,IAAY;CAE/B,YAAY,cAA6C,YAAY;EAAxC,KAAA,cAAA;EAC3B,MAAM,OAAO,kBAAkB,KAAK,aAAa,SAAS;GACxD,MAAM;GACN,OAAO;GACP,QAAQ;EACV,CAAC;EACD,KAAK,SAAS,KAAK;EACnB,KAAK,MAAM,IAAI,KAAK,IAAI,IAAI;EAE5B,KAAK,QAAQ,QAAQ;CACvB;CACA,QAAQ,MAAyB;EAC/B,OAAO,KAAK,WAAW,UAAU,K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AO;GAAM,CAAC;GAClC,IAAI,MAAM,SAAS,SAAS,GAAG,OAAO,KAAK,GAAG,KAAK,YAAY,SAAS,QAAQ,CAAC,CAAC;EACpF;EACA,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;;iBA2LgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;iBA2Ea,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,eACC;;iBA6Ba,gBAAgB,OAAO,YAAY;;;;;iBASnC,qBACd,OAAO,YACP,YACA,YACA,kBACC;;;;;;;;iBA0Ea,kBAAkB,OAAO,YAAY,MAAM,MAAM,kBAAkB;;iBASnE,cAAc,OAAO,YAAY,gBAAgB,YAAY;UAgE5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}
1
+ {"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;;iBAqTgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;iBA2Ea,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,eACC;;iBA6Ba,gBAAgB,OAAO,YAAY;;;;;iBASnC,qBACd,OAAO,YACP,YACA,YACA,kBACC;;;;;;;;iBA0Ea,kBAAkB,OAAO,YAAY,MAAM,MAAM,kBAAkB;;iBASnE,cAAc,OAAO,YAAY,gBAAgB,YAAY;UAgE5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}
package/dist/hit-test.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import Matrix from "./matrix.js";
2
2
  import { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from "./coordinate.js";
3
+ import { geometryBlobPolylines } from "./geometry.js";
3
4
  import { hitsConnectorLine } from "./connectors/hit.js";
4
5
  //#region src/hit-test.ts
5
6
  const CONTAINER_TYPES = /* @__PURE__ */ new Set([
@@ -12,6 +13,11 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
12
13
  "INSTANCE"
13
14
  ]);
14
15
  const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]);
16
+ /**
17
+ * How far from a zero-width or zero-height layer, in canvas units, a point still lands on it, so
18
+ * a flat line or an empty box stays clickable; matches a connector line's slop (`connectors/hit.ts`).
19
+ */
20
+ const DEGENERATE_AXIS_SLOP = 4;
15
21
  function hasVisibleFillOrStroke(node) {
16
22
  return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible);
17
23
  }
@@ -36,17 +42,96 @@ function hasTransformedAncestor(node, graph, cache) {
36
42
  cache.set(node.id, transformed);
37
43
  return transformed;
38
44
  }
39
- /** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */
40
- function containsPoint(px, py, node, graph, transformCache, pad = 0) {
45
+ /**
46
+ * Where the point lies in the node's own coordinates: its offset from the position when nothing
47
+ * above it is turned, else through the inverse world matrix. Null when that cannot be inverted.
48
+ */
49
+ function localPoint(px, py, node, graph, transformCache) {
41
50
  if (!hasTransformedAncestor(node, graph, transformCache)) {
42
51
  const absolute = graph.getAbsolutePosition(node.id);
43
- return px >= absolute.x - pad && px <= absolute.x + node.width + pad && py >= absolute.y - pad && py <= absolute.y + node.height + pad;
52
+ return {
53
+ x: px - absolute.x,
54
+ y: py - absolute.y
55
+ };
44
56
  }
45
- const m = getWorldMatrix(node, graph);
46
- const inv = Matrix.invert(m);
47
- if (!inv) return false;
48
- const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
49
- return localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad;
57
+ const inv = Matrix.invert(getWorldMatrix(node, graph));
58
+ if (!inv) return null;
59
+ const [x, y] = Matrix.mapPoints(inv, [px, py]);
60
+ return {
61
+ x,
62
+ y
63
+ };
64
+ }
65
+ /** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */
66
+ function containsPoint(px, py, node, graph, transformCache, pad = 0) {
67
+ const local = localPoint(px, py, node, graph, transformCache);
68
+ if (!local) return false;
69
+ const padX = node.width > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP);
70
+ const padY = node.height > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP);
71
+ return local.x >= -padX && local.x <= node.width + padX && local.y >= -padY && local.y <= node.height + padY;
72
+ }
73
+ /** Whether a rounded rectangle of `width` × `height` holds the point. */
74
+ function roundedRectContains(point, width, height, radius) {
75
+ if (point.x < 0 || point.y < 0 || point.x > width || point.y > height) return false;
76
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
77
+ const cx = Math.min(Math.max(point.x, r), width - r);
78
+ const cy = Math.min(Math.max(point.y, r), height - r);
79
+ return Math.hypot(point.x - cx, point.y - cy) <= r;
80
+ }
81
+ /** Whether the point is inside a closed polyline, by the even-odd rule. */
82
+ function insidePolyline(polyline, x, y) {
83
+ let inside = false;
84
+ for (let i = 0, j = polyline.length - 1; i < polyline.length; j = i++) {
85
+ const a = polyline[i];
86
+ const b = polyline[j];
87
+ if (a.y > y === b.y > y) continue;
88
+ if (x < (b.x - a.x) * (y - a.y) / (b.y - a.y) + a.x) inside = !inside;
89
+ }
90
+ return inside;
91
+ }
92
+ /**
93
+ * Whether a mask lets the point through, by the outline it draws: an ellipse's curve, a rounded
94
+ * rectangle's corners, or a vector's filled path. Other shapes clip by their box.
95
+ */
96
+ function maskContainsPoint(px, py, mask, graph, transformCache) {
97
+ if (!(mask.type === "ELLIPSE" && mask.width > 0 && mask.height > 0 || mask.type === "RECTANGLE" && mask.cornerRadius > 0 || mask.type === "VECTOR" && mask.fillGeometry.length > 0)) return containsPoint(px, py, mask, graph, transformCache);
98
+ const local = localPoint(px, py, mask, graph, transformCache);
99
+ if (!local) return false;
100
+ if (mask.type === "ELLIPSE") {
101
+ const rx = mask.width / 2;
102
+ const ry = mask.height / 2;
103
+ const dx = (local.x - rx) / rx;
104
+ const dy = (local.y - ry) / ry;
105
+ return dx * dx + dy * dy <= 1;
106
+ }
107
+ if (mask.type === "RECTANGLE") return roundedRectContains(local, mask.width, mask.height, mask.cornerRadius);
108
+ return geometryBlobPolylines(mask.fillGeometry).some((points) => insidePolyline(points, local.x, local.y));
109
+ }
110
+ function isVisibleMask(node) {
111
+ return node !== void 0 && node.visible && node.isMask;
112
+ }
113
+ /**
114
+ * The masks that clip each child, by index, as the renderer groups them (`core/canvas/masks.ts`):
115
+ * a run of visible masks clips the layers after it up to the next visible mask. Empty when the
116
+ * container has no visible mask.
117
+ */
118
+ function clippingMasks(graph, childIds) {
119
+ const children = childIds.map((childId) => graph.nodes.get(childId));
120
+ if (!children.some(isVisibleMask)) return [];
121
+ const result = [];
122
+ let run = [];
123
+ let previousWasMask = false;
124
+ for (const child of children) {
125
+ if (isVisibleMask(child)) {
126
+ run = previousWasMask ? [...run, child] : [child];
127
+ previousWasMask = true;
128
+ result.push([]);
129
+ continue;
130
+ }
131
+ previousWasMask = false;
132
+ result.push(run);
133
+ }
134
+ return result;
50
135
  }
51
136
  function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad) {
52
137
  if (!containsPoint(px, py, child, graph, transformCache)) return null;
@@ -69,6 +154,11 @@ function hitTestTransparentContainer(graph, px, py, child, childId, deep, transf
69
154
  if (containsPoint(px, py, child, graph, transformCache) && (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))) return child;
70
155
  return null;
71
156
  }
157
+ /** Whether the masks that clip a layer leave the point outside every one of their outlines. */
158
+ function isMaskedOut(px, py, masks, graph, transformCache) {
159
+ if (!masks) return false;
160
+ return masks.length > 0 && !masks.some((mask) => maskContainsPoint(px, py, mask, graph, transformCache));
161
+ }
72
162
  /**
73
163
  * The topmost layer under the point among a container's children. `pad`, in canvas units, grows
74
164
  * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.
@@ -79,10 +169,12 @@ function hitTestChildren(graph, px, py, parentId, deep = false, transformCache =
79
169
  if (parent.clipsContent) {
80
170
  if (!containsPoint(px, py, parent, graph, transformCache)) return null;
81
171
  }
172
+ const masks = clippingMasks(graph, parent.childIds);
82
173
  for (let i = parent.childIds.length - 1; i >= 0; i--) {
83
174
  const childId = parent.childIds[i];
84
175
  const child = graph.nodes.get(childId);
85
176
  if (!child || child.internalOnly || !child.visible) continue;
177
+ if (isMaskedOut(px, py, masks[i], graph, transformCache)) continue;
86
178
  if (CONTAINER_TYPES.has(child.type)) {
87
179
  if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
88
180
  const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad);
@@ -1 +1 @@
1
- {"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x - pad &&\n px <= absolute.x + node.width + pad &&\n py >= absolute.y - pad &&\n py <= absolute.y + node.height + pad\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return (\n localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad\n )\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return deep ? childHit : child\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))\n )\n return child\n return null\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return hasVisibleFillOrStroke(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;AAOA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;AAE1E,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,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OACA,IACA,IACA,YACA,SACA,UAA6B,CAAC,GACZ;CAClB,MAAM,QAAQ,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
1
+ {"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport { geometryBlobPolylines } from './geometry'\nimport type { SceneGraph } from './graph'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n/**\n * How far from a zero-width or zero-height layer, in canvas units, a point still lands on it, so\n * a flat line or an empty box stays clickable; matches a connector line's slop (`connectors/hit.ts`).\n */\nconst DEGENERATE_AXIS_SLOP = 4\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/**\n * Where the point lies in the node's own coordinates: its offset from the position when nothing\n * above it is turned, else through the inverse world matrix. Null when that cannot be inverted.\n */\nfunction localPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): Vector | null {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return { x: px - absolute.x, y: py - absolute.y }\n }\n const inv = Matrix.invert(getWorldMatrix(node, graph))\n if (!inv) return null\n const [x, y] = Matrix.mapPoints(inv, [px, py])\n return { x, y }\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n const local = localPoint(px, py, node, graph, transformCache)\n if (!local) return false\n const padX = node.width > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n const padY = node.height > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n return (\n local.x >= -padX &&\n local.x <= node.width + padX &&\n local.y >= -padY &&\n local.y <= node.height + padY\n )\n}\n\n/** Whether a rounded rectangle of `width` × `height` holds the point. */\nfunction roundedRectContains(\n point: Vector,\n width: number,\n height: number,\n radius: number\n): boolean {\n if (point.x < 0 || point.y < 0 || point.x > width || point.y > height) return false\n const r = Math.max(0, Math.min(radius, width / 2, height / 2))\n const cx = Math.min(Math.max(point.x, r), width - r)\n const cy = Math.min(Math.max(point.y, r), height - r)\n return Math.hypot(point.x - cx, point.y - cy) <= r\n}\n\n/** Whether the point is inside a closed polyline, by the even-odd rule. */\nfunction insidePolyline(polyline: readonly Vector[], x: number, y: number): boolean {\n let inside = false\n for (let i = 0, j = polyline.length - 1; i < polyline.length; j = i++) {\n const a = polyline[i]\n const b = polyline[j]\n if (a.y > y === b.y > y) continue\n if (x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x) inside = !inside\n }\n return inside\n}\n\n/**\n * Whether a mask lets the point through, by the outline it draws: an ellipse's curve, a rounded\n * rectangle's corners, or a vector's filled path. Other shapes clip by their box.\n */\nfunction maskContainsPoint(\n px: number,\n py: number,\n mask: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n const outlined =\n (mask.type === 'ELLIPSE' && mask.width > 0 && mask.height > 0) ||\n (mask.type === 'RECTANGLE' && mask.cornerRadius > 0) ||\n (mask.type === 'VECTOR' && mask.fillGeometry.length > 0)\n if (!outlined) return containsPoint(px, py, mask, graph, transformCache)\n const local = localPoint(px, py, mask, graph, transformCache)\n if (!local) return false\n if (mask.type === 'ELLIPSE') {\n const rx = mask.width / 2\n const ry = mask.height / 2\n const dx = (local.x - rx) / rx\n const dy = (local.y - ry) / ry\n return dx * dx + dy * dy <= 1\n }\n if (mask.type === 'RECTANGLE') {\n return roundedRectContains(local, mask.width, mask.height, mask.cornerRadius)\n }\n return geometryBlobPolylines(mask.fillGeometry).some((points) =>\n insidePolyline(points, local.x, local.y)\n )\n}\n\nfunction isVisibleMask(node: SceneNode | undefined): node is SceneNode {\n return node !== undefined && node.visible && node.isMask\n}\n\n/**\n * The masks that clip each child, by index, as the renderer groups them (`core/canvas/masks.ts`):\n * a run of visible masks clips the layers after it up to the next visible mask. Empty when the\n * container has no visible mask.\n */\nfunction clippingMasks(graph: SceneGraph, childIds: readonly string[]): SceneNode[][] {\n const children = childIds.map((childId) => graph.nodes.get(childId))\n if (!children.some(isVisibleMask)) return []\n const result: SceneNode[][] = []\n let run: SceneNode[] = []\n let previousWasMask = false\n for (const child of children) {\n if (isVisibleMask(child)) {\n run = previousWasMask ? [...run, child] : [child]\n previousWasMask = true\n result.push([])\n continue\n }\n previousWasMask = false\n result.push(run)\n }\n return result\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return deep ? childHit : child\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))\n )\n return child\n return null\n}\n\n/** Whether the masks that clip a layer leave the point outside every one of their outlines. */\nfunction isMaskedOut(\n px: number,\n py: number,\n masks: readonly SceneNode[] | undefined,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!masks) return false\n return (\n masks.length > 0 &&\n !masks.some((mask) => maskContainsPoint(px, py, mask, graph, transformCache))\n )\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n const masks = clippingMasks(graph, parent.childIds)\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (isMaskedOut(px, py, masks[i], graph, transformCache)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return hasVisibleFillOrStroke(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;AAQA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;;;;AAK1E,MAAM,uBAAuB;AAE7B,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS;AACvD;;;;;;;AAQA,SAAS,iBAAiB,OAAmB,MAA0B;CACrE,OAAO,KAAK,SAAS,WAAW,KAAK,eAAe,UAAU,WAAW,OAAO,IAAI;AACtF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,MAAM,cACJ,KAAK,aAAa,KAClB,KAAK,SACL,KAAK,UACJ,SAAS,uBAAuB,QAAQ,OAAO,KAAK,IAAI;CAC3D,MAAM,IAAI,KAAK,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XT_SHAPING_FIELDS } from "../fields/text.js";
2
3
  import { layoutSizing } from "../layout/sizing.js";
3
- import { resizedChildRect } from "../resize.js";
4
4
  import { isEqual } from "es-toolkit/predicate";
5
5
  //#region src/instances/content-size.ts
6
6
  const METRIC_FIELDS = new Set(TEXT_METRIC_FIELDS);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;;iBAkDgB,2BAA2B,WAAW,YAAY,QAAQ;iBAM1D,eACd,OAAO,YACP,qBACA,kBACA,YAAW,QAAQ,aAClB;iBAkBa,yBACd,OAAO,YACP,oBACA,qBACA,OAAM;UAmCS;;;;;;EAMf;;iBAGc,sBACd,OAAO,YACP,oBACA,uBACE,aAAoB;iBAgCR,cAAc,OAAO,YAAY;;;;;iBAQjC,sBAAsB,OAAO,YAAY,cAAc;;iBAOvD,aAAa,OAAO,YAAY;;;;;;iBAqDhC,wBACd,OAAO,YACP,QAAQ;iBAeM,eAAe,OAAO,YAAY;iBAWlC,iBAAiB,OAAO,YAAY,qBAAqB;iBAMzD,aAAa,OAAO,YAAY,sBAAsB;;iBAYtD,qBAAqB,OAAO,YAAY,iBAAiB;;;;iBAYzD,oBAAoB,OAAO,YAAY,gBAAgB;iBAuCvD,uBACd,OAAO,YACP,gBACA,QAAQ;;iBA6CM,wBAAwB,OAAO,YAAY;;;;;;;;;iBAqB3C,qBACd,OAAO,YACP,kBACA;;;;;iBAmDc,qBAAqB,OAAO,YAAY"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;;iBAkDgB,2BAA2B,WAAW,YAAY,QAAQ;iBAM1D,eACd,OAAO,YACP,qBACA,kBACA,YAAW,QAAQ,aAClB;iBAkBa,yBACd,OAAO,YACP,oBACA,qBACA,OAAM;UAmCS;;;;;;EAMf;;iBAGc,sBACd,OAAO,YACP,oBACA,uBACE,aAAoB;iBAoCR,cAAc,OAAO,YAAY;;;;;iBAQjC,sBAAsB,OAAO,YAAY,cAAc;;iBAOvD,aAAa,OAAO,YAAY;;;;;;iBAqDhC,wBACd,OAAO,YACP,QAAQ;iBAeM,eAAe,OAAO,YAAY;iBAWlC,iBAAiB,OAAO,YAAY,qBAAqB;iBAMzD,aAAa,OAAO,YAAY,sBAAsB;;iBAYtD,qBAAqB,OAAO,YAAY,iBAAiB;;;;iBAYzD,oBAAoB,OAAO,YAAY,gBAAgB;iBAuCvD,uBACd,OAAO,YACP,gBACA,QAAQ;;iBA6CM,wBAAwB,OAAO,YAAY;;;;;;;;;iBAqB3C,qBACd,OAAO,YACP,kBACA;;;;;iBAmDc,qBAAqB,OAAO,YAAY"}
@@ -67,7 +67,10 @@ function swapInstanceComponent(graph, instanceId, componentId, { keepName = fals
67
67
  if (!keepName && (!previousComponent || instance.name === previousComponent.name)) updates.name = component.name;
68
68
  const childIds = Array.from(instance.childIds);
69
69
  const slotContent = detachOwnedSlotContent(graph, instance);
70
- for (const childId of childIds) graph.deleteNode(childId);
70
+ for (const childId of childIds) {
71
+ forgetOverridesOf(graph, childId);
72
+ graph.deleteNode(childId);
73
+ }
71
74
  graph.updateNode(instanceId, updates);
72
75
  cloneChildrenWithMapping(graph, componentId, instanceId);
73
76
  restoreOwnedSlotContent(graph, instance, slotContent);