@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/index.ts
CHANGED
package/src/mirror.ts
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
} from "@pooder/core";
|
|
8
|
-
import CanvasService from "./CanvasService";
|
|
9
|
-
|
|
10
|
-
export class MirrorTool implements Extension {
|
|
11
|
-
id = "pooder.kit.mirror";
|
|
12
|
-
|
|
13
|
-
public metadata = {
|
|
14
|
-
name: "MirrorTool",
|
|
15
|
-
};
|
|
16
|
-
private enabled = false;
|
|
17
|
-
|
|
18
|
-
private canvasService?: CanvasService;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
options?: Partial<{
|
|
22
|
-
enabled: boolean;
|
|
23
|
-
}>,
|
|
24
|
-
) {
|
|
25
|
-
if (options) {
|
|
26
|
-
Object.assign(this, options);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
toJSON() {
|
|
31
|
-
return {
|
|
32
|
-
enabled: this.enabled,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
loadFromJSON(json: any) {
|
|
37
|
-
this.enabled = json.enabled;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
activate(context: ExtensionContext) {
|
|
41
|
-
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
42
|
-
if (!this.canvasService) {
|
|
43
|
-
console.warn("CanvasService not found for MirrorTool");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const configService = context.services.get<any>("ConfigurationService");
|
|
48
|
-
if (configService) {
|
|
49
|
-
// Load initial config
|
|
50
|
-
this.enabled = configService.get("mirror.enabled", this.enabled);
|
|
51
|
-
|
|
52
|
-
// Listen for changes
|
|
53
|
-
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
54
|
-
if (e.key === "mirror.enabled") {
|
|
55
|
-
this.applyMirror(e.value);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Initialize with current state (if enabled was persisted)
|
|
61
|
-
if (this.enabled) {
|
|
62
|
-
this.applyMirror(true);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
deactivate(context: ExtensionContext) {
|
|
67
|
-
this.applyMirror(false);
|
|
68
|
-
this.canvasService = undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
contribute() {
|
|
72
|
-
return {
|
|
73
|
-
[ContributionPointIds.CONFIGURATIONS]: [
|
|
74
|
-
{
|
|
75
|
-
id: "mirror.enabled",
|
|
76
|
-
type: "boolean",
|
|
77
|
-
label: "Enable Mirror",
|
|
78
|
-
default: false,
|
|
79
|
-
},
|
|
80
|
-
] as ConfigurationContribution[],
|
|
81
|
-
[ContributionPointIds.COMMANDS]: [
|
|
82
|
-
{
|
|
83
|
-
command: "setMirror",
|
|
84
|
-
title: "Set Mirror",
|
|
85
|
-
handler: (enabled: boolean) => {
|
|
86
|
-
this.applyMirror(enabled);
|
|
87
|
-
return true;
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
] as CommandContribution[],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private applyMirror(enabled: boolean) {
|
|
95
|
-
if (!this.canvasService) return;
|
|
96
|
-
const canvas = this.canvasService.canvas;
|
|
97
|
-
if (!canvas) return;
|
|
98
|
-
|
|
99
|
-
const width = canvas.width || 800;
|
|
100
|
-
|
|
101
|
-
// Fabric.js v6+ uses viewportTransform property
|
|
102
|
-
let vpt = canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
|
|
103
|
-
// Create a copy to avoid mutating the reference directly before setting
|
|
104
|
-
vpt = [...vpt];
|
|
105
|
-
|
|
106
|
-
// If we are enabling and currently not flipped (scaleX > 0)
|
|
107
|
-
// Or disabling and currently flipped (scaleX < 0)
|
|
108
|
-
const isFlipped = vpt[0] < 0;
|
|
109
|
-
|
|
110
|
-
if (enabled && !isFlipped) {
|
|
111
|
-
// Flip scale X
|
|
112
|
-
vpt[0] = -vpt[0]; // Flip scale
|
|
113
|
-
vpt[4] = width - vpt[4]; // Adjust pan X
|
|
114
|
-
|
|
115
|
-
canvas.setViewportTransform(vpt as any);
|
|
116
|
-
canvas.requestRenderAll();
|
|
117
|
-
this.enabled = true;
|
|
118
|
-
} else if (!enabled && isFlipped) {
|
|
119
|
-
// Restore
|
|
120
|
-
vpt[0] = -vpt[0]; // Unflip scale
|
|
121
|
-
vpt[4] = width - vpt[4]; // Restore pan X
|
|
122
|
-
|
|
123
|
-
canvas.setViewportTransform(vpt as any);
|
|
124
|
-
canvas.requestRenderAll();
|
|
125
|
-
this.enabled = false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
} from "@pooder/core";
|
|
8
|
+
import CanvasService from "./CanvasService";
|
|
9
|
+
|
|
10
|
+
export class MirrorTool implements Extension {
|
|
11
|
+
id = "pooder.kit.mirror";
|
|
12
|
+
|
|
13
|
+
public metadata = {
|
|
14
|
+
name: "MirrorTool",
|
|
15
|
+
};
|
|
16
|
+
private enabled = false;
|
|
17
|
+
|
|
18
|
+
private canvasService?: CanvasService;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
options?: Partial<{
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
}>,
|
|
24
|
+
) {
|
|
25
|
+
if (options) {
|
|
26
|
+
Object.assign(this, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
toJSON() {
|
|
31
|
+
return {
|
|
32
|
+
enabled: this.enabled,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
loadFromJSON(json: any) {
|
|
37
|
+
this.enabled = json.enabled;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
activate(context: ExtensionContext) {
|
|
41
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
42
|
+
if (!this.canvasService) {
|
|
43
|
+
console.warn("CanvasService not found for MirrorTool");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const configService = context.services.get<any>("ConfigurationService");
|
|
48
|
+
if (configService) {
|
|
49
|
+
// Load initial config
|
|
50
|
+
this.enabled = configService.get("mirror.enabled", this.enabled);
|
|
51
|
+
|
|
52
|
+
// Listen for changes
|
|
53
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
54
|
+
if (e.key === "mirror.enabled") {
|
|
55
|
+
this.applyMirror(e.value);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Initialize with current state (if enabled was persisted)
|
|
61
|
+
if (this.enabled) {
|
|
62
|
+
this.applyMirror(true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
deactivate(context: ExtensionContext) {
|
|
67
|
+
this.applyMirror(false);
|
|
68
|
+
this.canvasService = undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
contribute() {
|
|
72
|
+
return {
|
|
73
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
74
|
+
{
|
|
75
|
+
id: "mirror.enabled",
|
|
76
|
+
type: "boolean",
|
|
77
|
+
label: "Enable Mirror",
|
|
78
|
+
default: false,
|
|
79
|
+
},
|
|
80
|
+
] as ConfigurationContribution[],
|
|
81
|
+
[ContributionPointIds.COMMANDS]: [
|
|
82
|
+
{
|
|
83
|
+
command: "setMirror",
|
|
84
|
+
title: "Set Mirror",
|
|
85
|
+
handler: (enabled: boolean) => {
|
|
86
|
+
this.applyMirror(enabled);
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
] as CommandContribution[],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private applyMirror(enabled: boolean) {
|
|
95
|
+
if (!this.canvasService) return;
|
|
96
|
+
const canvas = this.canvasService.canvas;
|
|
97
|
+
if (!canvas) return;
|
|
98
|
+
|
|
99
|
+
const width = canvas.width || 800;
|
|
100
|
+
|
|
101
|
+
// Fabric.js v6+ uses viewportTransform property
|
|
102
|
+
let vpt = canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
|
|
103
|
+
// Create a copy to avoid mutating the reference directly before setting
|
|
104
|
+
vpt = [...vpt];
|
|
105
|
+
|
|
106
|
+
// If we are enabling and currently not flipped (scaleX > 0)
|
|
107
|
+
// Or disabling and currently flipped (scaleX < 0)
|
|
108
|
+
const isFlipped = vpt[0] < 0;
|
|
109
|
+
|
|
110
|
+
if (enabled && !isFlipped) {
|
|
111
|
+
// Flip scale X
|
|
112
|
+
vpt[0] = -vpt[0]; // Flip scale
|
|
113
|
+
vpt[4] = width - vpt[4]; // Adjust pan X
|
|
114
|
+
|
|
115
|
+
canvas.setViewportTransform(vpt as any);
|
|
116
|
+
canvas.requestRenderAll();
|
|
117
|
+
this.enabled = true;
|
|
118
|
+
} else if (!enabled && isFlipped) {
|
|
119
|
+
// Restore
|
|
120
|
+
vpt[0] = -vpt[0]; // Unflip scale
|
|
121
|
+
vpt[4] = width - vpt[4]; // Restore pan X
|
|
122
|
+
|
|
123
|
+
canvas.setViewportTransform(vpt as any);
|
|
124
|
+
canvas.requestRenderAll();
|
|
125
|
+
this.enabled = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|