@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
@@ -1,332 +1,332 @@
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;
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;