@vestra-player/sdk 1.9.0 → 1.10.1

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 (53) hide show
  1. package/CHANGELOG.md +44 -7
  2. package/bin/vestra-plugin.mjs +89 -8
  3. package/capability-scan.json +20 -0
  4. package/dist/api-requests.d.ts +4 -3
  5. package/dist/api-requests.js +11 -3
  6. package/dist/commands.js +1 -0
  7. package/dist/condition-table.d.ts +1889 -0
  8. package/dist/condition-table.js +562 -0
  9. package/dist/docs-tree.json.gz +0 -0
  10. package/dist/i18n-tools.d.ts +7 -0
  11. package/dist/i18n-tools.js +66 -3
  12. package/dist/player-runtime.d.ts +3 -0
  13. package/dist/player-runtime.js +3 -0
  14. package/dist/plugin/connection.d.ts +13 -2
  15. package/dist/plugin/connection.js +67 -4
  16. package/dist/plugin/index.d.ts +7 -0
  17. package/dist/plugin/index.js +13 -0
  18. package/dist/plugin/mpv.js +39 -5
  19. package/dist/plugin/player/events.d.ts +14 -5
  20. package/dist/plugin/player/events.js +19 -3
  21. package/dist/plugin/player.d.ts +16 -0
  22. package/dist/plugin/player.js +77 -1
  23. package/dist/plugin/scope.d.ts +4 -1
  24. package/dist/plugin/scope.js +8 -0
  25. package/dist/plugin/testing/commands.d.ts +5 -0
  26. package/dist/plugin/testing/commands.js +23 -24
  27. package/dist/plugin/testing/index.d.ts +134 -0
  28. package/dist/plugin/testing/index.js +180 -21
  29. package/dist/plugin/testing/media.d.ts +6 -0
  30. package/dist/plugin/testing/media.js +15 -2
  31. package/dist/plugin/testing/services.js +50 -1
  32. package/dist/plugin/testing/source-events.d.ts +28 -0
  33. package/dist/plugin/testing/source-events.js +66 -0
  34. package/dist/plugin/testing/transport.js +5 -0
  35. package/dist/plugin/testing/triggers.d.ts +82 -0
  36. package/dist/plugin/testing/triggers.js +448 -0
  37. package/dist/plugin/timeline.d.ts +3 -3
  38. package/dist/plugin/timeline.js +3 -3
  39. package/dist/plugin/triggers.d.ts +55 -0
  40. package/dist/plugin/triggers.js +233 -0
  41. package/dist/plugin/types/base.d.ts +117 -3
  42. package/dist/plugin/types/commands.d.ts +374 -1
  43. package/dist/plugin/types/packages.d.ts +10 -1
  44. package/dist/plugin/types/playback.d.ts +257 -9
  45. package/dist/plugin/types/services.d.ts +10 -4
  46. package/dist/plugin/when.d.ts +78 -4
  47. package/dist/plugin/when.js +182 -14
  48. package/dist/slint-version.d.ts +7 -0
  49. package/dist/slint-version.js +7 -0
  50. package/dist/wire.d.ts +18 -0
  51. package/dist/wire.js +12 -0
  52. package/llms.txt +4 -4
  53. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import type { Scope } from "./base.ts";
2
- import type { Player } from "./playback.ts";
2
+ import type { AudioTrack, Player, TimelineLayer } from "./playback.ts";
3
3
  import type { Ui, View } from "./ui-content.ts";
4
4
  import type { Disposable } from "./base.ts";
5
5
  import type { PlayerState } from "./playback.ts";
@@ -252,6 +252,379 @@ export interface When {
252
252
  * @since 1.5.40
253
253
  */
254
254
  language(language: LanguagePreference): Condition;
255
+ /**
256
+ * The source is muted (`PlayerState.muted`).
257
+ *
258
+ * @since 1.10.0
259
+ */
260
+ readonly muted: Condition;
261
+ /**
262
+ * The main window is maximized (`MainWindowState.maximized`).
263
+ *
264
+ * @since 1.10.0
265
+ */
266
+ readonly maximized: Condition;
267
+ /**
268
+ * The video shows in the picture-in-picture window.
269
+ *
270
+ * @since 1.10.0
271
+ */
272
+ readonly pip: Condition;
273
+ /**
274
+ * An A-B loop is set (`PlayerState.loop` is not `null`).
275
+ *
276
+ * @since 1.10.0
277
+ */
278
+ readonly looping: Condition;
279
+ /**
280
+ * The source's duration in seconds is within `min ≤ duration < max`
281
+ * (at least one bound); false while it is unknown.
282
+ *
283
+ * @throws `TypeError` (throws) No bound, a bound that is not a finite
284
+ * number, or `min ≥ max`.
285
+ *
286
+ * @example Only for files longer than ten minutes
287
+ * The condition holds once the player knows the file lasts 600 seconds
288
+ * or more; with no `max` the range is open upwards.
289
+ * ```ts
290
+ * const { when } = plugin;
291
+ * const long = when.duration({ min: 600 });
292
+ * ```
293
+ *
294
+ * @since 1.10.0
295
+ */
296
+ duration(bounds: {
297
+ min?: number;
298
+ max?: number;
299
+ }): Condition;
300
+ /**
301
+ * The volume (0–200) is within `min ≤ volume < max`.
302
+ *
303
+ * @throws `TypeError` (throws) As {@link When.duration}.
304
+ *
305
+ * @example Check a Boost item above full volume
306
+ * The item carries a check mark while the volume is above 100, whoever
307
+ * raised it; the player compares its own volume, so the plugin need
308
+ * not follow the state.
309
+ * ```ts
310
+ * const { when } = plugin;
311
+ * const boosted = when.volume({ min: 101 });
312
+ * ```
313
+ *
314
+ * @since 1.10.0
315
+ */
316
+ volume(bounds: {
317
+ min?: number;
318
+ max?: number;
319
+ }): Condition;
320
+ /**
321
+ * The playback rate is within `min ≤ rate < max`.
322
+ *
323
+ * @throws `TypeError` (throws) As {@link When.duration}.
324
+ *
325
+ * @example Enable Normal Speed only when sped up
326
+ * The item is greyed out at normal speed or slower: the condition holds
327
+ * from a rate of just over 1 upwards.
328
+ * ```ts
329
+ * const { when } = plugin;
330
+ * const fast = when.rate({ min: 1.01 });
331
+ * ```
332
+ *
333
+ * @since 1.10.0
334
+ */
335
+ rate(bounds: {
336
+ min?: number;
337
+ max?: number;
338
+ }): Condition;
339
+ /**
340
+ * The wall clock (Unix milliseconds, as `Date.now()`) is within
341
+ * `min ≤ now < max`. For a trigger only (`plugin.trigger().firesOn`): a
342
+ * command's state refuses it.
343
+ *
344
+ * @throws `TypeError` (throws) As {@link When.duration}.
345
+ *
346
+ * @example The clock is at or past 45 minutes from now
347
+ * The bound is computed once, when the condition is made, so the
348
+ * condition turns true 45 minutes later and stays true.
349
+ * ```ts
350
+ * const { when } = plugin;
351
+ * const due = when.time({ min: Date.now() + 45 * 60_000 });
352
+ * ```
353
+ *
354
+ * @since 1.10.0
355
+ */
356
+ time(bounds: {
357
+ min?: number;
358
+ max?: number;
359
+ }): Condition;
360
+ /**
361
+ * The selected audio track is `id` ({@link AudioTrack.id}).
362
+ *
363
+ * @throws `TypeError` (throws) `id` is not an integer.
364
+ *
365
+ * @example Check the item of each audio track
366
+ * One menu item per track of the file carries a check mark while that
367
+ * track plays, also when the user picks it in the player's own menu.
368
+ * ```ts
369
+ * const { when, player } = plugin;
370
+ * for (const track of player.state.audioTracks ?? [])
371
+ * plugin.commands.add({
372
+ * id: `audio-${track.id}`,
373
+ * path: ["@audio", "Track", track.title ?? `Track ${track.id}`],
374
+ * radio: true,
375
+ * checked: when.audioTrack(track.id), // the player keeps the mark current
376
+ * run: () => player.selectAudioTrack(track.id),
377
+ * });
378
+ * ```
379
+ *
380
+ * @since 1.10.0
381
+ */
382
+ audioTrack(id: number): Condition;
383
+ /**
384
+ * The primary subtitle track is `id` (`SubtitleTrack.id`).
385
+ *
386
+ * @throws `TypeError` (throws) `id` is not a string of 1–256 characters.
387
+ *
388
+ * @example Check the item of a subtitle track
389
+ * The item carries a check mark while the track with this id is the
390
+ * primary subtitle, whoever selected it.
391
+ * ```ts
392
+ * declare const trackId: string;
393
+ * // ---cut---
394
+ * const { when } = plugin;
395
+ * const shown = when.subtitleTrack(trackId);
396
+ * ```
397
+ *
398
+ * @since 1.10.0
399
+ */
400
+ subtitleTrack(id: string): Condition;
401
+ /**
402
+ * The active audio output device is `id` (`PlayerState.audioOutput.active`).
403
+ *
404
+ * @throws `TypeError` (throws) `id` is not a string of 1–256 characters.
405
+ *
406
+ * @example Check the item of the active output device
407
+ * One menu item per output device carries a check mark while the
408
+ * player plays through it; the player compares its own active device.
409
+ * ```ts
410
+ * const { when, player } = plugin;
411
+ * for (const device of await player.audioDevices())
412
+ * plugin.commands.add({
413
+ * id: `out-${device.id}`,
414
+ * path: ["@audio", "Output", device.name],
415
+ * radio: true,
416
+ * checked: when.audioDevice(device.id), // no state read in the plugin
417
+ * run: () => player.setAudioDevice(device.id),
418
+ * });
419
+ * ```
420
+ *
421
+ * @since 1.10.0
422
+ */
423
+ audioDevice(id: string): Condition;
424
+ /**
425
+ * The playback position. For a trigger only: a command's state refuses
426
+ * it.
427
+ *
428
+ * @since 1.10.0
429
+ */
430
+ readonly position: {
431
+ /**
432
+ * The position is inside one of `ranges` (`start ≤ position < end`; no
433
+ * `end`: open), or less than `lead` media seconds before a range's
434
+ * start. The player binds the list to the source that is current when
435
+ * it receives it: for any other source this is false. When several
436
+ * ranges hold, the one with the earliest start is the one a trigger's
437
+ * `enter` gets as `range`. At most one position list per condition;
438
+ * it counts as one part however long it is.
439
+ *
440
+ * @param ranges - Objects with `start` and optionally `end` (media
441
+ * seconds); other fields are ignored, so the list given to
442
+ * {@link TimelineLayer.setRanges} fits as it is. At most 1000
443
+ * (`TIMELINE_LIMITS.ranges`).
444
+ * @param options - `lead`: media seconds each range starts earlier,
445
+ * to make up for the time a plugin in standby takes to start.
446
+ * @throws `TypeError` (throws) A start that is not a finite number of
447
+ * 0 or more, an end not after its start, a negative lead.
448
+ * @throws `limit` (throws) More than 1000 ranges.
449
+ *
450
+ * @example Be told 2 s before each silence
451
+ * ```ts
452
+ * declare const spans: { start: number; end: number }[];
453
+ * // ---cut---
454
+ * const { when } = plugin;
455
+ * const near = when.playing.and(when.position.in(spans, { lead: 2 }));
456
+ * ```
457
+ *
458
+ * @since 1.10.0
459
+ */
460
+ in(ranges: Iterable<PositionRange>, options?: {
461
+ lead?: number;
462
+ }): Condition;
463
+ };
464
+ }
465
+ /**
466
+ * A range of media time for {@link When.position}: any object with `start`
467
+ * and, optionally, `end`, in seconds.
468
+ *
469
+ * @since 1.10.0
470
+ * @category Commands
471
+ */
472
+ export interface PositionRange {
473
+ /** Where the range starts, in media seconds (0 or more). */
474
+ readonly start: number;
475
+ /** Where it ends, in media seconds, after `start`; absent or `null`: open. */
476
+ readonly end?: number | null;
477
+ }
478
+ /**
479
+ * What a trigger's `enter` and `leave` get.
480
+ *
481
+ * @since 1.10.0
482
+ * @category Commands
483
+ */
484
+ export interface TriggerEvent {
485
+ /** The player's state at the moment the player saw the condition flip. */
486
+ readonly state: PlayerState;
487
+ /**
488
+ * For a condition with {@link When.position}`.in`, when the position is
489
+ * in one of its ranges: that range as given, and its place in the list
490
+ * the player evaluated. `start` and `end` name the range; `index` is its
491
+ * place in that list: an `enter` that was on its way while the plugin
492
+ * gave a new list holding the same range (the trigger stays entered)
493
+ * carries the place in the old list, and the later `leave` the place in
494
+ * the new one.
495
+ */
496
+ readonly range?: {
497
+ /** The range's start, in media seconds. */
498
+ readonly start: number;
499
+ /** The range's end, in media seconds (`null`: open). */
500
+ readonly end: number | null;
501
+ /** Its place in the list given to `when.position.in`, from 0. */
502
+ readonly index: number;
503
+ };
504
+ }
505
+ /**
506
+ * A trigger (`plugin.trigger()`): a place for one condition the player
507
+ * keeps and evaluates, also while the plugin is in standby, and the
508
+ * functions to call when it becomes true (`enter`) and false (`leave`).
509
+ *
510
+ * @remarks
511
+ * When it flips while the plugin has no process, the player starts the
512
+ * plugin; `activate()` declares the same triggers again and the waiting
513
+ * notification reaches the same trigger. Every method returns the
514
+ * trigger, so the calls chain.
515
+ *
516
+ * @example On top while playing in fullscreen
517
+ * The window stays on top while a file plays in fullscreen and goes back
518
+ * when either ends. The player evaluates the condition itself, so the
519
+ * plugin may be in standby in between.
520
+ * ```ts
521
+ * const { when, window } = plugin;
522
+ * plugin
523
+ * .trigger()
524
+ * // The player keeps this condition and calls back when it flips.
525
+ * .firesOn(when.playing.and(when.fullscreen))
526
+ * .enter(() => window.setAlwaysOnTop(true))
527
+ * .leave(() => window.setAlwaysOnTop(false));
528
+ * ```
529
+ *
530
+ * @since 1.10.0
531
+ * @category Commands
532
+ */
533
+ export interface Trigger {
534
+ /**
535
+ * Hands the player this condition, replacing the one it has (without a
536
+ * `leave` for the old one). A condition already true is entered at once,
537
+ * except a range list given again for the same source while the
538
+ * position is still in the range it was entered with (the same start,
539
+ * end and lead; a list that grew as a scan went on): that range stays
540
+ * entered, with no second `enter`, and an `enter` of it still on its way
541
+ * (a plugin woken for it) reaches `enter` all the same. The same
542
+ * condition again changes nothing. A refusal (`invalid`,
543
+ * `limit`) reaches the plugin's error handlers.
544
+ *
545
+ * @throws `TypeError` (throws) Not a condition from `plugin.when`, or
546
+ * one with two position lists.
547
+ *
548
+ * @example Pause ten seconds before the end
549
+ * A command arms the trigger for the file open now: its condition holds
550
+ * from ten seconds before the end, and `enter` pauses. Pressing it again
551
+ * replaces the condition, without a `leave` for the old one.
552
+ * ```ts
553
+ * const { when, player } = plugin;
554
+ * const nearEnd = plugin.trigger("near-end").enter(() => player.setPaused(true));
555
+ * plugin.commands.add({
556
+ * id: "pause-near-end",
557
+ * path: ["Tools", "Pause Near the End"],
558
+ * run: () => {
559
+ * const duration = player.state.duration;
560
+ * // Bound to the current file: another file never matches it.
561
+ * if (duration !== null)
562
+ * nearEnd.firesOn(when.position.in([{ start: Math.max(0, duration - 10) }]));
563
+ * },
564
+ * });
565
+ * ```
566
+ *
567
+ * @since 1.10.0
568
+ */
569
+ firesOn(condition: Condition): Trigger;
570
+ /**
571
+ * `fn` runs each time the condition turns from false to true. One
572
+ * trigger's functions run one after another: the next waits for the
573
+ * promise of the one before. A second call replaces the function.
574
+ *
575
+ * @throws `TypeError` (throws) `fn` is not a function.
576
+ *
577
+ * @example Show a note as each marked range starts
578
+ * The OSD names the part of the file as playback reaches it. `range`
579
+ * says which of the ranges was entered: `index` is its place in the
580
+ * list the condition was given.
581
+ * ```ts
582
+ * declare const parts: { start: number; end: number; name: string }[];
583
+ * // ---cut---
584
+ * const { when, osd } = plugin;
585
+ * plugin
586
+ * .trigger()
587
+ * .firesOn(when.position.in(parts))
588
+ * // `range` is set because the condition has a position list.
589
+ * .enter(async ({ range }) => {
590
+ * if (range) await osd.show("Now: {}", [parts[range.index].name]);
591
+ * });
592
+ * ```
593
+ *
594
+ * @since 1.10.0
595
+ */
596
+ enter(fn: (event: TriggerEvent) => unknown): Trigger;
597
+ /**
598
+ * Optional: `fn` runs each time the condition turns from true to false.
599
+ * A second call replaces the function.
600
+ *
601
+ * @throws `TypeError` (throws) `fn` is not a function.
602
+ *
603
+ * @example See Trigger
604
+ * {@link Trigger}
605
+ *
606
+ * @since 1.10.0
607
+ */
608
+ leave(fn: (event: TriggerEvent) => unknown): Trigger;
609
+ /**
610
+ * Removes the condition, without a `leave`. The trigger stays declared
611
+ * and can be given a new condition.
612
+ *
613
+ * @example Cancel a sleep timer
614
+ * A second command disarms the timer the first one set: the player
615
+ * forgets the condition, so the plugin is not started for it.
616
+ * ```ts
617
+ * const sleep = plugin.trigger("sleep").enter(() => plugin.player.setPaused(true));
618
+ * plugin.commands.add({
619
+ * id: "sleep-cancel",
620
+ * path: ["Tools", "Cancel Sleep Timer"],
621
+ * run: () => sleep.off(), // the trigger stays; only its condition goes
622
+ * });
623
+ * ```
624
+ *
625
+ * @since 1.10.0
626
+ */
627
+ off(): Trigger;
255
628
  }
256
629
  /**
257
630
  * A built-in top-level menu of the player, named in a command path as `@<id>`
@@ -1,4 +1,4 @@
1
- import type { Plugin } from "./base.ts";
1
+ import type { AppInfo, Plugin } from "./base.ts";
2
2
  import type { Disposable } from "./base.ts";
3
3
  /**
4
4
  * The manifest of a package, as validated. The display fields and
@@ -160,6 +160,9 @@ export interface PackageCandidate {
160
160
  * needed).
161
161
  * @throws `stale` (rejects) The candidate is older than the 32 the player
162
162
  * keeps.
163
+ * @throws `unavailable` (rejects) The player is a temporary window
164
+ * ({@link AppInfo.temporary}, player 0.10.3): it runs the main window's
165
+ * plugins as they are and installs or updates none.
163
166
  *
164
167
  * @example Replace a plugin installed from another source
165
168
  * The new package replaces the installed plugin even though it came from
@@ -531,6 +534,9 @@ export interface Packages {
531
534
  * @throws `missing` (rejects) An unknown id.
532
535
  * @throws `busy` (rejects) The plugin is being installed or reloaded.
533
536
  * @throws `unsupported` (rejects) A built-in plugin.
537
+ * @throws `unavailable` (rejects) The player is a temporary window
538
+ * ({@link AppInfo.temporary}, player 0.10.3): it runs the main window's
539
+ * plugins as they are and enables or disables none.
534
540
  *
535
541
  * @example Turn a third-party plugin off
536
542
  * The plugin stops another plugin and keeps it disabled across launches
@@ -590,6 +596,9 @@ export interface Packages {
590
596
  * plugin is being installed or reloaded.
591
597
  * @throws `revisionConflict` (rejects) The installed revision of that
592
598
  * plugin changed meanwhile; call `uninstall` again.
599
+ * @throws `unavailable` (rejects) The player is a temporary window
600
+ * ({@link AppInfo.temporary}, player 0.10.3): it runs the main window's
601
+ * plugins as they are and removes none.
593
602
  *
594
603
  * @example Uninstall a plugin together with its data
595
604
  * The other plugin is removed and its data directory deleted, so a later