@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.
Files changed (90) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.mts +243 -36
  3. package/dist/index.d.ts +243 -36
  4. package/dist/index.js +2278 -1041
  5. package/dist/index.mjs +2278 -1041
  6. package/package.json +1 -1
  7. package/src/coordinate.ts +106 -106
  8. package/src/extensions/background.ts +323 -230
  9. package/src/extensions/bridgeSelection.ts +17 -17
  10. package/src/extensions/constraints.ts +322 -322
  11. package/src/extensions/dieline.ts +1149 -1076
  12. package/src/extensions/dielineShape.ts +109 -0
  13. package/src/extensions/edgeScale.ts +19 -19
  14. package/src/extensions/feature.ts +1137 -1021
  15. package/src/extensions/featureComplete.ts +46 -46
  16. package/src/extensions/film.ts +266 -194
  17. package/src/extensions/geometry.ts +885 -752
  18. package/src/extensions/image.ts +2054 -1926
  19. package/src/extensions/index.ts +11 -11
  20. package/src/extensions/maskOps.ts +283 -283
  21. package/src/extensions/mirror.ts +128 -128
  22. package/src/extensions/ruler.ts +654 -451
  23. package/src/extensions/sceneLayout.ts +140 -140
  24. package/src/extensions/sceneLayoutModel.ts +364 -352
  25. package/src/extensions/sceneVisibility.ts +64 -71
  26. package/src/extensions/size.ts +389 -389
  27. package/src/extensions/tracer.ts +1019 -1019
  28. package/src/extensions/white-ink.ts +1567 -1514
  29. package/src/extensions/wrappedOffsets.ts +33 -33
  30. package/src/index.ts +2 -2
  31. package/src/services/CanvasService.ts +832 -300
  32. package/src/services/ViewportSystem.ts +95 -95
  33. package/src/services/index.ts +3 -3
  34. package/src/services/renderSpec.ts +53 -18
  35. package/src/units.ts +27 -27
  36. package/tests/run.ts +118 -118
  37. package/tsconfig.test.json +15 -15
  38. package/.test-dist/src/CanvasService.js +0 -249
  39. package/.test-dist/src/ViewportSystem.js +0 -75
  40. package/.test-dist/src/background.js +0 -203
  41. package/.test-dist/src/bridgeSelection.js +0 -20
  42. package/.test-dist/src/constraints.js +0 -237
  43. package/.test-dist/src/coordinate.js +0 -74
  44. package/.test-dist/src/dieline.js +0 -818
  45. package/.test-dist/src/edgeScale.js +0 -12
  46. package/.test-dist/src/extensions/background.js +0 -203
  47. package/.test-dist/src/extensions/bridgeSelection.js +0 -20
  48. package/.test-dist/src/extensions/constraints.js +0 -237
  49. package/.test-dist/src/extensions/dieline.js +0 -828
  50. package/.test-dist/src/extensions/edgeScale.js +0 -12
  51. package/.test-dist/src/extensions/feature.js +0 -825
  52. package/.test-dist/src/extensions/featureComplete.js +0 -32
  53. package/.test-dist/src/extensions/film.js +0 -167
  54. package/.test-dist/src/extensions/geometry.js +0 -545
  55. package/.test-dist/src/extensions/image.js +0 -1529
  56. package/.test-dist/src/extensions/index.js +0 -30
  57. package/.test-dist/src/extensions/maskOps.js +0 -279
  58. package/.test-dist/src/extensions/mirror.js +0 -104
  59. package/.test-dist/src/extensions/ruler.js +0 -345
  60. package/.test-dist/src/extensions/sceneLayout.js +0 -96
  61. package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
  62. package/.test-dist/src/extensions/sceneVisibility.js +0 -62
  63. package/.test-dist/src/extensions/size.js +0 -331
  64. package/.test-dist/src/extensions/tracer.js +0 -538
  65. package/.test-dist/src/extensions/white-ink.js +0 -1190
  66. package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
  67. package/.test-dist/src/feature.js +0 -826
  68. package/.test-dist/src/featureComplete.js +0 -32
  69. package/.test-dist/src/film.js +0 -167
  70. package/.test-dist/src/geometry.js +0 -506
  71. package/.test-dist/src/image.js +0 -1250
  72. package/.test-dist/src/index.js +0 -18
  73. package/.test-dist/src/maskOps.js +0 -270
  74. package/.test-dist/src/mirror.js +0 -104
  75. package/.test-dist/src/renderSpec.js +0 -2
  76. package/.test-dist/src/ruler.js +0 -343
  77. package/.test-dist/src/sceneLayout.js +0 -99
  78. package/.test-dist/src/sceneLayoutModel.js +0 -196
  79. package/.test-dist/src/sceneView.js +0 -40
  80. package/.test-dist/src/sceneVisibility.js +0 -42
  81. package/.test-dist/src/services/CanvasService.js +0 -249
  82. package/.test-dist/src/services/ViewportSystem.js +0 -76
  83. package/.test-dist/src/services/index.js +0 -24
  84. package/.test-dist/src/services/renderSpec.js +0 -2
  85. package/.test-dist/src/size.js +0 -332
  86. package/.test-dist/src/tracer.js +0 -544
  87. package/.test-dist/src/units.js +0 -30
  88. package/.test-dist/src/white-ink.js +0 -829
  89. package/.test-dist/src/wrappedOffsets.js +0 -33
  90. package/.test-dist/tests/run.js +0 -94
@@ -1,345 +0,0 @@
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
242
- ? layout.cutWidthMm
243
- : layout.trimWidthMm;
244
- const displayHeightMm = useCutAsRuler
245
- ? layout.cutHeightMm
246
- : layout.trimHeightMm;
247
- const displayUnit = sizeState.unit;
248
- // Ruler Placement Coordinates
249
- // Top Ruler: Above the top boundary
250
- const topRulerY = rulerTop - gap;
251
- const topRulerXStart = rulerLeft;
252
- const topRulerXEnd = rulerRight;
253
- // Left Ruler: Left of the left boundary
254
- const leftRulerX = rulerLeft - gap;
255
- const leftRulerYStart = rulerTop;
256
- const leftRulerYEnd = rulerBottom;
257
- // 1. Top Dimension Line (X-Axis)
258
- const topDimLine = this.createArrowLine(topRulerXStart, topRulerY, topRulerXEnd, topRulerY, lineColor);
259
- layer.add(topDimLine);
260
- // Top Extension Lines
261
- const extLen = 5;
262
- layer.add(new fabric_1.Line([
263
- topRulerXStart,
264
- topRulerY - extLen,
265
- topRulerXStart,
266
- topRulerY + extLen,
267
- ], {
268
- stroke: lineColor,
269
- strokeWidth: 1,
270
- selectable: false,
271
- evented: false,
272
- }));
273
- layer.add(new fabric_1.Line([topRulerXEnd, topRulerY - extLen, topRulerXEnd, topRulerY + extLen], {
274
- stroke: lineColor,
275
- strokeWidth: 1,
276
- selectable: false,
277
- evented: false,
278
- }));
279
- // Top Text (Centered)
280
- const widthStr = (0, units_1.formatMm)(displayWidthMm, displayUnit);
281
- const topTextContent = `${widthStr} ${displayUnit}`;
282
- const topText = new fabric_1.Text(topTextContent, {
283
- left: topRulerXStart + (rulerRight - rulerLeft) / 2,
284
- top: topRulerY,
285
- fontSize: fontSize,
286
- fill: textColor,
287
- fontFamily: "Arial",
288
- originX: "center",
289
- originY: "center",
290
- backgroundColor: backgroundColor, // Background mask for readability
291
- selectable: false,
292
- evented: false,
293
- });
294
- // Add small padding to text background if Fabric supports it directly or via separate rect
295
- // Fabric Text backgroundColor is tight.
296
- layer.add(topText);
297
- // 2. Left Dimension Line (Y-Axis)
298
- const leftDimLine = this.createArrowLine(leftRulerX, leftRulerYStart, leftRulerX, leftRulerYEnd, lineColor);
299
- layer.add(leftDimLine);
300
- // Left Extension Lines
301
- layer.add(new fabric_1.Line([
302
- leftRulerX - extLen,
303
- leftRulerYStart,
304
- leftRulerX + extLen,
305
- leftRulerYStart,
306
- ], {
307
- stroke: lineColor,
308
- strokeWidth: 1,
309
- selectable: false,
310
- evented: false,
311
- }));
312
- layer.add(new fabric_1.Line([
313
- leftRulerX - extLen,
314
- leftRulerYEnd,
315
- leftRulerX + extLen,
316
- leftRulerYEnd,
317
- ], {
318
- stroke: lineColor,
319
- strokeWidth: 1,
320
- selectable: false,
321
- evented: false,
322
- }));
323
- // Left Text (Centered, Rotated)
324
- const heightStr = (0, units_1.formatMm)(displayHeightMm, displayUnit);
325
- const leftTextContent = `${heightStr} ${displayUnit}`;
326
- const leftText = new fabric_1.Text(leftTextContent, {
327
- left: leftRulerX,
328
- top: leftRulerYStart + (rulerBottom - rulerTop) / 2,
329
- angle: -90,
330
- fontSize: fontSize,
331
- fill: textColor,
332
- fontFamily: "Arial",
333
- originX: "center",
334
- originY: "center",
335
- backgroundColor: backgroundColor,
336
- selectable: false,
337
- evented: false,
338
- });
339
- layer.add(leftText);
340
- // Always bring ruler to front
341
- this.canvasService.canvas.bringObjectToFront(layer);
342
- this.canvasService.canvas.requestRenderAll();
343
- }
344
- }
345
- exports.RulerTool = RulerTool;
@@ -1,96 +0,0 @@
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 CONFIG_WATCH_PREFIXES = ["size.", "dieline."];
7
- const CANVAS_SERVICE_ID = "CanvasService";
8
- const GET_SCENE_LAYOUT_COMMAND = "getSceneLayout";
9
- const GET_SCENE_GEOMETRY_COMMAND = "getSceneGeometry";
10
- class SceneLayoutService {
11
- constructor() {
12
- this.lastLayout = null;
13
- this.lastGeometry = null;
14
- this.commandDisposables = [];
15
- this.onCanvasResized = () => {
16
- this.refresh();
17
- };
18
- this.onConfigChanged = (e) => {
19
- if (CONFIG_WATCH_PREFIXES.some((prefix) => e.key.startsWith(prefix))) {
20
- this.refresh();
21
- }
22
- };
23
- }
24
- init(context) {
25
- if (this.context) {
26
- this.dispose(this.context);
27
- }
28
- const canvasService = context.get(CANVAS_SERVICE_ID);
29
- const configService = context.get(core_1.CONFIGURATION_SERVICE);
30
- const commandService = context.get(core_1.COMMAND_SERVICE);
31
- if (!canvasService || !configService || !commandService) {
32
- throw new Error("[SceneLayoutService] CanvasService, ConfigurationService and CommandService are required.");
33
- }
34
- this.context = context;
35
- this.canvasService = canvasService;
36
- this.configService = configService;
37
- this.commandDisposables.push(commandService.registerCommand(GET_SCENE_LAYOUT_COMMAND, () => this.getLayout()), commandService.registerCommand(GET_SCENE_GEOMETRY_COMMAND, () => this.getGeometry()));
38
- this.onConfigChange = configService.onAnyChange(this.onConfigChanged);
39
- context.eventBus.on("canvas:resized", this.onCanvasResized);
40
- this.refresh();
41
- }
42
- dispose(context) {
43
- const activeContext = this.context ?? context;
44
- activeContext.eventBus.off("canvas:resized", this.onCanvasResized);
45
- this.onConfigChange?.dispose();
46
- this.onConfigChange = undefined;
47
- this.commandDisposables.forEach((item) => item.dispose());
48
- this.commandDisposables = [];
49
- this.context = undefined;
50
- this.canvasService = undefined;
51
- this.configService = undefined;
52
- this.lastLayout = null;
53
- this.lastGeometry = null;
54
- }
55
- refresh() {
56
- const layout = this.getLayout(true);
57
- if (!layout) {
58
- this.lastGeometry = null;
59
- return;
60
- }
61
- this.context?.eventBus.emit("scene:layout:change", layout);
62
- const geometry = this.getGeometry(true);
63
- if (geometry) {
64
- this.context?.eventBus.emit("scene:geometry:change", geometry);
65
- }
66
- }
67
- getLayout(forceRefresh = false) {
68
- if (!this.canvasService || !this.configService)
69
- return null;
70
- if (!forceRefresh && this.lastLayout)
71
- return this.lastLayout;
72
- const state = (0, sceneLayoutModel_1.readSizeState)(this.configService);
73
- const layout = (0, sceneLayoutModel_1.computeSceneLayout)(this.canvasService, state);
74
- if (!layout) {
75
- this.lastLayout = null;
76
- return null;
77
- }
78
- this.lastLayout = layout;
79
- return layout;
80
- }
81
- getGeometry(forceRefresh = false) {
82
- if (!this.configService)
83
- return null;
84
- const layout = this.getLayout(forceRefresh);
85
- if (!layout) {
86
- this.lastGeometry = null;
87
- return null;
88
- }
89
- if (!forceRefresh && this.lastGeometry)
90
- return this.lastGeometry;
91
- const geometry = (0, sceneLayoutModel_1.buildSceneGeometry)(this.configService, layout);
92
- this.lastGeometry = geometry;
93
- return geometry;
94
- }
95
- }
96
- exports.SceneLayoutService = SceneLayoutService;
@@ -1,196 +0,0 @@
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
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SceneVisibilityService = void 0;
4
- const core_1 = require("@pooder/core");
5
- const CANVAS_SERVICE_ID = "CanvasService";
6
- const HIDDEN_DIELINE_TOOLS = new Set(["pooder.kit.image", "pooder.kit.white-ink"]);
7
- const HIDDEN_RULER_TOOLS = new Set(["pooder.kit.white-ink"]);
8
- class SceneVisibilityService {
9
- constructor() {
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
- init(context) {
20
- if (this.context) {
21
- this.dispose(this.context);
22
- }
23
- const canvasService = context.get(CANVAS_SERVICE_ID);
24
- if (!canvasService) {
25
- throw new Error("[SceneVisibilityService] CanvasService is required.");
26
- }
27
- this.context = context;
28
- this.canvasService = canvasService;
29
- this.activeToolId = context.get(core_1.WORKBENCH_SERVICE)?.activeToolId ?? null;
30
- context.eventBus.on("tool:activated", this.onToolActivated);
31
- context.eventBus.on("object:added", this.onObjectAdded);
32
- this.apply();
33
- }
34
- dispose(context) {
35
- const activeContext = this.context ?? context;
36
- activeContext.eventBus.off("tool:activated", this.onToolActivated);
37
- activeContext.eventBus.off("object:added", this.onObjectAdded);
38
- this.context = undefined;
39
- this.activeToolId = null;
40
- this.canvasService = undefined;
41
- }
42
- apply() {
43
- if (!this.canvasService)
44
- return;
45
- const dielineLayer = this.canvasService.getLayer("dieline-overlay");
46
- if (dielineLayer) {
47
- const visible = !HIDDEN_DIELINE_TOOLS.has(this.activeToolId || "");
48
- if (dielineLayer.visible !== visible) {
49
- dielineLayer.set({ visible });
50
- }
51
- }
52
- const rulerLayer = this.canvasService.getLayer("ruler-overlay");
53
- if (rulerLayer) {
54
- const visible = !HIDDEN_RULER_TOOLS.has(this.activeToolId || "");
55
- if (rulerLayer.visible !== visible) {
56
- rulerLayer.set({ visible });
57
- }
58
- }
59
- this.canvasService.requestRenderAll();
60
- }
61
- }
62
- exports.SceneVisibilityService = SceneVisibilityService;