@open-pencil/scene-graph 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +5 -0
  2. package/dist/chunks/bindings.js +18 -0
  3. package/dist/chunks/bindings.js.map +1 -0
  4. package/dist/chunks/coordinate.js +293 -0
  5. package/dist/chunks/coordinate.js.map +1 -0
  6. package/dist/chunks/copy.js +576 -0
  7. package/dist/chunks/copy.js.map +1 -0
  8. package/dist/chunks/events.js +18 -0
  9. package/dist/chunks/events.js.map +1 -0
  10. package/dist/chunks/export-scale.js +19 -0
  11. package/dist/chunks/export-scale.js.map +1 -0
  12. package/dist/chunks/font-style.js +95 -0
  13. package/dist/chunks/font-style.js.map +1 -0
  14. package/dist/constants.d.ts +2 -0
  15. package/dist/constants.js +19 -0
  16. package/dist/constants.js.map +1 -0
  17. package/dist/constants2.d.ts +10 -0
  18. package/dist/constants2.d.ts.map +1 -0
  19. package/dist/coordinate.d.ts +352 -0
  20. package/dist/coordinate.d.ts.map +1 -0
  21. package/dist/coordinate.js +2 -0
  22. package/dist/coordinate2.d.ts +2 -0
  23. package/dist/copy.d.ts +2 -0
  24. package/dist/copy.js +2 -0
  25. package/dist/geometry.d.ts +2 -0
  26. package/dist/geometry.js +431 -0
  27. package/dist/geometry.js.map +1 -0
  28. package/dist/hit-test.d.ts +10 -0
  29. package/dist/hit-test.d.ts.map +1 -0
  30. package/dist/hit-test.js +97 -0
  31. package/dist/hit-test.js.map +1 -0
  32. package/dist/images.d.ts +2 -0
  33. package/dist/images.js +45 -0
  34. package/dist/images.js.map +1 -0
  35. package/dist/images2.d.ts +5 -0
  36. package/dist/images2.d.ts.map +1 -0
  37. package/dist/index.d.ts +9 -0
  38. package/dist/index.js +9 -0
  39. package/dist/instances.d.ts +2 -0
  40. package/dist/instances.js +2 -0
  41. package/dist/matrix.d.ts +2 -0
  42. package/dist/matrix.js +2 -0
  43. package/dist/matrix2.d.ts +17 -0
  44. package/dist/matrix2.d.ts.map +1 -0
  45. package/dist/node-defaults.d.ts +9 -0
  46. package/dist/node-defaults.d.ts.map +1 -0
  47. package/dist/node-defaults.js +2 -0
  48. package/dist/parse-path.d.ts +23 -0
  49. package/dist/parse-path.d.ts.map +1 -0
  50. package/dist/parse-path.js +159 -0
  51. package/dist/parse-path.js.map +1 -0
  52. package/dist/preview.d.ts +12 -0
  53. package/dist/preview.d.ts.map +1 -0
  54. package/dist/preview.js +2 -0
  55. package/dist/primitives.d.ts +2 -0
  56. package/dist/primitives.js +0 -0
  57. package/dist/primitives2.d.ts +42 -0
  58. package/dist/primitives2.d.ts.map +1 -0
  59. package/dist/resize.d.ts +16 -0
  60. package/dist/resize.d.ts.map +1 -0
  61. package/dist/resize.js +136 -0
  62. package/dist/resize.js.map +1 -0
  63. package/dist/snap.d.ts +2 -0
  64. package/dist/snap.js +2 -0
  65. package/dist/source-metadata.d.ts +7 -0
  66. package/dist/source-metadata.d.ts.map +1 -0
  67. package/dist/source-metadata.js +2 -0
  68. package/dist/text-picture.d.ts +7 -0
  69. package/dist/text-picture.d.ts.map +1 -0
  70. package/dist/text-picture.js +2 -0
  71. package/dist/types.d.ts +2 -0
  72. package/dist/types.js +1296 -0
  73. package/dist/types.js.map +1 -0
  74. package/dist/types2.d.ts +430 -0
  75. package/dist/types2.d.ts.map +1 -0
  76. package/dist/undo.d.ts +2 -0
  77. package/dist/undo.js +2 -0
  78. package/dist/undo2.d.ts +40 -0
  79. package/dist/undo2.d.ts.map +1 -0
  80. package/dist/variables.d.ts +30 -0
  81. package/dist/variables.d.ts.map +1 -0
  82. package/dist/variables.js +2 -0
  83. package/dist/variant-name.d.ts +6 -0
  84. package/dist/variant-name.d.ts.map +1 -0
  85. package/dist/variant-name.js +17 -0
  86. package/dist/variant-name.js.map +1 -0
  87. package/dist/vector-network.d.ts +2 -0
  88. package/dist/vector-network.js +2 -0
  89. package/dist/vector-network2.d.ts +33 -0
  90. package/dist/vector-network2.d.ts.map +1 -0
  91. package/package.json +157 -0
@@ -0,0 +1,431 @@
1
+ //#region src/geometry.ts
2
+ function degToRad(degrees) {
3
+ return degrees * Math.PI / 180;
4
+ }
5
+ function radToDeg(radians) {
6
+ return radians * 180 / Math.PI;
7
+ }
8
+ function rotatePoint(px, py, cx, cy, rad) {
9
+ const cos = Math.cos(rad);
10
+ const sin = Math.sin(rad);
11
+ return {
12
+ x: cx + (px - cx) * cos - (py - cy) * sin,
13
+ y: cy + (px - cx) * sin + (py - cy) * cos
14
+ };
15
+ }
16
+ function rotatedCorners(cx, cy, hw, hh, rotationDeg) {
17
+ const rad = degToRad(rotationDeg);
18
+ const cos = Math.cos(rad);
19
+ const sin = Math.sin(rad);
20
+ return [
21
+ {
22
+ x: cx + -hw * cos - -hh * sin,
23
+ y: cy + -hw * sin + -hh * cos
24
+ },
25
+ {
26
+ x: cx + hw * cos - -hh * sin,
27
+ y: cy + hw * sin + -hh * cos
28
+ },
29
+ {
30
+ x: cx + hw * cos - hh * sin,
31
+ y: cy + hw * sin + hh * cos
32
+ },
33
+ {
34
+ x: cx + -hw * cos - hh * sin,
35
+ y: cy + -hw * sin + hh * cos
36
+ }
37
+ ];
38
+ }
39
+ function rotatedBBox(x, y, w, h, rotationDeg) {
40
+ if (rotationDeg === 0) return {
41
+ left: x,
42
+ right: x + w,
43
+ top: y,
44
+ bottom: y + h,
45
+ centerX: x + w / 2,
46
+ centerY: y + h / 2
47
+ };
48
+ const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg);
49
+ let left = Infinity, right = -Infinity, top = Infinity, bottom = -Infinity;
50
+ for (const c of corners) {
51
+ left = Math.min(left, c.x);
52
+ right = Math.max(right, c.x);
53
+ top = Math.min(top, c.y);
54
+ bottom = Math.max(bottom, c.y);
55
+ }
56
+ return {
57
+ left,
58
+ right,
59
+ top,
60
+ bottom,
61
+ centerX: (left + right) / 2,
62
+ centerY: (top + bottom) / 2
63
+ };
64
+ }
65
+ function createBoundsAccumulator() {
66
+ return {
67
+ minX: Infinity,
68
+ minY: Infinity,
69
+ maxX: -Infinity,
70
+ maxY: -Infinity
71
+ };
72
+ }
73
+ function includePoint(bounds, x, y) {
74
+ bounds.minX = Math.min(bounds.minX, x);
75
+ bounds.minY = Math.min(bounds.minY, y);
76
+ bounds.maxX = Math.max(bounds.maxX, x);
77
+ bounds.maxY = Math.max(bounds.maxY, y);
78
+ }
79
+ function includeRect(bounds, rect) {
80
+ includePoint(bounds, rect.x, rect.y);
81
+ includePoint(bounds, rect.x + rect.width, rect.y + rect.height);
82
+ }
83
+ function boundsToRect(bounds) {
84
+ return bounds.minX === Infinity ? {
85
+ x: 0,
86
+ y: 0,
87
+ width: 0,
88
+ height: 0
89
+ } : {
90
+ x: bounds.minX,
91
+ y: bounds.minY,
92
+ width: bounds.maxX - bounds.minX,
93
+ height: bounds.maxY - bounds.minY
94
+ };
95
+ }
96
+ function computeBounds(items) {
97
+ const bounds = createBoundsAccumulator();
98
+ for (const item of items) includeRect(bounds, item);
99
+ return boundsToRect(bounds);
100
+ }
101
+ function polygonVertices(node) {
102
+ const cx = node.width / 2;
103
+ const cy = node.height / 2;
104
+ const rx = node.width / 2;
105
+ const ry = node.height / 2;
106
+ const pointCount = Math.max(3, node.pointCount);
107
+ const isStar = node.type === "STAR";
108
+ const innerRatio = isStar ? node.starInnerRadius : 1;
109
+ const totalPoints = isStar ? pointCount * 2 : pointCount;
110
+ const angleOffset = -Math.PI / 2;
111
+ return Array.from({ length: totalPoints }, (_, index) => {
112
+ const angle = angleOffset + 2 * Math.PI * index / totalPoints;
113
+ const radius = isStar && index % 2 === 1 ? innerRatio : 1;
114
+ return {
115
+ x: cx + rx * radius * Math.cos(angle),
116
+ y: cy + ry * radius * Math.sin(angle)
117
+ };
118
+ });
119
+ }
120
+ function strokeOverflow(strokes) {
121
+ let overflow = 0;
122
+ for (const stroke of strokes ?? []) {
123
+ if (!stroke.visible) continue;
124
+ let extra = 0;
125
+ if (stroke.align === "OUTSIDE") extra = stroke.weight;
126
+ else if (stroke.align === "CENTER") extra = stroke.weight / 2;
127
+ overflow = Math.max(overflow, extra);
128
+ }
129
+ return overflow;
130
+ }
131
+ function effectOverflow(effects) {
132
+ let left = 0;
133
+ let right = 0;
134
+ let top = 0;
135
+ let bottom = 0;
136
+ for (const effect of effects ?? []) {
137
+ if (!effect.visible) continue;
138
+ if (effect.type !== "DROP_SHADOW" && effect.type !== "LAYER_BLUR" && effect.type !== "FOREGROUND_BLUR") continue;
139
+ const blurSpread = effect.radius + effect.spread;
140
+ left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x));
141
+ right = Math.max(right, blurSpread + Math.max(0, effect.offset.x));
142
+ top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y));
143
+ bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y));
144
+ }
145
+ return {
146
+ left,
147
+ right,
148
+ top,
149
+ bottom
150
+ };
151
+ }
152
+ function computeAbsoluteBounds(nodes, getAbsolutePosition) {
153
+ const bounds = createBoundsAccumulator();
154
+ for (const n of nodes) {
155
+ const abs = getAbsolutePosition(n.id);
156
+ includeRect(bounds, {
157
+ x: abs.x,
158
+ y: abs.y,
159
+ width: n.width,
160
+ height: n.height
161
+ });
162
+ }
163
+ return boundsToRect(bounds);
164
+ }
165
+ function computeVisualBounds(nodes, getAbsolutePosition) {
166
+ const bounds = createBoundsAccumulator();
167
+ for (const n of nodes) {
168
+ const abs = getAbsolutePosition(n.id);
169
+ const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0);
170
+ const stroke = strokeOverflow(n.strokes);
171
+ const effects = effectOverflow(n.effects);
172
+ includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top);
173
+ includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom);
174
+ }
175
+ return boundsToRect(bounds);
176
+ }
177
+ function unionVisualBounds(a, b) {
178
+ if (!a) return b;
179
+ if (!b) return a;
180
+ return {
181
+ minX: Math.min(a.minX, b.minX),
182
+ minY: Math.min(a.minY, b.minY),
183
+ maxX: Math.max(a.maxX, b.maxX),
184
+ maxY: Math.max(a.maxY, b.maxY)
185
+ };
186
+ }
187
+ function intersectVisualBounds(a, b) {
188
+ const minX = Math.max(a.minX, b.minX);
189
+ const minY = Math.max(a.minY, b.minY);
190
+ const maxX = Math.min(a.maxX, b.maxX);
191
+ const maxY = Math.min(a.maxY, b.maxY);
192
+ return minX < maxX && minY < maxY ? {
193
+ minX,
194
+ minY,
195
+ maxX,
196
+ maxY
197
+ } : null;
198
+ }
199
+ function geometryCommandCoordCount(command) {
200
+ if (command === 0) return 0;
201
+ if (command === 1 || command === 2) return 1;
202
+ if (command === 4) return 3;
203
+ return null;
204
+ }
205
+ function geometryBlobBounds(paths) {
206
+ const bounds = createBoundsAccumulator();
207
+ for (const path of paths) {
208
+ const blob = path.commandsBlob;
209
+ const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
210
+ let offset = 0;
211
+ while (offset < blob.length) {
212
+ const command = blob[offset++];
213
+ const coords = geometryCommandCoordCount(command);
214
+ if (coords == null) break;
215
+ for (let i = 0; i < coords; i++) {
216
+ if (offset + 8 > blob.length) break;
217
+ includePoint(bounds, dv.getFloat32(offset, true), dv.getFloat32(offset + 4, true));
218
+ offset += 8;
219
+ }
220
+ }
221
+ }
222
+ return bounds.minX === Infinity ? null : boundsToRect(bounds);
223
+ }
224
+ function transformLocalPoint(node, point) {
225
+ let x = node.flipX ? node.width - point.x : point.x;
226
+ let y = node.flipY ? node.height - point.y : point.y;
227
+ const rotation = node.rotation ?? 0;
228
+ if (rotation !== 0) {
229
+ const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation));
230
+ x = rotated.x;
231
+ y = rotated.y;
232
+ }
233
+ return {
234
+ x,
235
+ y
236
+ };
237
+ }
238
+ function transformedLocalBounds(node, local, abs) {
239
+ const points = [
240
+ {
241
+ x: local.x,
242
+ y: local.y
243
+ },
244
+ {
245
+ x: local.x + local.width,
246
+ y: local.y
247
+ },
248
+ {
249
+ x: local.x + local.width,
250
+ y: local.y + local.height
251
+ },
252
+ {
253
+ x: local.x,
254
+ y: local.y + local.height
255
+ }
256
+ ].map((point) => transformLocalPoint(node, point));
257
+ return {
258
+ minX: abs.x + Math.min(...points.map((point) => point.x)),
259
+ minY: abs.y + Math.min(...points.map((point) => point.y)),
260
+ maxX: abs.x + Math.max(...points.map((point) => point.x)),
261
+ maxY: abs.y + Math.max(...points.map((point) => point.y))
262
+ };
263
+ }
264
+ function nodeVisualBounds(node, getAbsolutePosition) {
265
+ const abs = getAbsolutePosition(node.id);
266
+ const base = computeVisualBounds([node], getAbsolutePosition);
267
+ let bounds = {
268
+ minX: base.x,
269
+ minY: base.y,
270
+ maxX: base.x + base.width,
271
+ maxY: base.y + base.height
272
+ };
273
+ const hasNonInsideStroke = node.strokes?.some((stroke) => stroke.visible && stroke.align !== "INSIDE");
274
+ const localGeometry = geometryBlobBounds([...node.fillGeometry ?? [], ...hasNonInsideStroke ? node.strokeGeometry ?? [] : []]);
275
+ if (localGeometry) bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds;
276
+ if (node.type === "TEXT" && node.textDecoration && node.textDecoration !== "NONE") {
277
+ const fontSize = node.fontSize ?? 14;
278
+ const underlineOffset = node.textUnderlineOffset ?? fontSize * .18;
279
+ const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16);
280
+ bounds.maxY += underlineOffset + thickness + fontSize * .35;
281
+ }
282
+ return bounds;
283
+ }
284
+ function collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition, clip = null) {
285
+ const node = getNode(nodeId);
286
+ if (!node?.visible) return null;
287
+ const own = nodeVisualBounds(node, getAbsolutePosition);
288
+ let bounds = clip ? intersectVisualBounds(own, clip) : own;
289
+ const isClippableContainer = node.type === "FRAME" || node.type === "COMPONENT" || node.type === "INSTANCE";
290
+ let childClip = clip;
291
+ if (isClippableContainer && node.clipsContent) {
292
+ const abs = getAbsolutePosition(node.id);
293
+ const nodeClip = {
294
+ minX: abs.x,
295
+ minY: abs.y,
296
+ maxX: abs.x + node.width,
297
+ maxY: abs.y + node.height
298
+ };
299
+ childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip;
300
+ if (!childClip) return bounds;
301
+ }
302
+ for (const childId of node.childIds ?? []) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip));
303
+ return bounds;
304
+ }
305
+ function computeDescendantVisualBounds(nodeIds, getNode, getAbsolutePosition) {
306
+ let bounds = null;
307
+ for (const nodeId of nodeIds) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition));
308
+ return bounds;
309
+ }
310
+ function crossProduct(a, b, p) {
311
+ return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);
312
+ }
313
+ function lineSegmentIntersect(p1, p2, p3, p4) {
314
+ const dx1 = p2.x - p1.x;
315
+ const dy1 = p2.y - p1.y;
316
+ const dx2 = p4.x - p3.x;
317
+ const dy2 = p4.y - p3.y;
318
+ const denom = dx1 * dy2 - dy1 * dx2;
319
+ if (denom === 0) return p1;
320
+ const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom;
321
+ return {
322
+ x: p1.x + t * dx1,
323
+ y: p1.y + t * dy1
324
+ };
325
+ }
326
+ function clipHalfPlane(polygon, a, b, wantPositive) {
327
+ const output = [];
328
+ const isInside = (p) => {
329
+ const cross = crossProduct(a, b, p);
330
+ return wantPositive ? cross >= 0 : cross <= 0;
331
+ };
332
+ for (let i = 0; i < polygon.length; i++) {
333
+ const curr = polygon[i];
334
+ const prev = polygon[i === 0 ? polygon.length - 1 : i - 1];
335
+ const currInside = isInside(curr);
336
+ const prevInside = isInside(prev);
337
+ if (currInside) {
338
+ if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
339
+ output.push(curr);
340
+ } else if (prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
341
+ }
342
+ return output;
343
+ }
344
+ /**
345
+ * Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space
346
+ * corners of a rotated clipping ancestor).
347
+ *
348
+ * Uses Sutherland–Hodgman polygon clipping with centroid-based interior
349
+ * detection, making it robust to either winding order of the clip polygon.
350
+ * Returns the clipped polygon, or null if the subject is fully outside the
351
+ * clip polygon. When `clipCorners` has fewer than 3 points the subject is
352
+ * returned unchanged (no clipping).
353
+ *
354
+ * Preserving the polygon (rather than collapsing to an AABB) lets callers
355
+ * chain multiple clips without reintroducing corners removed by an inner clip.
356
+ */
357
+ function clipPolygon(subject, clipCorners) {
358
+ if (clipCorners.length < 3) return subject;
359
+ let cx = 0;
360
+ let cy = 0;
361
+ for (const c of clipCorners) {
362
+ cx += c.x;
363
+ cy += c.y;
364
+ }
365
+ cx /= clipCorners.length;
366
+ cy /= clipCorners.length;
367
+ let polygon = subject;
368
+ for (let i = 0; i < clipCorners.length; i++) {
369
+ if (polygon.length === 0) return null;
370
+ const a = clipCorners[i];
371
+ const b = clipCorners[(i + 1) % clipCorners.length];
372
+ const centroidCross = crossProduct(a, b, {
373
+ x: cx,
374
+ y: cy
375
+ });
376
+ polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0);
377
+ }
378
+ return polygon.length === 0 ? null : polygon;
379
+ }
380
+ /**
381
+ * Clip an axis-aligned VisualBounds rectangle against a convex polygon
382
+ * (e.g. the 4 canvas-space corners of a rotated clipping ancestor).
383
+ *
384
+ * Returns the AABB of the intersection, or null if the bounds are fully
385
+ * outside the clip polygon. Delegates to {@link clipPolygon}.
386
+ *
387
+ * For a non-rotated clip (axis-aligned corners) the result is identical
388
+ * to `intersectVisualBounds`.
389
+ */
390
+ function clipBoundsToPolygon(bounds, clipCorners) {
391
+ if (clipCorners.length < 3) return bounds;
392
+ const polygon = clipPolygon([
393
+ {
394
+ x: bounds.minX,
395
+ y: bounds.minY
396
+ },
397
+ {
398
+ x: bounds.maxX,
399
+ y: bounds.minY
400
+ },
401
+ {
402
+ x: bounds.maxX,
403
+ y: bounds.maxY
404
+ },
405
+ {
406
+ x: bounds.minX,
407
+ y: bounds.maxY
408
+ }
409
+ ], clipCorners);
410
+ if (!polygon) return null;
411
+ let minX = Infinity;
412
+ let minY = Infinity;
413
+ let maxX = -Infinity;
414
+ let maxY = -Infinity;
415
+ for (const p of polygon) {
416
+ if (p.x < minX) minX = p.x;
417
+ if (p.y < minY) minY = p.y;
418
+ if (p.x > maxX) maxX = p.x;
419
+ if (p.y > maxY) maxY = p.y;
420
+ }
421
+ return minX < maxX && minY < maxY ? {
422
+ minX,
423
+ minY,
424
+ maxX,
425
+ maxY
426
+ } : null;
427
+ }
428
+ //#endregion
429
+ export { clipBoundsToPolygon, clipPolygon, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, unionVisualBounds };
430
+
431
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import type { Effect, Stroke } from './index'\nimport type { Rect, Vector } from './primitives'\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\nexport function strokeOverflow(strokes?: Stroke[]): number {\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n let extra = 0\n if (stroke.align === 'OUTSIDE') extra = stroke.weight\n else if (stroke.align === 'CENTER') extra = stroke.weight / 2\n overflow = Math.max(overflow, extra)\n }\n return overflow\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 id: string\n width: number\n height: number\n rotation?: number\n strokes?: Stroke[]\n effects?: Effect[]\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 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 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}\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\nfunction geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\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 if (node.type === 'TEXT' && node.textDecoration && node.textDecoration !== 'NONE') {\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 bounds.maxY += underlineOffset + thickness + fontSize * 0.35\n }\n\n return bounds\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\n// ── Rotated-rectangle clipping ──\n\nfunction crossProduct(a: Vector, b: Vector, p: Vector): number {\n return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x)\n}\n\nfunction lineSegmentIntersect(p1: Vector, p2: Vector, p3: Vector, p4: Vector): Vector {\n const dx1 = p2.x - p1.x\n const dy1 = p2.y - p1.y\n const dx2 = p4.x - p3.x\n const dy2 = p4.y - p3.y\n const denom = dx1 * dy2 - dy1 * dx2\n if (denom === 0) return p1\n const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom\n return { x: p1.x + t * dx1, y: p1.y + t * dy1 }\n}\n\nfunction clipHalfPlane(polygon: Vector[], a: Vector, b: Vector, wantPositive: boolean): Vector[] {\n const output: Vector[] = []\n const isInside = (p: Vector): boolean => {\n const cross = crossProduct(a, b, p)\n return wantPositive ? cross >= 0 : cross <= 0\n }\n for (let i = 0; i < polygon.length; i++) {\n const curr = polygon[i]\n const prev = polygon[i === 0 ? polygon.length - 1 : i - 1]\n const currInside = isInside(curr)\n const prevInside = isInside(prev)\n if (currInside) {\n if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b))\n output.push(curr)\n } else if (prevInside) {\n output.push(lineSegmentIntersect(prev, curr, a, b))\n }\n }\n return output\n}\n\n/**\n * Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space\n * corners of a rotated clipping ancestor).\n *\n * Uses Sutherland–Hodgman polygon clipping with centroid-based interior\n * detection, making it robust to either winding order of the clip polygon.\n * Returns the clipped polygon, or null if the subject is fully outside the\n * clip polygon. When `clipCorners` has fewer than 3 points the subject is\n * returned unchanged (no clipping).\n *\n * Preserving the polygon (rather than collapsing to an AABB) lets callers\n * chain multiple clips without reintroducing corners removed by an inner clip.\n */\nexport function clipPolygon(subject: Vector[], clipCorners: Vector[]): Vector[] | null {\n if (clipCorners.length < 3) return subject\n\n let cx = 0\n let cy = 0\n for (const c of clipCorners) {\n cx += c.x\n cy += c.y\n }\n cx /= clipCorners.length\n cy /= clipCorners.length\n\n let polygon: Vector[] = subject\n\n for (let i = 0; i < clipCorners.length; i++) {\n if (polygon.length === 0) return null\n const a = clipCorners[i]\n const b = clipCorners[(i + 1) % clipCorners.length]\n const centroidCross = crossProduct(a, b, { x: cx, y: cy })\n polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0)\n }\n\n return polygon.length === 0 ? null : polygon\n}\n\n/**\n * Clip an axis-aligned VisualBounds rectangle against a convex polygon\n * (e.g. the 4 canvas-space corners of a rotated clipping ancestor).\n *\n * Returns the AABB of the intersection, or null if the bounds are fully\n * outside the clip polygon. Delegates to {@link clipPolygon}.\n *\n * For a non-rotated clip (axis-aligned corners) the result is identical\n * to `intersectVisualBounds`.\n */\nexport function clipBoundsToPolygon(\n bounds: VisualBounds,\n clipCorners: Vector[]\n): VisualBounds | null {\n if (clipCorners.length < 3) return bounds\n\n const subject: Vector[] = [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY }\n ]\n\n const polygon = clipPolygon(subject, clipCorners)\n if (!polygon) return null\n\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const p of polygon) {\n if (p.x < minX) minX = p.x\n if (p.y < minY) minY = p.y\n if (p.x > maxX) maxX = p.x\n if (p.y > maxY) maxY = p.y\n }\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n"],"mappings":";AAGA,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,MAA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SceneGraph } from "./coordinate.js";
2
+ import { SceneNode } from "./types2.js";
3
+
4
+ //#region src/hit-test.d.ts
5
+ declare function hitTest(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
6
+ declare function hitTestDeep(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
7
+ declare function hitTestFrame(graph: SceneGraph, px: number, py: number, excludeIds: Set<string>, scopeId?: string): SceneNode | null;
8
+ //#endregion
9
+ export { hitTest, hitTestDeep, hitTestFrame };
10
+ //# sourceMappingURL=hit-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;;iBAyGgB,OAAA,CACd,KAAA,EAAO,UAAA,EACP,EAAA,UACA,EAAA,UACA,OAAA,YACC,SAAS;AAAA,iBAKI,WAAA,CACd,KAAA,EAAO,UAAA,EACP,EAAA,UACA,EAAA,UACA,OAAA,YACC,SAAS;AAAA,iBAuCI,YAAA,CACd,KAAA,EAAO,UAAA,EACP,EAAA,UACA,EAAA,UACA,UAAA,EAAY,GAAA,UACZ,OAAA,YACC,SAAA"}
@@ -0,0 +1,97 @@
1
+ import { Matrix, getWorldMatrix } from "./chunks/coordinate.js";
2
+ //#region src/hit-test.ts
3
+ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
4
+ "CANVAS",
5
+ "FRAME",
6
+ "GROUP",
7
+ "SECTION",
8
+ "COMPONENT",
9
+ "COMPONENT_SET",
10
+ "INSTANCE"
11
+ ]);
12
+ const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]);
13
+ function hasVisibleFillOrStroke(node) {
14
+ return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible);
15
+ }
16
+ function containsPoint(px, py, node, graph) {
17
+ const m = getWorldMatrix(node, graph);
18
+ const inv = Matrix.invert(m);
19
+ if (!inv) return false;
20
+ const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
21
+ return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height;
22
+ }
23
+ function hitTestOpaqueContainer(graph, px, py, child, childId, deep) {
24
+ if (!containsPoint(px, py, child, graph)) return null;
25
+ if (hitTestChildren(graph, px, py, childId, deep)) return child;
26
+ if (hasVisibleFillOrStroke(child)) return child;
27
+ return null;
28
+ }
29
+ function hitTestTransparentContainer(graph, px, py, child, childId, deep) {
30
+ if (child.type === "GROUP") {
31
+ if (!containsPoint(px, py, child, graph)) return null;
32
+ if (deep) return hitTestChildren(graph, px, py, childId, deep) ?? child;
33
+ return child;
34
+ }
35
+ const childHit = hitTestChildren(graph, px, py, childId, deep);
36
+ if (childHit) {
37
+ if (child.locked) return child;
38
+ return childHit;
39
+ }
40
+ if (containsPoint(px, py, child, graph) && hasVisibleFillOrStroke(child)) return child;
41
+ return null;
42
+ }
43
+ function hitTestChildren(graph, px, py, parentId, deep = false) {
44
+ const parent = graph.nodes.get(parentId);
45
+ if (!parent) return null;
46
+ if (parent.clipsContent) {
47
+ if (!containsPoint(px, py, parent, graph)) return null;
48
+ }
49
+ for (let i = parent.childIds.length - 1; i >= 0; i--) {
50
+ const childId = parent.childIds[i];
51
+ const child = graph.nodes.get(childId);
52
+ if (!child || child.internalOnly || !child.visible) continue;
53
+ if (CONTAINER_TYPES.has(child.type)) {
54
+ if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
55
+ const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep);
56
+ if (hit) return hit;
57
+ continue;
58
+ }
59
+ const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep);
60
+ if (hit) return hit;
61
+ continue;
62
+ }
63
+ if (containsPoint(px, py, child, graph)) return child;
64
+ }
65
+ return null;
66
+ }
67
+ function hitTest(graph, px, py, scopeId) {
68
+ return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, false);
69
+ }
70
+ function hitTestDeep(graph, px, py, scopeId) {
71
+ return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, true);
72
+ }
73
+ function hitTestFrameChildren(graph, px, py, parentId, offsetX, offsetY, excludeIds) {
74
+ const parent = graph.nodes.get(parentId);
75
+ if (!parent) return null;
76
+ let best = null;
77
+ for (const childId of parent.childIds) {
78
+ if (excludeIds.has(childId)) continue;
79
+ const child = graph.nodes.get(childId);
80
+ if (!child || child.internalOnly || !child.visible) continue;
81
+ const ax = offsetX + child.x;
82
+ const ay = offsetY + child.y;
83
+ if (!CONTAINER_TYPES.has(child.type)) continue;
84
+ if (px < ax || px > ax + child.width || py < ay || py > ay + child.height) continue;
85
+ best = child;
86
+ const deeper = hitTestFrameChildren(graph, px, py, childId, ax, ay, excludeIds);
87
+ if (deeper) best = deeper;
88
+ }
89
+ return best;
90
+ }
91
+ function hitTestFrame(graph, px, py, excludeIds, scopeId) {
92
+ return hitTestFrameChildren(graph, px, py, scopeId ?? graph.rootId, 0, 0, excludeIds);
93
+ }
94
+ //#endregion
95
+ export { hitTest, hitTestDeep, hitTestFrame };
96
+
97
+ //# sourceMappingURL=hit-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction containsPoint(px: number, py: number, node: SceneNode, graph: SceneGraph): boolean {\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean\n): SceneNode | null {\n if (child.type === 'GROUP') {\n if (!containsPoint(px, py, child, graph)) return null\n\n if (deep) return hitTestChildren(graph, px, py, childId, deep) ?? child\n\n return child\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (containsPoint(px, py, child, graph) && hasVisibleFillOrStroke(child)) return child\n return null\n}\n\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph)) return null\n }\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep)\n if (hit) return hit\n continue\n }\n\n if (containsPoint(px, py, child, graph)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true)\n}\n\nfunction hitTestFrameChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n offsetX: number,\n offsetY: number,\n excludeIds: Set<string>\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n let best: SceneNode | null = null\n\n for (const childId of parent.childIds) {\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n\n const ax = offsetX + child.x\n const ay = offsetY + child.y\n\n if (!CONTAINER_TYPES.has(child.type)) continue\n if (px < ax || px > ax + child.width || py < ay || py > ay + child.height) continue\n\n best = child\n\n const deeper = hitTestFrameChildren(graph, px, py, childId, ax, ay, excludeIds)\n if (deeper) best = deeper\n }\n\n return best\n}\n\nexport function hitTestFrame(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: Set<string>,\n scopeId?: string\n): SceneNode | null {\n return hitTestFrameChildren(graph, px, py, scopeId ?? graph.rootId, 0, 0, excludeIds)\n}\n"],"mappings":";;AAIA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;AAE1E,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,cAAc,IAAY,IAAY,MAAiB,OAA4B;CAC1F,MAAM,IAAI,eAAe,MAAM,KAAK;CAEpC,MAAM,MAAM,OAAO,OAAO,CAAC;CAC3B,IAAI,CAAC,KAAK,OAAO;CAEjB,MAAM,CAAC,QAAQ,UAAU,OAAO,UAAU,KAAK,CAAC,IAAI,EAAE,CAAC;CACvD,OAAO,UAAU,KAAK,UAAU,KAAK,SAAS,UAAU,KAAK,UAAU,KAAK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1
+ import { computeImageHash } from "./images2.js";
2
+ export { computeImageHash };
package/dist/images.js ADDED
@@ -0,0 +1,45 @@
1
+ //#region src/images.ts
2
+ function computeImageHash(data) {
3
+ let h1 = 2166136261;
4
+ let h2 = 2166136261;
5
+ let h3 = 2166136261;
6
+ let h4 = 2166136261;
7
+ let h5 = 2166136261;
8
+ for (let i = 0; i < data.length; i++) {
9
+ const b = data[i];
10
+ switch (i % 5) {
11
+ case 0:
12
+ h1 ^= b;
13
+ h1 = Math.imul(h1, 16777619) >>> 0;
14
+ break;
15
+ case 1:
16
+ h2 ^= b;
17
+ h2 = Math.imul(h2, 16777619) >>> 0;
18
+ break;
19
+ case 2:
20
+ h3 ^= b;
21
+ h3 = Math.imul(h3, 16777619) >>> 0;
22
+ break;
23
+ case 3:
24
+ h4 ^= b;
25
+ h4 = Math.imul(h4, 16777619) >>> 0;
26
+ break;
27
+ default:
28
+ h5 ^= b;
29
+ h5 = Math.imul(h5, 16777619) >>> 0;
30
+ break;
31
+ }
32
+ }
33
+ h5 = Math.imul(h5 ^ data.length, 16777619) >>> 0;
34
+ return [
35
+ h1,
36
+ h2,
37
+ h3,
38
+ h4,
39
+ h5
40
+ ].map((hash) => hash.toString(16).padStart(8, "0")).join("");
41
+ }
42
+ //#endregion
43
+ export { computeImageHash };
44
+
45
+ //# sourceMappingURL=images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"images.js","names":[],"sources":["../src/images.ts"],"sourcesContent":["export function computeImageHash(data: Uint8Array): string {\n let h1 = 0x811c9dc5 >>> 0\n let h2 = 0x811c9dc5 >>> 0\n let h3 = 0x811c9dc5 >>> 0\n let h4 = 0x811c9dc5 >>> 0\n let h5 = 0x811c9dc5 >>> 0\n for (let i = 0; i < data.length; i++) {\n const b = data[i]\n switch (i % 5) {\n case 0:\n h1 ^= b\n h1 = Math.imul(h1, 0x01000193) >>> 0\n break\n case 1:\n h2 ^= b\n h2 = Math.imul(h2, 0x01000193) >>> 0\n break\n case 2:\n h3 ^= b\n h3 = Math.imul(h3, 0x01000193) >>> 0\n break\n case 3:\n h4 ^= b\n h4 = Math.imul(h4, 0x01000193) >>> 0\n break\n default:\n h5 ^= b\n h5 = Math.imul(h5, 0x01000193) >>> 0\n break\n }\n }\n h5 = Math.imul(h5 ^ data.length, 0x01000193) >>> 0\n return [h1, h2, h3, h4, h5].map((hash) => hash.toString(16).padStart(8, '0')).join('')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,MAA0B;CACzD,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,IAAI,KAAK;EACf,QAAQ,IAAI,GAAZ;GACE,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF;IACE,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;EACJ;CACF;CACA,KAAK,KAAK,KAAK,KAAK,KAAK,QAAQ,QAAU,MAAM;CACjD,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE,CAAC,CAAC,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AACvF"}
@@ -0,0 +1,5 @@
1
+ //#region src/images.d.ts
2
+ declare function computeImageHash(data: Uint8Array): string;
3
+ //#endregion
4
+ export { computeImageHash };
5
+ //# sourceMappingURL=images2.d.ts.map