@pooder/kit 5.3.1 → 6.0.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/.test-dist/src/extensions/background.js +475 -131
  2. package/.test-dist/src/extensions/dieline.js +283 -180
  3. package/.test-dist/src/extensions/dielineShape.js +66 -0
  4. package/.test-dist/src/extensions/feature.js +388 -303
  5. package/.test-dist/src/extensions/film.js +133 -74
  6. package/.test-dist/src/extensions/geometry.js +120 -56
  7. package/.test-dist/src/extensions/image.js +296 -212
  8. package/.test-dist/src/extensions/index.js +1 -3
  9. package/.test-dist/src/extensions/maskOps.js +75 -20
  10. package/.test-dist/src/extensions/ruler.js +312 -215
  11. package/.test-dist/src/extensions/sceneLayoutModel.js +9 -3
  12. package/.test-dist/src/extensions/sceneVisibility.js +3 -10
  13. package/.test-dist/src/extensions/tracer.js +229 -58
  14. package/.test-dist/src/extensions/white-ink.js +139 -129
  15. package/.test-dist/src/services/CanvasService.js +888 -126
  16. package/.test-dist/src/services/index.js +1 -0
  17. package/.test-dist/src/services/visibility.js +54 -0
  18. package/.test-dist/tests/run.js +58 -4
  19. package/CHANGELOG.md +12 -0
  20. package/dist/index.d.mts +377 -82
  21. package/dist/index.d.ts +377 -82
  22. package/dist/index.js +3920 -2178
  23. package/dist/index.mjs +3992 -2247
  24. package/package.json +1 -1
  25. package/src/extensions/background.ts +631 -145
  26. package/src/extensions/dieline.ts +280 -187
  27. package/src/extensions/dielineShape.ts +109 -0
  28. package/src/extensions/feature.ts +485 -366
  29. package/src/extensions/film.ts +152 -76
  30. package/src/extensions/geometry.ts +203 -104
  31. package/src/extensions/image.ts +319 -238
  32. package/src/extensions/index.ts +0 -1
  33. package/src/extensions/ruler.ts +481 -268
  34. package/src/extensions/sceneLayoutModel.ts +18 -6
  35. package/src/extensions/white-ink.ts +157 -171
  36. package/src/services/CanvasService.ts +1126 -140
  37. package/src/services/index.ts +1 -0
  38. package/src/services/renderSpec.ts +69 -4
  39. package/src/services/visibility.ts +78 -0
  40. package/tests/run.ts +139 -4
  41. package/.test-dist/src/CanvasService.js +0 -249
  42. package/.test-dist/src/ViewportSystem.js +0 -75
  43. package/.test-dist/src/background.js +0 -203
  44. package/.test-dist/src/bridgeSelection.js +0 -20
  45. package/.test-dist/src/constraints.js +0 -237
  46. package/.test-dist/src/dieline.js +0 -818
  47. package/.test-dist/src/edgeScale.js +0 -12
  48. package/.test-dist/src/feature.js +0 -826
  49. package/.test-dist/src/featureComplete.js +0 -32
  50. package/.test-dist/src/film.js +0 -167
  51. package/.test-dist/src/geometry.js +0 -506
  52. package/.test-dist/src/image.js +0 -1250
  53. package/.test-dist/src/maskOps.js +0 -270
  54. package/.test-dist/src/mirror.js +0 -104
  55. package/.test-dist/src/renderSpec.js +0 -2
  56. package/.test-dist/src/ruler.js +0 -343
  57. package/.test-dist/src/sceneLayout.js +0 -99
  58. package/.test-dist/src/sceneLayoutModel.js +0 -196
  59. package/.test-dist/src/sceneView.js +0 -40
  60. package/.test-dist/src/sceneVisibility.js +0 -42
  61. package/.test-dist/src/size.js +0 -332
  62. package/.test-dist/src/tracer.js +0 -544
  63. package/.test-dist/src/white-ink.js +0 -829
  64. package/.test-dist/src/wrappedOffsets.js +0 -33
  65. package/src/extensions/sceneVisibility.ts +0 -71
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SceneVisibilityService = exports.SceneLayoutService = void 0;
17
+ exports.SceneLayoutService = void 0;
18
18
  __exportStar(require("./background"), exports);
19
19
  __exportStar(require("./image"), exports);
20
20
  __exportStar(require("./size"), exports);
@@ -26,5 +26,3 @@ __exportStar(require("./ruler"), exports);
26
26
  __exportStar(require("./white-ink"), exports);
27
27
  var sceneLayout_1 = require("./sceneLayout");
28
28
  Object.defineProperty(exports, "SceneLayoutService", { enumerable: true, get: function () { return sceneLayout_1.SceneLayoutService; } });
29
- var sceneVisibility_1 = require("./sceneVisibility");
30
- Object.defineProperty(exports, "SceneVisibilityService", { enumerable: true, get: function () { return sceneVisibility_1.SceneVisibilityService; } });
@@ -69,16 +69,21 @@ function analyzeAlpha(imageData, alphaOpaqueCutoff) {
69
69
  };
70
70
  }
71
71
  function circularMorphology(mask, width, height, radius, op) {
72
- const dilate = (m, r) => {
72
+ const r = Math.max(0, Math.floor(radius));
73
+ if (r <= 0) {
74
+ return mask.slice();
75
+ }
76
+ // Disk kernel dilation (Euclidean metric).
77
+ const dilateDisk = (m, radiusPx) => {
73
78
  const horizontalDist = new Int32Array(width * height);
74
79
  for (let y = 0; y < height; y++) {
75
- let lastSolid = -r * 2;
80
+ let lastSolid = -radiusPx * 2;
76
81
  for (let x = 0; x < width; x++) {
77
82
  if (m[y * width + x])
78
83
  lastSolid = x;
79
84
  horizontalDist[y * width + x] = x - lastSolid;
80
85
  }
81
- lastSolid = width + r * 2;
86
+ lastSolid = width + radiusPx * 2;
82
87
  for (let x = width - 1; x >= 0; x--) {
83
88
  if (m[y * width + x])
84
89
  lastSolid = x;
@@ -86,12 +91,12 @@ function circularMorphology(mask, width, height, radius, op) {
86
91
  }
87
92
  }
88
93
  const result = new Uint8Array(width * height);
89
- const r2 = r * r;
94
+ const r2 = radiusPx * radiusPx;
90
95
  for (let x = 0; x < width; x++) {
91
96
  for (let y = 0; y < height; y++) {
92
97
  let found = false;
93
- const minY = Math.max(0, y - r);
94
- const maxY = Math.min(height - 1, y + r);
98
+ const minY = Math.max(0, y - radiusPx);
99
+ const maxY = Math.min(height - 1, y + radiusPx);
95
100
  for (let dy = minY; dy <= maxY; dy++) {
96
101
  const dY = dy - y;
97
102
  const hDist = horizontalDist[dy * width + x];
@@ -106,25 +111,75 @@ function circularMorphology(mask, width, height, radius, op) {
106
111
  }
107
112
  return result;
108
113
  };
109
- const erode = (m, r) => {
110
- const inverted = new Uint8Array(m.length);
111
- for (let i = 0; i < m.length; i++)
112
- inverted[i] = m[i] ? 0 : 1;
113
- const dilatedInverted = dilate(inverted, r);
114
- const result = new Uint8Array(m.length);
115
- for (let i = 0; i < m.length; i++)
116
- result[i] = dilatedInverted[i] ? 0 : 1;
117
- return result;
114
+ // Diamond kernel erosion (L1 metric), implemented as radius iterations of
115
+ // 4-neighbor erosion. This is intentionally different from dilation kernel.
116
+ const erodeDiamond = (m, radiusPx) => {
117
+ if (radiusPx <= 0)
118
+ return m.slice();
119
+ let current = m;
120
+ for (let step = 0; step < radiusPx; step++) {
121
+ const next = new Uint8Array(width * height);
122
+ for (let y = 1; y < height - 1; y++) {
123
+ const row = y * width;
124
+ for (let x = 1; x < width - 1; x++) {
125
+ const idx = row + x;
126
+ if (current[idx] &&
127
+ current[idx - 1] &&
128
+ current[idx + 1] &&
129
+ current[idx - width] &&
130
+ current[idx + width]) {
131
+ next[idx] = 1;
132
+ }
133
+ }
134
+ }
135
+ current = next;
136
+ }
137
+ return current;
138
+ };
139
+ // Restore thin bridges removed by erosion: if a removed pixel links two
140
+ // opposite neighbors in the source mask, bring it back.
141
+ const restoreBridgePixels = (source, eroded) => {
142
+ const restored = eroded.slice();
143
+ for (let y = 1; y < height - 1; y++) {
144
+ const row = y * width;
145
+ for (let x = 1; x < width - 1; x++) {
146
+ const idx = row + x;
147
+ if (!source[idx] || restored[idx])
148
+ continue;
149
+ const up = source[idx - width] === 1;
150
+ const down = source[idx + width] === 1;
151
+ const left = source[idx - 1] === 1;
152
+ const right = source[idx + 1] === 1;
153
+ const upLeft = source[idx - width - 1] === 1;
154
+ const upRight = source[idx - width + 1] === 1;
155
+ const downLeft = source[idx + width - 1] === 1;
156
+ const downRight = source[idx + width + 1] === 1;
157
+ const keepsBridge = (left && right) ||
158
+ (up && down) ||
159
+ (upLeft && downRight) ||
160
+ (upRight && downLeft);
161
+ if (keepsBridge) {
162
+ restored[idx] = 1;
163
+ }
164
+ }
165
+ }
166
+ return restored;
167
+ };
168
+ const erodePreservingBridges = (m, radiusPx) => {
169
+ const eroded = erodeDiamond(m, radiusPx);
170
+ return restoreBridgePixels(m, eroded);
118
171
  };
119
172
  switch (op) {
120
173
  case "dilate":
121
- return dilate(mask, radius);
174
+ return dilateDisk(mask, r);
122
175
  case "erode":
123
- return erode(mask, radius);
124
- case "closing":
125
- return erode(dilate(mask, radius), radius);
176
+ return erodePreservingBridges(mask, r);
177
+ case "closing": {
178
+ const erodeRadius = Math.max(1, Math.floor(r * 0.65));
179
+ return erodePreservingBridges(dilateDisk(mask, r), erodeRadius);
180
+ }
126
181
  case "opening":
127
- return dilate(erode(mask, radius), radius);
182
+ return dilateDisk(erodePreservingBridges(mask, r), r);
128
183
  default:
129
184
  return mask;
130
185
  }