@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
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SceneVisibilityService = void 0;
4
- class SceneVisibilityService {
5
- constructor() {
6
- this.id = "pooder.kit.sceneVisibility";
7
- this.metadata = {
8
- name: "SceneVisibilityService",
9
- };
10
- this.activeToolId = null;
11
- this.onToolActivated = (e) => {
12
- this.activeToolId = e.id;
13
- this.apply();
14
- };
15
- this.onObjectAdded = () => {
16
- this.apply();
17
- };
18
- }
19
- activate(context) {
20
- this.canvasService = context.services.get("CanvasService");
21
- context.eventBus.on("tool:activated", this.onToolActivated);
22
- context.eventBus.on("object:added", this.onObjectAdded);
23
- }
24
- deactivate(context) {
25
- context.eventBus.off("tool:activated", this.onToolActivated);
26
- context.eventBus.off("object:added", this.onObjectAdded);
27
- this.activeToolId = null;
28
- this.canvasService = undefined;
29
- }
30
- apply() {
31
- if (!this.canvasService)
32
- return;
33
- const dielineLayer = this.canvasService.getLayer("dieline-overlay");
34
- if (dielineLayer) {
35
- const visible = this.activeToolId !== "pooder.kit.image" &&
36
- this.activeToolId !== "pooder.kit.white-ink";
37
- dielineLayer.set({ visible });
38
- }
39
- this.canvasService.requestRenderAll();
40
- }
41
- }
42
- exports.SceneVisibilityService = SceneVisibilityService;
@@ -1,332 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SizeTool = void 0;
4
- const core_1 = require("@pooder/core");
5
- const sceneLayoutModel_1 = require("./sceneLayoutModel");
6
- class SizeTool {
7
- constructor() {
8
- this.id = "pooder.kit.size";
9
- this.metadata = {
10
- name: "SizeTool",
11
- };
12
- }
13
- activate(context) {
14
- this.context = context;
15
- this.canvasService = context.services.get("CanvasService");
16
- const configService = context.services.get("ConfigurationService");
17
- if (!configService)
18
- return;
19
- this.ensureDefaults(configService);
20
- this.emitStateChanged();
21
- }
22
- deactivate(_context) {
23
- this.context = undefined;
24
- this.canvasService = undefined;
25
- }
26
- contribute() {
27
- return {
28
- [core_1.ContributionPointIds.TOOLS]: [
29
- {
30
- id: this.id,
31
- name: "Size",
32
- interaction: "instant",
33
- },
34
- ],
35
- [core_1.ContributionPointIds.CONFIGURATIONS]: [
36
- {
37
- id: "size.unit",
38
- type: "select",
39
- label: "Display Unit",
40
- options: ["mm", "cm", "in"],
41
- default: "mm",
42
- },
43
- {
44
- id: "size.actualWidthMm",
45
- type: "number",
46
- label: "Actual Width (mm)",
47
- min: 10,
48
- max: 2000,
49
- step: 0.1,
50
- default: 500,
51
- },
52
- {
53
- id: "size.actualHeightMm",
54
- type: "number",
55
- label: "Actual Height (mm)",
56
- min: 10,
57
- max: 2000,
58
- step: 0.1,
59
- default: 500,
60
- },
61
- {
62
- id: "size.constraintMode",
63
- type: "select",
64
- label: "Constraint Mode",
65
- options: ["free", "lockAspect", "equal"],
66
- default: "free",
67
- },
68
- {
69
- id: "size.aspectRatio",
70
- type: "number",
71
- label: "Aspect Ratio",
72
- min: 0.01,
73
- max: 100,
74
- step: 0.01,
75
- default: 1,
76
- },
77
- {
78
- id: "size.cutMode",
79
- type: "select",
80
- label: "Cut Mode",
81
- options: ["trim", "outset", "inset"],
82
- default: "trim",
83
- },
84
- {
85
- id: "size.cutMarginMm",
86
- type: "number",
87
- label: "Cut Margin (mm)",
88
- min: 0,
89
- max: 100,
90
- step: 0.1,
91
- default: 0,
92
- },
93
- {
94
- id: "size.viewPadding",
95
- type: "select",
96
- label: "View Padding",
97
- options: [0, 10, 20, 40, 60, 100, "2%", "5%", "10%", "15%", "20%"],
98
- default: 140,
99
- },
100
- {
101
- id: "size.minMm",
102
- type: "number",
103
- label: "Min Size (mm)",
104
- min: 0.1,
105
- max: 2000,
106
- step: 0.1,
107
- default: 10,
108
- },
109
- {
110
- id: "size.maxMm",
111
- type: "number",
112
- label: "Max Size (mm)",
113
- min: 1,
114
- max: 10000,
115
- step: 1,
116
- default: 2000,
117
- },
118
- {
119
- id: "size.stepMm",
120
- type: "number",
121
- label: "Size Step (mm)",
122
- min: 0.001,
123
- max: 100,
124
- step: 0.001,
125
- default: 0.1,
126
- },
127
- ],
128
- [core_1.ContributionPointIds.COMMANDS]: [
129
- {
130
- command: "getSizeState",
131
- title: "Get Size State",
132
- handler: () => this.getStateForUI(),
133
- },
134
- {
135
- command: "updateSizeDimensions",
136
- title: "Update Size Dimensions",
137
- handler: (input = {}) => this.updateDimensions(input),
138
- },
139
- {
140
- command: "setSizeConstraintMode",
141
- title: "Set Size Constraint Mode",
142
- handler: (mode) => this.setConstraintMode(mode),
143
- },
144
- {
145
- command: "setSizeDisplayUnit",
146
- title: "Set Size Display Unit",
147
- handler: (unit) => this.setUnit(unit),
148
- },
149
- {
150
- command: "setSizeCut",
151
- title: "Set Size Cut",
152
- handler: (cutMode, cutMarginMm = 0) => this.setCut(cutMode, cutMarginMm),
153
- },
154
- {
155
- command: "getSelectedImageSize",
156
- title: "Get Selected Image Size",
157
- handler: (id) => this.getSelectedImageSize(id),
158
- },
159
- ],
160
- };
161
- }
162
- getConfigService() {
163
- return this.context?.services.get("ConfigurationService");
164
- }
165
- ensureDefaults(configService) {
166
- const state = (0, sceneLayoutModel_1.readSizeState)(configService);
167
- configService.update("size.unit", state.unit);
168
- configService.update("size.actualWidthMm", state.actualWidthMm);
169
- configService.update("size.actualHeightMm", state.actualHeightMm);
170
- configService.update("size.constraintMode", state.constraintMode);
171
- configService.update("size.aspectRatio", state.actualWidthMm / Math.max(0.001, state.actualHeightMm));
172
- configService.update("size.cutMode", state.cutMode);
173
- configService.update("size.cutMarginMm", state.cutMarginMm);
174
- configService.update("size.viewPadding", state.viewPadding);
175
- configService.update("size.minMm", state.minMm);
176
- configService.update("size.maxMm", state.maxMm);
177
- configService.update("size.stepMm", state.stepMm);
178
- }
179
- emitStateChanged() {
180
- const state = this.getStateForUI();
181
- if (!state)
182
- return;
183
- this.context?.eventBus.emit("size:state:changed", state);
184
- }
185
- getStateForUI() {
186
- const configService = this.getConfigService();
187
- if (!configService)
188
- return null;
189
- const state = (0, sceneLayoutModel_1.readSizeState)(configService);
190
- return {
191
- ...state,
192
- actualWidth: (0, sceneLayoutModel_1.fromMm)(state.actualWidthMm, state.unit),
193
- actualHeight: (0, sceneLayoutModel_1.fromMm)(state.actualHeightMm, state.unit),
194
- };
195
- }
196
- updateDimensions(input) {
197
- const configService = this.getConfigService();
198
- if (!configService)
199
- return null;
200
- const state = (0, sceneLayoutModel_1.readSizeState)(configService);
201
- const inputUnit = (0, sceneLayoutModel_1.normalizeUnit)(input.unit ?? state.unit);
202
- const changed = input.changed || "both";
203
- const providedWidthMm = Number.isFinite(input.width)
204
- ? (0, sceneLayoutModel_1.toMm)(Number(input.width), inputUnit)
205
- : undefined;
206
- const providedHeightMm = Number.isFinite(input.height)
207
- ? (0, sceneLayoutModel_1.toMm)(Number(input.height), inputUnit)
208
- : undefined;
209
- const limits = {
210
- minMm: state.minMm,
211
- maxMm: state.maxMm,
212
- stepMm: state.stepMm,
213
- };
214
- let nextWidthMm = providedWidthMm !== undefined ? providedWidthMm : state.actualWidthMm;
215
- let nextHeightMm = providedHeightMm !== undefined ? providedHeightMm : state.actualHeightMm;
216
- if (state.constraintMode === "equal") {
217
- const anchor = changed === "height"
218
- ? nextHeightMm
219
- : changed === "width"
220
- ? nextWidthMm
221
- : providedWidthMm ?? providedHeightMm ?? nextWidthMm;
222
- nextWidthMm = anchor;
223
- nextHeightMm = anchor;
224
- }
225
- else if (state.constraintMode === "lockAspect") {
226
- const ratio = Math.max(0.0001, state.aspectRatio);
227
- if (changed === "height") {
228
- nextWidthMm = nextHeightMm * ratio;
229
- }
230
- else {
231
- nextHeightMm = nextWidthMm / ratio;
232
- }
233
- }
234
- nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm, limits);
235
- nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm, limits);
236
- if (state.constraintMode === "equal") {
237
- const value = Math.max(nextWidthMm, nextHeightMm);
238
- nextWidthMm = value;
239
- nextHeightMm = value;
240
- }
241
- else if (state.constraintMode === "lockAspect") {
242
- const ratio = Math.max(0.0001, state.aspectRatio);
243
- if (changed === "height") {
244
- nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm * ratio, limits);
245
- }
246
- else {
247
- nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm / ratio, limits);
248
- }
249
- }
250
- configService.update("size.actualWidthMm", nextWidthMm);
251
- configService.update("size.actualHeightMm", nextHeightMm);
252
- configService.update("size.unit", inputUnit);
253
- this.emitStateChanged();
254
- return this.getStateForUI();
255
- }
256
- setConstraintMode(modeRaw) {
257
- const configService = this.getConfigService();
258
- if (!configService)
259
- return null;
260
- const state = (0, sceneLayoutModel_1.readSizeState)(configService);
261
- const mode = (0, sceneLayoutModel_1.normalizeConstraintMode)(modeRaw);
262
- configService.update("size.constraintMode", mode);
263
- if (mode === "lockAspect") {
264
- const ratio = state.actualWidthMm / Math.max(0.001, state.actualHeightMm);
265
- configService.update("size.aspectRatio", ratio);
266
- }
267
- if (mode === "equal") {
268
- const value = (0, sceneLayoutModel_1.sanitizeMmValue)(Math.max(state.actualWidthMm, state.actualHeightMm), {
269
- minMm: state.minMm,
270
- maxMm: state.maxMm,
271
- stepMm: state.stepMm,
272
- });
273
- configService.update("size.actualWidthMm", value);
274
- configService.update("size.actualHeightMm", value);
275
- configService.update("size.aspectRatio", 1);
276
- }
277
- this.emitStateChanged();
278
- return this.getStateForUI();
279
- }
280
- setUnit(unitRaw) {
281
- const configService = this.getConfigService();
282
- if (!configService)
283
- return null;
284
- const unit = (0, sceneLayoutModel_1.normalizeUnit)(unitRaw);
285
- configService.update("size.unit", unit);
286
- this.emitStateChanged();
287
- return this.getStateForUI();
288
- }
289
- setCut(cutModeRaw, cutMarginMm = 0) {
290
- const configService = this.getConfigService();
291
- if (!configService)
292
- return null;
293
- const cutMode = (0, sceneLayoutModel_1.normalizeCutMode)(cutModeRaw);
294
- const margin = Math.max(0, Number(cutMarginMm) || 0);
295
- configService.update("size.cutMode", cutMode);
296
- configService.update("size.cutMarginMm", margin);
297
- this.emitStateChanged();
298
- return this.getStateForUI();
299
- }
300
- getSelectedImageSize(id) {
301
- const configService = this.getConfigService();
302
- if (!configService || !this.canvasService)
303
- return null;
304
- const sizeState = (0, sceneLayoutModel_1.readSizeState)(configService);
305
- const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, sizeState);
306
- if (!layout || layout.scale <= 0)
307
- return null;
308
- const all = this.canvasService.canvas.getObjects();
309
- const active = this.canvasService.canvas.getActiveObject();
310
- const activeId = active?.data?.layerId === "image.user" ? active?.data?.id : null;
311
- const targetId = id || activeId;
312
- const target = all.find((obj) => obj?.data?.layerId === "image.user" && obj?.data?.id === targetId) ||
313
- all.find((obj) => obj?.data?.layerId === "image.user");
314
- if (!target)
315
- return null;
316
- const objectWidthPx = Math.abs((target.width || 0) * (target.scaleX || 1));
317
- const objectHeightPx = Math.abs((target.height || 0) * (target.scaleY || 1));
318
- if (objectWidthPx <= 0 || objectHeightPx <= 0)
319
- return null;
320
- const widthMm = objectWidthPx / layout.scale;
321
- const heightMm = objectHeightPx / layout.scale;
322
- return {
323
- id: target?.data?.id || null,
324
- widthMm,
325
- heightMm,
326
- width: (0, sceneLayoutModel_1.fromMm)(widthMm, sizeState.unit),
327
- height: (0, sceneLayoutModel_1.fromMm)(heightMm, sizeState.unit),
328
- unit: sizeState.unit,
329
- };
330
- }
331
- }
332
- exports.SizeTool = SizeTool;