@pooder/kit 5.1.0 → 5.3.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 (86) hide show
  1. package/.test-dist/src/CanvasService.js +249 -249
  2. package/.test-dist/src/ViewportSystem.js +75 -75
  3. package/.test-dist/src/background.js +203 -203
  4. package/.test-dist/src/bridgeSelection.js +20 -20
  5. package/.test-dist/src/constraints.js +237 -237
  6. package/.test-dist/src/dieline.js +818 -818
  7. package/.test-dist/src/edgeScale.js +12 -12
  8. package/.test-dist/src/extensions/background.js +203 -0
  9. package/.test-dist/src/extensions/bridgeSelection.js +20 -0
  10. package/.test-dist/src/extensions/constraints.js +237 -0
  11. package/.test-dist/src/extensions/dieline.js +828 -0
  12. package/.test-dist/src/extensions/edgeScale.js +12 -0
  13. package/.test-dist/src/extensions/feature.js +825 -0
  14. package/.test-dist/src/extensions/featureComplete.js +32 -0
  15. package/.test-dist/src/extensions/film.js +167 -0
  16. package/.test-dist/src/extensions/geometry.js +545 -0
  17. package/.test-dist/src/extensions/image.js +1529 -0
  18. package/.test-dist/src/extensions/index.js +30 -0
  19. package/.test-dist/src/extensions/maskOps.js +279 -0
  20. package/.test-dist/src/extensions/mirror.js +104 -0
  21. package/.test-dist/src/extensions/ruler.js +345 -0
  22. package/.test-dist/src/extensions/sceneLayout.js +96 -0
  23. package/.test-dist/src/extensions/sceneLayoutModel.js +196 -0
  24. package/.test-dist/src/extensions/sceneVisibility.js +62 -0
  25. package/.test-dist/src/extensions/size.js +331 -0
  26. package/.test-dist/src/extensions/tracer.js +538 -0
  27. package/.test-dist/src/extensions/white-ink.js +1190 -0
  28. package/.test-dist/src/extensions/wrappedOffsets.js +33 -0
  29. package/.test-dist/src/feature.js +826 -826
  30. package/.test-dist/src/featureComplete.js +32 -32
  31. package/.test-dist/src/film.js +167 -167
  32. package/.test-dist/src/geometry.js +506 -506
  33. package/.test-dist/src/image.js +1250 -1250
  34. package/.test-dist/src/index.js +2 -19
  35. package/.test-dist/src/maskOps.js +270 -270
  36. package/.test-dist/src/mirror.js +104 -104
  37. package/.test-dist/src/renderSpec.js +2 -2
  38. package/.test-dist/src/ruler.js +343 -343
  39. package/.test-dist/src/sceneLayout.js +99 -99
  40. package/.test-dist/src/sceneLayoutModel.js +196 -196
  41. package/.test-dist/src/sceneView.js +40 -40
  42. package/.test-dist/src/sceneVisibility.js +42 -42
  43. package/.test-dist/src/services/CanvasService.js +249 -0
  44. package/.test-dist/src/services/ViewportSystem.js +76 -0
  45. package/.test-dist/src/services/index.js +24 -0
  46. package/.test-dist/src/services/renderSpec.js +2 -0
  47. package/.test-dist/src/size.js +332 -332
  48. package/.test-dist/src/tracer.js +544 -544
  49. package/.test-dist/src/white-ink.js +829 -829
  50. package/.test-dist/src/wrappedOffsets.js +33 -33
  51. package/CHANGELOG.md +12 -0
  52. package/dist/index.d.mts +14 -0
  53. package/dist/index.d.ts +14 -0
  54. package/dist/index.js +3521 -3220
  55. package/dist/index.mjs +3532 -3226
  56. package/package.json +1 -1
  57. package/src/coordinate.ts +106 -106
  58. package/src/extensions/background.ts +230 -230
  59. package/src/extensions/bridgeSelection.ts +17 -17
  60. package/src/extensions/constraints.ts +322 -322
  61. package/src/extensions/dieline.ts +20 -17
  62. package/src/extensions/edgeScale.ts +19 -19
  63. package/src/extensions/feature.ts +1021 -1021
  64. package/src/extensions/featureComplete.ts +46 -46
  65. package/src/extensions/film.ts +194 -194
  66. package/src/extensions/geometry.ts +719 -719
  67. package/src/extensions/image.ts +1924 -1594
  68. package/src/extensions/index.ts +11 -11
  69. package/src/extensions/maskOps.ts +365 -299
  70. package/src/extensions/mirror.ts +128 -128
  71. package/src/extensions/ruler.ts +451 -451
  72. package/src/extensions/sceneLayout.ts +140 -140
  73. package/src/extensions/sceneLayoutModel.ts +342 -342
  74. package/src/extensions/sceneVisibility.ts +71 -71
  75. package/src/extensions/size.ts +389 -389
  76. package/src/extensions/tracer.ts +302 -370
  77. package/src/extensions/white-ink.ts +1489 -1366
  78. package/src/extensions/wrappedOffsets.ts +33 -33
  79. package/src/index.ts +2 -2
  80. package/src/services/CanvasService.ts +300 -300
  81. package/src/services/ViewportSystem.ts +95 -95
  82. package/src/services/index.ts +3 -3
  83. package/src/services/renderSpec.ts +18 -18
  84. package/src/units.ts +27 -27
  85. package/tests/run.ts +118 -118
  86. package/tsconfig.test.json +15 -15
@@ -0,0 +1,545 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveFeaturePosition = resolveFeaturePosition;
7
+ exports.generateDielinePath = generateDielinePath;
8
+ exports.generateMaskPath = generateMaskPath;
9
+ exports.generateBleedZonePath = generateBleedZonePath;
10
+ exports.getLowestPointOnDieline = getLowestPointOnDieline;
11
+ exports.getNearestPointOnDieline = getNearestPointOnDieline;
12
+ exports.getPathBounds = getPathBounds;
13
+ const paper_1 = __importDefault(require("paper"));
14
+ const bridgeSelection_1 = require("./bridgeSelection");
15
+ const wrappedOffsets_1 = require("./wrappedOffsets");
16
+ /**
17
+ * Resolves the absolute position of a feature based on normalized coordinates.
18
+ */
19
+ function resolveFeaturePosition(feature, geometry) {
20
+ const { x, y, width, height } = geometry;
21
+ // geometry.x/y is the Center.
22
+ const left = x - width / 2;
23
+ const top = y - height / 2;
24
+ return {
25
+ x: left + feature.x * width,
26
+ y: top + feature.y * height,
27
+ };
28
+ }
29
+ /**
30
+ * Initializes paper.js project if not already initialized.
31
+ */
32
+ function ensurePaper(width, height) {
33
+ if (!paper_1.default.project) {
34
+ paper_1.default.setup(new paper_1.default.Size(width, height));
35
+ }
36
+ else {
37
+ paper_1.default.view.viewSize = new paper_1.default.Size(width, height);
38
+ }
39
+ }
40
+ const isBridgeDebugEnabled = () => Boolean(globalThis.__POODER_BRIDGE_DEBUG__);
41
+ function normalizePathItem(shape) {
42
+ let result = shape;
43
+ if (typeof result.resolveCrossings === "function")
44
+ result = result.resolveCrossings();
45
+ if (typeof result.reduce === "function")
46
+ result = result.reduce({});
47
+ if (typeof result.reorient === "function")
48
+ result = result.reorient(true, true);
49
+ if (typeof result.reduce === "function")
50
+ result = result.reduce({});
51
+ return result;
52
+ }
53
+ function getBridgeDelta(itemBounds, overlap) {
54
+ return Math.max(overlap, Math.min(5, Math.max(1, itemBounds.height * 0.02)));
55
+ }
56
+ function getExitHit(args) {
57
+ const { mainShape, x, bridgeBottom, toY, eps, delta, overlap, op } = args;
58
+ const ray = new paper_1.default.Path.Line({
59
+ from: [x, bridgeBottom],
60
+ to: [x, toY],
61
+ insert: false,
62
+ });
63
+ const intersections = mainShape.getIntersections(ray) || [];
64
+ ray.remove();
65
+ const validHits = intersections.filter((i) => i.point.y < bridgeBottom - eps);
66
+ if (validHits.length === 0)
67
+ return null;
68
+ validHits.sort((a, b) => b.point.y - a.point.y);
69
+ const flags = validHits.map((h) => {
70
+ const above = h.point.add(new paper_1.default.Point(0, -delta));
71
+ const below = h.point.add(new paper_1.default.Point(0, delta));
72
+ return {
73
+ insideAbove: mainShape.contains(above),
74
+ insideBelow: mainShape.contains(below),
75
+ };
76
+ });
77
+ const idx = (0, bridgeSelection_1.pickExitIndex)(flags);
78
+ if (idx < 0)
79
+ return null;
80
+ if (isBridgeDebugEnabled()) {
81
+ console.debug("Geometry: Bridge ray", {
82
+ x,
83
+ validHits: validHits.length,
84
+ idx,
85
+ delta,
86
+ overlap,
87
+ op,
88
+ });
89
+ }
90
+ const hit = validHits[idx];
91
+ return { point: hit.point, location: hit };
92
+ }
93
+ function selectOuterChain(args) {
94
+ const { mainShape, pointsA, pointsB, delta, overlap, op } = args;
95
+ const scoreA = (0, bridgeSelection_1.scoreOutsideAbove)(pointsA.map((p) => ({
96
+ outsideAbove: !mainShape.contains(p.add(new paper_1.default.Point(0, -delta))),
97
+ })));
98
+ const scoreB = (0, bridgeSelection_1.scoreOutsideAbove)(pointsB.map((p) => ({
99
+ outsideAbove: !mainShape.contains(p.add(new paper_1.default.Point(0, -delta))),
100
+ })));
101
+ const ratioA = scoreA / pointsA.length;
102
+ const ratioB = scoreB / pointsB.length;
103
+ if (isBridgeDebugEnabled()) {
104
+ console.debug("Geometry: Bridge chain", {
105
+ scoreA,
106
+ scoreB,
107
+ lenA: pointsA.length,
108
+ lenB: pointsB.length,
109
+ ratioA,
110
+ ratioB,
111
+ delta,
112
+ overlap,
113
+ op,
114
+ });
115
+ }
116
+ const ratioEps = 1e-6;
117
+ if (Math.abs(ratioA - ratioB) > ratioEps) {
118
+ return ratioA > ratioB ? pointsA : pointsB;
119
+ }
120
+ if (scoreA !== scoreB)
121
+ return scoreA > scoreB ? pointsA : pointsB;
122
+ return pointsA.length <= pointsB.length ? pointsA : pointsB;
123
+ }
124
+ /**
125
+ * Creates the base dieline shape (Rect/Circle/Ellipse/Custom)
126
+ */
127
+ function createBaseShape(options) {
128
+ const { shape, width, height, radius, x, y, pathData } = options;
129
+ const center = new paper_1.default.Point(x, y);
130
+ if (shape === "rect") {
131
+ return new paper_1.default.Path.Rectangle({
132
+ point: [x - width / 2, y - height / 2],
133
+ size: [Math.max(0, width), Math.max(0, height)],
134
+ radius: Math.max(0, radius),
135
+ });
136
+ }
137
+ else if (shape === "circle") {
138
+ const r = Math.min(width, height) / 2;
139
+ return new paper_1.default.Path.Circle({
140
+ center: center,
141
+ radius: Math.max(0, r),
142
+ });
143
+ }
144
+ else if (shape === "ellipse") {
145
+ return new paper_1.default.Path.Ellipse({
146
+ center: center,
147
+ radius: [Math.max(0, width / 2), Math.max(0, height / 2)],
148
+ });
149
+ }
150
+ else if (shape === "custom" && pathData) {
151
+ const hasMultipleSubPaths = ((pathData.match(/[Mm]/g) || []).length ?? 0) > 1;
152
+ const path = hasMultipleSubPaths
153
+ ? new paper_1.default.CompoundPath(pathData)
154
+ : (() => {
155
+ const single = new paper_1.default.Path();
156
+ single.pathData = pathData;
157
+ return single;
158
+ })();
159
+ // Align center
160
+ path.position = center;
161
+ if (width > 0 &&
162
+ height > 0 &&
163
+ path.bounds.width > 0 &&
164
+ path.bounds.height > 0) {
165
+ path.scale(width / path.bounds.width, height / path.bounds.height);
166
+ }
167
+ return path;
168
+ }
169
+ else {
170
+ return new paper_1.default.Path.Rectangle({
171
+ point: [x - width / 2, y - height / 2],
172
+ size: [Math.max(0, width), Math.max(0, height)],
173
+ });
174
+ }
175
+ }
176
+ function resolveBridgeBasePath(shape, anchor) {
177
+ if (shape instanceof paper_1.default.Path) {
178
+ return shape;
179
+ }
180
+ if (shape instanceof paper_1.default.CompoundPath) {
181
+ const children = (shape.children || []).filter((child) => child instanceof paper_1.default.Path);
182
+ if (!children.length)
183
+ return null;
184
+ let best = children[0];
185
+ let bestDistance = Infinity;
186
+ for (const child of children) {
187
+ const location = child.getNearestLocation(anchor);
188
+ const point = location?.point;
189
+ if (!point)
190
+ continue;
191
+ const distance = point.getDistance(anchor);
192
+ if (distance < bestDistance) {
193
+ bestDistance = distance;
194
+ best = child;
195
+ }
196
+ }
197
+ return best;
198
+ }
199
+ return null;
200
+ }
201
+ /**
202
+ * Creates a Paper.js Item for a single feature.
203
+ */
204
+ function createFeatureItem(feature, center) {
205
+ let item;
206
+ if (feature.shape === "rect") {
207
+ const w = feature.width || 10;
208
+ const h = feature.height || 10;
209
+ const r = feature.radius || 0;
210
+ item = new paper_1.default.Path.Rectangle({
211
+ point: [center.x - w / 2, center.y - h / 2],
212
+ size: [w, h],
213
+ radius: r,
214
+ });
215
+ }
216
+ else {
217
+ // Circle
218
+ const r = feature.radius || 5;
219
+ item = new paper_1.default.Path.Circle({
220
+ center: center,
221
+ radius: r,
222
+ });
223
+ }
224
+ if (feature.rotation) {
225
+ item.rotate(feature.rotation, center);
226
+ }
227
+ return item;
228
+ }
229
+ /**
230
+ * Internal helper to generate the Perimeter Shape (Base + Edge Features).
231
+ */
232
+ function getPerimeterShape(options) {
233
+ // 1. Create Base Shape
234
+ let mainShape = createBaseShape(options);
235
+ const { features } = options;
236
+ if (features && features.length > 0) {
237
+ // Filter for Edge Features (Default is Edge, unless explicit 'surface')
238
+ const edgeFeatures = features.filter((f) => !f.renderBehavior || f.renderBehavior === "edge");
239
+ const adds = [];
240
+ const subtracts = [];
241
+ edgeFeatures.forEach((f) => {
242
+ const pos = resolveFeaturePosition(f, options);
243
+ const center = new paper_1.default.Point(pos.x, pos.y);
244
+ const item = createFeatureItem(f, center);
245
+ // Handle Bridge logic: Create a connection shape to the main body
246
+ if (f.bridge && f.bridge.type === "vertical") {
247
+ const itemBounds = item.bounds;
248
+ const mainBounds = mainShape.bounds;
249
+ const bridgeTop = mainBounds.top;
250
+ const bridgeBottom = itemBounds.top;
251
+ if (bridgeBottom > bridgeTop) {
252
+ const overlap = 2;
253
+ const rayPadding = 10;
254
+ const eps = 0.1;
255
+ const delta = getBridgeDelta(itemBounds, overlap);
256
+ const toY = bridgeTop - rayPadding;
257
+ const inset = Math.min(1, Math.max(0, itemBounds.width * 0.01));
258
+ const xLeft = itemBounds.left + inset;
259
+ const xRight = itemBounds.right - inset;
260
+ const bridgeBasePath = resolveBridgeBasePath(mainShape, center);
261
+ const canBridge = !!bridgeBasePath && xRight - xLeft > eps;
262
+ if (canBridge && bridgeBasePath) {
263
+ const leftHit = getExitHit({
264
+ mainShape: bridgeBasePath,
265
+ x: xLeft,
266
+ bridgeBottom,
267
+ toY,
268
+ eps,
269
+ delta,
270
+ overlap,
271
+ op: f.operation,
272
+ });
273
+ const rightHit = getExitHit({
274
+ mainShape: bridgeBasePath,
275
+ x: xRight,
276
+ bridgeBottom,
277
+ toY,
278
+ eps,
279
+ delta,
280
+ overlap,
281
+ op: f.operation,
282
+ });
283
+ if (leftHit && rightHit) {
284
+ const pathLength = bridgeBasePath.length;
285
+ const leftOffset = leftHit.location.offset;
286
+ const rightOffset = rightHit.location.offset;
287
+ const distanceA = (0, wrappedOffsets_1.wrappedDistance)(pathLength, leftOffset, rightOffset);
288
+ const distanceB = (0, wrappedOffsets_1.wrappedDistance)(pathLength, rightOffset, leftOffset);
289
+ const countFor = (d) => Math.max(8, Math.min(80, Math.ceil(d / 6)));
290
+ const offsetsA = (0, wrappedOffsets_1.sampleWrappedOffsets)(pathLength, leftOffset, rightOffset, countFor(distanceA));
291
+ const offsetsB = (0, wrappedOffsets_1.sampleWrappedOffsets)(pathLength, rightOffset, leftOffset, countFor(distanceB));
292
+ const pointsA = offsetsA
293
+ .map((o) => bridgeBasePath.getPointAt(o))
294
+ .filter((p) => Boolean(p));
295
+ const pointsB = offsetsB
296
+ .map((o) => bridgeBasePath.getPointAt(o))
297
+ .filter((p) => Boolean(p));
298
+ if (pointsA.length >= 2 && pointsB.length >= 2) {
299
+ let topBase = selectOuterChain({
300
+ mainShape: bridgeBasePath,
301
+ pointsA,
302
+ pointsB,
303
+ delta,
304
+ overlap,
305
+ op: f.operation,
306
+ });
307
+ const dist2 = (a, b) => {
308
+ const dx = a.x - b.x;
309
+ const dy = a.y - b.y;
310
+ return dx * dx + dy * dy;
311
+ };
312
+ if (dist2(topBase[0], leftHit.point) >
313
+ dist2(topBase[0], rightHit.point)) {
314
+ topBase = topBase.slice().reverse();
315
+ }
316
+ topBase = topBase.slice();
317
+ topBase[0] = leftHit.point;
318
+ topBase[topBase.length - 1] = rightHit.point;
319
+ const capShiftY = f.operation === "subtract"
320
+ ? -Math.max(overlap * 2, delta)
321
+ : overlap;
322
+ const topPoints = topBase.map((p) => p.add(new paper_1.default.Point(0, capShiftY)));
323
+ const bridgeBottomY = bridgeBottom + overlap * 2;
324
+ const bridgePoly = new paper_1.default.Path({ insert: false });
325
+ for (const p of topPoints)
326
+ bridgePoly.add(p);
327
+ bridgePoly.add(new paper_1.default.Point(xRight, bridgeBottomY));
328
+ bridgePoly.add(new paper_1.default.Point(xLeft, bridgeBottomY));
329
+ bridgePoly.closed = true;
330
+ const unitedItem = item.unite(bridgePoly);
331
+ item.remove();
332
+ bridgePoly.remove();
333
+ if (f.operation === "add") {
334
+ adds.push(unitedItem);
335
+ }
336
+ else {
337
+ subtracts.push(unitedItem);
338
+ }
339
+ return;
340
+ }
341
+ }
342
+ }
343
+ if (f.operation === "add") {
344
+ adds.push(item);
345
+ }
346
+ else {
347
+ subtracts.push(item);
348
+ }
349
+ }
350
+ else {
351
+ if (f.operation === "add") {
352
+ adds.push(item);
353
+ }
354
+ else {
355
+ subtracts.push(item);
356
+ }
357
+ }
358
+ }
359
+ else {
360
+ if (f.operation === "add") {
361
+ adds.push(item);
362
+ }
363
+ else {
364
+ subtracts.push(item);
365
+ }
366
+ }
367
+ });
368
+ // 2. Process Additions (Union)
369
+ if (adds.length > 0) {
370
+ for (const item of adds) {
371
+ try {
372
+ const temp = mainShape.unite(item);
373
+ mainShape.remove();
374
+ item.remove();
375
+ mainShape = normalizePathItem(temp);
376
+ }
377
+ catch (e) {
378
+ console.error("Geometry: Failed to unite feature", e);
379
+ item.remove();
380
+ }
381
+ }
382
+ }
383
+ // 3. Process Subtractions (Difference)
384
+ if (subtracts.length > 0) {
385
+ for (const item of subtracts) {
386
+ try {
387
+ const temp = mainShape.subtract(item);
388
+ mainShape.remove();
389
+ item.remove();
390
+ mainShape = normalizePathItem(temp);
391
+ }
392
+ catch (e) {
393
+ console.error("Geometry: Failed to subtract feature", e);
394
+ item.remove();
395
+ }
396
+ }
397
+ }
398
+ }
399
+ return mainShape;
400
+ }
401
+ /**
402
+ * Applies Internal/Surface features to a shape.
403
+ */
404
+ function applySurfaceFeatures(shape, features, options) {
405
+ const surfaceFeatures = features.filter((f) => f.renderBehavior === "surface");
406
+ if (surfaceFeatures.length === 0)
407
+ return shape;
408
+ let result = shape;
409
+ // Internal features are usually subtractive (holes)
410
+ // But we support 'add' too (islands? maybe just unite)
411
+ for (const f of surfaceFeatures) {
412
+ const pos = resolveFeaturePosition(f, options);
413
+ const center = new paper_1.default.Point(pos.x, pos.y);
414
+ const item = createFeatureItem(f, center);
415
+ try {
416
+ if (f.operation === "add") {
417
+ const temp = result.unite(item);
418
+ result.remove();
419
+ item.remove();
420
+ result = normalizePathItem(temp);
421
+ }
422
+ else {
423
+ const temp = result.subtract(item);
424
+ result.remove();
425
+ item.remove();
426
+ result = normalizePathItem(temp);
427
+ }
428
+ }
429
+ catch (e) {
430
+ console.error("Geometry: Failed to apply surface feature", e);
431
+ item.remove();
432
+ }
433
+ }
434
+ return result;
435
+ }
436
+ /**
437
+ * Generates the path data for the Dieline (Product Shape).
438
+ */
439
+ function generateDielinePath(options) {
440
+ const paperWidth = options.canvasWidth || options.width * 2 || 2000;
441
+ const paperHeight = options.canvasHeight || options.height * 2 || 2000;
442
+ ensurePaper(paperWidth, paperHeight);
443
+ paper_1.default.project.activeLayer.removeChildren();
444
+ const perimeter = getPerimeterShape(options);
445
+ const finalShape = applySurfaceFeatures(perimeter, options.features, options);
446
+ const pathData = finalShape.pathData;
447
+ finalShape.remove();
448
+ return pathData;
449
+ }
450
+ /**
451
+ * Generates the path data for the Mask (Background Overlay).
452
+ * Logic: Canvas SUBTRACT ProductShape
453
+ */
454
+ function generateMaskPath(options) {
455
+ ensurePaper(options.canvasWidth, options.canvasHeight);
456
+ paper_1.default.project.activeLayer.removeChildren();
457
+ const { canvasWidth, canvasHeight } = options;
458
+ const maskRect = new paper_1.default.Path.Rectangle({
459
+ point: [0, 0],
460
+ size: [canvasWidth, canvasHeight],
461
+ });
462
+ const perimeter = getPerimeterShape(options);
463
+ const mainShape = applySurfaceFeatures(perimeter, options.features, options);
464
+ const finalMask = maskRect.subtract(mainShape);
465
+ maskRect.remove();
466
+ mainShape.remove();
467
+ const pathData = finalMask.pathData;
468
+ finalMask.remove();
469
+ return pathData;
470
+ }
471
+ /**
472
+ * Generates the path data for the Bleed Zone.
473
+ */
474
+ function generateBleedZonePath(originalOptions, offsetOptions, offset) {
475
+ const paperWidth = originalOptions.canvasWidth || originalOptions.width * 2 || 2000;
476
+ const paperHeight = originalOptions.canvasHeight || originalOptions.height * 2 || 2000;
477
+ ensurePaper(paperWidth, paperHeight);
478
+ paper_1.default.project.activeLayer.removeChildren();
479
+ // 1. Generate Original Shape
480
+ const pOriginal = getPerimeterShape(originalOptions);
481
+ const shapeOriginal = applySurfaceFeatures(pOriginal, originalOptions.features, originalOptions);
482
+ // 2. Generate Offset Shape
483
+ const pOffset = getPerimeterShape(offsetOptions);
484
+ const shapeOffset = applySurfaceFeatures(pOffset, offsetOptions.features, offsetOptions);
485
+ // 3. Calculate Difference
486
+ let bleedZone;
487
+ if (offset > 0) {
488
+ bleedZone = shapeOffset.subtract(shapeOriginal);
489
+ }
490
+ else {
491
+ bleedZone = shapeOriginal.subtract(shapeOffset);
492
+ }
493
+ const pathData = bleedZone.pathData;
494
+ shapeOriginal.remove();
495
+ shapeOffset.remove();
496
+ bleedZone.remove();
497
+ return pathData;
498
+ }
499
+ /**
500
+ * Finds the lowest point (Max Y) on the Dieline geometry (Base Shape ONLY).
501
+ */
502
+ function getLowestPointOnDieline(options) {
503
+ ensurePaper(options.width * 2, options.height * 2);
504
+ paper_1.default.project.activeLayer.removeChildren();
505
+ const shape = createBaseShape(options);
506
+ const bounds = shape.bounds;
507
+ const result = {
508
+ x: bounds.center.x,
509
+ y: bounds.bottom,
510
+ };
511
+ shape.remove();
512
+ return result;
513
+ }
514
+ /**
515
+ * Finds the nearest point on the Dieline geometry (Base Shape ONLY) for a given target point.
516
+ * Used for constraining feature movement.
517
+ */
518
+ function getNearestPointOnDieline(point, options) {
519
+ ensurePaper(options.width * 2, options.height * 2);
520
+ paper_1.default.project.activeLayer.removeChildren();
521
+ // We constrain to the BASE shape, not including other features,
522
+ // because usually you want to snap to the main edge.
523
+ const shape = createBaseShape(options);
524
+ const p = new paper_1.default.Point(point.x, point.y);
525
+ const location = shape.getNearestLocation(p);
526
+ const result = {
527
+ x: location.point.x,
528
+ y: location.point.y,
529
+ normal: location.normal ? { x: location.normal.x, y: location.normal.y } : undefined
530
+ };
531
+ shape.remove();
532
+ return result;
533
+ }
534
+ function getPathBounds(pathData) {
535
+ const path = new paper_1.default.Path();
536
+ path.pathData = pathData;
537
+ const bounds = path.bounds;
538
+ path.remove();
539
+ return {
540
+ x: bounds.x,
541
+ y: bounds.y,
542
+ width: bounds.width,
543
+ height: bounds.height,
544
+ };
545
+ }