@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.6

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 (345) hide show
  1. package/dist/buffered-events.js +1 -1
  2. package/dist/buffered-events.js.map +1 -1
  3. package/dist/clipping.d.ts +7 -1
  4. package/dist/clipping.d.ts.map +1 -1
  5. package/dist/clipping.js +23 -19
  6. package/dist/clipping.js.map +1 -1
  7. package/dist/comments/schema.d.ts.map +1 -1
  8. package/dist/comments/schema.js +1 -0
  9. package/dist/comments/schema.js.map +1 -1
  10. package/dist/comments/threads.d.ts +2 -0
  11. package/dist/comments/threads.d.ts.map +1 -1
  12. package/dist/comments/threads.js +11 -5
  13. package/dist/comments/threads.js.map +1 -1
  14. package/dist/components/index.d.ts +2 -2
  15. package/dist/components/index.js +2 -2
  16. package/dist/components/properties.d.ts +1 -3
  17. package/dist/components/properties.d.ts.map +1 -1
  18. package/dist/components/properties.js +3 -10
  19. package/dist/components/properties.js.map +1 -1
  20. package/dist/constants.d.ts +12 -2
  21. package/dist/constants.d.ts.map +1 -1
  22. package/dist/constants.js +42 -1
  23. package/dist/constants.js.map +1 -1
  24. package/dist/copy.d.ts.map +1 -1
  25. package/dist/copy.js +2 -0
  26. package/dist/copy.js.map +1 -1
  27. package/dist/corners.d.ts +22 -0
  28. package/dist/corners.d.ts.map +1 -0
  29. package/dist/corners.js +52 -0
  30. package/dist/corners.js.map +1 -0
  31. package/dist/css/grid.d.ts +4 -1
  32. package/dist/css/grid.d.ts.map +1 -1
  33. package/dist/css/grid.js +40 -7
  34. package/dist/css/grid.js.map +1 -1
  35. package/dist/css/index.d.ts +3 -3
  36. package/dist/css/index.js +3 -3
  37. package/dist/css/layout.d.ts +13 -1
  38. package/dist/css/layout.d.ts.map +1 -1
  39. package/dist/css/layout.js +26 -1
  40. package/dist/css/layout.js.map +1 -1
  41. package/dist/css/values.d.ts +23 -1
  42. package/dist/css/values.d.ts.map +1 -1
  43. package/dist/css/values.js +39 -1
  44. package/dist/css/values.js.map +1 -1
  45. package/dist/font-style.d.ts +2 -1
  46. package/dist/font-style.d.ts.map +1 -1
  47. package/dist/font-style.js +31 -6
  48. package/dist/font-style.js.map +1 -1
  49. package/dist/geometry.d.ts +68 -3
  50. package/dist/geometry.d.ts.map +1 -1
  51. package/dist/geometry.js +159 -25
  52. package/dist/geometry.js.map +1 -1
  53. package/dist/gradient.d.ts +9 -2
  54. package/dist/gradient.d.ts.map +1 -1
  55. package/dist/gradient.js +29 -1
  56. package/dist/gradient.js.map +1 -1
  57. package/dist/graph.d.ts +9 -2
  58. package/dist/graph.d.ts.map +1 -1
  59. package/dist/graph.js +46 -10
  60. package/dist/graph.js.map +1 -1
  61. package/dist/group-bounds.d.ts.map +1 -1
  62. package/dist/group-bounds.js +4 -3
  63. package/dist/group-bounds.js.map +1 -1
  64. package/dist/guides.d.ts +11 -2
  65. package/dist/guides.d.ts.map +1 -1
  66. package/dist/guides.js +30 -1
  67. package/dist/guides.js.map +1 -1
  68. package/dist/hit-test.d.ts.map +1 -1
  69. package/dist/hit-test.js +57 -5
  70. package/dist/hit-test.js.map +1 -1
  71. package/dist/icons/fit.d.ts +17 -0
  72. package/dist/icons/fit.d.ts.map +1 -0
  73. package/dist/icons/fit.js +21 -0
  74. package/dist/icons/fit.js.map +1 -0
  75. package/dist/icons/glyph.d.ts.map +1 -1
  76. package/dist/icons/glyph.js +5 -4
  77. package/dist/icons/glyph.js.map +1 -1
  78. package/dist/icons/index.d.ts +2 -1
  79. package/dist/icons/index.js +2 -1
  80. package/dist/ids.js +1 -1
  81. package/dist/ids.js.map +1 -1
  82. package/dist/images.d.ts +14 -4
  83. package/dist/images.d.ts.map +1 -1
  84. package/dist/images.js +45 -5
  85. package/dist/images.js.map +1 -1
  86. package/dist/index.d.ts +2 -2
  87. package/dist/instances/assignments.js +39 -6
  88. package/dist/instances/assignments.js.map +1 -1
  89. package/dist/instances/index.d.ts +6 -1
  90. package/dist/instances/index.d.ts.map +1 -1
  91. package/dist/instances/index.js +58 -9
  92. package/dist/instances/index.js.map +1 -1
  93. package/dist/instances/kept-overrides.js +2 -2
  94. package/dist/instances/kept-overrides.js.map +1 -1
  95. package/dist/instances/matching.js +68 -0
  96. package/dist/instances/matching.js.map +1 -0
  97. package/dist/instances/overrides.d.ts +4 -1
  98. package/dist/instances/overrides.d.ts.map +1 -1
  99. package/dist/instances/overrides.js +13 -1
  100. package/dist/instances/overrides.js.map +1 -1
  101. package/dist/instances/protection.js +67 -0
  102. package/dist/instances/protection.js.map +1 -0
  103. package/dist/instances/swap.js +7 -5
  104. package/dist/instances/swap.js.map +1 -1
  105. package/dist/instances/sync.js +34 -116
  106. package/dist/instances/sync.js.map +1 -1
  107. package/dist/layout/guides.d.ts +17 -1
  108. package/dist/layout/guides.d.ts.map +1 -1
  109. package/dist/layout/guides.js +31 -11
  110. package/dist/layout/guides.js.map +1 -1
  111. package/dist/layout/index.d.ts +5 -2
  112. package/dist/layout/index.js +5 -2
  113. package/dist/layout/limits.d.ts +40 -0
  114. package/dist/layout/limits.d.ts.map +1 -0
  115. package/dist/layout/limits.js +54 -0
  116. package/dist/layout/limits.js.map +1 -0
  117. package/dist/layout/sizing.d.ts.map +1 -1
  118. package/dist/layout/sizing.js +0 -1
  119. package/dist/layout/sizing.js.map +1 -1
  120. package/dist/layout/spacing.d.ts +10 -0
  121. package/dist/layout/spacing.d.ts.map +1 -0
  122. package/dist/layout/spacing.js +12 -0
  123. package/dist/layout/spacing.js.map +1 -0
  124. package/dist/layout/strokes.d.ts +10 -0
  125. package/dist/layout/strokes.d.ts.map +1 -0
  126. package/dist/layout/strokes.js +30 -0
  127. package/dist/layout/strokes.js.map +1 -0
  128. package/dist/masks.d.ts +28 -0
  129. package/dist/masks.d.ts.map +1 -0
  130. package/dist/masks.js +53 -0
  131. package/dist/masks.js.map +1 -0
  132. package/dist/matrix.d.ts +2 -1
  133. package/dist/matrix.d.ts.map +1 -1
  134. package/dist/matrix.js +14 -1
  135. package/dist/matrix.js.map +1 -1
  136. package/dist/node-defaults.d.ts +9 -1
  137. package/dist/node-defaults.d.ts.map +1 -1
  138. package/dist/node-defaults.js +65 -38
  139. package/dist/node-defaults.js.map +1 -1
  140. package/dist/outline/flatten.d.ts.map +1 -1
  141. package/dist/outline/flatten.js +24 -17
  142. package/dist/outline/flatten.js.map +1 -1
  143. package/dist/outline/hit.d.ts +2 -8
  144. package/dist/outline/hit.d.ts.map +1 -1
  145. package/dist/outline/hit.js +16 -25
  146. package/dist/outline/hit.js.map +1 -1
  147. package/dist/outline/index.d.ts +3 -3
  148. package/dist/outline/index.js +3 -3
  149. package/dist/outline/shapes.d.ts +3 -1
  150. package/dist/outline/shapes.d.ts.map +1 -1
  151. package/dist/outline/shapes.js +18 -39
  152. package/dist/outline/shapes.js.map +1 -1
  153. package/dist/paints/index.d.ts +3 -1
  154. package/dist/paints/index.js +3 -1
  155. package/dist/paints/pattern.d.ts +13 -0
  156. package/dist/paints/pattern.d.ts.map +1 -0
  157. package/dist/paints/pattern.js +47 -0
  158. package/dist/paints/pattern.js.map +1 -0
  159. package/dist/paints/shows.d.ts +11 -0
  160. package/dist/paints/shows.d.ts.map +1 -0
  161. package/dist/paints/shows.js +16 -0
  162. package/dist/paints/shows.js.map +1 -0
  163. package/dist/parse-path.d.ts +4 -1
  164. package/dist/parse-path.d.ts.map +1 -1
  165. package/dist/parse-path.js +15 -1
  166. package/dist/parse-path.js.map +1 -1
  167. package/dist/paths/arc.d.ts +32 -0
  168. package/dist/paths/arc.d.ts.map +1 -0
  169. package/dist/paths/arc.js +49 -0
  170. package/dist/paths/arc.js.map +1 -0
  171. package/dist/paths/index.d.ts +5 -0
  172. package/dist/paths/index.js +5 -0
  173. package/dist/paths/network.d.ts +63 -0
  174. package/dist/paths/network.d.ts.map +1 -0
  175. package/dist/paths/network.js +315 -0
  176. package/dist/paths/network.js.map +1 -0
  177. package/dist/paths/sink.d.ts +20 -0
  178. package/dist/paths/sink.d.ts.map +1 -0
  179. package/dist/paths/sink.js +32 -0
  180. package/dist/paths/sink.js.map +1 -0
  181. package/dist/paths/smooth-corners.d.ts +25 -0
  182. package/dist/paths/smooth-corners.d.ts.map +1 -0
  183. package/dist/paths/smooth-corners.js +196 -0
  184. package/dist/paths/smooth-corners.js.map +1 -0
  185. package/dist/plugin-data/fields.d.ts +4 -0
  186. package/dist/plugin-data/fields.d.ts.map +1 -1
  187. package/dist/plugin-data/fields.js +2 -0
  188. package/dist/plugin-data/fields.js.map +1 -1
  189. package/dist/polygon.d.ts +1 -3
  190. package/dist/polygon.d.ts.map +1 -1
  191. package/dist/polygon.js +1 -16
  192. package/dist/polygon.js.map +1 -1
  193. package/dist/primitives/index.d.ts +1 -7
  194. package/dist/primitives/index.d.ts.map +1 -1
  195. package/dist/resize.d.ts.map +1 -1
  196. package/dist/resize.js +5 -5
  197. package/dist/resize.js.map +1 -1
  198. package/dist/scaling/node.d.ts.map +1 -1
  199. package/dist/scaling/node.js +25 -3
  200. package/dist/scaling/node.js.map +1 -1
  201. package/dist/shaders/model.d.ts.map +1 -1
  202. package/dist/shaders/model.js +1 -1
  203. package/dist/shaders/model.js.map +1 -1
  204. package/dist/shared-styles.d.ts.map +1 -1
  205. package/dist/shared-styles.js +2 -9
  206. package/dist/shared-styles.js.map +1 -1
  207. package/dist/strokes.d.ts +39 -0
  208. package/dist/strokes.d.ts.map +1 -0
  209. package/dist/strokes.js +104 -0
  210. package/dist/strokes.js.map +1 -0
  211. package/dist/text/auto-resize.d.ts +15 -0
  212. package/dist/text/auto-resize.d.ts.map +1 -0
  213. package/dist/text/auto-resize.js +23 -0
  214. package/dist/text/auto-resize.js.map +1 -0
  215. package/dist/text/index.d.ts +5 -3
  216. package/dist/text/index.js +5 -3
  217. package/dist/text/lengths.d.ts +6 -1
  218. package/dist/text/lengths.d.ts.map +1 -1
  219. package/dist/text/lengths.js +10 -1
  220. package/dist/text/lengths.js.map +1 -1
  221. package/dist/text/overflow.d.ts +14 -5
  222. package/dist/text/overflow.d.ts.map +1 -1
  223. package/dist/text/overflow.js +24 -6
  224. package/dist/text/overflow.js.map +1 -1
  225. package/dist/text/path.js +10 -0
  226. package/dist/text/path.js.map +1 -0
  227. package/dist/text/picture.js +5 -5
  228. package/dist/text/picture.js.map +1 -1
  229. package/dist/text/runs.d.ts +29 -0
  230. package/dist/text/runs.d.ts.map +1 -0
  231. package/dist/text/runs.js +72 -0
  232. package/dist/text/runs.js.map +1 -0
  233. package/dist/transfer/dependencies.d.ts.map +1 -1
  234. package/dist/transfer/dependencies.js +3 -2
  235. package/dist/transfer/dependencies.js.map +1 -1
  236. package/dist/transfer/nodes.js +2 -1
  237. package/dist/transfer/nodes.js.map +1 -1
  238. package/dist/types.d.ts +56 -10
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js.map +1 -1
  241. package/dist/variables/index.d.ts +4 -3
  242. package/dist/variables/index.d.ts.map +1 -1
  243. package/dist/variables/index.js +4 -3
  244. package/dist/variables/index.js.map +1 -1
  245. package/dist/variables/lookup.d.ts +20 -0
  246. package/dist/variables/lookup.d.ts.map +1 -0
  247. package/dist/variables/lookup.js +34 -0
  248. package/dist/variables/lookup.js.map +1 -0
  249. package/dist/variables/paints.d.ts +35 -4
  250. package/dist/variables/paints.d.ts.map +1 -1
  251. package/dist/variables/paints.js +67 -16
  252. package/dist/variables/paints.js.map +1 -1
  253. package/dist/variables/resolution.d.ts +3 -1
  254. package/dist/variables/resolution.d.ts.map +1 -1
  255. package/dist/variables/resolution.js +8 -3
  256. package/dist/variables/resolution.js.map +1 -1
  257. package/dist/variables/subtree.js +1 -1
  258. package/dist/variables/subtree.js.map +1 -1
  259. package/dist/vector-network.d.ts.map +1 -1
  260. package/dist/vector-network.js +13 -79
  261. package/dist/vector-network.js.map +1 -1
  262. package/package.json +28 -7
  263. package/src/buffered-events.ts +2 -1
  264. package/src/clipping.ts +11 -8
  265. package/src/comments/schema.ts +1 -0
  266. package/src/comments/threads.ts +13 -5
  267. package/src/components/properties.ts +3 -14
  268. package/src/constants.ts +25 -1
  269. package/src/copy.ts +2 -0
  270. package/src/corners.ts +93 -0
  271. package/src/css/grid.ts +49 -7
  272. package/src/css/index.ts +13 -2
  273. package/src/css/layout.ts +36 -0
  274. package/src/css/values.ts +49 -0
  275. package/src/font-style.ts +38 -4
  276. package/src/geometry.ts +223 -28
  277. package/src/gradient.ts +23 -1
  278. package/src/graph.ts +35 -10
  279. package/src/group-bounds.ts +7 -3
  280. package/src/guides.ts +26 -1
  281. package/src/hit-test.ts +68 -10
  282. package/src/icons/fit.ts +24 -0
  283. package/src/icons/glyph.ts +6 -4
  284. package/src/icons/index.ts +1 -0
  285. package/src/ids.ts +1 -1
  286. package/src/images.ts +67 -7
  287. package/src/instances/assignments.ts +65 -7
  288. package/src/instances/index.ts +77 -13
  289. package/src/instances/kept-overrides.ts +2 -5
  290. package/src/instances/matching.ts +101 -0
  291. package/src/instances/overrides.ts +18 -0
  292. package/src/instances/protection.ts +103 -0
  293. package/src/instances/swap.ts +12 -9
  294. package/src/instances/sync.ts +52 -184
  295. package/src/layout/guides.ts +42 -9
  296. package/src/layout/index.ts +3 -0
  297. package/src/layout/limits.ts +64 -0
  298. package/src/layout/sizing.ts +0 -2
  299. package/src/layout/spacing.ts +11 -0
  300. package/src/layout/strokes.ts +23 -0
  301. package/src/masks.ts +51 -0
  302. package/src/matrix.ts +15 -2
  303. package/src/node-defaults.ts +71 -36
  304. package/src/outline/flatten.ts +31 -18
  305. package/src/outline/hit.ts +16 -33
  306. package/src/outline/index.ts +2 -2
  307. package/src/outline/shapes.ts +19 -36
  308. package/src/paints/index.ts +2 -0
  309. package/src/paints/pattern.ts +45 -0
  310. package/src/paints/shows.ts +13 -0
  311. package/src/parse-path.ts +14 -0
  312. package/src/paths/arc.ts +59 -0
  313. package/src/paths/index.ts +4 -0
  314. package/src/paths/network.ts +411 -0
  315. package/src/paths/sink.ts +50 -0
  316. package/src/paths/smooth-corners.ts +357 -0
  317. package/src/plugin-data/fields.ts +2 -0
  318. package/src/polygon.ts +0 -17
  319. package/src/primitives/index.ts +0 -5
  320. package/src/resize.ts +6 -7
  321. package/src/scaling/node.ts +29 -3
  322. package/src/shaders/model.ts +2 -1
  323. package/src/shared-styles.ts +3 -4
  324. package/src/strokes.ts +121 -0
  325. package/src/text/auto-resize.ts +25 -0
  326. package/src/text/index.ts +2 -0
  327. package/src/text/lengths.ts +11 -0
  328. package/src/text/overflow.ts +32 -6
  329. package/src/text/path.ts +13 -0
  330. package/src/text/picture.ts +5 -5
  331. package/src/text/runs.ts +80 -0
  332. package/src/transfer/dependencies.ts +4 -2
  333. package/src/transfer/nodes.ts +2 -1
  334. package/src/types.ts +62 -8
  335. package/src/variables/index.ts +1 -0
  336. package/src/variables/lookup.ts +31 -0
  337. package/src/variables/paints.ts +101 -20
  338. package/src/variables/resolution.ts +15 -2
  339. package/src/variables/subtree.ts +1 -1
  340. package/src/vector-network.ts +19 -142
  341. package/dist/random.d.ts +0 -7
  342. package/dist/random.d.ts.map +0 -1
  343. package/dist/random.js +0 -25
  344. package/dist/random.js.map +0 -1
  345. package/src/random.ts +0 -28
package/dist/graph.d.ts CHANGED
@@ -166,8 +166,11 @@ declare class SceneGraph {
166
166
  * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.
167
167
  */
168
168
  updateNode(id: string, changes: Partial<SceneNode>): void;
169
- /** A size set from outside layout, with what it also sets on a generated frame. */
170
- private sizedChanges;
169
+ /**
170
+ * `changes` with what they also set: a size from outside layout on a generated frame, and
171
+ * strokes and the layer's line fields kept in agreement (`strokeLineChanges`).
172
+ */
173
+ private impliedChanges;
171
174
  /** Replay captured properties without dropping explicit undefined values or absent keys. */
172
175
  restoreNodeProperties(id: string, changes: Partial<SceneNode>, absent: readonly (keyof SceneNode)[]): void;
173
176
  private applyNodeChanges;
@@ -204,6 +207,10 @@ declare class SceneGraph {
204
207
  detachInstance(instanceId: string): void;
205
208
  getMainComponent(instanceId: string): SceneNode | undefined;
206
209
  getInstances(componentId: string): SceneNode[];
210
+ /**
211
+ * The descendants of a layer in depth-first order with their depths. Each layer with children is
212
+ * walked once, so a cycle or repeated links in bad data cannot hang it or repeat its subtree.
213
+ */
207
214
  flattenTree(parentId?: string, depth?: number): Array<{
208
215
  node: SceneNode;
209
216
  depth: number;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;cAuDa;mBAkCkB;EAjC7B,OAAK,YAAA;EACL,QAAM,YAAA,WAAA;EACN,WAAS,YAAA;EACT,qBAAmB,YAAA;EACnB;EACA;;EAEA,mBAAmB;EACnB,oBAAoB;EACpB,cAAc;EACd,kBAAgB,YAAA;WACP,SAAO;UACR;mBACS;UAQT;mBACS;;mBAEA;UACT;UACA;UACA;EACR;EACA,eAAa,YAAA;;EAEb,cAAY;EAEiB,YAAA;EAW7B,QAAQ,eAAe;EAIvB,SAAS,4BAA0B;EAKnC,eAAe,SAAS;EAGxB,QAAQ,aAAa;EAGrB,aAAa,UAAU;;;;;;;;EAWvB,mBAAmB,UAAU;;;;;;EAUvB,gBAAgB,GAAG,SAAS,QAAQ,KAAK,QAAQ;;;;;EAavD,gBAAgB,GAAG,aAAa,IAAI;;MAYhC;;;;;;UASI;;EAqBR,eAAe,MAAM;;;;;;EAUrB,mBAAmB;;EAKnB,qBAAqB;EAIrB,iBAAiB;EAkBjB,YAAY,UAAU;EAGtB,eAAe;EAGf,cAAc,YAAY;EAG1B,eACE,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;EAWH,iBAAiB,eAAe;EAMhC,WAAW,sBAAsB,cAAc;EAU/C,iBAAiB;EAIjB,sBAAsB,gBAAgB;EAItC,QAAQ,sBAAsB,gBAAgB,cAAc;EAI5D,WAAW,sBAAsB;EAIjC,WAAW,sBAAsB,gBAAgB;EAIjD,eAAe,sBAAsB;EAIrC,gBACE,oBACA,iBACA,UAAU,cACT;EAIH,qBAAqB,qBAAqB;EAI1C,sBAAs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AAQ,YAAY,YAAY,mBAAmB;;EAKnD,YAAY,YAAY,YAAY,kBAAkB,eAAU;EAIhE,kBACE,YACA,YACA,iBACA,aAAa,qBACb,UAAU,uBACT;EAIH,qBAAqB,YAAY,YAAY,kBAAkB;EAI/D,gBAAgB,gBAAgB;EAIhC,cAAc,gBAAgB,YAAY;EAI1C,kBACE,YACA,YACA,YAAY,qBACZ,kBACA,UAAU,oBACT;EAIH,UACE,kBACA,kBACA,YAAW,QAAQ,aAClB;UAWK;EA0BR,eACE,qBACA,kBACA,YAAW,QAAQ,aAClB;EAIH,yBACE,oBACA,qBACA,OAAM;EAKR,sBACE,oBACA,qBACA,UAAU;EAKZ,cAAc;EAId,sBAAsB,cAAc;EAIpC,aAAa;EAIb,eAAe;EAIf,iBAAiB,qBAAqB;EAItC,aAAa,sBAAsB;;;;;EAQnC,YAAY,mBAAmB,iBAAY;IAAQ,MAAM;IAAW"}
package/dist/graph.js CHANGED
@@ -10,6 +10,7 @@ import { LAYOUT_AFFECTING_KEYS } from "./fields/layout.js";
10
10
  import { withGeneratedFrameSize } from "./generated/index.js";
11
11
  import { hitTest, hitTestDeep, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode } from "./hit-test.js";
12
12
  import { generateId } from "./ids.js";
13
+ import { strokeLineChanges } from "./strokes.js";
13
14
  import { getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode } from "./variables/resolution.js";
14
15
  import { copyAppliedBoundPaints, recordWrittenBoundPaints, refreshMovedBoundPaints } from "./variables/paints.js";
15
16
  import { normalizeVectorNetwork } from "./vector-network.js";
@@ -21,7 +22,7 @@ import { markSourceFieldsEdited } from "./source-metadata.js";
21
22
  import { remapCopiedReferences } from "./transfer/copied.js";
22
23
  import { addCollection, addMode, addVariable, bindVariable, createCollection, createMode, createVariable, getVariablesByType, getVariablesForCollection, removeCollection, removeMode, removeVariable, renameMode, setDefaultMode, unbindVariable } from "./variables/index.js";
23
24
  import { omitBy, pick } from "es-toolkit/object";
24
- import { isUndefined } from "es-toolkit/predicate";
25
+ import { isEmptyObject, isUndefined } from "es-toolkit/predicate";
25
26
  //#region src/graph.ts
26
27
  var SceneGraph = class {
27
28
  idGenerator;
@@ -364,6 +365,7 @@ var SceneGraph = class {
364
365
  }
365
366
  createNode(type, parentId, overrides = {}) {
366
367
  const node = createDefaultNode(() => this.generateEntityId(), type, overrides);
368
+ Object.assign(node, strokeLineChanges(node, overrides));
367
369
  const parent = this.nodes.get(parentId);
368
370
  this.willChangeNode(parent);
369
371
  parent?.childIds.push(node.id);
@@ -473,8 +475,9 @@ var SceneGraph = class {
473
475
  }
474
476
  updateNodePreview(id, changes) {
475
477
  const node = this.nodes.get(id);
476
- if (node) changes = this.sizedChanges(node, changes);
478
+ if (node) changes = this.impliedChanges(node, changes);
477
479
  const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {
480
+ for (const observer of this.changeObservers) observer.previewed?.(node);
478
481
  for (const observe of this.previewObservers) observe(node, applied);
479
482
  });
480
483
  if (appliedChanges) this.emitter.emit("node:previewUpdated", id, appliedChanges);
@@ -490,11 +493,19 @@ var SceneGraph = class {
490
493
  }
491
494
  const node = this.nodes.get(id);
492
495
  if (!node) return;
493
- this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)));
496
+ this.applyNodeChanges(node, this.impliedChanges(node, omitBy(changes, isUndefined)));
494
497
  }
495
- /** A size set from outside layout, with what it also sets on a generated frame. */
496
- sizedChanges(node, changes) {
497
- return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes);
498
+ /**
499
+ * `changes` with what they also set: a size from outside layout on a generated frame, and
500
+ * strokes and the layer's line fields kept in agreement (`strokeLineChanges`).
501
+ */
502
+ impliedChanges(node, changes) {
503
+ const sized = this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes);
504
+ const lines = strokeLineChanges(node, sized);
505
+ return isEmptyObject(lines) ? sized : {
506
+ ...sized,
507
+ ...lines
508
+ };
498
509
  }
499
510
  /** Replay captured properties without dropping explicit undefined values or absent keys. */
500
511
  restoreNodeProperties(id, changes, absent) {
@@ -688,19 +699,44 @@ var SceneGraph = class {
688
699
  getInstances(componentId) {
689
700
  return getInstances(this, componentId);
690
701
  }
702
+ /**
703
+ * The descendants of a layer in depth-first order with their depths. Each layer with children is
704
+ * walked once, so a cycle or repeated links in bad data cannot hang it or repeat its subtree.
705
+ */
691
706
  flattenTree(parentId, depth = 0) {
692
707
  const id = parentId ?? this.rootId;
693
708
  const parent = this.nodes.get(id);
694
709
  if (!parent) return [];
695
710
  const result = [];
696
- for (const childId of parent.childIds) {
697
- const child = this.nodes.get(childId);
711
+ const pending = [{
712
+ node: parent,
713
+ depth,
714
+ index: 0
715
+ }];
716
+ const walked = /* @__PURE__ */ new Set([parent]);
717
+ while (pending.length > 0) {
718
+ const frame = pending.at(-1);
719
+ if (!frame) break;
720
+ if (frame.index >= frame.node.childIds.length) {
721
+ pending.pop();
722
+ continue;
723
+ }
724
+ const child = this.nodes.get(frame.node.childIds[frame.index++]);
698
725
  if (!child) continue;
726
+ const container = child.childIds.length > 0;
727
+ if (container && walked.has(child)) continue;
699
728
  result.push({
700
729
  node: child,
701
- depth
730
+ depth: frame.depth
702
731
  });
703
- if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1));
732
+ if (container) {
733
+ walked.add(child);
734
+ pending.push({
735
+ node: child,
736
+ depth: frame.depth + 1,
737
+ index: 0
738
+ });
739
+ }
704
740
  }
705
741
  return result;
706
742
  }
package/dist/graph.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"graph.js","names":["Variables.createVariable","Variables.createCollection","Variables.createMode","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy, pick } from 'es-toolkit/object'\nimport { isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { bindNodeEvents } from './events'\nimport { TRANSFORM_FIELDS } from './fields/geometry'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { textCacheInvalidationChanges } from './text/picture'\nimport { remapCopiedReferences } from './transfer/copied'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope =\n | 'preview'\n | 'sourceMetadata'\n | 'importedState'\n | 'layout'\n | 'derivedLayout'\n | 'componentDerived'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0,\n componentDerived: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n /** How many waits outside the edit each recorder is paused for. */\n private readonly outsideWaits = new Map<NodeChangeObserver, number>()\n private outsideWrites = 0\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node, variable,\n * and collection it is about to change, so a recorder can keep it as it was. Unlike node events\n * these are never buffered. Graph methods report what they change; code that writes into a\n * node, variable, or collection directly reports it with `willChangeNode`,\n * `willChangeVariable`, or `willChangeCollection` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /**\n * Waits for `promise`, such as a font or an image download an edit needs, outside the edit in\n * progress: what changes meanwhile, such as the user's or a collaborator's edit, is not recorded\n * as the waiting edit's. Only for code that writes nothing itself until the wait ends.\n */\n async waitOutsideEdit<T>(promise: Promise<T>): Promise<T> {\n const resume = this.pauseOpenEdits()\n try {\n return await promise\n } finally {\n resume()\n }\n }\n\n /**\n * Runs `write`, a change someone else makes, such as a collaborator's arriving or an undo,\n * outside every edit in progress, so none records it as its own.\n */\n runOutsideEdits<T>(write: () => T): T {\n const resume = this.pauseOpenEdits()\n this.outsideWrites++\n try {\n return write()\n } finally {\n this.outsideWrites--\n resume()\n }\n }\n\n /** Whether a write run with `runOutsideEdits`, such as a collaborator's change, is in progress. */\n get isWritingOutsideEdits(): boolean {\n return this.outsideWrites > 0\n }\n\n /**\n * Pauses the recorders open now, and only those, until the returned function resumes them: a\n * recorder that opens while an earlier pause is still pending, such as during a script's load\n * left unawaited, pauses for its own waits and is not resumed by the earlier one.\n */\n private pauseOpenEdits(): () => void {\n const paused = [...this.changeObservers]\n for (const observer of paused) {\n const waits = this.outsideWaits.get(observer) ?? 0\n if (waits === 0) observer.pause?.()\n this.outsideWaits.set(observer, waits + 1)\n }\n return () => {\n for (const observer of paused) {\n const waits = (this.outsideWaits.get(observer) ?? 1) - 1\n if (waits > 0) {\n this.outsideWaits.set(observer, waits)\n continue\n }\n this.outsideWaits.delete(observer)\n if (this.changeObservers.has(observer)) observer.resume?.()\n }\n }\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n /**\n * Tells `observeNodeChanges` observers that the variable `id` is about to change, be added, or\n * be removed. Graph methods report the variables they change; code that writes into one\n * directly reports it first.\n */\n willChangeVariable(id: string): void {\n for (const observer of this.changeObservers) observer.beforeRecord?.('variable', id)\n }\n\n /** As `willChangeVariable`, for the collection `id`. */\n willChangeCollection(id: string): void {\n for (const observer of this.changeObservers) observer.beforeRecord?.('collection', id)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(nodeId: string, variableId: string): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId)\n }\n\n resolveNumberVariableForNode(nodeId: string, variableId: string): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId)\n }\n\n resolveVariableForNode(nodeId: string, variableId: string): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId)\n }\n\n resolveStringVariableForNode(nodeId: string, variableId: string): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n const parent = this.nodes.get(parentId)\n this.willChangeNode(parent)\n parent?.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n const parent = parentId ? this.nodes.get(parentId) : undefined\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n /**\n * Runs `fn` as values a copy takes from its component, such as the bound paints of a layer an\n * instance copies, refreshed for it. Source metadata is preserved, and a save leaves them to the\n * component rather than writing them as edits of the copy.\n */\n applyComponentDerivedDuring(fn: () => void): void {\n this.withScope('componentDerived', () => this.preserveSourceMetadataDuring(fn))\n }\n\n get isApplyingComponentDerived(): boolean {\n return this.scopeDepths.componentDerived > 0\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.sizedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /** A size set from outside layout, with what it also sets on a generated frame. */\n private sizedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n if (\n node.type === 'INSTANCE' &&\n 'componentId' in changes &&\n changes.componentId !== node.componentId\n ) {\n if (node.componentId) this.unindexInstance(node.componentId, id)\n if (changes.componentId) this.indexInstance(changes.componentId, id)\n }\n this.markEdited(node, Object.keys(changes))\n // Cache resets that change the node travel with the change, under the caller's own values,\n // so a layout put-back cannot drop their event.\n if (node.type === 'TEXT') {\n const resets = omitBy(textCacheInvalidationChanges(node, changes), (value, key) =>\n Object.is(node[key], value)\n )\n changes = { ...resets, ...changes }\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n this.followListBindings(node, changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Bindings of paints and effects a write sets follow the lists it wrote. */\n private followListBindings(node: SceneNode, changes: Partial<SceneNode>): void {\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n if (changes.effects) removeStaleBindings(node, 'effects', changes)\n // A bound paint written keeps what it was given until its variable's color changes.\n if ((changes.fills || changes.strokes) && !this.isApplyingImportedState)\n Variables.recordWrittenBoundPaints(this, node, changes)\n }\n\n /** Marks fields an edit changed, unless metadata is being restored or layout is writing them. */\n private markEdited(node: SceneNode, keys: string[]): void {\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, keys)\n }\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n const before = pick(node, TRANSFORM_FIELDS)\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n // The node keeps its place on the canvas by new coordinates, which a save must write.\n this.markEdited(\n node,\n TRANSFORM_FIELDS.filter((key) => node[key] !== before[key])\n )\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n // Bound paints show their variables in the modes the layer now sits in.\n Variables.refreshMovedBoundPaints(this, nodeId, oldParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n if (previousParentId !== parentId)\n Variables.refreshMovedBoundPaints(this, childId, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n options?: HitTest.SelectableHitOptions\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, options)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string, framesOpen = true): boolean {\n return HitTest.isOpenContainer(this, nodeId, framesOpen)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const ids = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, ids)\n // Copies point at one another, as a paste's do: an instance at a component cloned with it,\n // as Figma's clone does (desktop 126), and its override records at its copies' new ids.\n remapCopiedReferences(this, ids)\n // A copy placed in other modes than its source shows its bound paints there, as a move does.\n if (clone) Variables.refreshMovedBoundPaints(this, clone.id, this.nodes.get(sourceId)?.parentId)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n ids: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n Variables.copyAppliedBoundPaints(src, clone)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n ids.set(src.id, clone.id)\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, ids)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n for (const childId of parent.childIds) {\n const child = this.nodes.get(childId)\n if (!child) continue\n result.push({ node: child, depth })\n if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1))\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,aAAb,MAAwB;CAkCO;CAjC7B,wBAAQ,IAAI,IAAuB;CACnC,yBAAS,IAAI,IAAwB;CACrC,4BAAY,IAAI,IAAsB;CACtC,sCAAsB,IAAI,IAAgC;CAC1D;CACA,iBAAgC;;CAEhC,oBAAuC;CACvC,qBAAyC;CACzC,eAA6B;CAC7B,mCAAmB,IAAI,IAAmC;CAC1D,UAAmB,IAAI,qBAAqB;CAC5C,8BAAsB,IAAI,IAAoB;CAC9C,cAA2D;EACzD,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,QAAQ;EACR,eAAe;EACf,kBAAkB;CACpB;CACA,mBAAkD,CAAC;CACnD,kCAAmC,IAAI,IAAwB;;CAE/D,+BAAgC,IAAI,IAAgC;CACpE,gBAAwB;CACxB;CACA,eAA4C;CAC5C,yBAAyB;CACzB,gCAAgB,IAAI,IAAyB;;CAE7C,+BAAe,IAAI,IAAY;CAE/B,YAAY,cAA6C,YAAY;EAAxC,KAAA,cAAA;EAC3B,MAAM,OAAO,kBAAkB,KAAK,aAAa,SAAS;GACxD,MAAM;GACN,OAAO;GACP,QAAQ;EACV,CAAC;EACD,KAAK,SAAS,KAAK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SAAS,GAAG,OAAO,KAAK,GAAG,KAAK,YAAY,SAAS,QAAQ,CAAC,CAAC;EACpF;EACA,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"graph.js","names":["Variables.createVariable","Variables.createCollection","Variables.createMode","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy, pick } from 'es-toolkit/object'\nimport { isEmptyObject, isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { bindNodeEvents } from './events'\nimport { TRANSFORM_FIELDS } from './fields/geometry'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { strokeLineChanges } from './strokes'\nimport { textCacheInvalidationChanges } from './text/picture'\nimport { remapCopiedReferences } from './transfer/copied'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope =\n | 'preview'\n | 'sourceMetadata'\n | 'importedState'\n | 'layout'\n | 'derivedLayout'\n | 'componentDerived'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0,\n componentDerived: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n /** How many waits outside the edit each recorder is paused for. */\n private readonly outsideWaits = new Map<NodeChangeObserver, number>()\n private outsideWrites = 0\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node, variable,\n * and collection it is about to change, so a recorder can keep it as it was. Unlike node events\n * these are never buffered. Graph methods report what they change; code that writes into a\n * node, variable, or collection directly reports it with `willChangeNode`,\n * `willChangeVariable`, or `willChangeCollection` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /**\n * Waits for `promise`, such as a font or an image download an edit needs, outside the edit in\n * progress: what changes meanwhile, such as the user's or a collaborator's edit, is not recorded\n * as the waiting edit's. Only for code that writes nothing itself until the wait ends.\n */\n async waitOutsideEdit<T>(promise: Promise<T>): Promise<T> {\n const resume = this.pauseOpenEdits()\n try {\n return await promise\n } finally {\n resume()\n }\n }\n\n /**\n * Runs `write`, a change someone else makes, such as a collaborator's arriving or an undo,\n * outside every edit in progress, so none records it as its own.\n */\n runOutsideEdits<T>(write: () => T): T {\n const resume = this.pauseOpenEdits()\n this.outsideWrites++\n try {\n return write()\n } finally {\n this.outsideWrites--\n resume()\n }\n }\n\n /** Whether a write run with `runOutsideEdits`, such as a collaborator's change, is in progress. */\n get isWritingOutsideEdits(): boolean {\n return this.outsideWrites > 0\n }\n\n /**\n * Pauses the recorders open now, and only those, until the returned function resumes them: a\n * recorder that opens while an earlier pause is still pending, such as during a script's load\n * left unawaited, pauses for its own waits and is not resumed by the earlier one.\n */\n private pauseOpenEdits(): () => void {\n const paused = [...this.changeObservers]\n for (const observer of paused) {\n const waits = this.outsideWaits.get(observer) ?? 0\n if (waits === 0) observer.pause?.()\n this.outsideWaits.set(observer, waits + 1)\n }\n return () => {\n for (const observer of paused) {\n const waits = (this.outsideWaits.get(observer) ?? 1) - 1\n if (waits > 0) {\n this.outsideWaits.set(observer, waits)\n continue\n }\n this.outsideWaits.delete(observer)\n if (this.changeObservers.has(observer)) observer.resume?.()\n }\n }\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n /**\n * Tells `observeNodeChanges` observers that the variable `id` is about to change, be added, or\n * be removed. Graph methods report the variables they change; code that writes into one\n * directly reports it first.\n */\n willChangeVariable(id: string): void {\n for (const observer of this.changeObservers) observer.beforeRecord?.('variable', id)\n }\n\n /** As `willChangeVariable`, for the collection `id`. */\n willChangeCollection(id: string): void {\n for (const observer of this.changeObservers) observer.beforeRecord?.('collection', id)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(nodeId: string, variableId: string): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId)\n }\n\n resolveNumberVariableForNode(nodeId: string, variableId: string): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId)\n }\n\n resolveVariableForNode(nodeId: string, variableId: string): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId)\n }\n\n resolveStringVariableForNode(nodeId: string, variableId: string): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n Object.assign(node, strokeLineChanges(node, overrides))\n const parent = this.nodes.get(parentId)\n this.willChangeNode(parent)\n parent?.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n const parent = parentId ? this.nodes.get(parentId) : undefined\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n /**\n * Runs `fn` as values a copy takes from its component, such as the bound paints of a layer an\n * instance copies, refreshed for it. Source metadata is preserved, and a save leaves them to the\n * component rather than writing them as edits of the copy.\n */\n applyComponentDerivedDuring(fn: () => void): void {\n this.withScope('componentDerived', () => this.preserveSourceMetadataDuring(fn))\n }\n\n get isApplyingComponentDerived(): boolean {\n return this.scopeDepths.componentDerived > 0\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.impliedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observer of this.changeObservers) observer.previewed?.(node)\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.impliedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /**\n * `changes` with what they also set: a size from outside layout on a generated frame, and\n * strokes and the layer's line fields kept in agreement (`strokeLineChanges`).\n */\n private impliedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n const sized = this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n const lines = strokeLineChanges(node, sized)\n return isEmptyObject(lines) ? sized : { ...sized, ...lines }\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n if (\n node.type === 'INSTANCE' &&\n 'componentId' in changes &&\n changes.componentId !== node.componentId\n ) {\n if (node.componentId) this.unindexInstance(node.componentId, id)\n if (changes.componentId) this.indexInstance(changes.componentId, id)\n }\n this.markEdited(node, Object.keys(changes))\n // Cache resets that change the node travel with the change, under the caller's own values,\n // so a layout put-back cannot drop their event.\n if (node.type === 'TEXT') {\n const resets = omitBy(textCacheInvalidationChanges(node, changes), (value, key) =>\n Object.is(node[key], value)\n )\n changes = { ...resets, ...changes }\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n this.followListBindings(node, changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Bindings of paints and effects a write sets follow the lists it wrote. */\n private followListBindings(node: SceneNode, changes: Partial<SceneNode>): void {\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n if (changes.effects) removeStaleBindings(node, 'effects', changes)\n // A bound paint written keeps what it was given until its variable's color changes.\n if ((changes.fills || changes.strokes) && !this.isApplyingImportedState)\n Variables.recordWrittenBoundPaints(this, node, changes)\n }\n\n /** Marks fields an edit changed, unless metadata is being restored or layout is writing them. */\n private markEdited(node: SceneNode, keys: string[]): void {\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, keys)\n }\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n const before = pick(node, TRANSFORM_FIELDS)\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n // The node keeps its place on the canvas by new coordinates, which a save must write.\n this.markEdited(\n node,\n TRANSFORM_FIELDS.filter((key) => node[key] !== before[key])\n )\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n // Bound paints show their variables in the modes the layer now sits in.\n Variables.refreshMovedBoundPaints(this, nodeId, oldParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n if (previousParentId !== parentId)\n Variables.refreshMovedBoundPaints(this, childId, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n options?: HitTest.SelectableHitOptions\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, options)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string, framesOpen = true): boolean {\n return HitTest.isOpenContainer(this, nodeId, framesOpen)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const ids = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, ids)\n // Copies point at one another, as a paste's do: an instance at a component cloned with it,\n // as Figma's clone does (desktop 126), and its override records at its copies' new ids.\n remapCopiedReferences(this, ids)\n // A copy placed in other modes than its source shows its bound paints there, as a move does.\n if (clone) Variables.refreshMovedBoundPaints(this, clone.id, this.nodes.get(sourceId)?.parentId)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n ids: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n Variables.copyAppliedBoundPaints(src, clone)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n ids.set(src.id, clone.id)\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, ids)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n /**\n * The descendants of a layer in depth-first order with their depths. Each layer with children is\n * walked once, so a cycle or repeated links in bad data cannot hang it or repeat its subtree.\n */\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n const pending = [{ node: parent, depth, index: 0 }]\n const walked = new Set([parent])\n while (pending.length > 0) {\n const frame = pending.at(-1)\n if (!frame) break\n if (frame.index >= frame.node.childIds.length) {\n pending.pop()\n continue\n }\n const child = this.nodes.get(frame.node.childIds[frame.index++])\n if (!child) continue\n const container = child.childIds.length > 0\n if (container && walked.has(child)) continue\n result.push({ node: child, depth: frame.depth })\n if (container) {\n walked.add(child)\n pending.push({ node: child, depth: frame.depth + 1, index: 0 })\n }\n }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AAM,YAAY,MAAM,SAAS,SAAS;GAC1C,IAAI,aAAa,OAAO,IAAI,KAAK,GAAG;GACpC,OAAO,KAAK;IAAE,MAAM;IAAO,OAAO,MAAM;GAAM,CAAC;GAC/C,IAAI,WAAW;IACb,OAAO,IAAI,KAAK;IAChB,QAAQ,KAAK;KAAE,MAAM;KAAO,OAAO,MAAM,QAAQ;KAAG,OAAO;IAAE,CAAC;GAChE;EACF;EACA,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"group-bounds.d.ts","names":[],"sources":["../src/group-bounds.ts"],"mappings":";;;;;;;;KAWY,gBAAgB,KAAK;;KAG5B,YAAY,KAAK,6CACpB,QAAQ,KAAK;;UAGE;EACf,QAAQ,YAAY;EACpB,OAAO,YAAY;;EAEnB,SAAS;IAAQ,MAAM;IAAW;;;UAGnB;;;;;EAKf,iBAAiB,MAAM,cAAc;;;;;;iBA0DvB,YACd,OAAO,eACP,mBAAmB,aACnB,kBACA,QAAQ,SACP;;;;;iBAgEa,gBACd,OAAO,eACP,OAAO,WACP,UAAU,aACV,UAAS,kBACR,YAAY,QAAQ;;;;;;;iBAqDP,mBACd,OAAO,YACP,WAAW,kBACX,UAAS,kBACR;;iBAWa,aAAa,OAAO,YAAY,KAAK;;iBAMrC,aAAa,OAAO,YAAY,KAAK"}
1
+ {"version":3,"file":"group-bounds.d.ts","names":[],"sources":["../src/group-bounds.ts"],"mappings":";;;;;;;;KAYY,gBAAgB,KAAK;;KAG5B,YAAY,KAAK,6CACpB,QAAQ,KAAK;;UAGE;EACf,QAAQ,YAAY;EACpB,OAAO,YAAY;;EAEnB,SAAS;IAAQ,MAAM;IAAW;;;UAGnB;;;;;EAKf,iBAAiB,MAAM,cAAc;;;;;;iBA6DvB,YACd,OAAO,eACP,mBAAmB,aACnB,kBACA,QAAQ,SACP;;;;;iBAgEa,gBACd,OAAO,eACP,OAAO,WACP,UAAU,aACV,UAAS,kBACR,YAAY,QAAQ;;;;;;;iBAqDP,mBACd,OAAO,YACP,WAAW,kBACX,UAAS,kBACR;;iBAWa,aAAa,OAAO,YAAY,KAAK;;iBAMrC,aAAa,OAAO,YAAY,KAAK"}
@@ -1,6 +1,7 @@
1
1
  import Matrix from "./matrix.js";
2
2
  import { FITTED_CONTAINER_TYPES } from "./node-defaults.js";
3
3
  import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from "./coordinate.js";
4
+ import { isVisibleMask, maskRuns } from "./masks.js";
4
5
  //#region src/group-bounds.ts
5
6
  function placement(node) {
6
7
  const box = {
@@ -50,9 +51,9 @@ function fittedAncestors(graph, parentIds) {
50
51
  */
51
52
  function groupBoundingLayers(children) {
52
53
  const shown = children.filter((child) => child.visible);
53
- const firstMask = shown.findIndex((child) => child.isMask);
54
- if (firstMask === -1) return shown;
55
- return [...shown.slice(0, firstMask), ...shown.slice(firstMask).filter((c) => c.isMask)];
54
+ const runs = maskRuns(shown, isVisibleMask);
55
+ if (runs.length === 0) return shown;
56
+ return [...shown.slice(0, runs[0].start), ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))];
56
57
  }
57
58
  /**
58
59
  * A group's box in its parent's space: around the layers it shows, or, with every layer hidden,
@@ -1 +1 @@
1
- {"version":3,"file":"group-bounds.js","names":[],"sources":["../src/group-bounds.ts"],"sourcesContent":["import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport Matrix from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * What fitting a group reads: its layers and their parents, as the graph has them or as a resize\n * plans them before writing.\n */\nexport type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>\n\n/** Where a layer sits, with a connector's ends, since a free end is in the parent's axes too. */\ntype Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &\n Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd'>>\n\n/** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */\nexport interface GroupFit {\n before: Map<string, Placement>\n after: Map<string, Placement>\n /** Emptied groups, outermost last, with their index in their parent. */\n removed: Array<{ node: SceneNode; index: number }>\n}\n\nexport interface GroupFitOptions {\n /**\n * The box of a boolean operation's result in its parent's space, which Figma sizes a boolean to,\n * or null to fit its operands. Measuring needs path operations, so the renderer supplies it.\n */\n booleanBounds?: (node: SceneNode) => Rect | null\n}\n\nfunction placement(node: SceneNode): Placement {\n const box = { x: node.x, y: node.y, width: node.width, height: node.height }\n if (node.type !== 'CONNECTOR') return box\n return {\n ...box,\n connectorStart: structuredClone(node.connectorStart),\n connectorEnd: structuredClone(node.connectorEnd)\n }\n}\n\n/** A connector end moved by `dx`, `dy` when it is free, as its point is in the parent's axes. */\nfunction shiftedEnd(\n end: SceneNode['connectorStart'],\n dx: number,\n dy: number\n): SceneNode['connectorStart'] {\n if (end?.nodeId !== null) return end\n return { ...end, position: { x: end.position.x - dx, y: end.position.y - dy } }\n}\n\n/** Groups and booleans holding the parents, innermost first. */\nfunction fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneNode[] {\n const found = new Map<string, { node: SceneNode; depth: number }>()\n for (const parentId of parentIds) {\n const chain: SceneNode[] = []\n for (let node = graph.getNode(parentId); node && FITTED_CONTAINER_TYPES.has(node.type);) {\n chain.push(node)\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n for (const [index, node] of chain.entries()) {\n found.set(node.id, {\n node,\n depth: Math.max(found.get(node.id)?.depth ?? 0, chain.length - index)\n })\n }\n }\n return [...found.values()].sort((a, b) => b.depth - a.depth).map(({ node }) => node)\n}\n\n/**\n * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma. A mask\n * hides the layers above it outside its shape, so they count only through the mask: the box is\n * the layers below it and the masks.\n */\nfunction groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {\n const shown = children.filter((child) => child.visible)\n const firstMask = shown.findIndex((child) => child.isMask)\n if (firstMask === -1) return shown\n return [...shown.slice(0, firstMask), ...shown.slice(firstMask).filter((c) => c.isMask)]\n}\n\n/**\n * A group's box in its parent's space: around the layers it shows, or, with every layer hidden,\n * empty at `origin`, where Figma leaves it.\n */\nexport function groupBounds(\n graph: GroupFitGraph,\n children: readonly SceneNode[],\n parentId: string,\n origin: Vector\n): Rect {\n const layers = groupBoundingLayers(children)\n return layers.length > 0\n ? getAxisAlignedBoundsInParent(layers, parentId, graph)\n : { x: origin.x, y: origin.y, width: 0, height: 0 }\n}\n\n/** A child moved back by the group's shift, a connector's free ends with it. */\nfunction shiftedBack(child: SceneNode, dx: number, dy: number): Partial<SceneNode> {\n const moved = { x: child.x - dx, y: child.y - dy }\n if (child.type !== 'CONNECTOR') return moved\n return {\n ...moved,\n connectorStart: shiftedEnd(child.connectorStart, dx, dy),\n connectorEnd: shiftedEnd(child.connectorEnd, dx, dy)\n }\n}\n\nfunction isTransformed(node: SceneNode): boolean {\n return node.rotation !== 0 || node.flipX || node.flipY\n}\n\n/**\n * The group's new box in its parent's space and how far its children shift in its own frame, so\n * that the group holds its children while they stay put on the canvas. An unrotated group takes\n * their bounds in its parent's space. A rotated or flipped group keeps its angle: it takes their\n * bounds in its own frame, and its position is solved so its frame still maps every child to the\n * same canvas point, as its rotation and flips are unchanged. A rotated or flipped boolean, whose\n * box comes from its result's path, keeps its bounds.\n */\nfunction fittedBox(\n graph: GroupFitGraph,\n group: SceneNode,\n parentId: string,\n children: SceneNode[],\n options: GroupFitOptions\n): { box: Rect; shift: Vector } | null {\n if (!isTransformed(group)) {\n const box =\n (group.type === 'BOOLEAN_OPERATION' ? options.booleanBounds?.(group) : null) ??\n groupBounds(graph, children, parentId, group)\n return { box, shift: { x: box.x - group.x, y: box.y - group.y } }\n }\n if (group.type === 'BOOLEAN_OPERATION') return null\n const local = groupBounds(graph, children, group.id, { x: 0, y: 0 })\n const [px, py] = Matrix.mapPoints(getNodeLocalMatrix(group), [local.x, local.y])\n const sized = { ...group, width: local.width, height: local.height }\n const [qx, qy] = Matrix.mapPoints(getNodeLocalMatrix(sized, { x: 0, y: 0 }), [0, 0])\n return {\n box: { x: px - qx, y: py - qy, width: local.width, height: local.height },\n shift: { x: local.x, y: local.y }\n }\n}\n\nconst FIT_TOLERANCE = 1e-9\n\nfunction unchanged(value: number, previous: number): boolean {\n return Math.abs(value - previous) <= FIT_TOLERANCE * Math.max(1, Math.abs(previous))\n}\n\n/**\n * The changes that fit `group` to `children`: its box in its parent's space, and each child moved\n * back so it stays put on the canvas. Null when the fit changes nothing.\n */\nexport function groupFitChanges(\n graph: GroupFitGraph,\n group: SceneNode,\n children: SceneNode[],\n options: GroupFitOptions = {}\n): Map<string, Partial<SceneNode>> | null {\n if (!group.parentId) return null\n const fitted = fittedBox(graph, group, group.parentId, children, options)\n if (!fitted) return null\n const { box, shift } = fitted\n // A rotated group's frame leaves rounding residue; a fit within it changes nothing.\n if (\n unchanged(shift.x, 0) &&\n unchanged(shift.y, 0) &&\n unchanged(box.width, group.width) &&\n unchanged(box.height, group.height)\n ) {\n return null\n }\n const changes = new Map<string, Partial<SceneNode>>([[group.id, box]])\n for (const child of children) changes.set(child.id, shiftedBack(child, shift.x, shift.y))\n return changes\n}\n\n/** Moves the group to its children's bounds, shifting them back so they stay put. */\nfunction fitGroup(\n graph: SceneGraph,\n group: SceneNode,\n children: SceneNode[],\n fit: GroupFit,\n options: GroupFitOptions\n) {\n const changes = groupFitChanges(graph, group, children, options)\n if (!changes) return\n for (const node of [group, ...children]) {\n if (!fit.before.has(node.id)) fit.before.set(node.id, placement(node))\n }\n for (const [id, change] of changes) graph.updateNode(id, change)\n for (const node of [group, ...children]) {\n const current = graph.getNode(node.id)\n if (current) fit.after.set(node.id, placement(current))\n }\n}\n\n/** A group left without layers goes away; an empty boolean stays, as in Figma. */\nfunction removeEmptyGroup(graph: SceneGraph, group: SceneNode, fit: GroupFit) {\n if (group.type !== 'GROUP' || !group.parentId) return\n const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1\n fit.removed.push({ node: structuredClone(group), index })\n graph.deleteNode(group.id)\n}\n\n/**\n * Refits the groups and booleans around these parents to their children, keeping every child where\n * it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,\n * resizes, or leaves. Rotated or flipped groups keep their angle; a rotated or flipped boolean keeps\n * its bounds. Returns null when nothing changed.\n */\nexport function fitEnclosingGroups(\n graph: SceneGraph,\n parentIds: Iterable<string>,\n options: GroupFitOptions = {}\n): GroupFit | null {\n const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }\n for (const group of fittedAncestors(graph, parentIds)) {\n const children = graph.getChildren(group.id)\n if (children.length === 0) removeEmptyGroup(graph, group, fit)\n else fitGroup(graph, group, children, fit, options)\n }\n return fit.before.size === 0 && fit.removed.length === 0 ? null : fit\n}\n\n/** Reapplies a fit after `undoGroupFit`. */\nexport function redoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n for (const [id, value] of fit.after) graph.updateNode(id, value)\n for (const { node } of fit.removed) graph.deleteNode(node.id)\n}\n\n/** Brings back the groups a fit removed and their earlier bounds. */\nexport function undoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n // Outer groups were removed after inner ones, so they come back first.\n for (const { node, index } of fit.removed.toReversed()) {\n const parentId = node.parentId ?? graph.rootId\n graph.createNode(node.type, parentId, { ...structuredClone(node), childIds: [] })\n if (index >= 0) graph.insertChildAt(node.id, parentId, index)\n }\n for (const [id, value] of fit.before) graph.updateNode(id, value)\n}\n"],"mappings":";;;;AAiCA,SAAS,UAAU,MAA4B;CAC7C,MAAM,MAAM;EAAE,GAAG,KAAK;EAAG,GAAG,KAAK;EAAG,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;CAC3E,IAAI,KAAK,SAAS,aAAa,OAAO;CACtC,OAAO;EACL,GAAG;EACH,gBAAgB,gBAAgB,KAAK,cAAc;EACnD,cAAc,gBAAgB,KAAK,YAAY;CACjD;AACF;;AAGA,SAAS,WACP,KACA,IACA,IAC6B;CAC7B,IAAI,KA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A,KAAK,MAAM,CAAC,IAAI,UAAU,IAAI,QAAQ,MAAM,WAAW,IAAI,KAAK;AAClE"}
1
+ {"version":3,"file":"group-bounds.js","names":[],"sources":["../src/group-bounds.ts"],"sourcesContent":["import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport { isVisibleMask, maskRuns } from './masks'\nimport Matrix from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * What fitting a group reads: its layers and their parents, as the graph has them or as a resize\n * plans them before writing.\n */\nexport type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>\n\n/** Where a layer sits, with a connector's ends, since a free end is in the parent's axes too. */\ntype Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &\n Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd'>>\n\n/** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */\nexport interface GroupFit {\n before: Map<string, Placement>\n after: Map<string, Placement>\n /** Emptied groups, outermost last, with their index in their parent. */\n removed: Array<{ node: SceneNode; index: number }>\n}\n\nexport interface GroupFitOptions {\n /**\n * The box of a boolean operation's result in its parent's space, which Figma sizes a boolean to,\n * or null to fit its operands. Measuring needs path operations, so the renderer supplies it.\n */\n booleanBounds?: (node: SceneNode) => Rect | null\n}\n\nfunction placement(node: SceneNode): Placement {\n const box = { x: node.x, y: node.y, width: node.width, height: node.height }\n if (node.type !== 'CONNECTOR') return box\n return {\n ...box,\n connectorStart: structuredClone(node.connectorStart),\n connectorEnd: structuredClone(node.connectorEnd)\n }\n}\n\n/** A connector end moved by `dx`, `dy` when it is free, as its point is in the parent's axes. */\nfunction shiftedEnd(\n end: SceneNode['connectorStart'],\n dx: number,\n dy: number\n): SceneNode['connectorStart'] {\n if (end?.nodeId !== null) return end\n return { ...end, position: { x: end.position.x - dx, y: end.position.y - dy } }\n}\n\n/** Groups and booleans holding the parents, innermost first. */\nfunction fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneNode[] {\n const found = new Map<string, { node: SceneNode; depth: number }>()\n for (const parentId of parentIds) {\n const chain: SceneNode[] = []\n for (let node = graph.getNode(parentId); node && FITTED_CONTAINER_TYPES.has(node.type);) {\n chain.push(node)\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n for (const [index, node] of chain.entries()) {\n found.set(node.id, {\n node,\n depth: Math.max(found.get(node.id)?.depth ?? 0, chain.length - index)\n })\n }\n }\n return [...found.values()].sort((a, b) => b.depth - a.depth).map(({ node }) => node)\n}\n\n/**\n * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma. A mask\n * hides the layers above it outside its shape, so they count only through the mask: the box is\n * the layers below it and the masks.\n */\nfunction groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {\n const shown = children.filter((child) => child.visible)\n const runs = maskRuns(shown, isVisibleMask)\n if (runs.length === 0) return shown\n return [\n ...shown.slice(0, runs[0].start),\n ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))\n ]\n}\n\n/**\n * A group's box in its parent's space: around the layers it shows, or, with every layer hidden,\n * empty at `origin`, where Figma leaves it.\n */\nexport function groupBounds(\n graph: GroupFitGraph,\n children: readonly SceneNode[],\n parentId: string,\n origin: Vector\n): Rect {\n const layers = groupBoundingLayers(children)\n return layers.length > 0\n ? getAxisAlignedBoundsInParent(layers, parentId, graph)\n : { x: origin.x, y: origin.y, width: 0, height: 0 }\n}\n\n/** A child moved back by the group's shift, a connector's free ends with it. */\nfunction shiftedBack(child: SceneNode, dx: number, dy: number): Partial<SceneNode> {\n const moved = { x: child.x - dx, y: child.y - dy }\n if (child.type !== 'CONNECTOR') return moved\n return {\n ...moved,\n connectorStart: shiftedEnd(child.connectorStart, dx, dy),\n connectorEnd: shiftedEnd(child.connectorEnd, dx, dy)\n }\n}\n\nfunction isTransformed(node: SceneNode): boolean {\n return node.rotation !== 0 || node.flipX || node.flipY\n}\n\n/**\n * The group's new box in its parent's space and how far its children shift in its own frame, so\n * that the group holds its children while they stay put on the canvas. An unrotated group takes\n * their bounds in its parent's space. A rotated or flipped group keeps its angle: it takes their\n * bounds in its own frame, and its position is solved so its frame still maps every child to the\n * same canvas point, as its rotation and flips are unchanged. A rotated or flipped boolean, whose\n * box comes from its result's path, keeps its bounds.\n */\nfunction fittedBox(\n graph: GroupFitGraph,\n group: SceneNode,\n parentId: string,\n children: SceneNode[],\n options: GroupFitOptions\n): { box: Rect; shift: Vector } | null {\n if (!isTransformed(group)) {\n const box =\n (group.type === 'BOOLEAN_OPERATION' ? options.booleanBounds?.(group) : null) ??\n groupBounds(graph, children, parentId, group)\n return { box, shift: { x: box.x - group.x, y: box.y - group.y } }\n }\n if (group.type === 'BOOLEAN_OPERATION') return null\n const local = groupBounds(graph, children, group.id, { x: 0, y: 0 })\n const [px, py] = Matrix.mapPoints(getNodeLocalMatrix(group), [local.x, local.y])\n const sized = { ...group, width: local.width, height: local.height }\n const [qx, qy] = Matrix.mapPoints(getNodeLocalMatrix(sized, { x: 0, y: 0 }), [0, 0])\n return {\n box: { x: px - qx, y: py - qy, width: local.width, height: local.height },\n shift: { x: local.x, y: local.y }\n }\n}\n\nconst FIT_TOLERANCE = 1e-9\n\nfunction unchanged(value: number, previous: number): boolean {\n return Math.abs(value - previous) <= FIT_TOLERANCE * Math.max(1, Math.abs(previous))\n}\n\n/**\n * The changes that fit `group` to `children`: its box in its parent's space, and each child moved\n * back so it stays put on the canvas. Null when the fit changes nothing.\n */\nexport function groupFitChanges(\n graph: GroupFitGraph,\n group: SceneNode,\n children: SceneNode[],\n options: GroupFitOptions = {}\n): Map<string, Partial<SceneNode>> | null {\n if (!group.parentId) return null\n const fitted = fittedBox(graph, group, group.parentId, children, options)\n if (!fitted) return null\n const { box, shift } = fitted\n // A rotated group's frame leaves rounding residue; a fit within it changes nothing.\n if (\n unchanged(shift.x, 0) &&\n unchanged(shift.y, 0) &&\n unchanged(box.width, group.width) &&\n unchanged(box.height, group.height)\n ) {\n return null\n }\n const changes = new Map<string, Partial<SceneNode>>([[group.id, box]])\n for (const child of children) changes.set(child.id, shiftedBack(child, shift.x, shift.y))\n return changes\n}\n\n/** Moves the group to its children's bounds, shifting them back so they stay put. */\nfunction fitGroup(\n graph: SceneGraph,\n group: SceneNode,\n children: SceneNode[],\n fit: GroupFit,\n options: GroupFitOptions\n) {\n const changes = groupFitChanges(graph, group, children, options)\n if (!changes) return\n for (const node of [group, ...children]) {\n if (!fit.before.has(node.id)) fit.before.set(node.id, placement(node))\n }\n for (const [id, change] of changes) graph.updateNode(id, change)\n for (const node of [group, ...children]) {\n const current = graph.getNode(node.id)\n if (current) fit.after.set(node.id, placement(current))\n }\n}\n\n/** A group left without layers goes away; an empty boolean stays, as in Figma. */\nfunction removeEmptyGroup(graph: SceneGraph, group: SceneNode, fit: GroupFit) {\n if (group.type !== 'GROUP' || !group.parentId) return\n const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1\n fit.removed.push({ node: structuredClone(group), index })\n graph.deleteNode(group.id)\n}\n\n/**\n * Refits the groups and booleans around these parents to their children, keeping every child where\n * it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,\n * resizes, or leaves. Rotated or flipped groups keep their angle; a rotated or flipped boolean keeps\n * its bounds. Returns null when nothing changed.\n */\nexport function fitEnclosingGroups(\n graph: SceneGraph,\n parentIds: Iterable<string>,\n options: GroupFitOptions = {}\n): GroupFit | null {\n const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }\n for (const group of fittedAncestors(graph, parentIds)) {\n const children = graph.getChildren(group.id)\n if (children.length === 0) removeEmptyGroup(graph, group, fit)\n else fitGroup(graph, group, children, fit, options)\n }\n return fit.before.size === 0 && fit.removed.length === 0 ? null : fit\n}\n\n/** Reapplies a fit after `undoGroupFit`. */\nexport function redoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n for (const [id, value] of fit.after) graph.updateNode(id, value)\n for (const { node } of fit.removed) graph.deleteNode(node.id)\n}\n\n/** Brings back the groups a fit removed and their earlier bounds. */\nexport function undoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n // Outer groups were removed after inner ones, so they come back first.\n for (const { node, index } of fit.removed.toReversed()) {\n const parentId = node.parentId ?? graph.rootId\n graph.createNode(node.type, parentId, { ...structuredClone(node), childIds: [] })\n if (index >= 0) graph.insertChildAt(node.id, parentId, index)\n }\n for (const [id, value] of fit.before) graph.updateNode(id, value)\n}\n"],"mappings":";;;;;AAkCA,SAAS,UAAU,MAA4B;CAC7C,MAAM,MAAM;EAAE,GAAG,KAAK;EAAG,GAAG,KAAK;EAAG,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;CAC3E,IAAI,KAAK,SAAS,aAAa,OAAO;CACtC,OAAO;EACL,GAAG;EACH,gBAAgB,gBAAgB,KAAK,cAAc;EACnD,cAAc,gBAAgB,KAAK,YAAY;CACjD;AACF;;AAGA,SAAS,WACP,KACA,IACA,IAC6B;CAC7B,IAAI,KAAK,WAAW,MAAM,OAAO;CACjC,OAAO;EAAE,GAAG;EAAK,UAAU;GAAE,GAAG,IAAI,SAAS,IAAI;GAAI,GAAG,IAAI,SAAS,IAAI;EAAG;CAAE;AAChF;;AAGA,SAAS,gBAAgB,OAAmB,WAA0C;CACpF,MAAM,wBAAQ,IAAI,IAAgD;CAClE,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,QAAqB,CAAC;EAC5B,KAAK,IAAI,OAAO,MAAM,QAAQ,QAAQ,GAAG,QAAQ,uBAAuB,IAAI,KAAK,IAAI,IAAI;GACvF,MAAM,KAAK,IAAI;GACf,OAAO,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EACxD;EACA,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GACxC,MAAM,IAAI,KAAK,IAAI;GACjB;GACA,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,SAAS,KA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WAAW,GAAG,iBAAiB,OAAO,OAAO,GAAG;OACxD,SAAS,OAAO,OAAO,UAAU,KAAK,OAAO;CACpD;CACA,OAAO,IAAI,OAAO,SAAS,KAAK,IAAI,QAAQ,WAAW,IAAI,OAAO;AACpE;;AAGA,SAAgB,aAAa,OAAmB,KAAqB;CACnE,KAAK,MAAM,CAAC,IAAI,UAAU,IAAI,OAAO,MAAM,WAAW,IAAI,KAAK;CAC/D,KAAK,MAAM,EAAE,UAAU,IAAI,SAAS,MAAM,WAAW,KAAK,EAAE;AAC9D;;AAGA,SAAgB,aAAa,OAAmB,KAAqB;CAEnE,KAAK,MAAM,EAAE,MAAM,WAAW,IAAI,QAAQ,WAAW,GAAG;EACtD,MAAM,WAAW,KAAK,YAAY,MAAM;EACxC,MAAM,WAAW,KAAK,MAAM,UAAU;GAAE,GAAG,gBAAgB,IAAI;GAAG,UAAU,CAAC;EAAE,CAAC;EAChF,IAAI,SAAS,GAAG,MAAM,cAAc,KAAK,IAAI,UAAU,KAAK;CAC9D;CACA,KAAK,MAAM,CAAC,IAAI,UAAU,IAAI,QAAQ,MAAM,WAAW,IAAI,KAAK;AAClE"}
package/dist/guides.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { GUID } from "./primitives/index.js";
1
+ import { GUID, Vector } from "./primitives/index.js";
2
2
  import { SceneGraph } from "./graph.js";
3
3
  import { SceneNode } from "./types.js";
4
4
  //#region src/guides.d.ts
@@ -16,6 +16,15 @@ declare function newGuideId(): string;
16
16
  * walk the page's whole tree on every frame.
17
17
  */
18
18
  declare function guideOwnersOnPage(graph: SceneGraph, pageId: string): SceneNode[];
19
+ /**
20
+ * A guide or layout line `owner` carries, across its box from edge to edge at `position` along
21
+ * `axis` in its own axes, in page coordinates: where the canvas draws it, a pointer finds it, and
22
+ * a drag snaps to it.
23
+ */
24
+ declare function guideLineInWorld(graph: SceneGraph, owner: SceneNode, axis: CanvasGuide['axis'], position: number): {
25
+ start: Vector;
26
+ end: Vector;
27
+ };
19
28
  //#endregion
20
- export { CanvasGuide, guideOwnersOnPage, newGuideId };
29
+ export { CanvasGuide, guideLineInWorld, guideOwnersOnPage, newGuideId };
21
30
  //# sourceMappingURL=guides.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guides.d.ts","names":[],"sources":["../src/guides.ts"],"mappings":";;;;UAIiB;EACf;EACA;EACA;EACA,UAAU;;;iBAII;;;;;;iBA+BA,kBAAkB,OAAO,YAAY,iBAAiB"}
1
+ {"version":3,"file":"guides.d.ts","names":[],"sources":["../src/guides.ts"],"mappings":";;;;UAMiB;EACf;EACA;EACA;EACA,UAAU;;;iBAII;;;;;;iBA+BA,kBAAkB,OAAO,YAAY,iBAAiB;;;;;;iBAetD,iBACd,OAAO,YACP,OAAO,WACP,MAAM,qBACN;EACG,OAAO;EAAQ,KAAK"}
package/dist/guides.js CHANGED
@@ -1,3 +1,5 @@
1
+ import Matrix from "./matrix.js";
2
+ import { getWorldMatrix } from "./coordinate.js";
1
3
  //#region src/guides.ts
2
4
  /** A new guide's id, unique across documents as a copied guide keeps its id. */
3
5
  function newGuideId() {
@@ -37,7 +39,34 @@ function guideOwnersOnPage(graph, pageId) {
37
39
  }
38
40
  return owners;
39
41
  }
42
+ /**
43
+ * A guide or layout line `owner` carries, across its box from edge to edge at `position` along
44
+ * `axis` in its own axes, in page coordinates: where the canvas draws it, a pointer finds it, and
45
+ * a drag snaps to it.
46
+ */
47
+ function guideLineInWorld(graph, owner, axis, position) {
48
+ const matrix = getWorldMatrix(owner, graph);
49
+ return axis === "x" ? {
50
+ start: Matrix.mapPoint(matrix, {
51
+ x: position,
52
+ y: 0
53
+ }),
54
+ end: Matrix.mapPoint(matrix, {
55
+ x: position,
56
+ y: owner.height
57
+ })
58
+ } : {
59
+ start: Matrix.mapPoint(matrix, {
60
+ x: 0,
61
+ y: position
62
+ }),
63
+ end: Matrix.mapPoint(matrix, {
64
+ x: owner.width,
65
+ y: position
66
+ })
67
+ };
68
+ }
40
69
  //#endregion
41
- export { guideOwnersOnPage, newGuideId };
70
+ export { guideLineInWorld, guideOwnersOnPage, newGuideId };
42
71
 
43
72
  //# sourceMappingURL=guides.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"guides.js","names":[],"sources":["../src/guides.ts"],"sourcesContent":["import type { SceneGraph } from './graph'\nimport type { GUID } from './primitives'\nimport type { SceneNode } from './types'\n\nexport interface CanvasGuide {\n id: string\n axis: 'x' | 'y'\n position: number\n figGuid?: GUID\n}\n\n/** A new guide's id, unique across documents as a copied guide keeps its id. */\nexport function newGuideId(): string {\n return `guide:${crypto.randomUUID()}`\n}\n\nconst ownersByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nfunction ownerSet(graph: SceneGraph): Set<string> {\n const existing = ownersByGraph.get(graph)\n if (existing) return existing\n const owners = new Set<string>()\n for (const node of graph.getAllNodes()) if (node.guides.length > 0) owners.add(node.id)\n const track = (node: SceneNode | undefined, id: string) => {\n if (node && node.guides.length > 0) owners.add(id)\n else owners.delete(id)\n }\n graph.onNodeEvents({\n created: (node) => track(node, node.id),\n updated: (id, changes) => {\n if ('guides' in changes) track(graph.getNode(id), id)\n },\n deleted: (id) => owners.delete(id)\n })\n ownersByGraph.set(graph, owners)\n return owners\n}\n\n/**\n * The layers on a page that carry guides, which a frame anywhere in the tree can, as in Figma.\n * The graph keeps the set current from its node events, so drawing and hit-testing guides do not\n * walk the page's whole tree on every frame.\n */\nexport function guideOwnersOnPage(graph: SceneGraph, pageId: string): SceneNode[] {\n const owners: SceneNode[] = []\n for (const id of ownerSet(graph)) {\n const node = graph.getNode(id)\n if (!node || node.guides.length === 0) continue\n if (graph.pageOf(id) === pageId) owners.push(node)\n }\n return owners\n}\n"],"mappings":";;AAYA,SAAgB,aAAqB;CACnC,OAAO,SAAS,OAAO,WAAW;AACpC;AAEA,MAAM,gCAAgB,IAAI,QAAiC;AAE3D,SAAS,SAAS,OAAgC;CAChD,MAAM,WAAW,cAAc,IAAI,KAAK;CACxC,IAAI,UAAU,OAAO;CACrB,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,MAAM,YAAY,GAAG,IAAI,KAAK,OAAO,SAAS,GAAG,OAAO,IAAI,KAAK,EAAE;CACtF,MAAM,SAAS,MAA6B,OAAe;EACzD,IAAI,QAAQ,KAAK,OAAO,SAAS,GAAG,OAAO,IAAI,EAAE;OAC5C,OAAO,OAAO,EAAE;CACvB;CACA,MAAM,aAAa;EACjB,UAAU,SAAS,MAAM,MAAM,KAAK,EAAE;EACtC,UAAU,IAAI,YAAY;GACxB,IAAI,YAAY,SAAS,MAAM,MAAM,QAAQ,EAAE,GAAG,EAAE;EACtD;EACA,UAAU,OAAO,OAAO,OAAO,EAAE;CACnC,CAAC;CACD,cAAc,IAAI,OAAO,MAAM;CAC/B,OAAO;AACT;;;;;;AAOA,SAAgB,kBAAkB,OAAmB,QAA6B;CAChF,MAAM,SAAsB,CAAC;CAC7B,KAAK,MAAM,MAAM,SAAS,KAAK,GAAG;EAChC,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,QAAQ,KAAK,OAAO,WAAW,GAAG;EACvC,IAAI,MAAM,OAAO,EAAE,MAAM,QAAQ,OAAO,KAAK,IAAI;CACnD;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"guides.js","names":[],"sources":["../src/guides.ts"],"sourcesContent":["import { getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport Matrix from './matrix'\nimport type { GUID, Vector } from './primitives'\nimport type { SceneNode } from './types'\n\nexport interface CanvasGuide {\n id: string\n axis: 'x' | 'y'\n position: number\n figGuid?: GUID\n}\n\n/** A new guide's id, unique across documents as a copied guide keeps its id. */\nexport function newGuideId(): string {\n return `guide:${crypto.randomUUID()}`\n}\n\nconst ownersByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nfunction ownerSet(graph: SceneGraph): Set<string> {\n const existing = ownersByGraph.get(graph)\n if (existing) return existing\n const owners = new Set<string>()\n for (const node of graph.getAllNodes()) if (node.guides.length > 0) owners.add(node.id)\n const track = (node: SceneNode | undefined, id: string) => {\n if (node && node.guides.length > 0) owners.add(id)\n else owners.delete(id)\n }\n graph.onNodeEvents({\n created: (node) => track(node, node.id),\n updated: (id, changes) => {\n if ('guides' in changes) track(graph.getNode(id), id)\n },\n deleted: (id) => owners.delete(id)\n })\n ownersByGraph.set(graph, owners)\n return owners\n}\n\n/**\n * The layers on a page that carry guides, which a frame anywhere in the tree can, as in Figma.\n * The graph keeps the set current from its node events, so drawing and hit-testing guides do not\n * walk the page's whole tree on every frame.\n */\nexport function guideOwnersOnPage(graph: SceneGraph, pageId: string): SceneNode[] {\n const owners: SceneNode[] = []\n for (const id of ownerSet(graph)) {\n const node = graph.getNode(id)\n if (!node || node.guides.length === 0) continue\n if (graph.pageOf(id) === pageId) owners.push(node)\n }\n return owners\n}\n\n/**\n * A guide or layout line `owner` carries, across its box from edge to edge at `position` along\n * `axis` in its own axes, in page coordinates: where the canvas draws it, a pointer finds it, and\n * a drag snaps to it.\n */\nexport function guideLineInWorld(\n graph: SceneGraph,\n owner: SceneNode,\n axis: CanvasGuide['axis'],\n position: number\n): { start: Vector; end: Vector } {\n const matrix = getWorldMatrix(owner, graph)\n return axis === 'x'\n ? {\n start: Matrix.mapPoint(matrix, { x: position, y: 0 }),\n end: Matrix.mapPoint(matrix, { x: position, y: owner.height })\n }\n : {\n start: Matrix.mapPoint(matrix, { x: 0, y: position }),\n end: Matrix.mapPoint(matrix, { x: owner.width, y: position })\n }\n}\n"],"mappings":";;;;AAcA,SAAgB,aAAqB;CACnC,OAAO,SAAS,OAAO,WAAW;AACpC;AAEA,MAAM,gCAAgB,IAAI,QAAiC;AAE3D,SAAS,SAAS,OAAgC;CAChD,MAAM,WAAW,cAAc,IAAI,KAAK;CACxC,IAAI,UAAU,OAAO;CACrB,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,MAAM,YAAY,GAAG,IAAI,KAAK,OAAO,SAAS,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,YACA,YACA,kBACA,eACC;;;;;;;;;UA2Fc;;EAEf;;EAEA;;EAEA;;;;;EAKA;;iBAGc,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,UAAS,uBACR;;iBA+Ba,gBAAgB,OAAO,YAAY,gBAAgB;;;;;iBASnD,qBACd,OAAO,YACP,YACA,YACA,kBACC;;iBAUa,cAAc,OAAO,YAAY,gBAAgB,YAAY;UAgE5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}
1
+ {"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;iBA+QgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;UA2Fc;;EAEf;;EAEA;;EAEA;;;;;EAKA;;iBAGc,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,UAAS,uBACR;;iBA+Ba,gBAAgB,OAAO,YAAY,gBAAgB;;;;;iBASnD,qBACd,OAAO,YACP,YACA,YACA,kBACC;;iBAUa,cAAc,OAAO,YAAY,gBAAgB,YAAY;UA2D5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}