@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.
- 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 +2 -0
- package/dist/color-scheme.js +2 -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
|
@@ -0,0 +1,313 @@
|
|
|
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
|
+
/**
|
|
28
|
+
* Where a bare program name is looked for, in order: the system's directories, then Homebrew's on
|
|
29
|
+
* Apple silicon and on Intel. A Finder-launched app inherits only launchd's `PATH`, so Homebrew's
|
|
30
|
+
* tools would never resolve on the inherited one.
|
|
31
|
+
*/
|
|
32
|
+
export const SEARCH_PATH = [
|
|
33
|
+
'/usr/bin',
|
|
34
|
+
'/bin',
|
|
35
|
+
'/usr/sbin',
|
|
36
|
+
'/sbin',
|
|
37
|
+
'/opt/homebrew/bin',
|
|
38
|
+
'/usr/local/bin',
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Programs refused whatever their path: shells, and programs whose job is to run their own
|
|
42
|
+
* arguments as a command (`env`, `xargs`, `sudo`, `nice`, `nohup`), which would turn an argument
|
|
43
|
+
* pattern into a command line.
|
|
44
|
+
*/
|
|
45
|
+
const REFUSED_PROGRAMS = new Set([
|
|
46
|
+
'sh',
|
|
47
|
+
'bash',
|
|
48
|
+
'zsh',
|
|
49
|
+
'dash',
|
|
50
|
+
'ksh',
|
|
51
|
+
'mksh',
|
|
52
|
+
'csh',
|
|
53
|
+
'tcsh',
|
|
54
|
+
'fish',
|
|
55
|
+
'nu',
|
|
56
|
+
'env',
|
|
57
|
+
'xargs',
|
|
58
|
+
'sudo',
|
|
59
|
+
'doas',
|
|
60
|
+
'su',
|
|
61
|
+
'osascript',
|
|
62
|
+
'cmd',
|
|
63
|
+
'powershell',
|
|
64
|
+
'pwsh',
|
|
65
|
+
'nice',
|
|
66
|
+
'nohup',
|
|
67
|
+
]);
|
|
68
|
+
/** Windows batch files, which run through `cmd.exe` and so re-parse their arguments. */
|
|
69
|
+
const REFUSED_EXTENSIONS = ['.bat', '.cmd'];
|
|
70
|
+
const PLACEHOLDER = /^\{([A-Za-z_][A-Za-z0-9_]*):([\s\S]+)\}(\.\.\.)?$/;
|
|
71
|
+
/** Why a declaration or a call was refused. */
|
|
72
|
+
export class SpawnRuleError extends Error {
|
|
73
|
+
name = 'SpawnRuleError';
|
|
74
|
+
}
|
|
75
|
+
/** The last segment of a path, either separator, lower-cased and without `.exe`. */
|
|
76
|
+
function baseName(program) {
|
|
77
|
+
const last = program.split(/[\\/]/).at(-1) ?? '';
|
|
78
|
+
return last.toLowerCase().replace(/\.exe$/, '');
|
|
79
|
+
}
|
|
80
|
+
/** Why `program` cannot be declared, or null when it can. */
|
|
81
|
+
export function programProblem(program) {
|
|
82
|
+
if (typeof program !== 'string' || program.length === 0)
|
|
83
|
+
return 'a program is required';
|
|
84
|
+
if (program.includes('\0'))
|
|
85
|
+
return 'a program cannot hold a NUL character';
|
|
86
|
+
if (program !== program.trim())
|
|
87
|
+
return 'a program cannot start or end with white space';
|
|
88
|
+
const lower = program.toLowerCase();
|
|
89
|
+
if (REFUSED_EXTENSIONS.some((extension) => lower.endsWith(extension))) {
|
|
90
|
+
return `${program} is a batch file, which runs through cmd.exe and re-parses its arguments`;
|
|
91
|
+
}
|
|
92
|
+
const name = baseName(program);
|
|
93
|
+
if (REFUSED_PROGRAMS.has(name)) {
|
|
94
|
+
return `${program} runs its arguments as a command, so it cannot be declared`;
|
|
95
|
+
}
|
|
96
|
+
if (program.startsWith('/')) {
|
|
97
|
+
const segments = program.split('/').slice(1);
|
|
98
|
+
if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
|
|
99
|
+
return `${program} is not a normalized absolute path`;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (/[\\/]/.test(program)) {
|
|
104
|
+
return `${program} is a relative path: give an absolute path or a bare name`;
|
|
105
|
+
}
|
|
106
|
+
if (program === '.' || program === '..')
|
|
107
|
+
return `${program} is not a program`;
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
/** Parse one declared argument. */
|
|
111
|
+
export function parseArgument(arg) {
|
|
112
|
+
if (typeof arg !== 'string')
|
|
113
|
+
throw new SpawnRuleError('an argument must be a string');
|
|
114
|
+
if (arg.includes('\0'))
|
|
115
|
+
throw new SpawnRuleError('an argument cannot hold a NUL character');
|
|
116
|
+
const placeholder = PLACEHOLDER.exec(arg);
|
|
117
|
+
if (!placeholder)
|
|
118
|
+
return { kind: 'literal', value: arg };
|
|
119
|
+
const [, name, source, dots] = placeholder;
|
|
120
|
+
if (hasLookbehindOrNamedGroup(source)) {
|
|
121
|
+
throw new SpawnRuleError(`{${name}} has a (?< named group or lookbehind, which the desktop's native rules cannot compile`);
|
|
122
|
+
}
|
|
123
|
+
let pattern;
|
|
124
|
+
try {
|
|
125
|
+
// On its own first: a pattern that compiles alone has balanced groups, so one such as
|
|
126
|
+
// `a)|(.*` cannot close the anchoring group early and escape it.
|
|
127
|
+
new RegExp(source);
|
|
128
|
+
// Anchored as a whole, so an alternation cannot escape it: `{x:a|b}` is `^(?:a|b)$`.
|
|
129
|
+
pattern = new RegExp(`^(?:${source})$`);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new SpawnRuleError(`{${name}} has a pattern that does not compile: ${String(error)}`);
|
|
133
|
+
}
|
|
134
|
+
const option = alternatives(source).every((one) => /^\^?\\?-/.test(one));
|
|
135
|
+
return { kind: 'placeholder', name, pattern, option, repeated: dots !== undefined };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether a pattern opens a `(?<` group (a named group or a lookbehind) outside an escape or a
|
|
139
|
+
* class. JavaScript compiles one, but the native rules' ECMAScript `std::regex` does not, and a
|
|
140
|
+
* declaration it cannot compile would be dropped there with no error.
|
|
141
|
+
*/
|
|
142
|
+
function hasLookbehindOrNamedGroup(source) {
|
|
143
|
+
let inClass = false;
|
|
144
|
+
for (let at = 0; at < source.length; at++) {
|
|
145
|
+
const char = source[at];
|
|
146
|
+
if (char === '\\')
|
|
147
|
+
at++;
|
|
148
|
+
else if (inClass)
|
|
149
|
+
inClass = char !== ']';
|
|
150
|
+
else if (char === '[')
|
|
151
|
+
inClass = true;
|
|
152
|
+
else if (source.startsWith('(?<', at))
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A pattern's top-level alternatives: `-v|.*` is `-v` and `.*`. A `|` in a group, in a class or
|
|
159
|
+
* escaped is not one. The pattern has compiled, so its groups and classes are balanced.
|
|
160
|
+
*/
|
|
161
|
+
function alternatives(source) {
|
|
162
|
+
const found = [];
|
|
163
|
+
let depth = 0;
|
|
164
|
+
let inClass = false;
|
|
165
|
+
let start = 0;
|
|
166
|
+
for (let at = 0; at < source.length; at++) {
|
|
167
|
+
const char = source[at];
|
|
168
|
+
if (char === '\\')
|
|
169
|
+
at++;
|
|
170
|
+
else if (inClass)
|
|
171
|
+
inClass = char !== ']';
|
|
172
|
+
else if (char === '[')
|
|
173
|
+
inClass = true;
|
|
174
|
+
else if (char === '(')
|
|
175
|
+
depth++;
|
|
176
|
+
else if (char === ')')
|
|
177
|
+
depth--;
|
|
178
|
+
else if (char === '|' && depth === 0) {
|
|
179
|
+
found.push(source.slice(start, at));
|
|
180
|
+
start = at + 1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
found.push(source.slice(start));
|
|
184
|
+
return found;
|
|
185
|
+
}
|
|
186
|
+
/** Check and parse one declared capability. Throws `SpawnRuleError` on a bad declaration. */
|
|
187
|
+
export function compileCapability(capability) {
|
|
188
|
+
const problem = programProblem(capability?.program);
|
|
189
|
+
if (problem)
|
|
190
|
+
throw new SpawnRuleError(problem);
|
|
191
|
+
if (capability.args !== undefined && !Array.isArray(capability.args)) {
|
|
192
|
+
throw new SpawnRuleError(`${capability.program}: args must be a list`);
|
|
193
|
+
}
|
|
194
|
+
const args = (capability.args ?? []).map(parseArgument);
|
|
195
|
+
const names = new Set();
|
|
196
|
+
let repeated = 0;
|
|
197
|
+
for (const rule of args) {
|
|
198
|
+
if (rule.kind !== 'placeholder')
|
|
199
|
+
continue;
|
|
200
|
+
if (names.has(rule.name)) {
|
|
201
|
+
throw new SpawnRuleError(`${capability.program}: {${rule.name}} is declared twice`);
|
|
202
|
+
}
|
|
203
|
+
names.add(rule.name);
|
|
204
|
+
if (rule.repeated)
|
|
205
|
+
repeated++;
|
|
206
|
+
}
|
|
207
|
+
// Two repeated placeholders could share the arguments between them in more than one way.
|
|
208
|
+
if (repeated > 1) {
|
|
209
|
+
throw new SpawnRuleError(`${capability.program}: at most one placeholder may repeat`);
|
|
210
|
+
}
|
|
211
|
+
return { program: capability.program, args };
|
|
212
|
+
}
|
|
213
|
+
/** Whether one argument passes a placeholder. */
|
|
214
|
+
function passes(rule, arg) {
|
|
215
|
+
if (arg.startsWith('-') && !rule.option)
|
|
216
|
+
return false;
|
|
217
|
+
return rule.pattern.test(arg);
|
|
218
|
+
}
|
|
219
|
+
/** Whether one argument passes a rule. */
|
|
220
|
+
function fits(rule, arg) {
|
|
221
|
+
return rule.kind === 'literal' ? rule.value === arg : passes(rule, arg);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Whether `args` fit a capability's argument rules, and the values its placeholders took; null
|
|
225
|
+
* when they do not. The rules before a repeated placeholder take the first arguments, those after
|
|
226
|
+
* it the last, and it takes what is left between, each by its own pattern.
|
|
227
|
+
*/
|
|
228
|
+
export function matchArguments(rules, args) {
|
|
229
|
+
if (args.some((arg) => typeof arg !== 'string' || arg.includes('\0')))
|
|
230
|
+
return null;
|
|
231
|
+
const at = rules.findIndex((rule) => rule.kind === 'placeholder' && rule.repeated);
|
|
232
|
+
const head = at === -1 ? rules : rules.slice(0, at);
|
|
233
|
+
const tail = at === -1 ? [] : rules.slice(at + 1);
|
|
234
|
+
if (at === -1 ? args.length !== rules.length : args.length < head.length + tail.length) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const values = {};
|
|
238
|
+
const take = (rule, arg) => {
|
|
239
|
+
if (!fits(rule, arg))
|
|
240
|
+
return false;
|
|
241
|
+
if (rule.kind === 'placeholder')
|
|
242
|
+
values[rule.name] = arg;
|
|
243
|
+
return true;
|
|
244
|
+
};
|
|
245
|
+
for (let index = 0; index < head.length; index++) {
|
|
246
|
+
if (!take(head[index], args[index]))
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
const tailStart = args.length - tail.length;
|
|
250
|
+
for (let index = 0; index < tail.length; index++) {
|
|
251
|
+
if (!take(tail[index], args[tailStart + index]))
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
if (at !== -1) {
|
|
255
|
+
const rule = rules[at];
|
|
256
|
+
const middle = args.slice(head.length, tailStart);
|
|
257
|
+
if (!middle.every((arg) => passes(rule, arg)))
|
|
258
|
+
return null;
|
|
259
|
+
values[rule.name] = middle;
|
|
260
|
+
}
|
|
261
|
+
return values;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* The capability that allows running `program` with `args`, or null when none does. `program` is
|
|
265
|
+
* the declared path or name exactly: a bare name is never looked up on any `PATH` here, and only
|
|
266
|
+
* runs where `resolved` pinned it.
|
|
267
|
+
*
|
|
268
|
+
* @param resolved where each declared bare name was pinned at startup, by `resolveProgram`
|
|
269
|
+
*/
|
|
270
|
+
export function matchSpawn(capabilities, program, args, resolved = {}) {
|
|
271
|
+
for (const capability of capabilities) {
|
|
272
|
+
const pinned = capability.program.startsWith('/')
|
|
273
|
+
? capability.program
|
|
274
|
+
: (resolved[capability.program] ?? null);
|
|
275
|
+
if (pinned === null)
|
|
276
|
+
continue;
|
|
277
|
+
if (program !== capability.program && program !== pinned)
|
|
278
|
+
continue;
|
|
279
|
+
const values = matchArguments(capability.args, args);
|
|
280
|
+
if (values)
|
|
281
|
+
return { capability, path: pinned, values };
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Where a declared program runs from, pinned once at startup, or null when it is absent: not
|
|
287
|
+
* found, or an `xcrun` stub without the Command Line Tools. A bare name is looked for on
|
|
288
|
+
* `SEARCH_PATH` alone.
|
|
289
|
+
*/
|
|
290
|
+
export function resolveProgram(program, lookup) {
|
|
291
|
+
if (programProblem(program))
|
|
292
|
+
return null;
|
|
293
|
+
const candidates = program.startsWith('/')
|
|
294
|
+
? [program]
|
|
295
|
+
: SEARCH_PATH.map((dir) => `${dir}/${program}`);
|
|
296
|
+
for (const candidate of candidates) {
|
|
297
|
+
if (!lookup.isExecutable(candidate))
|
|
298
|
+
continue;
|
|
299
|
+
return lookup.isStub?.(candidate) ? null : candidate;
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
/** The environment a spawned program gets: only the variables declared, of those given. */
|
|
304
|
+
export function filterEnvironment(env, allowed) {
|
|
305
|
+
const filtered = {};
|
|
306
|
+
for (const name of allowed) {
|
|
307
|
+
const value = Object.hasOwn(env, name) ? env[name] : undefined;
|
|
308
|
+
if (typeof value === 'string' && !value.includes('\0'))
|
|
309
|
+
filtered[name] = value;
|
|
310
|
+
}
|
|
311
|
+
return filtered;
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=spawn-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-rules.js","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AC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,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]);\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"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the iOS host draws `<split-view>` itself, as a UISplitViewController: on an iPad, with
|
|
3
|
+
* `@ng-native/components`' pod, whose `NgNativeSplitViews` module says so with its constant
|
|
4
|
+
* `available`. False on an iPhone, in Expo Go, and wherever React Native is not. Asked as an
|
|
5
|
+
* element is named, so the module is looked up each time and its constant read once.
|
|
6
|
+
*/
|
|
7
|
+
export declare function nativeSplitViews(): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { reactNative } from "./react-native.js";
|
|
2
|
+
/** The module's answer, asked once of each module: it is fixed for the app's life. */
|
|
3
|
+
const answers = new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Whether the iOS host draws `<split-view>` itself, as a UISplitViewController: on an iPad, with
|
|
6
|
+
* `@ng-native/components`' pod, whose `NgNativeSplitViews` module says so with its constant
|
|
7
|
+
* `available`. False on an iPhone, in Expo Go, and wherever React Native is not. Asked as an
|
|
8
|
+
* element is named, so the module is looked up each time and its constant read once.
|
|
9
|
+
*/
|
|
10
|
+
export function nativeSplitViews() {
|
|
11
|
+
const module = reactNative()?.TurboModuleRegistry?.get?.('NgNativeSplitViews');
|
|
12
|
+
if (!module)
|
|
13
|
+
return false;
|
|
14
|
+
let answer = answers.get(module);
|
|
15
|
+
if (answer === undefined) {
|
|
16
|
+
answer = module.getConstants?.().available === true;
|
|
17
|
+
answers.set(module, answer);
|
|
18
|
+
}
|
|
19
|
+
return answer;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=split-views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-views.js","sourceRoot":"","sources":["../src/split-views.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD,sFAAsF;AACtF,MAAM,OAAO,GAAG,IAAI,OAAO,EAAmB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAG,WAAW,EAAE,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,oBAAoB,CACxC,CAAC;IACtC,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { reactNative } from './react-native.ts';\n\ninterface SplitViewsModule {\n getConstants?(): { available?: boolean };\n}\n\n/** The module's answer, asked once of each module: it is fixed for the app's life. */\nconst answers = new WeakMap<object, boolean>();\n\n/**\n * Whether the iOS host draws `<split-view>` itself, as a UISplitViewController: on an iPad, with\n * `@ng-native/components`' pod, whose `NgNativeSplitViews` module says so with its constant\n * `available`. False on an iPhone, in Expo Go, and wherever React Native is not. Asked as an\n * element is named, so the module is looked up each time and its constant read once.\n */\nexport function nativeSplitViews(): boolean {\n const module = reactNative()?.TurboModuleRegistry?.get?.('NgNativeSplitViews') as\n SplitViewsModule | null | undefined;\n if (!module) return false;\n let answer = answers.get(module);\n if (answer === undefined) {\n answer = module.getConstants?.().available === true;\n answers.set(module, answer);\n }\n return answer;\n}\n"]}
|
package/dist/status-bar.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The status bar: what colour its text is, whether it is there at all, and how tall it is.
|
|
3
|
-
*
|
|
4
|
-
* React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,
|
|
5
|
-
* and does it through a stack of entries so that a screen pushed on top can change the bar and
|
|
6
|
-
* the screen underneath gets its own back when that one leaves. None of the rendering survives
|
|
7
|
-
* without React - but the statics underneath do, and the stack is exactly what a navigation-driven
|
|
8
|
-
* app needs, so it is the part worth keeping.
|
|
9
|
-
*
|
|
10
|
-
* `expo-status-bar` is the same statics with a React component around them, so nothing here needs
|
|
11
|
-
* that package installed.
|
|
12
|
-
*/
|
|
13
1
|
import { InjectionToken, type Signal } from '@angular/core';
|
|
14
2
|
import * as i0 from "@angular/core";
|
|
15
3
|
/**
|
|
@@ -70,6 +58,8 @@ export declare class StatusBar {
|
|
|
70
58
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
71
59
|
static readonly SOURCE: InjectionToken<StatusBarSource>;
|
|
72
60
|
private readonly source;
|
|
61
|
+
/** Whether there is a status bar: on iOS and Android, and not on a Mac or the web. */
|
|
62
|
+
readonly available: Signal<boolean>;
|
|
73
63
|
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
74
64
|
private readonly owner;
|
|
75
65
|
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
package/dist/status-bar.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* `expo-status-bar` is the same statics with a React component around them, so nothing here needs
|
|
11
11
|
* that package installed.
|
|
12
12
|
*/
|
|
13
|
+
import { injectOs, isPhoneOs } from "./os.js";
|
|
13
14
|
import { DestroyRef, InjectionToken, Service, computed, inject, signal, untracked, } from '@angular/core';
|
|
14
15
|
import { ColorScheme } from "./color-scheme.js";
|
|
15
16
|
import { mergeClaims } from "./merge-claims.js";
|
|
@@ -93,6 +94,8 @@ export class StatusBar {
|
|
|
93
94
|
factory: statusBarSource,
|
|
94
95
|
});
|
|
95
96
|
source = inject(StatusBar.SOURCE);
|
|
97
|
+
/** Whether there is a status bar: on iOS and Android, and not on a Mac or the web. */
|
|
98
|
+
available = signal(isPhoneOs(injectOs())).asReadonly();
|
|
96
99
|
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
97
100
|
owner = { scheme: inject(ColorScheme) };
|
|
98
101
|
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
package/dist/status-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmDjF,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,IAAI,GAAoB;IAC5B,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,MAAM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AyD;IACjD,UAAU;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,KAAK,CAAC;IACvE,CAAC;IAED,8FAA8F;IACtF,OAAO,CAAC,QAA4C,EAAE,KAAc;QAC1E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { edgeToEdgeFlag, reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n /**\n * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nconst NONE: StatusBarSource = {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n};\n\n/** One per React Native, so every app the runtime mounts claims the same bar. */\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n // A copy: with no bar to share, each app claims its own.\n if (!native) return { ...NONE };\n return sharedBySource(statusBarSource, native, () => nativeSource(native));\n}\n\nfunction nativeSource(native: NonNullable<ReturnType<typeof reactNative>>): StatusBarSource {\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n // React Native 0.88 draws every Android app edge-to-edge, and removed both setters with it.\n const settable = typeof StatusBar.setBackgroundColor === 'function';\n const edgeToEdge =\n android && (!settable || Number(native.Platform.Version) >= 36 || edgeToEdgeFlag(native));\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor?.(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent?.(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n onWindowFront,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\n );\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(\n StatusBarWindow,\n this.source,\n () => new StatusBarWindow(this.source),\n );\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = this.window.state;\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && this.window.resolve(style), hidden };\n });\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass StatusBarWindow {\n readonly claims = new WindowClaims<StatusBarState, Owner>();\n readonly state: Signal<StatusBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n private readonly source: StatusBarSource;\n\n constructor(source: StatusBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */\n resolve(style: StatusBarStyle, scheme?: Scheme): PlatformStatusBarStyle {\n return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');\n }\n\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const { style, animated } = untracked(this.state);\n if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner) return;\n this.source.setStyle(this.resolve(style, scheme), animated);\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part. A property\n * the last claim to name it has dropped goes back to the platform's own, once. Not the\n * background color, whose own the theme decides. Read untracked, so an effect that sets the bar\n * does not also subscribe to it and run again on every later claim. A window come to the front\n * is given what is claimed, with nothing animated and nothing put back.\n */\n apply(front = false): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n const animate = front ? undefined : animated;\n if (this.changes('style', style)) {\n this.source.setStyle(\n untracked(() => this.resolve(style ?? 'default')),\n animate,\n );\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animate);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** The app whose claim the style in force comes from. */\n private styleOwner(): Owner | undefined {\n return this.claims.last((state) => state.style !== undefined)?.owner;\n }\n\n /** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */\n private changes(property: 'style' | 'hidden' | 'translucent', value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmDjF,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,IAAI,GAAoB;IAC5B,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,MAAM,EAAE,SAAS;CA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AI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,yDAAyD;IACjD,UAAU;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,KAAK,CAAC;IACvE,CAAC;IAED,8FAA8F;IACtF,OAAO,CAAC,QAA4C,EAAE,KAAc;QAC1E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport { injectOs, isPhoneOs } from './os.ts';\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { edgeToEdgeFlag, reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n /**\n * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nconst NONE: StatusBarSource = {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n};\n\n/** One per React Native, so every app the runtime mounts claims the same bar. */\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n // A copy: with no bar to share, each app claims its own.\n if (!native) return { ...NONE };\n return sharedBySource(statusBarSource, native, () => nativeSource(native));\n}\n\nfunction nativeSource(native: NonNullable<ReturnType<typeof reactNative>>): StatusBarSource {\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n // React Native 0.88 draws every Android app edge-to-edge, and removed both setters with it.\n const settable = typeof StatusBar.setBackgroundColor === 'function';\n const edgeToEdge =\n android && (!settable || Number(native.Platform.Version) >= 36 || edgeToEdgeFlag(native));\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor?.(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent?.(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n onWindowFront,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\n );\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n\n /** Whether there is a status bar: on iOS and Android, and not on a Mac or the web. */\n readonly available: Signal<boolean> = signal(isPhoneOs(injectOs())).asReadonly();\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(\n StatusBarWindow,\n this.source,\n () => new StatusBarWindow(this.source),\n );\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = this.window.state;\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && this.window.resolve(style), hidden };\n });\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass StatusBarWindow {\n readonly claims = new WindowClaims<StatusBarState, Owner>();\n readonly state: Signal<StatusBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n private readonly source: StatusBarSource;\n\n constructor(source: StatusBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */\n resolve(style: StatusBarStyle, scheme?: Scheme): PlatformStatusBarStyle {\n return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');\n }\n\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const { style, animated } = untracked(this.state);\n if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner) return;\n this.source.setStyle(this.resolve(style, scheme), animated);\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part. A property\n * the last claim to name it has dropped goes back to the platform's own, once. Not the\n * background color, whose own the theme decides. Read untracked, so an effect that sets the bar\n * does not also subscribe to it and run again on every later claim. A window come to the front\n * is given what is claimed, with nothing animated and nothing put back.\n */\n apply(front = false): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n const animate = front ? undefined : animated;\n if (this.changes('style', style)) {\n this.source.setStyle(\n untracked(() => this.resolve(style ?? 'default')),\n animate,\n );\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animate);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** The app whose claim the style in force comes from. */\n private styleOwner(): Owner | undefined {\n return this.claims.last((state) => state.style !== undefined)?.owner;\n }\n\n /** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */\n private changes(property: 'style' | 'hidden' | 'translucent', value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
package/dist/tray.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icons in the macOS menu bar's status area, each with a menu or a press of its own. `<tray-icon>`
|
|
3
|
+
* in `@ng-native/components` registers here. Absent on iOS and Android, where nothing is drawn.
|
|
4
|
+
*
|
|
5
|
+
* The host contract, on the `NgNativeTray` module: `setIcons(icons)` takes every icon each time one
|
|
6
|
+
* changes, as `{ id, title, sfSymbol, image, tooltip, menu }`, `menu` as `serializeMenu` makes it
|
|
7
|
+
* (null for an icon with a press instead). It sends `{ type: 'press', icon }` and
|
|
8
|
+
* `{ type: 'menuSelect', icon, id }` on `ngNativeTray`.
|
|
9
|
+
*/
|
|
10
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
11
|
+
import type { MenuEntry } from './menu-model.ts';
|
|
12
|
+
import { type NativeMenuEntry } from './menus.ts';
|
|
13
|
+
import * as i0 from "@angular/core";
|
|
14
|
+
/** One icon as an app describes it. */
|
|
15
|
+
export interface TrayIconModel {
|
|
16
|
+
readonly title?: string;
|
|
17
|
+
/** An SF Symbol, drawn as a template image that follows the menu bar's appearance. */
|
|
18
|
+
readonly sfSymbol?: string;
|
|
19
|
+
/** An image asset's name, for an icon of the app's own. */
|
|
20
|
+
readonly image?: string;
|
|
21
|
+
readonly tooltip?: string;
|
|
22
|
+
/** The menu a click opens; with none, a click is a press. */
|
|
23
|
+
readonly menu: readonly MenuEntry[];
|
|
24
|
+
readonly press: () => void;
|
|
25
|
+
}
|
|
26
|
+
export interface NativeTrayIcon {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly title?: string;
|
|
29
|
+
readonly sfSymbol?: string;
|
|
30
|
+
readonly image?: string;
|
|
31
|
+
readonly tooltip?: string;
|
|
32
|
+
readonly menu: readonly NativeMenuEntry[] | null;
|
|
33
|
+
}
|
|
34
|
+
export type NativeTrayEvent = {
|
|
35
|
+
readonly type: 'press';
|
|
36
|
+
readonly icon: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: 'menuSelect';
|
|
39
|
+
readonly icon: string;
|
|
40
|
+
readonly id: string;
|
|
41
|
+
};
|
|
42
|
+
export interface NativeTray {
|
|
43
|
+
setIcons(icons: readonly NativeTrayIcon[]): void;
|
|
44
|
+
subscribe(listener: (event: NativeTrayEvent) => void): () => void;
|
|
45
|
+
}
|
|
46
|
+
export declare class Tray {
|
|
47
|
+
/** Overridden in a test with a fake host. */
|
|
48
|
+
static readonly SOURCE: InjectionToken<NativeTray | null>;
|
|
49
|
+
private readonly native;
|
|
50
|
+
private readonly icons;
|
|
51
|
+
private next;
|
|
52
|
+
/** Whether the OS has a status area for the app: macOS. */
|
|
53
|
+
readonly available: Signal<boolean>;
|
|
54
|
+
private readonly sent;
|
|
55
|
+
private readonly unsubscribe;
|
|
56
|
+
constructor();
|
|
57
|
+
/** Show an icon for as long as the function answered is not called. */
|
|
58
|
+
add(model: Signal<TrayIconModel>): () => void;
|
|
59
|
+
private hostSaid;
|
|
60
|
+
ngOnDestroy(): void;
|
|
61
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Tray, never>;
|
|
62
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
63
|
+
}
|