@pooder/kit 6.0.1 → 6.1.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/.test-dist/src/extensions/background/BackgroundTool.js +524 -0
- package/.test-dist/src/extensions/background/index.js +17 -0
- package/.test-dist/src/extensions/dieline/DielineTool.js +748 -0
- package/.test-dist/src/extensions/dieline/commands.js +127 -0
- package/.test-dist/src/extensions/dieline/config.js +107 -0
- package/.test-dist/src/extensions/dieline/index.js +21 -0
- package/.test-dist/src/extensions/dieline/model.js +2 -0
- package/.test-dist/src/extensions/dieline/renderer.js +2 -0
- package/.test-dist/src/extensions/feature/FeatureTool.js +914 -0
- package/.test-dist/src/extensions/feature/index.js +17 -0
- package/.test-dist/src/extensions/film/FilmTool.js +207 -0
- package/.test-dist/src/extensions/film/index.js +17 -0
- package/.test-dist/src/extensions/image/ImageTool.js +1499 -0
- package/.test-dist/src/extensions/image/commands.js +162 -0
- package/.test-dist/src/extensions/image/config.js +129 -0
- package/.test-dist/src/extensions/image/index.js +21 -0
- package/.test-dist/src/extensions/image/model.js +2 -0
- package/.test-dist/src/extensions/image/renderer.js +5 -0
- package/.test-dist/src/extensions/mirror/MirrorTool.js +104 -0
- package/.test-dist/src/extensions/mirror/index.js +17 -0
- package/.test-dist/src/extensions/ruler/RulerTool.js +442 -0
- package/.test-dist/src/extensions/ruler/index.js +17 -0
- package/.test-dist/src/extensions/sceneLayout.js +2 -93
- package/.test-dist/src/extensions/sceneLayoutModel.js +15 -200
- package/.test-dist/src/extensions/size/SizeTool.js +332 -0
- package/.test-dist/src/extensions/size/index.js +17 -0
- package/.test-dist/src/extensions/white-ink/WhiteInkTool.js +1003 -0
- package/.test-dist/src/extensions/white-ink/commands.js +148 -0
- package/.test-dist/src/extensions/white-ink/config.js +31 -0
- package/.test-dist/src/extensions/white-ink/index.js +21 -0
- package/.test-dist/src/extensions/white-ink/model.js +2 -0
- package/.test-dist/src/extensions/white-ink/renderer.js +5 -0
- package/.test-dist/src/services/SceneLayoutService.js +96 -0
- package/.test-dist/src/services/index.js +1 -0
- package/.test-dist/src/shared/constants/layers.js +25 -0
- package/.test-dist/src/shared/imaging/sourceSizeCache.js +82 -0
- package/.test-dist/src/shared/index.js +22 -0
- package/.test-dist/src/shared/runtime/sessionState.js +74 -0
- package/.test-dist/src/shared/runtime/subscriptions.js +30 -0
- package/.test-dist/src/shared/scene/frame.js +34 -0
- package/.test-dist/src/shared/scene/sceneLayoutModel.js +202 -0
- package/.test-dist/tests/run.js +116 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +390 -367
- package/dist/index.d.ts +390 -367
- package/dist/index.js +5138 -4927
- package/dist/index.mjs +1149 -1977
- package/dist/tracer-PO7CRBYY.mjs +1016 -0
- package/package.json +1 -1
- package/src/extensions/{background.ts → background/BackgroundTool.ts} +33 -50
- package/src/extensions/background/index.ts +1 -0
- package/src/extensions/{dieline.ts → dieline/DielineTool.ts} +14 -218
- package/src/extensions/dieline/commands.ts +109 -0
- package/src/extensions/dieline/config.ts +106 -0
- package/src/extensions/dieline/index.ts +5 -0
- package/src/extensions/dieline/model.ts +1 -0
- package/src/extensions/dieline/renderer.ts +1 -0
- package/src/extensions/{feature.ts → feature/FeatureTool.ts} +27 -21
- package/src/extensions/feature/index.ts +1 -0
- package/src/extensions/{film.ts → film/FilmTool.ts} +36 -48
- package/src/extensions/film/index.ts +1 -0
- package/src/extensions/{image.ts → image/ImageTool.ts} +123 -402
- package/src/extensions/image/commands.ts +176 -0
- package/src/extensions/image/config.ts +128 -0
- package/src/extensions/image/index.ts +5 -0
- package/src/extensions/image/model.ts +1 -0
- package/src/extensions/image/renderer.ts +1 -0
- package/src/extensions/{mirror.ts → mirror/MirrorTool.ts} +1 -1
- package/src/extensions/mirror/index.ts +1 -0
- package/src/extensions/{ruler.ts → ruler/RulerTool.ts} +4 -5
- package/src/extensions/ruler/index.ts +1 -0
- package/src/extensions/sceneLayout.ts +1 -140
- package/src/extensions/sceneLayoutModel.ts +1 -364
- package/src/extensions/{size.ts → size/SizeTool.ts} +7 -6
- package/src/extensions/size/index.ts +1 -0
- package/src/extensions/{white-ink.ts → white-ink/WhiteInkTool.ts} +130 -317
- package/src/extensions/white-ink/commands.ts +157 -0
- package/src/extensions/white-ink/config.ts +30 -0
- package/src/extensions/white-ink/index.ts +5 -0
- package/src/extensions/white-ink/model.ts +1 -0
- package/src/extensions/white-ink/renderer.ts +1 -0
- package/src/services/SceneLayoutService.ts +139 -0
- package/src/services/index.ts +1 -0
- package/src/shared/constants/layers.ts +23 -0
- package/src/shared/imaging/sourceSizeCache.ts +103 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/runtime/sessionState.ts +105 -0
- package/src/shared/runtime/subscriptions.ts +45 -0
- package/src/shared/scene/frame.ts +46 -0
- package/src/shared/scene/sceneLayoutModel.ts +367 -0
- package/tests/run.ts +146 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./FeatureTool"), exports);
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilmTool = void 0;
|
|
4
|
+
const core_1 = require("@pooder/core");
|
|
5
|
+
const fabric_1 = require("fabric");
|
|
6
|
+
const layers_1 = require("../../shared/constants/layers");
|
|
7
|
+
const sourceSizeCache_1 = require("../../shared/imaging/sourceSizeCache");
|
|
8
|
+
const subscriptions_1 = require("../../shared/runtime/subscriptions");
|
|
9
|
+
const FILM_IMAGE_ID = "film-image";
|
|
10
|
+
const DEFAULT_WIDTH = 800;
|
|
11
|
+
const DEFAULT_HEIGHT = 600;
|
|
12
|
+
class FilmTool {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.id = "pooder.kit.film";
|
|
15
|
+
this.metadata = {
|
|
16
|
+
name: "FilmTool",
|
|
17
|
+
};
|
|
18
|
+
this.url = "";
|
|
19
|
+
this.opacity = 0.5;
|
|
20
|
+
this.specs = [];
|
|
21
|
+
this.renderSeq = 0;
|
|
22
|
+
this.renderImageUrl = "";
|
|
23
|
+
this.sourceSizeCache = (0, sourceSizeCache_1.createSourceSizeCache)((src) => this.loadImageSize(src));
|
|
24
|
+
this.subscriptions = new subscriptions_1.SubscriptionBag();
|
|
25
|
+
this.onCanvasResized = () => {
|
|
26
|
+
this.updateFilm();
|
|
27
|
+
};
|
|
28
|
+
if (options) {
|
|
29
|
+
Object.assign(this, options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
activate(context) {
|
|
33
|
+
this.subscriptions.disposeAll();
|
|
34
|
+
this.canvasService = context.services.get("CanvasService");
|
|
35
|
+
if (!this.canvasService) {
|
|
36
|
+
console.warn("CanvasService not found for FilmTool");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.renderProducerDisposable?.dispose();
|
|
40
|
+
this.renderProducerDisposable = this.canvasService.registerRenderProducer(this.id, () => ({
|
|
41
|
+
passes: [
|
|
42
|
+
{
|
|
43
|
+
id: layers_1.FILM_LAYER_ID,
|
|
44
|
+
stack: 1000,
|
|
45
|
+
order: 0,
|
|
46
|
+
objects: this.specs,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
}), { priority: 500 });
|
|
50
|
+
const configService = context.services.get("ConfigurationService");
|
|
51
|
+
if (configService) {
|
|
52
|
+
// Load initial config
|
|
53
|
+
this.url = configService.get("film.url", this.url);
|
|
54
|
+
this.opacity = configService.get("film.opacity", this.opacity);
|
|
55
|
+
// Listen for changes
|
|
56
|
+
this.subscriptions.onConfigChange(configService, (e) => {
|
|
57
|
+
if (e.key.startsWith("film.")) {
|
|
58
|
+
const prop = e.key.split(".")[1];
|
|
59
|
+
console.log(`[FilmTool] Config change detected: ${e.key} -> ${e.value}`);
|
|
60
|
+
if (prop && prop in this) {
|
|
61
|
+
this[prop] = e.value;
|
|
62
|
+
this.updateFilm();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
this.subscriptions.on(context.eventBus, "canvas:resized", this.onCanvasResized);
|
|
68
|
+
this.updateFilm();
|
|
69
|
+
}
|
|
70
|
+
deactivate(context) {
|
|
71
|
+
this.subscriptions.disposeAll();
|
|
72
|
+
this.renderSeq += 1;
|
|
73
|
+
this.specs = [];
|
|
74
|
+
this.renderImageUrl = "";
|
|
75
|
+
this.sourceSizeCache.clear();
|
|
76
|
+
this.renderProducerDisposable?.dispose();
|
|
77
|
+
this.renderProducerDisposable = undefined;
|
|
78
|
+
if (!this.canvasService)
|
|
79
|
+
return;
|
|
80
|
+
void this.canvasService.flushRenderFromProducers();
|
|
81
|
+
this.canvasService.requestRenderAll();
|
|
82
|
+
this.canvasService = undefined;
|
|
83
|
+
}
|
|
84
|
+
contribute() {
|
|
85
|
+
return {
|
|
86
|
+
[core_1.ContributionPointIds.CONFIGURATIONS]: [
|
|
87
|
+
{
|
|
88
|
+
id: "film.url",
|
|
89
|
+
type: "string",
|
|
90
|
+
label: "Film Image URL",
|
|
91
|
+
default: "",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "film.opacity",
|
|
95
|
+
type: "number",
|
|
96
|
+
label: "Opacity",
|
|
97
|
+
min: 0,
|
|
98
|
+
max: 1,
|
|
99
|
+
step: 0.1,
|
|
100
|
+
default: 0.5,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[core_1.ContributionPointIds.COMMANDS]: [
|
|
104
|
+
{
|
|
105
|
+
command: "setFilmImage",
|
|
106
|
+
title: "Set Film Image",
|
|
107
|
+
handler: (url, opacity) => {
|
|
108
|
+
if (this.url === url && this.opacity === opacity)
|
|
109
|
+
return true;
|
|
110
|
+
this.url = url;
|
|
111
|
+
this.opacity = opacity;
|
|
112
|
+
this.updateFilm();
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
getViewportSize() {
|
|
120
|
+
const width = Number(this.canvasService?.canvas.width || 0);
|
|
121
|
+
const height = Number(this.canvasService?.canvas.height || 0);
|
|
122
|
+
return {
|
|
123
|
+
width: width > 0 ? width : DEFAULT_WIDTH,
|
|
124
|
+
height: height > 0 ? height : DEFAULT_HEIGHT,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
clampOpacity(value) {
|
|
128
|
+
return Math.max(0, Math.min(1, Number(value)));
|
|
129
|
+
}
|
|
130
|
+
buildFilmSpecs(imageUrl, opacity) {
|
|
131
|
+
if (!imageUrl) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const { width, height } = this.getViewportSize();
|
|
135
|
+
const sourceSize = this.sourceSizeCache.getSourceSize(imageUrl);
|
|
136
|
+
const sourceWidth = Math.max(1, Number(sourceSize?.width || width));
|
|
137
|
+
const sourceHeight = Math.max(1, Number(sourceSize?.height || height));
|
|
138
|
+
const coverScale = (0, sourceSizeCache_1.getCoverScale)({ width, height }, { width: sourceWidth, height: sourceHeight });
|
|
139
|
+
return [
|
|
140
|
+
{
|
|
141
|
+
id: FILM_IMAGE_ID,
|
|
142
|
+
type: "image",
|
|
143
|
+
src: imageUrl,
|
|
144
|
+
space: "screen",
|
|
145
|
+
data: {
|
|
146
|
+
id: FILM_IMAGE_ID,
|
|
147
|
+
layerId: layers_1.FILM_LAYER_ID,
|
|
148
|
+
type: "film-image",
|
|
149
|
+
},
|
|
150
|
+
props: {
|
|
151
|
+
left: 0,
|
|
152
|
+
top: 0,
|
|
153
|
+
originX: "left",
|
|
154
|
+
originY: "top",
|
|
155
|
+
opacity: this.clampOpacity(opacity),
|
|
156
|
+
scaleX: coverScale,
|
|
157
|
+
scaleY: coverScale,
|
|
158
|
+
selectable: false,
|
|
159
|
+
evented: false,
|
|
160
|
+
excludeFromExport: true,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
async loadImageSize(src) {
|
|
166
|
+
try {
|
|
167
|
+
const image = await fabric_1.FabricImage.fromURL(src, {
|
|
168
|
+
crossOrigin: "anonymous",
|
|
169
|
+
});
|
|
170
|
+
const width = Number(image?.width || 0);
|
|
171
|
+
const height = Number(image?.height || 0);
|
|
172
|
+
if (width > 0 && height > 0) {
|
|
173
|
+
return { width, height };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error("[FilmTool] Failed to load film image", src, error);
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
updateFilm() {
|
|
182
|
+
void this.updateFilmAsync();
|
|
183
|
+
}
|
|
184
|
+
async updateFilmAsync() {
|
|
185
|
+
if (!this.canvasService)
|
|
186
|
+
return;
|
|
187
|
+
const seq = ++this.renderSeq;
|
|
188
|
+
const nextUrl = String(this.url || "").trim();
|
|
189
|
+
if (!nextUrl) {
|
|
190
|
+
this.renderImageUrl = "";
|
|
191
|
+
}
|
|
192
|
+
else if (nextUrl !== this.renderImageUrl) {
|
|
193
|
+
const loaded = await this.sourceSizeCache.ensureImageSize(nextUrl);
|
|
194
|
+
if (seq !== this.renderSeq)
|
|
195
|
+
return;
|
|
196
|
+
if (loaded) {
|
|
197
|
+
this.renderImageUrl = nextUrl;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
this.specs = this.buildFilmSpecs(this.renderImageUrl, this.opacity);
|
|
201
|
+
await this.canvasService.flushRenderFromProducers();
|
|
202
|
+
if (seq !== this.renderSeq)
|
|
203
|
+
return;
|
|
204
|
+
this.canvasService.requestRenderAll();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.FilmTool = FilmTool;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./FilmTool"), exports);
|