@vestra-player/sdk 1.7.1 → 1.7.3

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 (93) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +6 -9
  3. package/bin/vestra-plugin.mjs +4 -4
  4. package/dist/api-requests.d.ts +8 -8
  5. package/dist/api-requests.js +8 -8
  6. package/dist/capability-check.d.ts +15 -15
  7. package/dist/capability-check.js +4 -4
  8. package/dist/capability-rules.d.ts +4 -5
  9. package/dist/capability-rules.js +4 -5
  10. package/dist/commands.d.ts +34 -44
  11. package/dist/commands.js +21 -27
  12. package/dist/docs-tree.json.gz +0 -0
  13. package/dist/docs.d.ts +1 -1
  14. package/dist/docs.js +13 -3
  15. package/dist/i18n-tools.js +1 -1
  16. package/dist/i18n.js +1 -1
  17. package/dist/media.d.ts +7 -7
  18. package/dist/palettes.d.ts +5 -5
  19. package/dist/palettes.js +5 -5
  20. package/dist/plugin/appearance.js +1 -1
  21. package/dist/plugin/bindings.d.ts +2 -3
  22. package/dist/plugin/bindings.js +2 -3
  23. package/dist/plugin/commands.js +10 -11
  24. package/dist/plugin/connection.d.ts +18 -19
  25. package/dist/plugin/connection.js +23 -24
  26. package/dist/plugin/index.d.ts +5 -5
  27. package/dist/plugin/index.js +1 -1
  28. package/dist/plugin/osd.d.ts +1 -1
  29. package/dist/plugin/osd.js +1 -1
  30. package/dist/plugin/passes.d.ts +4 -4
  31. package/dist/plugin/passes.js +4 -4
  32. package/dist/plugin/patch.d.ts +8 -8
  33. package/dist/plugin/patch.js +12 -12
  34. package/dist/plugin/player/events.js +5 -5
  35. package/dist/plugin/resolvers.js +3 -3
  36. package/dist/plugin/scope.d.ts +4 -4
  37. package/dist/plugin/scope.js +4 -4
  38. package/dist/plugin/services.d.ts +2 -3
  39. package/dist/plugin/services.js +2 -3
  40. package/dist/plugin/shaders.js +5 -6
  41. package/dist/plugin/state.js +10 -10
  42. package/dist/plugin/testing/commands.d.ts +4 -5
  43. package/dist/plugin/testing/commands.js +4 -5
  44. package/dist/plugin/testing/i18n.d.ts +1 -1
  45. package/dist/plugin/testing/i18n.js +1 -1
  46. package/dist/plugin/testing/index.d.ts +147 -165
  47. package/dist/plugin/testing/index.js +141 -155
  48. package/dist/plugin/testing/internals.d.ts +9 -2
  49. package/dist/plugin/testing/internals.js +9 -2
  50. package/dist/plugin/testing/layout.d.ts +46 -3
  51. package/dist/plugin/testing/layout.js +102 -7
  52. package/dist/plugin/testing/services.js +10 -2
  53. package/dist/plugin/testing/slint-types.d.ts +75 -0
  54. package/dist/plugin/testing/slint-types.js +974 -0
  55. package/dist/plugin/timeline.d.ts +1 -1
  56. package/dist/plugin/timeline.js +2 -2
  57. package/dist/plugin/types/base.d.ts +90 -111
  58. package/dist/plugin/types/commands.d.ts +142 -174
  59. package/dist/plugin/types/packages.d.ts +48 -63
  60. package/dist/plugin/types/playback.d.ts +45 -59
  61. package/dist/plugin/types/plugin-wire.d.ts +38 -45
  62. package/dist/plugin/types/processing.d.ts +52 -65
  63. package/dist/plugin/types/services.d.ts +18 -25
  64. package/dist/plugin/types/snapshots.d.ts +34 -46
  65. package/dist/plugin/types/sources.d.ts +14 -16
  66. package/dist/plugin/types/subtitles.d.ts +7 -8
  67. package/dist/plugin/types/ui-content.d.ts +111 -116
  68. package/dist/plugin/types/ui-layout.d.ts +52 -63
  69. package/dist/plugin/types/ui-locale.d.ts +41 -45
  70. package/dist/plugin/types/ui-shell.d.ts +69 -87
  71. package/dist/plugin/values.d.ts +15 -18
  72. package/dist/plugin/values.js +16 -19
  73. package/dist/plugin/view/base.d.ts +2 -2
  74. package/dist/plugin/view/base.js +7 -8
  75. package/dist/plugin/view/layout.d.ts +2 -2
  76. package/dist/plugin/view/panel.js +2 -4
  77. package/dist/plugin/view/writer.d.ts +8 -8
  78. package/dist/plugin/view/writer.js +37 -39
  79. package/dist/plugin/when.d.ts +3 -3
  80. package/dist/plugin/wire-facade.js +6 -7
  81. package/dist/processing.d.ts +26 -30
  82. package/dist/processing.js +4 -4
  83. package/dist/source-resolvers.d.ts +2 -2
  84. package/dist/source.d.ts +1 -2
  85. package/dist/subtitles.d.ts +1 -1
  86. package/dist/ts-plugin.d.ts +5 -5
  87. package/dist/wire.d.ts +63 -70
  88. package/dist/wire.js +21 -25
  89. package/llms.txt +7 -10
  90. package/package.json +1 -1
  91. package/slint/vestra/bar-buttons.slint +6 -8
  92. package/slint/vestra/focus.slint +1 -1
  93. package/slint/vestra/widgets.slint +2 -4
@@ -14,6 +14,7 @@ import { isTextValue } from "../../i18n.js";
14
14
  import { taken } from "./transport.js";
15
15
  import { windowFacts } from "./core-actions.js";
16
16
  import { declaredText, shownValues, hostText } from "./i18n.js";
17
+ import { packageDirectories, refusal, spellingProblem, viewTypes, } from "./slint-types.js";
17
18
  export const kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
18
19
  export const SLOT_LABELS = {
19
20
  bottom: "bottom bar",
@@ -118,8 +119,15 @@ export function resetWrites(_host, inner, view) {
118
119
  * otherwise). The result is checked against the value limits whole: the
119
120
  * player counts the rows a patch keeps too.
120
121
  */
121
- export function writeProperty(host, inner, view, property, p, current) {
122
+ export function writeProperty(host, inner, view, property, p, current, typed = null) {
122
123
  const slot = `${view}\u0000${property}`;
124
+ // The value the view shows after the write: its type is checked once
125
+ // the value is whole, as the player sets it then.
126
+ const shown = (value) => {
127
+ checkSpelling(property, value);
128
+ if (typed)
129
+ checkType(typed, property, value, current);
130
+ };
123
131
  const patch = p.patch;
124
132
  // A whole array sent in parts (player 0.6.0, SDK 1.5.46): every part but
125
133
  // the last carries `more`; the player holds them and writes the whole
@@ -153,6 +161,7 @@ export function writeProperty(host, inner, view, property, p, current) {
153
161
  inner.parts.set(slot, { seq: patch.seq, rows });
154
162
  return undefined;
155
163
  }
164
+ shown(rows);
156
165
  seeImages(host, inner, [rows]);
157
166
  inner.writes.set(slot, patch.seq);
158
167
  return rows;
@@ -162,6 +171,7 @@ export function writeProperty(host, inner, view, property, p, current) {
162
171
  if (patch === undefined) {
163
172
  const value = shownValues(host, inner, p.value);
164
173
  checkValues(host, inner, { [property]: value });
174
+ shown(value);
165
175
  seeImages(host, inner, [value]);
166
176
  inner.writes.set(slot, typeof p.seq === "number" ? p.seq : 0);
167
177
  return value;
@@ -183,6 +193,7 @@ export function writeProperty(host, inner, view, property, p, current) {
183
193
  : op);
184
194
  const value = applyOps(current, resolved);
185
195
  checkValues(host, inner, { [property]: value });
196
+ shown(value);
186
197
  seeImages(host, inner, resolved.flatMap((op) => op.op === "set" ? [op.row] : op.op === "insert" ? op.rows : []));
187
198
  inner.writes.set(slot, seq);
188
199
  return value;
@@ -198,20 +209,63 @@ export function checkValues(_host, _inner, values) {
198
209
  throw new HostError("limit", `${property}: ${problem}`);
199
210
  }
200
211
  }
212
+ /**
213
+ * The declared types of the view in `file` of the plugin's package: its
214
+ * exported component, or `global` (a panel's or settings page's). `null`
215
+ * (nothing checked) when the host runs no package or the file cannot be
216
+ * read.
217
+ */
218
+ export function typedView(host, file, global, code, bare) {
219
+ const directory = packageDirectories.get(host);
220
+ const types = directory === undefined ? null : viewTypes(directory, file, global);
221
+ return types && { types, code, bare };
222
+ }
223
+ /** A refusal in the player's words, for a write that reads the property first (`bare`) or not. */
224
+ export const refusalText = (found, bare) => bare && found.why === "missing" ? "no such property" : found.message;
225
+ /**
226
+ * Refuse a value the player's Slint refuses for `property` (a value of
227
+ * another type than declared, an undeclared or `out` property), with the
228
+ * player's code and words. `current`: what the property shows now (none:
229
+ * its default), which the words describe the declared type by.
230
+ */
231
+ export function checkType(typed, property, value, current) {
232
+ const found = refusal(typed.types, property, value, typed.fresh ? undefined : current, { reconciles: typed.bare });
233
+ if (found)
234
+ throw new HostError(typed.code, refusalText(found, typed.bare));
235
+ }
236
+ /**
237
+ * Refuse a struct field name the player's conversion refuses (not in
238
+ * Slint's canonical spelling), whatever the view declares: code `host`,
239
+ * the property named.
240
+ */
241
+ export function checkSpelling(property, value) {
242
+ const problem = spellingProblem(value);
243
+ if (problem)
244
+ throw new HostError("host", `${property}: ${problem}`);
245
+ }
246
+ /** Property names in the order the player sets them (a `BTreeMap`). */
247
+ export const inSetOrder = (values) => Object.keys(values).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
201
248
  /**
202
249
  * A panel's or settings page's initial properties, as the player keeps
203
- * them: one over the limits is left out (the property keeps its default)
204
- * and reported with `ui.error`, the request itself succeeds.
250
+ * them: one over the limits (`limit`) or with a struct field name not in
251
+ * Slint's canonical spelling (`host`) is left out (the property keeps its
252
+ * default) and reported with `ui.error`, the request itself succeeds.
205
253
  */
206
254
  export function initialValues(host, _inner, values) {
207
255
  const kept = {};
208
256
  for (const [property, value] of Object.entries(values)) {
209
257
  const problem = valueLimitProblem(value);
258
+ const spelling = problem ? null : spellingProblem(value);
210
259
  if (problem)
211
260
  host.emit("ui.error", {
212
261
  code: "limit",
213
262
  message: `${property}: ${problem}`,
214
263
  });
264
+ else if (spelling)
265
+ host.emit("ui.error", {
266
+ code: "host",
267
+ message: `${property}: ${spelling}`,
268
+ });
215
269
  else
216
270
  kept[property] = value;
217
271
  }
@@ -358,6 +412,14 @@ export function layoutHandlers(host, inner) {
358
412
  resetWrites(host, inner, `w:${id}`);
359
413
  const properties = shownValues(host, inner, p.properties);
360
414
  checkValues(host, inner, properties);
415
+ // Converted, then set one by one on the new component: the first
416
+ // one refused fails the open (code `host`, the property named).
417
+ for (const name of inSetOrder(properties))
418
+ checkSpelling(name, properties[name]);
419
+ const typed = typedView(host, String(p.file), undefined, "host", false);
420
+ if (typed)
421
+ for (const name of inSetOrder(properties))
422
+ checkType(typed, name, properties[name], undefined);
361
423
  seeImages(host, inner, properties);
362
424
  host.windows.set(id, {
363
425
  file: String(p.file),
@@ -381,7 +443,7 @@ export function layoutHandlers(host, inner) {
381
443
  if (!window)
382
444
  throw new HostError("missing", "view not found");
383
445
  const property = String(p.property);
384
- const next = writeProperty(host, inner, `w:${String(p.id)}`, property, p, window.props[property]);
446
+ const next = writeProperty(host, inner, `w:${String(p.id)}`, property, p, window.props[property], typedView(host, window.file, undefined, "ui", true));
385
447
  // A part of a value sent in parts is held until the last (player 0.6.0).
386
448
  if (next !== undefined)
387
449
  window.props[property] = next;
@@ -416,8 +478,32 @@ export function layoutHandlers(host, inner) {
416
478
  String(holder),
417
479
  ]));
418
480
  const properties = initialValues(host, inner, shownValues(host, inner, p.properties));
419
- seeImages(host, inner, properties);
420
481
  const panelSlot = String(p.slot);
482
+ const global = typeof p.global === "string" ? p.global : undefined;
483
+ inner.globals.set(panelSlot, global);
484
+ // A value of a type the panel refuses is reported with `ui.error` as
485
+ // the player reports it when it builds the panel (named before the
486
+ // refusal). The panel shows its default for it; the value stays
487
+ // stored, as in the player, and a patch applies on it.
488
+ const view = mountView(panelSlot);
489
+ for (const key of [...inner.unshown])
490
+ if (key.startsWith(`${view}\u0000`))
491
+ inner.unshown.delete(key);
492
+ const typed = global === undefined
493
+ ? null
494
+ : typedView(host, String(p.file), global, "ui", true);
495
+ if (typed)
496
+ for (const name of inSetOrder(properties)) {
497
+ const found = refusal(typed.types, name, properties[name], undefined, { reconciles: true });
498
+ if (!found)
499
+ continue;
500
+ inner.unshown.add(`${view}\u0000${name}`);
501
+ host.emit("ui.error", {
502
+ code: "ui",
503
+ message: `${name}: ${refusalText(found, true)}`,
504
+ });
505
+ }
506
+ seeImages(host, inner, properties);
421
507
  resetWrites(host, inner, mountView(panelSlot));
422
508
  host.panels.set(panelSlot, {
423
509
  slot: panelSlot,
@@ -527,10 +613,19 @@ export function layoutHandlers(host, inner) {
527
613
  "ui.setMount": (p) => {
528
614
  const panel = panelFor(host, inner, p);
529
615
  const property = String(p.property);
530
- const next = writeProperty(host, inner, mountView(panel.slot), property, p, panel.props[property]);
616
+ const global = inner.globals.get(panel.slot);
617
+ const unshown = `${mountView(panel.slot)}\u0000${property}`;
618
+ const typed = global === undefined
619
+ ? null
620
+ : typedView(host, panel.file, global, "host", true);
621
+ if (typed)
622
+ typed.fresh = inner.unshown.has(unshown);
623
+ const next = writeProperty(host, inner, mountView(panel.slot), property, p, panel.props[property], typed);
531
624
  // A part of a value sent in parts is held until the last (player 0.6.0).
532
- if (next !== undefined)
625
+ if (next !== undefined) {
533
626
  panel.props[property] = next;
627
+ inner.unshown.delete(unshown);
628
+ }
534
629
  },
535
630
  "timeline.marks": () => ({
536
631
  marks: host.timeline.marks,
@@ -12,7 +12,7 @@ import { SESSION_STORAGE_LIMITS } from "../services.js";
12
12
  import { validStep } from "../player/rules.js";
13
13
  import { runCore, windowFacts } from "./core-actions.js";
14
14
  import { shownText, declaredText, shownValues, hostText } from "./i18n.js";
15
- import { resetWrites, writeProperty, initialValues, seeImages, kebab, } from "./layout.js";
15
+ import { resetWrites, writeProperty, initialValues, seeImages, kebab, typedView, checkType, inSetOrder, } from "./layout.js";
16
16
  /** A `plugin.storage.session` key, checked as the player does. */
17
17
  export function sessionKey(key) {
18
18
  if (typeof key !== "string" ||
@@ -219,6 +219,14 @@ export function servicesHandlers(host, inner) {
219
219
  if (host.settings.pages.size >= 8)
220
220
  throw new HostError("invalid", "a plugin has at most 8 settings pages");
221
221
  const properties = initialValues(host, inner, shownValues(host, inner, p.properties));
222
+ // Stricter than the player, which sets a page's values when the
223
+ // Options window shows it (and fails to show it, code `ui`): the
224
+ // test host checks their types when they are written, so a test
225
+ // need not open the window.
226
+ const typed = typedView(host, String(p.file), String(p.global), "ui", true);
227
+ if (typed)
228
+ for (const name of inSetOrder(properties))
229
+ checkType(typed, name, properties[name], undefined);
222
230
  seeImages(host, inner, properties);
223
231
  resetWrites(host, inner, `$settings:${id}`);
224
232
  host.settings.pages.set(id, {
@@ -243,7 +251,7 @@ export function servicesHandlers(host, inner) {
243
251
  if (!page)
244
252
  throw new HostError("missing", "page not registered");
245
253
  const property = String(p.property);
246
- const next = writeProperty(host, inner, `$settings:${String(p.id)}`, property, p, page.props[property]);
254
+ const next = writeProperty(host, inner, `$settings:${String(p.id)}`, property, p, page.props[property], typedView(host, page.file, page.global, "ui", true));
247
255
  // A part of a value sent in parts is held until the last (player 0.6.0).
248
256
  if (next !== undefined)
249
257
  page.props[property] = next;
@@ -0,0 +1,75 @@
1
+ import type { Json } from "../../wire.ts";
2
+ import type { TestHost } from "./index.ts";
3
+ /** The package directory of the plugin a host runs (set by `startPlugin`). */
4
+ export declare const packageDirectories: WeakMap<TestHost, string>;
5
+ /** A declared type, resolved. `any`: not known here, every value passes. */
6
+ export type SlintType = {
7
+ k: "number" | "string" | "bool" | "image" | "brush" | "enum" | "other";
8
+ } | {
9
+ k: "array";
10
+ of: SlintType;
11
+ } | {
12
+ k: "struct";
13
+ fields: Map<string, SlintType>;
14
+ } | {
15
+ k: "any";
16
+ };
17
+ type Visibility = "in" | "out" | "in-out" | "private";
18
+ /**
19
+ * Slint's `normalize_identifier`: `_` is `-` except as the first
20
+ * character, where `-` is `_`.
21
+ */
22
+ export declare const normalize: (name: string) => string;
23
+ /** A property as declared: its visibility, type and default rows. */
24
+ export interface Declared {
25
+ visibility: Visibility;
26
+ type: SlintType;
27
+ rows: boolean;
28
+ /**
29
+ * The value it holds before any write, as the player's `to_json` gives
30
+ * it, when the test host can tell (`undefined`: it cannot).
31
+ */
32
+ initial: Json | undefined;
33
+ }
34
+ /**
35
+ * The writable surface of a view: its properties by normalized name.
36
+ * `open`: names not listed may still exist (the component inherits a
37
+ * component this parser does not look into), so they are not refused.
38
+ */
39
+ export interface ViewTypes {
40
+ properties: Map<string, Declared>;
41
+ open: boolean;
42
+ }
43
+ /**
44
+ * The properties of the view `file` (relative to `directory`) shows: its
45
+ * one exported component (a window), or the exported `global` (a panel or
46
+ * settings page). `null` when the file cannot be read or the view cannot
47
+ * be found: then nothing is checked. Kept while none of the files it was
48
+ * read from (the view's and those it imports) changed.
49
+ */
50
+ export declare function viewTypes(directory: string, file: string, global?: string): ViewTypes | null;
51
+ /** Why the player refuses a write: no such property, an out property, or the type. */
52
+ export interface Refusal {
53
+ why: "missing" | "readonly" | "type";
54
+ /** The player's words (`ui_values::refusal`), the property named first. */
55
+ message: string;
56
+ }
57
+ /**
58
+ * The player's refusal of `value` for `property` of a view of `types`, or
59
+ * `null` when it takes it. `current`: what the property holds (the last
60
+ * value it took; none: its default), which the words of a type refusal
61
+ * describe the declaration by, as the player's do.
62
+ */
63
+ export declare function refusal(types: ViewTypes, property: string, value: Json, current: Json | undefined, options?: {
64
+ reconciles?: boolean;
65
+ }): Refusal | null;
66
+ /**
67
+ * The player's conversion refuses a struct field name not in Slint's
68
+ * canonical spelling (`ui_values`: no `-` first, no `_` after the first
69
+ * character), whatever the declaration says: the first such name in the
70
+ * order the player meets them (fields by name, a field's value before its
71
+ * name), in its words; `null` when there is none. Image references and
72
+ * Markdown documents are not structs.
73
+ */
74
+ export declare function spellingProblem(value: Json): string | null;
75
+ export {};