@pooder/kit 5.3.0 → 5.4.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 (73) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.d.mts +249 -36
  3. package/dist/index.d.ts +249 -36
  4. package/dist/index.js +2374 -1049
  5. package/dist/index.mjs +2375 -1050
  6. package/package.json +1 -1
  7. package/src/extensions/background.ts +178 -85
  8. package/src/extensions/dieline.ts +1149 -1030
  9. package/src/extensions/dielineShape.ts +109 -0
  10. package/src/extensions/feature.ts +482 -366
  11. package/src/extensions/film.ts +148 -76
  12. package/src/extensions/geometry.ts +210 -44
  13. package/src/extensions/image.ts +244 -114
  14. package/src/extensions/ruler.ts +471 -268
  15. package/src/extensions/sceneLayoutModel.ts +28 -6
  16. package/src/extensions/sceneVisibility.ts +3 -10
  17. package/src/extensions/tracer.ts +1019 -980
  18. package/src/extensions/white-ink.ts +284 -231
  19. package/src/services/CanvasService.ts +543 -11
  20. package/src/services/renderSpec.ts +37 -2
  21. package/.test-dist/src/CanvasService.js +0 -249
  22. package/.test-dist/src/ViewportSystem.js +0 -75
  23. package/.test-dist/src/background.js +0 -203
  24. package/.test-dist/src/bridgeSelection.js +0 -20
  25. package/.test-dist/src/constraints.js +0 -237
  26. package/.test-dist/src/coordinate.js +0 -74
  27. package/.test-dist/src/dieline.js +0 -818
  28. package/.test-dist/src/edgeScale.js +0 -12
  29. package/.test-dist/src/extensions/background.js +0 -203
  30. package/.test-dist/src/extensions/bridgeSelection.js +0 -20
  31. package/.test-dist/src/extensions/constraints.js +0 -237
  32. package/.test-dist/src/extensions/dieline.js +0 -828
  33. package/.test-dist/src/extensions/edgeScale.js +0 -12
  34. package/.test-dist/src/extensions/feature.js +0 -825
  35. package/.test-dist/src/extensions/featureComplete.js +0 -32
  36. package/.test-dist/src/extensions/film.js +0 -167
  37. package/.test-dist/src/extensions/geometry.js +0 -545
  38. package/.test-dist/src/extensions/image.js +0 -1529
  39. package/.test-dist/src/extensions/index.js +0 -30
  40. package/.test-dist/src/extensions/maskOps.js +0 -279
  41. package/.test-dist/src/extensions/mirror.js +0 -104
  42. package/.test-dist/src/extensions/ruler.js +0 -345
  43. package/.test-dist/src/extensions/sceneLayout.js +0 -96
  44. package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
  45. package/.test-dist/src/extensions/sceneVisibility.js +0 -62
  46. package/.test-dist/src/extensions/size.js +0 -331
  47. package/.test-dist/src/extensions/tracer.js +0 -538
  48. package/.test-dist/src/extensions/white-ink.js +0 -1190
  49. package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
  50. package/.test-dist/src/feature.js +0 -826
  51. package/.test-dist/src/featureComplete.js +0 -32
  52. package/.test-dist/src/film.js +0 -167
  53. package/.test-dist/src/geometry.js +0 -506
  54. package/.test-dist/src/image.js +0 -1250
  55. package/.test-dist/src/index.js +0 -18
  56. package/.test-dist/src/maskOps.js +0 -270
  57. package/.test-dist/src/mirror.js +0 -104
  58. package/.test-dist/src/renderSpec.js +0 -2
  59. package/.test-dist/src/ruler.js +0 -343
  60. package/.test-dist/src/sceneLayout.js +0 -99
  61. package/.test-dist/src/sceneLayoutModel.js +0 -196
  62. package/.test-dist/src/sceneView.js +0 -40
  63. package/.test-dist/src/sceneVisibility.js +0 -42
  64. package/.test-dist/src/services/CanvasService.js +0 -249
  65. package/.test-dist/src/services/ViewportSystem.js +0 -76
  66. package/.test-dist/src/services/index.js +0 -24
  67. package/.test-dist/src/services/renderSpec.js +0 -2
  68. package/.test-dist/src/size.js +0 -332
  69. package/.test-dist/src/tracer.js +0 -544
  70. package/.test-dist/src/units.js +0 -30
  71. package/.test-dist/src/white-ink.js +0 -829
  72. package/.test-dist/src/wrappedOffsets.js +0 -33
  73. package/.test-dist/tests/run.js +0 -94
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SceneVisibilityService = exports.SceneLayoutService = void 0;
18
- __exportStar(require("./background"), exports);
19
- __exportStar(require("./image"), exports);
20
- __exportStar(require("./size"), exports);
21
- __exportStar(require("./dieline"), exports);
22
- __exportStar(require("./feature"), exports);
23
- __exportStar(require("./film"), exports);
24
- __exportStar(require("./mirror"), exports);
25
- __exportStar(require("./ruler"), exports);
26
- __exportStar(require("./white-ink"), exports);
27
- var sceneLayout_1 = require("./sceneLayout");
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; } });
@@ -1,279 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMask = createMask;
4
- exports.inferMaskMode = inferMaskMode;
5
- exports.analyzeAlpha = analyzeAlpha;
6
- exports.circularMorphology = circularMorphology;
7
- exports.fillHoles = fillHoles;
8
- exports.countForeground = countForeground;
9
- exports.isMaskConnected8 = isMaskConnected8;
10
- exports.findMinimalConnectRadius = findMinimalConnectRadius;
11
- exports.polygonSignedArea = polygonSignedArea;
12
- function createMask(imageData, options) {
13
- const { width, height, data } = imageData;
14
- const { threshold, padding, paddedWidth, paddedHeight, maskMode = "auto", whiteThreshold = 240, alphaOpaqueCutoff = 250, } = options;
15
- const resolvedMode = maskMode === "auto" ? inferMaskMode(imageData, alphaOpaqueCutoff) : maskMode;
16
- const mask = new Uint8Array(paddedWidth * paddedHeight);
17
- for (let y = 0; y < height; y++) {
18
- for (let x = 0; x < width; x++) {
19
- const srcIdx = (y * width + x) * 4;
20
- const r = data[srcIdx];
21
- const g = data[srcIdx + 1];
22
- const b = data[srcIdx + 2];
23
- const a = data[srcIdx + 3];
24
- const destIdx = (y + padding) * paddedWidth + (x + padding);
25
- if (resolvedMode === "alpha") {
26
- if (a > threshold)
27
- mask[destIdx] = 1;
28
- }
29
- else {
30
- if (a > threshold &&
31
- !(r > whiteThreshold && g > whiteThreshold && b > whiteThreshold)) {
32
- mask[destIdx] = 1;
33
- }
34
- }
35
- }
36
- }
37
- return mask;
38
- }
39
- function inferMaskMode(imageData, alphaOpaqueCutoff) {
40
- const analysis = analyzeAlpha(imageData, alphaOpaqueCutoff);
41
- if (analysis.minAlpha === 255)
42
- return "whitebg";
43
- if (analysis.veryTransparentRatio >= 0.0005)
44
- return "alpha";
45
- if (analysis.belowOpaqueRatio >= 0.01)
46
- return "alpha";
47
- return "whitebg";
48
- }
49
- function analyzeAlpha(imageData, alphaOpaqueCutoff) {
50
- const { data } = imageData;
51
- const total = data.length / 4;
52
- let belowOpaque = 0;
53
- let veryTransparent = 0;
54
- let minAlpha = 255;
55
- for (let i = 3; i < data.length; i += 4) {
56
- const a = data[i];
57
- if (a < minAlpha)
58
- minAlpha = a;
59
- if (a < alphaOpaqueCutoff)
60
- belowOpaque++;
61
- if (a < 32)
62
- veryTransparent++;
63
- }
64
- return {
65
- total,
66
- minAlpha,
67
- belowOpaqueRatio: belowOpaque / total,
68
- veryTransparentRatio: veryTransparent / total,
69
- };
70
- }
71
- function circularMorphology(mask, width, height, radius, op) {
72
- const dilate = (m, r) => {
73
- const horizontalDist = new Int32Array(width * height);
74
- for (let y = 0; y < height; y++) {
75
- let lastSolid = -r * 2;
76
- for (let x = 0; x < width; x++) {
77
- if (m[y * width + x])
78
- lastSolid = x;
79
- horizontalDist[y * width + x] = x - lastSolid;
80
- }
81
- lastSolid = width + r * 2;
82
- for (let x = width - 1; x >= 0; x--) {
83
- if (m[y * width + x])
84
- lastSolid = x;
85
- horizontalDist[y * width + x] = Math.min(horizontalDist[y * width + x], lastSolid - x);
86
- }
87
- }
88
- const result = new Uint8Array(width * height);
89
- const r2 = r * r;
90
- for (let x = 0; x < width; x++) {
91
- for (let y = 0; y < height; y++) {
92
- let found = false;
93
- const minY = Math.max(0, y - r);
94
- const maxY = Math.min(height - 1, y + r);
95
- for (let dy = minY; dy <= maxY; dy++) {
96
- const dY = dy - y;
97
- const hDist = horizontalDist[dy * width + x];
98
- if (hDist * hDist + dY * dY <= r2) {
99
- found = true;
100
- break;
101
- }
102
- }
103
- if (found)
104
- result[y * width + x] = 1;
105
- }
106
- }
107
- return result;
108
- };
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;
118
- };
119
- switch (op) {
120
- case "dilate":
121
- return dilate(mask, radius);
122
- case "erode":
123
- return erode(mask, radius);
124
- case "closing":
125
- return erode(dilate(mask, radius), radius);
126
- case "opening":
127
- return dilate(erode(mask, radius), radius);
128
- default:
129
- return mask;
130
- }
131
- }
132
- function fillHoles(mask, width, height) {
133
- const background = new Uint8Array(width * height);
134
- const queue = [];
135
- for (let x = 0; x < width; x++) {
136
- if (mask[x] === 0) {
137
- background[x] = 1;
138
- queue.push(x);
139
- }
140
- const lastRowIdx = (height - 1) * width + x;
141
- if (mask[lastRowIdx] === 0) {
142
- background[lastRowIdx] = 1;
143
- queue.push(lastRowIdx);
144
- }
145
- }
146
- for (let y = 1; y < height - 1; y++) {
147
- const leftIdx = y * width;
148
- const rightIdx = y * width + (width - 1);
149
- if (mask[leftIdx] === 0) {
150
- background[leftIdx] = 1;
151
- queue.push(leftIdx);
152
- }
153
- if (mask[rightIdx] === 0) {
154
- background[rightIdx] = 1;
155
- queue.push(rightIdx);
156
- }
157
- }
158
- let head = 0;
159
- while (head < queue.length) {
160
- const idx = queue[head++];
161
- const x = idx % width;
162
- const y = (idx - x) / width;
163
- const up = y > 0 ? idx - width : -1;
164
- const down = y < height - 1 ? idx + width : -1;
165
- const left = x > 0 ? idx - 1 : -1;
166
- const right = x < width - 1 ? idx + 1 : -1;
167
- if (up >= 0 && mask[up] === 0 && background[up] === 0) {
168
- background[up] = 1;
169
- queue.push(up);
170
- }
171
- if (down >= 0 && mask[down] === 0 && background[down] === 0) {
172
- background[down] = 1;
173
- queue.push(down);
174
- }
175
- if (left >= 0 && mask[left] === 0 && background[left] === 0) {
176
- background[left] = 1;
177
- queue.push(left);
178
- }
179
- if (right >= 0 && mask[right] === 0 && background[right] === 0) {
180
- background[right] = 1;
181
- queue.push(right);
182
- }
183
- }
184
- const filledMask = new Uint8Array(width * height);
185
- for (let i = 0; i < width * height; i++) {
186
- filledMask[i] = background[i] === 0 ? 1 : 0;
187
- }
188
- return filledMask;
189
- }
190
- function countForeground(mask) {
191
- let c = 0;
192
- for (let i = 0; i < mask.length; i++)
193
- c += mask[i] ? 1 : 0;
194
- return c;
195
- }
196
- function isMaskConnected8(mask, width, height) {
197
- const total = countForeground(mask);
198
- if (total === 0)
199
- return true;
200
- let start = -1;
201
- for (let i = 0; i < mask.length; i++) {
202
- if (mask[i]) {
203
- start = i;
204
- break;
205
- }
206
- }
207
- if (start === -1)
208
- return true;
209
- const visited = new Uint8Array(mask.length);
210
- const queue = [start];
211
- visited[start] = 1;
212
- let seen = 1;
213
- let head = 0;
214
- while (head < queue.length) {
215
- const idx = queue[head++];
216
- const x = idx % width;
217
- const y = (idx - x) / width;
218
- for (let dy = -1; dy <= 1; dy++) {
219
- const ny = y + dy;
220
- if (ny < 0 || ny >= height)
221
- continue;
222
- for (let dx = -1; dx <= 1; dx++) {
223
- if (dx === 0 && dy === 0)
224
- continue;
225
- const nx = x + dx;
226
- if (nx < 0 || nx >= width)
227
- continue;
228
- const nidx = ny * width + nx;
229
- if (mask[nidx] && !visited[nidx]) {
230
- visited[nidx] = 1;
231
- queue.push(nidx);
232
- seen++;
233
- }
234
- }
235
- }
236
- }
237
- return seen === total;
238
- }
239
- function findMinimalConnectRadius(mask, width, height, maxRadius) {
240
- if (maxRadius <= 0)
241
- return 0;
242
- if (isMaskConnected8(mask, width, height))
243
- return 0;
244
- let low = 0;
245
- let high = 1;
246
- while (high <= maxRadius) {
247
- const closed = circularMorphology(mask, width, height, high, "closing");
248
- if (isMaskConnected8(closed, width, height))
249
- break;
250
- high *= 2;
251
- }
252
- if (high > maxRadius)
253
- high = maxRadius;
254
- if (!isMaskConnected8(circularMorphology(mask, width, height, high, "closing"), width, height)) {
255
- return high;
256
- }
257
- while (low + 1 < high) {
258
- const mid = Math.floor((low + high) / 2);
259
- const closed = circularMorphology(mask, width, height, mid, "closing");
260
- if (isMaskConnected8(closed, width, height)) {
261
- high = mid;
262
- }
263
- else {
264
- low = mid;
265
- }
266
- }
267
- return high;
268
- }
269
- function polygonSignedArea(points) {
270
- if (points.length < 3)
271
- return 0;
272
- let sum = 0;
273
- for (let i = 0; i < points.length; i++) {
274
- const a = points[i];
275
- const b = points[(i + 1) % points.length];
276
- sum += a.x * b.y - b.x * a.y;
277
- }
278
- return sum / 2;
279
- }
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MirrorTool = void 0;
4
- const core_1 = require("@pooder/core");
5
- class MirrorTool {
6
- constructor(options) {
7
- this.id = "pooder.kit.mirror";
8
- this.metadata = {
9
- name: "MirrorTool",
10
- };
11
- this.enabled = false;
12
- if (options) {
13
- Object.assign(this, options);
14
- }
15
- }
16
- toJSON() {
17
- return {
18
- enabled: this.enabled,
19
- };
20
- }
21
- loadFromJSON(json) {
22
- this.enabled = json.enabled;
23
- }
24
- activate(context) {
25
- this.canvasService = context.services.get("CanvasService");
26
- if (!this.canvasService) {
27
- console.warn("CanvasService not found for MirrorTool");
28
- return;
29
- }
30
- const configService = context.services.get("ConfigurationService");
31
- if (configService) {
32
- // Load initial config
33
- this.enabled = configService.get("mirror.enabled", this.enabled);
34
- // Listen for changes
35
- configService.onAnyChange((e) => {
36
- if (e.key === "mirror.enabled") {
37
- this.applyMirror(e.value);
38
- }
39
- });
40
- }
41
- // Initialize with current state (if enabled was persisted)
42
- if (this.enabled) {
43
- this.applyMirror(true);
44
- }
45
- }
46
- deactivate(context) {
47
- this.applyMirror(false);
48
- this.canvasService = undefined;
49
- }
50
- contribute() {
51
- return {
52
- [core_1.ContributionPointIds.CONFIGURATIONS]: [
53
- {
54
- id: "mirror.enabled",
55
- type: "boolean",
56
- label: "Enable Mirror",
57
- default: false,
58
- },
59
- ],
60
- [core_1.ContributionPointIds.COMMANDS]: [
61
- {
62
- command: "setMirror",
63
- title: "Set Mirror",
64
- handler: (enabled) => {
65
- this.applyMirror(enabled);
66
- return true;
67
- },
68
- },
69
- ],
70
- };
71
- }
72
- applyMirror(enabled) {
73
- if (!this.canvasService)
74
- return;
75
- const canvas = this.canvasService.canvas;
76
- if (!canvas)
77
- return;
78
- const width = canvas.width || 800;
79
- // Fabric.js v6+ uses viewportTransform property
80
- let vpt = canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
81
- // Create a copy to avoid mutating the reference directly before setting
82
- vpt = [...vpt];
83
- // If we are enabling and currently not flipped (scaleX > 0)
84
- // Or disabling and currently flipped (scaleX < 0)
85
- const isFlipped = vpt[0] < 0;
86
- if (enabled && !isFlipped) {
87
- // Flip scale X
88
- vpt[0] = -vpt[0]; // Flip scale
89
- vpt[4] = width - vpt[4]; // Adjust pan X
90
- canvas.setViewportTransform(vpt);
91
- canvas.requestRenderAll();
92
- this.enabled = true;
93
- }
94
- else if (!enabled && isFlipped) {
95
- // Restore
96
- vpt[0] = -vpt[0]; // Unflip scale
97
- vpt[4] = width - vpt[4]; // Restore pan X
98
- canvas.setViewportTransform(vpt);
99
- canvas.requestRenderAll();
100
- this.enabled = false;
101
- }
102
- }
103
- }
104
- exports.MirrorTool = MirrorTool;