@vestra-player/sdk 1.5.13 → 1.5.15

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.
@@ -7,54 +7,103 @@
7
7
  * input = key | "Mouse:" mouse
8
8
  */
9
9
  import { failure } from "./runtime.js";
10
- const MODIFIERS = ["Ctrl", "Alt", "Shift", "Cmd"];
10
+ /**
11
+ * The names a binding (`CommandOptions.bindings`, `Bindings.set`) is made
12
+ * of, as the player's binding parser accepts them. A binding is
13
+ * `{ modifier "+" } input`: modifiers in the order of `modifiers`, each at
14
+ * most once, then one input. An input is a name of `letters`, `digits`,
15
+ * `functionKeys`, `named` or `mouse`, or one other printable character that
16
+ * is not a letter, digit, space or `+` (`">"`, `"["`, `"/"`), written as
17
+ * typed, never with `Shift` (`">"`, not `"Shift+."`; `"!"`, not
18
+ * `"Shift+1"`). Anything else fails with code `invalid`. The player's tests
19
+ * check that these agree with the player.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { BINDING_INPUTS } from "@vestra-player/sdk/testing";
24
+ *
25
+ * assert.ok(BINDING_INPUTS.named.includes("PageUp"));
26
+ * assert.ok(BINDING_INPUTS.mouse.includes("Mouse:WheelUp"));
27
+ * ```
28
+ *
29
+ * @since 1.5.14
30
+ */
31
+ export const BINDING_INPUTS = Object.freeze({
32
+ /**
33
+ * Modifiers, in the order a binding writes them. `Cmd` is ⌘ on macOS and
34
+ * the Windows logo key on Windows; on macOS `Ctrl` also matches ⌘.
35
+ */
36
+ modifiers: ["Ctrl", "Alt", "Shift", "Cmd"],
37
+ /** Letter keys, by key name whatever the case: `A` to `Z`. */
38
+ letters: [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"],
39
+ /** Digit keys of the main keyboard: `0` to `9`. */
40
+ digits: [..."0123456789"],
41
+ /** Function keys: `F1` to `F24`. */
42
+ functionKeys: Array.from({ length: 24 }, (_, index) => `F${index + 1}`),
43
+ /**
44
+ * Other named keys, matched by the physical key. `Plus` is the `+` key
45
+ * however it is typed; the `Numpad…` names are the numeric keypad only,
46
+ * never the main keyboard.
47
+ */
48
+ named: [
49
+ "Space",
50
+ "Enter",
51
+ "Tab",
52
+ "Escape",
53
+ "Backspace",
54
+ "Delete",
55
+ "Insert",
56
+ "Home",
57
+ "End",
58
+ "PageUp",
59
+ "PageDown",
60
+ "ArrowLeft",
61
+ "ArrowRight",
62
+ "ArrowUp",
63
+ "ArrowDown",
64
+ "Plus",
65
+ ...Array.from({ length: 10 }, (_, digit) => `Numpad${digit}`),
66
+ "NumpadPlus",
67
+ "NumpadMinus",
68
+ "NumpadMultiply",
69
+ "NumpadDivide",
70
+ "NumpadEnter",
71
+ "NumpadDecimal",
72
+ ],
73
+ /**
74
+ * Mouse inputs on the video area. `:LeftHalf` and `:RightHalf` tell the
75
+ * halves of the video apart for a double click.
76
+ */
77
+ mouse: [
78
+ "Mouse:LeftClick",
79
+ "Mouse:LeftDoubleClick",
80
+ "Mouse:LeftDoubleClick:LeftHalf",
81
+ "Mouse:LeftDoubleClick:RightHalf",
82
+ "Mouse:MiddleClick",
83
+ "Mouse:X1",
84
+ "Mouse:X2",
85
+ "Mouse:WheelUp",
86
+ "Mouse:WheelDown",
87
+ "Mouse:WheelLeft",
88
+ "Mouse:WheelRight",
89
+ ],
90
+ });
91
+ const MODIFIERS = BINDING_INPUTS.modifiers;
11
92
  const NAMED = new Set([
12
- "Space",
13
- "Enter",
14
- "Tab",
15
- "Escape",
16
- "Backspace",
17
- "Delete",
18
- "Insert",
19
- "Home",
20
- "End",
21
- "PageUp",
22
- "PageDown",
23
- "ArrowLeft",
24
- "ArrowRight",
25
- "ArrowUp",
26
- "ArrowDown",
27
- "Plus",
28
- // Numeric keypad: never matched by the main keyboard keys, nor they by these.
29
- ..."0123456789".split("").map((digit) => `Numpad${digit}`),
30
- "NumpadPlus",
31
- "NumpadMinus",
32
- "NumpadMultiply",
33
- "NumpadDivide",
34
- "NumpadEnter",
35
- "NumpadDecimal",
36
- ]);
37
- const MOUSE = new Set([
38
- "LeftClick",
39
- "LeftDoubleClick",
40
- "LeftDoubleClick:LeftHalf",
41
- "LeftDoubleClick:RightHalf",
42
- "MiddleClick",
43
- "X1",
44
- "X2",
45
- "WheelUp",
46
- "WheelDown",
47
- "WheelLeft",
48
- "WheelRight",
93
+ ...BINDING_INPUTS.functionKeys,
94
+ ...BINDING_INPUTS.named,
49
95
  ]);
96
+ const MOUSE = new Set(BINDING_INPUTS.mouse);
97
+ const LETTERS = new Set(BINDING_INPUTS.letters);
98
+ const DIGITS = new Set(BINDING_INPUTS.digits);
50
99
  function kind(input) {
51
100
  if (input.startsWith("Mouse:"))
52
- return MOUSE.has(input.slice(6)) ? "mouse" : null;
53
- if (/^[A-Z]$/.test(input))
101
+ return MOUSE.has(input) ? "mouse" : null;
102
+ if (LETTERS.has(input))
54
103
  return "letter";
55
- if (/^[0-9]$/.test(input))
104
+ if (DIGITS.has(input))
56
105
  return "digit";
57
- if (/^F([1-9]|1[0-9]|2[0-4])$/.test(input) || NAMED.has(input))
106
+ if (NAMED.has(input))
58
107
  return "named";
59
108
  // One printable, non-alphanumeric, non-space character; "+" is written Plus.
60
109
  if ([...input].length === 1 && /^[^\p{L}\p{N}\s+]$/u.test(input))
@@ -1,6 +1,38 @@
1
1
  import type { ScopeImpl } from "./scope.ts";
2
2
  import type { Osd } from "./types.ts";
3
3
  import type { TemplateArgsJson, TextValueJson } from "../wire.ts";
4
+ /**
5
+ * The player's limits on the on-screen display ({@link Osd}), counted on
6
+ * the text as shown: after the player translated it and filled in its
7
+ * arguments. A text over them fails with code `invalid`: `osd.show`
8
+ * rejects, `OsdPanel.set` reports to `Scope.onError`. The player's tests
9
+ * check that these agree with the player.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { OSD_LIMITS } from "@vestra-player/sdk/testing";
14
+ *
15
+ * const lines = rows.slice(0, OSD_LIMITS.panelLines);
16
+ * panel.set(lines.join("\n"), null, { maxColumns: 60 });
17
+ * ```
18
+ *
19
+ * @since 1.5.14
20
+ */
21
+ export declare const OSD_LIMITS: Readonly<{
22
+ /**
23
+ * Characters of one `osd.show` message (200; at least 1 that is not
24
+ * white space). Line breaks are shown as spaces.
25
+ */
26
+ readonly messageChars: 200;
27
+ /** Lines of the information block (`OsdPanel.set`) (32). */
28
+ readonly panelLines: 32;
29
+ /** UTF-8 bytes of the information block (4096). */
30
+ readonly panelBytes: 4096;
31
+ /** The smallest `OsdPanelOptions.maxColumns` (8). */
32
+ readonly minColumns: 8;
33
+ /** The largest `OsdPanelOptions.maxColumns` (1000). */
34
+ readonly maxColumns: 1000;
35
+ }>;
4
36
  /**
5
37
  * Copy and check template arguments: an array or object of at most 16
6
38
  * strings, finite numbers, texts and lists (`TEXT_LIMITS`).
@@ -2,6 +2,38 @@
2
2
  import { Latest } from "./runtime.js";
3
3
  import { failure } from "./runtime.js";
4
4
  import { isTextValue, textProblem } from "../i18n.js";
5
+ /**
6
+ * The player's limits on the on-screen display ({@link Osd}), counted on
7
+ * the text as shown: after the player translated it and filled in its
8
+ * arguments. A text over them fails with code `invalid`: `osd.show`
9
+ * rejects, `OsdPanel.set` reports to `Scope.onError`. The player's tests
10
+ * check that these agree with the player.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { OSD_LIMITS } from "@vestra-player/sdk/testing";
15
+ *
16
+ * const lines = rows.slice(0, OSD_LIMITS.panelLines);
17
+ * panel.set(lines.join("\n"), null, { maxColumns: 60 });
18
+ * ```
19
+ *
20
+ * @since 1.5.14
21
+ */
22
+ export const OSD_LIMITS = Object.freeze({
23
+ /**
24
+ * Characters of one `osd.show` message (200; at least 1 that is not
25
+ * white space). Line breaks are shown as spaces.
26
+ */
27
+ messageChars: 200,
28
+ /** Lines of the information block (`OsdPanel.set`) (32). */
29
+ panelLines: 32,
30
+ /** UTF-8 bytes of the information block (4096). */
31
+ panelBytes: 4096,
32
+ /** The smallest `OsdPanelOptions.maxColumns` (8). */
33
+ minColumns: 8,
34
+ /** The largest `OsdPanelOptions.maxColumns` (1000). */
35
+ maxColumns: 1000,
36
+ });
5
37
  /**
6
38
  * Copy and check template arguments: an array or object of at most 16
7
39
  * strings, finite numbers, texts and lists (`TEXT_LIMITS`).
@@ -54,8 +86,10 @@ class PanelHandle {
54
86
  try {
55
87
  const max = options?.maxColumns;
56
88
  if (max !== undefined &&
57
- !(Number.isInteger(max) && max >= 8 && max <= 1000))
58
- throw failure("invalid", "maxColumns is an integer from 8 to 1000");
89
+ !(Number.isInteger(max) &&
90
+ max >= OSD_LIMITS.minColumns &&
91
+ max <= OSD_LIMITS.maxColumns))
92
+ throw failure("invalid", `maxColumns is an integer from ${OSD_LIMITS.minColumns} to ${OSD_LIMITS.maxColumns}`);
59
93
  value = {
60
94
  text: text === null ? null : shownText(text, args),
61
95
  ...(text === null || args === undefined || args === null
@@ -81,6 +81,12 @@ function view(raw) {
81
81
  raws.set(state, raw);
82
82
  return state;
83
83
  }
84
+ /** `stats().video.decoding` from `hwdec` for players that do not send it. */
85
+ function decoding(hwdec) {
86
+ if (hwdec === null || hwdec === undefined || hwdec === "")
87
+ return null;
88
+ return hwdec === "no" ? "software" : "hardware";
89
+ }
84
90
  export const rawOf = (state) => raws.get(state);
85
91
  export const sameStamp = (a, b) => a.generation === b.generation && a.intentVersion === b.intentVersion;
86
92
  function sourceFailure(error) {
@@ -474,6 +480,7 @@ export function player(scope) {
474
480
  session: raw.session,
475
481
  framesShown: raw.framesShown,
476
482
  framesDropped: raw.framesDropped,
483
+ presentedFps: n(raw.presentedFps),
477
484
  video: raw.video && {
478
485
  codec: raw.video.codec,
479
486
  width: raw.video.width,
@@ -487,6 +494,7 @@ export function player(scope) {
487
494
  displayFps: n(raw.video.displayFps),
488
495
  bitrate: n(raw.video.bitrate),
489
496
  hwdec: n(raw.video.hwdec),
497
+ decoding: raw.video.decoding ?? decoding(raw.video.hwdec),
490
498
  transfer: n(raw.video.transfer),
491
499
  },
492
500
  audio: raw.audio && {
@@ -6,4 +6,29 @@ export declare const power: (scope: ScopeImpl) => Power;
6
6
  export declare function tools(scope: ScopeImpl): Tools;
7
7
  export declare const storage: (scope: ScopeImpl) => Storage;
8
8
  export declare function system(scope: ScopeImpl): System;
9
+ /**
10
+ * The player's limits on {@link Secrets}. A name or value outside them
11
+ * fails with code `invalid`; a new name beyond `names` fails with `limit`.
12
+ * The player's tests check that these agree with the player.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { SECRET_LIMITS } from "@vestra-player/sdk/testing";
17
+ *
18
+ * assert.ok(Buffer.byteLength(token) <= SECRET_LIMITS.valueBytes);
19
+ * ```
20
+ *
21
+ * @since 1.5.14
22
+ */
23
+ export declare const SECRET_LIMITS: Readonly<{
24
+ /**
25
+ * Characters of a name (64, at least 1), each one of `a-z`, `0-9`, `.`,
26
+ * `_` and `-`.
27
+ */
28
+ readonly nameChars: 64;
29
+ /** UTF-8 bytes of a value (1024, at least 1; no NUL character). */
30
+ readonly valueBytes: 1024;
31
+ /** Different names one plugin may have stored at the same time (256). */
32
+ readonly names: 256;
33
+ }>;
9
34
  export declare const secrets: (scope: ScopeImpl) => Secrets;
@@ -292,13 +292,38 @@ export function system(scope) {
292
292
  },
293
293
  };
294
294
  }
295
- const SECRET = /^[a-z0-9._-]{1,64}$/;
295
+ /**
296
+ * The player's limits on {@link Secrets}. A name or value outside them
297
+ * fails with code `invalid`; a new name beyond `names` fails with `limit`.
298
+ * The player's tests check that these agree with the player.
299
+ *
300
+ * @example
301
+ * ```ts
302
+ * import { SECRET_LIMITS } from "@vestra-player/sdk/testing";
303
+ *
304
+ * assert.ok(Buffer.byteLength(token) <= SECRET_LIMITS.valueBytes);
305
+ * ```
306
+ *
307
+ * @since 1.5.14
308
+ */
309
+ export const SECRET_LIMITS = Object.freeze({
310
+ /**
311
+ * Characters of a name (64, at least 1), each one of `a-z`, `0-9`, `.`,
312
+ * `_` and `-`.
313
+ */
314
+ nameChars: 64,
315
+ /** UTF-8 bytes of a value (1024, at least 1; no NUL character). */
316
+ valueBytes: 1024,
317
+ /** Different names one plugin may have stored at the same time (256). */
318
+ names: 256,
319
+ });
320
+ const SECRET = new RegExp(`^[a-z0-9._-]{1,${SECRET_LIMITS.nameChars}}$`);
296
321
  export const secrets = (scope) => {
297
322
  const named = (name) => {
298
323
  if (!scope.runtime.can("secrets"))
299
324
  throw failure("capability", "secrets must be declared in manifest");
300
325
  if (typeof name !== "string" || !SECRET.test(name))
301
- throw failure("invalid", "secret names are 1–64 of a-z, 0-9, ., _ and -");
326
+ throw failure("invalid", `secret names are 1–${SECRET_LIMITS.nameChars} of a-z, 0-9, ., _ and -`);
302
327
  return name;
303
328
  };
304
329
  return {
@@ -307,8 +332,8 @@ export const secrets = (scope) => {
307
332
  if (typeof value !== "string" ||
308
333
  !value ||
309
334
  value.includes("\0") ||
310
- Buffer.byteLength(value) > 1024)
311
- throw failure("invalid", "secret values are 1–1024 bytes of text; delete() removes one");
335
+ Buffer.byteLength(value) > SECRET_LIMITS.valueBytes)
336
+ throw failure("invalid", `secret values are 1–${SECRET_LIMITS.valueBytes} bytes of text; delete() removes one`);
312
337
  await scope.runtime.host.secrets.set(named(name), value);
313
338
  },
314
339
  delete: async (name) => scope.runtime.host.secrets.delete(named(name)),
@@ -2,7 +2,14 @@ import type { Server } from "node:net";
2
2
  import { HostError } from "../wire.ts";
3
3
  import type { PackageManifest, PackageSource } from "./types.ts";
4
4
  import type { Json, LayoutSlot, LocalServices, PlaybackStats, Transport, WireSystemInfo } from "../wire.ts";
5
- import { COMMAND_LIMITS, MENU_IDS } from "../commands.ts";
5
+ import { BUILTIN_COMMANDS, BUILTIN_SUBMENUS, COMMAND_LIMITS, MENU_IDS } from "../commands.ts";
6
+ import type { BuiltinCommand, BuiltinSubmenu } from "../commands.ts";
7
+ import { CAPABILITY_INFO, MESSAGE_LIMIT } from "../capabilities.ts";
8
+ import type { CapabilityInfo } from "../capabilities.ts";
9
+ import { OSD_LIMITS } from "./osd.ts";
10
+ import { SECRET_LIMITS } from "./services.ts";
11
+ import { BINDING_INPUTS } from "./bindings.ts";
12
+ import { THEME_PALETTES } from "../palettes.ts";
6
13
  import { UI_VALUE_LIMITS } from "./values.ts";
7
14
  import type { CommandDeclaration } from "../commands.ts";
8
15
  import type { SourceState } from "../source.ts";
@@ -15,6 +22,22 @@ import { LOCALES, LIST_SEPARATORS, TEXT_LIMITS } from "../i18n.ts";
15
22
  export { HostError };
16
23
  /** The player's command caps, which the test host enforces as well. */
17
24
  export { COMMAND_LIMITS, MENU_IDS };
25
+ /** The submenus of the player's built-in plugins, by key path. */
26
+ export { BUILTIN_COMMANDS, BUILTIN_SUBMENUS };
27
+ export type { BuiltinCommand, BuiltinSubmenu };
28
+ /** The manifest capabilities: what each opens and how the store shows it. */
29
+ export { CAPABILITY_INFO };
30
+ export type { CapabilityInfo };
31
+ /** The longest message a plugin may send the player. */
32
+ export { MESSAGE_LIMIT };
33
+ /** The player's limits on the on-screen display. */
34
+ export { OSD_LIMITS };
35
+ /** The player's limits on stored secrets. */
36
+ export { SECRET_LIMITS };
37
+ /** The names bindings are made of. */
38
+ export { BINDING_INPUTS };
39
+ /** The colours of the player's palettes, by `Theme` token. */
40
+ export { THEME_PALETTES };
18
41
  /** The player's property value limits, which the test host enforces as well. */
19
42
  export { UI_VALUE_LIMITS };
20
43
  /**
@@ -65,7 +65,12 @@ import { tmpdir } from "node:os";
65
65
  import { extname, isAbsolute, join } from "node:path";
66
66
  import { fileURLToPath } from "node:url";
67
67
  import { HostError } from "../wire.js";
68
- import { COMMAND_LIMITS, MENU_IDS } from "../commands.js";
68
+ import { BUILTIN_COMMANDS, BUILTIN_SUBMENUS, COMMAND_LIMITS, MENU_IDS, } from "../commands.js";
69
+ import { CAPABILITY_INFO, MESSAGE_LIMIT } from "../capabilities.js";
70
+ import { OSD_LIMITS } from "./osd.js";
71
+ import { SECRET_LIMITS } from "./services.js";
72
+ import { BINDING_INPUTS } from "./bindings.js";
73
+ import { THEME_PALETTES } from "../palettes.js";
69
74
  import { UI_VALUE_LIMITS, valueLimitProblem } from "./values.js";
70
75
  import { nodeProblem } from "../processing.js";
71
76
  import { RENDER_DEFAULTS, renderProblem, VIEW_DEFAULTS, viewProblem, } from "./view.js";
@@ -76,6 +81,20 @@ import { Catalog, format as formatTemplate, HOST_GROUPS, HOST_ZH_HANS, LOCALES,
76
81
  export { HostError };
77
82
  /** The player's command caps, which the test host enforces as well. */
78
83
  export { COMMAND_LIMITS, MENU_IDS };
84
+ /** The submenus of the player's built-in plugins, by key path. */
85
+ export { BUILTIN_COMMANDS, BUILTIN_SUBMENUS };
86
+ /** The manifest capabilities: what each opens and how the store shows it. */
87
+ export { CAPABILITY_INFO };
88
+ /** The longest message a plugin may send the player. */
89
+ export { MESSAGE_LIMIT };
90
+ /** The player's limits on the on-screen display. */
91
+ export { OSD_LIMITS };
92
+ /** The player's limits on stored secrets. */
93
+ export { SECRET_LIMITS };
94
+ /** The names bindings are made of. */
95
+ export { BINDING_INPUTS };
96
+ /** The colours of the player's palettes, by `Theme` token. */
97
+ export { THEME_PALETTES };
79
98
  /** The player's property value limits, which the test host enforces as well. */
80
99
  export { UI_VALUE_LIMITS };
81
100
  /**
@@ -460,6 +479,7 @@ export class TestHost {
460
479
  session: 0,
461
480
  framesShown: 0,
462
481
  framesDropped: 0,
482
+ presentedFps: null,
463
483
  video: null,
464
484
  audio: null,
465
485
  avSyncMs: null,
@@ -2545,8 +2565,8 @@ export class TestHost {
2545
2565
  },
2546
2566
  "osd.show": (p) => {
2547
2567
  const text = this.#shown(p.text, p.args, "text").replace(/[\n\r]/g, " ");
2548
- if (!text.trim() || [...text].length > 200)
2549
- throw new HostError("invalid", "osd text needs 1..200 characters");
2568
+ if (!text.trim() || [...text].length > OSD_LIMITS.messageChars)
2569
+ throw new HostError("invalid", `osd text needs 1..${OSD_LIMITS.messageChars} characters`);
2550
2570
  this.osd.push(text);
2551
2571
  },
2552
2572
  "osd.panel": (p) => {
@@ -2554,10 +2574,20 @@ export class TestHost {
2554
2574
  return void (this.osdPanel = null);
2555
2575
  const max = p.maxColumns;
2556
2576
  if (max !== undefined &&
2557
- !(Number.isInteger(max) && Number(max) >= 8 && Number(max) <= 1000))
2558
- throw new HostError("invalid", "maxColumns is an integer from 8 to 1000");
2559
- const text = this.#shown(p.text, p.args, "text");
2560
- this.osdPanel = max === undefined ? text : fitColumns(text, Number(max));
2577
+ !(Number.isInteger(max) &&
2578
+ Number(max) >= OSD_LIMITS.minColumns &&
2579
+ Number(max) <= OSD_LIMITS.maxColumns))
2580
+ throw new HostError("invalid", `maxColumns is an integer from ${OSD_LIMITS.minColumns} to ${OSD_LIMITS.maxColumns}`);
2581
+ const shown = this.#shown(p.text, p.args, "text");
2582
+ const text = max === undefined ? shown : fitColumns(shown, Number(max));
2583
+ // As the player: \n separates lines, a trailing one ends the last.
2584
+ const lines = text.split("\n");
2585
+ if (text.endsWith("\n"))
2586
+ lines.pop();
2587
+ if (Buffer.byteLength(text) > OSD_LIMITS.panelBytes ||
2588
+ lines.length > OSD_LIMITS.panelLines)
2589
+ throw new HostError("invalid", `osd panel allows ${OSD_LIMITS.panelLines} lines, ${OSD_LIMITS.panelBytes} bytes`);
2590
+ this.osdPanel = text;
2561
2591
  },
2562
2592
  "playback.stats": () => this.stats,
2563
2593
  "audio.addTrack": (p) => {