@mattebox/player 0.5.0 → 0.7.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/README.md +9 -6
- package/dist/cdn/mattebox-player.min.js +3 -444
- package/dist/controls/airplay.js +28 -44
- package/dist/controls/airplay.js.map +1 -1
- package/dist/controls/chapters.d.ts +22 -11
- package/dist/controls/chapters.d.ts.map +1 -1
- package/dist/controls/chapters.js +87 -73
- package/dist/controls/chapters.js.map +1 -1
- package/dist/controls/cues.d.ts +0 -22
- package/dist/controls/cues.d.ts.map +1 -1
- package/dist/controls/cues.js +161 -191
- package/dist/controls/cues.js.map +1 -1
- package/dist/controls/fullscreen.js +52 -70
- package/dist/controls/fullscreen.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 +46 -70
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/menu.d.ts +7 -4
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +241 -223
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/pip.js +35 -49
- package/dist/controls/pip.js.map +1 -1
- package/dist/controls/ranges.js +42 -37
- package/dist/controls/ranges.js.map +1 -1
- package/dist/controls/session.d.ts +6 -1
- package/dist/controls/session.d.ts.map +1 -1
- package/dist/controls/session.js +41 -26
- package/dist/controls/session.js.map +1 -1
- package/dist/controls/slider.d.ts +2 -2
- package/dist/controls/slider.d.ts.map +1 -1
- package/dist/controls/slider.js +151 -159
- package/dist/controls/slider.js.map +1 -1
- package/dist/controls/time.js +17 -17
- package/dist/controls/time.js.map +1 -1
- package/dist/dom.d.ts +6 -0
- package/dist/dom.d.ts.map +1 -1
- package/dist/dom.js +28 -19
- package/dist/dom.js.map +1 -1
- package/dist/element-entry.js +9 -6
- package/dist/element-entry.js.map +1 -1
- package/dist/element.d.ts +15 -24
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +385 -454
- package/dist/element.js.map +1 -1
- package/dist/elements/airplay-button.js +51 -53
- package/dist/elements/airplay-button.js.map +1 -1
- package/dist/elements/audio-menu.js +62 -63
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/chapters-menu.d.ts.map +1 -1
- package/dist/elements/chapters-menu.js +75 -65
- package/dist/elements/chapters-menu.js.map +1 -1
- package/dist/elements/component.d.ts +1 -1
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +86 -89
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +18 -5
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +282 -319
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.js +26 -25
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.d.ts.map +1 -1
- package/dist/elements/drm-badge.js +107 -141
- package/dist/elements/drm-badge.js.map +1 -1
- package/dist/elements/duration.d.ts.map +1 -1
- package/dist/elements/duration.js +24 -21
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.d.ts.map +1 -1
- package/dist/elements/error-screen.js +68 -102
- package/dist/elements/error-screen.js.map +1 -1
- package/dist/elements/fullscreen-button.js +48 -54
- package/dist/elements/fullscreen-button.js.map +1 -1
- package/dist/elements/live-button.d.ts.map +1 -1
- package/dist/elements/live-button.js +67 -94
- package/dist/elements/live-button.js.map +1 -1
- package/dist/elements/menu-element.js +31 -28
- package/dist/elements/menu-element.js.map +1 -1
- package/dist/elements/mute-button.js +58 -59
- package/dist/elements/mute-button.js.map +1 -1
- package/dist/elements/pip-button.js +54 -54
- package/dist/elements/pip-button.js.map +1 -1
- package/dist/elements/play-button.d.ts.map +1 -1
- package/dist/elements/play-button.js +73 -58
- package/dist/elements/play-button.js.map +1 -1
- package/dist/elements/quality-menu.js +66 -69
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/remaining-time.d.ts.map +1 -1
- package/dist/elements/remaining-time.js +27 -24
- package/dist/elements/remaining-time.js.map +1 -1
- package/dist/elements/scan-button.d.ts +17 -0
- package/dist/elements/scan-button.d.ts.map +1 -0
- package/dist/elements/scan-button.js +117 -0
- package/dist/elements/scan-button.js.map +1 -0
- package/dist/elements/seek-bar.d.ts +93 -14
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +475 -335
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.d.ts +3 -11
- package/dist/elements/shared.d.ts.map +1 -1
- package/dist/elements/shared.js +44 -144
- package/dist/elements/shared.js.map +1 -1
- package/dist/elements/skip-button.d.ts.map +1 -1
- package/dist/elements/skip-button.js +54 -55
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spacer.d.ts.map +1 -1
- package/dist/elements/spacer.js +12 -7
- package/dist/elements/spacer.js.map +1 -1
- package/dist/elements/speed-menu.js +60 -55
- package/dist/elements/speed-menu.js.map +1 -1
- package/dist/elements/spinner.d.ts.map +1 -1
- package/dist/elements/spinner.js +52 -78
- package/dist/elements/spinner.js.map +1 -1
- package/dist/elements/start-button.d.ts.map +1 -1
- package/dist/elements/start-button.js +107 -120
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.js +95 -103
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/time-element.d.ts.map +1 -1
- package/dist/elements/time-element.js +36 -28
- package/dist/elements/time-element.js.map +1 -1
- package/dist/elements/title.d.ts.map +1 -1
- package/dist/elements/title.js +105 -137
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/volume-slider.d.ts.map +1 -1
- package/dist/elements/volume-slider.js +47 -45
- package/dist/elements/volume-slider.js.map +1 -1
- package/dist/elements/volume.d.ts.map +1 -1
- package/dist/elements/volume.js +42 -50
- package/dist/elements/volume.js.map +1 -1
- package/dist/entries/airplay-button.js +7 -7
- package/dist/entries/airplay-button.js.map +1 -1
- package/dist/entries/audio-menu.js +7 -6
- package/dist/entries/audio-menu.js.map +1 -1
- package/dist/entries/chapters-menu.js +7 -7
- package/dist/entries/chapters-menu.js.map +1 -1
- package/dist/entries/control-bar.js +7 -6
- package/dist/entries/control-bar.js.map +1 -1
- package/dist/entries/current-time.js +7 -6
- package/dist/entries/current-time.js.map +1 -1
- package/dist/entries/drm-badge.js +7 -6
- package/dist/entries/drm-badge.js.map +1 -1
- package/dist/entries/duration.js +7 -6
- package/dist/entries/duration.js.map +1 -1
- package/dist/entries/error-screen.js +7 -6
- package/dist/entries/error-screen.js.map +1 -1
- package/dist/entries/fullscreen-button.js +7 -6
- package/dist/entries/fullscreen-button.js.map +1 -1
- package/dist/entries/live-button.js +7 -6
- package/dist/entries/live-button.js.map +1 -1
- package/dist/entries/mute-button.js +7 -6
- package/dist/entries/mute-button.js.map +1 -1
- package/dist/entries/pip-button.js +7 -6
- package/dist/entries/pip-button.js.map +1 -1
- package/dist/entries/play-button.js +7 -6
- package/dist/entries/play-button.js.map +1 -1
- package/dist/entries/quality-menu.js +7 -6
- package/dist/entries/quality-menu.js.map +1 -1
- package/dist/entries/remaining-time.js +7 -7
- package/dist/entries/remaining-time.js.map +1 -1
- package/dist/entries/scan-button.d.ts +5 -0
- package/dist/entries/scan-button.d.ts.map +1 -0
- package/dist/entries/scan-button.js +9 -0
- package/dist/entries/scan-button.js.map +1 -0
- package/dist/entries/seek-bar.js +7 -6
- package/dist/entries/seek-bar.js.map +1 -1
- package/dist/entries/skip-button.js +7 -6
- package/dist/entries/skip-button.js.map +1 -1
- package/dist/entries/spacer.js +7 -6
- package/dist/entries/spacer.js.map +1 -1
- package/dist/entries/speed-menu.js +7 -6
- package/dist/entries/speed-menu.js.map +1 -1
- package/dist/entries/spinner.js +7 -7
- package/dist/entries/spinner.js.map +1 -1
- package/dist/entries/start-button.js +7 -6
- package/dist/entries/start-button.js.map +1 -1
- package/dist/entries/subtitles-menu.js +7 -6
- package/dist/entries/subtitles-menu.js.map +1 -1
- package/dist/entries/title.js +7 -7
- package/dist/entries/title.js.map +1 -1
- package/dist/entries/volume-slider.js +7 -6
- package/dist/entries/volume-slider.js.map +1 -1
- package/dist/entries/volume.js +9 -8
- package/dist/entries/volume.js.map +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +40 -7
- package/dist/es2015/controls/cues.js +1 -8
- package/dist/es2015/controls/icons.js +3 -1
- package/dist/es2015/controls/menu.js +28 -9
- package/dist/es2015/controls/session.js +16 -4
- package/dist/es2015/controls/slider.js +5 -4
- package/dist/es2015/dom.js +10 -1
- package/dist/es2015/element.js +49 -40
- package/dist/es2015/elements/chapters-menu.js +18 -10
- package/dist/es2015/elements/control-bar.js +41 -35
- package/dist/es2015/elements/drm-badge.js +1 -25
- package/dist/es2015/elements/duration.js +2 -1
- package/dist/es2015/elements/error-screen.js +1 -30
- package/dist/es2015/elements/live-button.js +1 -29
- package/dist/es2015/elements/menu-element.js +2 -2
- package/dist/es2015/elements/play-button.js +10 -3
- package/dist/es2015/elements/remaining-time.js +2 -1
- package/dist/es2015/elements/scan-button.js +118 -0
- package/dist/es2015/elements/seek-bar.js +264 -71
- package/dist/es2015/elements/shared.js +5 -106
- package/dist/es2015/elements/skip-button.js +2 -1
- package/dist/es2015/elements/spacer.js +2 -1
- package/dist/es2015/elements/spinner.js +1 -32
- package/dist/es2015/elements/start-button.js +8 -26
- package/dist/es2015/elements/time-element.js +1 -4
- package/dist/es2015/elements/title.js +1 -45
- package/dist/es2015/elements/volume-slider.js +2 -1
- package/dist/es2015/elements/volume.js +1 -11
- package/dist/es2015/entries/scan-button.js +7 -0
- package/dist/es2015/index.js +3 -3
- package/dist/es2015/presets.js +1 -1
- package/dist/es2015/style.js +1 -98
- package/dist/es2015/tags.js +2 -2
- package/dist/host.js +19 -17
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -28
- package/dist/labels.js +13 -9
- package/dist/labels.js.map +1 -1
- package/dist/namespaces.d.ts +9 -26
- package/dist/namespaces.d.ts.map +1 -1
- package/dist/namespaces.js +6 -2
- package/dist/namespaces.js.map +1 -1
- package/dist/presets.js +33 -28
- package/dist/presets.js.map +1 -1
- package/dist/style.d.ts +1 -20
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +4 -97
- package/dist/style.js.map +1 -1
- package/dist/surface.js +25 -21
- package/dist/surface.js.map +1 -1
- package/dist/tags.d.ts +1 -1
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +31 -27
- package/dist/tags.js.map +1 -1
- package/package.json +4 -4
- package/dist/compose.d.ts +0 -5
- package/dist/compose.d.ts.map +0 -1
- package/dist/compose.js +0 -31
- package/dist/compose.js.map +0 -1
- package/dist/elements/panels.d.ts +0 -15
- package/dist/elements/panels.d.ts.map +0 -1
- package/dist/elements/panels.js +0 -55
- package/dist/elements/panels.js.map +0 -1
- package/dist/entries/panels.d.ts +0 -5
- package/dist/entries/panels.d.ts.map +0 -1
- package/dist/entries/panels.js +0 -8
- package/dist/entries/panels.js.map +0 -1
- package/dist/es2015/compose.js +0 -33
- package/dist/es2015/elements/panels.js +0 -52
- package/dist/es2015/entries/panels.js +0 -7
- package/dist/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-element.js","
|
|
1
|
+
{"version":3,"file":"menu-element.js","names":[],"sources":["../../src/elements/menu-element.ts"],"sourcesContent":["/**\n * What the menus share: the primitive in the shadow root, the glyph slots\n * on its button, the name from `label`, the Back item's name from\n * `label-back`, and the popup fitted under the top of the picture. A\n * subclass fills the entries in `render()`, which runs on attach, on every\n * observed attribute, and whenever it asks.\n */\nimport type { IconName } from '../controls/icons.js';\nimport { icon } from '../controls/icons.js';\nimport type { Menu } from '../controls/menu.js';\nimport { menu } from '../controls/menu.js';\nimport { fill } from '../labels.js';\nimport { Component } from './component.js';\nimport { iconSlots, MENU_STYLE, style } from './shared.js';\n\nexport abstract class MenuElement<S extends string = 'default'> extends Component {\n declare protected readonly menu: Menu;\n declare protected readonly slots: Record<S, HTMLSlotElement>;\n\n constructor(states: readonly S[], glyphs: (state: S) => SVGSVGElement) {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.menu = menu({\n host: this,\n picture: () => this.player?.video.getBoundingClientRect() ?? null,\n back: (page) => fill(this.getAttribute('label-back') ?? 'Back from {page}', { page }),\n });\n this.slots = iconSlots(states, glyphs);\n for (const state of states) this.menu.button.append(this.slots[state]);\n root.append(style(MENU_STYLE), this.menu.button, this.menu.popup);\n }\n\n /** The default name of the button. */\n protected abstract name(): string;\n\n protected override detach(): void {\n this.menu.close();\n }\n\n protected override render(): void {\n this.menu.label(this.getAttribute('label') ?? this.name());\n }\n}\n\n/** A glyph that never changes, for a menu of one state. */\nexport function single(name: IconName): [readonly ['default'], () => SVGSVGElement] {\n return [['default'], () => icon(name)];\n}\n"],"mappings":";;;;;;AAeA,IAAsB,cAAtB,cAAwE,UAAU;CAIhF,YAAY,QAAsB,QAAqC;EACrE,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,OAAO,KAAK;GACf,MAAM;GACN,eAAe,KAAK,QAAQ,MAAM,sBAAsB,KAAK;GAC7D,OAAO,SAAS,KAAK,KAAK,aAAa,YAAY,KAAK,oBAAoB,EAAE,KAAK,CAAC;EACtF,CAAC;EACD,KAAK,QAAQ,UAAU,QAAQ,MAAM;EACrC,KAAK,MAAM,SAAS,QAAQ,KAAK,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EACrE,KAAK,OAAO,MAAM,UAAU,GAAG,KAAK,KAAK,QAAQ,KAAK,KAAK,KAAK;CAClE;CAKA,SAAkC;EAChC,KAAK,KAAK,MAAM;CAClB;CAEA,SAAkC;EAChC,KAAK,KAAK,MAAM,KAAK,aAAa,OAAO,KAAK,KAAK,KAAK,CAAC;CAC3D;AACF;;AAGA,SAAgB,OAAO,MAA6D;CAClF,OAAO,CAAC,CAAC,SAAS,SAAS,KAAK,IAAI,CAAC;AACvC"}
|
|
@@ -1,61 +1,60 @@
|
|
|
1
|
+
import { icon } from "../controls/icons.js";
|
|
2
|
+
import { Component } from "./component.js";
|
|
3
|
+
import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
|
|
4
|
+
//#region src/elements/mute-button.ts
|
|
1
5
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
? (this.getAttribute('label-unmute') ?? 'Unmute')
|
|
57
|
-
: (this.getAttribute('label-mute') ?? 'Mute'));
|
|
58
|
-
this.button.setAttribute('aria-pressed', String(video.muted));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
6
|
+
* <mbx-mute-button>: mute and unmute, with the level drawn in the glyph:
|
|
7
|
+
* `icon-mute` while muted or at zero, `icon-low` up to half, `icon-high`
|
|
8
|
+
* above. Unmuting at zero volume would change nothing the viewer can
|
|
9
|
+
* hear, so it brings the volume up too. The name comes from `label-mute`
|
|
10
|
+
* and `label-unmute`, and `aria-pressed` says which state it is in.
|
|
11
|
+
*/
|
|
12
|
+
const LEVELS = [
|
|
13
|
+
"mute",
|
|
14
|
+
"low",
|
|
15
|
+
"high"
|
|
16
|
+
];
|
|
17
|
+
var MbxMuteButton = class extends Component {
|
|
18
|
+
static get observedAttributes() {
|
|
19
|
+
return ["label-mute", "label-unmute"];
|
|
20
|
+
}
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
const root = this.attachShadow({ mode: "open" });
|
|
24
|
+
this.button = document.createElement("button");
|
|
25
|
+
this.button.type = "button";
|
|
26
|
+
this.button.setAttribute("part", "button");
|
|
27
|
+
this.slots = iconSlots(LEVELS, (level) => icon(level === "mute" ? "mute" : level === "low" ? "volume-low" : "volume-high"));
|
|
28
|
+
for (const level of LEVELS) this.button.append(this.slots[level]);
|
|
29
|
+
this.button.addEventListener("click", () => {
|
|
30
|
+
this.toggle();
|
|
31
|
+
});
|
|
32
|
+
root.append(style(BUTTON_STYLE), this.button);
|
|
33
|
+
}
|
|
34
|
+
toggle() {
|
|
35
|
+
const video = this.player?.video;
|
|
36
|
+
if (video === void 0) return;
|
|
37
|
+
if (video.muted) {
|
|
38
|
+
video.muted = false;
|
|
39
|
+
if (video.volume === 0) video.volume = 1;
|
|
40
|
+
} else video.muted = true;
|
|
41
|
+
}
|
|
42
|
+
attach(player) {
|
|
43
|
+
this.listen(player.video, ["volumechange", "emptied"], () => {
|
|
44
|
+
this.render();
|
|
45
|
+
});
|
|
46
|
+
this.render();
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
const video = this.player?.video;
|
|
50
|
+
if (video === void 0) return;
|
|
51
|
+
const silent = video.muted || video.volume === 0;
|
|
52
|
+
show(this.slots, silent ? "mute" : video.volume <= .5 ? "low" : "high");
|
|
53
|
+
this.button.setAttribute("aria-label", silent ? this.getAttribute("label-unmute") ?? "Unmute" : this.getAttribute("label-mute") ?? "Mute");
|
|
54
|
+
this.button.setAttribute("aria-pressed", String(video.muted));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { MbxMuteButton };
|
|
59
|
+
|
|
61
60
|
//# sourceMappingURL=mute-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mute-button.js","
|
|
1
|
+
{"version":3,"file":"mute-button.js","names":[],"sources":["../../src/elements/mute-button.ts"],"sourcesContent":["/**\n * <mbx-mute-button>: mute and unmute, with the level drawn in the glyph:\n * `icon-mute` while muted or at zero, `icon-low` up to half, `icon-high`\n * above. Unmuting at zero volume would change nothing the viewer can\n * hear, so it brings the volume up too. The name comes from `label-mute`\n * and `label-unmute`, and `aria-pressed` says which state it is in.\n */\nimport { icon } from '../controls/icons.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { BUTTON_STYLE, iconSlots, show, style } from './shared.js';\n\ntype Level = 'mute' | 'low' | 'high';\nconst LEVELS: readonly Level[] = ['mute', 'low', 'high'];\n\nexport class MbxMuteButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-mute', 'label-unmute'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<Level, HTMLSlotElement>;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.slots = iconSlots(LEVELS, (level) =>\n icon(level === 'mute' ? 'mute' : level === 'low' ? 'volume-low' : 'volume-high'),\n );\n for (const level of LEVELS) this.button.append(this.slots[level]);\n this.button.addEventListener('click', () => {\n this.toggle();\n });\n root.append(style(BUTTON_STYLE), this.button);\n }\n\n private toggle(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n if (video.muted) {\n video.muted = false;\n if (video.volume === 0) video.volume = 1;\n } else {\n video.muted = true;\n }\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player.video, ['volumechange', 'emptied'], () => {\n this.render();\n });\n this.render();\n }\n\n protected override render(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n const silent = video.muted || video.volume === 0;\n show(this.slots, silent ? 'mute' : video.volume <= 0.5 ? 'low' : 'high');\n this.button.setAttribute(\n 'aria-label',\n silent\n ? (this.getAttribute('label-unmute') ?? 'Unmute')\n : (this.getAttribute('label-mute') ?? 'Mute'),\n );\n this.button.setAttribute('aria-pressed', String(video.muted));\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,SAA2B;CAAC;CAAQ;CAAO;AAAM;AAEvD,IAAa,gBAAb,cAAmC,UAAU;CAC3C,WAAW,qBAAwC;EACjD,OAAO,CAAC,cAAc,cAAc;CACtC;CAKA,cAAc;EACZ,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,SAAS,cAAc,QAAQ;EAC7C,KAAK,OAAO,OAAO;EACnB,KAAK,OAAO,aAAa,QAAQ,QAAQ;EACzC,KAAK,QAAQ,UAAU,SAAS,UAC9B,KAAK,UAAU,SAAS,SAAS,UAAU,QAAQ,eAAe,aAAa,CACjF;EACA,KAAK,MAAM,SAAS,QAAQ,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EAChE,KAAK,OAAO,iBAAiB,eAAe;GAC1C,KAAK,OAAO;EACd,CAAC;EACD,KAAK,OAAO,MAAM,YAAY,GAAG,KAAK,MAAM;CAC9C;CAEA,SAAuB;EACrB,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,IAAI,MAAM,OAAO;GACf,MAAM,QAAQ;GACd,IAAI,MAAM,WAAW,GAAG,MAAM,SAAS;EACzC,OACE,MAAM,QAAQ;CAElB;CAEA,OAA0B,QAA0B;EAClD,KAAK,OAAO,OAAO,OAAO,CAAC,gBAAgB,SAAS,SAAS;GAC3D,KAAK,OAAO;EACd,CAAC;EACD,KAAK,OAAO;CACd;CAEA,SAAkC;EAChC,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,SAAS,MAAM,SAAS,MAAM,WAAW;EAC/C,KAAK,KAAK,OAAO,SAAS,SAAS,MAAM,UAAU,KAAM,QAAQ,MAAM;EACvE,KAAK,OAAO,aACV,cACA,SACK,KAAK,aAAa,cAAc,KAAK,WACrC,KAAK,aAAa,YAAY,KAAK,MAC1C;EACA,KAAK,OAAO,aAAa,gBAAgB,OAAO,MAAM,KAAK,CAAC;CAC9D;AACF"}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
+
import { icon } from "../controls/icons.js";
|
|
2
|
+
import { Component } from "./component.js";
|
|
3
|
+
import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
|
|
4
|
+
import { pictureInPicture } from "../controls/pip.js";
|
|
5
|
+
//#region src/elements/pip-button.ts
|
|
1
6
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
? (this.getAttribute('label-exit') ?? 'Leave picture in picture')
|
|
52
|
-
: (this.getAttribute('label-enter') ?? 'Picture in picture'));
|
|
53
|
-
player.toggleAttribute('pip', active);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
7
|
+
* <mbx-pip-button>: picture in picture, through whichever API the browser
|
|
8
|
+
* has, and hidden where there is none. The glyph is `icon-enter` or
|
|
9
|
+
* `icon-exit`, the name `label-enter` or `label-exit`, and the element
|
|
10
|
+
* sets `pip` on the player while the video is in the floating window.
|
|
11
|
+
*/
|
|
12
|
+
const STATES = ["enter", "exit"];
|
|
13
|
+
var MbxPipButton = class extends Component {
|
|
14
|
+
static get observedAttributes() {
|
|
15
|
+
return ["label-enter", "label-exit"];
|
|
16
|
+
}
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.api = null;
|
|
20
|
+
const root = this.attachShadow({ mode: "open" });
|
|
21
|
+
this.button = document.createElement("button");
|
|
22
|
+
this.button.type = "button";
|
|
23
|
+
this.button.setAttribute("part", "button");
|
|
24
|
+
this.slots = iconSlots(STATES, (state) => icon(state === "enter" ? "picture-in-picture" : "picture-in-picture-exit"));
|
|
25
|
+
for (const state of STATES) this.button.append(this.slots[state]);
|
|
26
|
+
this.button.addEventListener("click", () => {
|
|
27
|
+
this.api?.toggle();
|
|
28
|
+
});
|
|
29
|
+
root.append(style(BUTTON_STYLE), this.button);
|
|
30
|
+
}
|
|
31
|
+
attach(player) {
|
|
32
|
+
const api = pictureInPicture(player.video);
|
|
33
|
+
this.api = api;
|
|
34
|
+
this.hidden = !api.supported;
|
|
35
|
+
this.keep(api.watch(() => {
|
|
36
|
+
this.render();
|
|
37
|
+
}));
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
detach(player) {
|
|
41
|
+
this.api = null;
|
|
42
|
+
player.removeAttribute("pip");
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
const player = this.player;
|
|
46
|
+
if (player === null || this.api === null) return;
|
|
47
|
+
const active = this.api.active();
|
|
48
|
+
show(this.slots, active ? "exit" : "enter");
|
|
49
|
+
this.button.setAttribute("aria-label", active ? this.getAttribute("label-exit") ?? "Leave picture in picture" : this.getAttribute("label-enter") ?? "Picture in picture");
|
|
50
|
+
player.toggleAttribute("pip", active);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { MbxPipButton };
|
|
55
|
+
|
|
56
56
|
//# sourceMappingURL=pip-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pip-button.js","
|
|
1
|
+
{"version":3,"file":"pip-button.js","names":[],"sources":["../../src/elements/pip-button.ts"],"sourcesContent":["/**\n * <mbx-pip-button>: picture in picture, through whichever API the browser\n * has, and hidden where there is none. The glyph is `icon-enter` or\n * `icon-exit`, the name `label-enter` or `label-exit`, and the element\n * sets `pip` on the player while the video is in the floating window.\n */\nimport { icon } from '../controls/icons.js';\nimport type { PictureInPicture } from '../controls/pip.js';\nimport { pictureInPicture } from '../controls/pip.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { BUTTON_STYLE, iconSlots, show, style } from './shared.js';\n\ntype State = 'enter' | 'exit';\nconst STATES: readonly State[] = ['enter', 'exit'];\n\nexport class MbxPipButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-enter', 'label-exit'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n declare private api: PictureInPicture | null;\n\n constructor() {\n super();\n this.api = null;\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.slots = iconSlots(STATES, (state) =>\n icon(state === 'enter' ? 'picture-in-picture' : 'picture-in-picture-exit'),\n );\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.api?.toggle();\n });\n root.append(style(BUTTON_STYLE), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n const api = pictureInPicture(player.video);\n this.api = api;\n this.hidden = !api.supported;\n this.keep(\n api.watch(() => {\n this.render();\n }),\n );\n this.render();\n }\n\n protected override detach(player: PlayerHost): void {\n this.api = null;\n player.removeAttribute('pip');\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null || this.api === null) return;\n const active = this.api.active();\n show(this.slots, active ? 'exit' : 'enter');\n this.button.setAttribute(\n 'aria-label',\n active\n ? (this.getAttribute('label-exit') ?? 'Leave picture in picture')\n : (this.getAttribute('label-enter') ?? 'Picture in picture'),\n );\n player.toggleAttribute('pip', active);\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,SAA2B,CAAC,SAAS,MAAM;AAEjD,IAAa,eAAb,cAAkC,UAAU;CAC1C,WAAW,qBAAwC;EACjD,OAAO,CAAC,eAAe,YAAY;CACrC;CAMA,cAAc;EACZ,MAAM;EACN,KAAK,MAAM;EACX,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,SAAS,cAAc,QAAQ;EAC7C,KAAK,OAAO,OAAO;EACnB,KAAK,OAAO,aAAa,QAAQ,QAAQ;EACzC,KAAK,QAAQ,UAAU,SAAS,UAC9B,KAAK,UAAU,UAAU,uBAAuB,yBAAyB,CAC3E;EACA,KAAK,MAAM,SAAS,QAAQ,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EAChE,KAAK,OAAO,iBAAiB,eAAe;GAC1C,KAAK,KAAK,OAAO;EACnB,CAAC;EACD,KAAK,OAAO,MAAM,YAAY,GAAG,KAAK,MAAM;CAC9C;CAEA,OAA0B,QAA0B;EAClD,MAAM,MAAM,iBAAiB,OAAO,KAAK;EACzC,KAAK,MAAM;EACX,KAAK,SAAS,CAAC,IAAI;EACnB,KAAK,KACH,IAAI,YAAY;GACd,KAAK,OAAO;EACd,CAAC,CACH;EACA,KAAK,OAAO;CACd;CAEA,OAA0B,QAA0B;EAClD,KAAK,MAAM;EACX,OAAO,gBAAgB,KAAK;CAC9B;CAEA,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,QAAQ,KAAK,QAAQ,MAAM;EAC1C,MAAM,SAAS,KAAK,IAAI,OAAO;EAC/B,KAAK,KAAK,OAAO,SAAS,SAAS,OAAO;EAC1C,KAAK,OAAO,aACV,cACA,SACK,KAAK,aAAa,YAAY,KAAK,6BACnC,KAAK,aAAa,aAAa,KAAK,oBAC3C;EACA,OAAO,gBAAgB,OAAO,MAAM;CACtC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"play-button.d.ts","sourceRoot":"","sources":["../../src/elements/play-button.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"play-button.d.ts","sourceRoot":"","sources":["../../src/elements/play-button.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;;IAgB/D,OAAO,CAAC,MAAM;cAYK,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAUhC,MAAM,IAAI,IAAI;CASlC"}
|
|
@@ -1,60 +1,75 @@
|
|
|
1
|
+
import { icon } from "../controls/icons.js";
|
|
2
|
+
import { Component } from "./component.js";
|
|
3
|
+
import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
|
|
4
|
+
//#region src/elements/play-button.ts
|
|
1
5
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
6
|
+
* <mbx-play-button>: play, pause, or replay once the media has ended. It
|
|
7
|
+
* reads the video on the events the video already fires and writes one
|
|
8
|
+
* thing back on click. The glyph is a slot per state, so a page drops its
|
|
9
|
+
* own SVG into `icon-play`, `icon-pause` or `icon-replay`; the name is on
|
|
10
|
+
* the button, from `label-play`, `label-pause` and `label-replay`, where a
|
|
11
|
+
* screen reader reads it. While the seek bar holds the video paused for a
|
|
12
|
+
* drag, the button shows the state from before the drag, which the player
|
|
13
|
+
* carries as `scrubbing`.
|
|
14
|
+
*/
|
|
15
|
+
const STATES = [
|
|
16
|
+
"play",
|
|
17
|
+
"pause",
|
|
18
|
+
"replay"
|
|
19
|
+
];
|
|
20
|
+
const LABELS = {
|
|
21
|
+
play: "Play",
|
|
22
|
+
pause: "Pause",
|
|
23
|
+
replay: "Replay"
|
|
24
|
+
};
|
|
25
|
+
var MbxPlayButton = class extends Component {
|
|
26
|
+
static get observedAttributes() {
|
|
27
|
+
return STATES.map((state) => `label-${state}`);
|
|
28
|
+
}
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
const root = this.attachShadow({ mode: "open" });
|
|
32
|
+
this.button = document.createElement("button");
|
|
33
|
+
this.button.type = "button";
|
|
34
|
+
this.button.setAttribute("part", "button");
|
|
35
|
+
this.slots = iconSlots(STATES, icon);
|
|
36
|
+
for (const state of STATES) this.button.append(this.slots[state]);
|
|
37
|
+
this.button.addEventListener("click", () => {
|
|
38
|
+
this.toggle();
|
|
39
|
+
});
|
|
40
|
+
root.append(style(BUTTON_STYLE), this.button);
|
|
41
|
+
}
|
|
42
|
+
toggle() {
|
|
43
|
+
const video = this.player?.video;
|
|
44
|
+
if (video === void 0) return;
|
|
45
|
+
if (video.paused) video.play().catch(() => void 0);
|
|
46
|
+
else video.pause();
|
|
47
|
+
}
|
|
48
|
+
attach(player) {
|
|
49
|
+
this.listen(player.video, [
|
|
50
|
+
"play",
|
|
51
|
+
"pause",
|
|
52
|
+
"ended",
|
|
53
|
+
"emptied"
|
|
54
|
+
], () => {
|
|
55
|
+
this.render();
|
|
56
|
+
});
|
|
57
|
+
this.observe(player, ["scrubbing"], () => {
|
|
58
|
+
this.render();
|
|
59
|
+
});
|
|
60
|
+
this.render();
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
const video = this.player?.video;
|
|
64
|
+
if (video === void 0) return;
|
|
65
|
+
const held = this.player?.getAttribute("scrubbing") ?? null;
|
|
66
|
+
const paused = held === null ? video.paused : held === "paused";
|
|
67
|
+
const state = video.ended ? "replay" : paused ? "play" : "pause";
|
|
68
|
+
show(this.slots, state);
|
|
69
|
+
this.button.setAttribute("aria-label", this.getAttribute(`label-${state}`) ?? LABELS[state]);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
export { MbxPlayButton };
|
|
74
|
+
|
|
60
75
|
//# sourceMappingURL=play-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"play-button.js","
|
|
1
|
+
{"version":3,"file":"play-button.js","names":[],"sources":["../../src/elements/play-button.ts"],"sourcesContent":["/**\n * <mbx-play-button>: play, pause, or replay once the media has ended. It\n * reads the video on the events the video already fires and writes one\n * thing back on click. The glyph is a slot per state, so a page drops its\n * own SVG into `icon-play`, `icon-pause` or `icon-replay`; the name is on\n * the button, from `label-play`, `label-pause` and `label-replay`, where a\n * screen reader reads it. While the seek bar holds the video paused for a\n * drag, the button shows the state from before the drag, which the player\n * carries as `scrubbing`.\n */\nimport { icon } from '../controls/icons.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { BUTTON_STYLE, iconSlots, show, style } from './shared.js';\n\ntype State = 'play' | 'pause' | 'replay';\nconst STATES: readonly State[] = ['play', 'pause', 'replay'];\nconst LABELS: Readonly<Record<State, string>> = { play: 'Play', pause: 'Pause', replay: 'Replay' };\n\nexport class MbxPlayButton extends Component {\n static get observedAttributes(): readonly string[] {\n return STATES.map((state) => `label-${state}`);\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.slots = iconSlots(STATES, icon);\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.toggle();\n });\n root.append(style(BUTTON_STYLE), this.button);\n }\n\n private toggle(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n if (video.paused) {\n // Rejected outside a user gesture on an unmuted video, which the\n // browser reports on the video's own error path; nothing to add.\n video.play().catch(() => undefined);\n } else {\n video.pause();\n }\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player.video, ['play', 'pause', 'ended', 'emptied'], () => {\n this.render();\n });\n this.observe(player, ['scrubbing'], () => {\n this.render();\n });\n this.render();\n }\n\n protected override render(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n const held = this.player?.getAttribute('scrubbing') ?? null;\n const paused = held === null ? video.paused : held === 'paused';\n const state: State = video.ended ? 'replay' : paused ? 'play' : 'pause';\n show(this.slots, state);\n this.button.setAttribute('aria-label', this.getAttribute(`label-${state}`) ?? LABELS[state]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,SAA2B;CAAC;CAAQ;CAAS;AAAQ;AAC3D,MAAM,SAA0C;CAAE,MAAM;CAAQ,OAAO;CAAS,QAAQ;AAAS;AAEjG,IAAa,gBAAb,cAAmC,UAAU;CAC3C,WAAW,qBAAwC;EACjD,OAAO,OAAO,KAAK,UAAU,SAAS,OAAO;CAC/C;CAKA,cAAc;EACZ,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,SAAS,cAAc,QAAQ;EAC7C,KAAK,OAAO,OAAO;EACnB,KAAK,OAAO,aAAa,QAAQ,QAAQ;EACzC,KAAK,QAAQ,UAAU,QAAQ,IAAI;EACnC,KAAK,MAAM,SAAS,QAAQ,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EAChE,KAAK,OAAO,iBAAiB,eAAe;GAC1C,KAAK,OAAO;EACd,CAAC;EACD,KAAK,OAAO,MAAM,YAAY,GAAG,KAAK,MAAM;CAC9C;CAEA,SAAuB;EACrB,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,IAAI,MAAM,QAGR,MAAM,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;OAElC,MAAM,MAAM;CAEhB;CAEA,OAA0B,QAA0B;EAClD,KAAK,OAAO,OAAO,OAAO;GAAC;GAAQ;GAAS;GAAS;EAAS,SAAS;GACrE,KAAK,OAAO;EACd,CAAC;EACD,KAAK,QAAQ,QAAQ,CAAC,WAAW,SAAS;GACxC,KAAK,OAAO;EACd,CAAC;EACD,KAAK,OAAO;CACd;CAEA,SAAkC;EAChC,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,OAAO,KAAK,QAAQ,aAAa,WAAW,KAAK;EACvD,MAAM,SAAS,SAAS,OAAO,MAAM,SAAS,SAAS;EACvD,MAAM,QAAe,MAAM,QAAQ,WAAW,SAAS,SAAS;EAChE,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,OAAO,aAAa,cAAc,KAAK,aAAa,SAAS,OAAO,KAAK,OAAO,MAAM;CAC7F;AACF"}
|
|
@@ -1,72 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { show } from "./shared.js";
|
|
2
|
+
import { MenuElement, single } from "./menu-element.js";
|
|
3
|
+
//#region src/elements/quality-menu.ts
|
|
4
|
+
const AUTO = "auto";
|
|
4
5
|
function renditionLabel(rendition) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return `${Math.round(rendition.bitrate / 1000)} kbps`;
|
|
8
|
-
}
|
|
9
|
-
export class MbxQualityMenu extends MenuElement {
|
|
10
|
-
static get observedAttributes() {
|
|
11
|
-
return ['label', 'label-auto', 'label-back'];
|
|
12
|
-
}
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...single('settings'));
|
|
15
|
-
this.engine = null;
|
|
16
|
-
show(this.slots, 'default');
|
|
17
|
-
}
|
|
18
|
-
name() {
|
|
19
|
-
return 'Quality';
|
|
20
|
-
}
|
|
21
|
-
attach(player) {
|
|
22
|
-
this.follow(player, (engine) => {
|
|
23
|
-
this.engine = engine;
|
|
24
|
-
this.render();
|
|
25
|
-
if (engine === null)
|
|
26
|
-
return undefined;
|
|
27
|
-
const tick = () => {
|
|
28
|
-
this.render();
|
|
29
|
-
};
|
|
30
|
-
const offs = [
|
|
31
|
-
engine.on('tracks:changed', tick),
|
|
32
|
-
engine.on('quality:constraints-unsatisfiable', tick),
|
|
33
|
-
engine.on('quality:pin-unsatisfiable', tick),
|
|
34
|
-
];
|
|
35
|
-
return () => {
|
|
36
|
-
for (const off of offs)
|
|
37
|
-
off();
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
render() {
|
|
42
|
-
super.render();
|
|
43
|
-
const engine = this.engine;
|
|
44
|
-
if (engine === null) {
|
|
45
|
-
this.hidden = true;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const quality = engine.quality;
|
|
49
|
-
const items = [
|
|
50
|
-
[AUTO, this.getAttribute('label-auto') ?? 'Auto'],
|
|
51
|
-
];
|
|
52
|
-
for (const rendition of quality.renditions) {
|
|
53
|
-
items.push([rendition.id, renditionLabel(rendition)]);
|
|
54
|
-
}
|
|
55
|
-
this.menu.fill([
|
|
56
|
-
{
|
|
57
|
-
name: 'rendition',
|
|
58
|
-
items,
|
|
59
|
-
value: quality.pinned ?? AUTO,
|
|
60
|
-
onSelect: (value) => {
|
|
61
|
-
if (value === AUTO)
|
|
62
|
-
quality.auto();
|
|
63
|
-
else
|
|
64
|
-
quality.pin(value);
|
|
65
|
-
this.render();
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
]);
|
|
69
|
-
this.hidden = quality.renditions.length === 0;
|
|
70
|
-
}
|
|
6
|
+
if (rendition.height !== void 0) return `${rendition.height}p`;
|
|
7
|
+
return `${Math.round(rendition.bitrate / 1e3)} kbps`;
|
|
71
8
|
}
|
|
9
|
+
var MbxQualityMenu = class extends MenuElement {
|
|
10
|
+
static get observedAttributes() {
|
|
11
|
+
return [
|
|
12
|
+
"label",
|
|
13
|
+
"label-auto",
|
|
14
|
+
"label-back"
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...single("settings"));
|
|
19
|
+
this.engine = null;
|
|
20
|
+
show(this.slots, "default");
|
|
21
|
+
}
|
|
22
|
+
name() {
|
|
23
|
+
return "Quality";
|
|
24
|
+
}
|
|
25
|
+
attach(player) {
|
|
26
|
+
this.follow(player, (engine) => {
|
|
27
|
+
this.engine = engine;
|
|
28
|
+
this.render();
|
|
29
|
+
if (engine === null) return void 0;
|
|
30
|
+
const tick = () => {
|
|
31
|
+
this.render();
|
|
32
|
+
};
|
|
33
|
+
const offs = [
|
|
34
|
+
engine.on("tracks:changed", tick),
|
|
35
|
+
engine.on("quality:constraints-unsatisfiable", tick),
|
|
36
|
+
engine.on("quality:pin-unsatisfiable", tick)
|
|
37
|
+
];
|
|
38
|
+
return () => {
|
|
39
|
+
for (const off of offs) off();
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
render() {
|
|
44
|
+
super.render();
|
|
45
|
+
const engine = this.engine;
|
|
46
|
+
if (engine === null) {
|
|
47
|
+
this.hidden = true;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const quality = engine.quality;
|
|
51
|
+
const items = [[AUTO, this.getAttribute("label-auto") ?? "Auto"]];
|
|
52
|
+
for (const rendition of quality.renditions) items.push([rendition.id, renditionLabel(rendition)]);
|
|
53
|
+
this.menu.fill([{
|
|
54
|
+
name: "rendition",
|
|
55
|
+
items,
|
|
56
|
+
value: quality.pinned ?? AUTO,
|
|
57
|
+
onSelect: (value) => {
|
|
58
|
+
if (value === AUTO) quality.auto();
|
|
59
|
+
else quality.pin(value);
|
|
60
|
+
this.render();
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
this.hidden = quality.renditions.length === 0;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { MbxQualityMenu };
|
|
68
|
+
|
|
72
69
|
//# sourceMappingURL=quality-menu.js.map
|