@ng-native/device 0.22.1 → 0.23.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 (132) hide show
  1. package/dist/accessibility.d.ts +7 -0
  2. package/dist/accessibility.js +14 -2
  3. package/dist/accessibility.js.map +1 -1
  4. package/dist/app-lifecycle.d.ts +49 -0
  5. package/dist/app-lifecycle.js +67 -0
  6. package/dist/app-lifecycle.js.map +1 -0
  7. package/dist/app-state.d.ts +2 -0
  8. package/dist/app-state.js +2 -0
  9. package/dist/app-state.js.map +1 -1
  10. package/dist/app-windows.d.ts +321 -0
  11. package/dist/app-windows.js +526 -0
  12. package/dist/app-windows.js.map +1 -0
  13. package/dist/color-scheme.d.ts +2 -0
  14. package/dist/color-scheme.js +2 -0
  15. package/dist/color-scheme.js.map +1 -1
  16. package/dist/conditions.d.ts +11 -3
  17. package/dist/conditions.js +42 -9
  18. package/dist/conditions.js.map +1 -1
  19. package/dist/control-size.d.ts +6 -0
  20. package/dist/control-size.js +2 -0
  21. package/dist/control-size.js.map +1 -0
  22. package/dist/deep-links.d.ts +3 -1
  23. package/dist/deep-links.js +3 -1
  24. package/dist/deep-links.js.map +1 -1
  25. package/dist/desktop-options.d.ts +73 -0
  26. package/dist/desktop-options.js +182 -0
  27. package/dist/desktop-options.js.map +1 -0
  28. package/dist/desktop-permissions.d.ts +30 -0
  29. package/dist/desktop-permissions.js +169 -0
  30. package/dist/desktop-permissions.js.map +1 -0
  31. package/dist/dev-menu.d.ts +2 -2
  32. package/dist/dev-menu.js +3 -5
  33. package/dist/dev-menu.js.map +1 -1
  34. package/dist/dialogs.d.ts +9 -7
  35. package/dist/dialogs.js +15 -10
  36. package/dist/dialogs.js.map +1 -1
  37. package/dist/direction.d.ts +2 -0
  38. package/dist/direction.js +2 -0
  39. package/dist/direction.js.map +1 -1
  40. package/dist/dock.d.ts +48 -0
  41. package/dist/dock.js +70 -0
  42. package/dist/dock.js.map +1 -0
  43. package/dist/drag-and-drop.d.ts +67 -0
  44. package/dist/drag-and-drop.js +74 -0
  45. package/dist/drag-and-drop.js.map +1 -0
  46. package/dist/expo-view-name.d.ts +16 -0
  47. package/dist/expo-view-name.js +22 -0
  48. package/dist/expo-view-name.js.map +1 -0
  49. package/dist/hardware-back.d.ts +3 -10
  50. package/dist/hardware-back.js +4 -1
  51. package/dist/hardware-back.js.map +1 -1
  52. package/dist/index.d.ts +26 -2
  53. package/dist/index.js +26 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/interaction-observer.d.ts +117 -0
  56. package/dist/interaction-observer.js +241 -0
  57. package/dist/interaction-observer.js.map +1 -0
  58. package/dist/keyboard.d.ts +2 -8
  59. package/dist/keyboard.js +3 -0
  60. package/dist/keyboard.js.map +1 -1
  61. package/dist/layout-animation.d.ts +3 -1
  62. package/dist/layout-animation.js +3 -1
  63. package/dist/layout-animation.js.map +1 -1
  64. package/dist/menu-model.d.ts +108 -0
  65. package/dist/menu-model.js +259 -0
  66. package/dist/menu-model.js.map +1 -0
  67. package/dist/menu-template.d.ts +19 -0
  68. package/dist/menu-template.js +31 -0
  69. package/dist/menu-template.js.map +1 -0
  70. package/dist/menus.d.ts +225 -0
  71. package/dist/menus.js +341 -0
  72. package/dist/menus.js.map +1 -0
  73. package/dist/navigation-bar.d.ts +2 -12
  74. package/dist/navigation-bar.js +4 -1
  75. package/dist/navigation-bar.js.map +1 -1
  76. package/dist/os-support.d.ts +42 -0
  77. package/dist/os-support.js +207 -0
  78. package/dist/os-support.js.map +1 -0
  79. package/dist/os.d.ts +26 -5
  80. package/dist/os.js +35 -7
  81. package/dist/os.js.map +1 -1
  82. package/dist/own-host.d.ts +27 -0
  83. package/dist/own-host.js +79 -0
  84. package/dist/own-host.js.map +1 -0
  85. package/dist/processes.d.ts +116 -0
  86. package/dist/processes.js +177 -0
  87. package/dist/processes.js.map +1 -0
  88. package/dist/react-native.d.ts +19 -0
  89. package/dist/react-native.js.map +1 -1
  90. package/dist/safe-area.d.ts +12 -1
  91. package/dist/safe-area.js +16 -2
  92. package/dist/safe-area.js.map +1 -1
  93. package/dist/screen.d.ts +2 -0
  94. package/dist/screen.js +2 -0
  95. package/dist/screen.js.map +1 -1
  96. package/dist/sharing.d.ts +3 -1
  97. package/dist/sharing.js +8 -1
  98. package/dist/sharing.js.map +1 -1
  99. package/dist/shell.d.ts +33 -0
  100. package/dist/shell.js +73 -0
  101. package/dist/shell.js.map +1 -0
  102. package/dist/shortcut.d.ts +49 -0
  103. package/dist/shortcut.js +92 -0
  104. package/dist/shortcut.js.map +1 -0
  105. package/dist/sidebar-selection.d.ts +8 -0
  106. package/dist/sidebar-selection.js +9 -0
  107. package/dist/sidebar-selection.js.map +1 -0
  108. package/dist/spawn-rules.d.ts +108 -0
  109. package/dist/spawn-rules.js +313 -0
  110. package/dist/spawn-rules.js.map +1 -0
  111. package/dist/split-views.d.ts +7 -0
  112. package/dist/split-views.js +21 -0
  113. package/dist/split-views.js.map +1 -0
  114. package/dist/status-bar.d.ts +2 -12
  115. package/dist/status-bar.js +3 -0
  116. package/dist/status-bar.js.map +1 -1
  117. package/dist/tray.d.ts +63 -0
  118. package/dist/tray.js +76 -0
  119. package/dist/tray.js.map +1 -0
  120. package/dist/undo-stack.d.ts +64 -0
  121. package/dist/undo-stack.js +110 -0
  122. package/dist/undo-stack.js.map +1 -0
  123. package/dist/vibration.d.ts +3 -14
  124. package/dist/vibration.js +4 -1
  125. package/dist/vibration.js.map +1 -1
  126. package/dist/window-navigator.d.ts +25 -0
  127. package/dist/window-navigator.js +7 -0
  128. package/dist/window-navigator.js.map +1 -0
  129. package/dist/window-restore.d.ts +45 -0
  130. package/dist/window-restore.js +66 -0
  131. package/dist/window-restore.js.map +1 -0
  132. package/package.json +10 -2
@@ -1 +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,OA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,EAAE;YACd,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC;YAC5D,wFAAwF;YACxF,gEAAgE;YAChE,IAAI,MAAM,KAAK,IAAI;gBAAE,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,YAAY,CAAC;oBAAE,QAAQ,EAAE,CAAC;QAC5E,CAAC;KACF,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\n/**\n * Every source's listeners, told of a scheme the app sets. React Native takes it at once but\n * reports it only when its root view next changes appearance, and on iOS a full-screen modal takes\n * that view out of the window, so the change arrived when the modal closed. The platform's own\n * report, when it comes, repeats the same scheme.\n */\nconst setListeners = new Set<() => void>();\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 // Each scheme once: the platform's report repeats one the app set, and it also reports\n // appearance changes that are not the scheme.\n let last = read();\n const onChange = () => {\n const scheme = read();\n if (scheme === last) return;\n last = scheme;\n listener(scheme);\n };\n const subscription = native.Appearance.addChangeListener(onChange);\n setListeners.add(onChange);\n return () => {\n subscription.remove();\n setListeners.delete(onChange);\n };\n },\n set: (scheme) => {\n native.Appearance.setColorScheme?.(scheme ?? 'unspecified');\n // Back to the system's waits for the platform's report: React Native resolves it from a\n // native cache that a full-screen modal on iOS can leave stale.\n if (scheme !== null) for (const listener of [...setListeners]) listener();\n },\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"]}
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;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAc,CAAC;AAE3C,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,uFAAuF;YACvF,8CAA8C;YAC9C,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;YAClB,MAAM,QAAQ,GAAG,GAAG,EAAE;gBACpB,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;gBACtB,IAAI,MAAM,KAAK,IAAI;oBAAE,OAAO;gBAC5B,IAAI,GAAG,MAAM,CAAC;gBACd,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnB,CAAC,CAAC;YACF,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YACnE,YAAY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1BU,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\n/**\n * Every source's listeners, told of a scheme the app sets. React Native takes it at once but\n * reports it only when its root view next changes appearance, and on iOS a full-screen modal takes\n * that view out of the window, so the change arrived when the modal closed. The platform's own\n * report, when it comes, repeats the same scheme.\n */\nconst setListeners = new Set<() => void>();\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 // Each scheme once: the platform's report repeats one the app set, and it also reports\n // appearance changes that are not the scheme.\n let last = read();\n const onChange = () => {\n const scheme = read();\n if (scheme === last) return;\n last = scheme;\n listener(scheme);\n };\n const subscription = native.Appearance.addChangeListener(onChange);\n setListeners.add(onChange);\n return () => {\n subscription.remove();\n setListeners.delete(onChange);\n };\n },\n set: (scheme) => {\n native.Appearance.setColorScheme?.(scheme ?? 'unspecified');\n // Back to the system's waits for the platform's report: React Native resolves it from a\n // native cache that a full-screen modal on iOS can leave stale.\n if (scheme !== null) for (const listener of [...setListeners]) listener();\n },\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\n /** Whether the service is here: on every OS, where it answers what the OS reports. */\n readonly available: Signal<boolean> = signal(true).asReadonly();\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"]}
@@ -17,6 +17,8 @@ interface Resolves<Node = unknown> {
17
17
  removeClass(node: Node, name: string): void;
18
18
  /** Measure every text again, after the system text size changed. */
19
19
  remeasureText?(): void;
20
+ /** Merge custom properties into the root's, as `--hairline` after the pixel ratio changed. */
21
+ updateTokens?(tokens: Readonly<Record<string, TokenValue>>): void;
20
22
  }
21
23
  export interface WatchOptions {
22
24
  /**
@@ -36,11 +38,17 @@ export declare function currentConditions(): Conditions;
36
38
  * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of
37
39
  * the wrong weight in every test that draws one.
38
40
  *
39
- * Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so
40
- * a window moved to a screen of another density keeps the first screen's, as a React Native app's
41
- * `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.
41
+ * React Native works `StyleSheet.hairlineWidth` out once and keeps it. `watchConditions` hands
42
+ * the engine a new `--hairline` when a window resize reports another pixel ratio, as when a
43
+ * window moves to a screen of another density. The safe-area insets arrive through
44
+ * `updateTokens` too.
42
45
  */
43
46
  export declare function deviceTokens(): Record<string, TokenValue>;
47
+ /**
48
+ * The `--hairline` for a screen of `pixelRatio` pixels to the point: what a window on that screen
49
+ * draws its thinnest line with, as `watchConditions` gives the app's engine for the app's ratio.
50
+ */
51
+ export declare function hairlineTokens(pixelRatio: number): Record<string, TokenValue>;
44
52
  /**
45
53
  * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at
46
54
  * bootstrap will never use it.
@@ -1,12 +1,27 @@
1
- import { accessibilitySource } from "./accessibility.js";
1
+ import { accessibilitySource, systemFontScale } from "./accessibility.js";
2
2
  import { colorSchemeSource } from "./color-scheme.js";
3
3
  import { directionSource } from "./direction.js";
4
4
  import { recordKeyboard } from "./keyboard.js";
5
+ import { isPhoneOs, platformOs } from "./os.js";
5
6
  import { screenSource } from "./screen.js";
6
7
  import { reactNative } from "./react-native.js";
7
- /** The system text size, as a multiplier. One off a device. */
8
- function fontScale() {
9
- return reactNative()?.PixelRatio.getFontScale() ?? 1;
8
+ /**
9
+ * The pointer media features: a desktop hovers with a fine pointer, and a phone or tablet has a
10
+ * finger, coarse and unable to hover. An iPad with a trackpad still answers as a phone.
11
+ */
12
+ function pointerConditions() {
13
+ const desktop = !isPhoneOs(platformOs());
14
+ const hover = desktop ? 'hover' : 'none';
15
+ const pointer = desktop ? 'fine' : 'coarse';
16
+ return { hover, anyHover: hover, pointer, anyPointer: pointer };
17
+ }
18
+ /**
19
+ * The thinnest line a screen of `ratio` pixels to the point draws, worked out as React Native
20
+ * works out `StyleSheet.hairlineWidth`: 0.4 points rounded to a whole pixel, or one pixel where
21
+ * that rounds to none.
22
+ */
23
+ function hairlineAt(ratio) {
24
+ return Math.round(0.4 * ratio) / ratio || 1 / ratio;
10
25
  }
11
26
  /** The screen's pixels in a point. One off a device. */
12
27
  function pixelRatio() {
@@ -22,11 +37,12 @@ export function currentConditions() {
22
37
  // corrects it. Reduced motion is a preference about what happens next, not about the frame
23
38
  // already on screen, so nothing is lost by learning it a tick late.
24
39
  reducedMotion: false,
25
- fontScale: fontScale(),
40
+ fontScale: systemFontScale(),
26
41
  // Read again when the window is resized, which it is when it moves to a screen of another density.
27
42
  pixelRatio: pixelRatio(),
28
43
  // Settled while the native side starts up, and fixed until the app restarts.
29
44
  direction: directionSource().current(),
45
+ ...pointerConditions(),
30
46
  };
31
47
  }
32
48
  /**
@@ -38,14 +54,22 @@ export function currentConditions() {
38
54
  * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of
39
55
  * the wrong weight in every test that draws one.
40
56
  *
41
- * Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so
42
- * a window moved to a screen of another density keeps the first screen's, as a React Native app's
43
- * `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.
57
+ * React Native works `StyleSheet.hairlineWidth` out once and keeps it. `watchConditions` hands
58
+ * the engine a new `--hairline` when a window resize reports another pixel ratio, as when a
59
+ * window moves to a screen of another density. The safe-area insets arrive through
60
+ * `updateTokens` too.
44
61
  */
45
62
  export function deviceTokens() {
46
63
  const native = reactNative();
47
64
  return native ? { '--hairline': { length: native.StyleSheet.hairlineWidth } } : {};
48
65
  }
66
+ /**
67
+ * The `--hairline` for a screen of `pixelRatio` pixels to the point: what a window on that screen
68
+ * draws its thinnest line with, as `watchConditions` gives the app's engine for the app's ratio.
69
+ */
70
+ export function hairlineTokens(pixelRatio) {
71
+ return { '--hairline': { length: hairlineAt(pixelRatio) } };
72
+ }
49
73
  /**
50
74
  * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at
51
75
  * bootstrap will never use it.
@@ -83,7 +107,16 @@ export function watchConditions(engine, options = {}) {
83
107
  if (rescaled)
84
108
  engine.remeasureText?.();
85
109
  };
86
- const sizes = screen.subscribe(({ window }) => resize({ width: window.width, height: window.height, pixelRatio: pixelRatio() }, fontScale()));
110
+ // The hairline for the pixel ratio now in effect, handed over only when that changes.
111
+ let ratio = conditions.pixelRatio ?? 1;
112
+ const sizes = screen.subscribe(({ window }) => {
113
+ const next = pixelRatio();
114
+ resize({ width: window.width, height: window.height, pixelRatio: next }, systemFontScale());
115
+ if (next === ratio)
116
+ return;
117
+ ratio = next;
118
+ engine.updateTokens?.(hairlineTokens(next));
119
+ });
87
120
  const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));
88
121
  let heardReduceMotion = false;
89
122
  let stopped = false;
@@ -1 +1 @@
1
- {"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhD,+DAA+D;AAC/D,SAAS,SAAS;IAChB,OAAO,WAAW,EAAE,EAAE,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC;AAED,wDAAwD;AACxD,SAAS,UAAU;IACjB,OAAO,WAAW,EAAE,EAAE,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC;AAWD,MAAM,UAAU,iBAAiB;IAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC;IAC5C,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,WAAW,EAAE,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAC1C,8FAA8F;QAC9F,2FAA2F;QAC3F,oEAAoE;QACpE,aAAa,EAAE,KAAK;QACpB,SAAS,EAAE,SAAS,EAAE;QACtB,mGAAmG;QACnG,UAAU,EAAE,UAAU,EAAE;QACxB,6EAA6E;QAC7E,SAAS,EAAE,eAAe,EAAE,CAAC,OAAO,EAAE;KACvC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,WAAW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,IAAI,YAAY,IAAI,IAAI,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EACjF,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,OAAO,GAAG,IAAI,CAAC;QACf,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * What the engine evaluates media queries against, kept in step with the device.\n *\n * Not a service, because the engine is not injectable and has no reason to be: it is handed to\n * `mount` and handed back, and this connects the two. An app that wants `@media` to keep working\n * after a rotation or a theme change calls `watchConditions` once and never thinks about it again.\n *\n * A rotation changes no component and no binding, so nothing would be dirty and nothing would\n * re-render. The engine re-resolves and commits on its own when the conditions change.\n */\nimport type { Conditions, TokenValue } from '@ng-native/fabric';\nimport { accessibilitySource } from './accessibility.ts';\nimport { colorSchemeSource } from './color-scheme.ts';\nimport { directionSource } from './direction.ts';\nimport { recordKeyboard } from './keyboard.ts';\nimport { screenSource } from './screen.ts';\nimport { reactNative } from './react-native.ts';\n\n/** Just enough of the engine to be told. */\ninterface Resolves<Node = unknown> {\n readonly root: Node;\n updateConditions(conditions: Conditions): void;\n addClass(node: Node, name: string): void;\n removeClass(node: Node, name: string): void;\n /** Measure every text again, after the system text size changed. */\n remeasureText?(): void;\n}\n\n/** The system text size, as a multiplier. One off a device. */\nfunction fontScale(): number {\n return reactNative()?.PixelRatio.getFontScale() ?? 1;\n}\n\n/** The screen's pixels in a point. One off a device. */\nfunction pixelRatio(): number {\n return reactNative()?.PixelRatio.get() ?? 1;\n}\n\nexport interface WatchOptions {\n /**\n * Keep a `dark` class on the root in step with the system scheme, which is what\n * `@ng-native/tailwind`'s `dark:` variant matches. On by default; an app with its own theme\n * switch turns it off and puts `dark` on its own root view instead.\n */\n readonly darkClass?: boolean;\n}\n\nexport function currentConditions(): Conditions {\n const { window } = screenSource().current();\n return {\n width: window.width,\n height: window.height,\n colorScheme: colorSchemeSource().current(),\n // Asynchronous on both platforms, so the first paint says no preference and `watchConditions`\n // corrects it. Reduced motion is a preference about what happens next, not about the frame\n // already on screen, so nothing is lost by learning it a tick late.\n reducedMotion: false,\n fontScale: fontScale(),\n // Read again when the window is resized, which it is when it moves to a screen of another density.\n pixelRatio: pixelRatio(),\n // Settled while the native side starts up, and fixed until the app restarts.\n direction: directionSource().current(),\n };\n}\n\n/**\n * Custom properties the device settles before the first frame, for `mount`'s `tokens` option.\n *\n * Only the hairline so far: the thinnest line the screen can draw, which is a third of a point on\n * a 3x phone and half of one on a 2x. `1px` is what a browser would give and is a visibly fat\n * divider on a modern screen, so a native-looking rule has to ask. React Native works the number\n * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of\n * the wrong weight in every test that draws one.\n *\n * Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so\n * a window moved to a screen of another density keeps the first screen's, as a React Native app's\n * `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.\n */\nexport function deviceTokens(): Record<string, TokenValue> {\n const native = reactNative();\n return native ? { '--hairline': { length: native.StyleSheet.hairlineWidth } } : {};\n}\n\n/**\n * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at\n * bootstrap will never use it.\n */\nexport function watchConditions<Node>(\n engine: Resolves<Node>,\n options: WatchOptions = {},\n): () => void {\n // Not a condition, but this is what runs at startup: see `recordKeyboard`.\n recordKeyboard();\n const screen = screenSource();\n const colors = colorSchemeSource();\n const accessibility = accessibilitySource();\n\n let conditions = currentConditions();\n const push = (change: Partial<Conditions>) => {\n conditions = { ...conditions, ...change };\n if (options.darkClass !== false) {\n if (conditions.colorScheme === 'dark') engine.addClass(engine.root, 'dark');\n else engine.removeClass(engine.root, 'dark');\n }\n engine.updateConditions(conditions);\n };\n // The class for the scheme the app started in, committed at once. Light needs nothing: an app\n // starting light is exactly what it already rendered.\n if (options.darkClass !== false && conditions.colorScheme === 'dark') push({});\n\n // The system text size. Every text on screen was measured at the old one, and keeps that box\n // until it is measured again, so a change goes into the conditions and then re-measures them\n // all. A change arrives as a `Dimensions` change on both platforms; the app coming back to the\n // foreground is checked as well, and the same change reported by both is re-measured once.\n let scale = conditions.fontScale ?? 1;\n const resize = (change: Partial<Conditions>, next: number) => {\n const rescaled = next !== scale;\n scale = next;\n push({ ...change, fontScale: next });\n if (rescaled) engine.remeasureText?.();\n };\n\n const sizes = screen.subscribe(({ window }) =>\n resize({ width: window.width, height: window.height, pixelRatio: pixelRatio() }, fontScale()),\n );\n const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));\n let heardReduceMotion = false;\n let stopped = false;\n const settings = accessibility.subscribe((change) => {\n if (change.fontScale !== undefined && change.fontScale !== scale) resize({}, change.fontScale);\n if (change.reduceMotion !== undefined) {\n heardReduceMotion = true;\n push({ reducedMotion: change.reduceMotion });\n }\n });\n // A read that fails leaves no reduced motion, as the first paint assumed.\n accessibility.current().then(\n ({ reduceMotion }) =>\n !stopped && !heardReduceMotion && reduceMotion && push({ reducedMotion: true }),\n () => {},\n );\n\n return () => {\n stopped = true;\n sizes();\n scheme();\n settings();\n };\n}\n"]}
1
+ {"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAchD;;;GAGG;AACH,SAAS,iBAAiB;IACxB,MAAM,OAAO,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE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,CAAC;QAC/F,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACtC,iBAAiB,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,0EAA0E;IAC1E,aAAa,CAAC,OAAO,EAAE,CAAC,IAAI,CAC1B,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACnB,CAAC,OAAO,IAAI,CAAC,iBAAiB,IAAI,YAAY,IAAI,IAAI,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EACjF,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,OAAO,GAAG,IAAI,CAAC;QACf,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * What the engine evaluates media queries against, kept in step with the device.\n *\n * Not a service, because the engine is not injectable and has no reason to be: it is handed to\n * `mount` and handed back, and this connects the two. An app that wants `@media` to keep working\n * after a rotation or a theme change calls `watchConditions` once and never thinks about it again.\n *\n * A rotation changes no component and no binding, so nothing would be dirty and nothing would\n * re-render. The engine re-resolves and commits on its own when the conditions change.\n */\nimport type { Conditions, TokenValue } from '@ng-native/fabric';\nimport { accessibilitySource, systemFontScale } from './accessibility.ts';\nimport { colorSchemeSource } from './color-scheme.ts';\nimport { directionSource } from './direction.ts';\nimport { recordKeyboard } from './keyboard.ts';\nimport { isPhoneOs, platformOs } from './os.ts';\nimport { screenSource } from './screen.ts';\nimport { reactNative } from './react-native.ts';\n\n/** Just enough of the engine to be told. */\ninterface Resolves<Node = unknown> {\n readonly root: Node;\n updateConditions(conditions: Conditions): void;\n addClass(node: Node, name: string): void;\n removeClass(node: Node, name: string): void;\n /** Measure every text again, after the system text size changed. */\n remeasureText?(): void;\n /** Merge custom properties into the root's, as `--hairline` after the pixel ratio changed. */\n updateTokens?(tokens: Readonly<Record<string, TokenValue>>): void;\n}\n\n/**\n * The pointer media features: a desktop hovers with a fine pointer, and a phone or tablet has a\n * finger, coarse and unable to hover. An iPad with a trackpad still answers as a phone.\n */\nfunction pointerConditions(): Pick<Conditions, 'hover' | 'anyHover' | 'pointer' | 'anyPointer'> {\n const desktop = !isPhoneOs(platformOs());\n const hover = desktop ? 'hover' : 'none';\n const pointer = desktop ? 'fine' : 'coarse';\n return { hover, anyHover: hover, pointer, anyPointer: pointer };\n}\n\n/**\n * The thinnest line a screen of `ratio` pixels to the point draws, worked out as React Native\n * works out `StyleSheet.hairlineWidth`: 0.4 points rounded to a whole pixel, or one pixel where\n * that rounds to none.\n */\nfunction hairlineAt(ratio: number): number {\n return Math.round(0.4 * ratio) / ratio || 1 / ratio;\n}\n\n/** The screen's pixels in a point. One off a device. */\nfunction pixelRatio(): number {\n return reactNative()?.PixelRatio.get() ?? 1;\n}\n\nexport interface WatchOptions {\n /**\n * Keep a `dark` class on the root in step with the system scheme, which is what\n * `@ng-native/tailwind`'s `dark:` variant matches. On by default; an app with its own theme\n * switch turns it off and puts `dark` on its own root view instead.\n */\n readonly darkClass?: boolean;\n}\n\nexport function currentConditions(): Conditions {\n const { window } = screenSource().current();\n return {\n width: window.width,\n height: window.height,\n colorScheme: colorSchemeSource().current(),\n // Asynchronous on both platforms, so the first paint says no preference and `watchConditions`\n // corrects it. Reduced motion is a preference about what happens next, not about the frame\n // already on screen, so nothing is lost by learning it a tick late.\n reducedMotion: false,\n fontScale: systemFontScale(),\n // Read again when the window is resized, which it is when it moves to a screen of another density.\n pixelRatio: pixelRatio(),\n // Settled while the native side starts up, and fixed until the app restarts.\n direction: directionSource().current(),\n ...pointerConditions(),\n };\n}\n\n/**\n * Custom properties the device settles before the first frame, for `mount`'s `tokens` option.\n *\n * Only the hairline so far: the thinnest line the screen can draw, which is a third of a point on\n * a 3x phone and half of one on a 2x. `1px` is what a browser would give and is a visibly fat\n * divider on a modern screen, so a native-looking rule has to ask. React Native works the number\n * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of\n * the wrong weight in every test that draws one.\n *\n * React Native works `StyleSheet.hairlineWidth` out once and keeps it. `watchConditions` hands\n * the engine a new `--hairline` when a window resize reports another pixel ratio, as when a\n * window moves to a screen of another density. The safe-area insets arrive through\n * `updateTokens` too.\n */\nexport function deviceTokens(): Record<string, TokenValue> {\n const native = reactNative();\n return native ? { '--hairline': { length: native.StyleSheet.hairlineWidth } } : {};\n}\n\n/**\n * The `--hairline` for a screen of `pixelRatio` pixels to the point: what a window on that screen\n * draws its thinnest line with, as `watchConditions` gives the app's engine for the app's ratio.\n */\nexport function hairlineTokens(pixelRatio: number): Record<string, TokenValue> {\n return { '--hairline': { length: hairlineAt(pixelRatio) } };\n}\n\n/**\n * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at\n * bootstrap will never use it.\n */\nexport function watchConditions<Node>(\n engine: Resolves<Node>,\n options: WatchOptions = {},\n): () => void {\n // Not a condition, but this is what runs at startup: see `recordKeyboard`.\n recordKeyboard();\n const screen = screenSource();\n const colors = colorSchemeSource();\n const accessibility = accessibilitySource();\n\n let conditions = currentConditions();\n const push = (change: Partial<Conditions>) => {\n conditions = { ...conditions, ...change };\n if (options.darkClass !== false) {\n if (conditions.colorScheme === 'dark') engine.addClass(engine.root, 'dark');\n else engine.removeClass(engine.root, 'dark');\n }\n engine.updateConditions(conditions);\n };\n // The class for the scheme the app started in, committed at once. Light needs nothing: an app\n // starting light is exactly what it already rendered.\n if (options.darkClass !== false && conditions.colorScheme === 'dark') push({});\n\n // The system text size. Every text on screen was measured at the old one, and keeps that box\n // until it is measured again, so a change goes into the conditions and then re-measures them\n // all. A change arrives as a `Dimensions` change on both platforms; the app coming back to the\n // foreground is checked as well, and the same change reported by both is re-measured once.\n let scale = conditions.fontScale ?? 1;\n const resize = (change: Partial<Conditions>, next: number) => {\n const rescaled = next !== scale;\n scale = next;\n push({ ...change, fontScale: next });\n if (rescaled) engine.remeasureText?.();\n };\n\n // The hairline for the pixel ratio now in effect, handed over only when that changes.\n let ratio = conditions.pixelRatio ?? 1;\n const sizes = screen.subscribe(({ window }) => {\n const next = pixelRatio();\n resize({ width: window.width, height: window.height, pixelRatio: next }, systemFontScale());\n if (next === ratio) return;\n ratio = next;\n engine.updateTokens?.(hairlineTokens(next));\n });\n const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));\n let heardReduceMotion = false;\n let stopped = false;\n const settings = accessibility.subscribe((change) => {\n if (change.fontScale !== undefined && change.fontScale !== scale) resize({}, change.fontScale);\n if (change.reduceMotion !== undefined) {\n heardReduceMotion = true;\n push({ reducedMotion: change.reduceMotion });\n }\n });\n // A read that fails leaves no reduced motion, as the first paint assumed.\n accessibility.current().then(\n ({ reduceMotion }) =>\n !stopped && !heardReduceMotion && reduceMotion && push({ reducedMotion: true }),\n () => {},\n );\n\n return () => {\n stopped = true;\n sizes();\n scheme();\n settings();\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * How a native control is sized: AppKit's control sizes on macOS, and on iOS UIKit's button sizes
3
+ * for `<native-button>`. Android and the web ignore it. Unset is `regular`. Taken by `<native-button>`, `<switch>`,
4
+ * `<activity-indicator>`, `<segmented-control>`, `<date-time-picker>` and `<search-field>`.
5
+ */
6
+ export type ControlSize = 'mini' | 'small' | 'regular' | 'large';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=control-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-size.js","sourceRoot":"","sources":["../src/control-size.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * How a native control is sized: AppKit's control sizes on macOS, and on iOS UIKit's button sizes\n * for `<native-button>`. Android and the web ignore it. Unset is `regular`. Taken by `<native-button>`, `<switch>`,\n * `<activity-indicator>`, `<segmented-control>`, `<date-time-picker>` and `<search-field>`.\n */\nexport type ControlSize = 'mini' | 'small' | 'regular' | 'large';\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.
3
3
  */
4
- import { InjectionToken } from '@angular/core';
4
+ import { InjectionToken, type Signal } from '@angular/core';
5
5
  import * as i0 from "@angular/core";
6
6
  export interface DeepLinkSource {
7
7
  /** The url the app was launched with. A promise, and nothing says it settles before mount. */
@@ -27,6 +27,8 @@ export declare class DeepLinks {
27
27
  /** Overridden in a test to deliver a link with no platform under it. */
28
28
  static readonly SOURCE: InjectionToken<DeepLinkSource>;
29
29
  private readonly source;
30
+ /** Whether the service is here: on every OS, where it answers what the OS reports. */
31
+ readonly available: Signal<boolean>;
30
32
  private readonly injector;
31
33
  private launch;
32
34
  private readonly listeners;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.
3
3
  */
4
- import { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';
4
+ import { ErrorHandler, InjectionToken, Injector, Service, inject, signal, } from '@angular/core';
5
5
  import { reactNative } from "./react-native.js";
6
6
  import * as i0 from "@angular/core";
7
7
  /**
@@ -95,6 +95,8 @@ export class DeepLinks {
95
95
  factory: deepLinkSource,
96
96
  });
97
97
  source = inject(DeepLinks.SOURCE);
98
+ /** Whether the service is here: on every OS, where it answers what the OS reports. */
99
+ available = signal(true).asReadonly();
98
100
  injector = inject(Injector);
99
101
  launch = null;
100
102
  listeners = new Set();
@@ -1 +1 @@
1
- {"version":3,"file":"deep-links.js","sourceRoot":"","sources":["../src/deep-links.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI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;OAGG;IACH,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,0FAA0F;IAC1F,IAAI,CAAC,GAAW;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC;uGAhFU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\n/**\n * React Native's `Linking`, with each url whole: the scheme, host, query and fragment that\n * `DeepLinks` strips to a path. Off a device, a source that never delivers a link.\n */\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\n/**\n * The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a\n * fragment, `/--/` is the app's own: a search for it is not a launch prefix.\n */\nfunction expoGoPath(rest: string): string | null {\n const end = rest.search(/[?#]/);\n const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');\n return marker === -1 ? null : rest.slice(marker + 3);\n}\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = expoGoPath(rest);\n if (expoGo !== null) return expoGo;\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /**\n * Follow a path of the app's own as a link to it that arrived from outside is followed: a\n * library that sets `location.href` to a page of the app goes there the way a link does.\n */\n follow(path: string): void {\n this.listeners.forEach((listener) => this.deliver(listener, path));\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
1
+ {"version":3,"file":"deep-links.js","sourceRoot":"","sources":["../src/deep-links.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,OAAO,EACP,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;YACzB,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;YACd,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;SACvB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE;QAC/C,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YACxF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACrC,CAAC;QACD,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,MAAM,CAA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J,CAAC;IAED;;;;OAIG;IACK,OAAO,CAAC,QAAgC,EAAE,IAAY;QAC5D,IAAI,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4FAA4F;YAC5F,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBACrD,IAAI,MAAM;oBAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;;oBACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,SAAS,EAAE,CAAC;gBACnB,IAAI,SAAS,KAAK,KAAK;oBAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;oBACzC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,0FAA0F;IAC1F,IAAI,CAAC,GAAW;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC;uGAnFU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport {\n ErrorHandler,\n InjectionToken,\n Injector,\n Service,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\n/**\n * React Native's `Linking`, with each url whole: the scheme, host, query and fragment that\n * `DeepLinks` strips to a path. Off a device, a source that never delivers a link.\n */\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\n/**\n * The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a\n * fragment, `/--/` is the app's own: a search for it is not a launch prefix.\n */\nfunction expoGoPath(rest: string): string | null {\n const end = rest.search(/[?#]/);\n const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');\n return marker === -1 ? null : rest.slice(marker + 3);\n}\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = expoGoPath(rest);\n if (expoGo !== null) return expoGo;\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n\n /** Whether the service is here: on every OS, where it answers what the OS reports. */\n readonly available: Signal<boolean> = signal(true).asReadonly();\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /**\n * Follow a path of the app's own as a link to it that arrived from outside is followed: a\n * library that sets `location.href` to a page of the app goes there the way a link does.\n */\n follow(path: string): void {\n this.listeners.forEach((listener) => this.deliver(listener, path));\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The `@ng-native/desktop` plugin's options in `app.json`, and their validation. They hold only
3
+ * what has to exist before JavaScript runs: the document types the app opens, its declared
4
+ * capabilities (programs it spawns, environment variables it reads and paths outside its own
5
+ * folders), and the libraries kept out of the desktop build.
6
+ *
7
+ * ["@ng-native/desktop", {
8
+ * "documentTypes": [{ "name": "Markdown", "extensions": ["md"], "role": "editor" }],
9
+ * "capabilities": {
10
+ * "spawn": [{ "program": "git", "args": ["status", "--porcelain"] }],
11
+ * "env": ["HOME", "LANG"],
12
+ * "paths": [{ "path": "~/Projects", "access": "readwrite" }]
13
+ * },
14
+ * "deny": ["react-native-some-library"]
15
+ * }]
16
+ *
17
+ * Permissions are not here: the Expo keys (`ios.infoPlist`'s usage strings and each `expo-*`
18
+ * plugin's permission option) declare them for every OS. Plain TypeScript with no Angular, so the
19
+ * config plugin can run it in Node.
20
+ */
21
+ import { type SpawnCapability } from './spawn-rules.ts';
22
+ /** A kind of document the app opens from Finder, by its file extensions. */
23
+ export interface DocumentType {
24
+ /** What Finder calls the kind, e.g. `Markdown`. */
25
+ readonly name: string;
26
+ /** File extensions without the dot, e.g. `md`. */
27
+ readonly extensions: readonly string[];
28
+ /** Whether the app edits these files or only views them. `editor` when unset. */
29
+ readonly role?: 'editor' | 'viewer';
30
+ /** Uniform type identifiers, where the kind has them, e.g. `net.daringfireball.markdown`. */
31
+ readonly utis?: readonly string[];
32
+ /** An icon in the app's assets for documents of this kind. */
33
+ readonly icon?: string;
34
+ }
35
+ /** A path outside the app's own folders that it may use. */
36
+ export interface PathCapability {
37
+ /** An absolute path, or one under the home folder written `~/...`. */
38
+ readonly path: string;
39
+ /** `read` unless it says `readwrite`. */
40
+ readonly access?: 'read' | 'readwrite';
41
+ }
42
+ /** What the app may do beyond its own folders, the user's picks and the Expo-keyed permissions. */
43
+ export interface DesktopCapabilities {
44
+ readonly spawn?: readonly SpawnCapability[];
45
+ /** The environment variables `Processes.env` holds and a spawned program is given. */
46
+ readonly env?: readonly string[];
47
+ readonly paths?: readonly PathCapability[];
48
+ }
49
+ /** The plugin's options. */
50
+ export interface DesktopOptions {
51
+ readonly documentTypes?: readonly DocumentType[];
52
+ readonly capabilities?: DesktopCapabilities;
53
+ /** npm packages whose native code stays out of the desktop build, even where they ship some. */
54
+ readonly deny?: readonly string[];
55
+ }
56
+ /** Why a declared path cannot be used, or null when it can. */
57
+ export declare function pathProblem(path: string): string | null;
58
+ /**
59
+ * The problems with a set of options, each naming where it is, e.g.
60
+ * `capabilities.spawn[0].program: /bin/sh runs its arguments as a command`. Empty when there are
61
+ * none. Unknown keys are problems too, so a misspelt key is not silently a capability missing.
62
+ */
63
+ export declare function desktopOptionProblems(options: unknown): string[];
64
+ /** Check a set of options, throwing one error that lists every problem. */
65
+ export declare function validateDesktopOptions(options: unknown): DesktopOptions;
66
+ /**
67
+ * Whether `path` is inside one of the declared paths, with the access asked for. `home` is the
68
+ * user's home folder, which `~/` stands for. A path with a `.` or `..` segment is refused rather
69
+ * than resolved: the host resolves links and normalizes before it asks.
70
+ */
71
+ export declare function pathAllowed(declared: readonly PathCapability[], path: string, home: string, access?: 'read' | 'readwrite'): boolean;
72
+ export * from './spawn-rules.ts';
73
+ export * from './desktop-permissions.ts';
@@ -0,0 +1,182 @@
1
+ /**
2
+ * The `@ng-native/desktop` plugin's options in `app.json`, and their validation. They hold only
3
+ * what has to exist before JavaScript runs: the document types the app opens, its declared
4
+ * capabilities (programs it spawns, environment variables it reads and paths outside its own
5
+ * folders), and the libraries kept out of the desktop build.
6
+ *
7
+ * ["@ng-native/desktop", {
8
+ * "documentTypes": [{ "name": "Markdown", "extensions": ["md"], "role": "editor" }],
9
+ * "capabilities": {
10
+ * "spawn": [{ "program": "git", "args": ["status", "--porcelain"] }],
11
+ * "env": ["HOME", "LANG"],
12
+ * "paths": [{ "path": "~/Projects", "access": "readwrite" }]
13
+ * },
14
+ * "deny": ["react-native-some-library"]
15
+ * }]
16
+ *
17
+ * Permissions are not here: the Expo keys (`ios.infoPlist`'s usage strings and each `expo-*`
18
+ * plugin's permission option) declare them for every OS. Plain TypeScript with no Angular, so the
19
+ * config plugin can run it in Node.
20
+ */
21
+ import { SpawnRuleError, compileCapability } from "./spawn-rules.js";
22
+ const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
23
+ const EXTENSION = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
24
+ const UTI = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/;
25
+ const PACKAGE = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
26
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
27
+ /** Why a declared path cannot be used, or null when it can. */
28
+ export function pathProblem(path) {
29
+ if (typeof path !== 'string' || path.length === 0)
30
+ return 'a path is required';
31
+ if (path.includes('\0'))
32
+ return 'a path cannot hold a NUL character';
33
+ const rooted = path.startsWith('/')
34
+ ? path.slice(1)
35
+ : path.startsWith('~/')
36
+ ? path.slice(2)
37
+ : null;
38
+ if (rooted === null)
39
+ return `${path} must be absolute, or start with ~/`;
40
+ if (rooted === '')
41
+ return `${path} would give the whole ${path === '/' ? 'disk' : 'home folder'}`;
42
+ const segments = rooted.replace(/\/$/, '').split('/');
43
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
44
+ return `${path} is not a normalized path`;
45
+ }
46
+ return null;
47
+ }
48
+ /**
49
+ * The problems with a set of options, each naming where it is, e.g.
50
+ * `capabilities.spawn[0].program: /bin/sh runs its arguments as a command`. Empty when there are
51
+ * none. Unknown keys are problems too, so a misspelt key is not silently a capability missing.
52
+ */
53
+ export function desktopOptionProblems(options) {
54
+ const problems = [];
55
+ const report = (where, problem) => problems.push(`${where}: ${problem}`);
56
+ if (options === undefined)
57
+ return problems;
58
+ if (!isRecord(options))
59
+ return ['options must be an object'];
60
+ unknownKeys(options, ['documentTypes', 'capabilities', 'deny'], '', report);
61
+ list(options['documentTypes'], 'documentTypes', report, (type, where) => {
62
+ if (!isRecord(type)) {
63
+ report(where, 'must be an object');
64
+ return;
65
+ }
66
+ unknownKeys(type, ['name', 'extensions', 'role', 'utis', 'icon'], where, report);
67
+ if (typeof type['name'] !== 'string' || type['name'] === '') {
68
+ report(`${where}.name`, 'a name is required');
69
+ }
70
+ const extensions = type['extensions'];
71
+ if (!Array.isArray(extensions) || extensions.length === 0) {
72
+ report(`${where}.extensions`, 'at least one extension is required');
73
+ }
74
+ list(extensions, `${where}.extensions`, report, (extension, at) => {
75
+ if (typeof extension !== 'string' || !EXTENSION.test(extension)) {
76
+ report(at, `${JSON.stringify(extension)} is not an extension: write it without the dot`);
77
+ }
78
+ });
79
+ if (type['role'] !== undefined && type['role'] !== 'editor' && type['role'] !== 'viewer') {
80
+ report(`${where}.role`, "must be 'editor' or 'viewer'");
81
+ }
82
+ list(type['utis'], `${where}.utis`, report, (uti, at) => {
83
+ if (typeof uti !== 'string' || !UTI.test(uti))
84
+ report(at, 'is not a type identifier');
85
+ });
86
+ if (type['icon'] !== undefined && typeof type['icon'] !== 'string') {
87
+ report(`${where}.icon`, 'must be a string');
88
+ }
89
+ });
90
+ const capabilities = options['capabilities'];
91
+ if (capabilities !== undefined && !isRecord(capabilities)) {
92
+ report('capabilities', 'must be an object');
93
+ }
94
+ else if (capabilities) {
95
+ unknownKeys(capabilities, ['spawn', 'env', 'paths'], 'capabilities', report);
96
+ list(capabilities['spawn'], 'capabilities.spawn', report, (entry, where) => {
97
+ if (!isRecord(entry)) {
98
+ report(where, 'must be an object');
99
+ return;
100
+ }
101
+ unknownKeys(entry, ['program', 'args'], where, report);
102
+ try {
103
+ compileCapability(entry);
104
+ }
105
+ catch (error) {
106
+ if (!(error instanceof SpawnRuleError))
107
+ throw error;
108
+ report(where, error.message);
109
+ }
110
+ });
111
+ list(capabilities['env'], 'capabilities.env', report, (name, where) => {
112
+ if (typeof name !== 'string' || !ENV_NAME.test(name)) {
113
+ report(where, `${JSON.stringify(name)} is not an environment variable name`);
114
+ }
115
+ });
116
+ list(capabilities['paths'], 'capabilities.paths', report, (entry, where) => {
117
+ if (!isRecord(entry)) {
118
+ report(where, 'must be an object');
119
+ return;
120
+ }
121
+ unknownKeys(entry, ['path', 'access'], where, report);
122
+ const problem = pathProblem(entry['path']);
123
+ if (problem)
124
+ report(`${where}.path`, problem);
125
+ const access = entry['access'];
126
+ if (access !== undefined && access !== 'read' && access !== 'readwrite') {
127
+ report(`${where}.access`, "must be 'read' or 'readwrite'");
128
+ }
129
+ });
130
+ }
131
+ list(options['deny'], 'deny', report, (name, where) => {
132
+ if (typeof name !== 'string' || !PACKAGE.test(name))
133
+ report(where, 'is not an npm package name');
134
+ });
135
+ return problems;
136
+ }
137
+ /** Check a set of options, throwing one error that lists every problem. */
138
+ export function validateDesktopOptions(options) {
139
+ const problems = desktopOptionProblems(options);
140
+ if (problems.length > 0) {
141
+ throw new Error(`[@ng-native/desktop] The plugin options in app.json are not valid:\n` +
142
+ problems.map((problem) => ` - ${problem}`).join('\n'));
143
+ }
144
+ return (options ?? {});
145
+ }
146
+ /**
147
+ * Whether `path` is inside one of the declared paths, with the access asked for. `home` is the
148
+ * user's home folder, which `~/` stands for. A path with a `.` or `..` segment is refused rather
149
+ * than resolved: the host resolves links and normalizes before it asks.
150
+ */
151
+ export function pathAllowed(declared, path, home, access = 'read') {
152
+ if (pathProblem(path) !== null || !path.startsWith('/'))
153
+ return false;
154
+ const target = path.replace(/\/$/, '');
155
+ return declared.some((entry) => {
156
+ if (pathProblem(entry.path) !== null)
157
+ return false;
158
+ if (access === 'readwrite' && entry.access !== 'readwrite')
159
+ return false;
160
+ const root = (entry.path.startsWith('~/') ? `${home}/${entry.path.slice(2)}` : entry.path).replace(/\/$/, '');
161
+ return target === root || target.startsWith(`${root}/`);
162
+ });
163
+ }
164
+ function unknownKeys(value, known, where, report) {
165
+ for (const key of Object.keys(value)) {
166
+ if (!known.includes(key)) {
167
+ report(where ? `${where}.${key}` : key, `is not an option (expected one of ${known.join(', ')})`);
168
+ }
169
+ }
170
+ }
171
+ function list(value, where, report, each) {
172
+ if (value === undefined)
173
+ return;
174
+ if (!Array.isArray(value)) {
175
+ report(where, 'must be a list');
176
+ return;
177
+ }
178
+ value.forEach((item, index) => each(item, `${where}[${index}]`));
179
+ }
180
+ export * from "./spawn-rules.js";
181
+ export * from "./desktop-permissions.js";
182
+ //# sourceMappingURL=desktop-options.js.map
@@ -0,0 +1 @@
1
+ {"version":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,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAClB,KAA8B,EAC9B,KAAwB,EACxB,KAAa,EACb,MAAgD;IAEhD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,CACJ,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAC/B,qCAAqC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACzD,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CACX,KAAc,EACd,KAAa,EACb,MAAgD,EAChD,IAA4C;IAE5C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QAChC,OAAO;IACT,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * The `@ng-native/desktop` plugin's options in `app.json`, and their validation. They hold only\n * what has to exist before JavaScript runs: the document types the app opens, its declared\n * capabilities (programs it spawns, environment variables it reads and paths outside its own\n * folders), and the libraries kept out of the desktop build.\n *\n * [\"@ng-native/desktop\", {\n * \"documentTypes\": [{ \"name\": \"Markdown\", \"extensions\": [\"md\"], \"role\": \"editor\" }],\n * \"capabilities\": {\n * \"spawn\": [{ \"program\": \"git\", \"args\": [\"status\", \"--porcelain\"] }],\n * \"env\": [\"HOME\", \"LANG\"],\n * \"paths\": [{ \"path\": \"~/Projects\", \"access\": \"readwrite\" }]\n * },\n * \"deny\": [\"react-native-some-library\"]\n * }]\n *\n * Permissions are not here: the Expo keys (`ios.infoPlist`'s usage strings and each `expo-*`\n * plugin's permission option) declare them for every OS. Plain TypeScript with no Angular, so the\n * config plugin can run it in Node.\n */\nimport { SpawnRuleError, compileCapability, type SpawnCapability } from './spawn-rules.ts';\n\n/** A kind of document the app opens from Finder, by its file extensions. */\nexport interface DocumentType {\n /** What Finder calls the kind, e.g. `Markdown`. */\n readonly name: string;\n /** File extensions without the dot, e.g. `md`. */\n readonly extensions: readonly string[];\n /** Whether the app edits these files or only views them. `editor` when unset. */\n readonly role?: 'editor' | 'viewer';\n /** Uniform type identifiers, where the kind has them, e.g. `net.daringfireball.markdown`. */\n readonly utis?: readonly string[];\n /** An icon in the app's assets for documents of this kind. */\n readonly icon?: string;\n}\n\n/** A path outside the app's own folders that it may use. */\nexport interface PathCapability {\n /** An absolute path, or one under the home folder written `~/...`. */\n readonly path: string;\n /** `read` unless it says `readwrite`. */\n readonly access?: 'read' | 'readwrite';\n}\n\n/** What the app may do beyond its own folders, the user's picks and the Expo-keyed permissions. */\nexport interface DesktopCapabilities {\n readonly spawn?: readonly SpawnCapability[];\n /** The environment variables `Processes.env` holds and a spawned program is given. */\n readonly env?: readonly string[];\n readonly paths?: readonly PathCapability[];\n}\n\n/** The plugin's options. */\nexport interface DesktopOptions {\n readonly documentTypes?: readonly DocumentType[];\n readonly capabilities?: DesktopCapabilities;\n /** npm packages whose native code stays out of the desktop build, even where they ship some. */\n readonly deny?: readonly string[];\n}\n\nconst ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\nconst EXTENSION = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\nconst UTI = /^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)+$/;\nconst PACKAGE = /^(@[a-z0-9][a-z0-9._~-]*\\/)?[a-z0-9][a-z0-9._~-]*$/;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** Why a declared path cannot be used, or null when it can. */\nexport function pathProblem(path: string): string | null {\n if (typeof path !== 'string' || path.length === 0) return 'a path is required';\n if (path.includes('\\0')) return 'a path cannot hold a NUL character';\n const rooted = path.startsWith('/')\n ? path.slice(1)\n : path.startsWith('~/')\n ? path.slice(2)\n : null;\n if (rooted === null) return `${path} must be absolute, or start with ~/`;\n if (rooted === '') return `${path} would give the whole ${path === '/' ? 'disk' : 'home folder'}`;\n const segments = rooted.replace(/\\/$/, '').split('/');\n if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {\n return `${path} is not a normalized path`;\n }\n return null;\n}\n\n/**\n * The problems with a set of options, each naming where it is, e.g.\n * `capabilities.spawn[0].program: /bin/sh runs its arguments as a command`. Empty when there are\n * none. Unknown keys are problems too, so a misspelt key is not silently a capability missing.\n */\nexport function desktopOptionProblems(options: unknown): string[] {\n const problems: string[] = [];\n const report = (where: string, problem: string) => problems.push(`${where}: ${problem}`);\n if (options === undefined) return problems;\n if (!isRecord(options)) return ['options must be an object'];\n unknownKeys(options, ['documentTypes', 'capabilities', 'deny'], '', report);\n\n list(options['documentTypes'], 'documentTypes', report, (type, where) => {\n if (!isRecord(type)) {\n report(where, 'must be an object');\n return;\n }\n unknownKeys(type, ['name', 'extensions', 'role', 'utis', 'icon'], where, report);\n if (typeof type['name'] !== 'string' || type['name'] === '') {\n report(`${where}.name`, 'a name is required');\n }\n const extensions = type['extensions'];\n if (!Array.isArray(extensions) || extensions.length === 0) {\n report(`${where}.extensions`, 'at least one extension is required');\n }\n list(extensions, `${where}.extensions`, report, (extension, at) => {\n if (typeof extension !== 'string' || !EXTENSION.test(extension)) {\n report(at, `${JSON.stringify(extension)} is not an extension: write it without the dot`);\n }\n });\n if (type['role'] !== undefined && type['role'] !== 'editor' && type['role'] !== 'viewer') {\n report(`${where}.role`, \"must be 'editor' or 'viewer'\");\n }\n list(type['utis'], `${where}.utis`, report, (uti, at) => {\n if (typeof uti !== 'string' || !UTI.test(uti)) report(at, 'is not a type identifier');\n });\n if (type['icon'] !== undefined && typeof type['icon'] !== 'string') {\n report(`${where}.icon`, 'must be a string');\n }\n });\n\n const capabilities = options['capabilities'];\n if (capabilities !== undefined && !isRecord(capabilities)) {\n report('capabilities', 'must be an object');\n } else if (capabilities) {\n unknownKeys(capabilities, ['spawn', 'env', 'paths'], 'capabilities', report);\n list(capabilities['spawn'], 'capabilities.spawn', report, (entry, where) => {\n if (!isRecord(entry)) {\n report(where, 'must be an object');\n return;\n }\n unknownKeys(entry, ['program', 'args'], where, report);\n try {\n compileCapability(entry as unknown as SpawnCapability);\n } catch (error) {\n if (!(error instanceof SpawnRuleError)) throw error;\n report(where, error.message);\n }\n });\n list(capabilities['env'], 'capabilities.env', report, (name, where) => {\n if (typeof name !== 'string' || !ENV_NAME.test(name)) {\n report(where, `${JSON.stringify(name)} is not an environment variable name`);\n }\n });\n list(capabilities['paths'], 'capabilities.paths', report, (entry, where) => {\n if (!isRecord(entry)) {\n report(where, 'must be an object');\n return;\n }\n unknownKeys(entry, ['path', 'access'], where, report);\n const problem = pathProblem(entry['path'] as string);\n if (problem) report(`${where}.path`, problem);\n const access = entry['access'];\n if (access !== undefined && access !== 'read' && access !== 'readwrite') {\n report(`${where}.access`, \"must be 'read' or 'readwrite'\");\n }\n });\n }\n\n list(options['deny'], 'deny', report, (name, where) => {\n if (typeof name !== 'string' || !PACKAGE.test(name))\n report(where, 'is not an npm package name');\n });\n return problems;\n}\n\n/** Check a set of options, throwing one error that lists every problem. */\nexport function validateDesktopOptions(options: unknown): DesktopOptions {\n const problems = desktopOptionProblems(options);\n if (problems.length > 0) {\n throw new Error(\n `[@ng-native/desktop] The plugin options in app.json are not valid:\\n` +\n problems.map((problem) => ` - ${problem}`).join('\\n'),\n );\n }\n return (options ?? {}) as DesktopOptions;\n}\n\n/**\n * Whether `path` is inside one of the declared paths, with the access asked for. `home` is the\n * user's home folder, which `~/` stands for. A path with a `.` or `..` segment is refused rather\n * than resolved: the host resolves links and normalizes before it asks.\n */\nexport function pathAllowed(\n declared: readonly PathCapability[],\n path: string,\n home: string,\n access: 'read' | 'readwrite' = 'read',\n): boolean {\n if (pathProblem(path) !== null || !path.startsWith('/')) return false;\n const target = path.replace(/\\/$/, '');\n return declared.some((entry) => {\n if (pathProblem(entry.path) !== null) return false;\n if (access === 'readwrite' && entry.access !== 'readwrite') return false;\n const root = (\n entry.path.startsWith('~/') ? `${home}/${entry.path.slice(2)}` : entry.path\n ).replace(/\\/$/, '');\n return target === root || target.startsWith(`${root}/`);\n });\n}\n\nfunction unknownKeys(\n value: Record<string, unknown>,\n known: readonly string[],\n where: string,\n report: (where: string, problem: string) => void,\n): void {\n for (const key of Object.keys(value)) {\n if (!known.includes(key)) {\n report(\n where ? `${where}.${key}` : key,\n `is not an option (expected one of ${known.join(', ')})`,\n );\n }\n }\n}\n\nfunction list(\n value: unknown,\n where: string,\n report: (where: string, problem: string) => void,\n each: (item: unknown, where: string) => void,\n): void {\n if (value === undefined) return;\n if (!Array.isArray(value)) {\n report(where, 'must be a list');\n return;\n }\n value.forEach((item, index) => each(item, `${where}[${index}]`));\n}\n\nexport * from './spawn-rules.ts';\nexport * from './desktop-permissions.ts';\n"]}