@solidtv/solid 1.1.2 → 1.1.3

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 (91) hide show
  1. package/dist/src/core/clickInspector.d.ts +1 -0
  2. package/dist/src/core/clickInspector.js +69 -0
  3. package/dist/src/core/clickInspector.js.map +1 -0
  4. package/dist/src/core/config.d.ts +1 -13
  5. package/dist/src/core/config.js +10 -2
  6. package/dist/src/core/config.js.map +1 -1
  7. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -1
  8. package/dist/src/core/dom-renderer/domRenderer.js +254 -67
  9. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  10. package/dist/src/core/elementNode.d.ts +20 -7
  11. package/dist/src/core/elementNode.js +54 -14
  12. package/dist/src/core/elementNode.js.map +1 -1
  13. package/dist/src/core/focusManager.js +5 -3
  14. package/dist/src/core/focusManager.js.map +1 -1
  15. package/dist/src/core/intrinsicTypes.d.ts +2 -0
  16. package/dist/src/core/lightningInit.d.ts +1 -1
  17. package/dist/src/core/lightningInit.js +6 -6
  18. package/dist/src/core/lightningInit.js.map +1 -1
  19. package/dist/src/core/utils.js +4 -4
  20. package/dist/src/core/utils.js.map +1 -1
  21. package/dist/src/primitives/FPSCounter.jsx +5 -5
  22. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  23. package/dist/src/primitives/Image.jsx +6 -1
  24. package/dist/src/primitives/Image.jsx.map +1 -1
  25. package/dist/src/primitives/KeepAlive.jsx +13 -3
  26. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  27. package/dist/src/primitives/LazyImport.js +4 -2
  28. package/dist/src/primitives/LazyImport.js.map +1 -1
  29. package/dist/src/primitives/Preserve.jsx +10 -4
  30. package/dist/src/primitives/Preserve.jsx.map +1 -1
  31. package/dist/src/primitives/Suspense.jsx +7 -7
  32. package/dist/src/primitives/Suspense.jsx.map +1 -1
  33. package/dist/src/primitives/Virtual.jsx.map +1 -1
  34. package/dist/src/primitives/announcer/announcer.js +3 -2
  35. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  36. package/dist/src/primitives/announcer/speech.js +2 -2
  37. package/dist/src/primitives/announcer/speech.js.map +1 -1
  38. package/dist/src/primitives/borderBox.jsx +2 -1
  39. package/dist/src/primitives/borderBox.jsx.map +1 -1
  40. package/dist/src/primitives/createTag.jsx +3 -3
  41. package/dist/src/primitives/createTag.jsx.map +1 -1
  42. package/dist/src/primitives/portal.jsx +4 -3
  43. package/dist/src/primitives/portal.jsx.map +1 -1
  44. package/dist/src/primitives/utils/chainFunctions.js +35 -9
  45. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  46. package/dist/src/primitives/utils/createBlurredImage.js +57 -37
  47. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -1
  48. package/dist/src/primitives/utils/handleNavigation.js +8 -6
  49. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  50. package/dist/src/primitives/utils/withScrolling.js +1 -3
  51. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  52. package/dist/src/render.d.ts +1 -1
  53. package/dist/src/render.js +2 -1
  54. package/dist/src/render.js.map +1 -1
  55. package/dist/src/solidOpts.d.ts +1 -1
  56. package/dist/src/solidOpts.js +4 -2
  57. package/dist/src/solidOpts.js.map +1 -1
  58. package/dist/src/utils.js +10 -5
  59. package/dist/src/utils.js.map +1 -1
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/docs/README.md +2 -2
  62. package/package.json +28 -29
  63. package/src/core/clickInspector.ts +77 -0
  64. package/src/core/config.ts +6 -20
  65. package/src/core/dom-renderer/domRenderer.ts +307 -89
  66. package/src/core/dom-renderer/domRendererTypes.ts +9 -6
  67. package/src/core/elementNode.ts +80 -26
  68. package/src/core/focusManager.ts +16 -8
  69. package/src/core/intrinsicTypes.ts +19 -7
  70. package/src/core/lightningInit.ts +20 -18
  71. package/src/core/utils.ts +4 -4
  72. package/src/primitives/FPSCounter.tsx +14 -10
  73. package/src/primitives/Image.tsx +18 -9
  74. package/src/primitives/KeepAlive.tsx +18 -10
  75. package/src/primitives/LazyImport.ts +8 -6
  76. package/src/primitives/Preserve.tsx +13 -8
  77. package/src/primitives/Suspense.tsx +10 -9
  78. package/src/primitives/Virtual.tsx +1 -8
  79. package/src/primitives/announcer/announcer.ts +3 -2
  80. package/src/primitives/announcer/speech.ts +2 -2
  81. package/src/primitives/borderBox.tsx +7 -3
  82. package/src/primitives/createTag.tsx +23 -17
  83. package/src/primitives/portal.tsx +20 -10
  84. package/src/primitives/utils/chainFunctions.ts +31 -11
  85. package/src/primitives/utils/createBlurredImage.ts +58 -40
  86. package/src/primitives/utils/handleNavigation.ts +9 -7
  87. package/src/primitives/utils/withScrolling.ts +3 -5
  88. package/src/render.ts +4 -4
  89. package/src/solidOpts.ts +9 -7
  90. package/src/types.ts +0 -1
  91. package/src/utils.ts +12 -10
@@ -20,12 +20,14 @@ export function lazy<T extends Component<any>>(
20
20
  const [s, set] = createSignal<T>();
21
21
  sharedConfig.count || (sharedConfig.count = 0);
22
22
  sharedConfig.count++;
23
- (p || (p = fn())).then((mod) => {
24
- !sharedConfig.done && (sharedConfig.context = ctx);
25
- sharedConfig.count!--;
26
- set(() => mod.default);
27
- sharedConfig.context = undefined;
28
- });
23
+ (p || (p = fn()))
24
+ .then((mod) => {
25
+ !sharedConfig.done && (sharedConfig.context = ctx);
26
+ sharedConfig.count!--;
27
+ set(() => mod.default);
28
+ sharedConfig.context = undefined;
29
+ })
30
+ .catch(() => {});
29
31
  comp = s;
30
32
  } else if (!comp) {
31
33
  const [s] = createResource<T>(() =>
@@ -1,18 +1,23 @@
1
- import * as s from 'solid-js'
2
- import * as lng from '@solidtv/solid'
1
+ import * as s from 'solid-js';
2
+ import * as lng from '@solidtv/solid';
3
3
 
4
4
  function Preserve(props: lng.NodeProps): s.JSX.Element {
5
-
6
- const view = <view {...props} /> as any as lng.ElementNode
5
+ const view = (<view {...props} />) as unknown as lng.ElementNode;
7
6
 
8
7
  view.preserve = true;
9
8
 
10
- view.onRender ??= () => {view.hidden = false}
11
- view.onRemove ??= () => {view.hidden = true}
9
+ view.onRender ??= () => {
10
+ view.hidden = false;
11
+ };
12
+ view.onRemove ??= () => {
13
+ view.hidden = true;
14
+ };
12
15
 
13
- s.onCleanup(() => {view.destroy()})
16
+ s.onCleanup(() => {
17
+ view.destroy();
18
+ });
14
19
 
15
- return view as any as s.JSX.Element
20
+ return view as unknown as s.JSX.Element;
16
21
  }
17
22
 
18
23
  export default Preserve;
@@ -21,19 +21,20 @@ export function Suspense(props: {
21
21
  fallback?: s.JSX.Element;
22
22
  children: s.JSX.Element;
23
23
  }): s.JSX.Element {
24
-
25
24
  let children: s.JSX.Element;
26
25
 
27
26
  const suspense = s.Suspense({
28
27
  get children() {
29
- return [children = s.children(() => props.children) as any];
28
+ return [(children = s.children(() => props.children) as any)];
30
29
  },
31
- }) as any as () => s.JSX.Element;
30
+ }) as unknown as () => s.JSX.Element;
32
31
 
33
- return <>
34
- {suspense() ?? props.fallback}
35
- <view hidden forwardFocus={0}>
36
- {suspense() ? null : children}
37
- </view>
38
- </>
32
+ return (
33
+ <>
34
+ {suspense() ?? props.fallback}
35
+ <view hidden forwardFocus={0}>
36
+ {suspense() ? null : children}
37
+ </view>
38
+ </>
39
+ );
39
40
  }
@@ -317,7 +317,6 @@ function createVirtual<T>(
317
317
  }
318
318
  break;
319
319
  }
320
-
321
320
  case 'none':
322
321
  default:
323
322
  start = 0;
@@ -405,13 +404,7 @@ function createVirtual<T>(
405
404
  originalPosition = originalPosition ?? elm[axis];
406
405
 
407
406
  if (props.onSelectedChanged) {
408
- props.onSelectedChanged.call(
409
- this,
410
- idx,
411
- this,
412
- active,
413
- lastIdx,
414
- );
407
+ props.onSelectedChanged.call(this, idx, this, active, lastIdx);
415
408
  }
416
409
 
417
410
  if (noChange) return;
@@ -148,7 +148,7 @@ export const Announcer: Announcer = {
148
148
  lang: 'en-US',
149
149
  aria: false,
150
150
  cancel: function () {
151
- currentlySpeaking && currentlySpeaking.cancel();
151
+ currentlySpeaking?.cancel();
152
152
  },
153
153
  clearPrevFocus: function (depth = 0) {
154
154
  prevFocusPath = prevFocusPath.slice(0, depth);
@@ -178,8 +178,9 @@ export const Announcer: Announcer = {
178
178
  },
179
179
  refresh: function (depth = 0) {
180
180
  Announcer.clearPrevFocus(depth);
181
- Announcer.onFocusChange &&
181
+ if (Announcer.onFocusChange) {
182
182
  Announcer.onFocusChange(untrack(() => focusPath()));
183
+ }
183
184
  },
184
185
  setupTimers: function ({
185
186
  focusDebounce = 400,
@@ -154,7 +154,7 @@ function speak(
154
154
  resolve();
155
155
  };
156
156
  utterance.onerror = (e) => {
157
- reject(e);
157
+ reject(new Error(`Speech synthesis error: ${e.error}`));
158
158
  };
159
159
  utterances.push(utterance);
160
160
  synth.speak(utterance);
@@ -328,7 +328,7 @@ export default function (
328
328
  lang: string = 'en-US',
329
329
  voice?: string,
330
330
  ) {
331
- currentSeries && currentSeries.cancel();
331
+ currentSeries?.cancel();
332
332
  currentSeries = speakSeries(toSpeak, aria, lang, voice);
333
333
  return currentSeries;
334
334
  }
@@ -28,8 +28,12 @@ const borderComponent = (props: BorderProps) => {
28
28
  el.alpha = 1;
29
29
  }}
30
30
  onDestroy={(el) => {
31
+ const transition = el.transition;
31
32
  return el
32
- .animate({ alpha: 0 }, el.transition as any)
33
+ .animate(
34
+ { alpha: 0 },
35
+ typeof transition === 'object' ? transition : undefined,
36
+ )
33
37
  .start()
34
38
  .waitUntilStopped();
35
39
  }}
@@ -55,8 +59,8 @@ export function borderBox(
55
59
  runWithOwner(owner, () => {
56
60
  const props = accessor();
57
61
  border = borderComponent(
58
- props === true || props === undefined ? ({} as NodeProps) : props,
59
- ) as any as ElementNode;
62
+ props === true || props === undefined ? {} : props,
63
+ ) as unknown as ElementNode;
60
64
  insertNode(el, border);
61
65
  border.render();
62
66
  });
@@ -1,5 +1,5 @@
1
- import * as s from 'solid-js'
2
- import * as lng from '@solidtv/solid'
1
+ import * as s from 'solid-js';
2
+ import * as lng from '@solidtv/solid';
3
3
 
4
4
  interface Destroyable {
5
5
  (props: lng.NodeProps): s.JSX.Element;
@@ -7,21 +7,27 @@ interface Destroyable {
7
7
  }
8
8
 
9
9
  export function createTag(children: s.JSX.Element): Destroyable {
10
- const [texture, setTexture] = s.createSignal<lng.Texture | null | undefined>(null);
11
- const Tag = <view
12
- x={lng.rootNode.w - 1}
13
- y={lng.rootNode.h - 1}
14
- display='flex'
15
- onLayout={(n) => {
16
- if (n.preFlexwidth && n.width !== n.preFlexwidth) {
17
- n.rtt = true;
18
- setTimeout(() => setTexture(n.texture), 1);
19
- }
20
- }}
21
- parent={lng.rootNode} children={children}
22
- textureOptions={{
23
- preventCleanup: true
24
- }} /> as any as lng.ElementNode
10
+ const [texture, setTexture] = s.createSignal<lng.Texture | null | undefined>(
11
+ null,
12
+ );
13
+ const Tag = (
14
+ <view
15
+ x={lng.rootNode.w - 1}
16
+ y={lng.rootNode.h - 1}
17
+ display="flex"
18
+ onLayout={(n) => {
19
+ if (n.preFlexwidth && n.width !== n.preFlexwidth) {
20
+ n.rtt = true;
21
+ setTimeout(() => setTexture(n.texture), 1);
22
+ }
23
+ }}
24
+ parent={lng.rootNode}
25
+ children={children}
26
+ textureOptions={{
27
+ preventCleanup: true,
28
+ }}
29
+ />
30
+ ) as unknown as lng.ElementNode;
25
31
  Tag.render(false);
26
32
 
27
33
  const TagComponent = (props: lng.NodeProps) => {
@@ -1,5 +1,14 @@
1
1
  import { rootNode, type ElementNode, insert } from '@solidtv/solid';
2
- import { createEffect, createMemo, createRoot, createSignal, getOwner, JSX, onCleanup, runWithOwner } from 'solid-js';
2
+ import {
3
+ createEffect,
4
+ createMemo,
5
+ createRoot,
6
+ createSignal,
7
+ getOwner,
8
+ JSX,
9
+ onCleanup,
10
+ runWithOwner,
11
+ } from 'solid-js';
3
12
 
4
13
  export function Portal(props: { mount?: string; children: JSX.Element }) {
5
14
  let content: undefined | (() => JSX.Element);
@@ -11,15 +20,16 @@ export function Portal(props: { mount?: string; children: JSX.Element }) {
11
20
  return rootNode.searchChildrenById(mount) || rootNode;
12
21
  }
13
22
 
14
- createEffect(
15
- () => {
16
- const [clean, setClean] = createSignal(false);
17
- const cleanup = () => setClean(true);
18
- content || (content = runWithOwner(owner, () => createMemo(() => props.children)));
19
- createRoot(dispose => insert(mount(), () => (!clean() ? content!() : dispose()), null));
20
- onCleanup(cleanup);
21
- }
22
- );
23
+ createEffect(() => {
24
+ const [clean, setClean] = createSignal(false);
25
+ const cleanup = () => setClean(true);
26
+ content =
27
+ content || runWithOwner(owner, () => createMemo(() => props.children));
28
+ createRoot((dispose) =>
29
+ insert(mount(), () => (!clean() ? content!() : dispose()), null),
30
+ );
31
+ onCleanup(cleanup);
32
+ });
23
33
 
24
34
  return null;
25
35
  }
@@ -23,22 +23,42 @@ export function chainFunctions<T extends AnyFunction>(
23
23
  export function chainFunctions(
24
24
  ...fns: (AnyFunction | undefined | null | false)[]
25
25
  ): AnyFunction | undefined {
26
- const onlyFunctions = fns.filter((func) => typeof func === 'function');
27
- if (onlyFunctions.length === 0) {
28
- return undefined;
26
+ // Inline filter to avoid the intermediate array allocation when most
27
+ // callers pass 2 args and one or both happen to be falsy.
28
+ let first: AnyFunction | undefined;
29
+ let onlyFunctions: AnyFunction[] | undefined;
30
+ for (let i = 0; i < fns.length; i++) {
31
+ const fn = fns[i];
32
+ if (typeof fn !== 'function') continue;
33
+ if (first === undefined) {
34
+ first = fn;
35
+ } else {
36
+ if (onlyFunctions === undefined) onlyFunctions = [first];
37
+ onlyFunctions.push(fn);
38
+ }
29
39
  }
30
40
 
31
- if (onlyFunctions.length === 1) {
32
- return onlyFunctions[0];
41
+ if (first === undefined) return undefined;
42
+ if (onlyFunctions === undefined) return first;
43
+
44
+ // Fast path: exactly two functions — the common case for ref/handler
45
+ // forwarding (props.onX + local onX). Avoids the loop.
46
+ if (onlyFunctions.length === 2) {
47
+ const a = onlyFunctions[0]!;
48
+ const b = onlyFunctions[1]!;
49
+ return function (this: unknown, ...innerArgs) {
50
+ const result = a.apply(this, innerArgs);
51
+ if (result === true) return result;
52
+ return b.apply(this, innerArgs);
53
+ };
33
54
  }
34
55
 
35
- return function (...innerArgs) {
56
+ const chained = onlyFunctions;
57
+ return function (this: unknown, ...innerArgs) {
36
58
  let result;
37
- for (const func of onlyFunctions) {
38
- result = func.apply(this, innerArgs);
39
- if (result === true) {
40
- return result;
41
- }
59
+ for (let i = 0; i < chained.length; i++) {
60
+ result = chained[i]!.apply(this, innerArgs);
61
+ if (result === true) return result;
42
62
  }
43
63
  return result;
44
64
  };
@@ -100,32 +100,38 @@ function applyVerticalBlur(
100
100
  half: number,
101
101
  ): void {
102
102
  for (let y = 0; y < height; y++) {
103
+ const kStart = -y < -half ? -half : -y;
104
+ const kEnd = height - 1 - y < half ? height - 1 - y : half;
105
+
106
+ // Kernel sums to 1; only edge rows need a renormalization factor.
107
+ let invWeight = 1;
108
+ if (kStart !== -half || kEnd !== half) {
109
+ let weightSum = 0;
110
+ for (let k = kStart; k <= kEnd; k++) weightSum += kernel[k + half]!;
111
+ invWeight = 1 / weightSum;
112
+ }
113
+
114
+ const rowBase = y * width;
103
115
  for (let x = 0; x < width; x++) {
104
116
  let r = 0,
105
117
  g = 0,
106
118
  b = 0,
107
119
  a = 0;
108
- let weightSum = 0;
109
120
 
110
- for (let ky = -half; ky <= half; ky++) {
111
- const py = y + ky;
112
- if (py >= 0 && py < height) {
113
- const pixelIndex = (py * width + x) * 4;
114
- const weight = kernel[ky + half]!;
115
-
116
- r += input[pixelIndex]! * weight;
117
- g += input[pixelIndex + 1]! * weight;
118
- b += input[pixelIndex + 2]! * weight;
119
- a += input[pixelIndex + 3]! * weight;
120
- weightSum += weight;
121
- }
121
+ for (let ky = kStart; ky <= kEnd; ky++) {
122
+ const pixelIndex = ((y + ky) * width + x) * 4;
123
+ const weight = kernel[ky + half]!;
124
+ r += input[pixelIndex]! * weight;
125
+ g += input[pixelIndex + 1]! * weight;
126
+ b += input[pixelIndex + 2]! * weight;
127
+ a += input[pixelIndex + 3]! * weight;
122
128
  }
123
129
 
124
- const outputIndex = (y * width + x) * 4;
125
- output[outputIndex] = r / weightSum;
126
- output[outputIndex + 1] = g / weightSum;
127
- output[outputIndex + 2] = b / weightSum;
128
- output[outputIndex + 3] = a / weightSum;
130
+ const outputIndex = (rowBase + x) * 4;
131
+ output[outputIndex] = r * invWeight;
132
+ output[outputIndex + 1] = g * invWeight;
133
+ output[outputIndex + 2] = b * invWeight;
134
+ output[outputIndex + 3] = a * invWeight;
129
135
  }
130
136
  }
131
137
  }
@@ -147,33 +153,46 @@ function applyHorizontalBlur(
147
153
  kernel: Readonly<GaussianKernel>,
148
154
  half: number,
149
155
  ): void {
156
+ // Precompute per-column inverse weight sums; kernel sums to 1 in the interior.
157
+ const invWeights = new Float64Array(width);
158
+ for (let x = 0; x < width; x++) {
159
+ const kStart = -x < -half ? -half : -x;
160
+ const kEnd = width - 1 - x < half ? width - 1 - x : half;
161
+ if (kStart === -half && kEnd === half) {
162
+ invWeights[x] = 1;
163
+ } else {
164
+ let weightSum = 0;
165
+ for (let k = kStart; k <= kEnd; k++) weightSum += kernel[k + half]!;
166
+ invWeights[x] = 1 / weightSum;
167
+ }
168
+ }
169
+
150
170
  for (let y = 0; y < height; y++) {
171
+ const rowBase = y * width;
151
172
  for (let x = 0; x < width; x++) {
173
+ const kStart = -x < -half ? -half : -x;
174
+ const kEnd = width - 1 - x < half ? width - 1 - x : half;
175
+
152
176
  let r = 0,
153
177
  g = 0,
154
178
  b = 0,
155
179
  a = 0;
156
- let weightSum = 0;
157
180
 
158
- for (let kx = -half; kx <= half; kx++) {
159
- const px = x + kx;
160
- if (px >= 0 && px < width) {
161
- const pixelIndex = (y * width + px) * 4;
162
- const weight = kernel[kx + half]!;
163
-
164
- r += input[pixelIndex]! * weight;
165
- g += input[pixelIndex + 1]! * weight;
166
- b += input[pixelIndex + 2]! * weight;
167
- a += input[pixelIndex + 3]! * weight;
168
- weightSum += weight;
169
- }
181
+ for (let kx = kStart; kx <= kEnd; kx++) {
182
+ const pixelIndex = (rowBase + x + kx) * 4;
183
+ const weight = kernel[kx + half]!;
184
+ r += input[pixelIndex]! * weight;
185
+ g += input[pixelIndex + 1]! * weight;
186
+ b += input[pixelIndex + 2]! * weight;
187
+ a += input[pixelIndex + 3]! * weight;
170
188
  }
171
189
 
172
- const outputIndex = (y * width + x) * 4;
173
- output[outputIndex] = r / weightSum;
174
- output[outputIndex + 1] = g / weightSum;
175
- output[outputIndex + 2] = b / weightSum;
176
- output[outputIndex + 3] = a / weightSum;
190
+ const invWeight = invWeights[x]!;
191
+ const outputIndex = (rowBase + x) * 4;
192
+ output[outputIndex] = r * invWeight;
193
+ output[outputIndex + 1] = g * invWeight;
194
+ output[outputIndex + 2] = b * invWeight;
195
+ output[outputIndex + 3] = a * invWeight;
177
196
  }
178
197
  }
179
198
  }
@@ -215,15 +234,14 @@ function gaussianBlurConvolution(
215
234
  ): ImageData {
216
235
  const { data } = imageData;
217
236
  const { width, height } = dimensions;
237
+ const tempData = new Uint8ClampedArray(data.length);
218
238
  const output = new Uint8ClampedArray(data.length);
219
239
 
220
240
  const kernelSize = Math.ceil(radius * 2) * 2 + 1;
221
241
  const kernel = generateGaussianKernel(kernelSize, radius);
222
- const half = Math.floor(kernelSize / 2);
223
-
224
- applyHorizontalBlur(data, output, width, height, kernel, half);
242
+ const half = (kernelSize - 1) >> 1;
225
243
 
226
- const tempData = new Uint8ClampedArray(output);
244
+ applyHorizontalBlur(data, tempData, width, height, kernel, half);
227
245
  applyVerticalBlur(tempData, output, width, height, kernel, half);
228
246
 
229
247
  return new ImageData(output, width, height);
@@ -30,7 +30,7 @@ export const defaultTransitionUp = {
30
30
  },
31
31
  };
32
32
 
33
- function idxInArray(idx: number, arr: readonly any[]): boolean {
33
+ function idxInArray(idx: number, arr: readonly unknown[]): boolean {
34
34
  return idx >= 0 && idx < arr.length;
35
35
  }
36
36
 
@@ -220,10 +220,10 @@ export function moveSelection(
220
220
  return selectChild(el, selected);
221
221
  }
222
222
 
223
- function distanceBetweenRectCenters(a: lng.Rect, b: lng.Rect): number {
224
- const dx = Math.abs(a.x + a.width / 2 - (b.x + b.width / 2)) / 2;
225
- const dy = Math.abs(a.y + a.height / 2 - (b.y + b.height / 2)) / 2;
226
- return Math.sqrt(dx * dx + dy * dy);
223
+ function squaredDistanceBetweenRectCenters(a: lng.Rect, b: lng.Rect): number {
224
+ const dx = a.x + a.width / 2 - (b.x + b.width / 2);
225
+ const dy = a.y + a.height / 2 - (b.y + b.height / 2);
226
+ return dx * dx + dy * dy;
227
227
  }
228
228
 
229
229
  function findClosestFocusableChildIdx(
@@ -238,12 +238,14 @@ function findClosestFocusableChildIdx(
238
238
  let closestIdx = -1;
239
239
  let closestDist = Infinity;
240
240
 
241
- for (const [idx, child] of el.children.entries()) {
241
+ const children = el.children;
242
+ for (let idx = 0; idx < children.length; idx++) {
243
+ const child = children[idx]!;
242
244
  if (!child.skipFocus) {
243
245
  lng.getElementScreenRect(child, el, childRect);
244
246
  childRect.x += elRect.x;
245
247
  childRect.y += elRect.y;
246
- const distance = distanceBetweenRectCenters(prevRect, childRect);
248
+ const distance = squaredDistanceBetweenRectCenters(prevRect, childRect);
247
249
  if (distance < closestDist) {
248
250
  closestDist = distance;
249
251
  closestIdx = idx;
@@ -31,9 +31,9 @@ export interface ScrollableElement extends ElementNode {
31
31
  }
32
32
 
33
33
  // From the renderer, not exported
34
- const InViewPort = 8;
34
+ const InViewPort = 8 as const;
35
35
  const isNotShown = (node: ElementNode | ElementText) => {
36
- return node.lng.renderState !== InViewPort;
36
+ return (node.lng.renderState as number) !== InViewPort;
37
37
  };
38
38
  /*
39
39
  Auto Scrolling starts scrolling right away until the last item is shown. Keeping a full view of the list.
@@ -114,9 +114,7 @@ export function withScrolling(isRow: boolean): Scroller {
114
114
  : Math.max(targetPosition, componentRef[axis]);
115
115
  componentRef.offset = componentRef.offset ?? rootPosition;
116
116
  const offset = componentRef.offset;
117
- selectedElement =
118
- selectedElement ||
119
- (componentRef.children[selected] as ElementNode | undefined);
117
+ selectedElement = selectedElement || componentRef.children[selected];
120
118
 
121
119
  if (!selectedElement) {
122
120
  return;
package/src/render.ts CHANGED
@@ -34,10 +34,9 @@ export function createRenderer(
34
34
  rendererOptions?: RendererMainSettings | DomRendererMainSettings,
35
35
  node?: HTMLElement | string,
36
36
  ) {
37
- const options =
38
- rendererOptions || (Config.rendererOptions as RendererMainSettings);
37
+ const options = rendererOptions || Config.rendererOptions;
39
38
 
40
- renderer = startLightningRenderer(options, node || 'app');
39
+ renderer = startLightningRenderer(options!, node || 'app');
41
40
  //Prevent this from happening automatically
42
41
  Config.setActiveElement = setActiveElement;
43
42
  rootNode.lng = renderer.root!;
@@ -135,6 +134,7 @@ export function Dynamic<T extends Record<string, any>>(
135
134
 
136
135
  case 'string': {
137
136
  const el = createElement(component);
137
+ (el as { componentName?: string }).componentName = component;
138
138
  spread(el, others);
139
139
  return el;
140
140
  }
@@ -158,7 +158,7 @@ export const Text = (props: TextProps) => {
158
158
  return el as unknown as JSXElement;
159
159
  };
160
160
 
161
- export function registerDefaultShader(name: string, shader: any) {
161
+ export function registerDefaultShader(_name: string, _shader: any) {
162
162
  // noop for v2
163
163
  // renderer.stage.shManager.registerShaderType('rounded', Rounded);
164
164
  }
package/src/solidOpts.ts CHANGED
@@ -11,10 +11,10 @@ import {
11
11
  import type { SolidNode, SolidRendererOptions } from './types.js';
12
12
 
13
13
  Object.defineProperty(ElementNode.prototype, 'preserve', {
14
- get(): boolean | undefined {
14
+ get(this: ElementNode): boolean | undefined {
15
15
  return this._queueDelete === 0;
16
16
  },
17
- set(v: boolean) {
17
+ set(this: ElementNode, v: boolean) {
18
18
  this._queueDelete = v ? 0 : undefined;
19
19
  },
20
20
  });
@@ -55,7 +55,9 @@ export default {
55
55
  parent.insertChild(node, anchor);
56
56
 
57
57
  if (node instanceof ElementNode) {
58
- node.parent!.rendered && node.render(true);
58
+ if (node.parent!.rendered) {
59
+ node.render(true);
60
+ }
59
61
  if (prevParent !== undefined) {
60
62
  pushDeleteQueue(node, 1);
61
63
  }
@@ -83,13 +85,13 @@ export default {
83
85
  return node.parent;
84
86
  },
85
87
  getFirstChild(node: ElementNode): SolidNode | undefined {
86
- return node.children[0] as SolidNode;
88
+ return node.children[0];
87
89
  },
88
90
  getNextSibling(node: SolidNode): SolidNode | undefined {
89
- const children = node.parent!.children || [];
90
- const index = children.indexOf(node as any) + 1;
91
+ const children = (node.parent!.children || []) as SolidNode[];
92
+ const index = children.indexOf(node) + 1;
91
93
  if (index < children.length) {
92
- return children[index] as SolidNode;
94
+ return children[index];
93
95
  }
94
96
  return undefined;
95
97
  },
package/src/types.ts CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  type ElementText,
5
5
  type TextNode,
6
6
  } from './core/index.js';
7
- import type { JSXElement } from 'solid-js';
8
7
  import { createRenderer } from 'solid-js/universal';
9
8
 
10
9
  export type SolidRendererOptions = Parameters<
package/src/utils.ts CHANGED
@@ -19,16 +19,18 @@ export function hexColor(color: string | number = ''): number {
19
19
 
20
20
  if (typeof color === 'string') {
21
21
  // Renderer expects RGBA values
22
- if (color.startsWith('#')) {
23
- return Number(
24
- color.replace('#', '0x') + (color.length === 7 ? 'ff' : ''),
25
- );
26
- }
27
-
28
- if (color.startsWith('0x')) {
29
- return Number(color);
22
+ let hex: string;
23
+ if (color.charCodeAt(0) === 35 /* '#' */) {
24
+ hex = color.length === 7 ? color.slice(1) + 'ff' : color.slice(1);
25
+ } else if (
26
+ color.charCodeAt(0) === 48 &&
27
+ color.charCodeAt(1) === 120 /* '0x' */
28
+ ) {
29
+ hex = color.slice(2);
30
+ } else {
31
+ hex = color.length === 6 ? color + 'ff' : color;
30
32
  }
31
- return Number('0x' + (color.length === 6 ? color + 'ff' : color));
33
+ return parseInt(hex, 16);
32
34
  }
33
35
 
34
36
  return 0x00000000;
@@ -101,7 +103,7 @@ export function getWebglSupportedVersions(
101
103
  (context instanceof WebGLRenderingContext ||
102
104
  context instanceof WebGL2RenderingContext ||
103
105
  ('getParameter' in context &&
104
- typeof (context as any).getParameter === 'function'))
106
+ typeof context.getParameter === 'function'))
105
107
  );
106
108
  } catch {
107
109
  return false;