@mattebox/player 0.7.0 → 0.9.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 (138) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/icons.d.ts +5 -28
  3. package/dist/controls/icons.d.ts.map +1 -1
  4. package/dist/controls/icons.js +38 -29
  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 +14 -2
  11. package/dist/controls/menu.d.ts.map +1 -1
  12. package/dist/controls/menu.js +50 -4
  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 +60 -2
  27. package/dist/element.d.ts.map +1 -1
  28. package/dist/element.js +182 -23
  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 +60 -19
  33. package/dist/elements/audio-menu.js.map +1 -1
  34. package/dist/elements/component.d.ts.map +1 -1
  35. package/dist/elements/component.js +10 -0
  36. package/dist/elements/component.js.map +1 -1
  37. package/dist/elements/control-bar.d.ts +2 -0
  38. package/dist/elements/control-bar.d.ts.map +1 -1
  39. package/dist/elements/control-bar.js +23 -7
  40. package/dist/elements/control-bar.js.map +1 -1
  41. package/dist/elements/current-time.d.ts.map +1 -1
  42. package/dist/elements/current-time.js +1 -1
  43. package/dist/elements/current-time.js.map +1 -1
  44. package/dist/elements/drm-badge.d.ts +3 -2
  45. package/dist/elements/drm-badge.d.ts.map +1 -1
  46. package/dist/elements/drm-badge.js +11 -9
  47. package/dist/elements/drm-badge.js.map +1 -1
  48. package/dist/elements/duration.d.ts.map +1 -1
  49. package/dist/elements/duration.js +6 -2
  50. package/dist/elements/duration.js.map +1 -1
  51. package/dist/elements/error-screen.js +1 -1
  52. package/dist/elements/live-button.js +1 -1
  53. package/dist/elements/marker-button.d.ts +22 -0
  54. package/dist/elements/marker-button.d.ts.map +1 -0
  55. package/dist/elements/marker-button.js +95 -0
  56. package/dist/elements/marker-button.js.map +1 -0
  57. package/dist/elements/quality-menu.d.ts +4 -0
  58. package/dist/elements/quality-menu.d.ts.map +1 -1
  59. package/dist/elements/quality-menu.js +22 -8
  60. package/dist/elements/quality-menu.js.map +1 -1
  61. package/dist/elements/scan-button.js +1 -1
  62. package/dist/elements/seek-bar.d.ts +6 -1
  63. package/dist/elements/seek-bar.d.ts.map +1 -1
  64. package/dist/elements/seek-bar.js +37 -25
  65. package/dist/elements/seek-bar.js.map +1 -1
  66. package/dist/elements/shared.js +3 -3
  67. package/dist/elements/skip-button.js +2 -2
  68. package/dist/elements/skip-button.js.map +1 -1
  69. package/dist/elements/spinner.js +1 -1
  70. package/dist/elements/start-button.d.ts +5 -0
  71. package/dist/elements/start-button.d.ts.map +1 -1
  72. package/dist/elements/start-button.js +15 -2
  73. package/dist/elements/start-button.js.map +1 -1
  74. package/dist/elements/subtitles-menu.d.ts +7 -1
  75. package/dist/elements/subtitles-menu.d.ts.map +1 -1
  76. package/dist/elements/subtitles-menu.js +62 -20
  77. package/dist/elements/subtitles-menu.js.map +1 -1
  78. package/dist/elements/title.d.ts.map +1 -1
  79. package/dist/elements/title.js +3 -1
  80. package/dist/elements/title.js.map +1 -1
  81. package/dist/elements/volume-slider.js +1 -1
  82. package/dist/elements/volume.js +1 -1
  83. package/dist/entries/marker-button.d.ts +5 -0
  84. package/dist/entries/marker-button.d.ts.map +1 -0
  85. package/dist/entries/marker-button.js +9 -0
  86. package/dist/entries/marker-button.js.map +1 -0
  87. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/asyncToGenerator.js +1 -1
  88. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/defineProperty.js +1 -1
  89. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/objectSpread2.js +1 -1
  90. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPrimitive.js +1 -1
  91. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPropertyKey.js +1 -1
  92. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/typeof.js +1 -1
  93. package/dist/es2015/controls/chapters.js +1 -1
  94. package/dist/es2015/controls/icons.js +38 -29
  95. package/dist/es2015/controls/markers.js +36 -0
  96. package/dist/es2015/controls/menu.js +52 -5
  97. package/dist/es2015/controls/native-tracks.js +29 -0
  98. package/dist/es2015/controls/quality-names.js +67 -0
  99. package/dist/es2015/controls/track-names.js +57 -0
  100. package/dist/es2015/element.js +185 -29
  101. package/dist/es2015/elements/audio-menu.js +66 -20
  102. package/dist/es2015/elements/component.js +10 -0
  103. package/dist/es2015/elements/control-bar.js +23 -7
  104. package/dist/es2015/elements/current-time.js +1 -1
  105. package/dist/es2015/elements/drm-badge.js +12 -9
  106. package/dist/es2015/elements/duration.js +6 -2
  107. package/dist/es2015/elements/error-screen.js +1 -1
  108. package/dist/es2015/elements/live-button.js +1 -1
  109. package/dist/es2015/elements/marker-button.js +96 -0
  110. package/dist/es2015/elements/quality-menu.js +23 -8
  111. package/dist/es2015/elements/scan-button.js +1 -1
  112. package/dist/es2015/elements/seek-bar.js +42 -29
  113. package/dist/es2015/elements/shared.js +3 -3
  114. package/dist/es2015/elements/skip-button.js +2 -2
  115. package/dist/es2015/elements/spinner.js +1 -1
  116. package/dist/es2015/elements/start-button.js +15 -2
  117. package/dist/es2015/elements/subtitles-menu.js +72 -26
  118. package/dist/es2015/elements/title.js +3 -1
  119. package/dist/es2015/elements/volume-slider.js +1 -1
  120. package/dist/es2015/elements/volume.js +1 -1
  121. package/dist/es2015/entries/marker-button.js +7 -0
  122. package/dist/es2015/index.js +3 -1
  123. package/dist/es2015/presets.js +1 -1
  124. package/dist/es2015/style.js +1 -1
  125. package/dist/es2015/tags.js +2 -1
  126. package/dist/host.d.ts +3 -0
  127. package/dist/host.d.ts.map +1 -1
  128. package/dist/host.js.map +1 -1
  129. package/dist/index.d.ts +4 -0
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +3 -1
  132. package/dist/style.js +1 -1
  133. package/dist/tags.d.ts +1 -0
  134. package/dist/tags.d.ts.map +1 -1
  135. package/dist/tags.js +2 -1
  136. package/dist/tags.js.map +1 -1
  137. package/package.json +4 -5
  138. package/NOTICE +0 -24
@@ -1,18 +1,33 @@
1
+ import { icon } from "../controls/icons.js";
1
2
  import { show } from "./shared.js";
3
+ import { nativeTracks, onNativeTracks } from "../controls/native-tracks.js";
4
+ import { layout, trackNames } from "../controls/track-names.js";
2
5
  import { MenuElement, single } from "./menu-element.js";
6
+ import { isAudioDescription, isOriginal } from "mattebox";
3
7
  //#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(" · ");
8
+ /** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */
9
+ function channels(track) {
10
+ const first = track.renditions[0];
11
+ return first?.channels === void 0 ? void 0 : layout(`${first.channels}${first.audioObjects ? `/${first.audioObjects}` : ""}`);
8
12
  }
9
- /** The tracks of one content type as menu items, with the active one's id. */
10
- function trackItems(engine, contentType) {
13
+ /**
14
+ * The tracks of one content type that the engine can play and `listed`
15
+ * keeps, as entries with their badges, and the active one's id when it
16
+ * is listed. A track the browser cannot decode, or that no stage plays,
17
+ * stays out (guide chapter 06).
18
+ */
19
+ function trackItems(engine, contentType, badges = () => [], listed = () => true) {
11
20
  const tracks = engine.tracks;
12
- const available = tracks.available.filter((track) => track.contentType === contentType);
13
- const items = [];
14
- for (const track of available) items.push([track.id, trackLabel(track)]);
15
- return [items, tracks.active(contentType)?.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(contentType)?.id;
30
+ return [entries, available.some((track) => track.id === active) ? active : null];
16
31
  }
17
32
  /** Subscribes `tick` to the track events, and answers the unsubscribe. */
18
33
  function onTracks(engine, tick) {
@@ -23,10 +38,16 @@ function onTracks(engine, tick) {
23
38
  }
24
39
  var MbxAudioMenu = class extends MenuElement {
25
40
  static get observedAttributes() {
26
- return ["label", "label-back"];
41
+ return [
42
+ "label",
43
+ "label-back",
44
+ "label-ad",
45
+ "label-original",
46
+ "label-track"
47
+ ];
27
48
  }
28
49
  constructor() {
29
- super(...single("music"));
50
+ super(...single("audio"));
30
51
  this.engine = null;
31
52
  show(this.slots, "default");
32
53
  }
@@ -37,26 +58,46 @@ var MbxAudioMenu = class extends MenuElement {
37
58
  this.follow(player, (engine) => {
38
59
  this.engine = engine;
39
60
  this.render();
40
- if (engine === null) return void 0;
41
- return onTracks(engine, () => {
61
+ const tick = () => {
42
62
  this.render();
43
- });
63
+ };
64
+ return engine === null ? onNativeTracks(player.video, "audioTracks", tick) : onTracks(engine, tick);
44
65
  });
45
66
  }
67
+ /** The native session's audio tracks as entries, and the enabled one's. */
68
+ native(tracks) {
69
+ const ad = this.getAttribute("label-ad") ?? "AD";
70
+ const entries = tracks.map((track, index) => [
71
+ String(index),
72
+ track.label,
73
+ track.language,
74
+ track.kind === "description" || track.kind === "main-desc" ? [ad] : [],
75
+ []
76
+ ]);
77
+ const on = tracks.findIndex((track) => track.enabled);
78
+ return [entries, on === -1 ? null : String(on)];
79
+ }
46
80
  render() {
47
81
  super.render();
48
82
  const engine = this.engine;
49
- if (engine === null) {
83
+ const player = this.player;
84
+ const tracks = engine === null && player !== null ? nativeTracks(player, "audioTracks") : void 0;
85
+ if (engine === null && tracks === void 0) {
50
86
  this.hidden = true;
51
87
  return;
52
88
  }
53
- const [items, active] = trackItems(engine, "audio");
89
+ const [entries, active] = tracks !== void 0 ? this.native(tracks) : trackItems(engine, "audio", (track) => [...isAudioDescription(track) ? [this.getAttribute("label-ad") ?? "AD"] : [], ...isOriginal(track) ? [this.getAttribute("label-original") ?? "Original"] : []]);
90
+ const items = trackNames(entries, this.getAttribute("label-track"));
54
91
  this.menu.fill([{
55
92
  name: "track",
56
93
  items,
94
+ badgeGlyphs: { [this.getAttribute("label-ad") ?? "AD"]: () => icon("audio-description") },
57
95
  value: active ?? "",
58
96
  onSelect: (value) => {
59
- engine.tracks.select(value);
97
+ if (tracks !== void 0) tracks.forEach((track, index) => {
98
+ track.enabled = String(index) === value;
99
+ });
100
+ else engine?.tracks.select(value);
60
101
  this.render();
61
102
  }
62
103
  }]);
@@ -64,6 +105,6 @@ var MbxAudioMenu = class extends MenuElement {
64
105
  }
65
106
  };
66
107
  //#endregion
67
- export { MbxAudioMenu, onTracks, trackItems, trackLabel };
108
+ export { MbxAudioMenu, onTracks, trackItems };
68
109
 
69
110
  //# sourceMappingURL=audio-menu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"audio-menu.js","names":[],"sources":["../../src/elements/audio-menu.ts"],"sourcesContent":["/**\n * <mbx-audio-menu>: the audio track over `engine.tracks`. Hidden unless\n * there is a choice to make, and for a native session. The name comes\n * from `label`. A track reads as its language, then its role, then its\n * id: whichever the manifest gave.\n */\nimport type { ContentType, Mattebox, Track } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\n/** The language, then the role, then the id: whichever the manifest gave. */\nexport function trackLabel(track: Track): string {\n const parts = [track.lang, track.role].filter((part) => part !== undefined);\n return parts.length === 0 ? track.id : parts.join(' · ');\n}\n\n/** The tracks of one content type as menu items, with the active one's id. */\nexport function trackItems(\n engine: Mattebox,\n contentType: ContentType,\n): [Array<readonly [string, string]>, string | null] {\n const tracks = engine.tracks;\n const available = tracks.available.filter((track) => track.contentType === contentType);\n const items: Array<readonly [string, string]> = [];\n for (const track of available) items.push([track.id, trackLabel(track)]);\n return [items, tracks.active(contentType)?.id ?? null];\n}\n\n/** Subscribes `tick` to the track events, and answers the unsubscribe. */\nexport function onTracks(engine: Mattebox, tick: () => void): () => void {\n const offs = [engine.on('tracks:changed', tick), engine.on('tracks:selected', tick)];\n return () => {\n for (const off of offs) off();\n };\n}\n\nexport class MbxAudioMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back'];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(...single('music'));\n this.engine = null;\n show(this.slots, 'default');\n }\n\n protected override name(): string {\n return 'Audio';\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n if (engine === null) return undefined;\n return onTracks(engine, () => {\n this.render();\n });\n });\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n if (engine === null) {\n this.hidden = true;\n return;\n }\n const [items, active] = trackItems(engine, 'audio');\n this.menu.fill([\n {\n name: 'track',\n items,\n value: active ?? '',\n onSelect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AAI,WAAW,MAAM;GACnB,KAAK,SAAS;GACd;EACF;EACA,MAAM,CAAC,OAAO,UAAU,WAAW,QAAQ,OAAO;EAClD,KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN;GACA,OAAO,UAAU;GACjB,WAAW,UAAU;IACnB,OAAO,OAAO,OAAO,KAAK;IAC1B,KAAK,OAAO;GACd;EACF,CACF,CAAC;EACD,KAAK,SAAS,MAAM,SAAS;CAC/B;AACF"}
1
+ {"version":3,"file":"audio-menu.js","names":[],"sources":["../../src/elements/audio-menu.ts"],"sourcesContent":["/**\n * <mbx-audio-menu>: the audio track over `engine.tracks`, or over the\n * video's `audioTracks` for a native session. Hidden unless there is a\n * choice to make. The name comes from `label`. An engine track reads as\n * its name in the manifest, else its language's name, else its language\n * code, else \"Track\" (`label-track`) and its place. A native track reads\n * the same from its label and language. A badge marks an\n * audio description track (`label-ad`, \"AD\") and the original language\n * (`label-original`, \"Original\"), from the engine's standard\n * characteristics (guide chapter 06), or from the native track's `kind`.\n */\nimport type { ContentType, Mattebox, Track } from 'mattebox';\nimport { isAudioDescription, isOriginal } from 'mattebox';\nimport { icon } from '../controls/icons.js';\nimport type { NativeTrack } from '../controls/native-tracks.js';\nimport { nativeTracks, onNativeTracks } from '../controls/native-tracks.js';\nimport type { TrackEntry } from '../controls/track-names.js';\nimport { layout, trackNames } from '../controls/track-names.js';\nimport type { PlayerHost } from '../host.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\n/** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */\nfunction channels(track: Track): string | undefined {\n const first = track.renditions[0];\n return first?.channels === undefined\n ? undefined\n : layout(`${first.channels}${first.audioObjects ? `/${first.audioObjects}` : ''}`);\n}\n\n/**\n * The tracks of one content type that the engine can play and `listed`\n * keeps, as entries with their badges, and the active one's id when it\n * is listed. A track the browser cannot decode, or that no stage plays,\n * stays out (guide chapter 06).\n */\nexport function trackItems(\n engine: Mattebox,\n contentType: ContentType,\n badges: (track: Track) => readonly string[] = () => [],\n listed: (track: Track) => boolean = () => true,\n): [TrackEntry[], string | null] {\n const tracks = engine.tracks;\n const available = tracks.available.filter(\n (track) => track.contentType === contentType && tracks.selectable(track.id) && listed(track),\n );\n const entries = available.map(\n (track): TrackEntry => [\n track.id,\n track.name,\n track.lang,\n badges(track),\n // The role \"main\" tells nothing apart: every stream has one.\n [channels(track), track.role === 'main' ? undefined : track.role],\n ],\n );\n const active = tracks.active(contentType)?.id;\n return [entries, available.some((track) => track.id === active) ? (active as string) : null];\n}\n\n/** What the menu reads and writes of Safari's `AudioTrack`. */\ninterface NativeAudioTrack extends NativeTrack {\n enabled: boolean;\n}\n\n/** Subscribes `tick` to the track events, and answers the unsubscribe. */\nexport function onTracks(engine: Mattebox, tick: () => void): () => void {\n const offs = [engine.on('tracks:changed', tick), engine.on('tracks:selected', tick)];\n return () => {\n for (const off of offs) off();\n };\n}\n\nexport class MbxAudioMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back', 'label-ad', 'label-original', 'label-track'];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(...single('audio'));\n this.engine = null;\n show(this.slots, 'default');\n }\n\n protected override name(): string {\n return 'Audio';\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n const tick = (): void => {\n this.render();\n };\n return engine === null\n ? onNativeTracks(player.video, 'audioTracks', tick)\n : onTracks(engine, tick);\n });\n }\n\n /** The native session's audio tracks as entries, and the enabled one's. */\n private native(tracks: readonly NativeAudioTrack[]): [TrackEntry[], string | null] {\n const ad = this.getAttribute('label-ad') ?? 'AD';\n const entries = tracks.map(\n (track, index): TrackEntry => [\n String(index),\n track.label,\n track.language,\n // HTML's kinds for an audio description track.\n track.kind === 'description' || track.kind === 'main-desc' ? [ad] : [],\n [],\n ],\n );\n const on = tracks.findIndex((track) => track.enabled);\n return [entries, on === -1 ? null : String(on)];\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n const player = this.player;\n const tracks =\n engine === null && player !== null\n ? nativeTracks<NativeAudioTrack>(player, 'audioTracks')\n : undefined;\n if (engine === null && tracks === undefined) {\n this.hidden = true;\n return;\n }\n const [entries, active] =\n tracks !== undefined\n ? this.native(tracks)\n : trackItems(engine as Mattebox, 'audio', (track) => [\n ...(isAudioDescription(track) ? [this.getAttribute('label-ad') ?? 'AD'] : []),\n ...(isOriginal(track) ? [this.getAttribute('label-original') ?? 'Original'] : []),\n ]);\n const items = trackNames(entries, this.getAttribute('label-track'));\n this.menu.fill([\n {\n name: 'track',\n items,\n // The audio description badge is the AD mark, named by `label-ad`.\n badgeGlyphs: { [this.getAttribute('label-ad') ?? 'AD']: () => icon('audio-description') },\n value: active ?? '',\n onSelect: (value) => {\n // One audio track plays at a time, so the others are turned off.\n if (tracks !== undefined) {\n tracks.forEach((track, index) => {\n track.enabled = String(index) === value;\n });\n } else engine?.tracks.select(value);\n this.render();\n },\n },\n ]);\n this.hidden = items.length < 2;\n }\n}\n"],"mappings":";;;;;;;;AAuBA,SAAS,SAAS,OAAkC;CAClD,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,aAAa,KAAA,IACvB,KAAA,IACA,OAAO,GAAG,MAAM,WAAW,MAAM,eAAe,IAAI,MAAM,iBAAiB,IAAI;AACrF;;;;;;;AAQA,SAAgB,WACd,QACA,aACA,eAAoD,CAAC,GACrD,eAA0C,MACX;CAC/B,MAAM,SAAS,OAAO;CACtB,MAAM,YAAY,OAAO,UAAU,QAChC,UAAU,MAAM,gBAAgB,eAAe,OAAO,WAAW,MAAM,EAAE,KAAK,OAAO,KAAK,CAC7F;CACA,MAAM,UAAU,UAAU,KACvB,UAAsB;EACrB,MAAM;EACN,MAAM;EACN,MAAM;EACN,OAAO,KAAK;EAEZ,CAAC,SAAS,KAAK,GAAG,MAAM,SAAS,SAAS,KAAA,IAAY,MAAM,IAAI;CAClE,CACF;CACA,MAAM,SAAS,O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IAU5B,wBAAwB,IAAI,IAAI;IAIhC,qEAAqE;IACrE,SAAS,CAAC,MAAM,CACd,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GACzB,IAAI;IAOP,oCAAoC;IACpC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,IAAI;IAIrC;;;;OAIG;IACH,SAAS,CAAC,MAAM,CACd,MAAM,EAAE,UAAU,EAClB,EAAE,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GACxD,IAAI;IAcP,mGAAmG;IACnG,SAAS,CAAC,OAAO,CACf,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,UAAQ,GACd,IAAI;IAQP,gFAAgF;IAChF,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAEnD,mFAAmF;IACnF,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAE3C,yFAAyF;IACzF,SAAS,CAAC,MAAM,IAAI,IAAI;CACzB"}
@@ -18,6 +18,16 @@ var Component = class extends HTMLElement {
18
18
  customElements.upgrade(found);
19
19
  if (!("video" in found)) return;
20
20
  this.player = found;
21
+ const tier = () => {
22
+ const layout = found.getAttribute("layout");
23
+ if (layout === null) this.removeAttribute("layout");
24
+ else this.setAttribute("layout", layout);
25
+ };
26
+ this.listen(found, ["layoutchange"], () => {
27
+ tier();
28
+ this.render();
29
+ });
30
+ tier();
21
31
  this.attach(this.player);
22
32
  };
23
33
  if ("video" in found) attach();
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport { PLAYER } from '../tags.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `video` is on the prototype.\n customElements.upgrade(found);\n if (!('video' in found)) return;\n this.player = found as PlayerHost;\n this.attach(this.player);\n };\n if ('video' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;AAmBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,KAAK,aAAa;GAE/C,eAAe,QAAQ,KAAK;GAC5B,IAAI,EAAE,WAAW,QAAQ;GACzB,KAAK,SAAS;GACd,KAAK,OAAO,KAAK,MAAM;EACzB;EACA,IAAI,WAAW,OAAO,OAAO;OACxB,eAAoB,YAAY,MAAM,CAAC,CAAC,KAAK,MAAM;CAC1D;CAEA,uBAA6B;EAC3B,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI;EACjC,KAAK,OAAO,CAAC;EACb,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,KAAK,SAAS;EACd,KAAK,OAAO,MAAM;CACpB;CAEA,2BAAiC;EAC/B,IAAI,KAAK,WAAW,MAAM,KAAK,OAAO;CACxC;;CAGA,OACE,QACA,OACA,IACM;EACN,KAAK,MAAM,QAAQ,OAAO,OAAO,iBAAiB,MAAM,EAAE;EAC1D,KAAK,KAAK,WAAW;GACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,oBAAoB,MAAM,EAAE;EAC/D,CAAC;CACH;;CAGA,KAAe,KAAuB;EACpC,KAAK,KAAK,KAAK,GAAG;CACpB;;;;;;CAOA,OACE,QACA,IACM;EACN,IAAI;EACJ,MAAM,YAAkB;GACtB,MAAM;GACN,MAAM,GAAG,OAAO,MAAM;EACxB;EACA,KAAK,OAAO,QAAQ,CAAC,cAAc,GAAG,GAAG;EACzC,KAAK,KAAK,WAAW;GACnB,MAAM;GACN,MAAM,KAAA;EACR,CAAC;EACD,IAAI;CACN;;CAGA,QACE,QACA,OACA,IACA,UAAU,OACJ;EACN,MAAM,WAAW,IAAI,iBAAiB,EAAE;EACxC,SAAS,QAAQ,QAAQ;GAAE,YAAY;GAAM,iBAAiB,CAAC,GAAG,KAAK;GAAG;EAAQ,CAAC;EACnF,KAAK,KAAK,WAAW;GACnB,SAAS,WAAW;EACtB,CAAC;CACH;;CAMA,OAAiB,SAA2B,CAAC;;CAG7C,SAAyB,CAAC;AAC5B"}
1
+ {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport { PLAYER } from '../tags.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `video` is on the prototype.\n customElements.upgrade(found);\n if (!('video' in found)) return;\n this.player = found as PlayerHost;\n // The player's size tier, on the control itself: a shadow tree cannot\n // match an attribute of an ancestor in every browser, and with it\n // here a control's stylesheet says `:host([layout=\"compact\"])`.\n const tier = (): void => {\n const layout = found.getAttribute('layout');\n if (layout === null) this.removeAttribute('layout');\n else this.setAttribute('layout', layout);\n };\n this.listen(found, ['layoutchange'], () => {\n tier();\n this.render();\n });\n tier();\n this.attach(this.player);\n };\n if ('video' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;AAmBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,KAAK,aAAa;GAE/C,eAAe,QAAQ,KAAK;GAC5B,IAAI,EAAE,WAAW,QAAQ;GACzB,KAAK,SAAS;GAId,MAAM,aAAmB;IACvB,MAAM,SAAS,MAAM,aAAa,QAAQ;IAC1C,IAAI,WAAW,MAAM,KAAK,gBAAgB,QAAQ;SAC7C,KAAK,aAAa,UAAU,MAAM;GACzC;GACA,KAAK,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK;IACL,KAAK,OAAO;GACd,CAAC;GACD,KAAK;GACL,KAAK,OAAO,KAAK,MAAM;EACzB;EACA,IAAI,WAAW,OAAO,OAAO;OACxB,eAAoB,YAAY,MAAM,CAAC,CAAC,KAAK,MAAM;CAC1D;CAEA,uBAA6B;EAC3B,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI;EACjC,KAAK,OAAO,CAAC;EACb,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,KAAK,SAAS;EACd,KAAK,OAAO,MAAM;CACpB;CAEA,2BAAiC;EAC/B,IAAI,KAAK,WAAW,MAAM,KAAK,OAAO;CACxC;;CAGA,OACE,QACA,OACA,IACM;EACN,KAAK,MAAM,QAAQ,OAAO,OAAO,iBAAiB,MAAM,EAAE;EAC1D,KAAK,KAAK,WAAW;GACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,oBAAoB,MAAM,EAAE;EAC/D,CAAC;CACH;;CAGA,KAAe,KAAuB;EACpC,KAAK,KAAK,KAAK,GAAG;CACpB;;;;;;CAOA,OACE,QACA,IACM;EACN,IAAI;EACJ,MAAM,YAAkB;GACtB,MAAM;GACN,MAAM,GAAG,OAAO,MAAM;EACxB;EACA,KAAK,OAAO,QAAQ,CAAC,cAAc,GAAG,GAAG;EACzC,KAAK,KAAK,WAAW;GACnB,MAAM;GACN,MAAM,KAAA;EACR,CAAC;EACD,IAAI;CACN;;CAGA,QACE,QACA,OACA,IACA,UAAU,OACJ;EACN,MAAM,WAAW,IAAI,iBAAiB,EAAE;EACxC,SAAS,QAAQ,QAAQ;GAAE,YAAY;GAAM,iBAAiB,CAAC,GAAG,KAAK;GAAG;EAAQ,CAAC;EACnF,KAAK,KAAK,WAAW;GACnB,SAAS,WAAW;EACtB,CAAC;CACH;;CAMA,OAAiB,SAA2B,CAAC;;CAG7C,SAAyB,CAAC;AAC5B"}
@@ -60,6 +60,8 @@ export declare class MbxControlBar extends Component {
60
60
  * folded slider at the width it unfolds to. The row's own width says nothing, because the
61
61
  * spacer fills it whatever the buttons take.
62
62
  */
63
+ /** The bar's em in pixels: its sizes follow the player's font size. */
64
+ private em;
63
65
  private needed;
64
66
  /**
65
67
  * Collapses the buttons row to its width. Everything is shown first, so
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6E3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAiB;IACjD,iBAAyB,UAAU,CAAiB;IACpD,iBAAyB,OAAO,CAAkB;IAClD,QAAgB,KAAK,CAA4C;IACjE,6FAA6F;IAC7F,QAAgB,OAAO,CAAwB;IAC/C,uEAAuE;IACvE,QAAgB,QAAQ,CAAU;IAClC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAsB1C;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyBhB,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;cAkDQ,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAmDhC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAgBpD"}
1
+ {"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6E3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAiB;IACjD,iBAAyB,UAAU,CAAiB;IACpD,iBAAyB,OAAO,CAAkB;IAClD,QAAgB,KAAK,CAA4C;IACjE,6FAA6F;IAC7F,QAAgB,OAAO,CAAwB;IAC/C,uEAAuE;IACvE,QAAgB,QAAQ,CAAU;IAClC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAsB1C;;;;;OAKG;IACH,uEAAuE;IACvE,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyBhB,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;cAkDQ,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cA6DhC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAgBpD"}
@@ -4,7 +4,7 @@ import { number, 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
7
- const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 16px / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:40px 16px 12px;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -4px;display:flex}[part~=buttons-row]{margin-top:4px}[part~=seek-row]{margin:0 -8px}slot:not([name])::slotted(*){margin:0 4px}slot[name=seek]::slotted(*){margin:0 8px}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}";
7
+ const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 1em / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:2.5em 1em .75em;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([menu]){z-index:2;--mbx-tooltip:none}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -.25em;display:flex}[part~=buttons-row]{margin-top:.25em}[part~=seek-row]{margin:0 -.5em}slot:not([name])::slotted(*){margin:0 .25em}slot[name=seek]::slotted(*){margin:0 .5em}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}:host([layout=compact]){padding:1.5em .5em .25em}";
8
8
  const IDLE_MS = 3e3;
9
9
  const SEEK_STEP = 5;
10
10
  /**
@@ -33,10 +33,10 @@ const PRIORITY = {
33
33
  [VOLUME]: 1,
34
34
  [MUTE_BUTTON]: 1
35
35
  };
36
- /** The width the volume group unfolds its slider to, from volume.ts: what a folded slider is counted at. */
37
- const SLIDER_WIDTH = 80;
38
- /** Room kept between the last button and the edge, so nothing sits flush against it. */
39
- const SLACK = 8;
36
+ /** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */
37
+ const SLIDER_WIDTH = 5;
38
+ /** Room kept between the last button and the edge, in em, so nothing sits flush against it. */
39
+ const SLACK = .5;
40
40
  function shown(node) {
41
41
  return node.getClientRects().length > 0;
42
42
  }
@@ -91,6 +91,10 @@ var MbxControlBar = class extends Component {
91
91
  * folded slider at the width it unfolds to. The row's own width says nothing, because the
92
92
  * spacer fills it whatever the buttons take.
93
93
  */
94
+ /** The bar's em in pixels: its sizes follow the player's font size. */
95
+ em() {
96
+ return Number.parseFloat(getComputedStyle(this).fontSize) || 16;
97
+ }
94
98
  needed(children) {
95
99
  let sum = 0;
96
100
  for (const child of children) {
@@ -99,7 +103,7 @@ var MbxControlBar = class extends Component {
99
103
  sum += child.getBoundingClientRect().width;
100
104
  sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);
101
105
  const folded = slider(child);
102
- if (folded !== null && shown(folded)) sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);
106
+ if (folded !== null && shown(folded)) sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);
103
107
  }
104
108
  return sum;
105
109
  }
@@ -129,7 +133,7 @@ var MbxControlBar = class extends Component {
129
133
  });
130
134
  }
131
135
  candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);
132
- const room = this.buttonsRow.clientWidth - SLACK;
136
+ const room = this.buttonsRow.clientWidth - SLACK * this.em();
133
137
  for (const { node, priority: level } of candidates) {
134
138
  if (level === 0) return;
135
139
  if (this.needed(children) <= room) return;
@@ -239,6 +243,18 @@ var MbxControlBar = class extends Component {
239
243
  };
240
244
  this.keep(screen.watch(reflect));
241
245
  reflect();
246
+ const menus = new MutationObserver(() => {
247
+ this.toggleAttribute("menu", this.querySelector("[open]") !== null);
248
+ });
249
+ menus.observe(this, {
250
+ subtree: true,
251
+ attributes: true,
252
+ attributeFilter: ["open"]
253
+ });
254
+ this.keep(() => {
255
+ menus.disconnect();
256
+ this.removeAttribute("menu");
257
+ });
242
258
  const pointer = () => {
243
259
  this.keyboard = false;
244
260
  this.wake(player);
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute and the subtitles. The subtitles\n * menu goes last of the menus because it is the one a viewer may need.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, from volume.ts: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 80;\n\n/** Room kept between the last button and the edge, so nothing sits flush against it. */\nconst SLACK = 8;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK;\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (player.video.paused) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.video;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.video;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === video) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;AAgEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;AAYA,MAAA,WAAA;EACA,cAAA;EACA,gBAAA;CACA,mBAAA;EACA,YAAA;EACA,aAAA;EACA,gBAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,iBAAA;EACA,cAAA;EACA,iBAAA;EACA,SAAA;EACA,cAAA;AACA;;AAGA,MAAA,eAAA;;AAGA,MAAA,QAAA;AASA,SAAA,MAAA,MAAA;CACA,OAAA,KAAA,eAAA,CAAA,CAAA,SAAA;AACA;;AAGA,SAAA,OAAA,OAAA;CACA,OAAA,MAAA,cAAA,eAAA,MAAA,cAAA,aAAA,IAAA;AACA;;AAGA,SAAA,SAAA,OAAA;CACA,MAAA,MAAA,MAAA,aAAA,UAAA;CACA,IAAA,QAAA,MAAA;EACA,MAAA,QAAA,OAAA,GAAA;EACA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A;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,eAAA,QAAA;GACA,KAAA,QAAA,QAAA,KAAA,UAAA;EACA;EACA,SAAA;CACA;CAEA,OAAA,QAAA;EACA,aAAA,KAAA,KAAA;EACA,KAAA,QAAA,KAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,MAAA,SAAA,KAAA,QAAA,iBAAA,GAAA;GACA,MAAA,gBAAA,WAAA;GACA,OAAA,KAAA,CAAA,EAAA,gBAAA,WAAA;EACA;EACA,KAAA,MAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,YAAA;CACA;AACA"}
1
+ {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute and the subtitles. The subtitles\n * menu goes last of the menus because it is the one a viewer may need.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 5;\n\n/** Room kept between the last button and the edge, in em, so nothing sits flush against it. */\nconst SLACK = 0.5;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n /** The bar's em in pixels: its sizes follow the player's font size. */\n private em(): number {\n return Number.parseFloat(getComputedStyle(this).fontSize) || 16;\n }\n\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK * this.em();\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (player.video.paused) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.video;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.video;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n // `menu` while one of the bar's menus is open, by its `open` attribute:\n // the bar then stacks above the screens and hides its tooltips.\n const menus = new MutationObserver(() => {\n this.toggleAttribute('menu', this.querySelector('[open]') !== null);\n });\n menus.observe(this, { subtree: true, attributes: true, attributeFilter: ['open'] });\n this.keep(() => {\n menus.disconnect();\n this.removeAttribute('menu');\n });\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === video) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;AAgEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;AAYA,MAAA,WAAA;EACA,cAAA;EACA,gBAAA;CACA,mBAAA;EACA,YAAA;EACA,aAAA;EACA,gBAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,iBAAA;EACA,cAAA;EACA,iBAAA;EACA,SAAA;EACA,cAAA;AACA;;AAGA,MAAA,eAAA;;AAGA,MAAA,QAAA;AASA,SAAA,MAAA,MAAA;CACA,OAAA,KAAA,eAAA,CAAA,CAAA,SAAA;AACA;;AAGA,SAAA,OAAA,OAAA;CACA,OAAA,MAAA,cAAA,eAAA,MAAA,cAAA,aAAA,IAAA;AACA;;AAGA,SAAA,SAAA,OAAA;CACA,MAAA,MAAA,MAAA,aAAA,UAAA;CACA,IAAA,QAAA,MAAA;EACA,MAAA,QAAA,OAAA,GAAA;EACA,OAAA,OAAA,SA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AAA,GAAA;GACA,OAAA,oBAAA,SAAA,KAAA;EACA,CAAA;EACA,KAAA,OAAA,OAAA;GAAA;GAAA;GAAA;EAAA,SAAA;GACA,KAAA,KAAA,MAAA;EACA,CAAA;EACA,KAAA,KAAA,MAAA;EACA,KAAA,KAAA,OAAA,IAAA;EAKA,MAAA,iBAAA;GACA,KAAA,SAAA;EACA;EACA,KAAA,OAAA,KAAA,SAAA,CAAA,YAAA,GAAA,QAAA;EACA,KAAA,QAAA,MAAA;GAAA;GAAA;GAAA;EAAA,GAAA,UAAA,IAAA;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,eAAA,QAAA;GACA,KAAA,QAAA,QAAA,KAAA,UAAA;EACA;EACA,SAAA;CACA;CAEA,OAAA,QAAA;EACA,aAAA,KAAA,KAAA;EACA,KAAA,QAAA,KAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,MAAA,SAAA,KAAA,QAAA,iBAAA,GAAA;GACA,MAAA,gBAAA,WAAA;GACA,OAAA,KAAA,CAAA,EAAA,gBAAA,WAAA;EACA;EACA,KAAA,MAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,YAAA;CACA;AACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"current-time.d.ts","sourceRoot":"","sources":["../../src/elements/current-time.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,cAAe,SAAQ,WAAW;cAC1B,MAAM,IAAI,IAAI;CAYlC"}
1
+ {"version":3,"file":"current-time.d.ts","sourceRoot":"","sources":["../../src/elements/current-time.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,cAAe,SAAQ,WAAW;cAC1B,MAAM,IAAI,IAAI;CAelC"}
@@ -19,7 +19,7 @@ var MbxCurrentTime = class extends TimeElement {
19
19
  const on = live(engine) !== void 0;
20
20
  const time = video.currentTime;
21
21
  this.text.data = on ? wall(engine, time) ?? `-${format(span(video, engine).end - time)}` : format(time);
22
- this.hidden = on && player.hasAttribute("live") && !player.hasAttribute("seekable");
22
+ this.hidden = on && player.hasAttribute("live") && !player.hasAttribute("seekable") || !on && this.getAttribute("layout") === "compact";
23
23
  }
24
24
  };
25
25
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.video;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n this.hidden = on && player.hasAttribute('live') && !player.hasAttribute('seekable');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC9C,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EACf,KAAK,SAAS,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU;CACpF;AACF"}
1
+ {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.video;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n // A compact player keeps one readout, the time left, which the duration shows.\n this.hidden =\n (on && player.hasAttribute('live') && !player.hasAttribute('seekable')) ||\n (!on && this.getAttribute('layout') === 'compact');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC9C,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EAEf,KAAK,SACF,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU,KACpE,CAAC,MAAM,KAAK,aAAa,QAAQ,MAAM;CAC5C;AACF"}
@@ -1,5 +1,6 @@
1
1
  /**
2
- * <mbx-drm-badge>: a lock over `engine.drm`, hidden until a key system is
2
+ * <mbx-drm-badge>: a lock over `engine.drm`, or over `session.eme.drm`
3
+ * for a native session that attached DRM, hidden until a key system is
3
4
  * known and for a session without the EME stages. Hover or focus shows
4
5
  * what it knows: the key system, and the key sessions with their
5
6
  * statuses. The glyph is `icon`; the name comes from `label`, where
@@ -16,7 +17,7 @@ export declare class MbxDrmBadge extends Component {
16
17
  private readonly system;
17
18
  private readonly system_id;
18
19
  private readonly keys;
19
- private engine;
20
+ private drm;
20
21
  constructor();
21
22
  /** Named and focusable before attaching: a constructor must not add attributes. */
22
23
  connectedCallback(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"drm-badge.d.ts","sourceRoot":"","sources":["../../src/elements/drm-badge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAY3C,qBAAa,WAAY,SAAQ,SAAS;IACxC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAc;IAC9C,iBAAyB,MAAM,CAAc;IAC7C,iBAAyB,SAAS,CAAc;IAChD,iBAAyB,IAAI,CAAc;IAC3C,QAAgB,MAAM,CAAkB;;IA6BxC,mFAAmF;IAC1E,iBAAiB,IAAI,IAAI;IAOlC,qDAAqD;IACrD,OAAO,CAAC,YAAY;cAeD,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAmBhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAelC"}
1
+ {"version":3,"file":"drm-badge.d.ts","sourceRoot":"","sources":["../../src/elements/drm-badge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAY3C,qBAAa,WAAY,SAAQ,SAAS;IACxC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAc;IAC9C,iBAAyB,MAAM,CAAc;IAC7C,iBAAyB,SAAS,CAAc;IAChD,iBAAyB,IAAI,CAAc;IAC3C,QAAgB,GAAG,CAAqB;;IA6BxC,mFAAmF;IAC1E,iBAAiB,IAAI,IAAI;IAOlC,qDAAqD;IACrD,OAAO,CAAC,YAAY;cAeD,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAoBhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAelC"}
@@ -5,7 +5,7 @@ import { Component } from "./component.js";
5
5
  import { style } from "./shared.js";
6
6
  import { fill } from "../labels.js";
7
7
  //#region src/elements/drm-badge.ts
8
- const STYLE = ":host{width:40px;height:40px;color:var(--mbx-muted);border-radius:var(--mbx-radius);cursor:default;justify-content:center;align-items:center;display:inline-flex;position:relative}:host([hidden]){display:none}:host(:focus){outline:2px solid var(--mbx-accent);outline-offset:-2px}:host(:focus:not(:focus-visible)){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}[part~=tooltip]{border-radius:var(--mbx-radius);color:var(--mbx-text);text-align:left;white-space:nowrap;pointer-events:none;background:#101114f2;margin-bottom:8px;padding:8px 10px;font-size:13px;line-height:1.4;position:absolute;bottom:100%;right:0;box-shadow:0 4px 16px #00000080}[part~=tooltip][hidden]{display:none}[part~=tooltip-title]{font-weight:600}[part~=tooltip-text]{color:var(--mbx-muted)}";
8
+ const STYLE = ":host{width:2.5em;height:2.5em;color:var(--mbx-muted);border-radius:var(--mbx-radius);cursor:default;justify-content:center;align-items:center;display:inline-flex;position:relative}:host([hidden]){display:none}:host(:focus){outline:2px solid var(--mbx-accent);outline-offset:-2px}:host(:focus:not(:focus-visible)){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}[part~=tooltip]{border-radius:var(--mbx-radius);color:var(--mbx-text);text-align:left;white-space:nowrap;pointer-events:none;background:#1c1c20f2;margin-bottom:.6154em;padding:.6154em .7692em;font-size:.8125em;line-height:1.4;position:absolute;bottom:100%;right:0;box-shadow:0 4px 16px #00000080}[part~=tooltip][hidden]{display:none}[part~=tooltip-title]{font-weight:600}[part~=tooltip-text]{color:var(--mbx-muted)}";
9
9
  /** The name a viewer knows a key system by. */
10
10
  function keySystemName(id) {
11
11
  if (id.startsWith("com.widevine")) return "Widevine";
@@ -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";
@@ -70,17 +70,19 @@ var MbxDrmBadge = class extends Component {
70
70
  }
71
71
  attach(player) {
72
72
  this.follow(player, (engine) => {
73
- this.engine = engine;
73
+ const eme = player.player?.session?.eme;
74
+ const source = engine ?? eme;
75
+ this.drm = engine === null ? eme?.drm : namespaces(engine).drm;
74
76
  this.render();
75
- if (engine === null || namespaces(engine).drm === void 0) return void 0;
77
+ if (source === void 0 || this.drm === void 0) return void 0;
76
78
  const tick = () => {
77
79
  this.render();
78
80
  };
79
81
  const offs = [
80
- engine.on("drm:keysystem", tick),
81
- engine.on("drm:keystatus", tick),
82
- engine.on("drm:encrypted", tick)
83
- ];
82
+ "drm:keysystem",
83
+ "drm:keystatus",
84
+ "drm:encrypted"
85
+ ].map((event) => source.on(event, tick));
84
86
  return () => {
85
87
  for (const off of offs) off();
86
88
  };
@@ -90,7 +92,7 @@ var MbxDrmBadge = class extends Component {
90
92
  this.tooltip.hidden = true;
91
93
  }
92
94
  render() {
93
- const drm = this.engine === null ? void 0 : namespaces(this.engine).drm;
95
+ const drm = this.drm;
94
96
  const name = drm?.keySystem ?? null;
95
97
  this.hidden = name === null;
96
98
  if (drm === void 0 || name === null) return;
@@ -1 +1 @@
1
- {"version":3,"file":"drm-badge.js","names":[],"sources":["../../src/elements/drm-badge.ts"],"sourcesContent":["/**\n * <mbx-drm-badge>: a lock over `engine.drm`, hidden until a key system is\n * known and for a session without the EME stages. Hover or focus shows\n * what it knows: the key system, and the key sessions with their\n * statuses. The glyph is `icon`; the name comes from `label`, where\n * `{system}` is the key system's name and `{keys}` the sessions:\n * \"Protected by {system}, {keys}\". The sessions read from `label-keys`\n * with `{count}` and `{statuses}`, `label-key` for one, `label-no-key`\n * for none.\n */\n\nimport type { Mattebox } from 'mattebox';\nimport { icon } from '../controls/icons.js';\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport { namespaces } from '../namespaces.js';\nimport { Component } from './component.js';\nimport STYLE from './drm-badge.css?inline';\nimport { style } from './shared.js';\n\n/** The name a viewer knows a key system by. */\nfunction keySystemName(id: string): string {\n if (id.startsWith('com.widevine')) return 'Widevine';\n if (id.startsWith('com.microsoft.playready')) return 'PlayReady';\n if (id.startsWith('com.apple.fps')) return 'FairPlay';\n return id;\n}\n\nexport class MbxDrmBadge extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-key', 'label-keys', 'label-no-key'];\n }\n\n declare private readonly tooltip: HTMLElement;\n declare private readonly system: HTMLElement;\n declare private readonly system_id: HTMLElement;\n declare private readonly keys: HTMLElement;\n declare private engine: Mattebox | null;\n\n constructor() {\n super();\n this.engine = null;\n const root = this.attachShadow({ mode: 'open' });\n const slot = document.createElement('slot');\n slot.name = 'icon';\n slot.append(icon('lock-closed'));\n this.tooltip = el('div', 'tooltip');\n this.tooltip.setAttribute('role', 'tooltip');\n this.system = el('div', 'tooltip-title');\n this.system_id = el('div', 'tooltip-text');\n this.keys = el('div', 'tooltip-text');\n this.tooltip.append(this.system, this.system_id, this.keys);\n this.tooltip.hidden = true;\n root.append(style(STYLE), slot, this.tooltip);\n const show = (): void => {\n this.tooltip.hidden = false;\n };\n const hide = (): void => {\n this.tooltip.hidden = true;\n };\n this.addEventListener('pointerenter', show);\n this.addEventListener('pointerleave', hide);\n this.addEventListener('focus', show);\n this.addEventListener('blur', hide);\n }\n\n /** Named and focusable before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (!this.hasAttribute('role')) this.setAttribute('role', 'img');\n if (!this.hasAttribute('tabindex')) this.tabIndex = 0;\n if (this.player === null) this.hidden = true;\n super.connectedCallback();\n }\n\n /** \"3 keys: usable ×2, expired\", or \"no key yet\". */\n private sessionsText(sessions: ReadonlyArray<{ readonly status: string }>): string {\n if (sessions.length === 0) return this.getAttribute('label-no-key') ?? 'no key yet';\n const counts = new Map<string, number>();\n for (const session of sessions) {\n counts.set(session.status, (counts.get(session.status) ?? 0) + 1);\n }\n const parts: string[] = [];\n for (const [status, count] of counts) parts.push(count > 1 ? `${status} ×${count}` : status);\n const template =\n sessions.length === 1\n ? (this.getAttribute('label-key') ?? '{count} key: {statuses}')\n : (this.getAttribute('label-keys') ?? '{count} keys: {statuses}');\n return fill(template, { count: sessions.length, statuses: parts.join(', ') });\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n if (engine === null || namespaces(engine).drm === undefined) return undefined;\n const tick = (): void => {\n this.render();\n };\n const offs = [\n engine.on('drm:keysystem', tick),\n engine.on('drm:keystatus', tick),\n engine.on('drm:encrypted', tick),\n ];\n return () => {\n for (const off of offs) off();\n };\n });\n }\n\n protected override detach(): void {\n this.tooltip.hidden = true;\n }\n\n protected override render(): void {\n const drm = this.engine === null ? undefined : namespaces(this.engine).drm;\n const name = drm?.keySystem ?? null;\n this.hidden = name === null;\n if (drm === undefined || name === null) return;\n const keys = this.sessionsText(drm.sessions);\n const system = keySystemName(name);\n this.system.textContent = system;\n this.system_id.textContent = name;\n this.keys.textContent = keys;\n this.setAttribute(\n 'aria-label',\n fill(this.getAttribute('label') ?? 'Protected by {system}, {keys}', { system, keys }),\n );\n }\n}\n"],"mappings":";;;;;;;AAkBA,MAAA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A;EAAA,CAAA,CACA;CACA;AACA"}
1
+ {"version":3,"file":"drm-badge.js","names":[],"sources":["../../src/elements/drm-badge.ts"],"sourcesContent":["/**\n * <mbx-drm-badge>: a lock over `engine.drm`, or over `session.eme.drm`\n * for a native session that attached DRM, hidden until a key system is\n * known and for a session without the EME stages. Hover or focus shows\n * what it knows: the key system, and the key sessions with their\n * statuses. The glyph is `icon`; the name comes from `label`, where\n * `{system}` is the key system's name and `{keys}` the sessions:\n * \"Protected by {system}, {keys}\". The sessions read from `label-keys`\n * with `{count}` and `{statuses}`, `label-key` for one, `label-no-key`\n * for none.\n */\n\nimport type { DrmApi } from 'mattebox/eme';\nimport { icon } from '../controls/icons.js';\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport { namespaces } from '../namespaces.js';\nimport { Component } from './component.js';\nimport STYLE from './drm-badge.css?inline';\nimport { style } from './shared.js';\n\n/** The name a viewer knows a key system by. */\nfunction keySystemName(id: string): string {\n if (id.startsWith('com.widevine')) return 'Widevine';\n if (id.startsWith('com.microsoft.playready')) return 'PlayReady';\n if (id.startsWith('com.apple.fps')) return 'FairPlay';\n return id;\n}\n\nexport class MbxDrmBadge extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-key', 'label-keys', 'label-no-key'];\n }\n\n declare private readonly tooltip: HTMLElement;\n declare private readonly system: HTMLElement;\n declare private readonly system_id: HTMLElement;\n declare private readonly keys: HTMLElement;\n declare private drm: DrmApi | undefined;\n\n constructor() {\n super();\n this.drm = undefined;\n const root = this.attachShadow({ mode: 'open' });\n const slot = document.createElement('slot');\n slot.name = 'icon';\n slot.append(icon('lock-closed'));\n this.tooltip = el('div', 'tooltip');\n this.tooltip.setAttribute('role', 'tooltip');\n this.system = el('div', 'tooltip-title');\n this.system_id = el('div', 'tooltip-text');\n this.keys = el('div', 'tooltip-text');\n this.tooltip.append(this.system, this.system_id, this.keys);\n this.tooltip.hidden = true;\n root.append(style(STYLE), slot, this.tooltip);\n const show = (): void => {\n this.tooltip.hidden = false;\n };\n const hide = (): void => {\n this.tooltip.hidden = true;\n };\n this.addEventListener('pointerenter', show);\n this.addEventListener('pointerleave', hide);\n this.addEventListener('focus', show);\n this.addEventListener('blur', hide);\n }\n\n /** Named and focusable before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (!this.hasAttribute('role')) this.setAttribute('role', 'img');\n if (!this.hasAttribute('tabindex')) this.tabIndex = 0;\n if (this.player === null) this.hidden = true;\n super.connectedCallback();\n }\n\n /** \"3 keys: usable ×2, expired\", or \"no key yet\". */\n private sessionsText(sessions: ReadonlyArray<{ readonly status: string }>): string {\n if (sessions.length === 0) return this.getAttribute('label-no-key') ?? 'no key yet';\n const counts = new Map<string, number>();\n for (const session of sessions) {\n counts.set(session.status, (counts.get(session.status) ?? 0) + 1);\n }\n const parts: string[] = [];\n for (const [status, count] of counts) parts.push(count > 1 ? `${status} ×${count}` : status);\n const template =\n sessions.length === 1\n ? (this.getAttribute('label-key') ?? '{count} key: {statuses}')\n : (this.getAttribute('label-keys') ?? '{count} keys: {statuses}');\n return fill(template, { count: sessions.length, statuses: parts.join(', ') });\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n // The engine's DRM, or the attachment a native session made: one API, the same events.\n const eme = player.player?.session?.eme;\n const source = engine ?? eme;\n this.drm = engine === null ? eme?.drm : namespaces(engine).drm;\n this.render();\n if (source === undefined || this.drm === undefined) return undefined;\n const tick = (): void => {\n this.render();\n };\n const offs = ['drm:keysystem', 'drm:keystatus', 'drm:encrypted'].map((event) =>\n source.on(event, tick),\n );\n return () => {\n for (const off of offs) off();\n };\n });\n }\n\n protected override detach(): void {\n this.tooltip.hidden = true;\n }\n\n protected override render(): void {\n const drm = this.drm;\n const name = drm?.keySystem ?? null;\n this.hidden = name === null;\n if (drm === undefined || name === null) return;\n const keys = this.sessionsText(drm.sessions);\n const system = keySystemName(name);\n this.system.textContent = system;\n this.system_id.textContent = name;\n this.keys.textContent = keys;\n this.setAttribute(\n 'aria-label',\n fill(this.getAttribute('label') ?? 'Protected by {system}, {keys}', { system, keys }),\n );\n }\n}\n"],"mappings":";;;;;;;AAmBA,MAAA,QAAA;;AAIA,SAAA,cAAA,IAAA;CACA,IAAA,GAAA,WAAA,cAAA,GAAA,OAAA;CACA,IAAA,GAAA,WAAA,yBAAA,GAAA,OAAA;CACA,IAAA,GAAA,WAAA,eAAA,GAAA,OAAA;CACA,OAAA;AACA;AAEA,IAAA,cAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA;GAAA;GAAA;GAAA;GAAA;EAAA;CACA;CAQA,cAAA;EACA,MAAA;EACA,KAAA,MAAA,KAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,MAAA,OAAA,SAAA,cAAA,MAAA;EACA,KAAA,OAAA;EACA,KAAA,OAAA,KAAA,aAAA,CAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,QAAA,aAAA,QAAA,SAAA;EACA,KAAA,SAAA,GAAA,OAAA,eAAA;EACA,KAAA,YAAA,GAAA,OAAA,cAAA;EACA,KAAA,OAAA,GAAA,OAAA,cAAA;EACA,KAAA,QAAA,OAAA,KAAA,QAAA,KAAA,WAAA,KAAA,IAAA;EACA,KAAA,QAAA,SAAA;EACA,KAAA,OAAA,MAAA,KAAA,GAAA,MAAA,KAAA,OAAA;EACA,MAAA,aAAA;GACA,KAAA,QAAA,SAAA;EACA;EACA,MAAA,aAAA;GACA,KAAA,QAAA,SAAA;EACA;EACA,KAAA,iBAAA,gBAAA,IAAA;EACA,KAAA,iBAAA,gBAAA,IAAA;EACA,KAAA,iBAAA,SAAA,IAAA;EACA,KAAA,iBAAA,QAAA,IAAA;CACA;;CAGA,oBAAA;EACA,IAAA,CAAA,KAAA,aAAA,MAAA,GAAA,KAAA,aAAA,QAAA,KAAA;EACA,IAAA,CAAA,KAAA,aAAA,UAAA,GAAA,KAAA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AA,SAAA,cAAA,IAAA;EACA,KAAA,OAAA,cAAA;EACA,KAAA,UAAA,cAAA;EACA,KAAA,KAAA,cAAA;EACA,KAAA,aACA,cACA,KAAA,KAAA,aAAA,OAAA,KAAA,iCAAA;GAAA;GAAA;EAAA,CAAA,CACA;CACA;AACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/elements/duration.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,qBAAa,WAAY,SAAQ,WAAW;;cAKvB,MAAM,IAAI,IAAI;CAQlC"}
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/elements/duration.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,qBAAa,WAAY,SAAQ,WAAW;;cAKvB,MAAM,IAAI,IAAI;CAclC"}
@@ -4,7 +4,9 @@ import { TimeElement } from "./time-element.js";
4
4
  //#region src/elements/duration.ts
5
5
  /**
6
6
  * <mbx-duration>: the duration, "4:56", once the metadata is in. A live
7
- * stream has none, so the element hides while the stream is live.
7
+ * stream has none, so the element hides while the stream is live. On a
8
+ * compact player it shows the time left, "-3:12", in place of the current
9
+ * time, which hides there.
8
10
  */
9
11
  const TRAILING = ":host{text-align:right}";
10
12
  var MbxDuration = class extends TimeElement {
@@ -17,7 +19,9 @@ var MbxDuration = class extends TimeElement {
17
19
  const engine = player.engine;
18
20
  const on = live(engine) !== void 0;
19
21
  this.hidden = on;
20
- if (!on) this.text.data = format(span(player.video, engine).end);
22
+ if (on) return;
23
+ const end = span(player.video, engine).end;
24
+ this.text.data = this.getAttribute("layout") === "compact" ? `-${format(Math.max(0, end - player.video.currentTime))}` : format(end);
21
25
  }
22
26
  };
23
27
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (!on) this.text.data = format(span(player.video, engine).end);\n }\n}\n"],"mappings":";;;;;;;;AAOA,MAAA,WAAA;AAEA,IAAA,cAAA,cAAA,YAAA;CACA,cAAA;EACA,MAAA,QAAA;CACA;CAEA,SAAA;EACA,MAAA,SAAA,KAAA;EACA,IAAA,WAAA,MAAA;EACA,MAAA,SAAA,OAAA;EACA,MAAA,KAAA,KAAA,MAAA,MAAA,KAAA;EACA,KAAA,SAAA;EACA,IAAA,CAAA,IAAA,KAAA,KAAA,OAAA,OAAA,KAAA,OAAA,OAAA,MAAA,CAAA,CAAA,GAAA;CACA;AACA"}
1
+ {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live. On a\n * compact player it shows the time left, \"-3:12\", in place of the current\n * time, which hides there.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (on) return;\n const end = span(player.video, engine).end;\n // A compact player has one readout, so this one counts down.\n this.text.data =\n this.getAttribute('layout') === 'compact'\n ? `-${format(Math.max(0, end - player.video.currentTime))}`\n : format(end);\n }\n}\n"],"mappings":";;;;;;;;;;AASA,MAAA,WAAA;AAEA,IAAA,cAAA,cAAA,YAAA;CACA,cAAA;EACA,MAAA,QAAA;CACA;CAEA,SAAA;EACA,MAAA,SAAA,KAAA;EACA,IAAA,WAAA,MAAA;EACA,MAAA,SAAA,OAAA;EACA,MAAA,KAAA,KAAA,MAAA,MAAA,KAAA;EACA,KAAA,SAAA;EACA,IAAA,IAAA;EACA,MAAA,MAAA,KAAA,OAAA,OAAA,MAAA,CAAA,CAAA;EAEA,KAAA,KAAA,OACA,KAAA,aAAA,QAAA,MAAA,YACA,IAAA,OAAA,KAAA,IAAA,GAAA,MAAA,OAAA,MAAA,WAAA,CAAA,MACA,OAAA,GAAA;CACA;AACA"}