@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen-in-front.js","sourceRoot":"","sources":["../src/screen-in-front.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,cAAc,CAAkB,8BAA8B,EAAE;IACjG,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM;CACtB,CAAC,CAAC","sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\n\nconst ALWAYS = signal(true).asReadonly();\n\n/**\n * Whether the screen something is on is the one in front: false while another screen is pushed\n * over it or presented from it, or while its tab is not the selected one. A navigation outlet\n * provides it for each screen it shows; outside one it is always true.\n *\n * For what native keeps showing whatever covers a screen: a bar docked on the keyboard belongs to\n * the keyboard's window, above every screen the app has, and has to step down itself.\n */\nexport const SCREEN_IN_FRONT = new InjectionToken<Signal<boolean>>('angular-native.screenInFront', {\n factory: () => ALWAYS,\n});\n"]}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * How big the screen is, and which way up.
3
+ *
4
+ * The engine already tracks this for media queries, but only for the cascade: it resolves `@media`
5
+ * and viewport units and tells nobody. Component logic that has to branch on size - a two-column
6
+ * layout above a breakpoint, a different image for a tall screen - has no way to ask, and reaching
7
+ * for `Dimensions.get` directly gets a value that never updates on rotation.
8
+ */
9
+ import { InjectionToken, type Signal } from '@angular/core';
10
+ import * as i0 from "@angular/core";
11
+ export interface Size {
12
+ readonly width: number;
13
+ readonly height: number;
14
+ }
15
+ export interface Sizes {
16
+ /**
17
+ * What `Dimensions` calls the window, which is not always what the app can draw in.
18
+ *
19
+ * On Android 15 an app draws edge to edge, painting behind the status and navigation bars, and
20
+ * this reports the area *between* them - short by their height. `Screen.window` prefers the
21
+ * safe-area provider's measured frame for that reason; this is the fallback for the frame before
22
+ * the provider has laid out.
23
+ */
24
+ readonly window: Size;
25
+ /** The physical display. */
26
+ readonly screen: Size;
27
+ }
28
+ export interface ScreenSource {
29
+ current(): Sizes;
30
+ subscribe(listener: (sizes: Sizes) => void): () => void;
31
+ }
32
+ /** Tailwind's `md`. Below it a phone layout, at or above it a tablet one. */
33
+ export declare const COMPACT_WIDTH = 768;
34
+ export declare function screenSource(): ScreenSource;
35
+ export declare class Screen {
36
+ /** Overridden in a test to resize the screen, or rotate it. */
37
+ static readonly SOURCE: InjectionToken<ScreenSource>;
38
+ private readonly source;
39
+ private readonly safeArea;
40
+ private readonly sizes;
41
+ /**
42
+ * What the app can draw in: the one almost everything wants.
43
+ *
44
+ * Measured by the safe-area provider rather than read from `Dimensions`, because on Android 15
45
+ * an app draws edge to edge - behind the status and navigation bars - and `Dimensions` reports
46
+ * the area between them instead. On a 1080x2400 phone that was 838.5pt against a real drawable
47
+ * height of 914.3, so viewport units, height media queries and anything sizing itself from this
48
+ * were all short by the bars. The provider measures the frame it was actually handed, which is
49
+ * the drawable area by definition and on both platforms.
50
+ *
51
+ * `Dimensions` is the fallback for the one frame between mounting and the provider laying out,
52
+ * because a window of zero for that frame would be worse than a slightly wrong one. An app with
53
+ * no `<safe-area-provider>` never gets past the fallback, which is the behaviour it had before.
54
+ */
55
+ readonly window: Signal<Size>;
56
+ /** The physical display, which on Android is larger than the window. */
57
+ readonly display: Signal<Size>;
58
+ readonly orientation: Signal<'portrait' | 'landscape'>;
59
+ /**
60
+ * Whether the window is narrow enough to want the phone layout.
61
+ *
62
+ * The one branch a component library actually needs, and the reason it is a signal rather than
63
+ * a media query: a sidebar that is a rail on an iPad and a sheet on a phone is not two sets of
64
+ * classes on one tree, it is two different trees. shadcn's own sidebar branches in JavaScript
65
+ * for exactly this reason, and `@media` in the stylesheet cannot decide which components to
66
+ * build. Where the difference *is* only classes, write `md:` and let the cascade do it - the
67
+ * compiler answers width, height and orientation queries, so Tailwind's breakpoints work.
68
+ *
69
+ * `COMPACT_WIDTH` is Tailwind's `md`, which is also the number `useIsMobile` uses upstream.
70
+ * It is close to, but not the same as, iOS's own compact/regular width class: an iPad mini in
71
+ * portrait is 744pt, which Apple calls regular and this calls compact. Close enough to be the
72
+ * right default and named so an app that disagrees can say so.
73
+ */
74
+ readonly compact: Signal<boolean>;
75
+ constructor();
76
+ static ɵfac: i0.ɵɵFactoryDeclaration<Screen, never>;
77
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
78
+ }
package/dist/screen.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * How big the screen is, and which way up.
3
+ *
4
+ * The engine already tracks this for media queries, but only for the cascade: it resolves `@media`
5
+ * and viewport units and tells nobody. Component logic that has to branch on size - a two-column
6
+ * layout above a breakpoint, a different image for a tall screen - has no way to ask, and reaching
7
+ * for `Dimensions.get` directly gets a value that never updates on rotation.
8
+ */
9
+ import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
10
+ import { reactNative } from "./react-native.js";
11
+ import { SafeArea } from "./safe-area.js";
12
+ import * as i0 from "@angular/core";
13
+ const NOTHING = { window: { width: 0, height: 0 }, screen: { width: 0, height: 0 } };
14
+ /** Tailwind's `md`. Below it a phone layout, at or above it a tablet one. */
15
+ export const COMPACT_WIDTH = 768;
16
+ export function screenSource() {
17
+ const native = reactNative();
18
+ if (!native)
19
+ return { current: () => NOTHING, subscribe: () => () => { } };
20
+ return {
21
+ current: () => ({
22
+ window: native.Dimensions.get('window'),
23
+ screen: native.Dimensions.get('screen'),
24
+ }),
25
+ subscribe: (listener) => {
26
+ const subscription = native.Dimensions.addEventListener('change', (sizes) => listener({ window: sizes.window, screen: sizes.screen }));
27
+ return () => subscription.remove();
28
+ },
29
+ };
30
+ }
31
+ export class Screen {
32
+ /** Overridden in a test to resize the screen, or rotate it. */
33
+ static SOURCE = new InjectionToken('angular-native.screenSource', {
34
+ factory: screenSource,
35
+ });
36
+ source = inject(Screen.SOURCE);
37
+ safeArea = inject(SafeArea);
38
+ sizes = signal(this.source.current(), /* @ts-ignore */
39
+ ...(ngDevMode ? [{ debugName: "sizes" }] : /* istanbul ignore next */ []));
40
+ /**
41
+ * What the app can draw in: the one almost everything wants.
42
+ *
43
+ * Measured by the safe-area provider rather than read from `Dimensions`, because on Android 15
44
+ * an app draws edge to edge - behind the status and navigation bars - and `Dimensions` reports
45
+ * the area between them instead. On a 1080x2400 phone that was 838.5pt against a real drawable
46
+ * height of 914.3, so viewport units, height media queries and anything sizing itself from this
47
+ * were all short by the bars. The provider measures the frame it was actually handed, which is
48
+ * the drawable area by definition and on both platforms.
49
+ *
50
+ * `Dimensions` is the fallback for the one frame between mounting and the provider laying out,
51
+ * because a window of zero for that frame would be worse than a slightly wrong one. An app with
52
+ * no `<safe-area-provider>` never gets past the fallback, which is the behaviour it had before.
53
+ */
54
+ window = computed(() => {
55
+ const frame = this.safeArea.frame();
56
+ return frame ? { width: frame.width, height: frame.height } : this.sizes().window;
57
+ }, /* @ts-ignore */
58
+ ...(ngDevMode ? [{ debugName: "window" }] : /* istanbul ignore next */ []));
59
+ /** The physical display, which on Android is larger than the window. */
60
+ display = computed(() => this.sizes().screen, /* @ts-ignore */
61
+ ...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
62
+ orientation = computed(() => this.window().width > this.window().height ? 'landscape' : 'portrait', /* @ts-ignore */
63
+ ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
64
+ /**
65
+ * Whether the window is narrow enough to want the phone layout.
66
+ *
67
+ * The one branch a component library actually needs, and the reason it is a signal rather than
68
+ * a media query: a sidebar that is a rail on an iPad and a sheet on a phone is not two sets of
69
+ * classes on one tree, it is two different trees. shadcn's own sidebar branches in JavaScript
70
+ * for exactly this reason, and `@media` in the stylesheet cannot decide which components to
71
+ * build. Where the difference *is* only classes, write `md:` and let the cascade do it - the
72
+ * compiler answers width, height and orientation queries, so Tailwind's breakpoints work.
73
+ *
74
+ * `COMPACT_WIDTH` is Tailwind's `md`, which is also the number `useIsMobile` uses upstream.
75
+ * It is close to, but not the same as, iOS's own compact/regular width class: an iPad mini in
76
+ * portrait is 744pt, which Apple calls regular and this calls compact. Close enough to be the
77
+ * right default and named so an app that disagrees can say so.
78
+ */
79
+ compact = computed(() => this.window().width < COMPACT_WIDTH, /* @ts-ignore */
80
+ ...(ngDevMode ? [{ debugName: "compact" }] : /* istanbul ignore next */ []));
81
+ constructor() {
82
+ inject(DestroyRef).onDestroy(this.source.subscribe((sizes) => this.sizes.set(sizes)));
83
+ }
84
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Screen, deps: [], target: i0.ɵɵFactoryTarget.Service });
85
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Screen });
86
+ }
87
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Screen, decorators: [{
88
+ type: Service
89
+ }], ctorParameters: () => [] });
90
+ //# sourceMappingURL=screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[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AAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;uGArDU,MAAM;wGAAN,MAAM;;2FAAN,MAAM;kBADlB,OAAO","sourcesContent":["/**\n * How big the screen is, and which way up.\n *\n * The engine already tracks this for media queries, but only for the cascade: it resolves `@media`\n * and viewport units and tells nobody. Component logic that has to branch on size - a two-column\n * layout above a breakpoint, a different image for a tall screen - has no way to ask, and reaching\n * for `Dimensions.get` directly gets a value that never updates on rotation.\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';\nimport { SafeArea } from './safe-area.ts';\n\nexport interface Size {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Sizes {\n /**\n * What `Dimensions` calls the window, which is not always what the app can draw in.\n *\n * On Android 15 an app draws edge to edge, painting behind the status and navigation bars, and\n * this reports the area *between* them - short by their height. `Screen.window` prefers the\n * safe-area provider's measured frame for that reason; this is the fallback for the frame before\n * the provider has laid out.\n */\n readonly window: Size;\n /** The physical display. */\n readonly screen: Size;\n}\n\nexport interface ScreenSource {\n current(): Sizes;\n subscribe(listener: (sizes: Sizes) => void): () => void;\n}\n\nconst NOTHING: Sizes = { window: { width: 0, height: 0 }, screen: { width: 0, height: 0 } };\n\n/** Tailwind's `md`. Below it a phone layout, at or above it a tablet one. */\nexport const COMPACT_WIDTH = 768;\n\nexport function screenSource(): ScreenSource {\n const native = reactNative();\n if (!native) return { current: () => NOTHING, subscribe: () => () => {} };\n\n return {\n current: () => ({\n window: native.Dimensions.get('window'),\n screen: native.Dimensions.get('screen'),\n }),\n subscribe: (listener) => {\n const subscription = native.Dimensions.addEventListener('change', (sizes) =>\n listener({ window: sizes.window, screen: sizes.screen }),\n );\n return () => subscription.remove();\n },\n };\n}\n\n@Service()\nexport class Screen {\n /** Overridden in a test to resize the screen, or rotate it. */\n static readonly SOURCE = new InjectionToken<ScreenSource>('angular-native.screenSource', {\n factory: screenSource,\n });\n\n private readonly source = inject(Screen.SOURCE);\n private readonly safeArea = inject(SafeArea);\n private readonly sizes = signal<Sizes>(this.source.current());\n\n /**\n * What the app can draw in: the one almost everything wants.\n *\n * Measured by the safe-area provider rather than read from `Dimensions`, because on Android 15\n * an app draws edge to edge - behind the status and navigation bars - and `Dimensions` reports\n * the area between them instead. On a 1080x2400 phone that was 838.5pt against a real drawable\n * height of 914.3, so viewport units, height media queries and anything sizing itself from this\n * were all short by the bars. The provider measures the frame it was actually handed, which is\n * the drawable area by definition and on both platforms.\n *\n * `Dimensions` is the fallback for the one frame between mounting and the provider laying out,\n * because a window of zero for that frame would be worse than a slightly wrong one. An app with\n * no `<safe-area-provider>` never gets past the fallback, which is the behaviour it had before.\n */\n readonly window: Signal<Size> = computed(() => {\n const frame = this.safeArea.frame();\n return frame ? { width: frame.width, height: frame.height } : this.sizes().window;\n });\n /** The physical display, which on Android is larger than the window. */\n readonly display: Signal<Size> = computed(() => this.sizes().screen);\n readonly orientation: Signal<'portrait' | 'landscape'> = computed(() =>\n this.window().width > this.window().height ? 'landscape' : 'portrait',\n );\n\n /**\n * Whether the window is narrow enough to want the phone layout.\n *\n * The one branch a component library actually needs, and the reason it is a signal rather than\n * a media query: a sidebar that is a rail on an iPad and a sheet on a phone is not two sets of\n * classes on one tree, it is two different trees. shadcn's own sidebar branches in JavaScript\n * for exactly this reason, and `@media` in the stylesheet cannot decide which components to\n * build. Where the difference *is* only classes, write `md:` and let the cascade do it - the\n * compiler answers width, height and orientation queries, so Tailwind's breakpoints work.\n *\n * `COMPACT_WIDTH` is Tailwind's `md`, which is also the number `useIsMobile` uses upstream.\n * It is close to, but not the same as, iOS's own compact/regular width class: an iPad mini in\n * portrait is 744pt, which Apple calls regular and this calls compact. Close enough to be the\n * right default and named so an app that disagrees can say so.\n */\n readonly compact: Signal<boolean> = computed(() => this.window().width < COMPACT_WIDTH);\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((sizes) => this.sizes.set(sizes)));\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The system share sheet.
3
+ *
4
+ * `Share.share` resolves either way - dismissing the sheet is not an error - and the distinction
5
+ * it draws is one a caller usually wants: `shared` means an app took the content, `dismissed`
6
+ * means they changed their mind, and only the first is worth a confirmation or an analytics event.
7
+ */
8
+ import { InjectionToken } from '@angular/core';
9
+ import * as i0 from "@angular/core";
10
+ export interface ShareRequest {
11
+ /** What is being shared. At least one of these; iOS prefers `url` when both are present. */
12
+ readonly message?: string;
13
+ readonly url?: string;
14
+ /** Android's dialog title, and iOS's mail subject. */
15
+ readonly title?: string;
16
+ }
17
+ export interface NativeSharing {
18
+ share(request: ShareRequest): Promise<{
19
+ action: string;
20
+ activityType?: string | null;
21
+ }>;
22
+ }
23
+ export declare function sharingSource(): NativeSharing | null;
24
+ export declare class Sharing {
25
+ /** Overridden in a test to answer the sheet without one opening. */
26
+ static readonly SOURCE: InjectionToken<NativeSharing | null>;
27
+ private readonly native;
28
+ /**
29
+ * Open the share sheet. Resolves to whether anything took the content.
30
+ *
31
+ * Failures resolve to false rather than rejecting: the sheet failing to open and the user
32
+ * closing it are the same outcome at the call site, and neither is exceptional.
33
+ */
34
+ share(request: ShareRequest): Promise<boolean>;
35
+ static ɵfac: i0.ɵɵFactoryDeclaration<Sharing, never>;
36
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
37
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The system share sheet.
3
+ *
4
+ * `Share.share` resolves either way - dismissing the sheet is not an error - and the distinction
5
+ * it draws is one a caller usually wants: `shared` means an app took the content, `dismissed`
6
+ * means they changed their mind, and only the first is worth a confirmation or an analytics event.
7
+ */
8
+ import { InjectionToken, Service, inject } from '@angular/core';
9
+ import { reactNative } from "./react-native.js";
10
+ import * as i0 from "@angular/core";
11
+ export function sharingSource() {
12
+ const native = reactNative();
13
+ if (!native)
14
+ return null;
15
+ const android = native.Platform.OS === 'android';
16
+ return { share: (request) => native.Share.share(android ? forAndroid(request) : request) };
17
+ }
18
+ /**
19
+ * `Share.share` on Android reads `title` and `message` and nothing else - `url` is not a field
20
+ * React Native's own Android module looks at, so a request built the iOS way, `{ url, title }`
21
+ * with no `message`, opens a sheet with a title and an empty body and nothing to actually share.
22
+ * React Native's own docs say as much: Android's `message` "will often include a URL". Folding it
23
+ * in here is what makes `share({ url, title })` behave the same on both platforms, as the type
24
+ * says it should.
25
+ */
26
+ function forAndroid(request) {
27
+ if (!request.url)
28
+ return request;
29
+ const message = request.message ? `${request.message}\n${request.url}` : request.url;
30
+ return { title: request.title, message };
31
+ }
32
+ export class Sharing {
33
+ /** Overridden in a test to answer the sheet without one opening. */
34
+ static SOURCE = new InjectionToken('angular-native.sharingSource', { factory: sharingSource });
35
+ native = inject(Sharing.SOURCE);
36
+ /**
37
+ * Open the share sheet. Resolves to whether anything took the content.
38
+ *
39
+ * Failures resolve to false rather than rejecting: the sheet failing to open and the user
40
+ * closing it are the same outcome at the call site, and neither is exceptional.
41
+ */
42
+ async share(request) {
43
+ if (!this.native)
44
+ return false;
45
+ if (!request.message && !request.url)
46
+ return false;
47
+ try {
48
+ const { action } = await this.native.share(request);
49
+ return action === 'sharedAction';
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Sharing, deps: [], target: i0.ɵɵFactoryTarget.Service });
56
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Sharing });
57
+ }
58
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Sharing, decorators: [{
59
+ type: Service
60
+ }] });
61
+ //# sourceMappingURL=sharing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharing.js","sourceRoot":"","sources":["../src/sharing.ts"],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AC,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;YAAE,OAAO,KAAK,CAAC;QAEnD,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpD,OAAO,MAAM,KAAK,cAAc,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;uGAzBU,OAAO;wGAAP,OAAO;;2FAAP,OAAO;kBADnB,OAAO","sourcesContent":["/**\n * The system share sheet.\n *\n * `Share.share` resolves either way - dismissing the sheet is not an error - and the distinction\n * it draws is one a caller usually wants: `shared` means an app took the content, `dismissed`\n * means they changed their mind, and only the first is worth a confirmation or an analytics event.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface ShareRequest {\n /** What is being shared. At least one of these; iOS prefers `url` when both are present. */\n readonly message?: string;\n readonly url?: string;\n /** Android's dialog title, and iOS's mail subject. */\n readonly title?: string;\n}\n\nexport interface NativeSharing {\n share(request: ShareRequest): Promise<{ action: string; activityType?: string | null }>;\n}\n\nexport function sharingSource(): NativeSharing | null {\n const native = reactNative();\n if (!native) return null;\n const android = native.Platform.OS === 'android';\n return { share: (request) => native.Share.share(android ? forAndroid(request) : request) };\n}\n\n/**\n * `Share.share` on Android reads `title` and `message` and nothing else - `url` is not a field\n * React Native's own Android module looks at, so a request built the iOS way, `{ url, title }`\n * with no `message`, opens a sheet with a title and an empty body and nothing to actually share.\n * React Native's own docs say as much: Android's `message` \"will often include a URL\". Folding it\n * in here is what makes `share({ url, title })` behave the same on both platforms, as the type\n * says it should.\n */\nfunction forAndroid(request: ShareRequest): ShareRequest {\n if (!request.url) return request;\n const message = request.message ? `${request.message}\\n${request.url}` : request.url;\n return { title: request.title, message };\n}\n\n@Service()\nexport class Sharing {\n /** Overridden in a test to answer the sheet without one opening. */\n static readonly SOURCE = new InjectionToken<NativeSharing | null>(\n 'angular-native.sharingSource',\n { factory: sharingSource },\n );\n\n private readonly native = inject(Sharing.SOURCE);\n\n /**\n * Open the share sheet. Resolves to whether anything took the content.\n *\n * Failures resolve to false rather than rejecting: the sheet failing to open and the user\n * closing it are the same outcome at the call site, and neither is exceptional.\n */\n async share(request: ShareRequest): Promise<boolean> {\n if (!this.native) return false;\n if (!request.message && !request.url) return false;\n\n try {\n const { action } = await this.native.share(request);\n return action === 'sharedAction';\n } catch {\n return false;\n }\n }\n}\n"]}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The status bar: what colour its text is, whether it is there at all, and how tall it is.
3
+ *
4
+ * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,
5
+ * and does it through a stack of entries so that a screen pushed on top can change the bar and
6
+ * the screen underneath gets its own back when that one leaves. None of the rendering survives
7
+ * without React - but the statics underneath do, and the stack is exactly what a navigation-driven
8
+ * app needs, so it is the part worth keeping.
9
+ *
10
+ * `expo-status-bar` is the same statics with a React component around them, so nothing here needs
11
+ * that package installed.
12
+ */
13
+ import { InjectionToken, type Signal } from '@angular/core';
14
+ import * as i0 from "@angular/core";
15
+ /** Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks. */
16
+ export type StatusBarStyle = 'default' | 'light' | 'dark';
17
+ /** What a claim asks for. Anything absent is left as whatever the claim underneath said. */
18
+ export interface StatusBarState {
19
+ readonly style?: StatusBarStyle;
20
+ readonly hidden?: boolean;
21
+ readonly animated?: boolean;
22
+ /** Android only: the bar's own background. iOS has no such thing. */
23
+ readonly backgroundColor?: string;
24
+ /** Android only: whether content draws underneath the bar. */
25
+ readonly translucent?: boolean;
26
+ }
27
+ /** Where the bar actually is. A fake stands in for the platform in tests. */
28
+ export interface StatusBarSource {
29
+ setStyle(style: StatusBarStyle, animated?: boolean): void;
30
+ setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;
31
+ setBackgroundColor(color: string, animated?: boolean): void;
32
+ setTranslucent(translucent: boolean): void;
33
+ /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */
34
+ readonly height: number | undefined;
35
+ }
36
+ export declare function statusBarSource(): StatusBarSource;
37
+ /**
38
+ * A stack, not a setter.
39
+ *
40
+ * A modal that makes the bar light has to put back whatever the screen behind it asked for when
41
+ * it is dismissed, and nothing else in an app remembers what that was. `push` returns the
42
+ * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.
43
+ */
44
+ export declare class StatusBar {
45
+ /** Overridden in a test to watch the bar without one on screen. */
46
+ static readonly SOURCE: InjectionToken<StatusBarSource>;
47
+ private readonly source;
48
+ private readonly stack;
49
+ /** What is actually showing: every claim in order, later ones winning per property. */
50
+ readonly state: Signal<StatusBarState>;
51
+ /**
52
+ * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout
53
+ * wants is the safe-area top inset, which `SafeArea` has.
54
+ */
55
+ readonly height: Signal<number>;
56
+ /** The base claim, for an app that sets the bar once at startup. */
57
+ set(state: StatusBarState): void;
58
+ /** A claim on top of whatever is there. Call the returned function to drop it. */
59
+ push(state: StatusBarState): () => void;
60
+ /**
61
+ * Push the merged state at the platform.
62
+ *
63
+ * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff
64
+ * would have to know which properties a *dropped* claim had been holding.
65
+ */
66
+ private apply;
67
+ static ɵfac: i0.ɵɵFactoryDeclaration<StatusBar, never>;
68
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
69
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The status bar: what colour its text is, whether it is there at all, and how tall it is.
3
+ *
4
+ * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,
5
+ * and does it through a stack of entries so that a screen pushed on top can change the bar and
6
+ * the screen underneath gets its own back when that one leaves. None of the rendering survives
7
+ * without React - but the statics underneath do, and the stack is exactly what a navigation-driven
8
+ * app needs, so it is the part worth keeping.
9
+ *
10
+ * `expo-status-bar` is the same statics with a React component around them, so nothing here needs
11
+ * that package installed.
12
+ */
13
+ import { InjectionToken, Service, computed, inject, signal } from '@angular/core';
14
+ import { reactNative } from "./react-native.js";
15
+ import * as i0 from "@angular/core";
16
+ /** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */
17
+ const BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' };
18
+ export function statusBarSource() {
19
+ const native = reactNative();
20
+ if (!native) {
21
+ return {
22
+ setStyle: () => { },
23
+ setHidden: () => { },
24
+ setBackgroundColor: () => { },
25
+ setTranslucent: () => { },
26
+ height: undefined,
27
+ };
28
+ }
29
+ const { StatusBar } = native;
30
+ return {
31
+ setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),
32
+ setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),
33
+ setBackgroundColor: (color, animated) => StatusBar.setBackgroundColor(color, animated),
34
+ setTranslucent: (translucent) => StatusBar.setTranslucent(translucent),
35
+ get height() {
36
+ return StatusBar.currentHeight;
37
+ },
38
+ };
39
+ }
40
+ /**
41
+ * A stack, not a setter.
42
+ *
43
+ * A modal that makes the bar light has to put back whatever the screen behind it asked for when
44
+ * it is dismissed, and nothing else in an app remembers what that was. `push` returns the
45
+ * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.
46
+ */
47
+ export class StatusBar {
48
+ /** Overridden in a test to watch the bar without one on screen. */
49
+ static SOURCE = new InjectionToken('angular-native.statusBarSource', {
50
+ factory: statusBarSource,
51
+ });
52
+ source = inject(StatusBar.SOURCE);
53
+ stack = signal([], /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "stack" }] : /* istanbul ignore next */ []));
55
+ /** What is actually showing: every claim in order, later ones winning per property. */
56
+ state = computed(() => this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}), /* @ts-ignore */
57
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
58
+ /**
59
+ * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout
60
+ * wants is the safe-area top inset, which `SafeArea` has.
61
+ */
62
+ height = signal(this.source.height ?? 0).asReadonly();
63
+ /** The base claim, for an app that sets the bar once at startup. */
64
+ set(state) {
65
+ this.stack.update((entries) => [state, ...entries.slice(1)]);
66
+ this.apply();
67
+ }
68
+ /** A claim on top of whatever is there. Call the returned function to drop it. */
69
+ push(state) {
70
+ const entry = { ...state };
71
+ this.stack.update((entries) => [...entries, entry]);
72
+ this.apply();
73
+ return () => {
74
+ this.stack.update((entries) => entries.filter((one) => one !== entry));
75
+ this.apply();
76
+ };
77
+ }
78
+ /**
79
+ * Push the merged state at the platform.
80
+ *
81
+ * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff
82
+ * would have to know which properties a *dropped* claim had been holding.
83
+ */
84
+ apply() {
85
+ const { style, hidden, animated, backgroundColor, translucent } = this.state();
86
+ if (style !== undefined)
87
+ this.source.setStyle(style, animated);
88
+ if (hidden !== undefined)
89
+ this.source.setHidden(hidden, animated ? 'fade' : undefined);
90
+ if (backgroundColor !== undefined)
91
+ this.source.setBackgroundColor(backgroundColor, animated);
92
+ if (translucent !== undefined)
93
+ this.source.setTranslucent(translucent);
94
+ }
95
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
96
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: StatusBar });
97
+ }
98
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, decorators: [{
99
+ type: Service
100
+ }] });
101
+ //# sourceMappingURL=status-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EA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f,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACK,KAAK;QACX,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC/E,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/D,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACvF,IAAI,eAAe,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAC7F,IAAI,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACzE,CAAC;uGAlDU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport { InjectionToken, Service, computed, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/** Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks. */\nexport type StatusBarStyle = 'default' | 'light' | 'dark';\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /** Android only: the bar's own background. iOS has no such thing. */\n readonly backgroundColor?: string;\n /** Android only: whether content draws underneath the bar. */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: StatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) {\n return {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n };\n }\n\n const { StatusBar } = native;\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => StatusBar.setBackgroundColor(color, animated),\n setTranslucent: (translucent) => StatusBar.setTranslucent(translucent),\n get height() {\n return StatusBar.currentHeight;\n },\n };\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n private readonly stack = signal<readonly StatusBarState[]>([]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff\n * would have to know which properties a *dropped* claim had been holding.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = this.state();\n if (style !== undefined) this.source.setStyle(style, animated);\n if (hidden !== undefined) this.source.setHidden(hidden, animated ? 'fade' : undefined);\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (translucent !== undefined) this.source.setTranslucent(translucent);\n }\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Vibration, which is not haptics.
3
+ *
4
+ * `Haptics` is the Taptic Engine: a tap, a nudge, a success chime you feel rather than hear, tied
5
+ * to something the user just did. This is the motor - a buzz of a stated length, or a pattern -
6
+ * and it is what an alarm, a timer or an incoming call uses. An app that wants feedback for a
7
+ * button press wants the other one.
8
+ *
9
+ * iOS has one duration and ignores the number, so a pattern there is on and off at a fixed
10
+ * strength; Android takes the milliseconds as written. Both are said plainly rather than papered
11
+ * over, because a pattern designed on Android does not feel the same on iOS and nothing here can
12
+ * make it.
13
+ */
14
+ import { InjectionToken } from '@angular/core';
15
+ import * as i0 from "@angular/core";
16
+ export interface NativeVibration {
17
+ vibrate(pattern?: number | number[], repeat?: boolean): void;
18
+ cancel(): void;
19
+ }
20
+ export declare class Vibration {
21
+ /** Overridden in a test to record a buzz without one happening. */
22
+ static readonly SOURCE: InjectionToken<NativeVibration | null>;
23
+ private readonly native;
24
+ /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */
25
+ buzz(durationMs?: number): void;
26
+ /**
27
+ * A pattern of waits and buzzes, in milliseconds, starting with a wait.
28
+ *
29
+ * `repeat` runs it until `stop()`, which is for something that must be answered - an alarm, a
30
+ * call - and is a promise to call `stop` rather than a decoration.
31
+ */
32
+ pattern(millis: readonly number[], options?: {
33
+ repeat?: boolean;
34
+ }): void;
35
+ stop(): void;
36
+ static ɵfac: i0.ɵɵFactoryDeclaration<Vibration, never>;
37
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
38
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Vibration, which is not haptics.
3
+ *
4
+ * `Haptics` is the Taptic Engine: a tap, a nudge, a success chime you feel rather than hear, tied
5
+ * to something the user just did. This is the motor - a buzz of a stated length, or a pattern -
6
+ * and it is what an alarm, a timer or an incoming call uses. An app that wants feedback for a
7
+ * button press wants the other one.
8
+ *
9
+ * iOS has one duration and ignores the number, so a pattern there is on and off at a fixed
10
+ * strength; Android takes the milliseconds as written. Both are said plainly rather than papered
11
+ * over, because a pattern designed on Android does not feel the same on iOS and nothing here can
12
+ * make it.
13
+ */
14
+ import { InjectionToken, Service, inject } from '@angular/core';
15
+ import { reactNative } from "./react-native.js";
16
+ import * as i0 from "@angular/core";
17
+ export class Vibration {
18
+ /** Overridden in a test to record a buzz without one happening. */
19
+ static SOURCE = new InjectionToken('angular-native.vibrationSource', { factory: () => reactNative()?.Vibration ?? null });
20
+ native = inject(Vibration.SOURCE);
21
+ /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */
22
+ buzz(durationMs = 400) {
23
+ this.native?.vibrate(durationMs);
24
+ }
25
+ /**
26
+ * A pattern of waits and buzzes, in milliseconds, starting with a wait.
27
+ *
28
+ * `repeat` runs it until `stop()`, which is for something that must be answered - an alarm, a
29
+ * call - and is a promise to call `stop` rather than a decoration.
30
+ */
31
+ pattern(millis, options = {}) {
32
+ this.native?.vibrate([...millis], options.repeat ?? false);
33
+ }
34
+ stop() {
35
+ this.native?.cancel();
36
+ }
37
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Vibration, deps: [], target: i0.ɵɵFactoryTarget.Service });
38
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Vibration });
39
+ }
40
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Vibration, decorators: [{
41
+ type: Service
42
+ }] });
43
+ //# sourceMappingURL=vibration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vibration.js","sourceRoot":"","sources":["../src/vibration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAQhD,MAAM,OAAO,SAAS;IACpB,mEAAmE;IACnE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,gCAAgC,EAChC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,IAAI,IAAI,EAAE,CACpD,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAEnD,uFAAuF;IACvF,IAAI,CAAC,UAAU,GAAG,GAAG;QACnB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,MAAyB,EAAE,UAAgC,EAAE;QACnE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IACxB,CAAC;uGA1BU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Vibration, which is not haptics.\n *\n * `Haptics` is the Taptic Engine: a tap, a nudge, a success chime you feel rather than hear, tied\n * to something the user just did. This is the motor - a buzz of a stated length, or a pattern -\n * and it is what an alarm, a timer or an incoming call uses. An app that wants feedback for a\n * button press wants the other one.\n *\n * iOS has one duration and ignores the number, so a pattern there is on and off at a fixed\n * strength; Android takes the milliseconds as written. Both are said plainly rather than papered\n * over, because a pattern designed on Android does not feel the same on iOS and nothing here can\n * make it.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeVibration {\n vibrate(pattern?: number | number[], repeat?: boolean): void;\n cancel(): void;\n}\n\n@Service()\nexport class Vibration {\n /** Overridden in a test to record a buzz without one happening. */\n static readonly SOURCE = new InjectionToken<NativeVibration | null>(\n 'angular-native.vibrationSource',\n { factory: () => reactNative()?.Vibration ?? null },\n );\n\n private readonly native = inject(Vibration.SOURCE);\n\n /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */\n buzz(durationMs = 400): void {\n this.native?.vibrate(durationMs);\n }\n\n /**\n * A pattern of waits and buzzes, in milliseconds, starting with a wait.\n *\n * `repeat` runs it until `stop()`, which is for something that must be answered - an alarm, a\n * call - and is a promise to call `stop` rather than a decoration.\n */\n pattern(millis: readonly number[], options: { repeat?: boolean } = {}): void {\n this.native?.vibrate([...millis], options.repeat ?? false);\n }\n\n stop(): void {\n this.native?.cancel();\n }\n}\n"]}