@mattebox/player 0.14.0 → 0.16.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.
- package/dist/cdn/mattebox-player.min.js +3 -3
- package/dist/controls/chapters.d.ts +2 -8
- package/dist/controls/chapters.d.ts.map +1 -1
- package/dist/controls/chapters.js +1 -1
- package/dist/controls/chapters.js.map +1 -1
- package/dist/controls/cues.d.ts.map +1 -1
- package/dist/controls/cues.js +2 -2
- package/dist/controls/cues.js.map +1 -1
- package/dist/controls/icons.d.ts +1 -1
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +2 -0
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/native-tracks.js +1 -1
- package/dist/controls/native-tracks.js.map +1 -1
- package/dist/element-entry.d.ts +1 -0
- package/dist/element-entry.d.ts.map +1 -1
- package/dist/element-entry.js.map +1 -1
- package/dist/element.d.ts +68 -5
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +242 -42
- package/dist/element.js.map +1 -1
- package/dist/elements/airplay-button.js +1 -1
- package/dist/elements/airplay-button.js.map +1 -1
- package/dist/elements/audio-menu.d.ts.map +1 -1
- package/dist/elements/audio-menu.js +4 -3
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/casting.d.ts +15 -0
- package/dist/elements/casting.d.ts.map +1 -0
- package/dist/elements/casting.js +55 -0
- package/dist/elements/casting.js.map +1 -0
- package/dist/elements/chapters-menu.js +5 -5
- package/dist/elements/chapters-menu.js.map +1 -1
- package/dist/elements/component.d.ts +13 -0
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +21 -3
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +16 -2
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +29 -7
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.js +2 -2
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.js +2 -2
- package/dist/elements/drm-badge.js.map +1 -1
- package/dist/elements/duration.js +3 -3
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.js +2 -2
- package/dist/elements/error-screen.js.map +1 -1
- package/dist/elements/fullscreen-button.d.ts.map +1 -1
- package/dist/elements/fullscreen-button.js +3 -2
- package/dist/elements/fullscreen-button.js.map +1 -1
- package/dist/elements/live-button.js +3 -3
- package/dist/elements/live-button.js.map +1 -1
- package/dist/elements/marker-button.js +3 -3
- package/dist/elements/marker-button.js.map +1 -1
- package/dist/elements/menu-element.js +3 -3
- package/dist/elements/menu-element.js.map +1 -1
- package/dist/elements/mute-button.js +3 -3
- package/dist/elements/mute-button.js.map +1 -1
- package/dist/elements/pip-button.d.ts.map +1 -1
- package/dist/elements/pip-button.js +6 -2
- package/dist/elements/pip-button.js.map +1 -1
- package/dist/elements/play-button.js +3 -3
- package/dist/elements/play-button.js.map +1 -1
- package/dist/elements/quality-menu.d.ts.map +1 -1
- package/dist/elements/quality-menu.js +5 -4
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/remaining-time.js +2 -2
- package/dist/elements/remaining-time.js.map +1 -1
- package/dist/elements/scan-button.d.ts.map +1 -1
- package/dist/elements/scan-button.js +4 -3
- package/dist/elements/scan-button.js.map +1 -1
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +20 -16
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.js +4 -4
- package/dist/elements/shared.js.map +1 -1
- package/dist/elements/skip-button.js +2 -2
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spacer.js.map +1 -1
- package/dist/elements/speed-menu.d.ts.map +1 -1
- package/dist/elements/speed-menu.js +4 -3
- package/dist/elements/speed-menu.js.map +1 -1
- package/dist/elements/spinner.js +1 -1
- package/dist/elements/spinner.js.map +1 -1
- package/dist/elements/start-button.js +3 -3
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.d.ts.map +1 -1
- package/dist/elements/subtitles-menu.js +34 -10
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/time-element.js +1 -1
- package/dist/elements/time-element.js.map +1 -1
- package/dist/elements/title.js +1 -1
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/video-menu.d.ts.map +1 -1
- package/dist/elements/video-menu.js +5 -4
- package/dist/elements/video-menu.js.map +1 -1
- package/dist/elements/volume-slider.js +4 -4
- package/dist/elements/volume-slider.js.map +1 -1
- package/dist/elements/volume.js.map +1 -1
- package/dist/entries/airplay-button.js +1 -1
- package/dist/entries/audio-menu.js +1 -1
- package/dist/entries/casting.d.ts +5 -0
- package/dist/entries/casting.d.ts.map +1 -0
- package/dist/entries/casting.js +8 -0
- package/dist/entries/casting.js.map +1 -0
- package/dist/entries/chapters-menu.js +1 -1
- package/dist/entries/control-bar.js +1 -1
- package/dist/entries/current-time.js +1 -1
- package/dist/entries/drm-badge.js +1 -1
- package/dist/entries/duration.js +1 -1
- package/dist/entries/error-screen.js +1 -1
- package/dist/entries/fullscreen-button.js +1 -1
- package/dist/entries/live-button.js +1 -1
- package/dist/entries/marker-button.js +1 -1
- package/dist/entries/mute-button.js +1 -1
- package/dist/entries/pip-button.js +1 -1
- package/dist/entries/play-button.js +1 -1
- package/dist/entries/quality-menu.js +1 -1
- package/dist/entries/remaining-time.js +1 -1
- package/dist/entries/scan-button.js +1 -1
- package/dist/entries/seek-bar.js +1 -1
- package/dist/entries/skip-button.js +1 -1
- package/dist/entries/spacer.js +1 -1
- package/dist/entries/speed-menu.js +1 -1
- package/dist/entries/spinner.js +1 -1
- package/dist/entries/start-button.js +1 -1
- package/dist/entries/subtitles-menu.js +1 -1
- package/dist/entries/title.js +1 -1
- package/dist/entries/video-menu.js +1 -1
- package/dist/entries/volume-slider.js +1 -1
- package/dist/entries/volume.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +2 -2
- package/dist/es2015/controls/cues.js +2 -2
- package/dist/es2015/controls/icons.js +2 -0
- package/dist/es2015/controls/menu.js +1 -1
- package/dist/es2015/controls/native-tracks.js +1 -1
- package/dist/es2015/element.js +262 -55
- package/dist/es2015/elements/airplay-button.js +1 -1
- package/dist/es2015/elements/audio-menu.js +4 -3
- package/dist/es2015/elements/casting.js +55 -0
- package/dist/es2015/elements/chapters-menu.js +5 -5
- package/dist/es2015/elements/component.js +26 -7
- package/dist/es2015/elements/control-bar.js +29 -7
- package/dist/es2015/elements/current-time.js +2 -2
- package/dist/es2015/elements/drm-badge.js +2 -2
- package/dist/es2015/elements/duration.js +3 -3
- package/dist/es2015/elements/error-screen.js +2 -2
- package/dist/es2015/elements/fullscreen-button.js +3 -2
- package/dist/es2015/elements/live-button.js +3 -3
- package/dist/es2015/elements/marker-button.js +3 -3
- package/dist/es2015/elements/menu-element.js +4 -4
- package/dist/es2015/elements/mute-button.js +3 -3
- package/dist/es2015/elements/pip-button.js +6 -2
- package/dist/es2015/elements/play-button.js +3 -3
- package/dist/es2015/elements/quality-menu.js +5 -4
- package/dist/es2015/elements/remaining-time.js +2 -2
- package/dist/es2015/elements/scan-button.js +4 -3
- package/dist/es2015/elements/seek-bar.js +20 -16
- package/dist/es2015/elements/shared.js +4 -4
- package/dist/es2015/elements/skip-button.js +2 -2
- package/dist/es2015/elements/speed-menu.js +4 -3
- package/dist/es2015/elements/spinner.js +1 -1
- package/dist/es2015/elements/start-button.js +3 -3
- package/dist/es2015/elements/subtitles-menu.js +34 -10
- package/dist/es2015/elements/time-element.js +1 -1
- package/dist/es2015/elements/title.js +1 -1
- package/dist/es2015/elements/video-menu.js +5 -4
- package/dist/es2015/elements/volume-slider.js +4 -4
- package/dist/es2015/entries/airplay-button.js +1 -1
- package/dist/es2015/entries/audio-menu.js +1 -1
- package/dist/es2015/entries/casting.js +6 -0
- package/dist/es2015/entries/chapters-menu.js +1 -1
- package/dist/es2015/entries/control-bar.js +1 -1
- package/dist/es2015/entries/current-time.js +1 -1
- package/dist/es2015/entries/drm-badge.js +1 -1
- package/dist/es2015/entries/duration.js +1 -1
- package/dist/es2015/entries/error-screen.js +1 -1
- package/dist/es2015/entries/fullscreen-button.js +1 -1
- package/dist/es2015/entries/live-button.js +1 -1
- package/dist/es2015/entries/marker-button.js +1 -1
- package/dist/es2015/entries/mute-button.js +1 -1
- package/dist/es2015/entries/pip-button.js +1 -1
- package/dist/es2015/entries/play-button.js +1 -1
- package/dist/es2015/entries/quality-menu.js +1 -1
- package/dist/es2015/entries/remaining-time.js +1 -1
- package/dist/es2015/entries/scan-button.js +1 -1
- package/dist/es2015/entries/seek-bar.js +1 -1
- package/dist/es2015/entries/skip-button.js +1 -1
- package/dist/es2015/entries/spacer.js +1 -1
- package/dist/es2015/entries/speed-menu.js +1 -1
- package/dist/es2015/entries/spinner.js +1 -1
- package/dist/es2015/entries/start-button.js +1 -1
- package/dist/es2015/entries/subtitles-menu.js +1 -1
- package/dist/es2015/entries/title.js +1 -1
- package/dist/es2015/entries/video-menu.js +1 -1
- package/dist/es2015/entries/volume-slider.js +1 -1
- package/dist/es2015/entries/volume.js +1 -1
- package/dist/es2015/host.js +9 -1
- package/dist/es2015/index.js +5 -3
- package/dist/es2015/locales/ar.js +4 -1
- package/dist/es2015/locales/ca.js +4 -1
- package/dist/es2015/locales/de.js +4 -1
- package/dist/es2015/locales/es.js +4 -1
- package/dist/es2015/locales/fr.js +4 -1
- package/dist/es2015/locales/hi.js +4 -1
- package/dist/es2015/locales/it.js +4 -1
- package/dist/es2015/locales/ja.js +4 -1
- package/dist/es2015/locales/ko.js +4 -1
- package/dist/es2015/locales/pt.js +4 -1
- package/dist/es2015/locales/zh.js +4 -1
- package/dist/es2015/locales.js +1 -1
- package/dist/es2015/media.js +136 -0
- package/dist/es2015/presets.js +3 -2
- package/dist/es2015/style.js +1 -1
- package/dist/es2015/tags.js +2 -1
- package/dist/es2015/video-sources.js +1 -1
- package/dist/host.d.ts +32 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +9 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/locales/ar.d.ts +3 -0
- package/dist/locales/ar.d.ts.map +1 -1
- package/dist/locales/ar.js +4 -1
- package/dist/locales/ar.js.map +1 -1
- package/dist/locales/ca.d.ts +3 -0
- package/dist/locales/ca.d.ts.map +1 -1
- package/dist/locales/ca.js +4 -1
- package/dist/locales/ca.js.map +1 -1
- package/dist/locales/de.d.ts +3 -0
- package/dist/locales/de.d.ts.map +1 -1
- package/dist/locales/de.js +4 -1
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/es.d.ts +3 -0
- package/dist/locales/es.d.ts.map +1 -1
- package/dist/locales/es.js +4 -1
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fr.d.ts +3 -0
- package/dist/locales/fr.d.ts.map +1 -1
- package/dist/locales/fr.js +4 -1
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/hi.d.ts +3 -0
- package/dist/locales/hi.d.ts.map +1 -1
- package/dist/locales/hi.js +4 -1
- package/dist/locales/hi.js.map +1 -1
- package/dist/locales/it.d.ts +3 -0
- package/dist/locales/it.d.ts.map +1 -1
- package/dist/locales/it.js +4 -1
- package/dist/locales/it.js.map +1 -1
- package/dist/locales/ja.d.ts +3 -0
- package/dist/locales/ja.d.ts.map +1 -1
- package/dist/locales/ja.js +4 -1
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.d.ts +3 -0
- package/dist/locales/ko.d.ts.map +1 -1
- package/dist/locales/ko.js +4 -1
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/pt.d.ts +3 -0
- package/dist/locales/pt.d.ts.map +1 -1
- package/dist/locales/pt.js +4 -1
- package/dist/locales/pt.js.map +1 -1
- package/dist/locales/zh.d.ts +3 -0
- package/dist/locales/zh.d.ts.map +1 -1
- package/dist/locales/zh.js +4 -1
- package/dist/locales/zh.js.map +1 -1
- package/dist/media.d.ts +22 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +136 -0
- package/dist/media.js.map +1 -0
- package/dist/messages.d.ts +6 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/presets.js +2 -1
- package/dist/presets.js.map +1 -1
- package/dist/remote.d.ts +80 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/tags.d.ts +1 -0
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +2 -1
- package/dist/tags.js.map +1 -1
- package/package.json +3 -3
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/toPrimitive.js +0 -13
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { icon } from "../controls/icons.js";
|
|
2
|
+
import { el } from "../dom.js";
|
|
3
|
+
import { fill } from "../labels.js";
|
|
4
|
+
import { Component } from "./component.js";
|
|
5
|
+
import { style } from "./shared.js";
|
|
6
|
+
// src/elements/casting.ts
|
|
7
|
+
const STYLE = ":host{color:var(--mbx-text);font-family:var(--mbx-font);pointer-events:none;background:#000;justify-content:center;align-items:center;display:none;position:absolute;top:0;bottom:0;left:0;right:0}:host([casting]){display:flex}:host([hidden]){display:none}[part~=poster]{object-fit:contain;opacity:.35;width:100%;height:100%;position:absolute;top:0;left:0}[part~=device]{max-width:100%;padding:0 var(--mbx-pad) var(--mbx-bar-rows,0px);text-align:center;text-shadow:0 1px 3px #0009;flex-direction:column;align-items:center;display:flex;position:relative}[part~=icon]{fill:currentColor;filter:drop-shadow(0 1px 3px #0009);width:3.5em;height:3.5em;margin-bottom:.6em}[part~=label]{font-size:1.25em;font-weight:600;line-height:1.3}:host([layout=compact]) [part~=icon]{width:2.5em;height:2.5em;margin-bottom:.4em}:host([layout=compact]) [part~=label]{font-size:1em}";
|
|
8
|
+
var MbxCasting = class extends Component {
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["label"];
|
|
11
|
+
}
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
const root = this.attachShadow({ mode: "open" });
|
|
15
|
+
this.poster = el("img", "poster");
|
|
16
|
+
this.poster.alt = "";
|
|
17
|
+
this.poster.hidden = true;
|
|
18
|
+
this.device = el("div", "device");
|
|
19
|
+
this.label = el("div", "label");
|
|
20
|
+
this.label.setAttribute("role", "status");
|
|
21
|
+
this.device.append(this.label);
|
|
22
|
+
this.glyph = null;
|
|
23
|
+
root.append(style(STYLE), this.poster, this.device);
|
|
24
|
+
}
|
|
25
|
+
attach(player) {
|
|
26
|
+
this.listen(player, ["programmechange"], () => {
|
|
27
|
+
this.render();
|
|
28
|
+
});
|
|
29
|
+
this.render();
|
|
30
|
+
}
|
|
31
|
+
detach() {
|
|
32
|
+
this.removeAttribute("casting");
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
const player = this.player;
|
|
36
|
+
const target = player?.casting ?? null;
|
|
37
|
+
if (target === null) this.removeAttribute("casting");
|
|
38
|
+
else this.setAttribute("casting", target.kind);
|
|
39
|
+
if (player === null || target === null) return;
|
|
40
|
+
const metadata = player.programme?.metadata;
|
|
41
|
+
const poster = metadata?.poster ?? metadata?.image ?? player.getAttribute("poster");
|
|
42
|
+
this.poster.hidden = poster === null || poster === void 0;
|
|
43
|
+
if (poster !== null && poster !== void 0 && this.poster.getAttribute("src") !== poster) this.poster.src = poster;
|
|
44
|
+
const glyph = target.kind === "airplay" ? "airplay-active" : "cast";
|
|
45
|
+
if (glyph !== this.glyph) {
|
|
46
|
+
this.glyph = glyph;
|
|
47
|
+
this.device.querySelector("svg")?.remove();
|
|
48
|
+
this.device.insertBefore(icon(glyph), this.label);
|
|
49
|
+
}
|
|
50
|
+
this.label.textContent = target.name === "" ? target.kind === "airplay" ? this.word("label", "airplay", "AirPlay") : "" : fill(this.word("label", "castingTo", "Casting to {device}"), { device: target.name });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export { MbxCasting };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=casting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"casting.js","names":[],"sources":["../../src/elements/casting.ts"],"sourcesContent":["/**\n * <mbx-casting>: what the picture shows while a device plays in the\n * video's place. The programme's poster, or its image, covers the paused\n * video, dimmed, and the device's glyph sits over it with a line that names\n * the device: \"Casting to Living room\". The controls stay as they are and\n * drive the device, and the bar does not hide while it plays.\n *\n * Shown while the player carries `casting`, for a Chromecast and for\n * AirPlay alike, and hidden otherwise. The element carries `casting` too,\n * with the device's kind, so a page styles one kind in CSS. Safari names no AirPlay device, so\n * the line is \"AirPlay\" there. The `label` attribute gives the line its\n * words, with `{device}` for the name. Placed first among the screens, so\n * the title, the start button and the bar paint over it.\n */\nimport type { IconName } from '../controls/icons.js';\nimport { icon } from '../controls/icons.js';\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport STYLE from './casting.css?inline';\nimport { Component } from './component.js';\nimport { style } from './shared.js';\n\nexport class MbxCasting extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label'];\n }\n\n declare private readonly poster: HTMLImageElement;\n declare private readonly device: HTMLElement;\n declare private readonly label: HTMLElement;\n /** The glyph on show, so a render that changes nothing leaves it in place. */\n declare private glyph: IconName | null;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.poster = el('img', 'poster');\n this.poster.alt = '';\n this.poster.hidden = true;\n this.device = el('div', 'device');\n this.label = el('div', 'label');\n // Said once when the device takes over.\n this.label.setAttribute('role', 'status');\n this.device.append(this.label);\n this.glyph = null;\n root.append(style(STYLE), this.poster, this.device);\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player, ['programmechange'], () => {\n this.render();\n });\n this.render();\n }\n\n protected override detach(): void {\n this.removeAttribute('casting');\n }\n\n protected override render(): void {\n const player = this.player;\n const target = player?.casting ?? null;\n // The device's kind on the element, for its own stylesheet and the page's.\n if (target === null) this.removeAttribute('casting');\n else this.setAttribute('casting', target.kind);\n if (player === null || target === null) return;\n const metadata = player.programme?.metadata;\n const poster = metadata?.poster ?? metadata?.image ?? player.getAttribute('poster');\n this.poster.hidden = poster === null || poster === undefined;\n if (poster !== null && poster !== undefined && this.poster.getAttribute('src') !== poster) {\n this.poster.src = poster;\n }\n const glyph: IconName = target.kind === 'airplay' ? 'airplay-active' : 'cast';\n if (glyph !== this.glyph) {\n this.glyph = glyph;\n this.device.querySelector('svg')?.remove();\n this.device.insertBefore(icon(glyph), this.label);\n }\n this.label.textContent =\n target.name === ''\n ? target.kind === 'airplay'\n ? this.word('label', 'airplay', 'AirPlay')\n : ''\n : fill(this.word('label', 'castingTo', 'Casting to {device}'), { device: target.name });\n }\n}\n"],"mappings":";;;;;;AAmBA,MAAA,QAAA;AAIA,IAAa,aAAb,cAAgC,UAAU;CACxC,WAAW,qBAAwC;EACjD,OAAO,CAAC,OAAO;CACjB;CAQA,cAAc;EACZ,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,GAAG,OAAO,QAAQ;EAChC,KAAK,OAAO,MAAM;EAClB,KAAK,OAAO,SAAS;EACrB,KAAK,SAAS,GAAG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-
import { show } from "./shared.js";
|
|
2
|
-
import { MenuElement, single } from "./menu-element.js";
|
|
3
|
-
import { format } from "../controls/time.js";
|
|
4
1
|
import { chapterAt, chapters, followChapters } from "../controls/chapters.js";
|
|
2
|
+
import { format } from "../controls/time.js";
|
|
3
|
+
import { MenuElement, single } from "./menu-element.js";
|
|
4
|
+
import { show } from "./shared.js";
|
|
5
5
|
// src/elements/chapters-menu.ts
|
|
6
6
|
/**
|
|
7
7
|
* <mbx-chapters-menu>: the chapters of the video as a list, each with its
|
|
@@ -30,7 +30,7 @@ var MbxChaptersMenu = class extends MenuElement {
|
|
|
30
30
|
this.render();
|
|
31
31
|
};
|
|
32
32
|
this.keep(followChapters(player, tick));
|
|
33
|
-
this.listen(player.
|
|
33
|
+
this.listen(player.media, [
|
|
34
34
|
"timeupdate",
|
|
35
35
|
"seeked",
|
|
36
36
|
"emptied",
|
|
@@ -41,7 +41,7 @@ var MbxChaptersMenu = class extends MenuElement {
|
|
|
41
41
|
}
|
|
42
42
|
render() {
|
|
43
43
|
super.render();
|
|
44
|
-
const video = this.player?.
|
|
44
|
+
const video = this.player?.media;
|
|
45
45
|
if (video === void 0) return;
|
|
46
46
|
const list = chapters(video, this.player?.engine ?? null);
|
|
47
47
|
this.hidden = list.length === 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chapters-menu.js","names":[],"sources":["../../src/elements/chapters-menu.ts"],"sourcesContent":["/**\n * <mbx-chapters-menu>: the chapters of the video as a list, each with its\n * start time, the one the playhead is in checked; choosing one seeks to its\n * start. The chapters are the engine's when the session holds some, and\n * the video's own chapters text track otherwise, see `controls/chapters.ts`,\n * so the menu works for every session, native included, and hides while\n * there are none. Each item shows the chapter's picture when every chapter\n * has one: a list where some rows have a picture and some do not reads as\n * broken. The name comes from `label`.\n */\nimport { chapterAt, chapters, followChapters } from '../controls/chapters.js';\nimport { format } from '../controls/time.js';\nimport type { PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\nexport class MbxChaptersMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back'];\n }\n\n /** What the last fill drew, so a cue change inside the same chapter leaves the popup alone. */\n declare private drawn: string;\n\n constructor() {\n super(...single('chapters'));\n this.drawn = '';\n show(this.slots, 'default');\n }\n\n protected override name(): readonly [keyof Messages, string] {\n return ['chapters', 'Chapters'];\n }\n\n protected override attach(player: PlayerHost): void {\n const tick = (): void => {\n this.render();\n };\n this.keep(followChapters(player, tick));\n // The clock too: WebKit fires no `cuechange` for a hidden track, and the\n // render is a no-op while the chapter is the same.\n this.listen(player.
|
|
1
|
+
{"version":3,"file":"chapters-menu.js","names":[],"sources":["../../src/elements/chapters-menu.ts"],"sourcesContent":["/**\n * <mbx-chapters-menu>: the chapters of the video as a list, each with its\n * start time, the one the playhead is in checked; choosing one seeks to its\n * start. The chapters are the engine's when the session holds some, and\n * the video's own chapters text track otherwise, see `controls/chapters.ts`,\n * so the menu works for every session, native included, and hides while\n * there are none. Each item shows the chapter's picture when every chapter\n * has one: a list where some rows have a picture and some do not reads as\n * broken. The name comes from `label`.\n */\nimport { chapterAt, chapters, followChapters } from '../controls/chapters.js';\nimport { format } from '../controls/time.js';\nimport type { PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\nexport class MbxChaptersMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back'];\n }\n\n /** What the last fill drew, so a cue change inside the same chapter leaves the popup alone. */\n declare private drawn: string;\n\n constructor() {\n super(...single('chapters'));\n this.drawn = '';\n show(this.slots, 'default');\n }\n\n protected override name(): readonly [keyof Messages, string] {\n return ['chapters', 'Chapters'];\n }\n\n protected override attach(player: PlayerHost): void {\n const tick = (): void => {\n this.render();\n };\n this.keep(followChapters(player, tick));\n // The clock too: WebKit fires no `cuechange` for a hidden track, and the\n // render is a no-op while the chapter is the same.\n this.listen(player.media, ['timeupdate', 'seeked', 'emptied', 'loadedmetadata'], tick);\n this.listen(player, ['sourcechange'], tick);\n this.render();\n }\n\n protected override render(): void {\n super.render();\n const video = this.player?.media;\n if (video === undefined) return;\n const list = chapters(video, this.player?.engine ?? null);\n this.hidden = list.length === 0;\n const current = String(chapterAt(list, video.currentTime));\n const pictured = list.every((chapter) => chapter.image !== undefined);\n const items = list.map((chapter, i): readonly [string, string, string, string?] =>\n pictured && chapter.image !== undefined\n ? [String(i), chapter.title, format(chapter.start), chapter.image]\n : [String(i), chapter.title, format(chapter.start)],\n );\n const key = `${current}|${items.map((item) => item.slice(1).join(' ')).join('\\n')}`;\n if (key === this.drawn) return;\n this.drawn = key;\n this.menu.fill([\n {\n name: 'chapter',\n items,\n value: current,\n onSelect: (value) => {\n const chapter = list[Number(value)];\n if (chapter !== undefined) video.currentTime = chapter.start;\n },\n },\n ]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAa,kBAAb,cAAqC,YAAY;CAC/C,WAAW,qBAAwC;EACjD,OAAO,CAAC,SAAS,YAAY;CAC/B;CAKA,cAAc;EACZ,MAAM,GAAG,OAAO,UAAU,CAAC;EAC3B,KAAK,QAAQ;EACb,KAAK,KAAK,OAAO,SAAS;CAC5B;CAEmB,OAA0C;EAC3D,OAAO,CAAC,YAAY,UAAU;CAChC;CAEmB,OAAO,QAA0B;EAClD,MAAM,aAAmB;GACvB,KAAK,OAAO;EACd;EACA,KAAK,KAAK,eAAe,QAAQ,IAAI,CAAC;EAGtC,KAAK,OAAO,OAAO,OAAO;GAAC;GAAc;GAAU;GAAW;EAAgB,GAAG,IAAI;EACrF,KAAK,OAAO,QAAQ,CAAC,cAAc,GAAG,IAAI;EAC1C,KAAK,OAAO;CACd;CAEmB,SAAe;EAChC,MAAM,OAAO;EACb,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,OAAO,SAAS,OAAO,KAAK,QAAQ,UAAU,IAAI;EACxD,KAAK,SAAS,KAAK,WAAW;EAC9B,MAAM,UAAU,OAAO,UAAU,MAAM,MAAM,WAAW,CAAC;EACzD,MAAM,WAAW,KAAK,OAAO,YAAY,QAAQ,UAAU,KAAA,CAAS;EACpE,MAAM,QAAQ,KAAK,KAAK,SAAS,MAC/B,YAAY,QAAQ,UAAU,KAAA,IAC1B;GAAC,OAAO,CAAC;GAAG,QAAQ;GAAO,OAAO,QAAQ,KAAK;GAAG,QAAQ;EAAK,IAC/D;GAAC,OAAO,CAAC;GAAG,QAAQ;GAAO,OAAO,QAAQ,KAAK;EAAC,CACtD;EACA,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI;EAChF,IAAI,QAAQ,KAAK,OAAO;EACxB,KAAK,QAAQ;EACb,KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN;GACA,OAAO;GACP,WAAW,UAAU;IACnB,MAAM,UAAU,KAAK,OAAO,KAAK;IACjC,IAAI,YAAY,KAAA,GAAW,MAAM,cAAc,QAAQ;GACzD;EACF,CACF,CAAC;CACH;AACF"}
|
|
@@ -18,6 +18,14 @@ import type { Messages } from '../messages.js';
|
|
|
18
18
|
import type { Text } from '../text.js';
|
|
19
19
|
export declare abstract class Component extends HTMLElement {
|
|
20
20
|
protected player: PlayerHost | null;
|
|
21
|
+
/**
|
|
22
|
+
* When the control has nothing to act on while a device plays in the
|
|
23
|
+
* video's place: `device` for any device, since the control acts on the
|
|
24
|
+
* picture of the page or on its quality, and `remote` for a device that
|
|
25
|
+
* is not the video itself, as AirPlay is. The control then carries
|
|
26
|
+
* `away`, and its stylesheet hides it. Null for a control that stays.
|
|
27
|
+
*/
|
|
28
|
+
protected leaves: 'device' | 'remote' | null;
|
|
21
29
|
private offs;
|
|
22
30
|
/** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */
|
|
23
31
|
private epoch;
|
|
@@ -27,6 +35,11 @@ export declare abstract class Component extends HTMLElement {
|
|
|
27
35
|
attributeChangedCallback(): void;
|
|
28
36
|
/** Adds `fn` for every name on `target`, to be removed on detach. */
|
|
29
37
|
protected listen(target: EventTarget, names: readonly string[], fn: (event: Event) => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Whether a device plays that is not the video itself. Under AirPlay the
|
|
40
|
+
* video still plays the source and answers every member.
|
|
41
|
+
*/
|
|
42
|
+
protected remote(): boolean;
|
|
30
43
|
/**
|
|
31
44
|
* A word the control shows: its `attribute` when the page set one, else
|
|
32
45
|
* the player's language's `id`, else `english`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/elements/component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,8BAAsB,SAAU,SAAQ,WAAW;IACjD,UAAkB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5C,QAAgB,IAAI,CAAoB;IACxC,yGAAyG;IACzG,QAAgB,KAAK,CAAS;;
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/elements/component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM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AU,GAAG,IAAI;IAEnD,mFAAmF;IACnF,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAE3C,yFAAyF;IACzF,SAAS,CAAC,MAAM,IAAI,IAAI;CACzB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { findPlayer } from "../host.js";
|
|
1
2
|
import { PLAYER } from "../tags.js";
|
|
2
3
|
import { textIn } from "../text.js";
|
|
3
|
-
import { findPlayer } from "../host.js";
|
|
4
4
|
// src/elements/component.ts
|
|
5
5
|
var Component = class extends HTMLElement {
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
8
8
|
this.player = null;
|
|
9
|
+
this.leaves = null;
|
|
9
10
|
this.offs = [];
|
|
10
11
|
this.epoch = 0;
|
|
11
12
|
}
|
|
@@ -17,7 +18,7 @@ var Component = class extends HTMLElement {
|
|
|
17
18
|
const attach = () => {
|
|
18
19
|
if (epoch !== this.epoch || !this.isConnected) return;
|
|
19
20
|
customElements.upgrade(found);
|
|
20
|
-
if (!("
|
|
21
|
+
if (!("media" in found)) return;
|
|
21
22
|
this.player = found;
|
|
22
23
|
const tier = () => {
|
|
23
24
|
const layout = found.getAttribute("layout");
|
|
@@ -31,10 +32,19 @@ var Component = class extends HTMLElement {
|
|
|
31
32
|
this.listen(found, ["localechange"], () => {
|
|
32
33
|
this.render();
|
|
33
34
|
});
|
|
35
|
+
const cast = () => {
|
|
36
|
+
const gone = this.leaves !== null && found.hasAttribute("casting") && (this.leaves === "device" || this.remote());
|
|
37
|
+
this.toggleAttribute("away", gone);
|
|
38
|
+
};
|
|
39
|
+
this.listen(found, ["castingchange"], () => {
|
|
40
|
+
cast();
|
|
41
|
+
this.render();
|
|
42
|
+
});
|
|
34
43
|
tier();
|
|
44
|
+
cast();
|
|
35
45
|
this.attach(this.player);
|
|
36
46
|
};
|
|
37
|
-
if ("
|
|
47
|
+
if ("media" in found) attach();
|
|
38
48
|
else customElements.whenDefined(PLAYER).then(attach);
|
|
39
49
|
}
|
|
40
50
|
disconnectedCallback() {
|
|
@@ -57,6 +67,14 @@ var Component = class extends HTMLElement {
|
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
/**
|
|
70
|
+
* Whether a device plays that is not the video itself. Under AirPlay the
|
|
71
|
+
* video still plays the source and answers every member.
|
|
72
|
+
*/
|
|
73
|
+
remote() {
|
|
74
|
+
const target = this.player?.casting ?? null;
|
|
75
|
+
return target !== null && target.kind !== "airplay";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
60
78
|
* A word the control shows: its `attribute` when the page set one, else
|
|
61
79
|
* the player's language's `id`, else `english`.
|
|
62
80
|
*/
|
|
@@ -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 type { Messages } from '../messages.js';\nimport { PLAYER } from '../tags.js';\nimport type { Text } from '../text.js';\nimport { textIn } from '../text.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: `
|
|
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 type { Messages } from '../messages.js';\nimport { PLAYER } from '../tags.js';\nimport type { Text } from '../text.js';\nimport { textIn } from '../text.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n /**\n * When the control has nothing to act on while a device plays in the\n * video's place: `device` for any device, since the control acts on the\n * picture of the page or on its quality, and `remote` for a device that\n * is not the video itself, as AirPlay is. The control then carries\n * `away`, and its stylesheet hides it. Null for a control that stays.\n */\n declare protected leaves: 'device' | 'remote' | 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.leaves = 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: `media` is on the prototype.\n customElements.upgrade(found);\n if (!('media' 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 this.listen(found, ['localechange'], () => {\n this.render();\n });\n const cast = (): void => {\n const gone =\n this.leaves !== null &&\n found.hasAttribute('casting') &&\n (this.leaves === 'device' || this.remote());\n this.toggleAttribute('away', gone);\n };\n this.listen(found, ['castingchange'], () => {\n cast();\n this.render();\n });\n tier();\n cast();\n this.attach(this.player);\n };\n if ('media' 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 /**\n * Whether a device plays that is not the video itself. Under AirPlay the\n * video still plays the source and answers every member.\n */\n protected remote(): boolean {\n const target = this.player?.casting ?? null;\n return target !== null && target.kind !== 'airplay';\n }\n\n /**\n * A word the control shows: its `attribute` when the page set one, else\n * the player's language's `id`, else `english`.\n */\n protected word(attribute: string, id: keyof Messages, english: string): string {\n return this.getAttribute(attribute) ?? this.player?.message(id) ?? english;\n }\n\n /** Words the page gave, in the player's language. */\n protected pageText(text: Text): string {\n return textIn(text, this.player?.locale ?? '');\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":";;;;AAsBA,IAAsB,YAAtB,cAAwC,YAAY;CAclD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,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,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK,OAAO;GACd,CAAC;GACD,MAAM,aAAmB;IACvB,MAAM,OACJ,KAAK,WAAW,QAChB,MAAM,aAAa,SAAS,MAC3B,KAAK,WAAW,YAAY,KAAK,OAAO;IAC3C,KAAK,gBAAgB,QAAQ,IAAI;GACnC;GACA,KAAK,OAAO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U,QACR,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;;CAMU,OAAO,SAA2B,CAAC;;CAGnC,SAAe,CAAC;AAC5B"}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* The fade is one timer. Any activity, a pointer moving or pressing, a
|
|
12
12
|
* key, playback starting, re-arms it for `idle-ms`, and when it fires the
|
|
13
13
|
* bar hides unless something it can know for certain holds it: the video
|
|
14
|
-
* is paused, a descendant carries `open`, or
|
|
15
|
-
* where keyboard means the last input was a
|
|
14
|
+
* is paused, a device plays in its place, a descendant carries `open`, or
|
|
15
|
+
* keyboard focus is inside it, where keyboard means the last input was a
|
|
16
|
+
* key and not a pointer.
|
|
16
17
|
* Whether the pointer is over the player is never tracked: that goes
|
|
17
18
|
* stale when the pointer leaves without a move the player sees.
|
|
18
19
|
*
|
|
@@ -27,6 +28,13 @@
|
|
|
27
28
|
* the capture phase, decide before it. Space is left to a
|
|
28
29
|
* focused button, which is its own. A key another handler prevented is
|
|
29
30
|
* left alone. A click on the video toggles play.
|
|
31
|
+
*
|
|
32
|
+
* A tap is not a click. A finger on the picture shows the bar while it is
|
|
33
|
+
* hidden and hides it while it shows, and never plays or pauses, as on a
|
|
34
|
+
* phone's own players. The pointer's `pointerType` tells the two apart,
|
|
35
|
+
* not the device, since a laptop can have both. `tap-plays` gives a tap
|
|
36
|
+
* the click's play and pause back. During a cast the bar stays, so a tap
|
|
37
|
+
* plays and pauses there too.
|
|
30
38
|
* Fullscreen goes on the player itself, so the bar comes along.
|
|
31
39
|
*
|
|
32
40
|
* A narrow bar collapses the buttons row by `priority`: each child carries
|
|
@@ -51,6 +59,10 @@ export declare class MbxControlBar extends Component {
|
|
|
51
59
|
private resizer;
|
|
52
60
|
/** Whether the last input was a key, so focus inside holds the bar. */
|
|
53
61
|
private keyboard;
|
|
62
|
+
/** Whether the last press was a finger: its click on the video is a tap. */
|
|
63
|
+
private touch;
|
|
64
|
+
/** Whether the bar showed when that press began, before the press woke it. */
|
|
65
|
+
private shownAtPress;
|
|
54
66
|
private cues;
|
|
55
67
|
private screen;
|
|
56
68
|
constructor();
|
|
@@ -76,6 +88,8 @@ export declare class MbxControlBar extends Component {
|
|
|
76
88
|
private held;
|
|
77
89
|
private idle;
|
|
78
90
|
private sleep;
|
|
91
|
+
/** Hides the bar now, as a tap asks: the next input shows it again. */
|
|
92
|
+
private rest;
|
|
79
93
|
private wake;
|
|
80
94
|
/**
|
|
81
95
|
* A seeking key: `seekkey` on the player first, cancellable, with the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAmB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+E3C,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,4EAA4E;IAC5E,QAAgB,KAAK,CAAU;IAC/B,8EAA8E;IAC9E,QAAgB,YAAY,CAAU;IACtC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAwB1C;;;;;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;IAUZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK;IAWb,uEAAuE;IACvE,OAAO,CAAC,IAAI;IAMZ,OAAO,CAAC,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;cAmDQ,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cA0EhC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAgBpD"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { cueLift, cueStyle } from "../controls/cues.js";
|
|
2
|
+
import { fullscreen } from "../controls/fullscreen.js";
|
|
3
|
+
import { videoOf } from "../host.js";
|
|
1
4
|
import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SCAN_BUTTON, SKIP_BUTTON, SPEED_MENU, SUBTITLES_MENU, VIDEO_MENU, VOLUME, VOLUME_SLIDER } from "../tags.js";
|
|
2
5
|
import { Component } from "./component.js";
|
|
3
6
|
import { number, shownPaused, style } from "./shared.js";
|
|
4
|
-
import { cueLift, cueStyle } from "../controls/cues.js";
|
|
5
|
-
import { fullscreen } from "../controls/fullscreen.js";
|
|
6
7
|
// src/elements/control-bar.ts
|
|
7
8
|
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
9
|
const IDLE_MS = 3e3;
|
|
@@ -72,6 +73,8 @@ var MbxControlBar = class extends Component {
|
|
|
72
73
|
super();
|
|
73
74
|
this.timer = void 0;
|
|
74
75
|
this.keyboard = false;
|
|
76
|
+
this.touch = false;
|
|
77
|
+
this.shownAtPress = false;
|
|
75
78
|
this.cues = null;
|
|
76
79
|
this.screen = null;
|
|
77
80
|
this.resizer = null;
|
|
@@ -151,6 +154,7 @@ var MbxControlBar = class extends Component {
|
|
|
151
154
|
}
|
|
152
155
|
held(player) {
|
|
153
156
|
if (shownPaused(player, ["switching"])) return true;
|
|
157
|
+
if (player.hasAttribute("casting")) return true;
|
|
154
158
|
if (this.querySelector("[open]") !== null) return true;
|
|
155
159
|
if (!this.keyboard) return false;
|
|
156
160
|
const active = this.getRootNode().activeElement;
|
|
@@ -170,6 +174,12 @@ var MbxControlBar = class extends Component {
|
|
|
170
174
|
}
|
|
171
175
|
this.idle(player, true);
|
|
172
176
|
}
|
|
177
|
+
/** Hides the bar now, as a tap asks: the next input shows it again. */
|
|
178
|
+
rest(player) {
|
|
179
|
+
clearTimeout(this.timer);
|
|
180
|
+
this.timer = void 0;
|
|
181
|
+
this.idle(player, true);
|
|
182
|
+
}
|
|
173
183
|
wake(player) {
|
|
174
184
|
clearTimeout(this.timer);
|
|
175
185
|
this.idle(player, false);
|
|
@@ -186,14 +196,15 @@ var MbxControlBar = class extends Component {
|
|
|
186
196
|
cancelable: true
|
|
187
197
|
});
|
|
188
198
|
if (!player.dispatchEvent(asked)) return;
|
|
189
|
-
const video = player.
|
|
199
|
+
const video = player.media;
|
|
190
200
|
video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));
|
|
191
201
|
}
|
|
192
202
|
key(player, event) {
|
|
193
203
|
this.keyboard = true;
|
|
204
|
+
this.touch = false;
|
|
194
205
|
this.wake(player);
|
|
195
206
|
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
196
|
-
const video = player.
|
|
207
|
+
const video = player.media;
|
|
197
208
|
const onButton = event.composedPath()[0] instanceof HTMLButtonElement;
|
|
198
209
|
switch (event.key) {
|
|
199
210
|
case " ":
|
|
@@ -235,7 +246,7 @@ var MbxControlBar = class extends Component {
|
|
|
235
246
|
event.preventDefault();
|
|
236
247
|
}
|
|
237
248
|
attach(player) {
|
|
238
|
-
const video = player.
|
|
249
|
+
const video = player.media;
|
|
239
250
|
cueStyle();
|
|
240
251
|
this.cues = cueLift(video, player, () => this.covered());
|
|
241
252
|
const screen = fullscreen(player, video);
|
|
@@ -261,13 +272,24 @@ var MbxControlBar = class extends Component {
|
|
|
261
272
|
this.keyboard = false;
|
|
262
273
|
this.wake(player);
|
|
263
274
|
};
|
|
275
|
+
const press = (event) => {
|
|
276
|
+
this.touch = event.pointerType === "touch";
|
|
277
|
+
this.shownAtPress = !this.hasAttribute("idle");
|
|
278
|
+
pointer();
|
|
279
|
+
};
|
|
264
280
|
const key = (event) => {
|
|
265
281
|
this.key(player, event);
|
|
266
282
|
};
|
|
267
283
|
const click = (event) => {
|
|
268
|
-
if (event.composedPath()[0]
|
|
284
|
+
if (event.composedPath()[0] !== videoOf(player)) return;
|
|
285
|
+
if (this.touch && !this.hasAttribute("tap-plays") && !player.hasAttribute("casting")) {
|
|
286
|
+
if (this.shownAtPress) this.rest(player);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
toggle(video);
|
|
269
290
|
};
|
|
270
|
-
this.listen(player, ["pointermove"
|
|
291
|
+
this.listen(player, ["pointermove"], pointer);
|
|
292
|
+
this.listen(player, ["pointerdown"], press);
|
|
271
293
|
player.addEventListener("keydown", key);
|
|
272
294
|
player.addEventListener("click", click);
|
|
273
295
|
this.keep(() => {
|
|
@@ -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 VIDEO_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, shownPaused, 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, the subtitles and the video\n * menu. The subtitles and video menus go last of the menus because a\n * viewer may need them: the video menu holds the sign-language version.\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 [VIDEO_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 (shownPaused(player, ['switching'])) 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 // The load of a switch pauses and plays the video, and the viewer did neither.\n if (!player.hasAttribute('switching')) 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":";;;;;;AAiEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;;AAaA,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,aAAA;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,SAAA,KAAA,KAAA,QAAA,IAAA,QAAA;CACA;CACA,OAAA,SAAA,MAAA,cAAA;AACA;AAEA,SAAA,IAAA,OAAA;CACA,IAAA,OAAA,SAAA,MAAA,QAAA,GAAA,OAAA,MAAA;CACA,MAAA,SAAA,MAAA;CACA,OAAA,OAAA,SAAA,IAAA,OAAA,IAAA,OAAA,SAAA,CAAA,IAAA,MAAA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AA;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
|
+
{"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 device plays in its place, a descendant carries `open`, or\n * keyboard focus is inside it, where keyboard means the last input was a\n * 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 *\n * A tap is not a click. A finger on the picture shows the bar while it is\n * hidden and hides it while it shows, and never plays or pauses, as on a\n * phone's own players. The pointer's `pointerType` tells the two apart,\n * not the device, since a laptop can have both. `tap-plays` gives a tap\n * the click's play and pause back. During a cast the bar stays, so a tap\n * plays and pauses there too.\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 { videoOf } 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 VIDEO_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, shownPaused, 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, the subtitles and the video\n * menu. The subtitles and video menus go last of the menus because a\n * viewer may need them: the video menu holds the sign-language version.\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 [VIDEO_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 /** Whether the last press was a finger: its click on the video is a tap. */\n declare private touch: boolean;\n /** Whether the bar showed when that press began, before the press woke it. */\n declare private shownAtPress: 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.touch = false;\n this.shownAtPress = 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 (shownPaused(player, ['switching'])) return true;\n // The device's controls are these: they stay while it plays.\n if (player.hasAttribute('casting')) 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 /** Hides the bar now, as a tap asks: the next input shows it again. */\n private rest(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\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.media;\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.touch = false;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.media;\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.media;\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 press = (event: Event): void => {\n this.touch = (event as PointerEvent).pointerType === 'touch';\n this.shownAtPress = !this.hasAttribute('idle');\n pointer();\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] !== videoOf(player)) return;\n if (this.touch && !this.hasAttribute('tap-plays') && !player.hasAttribute('casting')) {\n // The press showed a hidden bar already; a tap on a shown one hides it.\n if (this.shownAtPress) this.rest(player);\n return;\n }\n toggle(video);\n };\n this.listen(player, ['pointermove'], pointer);\n this.listen(player, ['pointerdown'], press);\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 // The load of a switch pauses and plays the video, and the viewer did neither.\n if (!player.hasAttribute('switching')) 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":";;;;;;;AA0EA,MAAA,QAAA;AAGA,MAAM,UAAU;AAChB,MAAM,YAAY;;;;;;;;;;;;AAalB,MAAM,WAA6C;EAChD,cAAc;EACd,gBAAgB;CACjB,mBAAmB;EAClB,YAAY;EACZ,aAAa;EACb,gBAAgB;EAChB,aAAa;EACb,eAAe;EACf,aAAa;EACb,iBAAiB;EACjB,cAAc;EACd,iBAAiB;EACjB,aAAa;EACb,SAAS;EACT,cAAc;AACjB;;AAGA,MAAM,eAAe;;AAGrB,MAAM,QAAQ;AASd,SAAS,MAAM,MAAwB;CACrC,OAAO,KAAK,eAAe,CAAC,CAAC,SAAS;AACxC;;AAGA,SAAS,OAAO,OAAgC;CAC9C,OAAO,MAAM,cAAA,eAAuB,MAAM,cAAc,aAAa,IAAI;AAC3E;;AAGA,SAAS,SAAS,OAAwB;CACxC,MAAM,MAAM,MAAM,aAAa,UAAU;CACzC,IAAI,QAAQ,MAAM;EAChB,MAAM,QAAQ,OAAO,GAAG;EACxB,OAAO,OAAO,SAAS,KAAK,KAAK,QAAQ,IAAI,QAAQ;CACvD;CACA,OAAO,SAAS,MAAM,cAAc;AACtC;AAEA,SAAS,IAAI,OAAiC;CAC5C,IAAI,OAAO,SAAS,MAAM,QAAQ,GAAG,OAAO,MAAM;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X;CAEmB,OAAO,QAA0B;EAClD,aAAa,KAAK,KAAK;EACvB,KAAK,QAAQ,KAAA;EACb,KAAK,SAAS,WAAW;EACzB,KAAK,UAAU;EACf,KAAK,MAAM,SAAS,KAAK,QAAQ,iBAAiB,GAAG;GACnD,MAAM,gBAAgB,WAAW;GACjC,OAAO,KAAK,CAAC,EAAE,gBAAgB,WAAW;EAC5C;EACA,KAAK,MAAM,QAAQ;EACnB,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,gBAAgB,MAAM;EAC3B,OAAO,gBAAgB,MAAM;EAC7B,OAAO,gBAAgB,YAAY;CACrC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { format } from "../controls/time.js";
|
|
2
1
|
import { live, span, wall } from "../controls/session.js";
|
|
2
|
+
import { format } from "../controls/time.js";
|
|
3
3
|
import { TimeElement } from "./time-element.js";
|
|
4
4
|
// src/elements/current-time.ts
|
|
5
5
|
/**
|
|
@@ -14,7 +14,7 @@ var MbxCurrentTime = class extends TimeElement {
|
|
|
14
14
|
render() {
|
|
15
15
|
const player = this.player;
|
|
16
16
|
if (player === null) return;
|
|
17
|
-
const video = player.
|
|
17
|
+
const video = player.media;
|
|
18
18
|
const engine = player.engine;
|
|
19
19
|
const on = live(engine) !== void 0;
|
|
20
20
|
const time = video.currentTime;
|
|
@@ -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.
|
|
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.media;\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;CAC3B,SAAe;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,11 +1,11 @@
|
|
|
1
|
+
import { icon } from "../controls/icons.js";
|
|
1
2
|
import { el } from "../dom.js";
|
|
2
3
|
import { fill } from "../labels.js";
|
|
3
4
|
import { namespaces } from "../namespaces.js";
|
|
4
|
-
import { icon } from "../controls/icons.js";
|
|
5
5
|
import { Component } from "./component.js";
|
|
6
6
|
import { style } from "./shared.js";
|
|
7
7
|
// src/elements/drm-badge.ts
|
|
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)}";
|
|
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-style:var(--mbx-focus-ring,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";
|