@solidtv/solid 1.0.3 → 1.1.1

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 (93) hide show
  1. package/dist/jsx-runtime.d.ts +0 -1
  2. package/dist/src/core/config.js.map +1 -1
  3. package/dist/src/core/dom-renderer/domRenderer.js +38 -36
  4. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  5. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +1 -0
  6. package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
  7. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
  8. package/dist/src/core/elementNode.d.ts +35 -17
  9. package/dist/src/core/elementNode.js +184 -56
  10. package/dist/src/core/elementNode.js.map +1 -1
  11. package/dist/src/core/flex.js +1 -1
  12. package/dist/src/core/flex.js.map +1 -1
  13. package/dist/src/core/flexLayout.js +5 -9
  14. package/dist/src/core/flexLayout.js.map +1 -1
  15. package/dist/src/core/focusManager.js.map +1 -1
  16. package/dist/src/core/intrinsicTypes.d.ts +2 -7
  17. package/dist/src/core/nodeTypes.d.ts +7 -0
  18. package/dist/src/core/nodeTypes.js +8 -0
  19. package/dist/src/core/nodeTypes.js.map +1 -1
  20. package/dist/src/core/shaders.js +1 -1
  21. package/dist/src/core/shaders.js.map +1 -1
  22. package/dist/src/core/states.js.map +1 -1
  23. package/dist/src/core/utils.d.ts +2 -1
  24. package/dist/src/core/utils.js +2 -1
  25. package/dist/src/core/utils.js.map +1 -1
  26. package/dist/src/devtools/hexColorTransform.d.ts +6 -0
  27. package/dist/src/devtools/hexColorTransform.js +42 -0
  28. package/dist/src/devtools/hexColorTransform.js.map +1 -0
  29. package/dist/src/devtools/index.d.ts +2 -0
  30. package/dist/src/devtools/index.js +3 -2
  31. package/dist/src/devtools/index.js.map +1 -1
  32. package/dist/src/primitives/Grid.jsx.map +1 -1
  33. package/dist/src/primitives/Image.jsx.map +1 -1
  34. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  35. package/dist/src/primitives/Lazy.d.ts +16 -0
  36. package/dist/src/primitives/Lazy.jsx +82 -38
  37. package/dist/src/primitives/Lazy.jsx.map +1 -1
  38. package/dist/src/primitives/LazyImport.js +14 -11
  39. package/dist/src/primitives/LazyImport.js.map +1 -1
  40. package/dist/src/primitives/Marquee.jsx +3 -3
  41. package/dist/src/primitives/Marquee.jsx.map +1 -1
  42. package/dist/src/primitives/Preserve.jsx +1 -1
  43. package/dist/src/primitives/Preserve.jsx.map +1 -1
  44. package/dist/src/primitives/Suspense.jsx +1 -1
  45. package/dist/src/primitives/Suspense.jsx.map +1 -1
  46. package/dist/src/primitives/Virtual.jsx +6 -5
  47. package/dist/src/primitives/Virtual.jsx.map +1 -1
  48. package/dist/src/primitives/borderBox.jsx.map +1 -1
  49. package/dist/src/primitives/index.d.ts +0 -2
  50. package/dist/src/primitives/index.js +0 -2
  51. package/dist/src/primitives/index.js.map +1 -1
  52. package/dist/src/primitives/routerIndex.d.ts +2 -0
  53. package/dist/src/primitives/routerIndex.js +3 -0
  54. package/dist/src/primitives/routerIndex.js.map +1 -0
  55. package/dist/src/primitives/useMouse.js +72 -82
  56. package/dist/src/primitives/useMouse.js.map +1 -1
  57. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
  58. package/dist/src/solidOpts.d.ts +1 -1
  59. package/dist/src/solidOpts.js +4 -14
  60. package/dist/src/solidOpts.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/jsx-runtime.d.ts +0 -1
  63. package/package.json +11 -3
  64. package/src/core/config.ts +2 -0
  65. package/src/core/dom-renderer/domRenderer.ts +48 -46
  66. package/src/core/dom-renderer/domRendererTypes.ts +1 -0
  67. package/src/core/dom-renderer/domRendererUtils.ts +2 -2
  68. package/src/core/elementNode.ts +213 -74
  69. package/src/core/flex.ts +3 -3
  70. package/src/core/flexLayout.ts +7 -11
  71. package/src/core/focusManager.ts +1 -1
  72. package/src/core/intrinsicTypes.ts +3 -7
  73. package/src/core/nodeTypes.ts +12 -0
  74. package/src/core/shaders.ts +1 -1
  75. package/src/core/states.ts +2 -2
  76. package/src/core/utils.ts +4 -3
  77. package/src/devtools/hexColorTransform.ts +56 -0
  78. package/src/devtools/index.ts +5 -2
  79. package/src/primitives/Grid.tsx +1 -1
  80. package/src/primitives/Image.tsx +1 -1
  81. package/src/primitives/KeepAlive.tsx +2 -2
  82. package/src/primitives/Lazy.tsx +106 -37
  83. package/src/primitives/LazyImport.ts +5 -4
  84. package/src/primitives/Marquee.tsx +3 -3
  85. package/src/primitives/Preserve.tsx +1 -1
  86. package/src/primitives/Suspense.tsx +1 -1
  87. package/src/primitives/Virtual.tsx +8 -7
  88. package/src/primitives/borderBox.tsx +1 -1
  89. package/src/primitives/index.ts +0 -2
  90. package/src/primitives/routerIndex.ts +2 -0
  91. package/src/primitives/useMouse.ts +97 -128
  92. package/src/primitives/utils/createSpriteMap.ts +1 -1
  93. package/src/solidOpts.ts +6 -17
@@ -1,6 +1,9 @@
1
1
  import * as debug from '@solid-devtools/debugger/types';
2
2
  import * as lng from '../core/index.js';
3
3
 
4
+ export { default as hexColorTransform } from './hexColorTransform.js';
5
+ export type { HexColorTransformOptions } from './hexColorTransform.js';
6
+
4
7
  const EMPTY_CHILDREN: (lng.ElementNode | lng.ElementText)[] = [];
5
8
 
6
9
  /**
@@ -49,7 +52,7 @@ export const elementInterface: debug.ElementInterface<
49
52
  }
50
53
 
51
54
  if (lng.Config.rendererOptions != null) {
52
- let dpr = lng.Config.rendererOptions.deviceLogicalPixelRatio;
55
+ const dpr = lng.Config.rendererOptions.deviceLogicalPixelRatio;
53
56
  if (dpr != null) {
54
57
  x *= dpr;
55
58
  y *= dpr;
@@ -61,7 +64,7 @@ export const elementInterface: debug.ElementInterface<
61
64
  return { x, y, width, height };
62
65
  },
63
66
  getElementAt(e) {
64
- let target = e.target as any;
67
+ const target = e.target as any;
65
68
  return target != null && target.element instanceof lng.ElementNode
66
69
  ? target.element
67
70
  : null;
@@ -33,7 +33,7 @@ export function Grid<T>(props: GridProps<T>): JSX.Element {
33
33
  const currentIndex = untrack(focusedIndex);
34
34
  if (props.selected === currentIndex) return;
35
35
  if (props.selected !== undefined && props.items?.length > props.selected) {
36
- moveFocus(props.selected! - currentIndex);
36
+ moveFocus(props.selected - currentIndex);
37
37
  }
38
38
  });
39
39
 
@@ -32,7 +32,7 @@ export const Image: Component<ImageProps> = (props) => {
32
32
  return;
33
33
  }
34
34
 
35
- const srcTexture = renderer.createTexture('ImageTexture', props) as ImageTexture;
35
+ const srcTexture = renderer.createTexture('ImageTexture', props);
36
36
 
37
37
  if (props.fallback) {
38
38
  srcTexture.once('failed', () => {
@@ -140,7 +140,7 @@ const createKeepAliveComponent = (
140
140
  });
141
141
  } else if (existing && !existing.children) {
142
142
  existing.children = s.runWithOwner(existing.owner, () =>
143
- wrapChildren(props, existing!.setIsAlive),
143
+ wrapChildren(props, existing.setIsAlive),
144
144
  );
145
145
  }
146
146
  return existing.children;
@@ -202,7 +202,7 @@ export const KeepAliveRoute = <S extends string>(
202
202
  isChild = true;
203
203
  break;
204
204
  }
205
- current = current.parent as ElementNode | undefined;
205
+ current = current.parent;
206
206
  }
207
207
 
208
208
  if (isChild && savedFocusedElement) {
@@ -4,15 +4,51 @@ import * as s from 'solid-js';
4
4
 
5
5
  type LazyProps<T extends readonly any[]> = lng.NewOmit<lng.NodeProps, 'children'> & {
6
6
  each: T | undefined | null | false;
7
+
8
+ /** Initial visible item count before user navigation. */
7
9
  upCount: number;
10
+
11
+ /**
12
+ * Items to keep rendered ahead of the current selection. When selection
13
+ * moves within this distance of the rendered edge, the next item is
14
+ * scheduled to mount. Default depends on the scroll mode.
15
+ */
8
16
  buffer?: number;
17
+
18
+ /**
19
+ * Milliseconds to wait after a navigation key press before mounting the
20
+ * next item. Should match the scroll animation duration — mounting items
21
+ * mid-animation causes jank. If the user presses again before this timer
22
+ * fires (faster than the animation), an item is added synchronously to
23
+ * keep the rendered window ahead of selection.
24
+ */
9
25
  delay?: number;
26
+
27
+ /** Render `upCount` items synchronously on mount instead of ramping up. */
10
28
  sync?: boolean;
29
+
30
+ /** Continue mounting items in the background past `upCount`. */
11
31
  eagerLoad?: boolean;
32
+
33
+ /** Skip refocusing the container when `each.length` changes. */
12
34
  noRefocus?: boolean;
35
+
13
36
  children: (item: s.Accessor<T[number]>, index: number) => s.JSX.Element;
14
37
  };
15
38
 
39
+ // Lifecycle when props.each changes:
40
+ // 1. items memo invalidates → <Index> reconciles → new ElementNodes mounted (sync)
41
+ // 2. refocus effect runs (microtask) → calls viewRef.setFocus()
42
+ // 3. setFocus queues runPostMutation
43
+ // 4. post-mutation: delete-flush → layout → setActiveElement
44
+ // Children are always mounted before focus is applied; do not wrap setFocus
45
+ // in queueMicrotask — it only adds a redundant defer.
46
+ //
47
+ // Navigation key handler (updateOffset):
48
+ // - On each onRight/onDown, if selection is within `buffer` of the rendered
49
+ // edge, mount one more item. With `delay` set, the mount is deferred until
50
+ // the scroll animation completes so it doesn't drop a frame mid-animation.
51
+ // If the user out-paces `delay`, the mount fires synchronously instead.
16
52
  function createLazy<T>(
17
53
  component: s.ValidComponent,
18
54
  props: LazyProps<readonly T[]>,
@@ -20,9 +56,17 @@ function createLazy<T>(
20
56
  ) {
21
57
  // Need at least one item so it can be focused
22
58
  const [offset, setOffset] = s.createSignal<number>(props.sync ? props.upCount : 0);
23
- let timeoutId: ReturnType<typeof setTimeout> | null = null;
59
+ let preloadTimer: ReturnType<typeof setTimeout> | null = null;
60
+ let navDelayTimer: ReturnType<typeof setTimeout> | null = null;
61
+ let disposed = false;
24
62
  let viewRef!: lngp.NavigableElement;
25
- let itemLength: number = 0;
63
+ let itemLength = 0;
64
+
65
+ s.onCleanup(() => {
66
+ disposed = true;
67
+ if (preloadTimer) clearTimeout(preloadTimer);
68
+ if (navDelayTimer) clearTimeout(navDelayTimer);
69
+ });
26
70
 
27
71
  const buffer = s.createMemo(() => {
28
72
  if (typeof props.buffer === 'number') {
@@ -44,39 +88,54 @@ function createLazy<T>(
44
88
 
45
89
  if (!props.sync || props.eagerLoad) {
46
90
  s.createEffect(() => {
47
- if (props.each) {
48
- const loadItems = () => {
49
- let count = s.untrack(offset);
50
- if (count < props.upCount) {
51
- setOffset(count + 1);
52
- timeoutId = setTimeout(loadItems, 16); // ~60fps
53
- count++;
54
- } else if (props.eagerLoad) {
55
- const maxOffset = props.each ? props.each.length : 0;
56
- if (count >= maxOffset) return;
57
- setOffset((prev) => Math.min(prev + 1, maxOffset));
58
- lng.scheduleTask(loadItems);
59
- }
60
- };
61
- loadItems();
91
+ if (!props.each) return;
92
+ // Cancel any in-flight preload chain from a prior effect run before
93
+ // starting a new one — otherwise two chains share state and race.
94
+ if (preloadTimer) {
95
+ clearTimeout(preloadTimer);
96
+ preloadTimer = null;
62
97
  }
98
+ const loadItems = () => {
99
+ if (disposed) return;
100
+ const count = s.untrack(offset);
101
+ if (count < props.upCount) {
102
+ setOffset(count + 1);
103
+ preloadTimer = setTimeout(loadItems, 16); // ~60fps
104
+ } else if (props.eagerLoad) {
105
+ const maxOffset = props.each ? props.each.length : 0;
106
+ if (count >= maxOffset) return;
107
+ setOffset((prev) => Math.min(prev + 1, maxOffset));
108
+ lng.scheduleTask(loadItems);
109
+ }
110
+ };
111
+ loadItems();
63
112
  });
64
113
  }
65
114
 
66
- const items: s.Accessor<T[]> = s.createMemo(() => {
67
- if (Array.isArray(props.each)) {
68
- if (itemLength != props.each.length) {
69
- itemLength = props.each.length;
70
- if (viewRef && !viewRef.noRefocus && lng.hasFocus(viewRef)) {
71
- queueMicrotask(() => viewRef.setFocus());
115
+ // Refocus when each.length changes. Side effect kept out of the items memo
116
+ // (memos must be pure — Solid may skip evaluation when there are no readers).
117
+ s.createEffect(() => {
118
+ if (!Array.isArray(props.each)) {
119
+ itemLength = 0;
120
+ return;
121
+ }
122
+ const len = props.each.length;
123
+ if (itemLength !== len) {
124
+ itemLength = len;
125
+ if (viewRef && !viewRef.noRefocus && lng.hasFocus(viewRef)) {
126
+ // Clamp selected so a shrunk list doesn't refocus a disposed index.
127
+ if (typeof viewRef.selected === 'number' && viewRef.selected >= len) {
128
+ viewRef.selected = Math.max(0, len - 1);
72
129
  }
130
+ viewRef.setFocus();
73
131
  }
74
- return props.each.slice(0, offset());
75
132
  }
76
- itemLength = 0;
77
- return [];
78
133
  });
79
134
 
135
+ const items: s.Accessor<T[]> = s.createMemo(() =>
136
+ Array.isArray(props.each) ? props.each.slice(0, offset()) : [],
137
+ );
138
+
80
139
  function lazyScrollToIndex(this: lngp.NavigableElement, index: number) {
81
140
  setOffset(Math.max(index, 0) + buffer())
82
141
  queueMicrotask(() => viewRef.scrollToIndex(index));
@@ -85,24 +144,34 @@ function createLazy<T>(
85
144
  const updateOffset = (_event: KeyboardEvent, container: lng.ElementNode) => {
86
145
  const maxOffset = props.each ? props.each.length : 0;
87
146
  const selected = container.selected || 0;
88
- const numChildren = container.children.length;
89
- if (offset() >= maxOffset || selected < numChildren - buffer()) return;
147
+ const rendered = offset(); // == container.children.length
148
+
149
+ // Already mounted everything, or still far enough from the rendered edge
150
+ // that the buffer covers the next selection — no work to do.
151
+ if (rendered >= maxOffset || selected < rendered - buffer()) return;
152
+
153
+ const bump = () => setOffset((prev) => Math.min(prev + 1, maxOffset));
90
154
 
155
+ // No animation to hide behind — mount immediately.
91
156
  if (!props.delay) {
92
- setOffset((prev) => Math.min(prev + 1, maxOffset));
157
+ bump();
93
158
  return;
94
159
  }
95
160
 
96
- if (timeoutId) {
97
- clearTimeout(timeoutId);
98
- //Moving faster than the delay so need to go sync
99
- setOffset((prev) => Math.min(prev + 1, maxOffset));
161
+ // A delayed mount from the previous press hasn't fired yet, which means
162
+ // the user is navigating faster than the scroll animation. Drop the wait
163
+ // (we can't smooth a frame the user is already past) and mount now.
164
+ if (navDelayTimer) {
165
+ clearTimeout(navDelayTimer);
166
+ bump();
100
167
  }
101
168
 
102
- timeoutId = setTimeout(() => {
103
- setOffset((prev) => Math.min(prev + 1, maxOffset));
104
- timeoutId = null;
105
- }, props.delay ?? 0);
169
+ // Schedule the trailing mount to land after the scroll animation completes,
170
+ // so a single item mount doesn't jank the in-flight animation.
171
+ navDelayTimer = setTimeout(() => {
172
+ bump();
173
+ navDelayTimer = null;
174
+ }, props.delay);
106
175
  };
107
176
 
108
177
  const handler = keyHandler(updateOffset);
@@ -34,8 +34,9 @@ export function lazy<T extends Component<any>>(
34
34
  comp = s;
35
35
  }
36
36
  let Comp: T | undefined;
37
- return createMemo(() =>
38
- (Comp = comp())
37
+ return createMemo(() => {
38
+ Comp = comp();
39
+ return Comp
39
40
  ? untrack(() => {
40
41
  if (!ctx || sharedConfig.done) return Comp!(props);
41
42
  const c = sharedConfig.context;
@@ -44,8 +45,8 @@ export function lazy<T extends Component<any>>(
44
45
  sharedConfig.context = c;
45
46
  return r;
46
47
  })
47
- : null,
48
- ) as unknown as JSX.Element;
48
+ : null;
49
+ }) as unknown as JSX.Element;
49
50
  }) as T;
50
51
  wrap.preload = () =>
51
52
  p || ((p = fn()).then((mod) => (comp = () => mod.default)), p);
@@ -69,7 +69,7 @@ export function MarqueeText(props: MarqueeTextProps) {
69
69
  s.createEffect(() => {
70
70
  if (shouldScroll()) {
71
71
 
72
- let options: lng.AnimationSettings = {
72
+ const options: lng.AnimationSettings = {
73
73
  duration: (textWidth() + scrollGap()) / speed() * 1000,
74
74
  delay: delay(),
75
75
  loop: true,
@@ -79,8 +79,8 @@ export function MarqueeText(props: MarqueeTextProps) {
79
79
  text1.lng.x = 0
80
80
  text2.lng.x = textWidth() + scrollGap()
81
81
 
82
- let a1 = text1.lng.animate!({x: -textWidth() -scrollGap()}, options).start()
83
- let a2 = text2.lng.animate!({x: 0}, options).start()
82
+ const a1 = text1.lng.animate!({x: -textWidth() -scrollGap()}, options).start()
83
+ const a2 = text2.lng.animate!({x: 0}, options).start()
84
84
 
85
85
  s.onCleanup(() => {
86
86
  a1.stop()
@@ -3,7 +3,7 @@ import * as lng from '@solidtv/solid'
3
3
 
4
4
  function Preserve(props: lng.NodeProps): s.JSX.Element {
5
5
 
6
- let view = <view {...props} /> as any as lng.ElementNode
6
+ const view = <view {...props} /> as any as lng.ElementNode
7
7
 
8
8
  view.preserve = true;
9
9
 
@@ -24,7 +24,7 @@ export function Suspense(props: {
24
24
 
25
25
  let children: s.JSX.Element;
26
26
 
27
- let suspense = s.Suspense({
27
+ const suspense = s.Suspense({
28
28
  get children() {
29
29
  return [children = s.children(() => props.children) as any];
30
30
  },
@@ -247,7 +247,7 @@ function createVirtual<T>(
247
247
  }
248
248
  break;
249
249
 
250
- case 'edge':
250
+ case 'edge': {
251
251
  const startScrolling = Math.max(
252
252
  1,
253
253
  props.displaySize + (atStart ? -1 : 0),
@@ -316,6 +316,7 @@ function createVirtual<T>(
316
316
  }
317
317
  }
318
318
  break;
319
+ }
319
320
 
320
321
  case 'none':
321
322
  default:
@@ -396,18 +397,18 @@ function createVirtual<T>(
396
397
  _active,
397
398
  _lastIdx,
398
399
  ) {
399
- let idx = _idx;
400
- let lastIdx = _lastIdx || 0;
401
- let active = _active;
400
+ const idx = _idx;
401
+ const lastIdx = _lastIdx || 0;
402
+ const active = _active;
402
403
  const noChange = idx === lastIdx;
403
404
  const total = itemCount();
404
405
  originalPosition = originalPosition ?? elm[axis];
405
406
 
406
407
  if (props.onSelectedChanged) {
407
408
  props.onSelectedChanged.call(
408
- this as lngp.NavigableElement,
409
+ this,
409
410
  idx,
410
- this as lngp.NavigableElement,
411
+ this,
411
412
  active,
412
413
  lastIdx,
413
414
  );
@@ -480,7 +481,7 @@ function createVirtual<T>(
480
481
 
481
482
  queueMicrotask(() => {
482
483
  viewRef.updateLayout();
483
- let activeIndex = viewRef.children.findIndex((x) => x.item === item);
484
+ const activeIndex = viewRef.children.findIndex((x) => x.item === item);
484
485
  if (activeIndex === -1) return;
485
486
  viewRef.selected = activeIndex;
486
487
  if (lng.hasFocus(viewRef)) {
@@ -62,7 +62,7 @@ export function borderBox(
62
62
  });
63
63
  } else if (border) {
64
64
  border.destroy();
65
- el.removeChild(border!);
65
+ el.removeChild(border);
66
66
  border = null;
67
67
  }
68
68
  }, el.onFocusChanged);
@@ -8,7 +8,6 @@ export * from './Lazy.jsx';
8
8
  export * from './LazyImport.js';
9
9
  export * from './Image.jsx';
10
10
  export * from './Visible.jsx';
11
- export * from './router.js';
12
11
  export * from './Column.jsx';
13
12
  export * from './Row.jsx';
14
13
  export * from './Grid.jsx';
@@ -19,7 +18,6 @@ export * from './Suspense.jsx';
19
18
  export * from './Marquee.jsx';
20
19
  export * from './createFocusStack.jsx';
21
20
  export * from './useHold.js';
22
- export * from './KeepAlive.jsx';
23
21
  export * from './VirtualGrid.jsx';
24
22
  export * from './Virtual.jsx';
25
23
  export * from './utils/withScrolling.js';
@@ -0,0 +1,2 @@
1
+ export * from './router.js';
2
+ export * from './KeepAlive.jsx';