@pooder/kit 6.0.1 → 6.1.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 (91) hide show
  1. package/.test-dist/src/extensions/background/BackgroundTool.js +524 -0
  2. package/.test-dist/src/extensions/background/index.js +17 -0
  3. package/.test-dist/src/extensions/dieline/DielineTool.js +748 -0
  4. package/.test-dist/src/extensions/dieline/commands.js +127 -0
  5. package/.test-dist/src/extensions/dieline/config.js +107 -0
  6. package/.test-dist/src/extensions/dieline/index.js +21 -0
  7. package/.test-dist/src/extensions/dieline/model.js +2 -0
  8. package/.test-dist/src/extensions/dieline/renderer.js +2 -0
  9. package/.test-dist/src/extensions/feature/FeatureTool.js +914 -0
  10. package/.test-dist/src/extensions/feature/index.js +17 -0
  11. package/.test-dist/src/extensions/film/FilmTool.js +207 -0
  12. package/.test-dist/src/extensions/film/index.js +17 -0
  13. package/.test-dist/src/extensions/image/ImageTool.js +1499 -0
  14. package/.test-dist/src/extensions/image/commands.js +162 -0
  15. package/.test-dist/src/extensions/image/config.js +129 -0
  16. package/.test-dist/src/extensions/image/index.js +21 -0
  17. package/.test-dist/src/extensions/image/model.js +2 -0
  18. package/.test-dist/src/extensions/image/renderer.js +5 -0
  19. package/.test-dist/src/extensions/mirror/MirrorTool.js +104 -0
  20. package/.test-dist/src/extensions/mirror/index.js +17 -0
  21. package/.test-dist/src/extensions/ruler/RulerTool.js +442 -0
  22. package/.test-dist/src/extensions/ruler/index.js +17 -0
  23. package/.test-dist/src/extensions/sceneLayout.js +2 -93
  24. package/.test-dist/src/extensions/sceneLayoutModel.js +15 -200
  25. package/.test-dist/src/extensions/size/SizeTool.js +332 -0
  26. package/.test-dist/src/extensions/size/index.js +17 -0
  27. package/.test-dist/src/extensions/white-ink/WhiteInkTool.js +1003 -0
  28. package/.test-dist/src/extensions/white-ink/commands.js +148 -0
  29. package/.test-dist/src/extensions/white-ink/config.js +31 -0
  30. package/.test-dist/src/extensions/white-ink/index.js +21 -0
  31. package/.test-dist/src/extensions/white-ink/model.js +2 -0
  32. package/.test-dist/src/extensions/white-ink/renderer.js +5 -0
  33. package/.test-dist/src/services/SceneLayoutService.js +96 -0
  34. package/.test-dist/src/services/index.js +1 -0
  35. package/.test-dist/src/shared/constants/layers.js +25 -0
  36. package/.test-dist/src/shared/imaging/sourceSizeCache.js +82 -0
  37. package/.test-dist/src/shared/index.js +22 -0
  38. package/.test-dist/src/shared/runtime/sessionState.js +74 -0
  39. package/.test-dist/src/shared/runtime/subscriptions.js +30 -0
  40. package/.test-dist/src/shared/scene/frame.js +34 -0
  41. package/.test-dist/src/shared/scene/sceneLayoutModel.js +202 -0
  42. package/.test-dist/tests/run.js +116 -0
  43. package/CHANGELOG.md +6 -0
  44. package/dist/index.d.mts +390 -367
  45. package/dist/index.d.ts +390 -367
  46. package/dist/index.js +5138 -4927
  47. package/dist/index.mjs +1149 -1977
  48. package/dist/tracer-PO7CRBYY.mjs +1016 -0
  49. package/package.json +1 -1
  50. package/src/extensions/{background.ts → background/BackgroundTool.ts} +33 -50
  51. package/src/extensions/background/index.ts +1 -0
  52. package/src/extensions/{dieline.ts → dieline/DielineTool.ts} +14 -218
  53. package/src/extensions/dieline/commands.ts +109 -0
  54. package/src/extensions/dieline/config.ts +106 -0
  55. package/src/extensions/dieline/index.ts +5 -0
  56. package/src/extensions/dieline/model.ts +1 -0
  57. package/src/extensions/dieline/renderer.ts +1 -0
  58. package/src/extensions/{feature.ts → feature/FeatureTool.ts} +27 -21
  59. package/src/extensions/feature/index.ts +1 -0
  60. package/src/extensions/{film.ts → film/FilmTool.ts} +36 -48
  61. package/src/extensions/film/index.ts +1 -0
  62. package/src/extensions/{image.ts → image/ImageTool.ts} +123 -402
  63. package/src/extensions/image/commands.ts +176 -0
  64. package/src/extensions/image/config.ts +128 -0
  65. package/src/extensions/image/index.ts +5 -0
  66. package/src/extensions/image/model.ts +1 -0
  67. package/src/extensions/image/renderer.ts +1 -0
  68. package/src/extensions/{mirror.ts → mirror/MirrorTool.ts} +1 -1
  69. package/src/extensions/mirror/index.ts +1 -0
  70. package/src/extensions/{ruler.ts → ruler/RulerTool.ts} +4 -5
  71. package/src/extensions/ruler/index.ts +1 -0
  72. package/src/extensions/sceneLayout.ts +1 -140
  73. package/src/extensions/sceneLayoutModel.ts +1 -364
  74. package/src/extensions/{size.ts → size/SizeTool.ts} +7 -6
  75. package/src/extensions/size/index.ts +1 -0
  76. package/src/extensions/{white-ink.ts → white-ink/WhiteInkTool.ts} +130 -317
  77. package/src/extensions/white-ink/commands.ts +157 -0
  78. package/src/extensions/white-ink/config.ts +30 -0
  79. package/src/extensions/white-ink/index.ts +5 -0
  80. package/src/extensions/white-ink/model.ts +1 -0
  81. package/src/extensions/white-ink/renderer.ts +1 -0
  82. package/src/services/SceneLayoutService.ts +139 -0
  83. package/src/services/index.ts +1 -0
  84. package/src/shared/constants/layers.ts +23 -0
  85. package/src/shared/imaging/sourceSizeCache.ts +103 -0
  86. package/src/shared/index.ts +6 -0
  87. package/src/shared/runtime/sessionState.ts +105 -0
  88. package/src/shared/runtime/subscriptions.ts +45 -0
  89. package/src/shared/scene/frame.ts +46 -0
  90. package/src/shared/scene/sceneLayoutModel.ts +367 -0
  91. package/tests/run.ts +146 -0
@@ -1,202 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizeMmValue = sanitizeMmValue;
4
- exports.normalizeUnit = normalizeUnit;
5
- exports.normalizeConstraintMode = normalizeConstraintMode;
6
- exports.normalizeCutMode = normalizeCutMode;
7
- exports.toMm = toMm;
8
- exports.fromMm = fromMm;
9
- exports.resolvePaddingPx = resolvePaddingPx;
10
- exports.readSizeState = readSizeState;
11
- exports.computeSceneLayout = computeSceneLayout;
12
- exports.buildSceneGeometry = buildSceneGeometry;
13
- const coordinate_1 = require("../coordinate");
14
- const units_1 = require("../units");
15
- const dielineShape_1 = require("./dielineShape");
16
- const DEFAULT_SIZE_STATE = {
17
- unit: "mm",
18
- actualWidthMm: 500,
19
- actualHeightMm: 500,
20
- constraintMode: "free",
21
- aspectRatio: 1,
22
- cutMode: "trim",
23
- cutMarginMm: 0,
24
- viewPadding: 140,
25
- minMm: 10,
26
- maxMm: 2000,
27
- stepMm: 0.1,
28
- };
29
- function clamp(value, min, max) {
30
- return Math.max(min, Math.min(max, value));
31
- }
32
- function roundToStep(value, step) {
33
- if (!Number.isFinite(step) || step <= 0)
34
- return value;
35
- return Math.round(value / step) * step;
36
- }
37
- function sanitizeMmValue(valueMm, limits) {
38
- if (!Number.isFinite(valueMm))
39
- return limits.minMm;
40
- const rounded = roundToStep(valueMm, limits.stepMm);
41
- return clamp(rounded, limits.minMm, limits.maxMm);
42
- }
43
- function normalizeUnit(value) {
44
- if (value === "cm" || value === "in")
45
- return value;
46
- return "mm";
47
- }
48
- function normalizeConstraintMode(value) {
49
- if (value === "lockAspect" || value === "equal")
50
- return value;
51
- return "free";
52
- }
53
- function normalizeCutMode(value) {
54
- if (value === "outset" || value === "inset")
55
- return value;
56
- return "trim";
57
- }
58
- function toMm(value, fromUnit) {
59
- return coordinate_1.Coordinate.convertUnit(value, fromUnit, "mm");
60
- }
61
- function fromMm(valueMm, toUnit) {
62
- return coordinate_1.Coordinate.convertUnit(valueMm, "mm", toUnit);
63
- }
64
- function resolvePaddingPx(raw, containerWidth, containerHeight) {
65
- if (typeof raw === "number")
66
- return Math.max(0, raw);
67
- if (typeof raw === "string") {
68
- if (raw.endsWith("%")) {
69
- const percent = parseFloat(raw) / 100;
70
- if (!Number.isFinite(percent))
71
- return 0;
72
- return Math.max(0, Math.min(containerWidth, containerHeight) * percent);
73
- }
74
- const fixed = parseFloat(raw);
75
- return Number.isFinite(fixed) ? Math.max(0, fixed) : 0;
76
- }
77
- return 0;
78
- }
79
- function readSizeState(configService) {
80
- const unit = normalizeUnit(configService.get("size.unit", DEFAULT_SIZE_STATE.unit));
81
- const minMm = Math.max(0.1, Number(configService.get("size.minMm", DEFAULT_SIZE_STATE.minMm)));
82
- const maxMm = Math.max(minMm, Number(configService.get("size.maxMm", DEFAULT_SIZE_STATE.maxMm)));
83
- const stepMm = Math.max(0.001, Number(configService.get("size.stepMm", DEFAULT_SIZE_STATE.stepMm)));
84
- const actualWidthMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualWidthMm", DEFAULT_SIZE_STATE.actualWidthMm), "mm"), { minMm, maxMm, stepMm });
85
- const actualHeightMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualHeightMm", DEFAULT_SIZE_STATE.actualHeightMm), "mm"), { minMm, maxMm, stepMm });
86
- const aspectRaw = Number(configService.get("size.aspectRatio", DEFAULT_SIZE_STATE.aspectRatio));
87
- const aspectRatio = Number.isFinite(aspectRaw) && aspectRaw > 0
88
- ? aspectRaw
89
- : actualWidthMm / Math.max(0.001, actualHeightMm);
90
- const cutMarginMm = Math.max(0, (0, units_1.parseLengthToMm)(configService.get("size.cutMarginMm", DEFAULT_SIZE_STATE.cutMarginMm), "mm"));
91
- const viewPadding = configService.get("size.viewPadding", DEFAULT_SIZE_STATE.viewPadding);
92
- return {
93
- unit,
94
- actualWidthMm,
95
- actualHeightMm,
96
- constraintMode: normalizeConstraintMode(configService.get("size.constraintMode", DEFAULT_SIZE_STATE.constraintMode)),
97
- aspectRatio,
98
- cutMode: normalizeCutMode(configService.get("size.cutMode", DEFAULT_SIZE_STATE.cutMode)),
99
- cutMarginMm,
100
- viewPadding,
101
- minMm,
102
- maxMm,
103
- stepMm,
104
- };
105
- }
106
- function rectByCenter(centerX, centerY, width, height) {
107
- return {
108
- left: centerX - width / 2,
109
- top: centerY - height / 2,
110
- width,
111
- height,
112
- centerX,
113
- centerY,
114
- };
115
- }
116
- function getCutSizeMm(size) {
117
- if (size.cutMode === "trim") {
118
- return { widthMm: size.actualWidthMm, heightMm: size.actualHeightMm };
119
- }
120
- const delta = size.cutMarginMm * 2;
121
- if (size.cutMode === "outset") {
122
- return {
123
- widthMm: size.actualWidthMm + delta,
124
- heightMm: size.actualHeightMm + delta,
125
- };
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]; } };
126
7
  }
127
- return {
128
- widthMm: Math.max(size.minMm, size.actualWidthMm - delta),
129
- heightMm: Math.max(size.minMm, size.actualHeightMm - delta),
130
- };
131
- }
132
- function computeSceneLayout(canvasService, size) {
133
- const canvasWidth = canvasService.canvas.width || 0;
134
- const canvasHeight = canvasService.canvas.height || 0;
135
- if (canvasWidth <= 0 || canvasHeight <= 0)
136
- return null;
137
- const { widthMm: cutWidthMm, heightMm: cutHeightMm } = getCutSizeMm(size);
138
- const viewWidthMm = Math.max(size.actualWidthMm, cutWidthMm);
139
- const viewHeightMm = Math.max(size.actualHeightMm, cutHeightMm);
140
- if (!Number.isFinite(viewWidthMm) ||
141
- !Number.isFinite(viewHeightMm) ||
142
- viewWidthMm <= 0 ||
143
- viewHeightMm <= 0) {
144
- return null;
145
- }
146
- const paddingPx = resolvePaddingPx(size.viewPadding, canvasWidth, canvasHeight);
147
- canvasService.viewport.updateContainer(canvasWidth, canvasHeight);
148
- canvasService.viewport.setPadding(paddingPx);
149
- canvasService.viewport.updatePhysical(viewWidthMm, viewHeightMm);
150
- const layout = canvasService.viewport.layout;
151
- if (!Number.isFinite(layout.scale) ||
152
- !Number.isFinite(layout.offsetX) ||
153
- !Number.isFinite(layout.offsetY) ||
154
- layout.scale <= 0) {
155
- return null;
156
- }
157
- const centerX = layout.offsetX + layout.width / 2;
158
- const centerY = layout.offsetY + layout.height / 2;
159
- const trimWidthPx = size.actualWidthMm * layout.scale;
160
- const trimHeightPx = size.actualHeightMm * layout.scale;
161
- const cutWidthPx = cutWidthMm * layout.scale;
162
- const cutHeightPx = cutHeightMm * layout.scale;
163
- const trimRect = rectByCenter(centerX, centerY, trimWidthPx, trimHeightPx);
164
- const cutRect = rectByCenter(centerX, centerY, cutWidthPx, cutHeightPx);
165
- const bleedRect = rectByCenter(centerX, centerY, Math.max(trimWidthPx, cutWidthPx), Math.max(trimHeightPx, cutHeightPx));
166
- return {
167
- scale: layout.scale,
168
- canvasWidth,
169
- canvasHeight,
170
- trimRect,
171
- cutRect,
172
- bleedRect,
173
- trimWidthMm: size.actualWidthMm,
174
- trimHeightMm: size.actualHeightMm,
175
- cutWidthMm,
176
- cutHeightMm,
177
- cutMode: size.cutMode,
178
- cutMarginMm: size.cutMarginMm,
179
- };
180
- }
181
- function buildSceneGeometry(configService, layout) {
182
- const radiusMm = (0, units_1.parseLengthToMm)(configService.get("dieline.radius", 0), "mm");
183
- const offset = (layout.cutRect.width - layout.trimRect.width) / 2;
184
- const sourceWidth = Number(configService.get("dieline.customSourceWidthPx", 0));
185
- const sourceHeight = Number(configService.get("dieline.customSourceHeightPx", 0));
186
- const shapeStyle = (0, dielineShape_1.normalizeShapeStyle)(configService.get("dieline.shapeStyle", dielineShape_1.DEFAULT_DIELINE_SHAPE_STYLE));
187
- return {
188
- shape: (0, dielineShape_1.normalizeDielineShape)(configService.get("dieline.shape", dielineShape_1.DEFAULT_DIELINE_SHAPE)),
189
- shapeStyle,
190
- unit: "px",
191
- x: layout.trimRect.centerX,
192
- y: layout.trimRect.centerY,
193
- width: layout.trimRect.width,
194
- height: layout.trimRect.height,
195
- radius: radiusMm * layout.scale,
196
- offset,
197
- scale: layout.scale,
198
- pathData: configService.get("dieline.pathData"),
199
- customSourceWidthPx: Number.isFinite(sourceWidth) && sourceWidth > 0 ? sourceWidth : undefined,
200
- customSourceHeightPx: Number.isFinite(sourceHeight) && sourceHeight > 0 ? sourceHeight : undefined,
201
- };
202
- }
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
+ __exportStar(require("../shared/scene/sceneLayoutModel"), exports);
@@ -0,0 +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("../../shared/scene/sceneLayoutModel");
6
+ const layers_1 = require("../../shared/constants/layers");
7
+ class SizeTool {
8
+ constructor() {
9
+ this.id = "pooder.kit.size";
10
+ this.metadata = {
11
+ name: "SizeTool",
12
+ };
13
+ }
14
+ activate(context) {
15
+ this.context = context;
16
+ this.canvasService = context.services.get("CanvasService");
17
+ const configService = context.services.get("ConfigurationService");
18
+ if (!configService)
19
+ return;
20
+ this.ensureDefaults(configService);
21
+ this.emitStateChanged();
22
+ }
23
+ deactivate(_context) {
24
+ this.context = undefined;
25
+ this.canvasService = undefined;
26
+ }
27
+ contribute() {
28
+ return {
29
+ [core_1.ContributionPointIds.TOOLS]: [
30
+ {
31
+ id: this.id,
32
+ name: "Size",
33
+ interaction: "instant",
34
+ },
35
+ ],
36
+ [core_1.ContributionPointIds.CONFIGURATIONS]: [
37
+ {
38
+ id: "size.unit",
39
+ type: "select",
40
+ label: "Display Unit",
41
+ options: ["mm", "cm", "in"],
42
+ default: "mm",
43
+ },
44
+ {
45
+ id: "size.actualWidthMm",
46
+ type: "number",
47
+ label: "Actual Width (mm)",
48
+ min: 10,
49
+ max: 2000,
50
+ step: 0.1,
51
+ default: 500,
52
+ },
53
+ {
54
+ id: "size.actualHeightMm",
55
+ type: "number",
56
+ label: "Actual Height (mm)",
57
+ min: 10,
58
+ max: 2000,
59
+ step: 0.1,
60
+ default: 500,
61
+ },
62
+ {
63
+ id: "size.constraintMode",
64
+ type: "select",
65
+ label: "Constraint Mode",
66
+ options: ["free", "lockAspect", "equal"],
67
+ default: "free",
68
+ },
69
+ {
70
+ id: "size.aspectRatio",
71
+ type: "number",
72
+ label: "Aspect Ratio",
73
+ min: 0.01,
74
+ max: 100,
75
+ step: 0.01,
76
+ default: 1,
77
+ },
78
+ {
79
+ id: "size.cutMode",
80
+ type: "select",
81
+ label: "Cut Mode",
82
+ options: ["trim", "outset", "inset"],
83
+ default: "trim",
84
+ },
85
+ {
86
+ id: "size.cutMarginMm",
87
+ type: "number",
88
+ label: "Cut Margin (mm)",
89
+ min: 0,
90
+ max: 100,
91
+ step: 0.1,
92
+ default: 0,
93
+ },
94
+ {
95
+ id: "size.viewPadding",
96
+ type: "select",
97
+ label: "View Padding",
98
+ options: [0, 10, 20, 40, 60, 100, "2%", "5%", "10%", "15%", "20%"],
99
+ default: 140,
100
+ },
101
+ {
102
+ id: "size.minMm",
103
+ type: "number",
104
+ label: "Min Size (mm)",
105
+ min: 0.1,
106
+ max: 2000,
107
+ step: 0.1,
108
+ default: 10,
109
+ },
110
+ {
111
+ id: "size.maxMm",
112
+ type: "number",
113
+ label: "Max Size (mm)",
114
+ min: 1,
115
+ max: 10000,
116
+ step: 1,
117
+ default: 2000,
118
+ },
119
+ {
120
+ id: "size.stepMm",
121
+ type: "number",
122
+ label: "Size Step (mm)",
123
+ min: 0.001,
124
+ max: 100,
125
+ step: 0.001,
126
+ default: 0.1,
127
+ },
128
+ ],
129
+ [core_1.ContributionPointIds.COMMANDS]: [
130
+ {
131
+ command: "getSizeState",
132
+ title: "Get Size State",
133
+ handler: () => this.getStateForUI(),
134
+ },
135
+ {
136
+ command: "updateSizeDimensions",
137
+ title: "Update Size Dimensions",
138
+ handler: (input = {}) => this.updateDimensions(input),
139
+ },
140
+ {
141
+ command: "setSizeConstraintMode",
142
+ title: "Set Size Constraint Mode",
143
+ handler: (mode) => this.setConstraintMode(mode),
144
+ },
145
+ {
146
+ command: "setSizeDisplayUnit",
147
+ title: "Set Size Display Unit",
148
+ handler: (unit) => this.setUnit(unit),
149
+ },
150
+ {
151
+ command: "setSizeCut",
152
+ title: "Set Size Cut",
153
+ handler: (cutMode, cutMarginMm = 0) => this.setCut(cutMode, cutMarginMm),
154
+ },
155
+ {
156
+ command: "getSelectedImageSize",
157
+ title: "Get Selected Image Size",
158
+ handler: (id) => this.getSelectedImageSize(id),
159
+ },
160
+ ],
161
+ };
162
+ }
163
+ getConfigService() {
164
+ return this.context?.services.get("ConfigurationService");
165
+ }
166
+ ensureDefaults(configService) {
167
+ const state = (0, sceneLayoutModel_1.readSizeState)(configService);
168
+ configService.update("size.unit", state.unit);
169
+ configService.update("size.actualWidthMm", state.actualWidthMm);
170
+ configService.update("size.actualHeightMm", state.actualHeightMm);
171
+ configService.update("size.constraintMode", state.constraintMode);
172
+ configService.update("size.aspectRatio", state.actualWidthMm / Math.max(0.001, state.actualHeightMm));
173
+ configService.update("size.cutMode", state.cutMode);
174
+ configService.update("size.cutMarginMm", state.cutMarginMm);
175
+ configService.update("size.viewPadding", state.viewPadding);
176
+ configService.update("size.minMm", state.minMm);
177
+ configService.update("size.maxMm", state.maxMm);
178
+ configService.update("size.stepMm", state.stepMm);
179
+ }
180
+ emitStateChanged() {
181
+ const state = this.getStateForUI();
182
+ if (!state)
183
+ return;
184
+ this.context?.eventBus.emit("size:state:changed", state);
185
+ }
186
+ getStateForUI() {
187
+ const configService = this.getConfigService();
188
+ if (!configService)
189
+ return null;
190
+ const state = (0, sceneLayoutModel_1.readSizeState)(configService);
191
+ return {
192
+ ...state,
193
+ actualWidth: (0, sceneLayoutModel_1.fromMm)(state.actualWidthMm, state.unit),
194
+ actualHeight: (0, sceneLayoutModel_1.fromMm)(state.actualHeightMm, state.unit),
195
+ };
196
+ }
197
+ updateDimensions(input) {
198
+ const configService = this.getConfigService();
199
+ if (!configService)
200
+ return null;
201
+ const state = (0, sceneLayoutModel_1.readSizeState)(configService);
202
+ const inputUnit = (0, sceneLayoutModel_1.normalizeUnit)(input.unit ?? state.unit);
203
+ const changed = input.changed || "both";
204
+ const providedWidthMm = Number.isFinite(input.width)
205
+ ? (0, sceneLayoutModel_1.toMm)(Number(input.width), inputUnit)
206
+ : undefined;
207
+ const providedHeightMm = Number.isFinite(input.height)
208
+ ? (0, sceneLayoutModel_1.toMm)(Number(input.height), inputUnit)
209
+ : undefined;
210
+ const limits = {
211
+ minMm: state.minMm,
212
+ maxMm: state.maxMm,
213
+ stepMm: state.stepMm,
214
+ };
215
+ let nextWidthMm = providedWidthMm !== undefined ? providedWidthMm : state.actualWidthMm;
216
+ let nextHeightMm = providedHeightMm !== undefined ? providedHeightMm : state.actualHeightMm;
217
+ if (state.constraintMode === "equal") {
218
+ const anchor = changed === "height"
219
+ ? nextHeightMm
220
+ : changed === "width"
221
+ ? nextWidthMm
222
+ : (providedWidthMm ?? providedHeightMm ?? nextWidthMm);
223
+ nextWidthMm = anchor;
224
+ nextHeightMm = anchor;
225
+ }
226
+ else if (state.constraintMode === "lockAspect") {
227
+ const ratio = Math.max(0.0001, state.aspectRatio);
228
+ if (changed === "height") {
229
+ nextWidthMm = nextHeightMm * ratio;
230
+ }
231
+ else {
232
+ nextHeightMm = nextWidthMm / ratio;
233
+ }
234
+ }
235
+ nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm, limits);
236
+ nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm, limits);
237
+ if (state.constraintMode === "equal") {
238
+ const value = Math.max(nextWidthMm, nextHeightMm);
239
+ nextWidthMm = value;
240
+ nextHeightMm = value;
241
+ }
242
+ else if (state.constraintMode === "lockAspect") {
243
+ const ratio = Math.max(0.0001, state.aspectRatio);
244
+ if (changed === "height") {
245
+ nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm * ratio, limits);
246
+ }
247
+ else {
248
+ nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm / ratio, limits);
249
+ }
250
+ }
251
+ configService.update("size.actualWidthMm", nextWidthMm);
252
+ configService.update("size.actualHeightMm", nextHeightMm);
253
+ configService.update("size.unit", inputUnit);
254
+ this.emitStateChanged();
255
+ return this.getStateForUI();
256
+ }
257
+ setConstraintMode(modeRaw) {
258
+ const configService = this.getConfigService();
259
+ if (!configService)
260
+ return null;
261
+ const state = (0, sceneLayoutModel_1.readSizeState)(configService);
262
+ const mode = (0, sceneLayoutModel_1.normalizeConstraintMode)(modeRaw);
263
+ configService.update("size.constraintMode", mode);
264
+ if (mode === "lockAspect") {
265
+ const ratio = state.actualWidthMm / Math.max(0.001, state.actualHeightMm);
266
+ configService.update("size.aspectRatio", ratio);
267
+ }
268
+ if (mode === "equal") {
269
+ const value = (0, sceneLayoutModel_1.sanitizeMmValue)(Math.max(state.actualWidthMm, state.actualHeightMm), {
270
+ minMm: state.minMm,
271
+ maxMm: state.maxMm,
272
+ stepMm: state.stepMm,
273
+ });
274
+ configService.update("size.actualWidthMm", value);
275
+ configService.update("size.actualHeightMm", value);
276
+ configService.update("size.aspectRatio", 1);
277
+ }
278
+ this.emitStateChanged();
279
+ return this.getStateForUI();
280
+ }
281
+ setUnit(unitRaw) {
282
+ const configService = this.getConfigService();
283
+ if (!configService)
284
+ return null;
285
+ const unit = (0, sceneLayoutModel_1.normalizeUnit)(unitRaw);
286
+ configService.update("size.unit", unit);
287
+ this.emitStateChanged();
288
+ return this.getStateForUI();
289
+ }
290
+ setCut(cutModeRaw, cutMarginMm = 0) {
291
+ const configService = this.getConfigService();
292
+ if (!configService)
293
+ return null;
294
+ const cutMode = (0, sceneLayoutModel_1.normalizeCutMode)(cutModeRaw);
295
+ const margin = Math.max(0, Number(cutMarginMm) || 0);
296
+ configService.update("size.cutMode", cutMode);
297
+ configService.update("size.cutMarginMm", margin);
298
+ this.emitStateChanged();
299
+ return this.getStateForUI();
300
+ }
301
+ getSelectedImageSize(id) {
302
+ const configService = this.getConfigService();
303
+ if (!configService || !this.canvasService)
304
+ return null;
305
+ const sizeState = (0, sceneLayoutModel_1.readSizeState)(configService);
306
+ const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, sizeState);
307
+ if (!layout || layout.scale <= 0)
308
+ return null;
309
+ const all = this.canvasService.canvas.getObjects();
310
+ const active = this.canvasService.canvas.getActiveObject();
311
+ const activeId = active?.data?.layerId === layers_1.IMAGE_OBJECT_LAYER_ID ? active?.data?.id : null;
312
+ const targetId = id || activeId;
313
+ const target = all.find((obj) => obj?.data?.layerId === layers_1.IMAGE_OBJECT_LAYER_ID && obj?.data?.id === targetId) || all.find((obj) => obj?.data?.layerId === layers_1.IMAGE_OBJECT_LAYER_ID);
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;
@@ -0,0 +1,17 @@
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
+ __exportStar(require("./SizeTool"), exports);