@solidtv/solid 1.6.3 → 1.6.5
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.
- package/README.md +4 -0
- package/dist/src/core/config.d.ts +9 -0
- package/dist/src/core/config.js +1 -0
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.d.ts +2 -0
- package/dist/src/core/dom-renderer/domRenderer.js +9 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +4 -5
- package/dist/src/core/dom-renderer/domRendererUtils.d.ts +3 -8
- package/dist/src/core/dom-renderer/domRendererUtils.js +12 -22
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
- package/dist/src/core/focusManager.d.ts +6 -0
- package/dist/src/core/focusManager.js +33 -12
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/primitives/createFocusStack.d.ts +1 -1
- package/dist/src/primitives/createFocusStack.jsx +6 -2
- package/dist/src/primitives/createFocusStack.jsx.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/README.md +2 -0
- package/package.json +9 -4
- package/src/core/config.ts +10 -0
- package/src/core/dom-renderer/domRenderer.ts +11 -0
- package/src/core/dom-renderer/domRendererTypes.ts +4 -5
- package/src/core/dom-renderer/domRendererUtils.ts +13 -24
- package/src/core/focusManager.ts +50 -13
- package/src/primitives/createFocusStack.tsx +6 -2
package/docs/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
`@solidtv/solid` is an integration for the [SolidTV Renderer](https://github.com/solid-tv/renderer) built with [SolidJS](https://www.solidjs.com/) [Universal Renderer](https://github.com/solidjs/solid/releases/tag/v1.2.0). It allows you to declaratively construct WebGL nodes with SolidJS reactive primitives. It includes everything you need to rapidly build performant TV Apps.
|
|
6
6
|
|
|
7
|
+
?> **Commercial support available.** Support plans, performance audits, migrations to SolidTV, Apple TV ports and team training from the creator of SolidTV. [See support & services](https://solidtv.dev/#services).
|
|
8
|
+
|
|
7
9
|
## Starter Template
|
|
8
10
|
|
|
9
11
|
Clone starter template:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidtv/solid",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"description": "SolidTV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"sideEffects": false,
|
|
49
49
|
"scripts": {
|
|
50
50
|
"start": "pnpm run watch",
|
|
51
|
+
"bench": "node bench/run.mjs",
|
|
51
52
|
"test": "vitest",
|
|
52
53
|
"lint": "pnpm run lint:prettier && pnpm run lint:eslint",
|
|
53
54
|
"lint:fix": "pnpm run lint:fix:prettier && pnpm run lint:fix:eslint",
|
|
@@ -56,12 +57,13 @@
|
|
|
56
57
|
"lint:eslint": "eslint .",
|
|
57
58
|
"lint:fix:eslint": "eslint --fix .",
|
|
58
59
|
"build": "rm -rf dist && pnpm run tsc && cp jsx-runtime.d.ts dist/",
|
|
59
|
-
"tsc": "tsc",
|
|
60
|
+
"tsc": "tsc && tsc -p tests/tsconfig.contract.json",
|
|
60
61
|
"watch": "tsc -w",
|
|
61
62
|
"prepare": "husky",
|
|
62
63
|
"prepack": "pnpm run build",
|
|
63
64
|
"release": "release-it",
|
|
64
|
-
"test:browser": "vitest --config=vitest.browser.config.ts"
|
|
65
|
+
"test:browser": "vitest --config=vitest.browser.config.ts",
|
|
66
|
+
"test:webgl": "vitest run --config=vitest.webgl.config.ts"
|
|
65
67
|
},
|
|
66
68
|
"keywords": [
|
|
67
69
|
"lightning",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
82
84
|
"@eslint/js": "^9.39.4",
|
|
85
|
+
"@lightningtv/vite-hex-transform": "^1.1.0",
|
|
83
86
|
"@solid-devtools/debugger": "^0.28.1",
|
|
84
87
|
"@solidjs/testing-library": "^0.8.10",
|
|
85
88
|
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
@@ -92,8 +95,10 @@
|
|
|
92
95
|
"husky": "^9.1.7",
|
|
93
96
|
"jsdom": "^26.1.0",
|
|
94
97
|
"lint-staged": "^17.0.4",
|
|
98
|
+
"playwright": "1.56.1",
|
|
95
99
|
"prettier": "^3.8.3",
|
|
96
100
|
"release-it": "^20.0.1",
|
|
101
|
+
"terser": "^5.51.2",
|
|
97
102
|
"typescript": "^6.0.3",
|
|
98
103
|
"typescript-eslint": "^8.59.2",
|
|
99
104
|
"vite": "^8.0.13",
|
|
@@ -109,7 +114,7 @@
|
|
|
109
114
|
},
|
|
110
115
|
"peerDependencies": {
|
|
111
116
|
"@solidjs/router": "^0.16.1",
|
|
112
|
-
"@solidtv/renderer": "^1.
|
|
117
|
+
"@solidtv/renderer": "^1.10.1",
|
|
113
118
|
"solid-js": "*"
|
|
114
119
|
},
|
|
115
120
|
"peerDependenciesMeta": {},
|
package/src/core/config.ts
CHANGED
|
@@ -73,6 +73,15 @@ export interface Config {
|
|
|
73
73
|
lockStyles?: boolean;
|
|
74
74
|
fontWeightAlias?: Record<string, number | string>;
|
|
75
75
|
throttleInput?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Call `preventDefault()` on every key event the app consumed: a handler
|
|
78
|
+
* returned `true`, or the focus manager dropped the press itself (a
|
|
79
|
+
* throttled press, a suppressed repeat). A host that hands the system
|
|
80
|
+
* whatever the app leaves unhandled, such as the Menu button on tvOS,
|
|
81
|
+
* reads it to tell the two apart. Off by default: in a browser it would
|
|
82
|
+
* also stop the default action of every handled key.
|
|
83
|
+
*/
|
|
84
|
+
preventDefaultOnHandledKeys: boolean;
|
|
76
85
|
taskDelay?: number;
|
|
77
86
|
convertToShader: (_node: ElementNode, v: StyleEffects) => IRendererShader;
|
|
78
87
|
stateOrder?: DollarString[];
|
|
@@ -106,6 +115,7 @@ export const Config: Config = {
|
|
|
106
115
|
},
|
|
107
116
|
focusStateKey: '$focus',
|
|
108
117
|
lockStyles: true,
|
|
118
|
+
preventDefaultOnHandledKeys: false,
|
|
109
119
|
rendererOptions: {},
|
|
110
120
|
stateOrder: [],
|
|
111
121
|
};
|
|
@@ -1358,6 +1358,8 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1358
1358
|
|
|
1359
1359
|
preventCleanup = true;
|
|
1360
1360
|
|
|
1361
|
+
destroyed = false;
|
|
1362
|
+
|
|
1361
1363
|
constructor(
|
|
1362
1364
|
public stage: IRendererStage,
|
|
1363
1365
|
public props: IRendererNodeProps,
|
|
@@ -1380,6 +1382,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1380
1382
|
}
|
|
1381
1383
|
|
|
1382
1384
|
destroy(): void {
|
|
1385
|
+
this.markDestroyed();
|
|
1383
1386
|
elMap.delete(this);
|
|
1384
1387
|
const parent = this.props.parent;
|
|
1385
1388
|
if (parent instanceof DOMNode) {
|
|
@@ -1388,6 +1391,14 @@ export class DOMNode extends EventEmitter implements IRendererNode {
|
|
|
1388
1391
|
this.div.parentNode?.removeChild(this.div);
|
|
1389
1392
|
}
|
|
1390
1393
|
|
|
1394
|
+
// Like CoreNode, destroying a node marks its whole subtree destroyed.
|
|
1395
|
+
private markDestroyed() {
|
|
1396
|
+
this.destroyed = true;
|
|
1397
|
+
for (const child of this.children) {
|
|
1398
|
+
child.markDestroyed();
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1391
1402
|
get parent() {
|
|
1392
1403
|
return this.props.parent;
|
|
1393
1404
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
/** Based on {@link lng.CoreRenderer} */
|
|
13
13
|
export interface IRendererCoreRenderer {
|
|
14
14
|
mode: 'canvas' | 'webgl' | undefined;
|
|
15
|
-
boundsMargin?: number;
|
|
15
|
+
boundsMargin?: number | [number, number, number, number];
|
|
16
16
|
}
|
|
17
17
|
/** Based on {@link lng.TrFontManager} */
|
|
18
18
|
export interface IRendererFontManager {
|
|
@@ -148,9 +148,8 @@ export interface DomRendererMainSettings {
|
|
|
148
148
|
* Preload margin around the viewport, in logical pixels (default: 200)
|
|
149
149
|
*
|
|
150
150
|
* @remarks
|
|
151
|
-
* A single number applied to all sides
|
|
152
|
-
*
|
|
153
|
-
* (the largest edge wins, with a warning) but should be replaced.
|
|
151
|
+
* A single number applied to all sides, or a per-side
|
|
152
|
+
* `[top, right, bottom, left]` tuple.
|
|
154
153
|
*/
|
|
155
|
-
boundsMargin?: number;
|
|
154
|
+
boundsMargin?: number | [number, number, number, number];
|
|
156
155
|
}
|
|
@@ -222,30 +222,19 @@ export function nodeHasTextureSource(node: DOMNode): boolean {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @remarks
|
|
228
|
-
* The `[top, right, bottom, left]` array form was dropped in renderer 1.8. An
|
|
229
|
-
* untyped app upgrading from 1.7 can still pass it, so mirror the WebGL
|
|
230
|
-
* renderer and take the widest edge rather than letting the margin arithmetic
|
|
231
|
-
* go wrong.
|
|
225
|
+
* Normalize a `boundsMargin` value (scalar or per-side tuple) into a
|
|
226
|
+
* `[top, right, bottom, left]` tuple.
|
|
232
227
|
*/
|
|
233
228
|
export function normalizeBoundsMargin(
|
|
234
229
|
margin: number | number[] | null | undefined,
|
|
235
|
-
): number {
|
|
236
|
-
if (margin == null) return 0;
|
|
237
|
-
if (Array.isArray(margin) === false)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for (let i = 0; i < arr.length; i++) {
|
|
241
|
-
if (arr[i]! > max) {
|
|
242
|
-
max = arr[i]!;
|
|
243
|
-
}
|
|
230
|
+
): [number, number, number, number] {
|
|
231
|
+
if (margin == null) return [0, 0, 0, 0];
|
|
232
|
+
if (Array.isArray(margin) === false) {
|
|
233
|
+
const m = (margin as number) || 0;
|
|
234
|
+
return [m, m, m, m];
|
|
244
235
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
);
|
|
248
|
-
return max;
|
|
236
|
+
const arr = margin as number[];
|
|
237
|
+
return [arr[0] || 0, arr[1] || 0, arr[2] || 0, arr[3] || 0];
|
|
249
238
|
}
|
|
250
239
|
|
|
251
240
|
export function computeRenderStateForNode(
|
|
@@ -273,10 +262,10 @@ export function computeRenderStateForNode(
|
|
|
273
262
|
const right = left + width;
|
|
274
263
|
const bottom = top + height;
|
|
275
264
|
|
|
276
|
-
const expandedLeft = rootLeft - margin;
|
|
277
|
-
const expandedTop = rootTop - margin;
|
|
278
|
-
const expandedRight = rootRight + margin;
|
|
279
|
-
const expandedBottom = rootBottom + margin;
|
|
265
|
+
const expandedLeft = rootLeft - margin[3];
|
|
266
|
+
const expandedTop = rootTop - margin[0];
|
|
267
|
+
const expandedRight = rootRight + margin[1];
|
|
268
|
+
const expandedBottom = rootBottom + margin[2];
|
|
280
269
|
|
|
281
270
|
const intersectsBounds =
|
|
282
271
|
right >= expandedLeft &&
|
package/src/core/focusManager.ts
CHANGED
|
@@ -397,7 +397,10 @@ const propagateKeyPress = (
|
|
|
397
397
|
`Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
|
|
398
398
|
);
|
|
399
399
|
}
|
|
400
|
-
|
|
400
|
+
// Dropped on purpose, so consumed: the same answer an element's own
|
|
401
|
+
// throttleInput gives below, and what a host asking through
|
|
402
|
+
// Config.preventDefaultOnHandledKeys needs to hear.
|
|
403
|
+
return true;
|
|
401
404
|
}
|
|
402
405
|
lastGlobalKeyPressTime = currentTime;
|
|
403
406
|
}
|
|
@@ -529,33 +532,40 @@ export const releaseKeySuppression = (
|
|
|
529
532
|
liftSuppression(keyIdentities(keyOrEvent));
|
|
530
533
|
};
|
|
531
534
|
|
|
532
|
-
|
|
535
|
+
// Returns whether the app consumed the event: a handler took it, or the focus
|
|
536
|
+
// manager dropped it on purpose (a suppressed repeat, a throttled press).
|
|
537
|
+
const handleKeyEvents = (
|
|
538
|
+
keydown?: KeyboardEvent,
|
|
539
|
+
keyup?: KeyboardEvent,
|
|
540
|
+
): boolean => {
|
|
533
541
|
if (keydown) {
|
|
534
542
|
const ids = keyIdentities(keydown);
|
|
535
543
|
if (keydown.repeat) {
|
|
536
|
-
if (findSuppression(ids)) return;
|
|
544
|
+
if (findSuppression(ids)) return true;
|
|
537
545
|
} else {
|
|
538
546
|
// A fresh press starts a new gesture, so the previous one is over even
|
|
539
547
|
// though its key-up never arrived. Settle it before handling this press.
|
|
540
548
|
liftSuppression(ids);
|
|
541
549
|
}
|
|
542
550
|
|
|
543
|
-
propagateKeyPress(
|
|
551
|
+
return propagateKeyPress(
|
|
544
552
|
keydown,
|
|
545
553
|
keyMapEntries[keydown.key] || keyMapEntries[keydown.keyCode],
|
|
546
554
|
);
|
|
547
|
-
}
|
|
555
|
+
}
|
|
556
|
+
if (keyup) {
|
|
548
557
|
// The key is up: whatever was suppressing its repeats is done. Settle it
|
|
549
558
|
// before propagating, so a suppressor that is still in the focus path sees
|
|
550
559
|
// its own release callback rather than a second one via the key-up below.
|
|
551
560
|
liftSuppression(keyIdentities(keyup));
|
|
552
561
|
|
|
553
|
-
propagateKeyPress(
|
|
562
|
+
return propagateKeyPress(
|
|
554
563
|
keyup,
|
|
555
564
|
keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode],
|
|
556
565
|
true,
|
|
557
566
|
);
|
|
558
567
|
}
|
|
568
|
+
return false;
|
|
559
569
|
};
|
|
560
570
|
|
|
561
571
|
/**
|
|
@@ -567,6 +577,12 @@ export interface KeyEventLike {
|
|
|
567
577
|
readonly key: string;
|
|
568
578
|
readonly keyCode: number;
|
|
569
579
|
readonly repeat: boolean;
|
|
580
|
+
/**
|
|
581
|
+
* Called on an event the app consumed when
|
|
582
|
+
* `Config.preventDefaultOnHandledKeys` is set; optional, since a host's
|
|
583
|
+
* own event objects need not have it.
|
|
584
|
+
*/
|
|
585
|
+
preventDefault?(): void;
|
|
570
586
|
}
|
|
571
587
|
|
|
572
588
|
/**
|
|
@@ -587,12 +603,19 @@ export interface KeyEventTarget {
|
|
|
587
603
|
|
|
588
604
|
export const useFocusManager = (
|
|
589
605
|
userKeyMap?: Partial<KeyMap>,
|
|
590
|
-
target
|
|
606
|
+
target?: KeyEventTarget,
|
|
591
607
|
) => {
|
|
592
608
|
if (userKeyMap) {
|
|
593
609
|
flattenKeyMap(userKeyMap, keyMapEntries);
|
|
594
610
|
}
|
|
595
611
|
|
|
612
|
+
// Before the target parameter existed the second argument was ignored, and
|
|
613
|
+
// an object that cannot listen (the removed hold options, say) still is.
|
|
614
|
+
const eventTarget: KeyEventTarget =
|
|
615
|
+
target !== undefined && isFunction(target.addEventListener)
|
|
616
|
+
? target
|
|
617
|
+
: document;
|
|
618
|
+
|
|
596
619
|
// Capture the calling owner so signal updates and key-event reactions
|
|
597
620
|
// can run inside it — needed for programmatic .setFocus(), post-mutation
|
|
598
621
|
// focus, and any effect subscribers that rely on onCleanup.
|
|
@@ -610,16 +633,30 @@ export const useFocusManager = (
|
|
|
610
633
|
// Handlers are typed as KeyboardEvent throughout; on a host that raises
|
|
611
634
|
// its own objects they see those, which carry the fields read here.
|
|
612
635
|
const keyPressHandler = (event: KeyEventLike) =>
|
|
613
|
-
ownerContext(() =>
|
|
636
|
+
ownerContext(() => {
|
|
637
|
+
if (
|
|
638
|
+
handleKeyEvents(event as KeyboardEvent, undefined) &&
|
|
639
|
+
Config.preventDefaultOnHandledKeys
|
|
640
|
+
) {
|
|
641
|
+
event.preventDefault?.();
|
|
642
|
+
}
|
|
643
|
+
});
|
|
614
644
|
const keyUpHandler = (event: KeyEventLike) =>
|
|
615
|
-
ownerContext(() =>
|
|
645
|
+
ownerContext(() => {
|
|
646
|
+
if (
|
|
647
|
+
handleKeyEvents(undefined, event as KeyboardEvent) &&
|
|
648
|
+
Config.preventDefaultOnHandledKeys
|
|
649
|
+
) {
|
|
650
|
+
event.preventDefault?.();
|
|
651
|
+
}
|
|
652
|
+
});
|
|
616
653
|
|
|
617
|
-
|
|
618
|
-
|
|
654
|
+
eventTarget.addEventListener('keydown', keyPressHandler);
|
|
655
|
+
eventTarget.addEventListener('keyup', keyUpHandler);
|
|
619
656
|
|
|
620
657
|
onCleanup(() => {
|
|
621
|
-
|
|
622
|
-
|
|
658
|
+
eventTarget.removeEventListener('keydown', keyPressHandler);
|
|
659
|
+
eventTarget.removeEventListener('keyup', keyUpHandler);
|
|
623
660
|
suppressedKeys.clear();
|
|
624
661
|
});
|
|
625
662
|
};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Functions:
|
|
16
16
|
* - `storeFocus(element: ElementNode, prevElement?: ElementNode)`: Stores the provided element in the focus stack.
|
|
17
|
-
* - `restoreFocus()`: Restores focus to the last stored element and removes it from the stack. Returns `true` if successful, `false` otherwise.
|
|
17
|
+
* - `restoreFocus()`: Restores focus to the last stored element and removes it from the stack, skipping (and removing) destroyed elements. Returns `true` if successful, `false` otherwise.
|
|
18
18
|
* - `clearFocusStack()`: Empties the focus stack.
|
|
19
19
|
*/
|
|
20
20
|
import * as s from 'solid-js';
|
|
@@ -41,7 +41,11 @@ export function FocusStackProvider(props: { children: s.JSX.Element}) {
|
|
|
41
41
|
function restoreFocus(): boolean {
|
|
42
42
|
let wasFocused = false;
|
|
43
43
|
setFocusStack((stack) => {
|
|
44
|
-
|
|
44
|
+
let prevElement = stack.pop();
|
|
45
|
+
// Skip elements destroyed since they were stored
|
|
46
|
+
while (prevElement?.destroyed) {
|
|
47
|
+
prevElement = stack.pop();
|
|
48
|
+
}
|
|
45
49
|
if (prevElement && typeof prevElement.setFocus === 'function') {
|
|
46
50
|
prevElement.setFocus();
|
|
47
51
|
wasFocused = true;
|