@pairdraw/scene-graph 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/checkpoint.d.ts.map +1 -1
  2. package/dist/checkpoint.js +8 -3
  3. package/dist/checkpoint.js.map +1 -1
  4. package/dist/color/index.d.ts.map +1 -1
  5. package/dist/color/index.js +3 -3
  6. package/dist/color/index.js.map +1 -1
  7. package/dist/color/management.d.ts.map +1 -1
  8. package/dist/color/management.js +4 -2
  9. package/dist/color/management.js.map +1 -1
  10. package/dist/coordinate.d.ts.map +1 -1
  11. package/dist/coordinate.js +3 -1
  12. package/dist/coordinate.js.map +1 -1
  13. package/dist/copy.d.ts.map +1 -1
  14. package/dist/copy.js +1 -0
  15. package/dist/copy.js.map +1 -1
  16. package/dist/css/values.d.ts.map +1 -1
  17. package/dist/css/values.js +2 -2
  18. package/dist/css/values.js.map +1 -1
  19. package/dist/geometry.d.ts +14 -7
  20. package/dist/geometry.d.ts.map +1 -1
  21. package/dist/geometry.js +130 -26
  22. package/dist/geometry.js.map +1 -1
  23. package/dist/graph.d.ts.map +1 -1
  24. package/dist/graph.js +7 -3
  25. package/dist/graph.js.map +1 -1
  26. package/dist/hit-test.d.ts.map +1 -1
  27. package/dist/hit-test.js +100 -8
  28. package/dist/hit-test.js.map +1 -1
  29. package/dist/instances/content-size.js +1 -1
  30. package/dist/instances/index.d.ts.map +1 -1
  31. package/dist/instances/index.js +4 -1
  32. package/dist/instances/index.js.map +1 -1
  33. package/dist/instances/sync.js +4 -3
  34. package/dist/instances/sync.js.map +1 -1
  35. package/dist/layout/index.js +1 -1
  36. package/dist/resize.d.ts +4 -1
  37. package/dist/resize.d.ts.map +1 -1
  38. package/dist/resize.js +18 -12
  39. package/dist/resize.js.map +1 -1
  40. package/dist/scaling/node.d.ts.map +1 -1
  41. package/dist/scaling/node.js +3 -1
  42. package/dist/scaling/node.js.map +1 -1
  43. package/dist/scaling/tree.d.ts.map +1 -1
  44. package/dist/scaling/tree.js +8 -5
  45. package/dist/scaling/tree.js.map +1 -1
  46. package/dist/slots/authoring.js +3 -6
  47. package/dist/slots/authoring.js.map +1 -1
  48. package/dist/slots/content.d.ts.map +1 -1
  49. package/dist/slots/content.js +15 -25
  50. package/dist/slots/content.js.map +1 -1
  51. package/dist/slots/frames.js +1 -2
  52. package/dist/slots/frames.js.map +1 -1
  53. package/dist/snap.d.ts.map +1 -1
  54. package/dist/snap.js +12 -4
  55. package/dist/snap.js.map +1 -1
  56. package/dist/types.d.ts +5 -0
  57. package/dist/types.d.ts.map +1 -1
  58. package/dist/types.js.map +1 -1
  59. package/dist/undo.d.ts +2 -1
  60. package/dist/undo.d.ts.map +1 -1
  61. package/dist/undo.js +3 -2
  62. package/dist/undo.js.map +1 -1
  63. package/dist/variables/bindings.d.ts +2 -1
  64. package/dist/variables/bindings.d.ts.map +1 -1
  65. package/dist/variables/bindings.js +6 -2
  66. package/dist/variables/bindings.js.map +1 -1
  67. package/dist/variables/index.d.ts +2 -1
  68. package/dist/variables/index.d.ts.map +1 -1
  69. package/dist/variables/index.js +23 -5
  70. package/dist/variables/index.js.map +1 -1
  71. package/dist/variables/units.d.ts +31 -0
  72. package/dist/variables/units.d.ts.map +1 -0
  73. package/dist/variables/units.js +79 -4
  74. package/dist/variables/units.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/checkpoint.ts +8 -2
  77. package/src/color/index.ts +3 -6
  78. package/src/color/management.ts +8 -2
  79. package/src/coordinate.ts +4 -1
  80. package/src/copy.ts +2 -0
  81. package/src/css/values.ts +3 -2
  82. package/src/geometry.ts +147 -24
  83. package/src/graph.ts +9 -3
  84. package/src/hit-test.ts +138 -16
  85. package/src/instances/index.ts +5 -1
  86. package/src/instances/sync.ts +5 -3
  87. package/src/resize.ts +40 -20
  88. package/src/scaling/node.ts +3 -1
  89. package/src/scaling/tree.ts +3 -2
  90. package/src/slots/authoring.ts +7 -7
  91. package/src/slots/content.ts +13 -19
  92. package/src/slots/frames.ts +3 -3
  93. package/src/snap.ts +14 -4
  94. package/src/types.ts +5 -0
  95. package/src/undo.ts +3 -2
  96. package/src/variables/bindings.ts +6 -2
  97. package/src/variables/index.ts +29 -6
  98. package/src/variables/units.ts +97 -4
package/dist/geometry.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getAxisAlignedWorldBounds } from "./coordinate.js";
1
2
  import { arrowCapOverflow } from "./arrow-caps.js";
2
3
  import { textLinesOverflow } from "./text/overflow.js";
3
4
  //#region src/geometry.ts
@@ -193,23 +194,16 @@ function effectOverflow(effects) {
193
194
  bottom
194
195
  };
195
196
  }
196
- function computeAbsoluteBounds(nodes, getAbsolutePosition) {
197
+ /** Axis-aligned canvas box around the layers, through each one's rotation, flips, and ancestors. */
198
+ function computeAbsoluteBounds(nodes, graph) {
197
199
  const bounds = createBoundsAccumulator();
198
- for (const n of nodes) {
199
- const abs = getAbsolutePosition(n.id);
200
- includeRect(bounds, {
201
- x: abs.x,
202
- y: abs.y,
203
- width: n.width,
204
- height: n.height
205
- });
206
- }
200
+ for (const n of nodes) includeRect(bounds, getAxisAlignedWorldBounds(n, graph));
207
201
  return boundsToRect(bounds);
208
202
  }
209
203
  function computeVisualBounds(nodes, getAbsolutePosition) {
210
204
  const bounds = createBoundsAccumulator();
211
205
  for (const n of nodes) {
212
- const abs = getAbsolutePosition(n.id);
206
+ const abs = unturnedTopLeft(n, getAbsolutePosition(n.id));
213
207
  const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0);
214
208
  const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n);
215
209
  const effects = effectOverflow(n.effects);
@@ -271,20 +265,131 @@ function geometryBlobBounds(paths) {
271
265
  }
272
266
  return bounds.minX === Infinity ? null : boundsToRect(bounds);
273
267
  }
268
+ /** How many straight steps a curve is sampled in when its outline is needed as points. */
269
+ const OUTLINE_CURVE_STEPS = 8;
270
+ /**
271
+ * Points along a quad (`command` 3) or cubic (4) from `start`, sampled so the curve's outline can
272
+ * be tested without a path engine. The last coordinate pair is the curve's end.
273
+ */
274
+ function curvePoints(command, start, points, steps) {
275
+ const end = points[points.length - 1];
276
+ const sampled = [];
277
+ for (let step = 1; step <= steps; step++) {
278
+ const t = step / steps;
279
+ const u = 1 - t;
280
+ if (command === 3) {
281
+ const control = points[0];
282
+ sampled.push({
283
+ x: u * u * start.x + 2 * u * t * control.x + t * t * end.x,
284
+ y: u * u * start.y + 2 * u * t * control.y + t * t * end.y
285
+ });
286
+ continue;
287
+ }
288
+ const [first, second] = points;
289
+ sampled.push({
290
+ x: u * u * u * start.x + 3 * u * u * t * first.x + 3 * u * t * t * second.x + t * t * t * end.x,
291
+ y: u * u * u * start.y + 3 * u * u * t * first.y + 3 * u * t * t * second.y + t * t * t * end.y
292
+ });
293
+ }
294
+ return sampled;
295
+ }
296
+ /** One blob's subpaths as polylines in the layer's own coordinates. */
297
+ function blobPolylines(blob, curveSteps) {
298
+ const polylines = [];
299
+ const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
300
+ let offset = 0;
301
+ let current = [];
302
+ let cursor = {
303
+ x: 0,
304
+ y: 0
305
+ };
306
+ const readPoint = () => {
307
+ if (offset + 8 > blob.length) return null;
308
+ const point = {
309
+ x: view.getFloat32(offset, true),
310
+ y: view.getFloat32(offset + 4, true)
311
+ };
312
+ offset += 8;
313
+ return point;
314
+ };
315
+ while (offset < blob.length) {
316
+ const command = blob[offset++];
317
+ const coords = geometryCommandCoordCount(command);
318
+ if (coords === null) break;
319
+ if (command === 0) {
320
+ if (current.length > 0) polylines.push(current);
321
+ current = [];
322
+ continue;
323
+ }
324
+ const points = [];
325
+ let complete = true;
326
+ for (let index = 0; index < Math.max(coords, 1); index++) {
327
+ const point = readPoint();
328
+ if (!point) {
329
+ complete = false;
330
+ break;
331
+ }
332
+ points.push(point);
333
+ }
334
+ if (!complete) break;
335
+ const end = points[points.length - 1];
336
+ if (command === 1) {
337
+ if (current.length > 0) polylines.push(current);
338
+ current = [end];
339
+ } else if (command === 2) {
340
+ if (current.length === 0) current.push(cursor);
341
+ current.push(end);
342
+ } else {
343
+ if (current.length === 0) current.push(cursor);
344
+ current.push(...curvePoints(command, cursor, points, curveSteps));
345
+ }
346
+ cursor = end;
347
+ }
348
+ if (current.length > 0) polylines.push(current);
349
+ return polylines;
350
+ }
351
+ /**
352
+ * The subpaths a layer's geometry blobs draw, as polylines in its own coordinates. Curves are
353
+ * sampled, so a caller can test a point against the outline without a path engine.
354
+ */
355
+ function geometryBlobPolylines(paths, curveSteps = OUTLINE_CURVE_STEPS) {
356
+ const polylines = [];
357
+ for (const path of paths) polylines.push(...blobPolylines(path.commandsBlob, curveSteps));
358
+ return polylines;
359
+ }
360
+ /**
361
+ * Where a local point lands relative to the box's unturned top-left, turned about the center and
362
+ * then flipped about it, in the order `getNodeLocalMatrix` composes the same two steps.
363
+ */
274
364
  function transformLocalPoint(node, point) {
275
- let x = node.flipX ? node.width - point.x : point.x;
276
- let y = node.flipY ? node.height - point.y : point.y;
365
+ let { x, y } = point;
277
366
  const rotation = node.rotation ?? 0;
278
367
  if (rotation !== 0) {
279
368
  const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation));
280
369
  x = rotated.x;
281
370
  y = rotated.y;
282
371
  }
372
+ if (node.flipX) x = node.width - x;
373
+ if (node.flipY) y = node.height - y;
283
374
  return {
284
375
  x,
285
376
  y
286
377
  };
287
378
  }
379
+ /**
380
+ * The unturned top-left of a box whose origin (its own 0,0, as `SceneGraph.getAbsolutePosition`
381
+ * returns it) sits at `origin` after the rotation.
382
+ */
383
+ function unturnedTopLeft(node, origin) {
384
+ const offset = transformLocalPoint(node, {
385
+ x: 0,
386
+ y: 0
387
+ });
388
+ return {
389
+ x: origin.x - offset.x,
390
+ y: origin.y - offset.y
391
+ };
392
+ }
288
393
  function transformedLocalBounds(node, local, abs) {
289
394
  const points = [
290
395
  {
@@ -312,7 +417,7 @@ function transformedLocalBounds(node, local, abs) {
312
417
  };
313
418
  }
314
419
  function nodeVisualBounds(node, getAbsolutePosition) {
315
- const abs = getAbsolutePosition(node.id);
420
+ const abs = unturnedTopLeft(node, getAbsolutePosition(node.id));
316
421
  const base = computeVisualBounds([node], getAbsolutePosition);
317
422
  let bounds = {
318
423
  minX: base.x,
@@ -323,17 +428,16 @@ function nodeVisualBounds(node, getAbsolutePosition) {
323
428
  const hasNonInsideStroke = node.strokes?.some((stroke) => stroke.visible && stroke.align !== "INSIDE");
324
429
  const localGeometry = geometryBlobBounds([...node.fillGeometry ?? [], ...hasNonInsideStroke ? node.strokeGeometry ?? [] : []]);
325
430
  if (localGeometry) bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds;
326
- const linesOverflow = textLinesOverflow(node);
327
- if (linesOverflow > 0) {
431
+ const below = Math.max(textLinesOverflow(node), 0) + textDecorationOverflow(node);
432
+ if (below > 0) {
328
433
  const lines = {
329
434
  x: 0,
330
435
  y: 0,
331
436
  width: node.width,
332
- height: node.height + linesOverflow
437
+ height: node.height + below
333
438
  };
334
439
  bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds;
335
440
  }
336
- bounds.maxY += textDecorationOverflow(node);
337
441
  return bounds;
338
442
  }
339
443
  /** How far a text node's underline or strikethrough reaches below its box. */
@@ -350,13 +454,13 @@ function collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition, cli
350
454
  const isClippableContainer = node.type === "FRAME" || node.type === "COMPONENT" || node.type === "INSTANCE";
351
455
  let childClip = clip;
352
456
  if (isClippableContainer && node.clipsContent) {
353
- const abs = getAbsolutePosition(node.id);
354
- const nodeClip = {
355
- minX: abs.x,
356
- minY: abs.y,
357
- maxX: abs.x + node.width,
358
- maxY: abs.y + node.height
359
- };
457
+ const abs = unturnedTopLeft(node, getAbsolutePosition(node.id));
458
+ const nodeClip = transformedLocalBounds(node, {
459
+ x: 0,
460
+ y: 0,
461
+ width: node.width,
462
+ height: node.height
463
+ }, abs);
360
464
  childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip;
361
465
  if (!childClip) return bounds;
362
466
  }
@@ -369,6 +473,6 @@ function computeDescendantVisualBounds(nodeIds, getNode, getAbsolutePosition) {
369
473
  return bounds;
370
474
  }
371
475
  //#endregion
372
- export { computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
476
+ export { computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
373
477
 
374
478
  //# sourceMappingURL=geometry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Rect, Vector } from './primitives'\nimport { textLinesOverflow } from './text/overflow'\nimport type { Effect, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const align = sided ? stroke.align : 'CENTER'\n let extra = open ? stroke.weight / 2 : 0\n if (line || align === 'OUTSIDE') extra = stroke.weight\n else if (align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = effect.radius + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeShape\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n derivedTextHeight?: number | null\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\nfunction transformLocalPoint(node: VisualBoundsNode, point: Vector): Vector {\n let x = node.flipX ? node.width - point.x : point.x\n let y = node.flipY ? node.height - point.y : point.y\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n return { x, y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = getAbsolutePosition(node.id)\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n const linesOverflow = textLinesOverflow(node)\n if (linesOverflow > 0) {\n const lines = { x: 0, y: 0, width: node.width, height: node.height + linesOverflow }\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds\n }\n\n bounds.maxY += textDecorationOverflow(node)\n\n return bounds\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(node: VisualBoundsNode): number {\n if (node.type !== 'TEXT' || !node.textDecoration || node.textDecoration === 'NONE') return 0\n const fontSize = node.fontSize ?? 14\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n return underlineOffset + thickness + fontSize * 0.35\n}\n\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n const abs = getAbsolutePosition(node.id)\n const nodeClip = {\n minX: abs.x,\n minY: abs.y,\n maxX: abs.x + node.width,\n maxY: abs.y + node.height\n }\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n"],"mappings":";;;AAKA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,SAAgB,YAAY,IAAY,IAAY,IAAY,IAAY,KAAqB;CAC/F,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL,G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AAE,KACtC,WAAW;AAClD;AAEA,SAAS,8BACP,QACA,SACA,qBACA,OAA4B,MACP;CACrB,MAAM,OAAO,QAAQ,MAAM;CAC3B,IAAI,CAAC,MAAM,SAAS,OAAO;CAE3B,MAAM,MAAM,iBAAiB,MAAM,mBAAmB;CACtD,IAAI,SAAS,OAAO,sBAAsB,KAAK,IAAI,IAAI;CAEvD,MAAM,uBACJ,KAAK,SAAS,WAAW,KAAK,SAAS,eAAe,KAAK,SAAS;CACtE,IAAI,YAAY;CAChB,IAAI,wBAAwB,KAAK,cAAc;EAC7C,MAAM,MAAM,oBAAoB,KAAK,EAAE;EACvC,MAAM,WAAW;GACf,MAAM,IAAI;GACV,MAAM,IAAI;GACV,MAAM,IAAI,IAAI,KAAK;GACnB,MAAM,IAAI,IAAI,KAAK;EACrB;EACA,YAAY,YAAY,sBAAsB,WAAW,QAAQ,IAAI;EACrE,IAAI,CAAC,WAAW,OAAO;CACzB;CAEA,KAAK,MAAM,WAAW,KAAK,YAAY,CAAC,GACtC,SAAS,kBACP,QACA,8BAA8B,SAAS,SAAS,qBAAqB,SAAS,CAChF;CAGF,OAAO;AACT;AAEA,SAAgB,8BACd,SACA,SACA,qBACqB;CACrB,IAAI,SAA8B;CAClC,KAAK,MAAM,UAAU,SACnB,SAAS,kBACP,QACA,8BAA8B,QAAQ,SAAS,mBAAmB,CACpE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport { getAxisAlignedWorldBounds } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport type { Rect, Vector } from './primitives'\nimport { textLinesOverflow } from './text/overflow'\nimport type { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const align = sided ? stroke.align : 'CENTER'\n let extra = open ? stroke.weight / 2 : 0\n if (line || align === 'OUTSIDE') extra = stroke.weight\n else if (align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = effect.radius + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\n/** Axis-aligned canvas box around the layers, through each one's rotation, flips, and ancestors. */\nexport function computeAbsoluteBounds(\n nodes: Iterable<SceneNode>,\n graph: Pick<SceneGraph, 'getNode'>\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) includeRect(bounds, getAxisAlignedWorldBounds(n, graph))\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeShape\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = unturnedTopLeft(n, getAbsolutePosition(n.id))\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n derivedTextHeight?: number | null\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How many straight steps a curve is sampled in when its outline is needed as points. */\nconst OUTLINE_CURVE_STEPS = 8\n\n/**\n * Points along a quad (`command` 3) or cubic (4) from `start`, sampled so the curve's outline can\n * be tested without a path engine. The last coordinate pair is the curve's end.\n */\nfunction curvePoints(\n command: number,\n start: Vector,\n points: readonly Vector[],\n steps: number\n): Vector[] {\n const end = points[points.length - 1]\n const sampled: Vector[] = []\n for (let step = 1; step <= steps; step++) {\n const t = step / steps\n const u = 1 - t\n if (command === 3) {\n const control = points[0]\n sampled.push({\n x: u * u * start.x + 2 * u * t * control.x + t * t * end.x,\n y: u * u * start.y + 2 * u * t * control.y + t * t * end.y\n })\n continue\n }\n const [first, second] = points\n sampled.push({\n x:\n u * u * u * start.x +\n 3 * u * u * t * first.x +\n 3 * u * t * t * second.x +\n t * t * t * end.x,\n y:\n u * u * u * start.y + 3 * u * u * t * first.y + 3 * u * t * t * second.y + t * t * t * end.y\n })\n }\n return sampled\n}\n\n/** One blob's subpaths as polylines in the layer's own coordinates. */\nfunction blobPolylines(blob: Uint8Array, curveSteps: number): Vector[][] {\n const polylines: Vector[][] = []\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n let current: Vector[] = []\n let cursor: Vector = { x: 0, y: 0 }\n const readPoint = (): Vector | null => {\n if (offset + 8 > blob.length) return null\n const point = { x: view.getFloat32(offset, true), y: view.getFloat32(offset + 4, true) }\n offset += 8\n return point\n }\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords === null) break\n if (command === 0) {\n if (current.length > 0) polylines.push(current)\n current = []\n continue\n }\n const points: Vector[] = []\n let complete = true\n for (let index = 0; index < Math.max(coords, 1); index++) {\n const point = readPoint()\n if (!point) {\n complete = false\n break\n }\n points.push(point)\n }\n if (!complete) break\n const end = points[points.length - 1]\n if (command === 1) {\n if (current.length > 0) polylines.push(current)\n current = [end]\n } else if (command === 2) {\n if (current.length === 0) current.push(cursor)\n current.push(end)\n } else {\n if (current.length === 0) current.push(cursor)\n current.push(...curvePoints(command, cursor, points, curveSteps))\n }\n cursor = end\n }\n if (current.length > 0) polylines.push(current)\n return polylines\n}\n\n/**\n * The subpaths a layer's geometry blobs draw, as polylines in its own coordinates. Curves are\n * sampled, so a caller can test a point against the outline without a path engine.\n */\nexport function geometryBlobPolylines(\n paths: Array<{ commandsBlob: Uint8Array }>,\n curveSteps = OUTLINE_CURVE_STEPS\n): Vector[][] {\n const polylines: Vector[][] = []\n for (const path of paths) polylines.push(...blobPolylines(path.commandsBlob, curveSteps))\n return polylines\n}\n\ntype TurnedBox = Pick<VisualBoundsNode, 'width' | 'height' | 'rotation' | 'flipX' | 'flipY'>\n\n/**\n * Where a local point lands relative to the box's unturned top-left, turned about the center and\n * then flipped about it, in the order `getNodeLocalMatrix` composes the same two steps.\n */\nfunction transformLocalPoint(node: TurnedBox, point: Vector): Vector {\n let { x, y } = point\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n if (node.flipX) x = node.width - x\n if (node.flipY) y = node.height - y\n return { x, y }\n}\n\n/**\n * The unturned top-left of a box whose origin (its own 0,0, as `SceneGraph.getAbsolutePosition`\n * returns it) sits at `origin` after the rotation.\n */\nfunction unturnedTopLeft(node: TurnedBox, origin: Vector): Vector {\n // `getAbsolutePosition` maps the box's own origin through the world matrix, flips included.\n const offset = transformLocalPoint(node, { x: 0, y: 0 })\n return { x: origin.x - offset.x, y: origin.y - offset.y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n const linesOverflow = Math.max(textLinesOverflow(node), 0)\n // An underline or strikethrough reaches below the last line, turning with the text.\n const below = linesOverflow + textDecorationOverflow(node)\n if (below > 0) {\n const lines = { x: 0, y: 0, width: node.width, height: node.height + below }\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds\n }\n\n return bounds\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(node: VisualBoundsNode): number {\n if (node.type !== 'TEXT' || !node.textDecoration || node.textDecoration === 'NONE') return 0\n const fontSize = node.fontSize ?? 14\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n return underlineOffset + thickness + fontSize * 0.35\n}\n\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n // The frame's own drawn box, so a turned frame clips where it is drawn. For an unturned,\n // unflipped frame this is the same box as its position and size give.\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const nodeClip = transformedLocalBounds(\n node,\n { x: 0, y: 0, width: node.width, height: node.height },\n abs\n )\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n"],"mappings":";;;;AAOA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,SAAgB,YAAY,IAAY,IAAY,IAAY,IAAY,KAAqB;CAC/F,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC,GAAG,MAAM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AG1C;EAIJ,yBAAyB,GAAG,UAAU,GAAG,6BAA6B;MAUlE;;;;;EAQJ,yBAAyB;MAIrB;;;;;;EASJ,oBAAoB;UAeZ;MASJ;EAGJ,0BAA0B,YAAY,WAAW;EAGjD,kBAAkB,YAAY,SAAS,QAAQ;;;;;EAa/C,WAAW,YAAY,SAAS,QAAQ;;UAYhC;;EAKR,sBACE,YACA,SAAS,QAAQ,YACjB,wBAAwB;UAMlB;;UAsCA;EAIR,aAAa,gBAAgB;;;;;;EA2C7B,cAAc,iBAAiB,kBAAkB;EAoBjD,WAAW;EAuBX,QAAQ,YAAY,YAAY,mBAAmB;;EAKnD,YAAY,YAAY,YAAY,kBAAkB,eAAU;EAIhE,kBACE,YACA,YACA,iBACA,aAAa,qBACb,eACC;EAIH,qBAAqB,YAAY,YAAY,kBAAkB;EAI/D,gBAAgB;EAIhB,cAAc,gBAAgB,YAAY;EAI1C,kBACE,YACA,YACA,YAAY,qBACZ,kBACA,UAAU,oBACT;EAIH,UACE,kBACA,kBACA,YAAW,QAAQ,aAClB;UAQK;EAyBR,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;EAInC,YAAY,mBAAmB,iBAAY;IAAQ,MAAM;IAAW"}
package/dist/graph.js CHANGED
@@ -315,16 +315,20 @@ var SceneGraph = class {
315
315
  return this.emitter.batch(action);
316
316
  }
317
317
  createNode(type, parentId, overrides = {}) {
318
- const node = createDefaultNode(() => this.generateEntityId(), type, overrides);
319
318
  const parent = this.nodes.get(parentId);
319
+ if (!parent) throw new Error(`Parent "${parentId}" does not exist`);
320
+ const node = createDefaultNode(() => this.generateEntityId(), type, overrides);
320
321
  this.willChangeNode(parent);
321
- parent?.childIds.push(node.id);
322
+ parent.childIds.push(node.id);
322
323
  return this.registerNode(node, parentId);
323
324
  }
324
325
  createNodeWithId(id, type, parentId, overrides = {}) {
326
+ if (this.nodes.has(id)) throw new Error(`Node "${id}" already exists`);
327
+ if (parentId === id) throw new Error(`Node "${id}" cannot be its own parent`);
328
+ const parent = parentId === null ? void 0 : this.nodes.get(parentId);
329
+ if (parentId !== null && !parent) throw new Error(`Parent "${parentId}" does not exist`);
325
330
  const node = createDefaultNode(() => id, type, overrides);
326
331
  node.id = id;
327
- const parent = parentId ? this.nodes.get(parentId) : void 0;
328
332
  if (parent && !parent.childIds.includes(id)) {
329
333
  this.willChangeNode(parent);
330
334
  parent.childIds.push(id);
package/dist/graph.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"graph.js","names":["Variables.createVariable","Variables.createCollection","Variables.createMode","Variables.getActiveModeId","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy } from 'es-toolkit/object'\nimport { isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { bindNodeEvents } from './events'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { invalidateTextCaches } from './text/picture'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport type { VariableModeFallback } from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope = 'preview' | 'sourceMetadata' | 'importedState' | 'layout' | 'derivedLayout'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n activeMode = new Map<string, string>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node it is about\n * to change, so a recorder can keep the node as it was. Unlike node events these are never\n * buffered. Graph methods report the nodes they change; code that writes into a node directly\n * reports it with `willChangeNode` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n /**\n * Mints IDs from this graph's generator for variables, collections, and modes built outside\n * it, such as a paste's: none is in use, and none repeats one this minter gave.\n */\n entityIdMinter(): () => string {\n const issued = new Set<string>()\n return () => this.generateEntityId(issued)\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getActiveModeId(collectionId: string): string {\n return Variables.getActiveModeId(this, collectionId)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n setActiveMode(collectionId: string, modeId: string): void {\n Variables.setActiveMode(this, collectionId, modeId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveNumberVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveStringVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId, fallback)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n /**\n * The index lists instances by component, so a change of either, such as undoing a detach that\n * turns a frame back into an instance, moves the layer in it.\n */\n private reindexInstance(node: SceneNode, changes: Partial<SceneNode>): void {\n const indexedBefore = node.type === 'INSTANCE' ? node.componentId : null\n const componentAfter =\n 'componentId' in changes ? (changes.componentId ?? null) : node.componentId\n const indexedAfter = (changes.type ?? node.type) === 'INSTANCE' ? componentAfter : null\n if (indexedBefore === indexedAfter) return\n if (indexedBefore) this.unindexInstance(indexedBefore, node.id)\n if (indexedAfter) this.indexInstance(indexedAfter, node.id)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n const parent = this.nodes.get(parentId)\n this.willChangeNode(parent)\n parent?.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n const parent = parentId ? this.nodes.get(parentId) : undefined\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.sizedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /** A size set from outside layout, with what it also sets on a generated frame. */\n private sizedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n this.reindexInstance(node, changes)\n if (node.type === 'TEXT') invalidateTextCaches(node, changes)\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, Object.keys(changes))\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, pad)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string): boolean {\n return HitTest.isOpenContainer(this, nodeId)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const copies = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, copies)\n // A copied instance records the overrides of its own layers, which are the cloned ones.\n Instances.retargetCopiedOverrides(this, copies)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n copies: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n copies.set(src.id, clone.id)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, copies)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n for (const childId of parent.childIds) {\n const child = this.nodes.get(childId)\n if (!child) continue\n result.push({ node: child, depth })\n if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1))\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAa,aAAb,MAAwB;CA+BO;CA9B7B,wBAAQ,IAAI,IAAuB;CACnC,yBAAS,IAAI,IAAwB;CACrC,4BAAY,IAAI,IAAsB;CACtC,sCAAsB,IAAI,IAAgC;CAC1D,6BAAa,IAAI,IAAoB;CACrC;CACA,iBAAgC;;CAEhC,oBAAuC;CACvC,qBAAyC;CACzC,eAA6B;CAC7B,mCAAmB,IAAI,IAAmC;CAC1D,UAAmB,IAAI,qBAAqB;CAC5C,8BAAsB,IAAI,IAAoB;CAC9C,cAA2D;EACzD,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,QAAQ;EACR,eAAe;CACjB;CACA,mBAAkD,CAAC;CACnD,kCAAmC,IAAI,IAAwB;CAC/D;CACA,eAA4C;CAC5C,yBAAyB;CACzB,gCAAgB,IAAI,IAAyB;;CAE7C,+BAAe,IAAI,IAAY;CAE/B,YAAY,cAA6C,YAAY;EAAxC,KAAA,cAAA;EAC3B,MAAM,OAAO,kBAAkB,KAAK,aAAa,SAAS;GACxD,MAAM;GACN,OAAO;GACP,QAAQ;EACV,CAAC;EACD,KAAK,SAA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AAC,QAAQ,CAAC;EAExD,KAAK,MAAM,WAAW,IAAI,UACxB,KAAK,aAAa,SAAS,MAAM,IAAI,CAAC,GAAG,MAAM;EAGjD,OAAO;CACT;CAEA,eACE,aACA,UACA,YAAgC,CAAC,GACf;EAClB,OAAOC,eAAyB,MAAM,aAAa,UAAU,SAAS;CACxE;CAEA,yBACE,YACA,aACA,OAAsB,QAChB;EACN,yBAAmC,MAAM,YAAY,aAAa,IAAI;CACxE;CAEA,sBACE,YACA,aACA,SACM;EACN,sBAAgC,MAAM,YAAY,aAAa,OAAO;CACxE;CAEA,cAAc,aAA2B;EACvC,cAAwB,MAAM,WAAW;CAC3C;CAEA,sBAAsB,cAAsC;EAC1D,sBAAgC,MAAM,YAAY;CACpD;CAEA,aAAa,YAA0B;EACrC,aAAuB,MAAM,UAAU;CACzC;CAEA,eAAe,YAA0B;EACvC,eAAyB,MAAM,UAAU;CAC3C;CAEA,iBAAiB,YAA2C;EAC1D,OAAOC,iBAA2B,MAAM,UAAU;CACpD;CAEA,aAAa,aAAkC;EAC7C,OAAOC,aAAuB,MAAM,WAAW;CACjD;CAEA,YAAY,UAAmB,QAAQ,GAA8C;EACnF,MAAM,KAAK,YAAY,KAAK;EAC5B,MAAM,SAAS,KAAK,MAAM,IAAI,EAAE;EAChC,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,MAAM,SAAoD,CAAC;EAC3D,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,QAAQ,KAAK,MAAM,IAAI,OAAO;GACpC,IAAI,CAAC,OAAO;GACZ,OAAO,KAAK;IAAE,MAAM;IAAO;GAAM,CAAC;GAClC,IAAI,MAAM,SAAS,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.getActiveModeId","Variables.getNodeVariableModeId","Variables.resolveVariable","Variables.resolveColorVariable","Variables.resolveNumberVariable","Variables.resolveColorVariableForNode","Variables.resolveNumberVariableForNode","Variables.resolveVariableForNode","Variables.resolveStringVariableForNode","Variables.getVariablesForCollection","Variables.getVariablesByType","HitTest.hitTest","HitTest.hitTestDeep","HitTest.hitTestSelectable","HitTest.hitTestOpenContainer","HitTest.isOpenContainer","HitTest.isPointInNode","HitTest.hitTestDropTarget","Instances.createInstance","Instances.getMainComponent","Instances.getInstances"],"sources":["../src/graph.ts"],"sourcesContent":["/* eslint-disable max-lines -- SceneGraph is the facade over the domain modules */\nimport { omitBy } from 'es-toolkit/object'\nimport { isUndefined } from 'es-toolkit/predicate'\n\nimport { removeStaleBindings } from './bindings'\nimport { BufferedSceneEmitter } from './buffered-events'\nimport {\n getAbsolutePosition,\n getNodeLocalMatrix,\n getParentWorldMatrix,\n isTranslationOnly,\n localTransformFromWorld\n} from './coordinate'\nimport { cloneNodeProps, type NodeCloneMode } from './copy'\nimport { bindNodeEvents } from './events'\nimport { LAYOUT_AFFECTING_KEYS } from './fields/layout'\nimport { withGeneratedFrameSize } from './generated'\nimport * as HitTest from './hit-test'\nimport { generateId } from './ids'\nimport * as Instances from './instances'\nimport { LayoutWrites } from './layout/writes'\nimport Matrix from './matrix'\nimport { CONTAINER_TYPES, createDefaultNode } from './node-defaults'\nimport { updateNodePreview, type NodePreviewObserver } from './preview'\nimport type { Color, Rect, Vector } from './primitives'\nimport { markSourceFieldsEdited } from './source-metadata'\nimport { invalidateTextCaches } from './text/picture'\nimport type {\n DocumentColorSpace,\n DocumentKind,\n EnabledLibraryBinding,\n NodeChangeObserver,\n NodeType,\n SceneGraphEventHandlers,\n SceneNode,\n Variable,\n VariableCollection,\n VariableType,\n VariableValue,\n VariableLiteral\n} from './types'\nimport * as Variables from './variables'\nimport type { VariableModeFallback } from './variables'\nimport { normalizeVectorNetwork } from './vector-network'\n\n/** Scopes that graph methods check while a caller's callback runs; scopes nest. */\ntype GraphScope = 'preview' | 'sourceMetadata' | 'importedState' | 'layout' | 'derivedLayout'\n\nexport class SceneGraph {\n nodes = new Map<string, SceneNode>()\n images = new Map<string, Uint8Array>()\n variables = new Map<string, Variable>()\n variableCollections = new Map<string, VariableCollection>()\n activeMode = new Map<string, string>()\n rootId: string\n figKiwiVersion: number | null = null\n /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */\n figSchemaDeflated: Uint8Array | null = null\n documentColorSpace: DocumentColorSpace = 'srgb'\n documentKind: DocumentKind = 'design'\n enabledLibraries = new Map<string, EnabledLibraryBinding>()\n readonly emitter = new BufferedSceneEmitter()\n private absPosCache = new Map<string, Vector>()\n private readonly scopeDepths: Record<GraphScope, number> = {\n preview: 0,\n sourceMetadata: 0,\n importedState: 0,\n layout: 0,\n derivedLayout: 0\n }\n private previewObservers: NodePreviewObserver[] = []\n private readonly changeObservers = new Set<NodeChangeObserver>()\n private importedIdGenerator: (() => string) | undefined\n private layoutWrites: LayoutWrites | null = null\n positionPreviewVersion = 0\n instanceIndex = new Map<string, Set<string>>()\n /** Every connector in the graph, so routing need not scan every layer. */\n connectorIds = new Set<string>()\n\n constructor(private readonly idGenerator: () => string = generateId) {\n const root = createDefaultNode(this.idGenerator, 'FRAME', {\n name: 'Document',\n width: 0,\n height: 0\n })\n this.rootId = root.id\n this.nodes.set(root.id, root)\n\n this.addPage('Page 1')\n }\n addPage(name: string): SceneNode {\n return this.createNode('CANVAS', this.rootId, { name, width: 0, height: 0 })\n }\n\n getPages(includeInternal = false): SceneNode[] {\n return this.getChildren(this.rootId).filter(\n (n) => n.type === 'CANVAS' && (includeInternal || !n.internalOnly)\n )\n }\n getAllNodes(): Iterable<SceneNode> {\n return this.nodes.values()\n }\n getNode(id: string): SceneNode | undefined {\n return this.nodes.get(id)\n }\n onNodeEvents(handlers: SceneGraphEventHandlers): () => void {\n return bindNodeEvents(this.emitter, handlers)\n }\n\n /**\n * Tells `observer` about each node an edit adds and, before it changes, each node it is about\n * to change, so a recorder can keep the node as it was. Unlike node events these are never\n * buffered. Graph methods report the nodes they change; code that writes into a node directly\n * reports it with `willChangeNode` first.\n */\n observeNodeChanges(observer: NodeChangeObserver): () => void {\n this.changeObservers.add(observer)\n return () => this.changeObservers.delete(observer)\n }\n\n /** Tells `observeNodeChanges` observers that `node` is about to change. */\n willChangeNode(node: SceneNode | undefined): void {\n if (!node) return\n for (const observer of this.changeObservers) observer.before(node)\n }\n\n countDescendants(nodeId: string): number {\n const node = this.nodes.get(nodeId)\n if (!node) return 0\n let count = 0\n const stack = [...node.childIds]\n while (stack.length > 0) {\n const id = stack.pop()\n if (id === undefined) break\n count++\n const child = this.nodes.get(id)\n if (child) {\n for (const childId of child.childIds) {\n stack.push(childId)\n }\n }\n }\n return count\n }\n addVariable(variable: Variable): void {\n Variables.addVariable(this, variable)\n }\n removeVariable(id: string): void {\n Variables.removeVariable(this, id)\n }\n addCollection(collection: VariableCollection): void {\n Variables.addCollection(this, collection)\n }\n createVariable(\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n ): Variable {\n return Variables.createVariable(\n this,\n () => this.generateEntityId(),\n name,\n type,\n collectionId,\n value\n )\n }\n\n createCollection(name: string): VariableCollection {\n // The collection and its default mode are both created before either is registered.\n const issued = new Set<string>()\n return Variables.createCollection(this, () => this.generateEntityId(issued), name)\n }\n\n createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined {\n return Variables.createMode(\n this,\n () => this.generateEntityId(),\n collectionId,\n name,\n sourceModeId\n )\n }\n\n /**\n * Mints IDs from this graph's generator for variables, collections, and modes built outside\n * it, such as a paste's: none is in use, and none repeats one this minter gave.\n */\n entityIdMinter(): () => string {\n const issued = new Set<string>()\n return () => this.generateEntityId(issued)\n }\n\n removeCollection(id: string): void {\n Variables.removeCollection(this, id)\n }\n\n getActiveModeId(collectionId: string): string {\n return Variables.getActiveModeId(this, collectionId)\n }\n\n getNodeVariableModeId(nodeId: string, collectionId: string): string {\n return Variables.getNodeVariableModeId(this, nodeId, collectionId)\n }\n\n setActiveMode(collectionId: string, modeId: string): void {\n Variables.setActiveMode(this, collectionId, modeId)\n }\n\n addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void {\n Variables.addMode(this, collectionId, modeId, name, sourceMode)\n }\n\n removeMode(collectionId: string, modeId: string): void {\n Variables.removeMode(this, collectionId, modeId)\n }\n\n renameMode(collectionId: string, modeId: string, name: string): void {\n Variables.renameMode(this, collectionId, modeId, name)\n }\n\n setDefaultMode(collectionId: string, modeId: string): void {\n Variables.setDefaultMode(this, collectionId, modeId)\n }\n\n resolveVariable(\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n ): VariableLiteral | undefined {\n return Variables.resolveVariable(this, variableId, modeId, visited)\n }\n\n resolveColorVariable(variableId: string): Color | undefined {\n return Variables.resolveColorVariable(this, variableId)\n }\n\n resolveNumberVariable(variableId: string): number | undefined {\n return Variables.resolveNumberVariable(this, variableId)\n }\n\n resolveColorVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): Color | undefined {\n return Variables.resolveColorVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveNumberVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): number | undefined {\n return Variables.resolveNumberVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): VariableLiteral | undefined {\n return Variables.resolveVariableForNode(this, nodeId, variableId, fallback)\n }\n\n resolveStringVariableForNode(\n nodeId: string,\n variableId: string,\n fallback?: VariableModeFallback\n ): string | undefined {\n return Variables.resolveStringVariableForNode(this, nodeId, variableId, fallback)\n }\n\n getVariablesForCollection(collectionId: string): Variable[] {\n return Variables.getVariablesForCollection(this, collectionId)\n }\n\n getVariablesByType(type: VariableType): Variable[] {\n return Variables.getVariablesByType(this, type)\n }\n\n bindVariable(nodeId: string, field: string, variableId: string): void {\n Variables.bindVariable(this, nodeId, field, variableId)\n }\n\n unbindVariable(nodeId: string, field: string): void {\n Variables.unbindVariable(this, nodeId, field)\n }\n\n getChildren(id: string): SceneNode[] {\n const node = this.nodes.get(id)\n if (!node) return []\n return node.childIds\n .map((cid) => this.nodes.get(cid))\n .filter((n): n is SceneNode => n !== undefined)\n }\n\n isContainer(id: string): boolean {\n const node = this.nodes.get(id)\n return node ? CONTAINER_TYPES.has(node.type) : false\n }\n\n isDescendant(childId: string, ancestorId: string): boolean {\n return this.closest(childId, (node) => node.id === ancestorId) !== undefined\n }\n\n /**\n * The node itself or its nearest ancestor that matches. The walk visits at most as many nodes\n * as the graph holds, so a parent cycle in bad data cannot hang it.\n */\n closest(id: string, match: (node: SceneNode) => boolean): SceneNode | undefined {\n let current = this.nodes.get(id)\n for (let steps = 0; current && steps < this.nodes.size; steps++) {\n if (match(current)) return current\n current = current.parentId ? this.nodes.get(current.parentId) : undefined\n }\n return undefined\n }\n\n /**\n * The page a node is on: the node itself for a page, its nearest page ancestor otherwise, and\n * null for the document root or a node on no page.\n */\n pageOf(id: string): string | null {\n return this.closest(id, (node) => node.type === 'CANVAS')?.id ?? null\n }\n\n clearAbsPosCache(): void {\n this.absPosCache.clear()\n }\n\n getAbsolutePosition(id: string): Vector {\n const cached = this.absPosCache.get(id)\n if (cached) return cached\n\n const node = this.getNode(id)\n if (!node) return { x: 0, y: 0 }\n\n const result = getAbsolutePosition(node, this)\n this.absPosCache.set(id, result)\n return result\n }\n\n getAbsoluteBounds(id: string): Rect {\n const pos = this.getAbsolutePosition(id)\n const node = this.nodes.get(id)\n return {\n x: pos.x,\n y: pos.y,\n width: node?.width ?? 0,\n height: node?.height ?? 0\n }\n }\n /**\n * An ID no entity uses; `issued` also excludes IDs handed out earlier in the same creation.\n * A generator that returns more taken IDs than the graph holds must be repeating itself, so\n * it counts as exhausted then; a fixed cap would reject a sequence walking past a large import.\n */\n private generateEntityId(issued?: Set<string>): string {\n let limit = Infinity\n for (let attempt = 0; attempt < limit; attempt++) {\n const id = (this.importedIdGenerator ?? this.idGenerator)()\n if (this.isEntityIdTaken(id) || issued?.has(id)) {\n if (limit === Infinity) limit = this.entityIdCount() + (issued?.size ?? 0) + 1\n continue\n }\n issued?.add(id)\n return id\n }\n throw new Error('The ID generator only returned IDs that are in use')\n }\n private entityIdCount(): number {\n let count = this.nodes.size + this.variables.size + this.variableCollections.size\n for (const collection of this.variableCollections.values()) count += collection.modes.length\n return count\n }\n /** Whether a node, variable, collection, or mode has this id. */\n isEntityIdTaken(id: string): boolean {\n if (this.nodes.has(id) || this.variables.has(id) || this.variableCollections.has(id))\n return true\n // Callers replace collection maps and edit `modes` in place (history snapshots, transfer,\n // undo), so an index of mode IDs would go stale; walk them without allocating instead.\n for (const collection of this.variableCollections.values()) {\n for (const mode of collection.modes) if (mode.modeId === id) return true\n }\n return false\n }\n private indexInstance(componentId: string, instanceId: string): void {\n let set = this.instanceIndex.get(componentId)\n if (!set) {\n set = new Set()\n this.instanceIndex.set(componentId, set)\n }\n set.add(instanceId)\n }\n private unindexInstance(componentId: string, instanceId: string): void {\n this.instanceIndex.get(componentId)?.delete(instanceId)\n }\n /**\n * The index lists instances by component, so a change of either, such as undoing a detach that\n * turns a frame back into an instance, moves the layer in it.\n */\n private reindexInstance(node: SceneNode, changes: Partial<SceneNode>): void {\n const indexedBefore = node.type === 'INSTANCE' ? node.componentId : null\n const componentAfter =\n 'componentId' in changes ? (changes.componentId ?? null) : node.componentId\n const indexedAfter = (changes.type ?? node.type) === 'INSTANCE' ? componentAfter : null\n if (indexedBefore === indexedAfter) return\n if (indexedBefore) this.unindexInstance(indexedBefore, node.id)\n if (indexedAfter) this.indexInstance(indexedAfter, node.id)\n }\n private registerNode(node: SceneNode, parentId: string | null): SceneNode {\n node.parentId = parentId\n this.nodes.set(node.id, node)\n if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)\n for (const observer of this.changeObservers) observer.created(node)\n if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)\n this.emitter.emit('node:created', node)\n return node\n }\n /** Publish synchronous graph events only after the supplied mutation succeeds. */\n withBufferedEvents<T>(action: () => T): T {\n return this.emitter.batch(action)\n }\n\n createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {\n const parent = this.nodes.get(parentId)\n if (!parent) throw new Error(`Parent \"${parentId}\" does not exist`)\n const node = createDefaultNode(() => this.generateEntityId(), type, overrides)\n this.willChangeNode(parent)\n parent.childIds.push(node.id)\n return this.registerNode(node, parentId)\n }\n createNodeWithId(\n id: string,\n type: NodeType,\n parentId: string | null,\n overrides: Partial<SceneNode> = {}\n ): SceneNode {\n // A caller restoring or importing a layer must know it brings a new one: replacing a layer\n // that already has the ID would drop it, and its children, from the document.\n if (this.nodes.has(id)) throw new Error(`Node \"${id}\" already exists`)\n if (parentId === id) throw new Error(`Node \"${id}\" cannot be its own parent`)\n const parent = parentId === null ? undefined : this.nodes.get(parentId)\n if (parentId !== null && !parent) throw new Error(`Parent \"${parentId}\" does not exist`)\n const node = createDefaultNode(() => id, type, overrides)\n // `overrides` may be another node's snapshot, ID included.\n node.id = id\n if (parent && !parent.childIds.includes(id)) {\n this.willChangeNode(parent)\n parent.childIds.push(id)\n }\n return this.registerNode(node, parentId)\n }\n\n private withScope<T>(scope: GraphScope, fn: () => T): T {\n this.scopeDepths[scope]++\n try {\n return fn()\n } finally {\n this.scopeDepths[scope]--\n }\n }\n\n runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void {\n if (beforeUpdate) this.previewObservers.push(beforeUpdate)\n try {\n this.withScope('preview', fn)\n } finally {\n if (beforeUpdate) this.previewObservers.pop()\n }\n }\n preserveSourceMetadataDuring<T>(fn: () => T): T {\n return this.withScope('sourceMetadata', fn)\n }\n get isPreservingSourceMetadata(): boolean {\n return this.scopeDepths.sourceMetadata > 0\n }\n\n applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T {\n const previousGenerator = this.importedIdGenerator\n this.importedIdGenerator = idGenerator ?? previousGenerator\n try {\n return this.withScope('importedState', () => this.preserveSourceMetadataDuring(fn))\n } finally {\n this.importedIdGenerator = previousGenerator\n }\n }\n\n get isApplyingImportedState(): boolean {\n return this.scopeDepths.importedState > 0\n }\n\n /**\n * Lays out what the document already holds: a page as it loads, or again once its fonts\n * arrive. What this writes derives from the document; an edit's own layout is not this.\n */\n applyDerivedLayoutDuring(fn: () => void): void {\n this.withScope('derivedLayout', fn)\n }\n\n get isApplyingDerivedLayout(): boolean {\n return this.scopeDepths.derivedLayout > 0\n }\n\n /**\n * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as\n * layout, and without values a pass changed and a later pass put back (`LayoutWrites`). Outside\n * derived layout, the positions and sizes it publishes count as edited, so formats save them.\n */\n withLayoutMutations(fn: () => void): void {\n const outermost = this.scopeDepths.layout === 0\n this.scopeDepths.layout++\n if (outermost) this.layoutWrites = new LayoutWrites()\n try {\n fn()\n } finally {\n try {\n if (outermost) this.publishLayoutUpdates()\n } finally {\n this.scopeDepths.layout--\n }\n }\n }\n\n private publishLayoutUpdates(): void {\n const writes = this.layoutWrites\n this.layoutWrites = null\n if (!writes) return\n for (const [node, changes, edited] of writes.updates((nodeId) => this.nodes.get(nodeId))) {\n markSourceFieldsEdited(node, edited)\n this.emitter.emit('node:updated', node.id, changes)\n }\n }\n get isApplyingLayout(): boolean {\n return this.scopeDepths.layout > 0\n }\n updateNodePositionPreview(id: string, x: number, y: number): void {\n this.updateNodePreview(id, { x, y })\n }\n updateNodePreview(id: string, changes: Partial<SceneNode>): void {\n const node = this.nodes.get(id)\n if (node) changes = this.sizedChanges(node, changes)\n const appliedChanges = updateNodePreview(this, id, changes, (node, applied) => {\n for (const observe of this.previewObservers) observe(node, applied)\n })\n if (appliedChanges) this.emitter.emit('node:previewUpdated', id, appliedChanges)\n }\n\n /**\n * Writes fields as given. Edits detach the shared styles whose fields they change before\n * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.\n */\n updateNode(id: string, changes: Partial<SceneNode>): void {\n if (this.scopeDepths.preview > 0) {\n this.updateNodePreview(id, changes)\n return\n }\n\n const node = this.nodes.get(id)\n if (!node) return\n this.applyNodeChanges(node, this.sizedChanges(node, omitBy(changes, isUndefined)))\n }\n\n /** A size set from outside layout, with what it also sets on a generated frame. */\n private sizedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n return this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)\n }\n\n /** Replay captured properties without dropping explicit undefined values or absent keys. */\n restoreNodeProperties(\n id: string,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[]\n ): void {\n const node = this.nodes.get(id)\n if (node) this.applyNodeChanges(node, changes, absent)\n }\n\n private applyNodeChanges(\n node: SceneNode,\n changes: Partial<SceneNode>,\n absent: readonly (keyof SceneNode)[] = []\n ): void {\n const { id } = node\n this.willChangeNode(node)\n // Include removed keys in cache invalidation and update notifications.\n if (absent.length) {\n changes = { ...changes }\n for (const key of absent) Reflect.set(changes, key, undefined)\n }\n\n // Only clear absPosCache when layout-affecting properties change.\n // Fills, strokes, effects, plugin data changes do NOT affect absolute position.\n const affectsLayout = Object.keys(changes).some((k) => LAYOUT_AFFECTING_KEYS.has(k))\n if (affectsLayout) this.absPosCache.clear()\n this.reindexInstance(node, changes)\n if (node.type === 'TEXT') invalidateTextCaches(node, changes)\n if (this.scopeDepths.sourceMetadata === 0 && !this.isApplyingLayout) {\n markSourceFieldsEdited(node, Object.keys(changes))\n }\n if (changes.vectorNetwork) {\n changes = { ...changes, vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork) }\n }\n this.layoutWrites?.record(\n node,\n changes,\n this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout\n )\n Object.assign(node, changes)\n if (changes.fills) removeStaleBindings(node, 'fills', changes)\n if (changes.strokes) removeStaleBindings(node, 'strokes', changes)\n for (const key of absent) Reflect.deleteProperty(node, key)\n this.publishNodeUpdate(id, changes)\n }\n\n /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */\n private publishNodeUpdate(id: string, changes: Partial<SceneNode>): void {\n if (!this.layoutWrites) this.emitter.emit('node:updated', id, changes)\n }\n\n reparentNode(nodeId: string, newParentId: string): void {\n const node = this.nodes.get(nodeId)\n if (!node || nodeId === this.rootId) return\n if (this.isDescendant(newParentId, nodeId)) return\n\n const oldParent = node.parentId ? this.nodes.get(node.parentId) : undefined\n const newParent = this.nodes.get(newParentId)\n if (!newParent) return\n if (node.parentId === newParentId) return\n\n const oldParentId = node.parentId\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n this.absPosCache.clear()\n\n const oldParentWorld = getParentWorldMatrix(oldParent, this)\n const newParentWorld = getParentWorldMatrix(newParent, this)\n\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((cid) => cid !== nodeId)\n }\n\n node.parentId = newParentId\n newParent.childIds.push(nodeId)\n\n if (isTranslationOnly(oldParentWorld) && isTranslationOnly(newParentWorld)) {\n node.x += oldParentWorld[2] - newParentWorld[2]\n node.y += oldParentWorld[5] - newParentWorld[5]\n } else {\n const world = Matrix.multiply(oldParentWorld, getNodeLocalMatrix(node))\n const local = localTransformFromWorld(node, world, newParentWorld)\n if (local) Object.assign(node, local)\n }\n\n this.emitter.emit('node:reparented', nodeId, oldParentId, newParentId)\n }\n\n /**\n * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing\n * its own coordinates. An index past the end appends; a move into the node itself or one of\n * its descendants is ignored.\n */\n insertChildAt(childId: string, parentId: string, index: number): void {\n const node = this.nodes.get(childId)\n const newParent = this.nodes.get(parentId)\n if (!node || !newParent || this.isDescendant(parentId, childId)) return\n const previousParentId = node.parentId\n const oldParent = previousParentId ? this.nodes.get(previousParentId) : undefined\n this.willChangeNode(node)\n this.willChangeNode(oldParent)\n this.willChangeNode(newParent)\n if (oldParent) {\n oldParent.childIds = oldParent.childIds.filter((id) => id !== childId)\n }\n newParent.childIds = newParent.childIds.filter((id) => id !== childId)\n const at = Math.min(index, newParent.childIds.length)\n newParent.childIds.splice(at, 0, childId)\n node.parentId = parentId\n this.absPosCache.clear()\n this.emitter.emit('node:reordered', childId, parentId, at, previousParentId)\n }\n\n deleteNode(id: string): void {\n const node = this.nodes.get(id)\n if (!node || id === this.rootId) return\n this.willChangeNode(node)\n\n if (node.parentId) {\n const parent = this.nodes.get(node.parentId)\n this.willChangeNode(parent)\n if (parent) {\n parent.childIds = parent.childIds.filter((cid) => cid !== id)\n }\n }\n\n for (const childId of Array.from(node.childIds)) {\n this.deleteNode(childId)\n }\n\n if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)\n this.connectorIds.delete(id)\n this.nodes.delete(id)\n this.emitter.emit('node:deleted', id, node.parentId)\n }\n\n hitTest(px: number, py: number, scopeId?: string): SceneNode | null {\n return HitTest.hitTest(this, px, py, scopeId)\n }\n\n /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */\n hitTestDeep(px: number, py: number, scopeId?: string, pad = 0): SceneNode | null {\n return HitTest.hitTestDeep(this, px, py, scopeId, pad)\n }\n\n hitTestSelectable(\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n ): SceneNode | null {\n return HitTest.hitTestSelectable(this, px, py, scopeId, selectedIds, pad)\n }\n\n hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null {\n return HitTest.hitTestOpenContainer(this, px, py, scopeId)\n }\n\n isOpenContainer(nodeId: string): boolean {\n return HitTest.isOpenContainer(this, nodeId)\n }\n\n isPointInNode(nodeId: string, px: number, py: number): boolean {\n return HitTest.isPointInNode(this, nodeId, px, py)\n }\n\n hitTestDropTarget(\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options?: HitTest.DropTargetOptions\n ): SceneNode | null {\n return HitTest.hitTestDropTarget(this, px, py, excludeIds, scopeId, options)\n }\n\n cloneTree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n const copies = new Map<string, string>()\n const clone = this.cloneSubtree(sourceId, parentId, overrides, copies)\n // A copied instance records the overrides of its own layers, which are the cloned ones.\n Instances.retargetCopiedOverrides(this, copies)\n return clone\n }\n\n private cloneSubtree(\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>,\n copies: Map<string, string>\n ): SceneNode | null {\n const src = this.nodes.get(sourceId)\n if (!src) return null\n\n const props = cloneNodeProps(src, null)\n // Null out Figma source identifiers so the clone is treated as local.\n if (props.source) props.source = { ...props.source, id: null, orderKey: null }\n // A copy is a new design nobody has reviewed: Figma's duplicate and clone() drop the status.\n props.status = null\n const clone = this.createNode(src.type, parentId, { ...props, ...overrides })\n copies.set(src.id, clone.id)\n if (src.status) markSourceFieldsEdited(clone, ['status'])\n\n for (const childId of src.childIds) {\n this.cloneSubtree(childId, clone.id, {}, copies)\n }\n\n return clone\n }\n\n createInstance(\n componentId: string,\n parentId: string,\n overrides: Partial<SceneNode> = {}\n ): SceneNode | null {\n return Instances.createInstance(this, componentId, parentId, overrides)\n }\n\n populateInstanceChildren(\n instanceId: string,\n componentId: string,\n mode: NodeCloneMode = 'deep'\n ): void {\n Instances.populateInstanceChildren(this, instanceId, componentId, mode)\n }\n\n swapInstanceComponent(\n instanceId: string,\n componentId: string,\n options?: Instances.SwapInstanceOptions\n ): void {\n Instances.swapInstanceComponent(this, instanceId, componentId, options)\n }\n\n syncInstances(componentId: string): void {\n Instances.syncInstances(this, componentId)\n }\n\n syncInstancesTogether(componentIds: Iterable<string>): void {\n Instances.syncInstancesTogether(this, componentIds)\n }\n\n syncInstance(instanceId: string): void {\n Instances.syncInstance(this, instanceId)\n }\n\n detachInstance(instanceId: string): void {\n Instances.detachInstance(this, instanceId)\n }\n\n getMainComponent(instanceId: string): SceneNode | undefined {\n return Instances.getMainComponent(this, instanceId)\n }\n\n getInstances(componentId: string): SceneNode[] {\n return Instances.getInstances(this, componentId)\n }\n\n flattenTree(parentId?: string, depth = 0): Array<{ node: SceneNode; depth: number }> {\n const id = parentId ?? this.rootId\n const parent = this.nodes.get(id)\n if (!parent) return []\n const result: Array<{ node: SceneNode; depth: number }> = []\n for (const childId of parent.childIds) {\n const child = this.nodes.get(childId)\n if (!child) continue\n result.push({ node: child, depth })\n if (child.childIds.length > 0) result.push(...this.flattenTree(childId, depth + 1))\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAa,aAAb,MAAwB;CA+BO;CA9B7B,wBAAQ,IAAI,IAAuB;CACnC,yBAAS,IAAI,IAAwB;CACrC,4BAAY,IAAI,IAAsB;CACtC,sCAAsB,IAAI,IAAgC;CAC1D,6BAAa,IAAI,IAAoB;CACrC;CACA,iBAAgC;;CAEhC,oBAAuC;CACvC,qBAAyC;CACzC,eAA6B;CAC7B,mCAAmB,IAAI,IAAmC;CAC1D,UAAmB,IAAI,qBAAqB;CAC5C,8BAAsB,IAAI,IAAoB;CAC9C,cAA2D;EACzD,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,QAAQ;EACR,eAAe;CACjB;CACA,mBAAkD,CAAC;CACnD,kCAAmC,IAAI,IAAwB;CAC/D;CACA,eAA4C;CAC5C,yBAAyB;CACzB,gCAAgB,IAAI,IAAyB;;CAE7C,+BAAe,IAAI,IAAY;CAE/B,YAAY,cAA6C,YAAY;EAAxC,KAAA,cAAA;EAC3B,MAAM,OAAO,kBAAkB,KAAK,aAAa,SAAS;GACxD,MAAM;GACN,OAAO;GACP,QAAQ;EACV,CAAC;EACD,KAAK,SAAS,KAAK;EACnB,KAAK,MAAM,IAAI,KAAK,IAAI,IAAI;EAE5B,KAAK,QAAQ,QAAQ;CACvB;CACA,QAAQ,MAAyB;EAC/B,OAAO,KAAK,WAAW,UAAU,KAAK,QAAQ;GAAE;GAAM,OAAO;GAAG,QAAQ;EAAE,CAAC;CAC7E;CAEA,SAAS,kBAAkB,OAAoB;EAC7C,OAAO,KAAK,YAAY,KAAK,MAAM,CAAC,CAAC,QAClC,MAAM,EAAE,SAAS,aAAa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BACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;iBA2Ea,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,eACC;;iBA6Ba,gBAAgB,OAAO,YAAY;;;;;iBASnC,qBACd,OAAO,YACP,YACA,YACA,kBACC;;;;;;;;iBA0Ea,kBAAkB,OAAO,YAAY,MAAM,MAAM,kBAAkB;;iBASnE,cAAc,OAAO,YAAY,gBAAgB,YAAY;UAgE5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}
1
+ {"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;;iBAqTgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;iBA2Ea,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,eACC;;iBA6Ba,gBAAgB,OAAO,YAAY;;;;;iBASnC,qBACd,OAAO,YACP,YACA,YACA,kBACC;;;;;;;;iBA0Ea,kBAAkB,OAAO,YAAY,MAAM,MAAM,kBAAkB;;iBASnE,cAAc,OAAO,YAAY,gBAAgB,YAAY;UAgE5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}