@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,1623 @@
1
+ import { renderer } from './lightningInit.js';
2
+ import {
3
+ type BorderRadius,
4
+ type BorderStyle,
5
+ type StyleEffects,
6
+ type AnimationSettings,
7
+ type ElementText,
8
+ type Styles,
9
+ AddColorString,
10
+ TextProps,
11
+ TextNode,
12
+ type OnEvent,
13
+ NewOmit,
14
+ SingleBorderStyle,
15
+ type DollarString,
16
+ } from './intrinsicTypes.js';
17
+ import States, { type NodeStates } from './states.js';
18
+ import calculateFlexOld from './flex.js';
19
+ import calculateFlexNew from './flexLayout.js';
20
+
21
+ const calculateFlex = (import.meta as any).env?.VITE_USE_NEW_FLEX
22
+ ? calculateFlexNew
23
+ : calculateFlexOld;
24
+ import {
25
+ log,
26
+ isArray,
27
+ isFunc,
28
+ keyExists,
29
+ isINode,
30
+ isElementNode,
31
+ isElementText,
32
+ logRenderTree,
33
+ isFunction,
34
+ spliceItem,
35
+ } from './utils.js';
36
+ import { Config, DOM_RENDERING, isDev, SHADERS_ENABLED } from './config.js';
37
+ import type {
38
+ RendererMain,
39
+ INode,
40
+ INodeAnimateProps,
41
+ IAnimationController,
42
+ LinearGradientProps,
43
+ RadialGradientProps,
44
+ ShadowProps,
45
+ CoreShaderNode,
46
+ ITextNodeProps,
47
+ INodeProps,
48
+ } from '@solidtv/renderer';
49
+ import { assertTruthy } from '@solidtv/renderer/utils';
50
+ import { NodeType } from './nodeTypes.js';
51
+ import {
52
+ ForwardFocusHandler,
53
+ setActiveElement,
54
+ FocusNode,
55
+ } from './focusManager.js';
56
+
57
+ import {
58
+ IRendererNode,
59
+ IRendererNodeProps,
60
+ IRendererShader,
61
+ IRendererShaderProps,
62
+ IRendererTextNode,
63
+ IRendererTextNodeProps,
64
+ } from './dom-renderer/domRendererTypes.js';
65
+
66
+ let nextActiveElement: ElementNode | null = null;
67
+ let focusQueued: boolean = false;
68
+ let layoutRunQueued = false;
69
+ const layoutQueue = new Set<ElementNode>();
70
+
71
+ function addToLayoutQueue(node: ElementNode) {
72
+ layoutQueue.add(node);
73
+ if (!layoutRunQueued) {
74
+ layoutRunQueued = true;
75
+ if (
76
+ 'reprocessUpdates' in renderer.stage &&
77
+ renderer.stage.reprocessUpdates
78
+ ) {
79
+ renderer.stage.reprocessUpdates(runLayout);
80
+ } else {
81
+ queueMicrotask(runLayout);
82
+ }
83
+ }
84
+ }
85
+
86
+ function runLayout() {
87
+ while (layoutQueue.size > 0) {
88
+ const queue = [...layoutQueue];
89
+ layoutQueue.clear();
90
+ for (let i = queue.length - 1; i >= 0; i--) {
91
+ const node = queue[i] as ElementNode;
92
+ node.updateLayout();
93
+ }
94
+ }
95
+ layoutRunQueued = false;
96
+ }
97
+
98
+ const parseAndAssignShaderProps = (
99
+ prefix: string,
100
+ obj: Record<string, any>,
101
+ props: Record<string, any> = {},
102
+ ) => {
103
+ if (!obj) return;
104
+
105
+ // Handle individual border sides: transform width/w to bottom/left/right/top
106
+ const borderSideMap: Record<string, string> = {
107
+ borderBottom: 'bottom',
108
+ borderLeft: 'left',
109
+ borderRight: 'right',
110
+ borderTop: 'top',
111
+ };
112
+
113
+ const side = borderSideMap[prefix];
114
+ const actualPrefix = side ? 'border' : prefix;
115
+
116
+ props[actualPrefix] = obj;
117
+ Object.entries(obj).forEach(([key, value]) => {
118
+ let transformedKey = key === 'width' ? 'w' : key;
119
+
120
+ // If border side and key is width/w, transform to side (bottom/left/right/top)
121
+ if (side && transformedKey === 'w') {
122
+ transformedKey = side;
123
+ }
124
+
125
+ props[`${actualPrefix}-${transformedKey}`] = value;
126
+ });
127
+ };
128
+
129
+ export function convertToShader(
130
+ _node: ElementNode,
131
+ v: StyleEffects,
132
+ ): IRendererShader {
133
+ let type = 'rounded';
134
+ if (v.border) type += 'WithBorder';
135
+ if (v.shadow) type += 'WithShadow';
136
+ return renderer.createShader(type, v);
137
+ }
138
+
139
+ function getPropertyAlias(name: string) {
140
+ if (name === 'w') return 'width';
141
+ if (name === 'h') return 'height';
142
+ return name;
143
+ }
144
+
145
+ export const LightningRendererNumberProps = [
146
+ 'alpha',
147
+ 'color',
148
+ 'colorTop',
149
+ 'colorRight',
150
+ 'colorLeft',
151
+ 'colorBottom',
152
+ 'colorTl',
153
+ 'colorTr',
154
+ 'colorBl',
155
+ 'colorBr',
156
+ 'h',
157
+ 'fontSize',
158
+ 'lineHeight',
159
+ 'mount',
160
+ 'mountX',
161
+ 'mountY',
162
+ 'pivot',
163
+ 'pivotX',
164
+ 'pivotY',
165
+ 'rotation',
166
+ 'scale',
167
+ 'scaleX',
168
+ 'scaleY',
169
+ 'w',
170
+ 'worldX',
171
+ 'worldY',
172
+ 'x',
173
+ 'y',
174
+ 'zIndex',
175
+ 'zIndexLocked',
176
+ ];
177
+
178
+ const LightningRendererNonAnimatingProps = [
179
+ 'absX',
180
+ 'absY',
181
+ 'autosize',
182
+ 'clipping',
183
+ 'contain',
184
+ 'data',
185
+ 'destroyed',
186
+ 'forceLoad',
187
+ 'fontStretch',
188
+ 'fontStyle',
189
+ 'group',
190
+ 'imageType',
191
+ 'letterSpacing',
192
+ 'maxHeight',
193
+ 'maxLines',
194
+ 'maxWidth',
195
+ 'offsetY',
196
+ 'overflowSuffix',
197
+ 'preventCleanup',
198
+ 'rtt',
199
+ 'scrollable',
200
+ 'scrollY',
201
+ 'srcHeight',
202
+ 'srcWidth',
203
+ 'srcX',
204
+ 'srcY',
205
+ 'strictBounds',
206
+ 'text',
207
+ 'textAlign',
208
+ 'textBaseline',
209
+ 'textOverflow',
210
+ 'texture',
211
+ 'textureOptions',
212
+ 'textRendererOverride',
213
+ 'verticalAlign',
214
+ 'wordBreak',
215
+ 'wordWrap',
216
+ ];
217
+
218
+ declare global {
219
+ interface HTMLElement {
220
+ /** Assigned for development, to quickly get ElementNode from selected HTMLElement */
221
+ element?: ElementNode;
222
+ }
223
+ }
224
+
225
+ export type RendererNode = AddColorString<
226
+ Partial<
227
+ NewOmit<
228
+ INode,
229
+ 'parent' | 'shader' | 'src' | 'children' | 'id' | 'removeChild'
230
+ >
231
+ >
232
+ >;
233
+ export interface ElementNode extends RendererNode, FocusNode {
234
+ [key: string]: unknown;
235
+
236
+ // Properties
237
+ /** @internal for managing series of insertions and deletions */
238
+ _queueDelete?: number;
239
+ preserve?: boolean;
240
+ _animationQueue?:
241
+ | Array<{
242
+ props: Partial<INodeAnimateProps<CoreShaderNode>>;
243
+ animationSettings?: AnimationSettings;
244
+ }>
245
+ | undefined;
246
+ _animationQueueSettings?: AnimationSettings;
247
+ _animationRunning?: boolean;
248
+ _animationSettings?: AnimationSettings;
249
+ _autofocus?: boolean;
250
+ _containsFlexGrow?: boolean | null;
251
+ _hasRenderedChildren?: boolean;
252
+ _effects?: Record<string, any>;
253
+ _fontFamily?: string;
254
+ _id: string | undefined;
255
+ _parent: ElementNode | undefined;
256
+ _rendererProps?: any;
257
+ _states?: States;
258
+ _style?: Styles;
259
+ _theme?: Styles;
260
+ _lastAnyKeyPressTime?: number;
261
+ _type: 'element' | 'textNode';
262
+ _undoStyles?: string[];
263
+ autosize?: boolean;
264
+ /**
265
+ * The distance from the bottom edge of the parent element.
266
+ * When `bottom` is set, `mountY` is automatically set to 1.
267
+ *
268
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
269
+ */
270
+ bottom?: number;
271
+ /**
272
+ * An array of child `ElementNode` or `ElementText` nodes.
273
+ */
274
+ children: Array<ElementNode | ElementText>;
275
+ /**
276
+ * Enable debug logging for this specific node.
277
+ */
278
+ debug?: boolean;
279
+ /**
280
+ * Specifies how much a flex item should grow relative to the rest of the flex items.
281
+ *
282
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex-grow
283
+ */
284
+ flexGrow?: number;
285
+ /**
286
+ * Specifies whether flex items are forced onto one line or can wrap onto multiple lines.
287
+ *
288
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
289
+ */
290
+ flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
291
+ /**
292
+ * Determines if an element is a flex item. If set to `false`, the element will be ignored by the flexbox layout.
293
+ * @default false
294
+ */
295
+ flexItem?: boolean;
296
+ /**
297
+ * Specifies the order of a flex item relative to the rest of the flex items.
298
+ *
299
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
300
+ */
301
+ flexOrder?: number;
302
+ /**
303
+ * Defines the ability for a flex item to shrink if necessary.
304
+ * Defaults to 0 since existing legacy implementations did not shrink layout boxes.
305
+ * Only available in NEW flex layout.
306
+ */
307
+ flexShrink?: number;
308
+ /**
309
+ * Defines the default size of an element before the remaining space is distributed.
310
+ * Only available in NEW flex layout.
311
+ */
312
+ flexBasis?: number | string;
313
+ /**
314
+ * Forwards focus to a child element. It can be a numeric index of the child or a handler function.
315
+ *
316
+ * @see https://lightning-tv.github.io/solid/#/essentials/focus?id=forwardfocus
317
+ */
318
+ forwardFocus?: number | ForwardFocusHandler;
319
+ /**
320
+ * If `true`, the states of this node will be propagated to its children.
321
+ *
322
+ * @see https://lightning-tv.github.io/solid/#/essentials/states?id=forwardstates
323
+ */
324
+ forwardStates?: boolean;
325
+ /**
326
+ * The underlying Lightning Renderer node object. This is where the properties are ultimately set for rendering.
327
+ */
328
+ lng:
329
+ | INode
330
+ | IRendererNode
331
+ | Partial<ElementNode>
332
+ | (IRendererTextNode & { shader?: any });
333
+ /**
334
+ * A reference to the `ElementNode` instance. Can be an object or a callback function.
335
+ */
336
+ ref?: ElementNode | ((node: ElementNode) => void) | undefined;
337
+ /**
338
+ * A boolean indicating whether the node has been rendered.
339
+ */
340
+ rendered: boolean;
341
+ /**
342
+ * The main renderer instance.
343
+ */
344
+ renderer?: RendererMain;
345
+ /**
346
+ * The distance from the right edge of the parent element.
347
+ * When `right` is set, `mountX` is automatically set to 1.
348
+ *
349
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=layout-and-positioning-elements
350
+ */
351
+ right?: number;
352
+ /**
353
+ * The index of the currently selected child element, used for focus management for Column and Row components.
354
+ */
355
+ selected?: number;
356
+ /**
357
+ * The width of the element before flexbox layout is applied. Used internally for layout calculations.
358
+ */
359
+ preFlexwidth?: number;
360
+ /**
361
+ * The height of the element before flexbox layout is applied. Used internally for layout calculations.
362
+ */
363
+ preFlexheight?: number;
364
+ /**
365
+ * The text content of a text node.
366
+ */
367
+ text?: string;
368
+ /**
369
+ * Aligns flex items along the cross axis of the current line of the flex container.
370
+ *
371
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex-properties
372
+ */
373
+ alignItems?: 'flexStart' | 'flexEnd' | 'center';
374
+ /**
375
+ * Aligns a flex item along the cross axis, overriding the `alignItems` value of the flex container.
376
+ *
377
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex-properties
378
+ */
379
+ alignSelf?: 'flexStart' | 'flexEnd' | 'center';
380
+ /**
381
+ * The border style for all sides of the element. Takes an object with width and color properties.
382
+ *
383
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
384
+ */
385
+ border?: BorderStyle;
386
+ /**
387
+ * The border style for the bottom side of the element.
388
+ *
389
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
390
+ */
391
+ borderBottom?: SingleBorderStyle;
392
+ /**
393
+ * The border style for the left side of the element.
394
+ *
395
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
396
+ */
397
+ borderLeft?: SingleBorderStyle;
398
+ /**
399
+ * The radius of the element's corners.
400
+ *
401
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
402
+ */
403
+ borderRadius?: BorderRadius;
404
+ /**
405
+ * The border style for the right side of the element.
406
+ *
407
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
408
+ */
409
+ borderRight?: SingleBorderStyle;
410
+ /**
411
+ * The border style for the top side of the element.
412
+ *
413
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects?id=border-and-borderradius
414
+ */
415
+ borderTop?: SingleBorderStyle;
416
+ /**
417
+ * A shorthand to set both `centerX` and `centerY` to true.
418
+ *
419
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=layout-and-positioning-elements
420
+ */
421
+ center?: boolean;
422
+ /**
423
+ * If `true`, centers the element horizontally within its parent.
424
+ *
425
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=layout-and-positioning-elements
426
+ */
427
+ centerX?: boolean;
428
+ /**
429
+ * If `true`, centers the element vertically within its parent.
430
+ *
431
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=layout-and-positioning-elements
432
+ */
433
+ centerY?: boolean;
434
+ /**
435
+ * Specifies the direction of the flex items.
436
+ *
437
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
438
+ */
439
+ direction?: 'ltr' | 'rtl';
440
+ /**
441
+ * Specifies the display behavior of an element. 'flex' enables flexbox layout.
442
+ *
443
+ * @default 'block'
444
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
445
+ */
446
+ display?: 'flex' | 'block';
447
+ /**
448
+ * Defines how the flex container's size is determined. 'contain' allows it to grow with its content, 'fixed' keeps it at its specified size.
449
+ *
450
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
451
+ */
452
+ flexBoundary?: 'contain' | 'fixed';
453
+ /**
454
+ * Defines how the flex container's cross-axis size is determined. 'fixed' keeps it at its specified size. Default is 'contain'.
455
+ *
456
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
457
+ */
458
+ flexCrossBoundary?: 'fixed'; // default is contain
459
+ /**
460
+ * Specifies the direction of the main axis for flex items.
461
+ *
462
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
463
+ */
464
+ flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
465
+ /**
466
+ * The gap between flex items.
467
+ *
468
+ * @see @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
469
+ */
470
+ gap?: number;
471
+ /**
472
+ * The gap between flex rows.
473
+ *
474
+ * @see @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
475
+ */
476
+ rowGap?: number;
477
+ /**
478
+ * The gap between flex columns.
479
+ *
480
+ * @see @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
481
+ */
482
+ columnGap?: number;
483
+ /**
484
+ * Defines the alignment of flex items along the main axis.
485
+ *
486
+ * @see @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
487
+ */
488
+ justifyContent?:
489
+ | 'flexStart'
490
+ | 'flexEnd'
491
+ | 'center'
492
+ | 'spaceBetween'
493
+ | 'spaceAround'
494
+ | 'spaceEvenly';
495
+ /**
496
+ * Applies a linear gradient effect to the element.
497
+ *
498
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects
499
+ */
500
+ linearGradient?: LinearGradientProps;
501
+ /**
502
+ * Applies a radial gradient effect to the element.
503
+ *
504
+ * @see https://lightning-tv.github.io/solid/#/essentials/effects
505
+ */
506
+ radialGradient?: RadialGradientProps;
507
+ /**
508
+ * The margin on the bottom side of the element for a flexItem.
509
+ *
510
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
511
+ */
512
+ marginBottom?: number;
513
+ /**
514
+ * The margin on the left side of the element for a flexItem.
515
+ *
516
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
517
+ */
518
+ marginLeft?: number;
519
+ /**
520
+ * The margin on the right side of the element for a flexItem.
521
+ *
522
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
523
+ */
524
+ marginRight?: number;
525
+ /**
526
+ * The margin on the top side of the element for a flexItem.
527
+ *
528
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
529
+ */
530
+ marginTop?: number;
531
+ /**
532
+ * The padding on all sides of the flex element, or an array defining [Top, Right, Bottom, Left] padding.
533
+ *
534
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
535
+ */
536
+ padding?:
537
+ | number
538
+ | [number, number]
539
+ | [number, number, number]
540
+ | [number, number, number, number];
541
+ /**
542
+ * The margin on all sides of the flex element, or an array defining [Top, Right, Bottom, Left] margins.
543
+ *
544
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
545
+ */
546
+ margin?:
547
+ | number
548
+ | [number, number]
549
+ | [number, number, number]
550
+ | [number, number, number, number];
551
+ /**
552
+ * The x-coordinate of the element's position.
553
+ *
554
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
555
+ */
556
+ x: number;
557
+ /**
558
+ * The y-coordinate of the element's position.
559
+ *
560
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
561
+ */
562
+ y: number;
563
+ /**
564
+ * Throttles key press events by the specified number of milliseconds.
565
+ *
566
+ * @see https://lightning-tv.github.io/solid/#/primitives/useFocusManager?id=input-throttling-available-core-212
567
+ */
568
+ throttleInput?: number;
569
+ /**
570
+ * The width of the element.
571
+ *
572
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
573
+ */
574
+ w: number;
575
+ /**
576
+ * The height of the element.
577
+ *
578
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
579
+ */
580
+ h: number;
581
+ /**
582
+ * The maximum width of the element.
583
+ */
584
+ maxWidth?: number;
585
+ /**
586
+ * The maximum height of the element.
587
+ */
588
+ maxHeight?: number;
589
+ /**
590
+ * The minimum width of the element.
591
+ */
592
+ minWidth?: number;
593
+ /**
594
+ * The minimum height of the element.
595
+ */
596
+ minHeight?: number;
597
+ /**
598
+ * The z-index of the element, which affects its stacking order.
599
+ *
600
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
601
+ */
602
+ zIndex?: number;
603
+ /**
604
+ * Defines transitions for animatable properties.
605
+ *
606
+ * @see https://lightning-tv.github.io/solid/#/essentials/transitions?id=transitions-animations
607
+ */
608
+ transition?:
609
+ | Record<string, AnimationSettings | undefined | true | false>
610
+ | true
611
+ | false;
612
+
613
+ /** Optional handler for when the element is created and rendered.
614
+ *
615
+ * @see https://lightning-tv.github.io/solid/#/flow/ondestroy
616
+ */
617
+ onCreate?: (this: ElementNode, el: ElementNode) => void;
618
+ /**
619
+ * Optional handler for when the element is destroyed.
620
+ * It can return a promise to wait for the cleanup to finish before the element is destroyed.
621
+ *
622
+ * @see https://lightning-tv.github.io/solid/#/flow/ondestroy
623
+ */
624
+ onDestroy?: (this: ElementNode, el: ElementNode) => Promise<any> | void;
625
+ /**
626
+ * Optional handlers for when the element is rendered—after creation and when switching parents.
627
+ *
628
+ * @see https://lightning-tv.github.io/solid/#/primitives/KeepAlive
629
+ */
630
+ onRender?: (this: ElementNode, el: ElementNode) => void;
631
+ /**
632
+ * Optional handlers for when the element is removed from a parent element.
633
+ *
634
+ * @see https://lightning-tv.github.io/solid/#/primitives/KeepAlive
635
+ */
636
+ onRemove?: (this: ElementNode, el: ElementNode) => void;
637
+ /**
638
+ * Listen to Events coming from the renderer
639
+ * @param NodeEvents
640
+ *
641
+ * Available events:
642
+ * - 'loaded'
643
+ * - 'failed'
644
+ * - 'freed'
645
+ * - 'inBounds'
646
+ * - 'outOfBounds'
647
+ * - 'inViewport'
648
+ * - 'outOfViewport'
649
+ *
650
+ * @typedef {'loaded' | 'failed' | 'freed' | 'inBounds' | 'outOfBounds' | 'inViewport' | 'outOfViewport'} NodeEvents
651
+ *
652
+ * @param {Partial<Record<NodeEvents, EventHandler>>} events - An object where the keys are event names from NodeEvents and the values are the respective event handlers.
653
+ * @returns {void}
654
+ *
655
+ * @see https://lightning-tv.github.io/solid/#/essentials/events
656
+ */
657
+ onEvent?: OnEvent;
658
+
659
+ /**
660
+ * Callback run after flex layout is calculated on flex elements
661
+ *
662
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
663
+ */
664
+ onLayout?: (this: ElementNode, target: ElementNode) => void;
665
+
666
+ /**
667
+ * The individual padding on each side of an element, acting as an override to the `padding` array property.
668
+ * `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`.
669
+ * Only in the new flex engine.
670
+ *
671
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
672
+ */
673
+ paddingTop?: number;
674
+ paddingRight?: number;
675
+ paddingBottom?: number;
676
+ paddingLeft?: number;
677
+ /**
678
+ * Defines the order in which state styles are applied for this element.
679
+ * Overrides the global `Config.stateOrder`.
680
+ */
681
+ stateOrder?: DollarString[];
682
+ }
683
+
684
+ export class ElementNode extends Object {
685
+ constructor(name: string) {
686
+ super();
687
+ this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
688
+ this.rendered = false;
689
+ this.lng = {};
690
+ this.children = [];
691
+ }
692
+
693
+ get effects(): StyleEffects | undefined {
694
+ return this.lng.shader;
695
+ }
696
+
697
+ set effects(v: StyleEffects) {
698
+ if (!SHADERS_ENABLED) return;
699
+ let target = this.lng.shader || {};
700
+ if (this.lng.shader?.props) {
701
+ target = this.lng.shader.props;
702
+ }
703
+ if (v.rounded) target.radius = v.rounded.radius;
704
+ if (v.borderRadius) target.radius = v.borderRadius;
705
+ if (v.border) parseAndAssignShaderProps('border', v.border, target);
706
+ if (v.borderTop)
707
+ parseAndAssignShaderProps('borderTop', v.borderTop, target);
708
+ if (v.borderRight)
709
+ parseAndAssignShaderProps('borderRight', v.borderRight, target);
710
+ if (v.borderBottom)
711
+ parseAndAssignShaderProps('borderBottom', v.borderBottom, target);
712
+ if (v.borderLeft)
713
+ parseAndAssignShaderProps('borderLeft', v.borderLeft, target);
714
+ if (v.shadow) parseAndAssignShaderProps('shadow', v.shadow, target);
715
+
716
+ if (this.rendered) {
717
+ if (!this.lng.shader) {
718
+ this.lng.shader = Config.convertToShader(this, target);
719
+ } else if (DOM_RENDERING && Config.domRendererEnabled) {
720
+ this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
721
+ }
722
+ } else {
723
+ this.lng.shader = target;
724
+ }
725
+ }
726
+
727
+ set id(id: string) {
728
+ this._id = id;
729
+ if (
730
+ Config.rendererOptions &&
731
+ 'inspector' in Config.rendererOptions &&
732
+ Config.rendererOptions.inspector
733
+ ) {
734
+ this.data = { ...this.data, testId: id };
735
+ }
736
+ }
737
+
738
+ get id(): string | undefined {
739
+ return this._id;
740
+ }
741
+
742
+ get parent() {
743
+ return this._parent;
744
+ }
745
+
746
+ set parent(p) {
747
+ this._parent = p;
748
+ if (this.rendered && p?.rendered) {
749
+ this.lng.parent = (p.lng as IRendererNode) ?? null;
750
+ }
751
+ }
752
+
753
+ get height(): number {
754
+ return this.maxHeight || this.h;
755
+ }
756
+
757
+ set height(h: number) {
758
+ this.h = h;
759
+ }
760
+
761
+ get width(): number {
762
+ return this.maxWidth || this.w;
763
+ }
764
+
765
+ set width(w: number) {
766
+ this.w = w;
767
+ }
768
+
769
+ set fontWeight(v) {
770
+ if (this._fontWeight === v) {
771
+ return;
772
+ }
773
+
774
+ this._fontWeight = v;
775
+ const weight =
776
+ (Config.fontWeightAlias &&
777
+ (Config.fontWeightAlias[v as string] as number | string)) ??
778
+ v;
779
+ (this.lng as any).fontFamily =
780
+ `${this.fontFamily || Config.fontSettings?.fontFamily}${weight}`;
781
+ }
782
+
783
+ get fontWeight() {
784
+ return this._fontWeight;
785
+ }
786
+
787
+ set fontFamily(v) {
788
+ this._fontFamily = v;
789
+ (this.lng as any).fontFamily = v;
790
+ }
791
+
792
+ get fontFamily() {
793
+ return this._fontFamily;
794
+ }
795
+
796
+ insertChild(
797
+ node: ElementNode | ElementText | TextNode,
798
+ beforeNode?: ElementNode | ElementText | TextNode | null,
799
+ ) {
800
+ // always remove nodes if they have a parent - for back swap of node
801
+ // this will then put the node at the end of the array when re-added
802
+ if (node.parent) {
803
+ node.parent.removeChild(node);
804
+
805
+ // We're inserting a node thats been rendered into a node that hasn't been
806
+ if (!this.rendered) {
807
+ this._hasRenderedChildren = true;
808
+ }
809
+ }
810
+
811
+ node.parent = this;
812
+
813
+ if (beforeNode) {
814
+ // SolidJS can move nodes around in the children array.
815
+ // We need to insert following DOM insertBefore which moves elements.
816
+ spliceItem(this.children, node as ElementNode, 1);
817
+ if (spliceItem(this.children, beforeNode as ElementNode, 0, node) > -1) {
818
+ return;
819
+ }
820
+ }
821
+
822
+ this.children.push(node as ElementNode);
823
+ }
824
+
825
+ removeChild(node: ElementNode | ElementText | TextNode) {
826
+ if (spliceItem(this.children, node, 1) > -1) {
827
+ node.onRemove?.call(node, node);
828
+ if (this.requiresLayout()) {
829
+ addToLayoutQueue(this);
830
+ }
831
+ }
832
+ }
833
+
834
+ get selectedNode(): ElementNode | undefined {
835
+ const selectedIndex = this.selected || 0;
836
+
837
+ for (let i = selectedIndex; i < this.children.length; i++) {
838
+ const element = this.children[i];
839
+ if (isElementNode(element)) {
840
+ this.selected = i;
841
+ return element;
842
+ }
843
+ }
844
+
845
+ return undefined;
846
+ }
847
+
848
+ set shader(
849
+ shaderProps: IRendererShader | [kind: string, props: IRendererShaderProps],
850
+ ) {
851
+ this.lng.shader = isArray(shaderProps)
852
+ ? renderer.createShader(...shaderProps)
853
+ : shaderProps;
854
+ }
855
+
856
+ _sendToLightningAnimatable(name: string, value: number) {
857
+ if (
858
+ this.transition &&
859
+ this.rendered &&
860
+ Config.animationsEnabled &&
861
+ (this.transition === true ||
862
+ this.transition[name] ||
863
+ this.transition[getPropertyAlias(name)])
864
+ ) {
865
+ const animationSettings =
866
+ this.transition === true || this.transition[name] === true
867
+ ? undefined
868
+ : this.transition[name] ||
869
+ (this.transition[getPropertyAlias(name)] as
870
+ | undefined
871
+ | AnimationSettings);
872
+
873
+ return (this.lng as any).animateProp(
874
+ name,
875
+ value,
876
+ animationSettings || this.animationSettings || {},
877
+ );
878
+ }
879
+
880
+ (this.lng[name as keyof (IRendererNode | INode)] as number | string) =
881
+ value;
882
+ }
883
+
884
+ animate(
885
+ props: Partial<INodeAnimateProps<CoreShaderNode>>,
886
+ animationSettings?: AnimationSettings,
887
+ ): IAnimationController {
888
+ isDev &&
889
+ assertTruthy(this.rendered, 'Node must be rendered before animating');
890
+ return (this.lng as IRendererNode).animate(
891
+ props,
892
+ animationSettings || this.animationSettings || {},
893
+ );
894
+ }
895
+
896
+ chain(
897
+ props: Partial<INodeAnimateProps<CoreShaderNode>>,
898
+ animationSettings?: AnimationSettings,
899
+ ) {
900
+ if (this._animationRunning) {
901
+ this._animationQueue = [];
902
+ this._animationRunning = false;
903
+ }
904
+
905
+ if (animationSettings) {
906
+ this._animationQueueSettings = animationSettings;
907
+ } else if (!this._animationQueueSettings) {
908
+ this._animationQueueSettings =
909
+ animationSettings || this.animationSettings;
910
+ }
911
+ animationSettings = animationSettings || this._animationQueueSettings;
912
+ this._animationQueue = this._animationQueue || [];
913
+ this._animationQueue.push({ props, animationSettings });
914
+ return this;
915
+ }
916
+
917
+ async start() {
918
+ let animation = this._animationQueue!.shift();
919
+ while (animation) {
920
+ this._animationRunning = true;
921
+ await this.animate(animation.props, animation.animationSettings)
922
+ .start()
923
+ .waitUntilStopped();
924
+ animation = this._animationQueue!.shift();
925
+ }
926
+ this._animationRunning = false;
927
+ this._animationQueueSettings = undefined;
928
+ }
929
+
930
+ emit(event: string, ...args: any[]): boolean {
931
+ let current = this as ElementNode;
932
+ const capitalizedEvent = `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
933
+
934
+ while (current) {
935
+ const handler = current[capitalizedEvent];
936
+ if (isFunction(handler)) {
937
+ if (handler.call(current, this, ...args) === true) {
938
+ return true;
939
+ }
940
+ }
941
+ current = current.parent!;
942
+ }
943
+ return false;
944
+ }
945
+
946
+ setFocus(): void {
947
+ if (this.rendered) {
948
+ // can be 0
949
+ if (this.forwardFocus !== undefined) {
950
+ if (isFunc(this.forwardFocus)) {
951
+ if (this.forwardFocus.call(this, this) !== false) {
952
+ return;
953
+ }
954
+ } else {
955
+ const focusedIndex =
956
+ typeof this.forwardFocus === 'number' ? this.forwardFocus : null;
957
+ const nodes = this.children;
958
+ if (focusedIndex !== null && focusedIndex < nodes.length) {
959
+ const child = nodes[focusedIndex];
960
+ isElementNode(child) && child.setFocus();
961
+ return;
962
+ }
963
+ }
964
+ }
965
+ // Delay setting focus so children can render (useful for Row + Column)
966
+ nextActiveElement = this;
967
+ if (focusQueued === false) {
968
+ focusQueued = true;
969
+ queueMicrotask(() => {
970
+ focusQueued = false;
971
+ if (nextActiveElement) {
972
+ const element = nextActiveElement;
973
+ nextActiveElement = null;
974
+ setActiveElement(element);
975
+ }
976
+ });
977
+ }
978
+ } else {
979
+ this._autofocus = true;
980
+ }
981
+ }
982
+
983
+ _layoutOnLoad() {
984
+ (this.lng as IRendererNode).on('loaded', () => {
985
+ if (
986
+ 'reprocessUpdates' in renderer.stage &&
987
+ renderer.stage.reprocessUpdates
988
+ ) {
989
+ renderer.stage.reprocessUpdates(runLayout);
990
+ }
991
+ this.parent!.updateLayout();
992
+ });
993
+ }
994
+
995
+ getText(this: ElementText) {
996
+ let result = '';
997
+ for (let i = 0; i < this.children.length; i++) {
998
+ result += this.children[i]!.text;
999
+ }
1000
+ return result;
1001
+ }
1002
+
1003
+ destroy() {
1004
+ if (this.onDestroy) {
1005
+ const destroyPromise: unknown = this.onDestroy(this);
1006
+
1007
+ // If onDestroy returns a promise, wait for it to resolve before destroying
1008
+ // Useful with animations waitUntilStopped method which returns promise
1009
+ if (destroyPromise instanceof Promise) {
1010
+ destroyPromise.then(() => this._destroy());
1011
+ } else {
1012
+ this._destroy();
1013
+ }
1014
+ } else {
1015
+ this._destroy();
1016
+ }
1017
+ }
1018
+
1019
+ _destroy() {
1020
+ if (isINode(this.lng)) {
1021
+ this.lng.destroy();
1022
+ }
1023
+ }
1024
+
1025
+ set style(style: Styles | undefined) {
1026
+ if (isDev && this._style) {
1027
+ // Avoid processing style changes again
1028
+ console.warn(
1029
+ 'Style already set: https://lightning-tv.github.io/solid/#/essentials/styling?id=style-patterns-to-avoid',
1030
+ );
1031
+ }
1032
+
1033
+ if (Config.lockStyles && this._style) {
1034
+ return;
1035
+ }
1036
+
1037
+ if (!style) {
1038
+ return;
1039
+ }
1040
+
1041
+ this._style = style;
1042
+
1043
+ // Keys set in JSX are more important
1044
+ for (const key in this._style) {
1045
+ // be careful of 0 values
1046
+ if (this[key as keyof Styles] === undefined) {
1047
+ this[key as keyof Styles] = this._style[key as keyof Styles];
1048
+ }
1049
+ }
1050
+ }
1051
+
1052
+ get style(): Styles {
1053
+ return this._style || {};
1054
+ }
1055
+
1056
+ set theme(styles: Styles | undefined) {
1057
+ if (!styles) {
1058
+ return;
1059
+ }
1060
+ this._theme = styles;
1061
+ for (const key in styles) {
1062
+ this[key as keyof Styles] = styles[key as keyof Styles];
1063
+ }
1064
+ }
1065
+
1066
+ get theme(): Styles {
1067
+ this._theme = this._theme || {};
1068
+ return this._theme;
1069
+ }
1070
+
1071
+ get hasChildren() {
1072
+ return this.children.length > 0;
1073
+ }
1074
+
1075
+ set src(src) {
1076
+ if (typeof src === 'string') {
1077
+ this.lng.src = src;
1078
+ if (!this.color && this.rendered) {
1079
+ this.color = 0xffffffff;
1080
+ }
1081
+ } else {
1082
+ this.color = 0x00000000;
1083
+ }
1084
+ }
1085
+
1086
+ get src(): string | null | undefined {
1087
+ return this.lng.src;
1088
+ }
1089
+
1090
+ getChildById(id: string) {
1091
+ return this.children.find((c) => c.id === id);
1092
+ }
1093
+
1094
+ searchChildrenById(id: string): ElementNode | undefined {
1095
+ // traverse all the childrens children
1096
+ for (let i = 0; i < this.children.length; i++) {
1097
+ const child = this.children[i];
1098
+ if (isElementNode(child)) {
1099
+ if (child.id === id) {
1100
+ return child;
1101
+ }
1102
+
1103
+ const found = child.searchChildrenById(id);
1104
+ if (found) {
1105
+ return found;
1106
+ }
1107
+ }
1108
+ }
1109
+ }
1110
+
1111
+ set states(states: NodeStates) {
1112
+ this._states = this._states
1113
+ ? this._states.merge(states)
1114
+ : new States(this._stateChanged.bind(this), states);
1115
+ if (this.rendered) {
1116
+ this._stateChanged();
1117
+ }
1118
+ }
1119
+
1120
+ get states(): States {
1121
+ this._states = this._states || new States(this._stateChanged.bind(this));
1122
+ return this._states;
1123
+ }
1124
+
1125
+ get animationSettings(): AnimationSettings | undefined {
1126
+ return this._animationSettings || Config.animationSettings;
1127
+ }
1128
+
1129
+ set animationSettings(animationSettings: AnimationSettings | undefined) {
1130
+ this._animationSettings = animationSettings;
1131
+ }
1132
+
1133
+ set hidden(val: boolean) {
1134
+ this.alpha = val ? 0 : 1;
1135
+ }
1136
+
1137
+ get hidden() {
1138
+ return this.alpha === 0;
1139
+ }
1140
+
1141
+ /**
1142
+ * Sets the autofocus state of the element.
1143
+ * When set to a truthy value, the element will automatically gain focus.
1144
+ * You can also set it to a signal to recalculate
1145
+ *
1146
+ * @param val - A value to determine if the element should autofocus.
1147
+ * A truthy value enables autofocus, otherwise disables it.
1148
+ */
1149
+ set autofocus(val: any) {
1150
+ this._autofocus = val;
1151
+ // Delay setting focus so children can render (useful for Row + Column)
1152
+ // which now uses forwardFocus
1153
+ val && queueMicrotask(() => this.setFocus());
1154
+ }
1155
+
1156
+ get autofocus() {
1157
+ return this._autofocus;
1158
+ }
1159
+
1160
+ requiresLayout() {
1161
+ return this.display === 'flex' || this.onLayout;
1162
+ }
1163
+
1164
+ set updateLayoutOn(v: any) {
1165
+ this.updateLayout();
1166
+ }
1167
+
1168
+ get updateLayoutOn() {
1169
+ return null;
1170
+ }
1171
+
1172
+ updateLayout() {
1173
+ if (this.hasChildren) {
1174
+ isDev && log('Layout: ', this);
1175
+
1176
+ if (this.display === 'flex' && this.flexGrow && this.width === 0) {
1177
+ return;
1178
+ }
1179
+
1180
+ const flexChanged = this.display === 'flex' && calculateFlex(this);
1181
+ layoutQueue.delete(this);
1182
+ const onLayoutChanged =
1183
+ isFunc(this.onLayout) && this.onLayout.call(this, this);
1184
+
1185
+ if ((flexChanged || onLayoutChanged) && this.parent) {
1186
+ addToLayoutQueue(this.parent);
1187
+ }
1188
+
1189
+ if (this._containsFlexGrow === true) {
1190
+ // Need to reprocess children
1191
+ this.children.forEach((c) => {
1192
+ if (c.display === 'flex' && isElementNode(c)) {
1193
+ // calculating directly to prevent infinite loops recalculating parents
1194
+ calculateFlex(c);
1195
+ isFunc(c.onLayout) && c.onLayout.call(c, c);
1196
+ addToLayoutQueue(this);
1197
+ }
1198
+ });
1199
+ }
1200
+ }
1201
+ }
1202
+
1203
+ _stateChanged() {
1204
+ isDev && log('State Changed: ', this, this.states);
1205
+
1206
+ if (this.forwardStates) {
1207
+ // apply states to children first
1208
+ const states = this.states.slice() as States;
1209
+ this.children.forEach((c) => {
1210
+ c.states = states;
1211
+ });
1212
+ }
1213
+
1214
+ const states = this.states;
1215
+
1216
+ if (this._undoStyles || keyExists(this, states)) {
1217
+ let stylesToUndo: { [key: string]: any } | undefined;
1218
+ if (this._undoStyles && this._undoStyles.length) {
1219
+ stylesToUndo = {};
1220
+ this._undoStyles.forEach((styleKey) => {
1221
+ let fallbackValue = this.theme[styleKey];
1222
+
1223
+ if (fallbackValue === undefined) {
1224
+ fallbackValue = this.style[styleKey];
1225
+ }
1226
+
1227
+ if (isDev) {
1228
+ if (fallbackValue === undefined) {
1229
+ console.warn('fallback style key not found: ', styleKey);
1230
+ }
1231
+ }
1232
+ stylesToUndo![styleKey] = fallbackValue;
1233
+ });
1234
+ }
1235
+
1236
+ const numStates = states.length;
1237
+ if (numStates === 0) {
1238
+ Object.assign(this, stylesToUndo);
1239
+ this._undoStyles = [];
1240
+ return;
1241
+ }
1242
+
1243
+ let newStyles: Styles;
1244
+ if (numStates === 1) {
1245
+ newStyles = this[states[0] as keyof Styles] as Styles;
1246
+ newStyles = stylesToUndo
1247
+ ? { ...stylesToUndo, ...newStyles }
1248
+ : newStyles;
1249
+ } else {
1250
+ let sortedStates = states as DollarString[];
1251
+ const stateOrder = this.stateOrder || Config.stateOrder;
1252
+ if (stateOrder && stateOrder.length > 0) {
1253
+ sortedStates = states.slice().sort((a, b) => {
1254
+ const aIdx = stateOrder.indexOf(a);
1255
+ const bIdx = stateOrder.indexOf(b);
1256
+
1257
+ // If a state is in the stateOrder, it should have higher specificity
1258
+ // than states not in the stateOrder.
1259
+ if (aIdx !== -1 && bIdx === -1) return 1;
1260
+ if (aIdx === -1 && bIdx !== -1) return -1;
1261
+
1262
+ return aIdx - bIdx;
1263
+ });
1264
+ }
1265
+
1266
+ newStyles = sortedStates.reduce((acc, state) => {
1267
+ const styles = this[state];
1268
+ return styles ? { ...acc, ...styles } : acc;
1269
+ }, stylesToUndo || {});
1270
+ }
1271
+
1272
+ if (newStyles) {
1273
+ this._undoStyles = Object.keys(newStyles);
1274
+ // Apply transition first
1275
+ if (newStyles.transition !== undefined) {
1276
+ this.transition = newStyles.transition as Styles['transition'];
1277
+ }
1278
+
1279
+ // Apply the styles
1280
+ Object.assign(this, newStyles);
1281
+ } else {
1282
+ this._undoStyles = [];
1283
+ }
1284
+ }
1285
+ }
1286
+
1287
+ render(topNode?: boolean) {
1288
+ // Elements are inserted from the inside out, then rendered from the outside in.
1289
+ // Render starts when an element is inserted with a parent that is already renderered.
1290
+ const node = this;
1291
+ const parent = this.parent;
1292
+
1293
+ if (!parent) {
1294
+ console.warn('Parent not set - no node created for: ', this);
1295
+ return;
1296
+ }
1297
+
1298
+ if (!parent.rendered) {
1299
+ console.warn('Parent not rendered yet: ', this);
1300
+ return;
1301
+ }
1302
+
1303
+ if (parent.requiresLayout()) {
1304
+ layoutQueue.add(parent);
1305
+ }
1306
+
1307
+ if (this.rendered) {
1308
+ // This happens if Array of items is reordered to reuse elements.
1309
+ // We return after layout is queued so the change can trigger layout updates.
1310
+ this.onRender?.(this);
1311
+ return;
1312
+ }
1313
+
1314
+ if (this._states) {
1315
+ this._stateChanged();
1316
+ }
1317
+
1318
+ const props = node.lng;
1319
+ const parentWidth = parent.w || 0;
1320
+ const parentHeight = parent.h || 0;
1321
+
1322
+ props.x = props.x || 0;
1323
+ props.y = props.y || 0;
1324
+ props.parent = parent.lng as IRendererNode;
1325
+
1326
+ if (this.right || this.right === 0) {
1327
+ props.x = parentWidth - this.right;
1328
+ props.mountX = 1;
1329
+ }
1330
+
1331
+ if (this.bottom || this.bottom === 0) {
1332
+ props.y = parentHeight - this.bottom;
1333
+ props.mountY = 1;
1334
+ }
1335
+
1336
+ if (this.center) {
1337
+ this.centerX = this.centerY = true;
1338
+ }
1339
+
1340
+ if (this.centerX) {
1341
+ props.x += parentWidth / 2;
1342
+ props.mountX = 0.5;
1343
+ }
1344
+
1345
+ if (this.centerY) {
1346
+ props.y += parentHeight / 2;
1347
+ props.mountY = 0.5;
1348
+ }
1349
+
1350
+ if (isElementText(node)) {
1351
+ const textProps = props as TextProps;
1352
+ if (Config.fontSettings) {
1353
+ for (const key in Config.fontSettings) {
1354
+ if (textProps[key] === undefined) {
1355
+ let value = Config.fontSettings[key];
1356
+ if (key === 'fontFamily' && textProps['fontWeight'] === undefined) {
1357
+ value = `${value}${Config.fontSettings.fontWeight || ''}`;
1358
+ }
1359
+ textProps[key] = value;
1360
+ }
1361
+ }
1362
+ }
1363
+ textProps.text = textProps.text || node.getText();
1364
+
1365
+ if (textProps.textAlign && !textProps.contain) {
1366
+ console.warn('Text align requires contain: ', node.getText());
1367
+ }
1368
+
1369
+ // contain is either width or both
1370
+ if (textProps.contain) {
1371
+ if (textProps.contain === 'both') {
1372
+ textProps.maxWidth = textProps.maxWidth ?? textProps.w;
1373
+ textProps.maxHeight = textProps.maxHeight ?? textProps.h;
1374
+ } else if (textProps.contain === 'width') {
1375
+ textProps.maxWidth = textProps.maxWidth ?? textProps.w;
1376
+ }
1377
+
1378
+ if (!textProps.h && !textProps.maxHeight) {
1379
+ textProps.maxLines = textProps.maxLines ?? 99;
1380
+ }
1381
+
1382
+ if (!textProps.maxWidth) {
1383
+ textProps.maxWidth =
1384
+ parentWidth - textProps.x! - (textProps.marginRight || 0);
1385
+ }
1386
+
1387
+ if (textProps.contain === 'both' && !textProps.maxHeight) {
1388
+ textProps.maxHeight =
1389
+ parentHeight - textProps.y! - (textProps.marginBottom || 0);
1390
+ } else if (textProps.maxLines === 1) {
1391
+ textProps.maxHeight = (textProps.maxHeight ||
1392
+ textProps.lineHeight ||
1393
+ textProps.fontSize) as number;
1394
+ }
1395
+ // textProps.w = textProps.h = 0;
1396
+ }
1397
+
1398
+ // Can you put effects on Text nodes? Need to confirm...
1399
+ if (SHADERS_ENABLED && props.shader && !props.shader.program) {
1400
+ props.shader = Config.convertToShader(node, props.shader);
1401
+ }
1402
+
1403
+ isDev && log('Rendering: ', this, props);
1404
+
1405
+ node.lng = renderer.createTextNode(
1406
+ props as Partial<ITextNodeProps> & Partial<IRendererTextNodeProps>,
1407
+ ) as IRendererTextNode;
1408
+
1409
+ if (parent.requiresLayout()) {
1410
+ if (!textProps.maxWidth || !textProps.maxHeight) {
1411
+ node._layoutOnLoad();
1412
+ }
1413
+ }
1414
+ } else {
1415
+ // If its not an image or texture apply some defaults
1416
+ if (!props.texture) {
1417
+ // Set width and height to parent less offset
1418
+ if (isNaN(props.w as number)) {
1419
+ props.w = node.flexGrow ? 0 : parentWidth - props.x;
1420
+ node._calcWidth = true;
1421
+ }
1422
+
1423
+ if (isNaN(props.h as number)) {
1424
+ props.h = parentHeight - props.y;
1425
+ node._calcHeight = true;
1426
+ }
1427
+
1428
+ if (props.rtt && !props.color) {
1429
+ props.color = 0xffffffff;
1430
+ }
1431
+
1432
+ if (!props.color && !props.src) {
1433
+ // Default color to transparent - If you later set a src, you'll need
1434
+ // to set color '#ffffffff'
1435
+ props.color = 0x00000000;
1436
+ }
1437
+ }
1438
+
1439
+ if (SHADERS_ENABLED && props.shader && !props.shader.program) {
1440
+ props.shader = Config.convertToShader(node, props.shader);
1441
+ }
1442
+
1443
+ isDev && log('Rendering: ', this, props);
1444
+
1445
+ node.lng = renderer.createNode(
1446
+ props as Partial<INodeProps<any>> & Partial<IRendererNodeProps>,
1447
+ );
1448
+
1449
+ if (node._hasRenderedChildren) {
1450
+ node._hasRenderedChildren = false;
1451
+
1452
+ for (const child of node.children) {
1453
+ if (isElementNode(child) && isINode(child.lng)) {
1454
+ child.lng.parent = node.lng as any;
1455
+ }
1456
+ }
1457
+ }
1458
+ }
1459
+
1460
+ node.rendered = true;
1461
+ if (isDev) {
1462
+ // Store props so we can recreate raw renderer code
1463
+ node._rendererProps = props;
1464
+ }
1465
+
1466
+ if (node.autosize && parent.requiresLayout()) {
1467
+ node._layoutOnLoad();
1468
+ }
1469
+
1470
+ this.onCreate?.(this);
1471
+ this.onRender?.(this);
1472
+
1473
+ if (node.onEvent) {
1474
+ for (const [name, handler] of Object.entries(node.onEvent)) {
1475
+ if (typeof node.lng.on === 'function') {
1476
+ node.lng.on(name, (_inode, data) => handler.call(node, node, data));
1477
+ }
1478
+ }
1479
+ }
1480
+
1481
+ // L3 Inspector adds div to the lng object
1482
+ const div: HTMLElement | undefined = (node.lng as any)?.div;
1483
+ if (div) div.element = node;
1484
+
1485
+ if (node._type === NodeType.Element) {
1486
+ // only element nodes will have children that need rendering
1487
+ const numChildren = node.children.length;
1488
+ for (let i = 0; i < numChildren; i++) {
1489
+ const c = node.children[i];
1490
+ isDev && assertTruthy(c, 'Child is undefined');
1491
+ // Text elements sneak in from Solid creating tracked nodes
1492
+ if (isElementNode(c)) {
1493
+ c.render();
1494
+ }
1495
+ }
1496
+ }
1497
+ if (topNode && !layoutRunQueued) {
1498
+ //Do one pass of layout, then another with Text loads
1499
+ layoutRunQueued = true;
1500
+ // We use queue because <For> loop will add children one at a time, causing lots of layout
1501
+ queueMicrotask(runLayout);
1502
+ }
1503
+
1504
+ node._autofocus && node.setFocus();
1505
+ }
1506
+ }
1507
+
1508
+ for (const key of LightningRendererNumberProps) {
1509
+ Object.defineProperty(ElementNode.prototype, key, {
1510
+ get(): number {
1511
+ return this.lng[key];
1512
+ },
1513
+ set(this: ElementNode, v: number) {
1514
+ this._sendToLightningAnimatable(key, v);
1515
+ },
1516
+ });
1517
+ }
1518
+
1519
+ for (const key of LightningRendererNonAnimatingProps) {
1520
+ Object.defineProperty(ElementNode.prototype, key, {
1521
+ get(): unknown {
1522
+ return this.lng[key];
1523
+ },
1524
+ set(v: unknown) {
1525
+ this.lng[key] = v;
1526
+ },
1527
+ });
1528
+ }
1529
+
1530
+ export function createRawShaderAccessor<T>(key: keyof StyleEffects) {
1531
+ return {
1532
+ set(this: ElementNode, value: T) {
1533
+ this.shader = [key, value as unknown as IRendererShaderProps];
1534
+ },
1535
+
1536
+ get(this: ElementNode) {
1537
+ return this.shader;
1538
+ },
1539
+ };
1540
+ }
1541
+
1542
+ export function shaderAccessor<T extends Record<string, any> | number>(
1543
+ key:
1544
+ | 'border'
1545
+ | 'shadow'
1546
+ | 'rounded'
1547
+ | 'borderBottom'
1548
+ | 'borderLeft'
1549
+ | 'borderRight'
1550
+ | 'borderTop',
1551
+ ) {
1552
+ return {
1553
+ set(this: ElementNode, value: T) {
1554
+ let target = this.lng.shader || {};
1555
+ this._effects = this._effects || {};
1556
+ this._effects[key] = value;
1557
+
1558
+ let animationSettings: AnimationSettings | undefined;
1559
+
1560
+ if (this.lng.shader?.props) {
1561
+ target = this.lng.shader.props;
1562
+ const transitionKey = key === 'rounded' ? 'borderRadius' : key;
1563
+ if (
1564
+ this.transition &&
1565
+ (this.transition === true || this.transition[transitionKey])
1566
+ ) {
1567
+ target = {};
1568
+ animationSettings =
1569
+ this.transition === true || this.transition[transitionKey] === true
1570
+ ? undefined
1571
+ : (this.transition[transitionKey] as
1572
+ | undefined
1573
+ | AnimationSettings);
1574
+ }
1575
+ }
1576
+
1577
+ if (key === 'rounded' || typeof value === 'number') {
1578
+ target.radius = value;
1579
+ } else {
1580
+ parseAndAssignShaderProps(key, value, target);
1581
+ }
1582
+
1583
+ if (this.rendered) {
1584
+ if (!this.lng.shader) {
1585
+ this.lng.shader = Config.convertToShader(this, target);
1586
+ } else if (DOM_RENDERING && Config.domRendererEnabled) {
1587
+ this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
1588
+ }
1589
+ } else {
1590
+ this.lng.shader = target;
1591
+ }
1592
+
1593
+ if (animationSettings) {
1594
+ this.animate({ shaderProps: target }, animationSettings).start();
1595
+ }
1596
+ },
1597
+ get(this: ElementNode) {
1598
+ return this._effects?.[key];
1599
+ },
1600
+ };
1601
+ }
1602
+
1603
+ if (isDev) {
1604
+ ElementNode.prototype.lngTree = function () {
1605
+ return logRenderTree(this);
1606
+ };
1607
+ }
1608
+
1609
+ Object.defineProperties(ElementNode.prototype, {
1610
+ border: shaderAccessor<BorderStyle>('border'),
1611
+ borderBottom: shaderAccessor<BorderStyle>('borderBottom'),
1612
+ borderTop: shaderAccessor<BorderStyle>('borderTop'),
1613
+ borderLeft: shaderAccessor<BorderStyle>('borderLeft'),
1614
+ borderRight: shaderAccessor<BorderStyle>('borderRight'),
1615
+ shadow: shaderAccessor<ShadowProps>('shadow'),
1616
+ rounded: shaderAccessor<BorderRadius>('rounded'),
1617
+ // Alias for rounded
1618
+ borderRadius: shaderAccessor<BorderRadius>('rounded'),
1619
+ linearGradient:
1620
+ createRawShaderAccessor<LinearGradientProps>('linearGradient'),
1621
+ radialGradient:
1622
+ createRawShaderAccessor<RadialGradientProps>('radialGradient'),
1623
+ });