@web-canvas-ui/react 0.0.0-stage → 0.1.1
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/Canvas.tsx +142 -0
- package/README.md +988 -2
- package/__tests__/pure-logic.test.ts +153 -0
- package/__tests__/scene-and-node.test.ts +131 -0
- package/__tests__/scratch-space.test.ts +30 -0
- package/__tests__/textarea-caret.test.ts +96 -0
- package/__tests__/utils.test.ts +114 -0
- package/canvas-handle.ts +114 -0
- package/components/Button/button.ts +57 -0
- package/components/Button/index.ts +3 -0
- package/components/Button/logic.ts +11 -0
- package/components/CanvasView/canvasView.ts +103 -0
- package/components/CanvasView/index.ts +7 -0
- package/components/Carousel/carousel.ts +107 -0
- package/components/Carousel/index.ts +3 -0
- package/components/Carousel/logic.ts +36 -0
- package/components/Checkbox/checkbox.ts +14 -0
- package/components/Checkbox/index.ts +2 -0
- package/components/ChoiceGroup/choiceGroup.ts +172 -0
- package/components/ChoiceGroup/index.ts +3 -0
- package/components/ChoiceGroup/logic.ts +14 -0
- package/components/Circle/circle.ts +31 -0
- package/components/Circle/index.ts +2 -0
- package/components/Collapse/collapse.ts +69 -0
- package/components/Collapse/index.ts +3 -0
- package/components/Collapse/logic.ts +14 -0
- package/components/CustomDraw/customDraw.ts +50 -0
- package/components/CustomDraw/index.ts +7 -0
- package/components/DatePicker/datePicker.ts +70 -0
- package/components/DatePicker/index.ts +2 -0
- package/components/Dialog/dialog.ts +102 -0
- package/components/Dialog/index.ts +2 -0
- package/components/Dropdown/dropdown.ts +125 -0
- package/components/Dropdown/index.ts +3 -0
- package/components/Dropdown/logic.ts +29 -0
- package/components/Grid/grid.ts +15 -0
- package/components/Grid/index.ts +2 -0
- package/components/GridItem/gridItem.ts +11 -0
- package/components/GridItem/index.ts +2 -0
- package/components/Group/group.ts +8 -0
- package/components/Group/index.ts +2 -0
- package/components/Icon/icon.ts +669 -0
- package/components/Icon/index.ts +2 -0
- package/components/Image/image.ts +69 -0
- package/components/Image/index.ts +2 -0
- package/components/Input/index.ts +2 -0
- package/components/Input/input.ts +139 -0
- package/components/Progress/index.ts +2 -0
- package/components/Progress/progress.ts +59 -0
- package/components/Radio/index.ts +2 -0
- package/components/Radio/radio.ts +14 -0
- package/components/Rect/index.ts +2 -0
- package/components/Rect/rect.ts +35 -0
- package/components/Slider/index.ts +3 -0
- package/components/Slider/logic.ts +19 -0
- package/components/Slider/slider.ts +58 -0
- package/components/Switch/index.ts +3 -0
- package/components/Switch/logic.ts +8 -0
- package/components/Switch/switch.ts +37 -0
- package/components/Tabs/index.ts +3 -0
- package/components/Tabs/logic.ts +14 -0
- package/components/Tabs/tabs.ts +78 -0
- package/components/Text/index.ts +2 -0
- package/components/Text/text.ts +95 -0
- package/components/Textarea/index.ts +2 -0
- package/components/Textarea/textarea.ts +16 -0
- package/components/Upload/index.ts +2 -0
- package/components/Upload/upload.ts +66 -0
- package/components/draw-utils.ts +230 -0
- package/components/shared.ts +15 -0
- package/components/size.ts +20 -0
- package/components/types.ts +37 -0
- package/components.ts +98 -0
- package/engine/__tests__/carousel.test.ts +218 -0
- package/engine/__tests__/hit-test.test.ts +282 -0
- package/engine/__tests__/layout.test.ts +474 -0
- package/engine/carousel.ts +150 -0
- package/engine/events.ts +73 -0
- package/engine/hit-test.ts +321 -0
- package/engine/images.ts +41 -0
- package/engine/interaction.ts +442 -0
- package/engine/layout.ts +355 -0
- package/engine/nodes.ts +166 -0
- package/engine/state.ts +75 -0
- package/engine/text-controls.ts +122 -0
- package/engine/transform.ts +61 -0
- package/engine/vnodes.ts +204 -0
- package/engine.ts +162 -0
- package/image-assets.ts +37 -0
- package/index.ts +78 -0
- package/input-bridge.ts +285 -0
- package/package.json +27 -4
- package/renderer.ts +303 -0
- package/scene.ts +122 -0
- package/theme.css +327 -0
- package/theme.scss +234 -0
- package/types.ts +256 -0
- package/web-canvas-ui-react-0.1.1.tgz +0 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import type { SceneNode } from '../scene';
|
|
2
|
+
import type { Transform } from '../types';
|
|
3
|
+
import { IDENTITY_TRANSFORM } from '../types';
|
|
4
|
+
import { number } from '../components/draw-utils';
|
|
5
|
+
import { normalizeDropdownOptions } from '../components/Dropdown';
|
|
6
|
+
import { carouselControlIndex } from '../components/Carousel';
|
|
7
|
+
import {
|
|
8
|
+
controlSize,
|
|
9
|
+
hasVisibleAncestors,
|
|
10
|
+
isCanvasElement,
|
|
11
|
+
isDescendantOf,
|
|
12
|
+
isInteractive,
|
|
13
|
+
} from './nodes';
|
|
14
|
+
import { invertPoint, multiplyTransform } from './transform';
|
|
15
|
+
import { gridScrollbarMetrics } from './vnodes';
|
|
16
|
+
import type { EngineCore } from './state';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Geometry: resolve client (viewport) coordinates to canvas / node-local space and
|
|
20
|
+
* determine which interactive node, if any, is under a pointer, honouring modal
|
|
21
|
+
* dialogs and grid/carousel clipping. Pure apart from reading the live scene graph.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export interface HitResult {
|
|
25
|
+
node: SceneNode;
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function canvasPoint(
|
|
31
|
+
core: EngineCore,
|
|
32
|
+
canvas: HTMLCanvasElement,
|
|
33
|
+
clientX: number,
|
|
34
|
+
clientY: number,
|
|
35
|
+
): { x: number; y: number } | null {
|
|
36
|
+
const rect = canvas.getBoundingClientRect();
|
|
37
|
+
if (!rect.width || !rect.height) return null;
|
|
38
|
+
return {
|
|
39
|
+
x: ((clientX - rect.left) * canvas.width) / rect.width / core.pixelRatio,
|
|
40
|
+
y: ((clientY - rect.top) * canvas.height) / rect.height / core.pixelRatio,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function localPoint(
|
|
45
|
+
core: EngineCore,
|
|
46
|
+
canvas: HTMLCanvasElement,
|
|
47
|
+
clientX: number,
|
|
48
|
+
clientY: number,
|
|
49
|
+
target: SceneNode,
|
|
50
|
+
): { x: number; y: number } | null {
|
|
51
|
+
const rect = canvas.getBoundingClientRect();
|
|
52
|
+
if (!rect.width || !rect.height) return null;
|
|
53
|
+
const x = ((clientX - rect.left) * canvas.width) / rect.width / core.pixelRatio;
|
|
54
|
+
const y = ((clientY - rect.top) * canvas.height) / rect.height / core.pixelRatio;
|
|
55
|
+
let result: { x: number; y: number } | null = null;
|
|
56
|
+
const find = (node: SceneNode, parent: Transform): boolean => {
|
|
57
|
+
const transform = multiplyTransform(parent, node.props);
|
|
58
|
+
if (node === target) {
|
|
59
|
+
result = invertPoint(x, y, transform);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
for (const child of node.children) {
|
|
63
|
+
if (find(child, transform)) return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
find(core.scene, IDENTITY_TRANSFORM);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isWithinClip(
|
|
72
|
+
core: EngineCore,
|
|
73
|
+
canvas: HTMLCanvasElement,
|
|
74
|
+
clientX: number,
|
|
75
|
+
clientY: number,
|
|
76
|
+
node: SceneNode,
|
|
77
|
+
): boolean {
|
|
78
|
+
let parent = node.parent;
|
|
79
|
+
while (parent) {
|
|
80
|
+
if (
|
|
81
|
+
(parent.type === 'grid' && typeof parent.props.height === 'number') ||
|
|
82
|
+
parent.type === 'carousel'
|
|
83
|
+
) {
|
|
84
|
+
const point = localPoint(core, canvas, clientX, clientY, parent);
|
|
85
|
+
const width =
|
|
86
|
+
parent.type === 'grid'
|
|
87
|
+
? number(parent.props._gridWidth, number(parent.props.width, 0))
|
|
88
|
+
: number(parent.props.width, 300);
|
|
89
|
+
const height = number(parent.props.height, parent.type === 'carousel' ? 180 : 0);
|
|
90
|
+
if (!point || point.x < 0 || point.x > width || point.y < 0 || point.y > height) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
parent = parent.parent;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function findHit(
|
|
100
|
+
core: EngineCore,
|
|
101
|
+
canvas: HTMLCanvasElement,
|
|
102
|
+
clientX: number,
|
|
103
|
+
clientY: number,
|
|
104
|
+
): HitResult | null {
|
|
105
|
+
const rect = canvas.getBoundingClientRect();
|
|
106
|
+
if (!rect.width || !rect.height) return null;
|
|
107
|
+
const pointX = ((clientX - rect.left) * canvas.width) / rect.width / core.pixelRatio;
|
|
108
|
+
const pointY = ((clientY - rect.top) * canvas.height) / rect.height / core.pixelRatio;
|
|
109
|
+
const candidates: Array<{ node: SceneNode; transform: Transform }> = [];
|
|
110
|
+
const collect = (node: SceneNode, parent: Transform, parentVisible: boolean) => {
|
|
111
|
+
const visible = parentVisible && node.props.visible !== false;
|
|
112
|
+
if (!visible) return;
|
|
113
|
+
// Dialogs render in viewport space, outside their enclosing group transforms.
|
|
114
|
+
const transform =
|
|
115
|
+
node.type === 'dialog'
|
|
116
|
+
? multiplyTransform(IDENTITY_TRANSFORM, node.props)
|
|
117
|
+
: multiplyTransform(parent, node.props);
|
|
118
|
+
if (isInteractive(node.type) || (node.type === 'dialog' && node.props.open === true)) {
|
|
119
|
+
candidates.push({ node, transform });
|
|
120
|
+
}
|
|
121
|
+
node.children.forEach((child) => collect(child, transform, visible));
|
|
122
|
+
};
|
|
123
|
+
collect(core.scene, IDENTITY_TRANSFORM, true);
|
|
124
|
+
const modal = [...candidates].reverse().find((candidate) => candidate.node.type === 'dialog');
|
|
125
|
+
|
|
126
|
+
for (let index = candidates.length - 1; index >= 0; index--) {
|
|
127
|
+
const candidate = candidates[index];
|
|
128
|
+
if (modal && candidate.node !== modal.node && !isDescendantOf(candidate.node, modal.node))
|
|
129
|
+
continue;
|
|
130
|
+
if (
|
|
131
|
+
candidate.node.type !== 'dropdown' ||
|
|
132
|
+
!candidate.node.props.open ||
|
|
133
|
+
candidate.node.props.disabled
|
|
134
|
+
)
|
|
135
|
+
continue;
|
|
136
|
+
if (!isWithinClip(core, canvas, clientX, clientY, candidate.node)) continue;
|
|
137
|
+
const local = invertPoint(pointX, pointY, candidate.transform);
|
|
138
|
+
if (!local) continue;
|
|
139
|
+
const { width, height } = controlSize(candidate.node);
|
|
140
|
+
const popupHeight = normalizeDropdownOptions(candidate.node.props.options).length * height;
|
|
141
|
+
if (
|
|
142
|
+
local.x >= 0 &&
|
|
143
|
+
local.x <= width &&
|
|
144
|
+
local.y >= height &&
|
|
145
|
+
local.y <= height + popupHeight
|
|
146
|
+
) {
|
|
147
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (let index = candidates.length - 1; index >= 0; index--) {
|
|
152
|
+
const candidate = candidates[index];
|
|
153
|
+
if (modal && candidate.node !== modal.node && !isDescendantOf(candidate.node, modal.node))
|
|
154
|
+
continue;
|
|
155
|
+
if (!isWithinClip(core, canvas, clientX, clientY, candidate.node)) continue;
|
|
156
|
+
const local = invertPoint(pointX, pointY, candidate.transform);
|
|
157
|
+
if (!local) continue;
|
|
158
|
+
if (candidate.node.type === 'customDraw') {
|
|
159
|
+
const { width, height } = controlSize(candidate.node);
|
|
160
|
+
if (local.x < 0 || local.x > width || local.y < 0 || local.y > height) continue;
|
|
161
|
+
const hitTest = candidate.node.props.hitTest;
|
|
162
|
+
if (
|
|
163
|
+
typeof hitTest === 'function' &&
|
|
164
|
+
!(
|
|
165
|
+
hitTest as (
|
|
166
|
+
x: number,
|
|
167
|
+
y: number,
|
|
168
|
+
size: { width: number; height: number },
|
|
169
|
+
) => boolean
|
|
170
|
+
)(local.x, local.y, { width, height })
|
|
171
|
+
)
|
|
172
|
+
continue;
|
|
173
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
174
|
+
}
|
|
175
|
+
if (candidate.node.type === 'canvasView') {
|
|
176
|
+
const source = candidate.node.props.source;
|
|
177
|
+
if (!isCanvasElement(source) || !source.width || !source.height) continue;
|
|
178
|
+
const { width, height } = controlSize(candidate.node);
|
|
179
|
+
if (local.x < 0 || local.x > width || local.y < 0 || local.y > height) continue;
|
|
180
|
+
const fit = candidate.node.props.fit ?? 'contain';
|
|
181
|
+
if (fit === 'contain') {
|
|
182
|
+
const scale = Math.min(width / source.width, height / source.height);
|
|
183
|
+
const drawnWidth = source.width * scale;
|
|
184
|
+
const drawnHeight = source.height * scale;
|
|
185
|
+
const offsetX = (width - drawnWidth) / 2;
|
|
186
|
+
const offsetY = (height - drawnHeight) / 2;
|
|
187
|
+
if (
|
|
188
|
+
local.x < offsetX ||
|
|
189
|
+
local.x > offsetX + drawnWidth ||
|
|
190
|
+
local.y < offsetY ||
|
|
191
|
+
local.y > offsetY + drawnHeight
|
|
192
|
+
)
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
196
|
+
}
|
|
197
|
+
if (candidate.node.type === 'dialog') {
|
|
198
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
199
|
+
}
|
|
200
|
+
if (candidate.node.type === 'tabs') {
|
|
201
|
+
const width = number(candidate.node.props.width, 300);
|
|
202
|
+
const height = number(candidate.node.props.height, 200);
|
|
203
|
+
if (local.x >= 0 && local.x <= width && local.y >= 0 && local.y <= height) {
|
|
204
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
205
|
+
}
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (candidate.node.type === 'carousel') {
|
|
209
|
+
const width = number(candidate.node.props.width, 300);
|
|
210
|
+
const height = number(candidate.node.props.height, 180);
|
|
211
|
+
if (local.x >= 0 && local.x <= width && local.y >= 0 && local.y <= height) {
|
|
212
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (candidate.node.type === 'grid') {
|
|
217
|
+
if (typeof candidate.node.props.height !== 'number') continue;
|
|
218
|
+
const width = number(
|
|
219
|
+
candidate.node.props._gridWidth,
|
|
220
|
+
number(candidate.node.props.width, 0),
|
|
221
|
+
);
|
|
222
|
+
const height = number(candidate.node.props.height, 0);
|
|
223
|
+
if (local.x >= 0 && local.x <= width && local.y >= 0 && local.y <= height) {
|
|
224
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (candidate.node.type === 'collapse') {
|
|
229
|
+
const width = number(candidate.node.props.width, 300);
|
|
230
|
+
const height = candidate.node.children.reduce(
|
|
231
|
+
(total, child) =>
|
|
232
|
+
total +
|
|
233
|
+
number(child.props._collapseHeaderHeight, 40) +
|
|
234
|
+
(child.props._expanded ? number(child.props.height, 100) : 0),
|
|
235
|
+
0,
|
|
236
|
+
);
|
|
237
|
+
if (local.x >= 0 && local.x <= width && local.y >= 0 && local.y <= height) {
|
|
238
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
239
|
+
}
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const { width, height } = controlSize(candidate.node);
|
|
243
|
+
const popupHeight =
|
|
244
|
+
candidate.node.type === 'dropdown' && candidate.node.props.open
|
|
245
|
+
? normalizeDropdownOptions(candidate.node.props.options).length * height
|
|
246
|
+
: 0;
|
|
247
|
+
if (local.x >= 0 && local.x <= width && local.y >= 0 && local.y <= height + popupHeight) {
|
|
248
|
+
return { node: candidate.node, x: local.x, y: local.y };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function findCarouselControlHit(
|
|
255
|
+
core: EngineCore,
|
|
256
|
+
canvas: HTMLCanvasElement,
|
|
257
|
+
clientX: number,
|
|
258
|
+
clientY: number,
|
|
259
|
+
): { node: SceneNode; index: number } | null {
|
|
260
|
+
const carousels: SceneNode[] = [];
|
|
261
|
+
const dialogs: SceneNode[] = [];
|
|
262
|
+
core.scene.traverse((node) => {
|
|
263
|
+
if (node.type === 'dialog' && node.props.open === true && hasVisibleAncestors(node)) {
|
|
264
|
+
dialogs.push(node);
|
|
265
|
+
}
|
|
266
|
+
if (node.type === 'carousel' && hasVisibleAncestors(node)) carousels.push(node);
|
|
267
|
+
});
|
|
268
|
+
const modal = dialogs[dialogs.length - 1];
|
|
269
|
+
for (const node of carousels.reverse()) {
|
|
270
|
+
if (modal && !isDescendantOf(node, modal)) continue;
|
|
271
|
+
const point = localPoint(core, canvas, clientX, clientY, node);
|
|
272
|
+
if (!point) continue;
|
|
273
|
+
const width = number(node.props.width, 300);
|
|
274
|
+
const height = number(node.props.height, 180);
|
|
275
|
+
const count = node.children.filter((child) => child.type === 'carouselItem').length;
|
|
276
|
+
const current = number(node.props._activeIndex, 0);
|
|
277
|
+
const index = carouselControlIndex(
|
|
278
|
+
node.props,
|
|
279
|
+
point.x,
|
|
280
|
+
point.y,
|
|
281
|
+
count,
|
|
282
|
+
current,
|
|
283
|
+
width,
|
|
284
|
+
height,
|
|
285
|
+
);
|
|
286
|
+
if (index !== undefined) return { node, index };
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function findGridScrollbarHit(
|
|
292
|
+
core: EngineCore,
|
|
293
|
+
canvas: HTMLCanvasElement,
|
|
294
|
+
clientX: number,
|
|
295
|
+
clientY: number,
|
|
296
|
+
): { node: SceneNode; pointerY: number; scrollTop: number } | null {
|
|
297
|
+
const grids: SceneNode[] = [];
|
|
298
|
+
core.scene.traverse((node) => {
|
|
299
|
+
if (node.type === 'grid' && typeof node.props.height === 'number') grids.push(node);
|
|
300
|
+
});
|
|
301
|
+
for (const grid of grids.reverse()) {
|
|
302
|
+
if (!isWithinClip(core, canvas, clientX, clientY, grid)) continue;
|
|
303
|
+
const point = localPoint(core, canvas, clientX, clientY, grid);
|
|
304
|
+
if (!point) continue;
|
|
305
|
+
const metrics = gridScrollbarMetrics(grid.props);
|
|
306
|
+
if (
|
|
307
|
+
metrics.maxScroll <= 0 ||
|
|
308
|
+
point.x < metrics.trackX ||
|
|
309
|
+
point.x > metrics.width ||
|
|
310
|
+
point.y < metrics.thumbY ||
|
|
311
|
+
point.y > metrics.thumbY + metrics.thumbHeight
|
|
312
|
+
)
|
|
313
|
+
continue;
|
|
314
|
+
return {
|
|
315
|
+
node: grid,
|
|
316
|
+
pointerY: point.y,
|
|
317
|
+
scrollTop: number(grid.props._scrollTop, 0),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
package/engine/images.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { subscribeCanvasImage } from '../image-assets';
|
|
2
|
+
import type { VNode } from '../types';
|
|
3
|
+
import type { EngineCore, EngineState } from './state';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Subscribes the engine to the shared image cache for every `image` source in the
|
|
7
|
+
* tree, tearing down subscriptions for sources that disappear. Load errors mark the
|
|
8
|
+
* scene dirty and forward to each image node's `onError` callback.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function syncImages(core: EngineCore, state: EngineState, tree: VNode[]): void {
|
|
12
|
+
const sources = new Set<string>();
|
|
13
|
+
const visit = (nodes: VNode[]) =>
|
|
14
|
+
nodes.forEach((node) => {
|
|
15
|
+
if (node.type === 'image' && typeof node.props.src === 'string' && node.props.src) {
|
|
16
|
+
sources.add(node.props.src);
|
|
17
|
+
}
|
|
18
|
+
visit(node.children);
|
|
19
|
+
});
|
|
20
|
+
visit(tree);
|
|
21
|
+
for (const [source, dispose] of state.imageSubscriptions) {
|
|
22
|
+
if (!sources.has(source)) {
|
|
23
|
+
dispose();
|
|
24
|
+
state.imageSubscriptions.delete(source);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const source of sources) {
|
|
28
|
+
if (state.imageSubscriptions.has(source)) continue;
|
|
29
|
+
const dispose = subscribeCanvasImage(source, (error) => {
|
|
30
|
+
core.scene.markDirty();
|
|
31
|
+
if (error) {
|
|
32
|
+
core.scene.traverse((node) => {
|
|
33
|
+
if (node.type === 'image' && node.props.src === source) {
|
|
34
|
+
(node.props.onError as ((error: Error) => void) | undefined)?.(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
state.imageSubscriptions.set(source, dispose);
|
|
40
|
+
}
|
|
41
|
+
}
|