@pixerate/editor 0.54.0 → 0.55.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 (65) hide show
  1. package/dist/agent/index.cjs +6 -6
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.js +6 -6
  4. package/dist/animation/index.cjs +1 -1
  5. package/dist/animation/index.cjs.map +1 -1
  6. package/dist/animation/index.d.cts +2 -1
  7. package/dist/animation/index.d.ts +2 -1
  8. package/dist/animation/index.js +1 -1
  9. package/dist/animation-editor/index.cjs +2221 -0
  10. package/dist/animation-editor/index.cjs.map +1 -0
  11. package/dist/animation-editor/index.d.cts +1117 -0
  12. package/dist/animation-editor/index.d.ts +1117 -0
  13. package/dist/animation-editor/index.js +2221 -0
  14. package/dist/animation-editor/index.js.map +1 -0
  15. package/dist/bezier-BfwIbVTl.d.cts +548 -0
  16. package/dist/bezier-DYBvLgUH.d.ts +548 -0
  17. package/dist/canvas/index.cjs +713 -486
  18. package/dist/canvas/index.cjs.map +1 -1
  19. package/dist/canvas/index.d.cts +105 -5
  20. package/dist/canvas/index.d.ts +105 -5
  21. package/dist/canvas/index.js +710 -483
  22. package/dist/canvas/index.js.map +1 -1
  23. package/dist/chart/index.cjs +1 -1
  24. package/dist/chart/index.cjs.map +1 -1
  25. package/dist/chart/index.js +1 -1
  26. package/dist/{chunk-TO22LX34.js → chunk-GTMJ4Y3S.js} +2208 -2920
  27. package/dist/chunk-GTMJ4Y3S.js.map +1 -0
  28. package/dist/chunk-MLREO6J3.cjs +737 -0
  29. package/dist/chunk-MLREO6J3.cjs.map +1 -0
  30. package/dist/chunk-NONDTTH7.js +5979 -0
  31. package/dist/chunk-NONDTTH7.js.map +1 -0
  32. package/dist/{chunk-YNSK4MGT.cjs → chunk-O2UH7LZE.cjs} +1549 -2261
  33. package/dist/chunk-O2UH7LZE.cjs.map +1 -0
  34. package/dist/chunk-VWZB6BCY.js +737 -0
  35. package/dist/chunk-VWZB6BCY.js.map +1 -0
  36. package/dist/chunk-XCXQDPID.cjs +5979 -0
  37. package/dist/chunk-XCXQDPID.cjs.map +1 -0
  38. package/dist/color-E9pwm--w.d.cts +33 -0
  39. package/dist/color-E9pwm--w.d.ts +33 -0
  40. package/dist/commands/index.cjs +2 -2
  41. package/dist/commands/index.cjs.map +1 -1
  42. package/dist/commands/index.js +3 -3
  43. package/dist/diagram/index.cjs +25 -4
  44. package/dist/diagram/index.cjs.map +1 -1
  45. package/dist/diagram/index.d.cts +23 -0
  46. package/dist/diagram/index.d.ts +23 -0
  47. package/dist/diagram/index.js +33 -12
  48. package/dist/diagram/index.js.map +1 -1
  49. package/dist/pathfinder-BZL8aSu0.d.cts +469 -0
  50. package/dist/pathfinder-CNtsbCRK.d.ts +469 -0
  51. package/dist/{player-DSMjdgQ9.d.cts → player-Dg0FT0UI.d.cts} +1 -33
  52. package/dist/{player-DdfVrKWq.d.ts → player-W-5DX3Go.d.ts} +1 -33
  53. package/dist/svg-CLg2zqZA.d.cts +847 -0
  54. package/dist/svg-CPK82TtU.d.ts +847 -0
  55. package/dist/vector/index.cjs +1328 -6752
  56. package/dist/vector/index.cjs.map +1 -1
  57. package/dist/vector/index.d.cts +6 -846
  58. package/dist/vector/index.d.ts +6 -846
  59. package/dist/vector/index.js +645 -6069
  60. package/dist/vector/index.js.map +1 -1
  61. package/package.json +6 -1
  62. package/dist/chunk-TO22LX34.js.map +0 -1
  63. package/dist/chunk-YNSK4MGT.cjs.map +0 -1
  64. package/dist/pathfinder-B9xh_pCZ.d.ts +0 -1013
  65. package/dist/pathfinder-QdG70sr9.d.cts +0 -1013
@@ -0,0 +1,737 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ var _chunkO2UH7LZEcjs = require('./chunk-O2UH7LZE.cjs');
20
+
21
+ // src/canvas/pathops/planar.ts
22
+ var twin = (h) => h ^ 1;
23
+ function boundsOf(segs) {
24
+ let minX = Infinity;
25
+ let minY = Infinity;
26
+ let maxX = -Infinity;
27
+ let maxY = -Infinity;
28
+ for (const s of segs) {
29
+ for (const [x, y] of s) {
30
+ if (x < minX) minX = x;
31
+ if (x > maxX) maxX = x;
32
+ if (y < minY) minY = y;
33
+ if (y > maxY) maxY = y;
34
+ }
35
+ }
36
+ return { minX, minY, maxX, maxY };
37
+ }
38
+ var inBounds = (b, p) => p[0] >= b.minX && p[0] <= b.maxX && p[1] >= b.minY && p[1] <= b.maxY;
39
+ function withoutSpurs(cycle) {
40
+ const out = [];
41
+ for (const h of cycle) {
42
+ if (out.length && out[out.length - 1] === twin(h)) out.pop();
43
+ else out.push(h);
44
+ }
45
+ while (out.length >= 2 && twin(out[0]) === out[out.length - 1]) {
46
+ out.pop();
47
+ out.shift();
48
+ }
49
+ return out;
50
+ }
51
+ function pinEnds(pts, a, b) {
52
+ const n = pts.length;
53
+ if (n === 2) return [a, b];
54
+ const out = pts.map((p) => [p[0], p[1]]);
55
+ const d0 = [a[0] - pts[0][0], a[1] - pts[0][1]];
56
+ const d1 = [b[0] - pts[n - 1][0], b[1] - pts[n - 1][1]];
57
+ out[0] = a;
58
+ out[n - 1] = b;
59
+ if (n === 3) {
60
+ out[1] = [pts[1][0] + (d0[0] + d1[0]) / 2, pts[1][1] + (d0[1] + d1[1]) / 2];
61
+ } else {
62
+ out[1] = [pts[1][0] + d0[0], pts[1][1] + d0[1]];
63
+ out[2] = [pts[2][0] + d1[0], pts[2][1] + d1[1]];
64
+ }
65
+ return out;
66
+ }
67
+ function interiorPoint(path) {
68
+ const chains = Array.isArray(path) && path.length > 0 && Array.isArray(path[0]) && Array.isArray(_optionalChain([path, 'access', _2 => _2[0], 'access', _3 => _3[0], 'optionalAccess', _4 => _4[0]])) ? path : _chunkO2UH7LZEcjs.pathToContours.call(void 0, path).map((c) => _chunkO2UH7LZEcjs.closeContour.call(void 0, c, true));
69
+ const b = boundsOf(chains.flat());
70
+ if (!(b.maxX > b.minX) || !(b.maxY > b.minY)) return null;
71
+ const tol = Math.max(b.maxX - b.minX, b.maxY - b.minY) * 1e-3;
72
+ const rings = chains.filter((c) => c.length).map((c) => _chunkO2UH7LZEcjs.flattenChain.call(void 0, c, tol));
73
+ let best = null;
74
+ for (const f of [0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875, 0.0625, 0.9375]) {
75
+ const y = b.minY + (b.maxY - b.minY) * (f + 61803e-7);
76
+ const xs = [];
77
+ for (const ring of rings) {
78
+ for (let i = 0; i < ring.length; i++) {
79
+ const a = ring[i];
80
+ const c = ring[(i + 1) % ring.length];
81
+ if (a[1] <= y !== c[1] <= y) xs.push(a[0] + (y - a[1]) / (c[1] - a[1]) * (c[0] - a[0]));
82
+ }
83
+ }
84
+ xs.sort((p, q) => p - q);
85
+ for (let i = 0; i + 1 < xs.length; i++) {
86
+ const width = xs[i + 1] - xs[i];
87
+ if (!(width > (_nullishCoalesce(_optionalChain([best, 'optionalAccess', _5 => _5.width]), () => ( 0))))) continue;
88
+ const m = [(xs[i] + xs[i + 1]) / 2, y];
89
+ if (_chunkO2UH7LZEcjs.windingNumber.call(void 0, chains, m) !== 0) best = { width, p: m };
90
+ }
91
+ }
92
+ return _nullishCoalesce(_optionalChain([best, 'optionalAccess', _6 => _6.p]), () => ( null));
93
+ }
94
+ var PlanarMap = (_class = class _PlanarMap {
95
+ constructor(vertices, edges, sources, eps, inputCount, inputs) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
96
+ this.vertices = vertices;
97
+ this.edges = edges;
98
+ this.sources = sources;
99
+ this.eps = eps;
100
+ this.inputCount = inputCount;
101
+ this.fills = inputs.map((input) => {
102
+ const chains = input.fills === false ? [] : _chunkO2UH7LZEcjs.pathToContours.call(void 0, input.path).filter((c) => c.closed).map((c) => _chunkO2UH7LZEcjs.closeContour.call(void 0, c));
103
+ return { chains, fillRule: _nullishCoalesce(input.fillRule, () => ( "nonzero")), bounds: boundsOf(chains.flat()) };
104
+ });
105
+ const nv = vertices.length;
106
+ this.around = Array.from({ length: nv }, () => []);
107
+ for (let h = 0; h < edges.length * 2; h++) this.around[this.origin(h)].push(h);
108
+ this.slot = new Array(edges.length * 2).fill(0);
109
+ this.around.forEach((list, v) => {
110
+ if (list.length === 0) return;
111
+ const at = vertices[v];
112
+ let r = Infinity;
113
+ for (const h of list) r = Math.min(r, _chunkO2UH7LZEcjs.dist.call(void 0, at, vertices[this.origin(twin(h))]));
114
+ r *= 0.5;
115
+ const keyed = list.map((h) => ({ h, angle: this.leavingAngle(h, at, r) }));
116
+ keyed.sort((a, b) => a.angle - b.angle);
117
+ list.length = 0;
118
+ keyed.forEach(({ h }, k) => {
119
+ list.push(h);
120
+ this.slot[h] = k;
121
+ });
122
+ });
123
+ const parent = Array.from({ length: nv }, (_, i) => i);
124
+ const find = (v) => {
125
+ while (parent[v] !== v) {
126
+ parent[v] = parent[parent[v]];
127
+ v = parent[v];
128
+ }
129
+ return v;
130
+ };
131
+ for (const e of edges) parent[find(e.a)] = find(e.b);
132
+ this.component = Array.from({ length: nv }, (_, v) => find(v));
133
+ }
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+ __init() {this.cyclesCache = null}
143
+ __init2() {this.sourcesCache = []}
144
+
145
+ /**
146
+ * Maps `inputs` (their subpaths as given: open ones stay open). Null when they cannot be mapped
147
+ * (non-finite points, more than `maxSegments` segments or an intersection search that does
148
+ * not settle) or have no edges.
149
+ */
150
+ static build(inputs, options = {}) {
151
+ const chains = inputs.map((input) => _chunkO2UH7LZEcjs.pathToContours.call(void 0, input.path).map((c) => _chunkO2UH7LZEcjs.closeContour.call(void 0, c)).filter((c) => c.length));
152
+ const count = chains.reduce((n, cs) => n + cs.reduce((m, c) => m + c.length, 0), 0);
153
+ if (count === 0 || count > (_nullishCoalesce(options.maxSegments, () => ( 4096)))) return null;
154
+ let split;
155
+ try {
156
+ split = _chunkO2UH7LZEcjs.planarSplit.call(void 0, chains, options);
157
+ } catch (e2) {
158
+ return null;
159
+ }
160
+ const edges = split.edges.filter((e) => e.a !== e.b).map((e) => ({ ...e, source: _nullishCoalesce(e.operands[e.operands.length - 1], () => ( -1)) }));
161
+ if (!edges.length) return null;
162
+ const gap = _nullishCoalesce(options.gap, () => ( 0));
163
+ if (gap > split.eps) closeGaps(split.vertices, edges, gap);
164
+ return new _PlanarMap(split.vertices, edges, split.sources, split.eps, inputs.length, inputs);
165
+ }
166
+ // -- half-edges ------------------------------------------------------------
167
+ origin(h) {
168
+ const e = this.edges[h >> 1];
169
+ return h & 1 ? e.b : e.a;
170
+ }
171
+ halfPts(h) {
172
+ const pts = this.edges[h >> 1].pts;
173
+ return h & 1 ? [...pts].reverse() : pts;
174
+ }
175
+ /** The half-edge after `h` on the face to its left: the sharpest left turn at its end. */
176
+ next(h) {
177
+ const back = twin(h);
178
+ const list = this.around[this.origin(back)];
179
+ return list[(this.slot[back] + list.length - 1) % list.length];
180
+ }
181
+ /** Direction (angle) in which half-edge `h`, leaving `at`, first gets `r` away from it. */
182
+ leavingAngle(h, at, r) {
183
+ const pts = this.halfPts(h);
184
+ const d = (t2) => _chunkO2UH7LZEcjs.dist.call(void 0, _chunkO2UH7LZEcjs.segmentPoint.call(void 0, pts, t2), at);
185
+ let lo = 0;
186
+ let hi = 1;
187
+ const steps = pts.length === 2 ? 1 : 16;
188
+ for (let k = 1; k <= steps; k++) {
189
+ if (d(k / steps) >= r) {
190
+ hi = k / steps;
191
+ break;
192
+ }
193
+ lo = k / steps;
194
+ }
195
+ for (let i = 0; i < 40 && hi - lo > 1e-12; i++) {
196
+ const m = (lo + hi) / 2;
197
+ if (d(m) >= r) hi = m;
198
+ else lo = m;
199
+ }
200
+ const p = _chunkO2UH7LZEcjs.segmentPoint.call(void 0, pts, hi);
201
+ if (_chunkO2UH7LZEcjs.dist.call(void 0, p, at) > 0) return Math.atan2(p[1] - at[1], p[0] - at[0]);
202
+ const t = _chunkO2UH7LZEcjs.segmentTangent.call(void 0, pts, 0);
203
+ return Math.atan2(t[1], t[0]);
204
+ }
205
+ /** Segments of a run of half-edges (a loop unless `closed` is false), pieces of one input segment joined again. */
206
+ cycleSegments(halves, closed = true) {
207
+ const runs = halves.map((h) => {
208
+ const e = this.edges[h >> 1];
209
+ return { h, src: e.source < 0 ? -1 : e.src, from: h & 1 ? e.sb : e.sa, to: h & 1 ? e.sa : e.sb };
210
+ });
211
+ const joins = (a, b) => a.src >= 0 && a.src === b.src && Math.abs(a.to - b.from) < 1e-9 && a.to - a.from > 0 === b.to - b.from > 0;
212
+ const n = runs.length;
213
+ let start = 0;
214
+ for (let k = 0; closed && k < n; k++) {
215
+ if (!joins(runs[(k + n - 1) % n], runs[k])) {
216
+ start = k;
217
+ break;
218
+ }
219
+ }
220
+ const ordered = [...runs.slice(start), ...runs.slice(0, start)];
221
+ const out = [];
222
+ let i = 0;
223
+ while (i < ordered.length) {
224
+ let j = i + 1;
225
+ while (j < ordered.length && joins(ordered[j - 1], ordered[j])) j++;
226
+ const first = ordered[i];
227
+ const last = ordered[j - 1];
228
+ if (j - i === 1) out.push(this.halfPts(first.h));
229
+ else {
230
+ const a = this.vertices[this.origin(first.h)];
231
+ const b = this.vertices[this.origin(twin(last.h))];
232
+ const seg = this.sources[first.src];
233
+ out.push(seg.length === 2 ? [a, b] : pinEnds(_chunkO2UH7LZEcjs.subSegment.call(void 0, seg, first.from, last.to), a, b));
234
+ }
235
+ i = j;
236
+ }
237
+ return out;
238
+ }
239
+ cycles() {
240
+ if (this.cyclesCache) return this.cyclesCache;
241
+ const halves = this.edges.length * 2;
242
+ const seen = new Uint8Array(halves);
243
+ const faces = [];
244
+ const holes = [];
245
+ const sliver = this.eps * 10;
246
+ for (let start = 0; start < halves; start++) {
247
+ if (seen[start]) continue;
248
+ const walk = [];
249
+ let h = start;
250
+ while (!seen[h]) {
251
+ seen[h] = 1;
252
+ walk.push(h);
253
+ h = this.next(h);
254
+ }
255
+ const cycle = withoutSpurs(walk);
256
+ if (!cycle.length) continue;
257
+ const segments = this.cycleSegments(cycle);
258
+ const area = _chunkO2UH7LZEcjs.contourSignedArea.call(void 0, segments);
259
+ let perimeter = 0;
260
+ for (const s of segments) perimeter += s.length === 2 ? _chunkO2UH7LZEcjs.dist.call(void 0, s[0], s[1]) : _chunkO2UH7LZEcjs.segmentLength.call(void 0, s, 0, 1, 1e-6);
261
+ if (!(perimeter > 0)) continue;
262
+ const entry = { halves: cycle, segments, area, bounds: boundsOf(segments) };
263
+ if (area > 0 && 2 * area / perimeter >= sliver) faces.push(entry);
264
+ else if (area < 0 && -2 * area / perimeter >= sliver) holes.push(entry);
265
+ }
266
+ const faceHoles = faces.map(() => []);
267
+ holes.forEach((hole, k) => {
268
+ const v = this.origin(hole.halves[0]);
269
+ const p = this.vertices[v];
270
+ const own = this.component[v];
271
+ let best = -1;
272
+ faces.forEach((face, i) => {
273
+ if (this.component[this.origin(face.halves[0])] === own || !inBounds(face.bounds, p)) return;
274
+ if (best >= 0 && faces[best].area <= face.area) return;
275
+ if (_chunkO2UH7LZEcjs.windingNumber.call(void 0, [face.segments], p) !== 0) best = i;
276
+ });
277
+ if (best >= 0) faceHoles[best].push(k);
278
+ });
279
+ const faceOf = new Int32Array(halves).fill(-1);
280
+ faces.forEach((face, i) => {
281
+ for (const h of face.halves) faceOf[h] = i;
282
+ for (const k of faceHoles[i]) for (const h of holes[k].halves) faceOf[h] = i;
283
+ });
284
+ this.cyclesCache = { faces, holes, faceHoles, faceOf };
285
+ this.sourcesCache = faces.map(() => null);
286
+ return this.cyclesCache;
287
+ }
288
+ faceChains(i) {
289
+ const { faces, holes, faceHoles } = this.cycles();
290
+ return [faces[i].segments, ...faceHoles[i].map((k) => holes[k].segments)];
291
+ }
292
+ /** The bounded faces of the map. */
293
+ get faces() {
294
+ const { faces, holes, faceHoles } = this.cycles();
295
+ return faces.map((f, i) => {
296
+ const chains = this.faceChains(i);
297
+ const area = f.area + faceHoles[i].reduce((sum, k) => sum + holes[k].area, 0);
298
+ return { path: _chunkO2UH7LZEcjs.contoursToPath.call(void 0, chains.map((segments) => ({ segments, closed: true }))), area, bounds: f.bounds };
299
+ });
300
+ }
301
+ /** The inputs whose fill covers face `i`, ascending (empty for an area only outlines enclose). */
302
+ faceSources(i) {
303
+ this.cycles();
304
+ const cached = this.sourcesCache[i];
305
+ if (cached) return cached;
306
+ const p = interiorPoint(this.faceChains(i));
307
+ const out = [];
308
+ if (p) {
309
+ this.fills.forEach((fill, k) => {
310
+ if (!fill.chains.length || !inBounds(fill.bounds, p)) return;
311
+ const w = _chunkO2UH7LZEcjs.windingNumber.call(void 0, fill.chains, p);
312
+ if (fill.fillRule === "evenodd" ? (w & 1) === 1 : w !== 0) out.push(k);
313
+ });
314
+ }
315
+ this.sourcesCache[i] = out;
316
+ return out;
317
+ }
318
+ /** A point well inside face `i`. */
319
+ faceInterior(i) {
320
+ return interiorPoint(this.faceChains(i));
321
+ }
322
+ /** The face under `p` (the smallest one around it), or -1. */
323
+ faceAt(p) {
324
+ const { faces } = this.cycles();
325
+ let best = -1;
326
+ faces.forEach((face, i) => {
327
+ if (!inBounds(face.bounds, p) || best >= 0 && faces[best].area <= face.area) return;
328
+ if (_chunkO2UH7LZEcjs.windingNumber.call(void 0, this.faceChains(i), p) !== 0) best = i;
329
+ });
330
+ return best;
331
+ }
332
+ /**
333
+ * The union of faces, traced along the map's own edges: those between two merged faces drop
334
+ * out exactly, so no seam or sliver is left where a boolean union of their outlines could
335
+ * round shared corners apart. Outer subpaths come out counter-clockwise (y-up), holes clockwise.
336
+ */
337
+ merge(faceIndices) {
338
+ const { faceOf } = this.cycles();
339
+ const picked = new Set(faceIndices);
340
+ const merged = (h) => faceOf[h] >= 0 && picked.has(faceOf[h]);
341
+ const boundary = (h) => merged(h) && !merged(twin(h));
342
+ const used = new Uint8Array(this.edges.length * 2);
343
+ const contours = [];
344
+ for (let start = 0; start < used.length; start++) {
345
+ if (used[start] || !boundary(start)) continue;
346
+ const cycle = [];
347
+ let h = start;
348
+ let ok = true;
349
+ while (!used[h]) {
350
+ used[h] = 1;
351
+ cycle.push(h);
352
+ const back = twin(h);
353
+ const list = this.around[this.origin(back)];
354
+ const k = this.slot[back];
355
+ const n = list.length;
356
+ let found = -1;
357
+ for (let j = 1; j <= n; j++) {
358
+ const g = list[(k - j + n * 2) % n];
359
+ if (boundary(g)) {
360
+ found = g;
361
+ break;
362
+ }
363
+ }
364
+ if (found < 0) {
365
+ ok = false;
366
+ break;
367
+ }
368
+ h = found;
369
+ }
370
+ if (!ok || h !== start) continue;
371
+ contours.push({ segments: this.cycleSegments(cycle), closed: true });
372
+ }
373
+ return _chunkO2UH7LZEcjs.contoursToPath.call(void 0, contours);
374
+ }
375
+ /**
376
+ * The edges joined into runs between junctions: vertices where other than two edges meet, or
377
+ * where the two edges lie on different inputs. Each run is keyed by its input.
378
+ */
379
+ chains() {
380
+ const passes = (v) => {
381
+ const list = this.around[v];
382
+ if (list.length !== 2) return null;
383
+ return this.edges[list[0] >> 1].source === this.edges[list[1] >> 1].source ? [list[0], list[1]] : null;
384
+ };
385
+ const used = new Uint8Array(this.edges.length);
386
+ const out = [];
387
+ const walk = (h0) => {
388
+ const source = this.edges[h0 >> 1].source;
389
+ const halves = [];
390
+ let h = h0;
391
+ let closed = false;
392
+ for (; ; ) {
393
+ if (used[h >> 1]) {
394
+ closed = true;
395
+ break;
396
+ }
397
+ used[h >> 1] = 1;
398
+ halves.push(h);
399
+ const v = this.origin(twin(h));
400
+ const pass = passes(v);
401
+ if (!pass) {
402
+ closed = v === this.origin(h0);
403
+ break;
404
+ }
405
+ h = pass[0] === twin(h) ? pass[1] : pass[0];
406
+ }
407
+ if (source < 0) return;
408
+ const segments = this.cycleSegments(halves, closed);
409
+ out.push({ segments, closed, source });
410
+ };
411
+ this.around.forEach((list, v) => {
412
+ if (passes(v)) return;
413
+ for (const h of list) if (!used[h >> 1]) walk(h);
414
+ });
415
+ for (let e = 0; e < this.edges.length; e++) if (!used[e]) walk(e * 2);
416
+ return out;
417
+ }
418
+ // -- fill regions (cadcraft `boundary_at_gap`) -------------------------------
419
+ /**
420
+ * The region enclosing `p`, traced as cadcraft does it: a ray from `p` towards +x meets the
421
+ * edges in order; for each, the half-edge with `p` on its left is followed by always taking the
422
+ * sharpest left turn, until a loop that runs counter-clockwise round `p` comes back. The pieces
423
+ * of the map nested inside that loop (islands) become its holes. Null when nothing encloses `p`.
424
+ */
425
+ regionAt(p) {
426
+ const { faces, faceOf } = this.cycles();
427
+ const hits = [];
428
+ this.edges.forEach((e, i) => {
429
+ const ay = this.vertices[e.a][1];
430
+ const by = this.vertices[e.b][1];
431
+ if (ay > p[1] === by > p[1]) return;
432
+ const t = _chunkO2UH7LZEcjs.solveMonotone.call(void 0, e.pts, 1, p[1]);
433
+ const x = _chunkO2UH7LZEcjs.segmentPoint.call(void 0, e.pts, t)[0];
434
+ if (x > p[0]) hits.push({ x, e: i });
435
+ });
436
+ hits.sort((a, b) => a.x - b.x);
437
+ for (const { e } of hits.slice(0, 64)) {
438
+ const ay = this.vertices[this.edges[e].a][1];
439
+ const by = this.vertices[this.edges[e].b][1];
440
+ const h = by > ay ? e * 2 : e * 2 + 1;
441
+ const walk = [];
442
+ const seen = /* @__PURE__ */ new Set();
443
+ let g = h;
444
+ while (!seen.has(g)) {
445
+ seen.add(g);
446
+ walk.push(g);
447
+ g = this.next(g);
448
+ }
449
+ if (g !== h) continue;
450
+ const cycle = withoutSpurs(walk);
451
+ if (!cycle.length) continue;
452
+ const segments = this.cycleSegments(cycle);
453
+ if (!(_chunkO2UH7LZEcjs.contourSignedArea.call(void 0, segments) > 0) || _chunkO2UH7LZEcjs.windingNumber.call(void 0, [segments], p) === 0) continue;
454
+ const face = faceOf[cycle[0]];
455
+ if (face >= 0 && faces[face].halves.includes(cycle[0])) {
456
+ return _chunkO2UH7LZEcjs.contoursToPath.call(void 0, this.faceChains(face).map((s) => ({ segments: s, closed: true })));
457
+ }
458
+ return _chunkO2UH7LZEcjs.contoursToPath.call(void 0, [{ segments, closed: true }]);
459
+ }
460
+ return null;
461
+ }
462
+ }, _class);
463
+ function closeGaps(vertices, edges, gap) {
464
+ const degree = new Array(vertices.length).fill(0);
465
+ const linked = /* @__PURE__ */ new Set();
466
+ for (const e of edges) {
467
+ degree[e.a]++;
468
+ degree[e.b]++;
469
+ linked.add(`${Math.min(e.a, e.b)},${Math.max(e.a, e.b)}`);
470
+ }
471
+ const ends = degree.flatMap((d, v) => d === 1 ? [v] : []).sort((a, b) => vertices[a][0] - vertices[b][0]);
472
+ const joined = /* @__PURE__ */ new Set();
473
+ let lo = 0;
474
+ for (let i = 0; i < ends.length; i++) {
475
+ const u = ends[i];
476
+ if (joined.has(u)) continue;
477
+ const pu = vertices[u];
478
+ while (lo < ends.length && vertices[ends[lo]][0] < pu[0] - gap) lo++;
479
+ let best = -1;
480
+ let bestD = Infinity;
481
+ for (let j = lo; j < ends.length; j++) {
482
+ const v = ends[j];
483
+ const pv = vertices[v];
484
+ if (pv[0] > pu[0] + gap) break;
485
+ if (v === u || joined.has(v) || linked.has(`${Math.min(u, v)},${Math.max(u, v)}`)) continue;
486
+ const d = _chunkO2UH7LZEcjs.dist.call(void 0, pu, pv);
487
+ if (d <= gap && d < bestD) {
488
+ best = v;
489
+ bestD = d;
490
+ }
491
+ }
492
+ if (best < 0) continue;
493
+ const a = Math.min(u, best);
494
+ const b = Math.max(u, best);
495
+ edges.push({ a, b, pts: [vertices[a], vertices[b]], operands: [], src: -1, sa: 0, sb: 1, source: -1 });
496
+ joined.add(u);
497
+ joined.add(best);
498
+ }
499
+ }
500
+ function contourEnclosesArea(contour) {
501
+ const segs = _chunkO2UH7LZEcjs.closeContour.call(void 0, contour, true);
502
+ if (!segs.length) return false;
503
+ const b = boundsOf(segs);
504
+ const w = b.maxX - b.minX;
505
+ const h = b.maxY - b.minY;
506
+ return Math.abs(_chunkO2UH7LZEcjs.contourSignedArea.call(void 0, segs)) > 1e-9 * (w * w + h * h);
507
+ }
508
+ function nearestU(segs, p) {
509
+ let best = null;
510
+ segs.forEach((seg, k) => {
511
+ const n = _chunkO2UH7LZEcjs.segmentNearest.call(void 0, seg, p);
512
+ if (!best || n.distance < best.d) best = { u: k + n.t, d: n.distance };
513
+ });
514
+ return best;
515
+ }
516
+ function span(segs, u0, u1) {
517
+ const n = segs.length;
518
+ if (!n || !Number.isFinite(u0) || !Number.isFinite(u1)) return [];
519
+ const first = Math.max(0, Math.floor(u0));
520
+ const last = Math.min(Math.max(0, Math.ceil(u1)), first + 2 * n);
521
+ const out = [];
522
+ for (let k = first; k < last; k++) {
523
+ const t0 = Math.min(1, Math.max(0, u0 - k));
524
+ const t1 = Math.min(1, Math.max(0, u1 - k));
525
+ if (t1 - t0 > 1e-12) out.push(_chunkO2UH7LZEcjs.subSegment.call(void 0, segs[k % n], t0, t1));
526
+ }
527
+ return out;
528
+ }
529
+ function snapEnds(segs, to, tol) {
530
+ if (!segs.length) return segs;
531
+ const out = segs.map((s) => [...s]);
532
+ const move = (seg, end, handle) => {
533
+ const q = to.find((t) => _chunkO2UH7LZEcjs.dist.call(void 0, t, seg[end]) <= tol);
534
+ if (!q) return;
535
+ const d = [q[0] - seg[end][0], q[1] - seg[end][1]];
536
+ seg[end] = q;
537
+ if (seg.length === 4) seg[handle] = [seg[handle][0] + d[0], seg[handle][1] + d[1]];
538
+ };
539
+ move(out[0], 0, 1);
540
+ const last = out[out.length - 1];
541
+ move(last, last.length - 1, last.length - 2);
542
+ return out;
543
+ }
544
+ function cutOutPiece(path, piece, fillCloses, tol) {
545
+ const segs = piece.segments;
546
+ if (!segs.length) return null;
547
+ let mid = null;
548
+ let longest = -1;
549
+ let perimeter = 0;
550
+ for (const seg of segs) {
551
+ const len2 = _chunkO2UH7LZEcjs.segmentLength.call(void 0, seg);
552
+ perimeter += len2;
553
+ if (len2 > longest) {
554
+ longest = len2;
555
+ mid = _chunkO2UH7LZEcjs.segmentPoint.call(void 0, seg, 0.5);
556
+ }
557
+ }
558
+ if (!mid || perimeter <= tol) return null;
559
+ const a = segs[0][0];
560
+ const lastSeg = segs[segs.length - 1];
561
+ const b = lastSeg[lastSeg.length - 1];
562
+ const whole = !!piece.closed || _chunkO2UH7LZEcjs.dist.call(void 0, a, b) <= tol;
563
+ const contours = _chunkO2UH7LZEcjs.pathToContours.call(void 0, path);
564
+ let found = null;
565
+ contours.forEach((c, index2) => {
566
+ if (!c.segments.length) return;
567
+ const closed2 = c.closed || fillCloses && contourEnclosesArea(c);
568
+ const ring2 = _chunkO2UH7LZEcjs.closeContour.call(void 0, c, closed2);
569
+ const n = nearestU(ring2, mid);
570
+ if (n && n.d <= tol && (!found || n.d < found.d)) found = { index: index2, ring: ring2, closed: closed2, um: n.u, d: n.d };
571
+ });
572
+ if (!found) return null;
573
+ const { index, ring, closed, um } = found;
574
+ const len = ring.length;
575
+ const real = _chunkO2UH7LZEcjs.closeContour.call(void 0, contours[index]).length;
576
+ const at = (p) => {
577
+ const n = nearestU(ring, p);
578
+ return n && n.d <= tol ? n.u : null;
579
+ };
580
+ let keep = [];
581
+ if (!whole) {
582
+ const ua = at(a);
583
+ const ub = at(b);
584
+ if (ua === null || ub === null) return null;
585
+ if (closed) {
586
+ const fwd = (from, to) => ((to - from) % len + len) % len;
587
+ const [start, end] = fwd(ua, um) <= fwd(ua, ub) ? [ub, ua] : [ua, ub];
588
+ const rest = fwd(start, end);
589
+ if (rest > 1e-9 && len - rest > 1e-9) {
590
+ const parts = real >= len ? [[0, 2 * len]] : [[0, real], [len, len + real]];
591
+ keep = parts.map(([lo, hi]) => [Math.max(start, lo), Math.min(start + rest, hi)]).filter(([x, y]) => y - x > 1e-9);
592
+ }
593
+ } else {
594
+ const lo = Math.min(ua, ub);
595
+ const hi = Math.max(ua, ub);
596
+ if (um < lo - 1e-9 || um > hi + 1e-9) return null;
597
+ keep = [[0, lo], [hi, len]].filter(([x, y]) => y - x > 1e-9);
598
+ }
599
+ }
600
+ const out = contours.slice(0, index);
601
+ for (const [u0, u1] of keep) {
602
+ const run = span(ring, u0, u1);
603
+ if (run.length) out.push({ segments: snapEnds(run, [a, b], tol), closed: false });
604
+ }
605
+ out.push(...contours.slice(index + 1));
606
+ return _chunkO2UH7LZEcjs.contoursToPath.call(void 0, out);
607
+ }
608
+
609
+ // src/canvas/pathops/hatch.ts
610
+ function hatchPath(path, options = {}) {
611
+ const out = [];
612
+ const b = _chunkO2UH7LZEcjs.bezierPathBounds.call(void 0, path);
613
+ if (!b || b.maxX - b.minX <= 0 || b.maxY - b.minY <= 0) return out;
614
+ const want = Math.max(_nullishCoalesce(options.gap, () => ( 4)), 1e-3);
615
+ const s = Math.SQRT1_2;
616
+ const rot = (p) => [(p[0] + p[1]) * s, (p[1] - p[0]) * s];
617
+ const unrot = (x, y) => ({ x: (x - y) * s, y: (x + y) * s });
618
+ const edges = [];
619
+ for (const contour of _chunkO2UH7LZEcjs.pathToContours.call(void 0, path)) {
620
+ const pts = _chunkO2UH7LZEcjs.flattenChain.call(void 0, _chunkO2UH7LZEcjs.closeContour.call(void 0, contour, true), want * 0.1).map(rot);
621
+ for (let i = 0; i < pts.length; i++) {
622
+ const p = pts[i];
623
+ const q = pts[(i + 1) % pts.length];
624
+ if (p[0] !== q[0] || p[1] !== q[1]) edges.push([p, q]);
625
+ }
626
+ }
627
+ let y0 = Infinity;
628
+ let y1 = -Infinity;
629
+ for (const [p, q] of edges) {
630
+ y0 = Math.min(y0, p[1], q[1]);
631
+ y1 = Math.max(y1, p[1], q[1]);
632
+ }
633
+ if (!(y1 > y0)) return out;
634
+ const gap = Math.max(want, (y1 - y0) / Math.max(1, _nullishCoalesce(options.maxLines, () => ( 400))), 1e-6);
635
+ const xs = [];
636
+ for (let y = Math.floor(y0 / gap) * gap + gap / 2; y < y1; y += gap) {
637
+ xs.length = 0;
638
+ for (const [p, q] of edges) if (p[1] <= y !== q[1] <= y) xs.push(p[0] + (y - p[1]) / (q[1] - p[1]) * (q[0] - p[0]));
639
+ xs.sort((m, n) => m - n);
640
+ for (let i = 0; i + 1 < xs.length; i += 2) {
641
+ out.push({ type: "M", ...unrot(xs[i], y) }, { type: "L", ...unrot(xs[i + 1], y) });
642
+ }
643
+ }
644
+ return out;
645
+ }
646
+
647
+ // src/canvas/pathops/pathfinder.ts
648
+ var PATHFINDER_OPERATIONS = ["divide", "trim", "merge", "crop", "outline", "minusBack"];
649
+ var top = (covering) => covering[covering.length - 1];
650
+ function pathfinder(op, shapes, options = {}) {
651
+ const n = shapes.length;
652
+ if (n === 0) return { pieces: [], engine: "curve" };
653
+ const filled = shapes.filter((s) => !s.line);
654
+ const operands = shapes.map((s) => ({ path: s.path, fillRule: _nullishCoalesce(s.fillRule, () => ( "nonzero")) }));
655
+ if (op === "outline") {
656
+ const map = PlanarMap.build(
657
+ shapes.map((s) => ({ path: s.line ? s.path : closeAll(s.path), fills: false })),
658
+ options
659
+ );
660
+ if (!map) return { pieces: [], engine: "curve", error: "could not map the outlines" };
661
+ const pieces = map.chains().map((c) => ({ path: _chunkO2UH7LZEcjs.contoursToPath.call(void 0, [{ segments: c.segments, closed: c.closed }]), source: c.source, open: !c.closed }));
662
+ return { pieces, engine: "curve" };
663
+ }
664
+ if (op === "divide") {
665
+ if (filled.length !== n) {
666
+ const map = PlanarMap.build(shapes.map((s) => ({ path: s.line ? s.path : closeAll(s.path), fillRule: s.fillRule, fills: !s.line })), options);
667
+ if (!map) return { pieces: [], engine: "curve", error: "could not map the shapes" };
668
+ const pieces = [];
669
+ map.faces.forEach((face, i) => {
670
+ const covering = map.faceSources(i);
671
+ if (covering.length) pieces.push({ path: face.path, source: top(covering) });
672
+ });
673
+ return { pieces, engine: "curve" };
674
+ }
675
+ const result = _chunkO2UH7LZEcjs.dividePaths.call(void 0, operands, options);
676
+ return { ...report(result), pieces: result.pieces.map((p) => ({ path: p.path, source: top(p.operands) })) };
677
+ }
678
+ const index = shapes.flatMap((s, i) => s.line ? [] : [i]);
679
+ const m = index.length;
680
+ if (m === 0) return { pieces: [], engine: "curve" };
681
+ const ops = index.map((i) => operands[i]);
682
+ const key = (k) => _nullishCoalesce(shapes[index[k]].key, () => ( index[k]));
683
+ const select = (selectors) => _chunkO2UH7LZEcjs.pathBooleanSelect.call(void 0, ops, selectors, options);
684
+ const joined = (parts) => parts.flat();
685
+ switch (op) {
686
+ case "trim": {
687
+ const result = select(index.map((_, k) => (c) => c.length > 0 && top(c) === k));
688
+ const pieces = result.parts.flatMap((parts, k) => parts.length ? [{ path: joined(parts), source: index[k] }] : []);
689
+ return { ...report(result), pieces };
690
+ }
691
+ case "merge": {
692
+ const keys = [];
693
+ for (let k = 0; k < m; k++) if (!keys.includes(key(k))) keys.push(key(k));
694
+ const result = select(keys.map((kk) => (c) => c.length > 0 && key(top(c)) === kk));
695
+ const pieces = [];
696
+ result.parts.forEach((parts, j) => {
697
+ let source = 0;
698
+ for (let k = 0; k < m; k++) if (key(k) === keys[j]) source = index[k];
699
+ for (const part of parts) pieces.push({ path: part, source });
700
+ });
701
+ return { ...report(result), pieces };
702
+ }
703
+ case "crop": {
704
+ if (m < 2) return { pieces: [], engine: "curve" };
705
+ const front = m - 1;
706
+ const result = select(
707
+ index.slice(0, front).map((_, k) => (c) => c.length >= 2 && top(c) === front && c[c.length - 2] === k)
708
+ );
709
+ const pieces = result.parts.flatMap((parts, k) => parts.length ? [{ path: joined(parts), source: index[k] }] : []);
710
+ return { ...report(result), pieces };
711
+ }
712
+ case "minusBack": {
713
+ const front = m - 1;
714
+ const result = select([(c) => c.length === 1 && c[0] === front]);
715
+ const parts = result.parts[0];
716
+ return { ...report(result), pieces: parts.length ? [{ path: joined(parts), source: index[front] }] : [] };
717
+ }
718
+ }
719
+ return { pieces: [], engine: "curve" };
720
+ }
721
+ function report(r) {
722
+ return { engine: r.engine, ...r.fallbackReason ? { fallbackReason: r.fallbackReason } : {}, ...r.error ? { error: r.error } : {} };
723
+ }
724
+ function closeAll(path) {
725
+ return _chunkO2UH7LZEcjs.contoursToPath.call(void 0, _chunkO2UH7LZEcjs.pathToContours.call(void 0, path).map((c) => ({ segments: c.segments, closed: true })));
726
+ }
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+ exports.interiorPoint = interiorPoint; exports.PlanarMap = PlanarMap; exports.contourEnclosesArea = contourEnclosesArea; exports.cutOutPiece = cutOutPiece; exports.hatchPath = hatchPath; exports.PATHFINDER_OPERATIONS = PATHFINDER_OPERATIONS; exports.pathfinder = pathfinder;
737
+ //# sourceMappingURL=chunk-MLREO6J3.cjs.map