@mattebox/player 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/mattebox-player.min.js +3 -3
- package/dist/controls/cues.d.ts.map +1 -1
- package/dist/controls/cues.js +11 -5
- package/dist/controls/cues.js.map +1 -1
- package/dist/controls/icons.d.ts +5 -30
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +38 -29
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/menu.d.ts +20 -0
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +83 -14
- package/dist/controls/menu.js.map +1 -1
- package/dist/element.d.ts +36 -2
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +140 -24
- package/dist/element.js.map +1 -1
- package/dist/elements/audio-menu.d.ts.map +1 -1
- package/dist/elements/audio-menu.js +3 -1
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +10 -0
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +2 -0
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +23 -7
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.d.ts.map +1 -1
- package/dist/elements/current-time.js +1 -1
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.js +1 -1
- package/dist/elements/duration.d.ts.map +1 -1
- package/dist/elements/duration.js +6 -2
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.js +1 -1
- package/dist/elements/live-button.js +1 -1
- package/dist/elements/marker-button.d.ts +3 -3
- package/dist/elements/marker-button.d.ts.map +1 -1
- package/dist/elements/marker-button.js +18 -22
- package/dist/elements/marker-button.js.map +1 -1
- package/dist/elements/menu-element.d.ts.map +1 -1
- package/dist/elements/menu-element.js +2 -1
- package/dist/elements/menu-element.js.map +1 -1
- package/dist/elements/quality-menu.js +1 -1
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/scan-button.js +1 -1
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +5 -4
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.js +3 -3
- package/dist/elements/skip-button.js +2 -2
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spinner.js +1 -1
- package/dist/elements/start-button.d.ts +8 -0
- package/dist/elements/start-button.d.ts.map +1 -1
- package/dist/elements/start-button.js +18 -2
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.d.ts +5 -1
- package/dist/elements/subtitles-menu.d.ts.map +1 -1
- package/dist/elements/subtitles-menu.js +29 -11
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/title.d.ts.map +1 -1
- package/dist/elements/title.js +3 -1
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/volume-slider.js +1 -1
- package/dist/elements/volume.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +1 -1
- package/dist/es2015/controls/cues.js +11 -5
- package/dist/es2015/controls/icons.js +38 -29
- package/dist/es2015/controls/menu.js +89 -17
- package/dist/es2015/element.js +144 -30
- package/dist/es2015/elements/audio-menu.js +4 -1
- package/dist/es2015/elements/component.js +10 -0
- package/dist/es2015/elements/control-bar.js +23 -7
- package/dist/es2015/elements/current-time.js +1 -1
- package/dist/es2015/elements/drm-badge.js +1 -1
- package/dist/es2015/elements/duration.js +6 -2
- package/dist/es2015/elements/error-screen.js +1 -1
- package/dist/es2015/elements/live-button.js +1 -1
- package/dist/es2015/elements/marker-button.js +19 -23
- package/dist/es2015/elements/menu-element.js +2 -1
- package/dist/es2015/elements/quality-menu.js +1 -1
- package/dist/es2015/elements/scan-button.js +1 -1
- package/dist/es2015/elements/seek-bar.js +5 -4
- package/dist/es2015/elements/shared.js +3 -3
- package/dist/es2015/elements/skip-button.js +2 -2
- package/dist/es2015/elements/spinner.js +1 -1
- package/dist/es2015/elements/start-button.js +18 -2
- package/dist/es2015/elements/subtitles-menu.js +35 -17
- package/dist/es2015/elements/title.js +3 -1
- package/dist/es2015/elements/volume-slider.js +1 -1
- package/dist/es2015/elements/volume.js +1 -1
- package/dist/es2015/presets.js +1 -1
- package/dist/es2015/style.js +1 -1
- package/dist/style.js +1 -1
- package/package.json +4 -5
- package/NOTICE +0 -24
|
@@ -12,6 +12,14 @@ export declare class MbxStartButton extends Component {
|
|
|
12
12
|
protected attach(player: PlayerHost): void;
|
|
13
13
|
protected detach(): void;
|
|
14
14
|
/**
|
|
15
|
+
* The button sits between two middles: the player's own, and the middle
|
|
16
|
+
* of the picture left over the bar's controls. With the bar at the foot,
|
|
17
|
+
* the player's middle reads as too low. The bar is light, a line and a
|
|
18
|
+
* few glyphs over a gradient, so the middle of what it leaves reads as
|
|
19
|
+
* too high, most of all in a short player. Halfway between them is where
|
|
20
|
+
* the eye puts the centre. The bar's top padding is the lead-in of its
|
|
21
|
+
* gradient, so the controls start under it.
|
|
22
|
+
*
|
|
15
23
|
* Cramped when the button's foot would be inside the bar's box, which
|
|
16
24
|
* starts at the top of its gradient: then the bar's own play button is
|
|
17
25
|
* the one to press. Measured with the button shown, since a hidden one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-button.d.ts","sourceRoot":"","sources":["../../src/elements/start-button.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,qBAAa,cAAe,SAAQ,SAAS;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,8FAA8F;IAC9F,QAAgB,MAAM,CAAU;IAChC,kFAAkF;IAClF,QAAgB,OAAO,CAAwB;;cAkB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"start-button.d.ts","sourceRoot":"","sources":["../../src/elements/start-button.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,qBAAa,cAAe,SAAQ,SAAS;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,8FAA8F;IAC9F,QAAgB,MAAM,CAAU;IAChC,kFAAkF;IAClF,QAAgB,OAAO,CAAwB;;cAkB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAwChC,MAAM,IAAI,IAAI;IAOjC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,GAAG;cAqBQ,MAAM,IAAI,IAAI;CAiBlC"}
|
|
@@ -2,7 +2,7 @@ import { icon } from "../controls/icons.js";
|
|
|
2
2
|
import { Component } from "./component.js";
|
|
3
3
|
import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
|
|
4
4
|
//#region src/elements/start-button.ts
|
|
5
|
-
const STYLE_CSS = ":host{margin:-
|
|
5
|
+
const STYLE_CSS = ":host{--mbx-tooltip:none;top:var(--mbx-start-top,50%);margin:-2.5em 0 0 -2.5em;position:absolute;left:50%}[part~=button]{z-index:0;width:5em;height:5em;color:var(--mbx-text);background:0 0;border:0;transition:color .15s;position:relative}[part~=button]:before{content:\"\";z-index:-1;background:var(--mbx-surface);opacity:.88;clip-path:polygon(0 0,79% 0,100% 21%,100% 100%,21% 100%,0 79%);transition:opacity .15s,background .15s;position:absolute;top:0;bottom:0;left:0;right:0}[part~=button]:hover{color:var(--mbx-surface)}[part~=button]:hover:before{background:var(--mbx-accent);opacity:1}:host([cramped]){display:none}[part~=icon],::slotted(*){width:3em;height:3em}slot[name=icon-play]>[part~=icon]{margin-left:.125em}@media (prefers-reduced-motion:reduce){[part~=button],[part~=button]:before{transition:none}}";
|
|
6
6
|
const STATES = ["play", "replay"];
|
|
7
7
|
const STYLE = BUTTON_STYLE + STYLE_CSS;
|
|
8
8
|
var MbxStartButton = class extends Component {
|
|
@@ -62,6 +62,8 @@ var MbxStartButton = class extends Component {
|
|
|
62
62
|
this.fit(player);
|
|
63
63
|
});
|
|
64
64
|
this.resizer.observe(player);
|
|
65
|
+
const bar = player.querySelector("mbx-control-bar");
|
|
66
|
+
if (bar !== null) this.resizer.observe(bar);
|
|
65
67
|
}
|
|
66
68
|
this.fit(player);
|
|
67
69
|
this.render();
|
|
@@ -70,8 +72,17 @@ var MbxStartButton = class extends Component {
|
|
|
70
72
|
this.resizer?.disconnect();
|
|
71
73
|
this.resizer = null;
|
|
72
74
|
this.removeAttribute("cramped");
|
|
75
|
+
this.style.removeProperty("--mbx-start-top");
|
|
73
76
|
}
|
|
74
77
|
/**
|
|
78
|
+
* The button sits between two middles: the player's own, and the middle
|
|
79
|
+
* of the picture left over the bar's controls. With the bar at the foot,
|
|
80
|
+
* the player's middle reads as too low. The bar is light, a line and a
|
|
81
|
+
* few glyphs over a gradient, so the middle of what it leaves reads as
|
|
82
|
+
* too high, most of all in a short player. Halfway between them is where
|
|
83
|
+
* the eye puts the centre. The bar's top padding is the lead-in of its
|
|
84
|
+
* gradient, so the controls start under it.
|
|
85
|
+
*
|
|
75
86
|
* Cramped when the button's foot would be inside the bar's box, which
|
|
76
87
|
* starts at the top of its gradient: then the bar's own play button is
|
|
77
88
|
* the one to press. Measured with the button shown, since a hidden one
|
|
@@ -81,13 +92,18 @@ var MbxStartButton = class extends Component {
|
|
|
81
92
|
const bar = player.querySelector("mbx-control-bar");
|
|
82
93
|
if (bar === null) {
|
|
83
94
|
this.removeAttribute("cramped");
|
|
95
|
+
this.style.removeProperty("--mbx-start-top");
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
98
|
+
const box = player.getBoundingClientRect();
|
|
99
|
+
const barBox = bar.getBoundingClientRect();
|
|
100
|
+
const controls = barBox.top + (Number.parseFloat(getComputedStyle(bar).paddingTop) || 0);
|
|
101
|
+
this.style.setProperty("--mbx-start-top", `${(box.height + controls - box.top) / 4}px`);
|
|
86
102
|
const wasHidden = this.hidden;
|
|
87
103
|
const wasCramped = this.hasAttribute("cramped");
|
|
88
104
|
this.hidden = false;
|
|
89
105
|
this.removeAttribute("cramped");
|
|
90
|
-
const cramped = this.button.getBoundingClientRect().bottom >
|
|
106
|
+
const cramped = this.button.getBoundingClientRect().bottom > barBox.top;
|
|
91
107
|
this.hidden = wasHidden;
|
|
92
108
|
this.toggleAttribute("cramped", cramped);
|
|
93
109
|
if (cramped !== wasCramped) this.render();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-button.js","names":[],"sources":["../../src/elements/start-button.ts"],"sourcesContent":["/**\n * <mbx-start-button>: the large play in the middle of the picture, shown\n * while the video is paused, a replay once it has ended, gone while it\n * plays, while a fatal error is on screen, and while the seek bar holds\n * the video paused for a drag (the player carries `scrubbing`). It sits in the player\n * beside the video, not in the bar, so it is over the poster and inside\n * fullscreen, and gone while the player waits for data, where the spinner\n * takes the centre. The glyph is `icon-play` or `icon-replay`, the name\n * `label-play` or `label-replay`.\n */\nimport type { PlayerError } from '@mattebox/player-core';\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';\nimport STYLE_CSS from './start-button.css?inline';\n\ntype State = 'play' | 'replay';\nconst STATES: readonly State[] = ['play', 'replay'];\n\nconst STYLE = BUTTON_STYLE + STYLE_CSS;\n\nexport class MbxStartButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-play', 'label-replay'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n /** A fatal error is on screen, and the play stays out of its way until playback or a load. */\n declare private failed: boolean;\n /** Watches the player's box: in a short one the button would sit over the bar. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.failed = false;\n this.resizer = 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, icon);\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.player?.video.play().catch(() => undefined);\n });\n root.append(style(STYLE), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n this.listen(video, ['play', 'pause', 'ended', 'waiting', 'stalled', 'canplay'], () => {\n this.render();\n });\n this.listen(video, ['playing', 'loadstart'], () => {\n this.failed = false;\n this.render();\n });\n this.listen(player, ['sourcechange'], () => {\n this.failed = false;\n this.render();\n });\n this.observe(player, ['scrubbing'], () => {\n this.render();\n });\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (!error.fatal) return;\n this.failed = true;\n this.render();\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n this.failed = player.error !== null;\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n }\n this.fit(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('cramped');\n }\n\n /**\n * Cramped when the button's foot would be inside the bar's box, which\n * starts at the top of its gradient: then the bar's own play button is\n * the one to press. Measured with the button shown, since a hidden one\n * has no box.\n */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n if (bar === null) {\n this.removeAttribute('cramped');\n return;\n }\n const wasHidden = this.hidden;\n const wasCramped = this.hasAttribute('cramped');\n this.hidden = false;\n this.removeAttribute('cramped');\n const cramped = this.button.getBoundingClientRect().bottom >
|
|
1
|
+
{"version":3,"file":"start-button.js","names":[],"sources":["../../src/elements/start-button.ts"],"sourcesContent":["/**\n * <mbx-start-button>: the large play in the middle of the picture, shown\n * while the video is paused, a replay once it has ended, gone while it\n * plays, while a fatal error is on screen, and while the seek bar holds\n * the video paused for a drag (the player carries `scrubbing`). It sits in the player\n * beside the video, not in the bar, so it is over the poster and inside\n * fullscreen, and gone while the player waits for data, where the spinner\n * takes the centre. The glyph is `icon-play` or `icon-replay`, the name\n * `label-play` or `label-replay`.\n */\nimport type { PlayerError } from '@mattebox/player-core';\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';\nimport STYLE_CSS from './start-button.css?inline';\n\ntype State = 'play' | 'replay';\nconst STATES: readonly State[] = ['play', 'replay'];\n\nconst STYLE = BUTTON_STYLE + STYLE_CSS;\n\nexport class MbxStartButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-play', 'label-replay'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n /** A fatal error is on screen, and the play stays out of its way until playback or a load. */\n declare private failed: boolean;\n /** Watches the player's box: in a short one the button would sit over the bar. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.failed = false;\n this.resizer = 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, icon);\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.player?.video.play().catch(() => undefined);\n });\n root.append(style(STYLE), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n this.listen(video, ['play', 'pause', 'ended', 'waiting', 'stalled', 'canplay'], () => {\n this.render();\n });\n this.listen(video, ['playing', 'loadstart'], () => {\n this.failed = false;\n this.render();\n });\n this.listen(player, ['sourcechange'], () => {\n this.failed = false;\n this.render();\n });\n this.observe(player, ['scrubbing'], () => {\n this.render();\n });\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (!error.fatal) return;\n this.failed = true;\n this.render();\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n this.failed = player.error !== null;\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n // The bar's height moves the middle too, when its rows wrap or a tier changes.\n const bar = player.querySelector('mbx-control-bar');\n if (bar !== null) this.resizer.observe(bar);\n }\n this.fit(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n }\n\n /**\n * The button sits between two middles: the player's own, and the middle\n * of the picture left over the bar's controls. With the bar at the foot,\n * the player's middle reads as too low. The bar is light, a line and a\n * few glyphs over a gradient, so the middle of what it leaves reads as\n * too high, most of all in a short player. Halfway between them is where\n * the eye puts the centre. The bar's top padding is the lead-in of its\n * gradient, so the controls start under it.\n *\n * Cramped when the button's foot would be inside the bar's box, which\n * starts at the top of its gradient: then the bar's own play button is\n * the one to press. Measured with the button shown, since a hidden one\n * has no box.\n */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n if (bar === null) {\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n return;\n }\n const box = player.getBoundingClientRect();\n const barBox = bar.getBoundingClientRect();\n const controls = barBox.top + (Number.parseFloat(getComputedStyle(bar).paddingTop) || 0);\n this.style.setProperty('--mbx-start-top', `${(box.height + controls - box.top) / 4}px`);\n const wasHidden = this.hidden;\n const wasCramped = this.hasAttribute('cramped');\n this.hidden = false;\n this.removeAttribute('cramped');\n const cramped = this.button.getBoundingClientRect().bottom > barBox.top;\n this.hidden = wasHidden;\n this.toggleAttribute('cramped', cramped);\n if (cramped !== wasCramped) this.render();\n }\n\n protected override render(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n const state: State = video.ended ? 'replay' : 'play';\n show(this.slots, state);\n this.button.setAttribute(\n 'aria-label',\n this.getAttribute(`label-${state}`) ?? (state === 'play' ? 'Play' : 'Replay'),\n );\n // The player reflects `waiting` first: it listens from its constructor.\n const player = this.player;\n this.hidden =\n this.failed ||\n !video.paused ||\n player?.hasAttribute('waiting') === true ||\n player?.hasAttribute('scrubbing') === true;\n }\n}\n"],"mappings":";;;;AAeA,MAAA,YAAA;AAGA,MAAA,SAAA,CAAA,QAAA,QAAA;AAEA,MAAA,QAAA,eAAA;AAEA,IAAA,iBAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA,CAAA,cAAA,cAAA;CACA;CASA,cAAA;EACA,MAAA;EACA,KAAA,SAAA;EACA,KAAA,UAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,KAAA,SAAA,SAAA,cAAA,QAAA;EACA,KAAA,OAAA,OAAA;EACA,KAAA,OAAA,aAAA,QAAA,QAAA;EACA,KAAA,QAAA,UAAA,QAAA,IAAA;EACA,KAAA,MAAA,SAAA,QAAA,KAAA,OAAA,OAAA,KAAA,MAAA,MAAA;EACA,KAAA,OA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MAAA,eAAA,iBAAA;GACA;EACA;EACA,MAAA,MAAA,OAAA,sBAAA;EACA,MAAA,SAAA,IAAA,sBAAA;EACA,MAAA,WAAA,OAAA,OAAA,OAAA,WAAA,iBAAA,GAAA,CAAA,CAAA,UAAA,KAAA;EACA,KAAA,MAAA,YAAA,mBAAA,IAAA,IAAA,SAAA,WAAA,IAAA,OAAA,EAAA,GAAA;EACA,MAAA,YAAA,KAAA;EACA,MAAA,aAAA,KAAA,aAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,SAAA;EACA,MAAA,UAAA,KAAA,OAAA,sBAAA,CAAA,CAAA,SAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,WAAA,OAAA;EACA,IAAA,YAAA,YAAA,KAAA,OAAA;CACA;CAEA,SAAA;EACA,MAAA,QAAA,KAAA,QAAA;EACA,IAAA,UAAA,KAAA,GAAA;EACA,MAAA,QAAA,MAAA,QAAA,WAAA;EACA,KAAA,KAAA,OAAA,KAAA;EACA,KAAA,OAAA,aACA,cACA,KAAA,aAAA,SAAA,OAAA,MAAA,UAAA,SAAA,SAAA,SACA;EAEA,MAAA,SAAA,KAAA;EACA,KAAA,SACA,KAAA,UACA,CAAA,MAAA,UACA,QAAA,aAAA,SAAA,MAAA,QACA,QAAA,aAAA,WAAA,MAAA;CACA;AACA"}
|
|
@@ -8,7 +8,11 @@ export declare class MbxSubtitlesMenu extends MenuElement<State> {
|
|
|
8
8
|
private engine;
|
|
9
9
|
constructor();
|
|
10
10
|
protected name(): string;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* A look's page: an item with the look's glyph, its name and the value
|
|
13
|
+
* chosen, which opens the choices. They are named from the attributes,
|
|
14
|
+
* and the value is the player's.
|
|
15
|
+
*/
|
|
12
16
|
private looks;
|
|
13
17
|
protected attach(player: PlayerHost): void;
|
|
14
18
|
/** The native session's subtitle tracks as entries, and the showing one's. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtitles-menu.d.ts","sourceRoot":"","sources":["../../src/elements/subtitles-menu.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subtitles-menu.d.ts","sourceRoot":"","sources":["../../src/elements/subtitles-menu.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAczD,KAAK,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;AAG1B,qBAAa,gBAAiB,SAAQ,WAAW,CAAC,KAAK,CAAC;IACtD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAcjD;IAED,QAAgB,MAAM,CAAkB;;cAQrB,IAAI,IAAI,MAAM;IAIjC;;;;OAIG;IACH,OAAO,CAAC,KAAK;cAoCM,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAanD,8EAA8E;IAC9E,OAAO,CAAC,MAAM;cAeK,MAAM,IAAI,IAAI;CA6ElC"}
|
|
@@ -38,26 +38,39 @@ var MbxSubtitlesMenu = class extends MenuElement {
|
|
|
38
38
|
];
|
|
39
39
|
}
|
|
40
40
|
constructor() {
|
|
41
|
-
super(STATES, (state) => icon(state === "on" ? "
|
|
41
|
+
super(STATES, (state) => icon(state === "on" ? "subtitles-on" : "subtitles"));
|
|
42
42
|
this.engine = null;
|
|
43
43
|
show(this.slots, "off");
|
|
44
44
|
}
|
|
45
45
|
name() {
|
|
46
46
|
return "Subtitles";
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
48
|
+
/**
|
|
49
|
+
* A look's page: an item with the look's glyph, its name and the value
|
|
50
|
+
* chosen, which opens the choices. They are named from the attributes,
|
|
51
|
+
* and the value is the player's.
|
|
52
|
+
*/
|
|
53
|
+
looks(player, attribute, name, fallback, choices, initial, glyph) {
|
|
50
54
|
const set = player.getAttribute(attribute);
|
|
51
55
|
const value = set !== null && choices.some(([id]) => id === set) ? set : initial;
|
|
56
|
+
const label = this.getAttribute(`label-${name}`) ?? fallback;
|
|
57
|
+
const items = choices.map(([id, text]) => [id, this.getAttribute(`label-${id}`) ?? text]);
|
|
52
58
|
return {
|
|
53
59
|
name,
|
|
54
|
-
label
|
|
55
|
-
|
|
56
|
-
value,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
label,
|
|
61
|
+
glyph: () => icon(glyph),
|
|
62
|
+
detail: items.find(([id]) => id === value)?.[1] ?? "",
|
|
63
|
+
entries: [{
|
|
64
|
+
name,
|
|
65
|
+
label,
|
|
66
|
+
hideLabel: true,
|
|
67
|
+
items,
|
|
68
|
+
value,
|
|
69
|
+
onSelect: (chosen) => {
|
|
70
|
+
player.setAttribute(attribute, chosen);
|
|
71
|
+
this.render();
|
|
72
|
+
}
|
|
73
|
+
}]
|
|
61
74
|
};
|
|
62
75
|
}
|
|
63
76
|
attach(player) {
|
|
@@ -98,7 +111,12 @@ var MbxSubtitlesMenu = class extends MenuElement {
|
|
|
98
111
|
this.menu.fill([{
|
|
99
112
|
name: "track",
|
|
100
113
|
label: word ?? "Track",
|
|
114
|
+
hideLabel: true,
|
|
101
115
|
items,
|
|
116
|
+
badgeGlyphs: {
|
|
117
|
+
[this.getAttribute("label-cc") ?? "CC"]: () => icon("closed-captions"),
|
|
118
|
+
[this.getAttribute("label-sdh") ?? "SDH"]: () => icon("sdh")
|
|
119
|
+
},
|
|
102
120
|
value: active ?? OFF,
|
|
103
121
|
onSelect: (value) => {
|
|
104
122
|
if (listed !== void 0) {
|
|
@@ -112,7 +130,7 @@ var MbxSubtitlesMenu = class extends MenuElement {
|
|
|
112
130
|
}, {
|
|
113
131
|
name: "settings",
|
|
114
132
|
label: this.getAttribute("label-settings") ?? "Settings",
|
|
115
|
-
entries: [this.looks(player, SUBTITLE_SIZE, "size", "Size", SIZES, "medium"), this.looks(player, SUBTITLE_BACKGROUND, "background", "Background", BACKGROUNDS, "dark")]
|
|
133
|
+
entries: [this.looks(player, SUBTITLE_SIZE, "size", "Size", SIZES, "medium", "text-size"), this.looks(player, SUBTITLE_BACKGROUND, "background", "Background", BACKGROUNDS, "dark", "text-background")]
|
|
116
134
|
}]);
|
|
117
135
|
show(this.slots, active === null ? "off" : "on");
|
|
118
136
|
this.hidden = tracks.length === 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtitles-menu.js","names":[],"sources":["../../src/elements/subtitles-menu.ts"],"sourcesContent":["/**\n * <mbx-subtitles-menu>: the text track over `engine.tracks`, or over the\n * video's `textTracks` of kind `subtitles` and `captions` for a native\n * session, with \"off\" because a text selection is releasable and an audio\n * one is not, and a Settings page behind it with the size and the\n * background. The glyph says whether a track is on: `icon` or `icon-on`.\n * Hidden without text tracks.\n *\n * The looks are attributes on the player, `subtitle-size` and\n * `subtitle-background`, where the element's stylesheet turns them into\n * the cue rules; a page can set them in markup and persist them however\n * it likes. Every word the menu shows is an attribute: `label`,\n * `label-off`, `label-track`, `label-settings`, `label-size`,\n * `label-background`, one per size and one per background, `label-sdh`\n * for the badge on subtitles for the deaf and hard of hearing, and\n * `label-cc` for the badge on closed captions carried in the video.\n * `label-track` also names a track that has no name and no language.\n *\n * Forced tracks are not listed. The engine's forced-subtitles stage shows\n * one while no subtitle is selected, so the menu reads Off then (guide\n * chapter 06). In a native session Safari shows them itself. A native\n * `captions` track carries the SDH badge: Safari gives that kind to the\n * subtitles that describe music and sound.\n */\nimport type { Mattebox } from 'mattebox';\nimport { isSdh } from 'mattebox';\nimport { icon } from '../controls/icons.js';\nimport type { MenuGroup } from '../controls/menu.js';\nimport { nativeTracks, onNativeTracks } from '../controls/native-tracks.js';\nimport type { TrackEntry } from '../controls/track-names.js';\nimport { trackNames } from '../controls/track-names.js';\nimport type { PlayerHost } from '../host.js';\nimport { onTracks, trackItems } from './audio-menu.js';\nimport { MenuElement } from './menu-element.js';\nimport { show } from './shared.js';\n\nconst OFF = 'off';\nexport const SUBTITLE_SIZE = 'subtitle-size';\nexport const SUBTITLE_BACKGROUND = 'subtitle-background';\n\nconst SIZES: ReadonlyArray<readonly [string, string]> = [\n ['small', 'Small'],\n ['medium', 'Medium'],\n ['large', 'Large'],\n ['xlarge', 'Extra large'],\n];\nconst BACKGROUNDS: ReadonlyArray<readonly [string, string]> = [\n ['none', 'None'],\n ['dark', 'Dark'],\n ['solid', 'Solid'],\n];\n\ntype State = 'off' | 'on';\nconst STATES: readonly State[] = ['off', 'on'];\n\nexport class MbxSubtitlesMenu extends MenuElement<State> {\n static get observedAttributes(): readonly string[] {\n return [\n 'label',\n 'label-back',\n 'label-off',\n 'label-track',\n 'label-settings',\n 'label-size',\n 'label-background',\n 'label-sdh',\n 'label-cc',\n ...SIZES.map(([id]) => `label-${id}`),\n ...BACKGROUNDS.map(([id]) => `label-${id}`),\n ];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(STATES, (state) => icon(state === 'on' ? 'closed-captions-on' : 'closed-captions'));\n this.engine = null;\n show(this.slots, 'off');\n }\n\n protected override name(): string {\n return 'Subtitles';\n }\n\n /** A look's group: the choices named from the attributes, the value from the player's. */\n private looks(\n player: PlayerHost,\n attribute: string,\n name: string,\n fallback: string,\n choices: ReadonlyArray<readonly [string, string]>,\n initial: string,\n ): MenuGroup {\n const set = player.getAttribute(attribute);\n const value = set !== null && choices.some(([id]) => id === set) ? set : initial;\n return {\n name,\n label: this.getAttribute(`label-${name}`) ?? fallback,\n items: choices.map(([id, text]) => [id, this.getAttribute(`label-${id}`) ?? text]),\n value,\n onSelect: (chosen) => {\n player.setAttribute(attribute, chosen);\n this.render();\n },\n };\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n const tick = (): void => {\n this.render();\n };\n return engine === null\n ? onNativeTracks(player.video, 'textTracks', tick)\n : onTracks(engine, tick);\n });\n }\n\n /** The native session's subtitle tracks as entries, and the showing one's. */\n private native(tracks: readonly TextTrack[]): [TrackEntry[], string | null] {\n const sdh = this.getAttribute('label-sdh') ?? 'SDH';\n const entries = tracks.map(\n (track, index): TrackEntry => [\n String(index),\n track.label,\n track.language,\n track.kind === 'captions' ? [sdh] : [],\n [],\n ],\n );\n const on = tracks.findIndex((track) => track.mode === 'showing');\n return [entries, on === -1 ? null : String(on)];\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n const player = this.player;\n // The chapters track the element adds, and any metadata track, are not subtitles.\n const listed =\n engine === null && player !== null\n ? nativeTracks<TextTrack>(player, 'textTracks')?.filter(\n (track) => track.kind === 'subtitles' || track.kind === 'captions',\n )\n : undefined;\n if (player === null || (engine === null && listed === undefined)) {\n this.hidden = true;\n return;\n }\n const [tracks, active] =\n listed !== undefined\n ? this.native(listed)\n : trackItems(\n engine as Mattebox,\n 'text',\n (track) => [\n // A manifest names in-band captions by their channel (guide chapter 06).\n ...(track.instreamId !== undefined ? [this.getAttribute('label-cc') ?? 'CC'] : []),\n ...(isSdh(track) ? [this.getAttribute('label-sdh') ?? 'SDH'] : []),\n ],\n (track) => track.forced !== true,\n );\n const word = this.getAttribute('label-track');\n const items: MenuGroup['items'] = [\n [OFF, this.getAttribute('label-off') ?? 'Off'],\n ...trackNames(tracks, word),\n ];\n this.menu.fill([\n {\n name: 'track',\n label: word ?? 'Track',\n items,\n value: active ?? OFF,\n onSelect: (value) => {\n if (listed !== undefined) {\n // Off first, so two tracks never show at once.\n for (const track of listed) track.mode = 'disabled';\n const chosen = listed[Number(value)];\n if (chosen !== undefined) chosen.mode = 'showing';\n } else if (value === OFF) engine?.tracks.deselect('text');\n else engine?.tracks.select(value);\n this.render();\n },\n },\n {\n name: 'settings',\n label: this.getAttribute('label-settings') ?? 'Settings',\n entries: [\n this.looks(player, SUBTITLE_SIZE, 'size', 'Size', SIZES, 'medium'),\n this.looks(player, SUBTITLE_BACKGROUND, 'background', 'Background', BACKGROUNDS, 'dark'),\n ],\n },\n ]);\n show(this.slots, active === null ? 'off' : 'on');\n this.hidden = tracks.length === 0;\n }\n}\n"],"mappings":";;;;;;;;AAoCA,MAAM,MAAM;AACZ,MAAa,gBAAgB;AAC7B,MAAa,sBAAsB;AAEnC,MAAM,QAAkD;CACtD,CAAC,SAAS,OAAO;CACjB,CAAC,UAAU,QAAQ;CACnB,CAAC,SAAS,OAAO;CACjB,CAAC,UAAU,aAAa;AAC1B;AACA,MAAM,cAAwD;CAC5D,CAAC,QAAQ,MAAM;CACf,CAAC,QAAQ,MAAM;CACf,CAAC,SAAS,OAAO;AACnB;AAGA,MAAM,SAA2B,CAAC,OAAO,IAAI;AAE7C,IAAa,mBAAb,cAAsC,YAAmB;CACvD,WAAW,qBAAwC;EACjD,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG,MAAM,KAAK,CAAC,QAAQ,SAAS,IAAI;GACpC,GAAG,YAAY,KAAK,CAAC,QAAQ,SAAS,IAAI;EAC5C;CACF;CAIA,cAAc;EACZ,MAAM,SAAS,UAAU,KAAK,UAAU,OAAO,uBAAuB,iBAAiB,CAAC;EACxF,KAAK,SAAS;EACd,KAAK,KAAK,OAAO,KAAK;CACxB;CAEA,OAAkC;EAChC,OAAO;CACT;;CAGA,MACE,QACA,WACA,MACA,UACA,SACA,SACW;EACX,MAAM,MAAM,OAAO,aAAa,SAAS;EACzC,MAAM,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,CAAC,QAAQ,OAAO,GAAG,IAAI,MAAM;EACzE,OAAO;GACL;GACA,OAAO,KAAK,aAAa,SAAS,MAAM,KAAK;GAC7C,OAAO,QAAQ,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,aAAa,SAAS,IAAI,KAAK,IAAI,CAAC;GACjF;GACA,WAAW,WAAW;IACpB,OAAO,aAAa,WAAW,MAAM;IACrC,KAAK,OAAO;GACd;EACF;CACF;CAE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,WAAW,KAAK,KAAK,GAC7C,GAAG,WAAW,QAAQ,IAAI,CAC5B;EACA,KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN,OAAO,QAAQ;GACf;GACA,OAAO,UAAU;GACjB,WAAW,UAAU;IACnB,IAAI,WAAW,KAAA,GAAW;KAExB,KAAK,MAAM,SAAS,QAAQ,MAAM,OAAO;KACzC,MAAM,SAAS,OAAO,OAAO,KAAK;KAClC,IAAI,WAAW,KAAA,GAAW,OAAO,OAAO;IAC1C,OAAO,IAAI,UAAU,KAAK,QAAQ,OAAO,SAAS,MAAM;SACnD,QAAQ,OAAO,OAAO,KAAK;IAChC,KAAK,OAAO;GACd;EACF,GACA;GACE,MAAM;GACN,OAAO,KAAK,aAAa,gBAAgB,KAAK;GAC9C,SAAS,CACP,KAAK,MAAM,QAAQ,eAAe,QAAQ,QAAQ,OAAO,QAAQ,GACjE,KAAK,MAAM,QAAQ,qBAAqB,cAAc,cAAc,aAAa,MAAM,CACzF;EACF,CACF,CAAC;EACD,KAAK,KAAK,OAAO,WAAW,OAAO,QAAQ,IAAI;EAC/C,KAAK,SAAS,OAAO,WAAW;CAClC;AACF"}
|
|
1
|
+
{"version":3,"file":"subtitles-menu.js","names":[],"sources":["../../src/elements/subtitles-menu.ts"],"sourcesContent":["/**\n * <mbx-subtitles-menu>: the text track over `engine.tracks`, or over the\n * video's `textTracks` of kind `subtitles` and `captions` for a native\n * session, with \"off\" because a text selection is releasable and an audio\n * one is not, and a Settings page behind it with the size and the\n * background. The glyph says whether a track is on: `icon` or `icon-on`.\n * Hidden without text tracks.\n *\n * The looks are attributes on the player, `subtitle-size` and\n * `subtitle-background`, where the element's stylesheet turns them into\n * the cue rules; a page can set them in markup and persist them however\n * it likes. Every word the menu shows is an attribute: `label`,\n * `label-off`, `label-track`, `label-settings`, `label-size`,\n * `label-background`, one per size and one per background, `label-sdh`\n * for the badge on subtitles for the deaf and hard of hearing, and\n * `label-cc` for the badge on closed captions carried in the video.\n * `label-track` also names a track that has no name and no language.\n *\n * Forced tracks are not listed. The engine's forced-subtitles stage shows\n * one while no subtitle is selected, so the menu reads Off then (guide\n * chapter 06). In a native session Safari shows them itself. A native\n * `captions` track carries the SDH badge: Safari gives that kind to the\n * subtitles that describe music and sound.\n */\nimport type { Mattebox } from 'mattebox';\nimport { isSdh } from 'mattebox';\nimport type { IconName } from '../controls/icons.js';\nimport { icon } from '../controls/icons.js';\nimport type { MenuGroup, MenuPage } from '../controls/menu.js';\nimport { nativeTracks, onNativeTracks } from '../controls/native-tracks.js';\nimport type { TrackEntry } from '../controls/track-names.js';\nimport { trackNames } from '../controls/track-names.js';\nimport type { PlayerHost } from '../host.js';\nimport { onTracks, trackItems } from './audio-menu.js';\nimport { MenuElement } from './menu-element.js';\nimport { show } from './shared.js';\n\nconst OFF = 'off';\nexport const SUBTITLE_SIZE = 'subtitle-size';\nexport const SUBTITLE_BACKGROUND = 'subtitle-background';\n\nconst SIZES: ReadonlyArray<readonly [string, string]> = [\n ['small', 'Small'],\n ['medium', 'Medium'],\n ['large', 'Large'],\n ['xlarge', 'Extra large'],\n];\nconst BACKGROUNDS: ReadonlyArray<readonly [string, string]> = [\n ['none', 'None'],\n ['dark', 'Dark'],\n ['solid', 'Solid'],\n];\n\ntype State = 'off' | 'on';\nconst STATES: readonly State[] = ['off', 'on'];\n\nexport class MbxSubtitlesMenu extends MenuElement<State> {\n static get observedAttributes(): readonly string[] {\n return [\n 'label',\n 'label-back',\n 'label-off',\n 'label-track',\n 'label-settings',\n 'label-size',\n 'label-background',\n 'label-sdh',\n 'label-cc',\n ...SIZES.map(([id]) => `label-${id}`),\n ...BACKGROUNDS.map(([id]) => `label-${id}`),\n ];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(STATES, (state) => icon(state === 'on' ? 'subtitles-on' : 'subtitles'));\n this.engine = null;\n show(this.slots, 'off');\n }\n\n protected override name(): string {\n return 'Subtitles';\n }\n\n /**\n * A look's page: an item with the look's glyph, its name and the value\n * chosen, which opens the choices. They are named from the attributes,\n * and the value is the player's.\n */\n private looks(\n player: PlayerHost,\n attribute: string,\n name: string,\n fallback: string,\n choices: ReadonlyArray<readonly [string, string]>,\n initial: string,\n glyph: IconName,\n ): MenuPage {\n const set = player.getAttribute(attribute);\n const value = set !== null && choices.some(([id]) => id === set) ? set : initial;\n const label = this.getAttribute(`label-${name}`) ?? fallback;\n const items = choices.map(\n ([id, text]) => [id, this.getAttribute(`label-${id}`) ?? text] as const,\n );\n return {\n name,\n label,\n glyph: () => icon(glyph),\n detail: items.find(([id]) => id === value)?.[1] ?? '',\n entries: [\n {\n name,\n label,\n hideLabel: true,\n items,\n value,\n onSelect: (chosen) => {\n player.setAttribute(attribute, chosen);\n this.render();\n },\n },\n ],\n };\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n const tick = (): void => {\n this.render();\n };\n return engine === null\n ? onNativeTracks(player.video, 'textTracks', tick)\n : onTracks(engine, tick);\n });\n }\n\n /** The native session's subtitle tracks as entries, and the showing one's. */\n private native(tracks: readonly TextTrack[]): [TrackEntry[], string | null] {\n const sdh = this.getAttribute('label-sdh') ?? 'SDH';\n const entries = tracks.map(\n (track, index): TrackEntry => [\n String(index),\n track.label,\n track.language,\n track.kind === 'captions' ? [sdh] : [],\n [],\n ],\n );\n const on = tracks.findIndex((track) => track.mode === 'showing');\n return [entries, on === -1 ? null : String(on)];\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n const player = this.player;\n // The chapters track the element adds, and any metadata track, are not subtitles.\n const listed =\n engine === null && player !== null\n ? nativeTracks<TextTrack>(player, 'textTracks')?.filter(\n (track) => track.kind === 'subtitles' || track.kind === 'captions',\n )\n : undefined;\n if (player === null || (engine === null && listed === undefined)) {\n this.hidden = true;\n return;\n }\n const [tracks, active] =\n listed !== undefined\n ? this.native(listed)\n : trackItems(\n engine as Mattebox,\n 'text',\n (track) => [\n // A manifest names in-band captions by their channel (guide chapter 06).\n ...(track.instreamId !== undefined ? [this.getAttribute('label-cc') ?? 'CC'] : []),\n ...(isSdh(track) ? [this.getAttribute('label-sdh') ?? 'SDH'] : []),\n ],\n (track) => track.forced !== true,\n );\n const word = this.getAttribute('label-track');\n const items: MenuGroup['items'] = [\n [OFF, this.getAttribute('label-off') ?? 'Off'],\n ...trackNames(tracks, word),\n ];\n this.menu.fill([\n {\n name: 'track',\n label: word ?? 'Track',\n // The menu's title says what the list is.\n hideLabel: true,\n items,\n // The badges are glyphs, named by `label-cc` and `label-sdh`.\n badgeGlyphs: {\n [this.getAttribute('label-cc') ?? 'CC']: () => icon('closed-captions'),\n [this.getAttribute('label-sdh') ?? 'SDH']: () => icon('sdh'),\n },\n value: active ?? OFF,\n onSelect: (value) => {\n if (listed !== undefined) {\n // Off first, so two tracks never show at once.\n for (const track of listed) track.mode = 'disabled';\n const chosen = listed[Number(value)];\n if (chosen !== undefined) chosen.mode = 'showing';\n } else if (value === OFF) engine?.tracks.deselect('text');\n else engine?.tracks.select(value);\n this.render();\n },\n },\n {\n name: 'settings',\n label: this.getAttribute('label-settings') ?? 'Settings',\n entries: [\n this.looks(player, SUBTITLE_SIZE, 'size', 'Size', SIZES, 'medium', 'text-size'),\n this.looks(\n player,\n SUBTITLE_BACKGROUND,\n 'background',\n 'Background',\n BACKGROUNDS,\n 'dark',\n 'text-background',\n ),\n ],\n },\n ]);\n show(this.slots, active === null ? 'off' : 'on');\n this.hidden = tracks.length === 0;\n }\n}\n"],"mappings":";;;;;;;;AAqCA,MAAM,MAAM;AACZ,MAAa,gBAAgB;AAC7B,MAAa,sBAAsB;AAEnC,MAAM,QAAkD;CACtD,CAAC,SAAS,OAAO;CACjB,CAAC,UAAU,QAAQ;CACnB,CAAC,SAAS,OAAO;CACjB,CAAC,UAAU,aAAa;AAC1B;AACA,MAAM,cAAwD;CAC5D,CAAC,QAAQ,MAAM;CACf,CAAC,QAAQ,MAAM;CACf,CAAC,SAAS,OAAO;AACnB;AAGA,MAAM,SAA2B,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,UAAU;GACjB,WAAW,UAAU;IACnB,IAAI,WAAW,KAAA,GAAW;KAExB,KAAK,MAAM,SAAS,QAAQ,MAAM,OAAO;KACzC,MAAM,SAAS,OAAO,OAAO,KAAK;KAClC,IAAI,WAAW,KAAA,GAAW,OAAO,OAAO;IAC1C,OAAO,IAAI,UAAU,KAAK,QAAQ,OAAO,SAAS,MAAM;SACnD,QAAQ,OAAO,OAAO,KAAK;IAChC,KAAK,OAAO;GACd;EACF,GACA;GACE,MAAM;GACN,OAAO,KAAK,aAAa,gBAAgB,KAAK;GAC9C,SAAS,CACP,KAAK,MAAM,QAAQ,eAAe,QAAQ,QAAQ,OAAO,UAAU,WAAW,GAC9E,KAAK,MACH,QACA,qBACA,cACA,cACA,aACA,QACA,iBACF,CACF;EACF,CACF,CAAC;EACD,KAAK,KAAK,OAAO,WAAW,OAAO,QAAQ,IAAI;EAC/C,KAAK,SAAS,OAAO,WAAW;CAClC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title.d.ts","sourceRoot":"","sources":["../../src/elements/title.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,qBAAa,QAAS,SAAQ,SAAS;IACrC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAmB;IACnD,iBAAyB,OAAO,CAAc;IAC9C,iBAAyB,UAAU,CAAc;IACjD,0FAA0F;IAC1F,QAAgB,OAAO,CAAwB;;cAgB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"title.d.ts","sourceRoot":"","sources":["../../src/elements/title.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,qBAAa,QAAS,SAAQ,SAAS;IACrC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAmB;IACnD,iBAAyB,OAAO,CAAc;IAC9C,iBAAyB,UAAU,CAAc;IACjD,0FAA0F;IAC1F,QAAgB,OAAO,CAAwB;;cAgB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAmBhC,MAAM,IAAI,IAAI;IAOjC,uEAAuE;IACvE,OAAO,CAAC,KAAK;IAIb,gHAAgH;IAChH,OAAO,CAAC,GAAG;cAUQ,MAAM,IAAI,IAAI;CAelC"}
|
package/dist/elements/title.js
CHANGED
|
@@ -24,7 +24,7 @@ import { style } from "./shared.js";
|
|
|
24
24
|
* override. Placed first among the screens, so the start button, the
|
|
25
25
|
* error screen and the spinner paint over its band.
|
|
26
26
|
*/
|
|
27
|
-
const STYLE = ":host{padding:
|
|
27
|
+
const STYLE = ":host{padding:4.5em calc(var(--mbx-pad) + .5em) calc(var(--mbx-bar-rows,0px) + .75em);color:var(--mbx-text);font:400 1em / 1.35 var(--mbx-font);text-shadow:0 1px 2px #0006;pointer-events:none;background:linear-gradient(#0000,#0000004d 55%,#0000008c);align-items:flex-end;display:flex;position:absolute;bottom:0;left:0;right:0}:host([playing]),:host([empty]),:host([hidden]){display:none}[part~=artwork]{border-radius:var(--mbx-radius);object-fit:cover;flex:none;width:auto;max-width:8em;height:4.5em;margin-right:.875em;box-shadow:0 0 0 1px #ffffff24}[part~=artwork][hidden]{display:none}[part~=text]{flex-direction:column;min-width:0;max-width:60ch;font-size:.875em;display:flex}[part~=text]>:not([hidden])~:not([hidden]){margin-top:.1429em}[part~=heading]{letter-spacing:-.01em;white-space:nowrap;text-overflow:ellipsis;font-size:1.4286em;font-weight:600;line-height:1.2;overflow:hidden}[part~=subheading]{color:#ffffffc7;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}[part~=heading]:empty,[part~=subheading]:empty{display:none}:host([artwork]) [part~=heading]:not(:empty){white-space:normal;-webkit-line-clamp:3;-webkit-box-orient:vertical;display:-webkit-box}:host([artwork][subheading]) [part~=heading]:not(:empty){-webkit-line-clamp:2}:host([layout=compact]){padding:.75em calc(var(--mbx-pad) + .5em) 2.5em;background:linear-gradient(#0000008c,#0000);align-items:flex-start;top:0;bottom:auto}:host([layout=compact]) [part~=artwork],:host([layout=compact]) [part~=subheading]{display:none}:host([layout=compact]) [part~=text] [part~=heading]:not(:empty){white-space:nowrap;font-size:1.1429em;display:block}";
|
|
28
28
|
var MbxTitle = class extends Component {
|
|
29
29
|
static get observedAttributes() {
|
|
30
30
|
return [
|
|
@@ -60,6 +60,8 @@ var MbxTitle = class extends Component {
|
|
|
60
60
|
this.fit(player);
|
|
61
61
|
});
|
|
62
62
|
this.resizer.observe(player);
|
|
63
|
+
const bar = player.querySelector("mbx-control-bar");
|
|
64
|
+
if (bar !== null) this.resizer.observe(bar);
|
|
63
65
|
}
|
|
64
66
|
this.fit(player);
|
|
65
67
|
this.state(player);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title.js","names":[],"sources":["../../src/elements/title.ts"],"sourcesContent":["/**\n * <mbx-title>: the heading, the subheading and the artwork of what plays,\n * as a lower third across the picture above the bar: a scrim that fades\n * upward, the artwork in the first column, the two lines in the second,\n * so a heading alone sits on a band and never floats. The content comes\n * from attributes, `heading`,\n * `subheading` and `artwork`, because the stream carries none of it: a page\n * writes what it knows, and a Cast receiver writes what the sender said.\n * With none of the three the element draws nothing.\n *\n * Shown while the video is paused, which includes before the first play,\n * and hidden while it plays. The element carries `playing` for that rule,\n * so a page changes it in CSS: `mattebox-player[started] mbx-title\n * { display: none }` keeps it to the time before the first play, like the\n * poster, and `mattebox-player:hover mbx-title { display: flex }` brings it\n * back on hover. The height of the bar's rows, its box less the fade it\n * pads itself with, goes on the host as `--mbx-bar-rows`, so the text sits\n * just above the seek row while the band runs under the bar to the bottom\n * edge, one ramp with the bar's own fade. The scrim is the page's to\n * override. Placed first among the screens, so the start button, the\n * error screen and the spinner paint over its band.\n */\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { style } from './shared.js';\nimport STYLE from './title.css?inline';\n\nexport class MbxTitle extends Component {\n static get observedAttributes(): readonly string[] {\n return ['heading', 'subheading', 'artwork'];\n }\n\n declare private readonly artwork: HTMLImageElement;\n declare private readonly heading: HTMLElement;\n declare private readonly subheading: HTMLElement;\n /** Watches the player's box: the height of the bar's rows decides where the text sits. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.artwork = el('img', 'artwork');\n this.artwork.alt = '';\n this.artwork.hidden = true;\n const text = el('div', 'text');\n this.heading = el('div', 'heading');\n this.subheading = el('div', 'subheading');\n text.append(this.heading, this.subheading);\n root.append(style(STYLE), this.artwork, text);\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player.video, ['play', 'pause', 'ended', 'emptied'], () => {\n this.state(player);\n });\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n }\n this.fit(player);\n this.state(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('playing');\n this.style.removeProperty('--mbx-bar-rows');\n }\n\n /** `playing` on the element, for its own stylesheet and the page's. */\n private state(player: PlayerHost): void {\n this.toggleAttribute('playing', !player.video.paused);\n }\n\n /** The height of the bar's rows: its box less the padding above them, which is its fade. Zero without a bar. */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n let rows = 0;\n if (bar !== null) {\n const top = Number.parseFloat(getComputedStyle(bar).paddingTop) || 0;\n rows = Math.max(0, bar.getBoundingClientRect().height - top);\n }\n this.style.setProperty('--mbx-bar-rows', `${rows}px`);\n }\n\n protected override render(): void {\n const heading = this.getAttribute('heading') ?? '';\n const subheading = this.getAttribute('subheading') ?? '';\n const artwork = this.getAttribute('artwork');\n this.heading.textContent = heading;\n this.subheading.textContent = subheading;\n if (artwork === null) {\n this.artwork.removeAttribute('src');\n this.artwork.hidden = true;\n } else {\n this.artwork.src = artwork;\n this.artwork.hidden = false;\n }\n this.toggleAttribute('empty', heading === '' && subheading === '' && artwork === null);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAA,QAAA;AAEA,IAAA,WAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA;GAAA;GAAA;GAAA;EAAA;CACA;CAQA,cAAA;EACA,MAAA;EACA,KAAA,UAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,QAAA,MAAA;EACA,KAAA,QAAA,SAAA;EACA,MAAA,OAAA,GAAA,OAAA,MAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,aAAA,GAAA,OAAA,YAAA;EACA,KAAA,OAAA,KAAA,SAAA,KAAA,UAAA;EACA,KAAA,OAAA,MAAA,KAAA,GAAA,KAAA,SAAA,IAAA;CACA;CAEA,OAAA,QAAA;EACA,KAAA,OAAA,OAAA,OAAA;GAAA;GAAA;GAAA;GAAA;EAAA,SAAA;GACA,KAAA,MAAA,MAAA;EACA,CAAA;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,qBAAA;IACA,KAAA,IAAA,MAAA;GACA,CAAA;GACA,KAAA,QAAA,QAAA,MAAA;EACA;EACA,KAAA,IAAA,MAAA;EACA,KAAA,MAAA,MAAA;EACA,KAAA,OAAA;CACA;CAEA,SAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,gBAAA,SAAA;EACA,KAAA,MAAA,eAAA,gBAAA;CACA;;CAGA,MAAA,QAAA;EACA,KAAA,gBAAA,WAAA,CAAA,OAAA,MAAA,MAAA;CACA;;CAGA,IAAA,QAAA;EACA,MAAA,MAAA,OAAA,cAAA,iBAAA;EACA,IAAA,OAAA;EACA,IAAA,QAAA,MAAA;GACA,MAAA,MAAA,OAAA,WAAA,iBAAA,GAAA,CAAA,CAAA,UAAA,KAAA;GACA,OAAA,KAAA,IAAA,GAAA,IAAA,sBAAA,CAAA,CAAA,SAAA,GAAA;EACA;EACA,KAAA,MAAA,YAAA,kBAAA,GAAA,KAAA,GAAA;CACA;CAEA,SAAA;EACA,MAAA,UAAA,KAAA,aAAA,SAAA,KAAA;EACA,MAAA,aAAA,KAAA,aAAA,YAAA,KAAA;EACA,MAAA,UAAA,KAAA,aAAA,SAAA;EACA,KAAA,QAAA,cAAA;EACA,KAAA,WAAA,cAAA;EACA,IAAA,YAAA,MAAA;GACA,KAAA,QAAA,gBAAA,KAAA;GACA,KAAA,QAAA,SAAA;EACA,OAAA;GACA,KAAA,QAAA,MAAA;GACA,KAAA,QAAA,SAAA;EACA;EACA,KAAA,gBAAA,SAAA,YAAA,MAAA,eAAA,MAAA,YAAA,IAAA;CACA;AACA"}
|
|
1
|
+
{"version":3,"file":"title.js","names":[],"sources":["../../src/elements/title.ts"],"sourcesContent":["/**\n * <mbx-title>: the heading, the subheading and the artwork of what plays,\n * as a lower third across the picture above the bar: a scrim that fades\n * upward, the artwork in the first column, the two lines in the second,\n * so a heading alone sits on a band and never floats. The content comes\n * from attributes, `heading`,\n * `subheading` and `artwork`, because the stream carries none of it: a page\n * writes what it knows, and a Cast receiver writes what the sender said.\n * With none of the three the element draws nothing.\n *\n * Shown while the video is paused, which includes before the first play,\n * and hidden while it plays. The element carries `playing` for that rule,\n * so a page changes it in CSS: `mattebox-player[started] mbx-title\n * { display: none }` keeps it to the time before the first play, like the\n * poster, and `mattebox-player:hover mbx-title { display: flex }` brings it\n * back on hover. The height of the bar's rows, its box less the fade it\n * pads itself with, goes on the host as `--mbx-bar-rows`, so the text sits\n * just above the seek row while the band runs under the bar to the bottom\n * edge, one ramp with the bar's own fade. The scrim is the page's to\n * override. Placed first among the screens, so the start button, the\n * error screen and the spinner paint over its band.\n */\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { style } from './shared.js';\nimport STYLE from './title.css?inline';\n\nexport class MbxTitle extends Component {\n static get observedAttributes(): readonly string[] {\n return ['heading', 'subheading', 'artwork'];\n }\n\n declare private readonly artwork: HTMLImageElement;\n declare private readonly heading: HTMLElement;\n declare private readonly subheading: HTMLElement;\n /** Watches the player's box: the height of the bar's rows decides where the text sits. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.artwork = el('img', 'artwork');\n this.artwork.alt = '';\n this.artwork.hidden = true;\n const text = el('div', 'text');\n this.heading = el('div', 'heading');\n this.subheading = el('div', 'subheading');\n text.append(this.heading, this.subheading);\n root.append(style(STYLE), this.artwork, text);\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player.video, ['play', 'pause', 'ended', 'emptied'], () => {\n this.state(player);\n });\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n // The bar's rows change height with the player's size tier, without\n // the player's box changing.\n const bar = player.querySelector('mbx-control-bar');\n if (bar !== null) this.resizer.observe(bar);\n }\n this.fit(player);\n this.state(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('playing');\n this.style.removeProperty('--mbx-bar-rows');\n }\n\n /** `playing` on the element, for its own stylesheet and the page's. */\n private state(player: PlayerHost): void {\n this.toggleAttribute('playing', !player.video.paused);\n }\n\n /** The height of the bar's rows: its box less the padding above them, which is its fade. Zero without a bar. */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n let rows = 0;\n if (bar !== null) {\n const top = Number.parseFloat(getComputedStyle(bar).paddingTop) || 0;\n rows = Math.max(0, bar.getBoundingClientRect().height - top);\n }\n this.style.setProperty('--mbx-bar-rows', `${rows}px`);\n }\n\n protected override render(): void {\n const heading = this.getAttribute('heading') ?? '';\n const subheading = this.getAttribute('subheading') ?? '';\n const artwork = this.getAttribute('artwork');\n this.heading.textContent = heading;\n this.subheading.textContent = subheading;\n if (artwork === null) {\n this.artwork.removeAttribute('src');\n this.artwork.hidden = true;\n } else {\n this.artwork.src = artwork;\n this.artwork.hidden = false;\n }\n this.toggleAttribute('empty', heading === '' && subheading === '' && artwork === null);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAA,QAAA;AAEA,IAAA,WAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA;GAAA;GAAA;GAAA;EAAA;CACA;CAQA,cAAA;EACA,MAAA;EACA,KAAA,UAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,QAAA,MAAA;EACA,KAAA,QAAA,SAAA;EACA,MAAA,OAAA,GAAA,OAAA,MAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,aAAA,GAAA,OAAA,YAAA;EACA,KAAA,OAAA,KAAA,SAAA,KAAA,UAAA;EACA,KAAA,OAAA,MAAA,KAAA,GAAA,KAAA,SAAA,IAAA;CACA;CAEA,OAAA,QAAA;EACA,KAAA,OAAA,OAAA,OAAA;GAAA;GAAA;GAAA;GAAA;EAAA,SAAA;GACA,KAAA,MAAA,MAAA;EACA,CAAA;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,qBAAA;IACA,KAAA,IAAA,MAAA;GACA,CAAA;GACA,KAAA,QAAA,QAAA,MAAA;GAGA,MAAA,MAAA,OAAA,cAAA,iBAAA;GACA,IAAA,QAAA,MAAA,KAAA,QAAA,QAAA,GAAA;EACA;EACA,KAAA,IAAA,MAAA;EACA,KAAA,MAAA,MAAA;EACA,KAAA,OAAA;CACA;CAEA,SAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,gBAAA,SAAA;EACA,KAAA,MAAA,eAAA,gBAAA;CACA;;CAGA,MAAA,QAAA;EACA,KAAA,gBAAA,WAAA,CAAA,OAAA,MAAA,MAAA;CACA;;CAGA,IAAA,QAAA;EACA,MAAA,MAAA,OAAA,cAAA,iBAAA;EACA,IAAA,OAAA;EACA,IAAA,QAAA,MAAA;GACA,MAAA,MAAA,OAAA,WAAA,iBAAA,GAAA,CAAA,CAAA,UAAA,KAAA;GACA,OAAA,KAAA,IAAA,GAAA,IAAA,sBAAA,CAAA,CAAA,SAAA,GAAA;EACA;EACA,KAAA,MAAA,YAAA,kBAAA,GAAA,KAAA,GAAA;CACA;CAEA,SAAA;EACA,MAAA,UAAA,KAAA,aAAA,SAAA,KAAA;EACA,MAAA,aAAA,KAAA,aAAA,YAAA,KAAA;EACA,MAAA,UAAA,KAAA,aAAA,SAAA;EACA,KAAA,QAAA,cAAA;EACA,KAAA,WAAA,cAAA;EACA,IAAA,YAAA,MAAA;GACA,KAAA,QAAA,gBAAA,KAAA;GACA,KAAA,QAAA,SAAA;EACA,OAAA;GACA,KAAA,QAAA,MAAA;GACA,KAAA,QAAA,SAAA;EACA;EACA,KAAA,gBAAA,SAAA,YAAA,MAAA,eAAA,MAAA,YAAA,IAAA;CACA;AACA"}
|
|
@@ -2,7 +2,7 @@ import { Component } from "./component.js";
|
|
|
2
2
|
import { SLIDER_STYLE, number, style } from "./shared.js";
|
|
3
3
|
import { slider } from "../controls/slider.js";
|
|
4
4
|
//#region src/elements/volume-slider.ts
|
|
5
|
-
const VOLUME_SLIDER_CSS = ":host{flex:none;width:
|
|
5
|
+
const VOLUME_SLIDER_CSS = ":host{flex:none;width:5em}";
|
|
6
6
|
const STEP = .05;
|
|
7
7
|
const PAGE = .2;
|
|
8
8
|
var MbxVolumeSlider = class extends Component {
|
package/dist/elements/volume.js
CHANGED
|
@@ -15,7 +15,7 @@ import { style } from "./shared.js";
|
|
|
15
15
|
* stuck. So the group carries `pointer` from a pointer press until a key
|
|
16
16
|
* is pressed or focus leaves, and focus unfolds the slider only without it.
|
|
17
17
|
*/
|
|
18
|
-
const STYLE = ":host{align-items:center;display:inline-flex}:host([hidden]){display:none}::slotted(mbx-volume-slider){opacity:0;width:0;transition:width .2s,opacity .2s;overflow:hidden}::slotted(mbx-volume-slider[collapsed]){display:none}:host(:hover) ::slotted(mbx-volume-slider),:host(:focus-within:not([pointer])) ::slotted(mbx-volume-slider){opacity:1;width:
|
|
18
|
+
const STYLE = ":host{align-items:center;display:inline-flex}:host([hidden]){display:none}::slotted(mbx-volume-slider){opacity:0;width:0;transition:width .2s,opacity .2s;overflow:hidden}::slotted(mbx-volume-slider[collapsed]){display:none}:host(:hover) ::slotted(mbx-volume-slider),:host(:focus-within:not([pointer])) ::slotted(mbx-volume-slider){opacity:1;width:5em}@media (prefers-reduced-motion:reduce){::slotted(mbx-volume-slider){transition:none}}";
|
|
19
19
|
var MbxVolume = class extends Component {
|
|
20
20
|
constructor() {
|
|
21
21
|
super();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import toPropertyKey from "./toPropertyKey.js";
|
|
2
|
-
//#region \0@oxc-project+runtime@0.
|
|
2
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
3
3
|
function _defineProperty(e, r, t) {
|
|
4
4
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
5
5
|
value: t,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "./defineProperty.js";
|
|
2
|
-
//#region \0@oxc-project+runtime@0.
|
|
2
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/objectSpread2.js
|
|
3
3
|
function ownKeys(e, r) {
|
|
4
4
|
var t = Object.keys(e);
|
|
5
5
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _typeof from "./typeof.js";
|
|
2
|
-
//#region \0@oxc-project+runtime@0.
|
|
2
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
3
3
|
function toPrimitive(t, r) {
|
|
4
4
|
if ("object" != _typeof(t) || !t) return t;
|
|
5
5
|
var e = t[Symbol.toPrimitive];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _typeof from "./typeof.js";
|
|
2
2
|
import toPrimitive from "./toPrimitive.js";
|
|
3
|
-
//#region \0@oxc-project+runtime@0.
|
|
3
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
4
4
|
function toPropertyKey(t) {
|
|
5
5
|
var i = toPrimitive(t, "string");
|
|
6
6
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
2
2
|
function _typeof(o) {
|
|
3
3
|
"@babel/helpers - typeof";
|
|
4
4
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
|
|
2
2
|
import { optional } from "./session.js";
|
|
3
3
|
//#region src/controls/chapters.ts
|
|
4
4
|
/** The first chapters track on the video, or null. */
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Subtitles and the bar. Two things.
|
|
4
4
|
*
|
|
5
|
-
* The lift: the browser draws native cues
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The lift: the browser draws native cues on the bottom edge of the video,
|
|
6
|
+
* and under the bar. Every active cue the author left unpositioned is
|
|
7
|
+
* moved up: above the bar while it shows, and one line off the edge while
|
|
8
|
+
* it is hidden, so the text never sits on the picture's border. The
|
|
8
9
|
* position is a negative line count, the one form every browser wraps at
|
|
9
10
|
* the video's width; a percentage does not wrap in Chromium. Chromium
|
|
10
11
|
* anchors the box's top on the count and Gecko its bottom, and their
|
|
@@ -43,6 +44,8 @@ const LINE_HEIGHT = 1.2;
|
|
|
43
44
|
const CUE_WIDTH = .96;
|
|
44
45
|
/** Pixels of air between the bar and the cue above it, before rounding up to a line. */
|
|
45
46
|
const AIR = 6;
|
|
47
|
+
/** Lines of air under a cue while the bar is hidden. */
|
|
48
|
+
const REST = 1;
|
|
46
49
|
/** Puts the cue rules in the document, once. */
|
|
47
50
|
function cueStyle() {
|
|
48
51
|
if (document.head.querySelector(`style[${MARK}]`) !== null) return;
|
|
@@ -55,6 +58,8 @@ function cueLift(video, host, covered) {
|
|
|
55
58
|
/** The cues moved, with what they were, so they and only they are put back. */
|
|
56
59
|
const lifted = /* @__PURE__ */ new Map();
|
|
57
60
|
let on = false;
|
|
61
|
+
/** False once disposed: the cues go back to where the author left them. */
|
|
62
|
+
let live = true;
|
|
58
63
|
let canvas;
|
|
59
64
|
function showing() {
|
|
60
65
|
const out = [];
|
|
@@ -104,10 +109,10 @@ function cueLift(video, host, covered) {
|
|
|
104
109
|
const height = box.height;
|
|
105
110
|
const span = covered();
|
|
106
111
|
const pixels = span.bottom - span.top;
|
|
107
|
-
const lift =
|
|
112
|
+
const lift = live && height > 0;
|
|
108
113
|
const font = fontSize(height);
|
|
109
114
|
const unit = font * LINE_HEIGHT;
|
|
110
|
-
const base = Math.ceil((pixels + AIR) / unit);
|
|
115
|
+
const base = on && pixels > 0 && pixels < height ? Math.ceil((pixels + AIR) / unit) : REST;
|
|
111
116
|
for (const track of showing()) {
|
|
112
117
|
var _track$activeCues;
|
|
113
118
|
const active = [...(_track$activeCues = track.activeCues) !== null && _track$activeCues !== void 0 ? _track$activeCues : []].filter((cue) => cue instanceof VTTCue).sort((a, b) => a.startTime - b.startTime);
|
|
@@ -163,6 +168,7 @@ function cueLift(video, host, covered) {
|
|
|
163
168
|
},
|
|
164
169
|
dispose() {
|
|
165
170
|
on = false;
|
|
171
|
+
live = false;
|
|
166
172
|
apply();
|
|
167
173
|
video.textTracks.removeEventListener("change", watch);
|
|
168
174
|
video.textTracks.removeEventListener("addtrack", watch);
|