@pooder/kit 5.3.1 → 5.4.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 +6 -0
- package/dist/index.d.mts +243 -36
- package/dist/index.d.ts +243 -36
- package/dist/index.js +2278 -1041
- package/dist/index.mjs +2278 -1041
- package/package.json +1 -1
- package/src/coordinate.ts +106 -106
- package/src/extensions/background.ts +323 -230
- package/src/extensions/bridgeSelection.ts +17 -17
- package/src/extensions/constraints.ts +322 -322
- package/src/extensions/dieline.ts +1149 -1076
- package/src/extensions/dielineShape.ts +109 -0
- package/src/extensions/edgeScale.ts +19 -19
- package/src/extensions/feature.ts +1137 -1021
- package/src/extensions/featureComplete.ts +46 -46
- package/src/extensions/film.ts +266 -194
- package/src/extensions/geometry.ts +885 -752
- package/src/extensions/image.ts +2054 -1926
- package/src/extensions/index.ts +11 -11
- package/src/extensions/maskOps.ts +283 -283
- package/src/extensions/mirror.ts +128 -128
- package/src/extensions/ruler.ts +654 -451
- package/src/extensions/sceneLayout.ts +140 -140
- package/src/extensions/sceneLayoutModel.ts +364 -352
- package/src/extensions/sceneVisibility.ts +64 -71
- package/src/extensions/size.ts +389 -389
- package/src/extensions/tracer.ts +1019 -1019
- package/src/extensions/white-ink.ts +1567 -1514
- package/src/extensions/wrappedOffsets.ts +33 -33
- package/src/index.ts +2 -2
- package/src/services/CanvasService.ts +832 -300
- package/src/services/ViewportSystem.ts +95 -95
- package/src/services/index.ts +3 -3
- package/src/services/renderSpec.ts +53 -18
- package/src/units.ts +27 -27
- package/tests/run.ts +118 -118
- package/tsconfig.test.json +15 -15
- package/.test-dist/src/CanvasService.js +0 -249
- package/.test-dist/src/ViewportSystem.js +0 -75
- package/.test-dist/src/background.js +0 -203
- package/.test-dist/src/bridgeSelection.js +0 -20
- package/.test-dist/src/constraints.js +0 -237
- package/.test-dist/src/coordinate.js +0 -74
- package/.test-dist/src/dieline.js +0 -818
- package/.test-dist/src/edgeScale.js +0 -12
- package/.test-dist/src/extensions/background.js +0 -203
- package/.test-dist/src/extensions/bridgeSelection.js +0 -20
- package/.test-dist/src/extensions/constraints.js +0 -237
- package/.test-dist/src/extensions/dieline.js +0 -828
- package/.test-dist/src/extensions/edgeScale.js +0 -12
- package/.test-dist/src/extensions/feature.js +0 -825
- package/.test-dist/src/extensions/featureComplete.js +0 -32
- package/.test-dist/src/extensions/film.js +0 -167
- package/.test-dist/src/extensions/geometry.js +0 -545
- package/.test-dist/src/extensions/image.js +0 -1529
- package/.test-dist/src/extensions/index.js +0 -30
- package/.test-dist/src/extensions/maskOps.js +0 -279
- package/.test-dist/src/extensions/mirror.js +0 -104
- package/.test-dist/src/extensions/ruler.js +0 -345
- package/.test-dist/src/extensions/sceneLayout.js +0 -96
- package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
- package/.test-dist/src/extensions/sceneVisibility.js +0 -62
- package/.test-dist/src/extensions/size.js +0 -331
- package/.test-dist/src/extensions/tracer.js +0 -538
- package/.test-dist/src/extensions/white-ink.js +0 -1190
- package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
- package/.test-dist/src/feature.js +0 -826
- package/.test-dist/src/featureComplete.js +0 -32
- package/.test-dist/src/film.js +0 -167
- package/.test-dist/src/geometry.js +0 -506
- package/.test-dist/src/image.js +0 -1250
- package/.test-dist/src/index.js +0 -18
- package/.test-dist/src/maskOps.js +0 -270
- package/.test-dist/src/mirror.js +0 -104
- package/.test-dist/src/renderSpec.js +0 -2
- package/.test-dist/src/ruler.js +0 -343
- package/.test-dist/src/sceneLayout.js +0 -99
- package/.test-dist/src/sceneLayoutModel.js +0 -196
- package/.test-dist/src/sceneView.js +0 -40
- package/.test-dist/src/sceneVisibility.js +0 -42
- package/.test-dist/src/services/CanvasService.js +0 -249
- package/.test-dist/src/services/ViewportSystem.js +0 -76
- package/.test-dist/src/services/index.js +0 -24
- package/.test-dist/src/services/renderSpec.js +0 -2
- package/.test-dist/src/size.js +0 -332
- package/.test-dist/src/tracer.js +0 -544
- package/.test-dist/src/units.js +0 -30
- package/.test-dist/src/white-ink.js +0 -829
- package/.test-dist/src/wrappedOffsets.js +0 -33
- package/.test-dist/tests/run.js +0 -94
|
@@ -1,230 +1,323 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
ConfigurationService,
|
|
8
|
+
} from "@pooder/core";
|
|
9
|
+
import { FabricImage } from "fabric";
|
|
10
|
+
import { CanvasService, RenderObjectSpec } from "../services";
|
|
11
|
+
|
|
12
|
+
interface SourceSize {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const BACKGROUND_LAYER_ID = "background";
|
|
18
|
+
const BACKGROUND_RECT_ID = "background-color-rect";
|
|
19
|
+
const BACKGROUND_IMAGE_ID = "background-image";
|
|
20
|
+
const DEFAULT_WIDTH = 800;
|
|
21
|
+
const DEFAULT_HEIGHT = 600;
|
|
22
|
+
|
|
23
|
+
export class BackgroundTool implements Extension {
|
|
24
|
+
id = "pooder.kit.background";
|
|
25
|
+
public metadata = {
|
|
26
|
+
name: "BackgroundTool",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
private color: string = "";
|
|
30
|
+
private url: string = "";
|
|
31
|
+
|
|
32
|
+
private canvasService?: CanvasService;
|
|
33
|
+
private specs: RenderObjectSpec[] = [];
|
|
34
|
+
private renderProducerDisposable?: { dispose: () => void };
|
|
35
|
+
private renderSeq = 0;
|
|
36
|
+
private renderImageUrl = "";
|
|
37
|
+
private sourceSizeBySrc: Map<string, SourceSize> = new Map();
|
|
38
|
+
private pendingSizeBySrc: Map<string, Promise<SourceSize | null>> = new Map();
|
|
39
|
+
private onCanvasResized = () => {
|
|
40
|
+
this.updateBackground();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
constructor(
|
|
44
|
+
options?: Partial<{
|
|
45
|
+
color: string;
|
|
46
|
+
url: string;
|
|
47
|
+
}>,
|
|
48
|
+
) {
|
|
49
|
+
if (options) {
|
|
50
|
+
Object.assign(this, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
activate(context: ExtensionContext) {
|
|
55
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
56
|
+
if (!this.canvasService) {
|
|
57
|
+
console.warn("CanvasService not found for BackgroundTool");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.renderProducerDisposable?.dispose();
|
|
62
|
+
this.renderProducerDisposable = this.canvasService.registerRenderProducer(
|
|
63
|
+
this.id,
|
|
64
|
+
() => ({
|
|
65
|
+
layerSpecs: {
|
|
66
|
+
[BACKGROUND_LAYER_ID]: this.specs,
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
{ priority: 0 },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const configService = context.services.get<ConfigurationService>(
|
|
73
|
+
"ConfigurationService",
|
|
74
|
+
);
|
|
75
|
+
if (configService) {
|
|
76
|
+
// Load initial config
|
|
77
|
+
this.color = configService.get("background.color", this.color);
|
|
78
|
+
this.url = configService.get("background.url", this.url);
|
|
79
|
+
|
|
80
|
+
// Listen for changes
|
|
81
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
82
|
+
if (e.key.startsWith("background.")) {
|
|
83
|
+
const prop = e.key.split(".")[1];
|
|
84
|
+
console.log(
|
|
85
|
+
`[BackgroundTool] Config change detected: ${e.key} -> ${e.value}, prop: ${prop}`,
|
|
86
|
+
);
|
|
87
|
+
if (prop && prop in this) {
|
|
88
|
+
console.log(
|
|
89
|
+
`[BackgroundTool] Updating option ${prop} to ${e.value}`,
|
|
90
|
+
);
|
|
91
|
+
(this as any)[prop] = e.value;
|
|
92
|
+
this.updateBackground();
|
|
93
|
+
} else {
|
|
94
|
+
console.warn(
|
|
95
|
+
`[BackgroundTool] Property ${prop} not found in options`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
context.eventBus.on("canvas:resized", this.onCanvasResized);
|
|
103
|
+
this.updateBackground();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
deactivate(context: ExtensionContext) {
|
|
107
|
+
context.eventBus.off("canvas:resized", this.onCanvasResized);
|
|
108
|
+
this.renderSeq += 1;
|
|
109
|
+
this.specs = [];
|
|
110
|
+
this.renderImageUrl = "";
|
|
111
|
+
this.renderProducerDisposable?.dispose();
|
|
112
|
+
this.renderProducerDisposable = undefined;
|
|
113
|
+
if (!this.canvasService) return;
|
|
114
|
+
const layer = this.canvasService.getLayer(BACKGROUND_LAYER_ID);
|
|
115
|
+
if (layer) {
|
|
116
|
+
this.canvasService.canvas.remove(layer);
|
|
117
|
+
}
|
|
118
|
+
void this.canvasService.flushRenderFromProducers();
|
|
119
|
+
this.canvasService.requestRenderAll();
|
|
120
|
+
this.canvasService = undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
contribute() {
|
|
124
|
+
return {
|
|
125
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
126
|
+
{
|
|
127
|
+
id: "background.color",
|
|
128
|
+
type: "color",
|
|
129
|
+
label: "Background Color",
|
|
130
|
+
default: "",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "background.url",
|
|
134
|
+
type: "string",
|
|
135
|
+
label: "Image URL",
|
|
136
|
+
default: "",
|
|
137
|
+
},
|
|
138
|
+
] as ConfigurationContribution[],
|
|
139
|
+
[ContributionPointIds.COMMANDS]: [
|
|
140
|
+
{
|
|
141
|
+
command: "reset",
|
|
142
|
+
title: "Reset Background",
|
|
143
|
+
handler: () => {
|
|
144
|
+
this.updateBackground();
|
|
145
|
+
return true;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
command: "clear",
|
|
150
|
+
title: "Clear Background",
|
|
151
|
+
handler: () => {
|
|
152
|
+
this.color = "transparent";
|
|
153
|
+
this.url = "";
|
|
154
|
+
this.updateBackground();
|
|
155
|
+
return true;
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
command: "setBackgroundColor",
|
|
160
|
+
title: "Set Background Color",
|
|
161
|
+
handler: (color: string) => {
|
|
162
|
+
if (this.color === color) return true;
|
|
163
|
+
this.color = color;
|
|
164
|
+
this.updateBackground();
|
|
165
|
+
return true;
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
command: "setBackgroundImage",
|
|
170
|
+
title: "Set Background Image",
|
|
171
|
+
handler: (url: string) => {
|
|
172
|
+
if (this.url === url) return true;
|
|
173
|
+
this.url = url;
|
|
174
|
+
this.updateBackground();
|
|
175
|
+
return true;
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
] as CommandContribution[],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private getViewportSize(): { width: number; height: number } {
|
|
183
|
+
const width = Number(this.canvasService?.canvas.width || 0);
|
|
184
|
+
const height = Number(this.canvasService?.canvas.height || 0);
|
|
185
|
+
return {
|
|
186
|
+
width: width > 0 ? width : DEFAULT_WIDTH,
|
|
187
|
+
height: height > 0 ? height : DEFAULT_HEIGHT,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private buildBackgroundSpecs(
|
|
192
|
+
color: string,
|
|
193
|
+
imageUrl: string,
|
|
194
|
+
): RenderObjectSpec[] {
|
|
195
|
+
const { width, height } = this.getViewportSize();
|
|
196
|
+
const specs: RenderObjectSpec[] = [
|
|
197
|
+
{
|
|
198
|
+
id: BACKGROUND_RECT_ID,
|
|
199
|
+
type: "rect",
|
|
200
|
+
space: "screen",
|
|
201
|
+
data: {
|
|
202
|
+
id: BACKGROUND_RECT_ID,
|
|
203
|
+
layerId: BACKGROUND_LAYER_ID,
|
|
204
|
+
type: "background-color",
|
|
205
|
+
},
|
|
206
|
+
props: {
|
|
207
|
+
left: 0,
|
|
208
|
+
top: 0,
|
|
209
|
+
width,
|
|
210
|
+
height,
|
|
211
|
+
originX: "left",
|
|
212
|
+
originY: "top",
|
|
213
|
+
fill: color,
|
|
214
|
+
selectable: false,
|
|
215
|
+
evented: false,
|
|
216
|
+
excludeFromExport: true,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
if (!imageUrl) {
|
|
222
|
+
return specs;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const sourceSize = this.sourceSizeBySrc.get(imageUrl);
|
|
226
|
+
const sourceWidth = Math.max(1, Number(sourceSize?.width || width));
|
|
227
|
+
const sourceHeight = Math.max(1, Number(sourceSize?.height || height));
|
|
228
|
+
const coverScale = Math.max(width / sourceWidth, height / sourceHeight);
|
|
229
|
+
specs.push({
|
|
230
|
+
id: BACKGROUND_IMAGE_ID,
|
|
231
|
+
type: "image",
|
|
232
|
+
src: imageUrl,
|
|
233
|
+
space: "screen",
|
|
234
|
+
data: {
|
|
235
|
+
id: BACKGROUND_IMAGE_ID,
|
|
236
|
+
layerId: BACKGROUND_LAYER_ID,
|
|
237
|
+
type: "background-image",
|
|
238
|
+
},
|
|
239
|
+
props: {
|
|
240
|
+
left: 0,
|
|
241
|
+
top: 0,
|
|
242
|
+
originX: "left",
|
|
243
|
+
originY: "top",
|
|
244
|
+
scaleX: coverScale,
|
|
245
|
+
scaleY: coverScale,
|
|
246
|
+
selectable: false,
|
|
247
|
+
evented: false,
|
|
248
|
+
excludeFromExport: true,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
return specs;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private async ensureImageSize(src: string): Promise<SourceSize | null> {
|
|
256
|
+
if (!src) return null;
|
|
257
|
+
const cached = this.sourceSizeBySrc.get(src);
|
|
258
|
+
if (cached) return cached;
|
|
259
|
+
|
|
260
|
+
const pending = this.pendingSizeBySrc.get(src);
|
|
261
|
+
if (pending) {
|
|
262
|
+
return pending;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const task = this.loadImageSize(src);
|
|
266
|
+
this.pendingSizeBySrc.set(src, task);
|
|
267
|
+
try {
|
|
268
|
+
return await task;
|
|
269
|
+
} finally {
|
|
270
|
+
if (this.pendingSizeBySrc.get(src) === task) {
|
|
271
|
+
this.pendingSizeBySrc.delete(src);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private async loadImageSize(src: string): Promise<SourceSize | null> {
|
|
277
|
+
try {
|
|
278
|
+
const image = await FabricImage.fromURL(src, {
|
|
279
|
+
crossOrigin: "anonymous",
|
|
280
|
+
});
|
|
281
|
+
const width = Number(image?.width || 0);
|
|
282
|
+
const height = Number(image?.height || 0);
|
|
283
|
+
if (width > 0 && height > 0) {
|
|
284
|
+
const size = { width, height };
|
|
285
|
+
this.sourceSizeBySrc.set(src, size);
|
|
286
|
+
return size;
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error("[BackgroundTool] Failed to load image", src, error);
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private updateBackground() {
|
|
295
|
+
void this.updateBackgroundAsync();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private async updateBackgroundAsync() {
|
|
299
|
+
if (!this.canvasService) return;
|
|
300
|
+
const seq = ++this.renderSeq;
|
|
301
|
+
const color = this.color;
|
|
302
|
+
const nextUrl = String(this.url || "").trim();
|
|
303
|
+
|
|
304
|
+
if (!nextUrl) {
|
|
305
|
+
this.renderImageUrl = "";
|
|
306
|
+
} else if (nextUrl !== this.renderImageUrl) {
|
|
307
|
+
const loaded = await this.ensureImageSize(nextUrl);
|
|
308
|
+
if (seq !== this.renderSeq) return;
|
|
309
|
+
if (loaded) {
|
|
310
|
+
this.renderImageUrl = nextUrl;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
this.specs = this.buildBackgroundSpecs(color, this.renderImageUrl);
|
|
315
|
+
await this.canvasService.flushRenderFromProducers();
|
|
316
|
+
if (seq !== this.renderSeq) return;
|
|
317
|
+
const layer = this.canvasService.getLayer(BACKGROUND_LAYER_ID);
|
|
318
|
+
if (layer) {
|
|
319
|
+
this.canvasService.canvas.sendObjectToBack(layer);
|
|
320
|
+
}
|
|
321
|
+
this.canvasService.requestRenderAll();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export function pickExitIndex(
|
|
2
|
-
hits: Array<{ insideAbove: boolean; insideBelow: boolean }>,
|
|
3
|
-
): number {
|
|
4
|
-
for (let i = 0; i < hits.length; i++) {
|
|
5
|
-
const h = hits[i];
|
|
6
|
-
if (h.insideBelow && !h.insideAbove) return i;
|
|
7
|
-
}
|
|
8
|
-
return -1;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function scoreOutsideAbove(samples: Array<{ outsideAbove: boolean }>): number {
|
|
12
|
-
let score = 0;
|
|
13
|
-
for (const s of samples) {
|
|
14
|
-
if (s.outsideAbove) score++;
|
|
15
|
-
}
|
|
16
|
-
return score;
|
|
17
|
-
}
|
|
1
|
+
export function pickExitIndex(
|
|
2
|
+
hits: Array<{ insideAbove: boolean; insideBelow: boolean }>,
|
|
3
|
+
): number {
|
|
4
|
+
for (let i = 0; i < hits.length; i++) {
|
|
5
|
+
const h = hits[i];
|
|
6
|
+
if (h.insideBelow && !h.insideAbove) return i;
|
|
7
|
+
}
|
|
8
|
+
return -1;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function scoreOutsideAbove(samples: Array<{ outsideAbove: boolean }>): number {
|
|
12
|
+
let score = 0;
|
|
13
|
+
for (const s of samples) {
|
|
14
|
+
if (s.outsideAbove) score++;
|
|
15
|
+
}
|
|
16
|
+
return score;
|
|
17
|
+
}
|