@mattebox/player 0.7.0 → 0.8.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 (96) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/icons.d.ts +3 -1
  3. package/dist/controls/icons.d.ts.map +1 -1
  4. package/dist/controls/icons.js +27 -27
  5. package/dist/controls/icons.js.map +1 -1
  6. package/dist/controls/markers.d.ts +39 -0
  7. package/dist/controls/markers.d.ts.map +1 -0
  8. package/dist/controls/markers.js +38 -0
  9. package/dist/controls/markers.js.map +1 -0
  10. package/dist/controls/menu.d.ts +3 -2
  11. package/dist/controls/menu.d.ts.map +1 -1
  12. package/dist/controls/menu.js +23 -3
  13. package/dist/controls/menu.js.map +1 -1
  14. package/dist/controls/native-tracks.d.ts +28 -0
  15. package/dist/controls/native-tracks.d.ts.map +1 -0
  16. package/dist/controls/native-tracks.js +30 -0
  17. package/dist/controls/native-tracks.js.map +1 -0
  18. package/dist/controls/quality-names.d.ts +15 -0
  19. package/dist/controls/quality-names.d.ts.map +1 -0
  20. package/dist/controls/quality-names.js +62 -0
  21. package/dist/controls/quality-names.js.map +1 -0
  22. package/dist/controls/track-names.d.ts +40 -0
  23. package/dist/controls/track-names.d.ts.map +1 -0
  24. package/dist/controls/track-names.js +59 -0
  25. package/dist/controls/track-names.js.map +1 -0
  26. package/dist/element.d.ts +24 -0
  27. package/dist/element.d.ts.map +1 -1
  28. package/dist/element.js +47 -4
  29. package/dist/element.js.map +1 -1
  30. package/dist/elements/audio-menu.d.ts +19 -8
  31. package/dist/elements/audio-menu.d.ts.map +1 -1
  32. package/dist/elements/audio-menu.js +57 -18
  33. package/dist/elements/audio-menu.js.map +1 -1
  34. package/dist/elements/drm-badge.d.ts +3 -2
  35. package/dist/elements/drm-badge.d.ts.map +1 -1
  36. package/dist/elements/drm-badge.js +10 -8
  37. package/dist/elements/drm-badge.js.map +1 -1
  38. package/dist/elements/marker-button.d.ts +22 -0
  39. package/dist/elements/marker-button.d.ts.map +1 -0
  40. package/dist/elements/marker-button.js +99 -0
  41. package/dist/elements/marker-button.js.map +1 -0
  42. package/dist/elements/quality-menu.d.ts +4 -0
  43. package/dist/elements/quality-menu.d.ts.map +1 -1
  44. package/dist/elements/quality-menu.js +21 -7
  45. package/dist/elements/quality-menu.js.map +1 -1
  46. package/dist/elements/seek-bar.d.ts +6 -1
  47. package/dist/elements/seek-bar.d.ts.map +1 -1
  48. package/dist/elements/seek-bar.js +33 -22
  49. package/dist/elements/seek-bar.js.map +1 -1
  50. package/dist/elements/shared.js +1 -1
  51. package/dist/elements/subtitles-menu.d.ts +2 -0
  52. package/dist/elements/subtitles-menu.d.ts.map +1 -1
  53. package/dist/elements/subtitles-menu.js +33 -9
  54. package/dist/elements/subtitles-menu.js.map +1 -1
  55. package/dist/entries/marker-button.d.ts +5 -0
  56. package/dist/entries/marker-button.d.ts.map +1 -0
  57. package/dist/entries/marker-button.js +9 -0
  58. package/dist/entries/marker-button.js.map +1 -0
  59. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/asyncToGenerator.js +1 -1
  60. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/defineProperty.js +1 -1
  61. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/objectSpread2.js +1 -1
  62. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPrimitive.js +1 -1
  63. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPropertyKey.js +1 -1
  64. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/typeof.js +1 -1
  65. package/dist/es2015/controls/chapters.js +1 -1
  66. package/dist/es2015/controls/icons.js +27 -27
  67. package/dist/es2015/controls/markers.js +36 -0
  68. package/dist/es2015/controls/menu.js +24 -4
  69. package/dist/es2015/controls/native-tracks.js +29 -0
  70. package/dist/es2015/controls/quality-names.js +67 -0
  71. package/dist/es2015/controls/track-names.js +57 -0
  72. package/dist/es2015/element.js +48 -6
  73. package/dist/es2015/elements/audio-menu.js +62 -19
  74. package/dist/es2015/elements/drm-badge.js +11 -8
  75. package/dist/es2015/elements/marker-button.js +100 -0
  76. package/dist/es2015/elements/quality-menu.js +22 -7
  77. package/dist/es2015/elements/seek-bar.js +38 -26
  78. package/dist/es2015/elements/shared.js +1 -1
  79. package/dist/es2015/elements/subtitles-menu.js +39 -11
  80. package/dist/es2015/entries/marker-button.js +7 -0
  81. package/dist/es2015/index.js +3 -1
  82. package/dist/es2015/presets.js +1 -1
  83. package/dist/es2015/style.js +1 -1
  84. package/dist/es2015/tags.js +2 -1
  85. package/dist/host.d.ts +3 -0
  86. package/dist/host.d.ts.map +1 -1
  87. package/dist/host.js.map +1 -1
  88. package/dist/index.d.ts +4 -0
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +3 -1
  91. package/dist/style.js +1 -1
  92. package/dist/tags.d.ts +1 -0
  93. package/dist/tags.d.ts.map +1 -1
  94. package/dist/tags.js +2 -1
  95. package/dist/tags.js.map +1 -1
  96. package/package.json +3 -3
@@ -0,0 +1,67 @@
1
+ //#region src/controls/quality-names.ts
2
+ /** The codec families a viewer may recognise, by their RFC 6381 prefix. */
3
+ const CODECS = [
4
+ [/^av(c1|c3)/, "H.264"],
5
+ [/^h(vc1|ev1)/, "HEVC"],
6
+ [/^vp0?9/, "VP9"],
7
+ [/^av01/, "AV1"]
8
+ ];
9
+ /** Dolby Vision, in the codec itself or as a layer over it. */
10
+ function dolbyVision(rendition) {
11
+ var _rendition$codecs, _rendition$supplement;
12
+ const codecs = `${(_rendition$codecs = rendition.codecs) !== null && _rendition$codecs !== void 0 ? _rendition$codecs : ""},${(_rendition$supplement = rendition.supplementalCodecs) !== null && _rendition$supplement !== void 0 ? _rendition$supplement : ""}`;
13
+ return /(^|[,/])\s*(dvh1|dvhe|dav1|dva1)/.test(codecs);
14
+ }
15
+ /** 0 for SDR, 1 for HDR, 2 for Dolby Vision: the sort order and the word. */
16
+ function range(rendition) {
17
+ if (dolbyVision(rendition)) return 2;
18
+ return rendition.videoRange === "PQ" || rendition.videoRange === "HLG" ? 1 : 0;
19
+ }
20
+ function rate(rendition) {
21
+ var _rendition$frameRate;
22
+ return Math.round((_rendition$frameRate = rendition.frameRate) !== null && _rendition$frameRate !== void 0 ? _rendition$frameRate : 0);
23
+ }
24
+ /** The average bitrate where the manifest gives one: closer to what plays. */
25
+ function bitrate(rendition) {
26
+ var _rendition$averageBit;
27
+ const bps = (_rendition$averageBit = rendition.averageBitrate) !== null && _rendition$averageBit !== void 0 ? _rendition$averageBit : rendition.bitrate;
28
+ return bps < 1e6 ? `${Math.round(bps / 1e3)} kbps` : `${(bps / 1e6).toFixed(1)} Mbps`;
29
+ }
30
+ function codec(rendition) {
31
+ var _rendition$codecs2, _CODECS$find;
32
+ const codecs = (_rendition$codecs2 = rendition.codecs) !== null && _rendition$codecs2 !== void 0 ? _rendition$codecs2 : "";
33
+ return (_CODECS$find = CODECS.find(([pattern]) => pattern.test(codecs))) === null || _CODECS$find === void 0 ? void 0 : _CODECS$find[1];
34
+ }
35
+ /** The label of every rendition, best first, twins included. */
36
+ function qualityLabels(renditions) {
37
+ const sorted = [...renditions].sort((a, b) => {
38
+ var _b$height, _a$height, _b$averageBitrate, _a$averageBitrate;
39
+ return ((_b$height = b.height) !== null && _b$height !== void 0 ? _b$height : 0) - ((_a$height = a.height) !== null && _a$height !== void 0 ? _a$height : 0) || rate(b) - rate(a) || range(b) - range(a) || ((_b$averageBitrate = b.averageBitrate) !== null && _b$averageBitrate !== void 0 ? _b$averageBitrate : b.bitrate) - ((_a$averageBitrate = a.averageBitrate) !== null && _a$averageBitrate !== void 0 ? _a$averageBitrate : a.bitrate);
40
+ });
41
+ const bases = sorted.map((r) => {
42
+ return `${r.height === void 0 ? bitrate(r) : `${r.height}p`}${rate(r) > 30 ? String(rate(r)) : ""}${[
43
+ "",
44
+ " HDR",
45
+ " Dolby Vision"
46
+ ][range(r)]}`;
47
+ });
48
+ let labels = bases;
49
+ for (const part of [bitrate, codec]) labels = labels.map((label, i) => {
50
+ const twin = labels.some((other, j) => j !== i && other === label);
51
+ const extra = part(sorted[i]);
52
+ return twin && extra !== void 0 && !label.endsWith(extra) ? `${label} · ${extra}` : label;
53
+ });
54
+ labels = labels.map((label, i) => bases.every((base, j) => base !== bases[i] || labels[j] === label) ? bases[i] : label);
55
+ return sorted.map((r, i) => [r.id, labels[i]]);
56
+ }
57
+ /** The label of each rendition, best first, one entry per distinct label. */
58
+ function qualityNames(renditions) {
59
+ const seen = /* @__PURE__ */ new Set();
60
+ return qualityLabels(renditions).filter(([, label]) => {
61
+ if (seen.has(label)) return false;
62
+ seen.add(label);
63
+ return true;
64
+ });
65
+ }
66
+ //#endregion
67
+ export { qualityLabels, qualityNames };
@@ -0,0 +1,57 @@
1
+ //#region src/controls/track-names.ts
2
+ /**
3
+ * The language's name in `locale`, with a capital first letter as the
4
+ * browsers' own menus show it: French gives "anglais", the menu shows
5
+ * "Anglais". Undefined without `Intl.DisplayNames` (Chromium 81, so not on
6
+ * Tizen 6 or webOS 6), for a code it does not know, and for a locale or a
7
+ * code it rejects.
8
+ */
9
+ function languageName(lang, locale) {
10
+ try {
11
+ const name = new Intl.DisplayNames(locale, {
12
+ type: "language",
13
+ fallback: "none"
14
+ }).of(lang);
15
+ return name.charAt(0).toUpperCase() + name.slice(1);
16
+ } catch (_unused) {
17
+ return;
18
+ }
19
+ }
20
+ const LAYOUTS = {
21
+ 1: "Mono",
22
+ 2: "Stereo",
23
+ 6: "5.1",
24
+ 8: "7.1"
25
+ };
26
+ /**
27
+ * The audio layout of an HLS CHANNELS value (RFC 8216bis §4.4.6.1): "2"
28
+ * reads Stereo, "6" reads 5.1, a "/JOC" suffix reads Dolby Atmos. Any
29
+ * other count reads as written.
30
+ */
31
+ function layout(channels) {
32
+ return channels && (/\/JOC$/.test(channels) ? "Dolby Atmos" : LAYOUTS[channels] || channels);
33
+ }
34
+ /**
35
+ * The entries as menu items. Each reads as its name, else its language's
36
+ * name, else its language code, else `word` ("Track") and its place. An
37
+ * entry that would read like another, badges included, takes in
38
+ * parentheses its first hint that differs from the other's, and at last
39
+ * its place.
40
+ */
41
+ function trackNames(entries, word, locale = document.documentElement.lang || navigator.language) {
42
+ let texts = entries.map(([, name, lang], index) => name || lang && (languageName(lang, locale) || lang) || `${word || "Track"} ${index + 1}`);
43
+ for (let round = 0; round < 3; round++) {
44
+ const keys = texts.map((text, index) => text + entries[index][3]);
45
+ const hint = (index) => round < 2 ? entries[index][4][round] : String(index + 1);
46
+ texts = texts.map((text, index) => hint(index) && keys.some((key, other) => other !== index && key === keys[index] && hint(other) !== hint(index)) ? `${text} (${hint(index)})` : text);
47
+ }
48
+ return entries.map(([value, , , badges], index) => [
49
+ value,
50
+ texts[index],
51
+ void 0,
52
+ void 0,
53
+ badges
54
+ ]);
55
+ }
56
+ //#endregion
57
+ export { languageName, layout, trackNames };
@@ -1,12 +1,19 @@
1
+ import { createMarkers } from "./controls/markers.js";
1
2
  import { namespaces } from "./namespaces.js";
2
- import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
3
+ import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/asyncToGenerator.js";
3
4
  import { drmGuard, resolvePreset } from "./presets.js";
4
5
  import { STYLE } from "./style.js";
5
6
  import { errorSurface } from "./surface.js";
6
7
  import { PLAYER } from "./tags.js";
7
- import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
8
- import { createPlayer, inferType, matteboxHandler, nativeHandler } from "@mattebox/player-core";
8
+ import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/objectSpread2.js";
9
+ import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHls } from "@mattebox/player-core";
9
10
  //#region src/element.ts
11
+ /**
12
+ * `off` keeps HLS on the engine in Safari. Anything else lets Safari play
13
+ * HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's
14
+ * fullscreen then work as Apple built them. Changing it reloads.
15
+ */
16
+ const NATIVE_HLS = "native-hls";
10
17
  /** Attributes forwarded onto the video as attributes, never as properties. */
11
18
  const FORWARDED = [
12
19
  "autoplay",
@@ -20,7 +27,9 @@ const OWN = [
20
27
  "type",
21
28
  "preset",
22
29
  "license-url",
23
- "thumbnails"
30
+ "certificate-url",
31
+ "thumbnails",
32
+ NATIVE_HLS
24
33
  ];
25
34
  /**
26
35
  * The chapters file URL. A session with the engine's `chapters` namespace
@@ -51,6 +60,7 @@ const STATE_EVENTS = [
51
60
  "play",
52
61
  "pause",
53
62
  "ended",
63
+ "seeked",
54
64
  "emptied",
55
65
  "volumechange",
56
66
  "loadedmetadata",
@@ -60,6 +70,8 @@ const STATE_EVENTS = [
60
70
  "stalled",
61
71
  "canplay"
62
72
  ];
73
+ /** The stages that register a key system, which a native session's DRM offers. */
74
+ const KEY_SYSTEMS = ["eme-fairplay", "eme-cenc"];
63
75
  /** Every stage the engine ships. A narrower preset is optimization. */
64
76
  const DEFAULT_PRESET = "full";
65
77
  /**
@@ -119,6 +131,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
119
131
  this.media.addEventListener("playing", () => {
120
132
  this.failure = null;
121
133
  });
134
+ this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
122
135
  this.stage = document.createElement("div");
123
136
  this.stage.setAttribute("part", "stage");
124
137
  this.stage.append(document.createElement("slot"));
@@ -134,6 +147,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
134
147
  get video() {
135
148
  return this.media;
136
149
  }
150
+ /** The ranges the page named in this source: credits to skip, parts that must not play. */
151
+ get markers() {
152
+ return this.marks;
153
+ }
137
154
  /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
138
155
  get player() {
139
156
  return this.core;
@@ -220,6 +237,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
220
237
  }
221
238
  if (name === "preset") this.enqueue(() => this.discard());
222
239
  if (name === "src" || name === "type") this.toggleAttribute("audio", this.audio());
240
+ if (name === "src" && this.marks.list.length > 0) this.marks.set([]);
223
241
  this.reload();
224
242
  }
225
243
  /**
@@ -360,7 +378,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
360
378
  var _this$getAttribute2;
361
379
  if (_this3.options.handlers !== void 0) return _this3.options.handlers;
362
380
  const config = _this3.options.config === void 0 ? {} : { config: _this3.options.config };
363
- if (_this3.options.stages !== void 0) return [matteboxHandler(_objectSpread2({ stages: _this3.options.stages }, config)), nativeHandler()];
381
+ const native = (stages) => nativeHandler({
382
+ prefer: (source, env) => _this3.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
383
+ drm: () => _this3.drm(stages)
384
+ });
385
+ if (_this3.options.stages !== void 0) return [matteboxHandler(_objectSpread2({ stages: _this3.options.stages }, config)), native(() => {
386
+ var _this$options$stages;
387
+ return (_this$options$stages = _this3.options.stages) !== null && _this$options$stages !== void 0 ? _this$options$stages : [];
388
+ })];
364
389
  const name = (_this$getAttribute2 = _this3.getAttribute("preset")) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : DEFAULT_PRESET;
365
390
  const preset = yield resolvePreset(name);
366
391
  if (preset === null) {
@@ -374,16 +399,33 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
374
399
  });
375
400
  return [nativeHandler()];
376
401
  }
377
- return [matteboxHandler(_objectSpread2(_objectSpread2({ preset }, config), drmGuard())), nativeHandler()];
402
+ return [matteboxHandler(_objectSpread2(_objectSpread2({ preset }, config), drmGuard())), native(() => preset.stages())];
378
403
  })();
379
404
  }
405
+ /**
406
+ * The DRM a native session attaches: the page's `drm` option, the
407
+ * key-system stages of the engine's stack, and the `license-url`
408
+ * attribute. None on a browser without EME, as for the engine.
409
+ */
410
+ drm(stages) {
411
+ if (drmGuard().without !== void 0) return void 0;
412
+ const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));
413
+ const license = this.getAttribute("license-url");
414
+ const certificate = this.getAttribute("certificate-url");
415
+ const page = this.options.drm;
416
+ if (keySystems.length === 0 && license === null && page === void 0) return void 0;
417
+ return _objectSpread2(_objectSpread2(_objectSpread2({ keySystems }, page), license === null ? {} : { licenseUrl: license }), certificate === null ? {} : { certificateUrl: certificate });
418
+ }
380
419
  /** What the attributes ask of the session's namespaces, once there is one. */
381
420
  configure(session) {
421
+ var _optional$drm;
382
422
  const engine = session.engine;
383
423
  if (engine === null) return;
384
424
  const optional = namespaces(engine);
385
425
  const license = this.getAttribute("license-url");
386
426
  if (license !== null && optional.drm !== void 0) optional.drm.setLicenseUrl(license);
427
+ const certificate = this.getAttribute("certificate-url");
428
+ if (certificate !== null) (_optional$drm = optional.drm) === null || _optional$drm === void 0 || _optional$drm.setCertificateUrl(certificate);
387
429
  const track = this.getAttribute("thumbnails");
388
430
  if (track !== null && optional.thumbnails !== void 0) optional.thumbnails.load(track).catch(() => void 0);
389
431
  }
@@ -1,19 +1,33 @@
1
1
  import { show } from "./shared.js";
2
+ import { nativeTracks, onNativeTracks } from "../controls/native-tracks.js";
3
+ import { layout, trackNames } from "../controls/track-names.js";
2
4
  import { MenuElement, single } from "./menu-element.js";
5
+ import { isAudioDescription, isOriginal } from "mattebox";
3
6
  //#region src/elements/audio-menu.ts
4
- /** The language, then the role, then the id: whichever the manifest gave. */
5
- function trackLabel(track) {
6
- const parts = [track.lang, track.role].filter((part) => part !== void 0);
7
- return parts.length === 0 ? track.id : parts.join(" · ");
7
+ /** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */
8
+ function channels(track) {
9
+ const first = track.renditions[0];
10
+ return (first === null || first === void 0 ? void 0 : first.channels) === void 0 ? void 0 : layout(`${first.channels}${first.audioObjects ? `/${first.audioObjects}` : ""}`);
8
11
  }
9
- /** The tracks of one content type as menu items, with the active one's id. */
10
- function trackItems(engine, contentType) {
11
- var _tracks$active$id, _tracks$active;
12
+ /**
13
+ * The tracks of one content type that the engine can play and `listed`
14
+ * keeps, as entries with their badges, and the active one's id when it
15
+ * is listed. A track the browser cannot decode, or that no stage plays,
16
+ * stays out (guide chapter 06).
17
+ */
18
+ function trackItems(engine, contentType, badges = () => [], listed = () => true) {
19
+ var _tracks$active;
12
20
  const tracks = engine.tracks;
13
- const available = tracks.available.filter((track) => track.contentType === contentType);
14
- const items = [];
15
- for (const track of available) items.push([track.id, trackLabel(track)]);
16
- return [items, (_tracks$active$id = (_tracks$active = tracks.active(contentType)) === null || _tracks$active === void 0 ? void 0 : _tracks$active.id) !== null && _tracks$active$id !== void 0 ? _tracks$active$id : null];
21
+ const available = tracks.available.filter((track) => track.contentType === contentType && tracks.selectable(track.id) && listed(track));
22
+ const entries = available.map((track) => [
23
+ track.id,
24
+ track.name,
25
+ track.lang,
26
+ badges(track),
27
+ [channels(track), track.role === "main" ? void 0 : track.role]
28
+ ]);
29
+ const active = (_tracks$active = tracks.active(contentType)) === null || _tracks$active === void 0 ? void 0 : _tracks$active.id;
30
+ return [entries, available.some((track) => track.id === active) ? active : null];
17
31
  }
18
32
  /** Subscribes `tick` to the track events, and answers the unsubscribe. */
19
33
  function onTracks(engine, tick) {
@@ -24,7 +38,13 @@ function onTracks(engine, tick) {
24
38
  }
25
39
  var MbxAudioMenu = class extends MenuElement {
26
40
  static get observedAttributes() {
27
- return ["label", "label-back"];
41
+ return [
42
+ "label",
43
+ "label-back",
44
+ "label-ad",
45
+ "label-original",
46
+ "label-track"
47
+ ];
28
48
  }
29
49
  constructor() {
30
50
  super(...single("music"));
@@ -38,26 +58,49 @@ var MbxAudioMenu = class extends MenuElement {
38
58
  this.follow(player, (engine) => {
39
59
  this.engine = engine;
40
60
  this.render();
41
- if (engine === null) return void 0;
42
- return onTracks(engine, () => {
61
+ const tick = () => {
43
62
  this.render();
44
- });
63
+ };
64
+ return engine === null ? onNativeTracks(player.video, "audioTracks", tick) : onTracks(engine, tick);
45
65
  });
46
66
  }
67
+ /** The native session's audio tracks as entries, and the enabled one's. */
68
+ native(tracks) {
69
+ var _this$getAttribute;
70
+ const ad = (_this$getAttribute = this.getAttribute("label-ad")) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "AD";
71
+ const entries = tracks.map((track, index) => [
72
+ String(index),
73
+ track.label,
74
+ track.language,
75
+ track.kind === "description" || track.kind === "main-desc" ? [ad] : [],
76
+ []
77
+ ]);
78
+ const on = tracks.findIndex((track) => track.enabled);
79
+ return [entries, on === -1 ? null : String(on)];
80
+ }
47
81
  render() {
48
82
  super.render();
49
83
  const engine = this.engine;
50
- if (engine === null) {
84
+ const player = this.player;
85
+ const tracks = engine === null && player !== null ? nativeTracks(player, "audioTracks") : void 0;
86
+ if (engine === null && tracks === void 0) {
51
87
  this.hidden = true;
52
88
  return;
53
89
  }
54
- const [items, active] = trackItems(engine, "audio");
90
+ const [entries, active] = tracks !== void 0 ? this.native(tracks) : trackItems(engine, "audio", (track) => {
91
+ var _this$getAttribute2, _this$getAttribute3;
92
+ return [...isAudioDescription(track) ? [(_this$getAttribute2 = this.getAttribute("label-ad")) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : "AD"] : [], ...isOriginal(track) ? [(_this$getAttribute3 = this.getAttribute("label-original")) !== null && _this$getAttribute3 !== void 0 ? _this$getAttribute3 : "Original"] : []];
93
+ });
94
+ const items = trackNames(entries, this.getAttribute("label-track"));
55
95
  this.menu.fill([{
56
96
  name: "track",
57
97
  items,
58
98
  value: active !== null && active !== void 0 ? active : "",
59
99
  onSelect: (value) => {
60
- engine.tracks.select(value);
100
+ if (tracks !== void 0) tracks.forEach((track, index) => {
101
+ track.enabled = String(index) === value;
102
+ });
103
+ else engine === null || engine === void 0 || engine.tracks.select(value);
61
104
  this.render();
62
105
  }
63
106
  }]);
@@ -65,4 +108,4 @@ var MbxAudioMenu = class extends MenuElement {
65
108
  }
66
109
  };
67
110
  //#endregion
68
- export { MbxAudioMenu, onTracks, trackItems, trackLabel };
111
+ export { MbxAudioMenu, onTracks, trackItems };
@@ -24,7 +24,7 @@ var MbxDrmBadge = class extends Component {
24
24
  }
25
25
  constructor() {
26
26
  super();
27
- this.engine = null;
27
+ this.drm = void 0;
28
28
  const root = this.attachShadow({ mode: "open" });
29
29
  const slot = document.createElement("slot");
30
30
  slot.name = "icon";
@@ -74,17 +74,20 @@ var MbxDrmBadge = class extends Component {
74
74
  }
75
75
  attach(player) {
76
76
  this.follow(player, (engine) => {
77
- this.engine = engine;
77
+ var _player$player;
78
+ const eme = (_player$player = player.player) === null || _player$player === void 0 || (_player$player = _player$player.session) === null || _player$player === void 0 ? void 0 : _player$player.eme;
79
+ const source = engine !== null && engine !== void 0 ? engine : eme;
80
+ this.drm = engine === null ? eme === null || eme === void 0 ? void 0 : eme.drm : namespaces(engine).drm;
78
81
  this.render();
79
- if (engine === null || namespaces(engine).drm === void 0) return void 0;
82
+ if (source === void 0 || this.drm === void 0) return void 0;
80
83
  const tick = () => {
81
84
  this.render();
82
85
  };
83
86
  const offs = [
84
- engine.on("drm:keysystem", tick),
85
- engine.on("drm:keystatus", tick),
86
- engine.on("drm:encrypted", tick)
87
- ];
87
+ "drm:keysystem",
88
+ "drm:keystatus",
89
+ "drm:encrypted"
90
+ ].map((event) => source.on(event, tick));
88
91
  return () => {
89
92
  for (const off of offs) off();
90
93
  };
@@ -95,7 +98,7 @@ var MbxDrmBadge = class extends Component {
95
98
  }
96
99
  render() {
97
100
  var _drm$keySystem, _this$getAttribute4;
98
- const drm = this.engine === null ? void 0 : namespaces(this.engine).drm;
101
+ const drm = this.drm;
99
102
  const name = (_drm$keySystem = drm === null || drm === void 0 ? void 0 : drm.keySystem) !== null && _drm$keySystem !== void 0 ? _drm$keySystem : null;
100
103
  this.hidden = name === null;
101
104
  if (drm === void 0 || name === null) return;
@@ -0,0 +1,100 @@
1
+ import { Component } from "./component.js";
2
+ import { BUTTON_STYLE, style } from "./shared.js";
3
+ //#region src/elements/marker-button.ts
4
+ const STYLE_CSS = ":host{right:calc(var(--mbx-pad,8px) + 8px);bottom:calc(var(--mbx-marker-lift,56px) + 12px);z-index:1;position:absolute}:host([hidden]){display:none}[part~=button]{width:auto;height:40px;color:var(--mbx-text);font:inherit;white-space:nowrap;background:#0009;border:1px solid #ffffff80;padding:0 18px;font-weight:600}[part~=button]:hover{background:#000c}";
5
+ const WORDS = {
6
+ "opening-credits": "Skip intro",
7
+ "closing-credits": "Skip credits"
8
+ };
9
+ var MbxMarkerButton = class extends Component {
10
+ static get observedAttributes() {
11
+ return [
12
+ "label-opening-credits",
13
+ "label-closing-credits",
14
+ "label-skip"
15
+ ];
16
+ }
17
+ constructor() {
18
+ super();
19
+ this.marker = null;
20
+ this.resizer = null;
21
+ const root = this.attachShadow({ mode: "open" });
22
+ this.button = document.createElement("button");
23
+ this.button.type = "button";
24
+ this.button.setAttribute("part", "button");
25
+ this.button.textContent = "Skip";
26
+ this.button.addEventListener("click", () => {
27
+ var _this$player;
28
+ const video = (_this$player = this.player) === null || _this$player === void 0 ? void 0 : _this$player.video;
29
+ if (video !== void 0 && this.marker !== null) video.currentTime = this.marker.end;
30
+ });
31
+ root.append(style(BUTTON_STYLE + STYLE_CSS), this.button);
32
+ }
33
+ connectedCallback() {
34
+ this.hidden = true;
35
+ super.connectedCallback();
36
+ }
37
+ attach(player) {
38
+ this.listen(player.video, [
39
+ "timeupdate",
40
+ "seeking",
41
+ "emptied"
42
+ ], () => {
43
+ this.render();
44
+ });
45
+ this.listen(player, ["markerschange"], () => {
46
+ this.render();
47
+ });
48
+ this.listen(player.video, [
49
+ "play",
50
+ "pause",
51
+ "ended"
52
+ ], () => {
53
+ this.fit(player);
54
+ });
55
+ if (typeof ResizeObserver !== "undefined") {
56
+ this.resizer = new ResizeObserver(() => {
57
+ this.fit(player);
58
+ });
59
+ this.resizer.observe(player);
60
+ for (const tag of ["mbx-control-bar", "mbx-title"]) {
61
+ const node = player.querySelector(tag);
62
+ if (node !== null) this.resizer.observe(node);
63
+ }
64
+ }
65
+ this.fit(player);
66
+ this.render();
67
+ }
68
+ detach() {
69
+ var _this$resizer;
70
+ (_this$resizer = this.resizer) === null || _this$resizer === void 0 || _this$resizer.disconnect();
71
+ this.resizer = null;
72
+ }
73
+ /**
74
+ * Lifts the button above the bar's rows, or above the title's text while
75
+ * it shows: each one's box less the padding over its content, which is
76
+ * its fade. A hidden title has no box.
77
+ */
78
+ fit(player) {
79
+ let lift = 0;
80
+ for (const tag of ["mbx-control-bar", "mbx-title"]) {
81
+ const node = player.querySelector(tag);
82
+ if (node === null) continue;
83
+ const fade = Number.parseFloat(getComputedStyle(node).paddingTop) || 0;
84
+ lift = Math.max(lift, node.getBoundingClientRect().height - fade);
85
+ }
86
+ this.style.setProperty("--mbx-marker-lift", `${lift}px`);
87
+ }
88
+ render() {
89
+ var _player$markers$withi, _this$getAttribute, _ref, _this$getAttribute2;
90
+ const player = this.player;
91
+ this.marker = (_player$markers$withi = player === null || player === void 0 ? void 0 : player.markers.within(player.video.currentTime).find((marker) => marker.kind !== "blocked")) !== null && _player$markers$withi !== void 0 ? _player$markers$withi : null;
92
+ this.hidden = this.marker === null;
93
+ if (this.marker === null) return;
94
+ const kind = this.marker.kind;
95
+ const skip = (_this$getAttribute = this.getAttribute("label-skip")) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "Skip";
96
+ this.button.textContent = (_ref = (_this$getAttribute2 = this.getAttribute(`label-${kind}`)) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : WORDS[kind]) !== null && _ref !== void 0 ? _ref : this.marker.label === void 0 ? skip : `${skip} ${this.marker.label}`;
97
+ }
98
+ };
99
+ //#endregion
100
+ export { MbxMarkerButton };
@@ -1,11 +1,8 @@
1
1
  import { show } from "./shared.js";
2
2
  import { MenuElement, single } from "./menu-element.js";
3
+ import { qualityLabels, qualityNames } from "../controls/quality-names.js";
3
4
  //#region src/elements/quality-menu.ts
4
5
  const AUTO = "auto";
5
- function renditionLabel(rendition) {
6
- if (rendition.height !== void 0) return `${rendition.height}p`;
7
- return `${Math.round(rendition.bitrate / 1e3)} kbps`;
8
- }
9
6
  var MbxQualityMenu = class extends MenuElement {
10
7
  static get observedAttributes() {
11
8
  return [
@@ -17,6 +14,7 @@ var MbxQualityMenu = class extends MenuElement {
17
14
  constructor() {
18
15
  super(...single("settings"));
19
16
  this.engine = null;
17
+ this.playing = void 0;
20
18
  show(this.slots, "default");
21
19
  }
22
20
  name() {
@@ -30,7 +28,12 @@ var MbxQualityMenu = class extends MenuElement {
30
28
  const tick = () => {
31
29
  this.render();
32
30
  };
31
+ const clock = () => {
32
+ if (this.playingName() !== this.playing) this.render();
33
+ };
34
+ player.video.addEventListener("timeupdate", clock);
33
35
  const offs = [
36
+ () => player.video.removeEventListener("timeupdate", clock),
34
37
  engine.on("tracks:changed", tick),
35
38
  engine.on("quality:constraints-unsatisfiable", tick),
36
39
  engine.on("quality:pin-unsatisfiable", tick)
@@ -49,8 +52,12 @@ var MbxQualityMenu = class extends MenuElement {
49
52
  return;
50
53
  }
51
54
  const quality = engine.quality;
52
- const items = [[AUTO, (_this$getAttribute = this.getAttribute("label-auto")) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "Auto"]];
53
- for (const rendition of quality.renditions) items.push([rendition.id, renditionLabel(rendition)]);
55
+ this.playing = this.playingName();
56
+ const items = [[
57
+ AUTO,
58
+ (_this$getAttribute = this.getAttribute("label-auto")) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "Auto",
59
+ this.playing
60
+ ], ...qualityNames(quality.selectable)];
54
61
  this.menu.fill([{
55
62
  name: "rendition",
56
63
  items,
@@ -61,7 +68,15 @@ var MbxQualityMenu = class extends MenuElement {
61
68
  this.render();
62
69
  }
63
70
  }]);
64
- this.hidden = quality.renditions.length === 0;
71
+ this.hidden = items.length === 1;
72
+ }
73
+ /** The name of the rendition that plays, under Auto only: a pin names itself by its tick. */
74
+ playingName() {
75
+ var _this$engine, _quality$playing, _qualityLabels$find;
76
+ const quality = (_this$engine = this.engine) === null || _this$engine === void 0 ? void 0 : _this$engine.quality;
77
+ if (quality === void 0 || quality.pinned !== null) return void 0;
78
+ const id = (_quality$playing = quality.playing) === null || _quality$playing === void 0 ? void 0 : _quality$playing.id;
79
+ return (_qualityLabels$find = qualityLabels(quality.selectable).find(([candidate]) => candidate === id)) === null || _qualityLabels$find === void 0 ? void 0 : _qualityLabels$find[1];
65
80
  }
66
81
  };
67
82
  //#endregion