@asyra/render 0.2.4 → 0.5.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/LICENSE +21 -0
- package/README.md +17 -1
- package/dist/canvas-pipeline-debugger/index.d.ts +4 -0
- package/dist/canvas-pipeline-debugger/index.d.ts.map +1 -0
- package/dist/canvas-pipeline-debugger/index.js +3 -0
- package/dist/canvas-pipeline-debugger/index.js.map +1 -0
- package/dist/canvas-pipeline-debugger/overlay.d.ts +4 -0
- package/dist/canvas-pipeline-debugger/overlay.d.ts.map +1 -0
- package/dist/canvas-pipeline-debugger/overlay.js +90 -0
- package/dist/canvas-pipeline-debugger/overlay.js.map +1 -0
- package/dist/canvas-pipeline-debugger/trace-projector.d.ts +8 -0
- package/dist/canvas-pipeline-debugger/trace-projector.d.ts.map +1 -0
- package/dist/canvas-pipeline-debugger/trace-projector.js +329 -0
- package/dist/canvas-pipeline-debugger/trace-projector.js.map +1 -0
- package/dist/canvas-pipeline-debugger/types.d.ts +77 -0
- package/dist/canvas-pipeline-debugger/types.d.ts.map +1 -0
- package/dist/canvas-pipeline-debugger/types.js.map +1 -0
- package/dist/diagnostics/canvas-pipeline.d.ts +84 -0
- package/dist/diagnostics/canvas-pipeline.d.ts.map +1 -0
- package/dist/diagnostics/canvas-pipeline.js +197 -0
- package/dist/diagnostics/canvas-pipeline.js.map +1 -0
- package/dist/diagnostics/freeze-evidence.d.ts +2 -0
- package/dist/diagnostics/freeze-evidence.d.ts.map +1 -0
- package/dist/diagnostics/freeze-evidence.js +9 -0
- package/dist/diagnostics/freeze-evidence.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/fills/even-odd-fill.d.ts +38 -0
- package/dist/fills/even-odd-fill.d.ts.map +1 -0
- package/dist/fills/even-odd-fill.js +369 -0
- package/dist/fills/even-odd-fill.js.map +1 -0
- package/dist/fills/gradient-fill.d.ts +27 -0
- package/dist/fills/gradient-fill.d.ts.map +1 -0
- package/dist/fills/gradient-fill.js +8 -0
- package/dist/fills/gradient-fill.js.map +1 -0
- package/dist/handlers/element-selection.d.ts +15 -2
- package/dist/handlers/element-selection.d.ts.map +1 -1
- package/dist/handlers/element-selection.js +19 -4
- package/dist/handlers/element-selection.js.map +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/index.js +1 -1
- package/dist/handlers/index.js.map +1 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/interaction/engine-interaction-bridge.d.ts +9 -0
- package/dist/interaction/engine-interaction-bridge.d.ts.map +1 -0
- package/dist/interaction/engine-interaction-bridge.js +22 -0
- package/dist/interaction/engine-interaction-bridge.js.map +1 -0
- package/dist/interaction/interaction-bridge.d.ts +26 -0
- package/dist/interaction/interaction-bridge.d.ts.map +1 -0
- package/dist/interaction/interaction-bridge.js +238 -0
- package/dist/interaction/interaction-bridge.js.map +1 -0
- package/dist/interaction/target-helpers.d.ts +31 -0
- package/dist/interaction/target-helpers.d.ts.map +1 -0
- package/dist/interaction/target-helpers.js +99 -0
- package/dist/interaction/target-helpers.js.map +1 -0
- package/dist/layers/overlay-layer.d.ts +30 -0
- package/dist/layers/overlay-layer.d.ts.map +1 -0
- package/dist/layers/overlay-layer.js +161 -0
- package/dist/layers/overlay-layer.js.map +1 -0
- package/dist/layers/scene/index.d.ts +2 -0
- package/dist/layers/scene/index.d.ts.map +1 -0
- package/dist/layers/scene/index.js +2 -0
- package/dist/layers/scene/index.js.map +1 -0
- package/dist/{render-layer → layers/scene}/render-layer.d.ts +15 -15
- package/dist/layers/scene/render-layer.d.ts.map +1 -0
- package/dist/layers/scene/render-layer.js +347 -0
- package/dist/layers/scene/render-layer.js.map +1 -0
- package/dist/layers/viewport/index.d.ts +2 -0
- package/dist/layers/viewport/index.d.ts.map +1 -0
- package/dist/layers/viewport/index.js +2 -0
- package/dist/layers/viewport/index.js.map +1 -0
- package/dist/{viewport-layer → layers/viewport}/viewport-layer.d.ts +23 -12
- package/dist/layers/viewport/viewport-layer.d.ts.map +1 -0
- package/dist/{viewport-layer → layers/viewport}/viewport-layer.js +31 -10
- package/dist/layers/viewport/viewport-layer.js.map +1 -0
- package/dist/pixi-renderer.d.ts +6 -0
- package/dist/pixi-renderer.d.ts.map +1 -0
- package/dist/pixi-renderer.js +6 -0
- package/dist/pixi-renderer.js.map +1 -0
- package/dist/projections/mesh-projection.d.ts +32 -0
- package/dist/projections/mesh-projection.d.ts.map +1 -0
- package/dist/projections/mesh-projection.js +192 -0
- package/dist/projections/mesh-projection.js.map +1 -0
- package/dist/registries/interaction-target.d.ts +31 -0
- package/dist/registries/interaction-target.d.ts.map +1 -0
- package/dist/registries/interaction-target.js +126 -0
- package/dist/registries/interaction-target.js.map +1 -0
- package/dist/registries/render-interaction-handler.d.ts +12 -0
- package/dist/registries/render-interaction-handler.d.ts.map +1 -0
- package/dist/registries/render-interaction-handler.js +81 -0
- package/dist/registries/render-interaction-handler.js.map +1 -0
- package/dist/registries/render-layer.d.ts +14 -0
- package/dist/registries/render-layer.d.ts.map +1 -0
- package/dist/registries/render-layer.js +44 -0
- package/dist/registries/render-layer.js.map +1 -0
- package/dist/registries/render-strategy.d.ts +12 -0
- package/dist/registries/render-strategy.d.ts.map +1 -0
- package/dist/registries/render-strategy.js +29 -0
- package/dist/registries/render-strategy.js.map +1 -0
- package/dist/render.d.ts +102 -39
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +629 -68
- package/dist/render.js.map +1 -1
- package/dist/renderer.d.ts +33 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +88 -0
- package/dist/renderer.js.map +1 -0
- package/dist/stores/scene-tree.d.ts +58 -7
- package/dist/stores/scene-tree.d.ts.map +1 -1
- package/dist/stores/scene-tree.js +1270 -28
- package/dist/stores/scene-tree.js.map +1 -1
- package/dist/stores/selection.d.ts +3 -2
- package/dist/stores/selection.d.ts.map +1 -1
- package/dist/stores/selection.js +9 -4
- package/dist/stores/selection.js.map +1 -1
- package/dist/strategies/default-strategy.d.ts +4 -0
- package/dist/strategies/default-strategy.d.ts.map +1 -0
- package/dist/strategies/default-strategy.js +15 -0
- package/dist/strategies/default-strategy.js.map +1 -0
- package/dist/types/render-interaction.d.ts +25 -0
- package/dist/types/render-interaction.d.ts.map +1 -0
- package/dist/types/render-interaction.js +2 -0
- package/dist/types/render-interaction.js.map +1 -0
- package/dist/types/render-layer.d.ts +8 -0
- package/dist/types/render-layer.d.ts.map +1 -0
- package/dist/types/render-layer.js +2 -0
- package/dist/types/render-layer.js.map +1 -0
- package/dist/types/render-object.d.ts +190 -0
- package/dist/types/render-object.d.ts.map +1 -0
- package/dist/types/render-object.js +870 -0
- package/dist/types/render-object.js.map +1 -0
- package/dist/types/render-strategy.compatibility.d.ts +2 -0
- package/dist/types/render-strategy.compatibility.d.ts.map +1 -0
- package/dist/types/render-strategy.compatibility.js +2 -0
- package/dist/types/render-strategy.compatibility.js.map +1 -0
- package/dist/types/render-strategy.d.ts +35 -0
- package/dist/types/render-strategy.d.ts.map +1 -0
- package/dist/types/render-strategy.js +2 -0
- package/dist/types/render-strategy.js.map +1 -0
- package/dist/types/renderer.d.ts +86 -0
- package/dist/types/renderer.d.ts.map +1 -0
- package/dist/types/renderer.js +2 -0
- package/dist/types/renderer.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +33 -8
- package/.turbo/turbo-test$colon$local.log +0 -45
- package/CHANGELOG.md +0 -46
- package/dist/__tests__/render.test.d.ts +0 -2
- package/dist/__tests__/render.test.d.ts.map +0 -1
- package/dist/__tests__/render.test.js +0 -148
- package/dist/__tests__/render.test.js.map +0 -1
- package/dist/render-layer/element-interaction-handler.d.ts +0 -8
- package/dist/render-layer/element-interaction-handler.d.ts.map +0 -1
- package/dist/render-layer/element-interaction-handler.js +0 -20
- package/dist/render-layer/element-interaction-handler.js.map +0 -1
- package/dist/render-layer/index.d.ts +0 -2
- package/dist/render-layer/index.d.ts.map +0 -1
- package/dist/render-layer/index.js +0 -2
- package/dist/render-layer/index.js.map +0 -1
- package/dist/render-layer/render-layer.d.ts.map +0 -1
- package/dist/render-layer/render-layer.js +0 -189
- package/dist/render-layer/render-layer.js.map +0 -1
- package/dist/selection-layer/index.d.ts +0 -3
- package/dist/selection-layer/index.d.ts.map +0 -1
- package/dist/selection-layer/index.js +0 -3
- package/dist/selection-layer/index.js.map +0 -1
- package/dist/selection-layer/selection-layer.d.ts +0 -29
- package/dist/selection-layer/selection-layer.d.ts.map +0 -1
- package/dist/selection-layer/selection-layer.js +0 -63
- package/dist/selection-layer/selection-layer.js.map +0 -1
- package/dist/selection-layer/utils.d.ts +0 -13
- package/dist/selection-layer/utils.d.ts.map +0 -1
- package/dist/selection-layer/utils.js +0 -27
- package/dist/selection-layer/utils.js.map +0 -1
- package/dist/subscribes/index.d.ts +0 -2
- package/dist/subscribes/index.d.ts.map +0 -1
- package/dist/subscribes/index.js +0 -11
- package/dist/subscribes/index.js.map +0 -1
- package/dist/subscribes/scene-tree.d.ts +0 -4
- package/dist/subscribes/scene-tree.d.ts.map +0 -1
- package/dist/subscribes/scene-tree.js +0 -56
- package/dist/subscribes/scene-tree.js.map +0 -1
- package/dist/subscribes/selection.d.ts +0 -3
- package/dist/subscribes/selection.d.ts.map +0 -1
- package/dist/subscribes/selection.js +0 -31
- package/dist/subscribes/selection.js.map +0 -1
- package/dist/subscribes/system.d.ts +0 -2
- package/dist/subscribes/system.d.ts.map +0 -1
- package/dist/subscribes/system.js +0 -15
- package/dist/subscribes/system.js.map +0 -1
- package/dist/subscribes/viewport.d.ts +0 -2
- package/dist/subscribes/viewport.d.ts.map +0 -1
- package/dist/subscribes/viewport.js +0 -36
- package/dist/subscribes/viewport.js.map +0 -1
- package/dist/viewport-layer/index.d.ts +0 -4
- package/dist/viewport-layer/index.d.ts.map +0 -1
- package/dist/viewport-layer/index.js +0 -4
- package/dist/viewport-layer/index.js.map +0 -1
- package/dist/viewport-layer/types.d.ts +0 -17
- package/dist/viewport-layer/types.d.ts.map +0 -1
- package/dist/viewport-layer/types.js.map +0 -1
- package/dist/viewport-layer/utils.d.ts +0 -8
- package/dist/viewport-layer/utils.d.ts.map +0 -1
- package/dist/viewport-layer/utils.js +0 -49
- package/dist/viewport-layer/utils.js.map +0 -1
- package/dist/viewport-layer/viewport-layer.d.ts.map +0 -1
- package/dist/viewport-layer/viewport-layer.js.map +0 -1
- package/src/__tests__/render.test.ts +0 -209
- package/src/handlers/element-selection.ts +0 -7
- package/src/handlers/index.ts +0 -1
- package/src/index.ts +0 -7
- package/src/render-layer/element-interaction-handler.ts +0 -31
- package/src/render-layer/index.ts +0 -1
- package/src/render-layer/render-layer.ts +0 -238
- package/src/render.ts +0 -161
- package/src/selection-layer/index.ts +0 -2
- package/src/selection-layer/selection-layer.ts +0 -90
- package/src/selection-layer/utils.ts +0 -37
- package/src/stores/scene-tree.ts +0 -79
- package/src/stores/selection.ts +0 -40
- package/src/subscribes/index.ts +0 -11
- package/src/subscribes/scene-tree.ts +0 -72
- package/src/subscribes/selection.ts +0 -40
- package/src/subscribes/system.ts +0 -18
- package/src/subscribes/viewport.ts +0 -54
- package/src/types.ts +0 -15
- package/src/viewport-layer/index.ts +0 -3
- package/src/viewport-layer/types.ts +0 -18
- package/src/viewport-layer/utils.ts +0 -55
- package/src/viewport-layer/viewport-layer.ts +0 -172
- package/test-global.d.ts +0 -11
- package/test-setup.ts +0 -28
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -8
- /package/dist/{viewport-layer → canvas-pipeline-debugger}/types.js +0 -0
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
export const createRenderResourceStyle = (descriptor) => {
|
|
2
|
+
const listeners = new Set();
|
|
3
|
+
let released = false;
|
|
4
|
+
const style = {
|
|
5
|
+
__renderResourceDescriptor: descriptor
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperties(style, {
|
|
8
|
+
__subscribeRenderResourceRelease: {
|
|
9
|
+
enumerable: false,
|
|
10
|
+
value: (listener) => {
|
|
11
|
+
if (released) {
|
|
12
|
+
listener();
|
|
13
|
+
return () => undefined;
|
|
14
|
+
}
|
|
15
|
+
listeners.add(listener);
|
|
16
|
+
return () => listeners.delete(listener);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
__isRenderResourceReleased: {
|
|
20
|
+
enumerable: false,
|
|
21
|
+
value: () => released
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
style,
|
|
26
|
+
dispose: () => {
|
|
27
|
+
if (released) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
released = true;
|
|
31
|
+
listeners.forEach((listener) => listener());
|
|
32
|
+
listeners.clear();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export class RenderMatrix {
|
|
37
|
+
constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
|
|
38
|
+
this.a = a;
|
|
39
|
+
this.b = b;
|
|
40
|
+
this.c = c;
|
|
41
|
+
this.d = d;
|
|
42
|
+
this.tx = tx;
|
|
43
|
+
this.ty = ty;
|
|
44
|
+
}
|
|
45
|
+
clone() {
|
|
46
|
+
return new RenderMatrix(this.a, this.b, this.c, this.d, this.tx, this.ty);
|
|
47
|
+
}
|
|
48
|
+
apply(point) {
|
|
49
|
+
return {
|
|
50
|
+
x: this.a * point.x + this.c * point.y + this.tx,
|
|
51
|
+
y: this.b * point.x + this.d * point.y + this.ty
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
applyInverse(point) {
|
|
55
|
+
const determinant = this.a * this.d - this.b * this.c;
|
|
56
|
+
if (Math.abs(determinant) <= Number.EPSILON) {
|
|
57
|
+
return { x: 0, y: 0 };
|
|
58
|
+
}
|
|
59
|
+
const x = point.x - this.tx;
|
|
60
|
+
const y = point.y - this.ty;
|
|
61
|
+
return {
|
|
62
|
+
x: (this.d * x - this.c * y) / determinant,
|
|
63
|
+
y: (-this.b * x + this.a * y) / determinant
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const multiplyMatrices = (parent, local) => new RenderMatrix(parent.a * local.a + parent.c * local.b, parent.b * local.a + parent.d * local.b, parent.a * local.c + parent.c * local.d, parent.b * local.c + parent.d * local.d, parent.a * local.tx + parent.c * local.ty + parent.tx, parent.b * local.tx + parent.d * local.ty + parent.ty);
|
|
68
|
+
export class RenderPoint {
|
|
69
|
+
constructor(onChange, x = 0, y = 0) {
|
|
70
|
+
this.onChange = onChange;
|
|
71
|
+
this.x = x;
|
|
72
|
+
this.y = y;
|
|
73
|
+
}
|
|
74
|
+
set(x, y = x) {
|
|
75
|
+
this.x = x;
|
|
76
|
+
this.y = y;
|
|
77
|
+
this.onChange(x, y);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const normalizePaint = (value) => {
|
|
81
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
82
|
+
return { color: value };
|
|
83
|
+
}
|
|
84
|
+
if (typeof value === 'object' && value !== null) {
|
|
85
|
+
const style = value;
|
|
86
|
+
if (style.fill !== undefined) {
|
|
87
|
+
return normalizePaint(style.fill);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
color: typeof style.color === 'number' || typeof style.color === 'string'
|
|
91
|
+
? style.color
|
|
92
|
+
: undefined,
|
|
93
|
+
alpha: typeof style.alpha === 'number' ? style.alpha : undefined
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {};
|
|
97
|
+
};
|
|
98
|
+
export class RenderObjectRuntime {
|
|
99
|
+
constructor(engine, root, beforeExecute) {
|
|
100
|
+
this.engine = engine;
|
|
101
|
+
this.root = root;
|
|
102
|
+
this.beforeExecute = beforeExecute;
|
|
103
|
+
this.objectByHandle = new Map();
|
|
104
|
+
this.dirtyGraphics = new Set();
|
|
105
|
+
this.resourceByStyle = new WeakMap();
|
|
106
|
+
this.resourceStylesByGraphics = new Map();
|
|
107
|
+
this.resourceReleaseSubscriptions = new Set();
|
|
108
|
+
}
|
|
109
|
+
execute(command, node, relatedNode) {
|
|
110
|
+
this.beforeExecute?.(command, node, relatedNode);
|
|
111
|
+
return this.engine.execute(command);
|
|
112
|
+
}
|
|
113
|
+
attachRoot(node) {
|
|
114
|
+
const handle = this.attachNode(node);
|
|
115
|
+
this.execute({
|
|
116
|
+
type: 'append-child',
|
|
117
|
+
parent: this.root,
|
|
118
|
+
child: handle
|
|
119
|
+
}, node);
|
|
120
|
+
}
|
|
121
|
+
detachRoot(node) {
|
|
122
|
+
const handle = node.getEngineHandle();
|
|
123
|
+
if (handle) {
|
|
124
|
+
this.execute({
|
|
125
|
+
type: 'remove-child',
|
|
126
|
+
parent: this.root,
|
|
127
|
+
child: handle
|
|
128
|
+
}, node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
attachNode(node) {
|
|
132
|
+
const existingHandle = node.getEngineHandle();
|
|
133
|
+
if (existingHandle) {
|
|
134
|
+
return existingHandle;
|
|
135
|
+
}
|
|
136
|
+
const result = this.execute({
|
|
137
|
+
type: 'create-object',
|
|
138
|
+
requestId: node.label || node.objectType,
|
|
139
|
+
objectType: node.objectType,
|
|
140
|
+
properties: node.getEngineProperties()
|
|
141
|
+
}, node);
|
|
142
|
+
if (!result.object) {
|
|
143
|
+
throw new Error('Render engine did not return an object handle');
|
|
144
|
+
}
|
|
145
|
+
node.bindRuntime(this, result.object);
|
|
146
|
+
this.objectByHandle.set(result.object, node);
|
|
147
|
+
node.children.forEach((child) => {
|
|
148
|
+
const childHandle = this.attachNode(child);
|
|
149
|
+
this.execute({
|
|
150
|
+
type: 'append-child',
|
|
151
|
+
parent: result.object,
|
|
152
|
+
child: childHandle
|
|
153
|
+
}, child, node);
|
|
154
|
+
});
|
|
155
|
+
if (node instanceof RenderGraphics) {
|
|
156
|
+
this.dirtyGraphics.add(node);
|
|
157
|
+
}
|
|
158
|
+
return result.object;
|
|
159
|
+
}
|
|
160
|
+
appendChild(parent, child, index) {
|
|
161
|
+
const parentHandle = parent.getEngineHandle();
|
|
162
|
+
if (!parentHandle) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const childHandle = this.attachNode(child);
|
|
166
|
+
this.execute({
|
|
167
|
+
type: 'append-child',
|
|
168
|
+
parent: parentHandle,
|
|
169
|
+
child: childHandle
|
|
170
|
+
}, child, parent);
|
|
171
|
+
if (index !== undefined) {
|
|
172
|
+
this.execute({
|
|
173
|
+
type: 'set-child-index',
|
|
174
|
+
parent: parentHandle,
|
|
175
|
+
child: childHandle,
|
|
176
|
+
index
|
|
177
|
+
}, child, parent);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
removeChild(parent, child) {
|
|
181
|
+
const parentHandle = parent.getEngineHandle();
|
|
182
|
+
const childHandle = child.getEngineHandle();
|
|
183
|
+
if (parentHandle && childHandle) {
|
|
184
|
+
this.execute({
|
|
185
|
+
type: 'remove-child',
|
|
186
|
+
parent: parentHandle,
|
|
187
|
+
child: childHandle
|
|
188
|
+
}, child, parent);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
setChildIndex(parent, child, index) {
|
|
192
|
+
const parentHandle = parent.getEngineHandle();
|
|
193
|
+
const childHandle = child.getEngineHandle();
|
|
194
|
+
if (parentHandle && childHandle) {
|
|
195
|
+
this.execute({
|
|
196
|
+
type: 'set-child-index',
|
|
197
|
+
parent: parentHandle,
|
|
198
|
+
child: childHandle,
|
|
199
|
+
index
|
|
200
|
+
}, child, parent);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
updateObject(node, properties) {
|
|
204
|
+
const handle = node.getEngineHandle();
|
|
205
|
+
if (handle) {
|
|
206
|
+
this.execute({ type: 'update-object', object: handle, properties }, node);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
destroyObject(node) {
|
|
210
|
+
const handle = node.getEngineHandle();
|
|
211
|
+
if (!handle) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.execute({ type: 'destroy-object', object: handle }, node);
|
|
215
|
+
this.objectByHandle.delete(handle);
|
|
216
|
+
node.unbindRuntime();
|
|
217
|
+
}
|
|
218
|
+
markDrawDirty(graphics) {
|
|
219
|
+
if (graphics.getEngineHandle()) {
|
|
220
|
+
this.dirtyGraphics.add(graphics);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
flushDraws() {
|
|
224
|
+
if (this.dirtyGraphics.size === 0) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
for (const graphics of this.dirtyGraphics) {
|
|
228
|
+
const handle = graphics.getEngineHandle();
|
|
229
|
+
if (handle) {
|
|
230
|
+
this.execute({
|
|
231
|
+
type: 'draw',
|
|
232
|
+
object: handle,
|
|
233
|
+
operations: graphics.getDrawOperations()
|
|
234
|
+
}, graphics);
|
|
235
|
+
graphics.markDrawClean();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
this.dirtyGraphics.clear();
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
createPaint(style, owner) {
|
|
242
|
+
const resourceCandidate = typeof style === 'object' && style !== null && 'fill' in style
|
|
243
|
+
? style.fill
|
|
244
|
+
: style;
|
|
245
|
+
if (typeof resourceCandidate === 'object' &&
|
|
246
|
+
resourceCandidate !== null &&
|
|
247
|
+
'__renderResourceDescriptor' in resourceCandidate) {
|
|
248
|
+
const resourceStyle = resourceCandidate;
|
|
249
|
+
if (resourceStyle.__isRenderResourceReleased?.()) {
|
|
250
|
+
throw new Error('Cannot use a disposed render resource style');
|
|
251
|
+
}
|
|
252
|
+
let record = this.resourceByStyle.get(resourceCandidate);
|
|
253
|
+
if (!record) {
|
|
254
|
+
const result = this.execute({
|
|
255
|
+
type: 'create-resource',
|
|
256
|
+
requestId: resourceStyle.__renderResourceDescriptor.kind,
|
|
257
|
+
descriptor: resourceStyle.__renderResourceDescriptor
|
|
258
|
+
}, owner);
|
|
259
|
+
if (!result.resource) {
|
|
260
|
+
throw new Error('Render engine did not return a resource handle');
|
|
261
|
+
}
|
|
262
|
+
const createdRecord = {
|
|
263
|
+
handle: result.resource,
|
|
264
|
+
owners: new Set()
|
|
265
|
+
};
|
|
266
|
+
record = createdRecord;
|
|
267
|
+
this.resourceByStyle.set(resourceCandidate, createdRecord);
|
|
268
|
+
const unsubscribe = resourceStyle.__subscribeRenderResourceRelease?.(() => {
|
|
269
|
+
this.destroyResourceRecord(resourceCandidate, createdRecord);
|
|
270
|
+
});
|
|
271
|
+
if (unsubscribe) {
|
|
272
|
+
createdRecord.unsubscribe = unsubscribe;
|
|
273
|
+
this.resourceReleaseSubscriptions.add(unsubscribe);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (owner) {
|
|
277
|
+
record.owners.add(owner);
|
|
278
|
+
const styles = this.resourceStylesByGraphics.get(owner) ?? new Set();
|
|
279
|
+
styles.add(resourceCandidate);
|
|
280
|
+
this.resourceStylesByGraphics.set(owner, styles);
|
|
281
|
+
}
|
|
282
|
+
return { resource: record.handle };
|
|
283
|
+
}
|
|
284
|
+
return normalizePaint(style);
|
|
285
|
+
}
|
|
286
|
+
releaseGraphicResources(graphics) {
|
|
287
|
+
const styles = this.resourceStylesByGraphics.get(graphics);
|
|
288
|
+
if (!styles) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
styles.forEach((style) => {
|
|
292
|
+
const record = this.resourceByStyle.get(style);
|
|
293
|
+
if (!record) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
record.owners.delete(graphics);
|
|
297
|
+
if (record.owners.size === 0) {
|
|
298
|
+
this.destroyResourceRecord(style, record);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
this.resourceStylesByGraphics.delete(graphics);
|
|
302
|
+
}
|
|
303
|
+
getObject(handle) {
|
|
304
|
+
return handle ? (this.objectByHandle.get(handle) ?? null) : null;
|
|
305
|
+
}
|
|
306
|
+
detachResourceLifecycles() {
|
|
307
|
+
this.resourceReleaseSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
308
|
+
this.resourceReleaseSubscriptions.clear();
|
|
309
|
+
}
|
|
310
|
+
destroyResourceRecord(style, record) {
|
|
311
|
+
if (this.resourceByStyle.get(style) !== record) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this.execute({
|
|
315
|
+
type: 'destroy-resource',
|
|
316
|
+
resource: record.handle
|
|
317
|
+
});
|
|
318
|
+
this.resourceByStyle.delete(style);
|
|
319
|
+
record.owners.forEach((owner) => {
|
|
320
|
+
const styles = this.resourceStylesByGraphics.get(owner);
|
|
321
|
+
styles?.delete(style);
|
|
322
|
+
if (styles?.size === 0) {
|
|
323
|
+
this.resourceStylesByGraphics.delete(owner);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
record.owners.clear();
|
|
327
|
+
if (record.unsubscribe) {
|
|
328
|
+
record.unsubscribe();
|
|
329
|
+
this.resourceReleaseSubscriptions.delete(record.unsubscribe);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
queryPoint(type, node, point) {
|
|
333
|
+
const handle = node.getEngineHandle();
|
|
334
|
+
if (!handle) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
const result = this.engine.query({
|
|
338
|
+
type,
|
|
339
|
+
object: handle,
|
|
340
|
+
point
|
|
341
|
+
});
|
|
342
|
+
return result.type === 'point' ? result.point : null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
export class RenderNode {
|
|
346
|
+
constructor(objectType) {
|
|
347
|
+
this.objectType = objectType;
|
|
348
|
+
this.children = [];
|
|
349
|
+
this.parent = null;
|
|
350
|
+
this.hitArea = null;
|
|
351
|
+
this.context = { batchMode: 'auto' };
|
|
352
|
+
this.geometry = { clear: () => undefined };
|
|
353
|
+
this._transform = { updateLocalTransform: () => undefined };
|
|
354
|
+
this.listeners = new Map();
|
|
355
|
+
this._x = 0;
|
|
356
|
+
this._y = 0;
|
|
357
|
+
this._width = 0;
|
|
358
|
+
this._height = 0;
|
|
359
|
+
this._visible = true;
|
|
360
|
+
this._renderable = true;
|
|
361
|
+
this._label = '';
|
|
362
|
+
this._eventMode = 'auto';
|
|
363
|
+
this._cursor = 'default';
|
|
364
|
+
this._alpha = 1;
|
|
365
|
+
this._angle = 0;
|
|
366
|
+
this._rotation = 0;
|
|
367
|
+
this._zIndex = 0;
|
|
368
|
+
this._batched = false;
|
|
369
|
+
this.handle = null;
|
|
370
|
+
this.runtime = null;
|
|
371
|
+
this.position = new RenderPoint((x, y) => {
|
|
372
|
+
this._x = x;
|
|
373
|
+
this._y = y;
|
|
374
|
+
this.updateEngineProperties({ x, y });
|
|
375
|
+
});
|
|
376
|
+
this.scale = new RenderPoint((scaleX, scaleY) => {
|
|
377
|
+
this.updateEngineProperties({
|
|
378
|
+
scaleX: scaleX * this.getDimensionScaleX(),
|
|
379
|
+
scaleY: scaleY * this.getDimensionScaleY()
|
|
380
|
+
});
|
|
381
|
+
}, 1, 1);
|
|
382
|
+
this.skew = new RenderPoint((skewX, skewY) => {
|
|
383
|
+
this.updateEngineProperties({ skewX, skewY });
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
get x() {
|
|
387
|
+
return this._x;
|
|
388
|
+
}
|
|
389
|
+
set x(value) {
|
|
390
|
+
this._x = value;
|
|
391
|
+
this.position.x = value;
|
|
392
|
+
this.updateEngineProperties({ x: value });
|
|
393
|
+
}
|
|
394
|
+
get y() {
|
|
395
|
+
return this._y;
|
|
396
|
+
}
|
|
397
|
+
set y(value) {
|
|
398
|
+
this._y = value;
|
|
399
|
+
this.position.y = value;
|
|
400
|
+
this.updateEngineProperties({ y: value });
|
|
401
|
+
}
|
|
402
|
+
get width() {
|
|
403
|
+
return this._width || this.getLocalBounds().width;
|
|
404
|
+
}
|
|
405
|
+
set width(value) {
|
|
406
|
+
this._width = value;
|
|
407
|
+
this.updateEngineProperties({
|
|
408
|
+
width: value,
|
|
409
|
+
scaleX: this.scale.x * this.getDimensionScaleX()
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
get height() {
|
|
413
|
+
return this._height || this.getLocalBounds().height;
|
|
414
|
+
}
|
|
415
|
+
set height(value) {
|
|
416
|
+
this._height = value;
|
|
417
|
+
this.updateEngineProperties({
|
|
418
|
+
height: value,
|
|
419
|
+
scaleY: this.scale.y * this.getDimensionScaleY()
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
get visible() {
|
|
423
|
+
return this._visible;
|
|
424
|
+
}
|
|
425
|
+
set visible(value) {
|
|
426
|
+
this._visible = value;
|
|
427
|
+
this.updateEngineProperties({ visible: value });
|
|
428
|
+
}
|
|
429
|
+
get renderable() {
|
|
430
|
+
return this._renderable;
|
|
431
|
+
}
|
|
432
|
+
set renderable(value) {
|
|
433
|
+
this._renderable = value;
|
|
434
|
+
this.updateEngineProperties({ renderable: value });
|
|
435
|
+
}
|
|
436
|
+
get label() {
|
|
437
|
+
return this._label;
|
|
438
|
+
}
|
|
439
|
+
set label(value) {
|
|
440
|
+
this._label = value;
|
|
441
|
+
this.updateEngineProperties({ label: value });
|
|
442
|
+
}
|
|
443
|
+
get eventMode() {
|
|
444
|
+
return this._eventMode;
|
|
445
|
+
}
|
|
446
|
+
set eventMode(value) {
|
|
447
|
+
this._eventMode = value;
|
|
448
|
+
this.updateEngineProperties({ eventMode: value });
|
|
449
|
+
}
|
|
450
|
+
get cursor() {
|
|
451
|
+
return this._cursor;
|
|
452
|
+
}
|
|
453
|
+
set cursor(value) {
|
|
454
|
+
this._cursor = value;
|
|
455
|
+
this.updateEngineProperties({ cursor: value });
|
|
456
|
+
}
|
|
457
|
+
get alpha() {
|
|
458
|
+
return this._alpha;
|
|
459
|
+
}
|
|
460
|
+
set alpha(value) {
|
|
461
|
+
this._alpha = value;
|
|
462
|
+
this.updateEngineProperties({ alpha: value });
|
|
463
|
+
}
|
|
464
|
+
get angle() {
|
|
465
|
+
return this._angle;
|
|
466
|
+
}
|
|
467
|
+
set angle(value) {
|
|
468
|
+
this._angle = value;
|
|
469
|
+
this.updateEngineProperties({ angle: value });
|
|
470
|
+
}
|
|
471
|
+
get rotation() {
|
|
472
|
+
return this._rotation;
|
|
473
|
+
}
|
|
474
|
+
set rotation(value) {
|
|
475
|
+
this._rotation = value;
|
|
476
|
+
this.updateEngineProperties({ rotation: value });
|
|
477
|
+
}
|
|
478
|
+
get zIndex() {
|
|
479
|
+
return this._zIndex;
|
|
480
|
+
}
|
|
481
|
+
set zIndex(value) {
|
|
482
|
+
this._zIndex = value;
|
|
483
|
+
this.updateEngineProperties({ zIndex: value });
|
|
484
|
+
}
|
|
485
|
+
get batched() {
|
|
486
|
+
return this._batched;
|
|
487
|
+
}
|
|
488
|
+
set batched(value) {
|
|
489
|
+
this._batched = value;
|
|
490
|
+
this.updateEngineProperties({ batched: value });
|
|
491
|
+
}
|
|
492
|
+
get worldTransform() {
|
|
493
|
+
const rotationPlusSkewY = this.rotation + this.skew.y;
|
|
494
|
+
const rotationMinusSkewX = this.rotation - this.skew.x;
|
|
495
|
+
const scaleX = this.scale.x * this.getDimensionScaleX();
|
|
496
|
+
const scaleY = this.scale.y * this.getDimensionScaleY();
|
|
497
|
+
const local = new RenderMatrix(Math.cos(rotationPlusSkewY) * scaleX, Math.sin(rotationPlusSkewY) * scaleX, -Math.sin(rotationMinusSkewX) * scaleY, Math.cos(rotationMinusSkewX) * scaleY, this.x, this.y);
|
|
498
|
+
return this.parent
|
|
499
|
+
? multiplyMatrices(this.parent.worldTransform, local)
|
|
500
|
+
: local;
|
|
501
|
+
}
|
|
502
|
+
getEngineProperties() {
|
|
503
|
+
return {
|
|
504
|
+
x: this.x,
|
|
505
|
+
y: this.y,
|
|
506
|
+
width: this._width,
|
|
507
|
+
height: this._height,
|
|
508
|
+
scaleX: this.scale.x * this.getDimensionScaleX(),
|
|
509
|
+
scaleY: this.scale.y * this.getDimensionScaleY(),
|
|
510
|
+
skewX: this.skew.x,
|
|
511
|
+
skewY: this.skew.y,
|
|
512
|
+
visible: this.visible,
|
|
513
|
+
renderable: this.renderable,
|
|
514
|
+
label: this.label,
|
|
515
|
+
alpha: this.alpha,
|
|
516
|
+
angle: this.angle,
|
|
517
|
+
rotation: this.rotation,
|
|
518
|
+
zIndex: this.zIndex,
|
|
519
|
+
eventMode: this.eventMode,
|
|
520
|
+
cursor: this.cursor,
|
|
521
|
+
batched: this.batched
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
getDimensionScaleX() {
|
|
525
|
+
const geometryBounds = this.__geometryLocalBounds;
|
|
526
|
+
return geometryBounds &&
|
|
527
|
+
geometryBounds.width > 0 &&
|
|
528
|
+
Number.isFinite(geometryBounds.width) &&
|
|
529
|
+
this._width > 0
|
|
530
|
+
? this._width / geometryBounds.width
|
|
531
|
+
: 1;
|
|
532
|
+
}
|
|
533
|
+
getDimensionScaleY() {
|
|
534
|
+
const geometryBounds = this.__geometryLocalBounds;
|
|
535
|
+
return geometryBounds &&
|
|
536
|
+
geometryBounds.height > 0 &&
|
|
537
|
+
Number.isFinite(geometryBounds.height) &&
|
|
538
|
+
this._height > 0
|
|
539
|
+
? this._height / geometryBounds.height
|
|
540
|
+
: 1;
|
|
541
|
+
}
|
|
542
|
+
bindRuntime(runtime, handle) {
|
|
543
|
+
this.runtime = runtime;
|
|
544
|
+
this.handle = handle;
|
|
545
|
+
}
|
|
546
|
+
unbindRuntime() {
|
|
547
|
+
this.runtime = null;
|
|
548
|
+
this.handle = null;
|
|
549
|
+
}
|
|
550
|
+
releaseRuntime() {
|
|
551
|
+
this.children.forEach((child) => child.releaseRuntime());
|
|
552
|
+
this.unbindRuntime();
|
|
553
|
+
}
|
|
554
|
+
getEngineHandle() {
|
|
555
|
+
return this.handle;
|
|
556
|
+
}
|
|
557
|
+
addChild(child) {
|
|
558
|
+
return this.addChildAt(child, this.children.length);
|
|
559
|
+
}
|
|
560
|
+
addChildAt(child, index) {
|
|
561
|
+
if (child.parent === this) {
|
|
562
|
+
this.setChildIndex(child, index);
|
|
563
|
+
return child;
|
|
564
|
+
}
|
|
565
|
+
const previousParent = child.parent;
|
|
566
|
+
const previousIndex = previousParent?.children.indexOf(child) ?? -1;
|
|
567
|
+
const boundedIndex = Math.max(0, Math.min(index, this.children.length));
|
|
568
|
+
if (previousParent && previousIndex >= 0) {
|
|
569
|
+
previousParent.runtime?.removeChild(previousParent, child);
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
this.runtime?.appendChild(this, child, boundedIndex);
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
if (previousParent && previousIndex >= 0) {
|
|
576
|
+
try {
|
|
577
|
+
this.runtime?.removeChild(this, child);
|
|
578
|
+
}
|
|
579
|
+
catch {
|
|
580
|
+
// The target append may have failed before attaching the child.
|
|
581
|
+
}
|
|
582
|
+
try {
|
|
583
|
+
previousParent.runtime?.appendChild(previousParent, child, previousIndex);
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
// Preserve the target handoff failure after rollback effort.
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
if (previousParent && previousIndex >= 0) {
|
|
592
|
+
previousParent.children.splice(previousIndex, 1);
|
|
593
|
+
}
|
|
594
|
+
this.children.splice(boundedIndex, 0, child);
|
|
595
|
+
child.parent = this;
|
|
596
|
+
return child;
|
|
597
|
+
}
|
|
598
|
+
removeChild(child) {
|
|
599
|
+
const index = this.children.indexOf(child);
|
|
600
|
+
if (index >= 0) {
|
|
601
|
+
this.runtime?.removeChild(this, child);
|
|
602
|
+
this.children.splice(index, 1);
|
|
603
|
+
child.parent = null;
|
|
604
|
+
}
|
|
605
|
+
return child;
|
|
606
|
+
}
|
|
607
|
+
removeChildren() {
|
|
608
|
+
const removed = [...this.children];
|
|
609
|
+
removed.forEach((child) => this.removeChild(child));
|
|
610
|
+
return removed;
|
|
611
|
+
}
|
|
612
|
+
setChildIndex(child, index) {
|
|
613
|
+
const currentIndex = this.children.indexOf(child);
|
|
614
|
+
if (currentIndex < 0) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const boundedIndex = Math.max(0, Math.min(index, this.children.length - 1));
|
|
618
|
+
this.runtime?.setChildIndex(this, child, boundedIndex);
|
|
619
|
+
this.children.splice(currentIndex, 1);
|
|
620
|
+
this.children.splice(boundedIndex, 0, child);
|
|
621
|
+
}
|
|
622
|
+
toGlobal(point) {
|
|
623
|
+
return this.worldTransform.apply(point);
|
|
624
|
+
}
|
|
625
|
+
toLocal(point) {
|
|
626
|
+
return this.worldTransform.applyInverse(point);
|
|
627
|
+
}
|
|
628
|
+
getLocalBounds() {
|
|
629
|
+
if (this.children.length === 0) {
|
|
630
|
+
return { x: 0, y: 0, width: this._width, height: this._height };
|
|
631
|
+
}
|
|
632
|
+
const childBounds = this.children.map((child) => child.getBounds());
|
|
633
|
+
const minX = Math.min(...childBounds.map((bounds) => bounds.x));
|
|
634
|
+
const minY = Math.min(...childBounds.map((bounds) => bounds.y));
|
|
635
|
+
const maxX = Math.max(...childBounds.map((bounds) => bounds.x + bounds.width));
|
|
636
|
+
const maxY = Math.max(...childBounds.map((bounds) => bounds.y + bounds.height));
|
|
637
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
638
|
+
}
|
|
639
|
+
getBounds() {
|
|
640
|
+
const local = this.getLocalBounds();
|
|
641
|
+
const corners = [
|
|
642
|
+
this.toGlobal({ x: local.x, y: local.y }),
|
|
643
|
+
this.toGlobal({ x: local.x + local.width, y: local.y }),
|
|
644
|
+
this.toGlobal({ x: local.x + local.width, y: local.y + local.height }),
|
|
645
|
+
this.toGlobal({ x: local.x, y: local.y + local.height })
|
|
646
|
+
];
|
|
647
|
+
const minX = Math.min(...corners.map((point) => point.x));
|
|
648
|
+
const minY = Math.min(...corners.map((point) => point.y));
|
|
649
|
+
const maxX = Math.max(...corners.map((point) => point.x));
|
|
650
|
+
const maxY = Math.max(...corners.map((point) => point.y));
|
|
651
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
652
|
+
}
|
|
653
|
+
setTransform(matrix) {
|
|
654
|
+
this.x = matrix.tx;
|
|
655
|
+
this.y = matrix.ty;
|
|
656
|
+
this.rotation = Math.atan2(matrix.b, matrix.a);
|
|
657
|
+
this.scale.set(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d));
|
|
658
|
+
this.updateEngineProperties({
|
|
659
|
+
x: this.x,
|
|
660
|
+
y: this.y,
|
|
661
|
+
rotation: this.rotation,
|
|
662
|
+
scaleX: this.scale.x * this.getDimensionScaleX(),
|
|
663
|
+
scaleY: this.scale.y * this.getDimensionScaleY(),
|
|
664
|
+
skewX: this.skew.x,
|
|
665
|
+
skewY: this.skew.y
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
on(type, listener) {
|
|
669
|
+
const listeners = this.listeners.get(type) ?? new Set();
|
|
670
|
+
listeners.add(listener);
|
|
671
|
+
this.listeners.set(type, listeners);
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
off(type, listener) {
|
|
675
|
+
this.listeners.get(type)?.delete(listener);
|
|
676
|
+
return this;
|
|
677
|
+
}
|
|
678
|
+
removeAllListeners() {
|
|
679
|
+
this.listeners.clear();
|
|
680
|
+
}
|
|
681
|
+
emit(type, event) {
|
|
682
|
+
this.listeners.get(type)?.forEach((listener) => listener(event));
|
|
683
|
+
}
|
|
684
|
+
destroy(options) {
|
|
685
|
+
if (options?.children !== false) {
|
|
686
|
+
;
|
|
687
|
+
[...this.children].reverse().forEach((child) => child.destroy(options));
|
|
688
|
+
}
|
|
689
|
+
this.parent?.removeChild(this);
|
|
690
|
+
this.runtime?.destroyObject(this);
|
|
691
|
+
this.removeAllListeners();
|
|
692
|
+
}
|
|
693
|
+
updateEngineProperties(properties) {
|
|
694
|
+
this.runtime?.updateObject(this, properties);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
export class RenderContainer extends RenderNode {
|
|
698
|
+
constructor(properties = {}, objectType = 'container') {
|
|
699
|
+
super(objectType);
|
|
700
|
+
if (typeof properties.label === 'string')
|
|
701
|
+
this.label = properties.label;
|
|
702
|
+
if (typeof properties.x === 'number')
|
|
703
|
+
this.x = properties.x;
|
|
704
|
+
if (typeof properties.y === 'number')
|
|
705
|
+
this.y = properties.y;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
export class RenderGraphics extends RenderContainer {
|
|
709
|
+
constructor() {
|
|
710
|
+
super({}, 'graphics');
|
|
711
|
+
this.drawOperations = [];
|
|
712
|
+
this.paintStyles = new Map();
|
|
713
|
+
this.drawDirty = false;
|
|
714
|
+
this.bounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
715
|
+
this.lineStyleValue = null;
|
|
716
|
+
}
|
|
717
|
+
clear() {
|
|
718
|
+
this.runtime?.releaseGraphicResources(this);
|
|
719
|
+
this.drawOperations = [{ type: 'clear' }];
|
|
720
|
+
this.paintStyles.clear();
|
|
721
|
+
this.bounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
722
|
+
return this.markDrawDirty();
|
|
723
|
+
}
|
|
724
|
+
rect(x, y, width, height) {
|
|
725
|
+
this.drawOperations.push({ type: 'rect', x, y, width, height });
|
|
726
|
+
this.includeBounds(x, y, width, height);
|
|
727
|
+
return this.markDrawDirty();
|
|
728
|
+
}
|
|
729
|
+
drawRect(x, y, width, height) {
|
|
730
|
+
this.rect(x, y, width, height);
|
|
731
|
+
if (this.lineStyleValue) {
|
|
732
|
+
this.stroke(this.lineStyleValue);
|
|
733
|
+
}
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
ellipse(x, y, radiusX, radiusY) {
|
|
737
|
+
this.drawOperations.push({ type: 'ellipse', x, y, radiusX, radiusY });
|
|
738
|
+
this.includeBounds(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2);
|
|
739
|
+
return this.markDrawDirty();
|
|
740
|
+
}
|
|
741
|
+
circle(x, y, radius) {
|
|
742
|
+
this.drawOperations.push({ type: 'circle', x, y, radius });
|
|
743
|
+
this.includeBounds(x - radius, y - radius, radius * 2, radius * 2);
|
|
744
|
+
return this.markDrawDirty();
|
|
745
|
+
}
|
|
746
|
+
poly(points, close = false) {
|
|
747
|
+
const ownedPoints = points.map(({ x, y }) => ({ x, y }));
|
|
748
|
+
this.drawOperations.push({ type: 'poly', points: ownedPoints, close });
|
|
749
|
+
ownedPoints.forEach(({ x, y }) => this.includePoint(x, y));
|
|
750
|
+
return this.markDrawDirty();
|
|
751
|
+
}
|
|
752
|
+
moveTo(x, y) {
|
|
753
|
+
this.drawOperations.push({ type: 'move-to', x, y });
|
|
754
|
+
this.includePoint(x, y);
|
|
755
|
+
return this.markDrawDirty();
|
|
756
|
+
}
|
|
757
|
+
lineTo(x, y) {
|
|
758
|
+
this.drawOperations.push({ type: 'line-to', x, y });
|
|
759
|
+
this.includePoint(x, y);
|
|
760
|
+
return this.markDrawDirty();
|
|
761
|
+
}
|
|
762
|
+
bezierCurveTo(controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, destinationX, destinationY) {
|
|
763
|
+
this.drawOperations.push({
|
|
764
|
+
type: 'bezier-curve-to',
|
|
765
|
+
controlPoint1: { x: controlPoint1X, y: controlPoint1Y },
|
|
766
|
+
controlPoint2: { x: controlPoint2X, y: controlPoint2Y },
|
|
767
|
+
destination: { x: destinationX, y: destinationY }
|
|
768
|
+
});
|
|
769
|
+
this.includePoint(controlPoint1X, controlPoint1Y);
|
|
770
|
+
this.includePoint(controlPoint2X, controlPoint2Y);
|
|
771
|
+
this.includePoint(destinationX, destinationY);
|
|
772
|
+
return this.markDrawDirty();
|
|
773
|
+
}
|
|
774
|
+
closePath() {
|
|
775
|
+
this.drawOperations.push({ type: 'close-path' });
|
|
776
|
+
return this.markDrawDirty();
|
|
777
|
+
}
|
|
778
|
+
fill(style) {
|
|
779
|
+
const operationIndex = this.drawOperations.length;
|
|
780
|
+
this.drawOperations.push({
|
|
781
|
+
type: 'fill',
|
|
782
|
+
paint: normalizePaint(style)
|
|
783
|
+
});
|
|
784
|
+
this.paintStyles.set(operationIndex, style);
|
|
785
|
+
return this.markDrawDirty();
|
|
786
|
+
}
|
|
787
|
+
stroke(style) {
|
|
788
|
+
const value = typeof style === 'object' && style !== null
|
|
789
|
+
? style
|
|
790
|
+
: {};
|
|
791
|
+
const width = typeof value.width === 'number' ? value.width : 1;
|
|
792
|
+
const operationIndex = this.drawOperations.length;
|
|
793
|
+
this.drawOperations.push({
|
|
794
|
+
type: 'stroke',
|
|
795
|
+
paint: normalizePaint(value),
|
|
796
|
+
width
|
|
797
|
+
});
|
|
798
|
+
this.paintStyles.set(operationIndex, value);
|
|
799
|
+
return this.markDrawDirty();
|
|
800
|
+
}
|
|
801
|
+
lineStyle(width, color, alpha = 1) {
|
|
802
|
+
this.lineStyleValue = { width, color, alpha };
|
|
803
|
+
return this;
|
|
804
|
+
}
|
|
805
|
+
getLocalBounds() {
|
|
806
|
+
return { ...this.bounds };
|
|
807
|
+
}
|
|
808
|
+
getDrawOperations() {
|
|
809
|
+
return this.drawOperations.map((operation, index) => {
|
|
810
|
+
if (!this.paintStyles.has(index)) {
|
|
811
|
+
return operation;
|
|
812
|
+
}
|
|
813
|
+
const style = this.paintStyles.get(index);
|
|
814
|
+
const paint = this.runtime?.createPaint(style, this) ?? normalizePaint(style);
|
|
815
|
+
if (operation.type === 'fill' || operation.type === 'stroke') {
|
|
816
|
+
return { ...operation, paint };
|
|
817
|
+
}
|
|
818
|
+
return operation;
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
isDrawDirty() {
|
|
822
|
+
return this.drawDirty;
|
|
823
|
+
}
|
|
824
|
+
markDrawClean() {
|
|
825
|
+
this.drawDirty = false;
|
|
826
|
+
}
|
|
827
|
+
destroy(options) {
|
|
828
|
+
this.runtime?.releaseGraphicResources(this);
|
|
829
|
+
super.destroy(options);
|
|
830
|
+
}
|
|
831
|
+
markDrawDirty() {
|
|
832
|
+
this.drawDirty = true;
|
|
833
|
+
this.runtime?.markDrawDirty(this);
|
|
834
|
+
return this;
|
|
835
|
+
}
|
|
836
|
+
includePoint(x, y) {
|
|
837
|
+
this.includeBounds(x, y, 0, 0);
|
|
838
|
+
}
|
|
839
|
+
includeBounds(x, y, width, height) {
|
|
840
|
+
if (this.bounds.width === 0 && this.bounds.height === 0) {
|
|
841
|
+
this.bounds = { x, y, width, height };
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const minX = Math.min(this.bounds.x, x);
|
|
845
|
+
const minY = Math.min(this.bounds.y, y);
|
|
846
|
+
const maxX = Math.max(this.bounds.x + this.bounds.width, x + width);
|
|
847
|
+
const maxY = Math.max(this.bounds.y + this.bounds.height, y + height);
|
|
848
|
+
this.bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
export class RenderMesh extends RenderContainer {
|
|
852
|
+
constructor(properties = {}) {
|
|
853
|
+
super(properties, 'mesh');
|
|
854
|
+
this.meshProperties = { ...properties };
|
|
855
|
+
}
|
|
856
|
+
getEngineProperties() {
|
|
857
|
+
return {
|
|
858
|
+
...super.getEngineProperties(),
|
|
859
|
+
...this.meshProperties
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
update(properties) {
|
|
863
|
+
this.meshProperties = {
|
|
864
|
+
...this.meshProperties,
|
|
865
|
+
...properties
|
|
866
|
+
};
|
|
867
|
+
this.updateEngineProperties(properties);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
//# sourceMappingURL=render-object.js.map
|