@pooder/kit 4.3.0 → 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 +17 -0
- package/dist/index.d.mts +339 -36
- package/dist/index.d.ts +339 -36
- package/dist/index.js +3587 -854
- package/dist/index.mjs +3580 -856
- 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 -955
- package/src/edgeScale.ts +19 -0
- package/src/feature.ts +83 -30
- package/src/film.ts +194 -194
- package/src/geometry.ts +234 -80
- 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,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RulerTool = void 0;
|
|
4
|
+
const core_1 = require("@pooder/core");
|
|
5
|
+
const fabric_1 = require("fabric");
|
|
6
|
+
const units_1 = require("./units");
|
|
7
|
+
const sceneLayoutModel_1 = require("./sceneLayoutModel");
|
|
8
|
+
class RulerTool {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.id = "pooder.kit.ruler";
|
|
11
|
+
this.metadata = {
|
|
12
|
+
name: "RulerTool",
|
|
13
|
+
};
|
|
14
|
+
this.thickness = 20;
|
|
15
|
+
this.gap = 15;
|
|
16
|
+
this.backgroundColor = "#f0f0f0";
|
|
17
|
+
this.textColor = "#333333";
|
|
18
|
+
this.lineColor = "#999999";
|
|
19
|
+
this.fontSize = 10;
|
|
20
|
+
this.onCanvasResized = () => {
|
|
21
|
+
this.updateRuler();
|
|
22
|
+
};
|
|
23
|
+
if (options) {
|
|
24
|
+
Object.assign(this, options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
activate(context) {
|
|
28
|
+
this.context = context;
|
|
29
|
+
this.canvasService = context.services.get("CanvasService");
|
|
30
|
+
if (!this.canvasService) {
|
|
31
|
+
console.warn("CanvasService not found for RulerTool");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const configService = context.services.get("ConfigurationService");
|
|
35
|
+
if (configService) {
|
|
36
|
+
// Load initial config
|
|
37
|
+
this.thickness = configService.get("ruler.thickness", this.thickness);
|
|
38
|
+
this.gap = configService.get("ruler.gap", this.gap);
|
|
39
|
+
this.backgroundColor = configService.get("ruler.backgroundColor", this.backgroundColor);
|
|
40
|
+
this.textColor = configService.get("ruler.textColor", this.textColor);
|
|
41
|
+
this.lineColor = configService.get("ruler.lineColor", this.lineColor);
|
|
42
|
+
this.fontSize = configService.get("ruler.fontSize", this.fontSize);
|
|
43
|
+
// Listen for changes
|
|
44
|
+
configService.onAnyChange((e) => {
|
|
45
|
+
let shouldUpdate = false;
|
|
46
|
+
if (e.key.startsWith("ruler.")) {
|
|
47
|
+
const prop = e.key.split(".")[1];
|
|
48
|
+
if (prop && prop in this) {
|
|
49
|
+
this[prop] = e.value;
|
|
50
|
+
shouldUpdate = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (e.key.startsWith("size.")) {
|
|
54
|
+
shouldUpdate = true;
|
|
55
|
+
}
|
|
56
|
+
if (shouldUpdate) {
|
|
57
|
+
this.updateRuler();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
this.createLayer();
|
|
62
|
+
context.eventBus.on("canvas:resized", this.onCanvasResized);
|
|
63
|
+
this.updateRuler();
|
|
64
|
+
}
|
|
65
|
+
deactivate(context) {
|
|
66
|
+
context.eventBus.off("canvas:resized", this.onCanvasResized);
|
|
67
|
+
this.destroyLayer();
|
|
68
|
+
this.canvasService = undefined;
|
|
69
|
+
this.context = undefined;
|
|
70
|
+
}
|
|
71
|
+
contribute() {
|
|
72
|
+
return {
|
|
73
|
+
[core_1.ContributionPointIds.CONFIGURATIONS]: [
|
|
74
|
+
{
|
|
75
|
+
id: "ruler.thickness",
|
|
76
|
+
type: "number",
|
|
77
|
+
label: "Thickness",
|
|
78
|
+
min: 10,
|
|
79
|
+
max: 100,
|
|
80
|
+
default: 20,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "ruler.gap",
|
|
84
|
+
type: "number",
|
|
85
|
+
label: "Gap",
|
|
86
|
+
min: 0,
|
|
87
|
+
max: 100,
|
|
88
|
+
default: 15,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "ruler.backgroundColor",
|
|
92
|
+
type: "color",
|
|
93
|
+
label: "Background Color",
|
|
94
|
+
default: "#f0f0f0",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "ruler.textColor",
|
|
98
|
+
type: "color",
|
|
99
|
+
label: "Text Color",
|
|
100
|
+
default: "#333333",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "ruler.lineColor",
|
|
104
|
+
type: "color",
|
|
105
|
+
label: "Line Color",
|
|
106
|
+
default: "#999999",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "ruler.fontSize",
|
|
110
|
+
type: "number",
|
|
111
|
+
label: "Font Size",
|
|
112
|
+
min: 8,
|
|
113
|
+
max: 24,
|
|
114
|
+
default: 10,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
[core_1.ContributionPointIds.COMMANDS]: [
|
|
118
|
+
{
|
|
119
|
+
command: "setTheme",
|
|
120
|
+
title: "Set Ruler Theme",
|
|
121
|
+
handler: (theme) => {
|
|
122
|
+
const oldState = {
|
|
123
|
+
backgroundColor: this.backgroundColor,
|
|
124
|
+
textColor: this.textColor,
|
|
125
|
+
lineColor: this.lineColor,
|
|
126
|
+
fontSize: this.fontSize,
|
|
127
|
+
thickness: this.thickness,
|
|
128
|
+
};
|
|
129
|
+
const newState = { ...oldState, ...theme };
|
|
130
|
+
if (JSON.stringify(newState) === JSON.stringify(oldState))
|
|
131
|
+
return true;
|
|
132
|
+
Object.assign(this, newState);
|
|
133
|
+
this.updateRuler();
|
|
134
|
+
return true;
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
getLayer() {
|
|
141
|
+
return this.canvasService?.getLayer("ruler-overlay");
|
|
142
|
+
}
|
|
143
|
+
createLayer() {
|
|
144
|
+
if (!this.canvasService)
|
|
145
|
+
return;
|
|
146
|
+
const canvas = this.canvasService.canvas;
|
|
147
|
+
const width = canvas.width || 800;
|
|
148
|
+
const height = canvas.height || 600;
|
|
149
|
+
const layer = this.canvasService.createLayer("ruler-overlay", {
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
selectable: false,
|
|
153
|
+
evented: false,
|
|
154
|
+
left: 0,
|
|
155
|
+
top: 0,
|
|
156
|
+
originX: "left",
|
|
157
|
+
originY: "top",
|
|
158
|
+
});
|
|
159
|
+
canvas.bringObjectToFront(layer);
|
|
160
|
+
}
|
|
161
|
+
destroyLayer() {
|
|
162
|
+
if (!this.canvasService)
|
|
163
|
+
return;
|
|
164
|
+
const layer = this.getLayer();
|
|
165
|
+
if (layer) {
|
|
166
|
+
this.canvasService.canvas.remove(layer);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
createArrowLine(x1, y1, x2, y2, color) {
|
|
170
|
+
const line = new fabric_1.Line([x1, y1, x2, y2], {
|
|
171
|
+
stroke: color,
|
|
172
|
+
strokeWidth: this.thickness / 20, // Scale stroke width relative to thickness (default 1)
|
|
173
|
+
selectable: false,
|
|
174
|
+
evented: false,
|
|
175
|
+
});
|
|
176
|
+
// Arrow size proportional to thickness
|
|
177
|
+
const arrowSize = Math.max(4, this.thickness * 0.3);
|
|
178
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
179
|
+
// End Arrow (at x2, y2)
|
|
180
|
+
const endArrow = new fabric_1.Polygon([
|
|
181
|
+
{ x: 0, y: 0 },
|
|
182
|
+
{ x: -arrowSize, y: -arrowSize / 2 },
|
|
183
|
+
{ x: -arrowSize, y: arrowSize / 2 },
|
|
184
|
+
], {
|
|
185
|
+
fill: color,
|
|
186
|
+
left: x2,
|
|
187
|
+
top: y2,
|
|
188
|
+
originX: "right",
|
|
189
|
+
originY: "center",
|
|
190
|
+
angle: (angle * 180) / Math.PI,
|
|
191
|
+
selectable: false,
|
|
192
|
+
evented: false,
|
|
193
|
+
});
|
|
194
|
+
// Start Arrow (at x1, y1)
|
|
195
|
+
const startArrow = new fabric_1.Polygon([
|
|
196
|
+
{ x: 0, y: 0 },
|
|
197
|
+
{ x: arrowSize, y: -arrowSize / 2 },
|
|
198
|
+
{ x: arrowSize, y: arrowSize / 2 },
|
|
199
|
+
], {
|
|
200
|
+
fill: color,
|
|
201
|
+
left: x1,
|
|
202
|
+
top: y1,
|
|
203
|
+
originX: "left",
|
|
204
|
+
originY: "center",
|
|
205
|
+
angle: (angle * 180) / Math.PI,
|
|
206
|
+
selectable: false,
|
|
207
|
+
evented: false,
|
|
208
|
+
});
|
|
209
|
+
return new fabric_1.Group([line, startArrow, endArrow], {
|
|
210
|
+
selectable: false,
|
|
211
|
+
evented: false,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
updateRuler() {
|
|
215
|
+
if (!this.canvasService)
|
|
216
|
+
return;
|
|
217
|
+
const layer = this.getLayer();
|
|
218
|
+
if (!layer)
|
|
219
|
+
return;
|
|
220
|
+
layer.remove(...layer.getObjects());
|
|
221
|
+
const { backgroundColor, lineColor, textColor, fontSize } = this;
|
|
222
|
+
const configService = this.context?.services.get("ConfigurationService");
|
|
223
|
+
if (!configService)
|
|
224
|
+
return;
|
|
225
|
+
const sizeState = (0, sceneLayoutModel_1.readSizeState)(configService);
|
|
226
|
+
const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, sizeState);
|
|
227
|
+
if (!layout)
|
|
228
|
+
return;
|
|
229
|
+
const trimRect = layout.trimRect;
|
|
230
|
+
const cutRect = layout.cutRect;
|
|
231
|
+
const useCutAsRuler = layout.cutMode === "outset";
|
|
232
|
+
const rulerRect = useCutAsRuler ? cutRect : trimRect;
|
|
233
|
+
// Use gap configuration
|
|
234
|
+
const gap = this.gap || 15;
|
|
235
|
+
// New Bounding Box for Ruler
|
|
236
|
+
const rulerLeft = rulerRect.left;
|
|
237
|
+
const rulerTop = rulerRect.top;
|
|
238
|
+
const rulerRight = rulerRect.left + rulerRect.width;
|
|
239
|
+
const rulerBottom = rulerRect.top + rulerRect.height;
|
|
240
|
+
// Display Dimensions (Physical)
|
|
241
|
+
const displayWidthMm = useCutAsRuler ? layout.cutWidthMm : layout.trimWidthMm;
|
|
242
|
+
const displayHeightMm = useCutAsRuler
|
|
243
|
+
? layout.cutHeightMm
|
|
244
|
+
: layout.trimHeightMm;
|
|
245
|
+
const displayUnit = sizeState.unit;
|
|
246
|
+
// Ruler Placement Coordinates
|
|
247
|
+
// Top Ruler: Above the top boundary
|
|
248
|
+
const topRulerY = rulerTop - gap;
|
|
249
|
+
const topRulerXStart = rulerLeft;
|
|
250
|
+
const topRulerXEnd = rulerRight;
|
|
251
|
+
// Left Ruler: Left of the left boundary
|
|
252
|
+
const leftRulerX = rulerLeft - gap;
|
|
253
|
+
const leftRulerYStart = rulerTop;
|
|
254
|
+
const leftRulerYEnd = rulerBottom;
|
|
255
|
+
// 1. Top Dimension Line (X-Axis)
|
|
256
|
+
const topDimLine = this.createArrowLine(topRulerXStart, topRulerY, topRulerXEnd, topRulerY, lineColor);
|
|
257
|
+
layer.add(topDimLine);
|
|
258
|
+
// Top Extension Lines
|
|
259
|
+
const extLen = 5;
|
|
260
|
+
layer.add(new fabric_1.Line([
|
|
261
|
+
topRulerXStart,
|
|
262
|
+
topRulerY - extLen,
|
|
263
|
+
topRulerXStart,
|
|
264
|
+
topRulerY + extLen,
|
|
265
|
+
], {
|
|
266
|
+
stroke: lineColor,
|
|
267
|
+
strokeWidth: 1,
|
|
268
|
+
selectable: false,
|
|
269
|
+
evented: false,
|
|
270
|
+
}));
|
|
271
|
+
layer.add(new fabric_1.Line([topRulerXEnd, topRulerY - extLen, topRulerXEnd, topRulerY + extLen], {
|
|
272
|
+
stroke: lineColor,
|
|
273
|
+
strokeWidth: 1,
|
|
274
|
+
selectable: false,
|
|
275
|
+
evented: false,
|
|
276
|
+
}));
|
|
277
|
+
// Top Text (Centered)
|
|
278
|
+
const widthStr = (0, units_1.formatMm)(displayWidthMm, displayUnit);
|
|
279
|
+
const topTextContent = `${widthStr} ${displayUnit}`;
|
|
280
|
+
const topText = new fabric_1.Text(topTextContent, {
|
|
281
|
+
left: topRulerXStart + (rulerRight - rulerLeft) / 2,
|
|
282
|
+
top: topRulerY,
|
|
283
|
+
fontSize: fontSize,
|
|
284
|
+
fill: textColor,
|
|
285
|
+
fontFamily: "Arial",
|
|
286
|
+
originX: "center",
|
|
287
|
+
originY: "center",
|
|
288
|
+
backgroundColor: backgroundColor, // Background mask for readability
|
|
289
|
+
selectable: false,
|
|
290
|
+
evented: false,
|
|
291
|
+
});
|
|
292
|
+
// Add small padding to text background if Fabric supports it directly or via separate rect
|
|
293
|
+
// Fabric Text backgroundColor is tight.
|
|
294
|
+
layer.add(topText);
|
|
295
|
+
// 2. Left Dimension Line (Y-Axis)
|
|
296
|
+
const leftDimLine = this.createArrowLine(leftRulerX, leftRulerYStart, leftRulerX, leftRulerYEnd, lineColor);
|
|
297
|
+
layer.add(leftDimLine);
|
|
298
|
+
// Left Extension Lines
|
|
299
|
+
layer.add(new fabric_1.Line([
|
|
300
|
+
leftRulerX - extLen,
|
|
301
|
+
leftRulerYStart,
|
|
302
|
+
leftRulerX + extLen,
|
|
303
|
+
leftRulerYStart,
|
|
304
|
+
], {
|
|
305
|
+
stroke: lineColor,
|
|
306
|
+
strokeWidth: 1,
|
|
307
|
+
selectable: false,
|
|
308
|
+
evented: false,
|
|
309
|
+
}));
|
|
310
|
+
layer.add(new fabric_1.Line([
|
|
311
|
+
leftRulerX - extLen,
|
|
312
|
+
leftRulerYEnd,
|
|
313
|
+
leftRulerX + extLen,
|
|
314
|
+
leftRulerYEnd,
|
|
315
|
+
], {
|
|
316
|
+
stroke: lineColor,
|
|
317
|
+
strokeWidth: 1,
|
|
318
|
+
selectable: false,
|
|
319
|
+
evented: false,
|
|
320
|
+
}));
|
|
321
|
+
// Left Text (Centered, Rotated)
|
|
322
|
+
const heightStr = (0, units_1.formatMm)(displayHeightMm, displayUnit);
|
|
323
|
+
const leftTextContent = `${heightStr} ${displayUnit}`;
|
|
324
|
+
const leftText = new fabric_1.Text(leftTextContent, {
|
|
325
|
+
left: leftRulerX,
|
|
326
|
+
top: leftRulerYStart + (rulerBottom - rulerTop) / 2,
|
|
327
|
+
angle: -90,
|
|
328
|
+
fontSize: fontSize,
|
|
329
|
+
fill: textColor,
|
|
330
|
+
fontFamily: "Arial",
|
|
331
|
+
originX: "center",
|
|
332
|
+
originY: "center",
|
|
333
|
+
backgroundColor: backgroundColor,
|
|
334
|
+
selectable: false,
|
|
335
|
+
evented: false,
|
|
336
|
+
});
|
|
337
|
+
layer.add(leftText);
|
|
338
|
+
// Always bring ruler to front
|
|
339
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
340
|
+
this.canvasService.canvas.requestRenderAll();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
exports.RulerTool = RulerTool;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SceneViewService = void 0;
|
|
4
|
+
class SceneViewService {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.id = "pooder.kit.sceneView";
|
|
7
|
+
this.metadata = {
|
|
8
|
+
name: "SceneViewService",
|
|
9
|
+
};
|
|
10
|
+
this.onToolActivated = (e) => {
|
|
11
|
+
this.activeToolId = e.id;
|
|
12
|
+
this.apply();
|
|
13
|
+
};
|
|
14
|
+
this.onObjectAdded = () => {
|
|
15
|
+
this.apply();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
activate(context) {
|
|
19
|
+
this.canvasService = context.services.get("CanvasService");
|
|
20
|
+
context.eventBus.on("tool:activated", this.onToolActivated);
|
|
21
|
+
context.eventBus.on("object:added", this.onObjectAdded);
|
|
22
|
+
}
|
|
23
|
+
deactivate(context) {
|
|
24
|
+
context.eventBus.off("tool:activated", this.onToolActivated);
|
|
25
|
+
context.eventBus.off("object:added", this.onObjectAdded);
|
|
26
|
+
this.activeToolId = undefined;
|
|
27
|
+
this.canvasService = undefined;
|
|
28
|
+
}
|
|
29
|
+
apply() {
|
|
30
|
+
if (!this.canvasService || !this.activeToolId)
|
|
31
|
+
return;
|
|
32
|
+
const dielineLayer = this.canvasService.getLayer("dieline-overlay");
|
|
33
|
+
if (dielineLayer) {
|
|
34
|
+
const visible = this.activeToolId !== "pooder.kit.image";
|
|
35
|
+
dielineLayer.set({ visible });
|
|
36
|
+
}
|
|
37
|
+
this.canvasService.requestRenderAll();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.SceneViewService = SceneViewService;
|