@pairdraw/core 0.19.1 → 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/images/previews.d.ts +1 -1
  2. package/dist/canvas/overlays/index.d.ts +2 -2
  3. package/dist/canvas/overlays/index.js +2 -2
  4. package/dist/canvas/overlays/selection.d.ts +1 -2
  5. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  6. package/dist/canvas/overlays/selection.js +2 -9
  7. package/dist/canvas/overlays/selection.js.map +1 -1
  8. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  9. package/dist/canvas/renderer/fonts.js +2 -0
  10. package/dist/canvas/renderer/fonts.js.map +1 -1
  11. package/dist/canvas/renderer/methods.d.ts +0 -1
  12. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  13. package/dist/canvas/renderer/methods.js +1 -4
  14. package/dist/canvas/renderer/methods.js.map +1 -1
  15. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  16. package/dist/canvas/renderer/overlay-pass.js +0 -1
  17. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  18. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  19. package/dist/canvas/renderer/pipeline.js +0 -1
  20. package/dist/canvas/renderer/pipeline.js.map +1 -1
  21. package/dist/canvas/renderer/types.d.ts +0 -1
  22. package/dist/canvas/renderer/types.d.ts.map +1 -1
  23. package/dist/canvas/renderer.d.ts +0 -1
  24. package/dist/canvas/renderer.d.ts.map +1 -1
  25. package/dist/canvas/renderer.js.map +1 -1
  26. package/dist/design-jsx/index.d.ts +2 -2
  27. package/dist/design-jsx/index.js +2 -2
  28. package/dist/design-jsx/renderer.d.ts +3 -2
  29. package/dist/design-jsx/renderer.d.ts.map +1 -1
  30. package/dist/design-jsx/renderer.js +2 -2
  31. package/dist/design-jsx/renderer.js.map +1 -1
  32. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  33. package/dist/editor/clipboard/snapshot.js +12 -4
  34. package/dist/editor/clipboard/snapshot.js.map +1 -1
  35. package/dist/editor/clipboard.d.ts.map +1 -1
  36. package/dist/editor/clipboard.js +2 -7
  37. package/dist/editor/clipboard.js.map +1 -1
  38. package/dist/editor/color-space.d.ts.map +1 -1
  39. package/dist/editor/color-space.js +33 -38
  40. package/dist/editor/color-space.js.map +1 -1
  41. package/dist/editor/create.d.ts +9 -5
  42. package/dist/editor/create.d.ts.map +1 -1
  43. package/dist/editor/create.js +10 -1
  44. package/dist/editor/create.js.map +1 -1
  45. package/dist/editor/history/edit.d.ts.map +1 -1
  46. package/dist/editor/history/edit.js +2 -1
  47. package/dist/editor/history/edit.js.map +1 -1
  48. package/dist/editor/nudge.js +1 -1
  49. package/dist/editor/nudge.js.map +1 -1
  50. package/dist/editor/read-only/actions.js +2 -0
  51. package/dist/editor/read-only/actions.js.map +1 -1
  52. package/dist/editor/selection/container.d.ts +2 -0
  53. package/dist/editor/selection/container.d.ts.map +1 -1
  54. package/dist/editor/selection/container.js +17 -1
  55. package/dist/editor/selection/container.js.map +1 -1
  56. package/dist/editor/selection/navigation.js +7 -4
  57. package/dist/editor/selection/navigation.js.map +1 -1
  58. package/dist/editor/selection/read.d.ts +2 -2
  59. package/dist/editor/selection.d.ts +4 -2
  60. package/dist/editor/selection.d.ts.map +1 -1
  61. package/dist/editor/shapes/with-text.d.ts.map +1 -1
  62. package/dist/editor/shapes/with-text.js +2 -5
  63. package/dist/editor/shapes/with-text.js.map +1 -1
  64. package/dist/editor/structure/auto-layout-wrap.js +1 -1
  65. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  66. package/dist/editor/structure/boolean.d.ts +2 -3
  67. package/dist/editor/structure/boolean.d.ts.map +1 -1
  68. package/dist/editor/structure/boolean.js.map +1 -1
  69. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  70. package/dist/editor/structure/group/bounds.js +1 -3
  71. package/dist/editor/structure/group/bounds.js.map +1 -1
  72. package/dist/editor/structure/outline-stroke.js +3 -3
  73. package/dist/editor/structure/outline-stroke.js.map +1 -1
  74. package/dist/editor/structure/reorder.d.ts.map +1 -1
  75. package/dist/editor/structure/reorder.js +7 -14
  76. package/dist/editor/structure/reorder.js.map +1 -1
  77. package/dist/editor/structure/state.js +1 -1
  78. package/dist/editor/structure/state.js.map +1 -1
  79. package/dist/editor/structure.d.ts +1 -2
  80. package/dist/editor/structure.d.ts.map +1 -1
  81. package/dist/editor/structure.js +3 -3
  82. package/dist/editor/structure.js.map +1 -1
  83. package/dist/editor/types.d.ts +4 -1
  84. package/dist/editor/types.d.ts.map +1 -1
  85. package/dist/editor/variables.d.ts.map +1 -1
  86. package/dist/editor/variables.js +57 -1
  87. package/dist/editor/variables.js.map +1 -1
  88. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  89. package/dist/figma-api/accessors/text/index.js +4 -1
  90. package/dist/figma-api/accessors/text/index.js.map +1 -1
  91. package/dist/figma-api/fonts/loaded.d.ts +3 -1
  92. package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
  93. package/dist/figma-api/fonts/loaded.js +8 -1
  94. package/dist/figma-api/fonts/loaded.js.map +1 -1
  95. package/dist/figma-api/index.d.ts +13 -0
  96. package/dist/figma-api/index.d.ts.map +1 -1
  97. package/dist/figma-api/index.js +13 -0
  98. package/dist/figma-api/index.js.map +1 -1
  99. package/dist/figma-api/serialization.d.ts.map +1 -1
  100. package/dist/figma-api/serialization.js +2 -1
  101. package/dist/figma-api/serialization.js.map +1 -1
  102. package/dist/figma-api/shape-details.d.ts +26 -0
  103. package/dist/figma-api/shape-details.d.ts.map +1 -0
  104. package/dist/figma-api/shape-details.js +28 -0
  105. package/dist/figma-api/shape-details.js.map +1 -0
  106. package/dist/figma-api/shape-with-text.js +2 -5
  107. package/dist/figma-api/shape-with-text.js.map +1 -1
  108. package/dist/figma-api/surface.d.ts +1 -1
  109. package/dist/figma-api/surface.d.ts.map +1 -1
  110. package/dist/figma-api/surface.js +1 -0
  111. package/dist/figma-api/surface.js.map +1 -1
  112. package/dist/icons/svg.js +1 -1
  113. package/dist/icons/svg.js.map +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":"outline-stroke.js","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport {\n layersToOutline,\n outlineStrokeLayer,\n type OutlinePiece,\n type OutlinedLayer\n} from '#core/canvas/outline-stroke'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\n/** A layer to outline, where it sits, and what it becomes. */\ninterface Outlining {\n node: SceneNode\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n outlined: OutlinedLayer\n}\n\n/** Where a layer Outline stroke made sits, to put it back on redo. */\ninterface Made {\n id: string\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n}\n\n/** Creates a piece in `parentId` at `index`, with a group's glyph vectors inside it. */\nfunction createPiece(ctx: EditorContext, piece: OutlinePiece, parentId: string, index: number) {\n const node = ctx.graph.createNode(piece.type, parentId, piece.props)\n for (const child of piece.children) ctx.graph.createNode('VECTOR', node.id, child)\n ctx.graph.insertChildAt(node.id, parentId, index)\n return node.id\n}\n\n/** Restores snapshots taken in one parent, lowest index first so each lands where it was. */\nfunction restoreAt(ctx: EditorContext, entries: readonly Made[]) {\n for (const { id, parentId, index, snapshot } of entries.toSorted((a, b) => a.index - b.index)) {\n const root = snapshot.get(id)\n if (!root) continue\n restoreSubtree(ctx.graph, root, parentId, snapshot)\n ctx.graph.insertChildAt(id, parentId, index)\n }\n}\n\n/**\n * Figma's Outline stroke: every stroked layer is replaced, where it was, by its fill as a shape\n * of its own under its stroke as one, both selected. Undo puts the layers back.\n */\nexport function outlineStrokeSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[]\n): string[] | null {\n const renderer = ctx.getRenderer()\n if (!renderer) return null\n const plan: Outlining[] = []\n for (const node of layersToOutline(selectedNodes, ctx.graph)) {\n const parent = node.parentId ? ctx.graph.getNode(node.parentId) : undefined\n const outlined = parent ? outlineStrokeLayer(renderer, node, ctx.graph) : null\n if (!parent || !outlined) continue\n plan.push({\n node,\n parentId: parent.id,\n index: parent.childIds.indexOf(node.id),\n snapshot: snapshotSubtree(ctx.graph, node.id),\n outlined\n })\n }\n if (plan.length === 0) return null\n\n const madeIds: string[] = []\n for (const { node, parentId, outlined } of plan) {\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? 0\n const fill = outlined.fill ? createPiece(ctx, outlined.fill, parentId, index) : null\n const stroke = createPiece(ctx, outlined.stroke, parentId, index + (fill ? 1 : 0))\n ctx.graph.deleteNode(node.id)\n if (fill) madeIds.push(fill)\n madeIds.push(stroke)\n }\n const made: Made[] = madeIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return []\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(id) ?? 0\n return [{ id, parentId, index, snapshot: snapshotSubtree(ctx.graph, id) }]\n })\n const parentIds = new Set(plan.map((entry) => entry.parentId))\n const prevSelection = new Set(ctx.state.selectedIds)\n for (const parentId of parentIds) ctx.runLayoutForNode(parentId)\n ctx.setSelectedIds(new Set(madeIds))\n\n // Groups around the outlines fit them, which can reach past the layers they replace, in the\n // same undo step.\n ctx.undo.runBatch('Outline stroke', () => {\n pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n return madeIds\n}\n\n/** The undo step that puts the outlined layers back, and redo that outlines them again. */\nfunction pushOutlineUndo(\n ctx: EditorContext,\n {\n plan,\n made,\n madeIds,\n parentIds,\n prevSelection\n }: {\n plan: readonly Outlining[]\n made: readonly Made[]\n madeIds: readonly string[]\n parentIds: ReadonlySet<string>\n prevSelection: ReadonlySet<string>\n }\n) {\n ctx.undo.push({\n label: 'Outline stroke',\n forward: () => {\n for (const { node } of plan) ctx.graph.deleteNode(node.id)\n restoreAt(ctx, made)\n for (const parentId of parentIds) ctx.runLayoutForNode(parentId)\n ctx.setSelectedIds(new Set(madeIds))\n },\n inverse: () => {\n for (const { id } of made) ctx.graph.deleteNode(id)\n restoreAt(\n ctx,\n plan.map(({ node, parentId, index, snapshot }) => ({\n id: node.id,\n parentId,\n index,\n snapshot\n }))\n )\n for (const parentId of parentIds) ctx.runLayoutForNode(parentId)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n}\n"],"mappings":";;;;;AA8BA,SAAS,YAAY,KAAoB,OAAqB,UAAkB,OAAe;CAC7F,MAAM,OAAO,IAAI,MAAM,WAAW,MAAM,MAAM,UAAU,MAAM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K,EAAE,MAAM,UAAU,OAAO,gBAAgB;IACjD,IAAI,KAAK;IACT;IACA;IACA;GACF,EAAE,CACJ;GACA,KAAK,MAAM,YAAY,WAAW,IAAI,iBAAiB,QAAQ;GAC/D,IAAI,eAAe,IAAI,IAAI,aAAa,CAAC;EAC3C;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"outline-stroke.js","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport {\n layersToOutline,\n outlineStrokeLayer,\n type OutlinePiece,\n type OutlinedLayer\n} from '#core/canvas/outline-stroke'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\n/** A layer to outline, where it sits, and what it becomes. */\ninterface Outlining {\n node: SceneNode\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n outlined: OutlinedLayer\n}\n\n/** Where a layer Outline stroke made sits, to put it back on redo. */\ninterface Made {\n id: string\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n}\n\n/** Creates a piece in `parentId` at `index`, with a group's glyph vectors inside it. */\nfunction createPiece(ctx: EditorContext, piece: OutlinePiece, parentId: string, index: number) {\n const node = ctx.graph.createNode(piece.type, parentId, piece.props)\n for (const child of piece.children) ctx.graph.createNode('VECTOR', node.id, child)\n ctx.graph.insertChildAt(node.id, parentId, index)\n return node.id\n}\n\n/** Restores snapshots taken in one parent, lowest index first so each lands where it was. */\nfunction restoreAt(ctx: EditorContext, entries: readonly Made[]) {\n for (const { id, parentId, index, snapshot } of entries.toSorted((a, b) => a.index - b.index)) {\n const root = snapshot.get(id)\n if (!root) continue\n restoreSubtree(ctx.graph, root, parentId, snapshot)\n ctx.graph.insertChildAt(id, parentId, index)\n }\n}\n\n/**\n * Figma's Outline stroke: every stroked layer is replaced, where it was, by its fill as a shape\n * of its own under its stroke as one, both selected. Undo puts the layers back.\n */\nexport function outlineStrokeSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[]\n): string[] | null {\n const renderer = ctx.getRenderer()\n if (!renderer) return null\n const plan: Outlining[] = []\n for (const node of layersToOutline(selectedNodes, ctx.graph)) {\n const parent = node.parentId ? ctx.graph.getNode(node.parentId) : undefined\n const outlined = parent ? outlineStrokeLayer(renderer, node, ctx.graph) : null\n if (!parent || !outlined) continue\n plan.push({\n node,\n parentId: parent.id,\n index: parent.childIds.indexOf(node.id),\n snapshot: snapshotSubtree(ctx.graph, node.id),\n outlined\n })\n }\n if (plan.length === 0) return null\n\n const madeIds: string[] = []\n for (const { node, parentId, outlined } of plan) {\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? 0\n const fill = outlined.fill ? createPiece(ctx, outlined.fill, parentId, index) : null\n const stroke = createPiece(ctx, outlined.stroke, parentId, index + (fill ? 1 : 0))\n ctx.graph.deleteNode(node.id)\n if (fill) madeIds.push(fill)\n madeIds.push(stroke)\n }\n const made: Made[] = madeIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return []\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(id) ?? 0\n return [{ id, parentId, index, snapshot: snapshotSubtree(ctx.graph, id) }]\n })\n const parentIds = new Set(plan.map((entry) => entry.parentId))\n const prevSelection = new Set(ctx.state.selectedIds)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n\n // Groups around the outlines fit them, which can reach past the layers they replace, in the\n // same undo step.\n ctx.undo.runBatch('Outline stroke', () => {\n pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n return madeIds\n}\n\n/** The undo step that puts the outlined layers back, and redo that outlines them again. */\nfunction pushOutlineUndo(\n ctx: EditorContext,\n {\n plan,\n made,\n madeIds,\n parentIds,\n prevSelection\n }: {\n plan: readonly Outlining[]\n made: readonly Made[]\n madeIds: readonly string[]\n parentIds: ReadonlySet<string>\n prevSelection: ReadonlySet<string>\n }\n) {\n ctx.undo.push({\n label: 'Outline stroke',\n forward: () => {\n for (const { node } of plan) ctx.graph.deleteNode(node.id)\n restoreAt(ctx, made)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n },\n inverse: () => {\n for (const { id } of made) ctx.graph.deleteNode(id)\n restoreAt(\n ctx,\n plan.map(({ node, parentId, index, snapshot }) => ({\n id: node.id,\n parentId,\n index,\n snapshot\n }))\n )\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n}\n"],"mappings":";;;;;AA8BA,SAAS,YAAY,KAAoB,OAAqB,UAAkB,OAAe;CAC7F,MAAM,OAAO,IAAI,MAAM,WAAW,MAAM,MAAM,UAAU,MAAM,KAAK;CACnE,KAAK,MAAM,SAAS,MAAM,UAAU,IAAI,MAAM,WAAW,UAAU,KAAK,IAAI,KAAK;CACjF,IAAI,MAAM,cAAc,KAAK,IAAI,UAAU,KAAK;CAChD,OAAO,KAAK;AACd;;AAGA,SAAS,UAAU,KAAoB,SAA0B;CAC/D,KAAK,MAAM,EAAE,IAAI,UAAU,OAAO,cAAc,QAAQ,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;EAC7F,MAAM,OAAO,SAAS,IAAI,EAAE;EAC5B,IAAI,CAAC,MAAM;EACX,eAAe,IAAI,OAAO,MAAM,UAAU,QAAQ;EAClD,IAAI,MAAM,cAAc,IAAI,UAAU,KAAK;CAC7C;AACF;;;;;AAMA,SAAgB,sBACd,KACA,eACiB;CACjB,MAAM,WAAW,IAAI,YAAY;CACjC,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,OAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,gBAAgB,eAAe,IAAI,KAAK,GAAG;EAC5D,MAAM,SAAS,KAAK,WAAW,IAAI,MAAM,QAAQ,KAAK,QAAQ,IAAI,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C,gBAAgB,KAAK;GAAE;GAAM;GAAM;GAAS;GAAW;EAAc,CAAC;EACtE,2BAA2B,KAAK,SAAS;CAC3C,CAAC;CACD,OAAO;AACT;;AAGA,SAAS,gBACP,KACA,EACE,MACA,MACA,SACA,WACA,iBAQF;CACA,IAAI,KAAK,KAAK;EACZ,OAAO;EACP,eAAe;GACb,KAAK,MAAM,EAAE,UAAU,MAAM,IAAI,MAAM,WAAW,KAAK,EAAE;GACzD,UAAU,KAAK,IAAI;GACnB,IAAI,oBAAoB,SAAS;GACjC,IAAI,eAAe,IAAI,IAAI,OAAO,CAAC;EACrC;EACA,eAAe;GACb,KAAK,MAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,WAAW,EAAE;GAClD,UACE,KACA,KAAK,KAAK,EAAE,MAAM,UAAU,OAAO,gBAAgB;IACjD,IAAI,KAAK;IACT;IACA;IACA;GACF,EAAE,CACJ;GACA,IAAI,oBAAoB,SAAS;GACjC,IAAI,eAAe,IAAI,IAAI,aAAa,CAAC;EAC3C;CACF,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"reorder.d.ts","names":[],"sources":["../../../src/editor/structure/reorder.ts"],"mappings":";;iBAWgB,8BAA8B,KAAK;EAkBZ,sBAAA,gBAAM,kBAAkB;EAqG5B,gBAAA,kBAAM,0BAA0B;EA1D3B,uBAAA,gBAAM,qBAAqB"}
1
+ {"version":3,"file":"reorder.d.ts","names":[],"sources":["../../../src/editor/structure/reorder.ts"],"mappings":";;iBAUgB,8BAA8B,KAAK;EAiBZ,sBAAA,gBAAM,kBAAkB;EAiG5B,gBAAA,kBAAM,0BAA0B;EA3D3B,uBAAA,gBAAM,qBAAqB"}
@@ -1,5 +1,4 @@
1
1
  import { assertNodeEditable } from "../capabilities.js";
2
- import { computeLayout } from "../../layout.js";
3
2
  import { prepareSlotEdits } from "../components/slots/index.js";
4
3
  import { fitEnclosingGroupsWithUndo } from "./group/bounds.js";
5
4
  import { pick } from "es-toolkit";
@@ -21,8 +20,7 @@ function createStructureReorderActions(ctx) {
21
20
  });
22
21
  }
23
22
  ctx.graph.insertChildAt(nodeId, parentId, insertIndex);
24
- computeLayout(ctx.graph, parentId);
25
- ctx.runLayoutForNode(parentId);
23
+ ctx.runLayoutForParents([parentId]);
26
24
  }
27
25
  function reorderInAutoLayout(nodeId, parentId, insertIndex) {
28
26
  ctx.undo.runBatch("Reorder", () => reorderInFlow(nodeId, parentId, insertIndex));
@@ -49,12 +47,7 @@ function createStructureReorderActions(ctx) {
49
47
  x: origX,
50
48
  y: origY
51
49
  });
52
- computeLayout(ctx.graph, origParentId);
53
- ctx.runLayoutForNode(origParentId);
54
- if (origParentId !== parentId) {
55
- computeLayout(ctx.graph, parentId);
56
- ctx.runLayoutForNode(parentId);
57
- }
50
+ ctx.runLayoutForParents([origParentId, parentId]);
58
51
  }
59
52
  });
60
53
  fitEnclosingGroupsWithUndo(ctx, [origParentId]);
@@ -81,8 +74,8 @@ function createStructureReorderActions(ctx) {
81
74
  const place = () => {
82
75
  if (reparents) ctx.graph.reparentNode(nodeId, newParentId);
83
76
  ctx.graph.insertChildAt(nodeId, newParentId, insertIndex);
84
- ctx.runLayoutForNode(newParentId);
85
- if (reparents) ctx.runLayoutForNode(origParentId);
77
+ if (reparents) ctx.runLayoutForNode(nodeId);
78
+ ctx.runLayoutForParents([newParentId, origParentId]);
86
79
  };
87
80
  place();
88
81
  ctx.undo.push({
@@ -91,8 +84,8 @@ function createStructureReorderActions(ctx) {
91
84
  inverse: () => {
92
85
  ctx.graph.insertChildAt(nodeId, origParentId, origIndex);
93
86
  ctx.graph.updateNode(nodeId, origPlace);
94
- ctx.runLayoutForNode(origParentId);
95
- if (reparents) ctx.runLayoutForNode(newParentId);
87
+ if (reparents) ctx.runLayoutForNode(nodeId);
88
+ ctx.runLayoutForParents([origParentId, newParentId]);
96
89
  }
97
90
  });
98
91
  fitEnclosingGroupsWithUndo(ctx, [origParentId, newParentId]);
@@ -110,7 +103,7 @@ function createStructureReorderActions(ctx) {
110
103
  if (ctx.graph.getNode(parentId)?.childIds[index] === childId) continue;
111
104
  ctx.graph.insertChildAt(childId, parentId, index);
112
105
  }
113
- ctx.runLayoutForNode(parentId);
106
+ ctx.runLayoutForParents([parentId]);
114
107
  ctx.requestRender();
115
108
  }
116
109
  /** Puts a frame's children in `order` as one undo step, laying the frame out once. */
@@ -1 +1 @@
1
- {"version":3,"file":"reorder.js","names":[],"sources":["../../../src/editor/structure/reorder.ts"],"sourcesContent":["import { pick } from 'es-toolkit'\n\nimport { TRANSFORM_FIELDS } from '@pairdraw/scene-graph/fields'\nimport { createsComponentCycle } from '@pairdraw/scene-graph/instances'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport { prepareSlotEdits } from '#core/editor/components/slots'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\nimport { computeLayout } from '#core/layout'\n\nexport function createStructureReorderActions(ctx: EditorContext) {\n function doReorderChild(nodeId: string, parentId: string, insertIndex: number) {\n assertNodeEditable(ctx.graph, nodeId)\n assertNodeEditable(ctx.graph, parentId)\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n\n if (node.parentId !== parentId) {\n const absPos = ctx.graph.getAbsolutePosition(nodeId)\n const parentAbs = ctx.graph.getAbsolutePosition(parentId)\n ctx.graph.updateNode(nodeId, { x: absPos.x - parentAbs.x, y: absPos.y - parentAbs.y })\n }\n\n ctx.graph.insertChildAt(nodeId, parentId, insertIndex)\n computeLayout(ctx.graph, parentId)\n ctx.runLayoutForNode(parentId)\n }\n\n function reorderInAutoLayout(nodeId: string, parentId: string, insertIndex: number) {\n // One undo step for the move, any slot it claims, and the group it leaves.\n ctx.undo.runBatch('Reorder', () => reorderInFlow(nodeId, parentId, insertIndex))\n }\n\n function reorderInFlow(nodeId: string, parentId: string, insertIndex: number) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent || parent.layoutMode === 'NONE') return\n\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n const origParentId = node.parentId ?? ctx.state.currentPageId\n const origX = node.x\n const origY = node.y\n const origIndex = ctx.graph.getNode(origParentId)?.childIds.indexOf(nodeId) ?? -1\n if (!prepareSlotEdits(ctx, [origParentId, parentId])) return\n\n doReorderChild(nodeId, parentId, insertIndex)\n\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n doReorderChild(nodeId, parentId, insertIndex)\n },\n inverse: () => {\n ctx.graph.insertChildAt(nodeId, origParentId, origIndex >= 0 ? origIndex : 0)\n ctx.graph.updateNode(nodeId, { x: origX, y: origY })\n computeLayout(ctx.graph, origParentId)\n ctx.runLayoutForNode(origParentId)\n if (origParentId !== parentId) {\n computeLayout(ctx.graph, parentId)\n ctx.runLayoutForNode(parentId)\n }\n }\n })\n fitEnclosingGroupsWithUndo(ctx, [origParentId])\n }\n\n /**\n * Moves a layer to `insertIndex` among `newParentId`'s children, counted without the layer. A\n * new parent keeps the layer where it is drawn, as moving it into a frame on the canvas does, and\n * is refused when it would put a component inside itself.\n */\n function reorderChildWithUndo(nodeId: string, newParentId: string, insertIndex: number) {\n // One undo step for the move, any slot it claims, and the groups it changes.\n ctx.undo.runBatch('Reorder', () => reorderChild(nodeId, newParentId, insertIndex))\n }\n\n function reorderChild(nodeId: string, newParentId: string, insertIndex: number) {\n assertNodeEditable(ctx.graph, nodeId)\n assertNodeEditable(ctx.graph, newParentId)\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n const origParentId = node.parentId ?? ctx.state.currentPageId\n const reparents = origParentId !== newParentId\n if (reparents && createsComponentCycle(ctx.graph, nodeId, newParentId)) return\n if (!prepareSlotEdits(ctx, [origParentId, newParentId])) return\n const origIndex = ctx.graph.getNode(origParentId)?.childIds.indexOf(nodeId) ?? 0\n const origPlace = pick(node, TRANSFORM_FIELDS)\n\n const place = () => {\n if (reparents) ctx.graph.reparentNode(nodeId, newParentId)\n ctx.graph.insertChildAt(nodeId, newParentId, insertIndex)\n ctx.runLayoutForNode(newParentId)\n if (reparents) ctx.runLayoutForNode(origParentId)\n }\n place()\n\n ctx.undo.push({\n label: 'Reorder',\n forward: place,\n inverse: () => {\n ctx.graph.insertChildAt(nodeId, origParentId, origIndex)\n ctx.graph.updateNode(nodeId, origPlace)\n ctx.runLayoutForNode(origParentId)\n if (reparents) ctx.runLayoutForNode(newParentId)\n }\n })\n // Groups the layer left or joined fit their layers; a stacking change can move a group's box\n // too, when a mask changes what it clips.\n fitEnclosingGroupsWithUndo(ctx, [origParentId, newParentId])\n }\n\n /**\n * Puts a frame's children in `childIds`. Only the children it moves need to be editable, so a\n * read-only library layer that keeps its place does not block reordering its siblings.\n */\n function applyChildOrder(parentId: string, childIds: readonly string[]) {\n assertNodeEditable(ctx.graph, parentId)\n const current = ctx.graph.getNode(parentId)?.childIds ?? []\n const moved = childIds.filter((childId, index) => current[index] !== childId)\n for (const childId of moved) assertNodeEditable(ctx.graph, childId)\n for (const [index, childId] of childIds.entries()) {\n if (ctx.graph.getNode(parentId)?.childIds[index] === childId) continue\n ctx.graph.insertChildAt(childId, parentId, index)\n }\n ctx.runLayoutForNode(parentId)\n ctx.requestRender()\n }\n\n /** Puts a frame's children in `order` as one undo step, laying the frame out once. */\n function setChildOrder(parentId: string, order: readonly string[], label = 'Reorder') {\n const before = ctx.graph.getNode(parentId)?.childIds\n if (!before || order.every((id, index) => id === before[index])) return\n // One undo step with any slot the new order claims.\n ctx.undo.runBatch(label, () => {\n if (!prepareSlotEdits(ctx, [parentId])) return\n const previous = [...before]\n const next = [...order]\n applyChildOrder(parentId, next)\n ctx.undo.push({\n label,\n forward: () => applyChildOrder(parentId, next),\n inverse: () => applyChildOrder(parentId, previous)\n })\n })\n }\n\n function moveSelectionInZOrder(\n label: string,\n reorder: (childIds: readonly string[], selectedIds: ReadonlySet<string>) => string[]\n ) {\n const selectedIds = ctx.state.selectedIds\n for (const id of selectedIds) assertNodeEditable(ctx.graph, id)\n const parentIds = new Set<string>()\n for (const id of selectedIds) {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (parentId) parentIds.add(parentId)\n }\n\n const before = new Map<string, string[]>()\n const after = new Map<string, string[]>()\n for (const parentId of parentIds) {\n const childIds = ctx.graph.getNode(parentId)?.childIds\n if (!childIds) continue\n const next = reorder(childIds, selectedIds)\n if (next.every((id, index) => id === childIds[index])) continue\n before.set(parentId, [...childIds])\n after.set(parentId, next)\n applyChildOrder(parentId, next)\n }\n if (after.size === 0) return\n\n ctx.undo.push({\n label,\n forward: () => {\n for (const [parentId, childIds] of after) applyChildOrder(parentId, childIds)\n },\n inverse: () => {\n for (const [parentId, childIds] of before) applyChildOrder(parentId, childIds)\n }\n })\n }\n\n function moveAdjacent(\n childIds: readonly string[],\n selectedIds: ReadonlySet<string>,\n direction: 'forward' | 'backward'\n ) {\n const result = [...childIds]\n const start = direction === 'forward' ? result.length - 2 : 1\n const end = direction === 'forward' ? -1 : result.length\n const step = direction === 'forward' ? -1 : 1\n for (let index = start; index !== end; index += step) {\n const neighborIndex = index - step\n const current = result[index]\n const neighbor = result[neighborIndex]\n if (current && neighbor && selectedIds.has(current) && !selectedIds.has(neighbor)) {\n result[index] = neighbor\n result[neighborIndex] = current\n }\n }\n return result\n }\n\n function bringForward() {\n moveSelectionInZOrder('Bring forward', (childIds, selectedIds) =>\n moveAdjacent(childIds, selectedIds, 'forward')\n )\n }\n\n function sendBackward() {\n moveSelectionInZOrder('Send backward', (childIds, selectedIds) =>\n moveAdjacent(childIds, selectedIds, 'backward')\n )\n }\n\n function bringToFront() {\n moveSelectionInZOrder('Bring to front', (childIds, selectedIds) => [\n ...childIds.filter((id) => !selectedIds.has(id)),\n ...childIds.filter((id) => selectedIds.has(id))\n ])\n }\n\n function sendToBack() {\n moveSelectionInZOrder('Send to back', (childIds, selectedIds) => [\n ...childIds.filter((id) => selectedIds.has(id)),\n ...childIds.filter((id) => !selectedIds.has(id))\n ])\n }\n\n return {\n reorderInAutoLayout,\n setChildOrder,\n reorderChildWithUndo,\n bringForward,\n sendBackward,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K,CAAC,YAAY,IAAI,QAAQ,GAAG;IACjF,OAAO,SAAS;IAChB,OAAO,iBAAiB;GAC1B;EACF;EACA,OAAO;CACT;CAEA,SAAS,eAAe;EACtB,sBAAsB,kBAAkB,UAAU,gBAChD,aAAa,UAAU,aAAa,SAAS,CAC/C;CACF;CAEA,SAAS,eAAe;EACtB,sBAAsB,kBAAkB,UAAU,gBAChD,aAAa,UAAU,aAAa,UAAU,CAChD;CACF;CAEA,SAAS,eAAe;EACtB,sBAAsB,mBAAmB,UAAU,gBAAgB,CACjE,GAAG,SAAS,QAAQ,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,GAC/C,GAAG,SAAS,QAAQ,OAAO,YAAY,IAAI,EAAE,CAAC,CAChD,CAAC;CACH;CAEA,SAAS,aAAa;EACpB,sBAAsB,iBAAiB,UAAU,gBAAgB,CAC/D,GAAG,SAAS,QAAQ,OAAO,YAAY,IAAI,EAAE,CAAC,GAC9C,GAAG,SAAS,QAAQ,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CACjD,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"reorder.js","names":[],"sources":["../../../src/editor/structure/reorder.ts"],"sourcesContent":["import { pick } from 'es-toolkit'\n\nimport { TRANSFORM_FIELDS } from '@pairdraw/scene-graph/fields'\nimport { createsComponentCycle } from '@pairdraw/scene-graph/instances'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport { prepareSlotEdits } from '#core/editor/components/slots'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\nexport function createStructureReorderActions(ctx: EditorContext) {\n function doReorderChild(nodeId: string, parentId: string, insertIndex: number) {\n assertNodeEditable(ctx.graph, nodeId)\n assertNodeEditable(ctx.graph, parentId)\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n\n if (node.parentId !== parentId) {\n const absPos = ctx.graph.getAbsolutePosition(nodeId)\n const parentAbs = ctx.graph.getAbsolutePosition(parentId)\n ctx.graph.updateNode(nodeId, { x: absPos.x - parentAbs.x, y: absPos.y - parentAbs.y })\n }\n\n ctx.graph.insertChildAt(nodeId, parentId, insertIndex)\n ctx.runLayoutForParents([parentId])\n }\n\n function reorderInAutoLayout(nodeId: string, parentId: string, insertIndex: number) {\n // One undo step for the move, any slot it claims, and the group it leaves.\n ctx.undo.runBatch('Reorder', () => reorderInFlow(nodeId, parentId, insertIndex))\n }\n\n function reorderInFlow(nodeId: string, parentId: string, insertIndex: number) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent || parent.layoutMode === 'NONE') return\n\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n const origParentId = node.parentId ?? ctx.state.currentPageId\n const origX = node.x\n const origY = node.y\n const origIndex = ctx.graph.getNode(origParentId)?.childIds.indexOf(nodeId) ?? -1\n if (!prepareSlotEdits(ctx, [origParentId, parentId])) return\n\n doReorderChild(nodeId, parentId, insertIndex)\n\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n doReorderChild(nodeId, parentId, insertIndex)\n },\n inverse: () => {\n ctx.graph.insertChildAt(nodeId, origParentId, origIndex >= 0 ? origIndex : 0)\n ctx.graph.updateNode(nodeId, { x: origX, y: origY })\n ctx.runLayoutForParents([origParentId, parentId])\n }\n })\n fitEnclosingGroupsWithUndo(ctx, [origParentId])\n }\n\n /**\n * Moves a layer to `insertIndex` among `newParentId`'s children, counted without the layer. A\n * new parent keeps the layer where it is drawn, as moving it into a frame on the canvas does, and\n * is refused when it would put a component inside itself.\n */\n function reorderChildWithUndo(nodeId: string, newParentId: string, insertIndex: number) {\n // One undo step for the move, any slot it claims, and the groups it changes.\n ctx.undo.runBatch('Reorder', () => reorderChild(nodeId, newParentId, insertIndex))\n }\n\n function reorderChild(nodeId: string, newParentId: string, insertIndex: number) {\n assertNodeEditable(ctx.graph, nodeId)\n assertNodeEditable(ctx.graph, newParentId)\n const node = ctx.graph.getNode(nodeId)\n if (!node) return\n const origParentId = node.parentId ?? ctx.state.currentPageId\n const reparents = origParentId !== newParentId\n if (reparents && createsComponentCycle(ctx.graph, nodeId, newParentId)) return\n if (!prepareSlotEdits(ctx, [origParentId, newParentId])) return\n const origIndex = ctx.graph.getNode(origParentId)?.childIds.indexOf(nodeId) ?? 0\n const origPlace = pick(node, TRANSFORM_FIELDS)\n\n const place = () => {\n if (reparents) ctx.graph.reparentNode(nodeId, newParentId)\n ctx.graph.insertChildAt(nodeId, newParentId, insertIndex)\n // A new parent can change what the layer inherits, such as its layout direction.\n if (reparents) ctx.runLayoutForNode(nodeId)\n ctx.runLayoutForParents([newParentId, origParentId])\n }\n place()\n\n ctx.undo.push({\n label: 'Reorder',\n forward: place,\n inverse: () => {\n ctx.graph.insertChildAt(nodeId, origParentId, origIndex)\n ctx.graph.updateNode(nodeId, origPlace)\n if (reparents) ctx.runLayoutForNode(nodeId)\n ctx.runLayoutForParents([origParentId, newParentId])\n }\n })\n // Groups the layer left or joined fit their layers; a stacking change can move a group's box\n // too, when a mask changes what it clips.\n fitEnclosingGroupsWithUndo(ctx, [origParentId, newParentId])\n }\n\n /**\n * Puts a frame's children in `childIds`. Only the children it moves need to be editable, so a\n * read-only library layer that keeps its place does not block reordering its siblings.\n */\n function applyChildOrder(parentId: string, childIds: readonly string[]) {\n assertNodeEditable(ctx.graph, parentId)\n const current = ctx.graph.getNode(parentId)?.childIds ?? []\n const moved = childIds.filter((childId, index) => current[index] !== childId)\n for (const childId of moved) assertNodeEditable(ctx.graph, childId)\n for (const [index, childId] of childIds.entries()) {\n if (ctx.graph.getNode(parentId)?.childIds[index] === childId) continue\n ctx.graph.insertChildAt(childId, parentId, index)\n }\n ctx.runLayoutForParents([parentId])\n ctx.requestRender()\n }\n\n /** Puts a frame's children in `order` as one undo step, laying the frame out once. */\n function setChildOrder(parentId: string, order: readonly string[], label = 'Reorder') {\n const before = ctx.graph.getNode(parentId)?.childIds\n if (!before || order.every((id, index) => id === before[index])) return\n // One undo step with any slot the new order claims.\n ctx.undo.runBatch(label, () => {\n if (!prepareSlotEdits(ctx, [parentId])) return\n const previous = [...before]\n const next = [...order]\n applyChildOrder(parentId, next)\n ctx.undo.push({\n label,\n forward: () => applyChildOrder(parentId, next),\n inverse: () => applyChildOrder(parentId, previous)\n })\n })\n }\n\n function moveSelectionInZOrder(\n label: string,\n reorder: (childIds: readonly string[], selectedIds: ReadonlySet<string>) => string[]\n ) {\n const selectedIds = ctx.state.selectedIds\n for (const id of selectedIds) assertNodeEditable(ctx.graph, id)\n const parentIds = new Set<string>()\n for (const id of selectedIds) {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (parentId) parentIds.add(parentId)\n }\n\n const before = new Map<string, string[]>()\n const after = new Map<string, string[]>()\n for (const parentId of parentIds) {\n const childIds = ctx.graph.getNode(parentId)?.childIds\n if (!childIds) continue\n const next = reorder(childIds, selectedIds)\n if (next.every((id, index) => id === childIds[index])) continue\n before.set(parentId, [...childIds])\n after.set(parentId, next)\n applyChildOrder(parentId, next)\n }\n if (after.size === 0) return\n\n ctx.undo.push({\n label,\n forward: () => {\n for (const [parentId, childIds] of after) applyChildOrder(parentId, childIds)\n },\n inverse: () => {\n for (const [parentId, childIds] of before) applyChildOrder(parentId, childIds)\n }\n })\n }\n\n function moveAdjacent(\n childIds: readonly string[],\n selectedIds: ReadonlySet<string>,\n direction: 'forward' | 'backward'\n ) {\n const result = [...childIds]\n const start = direction === 'forward' ? result.length - 2 : 1\n const end = direction === 'forward' ? -1 : result.length\n const step = direction === 'forward' ? -1 : 1\n for (let index = start; index !== end; index += step) {\n const neighborIndex = index - step\n const current = result[index]\n const neighbor = result[neighborIndex]\n if (current && neighbor && selectedIds.has(current) && !selectedIds.has(neighbor)) {\n result[index] = neighbor\n result[neighborIndex] = current\n }\n }\n return result\n }\n\n function bringForward() {\n moveSelectionInZOrder('Bring forward', (childIds, selectedIds) =>\n moveAdjacent(childIds, selectedIds, 'forward')\n )\n }\n\n function sendBackward() {\n moveSelectionInZOrder('Send backward', (childIds, selectedIds) =>\n moveAdjacent(childIds, selectedIds, 'backward')\n )\n }\n\n function bringToFront() {\n moveSelectionInZOrder('Bring to front', (childIds, selectedIds) => [\n ...childIds.filter((id) => !selectedIds.has(id)),\n ...childIds.filter((id) => selectedIds.has(id))\n ])\n }\n\n function sendToBack() {\n moveSelectionInZOrder('Send to back', (childIds, selectedIds) => [\n ...childIds.filter((id) => selectedIds.has(id)),\n ...childIds.filter((id) => !selectedIds.has(id))\n ])\n }\n\n return {\n reorderInAutoLayout,\n setChildOrder,\n reorderChildWithUndo,\n bringForward,\n sendBackward,\n bringToFront,\n sendToBack\n }\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,8BAA8B,KAAoB;CAChE,SAAS,eAAe,QAAgB,UAAkB,aAAqB;EAC7E,mBAAmB,IAAI,OAAO,MAAM;EACpC,mBAAmB,IAAI,OAAO,QAAQ;EACtC,MAAM,OAAO,IAAI,MAAM,QAAQ,MAAM;EACrC,IAAI,CAAC,MAAM;EAEX,IAAI,KAAK,aAAa,UAAU;GAC9B,MAAM,SAAS,IAAI,MAAM,oBAAoB,MAAM;GACnD,MAAM,YAAY,IAAI,MAAM,oBAAoB,QAAQ;GACxD,IAAI,MAAM,WAAW,QAAQ;IAAE,GAAG,OAAO,IAAI,UAAU;IAAG,GAAG,OAAO,IAAI,UAAU;GAAE,CAAC;EACvF;EAEA,IAAI,MAAM,cAAc,QAAQ,UAAU,WAAW;EACrD,IAAI,oBAAoB,CAAC,QAAQ,CAAC;CACpC;CAEA,SAAS,oBAAoB,QAAgB,UAAkB,aAAqB;EAElF,IAAI,KAAK,SAAS,iBAAiB,cAAc,QAAQ,UAAU,WAAW,CAAC;CACjF;CAEA,SAAS,cAAc,QAAgB,UAAkB,aAAqB;EAC5E,MAAM,SAAS,IAAI,MAAM,QAAQ,QAAQ;EACzC,IAAI,CAAC,UAAU,OAAO,eAAe,QAAQ;EAE7C,MAAM,OAAO,IAAI,MA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AG,QAAQ;EAC3B,MAAM,QAAQ,cAAc,YAAY,OAAO,SAAS,IAAI;EAC5D,MAAM,MAAM,cAAc,YAAY,KAAK,OAAO;EAClD,MAAM,OAAO,cAAc,YAAY,KAAK;EAC5C,KAAK,IAAI,QAAQ,OAAO,UAAU,KAAK,SAAS,MAAM;GACpD,MAAM,gBAAgB,QAAQ;GAC9B,MAAM,UAAU,OAAO;GACvB,MAAM,WAAW,OAAO;GACxB,IAAI,WAAW,YAAY,YAAY,IAAI,OAAO,KAAK,CAAC,YAAY,IAAI,QAAQ,GAAG;IACjF,OAAO,SAAS;IAChB,OAAO,iBAAiB;GAC1B;EACF;EACA,OAAO;CACT;CAEA,SAAS,eAAe;EACtB,sBAAsB,kBAAkB,UAAU,gBAChD,aAAa,UAAU,aAAa,SAAS,CAC/C;CACF;CAEA,SAAS,eAAe;EACtB,sBAAsB,kBAAkB,UAAU,gBAChD,aAAa,UAAU,aAAa,UAAU,CAChD;CACF;CAEA,SAAS,eAAe;EACtB,sBAAsB,mBAAmB,UAAU,gBAAgB,CACjE,GAAG,SAAS,QAAQ,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,GAC/C,GAAG,SAAS,QAAQ,OAAO,YAAY,IAAI,EAAE,CAAC,CAChD,CAAC;CACH;CAEA,SAAS,aAAa;EACpB,sBAAsB,iBAAiB,UAAU,gBAAgB,CAC/D,GAAG,SAAS,QAAQ,OAAO,YAAY,IAAI,EAAE,CAAC,GAC9C,GAAG,SAAS,QAAQ,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CACjD,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -17,7 +17,7 @@ function createStructureStateActions(ctx) {
17
17
  ctx.graph.updateNode(id, { visible: shown });
18
18
  const parentId = ctx.graph.getNode(id)?.parentId;
19
19
  if (!parentId) return;
20
- ctx.runLayoutForNode(parentId);
20
+ ctx.runLayoutForParents([parentId]);
21
21
  refitGroupsAroundLayers(ctx, [id]);
22
22
  };
23
23
  const forward = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","names":[],"sources":["../../../src/editor/structure/state.ts"],"sourcesContent":["import { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport {\n cloneInstanceOverrideState,\n setInstanceOverride\n} from '@pairdraw/scene-graph/instances/overrides'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport {\n applyBoundVisibilityEdit,\n bindsVisibility\n} from '#core/editor/components/authoring/visibility-edit'\nimport { refitGroupsAroundLayers } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\nexport function createStructureStateActions(ctx: EditorContext) {\n /** Shows or hides a layer; one a boolean property drives sets the property, as in Figma. */\n function applyNodeVisibility(id: string, visible: boolean) {\n const node = ctx.graph.getNode(id)\n if (!node) return\n const owner = findInstanceAncestor(ctx.graph, id)\n // The property takes the value even where the layer already shows it, so the two agree.\n if (owner && bindsVisibility(node) && applyBoundVisibilityEdit(ctx, id, visible)) return\n if (node.visible === visible) return\n const previousOverrides = owner && cloneInstanceOverrideState(owner.instanceOverrides)\n const show = (shown: boolean) => {\n ctx.graph.updateNode(id, { visible: shown })\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return\n ctx.runLayoutForNode(parentId)\n refitGroupsAroundLayers(ctx, [id])\n }\n const forward = () => {\n const instance = findInstanceAncestor(ctx.graph, id)\n if (instance)\n setInstanceOverride(instance.instanceOverrides, instance.id, id, 'visible', true)\n show(visible)\n }\n forward()\n ctx.undo.push({\n label: visible ? 'Show layer' : 'Hide layer',\n forward,\n inverse: () => {\n if (owner && previousOverrides)\n ctx.graph.updateNode(owner.id, {\n instanceOverrides: cloneInstanceOverrideState(previousOverrides)\n })\n show(!visible)\n }\n })\n }\n\n function setNodeVisibility(id: string, visible: boolean) {\n assertNodeEditable(ctx.graph, id)\n applyNodeVisibility(id, visible)\n }\n\n function toggleNodeVisibility(id: string) {\n assertNodeEditable(ctx.graph, id)\n const node = ctx.graph.getNode(id)\n if (node) applyNodeVisibility(id, !node.visible)\n }\n\n function toggleNodeLock(id: string) {\n assertNodeEditable(ctx.graph, id)\n const node = ctx.graph.getNode(id)\n if (!node) return\n const locked = !node.locked\n ctx.graph.updateNode(id, { locked })\n ctx.undo.push({\n label: locked ? 'Lock layer' : 'Unlock layer',\n forward: () => ctx.graph.updateNode(id, { locked }),\n inverse: () => ctx.graph.updateNode(id, { locked: !locked })\n })\n }\n\n function toggleVisibility() {\n for (const id of ctx.state.selectedIds) assertNodeEditable(ctx.graph, id)\n // Each layer takes the opposite of what it showed before any of them changed: layers a\n // property drives together would otherwise toggle it back and forth.\n const targets = [...ctx.state.selectedIds].flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [[id, !node.visible] as const] : []\n })\n ctx.undo.runBatch('Toggle visibility', () => {\n for (const [id, visible] of targets) applyNodeVisibility(id, visible)\n })\n }\n\n function toggleLock() {\n for (const id of ctx.state.selectedIds) assertNodeEditable(ctx.graph, id)\n ctx.undo.runBatch('Toggle lock', () => {\n for (const id of ctx.state.selectedIds) toggleNodeLock(id)\n })\n }\n\n return { setNodeVisibility, toggleNodeVisibility, toggleNodeLock, toggleVisibility, toggleLock }\n}\n"],"mappings":";;;;;;AAcA,SAAgB,4BAA4B,KAAoB;;CAE9D,SAAS,oBAAoB,IAAY,SAAkB;EACzD,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,CAAC,MAAM;EACX,MAAM,QAAQ,qBAAqB,IAAI,OAAO,EAAE;EAEhD,IAAI,SAAS,gBAAgB,IAAI,KAAK,yBAAyB,KAAK,IAAI,OAAO,GAAG;EAClF,IAAI,KAAK,YAAY,SAAS;EAC9B,MAAM,oBAAoB,SAAS,2BAA2B,MAAM,iBAAiB;EACrF,MAAM,QAAQ,UAAmB;GAC/B,IAAI,MAAM,WAAW,IAAI,EAAE,SAAS,MAAM,CAAC;GAC3C,MAAM,WAAW,IAAI,MAAM,QAAQ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,MAAM,UAAU,CAAC,GAAG,IAAI,MAAM,WAAW,CAAC,CAAC,SAAS,OAAO;GACzD,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,CAAU,IAAI,CAAC;EAClD,CAAC;EACD,IAAI,KAAK,SAAS,2BAA2B;GAC3C,KAAK,MAAM,CAAC,IAAI,YAAY,SAAS,oBAAoB,IAAI,OAAO;EACtE,CAAC;CACH;CAEA,SAAS,aAAa;EACpB,KAAK,MAAM,MAAM,IAAI,MAAM,aAAa,mBAAmB,IAAI,OAAO,EAAE;EACxE,IAAI,KAAK,SAAS,qBAAqB;GACrC,KAAK,MAAM,MAAM,IAAI,MAAM,aAAa,eAAe,EAAE;EAC3D,CAAC;CACH;CAEA,OAAO;EAAE;EAAmB;EAAsB;EAAgB;EAAkB;CAAW;AACjG"}
1
+ {"version":3,"file":"state.js","names":[],"sources":["../../../src/editor/structure/state.ts"],"sourcesContent":["import { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport {\n cloneInstanceOverrideState,\n setInstanceOverride\n} from '@pairdraw/scene-graph/instances/overrides'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport {\n applyBoundVisibilityEdit,\n bindsVisibility\n} from '#core/editor/components/authoring/visibility-edit'\nimport { refitGroupsAroundLayers } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\nexport function createStructureStateActions(ctx: EditorContext) {\n /** Shows or hides a layer; one a boolean property drives sets the property, as in Figma. */\n function applyNodeVisibility(id: string, visible: boolean) {\n const node = ctx.graph.getNode(id)\n if (!node) return\n const owner = findInstanceAncestor(ctx.graph, id)\n // The property takes the value even where the layer already shows it, so the two agree.\n if (owner && bindsVisibility(node) && applyBoundVisibilityEdit(ctx, id, visible)) return\n if (node.visible === visible) return\n const previousOverrides = owner && cloneInstanceOverrideState(owner.instanceOverrides)\n const show = (shown: boolean) => {\n ctx.graph.updateNode(id, { visible: shown })\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return\n ctx.runLayoutForParents([parentId])\n refitGroupsAroundLayers(ctx, [id])\n }\n const forward = () => {\n const instance = findInstanceAncestor(ctx.graph, id)\n if (instance)\n setInstanceOverride(instance.instanceOverrides, instance.id, id, 'visible', true)\n show(visible)\n }\n forward()\n ctx.undo.push({\n label: visible ? 'Show layer' : 'Hide layer',\n forward,\n inverse: () => {\n if (owner && previousOverrides)\n ctx.graph.updateNode(owner.id, {\n instanceOverrides: cloneInstanceOverrideState(previousOverrides)\n })\n show(!visible)\n }\n })\n }\n\n function setNodeVisibility(id: string, visible: boolean) {\n assertNodeEditable(ctx.graph, id)\n applyNodeVisibility(id, visible)\n }\n\n function toggleNodeVisibility(id: string) {\n assertNodeEditable(ctx.graph, id)\n const node = ctx.graph.getNode(id)\n if (node) applyNodeVisibility(id, !node.visible)\n }\n\n function toggleNodeLock(id: string) {\n assertNodeEditable(ctx.graph, id)\n const node = ctx.graph.getNode(id)\n if (!node) return\n const locked = !node.locked\n ctx.graph.updateNode(id, { locked })\n ctx.undo.push({\n label: locked ? 'Lock layer' : 'Unlock layer',\n forward: () => ctx.graph.updateNode(id, { locked }),\n inverse: () => ctx.graph.updateNode(id, { locked: !locked })\n })\n }\n\n function toggleVisibility() {\n for (const id of ctx.state.selectedIds) assertNodeEditable(ctx.graph, id)\n // Each layer takes the opposite of what it showed before any of them changed: layers a\n // property drives together would otherwise toggle it back and forth.\n const targets = [...ctx.state.selectedIds].flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [[id, !node.visible] as const] : []\n })\n ctx.undo.runBatch('Toggle visibility', () => {\n for (const [id, visible] of targets) applyNodeVisibility(id, visible)\n })\n }\n\n function toggleLock() {\n for (const id of ctx.state.selectedIds) assertNodeEditable(ctx.graph, id)\n ctx.undo.runBatch('Toggle lock', () => {\n for (const id of ctx.state.selectedIds) toggleNodeLock(id)\n })\n }\n\n return { setNodeVisibility, toggleNod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IAAI,CAAC,KAAK,OAAO;CACjD;CAEA,SAAS,eAAe,IAAY;EAClC,mBAAmB,IAAI,OAAO,EAAE;EAChC,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,CAAC,MAAM;EACX,MAAM,SAAS,CAAC,KAAK;EACrB,IAAI,MAAM,WAAW,IAAI,EAAE,OAAO,CAAC;EACnC,IAAI,KAAK,KAAK;GACZ,OAAO,SAAS,eAAe;GAC/B,eAAe,IAAI,MAAM,WAAW,IAAI,EAAE,OAAO,CAAC;GAClD,eAAe,IAAI,MAAM,WAAW,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC;EAC7D,CAAC;CACH;CAEA,SAAS,mBAAmB;EAC1B,KAAK,MAAM,MAAM,IAAI,MAAM,aAAa,mBAAmB,IAAI,OAAO,EAAE;EAGxE,MAAM,UAAU,CAAC,GAAG,IAAI,MAAM,WAAW,CAAC,CAAC,SAAS,OAAO;GACzD,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,CAAU,IAAI,CAAC;EAClD,CAAC;EACD,IAAI,KAAK,SAAS,2BAA2B;GAC3C,KAAK,MAAM,CAAC,IAAI,YAAY,SAAS,oBAAoB,IAAI,OAAO;EACtE,CAAC;CACH;CAEA,SAAS,aAAa;EACpB,KAAK,MAAM,MAAM,IAAI,MAAM,aAAa,mBAAmB,IAAI,OAAO,EAAE;EACxE,IAAI,KAAK,SAAS,qBAAqB;GACrC,KAAK,MAAM,MAAM,IAAI,MAAM,aAAa,eAAe,EAAE;EAC3D,CAAC;CACH;CAEA,OAAO;EAAE;EAAmB;EAAsB;EAAgB;EAAkB;CAAW;AACjG"}
@@ -2,8 +2,7 @@ import { EditorContext } from "./types.js";
2
2
  import { LayerType } from "./structure/layer-type.js";
3
3
  import { RenameSelectionOptions, RenameSelectionPreview } from "./structure/rename.js";
4
4
  import "./index.js";
5
- import { BooleanOperation } from "./structure/boolean.js";
6
- import { SceneNode } from "@pairdraw/scene-graph";
5
+ import { BooleanOperation, SceneNode } from "@pairdraw/scene-graph";
7
6
  //#region src/editor/structure.d.ts
8
7
  declare function createStructureActions(ctx: EditorContext): {
9
8
  moveToPage: (pageId: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"structure.d.ts","names":[],"sources":["../../src/editor/structure.ts"],"mappings":";;;;;;;iBA0BgB,uBAAuB,KAAK;EAgId,aAAA;EA+CY,wBAAA,SAAA,2BAAA;EAIP,iBAAA,SAAA;EA8BT,aAAA,YAAM;;;;;;EAvGmB,2BAAA,eAAA,aAAW,WAAa;EAIlC,kBAAA,cAAA;EAIC,kBAAA,eAAA;EAII,sBAAA,eAAA;EAME,wBAAA,eAAA;2CAAA;EA/Gd,gBAAA,mBAAQ;EAuBvB,2BAAA,kEAAiD,eACjD,aAAW,aACb,QAAQ;EAKkB,mBAAA,eAAA;EAIH,gBAAA,eAAA;EAoBD,eAAA,eAAA;EAmCE,iBAAA,eAAA;;;;;;;;EAjGT,aAAA;EA+NA,kBAAA;EACA,kBAAA;EACI,qBAAA,WAAA"}
1
+ {"version":3,"file":"structure.d.ts","names":[],"sources":["../../src/editor/structure.ts"],"mappings":";;;;;;iBAuBgB,uBAAuB,KAAK;EAgId,aAAA;EA+CY,wBAAA,SAAA,2BAAA;EAIP,iBAAA,SAAA;EA8BT,aAAA,YAAM;;;;;;EAvGmB,2BAAA,eAAA,aAAW,WAAa;EAIlC,kBAAA,cAAA;EAIC,kBAAA,eAAA;EAII,sBAAA,eAAA;EAME,wBAAA,eAAA;2CAAA;EA/Gd,gBAAA,mBAAQ;EAuBvB,2BAAA,kEAAiD,eACjD,aAAW,aACb,QAAQ;EAKkB,mBAAA,eAAA;EAIH,gBAAA,eAAA;EAoBD,eAAA,eAAA;EAmCE,iBAAA,eAAA;;;;;;;;EAjGT,aAAA;EA+NA,kBAAA;EACA,kBAAA;EACI,qBAAA,WAAA"}
@@ -128,11 +128,11 @@ function createStructureActions(ctx) {
128
128
  }];
129
129
  }).sort((a, b) => a.index - b.index);
130
130
  if (origins.length === 0) return;
131
- const parentIds = new Set(origins.map((origin) => origin.parentId));
131
+ const parentIds = origins.map((origin) => origin.parentId);
132
132
  const prevSelection = new Set(ctx.state.selectedIds);
133
133
  const move = () => {
134
134
  for (const { id } of origins) ctx.graph.reparentNode(id, pageId);
135
- for (const parentId of parentIds) ctx.runLayoutForNode(parentId);
135
+ ctx.runLayoutForParents(parentIds);
136
136
  ctx.setSelectedIds(/* @__PURE__ */ new Set());
137
137
  };
138
138
  move();
@@ -145,7 +145,7 @@ function createStructureActions(ctx) {
145
145
  ctx.graph.insertChildAt(id, parentId, index);
146
146
  ctx.graph.updateNode(id, place);
147
147
  }
148
- for (const parentId of parentIds) ctx.runLayoutForNode(parentId);
148
+ ctx.runLayoutForParents(parentIds);
149
149
  ctx.setSelectedIds(new Set(prevSelection));
150
150
  }
151
151
  });
@@ -1 +1 @@
1
- {"version":3,"file":"structure.js","names":["wrapSelectionInContainer","wrapSelectionInContainerImpl","wrapInAutoLayout","wrapInAutoLayoutImpl","booleanOperationSelected","booleanOperationSelectedImpl","ungroupSelected","flattenSelected","flattenSelectedImpl","outlineStrokeSelected","outlineStrokeSelectedImpl"],"sources":["../../src/editor/structure.ts"],"sourcesContent":["import { pick } from 'es-toolkit'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { TRANSFORM_FIELDS } from '@pairdraw/scene-graph/fields'\nimport { createsComponentCycle } from '@pairdraw/scene-graph/instances'\nimport { defaultNodeName } from '@pairdraw/scene-graph/node-defaults'\n\nimport { acceptingParent, acceptsChildren, prepareSlotEdits } from '#core/editor/components/slots'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\n\nimport { wrapInAutoLayout as wrapInAutoLayoutImpl } from './structure/auto-layout-wrap'\nimport {\n booleanOperationSelected as booleanOperationSelectedImpl,\n type BooleanOperation\n} from './structure/boolean'\nimport { wrapSelectionInContainer as wrapSelectionInContainerImpl } from './structure/container-wrap'\nimport { flattenSelected as flattenSelectedImpl } from './structure/flatten'\nimport { ungroupSelected as ungroupImpl } from './structure/group/ungroup'\nimport { createLayerTypeActions } from './structure/layer-type'\nimport { outlineStrokeSelected as outlineStrokeSelectedImpl } from './structure/outline-stroke'\nimport { previewRenamedNodes, type RenameSelectionOptions } from './structure/rename'\nimport { createStructureReorderActions } from './structure/reorder'\nimport { createStructureStateActions } from './structure/state'\nimport { namedByText } from './text/name'\nimport type { EditorContext } from './types'\n\nexport function createStructureActions(ctx: EditorContext) {\n const reorderActions = createStructureReorderActions(ctx)\n const stateActions = createStructureStateActions(ctx)\n const layerTypeActions = createLayerTypeActions(ctx)\n\n function isTopLevel(parentId: string | null): boolean {\n return !parentId || parentId === ctx.graph.rootId || parentId === ctx.state.currentPageId\n }\n\n /**\n * Moves layers under a new parent; refuses the locked part of an instance, and a layer that\n * would make a component contain itself, as Figma does.\n */\n function reparentNodes(nodeIds: string[], newParentId: string): boolean {\n const parent = ctx.graph.getNode(newParentId)\n // Sections only go into pages and other sections.\n const movable = nodeIds.filter(\n (id) =>\n (ctx.graph.getNode(id)?.type !== 'SECTION' ||\n !parent ||\n parent.type === 'CANVAS' ||\n parent.type === 'SECTION') &&\n !createsComponentCycle(ctx.graph, id, newParentId)\n )\n if (movable.length === 0) return true\n const parents = new Set([newParentId])\n for (const id of movable) {\n const current = ctx.graph.getNode(id)?.parentId\n if (current && current !== newParentId) parents.add(current)\n }\n if (!prepareSlotEdits(ctx, parents)) return false\n for (const id of movable) ctx.graph.reparentNode(id, newParentId)\n return true\n }\n\n function wrapSelectionInContainer(\n containerType: 'GROUP' | 'FRAME' | 'COMPONENT' | 'COMPONENT_SET',\n selectedNodes: SceneNode[],\n extraProps?: Partial<SceneNode>\n ) {\n return wrapSelectionInContainerImpl(ctx, containerType, selectedNodes, extraProps)\n }\n\n function wrapInAutoLayout(selectedNodes: SceneNode[]) {\n return wrapInAutoLayoutImpl(ctx, selectedNodes)\n }\n\n function groupSelected(selectedNodes: SceneNode[]) {\n return wrapSelectionInContainer('GROUP', selectedNodes)\n }\n\n /** How a mask toggles on one layer, as its own undo step. */\n function toggleMask(node: SceneNode): void {\n const next = !node.isMask\n const changes = { isMask: next }\n ctx.graph.updateNode(node.id, changes)\n ctx.undo.push({\n label: next ? 'Use as mask' : 'Remove mask',\n forward: () => ctx.graph.updateNode(node.id, changes),\n inverse: () => ctx.graph.updateNode(node.id, { isMask: !next })\n })\n }\n\n /**\n * Use as mask: one layer toggles its own mask; sibling layers are wrapped in a \"Mask group\"\n * whose bottom layer masks the layers above it, as Figma does. One undo step.\n */\n function maskSelected(selectedNodes: SceneNode[]): boolean {\n if (selectedNodes.length === 0) return false\n if (selectedNodes.length === 1) {\n toggleMask(selectedNodes[0])\n return true\n }\n const parentId = selectedNodes[0]?.parentId\n const parent = parentId ? ctx.graph.getNode(parentId) : undefined\n const selected = new Set(selectedNodes.map((node) => node.id))\n // The page's child order is the stack order, bottom first.\n const stack = parent ? parent.childIds.filter((id) => selected.has(id)) : []\n // Layers under different parents cannot share a group; the first one toggles, as before.\n if (stack.length !== selectedNodes.length) {\n toggleMask(selectedNodes[0])\n return true\n }\n const [bottomId] = stack\n const bottom = ctx.graph.getNode(bottomId)\n if (!bottom) return false\n // A mask already set on the bottom layer comes off, as the menu's Remove mask does.\n if (bottom.isMask) {\n toggleMask(bottom)\n return true\n }\n let grouped = false\n ctx.undo.runBatch('Use as mask', () => {\n const group = wrapSelectionInContainer('GROUP', selectedNodes, { name: 'Mask group' })\n if (!group) return\n grouped = true\n toggleMask(bottom)\n })\n return grouped\n }\n\n /** Figma frames a selection without a fill or clipping, unlike a drawn frame. */\n function frameSelection(selectedNodes: SceneNode[]) {\n return wrapSelectionInContainer('FRAME', selectedNodes)\n }\n\n function booleanOperationSelected(selectedNodes: SceneNode[], operation: BooleanOperation) {\n return booleanOperationSelectedImpl(ctx, selectedNodes, operation)\n }\n\n function ungroupSelected(selectedNode: SceneNode | undefined) {\n ungroupImpl(ctx, selectedNode)\n }\n\n function flattenSelected(selectedNodes: SceneNode[]) {\n return flattenSelectedImpl(ctx, selectedNodes)\n }\n\n function outlineTextSelected(selectedNodes: SceneNode[]) {\n if (selectedNodes.length === 0 || selectedNodes.some((node) => node.type !== 'TEXT'))\n return null\n return flattenSelectedImpl(ctx, selectedNodes, { label: 'Outline text' })\n }\n\n function outlineStrokeSelected(selectedNodes: SceneNode[]) {\n return outlineStrokeSelectedImpl(ctx, selectedNodes)\n }\n\n function moveToPage(pageId: string) {\n const targetPage = ctx.graph.getNode(pageId)\n if (targetPage?.type !== 'CANVAS') return\n // Where each layer was, read before any of them moves: put back in this order, each lands at\n // its own index again.\n const origins = [...ctx.state.selectedIds]\n .flatMap((id) => {\n const node = ctx.graph.getNode(id)\n const parent = node?.parentId ? ctx.graph.getNode(node.parentId) : undefined\n if (!node || !parent || parent.id === pageId) return []\n const index = parent.childIds.indexOf(id)\n return [{ id, parentId: parent.id, index, place: pick(node, TRANSFORM_FIELDS) }]\n })\n .sort((a, b) => a.index - b.index)\n if (origins.length === 0) return\n const parentIds = new Set(origins.map((origin) => origin.parentId))\n const prevSelection = new Set(ctx.state.selectedIds)\n const move = () => {\n for (const { id } of origins) ctx.graph.reparentNode(id, pageId)\n for (const parentId of parentIds) ctx.runLayoutForNode(parentId)\n ctx.setSelectedIds(new Set())\n }\n move()\n // Groups the layers left shrink to the rest, or go when empty, in the same undo step.\n ctx.undo.runBatch('Move to page', () => {\n ctx.undo.push({\n label: 'Move to page',\n forward: move,\n inverse: () => {\n for (const { id, parentId, index, place } of origins) {\n ctx.graph.insertChildAt(id, parentId, index)\n ctx.graph.updateNode(id, place)\n }\n for (const parentId of parentIds) ctx.runLayoutForNode(parentId)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n }\n\n function selectedNodes(): SceneNode[] {\n return [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((node): node is SceneNode => node != null)\n }\n\n function previewRenameSelected(options: RenameSelectionOptions) {\n return previewRenamedNodes(selectedNodes(), options)\n }\n\n function renameSelected(options: RenameSelectionOptions) {\n const nodes = selectedNodes()\n if (nodes.length === 0) return\n const preview = previewRenamedNodes(nodes, options)\n if (preview.error) return\n const before = new Map(\n nodes.map((node) => [node.id, { name: node.name, autoRename: node.autoRename }])\n )\n // A layer named by its text keeps the name it is given, as in Figma.\n const names = new Map(\n nodes.map((node) => [\n node.id,\n {\n name: preview.names.get(node.id) ?? node.name,\n autoRename: namedByText(node) ? false : node.autoRename\n }\n ])\n )\n const applyNames = (values: ReadonlyMap<string, { name: string; autoRename: boolean }>) => {\n for (const [id, next] of values) ctx.graph.updateNode(id, next)\n }\n\n applyNames(names)\n ctx.undo.push({\n label: 'Rename selection',\n forward: () => applyNames(names),\n inverse: () => applyNames(before)\n })\n }\n\n function renameNode(id: string, name: string) {\n const node = ctx.graph.getNode(id)\n if (!node) return\n const previous = { name: node.name, autoRename: node.autoRename }\n const next = name.trim() || defaultNodeName(node.type)\n if (next === previous.name) return\n // A layer named by its text, as a text layer or a sticky note is, keeps the name it is\n // given, as in Figma.\n const renamed = { name: next, autoRename: namedByText(node) ? false : node.autoRename }\n ctx.graph.updateNode(id, renamed)\n ctx.undo.push({\n label: 'Rename',\n forward: () => ctx.graph.updateNode(id, renamed),\n inverse: () => ctx.graph.updateNode(id, previous)\n })\n }\n\n return {\n isTopLevel,\n acceptsChildren: (parentId: string) => acceptsChildren(ctx, parentId),\n acceptingParent: (parentId: string) => acceptingParent(ctx, parentId),\n fitEnclosingGroups: (parentIds: Iterable<string>) => fitEnclosingGroupsWithUndo(ctx, parentIds),\n ...reorderActions,\n reparentNodes,\n wrapSelectionInContainer,\n wrapInAutoLayout,\n groupSelected,\n maskSelected,\n frameSelection,\n ...layerTypeActions,\n booleanOperationSelected,\n ungroupSelected,\n flattenSelected,\n outlineTextSelected,\n outlineStrokeSelected,\n ...stateActions,\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Ae,WAAW,KAAK;GAC/B,eAAe,WAAW,MAAM;EAClC,CAAC;CACH;CAEA,SAAS,WAAW,IAAY,MAAc;EAC5C,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,CAAC,MAAM;EACX,MAAM,WAAW;GAAE,MAAM,KAAK;GAAM,YAAY,KAAK;EAAW;EAChE,MAAM,OAAO,KAAK,KAAK,KAAK,gBAAgB,KAAK,IAAI;EACrD,IAAI,SAAS,SAAS,MAAM;EAG5B,MAAM,UAAU;GAAE,MAAM;GAAM,YAAY,YAAY,IAAI,IAAI,QAAQ,KAAK;EAAW;EACtF,IAAI,MAAM,WAAW,IAAI,OAAO;EAChC,IAAI,KAAK,KAAK;GACZ,OAAO;GACP,eAAe,IAAI,MAAM,WAAW,IAAI,OAAO;GAC/C,eAAe,IAAI,MAAM,WAAW,IAAI,QAAQ;EAClD,CAAC;CACH;CAEA,OAAO;EACL;EACA,kBAAkB,aAAqB,gBAAgB,KAAK,QAAQ;EACpE,kBAAkB,aAAqB,gBAAgB,KAAK,QAAQ;EACpE,qBAAqB,cAAgC,2BAA2B,KAAK,SAAS;EAC9F,GAAG;EACH;EACA,0BAAA;EACA,kBAAA;EACA;EACA;EACA;EACA,GAAG;EACH,0BAAA;EACA,iBAAA;EACA,iBAAA;EACA;EACA,uBAAA;EACA,GAAG;EACH;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"structure.js","names":["wrapSelectionInContainer","wrapSelectionInContainerImpl","wrapInAutoLayout","wrapInAutoLayoutImpl","booleanOperationSelected","booleanOperationSelectedImpl","ungroupSelected","flattenSelected","flattenSelectedImpl","outlineStrokeSelected","outlineStrokeSelectedImpl"],"sources":["../../src/editor/structure.ts"],"sourcesContent":["import { pick } from 'es-toolkit'\n\nimport type { BooleanOperation, SceneNode } from '@pairdraw/scene-graph'\nimport { TRANSFORM_FIELDS } from '@pairdraw/scene-graph/fields'\nimport { createsComponentCycle } from '@pairdraw/scene-graph/instances'\nimport { defaultNodeName } from '@pairdraw/scene-graph/node-defaults'\n\nimport { acceptingParent, acceptsChildren, prepareSlotEdits } from '#core/editor/components/slots'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\n\nimport { wrapInAutoLayout as wrapInAutoLayoutImpl } from './structure/auto-layout-wrap'\nimport { booleanOperationSelected as booleanOperationSelectedImpl } from './structure/boolean'\nimport { wrapSelectionInContainer as wrapSelectionInContainerImpl } from './structure/container-wrap'\nimport { flattenSelected as flattenSelectedImpl } from './structure/flatten'\nimport { ungroupSelected as ungroupImpl } from './structure/group/ungroup'\nimport { createLayerTypeActions } from './structure/layer-type'\nimport { outlineStrokeSelected as outlineStrokeSelectedImpl } from './structure/outline-stroke'\nimport { previewRenamedNodes, type RenameSelectionOptions } from './structure/rename'\nimport { createStructureReorderActions } from './structure/reorder'\nimport { createStructureStateActions } from './structure/state'\nimport { namedByText } from './text/name'\nimport type { EditorContext } from './types'\n\nexport function createStructureActions(ctx: EditorContext) {\n const reorderActions = createStructureReorderActions(ctx)\n const stateActions = createStructureStateActions(ctx)\n const layerTypeActions = createLayerTypeActions(ctx)\n\n function isTopLevel(parentId: string | null): boolean {\n return !parentId || parentId === ctx.graph.rootId || parentId === ctx.state.currentPageId\n }\n\n /**\n * Moves layers under a new parent; refuses the locked part of an instance, and a layer that\n * would make a component contain itself, as Figma does.\n */\n function reparentNodes(nodeIds: string[], newParentId: string): boolean {\n const parent = ctx.graph.getNode(newParentId)\n // Sections only go into pages and other sections.\n const movable = nodeIds.filter(\n (id) =>\n (ctx.graph.getNode(id)?.type !== 'SECTION' ||\n !parent ||\n parent.type === 'CANVAS' ||\n parent.type === 'SECTION') &&\n !createsComponentCycle(ctx.graph, id, newParentId)\n )\n if (movable.length === 0) return true\n const parents = new Set([newParentId])\n for (const id of movable) {\n const current = ctx.graph.getNode(id)?.parentId\n if (current && current !== newParentId) parents.add(current)\n }\n if (!prepareSlotEdits(ctx, parents)) return false\n for (const id of movable) ctx.graph.reparentNode(id, newParentId)\n return true\n }\n\n function wrapSelectionInContainer(\n containerType: 'GROUP' | 'FRAME' | 'COMPONENT' | 'COMPONENT_SET',\n selectedNodes: SceneNode[],\n extraProps?: Partial<SceneNode>\n ) {\n return wrapSelectionInContainerImpl(ctx, containerType, selectedNodes, extraProps)\n }\n\n function wrapInAutoLayout(selectedNodes: SceneNode[]) {\n return wrapInAutoLayoutImpl(ctx, selectedNodes)\n }\n\n function groupSelected(selectedNodes: SceneNode[]) {\n return wrapSelectionInContainer('GROUP', selectedNodes)\n }\n\n /** How a mask toggles on one layer, as its own undo step. */\n function toggleMask(node: SceneNode): void {\n const next = !node.isMask\n const changes = { isMask: next }\n ctx.graph.updateNode(node.id, changes)\n ctx.undo.push({\n label: next ? 'Use as mask' : 'Remove mask',\n forward: () => ctx.graph.updateNode(node.id, changes),\n inverse: () => ctx.graph.updateNode(node.id, { isMask: !next })\n })\n }\n\n /**\n * Use as mask: one layer toggles its own mask; sibling layers are wrapped in a \"Mask group\"\n * whose bottom layer masks the layers above it, as Figma does. One undo step.\n */\n function maskSelected(selectedNodes: SceneNode[]): boolean {\n if (selectedNodes.length === 0) return false\n if (selectedNodes.length === 1) {\n toggleMask(selectedNodes[0])\n return true\n }\n const parentId = selectedNodes[0]?.parentId\n const parent = parentId ? ctx.graph.getNode(parentId) : undefined\n const selected = new Set(selectedNodes.map((node) => node.id))\n // The page's child order is the stack order, bottom first.\n const stack = parent ? parent.childIds.filter((id) => selected.has(id)) : []\n // Layers under different parents cannot share a group; the first one toggles, as before.\n if (stack.length !== selectedNodes.length) {\n toggleMask(selectedNodes[0])\n return true\n }\n const [bottomId] = stack\n const bottom = ctx.graph.getNode(bottomId)\n if (!bottom) return false\n // A mask already set on the bottom layer comes off, as the menu's Remove mask does.\n if (bottom.isMask) {\n toggleMask(bottom)\n return true\n }\n let grouped = false\n ctx.undo.runBatch('Use as mask', () => {\n const group = wrapSelectionInContainer('GROUP', selectedNodes, { name: 'Mask group' })\n if (!group) return\n grouped = true\n toggleMask(bottom)\n })\n return grouped\n }\n\n /** Figma frames a selection without a fill or clipping, unlike a drawn frame. */\n function frameSelection(selectedNodes: SceneNode[]) {\n return wrapSelectionInContainer('FRAME', selectedNodes)\n }\n\n function booleanOperationSelected(selectedNodes: SceneNode[], operation: BooleanOperation) {\n return booleanOperationSelectedImpl(ctx, selectedNodes, operation)\n }\n\n function ungroupSelected(selectedNode: SceneNode | undefined) {\n ungroupImpl(ctx, selectedNode)\n }\n\n function flattenSelected(selectedNodes: SceneNode[]) {\n return flattenSelectedImpl(ctx, selectedNodes)\n }\n\n function outlineTextSelected(selectedNodes: SceneNode[]) {\n if (selectedNodes.length === 0 || selectedNodes.some((node) => node.type !== 'TEXT'))\n return null\n return flattenSelectedImpl(ctx, selectedNodes, { label: 'Outline text' })\n }\n\n function outlineStrokeSelected(selectedNodes: SceneNode[]) {\n return outlineStrokeSelectedImpl(ctx, selectedNodes)\n }\n\n function moveToPage(pageId: string) {\n const targetPage = ctx.graph.getNode(pageId)\n if (targetPage?.type !== 'CANVAS') return\n // Where each layer was, read before any of them moves: put back in this order, each lands at\n // its own index again.\n const origins = [...ctx.state.selectedIds]\n .flatMap((id) => {\n const node = ctx.graph.getNode(id)\n const parent = node?.parentId ? ctx.graph.getNode(node.parentId) : undefined\n if (!node || !parent || parent.id === pageId) return []\n const index = parent.childIds.indexOf(id)\n return [{ id, parentId: parent.id, index, place: pick(node, TRANSFORM_FIELDS) }]\n })\n .sort((a, b) => a.index - b.index)\n if (origins.length === 0) return\n const parentIds = origins.map((origin) => origin.parentId)\n const prevSelection = new Set(ctx.state.selectedIds)\n const move = () => {\n for (const { id } of origins) ctx.graph.reparentNode(id, pageId)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set())\n }\n move()\n // Groups the layers left shrink to the rest, or go when empty, in the same undo step.\n ctx.undo.runBatch('Move to page', () => {\n ctx.undo.push({\n label: 'Move to page',\n forward: move,\n inverse: () => {\n for (const { id, parentId, index, place } of origins) {\n ctx.graph.insertChildAt(id, parentId, index)\n ctx.graph.updateNode(id, place)\n }\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n }\n\n function selectedNodes(): SceneNode[] {\n return [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((node): node is SceneNode => node != null)\n }\n\n function previewRenameSelected(options: RenameSelectionOptions) {\n return previewRenamedNodes(selectedNodes(), options)\n }\n\n function renameSelected(options: RenameSelectionOptions) {\n const nodes = selectedNodes()\n if (nodes.length === 0) return\n const preview = previewRenamedNodes(nodes, options)\n if (preview.error) return\n const before = new Map(\n nodes.map((node) => [node.id, { name: node.name, autoRename: node.autoRename }])\n )\n // A layer named by its text keeps the name it is given, as in Figma.\n const names = new Map(\n nodes.map((node) => [\n node.id,\n {\n name: preview.names.get(node.id) ?? node.name,\n autoRename: namedByText(node) ? false : node.autoRename\n }\n ])\n )\n const applyNames = (values: ReadonlyMap<string, { name: string; autoRename: boolean }>) => {\n for (const [id, next] of values) ctx.graph.updateNode(id, next)\n }\n\n applyNames(names)\n ctx.undo.push({\n label: 'Rename selection',\n forward: () => applyNames(names),\n inverse: () => applyNames(before)\n })\n }\n\n function renameNode(id: string, name: string) {\n const node = ctx.graph.getNode(id)\n if (!node) return\n const previous = { name: node.name, autoRename: node.autoRename }\n const next = name.trim() || defaultNodeName(node.type)\n if (next === previous.name) return\n // A layer named by its text, as a text layer or a sticky note is, keeps the name it is\n // given, as in Figma.\n const renamed = { name: next, autoRename: namedByText(node) ? false : node.autoRename }\n ctx.graph.updateNode(id, renamed)\n ctx.undo.push({\n label: 'Rename',\n forward: () => ctx.graph.updateNode(id, renamed),\n inverse: () => ctx.graph.updateNode(id, previous)\n })\n }\n\n return {\n isTopLevel,\n acceptsChildren: (parentId: string) => acceptsChildren(ctx, parentId),\n acceptingParent: (parentId: string) => acceptingParent(ctx, parentId),\n fitEnclosingGroups: (parentIds: Iterable<string>) => fitEnclosingGroupsWithUndo(ctx, parentIds),\n ...reorderActions,\n reparentNodes,\n wrapSelectionInContainer,\n wrapInAutoLayout,\n groupSelected,\n maskSelected,\n frameSelection,\n ...layerTypeActions,\n booleanOperationSelected,\n ungroupSelected,\n flattenSelected,\n outlineTextSelected,\n outlineStrokeSelected,\n ...stateActions,\n moveToPage,\n previewRenameSelected,\n renameSelected,\n renameNode\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,uBAAuB,KAAoB;CACzD,MAAM,iBAAiB,8BAA8B,GAAG;CACxD,MAAM,eAAe,4BAA4B,GAAG;CACpD,MAAM,mBAAmB,uBAAuB,GAAG;CAEnD,SAAS,WAAW,UAAkC;EACpD,OAAO,CAAC,YAAY,aAAa,IAAI,MAAM,UAAU,aAAa,IAAI,MAAM;CAC9E;;;;;CAMA,SAAS,cAAc,SAAmB,aAA8B;EACtE,MAAM,SAAS,IAAI,MAAM,QAAQ,WAAW;EAE5C,MAAM,UAAU,QAAQ,QACrB,QACE,IAAI,MAAM,QAAQ,EAAE,CAAC,EAAE,SAAS,aAC/B,CAAC,UACD,OAAO,SAAS,YAChB,OAAO,SAAS,cAClB,CAAC,sBAAsB,IAAI,OAAO,IAAI,WAAW,CACrD;EACA,IAAI,QAAQ,WAAW,GAAG,OAAO;EACjC,MAAM,0BAAU,IAAI,IAAI,CAAC,WAAW,CAAC;EACrC,KAAK,MAAM,MAAM,SAAS;GACxB,MAAM,UAAU,IAAI,MAAM,QAAQ,EAAE,CAAC,EAAE;GACvC,IAAI,WAAW,YAAY,aAAa,QAAQ,IAAI,OAAO;EAC7D;EACA,IAAI,CAAC,iBAAiB,KAAK,OAAO,GAAG,OAAO;EAC5C,KAAK,MAAM,MAAM,SAAS,IAAI,MAAM,aAAa,IAAI,WAAW;EAChE,OAAO;CACT;CAEA,SAASA,2BACP,eACA,eACA,YACA;EACA,OAAOC,yBAA6B,KAAK,eAAe,eAAe,UAAU;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AAM,cAAc,WAAuE;GACzF,KAAK,MAAM,CAAC,IAAI,SAAS,QAAQ,IAAI,MAAM,WAAW,IAAI,IAAI;EAChE;EAEA,WAAW,KAAK;EAChB,IAAI,KAAK,KAAK;GACZ,OAAO;GACP,eAAe,WAAW,KAAK;GAC/B,eAAe,WAAW,MAAM;EAClC,CAAC;CACH;CAEA,SAAS,WAAW,IAAY,MAAc;EAC5C,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,CAAC,MAAM;EACX,MAAM,WAAW;GAAE,MAAM,KAAK;GAAM,YAAY,KAAK;EAAW;EAChE,MAAM,OAAO,KAAK,KAAK,KAAK,gBAAgB,KAAK,IAAI;EACrD,IAAI,SAAS,SAAS,MAAM;EAG5B,MAAM,UAAU;GAAE,MAAM;GAAM,YAAY,YAAY,IAAI,IAAI,QAAQ,KAAK;EAAW;EACtF,IAAI,MAAM,WAAW,IAAI,OAAO;EAChC,IAAI,KAAK,KAAK;GACZ,OAAO;GACP,eAAe,IAAI,MAAM,WAAW,IAAI,OAAO;GAC/C,eAAe,IAAI,MAAM,WAAW,IAAI,QAAQ;EAClD,CAAC;CACH;CAEA,OAAO;EACL;EACA,kBAAkB,aAAqB,gBAAgB,KAAK,QAAQ;EACpE,kBAAkB,aAAqB,gBAAgB,KAAK,QAAQ;EACpE,qBAAqB,cAAgC,2BAA2B,KAAK,SAAS;EAC9F,GAAG;EACH;EACA,0BAAA;EACA,kBAAA;EACA;EACA;EACA;EACA,GAAG;EACH,0BAAA;EACA,iBAAA;EACA,iBAAA;EACA;EACA,uBAAA;EACA,GAAG;EACH;EACA;EACA;EACA;CACF;AACF"}
@@ -17,7 +17,7 @@ import { CanvasKit } from "canvaskit-wasm";
17
17
  import { DocumentColorSpace, DocumentKind, SceneGraph, SceneGraphEvents, SceneNode, VectorNetwork, VectorSegment, VectorVertex } from "@pairdraw/scene-graph";
18
18
  import { ShapeWithTextType } from "@pairdraw/scene-graph/shape-with-text";
19
19
  import { CanvasGuide } from "@pairdraw/scene-graph/guides";
20
- import { UndoManager } from "@pairdraw/scene-graph/undo";
20
+ import { UndoEntry, UndoManager } from "@pairdraw/scene-graph/undo";
21
21
  import { SceneMutationImpact } from "@pairdraw/scene-graph/mutation-impact";
22
22
  import { Color as Color$1, Rect, Vector } from "@pairdraw/scene-graph/primitives";
23
23
  import { SnapGuide } from "@pairdraw/scene-graph/snap";
@@ -269,6 +269,8 @@ interface EditorContext {
269
269
  get graph(): SceneGraph;
270
270
  set graph(g: SceneGraph);
271
271
  undo: UndoManager;
272
+ /** Adds a step to the history of a graph that is not the open one, kept aside with it. */
273
+ parkStep: (graph: SceneGraph, entry: UndoEntry) => void;
272
274
  state: EditorState;
273
275
  loadFont: (family: string, style: string, characters?: string, signal?: AbortSignal) => Promise<ArrayBuffer | null>;
274
276
  resolveFigmaClipboardImages: FigmaClipboardImageResolver | null;
@@ -295,6 +297,7 @@ interface EditorContext {
295
297
  setActiveTool: (tool: Tool) => void;
296
298
  setNavigationPhase: (phase: NavigationPhase, inputAt?: number) => void;
297
299
  runLayoutForNode: (id: string) => void;
300
+ runLayoutForParents: (parentIds: Iterable<string>) => void;
298
301
  runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string,
299
302
  /** Runs once the operation is done and before layout, with the layers it touched. */
300
303
  beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void) => Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/editor/types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;KAsCY;;;;;;UAuBK;EACf;EACA;EACA;;EAEA;;;UAIe;EACf;;EAEA;;;UAIe;EACf;;EAEA;;EAEA,QAAQ;;EAER;;EAEA,SAAS;;UAGM;EACf,YAAY;;EAEZ,mBAAmB;;;;;;EAMnB,cAAc;EACd,kBAAkB;EAClB,qBAAqB;;EAErB;;EAEA,eAAe;;EAEf,YAAY;EACZ,iBAAiB;EACjB;;EAEA,sBAAs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,gBAAA,eAAM;;;;EAgBH,mBAAA,YAAM;EAqBD,gBAAA,YAAA;EAgBL,mBAAA;EAyBC,cAAA,UAAA;EAgBH,iBAAA;EAkFA,iBAAA,YAAM;EAoK5B,sBAAA,YAAM,gBACI,OACP,eAAa;EAjJS,UAAA,sBAAM;EAqBH,aAAA,sBAAM;EA0CN,aAAA,sBAAM,gBAAgB;EAqBlB,iBAAA,sBAAM;EA0BP,gBAAA,sBAAM;EAuBN,gBAAA,sBAAM"}
1
+ {"version":3,"file":"variables.d.ts","names":[],"sources":["../../src/editor/variables.ts"],"mappings":";;;;;KA0BY,sBAAsB,KAChC;iBA0Cc,sBAAsB,KAAK;EAQR,mBAAA,OAAA;EAsdA,sBAAA,YAAM,OAAS,QAAQ;EA8BhB,mBAAA,sBAAM,gBAAgB;EAxP/B,oBAAA,YAAM;EAtBG,mBAAA,sBAAM;EAySN,mBAAA,sBAAM;EA9fZ,qBAAA,MAAA,iBAAY;EAIrB,cAAA,eAAM;EAIG,uBAAA,0DAAM;EAIL,wBAAA;EAIc,4BAAA,yBAAM;EAI5B,gBAAA,eAAM;;;;EAgBH,mBAAA,YAAM;EAqBD,gBAAA,YAAA;EAgBL,mBAAA;EA0CC,cAAA,UAAA;EA8DH,iBAAA;EAqFA,iBAAA,YAAM;EAoK5B,sBAAA,YAAM,gBACI,OACP,eAAa;EAjJS,UAAA,sBAAM;EAqBH,aAAA,sBAAM;EA0CN,aAAA,sBAAM,gBAAgB;EAqBlB,iBAAA,sBAAM;EA0BP,gBAAA,sBAAM;EAuBN,gBAAA,sBAAM"}
@@ -1,10 +1,12 @@
1
1
  import { reconcileVariableLayouts } from "../layout/variables.js";
2
2
  import { loadBoundFonts } from "./text/bound-fonts.js";
3
3
  import { loadBoundIcons } from "./icons.js";
4
- import { tokenExpressionForValue } from "@pairdraw/scene-graph/variables";
4
+ import { tokenExpressionForValue, variableBindingOwner } from "@pairdraw/scene-graph/variables";
5
5
  import { isModeAttributeName } from "@pairdraw/scene-graph";
6
6
  import { isEmptyObject } from "es-toolkit/predicate";
7
7
  import { omit, omitBy } from "es-toolkit/object";
8
+ import { findInstanceAncestor } from "@pairdraw/scene-graph/instances";
9
+ import { cloneInstanceOverrideState } from "@pairdraw/scene-graph/instances/overrides";
8
10
  //#region src/editor/variables.ts
9
11
  /** Every token field, unset ones included, so restoring it also clears what was added. */
10
12
  function tokenFields(variable) {
@@ -127,6 +129,10 @@ function createVariableActions(ctx) {
127
129
  const snapshot = structuredClone(collection);
128
130
  const scope = { variables: snapshot.variableIds };
129
131
  const variables = snapshot.variableIds.map((vid) => ctx.graph.variables.get(vid)).filter((v) => v != null).map((v) => structuredClone(v));
132
+ const bindings = bindingSnapshots(snapshot.variableIds);
133
+ const activeMode = ctx.graph.activeMode.get(id);
134
+ const modeChoices = /* @__PURE__ */ new Map();
135
+ for (const node of ctx.graph.getAllNodes()) if (Object.hasOwn(node.variableModes, id)) modeChoices.set(node.id, node.variableModes[id]);
130
136
  ctx.graph.removeCollection(id);
131
137
  ctx.undo.push({
132
138
  label: "Remove collection",
@@ -137,6 +143,16 @@ function createVariableActions(ctx) {
137
143
  inverse: () => {
138
144
  ctx.graph.addCollection(snapshot);
139
145
  for (const v of variables) ctx.graph.addVariable(v);
146
+ if (activeMode !== void 0) ctx.graph.setActiveMode(id, activeMode);
147
+ for (const [nodeId, modeId] of modeChoices) {
148
+ const node = ctx.graph.getNode(nodeId);
149
+ if (!node) continue;
150
+ ctx.graph.updateNode(nodeId, { variableModes: {
151
+ ...node.variableModes,
152
+ [id]: modeId
153
+ } });
154
+ }
155
+ restoreBindings(bindings);
140
156
  refreshVariables(scope);
141
157
  }
142
158
  });
@@ -157,11 +173,50 @@ function createVariableActions(ctx) {
157
173
  });
158
174
  ctx.requestRefresh();
159
175
  }
176
+ /**
177
+ * The bindings removing these variables strips from layers, and the instance overrides it
178
+ * records, so undo can put both back. A layer keeps the value its variable last gave it.
179
+ */
180
+ function bindingSnapshots(ids) {
181
+ const removed = new Set(ids);
182
+ const snapshots = [];
183
+ for (const node of ctx.graph.getAllNodes()) {
184
+ const entries = Object.entries(node.boundVariables).filter(([, id]) => removed.has(id));
185
+ if (entries.length === 0) continue;
186
+ const owner = variableBindingOwner(ctx.graph, node);
187
+ const nearest = findInstanceAncestor(ctx.graph, node.id);
188
+ snapshots.push({
189
+ nodeId: node.id,
190
+ boundVariables: Object.fromEntries(entries),
191
+ variableBindingScales: Object.fromEntries(entries.map(([field]) => field).filter((field) => field in node.variableBindingScales).map((field) => [field, node.variableBindingScales[field]])),
192
+ owners: new Map([owner, ...nearest ? [nearest] : []].map((item) => [item.id, cloneInstanceOverrideState(item.instanceOverrides)]))
193
+ });
194
+ }
195
+ return snapshots;
196
+ }
197
+ function restoreBindings(snapshots) {
198
+ for (const snapshot of snapshots) {
199
+ for (const [ownerId, state] of snapshot.owners) ctx.graph.updateNode(ownerId, { instanceOverrides: cloneInstanceOverrideState(state) });
200
+ const node = ctx.graph.getNode(snapshot.nodeId);
201
+ if (!node) continue;
202
+ ctx.graph.updateNode(snapshot.nodeId, {
203
+ boundVariables: {
204
+ ...node.boundVariables,
205
+ ...snapshot.boundVariables
206
+ },
207
+ variableBindingScales: {
208
+ ...node.variableBindingScales,
209
+ ...snapshot.variableBindingScales
210
+ }
211
+ });
212
+ }
213
+ }
160
214
  function removeVariable(id) {
161
215
  const variable = ctx.graph.variables.get(id);
162
216
  if (!variable) return;
163
217
  const snapshot = structuredClone(variable);
164
218
  const order = [...ctx.graph.variableCollections.get(variable.collectionId)?.variableIds ?? []];
219
+ const bindings = bindingSnapshots([id]);
165
220
  ctx.graph.removeVariable(id);
166
221
  ctx.undo.push({
167
222
  label: "Remove variable",
@@ -172,6 +227,7 @@ function createVariableActions(ctx) {
172
227
  inverse: () => {
173
228
  ctx.graph.addVariable(structuredClone(snapshot));
174
229
  placeVariables(snapshot.collectionId, order);
230
+ restoreBindings(bindings);
175
231
  refreshVariables({ variables: [id] });
176
232
  }
177
233
  });