@solidtv/solid 1.1.3 → 1.2.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 (69) hide show
  1. package/README.md +2 -2
  2. package/dist/src/core/activeElement.d.ts +17 -0
  3. package/dist/src/core/activeElement.js +18 -0
  4. package/dist/src/core/activeElement.js.map +1 -0
  5. package/dist/src/core/config.d.ts +20 -0
  6. package/dist/src/core/config.js +15 -1
  7. package/dist/src/core/config.js.map +1 -1
  8. package/dist/src/core/dom-renderer/domRenderer.d.ts +2 -2
  9. package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
  10. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
  11. package/dist/src/core/elementNode.d.ts +10 -4
  12. package/dist/src/core/elementNode.js +59 -44
  13. package/dist/src/core/elementNode.js.map +1 -1
  14. package/dist/src/core/focusManager.d.ts +2 -9
  15. package/dist/src/core/focusManager.js +111 -97
  16. package/dist/src/core/focusManager.js.map +1 -1
  17. package/dist/src/core/lightningInit.js +3 -0
  18. package/dist/src/core/lightningInit.js.map +1 -1
  19. package/dist/src/core/shaders.js +10 -10
  20. package/dist/src/core/shaders.js.map +1 -1
  21. package/dist/src/core/utils.d.ts +0 -1
  22. package/dist/src/core/utils.js +0 -1
  23. package/dist/src/core/utils.js.map +1 -1
  24. package/dist/src/index.d.ts +2 -1
  25. package/dist/src/index.js +2 -1
  26. package/dist/src/index.js.map +1 -1
  27. package/dist/src/primitives/FadeInOut.jsx +1 -2
  28. package/dist/src/primitives/FadeInOut.jsx.map +1 -1
  29. package/dist/src/primitives/Rail.d.ts +27 -0
  30. package/dist/src/primitives/Rail.jsx +322 -0
  31. package/dist/src/primitives/Rail.jsx.map +1 -0
  32. package/dist/src/primitives/index.d.ts +1 -0
  33. package/dist/src/primitives/useFocusManager.d.ts +2 -5
  34. package/dist/src/primitives/useFocusManager.js +2 -20
  35. package/dist/src/primitives/useFocusManager.js.map +1 -1
  36. package/dist/src/primitives/useHold.d.ts +1 -1
  37. package/dist/src/primitives/useHold.js +1 -1
  38. package/dist/src/primitives/useMouse.js +4 -4
  39. package/dist/src/primitives/useMouse.js.map +1 -1
  40. package/dist/src/render.d.ts +6 -0
  41. package/dist/src/render.js +7 -3
  42. package/dist/src/render.js.map +1 -1
  43. package/dist/src/solidOpts.d.ts +1 -1
  44. package/dist/src/solidOpts.js +4 -23
  45. package/dist/src/solidOpts.js.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/docs/AI_CODING_GUIDELINES.md +7 -7
  48. package/package.json +2 -2
  49. package/src/core/activeElement.ts +21 -0
  50. package/src/core/config.ts +24 -1
  51. package/src/core/dom-renderer/domRendererUtils.ts +2 -2
  52. package/src/core/elementNode.ts +65 -40
  53. package/src/core/focusManager.ts +158 -136
  54. package/src/core/lightningInit.ts +3 -0
  55. package/src/core/shaders.ts +10 -10
  56. package/src/core/utils.ts +0 -3
  57. package/src/index.ts +2 -1
  58. package/src/primitives/FadeInOut.tsx +2 -2
  59. package/src/primitives/Rail.tsx +401 -0
  60. package/src/primitives/index.ts +1 -0
  61. package/src/primitives/useFocusManager.ts +8 -44
  62. package/src/primitives/useHold.ts +1 -1
  63. package/src/primitives/useMouse.ts +4 -4
  64. package/src/render.ts +7 -3
  65. package/src/solidOpts.ts +4 -25
  66. package/dist/src/activeElement.d.ts +0 -2
  67. package/dist/src/activeElement.js +0 -3
  68. package/dist/src/activeElement.js.map +0 -1
  69. package/src/activeElement.ts +0 -5
@@ -6,7 +6,7 @@
6
6
 
7
7
  - **Environment:** TV app development over WebGL (not the DOM). No pointer input; interaction is directional (Up/Down/Left/Right).
8
8
  - **Reactivity:** Uses SolidTV primitives (`createSignal`, `createEffect`, `createMemo`).
9
- - **Primitives:** UI is built using custom components like `<View>`, `<Text>`, `<Row>`, `<Column>`.
9
+ - **Primitives:** UI is built using the intrinsic elements `<view>` and `<text>` (no import needed — they're registered with the renderer) plus layout components like `<Row>` and `<Column>` from `@solidtv/solid/primitives`.
10
10
  - **Patterns:** Always use functional components and modern TypeScript/JSX. Avoid classes.
11
11
  - **Assumption:** Always frame answers within the context of SolidTV + SolidTV TV environment.
12
12
 
@@ -76,7 +76,7 @@
76
76
 
77
77
  ```tsx
78
78
  // Missing dimensions, invalid colors, using styles, directional padding
79
- <View
79
+ <view
80
80
  style={{
81
81
  backgroundColor: 'red',
82
82
  paddingLeft: 20,
@@ -84,8 +84,8 @@
84
84
  display: 'flex',
85
85
  }}
86
86
  >
87
- <Text textColor="white">Hello</Text>
88
- </View>
87
+ <text textColor="white">Hello</text>
88
+ </view>
89
89
  ```
90
90
 
91
91
  **✅ Correct:**
@@ -94,7 +94,7 @@
94
94
  const [focused, setFocused] = createSignal(false);
95
95
 
96
96
  // Uses direct props, hex colors, clear dimensions, and focus tracking
97
- <View
97
+ <view
98
98
  width={400}
99
99
  height={200}
100
100
  color={focused() ? '#ffff00ff' : '#ff0000ff'}
@@ -103,6 +103,6 @@ const [focused, setFocused] = createSignal(false);
103
103
  display="flex"
104
104
  onFocusChanged={setFocused}
105
105
  >
106
- <Text color="#ffffffff">Hello</Text>
107
- </View>;
106
+ <text color="#ffffffff">Hello</text>
107
+ </view>;
108
108
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -109,7 +109,7 @@
109
109
  },
110
110
  "peerDependencies": {
111
111
  "@solidjs/router": "^0.16.1",
112
- "@solidtv/renderer": "^1.1.2",
112
+ "@solidtv/renderer": "^1.3.0",
113
113
  "solid-js": "*"
114
114
  },
115
115
  "peerDependenciesMeta": {},
@@ -0,0 +1,21 @@
1
+ import { createSignal } from 'solid-js';
2
+ import type { ElementNode } from './elementNode.js';
3
+
4
+ /**
5
+ * Generic active-element signal — intentionally decoupled from the focus
6
+ * manager so consumers can drive focus from their own focus-management logic.
7
+ *
8
+ * `setActiveElementSignal` is the *raw* signal setter: it only updates the
9
+ * reactive value. It does NOT move focus state, fire `onFocus`/`onBlur`, or
10
+ * touch the focus path — that is the focus manager's job.
11
+ *
12
+ * The built-in focus manager applies focus via `setActiveElement`
13
+ * (see {@link ./focusManager.ts}) and publishes the result through
14
+ * `Config.setActiveElement`, which defaults to this setter. A library shipping
15
+ * its own focus manager can read {@link activeElement}, reassign
16
+ * `Config.setActiveElement` (e.g. to inject a Solid owner context), or call
17
+ * `setActiveElementSignal` directly — without depending on `focusManager.ts`.
18
+ */
19
+ export const [activeElement, setActiveElementSignal] = createSignal<
20
+ ElementNode | undefined
21
+ >(undefined);
@@ -9,6 +9,7 @@ import {
9
9
  type ElementNode,
10
10
  convertToShader as defaultConvertToShader,
11
11
  } from './elementNode.js';
12
+ import { setActiveElementSignal } from './activeElement.js';
12
13
  import {
13
14
  DomRendererMainSettings,
14
15
  IRendererShader,
@@ -33,6 +34,21 @@ export const SHADERS_ENABLED =
33
34
  typeof SOLIDTV_DISABLE_SHADERS === 'undefined' ||
34
35
  SOLIDTV_DISABLE_SHADERS !== true;
35
36
 
37
+ /**
38
+ * True when the DOM renderer is both built in (`DOM_RENDERING`) and turned on
39
+ * at runtime (`Config.domRendererEnabled`). `Config.domRendererEnabled` is
40
+ * mutable up until the renderer starts, so this is a function rather than a
41
+ * constant.
42
+ *
43
+ * NOTE: do not use this to gate code paths whose dead-code elimination matters
44
+ * (e.g. branches that reference DOM-renderer-only modules). Bundlers don't
45
+ * inline this call, so the gated branch — and its imports — stay live. In
46
+ * those spots inline `DOM_RENDERING && Config.domRendererEnabled` so the
47
+ * `DOM_RENDERING` build constant can collapse the branch.
48
+ */
49
+ export const isDomRendererActive = () =>
50
+ DOM_RENDERING && Config.domRendererEnabled;
51
+
36
52
  /**
37
53
  RUNTIME LIGHTNING CONFIGURATION \
38
54
  This configuration can be set at runtime, but it is recommended to set it
@@ -48,6 +64,13 @@ export interface Config {
48
64
  animationsEnabled: boolean;
49
65
  fontSettings: Partial<TextProps>;
50
66
  rendererOptions?: Partial<RendererMainSettings> | DomRendererMainSettings;
67
+ /**
68
+ * Hook the focus manager calls to publish the active element. Defaults to
69
+ * writing the {@link activeElement} signal directly; a custom focus manager
70
+ * (or the built-in `useFocusManager`) may reassign this — e.g. to run the
71
+ * write inside a captured Solid owner context. This is the seam that keeps
72
+ * the `activeElement` signal decoupled from focus-manager logic.
73
+ */
51
74
  setActiveElement: (elm: ElementNode) => void;
52
75
  focusStateKey: DollarString;
53
76
  lockStyles?: boolean;
@@ -70,6 +93,7 @@ export const Config: Config = {
70
93
  easing: 'ease-in-out',
71
94
  },
72
95
  convertToShader: defaultConvertToShader,
96
+ setActiveElement: (elm) => setActiveElementSignal(elm),
73
97
  fontSettings: {
74
98
  fontFamily: 'Ubuntu',
75
99
  fontSize: 100,
@@ -83,7 +107,6 @@ export const Config: Config = {
83
107
  bold: 700,
84
108
  black: 900,
85
109
  },
86
- setActiveElement: () => {},
87
110
  focusStateKey: '$focus',
88
111
  lockStyles: true,
89
112
  rendererOptions: {},
@@ -2,7 +2,7 @@
2
2
  import * as lng from '@solidtv/renderer';
3
3
  import { Config } from '../config.js';
4
4
  import { DOMNode } from './domRenderer.js';
5
- import { isFunc } from '../utils.js';
5
+ import { isFunction } from '../utils.js';
6
6
 
7
7
  // #region Color & Gradient Utils
8
8
 
@@ -160,7 +160,7 @@ export function applyEasing(
160
160
  easing: string | lng.TimingFunction,
161
161
  progress: number,
162
162
  ): number {
163
- if (isFunc(easing)) {
163
+ if (isFunction(easing)) {
164
164
  return easing(progress);
165
165
  }
166
166
 
@@ -25,7 +25,6 @@ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
25
25
  import {
26
26
  log,
27
27
  isArray,
28
- isFunc,
29
28
  keyExists,
30
29
  isINode,
31
30
  isElementNode,
@@ -34,7 +33,12 @@ import {
34
33
  isFunction,
35
34
  spliceItem,
36
35
  } from './utils.js';
37
- import { Config, DOM_RENDERING, isDev, SHADERS_ENABLED } from './config.js';
36
+ import {
37
+ Config,
38
+ isDev,
39
+ SHADERS_ENABLED,
40
+ isDomRendererActive,
41
+ } from './config.js';
38
42
  import type {
39
43
  RendererMain,
40
44
  INode,
@@ -78,9 +82,20 @@ let postMutationQueued = false;
78
82
  let nextActiveElement: ElementNode | null = null;
79
83
  let deferredFocusElement: ElementNode | null = null;
80
84
  const layoutQueue = new Set<ElementNode>();
81
- export const elementDeleteQueue: ElementNode[] = [];
85
+ const elementDeleteQueue: ElementNode[] = [];
82
86
 
83
- export function schedulePostMutation() {
87
+ export function enqueueDelete(node: ElementNode, n: number): void {
88
+ if (node._queueDelete === undefined) {
89
+ node._queueDelete = n;
90
+ if (elementDeleteQueue.push(node) === 1) {
91
+ schedulePostMutation();
92
+ }
93
+ } else {
94
+ node._queueDelete += n;
95
+ }
96
+ }
97
+
98
+ function schedulePostMutation() {
84
99
  if (postMutationQueued) return;
85
100
  postMutationQueued = true;
86
101
  if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) {
@@ -95,7 +110,7 @@ function runPostMutation() {
95
110
  // Phase 1: delete-flush
96
111
  if (elementDeleteQueue.length > 0) {
97
112
  for (const el of elementDeleteQueue) {
98
- if (Number(el._queueDelete) < 0) {
113
+ if ((el._queueDelete ?? 0) < 0) {
99
114
  el.destroy();
100
115
  }
101
116
  el._queueDelete = undefined;
@@ -153,6 +168,15 @@ function buildFontTemplate() {
153
168
  _fontTemplate = tpl;
154
169
  }
155
170
 
171
+ const EFFECT_SHADER_KEYS = [
172
+ 'border',
173
+ 'borderTop',
174
+ 'borderRight',
175
+ 'borderBottom',
176
+ 'borderLeft',
177
+ 'shadow',
178
+ ] as const satisfies ReadonlyArray<keyof StyleEffects>;
179
+
156
180
  const parseAndAssignShaderProps = (
157
181
  prefix: string,
158
182
  obj: Record<string, unknown>,
@@ -200,7 +224,7 @@ function getPropertyAlias(name: string) {
200
224
  return name;
201
225
  }
202
226
 
203
- export const LightningRendererNumberProps = [
227
+ const LightningRendererNumberProps = [
204
228
  'alpha',
205
229
  'color',
206
230
  'colorTop',
@@ -299,7 +323,6 @@ export interface ElementNode extends RendererNode, FocusNode {
299
323
  // Properties
300
324
  /** @internal for managing series of insertions and deletions */
301
325
  _queueDelete?: number;
302
- preserve?: boolean;
303
326
  _animationQueue?:
304
327
  | Array<{
305
328
  props: Partial<INodeAnimateProps<CoreShaderNode>>;
@@ -806,6 +829,25 @@ export class ElementNode {
806
829
  return this.lng.shader;
807
830
  }
808
831
 
832
+ /**
833
+ * Commit a built shader-props target back to `this.lng.shader`. When the
834
+ * node is already rendered we either convert the props into a real shader
835
+ * (first time) or self-assign so the DOM renderer's setter reapplies style;
836
+ * pre-render we just attach the bag for the upcoming `render()`.
837
+ */
838
+ _writeShaderTarget(target: unknown) {
839
+ if (this.rendered) {
840
+ if (!this.lng.shader) {
841
+ this.lng.shader = Config.convertToShader(this, target as StyleEffects);
842
+ } else if (isDomRendererActive()) {
843
+ // eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
844
+ this.lng.shader = this.lng.shader;
845
+ }
846
+ } else {
847
+ this.lng.shader = target;
848
+ }
849
+ }
850
+
809
851
  set effects(v: StyleEffects) {
810
852
  if (!SHADERS_ENABLED) return;
811
853
  let target = this.lng.shader || {};
@@ -814,27 +856,11 @@ export class ElementNode {
814
856
  }
815
857
  if (v.rounded) target.radius = v.rounded.radius;
816
858
  if (v.borderRadius) target.radius = v.borderRadius;
817
- if (v.border) parseAndAssignShaderProps('border', v.border, target);
818
- if (v.borderTop)
819
- parseAndAssignShaderProps('borderTop', v.borderTop, target);
820
- if (v.borderRight)
821
- parseAndAssignShaderProps('borderRight', v.borderRight, target);
822
- if (v.borderBottom)
823
- parseAndAssignShaderProps('borderBottom', v.borderBottom, target);
824
- if (v.borderLeft)
825
- parseAndAssignShaderProps('borderLeft', v.borderLeft, target);
826
- if (v.shadow) parseAndAssignShaderProps('shadow', v.shadow, target);
827
-
828
- if (this.rendered) {
829
- if (!this.lng.shader) {
830
- this.lng.shader = Config.convertToShader(this, target);
831
- } else if (DOM_RENDERING && Config.domRendererEnabled) {
832
- // eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
833
- this.lng.shader = this.lng.shader;
834
- }
835
- } else {
836
- this.lng.shader = target;
859
+ for (const k of EFFECT_SHADER_KEYS) {
860
+ if (v[k]) parseAndAssignShaderProps(k, v[k], target);
837
861
  }
862
+
863
+ this._writeShaderTarget(target);
838
864
  }
839
865
 
840
866
  set id(id: string) {
@@ -1094,7 +1120,7 @@ export class ElementNode {
1094
1120
  if (this.rendered) {
1095
1121
  // can be 0
1096
1122
  if (this.forwardFocus !== undefined) {
1097
- if (isFunc(this.forwardFocus)) {
1123
+ if (isFunction(this.forwardFocus)) {
1098
1124
  if (this.forwardFocus.call(this, this) !== false) {
1099
1125
  return;
1100
1126
  }
@@ -1274,6 +1300,14 @@ export class ElementNode {
1274
1300
  return this.alpha === 0;
1275
1301
  }
1276
1302
 
1303
+ get preserve(): boolean {
1304
+ return this._queueDelete === 0;
1305
+ }
1306
+
1307
+ set preserve(v: boolean) {
1308
+ this._queueDelete = v ? 0 : undefined;
1309
+ }
1310
+
1277
1311
  /**
1278
1312
  * Sets the autofocus state of the element.
1279
1313
  * When set to a truthy value, the element will automatically gain focus.
@@ -1352,7 +1386,7 @@ export class ElementNode {
1352
1386
  const flexChanged = this.display === 'flex' && calculateFlex(this);
1353
1387
  layoutQueue.delete(this);
1354
1388
  const onLayoutChanged =
1355
- isFunc(this.onLayout) && this.onLayout.call(this, this);
1389
+ isFunction(this.onLayout) && this.onLayout.call(this, this);
1356
1390
 
1357
1391
  if ((flexChanged || onLayoutChanged) && this.parent) {
1358
1392
  addToLayoutQueue(this.parent);
@@ -1364,7 +1398,7 @@ export class ElementNode {
1364
1398
  if (c.display === 'flex' && isElementNode(c)) {
1365
1399
  // calculating directly to prevent infinite loops recalculating parents
1366
1400
  calculateFlex(c);
1367
- isFunc(c.onLayout) && c.onLayout.call(c, c);
1401
+ isFunction(c.onLayout) && c.onLayout.call(c, c);
1368
1402
  addToLayoutQueue(this);
1369
1403
  }
1370
1404
  });
@@ -1774,16 +1808,7 @@ export function shaderAccessor<T extends Record<string, any> | number>(
1774
1808
  parseAndAssignShaderProps(key, value, target);
1775
1809
  }
1776
1810
 
1777
- if (this.rendered) {
1778
- if (!this.lng.shader) {
1779
- this.lng.shader = Config.convertToShader(this, target);
1780
- } else if (DOM_RENDERING && Config.domRendererEnabled) {
1781
- // eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
1782
- this.lng.shader = this.lng.shader;
1783
- }
1784
- } else {
1785
- this.lng.shader = target;
1786
- }
1811
+ this._writeShaderTarget(target);
1787
1812
 
1788
1813
  if (animationSettings) {
1789
1814
  this.animate({ shaderProps: target }, animationSettings).start();