@ng-native/device 0.0.1 → 0.1.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -1
  3. package/dist/accessibility.d.ts +60 -0
  4. package/dist/accessibility.js +101 -0
  5. package/dist/accessibility.js.map +1 -0
  6. package/dist/android-permissions.d.ts +31 -0
  7. package/dist/android-permissions.js +51 -0
  8. package/dist/android-permissions.js.map +1 -0
  9. package/dist/app-state.d.ts +27 -0
  10. package/dist/app-state.js +45 -0
  11. package/dist/app-state.js.map +1 -0
  12. package/dist/color-scheme.d.ts +33 -0
  13. package/dist/color-scheme.js +50 -0
  14. package/dist/color-scheme.js.map +1 -0
  15. package/dist/conditions.d.ts +48 -0
  16. package/dist/conditions.js +91 -0
  17. package/dist/conditions.js.map +1 -0
  18. package/dist/deep-links.d.ts +35 -0
  19. package/dist/deep-links.js +119 -0
  20. package/dist/deep-links.js.map +1 -0
  21. package/dist/dev-menu.d.ts +48 -0
  22. package/dist/dev-menu.js +52 -0
  23. package/dist/dev-menu.js.map +1 -0
  24. package/dist/dialogs.d.ts +111 -0
  25. package/dist/dialogs.js +186 -0
  26. package/dist/dialogs.js.map +1 -0
  27. package/dist/direction.d.ts +49 -0
  28. package/dist/direction.js +57 -0
  29. package/dist/direction.js.map +1 -0
  30. package/dist/hardware-back.d.ts +27 -0
  31. package/dist/hardware-back.js +41 -0
  32. package/dist/hardware-back.js.map +1 -0
  33. package/dist/index.d.ts +26 -0
  34. package/dist/index.js +27 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/keyboard.d.ts +67 -0
  37. package/dist/keyboard.js +103 -0
  38. package/dist/keyboard.js.map +1 -0
  39. package/dist/layout-animation.d.ts +54 -0
  40. package/dist/layout-animation.js +75 -0
  41. package/dist/layout-animation.js.map +1 -0
  42. package/dist/react-native.d.ts +176 -0
  43. package/dist/react-native.js +38 -0
  44. package/dist/react-native.js.map +1 -0
  45. package/dist/safe-area.d.ts +52 -0
  46. package/dist/safe-area.js +51 -0
  47. package/dist/safe-area.js.map +1 -0
  48. package/dist/screen-in-front.d.ts +10 -0
  49. package/dist/screen-in-front.js +14 -0
  50. package/dist/screen-in-front.js.map +1 -0
  51. package/dist/screen.d.ts +78 -0
  52. package/dist/screen.js +90 -0
  53. package/dist/screen.js.map +1 -0
  54. package/dist/sharing.d.ts +37 -0
  55. package/dist/sharing.js +61 -0
  56. package/dist/sharing.js.map +1 -0
  57. package/dist/status-bar.d.ts +69 -0
  58. package/dist/status-bar.js +101 -0
  59. package/dist/status-bar.js.map +1 -0
  60. package/dist/vibration.d.ts +38 -0
  61. package/dist/vibration.js +43 -0
  62. package/dist/vibration.js.map +1 -0
  63. package/package.json +59 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ashley Hunter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
1
  # @ng-native/device
2
2
 
3
- A placeholder: this version has no code. See https://ng-native.com.
3
+ The host: the device, the operating system, and the user's settings.
4
+
5
+ Alpha: APIs may change before 1.0.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @ng-native/device
11
+ npm install @angular/core react-native
12
+ ```
13
+
14
+ ## Example
15
+
16
+ ```ts
17
+ import { Accessibility, Keyboard, Screen } from '@ng-native/device';
18
+
19
+ export class Composer {
20
+ private readonly keyboard = inject(Keyboard);
21
+ private readonly screen = inject(Screen);
22
+ private readonly accessibility = inject(Accessibility);
23
+
24
+ protected readonly wide = computed(() => this.screen.window().width > 600);
25
+ protected readonly clearance = computed(() => this.keyboard.height() + 16);
26
+
27
+ protected saved(): void {
28
+ this.accessibility.announce('Draft saved');
29
+ }
30
+ }
31
+ ```
32
+
33
+ Nothing is provided anywhere. Each service declares its own factory, so injecting it is the whole
34
+ setup, and one nobody injects is never constructed.
35
+
36
+ | Service | What |
37
+ | --------------- | ---------------------------------------------------------------------- |
38
+ | `Keyboard` | `height`, `visible` and the full `metrics`, plus `dismiss()`. |
39
+ | `Screen` | `window`, `display` and `orientation`, following a rotation. |
40
+ | `ColorScheme` | `current`: light or dark, as the user set it. |
41
+ | `AppState` | `current` and `active`: whether the app is in front of the user. |
42
+ | `Accessibility` | `screenReader`, `reduceMotion`, `boldText`, and `announce()`. |
43
+ | `HardwareBack` | `handle()`: Android's back button, answering whether it was consumed. |
44
+ | `DeepLinks` | `initialUrl()`, `subscribe()` and `open()`, as paths rather than urls. |
45
+
46
+ ## Styling reads most of this without injecting anything
47
+
48
+ The engine answers `@media (prefers-color-scheme: dark)`, `(orientation: landscape)`,
49
+ `(min-width: …)` and `(prefers-reduced-motion: reduce)` from the same values, so styling should use
50
+ a media query and leave these services for the decisions CSS cannot make - which asset to load,
51
+ which native component to render, whether to announce something. `watchConditions(engine)` is what
52
+ keeps the engine in step; an app calls it once, next to `mount`.
53
+
54
+ ## Testing
55
+
56
+ Every service reads its platform through a token that hangs off the service itself, so a test
57
+ overrides the token rather than the service and the code under test stays real:
58
+
59
+ ```ts
60
+ mount(1, App, fabric, {
61
+ providers: [
62
+ { provide: Keyboard.SOURCE, useValue: { subscribe: fakeKeyboard, dismiss: () => {} } },
63
+ ],
64
+ });
65
+ ```
66
+
67
+ ## Off a device
68
+
69
+ `react-native` is required lazily, inside each source, because React Native ships its JavaScript as
70
+ Flow and a static import would make this package - and `@ng-native/components`, which imports
71
+ it - unloadable in Node. Off a device the require finds nothing and every capability is inert: the
72
+ keyboard is never visible, the screen is zero by zero, a back handler is never called. That is the
73
+ same behavior as not providing the token that used to stand here, and it is what lets the test
74
+ suite import any of this without a simulator.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What the user has turned on in the system's accessibility settings.
3
+ *
4
+ * The components apply the defaults React Native's wrappers do - roles, labels, whether a view is
5
+ * an element at all - without anything being injected. This is for the decisions those defaults
6
+ * cannot make: not animating when the user asked for less motion, announcing something that
7
+ * changed off screen, giving a screen reader a different affordance than a finger gets.
8
+ *
9
+ * Every value starts at its neutral setting and is corrected once the platform answers, because
10
+ * React Native reports all three asynchronously. A first paint therefore assumes nothing is on.
11
+ */
12
+ import { InjectionToken, type Signal } from '@angular/core';
13
+ import * as i0 from "@angular/core";
14
+ export interface AccessibilitySettings {
15
+ readonly screenReader: boolean;
16
+ readonly reduceMotion: boolean;
17
+ readonly boldText: boolean;
18
+ /**
19
+ * The user's text size, as a multiplier of the default.
20
+ *
21
+ * Not an event: it is read at startup and again when the app comes back, because changing it
22
+ * means leaving for Settings. Text scales natively without anything here, so this is for the
23
+ * layouts that have to give way to it - a row height, a line clamp, an icon beside a label.
24
+ */
25
+ readonly fontScale: number;
26
+ }
27
+ export interface AccessibilitySource {
28
+ current(): Promise<AccessibilitySettings>;
29
+ subscribe(listener: (settings: Partial<AccessibilitySettings>) => void): () => void;
30
+ announce(message: string): void;
31
+ }
32
+ export declare function accessibilitySource(): AccessibilitySource;
33
+ export declare class Accessibility {
34
+ /** Overridden in a test to turn a setting on. */
35
+ static readonly SOURCE: InjectionToken<AccessibilitySource>;
36
+ private readonly source;
37
+ private readonly settings;
38
+ /** VoiceOver or TalkBack is running. */
39
+ readonly screenReader: Signal<boolean>;
40
+ /**
41
+ * The user asked for less animation. `@media (prefers-reduced-motion: reduce)` reads the same
42
+ * setting and is the better answer wherever the motion is styling rather than logic.
43
+ */
44
+ readonly reduceMotion: Signal<boolean>;
45
+ /** The system font is heavier, so hand-tuned weights may need to give way. */
46
+ readonly boldText: Signal<boolean>;
47
+ /**
48
+ * How much larger the user has asked text to be. One is the default; the largest accessibility
49
+ * sizes are past three, which is where a row built for one line stops working.
50
+ */
51
+ readonly fontScale: Signal<number>;
52
+ constructor();
53
+ /**
54
+ * Say something to a screen reader that no focus change would have said. A list that reordered,
55
+ * a search that returned nothing: changes a sighted user sees and a screen reader would miss.
56
+ */
57
+ announce(message: string): void;
58
+ static ɵfac: i0.ɵɵFactoryDeclaration<Accessibility, never>;
59
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
60
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * What the user has turned on in the system's accessibility settings.
3
+ *
4
+ * The components apply the defaults React Native's wrappers do - roles, labels, whether a view is
5
+ * an element at all - without anything being injected. This is for the decisions those defaults
6
+ * cannot make: not animating when the user asked for less motion, announcing something that
7
+ * changed off screen, giving a screen reader a different affordance than a finger gets.
8
+ *
9
+ * Every value starts at its neutral setting and is corrected once the platform answers, because
10
+ * React Native reports all three asynchronously. A first paint therefore assumes nothing is on.
11
+ */
12
+ import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
13
+ import { reactNative } from "./react-native.js";
14
+ import * as i0 from "@angular/core";
15
+ export function accessibilitySource() {
16
+ const native = reactNative();
17
+ if (!native) {
18
+ return {
19
+ current: () => Promise.resolve({
20
+ screenReader: false,
21
+ reduceMotion: false,
22
+ boldText: false,
23
+ fontScale: 1,
24
+ }),
25
+ subscribe: () => () => { },
26
+ announce: () => { },
27
+ };
28
+ }
29
+ const info = native.AccessibilityInfo;
30
+ return {
31
+ current: async () => ({
32
+ screenReader: await info.isScreenReaderEnabled(),
33
+ reduceMotion: await info.isReduceMotionEnabled(),
34
+ boldText: await info.isBoldTextEnabled(),
35
+ fontScale: native.PixelRatio.getFontScale(),
36
+ }),
37
+ subscribe: (listener) => {
38
+ const subscriptions = [
39
+ info.addEventListener('screenReaderChanged', (screenReader) => listener({ screenReader })),
40
+ info.addEventListener('reduceMotionChanged', (reduceMotion) => listener({ reduceMotion })),
41
+ info.addEventListener('boldTextChanged', (boldText) => listener({ boldText })),
42
+ // `fontScale` has no change event of its own - changing it means leaving for Settings -
43
+ // so the app coming back to the foreground is what stands in for one.
44
+ native.AppState.addEventListener('change', (state) => {
45
+ if (state === 'active')
46
+ listener({ fontScale: native.PixelRatio.getFontScale() });
47
+ }),
48
+ ];
49
+ return () => subscriptions.forEach((subscription) => subscription.remove());
50
+ },
51
+ announce: (message) => info.announceForAccessibility(message),
52
+ };
53
+ }
54
+ export class Accessibility {
55
+ /** Overridden in a test to turn a setting on. */
56
+ static SOURCE = new InjectionToken('angular-native.accessibilitySource', { factory: accessibilitySource });
57
+ source = inject(Accessibility.SOURCE);
58
+ settings = signal({
59
+ screenReader: false,
60
+ reduceMotion: false,
61
+ boldText: false,
62
+ fontScale: 1,
63
+ }, /* @ts-ignore */
64
+ ...(ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []));
65
+ /** VoiceOver or TalkBack is running. */
66
+ screenReader = computed(() => this.settings().screenReader, /* @ts-ignore */
67
+ ...(ngDevMode ? [{ debugName: "screenReader" }] : /* istanbul ignore next */ []));
68
+ /**
69
+ * The user asked for less animation. `@media (prefers-reduced-motion: reduce)` reads the same
70
+ * setting and is the better answer wherever the motion is styling rather than logic.
71
+ */
72
+ reduceMotion = computed(() => this.settings().reduceMotion, /* @ts-ignore */
73
+ ...(ngDevMode ? [{ debugName: "reduceMotion" }] : /* istanbul ignore next */ []));
74
+ /** The system font is heavier, so hand-tuned weights may need to give way. */
75
+ boldText = computed(() => this.settings().boldText, /* @ts-ignore */
76
+ ...(ngDevMode ? [{ debugName: "boldText" }] : /* istanbul ignore next */ []));
77
+ /**
78
+ * How much larger the user has asked text to be. One is the default; the largest accessibility
79
+ * sizes are past three, which is where a row built for one line stops working.
80
+ */
81
+ fontScale = computed(() => this.settings().fontScale, /* @ts-ignore */
82
+ ...(ngDevMode ? [{ debugName: "fontScale" }] : /* istanbul ignore next */ []));
83
+ constructor() {
84
+ void this.source.current().then((settings) => this.settings.set(settings));
85
+ const stop = this.source.subscribe((change) => this.settings.update((current) => ({ ...current, ...change })));
86
+ inject(DestroyRef).onDestroy(stop);
87
+ }
88
+ /**
89
+ * Say something to a screen reader that no focus change would have said. A list that reordered,
90
+ * a search that returned nothing: changes a sighted user sees and a screen reader would miss.
91
+ */
92
+ announce(message) {
93
+ this.source.announce(message);
94
+ }
95
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Accessibility, deps: [], target: i0.ɵɵFactoryTarget.Service });
96
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Accessibility });
97
+ }
98
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Accessibility, decorators: [{
99
+ type: Service
100
+ }], ctorParameters: () => [] });
101
+ //# sourceMappingURL=accessibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessibility.js","sourceRoot":"","sources":["../src/accessibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAsBhD,MA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,QAAQ,EAAE,CAAC,SAAS;kFAAC,CAAC;IAE/E;QACE,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAC5C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAC/D,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,OAAe;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;uGA5CU,aAAa;wGAAb,aAAa;;2FAAb,aAAa;kBADzB,OAAO","sourcesContent":["/**\n * What the user has turned on in the system's accessibility settings.\n *\n * The components apply the defaults React Native's wrappers do - roles, labels, whether a view is\n * an element at all - without anything being injected. This is for the decisions those defaults\n * cannot make: not animating when the user asked for less motion, announcing something that\n * changed off screen, giving a screen reader a different affordance than a finger gets.\n *\n * Every value starts at its neutral setting and is corrected once the platform answers, because\n * React Native reports all three asynchronously. A first paint therefore assumes nothing is on.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface AccessibilitySettings {\n readonly screenReader: boolean;\n readonly reduceMotion: boolean;\n readonly boldText: boolean;\n /**\n * The user's text size, as a multiplier of the default.\n *\n * Not an event: it is read at startup and again when the app comes back, because changing it\n * means leaving for Settings. Text scales natively without anything here, so this is for the\n * layouts that have to give way to it - a row height, a line clamp, an icon beside a label.\n */\n readonly fontScale: number;\n}\n\nexport interface AccessibilitySource {\n current(): Promise<AccessibilitySettings>;\n subscribe(listener: (settings: Partial<AccessibilitySettings>) => void): () => void;\n announce(message: string): void;\n}\n\nexport function accessibilitySource(): AccessibilitySource {\n const native = reactNative();\n if (!native) {\n return {\n current: () =>\n Promise.resolve({\n screenReader: false,\n reduceMotion: false,\n boldText: false,\n fontScale: 1,\n }),\n subscribe: () => () => {},\n announce: () => {},\n };\n }\n\n const info = native.AccessibilityInfo;\n return {\n current: async () => ({\n screenReader: await info.isScreenReaderEnabled(),\n reduceMotion: await info.isReduceMotionEnabled(),\n boldText: await info.isBoldTextEnabled(),\n fontScale: native.PixelRatio.getFontScale(),\n }),\n subscribe: (listener) => {\n const subscriptions = [\n info.addEventListener('screenReaderChanged', (screenReader) => listener({ screenReader })),\n info.addEventListener('reduceMotionChanged', (reduceMotion) => listener({ reduceMotion })),\n info.addEventListener('boldTextChanged', (boldText) => listener({ boldText })),\n // `fontScale` has no change event of its own - changing it means leaving for Settings -\n // so the app coming back to the foreground is what stands in for one.\n native.AppState.addEventListener('change', (state) => {\n if (state === 'active') listener({ fontScale: native.PixelRatio.getFontScale() });\n }),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n announce: (message) => info.announceForAccessibility(message),\n };\n}\n\n@Service()\nexport class Accessibility {\n /** Overridden in a test to turn a setting on. */\n static readonly SOURCE = new InjectionToken<AccessibilitySource>(\n 'angular-native.accessibilitySource',\n { factory: accessibilitySource },\n );\n\n private readonly source = inject(Accessibility.SOURCE);\n private readonly settings = signal<AccessibilitySettings>({\n screenReader: false,\n reduceMotion: false,\n boldText: false,\n fontScale: 1,\n });\n\n /** VoiceOver or TalkBack is running. */\n readonly screenReader: Signal<boolean> = computed(() => this.settings().screenReader);\n /**\n * The user asked for less animation. `@media (prefers-reduced-motion: reduce)` reads the same\n * setting and is the better answer wherever the motion is styling rather than logic.\n */\n readonly reduceMotion: Signal<boolean> = computed(() => this.settings().reduceMotion);\n /** The system font is heavier, so hand-tuned weights may need to give way. */\n readonly boldText: Signal<boolean> = computed(() => this.settings().boldText);\n /**\n * How much larger the user has asked text to be. One is the default; the largest accessibility\n * sizes are past three, which is where a row built for one line stops working.\n */\n readonly fontScale: Signal<number> = computed(() => this.settings().fontScale);\n\n constructor() {\n void this.source.current().then((settings) => this.settings.set(settings));\n const stop = this.source.subscribe((change) =>\n this.settings.update((current) => ({ ...current, ...change })),\n );\n inject(DestroyRef).onDestroy(stop);\n }\n\n /**\n * Say something to a screen reader that no focus change would have said. A list that reordered,\n * a search that returned nothing: changes a sighted user sees and a screen reader would miss.\n */\n announce(message: string): void {\n this.source.announce(message);\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Android's runtime permissions, in the shape the rest of the permissions here take.
3
+ *
4
+ * `PermissionsAndroid` predates the pattern every Expo module settled on - it returns a string
5
+ * where they return a record, and has no notion of "the platform will not ask again" beyond a
6
+ * third status. This adapts it, so a camera permission from `expo-camera` and a
7
+ * `POST_NOTIFICATIONS` from Android read the same way at the call site.
8
+ *
9
+ * On iOS every one of these is granted: the permissions Android asks about at runtime are ones
10
+ * iOS either grants at install or does not have.
11
+ */
12
+ export interface AndroidPermissions {
13
+ check(permission: string): Promise<boolean>;
14
+ request(permission: string, rationale?: object): Promise<string>;
15
+ }
16
+ /** What every permission call here answers with, matching Expo's own shape. */
17
+ export interface PermissionAnswer {
18
+ readonly status: 'granted' | 'denied' | 'undetermined';
19
+ readonly granted: boolean;
20
+ readonly canAskAgain: boolean;
21
+ }
22
+ /**
23
+ * The pair of functions `Permission.of` takes, for one Android permission.
24
+ *
25
+ * ```ts
26
+ * const notify = Permission.of(...androidPermission('android.permission.POST_NOTIFICATIONS'));
27
+ * ```
28
+ */
29
+ export declare function androidPermission(permission: string): [() => Promise<PermissionAnswer>, () => Promise<PermissionAnswer>];
30
+ /** The same, against a stated platform. Separated so a test can drive it without a device. */
31
+ export declare function androidPermissionOf(native: AndroidPermissions | null, permission: string): [() => Promise<PermissionAnswer>, () => Promise<PermissionAnswer>];
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Android's runtime permissions, in the shape the rest of the permissions here take.
3
+ *
4
+ * `PermissionsAndroid` predates the pattern every Expo module settled on - it returns a string
5
+ * where they return a record, and has no notion of "the platform will not ask again" beyond a
6
+ * third status. This adapts it, so a camera permission from `expo-camera` and a
7
+ * `POST_NOTIFICATIONS` from Android read the same way at the call site.
8
+ *
9
+ * On iOS every one of these is granted: the permissions Android asks about at runtime are ones
10
+ * iOS either grants at install or does not have.
11
+ */
12
+ import { reactNative } from "./react-native.js";
13
+ const GRANTED = { status: 'granted', granted: true, canAskAgain: false };
14
+ /**
15
+ * The pair of functions `Permission.of` takes, for one Android permission.
16
+ *
17
+ * ```ts
18
+ * const notify = Permission.of(...androidPermission('android.permission.POST_NOTIFICATIONS'));
19
+ * ```
20
+ */
21
+ export function androidPermission(permission) {
22
+ const native = reactNative();
23
+ // `PermissionsAndroid` is the same module object on every platform - it is not absent on iOS,
24
+ // it is a stub that warns and resolves `false`/`'denied'`. Left ungated, this would read an iOS
25
+ // permission the platform never asked about as refused, rather than the `granted` promised above.
26
+ const android = native?.Platform.OS === 'android' ? (native.PermissionsAndroid ?? null) : null;
27
+ return androidPermissionOf(android, permission);
28
+ }
29
+ /** The same, against a stated platform. Separated so a test can drive it without a device. */
30
+ export function androidPermissionOf(native, permission) {
31
+ if (!native)
32
+ return [async () => GRANTED, async () => GRANTED];
33
+ return [
34
+ async () => {
35
+ // `check` cannot tell "denied" from "not yet asked", and only the second is worth a dialog.
36
+ // Undetermined is the honest answer, and `ensure()` will ask.
37
+ const granted = await native.check(permission);
38
+ return granted ? GRANTED : { status: 'undetermined', granted: false, canAskAgain: true };
39
+ },
40
+ async () => {
41
+ const result = await native.request(permission);
42
+ if (result === 'granted')
43
+ return GRANTED;
44
+ // `never_ask_again` is Android's way of saying the dialog is over. Anything else is a no
45
+ // the user can still change their mind about.
46
+ const canAskAgain = result !== 'never_ask_again';
47
+ return { status: 'denied', granted: false, canAskAgain };
48
+ },
49
+ ];
50
+ }
51
+ //# sourceMappingURL=android-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"android-permissions.js","sourceRoot":"","sources":["../src/android-permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAchD,MAAM,OAAO,GAAqB,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AAE3F;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB;IAElB,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,8FAA8F;IAC9F,gGAAgG;IAChG,kGAAkG;IAClG,MAAM,OAAO,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/F,OAAO,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAClD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,mBAAmB,CACjC,MAAiC,EACjC,UAAkB;IAElB,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC;IAE/D,OAAO;QACL,KAAK,IAAI,EAAE;YACT,4FAA4F;YAC5F,8DAA8D;YAC9D,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC/C,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC3F,CAAC;QACD,KAAK,IAAI,EAAE;YACT,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChD,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC;YACzC,yFAAyF;YACzF,8CAA8C;YAC9C,MAAM,WAAW,GAAG,MAAM,KAAK,iBAAiB,CAAC;YACjD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Android's runtime permissions, in the shape the rest of the permissions here take.\n *\n * `PermissionsAndroid` predates the pattern every Expo module settled on - it returns a string\n * where they return a record, and has no notion of \"the platform will not ask again\" beyond a\n * third status. This adapts it, so a camera permission from `expo-camera` and a\n * `POST_NOTIFICATIONS` from Android read the same way at the call site.\n *\n * On iOS every one of these is granted: the permissions Android asks about at runtime are ones\n * iOS either grants at install or does not have.\n */\n\nimport { reactNative } from './react-native.ts';\n\nexport interface AndroidPermissions {\n check(permission: string): Promise<boolean>;\n request(permission: string, rationale?: object): Promise<string>;\n}\n\n/** What every permission call here answers with, matching Expo's own shape. */\nexport interface PermissionAnswer {\n readonly status: 'granted' | 'denied' | 'undetermined';\n readonly granted: boolean;\n readonly canAskAgain: boolean;\n}\n\nconst GRANTED: PermissionAnswer = { status: 'granted', granted: true, canAskAgain: false };\n\n/**\n * The pair of functions `Permission.of` takes, for one Android permission.\n *\n * ```ts\n * const notify = Permission.of(...androidPermission('android.permission.POST_NOTIFICATIONS'));\n * ```\n */\nexport function androidPermission(\n permission: string,\n): [() => Promise<PermissionAnswer>, () => Promise<PermissionAnswer>] {\n const native = reactNative();\n // `PermissionsAndroid` is the same module object on every platform - it is not absent on iOS,\n // it is a stub that warns and resolves `false`/`'denied'`. Left ungated, this would read an iOS\n // permission the platform never asked about as refused, rather than the `granted` promised above.\n const android = native?.Platform.OS === 'android' ? (native.PermissionsAndroid ?? null) : null;\n return androidPermissionOf(android, permission);\n}\n\n/** The same, against a stated platform. Separated so a test can drive it without a device. */\nexport function androidPermissionOf(\n native: AndroidPermissions | null,\n permission: string,\n): [() => Promise<PermissionAnswer>, () => Promise<PermissionAnswer>] {\n if (!native) return [async () => GRANTED, async () => GRANTED];\n\n return [\n async () => {\n // `check` cannot tell \"denied\" from \"not yet asked\", and only the second is worth a dialog.\n // Undetermined is the honest answer, and `ensure()` will ask.\n const granted = await native.check(permission);\n return granted ? GRANTED : { status: 'undetermined', granted: false, canAskAgain: true };\n },\n async () => {\n const result = await native.request(permission);\n if (result === 'granted') return GRANTED;\n // `never_ask_again` is Android's way of saying the dialog is over. Anything else is a no\n // the user can still change their mind about.\n const canAskAgain = result !== 'never_ask_again';\n return { status: 'denied', granted: false, canAskAgain };\n },\n ];\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Whether the app is in front of the user.
3
+ *
4
+ * `inactive` is iOS only and means the transitional state: the app switcher is open, a call is
5
+ * coming in, the notification shade is down. Anything that should stop when the user is not
6
+ * looking - a poll, a video, a timer - wants `active`, not the absence of `background`.
7
+ */
8
+ import { InjectionToken, type Signal } from '@angular/core';
9
+ import * as i0 from "@angular/core";
10
+ export type AppStatus = 'active' | 'background' | 'inactive';
11
+ export interface AppStateSource {
12
+ current(): AppStatus;
13
+ subscribe(listener: (state: AppStatus) => void): () => void;
14
+ }
15
+ export declare function appStateSource(): AppStateSource;
16
+ export declare class AppState {
17
+ /** Overridden in a test to send the app to the background. */
18
+ static readonly SOURCE: InjectionToken<AppStateSource>;
19
+ private readonly source;
20
+ private readonly state;
21
+ readonly current: Signal<AppStatus>;
22
+ /** In front of the user and taking input. */
23
+ readonly active: Signal<boolean>;
24
+ constructor();
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<AppState, never>;
26
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
27
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Whether the app is in front of the user.
3
+ *
4
+ * `inactive` is iOS only and means the transitional state: the app switcher is open, a call is
5
+ * coming in, the notification shade is down. Anything that should stop when the user is not
6
+ * looking - a poll, a video, a timer - wants `active`, not the absence of `background`.
7
+ */
8
+ import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
9
+ import { reactNative } from "./react-native.js";
10
+ import * as i0 from "@angular/core";
11
+ const known = (state) => state === 'background' || state === 'inactive' ? state : 'active';
12
+ export function appStateSource() {
13
+ const native = reactNative();
14
+ if (!native)
15
+ return { current: () => 'active', subscribe: () => () => { } };
16
+ return {
17
+ current: () => known(native.AppState.currentState),
18
+ subscribe: (listener) => {
19
+ const subscription = native.AppState.addEventListener('change', (state) => listener(known(state)));
20
+ return () => subscription.remove();
21
+ },
22
+ };
23
+ }
24
+ export class AppState {
25
+ /** Overridden in a test to send the app to the background. */
26
+ static SOURCE = new InjectionToken('angular-native.appStateSource', {
27
+ factory: appStateSource,
28
+ });
29
+ source = inject(AppState.SOURCE);
30
+ state = signal(this.source.current(), /* @ts-ignore */
31
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
32
+ current = this.state.asReadonly();
33
+ /** In front of the user and taking input. */
34
+ active = computed(() => this.state() === 'active', /* @ts-ignore */
35
+ ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
36
+ constructor() {
37
+ inject(DestroyRef).onDestroy(this.source.subscribe((state) => this.state.set(state)));
38
+ }
39
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: AppState, deps: [], target: i0.ɵɵFactoryTarget.Service });
40
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: AppState });
41
+ }
42
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: AppState, decorators: [{
43
+ type: Service
44
+ }], ctorParameters: () => [] });
45
+ //# sourceMappingURL=app-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AAC,CAAC;IACjC,KAAK,GAAG,MAAM,CAAY,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;8EAAC,CAAC;IAEzD,OAAO,GAAsB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IAC9D,6CAA6C;IACpC,MAAM,GAAoB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,QAAQ;+EAAC,CAAC;IAE7E;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;uGAfU,QAAQ;wGAAR,QAAQ;;2FAAR,QAAQ;kBADpB,OAAO","sourcesContent":["/**\n * Whether the app is in front of the user.\n *\n * `inactive` is iOS only and means the transitional state: the app switcher is open, a call is\n * coming in, the notification shade is down. Anything that should stop when the user is not\n * looking - a poll, a video, a timer - wants `active`, not the absence of `background`.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport type AppStatus = 'active' | 'background' | 'inactive';\n\nexport interface AppStateSource {\n current(): AppStatus;\n subscribe(listener: (state: AppStatus) => void): () => void;\n}\n\nconst known = (state: string | null | undefined): AppStatus =>\n state === 'background' || state === 'inactive' ? state : 'active';\n\nexport function appStateSource(): AppStateSource {\n const native = reactNative();\n if (!native) return { current: () => 'active', subscribe: () => () => {} };\n\n return {\n current: () => known(native.AppState.currentState),\n subscribe: (listener) => {\n const subscription = native.AppState.addEventListener('change', (state) =>\n listener(known(state)),\n );\n return () => subscription.remove();\n },\n };\n}\n\n@Service()\nexport class AppState {\n /** Overridden in a test to send the app to the background. */\n static readonly SOURCE = new InjectionToken<AppStateSource>('angular-native.appStateSource', {\n factory: appStateSource,\n });\n\n private readonly source = inject(AppState.SOURCE);\n private readonly state = signal<AppStatus>(this.source.current());\n\n readonly current: Signal<AppStatus> = this.state.asReadonly();\n /** In front of the user and taking input. */\n readonly active: Signal<boolean> = computed(() => this.state() === 'active');\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((state) => this.state.set(state)));\n }\n}\n"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Light or dark, as the user set it, or as the app sets it over them.
3
+ *
4
+ * Styling should use `@media (prefers-color-scheme: dark)`, which the engine resolves without
5
+ * anything being injected. This is for the decisions CSS cannot make: which asset to load, which
6
+ * status bar style to ask for, which of two native components to render.
7
+ */
8
+ import { InjectionToken, type Signal } from '@angular/core';
9
+ import * as i0 from "@angular/core";
10
+ export type Scheme = 'light' | 'dark';
11
+ export interface ColorSchemeSource {
12
+ current(): Scheme;
13
+ subscribe(listener: (scheme: Scheme) => void): () => void;
14
+ /** Put the whole app in one scheme, or back in the system's with null. */
15
+ set?(scheme: Scheme | null): void;
16
+ }
17
+ export declare function colorSchemeSource(): ColorSchemeSource;
18
+ export declare class ColorScheme {
19
+ /** Overridden in a test to switch the theme. */
20
+ static readonly SOURCE: InjectionToken<ColorSchemeSource>;
21
+ private readonly source;
22
+ private readonly scheme;
23
+ readonly current: Signal<Scheme>;
24
+ /**
25
+ * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:
26
+ * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's
27
+ * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.
28
+ */
29
+ set(scheme: Scheme | null): void;
30
+ constructor();
31
+ static ɵfac: i0.ɵɵFactoryDeclaration<ColorScheme, never>;
32
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
33
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Light or dark, as the user set it, or as the app sets it over them.
3
+ *
4
+ * Styling should use `@media (prefers-color-scheme: dark)`, which the engine resolves without
5
+ * anything being injected. This is for the decisions CSS cannot make: which asset to load, which
6
+ * status bar style to ask for, which of two native components to render.
7
+ */
8
+ import { DestroyRef, InjectionToken, Service, inject, signal } from '@angular/core';
9
+ import { reactNative } from "./react-native.js";
10
+ import * as i0 from "@angular/core";
11
+ export function colorSchemeSource() {
12
+ const native = reactNative();
13
+ if (!native)
14
+ return { current: () => 'light', subscribe: () => () => { } };
15
+ // `null` means the platform has no preference, which is light.
16
+ const read = () => (native.Appearance.getColorScheme() === 'dark' ? 'dark' : 'light');
17
+ return {
18
+ current: read,
19
+ subscribe: (listener) => {
20
+ const subscription = native.Appearance.addChangeListener(() => listener(read()));
21
+ return () => subscription.remove();
22
+ },
23
+ set: (scheme) => native.Appearance.setColorScheme?.(scheme ?? 'unspecified'),
24
+ };
25
+ }
26
+ export class ColorScheme {
27
+ /** Overridden in a test to switch the theme. */
28
+ static SOURCE = new InjectionToken('angular-native.colorSchemeSource', { factory: colorSchemeSource });
29
+ source = inject(ColorScheme.SOURCE);
30
+ scheme = signal(this.source.current(), /* @ts-ignore */
31
+ ...(ngDevMode ? [{ debugName: "scheme" }] : /* istanbul ignore next */ []));
32
+ current = this.scheme.asReadonly();
33
+ /**
34
+ * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:
35
+ * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's
36
+ * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.
37
+ */
38
+ set(scheme) {
39
+ this.source.set?.(scheme);
40
+ }
41
+ constructor() {
42
+ inject(DestroyRef).onDestroy(this.source.subscribe((scheme) => this.scheme.set(scheme)));
43
+ }
44
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ColorScheme, deps: [], target: i0.ɵɵFactoryTarget.Service });
45
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: ColorScheme });
46
+ }
47
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ColorScheme, decorators: [{
48
+ type: Service
49
+ }], ctorParameters: () => [] });
50
+ //# sourceMappingURL=color-scheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-scheme.js","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAE1E,+DAA+D;IAC/D,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACtF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACjF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACrC,CAAC;QACD,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,MAAM,IAAI,aAAa,CAAC;KAC7E,CAAC;AACJ,CAAC;AAGD,MAAM,OAAO,WAAW;IACtB,gDAAgD;IAChD,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,kCAAkC,EAClC,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAC/B,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,GAAG,MAAM,CAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;+EAAC,CAAC;IAEvD,OAAO,GAAmB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAE5D;;;;OAIG;IACH,GAAG,CAAC,MAAqB;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;uGAvBU,WAAW;wGAAX,WAAW;;2FAAX,WAAW;kBADvB,OAAO","sourcesContent":["/**\n * Light or dark, as the user set it, or as the app sets it over them.\n *\n * Styling should use `@media (prefers-color-scheme: dark)`, which the engine resolves without\n * anything being injected. This is for the decisions CSS cannot make: which asset to load, which\n * status bar style to ask for, which of two native components to render.\n */\nimport { DestroyRef, InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport type Scheme = 'light' | 'dark';\n\nexport interface ColorSchemeSource {\n current(): Scheme;\n subscribe(listener: (scheme: Scheme) => void): () => void;\n /** Put the whole app in one scheme, or back in the system's with null. */\n set?(scheme: Scheme | null): void;\n}\n\nexport function colorSchemeSource(): ColorSchemeSource {\n const native = reactNative();\n if (!native) return { current: () => 'light', subscribe: () => () => {} };\n\n // `null` means the platform has no preference, which is light.\n const read = () => (native.Appearance.getColorScheme() === 'dark' ? 'dark' : 'light');\n return {\n current: read,\n subscribe: (listener) => {\n const subscription = native.Appearance.addChangeListener(() => listener(read()));\n return () => subscription.remove();\n },\n set: (scheme) => native.Appearance.setColorScheme?.(scheme ?? 'unspecified'),\n };\n}\n\n@Service()\nexport class ColorScheme {\n /** Overridden in a test to switch the theme. */\n static readonly SOURCE = new InjectionToken<ColorSchemeSource>(\n 'angular-native.colorSchemeSource',\n { factory: colorSchemeSource },\n );\n\n private readonly source = inject(ColorScheme.SOURCE);\n private readonly scheme = signal<Scheme>(this.source.current());\n\n readonly current: Signal<Scheme> = this.scheme.asReadonly();\n\n /**\n * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:\n * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's\n * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.\n */\n set(scheme: Scheme | null): void {\n this.source.set?.(scheme);\n }\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((scheme) => this.scheme.set(scheme)));\n }\n}\n"]}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * What the engine evaluates media queries against, kept in step with the device.
3
+ *
4
+ * Not a service, because the engine is not injectable and has no reason to be: it is handed to
5
+ * `mount` and handed back, and this connects the two. An app that wants `@media` to keep working
6
+ * after a rotation or a theme change calls `watchConditions` once and never thinks about it again.
7
+ *
8
+ * A rotation changes no component and no binding, so nothing would be dirty and nothing would
9
+ * re-render. The engine re-resolves and commits on its own when the conditions change.
10
+ */
11
+ import type { Conditions, TokenValue } from '@ng-native/fabric';
12
+ /** Just enough of the engine to be told. */
13
+ interface Resolves<Node = unknown> {
14
+ readonly root: Node;
15
+ updateConditions(conditions: Conditions): void;
16
+ addClass(node: Node, name: string): void;
17
+ removeClass(node: Node, name: string): void;
18
+ /** Measure every text again, after the system text size changed. */
19
+ remeasureText?(): void;
20
+ }
21
+ export interface WatchOptions {
22
+ /**
23
+ * Keep a `dark` class on the root in step with the system scheme, which is what
24
+ * `@ng-native/tailwind`'s `dark:` variant matches. On by default; an app with its own theme
25
+ * switch turns it off and puts `dark` on its own root view instead.
26
+ */
27
+ readonly darkClass?: boolean;
28
+ }
29
+ export declare function currentConditions(): Conditions;
30
+ /**
31
+ * Custom properties the device settles before the first frame, for `mount`'s `tokens` option.
32
+ *
33
+ * Only the hairline so far: the thinnest line the screen can draw, which is a third of a point on
34
+ * a 3x phone and half of one on a 2x. `1px` is what a browser would give and is a visibly fat
35
+ * divider on a modern screen, so a native-looking rule has to ask. React Native works the number
36
+ * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of
37
+ * the wrong weight in every test that draws one.
38
+ *
39
+ * Not watched, unlike the conditions: the pixel density of a screen does not change while an app
40
+ * is open. The safe-area insets are the opposite case and arrive through `updateTokens`.
41
+ */
42
+ export declare function deviceTokens(): Record<string, TokenValue>;
43
+ /**
44
+ * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at
45
+ * bootstrap will never use it.
46
+ */
47
+ export declare function watchConditions<Node>(engine: Resolves<Node>, options?: WatchOptions): () => void;
48
+ export {};