@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,331 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SizeTool = void 0;
|
|
4
|
-
const core_1 = require("@pooder/core");
|
|
5
|
-
const sceneLayoutModel_1 = require("./sceneLayoutModel");
|
|
6
|
-
class SizeTool {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.id = "pooder.kit.size";
|
|
9
|
-
this.metadata = {
|
|
10
|
-
name: "SizeTool",
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
activate(context) {
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.canvasService = context.services.get("CanvasService");
|
|
16
|
-
const configService = context.services.get("ConfigurationService");
|
|
17
|
-
if (!configService)
|
|
18
|
-
return;
|
|
19
|
-
this.ensureDefaults(configService);
|
|
20
|
-
this.emitStateChanged();
|
|
21
|
-
}
|
|
22
|
-
deactivate(_context) {
|
|
23
|
-
this.context = undefined;
|
|
24
|
-
this.canvasService = undefined;
|
|
25
|
-
}
|
|
26
|
-
contribute() {
|
|
27
|
-
return {
|
|
28
|
-
[core_1.ContributionPointIds.TOOLS]: [
|
|
29
|
-
{
|
|
30
|
-
id: this.id,
|
|
31
|
-
name: "Size",
|
|
32
|
-
interaction: "instant",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
[core_1.ContributionPointIds.CONFIGURATIONS]: [
|
|
36
|
-
{
|
|
37
|
-
id: "size.unit",
|
|
38
|
-
type: "select",
|
|
39
|
-
label: "Display Unit",
|
|
40
|
-
options: ["mm", "cm", "in"],
|
|
41
|
-
default: "mm",
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: "size.actualWidthMm",
|
|
45
|
-
type: "number",
|
|
46
|
-
label: "Actual Width (mm)",
|
|
47
|
-
min: 10,
|
|
48
|
-
max: 2000,
|
|
49
|
-
step: 0.1,
|
|
50
|
-
default: 500,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: "size.actualHeightMm",
|
|
54
|
-
type: "number",
|
|
55
|
-
label: "Actual Height (mm)",
|
|
56
|
-
min: 10,
|
|
57
|
-
max: 2000,
|
|
58
|
-
step: 0.1,
|
|
59
|
-
default: 500,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "size.constraintMode",
|
|
63
|
-
type: "select",
|
|
64
|
-
label: "Constraint Mode",
|
|
65
|
-
options: ["free", "lockAspect", "equal"],
|
|
66
|
-
default: "free",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: "size.aspectRatio",
|
|
70
|
-
type: "number",
|
|
71
|
-
label: "Aspect Ratio",
|
|
72
|
-
min: 0.01,
|
|
73
|
-
max: 100,
|
|
74
|
-
step: 0.01,
|
|
75
|
-
default: 1,
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: "size.cutMode",
|
|
79
|
-
type: "select",
|
|
80
|
-
label: "Cut Mode",
|
|
81
|
-
options: ["trim", "outset", "inset"],
|
|
82
|
-
default: "trim",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: "size.cutMarginMm",
|
|
86
|
-
type: "number",
|
|
87
|
-
label: "Cut Margin (mm)",
|
|
88
|
-
min: 0,
|
|
89
|
-
max: 100,
|
|
90
|
-
step: 0.1,
|
|
91
|
-
default: 0,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "size.viewPadding",
|
|
95
|
-
type: "select",
|
|
96
|
-
label: "View Padding",
|
|
97
|
-
options: [0, 10, 20, 40, 60, 100, "2%", "5%", "10%", "15%", "20%"],
|
|
98
|
-
default: 140,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
id: "size.minMm",
|
|
102
|
-
type: "number",
|
|
103
|
-
label: "Min Size (mm)",
|
|
104
|
-
min: 0.1,
|
|
105
|
-
max: 2000,
|
|
106
|
-
step: 0.1,
|
|
107
|
-
default: 10,
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
id: "size.maxMm",
|
|
111
|
-
type: "number",
|
|
112
|
-
label: "Max Size (mm)",
|
|
113
|
-
min: 1,
|
|
114
|
-
max: 10000,
|
|
115
|
-
step: 1,
|
|
116
|
-
default: 2000,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
id: "size.stepMm",
|
|
120
|
-
type: "number",
|
|
121
|
-
label: "Size Step (mm)",
|
|
122
|
-
min: 0.001,
|
|
123
|
-
max: 100,
|
|
124
|
-
step: 0.001,
|
|
125
|
-
default: 0.1,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
[core_1.ContributionPointIds.COMMANDS]: [
|
|
129
|
-
{
|
|
130
|
-
command: "getSizeState",
|
|
131
|
-
title: "Get Size State",
|
|
132
|
-
handler: () => this.getStateForUI(),
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
command: "updateSizeDimensions",
|
|
136
|
-
title: "Update Size Dimensions",
|
|
137
|
-
handler: (input = {}) => this.updateDimensions(input),
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
command: "setSizeConstraintMode",
|
|
141
|
-
title: "Set Size Constraint Mode",
|
|
142
|
-
handler: (mode) => this.setConstraintMode(mode),
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
command: "setSizeDisplayUnit",
|
|
146
|
-
title: "Set Size Display Unit",
|
|
147
|
-
handler: (unit) => this.setUnit(unit),
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
command: "setSizeCut",
|
|
151
|
-
title: "Set Size Cut",
|
|
152
|
-
handler: (cutMode, cutMarginMm = 0) => this.setCut(cutMode, cutMarginMm),
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
command: "getSelectedImageSize",
|
|
156
|
-
title: "Get Selected Image Size",
|
|
157
|
-
handler: (id) => this.getSelectedImageSize(id),
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
getConfigService() {
|
|
163
|
-
return this.context?.services.get("ConfigurationService");
|
|
164
|
-
}
|
|
165
|
-
ensureDefaults(configService) {
|
|
166
|
-
const state = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
167
|
-
configService.update("size.unit", state.unit);
|
|
168
|
-
configService.update("size.actualWidthMm", state.actualWidthMm);
|
|
169
|
-
configService.update("size.actualHeightMm", state.actualHeightMm);
|
|
170
|
-
configService.update("size.constraintMode", state.constraintMode);
|
|
171
|
-
configService.update("size.aspectRatio", state.actualWidthMm / Math.max(0.001, state.actualHeightMm));
|
|
172
|
-
configService.update("size.cutMode", state.cutMode);
|
|
173
|
-
configService.update("size.cutMarginMm", state.cutMarginMm);
|
|
174
|
-
configService.update("size.viewPadding", state.viewPadding);
|
|
175
|
-
configService.update("size.minMm", state.minMm);
|
|
176
|
-
configService.update("size.maxMm", state.maxMm);
|
|
177
|
-
configService.update("size.stepMm", state.stepMm);
|
|
178
|
-
}
|
|
179
|
-
emitStateChanged() {
|
|
180
|
-
const state = this.getStateForUI();
|
|
181
|
-
if (!state)
|
|
182
|
-
return;
|
|
183
|
-
this.context?.eventBus.emit("size:state:changed", state);
|
|
184
|
-
}
|
|
185
|
-
getStateForUI() {
|
|
186
|
-
const configService = this.getConfigService();
|
|
187
|
-
if (!configService)
|
|
188
|
-
return null;
|
|
189
|
-
const state = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
190
|
-
return {
|
|
191
|
-
...state,
|
|
192
|
-
actualWidth: (0, sceneLayoutModel_1.fromMm)(state.actualWidthMm, state.unit),
|
|
193
|
-
actualHeight: (0, sceneLayoutModel_1.fromMm)(state.actualHeightMm, state.unit),
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
updateDimensions(input) {
|
|
197
|
-
const configService = this.getConfigService();
|
|
198
|
-
if (!configService)
|
|
199
|
-
return null;
|
|
200
|
-
const state = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
201
|
-
const inputUnit = (0, sceneLayoutModel_1.normalizeUnit)(input.unit ?? state.unit);
|
|
202
|
-
const changed = input.changed || "both";
|
|
203
|
-
const providedWidthMm = Number.isFinite(input.width)
|
|
204
|
-
? (0, sceneLayoutModel_1.toMm)(Number(input.width), inputUnit)
|
|
205
|
-
: undefined;
|
|
206
|
-
const providedHeightMm = Number.isFinite(input.height)
|
|
207
|
-
? (0, sceneLayoutModel_1.toMm)(Number(input.height), inputUnit)
|
|
208
|
-
: undefined;
|
|
209
|
-
const limits = {
|
|
210
|
-
minMm: state.minMm,
|
|
211
|
-
maxMm: state.maxMm,
|
|
212
|
-
stepMm: state.stepMm,
|
|
213
|
-
};
|
|
214
|
-
let nextWidthMm = providedWidthMm !== undefined ? providedWidthMm : state.actualWidthMm;
|
|
215
|
-
let nextHeightMm = providedHeightMm !== undefined ? providedHeightMm : state.actualHeightMm;
|
|
216
|
-
if (state.constraintMode === "equal") {
|
|
217
|
-
const anchor = changed === "height"
|
|
218
|
-
? nextHeightMm
|
|
219
|
-
: changed === "width"
|
|
220
|
-
? nextWidthMm
|
|
221
|
-
: (providedWidthMm ?? providedHeightMm ?? nextWidthMm);
|
|
222
|
-
nextWidthMm = anchor;
|
|
223
|
-
nextHeightMm = anchor;
|
|
224
|
-
}
|
|
225
|
-
else if (state.constraintMode === "lockAspect") {
|
|
226
|
-
const ratio = Math.max(0.0001, state.aspectRatio);
|
|
227
|
-
if (changed === "height") {
|
|
228
|
-
nextWidthMm = nextHeightMm * ratio;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
nextHeightMm = nextWidthMm / ratio;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm, limits);
|
|
235
|
-
nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm, limits);
|
|
236
|
-
if (state.constraintMode === "equal") {
|
|
237
|
-
const value = Math.max(nextWidthMm, nextHeightMm);
|
|
238
|
-
nextWidthMm = value;
|
|
239
|
-
nextHeightMm = value;
|
|
240
|
-
}
|
|
241
|
-
else if (state.constraintMode === "lockAspect") {
|
|
242
|
-
const ratio = Math.max(0.0001, state.aspectRatio);
|
|
243
|
-
if (changed === "height") {
|
|
244
|
-
nextWidthMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextHeightMm * ratio, limits);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
nextHeightMm = (0, sceneLayoutModel_1.sanitizeMmValue)(nextWidthMm / ratio, limits);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
configService.update("size.actualWidthMm", nextWidthMm);
|
|
251
|
-
configService.update("size.actualHeightMm", nextHeightMm);
|
|
252
|
-
configService.update("size.unit", inputUnit);
|
|
253
|
-
this.emitStateChanged();
|
|
254
|
-
return this.getStateForUI();
|
|
255
|
-
}
|
|
256
|
-
setConstraintMode(modeRaw) {
|
|
257
|
-
const configService = this.getConfigService();
|
|
258
|
-
if (!configService)
|
|
259
|
-
return null;
|
|
260
|
-
const state = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
261
|
-
const mode = (0, sceneLayoutModel_1.normalizeConstraintMode)(modeRaw);
|
|
262
|
-
configService.update("size.constraintMode", mode);
|
|
263
|
-
if (mode === "lockAspect") {
|
|
264
|
-
const ratio = state.actualWidthMm / Math.max(0.001, state.actualHeightMm);
|
|
265
|
-
configService.update("size.aspectRatio", ratio);
|
|
266
|
-
}
|
|
267
|
-
if (mode === "equal") {
|
|
268
|
-
const value = (0, sceneLayoutModel_1.sanitizeMmValue)(Math.max(state.actualWidthMm, state.actualHeightMm), {
|
|
269
|
-
minMm: state.minMm,
|
|
270
|
-
maxMm: state.maxMm,
|
|
271
|
-
stepMm: state.stepMm,
|
|
272
|
-
});
|
|
273
|
-
configService.update("size.actualWidthMm", value);
|
|
274
|
-
configService.update("size.actualHeightMm", value);
|
|
275
|
-
configService.update("size.aspectRatio", 1);
|
|
276
|
-
}
|
|
277
|
-
this.emitStateChanged();
|
|
278
|
-
return this.getStateForUI();
|
|
279
|
-
}
|
|
280
|
-
setUnit(unitRaw) {
|
|
281
|
-
const configService = this.getConfigService();
|
|
282
|
-
if (!configService)
|
|
283
|
-
return null;
|
|
284
|
-
const unit = (0, sceneLayoutModel_1.normalizeUnit)(unitRaw);
|
|
285
|
-
configService.update("size.unit", unit);
|
|
286
|
-
this.emitStateChanged();
|
|
287
|
-
return this.getStateForUI();
|
|
288
|
-
}
|
|
289
|
-
setCut(cutModeRaw, cutMarginMm = 0) {
|
|
290
|
-
const configService = this.getConfigService();
|
|
291
|
-
if (!configService)
|
|
292
|
-
return null;
|
|
293
|
-
const cutMode = (0, sceneLayoutModel_1.normalizeCutMode)(cutModeRaw);
|
|
294
|
-
const margin = Math.max(0, Number(cutMarginMm) || 0);
|
|
295
|
-
configService.update("size.cutMode", cutMode);
|
|
296
|
-
configService.update("size.cutMarginMm", margin);
|
|
297
|
-
this.emitStateChanged();
|
|
298
|
-
return this.getStateForUI();
|
|
299
|
-
}
|
|
300
|
-
getSelectedImageSize(id) {
|
|
301
|
-
const configService = this.getConfigService();
|
|
302
|
-
if (!configService || !this.canvasService)
|
|
303
|
-
return null;
|
|
304
|
-
const sizeState = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
305
|
-
const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, sizeState);
|
|
306
|
-
if (!layout || layout.scale <= 0)
|
|
307
|
-
return null;
|
|
308
|
-
const all = this.canvasService.canvas.getObjects();
|
|
309
|
-
const active = this.canvasService.canvas.getActiveObject();
|
|
310
|
-
const activeId = active?.data?.layerId === "image.user" ? active?.data?.id : null;
|
|
311
|
-
const targetId = id || activeId;
|
|
312
|
-
const target = all.find((obj) => obj?.data?.layerId === "image.user" && obj?.data?.id === targetId) || all.find((obj) => obj?.data?.layerId === "image.user");
|
|
313
|
-
if (!target)
|
|
314
|
-
return null;
|
|
315
|
-
const objectWidthPx = Math.abs((target.width || 0) * (target.scaleX || 1));
|
|
316
|
-
const objectHeightPx = Math.abs((target.height || 0) * (target.scaleY || 1));
|
|
317
|
-
if (objectWidthPx <= 0 || objectHeightPx <= 0)
|
|
318
|
-
return null;
|
|
319
|
-
const widthMm = objectWidthPx / layout.scale;
|
|
320
|
-
const heightMm = objectHeightPx / layout.scale;
|
|
321
|
-
return {
|
|
322
|
-
id: target?.data?.id || null,
|
|
323
|
-
widthMm,
|
|
324
|
-
heightMm,
|
|
325
|
-
width: (0, sceneLayoutModel_1.fromMm)(widthMm, sizeState.unit),
|
|
326
|
-
height: (0, sceneLayoutModel_1.fromMm)(heightMm, sizeState.unit),
|
|
327
|
-
unit: sizeState.unit,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
exports.SizeTool = SizeTool;
|