@pooder/kit 3.3.0 → 3.5.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 +12 -0
- package/dist/index.d.mts +53 -57
- package/dist/index.d.ts +53 -57
- package/dist/index.js +1081 -930
- package/dist/index.mjs +1080 -929
- package/package.json +1 -1
- package/src/CanvasService.ts +65 -65
- package/src/background.ts +230 -230
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +282 -218
- package/src/feature.ts +724 -0
- package/src/film.ts +194 -194
- package/src/geometry.ts +118 -370
- package/src/image.ts +471 -496
- package/src/index.ts +1 -1
- package/src/mirror.ts +128 -128
- package/src/ruler.ts +500 -500
- package/src/tracer.ts +570 -372
- package/src/white-ink.ts +373 -373
- package/src/hole.ts +0 -786
package/src/film.ts
CHANGED
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
} from "@pooder/core";
|
|
8
|
-
import { FabricImage as Image } from "fabric";
|
|
9
|
-
import CanvasService from "./CanvasService";
|
|
10
|
-
|
|
11
|
-
export class FilmTool implements Extension {
|
|
12
|
-
id = "pooder.kit.film";
|
|
13
|
-
|
|
14
|
-
public metadata = {
|
|
15
|
-
name: "FilmTool",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
private url: string = "";
|
|
19
|
-
private opacity: number = 0.5;
|
|
20
|
-
|
|
21
|
-
private canvasService?: CanvasService;
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
options?: Partial<{
|
|
25
|
-
url: string;
|
|
26
|
-
opacity: number;
|
|
27
|
-
}>,
|
|
28
|
-
) {
|
|
29
|
-
if (options) {
|
|
30
|
-
Object.assign(this, options);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
activate(context: ExtensionContext) {
|
|
35
|
-
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
36
|
-
if (!this.canvasService) {
|
|
37
|
-
console.warn("CanvasService not found for FilmTool");
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const configService = context.services.get<any>("ConfigurationService");
|
|
42
|
-
if (configService) {
|
|
43
|
-
// Load initial config
|
|
44
|
-
this.url = configService.get("film.url", this.url);
|
|
45
|
-
this.opacity = configService.get("film.opacity", this.opacity);
|
|
46
|
-
|
|
47
|
-
// Listen for changes
|
|
48
|
-
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
49
|
-
if (e.key.startsWith("film.")) {
|
|
50
|
-
const prop = e.key.split(".")[1];
|
|
51
|
-
console.log(
|
|
52
|
-
`[FilmTool] Config change detected: ${e.key} -> ${e.value}`,
|
|
53
|
-
);
|
|
54
|
-
if (prop && prop in this) {
|
|
55
|
-
(this as any)[prop] = e.value;
|
|
56
|
-
this.updateFilm();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.initLayer();
|
|
63
|
-
this.updateFilm();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
deactivate(context: ExtensionContext) {
|
|
67
|
-
if (this.canvasService) {
|
|
68
|
-
const layer = this.canvasService.getLayer("overlay");
|
|
69
|
-
if (layer) {
|
|
70
|
-
const img = this.canvasService.getObject("film-image", "overlay");
|
|
71
|
-
if (img) {
|
|
72
|
-
layer.remove(img);
|
|
73
|
-
this.canvasService.requestRenderAll();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
this.canvasService = undefined;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
contribute() {
|
|
81
|
-
return {
|
|
82
|
-
[ContributionPointIds.CONFIGURATIONS]: [
|
|
83
|
-
{
|
|
84
|
-
id: "film.url",
|
|
85
|
-
type: "string",
|
|
86
|
-
label: "Film Image URL",
|
|
87
|
-
default: "",
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
id: "film.opacity",
|
|
91
|
-
type: "number",
|
|
92
|
-
label: "Opacity",
|
|
93
|
-
min: 0,
|
|
94
|
-
max: 1,
|
|
95
|
-
step: 0.1,
|
|
96
|
-
default: 0.5,
|
|
97
|
-
},
|
|
98
|
-
] as ConfigurationContribution[],
|
|
99
|
-
[ContributionPointIds.COMMANDS]: [
|
|
100
|
-
{
|
|
101
|
-
command: "setFilmImage",
|
|
102
|
-
title: "Set Film Image",
|
|
103
|
-
handler: (url: string, opacity: number) => {
|
|
104
|
-
if (this.url === url && this.opacity === opacity) return true;
|
|
105
|
-
|
|
106
|
-
this.url = url;
|
|
107
|
-
this.opacity = opacity;
|
|
108
|
-
|
|
109
|
-
this.updateFilm();
|
|
110
|
-
|
|
111
|
-
return true;
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
] as CommandContribution[],
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private initLayer() {
|
|
119
|
-
if (!this.canvasService) return;
|
|
120
|
-
let overlayLayer = this.canvasService.getLayer("overlay");
|
|
121
|
-
if (!overlayLayer) {
|
|
122
|
-
const width = this.canvasService.canvas.width || 800;
|
|
123
|
-
const height = this.canvasService.canvas.height || 600;
|
|
124
|
-
|
|
125
|
-
const layer = this.canvasService.createLayer("overlay", {
|
|
126
|
-
width,
|
|
127
|
-
height,
|
|
128
|
-
left: 0,
|
|
129
|
-
top: 0,
|
|
130
|
-
originX: "left",
|
|
131
|
-
originY: "top",
|
|
132
|
-
selectable: false,
|
|
133
|
-
evented: false,
|
|
134
|
-
subTargetCheck: false,
|
|
135
|
-
interactive: false,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
this.canvasService.canvas.bringObjectToFront(layer);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private async updateFilm() {
|
|
143
|
-
if (!this.canvasService) return;
|
|
144
|
-
const layer = this.canvasService.getLayer("overlay");
|
|
145
|
-
if (!layer) {
|
|
146
|
-
console.warn("[FilmTool] Overlay layer not found");
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const { url, opacity } = this;
|
|
151
|
-
|
|
152
|
-
if (!url) {
|
|
153
|
-
const img = this.canvasService.getObject("film-image", "overlay");
|
|
154
|
-
if (img) {
|
|
155
|
-
layer.remove(img);
|
|
156
|
-
this.canvasService.requestRenderAll();
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const width = this.canvasService.canvas.width || 800;
|
|
162
|
-
const height = this.canvasService.canvas.height || 600;
|
|
163
|
-
|
|
164
|
-
let img = this.canvasService.getObject("film-image", "overlay") as Image;
|
|
165
|
-
try {
|
|
166
|
-
if (img) {
|
|
167
|
-
if (img.getSrc() !== url) {
|
|
168
|
-
await img.setSrc(url);
|
|
169
|
-
}
|
|
170
|
-
img.set({ opacity });
|
|
171
|
-
} else {
|
|
172
|
-
img = await Image.fromURL(url, { crossOrigin: "anonymous" });
|
|
173
|
-
img.scaleToWidth(width);
|
|
174
|
-
if (img.getScaledHeight() < height) img.scaleToHeight(height);
|
|
175
|
-
img.set({
|
|
176
|
-
originX: "left",
|
|
177
|
-
originY: "top",
|
|
178
|
-
left: 0,
|
|
179
|
-
top: 0,
|
|
180
|
-
opacity,
|
|
181
|
-
selectable: false,
|
|
182
|
-
evented: false,
|
|
183
|
-
data: { id: "film-image" },
|
|
184
|
-
});
|
|
185
|
-
layer.add(img);
|
|
186
|
-
}
|
|
187
|
-
this.canvasService.requestRenderAll();
|
|
188
|
-
} catch (error) {
|
|
189
|
-
console.error("[FilmTool] Failed to load film image", url, error);
|
|
190
|
-
}
|
|
191
|
-
layer.dirty = true;
|
|
192
|
-
this.canvasService.requestRenderAll();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
} from "@pooder/core";
|
|
8
|
+
import { FabricImage as Image } from "fabric";
|
|
9
|
+
import CanvasService from "./CanvasService";
|
|
10
|
+
|
|
11
|
+
export class FilmTool implements Extension {
|
|
12
|
+
id = "pooder.kit.film";
|
|
13
|
+
|
|
14
|
+
public metadata = {
|
|
15
|
+
name: "FilmTool",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
private url: string = "";
|
|
19
|
+
private opacity: number = 0.5;
|
|
20
|
+
|
|
21
|
+
private canvasService?: CanvasService;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
options?: Partial<{
|
|
25
|
+
url: string;
|
|
26
|
+
opacity: number;
|
|
27
|
+
}>,
|
|
28
|
+
) {
|
|
29
|
+
if (options) {
|
|
30
|
+
Object.assign(this, options);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
activate(context: ExtensionContext) {
|
|
35
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
36
|
+
if (!this.canvasService) {
|
|
37
|
+
console.warn("CanvasService not found for FilmTool");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const configService = context.services.get<any>("ConfigurationService");
|
|
42
|
+
if (configService) {
|
|
43
|
+
// Load initial config
|
|
44
|
+
this.url = configService.get("film.url", this.url);
|
|
45
|
+
this.opacity = configService.get("film.opacity", this.opacity);
|
|
46
|
+
|
|
47
|
+
// Listen for changes
|
|
48
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
49
|
+
if (e.key.startsWith("film.")) {
|
|
50
|
+
const prop = e.key.split(".")[1];
|
|
51
|
+
console.log(
|
|
52
|
+
`[FilmTool] Config change detected: ${e.key} -> ${e.value}`,
|
|
53
|
+
);
|
|
54
|
+
if (prop && prop in this) {
|
|
55
|
+
(this as any)[prop] = e.value;
|
|
56
|
+
this.updateFilm();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.initLayer();
|
|
63
|
+
this.updateFilm();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
deactivate(context: ExtensionContext) {
|
|
67
|
+
if (this.canvasService) {
|
|
68
|
+
const layer = this.canvasService.getLayer("overlay");
|
|
69
|
+
if (layer) {
|
|
70
|
+
const img = this.canvasService.getObject("film-image", "overlay");
|
|
71
|
+
if (img) {
|
|
72
|
+
layer.remove(img);
|
|
73
|
+
this.canvasService.requestRenderAll();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
this.canvasService = undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
contribute() {
|
|
81
|
+
return {
|
|
82
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
83
|
+
{
|
|
84
|
+
id: "film.url",
|
|
85
|
+
type: "string",
|
|
86
|
+
label: "Film Image URL",
|
|
87
|
+
default: "",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "film.opacity",
|
|
91
|
+
type: "number",
|
|
92
|
+
label: "Opacity",
|
|
93
|
+
min: 0,
|
|
94
|
+
max: 1,
|
|
95
|
+
step: 0.1,
|
|
96
|
+
default: 0.5,
|
|
97
|
+
},
|
|
98
|
+
] as ConfigurationContribution[],
|
|
99
|
+
[ContributionPointIds.COMMANDS]: [
|
|
100
|
+
{
|
|
101
|
+
command: "setFilmImage",
|
|
102
|
+
title: "Set Film Image",
|
|
103
|
+
handler: (url: string, opacity: number) => {
|
|
104
|
+
if (this.url === url && this.opacity === opacity) return true;
|
|
105
|
+
|
|
106
|
+
this.url = url;
|
|
107
|
+
this.opacity = opacity;
|
|
108
|
+
|
|
109
|
+
this.updateFilm();
|
|
110
|
+
|
|
111
|
+
return true;
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
] as CommandContribution[],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private initLayer() {
|
|
119
|
+
if (!this.canvasService) return;
|
|
120
|
+
let overlayLayer = this.canvasService.getLayer("overlay");
|
|
121
|
+
if (!overlayLayer) {
|
|
122
|
+
const width = this.canvasService.canvas.width || 800;
|
|
123
|
+
const height = this.canvasService.canvas.height || 600;
|
|
124
|
+
|
|
125
|
+
const layer = this.canvasService.createLayer("overlay", {
|
|
126
|
+
width,
|
|
127
|
+
height,
|
|
128
|
+
left: 0,
|
|
129
|
+
top: 0,
|
|
130
|
+
originX: "left",
|
|
131
|
+
originY: "top",
|
|
132
|
+
selectable: false,
|
|
133
|
+
evented: false,
|
|
134
|
+
subTargetCheck: false,
|
|
135
|
+
interactive: false,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async updateFilm() {
|
|
143
|
+
if (!this.canvasService) return;
|
|
144
|
+
const layer = this.canvasService.getLayer("overlay");
|
|
145
|
+
if (!layer) {
|
|
146
|
+
console.warn("[FilmTool] Overlay layer not found");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const { url, opacity } = this;
|
|
151
|
+
|
|
152
|
+
if (!url) {
|
|
153
|
+
const img = this.canvasService.getObject("film-image", "overlay");
|
|
154
|
+
if (img) {
|
|
155
|
+
layer.remove(img);
|
|
156
|
+
this.canvasService.requestRenderAll();
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const width = this.canvasService.canvas.width || 800;
|
|
162
|
+
const height = this.canvasService.canvas.height || 600;
|
|
163
|
+
|
|
164
|
+
let img = this.canvasService.getObject("film-image", "overlay") as Image;
|
|
165
|
+
try {
|
|
166
|
+
if (img) {
|
|
167
|
+
if (img.getSrc() !== url) {
|
|
168
|
+
await img.setSrc(url);
|
|
169
|
+
}
|
|
170
|
+
img.set({ opacity });
|
|
171
|
+
} else {
|
|
172
|
+
img = await Image.fromURL(url, { crossOrigin: "anonymous" });
|
|
173
|
+
img.scaleToWidth(width);
|
|
174
|
+
if (img.getScaledHeight() < height) img.scaleToHeight(height);
|
|
175
|
+
img.set({
|
|
176
|
+
originX: "left",
|
|
177
|
+
originY: "top",
|
|
178
|
+
left: 0,
|
|
179
|
+
top: 0,
|
|
180
|
+
opacity,
|
|
181
|
+
selectable: false,
|
|
182
|
+
evented: false,
|
|
183
|
+
data: { id: "film-image" },
|
|
184
|
+
});
|
|
185
|
+
layer.add(img);
|
|
186
|
+
}
|
|
187
|
+
this.canvasService.requestRenderAll();
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error("[FilmTool] Failed to load film image", url, error);
|
|
190
|
+
}
|
|
191
|
+
layer.dirty = true;
|
|
192
|
+
this.canvasService.requestRenderAll();
|
|
193
|
+
}
|
|
194
|
+
}
|