@pairdraw/scene-graph 0.16.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/checkpoint.d.ts.map +1 -1
  2. package/dist/checkpoint.js +8 -3
  3. package/dist/checkpoint.js.map +1 -1
  4. package/dist/color/index.d.ts.map +1 -1
  5. package/dist/color/index.js +3 -3
  6. package/dist/color/index.js.map +1 -1
  7. package/dist/color/management.d.ts.map +1 -1
  8. package/dist/color/management.js +4 -2
  9. package/dist/color/management.js.map +1 -1
  10. package/dist/coordinate.d.ts.map +1 -1
  11. package/dist/coordinate.js +3 -1
  12. package/dist/coordinate.js.map +1 -1
  13. package/dist/copy.d.ts.map +1 -1
  14. package/dist/copy.js +7 -3
  15. package/dist/copy.js.map +1 -1
  16. package/dist/css/values.d.ts.map +1 -1
  17. package/dist/css/values.js +2 -2
  18. package/dist/css/values.js.map +1 -1
  19. package/dist/effects.d.ts +16 -0
  20. package/dist/effects.d.ts.map +1 -0
  21. package/dist/effects.js +78 -0
  22. package/dist/effects.js.map +1 -0
  23. package/dist/geometry.d.ts +14 -7
  24. package/dist/geometry.d.ts.map +1 -1
  25. package/dist/geometry.js +130 -26
  26. package/dist/geometry.js.map +1 -1
  27. package/dist/graph.d.ts.map +1 -1
  28. package/dist/graph.js +12 -3
  29. package/dist/graph.js.map +1 -1
  30. package/dist/hit-test.d.ts.map +1 -1
  31. package/dist/hit-test.js +100 -8
  32. package/dist/hit-test.js.map +1 -1
  33. package/dist/instances/content-size.js +1 -1
  34. package/dist/instances/index.d.ts.map +1 -1
  35. package/dist/instances/index.js +4 -1
  36. package/dist/instances/index.js.map +1 -1
  37. package/dist/instances/sync.js +4 -3
  38. package/dist/instances/sync.js.map +1 -1
  39. package/dist/layout/index.js +1 -1
  40. package/dist/node-defaults.d.ts.map +1 -1
  41. package/dist/node-defaults.js +4 -1
  42. package/dist/node-defaults.js.map +1 -1
  43. package/dist/preview.d.ts.map +1 -1
  44. package/dist/preview.js +5 -0
  45. package/dist/preview.js.map +1 -1
  46. package/dist/resize.d.ts +4 -1
  47. package/dist/resize.d.ts.map +1 -1
  48. package/dist/resize.js +18 -12
  49. package/dist/resize.js.map +1 -1
  50. package/dist/scaling/node.d.ts.map +1 -1
  51. package/dist/scaling/node.js +3 -1
  52. package/dist/scaling/node.js.map +1 -1
  53. package/dist/scaling/tree.d.ts.map +1 -1
  54. package/dist/scaling/tree.js +8 -5
  55. package/dist/scaling/tree.js.map +1 -1
  56. package/dist/slots/authoring.js +3 -6
  57. package/dist/slots/authoring.js.map +1 -1
  58. package/dist/slots/content.d.ts.map +1 -1
  59. package/dist/slots/content.js +15 -25
  60. package/dist/slots/content.js.map +1 -1
  61. package/dist/slots/frames.js +1 -2
  62. package/dist/slots/frames.js.map +1 -1
  63. package/dist/snap.d.ts.map +1 -1
  64. package/dist/snap.js +12 -4
  65. package/dist/snap.js.map +1 -1
  66. package/dist/types.d.ts +5 -0
  67. package/dist/types.d.ts.map +1 -1
  68. package/dist/types.js.map +1 -1
  69. package/dist/undo.d.ts +2 -1
  70. package/dist/undo.d.ts.map +1 -1
  71. package/dist/undo.js +3 -2
  72. package/dist/undo.js.map +1 -1
  73. package/dist/variables/bindings.d.ts +2 -1
  74. package/dist/variables/bindings.d.ts.map +1 -1
  75. package/dist/variables/bindings.js +6 -2
  76. package/dist/variables/bindings.js.map +1 -1
  77. package/dist/variables/index.d.ts +2 -1
  78. package/dist/variables/index.d.ts.map +1 -1
  79. package/dist/variables/index.js +37 -7
  80. package/dist/variables/index.js.map +1 -1
  81. package/dist/variables/units.d.ts +31 -0
  82. package/dist/variables/units.d.ts.map +1 -0
  83. package/dist/variables/units.js +79 -4
  84. package/dist/variables/units.js.map +1 -1
  85. package/package.json +6 -1
  86. package/src/checkpoint.ts +8 -2
  87. package/src/color/index.ts +4 -6
  88. package/src/color/management.ts +8 -2
  89. package/src/coordinate.ts +4 -1
  90. package/src/copy.ts +8 -3
  91. package/src/css/values.ts +3 -2
  92. package/src/effects.ts +76 -0
  93. package/src/geometry.ts +147 -24
  94. package/src/graph.ts +13 -3
  95. package/src/hit-test.ts +138 -16
  96. package/src/instances/index.ts +5 -1
  97. package/src/instances/sync.ts +5 -3
  98. package/src/node-defaults.ts +4 -1
  99. package/src/preview.ts +4 -0
  100. package/src/resize.ts +40 -20
  101. package/src/scaling/node.ts +3 -1
  102. package/src/scaling/tree.ts +3 -2
  103. package/src/slots/authoring.ts +7 -7
  104. package/src/slots/content.ts +13 -19
  105. package/src/slots/frames.ts +3 -3
  106. package/src/snap.ts +14 -4
  107. package/src/types.ts +5 -0
  108. package/src/undo.ts +3 -2
  109. package/src/variables/bindings.ts +6 -2
  110. package/src/variables/index.ts +49 -8
  111. package/src/variables/units.ts +97 -4
@@ -0,0 +1,78 @@
1
+ //#region src/effects.ts
2
+ const SHADOW_OFFSET = {
3
+ x: 0,
4
+ y: 4
5
+ };
6
+ const BLUR_OFFSET = {
7
+ x: 0,
8
+ y: 0
9
+ };
10
+ function fallbackOffset(type) {
11
+ return type === "DROP_SHADOW" || type === "INNER_SHADOW" ? SHADOW_OFFSET : BLUR_OFFSET;
12
+ }
13
+ function component(offset, key, fallback) {
14
+ if (!(key in offset)) return fallback;
15
+ const value = Reflect.get(offset, key);
16
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
17
+ }
18
+ /** A new offset when `effect.offset` is missing or not finite; null when it can stay. */
19
+ function finiteOffset(effect) {
20
+ const fallback = fallbackOffset(effect.type);
21
+ const offset = effect.offset;
22
+ if (offset === null || typeof offset !== "object") return {
23
+ x: fallback.x,
24
+ y: fallback.y
25
+ };
26
+ const x = component(offset, "x", fallback.x);
27
+ const y = component(offset, "y", fallback.y);
28
+ if (Reflect.get(offset, "x") === x && Reflect.get(offset, "y") === y) return null;
29
+ return {
30
+ x,
31
+ y
32
+ };
33
+ }
34
+ function isStoredShadow(effect) {
35
+ const offset = effect.offset;
36
+ return !!offset && typeof offset.x === "number" && Number.isFinite(offset.x) && typeof offset.y === "number" && Number.isFinite(offset.y);
37
+ }
38
+ function withFiniteOffset(effect) {
39
+ const offset = finiteOffset(effect);
40
+ if (!offset) {
41
+ if (isStoredShadow(effect)) return effect;
42
+ return {
43
+ ...effect,
44
+ offset: fallbackOffset(effect.type)
45
+ };
46
+ }
47
+ return {
48
+ ...effect,
49
+ offset
50
+ };
51
+ }
52
+ function isStoredEffect(effect) {
53
+ return effect.type === "SHADER" || isStoredShadow(effect);
54
+ }
55
+ /**
56
+ * Shadows and blurs keep a finite offset. A drop or inner shadow missing one uses `{x: 0, y: 4}`,
57
+ * the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader effects
58
+ * are left alone. An array that is already valid is returned as itself.
59
+ */
60
+ function normalizeEffects(effects) {
61
+ let next = null;
62
+ for (const [index, effect] of effects.entries()) {
63
+ const normalized = effect.type === "SHADER" ? effect : withFiniteOffset(effect);
64
+ if (normalized === effect) {
65
+ if (next && isStoredEffect(effect)) next.push(effect);
66
+ continue;
67
+ }
68
+ next ??= effects.slice(0, index).filter(isStoredEffect);
69
+ next.push(normalized);
70
+ }
71
+ if (next) return next;
72
+ if (effects.every(isStoredEffect)) return effects;
73
+ return effects.filter(isStoredEffect);
74
+ }
75
+ //#endregion
76
+ export { normalizeEffects };
77
+
78
+ //# sourceMappingURL=effects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.js","names":[],"sources":["../src/effects.ts"],"sourcesContent":["import type { Vector } from './primitives'\nimport type { Effect, ShaderEffect, ShadowEffect } from './types'\n\nconst SHADOW_OFFSET: Vector = { x: 0, y: 4 }\nconst BLUR_OFFSET: Vector = { x: 0, y: 0 }\n\n/** A shadow or blur whose offset may still be missing or only partly present. */\ntype ShadowInput = Omit<ShadowEffect, 'offset'> & {\n offset?: Partial<Vector> | null\n}\n\nfunction fallbackOffset(type: ShadowEffect['type']): Vector {\n return type === 'DROP_SHADOW' || type === 'INNER_SHADOW' ? SHADOW_OFFSET : BLUR_OFFSET\n}\n\nfunction component(offset: object, key: 'x' | 'y', fallback: number): number {\n if (!(key in offset)) return fallback\n const value: unknown = Reflect.get(offset, key)\n return typeof value === 'number' && Number.isFinite(value) ? value : fallback\n}\n\n/** A new offset when `effect.offset` is missing or not finite; null when it can stay. */\nfunction finiteOffset(effect: ShadowInput): Vector | null {\n const fallback = fallbackOffset(effect.type)\n const offset: unknown = effect.offset\n if (offset === null || typeof offset !== 'object') return { x: fallback.x, y: fallback.y }\n const x = component(offset, 'x', fallback.x)\n const y = component(offset, 'y', fallback.y)\n if (Reflect.get(offset, 'x') === x && Reflect.get(offset, 'y') === y) return null\n return { x, y }\n}\n\nfunction isStoredShadow(effect: ShadowInput): effect is ShadowEffect {\n const offset = effect.offset\n return (\n !!offset &&\n typeof offset.x === 'number' &&\n Number.isFinite(offset.x) &&\n typeof offset.y === 'number' &&\n Number.isFinite(offset.y)\n )\n}\n\nfunction withFiniteOffset(effect: ShadowInput): Effect {\n const offset = finiteOffset(effect)\n if (!offset) {\n if (isStoredShadow(effect)) return effect\n return { ...effect, offset: fallbackOffset(effect.type) }\n }\n return { ...effect, offset }\n}\n\nfunction isStoredEffect(effect: ShaderEffect | ShadowInput): effect is Effect {\n return effect.type === 'SHADER' || isStoredShadow(effect)\n}\n\n/**\n * Shadows and blurs keep a finite offset. A drop or inner shadow missing one uses `{x: 0, y: 4}`,\n * the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader effects\n * are left alone. An array that is already valid is returned as itself.\n */\nexport function normalizeEffects(effects: (ShaderEffect | ShadowInput)[]): Effect[] {\n let next: Effect[] | null = null\n for (const [index, effect] of effects.entries()) {\n const normalized = effect.type === 'SHADER' ? effect : withFiniteOffset(effect)\n if (normalized === effect) {\n if (next && isStoredEffect(effect)) next.push(effect)\n continue\n }\n next ??= effects.slice(0, index).filter(isStoredEffect)\n next.push(normalized)\n }\n if (next) return next\n if (effects.every(isStoredEffect)) return effects\n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AAO;AAC7B;AAEA,SAAS,eAAe,QAAsD;CAC5E,OAAO,OAAO,SAAS,YAAY,eAAe,MAAM;AAC1D;;;;;;AAOA,SAAgB,iBAAiB,SAAmD;CAClF,IAAI,OAAwB;CAC5B,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,QAAQ,GAAG;EAC/C,MAAM,aAAa,OAAO,SAAS,WAAW,SAAS,iBAAiB,MAAM;EAC9E,IAAI,eAAe,QAAQ;GACzB,IAAI,QAAQ,eAAe,MAAM,GAAG,KAAK,KAAK,MAAM;GACpD;EACF;EACA,SAAS,QAAQ,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,cAAc;EACtD,KAAK,KAAK,UAAU;CACtB;CACA,IAAI,MAAM,OAAO;CACjB,IAAI,QAAQ,MAAM,cAAc,GAAG,OAAO;CAC1C,OAAO,QAAQ,OAAO,cAAc;AACtC"}
@@ -1,5 +1,6 @@
1
1
  import { Rect, Vector } from "./primitives/index.js";
2
- import { Effect, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
2
+ import { SceneGraph } from "./graph.js";
3
+ import { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
3
4
  //#region src/geometry.d.ts
4
5
  declare function degToRad(degrees: number): number;
5
6
  declare function radToDeg(radians: number): number;
@@ -43,16 +44,15 @@ declare function effectOverflow(effects?: Effect[]): {
43
44
  top: number;
44
45
  bottom: number;
45
46
  };
46
- declare function computeAbsoluteBounds(nodes: Iterable<{
47
- id: string;
48
- width: number;
49
- height: number;
50
- }>, getAbsolutePosition: (id: string) => Vector): Rect;
47
+ /** Axis-aligned canvas box around the layers, through each one's rotation, flips, and ancestors. */
48
+ declare function computeAbsoluteBounds(nodes: Iterable<SceneNode>, graph: Pick<SceneGraph, 'getNode'>): Rect;
51
49
  declare function computeVisualBounds(nodes: Iterable<{
52
50
  id: string;
53
51
  width: number;
54
52
  height: number;
55
53
  rotation?: number;
54
+ flipX?: boolean;
55
+ flipY?: boolean;
56
56
  strokes?: Stroke[];
57
57
  strokeCap?: StrokeCap;
58
58
  vectorNetwork?: VectorNetwork | null;
@@ -96,10 +96,17 @@ declare function geometryCommandCoordCount(command: number): number | null;
96
96
  declare function geometryBlobBounds(paths: Array<{
97
97
  commandsBlob: Uint8Array;
98
98
  }>): Rect | null;
99
+ /**
100
+ * The subpaths a layer's geometry blobs draw, as polylines in its own coordinates. Curves are
101
+ * sampled, so a caller can test a point against the outline without a path engine.
102
+ */
103
+ declare function geometryBlobPolylines(paths: Array<{
104
+ commandsBlob: Uint8Array;
105
+ }>, curveSteps?: number): Vector[][];
99
106
  declare function nodeVisualBounds(node: VisualBoundsNode, getAbsolutePosition: (id: string) => Vector): VisualBounds;
100
107
  /** How far a text node's underline or strikethrough reaches below its box. */
101
108
  declare function textDecorationOverflow(node: VisualBoundsNode): number;
102
109
  declare function computeDescendantVisualBounds(nodeIds: string[], getNode: (id: string) => VisualBoundsNode | undefined, getAbsolutePosition: (id: string) => Vector): VisualBounds | null;
103
110
  //#endregion
104
- export { StrokeShape, VisualBounds, VisualBoundsNode, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
111
+ export { StrokeShape, VisualBounds, VisualBoundsNode, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
105
112
  //# sourceMappingURL=geometry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;iBAKgB,SAAS;iBAIT,SAAS;iBAIT,YAAY,YAAY,YAAY,YAAY,YAAY,cAAc;iBAS1E,eACd,YACA,YACA,YACA,YACA,uBACE,QAAQ,QAAQ,QAAQ;iBAYZ,YACd,WACA,WACA,WACA,WACA;EACG;EAAc;EAAe;EAAa;EAAgB;EAAiB;;UAyB/D;EACf;EACA;EACA;EACA;;iBAgCc,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;;;;UA0Ba;EACf;EACA,aAAa;EACb;;iBAGc,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;iBA+DM,eAAe,UAAU;;;;;;iBAyBzB,sBACd,OAAO;EAAW;EAAY;EAAe;IAC7C,sBAAsB,eAAe,SACpC;iBASa,oBACd,OAAO;EAEH;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;IACR,cAEN,sBAAsB,eAAe,SACpC;UAec;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,eAAe;IAAQ,cAAc;;EACrC,iBAAiB;IAAQ,cAAc;;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;;;;;iBAazD,0BAA0B;iBAQ1B,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;iBAoDhE,iBACd,MAAM,kBACN,sBAAsB,eAAe,SACpC;;iBAiCa,uBAAuB,MAAM;iBA6C7B,8BACd,mBACA,UAAU,eAAe,8BACzB,sBAAsB,eAAe,SACpC"}
1
+ {"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAOgB,SAAS;iBAIT,SAAS;iBAIT,YAAY,YAAY,YAAY,YAAY,YAAY,cAAc;iBAS1E,eACd,YACA,YACA,YACA,YACA,uBACE,QAAQ,QAAQ,QAAQ;iBAYZ,YACd,WACA,WACA,WACA,WACA;EACG;EAAc;EAAe;EAAa;EAAgB;EAAiB;;UAyB/D;EACf;EACA;EACA;EACA;;iBAgCc,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;;;;UA0Ba;EACf;EACA,aAAa;EACb;;iBAGc,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;iBA+DM,eAAe,UAAU;;;;;;;iBA0BzB,sBACd,OAAO,SAAS,YAChB,OAAO,KAAK,yBACX;iBAMa,oBACd,OAAO;EAEH;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;IACR,cAEN,sBAAsB,eAAe,SACpC;UAec;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,eAAe;IAAQ,cAAc;;EACrC,iBAAiB;IAAQ,cAAc;;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;;;;;iBAazD,0BAA0B;iBAQ1B,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;;;;;iBAsHhE,sBACd,OAAO;EAAQ,cAAc;IAC7B,sBACC;iBAmDa,iBACd,MAAM,kBACN,sBAAsB,eAAe,SACpC;;iBAiCa,uBAAuB,MAAM;iBA8C7B,8BACd,mBACA,UAAU,eAAe,8BACzB,sBAAsB,eAAe,SACpC"}
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,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;CACxC;AACF;AAEA,SAAgB,eACd,IACA,IACA,IACA,IACA,aACkC;CAClC,MAAM,MAAM,SAAS,WAAW;CAChC,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;EAAI;EAC/D;GAAE,GAAG,KAAK,KAAK,MA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M,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,KAAK,MAAM,OAAO,KAAK,MAAM;CACxC;AACF;AAEA,SAAgB,eACd,IACA,IACA,IACA,IACA,aACkC;CAClC,MAAM,MAAM,SAAS,WAAW;CAChC,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;EAAI;EAC/D;GAAE,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;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nD,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
@@ -1,6 +1,7 @@
1
1
  import { BufferedSceneEmitter } from "./buffered-events.js";
2
2
  import { removeStaleBindings } from "./bindings.js";
3
3
  import Matrix from "./matrix.js";
4
+ import { normalizeEffects } from "./effects.js";
4
5
  import { CONTAINER_TYPES, createDefaultNode } from "./node-defaults.js";
5
6
  import { getAbsolutePosition, getNodeLocalMatrix, getParentWorldMatrix, isTranslationOnly, localTransformFromWorld } from "./coordinate.js";
6
7
  import { normalizeVectorNetwork } from "./vector-network.js";
@@ -315,16 +316,20 @@ var SceneGraph = class {
315
316
  return this.emitter.batch(action);
316
317
  }
317
318
  createNode(type, parentId, overrides = {}) {
318
- const node = createDefaultNode(() => this.generateEntityId(), type, overrides);
319
319
  const parent = this.nodes.get(parentId);
320
+ if (!parent) throw new Error(`Parent "${parentId}" does not exist`);
321
+ const node = createDefaultNode(() => this.generateEntityId(), type, overrides);
320
322
  this.willChangeNode(parent);
321
- parent?.childIds.push(node.id);
323
+ parent.childIds.push(node.id);
322
324
  return this.registerNode(node, parentId);
323
325
  }
324
326
  createNodeWithId(id, type, parentId, overrides = {}) {
327
+ if (this.nodes.has(id)) throw new Error(`Node "${id}" already exists`);
328
+ if (parentId === id) throw new Error(`Node "${id}" cannot be its own parent`);
329
+ const parent = parentId === null ? void 0 : this.nodes.get(parentId);
330
+ if (parentId !== null && !parent) throw new Error(`Parent "${parentId}" does not exist`);
325
331
  const node = createDefaultNode(() => id, type, overrides);
326
332
  node.id = id;
327
- const parent = parentId ? this.nodes.get(parentId) : void 0;
328
333
  if (parent && !parent.childIds.includes(id)) {
329
334
  this.willChangeNode(parent);
330
335
  parent.childIds.push(id);
@@ -457,6 +462,10 @@ var SceneGraph = class {
457
462
  ...changes,
458
463
  vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork)
459
464
  };
465
+ if (changes.effects) changes = {
466
+ ...changes,
467
+ effects: normalizeEffects(changes.effects)
468
+ };
460
469
  this.layoutWrites?.record(node, changes, this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout);
461
470
  Object.assign(node, changes);
462
471
  if (changes.fills) removeStaleBindings(node, "fills", changes);