@pooder/kit 5.1.0 → 5.3.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 (86) 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/extensions/background.js +203 -0
  9. package/.test-dist/src/extensions/bridgeSelection.js +20 -0
  10. package/.test-dist/src/extensions/constraints.js +237 -0
  11. package/.test-dist/src/extensions/dieline.js +828 -0
  12. package/.test-dist/src/extensions/edgeScale.js +12 -0
  13. package/.test-dist/src/extensions/feature.js +825 -0
  14. package/.test-dist/src/extensions/featureComplete.js +32 -0
  15. package/.test-dist/src/extensions/film.js +167 -0
  16. package/.test-dist/src/extensions/geometry.js +545 -0
  17. package/.test-dist/src/extensions/image.js +1529 -0
  18. package/.test-dist/src/extensions/index.js +30 -0
  19. package/.test-dist/src/extensions/maskOps.js +279 -0
  20. package/.test-dist/src/extensions/mirror.js +104 -0
  21. package/.test-dist/src/extensions/ruler.js +345 -0
  22. package/.test-dist/src/extensions/sceneLayout.js +96 -0
  23. package/.test-dist/src/extensions/sceneLayoutModel.js +196 -0
  24. package/.test-dist/src/extensions/sceneVisibility.js +62 -0
  25. package/.test-dist/src/extensions/size.js +331 -0
  26. package/.test-dist/src/extensions/tracer.js +538 -0
  27. package/.test-dist/src/extensions/white-ink.js +1190 -0
  28. package/.test-dist/src/extensions/wrappedOffsets.js +33 -0
  29. package/.test-dist/src/feature.js +826 -826
  30. package/.test-dist/src/featureComplete.js +32 -32
  31. package/.test-dist/src/film.js +167 -167
  32. package/.test-dist/src/geometry.js +506 -506
  33. package/.test-dist/src/image.js +1250 -1250
  34. package/.test-dist/src/index.js +2 -19
  35. package/.test-dist/src/maskOps.js +270 -270
  36. package/.test-dist/src/mirror.js +104 -104
  37. package/.test-dist/src/renderSpec.js +2 -2
  38. package/.test-dist/src/ruler.js +343 -343
  39. package/.test-dist/src/sceneLayout.js +99 -99
  40. package/.test-dist/src/sceneLayoutModel.js +196 -196
  41. package/.test-dist/src/sceneView.js +40 -40
  42. package/.test-dist/src/sceneVisibility.js +42 -42
  43. package/.test-dist/src/services/CanvasService.js +249 -0
  44. package/.test-dist/src/services/ViewportSystem.js +76 -0
  45. package/.test-dist/src/services/index.js +24 -0
  46. package/.test-dist/src/services/renderSpec.js +2 -0
  47. package/.test-dist/src/size.js +332 -332
  48. package/.test-dist/src/tracer.js +544 -544
  49. package/.test-dist/src/white-ink.js +829 -829
  50. package/.test-dist/src/wrappedOffsets.js +33 -33
  51. package/CHANGELOG.md +12 -0
  52. package/dist/index.d.mts +14 -0
  53. package/dist/index.d.ts +14 -0
  54. package/dist/index.js +3521 -3220
  55. package/dist/index.mjs +3532 -3226
  56. package/package.json +1 -1
  57. package/src/coordinate.ts +106 -106
  58. package/src/extensions/background.ts +230 -230
  59. package/src/extensions/bridgeSelection.ts +17 -17
  60. package/src/extensions/constraints.ts +322 -322
  61. package/src/extensions/dieline.ts +20 -17
  62. package/src/extensions/edgeScale.ts +19 -19
  63. package/src/extensions/feature.ts +1021 -1021
  64. package/src/extensions/featureComplete.ts +46 -46
  65. package/src/extensions/film.ts +194 -194
  66. package/src/extensions/geometry.ts +719 -719
  67. package/src/extensions/image.ts +1924 -1594
  68. package/src/extensions/index.ts +11 -11
  69. package/src/extensions/maskOps.ts +365 -299
  70. package/src/extensions/mirror.ts +128 -128
  71. package/src/extensions/ruler.ts +451 -451
  72. package/src/extensions/sceneLayout.ts +140 -140
  73. package/src/extensions/sceneLayoutModel.ts +342 -342
  74. package/src/extensions/sceneVisibility.ts +71 -71
  75. package/src/extensions/size.ts +389 -389
  76. package/src/extensions/tracer.ts +302 -370
  77. package/src/extensions/white-ink.ts +1489 -1366
  78. package/src/extensions/wrappedOffsets.ts +33 -33
  79. package/src/index.ts +2 -2
  80. package/src/services/CanvasService.ts +300 -300
  81. package/src/services/ViewportSystem.ts +95 -95
  82. package/src/services/index.ts +3 -3
  83. package/src/services/renderSpec.ts +18 -18
  84. package/src/units.ts +27 -27
  85. package/tests/run.ts +118 -118
  86. package/tsconfig.test.json +15 -15
@@ -1,99 +1,99 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SceneLayoutService = void 0;
4
- const core_1 = require("@pooder/core");
5
- const sceneLayoutModel_1 = require("./sceneLayoutModel");
6
- const GEOMETRY_KEYS = new Set([
7
- "dieline.shape",
8
- "dieline.radius",
9
- "dieline.pathData",
10
- "size.unit",
11
- ]);
12
- class SceneLayoutService {
13
- constructor() {
14
- this.id = "pooder.kit.sceneLayout";
15
- this.metadata = {
16
- name: "SceneLayoutService",
17
- };
18
- this.lastLayout = null;
19
- this.lastGeometry = null;
20
- this.onCanvasResized = () => {
21
- this.refresh(true);
22
- };
23
- }
24
- activate(context) {
25
- this.context = context;
26
- this.canvasService = context.services.get("CanvasService");
27
- this.configService = context.services.get("ConfigurationService");
28
- if (!this.canvasService || !this.configService)
29
- return;
30
- this.onConfigChange = this.configService.onAnyChange((e) => {
31
- if (e.key.startsWith("size.") || e.key.startsWith("dieline.")) {
32
- this.refresh(GEOMETRY_KEYS.has(e.key));
33
- }
34
- });
35
- context.eventBus.on("canvas:resized", this.onCanvasResized);
36
- this.refresh(true);
37
- }
38
- deactivate(context) {
39
- context.eventBus.off("canvas:resized", this.onCanvasResized);
40
- this.onConfigChange?.dispose();
41
- this.onConfigChange = undefined;
42
- this.context = undefined;
43
- this.canvasService = undefined;
44
- this.configService = undefined;
45
- this.lastLayout = null;
46
- this.lastGeometry = null;
47
- }
48
- contribute() {
49
- return {
50
- [core_1.ContributionPointIds.COMMANDS]: [
51
- {
52
- command: "getSceneLayout",
53
- title: "Get Scene Layout",
54
- handler: () => this.getLayout(),
55
- },
56
- {
57
- command: "getSceneGeometry",
58
- title: "Get Scene Geometry",
59
- handler: () => this.getGeometry(),
60
- },
61
- ],
62
- };
63
- }
64
- refresh(forceGeometry = false) {
65
- const layout = this.getLayout(true);
66
- if (!layout)
67
- return;
68
- this.context?.eventBus.emit("scene:layout:change", layout);
69
- if (forceGeometry || !this.lastGeometry) {
70
- const geometry = this.getGeometry(true);
71
- if (geometry) {
72
- this.context?.eventBus.emit("scene:geometry:change", geometry);
73
- }
74
- }
75
- }
76
- getLayout(forceRefresh = false) {
77
- if (!this.canvasService || !this.configService)
78
- return null;
79
- if (!forceRefresh && this.lastLayout)
80
- return this.lastLayout;
81
- const state = (0, sceneLayoutModel_1.readSizeState)(this.configService);
82
- const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, state);
83
- this.lastLayout = layout;
84
- return layout;
85
- }
86
- getGeometry(forceRefresh = false) {
87
- if (!this.configService)
88
- return null;
89
- const layout = this.getLayout(forceRefresh);
90
- if (!layout)
91
- return null;
92
- if (!forceRefresh && this.lastGeometry)
93
- return this.lastGeometry;
94
- const geometry = (0, sceneLayoutModel_1.buildSceneGeometry)(this.configService, layout);
95
- this.lastGeometry = geometry;
96
- return geometry;
97
- }
98
- }
99
- exports.SceneLayoutService = SceneLayoutService;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SceneLayoutService = void 0;
4
+ const core_1 = require("@pooder/core");
5
+ const sceneLayoutModel_1 = require("./sceneLayoutModel");
6
+ const GEOMETRY_KEYS = new Set([
7
+ "dieline.shape",
8
+ "dieline.radius",
9
+ "dieline.pathData",
10
+ "size.unit",
11
+ ]);
12
+ class SceneLayoutService {
13
+ constructor() {
14
+ this.id = "pooder.kit.sceneLayout";
15
+ this.metadata = {
16
+ name: "SceneLayoutService",
17
+ };
18
+ this.lastLayout = null;
19
+ this.lastGeometry = null;
20
+ this.onCanvasResized = () => {
21
+ this.refresh(true);
22
+ };
23
+ }
24
+ activate(context) {
25
+ this.context = context;
26
+ this.canvasService = context.services.get("CanvasService");
27
+ this.configService = context.services.get("ConfigurationService");
28
+ if (!this.canvasService || !this.configService)
29
+ return;
30
+ this.onConfigChange = this.configService.onAnyChange((e) => {
31
+ if (e.key.startsWith("size.") || e.key.startsWith("dieline.")) {
32
+ this.refresh(GEOMETRY_KEYS.has(e.key));
33
+ }
34
+ });
35
+ context.eventBus.on("canvas:resized", this.onCanvasResized);
36
+ this.refresh(true);
37
+ }
38
+ deactivate(context) {
39
+ context.eventBus.off("canvas:resized", this.onCanvasResized);
40
+ this.onConfigChange?.dispose();
41
+ this.onConfigChange = undefined;
42
+ this.context = undefined;
43
+ this.canvasService = undefined;
44
+ this.configService = undefined;
45
+ this.lastLayout = null;
46
+ this.lastGeometry = null;
47
+ }
48
+ contribute() {
49
+ return {
50
+ [core_1.ContributionPointIds.COMMANDS]: [
51
+ {
52
+ command: "getSceneLayout",
53
+ title: "Get Scene Layout",
54
+ handler: () => this.getLayout(),
55
+ },
56
+ {
57
+ command: "getSceneGeometry",
58
+ title: "Get Scene Geometry",
59
+ handler: () => this.getGeometry(),
60
+ },
61
+ ],
62
+ };
63
+ }
64
+ refresh(forceGeometry = false) {
65
+ const layout = this.getLayout(true);
66
+ if (!layout)
67
+ return;
68
+ this.context?.eventBus.emit("scene:layout:change", layout);
69
+ if (forceGeometry || !this.lastGeometry) {
70
+ const geometry = this.getGeometry(true);
71
+ if (geometry) {
72
+ this.context?.eventBus.emit("scene:geometry:change", geometry);
73
+ }
74
+ }
75
+ }
76
+ getLayout(forceRefresh = false) {
77
+ if (!this.canvasService || !this.configService)
78
+ return null;
79
+ if (!forceRefresh && this.lastLayout)
80
+ return this.lastLayout;
81
+ const state = (0, sceneLayoutModel_1.readSizeState)(this.configService);
82
+ const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, state);
83
+ this.lastLayout = layout;
84
+ return layout;
85
+ }
86
+ getGeometry(forceRefresh = false) {
87
+ if (!this.configService)
88
+ return null;
89
+ const layout = this.getLayout(forceRefresh);
90
+ if (!layout)
91
+ return null;
92
+ if (!forceRefresh && this.lastGeometry)
93
+ return this.lastGeometry;
94
+ const geometry = (0, sceneLayoutModel_1.buildSceneGeometry)(this.configService, layout);
95
+ this.lastGeometry = geometry;
96
+ return geometry;
97
+ }
98
+ }
99
+ exports.SceneLayoutService = SceneLayoutService;
@@ -1,196 +1,196 @@
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 DEFAULT_SIZE_STATE = {
16
- unit: "mm",
17
- actualWidthMm: 500,
18
- actualHeightMm: 500,
19
- constraintMode: "free",
20
- aspectRatio: 1,
21
- cutMode: "trim",
22
- cutMarginMm: 0,
23
- viewPadding: 140,
24
- minMm: 10,
25
- maxMm: 2000,
26
- stepMm: 0.1,
27
- };
28
- function clamp(value, min, max) {
29
- return Math.max(min, Math.min(max, value));
30
- }
31
- function roundToStep(value, step) {
32
- if (!Number.isFinite(step) || step <= 0)
33
- return value;
34
- return Math.round(value / step) * step;
35
- }
36
- function sanitizeMmValue(valueMm, limits) {
37
- if (!Number.isFinite(valueMm))
38
- return limits.minMm;
39
- const rounded = roundToStep(valueMm, limits.stepMm);
40
- return clamp(rounded, limits.minMm, limits.maxMm);
41
- }
42
- function normalizeUnit(value) {
43
- if (value === "cm" || value === "in")
44
- return value;
45
- return "mm";
46
- }
47
- function normalizeConstraintMode(value) {
48
- if (value === "lockAspect" || value === "equal")
49
- return value;
50
- return "free";
51
- }
52
- function normalizeCutMode(value) {
53
- if (value === "outset" || value === "inset")
54
- return value;
55
- return "trim";
56
- }
57
- function toMm(value, fromUnit) {
58
- return coordinate_1.Coordinate.convertUnit(value, fromUnit, "mm");
59
- }
60
- function fromMm(valueMm, toUnit) {
61
- return coordinate_1.Coordinate.convertUnit(valueMm, "mm", toUnit);
62
- }
63
- function resolvePaddingPx(raw, containerWidth, containerHeight) {
64
- if (typeof raw === "number")
65
- return Math.max(0, raw);
66
- if (typeof raw === "string") {
67
- if (raw.endsWith("%")) {
68
- const percent = parseFloat(raw) / 100;
69
- if (!Number.isFinite(percent))
70
- return 0;
71
- return Math.max(0, Math.min(containerWidth, containerHeight) * percent);
72
- }
73
- const fixed = parseFloat(raw);
74
- return Number.isFinite(fixed) ? Math.max(0, fixed) : 0;
75
- }
76
- return 0;
77
- }
78
- function readSizeState(configService) {
79
- const unit = normalizeUnit(configService.get("size.unit", DEFAULT_SIZE_STATE.unit));
80
- const minMm = Math.max(0.1, Number(configService.get("size.minMm", DEFAULT_SIZE_STATE.minMm)));
81
- const maxMm = Math.max(minMm, Number(configService.get("size.maxMm", DEFAULT_SIZE_STATE.maxMm)));
82
- const stepMm = Math.max(0.001, Number(configService.get("size.stepMm", DEFAULT_SIZE_STATE.stepMm)));
83
- const actualWidthMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualWidthMm", DEFAULT_SIZE_STATE.actualWidthMm), "mm"), { minMm, maxMm, stepMm });
84
- const actualHeightMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualHeightMm", DEFAULT_SIZE_STATE.actualHeightMm), "mm"), { minMm, maxMm, stepMm });
85
- const aspectRaw = Number(configService.get("size.aspectRatio", DEFAULT_SIZE_STATE.aspectRatio));
86
- const aspectRatio = Number.isFinite(aspectRaw) && aspectRaw > 0
87
- ? aspectRaw
88
- : actualWidthMm / Math.max(0.001, actualHeightMm);
89
- const cutMarginMm = Math.max(0, (0, units_1.parseLengthToMm)(configService.get("size.cutMarginMm", DEFAULT_SIZE_STATE.cutMarginMm), "mm"));
90
- const viewPadding = configService.get("size.viewPadding", DEFAULT_SIZE_STATE.viewPadding);
91
- return {
92
- unit,
93
- actualWidthMm,
94
- actualHeightMm,
95
- constraintMode: normalizeConstraintMode(configService.get("size.constraintMode", DEFAULT_SIZE_STATE.constraintMode)),
96
- aspectRatio,
97
- cutMode: normalizeCutMode(configService.get("size.cutMode", DEFAULT_SIZE_STATE.cutMode)),
98
- cutMarginMm,
99
- viewPadding,
100
- minMm,
101
- maxMm,
102
- stepMm,
103
- };
104
- }
105
- function rectByCenter(centerX, centerY, width, height) {
106
- return {
107
- left: centerX - width / 2,
108
- top: centerY - height / 2,
109
- width,
110
- height,
111
- centerX,
112
- centerY,
113
- };
114
- }
115
- function getCutSizeMm(size) {
116
- if (size.cutMode === "trim") {
117
- return { widthMm: size.actualWidthMm, heightMm: size.actualHeightMm };
118
- }
119
- const delta = size.cutMarginMm * 2;
120
- if (size.cutMode === "outset") {
121
- return {
122
- widthMm: size.actualWidthMm + delta,
123
- heightMm: size.actualHeightMm + delta,
124
- };
125
- }
126
- return {
127
- widthMm: Math.max(size.minMm, size.actualWidthMm - delta),
128
- heightMm: Math.max(size.minMm, size.actualHeightMm - delta),
129
- };
130
- }
131
- function computeSceneLayout(canvasService, size) {
132
- const canvasWidth = canvasService.canvas.width || 0;
133
- const canvasHeight = canvasService.canvas.height || 0;
134
- if (canvasWidth <= 0 || canvasHeight <= 0)
135
- return null;
136
- const { widthMm: cutWidthMm, heightMm: cutHeightMm } = getCutSizeMm(size);
137
- const viewWidthMm = Math.max(size.actualWidthMm, cutWidthMm);
138
- const viewHeightMm = Math.max(size.actualHeightMm, cutHeightMm);
139
- if (!Number.isFinite(viewWidthMm) ||
140
- !Number.isFinite(viewHeightMm) ||
141
- viewWidthMm <= 0 ||
142
- viewHeightMm <= 0) {
143
- return null;
144
- }
145
- const paddingPx = resolvePaddingPx(size.viewPadding, canvasWidth, canvasHeight);
146
- canvasService.viewport.updateContainer(canvasWidth, canvasHeight);
147
- canvasService.viewport.setPadding(paddingPx);
148
- canvasService.viewport.updatePhysical(viewWidthMm, viewHeightMm);
149
- const layout = canvasService.viewport.layout;
150
- if (!Number.isFinite(layout.scale) ||
151
- !Number.isFinite(layout.offsetX) ||
152
- !Number.isFinite(layout.offsetY) ||
153
- layout.scale <= 0) {
154
- return null;
155
- }
156
- const centerX = layout.offsetX + layout.width / 2;
157
- const centerY = layout.offsetY + layout.height / 2;
158
- const trimWidthPx = size.actualWidthMm * layout.scale;
159
- const trimHeightPx = size.actualHeightMm * layout.scale;
160
- const cutWidthPx = cutWidthMm * layout.scale;
161
- const cutHeightPx = cutHeightMm * layout.scale;
162
- const trimRect = rectByCenter(centerX, centerY, trimWidthPx, trimHeightPx);
163
- const cutRect = rectByCenter(centerX, centerY, cutWidthPx, cutHeightPx);
164
- const bleedRect = rectByCenter(centerX, centerY, Math.max(trimWidthPx, cutWidthPx), Math.max(trimHeightPx, cutHeightPx));
165
- return {
166
- scale: layout.scale,
167
- canvasWidth,
168
- canvasHeight,
169
- trimRect,
170
- cutRect,
171
- bleedRect,
172
- trimWidthMm: size.actualWidthMm,
173
- trimHeightMm: size.actualHeightMm,
174
- cutWidthMm,
175
- cutHeightMm,
176
- cutMode: size.cutMode,
177
- cutMarginMm: size.cutMarginMm,
178
- };
179
- }
180
- function buildSceneGeometry(configService, layout) {
181
- const radiusMm = (0, units_1.parseLengthToMm)(configService.get("dieline.radius", 0), "mm");
182
- const offset = (layout.cutRect.width - layout.trimRect.width) / 2;
183
- return {
184
- shape: configService.get("dieline.shape", "rect"),
185
- unit: "mm",
186
- displayUnit: normalizeUnit(configService.get("size.unit", "mm")),
187
- x: layout.trimRect.centerX,
188
- y: layout.trimRect.centerY,
189
- width: layout.trimRect.width,
190
- height: layout.trimRect.height,
191
- radius: radiusMm * layout.scale,
192
- offset,
193
- scale: layout.scale,
194
- pathData: configService.get("dieline.pathData"),
195
- };
196
- }
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 DEFAULT_SIZE_STATE = {
16
+ unit: "mm",
17
+ actualWidthMm: 500,
18
+ actualHeightMm: 500,
19
+ constraintMode: "free",
20
+ aspectRatio: 1,
21
+ cutMode: "trim",
22
+ cutMarginMm: 0,
23
+ viewPadding: 140,
24
+ minMm: 10,
25
+ maxMm: 2000,
26
+ stepMm: 0.1,
27
+ };
28
+ function clamp(value, min, max) {
29
+ return Math.max(min, Math.min(max, value));
30
+ }
31
+ function roundToStep(value, step) {
32
+ if (!Number.isFinite(step) || step <= 0)
33
+ return value;
34
+ return Math.round(value / step) * step;
35
+ }
36
+ function sanitizeMmValue(valueMm, limits) {
37
+ if (!Number.isFinite(valueMm))
38
+ return limits.minMm;
39
+ const rounded = roundToStep(valueMm, limits.stepMm);
40
+ return clamp(rounded, limits.minMm, limits.maxMm);
41
+ }
42
+ function normalizeUnit(value) {
43
+ if (value === "cm" || value === "in")
44
+ return value;
45
+ return "mm";
46
+ }
47
+ function normalizeConstraintMode(value) {
48
+ if (value === "lockAspect" || value === "equal")
49
+ return value;
50
+ return "free";
51
+ }
52
+ function normalizeCutMode(value) {
53
+ if (value === "outset" || value === "inset")
54
+ return value;
55
+ return "trim";
56
+ }
57
+ function toMm(value, fromUnit) {
58
+ return coordinate_1.Coordinate.convertUnit(value, fromUnit, "mm");
59
+ }
60
+ function fromMm(valueMm, toUnit) {
61
+ return coordinate_1.Coordinate.convertUnit(valueMm, "mm", toUnit);
62
+ }
63
+ function resolvePaddingPx(raw, containerWidth, containerHeight) {
64
+ if (typeof raw === "number")
65
+ return Math.max(0, raw);
66
+ if (typeof raw === "string") {
67
+ if (raw.endsWith("%")) {
68
+ const percent = parseFloat(raw) / 100;
69
+ if (!Number.isFinite(percent))
70
+ return 0;
71
+ return Math.max(0, Math.min(containerWidth, containerHeight) * percent);
72
+ }
73
+ const fixed = parseFloat(raw);
74
+ return Number.isFinite(fixed) ? Math.max(0, fixed) : 0;
75
+ }
76
+ return 0;
77
+ }
78
+ function readSizeState(configService) {
79
+ const unit = normalizeUnit(configService.get("size.unit", DEFAULT_SIZE_STATE.unit));
80
+ const minMm = Math.max(0.1, Number(configService.get("size.minMm", DEFAULT_SIZE_STATE.minMm)));
81
+ const maxMm = Math.max(minMm, Number(configService.get("size.maxMm", DEFAULT_SIZE_STATE.maxMm)));
82
+ const stepMm = Math.max(0.001, Number(configService.get("size.stepMm", DEFAULT_SIZE_STATE.stepMm)));
83
+ const actualWidthMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualWidthMm", DEFAULT_SIZE_STATE.actualWidthMm), "mm"), { minMm, maxMm, stepMm });
84
+ const actualHeightMm = sanitizeMmValue((0, units_1.parseLengthToMm)(configService.get("size.actualHeightMm", DEFAULT_SIZE_STATE.actualHeightMm), "mm"), { minMm, maxMm, stepMm });
85
+ const aspectRaw = Number(configService.get("size.aspectRatio", DEFAULT_SIZE_STATE.aspectRatio));
86
+ const aspectRatio = Number.isFinite(aspectRaw) && aspectRaw > 0
87
+ ? aspectRaw
88
+ : actualWidthMm / Math.max(0.001, actualHeightMm);
89
+ const cutMarginMm = Math.max(0, (0, units_1.parseLengthToMm)(configService.get("size.cutMarginMm", DEFAULT_SIZE_STATE.cutMarginMm), "mm"));
90
+ const viewPadding = configService.get("size.viewPadding", DEFAULT_SIZE_STATE.viewPadding);
91
+ return {
92
+ unit,
93
+ actualWidthMm,
94
+ actualHeightMm,
95
+ constraintMode: normalizeConstraintMode(configService.get("size.constraintMode", DEFAULT_SIZE_STATE.constraintMode)),
96
+ aspectRatio,
97
+ cutMode: normalizeCutMode(configService.get("size.cutMode", DEFAULT_SIZE_STATE.cutMode)),
98
+ cutMarginMm,
99
+ viewPadding,
100
+ minMm,
101
+ maxMm,
102
+ stepMm,
103
+ };
104
+ }
105
+ function rectByCenter(centerX, centerY, width, height) {
106
+ return {
107
+ left: centerX - width / 2,
108
+ top: centerY - height / 2,
109
+ width,
110
+ height,
111
+ centerX,
112
+ centerY,
113
+ };
114
+ }
115
+ function getCutSizeMm(size) {
116
+ if (size.cutMode === "trim") {
117
+ return { widthMm: size.actualWidthMm, heightMm: size.actualHeightMm };
118
+ }
119
+ const delta = size.cutMarginMm * 2;
120
+ if (size.cutMode === "outset") {
121
+ return {
122
+ widthMm: size.actualWidthMm + delta,
123
+ heightMm: size.actualHeightMm + delta,
124
+ };
125
+ }
126
+ return {
127
+ widthMm: Math.max(size.minMm, size.actualWidthMm - delta),
128
+ heightMm: Math.max(size.minMm, size.actualHeightMm - delta),
129
+ };
130
+ }
131
+ function computeSceneLayout(canvasService, size) {
132
+ const canvasWidth = canvasService.canvas.width || 0;
133
+ const canvasHeight = canvasService.canvas.height || 0;
134
+ if (canvasWidth <= 0 || canvasHeight <= 0)
135
+ return null;
136
+ const { widthMm: cutWidthMm, heightMm: cutHeightMm } = getCutSizeMm(size);
137
+ const viewWidthMm = Math.max(size.actualWidthMm, cutWidthMm);
138
+ const viewHeightMm = Math.max(size.actualHeightMm, cutHeightMm);
139
+ if (!Number.isFinite(viewWidthMm) ||
140
+ !Number.isFinite(viewHeightMm) ||
141
+ viewWidthMm <= 0 ||
142
+ viewHeightMm <= 0) {
143
+ return null;
144
+ }
145
+ const paddingPx = resolvePaddingPx(size.viewPadding, canvasWidth, canvasHeight);
146
+ canvasService.viewport.updateContainer(canvasWidth, canvasHeight);
147
+ canvasService.viewport.setPadding(paddingPx);
148
+ canvasService.viewport.updatePhysical(viewWidthMm, viewHeightMm);
149
+ const layout = canvasService.viewport.layout;
150
+ if (!Number.isFinite(layout.scale) ||
151
+ !Number.isFinite(layout.offsetX) ||
152
+ !Number.isFinite(layout.offsetY) ||
153
+ layout.scale <= 0) {
154
+ return null;
155
+ }
156
+ const centerX = layout.offsetX + layout.width / 2;
157
+ const centerY = layout.offsetY + layout.height / 2;
158
+ const trimWidthPx = size.actualWidthMm * layout.scale;
159
+ const trimHeightPx = size.actualHeightMm * layout.scale;
160
+ const cutWidthPx = cutWidthMm * layout.scale;
161
+ const cutHeightPx = cutHeightMm * layout.scale;
162
+ const trimRect = rectByCenter(centerX, centerY, trimWidthPx, trimHeightPx);
163
+ const cutRect = rectByCenter(centerX, centerY, cutWidthPx, cutHeightPx);
164
+ const bleedRect = rectByCenter(centerX, centerY, Math.max(trimWidthPx, cutWidthPx), Math.max(trimHeightPx, cutHeightPx));
165
+ return {
166
+ scale: layout.scale,
167
+ canvasWidth,
168
+ canvasHeight,
169
+ trimRect,
170
+ cutRect,
171
+ bleedRect,
172
+ trimWidthMm: size.actualWidthMm,
173
+ trimHeightMm: size.actualHeightMm,
174
+ cutWidthMm,
175
+ cutHeightMm,
176
+ cutMode: size.cutMode,
177
+ cutMarginMm: size.cutMarginMm,
178
+ };
179
+ }
180
+ function buildSceneGeometry(configService, layout) {
181
+ const radiusMm = (0, units_1.parseLengthToMm)(configService.get("dieline.radius", 0), "mm");
182
+ const offset = (layout.cutRect.width - layout.trimRect.width) / 2;
183
+ return {
184
+ shape: configService.get("dieline.shape", "rect"),
185
+ unit: "mm",
186
+ displayUnit: normalizeUnit(configService.get("size.unit", "mm")),
187
+ x: layout.trimRect.centerX,
188
+ y: layout.trimRect.centerY,
189
+ width: layout.trimRect.width,
190
+ height: layout.trimRect.height,
191
+ radius: radiusMm * layout.scale,
192
+ offset,
193
+ scale: layout.scale,
194
+ pathData: configService.get("dieline.pathData"),
195
+ };
196
+ }