@pooder/kit 1.0.0 → 3.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/CHANGELOG.md +22 -0
- package/dist/index.d.mts +250 -115
- package/dist/index.d.ts +250 -115
- package/dist/index.js +2177 -831
- package/dist/index.mjs +2182 -826
- package/package.json +3 -2
- package/src/CanvasService.ts +65 -0
- package/src/background.ts +230 -172
- package/src/coordinate.ts +49 -0
- package/src/dieline.ts +780 -421
- package/src/film.ts +194 -156
- package/src/geometry.ts +464 -244
- package/src/hole.ts +629 -413
- package/src/image.ts +504 -147
- package/src/index.ts +9 -7
- package/src/mirror.ts +128 -0
- package/src/ruler.ts +325 -239
- package/src/tracer.ts +372 -0
- package/src/white-ink.ts +373 -301
- package/tsconfig.json +13 -13
package/src/ruler.ts
CHANGED
|
@@ -1,239 +1,325 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
} from "@pooder/core";
|
|
8
|
+
import { Rect, Line, Text } from "fabric";
|
|
9
|
+
import CanvasService from "./CanvasService";
|
|
10
|
+
|
|
11
|
+
export class RulerTool implements Extension {
|
|
12
|
+
id = "pooder.kit.ruler";
|
|
13
|
+
|
|
14
|
+
public metadata = {
|
|
15
|
+
name: "RulerTool",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
private unit: "px" | "mm" | "cm" | "in" = "px";
|
|
19
|
+
private thickness: number = 20;
|
|
20
|
+
private backgroundColor: string = "#f0f0f0";
|
|
21
|
+
private textColor: string = "#333333";
|
|
22
|
+
private lineColor: string = "#999999";
|
|
23
|
+
private fontSize: number = 10;
|
|
24
|
+
|
|
25
|
+
private canvasService?: CanvasService;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
options?: Partial<{
|
|
29
|
+
unit: "px" | "mm" | "cm" | "in";
|
|
30
|
+
thickness: number;
|
|
31
|
+
backgroundColor: string;
|
|
32
|
+
textColor: string;
|
|
33
|
+
lineColor: string;
|
|
34
|
+
fontSize: number;
|
|
35
|
+
}>,
|
|
36
|
+
) {
|
|
37
|
+
if (options) {
|
|
38
|
+
Object.assign(this, options);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
activate(context: ExtensionContext) {
|
|
43
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
44
|
+
if (!this.canvasService) {
|
|
45
|
+
console.warn("CanvasService not found for RulerTool");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const configService = context.services.get<any>("ConfigurationService");
|
|
50
|
+
if (configService) {
|
|
51
|
+
// Load initial config
|
|
52
|
+
this.unit = configService.get("ruler.unit", this.unit);
|
|
53
|
+
this.thickness = configService.get("ruler.thickness", this.thickness);
|
|
54
|
+
this.backgroundColor = configService.get(
|
|
55
|
+
"ruler.backgroundColor",
|
|
56
|
+
this.backgroundColor,
|
|
57
|
+
);
|
|
58
|
+
this.textColor = configService.get("ruler.textColor", this.textColor);
|
|
59
|
+
this.lineColor = configService.get("ruler.lineColor", this.lineColor);
|
|
60
|
+
this.fontSize = configService.get("ruler.fontSize", this.fontSize);
|
|
61
|
+
|
|
62
|
+
// Listen for changes
|
|
63
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
64
|
+
if (e.key.startsWith("ruler.")) {
|
|
65
|
+
const prop = e.key.split(".")[1];
|
|
66
|
+
if (prop && prop in this) {
|
|
67
|
+
(this as any)[prop] = e.value;
|
|
68
|
+
this.updateRuler();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.createLayer();
|
|
75
|
+
this.updateRuler();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
deactivate(context: ExtensionContext) {
|
|
79
|
+
this.destroyLayer();
|
|
80
|
+
this.canvasService = undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
contribute() {
|
|
84
|
+
return {
|
|
85
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
86
|
+
{
|
|
87
|
+
id: "ruler.unit",
|
|
88
|
+
type: "select",
|
|
89
|
+
label: "Unit",
|
|
90
|
+
options: ["px", "mm", "cm", "in"],
|
|
91
|
+
default: "px",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "ruler.thickness",
|
|
95
|
+
type: "number",
|
|
96
|
+
label: "Thickness",
|
|
97
|
+
min: 10,
|
|
98
|
+
max: 100,
|
|
99
|
+
default: 20,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "ruler.backgroundColor",
|
|
103
|
+
type: "color",
|
|
104
|
+
label: "Background Color",
|
|
105
|
+
default: "#f0f0f0",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "ruler.textColor",
|
|
109
|
+
type: "color",
|
|
110
|
+
label: "Text Color",
|
|
111
|
+
default: "#333333",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "ruler.lineColor",
|
|
115
|
+
type: "color",
|
|
116
|
+
label: "Line Color",
|
|
117
|
+
default: "#999999",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "ruler.fontSize",
|
|
121
|
+
type: "number",
|
|
122
|
+
label: "Font Size",
|
|
123
|
+
min: 8,
|
|
124
|
+
max: 24,
|
|
125
|
+
default: 10,
|
|
126
|
+
},
|
|
127
|
+
] as ConfigurationContribution[],
|
|
128
|
+
[ContributionPointIds.COMMANDS]: [
|
|
129
|
+
{
|
|
130
|
+
command: "setUnit",
|
|
131
|
+
title: "Set Ruler Unit",
|
|
132
|
+
handler: (unit: "px" | "mm" | "cm" | "in") => {
|
|
133
|
+
if (this.unit === unit) return true;
|
|
134
|
+
this.unit = unit;
|
|
135
|
+
this.updateRuler();
|
|
136
|
+
return true;
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
command: "setTheme",
|
|
141
|
+
title: "Set Ruler Theme",
|
|
142
|
+
handler: (
|
|
143
|
+
theme: Partial<{
|
|
144
|
+
backgroundColor: string;
|
|
145
|
+
textColor: string;
|
|
146
|
+
lineColor: string;
|
|
147
|
+
fontSize: number;
|
|
148
|
+
thickness: number;
|
|
149
|
+
}>,
|
|
150
|
+
) => {
|
|
151
|
+
const oldState = {
|
|
152
|
+
backgroundColor: this.backgroundColor,
|
|
153
|
+
textColor: this.textColor,
|
|
154
|
+
lineColor: this.lineColor,
|
|
155
|
+
fontSize: this.fontSize,
|
|
156
|
+
thickness: this.thickness,
|
|
157
|
+
};
|
|
158
|
+
const newState = { ...oldState, ...theme };
|
|
159
|
+
if (JSON.stringify(newState) === JSON.stringify(oldState))
|
|
160
|
+
return true;
|
|
161
|
+
|
|
162
|
+
Object.assign(this, newState);
|
|
163
|
+
this.updateRuler();
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
] as CommandContribution[],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private getLayer() {
|
|
172
|
+
return this.canvasService?.getLayer("ruler-overlay");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private createLayer() {
|
|
176
|
+
if (!this.canvasService) return;
|
|
177
|
+
|
|
178
|
+
const canvas = this.canvasService.canvas;
|
|
179
|
+
const width = canvas.width || 800;
|
|
180
|
+
const height = canvas.height || 600;
|
|
181
|
+
|
|
182
|
+
const layer = this.canvasService.createLayer("ruler-overlay", {
|
|
183
|
+
width,
|
|
184
|
+
height,
|
|
185
|
+
selectable: false,
|
|
186
|
+
evented: false,
|
|
187
|
+
left: 0,
|
|
188
|
+
top: 0,
|
|
189
|
+
originX: "left",
|
|
190
|
+
originY: "top",
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
canvas.bringObjectToFront(layer);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private destroyLayer() {
|
|
197
|
+
if (!this.canvasService) return;
|
|
198
|
+
const layer = this.getLayer();
|
|
199
|
+
if (layer) {
|
|
200
|
+
this.canvasService.canvas.remove(layer);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private updateRuler() {
|
|
205
|
+
if (!this.canvasService) return;
|
|
206
|
+
const layer = this.getLayer();
|
|
207
|
+
if (!layer) return;
|
|
208
|
+
|
|
209
|
+
layer.remove(...layer.getObjects());
|
|
210
|
+
|
|
211
|
+
const { thickness, backgroundColor, lineColor, textColor, fontSize } = this;
|
|
212
|
+
const width = this.canvasService.canvas.width || 800;
|
|
213
|
+
const height = this.canvasService.canvas.height || 600;
|
|
214
|
+
|
|
215
|
+
// Backgrounds
|
|
216
|
+
const topBg = new Rect({
|
|
217
|
+
left: 0,
|
|
218
|
+
top: 0,
|
|
219
|
+
width: width,
|
|
220
|
+
height: thickness,
|
|
221
|
+
fill: backgroundColor,
|
|
222
|
+
selectable: false,
|
|
223
|
+
evented: false,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const leftBg = new Rect({
|
|
227
|
+
left: 0,
|
|
228
|
+
top: 0,
|
|
229
|
+
width: thickness,
|
|
230
|
+
height: height,
|
|
231
|
+
fill: backgroundColor,
|
|
232
|
+
selectable: false,
|
|
233
|
+
evented: false,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const cornerBg = new Rect({
|
|
237
|
+
left: 0,
|
|
238
|
+
top: 0,
|
|
239
|
+
width: thickness,
|
|
240
|
+
height: thickness,
|
|
241
|
+
fill: backgroundColor,
|
|
242
|
+
stroke: lineColor,
|
|
243
|
+
strokeWidth: 1,
|
|
244
|
+
selectable: false,
|
|
245
|
+
evented: false,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
layer.add(topBg);
|
|
249
|
+
layer.add(leftBg);
|
|
250
|
+
layer.add(cornerBg);
|
|
251
|
+
|
|
252
|
+
// Drawing Constants (Pixel based for now)
|
|
253
|
+
const step = 100; // Major tick
|
|
254
|
+
const subStep = 10; // Minor tick
|
|
255
|
+
const midStep = 50; // Medium tick
|
|
256
|
+
|
|
257
|
+
// Top Ruler
|
|
258
|
+
for (let x = 0; x <= width; x += subStep) {
|
|
259
|
+
if (x < thickness) continue; // Skip corner
|
|
260
|
+
|
|
261
|
+
let len = thickness * 0.25;
|
|
262
|
+
if (x % step === 0) len = thickness * 0.8;
|
|
263
|
+
else if (x % midStep === 0) len = thickness * 0.5;
|
|
264
|
+
|
|
265
|
+
const line = new Line([x, thickness - len, x, thickness], {
|
|
266
|
+
stroke: lineColor,
|
|
267
|
+
strokeWidth: 1,
|
|
268
|
+
selectable: false,
|
|
269
|
+
evented: false,
|
|
270
|
+
});
|
|
271
|
+
layer.add(line);
|
|
272
|
+
|
|
273
|
+
if (x % step === 0) {
|
|
274
|
+
const text = new Text(x.toString(), {
|
|
275
|
+
left: x + 2,
|
|
276
|
+
top: 2,
|
|
277
|
+
fontSize: fontSize,
|
|
278
|
+
fill: textColor,
|
|
279
|
+
fontFamily: "Arial",
|
|
280
|
+
selectable: false,
|
|
281
|
+
evented: false,
|
|
282
|
+
});
|
|
283
|
+
layer.add(text);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Left Ruler
|
|
288
|
+
for (let y = 0; y <= height; y += subStep) {
|
|
289
|
+
if (y < thickness) continue; // Skip corner
|
|
290
|
+
|
|
291
|
+
let len = thickness * 0.25;
|
|
292
|
+
if (y % step === 0) len = thickness * 0.8;
|
|
293
|
+
else if (y % midStep === 0) len = thickness * 0.5;
|
|
294
|
+
|
|
295
|
+
const line = new Line([thickness - len, y, thickness, y], {
|
|
296
|
+
stroke: lineColor,
|
|
297
|
+
strokeWidth: 1,
|
|
298
|
+
selectable: false,
|
|
299
|
+
evented: false,
|
|
300
|
+
});
|
|
301
|
+
layer.add(line);
|
|
302
|
+
|
|
303
|
+
if (y % step === 0) {
|
|
304
|
+
const text = new Text(y.toString(), {
|
|
305
|
+
angle: -90,
|
|
306
|
+
left: thickness / 2 - fontSize / 3, // approximate centering
|
|
307
|
+
top: y + fontSize,
|
|
308
|
+
fontSize: fontSize,
|
|
309
|
+
fill: textColor,
|
|
310
|
+
fontFamily: "Arial",
|
|
311
|
+
originX: "center",
|
|
312
|
+
originY: "center",
|
|
313
|
+
selectable: false,
|
|
314
|
+
evented: false,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
layer.add(text);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Always bring ruler to front
|
|
322
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
323
|
+
this.canvasService.canvas.requestRenderAll();
|
|
324
|
+
}
|
|
325
|
+
}
|