@mattebox/player 0.10.0 → 0.11.0

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 (67) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/icons.d.ts +1 -1
  3. package/dist/controls/icons.d.ts.map +1 -1
  4. package/dist/controls/icons.js +1 -0
  5. package/dist/controls/icons.js.map +1 -1
  6. package/dist/controls/native-tracks.d.ts +8 -7
  7. package/dist/controls/native-tracks.d.ts.map +1 -1
  8. package/dist/controls/native-tracks.js.map +1 -1
  9. package/dist/element.d.ts +46 -1
  10. package/dist/element.d.ts.map +1 -1
  11. package/dist/element.js +142 -13
  12. package/dist/element.js.map +1 -1
  13. package/dist/elements/control-bar.d.ts.map +1 -1
  14. package/dist/elements/control-bar.js +8 -6
  15. package/dist/elements/control-bar.js.map +1 -1
  16. package/dist/elements/error-screen.d.ts.map +1 -1
  17. package/dist/elements/error-screen.js +1 -3
  18. package/dist/elements/error-screen.js.map +1 -1
  19. package/dist/elements/play-button.d.ts.map +1 -1
  20. package/dist/elements/play-button.js +7 -9
  21. package/dist/elements/play-button.js.map +1 -1
  22. package/dist/elements/shared.d.ts +18 -0
  23. package/dist/elements/shared.d.ts.map +1 -1
  24. package/dist/elements/shared.js +16 -9
  25. package/dist/elements/shared.js.map +1 -1
  26. package/dist/elements/start-button.d.ts.map +1 -1
  27. package/dist/elements/start-button.js +3 -3
  28. package/dist/elements/start-button.js.map +1 -1
  29. package/dist/elements/title.d.ts.map +1 -1
  30. package/dist/elements/title.js +5 -2
  31. package/dist/elements/title.js.map +1 -1
  32. package/dist/elements/video-menu.d.ts +23 -0
  33. package/dist/elements/video-menu.d.ts.map +1 -0
  34. package/dist/elements/video-menu.js +146 -0
  35. package/dist/elements/video-menu.js.map +1 -0
  36. package/dist/entries/video-menu.d.ts +5 -0
  37. package/dist/entries/video-menu.d.ts.map +1 -0
  38. package/dist/entries/video-menu.js +9 -0
  39. package/dist/entries/video-menu.js.map +1 -0
  40. package/dist/es2015/controls/icons.js +1 -0
  41. package/dist/es2015/element.js +187 -60
  42. package/dist/es2015/elements/control-bar.js +8 -6
  43. package/dist/es2015/elements/error-screen.js +2 -3
  44. package/dist/es2015/elements/play-button.js +8 -10
  45. package/dist/es2015/elements/shared.js +16 -9
  46. package/dist/es2015/elements/start-button.js +3 -3
  47. package/dist/es2015/elements/title.js +5 -2
  48. package/dist/es2015/elements/video-menu.js +152 -0
  49. package/dist/es2015/entries/video-menu.js +7 -0
  50. package/dist/es2015/index.js +3 -1
  51. package/dist/es2015/tags.js +2 -1
  52. package/dist/es2015/video-sources.js +128 -0
  53. package/dist/host.d.ts +10 -1
  54. package/dist/host.d.ts.map +1 -1
  55. package/dist/host.js.map +1 -1
  56. package/dist/index.d.ts +3 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +3 -1
  59. package/dist/tags.d.ts +1 -0
  60. package/dist/tags.d.ts.map +1 -1
  61. package/dist/tags.js +2 -1
  62. package/dist/tags.js.map +1 -1
  63. package/dist/video-sources.d.ts +48 -0
  64. package/dist/video-sources.d.ts.map +1 -0
  65. package/dist/video-sources.js +134 -0
  66. package/dist/video-sources.js.map +1 -0
  67. package/package.json +3 -3
@@ -8,6 +8,7 @@ import { STYLE } from "./style.js";
8
8
  import { errorSurface } from "./surface.js";
9
9
  import { PLAYER } from "./tags.js";
10
10
  import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/objectSpread2.js";
11
+ import { chosen, holdFrame, markupVideoTracks, onNextFrame, restore, resume, versionSource } from "./video-sources.js";
11
12
  import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHls } from "@mattebox/player-core";
12
13
  //#region src/element.ts
13
14
  /**
@@ -24,6 +25,16 @@ const FORWARDED = [
24
25
  "crossorigin"
25
26
  ];
26
27
  const LICENSE_URL = "license-url";
28
+ /** Carried through a switch: the play state from before it, `playing` or `paused`. */
29
+ const SWITCHING = "switching";
30
+ /** Whether the browser has EME, so a source may bring DRM. */
31
+ function emeAvailable() {
32
+ return drmGuard().without === void 0;
33
+ }
34
+ /** `source` without its DRM, for a browser without EME. */
35
+ function withoutDrm({ url, type, videoTracks }) {
36
+ return _objectSpread2(_objectSpread2({ url }, type === void 0 ? {} : { type }), videoTracks === void 0 ? {} : { videoTracks });
37
+ }
27
38
  const CERTIFICATE_URL = "certificate-url";
28
39
  /** Everything else the element watches. Changing any of them reloads. */
29
40
  const OWN = [
@@ -161,6 +172,11 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
161
172
  this.offs = [];
162
173
  this.queue = Promise.resolve();
163
174
  this.pending = false;
175
+ this.programme = null;
176
+ this.version = null;
177
+ this.switching = false;
178
+ this.switched = null;
179
+ this.held = null;
164
180
  this.slow = void 0;
165
181
  this.heardAudio = void 0;
166
182
  this.heardText = void 0;
@@ -190,7 +206,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
190
206
  });
191
207
  this.stage.append(slot);
192
208
  this.surface = errorSurface(() => {
193
- this.reload();
209
+ this.retry();
194
210
  });
195
211
  this.voice = announcer(this);
196
212
  const root = this.attachShadow({ mode: "open" });
@@ -219,14 +235,118 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
219
235
  if (this.marks.list.length > 0) this.marks.set([]);
220
236
  this.reload();
221
237
  }
238
+ /**
239
+ * Loads the sources again, in the order a load reads them: the `src`
240
+ * attribute, the `sources` property, then the `<source>` children. The
241
+ * error screens' Retry calls it. On a version of `videoSources`, it
242
+ * loads that version again.
243
+ */
244
+ retry() {
245
+ const again = this.version === null ? this.switched : versionSource(this.version, emeAvailable());
246
+ if (again === null) this.reload();
247
+ else this.swap(again, null, false, null, false);
248
+ }
249
+ /**
250
+ * Loads `source` in place of the one that plays, from the same position
251
+ * and in the same play state, with the same audio and subtitle choice.
252
+ * Use it for the same programme at another URL, such as its HLS and
253
+ * DASH manifests. The last frame and the controls hold until the new
254
+ * load shows a frame there. The markers stay, and the versions are the
255
+ * ones `source` names. A new `src`, `sources` or `<source>` load
256
+ * replaces it.
257
+ */
258
+ switchSource(source) {
259
+ var _this$current$engine, _this$current;
260
+ const media = this.media;
261
+ const at = Number.isFinite(media.duration) ? media.currentTime : null;
262
+ const playing = !media.paused;
263
+ const had = chosen((_this$current$engine = (_this$current = this.current) === null || _this$current === void 0 ? void 0 : _this$current.engine) !== null && _this$current$engine !== void 0 ? _this$current$engine : null);
264
+ const clean = emeAvailable() ? source : withoutDrm(source);
265
+ const was = this.version;
266
+ this.programme = clean;
267
+ this.switched = clean;
268
+ this.version = null;
269
+ if (was !== null) this.emit("videosourcechange", null);
270
+ this.swap(clean, at, playing, had, true);
271
+ }
272
+ /** The other versions of the picture the source names at their own URLs, for the video menu. */
273
+ get videoSources() {
274
+ var _this$programme$video, _this$programme;
275
+ return (_this$programme$video = (_this$programme = this.programme) === null || _this$programme === void 0 ? void 0 : _this$programme.videoTracks) !== null && _this$programme$video !== void 0 ? _this$programme$video : [];
276
+ }
277
+ /** The version of `videoSources` that plays, or null for the source itself. */
278
+ get videoSource() {
279
+ return this.version;
280
+ }
281
+ /**
282
+ * Plays a version of `videoSources`, or the source itself for null, from
283
+ * the same position and in the same play state, with the same audio and
284
+ * subtitle choice. A live source joins the version at its live edge.
285
+ * Fires `videosourcechange`.
286
+ */
287
+ selectVideoSource(track) {
288
+ var _programme$videoTrack, _this$current$engine2, _this$current2;
289
+ const programme = this.programme;
290
+ if (programme === null || track === this.version) return;
291
+ if (track !== null && ((_programme$videoTrack = programme.videoTracks) === null || _programme$videoTrack === void 0 ? void 0 : _programme$videoTrack.includes(track)) !== true) return;
292
+ const media = this.media;
293
+ const at = Number.isFinite(media.duration) ? media.currentTime : null;
294
+ const playing = !media.paused;
295
+ const had = chosen((_this$current$engine2 = (_this$current2 = this.current) === null || _this$current2 === void 0 ? void 0 : _this$current2.engine) !== null && _this$current$engine2 !== void 0 ? _this$current$engine2 : null);
296
+ this.version = track;
297
+ this.emit("videosourcechange", track);
298
+ this.swap(track === null ? programme : versionSource(track, emeAvailable()), at, playing, had, true);
299
+ }
300
+ /**
301
+ * Loads `source` under the programme that plays, and puts the position,
302
+ * play state and tracks back. With `hold`, the last frame stays as the
303
+ * poster and the player carries `switching`, the play state from
304
+ * before, so the controls show that state through the load.
305
+ */
306
+ swap(source, at, playing, had, hold) {
307
+ var _this = this;
308
+ var _this$held;
309
+ const media = this.media;
310
+ (_this$held = this.held) === null || _this$held === void 0 || _this$held.call(this);
311
+ let release = null;
312
+ if (hold) {
313
+ const frame = holdFrame(media);
314
+ const done = () => {
315
+ frame === null || frame === void 0 || frame();
316
+ if (this.held !== done) return;
317
+ this.held = null;
318
+ this.removeAttribute(SWITCHING);
319
+ this.reflect();
320
+ };
321
+ this.held = done;
322
+ this.setAttribute(SWITCHING, playing ? "playing" : "paused");
323
+ release = done;
324
+ }
325
+ this.enqueue(_asyncToGenerator(function* () {
326
+ var _this$current$engine3, _this$current3;
327
+ const core = yield _this.ensure();
328
+ _this.switching = true;
329
+ try {
330
+ yield core.load([source]);
331
+ } catch (_unused) {
332
+ release === null || release === void 0 || release();
333
+ return;
334
+ } finally {
335
+ _this.switching = false;
336
+ }
337
+ resume(media, at, playing);
338
+ if (release !== null) onNextFrame(media, at, release);
339
+ restore((_this$current$engine3 = (_this$current3 = _this.current) === null || _this$current3 === void 0 ? void 0 : _this$current3.engine) !== null && _this$current$engine3 !== void 0 ? _this$current$engine3 : null, had);
340
+ }));
341
+ }
222
342
  /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
223
343
  get player() {
224
344
  return this.core;
225
345
  }
226
346
  /** The engine feeding the video, or null for a native session and before the first load. */
227
347
  get engine() {
228
- var _this$current$engine, _this$current;
229
- return (_this$current$engine = (_this$current = this.current) === null || _this$current === void 0 ? void 0 : _this$current.engine) !== null && _this$current$engine !== void 0 ? _this$current$engine : null;
348
+ var _this$current$engine4, _this$current4;
349
+ return (_this$current$engine4 = (_this$current4 = this.current) === null || _this$current4 === void 0 ? void 0 : _this$current4.engine) !== null && _this$current$engine4 !== void 0 ? _this$current$engine4 : null;
230
350
  }
231
351
  /**
232
352
  * The fatal error of the current load, or null once a load starts or
@@ -272,7 +392,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
272
392
  } else if (event === "waiting" || event === "stalled") this.waiting = true;
273
393
  else if (event === "canplay") this.waiting = false;
274
394
  else if (event === "emptied") {
275
- this.started = false;
395
+ if (this.held === null) this.started = false;
276
396
  this.waiting = false;
277
397
  this.heardAudio = void 0;
278
398
  this.heardText = void 0;
@@ -280,8 +400,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
280
400
  }
281
401
  /** Says a play or a pause, and a wait once it has lasted `LOADING_MS`. */
282
402
  tell(event, was) {
283
- if (event === "play") this.voice.say("playing", "Playing");
284
- if (event === "pause" && !this.media.ended) this.voice.say("paused", "Paused");
403
+ if (event === "play" && this.held === null) this.voice.say("playing", "Playing");
404
+ if (event === "pause" && !this.media.ended && this.held === null) this.voice.say("paused", "Paused");
285
405
  if (this.waiting === was) return;
286
406
  clearTimeout(this.slow);
287
407
  if (this.waiting) this.slow = setTimeout(() => {
@@ -294,8 +414,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
294
414
  * reads as off, as in the subtitles menu.
295
415
  */
296
416
  tracks() {
297
- var _this$current$engine2, _this$current2;
298
- const engine = (_this$current$engine2 = (_this$current2 = this.current) === null || _this$current2 === void 0 ? void 0 : _this$current2.engine) !== null && _this$current$engine2 !== void 0 ? _this$current$engine2 : null;
417
+ var _this$current$engine5, _this$current5;
418
+ const engine = (_this$current$engine5 = (_this$current5 = this.current) === null || _this$current5 === void 0 ? void 0 : _this$current5.engine) !== null && _this$current$engine5 !== void 0 ? _this$current$engine5 : null;
299
419
  let audio;
300
420
  let text;
301
421
  if (engine !== null) {
@@ -325,8 +445,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
325
445
  reflect() {
326
446
  const video = this.media;
327
447
  this.reflecting = true;
328
- this.toggleAttribute("paused", video.paused);
329
- this.toggleAttribute("playing", !video.paused);
448
+ const held = this.getAttribute(SWITCHING);
449
+ const paused = held === null ? video.paused : held === "paused";
450
+ this.toggleAttribute("paused", paused);
451
+ this.toggleAttribute("playing", !paused);
330
452
  this.toggleAttribute("ended", video.ended);
331
453
  this.toggleAttribute("muted", video.muted);
332
454
  this.toggleAttribute("audio", this.audio());
@@ -405,9 +527,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
405
527
  }
406
528
  /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */
407
529
  chapters() {
408
- var _this$current$engine3, _this$current3;
530
+ var _this$current$engine6, _this$current6;
409
531
  const url = this.getAttribute(CHAPTERS);
410
- const engine = (_this$current$engine3 = (_this$current3 = this.current) === null || _this$current3 === void 0 ? void 0 : _this$current3.engine) !== null && _this$current$engine3 !== void 0 ? _this$current$engine3 : null;
532
+ const engine = (_this$current$engine6 = (_this$current6 = this.current) === null || _this$current6 === void 0 ? void 0 : _this$current6.engine) !== null && _this$current$engine6 !== void 0 ? _this$current$engine6 : null;
411
533
  const api = engine === null ? void 0 : namespaces(engine).chapters;
412
534
  if (api !== void 0) {
413
535
  var _this$track;
@@ -474,22 +596,22 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
474
596
  this.emit("error", error);
475
597
  }
476
598
  run() {
477
- var _this = this;
599
+ var _this2 = this;
478
600
  return _asyncToGenerator(function* () {
479
- _this.unmount();
480
- if (!_this.isConnected) return;
481
- const sources = _this.wanted();
482
- _this.tried = JSON.stringify(sources);
601
+ _this2.unmount();
602
+ if (!_this2.isConnected) return;
603
+ const sources = _this2.wanted();
604
+ _this2.tried = JSON.stringify(sources);
483
605
  if (sources.length === 0) return;
484
- const core = yield _this.ensure();
485
- _this.failure = null;
486
- _this.surface.clear();
606
+ const core = yield _this2.ensure();
607
+ _this2.failure = null;
608
+ _this2.surface.clear();
487
609
  try {
488
610
  yield core.load(sources);
489
- } catch (_unused) {
611
+ } catch (_unused2) {
490
612
  return;
491
613
  }
492
- if (!_this.isConnected) yield core.unload();
614
+ if (!_this2.isConnected) yield core.unload();
493
615
  })();
494
616
  }
495
617
  /**
@@ -498,19 +620,15 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
498
620
  * A child carries its own `license-url` and `certificate-url`.
499
621
  */
500
622
  wanted() {
623
+ const versions = markupVideoTracks(this);
624
+ const withVersions = versions.length === 0 ? {} : { videoTracks: versions };
501
625
  const url = this.getAttribute("src");
502
626
  if (url !== null) {
503
627
  const type = this.getAttribute("type");
504
- return [type === null ? { url } : {
505
- url,
506
- type
507
- }];
628
+ return [_objectSpread2(_objectSpread2({ url }, type === null ? {} : { type }), withVersions)];
508
629
  }
509
- const eme = drmGuard().without === void 0;
510
- if (this.list !== null) return eme ? this.list : this.list.map(({ url, type }) => type === void 0 ? { url } : {
511
- url,
512
- type
513
- });
630
+ const eme = emeAvailable();
631
+ if (this.list !== null) return eme ? this.list : this.list.map(withoutDrm);
514
632
  const found = [];
515
633
  for (const child of Array.from(this.children)) {
516
634
  const src = child.localName === "source" ? child.getAttribute("src") : null;
@@ -518,7 +636,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
518
636
  const type = child.getAttribute("type");
519
637
  const license = child.getAttribute(LICENSE_URL);
520
638
  const certificate = child.getAttribute(CERTIFICATE_URL);
521
- found.push(_objectSpread2(_objectSpread2({ url: src }, type === null ? {} : { type }), !eme || license === null && certificate === null ? {} : { drm: _objectSpread2(_objectSpread2({}, license === null ? {} : { licenseUrl: license }), certificate === null ? {} : { certificateUrl: certificate }) }));
639
+ found.push(_objectSpread2(_objectSpread2(_objectSpread2({ url: src }, type === null ? {} : { type }), withVersions), !eme || license === null && certificate === null ? {} : { drm: _objectSpread2(_objectSpread2({}, license === null ? {} : { licenseUrl: license }), certificate === null ? {} : { certificateUrl: certificate }) }));
522
640
  }
523
641
  return found;
524
642
  }
@@ -529,21 +647,30 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
529
647
  this.chapters();
530
648
  }
531
649
  ensure() {
532
- var _this2 = this;
650
+ var _this3 = this;
533
651
  return _asyncToGenerator(function* () {
534
- if (_this2.core !== null) return _this2.core;
535
- const core = createPlayer(_this2.media, { handlers: yield _this2.chain() });
536
- _this2.offs.push(core.on("sourcechange", (session) => {
652
+ if (_this3.core !== null) return _this3.core;
653
+ const core = createPlayer(_this3.media, { handlers: yield _this3.chain() });
654
+ _this3.offs.push(core.on("sourcechange", (session) => {
537
655
  var _this$offTracks, _session$engine$on, _session$engine;
538
- _this2.current = session;
539
- (_this$offTracks = _this2.offTracks) === null || _this$offTracks === void 0 || _this$offTracks.call(_this2);
540
- _this2.offTracks = (_session$engine$on = session === null || session === void 0 || (_session$engine = session.engine) === null || _session$engine === void 0 ? void 0 : _session$engine.on("tracks:selected", () => _this2.tracks())) !== null && _session$engine$on !== void 0 ? _session$engine$on : null;
541
- if (session !== null && _this2.isConnected) _this2.adopt(session);
542
- _this2.emit("sourcechange", session);
656
+ _this3.current = session;
657
+ if (!_this3.switching) {
658
+ var _session$source, _this$held2;
659
+ const was = _this3.version;
660
+ _this3.programme = (_session$source = session === null || session === void 0 ? void 0 : session.source) !== null && _session$source !== void 0 ? _session$source : null;
661
+ _this3.switched = null;
662
+ _this3.version = null;
663
+ (_this$held2 = _this3.held) === null || _this$held2 === void 0 || _this$held2.call(_this3);
664
+ if (was !== null) _this3.emit("videosourcechange", null);
665
+ }
666
+ (_this$offTracks = _this3.offTracks) === null || _this$offTracks === void 0 || _this$offTracks.call(_this3);
667
+ _this3.offTracks = (_session$engine$on = session === null || session === void 0 || (_session$engine = session.engine) === null || _session$engine === void 0 ? void 0 : _session$engine.on("tracks:selected", () => _this3.tracks())) !== null && _session$engine$on !== void 0 ? _session$engine$on : null;
668
+ if (session !== null && _this3.isConnected) _this3.adopt(session);
669
+ _this3.emit("sourcechange", session);
543
670
  }), core.on("error", (error) => {
544
- _this2.report(error);
671
+ _this3.report(error);
545
672
  }));
546
- _this2.core = core;
673
+ _this3.core = core;
547
674
  return core;
548
675
  })();
549
676
  }
@@ -557,23 +684,23 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
557
684
  return (_this$own = this.own) !== null && _this$own !== void 0 ? _this$own : defaults;
558
685
  }
559
686
  chain() {
560
- var _this3 = this;
687
+ var _this4 = this;
561
688
  return _asyncToGenerator(function* () {
562
689
  var _this$getAttribute2;
563
- if (_this3.options.handlers !== void 0) return _this3.options.handlers;
564
- const config = _this3.options.config === void 0 ? {} : { config: _this3.options.config };
690
+ if (_this4.options.handlers !== void 0) return _this4.options.handlers;
691
+ const config = _this4.options.config === void 0 ? {} : { config: _this4.options.config };
565
692
  const native = (stages) => nativeHandler({
566
- prefer: (source, env) => _this3.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
567
- drm: () => _this3.drm(stages)
693
+ prefer: (source, env) => _this4.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
694
+ drm: () => _this4.drm(stages)
568
695
  });
569
- if (_this3.options.stages !== void 0) return [matteboxHandler(_objectSpread2({ stages: _this3.options.stages }, config)), native(() => {
696
+ if (_this4.options.stages !== void 0) return [matteboxHandler(_objectSpread2({ stages: _this4.options.stages }, config)), native(() => {
570
697
  var _this$options$stages;
571
- return (_this$options$stages = _this3.options.stages) !== null && _this$options$stages !== void 0 ? _this$options$stages : [];
698
+ return (_this$options$stages = _this4.options.stages) !== null && _this$options$stages !== void 0 ? _this$options$stages : [];
572
699
  })];
573
- const name = (_this$getAttribute2 = _this3.getAttribute("preset")) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : DEFAULT_PRESET;
700
+ const name = (_this$getAttribute2 = _this4.getAttribute("preset")) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : DEFAULT_PRESET;
574
701
  const preset = yield resolvePreset(name);
575
702
  if (preset === null) {
576
- _this3.report({
703
+ _this4.report({
577
704
  category: "config",
578
705
  code: "CONFIG_INVALID",
579
706
  fatal: true,
@@ -621,20 +748,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
621
748
  this.current = null;
622
749
  }
623
750
  teardown() {
624
- var _this4 = this;
751
+ var _this5 = this;
625
752
  return _asyncToGenerator(function* () {
626
- _this4.unmount();
627
- if (_this4.core !== null) yield _this4.core.unload();
753
+ _this5.unmount();
754
+ if (_this5.core !== null) yield _this5.core.unload();
628
755
  })();
629
756
  }
630
757
  /** Drops the player itself, so the next run builds a chain from the new preset. */
631
758
  discard() {
632
- var _this5 = this;
759
+ var _this6 = this;
633
760
  return _asyncToGenerator(function* () {
634
- yield _this5.teardown();
635
- for (const off of _this5.offs) off();
636
- _this5.offs = [];
637
- _this5.core = null;
761
+ yield _this6.teardown();
762
+ for (const off of _this6.offs) off();
763
+ _this6.offs = [];
764
+ _this6.core = null;
638
765
  })();
639
766
  }
640
767
  };
@@ -1,6 +1,6 @@
1
- import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SCAN_BUTTON, SKIP_BUTTON, SPEED_MENU, SUBTITLES_MENU, VOLUME, VOLUME_SLIDER } from "../tags.js";
1
+ import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SCAN_BUTTON, SKIP_BUTTON, SPEED_MENU, SUBTITLES_MENU, VIDEO_MENU, VOLUME, VOLUME_SLIDER } from "../tags.js";
2
2
  import { Component } from "./component.js";
3
- import { number, style } from "./shared.js";
3
+ import { number, shownPaused, style } from "./shared.js";
4
4
  import { cueLift, cueStyle } from "../controls/cues.js";
5
5
  import { fullscreen } from "../controls/fullscreen.js";
6
6
  //#region src/elements/control-bar.ts
@@ -12,8 +12,9 @@ const SEEK_STEP = 5;
12
12
  * suit a TV remote more than a small screen; then the slider, which takes
13
13
  * the most room for the least; then the diagnostics, the lock and the
14
14
  * menus a viewer rarely opens; then the menus for the picture and the
15
- * sound; then the skips; then the mute and the subtitles. The subtitles
16
- * menu goes last of the menus because it is the one a viewer may need.
15
+ * sound; then the skips; then the mute, the subtitles and the video
16
+ * menu. The subtitles and video menus go last of the menus because a
17
+ * viewer may need them: the video menu holds the sign-language version.
17
18
  * The diagnostics is another package's, named here as a string. A
18
19
  * `priority` attribute on the control replaces its default.
19
20
  */
@@ -30,6 +31,7 @@ const PRIORITY = {
30
31
  [AIRPLAY_BUTTON]: 2,
31
32
  [SKIP_BUTTON]: 2,
32
33
  [SUBTITLES_MENU]: 1,
34
+ [VIDEO_MENU]: 1,
33
35
  [VOLUME]: 1,
34
36
  [MUTE_BUTTON]: 1
35
37
  };
@@ -149,7 +151,7 @@ var MbxControlBar = class extends Component {
149
151
  };
150
152
  }
151
153
  held(player) {
152
- if (player.video.paused) return true;
154
+ if (shownPaused(player, ["switching"])) return true;
153
155
  if (this.querySelector("[open]") !== null) return true;
154
156
  if (!this.keyboard) return false;
155
157
  const active = this.getRootNode().activeElement;
@@ -280,7 +282,7 @@ var MbxControlBar = class extends Component {
280
282
  "pause",
281
283
  "ended"
282
284
  ], () => {
283
- this.wake(player);
285
+ if (!player.hasAttribute("switching")) this.wake(player);
284
286
  });
285
287
  this.wake(player);
286
288
  this.cues.lifted(true);
@@ -19,9 +19,8 @@ var MbxErrorScreen = class extends Component {
19
19
  this.retry = el("button", "retry");
20
20
  this.retry.type = "button";
21
21
  this.retry.addEventListener("click", () => {
22
- const player = this.player;
23
- const src = player === null || player === void 0 ? void 0 : player.getAttribute("src");
24
- if (player !== null && player !== void 0 && src !== null && src !== void 0) player.setAttribute("src", src);
22
+ var _this$player;
23
+ (_this$player = this.player) === null || _this$player === void 0 || _this$player.retry();
25
24
  });
26
25
  box.append(this.title_, detail, this.retry);
27
26
  root.append(style(STYLE), box);
@@ -1,6 +1,6 @@
1
1
  import { icon } from "../controls/icons.js";
2
2
  import { Component } from "./component.js";
3
- import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
3
+ import { BUTTON_STYLE, HELD, iconSlots, show, shownPaused, style } from "./shared.js";
4
4
  //#region src/elements/play-button.ts
5
5
  /**
6
6
  * <mbx-play-button>: play, pause, or replay once the media has ended. It
@@ -9,8 +9,8 @@ import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
9
9
  * own SVG into `icon-play`, `icon-pause` or `icon-replay`; the name is on
10
10
  * the button, from `label-play`, `label-pause` and `label-replay`, where a
11
11
  * screen reader reads it. While the seek bar holds the video paused for a
12
- * drag, the button shows the state from before the drag, which the player
13
- * carries as `scrubbing`.
12
+ * drag, or a switch loads another source, the button shows the state from
13
+ * before, which the player carries as `scrubbing` or `switching`.
14
14
  */
15
15
  const STATES = [
16
16
  "play",
@@ -55,18 +55,16 @@ var MbxPlayButton = class extends Component {
55
55
  ], () => {
56
56
  this.render();
57
57
  });
58
- this.observe(player, ["scrubbing"], () => {
58
+ this.observe(player, HELD, () => {
59
59
  this.render();
60
60
  });
61
61
  this.render();
62
62
  }
63
63
  render() {
64
- var _this$player2, _this$player$getAttri, _this$player3, _this$getAttribute;
65
- const video = (_this$player2 = this.player) === null || _this$player2 === void 0 ? void 0 : _this$player2.video;
66
- if (video === void 0) return;
67
- const held = (_this$player$getAttri = (_this$player3 = this.player) === null || _this$player3 === void 0 ? void 0 : _this$player3.getAttribute("scrubbing")) !== null && _this$player$getAttri !== void 0 ? _this$player$getAttri : null;
68
- const paused = held === null ? video.paused : held === "paused";
69
- const state = video.ended ? "replay" : paused ? "play" : "pause";
64
+ var _this$getAttribute;
65
+ const player = this.player;
66
+ if (player === null) return;
67
+ const state = player.video.ended ? "replay" : shownPaused(player) ? "play" : "pause";
70
68
  show(this.slots, state);
71
69
  this.button.setAttribute("aria-label", (_this$getAttribute = this.getAttribute(`label-${state}`)) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : LABELS[state]);
72
70
  }
@@ -1,12 +1,4 @@
1
1
  //#region src/elements/shared.ts
2
- /**
3
- * The style every button control shares. Each element carries its own
4
- * copy in its shadow root, so the rules are short and the tokens come
5
- * through the `--mbx-*` custom properties the player sets, which inherit
6
- * through light DOM into every control.
7
- *
8
- * Nothing carries `!important`: a page's `::part()` rule must win.
9
- */
10
2
  const BUTTON_STYLE_CSS = ":host{display:inline-flex}:host([hidden]){display:none}[part~=button]{width:2.5em;height:2.5em;font:inherit;color:inherit;border-radius:var(--mbx-radius);cursor:pointer;opacity:.9;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex;position:relative}[part~=button][aria-label]:after{content:attr(aria-label);display:var(--mbx-tooltip,block);background:var(--mbx-surface);border-radius:var(--mbx-radius);white-space:nowrap;pointer-events:none;opacity:0;margin-bottom:.4615em;padding:.3077em .6154em;font-size:.8125em;transition:opacity .1s;position:absolute;bottom:100%;left:50%;transform:translate(-50%)}[part~=button][aria-label]:focus:after{opacity:1;transition-delay:.4s}[part~=button][aria-label]:focus:not(:focus-visible):after{opacity:0;transition-delay:0s}@media (hover:hover){[part~=button][aria-label]:hover:after{opacity:1;transition-delay:.4s}}:host(:last-child) [part~=button][aria-label]:after{left:auto;right:0;transform:none}[part~=button]:hover{opacity:1}[part~=button]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=button]:focus:not(:focus-visible){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}slot[hidden]{display:none}";
11
3
  const SLIDER_STYLE_CSS = ":host{display:block}:host([hidden]){display:none}[part~=slider]{border-radius:var(--mbx-radius);cursor:pointer;touch-action:none;height:2.5em;position:relative}[part~=slider]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=slider]:focus:not(:focus-visible){outline:none}[part~=rail]{position:absolute;top:0;bottom:0;left:.5em;right:.5em}[part~=track]{background:#ffffff59;border-radius:2px;height:.25em;position:absolute;top:50%;left:0;right:0;overflow:hidden;transform:translateY(-50%)}[part~=fill]{background:var(--mbx-accent);position:absolute;top:0;bottom:0;left:0}[part~=thumb]{background:var(--mbx-text);pointer-events:none;border-radius:50%;width:.75em;height:.75em;margin:-.375em 0 0 -.375em;position:absolute;top:50%}";
12
4
  const BUTTON_STYLE = BUTTON_STYLE_CSS;
@@ -50,5 +42,20 @@ function iconSlots(states, fallback) {
50
42
  function show(slots, state) {
51
43
  for (const key of Object.keys(slots)) slots[key].hidden = key !== state;
52
44
  }
45
+ /**
46
+ * The attributes the player carries while it holds the video in another
47
+ * state than the one shown: `scrubbing` through a drag, `switching` through
48
+ * the load of `switchSource` or a version. Each holds the state from
49
+ * before, `playing` or `paused`.
50
+ */
51
+ const HELD = ["scrubbing", "switching"];
52
+ /** Whether the controls show the video as paused: the held state, if one of `names` holds it. */
53
+ function shownPaused(player, names = HELD) {
54
+ for (const name of names) {
55
+ const held = player.getAttribute(name);
56
+ if (held !== null) return held === "paused";
57
+ }
58
+ return player.video.paused;
59
+ }
53
60
  //#endregion
54
- export { BUTTON_STYLE, MENU_STYLE, SLIDER_STYLE, iconSlots, number, seekRow, show, style };
61
+ export { BUTTON_STYLE, HELD, MENU_STYLE, SLIDER_STYLE, iconSlots, number, seekRow, show, shownPaused, style };
@@ -1,6 +1,6 @@
1
1
  import { icon } from "../controls/icons.js";
2
2
  import { Component } from "./component.js";
3
- import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
3
+ import { BUTTON_STYLE, HELD, iconSlots, show, shownPaused, style } from "./shared.js";
4
4
  //#region src/elements/start-button.ts
5
5
  const STYLE_CSS = ":host{--mbx-tooltip:none;top:var(--mbx-start-top,50%);margin:-2.5em 0 0 -2.5em;position:absolute;left:50%}[part~=button]{z-index:0;width:5em;height:5em;color:var(--mbx-text);background:0 0;border:0;transition:color .15s;position:relative}[part~=button]:before{content:\"\";z-index:-1;background:var(--mbx-surface);opacity:.88;clip-path:polygon(0 0,79% 0,100% 21%,100% 100%,21% 100%,0 79%);transition:opacity .15s,background .15s;position:absolute;top:0;bottom:0;left:0;right:0}[part~=button]:hover{color:var(--mbx-surface)}[part~=button]:hover:before{background:var(--mbx-accent);opacity:1}:host([cramped]){display:none}[part~=icon],::slotted(*){width:3em;height:3em}slot[name=icon-play]>[part~=icon]{margin-left:.125em}@media (prefers-reduced-motion:reduce){[part~=button],[part~=button]:before{transition:none}}";
6
6
  const STATES = ["play", "replay"];
@@ -45,7 +45,7 @@ var MbxStartButton = class extends Component {
45
45
  this.failed = false;
46
46
  this.render();
47
47
  });
48
- this.observe(player, ["scrubbing"], () => {
48
+ this.observe(player, HELD, () => {
49
49
  this.render();
50
50
  });
51
51
  const failure = (event) => {
@@ -118,7 +118,7 @@ var MbxStartButton = class extends Component {
118
118
  show(this.slots, state);
119
119
  this.button.setAttribute("aria-label", (_this$getAttribute = this.getAttribute(`label-${state}`)) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : state === "play" ? "Play" : "Replay");
120
120
  const player = this.player;
121
- this.hidden = this.failed || !video.paused || (player === null || player === void 0 ? void 0 : player.hasAttribute("waiting")) === true || (player === null || player === void 0 ? void 0 : player.hasAttribute("scrubbing")) === true;
121
+ this.hidden = this.failed || player !== null && !shownPaused(player, ["switching"]) || (player === null || player === void 0 ? void 0 : player.hasAttribute("waiting")) === true || (player === null || player === void 0 ? void 0 : player.hasAttribute("scrubbing")) === true;
122
122
  }
123
123
  };
124
124
  //#endregion
@@ -1,6 +1,6 @@
1
1
  import { el } from "../dom.js";
2
2
  import { Component } from "./component.js";
3
- import { style } from "./shared.js";
3
+ import { shownPaused, style } from "./shared.js";
4
4
  //#region src/elements/title.ts
5
5
  /**
6
6
  * <mbx-title>: the heading, the subheading and the artwork of what plays,
@@ -55,6 +55,9 @@ var MbxTitle = class extends Component {
55
55
  ], () => {
56
56
  this.state(player);
57
57
  });
58
+ this.observe(player, ["switching"], () => {
59
+ this.state(player);
60
+ });
58
61
  if (typeof ResizeObserver !== "undefined") {
59
62
  this.resizer = new ResizeObserver(() => {
60
63
  this.fit(player);
@@ -76,7 +79,7 @@ var MbxTitle = class extends Component {
76
79
  }
77
80
  /** `playing` on the element, for its own stylesheet and the page's. */
78
81
  state(player) {
79
- this.toggleAttribute("playing", !player.video.paused);
82
+ this.toggleAttribute("playing", !shownPaused(player, ["switching"]));
80
83
  }
81
84
  /** The height of the bar's rows: its box less the padding above them, which is its fade. Zero without a bar. */
82
85
  fit(player) {