@pooder/kit 5.3.1 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +243 -36
- package/dist/index.d.ts +243 -36
- package/dist/index.js +2278 -1041
- package/dist/index.mjs +2278 -1041
- package/package.json +1 -1
- package/src/coordinate.ts +106 -106
- package/src/extensions/background.ts +323 -230
- package/src/extensions/bridgeSelection.ts +17 -17
- package/src/extensions/constraints.ts +322 -322
- package/src/extensions/dieline.ts +1149 -1076
- package/src/extensions/dielineShape.ts +109 -0
- package/src/extensions/edgeScale.ts +19 -19
- package/src/extensions/feature.ts +1137 -1021
- package/src/extensions/featureComplete.ts +46 -46
- package/src/extensions/film.ts +266 -194
- package/src/extensions/geometry.ts +885 -752
- package/src/extensions/image.ts +2054 -1926
- package/src/extensions/index.ts +11 -11
- package/src/extensions/maskOps.ts +283 -283
- package/src/extensions/mirror.ts +128 -128
- package/src/extensions/ruler.ts +654 -451
- package/src/extensions/sceneLayout.ts +140 -140
- package/src/extensions/sceneLayoutModel.ts +364 -352
- package/src/extensions/sceneVisibility.ts +64 -71
- package/src/extensions/size.ts +389 -389
- package/src/extensions/tracer.ts +1019 -1019
- package/src/extensions/white-ink.ts +1567 -1514
- package/src/extensions/wrappedOffsets.ts +33 -33
- package/src/index.ts +2 -2
- package/src/services/CanvasService.ts +832 -300
- package/src/services/ViewportSystem.ts +95 -95
- package/src/services/index.ts +3 -3
- package/src/services/renderSpec.ts +53 -18
- package/src/units.ts +27 -27
- package/tests/run.ts +118 -118
- package/tsconfig.test.json +15 -15
- package/.test-dist/src/CanvasService.js +0 -249
- package/.test-dist/src/ViewportSystem.js +0 -75
- package/.test-dist/src/background.js +0 -203
- package/.test-dist/src/bridgeSelection.js +0 -20
- package/.test-dist/src/constraints.js +0 -237
- package/.test-dist/src/coordinate.js +0 -74
- package/.test-dist/src/dieline.js +0 -818
- package/.test-dist/src/edgeScale.js +0 -12
- package/.test-dist/src/extensions/background.js +0 -203
- package/.test-dist/src/extensions/bridgeSelection.js +0 -20
- package/.test-dist/src/extensions/constraints.js +0 -237
- package/.test-dist/src/extensions/dieline.js +0 -828
- package/.test-dist/src/extensions/edgeScale.js +0 -12
- package/.test-dist/src/extensions/feature.js +0 -825
- package/.test-dist/src/extensions/featureComplete.js +0 -32
- package/.test-dist/src/extensions/film.js +0 -167
- package/.test-dist/src/extensions/geometry.js +0 -545
- package/.test-dist/src/extensions/image.js +0 -1529
- package/.test-dist/src/extensions/index.js +0 -30
- package/.test-dist/src/extensions/maskOps.js +0 -279
- package/.test-dist/src/extensions/mirror.js +0 -104
- package/.test-dist/src/extensions/ruler.js +0 -345
- package/.test-dist/src/extensions/sceneLayout.js +0 -96
- package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
- package/.test-dist/src/extensions/sceneVisibility.js +0 -62
- package/.test-dist/src/extensions/size.js +0 -331
- package/.test-dist/src/extensions/tracer.js +0 -538
- package/.test-dist/src/extensions/white-ink.js +0 -1190
- package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
- package/.test-dist/src/feature.js +0 -826
- package/.test-dist/src/featureComplete.js +0 -32
- package/.test-dist/src/film.js +0 -167
- package/.test-dist/src/geometry.js +0 -506
- package/.test-dist/src/image.js +0 -1250
- package/.test-dist/src/index.js +0 -18
- package/.test-dist/src/maskOps.js +0 -270
- package/.test-dist/src/mirror.js +0 -104
- package/.test-dist/src/renderSpec.js +0 -2
- package/.test-dist/src/ruler.js +0 -343
- package/.test-dist/src/sceneLayout.js +0 -99
- package/.test-dist/src/sceneLayoutModel.js +0 -196
- package/.test-dist/src/sceneView.js +0 -40
- package/.test-dist/src/sceneVisibility.js +0 -42
- package/.test-dist/src/services/CanvasService.js +0 -249
- package/.test-dist/src/services/ViewportSystem.js +0 -76
- package/.test-dist/src/services/index.js +0 -24
- package/.test-dist/src/services/renderSpec.js +0 -2
- package/.test-dist/src/size.js +0 -332
- package/.test-dist/src/tracer.js +0 -544
- package/.test-dist/src/units.js +0 -30
- package/.test-dist/src/white-ink.js +0 -829
- package/.test-dist/src/wrappedOffsets.js +0 -33
- package/.test-dist/tests/run.js +0 -94
|
@@ -1,352 +1,364 @@
|
|
|
1
|
-
import type { ConfigurationService } from "@pooder/core";
|
|
2
|
-
import type { CanvasService } from "../services";
|
|
3
|
-
import { Coordinate, Unit } from "../coordinate";
|
|
4
|
-
import { parseLengthToMm } from "../units";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
parseLengthToMm(
|
|
163
|
-
configService.get(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
configService.get(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
1
|
+
import type { ConfigurationService } from "@pooder/core";
|
|
2
|
+
import type { CanvasService } from "../services";
|
|
3
|
+
import { Coordinate, Unit } from "../coordinate";
|
|
4
|
+
import { parseLengthToMm } from "../units";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_DIELINE_SHAPE,
|
|
7
|
+
DEFAULT_DIELINE_SHAPE_STYLE,
|
|
8
|
+
normalizeShapeStyle,
|
|
9
|
+
normalizeDielineShape,
|
|
10
|
+
} from "./dielineShape";
|
|
11
|
+
import type { DielineShape, DielineShapeStyle } from "./dielineShape";
|
|
12
|
+
|
|
13
|
+
export type SizeConstraintMode = "free" | "lockAspect" | "equal";
|
|
14
|
+
export type CutMode = "trim" | "outset" | "inset";
|
|
15
|
+
|
|
16
|
+
export interface SizeState {
|
|
17
|
+
unit: Unit;
|
|
18
|
+
actualWidthMm: number;
|
|
19
|
+
actualHeightMm: number;
|
|
20
|
+
constraintMode: SizeConstraintMode;
|
|
21
|
+
aspectRatio: number;
|
|
22
|
+
cutMode: CutMode;
|
|
23
|
+
cutMarginMm: number;
|
|
24
|
+
viewPadding: number | string;
|
|
25
|
+
minMm: number;
|
|
26
|
+
maxMm: number;
|
|
27
|
+
stepMm: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SceneRect {
|
|
31
|
+
left: number;
|
|
32
|
+
top: number;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
centerX: number;
|
|
36
|
+
centerY: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SceneLayoutSnapshot {
|
|
40
|
+
scale: number;
|
|
41
|
+
canvasWidth: number;
|
|
42
|
+
canvasHeight: number;
|
|
43
|
+
trimRect: SceneRect;
|
|
44
|
+
cutRect: SceneRect;
|
|
45
|
+
bleedRect: SceneRect;
|
|
46
|
+
trimWidthMm: number;
|
|
47
|
+
trimHeightMm: number;
|
|
48
|
+
cutWidthMm: number;
|
|
49
|
+
cutHeightMm: number;
|
|
50
|
+
cutMode: CutMode;
|
|
51
|
+
cutMarginMm: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface SceneGeometrySnapshot {
|
|
55
|
+
shape: DielineShape;
|
|
56
|
+
shapeStyle: DielineShapeStyle;
|
|
57
|
+
unit: "px";
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
radius: number;
|
|
63
|
+
offset: number;
|
|
64
|
+
scale: number;
|
|
65
|
+
pathData?: string;
|
|
66
|
+
customSourceWidthPx?: number;
|
|
67
|
+
customSourceHeightPx?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DEFAULT_SIZE_STATE: SizeState = {
|
|
71
|
+
unit: "mm",
|
|
72
|
+
actualWidthMm: 500,
|
|
73
|
+
actualHeightMm: 500,
|
|
74
|
+
constraintMode: "free",
|
|
75
|
+
aspectRatio: 1,
|
|
76
|
+
cutMode: "trim",
|
|
77
|
+
cutMarginMm: 0,
|
|
78
|
+
viewPadding: 140,
|
|
79
|
+
minMm: 10,
|
|
80
|
+
maxMm: 2000,
|
|
81
|
+
stepMm: 0.1,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function clamp(value: number, min: number, max: number): number {
|
|
85
|
+
return Math.max(min, Math.min(max, value));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function roundToStep(value: number, step: number): number {
|
|
89
|
+
if (!Number.isFinite(step) || step <= 0) return value;
|
|
90
|
+
return Math.round(value / step) * step;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function sanitizeMmValue(
|
|
94
|
+
valueMm: number,
|
|
95
|
+
limits: { minMm: number; maxMm: number; stepMm: number },
|
|
96
|
+
): number {
|
|
97
|
+
if (!Number.isFinite(valueMm)) return limits.minMm;
|
|
98
|
+
const rounded = roundToStep(valueMm, limits.stepMm);
|
|
99
|
+
return clamp(rounded, limits.minMm, limits.maxMm);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function normalizeUnit(value: unknown): Unit {
|
|
103
|
+
if (value === "cm" || value === "in") return value;
|
|
104
|
+
return "mm";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function normalizeConstraintMode(value: unknown): SizeConstraintMode {
|
|
108
|
+
if (value === "lockAspect" || value === "equal") return value;
|
|
109
|
+
return "free";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function normalizeCutMode(value: unknown): CutMode {
|
|
113
|
+
if (value === "outset" || value === "inset") return value;
|
|
114
|
+
return "trim";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function toMm(value: number, fromUnit: Unit): number {
|
|
118
|
+
return Coordinate.convertUnit(value, fromUnit, "mm");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function fromMm(valueMm: number, toUnit: Unit): number {
|
|
122
|
+
return Coordinate.convertUnit(valueMm, "mm", toUnit);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function resolvePaddingPx(
|
|
126
|
+
raw: number | string,
|
|
127
|
+
containerWidth: number,
|
|
128
|
+
containerHeight: number,
|
|
129
|
+
): number {
|
|
130
|
+
if (typeof raw === "number") return Math.max(0, raw);
|
|
131
|
+
if (typeof raw === "string") {
|
|
132
|
+
if (raw.endsWith("%")) {
|
|
133
|
+
const percent = parseFloat(raw) / 100;
|
|
134
|
+
if (!Number.isFinite(percent)) return 0;
|
|
135
|
+
return Math.max(0, Math.min(containerWidth, containerHeight) * percent);
|
|
136
|
+
}
|
|
137
|
+
const fixed = parseFloat(raw);
|
|
138
|
+
return Number.isFinite(fixed) ? Math.max(0, fixed) : 0;
|
|
139
|
+
}
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function readSizeState(configService: ConfigurationService): SizeState {
|
|
144
|
+
const unit = normalizeUnit(
|
|
145
|
+
configService.get("size.unit", DEFAULT_SIZE_STATE.unit),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const minMm = Math.max(
|
|
149
|
+
0.1,
|
|
150
|
+
Number(configService.get("size.minMm", DEFAULT_SIZE_STATE.minMm)),
|
|
151
|
+
);
|
|
152
|
+
const maxMm = Math.max(
|
|
153
|
+
minMm,
|
|
154
|
+
Number(configService.get("size.maxMm", DEFAULT_SIZE_STATE.maxMm)),
|
|
155
|
+
);
|
|
156
|
+
const stepMm = Math.max(
|
|
157
|
+
0.001,
|
|
158
|
+
Number(configService.get("size.stepMm", DEFAULT_SIZE_STATE.stepMm)),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const actualWidthMm = sanitizeMmValue(
|
|
162
|
+
parseLengthToMm(
|
|
163
|
+
configService.get("size.actualWidthMm", DEFAULT_SIZE_STATE.actualWidthMm),
|
|
164
|
+
"mm",
|
|
165
|
+
),
|
|
166
|
+
{ minMm, maxMm, stepMm },
|
|
167
|
+
);
|
|
168
|
+
const actualHeightMm = sanitizeMmValue(
|
|
169
|
+
parseLengthToMm(
|
|
170
|
+
configService.get(
|
|
171
|
+
"size.actualHeightMm",
|
|
172
|
+
DEFAULT_SIZE_STATE.actualHeightMm,
|
|
173
|
+
),
|
|
174
|
+
"mm",
|
|
175
|
+
),
|
|
176
|
+
{ minMm, maxMm, stepMm },
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const aspectRaw = Number(
|
|
180
|
+
configService.get("size.aspectRatio", DEFAULT_SIZE_STATE.aspectRatio),
|
|
181
|
+
);
|
|
182
|
+
const aspectRatio =
|
|
183
|
+
Number.isFinite(aspectRaw) && aspectRaw > 0
|
|
184
|
+
? aspectRaw
|
|
185
|
+
: actualWidthMm / Math.max(0.001, actualHeightMm);
|
|
186
|
+
|
|
187
|
+
const cutMarginMm = Math.max(
|
|
188
|
+
0,
|
|
189
|
+
parseLengthToMm(
|
|
190
|
+
configService.get("size.cutMarginMm", DEFAULT_SIZE_STATE.cutMarginMm),
|
|
191
|
+
"mm",
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const viewPadding = configService.get(
|
|
196
|
+
"size.viewPadding",
|
|
197
|
+
DEFAULT_SIZE_STATE.viewPadding,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
unit,
|
|
202
|
+
actualWidthMm,
|
|
203
|
+
actualHeightMm,
|
|
204
|
+
constraintMode: normalizeConstraintMode(
|
|
205
|
+
configService.get(
|
|
206
|
+
"size.constraintMode",
|
|
207
|
+
DEFAULT_SIZE_STATE.constraintMode,
|
|
208
|
+
),
|
|
209
|
+
),
|
|
210
|
+
aspectRatio,
|
|
211
|
+
cutMode: normalizeCutMode(
|
|
212
|
+
configService.get("size.cutMode", DEFAULT_SIZE_STATE.cutMode),
|
|
213
|
+
),
|
|
214
|
+
cutMarginMm,
|
|
215
|
+
viewPadding,
|
|
216
|
+
minMm,
|
|
217
|
+
maxMm,
|
|
218
|
+
stepMm,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function rectByCenter(
|
|
223
|
+
centerX: number,
|
|
224
|
+
centerY: number,
|
|
225
|
+
width: number,
|
|
226
|
+
height: number,
|
|
227
|
+
): SceneRect {
|
|
228
|
+
return {
|
|
229
|
+
left: centerX - width / 2,
|
|
230
|
+
top: centerY - height / 2,
|
|
231
|
+
width,
|
|
232
|
+
height,
|
|
233
|
+
centerX,
|
|
234
|
+
centerY,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getCutSizeMm(size: SizeState): { widthMm: number; heightMm: number } {
|
|
239
|
+
if (size.cutMode === "trim") {
|
|
240
|
+
return { widthMm: size.actualWidthMm, heightMm: size.actualHeightMm };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const delta = size.cutMarginMm * 2;
|
|
244
|
+
if (size.cutMode === "outset") {
|
|
245
|
+
return {
|
|
246
|
+
widthMm: size.actualWidthMm + delta,
|
|
247
|
+
heightMm: size.actualHeightMm + delta,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
widthMm: Math.max(size.minMm, size.actualWidthMm - delta),
|
|
253
|
+
heightMm: Math.max(size.minMm, size.actualHeightMm - delta),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function computeSceneLayout(
|
|
258
|
+
canvasService: CanvasService,
|
|
259
|
+
size: SizeState,
|
|
260
|
+
): SceneLayoutSnapshot | null {
|
|
261
|
+
const canvasWidth = canvasService.canvas.width || 0;
|
|
262
|
+
const canvasHeight = canvasService.canvas.height || 0;
|
|
263
|
+
if (canvasWidth <= 0 || canvasHeight <= 0) return null;
|
|
264
|
+
|
|
265
|
+
const { widthMm: cutWidthMm, heightMm: cutHeightMm } = getCutSizeMm(size);
|
|
266
|
+
const viewWidthMm = Math.max(size.actualWidthMm, cutWidthMm);
|
|
267
|
+
const viewHeightMm = Math.max(size.actualHeightMm, cutHeightMm);
|
|
268
|
+
if (
|
|
269
|
+
!Number.isFinite(viewWidthMm) ||
|
|
270
|
+
!Number.isFinite(viewHeightMm) ||
|
|
271
|
+
viewWidthMm <= 0 ||
|
|
272
|
+
viewHeightMm <= 0
|
|
273
|
+
) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const paddingPx = resolvePaddingPx(
|
|
278
|
+
size.viewPadding,
|
|
279
|
+
canvasWidth,
|
|
280
|
+
canvasHeight,
|
|
281
|
+
);
|
|
282
|
+
canvasService.viewport.updateContainer(canvasWidth, canvasHeight);
|
|
283
|
+
canvasService.viewport.setPadding(paddingPx);
|
|
284
|
+
canvasService.viewport.updatePhysical(viewWidthMm, viewHeightMm);
|
|
285
|
+
|
|
286
|
+
const layout = canvasService.viewport.layout;
|
|
287
|
+
if (
|
|
288
|
+
!Number.isFinite(layout.scale) ||
|
|
289
|
+
!Number.isFinite(layout.offsetX) ||
|
|
290
|
+
!Number.isFinite(layout.offsetY) ||
|
|
291
|
+
layout.scale <= 0
|
|
292
|
+
) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const centerX = layout.offsetX + layout.width / 2;
|
|
297
|
+
const centerY = layout.offsetY + layout.height / 2;
|
|
298
|
+
const trimWidthPx = size.actualWidthMm * layout.scale;
|
|
299
|
+
const trimHeightPx = size.actualHeightMm * layout.scale;
|
|
300
|
+
const cutWidthPx = cutWidthMm * layout.scale;
|
|
301
|
+
const cutHeightPx = cutHeightMm * layout.scale;
|
|
302
|
+
|
|
303
|
+
const trimRect = rectByCenter(centerX, centerY, trimWidthPx, trimHeightPx);
|
|
304
|
+
const cutRect = rectByCenter(centerX, centerY, cutWidthPx, cutHeightPx);
|
|
305
|
+
const bleedRect = rectByCenter(
|
|
306
|
+
centerX,
|
|
307
|
+
centerY,
|
|
308
|
+
Math.max(trimWidthPx, cutWidthPx),
|
|
309
|
+
Math.max(trimHeightPx, cutHeightPx),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
scale: layout.scale,
|
|
314
|
+
canvasWidth,
|
|
315
|
+
canvasHeight,
|
|
316
|
+
trimRect,
|
|
317
|
+
cutRect,
|
|
318
|
+
bleedRect,
|
|
319
|
+
trimWidthMm: size.actualWidthMm,
|
|
320
|
+
trimHeightMm: size.actualHeightMm,
|
|
321
|
+
cutWidthMm,
|
|
322
|
+
cutHeightMm,
|
|
323
|
+
cutMode: size.cutMode,
|
|
324
|
+
cutMarginMm: size.cutMarginMm,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function buildSceneGeometry(
|
|
329
|
+
configService: ConfigurationService,
|
|
330
|
+
layout: SceneLayoutSnapshot,
|
|
331
|
+
): SceneGeometrySnapshot {
|
|
332
|
+
const radiusMm = parseLengthToMm(
|
|
333
|
+
configService.get("dieline.radius", 0),
|
|
334
|
+
"mm",
|
|
335
|
+
);
|
|
336
|
+
const offset = (layout.cutRect.width - layout.trimRect.width) / 2;
|
|
337
|
+
const sourceWidth = Number(configService.get("dieline.customSourceWidthPx", 0));
|
|
338
|
+
const sourceHeight = Number(
|
|
339
|
+
configService.get("dieline.customSourceHeightPx", 0),
|
|
340
|
+
);
|
|
341
|
+
const shapeStyle = normalizeShapeStyle(
|
|
342
|
+
configService.get("dieline.shapeStyle", DEFAULT_DIELINE_SHAPE_STYLE),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
shape: normalizeDielineShape(
|
|
347
|
+
configService.get("dieline.shape", DEFAULT_DIELINE_SHAPE),
|
|
348
|
+
),
|
|
349
|
+
shapeStyle,
|
|
350
|
+
unit: "px",
|
|
351
|
+
x: layout.trimRect.centerX,
|
|
352
|
+
y: layout.trimRect.centerY,
|
|
353
|
+
width: layout.trimRect.width,
|
|
354
|
+
height: layout.trimRect.height,
|
|
355
|
+
radius: radiusMm * layout.scale,
|
|
356
|
+
offset,
|
|
357
|
+
scale: layout.scale,
|
|
358
|
+
pathData: configService.get("dieline.pathData"),
|
|
359
|
+
customSourceWidthPx:
|
|
360
|
+
Number.isFinite(sourceWidth) && sourceWidth > 0 ? sourceWidth : undefined,
|
|
361
|
+
customSourceHeightPx:
|
|
362
|
+
Number.isFinite(sourceHeight) && sourceHeight > 0 ? sourceHeight : undefined,
|
|
363
|
+
};
|
|
364
|
+
}
|