@solidtv/solid 1.0.0

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 (237) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +95 -0
  4. package/dist/jsx-runtime.d.ts +14 -0
  5. package/dist/src/activeElement.d.ts +2 -0
  6. package/dist/src/activeElement.js +3 -0
  7. package/dist/src/activeElement.js.map +1 -0
  8. package/dist/src/core/config.d.ts +51 -0
  9. package/dist/src/core/config.js +37 -0
  10. package/dist/src/core/config.js.map +1 -0
  11. package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
  12. package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
  13. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
  14. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
  15. package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
  16. package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
  17. package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
  18. package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
  19. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
  20. package/dist/src/core/elementNode.d.ts +508 -0
  21. package/dist/src/core/elementNode.js +928 -0
  22. package/dist/src/core/elementNode.js.map +1 -0
  23. package/dist/src/core/flex.d.ts +2 -0
  24. package/dist/src/core/flex.js +284 -0
  25. package/dist/src/core/flex.js.map +1 -0
  26. package/dist/src/core/flexLayout.d.ts +2 -0
  27. package/dist/src/core/flexLayout.js +360 -0
  28. package/dist/src/core/flexLayout.js.map +1 -0
  29. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  30. package/dist/src/core/focusKeyTypes.js +2 -0
  31. package/dist/src/core/focusKeyTypes.js.map +1 -0
  32. package/dist/src/core/focusManager.d.ts +13 -0
  33. package/dist/src/core/focusManager.js +270 -0
  34. package/dist/src/core/focusManager.js.map +1 -0
  35. package/dist/src/core/index.d.ts +14 -0
  36. package/dist/src/core/index.js +11 -0
  37. package/dist/src/core/index.js.map +1 -0
  38. package/dist/src/core/intrinsicTypes.d.ts +106 -0
  39. package/dist/src/core/intrinsicTypes.js +2 -0
  40. package/dist/src/core/intrinsicTypes.js.map +1 -0
  41. package/dist/src/core/lightningInit.d.ts +9 -0
  42. package/dist/src/core/lightningInit.js +34 -0
  43. package/dist/src/core/lightningInit.js.map +1 -0
  44. package/dist/src/core/nodeTypes.d.ts +6 -0
  45. package/dist/src/core/nodeTypes.js +6 -0
  46. package/dist/src/core/nodeTypes.js.map +1 -0
  47. package/dist/src/core/shaders.d.ts +52 -0
  48. package/dist/src/core/shaders.js +86 -0
  49. package/dist/src/core/shaders.js.map +1 -0
  50. package/dist/src/core/states.d.ts +12 -0
  51. package/dist/src/core/states.js +84 -0
  52. package/dist/src/core/states.js.map +1 -0
  53. package/dist/src/core/utils.d.ts +39 -0
  54. package/dist/src/core/utils.js +164 -0
  55. package/dist/src/core/utils.js.map +1 -0
  56. package/dist/src/devtools/index.d.ts +6 -0
  57. package/dist/src/devtools/index.js +65 -0
  58. package/dist/src/devtools/index.js.map +1 -0
  59. package/dist/src/index.d.ts +9 -0
  60. package/dist/src/index.js +7 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/primitives/Column.d.ts +3 -0
  63. package/dist/src/primitives/Column.jsx +25 -0
  64. package/dist/src/primitives/Column.jsx.map +1 -0
  65. package/dist/src/primitives/FPSCounter.d.ts +4 -0
  66. package/dist/src/primitives/FPSCounter.jsx +188 -0
  67. package/dist/src/primitives/FPSCounter.jsx.map +1 -0
  68. package/dist/src/primitives/FadeInOut.d.ts +18 -0
  69. package/dist/src/primitives/FadeInOut.jsx +39 -0
  70. package/dist/src/primitives/FadeInOut.jsx.map +1 -0
  71. package/dist/src/primitives/Grid.d.ts +23 -0
  72. package/dist/src/primitives/Grid.jsx +100 -0
  73. package/dist/src/primitives/Grid.jsx.map +1 -0
  74. package/dist/src/primitives/Image.d.ts +8 -0
  75. package/dist/src/primitives/Image.jsx +42 -0
  76. package/dist/src/primitives/Image.jsx.map +1 -0
  77. package/dist/src/primitives/KeepAlive.d.ts +42 -0
  78. package/dist/src/primitives/KeepAlive.jsx +160 -0
  79. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  80. package/dist/src/primitives/Lazy.d.ts +15 -0
  81. package/dist/src/primitives/Lazy.jsx +95 -0
  82. package/dist/src/primitives/Lazy.jsx.map +1 -0
  83. package/dist/src/primitives/LazyImport.d.ts +8 -0
  84. package/dist/src/primitives/LazyImport.js +40 -0
  85. package/dist/src/primitives/LazyImport.js.map +1 -0
  86. package/dist/src/primitives/Marquee.d.ts +64 -0
  87. package/dist/src/primitives/Marquee.jsx +86 -0
  88. package/dist/src/primitives/Marquee.jsx.map +1 -0
  89. package/dist/src/primitives/Preserve.d.ts +4 -0
  90. package/dist/src/primitives/Preserve.jsx +11 -0
  91. package/dist/src/primitives/Preserve.jsx.map +1 -0
  92. package/dist/src/primitives/Row.d.ts +3 -0
  93. package/dist/src/primitives/Row.jsx +24 -0
  94. package/dist/src/primitives/Row.jsx.map +1 -0
  95. package/dist/src/primitives/Suspense.d.ts +22 -0
  96. package/dist/src/primitives/Suspense.jsx +33 -0
  97. package/dist/src/primitives/Suspense.jsx.map +1 -0
  98. package/dist/src/primitives/Virtual.d.ts +18 -0
  99. package/dist/src/primitives/Virtual.jsx +495 -0
  100. package/dist/src/primitives/Virtual.jsx.map +1 -0
  101. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  102. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  103. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  104. package/dist/src/primitives/Visible.d.ts +6 -0
  105. package/dist/src/primitives/Visible.jsx +37 -0
  106. package/dist/src/primitives/Visible.jsx.map +1 -0
  107. package/dist/src/primitives/announcer/announcer.d.ts +40 -0
  108. package/dist/src/primitives/announcer/announcer.js +125 -0
  109. package/dist/src/primitives/announcer/announcer.js.map +1 -0
  110. package/dist/src/primitives/announcer/index.d.ts +6 -0
  111. package/dist/src/primitives/announcer/index.js +15 -0
  112. package/dist/src/primitives/announcer/index.js.map +1 -0
  113. package/dist/src/primitives/announcer/speech.d.ts +10 -0
  114. package/dist/src/primitives/announcer/speech.js +281 -0
  115. package/dist/src/primitives/announcer/speech.js.map +1 -0
  116. package/dist/src/primitives/borderBox.d.ts +8 -0
  117. package/dist/src/primitives/borderBox.jsx +47 -0
  118. package/dist/src/primitives/borderBox.jsx.map +1 -0
  119. package/dist/src/primitives/createFocusStack.d.ts +31 -0
  120. package/dist/src/primitives/createFocusStack.jsx +62 -0
  121. package/dist/src/primitives/createFocusStack.jsx.map +1 -0
  122. package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
  123. package/dist/src/primitives/createInfiniteItems.js +46 -0
  124. package/dist/src/primitives/createInfiniteItems.js.map +1 -0
  125. package/dist/src/primitives/createTag.d.ts +8 -0
  126. package/dist/src/primitives/createTag.jsx +20 -0
  127. package/dist/src/primitives/createTag.jsx.map +1 -0
  128. package/dist/src/primitives/index.d.ts +32 -0
  129. package/dist/src/primitives/index.js +31 -0
  130. package/dist/src/primitives/index.js.map +1 -0
  131. package/dist/src/primitives/portal.d.ts +5 -0
  132. package/dist/src/primitives/portal.jsx +21 -0
  133. package/dist/src/primitives/portal.jsx.map +1 -0
  134. package/dist/src/primitives/router.d.ts +20 -0
  135. package/dist/src/primitives/router.js +90 -0
  136. package/dist/src/primitives/router.js.map +1 -0
  137. package/dist/src/primitives/types.d.ts +79 -0
  138. package/dist/src/primitives/types.js +2 -0
  139. package/dist/src/primitives/types.js.map +1 -0
  140. package/dist/src/primitives/useFocusManager.d.ts +5 -0
  141. package/dist/src/primitives/useFocusManager.js +21 -0
  142. package/dist/src/primitives/useFocusManager.js.map +1 -0
  143. package/dist/src/primitives/useHold.d.ts +27 -0
  144. package/dist/src/primitives/useHold.js +54 -0
  145. package/dist/src/primitives/useHold.js.map +1 -0
  146. package/dist/src/primitives/useMouse.d.ts +18 -0
  147. package/dist/src/primitives/useMouse.js +240 -0
  148. package/dist/src/primitives/useMouse.js.map +1 -0
  149. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
  150. package/dist/src/primitives/utils/chainFunctions.js +32 -0
  151. package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
  152. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  153. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  154. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  155. package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
  156. package/dist/src/primitives/utils/createSpriteMap.js +18 -0
  157. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
  158. package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
  159. package/dist/src/primitives/utils/handleNavigation.js +300 -0
  160. package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
  161. package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
  162. package/dist/src/primitives/utils/withScrolling.js +186 -0
  163. package/dist/src/primitives/utils/withScrolling.js.map +1 -0
  164. package/dist/src/render.d.ts +28 -0
  165. package/dist/src/render.js +107 -0
  166. package/dist/src/render.js.map +1 -0
  167. package/dist/src/solidOpts.d.ts +15 -0
  168. package/dist/src/solidOpts.js +93 -0
  169. package/dist/src/solidOpts.js.map +1 -0
  170. package/dist/src/types.d.ts +11 -0
  171. package/dist/src/types.js +2 -0
  172. package/dist/src/types.js.map +1 -0
  173. package/dist/src/utils.d.ts +19 -0
  174. package/dist/src/utils.js +94 -0
  175. package/dist/src/utils.js.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/docs/AI_CODING_GUIDELINES.md +108 -0
  178. package/docs/README.md +35 -0
  179. package/jsx-runtime.d.ts +14 -0
  180. package/package.json +125 -0
  181. package/src/activeElement.ts +5 -0
  182. package/src/core/config.ts +101 -0
  183. package/src/core/dom-renderer/domRenderer.ts +2066 -0
  184. package/src/core/dom-renderer/domRendererTypes.ts +148 -0
  185. package/src/core/dom-renderer/domRendererUtils.ts +292 -0
  186. package/src/core/elementNode.ts +1623 -0
  187. package/src/core/flex.ts +331 -0
  188. package/src/core/flexLayout.ts +414 -0
  189. package/src/core/focusKeyTypes.ts +90 -0
  190. package/src/core/focusManager.ts +374 -0
  191. package/src/core/index.ts +15 -0
  192. package/src/core/intrinsicTypes.ts +216 -0
  193. package/src/core/lightningInit.ts +45 -0
  194. package/src/core/nodeTypes.ts +6 -0
  195. package/src/core/shaders.ts +187 -0
  196. package/src/core/states.ts +91 -0
  197. package/src/core/utils.ts +222 -0
  198. package/src/devtools/index.ts +77 -0
  199. package/src/index.ts +18 -0
  200. package/src/primitives/Column.tsx +59 -0
  201. package/src/primitives/FPSCounter.tsx +209 -0
  202. package/src/primitives/FadeInOut.tsx +58 -0
  203. package/src/primitives/Grid.tsx +151 -0
  204. package/src/primitives/Image.tsx +56 -0
  205. package/src/primitives/KeepAlive.tsx +268 -0
  206. package/src/primitives/Lazy.tsx +128 -0
  207. package/src/primitives/LazyImport.ts +53 -0
  208. package/src/primitives/Marquee.tsx +149 -0
  209. package/src/primitives/Preserve.tsx +18 -0
  210. package/src/primitives/Row.tsx +58 -0
  211. package/src/primitives/Suspense.tsx +39 -0
  212. package/src/primitives/Virtual.tsx +602 -0
  213. package/src/primitives/VirtualGrid.tsx +220 -0
  214. package/src/primitives/Visible.tsx +59 -0
  215. package/src/primitives/announcer/announcer.ts +198 -0
  216. package/src/primitives/announcer/index.ts +20 -0
  217. package/src/primitives/announcer/speech.ts +334 -0
  218. package/src/primitives/borderBox.tsx +69 -0
  219. package/src/primitives/createFocusStack.tsx +79 -0
  220. package/src/primitives/createInfiniteItems.ts +66 -0
  221. package/src/primitives/createTag.tsx +33 -0
  222. package/src/primitives/index.ts +37 -0
  223. package/src/primitives/portal.tsx +25 -0
  224. package/src/primitives/router.ts +147 -0
  225. package/src/primitives/types.ts +109 -0
  226. package/src/primitives/useFocusManager.ts +47 -0
  227. package/src/primitives/useHold.ts +69 -0
  228. package/src/primitives/useMouse.ts +417 -0
  229. package/src/primitives/utils/chainFunctions.ts +60 -0
  230. package/src/primitives/utils/createBlurredImage.ts +366 -0
  231. package/src/primitives/utils/createSpriteMap.ts +32 -0
  232. package/src/primitives/utils/handleNavigation.ts +373 -0
  233. package/src/primitives/utils/withScrolling.ts +238 -0
  234. package/src/render.ts +164 -0
  235. package/src/solidOpts.ts +107 -0
  236. package/src/types.ts +22 -0
  237. package/src/utils.ts +129 -0
@@ -0,0 +1,334 @@
1
+ type CoreSpeechType =
2
+ | string
3
+ | (() => SpeechType)
4
+ | SpeechType[]
5
+ | SpeechSynthesisUtterance;
6
+ export type SpeechType = CoreSpeechType | Promise<CoreSpeechType>;
7
+
8
+ export interface SeriesResult {
9
+ series: Promise<void>;
10
+ readonly active: boolean;
11
+ append: (toSpeak: SpeechType) => void;
12
+ cancel: () => void;
13
+ }
14
+
15
+ // Aria label
16
+ type AriaLabel = { text: string; lang: string };
17
+ const ARIA_PARENT_ID = 'aria-parent';
18
+ let ariaLabelPhrases: AriaLabel[] = [];
19
+
20
+ /* global SpeechSynthesisErrorEvent */
21
+ function flattenStrings(series: SpeechType[] = []): SpeechType[] {
22
+ const flattenedSeries = [];
23
+
24
+ let i;
25
+ for (i = 0; i < series.length; i++) {
26
+ const s = series[i];
27
+ if (typeof s === 'string' && !s.includes('PAUSE-')) {
28
+ flattenedSeries.push(series[i]);
29
+ } else {
30
+ break;
31
+ }
32
+ }
33
+ // add a "word boundary" to ensure the Announcer doesn't automatically try to
34
+ // interpret strings that look like dates but are not actually dates
35
+ // for example, if "Rising Sun" and "1993" are meant to be two separate lines,
36
+ // when read together, "Sun 1993" is interpretted as "Sunday 1993"
37
+ return ([flattenedSeries.join(',\b ')] as SpeechType[]).concat(
38
+ series.slice(i),
39
+ );
40
+ }
41
+
42
+ function delay(pause: number) {
43
+ return new Promise((resolve) => {
44
+ setTimeout(resolve, pause);
45
+ });
46
+ }
47
+
48
+ /**
49
+ * @description This function is called at the end of the speak series
50
+ * @param Phrase is an object containing the text and the language
51
+ */
52
+ function addChildrenToAriaDiv(phrase: AriaLabel) {
53
+ if (phrase?.text?.trim().length === 0) return;
54
+ ariaLabelPhrases.push(phrase);
55
+ }
56
+
57
+ /**
58
+ * @description This function is triggered finally when the speak series is finished and we are to speak the aria labels
59
+ */
60
+ function focusElementForAria() {
61
+ const element = createAriaElement();
62
+
63
+ if (!element) {
64
+ console.error(`ARIA div not found: ${ARIA_PARENT_ID}`);
65
+ return;
66
+ }
67
+
68
+ for (const object of ariaLabelPhrases) {
69
+ const span = document.createElement('span');
70
+
71
+ // TODO: Not sure LG or Samsung support lang attribute on span or switching language
72
+ span.setAttribute('lang', object.lang);
73
+ span.setAttribute('aria-label', object.text);
74
+ element.appendChild(span);
75
+ }
76
+
77
+ // Cleanup
78
+ setTimeout(() => {
79
+ ariaLabelPhrases = [];
80
+ cleanAriaLabelParent();
81
+ focusCanvas();
82
+ }, 100);
83
+ }
84
+
85
+ /**
86
+ * @description Clean the aria label parent after speaking
87
+ */
88
+ function cleanAriaLabelParent(): void {
89
+ const parentTag = document.getElementById(ARIA_PARENT_ID);
90
+ if (parentTag) {
91
+ while (parentTag.firstChild) {
92
+ parentTag.removeChild(parentTag.firstChild);
93
+ }
94
+ }
95
+ }
96
+
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
+ /**
106
+ * @description Create the aria element in the DOM if it doesn't exist
107
+ * @private For xbox, we may need to create a different element each time we wanna use aria
108
+ */
109
+ function createAriaElement(): HTMLDivElement | HTMLElement {
110
+ const aria_container = document.getElementById(ARIA_PARENT_ID);
111
+
112
+ if (!aria_container) {
113
+ const element = document.createElement('div');
114
+ element.setAttribute('id', ARIA_PARENT_ID);
115
+ element.setAttribute('aria-live', 'assertive');
116
+ element.setAttribute('tabindex', '0');
117
+ document.body.appendChild(element);
118
+ return element;
119
+ }
120
+
121
+ return aria_container;
122
+ }
123
+
124
+ /**
125
+ * Speak a string
126
+ *
127
+ * @param phrase Phrase to speak
128
+ * @param utterances An array which the new SpeechSynthesisUtterance instance representing this utterance will be appended
129
+ * @param lang Language to speak in
130
+ * @return {Promise<void>} Promise resolved when the utterance has finished speaking, and rejected if there's an error
131
+ */
132
+ function speak(
133
+ phrase: string,
134
+ utterances: SpeechSynthesisUtterance[],
135
+ lang = 'en-US',
136
+ voiceName?: string,
137
+ ) {
138
+ const synth = window.speechSynthesis;
139
+
140
+ return new Promise<void>((resolve, reject) => {
141
+ let selectedVoice;
142
+ if (voiceName) {
143
+ const availableVoices = synth.getVoices();
144
+ selectedVoice =
145
+ availableVoices.find((v) => v.name === voiceName) || availableVoices[0];
146
+ }
147
+
148
+ const utterance = new SpeechSynthesisUtterance(phrase);
149
+ utterance.lang = lang;
150
+ if (selectedVoice) {
151
+ utterance.voice = selectedVoice;
152
+ }
153
+ utterance.onend = () => {
154
+ resolve();
155
+ };
156
+ utterance.onerror = (e) => {
157
+ reject(e);
158
+ };
159
+ utterances.push(utterance);
160
+ synth.speak(utterance);
161
+ });
162
+ }
163
+
164
+ function speakSeries(
165
+ series: SpeechType,
166
+ aria: boolean,
167
+ lang: string,
168
+ voice?: string,
169
+ root = true,
170
+ ): SeriesResult {
171
+ const synth = window.speechSynthesis;
172
+ const remainingPhrases = flattenStrings(
173
+ Array.isArray(series) ? series : [series],
174
+ );
175
+ const nestedSeriesResults: SeriesResult[] = [];
176
+ const utterances: SpeechSynthesisUtterance[] = [];
177
+ let active: boolean = true;
178
+
179
+ const seriesChain = (async () => {
180
+ try {
181
+ while (active && remainingPhrases.length) {
182
+ const phrase = await Promise.resolve(remainingPhrases.shift());
183
+ if (!active) {
184
+ break; // Exit if canceled
185
+ }
186
+
187
+ if (typeof phrase === 'string' && phrase.includes('PAUSE-')) {
188
+ // Handle pauses
189
+ const pause = Number(phrase.split('PAUSE-')[1]) * 1000;
190
+ if (!isNaN(pause)) {
191
+ await delay(pause);
192
+ }
193
+ } else if (typeof phrase === 'string') {
194
+ if (!phrase) {
195
+ continue; // Skip empty strings
196
+ }
197
+ // Handle regular strings with retry logic
198
+ const totalRetries = 3;
199
+ let retriesLeft = totalRetries;
200
+
201
+ while (active && retriesLeft > 0) {
202
+ try {
203
+ if (aria) addChildrenToAriaDiv({ text: phrase, lang });
204
+ else await speak(phrase, utterances, lang, voice);
205
+ retriesLeft = 0; // Exit retry loop on success
206
+ } catch (e) {
207
+ if (e instanceof SpeechSynthesisErrorEvent) {
208
+ if (e.error === 'network') {
209
+ retriesLeft--;
210
+ console.warn(
211
+ `Speech synthesis network error. Retries left: ${retriesLeft}`,
212
+ );
213
+ await delay(500 * (totalRetries - retriesLeft));
214
+ } else if (
215
+ e.error === 'canceled' ||
216
+ e.error === 'interrupted'
217
+ ) {
218
+ // Cancel or interrupt error (ignore)
219
+ retriesLeft = 0;
220
+ } else {
221
+ throw new Error(`SpeechSynthesisErrorEvent: ${e.error}`);
222
+ }
223
+ } else {
224
+ throw e;
225
+ }
226
+ }
227
+ }
228
+ } else if (phrase instanceof SpeechSynthesisUtterance) {
229
+ // Handle SpeechSynthesisUtterance objects with retry logic
230
+ const totalRetries = 3;
231
+ let retriesLeft = totalRetries;
232
+ const text = phrase.text;
233
+ const objectLang = phrase?.lang;
234
+ const objectVoice = phrase?.voice;
235
+
236
+ while (active && retriesLeft > 0) {
237
+ try {
238
+ if (text) {
239
+ if (aria) addChildrenToAriaDiv({ text, lang: objectLang });
240
+ else
241
+ await speak(text, utterances, objectLang, objectVoice?.name);
242
+ retriesLeft = 0; // Exit retry loop on success
243
+ }
244
+ } catch (e) {
245
+ if (e instanceof SpeechSynthesisErrorEvent) {
246
+ if (e.error === 'network') {
247
+ retriesLeft--;
248
+ console.warn(
249
+ `Speech synthesis network error. Retries left: ${retriesLeft}`,
250
+ );
251
+ await delay(500 * (totalRetries - retriesLeft));
252
+ } else if (
253
+ e.error === 'canceled' ||
254
+ e.error === 'interrupted'
255
+ ) {
256
+ // Cancel or interrupt error (ignore)
257
+ retriesLeft = 0;
258
+ } else {
259
+ throw new Error(`SpeechSynthesisErrorEvent: ${e.error}`);
260
+ }
261
+ } else {
262
+ throw e;
263
+ }
264
+ }
265
+ }
266
+ } else if (typeof phrase === 'function') {
267
+ // Handle functions
268
+ const seriesResult = speakSeries(phrase(), aria, lang, voice, false);
269
+ nestedSeriesResults.push(seriesResult);
270
+ await seriesResult.series;
271
+ } else if (Array.isArray(phrase)) {
272
+ // Handle nested arrays
273
+ const seriesResult = speakSeries(phrase, aria, lang, voice, false);
274
+ nestedSeriesResults.push(seriesResult);
275
+ await seriesResult.series;
276
+ }
277
+ }
278
+ } finally {
279
+ active = false;
280
+ // Call completion logic only for the original (root) series
281
+ if (root && aria) {
282
+ focusElementForAria();
283
+ }
284
+ }
285
+ })();
286
+
287
+ return {
288
+ series: seriesChain,
289
+ get active() {
290
+ return active;
291
+ },
292
+ append: (toSpeak: SpeechType) => {
293
+ remainingPhrases.push(toSpeak);
294
+ },
295
+ cancel: () => {
296
+ if (!active) {
297
+ return;
298
+ }
299
+
300
+ if (root) {
301
+ if (aria) {
302
+ const element = createAriaElement();
303
+
304
+ if (element) {
305
+ ariaLabelPhrases = [];
306
+ cleanAriaLabelParent();
307
+ element.focus();
308
+ focusCanvas();
309
+ }
310
+
311
+ return;
312
+ }
313
+
314
+ synth.cancel(); // Cancel all ongoing speech
315
+ }
316
+ nestedSeriesResults.forEach((nestedSeriesResult) => {
317
+ nestedSeriesResult.cancel();
318
+ });
319
+ active = false;
320
+ },
321
+ };
322
+ }
323
+
324
+ let currentSeries: SeriesResult | undefined;
325
+ export default function (
326
+ toSpeak: SpeechType,
327
+ aria: boolean,
328
+ lang: string = 'en-US',
329
+ voice?: string,
330
+ ) {
331
+ currentSeries && currentSeries.cancel();
332
+ currentSeries = speakSeries(toSpeak, aria, lang, voice);
333
+ return currentSeries;
334
+ }
@@ -0,0 +1,69 @@
1
+ import {
2
+ ElementNode,
3
+ insertNode,
4
+ type NodeProps,
5
+ type NodeStyles,
6
+ } from '@solidtv/solid';
7
+ import { getOwner, runWithOwner, type Accessor } from 'solid-js';
8
+ import { chainFunctions } from '@solidtv/solid/primitives';
9
+
10
+ export const BorderBoxStyle: NodeStyles = {
11
+ alpha: 0.01,
12
+ borderSpace: 6,
13
+ borderRadius: 20,
14
+ border: { color: 0xffffff, width: 2 },
15
+ transition: { alpha: { duration: 100, easing: 'linear' } },
16
+ };
17
+
18
+ type BorderProps = NodeProps & { borderSpace?: number };
19
+ const borderComponent = (props: BorderProps) => {
20
+ const space = props.borderSpace ?? (BorderBoxStyle.borderSpace as number);
21
+ return (
22
+ <view
23
+ skipFocus
24
+ onCreate={(el) => {
25
+ const parent = el.parent!;
26
+ el.width = parent.width + space * 2;
27
+ el.height = parent.height + space * 2;
28
+ el.alpha = 1;
29
+ }}
30
+ onDestroy={(el) => {
31
+ return el
32
+ .animate({ alpha: 0 }, el.transition as any)
33
+ .start()
34
+ .waitUntilStopped();
35
+ }}
36
+ style={BorderBoxStyle}
37
+ x={-space}
38
+ y={-space}
39
+ {...props}
40
+ />
41
+ );
42
+ };
43
+
44
+ // Solid directives can only be used on native root elements `view` and `text`
45
+ export function borderBox(
46
+ el: ElementNode,
47
+ accessor: Accessor<BorderProps | true | undefined>,
48
+ ) {
49
+ let border: ElementNode | null;
50
+ const owner = getOwner();
51
+
52
+ el.onFocusChanged = chainFunctions((f) => {
53
+ if (f) {
54
+ if (border) return;
55
+ runWithOwner(owner, () => {
56
+ const props = accessor();
57
+ border = borderComponent(
58
+ props === true || props === undefined ? ({} as NodeProps) : props,
59
+ ) as any as ElementNode;
60
+ insertNode(el, border);
61
+ border.render();
62
+ });
63
+ } else if (border) {
64
+ border.destroy();
65
+ el.removeChild(border!);
66
+ border = null;
67
+ }
68
+ }, el.onFocusChanged);
69
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Focus Stack Utility
3
+ *
4
+ * This utility manages a stack of focused elements, allowing for easy restoration
5
+ * of the previous focus state when navigating through a UI.
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * const { storeFocus, restoreFocus, clearFocusStack } = useFocusStack();
10
+ * storeFocus(element); // Store the currently focused element
11
+ * const success = restoreFocus(); // Restore the last stored focus and return success status
12
+ * clearFocusStack(); // Empty the focus stack
13
+ * ```
14
+ *
15
+ * Functions:
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.
18
+ * - `clearFocusStack()`: Empties the focus stack.
19
+ */
20
+ import * as s from 'solid-js';
21
+ import { type ElementNode } from '@solidtv/solid';
22
+
23
+ interface FocusStackContextType {
24
+ storeFocus: (element: ElementNode, prevElement?: ElementNode) => void;
25
+ restoreFocus: () => boolean;
26
+ clearFocusStack: () => void;
27
+ }
28
+
29
+ const FocusStackContext = s.createContext<FocusStackContextType | undefined>(undefined);
30
+
31
+ export function FocusStackProvider(props: { children: s.JSX.Element}) {
32
+ const [_focusStack, setFocusStack] = s.createSignal<ElementNode[]>([]);
33
+
34
+ function storeFocus(element: ElementNode, prevElement?: ElementNode) {
35
+ const elm = prevElement || element;
36
+ if (elm) {
37
+ setFocusStack(stack => [...stack, elm]);
38
+ }
39
+ }
40
+
41
+ function restoreFocus(): boolean {
42
+ let wasFocused = false;
43
+ setFocusStack((stack) => {
44
+ const prevElement = stack.pop();
45
+ if (prevElement && typeof prevElement.setFocus === 'function') {
46
+ prevElement.setFocus();
47
+ wasFocused = true;
48
+ }
49
+ return [...stack];
50
+ });
51
+ return wasFocused;
52
+ }
53
+
54
+ function clearFocusStack() {
55
+ setFocusStack([]);
56
+ }
57
+
58
+ return (
59
+ <FocusStackContext.Provider value={{ storeFocus, restoreFocus, clearFocusStack }}>
60
+ {props.children}
61
+ </FocusStackContext.Provider>
62
+ );
63
+ }
64
+
65
+ export function useFocusStack(autoClear = true) {
66
+ const context = s.useContext(FocusStackContext);
67
+ if (!context) {
68
+ throw new Error("useFocusStack must be used within a FocusStackProvider");
69
+ }
70
+
71
+ if (autoClear) {
72
+ s.onCleanup(() => {
73
+ // delay clearing the focus stack so restoreFocus can happen first.
74
+ setTimeout(() => context.clearFocusStack(), 5);
75
+ });
76
+ }
77
+
78
+ return context;
79
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ type Accessor,
3
+ batch,
4
+ type Setter,
5
+ createComputed,
6
+ createResource,
7
+ createSignal,
8
+ } from 'solid-js';
9
+
10
+ // Adopted from https://github.com/solidjs-community/solid-primitives/blob/main/packages/pagination/src/index.ts
11
+ // As we don't have intersection observer in Lightning, we can't use the original implementation
12
+
13
+ /**
14
+ * Provides an easy way to implement infinite items.
15
+ *
16
+ * ```ts
17
+ * const [items, loader, { item, setItem, setItems, end, setEnd }] = createInfiniteScroll(fetcher);
18
+ * ```
19
+ * @param fetcher `(item: number) => Promise<T[]>`
20
+ * @return `items()` is an accessor contains array of contents
21
+ * @property `items.loading` is a boolean indicator for the loading state
22
+ * @property `items.error` contains any error encountered
23
+ * @method `page` is an accessor that contains page number
24
+ * @method `setPage` allows to manually change the page number
25
+ * @method `setItems` allows to manually change the contents of the item
26
+ * @method `end` is a boolean indicator for end of the item
27
+ * @method `setEnd` allows to manually change the end
28
+ */
29
+ export function createInfiniteItems<T>(
30
+ fetcher: (item: number) => Promise<T[]>,
31
+ ): [
32
+ items: Accessor<T[]>,
33
+ options: {
34
+ page: Accessor<number>;
35
+ setPage: Setter<number>;
36
+ setItems: Setter<T[]>;
37
+ end: Accessor<boolean>;
38
+ setEnd: Setter<boolean>;
39
+ },
40
+ ] {
41
+ const [items, setItems] = createSignal<T[]>([]);
42
+ const [page, setPage] = createSignal(0);
43
+ const [end, setEnd] = createSignal(false);
44
+
45
+ const [contents] = createResource(page, fetcher);
46
+
47
+ createComputed(() => {
48
+ const content = contents();
49
+ if (!content) return;
50
+ batch(() => {
51
+ if (content.length === 0) setEnd(true);
52
+ setItems((p) => [...p, ...content]);
53
+ });
54
+ });
55
+
56
+ return [
57
+ items,
58
+ {
59
+ page,
60
+ setPage,
61
+ setItems,
62
+ end,
63
+ setEnd,
64
+ },
65
+ ];
66
+ }
@@ -0,0 +1,33 @@
1
+ import * as s from 'solid-js'
2
+ import * as lng from '@solidtv/solid'
3
+
4
+ interface Destroyable {
5
+ (props: lng.NodeProps): s.JSX.Element;
6
+ destroy: () => void;
7
+ }
8
+
9
+ export function createTag(children: s.JSX.Element): Destroyable {
10
+ const [texture, setTexture] = s.createSignal<lng.Texture | null | undefined>(null);
11
+ const Tag = <view
12
+ x={lng.rootNode.w - 1}
13
+ y={lng.rootNode.h - 1}
14
+ display='flex'
15
+ onLayout={(n) => {
16
+ if (n.preFlexwidth && n.width !== n.preFlexwidth) {
17
+ n.rtt = true;
18
+ setTimeout(() => setTexture(n.texture), 1);
19
+ }
20
+ }}
21
+ parent={lng.rootNode} children={children}
22
+ textureOptions={{
23
+ preventCleanup: true
24
+ }} /> as any as lng.ElementNode
25
+ Tag.render(false);
26
+
27
+ const TagComponent = (props: lng.NodeProps) => {
28
+ return <view color={0xffffffff} autosize {...props} texture={texture()} />;
29
+ };
30
+ TagComponent.destroy = () => Tag.destroy();
31
+
32
+ return TagComponent;
33
+ }
@@ -0,0 +1,37 @@
1
+ export * from './useFocusManager.js';
2
+ export * from './announcer/index.js';
3
+ export * from './createInfiniteItems.js';
4
+ export * from './borderBox.jsx';
5
+ export * from './useMouse.js';
6
+ export * from './portal.jsx';
7
+ export * from './Lazy.jsx';
8
+ export * from './LazyImport.js';
9
+ export * from './Image.jsx';
10
+ export * from './Visible.jsx';
11
+ export * from './router.js';
12
+ export * from './Column.jsx';
13
+ export * from './Row.jsx';
14
+ export * from './Grid.jsx';
15
+ export * from './FPSCounter.jsx';
16
+ export * from './FadeInOut.jsx';
17
+ export * from './Preserve.jsx';
18
+ export * from './Suspense.jsx';
19
+ export * from './Marquee.jsx';
20
+ export * from './createFocusStack.jsx';
21
+ export * from './useHold.js';
22
+ export * from './KeepAlive.jsx';
23
+ export * from './VirtualGrid.jsx';
24
+ export * from './Virtual.jsx';
25
+ export * from './utils/withScrolling.js';
26
+ export * from './createTag.jsx';
27
+ export {
28
+ type AnyFunction,
29
+ chainFunctions,
30
+ chainRefs,
31
+ } from './utils/chainFunctions.js';
32
+ export * from './utils/handleNavigation.js';
33
+ export { createSpriteMap, type SpriteDef } from './utils/createSpriteMap.js';
34
+ export { createBlurredImage } from './utils/createBlurredImage.js';
35
+
36
+ export type * from './types.js';
37
+ export type { KeyHandler } from '../core/focusManager.js';
@@ -0,0 +1,25 @@
1
+ import { rootNode, type ElementNode, insert } from '@solidtv/solid';
2
+ import { createEffect, createMemo, createRoot, createSignal, getOwner, JSX, onCleanup, runWithOwner } from 'solid-js';
3
+
4
+ export function Portal(props: { mount?: string; children: JSX.Element }) {
5
+ let content: undefined | (() => JSX.Element);
6
+ const mount = () => getMount(props.mount);
7
+ const owner = getOwner();
8
+
9
+ function getMount(mount?: string): ElementNode {
10
+ if (!mount) return rootNode;
11
+ return rootNode.searchChildrenById(mount) || rootNode;
12
+ }
13
+
14
+ createEffect(
15
+ () => {
16
+ const [clean, setClean] = createSignal(false);
17
+ const cleanup = () => setClean(true);
18
+ content || (content = runWithOwner(owner, () => createMemo(() => props.children)));
19
+ createRoot(dispose => insert(mount(), () => (!clean() ? content!() : dispose()), null));
20
+ onCleanup(cleanup);
21
+ }
22
+ );
23
+
24
+ return null;
25
+ }