@vestra-player/sdk 1.6.20 → 1.6.22

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.d.ts +1 -1
  3. package/dist/commands.js +8 -8
  4. package/dist/docs-tree.json.gz +0 -0
  5. package/dist/i18n-tools.js +7 -2
  6. package/dist/plugin/testing/commands.js +3 -3
  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,692 @@
1
+ import type { Plugin, Scope } from "./base.ts";
2
+ import type { System } from "./services.ts";
3
+ import type { Panel, Window } from "./ui-layout.ts";
4
+ import type { SettingsPage } from "./ui-shell.ts";
5
+ import type { Json } from "../../wire.ts";
6
+ import type { Disposable } from "./base.ts";
7
+ import type { Text, TextList } from "./ui-locale.ts";
8
+ /**
9
+ * An image file for a Slint `image` property, made by {@link Ui.image}.
10
+ *
11
+ * @remarks
12
+ * Opaque: pass it where the Slint type is `image`, with {@link View.set} or
13
+ * {@link View.bind}: the whole value of an `image` property or, from SDK
14
+ * 1.5.19 (player 0.5.1), an `image` field at any depth, such as the logo of
15
+ * each row of a list. Making the reference does not read the file: the
16
+ * player checks and decodes it each time it receives the value (a property
17
+ * write, a window opening; {@link Ui.image} has the rules and limits).
18
+ *
19
+ * A reference belongs to the {@link Scope} that created it. Once that scope
20
+ * is disposed, writing the reference fails with `invalid` (reported to
21
+ * {@link Scope.onError}); an image already on screen stays until the
22
+ * property changes or the view closes.
23
+ *
24
+ * @example Show a cover image from the data directory
25
+ * A window opens showing `cover.png`, which the plugin saved in its data
26
+ * directory. `ui.image` only makes a reference, without reading the file;
27
+ * the player checks and decodes the file when it receives the value, so a
28
+ * missing file fails that write with `missing` (here: `show` rejects, as
29
+ * it is an initial property). A missing image nested inside a value is
30
+ * drawn empty instead.
31
+ * ```ts
32
+ * const cover = plugin.windows.create("ui/cover.slint");
33
+ * // `art` is an `image` property in ui/cover.slint.
34
+ * cover.set({ art: plugin.ui.image(`${plugin.dataDirectory}/cover.png`) });
35
+ * await cover.show();
36
+ * ```
37
+ *
38
+ * @example Show a logo in each row of a list
39
+ * Each row of the list draws its own small logo next to its name. An
40
+ * `ImageRef` may sit in any field of a property value (SDK 1.5.19, player
41
+ * 0.5.1), so the rows carry their icons; `maxSide: 64` decodes each logo
42
+ * at most 64 px wide, which keeps the view's image memory small.
43
+ * ```slint
44
+ * export struct Row { key: string, name: string, icon: image }
45
+ * ```
46
+ * ```ts
47
+ * const items = [{ id: "a", name: "A", iconPath: `${plugin.dataDirectory}/a.png` }];
48
+ * const list = plugin.windows.create("ui/list.slint");
49
+ * list.bind(() => ({
50
+ * rows: items.map((item) => ({
51
+ * key: item.id,
52
+ * name: item.name,
53
+ * // About twice the drawn size (32 px) stays sharp on dense screens.
54
+ * icon: plugin.ui.image(item.iconPath, { maxSide: 64 }),
55
+ * })),
56
+ * }));
57
+ * ```
58
+ *
59
+ * @see {@link Ui.image}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md)
60
+ * @since 1.0.0
61
+ * @category UI
62
+ */
63
+ export interface ImageRef {
64
+ /** The path given to {@link Ui.image}, unchanged. */
65
+ readonly path: string;
66
+ /** Brand that marks the value as an image reference; never construct one yourself. */
67
+ readonly __vestraImage: true;
68
+ }
69
+ /**
70
+ * Options of {@link Ui.image} and {@link Ui.remoteImage}.
71
+ *
72
+ * @since 1.5.19
73
+ * @category UI
74
+ */
75
+ export interface ImageOptions {
76
+ /**
77
+ * Decode the image scaled down, aspect kept, so that neither side is over
78
+ * this many pixels (an integer 1–4096); smaller images stay as they are.
79
+ * Use about twice the drawn size (64 for a 32 px logo) so that it stays
80
+ * sharp on high-density screens. It keeps the decoded memory small: a
81
+ * 1024×1024 icon is 4 MB decoded, 16 KB at `maxSide: 64`.
82
+ *
83
+ * @player 0.5.1; older players refuse the reference (`invalid`).
84
+ */
85
+ maxSide?: number;
86
+ }
87
+ /**
88
+ * A Markdown document for `MarkdownView` or `MarkdownBlocks`, made by
89
+ * {@link Ui.markdown}.
90
+ *
91
+ * @remarks
92
+ * Opaque, like {@link ImageRef}: pass it where the Slint type is
93
+ * `[MarkdownBlock]`: the whole value of such a property (the `blocks` of
94
+ * `MarkdownView` from `@vestra/markdown.slint`) or, from SDK 1.5.4, a
95
+ * `[MarkdownBlock]` field at any depth of a property value, such as the
96
+ * `body` of each row of a chat's message list. It carries the text, the
97
+ * base address and the local copies of its remote images; the player parses
98
+ * and draws it. Writing a document whose text did not change (a new
99
+ * reference for the same text included) costs the player no parsing, and a
100
+ * changed document updates only the blocks that changed. It belongs to the
101
+ * scope that created it: once that scope is disposed, writing it fails with
102
+ * `invalid`, wherever it is in the value.
103
+ *
104
+ * @example Show chat messages, one document per row
105
+ * The chat window shows a formatted assistant message. `ui.markdown`
106
+ * resolves once the document is ready (here without downloading images);
107
+ * the reference goes into the `body` field of a row, whose Slint type is
108
+ * `[MarkdownBlock]`, and the player parses and draws it.
109
+ * ```ts
110
+ * const chat = plugin.windows.create("ui/chat.slint");
111
+ * const body = await plugin.ui.markdown("**Hello**", { remoteImages: false });
112
+ * chat.set({ messages: [{ id: "m1", role: "assistant", body }] });
113
+ * ```
114
+ *
115
+ * @player 0.2.0; nested in a value: the player after 0.4.0
116
+ * @see {@link Ui.markdown}, {@link MarkdownOptions}, {@link PropValue}
117
+ * @since 1.1.0
118
+ * @category UI
119
+ */
120
+ export interface MarkdownRef {
121
+ /** The Markdown text, as given to {@link Ui.markdown}. */
122
+ readonly text: string;
123
+ /** Brand that marks the value as a Markdown document; never construct one yourself. */
124
+ readonly __vestraMarkdown: true;
125
+ }
126
+ /**
127
+ * Options of {@link Ui.markdown}: where relative links and images point, and
128
+ * whether remote images are downloaded.
129
+ *
130
+ * @since 1.1.0
131
+ * @category UI
132
+ */
133
+ export interface MarkdownOptions {
134
+ /**
135
+ * What relative links and images resolve against: an `http:` or `https:`
136
+ * address (such as the document's own URL) or an absolute directory.
137
+ * Without it, relative links are reported as written and relative images
138
+ * show their alt text.
139
+ */
140
+ base?: string;
141
+ /**
142
+ * Download `https:` images into the data directory. Off: they show their
143
+ * alt text, and the call makes no network requests.
144
+ *
145
+ * @defaultValue `true`
146
+ */
147
+ remoteImages?: boolean;
148
+ }
149
+ /**
150
+ * The value of one Slint property: JSON with Markdown documents and images
151
+ * at any depth ({@link PropData}).
152
+ *
153
+ * @remarks
154
+ * JSON becomes Slint values as you would expect: booleans for `bool`,
155
+ * finite numbers for `int` and `float`, strings for `string`, arrays for
156
+ * models (`[T]`), objects for structs. Struct field names are passed
157
+ * unchanged, so write them as the Slint file spells them; a name with `_`
158
+ * is refused (Slint treats `_` and `-` as the same, so use camelCase or
159
+ * kebab-case).
160
+ *
161
+ * A {@link Text} or {@link TextList} goes where the Slint type is `string`,
162
+ * at any depth (SDK 1.5.11, player 0.4.3): the player shows it translated
163
+ * with the plugin's catalog, so a `[string]` model (a ComboBox) can mix
164
+ * words and data. The limits below count it as the string it becomes.
165
+ *
166
+ * A {@link MarkdownRef} goes where the Slint type is `[MarkdownBlock]`: the
167
+ * whole value, or a field at any depth (SDK 1.5.4; older players refuse a
168
+ * nested one). An {@link ImageRef} goes where the Slint type is `image`: the
169
+ * whole value, or a field at any depth (SDK 1.5.19, player 0.5.1; older
170
+ * players refuse a nested one with `invalid`). The images nested in the
171
+ * values of one view (a window, panel or settings page) may show at most
172
+ * 32 MB of decoded pixels together (`IMAGE_LIMITS.viewBytes` in
173
+ * `@vestra-player/sdk/runtime`): a write
174
+ * that would pass it is refused with `limit`; use
175
+ * {@link ImageOptions.maxSide} for small pictures such as logos and
176
+ * thumbnails.
177
+ *
178
+ * Limits per value (`UI_VALUE_LIMITS` in `@vestra-player/sdk/testing`,
179
+ * player 0.6.0; players 0.4.3 to 0.5: 16384 values, 4096 rows, 1 MiB of
180
+ * text): nesting depth 8, 1,048,576 values in total (every array, object,
181
+ * string, number, boolean and null counts, the value itself included; a
182
+ * document or an image is one), 100,000 rows per array, 64 KiB per string
183
+ * or field name and 32 MiB of text in total, field names and the text of
184
+ * its Markdown documents included (256 KB per document). A list of rows
185
+ * with 13 fields is 14 values per row, so 50,000 such rows fit. An array
186
+ * property larger than one 1 MiB request is sent in parts (SDK 1.5.46, a
187
+ * player that takes row patches); only the top-level array is split, so
188
+ * any other value, and each row, must fit in one request (a row of more
189
+ * than 512 KiB is refused with `limit`). A value over a limit is refused
190
+ * with code
191
+ * `limit` and the property keeps what it showed (see {@link View.set});
192
+ * `TestHost` refuses it the same way.
193
+ *
194
+ * Bind a whole list and draw it with a Slint `ListView`, which builds only
195
+ * the rows on screen; the SDK sends what changed (row patches).
196
+ *
197
+ * @since 1.0.0
198
+ * @category UI
199
+ */
200
+ export type PropValue = PropData | ImageRef;
201
+ /**
202
+ * JSON whose values may also be Markdown documents and (SDK 1.5.19) images,
203
+ * at any depth: the part of {@link PropValue} that nests.
204
+ *
205
+ * @example Type a message list whose rows carry a document
206
+ * A property value for a chat's message list, typed so that TypeScript
207
+ * accepts a Markdown document inside each row. `PropData` is the JSON a
208
+ * property takes plus documents and images at any depth; the player turns
209
+ * each object into a Slint struct by its field names.
210
+ * ```ts
211
+ * const messages: PropData = [
212
+ * { id: "m1", role: "user", body: await plugin.ui.markdown("Hi") },
213
+ * ];
214
+ * ```
215
+ *
216
+ * @since 1.5.4
217
+ * @category UI
218
+ */
219
+ export type PropData = null | boolean | number | string | MarkdownRef | ImageRef | Text | TextList | PropData[] | {
220
+ [key: string]: PropData;
221
+ };
222
+ /**
223
+ * Properties to write to a view, by name.
224
+ *
225
+ * @remarks
226
+ * Names may be camelCase: the SDK turns every capital letter into `-` plus
227
+ * the lower-case letter (`canMark` → `can-mark`); names already in
228
+ * kebab-case are kept. Only the property names are converted, not the
229
+ * fields of struct values.
230
+ *
231
+ * @example Prepare a window's initial properties
232
+ * An object of property values by name, as `windows.create` and
233
+ * `View.set` take them. Names match the Slint file (`canMark` for
234
+ * `can-mark`), and each value becomes the Slint type of its property: a
235
+ * boolean, and an array of structs for a model.
236
+ * ```ts
237
+ * const props: Props = { canMark: true, rows: [{ rowId: "a", title: "First" }] };
238
+ * ```
239
+ *
240
+ * @since 1.0.0
241
+ * @category UI
242
+ */
243
+ export type Props = Record<string, PropValue>;
244
+ /**
245
+ * Values for Slint properties that are not plain JSON: images from files and
246
+ * Markdown documents. `plugin.ui`.
247
+ *
248
+ * @remarks
249
+ * A Slint file can only name images compiled into it (`@image-url`). To show
250
+ * an image the plugin picks at run time (cover art, a thumbnail it rendered,
251
+ * a downloaded icon), make an {@link ImageRef} with {@link Ui.image} and
252
+ * write it to an `image` property. To show formatted text, make a
253
+ * {@link MarkdownRef} with {@link Ui.markdown} and give it to `MarkdownView`.
254
+ * Both work in tool windows, panels (the backdrop and the floating sidebar
255
+ * included) and settings pages.
256
+ *
257
+ * @capability None.
258
+ *
259
+ * @example Show a Markdown file in a window (examples/markdown)
260
+ * A menu item opens a window with a formatted Markdown file that ships
261
+ * with the plugin. The plugin reads the file, turns it into a document
262
+ * with `ui.markdown` (relative images resolve against the plugin's
263
+ * directory through `base`) and writes it to the window's `doc` property,
264
+ * which the Slint file hands to `MarkdownView`.
265
+ *
266
+ * {@includeCode ../../../examples/markdown/main.ts#document}
267
+ *
268
+ * `ui/document.slint`:
269
+ *
270
+ * {@includeCode ../../../examples/markdown/ui/document.slint}
271
+ *
272
+ * @see {@link ImageRef}, {@link MarkdownRef}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md)
273
+ * @since 1.0.0
274
+ * @category UI
275
+ */
276
+ export interface Ui {
277
+ /**
278
+ * Reference a PNG or JPEG file for an `image` property.
279
+ *
280
+ * @remarks
281
+ * Returns at once without touching the file. The player checks the file
282
+ * each time it receives the reference (a property write, a window or
283
+ * settings page opening, the main window being rebuilt): it must be inside this plugin's package
284
+ * directory or {@link Plugin.dataDirectory} after following links, at most
285
+ * 16 MB and 4096×4096 pixels, and PNG or JPEG by content (the extension
286
+ * does not matter). A failed check of a whole-value image is a failed
287
+ * property write: `missing` for a file that does not exist, `invalid`
288
+ * otherwise. It goes to {@link Scope.onError} and the property keeps its
289
+ * previous image; in the initial properties of a tool window it makes
290
+ * {@link Window.show} reject. A nested image (a field of a row, SDK
291
+ * 1.5.19) that fails its check is drawn empty instead, and the rest of
292
+ * the value is shown, as a Markdown image shows its alt text.
293
+ *
294
+ * The player caches decoded images per plugin (up to 64 MB, least recently
295
+ * used first) by path, size and modification time, and does not watch
296
+ * files. After rewriting a file under the same path, call `image()` again
297
+ * and write the new reference: the SDK does not send a value that did not
298
+ * change, so the player would not look at the file again.
299
+ *
300
+ * @capability None.
301
+ *
302
+ * @param path - Absolute path of the image file, inside the package
303
+ * directory or the data directory.
304
+ * @param options - `maxSide` (SDK 1.5.19, player 0.5.1): decode the image
305
+ * scaled down, aspect kept, so that neither side is over it.
306
+ * @returns A new {@link ImageRef}, owned by this scope.
307
+ *
308
+ * @throws `invalid` (throws) `path` is not a non-empty string, or
309
+ * `maxSide` is not an integer 1–4096.
310
+ *
311
+ * @example Show a thumbnail the plugin rendered
312
+ * A window shows a PNG the plugin wrote into its data directory. The file
313
+ * must be inside the package or data directory; `image` returns at once.
314
+ * The player decodes the file when it receives the value and notices a
315
+ * rewritten file by its size and modification time; the plugin still
316
+ * calls `image()` again after rewriting it, because the SDK does not send
317
+ * a value that did not change.
318
+ * ```ts
319
+ * const thumbnailWindow = plugin.windows.create("ui/thumbnail.slint");
320
+ * const file = `${plugin.dataDirectory}/thumbnail.png`;
321
+ * // … write the PNG to `file` (for example with plugin.tools.run("ffmpeg", …)) …
322
+ * thumbnailWindow.set({ thumbnail: plugin.ui.image(file) });
323
+ * await thumbnailWindow.show();
324
+ * ```
325
+ *
326
+ * @since 1.0.0
327
+ */
328
+ image(path: string, options?: ImageOptions): ImageRef;
329
+ /**
330
+ * Download an `https:` PNG or JPEG image (a thumbnail, a repository's
331
+ * plugin icon) and reference the local copy, as {@link Ui.image} does.
332
+ *
333
+ * @remarks
334
+ * Downloads like {@link Ui.markdown}'s remote images: Node's `fetch` in
335
+ * this plugin's process, at most 4 MB and 10 s per image, 4 downloads at a
336
+ * time per plugin, into `<dataDirectory>/.vestra-cache/images/`; the cache
337
+ * keeps 32 MB and fetches an address again after 24 hours, so a list that
338
+ * shows the same thumbnails again reads them from disk.
339
+ *
340
+ * @capability None (the plugin process has network access).
341
+ * @player Any (the reference is an ordinary {@link ImageRef}); nested in a
342
+ * value, player 0.5.1.
343
+ *
344
+ * @param url - The image's `https:` address.
345
+ * @param options - As for {@link Ui.image}.
346
+ * @returns The reference, owned by this scope, once the file is in the
347
+ * cache.
348
+ *
349
+ * @throws `invalid` (rejects) `url` is not an `https:` address, or
350
+ * `maxSide` is not an integer 1–4096.
351
+ * @throws `unavailable` (rejects) the download failed, timed out, was too
352
+ * large, or is not a PNG or JPEG image; or the plugin has no data
353
+ * directory.
354
+ *
355
+ * @example Show search results with downloaded thumbnails
356
+ * A results window lists each hit with its thumbnail, or a placeholder
357
+ * when a thumbnail cannot be fetched. `remoteImage` downloads the image
358
+ * in the plugin's process into the data directory's cache (at most 4 at a
359
+ * time) and resolves with a local reference; a failed download rejects
360
+ * with `unavailable`, which the `catch` turns into the placeholder.
361
+ * ```ts
362
+ * const results = [{ title: "A", thumbnailUrl: "https://example.com/a.jpg" }];
363
+ * const placeholder = plugin.ui.image(`${plugin.dataDirectory}/blank.png`);
364
+ * const rows = await Promise.all(
365
+ * results.map(async (r) => ({
366
+ * title: r.title,
367
+ * thumb: await plugin.ui
368
+ * .remoteImage(r.thumbnailUrl, { maxSide: 320 })
369
+ * .catch(() => placeholder), // `unavailable`: download failed
370
+ * })),
371
+ * );
372
+ * plugin.windows.create("ui/results.slint").set({ rows });
373
+ * ```
374
+ *
375
+ * @since 1.5.19
376
+ */
377
+ remoteImage(url: string, options?: ImageOptions): Promise<ImageRef>;
378
+ /**
379
+ * Prepare a Markdown document for `MarkdownView` (`@vestra/markdown.slint`).
380
+ *
381
+ * @remarks
382
+ * The player renders headings, paragraphs (bold, italic, strikethrough,
383
+ * inline code, links), lists and task lists, code blocks, block quotes,
384
+ * images, tables and rules; embedded HTML is not shown. A click on a link
385
+ * calls the view's `link-clicked(url)` callback with the address resolved
386
+ * against `base`; opening it is up to the plugin (for example with
387
+ * {@link System.openUrl}).
388
+ *
389
+ * Images: PNG or JPEG. Local ones follow {@link Ui.image}'s rules (this
390
+ * plugin's package or data directory). `https:` images are downloaded by
391
+ * this call into `<dataDirectory>/.vestra-cache/markdown/` (each at most
392
+ * 4 MB and 10 s, at most 64 per document; the cache keeps 32 MB and fetches
393
+ * an address again after 24 hours). A failed or unsupported image (SVG,
394
+ * GIF, `http:`…) shows its alt text; the call itself does not fail for it.
395
+ *
396
+ * The text is at most 256 KB; very long documents are cut off after 4000
397
+ * blocks.
398
+ *
399
+ * `MarkdownView` scrolls one document. `MarkdownBlocks` (SDK 1.5.4, players
400
+ * after 0.4.0) draws one without scrolling, as tall as its content, for a
401
+ * layout of your own or a `ListView` row. For a list of documents, write
402
+ * the whole list with one document per row: the player parses only the
403
+ * documents that changed and updates the list in place (rows added or
404
+ * removed at the end, a growing document's changed blocks), so re-sending
405
+ * the list on every streamed chunk keeps the scroll position and costs
406
+ * little.
407
+ *
408
+ * From player 0.7.1 both views take `selectable: true` (default `false`):
409
+ * the user can select and copy the text, one block at a time; blocks with
410
+ * links keep their clickable links and copy as `text (url)`. Code blocks
411
+ * are always selectable. `MarkdownBlock.plain` (the block as plain text)
412
+ * and `MarkdownBlock.links` (its link addresses) are readable in Slint.
413
+ * See [Reference: theme › Markdown](../../../docs/reference/theme.md#markdown).
414
+ *
415
+ * @capability None.
416
+ * @player 0.2.0 (set `"minPlayerVersion": "0.2.0"` in the manifest)
417
+ *
418
+ * @param text - The Markdown source (CommonMark with GitHub tables, task
419
+ * lists and strikethrough), at most 256 KB as UTF-8.
420
+ * @param options - Where relative addresses point and whether to download
421
+ * remote images.
422
+ * @returns The document, owned by this scope, once its remote images are
423
+ * downloaded (or have failed).
424
+ *
425
+ * @throws `invalid` (rejects) `text` is not a string or is over 256 KB, or
426
+ * `base` is neither an `http(s):` address nor an absolute path.
427
+ * @throws `unsupported` (rejects) The player is older than 0.2.0.
428
+ *
429
+ * @example Build a chat with one Markdown document per row
430
+ * A chat window lists messages as formatted text, with a Copy button on
431
+ * each code block that puts the code on the clipboard. Each row's `body`
432
+ * is a document from `ui.markdown`; the whole list is written again on
433
+ * each change, and the player parses only the documents that changed.
434
+ * `MarkdownBlocks` with `code-copy` calls `copy-code`, which the plugin
435
+ * handles with `on("copyCode")`.
436
+ *
437
+ * `ui/chat.slint`:
438
+ *
439
+ * ```slint
440
+ * import { ListView } from "std-widgets.slint";
441
+ * import { MarkdownBlocks, MarkdownBlock } from "@vestra/markdown.slint";
442
+ * export struct Message { id: string, role: string, body: [MarkdownBlock] }
443
+ * export component Chat inherits Window {
444
+ * in property <[Message]> messages;
445
+ * callback copy-code(string);
446
+ * ListView {
447
+ * for message in root.messages: VerticalLayout {
448
+ * padding: 8px;
449
+ * MarkdownBlocks {
450
+ * blocks: message.body;
451
+ * code-copy: true;
452
+ * copy-code(code) => { root.copy-code(code); }
453
+ * }
454
+ * }
455
+ * }
456
+ * }
457
+ * ```
458
+ *
459
+ * ```ts
460
+ * const chat = plugin.windows.create("ui/chat.slint");
461
+ * const history: { id: string; role: string; text: string }[] = [];
462
+ * chat.on("copyCode", (code: string) => plugin.clipboard.writeText(code));
463
+ * // Re-send the whole list: unchanged documents cost the player nothing.
464
+ * async function render() {
465
+ * const messages = [];
466
+ * for (const { id, role, text } of history)
467
+ * messages.push({ id, role, body: await plugin.ui.markdown(text) });
468
+ * chat.set({ messages });
469
+ * }
470
+ * history.push({ id: "1", role: "user", text: "Show me `ls`." });
471
+ * await render();
472
+ * await chat.show();
473
+ * ```
474
+ *
475
+ * @example Show a README from the web
476
+ * A window shows a README downloaded from the web, its images included,
477
+ * and clicked links open in the browser. `base` makes relative links and
478
+ * images resolve against the README's address; `markdown` resolves after
479
+ * its `https:` images are downloaded. A click on a link makes
480
+ * `MarkdownView` call `link-clicked`, which `ui/readme.slint` forwards as
481
+ * `open-link`; the plugin opens the address with `openUrl`.
482
+ * ```ts
483
+ * const readmeUrl = "https://example.com/plugin/README.md";
484
+ * const response = await fetch(readmeUrl);
485
+ * if (!response.ok) throw new Error(`README: HTTP ${response.status}`);
486
+ * const text = await response.text();
487
+ * const readmeWindow = plugin.windows.create("ui/readme.slint");
488
+ * // Bound before the first `show`, as a tool window requires.
489
+ * readmeWindow.on("openLink", (url: string) => plugin.system.openUrl(url));
490
+ * readmeWindow.set({ doc: await plugin.ui.markdown(text, { base: readmeUrl }) });
491
+ * await readmeWindow.show();
492
+ * ```
493
+ *
494
+ * @since 1.1.0
495
+ */
496
+ markdown(text: string, options?: MarkdownOptions): Promise<MarkdownRef>;
497
+ }
498
+ /**
499
+ * The surface that tool windows, panels and settings pages share: properties
500
+ * out to Slint, callbacks in from Slint.
501
+ *
502
+ * @remarks
503
+ * The plugin's TypeScript and its Slint files run in different processes and
504
+ * exchange two kinds of messages. Plugin → UI: `in` and `in-out` properties,
505
+ * written with {@link View.set} or kept up to date with {@link View.bind}.
506
+ * UI → plugin: Slint callbacks (returning nothing), handled with
507
+ * {@link View.on}. A {@link Window} declares them on its exported component;
508
+ * a {@link Panel} and a {@link SettingsPage} declare them on the file's
509
+ * exported global, the bridge. The plugin cannot call Slint functions or read
510
+ * a property back: a value the user changes reaches it only through a
511
+ * callback.
512
+ *
513
+ * `bind` is the usual way: the SDK re-evaluates bound functions in every
514
+ * full update pass (after each handler it calls, on {@link Scope.update}),
515
+ * and after a player state change those that read a changed field of
516
+ * `plugin.player.state`, and sends only what changed, at most one write in
517
+ * flight per view. `set` sends now, even an unchanged value.
518
+ *
519
+ * Writes that fail (a name the Slint file does not declare, a value of the
520
+ * wrong type, an image that fails its check): a bound value is not sent
521
+ * again until it changes; a `set` value is retried with back-off (0.25 s,
522
+ * doubling up to 30 s); the first failure of a series is reported to
523
+ * {@link Scope.onError}.
524
+ *
525
+ * A control whose value both the user and the plugin change needs a two-way
526
+ * binding to an `in-out` property (`value <=> root.level`). A one-way
527
+ * binding (`value: root.level`) is broken by Slint the first time the user
528
+ * moves the control.
529
+ *
530
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
531
+ *
532
+ * @example Wire a window's label and buttons to the plugin (examples/bookmark)
533
+ * A Bookmark window shows the saved position and two buttons that save
534
+ * it and jump back to it. `bind` keeps the label and the buttons' enabled
535
+ * state equal to the plugin's state: the SDK evaluates the function again
536
+ * after every handler and player change and sends only what changed. The
537
+ * buttons' Slint callbacks reach the plugin through `on`.
538
+ *
539
+ * {@includeCode ../../../examples/bookmark/main.ts#window}
540
+ *
541
+ * `ui/bookmark.slint`:
542
+ *
543
+ * {@includeCode ../../../examples/bookmark/ui/bookmark.slint}
544
+ *
545
+ * @see {@link Window}, {@link Panel}, {@link SettingsPage}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md), [Keep a slider responsive while dragging](../../../docs/how-to/slider.md)
546
+ * @since 1.0.0
547
+ * @category UI
548
+ */
549
+ export interface View {
550
+ /**
551
+ * Handle a Slint callback.
552
+ *
553
+ * @remarks
554
+ * The handler receives the callback's arguments as JSON (struct fields
555
+ * spelled as in Slint). It may be async. An error it throws, or a rejection
556
+ * of its promise, goes to {@link Scope.onError}. After it returns, and
557
+ * again when its promise settles, the SDK runs an update pass, so state it
558
+ * changed reaches bound properties without further calls (state changed
559
+ * after an `await` appears only when the promise settles; call
560
+ * {@link Scope.update} to show it earlier).
561
+ *
562
+ * Calling `on` again with the same name replaces the handler. A callback
563
+ * the plugin has no handler for is ignored.
564
+ *
565
+ * **Tool windows** forward only the callback names bound when the window
566
+ * opens: bind every name before the first {@link Window.show}. While the
567
+ * window is open, binding a new name throws; after a close the next `show`
568
+ * registers the names bound by then. A name the Slint file does not declare
569
+ * makes `show` reject. **Panels and settings pages** forward every
570
+ * callback of their bridge global, so bind whenever you like.
571
+ *
572
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
573
+ *
574
+ * @param callback - The Slint callback's name, in camelCase
575
+ * (`toggleEffect`) or as written in Slint (`toggle-effect`).
576
+ * @param handler - Receives the callback's arguments.
577
+ * @returns A handle that removes this handler (if it is still the current
578
+ * one for the name).
579
+ *
580
+ * @throws `Error` without a code (throws) On an open {@link Window}, for a
581
+ * name that has no handler yet.
582
+ *
583
+ * @example Keep a slider and the plugin's value in step
584
+ * Moving the window's brightness slider updates the plugin's value, and
585
+ * the slider shows it back. The Slint callback `brightness-changed`
586
+ * reaches the handler with the slider's value as JSON; after the handler
587
+ * returns, the SDK runs an update pass and `bind` sends the new value.
588
+ * Callbacks of a tool window must be bound before its first `show`.
589
+ * ```ts
590
+ * const picture = plugin.windows.create("ui/picture.slint");
591
+ * let brightness = 0;
592
+ * // camelCase here, `brightness-changed` in the Slint file.
593
+ * picture.on("brightnessChanged", (value: number) => {
594
+ * brightness = value;
595
+ * });
596
+ * picture.bind(() => ({ brightness }));
597
+ * await picture.show();
598
+ * ```
599
+ *
600
+ * @since 1.0.0
601
+ */
602
+ on<A extends Json[]>(callback: string, handler: (...args: A) => unknown): Disposable;
603
+ /**
604
+ * Write properties now, even values that did not change.
605
+ *
606
+ * @remarks
607
+ * Each value given is sent once with the next write, even if it equals the
608
+ * last value sent. That makes `set` the way to pull a control back to the
609
+ * model value after the user moved it, or to put a one-off value (a
610
+ * document, an image) on screen. While the view is not open (a window
611
+ * before `show`, a panel before `ready`) the values are kept and become its
612
+ * initial properties.
613
+ *
614
+ * Do not `set` a property that a {@link View.bind} function also returns:
615
+ * the next update pass replaces the set value with the bound one.
616
+ *
617
+ * Never throws. A write that fails is retried with back-off and reported
618
+ * to {@link Scope.onError} (the first failure of a run of failures; the
619
+ * message names the property). A value over the limits of
620
+ * {@link PropValue} fails with `limit`. As an initial property (written
621
+ * while the view is not open) it makes {@link Window.show} reject; a
622
+ * panel or settings page still opens without it (the property keeps its
623
+ * default) and the failure goes to the plugin's `onError` (player 0.4.3;
624
+ * older players left it out silently).
625
+ *
626
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
627
+ *
628
+ * @param props - Properties by name; see {@link Props}.
629
+ *
630
+ * @example Put a drop-down back when the user picks an entry the plugin refuses
631
+ * Choosing "Custom" snaps the drop-down back to the last real preset.
632
+ * The plugin cannot read a property back, only hear the callback; `set`
633
+ * sends the value even though it equals the one sent before, which is
634
+ * what pulls a control the user moved back to the plugin's value.
635
+ * ```ts
636
+ * const presetsWindow = plugin.windows.create("ui/presets.slint");
637
+ * let presetIndex = 0;
638
+ * presetsWindow.on("presetChosen", (index: number) => {
639
+ * if (index > 2) presetsWindow.set({ presetIndex }); // "Custom" is not a preset
640
+ * else presetIndex = index;
641
+ * });
642
+ * ```
643
+ *
644
+ * @since 1.0.0
645
+ */
646
+ set(props: Props): void;
647
+ /**
648
+ * Keep properties equal to a function of the plugin's state.
649
+ *
650
+ * @remarks
651
+ * The SDK calls `props` in every update pass (and right after `bind`) and
652
+ * sends the values that differ from the ones it sent last. After a change
653
+ * of the player state alone it calls `props` only if it read a field of
654
+ * `plugin.player.state` that changed (SDK 1.5.45); a full pass follows
655
+ * after each handler, on {@link Scope.update} and at least once a second
656
+ * while the player state keeps changing. Because an
657
+ * unchanged value is not sent again, text the user typed into an `in-out`
658
+ * property stays until the plugin's value for it changes.
659
+ *
660
+ * Keep the function quick and synchronous: it runs often. An error it
661
+ * throws is reported to {@link Scope.onError} and the other bindings still
662
+ * run. A view can have several bindings; when two return the same name,
663
+ * the one bound later wins.
664
+ *
665
+ * Never throws. Writes that fail are not repeated until the value
666
+ * changes, and are reported to {@link Scope.onError} like a failed
667
+ * {@link View.set} (a value over the limits of {@link PropValue}: `limit`).
668
+ *
669
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
670
+ *
671
+ * @param props - Returns the properties, by name.
672
+ * @returns A handle that stops this binding (the values last sent stay).
673
+ *
674
+ * @example Show what is playing and whether it can seek
675
+ * The status window always shows the current file and enables its seek
676
+ * controls only for seekable sources. The SDK calls the function right
677
+ * away, again in every full update pass (after each handler) and after
678
+ * each change of `source` or `can`, and sends only the values that
679
+ * changed.
680
+ * ```ts
681
+ * const status = plugin.windows.create("ui/status.slint");
682
+ * status.bind(() => ({
683
+ * title: plugin.player.state.source ?? "Nothing playing",
684
+ * canSeek: plugin.player.state.can.seek,
685
+ * }));
686
+ * ```
687
+ *
688
+ * @see [Keep a slider responsive while dragging](../../../docs/how-to/slider.md)
689
+ * @since 1.0.0
690
+ */
691
+ bind(props: () => Props): Disposable;
692
+ }