@lightningtv/solid 3.0.0-2 → 3.0.0-21

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.
Files changed (206) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -0
  3. package/dist/src/activeElement.d.ts +1 -1
  4. package/dist/src/core/animation.d.ts +35 -0
  5. package/dist/src/core/animation.js +120 -0
  6. package/dist/src/core/animation.js.map +1 -0
  7. package/dist/src/core/config.d.ts +47 -0
  8. package/dist/src/core/config.js +23 -0
  9. package/dist/src/core/config.js.map +1 -0
  10. package/dist/src/core/domRenderer.d.ts +117 -0
  11. package/dist/src/core/domRenderer.js +1160 -0
  12. package/dist/src/core/domRenderer.js.map +1 -0
  13. package/dist/src/core/elementNode.d.ts +209 -0
  14. package/dist/src/core/elementNode.js +829 -0
  15. package/dist/src/core/elementNode.js.map +1 -0
  16. package/dist/src/core/flex.d.ts +2 -0
  17. package/dist/src/core/flex.js +243 -0
  18. package/dist/src/core/flex.js.map +1 -0
  19. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  20. package/dist/src/core/focusKeyTypes.js +2 -0
  21. package/dist/src/core/focusKeyTypes.js.map +1 -0
  22. package/dist/src/core/focusManager.d.ts +13 -0
  23. package/dist/src/core/focusManager.js +269 -0
  24. package/dist/src/core/focusManager.js.map +1 -0
  25. package/dist/src/core/index.d.ts +12 -0
  26. package/dist/src/core/index.js +12 -0
  27. package/dist/src/core/index.js.map +1 -0
  28. package/dist/src/core/intrinsicTypes.d.ts +90 -0
  29. package/dist/src/core/intrinsicTypes.js +2 -0
  30. package/dist/src/core/intrinsicTypes.js.map +1 -0
  31. package/dist/src/core/lightningInit.d.ts +89 -0
  32. package/dist/src/core/lightningInit.js +26 -0
  33. package/dist/src/core/lightningInit.js.map +1 -0
  34. package/dist/src/core/nodeTypes.d.ts +6 -0
  35. package/dist/src/core/nodeTypes.js +6 -0
  36. package/dist/src/core/nodeTypes.js.map +1 -0
  37. package/dist/src/core/shaders.d.ts +51 -0
  38. package/dist/src/core/shaders.js +446 -0
  39. package/dist/src/core/shaders.js.map +1 -0
  40. package/dist/src/core/states.d.ts +12 -0
  41. package/dist/src/core/states.js +84 -0
  42. package/dist/src/core/states.js.map +1 -0
  43. package/dist/src/core/timings.d.ts +36 -0
  44. package/dist/src/core/timings.js +199 -0
  45. package/dist/src/core/timings.js.map +1 -0
  46. package/dist/src/core/utils.d.ts +39 -0
  47. package/dist/src/core/utils.js +164 -0
  48. package/dist/src/core/utils.js.map +1 -0
  49. package/dist/src/devtools/index.d.ts +1 -1
  50. package/dist/src/devtools/index.js +1 -1
  51. package/dist/src/devtools/index.js.map +1 -1
  52. package/dist/src/index.d.ts +3 -3
  53. package/dist/src/index.js +1 -1
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/jsx-runtime.d.ts +1 -3
  56. package/dist/src/primitives/Column.jsx +9 -10
  57. package/dist/src/primitives/Column.jsx.map +1 -1
  58. package/dist/src/primitives/FPSCounter.jsx +14 -1
  59. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  60. package/dist/src/primitives/Grid.d.ts +15 -6
  61. package/dist/src/primitives/Grid.jsx +35 -22
  62. package/dist/src/primitives/Grid.jsx.map +1 -1
  63. package/dist/src/primitives/Image.d.ts +8 -0
  64. package/dist/src/primitives/Image.jsx +24 -0
  65. package/dist/src/primitives/Image.jsx.map +1 -0
  66. package/dist/src/primitives/KeepAlive.d.ts +30 -0
  67. package/dist/src/primitives/KeepAlive.jsx +77 -0
  68. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  69. package/dist/src/primitives/Lazy.d.ts +8 -7
  70. package/dist/src/primitives/Lazy.jsx +52 -23
  71. package/dist/src/primitives/Lazy.jsx.map +1 -1
  72. package/dist/src/primitives/Marquee.d.ts +64 -0
  73. package/dist/src/primitives/Marquee.jsx +86 -0
  74. package/dist/src/primitives/Marquee.jsx.map +1 -0
  75. package/dist/src/primitives/Preserve.d.ts +4 -0
  76. package/dist/src/primitives/Preserve.jsx +11 -0
  77. package/dist/src/primitives/Preserve.jsx.map +1 -0
  78. package/dist/src/primitives/Row.jsx +9 -10
  79. package/dist/src/primitives/Row.jsx.map +1 -1
  80. package/dist/src/primitives/Suspense.d.ts +22 -0
  81. package/dist/src/primitives/Suspense.jsx +33 -0
  82. package/dist/src/primitives/Suspense.jsx.map +1 -0
  83. package/dist/src/primitives/Virtual.d.ts +18 -0
  84. package/dist/src/primitives/Virtual.jsx +434 -0
  85. package/dist/src/primitives/Virtual.jsx.map +1 -0
  86. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  87. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  88. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  89. package/dist/src/primitives/VirtualList.d.ts +11 -0
  90. package/dist/src/primitives/VirtualList.jsx +96 -0
  91. package/dist/src/primitives/VirtualList.jsx.map +1 -0
  92. package/dist/src/primitives/VirtualRow.d.ts +13 -0
  93. package/dist/src/primitives/VirtualRow.jsx +97 -0
  94. package/dist/src/primitives/VirtualRow.jsx.map +1 -0
  95. package/dist/src/primitives/Visible.d.ts +0 -1
  96. package/dist/src/primitives/Visible.jsx +1 -1
  97. package/dist/src/primitives/Visible.jsx.map +1 -1
  98. package/dist/src/primitives/announcer/announcer.d.ts +2 -0
  99. package/dist/src/primitives/announcer/announcer.js +7 -5
  100. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  101. package/dist/src/primitives/announcer/index.d.ts +5 -1
  102. package/dist/src/primitives/announcer/index.js +8 -2
  103. package/dist/src/primitives/announcer/index.js.map +1 -1
  104. package/dist/src/primitives/announcer/speech.d.ts +2 -2
  105. package/dist/src/primitives/announcer/speech.js +157 -28
  106. package/dist/src/primitives/announcer/speech.js.map +1 -1
  107. package/dist/src/primitives/createFocusStack.d.ts +4 -4
  108. package/dist/src/primitives/createFocusStack.jsx +15 -6
  109. package/dist/src/primitives/createFocusStack.jsx.map +1 -1
  110. package/dist/src/primitives/createTag.d.ts +8 -0
  111. package/dist/src/primitives/createTag.jsx +20 -0
  112. package/dist/src/primitives/createTag.jsx.map +1 -0
  113. package/dist/src/primitives/index.d.ts +14 -4
  114. package/dist/src/primitives/index.js +13 -3
  115. package/dist/src/primitives/index.js.map +1 -1
  116. package/dist/src/primitives/types.d.ts +5 -2
  117. package/dist/src/primitives/useFocusManager.d.ts +2 -2
  118. package/dist/src/primitives/useFocusManager.js +2 -2
  119. package/dist/src/primitives/useFocusManager.js.map +1 -1
  120. package/dist/src/primitives/useHold.d.ts +27 -0
  121. package/dist/src/primitives/useHold.js +54 -0
  122. package/dist/src/primitives/useHold.js.map +1 -0
  123. package/dist/src/primitives/useMouse.d.ts +18 -2
  124. package/dist/src/primitives/useMouse.js +171 -47
  125. package/dist/src/primitives/useMouse.js.map +1 -1
  126. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -4
  127. package/dist/src/primitives/utils/chainFunctions.js +14 -3
  128. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  129. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  130. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  131. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  132. package/dist/src/primitives/utils/createSpriteMap.d.ts +2 -2
  133. package/dist/src/primitives/utils/createSpriteMap.js +1 -1
  134. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
  135. package/dist/src/primitives/utils/handleNavigation.d.ts +79 -5
  136. package/dist/src/primitives/utils/handleNavigation.js +242 -69
  137. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  138. package/dist/src/primitives/utils/withScrolling.d.ts +14 -2
  139. package/dist/src/primitives/utils/withScrolling.js +66 -7
  140. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  141. package/dist/src/render.d.ts +8 -7
  142. package/dist/src/render.js +5 -1
  143. package/dist/src/render.js.map +1 -1
  144. package/dist/src/solidOpts.d.ts +1 -7
  145. package/dist/src/solidOpts.js +32 -16
  146. package/dist/src/solidOpts.js.map +1 -1
  147. package/dist/src/types.d.ts +1 -13
  148. package/dist/src/universal.d.ts +25 -0
  149. package/dist/src/universal.js +232 -0
  150. package/dist/src/universal.js.map +1 -0
  151. package/dist/src/utils.d.ts +3 -1
  152. package/dist/src/utils.js +9 -1
  153. package/dist/src/utils.js.map +1 -1
  154. package/dist/tsconfig.tsbuildinfo +1 -1
  155. package/jsx-runtime.d.ts +2 -4
  156. package/package.json +17 -15
  157. package/src/activeElement.ts +1 -1
  158. package/src/core/animation.ts +183 -0
  159. package/src/core/config.ts +77 -0
  160. package/src/core/domRenderer.ts +1308 -0
  161. package/src/core/elementNode.ts +1198 -0
  162. package/src/core/flex.ts +284 -0
  163. package/src/core/focusKeyTypes.ts +87 -0
  164. package/src/core/focusManager.ts +359 -0
  165. package/src/core/index.ts +13 -0
  166. package/src/core/intrinsicTypes.ts +199 -0
  167. package/src/core/lightningInit.ts +147 -0
  168. package/src/core/nodeTypes.ts +6 -0
  169. package/src/core/shaders.ts +567 -0
  170. package/src/core/states.ts +91 -0
  171. package/src/core/timings.ts +261 -0
  172. package/src/core/utils.ts +222 -0
  173. package/src/devtools/index.ts +1 -1
  174. package/src/index.ts +3 -3
  175. package/src/primitives/Column.tsx +10 -12
  176. package/src/primitives/FPSCounter.tsx +15 -1
  177. package/src/primitives/Grid.tsx +57 -33
  178. package/src/primitives/Image.tsx +36 -0
  179. package/src/primitives/KeepAlive.tsx +124 -0
  180. package/src/primitives/Lazy.tsx +66 -37
  181. package/src/primitives/Marquee.tsx +149 -0
  182. package/src/primitives/Preserve.tsx +18 -0
  183. package/src/primitives/Row.tsx +13 -14
  184. package/src/primitives/Suspense.tsx +39 -0
  185. package/src/primitives/Virtual.tsx +478 -0
  186. package/src/primitives/VirtualGrid.tsx +220 -0
  187. package/src/primitives/Visible.tsx +1 -2
  188. package/src/primitives/announcer/announcer.ts +16 -10
  189. package/src/primitives/announcer/index.ts +12 -2
  190. package/src/primitives/announcer/speech.ts +188 -27
  191. package/src/primitives/createFocusStack.tsx +18 -7
  192. package/src/primitives/createTag.tsx +31 -0
  193. package/src/primitives/index.ts +18 -4
  194. package/src/primitives/types.ts +12 -2
  195. package/src/primitives/useFocusManager.ts +3 -3
  196. package/src/primitives/useHold.ts +69 -0
  197. package/src/primitives/useMouse.ts +306 -67
  198. package/src/primitives/utils/chainFunctions.ts +40 -9
  199. package/src/primitives/utils/createBlurredImage.ts +366 -0
  200. package/src/primitives/utils/createSpriteMap.ts +6 -4
  201. package/src/primitives/utils/handleNavigation.ts +300 -84
  202. package/src/primitives/utils/withScrolling.ts +91 -18
  203. package/src/render.ts +10 -8
  204. package/src/solidOpts.ts +31 -24
  205. package/src/types.ts +1 -15
  206. package/src/utils.ts +11 -1
@@ -0,0 +1,1160 @@
1
+ /*
2
+
3
+ Experimental DOM renderer
4
+
5
+ */
6
+ import * as lng from '@lightningjs/renderer';
7
+ import { EventEmitter } from '@lightningjs/renderer/utils';
8
+ import { Config } from './config.js';
9
+ import { isFunc } from './utils.js';
10
+ const colorToRgba = (c) => `rgba(${(c >> 24) & 0xff},${(c >> 16) & 0xff},${(c >> 8) & 0xff},${(c & 0xff) / 255})`;
11
+ function applyEasing(easing, progress) {
12
+ if (isFunc(easing)) {
13
+ return easing(progress);
14
+ }
15
+ switch (easing) {
16
+ case 'linear':
17
+ default:
18
+ return progress;
19
+ case 'ease-in':
20
+ return progress * progress;
21
+ case 'ease-out':
22
+ return progress * (2 - progress);
23
+ case 'ease-in-out':
24
+ return progress < 0.5
25
+ ? 2 * progress * progress
26
+ : -1 + (4 - 2 * progress) * progress;
27
+ }
28
+ }
29
+ function interpolate(start, end, t) {
30
+ return start + (end - start) * t;
31
+ }
32
+ function interpolateColor(start, end, t) {
33
+ return ((interpolate((start >> 24) & 0xff, (end >> 24) & 0xff, t) << 24) |
34
+ (interpolate((start >> 16) & 0xff, (end >> 16) & 0xff, t) << 16) |
35
+ (interpolate((start >> 8) & 0xff, (end >> 8) & 0xff, t) << 8) |
36
+ interpolate(start & 0xff, end & 0xff, t));
37
+ }
38
+ function interpolateProp(name, start, end, t) {
39
+ return name.startsWith('color')
40
+ ? interpolateColor(start, end, t)
41
+ : interpolate(start, end, t);
42
+ }
43
+ /*
44
+ Animations
45
+ */
46
+ let animationTasks = [];
47
+ let animationFrameRequested = false;
48
+ function requestAnimationUpdate() {
49
+ if (!animationFrameRequested && animationTasks.length > 0) {
50
+ animationFrameRequested = true;
51
+ requestAnimationFrame(updateAnimations);
52
+ }
53
+ }
54
+ function updateAnimations(time) {
55
+ animationFrameRequested = false;
56
+ /*
57
+ tasks are iterated in insertion order
58
+ so that the later task will override the earlier ones
59
+ */
60
+ for (let i = 0; i < animationTasks.length; i++) {
61
+ let task = animationTasks[i];
62
+ if (task.pausedTime != null)
63
+ continue;
64
+ let elapsed = time - task.timeStart;
65
+ // Still in delay period
66
+ if (elapsed < task.settings.delay) {
67
+ requestAnimationUpdate();
68
+ continue;
69
+ }
70
+ let activeTime = elapsed - task.settings.delay;
71
+ if (activeTime >= task.settings.duration) {
72
+ // Start next iteration
73
+ if (task.settings.loop || task.iteration < task.settings.repeat - 1) {
74
+ task.iteration++;
75
+ task.timeStart = time - task.settings.delay;
76
+ requestAnimationUpdate();
77
+ }
78
+ // Animation complete
79
+ else {
80
+ Object.assign(task.node.props, task.propsEnd);
81
+ updateNodeStyles(task.node);
82
+ task.stop();
83
+ i--;
84
+ }
85
+ continue;
86
+ }
87
+ /*
88
+ Update props and styles
89
+ */
90
+ let t = activeTime / task.settings.duration;
91
+ t = applyEasing(task.settings.easing, t);
92
+ for (let prop in task.propsEnd) {
93
+ let start = task.propsStart[prop];
94
+ let end = task.propsEnd[prop];
95
+ task.node.props[prop] = interpolateProp(prop, start, end, t);
96
+ }
97
+ updateNodeStyles(task.node);
98
+ }
99
+ requestAnimationUpdate();
100
+ }
101
+ class AnimationController {
102
+ node;
103
+ state = 'paused';
104
+ stopPromise = null;
105
+ stopResolve = null;
106
+ propsStart = {};
107
+ propsEnd = {};
108
+ timeStart = performance.now();
109
+ timeEnd;
110
+ settings;
111
+ iteration = 0;
112
+ pausedTime = null;
113
+ constructor(node, props, rawSettings) {
114
+ this.node = node;
115
+ this.settings = {
116
+ duration: rawSettings.duration ?? 300,
117
+ delay: rawSettings.delay ?? 0,
118
+ easing: rawSettings.easing ?? 'linear',
119
+ loop: rawSettings.loop ?? false,
120
+ repeat: rawSettings.repeat ?? 1,
121
+ stopMethod: false,
122
+ };
123
+ this.timeEnd =
124
+ this.timeStart + this.settings.delay + this.settings.duration;
125
+ for (let [prop, value] of Object.entries(props)) {
126
+ if (value != null && typeof value === 'number') {
127
+ this.propsStart[prop] = node.props[prop];
128
+ this.propsEnd[prop] = value;
129
+ }
130
+ }
131
+ animationTasks.push(this);
132
+ }
133
+ start() {
134
+ if (this.pausedTime != null) {
135
+ this.timeStart += performance.now() - this.pausedTime;
136
+ this.pausedTime = null;
137
+ }
138
+ else {
139
+ this.timeStart = performance.now();
140
+ }
141
+ this.state = 'running';
142
+ requestAnimationUpdate();
143
+ return this;
144
+ }
145
+ pause() {
146
+ this.pausedTime = performance.now();
147
+ this.state = 'paused';
148
+ return this;
149
+ }
150
+ stop() {
151
+ let index = animationTasks.indexOf(this);
152
+ if (index !== -1) {
153
+ animationTasks.splice(index, 1);
154
+ }
155
+ this.state = 'stopped';
156
+ if (this.stopResolve) {
157
+ this.stopResolve();
158
+ this.stopResolve = null;
159
+ this.stopPromise = null;
160
+ }
161
+ return this;
162
+ }
163
+ restore() {
164
+ return this;
165
+ }
166
+ waitUntilStopped() {
167
+ this.stopPromise ??= new Promise((resolve) => {
168
+ this.stopResolve = resolve;
169
+ });
170
+ return this.stopPromise;
171
+ }
172
+ on() {
173
+ return this;
174
+ }
175
+ once() {
176
+ return this;
177
+ }
178
+ off() {
179
+ return this;
180
+ }
181
+ emit() {
182
+ return this;
183
+ }
184
+ }
185
+ function animate(props, settings) {
186
+ return new AnimationController(this, props, settings);
187
+ }
188
+ /*
189
+ Node Properties
190
+ */
191
+ let elMap = new WeakMap();
192
+ function updateNodeParent(node) {
193
+ if (node.parent != null) {
194
+ elMap.get(node.parent).appendChild(node.div);
195
+ }
196
+ }
197
+ function getNodeLineHeight(props) {
198
+ return (props.lineHeight ?? Config.fontSettings.lineHeight ?? 1.2 * props.fontSize);
199
+ }
200
+ function updateNodeStyles(node) {
201
+ let { props } = node;
202
+ let style = `position: absolute; z-index: ${props.zIndex};`;
203
+ if (props.alpha !== 1)
204
+ style += `opacity: ${props.alpha};`;
205
+ if (props.clipping) {
206
+ style += `overflow: hidden;`;
207
+ }
208
+ // Transform
209
+ {
210
+ let transform = '';
211
+ let { x, y } = props;
212
+ if (props.mountX != null) {
213
+ x -= (props.w ?? 0) * props.mountX;
214
+ }
215
+ if (props.mountY != null) {
216
+ y -= (props.h ?? 0) * props.mountY;
217
+ }
218
+ if (x !== 0)
219
+ transform += `translateX(${x}px)`;
220
+ if (y !== 0)
221
+ transform += `translateY(${y}px)`;
222
+ if (props.rotation !== 0)
223
+ transform += `rotate(${props.rotation}rad)`;
224
+ if (props.scale !== 1 && props.scale != null) {
225
+ transform += `scale(${props.scale})`;
226
+ }
227
+ else {
228
+ if (props.scaleX !== 1)
229
+ transform += `scaleX(${props.scaleX})`;
230
+ if (props.scaleY !== 1)
231
+ transform += `scaleY(${props.scaleY})`;
232
+ }
233
+ if (transform.length > 0) {
234
+ style += `transform: ${transform};`;
235
+ }
236
+ }
237
+ // <Text>
238
+ if (node instanceof DOMText) {
239
+ let textProps = node.props;
240
+ if (textProps.color != null && textProps.color !== 0) {
241
+ style += `color: ${colorToRgba(textProps.color)};`;
242
+ }
243
+ if (textProps.fontFamily) {
244
+ style += `font-family: ${textProps.fontFamily};`;
245
+ }
246
+ if (textProps.fontSize) {
247
+ style += `font-size: ${textProps.fontSize}px;`;
248
+ }
249
+ if (textProps.fontStyle !== 'normal') {
250
+ style += `font-style: ${textProps.fontStyle};`;
251
+ }
252
+ if (textProps.fontWeight !== 'normal') {
253
+ style += `font-weight: ${textProps.fontWeight};`;
254
+ }
255
+ if (textProps.lineHeight != null) {
256
+ style += `line-height: ${textProps.lineHeight}px;`;
257
+ }
258
+ if (textProps.letterSpacing) {
259
+ style += `letter-spacing: ${textProps.letterSpacing}px;`;
260
+ }
261
+ if (textProps.textAlign !== 'left') {
262
+ style += `text-align: ${textProps.textAlign};`;
263
+ }
264
+ let maxLines = textProps.maxLines || Infinity;
265
+ switch (textProps.contain) {
266
+ case 'width':
267
+ style += `width: ${props.w}px; overflow: hidden;`;
268
+ break;
269
+ case 'both': {
270
+ let lineHeight = getNodeLineHeight(textProps);
271
+ maxLines = Math.min(maxLines, Math.floor(props.h / lineHeight));
272
+ maxLines = Math.max(1, maxLines);
273
+ let height = maxLines * lineHeight;
274
+ style += `width: ${props.w}px; height: ${height}px; overflow: hidden;`;
275
+ break;
276
+ }
277
+ case 'none':
278
+ style += `width: max-content;`;
279
+ break;
280
+ }
281
+ if (maxLines !== Infinity) {
282
+ // https://stackoverflow.com/a/13924997
283
+ style += `display: -webkit-box;
284
+ overflow: hidden;
285
+ -webkit-line-clamp: ${maxLines};
286
+ line-clamp: ${maxLines};
287
+ -webkit-box-orient: vertical;`;
288
+ }
289
+ // if (node.overflowSuffix) style += `overflow-suffix: ${node.overflowSuffix};`
290
+ // if (node.verticalAlign) style += `vertical-align: ${node.verticalAlign};`
291
+ scheduleUpdateDOMTextMeasurement(node);
292
+ }
293
+ // <Node>
294
+ else {
295
+ if (props.w !== 0)
296
+ style += `width: ${props.w}px;`;
297
+ if (props.h !== 0)
298
+ style += `height: ${props.h}px;`;
299
+ let vGradient = props.colorBottom !== props.colorTop
300
+ ? `linear-gradient(to bottom, ${colorToRgba(props.colorTop)}, ${colorToRgba(props.colorBottom)})`
301
+ : null;
302
+ let hGradient = props.colorLeft !== props.colorRight
303
+ ? `linear-gradient(to right, ${colorToRgba(props.colorLeft)}, ${colorToRgba(props.colorRight)})`
304
+ : null;
305
+ let gradient = vGradient && hGradient
306
+ ? `${vGradient}, ${hGradient}`
307
+ : vGradient || hGradient;
308
+ let srcImg = null;
309
+ let srcPos = null;
310
+ if (props.texture != null &&
311
+ props.texture.type === lng.TextureType.subTexture) {
312
+ srcPos = props.texture.props;
313
+ srcImg = `url(${props.texture.props.texture.props.src})`;
314
+ }
315
+ else if (props.src) {
316
+ srcImg = `url(${props.src})`;
317
+ }
318
+ let bgStyle = '';
319
+ let borderStyle = '';
320
+ let radiusStyle = '';
321
+ let maskStyle = '';
322
+ if (srcImg) {
323
+ if (props.color !== 0xffffffff && props.color !== 0x00000000) {
324
+ // use image as a mask
325
+ bgStyle += `background-color: ${colorToRgba(props.color)}; background-blend-mode: multiply;`;
326
+ maskStyle += `mask-image: ${srcImg};`;
327
+ if (srcPos !== null) {
328
+ maskStyle += `mask-position: -${srcPos.x}px -${srcPos.y}px;`;
329
+ }
330
+ else {
331
+ maskStyle += `mask-size: 100% 100%;`;
332
+ }
333
+ }
334
+ else if (gradient) {
335
+ // use gradient as a mask
336
+ maskStyle += `mask-image: ${gradient};`;
337
+ }
338
+ bgStyle += `background-image: ${srcImg};`;
339
+ bgStyle += `background-repeat: no-repeat;`;
340
+ if (props.textureOptions.resizeMode?.type) {
341
+ bgStyle += `background-size: ${props.textureOptions.resizeMode.type}; background-position: center;`;
342
+ }
343
+ else if (srcPos !== null) {
344
+ bgStyle += `background-position: -${srcPos.x}px -${srcPos.y}px;`;
345
+ }
346
+ else {
347
+ bgStyle += 'background-size: 100% 100%;';
348
+ }
349
+ if (maskStyle !== '') {
350
+ bgStyle += maskStyle;
351
+ }
352
+ // separate layers are needed for the mask
353
+ if (maskStyle !== '' && node.divBg == null) {
354
+ node.div.appendChild((node.divBg = document.createElement('div')));
355
+ node.div.appendChild((node.divBorder = document.createElement('div')));
356
+ }
357
+ }
358
+ else if (gradient) {
359
+ bgStyle += `background-image: ${gradient};`;
360
+ bgStyle += `background-repeat: no-repeat;`;
361
+ bgStyle += `background-size: 100% 100%;`;
362
+ }
363
+ else if (props.color !== 0) {
364
+ bgStyle += `background-color: ${colorToRgba(props.color)};`;
365
+ }
366
+ if (props.shader?.props != null) {
367
+ let shader = props.shader.props;
368
+ let borderWidth = shader['border-w'];
369
+ let borderColor = shader['border-color'];
370
+ let borderGap = shader['border-gap'] ?? 0;
371
+ let borderInset = shader['border-inset'] ?? true;
372
+ let radius = shader['radius'];
373
+ // Border
374
+ if (typeof borderWidth === 'number' &&
375
+ borderWidth !== 0 &&
376
+ typeof borderColor === 'number' &&
377
+ borderColor !== 0) {
378
+ // Handle inset borders by making gap negative
379
+ let gap = borderInset ? -(borderWidth + borderGap) : borderGap;
380
+ borderStyle += `outline: ${borderWidth}px solid ${colorToRgba(borderColor)};`;
381
+ borderStyle += `outline-offset: ${gap}px;`;
382
+ }
383
+ // Rounded
384
+ if (typeof radius === 'number' && radius > 0) {
385
+ radiusStyle += `border-radius: ${radius}px;`;
386
+ }
387
+ else if (Array.isArray(radius) && radius.length === 4) {
388
+ radiusStyle += `border-radius: ${radius[0]}px ${radius[1]}px ${radius[2]}px ${radius[3]}px;`;
389
+ }
390
+ }
391
+ style += radiusStyle;
392
+ bgStyle += radiusStyle;
393
+ borderStyle += radiusStyle;
394
+ if (node.divBg == null) {
395
+ style += bgStyle;
396
+ }
397
+ else {
398
+ bgStyle += 'position: absolute; inset: 0; z-index: -1;';
399
+ node.divBg.setAttribute('style', bgStyle);
400
+ }
401
+ if (node.divBorder == null) {
402
+ style += borderStyle;
403
+ }
404
+ else {
405
+ borderStyle += 'position: absolute; inset: 0; z-index: -1;';
406
+ node.divBorder.setAttribute('style', borderStyle);
407
+ }
408
+ }
409
+ node.div.setAttribute('style', style);
410
+ }
411
+ const fontFamiliesToLoad = new Set();
412
+ const textNodesToMeasure = new Set();
413
+ function getElSize(node) {
414
+ let rect = node.div.getBoundingClientRect();
415
+ let dpr = Config.rendererOptions?.deviceLogicalPixelRatio ?? 1;
416
+ rect.height /= dpr;
417
+ rect.width /= dpr;
418
+ for (;;) {
419
+ if (node.props.scale != null && node.props.scale !== 1) {
420
+ rect.height /= node.props.scale;
421
+ rect.width /= node.props.scale;
422
+ }
423
+ else {
424
+ rect.height /= node.props.scaleY;
425
+ rect.width /= node.props.scaleX;
426
+ }
427
+ if (node.parent instanceof DOMNode) {
428
+ node = node.parent;
429
+ }
430
+ else {
431
+ break;
432
+ }
433
+ }
434
+ return rect;
435
+ }
436
+ /*
437
+ Text nodes with contain 'width' or 'none'
438
+ need to have their height or width calculated.
439
+ And then cause the flex layout to be recalculated.
440
+ */
441
+ function updateDOMTextSize(node) {
442
+ let size;
443
+ switch (node.contain) {
444
+ case 'width':
445
+ size = getElSize(node);
446
+ if (node.props.h !== size.height) {
447
+ node.props.h = size.height;
448
+ updateNodeStyles(node);
449
+ node.emit('loaded');
450
+ }
451
+ break;
452
+ case 'none':
453
+ size = getElSize(node);
454
+ if (node.props.h !== size.height || node.props.w !== size.width) {
455
+ node.props.w = size.width;
456
+ node.props.h = size.height;
457
+ updateNodeStyles(node);
458
+ node.emit('loaded');
459
+ }
460
+ break;
461
+ }
462
+ }
463
+ function updateDOMTextMeasurements() {
464
+ textNodesToMeasure.forEach(updateDOMTextSize);
465
+ textNodesToMeasure.clear();
466
+ }
467
+ function scheduleUpdateDOMTextMeasurement(node) {
468
+ /*
469
+ Make sure the font is loaded before measuring
470
+ */
471
+ if (node.fontFamily && !fontFamiliesToLoad.has(node.fontFamily)) {
472
+ fontFamiliesToLoad.add(node.fontFamily);
473
+ document.fonts.load(`16px ${node.fontFamily}`);
474
+ }
475
+ if (textNodesToMeasure.size === 0) {
476
+ if (document.fonts.status === 'loaded') {
477
+ setTimeout(updateDOMTextMeasurements);
478
+ }
479
+ else {
480
+ document.fonts.ready.then(updateDOMTextMeasurements);
481
+ }
482
+ }
483
+ textNodesToMeasure.add(node);
484
+ }
485
+ function updateNodeData(node) {
486
+ for (let key in node.data) {
487
+ let keyValue = node.data[key];
488
+ if (keyValue === undefined) {
489
+ node.div.removeAttribute('data-' + key);
490
+ }
491
+ else {
492
+ node.div.setAttribute('data-' + key, String(keyValue));
493
+ }
494
+ }
495
+ }
496
+ function resolveNodeDefaults(props) {
497
+ const color = props.color ?? 0xffffffff;
498
+ return {
499
+ x: props.x ?? 0,
500
+ y: props.y ?? 0,
501
+ w: props.w ?? 0,
502
+ h: props.h ?? 0,
503
+ alpha: props.alpha ?? 1,
504
+ autosize: props.autosize ?? false,
505
+ boundsMargin: props.boundsMargin ?? null,
506
+ clipping: props.clipping ?? false,
507
+ color,
508
+ colorTop: props.colorTop ?? color,
509
+ colorBottom: props.colorBottom ?? color,
510
+ colorLeft: props.colorLeft ?? color,
511
+ colorRight: props.colorRight ?? color,
512
+ colorBl: props.colorBl ?? props.colorBottom ?? props.colorLeft ?? color,
513
+ colorBr: props.colorBr ?? props.colorBottom ?? props.colorRight ?? color,
514
+ colorTl: props.colorTl ?? props.colorTop ?? props.colorLeft ?? color,
515
+ colorTr: props.colorTr ?? props.colorTop ?? props.colorRight ?? color,
516
+ zIndex: props.zIndex ?? 0,
517
+ zIndexLocked: props.zIndexLocked ?? 0,
518
+ parent: props.parent ?? null,
519
+ texture: props.texture ?? null,
520
+ textureOptions: props.textureOptions ?? {},
521
+ shader: props.shader ?? defaultShader,
522
+ // Since setting the `src` will trigger a texture load, we need to set it after
523
+ // we set the texture. Otherwise, problems happen.
524
+ src: props.src ?? null,
525
+ srcHeight: props.srcHeight,
526
+ srcWidth: props.srcWidth,
527
+ srcX: props.srcX,
528
+ srcY: props.srcY,
529
+ scale: props.scale ?? null,
530
+ scaleX: props.scaleX ?? props.scale ?? 1,
531
+ scaleY: props.scaleY ?? props.scale ?? 1,
532
+ mount: props.mount ?? 0,
533
+ mountX: props.mountX ?? props.mount ?? 0,
534
+ mountY: props.mountY ?? props.mount ?? 0,
535
+ pivot: props.pivot ?? 0.5,
536
+ pivotX: props.pivotX ?? props.pivot ?? 0.5,
537
+ pivotY: props.pivotY ?? props.pivot ?? 0.5,
538
+ rotation: props.rotation ?? 0,
539
+ rtt: props.rtt ?? false,
540
+ data: {},
541
+ imageType: props.imageType,
542
+ };
543
+ }
544
+ function resolveTextNodeDefaults(props) {
545
+ return {
546
+ ...resolveNodeDefaults(props),
547
+ text: props.text ?? '',
548
+ textRendererOverride: props.textRendererOverride ?? null,
549
+ fontSize: props.fontSize ?? 16,
550
+ fontFamily: props.fontFamily ?? 'sans-serif',
551
+ fontStyle: props.fontStyle ?? 'normal',
552
+ fontWeight: props.fontWeight ?? 'normal',
553
+ forceLoad: props.forceLoad ?? false,
554
+ textAlign: props.textAlign ?? 'left',
555
+ contain: props.contain ?? 'none',
556
+ offsetY: props.offsetY ?? 0,
557
+ letterSpacing: props.letterSpacing ?? 0,
558
+ lineHeight: props.lineHeight ?? 0,
559
+ maxLines: props.maxLines ?? 0,
560
+ maxWidth: props.maxWidth ?? 0,
561
+ maxHeight: props.maxHeight ?? 0,
562
+ verticalAlign: props.verticalAlign ?? 'middle',
563
+ overflowSuffix: props.overflowSuffix ?? '...',
564
+ wordBreak: props.wordBreak ?? 'overflow',
565
+ };
566
+ }
567
+ const defaultShader = {
568
+ shaderType: '',
569
+ props: undefined,
570
+ };
571
+ let lastNodeId = 0;
572
+ class DOMNode extends EventEmitter {
573
+ stage;
574
+ props;
575
+ div = document.createElement('div');
576
+ divBg;
577
+ divBorder;
578
+ id = ++lastNodeId;
579
+ renderState = 0 /* Init */;
580
+ constructor(stage, props) {
581
+ super();
582
+ this.stage = stage;
583
+ this.props = props;
584
+ // @ts-ignore
585
+ this.div._node = this;
586
+ this.div.setAttribute('data-id', String(this.id));
587
+ elMap.set(this, this.div);
588
+ updateNodeParent(this);
589
+ updateNodeStyles(this);
590
+ updateNodeData(this);
591
+ }
592
+ destroy() {
593
+ elMap.delete(this);
594
+ this.div.parentNode.removeChild(this.div);
595
+ }
596
+ get parent() {
597
+ return this.props.parent;
598
+ }
599
+ set parent(value) {
600
+ this.props.parent = value;
601
+ updateNodeParent(this);
602
+ }
603
+ animate = animate;
604
+ get x() {
605
+ return this.props.x;
606
+ }
607
+ set x(v) {
608
+ this.props.x = v;
609
+ updateNodeStyles(this);
610
+ }
611
+ get y() {
612
+ return this.props.y;
613
+ }
614
+ set y(v) {
615
+ this.props.y = v;
616
+ updateNodeStyles(this);
617
+ }
618
+ get w() {
619
+ return this.props.w;
620
+ }
621
+ set w(v) {
622
+ this.props.w = v;
623
+ updateNodeStyles(this);
624
+ }
625
+ get h() {
626
+ return this.props.h;
627
+ }
628
+ set h(v) {
629
+ this.props.h = v;
630
+ updateNodeStyles(this);
631
+ }
632
+ get width() {
633
+ return this.props.w;
634
+ }
635
+ set width(v) {
636
+ this.props.w = v;
637
+ updateNodeStyles(this);
638
+ }
639
+ get height() {
640
+ return this.props.h;
641
+ }
642
+ set height(v) {
643
+ this.props.h = v;
644
+ updateNodeStyles(this);
645
+ }
646
+ get alpha() {
647
+ return this.props.alpha;
648
+ }
649
+ set alpha(v) {
650
+ this.props.alpha = v;
651
+ updateNodeStyles(this);
652
+ }
653
+ get autosize() {
654
+ return this.props.autosize;
655
+ }
656
+ set autosize(v) {
657
+ this.props.autosize = v;
658
+ updateNodeStyles(this);
659
+ }
660
+ get clipping() {
661
+ return this.props.clipping;
662
+ }
663
+ set clipping(v) {
664
+ this.props.clipping = v;
665
+ updateNodeStyles(this);
666
+ }
667
+ get color() {
668
+ return this.props.color;
669
+ }
670
+ set color(v) {
671
+ this.props.color = v;
672
+ updateNodeStyles(this);
673
+ }
674
+ get colorTop() {
675
+ return this.props.colorTop;
676
+ }
677
+ set colorTop(v) {
678
+ this.props.colorTop = v;
679
+ updateNodeStyles(this);
680
+ }
681
+ get colorBottom() {
682
+ return this.props.colorBottom;
683
+ }
684
+ set colorBottom(v) {
685
+ this.props.colorBottom = v;
686
+ updateNodeStyles(this);
687
+ }
688
+ get colorLeft() {
689
+ return this.props.colorLeft;
690
+ }
691
+ set colorLeft(v) {
692
+ this.props.colorLeft = v;
693
+ updateNodeStyles(this);
694
+ }
695
+ get colorRight() {
696
+ return this.props.colorRight;
697
+ }
698
+ set colorRight(v) {
699
+ this.props.colorRight = v;
700
+ updateNodeStyles(this);
701
+ }
702
+ get colorTl() {
703
+ return this.props.colorTl;
704
+ }
705
+ set colorTl(v) {
706
+ this.props.colorTl = v;
707
+ updateNodeStyles(this);
708
+ }
709
+ get colorTr() {
710
+ return this.props.colorTr;
711
+ }
712
+ set colorTr(v) {
713
+ this.props.colorTr = v;
714
+ updateNodeStyles(this);
715
+ }
716
+ get colorBr() {
717
+ return this.props.colorBr;
718
+ }
719
+ set colorBr(v) {
720
+ this.props.colorBr = v;
721
+ updateNodeStyles(this);
722
+ }
723
+ get colorBl() {
724
+ return this.props.colorBl;
725
+ }
726
+ set colorBl(v) {
727
+ this.props.colorBl = v;
728
+ updateNodeStyles(this);
729
+ }
730
+ get zIndex() {
731
+ return this.props.zIndex;
732
+ }
733
+ set zIndex(v) {
734
+ this.props.zIndex = v;
735
+ updateNodeStyles(this);
736
+ }
737
+ get texture() {
738
+ return this.props.texture;
739
+ }
740
+ set texture(v) {
741
+ this.props.texture = v;
742
+ updateNodeStyles(this);
743
+ }
744
+ get textureOptions() {
745
+ return this.props.textureOptions;
746
+ }
747
+ set textureOptions(v) {
748
+ this.props.textureOptions = v;
749
+ updateNodeStyles(this);
750
+ }
751
+ get src() {
752
+ return this.props.src;
753
+ }
754
+ set src(v) {
755
+ this.props.src = v;
756
+ updateNodeStyles(this);
757
+ }
758
+ get zIndexLocked() {
759
+ return this.props.zIndexLocked;
760
+ }
761
+ set zIndexLocked(v) {
762
+ this.props.zIndexLocked = v;
763
+ updateNodeStyles(this);
764
+ }
765
+ get scale() {
766
+ return this.props.scale ?? 1;
767
+ }
768
+ set scale(v) {
769
+ this.props.scale = v;
770
+ updateNodeStyles(this);
771
+ }
772
+ get scaleX() {
773
+ return this.props.scaleX;
774
+ }
775
+ set scaleX(v) {
776
+ this.props.scaleX = v;
777
+ updateNodeStyles(this);
778
+ }
779
+ get scaleY() {
780
+ return this.props.scaleY;
781
+ }
782
+ set scaleY(v) {
783
+ this.props.scaleY = v;
784
+ updateNodeStyles(this);
785
+ }
786
+ get mount() {
787
+ return this.props.mount;
788
+ }
789
+ set mount(v) {
790
+ this.props.mount = v;
791
+ updateNodeStyles(this);
792
+ }
793
+ get mountX() {
794
+ return this.props.mountX;
795
+ }
796
+ set mountX(v) {
797
+ this.props.mountX = v;
798
+ updateNodeStyles(this);
799
+ }
800
+ get mountY() {
801
+ return this.props.mountY;
802
+ }
803
+ set mountY(v) {
804
+ this.props.mountY = v;
805
+ updateNodeStyles(this);
806
+ }
807
+ get pivot() {
808
+ return this.props.pivot;
809
+ }
810
+ set pivot(v) {
811
+ this.props.pivot = v;
812
+ updateNodeStyles(this);
813
+ }
814
+ get pivotX() {
815
+ return this.props.pivotX;
816
+ }
817
+ set pivotX(v) {
818
+ this.props.pivotX = v;
819
+ updateNodeStyles(this);
820
+ }
821
+ get pivotY() {
822
+ return this.props.pivotY;
823
+ }
824
+ set pivotY(v) {
825
+ this.props.pivotY = v;
826
+ updateNodeStyles(this);
827
+ }
828
+ get rotation() {
829
+ return this.props.rotation;
830
+ }
831
+ set rotation(v) {
832
+ this.props.rotation = v;
833
+ updateNodeStyles(this);
834
+ }
835
+ get rtt() {
836
+ return this.props.rtt;
837
+ }
838
+ set rtt(v) {
839
+ this.props.rtt = v;
840
+ updateNodeStyles(this);
841
+ }
842
+ get shader() {
843
+ return this.props.shader;
844
+ }
845
+ set shader(v) {
846
+ this.props.shader = v;
847
+ updateNodeStyles(this);
848
+ }
849
+ get data() {
850
+ return this.props.data;
851
+ }
852
+ set data(v) {
853
+ this.props.data = v;
854
+ updateNodeData(this);
855
+ }
856
+ get imageType() {
857
+ return this.props.imageType;
858
+ }
859
+ set imageType(v) {
860
+ this.props.imageType = v;
861
+ }
862
+ get srcWidth() {
863
+ return this.props.srcWidth;
864
+ }
865
+ set srcWidth(v) {
866
+ this.props.srcWidth = v;
867
+ }
868
+ get srcHeight() {
869
+ return this.props.srcHeight;
870
+ }
871
+ set srcHeight(v) {
872
+ this.props.srcHeight = v;
873
+ }
874
+ get srcX() {
875
+ return this.props.srcX;
876
+ }
877
+ set srcX(v) {
878
+ this.props.srcX = v;
879
+ }
880
+ get srcY() {
881
+ return this.props.srcY;
882
+ }
883
+ set srcY(v) {
884
+ this.props.srcY = v;
885
+ }
886
+ get boundsMargin() {
887
+ return this.props.boundsMargin;
888
+ }
889
+ set boundsMargin(value) {
890
+ this.props.boundsMargin = value;
891
+ }
892
+ get absX() {
893
+ return this.x + -this.width * this.mountX + (this.parent?.absX ?? 0);
894
+ }
895
+ get absY() {
896
+ return this.y + -this.height * this.mountY + (this.parent?.absY ?? 0);
897
+ }
898
+ }
899
+ class DOMText extends DOMNode {
900
+ props;
901
+ constructor(stage, props) {
902
+ super(stage, props);
903
+ this.props = props;
904
+ this.div.innerText = props.text;
905
+ }
906
+ get text() {
907
+ return this.props.text;
908
+ }
909
+ set text(v) {
910
+ this.props.text = v;
911
+ this.div.innerText = v;
912
+ scheduleUpdateDOMTextMeasurement(this);
913
+ }
914
+ get fontFamily() {
915
+ return this.props.fontFamily;
916
+ }
917
+ set fontFamily(v) {
918
+ this.props.fontFamily = v;
919
+ updateNodeStyles(this);
920
+ }
921
+ get fontSize() {
922
+ return this.props.fontSize;
923
+ }
924
+ set fontSize(v) {
925
+ this.props.fontSize = v;
926
+ updateNodeStyles(this);
927
+ }
928
+ get fontStyle() {
929
+ return this.props.fontStyle;
930
+ }
931
+ set fontStyle(v) {
932
+ this.props.fontStyle = v;
933
+ updateNodeStyles(this);
934
+ }
935
+ get fontWeight() {
936
+ return this.props.fontWeight;
937
+ }
938
+ set fontWeight(v) {
939
+ this.props.fontWeight = v;
940
+ updateNodeStyles(this);
941
+ }
942
+ get forceLoad() {
943
+ return this.props.forceLoad;
944
+ }
945
+ set forceLoad(v) {
946
+ this.props.forceLoad = v;
947
+ }
948
+ get lineHeight() {
949
+ return this.props.lineHeight;
950
+ }
951
+ set lineHeight(v) {
952
+ this.props.lineHeight = v;
953
+ updateNodeStyles(this);
954
+ }
955
+ get maxWidth() {
956
+ return this.props.maxWidth;
957
+ }
958
+ set maxWidth(v) {
959
+ this.props.maxWidth = v;
960
+ updateNodeStyles(this);
961
+ }
962
+ get maxHeight() {
963
+ return this.props.maxHeight;
964
+ }
965
+ set maxHeight(v) {
966
+ this.props.maxHeight = v;
967
+ updateNodeStyles(this);
968
+ }
969
+ get letterSpacing() {
970
+ return this.props.letterSpacing;
971
+ }
972
+ set letterSpacing(v) {
973
+ this.props.letterSpacing = v;
974
+ updateNodeStyles(this);
975
+ }
976
+ get textAlign() {
977
+ return this.props.textAlign;
978
+ }
979
+ set textAlign(v) {
980
+ this.props.textAlign = v;
981
+ updateNodeStyles(this);
982
+ }
983
+ get overflowSuffix() {
984
+ return this.props.overflowSuffix;
985
+ }
986
+ set overflowSuffix(v) {
987
+ this.props.overflowSuffix = v;
988
+ updateNodeStyles(this);
989
+ }
990
+ get maxLines() {
991
+ return this.props.maxLines;
992
+ }
993
+ set maxLines(v) {
994
+ this.props.maxLines = v;
995
+ updateNodeStyles(this);
996
+ }
997
+ get contain() {
998
+ return this.props.contain;
999
+ }
1000
+ set contain(v) {
1001
+ this.props.contain = v;
1002
+ updateNodeStyles(this);
1003
+ }
1004
+ get verticalAlign() {
1005
+ return this.props.verticalAlign;
1006
+ }
1007
+ set verticalAlign(v) {
1008
+ this.props.verticalAlign = v;
1009
+ updateNodeStyles(this);
1010
+ }
1011
+ get textRendererOverride() {
1012
+ return this.props.textRendererOverride;
1013
+ }
1014
+ set textRendererOverride(v) {
1015
+ this.props.textRendererOverride = v;
1016
+ updateNodeStyles(this);
1017
+ }
1018
+ get offsetY() {
1019
+ return this.props.offsetY;
1020
+ }
1021
+ set offsetY(v) {
1022
+ this.props.offsetY = v;
1023
+ updateNodeStyles(this);
1024
+ }
1025
+ get wordBreak() {
1026
+ return this.props.wordBreak;
1027
+ }
1028
+ set wordBreak(v) {
1029
+ this.props.wordBreak = v;
1030
+ updateNodeStyles(this);
1031
+ }
1032
+ }
1033
+ function updateRootPosition() {
1034
+ let { canvas, settings } = this;
1035
+ let rect = canvas.getBoundingClientRect();
1036
+ let top = document.documentElement.scrollTop + rect.top;
1037
+ let left = document.documentElement.scrollLeft + rect.left;
1038
+ let dpr = settings.deviceLogicalPixelRatio ?? 1;
1039
+ let height = Math.ceil(settings.appHeight ?? 1080 / dpr);
1040
+ let width = Math.ceil(settings.appWidth ?? 1920 / dpr);
1041
+ this.root.div.style.left = `${left}px`;
1042
+ this.root.div.style.top = `${top}px`;
1043
+ this.root.div.style.width = `${width}px`;
1044
+ this.root.div.style.height = `${height}px`;
1045
+ this.root.div.style.position = 'absolute';
1046
+ this.root.div.style.transformOrigin = '0 0 0';
1047
+ this.root.div.style.transform = `scale(${dpr}, ${dpr})`;
1048
+ this.root.div.style.overflow = 'hidden';
1049
+ }
1050
+ export class DOMRendererMain {
1051
+ settings;
1052
+ root;
1053
+ canvas;
1054
+ stage;
1055
+ constructor(settings, rawTarget) {
1056
+ this.settings = settings;
1057
+ let target;
1058
+ if (typeof rawTarget === 'string') {
1059
+ let result = document.getElementById(rawTarget);
1060
+ if (result instanceof HTMLElement) {
1061
+ target = result;
1062
+ }
1063
+ else {
1064
+ throw new Error(`Target #${rawTarget} not found`);
1065
+ }
1066
+ }
1067
+ else {
1068
+ target = rawTarget;
1069
+ }
1070
+ let canvas = document.body.appendChild(document.createElement('canvas'));
1071
+ canvas.style.position = 'absolute';
1072
+ canvas.style.top = '0';
1073
+ canvas.style.left = '0';
1074
+ canvas.style.width = '100vw';
1075
+ canvas.style.height = '100vh';
1076
+ this.canvas = canvas;
1077
+ this.stage = {
1078
+ root: null,
1079
+ renderer: {
1080
+ mode: 'canvas',
1081
+ },
1082
+ loadFont: async () => { },
1083
+ shManager: {
1084
+ registerShaderType() { },
1085
+ },
1086
+ animationManager: {
1087
+ registerAnimation() { },
1088
+ unregisterAnimation() { },
1089
+ },
1090
+ };
1091
+ this.root = new DOMNode(this.stage, resolveNodeDefaults({
1092
+ w: settings.appWidth ?? 1920,
1093
+ h: settings.appHeight ?? 1080,
1094
+ shader: defaultShader,
1095
+ zIndex: 65534,
1096
+ }));
1097
+ this.stage.root = this.root;
1098
+ target.appendChild(this.root.div);
1099
+ if (Config.fontSettings.fontFamily) {
1100
+ this.root.div.style.fontFamily = Config.fontSettings.fontFamily;
1101
+ }
1102
+ if (Config.fontSettings.fontSize) {
1103
+ this.root.div.style.fontSize = Config.fontSettings.fontSize + 'px';
1104
+ }
1105
+ if (Config.fontSettings.lineHeight) {
1106
+ this.root.div.style.lineHeight = Config.fontSettings.lineHeight + 'px';
1107
+ }
1108
+ else {
1109
+ this.root.div.style.lineHeight = '1.2';
1110
+ }
1111
+ if (Config.fontSettings.fontWeight) {
1112
+ if (typeof Config.fontSettings.fontWeight === 'number') {
1113
+ this.root.div.style.fontWeight = Config.fontSettings.fontWeight + 'px';
1114
+ }
1115
+ else {
1116
+ this.root.div.style.fontWeight = Config.fontSettings.fontWeight;
1117
+ }
1118
+ }
1119
+ updateRootPosition.call(this);
1120
+ new MutationObserver(updateRootPosition.bind(this)).observe(this.canvas, {
1121
+ attributes: true,
1122
+ });
1123
+ new ResizeObserver(updateRootPosition.bind(this)).observe(this.canvas);
1124
+ window.addEventListener('resize', updateRootPosition.bind(this));
1125
+ }
1126
+ createNode(props) {
1127
+ return new DOMNode(this.stage, resolveNodeDefaults(props));
1128
+ }
1129
+ createTextNode(props) {
1130
+ return new DOMText(this.stage, resolveTextNodeDefaults(props));
1131
+ }
1132
+ createShader(shaderType, props) {
1133
+ return { shaderType, props, program: {} };
1134
+ }
1135
+ createTexture(textureType, props) {
1136
+ let type = lng.TextureType.generic;
1137
+ switch (textureType) {
1138
+ case 'SubTexture':
1139
+ type = lng.TextureType.subTexture;
1140
+ break;
1141
+ case 'ImageTexture':
1142
+ type = lng.TextureType.image;
1143
+ break;
1144
+ case 'ColorTexture':
1145
+ type = lng.TextureType.color;
1146
+ break;
1147
+ case 'NoiseTexture':
1148
+ type = lng.TextureType.noise;
1149
+ break;
1150
+ case 'RenderTexture':
1151
+ type = lng.TextureType.renderToTexture;
1152
+ break;
1153
+ }
1154
+ return { type, props };
1155
+ }
1156
+ on(name, callback) {
1157
+ console.log('on', name, callback);
1158
+ }
1159
+ }
1160
+ //# sourceMappingURL=domRenderer.js.map