@pooder/kit 5.0.1 → 5.0.3
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/feature.js +87 -15
- package/.test-dist/src/image.js +28 -12
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +123 -38
- package/dist/index.mjs +123 -38
- package/package.json +1 -1
- package/src/feature.ts +96 -20
- package/src/image.ts +38 -24
|
@@ -16,6 +16,8 @@ class FeatureTool {
|
|
|
16
16
|
this.workingFeatures = [];
|
|
17
17
|
this.isUpdatingConfig = false;
|
|
18
18
|
this.isToolActive = false;
|
|
19
|
+
this.isFeatureSessionActive = false;
|
|
20
|
+
this.sessionOriginalFeatures = null;
|
|
19
21
|
this.hasWorkingChanges = false;
|
|
20
22
|
this.handleMoving = null;
|
|
21
23
|
this.handleModified = null;
|
|
@@ -23,6 +25,9 @@ class FeatureTool {
|
|
|
23
25
|
this.currentGeometry = null;
|
|
24
26
|
this.onToolActivated = (event) => {
|
|
25
27
|
this.isToolActive = event.id === this.id;
|
|
28
|
+
if (!this.isToolActive) {
|
|
29
|
+
this.restoreSessionFeaturesToConfig();
|
|
30
|
+
}
|
|
26
31
|
this.updateVisibility();
|
|
27
32
|
};
|
|
28
33
|
if (options) {
|
|
@@ -46,6 +51,8 @@ class FeatureTool {
|
|
|
46
51
|
if (this.isUpdatingConfig)
|
|
47
52
|
return;
|
|
48
53
|
if (e.key === "dieline.features") {
|
|
54
|
+
if (this.isFeatureSessionActive)
|
|
55
|
+
return;
|
|
49
56
|
const next = (e.value || []);
|
|
50
57
|
this.workingFeatures = this.cloneFeatures(next);
|
|
51
58
|
this.hasWorkingChanges = false;
|
|
@@ -62,6 +69,7 @@ class FeatureTool {
|
|
|
62
69
|
}
|
|
63
70
|
deactivate(context) {
|
|
64
71
|
context.eventBus.off("tool:activated", this.onToolActivated);
|
|
72
|
+
this.restoreSessionFeaturesToConfig();
|
|
65
73
|
this.dirtyTrackerDisposable?.dispose();
|
|
66
74
|
this.dirtyTrackerDisposable = undefined;
|
|
67
75
|
this.teardown();
|
|
@@ -95,9 +103,9 @@ class FeatureTool {
|
|
|
95
103
|
name: "Feature",
|
|
96
104
|
interaction: "session",
|
|
97
105
|
commands: {
|
|
98
|
-
begin: "
|
|
106
|
+
begin: "beginFeatureSession",
|
|
99
107
|
commit: "completeFeatures",
|
|
100
|
-
rollback: "
|
|
108
|
+
rollback: "rollbackFeatureSession",
|
|
101
109
|
},
|
|
102
110
|
session: {
|
|
103
111
|
autoBegin: false,
|
|
@@ -106,6 +114,25 @@ class FeatureTool {
|
|
|
106
114
|
},
|
|
107
115
|
],
|
|
108
116
|
[core_1.ContributionPointIds.COMMANDS]: [
|
|
117
|
+
{
|
|
118
|
+
command: "beginFeatureSession",
|
|
119
|
+
title: "Begin Feature Session",
|
|
120
|
+
handler: async () => {
|
|
121
|
+
if (this.isFeatureSessionActive) {
|
|
122
|
+
return { ok: true };
|
|
123
|
+
}
|
|
124
|
+
const original = this.getCommittedFeatures();
|
|
125
|
+
this.sessionOriginalFeatures = this.cloneFeatures(original);
|
|
126
|
+
this.isFeatureSessionActive = true;
|
|
127
|
+
await this.refreshGeometry();
|
|
128
|
+
this.setWorkingFeatures(this.cloneFeatures(original));
|
|
129
|
+
this.hasWorkingChanges = false;
|
|
130
|
+
this.redraw();
|
|
131
|
+
this.emitWorkingChange();
|
|
132
|
+
this.updateCommittedFeatures([]);
|
|
133
|
+
return { ok: true };
|
|
134
|
+
},
|
|
135
|
+
},
|
|
109
136
|
{
|
|
110
137
|
command: "addFeature",
|
|
111
138
|
title: "Add Edge Feature",
|
|
@@ -158,17 +185,25 @@ class FeatureTool {
|
|
|
158
185
|
},
|
|
159
186
|
},
|
|
160
187
|
{
|
|
161
|
-
command: "
|
|
162
|
-
title: "
|
|
188
|
+
command: "rollbackFeatureSession",
|
|
189
|
+
title: "Rollback Feature Session",
|
|
163
190
|
handler: async () => {
|
|
164
|
-
const
|
|
165
|
-
const next = (configService?.get("dieline.features", []) ||
|
|
166
|
-
[]);
|
|
191
|
+
const original = this.cloneFeatures(this.sessionOriginalFeatures || this.getCommittedFeatures());
|
|
167
192
|
await this.refreshGeometry();
|
|
168
|
-
this.setWorkingFeatures(
|
|
193
|
+
this.setWorkingFeatures(original);
|
|
169
194
|
this.hasWorkingChanges = false;
|
|
170
195
|
this.redraw();
|
|
171
196
|
this.emitWorkingChange();
|
|
197
|
+
this.updateCommittedFeatures(original);
|
|
198
|
+
this.clearFeatureSessionState();
|
|
199
|
+
return { ok: true };
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
command: "resetWorkingFeatures",
|
|
204
|
+
title: "Reset Working Features",
|
|
205
|
+
handler: async () => {
|
|
206
|
+
await this.resetWorkingFeaturesFromSource();
|
|
172
207
|
return { ok: true };
|
|
173
208
|
},
|
|
174
209
|
},
|
|
@@ -192,6 +227,38 @@ class FeatureTool {
|
|
|
192
227
|
cloneFeatures(features) {
|
|
193
228
|
return JSON.parse(JSON.stringify(features || []));
|
|
194
229
|
}
|
|
230
|
+
getConfigService() {
|
|
231
|
+
return this.context?.services.get("ConfigurationService");
|
|
232
|
+
}
|
|
233
|
+
getCommittedFeatures() {
|
|
234
|
+
const configService = this.getConfigService();
|
|
235
|
+
const committed = (configService?.get("dieline.features", []) ||
|
|
236
|
+
[]);
|
|
237
|
+
return this.cloneFeatures(committed);
|
|
238
|
+
}
|
|
239
|
+
updateCommittedFeatures(next) {
|
|
240
|
+
const configService = this.getConfigService();
|
|
241
|
+
if (!configService)
|
|
242
|
+
return;
|
|
243
|
+
this.isUpdatingConfig = true;
|
|
244
|
+
try {
|
|
245
|
+
configService.update("dieline.features", next);
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
this.isUpdatingConfig = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
clearFeatureSessionState() {
|
|
252
|
+
this.isFeatureSessionActive = false;
|
|
253
|
+
this.sessionOriginalFeatures = null;
|
|
254
|
+
}
|
|
255
|
+
restoreSessionFeaturesToConfig() {
|
|
256
|
+
if (!this.isFeatureSessionActive)
|
|
257
|
+
return;
|
|
258
|
+
const original = this.cloneFeatures(this.sessionOriginalFeatures || this.getCommittedFeatures());
|
|
259
|
+
this.updateCommittedFeatures(original);
|
|
260
|
+
this.clearFeatureSessionState();
|
|
261
|
+
}
|
|
195
262
|
emitWorkingChange() {
|
|
196
263
|
this.context?.eventBus.emit("feature:working:change", {
|
|
197
264
|
features: this.cloneFeatures(this.workingFeatures),
|
|
@@ -210,6 +277,16 @@ class FeatureTool {
|
|
|
210
277
|
}
|
|
211
278
|
catch (e) { }
|
|
212
279
|
}
|
|
280
|
+
async resetWorkingFeaturesFromSource() {
|
|
281
|
+
const next = this.cloneFeatures(this.isFeatureSessionActive && this.sessionOriginalFeatures
|
|
282
|
+
? this.sessionOriginalFeatures
|
|
283
|
+
: this.getCommittedFeatures());
|
|
284
|
+
await this.refreshGeometry();
|
|
285
|
+
this.setWorkingFeatures(next);
|
|
286
|
+
this.hasWorkingChanges = false;
|
|
287
|
+
this.redraw();
|
|
288
|
+
this.emitWorkingChange();
|
|
289
|
+
}
|
|
213
290
|
setWorkingFeatures(next) {
|
|
214
291
|
this.workingFeatures = next;
|
|
215
292
|
}
|
|
@@ -265,13 +342,7 @@ class FeatureTool {
|
|
|
265
342
|
const dielineWidth = sizeState.actualWidthMm;
|
|
266
343
|
const dielineHeight = sizeState.actualHeightMm;
|
|
267
344
|
const result = (0, featureComplete_1.completeFeaturesStrict)(this.workingFeatures, { dielineWidth, dielineHeight }, (next) => {
|
|
268
|
-
this.
|
|
269
|
-
try {
|
|
270
|
-
configService.update("dieline.features", next);
|
|
271
|
-
}
|
|
272
|
-
finally {
|
|
273
|
-
this.isUpdatingConfig = false;
|
|
274
|
-
}
|
|
345
|
+
this.updateCommittedFeatures(next);
|
|
275
346
|
this.workingFeatures = this.cloneFeatures(next);
|
|
276
347
|
this.emitWorkingChange();
|
|
277
348
|
});
|
|
@@ -282,6 +353,7 @@ class FeatureTool {
|
|
|
282
353
|
};
|
|
283
354
|
}
|
|
284
355
|
this.hasWorkingChanges = false;
|
|
356
|
+
this.clearFeatureSessionState();
|
|
285
357
|
// Keep feature markers above dieline overlay after config-driven redraw.
|
|
286
358
|
this.redraw();
|
|
287
359
|
return { ok: true };
|
package/.test-dist/src/image.js
CHANGED
|
@@ -275,7 +275,7 @@ class ImageTool {
|
|
|
275
275
|
id: "image.frame.outerBackground",
|
|
276
276
|
type: "color",
|
|
277
277
|
label: "Image Frame Outer Background",
|
|
278
|
-
default: "
|
|
278
|
+
default: "#f5f5f5",
|
|
279
279
|
},
|
|
280
280
|
],
|
|
281
281
|
[core_1.ContributionPointIds.COMMANDS]: [
|
|
@@ -318,6 +318,7 @@ class ImageTool {
|
|
|
318
318
|
this.workingItems = this.cloneItems(this.items);
|
|
319
319
|
this.hasWorkingChanges = false;
|
|
320
320
|
this.updateImages();
|
|
321
|
+
this.emitWorkingChange();
|
|
321
322
|
},
|
|
322
323
|
},
|
|
323
324
|
{
|
|
@@ -436,6 +437,12 @@ class ImageTool {
|
|
|
436
437
|
cloneItems(items) {
|
|
437
438
|
return this.normalizeItems((items || []).map((i) => ({ ...i })));
|
|
438
439
|
}
|
|
440
|
+
emitWorkingChange(changedId = null) {
|
|
441
|
+
this.context?.eventBus.emit("image:working:change", {
|
|
442
|
+
changedId,
|
|
443
|
+
items: this.cloneItems(this.workingItems),
|
|
444
|
+
});
|
|
445
|
+
}
|
|
439
446
|
generateId() {
|
|
440
447
|
return Math.random().toString(36).substring(2, 9);
|
|
441
448
|
}
|
|
@@ -509,6 +516,7 @@ class ImageTool {
|
|
|
509
516
|
return;
|
|
510
517
|
this.workingItems = this.cloneItems([...this.workingItems, item]);
|
|
511
518
|
this.updateImages();
|
|
519
|
+
this.emitWorkingChange(item.id);
|
|
512
520
|
}
|
|
513
521
|
async updateImage(id, updates, options = {}) {
|
|
514
522
|
this.syncToolActiveFromWorkbench();
|
|
@@ -681,7 +689,7 @@ class ImageTool {
|
|
|
681
689
|
strokeStyle,
|
|
682
690
|
dashLength: Number.isFinite(dashLength) ? Math.max(1, dashLength) : 8,
|
|
683
691
|
innerBackground: this.getConfig("image.frame.innerBackground", "rgba(0,0,0,0)") || "rgba(0,0,0,0)",
|
|
684
|
-
outerBackground:
|
|
692
|
+
outerBackground: "#f5f5f5",
|
|
685
693
|
};
|
|
686
694
|
}
|
|
687
695
|
resolveRenderImageState(item) {
|
|
@@ -833,10 +841,15 @@ class ImageTool {
|
|
|
833
841
|
const canvasW = this.canvasService.canvas.width || 0;
|
|
834
842
|
const canvasH = this.canvasService.canvas.height || 0;
|
|
835
843
|
const visual = this.getFrameVisualConfig();
|
|
836
|
-
const
|
|
837
|
-
const
|
|
838
|
-
const
|
|
839
|
-
const
|
|
844
|
+
const frameLeft = Math.max(0, Math.min(canvasW, frame.left));
|
|
845
|
+
const frameTop = Math.max(0, Math.min(canvasH, frame.top));
|
|
846
|
+
const frameRight = Math.max(frameLeft, Math.min(canvasW, frame.left + frame.width));
|
|
847
|
+
const frameBottom = Math.max(frameTop, Math.min(canvasH, frame.top + frame.height));
|
|
848
|
+
const visibleFrameH = Math.max(0, frameBottom - frameTop);
|
|
849
|
+
const topH = frameTop;
|
|
850
|
+
const bottomH = Math.max(0, canvasH - frameBottom);
|
|
851
|
+
const leftW = frameLeft;
|
|
852
|
+
const rightW = Math.max(0, canvasW - frameRight);
|
|
840
853
|
const mask = [
|
|
841
854
|
{
|
|
842
855
|
id: "image.cropMask.top",
|
|
@@ -860,7 +873,7 @@ class ImageTool {
|
|
|
860
873
|
data: { id: "image.cropMask.bottom", zIndex: 2 },
|
|
861
874
|
props: {
|
|
862
875
|
left: canvasW / 2,
|
|
863
|
-
top:
|
|
876
|
+
top: frameBottom + bottomH / 2,
|
|
864
877
|
width: canvasW,
|
|
865
878
|
height: bottomH,
|
|
866
879
|
originX: "center",
|
|
@@ -876,9 +889,9 @@ class ImageTool {
|
|
|
876
889
|
data: { id: "image.cropMask.left", zIndex: 3 },
|
|
877
890
|
props: {
|
|
878
891
|
left: leftW / 2,
|
|
879
|
-
top:
|
|
892
|
+
top: frameTop + visibleFrameH / 2,
|
|
880
893
|
width: leftW,
|
|
881
|
-
height:
|
|
894
|
+
height: visibleFrameH,
|
|
882
895
|
originX: "center",
|
|
883
896
|
originY: "center",
|
|
884
897
|
fill: visual.outerBackground,
|
|
@@ -891,10 +904,10 @@ class ImageTool {
|
|
|
891
904
|
type: "rect",
|
|
892
905
|
data: { id: "image.cropMask.right", zIndex: 4 },
|
|
893
906
|
props: {
|
|
894
|
-
left:
|
|
895
|
-
top:
|
|
907
|
+
left: frameRight + rightW / 2,
|
|
908
|
+
top: frameTop + visibleFrameH / 2,
|
|
896
909
|
width: rightW,
|
|
897
|
-
height:
|
|
910
|
+
height: visibleFrameH,
|
|
898
911
|
originX: "center",
|
|
899
912
|
originY: "center",
|
|
900
913
|
fill: visual.outerBackground,
|
|
@@ -988,6 +1001,7 @@ class ImageTool {
|
|
|
988
1001
|
if (this.isToolActive) {
|
|
989
1002
|
this.updateImages();
|
|
990
1003
|
}
|
|
1004
|
+
this.emitWorkingChange(id);
|
|
991
1005
|
}
|
|
992
1006
|
async updateImageInConfig(id, updates) {
|
|
993
1007
|
const index = this.items.findIndex((item) => item.id === id);
|
|
@@ -1073,6 +1087,7 @@ class ImageTool {
|
|
|
1073
1087
|
this.isImageSelectionActive = true;
|
|
1074
1088
|
this.focusedImageId = id;
|
|
1075
1089
|
this.updateImages();
|
|
1090
|
+
this.emitWorkingChange(id);
|
|
1076
1091
|
}
|
|
1077
1092
|
focusImageSelection(id) {
|
|
1078
1093
|
if (!this.canvasService)
|
|
@@ -1162,6 +1177,7 @@ class ImageTool {
|
|
|
1162
1177
|
this.hasWorkingChanges = false;
|
|
1163
1178
|
this.workingItems = this.cloneItems(next);
|
|
1164
1179
|
this.updateConfig(next);
|
|
1180
|
+
this.emitWorkingChange(focusId);
|
|
1165
1181
|
if (focusId) {
|
|
1166
1182
|
this.focusedImageId = focusId;
|
|
1167
1183
|
this.isImageSelectionActive = true;
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -178,6 +178,8 @@ declare class FeatureTool implements Extension {
|
|
|
178
178
|
private context?;
|
|
179
179
|
private isUpdatingConfig;
|
|
180
180
|
private isToolActive;
|
|
181
|
+
private isFeatureSessionActive;
|
|
182
|
+
private sessionOriginalFeatures;
|
|
181
183
|
private hasWorkingChanges;
|
|
182
184
|
private dirtyTrackerDisposable?;
|
|
183
185
|
private handleMoving;
|
|
@@ -209,8 +211,14 @@ declare class FeatureTool implements Extension {
|
|
|
209
211
|
[ContributionPointIds.COMMANDS]: CommandContribution[];
|
|
210
212
|
};
|
|
211
213
|
private cloneFeatures;
|
|
214
|
+
private getConfigService;
|
|
215
|
+
private getCommittedFeatures;
|
|
216
|
+
private updateCommittedFeatures;
|
|
217
|
+
private clearFeatureSessionState;
|
|
218
|
+
private restoreSessionFeaturesToConfig;
|
|
212
219
|
private emitWorkingChange;
|
|
213
220
|
private refreshGeometry;
|
|
221
|
+
private resetWorkingFeaturesFromSource;
|
|
214
222
|
private setWorkingFeatures;
|
|
215
223
|
private updateWorkingGroupPosition;
|
|
216
224
|
private completeFeatures;
|
|
@@ -286,6 +294,7 @@ declare class ImageTool implements Extension {
|
|
|
286
294
|
private normalizeItem;
|
|
287
295
|
private normalizeItems;
|
|
288
296
|
private cloneItems;
|
|
297
|
+
private emitWorkingChange;
|
|
289
298
|
private generateId;
|
|
290
299
|
private getImageIdFromActiveObject;
|
|
291
300
|
private resolveReplaceTargetId;
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,8 @@ declare class FeatureTool implements Extension {
|
|
|
178
178
|
private context?;
|
|
179
179
|
private isUpdatingConfig;
|
|
180
180
|
private isToolActive;
|
|
181
|
+
private isFeatureSessionActive;
|
|
182
|
+
private sessionOriginalFeatures;
|
|
181
183
|
private hasWorkingChanges;
|
|
182
184
|
private dirtyTrackerDisposable?;
|
|
183
185
|
private handleMoving;
|
|
@@ -209,8 +211,14 @@ declare class FeatureTool implements Extension {
|
|
|
209
211
|
[ContributionPointIds.COMMANDS]: CommandContribution[];
|
|
210
212
|
};
|
|
211
213
|
private cloneFeatures;
|
|
214
|
+
private getConfigService;
|
|
215
|
+
private getCommittedFeatures;
|
|
216
|
+
private updateCommittedFeatures;
|
|
217
|
+
private clearFeatureSessionState;
|
|
218
|
+
private restoreSessionFeaturesToConfig;
|
|
212
219
|
private emitWorkingChange;
|
|
213
220
|
private refreshGeometry;
|
|
221
|
+
private resetWorkingFeaturesFromSource;
|
|
214
222
|
private setWorkingFeatures;
|
|
215
223
|
private updateWorkingGroupPosition;
|
|
216
224
|
private completeFeatures;
|
|
@@ -286,6 +294,7 @@ declare class ImageTool implements Extension {
|
|
|
286
294
|
private normalizeItem;
|
|
287
295
|
private normalizeItems;
|
|
288
296
|
private cloneItems;
|
|
297
|
+
private emitWorkingChange;
|
|
289
298
|
private generateId;
|
|
290
299
|
private getImageIdFromActiveObject;
|
|
291
300
|
private resolveReplaceTargetId;
|