@pooder/kit 6.0.1 → 6.1.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.
- package/.test-dist/src/extensions/background/BackgroundTool.js +524 -0
- package/.test-dist/src/extensions/background/index.js +17 -0
- package/.test-dist/src/extensions/dieline/DielineTool.js +748 -0
- package/.test-dist/src/extensions/dieline/commands.js +127 -0
- package/.test-dist/src/extensions/dieline/config.js +107 -0
- package/.test-dist/src/extensions/dieline/index.js +21 -0
- package/.test-dist/src/extensions/dieline/model.js +2 -0
- package/.test-dist/src/extensions/dieline/renderer.js +2 -0
- package/.test-dist/src/extensions/feature/FeatureTool.js +914 -0
- package/.test-dist/src/extensions/feature/index.js +17 -0
- package/.test-dist/src/extensions/film/FilmTool.js +207 -0
- package/.test-dist/src/extensions/film/index.js +17 -0
- package/.test-dist/src/extensions/image/ImageTool.js +1499 -0
- package/.test-dist/src/extensions/image/commands.js +162 -0
- package/.test-dist/src/extensions/image/config.js +129 -0
- package/.test-dist/src/extensions/image/index.js +21 -0
- package/.test-dist/src/extensions/image/model.js +2 -0
- package/.test-dist/src/extensions/image/renderer.js +5 -0
- package/.test-dist/src/extensions/mirror/MirrorTool.js +104 -0
- package/.test-dist/src/extensions/mirror/index.js +17 -0
- package/.test-dist/src/extensions/ruler/RulerTool.js +442 -0
- package/.test-dist/src/extensions/ruler/index.js +17 -0
- package/.test-dist/src/extensions/sceneLayout.js +2 -93
- package/.test-dist/src/extensions/sceneLayoutModel.js +15 -200
- package/.test-dist/src/extensions/size/SizeTool.js +332 -0
- package/.test-dist/src/extensions/size/index.js +17 -0
- package/.test-dist/src/extensions/white-ink/WhiteInkTool.js +1003 -0
- package/.test-dist/src/extensions/white-ink/commands.js +148 -0
- package/.test-dist/src/extensions/white-ink/config.js +31 -0
- package/.test-dist/src/extensions/white-ink/index.js +21 -0
- package/.test-dist/src/extensions/white-ink/model.js +2 -0
- package/.test-dist/src/extensions/white-ink/renderer.js +5 -0
- package/.test-dist/src/services/SceneLayoutService.js +96 -0
- package/.test-dist/src/services/index.js +1 -0
- package/.test-dist/src/shared/constants/layers.js +25 -0
- package/.test-dist/src/shared/imaging/sourceSizeCache.js +82 -0
- package/.test-dist/src/shared/index.js +22 -0
- package/.test-dist/src/shared/runtime/sessionState.js +74 -0
- package/.test-dist/src/shared/runtime/subscriptions.js +30 -0
- package/.test-dist/src/shared/scene/frame.js +34 -0
- package/.test-dist/src/shared/scene/sceneLayoutModel.js +202 -0
- package/.test-dist/tests/run.js +116 -0
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts +390 -367
- package/dist/index.d.ts +390 -367
- package/dist/index.js +5138 -4927
- package/dist/index.mjs +1149 -1977
- package/dist/tracer-PO7CRBYY.mjs +1016 -0
- package/package.json +2 -2
- package/src/extensions/{background.ts → background/BackgroundTool.ts} +33 -50
- package/src/extensions/background/index.ts +1 -0
- package/src/extensions/{dieline.ts → dieline/DielineTool.ts} +14 -218
- package/src/extensions/dieline/commands.ts +109 -0
- package/src/extensions/dieline/config.ts +106 -0
- package/src/extensions/dieline/index.ts +5 -0
- package/src/extensions/dieline/model.ts +1 -0
- package/src/extensions/dieline/renderer.ts +1 -0
- package/src/extensions/{feature.ts → feature/FeatureTool.ts} +27 -21
- package/src/extensions/feature/index.ts +1 -0
- package/src/extensions/{film.ts → film/FilmTool.ts} +36 -48
- package/src/extensions/film/index.ts +1 -0
- package/src/extensions/{image.ts → image/ImageTool.ts} +123 -402
- package/src/extensions/image/commands.ts +176 -0
- package/src/extensions/image/config.ts +128 -0
- package/src/extensions/image/index.ts +5 -0
- package/src/extensions/image/model.ts +1 -0
- package/src/extensions/image/renderer.ts +1 -0
- package/src/extensions/{mirror.ts → mirror/MirrorTool.ts} +1 -1
- package/src/extensions/mirror/index.ts +1 -0
- package/src/extensions/{ruler.ts → ruler/RulerTool.ts} +4 -5
- package/src/extensions/ruler/index.ts +1 -0
- package/src/extensions/sceneLayout.ts +1 -140
- package/src/extensions/sceneLayoutModel.ts +1 -364
- package/src/extensions/{size.ts → size/SizeTool.ts} +7 -6
- package/src/extensions/size/index.ts +1 -0
- package/src/extensions/{white-ink.ts → white-ink/WhiteInkTool.ts} +130 -317
- package/src/extensions/white-ink/commands.ts +157 -0
- package/src/extensions/white-ink/config.ts +30 -0
- package/src/extensions/white-ink/index.ts +5 -0
- package/src/extensions/white-ink/model.ts +1 -0
- package/src/extensions/white-ink/renderer.ts +1 -0
- package/src/services/SceneLayoutService.ts +139 -0
- package/src/services/index.ts +1 -0
- package/src/shared/constants/layers.ts +23 -0
- package/src/shared/imaging/sourceSizeCache.ts +103 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/runtime/sessionState.ts +105 -0
- package/src/shared/runtime/subscriptions.ts +45 -0
- package/src/shared/scene/frame.ts +46 -0
- package/src/shared/scene/sceneLayoutModel.ts +367 -0
- package/tests/run.ts +146 -0
|
@@ -0,0 +1,367 @@
|
|
|
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 "../../extensions/dielineShape";
|
|
11
|
+
import type {
|
|
12
|
+
DielineShape,
|
|
13
|
+
DielineShapeStyle,
|
|
14
|
+
} from "../../extensions/dielineShape";
|
|
15
|
+
|
|
16
|
+
export type SizeConstraintMode = "free" | "lockAspect" | "equal";
|
|
17
|
+
export type CutMode = "trim" | "outset" | "inset";
|
|
18
|
+
|
|
19
|
+
export interface SizeState {
|
|
20
|
+
unit: Unit;
|
|
21
|
+
actualWidthMm: number;
|
|
22
|
+
actualHeightMm: number;
|
|
23
|
+
constraintMode: SizeConstraintMode;
|
|
24
|
+
aspectRatio: number;
|
|
25
|
+
cutMode: CutMode;
|
|
26
|
+
cutMarginMm: number;
|
|
27
|
+
viewPadding: number | string;
|
|
28
|
+
minMm: number;
|
|
29
|
+
maxMm: number;
|
|
30
|
+
stepMm: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SceneRect {
|
|
34
|
+
left: number;
|
|
35
|
+
top: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
centerX: number;
|
|
39
|
+
centerY: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SceneLayoutSnapshot {
|
|
43
|
+
scale: number;
|
|
44
|
+
canvasWidth: number;
|
|
45
|
+
canvasHeight: number;
|
|
46
|
+
trimRect: SceneRect;
|
|
47
|
+
cutRect: SceneRect;
|
|
48
|
+
bleedRect: SceneRect;
|
|
49
|
+
trimWidthMm: number;
|
|
50
|
+
trimHeightMm: number;
|
|
51
|
+
cutWidthMm: number;
|
|
52
|
+
cutHeightMm: number;
|
|
53
|
+
cutMode: CutMode;
|
|
54
|
+
cutMarginMm: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SceneGeometrySnapshot {
|
|
58
|
+
shape: DielineShape;
|
|
59
|
+
shapeStyle: DielineShapeStyle;
|
|
60
|
+
unit: "px";
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
radius: number;
|
|
66
|
+
offset: number;
|
|
67
|
+
scale: number;
|
|
68
|
+
pathData?: string;
|
|
69
|
+
customSourceWidthPx?: number;
|
|
70
|
+
customSourceHeightPx?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const DEFAULT_SIZE_STATE: SizeState = {
|
|
74
|
+
unit: "mm",
|
|
75
|
+
actualWidthMm: 500,
|
|
76
|
+
actualHeightMm: 500,
|
|
77
|
+
constraintMode: "free",
|
|
78
|
+
aspectRatio: 1,
|
|
79
|
+
cutMode: "trim",
|
|
80
|
+
cutMarginMm: 0,
|
|
81
|
+
viewPadding: 140,
|
|
82
|
+
minMm: 10,
|
|
83
|
+
maxMm: 2000,
|
|
84
|
+
stepMm: 0.1,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function clamp(value: number, min: number, max: number): number {
|
|
88
|
+
return Math.max(min, Math.min(max, value));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function roundToStep(value: number, step: number): number {
|
|
92
|
+
if (!Number.isFinite(step) || step <= 0) return value;
|
|
93
|
+
return Math.round(value / step) * step;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function sanitizeMmValue(
|
|
97
|
+
valueMm: number,
|
|
98
|
+
limits: { minMm: number; maxMm: number; stepMm: number },
|
|
99
|
+
): number {
|
|
100
|
+
if (!Number.isFinite(valueMm)) return limits.minMm;
|
|
101
|
+
const rounded = roundToStep(valueMm, limits.stepMm);
|
|
102
|
+
return clamp(rounded, limits.minMm, limits.maxMm);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function normalizeUnit(value: unknown): Unit {
|
|
106
|
+
if (value === "cm" || value === "in") return value;
|
|
107
|
+
return "mm";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function normalizeConstraintMode(value: unknown): SizeConstraintMode {
|
|
111
|
+
if (value === "lockAspect" || value === "equal") return value;
|
|
112
|
+
return "free";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function normalizeCutMode(value: unknown): CutMode {
|
|
116
|
+
if (value === "outset" || value === "inset") return value;
|
|
117
|
+
return "trim";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function toMm(value: number, fromUnit: Unit): number {
|
|
121
|
+
return Coordinate.convertUnit(value, fromUnit, "mm");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function fromMm(valueMm: number, toUnit: Unit): number {
|
|
125
|
+
return Coordinate.convertUnit(valueMm, "mm", toUnit);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function resolvePaddingPx(
|
|
129
|
+
raw: number | string,
|
|
130
|
+
containerWidth: number,
|
|
131
|
+
containerHeight: number,
|
|
132
|
+
): number {
|
|
133
|
+
if (typeof raw === "number") return Math.max(0, raw);
|
|
134
|
+
if (typeof raw === "string") {
|
|
135
|
+
if (raw.endsWith("%")) {
|
|
136
|
+
const percent = parseFloat(raw) / 100;
|
|
137
|
+
if (!Number.isFinite(percent)) return 0;
|
|
138
|
+
return Math.max(0, Math.min(containerWidth, containerHeight) * percent);
|
|
139
|
+
}
|
|
140
|
+
const fixed = parseFloat(raw);
|
|
141
|
+
return Number.isFinite(fixed) ? Math.max(0, fixed) : 0;
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function readSizeState(configService: ConfigurationService): SizeState {
|
|
147
|
+
const unit = normalizeUnit(
|
|
148
|
+
configService.get("size.unit", DEFAULT_SIZE_STATE.unit),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const minMm = Math.max(
|
|
152
|
+
0.1,
|
|
153
|
+
Number(configService.get("size.minMm", DEFAULT_SIZE_STATE.minMm)),
|
|
154
|
+
);
|
|
155
|
+
const maxMm = Math.max(
|
|
156
|
+
minMm,
|
|
157
|
+
Number(configService.get("size.maxMm", DEFAULT_SIZE_STATE.maxMm)),
|
|
158
|
+
);
|
|
159
|
+
const stepMm = Math.max(
|
|
160
|
+
0.001,
|
|
161
|
+
Number(configService.get("size.stepMm", DEFAULT_SIZE_STATE.stepMm)),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const actualWidthMm = sanitizeMmValue(
|
|
165
|
+
parseLengthToMm(
|
|
166
|
+
configService.get("size.actualWidthMm", DEFAULT_SIZE_STATE.actualWidthMm),
|
|
167
|
+
"mm",
|
|
168
|
+
),
|
|
169
|
+
{ minMm, maxMm, stepMm },
|
|
170
|
+
);
|
|
171
|
+
const actualHeightMm = sanitizeMmValue(
|
|
172
|
+
parseLengthToMm(
|
|
173
|
+
configService.get(
|
|
174
|
+
"size.actualHeightMm",
|
|
175
|
+
DEFAULT_SIZE_STATE.actualHeightMm,
|
|
176
|
+
),
|
|
177
|
+
"mm",
|
|
178
|
+
),
|
|
179
|
+
{ minMm, maxMm, stepMm },
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const aspectRaw = Number(
|
|
183
|
+
configService.get("size.aspectRatio", DEFAULT_SIZE_STATE.aspectRatio),
|
|
184
|
+
);
|
|
185
|
+
const aspectRatio =
|
|
186
|
+
Number.isFinite(aspectRaw) && aspectRaw > 0
|
|
187
|
+
? aspectRaw
|
|
188
|
+
: actualWidthMm / Math.max(0.001, actualHeightMm);
|
|
189
|
+
|
|
190
|
+
const cutMarginMm = Math.max(
|
|
191
|
+
0,
|
|
192
|
+
parseLengthToMm(
|
|
193
|
+
configService.get("size.cutMarginMm", DEFAULT_SIZE_STATE.cutMarginMm),
|
|
194
|
+
"mm",
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const viewPadding = configService.get(
|
|
199
|
+
"size.viewPadding",
|
|
200
|
+
DEFAULT_SIZE_STATE.viewPadding,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
unit,
|
|
205
|
+
actualWidthMm,
|
|
206
|
+
actualHeightMm,
|
|
207
|
+
constraintMode: normalizeConstraintMode(
|
|
208
|
+
configService.get(
|
|
209
|
+
"size.constraintMode",
|
|
210
|
+
DEFAULT_SIZE_STATE.constraintMode,
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
aspectRatio,
|
|
214
|
+
cutMode: normalizeCutMode(
|
|
215
|
+
configService.get("size.cutMode", DEFAULT_SIZE_STATE.cutMode),
|
|
216
|
+
),
|
|
217
|
+
cutMarginMm,
|
|
218
|
+
viewPadding,
|
|
219
|
+
minMm,
|
|
220
|
+
maxMm,
|
|
221
|
+
stepMm,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function rectByCenter(
|
|
226
|
+
centerX: number,
|
|
227
|
+
centerY: number,
|
|
228
|
+
width: number,
|
|
229
|
+
height: number,
|
|
230
|
+
): SceneRect {
|
|
231
|
+
return {
|
|
232
|
+
left: centerX - width / 2,
|
|
233
|
+
top: centerY - height / 2,
|
|
234
|
+
width,
|
|
235
|
+
height,
|
|
236
|
+
centerX,
|
|
237
|
+
centerY,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function getCutSizeMm(size: SizeState): { widthMm: number; heightMm: number } {
|
|
242
|
+
if (size.cutMode === "trim") {
|
|
243
|
+
return { widthMm: size.actualWidthMm, heightMm: size.actualHeightMm };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const delta = size.cutMarginMm * 2;
|
|
247
|
+
if (size.cutMode === "outset") {
|
|
248
|
+
return {
|
|
249
|
+
widthMm: size.actualWidthMm + delta,
|
|
250
|
+
heightMm: size.actualHeightMm + delta,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
widthMm: Math.max(size.minMm, size.actualWidthMm - delta),
|
|
256
|
+
heightMm: Math.max(size.minMm, size.actualHeightMm - delta),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function computeSceneLayout(
|
|
261
|
+
canvasService: CanvasService,
|
|
262
|
+
size: SizeState,
|
|
263
|
+
): SceneLayoutSnapshot | null {
|
|
264
|
+
const canvasWidth = canvasService.canvas.width || 0;
|
|
265
|
+
const canvasHeight = canvasService.canvas.height || 0;
|
|
266
|
+
if (canvasWidth <= 0 || canvasHeight <= 0) return null;
|
|
267
|
+
|
|
268
|
+
const { widthMm: cutWidthMm, heightMm: cutHeightMm } = getCutSizeMm(size);
|
|
269
|
+
const viewWidthMm = Math.max(size.actualWidthMm, cutWidthMm);
|
|
270
|
+
const viewHeightMm = Math.max(size.actualHeightMm, cutHeightMm);
|
|
271
|
+
if (
|
|
272
|
+
!Number.isFinite(viewWidthMm) ||
|
|
273
|
+
!Number.isFinite(viewHeightMm) ||
|
|
274
|
+
viewWidthMm <= 0 ||
|
|
275
|
+
viewHeightMm <= 0
|
|
276
|
+
) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const paddingPx = resolvePaddingPx(
|
|
281
|
+
size.viewPadding,
|
|
282
|
+
canvasWidth,
|
|
283
|
+
canvasHeight,
|
|
284
|
+
);
|
|
285
|
+
canvasService.viewport.updateContainer(canvasWidth, canvasHeight);
|
|
286
|
+
canvasService.viewport.setPadding(paddingPx);
|
|
287
|
+
canvasService.viewport.updatePhysical(viewWidthMm, viewHeightMm);
|
|
288
|
+
|
|
289
|
+
const layout = canvasService.viewport.layout;
|
|
290
|
+
if (
|
|
291
|
+
!Number.isFinite(layout.scale) ||
|
|
292
|
+
!Number.isFinite(layout.offsetX) ||
|
|
293
|
+
!Number.isFinite(layout.offsetY) ||
|
|
294
|
+
layout.scale <= 0
|
|
295
|
+
) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const centerX = layout.offsetX + layout.width / 2;
|
|
300
|
+
const centerY = layout.offsetY + layout.height / 2;
|
|
301
|
+
const trimWidthPx = size.actualWidthMm * layout.scale;
|
|
302
|
+
const trimHeightPx = size.actualHeightMm * layout.scale;
|
|
303
|
+
const cutWidthPx = cutWidthMm * layout.scale;
|
|
304
|
+
const cutHeightPx = cutHeightMm * layout.scale;
|
|
305
|
+
|
|
306
|
+
const trimRect = rectByCenter(centerX, centerY, trimWidthPx, trimHeightPx);
|
|
307
|
+
const cutRect = rectByCenter(centerX, centerY, cutWidthPx, cutHeightPx);
|
|
308
|
+
const bleedRect = rectByCenter(
|
|
309
|
+
centerX,
|
|
310
|
+
centerY,
|
|
311
|
+
Math.max(trimWidthPx, cutWidthPx),
|
|
312
|
+
Math.max(trimHeightPx, cutHeightPx),
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
scale: layout.scale,
|
|
317
|
+
canvasWidth,
|
|
318
|
+
canvasHeight,
|
|
319
|
+
trimRect,
|
|
320
|
+
cutRect,
|
|
321
|
+
bleedRect,
|
|
322
|
+
trimWidthMm: size.actualWidthMm,
|
|
323
|
+
trimHeightMm: size.actualHeightMm,
|
|
324
|
+
cutWidthMm,
|
|
325
|
+
cutHeightMm,
|
|
326
|
+
cutMode: size.cutMode,
|
|
327
|
+
cutMarginMm: size.cutMarginMm,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function buildSceneGeometry(
|
|
332
|
+
configService: ConfigurationService,
|
|
333
|
+
layout: SceneLayoutSnapshot,
|
|
334
|
+
): SceneGeometrySnapshot {
|
|
335
|
+
const radiusMm = parseLengthToMm(
|
|
336
|
+
configService.get("dieline.radius", 0),
|
|
337
|
+
"mm",
|
|
338
|
+
);
|
|
339
|
+
const offset = (layout.cutRect.width - layout.trimRect.width) / 2;
|
|
340
|
+
const sourceWidth = Number(configService.get("dieline.customSourceWidthPx", 0));
|
|
341
|
+
const sourceHeight = Number(
|
|
342
|
+
configService.get("dieline.customSourceHeightPx", 0),
|
|
343
|
+
);
|
|
344
|
+
const shapeStyle = normalizeShapeStyle(
|
|
345
|
+
configService.get("dieline.shapeStyle", DEFAULT_DIELINE_SHAPE_STYLE),
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
shape: normalizeDielineShape(
|
|
350
|
+
configService.get("dieline.shape", DEFAULT_DIELINE_SHAPE),
|
|
351
|
+
),
|
|
352
|
+
shapeStyle,
|
|
353
|
+
unit: "px",
|
|
354
|
+
x: layout.trimRect.centerX,
|
|
355
|
+
y: layout.trimRect.centerY,
|
|
356
|
+
width: layout.trimRect.width,
|
|
357
|
+
height: layout.trimRect.height,
|
|
358
|
+
radius: radiusMm * layout.scale,
|
|
359
|
+
offset,
|
|
360
|
+
scale: layout.scale,
|
|
361
|
+
pathData: configService.get("dieline.pathData"),
|
|
362
|
+
customSourceWidthPx:
|
|
363
|
+
Number.isFinite(sourceWidth) && sourceWidth > 0 ? sourceWidth : undefined,
|
|
364
|
+
customSourceHeightPx:
|
|
365
|
+
Number.isFinite(sourceHeight) && sourceHeight > 0 ? sourceHeight : undefined,
|
|
366
|
+
};
|
|
367
|
+
}
|
package/tests/run.ts
CHANGED
|
@@ -15,6 +15,12 @@ import {
|
|
|
15
15
|
} from "../src/extensions/maskOps";
|
|
16
16
|
import { computeDetectEdgeSize } from "../src/extensions/edgeScale";
|
|
17
17
|
import { evaluateVisibilityExpr } from "../src/services/visibility";
|
|
18
|
+
import { createImageCommands } from "../src/extensions/image/commands";
|
|
19
|
+
import { createImageConfigurations } from "../src/extensions/image/config";
|
|
20
|
+
import { createWhiteInkCommands } from "../src/extensions/white-ink/commands";
|
|
21
|
+
import { createWhiteInkConfigurations } from "../src/extensions/white-ink/config";
|
|
22
|
+
import { createDielineCommands } from "../src/extensions/dieline/commands";
|
|
23
|
+
import { createDielineConfigurations } from "../src/extensions/dieline/config";
|
|
18
24
|
|
|
19
25
|
function assert(condition: unknown, message: string) {
|
|
20
26
|
if (!condition) throw new Error(message);
|
|
@@ -246,12 +252,152 @@ function testVisibilityDsl() {
|
|
|
246
252
|
);
|
|
247
253
|
}
|
|
248
254
|
|
|
255
|
+
function testContributionCompatibility() {
|
|
256
|
+
const imageCommandNames = createImageCommands({} as any).map(
|
|
257
|
+
(entry) => entry.command,
|
|
258
|
+
);
|
|
259
|
+
const whiteInkCommandNames = createWhiteInkCommands({} as any).map(
|
|
260
|
+
(entry) => entry.command,
|
|
261
|
+
);
|
|
262
|
+
const dielineCommandNames = createDielineCommands({} as any, {
|
|
263
|
+
width: 0,
|
|
264
|
+
height: 0,
|
|
265
|
+
}).map((entry) => entry.command);
|
|
266
|
+
|
|
267
|
+
const expectedImageCommands = [
|
|
268
|
+
"addImage",
|
|
269
|
+
"upsertImage",
|
|
270
|
+
"getWorkingImages",
|
|
271
|
+
"setWorkingImage",
|
|
272
|
+
"resetWorkingImages",
|
|
273
|
+
"completeImages",
|
|
274
|
+
"exportUserCroppedImage",
|
|
275
|
+
"fitImageToArea",
|
|
276
|
+
"fitImageToDefaultArea",
|
|
277
|
+
"focusImage",
|
|
278
|
+
"removeImage",
|
|
279
|
+
"updateImage",
|
|
280
|
+
"clearImages",
|
|
281
|
+
"bringToFront",
|
|
282
|
+
"sendToBack",
|
|
283
|
+
];
|
|
284
|
+
const expectedWhiteInkCommands = [
|
|
285
|
+
"addWhiteInk",
|
|
286
|
+
"upsertWhiteInk",
|
|
287
|
+
"getWhiteInks",
|
|
288
|
+
"getWhiteInkSettings",
|
|
289
|
+
"setWhiteInkPrintEnabled",
|
|
290
|
+
"setWhiteInkPreviewImageVisible",
|
|
291
|
+
"getWorkingWhiteInks",
|
|
292
|
+
"setWorkingWhiteInk",
|
|
293
|
+
"updateWhiteInk",
|
|
294
|
+
"removeWhiteInk",
|
|
295
|
+
"clearWhiteInks",
|
|
296
|
+
"resetWorkingWhiteInks",
|
|
297
|
+
"completeWhiteInks",
|
|
298
|
+
"setWhiteInkImage",
|
|
299
|
+
];
|
|
300
|
+
const expectedDielineCommands = [
|
|
301
|
+
"updateFeaturePosition",
|
|
302
|
+
"exportCutImage",
|
|
303
|
+
"detectEdge",
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
assert(
|
|
307
|
+
JSON.stringify(imageCommandNames) === JSON.stringify(expectedImageCommands),
|
|
308
|
+
`image command set changed: ${JSON.stringify(imageCommandNames)}`,
|
|
309
|
+
);
|
|
310
|
+
assert(
|
|
311
|
+
JSON.stringify(whiteInkCommandNames) ===
|
|
312
|
+
JSON.stringify(expectedWhiteInkCommands),
|
|
313
|
+
`white-ink command set changed: ${JSON.stringify(whiteInkCommandNames)}`,
|
|
314
|
+
);
|
|
315
|
+
assert(
|
|
316
|
+
JSON.stringify(dielineCommandNames) ===
|
|
317
|
+
JSON.stringify(expectedDielineCommands),
|
|
318
|
+
`dieline command set changed: ${JSON.stringify(dielineCommandNames)}`,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const imageConfigKeys = createImageConfigurations().map((entry) => entry.id);
|
|
322
|
+
const whiteInkConfigKeys = createWhiteInkConfigurations().map(
|
|
323
|
+
(entry) => entry.id,
|
|
324
|
+
);
|
|
325
|
+
const dielineConfigKeys = createDielineConfigurations({
|
|
326
|
+
shape: "rect",
|
|
327
|
+
radius: 0,
|
|
328
|
+
shapeStyle: {},
|
|
329
|
+
showBleedLines: true,
|
|
330
|
+
mainLine: { width: 1, color: "#000", dashLength: 1, style: "solid" },
|
|
331
|
+
offsetLine: { width: 1, color: "#000", dashLength: 1, style: "solid" },
|
|
332
|
+
insideColor: "#000",
|
|
333
|
+
features: [],
|
|
334
|
+
}).map((entry) => entry.id);
|
|
335
|
+
|
|
336
|
+
const expectedImageConfigKeys = [
|
|
337
|
+
"image.items",
|
|
338
|
+
"image.debug",
|
|
339
|
+
"image.control.cornerSize",
|
|
340
|
+
"image.control.touchCornerSize",
|
|
341
|
+
"image.control.cornerStyle",
|
|
342
|
+
"image.control.cornerColor",
|
|
343
|
+
"image.control.cornerStrokeColor",
|
|
344
|
+
"image.control.transparentCorners",
|
|
345
|
+
"image.control.borderColor",
|
|
346
|
+
"image.control.borderScaleFactor",
|
|
347
|
+
"image.control.padding",
|
|
348
|
+
"image.frame.strokeColor",
|
|
349
|
+
"image.frame.strokeWidth",
|
|
350
|
+
"image.frame.strokeStyle",
|
|
351
|
+
"image.frame.dashLength",
|
|
352
|
+
"image.frame.innerBackground",
|
|
353
|
+
"image.frame.outerBackground",
|
|
354
|
+
];
|
|
355
|
+
const expectedWhiteInkConfigKeys = [
|
|
356
|
+
"whiteInk.items",
|
|
357
|
+
"whiteInk.printWithWhiteInk",
|
|
358
|
+
"whiteInk.previewImageVisible",
|
|
359
|
+
"whiteInk.debug",
|
|
360
|
+
];
|
|
361
|
+
const expectedDielineConfigKeys = [
|
|
362
|
+
"dieline.shape",
|
|
363
|
+
"dieline.radius",
|
|
364
|
+
"dieline.shapeStyle",
|
|
365
|
+
"dieline.showBleedLines",
|
|
366
|
+
"dieline.strokeWidth",
|
|
367
|
+
"dieline.strokeColor",
|
|
368
|
+
"dieline.dashLength",
|
|
369
|
+
"dieline.style",
|
|
370
|
+
"dieline.offsetStrokeWidth",
|
|
371
|
+
"dieline.offsetStrokeColor",
|
|
372
|
+
"dieline.offsetDashLength",
|
|
373
|
+
"dieline.offsetStyle",
|
|
374
|
+
"dieline.insideColor",
|
|
375
|
+
"dieline.features",
|
|
376
|
+
];
|
|
377
|
+
|
|
378
|
+
assert(
|
|
379
|
+
JSON.stringify(imageConfigKeys) === JSON.stringify(expectedImageConfigKeys),
|
|
380
|
+
`image config keys changed: ${JSON.stringify(imageConfigKeys)}`,
|
|
381
|
+
);
|
|
382
|
+
assert(
|
|
383
|
+
JSON.stringify(whiteInkConfigKeys) ===
|
|
384
|
+
JSON.stringify(expectedWhiteInkConfigKeys),
|
|
385
|
+
`white-ink config keys changed: ${JSON.stringify(whiteInkConfigKeys)}`,
|
|
386
|
+
);
|
|
387
|
+
assert(
|
|
388
|
+
JSON.stringify(dielineConfigKeys) ===
|
|
389
|
+
JSON.stringify(expectedDielineConfigKeys),
|
|
390
|
+
`dieline config keys changed: ${JSON.stringify(dielineConfigKeys)}`,
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
249
394
|
function main() {
|
|
250
395
|
testWrappedOffsets();
|
|
251
396
|
testBridgeSelection();
|
|
252
397
|
testMaskOps();
|
|
253
398
|
testEdgeScale();
|
|
254
399
|
testVisibilityDsl();
|
|
400
|
+
testContributionCompatibility();
|
|
255
401
|
console.log("ok");
|
|
256
402
|
}
|
|
257
403
|
|