@solidtv/solid 1.3.2 → 1.3.4
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/dist/src/core/elementNode.js +15 -1
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/lightningInit.js +4 -1
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/primitives/Column.jsx +5 -3
- package/dist/src/primitives/Column.jsx.map +1 -1
- package/dist/src/primitives/Lazy.jsx +2 -2
- package/dist/src/primitives/Lazy.jsx.map +1 -1
- package/dist/src/primitives/Row.jsx +4 -2
- package/dist/src/primitives/Row.jsx.map +1 -1
- package/dist/src/primitives/announcer/speech.js +19 -22
- package/dist/src/primitives/announcer/speech.js.map +1 -1
- package/dist/src/primitives/types.d.ts +8 -1
- package/dist/src/primitives/useHold.d.ts +20 -3
- package/dist/src/primitives/useHold.js +65 -16
- package/dist/src/primitives/useHold.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.d.ts +1 -0
- package/dist/src/primitives/utils/withScrolling.js +11 -2
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/elementNode.ts +16 -1
- package/src/core/lightningInit.ts +5 -1
- package/src/primitives/Column.tsx +9 -7
- package/src/primitives/Lazy.tsx +2 -2
- package/src/primitives/Row.tsx +4 -2
- package/src/primitives/announcer/speech.ts +20 -26
- package/src/primitives/types.ts +11 -1
- package/src/primitives/useHold.ts +68 -15
- package/src/primitives/utils/withScrolling.ts +13 -3
package/package.json
CHANGED
package/src/core/elementNode.ts
CHANGED
|
@@ -1640,7 +1640,22 @@ export class ElementNode {
|
|
|
1640
1640
|
if (!props.texture) {
|
|
1641
1641
|
// Set width and height to parent less offset
|
|
1642
1642
|
if (isNaN(props.w as number)) {
|
|
1643
|
-
|
|
1643
|
+
// A flex container that sizes its width to its children (contain on the
|
|
1644
|
+
// main axis) should default to 1 rather than filling its parent, so it
|
|
1645
|
+
// shrinks to fit content once layout runs.
|
|
1646
|
+
let flexFitsWidth = false;
|
|
1647
|
+
if (node.display === 'flex') {
|
|
1648
|
+
const flexDirection = node.flexDirection || 'row';
|
|
1649
|
+
const isFlexRow =
|
|
1650
|
+
flexDirection === 'row' || flexDirection === 'row-reverse';
|
|
1651
|
+
flexFitsWidth = isFlexRow && node.flexBoundary !== 'fixed';
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
if (node.flexGrow || flexFitsWidth) {
|
|
1655
|
+
props.w = 0;
|
|
1656
|
+
} else {
|
|
1657
|
+
props.w = parentWidth - props.x;
|
|
1658
|
+
}
|
|
1644
1659
|
node._calcWidth = true;
|
|
1645
1660
|
}
|
|
1646
1661
|
|
|
@@ -27,6 +27,10 @@ export function startLightningRenderer(
|
|
|
27
27
|
export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
28
28
|
// Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
|
|
29
29
|
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
|
|
30
|
+
const hasCanvas =
|
|
31
|
+
!enableDomRenderer &&
|
|
32
|
+
'textRenderers' in renderer.stage &&
|
|
33
|
+
!!(renderer.stage as lng.Stage).textRenderers.canvas;
|
|
30
34
|
await Promise.all(
|
|
31
35
|
fonts.map((font) => {
|
|
32
36
|
// WebGL — SDF
|
|
@@ -41,7 +45,7 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
|
41
45
|
if ('fontUrl' in font) {
|
|
42
46
|
if (enableDomRenderer) {
|
|
43
47
|
loadFontToDom(font);
|
|
44
|
-
} else if (
|
|
48
|
+
} else if (hasCanvas) {
|
|
45
49
|
return renderer.stage.loadFont('canvas', font);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Component } from 'solid-js';
|
|
2
|
-
import {
|
|
3
|
-
ElementNode,
|
|
4
|
-
combineStyles,
|
|
5
|
-
type NodeStyles,
|
|
6
|
-
} from '@solidtv/solid';
|
|
2
|
+
import { ElementNode, combineStyles, type NodeStyles } from '@solidtv/solid';
|
|
7
3
|
import {
|
|
8
4
|
navigableForwardFocus,
|
|
9
5
|
handleNavigation,
|
|
@@ -20,10 +16,16 @@ const ColumnStyles: NodeStyles = {
|
|
|
20
16
|
gap: 30,
|
|
21
17
|
};
|
|
22
18
|
|
|
23
|
-
function scrollToIndex(
|
|
19
|
+
function scrollToIndex(
|
|
20
|
+
this: ElementNode,
|
|
21
|
+
index: number,
|
|
22
|
+
options?: { noFocus?: boolean },
|
|
23
|
+
): void {
|
|
24
24
|
this.selected = index;
|
|
25
25
|
scrollColumn(index, this);
|
|
26
|
-
|
|
26
|
+
if (!options?.noFocus) {
|
|
27
|
+
this.children[index]?.setFocus();
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const onUp = handleNavigation('up');
|
package/src/primitives/Lazy.tsx
CHANGED
|
@@ -136,9 +136,9 @@ function createLazy<T>(
|
|
|
136
136
|
Array.isArray(props.each) ? props.each.slice(0, offset()) : [],
|
|
137
137
|
);
|
|
138
138
|
|
|
139
|
-
function lazyScrollToIndex(this: lngp.NavigableElement, index: number) {
|
|
139
|
+
function lazyScrollToIndex(this: lngp.NavigableElement, index: number, options?: {noFocus?: boolean}) {
|
|
140
140
|
setOffset(Math.max(index, 0) + buffer())
|
|
141
|
-
queueMicrotask(() => viewRef.scrollToIndex(index));
|
|
141
|
+
queueMicrotask(() => viewRef.scrollToIndex(index, options));
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const updateOffset = (_event: KeyboardEvent, container: lng.ElementNode) => {
|
package/src/primitives/Row.tsx
CHANGED
|
@@ -19,10 +19,12 @@ const RowStyles: NodeStyles = {
|
|
|
19
19
|
gap: 30,
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
function scrollToIndex(this: ElementNode, index: number) {
|
|
22
|
+
function scrollToIndex(this: ElementNode, index: number, options?: {noFocus?: boolean}) {
|
|
23
23
|
this.selected = index;
|
|
24
24
|
scrollRow(index, this);
|
|
25
|
-
|
|
25
|
+
if (!options?.noFocus) {
|
|
26
|
+
this.children[index]?.setFocus();
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const onLeft = handleNavigation('left');
|
|
@@ -58,6 +58,12 @@ function addChildrenToAriaDiv(phrase: AriaLabel) {
|
|
|
58
58
|
* @description This function is triggered finally when the speak series is finished and we are to speak the aria labels
|
|
59
59
|
*/
|
|
60
60
|
function focusElementForAria() {
|
|
61
|
+
// Nothing new to announce (e.g. a canceled series). Leave whatever the live
|
|
62
|
+
// region currently holds in place so an in-progress screen reader isn't cut off.
|
|
63
|
+
if (ariaLabelPhrases.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
const element = createAriaElement();
|
|
62
68
|
|
|
63
69
|
if (!element) {
|
|
@@ -65,6 +71,12 @@ function focusElementForAria() {
|
|
|
65
71
|
return;
|
|
66
72
|
}
|
|
67
73
|
|
|
74
|
+
// Replace-on-next-write: drop the previous announcement's nodes, then inject
|
|
75
|
+
// the current label. The label stays in the assertive live region until the
|
|
76
|
+
// *next* announcement replaces it — rather than being torn down on a timer —
|
|
77
|
+
// so on-device TV screen readers have time to finish reading it.
|
|
78
|
+
cleanAriaLabelParent();
|
|
79
|
+
|
|
68
80
|
for (const object of ariaLabelPhrases) {
|
|
69
81
|
const span = document.createElement('span');
|
|
70
82
|
|
|
@@ -74,12 +86,7 @@ function focusElementForAria() {
|
|
|
74
86
|
element.appendChild(span);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
ariaLabelPhrases = [];
|
|
80
|
-
cleanAriaLabelParent();
|
|
81
|
-
focusCanvas();
|
|
82
|
-
}, 100);
|
|
89
|
+
ariaLabelPhrases = [];
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
/**
|
|
@@ -94,14 +101,6 @@ function cleanAriaLabelParent(): void {
|
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
|
|
97
|
-
/**
|
|
98
|
-
* @description Focus the canvas element
|
|
99
|
-
*/
|
|
100
|
-
function focusCanvas(): void {
|
|
101
|
-
const canvas = document.getElementById('app')?.firstChild as HTMLElement;
|
|
102
|
-
canvas?.focus();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
104
|
/**
|
|
106
105
|
* @description Create the aria element in the DOM if it doesn't exist
|
|
107
106
|
* @private For xbox, we may need to create a different element each time we wanna use aria
|
|
@@ -299,19 +298,14 @@ function speakSeries(
|
|
|
299
298
|
|
|
300
299
|
if (root) {
|
|
301
300
|
if (aria) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return;
|
|
301
|
+
// Replace-on-next-write: don't tear down the live region here. The
|
|
302
|
+
// current label stays until the next announcement replaces it, so the
|
|
303
|
+
// screen reader can finish. Just drop any partially accumulated
|
|
304
|
+
// phrases from this canceled series.
|
|
305
|
+
ariaLabelPhrases = [];
|
|
306
|
+
} else {
|
|
307
|
+
synth.cancel(); // Cancel all ongoing speech
|
|
312
308
|
}
|
|
313
|
-
|
|
314
|
-
synth.cancel(); // Cancel all ongoing speech
|
|
315
309
|
}
|
|
316
310
|
nestedSeriesResults.forEach((nestedSeriesResult) => {
|
|
317
311
|
nestedSeriesResult.cancel();
|
package/src/primitives/types.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface NavigableProps extends NodeProps {
|
|
|
25
25
|
/** When auto scrolling, item index at which scrolling begins */
|
|
26
26
|
scrollIndex?: number;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* When true and scroll is 'edge' or 'auto', the last item keeps the same
|
|
30
|
+
* position as the second-to-last instead of scrolling to remove trailing space.
|
|
31
|
+
*/
|
|
32
|
+
scrollStopLast?: boolean;
|
|
33
|
+
|
|
28
34
|
/** The initial index */
|
|
29
35
|
selected?: number;
|
|
30
36
|
|
|
@@ -74,7 +80,11 @@ export interface NavigableProps extends NodeProps {
|
|
|
74
80
|
// @ts-expect-error animationSettings is not identical - weird
|
|
75
81
|
export interface NavigableElement extends ElementNode, NavigableProps {
|
|
76
82
|
selected: number;
|
|
77
|
-
scrollToIndex: (
|
|
83
|
+
scrollToIndex: (
|
|
84
|
+
this: NavigableElement,
|
|
85
|
+
index: number,
|
|
86
|
+
options?: { noFocus?: boolean },
|
|
87
|
+
) => void;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export interface NavigableStyleProperties {
|
|
@@ -9,13 +9,30 @@ export type UseHoldProps = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
+
* Distinguishes a tap from a press-and-hold for a single key, without depending
|
|
13
|
+
* on the key-up event. This matters on TV platforms (notably LG webOS) where the
|
|
14
|
+
* OK button does not reliably emit a key-up, so any tap logic gated on key-up
|
|
15
|
+
* (`onEnterRelease`) would never run and the card would never open.
|
|
16
|
+
*
|
|
17
|
+
* How a press resolves:
|
|
18
|
+
* - key-down starts the hold timer.
|
|
19
|
+
* - an auto-repeat key-down before the timer fires marks the key as still held;
|
|
20
|
+
* when the timer fires it resolves to a hold → `onHold`.
|
|
21
|
+
* - if key-up arrives before the timer, it's a tap → `onEnter` (fires
|
|
22
|
+
* immediately, no latency, on platforms that deliver key-up).
|
|
23
|
+
* - if neither key-up nor auto-repeat arrives, the timer resolves to a tap →
|
|
24
|
+
* `onEnter` after `holdThreshold` ms. This is the key-up-independent path that
|
|
25
|
+
* keeps taps working on webOS, at the cost of ~`holdThreshold` ms latency.
|
|
26
|
+
*
|
|
27
|
+
* `performOnEnterImmediately` keeps the legacy behavior of firing `onEnter` on
|
|
28
|
+
* key-down; a long-press then fires both `onEnter` and `onHold`.
|
|
29
|
+
*
|
|
12
30
|
* @example
|
|
13
31
|
* const [holdRight, releaseRight] = useHold({
|
|
14
32
|
* onHold: handleHoldRight,
|
|
15
33
|
* onEnter: handleOnRight,
|
|
16
34
|
* onRelease: handleReleaseHold,
|
|
17
35
|
* holdThreshold: 200,
|
|
18
|
-
* performOnEnterImmediately: true
|
|
19
36
|
* });
|
|
20
37
|
*
|
|
21
38
|
* <view
|
|
@@ -24,7 +41,7 @@ export type UseHoldProps = {
|
|
|
24
41
|
* />
|
|
25
42
|
*
|
|
26
43
|
* @param {UseHoldProps} props - The properties for configuring the hold behavior.
|
|
27
|
-
* @returns {[() => boolean, () => boolean]} A tuple containing `startHold` and `releaseHold` functions.
|
|
44
|
+
* @returns {[(e?: KeyboardEvent) => boolean, () => boolean]} A tuple containing `startHold` and `releaseHold` functions.
|
|
28
45
|
*/
|
|
29
46
|
|
|
30
47
|
export function useHold(props: UseHoldProps) {
|
|
@@ -34,32 +51,68 @@ export function useHold(props: UseHoldProps) {
|
|
|
34
51
|
);
|
|
35
52
|
|
|
36
53
|
let holdTimeout = -1;
|
|
37
|
-
let
|
|
54
|
+
let enterFired = false; // onEnter already fired for this press
|
|
55
|
+
let holdFired = false; // onHold already fired for this press
|
|
56
|
+
let repeated = false; // an auto-repeat key-down was seen (key still held)
|
|
57
|
+
|
|
58
|
+
const reset = () => {
|
|
59
|
+
if (holdTimeout !== -1) {
|
|
60
|
+
clearTimeout(holdTimeout);
|
|
61
|
+
holdTimeout = -1;
|
|
62
|
+
}
|
|
63
|
+
enterFired = false;
|
|
64
|
+
holdFired = false;
|
|
65
|
+
repeated = false;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const startHold = (e?: KeyboardEvent) => {
|
|
69
|
+
// Auto-repeat key-down: the key is still held. Record it so the timer
|
|
70
|
+
// resolves to a hold even if the key-up event never arrives (webOS).
|
|
71
|
+
if (e?.repeat) {
|
|
72
|
+
repeated = true;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Fresh key-down begins a new press. Reset first so a previous press whose
|
|
77
|
+
// key-up was never delivered doesn't leave us wedged for this one.
|
|
78
|
+
reset();
|
|
38
79
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
80
|
+
if (performOnEnterImmediately()) {
|
|
81
|
+
enterFired = true;
|
|
82
|
+
props.onEnter();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
holdTimeout = setTimeout(() => {
|
|
86
|
+
holdTimeout = -1;
|
|
87
|
+
if (repeated) {
|
|
88
|
+
// Held past the threshold → hold gesture.
|
|
89
|
+
holdFired = true;
|
|
90
|
+
props.onHold();
|
|
91
|
+
} else if (!enterFired) {
|
|
92
|
+
// No key-up and no auto-repeat arrived: resolve as a tap so the
|
|
93
|
+
// primary action still fires on remotes that swallow key-up.
|
|
94
|
+
enterFired = true;
|
|
42
95
|
props.onEnter();
|
|
43
96
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
props.onHold();
|
|
47
|
-
}, holdThreshold()) as unknown as number;
|
|
48
|
-
}
|
|
97
|
+
}, holdThreshold()) as unknown as number;
|
|
98
|
+
|
|
49
99
|
return true;
|
|
50
100
|
};
|
|
51
101
|
|
|
52
102
|
const releaseHold = () => {
|
|
53
103
|
if (holdTimeout !== -1) {
|
|
104
|
+
// Released before the threshold → tap. Fires immediately where key-up is
|
|
105
|
+
// delivered, avoiding the timer latency.
|
|
54
106
|
clearTimeout(holdTimeout);
|
|
55
107
|
holdTimeout = -1;
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
if (!enterFired) {
|
|
109
|
+
enterFired = true;
|
|
110
|
+
props.onEnter();
|
|
59
111
|
}
|
|
112
|
+
} else if (holdFired) {
|
|
60
113
|
props.onRelease?.();
|
|
61
|
-
wasHeld = false;
|
|
62
114
|
}
|
|
115
|
+
reset();
|
|
63
116
|
return true;
|
|
64
117
|
};
|
|
65
118
|
|
|
@@ -28,11 +28,12 @@ export interface ScrollableElement extends ElementNode {
|
|
|
28
28
|
_targetPosition?: number;
|
|
29
29
|
_screenOffset?: number;
|
|
30
30
|
_initialPosition?: number;
|
|
31
|
+
scrollStopLast?: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
// From the renderer, not exported
|
|
34
35
|
const InViewPort = 8 as const;
|
|
35
|
-
const isNotShown = (node: ElementNode | ElementText) => {
|
|
36
|
+
const isNotShown = (node: ElementNode | ElementText): boolean => {
|
|
36
37
|
return (node.lng.renderState as number) !== InViewPort;
|
|
37
38
|
};
|
|
38
39
|
/*
|
|
@@ -185,7 +186,11 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
185
186
|
nextPosition = Math.min(Math.max(centerPosition, maxOffset), offset);
|
|
186
187
|
} else if (!nextElement) {
|
|
187
188
|
// If at the last element, align to end
|
|
188
|
-
|
|
189
|
+
if (componentRef.scrollStopLast && isIncrementing) {
|
|
190
|
+
nextPosition = rootPosition - selectedSize - gap;
|
|
191
|
+
} else {
|
|
192
|
+
nextPosition = isIncrementing ? maxOffset : offset;
|
|
193
|
+
}
|
|
189
194
|
} else if (scroll === 'auto') {
|
|
190
195
|
if (componentRef.scrollIndex && componentRef.scrollIndex > 0) {
|
|
191
196
|
// Prevent scrolling if the selected item is within the last scrollIndex items
|
|
@@ -213,8 +218,13 @@ export function withScrolling(isRow: boolean): Scroller {
|
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
// Prevent container from moving beyond bounds
|
|
221
|
+
const isScrollStopLastCase =
|
|
222
|
+
componentRef.scrollStopLast && !nextElement && isIncrementing;
|
|
216
223
|
nextPosition =
|
|
217
|
-
isIncrementing &&
|
|
224
|
+
isIncrementing &&
|
|
225
|
+
scroll !== 'always' &&
|
|
226
|
+
scroll !== 'bounded' &&
|
|
227
|
+
!isScrollStopLastCase
|
|
218
228
|
? Math.max(nextPosition, maxOffset)
|
|
219
229
|
: Math.min(nextPosition, offset);
|
|
220
230
|
|