@solidtv/solid 1.1.1 → 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 (99) 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/Column.jsx +1 -1
  22. package/dist/src/primitives/Column.jsx.map +1 -1
  23. package/dist/src/primitives/FPSCounter.jsx +5 -5
  24. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  25. package/dist/src/primitives/Image.jsx +6 -1
  26. package/dist/src/primitives/Image.jsx.map +1 -1
  27. package/dist/src/primitives/KeepAlive.d.ts +4 -3
  28. package/dist/src/primitives/KeepAlive.jsx +60 -23
  29. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  30. package/dist/src/primitives/LazyImport.js +4 -2
  31. package/dist/src/primitives/LazyImport.js.map +1 -1
  32. package/dist/src/primitives/Preserve.jsx +10 -4
  33. package/dist/src/primitives/Preserve.jsx.map +1 -1
  34. package/dist/src/primitives/Row.jsx +1 -1
  35. package/dist/src/primitives/Row.jsx.map +1 -1
  36. package/dist/src/primitives/Suspense.jsx +7 -7
  37. package/dist/src/primitives/Suspense.jsx.map +1 -1
  38. package/dist/src/primitives/Virtual.jsx +1 -1
  39. package/dist/src/primitives/Virtual.jsx.map +1 -1
  40. package/dist/src/primitives/announcer/announcer.js +3 -2
  41. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  42. package/dist/src/primitives/announcer/speech.js +2 -2
  43. package/dist/src/primitives/announcer/speech.js.map +1 -1
  44. package/dist/src/primitives/borderBox.jsx +2 -1
  45. package/dist/src/primitives/borderBox.jsx.map +1 -1
  46. package/dist/src/primitives/createTag.jsx +3 -3
  47. package/dist/src/primitives/createTag.jsx.map +1 -1
  48. package/dist/src/primitives/portal.jsx +4 -3
  49. package/dist/src/primitives/portal.jsx.map +1 -1
  50. package/dist/src/primitives/utils/chainFunctions.js +35 -9
  51. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  52. package/dist/src/primitives/utils/createBlurredImage.js +57 -37
  53. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -1
  54. package/dist/src/primitives/utils/handleNavigation.js +21 -16
  55. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  56. package/dist/src/primitives/utils/withScrolling.js +1 -3
  57. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  58. package/dist/src/render.d.ts +1 -1
  59. package/dist/src/render.js +2 -1
  60. package/dist/src/render.js.map +1 -1
  61. package/dist/src/solidOpts.d.ts +1 -1
  62. package/dist/src/solidOpts.js +4 -2
  63. package/dist/src/solidOpts.js.map +1 -1
  64. package/dist/src/utils.js +10 -5
  65. package/dist/src/utils.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/docs/README.md +2 -2
  68. package/package.json +28 -29
  69. package/src/core/clickInspector.ts +77 -0
  70. package/src/core/config.ts +6 -20
  71. package/src/core/dom-renderer/domRenderer.ts +307 -89
  72. package/src/core/dom-renderer/domRendererTypes.ts +9 -6
  73. package/src/core/elementNode.ts +80 -26
  74. package/src/core/focusManager.ts +16 -8
  75. package/src/core/intrinsicTypes.ts +19 -7
  76. package/src/core/lightningInit.ts +20 -18
  77. package/src/core/utils.ts +4 -4
  78. package/src/primitives/Column.tsx +0 -1
  79. package/src/primitives/FPSCounter.tsx +14 -10
  80. package/src/primitives/Image.tsx +18 -9
  81. package/src/primitives/KeepAlive.tsx +88 -44
  82. package/src/primitives/LazyImport.ts +8 -6
  83. package/src/primitives/Preserve.tsx +13 -8
  84. package/src/primitives/Row.tsx +0 -1
  85. package/src/primitives/Suspense.tsx +10 -9
  86. package/src/primitives/Virtual.tsx +1 -9
  87. package/src/primitives/announcer/announcer.ts +3 -2
  88. package/src/primitives/announcer/speech.ts +2 -2
  89. package/src/primitives/borderBox.tsx +7 -3
  90. package/src/primitives/createTag.tsx +23 -17
  91. package/src/primitives/portal.tsx +20 -10
  92. package/src/primitives/utils/chainFunctions.ts +31 -11
  93. package/src/primitives/utils/createBlurredImage.ts +58 -40
  94. package/src/primitives/utils/handleNavigation.ts +29 -18
  95. package/src/primitives/utils/withScrolling.ts +3 -5
  96. package/src/render.ts +4 -4
  97. package/src/solidOpts.ts +9 -7
  98. package/src/types.ts +0 -1
  99. package/src/utils.ts +12 -10
@@ -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
 
@@ -117,32 +117,41 @@ export const navigableForwardFocus: lng.ForwardFocusHandler = function () {
117
117
  return selectChild(navigable, selected);
118
118
  };
119
119
 
120
+ type NavWithTransitionCache = lngp.NavigableElement & {
121
+ _navBaseTransition?: object;
122
+ _navLastMerged?: object;
123
+ };
124
+
120
125
  export function handleNavigation(
121
126
  direction: 'up' | 'right' | 'down' | 'left',
122
127
  ): lng.KeyHandler {
123
128
  return function () {
124
- const el = this as lngp.NavigableElement;
125
- const transition =
129
+ const el = this as NavWithTransitionCache;
130
+ const directional =
126
131
  direction === 'up'
127
132
  ? el.transitionUp
128
133
  : direction === 'down'
129
134
  ? el.transitionDown
130
135
  : direction === 'left'
131
136
  ? el.transitionLeft
132
- : direction === 'right'
133
- ? el.transitionRight
134
- : undefined;
137
+ : el.transitionRight;
135
138
 
136
- if (transition) {
137
- const currentTransition =
139
+ if (directional) {
140
+ const current =
138
141
  typeof el.transition === 'object' && el.transition !== null
139
142
  ? el.transition
140
143
  : {};
141
144
 
142
- el.transition = {
143
- ...currentTransition,
144
- ...(transition as object),
145
- };
145
+ // Re-snapshot the developer-supplied transition whenever el.transition
146
+ // doesn't match our last merge — that means it was set externally
147
+ // (initial render or a reactive update), not by this handler.
148
+ if (current !== el._navLastMerged) {
149
+ el._navBaseTransition = current;
150
+ }
151
+
152
+ const merged = { ...(directional as object), ...el._navBaseTransition };
153
+ el.transition = merged;
154
+ el._navLastMerged = merged;
146
155
  }
147
156
 
148
157
  return moveSelection(
@@ -211,10 +220,10 @@ export function moveSelection(
211
220
  return selectChild(el, selected);
212
221
  }
213
222
 
214
- function distanceBetweenRectCenters(a: lng.Rect, b: lng.Rect): number {
215
- const dx = Math.abs(a.x + a.width / 2 - (b.x + b.width / 2)) / 2;
216
- const dy = Math.abs(a.y + a.height / 2 - (b.y + b.height / 2)) / 2;
217
- 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;
218
227
  }
219
228
 
220
229
  function findClosestFocusableChildIdx(
@@ -229,12 +238,14 @@ function findClosestFocusableChildIdx(
229
238
  let closestIdx = -1;
230
239
  let closestDist = Infinity;
231
240
 
232
- 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]!;
233
244
  if (!child.skipFocus) {
234
245
  lng.getElementScreenRect(child, el, childRect);
235
246
  childRect.x += elRect.x;
236
247
  childRect.y += elRect.y;
237
- const distance = distanceBetweenRectCenters(prevRect, childRect);
248
+ const distance = squaredDistanceBetweenRectCenters(prevRect, childRect);
238
249
  if (distance < closestDist) {
239
250
  closestDist = distance;
240
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;