@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.
Files changed (237) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +95 -0
  4. package/dist/jsx-runtime.d.ts +14 -0
  5. package/dist/src/activeElement.d.ts +2 -0
  6. package/dist/src/activeElement.js +3 -0
  7. package/dist/src/activeElement.js.map +1 -0
  8. package/dist/src/core/config.d.ts +51 -0
  9. package/dist/src/core/config.js +37 -0
  10. package/dist/src/core/config.js.map +1 -0
  11. package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
  12. package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
  13. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
  14. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
  15. package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
  16. package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
  17. package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
  18. package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
  19. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
  20. package/dist/src/core/elementNode.d.ts +508 -0
  21. package/dist/src/core/elementNode.js +928 -0
  22. package/dist/src/core/elementNode.js.map +1 -0
  23. package/dist/src/core/flex.d.ts +2 -0
  24. package/dist/src/core/flex.js +284 -0
  25. package/dist/src/core/flex.js.map +1 -0
  26. package/dist/src/core/flexLayout.d.ts +2 -0
  27. package/dist/src/core/flexLayout.js +360 -0
  28. package/dist/src/core/flexLayout.js.map +1 -0
  29. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  30. package/dist/src/core/focusKeyTypes.js +2 -0
  31. package/dist/src/core/focusKeyTypes.js.map +1 -0
  32. package/dist/src/core/focusManager.d.ts +13 -0
  33. package/dist/src/core/focusManager.js +270 -0
  34. package/dist/src/core/focusManager.js.map +1 -0
  35. package/dist/src/core/index.d.ts +14 -0
  36. package/dist/src/core/index.js +11 -0
  37. package/dist/src/core/index.js.map +1 -0
  38. package/dist/src/core/intrinsicTypes.d.ts +106 -0
  39. package/dist/src/core/intrinsicTypes.js +2 -0
  40. package/dist/src/core/intrinsicTypes.js.map +1 -0
  41. package/dist/src/core/lightningInit.d.ts +9 -0
  42. package/dist/src/core/lightningInit.js +34 -0
  43. package/dist/src/core/lightningInit.js.map +1 -0
  44. package/dist/src/core/nodeTypes.d.ts +6 -0
  45. package/dist/src/core/nodeTypes.js +6 -0
  46. package/dist/src/core/nodeTypes.js.map +1 -0
  47. package/dist/src/core/shaders.d.ts +52 -0
  48. package/dist/src/core/shaders.js +86 -0
  49. package/dist/src/core/shaders.js.map +1 -0
  50. package/dist/src/core/states.d.ts +12 -0
  51. package/dist/src/core/states.js +84 -0
  52. package/dist/src/core/states.js.map +1 -0
  53. package/dist/src/core/utils.d.ts +39 -0
  54. package/dist/src/core/utils.js +164 -0
  55. package/dist/src/core/utils.js.map +1 -0
  56. package/dist/src/devtools/index.d.ts +6 -0
  57. package/dist/src/devtools/index.js +65 -0
  58. package/dist/src/devtools/index.js.map +1 -0
  59. package/dist/src/index.d.ts +9 -0
  60. package/dist/src/index.js +7 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/primitives/Column.d.ts +3 -0
  63. package/dist/src/primitives/Column.jsx +25 -0
  64. package/dist/src/primitives/Column.jsx.map +1 -0
  65. package/dist/src/primitives/FPSCounter.d.ts +4 -0
  66. package/dist/src/primitives/FPSCounter.jsx +188 -0
  67. package/dist/src/primitives/FPSCounter.jsx.map +1 -0
  68. package/dist/src/primitives/FadeInOut.d.ts +18 -0
  69. package/dist/src/primitives/FadeInOut.jsx +39 -0
  70. package/dist/src/primitives/FadeInOut.jsx.map +1 -0
  71. package/dist/src/primitives/Grid.d.ts +23 -0
  72. package/dist/src/primitives/Grid.jsx +100 -0
  73. package/dist/src/primitives/Grid.jsx.map +1 -0
  74. package/dist/src/primitives/Image.d.ts +8 -0
  75. package/dist/src/primitives/Image.jsx +42 -0
  76. package/dist/src/primitives/Image.jsx.map +1 -0
  77. package/dist/src/primitives/KeepAlive.d.ts +42 -0
  78. package/dist/src/primitives/KeepAlive.jsx +160 -0
  79. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  80. package/dist/src/primitives/Lazy.d.ts +15 -0
  81. package/dist/src/primitives/Lazy.jsx +95 -0
  82. package/dist/src/primitives/Lazy.jsx.map +1 -0
  83. package/dist/src/primitives/LazyImport.d.ts +8 -0
  84. package/dist/src/primitives/LazyImport.js +40 -0
  85. package/dist/src/primitives/LazyImport.js.map +1 -0
  86. package/dist/src/primitives/Marquee.d.ts +64 -0
  87. package/dist/src/primitives/Marquee.jsx +86 -0
  88. package/dist/src/primitives/Marquee.jsx.map +1 -0
  89. package/dist/src/primitives/Preserve.d.ts +4 -0
  90. package/dist/src/primitives/Preserve.jsx +11 -0
  91. package/dist/src/primitives/Preserve.jsx.map +1 -0
  92. package/dist/src/primitives/Row.d.ts +3 -0
  93. package/dist/src/primitives/Row.jsx +24 -0
  94. package/dist/src/primitives/Row.jsx.map +1 -0
  95. package/dist/src/primitives/Suspense.d.ts +22 -0
  96. package/dist/src/primitives/Suspense.jsx +33 -0
  97. package/dist/src/primitives/Suspense.jsx.map +1 -0
  98. package/dist/src/primitives/Virtual.d.ts +18 -0
  99. package/dist/src/primitives/Virtual.jsx +495 -0
  100. package/dist/src/primitives/Virtual.jsx.map +1 -0
  101. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  102. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  103. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  104. package/dist/src/primitives/Visible.d.ts +6 -0
  105. package/dist/src/primitives/Visible.jsx +37 -0
  106. package/dist/src/primitives/Visible.jsx.map +1 -0
  107. package/dist/src/primitives/announcer/announcer.d.ts +40 -0
  108. package/dist/src/primitives/announcer/announcer.js +125 -0
  109. package/dist/src/primitives/announcer/announcer.js.map +1 -0
  110. package/dist/src/primitives/announcer/index.d.ts +6 -0
  111. package/dist/src/primitives/announcer/index.js +15 -0
  112. package/dist/src/primitives/announcer/index.js.map +1 -0
  113. package/dist/src/primitives/announcer/speech.d.ts +10 -0
  114. package/dist/src/primitives/announcer/speech.js +281 -0
  115. package/dist/src/primitives/announcer/speech.js.map +1 -0
  116. package/dist/src/primitives/borderBox.d.ts +8 -0
  117. package/dist/src/primitives/borderBox.jsx +47 -0
  118. package/dist/src/primitives/borderBox.jsx.map +1 -0
  119. package/dist/src/primitives/createFocusStack.d.ts +31 -0
  120. package/dist/src/primitives/createFocusStack.jsx +62 -0
  121. package/dist/src/primitives/createFocusStack.jsx.map +1 -0
  122. package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
  123. package/dist/src/primitives/createInfiniteItems.js +46 -0
  124. package/dist/src/primitives/createInfiniteItems.js.map +1 -0
  125. package/dist/src/primitives/createTag.d.ts +8 -0
  126. package/dist/src/primitives/createTag.jsx +20 -0
  127. package/dist/src/primitives/createTag.jsx.map +1 -0
  128. package/dist/src/primitives/index.d.ts +32 -0
  129. package/dist/src/primitives/index.js +31 -0
  130. package/dist/src/primitives/index.js.map +1 -0
  131. package/dist/src/primitives/portal.d.ts +5 -0
  132. package/dist/src/primitives/portal.jsx +21 -0
  133. package/dist/src/primitives/portal.jsx.map +1 -0
  134. package/dist/src/primitives/router.d.ts +20 -0
  135. package/dist/src/primitives/router.js +90 -0
  136. package/dist/src/primitives/router.js.map +1 -0
  137. package/dist/src/primitives/types.d.ts +79 -0
  138. package/dist/src/primitives/types.js +2 -0
  139. package/dist/src/primitives/types.js.map +1 -0
  140. package/dist/src/primitives/useFocusManager.d.ts +5 -0
  141. package/dist/src/primitives/useFocusManager.js +21 -0
  142. package/dist/src/primitives/useFocusManager.js.map +1 -0
  143. package/dist/src/primitives/useHold.d.ts +27 -0
  144. package/dist/src/primitives/useHold.js +54 -0
  145. package/dist/src/primitives/useHold.js.map +1 -0
  146. package/dist/src/primitives/useMouse.d.ts +18 -0
  147. package/dist/src/primitives/useMouse.js +240 -0
  148. package/dist/src/primitives/useMouse.js.map +1 -0
  149. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
  150. package/dist/src/primitives/utils/chainFunctions.js +32 -0
  151. package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
  152. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  153. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  154. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  155. package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
  156. package/dist/src/primitives/utils/createSpriteMap.js +18 -0
  157. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
  158. package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
  159. package/dist/src/primitives/utils/handleNavigation.js +300 -0
  160. package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
  161. package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
  162. package/dist/src/primitives/utils/withScrolling.js +186 -0
  163. package/dist/src/primitives/utils/withScrolling.js.map +1 -0
  164. package/dist/src/render.d.ts +28 -0
  165. package/dist/src/render.js +107 -0
  166. package/dist/src/render.js.map +1 -0
  167. package/dist/src/solidOpts.d.ts +15 -0
  168. package/dist/src/solidOpts.js +93 -0
  169. package/dist/src/solidOpts.js.map +1 -0
  170. package/dist/src/types.d.ts +11 -0
  171. package/dist/src/types.js +2 -0
  172. package/dist/src/types.js.map +1 -0
  173. package/dist/src/utils.d.ts +19 -0
  174. package/dist/src/utils.js +94 -0
  175. package/dist/src/utils.js.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/docs/AI_CODING_GUIDELINES.md +108 -0
  178. package/docs/README.md +35 -0
  179. package/jsx-runtime.d.ts +14 -0
  180. package/package.json +125 -0
  181. package/src/activeElement.ts +5 -0
  182. package/src/core/config.ts +101 -0
  183. package/src/core/dom-renderer/domRenderer.ts +2066 -0
  184. package/src/core/dom-renderer/domRendererTypes.ts +148 -0
  185. package/src/core/dom-renderer/domRendererUtils.ts +292 -0
  186. package/src/core/elementNode.ts +1623 -0
  187. package/src/core/flex.ts +331 -0
  188. package/src/core/flexLayout.ts +414 -0
  189. package/src/core/focusKeyTypes.ts +90 -0
  190. package/src/core/focusManager.ts +374 -0
  191. package/src/core/index.ts +15 -0
  192. package/src/core/intrinsicTypes.ts +216 -0
  193. package/src/core/lightningInit.ts +45 -0
  194. package/src/core/nodeTypes.ts +6 -0
  195. package/src/core/shaders.ts +187 -0
  196. package/src/core/states.ts +91 -0
  197. package/src/core/utils.ts +222 -0
  198. package/src/devtools/index.ts +77 -0
  199. package/src/index.ts +18 -0
  200. package/src/primitives/Column.tsx +59 -0
  201. package/src/primitives/FPSCounter.tsx +209 -0
  202. package/src/primitives/FadeInOut.tsx +58 -0
  203. package/src/primitives/Grid.tsx +151 -0
  204. package/src/primitives/Image.tsx +56 -0
  205. package/src/primitives/KeepAlive.tsx +268 -0
  206. package/src/primitives/Lazy.tsx +128 -0
  207. package/src/primitives/LazyImport.ts +53 -0
  208. package/src/primitives/Marquee.tsx +149 -0
  209. package/src/primitives/Preserve.tsx +18 -0
  210. package/src/primitives/Row.tsx +58 -0
  211. package/src/primitives/Suspense.tsx +39 -0
  212. package/src/primitives/Virtual.tsx +602 -0
  213. package/src/primitives/VirtualGrid.tsx +220 -0
  214. package/src/primitives/Visible.tsx +59 -0
  215. package/src/primitives/announcer/announcer.ts +198 -0
  216. package/src/primitives/announcer/index.ts +20 -0
  217. package/src/primitives/announcer/speech.ts +334 -0
  218. package/src/primitives/borderBox.tsx +69 -0
  219. package/src/primitives/createFocusStack.tsx +79 -0
  220. package/src/primitives/createInfiniteItems.ts +66 -0
  221. package/src/primitives/createTag.tsx +33 -0
  222. package/src/primitives/index.ts +37 -0
  223. package/src/primitives/portal.tsx +25 -0
  224. package/src/primitives/router.ts +147 -0
  225. package/src/primitives/types.ts +109 -0
  226. package/src/primitives/useFocusManager.ts +47 -0
  227. package/src/primitives/useHold.ts +69 -0
  228. package/src/primitives/useMouse.ts +417 -0
  229. package/src/primitives/utils/chainFunctions.ts +60 -0
  230. package/src/primitives/utils/createBlurredImage.ts +366 -0
  231. package/src/primitives/utils/createSpriteMap.ts +32 -0
  232. package/src/primitives/utils/handleNavigation.ts +373 -0
  233. package/src/primitives/utils/withScrolling.ts +238 -0
  234. package/src/render.ts +164 -0
  235. package/src/solidOpts.ts +107 -0
  236. package/src/types.ts +22 -0
  237. package/src/utils.ts +129 -0
@@ -0,0 +1,928 @@
1
+ import { renderer } from './lightningInit.js';
2
+ import States from './states.js';
3
+ import calculateFlexOld from './flex.js';
4
+ import calculateFlexNew from './flexLayout.js';
5
+ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
6
+ ? calculateFlexNew
7
+ : calculateFlexOld;
8
+ import { log, isArray, isFunc, keyExists, isINode, isElementNode, isElementText, logRenderTree, isFunction, spliceItem, } from './utils.js';
9
+ import { Config, DOM_RENDERING, isDev, SHADERS_ENABLED } from './config.js';
10
+ import { assertTruthy } from '@solidtv/renderer/utils';
11
+ import { NodeType } from './nodeTypes.js';
12
+ import { setActiveElement, } from './focusManager.js';
13
+ let nextActiveElement = null;
14
+ let focusQueued = false;
15
+ let layoutRunQueued = false;
16
+ const layoutQueue = new Set();
17
+ function addToLayoutQueue(node) {
18
+ layoutQueue.add(node);
19
+ if (!layoutRunQueued) {
20
+ layoutRunQueued = true;
21
+ if ('reprocessUpdates' in renderer.stage &&
22
+ renderer.stage.reprocessUpdates) {
23
+ renderer.stage.reprocessUpdates(runLayout);
24
+ }
25
+ else {
26
+ queueMicrotask(runLayout);
27
+ }
28
+ }
29
+ }
30
+ function runLayout() {
31
+ while (layoutQueue.size > 0) {
32
+ const queue = [...layoutQueue];
33
+ layoutQueue.clear();
34
+ for (let i = queue.length - 1; i >= 0; i--) {
35
+ const node = queue[i];
36
+ node.updateLayout();
37
+ }
38
+ }
39
+ layoutRunQueued = false;
40
+ }
41
+ const parseAndAssignShaderProps = (prefix, obj, props = {}) => {
42
+ if (!obj)
43
+ return;
44
+ // Handle individual border sides: transform width/w to bottom/left/right/top
45
+ const borderSideMap = {
46
+ borderBottom: 'bottom',
47
+ borderLeft: 'left',
48
+ borderRight: 'right',
49
+ borderTop: 'top',
50
+ };
51
+ const side = borderSideMap[prefix];
52
+ const actualPrefix = side ? 'border' : prefix;
53
+ props[actualPrefix] = obj;
54
+ Object.entries(obj).forEach(([key, value]) => {
55
+ let transformedKey = key === 'width' ? 'w' : key;
56
+ // If border side and key is width/w, transform to side (bottom/left/right/top)
57
+ if (side && transformedKey === 'w') {
58
+ transformedKey = side;
59
+ }
60
+ props[`${actualPrefix}-${transformedKey}`] = value;
61
+ });
62
+ };
63
+ export function convertToShader(_node, v) {
64
+ let type = 'rounded';
65
+ if (v.border)
66
+ type += 'WithBorder';
67
+ if (v.shadow)
68
+ type += 'WithShadow';
69
+ return renderer.createShader(type, v);
70
+ }
71
+ function getPropertyAlias(name) {
72
+ if (name === 'w')
73
+ return 'width';
74
+ if (name === 'h')
75
+ return 'height';
76
+ return name;
77
+ }
78
+ export const LightningRendererNumberProps = [
79
+ 'alpha',
80
+ 'color',
81
+ 'colorTop',
82
+ 'colorRight',
83
+ 'colorLeft',
84
+ 'colorBottom',
85
+ 'colorTl',
86
+ 'colorTr',
87
+ 'colorBl',
88
+ 'colorBr',
89
+ 'h',
90
+ 'fontSize',
91
+ 'lineHeight',
92
+ 'mount',
93
+ 'mountX',
94
+ 'mountY',
95
+ 'pivot',
96
+ 'pivotX',
97
+ 'pivotY',
98
+ 'rotation',
99
+ 'scale',
100
+ 'scaleX',
101
+ 'scaleY',
102
+ 'w',
103
+ 'worldX',
104
+ 'worldY',
105
+ 'x',
106
+ 'y',
107
+ 'zIndex',
108
+ 'zIndexLocked',
109
+ ];
110
+ const LightningRendererNonAnimatingProps = [
111
+ 'absX',
112
+ 'absY',
113
+ 'autosize',
114
+ 'clipping',
115
+ 'contain',
116
+ 'data',
117
+ 'destroyed',
118
+ 'forceLoad',
119
+ 'fontStretch',
120
+ 'fontStyle',
121
+ 'group',
122
+ 'imageType',
123
+ 'letterSpacing',
124
+ 'maxHeight',
125
+ 'maxLines',
126
+ 'maxWidth',
127
+ 'offsetY',
128
+ 'overflowSuffix',
129
+ 'preventCleanup',
130
+ 'rtt',
131
+ 'scrollable',
132
+ 'scrollY',
133
+ 'srcHeight',
134
+ 'srcWidth',
135
+ 'srcX',
136
+ 'srcY',
137
+ 'strictBounds',
138
+ 'text',
139
+ 'textAlign',
140
+ 'textBaseline',
141
+ 'textOverflow',
142
+ 'texture',
143
+ 'textureOptions',
144
+ 'textRendererOverride',
145
+ 'verticalAlign',
146
+ 'wordBreak',
147
+ 'wordWrap',
148
+ ];
149
+ export class ElementNode extends Object {
150
+ constructor(name) {
151
+ super();
152
+ this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
153
+ this.rendered = false;
154
+ this.lng = {};
155
+ this.children = [];
156
+ }
157
+ get effects() {
158
+ return this.lng.shader;
159
+ }
160
+ set effects(v) {
161
+ if (!SHADERS_ENABLED)
162
+ return;
163
+ let target = this.lng.shader || {};
164
+ if (this.lng.shader?.props) {
165
+ target = this.lng.shader.props;
166
+ }
167
+ if (v.rounded)
168
+ target.radius = v.rounded.radius;
169
+ if (v.borderRadius)
170
+ target.radius = v.borderRadius;
171
+ if (v.border)
172
+ parseAndAssignShaderProps('border', v.border, target);
173
+ if (v.borderTop)
174
+ parseAndAssignShaderProps('borderTop', v.borderTop, target);
175
+ if (v.borderRight)
176
+ parseAndAssignShaderProps('borderRight', v.borderRight, target);
177
+ if (v.borderBottom)
178
+ parseAndAssignShaderProps('borderBottom', v.borderBottom, target);
179
+ if (v.borderLeft)
180
+ parseAndAssignShaderProps('borderLeft', v.borderLeft, target);
181
+ if (v.shadow)
182
+ parseAndAssignShaderProps('shadow', v.shadow, target);
183
+ if (this.rendered) {
184
+ if (!this.lng.shader) {
185
+ this.lng.shader = Config.convertToShader(this, target);
186
+ }
187
+ else if (DOM_RENDERING && Config.domRendererEnabled) {
188
+ this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
189
+ }
190
+ }
191
+ else {
192
+ this.lng.shader = target;
193
+ }
194
+ }
195
+ set id(id) {
196
+ this._id = id;
197
+ if (Config.rendererOptions &&
198
+ 'inspector' in Config.rendererOptions &&
199
+ Config.rendererOptions.inspector) {
200
+ this.data = { ...this.data, testId: id };
201
+ }
202
+ }
203
+ get id() {
204
+ return this._id;
205
+ }
206
+ get parent() {
207
+ return this._parent;
208
+ }
209
+ set parent(p) {
210
+ this._parent = p;
211
+ if (this.rendered && p?.rendered) {
212
+ this.lng.parent = p.lng ?? null;
213
+ }
214
+ }
215
+ get height() {
216
+ return this.maxHeight || this.h;
217
+ }
218
+ set height(h) {
219
+ this.h = h;
220
+ }
221
+ get width() {
222
+ return this.maxWidth || this.w;
223
+ }
224
+ set width(w) {
225
+ this.w = w;
226
+ }
227
+ set fontWeight(v) {
228
+ if (this._fontWeight === v) {
229
+ return;
230
+ }
231
+ this._fontWeight = v;
232
+ const weight = (Config.fontWeightAlias &&
233
+ Config.fontWeightAlias[v]) ??
234
+ v;
235
+ this.lng.fontFamily =
236
+ `${this.fontFamily || Config.fontSettings?.fontFamily}${weight}`;
237
+ }
238
+ get fontWeight() {
239
+ return this._fontWeight;
240
+ }
241
+ set fontFamily(v) {
242
+ this._fontFamily = v;
243
+ this.lng.fontFamily = v;
244
+ }
245
+ get fontFamily() {
246
+ return this._fontFamily;
247
+ }
248
+ insertChild(node, beforeNode) {
249
+ // always remove nodes if they have a parent - for back swap of node
250
+ // this will then put the node at the end of the array when re-added
251
+ if (node.parent) {
252
+ node.parent.removeChild(node);
253
+ // We're inserting a node thats been rendered into a node that hasn't been
254
+ if (!this.rendered) {
255
+ this._hasRenderedChildren = true;
256
+ }
257
+ }
258
+ node.parent = this;
259
+ if (beforeNode) {
260
+ // SolidJS can move nodes around in the children array.
261
+ // We need to insert following DOM insertBefore which moves elements.
262
+ spliceItem(this.children, node, 1);
263
+ if (spliceItem(this.children, beforeNode, 0, node) > -1) {
264
+ return;
265
+ }
266
+ }
267
+ this.children.push(node);
268
+ }
269
+ removeChild(node) {
270
+ if (spliceItem(this.children, node, 1) > -1) {
271
+ node.onRemove?.call(node, node);
272
+ if (this.requiresLayout()) {
273
+ addToLayoutQueue(this);
274
+ }
275
+ }
276
+ }
277
+ get selectedNode() {
278
+ const selectedIndex = this.selected || 0;
279
+ for (let i = selectedIndex; i < this.children.length; i++) {
280
+ const element = this.children[i];
281
+ if (isElementNode(element)) {
282
+ this.selected = i;
283
+ return element;
284
+ }
285
+ }
286
+ return undefined;
287
+ }
288
+ set shader(shaderProps) {
289
+ this.lng.shader = isArray(shaderProps)
290
+ ? renderer.createShader(...shaderProps)
291
+ : shaderProps;
292
+ }
293
+ _sendToLightningAnimatable(name, value) {
294
+ if (this.transition &&
295
+ this.rendered &&
296
+ Config.animationsEnabled &&
297
+ (this.transition === true ||
298
+ this.transition[name] ||
299
+ this.transition[getPropertyAlias(name)])) {
300
+ const animationSettings = this.transition === true || this.transition[name] === true
301
+ ? undefined
302
+ : this.transition[name] ||
303
+ this.transition[getPropertyAlias(name)];
304
+ return this.lng.animateProp(name, value, animationSettings || this.animationSettings || {});
305
+ }
306
+ this.lng[name] =
307
+ value;
308
+ }
309
+ animate(props, animationSettings) {
310
+ isDev &&
311
+ assertTruthy(this.rendered, 'Node must be rendered before animating');
312
+ return this.lng.animate(props, animationSettings || this.animationSettings || {});
313
+ }
314
+ chain(props, animationSettings) {
315
+ if (this._animationRunning) {
316
+ this._animationQueue = [];
317
+ this._animationRunning = false;
318
+ }
319
+ if (animationSettings) {
320
+ this._animationQueueSettings = animationSettings;
321
+ }
322
+ else if (!this._animationQueueSettings) {
323
+ this._animationQueueSettings =
324
+ animationSettings || this.animationSettings;
325
+ }
326
+ animationSettings = animationSettings || this._animationQueueSettings;
327
+ this._animationQueue = this._animationQueue || [];
328
+ this._animationQueue.push({ props, animationSettings });
329
+ return this;
330
+ }
331
+ async start() {
332
+ let animation = this._animationQueue.shift();
333
+ while (animation) {
334
+ this._animationRunning = true;
335
+ await this.animate(animation.props, animation.animationSettings)
336
+ .start()
337
+ .waitUntilStopped();
338
+ animation = this._animationQueue.shift();
339
+ }
340
+ this._animationRunning = false;
341
+ this._animationQueueSettings = undefined;
342
+ }
343
+ emit(event, ...args) {
344
+ let current = this;
345
+ const capitalizedEvent = `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
346
+ while (current) {
347
+ const handler = current[capitalizedEvent];
348
+ if (isFunction(handler)) {
349
+ if (handler.call(current, this, ...args) === true) {
350
+ return true;
351
+ }
352
+ }
353
+ current = current.parent;
354
+ }
355
+ return false;
356
+ }
357
+ setFocus() {
358
+ if (this.rendered) {
359
+ // can be 0
360
+ if (this.forwardFocus !== undefined) {
361
+ if (isFunc(this.forwardFocus)) {
362
+ if (this.forwardFocus.call(this, this) !== false) {
363
+ return;
364
+ }
365
+ }
366
+ else {
367
+ const focusedIndex = typeof this.forwardFocus === 'number' ? this.forwardFocus : null;
368
+ const nodes = this.children;
369
+ if (focusedIndex !== null && focusedIndex < nodes.length) {
370
+ const child = nodes[focusedIndex];
371
+ isElementNode(child) && child.setFocus();
372
+ return;
373
+ }
374
+ }
375
+ }
376
+ // Delay setting focus so children can render (useful for Row + Column)
377
+ nextActiveElement = this;
378
+ if (focusQueued === false) {
379
+ focusQueued = true;
380
+ queueMicrotask(() => {
381
+ focusQueued = false;
382
+ if (nextActiveElement) {
383
+ const element = nextActiveElement;
384
+ nextActiveElement = null;
385
+ setActiveElement(element);
386
+ }
387
+ });
388
+ }
389
+ }
390
+ else {
391
+ this._autofocus = true;
392
+ }
393
+ }
394
+ _layoutOnLoad() {
395
+ this.lng.on('loaded', () => {
396
+ if ('reprocessUpdates' in renderer.stage &&
397
+ renderer.stage.reprocessUpdates) {
398
+ renderer.stage.reprocessUpdates(runLayout);
399
+ }
400
+ this.parent.updateLayout();
401
+ });
402
+ }
403
+ getText() {
404
+ let result = '';
405
+ for (let i = 0; i < this.children.length; i++) {
406
+ result += this.children[i].text;
407
+ }
408
+ return result;
409
+ }
410
+ destroy() {
411
+ if (this.onDestroy) {
412
+ const destroyPromise = this.onDestroy(this);
413
+ // If onDestroy returns a promise, wait for it to resolve before destroying
414
+ // Useful with animations waitUntilStopped method which returns promise
415
+ if (destroyPromise instanceof Promise) {
416
+ destroyPromise.then(() => this._destroy());
417
+ }
418
+ else {
419
+ this._destroy();
420
+ }
421
+ }
422
+ else {
423
+ this._destroy();
424
+ }
425
+ }
426
+ _destroy() {
427
+ if (isINode(this.lng)) {
428
+ this.lng.destroy();
429
+ }
430
+ }
431
+ set style(style) {
432
+ if (isDev && this._style) {
433
+ // Avoid processing style changes again
434
+ console.warn('Style already set: https://lightning-tv.github.io/solid/#/essentials/styling?id=style-patterns-to-avoid');
435
+ }
436
+ if (Config.lockStyles && this._style) {
437
+ return;
438
+ }
439
+ if (!style) {
440
+ return;
441
+ }
442
+ this._style = style;
443
+ // Keys set in JSX are more important
444
+ for (const key in this._style) {
445
+ // be careful of 0 values
446
+ if (this[key] === undefined) {
447
+ this[key] = this._style[key];
448
+ }
449
+ }
450
+ }
451
+ get style() {
452
+ return this._style || {};
453
+ }
454
+ set theme(styles) {
455
+ if (!styles) {
456
+ return;
457
+ }
458
+ this._theme = styles;
459
+ for (const key in styles) {
460
+ this[key] = styles[key];
461
+ }
462
+ }
463
+ get theme() {
464
+ this._theme = this._theme || {};
465
+ return this._theme;
466
+ }
467
+ get hasChildren() {
468
+ return this.children.length > 0;
469
+ }
470
+ set src(src) {
471
+ if (typeof src === 'string') {
472
+ this.lng.src = src;
473
+ if (!this.color && this.rendered) {
474
+ this.color = 0xffffffff;
475
+ }
476
+ }
477
+ else {
478
+ this.color = 0x00000000;
479
+ }
480
+ }
481
+ get src() {
482
+ return this.lng.src;
483
+ }
484
+ getChildById(id) {
485
+ return this.children.find((c) => c.id === id);
486
+ }
487
+ searchChildrenById(id) {
488
+ // traverse all the childrens children
489
+ for (let i = 0; i < this.children.length; i++) {
490
+ const child = this.children[i];
491
+ if (isElementNode(child)) {
492
+ if (child.id === id) {
493
+ return child;
494
+ }
495
+ const found = child.searchChildrenById(id);
496
+ if (found) {
497
+ return found;
498
+ }
499
+ }
500
+ }
501
+ }
502
+ set states(states) {
503
+ this._states = this._states
504
+ ? this._states.merge(states)
505
+ : new States(this._stateChanged.bind(this), states);
506
+ if (this.rendered) {
507
+ this._stateChanged();
508
+ }
509
+ }
510
+ get states() {
511
+ this._states = this._states || new States(this._stateChanged.bind(this));
512
+ return this._states;
513
+ }
514
+ get animationSettings() {
515
+ return this._animationSettings || Config.animationSettings;
516
+ }
517
+ set animationSettings(animationSettings) {
518
+ this._animationSettings = animationSettings;
519
+ }
520
+ set hidden(val) {
521
+ this.alpha = val ? 0 : 1;
522
+ }
523
+ get hidden() {
524
+ return this.alpha === 0;
525
+ }
526
+ /**
527
+ * Sets the autofocus state of the element.
528
+ * When set to a truthy value, the element will automatically gain focus.
529
+ * You can also set it to a signal to recalculate
530
+ *
531
+ * @param val - A value to determine if the element should autofocus.
532
+ * A truthy value enables autofocus, otherwise disables it.
533
+ */
534
+ set autofocus(val) {
535
+ this._autofocus = val;
536
+ // Delay setting focus so children can render (useful for Row + Column)
537
+ // which now uses forwardFocus
538
+ val && queueMicrotask(() => this.setFocus());
539
+ }
540
+ get autofocus() {
541
+ return this._autofocus;
542
+ }
543
+ requiresLayout() {
544
+ return this.display === 'flex' || this.onLayout;
545
+ }
546
+ set updateLayoutOn(v) {
547
+ this.updateLayout();
548
+ }
549
+ get updateLayoutOn() {
550
+ return null;
551
+ }
552
+ updateLayout() {
553
+ if (this.hasChildren) {
554
+ isDev && log('Layout: ', this);
555
+ if (this.display === 'flex' && this.flexGrow && this.width === 0) {
556
+ return;
557
+ }
558
+ const flexChanged = this.display === 'flex' && calculateFlex(this);
559
+ layoutQueue.delete(this);
560
+ const onLayoutChanged = isFunc(this.onLayout) && this.onLayout.call(this, this);
561
+ if ((flexChanged || onLayoutChanged) && this.parent) {
562
+ addToLayoutQueue(this.parent);
563
+ }
564
+ if (this._containsFlexGrow === true) {
565
+ // Need to reprocess children
566
+ this.children.forEach((c) => {
567
+ if (c.display === 'flex' && isElementNode(c)) {
568
+ // calculating directly to prevent infinite loops recalculating parents
569
+ calculateFlex(c);
570
+ isFunc(c.onLayout) && c.onLayout.call(c, c);
571
+ addToLayoutQueue(this);
572
+ }
573
+ });
574
+ }
575
+ }
576
+ }
577
+ _stateChanged() {
578
+ isDev && log('State Changed: ', this, this.states);
579
+ if (this.forwardStates) {
580
+ // apply states to children first
581
+ const states = this.states.slice();
582
+ this.children.forEach((c) => {
583
+ c.states = states;
584
+ });
585
+ }
586
+ const states = this.states;
587
+ if (this._undoStyles || keyExists(this, states)) {
588
+ let stylesToUndo;
589
+ if (this._undoStyles && this._undoStyles.length) {
590
+ stylesToUndo = {};
591
+ this._undoStyles.forEach((styleKey) => {
592
+ let fallbackValue = this.theme[styleKey];
593
+ if (fallbackValue === undefined) {
594
+ fallbackValue = this.style[styleKey];
595
+ }
596
+ if (isDev) {
597
+ if (fallbackValue === undefined) {
598
+ console.warn('fallback style key not found: ', styleKey);
599
+ }
600
+ }
601
+ stylesToUndo[styleKey] = fallbackValue;
602
+ });
603
+ }
604
+ const numStates = states.length;
605
+ if (numStates === 0) {
606
+ Object.assign(this, stylesToUndo);
607
+ this._undoStyles = [];
608
+ return;
609
+ }
610
+ let newStyles;
611
+ if (numStates === 1) {
612
+ newStyles = this[states[0]];
613
+ newStyles = stylesToUndo
614
+ ? { ...stylesToUndo, ...newStyles }
615
+ : newStyles;
616
+ }
617
+ else {
618
+ let sortedStates = states;
619
+ const stateOrder = this.stateOrder || Config.stateOrder;
620
+ if (stateOrder && stateOrder.length > 0) {
621
+ sortedStates = states.slice().sort((a, b) => {
622
+ const aIdx = stateOrder.indexOf(a);
623
+ const bIdx = stateOrder.indexOf(b);
624
+ // If a state is in the stateOrder, it should have higher specificity
625
+ // than states not in the stateOrder.
626
+ if (aIdx !== -1 && bIdx === -1)
627
+ return 1;
628
+ if (aIdx === -1 && bIdx !== -1)
629
+ return -1;
630
+ return aIdx - bIdx;
631
+ });
632
+ }
633
+ newStyles = sortedStates.reduce((acc, state) => {
634
+ const styles = this[state];
635
+ return styles ? { ...acc, ...styles } : acc;
636
+ }, stylesToUndo || {});
637
+ }
638
+ if (newStyles) {
639
+ this._undoStyles = Object.keys(newStyles);
640
+ // Apply transition first
641
+ if (newStyles.transition !== undefined) {
642
+ this.transition = newStyles.transition;
643
+ }
644
+ // Apply the styles
645
+ Object.assign(this, newStyles);
646
+ }
647
+ else {
648
+ this._undoStyles = [];
649
+ }
650
+ }
651
+ }
652
+ render(topNode) {
653
+ // Elements are inserted from the inside out, then rendered from the outside in.
654
+ // Render starts when an element is inserted with a parent that is already renderered.
655
+ const node = this;
656
+ const parent = this.parent;
657
+ if (!parent) {
658
+ console.warn('Parent not set - no node created for: ', this);
659
+ return;
660
+ }
661
+ if (!parent.rendered) {
662
+ console.warn('Parent not rendered yet: ', this);
663
+ return;
664
+ }
665
+ if (parent.requiresLayout()) {
666
+ layoutQueue.add(parent);
667
+ }
668
+ if (this.rendered) {
669
+ // This happens if Array of items is reordered to reuse elements.
670
+ // We return after layout is queued so the change can trigger layout updates.
671
+ this.onRender?.(this);
672
+ return;
673
+ }
674
+ if (this._states) {
675
+ this._stateChanged();
676
+ }
677
+ const props = node.lng;
678
+ const parentWidth = parent.w || 0;
679
+ const parentHeight = parent.h || 0;
680
+ props.x = props.x || 0;
681
+ props.y = props.y || 0;
682
+ props.parent = parent.lng;
683
+ if (this.right || this.right === 0) {
684
+ props.x = parentWidth - this.right;
685
+ props.mountX = 1;
686
+ }
687
+ if (this.bottom || this.bottom === 0) {
688
+ props.y = parentHeight - this.bottom;
689
+ props.mountY = 1;
690
+ }
691
+ if (this.center) {
692
+ this.centerX = this.centerY = true;
693
+ }
694
+ if (this.centerX) {
695
+ props.x += parentWidth / 2;
696
+ props.mountX = 0.5;
697
+ }
698
+ if (this.centerY) {
699
+ props.y += parentHeight / 2;
700
+ props.mountY = 0.5;
701
+ }
702
+ if (isElementText(node)) {
703
+ const textProps = props;
704
+ if (Config.fontSettings) {
705
+ for (const key in Config.fontSettings) {
706
+ if (textProps[key] === undefined) {
707
+ let value = Config.fontSettings[key];
708
+ if (key === 'fontFamily' && textProps['fontWeight'] === undefined) {
709
+ value = `${value}${Config.fontSettings.fontWeight || ''}`;
710
+ }
711
+ textProps[key] = value;
712
+ }
713
+ }
714
+ }
715
+ textProps.text = textProps.text || node.getText();
716
+ if (textProps.textAlign && !textProps.contain) {
717
+ console.warn('Text align requires contain: ', node.getText());
718
+ }
719
+ // contain is either width or both
720
+ if (textProps.contain) {
721
+ if (textProps.contain === 'both') {
722
+ textProps.maxWidth = textProps.maxWidth ?? textProps.w;
723
+ textProps.maxHeight = textProps.maxHeight ?? textProps.h;
724
+ }
725
+ else if (textProps.contain === 'width') {
726
+ textProps.maxWidth = textProps.maxWidth ?? textProps.w;
727
+ }
728
+ if (!textProps.h && !textProps.maxHeight) {
729
+ textProps.maxLines = textProps.maxLines ?? 99;
730
+ }
731
+ if (!textProps.maxWidth) {
732
+ textProps.maxWidth =
733
+ parentWidth - textProps.x - (textProps.marginRight || 0);
734
+ }
735
+ if (textProps.contain === 'both' && !textProps.maxHeight) {
736
+ textProps.maxHeight =
737
+ parentHeight - textProps.y - (textProps.marginBottom || 0);
738
+ }
739
+ else if (textProps.maxLines === 1) {
740
+ textProps.maxHeight = (textProps.maxHeight ||
741
+ textProps.lineHeight ||
742
+ textProps.fontSize);
743
+ }
744
+ // textProps.w = textProps.h = 0;
745
+ }
746
+ // Can you put effects on Text nodes? Need to confirm...
747
+ if (SHADERS_ENABLED && props.shader && !props.shader.program) {
748
+ props.shader = Config.convertToShader(node, props.shader);
749
+ }
750
+ isDev && log('Rendering: ', this, props);
751
+ node.lng = renderer.createTextNode(props);
752
+ if (parent.requiresLayout()) {
753
+ if (!textProps.maxWidth || !textProps.maxHeight) {
754
+ node._layoutOnLoad();
755
+ }
756
+ }
757
+ }
758
+ else {
759
+ // If its not an image or texture apply some defaults
760
+ if (!props.texture) {
761
+ // Set width and height to parent less offset
762
+ if (isNaN(props.w)) {
763
+ props.w = node.flexGrow ? 0 : parentWidth - props.x;
764
+ node._calcWidth = true;
765
+ }
766
+ if (isNaN(props.h)) {
767
+ props.h = parentHeight - props.y;
768
+ node._calcHeight = true;
769
+ }
770
+ if (props.rtt && !props.color) {
771
+ props.color = 0xffffffff;
772
+ }
773
+ if (!props.color && !props.src) {
774
+ // Default color to transparent - If you later set a src, you'll need
775
+ // to set color '#ffffffff'
776
+ props.color = 0x00000000;
777
+ }
778
+ }
779
+ if (SHADERS_ENABLED && props.shader && !props.shader.program) {
780
+ props.shader = Config.convertToShader(node, props.shader);
781
+ }
782
+ isDev && log('Rendering: ', this, props);
783
+ node.lng = renderer.createNode(props);
784
+ if (node._hasRenderedChildren) {
785
+ node._hasRenderedChildren = false;
786
+ for (const child of node.children) {
787
+ if (isElementNode(child) && isINode(child.lng)) {
788
+ child.lng.parent = node.lng;
789
+ }
790
+ }
791
+ }
792
+ }
793
+ node.rendered = true;
794
+ if (isDev) {
795
+ // Store props so we can recreate raw renderer code
796
+ node._rendererProps = props;
797
+ }
798
+ if (node.autosize && parent.requiresLayout()) {
799
+ node._layoutOnLoad();
800
+ }
801
+ this.onCreate?.(this);
802
+ this.onRender?.(this);
803
+ if (node.onEvent) {
804
+ for (const [name, handler] of Object.entries(node.onEvent)) {
805
+ if (typeof node.lng.on === 'function') {
806
+ node.lng.on(name, (_inode, data) => handler.call(node, node, data));
807
+ }
808
+ }
809
+ }
810
+ // L3 Inspector adds div to the lng object
811
+ const div = node.lng?.div;
812
+ if (div)
813
+ div.element = node;
814
+ if (node._type === NodeType.Element) {
815
+ // only element nodes will have children that need rendering
816
+ const numChildren = node.children.length;
817
+ for (let i = 0; i < numChildren; i++) {
818
+ const c = node.children[i];
819
+ isDev && assertTruthy(c, 'Child is undefined');
820
+ // Text elements sneak in from Solid creating tracked nodes
821
+ if (isElementNode(c)) {
822
+ c.render();
823
+ }
824
+ }
825
+ }
826
+ if (topNode && !layoutRunQueued) {
827
+ //Do one pass of layout, then another with Text loads
828
+ layoutRunQueued = true;
829
+ // We use queue because <For> loop will add children one at a time, causing lots of layout
830
+ queueMicrotask(runLayout);
831
+ }
832
+ node._autofocus && node.setFocus();
833
+ }
834
+ }
835
+ for (const key of LightningRendererNumberProps) {
836
+ Object.defineProperty(ElementNode.prototype, key, {
837
+ get() {
838
+ return this.lng[key];
839
+ },
840
+ set(v) {
841
+ this._sendToLightningAnimatable(key, v);
842
+ },
843
+ });
844
+ }
845
+ for (const key of LightningRendererNonAnimatingProps) {
846
+ Object.defineProperty(ElementNode.prototype, key, {
847
+ get() {
848
+ return this.lng[key];
849
+ },
850
+ set(v) {
851
+ this.lng[key] = v;
852
+ },
853
+ });
854
+ }
855
+ export function createRawShaderAccessor(key) {
856
+ return {
857
+ set(value) {
858
+ this.shader = [key, value];
859
+ },
860
+ get() {
861
+ return this.shader;
862
+ },
863
+ };
864
+ }
865
+ export function shaderAccessor(key) {
866
+ return {
867
+ set(value) {
868
+ let target = this.lng.shader || {};
869
+ this._effects = this._effects || {};
870
+ this._effects[key] = value;
871
+ let animationSettings;
872
+ if (this.lng.shader?.props) {
873
+ target = this.lng.shader.props;
874
+ const transitionKey = key === 'rounded' ? 'borderRadius' : key;
875
+ if (this.transition &&
876
+ (this.transition === true || this.transition[transitionKey])) {
877
+ target = {};
878
+ animationSettings =
879
+ this.transition === true || this.transition[transitionKey] === true
880
+ ? undefined
881
+ : this.transition[transitionKey];
882
+ }
883
+ }
884
+ if (key === 'rounded' || typeof value === 'number') {
885
+ target.radius = value;
886
+ }
887
+ else {
888
+ parseAndAssignShaderProps(key, value, target);
889
+ }
890
+ if (this.rendered) {
891
+ if (!this.lng.shader) {
892
+ this.lng.shader = Config.convertToShader(this, target);
893
+ }
894
+ else if (DOM_RENDERING && Config.domRendererEnabled) {
895
+ this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
896
+ }
897
+ }
898
+ else {
899
+ this.lng.shader = target;
900
+ }
901
+ if (animationSettings) {
902
+ this.animate({ shaderProps: target }, animationSettings).start();
903
+ }
904
+ },
905
+ get() {
906
+ return this._effects?.[key];
907
+ },
908
+ };
909
+ }
910
+ if (isDev) {
911
+ ElementNode.prototype.lngTree = function () {
912
+ return logRenderTree(this);
913
+ };
914
+ }
915
+ Object.defineProperties(ElementNode.prototype, {
916
+ border: shaderAccessor('border'),
917
+ borderBottom: shaderAccessor('borderBottom'),
918
+ borderTop: shaderAccessor('borderTop'),
919
+ borderLeft: shaderAccessor('borderLeft'),
920
+ borderRight: shaderAccessor('borderRight'),
921
+ shadow: shaderAccessor('shadow'),
922
+ rounded: shaderAccessor('rounded'),
923
+ // Alias for rounded
924
+ borderRadius: shaderAccessor('rounded'),
925
+ linearGradient: createRawShaderAccessor('linearGradient'),
926
+ radialGradient: createRawShaderAccessor('radialGradient'),
927
+ });
928
+ //# sourceMappingURL=elementNode.js.map