@pooder/kit 0.0.2 → 2.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 +26 -9
- package/dist/index.d.mts +29 -6
- package/dist/index.d.ts +29 -6
- package/dist/index.js +405 -62
- package/dist/index.mjs +435 -68
- package/package.json +2 -2
- package/src/background.ts +183 -173
- package/src/dieline.ts +580 -424
- package/src/film.ts +163 -155
- package/src/geometry.ts +251 -244
- package/src/hole.ts +493 -413
- package/src/image.ts +304 -146
- package/src/index.ts +8 -7
- package/src/mirror.ts +91 -0
- package/src/ruler.ts +255 -238
- package/src/white-ink.ts +329 -302
- package/tsconfig.json +13 -13
package/src/ruler.ts
CHANGED
|
@@ -1,238 +1,255 @@
|
|
|
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
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Command,
|
|
3
|
+
Editor,
|
|
4
|
+
EditorState,
|
|
5
|
+
Extension,
|
|
6
|
+
OptionSchema,
|
|
7
|
+
PooderLayer,
|
|
8
|
+
Rect,
|
|
9
|
+
Line,
|
|
10
|
+
Text,
|
|
11
|
+
} from "@pooder/core";
|
|
12
|
+
|
|
13
|
+
export interface RulerToolOptions {
|
|
14
|
+
unit: "px" | "mm" | "cm" | "in";
|
|
15
|
+
thickness: number;
|
|
16
|
+
backgroundColor: string;
|
|
17
|
+
textColor: string;
|
|
18
|
+
lineColor: string;
|
|
19
|
+
fontSize: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class RulerTool implements Extension<RulerToolOptions> {
|
|
23
|
+
public name = "RulerTool";
|
|
24
|
+
public options: RulerToolOptions = {
|
|
25
|
+
unit: "px",
|
|
26
|
+
thickness: 20,
|
|
27
|
+
backgroundColor: "#f0f0f0",
|
|
28
|
+
textColor: "#333333",
|
|
29
|
+
lineColor: "#999999",
|
|
30
|
+
fontSize: 10,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
public schema: Record<keyof RulerToolOptions, OptionSchema> = {
|
|
34
|
+
unit: {
|
|
35
|
+
type: "select",
|
|
36
|
+
options: ["px", "mm", "cm", "in"],
|
|
37
|
+
label: "Unit",
|
|
38
|
+
},
|
|
39
|
+
thickness: { type: "number", min: 10, max: 100, label: "Thickness" },
|
|
40
|
+
backgroundColor: { type: "color", label: "Background Color" },
|
|
41
|
+
textColor: { type: "color", label: "Text Color" },
|
|
42
|
+
lineColor: { type: "color", label: "Line Color" },
|
|
43
|
+
fontSize: { type: "number", min: 8, max: 24, label: "Font Size" },
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
onMount(editor: Editor) {
|
|
47
|
+
this.createLayer(editor);
|
|
48
|
+
this.updateRuler(editor);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onUnmount(editor: Editor) {
|
|
52
|
+
this.destroyLayer(editor);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onUpdate(editor: Editor, state: EditorState) {
|
|
56
|
+
this.updateRuler(editor);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onDestroy(editor: Editor) {
|
|
60
|
+
this.destroyLayer(editor);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private getLayer(editor: Editor) {
|
|
64
|
+
return editor.canvas
|
|
65
|
+
.getObjects()
|
|
66
|
+
.find((obj: any) => obj.data?.id === "ruler-overlay") as
|
|
67
|
+
| PooderLayer
|
|
68
|
+
| undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private createLayer(editor: Editor) {
|
|
72
|
+
let layer = this.getLayer(editor);
|
|
73
|
+
|
|
74
|
+
if (!layer) {
|
|
75
|
+
const width = editor.canvas.width || 800;
|
|
76
|
+
const height = editor.canvas.height || 600;
|
|
77
|
+
|
|
78
|
+
layer = new PooderLayer([], {
|
|
79
|
+
width,
|
|
80
|
+
height,
|
|
81
|
+
selectable: false,
|
|
82
|
+
evented: false,
|
|
83
|
+
data: { id: "ruler-overlay" },
|
|
84
|
+
} as any);
|
|
85
|
+
|
|
86
|
+
editor.canvas.add(layer);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
editor.canvas.bringObjectToFront(layer);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private destroyLayer(editor: Editor) {
|
|
93
|
+
const layer = this.getLayer(editor);
|
|
94
|
+
if (layer) {
|
|
95
|
+
editor.canvas.remove(layer);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private updateRuler(editor: Editor) {
|
|
100
|
+
const layer = this.getLayer(editor);
|
|
101
|
+
if (!layer) return;
|
|
102
|
+
|
|
103
|
+
layer.remove(...layer.getObjects());
|
|
104
|
+
|
|
105
|
+
const { thickness, backgroundColor, lineColor, textColor, fontSize } =
|
|
106
|
+
this.options;
|
|
107
|
+
const width = editor.canvas.width || 800;
|
|
108
|
+
const height = editor.canvas.height || 600;
|
|
109
|
+
|
|
110
|
+
// Backgrounds
|
|
111
|
+
const topBg = new Rect({
|
|
112
|
+
left: 0,
|
|
113
|
+
top: 0,
|
|
114
|
+
width: width,
|
|
115
|
+
height: thickness,
|
|
116
|
+
fill: backgroundColor,
|
|
117
|
+
selectable: false,
|
|
118
|
+
evented: false,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const leftBg = new Rect({
|
|
122
|
+
left: 0,
|
|
123
|
+
top: 0,
|
|
124
|
+
width: thickness,
|
|
125
|
+
height: height,
|
|
126
|
+
fill: backgroundColor,
|
|
127
|
+
selectable: false,
|
|
128
|
+
evented: false,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const cornerBg = new Rect({
|
|
132
|
+
left: 0,
|
|
133
|
+
top: 0,
|
|
134
|
+
width: thickness,
|
|
135
|
+
height: thickness,
|
|
136
|
+
fill: backgroundColor,
|
|
137
|
+
stroke: lineColor,
|
|
138
|
+
strokeWidth: 1,
|
|
139
|
+
selectable: false,
|
|
140
|
+
evented: false,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
layer.add(topBg, leftBg, cornerBg);
|
|
144
|
+
|
|
145
|
+
// Drawing Constants (Pixel based for now)
|
|
146
|
+
const step = 100; // Major tick
|
|
147
|
+
const subStep = 10; // Minor tick
|
|
148
|
+
const midStep = 50; // Medium tick
|
|
149
|
+
|
|
150
|
+
// Top Ruler
|
|
151
|
+
for (let x = 0; x <= width; x += subStep) {
|
|
152
|
+
if (x < thickness) continue; // Skip corner
|
|
153
|
+
|
|
154
|
+
let len = thickness * 0.25;
|
|
155
|
+
if (x % step === 0) len = thickness * 0.8;
|
|
156
|
+
else if (x % midStep === 0) len = thickness * 0.5;
|
|
157
|
+
|
|
158
|
+
const line = new Line([x, thickness - len, x, thickness], {
|
|
159
|
+
stroke: lineColor,
|
|
160
|
+
strokeWidth: 1,
|
|
161
|
+
selectable: false,
|
|
162
|
+
evented: false,
|
|
163
|
+
});
|
|
164
|
+
layer.add(line);
|
|
165
|
+
|
|
166
|
+
if (x % step === 0) {
|
|
167
|
+
const text = new Text(x.toString(), {
|
|
168
|
+
left: x + 2,
|
|
169
|
+
top: 2,
|
|
170
|
+
fontSize: fontSize,
|
|
171
|
+
fill: textColor,
|
|
172
|
+
fontFamily: "Arial",
|
|
173
|
+
selectable: false,
|
|
174
|
+
evented: false,
|
|
175
|
+
});
|
|
176
|
+
layer.add(text);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Left Ruler
|
|
181
|
+
for (let y = 0; y <= height; y += subStep) {
|
|
182
|
+
if (y < thickness) continue; // Skip corner
|
|
183
|
+
|
|
184
|
+
let len = thickness * 0.25;
|
|
185
|
+
if (y % step === 0) len = thickness * 0.8;
|
|
186
|
+
else if (y % midStep === 0) len = thickness * 0.5;
|
|
187
|
+
|
|
188
|
+
const line = new Line([thickness - len, y, thickness, y], {
|
|
189
|
+
stroke: lineColor,
|
|
190
|
+
strokeWidth: 1,
|
|
191
|
+
selectable: false,
|
|
192
|
+
evented: false,
|
|
193
|
+
});
|
|
194
|
+
layer.add(line);
|
|
195
|
+
|
|
196
|
+
if (y % step === 0) {
|
|
197
|
+
const text = new Text(y.toString(), {
|
|
198
|
+
angle: -90,
|
|
199
|
+
left: thickness / 2 - fontSize / 3, // approximate centering
|
|
200
|
+
top: y + fontSize,
|
|
201
|
+
fontSize: fontSize,
|
|
202
|
+
fill: textColor,
|
|
203
|
+
fontFamily: "Arial",
|
|
204
|
+
originX: "center",
|
|
205
|
+
originY: "center",
|
|
206
|
+
selectable: false,
|
|
207
|
+
evented: false,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
layer.add(text);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Always bring ruler to front
|
|
215
|
+
editor.canvas.bringObjectToFront(layer);
|
|
216
|
+
editor.canvas.requestRenderAll();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
commands: Record<string, Command> = {
|
|
220
|
+
setUnit: {
|
|
221
|
+
execute: (editor: Editor, unit: "px" | "mm" | "cm" | "in") => {
|
|
222
|
+
if (this.options.unit === unit) return true;
|
|
223
|
+
this.options.unit = unit;
|
|
224
|
+
this.updateRuler(editor);
|
|
225
|
+
return true;
|
|
226
|
+
},
|
|
227
|
+
schema: {
|
|
228
|
+
unit: {
|
|
229
|
+
type: "string",
|
|
230
|
+
label: "Unit",
|
|
231
|
+
options: ["px", "mm", "cm", "in"],
|
|
232
|
+
required: true,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
setTheme: {
|
|
237
|
+
execute: (editor: Editor, theme: Partial<RulerToolOptions>) => {
|
|
238
|
+
const newOptions = { ...this.options, ...theme };
|
|
239
|
+
if (JSON.stringify(newOptions) === JSON.stringify(this.options))
|
|
240
|
+
return true;
|
|
241
|
+
|
|
242
|
+
this.options = newOptions;
|
|
243
|
+
this.updateRuler(editor);
|
|
244
|
+
return true;
|
|
245
|
+
},
|
|
246
|
+
schema: {
|
|
247
|
+
theme: {
|
|
248
|
+
type: "object",
|
|
249
|
+
label: "Theme",
|
|
250
|
+
required: true,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|