@pooder/kit 5.4.0 → 6.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/.test-dist/src/coordinate.js +74 -0
- package/.test-dist/src/extensions/background.js +547 -0
- package/.test-dist/src/extensions/bridgeSelection.js +20 -0
- package/.test-dist/src/extensions/constraints.js +237 -0
- package/.test-dist/src/extensions/dieline.js +931 -0
- package/.test-dist/src/extensions/dielineShape.js +66 -0
- package/.test-dist/src/extensions/edgeScale.js +12 -0
- package/.test-dist/src/extensions/feature.js +910 -0
- package/.test-dist/src/extensions/featureComplete.js +32 -0
- package/.test-dist/src/extensions/film.js +226 -0
- package/.test-dist/src/extensions/geometry.js +609 -0
- package/.test-dist/src/extensions/image.js +1613 -0
- package/.test-dist/src/extensions/index.js +28 -0
- package/.test-dist/src/extensions/maskOps.js +334 -0
- package/.test-dist/src/extensions/mirror.js +104 -0
- package/.test-dist/src/extensions/ruler.js +442 -0
- package/.test-dist/src/extensions/sceneLayout.js +96 -0
- package/.test-dist/src/extensions/sceneLayoutModel.js +202 -0
- package/.test-dist/src/extensions/sceneVisibility.js +55 -0
- package/.test-dist/src/extensions/size.js +331 -0
- package/.test-dist/src/extensions/tracer.js +709 -0
- package/.test-dist/src/extensions/white-ink.js +1200 -0
- package/.test-dist/src/extensions/wrappedOffsets.js +33 -0
- package/.test-dist/src/index.js +18 -0
- package/.test-dist/src/services/CanvasService.js +1011 -0
- package/.test-dist/src/services/ViewportSystem.js +76 -0
- package/.test-dist/src/services/index.js +25 -0
- package/.test-dist/src/services/renderSpec.js +2 -0
- package/.test-dist/src/services/visibility.js +54 -0
- package/.test-dist/src/units.js +30 -0
- package/.test-dist/tests/run.js +148 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +150 -62
- package/dist/index.d.ts +150 -62
- package/dist/index.js +2219 -1714
- package/dist/index.mjs +2226 -1718
- package/package.json +1 -1
- package/src/coordinate.ts +106 -106
- package/src/extensions/background.ts +716 -323
- package/src/extensions/bridgeSelection.ts +17 -17
- package/src/extensions/constraints.ts +322 -322
- package/src/extensions/dieline.ts +1169 -1149
- package/src/extensions/dielineShape.ts +109 -109
- package/src/extensions/edgeScale.ts +19 -19
- package/src/extensions/feature.ts +1140 -1137
- package/src/extensions/featureComplete.ts +46 -46
- package/src/extensions/film.ts +270 -266
- package/src/extensions/geometry.ts +851 -885
- package/src/extensions/image.ts +2007 -2054
- package/src/extensions/index.ts +10 -11
- package/src/extensions/maskOps.ts +283 -283
- package/src/extensions/mirror.ts +128 -128
- package/src/extensions/ruler.ts +664 -654
- package/src/extensions/sceneLayout.ts +140 -140
- package/src/extensions/sceneLayoutModel.ts +364 -364
- package/src/extensions/size.ts +389 -389
- package/src/extensions/tracer.ts +1019 -1019
- package/src/extensions/white-ink.ts +1508 -1575
- package/src/extensions/wrappedOffsets.ts +33 -33
- package/src/index.ts +2 -2
- package/src/services/CanvasService.ts +1286 -832
- package/src/services/ViewportSystem.ts +95 -95
- package/src/services/index.ts +4 -3
- package/src/services/renderSpec.ts +83 -53
- package/src/services/visibility.ts +78 -0
- package/src/units.ts +27 -27
- package/tests/run.ts +253 -118
- package/tsconfig.test.json +15 -15
- package/src/extensions/sceneVisibility.ts +0 -64
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFeaturesStrict = validateFeaturesStrict;
|
|
4
|
+
exports.completeFeaturesStrict = completeFeaturesStrict;
|
|
5
|
+
const constraints_1 = require("./constraints");
|
|
6
|
+
function validateFeaturesStrict(features, context) {
|
|
7
|
+
const eps = 1e-6;
|
|
8
|
+
const issues = [];
|
|
9
|
+
for (const f of features) {
|
|
10
|
+
if (!f.constraints || f.constraints.length === 0)
|
|
11
|
+
continue;
|
|
12
|
+
// Pass ALL constraints (including validateOnly) for strict validation check
|
|
13
|
+
const constrained = constraints_1.ConstraintRegistry.apply(f.x, f.y, f, context, f.constraints);
|
|
14
|
+
if (Math.abs(constrained.x - f.x) > eps ||
|
|
15
|
+
Math.abs(constrained.y - f.y) > eps) {
|
|
16
|
+
issues.push({
|
|
17
|
+
featureId: f.id,
|
|
18
|
+
groupId: f.groupId,
|
|
19
|
+
reason: "Position violates constraint strategy",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { ok: issues.length === 0, issues: issues.length ? issues : undefined };
|
|
24
|
+
}
|
|
25
|
+
function completeFeaturesStrict(features, context, update) {
|
|
26
|
+
const validation = validateFeaturesStrict(features, context);
|
|
27
|
+
if (!validation.ok)
|
|
28
|
+
return validation;
|
|
29
|
+
const next = JSON.parse(JSON.stringify(features || []));
|
|
30
|
+
update(next);
|
|
31
|
+
return { ok: true };
|
|
32
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
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 FILM_LAYER_ID = "overlay";
|
|
7
|
+
const FILM_IMAGE_ID = "film-image";
|
|
8
|
+
const DEFAULT_WIDTH = 800;
|
|
9
|
+
const DEFAULT_HEIGHT = 600;
|
|
10
|
+
class FilmTool {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.id = "pooder.kit.film";
|
|
13
|
+
this.metadata = {
|
|
14
|
+
name: "FilmTool",
|
|
15
|
+
};
|
|
16
|
+
this.url = "";
|
|
17
|
+
this.opacity = 0.5;
|
|
18
|
+
this.specs = [];
|
|
19
|
+
this.renderSeq = 0;
|
|
20
|
+
this.renderImageUrl = "";
|
|
21
|
+
this.sourceSizeBySrc = new Map();
|
|
22
|
+
this.pendingSizeBySrc = new Map();
|
|
23
|
+
this.onCanvasResized = () => {
|
|
24
|
+
this.updateFilm();
|
|
25
|
+
};
|
|
26
|
+
if (options) {
|
|
27
|
+
Object.assign(this, options);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
activate(context) {
|
|
31
|
+
this.canvasService = context.services.get("CanvasService");
|
|
32
|
+
if (!this.canvasService) {
|
|
33
|
+
console.warn("CanvasService not found for FilmTool");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.renderProducerDisposable?.dispose();
|
|
37
|
+
this.renderProducerDisposable = this.canvasService.registerRenderProducer(this.id, () => ({
|
|
38
|
+
passes: [
|
|
39
|
+
{
|
|
40
|
+
id: FILM_LAYER_ID,
|
|
41
|
+
stack: 1000,
|
|
42
|
+
order: 0,
|
|
43
|
+
objects: this.specs,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
}), { priority: 500 });
|
|
47
|
+
const configService = context.services.get("ConfigurationService");
|
|
48
|
+
if (configService) {
|
|
49
|
+
// Load initial config
|
|
50
|
+
this.url = configService.get("film.url", this.url);
|
|
51
|
+
this.opacity = configService.get("film.opacity", this.opacity);
|
|
52
|
+
// Listen for changes
|
|
53
|
+
configService.onAnyChange((e) => {
|
|
54
|
+
if (e.key.startsWith("film.")) {
|
|
55
|
+
const prop = e.key.split(".")[1];
|
|
56
|
+
console.log(`[FilmTool] Config change detected: ${e.key} -> ${e.value}`);
|
|
57
|
+
if (prop && prop in this) {
|
|
58
|
+
this[prop] = e.value;
|
|
59
|
+
this.updateFilm();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
context.eventBus.on("canvas:resized", this.onCanvasResized);
|
|
65
|
+
this.updateFilm();
|
|
66
|
+
}
|
|
67
|
+
deactivate(context) {
|
|
68
|
+
context.eventBus.off("canvas:resized", this.onCanvasResized);
|
|
69
|
+
this.renderSeq += 1;
|
|
70
|
+
this.specs = [];
|
|
71
|
+
this.renderImageUrl = "";
|
|
72
|
+
this.renderProducerDisposable?.dispose();
|
|
73
|
+
this.renderProducerDisposable = undefined;
|
|
74
|
+
if (!this.canvasService)
|
|
75
|
+
return;
|
|
76
|
+
void this.canvasService.flushRenderFromProducers();
|
|
77
|
+
this.canvasService.requestRenderAll();
|
|
78
|
+
this.canvasService = undefined;
|
|
79
|
+
}
|
|
80
|
+
contribute() {
|
|
81
|
+
return {
|
|
82
|
+
[core_1.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
|
+
],
|
|
99
|
+
[core_1.ContributionPointIds.COMMANDS]: [
|
|
100
|
+
{
|
|
101
|
+
command: "setFilmImage",
|
|
102
|
+
title: "Set Film Image",
|
|
103
|
+
handler: (url, opacity) => {
|
|
104
|
+
if (this.url === url && this.opacity === opacity)
|
|
105
|
+
return true;
|
|
106
|
+
this.url = url;
|
|
107
|
+
this.opacity = opacity;
|
|
108
|
+
this.updateFilm();
|
|
109
|
+
return true;
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
getViewportSize() {
|
|
116
|
+
const width = Number(this.canvasService?.canvas.width || 0);
|
|
117
|
+
const height = Number(this.canvasService?.canvas.height || 0);
|
|
118
|
+
return {
|
|
119
|
+
width: width > 0 ? width : DEFAULT_WIDTH,
|
|
120
|
+
height: height > 0 ? height : DEFAULT_HEIGHT,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
clampOpacity(value) {
|
|
124
|
+
return Math.max(0, Math.min(1, Number(value)));
|
|
125
|
+
}
|
|
126
|
+
buildFilmSpecs(imageUrl, opacity) {
|
|
127
|
+
if (!imageUrl) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
const { width, height } = this.getViewportSize();
|
|
131
|
+
const sourceSize = this.sourceSizeBySrc.get(imageUrl);
|
|
132
|
+
const sourceWidth = Math.max(1, Number(sourceSize?.width || width));
|
|
133
|
+
const sourceHeight = Math.max(1, Number(sourceSize?.height || height));
|
|
134
|
+
const coverScale = Math.max(width / sourceWidth, height / sourceHeight);
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
id: FILM_IMAGE_ID,
|
|
138
|
+
type: "image",
|
|
139
|
+
src: imageUrl,
|
|
140
|
+
space: "screen",
|
|
141
|
+
data: {
|
|
142
|
+
id: FILM_IMAGE_ID,
|
|
143
|
+
layerId: FILM_LAYER_ID,
|
|
144
|
+
type: "film-image",
|
|
145
|
+
},
|
|
146
|
+
props: {
|
|
147
|
+
left: 0,
|
|
148
|
+
top: 0,
|
|
149
|
+
originX: "left",
|
|
150
|
+
originY: "top",
|
|
151
|
+
opacity: this.clampOpacity(opacity),
|
|
152
|
+
scaleX: coverScale,
|
|
153
|
+
scaleY: coverScale,
|
|
154
|
+
selectable: false,
|
|
155
|
+
evented: false,
|
|
156
|
+
excludeFromExport: true,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
async ensureImageSize(src) {
|
|
162
|
+
if (!src)
|
|
163
|
+
return null;
|
|
164
|
+
const cached = this.sourceSizeBySrc.get(src);
|
|
165
|
+
if (cached)
|
|
166
|
+
return cached;
|
|
167
|
+
const pending = this.pendingSizeBySrc.get(src);
|
|
168
|
+
if (pending) {
|
|
169
|
+
return pending;
|
|
170
|
+
}
|
|
171
|
+
const task = this.loadImageSize(src);
|
|
172
|
+
this.pendingSizeBySrc.set(src, task);
|
|
173
|
+
try {
|
|
174
|
+
return await task;
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
if (this.pendingSizeBySrc.get(src) === task) {
|
|
178
|
+
this.pendingSizeBySrc.delete(src);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async loadImageSize(src) {
|
|
183
|
+
try {
|
|
184
|
+
const image = await fabric_1.FabricImage.fromURL(src, {
|
|
185
|
+
crossOrigin: "anonymous",
|
|
186
|
+
});
|
|
187
|
+
const width = Number(image?.width || 0);
|
|
188
|
+
const height = Number(image?.height || 0);
|
|
189
|
+
if (width > 0 && height > 0) {
|
|
190
|
+
const size = { width, height };
|
|
191
|
+
this.sourceSizeBySrc.set(src, size);
|
|
192
|
+
return size;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
console.error("[FilmTool] Failed to load film image", src, error);
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
updateFilm() {
|
|
201
|
+
void this.updateFilmAsync();
|
|
202
|
+
}
|
|
203
|
+
async updateFilmAsync() {
|
|
204
|
+
if (!this.canvasService)
|
|
205
|
+
return;
|
|
206
|
+
const seq = ++this.renderSeq;
|
|
207
|
+
const nextUrl = String(this.url || "").trim();
|
|
208
|
+
if (!nextUrl) {
|
|
209
|
+
this.renderImageUrl = "";
|
|
210
|
+
}
|
|
211
|
+
else if (nextUrl !== this.renderImageUrl) {
|
|
212
|
+
const loaded = await this.ensureImageSize(nextUrl);
|
|
213
|
+
if (seq !== this.renderSeq)
|
|
214
|
+
return;
|
|
215
|
+
if (loaded) {
|
|
216
|
+
this.renderImageUrl = nextUrl;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
this.specs = this.buildFilmSpecs(this.renderImageUrl, this.opacity);
|
|
220
|
+
await this.canvasService.flushRenderFromProducers();
|
|
221
|
+
if (seq !== this.renderSeq)
|
|
222
|
+
return;
|
|
223
|
+
this.canvasService.requestRenderAll();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.FilmTool = FilmTool;
|