@pooder/kit 5.3.0 → 5.3.1

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 (60) 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/feature.js +826 -826
  9. package/.test-dist/src/featureComplete.js +32 -32
  10. package/.test-dist/src/film.js +167 -167
  11. package/.test-dist/src/geometry.js +506 -506
  12. package/.test-dist/src/image.js +1250 -1250
  13. package/.test-dist/src/maskOps.js +270 -270
  14. package/.test-dist/src/mirror.js +104 -104
  15. package/.test-dist/src/renderSpec.js +2 -2
  16. package/.test-dist/src/ruler.js +343 -343
  17. package/.test-dist/src/sceneLayout.js +99 -99
  18. package/.test-dist/src/sceneLayoutModel.js +196 -196
  19. package/.test-dist/src/sceneView.js +40 -40
  20. package/.test-dist/src/sceneVisibility.js +42 -42
  21. package/.test-dist/src/size.js +332 -332
  22. package/.test-dist/src/tracer.js +544 -544
  23. package/.test-dist/src/white-ink.js +829 -829
  24. package/.test-dist/src/wrappedOffsets.js +33 -33
  25. package/CHANGELOG.md +6 -0
  26. package/dist/index.d.mts +6 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +108 -20
  29. package/dist/index.mjs +108 -20
  30. package/package.json +1 -1
  31. package/src/coordinate.ts +106 -106
  32. package/src/extensions/background.ts +230 -230
  33. package/src/extensions/bridgeSelection.ts +17 -17
  34. package/src/extensions/constraints.ts +322 -322
  35. package/src/extensions/dieline.ts +46 -0
  36. package/src/extensions/edgeScale.ts +19 -19
  37. package/src/extensions/feature.ts +1021 -1021
  38. package/src/extensions/featureComplete.ts +46 -46
  39. package/src/extensions/film.ts +194 -194
  40. package/src/extensions/geometry.ts +752 -719
  41. package/src/extensions/image.ts +1926 -1924
  42. package/src/extensions/index.ts +11 -11
  43. package/src/extensions/maskOps.ts +283 -283
  44. package/src/extensions/mirror.ts +128 -128
  45. package/src/extensions/ruler.ts +451 -451
  46. package/src/extensions/sceneLayout.ts +140 -140
  47. package/src/extensions/sceneLayoutModel.ts +352 -342
  48. package/src/extensions/sceneVisibility.ts +71 -71
  49. package/src/extensions/size.ts +389 -389
  50. package/src/extensions/tracer.ts +58 -19
  51. package/src/extensions/white-ink.ts +1400 -1400
  52. package/src/extensions/wrappedOffsets.ts +33 -33
  53. package/src/index.ts +2 -2
  54. package/src/services/CanvasService.ts +300 -300
  55. package/src/services/ViewportSystem.ts +95 -95
  56. package/src/services/index.ts +3 -3
  57. package/src/services/renderSpec.ts +18 -18
  58. package/src/units.ts +27 -27
  59. package/tests/run.ts +118 -118
  60. package/tsconfig.test.json +15 -15
@@ -306,14 +306,10 @@ export class ImageTracer {
306
306
 
307
307
  const baseUnpaddedContours = baseContours
308
308
  .map((contour) =>
309
- this.clampPointsToImageBounds(
310
- contour.map((p) => ({
311
- x: p.x - padding,
312
- y: p.y - padding,
313
- })),
314
- width,
315
- height,
316
- ),
309
+ contour.map((p) => ({
310
+ x: p.x - padding,
311
+ y: p.y - padding,
312
+ })),
317
313
  )
318
314
  .filter((contour) => contour.length > 2);
319
315
 
@@ -418,6 +414,49 @@ export class ImageTracer {
418
414
  );
419
415
  }
420
416
 
417
+ if (expand > 0) {
418
+ const expectedExpandedBounds = {
419
+ x: baseBounds.x - expand,
420
+ y: baseBounds.y - expand,
421
+ width: baseBounds.width + expand * 2,
422
+ height: baseBounds.height + expand * 2,
423
+ };
424
+ if (
425
+ expectedExpandedBounds.width > 0 &&
426
+ expectedExpandedBounds.height > 0 &&
427
+ globalBounds.width > 0 &&
428
+ globalBounds.height > 0
429
+ ) {
430
+ const shouldNormalizeExpandBounds =
431
+ Math.abs(globalBounds.x - expectedExpandedBounds.x) > 1 ||
432
+ Math.abs(globalBounds.y - expectedExpandedBounds.y) > 1 ||
433
+ Math.abs(globalBounds.width - expectedExpandedBounds.width) > 1 ||
434
+ Math.abs(globalBounds.height - expectedExpandedBounds.height) > 1;
435
+ if (shouldNormalizeExpandBounds) {
436
+ const beforeNormalize = globalBounds;
437
+ finalContours = this.translateContours(
438
+ this.scaleContours(
439
+ finalContours,
440
+ expectedExpandedBounds.width,
441
+ expectedExpandedBounds.height,
442
+ globalBounds,
443
+ ),
444
+ expectedExpandedBounds.x,
445
+ expectedExpandedBounds.y,
446
+ );
447
+ globalBounds = this.boundsFromPoints(
448
+ this.flattenContours(finalContours),
449
+ );
450
+ debugLog("traceWithBounds:expand-normalized", {
451
+ expand,
452
+ expectedExpandedBounds,
453
+ beforeNormalize,
454
+ afterNormalize: globalBounds,
455
+ });
456
+ }
457
+ }
458
+ }
459
+
421
460
  // Simplify and Generate SVG
422
461
  debugLog("traceWithBounds:contours", {
423
462
  baseContourCount: baseContoursRaw.length,
@@ -892,17 +931,17 @@ export class ImageTracer {
892
931
  );
893
932
  }
894
933
 
895
- private static clampPointsToImageBounds(
896
- points: Point[],
897
- width: number,
898
- height: number,
899
- ): Point[] {
900
- const maxX = Math.max(0, width);
901
- const maxY = Math.max(0, height);
902
- return points.map((p) => ({
903
- x: Math.max(0, Math.min(maxX, p.x)),
904
- y: Math.max(0, Math.min(maxY, p.y)),
905
- }));
934
+ private static translateContours(
935
+ contours: Point[][],
936
+ offsetX: number,
937
+ offsetY: number,
938
+ ): Point[][] {
939
+ return contours.map((points) =>
940
+ points.map((p) => ({
941
+ x: p.x + offsetX,
942
+ y: p.y + offsetY,
943
+ })),
944
+ );
906
945
  }
907
946
 
908
947
  private static pointsToSVG(points: Point[]): string {