@ng-native/device 0.29.0 → 0.30.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/README.md +2 -2
- package/dist/accessibility.js +3 -3
- package/dist/app-lifecycle.js +3 -3
- package/dist/app-state.js +3 -3
- package/dist/app-windows.d.ts +9 -0
- package/dist/app-windows.js +3 -3
- package/dist/app-windows.js.map +1 -1
- package/dist/color-scheme.js +3 -3
- package/dist/deep-links.js +3 -3
- package/dist/dev-menu.js +3 -3
- package/dist/dialogs.js +3 -3
- package/dist/direction.js +3 -3
- package/dist/dock.js +3 -3
- package/dist/drag-and-drop.js +3 -3
- package/dist/hardware-back.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keyboard-focus.d.ts +13 -0
- package/dist/keyboard-focus.js +22 -0
- package/dist/keyboard-focus.js.map +1 -0
- package/dist/keyboard.js +3 -3
- package/dist/layout-animation.js +3 -3
- package/dist/menus.d.ts +15 -2
- package/dist/menus.js +20 -7
- package/dist/menus.js.map +1 -1
- package/dist/navigation-bar.js +3 -3
- package/dist/os-support.js +3 -0
- package/dist/os-support.js.map +1 -1
- package/dist/processes.js +3 -3
- package/dist/safe-area.js +3 -3
- package/dist/screen.js +3 -3
- package/dist/sharing.js +3 -3
- package/dist/shell.js +3 -3
- package/dist/spawn-rules.d.ts +10 -4
- package/dist/spawn-rules.js +32 -16
- package/dist/spawn-rules.js.map +1 -1
- package/dist/status-bar.js +3 -3
- package/dist/tray.js +3 -3
- package/dist/undo-stack.js +3 -3
- package/dist/vibration.js +3 -3
- package/package.json +5 -5
package/dist/spawn-rules.d.ts
CHANGED
|
@@ -19,14 +19,15 @@
|
|
|
19
19
|
* - Shells, `env` and other programs that run their arguments as a command are refused as
|
|
20
20
|
* programs, and so are Windows `.bat` and `.cmd` files, which `cmd.exe` re-parses (the BatBadBut
|
|
21
21
|
* class of bug). `spawn` never goes through a shell.
|
|
22
|
-
* - A program is an absolute path,
|
|
23
|
-
* (`SEARCH_PATH`), never the inherited
|
|
22
|
+
* - A program is an absolute path, a path in the user's home folder (`~/.local/bin/claude`), or a
|
|
23
|
+
* bare name resolved once at startup on a fixed search path (`SEARCH_PATH`), never the inherited
|
|
24
|
+
* `PATH`, and pinned there. A home path is pinned against the account's home folder at startup.
|
|
24
25
|
*
|
|
25
26
|
* The boundary guards against bugs and injected content, not against a hostile app.
|
|
26
27
|
*/
|
|
27
28
|
/** A spawn capability as `app.json` declares it. */
|
|
28
29
|
export interface SpawnCapability {
|
|
29
|
-
/** An absolute path, or a bare name resolved on `SEARCH_PATH
|
|
30
|
+
/** An absolute path, a `~/` path in the home folder, or a bare name resolved on `SEARCH_PATH`. */
|
|
30
31
|
readonly program: string;
|
|
31
32
|
/** Literal arguments and `{name:regex}` placeholders, in order. */
|
|
32
33
|
readonly args?: readonly string[];
|
|
@@ -97,11 +98,16 @@ export interface ProgramLookup {
|
|
|
97
98
|
* installed to run. Such a tool reports absent.
|
|
98
99
|
*/
|
|
99
100
|
isStub?(path: string): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* The account's home folder, absolute, that a `~/` program is in: the user database's, never
|
|
103
|
+
* `HOME`. Without it one is absent.
|
|
104
|
+
*/
|
|
105
|
+
readonly home?: string;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Where a declared program runs from, pinned once at startup, or null when it is absent: not
|
|
103
109
|
* found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on
|
|
104
|
-
* `SEARCH_PATH` alone.
|
|
110
|
+
* `SEARCH_PATH` alone, and a `~/` path in `lookup.home` alone.
|
|
105
111
|
*/
|
|
106
112
|
export declare function resolveProgram(program: string, lookup: ProgramLookup): string | null;
|
|
107
113
|
/** The environment a spawned program gets: only the variables declared, of those given. */
|
package/dist/spawn-rules.js
CHANGED
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
* - Shells, `env` and other programs that run their arguments as a command are refused as
|
|
20
20
|
* programs, and so are Windows `.bat` and `.cmd` files, which `cmd.exe` re-parses (the BatBadBut
|
|
21
21
|
* class of bug). `spawn` never goes through a shell.
|
|
22
|
-
* - A program is an absolute path,
|
|
23
|
-
* (`SEARCH_PATH`), never the inherited
|
|
22
|
+
* - A program is an absolute path, a path in the user's home folder (`~/.local/bin/claude`), or a
|
|
23
|
+
* bare name resolved once at startup on a fixed search path (`SEARCH_PATH`), never the inherited
|
|
24
|
+
* `PATH`, and pinned there. A home path is pinned against the account's home folder at startup.
|
|
24
25
|
*
|
|
25
26
|
* The boundary guards against bugs and injected content, not against a hostile app.
|
|
26
27
|
*/
|
|
@@ -101,20 +102,27 @@ export function programProblem(program) {
|
|
|
101
102
|
if (REFUSED_PROGRAMS.has(name)) {
|
|
102
103
|
return `${program} runs its arguments as a command, so it cannot be declared`;
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return `${program} is not a normalized absolute path`;
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
if (/[\\/]/.test(program)) {
|
|
112
|
-
return `${program} is a relative path: give an absolute path or a bare name`;
|
|
113
|
-
}
|
|
105
|
+
const path = pathProblem(program);
|
|
106
|
+
if (path !== undefined)
|
|
107
|
+
return path;
|
|
114
108
|
if (program === '.' || program === '..')
|
|
115
109
|
return `${program} is not a program`;
|
|
116
110
|
return null;
|
|
117
111
|
}
|
|
112
|
+
/** Why a program given as a path cannot be declared, null when it can, undefined for a bare name. */
|
|
113
|
+
function pathProblem(program) {
|
|
114
|
+
const home = program.startsWith('~/');
|
|
115
|
+
if (!home && !program.startsWith('/')) {
|
|
116
|
+
return /[\\/]/.test(program)
|
|
117
|
+
? `${program} is a relative path: give an absolute path, a ~/ path or a bare name`
|
|
118
|
+
: undefined;
|
|
119
|
+
}
|
|
120
|
+
const segments = program.split('/').slice(1);
|
|
121
|
+
if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
|
|
122
|
+
return `${program} is not a normalized ${home ? 'home' : 'absolute'} path`;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
118
126
|
/** Parse one declared argument. */
|
|
119
127
|
export function parseArgument(arg) {
|
|
120
128
|
if (typeof arg !== 'string')
|
|
@@ -293,14 +301,22 @@ export function matchSpawn(capabilities, program, args, resolved = {}) {
|
|
|
293
301
|
/**
|
|
294
302
|
* Where a declared program runs from, pinned once at startup, or null when it is absent: not
|
|
295
303
|
* found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on
|
|
296
|
-
* `SEARCH_PATH` alone.
|
|
304
|
+
* `SEARCH_PATH` alone, and a `~/` path in `lookup.home` alone.
|
|
297
305
|
*/
|
|
298
306
|
export function resolveProgram(program, lookup) {
|
|
299
307
|
if (programProblem(program))
|
|
300
308
|
return null;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
309
|
+
let candidates;
|
|
310
|
+
if (program.startsWith('/'))
|
|
311
|
+
candidates = [program];
|
|
312
|
+
else if (program.startsWith('~/')) {
|
|
313
|
+
if (!lookup.home?.startsWith('/'))
|
|
314
|
+
return null;
|
|
315
|
+
// Trimmed after the check, so a home of `/` is the root: `~/tool` is `/tool`.
|
|
316
|
+
candidates = [lookup.home.replace(/\/+$/, '') + program.slice(1)];
|
|
317
|
+
}
|
|
318
|
+
else
|
|
319
|
+
candidates = SEARCH_PATH.map((dir) => `${dir}/${program}`);
|
|
304
320
|
for (const candidate of candidates) {
|
|
305
321
|
if (!lookup.isExecutable(candidate))
|
|
306
322
|
continue;
|
package/dist/spawn-rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-rules.js","sourceRoot":"","sources":["../src/spawn-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAgCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,UAAU;IACV,MAAM;IACN,W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,OAAO,EAAE,CAAC,CAAC;IAClD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC;YAAE,SAAS;QAC9C,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,iBAAiB,CAC/B,GAAiD,EACjD,OAA0B;IAE1B,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACjF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The rules a desktop app's declared spawn capabilities follow: which programs it may run, with\n * which arguments. Plain TypeScript with no imports, so the config plugin can check the declaration\n * at build time and `Processes` can refuse an undeclared call with a clear error before the\n * desktop host checks it again natively.\n *\n * An entry names a program and the arguments it may take:\n *\n * { program: '/usr/bin/git', args: ['clone', '{url:https://\\\\S+}', '{dir:[\\\\w.-]+}'] }\n *\n * Each argument is a literal, matched exactly, or a `{name:regex}` placeholder. A placeholder\n * followed by `...` matches zero or more arguments, each by the same rules.\n *\n * - A placeholder's pattern is anchored: it matches the whole argument, so `{branch:[a-z]+}`\n * never accepts `--upload-pack=...`.\n * - A placeholder never accepts an argument starting with `-` unless each alternative of its\n * pattern starts with one, so an option cannot be injected where a value was declared.\n * - No argument may hold a NUL character, which a C string would cut short.\n * - Shells, `env` and other programs that run their arguments as a command are refused as\n * programs, and so are Windows `.bat` and `.cmd` files, which `cmd.exe` re-parses (the BatBadBut\n * class of bug). `spawn` never goes through a shell.\n * - A program is an absolute path, or a bare name resolved once at startup on a fixed search path\n * (`SEARCH_PATH`), never the inherited `PATH`, and pinned there.\n *\n * The boundary guards against bugs and injected content, not against a hostile app.\n */\n\n/** A spawn capability as `app.json` declares it. */\nexport interface SpawnCapability {\n /** An absolute path, or a bare name resolved on `SEARCH_PATH` at startup. */\n readonly program: string;\n /** Literal arguments and `{name:regex}` placeholders, in order. */\n readonly args?: readonly string[];\n}\n\n/** One declared argument, parsed. */\nexport type ArgumentRule =\n | { readonly kind: 'literal'; readonly value: string }\n | {\n readonly kind: 'placeholder';\n readonly name: string;\n readonly pattern: RegExp;\n /** Whether each alternative of the pattern starts with `-`, so the value may be an option. */\n readonly option: boolean;\n /** `{name:regex}...`: zero or more arguments. */\n readonly repeated: boolean;\n };\n\n/** A spawn capability, checked and parsed. */\nexport interface CompiledCapability {\n readonly program: string;\n readonly args: readonly ArgumentRule[];\n}\n\n/** What a call that matched was given for each placeholder: a list for a repeated one. */\nexport type PlaceholderValues = Record<string, string | readonly string[]>;\n\n/**\n * Where a bare program name is looked for, in order: the system's directories, then Homebrew's on\n * Apple silicon and on Intel. A Finder-launched app inherits only launchd's `PATH`, so Homebrew's\n * tools would never resolve on the inherited one.\n */\nexport const SEARCH_PATH: readonly string[] = [\n '/usr/bin',\n '/bin',\n '/usr/sbin',\n '/sbin',\n '/opt/homebrew/bin',\n '/usr/local/bin',\n];\n\n/**\n * Programs refused whatever their path: shells, and programs whose job is to run their own\n * arguments as a command (`env`, `xargs`, `sudo`, `nice`, `nohup`), which would turn an argument\n * pattern into a command line.\n */\nconst REFUSED_PROGRAMS = new Set([\n 'sh',\n 'bash',\n 'zsh',\n 'dash',\n 'ksh',\n 'mksh',\n 'csh',\n 'tcsh',\n 'fish',\n 'nu',\n 'env',\n 'xargs',\n 'sudo',\n 'doas',\n 'su',\n 'osascript',\n 'cmd',\n 'powershell',\n 'pwsh',\n 'nice',\n 'nohup',\n // Linux's: escalation (`pkexec`), a shell of its own (`busybox`), and leaving a Flatpak sandbox,\n // the session or the mount namespace (`flatpak-spawn --host`, `systemd-run`, `nsenter`, `chroot`).\n 'pkexec',\n 'busybox',\n 'flatpak-spawn',\n 'systemd-run',\n 'nsenter',\n 'chroot',\n]);\n\n/** Windows batch files, which run through `cmd.exe` and so re-parse their arguments. */\nconst REFUSED_EXTENSIONS = ['.bat', '.cmd'];\n\nconst PLACEHOLDER = /^\\{([A-Za-z_][A-Za-z0-9_]*):([\\s\\S]+)\\}(\\.\\.\\.)?$/;\n\n/** Why a declaration or a call was refused. */\nexport class SpawnRuleError extends Error {\n override readonly name = 'SpawnRuleError';\n}\n\n/** The last segment of a path, either separator, lower-cased and without `.exe`. */\nfunction baseName(program: string): string {\n const last = program.split(/[\\\\/]/).at(-1) ?? '';\n return last.toLowerCase().replace(/\\.exe$/, '');\n}\n\n/** Why `program` cannot be declared, or null when it can. */\nexport function programProblem(program: string): string | null {\n if (typeof program !== 'string' || program.length === 0) return 'a program is required';\n if (program.includes('\\0')) return 'a program cannot hold a NUL character';\n if (program !== program.trim()) return 'a program cannot start or end with white space';\n const lower = program.toLowerCase();\n if (REFUSED_EXTENSIONS.some((extension) => lower.endsWith(extension))) {\n return `${program} is a batch file, which runs through cmd.exe and re-parses its arguments`;\n }\n const name = baseName(program);\n if (REFUSED_PROGRAMS.has(name)) {\n return `${program} runs its arguments as a command, so it cannot be declared`;\n }\n if (program.startsWith('/')) {\n const segments = program.split('/').slice(1);\n if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {\n return `${program} is not a normalized absolute path`;\n }\n return null;\n }\n if (/[\\\\/]/.test(program)) {\n return `${program} is a relative path: give an absolute path or a bare name`;\n }\n if (program === '.' || program === '..') return `${program} is not a program`;\n return null;\n}\n\n/** Parse one declared argument. */\nexport function parseArgument(arg: string): ArgumentRule {\n if (typeof arg !== 'string') throw new SpawnRuleError('an argument must be a string');\n if (arg.includes('\\0')) throw new SpawnRuleError('an argument cannot hold a NUL character');\n const placeholder = PLACEHOLDER.exec(arg);\n if (!placeholder) return { kind: 'literal', value: arg };\n const [, name, source, dots] = placeholder as unknown as [string, string, string, string?];\n if (hasLookbehindOrNamedGroup(source)) {\n throw new SpawnRuleError(\n `{${name}} has a (?< named group or lookbehind, which the desktop's native rules cannot compile`,\n );\n }\n let pattern: RegExp;\n try {\n // On its own first: a pattern that compiles alone has balanced groups, so one such as\n // `a)|(.*` cannot close the anchoring group early and escape it.\n new RegExp(source);\n // Anchored as a whole, so an alternation cannot escape it: `{x:a|b}` is `^(?:a|b)$`.\n pattern = new RegExp(`^(?:${source})$`);\n } catch (error) {\n throw new SpawnRuleError(`{${name}} has a pattern that does not compile: ${String(error)}`);\n }\n const option = alternatives(source).every((one) => /^\\^?\\\\?-/.test(one));\n return { kind: 'placeholder', name, pattern, option, repeated: dots !== undefined };\n}\n\n/**\n * Whether a pattern opens a `(?<` group (a named group or a lookbehind) outside an escape or a\n * class. JavaScript compiles one, but the native rules' ECMAScript `std::regex` does not, and a\n * declaration it cannot compile would be dropped there with no error.\n */\nfunction hasLookbehindOrNamedGroup(source: string): boolean {\n let inClass = false;\n for (let at = 0; at < source.length; at++) {\n const char = source[at];\n if (char === '\\\\') at++;\n else if (inClass) inClass = char !== ']';\n else if (char === '[') inClass = true;\n else if (source.startsWith('(?<', at)) return true;\n }\n return false;\n}\n\n/**\n * A pattern's top-level alternatives: `-v|.*` is `-v` and `.*`. A `|` in a group, in a class or\n * escaped is not one. The pattern has compiled, so its groups and classes are balanced.\n */\nfunction alternatives(source: string): string[] {\n const found: string[] = [];\n let depth = 0;\n let inClass = false;\n let start = 0;\n for (let at = 0; at < source.length; at++) {\n const char = source[at];\n if (char === '\\\\') at++;\n else if (inClass) inClass = char !== ']';\n else if (char === '[') inClass = true;\n else if (char === '(') depth++;\n else if (char === ')') depth--;\n else if (char === '|' && depth === 0) {\n found.push(source.slice(start, at));\n start = at + 1;\n }\n }\n found.push(source.slice(start));\n return found;\n}\n\n/** Check and parse one declared capability. Throws `SpawnRuleError` on a bad declaration. */\nexport function compileCapability(capability: SpawnCapability): CompiledCapability {\n const problem = programProblem(capability?.program);\n if (problem) throw new SpawnRuleError(problem);\n if (capability.args !== undefined && !Array.isArray(capability.args)) {\n throw new SpawnRuleError(`${capability.program}: args must be a list`);\n }\n const args = (capability.args ?? []).map(parseArgument);\n const names = new Set<string>();\n let repeated = 0;\n for (const rule of args) {\n if (rule.kind !== 'placeholder') continue;\n if (names.has(rule.name)) {\n throw new SpawnRuleError(`${capability.program}: {${rule.name}} is declared twice`);\n }\n names.add(rule.name);\n if (rule.repeated) repeated++;\n }\n // Two repeated placeholders could share the arguments between them in more than one way.\n if (repeated > 1) {\n throw new SpawnRuleError(`${capability.program}: at most one placeholder may repeat`);\n }\n return { program: capability.program, args };\n}\n\n/** Whether one argument passes a placeholder. */\nfunction passes(rule: Extract<ArgumentRule, { kind: 'placeholder' }>, arg: string): boolean {\n if (arg.startsWith('-') && !rule.option) return false;\n return rule.pattern.test(arg);\n}\n\n/** Whether one argument passes a rule. */\nfunction fits(rule: ArgumentRule, arg: string): boolean {\n return rule.kind === 'literal' ? rule.value === arg : passes(rule, arg);\n}\n\n/**\n * Whether `args` fit a capability's argument rules, and the values its placeholders took; null\n * when they do not. The rules before a repeated placeholder take the first arguments, those after\n * it the last, and it takes what is left between, each by its own pattern.\n */\nexport function matchArguments(\n rules: readonly ArgumentRule[],\n args: readonly string[],\n): PlaceholderValues | null {\n if (args.some((arg) => typeof arg !== 'string' || arg.includes('\\0'))) return null;\n const at = rules.findIndex((rule) => rule.kind === 'placeholder' && rule.repeated);\n const head = at === -1 ? rules : rules.slice(0, at);\n const tail = at === -1 ? [] : rules.slice(at + 1);\n if (at === -1 ? args.length !== rules.length : args.length < head.length + tail.length) {\n return null;\n }\n const values: Record<string, string | readonly string[]> = {};\n const take = (rule: ArgumentRule, arg: string): boolean => {\n if (!fits(rule, arg)) return false;\n if (rule.kind === 'placeholder') values[rule.name] = arg;\n return true;\n };\n for (let index = 0; index < head.length; index++) {\n if (!take(head[index]!, args[index]!)) return null;\n }\n const tailStart = args.length - tail.length;\n for (let index = 0; index < tail.length; index++) {\n if (!take(tail[index]!, args[tailStart + index]!)) return null;\n }\n if (at !== -1) {\n const rule = rules[at] as Extract<ArgumentRule, { kind: 'placeholder' }>;\n const middle = args.slice(head.length, tailStart);\n if (!middle.every((arg) => passes(rule, arg))) return null;\n values[rule.name] = middle;\n }\n return values;\n}\n\n/** What `matchSpawn` answers for a call a capability allows. */\nexport interface SpawnMatch {\n readonly capability: CompiledCapability;\n /** The program to run: the declared absolute path, or the name as it was pinned. */\n readonly path: string;\n readonly values: PlaceholderValues;\n}\n\n/**\n * The capability that allows running `program` with `args`, or null when none does. `program` is\n * the declared path or name exactly: a bare name is never looked up on any `PATH` here, and only\n * runs where `resolved` pinned it.\n *\n * @param resolved where each declared bare name was pinned at startup, by `resolveProgram`\n */\nexport function matchSpawn(\n capabilities: readonly CompiledCapability[],\n program: string,\n args: readonly string[],\n resolved: Readonly<Record<string, string | null>> = {},\n): SpawnMatch | null {\n for (const capability of capabilities) {\n const pinned = capability.program.startsWith('/')\n ? capability.program\n : (resolved[capability.program] ?? null);\n if (pinned === null) continue;\n if (program !== capability.program && program !== pinned) continue;\n const values = matchArguments(capability.args, args);\n if (values) return { capability, path: pinned, values };\n }\n return null;\n}\n\n/** What `resolveProgram` asks of the file system. */\nexport interface ProgramLookup {\n /** Whether an executable file is at `path`. */\n isExecutable(path: string): boolean;\n /**\n * Whether `path` is a developer tool stub that only runs `xcrun`, with no Command Line Tools\n * installed to run. Such a tool reports absent.\n */\n isStub?(path: string): boolean;\n}\n\n/**\n * Where a declared program runs from, pinned once at startup, or null when it is absent: not\n * found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on\n * `SEARCH_PATH` alone.\n */\nexport function resolveProgram(program: string, lookup: ProgramLookup): string | null {\n if (programProblem(program)) return null;\n const candidates = program.startsWith('/')\n ? [program]\n : SEARCH_PATH.map((dir) => `${dir}/${program}`);\n for (const candidate of candidates) {\n if (!lookup.isExecutable(candidate)) continue;\n return lookup.isStub?.(candidate) ? null : candidate;\n }\n return null;\n}\n\n/** The environment a spawned program gets: only the variables declared, of those given. */\nexport function filterEnvironment(\n env: Readonly<Record<string, string | undefined>>,\n allowed: readonly string[],\n): Record<string, string> {\n const filtered: Record<string, string> = {};\n for (const name of allowed) {\n const value = Object.hasOwn(env, name) ? env[name] : undefined;\n if (typeof value === 'string' && !value.includes('\\0')) filtered[name] = value;\n }\n return filtered;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"spawn-rules.js","sourceRoot":"","sources":["../src/spawn-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAgCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,UAAU;IACV,MAAM;IACN,WAAW;IACX,OAAO;IACP,mBAAmB;IACnB,gBAAgB;CACjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,IAAI;IACJ,WAAW;IACX,KAAK;IACL,YAAY;IACZ,MAAM;IACN,MAAM;IACN,OAAO;IACP,iGAAiG;IACjG,mGAAmG;IACnG,QAAQ;IACR,SAAS;IACT,eAAe;IACf,aAAa;IACb,SAAS;IACT,QAAQ;CACT,CAAC,CAAC;AAEH,wFAAwF;AACxF,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5C,MA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AAC,CAAC;IACpE,CAAC;;QAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC,CAAC;IAClE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC;YAAE,SAAS;QAC9C,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,iBAAiB,CAC/B,GAAiD,EACjD,OAA0B;IAE1B,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACjF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The rules a desktop app's declared spawn capabilities follow: which programs it may run, with\n * which arguments. Plain TypeScript with no imports, so the config plugin can check the declaration\n * at build time and `Processes` can refuse an undeclared call with a clear error before the\n * desktop host checks it again natively.\n *\n * An entry names a program and the arguments it may take:\n *\n * { program: '/usr/bin/git', args: ['clone', '{url:https://\\\\S+}', '{dir:[\\\\w.-]+}'] }\n *\n * Each argument is a literal, matched exactly, or a `{name:regex}` placeholder. A placeholder\n * followed by `...` matches zero or more arguments, each by the same rules.\n *\n * - A placeholder's pattern is anchored: it matches the whole argument, so `{branch:[a-z]+}`\n * never accepts `--upload-pack=...`.\n * - A placeholder never accepts an argument starting with `-` unless each alternative of its\n * pattern starts with one, so an option cannot be injected where a value was declared.\n * - No argument may hold a NUL character, which a C string would cut short.\n * - Shells, `env` and other programs that run their arguments as a command are refused as\n * programs, and so are Windows `.bat` and `.cmd` files, which `cmd.exe` re-parses (the BatBadBut\n * class of bug). `spawn` never goes through a shell.\n * - A program is an absolute path, a path in the user's home folder (`~/.local/bin/claude`), or a\n * bare name resolved once at startup on a fixed search path (`SEARCH_PATH`), never the inherited\n * `PATH`, and pinned there. A home path is pinned against the account's home folder at startup.\n *\n * The boundary guards against bugs and injected content, not against a hostile app.\n */\n\n/** A spawn capability as `app.json` declares it. */\nexport interface SpawnCapability {\n /** An absolute path, a `~/` path in the home folder, or a bare name resolved on `SEARCH_PATH`. */\n readonly program: string;\n /** Literal arguments and `{name:regex}` placeholders, in order. */\n readonly args?: readonly string[];\n}\n\n/** One declared argument, parsed. */\nexport type ArgumentRule =\n | { readonly kind: 'literal'; readonly value: string }\n | {\n readonly kind: 'placeholder';\n readonly name: string;\n readonly pattern: RegExp;\n /** Whether each alternative of the pattern starts with `-`, so the value may be an option. */\n readonly option: boolean;\n /** `{name:regex}...`: zero or more arguments. */\n readonly repeated: boolean;\n };\n\n/** A spawn capability, checked and parsed. */\nexport interface CompiledCapability {\n readonly program: string;\n readonly args: readonly ArgumentRule[];\n}\n\n/** What a call that matched was given for each placeholder: a list for a repeated one. */\nexport type PlaceholderValues = Record<string, string | readonly string[]>;\n\n/**\n * Where a bare program name is looked for, in order: the system's directories, then Homebrew's on\n * Apple silicon and on Intel. A Finder-launched app inherits only launchd's `PATH`, so Homebrew's\n * tools would never resolve on the inherited one.\n */\nexport const SEARCH_PATH: readonly string[] = [\n '/usr/bin',\n '/bin',\n '/usr/sbin',\n '/sbin',\n '/opt/homebrew/bin',\n '/usr/local/bin',\n];\n\n/**\n * Programs refused whatever their path: shells, and programs whose job is to run their own\n * arguments as a command (`env`, `xargs`, `sudo`, `nice`, `nohup`), which would turn an argument\n * pattern into a command line.\n */\nconst REFUSED_PROGRAMS = new Set([\n 'sh',\n 'bash',\n 'zsh',\n 'dash',\n 'ksh',\n 'mksh',\n 'csh',\n 'tcsh',\n 'fish',\n 'nu',\n 'env',\n 'xargs',\n 'sudo',\n 'doas',\n 'su',\n 'osascript',\n 'cmd',\n 'powershell',\n 'pwsh',\n 'nice',\n 'nohup',\n // Linux's: escalation (`pkexec`), a shell of its own (`busybox`), and leaving a Flatpak sandbox,\n // the session or the mount namespace (`flatpak-spawn --host`, `systemd-run`, `nsenter`, `chroot`).\n 'pkexec',\n 'busybox',\n 'flatpak-spawn',\n 'systemd-run',\n 'nsenter',\n 'chroot',\n]);\n\n/** Windows batch files, which run through `cmd.exe` and so re-parse their arguments. */\nconst REFUSED_EXTENSIONS = ['.bat', '.cmd'];\n\nconst PLACEHOLDER = /^\\{([A-Za-z_][A-Za-z0-9_]*):([\\s\\S]+)\\}(\\.\\.\\.)?$/;\n\n/** Why a declaration or a call was refused. */\nexport class SpawnRuleError extends Error {\n override readonly name = 'SpawnRuleError';\n}\n\n/** The last segment of a path, either separator, lower-cased and without `.exe`. */\nfunction baseName(program: string): string {\n const last = program.split(/[\\\\/]/).at(-1) ?? '';\n return last.toLowerCase().replace(/\\.exe$/, '');\n}\n\n/** Why `program` cannot be declared, or null when it can. */\nexport function programProblem(program: string): string | null {\n if (typeof program !== 'string' || program.length === 0) return 'a program is required';\n if (program.includes('\\0')) return 'a program cannot hold a NUL character';\n if (program !== program.trim()) return 'a program cannot start or end with white space';\n const lower = program.toLowerCase();\n if (REFUSED_EXTENSIONS.some((extension) => lower.endsWith(extension))) {\n return `${program} is a batch file, which runs through cmd.exe and re-parses its arguments`;\n }\n const name = baseName(program);\n if (REFUSED_PROGRAMS.has(name)) {\n return `${program} runs its arguments as a command, so it cannot be declared`;\n }\n const path = pathProblem(program);\n if (path !== undefined) return path;\n if (program === '.' || program === '..') return `${program} is not a program`;\n return null;\n}\n\n/** Why a program given as a path cannot be declared, null when it can, undefined for a bare name. */\nfunction pathProblem(program: string): string | null | undefined {\n const home = program.startsWith('~/');\n if (!home && !program.startsWith('/')) {\n return /[\\\\/]/.test(program)\n ? `${program} is a relative path: give an absolute path, a ~/ path or a bare name`\n : undefined;\n }\n const segments = program.split('/').slice(1);\n if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {\n return `${program} is not a normalized ${home ? 'home' : 'absolute'} path`;\n }\n return null;\n}\n\n/** Parse one declared argument. */\nexport function parseArgument(arg: string): ArgumentRule {\n if (typeof arg !== 'string') throw new SpawnRuleError('an argument must be a string');\n if (arg.includes('\\0')) throw new SpawnRuleError('an argument cannot hold a NUL character');\n const placeholder = PLACEHOLDER.exec(arg);\n if (!placeholder) return { kind: 'literal', value: arg };\n const [, name, source, dots] = placeholder as unknown as [string, string, string, string?];\n if (hasLookbehindOrNamedGroup(source)) {\n throw new SpawnRuleError(\n `{${name}} has a (?< named group or lookbehind, which the desktop's native rules cannot compile`,\n );\n }\n let pattern: RegExp;\n try {\n // On its own first: a pattern that compiles alone has balanced groups, so one such as\n // `a)|(.*` cannot close the anchoring group early and escape it.\n new RegExp(source);\n // Anchored as a whole, so an alternation cannot escape it: `{x:a|b}` is `^(?:a|b)$`.\n pattern = new RegExp(`^(?:${source})$`);\n } catch (error) {\n throw new SpawnRuleError(`{${name}} has a pattern that does not compile: ${String(error)}`);\n }\n const option = alternatives(source).every((one) => /^\\^?\\\\?-/.test(one));\n return { kind: 'placeholder', name, pattern, option, repeated: dots !== undefined };\n}\n\n/**\n * Whether a pattern opens a `(?<` group (a named group or a lookbehind) outside an escape or a\n * class. JavaScript compiles one, but the native rules' ECMAScript `std::regex` does not, and a\n * declaration it cannot compile would be dropped there with no error.\n */\nfunction hasLookbehindOrNamedGroup(source: string): boolean {\n let inClass = false;\n for (let at = 0; at < source.length; at++) {\n const char = source[at];\n if (char === '\\\\') at++;\n else if (inClass) inClass = char !== ']';\n else if (char === '[') inClass = true;\n else if (source.startsWith('(?<', at)) return true;\n }\n return false;\n}\n\n/**\n * A pattern's top-level alternatives: `-v|.*` is `-v` and `.*`. A `|` in a group, in a class or\n * escaped is not one. The pattern has compiled, so its groups and classes are balanced.\n */\nfunction alternatives(source: string): string[] {\n const found: string[] = [];\n let depth = 0;\n let inClass = false;\n let start = 0;\n for (let at = 0; at < source.length; at++) {\n const char = source[at];\n if (char === '\\\\') at++;\n else if (inClass) inClass = char !== ']';\n else if (char === '[') inClass = true;\n else if (char === '(') depth++;\n else if (char === ')') depth--;\n else if (char === '|' && depth === 0) {\n found.push(source.slice(start, at));\n start = at + 1;\n }\n }\n found.push(source.slice(start));\n return found;\n}\n\n/** Check and parse one declared capability. Throws `SpawnRuleError` on a bad declaration. */\nexport function compileCapability(capability: SpawnCapability): CompiledCapability {\n const problem = programProblem(capability?.program);\n if (problem) throw new SpawnRuleError(problem);\n if (capability.args !== undefined && !Array.isArray(capability.args)) {\n throw new SpawnRuleError(`${capability.program}: args must be a list`);\n }\n const args = (capability.args ?? []).map(parseArgument);\n const names = new Set<string>();\n let repeated = 0;\n for (const rule of args) {\n if (rule.kind !== 'placeholder') continue;\n if (names.has(rule.name)) {\n throw new SpawnRuleError(`${capability.program}: {${rule.name}} is declared twice`);\n }\n names.add(rule.name);\n if (rule.repeated) repeated++;\n }\n // Two repeated placeholders could share the arguments between them in more than one way.\n if (repeated > 1) {\n throw new SpawnRuleError(`${capability.program}: at most one placeholder may repeat`);\n }\n return { program: capability.program, args };\n}\n\n/** Whether one argument passes a placeholder. */\nfunction passes(rule: Extract<ArgumentRule, { kind: 'placeholder' }>, arg: string): boolean {\n if (arg.startsWith('-') && !rule.option) return false;\n return rule.pattern.test(arg);\n}\n\n/** Whether one argument passes a rule. */\nfunction fits(rule: ArgumentRule, arg: string): boolean {\n return rule.kind === 'literal' ? rule.value === arg : passes(rule, arg);\n}\n\n/**\n * Whether `args` fit a capability's argument rules, and the values its placeholders took; null\n * when they do not. The rules before a repeated placeholder take the first arguments, those after\n * it the last, and it takes what is left between, each by its own pattern.\n */\nexport function matchArguments(\n rules: readonly ArgumentRule[],\n args: readonly string[],\n): PlaceholderValues | null {\n if (args.some((arg) => typeof arg !== 'string' || arg.includes('\\0'))) return null;\n const at = rules.findIndex((rule) => rule.kind === 'placeholder' && rule.repeated);\n const head = at === -1 ? rules : rules.slice(0, at);\n const tail = at === -1 ? [] : rules.slice(at + 1);\n if (at === -1 ? args.length !== rules.length : args.length < head.length + tail.length) {\n return null;\n }\n const values: Record<string, string | readonly string[]> = {};\n const take = (rule: ArgumentRule, arg: string): boolean => {\n if (!fits(rule, arg)) return false;\n if (rule.kind === 'placeholder') values[rule.name] = arg;\n return true;\n };\n for (let index = 0; index < head.length; index++) {\n if (!take(head[index]!, args[index]!)) return null;\n }\n const tailStart = args.length - tail.length;\n for (let index = 0; index < tail.length; index++) {\n if (!take(tail[index]!, args[tailStart + index]!)) return null;\n }\n if (at !== -1) {\n const rule = rules[at] as Extract<ArgumentRule, { kind: 'placeholder' }>;\n const middle = args.slice(head.length, tailStart);\n if (!middle.every((arg) => passes(rule, arg))) return null;\n values[rule.name] = middle;\n }\n return values;\n}\n\n/** What `matchSpawn` answers for a call a capability allows. */\nexport interface SpawnMatch {\n readonly capability: CompiledCapability;\n /** The program to run: the declared absolute path, or the name as it was pinned. */\n readonly path: string;\n readonly values: PlaceholderValues;\n}\n\n/**\n * The capability that allows running `program` with `args`, or null when none does. `program` is\n * the declared path or name exactly: a bare name is never looked up on any `PATH` here, and only\n * runs where `resolved` pinned it.\n *\n * @param resolved where each declared bare name was pinned at startup, by `resolveProgram`\n */\nexport function matchSpawn(\n capabilities: readonly CompiledCapability[],\n program: string,\n args: readonly string[],\n resolved: Readonly<Record<string, string | null>> = {},\n): SpawnMatch | null {\n for (const capability of capabilities) {\n const pinned = capability.program.startsWith('/')\n ? capability.program\n : (resolved[capability.program] ?? null);\n if (pinned === null) continue;\n if (program !== capability.program && program !== pinned) continue;\n const values = matchArguments(capability.args, args);\n if (values) return { capability, path: pinned, values };\n }\n return null;\n}\n\n/** What `resolveProgram` asks of the file system. */\nexport interface ProgramLookup {\n /** Whether an executable file is at `path`. */\n isExecutable(path: string): boolean;\n /**\n * Whether `path` is a developer tool stub that only runs `xcrun`, with no Command Line Tools\n * installed to run. Such a tool reports absent.\n */\n isStub?(path: string): boolean;\n /**\n * The account's home folder, absolute, that a `~/` program is in: the user database's, never\n * `HOME`. Without it one is absent.\n */\n readonly home?: string;\n}\n\n/**\n * Where a declared program runs from, pinned once at startup, or null when it is absent: not\n * found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on\n * `SEARCH_PATH` alone, and a `~/` path in `lookup.home` alone.\n */\nexport function resolveProgram(program: string, lookup: ProgramLookup): string | null {\n if (programProblem(program)) return null;\n let candidates: string[];\n if (program.startsWith('/')) candidates = [program];\n else if (program.startsWith('~/')) {\n if (!lookup.home?.startsWith('/')) return null;\n // Trimmed after the check, so a home of `/` is the root: `~/tool` is `/tool`.\n candidates = [lookup.home.replace(/\\/+$/, '') + program.slice(1)];\n } else candidates = SEARCH_PATH.map((dir) => `${dir}/${program}`);\n for (const candidate of candidates) {\n if (!lookup.isExecutable(candidate)) continue;\n return lookup.isStub?.(candidate) ? null : candidate;\n }\n return null;\n}\n\n/** The environment a spawned program gets: only the variables declared, of those given. */\nexport function filterEnvironment(\n env: Readonly<Record<string, string | undefined>>,\n allowed: readonly string[],\n): Record<string, string> {\n const filtered: Record<string, string> = {};\n for (const name of allowed) {\n const value = Object.hasOwn(env, name) ? env[name] : undefined;\n if (typeof value === 'string' && !value.includes('\\0')) filtered[name] = value;\n }\n return filtered;\n}\n"]}
|
package/dist/status-bar.js
CHANGED
|
@@ -145,10 +145,10 @@ export class StatusBar {
|
|
|
145
145
|
this.window.apply();
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
149
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.
|
|
148
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: StatusBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
149
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.3.0", ngImport: i0, type: StatusBar });
|
|
150
150
|
}
|
|
151
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
151
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: StatusBar, decorators: [{
|
|
152
152
|
type: Service
|
|
153
153
|
}], ctorParameters: () => [] });
|
|
154
154
|
/** The bar, as every app on one source claims it. */
|
package/dist/tray.js
CHANGED
|
@@ -71,10 +71,10 @@ export class Tray {
|
|
|
71
71
|
ngOnDestroy() {
|
|
72
72
|
this.unsubscribe?.();
|
|
73
73
|
}
|
|
74
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
75
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.
|
|
74
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Tray, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
75
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.3.0", ngImport: i0, type: Tray });
|
|
76
76
|
}
|
|
77
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
77
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Tray, decorators: [{
|
|
78
78
|
type: Service
|
|
79
79
|
}], ctorParameters: () => [] });
|
|
80
80
|
//# sourceMappingURL=tray.js.map
|
package/dist/undo-stack.js
CHANGED
|
@@ -101,10 +101,10 @@ export class UndoStack {
|
|
|
101
101
|
ngOnDestroy() {
|
|
102
102
|
this.unsubscribe?.();
|
|
103
103
|
}
|
|
104
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
105
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.
|
|
104
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: UndoStack, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
105
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.3.0", ngImport: i0, type: UndoStack });
|
|
106
106
|
}
|
|
107
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
107
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: UndoStack, decorators: [{
|
|
108
108
|
type: Service
|
|
109
109
|
}] });
|
|
110
110
|
//# sourceMappingURL=undo-stack.js.map
|
package/dist/vibration.js
CHANGED
|
@@ -37,10 +37,10 @@ export class Vibration {
|
|
|
37
37
|
stop() {
|
|
38
38
|
this.native?.cancel();
|
|
39
39
|
}
|
|
40
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
41
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.
|
|
40
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Vibration, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
41
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.3.0", ngImport: i0, type: Vibration });
|
|
42
42
|
}
|
|
43
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
43
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Vibration, decorators: [{
|
|
44
44
|
type: Service
|
|
45
45
|
}] });
|
|
46
46
|
//# sourceMappingURL=vibration.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/device",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Angular Native device services: keyboard, screen, color scheme, app state, accessibility, hardware back and deep links.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ng-native/fabric": "0.
|
|
20
|
+
"@ng-native/fabric": "0.30.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@angular/core": "^22.0.0",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"homepage": "https://ng-native.com/packages/device",
|
|
39
39
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/coralogix/ng-native/issues"
|
|
41
41
|
},
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/
|
|
44
|
+
"url": "git+https://github.com/coralogix/ng-native.git",
|
|
45
45
|
"directory": "packages/device"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"dist"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@angular/core": "22.
|
|
51
|
+
"@angular/core": "22.3.0",
|
|
52
52
|
"@babel/core": "^7.29.7"
|
|
53
53
|
},
|
|
54
54
|
"exports": {
|