@pairdraw/core 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/dist/canvas/overlays/index.d.ts +2 -2
  2. package/dist/canvas/overlays/index.js +2 -2
  3. package/dist/canvas/overlays/selection.d.ts +1 -2
  4. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  5. package/dist/canvas/overlays/selection.js +2 -9
  6. package/dist/canvas/overlays/selection.js.map +1 -1
  7. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  8. package/dist/canvas/renderer/fonts.js +2 -0
  9. package/dist/canvas/renderer/fonts.js.map +1 -1
  10. package/dist/canvas/renderer/methods.d.ts +0 -1
  11. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  12. package/dist/canvas/renderer/methods.js +1 -4
  13. package/dist/canvas/renderer/methods.js.map +1 -1
  14. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  15. package/dist/canvas/renderer/overlay-pass.js +0 -1
  16. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  17. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  18. package/dist/canvas/renderer/pipeline.js +0 -1
  19. package/dist/canvas/renderer/pipeline.js.map +1 -1
  20. package/dist/canvas/renderer/types.d.ts +0 -1
  21. package/dist/canvas/renderer/types.d.ts.map +1 -1
  22. package/dist/canvas/renderer.d.ts +0 -1
  23. package/dist/canvas/renderer.d.ts.map +1 -1
  24. package/dist/canvas/renderer.js.map +1 -1
  25. package/dist/design-jsx/index.d.ts +2 -2
  26. package/dist/design-jsx/index.js +2 -2
  27. package/dist/design-jsx/renderer.d.ts +3 -2
  28. package/dist/design-jsx/renderer.d.ts.map +1 -1
  29. package/dist/design-jsx/renderer.js +2 -2
  30. package/dist/design-jsx/renderer.js.map +1 -1
  31. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  32. package/dist/editor/clipboard/snapshot.js +12 -4
  33. package/dist/editor/clipboard/snapshot.js.map +1 -1
  34. package/dist/editor/clipboard.d.ts.map +1 -1
  35. package/dist/editor/clipboard.js +2 -7
  36. package/dist/editor/clipboard.js.map +1 -1
  37. package/dist/editor/color-space.d.ts.map +1 -1
  38. package/dist/editor/color-space.js +33 -38
  39. package/dist/editor/color-space.js.map +1 -1
  40. package/dist/editor/create.d.ts +9 -5
  41. package/dist/editor/create.d.ts.map +1 -1
  42. package/dist/editor/create.js +10 -1
  43. package/dist/editor/create.js.map +1 -1
  44. package/dist/editor/history/edit.d.ts.map +1 -1
  45. package/dist/editor/history/edit.js +2 -1
  46. package/dist/editor/history/edit.js.map +1 -1
  47. package/dist/editor/nudge.js +1 -1
  48. package/dist/editor/nudge.js.map +1 -1
  49. package/dist/editor/read-only/actions.js +2 -0
  50. package/dist/editor/read-only/actions.js.map +1 -1
  51. package/dist/editor/selection/container.d.ts +2 -0
  52. package/dist/editor/selection/container.d.ts.map +1 -1
  53. package/dist/editor/selection/container.js +17 -1
  54. package/dist/editor/selection/container.js.map +1 -1
  55. package/dist/editor/selection/navigation.js +7 -4
  56. package/dist/editor/selection/navigation.js.map +1 -1
  57. package/dist/editor/selection/read.d.ts +2 -2
  58. package/dist/editor/selection.d.ts +4 -2
  59. package/dist/editor/selection.d.ts.map +1 -1
  60. package/dist/editor/shapes/with-text.d.ts.map +1 -1
  61. package/dist/editor/shapes/with-text.js +2 -5
  62. package/dist/editor/shapes/with-text.js.map +1 -1
  63. package/dist/editor/structure/auto-layout-wrap.js +1 -1
  64. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  65. package/dist/editor/structure/boolean.d.ts +2 -3
  66. package/dist/editor/structure/boolean.d.ts.map +1 -1
  67. package/dist/editor/structure/boolean.js.map +1 -1
  68. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  69. package/dist/editor/structure/group/bounds.js +1 -3
  70. package/dist/editor/structure/group/bounds.js.map +1 -1
  71. package/dist/editor/structure/outline-stroke.js +3 -3
  72. package/dist/editor/structure/outline-stroke.js.map +1 -1
  73. package/dist/editor/structure/reorder.d.ts.map +1 -1
  74. package/dist/editor/structure/reorder.js +7 -14
  75. package/dist/editor/structure/reorder.js.map +1 -1
  76. package/dist/editor/structure/state.js +1 -1
  77. package/dist/editor/structure/state.js.map +1 -1
  78. package/dist/editor/structure.d.ts +1 -2
  79. package/dist/editor/structure.d.ts.map +1 -1
  80. package/dist/editor/structure.js +3 -3
  81. package/dist/editor/structure.js.map +1 -1
  82. package/dist/editor/types.d.ts +4 -1
  83. package/dist/editor/types.d.ts.map +1 -1
  84. package/dist/editor/variables.d.ts.map +1 -1
  85. package/dist/editor/variables.js +57 -1
  86. package/dist/editor/variables.js.map +1 -1
  87. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  88. package/dist/figma-api/accessors/text/index.js +4 -1
  89. package/dist/figma-api/accessors/text/index.js.map +1 -1
  90. package/dist/figma-api/fonts/loaded.d.ts +3 -1
  91. package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
  92. package/dist/figma-api/fonts/loaded.js +8 -1
  93. package/dist/figma-api/fonts/loaded.js.map +1 -1
  94. package/dist/figma-api/index.d.ts +13 -0
  95. package/dist/figma-api/index.d.ts.map +1 -1
  96. package/dist/figma-api/index.js +13 -0
  97. package/dist/figma-api/index.js.map +1 -1
  98. package/dist/figma-api/serialization.d.ts.map +1 -1
  99. package/dist/figma-api/serialization.js +2 -1
  100. package/dist/figma-api/serialization.js.map +1 -1
  101. package/dist/figma-api/shape-details.d.ts +26 -0
  102. package/dist/figma-api/shape-details.d.ts.map +1 -0
  103. package/dist/figma-api/shape-details.js +28 -0
  104. package/dist/figma-api/shape-details.js.map +1 -0
  105. package/dist/figma-api/shape-with-text.js +2 -5
  106. package/dist/figma-api/shape-with-text.js.map +1 -1
  107. package/dist/figma-api/surface.d.ts +1 -1
  108. package/dist/figma-api/surface.d.ts.map +1 -1
  109. package/dist/figma-api/surface.js +1 -0
  110. package/dist/figma-api/surface.js.map +1 -1
  111. package/dist/icons/svg.js +1 -1
  112. package/dist/icons/svg.js.map +1 -1
  113. package/dist/io/formats/design-tokens/apply.d.ts +1 -1
  114. package/dist/io/formats/drawio/index.d.ts.map +1 -1
  115. package/dist/io/formats/drawio/index.js +1 -1
  116. package/dist/io/formats/drawio/index.js.map +1 -1
  117. package/dist/io/formats/html/layers.d.ts +7 -4
  118. package/dist/io/formats/html/layers.d.ts.map +1 -1
  119. package/dist/io/formats/html/layers.js +4 -1
  120. package/dist/io/formats/html/layers.js.map +1 -1
  121. package/dist/io/formats/pdf/dom.d.ts +6 -1
  122. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  123. package/dist/io/formats/pdf/dom.js +9 -22
  124. package/dist/io/formats/pdf/dom.js.map +1 -1
  125. package/dist/io/formats/pdf/export.js +1 -1
  126. package/dist/io/formats/pdf/export.js.map +1 -1
  127. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  128. package/dist/io/formats/svg/defs.js +3 -1
  129. package/dist/io/formats/svg/defs.js.map +1 -1
  130. package/dist/io/formats/svg/export.d.ts.map +1 -1
  131. package/dist/io/formats/svg/export.js +52 -16
  132. package/dist/io/formats/svg/export.js.map +1 -1
  133. package/dist/layout/apply.d.ts.map +1 -1
  134. package/dist/layout/apply.js +50 -12
  135. package/dist/layout/apply.js.map +1 -1
  136. package/dist/layout/derived.d.ts +7 -1
  137. package/dist/layout/derived.d.ts.map +1 -1
  138. package/dist/layout/derived.js +11 -1
  139. package/dist/layout/derived.js.map +1 -1
  140. package/dist/layout/grid.d.ts +7 -2
  141. package/dist/layout/grid.d.ts.map +1 -1
  142. package/dist/layout/grid.js +27 -9
  143. package/dist/layout/grid.js.map +1 -1
  144. package/dist/layout/mutations.d.ts +1 -0
  145. package/dist/layout/mutations.d.ts.map +1 -1
  146. package/dist/layout/mutations.js +10 -0
  147. package/dist/layout/mutations.js.map +1 -1
  148. package/dist/layout/strokes.d.ts +9 -1
  149. package/dist/layout/strokes.d.ts.map +1 -1
  150. package/dist/layout/strokes.js +12 -1
  151. package/dist/layout/strokes.js.map +1 -1
  152. package/dist/layout/yoga-helpers.d.ts +3 -1
  153. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  154. package/dist/layout/yoga-helpers.js +16 -2
  155. package/dist/layout/yoga-helpers.js.map +1 -1
  156. package/dist/layout.d.ts.map +1 -1
  157. package/dist/layout.js +71 -38
  158. package/dist/layout.js.map +1 -1
  159. package/dist/lint/linter.d.ts +1 -0
  160. package/dist/lint/linter.d.ts.map +1 -1
  161. package/dist/lint/linter.js +13 -1
  162. package/dist/lint/linter.js.map +1 -1
  163. package/dist/lint/rules/effect-style-required.js +1 -0
  164. package/dist/lint/rules/effect-style-required.js.map +1 -1
  165. package/dist/lint/rules/text-style-required.js +1 -0
  166. package/dist/lint/rules/text-style-required.js.map +1 -1
  167. package/dist/lint/types.d.ts +7 -0
  168. package/dist/lint/types.d.ts.map +1 -1
  169. package/dist/rpc/commands.d.ts +2 -2
  170. package/dist/rpc/index.d.ts +2 -2
  171. package/dist/rpc/read-commands.d.ts +18 -8
  172. package/dist/rpc/read-commands.d.ts.map +1 -1
  173. package/dist/rpc/read-commands.js +18 -9
  174. package/dist/rpc/read-commands.js.map +1 -1
  175. package/dist/text/font/faces.d.ts +12 -1
  176. package/dist/text/font/faces.d.ts.map +1 -1
  177. package/dist/text/font/faces.js +15 -1
  178. package/dist/text/font/faces.js.map +1 -1
  179. package/dist/text/font/manager.d.ts.map +1 -1
  180. package/dist/text/font/manager.js +6 -11
  181. package/dist/text/font/manager.js.map +1 -1
  182. package/dist/text/index.d.ts +2 -2
  183. package/dist/text/index.js +2 -2
  184. package/dist/tools/modify/layout.d.ts.map +1 -1
  185. package/dist/tools/modify/layout.js +1 -0
  186. package/dist/tools/modify/layout.js.map +1 -1
  187. package/dist/tools/read/nodes.d.ts.map +1 -1
  188. package/dist/tools/read/nodes.js.map +1 -1
  189. package/dist/tools/structure/batch.d.ts.map +1 -1
  190. package/dist/tools/structure/batch.js +14 -0
  191. package/dist/tools/structure/batch.js.map +1 -1
  192. package/dist/tools/vector/path.d.ts.map +1 -1
  193. package/dist/tools/vector/path.js +39 -7
  194. package/dist/tools/vector/path.js.map +1 -1
  195. package/dist/xpath.d.ts +3 -0
  196. package/dist/xpath.d.ts.map +1 -1
  197. package/dist/xpath.js +3 -1
  198. package/dist/xpath.js.map +1 -1
  199. package/package.json +9 -9
  200. package/src/canvas/overlays/index.ts +0 -1
  201. package/src/canvas/overlays/selection.ts +1 -12
  202. package/src/canvas/renderer/fonts.ts +2 -0
  203. package/src/canvas/renderer/methods.ts +0 -9
  204. package/src/canvas/renderer/overlay-pass.ts +0 -1
  205. package/src/canvas/renderer/pipeline.ts +0 -1
  206. package/src/canvas/renderer/types.ts +0 -1
  207. package/src/canvas/renderer.ts +0 -1
  208. package/src/design-jsx/index.ts +1 -1
  209. package/src/design-jsx/renderer.ts +1 -1
  210. package/src/editor/clipboard/snapshot.ts +21 -4
  211. package/src/editor/clipboard.ts +4 -14
  212. package/src/editor/color-space.ts +47 -38
  213. package/src/editor/create.ts +14 -2
  214. package/src/editor/history/edit.ts +5 -1
  215. package/src/editor/nudge.ts +1 -1
  216. package/src/editor/read-only/actions.ts +2 -0
  217. package/src/editor/selection/container.ts +24 -1
  218. package/src/editor/selection/navigation.ts +8 -6
  219. package/src/editor/shapes/with-text.ts +2 -5
  220. package/src/editor/structure/auto-layout-wrap.ts +1 -1
  221. package/src/editor/structure/boolean.ts +1 -3
  222. package/src/editor/structure/group/bounds.ts +1 -5
  223. package/src/editor/structure/outline-stroke.ts +3 -3
  224. package/src/editor/structure/reorder.ts +8 -14
  225. package/src/editor/structure/state.ts +1 -1
  226. package/src/editor/structure.ts +5 -8
  227. package/src/editor/types.ts +4 -1
  228. package/src/editor/variables.ts +74 -2
  229. package/src/figma-api/accessors/text/index.ts +10 -1
  230. package/src/figma-api/fonts/loaded.ts +9 -0
  231. package/src/figma-api/index.ts +25 -0
  232. package/src/figma-api/serialization.ts +2 -1
  233. package/src/figma-api/shape-details.ts +50 -0
  234. package/src/figma-api/shape-with-text.ts +2 -5
  235. package/src/figma-api/surface.ts +1 -0
  236. package/src/global.d.ts +5 -0
  237. package/src/icons/svg.ts +3 -1
  238. package/src/io/formats/drawio/index.ts +3 -1
  239. package/src/io/formats/html/layers.ts +11 -2
  240. package/src/io/formats/pdf/dom.ts +10 -18
  241. package/src/io/formats/pdf/export.ts +1 -1
  242. package/src/io/formats/svg/defs.ts +10 -1
  243. package/src/io/formats/svg/export.ts +94 -19
  244. package/src/layout/apply.ts +87 -21
  245. package/src/layout/derived.ts +14 -0
  246. package/src/layout/grid.ts +33 -9
  247. package/src/layout/mutations.ts +13 -1
  248. package/src/layout/strokes.ts +12 -0
  249. package/src/layout/yoga-helpers.ts +18 -1
  250. package/src/layout.ts +94 -49
  251. package/src/lint/linter.ts +17 -2
  252. package/src/lint/rules/effect-style-required.ts +2 -0
  253. package/src/lint/rules/text-style-required.ts +2 -0
  254. package/src/lint/types.ts +8 -0
  255. package/src/rpc/index.ts +1 -0
  256. package/src/rpc/read-commands.ts +40 -23
  257. package/src/text/font/faces.ts +22 -0
  258. package/src/text/font/manager.ts +9 -11
  259. package/src/tools/modify/layout.ts +5 -0
  260. package/src/tools/read/nodes.ts +0 -1
  261. package/src/tools/structure/batch.ts +22 -0
  262. package/src/tools/vector/path.ts +30 -6
  263. package/src/xpath.ts +6 -1
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.js","names":[],"sources":["../../src/editor/clipboard.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport { parseFigmaClipboard } from '@pairdraw/fig/clipboard'\nimport { CommittedGraphEventError, type SceneNode } from '@pairdraw/scene-graph'\nimport { attachedConnectors } from '@pairdraw/scene-graph/connectors'\nimport { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { cycleSafeParent, recordInstanceOverride } from '@pairdraw/scene-graph/instances'\nimport type { Rect, Vector } from '@pairdraw/scene-graph/primitives'\nimport { slotPropertyId } from '@pairdraw/scene-graph/slots'\nimport { keepPastedBoundPaints, type AppliedBoundPaints } from '@pairdraw/scene-graph/variables'\n\nimport { parsePairdrawClipboard } from '#core/clipboard'\nimport { prepareClipboardImport } from '#core/clipboard/fig-import'\nimport { computeAllLayouts, layoutAuthoredNodes } from '#core/layout'\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { createClipboardAssetActions } from './clipboard/assets'\nimport type { ClipboardImportChoice } from './clipboard/conflicts'\nimport type { ClipboardSnapshot } from './clipboard/copy'\nimport { createClipboardCopyActions } from './clipboard/copy'\nimport { importClipboardDependenciesWithUndo } from './clipboard/dependencies'\nimport { createClipboardExportActions } from './clipboard/export'\nimport { createClipboardFontActions } from './clipboard/fonts'\nimport { deleteIds, recreateSnapshots, restoreDeletedEntries } from './clipboard/history'\nimport type { PasteHistoryOperation } from './clipboard/paste/replace'\nimport { replaceTargetsWithCreated, selectedReplacementTargets } from './clipboard/paste/replace'\nimport {\n pastedComponentIds,\n requestedPasteTarget,\n resolvePasteTarget\n} from './clipboard/paste/target'\nimport {\n clipboardPlacement,\n createClipboardPlacementActions,\n type ClipboardPlacement\n} from './clipboard/placement'\nimport { createStyledPasteActions } from './clipboard/styled'\nimport { replaceableInstanceLayers, replaceInstanceLayersWith } from './components/replace'\nimport { acceptsChildren, prepareSlotEdits } from './components/slots'\nimport { collectSubtrees, restoreSubtree, snapshotSubtree } from './history/subtree'\nimport { newLayerDefaults } from './shapes/defaults'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport { loadBoundFonts } from './text/bound-fonts'\nimport type { EditorContext } from './types'\n\ntype PasteOptions = {\n replaceSelection?: boolean\n /**\n * Put the pasted layer in place of each selected layer inside an instance, as an override of\n * that instance (pen.dev's Replace inside instance), in the same undo step as the paste.\n */\n replaceInInstance?: boolean\n /** How a copy from another document brings its variables and styles (`planClipboardImport`). */\n dependencies?: ClipboardImportChoice\n}\n\ntype PasteNodesOptions = PasteOptions & {\n /** Resolve the pasted layers' variable bindings where they land, before history records them. */\n resolveBindings?: boolean\n}\n\n/**\n * A copy of the layer under the same parent, keeping its name as Figma does. A main component\n * outside a component set duplicates as an instance of itself.\n */\nexport function duplicateNode(\n ctx: Pick<EditorContext, 'graph'>,\n node: SceneNode,\n parentId: string,\n position: Vector\n): SceneNode | null {\n const parent = ctx.graph.getNode(parentId)\n if (node.type === 'COMPONENT' && parent?.type !== 'COMPONENT_SET') {\n return ctx.graph.createInstance(node.id, parentId, { name: node.name, ...position })\n }\n return ctx.graph.cloneTree(node.id, parentId, { name: node.name, ...position })\n}\n\nexport function createClipboardActions(ctx: EditorContext) {\n function duplicateSelected(selectedNodes: SceneNode[]) {\n // One undo step for the copies and any slot they claim.\n ctx.undo.runBatch('Duplicate', () => duplicateLayers(selectedNodes))\n }\n\n function duplicateLayers(selectedNodes: SceneNode[]) {\n const prevSelection = new Set(ctx.state.selectedIds)\n const selectedSet = new Set(selectedNodes.map((n) => n.id))\n const stackIndex = (node: SceneNode) =>\n ctx.graph.getNode(node.parentId ?? ctx.state.currentPageId)?.childIds.indexOf(node.id) ?? -1\n // Copy in stacking order, not selection order, so the copies stack as their originals do.\n const topLevel = selectedNodes\n .filter((n) => !n.parentId || !selectedSet.has(n.parentId))\n .sort((a, b) => stackIndex(a) - stackIndex(b))\n const parents = topLevel.map((node) => node.parentId ?? ctx.state.currentPageId)\n if (!prepareSlotEdits(ctx, parents)) return\n\n const newRootIds: string[] = []\n const allSnapshots = new Map<string, SceneNode>()\n // The topmost layer each parent's copies came from.\n const topSource = new Map<string, number>()\n\n const placed: Rect[] = []\n for (const node of topLevel) {\n const parentId = node.parentId ?? ctx.state.currentPageId\n const position =\n topLevel.length === 1\n ? placementActions.duplicatePosition(node, placed)\n : { x: node.x, y: node.y }\n const sourceIndex = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? -1\n const clone = duplicateNode(ctx, node, parentId, position)\n if (!clone) continue\n topSource.set(parentId, Math.max(topSource.get(parentId) ?? -1, sourceIndex))\n placed.push(getAxisAlignedBoundsInParent([clone], parentId, ctx.graph))\n newRootIds.push(clone.id)\n const subtree = snapshotSubtree(ctx.graph, clone.id)\n for (const [id, snap] of subtree) allSnapshots.set(id, snap)\n }\n\n // Figma stacks the copies directly above the topmost layer they copy, in their own order,\n // not on top of everything in the parent.\n const stacked = new Map<string, number>()\n const stacking = newRootIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n const top = parentId ? topSource.get(parentId) : undefined\n if (!parentId || top === undefined || top < 0) return []\n const offset = stacked.get(parentId) ?? 0\n stacked.set(parentId, offset + 1)\n return [{ id, parentId, index: top + 1 + offset }]\n })\n const stack = () => {\n for (const { id, parentId, index } of stacking) ctx.graph.insertChildAt(id, parentId, index)\n }\n // Auto layout parents lay out again, so a copy joins the flow and a hugging parent resizes.\n // Undo and redo do it too, because neither stores the parent's layout. Other parents, such\n // as the page, are skipped: laying out a page reaches every frame on it.\n const layoutParentIds = [...new Set(parents)].filter(\n (id) => ctx.graph.getNode(id)?.layoutMode !== 'NONE'\n )\n const relayoutParents = () => {\n for (const parentId of layoutParentIds) ctx.runLayoutForNode(parentId)\n }\n stack()\n\n if (newRootIds.length > 0) {\n relayoutParents()\n ctx.setSelectedIds(new Set(newRootIds))\n ctx.undo.push({\n label: 'Duplicate',\n forward: () => {\n for (const rootId of newRootIds) {\n const snapshot = allSnapshots.get(rootId)\n if (!snapshot) continue\n const parentId = snapshot.parentId ?? ctx.state.currentPageId\n restoreSubtree(ctx.graph, snapshot, parentId, allSnapshots)\n }\n stack()\n relayoutParents()\n ctx.setSelectedIds(new Set(newRootIds))\n },\n inverse: () => {\n for (const id of newRootIds.slice().reverse()) ctx.graph.deleteNode(id)\n relayoutParents()\n ctx.setSelectedIds(prevSelection)\n }\n })\n }\n }\n\n /** The selected layers a paste replaces inside their instances, read before it selects others. */\n function instanceReplacementTargets(options: PasteOptions): string[] {\n return options.replaceInInstance ? replaceableInstanceLayers(ctx, ctx.state.selectedIds) : []\n }\n\n function pushCreatedNodesUndo(\n created: string[],\n prevSelection: Set<string>,\n label = 'Paste',\n operation?: PasteHistoryOperation\n ) {\n const allNodes = collectSubtrees(ctx.graph, created)\n const pageId = ctx.state.currentPageId\n operation?.capture()\n ctx.undo.push({\n label,\n forward: () => {\n if (operation) operation.redo()\n else recreateSnapshots(ctx, allNodes, pageId)\n computeAllLayouts(ctx.graph, pageId)\n ctx.setSelectedIds(new Set(created))\n },\n inverse: () => {\n if (operation) operation.undo()\n else deleteIds(ctx, created)\n computeAllLayouts(ctx.graph, pageId)\n ctx.setSelectedIds(prevSelection)\n }\n })\n }\n\n async function pasteSnapshot(\n snapshot: ClipboardSnapshot,\n cursorPos?: Vector,\n options: PasteOptions = {}\n ) {\n // Copy properties writes layers for Paste properties only, as in Figma.\n if (snapshot.properties) return\n let created: string[] = []\n ctx.undo.runBatch('Paste', () => {\n const dependencies = importClipboardDependenciesWithUndo(ctx, snapshot, options.dependencies)\n created = pastePairdrawNodes(\n dependencies.nodes,\n snapshot.placement,\n snapshot.images,\n // Records from another document name its variables and modes, not the pasted ones.\n snapshot.sourceRootId === ctx.graph.rootId ? snapshot.appliedBoundPaints : new Map(),\n dependencies.componentDependencies,\n cursorPos,\n { ...options, resolveBindings: dependencies.resolveBindings }\n )\n })\n await fontActions.loadFontsForNodes(created)\n }\n\n async function pasteFromHTML(html: string, cursorPos?: Vector, options: PasteOptions = {}) {\n const pairdraw = parsePairdrawClipboard(html)\n if (pairdraw) {\n // One undo step for the paste and any slot it claims.\n const created = ctx.undo.runBatch('Paste', () =>\n pastePairdrawNodes(\n pairdraw.nodes,\n clipboardPlacement(ctx.graph, pairdraw.nodes),\n pairdraw.images,\n new Map(),\n [],\n cursorPos,\n options\n )\n )\n await fontActions.loadFontsForNodes(created)\n return\n }\n\n const figma = await parseFigmaClipboard(html)\n if (figma?.assetType === 'STYLE_PROPERTIES') return\n if (figma) {\n // One undo step for the paste and any slot it claims.\n const pasted = ctx.undo.runBatch('Paste', () => {\n const prevSelection = new Set(ctx.state.selectedIds)\n const replacementTargets = options.replaceSelection ? selectedReplacementTargets(ctx) : []\n const instanceTargets = instanceReplacementTargets(options)\n const pasteTarget = replacementTargets[0]?.parentId ?? resolvePasteTarget(ctx)\n if (!prepareSlotEdits(ctx, [pasteTarget])) return null\n const operation = prepareClipboardImport(figma.nodes, ctx.graph, pasteTarget, figma.blobs)\n let deliveryError: CommittedGraphEventError | undefined\n try {\n operation.commit()\n } catch (error) {\n if (!(error instanceof CommittedGraphEventError)) throw error\n deliveryError = error\n }\n const created = operation.plan.rootIds\n if (created.length === 0) return null\n\n if (replacementTargets.length > 0) {\n // The clipboard holds each layer as drawn on its canvas, and the import keeps that as\n // the layer's transform in the target's frame: turn it back, as the in-app paste does.\n const copied = created.flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [getNodeLocalMatrix(node)] : []\n })\n placementActions.keepCanvasTransforms(created, copied)\n replaceTargetsWithCreated(ctx, created, replacementTargets, prevSelection, operation)\n } else {\n placementActions.placeForeignPaste(created, pasteTarget, cursorPos)\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, prevSelection, 'Paste', operation)\n replaceInstanceLayersWith(ctx, instanceTargets, created)\n }\n return { created, deliveryError }\n })\n if (!pasted) return\n const { created, deliveryError } = pasted\n\n if (deliveryError) throw deliveryError\n await Promise.all([\n hydrateFigmaClipboardImages(figma.meta.fileKey, created),\n fontActions.loadFontsForNodes(created)\n ])\n ctx.requestRender()\n }\n }\n\n /** The name Figma gives pasted text: its first line, as the layer lists it. */\n const textLayerName = (text: string) => {\n const firstLine = text.split('\\n')[0]?.trim() ?? ''\n return firstLine.length > 64 ? `${firstLine.slice(0, 63)}…` : firstLine\n }\n\n /**\n * Paste plain text from another app as a text layer holding it, centred on the point and inside\n * the selected frame, in one undo step; false when the text has nothing to show.\n */\n async function pastePlainText(text: string, cx?: number, cy?: number): Promise<boolean> {\n const content = text.replace(/\\r\\n?/g, '\\n')\n const name = textLayerName(content)\n if (!name) return false\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n if (!prepareSlotEdits(ctx, [parentId])) return false\n const node = ctx.graph.createNode('TEXT', parentId, {\n ...newLayerDefaults('TEXT', ctx.state.theme),\n name,\n text: content,\n textAutoResize: 'WIDTH_AND_HEIGHT',\n x: 0,\n y: 0\n })\n // Measured with its font loaded, so it takes its content's size and centres on that.\n await fontActions.loadFontsForNodes([node.id])\n layoutAuthoredNodes(ctx.graph, [node.id])\n const cursorPos = cx !== undefined && cy !== undefined ? { x: cx, y: cy } : undefined\n placementActions.placeForeignPaste([node.id], parentId, cursorPos)\n if (ctx.state.snappingPreferences.pixelGrid) {\n const placed = ctx.graph.getNode(node.id)\n if (placed)\n ctx.graph.updateNode(node.id, { x: Math.round(placed.x), y: Math.round(placed.y) })\n }\n ctx.setSelectedIds(new Set([node.id]))\n pushCreatedNodesUndo([node.id], previousSelection, 'Paste text')\n ctx.requestRender()\n return true\n }\n\n function pastePairdrawNodes(\n nodes: Array<SceneNode & { children?: SceneNode[] }>,\n placement: ClipboardPlacement,\n images: Map<string, Uint8Array>,\n applied: AppliedBoundPaints,\n dependencies: Array<SceneNode & { children?: SceneNode[] }> = [],\n cursorPos?: Vector,\n options: PasteNodesOptions = {}\n ) {\n const prevSelection = new Set(ctx.state.selectedIds)\n const replacementTargets = options.replaceSelection ? selectedReplacementTargets(ctx) : []\n const instanceTargets = instanceReplacementTargets(options)\n for (const [hash, bytes] of images) ctx.graph.images.set(hash, bytes)\n\n const created: string[] = []\n const copiedIds = new Map<string, string>()\n const createNodeTree = (source: SceneNode & { children?: SceneNode[] }, parentId: string) => {\n const { id: _id, childIds: _childIds, children = [], parentId: _parentId, ...rest } = source\n const node = ctx.graph.createNode(source.type, parentId, {\n ...structuredClone(rest),\n childIds: []\n })\n copiedIds.set(source.id, node.id)\n for (const child of children) createNodeTree(child, node.id)\n return node.id\n }\n\n const { requestedTarget, returningTo } = requestedPasteTarget(\n ctx,\n placement.sources.map((source) => source?.id ?? null),\n replacementTargets[0]?.parentId ?? null,\n !!cursorPos\n )\n const pasteTarget = cycleSafeParent(\n ctx.graph,\n requestedTarget,\n pastedComponentIds(ctx.graph, [...nodes, ...dependencies])\n )\n if (!prepareSlotEdits(ctx, [pasteTarget])) return created\n const dependencyRootIds: string[] = []\n for (const dependency of dependencies)\n dependencyRootIds.push(createNodeTree(dependency, ctx.state.currentPageId))\n for (const node of nodes) created.push(createNodeTree(node, pasteTarget))\n for (const id of copiedIds.values()) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n const componentId = node.componentId ? copiedIds.get(node.componentId) : undefined\n const instanceOverrides = {\n self: node.instanceOverrides.self,\n descendants: new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copiedIds.get(target) ?? target,\n fields\n ])\n )\n }\n ctx.graph.updateNode(id, { componentId: componentId ?? node.componentId, instanceOverrides })\n }\n keepPastedBoundPaints(ctx.graph, copiedIds, applied)\n // Variables of this document can give the layers other values than the copied ones.\n if (options.resolveBindings) {\n const subtrees = [...dependencyRootIds, ...created]\n loadBoundFonts(ctx, reconcileVariableLayouts(ctx.graph, { subtrees }))\n }\n if (dependencyRootIds.length > 0) {\n const snapshots = collectSubtrees(ctx.graph, dependencyRootIds)\n ctx.undo.push({\n label: 'Import component dependencies',\n forward: () => recreateSnapshots(ctx, snapshots, ctx.state.currentPageId),\n inverse: () => deleteIds(ctx, dependencyRootIds)\n })\n }\n if (created.length === 0) return created\n placementActions.keepCanvasTransforms(created, placement.transforms)\n\n if (replacementTargets.length > 0) {\n replaceTargetsWithCreated(ctx, created, replacementTargets, prevSelection)\n return created\n }\n\n if (cursorPos) placementActions.centerNodesAtCanvasPoint(created, cursorPos)\n else if (returningTo === pasteTarget) placementActions.placeReturned(created)\n else placementActions.placePasted(created, placement, pasteTarget, requestedTarget)\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n\n pushCreatedNodesUndo(created, prevSelection)\n replaceInstanceLayersWith(ctx, instanceTargets, created)\n return created\n }\n\n function missingImageHashes(nodeIds: string[]) {\n const hashes = new Set<string>()\n for (const node of collectSubtrees(ctx.graph, nodeIds)) {\n for (const fill of node.fills) {\n if (fill.type === 'IMAGE' && fill.imageHash && !ctx.graph.images.has(fill.imageHash)) {\n hashes.add(fill.imageHash)\n }\n }\n }\n return [...hashes]\n }\n\n async function hydrateFigmaClipboardImages(fileKey: string, nodeIds: string[]) {\n const hashes = missingImageHashes(nodeIds)\n if (hashes.length === 0) return\n\n const resolver = ctx.resolveFigmaClipboardImages\n if (resolver) {\n try {\n const images = await resolver(fileKey, hashes)\n for (const hash of hashes) {\n const bytes = images.get(hash)\n if (bytes) ctx.graph.images.set(hash, bytes)\n }\n } catch (error) {\n console.warn('Failed to fetch Figma clipboard images', error)\n }\n }\n\n const missing = missingImageHashes(nodeIds).length\n if (missing > 0) {\n ctx.emitEditorEvent('clipboard:images-missing', {\n total: hashes.length,\n missing,\n fetchAttempted: Boolean(resolver)\n })\n }\n }\n\n function warnMissingImages(nodeIds: string[]) {\n return missingImageHashes(nodeIds).length > 0\n }\n\n /**\n * Deletes layers with their children as one undo step, skipping locked ones and, as in Figma,\n * layers of an instance outside its slots. Deleted layers leave the selection, and undo\n * restores the selection from before.\n */\n function deleteNodes(nodeIds: Iterable<string>, nextSelection?: ReadonlySet<string>) {\n // One undo step for the delete and any slot it claims.\n ctx.undo.runBatch('Delete', () => deleteLayers(nodeIds, nextSelection))\n }\n\n /** Whether a delete removes this layer: one that is unlocked and may leave its parent. */\n function deletable(id: string): boolean {\n const node = ctx.graph.getNode(id)\n if (!node || node.locked) return false\n return acceptsChildren(ctx, node.parentId ?? ctx.state.currentPageId)\n }\n\n /**\n * Whether the layer is one an instance mirrors from its component. A slot's contents are the\n * document's own, placed in the instance, so they delete like any other layer.\n */\n function insideInstance(id: string): boolean {\n let parentId = ctx.graph.getNode(id)?.parentId ?? null\n while (parentId) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return false\n if (parent.type === 'INSTANCE') return true\n if (slotPropertyId(parent)) return false\n parentId = parent.parentId\n }\n return false\n }\n\n function deleteLayers(nodeIds: Iterable<string>, nextSelection?: ReadonlySet<string>) {\n // Deleting a component child would take it out of every instance, so inside an instance it\n // is a hide instead, recorded as an override: Figma reopens the file with it still hidden.\n const requested: string[] = []\n const hidden: Array<{ id: string; visible: boolean }> = []\n for (const id of nodeIds) {\n const node = ctx.graph.getNode(id)\n if (!node || node.locked) continue\n // No parent takes children inside an instance, but hiding one is the delete Figma offers.\n if (insideInstance(id)) {\n if (node.visible) hidden.push({ id, visible: node.visible })\n } else if (deletable(id)) requested.push(id)\n }\n const hideLayers = () => {\n for (const { id } of hidden) {\n ctx.graph.updateNode(id, { visible: false })\n recordInstanceOverride(ctx.graph, id, ['visible'])\n }\n }\n // Connectors go with a layer they attach to, as in FigJam; one that stays keeps them.\n const attached = attachedConnectors(ctx.graph, requested).map((node) => node.id)\n const targets: Array<{ id: string; parentId: string; index: number }> = []\n for (const id of uniq([...requested, ...attached])) {\n const node = ctx.graph.getNode(id)\n if (!node || !deletable(id)) continue\n const parentId = node.parentId ?? ctx.state.currentPageId\n const parent = ctx.graph.getNode(parentId)\n const index = parent?.childIds.indexOf(id) ?? -1\n targets.push({ id, parentId, index })\n }\n if (targets.length === 0 && hidden.length === 0) return\n prepareSlotEdits(\n ctx,\n targets.map((entry) => entry.parentId)\n )\n // The slot edits above may change what a layer's subtree holds, so it is captured once, after.\n const entries = targets.map((entry) => ({\n ...entry,\n subtree: snapshotSubtree(ctx.graph, entry.id)\n }))\n\n const relayoutParents = () => {\n for (const parentId of new Set(entries.map((entry) => entry.parentId))) {\n ctx.runLayoutForNode(parentId)\n }\n }\n hideLayers()\n\n const prevSelection = new Set(ctx.state.selectedIds)\n for (const { id } of entries) ctx.graph.deleteNode(id)\n relayoutParents()\n const selectionAfter =\n nextSelection ?? new Set([...prevSelection].filter((id) => ctx.graph.getNode(id)))\n\n ctx.undo.push({\n label: 'Delete',\n forward: () => {\n for (const { id } of entries) ctx.graph.deleteNode(id)\n hideLayers()\n relayoutParents()\n ctx.setSelectedIds(new Set(selectionAfter))\n },\n inverse: () => {\n restoreDeletedEntries(ctx, entries)\n for (const { id, visible } of hidden) {\n ctx.graph.updateNode(id, { visible })\n recordInstanceOverride(ctx.graph, id, ['visible'])\n }\n relayoutParents()\n ctx.setSelectedIds(prevSelection)\n }\n })\n // Groups shrink to the layers left in them, and one left empty goes, in the same undo step,\n // which `deleteNodes` batches.\n fitEnclosingGroupsWithUndo(\n ctx,\n entries.map((entry) => entry.parentId)\n )\n ctx.setSelectedIds(new Set(selectionAfter))\n }\n\n function deleteSelected() {\n deleteNodes(ctx.state.selectedIds, new Set())\n }\n\n const copyActions = createClipboardCopyActions(ctx)\n const exportActions = createClipboardExportActions(ctx)\n const fontActions = createClipboardFontActions(ctx)\n const assetActions = createClipboardAssetActions(ctx, pushCreatedNodesUndo)\n const placementActions = createClipboardPlacementActions(ctx)\n const styledActions = createStyledPasteActions(ctx, {\n pushCreatedNodesUndo,\n placeForeignPaste: placementActions.placeForeignPaste,\n loadFontsForNodes: fontActions.loadFontsForNodes\n })\n\n return {\n collectSubtrees,\n ...placementActions,\n ...fontActions,\n duplicateSelected,\n duplicateNode: (node: SceneNode, parentId: string, position: Vector) =>\n duplicateNode(ctx, node, parentId, position),\n ...copyActions,\n pasteSnapshot,\n pasteFromHTML,\n pastePlainText,\n warnMissingImages,\n deleteNodes,\n deleteSelected,\n ...assetActions,\n ...styledActions,\n ...exportActions\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,cACd,KACA,MACA,UACA,UACkB;CAClB,MAAM,SAAS,IAAI,MAAM,QAAQ,QAAQ;CACzC,IAAI,KAAK,SAAS,eAAe,QAAQ,SAAS,iBAChD,OAAO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["../../src/editor/clipboard.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport { parseFigmaClipboard } from '@pairdraw/fig/clipboard'\nimport { CommittedGraphEventError, type SceneNode } from '@pairdraw/scene-graph'\nimport { attachedConnectors } from '@pairdraw/scene-graph/connectors'\nimport { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { cycleSafeParent, recordInstanceOverride } from '@pairdraw/scene-graph/instances'\nimport type { Rect, Vector } from '@pairdraw/scene-graph/primitives'\nimport { slotPropertyId } from '@pairdraw/scene-graph/slots'\nimport { keepPastedBoundPaints, type AppliedBoundPaints } from '@pairdraw/scene-graph/variables'\n\nimport { parsePairdrawClipboard } from '#core/clipboard'\nimport { prepareClipboardImport } from '#core/clipboard/fig-import'\nimport { computeAllLayouts, layoutAuthoredNodes } from '#core/layout'\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { createClipboardAssetActions } from './clipboard/assets'\nimport type { ClipboardImportChoice } from './clipboard/conflicts'\nimport type { ClipboardSnapshot } from './clipboard/copy'\nimport { createClipboardCopyActions } from './clipboard/copy'\nimport { importClipboardDependenciesWithUndo } from './clipboard/dependencies'\nimport { createClipboardExportActions } from './clipboard/export'\nimport { createClipboardFontActions } from './clipboard/fonts'\nimport { deleteIds, recreateSnapshots, restoreDeletedEntries } from './clipboard/history'\nimport type { PasteHistoryOperation } from './clipboard/paste/replace'\nimport { replaceTargetsWithCreated, selectedReplacementTargets } from './clipboard/paste/replace'\nimport {\n pastedComponentIds,\n requestedPasteTarget,\n resolvePasteTarget\n} from './clipboard/paste/target'\nimport {\n clipboardPlacement,\n createClipboardPlacementActions,\n type ClipboardPlacement\n} from './clipboard/placement'\nimport { createStyledPasteActions } from './clipboard/styled'\nimport { replaceableInstanceLayers, replaceInstanceLayersWith } from './components/replace'\nimport { acceptsChildren, prepareSlotEdits } from './components/slots'\nimport { collectSubtrees, restoreSubtree, snapshotSubtree } from './history/subtree'\nimport { newLayerDefaults } from './shapes/defaults'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport { loadBoundFonts } from './text/bound-fonts'\nimport type { EditorContext } from './types'\n\ntype PasteOptions = {\n replaceSelection?: boolean\n /**\n * Put the pasted layer in place of each selected layer inside an instance, as an override of\n * that instance (pen.dev's Replace inside instance), in the same undo step as the paste.\n */\n replaceInInstance?: boolean\n /** How a copy from another document brings its variables and styles (`planClipboardImport`). */\n dependencies?: ClipboardImportChoice\n}\n\ntype PasteNodesOptions = PasteOptions & {\n /** Resolve the pasted layers' variable bindings where they land, before history records them. */\n resolveBindings?: boolean\n}\n\n/**\n * A copy of the layer under the same parent, keeping its name as Figma does. A main component\n * outside a component set duplicates as an instance of itself.\n */\nexport function duplicateNode(\n ctx: Pick<EditorContext, 'graph'>,\n node: SceneNode,\n parentId: string,\n position: Vector\n): SceneNode | null {\n const parent = ctx.graph.getNode(parentId)\n if (node.type === 'COMPONENT' && parent?.type !== 'COMPONENT_SET') {\n return ctx.graph.createInstance(node.id, parentId, { name: node.name, ...position })\n }\n return ctx.graph.cloneTree(node.id, parentId, { name: node.name, ...position })\n}\n\nexport function createClipboardActions(ctx: EditorContext) {\n function duplicateSelected(selectedNodes: SceneNode[]) {\n // One undo step for the copies and any slot they claim.\n ctx.undo.runBatch('Duplicate', () => duplicateLayers(selectedNodes))\n }\n\n function duplicateLayers(selectedNodes: SceneNode[]) {\n const prevSelection = new Set(ctx.state.selectedIds)\n const selectedSet = new Set(selectedNodes.map((n) => n.id))\n const stackIndex = (node: SceneNode) =>\n ctx.graph.getNode(node.parentId ?? ctx.state.currentPageId)?.childIds.indexOf(node.id) ?? -1\n // Copy in stacking order, not selection order, so the copies stack as their originals do.\n const topLevel = selectedNodes\n .filter((n) => !n.parentId || !selectedSet.has(n.parentId))\n .sort((a, b) => stackIndex(a) - stackIndex(b))\n const parents = topLevel.map((node) => node.parentId ?? ctx.state.currentPageId)\n if (!prepareSlotEdits(ctx, parents)) return\n\n const newRootIds: string[] = []\n const allSnapshots = new Map<string, SceneNode>()\n // The topmost layer each parent's copies came from.\n const topSource = new Map<string, number>()\n\n const placed: Rect[] = []\n for (const node of topLevel) {\n const parentId = node.parentId ?? ctx.state.currentPageId\n const position =\n topLevel.length === 1\n ? placementActions.duplicatePosition(node, placed)\n : { x: node.x, y: node.y }\n const sourceIndex = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? -1\n const clone = duplicateNode(ctx, node, parentId, position)\n if (!clone) continue\n topSource.set(parentId, Math.max(topSource.get(parentId) ?? -1, sourceIndex))\n placed.push(getAxisAlignedBoundsInParent([clone], parentId, ctx.graph))\n newRootIds.push(clone.id)\n const subtree = snapshotSubtree(ctx.graph, clone.id)\n for (const [id, snap] of subtree) allSnapshots.set(id, snap)\n }\n\n // Figma stacks the copies directly above the topmost layer they copy, in their own order,\n // not on top of everything in the parent.\n const stacked = new Map<string, number>()\n const stacking = newRootIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n const top = parentId ? topSource.get(parentId) : undefined\n if (!parentId || top === undefined || top < 0) return []\n const offset = stacked.get(parentId) ?? 0\n stacked.set(parentId, offset + 1)\n return [{ id, parentId, index: top + 1 + offset }]\n })\n const stack = () => {\n for (const { id, parentId, index } of stacking) ctx.graph.insertChildAt(id, parentId, index)\n }\n // A copy joins its parent's flow and a hugging parent resizes, on undo and redo too, since\n // neither stores the parent's layout.\n const relayoutParents = () => ctx.runLayoutForParents(parents)\n stack()\n\n if (newRootIds.length > 0) {\n relayoutParents()\n ctx.setSelectedIds(new Set(newRootIds))\n ctx.undo.push({\n label: 'Duplicate',\n forward: () => {\n for (const rootId of newRootIds) {\n const snapshot = allSnapshots.get(rootId)\n if (!snapshot) continue\n const parentId = snapshot.parentId ?? ctx.state.currentPageId\n restoreSubtree(ctx.graph, snapshot, parentId, allSnapshots)\n }\n stack()\n relayoutParents()\n ctx.setSelectedIds(new Set(newRootIds))\n },\n inverse: () => {\n for (const id of newRootIds.slice().reverse()) ctx.graph.deleteNode(id)\n relayoutParents()\n ctx.setSelectedIds(prevSelection)\n }\n })\n }\n }\n\n /** The selected layers a paste replaces inside their instances, read before it selects others. */\n function instanceReplacementTargets(options: PasteOptions): string[] {\n return options.replaceInInstance ? replaceableInstanceLayers(ctx, ctx.state.selectedIds) : []\n }\n\n function pushCreatedNodesUndo(\n created: string[],\n prevSelection: Set<string>,\n label = 'Paste',\n operation?: PasteHistoryOperation\n ) {\n const allNodes = collectSubtrees(ctx.graph, created)\n const pageId = ctx.state.currentPageId\n operation?.capture()\n ctx.undo.push({\n label,\n forward: () => {\n if (operation) operation.redo()\n else recreateSnapshots(ctx, allNodes, pageId)\n computeAllLayouts(ctx.graph, pageId)\n ctx.setSelectedIds(new Set(created))\n },\n inverse: () => {\n if (operation) operation.undo()\n else deleteIds(ctx, created)\n computeAllLayouts(ctx.graph, pageId)\n ctx.setSelectedIds(prevSelection)\n }\n })\n }\n\n async function pasteSnapshot(\n snapshot: ClipboardSnapshot,\n cursorPos?: Vector,\n options: PasteOptions = {}\n ) {\n // Copy properties writes layers for Paste properties only, as in Figma.\n if (snapshot.properties) return\n let created: string[] = []\n ctx.undo.runBatch('Paste', () => {\n const dependencies = importClipboardDependenciesWithUndo(ctx, snapshot, options.dependencies)\n created = pastePairdrawNodes(\n dependencies.nodes,\n snapshot.placement,\n snapshot.images,\n // Records from another document name its variables and modes, not the pasted ones.\n snapshot.sourceRootId === ctx.graph.rootId ? snapshot.appliedBoundPaints : new Map(),\n dependencies.componentDependencies,\n cursorPos,\n { ...options, resolveBindings: dependencies.resolveBindings }\n )\n })\n await fontActions.loadFontsForNodes(created)\n }\n\n async function pasteFromHTML(html: string, cursorPos?: Vector, options: PasteOptions = {}) {\n const pairdraw = parsePairdrawClipboard(html)\n if (pairdraw) {\n // One undo step for the paste and any slot it claims.\n const created = ctx.undo.runBatch('Paste', () =>\n pastePairdrawNodes(\n pairdraw.nodes,\n clipboardPlacement(ctx.graph, pairdraw.nodes),\n pairdraw.images,\n new Map(),\n [],\n cursorPos,\n options\n )\n )\n await fontActions.loadFontsForNodes(created)\n return\n }\n\n const figma = await parseFigmaClipboard(html)\n if (figma?.assetType === 'STYLE_PROPERTIES') return\n if (figma) {\n // One undo step for the paste and any slot it claims.\n const pasted = ctx.undo.runBatch('Paste', () => {\n const prevSelection = new Set(ctx.state.selectedIds)\n const replacementTargets = options.replaceSelection ? selectedReplacementTargets(ctx) : []\n const instanceTargets = instanceReplacementTargets(options)\n const pasteTarget = replacementTargets[0]?.parentId ?? resolvePasteTarget(ctx)\n if (!prepareSlotEdits(ctx, [pasteTarget])) return null\n const operation = prepareClipboardImport(figma.nodes, ctx.graph, pasteTarget, figma.blobs)\n let deliveryError: CommittedGraphEventError | undefined\n try {\n operation.commit()\n } catch (error) {\n if (!(error instanceof CommittedGraphEventError)) throw error\n deliveryError = error\n }\n const created = operation.plan.rootIds\n if (created.length === 0) return null\n\n if (replacementTargets.length > 0) {\n // The clipboard holds each layer as drawn on its canvas, and the import keeps that as\n // the layer's transform in the target's frame: turn it back, as the in-app paste does.\n const copied = created.flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [getNodeLocalMatrix(node)] : []\n })\n placementActions.keepCanvasTransforms(created, copied)\n replaceTargetsWithCreated(ctx, created, replacementTargets, prevSelection, operation)\n } else {\n placementActions.placeForeignPaste(created, pasteTarget, cursorPos)\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, prevSelection, 'Paste', operation)\n replaceInstanceLayersWith(ctx, instanceTargets, created)\n }\n return { created, deliveryError }\n })\n if (!pasted) return\n const { created, deliveryError } = pasted\n\n if (deliveryError) throw deliveryError\n await Promise.all([\n hydrateFigmaClipboardImages(figma.meta.fileKey, created),\n fontActions.loadFontsForNodes(created)\n ])\n ctx.requestRender()\n }\n }\n\n /** The name Figma gives pasted text: its first line, as the layer lists it. */\n const textLayerName = (text: string) => {\n const firstLine = text.split('\\n')[0]?.trim() ?? ''\n return firstLine.length > 64 ? `${firstLine.slice(0, 63)}…` : firstLine\n }\n\n /**\n * Paste plain text from another app as a text layer holding it, centred on the point and inside\n * the selected frame, in one undo step; false when the text has nothing to show.\n */\n async function pastePlainText(text: string, cx?: number, cy?: number): Promise<boolean> {\n const content = text.replace(/\\r\\n?/g, '\\n')\n const name = textLayerName(content)\n if (!name) return false\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n if (!prepareSlotEdits(ctx, [parentId])) return false\n const node = ctx.graph.createNode('TEXT', parentId, {\n ...newLayerDefaults('TEXT', ctx.state.theme),\n name,\n text: content,\n textAutoResize: 'WIDTH_AND_HEIGHT',\n x: 0,\n y: 0\n })\n // Measured with its font loaded, so it takes its content's size and centres on that.\n await fontActions.loadFontsForNodes([node.id])\n layoutAuthoredNodes(ctx.graph, [node.id])\n const cursorPos = cx !== undefined && cy !== undefined ? { x: cx, y: cy } : undefined\n placementActions.placeForeignPaste([node.id], parentId, cursorPos)\n if (ctx.state.snappingPreferences.pixelGrid) {\n const placed = ctx.graph.getNode(node.id)\n if (placed)\n ctx.graph.updateNode(node.id, { x: Math.round(placed.x), y: Math.round(placed.y) })\n }\n ctx.setSelectedIds(new Set([node.id]))\n pushCreatedNodesUndo([node.id], previousSelection, 'Paste text')\n ctx.requestRender()\n return true\n }\n\n function pastePairdrawNodes(\n nodes: Array<SceneNode & { children?: SceneNode[] }>,\n placement: ClipboardPlacement,\n images: Map<string, Uint8Array>,\n applied: AppliedBoundPaints,\n dependencies: Array<SceneNode & { children?: SceneNode[] }> = [],\n cursorPos?: Vector,\n options: PasteNodesOptions = {}\n ) {\n const prevSelection = new Set(ctx.state.selectedIds)\n const replacementTargets = options.replaceSelection ? selectedReplacementTargets(ctx) : []\n const instanceTargets = instanceReplacementTargets(options)\n for (const [hash, bytes] of images) ctx.graph.images.set(hash, bytes)\n\n const created: string[] = []\n const copiedIds = new Map<string, string>()\n const createNodeTree = (source: SceneNode & { children?: SceneNode[] }, parentId: string) => {\n const { id: _id, childIds: _childIds, children = [], parentId: _parentId, ...rest } = source\n const node = ctx.graph.createNode(source.type, parentId, {\n ...structuredClone(rest),\n childIds: []\n })\n copiedIds.set(source.id, node.id)\n for (const child of children) createNodeTree(child, node.id)\n return node.id\n }\n\n const { requestedTarget, returningTo } = requestedPasteTarget(\n ctx,\n placement.sources.map((source) => source?.id ?? null),\n replacementTargets[0]?.parentId ?? null,\n !!cursorPos\n )\n const pasteTarget = cycleSafeParent(\n ctx.graph,\n requestedTarget,\n pastedComponentIds(ctx.graph, [...nodes, ...dependencies])\n )\n if (!prepareSlotEdits(ctx, [pasteTarget])) return created\n const dependencyRootIds: string[] = []\n for (const dependency of dependencies)\n dependencyRootIds.push(createNodeTree(dependency, ctx.state.currentPageId))\n for (const node of nodes) created.push(createNodeTree(node, pasteTarget))\n for (const id of copiedIds.values()) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n const componentId = node.componentId ? copiedIds.get(node.componentId) : undefined\n const instanceOverrides = {\n self: node.instanceOverrides.self,\n descendants: new Map(\n [...node.instanceOverrides.descendants].map(([target, fields]) => [\n copiedIds.get(target) ?? target,\n fields\n ])\n )\n }\n ctx.graph.updateNode(id, { componentId: componentId ?? node.componentId, instanceOverrides })\n }\n keepPastedBoundPaints(ctx.graph, copiedIds, applied)\n // Variables of this document can give the layers other values than the copied ones.\n if (options.resolveBindings) {\n const subtrees = [...dependencyRootIds, ...created]\n loadBoundFonts(ctx, reconcileVariableLayouts(ctx.graph, { subtrees }))\n }\n if (dependencyRootIds.length > 0) {\n const snapshots = collectSubtrees(ctx.graph, dependencyRootIds)\n ctx.undo.push({\n label: 'Import component dependencies',\n forward: () => recreateSnapshots(ctx, snapshots, ctx.state.currentPageId),\n inverse: () => deleteIds(ctx, dependencyRootIds)\n })\n }\n if (created.length === 0) return created\n placementActions.keepCanvasTransforms(created, placement.transforms)\n\n if (replacementTargets.length > 0) {\n replaceTargetsWithCreated(ctx, created, replacementTargets, prevSelection)\n return created\n }\n\n if (cursorPos) placementActions.centerNodesAtCanvasPoint(created, cursorPos)\n else if (returningTo === pasteTarget) placementActions.placeReturned(created)\n else placementActions.placePasted(created, placement, pasteTarget, requestedTarget)\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n\n pushCreatedNodesUndo(created, prevSelection)\n replaceInstanceLayersWith(ctx, instanceTargets, created)\n return created\n }\n\n function missingImageHashes(nodeIds: string[]) {\n const hashes = new Set<string>()\n for (const node of collectSubtrees(ctx.graph, nodeIds)) {\n for (const fill of node.fills) {\n if (fill.type === 'IMAGE' && fill.imageHash && !ctx.graph.images.has(fill.imageHash)) {\n hashes.add(fill.imageHash)\n }\n }\n }\n return [...hashes]\n }\n\n async function hydrateFigmaClipboardImages(fileKey: string, nodeIds: string[]) {\n const hashes = missingImageHashes(nodeIds)\n if (hashes.length === 0) return\n\n const resolver = ctx.resolveFigmaClipboardImages\n if (resolver) {\n try {\n const images = await resolver(fileKey, hashes)\n for (const hash of hashes) {\n const bytes = images.get(hash)\n if (bytes) ctx.graph.images.set(hash, bytes)\n }\n } catch (error) {\n console.warn('Failed to fetch Figma clipboard images', error)\n }\n }\n\n const missing = missingImageHashes(nodeIds).length\n if (missing > 0) {\n ctx.emitEditorEvent('clipboard:images-missing', {\n total: hashes.length,\n missing,\n fetchAttempted: Boolean(resolver)\n })\n }\n }\n\n function warnMissingImages(nodeIds: string[]) {\n return missingImageHashes(nodeIds).length > 0\n }\n\n /**\n * Deletes layers with their children as one undo step, skipping locked ones and, as in Figma,\n * layers of an instance outside its slots. Deleted layers leave the selection, and undo\n * restores the selection from before.\n */\n function deleteNodes(nodeIds: Iterable<string>, nextSelection?: ReadonlySet<string>) {\n // One undo step for the delete and any slot it claims.\n ctx.undo.runBatch('Delete', () => deleteLayers(nodeIds, nextSelection))\n }\n\n /** Whether a delete removes this layer: one that is unlocked and may leave its parent. */\n function deletable(id: string): boolean {\n const node = ctx.graph.getNode(id)\n if (!node || node.locked) return false\n return acceptsChildren(ctx, node.parentId ?? ctx.state.currentPageId)\n }\n\n /**\n * Whether the layer is one an instance mirrors from its component. A slot's contents are the\n * document's own, placed in the instance, so they delete like any other layer.\n */\n function insideInstance(id: string): boolean {\n let parentId = ctx.graph.getNode(id)?.parentId ?? null\n while (parentId) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return false\n if (parent.type === 'INSTANCE') return true\n if (slotPropertyId(parent)) return false\n parentId = parent.parentId\n }\n return false\n }\n\n function deleteLayers(nodeIds: Iterable<string>, nextSelection?: ReadonlySet<string>) {\n // Deleting a component child would take it out of every instance, so inside an instance it\n // is a hide instead, recorded as an override: Figma reopens the file with it still hidden.\n const requested: string[] = []\n const hidden: Array<{ id: string; visible: boolean }> = []\n for (const id of nodeIds) {\n const node = ctx.graph.getNode(id)\n if (!node || node.locked) continue\n // No parent takes children inside an instance, but hiding one is the delete Figma offers.\n if (insideInstance(id)) {\n if (node.visible) hidden.push({ id, visible: node.visible })\n } else if (deletable(id)) requested.push(id)\n }\n const hideLayers = () => {\n for (const { id } of hidden) {\n ctx.graph.updateNode(id, { visible: false })\n recordInstanceOverride(ctx.graph, id, ['visible'])\n }\n }\n // Connectors go with a layer they attach to, as in FigJam; one that stays keeps them.\n const attached = attachedConnectors(ctx.graph, requested).map((node) => node.id)\n const targets: Array<{ id: string; parentId: string; index: number }> = []\n for (const id of uniq([...requested, ...attached])) {\n const node = ctx.graph.getNode(id)\n if (!node || !deletable(id)) continue\n const parentId = node.parentId ?? ctx.state.currentPageId\n const parent = ctx.graph.getNode(parentId)\n const index = parent?.childIds.indexOf(id) ?? -1\n targets.push({ id, parentId, index })\n }\n if (targets.length === 0 && hidden.length === 0) return\n prepareSlotEdits(\n ctx,\n targets.map((entry) => entry.parentId)\n )\n // The slot edits above may change what a layer's subtree holds, so it is captured once, after.\n const entries = targets.map((entry) => ({\n ...entry,\n subtree: snapshotSubtree(ctx.graph, entry.id)\n }))\n\n const relayoutParents = () => ctx.runLayoutForParents(entries.map((entry) => entry.parentId))\n hideLayers()\n\n const prevSelection = new Set(ctx.state.selectedIds)\n for (const { id } of entries) ctx.graph.deleteNode(id)\n relayoutParents()\n const selectionAfter =\n nextSelection ?? new Set([...prevSelection].filter((id) => ctx.graph.getNode(id)))\n\n ctx.undo.push({\n label: 'Delete',\n forward: () => {\n for (const { id } of entries) ctx.graph.deleteNode(id)\n hideLayers()\n relayoutParents()\n ctx.setSelectedIds(new Set(selectionAfter))\n },\n inverse: () => {\n restoreDeletedEntries(ctx, entries)\n for (const { id, visible } of hidden) {\n ctx.graph.updateNode(id, { visible })\n recordInstanceOverride(ctx.graph, id, ['visible'])\n }\n relayoutParents()\n ctx.setSelectedIds(prevSelection)\n }\n })\n // Groups shrink to the layers left in them, and one left empty goes, in the same undo step,\n // which `deleteNodes` batches.\n fitEnclosingGroupsWithUndo(\n ctx,\n entries.map((entry) => entry.parentId)\n )\n ctx.setSelectedIds(new Set(selectionAfter))\n }\n\n function deleteSelected() {\n deleteNodes(ctx.state.selectedIds, new Set())\n }\n\n const copyActions = createClipboardCopyActions(ctx)\n const exportActions = createClipboardExportActions(ctx)\n const fontActions = createClipboardFontActions(ctx)\n const assetActions = createClipboardAssetActions(ctx, pushCreatedNodesUndo)\n const placementActions = createClipboardPlacementActions(ctx)\n const styledActions = createStyledPasteActions(ctx, {\n pushCreatedNodesUndo,\n placeForeignPaste: placementActions.placeForeignPaste,\n loadFontsForNodes: fontActions.loadFontsForNodes\n })\n\n return {\n collectSubtrees,\n ...placementActions,\n ...fontActions,\n duplicateSelected,\n duplicateNode: (node: SceneNode, parentId: string, position: Vector) =>\n duplicateNode(ctx, node, parentId, position),\n ...copyActions,\n pasteSnapshot,\n pasteFromHTML,\n pastePlainText,\n warnMissingImages,\n deleteNodes,\n deleteSelected,\n ...assetActions,\n ...styledActions,\n ...exportActions\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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,YAAA,oBAAkB,OACxB"}
1
+ {"version":3,"file":"color-space.d.ts","names":[],"sources":["../../src/editor/color-space.ts"],"mappings":";;;KAMY;iBAqEI,wBAAwB,KAAK;EAE7B,wBAAA,YAAA,oBAAkB,OACxB"}
@@ -1,50 +1,42 @@
1
1
  import { copyEffects, copyFill, copyStroke, copyStyleRuns } from "@pairdraw/scene-graph/copy";
2
- import { resolveOkHCLForPreview, rgbaToOkHCL } from "@pairdraw/scene-graph/color";
2
+ import { okhclToRGBA, rgbaToOkHCL } from "@pairdraw/scene-graph/color";
3
3
  //#region src/editor/color-space.ts
4
- function remapColor(color, target) {
5
- return resolveOkHCLForPreview(rgbaToOkHCL(color), { documentColorSpace: target }).color;
4
+ function remapColor(color, source, target) {
5
+ if (source === target) return color;
6
+ return okhclToRGBA(rgbaToOkHCL(color, source), target);
6
7
  }
7
- function remapNodeColors(node, target, mode) {
8
+ /** A paint's colours in the target space: the base colour, a gradient's stops, and mesh points. */
9
+ function remapPaint(next, fill, source, target) {
10
+ const resolved = remapColor(fill.color, source, target);
11
+ next.color = resolved;
12
+ if (fill.type === "SOLID") next.opacity = resolved.a;
13
+ if (fill.gradientStops) next.gradientStops = fill.gradientStops.map((stop) => ({
14
+ ...stop,
15
+ color: remapColor(stop.color, source, target)
16
+ }));
17
+ if (fill.meshPoints) next.meshPoints = fill.meshPoints.map((point) => ({
18
+ ...point,
19
+ color: remapColor(point.color, source, target)
20
+ }));
21
+ return next;
22
+ }
23
+ function remapFill(fill, source, target) {
24
+ return remapPaint(copyFill(fill), fill, source, target);
25
+ }
26
+ function remapNodeColors(node, source, target, mode) {
8
27
  if (mode === "assign") return null;
9
28
  return {
10
- fills: node.fills.map((fill) => {
11
- const next = copyFill(fill);
12
- if (fill.type === "SOLID") {
13
- const resolved = remapColor(fill.color, target);
14
- next.color = resolved;
15
- next.opacity = resolved.a;
16
- return next;
17
- }
18
- if (fill.gradientStops) next.gradientStops = fill.gradientStops.map((stop) => ({
19
- ...stop,
20
- color: remapColor(stop.color, target)
21
- }));
22
- return next;
23
- }),
24
- strokes: node.strokes.map((stroke) => {
25
- const next = copyStroke(stroke);
26
- const resolved = remapColor(stroke.color, target);
27
- next.color = resolved;
28
- next.opacity = resolved.a;
29
- return next;
30
- }),
29
+ fills: node.fills.map((fill) => remapFill(fill, source, target)),
30
+ strokes: node.strokes.map((stroke) => remapPaint(copyStroke(stroke), stroke, source, target)),
31
31
  effects: copyEffects(node.effects).map((effect) => effect.type === "SHADER" ? effect : {
32
32
  ...effect,
33
- color: remapColor(effect.color, target)
33
+ color: remapColor(effect.color, source, target)
34
34
  }),
35
35
  styleRuns: copyStyleRuns(node.styleRuns).map((run) => ({
36
36
  ...run,
37
37
  style: {
38
38
  ...run.style,
39
- fills: run.style.fills?.map((fill) => {
40
- const next = copyFill(fill);
41
- if (fill.type === "SOLID") {
42
- const resolved = remapColor(fill.color, target);
43
- next.color = resolved;
44
- next.opacity = resolved.a;
45
- }
46
- return next;
47
- })
39
+ fills: run.style.fills?.map((fill) => remapFill(fill, source, target))
48
40
  }
49
41
  }))
50
42
  };
@@ -52,9 +44,12 @@ function remapNodeColors(node, target, mode) {
52
44
  function createColorSpaceActions(ctx) {
53
45
  function setDocumentColorSpace(colorSpace, mode = "assign") {
54
46
  if (ctx.graph.documentColorSpace === colorSpace) return;
55
- if (mode === "convert") for (const node of ctx.graph.getAllNodes()) {
56
- const changes = remapNodeColors(node, colorSpace, mode);
57
- if (changes) ctx.graph.updateNode(node.id, changes);
47
+ if (mode === "convert") {
48
+ const source = ctx.graph.documentColorSpace;
49
+ for (const node of ctx.graph.getAllNodes()) {
50
+ const changes = remapNodeColors(node, source, colorSpace, mode);
51
+ if (changes) ctx.graph.updateNode(node.id, changes);
52
+ }
58
53
  }
59
54
  ctx.graph.documentColorSpace = colorSpace;
60
55
  ctx.emitEditorEvent("document:color-space-changed", colorSpace);
@@ -1 +1 @@
1
- {"version":3,"file":"color-space.js","names":[],"sources":["../../src/editor/color-space.ts"],"sourcesContent":["import type { DocumentColorSpace, SceneNode } from '@pairdraw/scene-graph'\nimport { resolveOkHCLForPreview, rgbaToOkHCL } from '@pairdraw/scene-graph/color'\nimport { copyEffects, copyFill, copyStyleRuns, copyStroke } from '@pairdraw/scene-graph/copy'\n\nimport type { EditorContext } from './types'\n\nexport type DocumentColorProfileMode = 'assign' | 'convert'\n\nfunction remapColor(color: SceneNode['fills'][number]['color'], target: DocumentColorSpace) {\n return resolveOkHCLForPreview(rgbaToOkHCL(color), { documentColorSpace: target }).color\n}\n\nfunction remapNodeColors(\n node: SceneNode,\n target: DocumentColorSpace,\n mode: DocumentColorProfileMode\n): Partial<SceneNode> | null {\n if (mode === 'assign') return null\n\n const fills = node.fills.map((fill) => {\n const next = copyFill(fill)\n if (fill.type === 'SOLID') {\n const resolved = remapColor(fill.color, target)\n next.color = resolved\n next.opacity = resolved.a\n return next\n }\n if (fill.gradientStops) {\n next.gradientStops = fill.gradientStops.map((stop) => ({\n ...stop,\n color: remapColor(stop.color, target)\n }))\n }\n return next\n })\n\n const strokes = node.strokes.map((stroke) => {\n const next = copyStroke(stroke)\n const resolved = remapColor(stroke.color, target)\n next.color = resolved\n next.opacity = resolved.a\n return next\n })\n\n const effects = copyEffects(node.effects).map((effect) =>\n effect.type === 'SHADER' ? effect : { ...effect, color: remapColor(effect.color, target) }\n )\n\n const styleRuns = copyStyleRuns(node.styleRuns).map((run) => ({\n ...run,\n style: {\n ...run.style,\n fills: run.style.fills?.map((fill) => {\n const next = copyFill(fill)\n if (fill.type === 'SOLID') {\n const resolved = remapColor(fill.color, target)\n next.color = resolved\n next.opacity = resolved.a\n }\n return next\n })\n }\n }))\n\n return { fills, strokes, effects, styleRuns }\n}\n\nexport function createColorSpaceActions(ctx: EditorContext) {\n function setDocumentColorSpace(\n colorSpace: DocumentColorSpace,\n mode: DocumentColorProfileMode = 'assign'\n ) {\n if (ctx.graph.documentColorSpace === colorSpace) return\n\n if (mode === 'convert') {\n for (const node of ctx.graph.getAllNodes()) {\n const changes = remapNodeColors(node, colorSpace, mode)\n if (changes) ctx.graph.updateNode(node.id, changes)\n }\n }\n\n ctx.graph.documentColorSpace = colorSpace\n ctx.emitEditorEvent('document:color-space-changed', colorSpace)\n ctx.requestRender()\n }\n\n return {\n setDocumentColorSpace\n }\n}\n"],"mappings":";;;AAQA,SAAS,WAAW,OAA4C,QAA4B;CAC1F,OAAO,uBAAuB,YAAY,KAAK,GAAG,EAAE,oBAAoB,OAAO,CAAC,CAAC,CAAC;AACpF;AAEA,SAAS,gBACP,MACA,QACA,MAC2B;CAC3B,IAAI,SAAS,UAAU,OAAO;CA+C9B,OAAO;EAAE,OA7CK,KAAK,MAAM,KAAK,SAAS;GACrC,MAAM,OAAO,SAAS,IAAI;GAC1B,IAAI,KAAK,SAAS,SAAS;IACzB,MAAM,WAAW,WAAW,KAAK,OAAO,MAAM;IAC9C,KAAK,QAAQ;IACb,KAAK,UAAU,SAAS;IACxB,OAAO;GACT;GACA,IAAI,KAAK,eACP,KAAK,gBAAgB,KAAK,cAAc,KAAK,UAAU;IACrD,GAAG;IACH,OAAO,WAAW,KAAK,OAAO,MAAM;GACtC,EAAE;GAEJ,OAAO;EACT,CA8Ba;EAAG,SA5BA,KAAK,QAAQ,KAAK,WAAW;GAC3C,MAAM,OAAO,WAAW,MAAM;GAC9B,MAAM,WAAW,WAAW,OAAO,OAAO,MAAM;GAChD,KAAK,QAAQ;GACb,KAAK,UAAU,SAAS;GACxB,OAAO;EACT,CAsBsB;EAAG,SApBT,YAAY,KAAK,OAAO,CAAC,CAAC,KAAK,WAC7C,OAAO,SAAS,WAAW,SAAS;GAAE,GAAG;GAAQ,OAAO,WAAW,OAAO,OAAO,MAAM;EAAE,CAmB5D;EAAG,WAhBhB,cAAc,KAAK,SAAS,CAAC,CAAC,KAAK,SAAS;GAC5D,GAAG;GACH,OAAO;IACL,GAAG,IAAI;IACP,OAAO,IAAI,MAAM,OAAO,KAAK,SAAS;KACpC,MAAM,OAAO,SAAS,IAAI;KAC1B,IAAI,KAAK,SAAS,SAAS;MACzB,MAAM,WAAW,WAAW,KAAK,OAAO,MAAM;MAC9C,KAAK,QAAQ;MACb,KAAK,UAAU,SAAS;KAC1B;KACA,OAAO;IACT,CAAC;GACH;EACF,EAE0C;CAAE;AAC9C;AAEA,SAAgB,wBAAwB,KAAoB;CAC1D,SAAS,sBACP,YACA,OAAiC,UACjC;EACA,IAAI,IAAI,MAAM,uBAAuB,YAAY;EAEjD,IAAI,SAAS,WACX,KAAK,MAAM,QAAQ,IAAI,MAAM,YAAY,GAAG;GAC1C,MAAM,UAAU,gBAAgB,MAAM,YAAY,IAAI;GACtD,IAAI,SAAS,IAAI,MAAM,WAAW,KAAK,IAAI,OAAO;EACpD;EAGF,IAAI,MAAM,qBAAqB;EAC/B,IAAI,gBAAgB,gCAAgC,UAAU;EAC9D,IAAI,cAAc;CACpB;CAEA,OAAO,EACL,sBACF;AACF"}
1
+ {"version":3,"file":"color-space.js","names":[],"sources":["../../src/editor/color-space.ts"],"sourcesContent":["import type { DocumentColorSpace, Fill, SceneNode } from '@pairdraw/scene-graph'\nimport { okhclToRGBA, rgbaToOkHCL } from '@pairdraw/scene-graph/color'\nimport { copyEffects, copyFill, copyStyleRuns, copyStroke } from '@pairdraw/scene-graph/copy'\n\nimport type { EditorContext } from './types'\n\nexport type DocumentColorProfileMode = 'assign' | 'convert'\n\nfunction remapColor(\n color: SceneNode['fills'][number]['color'],\n source: DocumentColorSpace,\n target: DocumentColorSpace\n) {\n if (source === target) return color\n return okhclToRGBA(rgbaToOkHCL(color, source), target)\n}\n\n/** A paint's colours in the target space: the base colour, a gradient's stops, and mesh points. */\nfunction remapPaint<T extends Fill>(\n next: T,\n fill: T,\n source: DocumentColorSpace,\n target: DocumentColorSpace\n): T {\n const resolved = remapColor(fill.color, source, target)\n next.color = resolved\n if (fill.type === 'SOLID') next.opacity = resolved.a\n if (fill.gradientStops)\n next.gradientStops = fill.gradientStops.map((stop) => ({\n ...stop,\n color: remapColor(stop.color, source, target)\n }))\n if (fill.meshPoints)\n next.meshPoints = fill.meshPoints.map((point) => ({\n ...point,\n color: remapColor(point.color, source, target)\n }))\n return next\n}\n\nfunction remapFill(fill: Fill, source: DocumentColorSpace, target: DocumentColorSpace): Fill {\n return remapPaint(copyFill(fill), fill, source, target)\n}\n\nfunction remapNodeColors(\n node: SceneNode,\n source: DocumentColorSpace,\n target: DocumentColorSpace,\n mode: DocumentColorProfileMode\n): Partial<SceneNode> | null {\n if (mode === 'assign') return null\n\n const fills = node.fills.map((fill) => remapFill(fill, source, target))\n\n const strokes = node.strokes.map((stroke) =>\n remapPaint(copyStroke(stroke), stroke, source, target)\n )\n\n const effects = copyEffects(node.effects).map((effect) =>\n effect.type === 'SHADER'\n ? effect\n : { ...effect, color: remapColor(effect.color, source, target) }\n )\n\n const styleRuns = copyStyleRuns(node.styleRuns).map((run) => ({\n ...run,\n style: {\n ...run.style,\n fills: run.style.fills?.map((fill) => remapFill(fill, source, target))\n }\n }))\n\n return { fills, strokes, effects, styleRuns }\n}\n\nexport function createColorSpaceActions(ctx: EditorContext) {\n function setDocumentColorSpace(\n colorSpace: DocumentColorSpace,\n mode: DocumentColorProfileMode = 'assign'\n ) {\n if (ctx.graph.documentColorSpace === colorSpace) return\n\n if (mode === 'convert') {\n const source = ctx.graph.documentColorSpace\n for (const node of ctx.graph.getAllNodes()) {\n const changes = remapNodeColors(node, source, colorSpace, mode)\n if (changes) ctx.graph.updateNode(node.id, changes)\n }\n }\n\n ctx.graph.documentColorSpace = colorSpace\n ctx.emitEditorEvent('document:color-space-changed', colorSpace)\n ctx.requestRender()\n }\n\n return {\n setDocumentColorSpace\n }\n}\n"],"mappings":";;;AAQA,SAAS,WACP,OACA,QACA,QACA;CACA,IAAI,WAAW,QAAQ,OAAO;CAC9B,OAAO,YAAY,YAAY,OAAO,MAAM,GAAG,MAAM;AACvD;;AAGA,SAAS,WACP,MACA,MACA,QACA,QACG;CACH,MAAM,WAAW,WAAW,KAAK,OAAO,QA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,MAAM,YAAY,GAAG;IAC1C,MAAM,UAAU,gBAAgB,MAAM,QAAQ,YAAY,IAAI;IAC9D,IAAI,SAAS,IAAI,MAAM,WAAW,KAAK,IAAI,OAAO;GACpD;EACF;EAEA,IAAI,MAAM,qBAAqB;EAC/B,IAAI,gBAAgB,gCAAgC,UAAU;EAC9D,IAAI,cAAc;CACpB;CAEA,OAAO,EACL,sBACF;AACF"}
@@ -56,7 +56,7 @@ import { RenameSelectionOptions, RenameSelectionPreview } from "./structure/rena
56
56
  import "./index.js";
57
57
  import { CanvasKit } from "canvaskit-wasm";
58
58
  import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
59
- import { UndoManager } from "@pairdraw/scene-graph/undo";
59
+ import { UndoEntry, UndoManager } from "@pairdraw/scene-graph/undo";
60
60
  //#region src/editor/create.d.ts
61
61
  declare function createEditor(options?: EditorOptions): {
62
62
  setReadOnly: (readOnly: boolean, options?: {
@@ -195,8 +195,8 @@ declare function createEditor(options?: EditorOptions): {
195
195
  recordEdit: <T>(options: RecordEditOptions, run: () => T) => T;
196
196
  recordEditAsync: <T>(options: RecordEditOptions, run: () => Promise<T>) => Promise<T>;
197
197
  restoreDocumentChange: (change: DocumentChange, side: "before" | "after") => void;
198
- pushUndoEntry: (entry: import("@pairdraw/scene-graph/undo").UndoEntry) => void;
199
- pushUndoStep: (entry: import("@pairdraw/scene-graph/undo").UndoEntry) => void;
198
+ pushUndoEntry: (entry: UndoEntry) => void;
199
+ pushUndoStep: (entry: UndoEntry) => void;
200
200
  zoomToNextFrame: () => void;
201
201
  zoomToPreviousFrame: () => void;
202
202
  viewportCanvasCenter: () => import("@pairdraw/scene-graph/primitives").Vector;
@@ -518,7 +518,7 @@ declare function createEditor(options?: EditorOptions): {
518
518
  layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
519
519
  vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
520
520
  handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
521
- booleanOperation: "UNION" | "SUBTRACT" | "INTERSECT" | "EXCLUDE" | undefined;
521
+ booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
522
522
  fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
523
523
  strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
524
524
  arcData: import("@pairdraw/scene-graph").ArcData | null;
@@ -690,7 +690,7 @@ declare function createEditor(options?: EditorOptions): {
690
690
  layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
691
691
  vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
692
692
  handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
693
- booleanOperation: "UNION" | "SUBTRACT" | "INTERSECT" | "EXCLUDE" | undefined;
693
+ booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
694
694
  fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
695
695
  strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
696
696
  arcData: import("@pairdraw/scene-graph").ArcData | null;
@@ -781,7 +781,9 @@ declare function createEditor(options?: EditorOptions): {
781
781
  }[];
782
782
  validateEnteredContainer: () => void;
783
783
  enterContainer: (id: string) => void;
784
+ enterContainerOf: (nodeId: string) => void;
784
785
  exitContainer: () => void;
786
+ exitContainers: () => void;
785
787
  setConnectorTarget: (target: ConnectorTarget | null) => void;
786
788
  setMarquee: (rect: import("@pairdraw/scene-graph/primitives").Rect | null) => void;
787
789
  setSnapGuides: (guides: import("@pairdraw/scene-graph/snap").SnapGuide[]) => void;
@@ -845,8 +847,10 @@ declare function createEditor(options?: EditorOptions): {
845
847
  canvasRenderers: SkiaRenderer[];
846
848
  textEditor: TextEditor | null;
847
849
  undo: UndoManager;
850
+ parkStep: (graph: SceneGraph, entry: UndoEntry) => void;
848
851
  state: EditorState;
849
852
  runLayoutForNode: (id: string) => void;
853
+ runLayoutForParents: (parentIds: Iterable<string>) => void;
850
854
  runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string, beforeLayout?: (result: T, impact: import("@pairdraw/scene-graph/mutation-impact").SceneMutationImpact) => Promise<void> | void) => Promise<T>;
851
855
  };
852
856
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","names":[],"sources":["../../src/editor/create.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0FgB,aAAa,UAAU;;IA9CqB;;sCA8CrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAofZ,mBAAA,YAAM,UAAY,QAAQ,YAAU;;;iGAAlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IArdY,SAAC;IAExC,cAAC,UAFuC;;;;;;;;;;;;;;;;;IA3FnC;IAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8fjB,aAAA,YAAM,SAAW,QAAQ;EAEjB,qBAAA,YAAM,SAAW,QAAQ,YAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAhZvC,gBAAA,UAAU,iBAAe,OAAS,GAAC,SAAW,aAAa,4BAAE;EA2P1D,eAAA,IAAA,WAAS,UAAY;EApMZ,qBAAA,OAAA,oCAAkC;EAuN7B,uBAAA,UAAA;EAiBR,eAAA,UAAA;;;;;;;;;;;;;;;EALP,WAAA,OAAA,YAAU,OAAS;;;;;;;;;;;UAmN7B,eAAe,kBAAkB"}
@@ -208,7 +208,7 @@ function createEditor(options) {
208
208
  emitEditorEvent("tool:changed", tool, previous);
209
209
  }
210
210
  const graphReads = createGraphReadActions(() => _graph);
211
- const { runLayoutForNode, runMutationWithLayout } = createLayoutRunner(() => _graph);
211
+ const { runLayoutForNode, runLayoutForParents, runMutationWithLayout } = createLayoutRunner(() => _graph);
212
212
  const pendingTextLayout = createPendingTextLayout({
213
213
  getGraph: () => _graph,
214
214
  runLayoutForNode,
@@ -238,6 +238,7 @@ function createEditor(options) {
238
238
  _graph = g;
239
239
  },
240
240
  undo,
241
+ parkStep,
241
242
  state,
242
243
  loadFont: _loadFont,
243
244
  resolveFigmaClipboardImages: options?.resolveFigmaClipboardImages ?? null,
@@ -259,6 +260,7 @@ function createEditor(options) {
259
260
  setActiveTool,
260
261
  setNavigationPhase,
261
262
  runLayoutForNode,
263
+ runLayoutForParents,
262
264
  runMutationWithLayout,
263
265
  subscribeToGraph
264
266
  };
@@ -348,6 +350,11 @@ function createEditor(options) {
348
350
  }
349
351
  /** Each graph's committed history, kept aside while another graph is open in this editor. */
350
352
  const histories = /* @__PURE__ */ new WeakMap();
353
+ /** A step recorded while its document was swapped away joins that document's own history. */
354
+ function parkStep(graph, entry) {
355
+ const history = histories.get(graph);
356
+ if (history) histories.set(graph, undo.pushIntoParked(history, entry));
357
+ }
351
358
  function replaceGraph(newGraph) {
352
359
  nodes.cancelNodePreviews();
353
360
  if (newGraph !== _graph) {
@@ -410,8 +417,10 @@ function createEditor(options) {
410
417
  return _textEditor;
411
418
  },
412
419
  undo: guardUndo(undo, readsOnly),
420
+ parkStep,
413
421
  state,
414
422
  runLayoutForNode,
423
+ runLayoutForParents,
415
424
  runMutationWithLayout,
416
425
  ...graphReads,
417
426
  beginInteractiveEdit,
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","names":[],"sources":["../../src/editor/create.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\nimport { createNanoEvents } from 'nanoevents'\nimport type { Emitter } from 'nanoevents'\n\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { UndoManager, type UndoHistory } from '@pairdraw/scene-graph/undo'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport { prefetchFigmaSchema } from '#core/clipboard'\nimport { IS_BROWSER } from '#core/constants'\nimport {\n getPageColor,\n hasStoredBackground,\n setDefaultPageBackground\n} from '#core/figma-api/page-backgrounds'\nimport { defaultIcons } from '#core/icons'\nimport { releaseFigPopulationWorker } from '#core/kiwi/fig/population/client'\nimport { releaseOriginalFigArchive } from '#core/kiwi/fig/session/original-archive'\nimport { installTextMeasurer } from '#core/layout'\nimport { createLayoutRunner } from '#core/layout/mutations'\nimport { emitNavigationTrace } from '#core/profiler'\nimport { TextEditor } from '#core/text/editor'\nimport { fontManager } from '#core/text/font/manager'\nimport { fontResolver } from '#core/text/resolver'\n\nimport { createAlignmentActions } from './alignment'\nimport { createClipboardBridge } from './bridges/clipboard'\nimport { createComponentBridge } from './bridges/components'\nimport { createFrameNavigationBridge } from './bridges/frames'\nimport { createLintFixBridge } from './bridges/lint'\nimport { createStructureBridge } from './bridges/structure'\nimport { createUndoBridge } from './bridges/undo'\nimport { createClipboardActions } from './clipboard'\nimport { createClipboardPropertiesActions } from './clipboard/paste/properties'\nimport { createColorSpaceActions } from './color-space'\nimport { createComponentSyncScheduler } from './component-sync'\nimport { createComponentActions } from './components'\nimport { createConnectorDrawActions, createConnectorEndpointActions } from './connectors/draw'\nimport { createConnectorLineActions } from './connectors/line'\nimport { createConnectorRouting } from './connectors/routing'\nimport { createConnectorStyleActions } from './connectors/style'\nimport { createDesignTokenActions } from './design-tokens'\nimport { createDocumentSettingsActions } from './document-settings'\nimport { createFigCompressionActions } from './fig-compression'\nimport { createGraphEventSubscription } from './graph-events'\nimport { createGraphReadActions } from './graph-reads'\nimport { createGuideActions } from './guides'\nimport { createIconActions } from './icons'\nimport { createImageEditActions } from './image-edit'\nimport { createDesignIssueActions } from './issues'\nimport { createLineEndActions } from './line-ends'\nimport { createNodeActions } from './nodes'\nimport { createPageActions } from './pages'\nimport { createReadOnlyActions, guardReadOnly, guardUndo } from './read-only'\nimport { createScaleActions } from './scale'\nimport { createSelectionActions } from './selection'\nimport { createShaderActions } from './shaders/actions'\nimport { createShaderFrames } from './shaders/frames'\nimport { createShapeActions } from './shapes'\nimport { createShapeWithTextActions } from './shapes/with-text'\nimport { createDefaultEditorState } from './state'\nimport { createStatusActions } from './statuses'\nimport { createStickyActions } from './stickies'\nimport { createStructureActions } from './structure'\nimport { createTextActions } from './text'\nimport { createTextHyperlinkActions } from './text/hyperlink'\nimport { createPendingTextLayout } from './text/pending-layout'\nimport { createTextSelectionStyle } from './text/selection-style'\nimport { createGeneratedTextActions } from './text/typeface'\nimport type {\n EditorContext,\n EditorEventName,\n EditorEvents,\n EditorOptions,\n EditorState,\n ViewportInsets\n} from './types'\nimport { createUndoActions } from './undo'\nimport { createVariableActions } from './variables'\nimport { createVectorizeActions } from './vectorize'\nimport { createViewportActions, NO_VIEWPORT_INSETS } from './viewport'\nimport { createCanvasViewActions, offeredTool, resolveEditorProfile } from './views'\n\nexport { createDefaultEditorState } from './state'\n\n/** A canvas with no chrome reports nothing, which is the same as none covering it. */\nfunction resolveViewportInsets(options?: EditorOptions): () => ViewportInsets {\n return options?.getViewportInsets ?? (() => NO_VIEWPORT_INSETS)\n}\n\nexport function createEditor(options?: EditorOptions) {\n let _graph = options?.graph ?? new SceneGraph()\n const skipInitialGraphSetup = options?.skipInitialGraphSetup ?? false\n const undo = new UndoManager({\n onChange: () => emitEditorEvent('history:changed'),\n // A step owns the edited-field marks its edit added, so undo takes them back and redo\n // marks them again. The marks are the graph's, and the document can be replaced.\n marks: {\n take: () => _graph.takeSourceMarks(),\n add: (id, fields) => _graph.addSourceMarks(id, fields),\n remove: (id, fields) => _graph.removeSourceMarks(id, fields),\n preserve: (run) => _graph.preserveSourceMetadataDuring(run)\n }\n })\n const _loadFont = options?.loadFont ?? fontManager.loadFont.bind(fontManager)\n const _getViewportSize =\n options?.getViewportSize ??\n (() => {\n if (IS_BROWSER) return { width: window.innerWidth, height: window.innerHeight }\n return { width: 800, height: 600 }\n })\n const _getViewportInsets = resolveViewportInsets(options)\n let _ck: CanvasKit | null = null\n let _renderer: SkiaRenderer | null = null\n const _renderers = new Set<SkiaRenderer>()\n let uninstallTextMeasurer: (() => void) | null = null\n const interactiveEdits = new Set<symbol>()\n let _textEditor: TextEditor | null = null\n const events: Emitter<EditorEvents> = createNanoEvents()\n const stopFontResolutionEvents = fontResolver.subscribe((event, snapshot) => {\n if (event === 'settled') pendingTextLayout.relayoutReady(_renderer)\n events.emit('font:resolution-changed', event, snapshot)\n })\n const stopFontLoadEvents = fontManager.onFaceLoaded((family, style) => {\n // Text measured in a substitute takes its own face's size once a face of its family loads.\n pendingTextLayout.relayoutSubstituted(_renderer, family)\n events.emit('font:loaded', family, style)\n })\n // Text blocked while its fonts were prepared is missing from the tiles drawn meanwhile.\n const stopUnblockEvents = fontManager.onNodesUnblocked((nodeIds) => {\n let redrawn = false\n for (const renderer of _renderers) {\n for (const id of nodeIds) {\n if (!_graph.getNode(id)) continue\n renderer.invalidateNodePicture(id)\n redrawn = true\n }\n }\n if (redrawn) requestRender()\n })\n\n void prefetchFigmaSchema()\n\n const state: EditorState = options?.state ?? createDefaultEditorState(_graph.getPages()[0].id)\n state.documentKind = _graph.documentKind\n state.activeTool = offeredTool(state, state.activeTool)\n\n function emitEditorEvent<K extends EditorEventName>(\n event: K,\n ...args: Parameters<EditorEvents[K]>\n ) {\n events.emit(event, ...args)\n }\n\n function onEditorEvent<K extends EditorEventName>(event: K, handler: EditorEvents[K]) {\n return events.on(event, handler)\n }\n\n function requestRender() {\n state.renderVersion++\n state.sceneVersion++\n state.canvasVersion++\n emitNavigationTrace('render:requested', {\n kind: 'render',\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n emitEditorEvent('render:requested', {\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n }\n\n /**\n * The caret or selection of the edited text moved: the canvas repaints its overlay and the\n * views that follow the selection update, without the document counting as changed.\n */\n function textSelectionChanged() {\n state.textSelectionVersion++\n requestRepaint()\n }\n\n function requestRefresh() {\n state.sceneVersion++\n }\n\n function requestRepaint() {\n state.renderVersion++\n emitNavigationTrace('render:requested', {\n kind: 'repaint',\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n emitEditorEvent('repaint:requested', {\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n }\n\n /** Track an actual live edit independently of history batching. Release is idempotent. */\n function beginInteractiveEdit() {\n const token = Symbol('interactive-edit')\n interactiveEdits.add(token)\n requestRepaint()\n return () => {\n if (interactiveEdits.delete(token)) requestRepaint()\n }\n }\n\n function setNavigationPhase(phase: EditorState['navigation']['phase'], inputAt = 0) {\n const previous = { ...state.navigation }\n const active = phase === 'pan' || phase === 'zoom' || phase === 'momentum'\n const wasActive =\n previous.phase === 'pan' || previous.phase === 'zoom' || previous.phase === 'momentum'\n state.navigation = {\n phase,\n generation: active && !wasActive ? previous.generation + 1 : previous.generation,\n lastInputAt: inputAt || previous.lastInputAt\n }\n if (\n state.navigation.phase !== previous.phase ||\n state.navigation.generation !== previous.generation ||\n state.navigation.lastInputAt !== previous.lastInputAt\n ) {\n emitNavigationTrace('navigation:phase', {\n phase: state.navigation.phase,\n previousPhase: previous.phase,\n generation: state.navigation.generation,\n lastInputAt: state.navigation.lastInputAt\n })\n emitEditorEvent('navigation:changed', state.navigation, previous)\n }\n }\n\n function setSelectedIds(ids: Set<string>) {\n const previous = [...state.selectedIds]\n state.selectedIds = ids\n if (ids.size === 0) state.measurementMode = 'off'\n const selected = [...ids]\n if (\n previous.length !== selected.length ||\n previous.some((id, index) => id !== selected[index])\n ) {\n emitEditorEvent('selection:changed', selected, previous)\n }\n }\n\n function setActiveTool(tool: EditorState['activeTool']) {\n if (offeredTool(state, tool) !== tool) return\n const previous = state.activeTool\n state.activeTool = tool\n if (tool !== 'SELECT') state.measurementMode = 'off'\n if (previous === tool) return\n // Guides the pen showed for its next point do not belong to the next tool.\n if (previous === 'PEN') state.snapGuides = []\n emitEditorEvent('tool:changed', tool, previous)\n }\n\n const graphReads = createGraphReadActions(() => _graph)\n const { runLayoutForNode, runMutationWithLayout } = createLayoutRunner(() => _graph)\n const pendingTextLayout = createPendingTextLayout({\n getGraph: () => _graph,\n runLayoutForNode,\n requestRender\n })\n const { scheduleComponentSync, flushComponentSync, isSyncingComponents } =\n createComponentSyncScheduler(() => _graph, requestRender)\n\n const { subscribeToGraph, unsubscribeFromGraph } = createGraphEventSubscription({\n getGraph: () => _graph,\n getRenderers: () => _renderers,\n scheduleComponentSync,\n requestRender,\n emitEditorEvent\n })\n\n if (!skipInitialGraphSetup) {\n subscribeToGraph()\n // A new document's first page takes Figma's background for the interface theme the app gives;\n // a page that already has one keeps it.\n const firstPage = _graph.getPages()[0]\n if (options?.state?.theme && !hasStoredBackground(firstPage)) {\n setDefaultPageBackground(_graph, firstPage, options.state.theme)\n options.state.pageColor = getPageColor(firstPage)\n }\n }\n\n // Build the shared context\n const ctx: EditorContext = {\n get graph() {\n return _graph\n },\n set graph(g) {\n _graph = g\n },\n undo,\n state,\n loadFont: _loadFont,\n resolveFigmaClipboardImages: options?.resolveFigmaClipboardImages ?? null,\n getViewportSize: _getViewportSize,\n getViewportInsets: _getViewportInsets,\n getUserName: () => options?.getUserName?.() ?? '',\n icons: options?.icons ?? defaultIcons,\n getCk: () => _ck,\n getRenderer: () => _renderer,\n getRenderers: () => _renderers,\n getTextEditor: () => _textEditor,\n requestRender,\n requestRefresh,\n requestRepaint,\n beginInteractiveEdit,\n onEditorEvent,\n emitEditorEvent,\n setSelectedIds,\n setActiveTool,\n setNavigationPhase,\n runLayoutForNode,\n runMutationWithLayout,\n subscribeToGraph\n }\n\n // Assemble domain modules\n const viewport = createViewportActions(ctx)\n const selection = createSelectionActions(ctx)\n const shaderFrames = createShaderFrames(ctx, options)\n const pages = createPageActions(ctx, shaderFrames)\n const guides = createGuideActions(ctx)\n const designIssues = createDesignIssueActions(ctx)\n const structure = createStructureActions(ctx)\n const components = createComponentActions(ctx)\n const clipboard = createClipboardActions(ctx)\n const colorSpace = createColorSpaceActions(ctx)\n const documentSettings = createDocumentSettingsActions(ctx)\n const undoActions = createUndoActions(ctx)\n const text = createTextActions(ctx)\n const nodes = createNodeActions(ctx)\n const shapes = createShapeActions(ctx, nodes.updateNodeWithUndo)\n const clipboardProperties = createClipboardPropertiesActions(\n ctx,\n nodes.updateNodeWithUndo,\n clipboard.loadFontsForNodes\n )\n const variables = createVariableActions(ctx)\n const designTokens = createDesignTokenActions(ctx, variables, nodes)\n const vectorize = createVectorizeActions(ctx)\n const icons = createIconActions(ctx)\n const stickies = createStickyActions(ctx, nodes)\n const scale = createScaleActions(ctx, nodes.beginNodePreview)\n const shapesWithText = createShapeWithTextActions(ctx, nodes)\n const generatedText = createGeneratedTextActions(ctx, nodes)\n const statuses = createStatusActions(ctx)\n const figCompression = createFigCompressionActions(ctx)\n createConnectorRouting(ctx)\n const connectorDrawing = createConnectorDrawActions(ctx)\n const connectorEndpoints = createConnectorEndpointActions(\n ctx,\n nodes.beginNodePreview,\n clipboard.deleteNodes\n )\n const connectorLines = createConnectorLineActions(ctx, nodes.beginNodePreview)\n const connectorStyles = createConnectorStyleActions(ctx, nodes)\n const lineEnds = createLineEndActions(ctx, nodes.beginNodePreview)\n const imageEdit = createImageEditActions(ctx, nodes.updateNodeWithUndo)\n const shaders = createShaderActions(ctx, nodes)\n const alignment = createAlignmentActions(ctx)\n const canvasViews = createCanvasViewActions(ctx, viewport)\n const clipboardBridge = createClipboardBridge(clipboard, selection)\n const componentBridge = createComponentBridge(components, selection, structure, pages)\n const structureBridge = createStructureBridge(structure, selection)\n const frameNavigation = createFrameNavigationBridge(ctx, selection, viewport)\n const undoBridge = createUndoBridge(undoActions, selection, nodes.flushNudge)\n const lintFixBridge = createLintFixBridge(ctx, nodes, structure, clipboard)\n const textSelectionStyle = createTextSelectionStyle(ctx, text.runTextEditStep)\n const textHyperlinks = createTextHyperlinkActions(ctx, {\n updateNodeWithUndo: nodes.updateNodeWithUndo,\n runTextEditStep: text.runTextEditStep,\n switchPage: (pageId) => pages.switchPage(pageId),\n revealNodes: viewport.revealNodes\n })\n /** Whether the editor refuses edits: its profile offers none, as for a read-only document. */\n const readsOnly = () => !resolveEditorProfile(state).edits\n const readOnly = createReadOnlyActions(ctx, () => {\n nodes.flushNudge()\n nodes.cancelNodePreviews()\n if (state.editingTextId) text.commitTextEdit()\n shapes.penCancel()\n shapes.pencilCancel()\n state.gradientEdit = null\n state.imageEdit = null\n })\n\n // The edited text follows changes made outside the editor, such as a panel field being\n // dragged, so its caret and selection move with the text instead of after the change.\n const invalidateEditedText = (id: string) => {\n if (id !== state.editingTextId) return\n const node = _graph.getNode(id)\n if (node) _textEditor?.invalidateParagraph(node)\n }\n onEditorEvent('node:updated', invalidateEditedText)\n onEditorEvent('node:previewUpdated', invalidateEditedText)\n\n function setCanvasKit(ck: CanvasKit, renderer: SkiaRenderer) {\n _ck = ck\n _renderer = renderer\n _renderers.add(renderer)\n _textEditor ??= new TextEditor(ck)\n uninstallTextMeasurer?.()\n uninstallTextMeasurer =\n typeof renderer.measureTextNode === 'function'\n ? installTextMeasurer((node, maxWidth) =>\n pendingTextLayout.measure(renderer, node, maxWidth)\n )\n : null\n }\n\n function releaseTextMeasurer() {\n uninstallTextMeasurer?.()\n uninstallTextMeasurer = null\n }\n\n function removeCanvasRenderer(renderer: SkiaRenderer) {\n _renderers.delete(renderer)\n if (_renderer === renderer) {\n _renderer = _renderers.values().next().value ?? null\n }\n if (_renderers.size === 0) releaseTextMeasurer()\n }\n\n /** Each graph's committed history, kept aside while another graph is open in this editor. */\n const histories = new WeakMap<SceneGraph, UndoHistory>()\n\n function replaceGraph(newGraph: SceneGraph) {\n nodes.cancelNodePreviews()\n if (newGraph !== _graph) {\n // Undo steps name layers by id and act on whichever graph is open, so history stays with\n // the graph it was recorded on: a document opened in this editor starts with its own,\n // instead of undoing the last document's layers that share an id.\n histories.set(_graph, undo.takeHistory())\n undo.adoptHistory(histories.get(newGraph))\n // Menus show the new graph's history; a step still being recorded keeps its own notice,\n // which is how it learns another write happened beside it.\n if (!undo.isRecording) emitEditorEvent('history:changed')\n }\n _graph = newGraph\n state.documentKind = _graph.documentKind\n setActiveTool(offeredTool(state, state.activeTool))\n pendingTextLayout.clear()\n subscribeToGraph()\n const previousPageId = state.currentPageId\n state.currentPageId = _graph.getPages()[0]?.id ?? _graph.rootId\n setSelectedIds(new Set())\n state.hoveredNodeId = null\n state.transforming = false\n state.measurementMode = 'off'\n state.snapGuides = []\n state.guides = { preview: null, hovered: null, selected: null, redline: null }\n state.layoutInsertIndicator = null\n state.dropTargetId = null\n pages.clearPageViewports()\n for (const renderer of _renderers) renderer.tiledScene.invalidateStructure()\n emitEditorEvent('graph:replaced', _graph)\n if (previousPageId !== state.currentPageId) {\n emitEditorEvent('page:changed', state.currentPageId, previousPageId)\n }\n requestRender()\n }\n\n function dispose() {\n releaseTextMeasurer()\n nodes.cancelNodePreviews()\n interactiveEdits.clear()\n stopFontResolutionEvents()\n stopFontLoadEvents()\n stopUnblockEvents()\n unsubscribeFromGraph()\n }\n\n function releaseGraphResources() {\n releaseFigPopulationWorker(_graph)\n releaseOriginalFigArchive(_graph)\n }\n\n const editor = {\n get graph() {\n return _graph\n },\n /** Instances are being brought in line with their components: results, not edits. */\n isSyncingComponents,\n get renderer() {\n return _renderer\n },\n get canvasRenderers() {\n return [..._renderers]\n },\n get textEditor() {\n return _textEditor\n },\n undo: guardUndo(undo, readsOnly),\n state,\n\n // Graph reads\n runLayoutForNode,\n runMutationWithLayout,\n ...graphReads,\n\n // Lifecycle\n beginInteractiveEdit,\n isInteractiveEditing: () => interactiveEdits.size > 0,\n flushComponentSync,\n requestRender,\n requestRefresh,\n textSelectionChanged,\n requestRepaint,\n onEditorEvent,\n setCanvasKit,\n setNavigationPhase,\n removeCanvasRenderer,\n replaceGraph,\n subscribeToGraph,\n dispose,\n releaseGraphResources,\n\n // Selection\n ...selection,\n\n // Pages\n ...pages,\n\n // Canvas and frame guides\n ...guides,\n ...designIssues,\n\n // Shapes & tools\n ...shapes,\n\n // Structure (group, reorder, reparent, z-order)\n ...structure,\n\n // Nodes (update, layout); while text is edited, character styles go to its selection\n ...nodes,\n updateNode: (id: string, changes: Partial<SceneNode>) =>\n textSelectionStyle.updateNode(id, changes, nodes.updateNode),\n updateNodeWithUndo: (id: string, changes: Partial<SceneNode>, label = 'Update') =>\n textSelectionStyle.updateNodeWithUndo(id, changes, (target, next) =>\n nodes.updateNodeWithUndo(target, next, label)\n ),\n getTextSelectionStyle: textSelectionStyle.selectionStyle,\n layerChanges: textSelectionStyle.layerChanges,\n\n // Alignment (align, flip, rotate)\n ...alignment,\n\n // Canvas views: editing, or a preview where instances with a behaviour respond to the pointer\n ...canvasViews,\n\n // Bitmap-to-vector replacement\n ...vectorize,\n ...icons,\n ...stickies,\n // The Scale tool: layers scale with their text, strokes, effects, radii, and spacing\n ...scale,\n ...shapesWithText,\n ...generatedText,\n statusWorkflow: statuses.statusWorkflow,\n getShownStatus: statuses.getShownStatus,\n setStatus: statuses.setStatus,\n setStatusWorkflow: statuses.setStatusWorkflow,\n ...connectorDrawing,\n ...connectorEndpoints,\n ...connectorLines,\n ...lineEnds,\n ...imageEdit,\n ...connectorStyles,\n ...shaders,\n ...shaderFrames,\n\n // Variables\n ...variables,\n ...designTokens,\n\n // Text editing\n ...text,\n ...textHyperlinks,\n\n // Viewport\n ...viewport,\n ...frameNavigation,\n\n // Undo — bridge functions that need cross-module refs\n ...undoBridge,\n commitNodeUpdate: (id: string, previous: Partial<SceneNode>, label = 'Update') =>\n textSelectionStyle.commitNodeUpdate(\n id,\n previous,\n (target, values) => undoBridge.commitNodeUpdate(target, values, label),\n (target, next) => nodes.updateNodeWithUndo(target, next, label)\n ),\n // While text is edited, what was typed undoes first and the editor keeps the result.\n undoAction: () => text.runTextEditStep(undoBridge.undoAction),\n redoAction: () => text.runTextEditStep(undoBridge.redoAction),\n\n setDocumentColorSpace: colorSpace.setDocumentColorSpace,\n updateEnabledLibraries: documentSettings.updateEnabledLibraries,\n refreshDocumentSettings: documentSettings.refreshDocumentSettings,\n setDocumentKind: documentSettings.setDocumentKind,\n figCompression: figCompression.figCompression,\n setFigCompression: figCompression.setFigCompression,\n\n // Clipboard — bridge functions that need selectedNodes\n ...clipboardBridge,\n\n // Paste properties: the look of a copied layer, onto the selection\n ...clipboardProperties,\n\n // Components — bridge functions\n ...componentBridge,\n\n // Structure — bridge functions that need selectedNodes\n ...structureBridge,\n\n // Lint fixes, which touch nodes, structure and deletion in one undo step\n ...lintFixBridge,\n\n // Read-only documents, which refuse every action above that changes them\n ...readOnly\n }\n return guardReadOnly(editor, readsOnly)\n}\n\n/**\n * The editor `createEditor` returns. An interface rather than an alias, so declarations that\n * mention it, such as a Vue composable's inferred return type, name it instead of spelling out\n * its members, some of whose types are internal to Core.\n */\n// eslint-disable-next-line typescript/no-empty-object-type -- The interface is the point: an alias's members are spelled out in emitted declarations.\nexport interface Editor extends ReturnType<typeof createEditor> {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,SAAS,sBAAsB,SAA+C;CAC5E,OAAO,SAAS,4BAA4B;AAC9C;AAEA,SAAgB,aAAa,SAAyB;CACpD,IAAI,SAAS,SAAS,SAAS,IAAI,WAAW;CAC9C,MAAM,wBAAwB,SAAS,yBAAyB;CAChE,MAAM,OAAO,IAAI,YAAY;EAC3B,gBAAgB,gBAAgB,iBAAiB;EAGjD,OAAO;GACL,YAAY,OAAO,gBAAgB;GACnC,MAAM,IAAI,WAAW,OAAO,eAAe,IAAI,MAAM;GACrD,SAAS,IAAI,WAAW,OAAO,kBAAkB,IAAI,MAAM;GAC3D,WAAW,QAAQ,OAAO,6BAA6B,GAAG;EAC5D;CACF,CAAC;CACD,MAAM,YAAY,SAAS,YAAY,YAAY,SAAS,KAAK,WAAW;CAC5E,MAAM,mBACJ,SAAS,0BACF;EACL,IAAI,YAAY,OAAO;GAAE,OAAO,OAAO;GAAY,QAAQ,OAAO;EAAY;EAC9E,OAAO;GAAE,OAAO;GAAK,QAAQ;EAAI;CACnC;CACF,MAAM,qBAAqB,sBAAsB,OAAO;CACxD,IAAI,MAAwB;CAC5B,IAAI,YAAiC;CACrC,MAAM,6BAAa,IAAI,IAAkB;CACzC,IAAI,wBAA6C;CACjD,MAAM,mCAAmB,IAAI,IAAY;CACzC,IAAI,cAAiC;CACrC,MAAM,SAAgC,iBAAiB;CACvD,MAAM,2BAA2B,aAAa,WAAW,OAAO,aAAa;EAC3E,IAAI,UAAU,WAAW,kBAAkB,cAAc,SAAS;EAClE,OAAO,KAAK,2BAA2B,OAAO,QAAQ;CACxD,CAAC;CACD,MAAM,qBAAqB,YAAY,cAAc,QAAQ,UAAU;EAErE,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L;CACA,OAAO,cAAc,QAAQ,SAAS;AACxC"}
1
+ {"version":3,"file":"create.js","names":[],"sources":["../../src/editor/create.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\nimport { createNanoEvents } from 'nanoevents'\nimport type { Emitter } from 'nanoevents'\n\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { UndoManager, type UndoEntry, type UndoHistory } from '@pairdraw/scene-graph/undo'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport { prefetchFigmaSchema } from '#core/clipboard'\nimport { IS_BROWSER } from '#core/constants'\nimport {\n getPageColor,\n hasStoredBackground,\n setDefaultPageBackground\n} from '#core/figma-api/page-backgrounds'\nimport { defaultIcons } from '#core/icons'\nimport { releaseFigPopulationWorker } from '#core/kiwi/fig/population/client'\nimport { releaseOriginalFigArchive } from '#core/kiwi/fig/session/original-archive'\nimport { installTextMeasurer } from '#core/layout'\nimport { createLayoutRunner } from '#core/layout/mutations'\nimport { emitNavigationTrace } from '#core/profiler'\nimport { TextEditor } from '#core/text/editor'\nimport { fontManager } from '#core/text/font/manager'\nimport { fontResolver } from '#core/text/resolver'\n\nimport { createAlignmentActions } from './alignment'\nimport { createClipboardBridge } from './bridges/clipboard'\nimport { createComponentBridge } from './bridges/components'\nimport { createFrameNavigationBridge } from './bridges/frames'\nimport { createLintFixBridge } from './bridges/lint'\nimport { createStructureBridge } from './bridges/structure'\nimport { createUndoBridge } from './bridges/undo'\nimport { createClipboardActions } from './clipboard'\nimport { createClipboardPropertiesActions } from './clipboard/paste/properties'\nimport { createColorSpaceActions } from './color-space'\nimport { createComponentSyncScheduler } from './component-sync'\nimport { createComponentActions } from './components'\nimport { createConnectorDrawActions, createConnectorEndpointActions } from './connectors/draw'\nimport { createConnectorLineActions } from './connectors/line'\nimport { createConnectorRouting } from './connectors/routing'\nimport { createConnectorStyleActions } from './connectors/style'\nimport { createDesignTokenActions } from './design-tokens'\nimport { createDocumentSettingsActions } from './document-settings'\nimport { createFigCompressionActions } from './fig-compression'\nimport { createGraphEventSubscription } from './graph-events'\nimport { createGraphReadActions } from './graph-reads'\nimport { createGuideActions } from './guides'\nimport { createIconActions } from './icons'\nimport { createImageEditActions } from './image-edit'\nimport { createDesignIssueActions } from './issues'\nimport { createLineEndActions } from './line-ends'\nimport { createNodeActions } from './nodes'\nimport { createPageActions } from './pages'\nimport { createReadOnlyActions, guardReadOnly, guardUndo } from './read-only'\nimport { createScaleActions } from './scale'\nimport { createSelectionActions } from './selection'\nimport { createShaderActions } from './shaders/actions'\nimport { createShaderFrames } from './shaders/frames'\nimport { createShapeActions } from './shapes'\nimport { createShapeWithTextActions } from './shapes/with-text'\nimport { createDefaultEditorState } from './state'\nimport { createStatusActions } from './statuses'\nimport { createStickyActions } from './stickies'\nimport { createStructureActions } from './structure'\nimport { createTextActions } from './text'\nimport { createTextHyperlinkActions } from './text/hyperlink'\nimport { createPendingTextLayout } from './text/pending-layout'\nimport { createTextSelectionStyle } from './text/selection-style'\nimport { createGeneratedTextActions } from './text/typeface'\nimport type {\n EditorContext,\n EditorEventName,\n EditorEvents,\n EditorOptions,\n EditorState,\n ViewportInsets\n} from './types'\nimport { createUndoActions } from './undo'\nimport { createVariableActions } from './variables'\nimport { createVectorizeActions } from './vectorize'\nimport { createViewportActions, NO_VIEWPORT_INSETS } from './viewport'\nimport { createCanvasViewActions, offeredTool, resolveEditorProfile } from './views'\n\nexport { createDefaultEditorState } from './state'\n\n/** A canvas with no chrome reports nothing, which is the same as none covering it. */\nfunction resolveViewportInsets(options?: EditorOptions): () => ViewportInsets {\n return options?.getViewportInsets ?? (() => NO_VIEWPORT_INSETS)\n}\n\nexport function createEditor(options?: EditorOptions) {\n let _graph = options?.graph ?? new SceneGraph()\n const skipInitialGraphSetup = options?.skipInitialGraphSetup ?? false\n const undo = new UndoManager({\n onChange: () => emitEditorEvent('history:changed'),\n // A step owns the edited-field marks its edit added, so undo takes them back and redo\n // marks them again. The marks are the graph's, and the document can be replaced.\n marks: {\n take: () => _graph.takeSourceMarks(),\n add: (id, fields) => _graph.addSourceMarks(id, fields),\n remove: (id, fields) => _graph.removeSourceMarks(id, fields),\n preserve: (run) => _graph.preserveSourceMetadataDuring(run)\n }\n })\n const _loadFont = options?.loadFont ?? fontManager.loadFont.bind(fontManager)\n const _getViewportSize =\n options?.getViewportSize ??\n (() => {\n if (IS_BROWSER) return { width: window.innerWidth, height: window.innerHeight }\n return { width: 800, height: 600 }\n })\n const _getViewportInsets = resolveViewportInsets(options)\n let _ck: CanvasKit | null = null\n let _renderer: SkiaRenderer | null = null\n const _renderers = new Set<SkiaRenderer>()\n let uninstallTextMeasurer: (() => void) | null = null\n const interactiveEdits = new Set<symbol>()\n let _textEditor: TextEditor | null = null\n const events: Emitter<EditorEvents> = createNanoEvents()\n const stopFontResolutionEvents = fontResolver.subscribe((event, snapshot) => {\n if (event === 'settled') pendingTextLayout.relayoutReady(_renderer)\n events.emit('font:resolution-changed', event, snapshot)\n })\n const stopFontLoadEvents = fontManager.onFaceLoaded((family, style) => {\n // Text measured in a substitute takes its own face's size once a face of its family loads.\n pendingTextLayout.relayoutSubstituted(_renderer, family)\n events.emit('font:loaded', family, style)\n })\n // Text blocked while its fonts were prepared is missing from the tiles drawn meanwhile.\n const stopUnblockEvents = fontManager.onNodesUnblocked((nodeIds) => {\n let redrawn = false\n for (const renderer of _renderers) {\n for (const id of nodeIds) {\n if (!_graph.getNode(id)) continue\n renderer.invalidateNodePicture(id)\n redrawn = true\n }\n }\n if (redrawn) requestRender()\n })\n\n void prefetchFigmaSchema()\n\n const state: EditorState = options?.state ?? createDefaultEditorState(_graph.getPages()[0].id)\n state.documentKind = _graph.documentKind\n state.activeTool = offeredTool(state, state.activeTool)\n\n function emitEditorEvent<K extends EditorEventName>(\n event: K,\n ...args: Parameters<EditorEvents[K]>\n ) {\n events.emit(event, ...args)\n }\n\n function onEditorEvent<K extends EditorEventName>(event: K, handler: EditorEvents[K]) {\n return events.on(event, handler)\n }\n\n function requestRender() {\n state.renderVersion++\n state.sceneVersion++\n state.canvasVersion++\n emitNavigationTrace('render:requested', {\n kind: 'render',\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n emitEditorEvent('render:requested', {\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n }\n\n /**\n * The caret or selection of the edited text moved: the canvas repaints its overlay and the\n * views that follow the selection update, without the document counting as changed.\n */\n function textSelectionChanged() {\n state.textSelectionVersion++\n requestRepaint()\n }\n\n function requestRefresh() {\n state.sceneVersion++\n }\n\n function requestRepaint() {\n state.renderVersion++\n emitNavigationTrace('render:requested', {\n kind: 'repaint',\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n emitEditorEvent('repaint:requested', {\n renderVersion: state.renderVersion,\n sceneVersion: state.sceneVersion\n })\n }\n\n /** Track an actual live edit independently of history batching. Release is idempotent. */\n function beginInteractiveEdit() {\n const token = Symbol('interactive-edit')\n interactiveEdits.add(token)\n requestRepaint()\n return () => {\n if (interactiveEdits.delete(token)) requestRepaint()\n }\n }\n\n function setNavigationPhase(phase: EditorState['navigation']['phase'], inputAt = 0) {\n const previous = { ...state.navigation }\n const active = phase === 'pan' || phase === 'zoom' || phase === 'momentum'\n const wasActive =\n previous.phase === 'pan' || previous.phase === 'zoom' || previous.phase === 'momentum'\n state.navigation = {\n phase,\n generation: active && !wasActive ? previous.generation + 1 : previous.generation,\n lastInputAt: inputAt || previous.lastInputAt\n }\n if (\n state.navigation.phase !== previous.phase ||\n state.navigation.generation !== previous.generation ||\n state.navigation.lastInputAt !== previous.lastInputAt\n ) {\n emitNavigationTrace('navigation:phase', {\n phase: state.navigation.phase,\n previousPhase: previous.phase,\n generation: state.navigation.generation,\n lastInputAt: state.navigation.lastInputAt\n })\n emitEditorEvent('navigation:changed', state.navigation, previous)\n }\n }\n\n function setSelectedIds(ids: Set<string>) {\n const previous = [...state.selectedIds]\n state.selectedIds = ids\n if (ids.size === 0) state.measurementMode = 'off'\n const selected = [...ids]\n if (\n previous.length !== selected.length ||\n previous.some((id, index) => id !== selected[index])\n ) {\n emitEditorEvent('selection:changed', selected, previous)\n }\n }\n\n function setActiveTool(tool: EditorState['activeTool']) {\n if (offeredTool(state, tool) !== tool) return\n const previous = state.activeTool\n state.activeTool = tool\n if (tool !== 'SELECT') state.measurementMode = 'off'\n if (previous === tool) return\n // Guides the pen showed for its next point do not belong to the next tool.\n if (previous === 'PEN') state.snapGuides = []\n emitEditorEvent('tool:changed', tool, previous)\n }\n\n const graphReads = createGraphReadActions(() => _graph)\n const { runLayoutForNode, runLayoutForParents, runMutationWithLayout } = createLayoutRunner(\n () => _graph\n )\n const pendingTextLayout = createPendingTextLayout({\n getGraph: () => _graph,\n runLayoutForNode,\n requestRender\n })\n const { scheduleComponentSync, flushComponentSync, isSyncingComponents } =\n createComponentSyncScheduler(() => _graph, requestRender)\n\n const { subscribeToGraph, unsubscribeFromGraph } = createGraphEventSubscription({\n getGraph: () => _graph,\n getRenderers: () => _renderers,\n scheduleComponentSync,\n requestRender,\n emitEditorEvent\n })\n\n if (!skipInitialGraphSetup) {\n subscribeToGraph()\n // A new document's first page takes Figma's background for the interface theme the app gives;\n // a page that already has one keeps it.\n const firstPage = _graph.getPages()[0]\n if (options?.state?.theme && !hasStoredBackground(firstPage)) {\n setDefaultPageBackground(_graph, firstPage, options.state.theme)\n options.state.pageColor = getPageColor(firstPage)\n }\n }\n\n // Build the shared context\n const ctx: EditorContext = {\n get graph() {\n return _graph\n },\n set graph(g) {\n _graph = g\n },\n undo,\n parkStep,\n state,\n loadFont: _loadFont,\n resolveFigmaClipboardImages: options?.resolveFigmaClipboardImages ?? null,\n getViewportSize: _getViewportSize,\n getViewportInsets: _getViewportInsets,\n getUserName: () => options?.getUserName?.() ?? '',\n icons: options?.icons ?? defaultIcons,\n getCk: () => _ck,\n getRenderer: () => _renderer,\n getRenderers: () => _renderers,\n getTextEditor: () => _textEditor,\n requestRender,\n requestRefresh,\n requestRepaint,\n beginInteractiveEdit,\n onEditorEvent,\n emitEditorEvent,\n setSelectedIds,\n setActiveTool,\n setNavigationPhase,\n runLayoutForNode,\n runLayoutForParents,\n runMutationWithLayout,\n subscribeToGraph\n }\n\n // Assemble domain modules\n const viewport = createViewportActions(ctx)\n const selection = createSelectionActions(ctx)\n const shaderFrames = createShaderFrames(ctx, options)\n const pages = createPageActions(ctx, shaderFrames)\n const guides = createGuideActions(ctx)\n const designIssues = createDesignIssueActions(ctx)\n const structure = createStructureActions(ctx)\n const components = createComponentActions(ctx)\n const clipboard = createClipboardActions(ctx)\n const colorSpace = createColorSpaceActions(ctx)\n const documentSettings = createDocumentSettingsActions(ctx)\n const undoActions = createUndoActions(ctx)\n const text = createTextActions(ctx)\n const nodes = createNodeActions(ctx)\n const shapes = createShapeActions(ctx, nodes.updateNodeWithUndo)\n const clipboardProperties = createClipboardPropertiesActions(\n ctx,\n nodes.updateNodeWithUndo,\n clipboard.loadFontsForNodes\n )\n const variables = createVariableActions(ctx)\n const designTokens = createDesignTokenActions(ctx, variables, nodes)\n const vectorize = createVectorizeActions(ctx)\n const icons = createIconActions(ctx)\n const stickies = createStickyActions(ctx, nodes)\n const scale = createScaleActions(ctx, nodes.beginNodePreview)\n const shapesWithText = createShapeWithTextActions(ctx, nodes)\n const generatedText = createGeneratedTextActions(ctx, nodes)\n const statuses = createStatusActions(ctx)\n const figCompression = createFigCompressionActions(ctx)\n createConnectorRouting(ctx)\n const connectorDrawing = createConnectorDrawActions(ctx)\n const connectorEndpoints = createConnectorEndpointActions(\n ctx,\n nodes.beginNodePreview,\n clipboard.deleteNodes\n )\n const connectorLines = createConnectorLineActions(ctx, nodes.beginNodePreview)\n const connectorStyles = createConnectorStyleActions(ctx, nodes)\n const lineEnds = createLineEndActions(ctx, nodes.beginNodePreview)\n const imageEdit = createImageEditActions(ctx, nodes.updateNodeWithUndo)\n const shaders = createShaderActions(ctx, nodes)\n const alignment = createAlignmentActions(ctx)\n const canvasViews = createCanvasViewActions(ctx, viewport)\n const clipboardBridge = createClipboardBridge(clipboard, selection)\n const componentBridge = createComponentBridge(components, selection, structure, pages)\n const structureBridge = createStructureBridge(structure, selection)\n const frameNavigation = createFrameNavigationBridge(ctx, selection, viewport)\n const undoBridge = createUndoBridge(undoActions, selection, nodes.flushNudge)\n const lintFixBridge = createLintFixBridge(ctx, nodes, structure, clipboard)\n const textSelectionStyle = createTextSelectionStyle(ctx, text.runTextEditStep)\n const textHyperlinks = createTextHyperlinkActions(ctx, {\n updateNodeWithUndo: nodes.updateNodeWithUndo,\n runTextEditStep: text.runTextEditStep,\n switchPage: (pageId) => pages.switchPage(pageId),\n revealNodes: viewport.revealNodes\n })\n /** Whether the editor refuses edits: its profile offers none, as for a read-only document. */\n const readsOnly = () => !resolveEditorProfile(state).edits\n const readOnly = createReadOnlyActions(ctx, () => {\n nodes.flushNudge()\n nodes.cancelNodePreviews()\n if (state.editingTextId) text.commitTextEdit()\n shapes.penCancel()\n shapes.pencilCancel()\n state.gradientEdit = null\n state.imageEdit = null\n })\n\n // The edited text follows changes made outside the editor, such as a panel field being\n // dragged, so its caret and selection move with the text instead of after the change.\n const invalidateEditedText = (id: string) => {\n if (id !== state.editingTextId) return\n const node = _graph.getNode(id)\n if (node) _textEditor?.invalidateParagraph(node)\n }\n onEditorEvent('node:updated', invalidateEditedText)\n onEditorEvent('node:previewUpdated', invalidateEditedText)\n\n function setCanvasKit(ck: CanvasKit, renderer: SkiaRenderer) {\n _ck = ck\n _renderer = renderer\n _renderers.add(renderer)\n _textEditor ??= new TextEditor(ck)\n uninstallTextMeasurer?.()\n uninstallTextMeasurer =\n typeof renderer.measureTextNode === 'function'\n ? installTextMeasurer((node, maxWidth) =>\n pendingTextLayout.measure(renderer, node, maxWidth)\n )\n : null\n }\n\n function releaseTextMeasurer() {\n uninstallTextMeasurer?.()\n uninstallTextMeasurer = null\n }\n\n function removeCanvasRenderer(renderer: SkiaRenderer) {\n _renderers.delete(renderer)\n if (_renderer === renderer) {\n _renderer = _renderers.values().next().value ?? null\n }\n if (_renderers.size === 0) releaseTextMeasurer()\n }\n\n /** Each graph's committed history, kept aside while another graph is open in this editor. */\n const histories = new WeakMap<SceneGraph, UndoHistory>()\n\n /** A step recorded while its document was swapped away joins that document's own history. */\n function parkStep(graph: SceneGraph, entry: UndoEntry) {\n const history = histories.get(graph)\n if (history) histories.set(graph, undo.pushIntoParked(history, entry))\n }\n\n function replaceGraph(newGraph: SceneGraph) {\n nodes.cancelNodePreviews()\n if (newGraph !== _graph) {\n // Undo steps name layers by id and act on whichever graph is open, so history stays with\n // the graph it was recorded on: a document opened in this editor starts with its own,\n // instead of undoing the last document's layers that share an id.\n histories.set(_graph, undo.takeHistory())\n undo.adoptHistory(histories.get(newGraph))\n // Menus show the new graph's history; a step still being recorded keeps its own notice,\n // which is how it learns another write happened beside it.\n if (!undo.isRecording) emitEditorEvent('history:changed')\n }\n _graph = newGraph\n state.documentKind = _graph.documentKind\n setActiveTool(offeredTool(state, state.activeTool))\n pendingTextLayout.clear()\n subscribeToGraph()\n const previousPageId = state.currentPageId\n state.currentPageId = _graph.getPages()[0]?.id ?? _graph.rootId\n setSelectedIds(new Set())\n state.hoveredNodeId = null\n state.transforming = false\n state.measurementMode = 'off'\n state.snapGuides = []\n state.guides = { preview: null, hovered: null, selected: null, redline: null }\n state.layoutInsertIndicator = null\n state.dropTargetId = null\n pages.clearPageViewports()\n for (const renderer of _renderers) renderer.tiledScene.invalidateStructure()\n emitEditorEvent('graph:replaced', _graph)\n if (previousPageId !== state.currentPageId) {\n emitEditorEvent('page:changed', state.currentPageId, previousPageId)\n }\n requestRender()\n }\n\n function dispose() {\n releaseTextMeasurer()\n nodes.cancelNodePreviews()\n interactiveEdits.clear()\n stopFontResolutionEvents()\n stopFontLoadEvents()\n stopUnblockEvents()\n unsubscribeFromGraph()\n }\n\n function releaseGraphResources() {\n releaseFigPopulationWorker(_graph)\n releaseOriginalFigArchive(_graph)\n }\n\n const editor = {\n get graph() {\n return _graph\n },\n /** Instances are being brought in line with their components: results, not edits. */\n isSyncingComponents,\n get renderer() {\n return _renderer\n },\n get canvasRenderers() {\n return [..._renderers]\n },\n get textEditor() {\n return _textEditor\n },\n undo: guardUndo(undo, readsOnly),\n parkStep,\n state,\n\n // Graph reads\n runLayoutForNode,\n runLayoutForParents,\n runMutationWithLayout,\n ...graphReads,\n\n // Lifecycle\n beginInteractiveEdit,\n isInteractiveEditing: () => interactiveEdits.size > 0,\n flushComponentSync,\n requestRender,\n requestRefresh,\n textSelectionChanged,\n requestRepaint,\n onEditorEvent,\n setCanvasKit,\n setNavigationPhase,\n removeCanvasRenderer,\n replaceGraph,\n subscribeToGraph,\n dispose,\n releaseGraphResources,\n\n // Selection\n ...selection,\n\n // Pages\n ...pages,\n\n // Canvas and frame guides\n ...guides,\n ...designIssues,\n\n // Shapes & tools\n ...shapes,\n\n // Structure (group, reorder, reparent, z-order)\n ...structure,\n\n // Nodes (update, layout); while text is edited, character styles go to its selection\n ...nodes,\n updateNode: (id: string, changes: Partial<SceneNode>) =>\n textSelectionStyle.updateNode(id, changes, nodes.updateNode),\n updateNodeWithUndo: (id: string, changes: Partial<SceneNode>, label = 'Update') =>\n textSelectionStyle.updateNodeWithUndo(id, changes, (target, next) =>\n nodes.updateNodeWithUndo(target, next, label)\n ),\n getTextSelectionStyle: textSelectionStyle.selectionStyle,\n layerChanges: textSelectionStyle.layerChanges,\n\n // Alignment (align, flip, rotate)\n ...alignment,\n\n // Canvas views: editing, or a preview where instances with a behaviour respond to the pointer\n ...canvasViews,\n\n // Bitmap-to-vector replacement\n ...vectorize,\n ...icons,\n ...stickies,\n // The Scale tool: layers scale with their text, strokes, effects, radii, and spacing\n ...scale,\n ...shapesWithText,\n ...generatedText,\n statusWorkflow: statuses.statusWorkflow,\n getShownStatus: statuses.getShownStatus,\n setStatus: statuses.setStatus,\n setStatusWorkflow: statuses.setStatusWorkflow,\n ...connectorDrawing,\n ...connectorEndpoints,\n ...connectorLines,\n ...lineEnds,\n ...imageEdit,\n ...connectorStyles,\n ...shaders,\n ...shaderFrames,\n\n // Variables\n ...variables,\n ...designTokens,\n\n // Text editing\n ...text,\n ...textHyperlinks,\n\n // Viewport\n ...viewport,\n ...frameNavigation,\n\n // Undo — bridge functions that need cross-module refs\n ...undoBridge,\n commitNodeUpdate: (id: string, previous: Partial<SceneNode>, label = 'Update') =>\n textSelectionStyle.commitNodeUpdate(\n id,\n previous,\n (target, values) => undoBridge.commitNodeUpdate(target, values, label),\n (target, next) => nodes.updateNodeWithUndo(target, next, label)\n ),\n // While text is edited, what was typed undoes first and the editor keeps the result.\n undoAction: () => text.runTextEditStep(undoBridge.undoAction),\n redoAction: () => text.runTextEditStep(undoBridge.redoAction),\n\n setDocumentColorSpace: colorSpace.setDocumentColorSpace,\n updateEnabledLibraries: documentSettings.updateEnabledLibraries,\n refreshDocumentSettings: documentSettings.refreshDocumentSettings,\n setDocumentKind: documentSettings.setDocumentKind,\n figCompression: figCompression.figCompression,\n setFigCompression: figCompression.setFigCompression,\n\n // Clipboard — bridge functions that need selectedNodes\n ...clipboardBridge,\n\n // Paste properties: the look of a copied layer, onto the selection\n ...clipboardProperties,\n\n // Components — bridge functions\n ...componentBridge,\n\n // Structure — bridge functions that need selectedNodes\n ...structureBridge,\n\n // Lint fixes, which touch nodes, structure and deletion in one undo step\n ...lintFixBridge,\n\n // Read-only documents, which refuse every action above that changes them\n ...readOnly\n }\n return guardReadOnly(editor, readsOnly)\n}\n\n/**\n * The editor `createEditor` returns. An interface rather than an alias, so declarations that\n * mention it, such as a Vue composable's inferred return type, name it instead of spelling out\n * its members, some of whose types are internal to Core.\n */\n// eslint-disable-next-line typescript/no-empty-object-type -- The interface is the point: an alias's members are spelled out in emitted declarations.\nexport interface Editor extends ReturnType<typeof createEditor> {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,SAAS,sBAAsB,SAA+C;CAC5E,OAAO,SAAS,4BA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["../../../src/editor/history/edit.ts"],"mappings":";;;UAaiB;;EAEf;;EAEA;;EAEA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;EAKA,cAAc,QAAQ;;;;;;;;iBAqJR,WAAW,GAAG,KAAK,eAAe,SAAS,mBAAmB,WAAW,IAAI;;;;;;;;;;;iBAuBvE,gBAAgB,GACpC,KAAK,eACL,SAAS,mBACT,WAAW,QAAQ,KAClB,QAAQ"}
1
+ {"version":3,"file":"edit.d.ts","names":[],"sources":["../../../src/editor/history/edit.ts"],"mappings":";;;UAaiB;;EAEf;;EAEA;;EAEA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;EAKA,cAAc,QAAQ;;;;;;;;iBAyJR,WAAW,GAAG,KAAK,eAAe,SAAS,mBAAmB,WAAW,IAAI;;;;;;;;;;;iBAuBvE,gBAAgB,GACpC,KAAK,eACL,SAAS,mBACT,WAAW,QAAQ,KAClB,QAAQ"}
@@ -114,7 +114,8 @@ function begin(ctx, options, awaits = false) {
114
114
  }
115
115
  if (options.push !== false && !empty) {
116
116
  const entry = changeStep(ctx, options.label, change);
117
- if (options.ownStep) ctx.undo.pushStep(entry);
117
+ if (ctx.graph !== graph) ctx.parkStep(graph, entry);
118
+ else if (options.ownStep) ctx.undo.pushStep(entry);
118
119
  else ctx.undo.push(entry);
119
120
  }
120
121
  options.onRecorded?.(change);