@pooder/kit 6.0.0 → 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/background.js +1 -1
- 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/dieline.js +4 -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/image.js +182 -7
- 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/CanvasService.js +34 -13
- package/.test-dist/src/services/SceneLayoutService.js +96 -0
- package/.test-dist/src/services/index.js +1 -0
- package/.test-dist/src/services/visibility.js +3 -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 +118 -0
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +403 -366
- package/dist/index.d.ts +403 -366
- package/dist/index.js +5172 -4752
- package/dist/index.mjs +1410 -2027
- 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} +18 -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} +289 -335
- 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/CanvasService.ts +43 -12
- package/src/services/SceneLayoutService.ts +139 -0
- package/src/services/index.ts +1 -0
- package/src/services/renderSpec.ts +2 -0
- package/src/services/visibility.ts +5 -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 +151 -0
|
@@ -6,16 +6,17 @@ import {
|
|
|
6
6
|
ConfigurationService,
|
|
7
7
|
ToolSessionService,
|
|
8
8
|
} from "@pooder/core";
|
|
9
|
-
import { CanvasService, RenderObjectSpec } from "
|
|
10
|
-
import { resolveFeaturePosition } from "
|
|
11
|
-
import { ConstraintRegistry, ConstraintFeature } from "
|
|
12
|
-
import { completeFeaturesStrict } from "
|
|
9
|
+
import { CanvasService, RenderObjectSpec } from "../../services";
|
|
10
|
+
import { resolveFeaturePosition } from "../geometry";
|
|
11
|
+
import { ConstraintRegistry, ConstraintFeature } from "../constraints";
|
|
12
|
+
import { completeFeaturesStrict } from "../featureComplete";
|
|
13
13
|
import {
|
|
14
14
|
readSizeState,
|
|
15
15
|
type SceneGeometrySnapshot as DielineGeometry,
|
|
16
|
-
} from "
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
} from "../../shared/scene/sceneLayoutModel";
|
|
17
|
+
import { FEATURE_OVERLAY_LAYER_ID } from "../../shared/constants/layers";
|
|
18
|
+
import { SubscriptionBag } from "../../shared/runtime/subscriptions";
|
|
19
|
+
import { cloneWithJson } from "../../shared/runtime/sessionState";
|
|
19
20
|
const FEATURE_STROKE_WIDTH = 2;
|
|
20
21
|
const DEFAULT_RECT_SIZE = 10;
|
|
21
22
|
const DEFAULT_CIRCLE_RADIUS = 5;
|
|
@@ -69,6 +70,7 @@ export class FeatureTool implements Extension {
|
|
|
69
70
|
private renderProducerDisposable?: { dispose: () => void };
|
|
70
71
|
private specs: RenderObjectSpec[] = [];
|
|
71
72
|
private renderSeq = 0;
|
|
73
|
+
private readonly subscriptions = new SubscriptionBag();
|
|
72
74
|
|
|
73
75
|
private handleMoving: ((e: any) => void) | null = null;
|
|
74
76
|
private handleModified: ((e: any) => void) | null = null;
|
|
@@ -89,6 +91,7 @@ export class FeatureTool implements Extension {
|
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
activate(context: ExtensionContext) {
|
|
94
|
+
this.subscriptions.disposeAll();
|
|
92
95
|
this.context = context;
|
|
93
96
|
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
94
97
|
|
|
@@ -122,18 +125,21 @@ export class FeatureTool implements Extension {
|
|
|
122
125
|
this.workingFeatures = this.cloneFeatures(features);
|
|
123
126
|
this.hasWorkingChanges = false;
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
this.subscriptions.onConfigChange(
|
|
129
|
+
configService,
|
|
130
|
+
(e: { key: string; value: any }) => {
|
|
131
|
+
if (this.isUpdatingConfig) return;
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
if (e.key === "dieline.features") {
|
|
134
|
+
if (this.isFeatureSessionActive) return;
|
|
135
|
+
const next = (e.value || []) as ConstraintFeature[];
|
|
136
|
+
this.workingFeatures = this.cloneFeatures(next);
|
|
137
|
+
this.hasWorkingChanges = false;
|
|
138
|
+
this.redraw();
|
|
139
|
+
this.emitWorkingChange();
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
);
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
const toolSessionService =
|
|
@@ -143,13 +149,13 @@ export class FeatureTool implements Extension {
|
|
|
143
149
|
() => this.hasWorkingChanges,
|
|
144
150
|
);
|
|
145
151
|
|
|
146
|
-
|
|
152
|
+
this.subscriptions.on(context.eventBus, "tool:activated", this.onToolActivated);
|
|
147
153
|
|
|
148
154
|
this.setup();
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
deactivate(context: ExtensionContext) {
|
|
152
|
-
|
|
158
|
+
this.subscriptions.disposeAll();
|
|
153
159
|
this.restoreSessionFeaturesToConfig();
|
|
154
160
|
this.dirtyTrackerDisposable?.dispose();
|
|
155
161
|
this.dirtyTrackerDisposable = undefined;
|
|
@@ -303,7 +309,7 @@ export class FeatureTool implements Extension {
|
|
|
303
309
|
}
|
|
304
310
|
|
|
305
311
|
private cloneFeatures(features: ConstraintFeature[]): ConstraintFeature[] {
|
|
306
|
-
return
|
|
312
|
+
return cloneWithJson(features || []) as ConstraintFeature[];
|
|
307
313
|
}
|
|
308
314
|
|
|
309
315
|
private getConfigService(): ConfigurationService | undefined {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FeatureTool";
|
|
@@ -7,14 +7,15 @@ import {
|
|
|
7
7
|
ConfigurationService,
|
|
8
8
|
} from "@pooder/core";
|
|
9
9
|
import { FabricImage } from "fabric";
|
|
10
|
-
import { CanvasService, RenderObjectSpec } from "
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
import { CanvasService, RenderObjectSpec } from "../../services";
|
|
11
|
+
import { FILM_LAYER_ID } from "../../shared/constants/layers";
|
|
12
|
+
import {
|
|
13
|
+
createSourceSizeCache,
|
|
14
|
+
getCoverScale,
|
|
15
|
+
type SourceSize,
|
|
16
|
+
} from "../../shared/imaging/sourceSizeCache";
|
|
17
|
+
import { SubscriptionBag } from "../../shared/runtime/subscriptions";
|
|
16
18
|
|
|
17
|
-
const FILM_LAYER_ID = "overlay";
|
|
18
19
|
const FILM_IMAGE_ID = "film-image";
|
|
19
20
|
const DEFAULT_WIDTH = 800;
|
|
20
21
|
const DEFAULT_HEIGHT = 600;
|
|
@@ -34,8 +35,10 @@ export class FilmTool implements Extension {
|
|
|
34
35
|
private renderProducerDisposable?: { dispose: () => void };
|
|
35
36
|
private renderSeq = 0;
|
|
36
37
|
private renderImageUrl = "";
|
|
37
|
-
private
|
|
38
|
-
|
|
38
|
+
private sourceSizeCache = createSourceSizeCache((src) =>
|
|
39
|
+
this.loadImageSize(src),
|
|
40
|
+
);
|
|
41
|
+
private readonly subscriptions = new SubscriptionBag();
|
|
39
42
|
private onCanvasResized = () => {
|
|
40
43
|
this.updateFilm();
|
|
41
44
|
};
|
|
@@ -52,6 +55,7 @@ export class FilmTool implements Extension {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
activate(context: ExtensionContext) {
|
|
58
|
+
this.subscriptions.disposeAll();
|
|
55
59
|
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
56
60
|
if (!this.canvasService) {
|
|
57
61
|
console.warn("CanvasService not found for FilmTool");
|
|
@@ -83,29 +87,33 @@ export class FilmTool implements Extension {
|
|
|
83
87
|
this.opacity = configService.get("film.opacity", this.opacity);
|
|
84
88
|
|
|
85
89
|
// Listen for changes
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this
|
|
90
|
+
this.subscriptions.onConfigChange(
|
|
91
|
+
configService,
|
|
92
|
+
(e: { key: string; value: any }) => {
|
|
93
|
+
if (e.key.startsWith("film.")) {
|
|
94
|
+
const prop = e.key.split(".")[1];
|
|
95
|
+
console.log(
|
|
96
|
+
`[FilmTool] Config change detected: ${e.key} -> ${e.value}`,
|
|
97
|
+
);
|
|
98
|
+
if (prop && prop in this) {
|
|
99
|
+
(this as any)[prop] = e.value;
|
|
100
|
+
this.updateFilm();
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
|
-
|
|
104
|
+
);
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
this.subscriptions.on(context.eventBus, "canvas:resized", this.onCanvasResized);
|
|
101
108
|
this.updateFilm();
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
deactivate(context: ExtensionContext) {
|
|
105
|
-
|
|
112
|
+
this.subscriptions.disposeAll();
|
|
106
113
|
this.renderSeq += 1;
|
|
107
114
|
this.specs = [];
|
|
108
115
|
this.renderImageUrl = "";
|
|
116
|
+
this.sourceSizeCache.clear();
|
|
109
117
|
this.renderProducerDisposable?.dispose();
|
|
110
118
|
this.renderProducerDisposable = undefined;
|
|
111
119
|
if (!this.canvasService) return;
|
|
@@ -173,10 +181,13 @@ export class FilmTool implements Extension {
|
|
|
173
181
|
return [];
|
|
174
182
|
}
|
|
175
183
|
const { width, height } = this.getViewportSize();
|
|
176
|
-
const sourceSize = this.
|
|
184
|
+
const sourceSize = this.sourceSizeCache.getSourceSize(imageUrl);
|
|
177
185
|
const sourceWidth = Math.max(1, Number(sourceSize?.width || width));
|
|
178
186
|
const sourceHeight = Math.max(1, Number(sourceSize?.height || height));
|
|
179
|
-
const coverScale =
|
|
187
|
+
const coverScale = getCoverScale(
|
|
188
|
+
{ width, height },
|
|
189
|
+
{ width: sourceWidth, height: sourceHeight },
|
|
190
|
+
);
|
|
180
191
|
return [
|
|
181
192
|
{
|
|
182
193
|
id: FILM_IMAGE_ID,
|
|
@@ -204,27 +215,6 @@ export class FilmTool implements Extension {
|
|
|
204
215
|
];
|
|
205
216
|
}
|
|
206
217
|
|
|
207
|
-
private async ensureImageSize(src: string): Promise<SourceSize | null> {
|
|
208
|
-
if (!src) return null;
|
|
209
|
-
const cached = this.sourceSizeBySrc.get(src);
|
|
210
|
-
if (cached) return cached;
|
|
211
|
-
|
|
212
|
-
const pending = this.pendingSizeBySrc.get(src);
|
|
213
|
-
if (pending) {
|
|
214
|
-
return pending;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const task = this.loadImageSize(src);
|
|
218
|
-
this.pendingSizeBySrc.set(src, task);
|
|
219
|
-
try {
|
|
220
|
-
return await task;
|
|
221
|
-
} finally {
|
|
222
|
-
if (this.pendingSizeBySrc.get(src) === task) {
|
|
223
|
-
this.pendingSizeBySrc.delete(src);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
218
|
private async loadImageSize(src: string): Promise<SourceSize | null> {
|
|
229
219
|
try {
|
|
230
220
|
const image = await FabricImage.fromURL(src, {
|
|
@@ -233,9 +223,7 @@ export class FilmTool implements Extension {
|
|
|
233
223
|
const width = Number(image?.width || 0);
|
|
234
224
|
const height = Number(image?.height || 0);
|
|
235
225
|
if (width > 0 && height > 0) {
|
|
236
|
-
|
|
237
|
-
this.sourceSizeBySrc.set(src, size);
|
|
238
|
-
return size;
|
|
226
|
+
return { width, height };
|
|
239
227
|
}
|
|
240
228
|
} catch (error) {
|
|
241
229
|
console.error("[FilmTool] Failed to load film image", src, error);
|
|
@@ -255,7 +243,7 @@ export class FilmTool implements Extension {
|
|
|
255
243
|
if (!nextUrl) {
|
|
256
244
|
this.renderImageUrl = "";
|
|
257
245
|
} else if (nextUrl !== this.renderImageUrl) {
|
|
258
|
-
const loaded = await this.ensureImageSize(nextUrl);
|
|
246
|
+
const loaded = await this.sourceSizeCache.ensureImageSize(nextUrl);
|
|
259
247
|
if (seq !== this.renderSeq) return;
|
|
260
248
|
if (loaded) {
|
|
261
249
|
this.renderImageUrl = nextUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FilmTool";
|