@ng-native/device 0.22.2 → 0.24.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.
- package/dist/accessibility.d.ts +7 -0
- package/dist/accessibility.js +14 -2
- package/dist/accessibility.js.map +1 -1
- package/dist/app-lifecycle.d.ts +49 -0
- package/dist/app-lifecycle.js +67 -0
- package/dist/app-lifecycle.js.map +1 -0
- package/dist/app-state.d.ts +2 -0
- package/dist/app-state.js +2 -0
- package/dist/app-state.js.map +1 -1
- package/dist/app-windows.d.ts +321 -0
- package/dist/app-windows.js +526 -0
- package/dist/app-windows.js.map +1 -0
- package/dist/color-scheme.d.ts +5 -0
- package/dist/color-scheme.js +16 -0
- package/dist/color-scheme.js.map +1 -1
- package/dist/conditions.d.ts +11 -3
- package/dist/conditions.js +42 -9
- package/dist/conditions.js.map +1 -1
- package/dist/control-size.d.ts +6 -0
- package/dist/control-size.js +2 -0
- package/dist/control-size.js.map +1 -0
- package/dist/deep-links.d.ts +3 -1
- package/dist/deep-links.js +3 -1
- package/dist/deep-links.js.map +1 -1
- package/dist/desktop-options.d.ts +73 -0
- package/dist/desktop-options.js +182 -0
- package/dist/desktop-options.js.map +1 -0
- package/dist/desktop-permissions.d.ts +30 -0
- package/dist/desktop-permissions.js +169 -0
- package/dist/desktop-permissions.js.map +1 -0
- package/dist/dev-menu.d.ts +2 -2
- package/dist/dev-menu.js +3 -5
- package/dist/dev-menu.js.map +1 -1
- package/dist/dialogs.d.ts +9 -7
- package/dist/dialogs.js +15 -10
- package/dist/dialogs.js.map +1 -1
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +2 -0
- package/dist/direction.js.map +1 -1
- package/dist/dock.d.ts +48 -0
- package/dist/dock.js +70 -0
- package/dist/dock.js.map +1 -0
- package/dist/drag-and-drop.d.ts +67 -0
- package/dist/drag-and-drop.js +74 -0
- package/dist/drag-and-drop.js.map +1 -0
- package/dist/expo-view-name.d.ts +16 -0
- package/dist/expo-view-name.js +22 -0
- package/dist/expo-view-name.js.map +1 -0
- package/dist/hardware-back.d.ts +3 -10
- package/dist/hardware-back.js +4 -1
- package/dist/hardware-back.js.map +1 -1
- package/dist/index.d.ts +26 -2
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction-observer.d.ts +117 -0
- package/dist/interaction-observer.js +241 -0
- package/dist/interaction-observer.js.map +1 -0
- package/dist/keyboard.d.ts +2 -8
- package/dist/keyboard.js +3 -0
- package/dist/keyboard.js.map +1 -1
- package/dist/layout-animation.d.ts +3 -1
- package/dist/layout-animation.js +3 -1
- package/dist/layout-animation.js.map +1 -1
- package/dist/menu-model.d.ts +108 -0
- package/dist/menu-model.js +259 -0
- package/dist/menu-model.js.map +1 -0
- package/dist/menu-template.d.ts +19 -0
- package/dist/menu-template.js +31 -0
- package/dist/menu-template.js.map +1 -0
- package/dist/menus.d.ts +225 -0
- package/dist/menus.js +341 -0
- package/dist/menus.js.map +1 -0
- package/dist/navigation-bar.d.ts +2 -12
- package/dist/navigation-bar.js +4 -1
- package/dist/navigation-bar.js.map +1 -1
- package/dist/os-support.d.ts +42 -0
- package/dist/os-support.js +207 -0
- package/dist/os-support.js.map +1 -0
- package/dist/os.d.ts +26 -5
- package/dist/os.js +35 -7
- package/dist/os.js.map +1 -1
- package/dist/own-host.d.ts +27 -0
- package/dist/own-host.js +79 -0
- package/dist/own-host.js.map +1 -0
- package/dist/processes.d.ts +116 -0
- package/dist/processes.js +177 -0
- package/dist/processes.js.map +1 -0
- package/dist/react-native.d.ts +19 -0
- package/dist/react-native.js.map +1 -1
- package/dist/safe-area.d.ts +12 -1
- package/dist/safe-area.js +16 -2
- package/dist/safe-area.js.map +1 -1
- package/dist/screen.d.ts +2 -0
- package/dist/screen.js +2 -0
- package/dist/screen.js.map +1 -1
- package/dist/sharing.d.ts +3 -1
- package/dist/sharing.js +8 -1
- package/dist/sharing.js.map +1 -1
- package/dist/shell.d.ts +33 -0
- package/dist/shell.js +73 -0
- package/dist/shell.js.map +1 -0
- package/dist/shortcut.d.ts +49 -0
- package/dist/shortcut.js +92 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/sidebar-selection.d.ts +8 -0
- package/dist/sidebar-selection.js +9 -0
- package/dist/sidebar-selection.js.map +1 -0
- package/dist/spawn-rules.d.ts +108 -0
- package/dist/spawn-rules.js +313 -0
- package/dist/spawn-rules.js.map +1 -0
- package/dist/split-views.d.ts +7 -0
- package/dist/split-views.js +21 -0
- package/dist/split-views.js.map +1 -0
- package/dist/status-bar.d.ts +2 -12
- package/dist/status-bar.js +3 -0
- package/dist/status-bar.js.map +1 -1
- package/dist/tray.d.ts +63 -0
- package/dist/tray.js +76 -0
- package/dist/tray.js.map +1 -0
- package/dist/undo-stack.d.ts +64 -0
- package/dist/undo-stack.js +110 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/vibration.d.ts +3 -14
- package/dist/vibration.js +4 -1
- package/dist/vibration.js.map +1 -1
- package/dist/window-navigator.d.ts +25 -0
- package/dist/window-navigator.js +7 -0
- package/dist/window-navigator.js.map +1 -0
- package/dist/window-restore.d.ts +45 -0
- package/dist/window-restore.js +66 -0
- package/dist/window-restore.js.map +1 -0
- package/package.json +10 -2
package/dist/sharing.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* it draws is one a caller usually wants: `shared` means an app took the content, `dismissed`
|
|
6
6
|
* means they changed their mind, and only the first is worth a confirmation or an analytics event.
|
|
7
7
|
*/
|
|
8
|
-
import { InjectionToken } from '@angular/core';
|
|
8
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
9
9
|
import * as i0 from "@angular/core";
|
|
10
10
|
export interface ShareRequest {
|
|
11
11
|
/** What is being shared. At least one of these; iOS prefers `url` when both are present. */
|
|
@@ -25,6 +25,8 @@ export declare class Sharing {
|
|
|
25
25
|
/** Overridden in a test to answer the sheet without one opening. */
|
|
26
26
|
static readonly SOURCE: InjectionToken<NativeSharing | null>;
|
|
27
27
|
private readonly native;
|
|
28
|
+
/** Whether React Native's module is here. Where it is not, every call is inert. */
|
|
29
|
+
readonly available: Signal<boolean>;
|
|
28
30
|
/**
|
|
29
31
|
* Open the share sheet. Resolves to whether anything took the content.
|
|
30
32
|
*
|
package/dist/sharing.js
CHANGED
|
@@ -5,13 +5,18 @@
|
|
|
5
5
|
* it draws is one a caller usually wants: `shared` means an app took the content, `dismissed`
|
|
6
6
|
* means they changed their mind, and only the first is worth a confirmation or an analytics event.
|
|
7
7
|
*/
|
|
8
|
-
import { InjectionToken, Service, inject } from '@angular/core';
|
|
8
|
+
import { InjectionToken, Service, inject, signal } from '@angular/core';
|
|
9
9
|
import { reactNative } from "./react-native.js";
|
|
10
10
|
import * as i0 from "@angular/core";
|
|
11
11
|
export function sharingSource() {
|
|
12
12
|
const native = reactNative();
|
|
13
13
|
if (!native)
|
|
14
14
|
return null;
|
|
15
|
+
// React Native's Share has no macOS implementation: the desktop host's NgNativeSharing is the
|
|
16
|
+
// share picker there, and without it sharing is absent.
|
|
17
|
+
if (native.Platform.OS === 'macos') {
|
|
18
|
+
return native.TurboModuleRegistry?.get('NgNativeSharing') ?? null;
|
|
19
|
+
}
|
|
15
20
|
const android = native.Platform.OS === 'android';
|
|
16
21
|
return { share: (request) => native.Share.share(android ? forAndroid(request) : request) };
|
|
17
22
|
}
|
|
@@ -33,6 +38,8 @@ export class Sharing {
|
|
|
33
38
|
/** Overridden in a test to answer the sheet without one opening. */
|
|
34
39
|
static SOURCE = new InjectionToken('angular-native.sharingSource', { factory: sharingSource });
|
|
35
40
|
native = inject(Sharing.SOURCE);
|
|
41
|
+
/** Whether React Native's module is here. Where it is not, every call is inert. */
|
|
42
|
+
available = signal(this.native !== null).asReadonly();
|
|
36
43
|
/**
|
|
37
44
|
* Open the share sheet. Resolves to whether anything took the content.
|
|
38
45
|
*
|
package/dist/sharing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharing.js","sourceRoot":"","sources":["../src/shar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AAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC;AAGD,MAAM,OAAO,OAAO;IAClB,oEAAoE;IACpE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,8BAA8B,EAC9B,EAAE,OAAO,EAAE,aAAa,EAAE,CAC3B,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD,mFAAmF;IAC1E,SAAS,GAAoB,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;IAEhF;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,OAAqB;QAC/B,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAC/B,IAAI,CAAC,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;uGA5BU,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, signal, type Signal } 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 // React Native's Share has no macOS implementation: the desktop host's NgNativeSharing is the\n // share picker there, and without it sharing is absent.\n if (native.Platform.OS === 'macos') {\n return (native.TurboModuleRegistry?.get('NgNativeSharing') as NativeSharing | null) ?? null;\n }\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 /** Whether React Native's module is here. Where it is not, every call is inert. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\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"]}
|
package/dist/shell.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Shell`: hand a url, a file or a folder to the OS. Absent on iOS, Android and the web, where
|
|
3
|
+
* each call does nothing and resolves false.
|
|
4
|
+
*
|
|
5
|
+
* The host contract, on the `NgNativeShell` module: `openExternal(url)`, `openPath(path)` and
|
|
6
|
+
* `showItemInFolder(path)`, each answering whether the OS took it. NSWorkspace on macOS.
|
|
7
|
+
*/
|
|
8
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
export interface NativeShell {
|
|
11
|
+
openExternal(url: string): Promise<boolean>;
|
|
12
|
+
openPath(path: string): Promise<boolean>;
|
|
13
|
+
showItemInFolder(path: string): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export declare class Shell {
|
|
16
|
+
/** Overridden in a test with a fake host. */
|
|
17
|
+
static readonly SOURCE: InjectionToken<NativeShell | null>;
|
|
18
|
+
private readonly native;
|
|
19
|
+
/** Whether the OS takes urls, files and folders from the app: macOS. */
|
|
20
|
+
readonly available: Signal<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Open `url` in the app the user chose for its scheme: a web page in their browser, a `mailto:`
|
|
23
|
+
* in their mail app. Resolves false for a url that does not start with a scheme, or one whose
|
|
24
|
+
* scheme runs or embeds content (`javascript:`, `data:`) or is a file (`file:`, `openPath`'s).
|
|
25
|
+
*/
|
|
26
|
+
openExternal(url: string): Promise<boolean>;
|
|
27
|
+
/** Open a file or folder in its default app, as a double click in Finder does. */
|
|
28
|
+
openPath(path: string): Promise<boolean>;
|
|
29
|
+
/** Show a file or folder selected in a Finder window. */
|
|
30
|
+
showItemInFolder(path: string): Promise<boolean>;
|
|
31
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Shell, never>;
|
|
32
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
33
|
+
}
|
package/dist/shell.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Shell`: hand a url, a file or a folder to the OS. Absent on iOS, Android and the web, where
|
|
3
|
+
* each call does nothing and resolves false.
|
|
4
|
+
*
|
|
5
|
+
* The host contract, on the `NgNativeShell` module: `openExternal(url)`, `openPath(path)` and
|
|
6
|
+
* `showItemInFolder(path)`, each answering whether the OS took it. NSWorkspace on macOS.
|
|
7
|
+
*/
|
|
8
|
+
import { InjectionToken, Service, inject, signal } from '@angular/core';
|
|
9
|
+
import { reactNative } from "./react-native.js";
|
|
10
|
+
import * as i0 from "@angular/core";
|
|
11
|
+
/** Schemes `openExternal` refuses: a file is `openPath`'s, and the rest run or embed content. */
|
|
12
|
+
const REFUSED_SCHEMES = new Set(['file:', 'javascript:', 'data:', 'vbscript:', 'blob:']);
|
|
13
|
+
/** A url's scheme, which it must start with: nothing before it, as RFC 3986 writes one. */
|
|
14
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z\d+.-]*):/;
|
|
15
|
+
function shellSource() {
|
|
16
|
+
const module = reactNative()?.TurboModuleRegistry?.get?.('NgNativeShell');
|
|
17
|
+
if (!module)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
openExternal: async (url) => (await module.openExternal?.(url)) === true,
|
|
21
|
+
openPath: async (path) => (await module.openPath?.(path)) === true,
|
|
22
|
+
showItemInFolder: async (path) => (await module.showItemInFolder?.(path)) === true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Whether `path` is absolute and normalized: no `.` or `..` to walk out of where it says. */
|
|
26
|
+
function plainPath(path) {
|
|
27
|
+
if (typeof path !== 'string' || !path.startsWith('/') || path.includes('\0'))
|
|
28
|
+
return false;
|
|
29
|
+
return !path
|
|
30
|
+
.slice(1)
|
|
31
|
+
.split('/')
|
|
32
|
+
.some((segment) => segment === '.' || segment === '..' || segment === '');
|
|
33
|
+
}
|
|
34
|
+
export class Shell {
|
|
35
|
+
/** Overridden in a test with a fake host. */
|
|
36
|
+
static SOURCE = new InjectionToken('angular-native.shellSource', {
|
|
37
|
+
factory: shellSource,
|
|
38
|
+
});
|
|
39
|
+
native = inject(Shell.SOURCE);
|
|
40
|
+
/** Whether the OS takes urls, files and folders from the app: macOS. */
|
|
41
|
+
available = signal(this.native !== null).asReadonly();
|
|
42
|
+
/**
|
|
43
|
+
* Open `url` in the app the user chose for its scheme: a web page in their browser, a `mailto:`
|
|
44
|
+
* in their mail app. Resolves false for a url that does not start with a scheme, or one whose
|
|
45
|
+
* scheme runs or embeds content (`javascript:`, `data:`) or is a file (`file:`, `openPath`'s).
|
|
46
|
+
*/
|
|
47
|
+
async openExternal(url) {
|
|
48
|
+
// Read here rather than by `URL`: React Native's keeps a leading space or control character
|
|
49
|
+
// a browser trims, and then reports no scheme at all, so a refused one would get through.
|
|
50
|
+
const scheme = typeof url === 'string' ? SCHEME.exec(url)?.[1]?.toLowerCase() : undefined;
|
|
51
|
+
if (scheme === undefined || REFUSED_SCHEMES.has(`${scheme}:`))
|
|
52
|
+
return false;
|
|
53
|
+
return (await this.native?.openExternal(url)) ?? false;
|
|
54
|
+
}
|
|
55
|
+
/** Open a file or folder in its default app, as a double click in Finder does. */
|
|
56
|
+
async openPath(path) {
|
|
57
|
+
if (!plainPath(path))
|
|
58
|
+
return false;
|
|
59
|
+
return (await this.native?.openPath(path)) ?? false;
|
|
60
|
+
}
|
|
61
|
+
/** Show a file or folder selected in a Finder window. */
|
|
62
|
+
async showItemInFolder(path) {
|
|
63
|
+
if (!plainPath(path))
|
|
64
|
+
return false;
|
|
65
|
+
return (await this.native?.showItemInFolder(path)) ?? false;
|
|
66
|
+
}
|
|
67
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Shell, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
68
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Shell });
|
|
69
|
+
}
|
|
70
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Shell, decorators: [{
|
|
71
|
+
type: Service
|
|
72
|
+
}] });
|
|
73
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +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D,KAAK,CAAC,gBAAgB,CAAC,IAAY;QACjC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACnC,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC;IAC9D,CAAC;uGAlCU,KAAK;wGAAL,KAAK;;2FAAL,KAAK;kBADjB,OAAO","sourcesContent":["/**\n * `Shell`: hand a url, a file or a folder to the OS. Absent on iOS, Android and the web, where\n * each call does nothing and resolves false.\n *\n * The host contract, on the `NgNativeShell` module: `openExternal(url)`, `openPath(path)` and\n * `showItemInFolder(path)`, each answering whether the OS took it. NSWorkspace on macOS.\n */\nimport { InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeShell {\n openExternal(url: string): Promise<boolean>;\n openPath(path: string): Promise<boolean>;\n showItemInFolder(path: string): Promise<boolean>;\n}\n\n/** Schemes `openExternal` refuses: a file is `openPath`'s, and the rest run or embed content. */\nconst REFUSED_SCHEMES = new Set(['file:', 'javascript:', 'data:', 'vbscript:', 'blob:']);\n\n/** A url's scheme, which it must start with: nothing before it, as RFC 3986 writes one. */\nconst SCHEME = /^([a-zA-Z][a-zA-Z\\d+.-]*):/;\n\nfunction shellSource(): NativeShell | null {\n const module = reactNative()?.TurboModuleRegistry?.get?.('NgNativeShell') as\n Partial<NativeShell> | null | undefined;\n if (!module) return null;\n return {\n openExternal: async (url) => (await module.openExternal?.(url)) === true,\n openPath: async (path) => (await module.openPath?.(path)) === true,\n showItemInFolder: async (path) => (await module.showItemInFolder?.(path)) === true,\n };\n}\n\n/** Whether `path` is absolute and normalized: no `.` or `..` to walk out of where it says. */\nfunction plainPath(path: string): boolean {\n if (typeof path !== 'string' || !path.startsWith('/') || path.includes('\\0')) return false;\n return !path\n .slice(1)\n .split('/')\n .some((segment) => segment === '.' || segment === '..' || segment === '');\n}\n\n@Service()\nexport class Shell {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeShell | null>('angular-native.shellSource', {\n factory: shellSource,\n });\n\n private readonly native = inject(Shell.SOURCE);\n\n /** Whether the OS takes urls, files and folders from the app: macOS. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n /**\n * Open `url` in the app the user chose for its scheme: a web page in their browser, a `mailto:`\n * in their mail app. Resolves false for a url that does not start with a scheme, or one whose\n * scheme runs or embeds content (`javascript:`, `data:`) or is a file (`file:`, `openPath`'s).\n */\n async openExternal(url: string): Promise<boolean> {\n // Read here rather than by `URL`: React Native's keeps a leading space or control character\n // a browser trims, and then reports no scheme at all, so a refused one would get through.\n const scheme = typeof url === 'string' ? SCHEME.exec(url)?.[1]?.toLowerCase() : undefined;\n if (scheme === undefined || REFUSED_SCHEMES.has(`${scheme}:`)) return false;\n return (await this.native?.openExternal(url)) ?? false;\n }\n\n /** Open a file or folder in its default app, as a double click in Finder does. */\n async openPath(path: string): Promise<boolean> {\n if (!plainPath(path)) return false;\n return (await this.native?.openPath(path)) ?? false;\n }\n\n /** Show a file or folder selected in a Finder window. */\n async showItemInFolder(path: string): Promise<boolean> {\n if (!plainPath(path)) return false;\n return (await this.native?.showItemInFolder(path)) ?? false;\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard shortcuts, as `<menu-item shortcut>` and `[shortcut]` write them: `mod+s`,
|
|
3
|
+
* `mod+shift+k`, `mod+,`. `mod` is Cmd on Apple's OSes and Ctrl everywhere else, so one string
|
|
4
|
+
* serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop
|
|
5
|
+
* host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.
|
|
6
|
+
*/
|
|
7
|
+
/** The OSes a shortcut is read on, as the `OS` token names them. */
|
|
8
|
+
export type ShortcutOs = 'ios' | 'android' | 'macos' | 'web';
|
|
9
|
+
/** A key pressed with its modifiers, as a key event reports it. */
|
|
10
|
+
export interface KeyChord {
|
|
11
|
+
/** The key, as `KeyboardEvent.key` names it: `s`, `,`, `ArrowLeft`, `[`. */
|
|
12
|
+
readonly key: string;
|
|
13
|
+
/** Cmd on a Mac or an iPad keyboard, the Windows or Meta key elsewhere. */
|
|
14
|
+
readonly meta?: boolean;
|
|
15
|
+
readonly ctrl?: boolean;
|
|
16
|
+
/** Option on a Mac. */
|
|
17
|
+
readonly alt?: boolean;
|
|
18
|
+
readonly shift?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** A shortcut read for one OS: the key, lower case, and exactly the modifiers it needs. */
|
|
21
|
+
export interface ParsedShortcut {
|
|
22
|
+
readonly key: string;
|
|
23
|
+
readonly meta: boolean;
|
|
24
|
+
readonly ctrl: boolean;
|
|
25
|
+
readonly alt: boolean;
|
|
26
|
+
readonly shift: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A shortcut read for `os`. Throws on one that names no key or a modifier it does not know, since
|
|
30
|
+
* that is a mistake in the app, not something a user can press.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseShortcut(shortcut: string, os: ShortcutOs): ParsedShortcut;
|
|
33
|
+
/** Whether pressing `chord` on `os` is `shortcut`: the same key, and exactly its modifiers. */
|
|
34
|
+
export declare function matchesShortcut(shortcut: string, chord: KeyChord, os: ShortcutOs): boolean;
|
|
35
|
+
/** Whether `shortcut` is one of the editing keys a focused text input owns on `os`. */
|
|
36
|
+
export declare function isEditingShortcut(shortcut: string, os: ShortcutOs): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether an app's `shortcut` fires for `chord`. It fires when the chord matches, except that the
|
|
39
|
+
* editing keys (mod+z, x, c, v and a) go to a focused text input, so an app's shortcut on one of
|
|
40
|
+
* them fires only while no text input has focus. Every other shortcut fires wherever focus is, as
|
|
41
|
+
* a menu's key equivalents do.
|
|
42
|
+
*/
|
|
43
|
+
export declare function shortcutFires(shortcut: string, chord: KeyChord, os: ShortcutOs, textInputFocused: boolean): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The back and forward keys on `os`: a shortcut role rather than a `mod` chord, since each OS has
|
|
46
|
+
* its own. Cmd-[ and Cmd-] on macOS and iPadOS keyboards (Cmd-Left stays with text editing), and
|
|
47
|
+
* Alt-Left and Alt-Right elsewhere, as Windows, Linux and Android browsers have them.
|
|
48
|
+
*/
|
|
49
|
+
export declare function navigationShortcut(direction: 'back' | 'forward', os: ShortcutOs): ParsedShortcut;
|
package/dist/shortcut.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard shortcuts, as `<menu-item shortcut>` and `[shortcut]` write them: `mod+s`,
|
|
3
|
+
* `mod+shift+k`, `mod+,`. `mod` is Cmd on Apple's OSes and Ctrl everywhere else, so one string
|
|
4
|
+
* serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop
|
|
5
|
+
* host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.
|
|
6
|
+
*/
|
|
7
|
+
const MODIFIERS = new Set(['mod', 'cmd', 'meta', 'ctrl', 'alt', 'option', 'shift']);
|
|
8
|
+
/** Whether `os` is one of Apple's, where `mod` is Cmd. */
|
|
9
|
+
const apple = (os) => os === 'ios' || os === 'macos';
|
|
10
|
+
/**
|
|
11
|
+
* A shortcut read for `os`. Throws on one that names no key or a modifier it does not know, since
|
|
12
|
+
* that is a mistake in the app, not something a user can press.
|
|
13
|
+
*/
|
|
14
|
+
export function parseShortcut(shortcut, os) {
|
|
15
|
+
const { key, held } = split(shortcut);
|
|
16
|
+
const mod = held.has('mod');
|
|
17
|
+
return {
|
|
18
|
+
key: key.length === 1 ? key.toLowerCase() : key,
|
|
19
|
+
meta: held.has('cmd') || held.has('meta') || (mod && apple(os)),
|
|
20
|
+
ctrl: held.has('ctrl') || (mod && !apple(os)),
|
|
21
|
+
alt: held.has('alt') || held.has('option'),
|
|
22
|
+
shift: held.has('shift'),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** A shortcut's key and the modifiers it names, checked. */
|
|
26
|
+
function split(shortcut) {
|
|
27
|
+
// A trailing `+` is the plus key itself: `mod++`.
|
|
28
|
+
const parts = shortcut.endsWith('++')
|
|
29
|
+
? [...shortcut.slice(0, -2).split('+'), '+']
|
|
30
|
+
: shortcut.split('+');
|
|
31
|
+
const key = parts.pop() ?? '';
|
|
32
|
+
const held = new Set(parts.map((part) => part.trim().toLowerCase()));
|
|
33
|
+
for (const modifier of held) {
|
|
34
|
+
if (!MODIFIERS.has(modifier)) {
|
|
35
|
+
throw new Error(`[angular-native] '${shortcut}' has no modifier '${modifier}'.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!key || MODIFIERS.has(key.toLowerCase())) {
|
|
39
|
+
throw new Error(`[angular-native] '${shortcut}' names no key to press.`);
|
|
40
|
+
}
|
|
41
|
+
return { key, held };
|
|
42
|
+
}
|
|
43
|
+
/** Whether pressing `chord` on `os` is `shortcut`: the same key, and exactly its modifiers. */
|
|
44
|
+
export function matchesShortcut(shortcut, chord, os) {
|
|
45
|
+
const wanted = parseShortcut(shortcut, os);
|
|
46
|
+
const key = chord.key.length === 1 ? chord.key.toLowerCase() : chord.key;
|
|
47
|
+
return (key === wanted.key &&
|
|
48
|
+
Boolean(chord.meta) === wanted.meta &&
|
|
49
|
+
Boolean(chord.ctrl) === wanted.ctrl &&
|
|
50
|
+
Boolean(chord.alt) === wanted.alt &&
|
|
51
|
+
Boolean(chord.shift) === wanted.shift);
|
|
52
|
+
}
|
|
53
|
+
/** The editing keys a focused text input owns: undo, cut, copy, paste and select all. */
|
|
54
|
+
const EDITING = ['mod+z', 'mod+x', 'mod+c', 'mod+v', 'mod+a'];
|
|
55
|
+
/** Whether `shortcut` is one of the editing keys a focused text input owns on `os`. */
|
|
56
|
+
export function isEditingShortcut(shortcut, os) {
|
|
57
|
+
const parsed = parseShortcut(shortcut, os);
|
|
58
|
+
return EDITING.some((editing) => {
|
|
59
|
+
const own = parseShortcut(editing, os);
|
|
60
|
+
return Object.keys(own).every((k) => own[k] === parsed[k]);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether an app's `shortcut` fires for `chord`. It fires when the chord matches, except that the
|
|
65
|
+
* editing keys (mod+z, x, c, v and a) go to a focused text input, so an app's shortcut on one of
|
|
66
|
+
* them fires only while no text input has focus. Every other shortcut fires wherever focus is, as
|
|
67
|
+
* a menu's key equivalents do.
|
|
68
|
+
*/
|
|
69
|
+
export function shortcutFires(shortcut, chord, os, textInputFocused) {
|
|
70
|
+
if (!matchesShortcut(shortcut, chord, os))
|
|
71
|
+
return false;
|
|
72
|
+
return !(textInputFocused && isEditingShortcut(shortcut, os));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The back and forward keys on `os`: a shortcut role rather than a `mod` chord, since each OS has
|
|
76
|
+
* its own. Cmd-[ and Cmd-] on macOS and iPadOS keyboards (Cmd-Left stays with text editing), and
|
|
77
|
+
* Alt-Left and Alt-Right elsewhere, as Windows, Linux and Android browsers have them.
|
|
78
|
+
*/
|
|
79
|
+
export function navigationShortcut(direction, os) {
|
|
80
|
+
if (apple(os)) {
|
|
81
|
+
return {
|
|
82
|
+
key: direction === 'back' ? '[' : ']',
|
|
83
|
+
meta: true,
|
|
84
|
+
ctrl: false,
|
|
85
|
+
alt: false,
|
|
86
|
+
shift: false,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const key = direction === 'back' ? 'ArrowLeft' : 'ArrowRight';
|
|
90
|
+
return { key, meta: false, ctrl: false, alt: true, shift: false };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=shortcut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut.js","sourceRoot":"","sources":["../src/shortcut.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KA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rC,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,KAAK;YACV,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC","sourcesContent":["/**\n * Keyboard shortcuts, as `<menu-item shortcut>` and `[shortcut]` write them: `mod+s`,\n * `mod+shift+k`, `mod+,`. `mod` is Cmd on Apple's OSes and Ctrl everywhere else, so one string\n * serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop\n * host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.\n */\n\n/** The OSes a shortcut is read on, as the `OS` token names them. */\nexport type ShortcutOs = 'ios' | 'android' | 'macos' | 'web';\n\n/** A key pressed with its modifiers, as a key event reports it. */\nexport interface KeyChord {\n /** The key, as `KeyboardEvent.key` names it: `s`, `,`, `ArrowLeft`, `[`. */\n readonly key: string;\n /** Cmd on a Mac or an iPad keyboard, the Windows or Meta key elsewhere. */\n readonly meta?: boolean;\n readonly ctrl?: boolean;\n /** Option on a Mac. */\n readonly alt?: boolean;\n readonly shift?: boolean;\n}\n\n/** A shortcut read for one OS: the key, lower case, and exactly the modifiers it needs. */\nexport interface ParsedShortcut {\n readonly key: string;\n readonly meta: boolean;\n readonly ctrl: boolean;\n readonly alt: boolean;\n readonly shift: boolean;\n}\n\nconst MODIFIERS = new Set(['mod', 'cmd', 'meta', 'ctrl', 'alt', 'option', 'shift']);\n\n/** Whether `os` is one of Apple's, where `mod` is Cmd. */\nconst apple = (os: ShortcutOs): boolean => os === 'ios' || os === 'macos';\n\n/**\n * A shortcut read for `os`. Throws on one that names no key or a modifier it does not know, since\n * that is a mistake in the app, not something a user can press.\n */\nexport function parseShortcut(shortcut: string, os: ShortcutOs): ParsedShortcut {\n const { key, held } = split(shortcut);\n const mod = held.has('mod');\n return {\n key: key.length === 1 ? key.toLowerCase() : key,\n meta: held.has('cmd') || held.has('meta') || (mod && apple(os)),\n ctrl: held.has('ctrl') || (mod && !apple(os)),\n alt: held.has('alt') || held.has('option'),\n shift: held.has('shift'),\n };\n}\n\n/** A shortcut's key and the modifiers it names, checked. */\nfunction split(shortcut: string): { key: string; held: Set<string> } {\n // A trailing `+` is the plus key itself: `mod++`.\n const parts = shortcut.endsWith('++')\n ? [...shortcut.slice(0, -2).split('+'), '+']\n : shortcut.split('+');\n const key = parts.pop() ?? '';\n const held = new Set(parts.map((part) => part.trim().toLowerCase()));\n for (const modifier of held) {\n if (!MODIFIERS.has(modifier)) {\n throw new Error(`[angular-native] '${shortcut}' has no modifier '${modifier}'.`);\n }\n }\n if (!key || MODIFIERS.has(key.toLowerCase())) {\n throw new Error(`[angular-native] '${shortcut}' names no key to press.`);\n }\n return { key, held };\n}\n\n/** Whether pressing `chord` on `os` is `shortcut`: the same key, and exactly its modifiers. */\nexport function matchesShortcut(shortcut: string, chord: KeyChord, os: ShortcutOs): boolean {\n const wanted = parseShortcut(shortcut, os);\n const key = chord.key.length === 1 ? chord.key.toLowerCase() : chord.key;\n return (\n key === wanted.key &&\n Boolean(chord.meta) === wanted.meta &&\n Boolean(chord.ctrl) === wanted.ctrl &&\n Boolean(chord.alt) === wanted.alt &&\n Boolean(chord.shift) === wanted.shift\n );\n}\n\n/** The editing keys a focused text input owns: undo, cut, copy, paste and select all. */\nconst EDITING = ['mod+z', 'mod+x', 'mod+c', 'mod+v', 'mod+a'];\n\n/** Whether `shortcut` is one of the editing keys a focused text input owns on `os`. */\nexport function isEditingShortcut(shortcut: string, os: ShortcutOs): boolean {\n const parsed = parseShortcut(shortcut, os);\n return EDITING.some((editing) => {\n const own = parseShortcut(editing, os);\n return (Object.keys(own) as (keyof ParsedShortcut)[]).every((k) => own[k] === parsed[k]);\n });\n}\n\n/**\n * Whether an app's `shortcut` fires for `chord`. It fires when the chord matches, except that the\n * editing keys (mod+z, x, c, v and a) go to a focused text input, so an app's shortcut on one of\n * them fires only while no text input has focus. Every other shortcut fires wherever focus is, as\n * a menu's key equivalents do.\n */\nexport function shortcutFires(\n shortcut: string,\n chord: KeyChord,\n os: ShortcutOs,\n textInputFocused: boolean,\n): boolean {\n if (!matchesShortcut(shortcut, chord, os)) return false;\n return !(textInputFocused && isEditingShortcut(shortcut, os));\n}\n\n/**\n * The back and forward keys on `os`: a shortcut role rather than a `mod` chord, since each OS has\n * its own. Cmd-[ and Cmd-] on macOS and iPadOS keyboards (Cmd-Left stays with text editing), and\n * Alt-Left and Alt-Right elsewhere, as Windows, Linux and Android browsers have them.\n */\nexport function navigationShortcut(direction: 'back' | 'forward', os: ShortcutOs): ParsedShortcut {\n if (apple(os)) {\n return {\n key: direction === 'back' ? '[' : ']',\n meta: true,\n ctrl: false,\n alt: false,\n shift: false,\n };\n }\n const key = direction === 'back' ? 'ArrowLeft' : 'ArrowRight';\n return { key, meta: false, ctrl: false, alt: true, shift: false };\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionToken, type WritableSignal } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a sidebar item is the selected one. A `<sidebar-item>` provides it, the router's
|
|
4
|
+
* `sidebar-item[path]` directive writes it as the route changes, and the item's `[(selected)]`
|
|
5
|
+
* reads it back. It lives here because the components and the router packages cannot import each
|
|
6
|
+
* other. There is none outside a sidebar item.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SIDEBAR_SELECTION: InjectionToken<WritableSignal<boolean>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a sidebar item is the selected one. A `<sidebar-item>` provides it, the router's
|
|
4
|
+
* `sidebar-item[path]` directive writes it as the route changes, and the item's `[(selected)]`
|
|
5
|
+
* reads it back. It lives here because the components and the router packages cannot import each
|
|
6
|
+
* other. There is none outside a sidebar item.
|
|
7
|
+
*/
|
|
8
|
+
export const SIDEBAR_SELECTION = new InjectionToken('angular-native.sidebarSelection');
|
|
9
|
+
//# sourceMappingURL=sidebar-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidebar-selection.js","sourceRoot":"","sources":["../src/sidebar-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAuB,MAAM,eAAe,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,cAAc,CACjD,iCAAiC,CAClC,CAAC","sourcesContent":["import { InjectionToken, type WritableSignal } from '@angular/core';\n\n/**\n * Whether a sidebar item is the selected one. A `<sidebar-item>` provides it, the router's\n * `sidebar-item[path]` directive writes it as the route changes, and the item's `[(selected)]`\n * reads it back. It lives here because the components and the router packages cannot import each\n * other. There is none outside a sidebar item.\n */\nexport const SIDEBAR_SELECTION = new InjectionToken<WritableSignal<boolean>>(\n 'angular-native.sidebarSelection',\n);\n"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules a desktop app's declared spawn capabilities follow: which programs it may run, with
|
|
3
|
+
* which arguments. Plain TypeScript with no imports, so the config plugin can check the declaration
|
|
4
|
+
* at build time and `Processes` can refuse an undeclared call with a clear error before the
|
|
5
|
+
* desktop host checks it again natively.
|
|
6
|
+
*
|
|
7
|
+
* An entry names a program and the arguments it may take:
|
|
8
|
+
*
|
|
9
|
+
* { program: '/usr/bin/git', args: ['clone', '{url:https://\\S+}', '{dir:[\\w.-]+}'] }
|
|
10
|
+
*
|
|
11
|
+
* Each argument is a literal, matched exactly, or a `{name:regex}` placeholder. A placeholder
|
|
12
|
+
* followed by `...` matches zero or more arguments, each by the same rules.
|
|
13
|
+
*
|
|
14
|
+
* - A placeholder's pattern is anchored: it matches the whole argument, so `{branch:[a-z]+}`
|
|
15
|
+
* never accepts `--upload-pack=...`.
|
|
16
|
+
* - A placeholder never accepts an argument starting with `-` unless each alternative of its
|
|
17
|
+
* pattern starts with one, so an option cannot be injected where a value was declared.
|
|
18
|
+
* - No argument may hold a NUL character, which a C string would cut short.
|
|
19
|
+
* - Shells, `env` and other programs that run their arguments as a command are refused as
|
|
20
|
+
* programs, and so are Windows `.bat` and `.cmd` files, which `cmd.exe` re-parses (the BatBadBut
|
|
21
|
+
* class of bug). `spawn` never goes through a shell.
|
|
22
|
+
* - A program is an absolute path, or a bare name resolved once at startup on a fixed search path
|
|
23
|
+
* (`SEARCH_PATH`), never the inherited `PATH`, and pinned there.
|
|
24
|
+
*
|
|
25
|
+
* The boundary guards against bugs and injected content, not against a hostile app.
|
|
26
|
+
*/
|
|
27
|
+
/** A spawn capability as `app.json` declares it. */
|
|
28
|
+
export interface SpawnCapability {
|
|
29
|
+
/** An absolute path, or a bare name resolved on `SEARCH_PATH` at startup. */
|
|
30
|
+
readonly program: string;
|
|
31
|
+
/** Literal arguments and `{name:regex}` placeholders, in order. */
|
|
32
|
+
readonly args?: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/** One declared argument, parsed. */
|
|
35
|
+
export type ArgumentRule = {
|
|
36
|
+
readonly kind: 'literal';
|
|
37
|
+
readonly value: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'placeholder';
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly pattern: RegExp;
|
|
42
|
+
/** Whether each alternative of the pattern starts with `-`, so the value may be an option. */
|
|
43
|
+
readonly option: boolean;
|
|
44
|
+
/** `{name:regex}...`: zero or more arguments. */
|
|
45
|
+
readonly repeated: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** A spawn capability, checked and parsed. */
|
|
48
|
+
export interface CompiledCapability {
|
|
49
|
+
readonly program: string;
|
|
50
|
+
readonly args: readonly ArgumentRule[];
|
|
51
|
+
}
|
|
52
|
+
/** What a call that matched was given for each placeholder: a list for a repeated one. */
|
|
53
|
+
export type PlaceholderValues = Record<string, string | readonly string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Where a bare program name is looked for, in order: the system's directories, then Homebrew's on
|
|
56
|
+
* Apple silicon and on Intel. A Finder-launched app inherits only launchd's `PATH`, so Homebrew's
|
|
57
|
+
* tools would never resolve on the inherited one.
|
|
58
|
+
*/
|
|
59
|
+
export declare const SEARCH_PATH: readonly string[];
|
|
60
|
+
/** Why a declaration or a call was refused. */
|
|
61
|
+
export declare class SpawnRuleError extends Error {
|
|
62
|
+
readonly name = "SpawnRuleError";
|
|
63
|
+
}
|
|
64
|
+
/** Why `program` cannot be declared, or null when it can. */
|
|
65
|
+
export declare function programProblem(program: string): string | null;
|
|
66
|
+
/** Parse one declared argument. */
|
|
67
|
+
export declare function parseArgument(arg: string): ArgumentRule;
|
|
68
|
+
/** Check and parse one declared capability. Throws `SpawnRuleError` on a bad declaration. */
|
|
69
|
+
export declare function compileCapability(capability: SpawnCapability): CompiledCapability;
|
|
70
|
+
/**
|
|
71
|
+
* Whether `args` fit a capability's argument rules, and the values its placeholders took; null
|
|
72
|
+
* when they do not. The rules before a repeated placeholder take the first arguments, those after
|
|
73
|
+
* it the last, and it takes what is left between, each by its own pattern.
|
|
74
|
+
*/
|
|
75
|
+
export declare function matchArguments(rules: readonly ArgumentRule[], args: readonly string[]): PlaceholderValues | null;
|
|
76
|
+
/** What `matchSpawn` answers for a call a capability allows. */
|
|
77
|
+
export interface SpawnMatch {
|
|
78
|
+
readonly capability: CompiledCapability;
|
|
79
|
+
/** The program to run: the declared absolute path, or the name as it was pinned. */
|
|
80
|
+
readonly path: string;
|
|
81
|
+
readonly values: PlaceholderValues;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The capability that allows running `program` with `args`, or null when none does. `program` is
|
|
85
|
+
* the declared path or name exactly: a bare name is never looked up on any `PATH` here, and only
|
|
86
|
+
* runs where `resolved` pinned it.
|
|
87
|
+
*
|
|
88
|
+
* @param resolved where each declared bare name was pinned at startup, by `resolveProgram`
|
|
89
|
+
*/
|
|
90
|
+
export declare function matchSpawn(capabilities: readonly CompiledCapability[], program: string, args: readonly string[], resolved?: Readonly<Record<string, string | null>>): SpawnMatch | null;
|
|
91
|
+
/** What `resolveProgram` asks of the file system. */
|
|
92
|
+
export interface ProgramLookup {
|
|
93
|
+
/** Whether an executable file is at `path`. */
|
|
94
|
+
isExecutable(path: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Whether `path` is a developer tool stub that only runs `xcrun`, with no Command Line Tools
|
|
97
|
+
* installed to run. Such a tool reports absent.
|
|
98
|
+
*/
|
|
99
|
+
isStub?(path: string): boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Where a declared program runs from, pinned once at startup, or null when it is absent: not
|
|
103
|
+
* found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on
|
|
104
|
+
* `SEARCH_PATH` alone.
|
|
105
|
+
*/
|
|
106
|
+
export declare function resolveProgram(program: string, lookup: ProgramLookup): string | null;
|
|
107
|
+
/** The environment a spawned program gets: only the variables declared, of those given. */
|
|
108
|
+
export declare function filterEnvironment(env: Readonly<Record<string, string | undefined>>, allowed: readonly string[]): Record<string, string>;
|