@vestra-player/sdk 1.6.19 → 1.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/commands.js +19 -18
  3. package/dist/docs-tree.json.gz +0 -0
  4. package/dist/i18n-tools.js +7 -2
  5. package/dist/plugin/runtime.d.ts +1 -0
  6. package/dist/plugin/runtime.js +3 -0
  7. package/dist/plugin/types/base.d.ts +1097 -0
  8. package/dist/plugin/types/base.js +1 -0
  9. package/dist/plugin/types/commands.d.ts +1189 -0
  10. package/dist/plugin/types/commands.js +1 -0
  11. package/dist/plugin/types/packages.d.ts +661 -0
  12. package/dist/plugin/types/packages.js +1 -0
  13. package/dist/plugin/types/playback.d.ts +1654 -0
  14. package/dist/plugin/types/playback.js +1 -0
  15. package/dist/plugin/types/processing.d.ts +974 -0
  16. package/dist/plugin/types/processing.js +1 -0
  17. package/dist/plugin/types/services.d.ts +1132 -0
  18. package/dist/plugin/types/services.js +1 -0
  19. package/dist/plugin/types/snapshots.d.ts +491 -0
  20. package/dist/plugin/types/snapshots.js +1 -0
  21. package/dist/plugin/types/sources.d.ts +302 -0
  22. package/dist/plugin/types/sources.js +1 -0
  23. package/dist/plugin/types/subtitles.d.ts +327 -0
  24. package/dist/plugin/types/subtitles.js +1 -0
  25. package/dist/plugin/types/ui-content.d.ts +692 -0
  26. package/dist/plugin/types/ui-content.js +1 -0
  27. package/dist/plugin/types/ui-layout.d.ts +1079 -0
  28. package/dist/plugin/types/ui-layout.js +1 -0
  29. package/dist/plugin/types/ui-locale.d.ts +490 -0
  30. package/dist/plugin/types/ui-locale.js +1 -0
  31. package/dist/plugin/types/ui-shell.d.ts +1072 -0
  32. package/dist/plugin/types/ui-shell.js +1 -0
  33. package/dist/plugin/types.d.ts +18 -11072
  34. package/llms.txt +1 -1
  35. package/package.json +1 -1
@@ -0,0 +1,1189 @@
1
+ import type { Scope } from "./base.ts";
2
+ import type { Player } from "./playback.ts";
3
+ import type { Ui, View } from "./ui-content.ts";
4
+ import type { Disposable } from "./base.ts";
5
+ import type { PlayerState } from "./playback.ts";
6
+ import type { ImageRef } from "./ui-content.ts";
7
+ import type { LanguagePreference, Text, TextValue, ThemeId } from "./ui-locale.ts";
8
+ /**
9
+ * The state of a command's menu item, as the player shows it.
10
+ *
11
+ * @see {@link Command.set}, {@link CommandOptions}
12
+ * @since 1.0.0
13
+ * @category Commands
14
+ */
15
+ export interface CommandState {
16
+ /** False greys the item out; the player then never calls `run` (bound keys are swallowed). Default true. */
17
+ enabled: boolean;
18
+ /** `null` means the menu item has no check mark. */
19
+ checked: boolean | null;
20
+ /** Shown as busy; like `enabled: false`, the player does not call `run`. Default false. */
21
+ busy: boolean;
22
+ /**
23
+ * Shown when the command is disabled or busy: English source text the
24
+ * player translates, or a {@link Text} (SDK 1.5.11).
25
+ */
26
+ reason: TextValue | null;
27
+ }
28
+ /**
29
+ * A value, or a function the SDK re-evaluates on every full update pass,
30
+ * and after a player state change only if it read a field of
31
+ * `plugin.player.state` that changed (see {@link Scope.update}); only
32
+ * changes are sent to the player.
33
+ *
34
+ * @example Mix a computed state with a fixed one
35
+ * The Loop item carries a check mark while a loop is set and is always
36
+ * enabled. A function is evaluated again in every full update pass (after
37
+ * each handler), and after a player state change only if it read a changed
38
+ * field; only changes are sent, and a plain value never changes.
39
+ * ```ts
40
+ * plugin.commands.add({
41
+ * id: "loop",
42
+ * path: ["Playback", "Loop"],
43
+ * checked: () => plugin.player.state.loop != null, // re-evaluated
44
+ * enabled: true, // a fixed value
45
+ * run: () => plugin.player.setLoop(null),
46
+ * });
47
+ * ```
48
+ *
49
+ * @since 1.0.0
50
+ * @category Commands
51
+ */
52
+ export type Bindable<T> = T | (() => T);
53
+ /**
54
+ * A condition on the player's own state, from {@link Scope.when}, for a
55
+ * command's `enabled` or `checked`. The player evaluates it, again on
56
+ * every change of that state, whether or not the plugin runs.
57
+ *
58
+ * @remarks
59
+ * Combine conditions with `and`, `or` and `not`; each returns a new
60
+ * condition and leaves the original as it was. A condition is data: it
61
+ * reads nothing in the plugin and keeps no listener, so a plugin whose
62
+ * menu state is made of conditions may be stopped while idle (lazy
63
+ * activation) and its menu stays current. A function (see {@link Bindable})
64
+ * keeps working; one that reads `plugin.player.state` or another service's
65
+ * state keeps the plugin running so the SDK can evaluate it.
66
+ *
67
+ * @capability commands
68
+ *
69
+ * @example Enable an item while a frame can be saved
70
+ * "Save Snapshot" is greyed out with its reason unless a media file is
71
+ * open at a frame the player can capture. The condition is sent with the
72
+ * command and evaluated by the player, so the item follows playback even
73
+ * while the plugin is stopped; with an `enabled` condition the player
74
+ * shows the `reason` only while the item is disabled.
75
+ * ```ts
76
+ * declare function saveSnapshot(): Promise<void>;
77
+ * // ---cut---
78
+ * const { when } = plugin;
79
+ * plugin.commands.add({
80
+ * id: "save",
81
+ * path: ["@video", "Save Snapshot"],
82
+ * enabled: when.can("snapshot").and(when.phase("ready", "ended"), when.stream.not()),
83
+ * reason: "No frame to capture", // shown only while disabled
84
+ * run: saveSnapshot,
85
+ * });
86
+ * ```
87
+ *
88
+ * @since 1.5.40
89
+ * @category Commands
90
+ */
91
+ export interface Condition {
92
+ /**
93
+ * True when this condition and every one of `others` hold.
94
+ *
95
+ * @example Combine two conditions with and
96
+ * The item is enabled only while a file plays in fullscreen. `and`
97
+ * returns a new condition; `when.playing` itself is unchanged.
98
+ * ```ts
99
+ * const { when } = plugin;
100
+ * const playingFullscreen = when.playing.and(when.fullscreen);
101
+ * ```
102
+ *
103
+ * @capability None (the command it is given to needs `commands`).
104
+ * @since 1.5.40
105
+ */
106
+ and(...others: Condition[]): Condition;
107
+ /**
108
+ * True when this condition or one of `others` holds.
109
+ *
110
+ * @example Combine two conditions with or
111
+ * The item is enabled while a file plays or is paused. `or` returns a
112
+ * new condition that holds when either of the two holds.
113
+ * ```ts
114
+ * const { when } = plugin;
115
+ * const active = when.playing.or(when.paused);
116
+ * ```
117
+ *
118
+ * @capability None (the command it is given to needs `commands`).
119
+ * @since 1.5.40
120
+ */
121
+ or(...others: Condition[]): Condition;
122
+ /**
123
+ * True when this condition does not hold.
124
+ *
125
+ * @example Negate a condition with not
126
+ * An "Enter Fullscreen" item is enabled only outside fullscreen. `not`
127
+ * returns the opposite condition; the player evaluates it on every
128
+ * window change.
129
+ * ```ts
130
+ * const { when } = plugin;
131
+ * const windowed = when.fullscreen.not();
132
+ * ```
133
+ *
134
+ * @capability None (the command it is given to needs `commands`).
135
+ * @since 1.5.40
136
+ */
137
+ not(): Condition;
138
+ }
139
+ /**
140
+ * `plugin.when`: the vocabulary of conditions (SDK 1.5.40, player 0.5.21).
141
+ * It names only state the player owns: the source's phase, kind, pause
142
+ * and controls (the same names as {@link PlayerState}), fullscreen, the
143
+ * palette and the saved interface language.
144
+ *
145
+ * @remarks
146
+ * Give a condition as a command's `enabled` or `checked`
147
+ * ({@link CommandOptions}, {@link Command.set}). The player evaluates it
148
+ * and shows the result in menus, on keys and on bar buttons, again
149
+ * whenever that state changes, also while the plugin is stopped because
150
+ * nothing used it. With an `enabled` condition the player shows the
151
+ * command's `reason` only while the condition is false (or the command
152
+ * is busy), so a fixed reason is enough. Players before 0.5.21 have no
153
+ * `plugin.when` (declare `"minPlayerVersion": "0.5.21"`).
154
+ *
155
+ * State the vocabulary does not name (a plugin's own settings, an open
156
+ * window, a track list) stays a function or a value set with
157
+ * {@link Command.set}.
158
+ *
159
+ * @capability commands
160
+ *
161
+ * @example Check a palette item and follow the palette
162
+ * The Appearance submenu has one radio item per palette; the player
163
+ * checks the one in use, also after another plugin or the user changed
164
+ * it, and while this plugin is stopped. Nothing in the plugin listens to
165
+ * the palette.
166
+ * ```ts
167
+ * const { when } = plugin;
168
+ * for (const [id, title] of [["vestra", "Dark"], ["vestra-light", "Light"]] as const)
169
+ * plugin.commands.add({
170
+ * id: `theme.${id}`,
171
+ * path: ["Settings", "Appearance", title],
172
+ * radio: true,
173
+ * checked: when.theme(id), // evaluated by the player, not the plugin
174
+ * run: () => plugin.appearance.set(id),
175
+ * });
176
+ * ```
177
+ *
178
+ * @since 1.5.40
179
+ * @category Commands
180
+ */
181
+ export interface When {
182
+ /** A source is open: any phase but `empty` (loading, ready, ended, error). */
183
+ readonly open: Condition;
184
+ /** The source is loaded and can play (`phase` is `ready`). */
185
+ readonly ready: Condition;
186
+ /** The source is ready and not paused. */
187
+ readonly playing: Condition;
188
+ /** The source is ready and paused. */
189
+ readonly paused: Condition;
190
+ /** The source is a generated stream (`PlayerState.kind` is `stream`). */
191
+ readonly stream: Condition;
192
+ /** The main window is fullscreen. */
193
+ readonly fullscreen: Condition;
194
+ /**
195
+ * The source's `phase` is one of `phases`.
196
+ *
197
+ * @throws `TypeError` (throws) No phase, or one that is not a phase.
198
+ *
199
+ * @example Enable an item while a file is loaded or finished
200
+ * The item is enabled while the source is ready or has ended, as a
201
+ * snapshot needs a frame. The phases are those of `PlayerState.phase`.
202
+ * ```ts
203
+ * const { when } = plugin;
204
+ * const hasFrame = when.phase("ready", "ended");
205
+ * ```
206
+ *
207
+ * @capability None (the command it is given to needs `commands`).
208
+ * @since 1.5.40
209
+ */
210
+ phase(...phases: PlayerState["phase"][]): Condition;
211
+ /**
212
+ * The source allows `control`: `PlayerState.can[control]` is true.
213
+ *
214
+ * @throws `TypeError` (throws) `control` is not one of `PlayerState.can`.
215
+ *
216
+ * @example Enable a seek item only where seeking works
217
+ * "Jump to Middle" is greyed out on live streams that cannot seek.
218
+ * The player reads its own `can.seek` for the current source.
219
+ * ```ts
220
+ * const { when } = plugin;
221
+ * const seekable = when.can("seek");
222
+ * ```
223
+ *
224
+ * @capability None (the command it is given to needs `commands`).
225
+ * @since 1.5.40
226
+ */
227
+ can(control: keyof PlayerState["can"]): Condition;
228
+ /**
229
+ * The palette in use is `theme` (`plugin.appearance.theme`).
230
+ *
231
+ * @throws `TypeError` (throws) `theme` is not a palette of the player.
232
+ *
233
+ * @example Check the light palette's item
234
+ * The item carries a check mark while the light palette is in use,
235
+ * whoever switched to it.
236
+ * ```ts
237
+ * const { when } = plugin;
238
+ * const light = when.theme("vestra-light");
239
+ * ```
240
+ *
241
+ * @capability None (the command it is given to needs `commands`).
242
+ * @since 1.5.40
243
+ */
244
+ theme(theme: ThemeId): Condition;
245
+ /**
246
+ * The saved interface language is `language`
247
+ * (`plugin.appearance.language`: `"system"` or a locale).
248
+ *
249
+ * @throws `TypeError` (throws) `language` is not `"system"` or a locale.
250
+ *
251
+ * @example Check the Follow System item
252
+ * The item carries a check mark while the player follows the system's
253
+ * language; the player reads its own saved preference.
254
+ * ```ts
255
+ * const { when } = plugin;
256
+ * const followSystem = when.language("system");
257
+ * ```
258
+ *
259
+ * @capability None (the command it is given to needs `commands`).
260
+ * @since 1.5.40
261
+ */
262
+ language(language: LanguagePreference): Condition;
263
+ }
264
+ /**
265
+ * A built-in top-level menu of the player, named in a command path as
266
+ * `@<id>` or by its English key (see {@link CommandOptions.path}): Open,
267
+ * Playback, Subtitles, Video, Audio, Screen, Settings, Reset. The list is
268
+ * `MENU_IDS` in `@vestra-player/sdk/testing`. Reset (`@reset`, SDK 1.5.51,
269
+ * player 0.6.3) gathers every command that puts something back to its
270
+ * default; older players refuse `@reset` with `invalid`.
271
+ *
272
+ * @since 1.3.0
273
+ * @category Commands
274
+ */
275
+ export type MenuId = "open" | "playback" | "subtitles" | "video" | "audio" | "screen" | "settings" | "reset";
276
+ /**
277
+ * An icon of the player's V-Line set (`@vestra/icons.slint`), by name: what
278
+ * a bottom-bar button may show. The list is `BAR_BUTTON_ICONS` in
279
+ * `@vestra-player/sdk/testing`.
280
+ *
281
+ * @since 1.5.29
282
+ *
283
+ * @category Commands
284
+ */
285
+ export type BarButtonIcon = "play" | "pause" | "stop" | "back" | "forward" | "open" | "volume" | "mute" | "playlist" | "detach" | "attach" | "close" | "failed" | "move-top" | "move-up" | "move-down" | "move-bottom" | "search" | "chapter" | "bookmark" | "check-task" | "check-box" | "menu-check" | "submenu" | "scroll-up" | "scroll-down" | "caret-down" | "sort-asc" | "sort-desc" | "tag-remove" | "preview-play" | "add" | "remove" | "sort" | "fullscreen" | "exit-fullscreen" | "store" | "ai";
286
+ /**
287
+ * A command's button on the bottom bar: {@link CommandOptions.button}.
288
+ *
289
+ * @remarks
290
+ * **Where it shows.** The player draws the bottom bar's button strip and
291
+ * decides where it goes: today at the right end of the bottom bar; this may
292
+ * change (older players let the bar place `BarButtons` itself). Buttons
293
+ * are ordered by `order`, then by plugin id; lower `order` comes first and
294
+ * stays visible longest. When the strip runs out of room, or more than 8
295
+ * plugin buttons are declared, the remaining buttons move to the strip's »
296
+ * menu, in the same order. A button is never dropped: it is either in the
297
+ * strip or in the » menu, and its command keeps its menu entry, its key and
298
+ * its place in the command palette. Users may pin and unpin buttons later;
299
+ * do not rely on a position. See
300
+ * [Bottom-bar buttons](../../../docs/explanation/commands.md#bottom-bar-buttons).
301
+ *
302
+ * **What it shows.** The icon, the command's title (translated, a trailing
303
+ * "…" removed) and its first key as the tooltip ("Plugin Store (F9)"),
304
+ * `enabled`, `busy` and `reason` as the menu item has them: a disabled or
305
+ * busy command's button is drawn disabled, its tooltip adds the reason, and
306
+ * a click runs nothing. Every button's icon is drawn in the accent colour;
307
+ * a command with `checked` shows a small dot under its icon while checked.
308
+ * A click runs the command exactly like a click on its menu item.
309
+ *
310
+ * **Limits.** One button per plugin, the first it declares (a later one
311
+ * stays a menu item only), and eight in the strip (`BAR_BUTTON_LIMITS`); the
312
+ * rest are in the » menu. The button goes
313
+ * with its command: disposing the command, or disabling, stopping or
314
+ * uninstalling the plugin, removes it.
315
+ *
316
+ * @example Give a command a button in the bottom bar
317
+ * A Store icon appears in the bottom bar's button strip; a click opens
318
+ * the store window, exactly like the menu item. The player draws the
319
+ * button from the command's title, keys and state, and places it by
320
+ * `order` (200 is where the player's own Plugin Store button sits).
321
+ * ```ts
322
+ * const store = plugin.windows.create("ui/store.slint");
323
+ * plugin.commands.add({
324
+ * id: "open",
325
+ * path: ["Plugin Store…"], // a button needs a menu path
326
+ * button: { icon: "store", order: 200 },
327
+ * run: () => store.show(),
328
+ * });
329
+ * ```
330
+ *
331
+ * @player 0.5.10; older players show the menu entry without a button
332
+ * (declare `"minPlayerVersion": "0.5.10"` when the button matters).
333
+ * @since 1.5.29
334
+ *
335
+ * @category Commands
336
+ */
337
+ export interface CommandButton {
338
+ /**
339
+ * A name of the player's icon set ({@link BarButtonIcon}), or an image
340
+ * made with {@link Ui.image} (a PNG or JPEG in your package or data
341
+ * directory), drawn in the 14×12 icon box, aspect kept, coloured like the
342
+ * player's line icons: only its alpha counts, so draw it as a dark shape
343
+ * on a transparent background. An unknown name fails with `invalid`.
344
+ */
345
+ icon: BarButtonIcon | ImageRef;
346
+ /**
347
+ * Place in the strip, left to right ascending: an integer 0–999. It is
348
+ * position only: a lower order sits further left, and in a narrow window
349
+ * (or past the limit of eight) it is the first to go. Equal orders sort
350
+ * by plugin id, then declaration order. The player's own buttons use AI
351
+ * 100, Plugin Store 200.
352
+ */
353
+ order: number;
354
+ }
355
+ /**
356
+ * The declaration passed to {@link Commands.add}.
357
+ *
358
+ * Menu order: siblings sort by `order` ascending; a submenu sits where its
359
+ * first command sits and takes that command's `group`. Equal orders sort by
360
+ * plugin id, then declaration order, never by title. `group` only draws
361
+ * separators, so keep a group's orders contiguous. Recommended top-level
362
+ * ranges: `open` 100–199, `domain` 200–699 (playback, subtitles, video,
363
+ * audio…), `screen` 700–799, `windows` 800–899, `exit` 900–999.
364
+ *
365
+ * Built-in menus keep their place. The built-in top-level menus
366
+ * ({@link MenuId}) sit at fixed orders, whatever is inside them: Open 110,
367
+ * Playback 200, Subtitles 300, Video 400, Audio 500, Screen 710, Settings
368
+ * 830 (player 0.3.0), Reset 840 (player 0.6.3; directly below Settings and
369
+ * in its separator group). Like every built-in menu, Reset shows only when
370
+ * a command is in it. This holds whether the path names the menu by id
371
+ * (`["@video", "Blur"]`) or by its key (`["Video", "Blur"]`), so a plugin's
372
+ * item never moves the player's menu. Directly inside a built-in menu,
373
+ * `order` 0 (the default) sorts after every other order: an item without
374
+ * `order` goes at the end, after the player's own items (which all use 100
375
+ * or more). Give a positive order to sit between them (the player's items
376
+ * in menu order are in
377
+ * [Built-in commands](../../../docs/reference/commands.md#built-in-commands)),
378
+ * or a negative one to come first. Deeper levels (a plugin's own submenu) have no such rule.
379
+ * Players before 0.3.0 place every submenu at its smallest order, so there
380
+ * an item without `order` moves the whole menu to the top; to avoid that,
381
+ * give it an order in the menu's range (Video: 400–499).
382
+ *
383
+ * {@link Commands.add} throws `invalid` synchronously for a bad path,
384
+ * order or binding; the player refuses an empty or overlong text, a control
385
+ * character or whitespace at either end (`COMMAND_LIMITS`) with
386
+ * `invalid` (through `ready`). The same path registered twice, or a path that
387
+ * is both an item and a submenu, fails with `conflict` (through `ready`).
388
+ *
389
+ * @see {@link Commands.add}, [Commands, menus and key bindings](../../../docs/explanation/commands.md)
390
+ * @since 1.0.0
391
+ * @category Commands
392
+ */
393
+ export interface CommandOptions {
394
+ /** Local id, unique within the plugin (the global id is `<manifest id>/<id>`). */
395
+ id: string;
396
+ /**
397
+ * Menu path including the leaf, 1–8 segments, e.g. `["@video", "Adjust picture…"]`;
398
+ * one segment is a top-level item. Omit it for a command that is not in the
399
+ * main menu (bindings and panel menus only); `title` is then required.
400
+ *
401
+ * Segments are English source text, and menus merge by them: commands
402
+ * of different plugins with the same leading segments share a submenu.
403
+ * The player shows each segment and the title in the interface language
404
+ * from the declaring plugin's catalog (`locales/<lang>.po`, see the
405
+ * [i18n guide](../../../docs/how-to/i18n.md)); the player's own menus
406
+ * (Open, Playback, Subtitles, Video, Audio, Screen, Settings, Reset, and
407
+ * Playback ▸ Speed, Playback ▸ Seek) always show the player's words.
408
+ * A built-in menu can also be named by its id, `@` plus a {@link MenuId}:
409
+ * `@open`, `@playback`, `@subtitles`, `@video`, `@audio`, `@screen`,
410
+ * `@settings` or `@reset` (player 0.6.3). Only the first segment is read as an id; an unknown id, or
411
+ * an id with nothing after it, fails with `invalid`. Players up to 0.4.2
412
+ * titled their menus in Chinese (视频…): there `["Video", "Blur"]` is a
413
+ * menu of its own, so plugins for those players write `@video`; player
414
+ * 0.4.3 still accepts the old Chinese titles of its own menus.
415
+ *
416
+ * A segment that mixes words with data (a track number, a count) is a
417
+ * {@link Text} (SDK 1.5.11, player 0.4.3): `plugin.i18n.text("Track {}
418
+ * ({})", [n, codec])`. The menu shows it translated and filled in; it
419
+ * merges by its English rendering ("Track 2 (opus)").
420
+ *
421
+ * @example Put items into built-in menus, one with a track number
422
+ * "Blur" appears in the Video menu and "Track 2 (opus)" under Audio ▸
423
+ * Audio Track, both in the user's language. `@video` and `@audio` name
424
+ * the built-in menus by id; "Audio Track" is a submenu key that merges
425
+ * with any other plugin's same key; the `text()` segment is translated
426
+ * with the plugin's catalog and then filled in with the number and codec.
427
+ * ```ts
428
+ * declare function toggle(): void;
429
+ * declare function select(): void;
430
+ * // ---cut---
431
+ * plugin.commands.add({ id: "blur", path: ["@video", "Blur"], run: toggle });
432
+ * const { text } = plugin.i18n;
433
+ * // A segment with data: translated as "Track {} ({})", then filled in.
434
+ * plugin.commands.add({
435
+ * id: "track-2",
436
+ * path: ["@audio", "Audio Track", text("Track {} ({})", [2, "opus"])],
437
+ * run: select,
438
+ * });
439
+ * ```
440
+ */
441
+ path?: (string | Text)[];
442
+ /**
443
+ * Menu label (English source text, shown translated, or a {@link Text});
444
+ * defaults to the last path segment.
445
+ */
446
+ title?: string | Text;
447
+ /**
448
+ * What the command is about, in a word or two (`"Subtitle Sync"`,
449
+ * `"Picture"`): English source text, shown translated like `title`, or a
450
+ * {@link Text}. The player's command palette (Ctrl+Shift+P, ⌘⇧P on macOS)
451
+ * and lists of commands name a command `Category: Title`, so a short title
452
+ * such as "Earlier 0.5 s", "Off" or "90°" still says what it changes once
453
+ * it is out of the menu. Without it the player uses the menu path above
454
+ * the item, then the plugin's name.
455
+ *
456
+ * 1–80 UTF-8 bytes (a text value counted by its English rendering), no
457
+ * control characters, no whitespace at either end
458
+ * (`COMMAND_LIMITS.categoryBytes`); the player refuses anything else with
459
+ * `invalid`. Sent only when set: players before 0.7.6 refuse the field
460
+ * with `invalid`, so declare `"minPlayerVersion": "0.7.6"` when you set
461
+ * it.
462
+ *
463
+ * @example Name commands that have no menu path
464
+ * The palette lists "Subtitle Sync: Earlier 0.5 s" and "Subtitle Sync:
465
+ * Later 0.5 s"; without a category both would read as a bare "Earlier
466
+ * 0.5 s", indistinguishable from an audio delay command of the same name.
467
+ * ```ts
468
+ * declare function shift(seconds: number): void;
469
+ * // ---cut---
470
+ * for (const [id, title, seconds] of [
471
+ * ["sync-earlier", "Earlier 0.5 s", -0.5],
472
+ * ["sync-later", "Later 0.5 s", 0.5],
473
+ * ] as const)
474
+ * plugin.commands.add({
475
+ * id,
476
+ * title,
477
+ * category: "Subtitle Sync", // the palette reads "Subtitle Sync: Earlier 0.5 s"
478
+ * bindings: [id === "sync-earlier" ? "." : ","],
479
+ * run: () => shift(seconds),
480
+ * });
481
+ * ```
482
+ *
483
+ * @player 0.7.6 (declare `"minPlayerVersion": "0.7.6"`; older players
484
+ * refuse the declaration with `invalid`).
485
+ * @since 1.6.4
486
+ */
487
+ category?: string | Text;
488
+ /**
489
+ * The id of this plugin's command that opens the window or panel where
490
+ * this command's control lives (`"tune"` for a Subtitle Tuning… command
491
+ * whose window has the sync slider). The player's command palette shows
492
+ * that place next to the command. A local id, like `id`: ASCII letters,
493
+ * digits, `.`, `_` and `-`, 1–128 bytes; the player refuses anything else
494
+ * with `invalid`. The command it names need not be registered yet; while
495
+ * it is not, the palette shows the place it would show without `home`:
496
+ * the menu path above the item, "Menu" for a top-level item, nothing for
497
+ * a command outside the menu. Sent only when set: players
498
+ * before 0.7.6 refuse the field with `invalid`, so declare
499
+ * `"minPlayerVersion": "0.7.6"` when you set it.
500
+ *
501
+ * @example Point a key command at its window
502
+ * The palette row for "Subtitle Sync: Earlier 0.5 s" also says where the
503
+ * same setting can be changed by hand: the Subtitle Tuning window that the
504
+ * `tune` command opens.
505
+ * ```ts
506
+ * declare const tuning: { show(): void };
507
+ * declare function shift(seconds: number): void;
508
+ * // ---cut---
509
+ * plugin.commands.add({
510
+ * id: "tune",
511
+ * path: ["@subtitles", "Subtitle Tuning…"],
512
+ * run: () => tuning.show(),
513
+ * });
514
+ * plugin.commands.add({
515
+ * id: "sync-earlier",
516
+ * title: "Earlier 0.5 s",
517
+ * category: "Subtitle Sync",
518
+ * home: "tune", // the palette shows "Subtitle Tuning" as its place
519
+ * run: () => shift(-0.5),
520
+ * });
521
+ * ```
522
+ *
523
+ * @player 0.7.6 (declare `"minPlayerVersion": "0.7.6"`; older players
524
+ * refuse the declaration with `invalid`).
525
+ * @since 1.6.4
526
+ */
527
+ home?: string;
528
+ /**
529
+ * Sibling order in the menu, ascending (integer, default 0). A submenu sits
530
+ * where its first command sits, except a built-in menu, which keeps its
531
+ * fixed place. Directly inside a built-in menu, 0 (the default) sorts last.
532
+ * Equal orders: plugin id, then declaration order. Range ±1,000,000. See
533
+ * {@link CommandOptions} for the menu order rules.
534
+ */
535
+ order?: number;
536
+ /** Separator label: a line is drawn between adjacent items of different groups. Default `"domain"`. */
537
+ group?: string;
538
+ /** Draw `checked` as a radio dot instead of a check mark. */
539
+ radio?: boolean;
540
+ /**
541
+ * Default input bindings, e.g. `["Space"]`, `["Ctrl+O", "F3"]`, `["Mouse:WheelUp"]`.
542
+ *
543
+ * Syntax: `{Modifier "+"} Input`, modifiers in the order `Ctrl`, `Alt`,
544
+ * `Shift`, `Cmd`, each at most once. Inputs: `A`–`Z`, `0`–`9`, `F1`–`F24`,
545
+ * `Space`, `Enter`, `Tab`, `Escape`, `Backspace`, `Delete`, `Insert`,
546
+ * `Home`, `End`, `PageUp`, `PageDown`, `ArrowLeft`/`Right`/`Up`/`Down`,
547
+ * `Plus`, any other single symbol as typed (`">"`, not `"Shift+."`),
548
+ * `Numpad0`–`Numpad9`, `NumpadPlus`, `NumpadMinus`, `NumpadMultiply`,
549
+ * `NumpadDivide`, `NumpadEnter`, `NumpadDecimal`, the video-area mouse
550
+ * inputs `Mouse:LeftClick`, `Mouse:LeftDoubleClick[:LeftHalf|:RightHalf]`,
551
+ * `Mouse:MiddleClick`, `Mouse:WheelUp`/`Down`/`Left`/`Right`, and the side
552
+ * buttons `Mouse:X1` (back), `Mouse:X2` (forward), from 0.6.0 on anywhere
553
+ * in the main window or the floating sidebar window, except while a menu
554
+ * is open.
555
+ *
556
+ * Platforms: on macOS `Ctrl+X` fires for both ⌃X and ⌘X while `Cmd+X`
557
+ * means ⌘X only; on Windows `Cmd` is the Windows logo key, so write
558
+ * `Ctrl+…` for bindings that work on both. Avoid the
559
+ * [keys the system takes first](../../../docs/reference/commands.md#keys-the-system-takes-first).
560
+ *
561
+ * Conflicts are not errors: the user's overrides win, then the player's
562
+ * own commands, then the plugin loaded first; a shadowed binding takes
563
+ * effect when the winner goes away. Up to 16 bindings.
564
+ */
565
+ bindings?: string[];
566
+ /** `"panel"`: the bindings apply only while this plugin's panel has focus. */
567
+ focus?: "panel";
568
+ /** Fire again on keyboard auto-repeat while the key is held. Default false. */
569
+ repeat?: boolean;
570
+ /**
571
+ * A button for this command on the bottom bar (SDK 1.5.29, player 0.5.10):
572
+ * an icon and a place, `{ icon: "store", order: 200 }`. Needs a `path`: the
573
+ * menu entry is where the command stays reachable wherever the button
574
+ * is (the strip or its » menu). See
575
+ * {@link CommandButton} for where it shows, what it shows and the limits.
576
+ * Fails with `invalid` for an unknown icon name, an order outside 0–999 or
577
+ * a button without a path.
578
+ */
579
+ button?: CommandButton;
580
+ /**
581
+ * Whether the command can run (default true): a value, a function, or a
582
+ * {@link Condition} the player evaluates (`plugin.when`, SDK 1.5.40).
583
+ */
584
+ enabled?: Bindable<boolean> | Condition;
585
+ /**
586
+ * Check mark (or radio dot with `radio`); `null` (default) draws none.
587
+ * A {@link Condition} (`plugin.when`, SDK 1.5.40) draws the mark while
588
+ * it holds.
589
+ */
590
+ checked?: Bindable<boolean | null> | Condition;
591
+ /** Busy state (default false); the player does not call `run` while busy. */
592
+ busy?: Bindable<boolean>;
593
+ /**
594
+ * Why the command is disabled or busy (shown to the user): English
595
+ * source text, or a {@link Text} for one with data in it (SDK 1.5.11).
596
+ * With an `enabled` {@link Condition} the player shows it only while the
597
+ * condition is false or the command is busy, so a fixed text is enough.
598
+ */
599
+ reason?: Bindable<TextValue | null>;
600
+ /**
601
+ * Run the command (menu item, binding, panel menu or
602
+ * `host.command(id).run()` in tests). It may return a promise; errors
603
+ * and rejections go to {@link Scope.onError}, and bound values are
604
+ * re-evaluated when it returns and when its promise settles.
605
+ */
606
+ run(): unknown;
607
+ }
608
+ /**
609
+ * A registered command, from {@link Commands.add}. Disposing it removes it
610
+ * from the menu and the binding table; the id can be added again right away.
611
+ *
612
+ * @remarks
613
+ * The handle of one menu item and its keys. Its state (`enabled`, `checked`,
614
+ * `busy`, `reason`) is bound: functions given to {@link Commands.add} or
615
+ * {@link Command.set} are evaluated again in every full update pass (after
616
+ * a player state change only if they read a changed field of
617
+ * `plugin.player.state`) and only changes reach the player. Its title, path, bindings and button cannot
618
+ * change in place; dispose the command (or a child {@link Scope}) and add it
619
+ * again. Disposing it, its scope or stopping the plugin removes the menu
620
+ * item, its keys and its bar button.
621
+ *
622
+ * @capability commands
623
+ *
624
+ * @example Enable an item only while a file is open
625
+ * Video ▸ Export… is greyed out until a file is open. `set` replaces the
626
+ * `enabled` field with a function; the SDK evaluates it again after every
627
+ * player state change and sends the new state when it changes, so the
628
+ * item follows the player without further code.
629
+ * ```ts
630
+ * declare function runExport(): Promise<void>;
631
+ * // ---cut---
632
+ * const exportCommand = plugin.commands.add({
633
+ * id: "export",
634
+ * path: ["@video", "Export…"],
635
+ * run: runExport,
636
+ * });
637
+ * // A function: re-evaluated in every full pass and when `phase` changes.
638
+ * exportCommand.set({ enabled: () => plugin.player.state.phase === "ready" });
639
+ * ```
640
+ *
641
+ * @see {@link Commands.add}, [Commands, menus and key bindings](../../../docs/explanation/commands.md)
642
+ * @since 1.0.0
643
+ * @category Commands
644
+ */
645
+ export interface Command extends Disposable {
646
+ /** The local id given in {@link CommandOptions.id}. */
647
+ readonly id: string;
648
+ /**
649
+ * Replace some state fields (values or functions). Last write wins.
650
+ *
651
+ * @example Show a command as busy while it works
652
+ * The Export item shows as busy with "Exporting…" as its reason while the
653
+ * export runs, then returns to normal. `set` replaces only the fields it
654
+ * names and the SDK sends the new state to the player; a busy command's
655
+ * menu item and key do not run it again until it is set back.
656
+ * ```ts
657
+ * declare function runExport(): Promise<void>;
658
+ * // ---cut---
659
+ * const exportCommand = plugin.commands.add({
660
+ * id: "export",
661
+ * path: ["@video", "Export…"],
662
+ * run: async () => {
663
+ * exportCommand.set({ busy: true, reason: "Exporting…" });
664
+ * try {
665
+ * await runExport();
666
+ * } finally {
667
+ * exportCommand.set({ busy: false, reason: null }); // also on failure
668
+ * }
669
+ * },
670
+ * });
671
+ * ```
672
+ *
673
+ * @capability commands
674
+ * @since 1.0.0
675
+ */
676
+ set(state: Partial<{
677
+ [K in "busy" | "reason"]: Bindable<CommandState[K]>;
678
+ } & {
679
+ enabled: Bindable<boolean> | Condition;
680
+ checked: Bindable<boolean | null> | Condition;
681
+ }>): void;
682
+ /**
683
+ * Resolves when the host has registered the command. Rejects with
684
+ * `conflict` (path already taken), `invalid` or `limit` (more than 160
685
+ * commands in this plugin, or 1024 in the whole player). You rarely need
686
+ * to await it: the refusal goes to {@link Scope.onError}. During
687
+ * activation the SDK, in the plugin's process, logs the refusal with the
688
+ * command id and the player's message, skips the command and lets the
689
+ * rest of the plugin activate (SDK 1.5.49; before, the refusal failed
690
+ * activation); the error reaches `onError` once activation completes,
691
+ * so a listener added anywhere in `activate` hears it. `startPlugin`
692
+ * stays strict: there a refusal during activation fails it, so tests
693
+ * show the bad declaration. Any other failure during activation
694
+ * (`capability`, no answer) fails activation.
695
+ *
696
+ * Only the player's answer is skipped. What {@link Commands.add} checks
697
+ * itself still throws from `add` (an unknown `@` menu id, more than 8
698
+ * path segments, an `order` out of range, a malformed binding or one
699
+ * listed twice, a bad `button`, a reason text of the wrong shape, an id
700
+ * already declared), and fails activation unless the plugin catches it.
701
+ *
702
+ * @throws `conflict` (rejects) Another command already has this menu path,
703
+ * or the path would be both a menu item and a submenu.
704
+ * @throws `capability` (rejects) The manifest does not declare `commands`.
705
+ * @throws `invalid` (rejects) The player refused the declaration.
706
+ * @throws `limit` (rejects) More than 160 commands in this plugin, or 1024 in
707
+ * the player.
708
+ */
709
+ readonly ready: Promise<void>;
710
+ }
711
+ /**
712
+ * `plugin.commands`: menu commands with default bindings. Needs `commands`.
713
+ *
714
+ * @remarks
715
+ * A command is one action of the plugin with a menu item (`path`), default
716
+ * keys (`bindings`), optionally a bottom-bar button (`button`) and a state
717
+ * the menu shows (`enabled`, `checked`, `busy`, `reason`). The player owns
718
+ * the menu, the binding table and the user's key overrides: it calls `run`
719
+ * when the user picks the item, presses a key or clicks the button.
720
+ * Commands of all plugins merge into the player's menus by their English
721
+ * path keys. Registration is asynchronous: `add` returns at once, and
722
+ * {@link Command.ready} reports the player's answer (during activation
723
+ * the SDK logs a refusal and skips that command, SDK 1.5.49;
724
+ * `startPlugin` fails on it). What `add` checks itself throws from `add`.
725
+ *
726
+ * @capability commands
727
+ *
728
+ * @example Add a menu item with a default key
729
+ * Tools ▸ Say hello, or Ctrl+H, shows a greeting. `add` declares the item;
730
+ * the player calls `run` when the user picks it or presses its key, and the
731
+ * user can change the key in the player's key settings.
732
+ * ```ts
733
+ * plugin.commands.add({
734
+ * id: "hello",
735
+ * path: ["Tools", "Say hello"],
736
+ * bindings: ["Ctrl+H"], // a default; the user may override it
737
+ * run: () => plugin.osd.show("Hello"),
738
+ * });
739
+ * ```
740
+ *
741
+ * @see {@link Command}, {@link CommandOptions}, [Commands, menus and key bindings](../../../docs/explanation/commands.md)
742
+ * @since 1.0.0
743
+ * @category Commands
744
+ */
745
+ export interface Commands {
746
+ /**
747
+ * Declare a command. It is registered and kept in sync; `dispose()` removes
748
+ * it from the menu and the binding table, and the id may be added again.
749
+ *
750
+ * Titles and paths cannot change in place: put changing items (track
751
+ * lists, presets) in a child {@link Scope} and rebuild it.
752
+ *
753
+ * @throws `invalid` synchronously for a malformed path (including an
754
+ * unknown `@` menu id), order or binding; `conflict` for an id this
755
+ * plugin has already declared and not disposed.
756
+ * @throws `invalid` (`ready` rejects; during activation, activation
757
+ * fails) for a text the player refuses: an id, title, path segment,
758
+ * group or reason that is empty, longer than its `COMMAND_LIMITS`
759
+ * bytes (a text value counted by its English rendering), has a control
760
+ * character or whitespace at either end, or an id with other characters
761
+ * than ASCII letters, digits, `.`, `_` and `-`. `TestHost`
762
+ * refuses the same (SDK 1.5.48).
763
+ *
764
+ * @example Pause playback from a menu item
765
+ * Playback ▸ Pause (and Ctrl+P) pauses and resumes, shows a check mark
766
+ * while paused and is greyed out when nothing can be paused. The player
767
+ * calls `run` when the user picks the item or presses its key; `enabled`
768
+ * and `checked` are functions the SDK evaluates again after every
769
+ * handler and player state change, sending only what changed.
770
+ * ```ts
771
+ * const toggle = plugin.commands.add({
772
+ * id: "toggle-pause",
773
+ * path: ["Playback", "Pause"],
774
+ * order: 210, // position among the Playback menu's items
775
+ * bindings: ["Ctrl+P"],
776
+ * enabled: () => plugin.player.state.can.pause,
777
+ * checked: () => plugin.player.state.paused,
778
+ * run: () => plugin.player.setPaused(!plugin.player.state.paused),
779
+ * });
780
+ * ```
781
+ *
782
+ * @capability commands
783
+ * @since 1.0.0
784
+ */
785
+ add(options: CommandOptions): Command;
786
+ /**
787
+ * The keys of one of this plugin's own commands (its local id, as in
788
+ * {@link CommandOptions.id}), written as the player's menus and command
789
+ * palette write them: `["W"]`, `["Ctrl+B"]`, `["⌘B"]` on macOS, arrows as
790
+ * `←`. Read-only, and always what is bound now: the user's own keys
791
+ * after a change in Keyboard Shortcuts, none when the user cleared them
792
+ * or turned on Ignore Default Shortcuts, and none for a key another
793
+ * command holds. Mouse bindings are left out, and so are `Cmd`
794
+ * bindings outside macOS (as in the menus). The first label is the one
795
+ * the menus show.
796
+ *
797
+ * @remarks
798
+ * For key hints beside a panel's controls (`KeyHint` and the `keys` of
799
+ * `ToolTipArea` in `@vestra/widgets.slint`). Read it in a
800
+ * {@link View.bind} function and the view follows every change; or
801
+ * listen with {@link Commands.onKeysChange}. The first read asks the
802
+ * player, and until its answer arrives (a few milliseconds) every
803
+ * command reads `[]`; a binding that read it runs again then.
804
+ *
805
+ * The plugin's own commands, and the player's own as `host/<id>` (SDK
806
+ * 1.6.16; `host/volume-up`, `host/mute`: the ids of
807
+ * {@link "@vestra-player/sdk/testing"!BUILTIN_COMMANDS | BUILTIN_COMMANDS} rows owned by `host`), for a panel that
808
+ * shows the player's keys beside its own controls; an id the plugin has
809
+ * not added (or another plugin's) reads `[]`. Needs nothing beyond `commands`, not
810
+ * `bindings.manage` (the whole binding table, every plugin's, is
811
+ * {@link Bindings.list}). Without the `commands` capability every
812
+ * command reads `[]`. Players before 0.7.6 have no `keys` (the player
813
+ * builds `plugin` from its own SDK) and no `KeyHint` in their widgets,
814
+ * so declare `"minPlayerVersion": "0.7.6"`.
815
+ *
816
+ * @example Show a slider's keys beside it
817
+ * The Brightness row shows its two keys, W and E by default, as key caps
818
+ * (`KeyHint` in `ui/picture.slint`). `keys` is read inside the `bind` function,
819
+ * so the view gets the new labels whenever the user changes a key or
820
+ * clears it (an empty list hides the cap).
821
+ * ```ts
822
+ * const pictureWindow = plugin.windows.create("ui/picture.slint");
823
+ * plugin.commands.add({ id: "brightness.down", path: ["@video", "Brightness −"], bindings: ["W"], run() {} });
824
+ * plugin.commands.add({ id: "brightness.up", path: ["@video", "Brightness +"], bindings: ["E"], run() {} });
825
+ * pictureWindow.bind(() => ({
826
+ * // Read in bind: the view follows every key change; "" hides a cap.
827
+ * brightnessDown: plugin.commands.keys("brightness.down")[0] ?? "",
828
+ * brightnessUp: plugin.commands.keys("brightness.up")[0] ?? "",
829
+ * }));
830
+ * ```
831
+ *
832
+ * @capability commands
833
+ * @player 0.7.6 (declare `"minPlayerVersion": "0.7.6"`; older players
834
+ * have no `keys`: calling it throws a `TypeError`).
835
+ * @since 1.6.6
836
+ */
837
+ keys(id: string): readonly string[];
838
+ /**
839
+ * Run `listener` after the keys of any of this plugin's commands changed
840
+ * (read them again with {@link Commands.keys}): the user changed or
841
+ * cleared a key, turned Ignore Default Shortcuts on or off, a command with
842
+ * keys was added or removed, or the player's first answer arrived. At most every
843
+ * 200 ms. A plugin in standby that listens is started for it, as for a
844
+ * key change in {@link Bindings.onChange}.
845
+ *
846
+ * @capability commands
847
+ *
848
+ * @example Name the current key in a status line
849
+ * The OSD tells the user the new key after they change it. The listener
850
+ * carries no data; it reads the labels with `keys`.
851
+ * ```ts
852
+ * plugin.commands.onKeysChange(() => {
853
+ * const [key] = plugin.commands.keys("toggle-blur");
854
+ * if (key) void plugin.osd.show("Blur: {}", [key]);
855
+ * else void plugin.osd.show("Blur has no key");
856
+ * });
857
+ * ```
858
+ *
859
+ * @player 0.7.6 (declare `"minPlayerVersion": "0.7.6"`; older players
860
+ * have no `onKeysChange`).
861
+ * @since 1.6.6
862
+ */
863
+ onKeysChange(listener: () => void): Disposable;
864
+ }
865
+ /**
866
+ * The core's basic playback actions (menu commands owned by the player),
867
+ * and the main window's fullscreen toggle.
868
+ *
869
+ * | action | default bindings | behaviour |
870
+ * | --- | --- | --- |
871
+ * | `stop` | F4 | close the source |
872
+ * | `play-pause` | Space, a left click on the video (player 0.5.2) | pause / resume, replay after the end |
873
+ * | `previous` / `next` | PageUp, Mouse:X2 / PageDown, Mouse:X1 (from 0.6.0; up to 0.5.x X1 was previous and X2 next) | ask the sequence provider |
874
+ * | `frame-back` / `frame-forward` | D / F | `player.step("frame", …)` |
875
+ * | `seek-backward` / `seek-forward` | ← / → | relative seek by `setStepSeek` seconds (or `host.run`'s `seconds`), exact or to keyframes as `setStepSeek` says |
876
+ * | `rate-normal`, `rate-down`, `rate-up` | Z, X, C | 1×, ±0.1 within 0.25–4 |
877
+ * | `volume-up` / `volume-down` | ↑ / ↓, wheel | ±5 (`volume-up` stops at 100) |
878
+ * | `mute` | M | toggle mute |
879
+ * | `fullscreen` | Escape (from 0.6.0; up to 0.5.x Enter, Alt+Enter, F11) | toggle the main window's fullscreen: enter it when windowed, leave it when fullscreen, as the Toggle Fullscreen command does (SDK 1.5.21, player 0.5.2; `unavailable` when the player has no window) |
880
+ *
881
+ * In the binding overlay their keys are `host/<action>`. `fullscreen`
882
+ * changes no playback state: read the result from `window.state.fullscreen`
883
+ * (`plugin.window.onChange`), which also changes when the user toggles it.
884
+ * Players before 0.5.2 reject it with `invalid`: set
885
+ * `"minPlayerVersion": "0.5.2"` when you use it.
886
+ *
887
+ * @see {@link Host.run}
888
+ * @since 1.0.0
889
+ * @category Commands
890
+ */
891
+ export type HostAction = "play-pause" | "stop" | "previous" | "next" | "frame-back" | "frame-forward" | "seek-backward" | "seek-forward" | "rate-down" | "rate-up" | "rate-normal" | "volume-up" | "volume-down" | "mute" | "fullscreen";
892
+ /**
893
+ * `plugin.host`: the player's own core actions.
894
+ *
895
+ * @remarks
896
+ * The player's core actions (play/pause, stop, step seeks, speed, volume,
897
+ * fullscreen…) are commands of the player itself, `host/<action>` in the
898
+ * binding table. Running them through `host.run` gives a plugin's own
899
+ * buttons exactly the player's behaviour: the same checks, the same
900
+ * accumulation of repeated presses and the same on-screen text, instead of
901
+ * reimplementing them with {@link Player} calls.
902
+ *
903
+ * @capability commands
904
+ *
905
+ * @example Give a custom bar the player's own Stop and Mute
906
+ * The plugin's bar buttons stop playback and mute exactly as the player's
907
+ * own keys do, with the same on-screen text. Each callback runs a core
908
+ * action; the player applies its checks and rejects with `unavailable`
909
+ * while the action is disabled, which the bar ignores.
910
+ * ```ts
911
+ * declare const bar: Panel;
912
+ * // ---cut---
913
+ * const run = (action: HostAction) =>
914
+ * plugin.host.run(action).catch((error: PluginError) => {
915
+ * if (error.code !== "unavailable") throw error; // disabled right now
916
+ * });
917
+ * bar.on("stop", () => run("stop"));
918
+ * bar.on("mute", () => run("mute"));
919
+ * ```
920
+ *
921
+ * @see {@link HostAction}, {@link Player}
922
+ * @since 1.0.0
923
+ * @category Commands
924
+ */
925
+ export interface Host {
926
+ /**
927
+ * Run a core action exactly like its menu item or key: same checks, same
928
+ * on-screen text. Resolves when it finished (or was dropped because the
929
+ * same action is still running). Rejects `unavailable` when disabled,
930
+ * `invalid` for an unknown id. Needs `commands`.
931
+ *
932
+ * Prefer this over reimplementing playback buttons.
933
+ *
934
+ * @example Make a bar button play and pause like Space
935
+ * The plugin's own Play button behaves exactly like the player's Space
936
+ * key, including its on-screen text. `host.run` runs the core action
937
+ * with the player's checks; it resolves when the action finished, and
938
+ * rejects with `unavailable` while the action is disabled (nothing open).
939
+ * ```ts
940
+ * declare const bar: Panel;
941
+ * // ---cut---
942
+ * bar.on("playPause", async () => {
943
+ * try {
944
+ * await plugin.host.run("play-pause");
945
+ * } catch (error) {
946
+ * if ((error as PluginError).code !== "unavailable") throw error;
947
+ * // Nothing to play: the button simply does nothing.
948
+ * }
949
+ * });
950
+ * ```
951
+ *
952
+ * @capability commands
953
+ * @throws `unavailable` (rejects) The action is disabled right now (nothing
954
+ * open, no window for `fullscreen`).
955
+ * @throws `invalid` (rejects) An unknown action, or `seconds` out of range.
956
+ * @throws `capability` (rejects) The manifest does not declare `commands`.
957
+ *
958
+ * @since 1.0.0
959
+ */
960
+ run(action: HostAction): Promise<void>;
961
+ /**
962
+ * One step seek of `seconds` (0.1–3600 in tenths) instead of the
963
+ * {@link Player.setStepSeek} step: the same checks, mode (exact or
964
+ * keyframes), accumulation and on-screen text as ← / →. Use it for more
965
+ * seek steps of your own (Ctrl+→ and the like) so that they add up with
966
+ * the core's and land the same way.
967
+ *
968
+ * In keyframe mode it resolves once the seek has landed (so
969
+ * `player.state.position` is current after the `await`); presses that add
970
+ * up resolve together, the last with the text. In exact mode it resolves
971
+ * once the seek is submitted, as before. `invalid` for `seconds` out of
972
+ * range.
973
+ *
974
+ * @player 0.5.1 (set `"minPlayerVersion": "0.5.1"`: older players ignore
975
+ * `seconds` and seek by the `setStepSeek` step)
976
+ * @since 1.5.19
977
+ *
978
+ * @example Add a 30-second skip that adds up with the arrow keys
979
+ * The plugin's "+30 s" button seeks forward 30 seconds and shows the same
980
+ * text as →. Passing `seconds` makes the core step seek use that step
981
+ * with the player's mode (exact or keyframes); quick presses of it and of
982
+ * → add up into one seek.
983
+ * ```ts
984
+ * declare const bar: Panel;
985
+ * // ---cut---
986
+ * bar.on("forward30", () => plugin.host.run("seek-forward", { seconds: 30 }));
987
+ * ```
988
+ *
989
+ * @capability commands
990
+ * @throws `unavailable` (rejects) The action is disabled right now (nothing
991
+ * open, no window for `fullscreen`).
992
+ * @throws `invalid` (rejects) An unknown action, or `seconds` out of range.
993
+ * @throws `capability` (rejects) The manifest does not declare `commands`.
994
+ */
995
+ run(action: "seek-backward" | "seek-forward", options: {
996
+ seconds: number;
997
+ }): Promise<void>;
998
+ }
999
+ /**
1000
+ * A command: manifest id (`"host"` for the player's own) and command id.
1001
+ *
1002
+ * @since 1.0.0
1003
+ * @category Commands
1004
+ */
1005
+ export interface BindingRef {
1006
+ /** Manifest id, or `"host"`. */
1007
+ plugin: string;
1008
+ /** Command id within that plugin. */
1009
+ command: string;
1010
+ }
1011
+ /**
1012
+ * One command's bindings, from {@link Bindings.list}.
1013
+ *
1014
+ * @since 1.0.0
1015
+ * @category Commands
1016
+ */
1017
+ export interface BindingInfo extends BindingRef {
1018
+ /** Menu title. */
1019
+ title: string;
1020
+ /** Menu path as shown; `null` for a command outside the menu. */
1021
+ path: string[] | null;
1022
+ /**
1023
+ * The menu path's keys: the English text menus merge by, the same in
1024
+ * every interface language (`["Playback", "Seek", "Back 5 s"]`; a
1025
+ * built-in menu by its key, `"Video"`, also when declared as `@video`).
1026
+ * `null` for a command outside the menu, and from players before 0.4.3.
1027
+ * Find a command by where it is in the menu with this, not with `path`.
1028
+ * Always set by `list()`; optional so that test fakes written for older
1029
+ * SDKs still type-check.
1030
+ *
1031
+ * @since 1.5.11
1032
+ */
1033
+ key?: string[] | null;
1034
+ /**
1035
+ * The command's category as shown ({@link CommandOptions.category},
1036
+ * translated), `null` when it declares none (and always from players
1037
+ * before 0.7.6). Always set by `list()`; optional so that test fakes
1038
+ * written for older SDKs still type-check. A list of commands names one `Category: Title`; without a
1039
+ * category, use the menu path (`path`) as before.
1040
+ *
1041
+ * @since 1.6.4
1042
+ */
1043
+ category?: string | null;
1044
+ /** Global, or only while the plugin's panel has focus. */
1045
+ scope: "global" | "panel";
1046
+ /** The command's own bindings. */
1047
+ defaults: string[];
1048
+ /** In effect for it: the user's override, else the defaults. */
1049
+ current: string[];
1050
+ /** The user overrode the defaults. */
1051
+ overridden: boolean;
1052
+ /** Inputs of `current` another command holds. */
1053
+ shadowed: {
1054
+ /** The input. */
1055
+ input: string;
1056
+ /** The command that holds it. */
1057
+ by: BindingRef;
1058
+ }[];
1059
+ /** Menu text of each of `current` (`Ctrl+←`, `Num5`). */
1060
+ labels: string[];
1061
+ }
1062
+ /**
1063
+ * `plugin.bindings`: list and override every command's bindings, including
1064
+ * the player's. Needs `bindings.manage`.
1065
+ *
1066
+ * @example Unbind the player's Mute key, then restore it
1067
+ * The player's Mute command loses its default key, and later gets it
1068
+ * back. `set` with `[]` saves an override that unbinds the command
1069
+ * (remembered across launches); `reset` removes the override, so the
1070
+ * command's own default bindings apply again.
1071
+ * ```ts
1072
+ * await plugin.bindings.set({ plugin: "host", command: "mute" }, []);
1073
+ * // later
1074
+ * await plugin.bindings.reset({ plugin: "host", command: "mute" });
1075
+ * ```
1076
+ *
1077
+ * @remarks
1078
+ * The player's binding table: every command's default keys (from
1079
+ * {@link CommandOptions.bindings}, the player's own as `host/<action>`)
1080
+ * and the user's overrides on top, saved across launches. A key-settings
1081
+ * plugin lists the table, writes overrides and resets them; the player
1082
+ * applies the change at once to every running plugin.
1083
+ *
1084
+ * @capability bindings.manage
1085
+ * @see [Commands, menus and key bindings](../../../docs/explanation/commands.md)
1086
+ * @since 1.0.0
1087
+ * @category Commands
1088
+ */
1089
+ export interface Bindings {
1090
+ /**
1091
+ * Every declared command, and overrides whose command is gone.
1092
+ *
1093
+ * @capability bindings.manage
1094
+ * @throws `capability` (rejects) The manifest does not declare
1095
+ * `bindings.manage`.
1096
+ *
1097
+ * @example Find the commands that use a key
1098
+ * A key-settings window shows which commands Ctrl+K is bound to now. `list`
1099
+ * resolves with every declared command and its current bindings (the
1100
+ * defaults with the user's overrides applied) and with the overrides
1101
+ * whose command is not running (`orphans`).
1102
+ * ```ts
1103
+ * const { commands } = await plugin.bindings.list();
1104
+ * const users = commands.filter((command) => command.current.includes("Ctrl+K"));
1105
+ * console.log(users.map((command) => `${command.plugin}/${command.command}`)); // "host" for the player
1106
+ * ```
1107
+ *
1108
+ * @since 1.0.0
1109
+ */
1110
+ list(): Promise<{
1111
+ /** Every declared command (running plugins and the player). */
1112
+ commands: BindingInfo[];
1113
+ /** Overrides whose command is not declared now (plugin stopped or removed). */
1114
+ orphans: {
1115
+ /** The command the override is for. */
1116
+ ref: BindingRef;
1117
+ /** The saved inputs. */
1118
+ inputs: string[];
1119
+ }[];
1120
+ }>;
1121
+ /**
1122
+ * Override a command's bindings (`[]` unbinds it); saved across launches.
1123
+ * `invalid` for a bad binding, `missing` for an unknown command that has
1124
+ * no override either.
1125
+ * At most 16 inputs, syntax as {@link CommandOptions.bindings}.
1126
+ *
1127
+ * @capability bindings.manage
1128
+ * @throws `invalid` (rejects) A malformed binding, or more than 16.
1129
+ * @throws `missing` (rejects) An unknown command that has no override
1130
+ * either.
1131
+ * @throws `capability` (rejects) The manifest does not declare
1132
+ * `bindings.manage`.
1133
+ *
1134
+ * @example Give the player's Mute command a second key
1135
+ * Mute now answers to M and to Ctrl+M. `set` replaces the command's
1136
+ * bindings with the list given (an override saved across launches), so it
1137
+ * repeats the default it keeps; `[]` would unbind it.
1138
+ * ```ts
1139
+ * await plugin.bindings.set({ plugin: "host", command: "mute" }, ["M", "Ctrl+M"]);
1140
+ * ```
1141
+ *
1142
+ * @since 1.0.0
1143
+ */
1144
+ set(ref: BindingRef, inputs: string[]): Promise<void>;
1145
+ /**
1146
+ * Back to the defaults: one command, or every override when omitted.
1147
+ *
1148
+ * @capability bindings.manage
1149
+ * @throws `missing` (rejects) A command that has no override and is not
1150
+ * declared.
1151
+ * @throws `capability` (rejects) The manifest does not declare
1152
+ * `bindings.manage`.
1153
+ *
1154
+ * @example Restore every default key
1155
+ * A "Restore defaults" button removes all of the user's overrides, so
1156
+ * every command has its declared keys again. Without an argument `reset`
1157
+ * clears every override; with a reference only that command's.
1158
+ * ```ts
1159
+ * await plugin.bindings.reset(); // every override
1160
+ * ```
1161
+ *
1162
+ * @since 1.0.0
1163
+ */
1164
+ reset(ref?: BindingRef): Promise<void>;
1165
+ /**
1166
+ * The binding list changed (read `list()` again): a declaration or an
1167
+ * override. At most every 200 ms; since player 0.5.21 only when the list
1168
+ * itself changed, not when a plugin starts again with the same commands.
1169
+ *
1170
+ * @capability bindings.manage
1171
+ *
1172
+ * @example Refresh a key list when bindings change
1173
+ * The plugin's key list stays current when the user changes a key in the
1174
+ * player or a plugin with other commands is installed. The listener
1175
+ * carries no data and runs at most every 200 ms; the plugin reads the
1176
+ * table again with `list`.
1177
+ * ```ts
1178
+ * declare function render(commands: BindingInfo[]): void;
1179
+ * // ---cut---
1180
+ * plugin.bindings.onChange(async () => {
1181
+ * const { commands } = await plugin.bindings.list(); // read the new table
1182
+ * render(commands);
1183
+ * });
1184
+ * ```
1185
+ *
1186
+ * @since 1.0.0
1187
+ */
1188
+ onChange(listener: () => void): Disposable;
1189
+ }