@solidtv/solid 1.0.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 +202 -0
- package/NOTICE +7 -0
- package/README.md +95 -0
- package/dist/jsx-runtime.d.ts +14 -0
- package/dist/src/activeElement.d.ts +2 -0
- package/dist/src/activeElement.js +3 -0
- package/dist/src/activeElement.js.map +1 -0
- package/dist/src/core/config.d.ts +51 -0
- package/dist/src/core/config.js +37 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
- package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
- package/dist/src/core/elementNode.d.ts +508 -0
- package/dist/src/core/elementNode.js +928 -0
- package/dist/src/core/elementNode.js.map +1 -0
- package/dist/src/core/flex.d.ts +2 -0
- package/dist/src/core/flex.js +284 -0
- package/dist/src/core/flex.js.map +1 -0
- package/dist/src/core/flexLayout.d.ts +2 -0
- package/dist/src/core/flexLayout.js +360 -0
- package/dist/src/core/flexLayout.js.map +1 -0
- package/dist/src/core/focusKeyTypes.d.ts +42 -0
- package/dist/src/core/focusKeyTypes.js +2 -0
- package/dist/src/core/focusKeyTypes.js.map +1 -0
- package/dist/src/core/focusManager.d.ts +13 -0
- package/dist/src/core/focusManager.js +270 -0
- package/dist/src/core/focusManager.js.map +1 -0
- package/dist/src/core/index.d.ts +14 -0
- package/dist/src/core/index.js +11 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/intrinsicTypes.d.ts +106 -0
- package/dist/src/core/intrinsicTypes.js +2 -0
- package/dist/src/core/intrinsicTypes.js.map +1 -0
- package/dist/src/core/lightningInit.d.ts +9 -0
- package/dist/src/core/lightningInit.js +34 -0
- package/dist/src/core/lightningInit.js.map +1 -0
- package/dist/src/core/nodeTypes.d.ts +6 -0
- package/dist/src/core/nodeTypes.js +6 -0
- package/dist/src/core/nodeTypes.js.map +1 -0
- package/dist/src/core/shaders.d.ts +52 -0
- package/dist/src/core/shaders.js +86 -0
- package/dist/src/core/shaders.js.map +1 -0
- package/dist/src/core/states.d.ts +12 -0
- package/dist/src/core/states.js +84 -0
- package/dist/src/core/states.js.map +1 -0
- package/dist/src/core/utils.d.ts +39 -0
- package/dist/src/core/utils.js +164 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/devtools/index.d.ts +6 -0
- package/dist/src/devtools/index.js +65 -0
- package/dist/src/devtools/index.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/primitives/Column.d.ts +3 -0
- package/dist/src/primitives/Column.jsx +25 -0
- package/dist/src/primitives/Column.jsx.map +1 -0
- package/dist/src/primitives/FPSCounter.d.ts +4 -0
- package/dist/src/primitives/FPSCounter.jsx +188 -0
- package/dist/src/primitives/FPSCounter.jsx.map +1 -0
- package/dist/src/primitives/FadeInOut.d.ts +18 -0
- package/dist/src/primitives/FadeInOut.jsx +39 -0
- package/dist/src/primitives/FadeInOut.jsx.map +1 -0
- package/dist/src/primitives/Grid.d.ts +23 -0
- package/dist/src/primitives/Grid.jsx +100 -0
- package/dist/src/primitives/Grid.jsx.map +1 -0
- package/dist/src/primitives/Image.d.ts +8 -0
- package/dist/src/primitives/Image.jsx +42 -0
- package/dist/src/primitives/Image.jsx.map +1 -0
- package/dist/src/primitives/KeepAlive.d.ts +42 -0
- package/dist/src/primitives/KeepAlive.jsx +160 -0
- package/dist/src/primitives/KeepAlive.jsx.map +1 -0
- package/dist/src/primitives/Lazy.d.ts +15 -0
- package/dist/src/primitives/Lazy.jsx +95 -0
- package/dist/src/primitives/Lazy.jsx.map +1 -0
- package/dist/src/primitives/LazyImport.d.ts +8 -0
- package/dist/src/primitives/LazyImport.js +40 -0
- package/dist/src/primitives/LazyImport.js.map +1 -0
- package/dist/src/primitives/Marquee.d.ts +64 -0
- package/dist/src/primitives/Marquee.jsx +86 -0
- package/dist/src/primitives/Marquee.jsx.map +1 -0
- package/dist/src/primitives/Preserve.d.ts +4 -0
- package/dist/src/primitives/Preserve.jsx +11 -0
- package/dist/src/primitives/Preserve.jsx.map +1 -0
- package/dist/src/primitives/Row.d.ts +3 -0
- package/dist/src/primitives/Row.jsx +24 -0
- package/dist/src/primitives/Row.jsx.map +1 -0
- package/dist/src/primitives/Suspense.d.ts +22 -0
- package/dist/src/primitives/Suspense.jsx +33 -0
- package/dist/src/primitives/Suspense.jsx.map +1 -0
- package/dist/src/primitives/Virtual.d.ts +18 -0
- package/dist/src/primitives/Virtual.jsx +495 -0
- package/dist/src/primitives/Virtual.jsx.map +1 -0
- package/dist/src/primitives/VirtualGrid.d.ts +13 -0
- package/dist/src/primitives/VirtualGrid.jsx +160 -0
- package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
- package/dist/src/primitives/Visible.d.ts +6 -0
- package/dist/src/primitives/Visible.jsx +37 -0
- package/dist/src/primitives/Visible.jsx.map +1 -0
- package/dist/src/primitives/announcer/announcer.d.ts +40 -0
- package/dist/src/primitives/announcer/announcer.js +125 -0
- package/dist/src/primitives/announcer/announcer.js.map +1 -0
- package/dist/src/primitives/announcer/index.d.ts +6 -0
- package/dist/src/primitives/announcer/index.js +15 -0
- package/dist/src/primitives/announcer/index.js.map +1 -0
- package/dist/src/primitives/announcer/speech.d.ts +10 -0
- package/dist/src/primitives/announcer/speech.js +281 -0
- package/dist/src/primitives/announcer/speech.js.map +1 -0
- package/dist/src/primitives/borderBox.d.ts +8 -0
- package/dist/src/primitives/borderBox.jsx +47 -0
- package/dist/src/primitives/borderBox.jsx.map +1 -0
- package/dist/src/primitives/createFocusStack.d.ts +31 -0
- package/dist/src/primitives/createFocusStack.jsx +62 -0
- package/dist/src/primitives/createFocusStack.jsx.map +1 -0
- package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
- package/dist/src/primitives/createInfiniteItems.js +46 -0
- package/dist/src/primitives/createInfiniteItems.js.map +1 -0
- package/dist/src/primitives/createTag.d.ts +8 -0
- package/dist/src/primitives/createTag.jsx +20 -0
- package/dist/src/primitives/createTag.jsx.map +1 -0
- package/dist/src/primitives/index.d.ts +32 -0
- package/dist/src/primitives/index.js +31 -0
- package/dist/src/primitives/index.js.map +1 -0
- package/dist/src/primitives/portal.d.ts +5 -0
- package/dist/src/primitives/portal.jsx +21 -0
- package/dist/src/primitives/portal.jsx.map +1 -0
- package/dist/src/primitives/router.d.ts +20 -0
- package/dist/src/primitives/router.js +90 -0
- package/dist/src/primitives/router.js.map +1 -0
- package/dist/src/primitives/types.d.ts +79 -0
- package/dist/src/primitives/types.js +2 -0
- package/dist/src/primitives/types.js.map +1 -0
- package/dist/src/primitives/useFocusManager.d.ts +5 -0
- package/dist/src/primitives/useFocusManager.js +21 -0
- package/dist/src/primitives/useFocusManager.js.map +1 -0
- package/dist/src/primitives/useHold.d.ts +27 -0
- package/dist/src/primitives/useHold.js +54 -0
- package/dist/src/primitives/useHold.js.map +1 -0
- package/dist/src/primitives/useMouse.d.ts +18 -0
- package/dist/src/primitives/useMouse.js +240 -0
- package/dist/src/primitives/useMouse.js.map +1 -0
- package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
- package/dist/src/primitives/utils/chainFunctions.js +32 -0
- package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
- package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
- package/dist/src/primitives/utils/createBlurredImage.js +223 -0
- package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
- package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
- package/dist/src/primitives/utils/createSpriteMap.js +18 -0
- package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
- package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
- package/dist/src/primitives/utils/handleNavigation.js +300 -0
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
- package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
- package/dist/src/primitives/utils/withScrolling.js +186 -0
- package/dist/src/primitives/utils/withScrolling.js.map +1 -0
- package/dist/src/render.d.ts +28 -0
- package/dist/src/render.js +107 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/solidOpts.d.ts +15 -0
- package/dist/src/solidOpts.js +93 -0
- package/dist/src/solidOpts.js.map +1 -0
- package/dist/src/types.d.ts +11 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +19 -0
- package/dist/src/utils.js +94 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/AI_CODING_GUIDELINES.md +108 -0
- package/docs/README.md +35 -0
- package/jsx-runtime.d.ts +14 -0
- package/package.json +125 -0
- package/src/activeElement.ts +5 -0
- package/src/core/config.ts +101 -0
- package/src/core/dom-renderer/domRenderer.ts +2066 -0
- package/src/core/dom-renderer/domRendererTypes.ts +148 -0
- package/src/core/dom-renderer/domRendererUtils.ts +292 -0
- package/src/core/elementNode.ts +1623 -0
- package/src/core/flex.ts +331 -0
- package/src/core/flexLayout.ts +414 -0
- package/src/core/focusKeyTypes.ts +90 -0
- package/src/core/focusManager.ts +374 -0
- package/src/core/index.ts +15 -0
- package/src/core/intrinsicTypes.ts +216 -0
- package/src/core/lightningInit.ts +45 -0
- package/src/core/nodeTypes.ts +6 -0
- package/src/core/shaders.ts +187 -0
- package/src/core/states.ts +91 -0
- package/src/core/utils.ts +222 -0
- package/src/devtools/index.ts +77 -0
- package/src/index.ts +18 -0
- package/src/primitives/Column.tsx +59 -0
- package/src/primitives/FPSCounter.tsx +209 -0
- package/src/primitives/FadeInOut.tsx +58 -0
- package/src/primitives/Grid.tsx +151 -0
- package/src/primitives/Image.tsx +56 -0
- package/src/primitives/KeepAlive.tsx +268 -0
- package/src/primitives/Lazy.tsx +128 -0
- package/src/primitives/LazyImport.ts +53 -0
- package/src/primitives/Marquee.tsx +149 -0
- package/src/primitives/Preserve.tsx +18 -0
- package/src/primitives/Row.tsx +58 -0
- package/src/primitives/Suspense.tsx +39 -0
- package/src/primitives/Virtual.tsx +602 -0
- package/src/primitives/VirtualGrid.tsx +220 -0
- package/src/primitives/Visible.tsx +59 -0
- package/src/primitives/announcer/announcer.ts +198 -0
- package/src/primitives/announcer/index.ts +20 -0
- package/src/primitives/announcer/speech.ts +334 -0
- package/src/primitives/borderBox.tsx +69 -0
- package/src/primitives/createFocusStack.tsx +79 -0
- package/src/primitives/createInfiniteItems.ts +66 -0
- package/src/primitives/createTag.tsx +33 -0
- package/src/primitives/index.ts +37 -0
- package/src/primitives/portal.tsx +25 -0
- package/src/primitives/router.ts +147 -0
- package/src/primitives/types.ts +109 -0
- package/src/primitives/useFocusManager.ts +47 -0
- package/src/primitives/useHold.ts +69 -0
- package/src/primitives/useMouse.ts +417 -0
- package/src/primitives/utils/chainFunctions.ts +60 -0
- package/src/primitives/utils/createBlurredImage.ts +366 -0
- package/src/primitives/utils/createSpriteMap.ts +32 -0
- package/src/primitives/utils/handleNavigation.ts +373 -0
- package/src/primitives/utils/withScrolling.ts +238 -0
- package/src/render.ts +164 -0
- package/src/solidOpts.ts +107 -0
- package/src/types.ts +22 -0
- package/src/utils.ts +129 -0
|
@@ -0,0 +1,1844 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Experimental DOM renderer
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
import * as lng from '@solidtv/renderer';
|
|
7
|
+
import { EventEmitter } from '@solidtv/renderer/utils';
|
|
8
|
+
import { Config } from '../config.js';
|
|
9
|
+
import { applyEasing, applySubTextureScaling, buildGradientStops, colorToRgba, compactString, computeLegacyObjectFit, computeRenderStateForNode, getNodeLineHeight, interpolateProp, isRenderStateInBounds, nodeHasTextureSource, } from './domRendererUtils.js';
|
|
10
|
+
// Feature detection for legacy brousers
|
|
11
|
+
const _styleRef = typeof document !== 'undefined' ? document.documentElement?.style || {} : {};
|
|
12
|
+
const supportsObjectFit = 'objectFit' in _styleRef;
|
|
13
|
+
const supportsObjectPosition = 'objectPosition' in _styleRef;
|
|
14
|
+
const supportsMixBlendMode = 'mixBlendMode' in _styleRef;
|
|
15
|
+
const supportsStandardMask = 'maskImage' in _styleRef;
|
|
16
|
+
const supportsWebkitMask = 'webkitMaskImage' in _styleRef;
|
|
17
|
+
const supportsCssMask = supportsStandardMask || supportsWebkitMask;
|
|
18
|
+
/*
|
|
19
|
+
Animations
|
|
20
|
+
*/
|
|
21
|
+
let animationTasks = [];
|
|
22
|
+
let animationFrameRequested = false;
|
|
23
|
+
function requestAnimationUpdate() {
|
|
24
|
+
if (!animationFrameRequested && animationTasks.length > 0) {
|
|
25
|
+
animationFrameRequested = true;
|
|
26
|
+
requestAnimationFrame(updateAnimations);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function updateAnimations(time) {
|
|
30
|
+
animationFrameRequested = false;
|
|
31
|
+
/*
|
|
32
|
+
tasks are iterated in insertion order
|
|
33
|
+
so that the later task will override the earlier ones
|
|
34
|
+
*/
|
|
35
|
+
for (let i = 0; i < animationTasks.length; i++) {
|
|
36
|
+
let task = animationTasks[i];
|
|
37
|
+
if (task.pausedTime != null)
|
|
38
|
+
continue;
|
|
39
|
+
let elapsed = time - task.timeStart;
|
|
40
|
+
// Still in delay period
|
|
41
|
+
if (elapsed < task.settings.delay) {
|
|
42
|
+
requestAnimationUpdate();
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
let activeTime = elapsed - task.settings.delay;
|
|
46
|
+
if (activeTime >= task.settings.duration) {
|
|
47
|
+
// Start next iteration
|
|
48
|
+
if (task.settings.loop || task.iteration < task.settings.repeat - 1) {
|
|
49
|
+
task.iteration++;
|
|
50
|
+
task.timeStart = time - task.settings.delay;
|
|
51
|
+
requestAnimationUpdate();
|
|
52
|
+
}
|
|
53
|
+
// Animation complete
|
|
54
|
+
else {
|
|
55
|
+
Object.assign(task.node.props, task.propsEnd);
|
|
56
|
+
task.node.boundsDirty = true;
|
|
57
|
+
task.node.markChildrenBoundsDirty();
|
|
58
|
+
updateNodeStyles(task.node);
|
|
59
|
+
task.stop();
|
|
60
|
+
i--;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
/*
|
|
65
|
+
Update props and styles
|
|
66
|
+
*/
|
|
67
|
+
let t = activeTime / task.settings.duration;
|
|
68
|
+
t = applyEasing(task.settings.easing, t);
|
|
69
|
+
for (let prop in task.propsEnd) {
|
|
70
|
+
let start = task.propsStart[prop];
|
|
71
|
+
let end = task.propsEnd[prop];
|
|
72
|
+
task.node.props[prop] = interpolateProp(prop, start, end, t);
|
|
73
|
+
}
|
|
74
|
+
updateNodeStyles(task.node);
|
|
75
|
+
}
|
|
76
|
+
requestAnimationUpdate();
|
|
77
|
+
}
|
|
78
|
+
class AnimationController {
|
|
79
|
+
node;
|
|
80
|
+
state = 'paused';
|
|
81
|
+
stopPromise = null;
|
|
82
|
+
stopResolve = null;
|
|
83
|
+
propsStart = {};
|
|
84
|
+
propsEnd = {};
|
|
85
|
+
timeStart = performance.now();
|
|
86
|
+
timeEnd;
|
|
87
|
+
settings;
|
|
88
|
+
iteration = 0;
|
|
89
|
+
pausedTime = null;
|
|
90
|
+
constructor(node, props, rawSettings) {
|
|
91
|
+
this.node = node;
|
|
92
|
+
this.settings = {
|
|
93
|
+
duration: rawSettings.duration ?? 300,
|
|
94
|
+
delay: rawSettings.delay ?? 0,
|
|
95
|
+
easing: rawSettings.easing ?? 'linear',
|
|
96
|
+
loop: rawSettings.loop ?? false,
|
|
97
|
+
repeat: rawSettings.repeat ?? 1,
|
|
98
|
+
stopMethod: false,
|
|
99
|
+
};
|
|
100
|
+
this.timeEnd =
|
|
101
|
+
this.timeStart + this.settings.delay + this.settings.duration;
|
|
102
|
+
for (let [prop, value] of Object.entries(props)) {
|
|
103
|
+
if (value != null && typeof value === 'number') {
|
|
104
|
+
this.propsStart[prop] = node.props[prop];
|
|
105
|
+
this.propsEnd[prop] = value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
animationTasks.push(this);
|
|
109
|
+
}
|
|
110
|
+
start() {
|
|
111
|
+
if (this.pausedTime != null) {
|
|
112
|
+
this.timeStart += performance.now() - this.pausedTime;
|
|
113
|
+
this.pausedTime = null;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.timeStart = performance.now();
|
|
117
|
+
}
|
|
118
|
+
this.state = 'running';
|
|
119
|
+
requestAnimationUpdate();
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
pause() {
|
|
123
|
+
this.pausedTime = performance.now();
|
|
124
|
+
this.state = 'paused';
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
stop() {
|
|
128
|
+
let index = animationTasks.indexOf(this);
|
|
129
|
+
if (index !== -1) {
|
|
130
|
+
animationTasks.splice(index, 1);
|
|
131
|
+
}
|
|
132
|
+
this.state = 'stopped';
|
|
133
|
+
if (this.stopResolve) {
|
|
134
|
+
this.stopResolve();
|
|
135
|
+
this.stopResolve = null;
|
|
136
|
+
this.stopPromise = null;
|
|
137
|
+
}
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
restore() {
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
waitUntilStopped() {
|
|
144
|
+
this.stopPromise ??= new Promise((resolve) => {
|
|
145
|
+
this.stopResolve = resolve;
|
|
146
|
+
});
|
|
147
|
+
return this.stopPromise;
|
|
148
|
+
}
|
|
149
|
+
on() {
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
once() {
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
off() {
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
emit() {
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function animate(props, settings) {
|
|
163
|
+
return new AnimationController(this, props, settings);
|
|
164
|
+
}
|
|
165
|
+
/*
|
|
166
|
+
Node Properties
|
|
167
|
+
*/
|
|
168
|
+
let elMap = new WeakMap();
|
|
169
|
+
function updateNodeParent(node) {
|
|
170
|
+
const parent = node.props.parent;
|
|
171
|
+
if (parent instanceof DOMNode) {
|
|
172
|
+
elMap.get(parent).appendChild(node.div);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function updateNodeStyles(node) {
|
|
176
|
+
let { props } = node;
|
|
177
|
+
let style = `position: absolute; z-index: ${props.zIndex}; opacity: ${props.alpha ?? 1};`;
|
|
178
|
+
if (props.clipping) {
|
|
179
|
+
style += `overflow: hidden;`;
|
|
180
|
+
}
|
|
181
|
+
// Transform
|
|
182
|
+
{
|
|
183
|
+
let transform = '';
|
|
184
|
+
let { x, y } = props;
|
|
185
|
+
const hasMountX = props.mountX != null && props.mountX !== 0;
|
|
186
|
+
const hasMountY = props.mountY != null && props.mountY !== 0;
|
|
187
|
+
if (x !== 0)
|
|
188
|
+
transform += `translateX(${x}px)`;
|
|
189
|
+
if (hasMountX)
|
|
190
|
+
transform += `translateX(${-props.mountX * 100}%)`;
|
|
191
|
+
if (y !== 0)
|
|
192
|
+
transform += `translateY(${y}px)`;
|
|
193
|
+
if (hasMountY)
|
|
194
|
+
transform += `translateY(${-props.mountY * 100}%)`;
|
|
195
|
+
if (props.rotation !== 0)
|
|
196
|
+
transform += `rotate(${props.rotation}rad)`;
|
|
197
|
+
if (props.scale !== 1 && props.scale != null) {
|
|
198
|
+
transform += `scale(${props.scale})`;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
if (props.scaleX !== 1)
|
|
202
|
+
transform += `scaleX(${props.scaleX})`;
|
|
203
|
+
if (props.scaleY !== 1)
|
|
204
|
+
transform += `scaleY(${props.scaleY})`;
|
|
205
|
+
}
|
|
206
|
+
if (transform.length > 0) {
|
|
207
|
+
style += `transform: ${transform};`;
|
|
208
|
+
}
|
|
209
|
+
let pivotX = props.pivotX ?? props.pivot ?? 0.5;
|
|
210
|
+
let pivotY = props.pivotY ?? props.pivot ?? 0.5;
|
|
211
|
+
if (pivotX !== 0.5 || pivotY !== 0.5) {
|
|
212
|
+
style += `transform-origin: ${pivotX * 100}% ${pivotY * 100}%;`;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// <Text>
|
|
216
|
+
if (node instanceof DOMText) {
|
|
217
|
+
let textProps = node.props;
|
|
218
|
+
if (textProps.color != null && textProps.color !== 0) {
|
|
219
|
+
style += `color: ${colorToRgba(textProps.color)};`;
|
|
220
|
+
}
|
|
221
|
+
if (textProps.fontFamily) {
|
|
222
|
+
style += `font-family: ${textProps.fontFamily};`;
|
|
223
|
+
}
|
|
224
|
+
if (textProps.fontSize) {
|
|
225
|
+
style += `font-size: ${textProps.fontSize}px;`;
|
|
226
|
+
}
|
|
227
|
+
if (textProps.fontStyle !== 'normal') {
|
|
228
|
+
style += `font-style: ${textProps.fontStyle};`;
|
|
229
|
+
}
|
|
230
|
+
if (textProps.fontWeight !== 'normal') {
|
|
231
|
+
style += `font-weight: ${textProps.fontWeight};`;
|
|
232
|
+
}
|
|
233
|
+
if (textProps.fontStretch && textProps.fontStretch !== 'normal') {
|
|
234
|
+
style += `font-stretch: ${textProps.fontStretch};`;
|
|
235
|
+
}
|
|
236
|
+
if (textProps.lineHeight) {
|
|
237
|
+
style += `line-height: ${textProps.lineHeight}px;`;
|
|
238
|
+
}
|
|
239
|
+
if (textProps.letterSpacing) {
|
|
240
|
+
style += `letter-spacing: ${textProps.letterSpacing}px;`;
|
|
241
|
+
}
|
|
242
|
+
if (textProps.textAlign !== 'left') {
|
|
243
|
+
style += `text-align: ${textProps.textAlign};`;
|
|
244
|
+
}
|
|
245
|
+
let maxLines = textProps.maxLines || Infinity;
|
|
246
|
+
switch (textProps.contain) {
|
|
247
|
+
case 'width':
|
|
248
|
+
if (textProps.maxWidth && textProps.maxWidth > 0) {
|
|
249
|
+
if (node.textAlign === 'center') {
|
|
250
|
+
style += `width: ${textProps.maxWidth}px;`;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
style += `max-width: ${textProps.maxWidth}px;`;
|
|
254
|
+
}
|
|
255
|
+
style += `overflow: hidden;`;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
style += `width: 100%;`;
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
case 'both': {
|
|
262
|
+
let lineHeight = getNodeLineHeight(textProps);
|
|
263
|
+
const widthConstraint = textProps.maxWidth && textProps.maxWidth > 0
|
|
264
|
+
? `${textProps.maxWidth}px`
|
|
265
|
+
: `100%`;
|
|
266
|
+
const heightConstraint = textProps.maxHeight && textProps.maxHeight > 0
|
|
267
|
+
? textProps.maxHeight
|
|
268
|
+
: props.h;
|
|
269
|
+
let height = heightConstraint || 0;
|
|
270
|
+
if (height > 0) {
|
|
271
|
+
const maxLinesByHeight = Math.max(1, Math.floor(height / lineHeight));
|
|
272
|
+
maxLines = Math.min(maxLines, maxLinesByHeight);
|
|
273
|
+
height = Math.max(lineHeight, maxLines * lineHeight);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
maxLines = Number.isFinite(maxLines) ? Math.max(1, maxLines) : 1;
|
|
277
|
+
height = maxLines * lineHeight;
|
|
278
|
+
}
|
|
279
|
+
style += `width: ${widthConstraint}; height: ${height}px; overflow: hidden;`;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case 'none':
|
|
283
|
+
style += `width: -webkit-max-content;`;
|
|
284
|
+
style += `width: max-content;`;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
style += `white-space: pre-wrap;`;
|
|
288
|
+
if (maxLines !== Infinity) {
|
|
289
|
+
// https://stackoverflow.com/a/13924997
|
|
290
|
+
style += `display: -webkit-box;
|
|
291
|
+
overflow: hidden;
|
|
292
|
+
-webkit-line-clamp: ${maxLines};
|
|
293
|
+
line-clamp: ${maxLines};
|
|
294
|
+
-webkit-box-orient: vertical;`;
|
|
295
|
+
}
|
|
296
|
+
if (textProps.offsetY != null && textProps.offsetY !== 0) {
|
|
297
|
+
style += `margin-top: ${textProps.offsetY}px;`;
|
|
298
|
+
}
|
|
299
|
+
if (textProps.wordBreak) {
|
|
300
|
+
const wb = textProps.wordBreak;
|
|
301
|
+
if (wb !== 'normal') {
|
|
302
|
+
if (wb === 'break-all') {
|
|
303
|
+
style += `word-break: break-all;`;
|
|
304
|
+
}
|
|
305
|
+
else if (wb === 'keep-all') {
|
|
306
|
+
style += `word-break: keep-all;`;
|
|
307
|
+
}
|
|
308
|
+
else if (wb === 'break-word') {
|
|
309
|
+
style += `word-wrap: break-word; overflow-wrap: break-word;`;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
style += `overflow-wrap: break-word;`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// if (node.overflowSuffix) style += `overflow-suffix: ${node.overflowSuffix};`
|
|
317
|
+
// if (node.verticalAlign) style += `vertical-align: ${node.verticalAlign};`
|
|
318
|
+
}
|
|
319
|
+
// <Node>
|
|
320
|
+
else {
|
|
321
|
+
if (props.w !== 0)
|
|
322
|
+
style += `width: ${props.w < 0 ? 0 : props.w}px;`;
|
|
323
|
+
if (props.h !== 0)
|
|
324
|
+
style += `height: ${props.h}px;`;
|
|
325
|
+
let vGradient = props.colorBottom !== props.colorTop
|
|
326
|
+
? `linear-gradient(to bottom, ${colorToRgba(props.colorTop)}, ${colorToRgba(props.colorBottom)})`
|
|
327
|
+
: null;
|
|
328
|
+
let hGradient = props.colorLeft !== props.colorRight
|
|
329
|
+
? `linear-gradient(to right, ${colorToRgba(props.colorLeft)}, ${colorToRgba(props.colorRight)})`
|
|
330
|
+
: null;
|
|
331
|
+
let gradient = vGradient && hGradient
|
|
332
|
+
? `${vGradient}, ${hGradient}`
|
|
333
|
+
: vGradient || hGradient;
|
|
334
|
+
let srcImg = null;
|
|
335
|
+
let srcPos = null;
|
|
336
|
+
let rawImgSrc = null;
|
|
337
|
+
if (props.texture != null &&
|
|
338
|
+
props.texture.type === lng.TextureType.subTexture) {
|
|
339
|
+
const texture = props.texture;
|
|
340
|
+
srcPos = texture.props;
|
|
341
|
+
rawImgSrc = texture.props.texture.props.src;
|
|
342
|
+
}
|
|
343
|
+
else if (props.src) {
|
|
344
|
+
rawImgSrc = props.src;
|
|
345
|
+
}
|
|
346
|
+
if (rawImgSrc) {
|
|
347
|
+
srcImg = `url(${rawImgSrc})`;
|
|
348
|
+
}
|
|
349
|
+
let bgStyle = '';
|
|
350
|
+
let borderStyle = '';
|
|
351
|
+
let radiusStyle = '';
|
|
352
|
+
let maskStyle = '';
|
|
353
|
+
let needsBackgroundLayer = false;
|
|
354
|
+
let imgStyle = '';
|
|
355
|
+
let hasDivBgTint = false;
|
|
356
|
+
if (rawImgSrc) {
|
|
357
|
+
needsBackgroundLayer = true;
|
|
358
|
+
const hasTint = props.color !== 0xffffffff && props.color !== 0x00000000;
|
|
359
|
+
if (hasTint) {
|
|
360
|
+
bgStyle += `background-color: ${colorToRgba(props.color)};`;
|
|
361
|
+
if (srcImg) {
|
|
362
|
+
maskStyle += `mask-image: ${srcImg};`;
|
|
363
|
+
if (srcPos !== null) {
|
|
364
|
+
maskStyle += `mask-position: -${srcPos.x}px -${srcPos.y}px;`;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
maskStyle += `mask-size: 100% 100%;`;
|
|
368
|
+
}
|
|
369
|
+
hasDivBgTint = true;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else if (gradient) {
|
|
373
|
+
// use gradient as a mask when no tint is applied
|
|
374
|
+
maskStyle += `mask-image: ${gradient};`;
|
|
375
|
+
}
|
|
376
|
+
const imgStyleParts = [
|
|
377
|
+
'position: absolute',
|
|
378
|
+
'top: 0',
|
|
379
|
+
'left: 0',
|
|
380
|
+
'right: 0',
|
|
381
|
+
'bottom: 0',
|
|
382
|
+
'display: block',
|
|
383
|
+
'pointer-events: none',
|
|
384
|
+
];
|
|
385
|
+
if (props.textureOptions.resizeMode?.type) {
|
|
386
|
+
const resizeMode = props.textureOptions.resizeMode;
|
|
387
|
+
imgStyleParts.push('width: 100%');
|
|
388
|
+
imgStyleParts.push('height: 100%');
|
|
389
|
+
imgStyleParts.push(`object-fit: ${resizeMode.type}`);
|
|
390
|
+
// Handle clipX and clipY for object-position
|
|
391
|
+
const clipX = resizeMode.clipX ?? 0.5;
|
|
392
|
+
const clipY = resizeMode.clipY ?? 0.5;
|
|
393
|
+
imgStyleParts.push(`object-position: ${clipX * 100}% ${clipY * 100}%`);
|
|
394
|
+
}
|
|
395
|
+
else if (srcPos !== null) {
|
|
396
|
+
imgStyleParts.push('width: auto');
|
|
397
|
+
imgStyleParts.push('height: auto');
|
|
398
|
+
imgStyleParts.push('object-fit: none');
|
|
399
|
+
imgStyleParts.push(`object-position: -${srcPos.x}px -${srcPos.y}px`);
|
|
400
|
+
}
|
|
401
|
+
else if (props.w && !props.h) {
|
|
402
|
+
imgStyleParts.push('width: 100%');
|
|
403
|
+
imgStyleParts.push('height: auto');
|
|
404
|
+
}
|
|
405
|
+
else if (props.h && !props.w) {
|
|
406
|
+
imgStyleParts.push('width: auto');
|
|
407
|
+
imgStyleParts.push('height: 100%');
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
imgStyleParts.push('width: 100%');
|
|
411
|
+
imgStyleParts.push('height: 100%');
|
|
412
|
+
imgStyleParts.push('object-fit: fill');
|
|
413
|
+
}
|
|
414
|
+
if (hasTint) {
|
|
415
|
+
if (supportsMixBlendMode) {
|
|
416
|
+
imgStyleParts.push('mix-blend-mode: multiply');
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
imgStyleParts.push('opacity: 0.9');
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
imgStyle = imgStyleParts.join('; ') + ';';
|
|
423
|
+
}
|
|
424
|
+
else if (gradient) {
|
|
425
|
+
bgStyle += `background-image: ${gradient};`;
|
|
426
|
+
bgStyle += `background-repeat: no-repeat;`;
|
|
427
|
+
bgStyle += `background-size: 100% 100%;`;
|
|
428
|
+
}
|
|
429
|
+
else if (props.color !== 0) {
|
|
430
|
+
bgStyle += `background-color: ${colorToRgba(props.color)};`;
|
|
431
|
+
}
|
|
432
|
+
if (props.shader?.props != null) {
|
|
433
|
+
let shaderProps = props.shader.props;
|
|
434
|
+
let borderWidth = shaderProps['border-w'];
|
|
435
|
+
let borderColor = shaderProps['border-color'];
|
|
436
|
+
let borderGap = shaderProps['border-gap'] ?? 0;
|
|
437
|
+
let borderAlign = shaderProps['border-align'] ?? 'inside';
|
|
438
|
+
let radius = shaderProps['radius'];
|
|
439
|
+
// Border
|
|
440
|
+
const borderWidthIsNumber = typeof borderWidth === 'number';
|
|
441
|
+
const borderWidthIsArray = Array.isArray(borderWidth);
|
|
442
|
+
const borderWidthHasValue = (borderWidthIsNumber && borderWidth !== 0) ||
|
|
443
|
+
(borderWidthIsArray &&
|
|
444
|
+
borderWidth.some((w) => typeof w === 'number' && w !== 0));
|
|
445
|
+
if (borderWidthHasValue &&
|
|
446
|
+
typeof borderColor === 'number' &&
|
|
447
|
+
borderColor !== 0) {
|
|
448
|
+
const rgbaColor = colorToRgba(borderColor);
|
|
449
|
+
if (borderWidthIsNumber) {
|
|
450
|
+
let insideWidth = 0;
|
|
451
|
+
let outsideWidth = 0;
|
|
452
|
+
if (borderAlign === 'inside') {
|
|
453
|
+
insideWidth = borderWidth;
|
|
454
|
+
}
|
|
455
|
+
else if (borderAlign === 'center') {
|
|
456
|
+
insideWidth = borderWidth / 2;
|
|
457
|
+
outsideWidth = borderWidth / 2;
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
outsideWidth = borderWidth;
|
|
461
|
+
}
|
|
462
|
+
outsideWidth += borderGap;
|
|
463
|
+
insideWidth -= borderGap;
|
|
464
|
+
if (insideWidth < 0) {
|
|
465
|
+
outsideWidth += insideWidth;
|
|
466
|
+
insideWidth = 0;
|
|
467
|
+
}
|
|
468
|
+
if (outsideWidth < 0) {
|
|
469
|
+
insideWidth += outsideWidth;
|
|
470
|
+
outsideWidth = 0;
|
|
471
|
+
}
|
|
472
|
+
const shadows = [];
|
|
473
|
+
if (outsideWidth > 0) {
|
|
474
|
+
shadows.push(`0 0 0 ${outsideWidth}px ${rgbaColor}`);
|
|
475
|
+
}
|
|
476
|
+
if (insideWidth > 0) {
|
|
477
|
+
shadows.push(`inset 0 0 0 ${insideWidth}px ${rgbaColor}`);
|
|
478
|
+
}
|
|
479
|
+
if (shadows.length > 0) {
|
|
480
|
+
borderStyle += `box-shadow: ${shadows.join(', ')};`;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else if (borderWidthIsArray) {
|
|
484
|
+
// Individual borders per side [top, right, bottom, left]
|
|
485
|
+
// Allow individual properties to override array values
|
|
486
|
+
const topWidth = shaderProps['border-top'] ?? borderWidth[0];
|
|
487
|
+
const rightWidth = shaderProps['border-right'] ?? borderWidth[1];
|
|
488
|
+
const bottomWidth = shaderProps['border-bottom'] ?? borderWidth[2];
|
|
489
|
+
const leftWidth = shaderProps['border-left'] ?? borderWidth[3];
|
|
490
|
+
const widths = [topWidth, rightWidth, bottomWidth, leftWidth];
|
|
491
|
+
const sides = ['top', 'right', 'bottom', 'left'];
|
|
492
|
+
for (let i = 0; i < sides.length; i++) {
|
|
493
|
+
const width = widths[i];
|
|
494
|
+
if (typeof width === 'number' && width !== 0) {
|
|
495
|
+
borderStyle += `border-${sides[i]}: ${width}px solid ${rgbaColor};`;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// Rounded
|
|
501
|
+
if (typeof radius === 'number' && radius > 0) {
|
|
502
|
+
radiusStyle += `border-radius: ${radius}px;`;
|
|
503
|
+
}
|
|
504
|
+
else if (Array.isArray(radius) && radius.length === 4) {
|
|
505
|
+
radiusStyle += `border-radius: ${radius[0]}px ${radius[1]}px ${radius[2]}px ${radius[3]}px;`;
|
|
506
|
+
}
|
|
507
|
+
if ('radial' in shaderProps) {
|
|
508
|
+
const rg = shaderProps.radial;
|
|
509
|
+
const colors = Array.isArray(rg?.colors) ? rg.colors : [];
|
|
510
|
+
const stops = Array.isArray(rg?.stops) ? rg.stops : undefined;
|
|
511
|
+
const pivot = Array.isArray(rg?.pivot) ? rg.pivot : [0.5, 0.5];
|
|
512
|
+
const width = typeof rg?.w === 'number' ? rg.w : props.w || 0;
|
|
513
|
+
const height = typeof rg?.h === 'number' ? rg.h : width;
|
|
514
|
+
if (colors.length > 0) {
|
|
515
|
+
const gradientStops = buildGradientStops(colors, stops);
|
|
516
|
+
if (gradientStops) {
|
|
517
|
+
if (colors.length === 1) {
|
|
518
|
+
// Single color -> solid fill
|
|
519
|
+
if (srcImg || gradient) {
|
|
520
|
+
maskStyle += `mask-image: linear-gradient(${gradientStops});`;
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
bgStyle += `background-color: ${colorToRgba(colors[0])};`;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const isEllipse = width > 0 && height > 0 && width !== height;
|
|
528
|
+
const pivotX = (pivot[0] ?? 0.5) * 100;
|
|
529
|
+
const pivotY = (pivot[1] ?? 0.5) * 100;
|
|
530
|
+
let sizePart = '';
|
|
531
|
+
if (width > 0 && height > 0) {
|
|
532
|
+
if (!isEllipse && width === height) {
|
|
533
|
+
sizePart = `${Math.round(width)}px`;
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
sizePart = `${Math.round(width)}px ${Math.round(height)}px`;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
sizePart = 'closest-side';
|
|
541
|
+
}
|
|
542
|
+
const radialGradient = `radial-gradient(${isEllipse ? 'ellipse' : 'circle'} ${sizePart} at ${pivotX.toFixed(2)}% ${pivotY.toFixed(2)}%, ${gradientStops})`;
|
|
543
|
+
if (srcImg || gradient) {
|
|
544
|
+
maskStyle += `mask-image: ${radialGradient};`;
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
bgStyle += `background-image: ${radialGradient};`;
|
|
548
|
+
bgStyle += `background-repeat: no-repeat;`;
|
|
549
|
+
bgStyle += `background-size: 100% 100%;`;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if ('linear' in shaderProps) {
|
|
556
|
+
const lg = shaderProps.linear;
|
|
557
|
+
const colors = Array.isArray(lg?.colors) ? lg.colors : [];
|
|
558
|
+
const stops = Array.isArray(lg?.stops) ? lg.stops : undefined;
|
|
559
|
+
const angleRad = typeof lg?.angle === 'number' ? lg.angle : 0; // radians
|
|
560
|
+
if (colors.length > 0) {
|
|
561
|
+
const gradientStops = buildGradientStops(colors, stops);
|
|
562
|
+
if (gradientStops) {
|
|
563
|
+
if (colors.length === 1) {
|
|
564
|
+
if (srcImg || gradient) {
|
|
565
|
+
maskStyle += `mask-image: linear-gradient(${gradientStops});`;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
bgStyle += `background-color: ${colorToRgba(colors[0])};`;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
const angleDeg = 180 * (angleRad / Math.PI - 1);
|
|
573
|
+
const linearGradient = `linear-gradient(${angleDeg.toFixed(2)}deg, ${gradientStops})`;
|
|
574
|
+
if (srcImg || gradient) {
|
|
575
|
+
maskStyle += `mask-image: ${linearGradient};`;
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
bgStyle += `background-image: ${linearGradient};`;
|
|
579
|
+
bgStyle += `background-repeat: no-repeat;`;
|
|
580
|
+
bgStyle += `background-size: 100% 100%;`;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (maskStyle !== '') {
|
|
588
|
+
if (!supportsStandardMask && supportsWebkitMask) {
|
|
589
|
+
maskStyle = maskStyle.replace(/mask-/g, '-webkit-mask-');
|
|
590
|
+
}
|
|
591
|
+
else if (!supportsCssMask) {
|
|
592
|
+
maskStyle = '';
|
|
593
|
+
}
|
|
594
|
+
if (maskStyle !== '') {
|
|
595
|
+
needsBackgroundLayer = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
style += radiusStyle;
|
|
599
|
+
if (needsBackgroundLayer) {
|
|
600
|
+
if (node.divBg == null) {
|
|
601
|
+
node.divBg = document.createElement('div');
|
|
602
|
+
node.div.insertBefore(node.divBg, node.div.firstChild);
|
|
603
|
+
}
|
|
604
|
+
else if (node.divBg.parentElement !== node.div) {
|
|
605
|
+
node.div.insertBefore(node.divBg, node.div.firstChild);
|
|
606
|
+
}
|
|
607
|
+
let bgLayerStyle = 'position: absolute; top:0; left:0; right:0; bottom:0; z-index: -1; pointer-events: none; overflow: hidden;';
|
|
608
|
+
if (bgStyle) {
|
|
609
|
+
bgLayerStyle += bgStyle;
|
|
610
|
+
}
|
|
611
|
+
if (maskStyle) {
|
|
612
|
+
bgLayerStyle += maskStyle;
|
|
613
|
+
}
|
|
614
|
+
node.divBg.setAttribute('style', bgLayerStyle + radiusStyle);
|
|
615
|
+
if (rawImgSrc) {
|
|
616
|
+
if (!node.imgEl) {
|
|
617
|
+
node.imgEl = document.createElement('img');
|
|
618
|
+
node.imgEl.alt = '';
|
|
619
|
+
node.imgEl.crossOrigin = 'anonymous';
|
|
620
|
+
node.imgEl.setAttribute('aria-hidden', 'true');
|
|
621
|
+
node.imgEl.setAttribute('loading', 'lazy');
|
|
622
|
+
node.imgEl.removeAttribute('src');
|
|
623
|
+
node.imgEl.addEventListener('load', () => {
|
|
624
|
+
const payload = {
|
|
625
|
+
type: 'texture',
|
|
626
|
+
dimensions: {
|
|
627
|
+
w: node.imgEl.naturalWidth,
|
|
628
|
+
h: node.imgEl.naturalHeight,
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
node.imgEl.style.display = '';
|
|
632
|
+
applySubTextureScaling(node, node.imgEl, node.lazyImageSubTextureProps);
|
|
633
|
+
const resizeMode = node.props.textureOptions?.resizeMode;
|
|
634
|
+
const clipX = resizeMode?.clipX ?? 0.5;
|
|
635
|
+
const clipY = resizeMode?.clipY ?? 0.5;
|
|
636
|
+
computeLegacyObjectFit(node, node.imgEl, resizeMode, clipX, clipY, node.lazyImageSubTextureProps, supportsObjectFit, supportsObjectPosition);
|
|
637
|
+
node.emit('loaded', payload);
|
|
638
|
+
});
|
|
639
|
+
node.imgEl.addEventListener('error', () => {
|
|
640
|
+
if (node.imgEl) {
|
|
641
|
+
node.imgEl.removeAttribute('src');
|
|
642
|
+
node.imgEl.style.display = 'none';
|
|
643
|
+
node.imgEl.removeAttribute('data-rawSrc');
|
|
644
|
+
}
|
|
645
|
+
const failedSrc = node.imgEl?.dataset.pendingSrc || node.lazyImagePendingSrc || '';
|
|
646
|
+
const payload = {
|
|
647
|
+
type: 'texture',
|
|
648
|
+
error: new Error(`Failed to load image: ${failedSrc}`),
|
|
649
|
+
};
|
|
650
|
+
node.emit('failed', payload);
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
node.lazyImagePendingSrc = rawImgSrc;
|
|
654
|
+
node.lazyImageSubTextureProps = srcPos;
|
|
655
|
+
node.imgEl.dataset.pendingSrc = rawImgSrc;
|
|
656
|
+
if (node.imgEl.parentElement !== node.divBg) {
|
|
657
|
+
node.divBg.appendChild(node.imgEl);
|
|
658
|
+
}
|
|
659
|
+
node.imgEl.setAttribute('style', imgStyle);
|
|
660
|
+
if (hasDivBgTint) {
|
|
661
|
+
node.imgEl.style.visibility = 'hidden';
|
|
662
|
+
}
|
|
663
|
+
if (isRenderStateInBounds(node.renderState)) {
|
|
664
|
+
node.applyPendingImageSrc();
|
|
665
|
+
}
|
|
666
|
+
else if (!node.imgEl.dataset.rawSrc) {
|
|
667
|
+
node.imgEl.removeAttribute('src');
|
|
668
|
+
}
|
|
669
|
+
if (srcPos &&
|
|
670
|
+
node.imgEl.complete &&
|
|
671
|
+
node.imgEl.dataset.rawSrc === rawImgSrc) {
|
|
672
|
+
applySubTextureScaling(node, node.imgEl, srcPos);
|
|
673
|
+
}
|
|
674
|
+
if (!srcPos &&
|
|
675
|
+
node.imgEl.complete &&
|
|
676
|
+
(!supportsObjectFit || !supportsObjectPosition) &&
|
|
677
|
+
node.imgEl.dataset.rawSrc === rawImgSrc) {
|
|
678
|
+
const resizeMode = node.props.textureOptions?.resizeMode;
|
|
679
|
+
const clipX = resizeMode?.clipX ?? 0.5;
|
|
680
|
+
const clipY = resizeMode?.clipY ?? 0.5;
|
|
681
|
+
computeLegacyObjectFit(node, node.imgEl, resizeMode, clipX, clipY, srcPos, supportsObjectFit, supportsObjectPosition);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
node.lazyImagePendingSrc = null;
|
|
686
|
+
node.lazyImageSubTextureProps = null;
|
|
687
|
+
if (node.imgEl) {
|
|
688
|
+
node.imgEl.remove();
|
|
689
|
+
node.imgEl = undefined;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
node.lazyImagePendingSrc = null;
|
|
695
|
+
node.lazyImageSubTextureProps = null;
|
|
696
|
+
if (node.imgEl) {
|
|
697
|
+
node.imgEl.remove();
|
|
698
|
+
node.imgEl = undefined;
|
|
699
|
+
}
|
|
700
|
+
if (node.divBg) {
|
|
701
|
+
node.divBg.remove();
|
|
702
|
+
node.divBg = undefined;
|
|
703
|
+
}
|
|
704
|
+
style += bgStyle;
|
|
705
|
+
}
|
|
706
|
+
const needsSeparateBorderLayer = needsBackgroundLayer && maskStyle !== '';
|
|
707
|
+
if (needsSeparateBorderLayer) {
|
|
708
|
+
if (node.divBorder == null) {
|
|
709
|
+
node.divBorder = document.createElement('div');
|
|
710
|
+
node.div.appendChild(node.divBorder);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
else if (node.divBorder) {
|
|
714
|
+
node.divBorder.remove();
|
|
715
|
+
node.divBorder = undefined;
|
|
716
|
+
}
|
|
717
|
+
if (node.divBorder == null) {
|
|
718
|
+
style += borderStyle;
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
let borderLayerStyle = 'position: absolute; top:0; left:0; right:0; bottom:0; z-index: -1; pointer-events: none;';
|
|
722
|
+
borderLayerStyle += borderStyle;
|
|
723
|
+
node.divBorder.setAttribute('style', borderLayerStyle + radiusStyle);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
node.div.setAttribute('style', compactString(style));
|
|
727
|
+
if (node instanceof DOMNode && node !== node.stage.root) {
|
|
728
|
+
const hasTextureSrc = nodeHasTextureSource(node);
|
|
729
|
+
if (hasTextureSrc && node.boundsDirty) {
|
|
730
|
+
const next = computeRenderStateForNode(node);
|
|
731
|
+
if (next != null) {
|
|
732
|
+
node.updateRenderState(next);
|
|
733
|
+
}
|
|
734
|
+
node.boundsDirty = false;
|
|
735
|
+
}
|
|
736
|
+
else if (!hasTextureSrc) {
|
|
737
|
+
node.boundsDirty = false;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const textNodesToMeasure = new Set();
|
|
742
|
+
const containTextNodes = new Set();
|
|
743
|
+
let fontLoadingListenerSetup = false;
|
|
744
|
+
function getElSize(node) {
|
|
745
|
+
const rawRect = node.div.getBoundingClientRect();
|
|
746
|
+
const dpr = Config.rendererOptions?.deviceLogicalPixelRatio ?? 1;
|
|
747
|
+
let width = rawRect.width / dpr;
|
|
748
|
+
let height = rawRect.height / dpr;
|
|
749
|
+
for (;;) {
|
|
750
|
+
if (node.props.scale != null && node.props.scale !== 1) {
|
|
751
|
+
width /= node.props.scale;
|
|
752
|
+
height /= node.props.scale;
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
width /= node.props.scaleX;
|
|
756
|
+
height /= node.props.scaleY;
|
|
757
|
+
}
|
|
758
|
+
if (node.parent instanceof DOMNode) {
|
|
759
|
+
node = node.parent;
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return { width, height };
|
|
766
|
+
}
|
|
767
|
+
/*
|
|
768
|
+
Text nodes with contain 'width' or 'none'
|
|
769
|
+
need to have their height or width calculated.
|
|
770
|
+
And then cause the flex layout to be recalculated.
|
|
771
|
+
*/
|
|
772
|
+
function updateDOMTextSize(node, emitLoaded = true) {
|
|
773
|
+
let size;
|
|
774
|
+
let dimensionsChanged = false;
|
|
775
|
+
switch (node.contain) {
|
|
776
|
+
case 'width':
|
|
777
|
+
size = getElSize(node);
|
|
778
|
+
if (node.props.w !== size.width) {
|
|
779
|
+
node.w = size.width;
|
|
780
|
+
dimensionsChanged = true;
|
|
781
|
+
}
|
|
782
|
+
if (node.props.h !== size.height) {
|
|
783
|
+
node.h = size.height;
|
|
784
|
+
dimensionsChanged = true;
|
|
785
|
+
}
|
|
786
|
+
break;
|
|
787
|
+
case 'none':
|
|
788
|
+
size = getElSize(node);
|
|
789
|
+
if (node.props.h !== size.height || node.props.w !== size.width) {
|
|
790
|
+
node.w = size.width;
|
|
791
|
+
node.h = size.height;
|
|
792
|
+
dimensionsChanged = true;
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
if (emitLoaded && (!node.loaded || dimensionsChanged)) {
|
|
797
|
+
const payload = {
|
|
798
|
+
type: 'text',
|
|
799
|
+
dimensions: {
|
|
800
|
+
w: node.w,
|
|
801
|
+
h: node.h,
|
|
802
|
+
},
|
|
803
|
+
};
|
|
804
|
+
node.emit('loaded', payload);
|
|
805
|
+
node.loaded = true;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function updateDOMTextMeasurements() {
|
|
809
|
+
textNodesToMeasure.forEach((node) => updateDOMTextSize(node));
|
|
810
|
+
textNodesToMeasure.clear();
|
|
811
|
+
}
|
|
812
|
+
function shouldTrackContainTextNode(node) {
|
|
813
|
+
return node.contain === 'width' || node.contain === 'none';
|
|
814
|
+
}
|
|
815
|
+
function syncContainTextNodeTracking(node) {
|
|
816
|
+
if (shouldTrackContainTextNode(node)) {
|
|
817
|
+
containTextNodes.add(node);
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
containTextNodes.delete(node);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
function scheduleContainTextNodesMeasurement() {
|
|
824
|
+
if (containTextNodes.size === 0)
|
|
825
|
+
return;
|
|
826
|
+
containTextNodes.forEach((node) => {
|
|
827
|
+
if (node.div.isConnected) {
|
|
828
|
+
textNodesToMeasure.add(node);
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
if (textNodesToMeasure.size > 0) {
|
|
832
|
+
setTimeout(updateDOMTextMeasurements);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function setupFontLoadingListeners() {
|
|
836
|
+
if (fontLoadingListenerSetup)
|
|
837
|
+
return;
|
|
838
|
+
if (typeof document === 'undefined' ||
|
|
839
|
+
!document.fonts) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const fonts = document.fonts;
|
|
843
|
+
if (typeof fonts.addEventListener === 'function') {
|
|
844
|
+
fonts.addEventListener('loadingdone', scheduleContainTextNodesMeasurement);
|
|
845
|
+
}
|
|
846
|
+
fontLoadingListenerSetup = true;
|
|
847
|
+
}
|
|
848
|
+
function scheduleUpdateDOMTextMeasurement(node) {
|
|
849
|
+
/*
|
|
850
|
+
Make sure the font is loaded before measuring
|
|
851
|
+
*/
|
|
852
|
+
setupFontLoadingListeners();
|
|
853
|
+
if (textNodesToMeasure.size === 0) {
|
|
854
|
+
if (typeof document !== 'undefined' && 'fonts' in document) {
|
|
855
|
+
const fonts = document.fonts;
|
|
856
|
+
if (fonts.status === 'loaded') {
|
|
857
|
+
setTimeout(updateDOMTextMeasurements);
|
|
858
|
+
}
|
|
859
|
+
else if (fonts.ready && typeof fonts.ready.then === 'function') {
|
|
860
|
+
fonts.ready.then(updateDOMTextMeasurements);
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
setTimeout(updateDOMTextMeasurements, 500);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
setTimeout(updateDOMTextMeasurements, 500);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
textNodesToMeasure.add(node);
|
|
871
|
+
}
|
|
872
|
+
function updateNodeData(node) {
|
|
873
|
+
const data = node.data;
|
|
874
|
+
for (let key in data) {
|
|
875
|
+
let keyValue = data[key];
|
|
876
|
+
if (keyValue === undefined) {
|
|
877
|
+
node.div.removeAttribute('data-' + key);
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
node.div.dataset[key] = String(keyValue);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function resolveNodeDefaults(props) {
|
|
885
|
+
const color = props.color ?? 0x00000000;
|
|
886
|
+
return {
|
|
887
|
+
x: props.x ?? 0,
|
|
888
|
+
y: props.y ?? 0,
|
|
889
|
+
w: props.w ?? 0,
|
|
890
|
+
h: props.h ?? 0,
|
|
891
|
+
alpha: props.alpha ?? 1,
|
|
892
|
+
autosize: props.autosize ?? false,
|
|
893
|
+
boundsMargin: props.boundsMargin ?? null,
|
|
894
|
+
clipping: props.clipping ?? false,
|
|
895
|
+
color,
|
|
896
|
+
colorTop: props.colorTop ?? color,
|
|
897
|
+
colorBottom: props.colorBottom ?? color,
|
|
898
|
+
colorLeft: props.colorLeft ?? color,
|
|
899
|
+
colorRight: props.colorRight ?? color,
|
|
900
|
+
colorBl: props.colorBl ?? props.colorBottom ?? props.colorLeft ?? color,
|
|
901
|
+
colorBr: props.colorBr ?? props.colorBottom ?? props.colorRight ?? color,
|
|
902
|
+
colorTl: props.colorTl ?? props.colorTop ?? props.colorLeft ?? color,
|
|
903
|
+
colorTr: props.colorTr ?? props.colorTop ?? props.colorRight ?? color,
|
|
904
|
+
zIndex: props.zIndex ?? 0,
|
|
905
|
+
parent: props.parent ?? null,
|
|
906
|
+
texture: props.texture ?? null,
|
|
907
|
+
textureOptions: props.textureOptions ?? {},
|
|
908
|
+
shader: props.shader ?? defaultShader,
|
|
909
|
+
// Since setting the `src` will trigger a texture load, we need to set it after
|
|
910
|
+
// we set the texture. Otherwise, problems happen.
|
|
911
|
+
src: props.src ?? null,
|
|
912
|
+
srcHeight: props.srcHeight,
|
|
913
|
+
srcWidth: props.srcWidth,
|
|
914
|
+
srcX: props.srcX,
|
|
915
|
+
srcY: props.srcY,
|
|
916
|
+
scale: props.scale ?? null,
|
|
917
|
+
scaleX: props.scaleX ?? props.scale ?? 1,
|
|
918
|
+
scaleY: props.scaleY ?? props.scale ?? 1,
|
|
919
|
+
mount: props.mount ?? 0,
|
|
920
|
+
mountX: props.mountX ?? props.mount ?? 0,
|
|
921
|
+
mountY: props.mountY ?? props.mount ?? 0,
|
|
922
|
+
pivot: props.pivot ?? 0.5,
|
|
923
|
+
pivotX: props.pivotX ?? props.pivot ?? 0.5,
|
|
924
|
+
pivotY: props.pivotY ?? props.pivot ?? 0.5,
|
|
925
|
+
rotation: props.rotation ?? 0,
|
|
926
|
+
rtt: props.rtt ?? false,
|
|
927
|
+
data: {},
|
|
928
|
+
imageType: props.imageType,
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
function resolveTextNodeDefaults(props) {
|
|
932
|
+
return {
|
|
933
|
+
...resolveNodeDefaults(props),
|
|
934
|
+
text: props.text ?? '',
|
|
935
|
+
textRendererOverride: props.textRendererOverride ?? null,
|
|
936
|
+
fontSize: props.fontSize ?? 16,
|
|
937
|
+
fontFamily: props.fontFamily ?? 'sans-serif',
|
|
938
|
+
fontStyle: props.fontStyle ?? 'normal',
|
|
939
|
+
fontWeight: props.fontWeight ?? 'normal',
|
|
940
|
+
forceLoad: props.forceLoad ?? false,
|
|
941
|
+
textAlign: props.textAlign ?? 'left',
|
|
942
|
+
contain: props.contain ?? 'none',
|
|
943
|
+
offsetY: props.offsetY ?? 0,
|
|
944
|
+
letterSpacing: props.letterSpacing ?? 0,
|
|
945
|
+
lineHeight: props.lineHeight ?? 0,
|
|
946
|
+
maxLines: props.maxLines ?? 0,
|
|
947
|
+
maxWidth: props.maxWidth ?? 0,
|
|
948
|
+
maxHeight: props.maxHeight ?? 0,
|
|
949
|
+
verticalAlign: props.verticalAlign ?? 'middle',
|
|
950
|
+
overflowSuffix: props.overflowSuffix ?? '...',
|
|
951
|
+
wordBreak: props.wordBreak ?? 'overflow',
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
const defaultShader = {
|
|
955
|
+
shaderType: '',
|
|
956
|
+
props: undefined,
|
|
957
|
+
};
|
|
958
|
+
let lastNodeId = 0;
|
|
959
|
+
const CoreNodeRenderStateMap = new Map([
|
|
960
|
+
[0, 'init'],
|
|
961
|
+
[2, 'outOfBounds'],
|
|
962
|
+
[4, 'inBounds'],
|
|
963
|
+
[8, 'inViewport'],
|
|
964
|
+
]);
|
|
965
|
+
export class DOMNode extends EventEmitter {
|
|
966
|
+
stage;
|
|
967
|
+
props;
|
|
968
|
+
div = document.createElement('div');
|
|
969
|
+
divBg;
|
|
970
|
+
divBorder;
|
|
971
|
+
imgEl;
|
|
972
|
+
lazyImagePendingSrc = null;
|
|
973
|
+
lazyImageSubTextureProps = null;
|
|
974
|
+
boundsDirty = true;
|
|
975
|
+
children = new Set();
|
|
976
|
+
id = ++lastNodeId;
|
|
977
|
+
renderState = 0 /* Init */;
|
|
978
|
+
preventCleanup = true;
|
|
979
|
+
constructor(stage, props) {
|
|
980
|
+
super();
|
|
981
|
+
this.stage = stage;
|
|
982
|
+
this.props = props;
|
|
983
|
+
// @ts-ignore
|
|
984
|
+
this.div._node = this;
|
|
985
|
+
this.div.setAttribute('data-id', String(this.id));
|
|
986
|
+
elMap.set(this, this.div);
|
|
987
|
+
const parent = this.props.parent;
|
|
988
|
+
if (parent instanceof DOMNode) {
|
|
989
|
+
parent.children.add(this);
|
|
990
|
+
}
|
|
991
|
+
updateNodeParent(this);
|
|
992
|
+
updateNodeStyles(this);
|
|
993
|
+
updateNodeData(this);
|
|
994
|
+
}
|
|
995
|
+
destroy() {
|
|
996
|
+
elMap.delete(this);
|
|
997
|
+
const parent = this.props.parent;
|
|
998
|
+
if (parent instanceof DOMNode) {
|
|
999
|
+
parent.children.delete(this);
|
|
1000
|
+
}
|
|
1001
|
+
this.div.parentNode.removeChild(this.div);
|
|
1002
|
+
}
|
|
1003
|
+
get parent() {
|
|
1004
|
+
return this.props.parent;
|
|
1005
|
+
}
|
|
1006
|
+
set parent(value) {
|
|
1007
|
+
if (this.props.parent === value)
|
|
1008
|
+
return;
|
|
1009
|
+
const prevParent = this.props.parent;
|
|
1010
|
+
if (prevParent instanceof DOMNode) {
|
|
1011
|
+
prevParent.children.delete(this);
|
|
1012
|
+
prevParent.markChildrenBoundsDirty();
|
|
1013
|
+
}
|
|
1014
|
+
this.props.parent = value;
|
|
1015
|
+
if (value instanceof DOMNode) {
|
|
1016
|
+
value.children.add(this);
|
|
1017
|
+
value.markChildrenBoundsDirty();
|
|
1018
|
+
}
|
|
1019
|
+
this.boundsDirty = true;
|
|
1020
|
+
this.markChildrenBoundsDirty();
|
|
1021
|
+
updateNodeParent(this);
|
|
1022
|
+
}
|
|
1023
|
+
markChildrenBoundsDirty() {
|
|
1024
|
+
for (const child of this.children) {
|
|
1025
|
+
child.boundsDirty = true;
|
|
1026
|
+
if (child !== child.stage.root) {
|
|
1027
|
+
if (nodeHasTextureSource(child)) {
|
|
1028
|
+
const nextState = computeRenderStateForNode(child);
|
|
1029
|
+
if (nextState != null) {
|
|
1030
|
+
child.updateRenderState(nextState);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
child.boundsDirty = false;
|
|
1034
|
+
}
|
|
1035
|
+
child.markChildrenBoundsDirty();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
animate = animate;
|
|
1039
|
+
updateRenderState(renderState) {
|
|
1040
|
+
if (renderState === this.renderState)
|
|
1041
|
+
return;
|
|
1042
|
+
const previous = this.renderState;
|
|
1043
|
+
this.renderState = renderState;
|
|
1044
|
+
const event = CoreNodeRenderStateMap.get(renderState);
|
|
1045
|
+
if (isRenderStateInBounds(renderState)) {
|
|
1046
|
+
this.applyPendingImageSrc();
|
|
1047
|
+
}
|
|
1048
|
+
if (event && event !== 'init') {
|
|
1049
|
+
this.emit(event, { previous, current: renderState });
|
|
1050
|
+
}
|
|
1051
|
+
if (this.imgEl) {
|
|
1052
|
+
this.imgEl.dataset.state = event;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
applyPendingImageSrc() {
|
|
1056
|
+
if (!this.imgEl)
|
|
1057
|
+
return;
|
|
1058
|
+
const pendingSrc = this.lazyImagePendingSrc;
|
|
1059
|
+
if (!pendingSrc)
|
|
1060
|
+
return;
|
|
1061
|
+
if (this.imgEl.dataset.rawSrc === pendingSrc)
|
|
1062
|
+
return;
|
|
1063
|
+
this.imgEl.style.display = '';
|
|
1064
|
+
this.imgEl.dataset.pendingSrc = pendingSrc;
|
|
1065
|
+
this.imgEl.src = pendingSrc;
|
|
1066
|
+
this.imgEl.dataset.rawSrc = pendingSrc;
|
|
1067
|
+
this.imgEl.dataset.pendingSrc = '';
|
|
1068
|
+
}
|
|
1069
|
+
get x() {
|
|
1070
|
+
return this.props.x;
|
|
1071
|
+
}
|
|
1072
|
+
set x(v) {
|
|
1073
|
+
if (this.props.x === v)
|
|
1074
|
+
return;
|
|
1075
|
+
this.props.x = v;
|
|
1076
|
+
this.boundsDirty = true;
|
|
1077
|
+
this.markChildrenBoundsDirty();
|
|
1078
|
+
updateNodeStyles(this);
|
|
1079
|
+
}
|
|
1080
|
+
get y() {
|
|
1081
|
+
return this.props.y;
|
|
1082
|
+
}
|
|
1083
|
+
set y(v) {
|
|
1084
|
+
if (this.props.y === v)
|
|
1085
|
+
return;
|
|
1086
|
+
this.props.y = v;
|
|
1087
|
+
this.boundsDirty = true;
|
|
1088
|
+
this.markChildrenBoundsDirty();
|
|
1089
|
+
updateNodeStyles(this);
|
|
1090
|
+
}
|
|
1091
|
+
get w() {
|
|
1092
|
+
return this.props.w;
|
|
1093
|
+
}
|
|
1094
|
+
set w(v) {
|
|
1095
|
+
if (this.props.w === v)
|
|
1096
|
+
return;
|
|
1097
|
+
this.props.w = v;
|
|
1098
|
+
this.boundsDirty = true;
|
|
1099
|
+
this.markChildrenBoundsDirty();
|
|
1100
|
+
updateNodeStyles(this);
|
|
1101
|
+
}
|
|
1102
|
+
get h() {
|
|
1103
|
+
return this.props.h;
|
|
1104
|
+
}
|
|
1105
|
+
set h(v) {
|
|
1106
|
+
if (this.props.h === v)
|
|
1107
|
+
return;
|
|
1108
|
+
this.props.h = v;
|
|
1109
|
+
this.boundsDirty = true;
|
|
1110
|
+
this.markChildrenBoundsDirty();
|
|
1111
|
+
updateNodeStyles(this);
|
|
1112
|
+
}
|
|
1113
|
+
get width() {
|
|
1114
|
+
return this.props.w;
|
|
1115
|
+
}
|
|
1116
|
+
set width(v) {
|
|
1117
|
+
if (this.props.w === v)
|
|
1118
|
+
return;
|
|
1119
|
+
this.props.w = v;
|
|
1120
|
+
this.boundsDirty = true;
|
|
1121
|
+
this.markChildrenBoundsDirty();
|
|
1122
|
+
updateNodeStyles(this);
|
|
1123
|
+
}
|
|
1124
|
+
get height() {
|
|
1125
|
+
return this.props.h;
|
|
1126
|
+
}
|
|
1127
|
+
set height(v) {
|
|
1128
|
+
if (this.props.h === v)
|
|
1129
|
+
return;
|
|
1130
|
+
this.props.h = v;
|
|
1131
|
+
this.boundsDirty = true;
|
|
1132
|
+
this.markChildrenBoundsDirty();
|
|
1133
|
+
updateNodeStyles(this);
|
|
1134
|
+
}
|
|
1135
|
+
get alpha() {
|
|
1136
|
+
return this.props.alpha;
|
|
1137
|
+
}
|
|
1138
|
+
set alpha(v) {
|
|
1139
|
+
this.props.alpha = v;
|
|
1140
|
+
updateNodeStyles(this);
|
|
1141
|
+
}
|
|
1142
|
+
get autosize() {
|
|
1143
|
+
return this.props.autosize;
|
|
1144
|
+
}
|
|
1145
|
+
set autosize(v) {
|
|
1146
|
+
this.props.autosize = v;
|
|
1147
|
+
updateNodeStyles(this);
|
|
1148
|
+
}
|
|
1149
|
+
get clipping() {
|
|
1150
|
+
return this.props.clipping;
|
|
1151
|
+
}
|
|
1152
|
+
set clipping(v) {
|
|
1153
|
+
this.props.clipping = v;
|
|
1154
|
+
updateNodeStyles(this);
|
|
1155
|
+
}
|
|
1156
|
+
get color() {
|
|
1157
|
+
return this.props.color;
|
|
1158
|
+
}
|
|
1159
|
+
set color(v) {
|
|
1160
|
+
this.props.color = v;
|
|
1161
|
+
updateNodeStyles(this);
|
|
1162
|
+
}
|
|
1163
|
+
get colorTop() {
|
|
1164
|
+
return this.props.colorTop;
|
|
1165
|
+
}
|
|
1166
|
+
set colorTop(v) {
|
|
1167
|
+
this.props.colorTop = v;
|
|
1168
|
+
updateNodeStyles(this);
|
|
1169
|
+
}
|
|
1170
|
+
get colorBottom() {
|
|
1171
|
+
return this.props.colorBottom;
|
|
1172
|
+
}
|
|
1173
|
+
set colorBottom(v) {
|
|
1174
|
+
this.props.colorBottom = v;
|
|
1175
|
+
updateNodeStyles(this);
|
|
1176
|
+
}
|
|
1177
|
+
get colorLeft() {
|
|
1178
|
+
return this.props.colorLeft;
|
|
1179
|
+
}
|
|
1180
|
+
set colorLeft(v) {
|
|
1181
|
+
this.props.colorLeft = v;
|
|
1182
|
+
updateNodeStyles(this);
|
|
1183
|
+
}
|
|
1184
|
+
get colorRight() {
|
|
1185
|
+
return this.props.colorRight;
|
|
1186
|
+
}
|
|
1187
|
+
set colorRight(v) {
|
|
1188
|
+
this.props.colorRight = v;
|
|
1189
|
+
updateNodeStyles(this);
|
|
1190
|
+
}
|
|
1191
|
+
get colorTl() {
|
|
1192
|
+
return this.props.colorTl;
|
|
1193
|
+
}
|
|
1194
|
+
set colorTl(v) {
|
|
1195
|
+
this.props.colorTl = v;
|
|
1196
|
+
updateNodeStyles(this);
|
|
1197
|
+
}
|
|
1198
|
+
get colorTr() {
|
|
1199
|
+
return this.props.colorTr;
|
|
1200
|
+
}
|
|
1201
|
+
set colorTr(v) {
|
|
1202
|
+
this.props.colorTr = v;
|
|
1203
|
+
updateNodeStyles(this);
|
|
1204
|
+
}
|
|
1205
|
+
get colorBr() {
|
|
1206
|
+
return this.props.colorBr;
|
|
1207
|
+
}
|
|
1208
|
+
set colorBr(v) {
|
|
1209
|
+
this.props.colorBr = v;
|
|
1210
|
+
updateNodeStyles(this);
|
|
1211
|
+
}
|
|
1212
|
+
get colorBl() {
|
|
1213
|
+
return this.props.colorBl;
|
|
1214
|
+
}
|
|
1215
|
+
set colorBl(v) {
|
|
1216
|
+
this.props.colorBl = v;
|
|
1217
|
+
updateNodeStyles(this);
|
|
1218
|
+
}
|
|
1219
|
+
get zIndex() {
|
|
1220
|
+
return this.props.zIndex;
|
|
1221
|
+
}
|
|
1222
|
+
set zIndex(v) {
|
|
1223
|
+
if (this.props.zIndex === v)
|
|
1224
|
+
return;
|
|
1225
|
+
this.props.zIndex = Math.ceil(v);
|
|
1226
|
+
updateNodeStyles(this);
|
|
1227
|
+
}
|
|
1228
|
+
get texture() {
|
|
1229
|
+
return this.props.texture;
|
|
1230
|
+
}
|
|
1231
|
+
set texture(v) {
|
|
1232
|
+
if (this.props.texture === v)
|
|
1233
|
+
return;
|
|
1234
|
+
this.props.texture = v;
|
|
1235
|
+
this.boundsDirty = true;
|
|
1236
|
+
updateNodeStyles(this);
|
|
1237
|
+
}
|
|
1238
|
+
get textureOptions() {
|
|
1239
|
+
return this.props.textureOptions;
|
|
1240
|
+
}
|
|
1241
|
+
set textureOptions(v) {
|
|
1242
|
+
this.props.textureOptions = v;
|
|
1243
|
+
updateNodeStyles(this);
|
|
1244
|
+
}
|
|
1245
|
+
get src() {
|
|
1246
|
+
return this.props.src;
|
|
1247
|
+
}
|
|
1248
|
+
set src(v) {
|
|
1249
|
+
if (this.props.src === v)
|
|
1250
|
+
return;
|
|
1251
|
+
this.props.src = v;
|
|
1252
|
+
this.boundsDirty = true;
|
|
1253
|
+
updateNodeStyles(this);
|
|
1254
|
+
}
|
|
1255
|
+
get scale() {
|
|
1256
|
+
return this.props.scale ?? 1;
|
|
1257
|
+
}
|
|
1258
|
+
set scale(v) {
|
|
1259
|
+
if (this.props.scale === v)
|
|
1260
|
+
return;
|
|
1261
|
+
this.props.scale = v;
|
|
1262
|
+
this.boundsDirty = true;
|
|
1263
|
+
this.markChildrenBoundsDirty();
|
|
1264
|
+
updateNodeStyles(this);
|
|
1265
|
+
}
|
|
1266
|
+
get scaleX() {
|
|
1267
|
+
return this.props.scaleX;
|
|
1268
|
+
}
|
|
1269
|
+
set scaleX(v) {
|
|
1270
|
+
if (this.props.scaleX === v)
|
|
1271
|
+
return;
|
|
1272
|
+
this.props.scaleX = v;
|
|
1273
|
+
this.boundsDirty = true;
|
|
1274
|
+
this.markChildrenBoundsDirty();
|
|
1275
|
+
updateNodeStyles(this);
|
|
1276
|
+
}
|
|
1277
|
+
get scaleY() {
|
|
1278
|
+
return this.props.scaleY;
|
|
1279
|
+
}
|
|
1280
|
+
set scaleY(v) {
|
|
1281
|
+
if (this.props.scaleY === v)
|
|
1282
|
+
return;
|
|
1283
|
+
this.props.scaleY = v;
|
|
1284
|
+
this.boundsDirty = true;
|
|
1285
|
+
this.markChildrenBoundsDirty();
|
|
1286
|
+
updateNodeStyles(this);
|
|
1287
|
+
}
|
|
1288
|
+
get mount() {
|
|
1289
|
+
return this.props.mount;
|
|
1290
|
+
}
|
|
1291
|
+
set mount(v) {
|
|
1292
|
+
if (this.props.mount === v)
|
|
1293
|
+
return;
|
|
1294
|
+
this.props.mount = v;
|
|
1295
|
+
this.boundsDirty = true;
|
|
1296
|
+
this.markChildrenBoundsDirty();
|
|
1297
|
+
updateNodeStyles(this);
|
|
1298
|
+
}
|
|
1299
|
+
get mountX() {
|
|
1300
|
+
return this.props.mountX;
|
|
1301
|
+
}
|
|
1302
|
+
set mountX(v) {
|
|
1303
|
+
if (this.props.mountX === v)
|
|
1304
|
+
return;
|
|
1305
|
+
this.props.mountX = v;
|
|
1306
|
+
this.boundsDirty = true;
|
|
1307
|
+
this.markChildrenBoundsDirty();
|
|
1308
|
+
updateNodeStyles(this);
|
|
1309
|
+
}
|
|
1310
|
+
get mountY() {
|
|
1311
|
+
return this.props.mountY;
|
|
1312
|
+
}
|
|
1313
|
+
set mountY(v) {
|
|
1314
|
+
if (this.props.mountY === v)
|
|
1315
|
+
return;
|
|
1316
|
+
this.props.mountY = v;
|
|
1317
|
+
this.boundsDirty = true;
|
|
1318
|
+
this.markChildrenBoundsDirty();
|
|
1319
|
+
updateNodeStyles(this);
|
|
1320
|
+
}
|
|
1321
|
+
get pivot() {
|
|
1322
|
+
return this.props.pivot;
|
|
1323
|
+
}
|
|
1324
|
+
set pivot(v) {
|
|
1325
|
+
if (this.props.pivot === v)
|
|
1326
|
+
return;
|
|
1327
|
+
this.props.pivot = v;
|
|
1328
|
+
this.boundsDirty = true;
|
|
1329
|
+
this.markChildrenBoundsDirty();
|
|
1330
|
+
updateNodeStyles(this);
|
|
1331
|
+
}
|
|
1332
|
+
get pivotX() {
|
|
1333
|
+
return this.props.pivotX;
|
|
1334
|
+
}
|
|
1335
|
+
set pivotX(v) {
|
|
1336
|
+
if (this.props.pivotX === v)
|
|
1337
|
+
return;
|
|
1338
|
+
this.props.pivotX = v;
|
|
1339
|
+
this.boundsDirty = true;
|
|
1340
|
+
this.markChildrenBoundsDirty();
|
|
1341
|
+
updateNodeStyles(this);
|
|
1342
|
+
}
|
|
1343
|
+
get pivotY() {
|
|
1344
|
+
return this.props.pivotY;
|
|
1345
|
+
}
|
|
1346
|
+
set pivotY(v) {
|
|
1347
|
+
if (this.props.pivotY === v)
|
|
1348
|
+
return;
|
|
1349
|
+
this.props.pivotY = v;
|
|
1350
|
+
this.boundsDirty = true;
|
|
1351
|
+
this.markChildrenBoundsDirty();
|
|
1352
|
+
updateNodeStyles(this);
|
|
1353
|
+
}
|
|
1354
|
+
get rotation() {
|
|
1355
|
+
return this.props.rotation;
|
|
1356
|
+
}
|
|
1357
|
+
set rotation(v) {
|
|
1358
|
+
if (this.props.rotation === v)
|
|
1359
|
+
return;
|
|
1360
|
+
this.props.rotation = v;
|
|
1361
|
+
this.boundsDirty = true;
|
|
1362
|
+
this.markChildrenBoundsDirty();
|
|
1363
|
+
updateNodeStyles(this);
|
|
1364
|
+
}
|
|
1365
|
+
get rtt() {
|
|
1366
|
+
return this.props.rtt;
|
|
1367
|
+
}
|
|
1368
|
+
set rtt(v) {
|
|
1369
|
+
this.props.rtt = v;
|
|
1370
|
+
updateNodeStyles(this);
|
|
1371
|
+
}
|
|
1372
|
+
get shader() {
|
|
1373
|
+
return this.props.shader;
|
|
1374
|
+
}
|
|
1375
|
+
set shader(v) {
|
|
1376
|
+
this.props.shader = v;
|
|
1377
|
+
updateNodeStyles(this);
|
|
1378
|
+
}
|
|
1379
|
+
get data() {
|
|
1380
|
+
return this.props.data;
|
|
1381
|
+
}
|
|
1382
|
+
set data(v) {
|
|
1383
|
+
this.props.data = v;
|
|
1384
|
+
updateNodeData(this);
|
|
1385
|
+
}
|
|
1386
|
+
get imageType() {
|
|
1387
|
+
return this.props.imageType;
|
|
1388
|
+
}
|
|
1389
|
+
set imageType(v) {
|
|
1390
|
+
this.props.imageType = v;
|
|
1391
|
+
}
|
|
1392
|
+
get srcWidth() {
|
|
1393
|
+
return this.props.srcWidth;
|
|
1394
|
+
}
|
|
1395
|
+
set srcWidth(v) {
|
|
1396
|
+
this.props.srcWidth = v;
|
|
1397
|
+
}
|
|
1398
|
+
get srcHeight() {
|
|
1399
|
+
return this.props.srcHeight;
|
|
1400
|
+
}
|
|
1401
|
+
set srcHeight(v) {
|
|
1402
|
+
this.props.srcHeight = v;
|
|
1403
|
+
}
|
|
1404
|
+
get srcX() {
|
|
1405
|
+
return this.props.srcX;
|
|
1406
|
+
}
|
|
1407
|
+
set srcX(v) {
|
|
1408
|
+
this.props.srcX = v;
|
|
1409
|
+
}
|
|
1410
|
+
get srcY() {
|
|
1411
|
+
return this.props.srcY;
|
|
1412
|
+
}
|
|
1413
|
+
set srcY(v) {
|
|
1414
|
+
this.props.srcY = v;
|
|
1415
|
+
}
|
|
1416
|
+
get boundsMargin() {
|
|
1417
|
+
return this.props.boundsMargin;
|
|
1418
|
+
}
|
|
1419
|
+
set boundsMargin(value) {
|
|
1420
|
+
this.props.boundsMargin = value;
|
|
1421
|
+
this.boundsDirty = true;
|
|
1422
|
+
this.markChildrenBoundsDirty();
|
|
1423
|
+
}
|
|
1424
|
+
get absX() {
|
|
1425
|
+
const parent = this.props.parent;
|
|
1426
|
+
return (this.x +
|
|
1427
|
+
-this.w * this.mountX +
|
|
1428
|
+
(parent instanceof DOMNode ? parent.absX : 0));
|
|
1429
|
+
}
|
|
1430
|
+
get absY() {
|
|
1431
|
+
const parent = this.props.parent;
|
|
1432
|
+
return (this.y +
|
|
1433
|
+
-this.h * this.mountY +
|
|
1434
|
+
(parent instanceof DOMNode ? parent.absY : 0));
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
class DOMText extends DOMNode {
|
|
1438
|
+
props;
|
|
1439
|
+
loaded = false;
|
|
1440
|
+
constructor(stage, props) {
|
|
1441
|
+
super(stage, props);
|
|
1442
|
+
this.props = props;
|
|
1443
|
+
this.div.innerText = props.text;
|
|
1444
|
+
updateNodeStyles(this);
|
|
1445
|
+
updateDOMTextSize(this, false);
|
|
1446
|
+
syncContainTextNodeTracking(this);
|
|
1447
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1448
|
+
}
|
|
1449
|
+
destroy() {
|
|
1450
|
+
textNodesToMeasure.delete(this);
|
|
1451
|
+
containTextNodes.delete(this);
|
|
1452
|
+
super.destroy();
|
|
1453
|
+
}
|
|
1454
|
+
get text() {
|
|
1455
|
+
return this.props.text;
|
|
1456
|
+
}
|
|
1457
|
+
set text(v) {
|
|
1458
|
+
if (this.props.text === v)
|
|
1459
|
+
return;
|
|
1460
|
+
this.props.text = v;
|
|
1461
|
+
this.div.innerText = v;
|
|
1462
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1463
|
+
}
|
|
1464
|
+
get fontFamily() {
|
|
1465
|
+
return this.props.fontFamily;
|
|
1466
|
+
}
|
|
1467
|
+
set fontFamily(v) {
|
|
1468
|
+
if (this.props.fontFamily === v)
|
|
1469
|
+
return;
|
|
1470
|
+
this.props.fontFamily = v;
|
|
1471
|
+
updateNodeStyles(this);
|
|
1472
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1473
|
+
}
|
|
1474
|
+
get fontSize() {
|
|
1475
|
+
return this.props.fontSize;
|
|
1476
|
+
}
|
|
1477
|
+
set fontSize(v) {
|
|
1478
|
+
if (this.props.fontSize === v)
|
|
1479
|
+
return;
|
|
1480
|
+
this.props.fontSize = v;
|
|
1481
|
+
updateNodeStyles(this);
|
|
1482
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1483
|
+
}
|
|
1484
|
+
get fontStyle() {
|
|
1485
|
+
return this.props.fontStyle;
|
|
1486
|
+
}
|
|
1487
|
+
set fontStyle(v) {
|
|
1488
|
+
if (this.props.fontStyle === v)
|
|
1489
|
+
return;
|
|
1490
|
+
this.props.fontStyle = v;
|
|
1491
|
+
updateNodeStyles(this);
|
|
1492
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1493
|
+
}
|
|
1494
|
+
get fontWeight() {
|
|
1495
|
+
return this.props.fontWeight;
|
|
1496
|
+
}
|
|
1497
|
+
set fontWeight(v) {
|
|
1498
|
+
if (this.props.fontWeight === v)
|
|
1499
|
+
return;
|
|
1500
|
+
this.props.fontWeight = v;
|
|
1501
|
+
updateNodeStyles(this);
|
|
1502
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1503
|
+
}
|
|
1504
|
+
get fontStretch() {
|
|
1505
|
+
return this.props.fontStretch;
|
|
1506
|
+
}
|
|
1507
|
+
set fontStretch(v) {
|
|
1508
|
+
if (this.props.fontStretch === v)
|
|
1509
|
+
return;
|
|
1510
|
+
this.props.fontStretch = v;
|
|
1511
|
+
updateNodeStyles(this);
|
|
1512
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1513
|
+
}
|
|
1514
|
+
get forceLoad() {
|
|
1515
|
+
return this.props.forceLoad;
|
|
1516
|
+
}
|
|
1517
|
+
set forceLoad(v) {
|
|
1518
|
+
this.props.forceLoad = v;
|
|
1519
|
+
}
|
|
1520
|
+
get lineHeight() {
|
|
1521
|
+
return this.props.lineHeight;
|
|
1522
|
+
}
|
|
1523
|
+
set lineHeight(v) {
|
|
1524
|
+
if (this.props.lineHeight === v)
|
|
1525
|
+
return;
|
|
1526
|
+
this.props.lineHeight = v;
|
|
1527
|
+
updateNodeStyles(this);
|
|
1528
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1529
|
+
}
|
|
1530
|
+
get maxWidth() {
|
|
1531
|
+
return this.props.maxWidth;
|
|
1532
|
+
}
|
|
1533
|
+
set maxWidth(v) {
|
|
1534
|
+
if (this.props.maxWidth === v)
|
|
1535
|
+
return;
|
|
1536
|
+
this.props.maxWidth = v;
|
|
1537
|
+
updateNodeStyles(this);
|
|
1538
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1539
|
+
}
|
|
1540
|
+
get maxHeight() {
|
|
1541
|
+
return this.props.maxHeight;
|
|
1542
|
+
}
|
|
1543
|
+
set maxHeight(v) {
|
|
1544
|
+
if (this.props.maxHeight === v)
|
|
1545
|
+
return;
|
|
1546
|
+
this.props.maxHeight = v;
|
|
1547
|
+
updateNodeStyles(this);
|
|
1548
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1549
|
+
}
|
|
1550
|
+
get letterSpacing() {
|
|
1551
|
+
return this.props.letterSpacing;
|
|
1552
|
+
}
|
|
1553
|
+
set letterSpacing(v) {
|
|
1554
|
+
if (this.props.letterSpacing === v)
|
|
1555
|
+
return;
|
|
1556
|
+
this.props.letterSpacing = v;
|
|
1557
|
+
updateNodeStyles(this);
|
|
1558
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1559
|
+
}
|
|
1560
|
+
get textAlign() {
|
|
1561
|
+
return this.props.textAlign;
|
|
1562
|
+
}
|
|
1563
|
+
set textAlign(v) {
|
|
1564
|
+
if (this.props.textAlign === v)
|
|
1565
|
+
return;
|
|
1566
|
+
this.props.textAlign = v;
|
|
1567
|
+
updateNodeStyles(this);
|
|
1568
|
+
}
|
|
1569
|
+
get overflowSuffix() {
|
|
1570
|
+
return this.props.overflowSuffix;
|
|
1571
|
+
}
|
|
1572
|
+
set overflowSuffix(v) {
|
|
1573
|
+
if (this.props.overflowSuffix === v)
|
|
1574
|
+
return;
|
|
1575
|
+
this.props.overflowSuffix = v;
|
|
1576
|
+
updateNodeStyles(this);
|
|
1577
|
+
}
|
|
1578
|
+
get maxLines() {
|
|
1579
|
+
return this.props.maxLines;
|
|
1580
|
+
}
|
|
1581
|
+
set maxLines(v) {
|
|
1582
|
+
if (this.props.maxLines === v)
|
|
1583
|
+
return;
|
|
1584
|
+
this.props.maxLines = v;
|
|
1585
|
+
updateNodeStyles(this);
|
|
1586
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1587
|
+
}
|
|
1588
|
+
get contain() {
|
|
1589
|
+
return this.props.contain;
|
|
1590
|
+
}
|
|
1591
|
+
set contain(v) {
|
|
1592
|
+
if (this.props.contain === v)
|
|
1593
|
+
return;
|
|
1594
|
+
this.props.contain = v;
|
|
1595
|
+
syncContainTextNodeTracking(this);
|
|
1596
|
+
updateNodeStyles(this);
|
|
1597
|
+
scheduleUpdateDOMTextMeasurement(this);
|
|
1598
|
+
}
|
|
1599
|
+
get verticalAlign() {
|
|
1600
|
+
return this.props.verticalAlign;
|
|
1601
|
+
}
|
|
1602
|
+
set verticalAlign(v) {
|
|
1603
|
+
this.props.verticalAlign = v;
|
|
1604
|
+
updateNodeStyles(this);
|
|
1605
|
+
}
|
|
1606
|
+
get textRendererOverride() {
|
|
1607
|
+
return this.props.textRendererOverride;
|
|
1608
|
+
}
|
|
1609
|
+
set textRendererOverride(v) {
|
|
1610
|
+
this.props.textRendererOverride = v;
|
|
1611
|
+
updateNodeStyles(this);
|
|
1612
|
+
}
|
|
1613
|
+
get offsetY() {
|
|
1614
|
+
return this.props.offsetY;
|
|
1615
|
+
}
|
|
1616
|
+
set offsetY(v) {
|
|
1617
|
+
this.props.offsetY = v;
|
|
1618
|
+
updateNodeStyles(this);
|
|
1619
|
+
}
|
|
1620
|
+
get wordBreak() {
|
|
1621
|
+
return this.props.wordBreak;
|
|
1622
|
+
}
|
|
1623
|
+
set wordBreak(v) {
|
|
1624
|
+
this.props.wordBreak = v;
|
|
1625
|
+
updateNodeStyles(this);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
function updateRootPosition() {
|
|
1629
|
+
let { canvas, settings } = this;
|
|
1630
|
+
let rect = canvas.getBoundingClientRect();
|
|
1631
|
+
let top = document.documentElement.scrollTop + rect.top;
|
|
1632
|
+
let left = document.documentElement.scrollLeft + rect.left;
|
|
1633
|
+
let dpr = settings.deviceLogicalPixelRatio ?? 1;
|
|
1634
|
+
let height = Math.ceil(settings.appHeight ?? 1080 / dpr);
|
|
1635
|
+
let width = Math.ceil(settings.appWidth ?? 1920 / dpr);
|
|
1636
|
+
this.root.div.style.left = `${left}px`;
|
|
1637
|
+
this.root.div.style.top = `${top}px`;
|
|
1638
|
+
this.root.div.style.width = `${width}px`;
|
|
1639
|
+
this.root.div.style.height = `${height}px`;
|
|
1640
|
+
this.root.div.style.position = 'absolute';
|
|
1641
|
+
this.root.div.style.transformOrigin = '0 0 0';
|
|
1642
|
+
this.root.div.style.transform = `scale(${dpr}, ${dpr})`;
|
|
1643
|
+
this.root.div.style.overflow = 'hidden';
|
|
1644
|
+
}
|
|
1645
|
+
export class DOMRendererMain {
|
|
1646
|
+
settings;
|
|
1647
|
+
root;
|
|
1648
|
+
canvas;
|
|
1649
|
+
stage;
|
|
1650
|
+
eventListeners = new Map();
|
|
1651
|
+
constructor(settings, rawTarget) {
|
|
1652
|
+
this.settings = settings;
|
|
1653
|
+
let target;
|
|
1654
|
+
if (typeof rawTarget === 'string') {
|
|
1655
|
+
let result = document.getElementById(rawTarget);
|
|
1656
|
+
if (result instanceof HTMLElement) {
|
|
1657
|
+
target = result;
|
|
1658
|
+
}
|
|
1659
|
+
else {
|
|
1660
|
+
throw new Error(`Target #${rawTarget} not found`);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
else {
|
|
1664
|
+
target = rawTarget;
|
|
1665
|
+
}
|
|
1666
|
+
let canvas = document.body.appendChild(document.createElement('canvas'));
|
|
1667
|
+
canvas.style.position = 'absolute';
|
|
1668
|
+
canvas.style.top = '0';
|
|
1669
|
+
canvas.style.left = '0';
|
|
1670
|
+
canvas.style.width = '100vw';
|
|
1671
|
+
canvas.style.height = '100vh';
|
|
1672
|
+
this.canvas = canvas;
|
|
1673
|
+
this.stage = {
|
|
1674
|
+
root: null,
|
|
1675
|
+
renderer: {
|
|
1676
|
+
mode: 'canvas',
|
|
1677
|
+
boundsMargin: settings.boundsMargin,
|
|
1678
|
+
},
|
|
1679
|
+
shManager: {
|
|
1680
|
+
registerShaderType() { },
|
|
1681
|
+
},
|
|
1682
|
+
animationManager: {
|
|
1683
|
+
registerAnimation(anim) {
|
|
1684
|
+
console.log('registerAnimation', anim);
|
|
1685
|
+
},
|
|
1686
|
+
unregisterAnimation(anim) {
|
|
1687
|
+
console.log('unregisterAnimation', anim);
|
|
1688
|
+
},
|
|
1689
|
+
},
|
|
1690
|
+
loadFont: async () => { },
|
|
1691
|
+
cleanup() { },
|
|
1692
|
+
};
|
|
1693
|
+
this.root = new DOMNode(this.stage, resolveNodeDefaults({
|
|
1694
|
+
w: settings.appWidth ?? 1920,
|
|
1695
|
+
h: settings.appHeight ?? 1080,
|
|
1696
|
+
shader: defaultShader,
|
|
1697
|
+
zIndex: 1,
|
|
1698
|
+
}));
|
|
1699
|
+
this.stage.root = this.root;
|
|
1700
|
+
target.appendChild(this.root.div);
|
|
1701
|
+
if (Config.fontSettings.fontFamily) {
|
|
1702
|
+
this.root.div.style.fontFamily = Config.fontSettings.fontFamily;
|
|
1703
|
+
}
|
|
1704
|
+
if (Config.fontSettings.fontSize) {
|
|
1705
|
+
this.root.div.style.fontSize = Config.fontSettings.fontSize + 'px';
|
|
1706
|
+
}
|
|
1707
|
+
if (Config.fontSettings.lineHeight) {
|
|
1708
|
+
this.root.div.style.lineHeight = Config.fontSettings.lineHeight + 'px';
|
|
1709
|
+
}
|
|
1710
|
+
else {
|
|
1711
|
+
this.root.div.style.lineHeight = '1.2';
|
|
1712
|
+
}
|
|
1713
|
+
if (Config.fontSettings.fontWeight) {
|
|
1714
|
+
if (typeof Config.fontSettings.fontWeight === 'number') {
|
|
1715
|
+
this.root.div.style.fontWeight = Config.fontSettings.fontWeight + 'px';
|
|
1716
|
+
}
|
|
1717
|
+
else {
|
|
1718
|
+
this.root.div.style.fontWeight = Config.fontSettings.fontWeight;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
updateRootPosition.call(this);
|
|
1722
|
+
new MutationObserver(updateRootPosition.bind(this)).observe(this.canvas, {
|
|
1723
|
+
attributes: true,
|
|
1724
|
+
});
|
|
1725
|
+
new ResizeObserver(updateRootPosition.bind(this)).observe(this.canvas);
|
|
1726
|
+
window.addEventListener('resize', updateRootPosition.bind(this));
|
|
1727
|
+
}
|
|
1728
|
+
removeAllListeners() {
|
|
1729
|
+
if (this.eventListeners.size === 0)
|
|
1730
|
+
return;
|
|
1731
|
+
this.eventListeners.forEach((listeners) => listeners.clear());
|
|
1732
|
+
this.eventListeners.clear();
|
|
1733
|
+
}
|
|
1734
|
+
once(event, listener) {
|
|
1735
|
+
const wrappedListener = (target, data) => {
|
|
1736
|
+
this.off(event, wrappedListener);
|
|
1737
|
+
listener(target, data);
|
|
1738
|
+
};
|
|
1739
|
+
this.on(event, wrappedListener);
|
|
1740
|
+
}
|
|
1741
|
+
on(name, callback) {
|
|
1742
|
+
let listeners = this.eventListeners.get(name);
|
|
1743
|
+
if (!listeners) {
|
|
1744
|
+
listeners = new Set();
|
|
1745
|
+
this.eventListeners.set(name, listeners);
|
|
1746
|
+
}
|
|
1747
|
+
listeners.add(callback);
|
|
1748
|
+
}
|
|
1749
|
+
off(event, listener) {
|
|
1750
|
+
const listeners = this.eventListeners.get(event);
|
|
1751
|
+
if (listeners) {
|
|
1752
|
+
listeners.delete(listener);
|
|
1753
|
+
if (listeners.size === 0) {
|
|
1754
|
+
this.eventListeners.delete(event);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
emit(event, targetOrData, maybeData) {
|
|
1759
|
+
const listeners = this.eventListeners.get(event);
|
|
1760
|
+
if (!listeners || listeners.size === 0) {
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
const hasExplicitTarget = arguments.length === 3;
|
|
1764
|
+
const target = hasExplicitTarget ? targetOrData : this.root;
|
|
1765
|
+
const data = hasExplicitTarget ? maybeData : targetOrData;
|
|
1766
|
+
for (const listener of Array.from(listeners)) {
|
|
1767
|
+
try {
|
|
1768
|
+
listener(target, data);
|
|
1769
|
+
}
|
|
1770
|
+
catch (error) {
|
|
1771
|
+
console.error(`Error in listener for event "${event}"`, error);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
createNode(props) {
|
|
1776
|
+
return new DOMNode(this.stage, resolveNodeDefaults(props));
|
|
1777
|
+
}
|
|
1778
|
+
createTextNode(props) {
|
|
1779
|
+
return new DOMText(this.stage, resolveTextNodeDefaults(props));
|
|
1780
|
+
}
|
|
1781
|
+
/** TODO: restore this */
|
|
1782
|
+
// createShader<ShType extends keyof ShaderMap>(
|
|
1783
|
+
// shType: ShType,
|
|
1784
|
+
// props?: OptionalShaderProps<ShType>,
|
|
1785
|
+
// ): InstanceType<lng.ShaderMap[ShType]> {
|
|
1786
|
+
// return { shaderType: shType, props, program: {} } as InstanceType<
|
|
1787
|
+
// lng.ShaderMap[ShType]
|
|
1788
|
+
// >;
|
|
1789
|
+
// }
|
|
1790
|
+
createShader(...args) {
|
|
1791
|
+
const [shaderType, props] = args;
|
|
1792
|
+
return {
|
|
1793
|
+
// @ts-ignore
|
|
1794
|
+
shaderType,
|
|
1795
|
+
props,
|
|
1796
|
+
program: {},
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
createTexture(textureType, props) {
|
|
1800
|
+
let type = lng.TextureType.generic;
|
|
1801
|
+
switch (textureType) {
|
|
1802
|
+
case 'SubTexture':
|
|
1803
|
+
type = lng.TextureType.subTexture;
|
|
1804
|
+
break;
|
|
1805
|
+
case 'ImageTexture':
|
|
1806
|
+
type = lng.TextureType.image;
|
|
1807
|
+
break;
|
|
1808
|
+
case 'ColorTexture':
|
|
1809
|
+
type = lng.TextureType.color;
|
|
1810
|
+
break;
|
|
1811
|
+
case 'NoiseTexture':
|
|
1812
|
+
type = lng.TextureType.noise;
|
|
1813
|
+
break;
|
|
1814
|
+
case 'RenderTexture':
|
|
1815
|
+
type = lng.TextureType.renderToTexture;
|
|
1816
|
+
break;
|
|
1817
|
+
}
|
|
1818
|
+
return { type, props };
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
export function loadFontToDom(font) {
|
|
1822
|
+
// fontFamily: string;
|
|
1823
|
+
// metrics?: FontMetrics;
|
|
1824
|
+
// fontUrl?: string;
|
|
1825
|
+
// atlasUrl?: string;
|
|
1826
|
+
// atlasDataUrl?: string;
|
|
1827
|
+
if (typeof document === 'undefined' ||
|
|
1828
|
+
!('fonts' in document) ||
|
|
1829
|
+
typeof FontFace === 'undefined' ||
|
|
1830
|
+
!font.fontUrl) {
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
const fontFace = new FontFace(font.fontFamily, `url(${font.fontUrl})`);
|
|
1834
|
+
const fontSet = document.fonts;
|
|
1835
|
+
fontSet.add?.(fontFace);
|
|
1836
|
+
fontFace
|
|
1837
|
+
.load()
|
|
1838
|
+
.then(scheduleContainTextNodesMeasurement)
|
|
1839
|
+
.catch(() => { });
|
|
1840
|
+
}
|
|
1841
|
+
export function isDomRenderer(r) {
|
|
1842
|
+
return r instanceof DOMRendererMain;
|
|
1843
|
+
}
|
|
1844
|
+
//# sourceMappingURL=domRenderer.js.map
|