@mattebox/player 0.12.0 → 0.13.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 (47) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/breaks.d.ts +24 -0
  3. package/dist/controls/breaks.d.ts.map +1 -0
  4. package/dist/controls/breaks.js +20 -0
  5. package/dist/controls/breaks.js.map +1 -0
  6. package/dist/element-entry.d.ts +1 -1
  7. package/dist/element-entry.d.ts.map +1 -1
  8. package/dist/element-entry.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 +89 -6
  12. package/dist/element.js.map +1 -1
  13. package/dist/elements/marker-button.d.ts +1 -0
  14. package/dist/elements/marker-button.d.ts.map +1 -1
  15. package/dist/elements/marker-button.js +12 -8
  16. package/dist/elements/marker-button.js.map +1 -1
  17. package/dist/elements/quality-menu.d.ts.map +1 -1
  18. package/dist/elements/quality-menu.js +1 -0
  19. package/dist/elements/quality-menu.js.map +1 -1
  20. package/dist/elements/seek-bar.d.ts +4 -0
  21. package/dist/elements/seek-bar.d.ts.map +1 -1
  22. package/dist/elements/seek-bar.js +19 -3
  23. package/dist/elements/seek-bar.js.map +1 -1
  24. package/dist/elements/spinner.d.ts +11 -9
  25. package/dist/elements/spinner.d.ts.map +1 -1
  26. package/dist/elements/spinner.js +8 -3
  27. package/dist/elements/spinner.js.map +1 -1
  28. package/dist/elements/start-button.d.ts.map +1 -1
  29. package/dist/elements/start-button.js +1 -1
  30. package/dist/elements/start-button.js.map +1 -1
  31. package/dist/elements/title.d.ts.map +1 -1
  32. package/dist/elements/title.js +6 -4
  33. package/dist/elements/title.js.map +1 -1
  34. package/dist/es2015/controls/breaks.js +18 -0
  35. package/dist/es2015/element.js +160 -66
  36. package/dist/es2015/elements/marker-button.js +12 -8
  37. package/dist/es2015/elements/quality-menu.js +1 -0
  38. package/dist/es2015/elements/seek-bar.js +25 -7
  39. package/dist/es2015/elements/spinner.js +8 -3
  40. package/dist/es2015/elements/start-button.js +1 -1
  41. package/dist/es2015/elements/title.js +6 -4
  42. package/dist/host.d.ts +31 -1
  43. package/dist/host.d.ts.map +1 -1
  44. package/dist/host.js.map +1 -1
  45. package/dist/index.d.ts +2 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  import { announcer } from "./announcer.js";
2
+ import { createBreakMarks } from "./controls/breaks.js";
2
3
  import { createMarkers } from "./controls/markers.js";
3
4
  import { languageName } from "./controls/track-names.js";
4
5
  import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/asyncToGenerator.js";
@@ -187,6 +188,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
187
188
  this.started = false;
188
189
  this.waiting = false;
189
190
  this.offs = [];
191
+ this.attached = /* @__PURE__ */ new Map();
192
+ this.interruption = null;
190
193
  this.queue = Promise.resolve();
191
194
  this.pending = false;
192
195
  this.original = null;
@@ -220,6 +223,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
220
223
  this.reflect();
221
224
  });
222
225
  this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
226
+ this.breakMarks = createBreakMarks((list) => this.emit("breakschange", list));
223
227
  this.tracking = createTrackers(this, () => this.emit("trackerschange", this.tracking.list));
224
228
  this.stage = document.createElement("div");
225
229
  this.stage.setAttribute("part", "stage");
@@ -248,6 +252,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
248
252
  get markers() {
249
253
  return this.marks;
250
254
  }
255
+ /** Where the programme's ad breaks are, which the seek bar draws: each add-on gives its own. */
256
+ get breaks() {
257
+ return this.breakMarks;
258
+ }
251
259
  /**
252
260
  * The sources to try in order, set from script. The `src` attribute wins
253
261
  * over them, and they win over the `<source>` children. Setting them
@@ -259,6 +267,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
259
267
  set sources(value) {
260
268
  this.list = value;
261
269
  if (this.marks.list.length > 0) this.marks.set([]);
270
+ this.interruption = null;
262
271
  this.unblock();
263
272
  this.reload();
264
273
  }
@@ -359,6 +368,63 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
359
368
  if (was !== null) this.emit("videosourcechange", null);
360
369
  this.swap(clean, at, playing, had, true);
361
370
  }
371
+ /**
372
+ * Plays `source` on the video in the programme's place, such as an ad of
373
+ * `@mattebox/player-ads`. The programme, its markers and its trackers
374
+ * stay, no `sourcechange` fires, and the controls drive the source as
375
+ * they drive the programme. An error of the source is not the
376
+ * programme's: listen to the video. `resume()` plays the programme again
377
+ * where it stopped. Resolves once the source is loaded; rejects when no
378
+ * handler plays it.
379
+ */
380
+ interrupt(source) {
381
+ var _this = this;
382
+ var _this$interruption, _this$current$engine2, _this$current2;
383
+ const media = this.media;
384
+ (_this$interruption = this.interruption) !== null && _this$interruption !== void 0 || (this.interruption = {
385
+ at: Number.isFinite(media.duration) ? media.currentTime : null,
386
+ playing: !media.paused,
387
+ 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)
388
+ });
389
+ return this.queued(_asyncToGenerator(function* () {
390
+ const core = yield _this.ensure();
391
+ yield core.interrupt(source);
392
+ _this.current = core.session;
393
+ media.play().catch(() => void 0);
394
+ }));
395
+ }
396
+ /**
397
+ * Plays the programme again where `interrupt` left it, in the play state
398
+ * it had, or as `options` says: `at` another position, such as its end
399
+ * after a post-roll, and `playing`.
400
+ */
401
+ resume(options = {}) {
402
+ var _this2 = this;
403
+ var _options$playing;
404
+ const left = this.interruption;
405
+ if (left === null) return Promise.resolve();
406
+ this.interruption = null;
407
+ const at = options.at === void 0 ? left.at : options.at;
408
+ const playing = (_options$playing = options.playing) !== null && _options$playing !== void 0 ? _options$playing : left.playing;
409
+ return this.queued(_asyncToGenerator(function* () {
410
+ var _this$current$engine3, _this$current3;
411
+ const core = yield _this2.ensure();
412
+ yield core.resume(at !== null && at !== void 0 ? at : void 0);
413
+ _this2.current = core.session;
414
+ restore((_this$current$engine3 = (_this$current3 = _this2.current) === null || _this$current3 === void 0 ? void 0 : _this$current3.engine) !== null && _this$current$engine3 !== void 0 ? _this$current$engine3 : null, left.had);
415
+ if (playing) _this2.media.play().catch(() => void 0);
416
+ }));
417
+ }
418
+ /** `interrupt` plays in the programme's place. */
419
+ get interrupted() {
420
+ return this.interruption !== null;
421
+ }
422
+ /** Runs `task` in the element's queue, and says how it went. */
423
+ queued(task) {
424
+ return new Promise((resolve, reject) => {
425
+ this.enqueue(() => task().then(resolve, reject));
426
+ });
427
+ }
362
428
  /** The other versions of the picture the source names at their own URLs, for the video menu. */
363
429
  get videoSources() {
364
430
  var _this$original$videoT, _this$original;
@@ -375,14 +441,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
375
441
  * Fires `videosourcechange`.
376
442
  */
377
443
  selectVideoSource(track) {
378
- var _programme$videoTrack, _this$current$engine2, _this$current2;
444
+ var _programme$videoTrack, _this$current$engine4, _this$current4;
379
445
  const programme = this.original;
380
446
  if (programme === null || track === this.version) return;
381
447
  if (track !== null && ((_programme$videoTrack = programme.videoTracks) === null || _programme$videoTrack === void 0 ? void 0 : _programme$videoTrack.includes(track)) !== true) return;
382
448
  const media = this.media;
383
449
  const at = Number.isFinite(media.duration) ? media.currentTime : null;
384
450
  const playing = !media.paused;
385
- 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);
451
+ const had = chosen((_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);
386
452
  this.version = track;
387
453
  this.emit("videosourcechange", track);
388
454
  this.swap(track === null ? programme : versionSource(track, emeAvailable()), at, playing, had, true);
@@ -394,7 +460,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
394
460
  * before, so the controls show that state through the load.
395
461
  */
396
462
  swap(source, at, playing, had, hold) {
397
- var _this = this;
463
+ var _this3 = this;
398
464
  var _this$held;
399
465
  const media = this.media;
400
466
  (_this$held = this.held) === null || _this$held === void 0 || _this$held.call(this);
@@ -413,20 +479,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
413
479
  release = done;
414
480
  }
415
481
  this.enqueue(_asyncToGenerator(function* () {
416
- var _this$current$engine3, _this$current3;
417
- const core = yield _this.ensure();
418
- _this.switching = true;
482
+ var _this$current$engine5, _this$current5;
483
+ const core = yield _this3.ensure();
484
+ _this3.switching = true;
419
485
  try {
420
486
  yield core.load([source]);
421
487
  } catch (_unused) {
422
488
  release === null || release === void 0 || release();
423
489
  return;
424
490
  } finally {
425
- _this.switching = false;
491
+ _this3.switching = false;
426
492
  }
427
493
  resume(media, at, playing);
428
494
  if (release !== null) onNextFrame(media, at, release);
429
- 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);
495
+ restore((_this$current$engine5 = (_this$current5 = _this3.current) === null || _this$current5 === void 0 ? void 0 : _this$current5.engine) !== null && _this$current$engine5 !== void 0 ? _this$current$engine5 : null, had);
430
496
  }));
431
497
  }
432
498
  /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
@@ -435,8 +501,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
435
501
  }
436
502
  /** The engine feeding the video, or null for a native session and before the first load. */
437
503
  get engine() {
438
- var _this$current$engine4, _this$current4;
439
- 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;
504
+ var _this$current$engine6, _this$current6;
505
+ return (_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;
440
506
  }
441
507
  /**
442
508
  * The fatal error of the current load, or null once a load starts or
@@ -536,8 +602,22 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
536
602
  }
537
603
  this.measure();
538
604
  this.watchLanguage();
605
+ this.attachAddons();
539
606
  this.reload();
540
607
  }
608
+ /**
609
+ * Attaches each add-on of the options once. At connect, and again at each
610
+ * load: a page that imports the player registers it before its own
611
+ * `define()` gives the add-ons, and the players already on the page
612
+ * connected then.
613
+ */
614
+ attachAddons() {
615
+ var _this$options$addons;
616
+ for (const addon of (_this$options$addons = this.options.addons) !== null && _this$options$addons !== void 0 ? _this$options$addons : []) {
617
+ var _addon$attach;
618
+ if (!this.attached.has(addon)) this.attached.set(addon, (_addon$attach = addon.attach) === null || _addon$attach === void 0 ? void 0 : _addon$attach.call(addon, this));
619
+ }
620
+ }
541
621
  /** Sets `layout` from the element's box, unless the page fixed it. */
542
622
  measure() {
543
623
  if (this.fixed) return;
@@ -582,8 +662,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
582
662
  * reads as off, as in the subtitles menu.
583
663
  */
584
664
  tracks() {
585
- var _this$current$engine5, _this$current5;
586
- 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;
665
+ var _this$current$engine7, _this$current7;
666
+ const engine = (_this$current$engine7 = (_this$current7 = this.current) === null || _this$current7 === void 0 ? void 0 : _this$current7.engine) !== null && _this$current$engine7 !== void 0 ? _this$current$engine7 : null;
587
667
  let audio;
588
668
  let text;
589
669
  if (engine !== null) {
@@ -648,7 +728,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
648
728
  (_this$unwatch = this.unwatch) === null || _this$unwatch === void 0 || _this$unwatch.call(this);
649
729
  this.unwatch = null;
650
730
  queueMicrotask(() => {
651
- if (!this.isConnected) this.enqueue(() => this.teardown());
731
+ if (this.isConnected) return;
732
+ for (const off of this.attached.values()) off === null || off === void 0 || off();
733
+ this.attached.clear();
734
+ this.enqueue(() => this.teardown());
652
735
  });
653
736
  }
654
737
  attributeChangedCallback(name) {
@@ -683,6 +766,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
683
766
  if (name === "preset") this.enqueue(() => this.discard());
684
767
  if (name === "src" || name === "type") this.toggleAttribute("audio", this.audio());
685
768
  if (name === "src" && this.marks.list.length > 0) this.marks.set([]);
769
+ if (name === "src") this.interruption = null;
686
770
  if (name === "src") this.unblock();
687
771
  this.reload();
688
772
  }
@@ -707,9 +791,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
707
791
  }
708
792
  /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */
709
793
  chapters() {
710
- var _this$current$engine6, _this$current6;
794
+ var _this$current$engine8, _this$current8;
711
795
  const url = this.getAttribute(CHAPTERS);
712
- 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;
796
+ const engine = (_this$current$engine8 = (_this$current8 = this.current) === null || _this$current8 === void 0 ? void 0 : _this$current8.engine) !== null && _this$current$engine8 !== void 0 ? _this$current$engine8 : null;
713
797
  const api = engine === null ? void 0 : namespaces(engine).chapters;
714
798
  if (api !== void 0) {
715
799
  var _this$track;
@@ -777,23 +861,23 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
777
861
  this.emit("error", error);
778
862
  }
779
863
  run() {
780
- var _this2 = this;
864
+ var _this4 = this;
781
865
  return _asyncToGenerator(function* () {
782
- _this2.unmount();
783
- if (!_this2.isConnected) return;
784
- const sources = _this2.wanted();
785
- _this2.tried = JSON.stringify(sources);
866
+ _this4.unmount();
867
+ if (!_this4.isConnected) return;
868
+ const sources = _this4.wanted();
869
+ _this4.tried = JSON.stringify(sources);
786
870
  if (sources.length === 0) return;
787
- const core = yield _this2.ensure();
788
- _this2.failure = null;
789
- _this2.surface.clear();
790
- _this2.reflect();
871
+ const core = yield _this4.ensure();
872
+ _this4.failure = null;
873
+ _this4.surface.clear();
874
+ _this4.reflect();
791
875
  try {
792
876
  yield core.load(sources);
793
877
  } catch (_unused2) {
794
878
  return;
795
879
  }
796
- if (!_this2.isConnected) yield core.unload();
880
+ if (!_this4.isConnected) yield core.unload();
797
881
  })();
798
882
  }
799
883
  /**
@@ -835,33 +919,33 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
835
919
  this.chapters();
836
920
  }
837
921
  ensure() {
838
- var _this3 = this;
922
+ var _this5 = this;
839
923
  return _asyncToGenerator(function* () {
840
- if (_this3.core !== null) return _this3.core;
841
- const connectors = _this3.options.connectors;
842
- const core = createPlayer(_this3.media, _objectSpread2({ handlers: yield _this3.chain() }, connectors === void 0 ? {} : { connectors }));
843
- _this3.offs.push(core.on("programme", (programme) => {
844
- _this3.programmed(programme);
924
+ if (_this5.core !== null) return _this5.core;
925
+ const connectors = _this5.options.connectors;
926
+ const core = createPlayer(_this5.media, _objectSpread2({ handlers: yield _this5.chain() }, connectors === void 0 ? {} : { connectors }));
927
+ _this5.offs.push(core.on("programme", (programme) => {
928
+ _this5.programmed(programme);
845
929
  }), core.on("sourcechange", (session) => {
846
930
  var _this$offTracks, _session$engine$on, _session$engine;
847
- _this3.current = session;
848
- if (!_this3.switching) {
931
+ _this5.current = session;
932
+ if (!_this5.switching) {
849
933
  var _session$source, _this$held2;
850
- const was = _this3.version;
851
- _this3.original = (_session$source = session === null || session === void 0 ? void 0 : session.source) !== null && _session$source !== void 0 ? _session$source : null;
852
- _this3.switched = null;
853
- _this3.version = null;
854
- (_this$held2 = _this3.held) === null || _this$held2 === void 0 || _this$held2.call(_this3);
855
- if (was !== null) _this3.emit("videosourcechange", null);
934
+ const was = _this5.version;
935
+ _this5.original = (_session$source = session === null || session === void 0 ? void 0 : session.source) !== null && _session$source !== void 0 ? _session$source : null;
936
+ _this5.switched = null;
937
+ _this5.version = null;
938
+ (_this$held2 = _this5.held) === null || _this$held2 === void 0 || _this$held2.call(_this5);
939
+ if (was !== null) _this5.emit("videosourcechange", null);
856
940
  }
857
- (_this$offTracks = _this3.offTracks) === null || _this$offTracks === void 0 || _this$offTracks.call(_this3);
858
- _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;
859
- if (session !== null && _this3.isConnected) _this3.adopt(session);
860
- _this3.emit("sourcechange", session);
941
+ (_this$offTracks = _this5.offTracks) === null || _this$offTracks === void 0 || _this$offTracks.call(_this5);
942
+ _this5.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", () => _this5.tracks())) !== null && _session$engine$on !== void 0 ? _session$engine$on : null;
943
+ if (session !== null && _this5.isConnected) _this5.adopt(session);
944
+ _this5.emit("sourcechange", session);
861
945
  }), core.on("error", (error) => {
862
- _this3.report(error);
946
+ _this5.report(error);
863
947
  }));
864
- _this3.core = core;
948
+ _this5.core = core;
865
949
  return core;
866
950
  })();
867
951
  }
@@ -875,23 +959,32 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
875
959
  return (_this$own = this.own) !== null && _this$own !== void 0 ? _this$own : defaults;
876
960
  }
877
961
  chain() {
878
- var _this4 = this;
962
+ var _this6 = this;
879
963
  return _asyncToGenerator(function* () {
880
- var _this$getAttribute4;
881
- if (_this4.options.handlers !== void 0) return _this4.options.handlers;
882
- const config = _this4.options.config === void 0 ? {} : { config: _this4.options.config };
964
+ var _this$options$addons3, _this$getAttribute4;
965
+ if (_this6.options.handlers !== void 0) return _this6.options.handlers;
966
+ const config = _this6.options.config === void 0 ? {} : { config: _this6.options.config };
883
967
  const native = (stages) => nativeHandler({
884
- prefer: (source, env) => _this4.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
885
- drm: () => _this4.drm(stages)
968
+ prefer: (source, env) => {
969
+ var _this$options$addons2;
970
+ return _this6.getAttribute(NATIVE_HLS) !== "off" && !((_this$options$addons2 = _this6.options.addons) !== null && _this$options$addons2 !== void 0 ? _this$options$addons2 : []).some((addon) => addon.engine === true) && preferNativeHls(source, env);
971
+ },
972
+ drm: () => _this6.drm(stages)
973
+ });
974
+ if (_this6.isConnected) _this6.attachAddons();
975
+ const added = ((_this$options$addons3 = _this6.options.addons) !== null && _this$options$addons3 !== void 0 ? _this$options$addons3 : []).flatMap((addon) => {
976
+ var _addon$stages, _addon$stages2;
977
+ return (_addon$stages = (_addon$stages2 = addon.stages) === null || _addon$stages2 === void 0 ? void 0 : _addon$stages2.call(addon)) !== null && _addon$stages !== void 0 ? _addon$stages : [];
886
978
  });
887
- if (_this4.options.stages !== void 0) return [matteboxHandler(_objectSpread2({ stages: _this4.options.stages }, config)), native(() => {
888
- var _this$options$stages;
889
- return (_this$options$stages = _this4.options.stages) !== null && _this$options$stages !== void 0 ? _this$options$stages : [];
890
- })];
891
- const name = (_this$getAttribute4 = _this4.getAttribute("preset")) !== null && _this$getAttribute4 !== void 0 ? _this$getAttribute4 : DEFAULT_PRESET;
979
+ if (_this6.options.stages !== void 0) {
980
+ const own = _this6.options.stages;
981
+ const stages = [...own, ...added.filter((stage) => !own.some((o) => o.name === stage.name))];
982
+ return [matteboxHandler(_objectSpread2({ stages }, config)), native(() => stages)];
983
+ }
984
+ const name = (_this$getAttribute4 = _this6.getAttribute("preset")) !== null && _this$getAttribute4 !== void 0 ? _this$getAttribute4 : DEFAULT_PRESET;
892
985
  const preset = yield resolvePreset(name);
893
986
  if (preset === null) {
894
- _this4.report({
987
+ _this6.report({
895
988
  category: "config",
896
989
  code: "CONFIG_INVALID",
897
990
  fatal: true,
@@ -901,7 +994,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
901
994
  });
902
995
  return [nativeHandler()];
903
996
  }
904
- return [matteboxHandler(_objectSpread2(_objectSpread2({ preset }, config), drmGuard())), native(() => preset.stages())];
997
+ const extra = added.length === 0 ? {} : { stages: added };
998
+ return [matteboxHandler(_objectSpread2(_objectSpread2(_objectSpread2({ preset }, extra), config), drmGuard())), native(() => preset.stages())];
905
999
  })();
906
1000
  }
907
1001
  /**
@@ -939,20 +1033,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
939
1033
  this.current = null;
940
1034
  }
941
1035
  teardown() {
942
- var _this5 = this;
1036
+ var _this7 = this;
943
1037
  return _asyncToGenerator(function* () {
944
- _this5.unmount();
945
- if (_this5.core !== null) yield _this5.core.unload();
1038
+ _this7.unmount();
1039
+ if (_this7.core !== null) yield _this7.core.unload();
946
1040
  })();
947
1041
  }
948
1042
  /** Drops the player itself, so the next run builds a chain from the new preset. */
949
1043
  discard() {
950
- var _this6 = this;
1044
+ var _this8 = this;
951
1045
  return _asyncToGenerator(function* () {
952
- yield _this6.teardown();
953
- for (const off of _this6.offs) off();
954
- _this6.offs = [];
955
- _this6.core = null;
1046
+ yield _this8.teardown();
1047
+ for (const off of _this8.offs) off();
1048
+ _this8.offs = [];
1049
+ _this8.core = null;
956
1050
  })();
957
1051
  }
958
1052
  };
@@ -1,7 +1,7 @@
1
1
  import { Component } from "./component.js";
2
2
  import { BUTTON_STYLE, style } from "./shared.js";
3
3
  // src/elements/marker-button.ts
4
- const STYLE_CSS = ":host{right:calc(var(--mbx-pad,.5em) + .5em);bottom:calc(var(--mbx-marker-lift,3.5em) + .75em);z-index:1;transition:transform .3s;position:absolute}:host([idle]){transform:translateY(var(--mbx-marker-lift,3.5em))}:host([hidden]){display:none}[part~=button]{width:auto;height:2.5em;color:var(--mbx-text);font:inherit;white-space:nowrap;background:#0009;border:1px solid #ffffff80;padding:0 1.125em;font-weight:600}[part~=button]:hover{background:#000c}@media (prefers-reduced-motion:reduce){:host{transition:none}}";
4
+ const STYLE_CSS = ":host{right:calc(var(--mbx-pad,.5em) + .5em);bottom:calc(var(--mbx-marker-lift,3.5em) + .75em);z-index:1;position:absolute}:host([hidden]){display:none}[part~=button]{border-radius:var(--mbx-radius);backdrop-filter:blur(12px);width:auto;height:2.75em;color:var(--mbx-text);font:inherit;white-space:nowrap;background:#1c1c20b8;border:0;align-items:center;padding:0 .85em 0 1.1em;font-size:1.07em;font-weight:600;display:inline-flex}[part~=button]:hover{background:#1c1c20e6}[part~=icon]{fill:none;stroke:currentColor;stroke-width:3px;stroke-linecap:round;stroke-linejoin:round;width:1.25em;height:1.25em;margin-inline-start:.3em}";
5
5
  /** The id and the English of the button over each kind of range. */
6
6
  const WORDS = {
7
7
  "opening-credits": ["skipIntro", "Skip intro"],
@@ -23,7 +23,16 @@ var MbxMarkerButton = class extends Component {
23
23
  this.button = document.createElement("button");
24
24
  this.button.type = "button";
25
25
  this.button.setAttribute("part", "button");
26
- this.button.textContent = "Skip";
26
+ this.text = document.createElement("span");
27
+ this.text.textContent = "Skip";
28
+ const chevron = document.createElementNS("http://www.w3.org/2000/svg", "svg");
29
+ chevron.setAttribute("viewBox", "0 0 32 32");
30
+ chevron.setAttribute("aria-hidden", "true");
31
+ chevron.setAttribute("part", "icon");
32
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
33
+ path.setAttribute("d", "M12 8l8 8l-8 8");
34
+ chevron.append(path);
35
+ this.button.append(this.text, chevron);
27
36
  this.button.addEventListener("click", () => {
28
37
  var _this$player;
29
38
  const video = (_this$player = this.player) === null || _this$player === void 0 ? void 0 : _this$player.video;
@@ -49,11 +58,6 @@ var MbxMarkerButton = class extends Component {
49
58
  this.observe(player, ["upnext"], () => {
50
59
  this.render();
51
60
  });
52
- const idle = () => {
53
- this.toggleAttribute("idle", player.hasAttribute("idle"));
54
- };
55
- this.observe(player, ["idle"], idle);
56
- idle();
57
61
  if (typeof ResizeObserver !== "undefined") {
58
62
  this.resizer = new ResizeObserver(() => {
59
63
  this.fit(player);
@@ -91,7 +95,7 @@ var MbxMarkerButton = class extends Component {
91
95
  const kind = this.marker.kind;
92
96
  const skip = this.word("label-skip", "skip", "Skip");
93
97
  const known = WORDS[kind];
94
- this.button.textContent = known !== void 0 ? this.word(`label-${kind}`, ...known) : (_this$getAttribute = this.getAttribute(`label-${kind}`)) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : this.marker.label === void 0 ? skip : `${skip} ${this.pageText(this.marker.label)}`;
98
+ this.text.textContent = known !== void 0 ? this.word(`label-${kind}`, ...known) : (_this$getAttribute = this.getAttribute(`label-${kind}`)) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : this.marker.label === void 0 ? skip : `${skip} ${this.pageText(this.marker.label)}`;
95
99
  }
96
100
  };
97
101
  export { MbxMarkerButton };
@@ -35,6 +35,7 @@ var MbxQualityMenu = class extends MenuElement {
35
35
  const offs = [
36
36
  () => player.video.removeEventListener("timeupdate", clock),
37
37
  engine.on("tracks:changed", tick),
38
+ engine.on("tracks:selected", tick),
38
39
  engine.on("quality:constraints-unsatisfiable", tick),
39
40
  engine.on("quality:pin-unsatisfiable", tick)
40
41
  ];
@@ -8,7 +8,7 @@ import { bufferGoal, live, optional, span, wall } from "../controls/session.js";
8
8
  import { chapterAt, chapters, followChapters } from "../controls/chapters.js";
9
9
  import { slider } from "../controls/slider.js";
10
10
  // src/elements/seek-bar.ts
11
- const STYLE_CSS = ":host,[part~=slider]{flex:1}[part~=thumb]{width:1em;height:1em;margin:-.5em 0 0 -.5em;box-shadow:0 1px 3px #0006}[part~=buffered]{position:absolute;top:0;bottom:0;left:0;right:0}[part~=blocked]{pointer-events:none;position:absolute;top:0;bottom:0;left:0;right:0}[part~=blocked-range]{background:var(--mbx-blocked,#000000bf);position:absolute;top:0;bottom:0}[part~=buffered-range]{background:#ffffff4d;position:absolute;top:0;bottom:0}[part~=hover]{background:var(--mbx-text);width:.125em;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=edge]{background:var(--mbx-live);width:.125em;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=preview]{background:var(--mbx-surface);border-radius:var(--mbx-radius);font-variant-numeric:tabular-nums;white-space:nowrap;pointer-events:none;flex-direction:column;align-items:center;margin-bottom:.3077em;padding:.1538em;font-size:.8125em;display:flex;position:absolute;bottom:100%;transform:translate(-50%)}[part~=preview]>:not([hidden])~:not([hidden]){margin-top:.125em}[part~=preview-image]{border-radius:2px;position:relative;overflow:hidden}[part~=preview-frame]{border-radius:2px;display:block}[part~=preview-tile]{transform-origin:0 0;background-repeat:no-repeat;position:absolute;top:0;left:0}[part~=preview-time]{padding:0 .3077em}[part~=preview-title]{text-overflow:ellipsis;max-width:18.4615em;padding:0 .3077em;overflow:hidden}[hidden]{display:none}";
11
+ const STYLE_CSS = ":host,[part~=slider]{flex:1}[part~=thumb]{width:1em;height:1em;margin:-.5em 0 0 -.5em;box-shadow:0 1px 3px #0006}[part~=buffered]{position:absolute;top:0;bottom:0;left:0;right:0}[part~=blocked]{pointer-events:none;position:absolute;top:0;bottom:0;left:0;right:0}[part~=blocked-range]{background:var(--mbx-blocked,#000000bf);position:absolute;top:0;bottom:0}[part~=break]{background:var(--mbx-ad,#f5c518);width:.25em;margin-left:-.125em;position:absolute;top:0;bottom:0}[part~=break][part~=span]{margin-left:0}[part~=break][part~=played]{opacity:.4}[part~=buffered-range]{background:#ffffff4d;position:absolute;top:0;bottom:0}[part~=hover]{background:var(--mbx-text);width:.125em;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=edge]{background:var(--mbx-live);width:.125em;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=preview]{background:var(--mbx-surface);border-radius:var(--mbx-radius);font-variant-numeric:tabular-nums;white-space:nowrap;pointer-events:none;flex-direction:column;align-items:center;margin-bottom:.3077em;padding:.1538em;font-size:.8125em;display:flex;position:absolute;bottom:100%;transform:translate(-50%)}[part~=preview]>:not([hidden])~:not([hidden]){margin-top:.125em}[part~=preview-image]{border-radius:2px;position:relative;overflow:hidden}[part~=preview-frame]{border-radius:2px;display:block}[part~=preview-tile]{transform-origin:0 0;background-repeat:no-repeat;position:absolute;top:0;left:0}[part~=preview-time]{padding:0 .3077em}[part~=preview-title]{text-overflow:ellipsis;max-width:18.4615em;padding:0 .3077em;overflow:hidden}[hidden]{display:none}";
12
12
  const STEP = 5;
13
13
  /** Under `key-mode="preview"`, a target seeks this long after the last key. */
14
14
  const KEY_COMMIT_MS = 1e3;
@@ -108,12 +108,13 @@ var MbxSeekBar = class extends Component {
108
108
  });
109
109
  this.buffered = el("div", "buffered");
110
110
  this.blocked = el("div", "blocked");
111
+ this.breaks = el("div", "breaks");
111
112
  this.hover = el("div", "hover");
112
113
  this.edge = el("div", "edge");
113
114
  this.hover.hidden = true;
114
115
  this.edge.hidden = true;
115
116
  this.bar.track.prepend(this.buffered);
116
- this.bar.track.append(this.blocked, this.hover, this.edge);
117
+ this.bar.track.append(this.blocked, this.breaks, this.hover, this.edge);
117
118
  this.preview = el("div", "preview");
118
119
  this.image = el("div", "preview-image");
119
120
  this.tile = el("div", "preview-tile");
@@ -412,12 +413,28 @@ var MbxSeekBar = class extends Component {
412
413
  node.style.width = percent(part[1] - part[0]);
413
414
  }
414
415
  }
416
+ /** The ad breaks inside the bar's range: a tick at each start, a span where one replaces a part. */
417
+ paintBreaks() {
418
+ var _this$player$breaks$l, _this$player14, _this$breaks$lastElem;
419
+ const { start, end } = this.range;
420
+ const marks = ((_this$player$breaks$l = (_this$player14 = this.player) === null || _this$player14 === void 0 ? void 0 : _this$player14.breaks.list) !== null && _this$player$breaks$l !== void 0 ? _this$player$breaks$l : []).filter((mark) => mark.start >= start && mark.start <= end);
421
+ while (this.breaks.childElementCount > marks.length) (_this$breaks$lastElem = this.breaks.lastElementChild) === null || _this$breaks$lastElem === void 0 || _this$breaks$lastElem.remove();
422
+ while (this.breaks.childElementCount < marks.length) this.breaks.append(el("div", "break"));
423
+ marks.forEach((mark, i) => {
424
+ var _mark$end;
425
+ const node = this.breaks.children[i];
426
+ const span = mark.end !== void 0 && mark.end > mark.start;
427
+ node.setAttribute("part", `break${span ? " span" : ""}${mark.played === true ? " played" : ""}`);
428
+ node.style.left = percent(fraction(mark.start, this.range));
429
+ node.style.width = span ? percent(fraction(Math.min((_mark$end = mark.end) !== null && _mark$end !== void 0 ? _mark$end : end, end), this.range) - fraction(mark.start, this.range)) : "";
430
+ });
431
+ }
415
432
  /** Whether a live window is wide enough to be worth a bar. */
416
433
  worthSeeking() {
417
- var _bufferGoal, _this$player$engine7, _this$player14;
434
+ var _bufferGoal, _this$player$engine7, _this$player15;
418
435
  const goals = number(this, "live-window", LIVE_WINDOW);
419
436
  if (goals === 0) return true;
420
- const goal = (_bufferGoal = bufferGoal((_this$player$engine7 = (_this$player14 = this.player) === null || _this$player14 === void 0 ? void 0 : _this$player14.engine) !== null && _this$player$engine7 !== void 0 ? _this$player$engine7 : null)) !== null && _bufferGoal !== void 0 ? _bufferGoal : BUFFER_GOAL;
437
+ const goal = (_bufferGoal = bufferGoal((_this$player$engine7 = (_this$player15 = this.player) === null || _this$player15 === void 0 ? void 0 : _this$player15.engine) !== null && _this$player$engine7 !== void 0 ? _this$player$engine7 : null)) !== null && _bufferGoal !== void 0 ? _bufferGoal : BUFFER_GOAL;
421
438
  return this.range.end - this.range.start >= goals * goal;
422
439
  }
423
440
  /** The hover marker and the preview follow the pointer, clamped to the bar. */
@@ -431,14 +448,14 @@ var MbxSeekBar = class extends Component {
431
448
  }
432
449
  /** The preview over `part` of the bar: the time, the chapter, and the picture. */
433
450
  previewAt(part) {
434
- var _this$player15, _chapter$title;
451
+ var _this$player16, _chapter$title;
435
452
  const rect = this.bar.rail.getBoundingClientRect();
436
453
  if (rect.width === 0 || this.range.end <= this.range.start) return;
437
454
  this.preview.hidden = false;
438
455
  const when = at(part, this.range);
439
456
  this.time.textContent = this.label(when);
440
457
  const chapter = this.chaptered("titles") ? this.list[chapterAt(this.list, when)] : void 0;
441
- const blocked = (_this$player15 = this.player) === null || _this$player15 === void 0 ? void 0 : _this$player15.markers.within(when).find((marker) => marker.kind === "blocked");
458
+ const blocked = (_this$player16 = this.player) === null || _this$player16 === void 0 ? void 0 : _this$player16.markers.within(when).find((marker) => marker.kind === "blocked");
442
459
  const title = blocked ? blocked.label === void 0 ? this.word("label-blocked", "blocked", "Not available") : this.pageText(blocked.label) : (_chapter$title = chapter === null || chapter === void 0 ? void 0 : chapter.title) !== null && _chapter$title !== void 0 ? _chapter$title : "";
443
460
  this.caption.hidden = title === "";
444
461
  this.caption.textContent = title;
@@ -462,7 +479,7 @@ var MbxSeekBar = class extends Component {
462
479
  };
463
480
  this.listen(player.video, EVENTS, tick);
464
481
  this.keep(followChapters(player, tick));
465
- this.listen(player, ["markerschange"], tick);
482
+ this.listen(player, ["markerschange", "breakschange"], tick);
466
483
  this.listen(player, ["sourcechange"], () => {
467
484
  this.drag = "none";
468
485
  this.stopAiming();
@@ -508,6 +525,7 @@ var MbxSeekBar = class extends Component {
508
525
  this.bar.range(this.range.start, this.range.end);
509
526
  this.paintRanges(this.buffered, spans(video.buffered), "buffered-range");
510
527
  this.paintRanges(this.blocked, this.blockedRanges(), "blocked-range");
528
+ this.paintBreaks();
511
529
  this.paintChapters();
512
530
  this.edge.hidden = !on;
513
531
  if (api !== void 0 && api.edge !== null) this.edge.style.left = percent(fraction(api.edge, this.range));
@@ -1,5 +1,5 @@
1
1
  import { Component } from "./component.js";
2
- import { style } from "./shared.js";
2
+ import { HELD, shownPaused, style } from "./shared.js";
3
3
  // src/elements/spinner.ts
4
4
  const STYLE = ":host{pointer-events:none;width:2.75em;height:2.75em;color:var(--mbx-text);filter:drop-shadow(0 1px 3px #00000080);margin:-1.375em 0 0 -1.375em;display:none;position:absolute;top:50%;left:50%}:host([waiting]){display:block}:host([hidden]){display:none}[part~=ring]{box-sizing:border-box;border:3px solid #ffffff38;border-top-color:currentColor;border-radius:50%;width:100%;height:100%;animation:.8s linear infinite mbx-turn}[part~=ring][hidden],slot[hidden]{display:none}::slotted(*){width:100%;height:100%}@keyframes mbx-turn{to{transform:rotate(360deg)}}@media (prefers-reduced-motion:reduce){[part~=ring]{animation:none}}";
5
5
  /** What the video fires as it waits and as it goes on. */
@@ -7,7 +7,9 @@ const EVENTS = [
7
7
  "waiting",
8
8
  "playing",
9
9
  "canplay",
10
- "emptied"
10
+ "emptied",
11
+ "play",
12
+ "pause"
11
13
  ];
12
14
  var MbxSpinner = class extends Component {
13
15
  static get observedAttributes() {
@@ -35,6 +37,9 @@ var MbxSpinner = class extends Component {
35
37
  this.listen(video, EVENTS, () => {
36
38
  this.render();
37
39
  });
40
+ this.observe(player, HELD, () => {
41
+ this.render();
42
+ });
38
43
  this.render();
39
44
  }
40
45
  detach() {
@@ -44,7 +49,7 @@ var MbxSpinner = class extends Component {
44
49
  const player = this.player;
45
50
  if (player === null) return;
46
51
  this.setAttribute("aria-label", this.word("label", "loading", "Loading"));
47
- this.toggleAttribute("waiting", player.hasAttribute("waiting"));
52
+ this.toggleAttribute("waiting", player.hasAttribute("waiting") && !shownPaused(player));
48
53
  }
49
54
  };
50
55
  export { MbxSpinner };
@@ -117,7 +117,7 @@ var MbxStartButton = class extends Component {
117
117
  show(this.slots, state);
118
118
  this.button.setAttribute("aria-label", state === "play" ? this.word("label-play", "play", "Play") : this.word("label-replay", "replay", "Replay"));
119
119
  const player = this.player;
120
- 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;
120
+ this.hidden = this.failed || player !== null && !shownPaused(player);
121
121
  }
122
122
  };
123
123
  export { MbxStartButton };
@@ -1,6 +1,6 @@
1
1
  import { el } from "../dom.js";
2
2
  import { Component } from "./component.js";
3
- import { shownPaused, style } from "./shared.js";
3
+ import { HELD, shownPaused, style } from "./shared.js";
4
4
  // src/elements/title.ts
5
5
  /**
6
6
  * <mbx-title>: the heading, the subheading and the artwork of what plays,
@@ -16,7 +16,9 @@ import { shownPaused, style } from "./shared.js";
16
16
  * the element draws nothing.
17
17
  *
18
18
  * Shown while the video is paused, which includes before the first play,
19
- * and hidden while it plays. The element carries `playing` for that rule,
19
+ * and hidden while it plays. A drag on the seek bar and a switch to another
20
+ * source keep the state from before, so a seek while playing never shows
21
+ * it. The element carries `playing` for that rule,
20
22
  * so a page changes it in CSS: `mattebox-player[started] mbx-title
21
23
  * { display: none }` keeps it to the time before the first play, like the
22
24
  * poster, and `mattebox-player:hover mbx-title { display: flex }` brings it
@@ -58,7 +60,7 @@ var MbxTitle = class extends Component {
58
60
  ], () => {
59
61
  this.state(player);
60
62
  });
61
- this.observe(player, ["switching"], () => {
63
+ this.observe(player, HELD, () => {
62
64
  this.state(player);
63
65
  });
64
66
  this.listen(player, ["programmechange"], () => {
@@ -85,7 +87,7 @@ var MbxTitle = class extends Component {
85
87
  }
86
88
  /** `playing` on the element, for its own stylesheet and the page's. */
87
89
  state(player) {
88
- this.toggleAttribute("playing", !shownPaused(player, ["switching"]));
90
+ this.toggleAttribute("playing", !shownPaused(player));
89
91
  }
90
92
  /** The height of the bar's rows: its box less the padding above them, which is its fade. Zero without a bar. */
91
93
  fit(player) {