react-native-roku 0.0.0-stage → 0.2.0-preview.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 (200) hide show
  1. package/CHANGELOG.md +318 -0
  2. package/CONTRIBUTING.md +34 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE.md +10 -0
  5. package/README.md +66 -2
  6. package/bin/react-native-roku.mjs +91 -0
  7. package/build/assets.cjs +311 -0
  8. package/build/assets.d.cts +50 -0
  9. package/build/compatibility.d.mts +40 -0
  10. package/build/compatibility.mjs +272 -0
  11. package/build/dev.d.mts +34 -0
  12. package/build/dev.mjs +297 -0
  13. package/build/devWorkspace.d.mts +11 -0
  14. package/build/devWorkspace.mjs +86 -0
  15. package/build/device.d.mts +47 -0
  16. package/build/device.mjs +310 -0
  17. package/build/environment.d.mts +29 -0
  18. package/build/environment.mjs +144 -0
  19. package/build/esbuild.d.mts +5 -0
  20. package/build/esbuild.mjs +118 -0
  21. package/build/fontVariants.d.mts +27 -0
  22. package/build/fontVariants.mjs +424 -0
  23. package/build/frontend.d.mts +52 -0
  24. package/build/frontend.mjs +75 -0
  25. package/build/identity.mjs +45 -0
  26. package/build/index.d.mts +22 -0
  27. package/build/index.mjs +87 -0
  28. package/build/intl.mjs +121 -0
  29. package/build/metro.cjs +38 -0
  30. package/build/metro.d.cts +37 -0
  31. package/build/metroFrontend.mjs +222 -0
  32. package/build/metroMetadata.mjs +119 -0
  33. package/build/metroModules.mjs +397 -0
  34. package/build/metroRefresh.d.mts +64 -0
  35. package/build/metroRefresh.mjs +346 -0
  36. package/build/metroTransformer.cjs +146 -0
  37. package/build/nativeTextMemo.mjs +296 -0
  38. package/build/nativewind.d.mts +9 -0
  39. package/build/nativewind.mjs +92 -0
  40. package/build/project.d.mts +111 -0
  41. package/build/project.mjs +615 -0
  42. package/build/reactCompiler.mjs +113 -0
  43. package/build/reactProfile.cjs +35 -0
  44. package/build/refreshRuntime.mjs +187 -0
  45. package/build/refreshSourceMap.mjs +53 -0
  46. package/build/release.mjs +99 -0
  47. package/build/resolution.d.mts +3 -0
  48. package/build/resolution.mjs +25 -0
  49. package/build/surfaces.d.mts +1 -0
  50. package/build/surfaces.mjs +42 -0
  51. package/build/testing/node.d.mts +29 -0
  52. package/build/testing/node.mjs +106 -0
  53. package/build/yoga.d.mts +8 -0
  54. package/build/yoga.mjs +186 -0
  55. package/compatibility/public-api.json +327 -0
  56. package/compatibility/registry.json +2258 -0
  57. package/config/release.json +15 -0
  58. package/config/toolchain.json +34 -0
  59. package/docs/compatibility.md +813 -0
  60. package/docs/getting-started.md +460 -0
  61. package/docs/maintenance.md +362 -0
  62. package/docs/qualification.md +241 -0
  63. package/docs/standalone-testing.md +56 -0
  64. package/examples/hello-roku/README.md +35 -0
  65. package/examples/hello-roku/package.template.json +31 -0
  66. package/examples/hello-roku/pnpm-workspace.yaml +11 -0
  67. package/examples/hello-roku/roku.config.json +22 -0
  68. package/examples/hello-roku/src/App.tsx +54 -0
  69. package/examples/hello-roku/src/Catalog.tsx +200 -0
  70. package/examples/hello-roku/src/assets.d.ts +16 -0
  71. package/examples/hello-roku/src/catalog-cover.png +0 -0
  72. package/examples/hello-roku/tsconfig.json +1 -0
  73. package/examples/hello-roku/tsconfig.react.json +1 -0
  74. package/native/components/RNRAppControl.brs +215 -0
  75. package/native/components/RNRAppControl.xml +13 -0
  76. package/native/components/RNRDeviceFacts.brs +19 -0
  77. package/native/components/RNRDeviceFacts.xml +9 -0
  78. package/native/components/RNRDeviceFactsTask.brs +74 -0
  79. package/native/components/RNRDeviceFactsTask.xml +9 -0
  80. package/native/components/RNRTextRaster.brs +15 -0
  81. package/native/components/RNRTextRaster.xml +9 -0
  82. package/native/components/RNRTextRasterTask.brs +77 -0
  83. package/native/components/RNRTextRasterTask.xml +9 -0
  84. package/native/manifest.json +7 -0
  85. package/package.json +183 -3
  86. package/src/animation/clock.ts +10 -0
  87. package/src/animation/derivedValue.ts +163 -0
  88. package/src/animation/legacyAnimated.ts +255 -0
  89. package/src/animation/reanimated.ts +243 -0
  90. package/src/animation/sharedValue.ts +285 -0
  91. package/src/animation/worklets.ts +23 -0
  92. package/src/application/AppRegistry.ts +31 -0
  93. package/src/application/mountApplication.ts +136 -0
  94. package/src/graphics/BitmapLayer.tsx +68 -0
  95. package/src/graphics/RoundedBorder.tsx +116 -0
  96. package/src/graphics/TextRasterCache.ts +259 -0
  97. package/src/graphics/gradient.ts +37 -0
  98. package/src/graphics/inlineRaster.ts +85 -0
  99. package/src/graphics/png.ts +77 -0
  100. package/src/graphics/rasterPixels.ts +89 -0
  101. package/src/graphics/surfaces.ts +105 -0
  102. package/src/graphics/textRaster.types.ts +60 -0
  103. package/src/graphics/textRasterGeometry.ts +116 -0
  104. package/src/host/host.types.ts +57 -0
  105. package/src/index.ts +22 -0
  106. package/src/interop/nativewind.ts +2 -0
  107. package/src/layout/FontResources.ts +252 -0
  108. package/src/layout/affine.ts +89 -0
  109. package/src/layout/flexLayout.ts +398 -0
  110. package/src/layout/fontFaces.d.mts +19 -0
  111. package/src/layout/fontFaces.mjs +85 -0
  112. package/src/layout/fontVariants.d.mts +2 -0
  113. package/src/layout/fontVariants.mjs +8 -0
  114. package/src/layout/inlineParagraph.ts +158 -0
  115. package/src/layout/inlineText.ts +68 -0
  116. package/src/layout/layoutReuse.ts +117 -0
  117. package/src/layout/nativeNodeFields.ts +179 -0
  118. package/src/layout/preparedFields.ts +78 -0
  119. package/src/layout/textLayout.ts +138 -0
  120. package/src/layout/transform.ts +113 -0
  121. package/src/media/SceneGraphAudio.ts +161 -0
  122. package/src/media/SceneGraphVideo.ts +167 -0
  123. package/src/media/audioSession.ts +84 -0
  124. package/src/media/index.ts +2 -0
  125. package/src/media/videoErrorDetails.ts +40 -0
  126. package/src/media/videoSession.ts +136 -0
  127. package/src/navigation/RouterStore.ts +244 -0
  128. package/src/navigation/expoRouter.ts +115 -0
  129. package/src/react-native/NativeInput.ts +494 -0
  130. package/src/react-native/NativeSystemState.ts +95 -0
  131. package/src/react-native/accessibility.ts +265 -0
  132. package/src/react-native/activityIndicator.ts +72 -0
  133. package/src/react-native/compilerPressable.ts +26 -0
  134. package/src/react-native/createNativeRoot.ts +2126 -0
  135. package/src/react-native/directionalFocus.ts +55 -0
  136. package/src/react-native/environment.ts +275 -0
  137. package/src/react-native/flatList.ts +1001 -0
  138. package/src/react-native/flatListViewability.ts +231 -0
  139. package/src/react-native/focusEvents.ts +85 -0
  140. package/src/react-native/image.ts +247 -0
  141. package/src/react-native/index.ts +54 -0
  142. package/src/react-native/interactionManager.ts +76 -0
  143. package/src/react-native/keyboard.ts +60 -0
  144. package/src/react-native/linearGradient.ts +94 -0
  145. package/src/react-native/modal.tsx +148 -0
  146. package/src/react-native/nativeHostContext.ts +80 -0
  147. package/src/react-native/nativeModules.ts +86 -0
  148. package/src/react-native/nativeRoot.types.ts +22 -0
  149. package/src/react-native/nativeViewHandle.ts +191 -0
  150. package/src/react-native/nativewindPressable.ts +38 -0
  151. package/src/react-native/panResponder.ts +73 -0
  152. package/src/react-native/primitives.ts +685 -0
  153. package/src/react-native/safeArea.ts +76 -0
  154. package/src/react-native/scrollView.ts +289 -0
  155. package/src/react-native/styleInterop.ts +8 -0
  156. package/src/react-native/styleSheet.ts +54 -0
  157. package/src/react-native/textInput.ts +334 -0
  158. package/src/react-native/unsupported.ts +25 -0
  159. package/src/renderer/SceneRoot.ts +1006 -0
  160. package/src/scene/SdkDeviceFacts.ts +151 -0
  161. package/src/scene/SdkDeviceServices.ts +72 -0
  162. package/src/scene/SdkSceneGraph.ts +124 -0
  163. package/src/scene/SdkTextEntry.ts +321 -0
  164. package/src/scene/SdkTextMetrics.ts +136 -0
  165. package/src/scene/SdkTextRasterTransport.ts +191 -0
  166. package/src/scene/SdkWebTransport.ts +122 -0
  167. package/src/scene/createRokuHost.ts +213 -0
  168. package/src/scene/sceneGraph.types.ts +38 -0
  169. package/src/services/DeviceServices.ts +53 -0
  170. package/src/services/RegistryStorage.ts +85 -0
  171. package/src/services/RokuKeySession.ts +29 -0
  172. package/src/services/asyncStorage.ts +23 -0
  173. package/src/services/base64.ts +52 -0
  174. package/src/services/crypto.ts +18 -0
  175. package/src/services/expoConstants.ts +11 -0
  176. package/src/services/expoLinking.ts +12 -0
  177. package/src/services/expoStatusBar.ts +4 -0
  178. package/src/services/installWebRuntime.ts +105 -0
  179. package/src/services/intlEnglish.ts +54 -0
  180. package/src/services/languageRuntime.ts +65 -0
  181. package/src/services/nativeTimers.ts +96 -0
  182. package/src/services/secureStore.ts +23 -0
  183. package/src/services/textEntryRequest.ts +22 -0
  184. package/src/services/utf8.ts +57 -0
  185. package/src/services/webRuntime.ts +346 -0
  186. package/src/testing/CanvasResources.ts +141 -0
  187. package/src/testing/CanvasSceneGraph.ts +496 -0
  188. package/src/testing/CanvasTextEntry.ts +237 -0
  189. package/src/testing/PreviewTextObservations.ts +82 -0
  190. package/src/testing/RecordingSceneGraph.ts +136 -0
  191. package/src/types/normalize-colors.d.ts +4 -0
  192. package/src/vector/dynamicSvg.tsx +226 -0
  193. package/src/vector/svg.ts +222 -0
  194. package/src/vector/svg.types.ts +4 -0
  195. package/src/vector/svgElements.ts +58 -0
  196. package/src/vector/svgKey.d.mts +4 -0
  197. package/src/vector/svgKey.mjs +16 -0
  198. package/src/vector/svgPath.ts +157 -0
  199. package/src/vector/svgPixels.ts +133 -0
  200. package/tsconfig.consumer.json +29 -0
@@ -0,0 +1,53 @@
1
+ export interface DeviceStorage {
2
+ read(section: string, key: string): Promise<string | null>;
3
+ write(section: string, key: string, value: string | null): Promise<void>;
4
+ }
5
+ export interface TextEntryRequest {
6
+ readonly title: string;
7
+ readonly text: string;
8
+ readonly secure: boolean;
9
+ readonly domain: "generic" | "numeric" | "email" | "password";
10
+ readonly maxLength: number;
11
+ }
12
+ export interface TextEntrySession {
13
+ /** Null ends editing without submission. Previously observed text changes
14
+ * are not rolled back by cancellation. */
15
+ readonly result: Promise<string | null>;
16
+ /** True only for a port-observed dialog dismissal. Logical cancellation,
17
+ * failed admission, disposal and missing acknowledgement settle false.
18
+ * Omit when the port cannot supply native/DOM closure observations. */
19
+ readonly closed?: Promise<boolean>;
20
+ /** Replace an active draft without submitting it. False means the editor has
21
+ * already closed; callers must fence its pending result. Optional for older
22
+ * ports, which cannot admit active controlled/imperative text updates. */
23
+ setText?(text: string): boolean;
24
+ /** Observe user edits while the dialog is open. A late subscriber receives
25
+ * the latest observed draft. Programmatic setText does not publish an edit.
26
+ * Omit only for legacy ports that expose accepted text at submission. */
27
+ subscribeText?(listener: (text: string) => void): () => void;
28
+ /** Observe the editor's actual selection in UTF-16 offsets. Replay the latest
29
+ * observation to a late subscriber; never infer a cursor from a text update.
30
+ * Native keyboards may expose only a collapsed caret, while DOM ports can
31
+ * report ranges. Omit when the port cannot observe selection. */
32
+ subscribeSelection?(
33
+ listener: (selection: Readonly<{ start: number; end: number }>) => void,
34
+ ): () => void;
35
+ close(): void;
36
+ }
37
+ export interface TextEntryPort {
38
+ open(request: TextEntryRequest): TextEntrySession;
39
+ }
40
+ export interface DeviceServices {
41
+ readonly textEntry?: TextEntryPort;
42
+ /** Raw platform facts; shared playback code owns capability policy. */
43
+ readonly nativeCapabilities?: {
44
+ probe(request: Readonly<Record<string, unknown>>): Promise<unknown>;
45
+ addListener(
46
+ name: string,
47
+ listener: (event: Readonly<Record<string, unknown>>) => void,
48
+ ): { remove(): void };
49
+ };
50
+ readonly storage: DeviceStorage;
51
+ randomUUID(): string;
52
+ randomBytes(length: number): Uint8Array;
53
+ }
@@ -0,0 +1,85 @@
1
+ import { RokuHostError } from "../scene/sceneGraph.types";
2
+ import type { DeviceStorage } from "./DeviceServices";
3
+ export interface RegistrySectionPort {
4
+ read(key: string): string | null;
5
+ write(key: string, value: string): boolean;
6
+ delete(key: string): boolean;
7
+ exists(key: string): boolean;
8
+ }
9
+ export interface RegistryPort {
10
+ create(section: string): RegistrySectionPort;
11
+ flush(): Promise<boolean>;
12
+ }
13
+ export interface SecretCodec {
14
+ encode(value: string): Promise<string>;
15
+ decode(value: string): Promise<string>;
16
+ }
17
+ /** Serialized writes resolve only after the native registry confirms its durable flush. */
18
+ export class RegistryStorage implements DeviceStorage {
19
+ private pending: Promise<unknown> = Promise.resolve();
20
+ private failed = false;
21
+ constructor(
22
+ private readonly registry: RegistryPort,
23
+ private readonly secrets?: SecretCodec,
24
+ private readonly prefix = "react-native-roku",
25
+ ) {}
26
+ read(section: string, key: string): Promise<string | null> {
27
+ return this.enqueue(async () => {
28
+ const value = this.section(section).read(key);
29
+ return value == null ? null : section === "secure" ? this.codec().decode(value) : value;
30
+ });
31
+ }
32
+ write(section: string, key: string, value: string | null): Promise<void> {
33
+ return this.enqueue(async () => {
34
+ const port = this.section(section),
35
+ previous = port.read(key);
36
+ if (value === null && previous === null) return;
37
+ let encoded = value;
38
+ if (value !== null && section === "secure") encoded = await this.codec().encode(value);
39
+ if (encoded === previous) return;
40
+ const apply = (next: string | null) =>
41
+ next === null ? !port.exists(key) || port.delete(key) : port.write(key, next);
42
+ let failure: unknown;
43
+ try {
44
+ if (!apply(encoded) || !(await this.registry.flush()))
45
+ throw new RokuHostError(
46
+ "C21_STORAGE_FLUSH",
47
+ "The native registry did not confirm persistence",
48
+ );
49
+ return;
50
+ } catch (error) {
51
+ failure = error;
52
+ }
53
+ try {
54
+ if (!apply(previous) || !(await this.registry.flush()))
55
+ throw new Error("rollback not confirmed");
56
+ } catch {
57
+ this.failed = true;
58
+ throw new RokuHostError(
59
+ "C21_STORAGE_RECOVERY",
60
+ "A failed registry write could not be rolled back; reopen the app before using persistent state",
61
+ );
62
+ }
63
+ throw failure;
64
+ });
65
+ }
66
+ private section(name: string): RegistrySectionPort {
67
+ if (!/^[a-z][a-z0-9-]*$/.test(name))
68
+ throw new RokuHostError("C21_STORAGE_SECTION", "Storage section must be a stable namespace");
69
+ return this.registry.create(`${this.prefix}-${name}`);
70
+ }
71
+ private codec(): SecretCodec {
72
+ if (!this.secrets)
73
+ throw new RokuHostError("C21_SECRET_STORAGE", "Device credential encryption is unavailable");
74
+ return this.secrets;
75
+ }
76
+ private enqueue<T>(work: () => Promise<T>): Promise<T> {
77
+ const operation = this.pending.then(() => {
78
+ if (this.failed)
79
+ throw new RokuHostError("C21_STORAGE_RECOVERY", "Persistent storage awaits app recovery");
80
+ return work();
81
+ });
82
+ this.pending = operation.catch(() => undefined);
83
+ return operation;
84
+ }
85
+ }
@@ -0,0 +1,29 @@
1
+ import type { NativeRemoteEvent, NativeRemoteKey } from "../react-native/NativeInput";
2
+ const keys: Readonly<Record<string, NativeRemoteKey>> = {
3
+ up: "up",
4
+ down: "down",
5
+ left: "left",
6
+ right: "right",
7
+ OK: "select",
8
+ enter: "select",
9
+ back: "back",
10
+ play: "playPause",
11
+ rewind: "rewind",
12
+ fastforward: "fastForward",
13
+ options: "options",
14
+ };
15
+ /** Firmware reports repeated presses without a separate repeat flag. */
16
+ export class RokuKeySession {
17
+ private readonly held = new Set<NativeRemoteKey>();
18
+ handle(key: string, press: boolean, dispatch: (event: NativeRemoteEvent) => boolean): boolean {
19
+ const mapped = keys[key];
20
+ if (!mapped) return false;
21
+ const phase = press ? (this.held.has(mapped) ? "repeat" : "down") : "up";
22
+ if (press) this.held.add(mapped);
23
+ else this.held.delete(mapped);
24
+ return dispatch({ key: mapped, phase });
25
+ }
26
+ reset(): void {
27
+ this.held.clear();
28
+ }
29
+ }
@@ -0,0 +1,23 @@
1
+ import { nativeDeviceServices } from "../react-native/environment";
2
+ const section = "preferences";
3
+ export const getItem = async (key: string) => nativeDeviceServices().storage.read(section, key);
4
+ export const setItem = async (key: string, value: string) =>
5
+ nativeDeviceServices().storage.write(section, key, value);
6
+ export const removeItem = async (key: string) =>
7
+ nativeDeviceServices().storage.write(section, key, null);
8
+ export const multiGet = (keys: readonly string[]) =>
9
+ Promise.all(keys.map(async (key) => [key, await getItem(key)] as [string, string | null]));
10
+ export async function multiSet(entries: readonly (readonly [string, string])[]) {
11
+ for (const [key, value] of entries) await setItem(key, value);
12
+ }
13
+ export async function multiRemove(keys: readonly string[]) {
14
+ for (const key of keys) await removeItem(key);
15
+ }
16
+ export default Object.freeze({
17
+ getItem,
18
+ setItem,
19
+ removeItem,
20
+ multiGet,
21
+ multiSet,
22
+ multiRemove,
23
+ });
@@ -0,0 +1,52 @@
1
+ import { RokuHostError } from "../scene/sceneGraph.types";
2
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3
+ export function encodeBase64(bytes: Uint8Array): string {
4
+ const chunks: string[] = [];
5
+ let part = "";
6
+ for (let index = 0; index < bytes.length; index += 3) {
7
+ const a = bytes[index],
8
+ b = bytes[index + 1],
9
+ c = bytes[index + 2],
10
+ value = (a << 16) | ((b ?? 0) << 8) | (c ?? 0);
11
+ part +=
12
+ alphabet[value >>> 18] +
13
+ alphabet[(value >>> 12) & 63] +
14
+ (b == null ? "=" : alphabet[(value >>> 6) & 63]) +
15
+ (c == null ? "=" : alphabet[value & 63]);
16
+ if (part.length >= 8192) {
17
+ chunks.push(part);
18
+ part = "";
19
+ }
20
+ }
21
+ chunks.push(part);
22
+ return chunks.join("");
23
+ }
24
+ export function decodeBase64(value: string): Uint8Array {
25
+ if (value.length % 4)
26
+ throw new RokuHostError("C04_RASTER_ENCODING", "Invalid raster base64 encoding");
27
+ const result = new Uint8Array(
28
+ (value.length / 4) * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0),
29
+ );
30
+ let cursor = 0;
31
+ for (let index = 0; index < value.length; index += 4) {
32
+ const a = alphabet.indexOf(value[index]),
33
+ b = alphabet.indexOf(value[index + 1]),
34
+ c = alphabet.indexOf(value[index + 2]),
35
+ d = alphabet.indexOf(value[index + 3]);
36
+ const last = index + 4 === value.length;
37
+ if (
38
+ a < 0 ||
39
+ b < 0 ||
40
+ (c < 0 && !(last && value[index + 2] === "=" && value[index + 3] === "=")) ||
41
+ (d < 0 && !(last && value[index + 3] === "="))
42
+ )
43
+ throw new RokuHostError("C04_RASTER_ENCODING", "Invalid raster base64 encoding");
44
+ if ((c < 0 && b & 15) || (d < 0 && c >= 0 && c & 3))
45
+ throw new RokuHostError("C04_RASTER_ENCODING", "Noncanonical raster base64 padding");
46
+ const bits = (a << 18) | (b << 12) | (Math.max(0, c) << 6) | Math.max(0, d);
47
+ if (cursor < result.length) result[cursor++] = bits >>> 16;
48
+ if (cursor < result.length) result[cursor++] = bits >>> 8;
49
+ if (cursor < result.length) result[cursor++] = bits;
50
+ }
51
+ return result;
52
+ }
@@ -0,0 +1,18 @@
1
+ import { nativeDeviceServices } from "../react-native/environment";
2
+ import { RokuHostError } from "../scene/sceneGraph.types";
3
+ export const randomUUID = () => nativeDeviceServices().randomUUID();
4
+ export function getRandomBytes(length: number): Uint8Array {
5
+ if (!Number.isSafeInteger(length) || length < 0 || length > 65_536)
6
+ throw new RokuHostError(
7
+ "C21_RANDOM_LENGTH",
8
+ "Secure random requests must be within 0..65536 bytes",
9
+ );
10
+ const result = nativeDeviceServices().randomBytes(length);
11
+ if (!(result instanceof Uint8Array) || result.length !== length)
12
+ throw new RokuHostError(
13
+ "C21_RANDOM_HOST",
14
+ "The native random port returned an invalid byte count",
15
+ );
16
+ return result;
17
+ }
18
+ export const getRandomBytesAsync = async (length: number) => getRandomBytes(length);
@@ -0,0 +1,11 @@
1
+ /** This package's authored manifest metadata; no Expo native container is present. */
2
+ export default Object.freeze({
3
+ nativeAppVersion: "0.1.0",
4
+ nativeBuildVersion: "0",
5
+ expoConfig: Object.freeze({
6
+ name: "React Native Roku",
7
+ version: "0.1.0",
8
+ extra: Object.freeze({}),
9
+ }),
10
+ appOwnership: null,
11
+ });
@@ -0,0 +1,12 @@
1
+ import { RokuHostError } from "../scene/sceneGraph.types";
2
+ // The beta launcher currently supplies application routes directly. No native URL source is installed.
3
+ export const getInitialURL = async (): Promise<null> => null;
4
+ export const useLinkingURL = (): null => null;
5
+ export const useURL = useLinkingURL;
6
+ export const canOpenURL = async (): Promise<boolean> => false;
7
+ export async function openURL(): Promise<never> {
8
+ throw new RokuHostError(
9
+ "C09_EXTERNAL_URL",
10
+ "The Roku launcher has no external URL capability installed",
11
+ );
12
+ }
@@ -0,0 +1,4 @@
1
+ /** SceneGraph occupies the entire application canvas; Roku has no app status bar. */
2
+ export function StatusBar(): null {
3
+ return null;
4
+ }
@@ -0,0 +1,105 @@
1
+ import { URL, URLSearchParams } from "react-native-url-polyfill/js/URL";
2
+ import { installLanguageRuntime } from "./languageRuntime";
3
+ import {
4
+ PortableAbortController,
5
+ PortableAbortSignal,
6
+ PortableDOMException,
7
+ PortableHeaders,
8
+ PortableRequest,
9
+ PortableResponse,
10
+ createPortableFetch,
11
+ type WebTransport,
12
+ } from "./webRuntime";
13
+ export { createPortableFetch } from "./webRuntime";
14
+ export type { WebTransport, WebRequest, WebResponse, WebRedirectMode } from "./webRuntime";
15
+
16
+ interface GlobalLease {
17
+ readonly value: unknown;
18
+ }
19
+ const owners = new WeakMap<
20
+ object,
21
+ Map<
22
+ string,
23
+ {
24
+ previous?: PropertyDescriptor;
25
+ leases: GlobalLease[];
26
+ }
27
+ >
28
+ >();
29
+
30
+ /** Install before the product graph is initialized. Returning a lease also
31
+ * lets host qualification restore its original globals without leaking state. */
32
+ export function installWebRuntime(
33
+ transport?: WebTransport,
34
+ target: Record<string, unknown> = globalThis as unknown as Record<string, unknown>,
35
+ ): () => void {
36
+ const releaseLanguage = installLanguageRuntime();
37
+ const values: Record<string, unknown> = {
38
+ URL,
39
+ URLSearchParams,
40
+ Headers: PortableHeaders,
41
+ Request: PortableRequest,
42
+ Response: PortableResponse,
43
+ DOMException: PortableDOMException,
44
+ AbortController: PortableAbortController,
45
+ AbortSignal: PortableAbortSignal,
46
+ };
47
+ if (transport) values.fetch = createPortableFetch(transport);
48
+ let entries = owners.get(target);
49
+ if (!entries) owners.set(target, (entries = new Map()));
50
+ const releases = new Set<() => void>([releaseLanguage]);
51
+ const release = () => {
52
+ if (!releases.size) return;
53
+ const failures: unknown[] = [];
54
+ for (const work of [...releases]) {
55
+ try {
56
+ work();
57
+ releases.delete(work);
58
+ } catch (error) {
59
+ failures.push(error);
60
+ }
61
+ }
62
+ if (!entries.size && owners.get(target) === entries) owners.delete(target);
63
+ if (failures.length) throw failures[0];
64
+ };
65
+ try {
66
+ for (const [key, value] of Object.entries(values)) {
67
+ const entry = entries.get(key) ?? {
68
+ previous: Object.getOwnPropertyDescriptor(target, key),
69
+ leases: [],
70
+ };
71
+ const lease = { value };
72
+ Object.defineProperty(target, key, { value, writable: true, configurable: true });
73
+ entries.set(key, entry);
74
+ entry.leases.push(lease);
75
+ releases.add(() => {
76
+ const index = entry.leases.indexOf(lease);
77
+ if (index < 0) return;
78
+ if (
79
+ index === entry.leases.length - 1 &&
80
+ Object.getOwnPropertyDescriptor(target, key)?.value === value
81
+ ) {
82
+ const previous = entry.leases[index - 1];
83
+ if (previous)
84
+ Object.defineProperty(target, key, {
85
+ value: previous.value,
86
+ writable: true,
87
+ configurable: true,
88
+ });
89
+ else if (entry.previous) Object.defineProperty(target, key, entry.previous);
90
+ else Reflect.deleteProperty(target, key);
91
+ }
92
+ entry.leases.splice(index, 1);
93
+ if (!entry.leases.length) entries.delete(key);
94
+ });
95
+ }
96
+ } catch (error) {
97
+ try {
98
+ release();
99
+ } catch {
100
+ /* Preserve the installation error. */
101
+ }
102
+ throw error;
103
+ }
104
+ return release;
105
+ }
@@ -0,0 +1,54 @@
1
+ // Opt-in English locale data. Dependency order is part of the FormatJS contract.
2
+ import "@formatjs/intl-getcanonicallocales/polyfill.js";
3
+ import "@formatjs/intl-locale/polyfill.js";
4
+ import "@formatjs/intl-pluralrules/polyfill.js";
5
+ import "@formatjs/intl-pluralrules/locale-data/en.js";
6
+ import "@formatjs/intl-numberformat/polyfill.js";
7
+ import "@formatjs/intl-numberformat/locale-data/en.js";
8
+ import "@formatjs/intl-datetimeformat/polyfill.js";
9
+ import { shouldPolyfill as shouldPolyfillCollator } from "@formatjs/intl-collator/should-polyfill.js";
10
+ import { RokuHostError } from "../scene/sceneGraph.types";
11
+
12
+ // Upstream locale/collation modules decode data before checking native support.
13
+ // Keep those modules lazy so a native host preserves its constructors without
14
+ // allocating fallback tables. A missing runtime receives the same full data.
15
+ const dateTimeFormat = Intl.DateTimeFormat as typeof Intl.DateTimeFormat & {
16
+ readonly __addLocaleData?: unknown;
17
+ };
18
+ if (typeof dateTimeFormat.__addLocaleData === "function") {
19
+ require("@formatjs/intl-datetimeformat/locale-data/en.js");
20
+ require("@formatjs/intl-datetimeformat/add-golden-tz.js");
21
+ }
22
+ if (shouldPolyfillCollator()) require("@formatjs/intl-collator/polyfill.js");
23
+
24
+ // Roku names that are not IANA identifiers; standard aliases pass through the
25
+ // formatter's own validation. Never infer a zone from a model or current offset.
26
+ const timeZones: Readonly<Record<string, string>> = Object.freeze({
27
+ "US/Puerto Rico-Virgin Islands": "America/Puerto_Rico",
28
+ "US/Guam": "Pacific/Guam",
29
+ "US/Samoa": "Pacific/Pago_Pago",
30
+ });
31
+
32
+ /** Call before application formatting. Native Intl keeps its own system zone;
33
+ * the polyfill requires an explicit observed device zone or fixture zone. */
34
+ export function configureIntlTimeZone(timeZone?: string): {
35
+ source: "native" | "polyfill";
36
+ timeZone: string;
37
+ } {
38
+ const formatter = Intl.DateTimeFormat as typeof Intl.DateTimeFormat & {
39
+ __setDefaultTimeZone?: (zone: string) => void;
40
+ };
41
+ if (typeof formatter.__setDefaultTimeZone !== "function")
42
+ return { source: "native", timeZone: new formatter().resolvedOptions().timeZone };
43
+ if (!timeZone?.trim())
44
+ throw new RokuHostError(
45
+ "C23_TIME_ZONE",
46
+ "Intl requires an observed device time zone before application startup",
47
+ );
48
+ const zone = timeZones[timeZone.trim()] ?? timeZone.trim();
49
+ // Validate before changing the process default so a rejected observation cannot
50
+ // corrupt existing formatting. The constructor also canonicalizes aliases.
51
+ const canonical = new formatter("en", { timeZone: zone }).resolvedOptions().timeZone;
52
+ formatter.__setDefaultTimeZone(canonical);
53
+ return { source: "polyfill", timeZone: canonical };
54
+ }
@@ -0,0 +1,65 @@
1
+ /** Small standard-language gaps used by the shared graph on older Hermes VMs. */
2
+ export function relativeIndex(this: unknown, index: number) {
3
+ if (this == null) throw new TypeError("at requires a receiver");
4
+ const receiver = Object(this) as { length: unknown; [key: number]: unknown };
5
+ const length = Math.min(
6
+ Math.max(Math.trunc(+(receiver.length as number)) || 0, 0),
7
+ Number.MAX_SAFE_INTEGER,
8
+ );
9
+ const integer = Math.trunc(+index) || 0;
10
+ const position = integer < 0 ? length + integer : integer;
11
+ return position >= 0 && position < length ? receiver[position] : undefined;
12
+ }
13
+ function stringAt(this: unknown, index: number) {
14
+ if (this == null) throw new TypeError("at requires a receiver");
15
+ return relativeIndex.call(`${this}`, index);
16
+ }
17
+ function hasOwn(value: unknown, key: PropertyKey) {
18
+ if (value == null) throw new TypeError("hasOwn requires an object");
19
+ return Object.prototype.hasOwnProperty.call(value, key);
20
+ }
21
+ const leases = new WeakMap<
22
+ object,
23
+ Map<PropertyKey, { references: number; value: unknown; previous?: PropertyDescriptor }>
24
+ >();
25
+
26
+ /** Native implementations win. Missing methods are leased across mounted hosts. */
27
+ export function installLanguageRuntime(
28
+ target: Pick<typeof globalThis, "Array" | "String" | "Object"> = globalThis,
29
+ ) {
30
+ const releases: Array<() => void> = [];
31
+ for (const [owner, key, value] of [
32
+ [target.Array.prototype, "at", relativeIndex],
33
+ [target.String.prototype, "at", stringAt],
34
+ [target.Object, "hasOwn", hasOwn],
35
+ ] as const) {
36
+ let entries = leases.get(owner),
37
+ entry = entries?.get(key);
38
+ if (!entry && typeof owner[key as keyof typeof owner] === "function") continue;
39
+ if (!entry) {
40
+ const previous = Object.getOwnPropertyDescriptor(owner, key);
41
+ Object.defineProperty(owner, key, {
42
+ value,
43
+ writable: true,
44
+ configurable: true,
45
+ });
46
+ if (!entries) leases.set(owner, (entries = new Map()));
47
+ entries.set(key, (entry = { references: 0, value, previous }));
48
+ }
49
+ entry.references++;
50
+ releases.push(() => {
51
+ if (--entry!.references) return;
52
+ if (Object.getOwnPropertyDescriptor(owner, key)?.value === entry!.value) {
53
+ if (entry!.previous) Object.defineProperty(owner, key, entry!.previous);
54
+ else Reflect.deleteProperty(owner, key);
55
+ }
56
+ entries!.delete(key);
57
+ });
58
+ }
59
+ let active = true;
60
+ return () => {
61
+ if (!active) return;
62
+ active = false;
63
+ for (const release of releases) release();
64
+ };
65
+ }
@@ -0,0 +1,96 @@
1
+ /** JS turn scheduling only; these callbacks never acknowledge native presentation. */
2
+ const normalizedDisposers = new WeakSet<Function>();
3
+ const intervals = new Map<number, { timer?: ReturnType<typeof setTimeout> }>();
4
+ let intervalSequence = 0;
5
+ export function installNativeAnimationFrames(): void {
6
+ if (typeof Promise.allSettled !== "function")
7
+ Object.defineProperty(Promise, "allSettled", {
8
+ configurable: true,
9
+ writable: true,
10
+ value: async (values: Iterable<unknown>) =>
11
+ Promise.all(
12
+ Array.from(values, (value) =>
13
+ Promise.resolve(value).then(
14
+ (value) => ({ status: "fulfilled", value }),
15
+ (reason) => ({ status: "rejected", reason }),
16
+ ),
17
+ ),
18
+ ),
19
+ });
20
+ if (typeof globalThis.queueMicrotask !== "function")
21
+ globalThis.queueMicrotask = (callback) => {
22
+ if (typeof callback !== "function") throw new TypeError("A microtask requires a callback");
23
+ void Promise.resolve()
24
+ .then(callback)
25
+ .catch((error) =>
26
+ setTimeout(() => {
27
+ throw error;
28
+ }, 0),
29
+ );
30
+ };
31
+ if (typeof globalThis.setInterval !== "function") {
32
+ const nativeClearInterval = globalThis.clearInterval;
33
+ globalThis.setInterval = ((
34
+ callback: (...args: unknown[]) => void,
35
+ milliseconds = 0,
36
+ ...args: unknown[]
37
+ ) => {
38
+ if (typeof callback !== "function") throw new TypeError("Intervals require a callback");
39
+ const id = --intervalSequence,
40
+ entry: { timer?: ReturnType<typeof setTimeout> } = {};
41
+ intervals.set(id, entry);
42
+ const delay = Math.max(1, Math.min(2_147_483_647, Number(milliseconds) || 0));
43
+ const tick = () => {
44
+ if (intervals.get(id) !== entry) return;
45
+ try {
46
+ callback(...args);
47
+ } finally {
48
+ if (intervals.get(id) === entry) entry.timer = setTimeout(tick, delay);
49
+ }
50
+ };
51
+ entry.timer = setTimeout(tick, delay);
52
+ return id;
53
+ }) as typeof setInterval;
54
+ globalThis.clearInterval = ((handle) => {
55
+ const entry = intervals.get(handle as number);
56
+ if (entry) {
57
+ intervals.delete(handle as number);
58
+ clearTimeout(entry.timer);
59
+ } else if (handle != null && typeof nativeClearInterval === "function")
60
+ (nativeClearInterval as (value: unknown) => void)(handle);
61
+ else if (handle != null) (clearTimeout as (value: unknown) => void)(handle);
62
+ }) as typeof clearInterval;
63
+ }
64
+ if (typeof globalThis.performance === "undefined") {
65
+ const origin = Date.now();
66
+ let last = 0;
67
+ // Elapsed JS scheduling clock only, not native frame or device timing.
68
+ globalThis.performance = {
69
+ timeOrigin: origin,
70
+ now: () => (last = Math.max(last, Date.now() - origin)),
71
+ } as Performance;
72
+ }
73
+ for (const name of ["clearTimeout", "clearInterval"] as const) {
74
+ const native = globalThis[name];
75
+ if (typeof native !== "function" || normalizedDisposers.has(native)) continue;
76
+ // Browser/RN callers routinely clear an optional timer. Bare Hermes and
77
+ // firmware bindings accept a numeric handle and may throw for undefined.
78
+ const dispose = (handle: Parameters<typeof clearTimeout>[0]) => {
79
+ const interval = intervals.get(handle as number);
80
+ if (interval) {
81
+ intervals.delete(handle as number);
82
+ globalThis.clearTimeout(interval.timer);
83
+ } else if (handle != null) native(handle);
84
+ };
85
+ normalizedDisposers.add(dispose);
86
+ globalThis[name] = dispose as typeof native;
87
+ }
88
+ if (typeof globalThis.requestAnimationFrame !== "function") {
89
+ globalThis.requestAnimationFrame = (callback) =>
90
+ setTimeout(
91
+ () => callback(typeof performance === "undefined" ? Date.now() : performance.now()),
92
+ 16,
93
+ ) as unknown as number;
94
+ globalThis.cancelAnimationFrame = (handle) => clearTimeout(handle);
95
+ }
96
+ }
@@ -0,0 +1,23 @@
1
+ import { nativeDeviceServices } from "../react-native/environment";
2
+ import { RokuHostError } from "../scene/sceneGraph.types";
3
+ export const WHEN_UNLOCKED_THIS_DEVICE_ONLY = "roku-device-private";
4
+ export const getItemAsync = async (key: string) =>
5
+ nativeDeviceServices().storage.read("secure", key);
6
+ export async function setItemAsync(
7
+ key: string,
8
+ value: string,
9
+ options?: { keychainAccessible?: string; requireAuthentication?: boolean },
10
+ ) {
11
+ if (
12
+ options?.requireAuthentication ||
13
+ (options?.keychainAccessible != null &&
14
+ options.keychainAccessible !== WHEN_UNLOCKED_THIS_DEVICE_ONLY)
15
+ )
16
+ throw new RokuHostError(
17
+ "C21_SECRET_POLICY",
18
+ "This secure-store policy requires a device capability that Roku does not provide",
19
+ );
20
+ await nativeDeviceServices().storage.write("secure", key, value);
21
+ }
22
+ export const deleteItemAsync = async (key: string) =>
23
+ nativeDeviceServices().storage.write("secure", key, null);
@@ -0,0 +1,22 @@
1
+ import type { TextEntryRequest } from "./DeviceServices";
2
+ import { RokuHostError } from "../scene/sceneGraph.types";
3
+
4
+ export function validateTextEntryText(text: string): void {
5
+ if (typeof text !== "string" || text.length > 4096)
6
+ throw new RokuHostError("C07_TEXT_ENTRY", "Text entry update exceeds the supported contract");
7
+ }
8
+
9
+ export function validateTextEntryRequest(request: TextEntryRequest): void {
10
+ if (
11
+ typeof request.title !== "string" ||
12
+ request.title.length > 256 ||
13
+ typeof request.text !== "string" ||
14
+ request.text.length > 4096 ||
15
+ typeof request.secure !== "boolean" ||
16
+ !["generic", "numeric", "email", "password"].includes(request.domain) ||
17
+ !Number.isInteger(request.maxLength) ||
18
+ request.maxLength < 1 ||
19
+ request.maxLength > 4096
20
+ )
21
+ throw new RokuHostError("C07_TEXT_ENTRY", "Text entry request exceeds the supported contract");
22
+ }