@pooder/kit 4.3.1 → 5.0.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/.test-dist/src/CanvasService.js +249 -0
- package/.test-dist/src/ViewportSystem.js +75 -0
- package/.test-dist/src/background.js +203 -0
- package/.test-dist/src/bridgeSelection.js +20 -0
- package/.test-dist/src/constraints.js +237 -0
- package/.test-dist/src/coordinate.js +74 -0
- package/.test-dist/src/dieline.js +723 -0
- package/.test-dist/src/edgeScale.js +12 -0
- package/.test-dist/src/feature.js +752 -0
- package/.test-dist/src/featureComplete.js +32 -0
- package/.test-dist/src/film.js +167 -0
- package/.test-dist/src/geometry.js +506 -0
- package/.test-dist/src/image.js +1234 -0
- package/.test-dist/src/index.js +35 -0
- package/.test-dist/src/maskOps.js +270 -0
- package/.test-dist/src/mirror.js +104 -0
- package/.test-dist/src/renderSpec.js +2 -0
- package/.test-dist/src/ruler.js +343 -0
- package/.test-dist/src/sceneLayout.js +99 -0
- package/.test-dist/src/sceneLayoutModel.js +196 -0
- package/.test-dist/src/sceneView.js +40 -0
- package/.test-dist/src/sceneVisibility.js +42 -0
- package/.test-dist/src/size.js +332 -0
- package/.test-dist/src/tracer.js +544 -0
- package/.test-dist/src/units.js +30 -0
- package/.test-dist/src/white-ink.js +829 -0
- package/.test-dist/src/wrappedOffsets.js +33 -0
- package/.test-dist/tests/run.js +94 -0
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +339 -36
- package/dist/index.d.ts +339 -36
- package/dist/index.js +3572 -850
- package/dist/index.mjs +3565 -852
- package/package.json +2 -2
- package/src/CanvasService.ts +300 -96
- package/src/ViewportSystem.ts +92 -92
- package/src/background.ts +230 -230
- package/src/bridgeSelection.ts +17 -0
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +897 -973
- package/src/edgeScale.ts +19 -0
- package/src/feature.ts +83 -30
- package/src/film.ts +194 -194
- package/src/geometry.ts +242 -84
- package/src/image.ts +1582 -512
- package/src/index.ts +14 -10
- package/src/maskOps.ts +326 -0
- package/src/mirror.ts +128 -128
- package/src/renderSpec.ts +18 -0
- package/src/ruler.ts +449 -508
- package/src/sceneLayout.ts +121 -0
- package/src/sceneLayoutModel.ts +335 -0
- package/src/sceneVisibility.ts +49 -0
- package/src/size.ts +379 -0
- package/src/tracer.ts +719 -570
- package/src/units.ts +27 -27
- package/src/white-ink.ts +1018 -373
- package/src/wrappedOffsets.ts +33 -0
- package/tests/run.ts +118 -0
- package/tsconfig.test.json +15 -15
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SceneVisibilityService = void 0;
|
|
4
|
+
class SceneVisibilityService {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.id = "pooder.kit.sceneVisibility";
|
|
7
|
+
this.metadata = {
|
|
8
|
+
name: "SceneVisibilityService",
|
|
9
|
+
};
|
|
10
|
+
this.activeToolId = null;
|
|
11
|
+
this.onToolActivated = (e) => {
|
|
12
|
+
this.activeToolId = e.id;
|
|
13
|
+
this.apply();
|
|
14
|
+
};
|
|
15
|
+
this.onObjectAdded = () => {
|
|
16
|
+
this.apply();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
activate(context) {
|
|
20
|
+
this.canvasService = context.services.get("CanvasService");
|
|
21
|
+
context.eventBus.on("tool:activated", this.onToolActivated);
|
|
22
|
+
context.eventBus.on("object:added", this.onObjectAdded);
|
|
23
|
+
}
|
|
24
|
+
deactivate(context) {
|
|
25
|
+
context.eventBus.off("tool:activated", this.onToolActivated);
|
|
26
|
+
context.eventBus.off("object:added", this.onObjectAdded);
|
|
27
|
+
this.activeToolId = null;
|
|
28
|
+
this.canvasService = undefined;
|
|
29
|
+
}
|
|
30
|
+
apply() {
|
|
31
|
+
if (!this.canvasService)
|
|
32
|
+
return;
|
|
33
|
+
const dielineLayer = this.canvasService.getLayer("dieline-overlay");
|
|
34
|
+
if (dielineLayer) {
|
|
35
|
+
const visible = this.activeToolId !== "pooder.kit.image" &&
|
|
36
|
+
this.activeToolId !== "pooder.kit.white-ink";
|
|
37
|
+
dielineLayer.set({ visible });
|
|
38
|
+
}
|
|
39
|
+
this.canvasService.requestRenderAll();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.SceneVisibilityService = SceneVisibilityService;
|
|
@@ -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("./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) ||
|
|
313
|
+
all.find((obj) => obj?.data?.layerId === "image.user");
|
|
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;
|