@lightningtv/solid 3.0.0-2 → 3.0.0-21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -0
  3. package/dist/src/activeElement.d.ts +1 -1
  4. package/dist/src/core/animation.d.ts +35 -0
  5. package/dist/src/core/animation.js +120 -0
  6. package/dist/src/core/animation.js.map +1 -0
  7. package/dist/src/core/config.d.ts +47 -0
  8. package/dist/src/core/config.js +23 -0
  9. package/dist/src/core/config.js.map +1 -0
  10. package/dist/src/core/domRenderer.d.ts +117 -0
  11. package/dist/src/core/domRenderer.js +1160 -0
  12. package/dist/src/core/domRenderer.js.map +1 -0
  13. package/dist/src/core/elementNode.d.ts +209 -0
  14. package/dist/src/core/elementNode.js +829 -0
  15. package/dist/src/core/elementNode.js.map +1 -0
  16. package/dist/src/core/flex.d.ts +2 -0
  17. package/dist/src/core/flex.js +243 -0
  18. package/dist/src/core/flex.js.map +1 -0
  19. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  20. package/dist/src/core/focusKeyTypes.js +2 -0
  21. package/dist/src/core/focusKeyTypes.js.map +1 -0
  22. package/dist/src/core/focusManager.d.ts +13 -0
  23. package/dist/src/core/focusManager.js +269 -0
  24. package/dist/src/core/focusManager.js.map +1 -0
  25. package/dist/src/core/index.d.ts +12 -0
  26. package/dist/src/core/index.js +12 -0
  27. package/dist/src/core/index.js.map +1 -0
  28. package/dist/src/core/intrinsicTypes.d.ts +90 -0
  29. package/dist/src/core/intrinsicTypes.js +2 -0
  30. package/dist/src/core/intrinsicTypes.js.map +1 -0
  31. package/dist/src/core/lightningInit.d.ts +89 -0
  32. package/dist/src/core/lightningInit.js +26 -0
  33. package/dist/src/core/lightningInit.js.map +1 -0
  34. package/dist/src/core/nodeTypes.d.ts +6 -0
  35. package/dist/src/core/nodeTypes.js +6 -0
  36. package/dist/src/core/nodeTypes.js.map +1 -0
  37. package/dist/src/core/shaders.d.ts +51 -0
  38. package/dist/src/core/shaders.js +446 -0
  39. package/dist/src/core/shaders.js.map +1 -0
  40. package/dist/src/core/states.d.ts +12 -0
  41. package/dist/src/core/states.js +84 -0
  42. package/dist/src/core/states.js.map +1 -0
  43. package/dist/src/core/timings.d.ts +36 -0
  44. package/dist/src/core/timings.js +199 -0
  45. package/dist/src/core/timings.js.map +1 -0
  46. package/dist/src/core/utils.d.ts +39 -0
  47. package/dist/src/core/utils.js +164 -0
  48. package/dist/src/core/utils.js.map +1 -0
  49. package/dist/src/devtools/index.d.ts +1 -1
  50. package/dist/src/devtools/index.js +1 -1
  51. package/dist/src/devtools/index.js.map +1 -1
  52. package/dist/src/index.d.ts +3 -3
  53. package/dist/src/index.js +1 -1
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/jsx-runtime.d.ts +1 -3
  56. package/dist/src/primitives/Column.jsx +9 -10
  57. package/dist/src/primitives/Column.jsx.map +1 -1
  58. package/dist/src/primitives/FPSCounter.jsx +14 -1
  59. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  60. package/dist/src/primitives/Grid.d.ts +15 -6
  61. package/dist/src/primitives/Grid.jsx +35 -22
  62. package/dist/src/primitives/Grid.jsx.map +1 -1
  63. package/dist/src/primitives/Image.d.ts +8 -0
  64. package/dist/src/primitives/Image.jsx +24 -0
  65. package/dist/src/primitives/Image.jsx.map +1 -0
  66. package/dist/src/primitives/KeepAlive.d.ts +30 -0
  67. package/dist/src/primitives/KeepAlive.jsx +77 -0
  68. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  69. package/dist/src/primitives/Lazy.d.ts +8 -7
  70. package/dist/src/primitives/Lazy.jsx +52 -23
  71. package/dist/src/primitives/Lazy.jsx.map +1 -1
  72. package/dist/src/primitives/Marquee.d.ts +64 -0
  73. package/dist/src/primitives/Marquee.jsx +86 -0
  74. package/dist/src/primitives/Marquee.jsx.map +1 -0
  75. package/dist/src/primitives/Preserve.d.ts +4 -0
  76. package/dist/src/primitives/Preserve.jsx +11 -0
  77. package/dist/src/primitives/Preserve.jsx.map +1 -0
  78. package/dist/src/primitives/Row.jsx +9 -10
  79. package/dist/src/primitives/Row.jsx.map +1 -1
  80. package/dist/src/primitives/Suspense.d.ts +22 -0
  81. package/dist/src/primitives/Suspense.jsx +33 -0
  82. package/dist/src/primitives/Suspense.jsx.map +1 -0
  83. package/dist/src/primitives/Virtual.d.ts +18 -0
  84. package/dist/src/primitives/Virtual.jsx +434 -0
  85. package/dist/src/primitives/Virtual.jsx.map +1 -0
  86. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  87. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  88. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  89. package/dist/src/primitives/VirtualList.d.ts +11 -0
  90. package/dist/src/primitives/VirtualList.jsx +96 -0
  91. package/dist/src/primitives/VirtualList.jsx.map +1 -0
  92. package/dist/src/primitives/VirtualRow.d.ts +13 -0
  93. package/dist/src/primitives/VirtualRow.jsx +97 -0
  94. package/dist/src/primitives/VirtualRow.jsx.map +1 -0
  95. package/dist/src/primitives/Visible.d.ts +0 -1
  96. package/dist/src/primitives/Visible.jsx +1 -1
  97. package/dist/src/primitives/Visible.jsx.map +1 -1
  98. package/dist/src/primitives/announcer/announcer.d.ts +2 -0
  99. package/dist/src/primitives/announcer/announcer.js +7 -5
  100. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  101. package/dist/src/primitives/announcer/index.d.ts +5 -1
  102. package/dist/src/primitives/announcer/index.js +8 -2
  103. package/dist/src/primitives/announcer/index.js.map +1 -1
  104. package/dist/src/primitives/announcer/speech.d.ts +2 -2
  105. package/dist/src/primitives/announcer/speech.js +157 -28
  106. package/dist/src/primitives/announcer/speech.js.map +1 -1
  107. package/dist/src/primitives/createFocusStack.d.ts +4 -4
  108. package/dist/src/primitives/createFocusStack.jsx +15 -6
  109. package/dist/src/primitives/createFocusStack.jsx.map +1 -1
  110. package/dist/src/primitives/createTag.d.ts +8 -0
  111. package/dist/src/primitives/createTag.jsx +20 -0
  112. package/dist/src/primitives/createTag.jsx.map +1 -0
  113. package/dist/src/primitives/index.d.ts +14 -4
  114. package/dist/src/primitives/index.js +13 -3
  115. package/dist/src/primitives/index.js.map +1 -1
  116. package/dist/src/primitives/types.d.ts +5 -2
  117. package/dist/src/primitives/useFocusManager.d.ts +2 -2
  118. package/dist/src/primitives/useFocusManager.js +2 -2
  119. package/dist/src/primitives/useFocusManager.js.map +1 -1
  120. package/dist/src/primitives/useHold.d.ts +27 -0
  121. package/dist/src/primitives/useHold.js +54 -0
  122. package/dist/src/primitives/useHold.js.map +1 -0
  123. package/dist/src/primitives/useMouse.d.ts +18 -2
  124. package/dist/src/primitives/useMouse.js +171 -47
  125. package/dist/src/primitives/useMouse.js.map +1 -1
  126. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -4
  127. package/dist/src/primitives/utils/chainFunctions.js +14 -3
  128. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  129. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  130. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  131. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  132. package/dist/src/primitives/utils/createSpriteMap.d.ts +2 -2
  133. package/dist/src/primitives/utils/createSpriteMap.js +1 -1
  134. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
  135. package/dist/src/primitives/utils/handleNavigation.d.ts +79 -5
  136. package/dist/src/primitives/utils/handleNavigation.js +242 -69
  137. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  138. package/dist/src/primitives/utils/withScrolling.d.ts +14 -2
  139. package/dist/src/primitives/utils/withScrolling.js +66 -7
  140. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  141. package/dist/src/render.d.ts +8 -7
  142. package/dist/src/render.js +5 -1
  143. package/dist/src/render.js.map +1 -1
  144. package/dist/src/solidOpts.d.ts +1 -7
  145. package/dist/src/solidOpts.js +32 -16
  146. package/dist/src/solidOpts.js.map +1 -1
  147. package/dist/src/types.d.ts +1 -13
  148. package/dist/src/universal.d.ts +25 -0
  149. package/dist/src/universal.js +232 -0
  150. package/dist/src/universal.js.map +1 -0
  151. package/dist/src/utils.d.ts +3 -1
  152. package/dist/src/utils.js +9 -1
  153. package/dist/src/utils.js.map +1 -1
  154. package/dist/tsconfig.tsbuildinfo +1 -1
  155. package/jsx-runtime.d.ts +2 -4
  156. package/package.json +17 -15
  157. package/src/activeElement.ts +1 -1
  158. package/src/core/animation.ts +183 -0
  159. package/src/core/config.ts +77 -0
  160. package/src/core/domRenderer.ts +1308 -0
  161. package/src/core/elementNode.ts +1198 -0
  162. package/src/core/flex.ts +284 -0
  163. package/src/core/focusKeyTypes.ts +87 -0
  164. package/src/core/focusManager.ts +359 -0
  165. package/src/core/index.ts +13 -0
  166. package/src/core/intrinsicTypes.ts +199 -0
  167. package/src/core/lightningInit.ts +147 -0
  168. package/src/core/nodeTypes.ts +6 -0
  169. package/src/core/shaders.ts +567 -0
  170. package/src/core/states.ts +91 -0
  171. package/src/core/timings.ts +261 -0
  172. package/src/core/utils.ts +222 -0
  173. package/src/devtools/index.ts +1 -1
  174. package/src/index.ts +3 -3
  175. package/src/primitives/Column.tsx +10 -12
  176. package/src/primitives/FPSCounter.tsx +15 -1
  177. package/src/primitives/Grid.tsx +57 -33
  178. package/src/primitives/Image.tsx +36 -0
  179. package/src/primitives/KeepAlive.tsx +124 -0
  180. package/src/primitives/Lazy.tsx +66 -37
  181. package/src/primitives/Marquee.tsx +149 -0
  182. package/src/primitives/Preserve.tsx +18 -0
  183. package/src/primitives/Row.tsx +13 -14
  184. package/src/primitives/Suspense.tsx +39 -0
  185. package/src/primitives/Virtual.tsx +478 -0
  186. package/src/primitives/VirtualGrid.tsx +220 -0
  187. package/src/primitives/Visible.tsx +1 -2
  188. package/src/primitives/announcer/announcer.ts +16 -10
  189. package/src/primitives/announcer/index.ts +12 -2
  190. package/src/primitives/announcer/speech.ts +188 -27
  191. package/src/primitives/createFocusStack.tsx +18 -7
  192. package/src/primitives/createTag.tsx +31 -0
  193. package/src/primitives/index.ts +18 -4
  194. package/src/primitives/types.ts +12 -2
  195. package/src/primitives/useFocusManager.ts +3 -3
  196. package/src/primitives/useHold.ts +69 -0
  197. package/src/primitives/useMouse.ts +306 -67
  198. package/src/primitives/utils/chainFunctions.ts +40 -9
  199. package/src/primitives/utils/createBlurredImage.ts +366 -0
  200. package/src/primitives/utils/createSpriteMap.ts +6 -4
  201. package/src/primitives/utils/handleNavigation.ts +300 -84
  202. package/src/primitives/utils/withScrolling.ts +91 -18
  203. package/src/render.ts +10 -8
  204. package/src/solidOpts.ts +31 -24
  205. package/src/types.ts +1 -15
  206. package/src/utils.ts +11 -1
@@ -0,0 +1,261 @@
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2023 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ /**
21
+ * Core Utility Functions
22
+ *
23
+ * @module
24
+ */
25
+
26
+ export const EPSILON = 0.000001;
27
+ export let ARRAY_TYPE =
28
+ typeof Float32Array !== 'undefined' ? Float32Array : Array;
29
+ export const RANDOM = Math.random;
30
+ export const ANGLE_ORDER = 'zyx';
31
+ const degree = Math.PI / 180;
32
+
33
+ export const setMatrixArrayType = (
34
+ type: Float32ArrayConstructor | ArrayConstructor,
35
+ ) => {
36
+ ARRAY_TYPE = type;
37
+ };
38
+
39
+ /**
40
+ * Merges two colors based on a given progress value.
41
+ *
42
+ * This function takes two colors (c1 and c2) represented as 32-bit integers
43
+ * in RGBA format and blends them based on the provided progress value (p).
44
+ * The result is a new color that is a weighted combination of the input colors,
45
+ * where the weight is determined by the progress value.
46
+ *
47
+ * @param {number} c1 - The first color in RGBA format (32-bit integer).
48
+ * @param {number} c2 - The second color in RGBA format (32-bit integer).
49
+ * @param {number} p - The progress value between 0 and 1.
50
+ * @returns {number} The merged color as a 32-bit integer in RGBA format.
51
+ */
52
+ export function mergeColorProgress(
53
+ rgba1: number,
54
+ rgba2: number,
55
+ p: number,
56
+ ): number {
57
+ const r1 = Math.trunc(rgba1 >>> 24);
58
+ const g1 = Math.trunc((rgba1 >>> 16) & 0xff);
59
+ const b1 = Math.trunc((rgba1 >>> 8) & 0xff);
60
+ const a1 = Math.trunc(rgba1 & 0xff);
61
+
62
+ const r2 = Math.trunc(rgba2 >>> 24);
63
+ const g2 = Math.trunc((rgba2 >>> 16) & 0xff);
64
+ const b2 = Math.trunc((rgba2 >>> 8) & 0xff);
65
+ const a2 = Math.trunc(rgba2 & 0xff);
66
+
67
+ const r = Math.round(r2 * p + r1 * (1 - p));
68
+ const g = Math.round(g2 * p + g1 * (1 - p));
69
+ const b = Math.round(b2 * p + b1 * (1 - p));
70
+ const a = Math.round(a2 * p + a1 * (1 - p));
71
+
72
+ return ((r << 24) | (g << 16) | (b << 8) | a) >>> 0;
73
+ }
74
+
75
+ export const toRadian = (a: number) => {
76
+ return a * degree;
77
+ };
78
+
79
+ export const equals = (a: number, b: number) => {
80
+ return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
81
+ };
82
+
83
+ export const rand = (min: number, max: number) => {
84
+ return Math.floor(Math.random() * (max - min + 1) + min);
85
+ };
86
+
87
+ export const isPowerOfTwo = (value: number) => {
88
+ return value && !(value & (value - 1));
89
+ };
90
+
91
+ const getTimingBezier = (
92
+ a: number,
93
+ b: number,
94
+ c: number,
95
+ d: number,
96
+ ): ((time: number) => number | undefined) => {
97
+ const xc = 3.0 * a;
98
+ const xb = 3.0 * (c - a) - xc;
99
+ const xa = 1.0 - xc - xb;
100
+ const yc = 3.0 * b;
101
+ const yb = 3.0 * (d - b) - yc;
102
+ const ya = 1.0 - yc - yb;
103
+
104
+ return function (time: number): number | undefined {
105
+ if (time >= 1.0) {
106
+ return 1;
107
+ }
108
+ if (time <= 0) {
109
+ return 0;
110
+ }
111
+
112
+ let t = 0.5,
113
+ cbx,
114
+ cbxd,
115
+ dx;
116
+
117
+ for (let it = 0; it < 20; it++) {
118
+ cbx = t * (t * (t * xa + xb) + xc);
119
+ dx = time - cbx;
120
+ if (dx > -1e-8 && dx < 1e-8) {
121
+ return t * (t * (t * ya + yb) + yc);
122
+ }
123
+
124
+ // Cubic bezier derivative.
125
+ cbxd = t * (t * (3 * xa) + 2 * xb) + xc;
126
+
127
+ if (cbxd > 1e-10 && cbxd < 1e-10) {
128
+ // Problematic. Fall back to binary search method.
129
+ break;
130
+ }
131
+
132
+ t += dx / cbxd;
133
+ }
134
+
135
+ // Fallback: binary search method. This is more reliable when there are near-0 slopes.
136
+ let minT = 0;
137
+ let maxT = 1;
138
+ for (let it = 0; it < 20; it++) {
139
+ t = 0.5 * (minT + maxT);
140
+
141
+ cbx = t * (t * (t * xa + xb) + xc);
142
+
143
+ dx = time - cbx;
144
+ if (dx > -1e-8 && dx < 1e-8) {
145
+ // Solution found!
146
+ return t * (t * (t * ya + yb) + yc);
147
+ }
148
+
149
+ if (dx < 0) {
150
+ maxT = t;
151
+ } else {
152
+ minT = t;
153
+ }
154
+ }
155
+ };
156
+ };
157
+
158
+ interface TimingFunctionMap {
159
+ [key: string]: (time: number) => number | undefined;
160
+ }
161
+
162
+ type TimingLookupArray = number[];
163
+ interface TimingLookup {
164
+ [key: string]: TimingLookupArray;
165
+ }
166
+
167
+ const timingMapping: TimingFunctionMap = {};
168
+
169
+ const timingLookup: TimingLookup = {
170
+ ease: [0.25, 0.1, 0.25, 1.0],
171
+ 'ease-in': [0.42, 0, 1.0, 1.0],
172
+ 'ease-out': [0, 0, 0.58, 1.0],
173
+ 'ease-in-out': [0.42, 0, 0.58, 1.0],
174
+ 'ease-in-sine': [0.12, 0, 0.39, 0],
175
+ 'ease-out-sine': [0.12, 0, 0.39, 0],
176
+ 'ease-in-out-sine': [0.37, 0, 0.63, 1],
177
+ 'ease-in-cubic': [0.32, 0, 0.67, 0],
178
+ 'ease-out-cubic': [0.33, 1, 0.68, 1],
179
+ 'ease-in-out-cubic': [0.65, 0, 0.35, 1],
180
+ 'ease-in-circ': [0.55, 0, 1, 0.45],
181
+ 'ease-out-circ': [0, 0.55, 0.45, 1],
182
+ 'ease-in-out-circ': [0.85, 0, 0.15, 1],
183
+ 'ease-in-back': [0.36, 0, 0.66, -0.56],
184
+ 'ease-out-back': [0.34, 1.56, 0.64, 1],
185
+ 'ease-in-out-back': [0.68, -0.6, 0.32, 1.6],
186
+ };
187
+
188
+ const defaultTiming = (t: number): number => t;
189
+
190
+ const parseCubicBezier = (str: string) => {
191
+ //cubic-bezier(0.84, 0.52, 0.56, 0.6)
192
+ const regex = /-?\d*\.?\d+/g;
193
+ const match = str.match(regex);
194
+
195
+ if (match) {
196
+ const [num1, num2, num3, num4] = match;
197
+ const a = parseFloat(num1 || '0.42');
198
+ const b = parseFloat(num2 || '0');
199
+ const c = parseFloat(num3 || '1');
200
+ const d = parseFloat(num4 || '1');
201
+
202
+ const timing = getTimingBezier(a, b, c, d);
203
+ timingMapping[str] = timing;
204
+
205
+ return timing;
206
+ }
207
+
208
+ // parse failed, return linear
209
+ console.warn('Unknown cubic-bezier timing: ' + str);
210
+ return defaultTiming;
211
+ };
212
+
213
+ export const getTimingFunction = (
214
+ str: string,
215
+ ): ((time: number) => number | undefined) => {
216
+ if (str === 'linear') {
217
+ return defaultTiming;
218
+ }
219
+
220
+ if (timingMapping[str] !== undefined) {
221
+ return timingMapping[str] || defaultTiming;
222
+ }
223
+
224
+ if (str === 'step-start') {
225
+ return () => {
226
+ return 1;
227
+ };
228
+ }
229
+
230
+ if (str === 'step-end') {
231
+ return (time: number) => {
232
+ return time === 1 ? 1 : 0;
233
+ };
234
+ }
235
+
236
+ const lookup = timingLookup[str];
237
+ if (lookup !== undefined) {
238
+ const [a, b, c, d] = lookup;
239
+ // @ts-ignore - TS doesn't understand that we've checked for undefined
240
+ const timing = getTimingBezier(a, b, c, d);
241
+ timingMapping[str] = timing;
242
+ return timing;
243
+ }
244
+
245
+ if (str.startsWith('cubic-bezier')) {
246
+ return parseCubicBezier(str);
247
+ }
248
+
249
+ console.warn('Unknown timing function: ' + str);
250
+ return defaultTiming;
251
+ };
252
+
253
+ /**
254
+ * Convert bytes to string of megabytes with 2 decimal points
255
+ *
256
+ * @param bytes
257
+ * @returns
258
+ */
259
+ export function bytesToMb(bytes: number) {
260
+ return (bytes / 1024 / 1024).toFixed(2);
261
+ }
@@ -0,0 +1,222 @@
1
+ import { type INode, type Point } from '@lightningjs/renderer';
2
+ import { Config, isDev } from './config.js';
3
+ import type { Styles, ElementText, TextNode } from './intrinsicTypes.js';
4
+ import { ElementNode } from './elementNode.js';
5
+ import { NodeType } from './nodeTypes.js';
6
+
7
+ function hasDebug(node: any) {
8
+ return isObject(node) && node.debug;
9
+ }
10
+
11
+ export function log(
12
+ msg: string,
13
+ node: ElementNode | ElementText | TextNode,
14
+ ...args: any[]
15
+ ) {
16
+ if (isDev) {
17
+ if (Config.debug || hasDebug(node) || hasDebug(args[0])) {
18
+ console.log(msg, node, ...args);
19
+ }
20
+ }
21
+ }
22
+
23
+ export const isFunc = (obj: unknown): obj is CallableFunction =>
24
+ obj instanceof Function;
25
+
26
+ export const isFunction = (obj: unknown): obj is Function =>
27
+ typeof obj === 'function';
28
+
29
+ export function isObject(
30
+ item: unknown,
31
+ ): item is Record<string | number | symbol, unknown> {
32
+ return typeof item === 'object';
33
+ }
34
+
35
+ export function isArray(item: unknown): item is any[] {
36
+ return Array.isArray(item);
37
+ }
38
+
39
+ export function isString(item: unknown): item is string {
40
+ return typeof item === 'string';
41
+ }
42
+
43
+ export function isNumber(item: unknown): item is number {
44
+ return typeof item === 'number';
45
+ }
46
+
47
+ export function isInteger(item: unknown): item is number {
48
+ return Number.isInteger(item);
49
+ }
50
+
51
+ export function isINode(node: object): node is INode {
52
+ return 'destroy' in node && typeof node.destroy === 'function';
53
+ }
54
+
55
+ export function isElementNode(node: unknown): node is ElementNode {
56
+ return node instanceof ElementNode;
57
+ }
58
+
59
+ export function isElementText(
60
+ node: ElementNode | ElementText | TextNode,
61
+ ): node is ElementText {
62
+ return node._type === NodeType.TextNode;
63
+ }
64
+
65
+ export function isTextNode(
66
+ node: ElementNode | ElementText | TextNode,
67
+ ): node is TextNode {
68
+ return node._type === NodeType.Text;
69
+ }
70
+
71
+ export function keyExists(
72
+ obj: Record<string, unknown>,
73
+ keys: (string | number | symbol)[],
74
+ ) {
75
+ for (const key of keys) {
76
+ if (key in obj) {
77
+ return true;
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+
83
+ export function spliceItem<T>(
84
+ arr: T[],
85
+ item: T,
86
+ deleteCount: number,
87
+ ...insert: T[]
88
+ ): number {
89
+ const index = arr.indexOf(item);
90
+ if (index > -1) {
91
+ arr.splice(index, deleteCount, ...insert);
92
+ }
93
+ return index;
94
+ }
95
+
96
+ export function flattenStyles(
97
+ obj: Styles | undefined | (Styles | undefined)[],
98
+ result: Styles = {},
99
+ ): Styles {
100
+ if (isArray(obj)) {
101
+ obj.forEach((item) => {
102
+ flattenStyles(item, result);
103
+ });
104
+ } else if (obj) {
105
+ // handle the case where the object is not an array
106
+ for (const key in obj) {
107
+ // be careful of 0 values
108
+ if (result[key] === undefined) {
109
+ result[key as keyof Styles] = obj[key as keyof Styles]!;
110
+ }
111
+ }
112
+ }
113
+
114
+ return result;
115
+ }
116
+
117
+ export function logRenderTree(node: ElementNode) {
118
+ const tree = [node];
119
+ let parent = node.parent;
120
+ while (parent) {
121
+ tree.push(parent);
122
+ parent = parent.parent;
123
+ }
124
+ tree.reverse();
125
+
126
+ let output = `
127
+ function convertEffectsToShader(styleEffects) {
128
+ const effects = [];
129
+ let index = 0;
130
+
131
+ for (const [type, props] of Object.entries(styleEffects)) {
132
+ effects.push({ type, props });
133
+ index++;
134
+ }
135
+ return createShader('DynamicShader', { effects });
136
+ }
137
+ `;
138
+ tree.forEach((node, i) => {
139
+ if (!node._rendererProps) {
140
+ return;
141
+ }
142
+ node._rendererProps.parent = undefined;
143
+ node._rendererProps.shader = undefined;
144
+ const props = JSON.stringify(node._rendererProps, null, 2);
145
+ const effects = node._effects
146
+ ? `props${i}.shader = convertEffectsToShader(${JSON.stringify(node._effects, null, 2)});`
147
+ : '';
148
+ const parent = i === 0 ? 'rootNode' : `node${i - 1}`;
149
+ output += `
150
+ const props${i} = ${props};
151
+ props${i}.parent = ${parent};
152
+ ${effects}
153
+ const node${i} = renderer.createNode(props${i});
154
+ `;
155
+ });
156
+
157
+ return output;
158
+ }
159
+
160
+ export interface Rect extends Point {
161
+ width: number;
162
+ height: number;
163
+ }
164
+
165
+ /**
166
+ * Calculates the rectangle of an element on the screen,
167
+ * taking into account its position, size, and scaling.
168
+ *
169
+ * @param el - The element to calculate the rectangle for.
170
+ * @param from - Optional ancestor element to calculate the rectangle relative to.
171
+ * @param out - Optional output rectangle to fill with the result.
172
+ * @returns The rectangle of the element on the screen.
173
+ */
174
+ export function getElementScreenRect(
175
+ el: ElementNode | ElementText,
176
+ from?: ElementNode,
177
+ out: Rect = { x: 0, y: 0, width: 0, height: 0 },
178
+ ): Rect {
179
+ out.x = 0;
180
+ out.y = 0;
181
+ out.width = el.width;
182
+ out.height = el.height;
183
+
184
+ if (el.scaleX != null) out.width *= el.scaleX;
185
+ if (el.scaleY != null) out.height *= el.scaleY;
186
+
187
+ let curr = el as ElementNode | undefined | null;
188
+ while (curr != null && curr !== from) {
189
+ out.x += curr.x;
190
+ out.y += curr.y;
191
+
192
+ if (curr.scaleX != null) {
193
+ out.x += (curr.width / 2) * (1 - curr.scaleX);
194
+ }
195
+ if (curr.scaleY != null) {
196
+ out.y += (curr.height / 2) * (1 - curr.scaleY);
197
+ }
198
+
199
+ curr = curr.parent;
200
+ }
201
+
202
+ if (Config.rendererOptions != null) {
203
+ let dpr = Config.rendererOptions.deviceLogicalPixelRatio;
204
+ if (dpr != null) {
205
+ out.x *= dpr;
206
+ out.y *= dpr;
207
+ out.width *= dpr;
208
+ out.height *= dpr;
209
+ }
210
+ }
211
+
212
+ return out;
213
+ }
214
+
215
+ /**
216
+ * Checks if the element has focus.\
217
+ * ({@link ElementNode.states} contains the {@link Config.focusStateKey} focus state)
218
+ */
219
+ export function isFocused(el: ElementNode | ElementText): boolean {
220
+ return el?.states?.has(Config.focusStateKey);
221
+ }
222
+ export const hasFocus = isFocused;
@@ -1,5 +1,5 @@
1
1
  import * as debug from '@solid-devtools/debugger/types';
2
- import * as lng from '@lightningtv/core';
2
+ import * as lng from '../core/index.js';
3
3
 
4
4
  const EMPTY_CHILDREN: (lng.ElementNode | lng.ElementText)[] = [];
5
5
 
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from '@lightningtv/solid/jsx-runtime';
2
- export * from '@lightningtv/core';
3
- export type * from '@lightningtv/core';
4
- export type { KeyHandler, KeyMap } from '@lightningtv/core/focusManager';
2
+ export * from './core/index.js';
3
+ export type * from './core/index.js';
4
+ export type { KeyHandler, KeyMap } from './core/focusManager.js';
5
5
  export * from './activeElement.js';
6
6
  export * from './utils.js';
7
7
  export * from './render.js';
@@ -1,10 +1,9 @@
1
1
  import { type Component } from 'solid-js';
2
2
  import { ElementNode, combineStyles, type NodeStyles } from '@lightningtv/solid';
3
3
  import {
4
- handleNavigation,
5
- onGridFocus,
4
+ navigableForwardFocus, handleNavigation
6
5
  } from './utils/handleNavigation.js';
7
- import { withScrolling } from './utils/withScrolling.js';
6
+ import { scrollColumn } from './utils/withScrolling.js';
8
7
  import { chainFunctions } from './utils/chainFunctions.js';
9
8
  import type { ColumnProps } from './types.js';
10
9
 
@@ -20,16 +19,15 @@ const ColumnStyles: NodeStyles = {
20
19
  },
21
20
  };
22
21
 
23
- const onUp = handleNavigation('up');
24
- const onDown = handleNavigation('down');
25
- const scroll = withScrolling(false);
26
-
27
22
  function scrollToIndex(this: ElementNode, index: number) {
28
23
  this.selected = index;
29
- scroll(index, this);
30
- this.setFocus();
24
+ scrollColumn(index, this);
25
+ this.children[index]?.setFocus();
31
26
  }
32
27
 
28
+ const onUp = handleNavigation('up');
29
+ const onDown = handleNavigation('down');
30
+
33
31
  export const Column: Component<ColumnProps> = (props) => {
34
32
  return (
35
33
  <view
@@ -38,15 +36,15 @@ export const Column: Component<ColumnProps> = (props) => {
38
36
  onDown={/* @once */ chainFunctions(props.onDown, onDown)}
39
37
  selected={props.selected || 0}
40
38
  scrollToIndex={scrollToIndex}
41
- forwardFocus={/* once */ onGridFocus(props.onSelectedChanged)}
39
+ forwardFocus={navigableForwardFocus}
42
40
  onLayout={
43
41
  /* @once */
44
- props.selected ? chainFunctions(props.onLayout, scroll) : props.onLayout
42
+ props.selected ? chainFunctions(props.onLayout, scrollColumn) : props.onLayout
45
43
  }
46
44
  onSelectedChanged={
47
45
  /* @once */ chainFunctions(
48
46
  props.onSelectedChanged,
49
- props.scroll !== 'none' ? scroll : undefined,
47
+ props.scroll !== 'none' ? scrollColumn : undefined,
50
48
  )
51
49
  }
52
50
  style={/* @once */ combineStyles(props.style, ColumnStyles)}
@@ -3,7 +3,7 @@ import { createSignal } from 'solid-js';
3
3
 
4
4
  const fpsStyle = {
5
5
  color: 0x000000ff,
6
- height: 180,
6
+ height: 192,
7
7
  width: 330,
8
8
  x: 1900,
9
9
  y: 6,
@@ -27,6 +27,7 @@ const [fps, setFps] = createSignal(0);
27
27
  const [avgFps, setAvgFps] = createSignal(0);
28
28
  const [minFps, setMinFps] = createSignal(99);
29
29
  const [maxFps, setMaxFps] = createSignal(0);
30
+ const [quads, setQuads] = createSignal(0);
30
31
  const [criticalThresholdSignal, setCriticalThresholdSignal] = createSignal('');
31
32
  const [targetThresholdSignal, setTargetThresholdSignal] = createSignal('');
32
33
  const [renderableMemUsedSignal, setRenderableMemUsedSignal] = createSignal('');
@@ -86,6 +87,10 @@ export function setupFPS(root: any) {
86
87
  frameCount++;
87
88
  }
88
89
  });
90
+
91
+ root.renderer.on('quadsUpdate', (target: RendererMain, quadsData: any) => {
92
+ setQuads(quadsData.quads);
93
+ });
89
94
  }
90
95
 
91
96
  export const FPSCounter = (props: NodeProps) => {
@@ -173,6 +178,15 @@ export const FPSCounter = (props: NodeProps) => {
173
178
  {loadedTexturesSignal().toString()}
174
179
  </text>
175
180
  </view>
181
+
182
+ <view height={infoFontSize}>
183
+ <text fontSize={infoFontSize} style={fpsLabel}>
184
+ quads:
185
+ </text>
186
+ <text fontSize={infoFontSize} style={fpsLabel} x={230}>
187
+ {quads().toString()}
188
+ </text>
189
+ </view>
176
190
  </view>
177
191
  </view>
178
192
  );