@hanifhan1f/vidstack 1.12.25 → 1.12.27
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/cdn/chunks/vidstack-8JHLDxl5.js +1 -0
- package/cdn/chunks/vidstack-Bpnl-N6k.js +1 -0
- package/cdn/chunks/vidstack-CnWKPIKT.js +16 -0
- package/cdn/chunks/vidstack-CqzAnF2W.js +16 -0
- package/cdn/vidstack.js +1 -1
- package/cdn/with-layouts/chunks/vidstack-BD5YoTt5.js +937 -0
- package/cdn/with-layouts/chunks/vidstack-DCaNJN4T.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-Dd3L-eQj.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-T2rZVigk.js +912 -0
- package/cdn/with-layouts/vidstack.js +1 -1
- package/dev/chunks/vidstack--aukHYxl.js +1520 -0
- package/dev/chunks/vidstack-B__DfQsT.js +1621 -0
- package/dev/chunks/vidstack-BoLIUOyq.js +204 -0
- package/dev/chunks/vidstack-CSryZFvY.js +1521 -0
- package/dev/chunks/vidstack-Cky9ors4.js +297 -0
- package/dev/chunks/vidstack-Crz0ROkT.js +3009 -0
- package/dev/chunks/vidstack-D-sqb6YI.js +308 -0
- package/dev/chunks/vidstack-DLXCqdYV.js +3010 -0
- package/dev/chunks/vidstack-DS7nRfge.js +204 -0
- package/dev/chunks/vidstack-Dco6kA4h.js +104 -0
- package/dev/chunks/vidstack-DpS0Kt4b.js +297 -0
- package/dev/chunks/vidstack-zJT-7ncH.js +5182 -0
- package/dev/define/plyr-layout.js +3 -4
- package/dev/define/templates/vidstack-audio-layout.js +4 -4
- package/dev/define/templates/vidstack-video-layout.js +4 -4
- package/dev/define/vidstack-player-default-layout.js +4 -4
- package/dev/define/vidstack-player-layouts.js +4 -4
- package/dev/define/vidstack-player-ui.js +5 -6
- package/dev/define/vidstack-player.js +3 -4
- package/dev/global/plyr.js +5 -6
- package/dev/global/vidstack-player.js +3 -4
- package/dev/providers/vidstack-dash.js +1 -2
- package/dev/providers/vidstack-hls.js +1 -2
- package/dev/providers/vidstack-video.js +1 -2
- package/dev/providers/vidstack-vimeo.js +1 -2
- package/dev/vidstack-elements.js +8 -9
- package/dev/vidstack.js +6 -7
- package/package.json +2 -1
- package/prod/chunks/vidstack-BVSJtdRd.js +297 -0
- package/prod/chunks/vidstack-BnEo_Sla.js +1621 -0
- package/prod/chunks/vidstack-CFXAYpuh.js +1521 -0
- package/prod/chunks/vidstack-CIvL96_j.js +297 -0
- package/prod/chunks/vidstack-CLTPjjXX.js +4772 -0
- package/prod/chunks/vidstack-CSHHV2zO.js +201 -0
- package/prod/chunks/vidstack-CYVCrFjx.js +201 -0
- package/prod/chunks/vidstack-D_atbNqH.js +3000 -0
- package/prod/chunks/vidstack-Eo46ZHu7.js +2999 -0
- package/prod/chunks/vidstack-sP7TQMB1.js +300 -0
- package/prod/chunks/vidstack-uVm3xX8H.js +104 -0
- package/prod/chunks/vidstack-zknLxihl.js +1520 -0
- package/prod/define/plyr-layout.js +3 -4
- package/prod/define/templates/vidstack-audio-layout.js +4 -4
- package/prod/define/templates/vidstack-video-layout.js +4 -4
- package/prod/define/vidstack-player-default-layout.js +4 -4
- package/prod/define/vidstack-player-layouts.js +4 -4
- package/prod/define/vidstack-player-ui.js +5 -6
- package/prod/define/vidstack-player.js +3 -4
- package/prod/global/plyr.js +5 -6
- package/prod/global/vidstack-player.js +3 -4
- package/prod/providers/vidstack-dash.js +1 -2
- package/prod/providers/vidstack-hls.js +1 -2
- package/prod/providers/vidstack-video.js +1 -2
- package/prod/providers/vidstack-vimeo.js +1 -2
- package/prod/vidstack-elements.js +8 -9
- package/prod/vidstack.js +6 -7
- package/server/chunks/vidstack-B3eA67nX.js +205 -0
- package/server/chunks/vidstack-B8P1aUCK.js +1503 -0
- package/server/chunks/vidstack-B8_v1VQn.js +3059 -0
- package/server/chunks/vidstack-BK4xGWUK.js +207 -0
- package/server/chunks/vidstack-BO8FLks6.js +295 -0
- package/server/chunks/vidstack-BaXvZgx2.js +141 -0
- package/server/chunks/vidstack-BlvJg_5A.js +4636 -0
- package/server/chunks/vidstack-CBhikwSz.js +67 -0
- package/server/chunks/vidstack-COczNXom.js +3059 -0
- package/server/chunks/vidstack-CyZPtpwO.js +1503 -0
- package/server/chunks/vidstack-Db22EuE_.js +207 -0
- package/server/chunks/vidstack-Dh1ZDEI-.js +29 -0
- package/server/chunks/vidstack-Dm-ETAZh.js +295 -0
- package/server/chunks/vidstack-NpAD9hfP.js +620 -0
- package/server/chunks/vidstack-O4BgIcQI.js +104 -0
- package/server/chunks/vidstack-n4zAyLEV.js +2139 -0
- package/server/chunks/vidstack-za5Yh5DQ.js +566 -0
- package/server/chunks/vidstack-zoXyfYxa.js +107 -0
- package/server/define/plyr-layout.js +7 -7
- package/server/define/vidstack-player-default-layout.js +3 -3
- package/server/define/vidstack-player-layouts.js +5 -5
- package/server/define/vidstack-player-ui.js +6 -6
- package/server/define/vidstack-player.js +4 -4
- package/server/global/plyr.js +9 -9
- package/server/global/vidstack-player.js +4 -4
- package/server/vidstack-elements.js +13 -13
- package/server/vidstack.js +8 -8
|
@@ -0,0 +1,1521 @@
|
|
|
1
|
+
import { Component, State, effect, tick, peek, setAttribute, isString, setStyle, createContext, signal, listenEvent, EventsController, provideContext, onDispose, useContext, prop, useState, isNull, functionThrottle, computed, method, scoped, createScope, animationFrameThrottle, functionDebounce, hasProvidedContext, isNumber, isPointerEvent, isTouchEvent, isMouseEvent, DOMEvent, kebabToCamelCase } from './vidstack-C1PwJD_4.js';
|
|
2
|
+
import { useMediaContext } from './vidstack-BjxlZzGu.js';
|
|
3
|
+
import { setAttributeIfEmpty, requestScopedAnimationFrame, autoPlacement, $ariaBool, setARIALabel, isTouchPinchEvent } from './vidstack-C0SWkbs7.js';
|
|
4
|
+
import { formatSpokenTime, Popper, ToggleButtonController, Slider, SliderController, sliderState, sliderValueFormatContext, TimeSlider, RadioGroupController, menuContext, formatTime } from './vidstack-DLXCqdYV.js';
|
|
5
|
+
import { FocusVisibleController, $keyboard } from './vidstack-Bur7I7Vy.js';
|
|
6
|
+
import { round } from './vidstack-Dihypf8P.js';
|
|
7
|
+
import { sortVideoQualities } from './vidstack-BTM4ERc7.js';
|
|
8
|
+
import { watchActiveTextTrack, isCueActive } from './vidstack-CcQdBWil.js';
|
|
9
|
+
import { isTrackCaptionKind } from './vidstack-C3N4zIuV.js';
|
|
10
|
+
|
|
11
|
+
class MediaAnnouncer extends Component {
|
|
12
|
+
static props = {
|
|
13
|
+
translations: null
|
|
14
|
+
};
|
|
15
|
+
static state = new State({
|
|
16
|
+
label: null,
|
|
17
|
+
busy: false
|
|
18
|
+
});
|
|
19
|
+
#media;
|
|
20
|
+
#initializing = false;
|
|
21
|
+
onSetup() {
|
|
22
|
+
this.#media = useMediaContext();
|
|
23
|
+
}
|
|
24
|
+
onAttach(el) {
|
|
25
|
+
el.style.display = "contents";
|
|
26
|
+
}
|
|
27
|
+
onConnect(el) {
|
|
28
|
+
el.setAttribute("data-media-announcer", "");
|
|
29
|
+
setAttributeIfEmpty(el, "role", "status");
|
|
30
|
+
setAttributeIfEmpty(el, "aria-live", "polite");
|
|
31
|
+
const { busy } = this.$state;
|
|
32
|
+
this.setAttributes({
|
|
33
|
+
"aria-busy": () => busy() ? "true" : null
|
|
34
|
+
});
|
|
35
|
+
this.#initializing = true;
|
|
36
|
+
effect(this.#watchPaused.bind(this));
|
|
37
|
+
effect(this.#watchVolume.bind(this));
|
|
38
|
+
effect(this.#watchCaptions.bind(this));
|
|
39
|
+
effect(this.#watchFullscreen.bind(this));
|
|
40
|
+
effect(this.#watchPiP.bind(this));
|
|
41
|
+
effect(this.#watchSeeking.bind(this));
|
|
42
|
+
effect(this.#watchLabel.bind(this));
|
|
43
|
+
tick();
|
|
44
|
+
this.#initializing = false;
|
|
45
|
+
}
|
|
46
|
+
#watchPaused() {
|
|
47
|
+
const { paused } = this.#media.$state;
|
|
48
|
+
this.#setLabel(!paused() ? "Play" : "Pause");
|
|
49
|
+
}
|
|
50
|
+
#watchFullscreen() {
|
|
51
|
+
const { fullscreen } = this.#media.$state;
|
|
52
|
+
this.#setLabel(fullscreen() ? "Enter Fullscreen" : "Exit Fullscreen");
|
|
53
|
+
}
|
|
54
|
+
#watchPiP() {
|
|
55
|
+
const { pictureInPicture } = this.#media.$state;
|
|
56
|
+
this.#setLabel(pictureInPicture() ? "Enter PiP" : "Exit PiP");
|
|
57
|
+
}
|
|
58
|
+
#watchCaptions() {
|
|
59
|
+
const { textTrack } = this.#media.$state;
|
|
60
|
+
this.#setLabel(textTrack() ? "Closed-Captions On" : "Closed-Captions Off");
|
|
61
|
+
}
|
|
62
|
+
#watchVolume() {
|
|
63
|
+
const { muted, volume, audioGain } = this.#media.$state;
|
|
64
|
+
this.#setLabel(
|
|
65
|
+
muted() || volume() === 0 ? "Mute" : `${Math.round(volume() * (audioGain() ?? 1) * 100)}% ${this.#translate("Volume")}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
#startedSeekingAt = -1;
|
|
69
|
+
#seekTimer = -1;
|
|
70
|
+
#watchSeeking() {
|
|
71
|
+
const { seeking, currentTime } = this.#media.$state, isSeeking = seeking();
|
|
72
|
+
if (this.#startedSeekingAt > 0) {
|
|
73
|
+
window.clearTimeout(this.#seekTimer);
|
|
74
|
+
this.#seekTimer = window.setTimeout(() => {
|
|
75
|
+
if (!this.scope) return;
|
|
76
|
+
const newTime = peek(currentTime), seconds = Math.abs(newTime - this.#startedSeekingAt);
|
|
77
|
+
if (seconds >= 1) {
|
|
78
|
+
const isForward = newTime >= this.#startedSeekingAt, spokenTime = formatSpokenTime(seconds);
|
|
79
|
+
this.#setLabel(
|
|
80
|
+
`${this.#translate(isForward ? "Seek Forward" : "Seek Backward")} ${spokenTime}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
this.#startedSeekingAt = -1;
|
|
84
|
+
this.#seekTimer = -1;
|
|
85
|
+
}, 300);
|
|
86
|
+
} else if (isSeeking) {
|
|
87
|
+
this.#startedSeekingAt = peek(currentTime);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
#translate(word) {
|
|
91
|
+
const { translations } = this.$props;
|
|
92
|
+
return translations?.()?.[word || ""] ?? word;
|
|
93
|
+
}
|
|
94
|
+
#watchLabel() {
|
|
95
|
+
const { label, busy } = this.$state, $label = this.#translate(label());
|
|
96
|
+
if (this.#initializing) return;
|
|
97
|
+
busy.set(true);
|
|
98
|
+
const id = window.setTimeout(() => void busy.set(false), 150);
|
|
99
|
+
this.el && setAttribute(this.el, "aria-label", $label);
|
|
100
|
+
if (isString($label)) {
|
|
101
|
+
this.dispatch("change", { detail: $label });
|
|
102
|
+
}
|
|
103
|
+
return () => window.clearTimeout(id);
|
|
104
|
+
}
|
|
105
|
+
#setLabel(word) {
|
|
106
|
+
const { label } = this.$state;
|
|
107
|
+
label.set(word);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class Controls extends Component {
|
|
112
|
+
static props = {
|
|
113
|
+
hideDelay: 2e3,
|
|
114
|
+
hideOnMouseLeave: false
|
|
115
|
+
};
|
|
116
|
+
#media;
|
|
117
|
+
onSetup() {
|
|
118
|
+
this.#media = useMediaContext();
|
|
119
|
+
effect(this.#watchProps.bind(this));
|
|
120
|
+
}
|
|
121
|
+
onAttach(el) {
|
|
122
|
+
const { pictureInPicture, fullscreen } = this.#media.$state;
|
|
123
|
+
setStyle(el, "pointer-events", "none");
|
|
124
|
+
setAttributeIfEmpty(el, "role", "group");
|
|
125
|
+
this.setAttributes({
|
|
126
|
+
"data-visible": this.#isShowing.bind(this),
|
|
127
|
+
"data-fullscreen": fullscreen,
|
|
128
|
+
"data-pip": pictureInPicture
|
|
129
|
+
});
|
|
130
|
+
effect(() => {
|
|
131
|
+
this.dispatch("change", { detail: this.#isShowing() });
|
|
132
|
+
});
|
|
133
|
+
effect(this.#hideControls.bind(this));
|
|
134
|
+
effect(() => {
|
|
135
|
+
const isFullscreen = fullscreen();
|
|
136
|
+
for (const side of ["top", "right", "bottom", "left"]) {
|
|
137
|
+
setStyle(el, `padding-${side}`, isFullscreen && `env(safe-area-inset-${side})`);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
#hideControls() {
|
|
142
|
+
if (!this.el) return;
|
|
143
|
+
const { nativeControls } = this.#media.$state, isHidden = nativeControls();
|
|
144
|
+
setAttribute(this.el, "aria-hidden", isHidden ? "true" : null);
|
|
145
|
+
setStyle(this.el, "display", isHidden ? "none" : null);
|
|
146
|
+
}
|
|
147
|
+
#watchProps() {
|
|
148
|
+
const { controls } = this.#media.player, { hideDelay, hideOnMouseLeave } = this.$props;
|
|
149
|
+
controls.defaultDelay = hideDelay() === 2e3 ? this.#media.$props.controlsDelay() : hideDelay();
|
|
150
|
+
controls.hideOnMouseLeave = hideOnMouseLeave();
|
|
151
|
+
}
|
|
152
|
+
#isShowing() {
|
|
153
|
+
const { controlsVisible } = this.#media.$state;
|
|
154
|
+
return controlsVisible();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class ControlsGroup extends Component {
|
|
159
|
+
onAttach(el) {
|
|
160
|
+
if (!el.style.pointerEvents) setStyle(el, "pointer-events", "auto");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const tooltipContext = createContext();
|
|
165
|
+
|
|
166
|
+
let id = 0;
|
|
167
|
+
class Tooltip extends Component {
|
|
168
|
+
static props = {
|
|
169
|
+
showDelay: 700
|
|
170
|
+
};
|
|
171
|
+
#id = `media-tooltip-${++id}`;
|
|
172
|
+
#trigger = signal(null);
|
|
173
|
+
#content = signal(null);
|
|
174
|
+
#showing = signal(false);
|
|
175
|
+
constructor() {
|
|
176
|
+
super();
|
|
177
|
+
new FocusVisibleController();
|
|
178
|
+
const { showDelay } = this.$props;
|
|
179
|
+
new Popper({
|
|
180
|
+
trigger: this.#trigger,
|
|
181
|
+
content: this.#content,
|
|
182
|
+
showDelay,
|
|
183
|
+
listen(trigger, show, hide) {
|
|
184
|
+
effect(() => {
|
|
185
|
+
if ($keyboard()) listenEvent(trigger, "focus", show);
|
|
186
|
+
listenEvent(trigger, "blur", hide);
|
|
187
|
+
});
|
|
188
|
+
new EventsController(trigger).add("touchstart", (e) => e.preventDefault(), { passive: false }).add("mouseenter", show).add("mouseleave", hide);
|
|
189
|
+
},
|
|
190
|
+
onChange: this.#onShowingChange.bind(this)
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
onAttach(el) {
|
|
194
|
+
el.style.setProperty("display", "contents");
|
|
195
|
+
}
|
|
196
|
+
onSetup() {
|
|
197
|
+
provideContext(tooltipContext, {
|
|
198
|
+
trigger: this.#trigger,
|
|
199
|
+
content: this.#content,
|
|
200
|
+
showing: this.#showing,
|
|
201
|
+
attachTrigger: this.#attachTrigger.bind(this),
|
|
202
|
+
detachTrigger: this.#detachTrigger.bind(this),
|
|
203
|
+
attachContent: this.#attachContent.bind(this),
|
|
204
|
+
detachContent: this.#detachContent.bind(this)
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
#attachTrigger(el) {
|
|
208
|
+
this.#trigger.set(el);
|
|
209
|
+
let tooltipName = el.getAttribute("data-media-tooltip");
|
|
210
|
+
if (tooltipName) {
|
|
211
|
+
this.el?.setAttribute(`data-media-${tooltipName}-tooltip`, "");
|
|
212
|
+
}
|
|
213
|
+
setAttribute(el, "data-describedby", this.#id);
|
|
214
|
+
}
|
|
215
|
+
#detachTrigger(el) {
|
|
216
|
+
el.removeAttribute("data-describedby");
|
|
217
|
+
el.removeAttribute("aria-describedby");
|
|
218
|
+
this.#trigger.set(null);
|
|
219
|
+
}
|
|
220
|
+
#attachContent(el) {
|
|
221
|
+
el.setAttribute("id", this.#id);
|
|
222
|
+
el.style.display = "none";
|
|
223
|
+
setAttributeIfEmpty(el, "role", "tooltip");
|
|
224
|
+
this.#content.set(el);
|
|
225
|
+
}
|
|
226
|
+
#detachContent(el) {
|
|
227
|
+
el.removeAttribute("id");
|
|
228
|
+
el.removeAttribute("role");
|
|
229
|
+
this.#content.set(null);
|
|
230
|
+
}
|
|
231
|
+
#onShowingChange(isShowing) {
|
|
232
|
+
const trigger = this.#trigger(), content = this.#content();
|
|
233
|
+
if (trigger) {
|
|
234
|
+
setAttribute(trigger, "aria-describedby", isShowing ? this.#id : null);
|
|
235
|
+
}
|
|
236
|
+
for (const el of [this.el, trigger, content]) {
|
|
237
|
+
el && setAttribute(el, "data-visible", isShowing);
|
|
238
|
+
}
|
|
239
|
+
this.#showing.set(isShowing);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
class TooltipTrigger extends Component {
|
|
244
|
+
constructor() {
|
|
245
|
+
super();
|
|
246
|
+
new FocusVisibleController();
|
|
247
|
+
}
|
|
248
|
+
onConnect(el) {
|
|
249
|
+
onDispose(
|
|
250
|
+
requestScopedAnimationFrame(() => {
|
|
251
|
+
if (!this.connectScope) return;
|
|
252
|
+
this.#attach();
|
|
253
|
+
const tooltip = useContext(tooltipContext);
|
|
254
|
+
onDispose(() => {
|
|
255
|
+
const button = this.#getButton();
|
|
256
|
+
button && tooltip.detachTrigger(button);
|
|
257
|
+
});
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
#attach() {
|
|
262
|
+
const button = this.#getButton(), tooltip = useContext(tooltipContext);
|
|
263
|
+
button && tooltip.attachTrigger(button);
|
|
264
|
+
}
|
|
265
|
+
#getButton() {
|
|
266
|
+
const candidate = this.el.firstElementChild;
|
|
267
|
+
return candidate?.localName === "button" || candidate?.getAttribute("role") === "button" ? candidate : this.el;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
class TooltipContent extends Component {
|
|
272
|
+
static props = {
|
|
273
|
+
placement: "top center",
|
|
274
|
+
offset: 0,
|
|
275
|
+
alignOffset: 0
|
|
276
|
+
};
|
|
277
|
+
constructor() {
|
|
278
|
+
super();
|
|
279
|
+
new FocusVisibleController();
|
|
280
|
+
const { placement } = this.$props;
|
|
281
|
+
this.setAttributes({
|
|
282
|
+
"data-placement": placement
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
onAttach(el) {
|
|
286
|
+
this.#attach(el);
|
|
287
|
+
Object.assign(el.style, {
|
|
288
|
+
position: "absolute",
|
|
289
|
+
top: 0,
|
|
290
|
+
left: 0,
|
|
291
|
+
width: "max-content"
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
onConnect(el) {
|
|
295
|
+
this.#attach(el);
|
|
296
|
+
const tooltip = useContext(tooltipContext);
|
|
297
|
+
onDispose(() => tooltip.detachContent(el));
|
|
298
|
+
onDispose(
|
|
299
|
+
requestScopedAnimationFrame(() => {
|
|
300
|
+
if (!this.connectScope) return;
|
|
301
|
+
effect(this.#watchPlacement.bind(this));
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
#attach(el) {
|
|
306
|
+
const tooltip = useContext(tooltipContext);
|
|
307
|
+
tooltip.attachContent(el);
|
|
308
|
+
}
|
|
309
|
+
#watchPlacement() {
|
|
310
|
+
const { showing } = useContext(tooltipContext);
|
|
311
|
+
if (!showing()) return;
|
|
312
|
+
const { placement, offset: mainOffset, alignOffset } = this.$props;
|
|
313
|
+
return autoPlacement(this.el, this.#getTrigger(), placement(), {
|
|
314
|
+
offsetVarName: "media-tooltip",
|
|
315
|
+
xOffset: alignOffset(),
|
|
316
|
+
yOffset: mainOffset()
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
#getTrigger() {
|
|
320
|
+
return useContext(tooltipContext).trigger();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
class ToggleButton extends Component {
|
|
325
|
+
static props = {
|
|
326
|
+
disabled: false,
|
|
327
|
+
defaultPressed: false
|
|
328
|
+
};
|
|
329
|
+
#pressed = signal(false);
|
|
330
|
+
/**
|
|
331
|
+
* Whether the toggle is currently in a `pressed` state.
|
|
332
|
+
*/
|
|
333
|
+
get pressed() {
|
|
334
|
+
return this.#pressed();
|
|
335
|
+
}
|
|
336
|
+
constructor() {
|
|
337
|
+
super();
|
|
338
|
+
new ToggleButtonController({
|
|
339
|
+
isPresssed: this.#pressed
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const togglebutton__proto = ToggleButton.prototype;
|
|
344
|
+
prop(togglebutton__proto, "pressed");
|
|
345
|
+
|
|
346
|
+
class GoogleCastButton extends Component {
|
|
347
|
+
static props = ToggleButtonController.props;
|
|
348
|
+
#media;
|
|
349
|
+
constructor() {
|
|
350
|
+
super();
|
|
351
|
+
new ToggleButtonController({
|
|
352
|
+
isPresssed: this.#isPressed.bind(this),
|
|
353
|
+
onPress: this.#onPress.bind(this)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
onSetup() {
|
|
357
|
+
this.#media = useMediaContext();
|
|
358
|
+
const { canGoogleCast, isGoogleCastConnected } = this.#media.$state;
|
|
359
|
+
this.setAttributes({
|
|
360
|
+
"data-active": isGoogleCastConnected,
|
|
361
|
+
"data-supported": canGoogleCast,
|
|
362
|
+
"data-state": this.#getState.bind(this),
|
|
363
|
+
"aria-hidden": $ariaBool(() => !canGoogleCast())
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
onAttach(el) {
|
|
367
|
+
el.setAttribute("data-media-tooltip", "google-cast");
|
|
368
|
+
setARIALabel(el, this.#getDefaultLabel.bind(this));
|
|
369
|
+
}
|
|
370
|
+
#onPress(event) {
|
|
371
|
+
const remote = this.#media.remote;
|
|
372
|
+
remote.requestGoogleCast(event);
|
|
373
|
+
}
|
|
374
|
+
#isPressed() {
|
|
375
|
+
const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
|
|
376
|
+
return remotePlaybackType() === "google-cast" && remotePlaybackState() !== "disconnected";
|
|
377
|
+
}
|
|
378
|
+
#getState() {
|
|
379
|
+
const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
|
|
380
|
+
return remotePlaybackType() === "google-cast" && remotePlaybackState();
|
|
381
|
+
}
|
|
382
|
+
#getDefaultLabel() {
|
|
383
|
+
const { remotePlaybackState } = this.#media.$state;
|
|
384
|
+
return `Google Cast ${remotePlaybackState()}`;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
class SliderVideo extends Component {
|
|
389
|
+
static props = {
|
|
390
|
+
src: null,
|
|
391
|
+
crossOrigin: null
|
|
392
|
+
};
|
|
393
|
+
static state = new State({
|
|
394
|
+
video: null,
|
|
395
|
+
src: null,
|
|
396
|
+
crossOrigin: null,
|
|
397
|
+
canPlay: false,
|
|
398
|
+
error: null,
|
|
399
|
+
hidden: false
|
|
400
|
+
});
|
|
401
|
+
#media;
|
|
402
|
+
#slider;
|
|
403
|
+
get video() {
|
|
404
|
+
return this.$state.video();
|
|
405
|
+
}
|
|
406
|
+
onSetup() {
|
|
407
|
+
this.#media = useMediaContext();
|
|
408
|
+
this.#slider = useState(Slider.state);
|
|
409
|
+
this.#watchCrossOrigin();
|
|
410
|
+
this.setAttributes({
|
|
411
|
+
"data-loading": this.#isLoading.bind(this),
|
|
412
|
+
"data-hidden": this.$state.hidden,
|
|
413
|
+
"data-error": this.#hasError.bind(this),
|
|
414
|
+
"aria-hidden": $ariaBool(this.$state.hidden)
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
onAttach(el) {
|
|
418
|
+
effect(this.#watchVideo.bind(this));
|
|
419
|
+
effect(this.#watchSrc.bind(this));
|
|
420
|
+
effect(this.#watchCrossOrigin.bind(this));
|
|
421
|
+
effect(this.#watchHidden.bind(this));
|
|
422
|
+
effect(this.#onSrcChange.bind(this));
|
|
423
|
+
effect(this.#onUpdateTime.bind(this));
|
|
424
|
+
}
|
|
425
|
+
#watchVideo() {
|
|
426
|
+
const video = this.$state.video();
|
|
427
|
+
if (!video) return;
|
|
428
|
+
if (video.readyState >= 2) this.#onCanPlay();
|
|
429
|
+
new EventsController(video).add("canplay", this.#onCanPlay.bind(this)).add("error", this.#onError.bind(this));
|
|
430
|
+
}
|
|
431
|
+
#watchSrc() {
|
|
432
|
+
const { src } = this.$state, { canLoad } = this.#media.$state;
|
|
433
|
+
src.set(canLoad() ? this.$props.src() : null);
|
|
434
|
+
}
|
|
435
|
+
#watchCrossOrigin() {
|
|
436
|
+
const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin } = this.#media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
|
|
437
|
+
crossOriginState.set(crossOrigin === true ? "anonymous" : crossOrigin);
|
|
438
|
+
}
|
|
439
|
+
#isLoading() {
|
|
440
|
+
const { canPlay, hidden } = this.$state;
|
|
441
|
+
return !canPlay() && !hidden();
|
|
442
|
+
}
|
|
443
|
+
#hasError() {
|
|
444
|
+
const { error } = this.$state;
|
|
445
|
+
return !isNull(error);
|
|
446
|
+
}
|
|
447
|
+
#watchHidden() {
|
|
448
|
+
const { src, hidden } = this.$state, { canLoad, duration } = this.#media.$state;
|
|
449
|
+
hidden.set(canLoad() && (!src() || this.#hasError() || !Number.isFinite(duration())));
|
|
450
|
+
}
|
|
451
|
+
#onSrcChange() {
|
|
452
|
+
const { src, canPlay, error } = this.$state;
|
|
453
|
+
src();
|
|
454
|
+
canPlay.set(false);
|
|
455
|
+
error.set(null);
|
|
456
|
+
}
|
|
457
|
+
#onCanPlay(event) {
|
|
458
|
+
const { canPlay, error } = this.$state;
|
|
459
|
+
canPlay.set(true);
|
|
460
|
+
error.set(null);
|
|
461
|
+
this.dispatch("can-play", { trigger: event });
|
|
462
|
+
}
|
|
463
|
+
#onError(event) {
|
|
464
|
+
const { canPlay, error } = this.$state;
|
|
465
|
+
canPlay.set(false);
|
|
466
|
+
error.set(event);
|
|
467
|
+
this.dispatch("error", { trigger: event });
|
|
468
|
+
}
|
|
469
|
+
#onUpdateTime() {
|
|
470
|
+
const { video, canPlay } = this.$state, { duration } = this.#media.$state, { pointerRate } = this.#slider, media = video(), canUpdate = canPlay() && media && Number.isFinite(duration()) && Number.isFinite(pointerRate());
|
|
471
|
+
if (canUpdate) {
|
|
472
|
+
media.currentTime = pointerRate() * duration();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
const slidervideo__proto = SliderVideo.prototype;
|
|
477
|
+
prop(slidervideo__proto, "video");
|
|
478
|
+
|
|
479
|
+
class AudioGainSlider extends Component {
|
|
480
|
+
static props = {
|
|
481
|
+
...SliderController.props,
|
|
482
|
+
step: 25,
|
|
483
|
+
keyStep: 25,
|
|
484
|
+
shiftKeyMultiplier: 2,
|
|
485
|
+
min: 0,
|
|
486
|
+
max: 300
|
|
487
|
+
};
|
|
488
|
+
static state = sliderState;
|
|
489
|
+
#media;
|
|
490
|
+
onSetup() {
|
|
491
|
+
this.#media = useMediaContext();
|
|
492
|
+
provideContext(sliderValueFormatContext, {
|
|
493
|
+
default: "percent",
|
|
494
|
+
percent: (_, decimalPlaces) => {
|
|
495
|
+
return round(this.$state.value(), decimalPlaces) + "%";
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
new SliderController({
|
|
499
|
+
getStep: this.$props.step,
|
|
500
|
+
getKeyStep: this.$props.keyStep,
|
|
501
|
+
roundValue: Math.round,
|
|
502
|
+
isDisabled: this.#isDisabled.bind(this),
|
|
503
|
+
aria: {
|
|
504
|
+
valueNow: this.#getARIAValueNow.bind(this),
|
|
505
|
+
valueText: this.#getARIAValueText.bind(this)
|
|
506
|
+
},
|
|
507
|
+
onDragValueChange: this.#onDragValueChange.bind(this),
|
|
508
|
+
onValueChange: this.#onValueChange.bind(this)
|
|
509
|
+
}).attach(this);
|
|
510
|
+
effect(this.#watchMinMax.bind(this));
|
|
511
|
+
effect(this.#watchAudioGain.bind(this));
|
|
512
|
+
}
|
|
513
|
+
onAttach(el) {
|
|
514
|
+
el.setAttribute("data-media-audio-gain-slider", "");
|
|
515
|
+
setAttributeIfEmpty(el, "aria-label", "Audio Boost");
|
|
516
|
+
const { canSetAudioGain } = this.#media.$state;
|
|
517
|
+
this.setAttributes({
|
|
518
|
+
"data-supported": canSetAudioGain,
|
|
519
|
+
"aria-hidden": $ariaBool(() => !canSetAudioGain())
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
#getARIAValueNow() {
|
|
523
|
+
const { value } = this.$state;
|
|
524
|
+
return Math.round(value());
|
|
525
|
+
}
|
|
526
|
+
#getARIAValueText() {
|
|
527
|
+
const { value } = this.$state;
|
|
528
|
+
return value() + "%";
|
|
529
|
+
}
|
|
530
|
+
#watchMinMax() {
|
|
531
|
+
const { min, max } = this.$props;
|
|
532
|
+
this.$state.min.set(min());
|
|
533
|
+
this.$state.max.set(max());
|
|
534
|
+
}
|
|
535
|
+
#watchAudioGain() {
|
|
536
|
+
const { audioGain } = this.#media.$state, value = ((audioGain() ?? 1) - 1) * 100;
|
|
537
|
+
this.$state.value.set(value);
|
|
538
|
+
this.dispatch("value-change", { detail: value });
|
|
539
|
+
}
|
|
540
|
+
#isDisabled() {
|
|
541
|
+
const { disabled } = this.$props, { canSetAudioGain } = this.#media.$state;
|
|
542
|
+
return disabled() || !canSetAudioGain();
|
|
543
|
+
}
|
|
544
|
+
#onAudioGainChange(event) {
|
|
545
|
+
if (!event.trigger) return;
|
|
546
|
+
const gain = round(1 + event.detail / 100, 2);
|
|
547
|
+
this.#media.remote.changeAudioGain(gain, event);
|
|
548
|
+
}
|
|
549
|
+
#onValueChange(event) {
|
|
550
|
+
this.#onAudioGainChange(event);
|
|
551
|
+
}
|
|
552
|
+
#onDragValueChange(event) {
|
|
553
|
+
this.#onAudioGainChange(event);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
class SpeedSlider extends Component {
|
|
558
|
+
static props = {
|
|
559
|
+
...SliderController.props,
|
|
560
|
+
step: 0.25,
|
|
561
|
+
keyStep: 0.25,
|
|
562
|
+
shiftKeyMultiplier: 2,
|
|
563
|
+
min: 0,
|
|
564
|
+
max: 2
|
|
565
|
+
};
|
|
566
|
+
static state = sliderState;
|
|
567
|
+
#media;
|
|
568
|
+
onSetup() {
|
|
569
|
+
this.#media = useMediaContext();
|
|
570
|
+
new SliderController({
|
|
571
|
+
getStep: this.$props.step,
|
|
572
|
+
getKeyStep: this.$props.keyStep,
|
|
573
|
+
roundValue: this.#roundValue,
|
|
574
|
+
isDisabled: this.#isDisabled.bind(this),
|
|
575
|
+
aria: {
|
|
576
|
+
valueNow: this.#getARIAValueNow.bind(this),
|
|
577
|
+
valueText: this.#getARIAValueText.bind(this)
|
|
578
|
+
},
|
|
579
|
+
onDragValueChange: this.#onDragValueChange.bind(this),
|
|
580
|
+
onValueChange: this.#onValueChange.bind(this)
|
|
581
|
+
}).attach(this);
|
|
582
|
+
effect(this.#watchMinMax.bind(this));
|
|
583
|
+
effect(this.#watchPlaybackRate.bind(this));
|
|
584
|
+
}
|
|
585
|
+
onAttach(el) {
|
|
586
|
+
el.setAttribute("data-media-speed-slider", "");
|
|
587
|
+
setAttributeIfEmpty(el, "aria-label", "Speed");
|
|
588
|
+
const { canSetPlaybackRate } = this.#media.$state;
|
|
589
|
+
this.setAttributes({
|
|
590
|
+
"data-supported": canSetPlaybackRate,
|
|
591
|
+
"aria-hidden": $ariaBool(() => !canSetPlaybackRate())
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
#getARIAValueNow() {
|
|
595
|
+
const { value } = this.$state;
|
|
596
|
+
return value();
|
|
597
|
+
}
|
|
598
|
+
#getARIAValueText() {
|
|
599
|
+
const { value } = this.$state;
|
|
600
|
+
return value() + "x";
|
|
601
|
+
}
|
|
602
|
+
#watchMinMax() {
|
|
603
|
+
const { min, max } = this.$props;
|
|
604
|
+
this.$state.min.set(min());
|
|
605
|
+
this.$state.max.set(max());
|
|
606
|
+
}
|
|
607
|
+
#watchPlaybackRate() {
|
|
608
|
+
const { playbackRate } = this.#media.$state;
|
|
609
|
+
const newValue = playbackRate();
|
|
610
|
+
this.$state.value.set(newValue);
|
|
611
|
+
this.dispatch("value-change", { detail: newValue });
|
|
612
|
+
}
|
|
613
|
+
#roundValue(value) {
|
|
614
|
+
return round(value, 2);
|
|
615
|
+
}
|
|
616
|
+
#isDisabled() {
|
|
617
|
+
const { disabled } = this.$props, { canSetPlaybackRate } = this.#media.$state;
|
|
618
|
+
return disabled() || !canSetPlaybackRate();
|
|
619
|
+
}
|
|
620
|
+
#throttledSpeedChange = functionThrottle(this.#onPlaybackRateChange.bind(this), 25);
|
|
621
|
+
#onPlaybackRateChange(event) {
|
|
622
|
+
if (!event.trigger) return;
|
|
623
|
+
const rate = event.detail;
|
|
624
|
+
this.#media.remote.changePlaybackRate(rate, event);
|
|
625
|
+
}
|
|
626
|
+
#onValueChange(event) {
|
|
627
|
+
this.#throttledSpeedChange(event);
|
|
628
|
+
}
|
|
629
|
+
#onDragValueChange(event) {
|
|
630
|
+
this.#throttledSpeedChange(event);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
class QualitySlider extends Component {
|
|
635
|
+
static props = {
|
|
636
|
+
...SliderController.props,
|
|
637
|
+
step: 1,
|
|
638
|
+
keyStep: 1,
|
|
639
|
+
shiftKeyMultiplier: 1
|
|
640
|
+
};
|
|
641
|
+
static state = sliderState;
|
|
642
|
+
#media;
|
|
643
|
+
#sortedQualities = computed(() => {
|
|
644
|
+
const { qualities } = this.#media.$state;
|
|
645
|
+
return sortVideoQualities(qualities());
|
|
646
|
+
});
|
|
647
|
+
onSetup() {
|
|
648
|
+
this.#media = useMediaContext();
|
|
649
|
+
new SliderController({
|
|
650
|
+
getStep: this.$props.step,
|
|
651
|
+
getKeyStep: this.$props.keyStep,
|
|
652
|
+
roundValue: Math.round,
|
|
653
|
+
isDisabled: this.#isDisabled.bind(this),
|
|
654
|
+
aria: {
|
|
655
|
+
valueNow: this.#getARIAValueNow.bind(this),
|
|
656
|
+
valueText: this.#getARIAValueText.bind(this)
|
|
657
|
+
},
|
|
658
|
+
onDragValueChange: this.#onDragValueChange.bind(this),
|
|
659
|
+
onValueChange: this.#onValueChange.bind(this)
|
|
660
|
+
}).attach(this);
|
|
661
|
+
effect(this.#watchMax.bind(this));
|
|
662
|
+
effect(this.#watchQuality.bind(this));
|
|
663
|
+
}
|
|
664
|
+
onAttach(el) {
|
|
665
|
+
el.setAttribute("data-media-quality-slider", "");
|
|
666
|
+
setAttributeIfEmpty(el, "aria-label", "Video Quality");
|
|
667
|
+
const { qualities, canSetQuality } = this.#media.$state, $supported = computed(() => canSetQuality() && qualities().length > 0);
|
|
668
|
+
this.setAttributes({
|
|
669
|
+
"data-supported": $supported,
|
|
670
|
+
"aria-hidden": $ariaBool(() => !$supported())
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
#getARIAValueNow() {
|
|
674
|
+
const { value } = this.$state;
|
|
675
|
+
return value();
|
|
676
|
+
}
|
|
677
|
+
#getARIAValueText() {
|
|
678
|
+
const { quality } = this.#media.$state;
|
|
679
|
+
if (!quality()) return "";
|
|
680
|
+
const { height, bitrate, label } = quality(), bitrateText = bitrate && bitrate > 0 ? `${(bitrate / 1e6).toFixed(2)} Mbps` : null;
|
|
681
|
+
const rootText = label ?? (height ? `${height}p` : "");
|
|
682
|
+
return rootText ? `${rootText}${bitrateText ? ` (${bitrateText})` : ""}` : "Auto";
|
|
683
|
+
}
|
|
684
|
+
#watchMax() {
|
|
685
|
+
const $qualities = this.#sortedQualities();
|
|
686
|
+
this.$state.max.set(Math.max(0, $qualities.length - 1));
|
|
687
|
+
}
|
|
688
|
+
#watchQuality() {
|
|
689
|
+
let { quality } = this.#media.$state, $qualities = this.#sortedQualities(), value = Math.max(0, $qualities.indexOf(quality()));
|
|
690
|
+
this.$state.value.set(value);
|
|
691
|
+
this.dispatch("value-change", { detail: value });
|
|
692
|
+
}
|
|
693
|
+
#isDisabled() {
|
|
694
|
+
const { disabled } = this.$props, { canSetQuality, qualities } = this.#media.$state;
|
|
695
|
+
return disabled() || qualities().length <= 1 || !canSetQuality();
|
|
696
|
+
}
|
|
697
|
+
#throttledQualityChange = functionThrottle(this.#onQualityChange.bind(this), 25);
|
|
698
|
+
#onQualityChange(event) {
|
|
699
|
+
if (!event.trigger) return;
|
|
700
|
+
const { qualities } = this.#media, quality = peek(this.#sortedQualities)[event.detail];
|
|
701
|
+
this.#media.remote.changeQuality(qualities.indexOf(quality), event);
|
|
702
|
+
}
|
|
703
|
+
#onValueChange(event) {
|
|
704
|
+
this.#throttledQualityChange(event);
|
|
705
|
+
}
|
|
706
|
+
#onDragValueChange(event) {
|
|
707
|
+
this.#throttledQualityChange(event);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
class SliderChapters extends Component {
|
|
712
|
+
static props = {
|
|
713
|
+
disabled: false
|
|
714
|
+
};
|
|
715
|
+
#media;
|
|
716
|
+
#sliderState;
|
|
717
|
+
#updateScope;
|
|
718
|
+
#titleRef = null;
|
|
719
|
+
#refs = [];
|
|
720
|
+
#$track = signal(null);
|
|
721
|
+
#$cues = signal([]);
|
|
722
|
+
#activeIndex = signal(-1);
|
|
723
|
+
#activePointerIndex = signal(-1);
|
|
724
|
+
#bufferedIndex = 0;
|
|
725
|
+
get cues() {
|
|
726
|
+
return this.#$cues();
|
|
727
|
+
}
|
|
728
|
+
get activeCue() {
|
|
729
|
+
return this.#$cues()[this.#activeIndex()] || null;
|
|
730
|
+
}
|
|
731
|
+
get activePointerCue() {
|
|
732
|
+
return this.#$cues()[this.#activePointerIndex()] || null;
|
|
733
|
+
}
|
|
734
|
+
onSetup() {
|
|
735
|
+
this.#media = useMediaContext();
|
|
736
|
+
this.#sliderState = useState(TimeSlider.state);
|
|
737
|
+
}
|
|
738
|
+
onAttach(el) {
|
|
739
|
+
watchActiveTextTrack(this.#media.textTracks, "chapters", this.#setTrack.bind(this));
|
|
740
|
+
effect(this.#watchSource.bind(this));
|
|
741
|
+
}
|
|
742
|
+
onConnect() {
|
|
743
|
+
onDispose(() => this.#reset.bind(this));
|
|
744
|
+
}
|
|
745
|
+
onDestroy() {
|
|
746
|
+
this.#setTrack(null);
|
|
747
|
+
}
|
|
748
|
+
setRefs(refs) {
|
|
749
|
+
this.#refs = refs;
|
|
750
|
+
this.#updateScope?.dispose();
|
|
751
|
+
if (this.#refs.length === 1) {
|
|
752
|
+
const el = this.#refs[0];
|
|
753
|
+
el.style.width = "100%";
|
|
754
|
+
el.style.setProperty("--chapter-fill", "var(--slider-fill)");
|
|
755
|
+
el.style.setProperty("--chapter-progress", "var(--slider-progress)");
|
|
756
|
+
} else if (this.#refs.length > 0) {
|
|
757
|
+
scoped(() => this.#watch(), this.#updateScope = createScope());
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
#setTrack(track) {
|
|
761
|
+
if (peek(this.#$track) === track) return;
|
|
762
|
+
this.#reset();
|
|
763
|
+
this.#$track.set(track);
|
|
764
|
+
}
|
|
765
|
+
#reset() {
|
|
766
|
+
this.#refs = [];
|
|
767
|
+
this.#$cues.set([]);
|
|
768
|
+
this.#activeIndex.set(-1);
|
|
769
|
+
this.#activePointerIndex.set(-1);
|
|
770
|
+
this.#bufferedIndex = 0;
|
|
771
|
+
this.#updateScope?.dispose();
|
|
772
|
+
}
|
|
773
|
+
#watch() {
|
|
774
|
+
if (!this.#refs.length) return;
|
|
775
|
+
effect(this.#watchUpdates.bind(this));
|
|
776
|
+
}
|
|
777
|
+
#watchUpdates() {
|
|
778
|
+
const { hidden } = this.#sliderState;
|
|
779
|
+
if (hidden()) return;
|
|
780
|
+
effect(this.#watchContainerWidths.bind(this));
|
|
781
|
+
effect(this.#watchFillPercent.bind(this));
|
|
782
|
+
effect(this.#watchPointerPercent.bind(this));
|
|
783
|
+
effect(this.#watchBufferedPercent.bind(this));
|
|
784
|
+
}
|
|
785
|
+
#watchContainerWidths() {
|
|
786
|
+
const cues = this.#$cues();
|
|
787
|
+
if (!cues.length) return;
|
|
788
|
+
let cue, { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd() || cues[cues.length - 1].endTime, duration = endTime - startTime, remainingWidth = 100;
|
|
789
|
+
for (let i = 0; i < cues.length; i++) {
|
|
790
|
+
cue = cues[i];
|
|
791
|
+
if (this.#refs[i]) {
|
|
792
|
+
const width = i === cues.length - 1 ? remainingWidth : round((cue.endTime - Math.max(startTime, cue.startTime)) / duration * 100, 3);
|
|
793
|
+
this.#refs[i].style.width = width + "%";
|
|
794
|
+
remainingWidth -= width;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
#watchFillPercent() {
|
|
799
|
+
let { liveEdge, seekableStart, seekableEnd } = this.#media.$state, { fillPercent, value } = this.#sliderState, cues = this.#$cues(), isLiveEdge = liveEdge(), prevActiveIndex = peek(this.#activeIndex), currentChapter = cues[prevActiveIndex];
|
|
800
|
+
let currentActiveIndex = isLiveEdge ? this.#$cues.length - 1 : this.#findActiveChapterIndex(
|
|
801
|
+
currentChapter ? currentChapter.startTime / seekableEnd() * 100 <= peek(value) ? prevActiveIndex : 0 : 0,
|
|
802
|
+
fillPercent()
|
|
803
|
+
);
|
|
804
|
+
if (isLiveEdge || !currentChapter) {
|
|
805
|
+
this.#updateFillPercents(0, cues.length, 100);
|
|
806
|
+
} else if (currentActiveIndex > prevActiveIndex) {
|
|
807
|
+
this.#updateFillPercents(prevActiveIndex, currentActiveIndex, 100);
|
|
808
|
+
} else if (currentActiveIndex < prevActiveIndex) {
|
|
809
|
+
this.#updateFillPercents(currentActiveIndex + 1, prevActiveIndex + 1, 0);
|
|
810
|
+
}
|
|
811
|
+
const percent = isLiveEdge ? 100 : this.#calcPercent(
|
|
812
|
+
cues[currentActiveIndex],
|
|
813
|
+
fillPercent(),
|
|
814
|
+
seekableStart(),
|
|
815
|
+
this.#getEndTime(cues)
|
|
816
|
+
);
|
|
817
|
+
this.#updateFillPercent(this.#refs[currentActiveIndex], percent);
|
|
818
|
+
this.#activeIndex.set(currentActiveIndex);
|
|
819
|
+
}
|
|
820
|
+
#watchPointerPercent() {
|
|
821
|
+
let { hidden, pointerPercent } = this.#sliderState;
|
|
822
|
+
if (hidden()) {
|
|
823
|
+
this.#activePointerIndex.set(-1);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const activeIndex = this.#findActiveChapterIndex(0, pointerPercent());
|
|
827
|
+
this.#activePointerIndex.set(activeIndex);
|
|
828
|
+
}
|
|
829
|
+
#updateFillPercents(start, end, percent) {
|
|
830
|
+
for (let i = start; i < end; i++) this.#updateFillPercent(this.#refs[i], percent);
|
|
831
|
+
}
|
|
832
|
+
#updateFillPercent(ref, percent) {
|
|
833
|
+
if (!ref) return;
|
|
834
|
+
ref.style.setProperty("--chapter-fill", percent + "%");
|
|
835
|
+
setAttribute(ref, "data-active", percent > 0 && percent < 100);
|
|
836
|
+
setAttribute(ref, "data-ended", percent === 100);
|
|
837
|
+
}
|
|
838
|
+
#findActiveChapterIndex(startIndex, percent) {
|
|
839
|
+
let chapterPercent = 0, cues = this.#$cues();
|
|
840
|
+
if (percent === 0) return 0;
|
|
841
|
+
else if (percent === 100) return cues.length - 1;
|
|
842
|
+
let { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
|
|
843
|
+
for (let i = startIndex; i < cues.length; i++) {
|
|
844
|
+
chapterPercent = this.#calcPercent(cues[i], percent, startTime, endTime);
|
|
845
|
+
if (chapterPercent >= 0 && chapterPercent < 100) return i;
|
|
846
|
+
}
|
|
847
|
+
return 0;
|
|
848
|
+
}
|
|
849
|
+
#watchBufferedPercent() {
|
|
850
|
+
this.#updateBufferedPercent(this.#bufferedPercent());
|
|
851
|
+
}
|
|
852
|
+
#updateBufferedPercent = animationFrameThrottle((bufferedPercent) => {
|
|
853
|
+
let percent, cues = this.#$cues(), { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
|
|
854
|
+
for (let i = this.#bufferedIndex; i < this.#refs.length; i++) {
|
|
855
|
+
percent = this.#calcPercent(cues[i], bufferedPercent, startTime, endTime);
|
|
856
|
+
this.#refs[i]?.style.setProperty("--chapter-progress", percent + "%");
|
|
857
|
+
if (percent < 100) {
|
|
858
|
+
this.#bufferedIndex = i;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
#bufferedPercent = computed(this.#calcMediaBufferedPercent.bind(this));
|
|
864
|
+
#calcMediaBufferedPercent() {
|
|
865
|
+
const { bufferedEnd, duration } = this.#media.$state;
|
|
866
|
+
return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1), 3) * 100;
|
|
867
|
+
}
|
|
868
|
+
#getEndTime(cues) {
|
|
869
|
+
const { seekableEnd } = this.#media.$state, endTime = seekableEnd();
|
|
870
|
+
return Number.isFinite(endTime) ? endTime : cues[cues.length - 1]?.endTime || 0;
|
|
871
|
+
}
|
|
872
|
+
#calcPercent(cue, percent, startTime, endTime) {
|
|
873
|
+
if (!cue) return 0;
|
|
874
|
+
const cues = this.#$cues();
|
|
875
|
+
if (cues.length === 0) return 0;
|
|
876
|
+
const duration = endTime - startTime, cueStartTime = Math.max(0, cue.startTime - startTime), cueEndTime = Math.min(endTime, cue.endTime) - startTime;
|
|
877
|
+
const startRatio = cueStartTime / duration, startPercent = startRatio * 100, endPercent = Math.min(1, startRatio + (cueEndTime - cueStartTime) / duration) * 100;
|
|
878
|
+
return Math.max(
|
|
879
|
+
0,
|
|
880
|
+
round(
|
|
881
|
+
percent >= endPercent ? 100 : (percent - startPercent) / (endPercent - startPercent) * 100,
|
|
882
|
+
3
|
|
883
|
+
)
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
#fillGaps(cues) {
|
|
887
|
+
let chapters = [], { seekableStart, seekableEnd, duration } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
|
|
888
|
+
cues = cues.filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime);
|
|
889
|
+
const firstCue = cues[0];
|
|
890
|
+
if (firstCue && firstCue.startTime > startTime) {
|
|
891
|
+
chapters.push(new window.VTTCue(startTime, firstCue.startTime, ""));
|
|
892
|
+
}
|
|
893
|
+
for (let i = 0; i < cues.length - 1; i++) {
|
|
894
|
+
const currentCue = cues[i], nextCue = cues[i + 1];
|
|
895
|
+
chapters.push(currentCue);
|
|
896
|
+
if (nextCue) {
|
|
897
|
+
const timeDiff = nextCue.startTime - currentCue.endTime;
|
|
898
|
+
if (timeDiff > 0) {
|
|
899
|
+
chapters.push(new window.VTTCue(currentCue.endTime, currentCue.endTime + timeDiff, ""));
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const lastCue = cues[cues.length - 1];
|
|
904
|
+
if (lastCue) {
|
|
905
|
+
chapters.push(lastCue);
|
|
906
|
+
const endTime2 = duration();
|
|
907
|
+
if (endTime2 >= 0 && endTime2 - lastCue.endTime > 1) {
|
|
908
|
+
chapters.push(new window.VTTCue(lastCue.endTime, duration(), ""));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return chapters;
|
|
912
|
+
}
|
|
913
|
+
#watchSource() {
|
|
914
|
+
const { source } = this.#media.$state;
|
|
915
|
+
source();
|
|
916
|
+
this.#onTrackChange();
|
|
917
|
+
}
|
|
918
|
+
#onTrackChange() {
|
|
919
|
+
if (!this.scope) return;
|
|
920
|
+
const { disabled } = this.$props;
|
|
921
|
+
if (disabled()) {
|
|
922
|
+
this.#$cues.set([]);
|
|
923
|
+
this.#activeIndex.set(0);
|
|
924
|
+
this.#bufferedIndex = 0;
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const track = this.#$track();
|
|
928
|
+
if (track) {
|
|
929
|
+
const onCuesChange = this.#onCuesChange.bind(this);
|
|
930
|
+
onCuesChange();
|
|
931
|
+
new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
|
|
932
|
+
effect(this.#watchMediaDuration.bind(this));
|
|
933
|
+
}
|
|
934
|
+
this.#titleRef = this.#findChapterTitleRef();
|
|
935
|
+
if (this.#titleRef) effect(this.#onChapterTitleChange.bind(this));
|
|
936
|
+
return () => {
|
|
937
|
+
if (this.#titleRef) {
|
|
938
|
+
this.#titleRef.textContent = "";
|
|
939
|
+
this.#titleRef = null;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
#watchMediaDuration() {
|
|
944
|
+
this.#media.$state.duration();
|
|
945
|
+
this.#onCuesChange();
|
|
946
|
+
}
|
|
947
|
+
#onCuesChange = functionDebounce(
|
|
948
|
+
() => {
|
|
949
|
+
const track = peek(this.#$track);
|
|
950
|
+
if (!this.scope || !track || !track.cues.length) return;
|
|
951
|
+
this.#$cues.set(this.#fillGaps(track.cues));
|
|
952
|
+
this.#activeIndex.set(0);
|
|
953
|
+
this.#bufferedIndex = 0;
|
|
954
|
+
},
|
|
955
|
+
150,
|
|
956
|
+
true
|
|
957
|
+
);
|
|
958
|
+
#onChapterTitleChange() {
|
|
959
|
+
const cue = this.activePointerCue || this.activeCue;
|
|
960
|
+
if (this.#titleRef) this.#titleRef.textContent = cue?.text || "";
|
|
961
|
+
}
|
|
962
|
+
#findParentSlider() {
|
|
963
|
+
let node = this.el;
|
|
964
|
+
while (node && node.getAttribute("role") !== "slider") {
|
|
965
|
+
node = node.parentElement;
|
|
966
|
+
}
|
|
967
|
+
return node;
|
|
968
|
+
}
|
|
969
|
+
#findChapterTitleRef() {
|
|
970
|
+
const slider = this.#findParentSlider();
|
|
971
|
+
return slider ? slider.querySelector('[data-part="chapter-title"]') : null;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
const sliderchapters__proto = SliderChapters.prototype;
|
|
975
|
+
prop(sliderchapters__proto, "cues");
|
|
976
|
+
prop(sliderchapters__proto, "activeCue");
|
|
977
|
+
prop(sliderchapters__proto, "activePointerCue");
|
|
978
|
+
method(sliderchapters__proto, "setRefs");
|
|
979
|
+
|
|
980
|
+
class RadioGroup extends Component {
|
|
981
|
+
static props = {
|
|
982
|
+
value: ""
|
|
983
|
+
};
|
|
984
|
+
#controller;
|
|
985
|
+
/**
|
|
986
|
+
* A list of radio values that belong this group.
|
|
987
|
+
*/
|
|
988
|
+
get values() {
|
|
989
|
+
return this.#controller.values;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* The radio value that is checked in this group.
|
|
993
|
+
*/
|
|
994
|
+
get value() {
|
|
995
|
+
return this.#controller.value;
|
|
996
|
+
}
|
|
997
|
+
set value(newValue) {
|
|
998
|
+
this.#controller.value = newValue;
|
|
999
|
+
}
|
|
1000
|
+
constructor() {
|
|
1001
|
+
super();
|
|
1002
|
+
this.#controller = new RadioGroupController();
|
|
1003
|
+
this.#controller.onValueChange = this.#onValueChange.bind(this);
|
|
1004
|
+
}
|
|
1005
|
+
onSetup() {
|
|
1006
|
+
effect(this.#watchValue.bind(this));
|
|
1007
|
+
}
|
|
1008
|
+
#watchValue() {
|
|
1009
|
+
this.#controller.value = this.$props.value();
|
|
1010
|
+
}
|
|
1011
|
+
#onValueChange(value, trigger) {
|
|
1012
|
+
const event = this.createEvent("change", { detail: value, trigger });
|
|
1013
|
+
this.dispatch(event);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
const radiogroup__proto = RadioGroup.prototype;
|
|
1017
|
+
prop(radiogroup__proto, "values");
|
|
1018
|
+
prop(radiogroup__proto, "value");
|
|
1019
|
+
|
|
1020
|
+
var __defProp = Object.defineProperty;
|
|
1021
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1022
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1023
|
+
var result = __getOwnPropDesc(target, key) ;
|
|
1024
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1025
|
+
if (decorator = decorators[i])
|
|
1026
|
+
result = (decorator(target, key, result) ) || result;
|
|
1027
|
+
if (result) __defProp(target, key, result);
|
|
1028
|
+
return result;
|
|
1029
|
+
};
|
|
1030
|
+
class ChaptersRadioGroup extends Component {
|
|
1031
|
+
static props = {
|
|
1032
|
+
thumbnails: null
|
|
1033
|
+
};
|
|
1034
|
+
#media;
|
|
1035
|
+
#menu;
|
|
1036
|
+
#controller;
|
|
1037
|
+
#track = signal(null);
|
|
1038
|
+
#cues = signal([]);
|
|
1039
|
+
get value() {
|
|
1040
|
+
return this.#controller.value;
|
|
1041
|
+
}
|
|
1042
|
+
get disabled() {
|
|
1043
|
+
return !this.#cues()?.length;
|
|
1044
|
+
}
|
|
1045
|
+
constructor() {
|
|
1046
|
+
super();
|
|
1047
|
+
this.#controller = new RadioGroupController();
|
|
1048
|
+
this.#controller.onValueChange = this.#onValueChange.bind(this);
|
|
1049
|
+
}
|
|
1050
|
+
onSetup() {
|
|
1051
|
+
this.#media = useMediaContext();
|
|
1052
|
+
if (hasProvidedContext(menuContext)) {
|
|
1053
|
+
this.#menu = useContext(menuContext);
|
|
1054
|
+
}
|
|
1055
|
+
const { thumbnails } = this.$props;
|
|
1056
|
+
this.setAttributes({
|
|
1057
|
+
"data-thumbnails": () => !!thumbnails()
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
onAttach(el) {
|
|
1061
|
+
this.#menu?.attachObserver({
|
|
1062
|
+
onOpen: this.#onOpen.bind(this)
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
getOptions() {
|
|
1066
|
+
const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
|
|
1067
|
+
return this.#cues().map((cue, i) => ({
|
|
1068
|
+
cue,
|
|
1069
|
+
value: i.toString(),
|
|
1070
|
+
label: cue.text,
|
|
1071
|
+
startTime: formatTime(Math.max(0, cue.startTime - startTime)),
|
|
1072
|
+
duration: formatSpokenTime(
|
|
1073
|
+
Math.min(endTime, cue.endTime) - Math.max(startTime, cue.startTime)
|
|
1074
|
+
)
|
|
1075
|
+
}));
|
|
1076
|
+
}
|
|
1077
|
+
#onOpen() {
|
|
1078
|
+
peek(() => this.#watchCurrentTime());
|
|
1079
|
+
}
|
|
1080
|
+
onConnect(el) {
|
|
1081
|
+
effect(this.#watchCurrentTime.bind(this));
|
|
1082
|
+
effect(this.#watchControllerDisabled.bind(this));
|
|
1083
|
+
effect(this.#watchTrack.bind(this));
|
|
1084
|
+
watchActiveTextTrack(this.#media.textTracks, "chapters", this.#track.set);
|
|
1085
|
+
}
|
|
1086
|
+
#watchTrack() {
|
|
1087
|
+
const track = this.#track();
|
|
1088
|
+
if (!track) return;
|
|
1089
|
+
const onCuesChange = this.#onCuesChange.bind(this, track);
|
|
1090
|
+
onCuesChange();
|
|
1091
|
+
new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
|
|
1092
|
+
return () => {
|
|
1093
|
+
this.#cues.set([]);
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
#onCuesChange(track) {
|
|
1097
|
+
const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
|
|
1098
|
+
this.#cues.set(
|
|
1099
|
+
[...track.cues].filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime)
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
#watchCurrentTime() {
|
|
1103
|
+
if (!this.#menu?.expanded()) return;
|
|
1104
|
+
const track = this.#track();
|
|
1105
|
+
if (!track) {
|
|
1106
|
+
this.#controller.value = "-1";
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
const { realCurrentTime, seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd(), time = realCurrentTime(), activeCueIndex = this.#cues().findIndex((cue) => isCueActive(cue, time));
|
|
1110
|
+
this.#controller.value = activeCueIndex.toString();
|
|
1111
|
+
if (activeCueIndex >= 0) {
|
|
1112
|
+
requestScopedAnimationFrame(() => {
|
|
1113
|
+
if (!this.connectScope) return;
|
|
1114
|
+
const cue = this.#cues()[activeCueIndex], radio = this.el.querySelector(`[aria-checked='true']`), cueStartTime = Math.max(startTime, cue.startTime), duration = Math.min(endTime, cue.endTime) - cueStartTime, playedPercent = Math.max(0, time - cueStartTime) / duration * 100;
|
|
1115
|
+
radio && setStyle(radio, "--progress", round(playedPercent, 3) + "%");
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
#watchControllerDisabled() {
|
|
1120
|
+
this.#menu?.disable(this.disabled);
|
|
1121
|
+
}
|
|
1122
|
+
#onValueChange(value, trigger) {
|
|
1123
|
+
if (this.disabled || !trigger) return;
|
|
1124
|
+
const index = +value, cues = this.#cues(), { clipStartTime } = this.#media.$state;
|
|
1125
|
+
if (isNumber(index) && cues?.[index]) {
|
|
1126
|
+
this.#controller.value = index.toString();
|
|
1127
|
+
this.#media.remote.seek(cues[index].startTime - clipStartTime(), trigger);
|
|
1128
|
+
this.dispatch("change", { detail: cues[index], trigger });
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
__decorateClass([
|
|
1133
|
+
prop
|
|
1134
|
+
], ChaptersRadioGroup.prototype, "value");
|
|
1135
|
+
__decorateClass([
|
|
1136
|
+
prop
|
|
1137
|
+
], ChaptersRadioGroup.prototype, "disabled");
|
|
1138
|
+
__decorateClass([
|
|
1139
|
+
method
|
|
1140
|
+
], ChaptersRadioGroup.prototype, "getOptions");
|
|
1141
|
+
|
|
1142
|
+
const DEFAULT_AUDIO_GAINS = [1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4];
|
|
1143
|
+
class AudioGainRadioGroup extends Component {
|
|
1144
|
+
static props = {
|
|
1145
|
+
normalLabel: "Disabled",
|
|
1146
|
+
gains: DEFAULT_AUDIO_GAINS
|
|
1147
|
+
};
|
|
1148
|
+
#media;
|
|
1149
|
+
#menu;
|
|
1150
|
+
#controller;
|
|
1151
|
+
get value() {
|
|
1152
|
+
return this.#controller.value;
|
|
1153
|
+
}
|
|
1154
|
+
get disabled() {
|
|
1155
|
+
const { gains } = this.$props, { canSetAudioGain } = this.#media.$state;
|
|
1156
|
+
return !canSetAudioGain() || gains().length === 0;
|
|
1157
|
+
}
|
|
1158
|
+
constructor() {
|
|
1159
|
+
super();
|
|
1160
|
+
this.#controller = new RadioGroupController();
|
|
1161
|
+
this.#controller.onValueChange = this.#onValueChange.bind(this);
|
|
1162
|
+
}
|
|
1163
|
+
onSetup() {
|
|
1164
|
+
this.#media = useMediaContext();
|
|
1165
|
+
if (hasProvidedContext(menuContext)) {
|
|
1166
|
+
this.#menu = useContext(menuContext);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
onConnect(el) {
|
|
1170
|
+
effect(this.#watchValue.bind(this));
|
|
1171
|
+
effect(this.#watchHintText.bind(this));
|
|
1172
|
+
effect(this.#watchControllerDisabled.bind(this));
|
|
1173
|
+
}
|
|
1174
|
+
getOptions() {
|
|
1175
|
+
const { gains, normalLabel } = this.$props;
|
|
1176
|
+
return gains().map((gain) => ({
|
|
1177
|
+
label: gain === 1 || gain === null ? normalLabel : String(gain * 100) + "%",
|
|
1178
|
+
value: gain.toString()
|
|
1179
|
+
}));
|
|
1180
|
+
}
|
|
1181
|
+
#watchValue() {
|
|
1182
|
+
this.#controller.value = this.#getValue();
|
|
1183
|
+
}
|
|
1184
|
+
#watchHintText() {
|
|
1185
|
+
const { normalLabel } = this.$props, { audioGain } = this.#media.$state, gain = audioGain();
|
|
1186
|
+
this.#menu?.hint.set(gain === 1 || gain == null ? normalLabel() : String(gain * 100) + "%");
|
|
1187
|
+
}
|
|
1188
|
+
#watchControllerDisabled() {
|
|
1189
|
+
this.#menu?.disable(this.disabled);
|
|
1190
|
+
}
|
|
1191
|
+
#getValue() {
|
|
1192
|
+
const { audioGain } = this.#media.$state;
|
|
1193
|
+
return audioGain()?.toString() ?? "1";
|
|
1194
|
+
}
|
|
1195
|
+
#onValueChange(value, trigger) {
|
|
1196
|
+
if (this.disabled) return;
|
|
1197
|
+
const gain = +value;
|
|
1198
|
+
this.#media.remote.changeAudioGain(gain, trigger);
|
|
1199
|
+
this.dispatch("change", { detail: gain, trigger });
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
const audiogainradiogroup__proto = AudioGainRadioGroup.prototype;
|
|
1203
|
+
prop(audiogainradiogroup__proto, "value");
|
|
1204
|
+
prop(audiogainradiogroup__proto, "disabled");
|
|
1205
|
+
method(audiogainradiogroup__proto, "getOptions");
|
|
1206
|
+
|
|
1207
|
+
class Gesture extends Component {
|
|
1208
|
+
static props = {
|
|
1209
|
+
disabled: false,
|
|
1210
|
+
event: void 0,
|
|
1211
|
+
action: void 0
|
|
1212
|
+
};
|
|
1213
|
+
#media;
|
|
1214
|
+
#provider = null;
|
|
1215
|
+
onSetup() {
|
|
1216
|
+
this.#media = useMediaContext();
|
|
1217
|
+
const { event, action } = this.$props;
|
|
1218
|
+
this.setAttributes({
|
|
1219
|
+
event,
|
|
1220
|
+
action
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
onAttach(el) {
|
|
1224
|
+
el.setAttribute("data-media-gesture", "");
|
|
1225
|
+
el.style.setProperty("pointer-events", "none");
|
|
1226
|
+
}
|
|
1227
|
+
onConnect(el) {
|
|
1228
|
+
this.#provider = this.#media.player.el?.querySelector(
|
|
1229
|
+
"[data-media-provider]"
|
|
1230
|
+
);
|
|
1231
|
+
effect(this.#attachListener.bind(this));
|
|
1232
|
+
}
|
|
1233
|
+
#attachListener() {
|
|
1234
|
+
let eventType = this.$props.event(), disabled = this.$props.disabled();
|
|
1235
|
+
if (!this.#provider || !eventType || disabled) return;
|
|
1236
|
+
if (/^dbl/.test(eventType)) {
|
|
1237
|
+
eventType = eventType.split(/^dbl/)[1];
|
|
1238
|
+
}
|
|
1239
|
+
if (eventType === "pointerup" || eventType === "pointerdown") {
|
|
1240
|
+
const pointer = this.#media.$state.pointer();
|
|
1241
|
+
if (pointer === "coarse") {
|
|
1242
|
+
eventType = eventType === "pointerup" ? "touchend" : "touchstart";
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
listenEvent(
|
|
1246
|
+
this.#provider,
|
|
1247
|
+
eventType,
|
|
1248
|
+
this.#acceptEvent.bind(this),
|
|
1249
|
+
{ passive: false }
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
#presses = 0;
|
|
1253
|
+
#pressTimerId = -1;
|
|
1254
|
+
#acceptEvent(event) {
|
|
1255
|
+
if (this.$props.disabled() || isPointerEvent(event) && (event.button !== 0 || this.#media.activeMenu) || isTouchEvent(event) && this.#media.activeMenu || isTouchPinchEvent(event) || !this.#inBounds(event)) {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
event.MEDIA_GESTURE = true;
|
|
1259
|
+
event.preventDefault();
|
|
1260
|
+
const eventType = peek(this.$props.event), isDblEvent = eventType?.startsWith("dbl");
|
|
1261
|
+
if (!isDblEvent) {
|
|
1262
|
+
if (this.#presses === 0) {
|
|
1263
|
+
setTimeout(() => {
|
|
1264
|
+
if (this.#presses === 1) this.#handleEvent(event);
|
|
1265
|
+
}, 250);
|
|
1266
|
+
}
|
|
1267
|
+
} else if (this.#presses === 1) {
|
|
1268
|
+
queueMicrotask(() => this.#handleEvent(event));
|
|
1269
|
+
clearTimeout(this.#pressTimerId);
|
|
1270
|
+
this.#presses = 0;
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
if (this.#presses === 0) {
|
|
1274
|
+
this.#pressTimerId = window.setTimeout(() => {
|
|
1275
|
+
this.#presses = 0;
|
|
1276
|
+
}, 275);
|
|
1277
|
+
}
|
|
1278
|
+
this.#presses++;
|
|
1279
|
+
}
|
|
1280
|
+
#handleEvent(event) {
|
|
1281
|
+
this.el.setAttribute("data-triggered", "");
|
|
1282
|
+
requestAnimationFrame(() => {
|
|
1283
|
+
if (this.#isTopLayer()) {
|
|
1284
|
+
this.#performAction(peek(this.$props.action), event);
|
|
1285
|
+
}
|
|
1286
|
+
requestAnimationFrame(() => {
|
|
1287
|
+
this.el.removeAttribute("data-triggered");
|
|
1288
|
+
});
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
/** Validate event occurred in gesture bounds. */
|
|
1292
|
+
#inBounds(event) {
|
|
1293
|
+
if (!this.el) return false;
|
|
1294
|
+
if (isPointerEvent(event) || isMouseEvent(event) || isTouchEvent(event)) {
|
|
1295
|
+
const touch = isTouchEvent(event) ? event.changedTouches[0] ?? event.touches[0] : void 0;
|
|
1296
|
+
const clientX = touch?.clientX ?? event.clientX;
|
|
1297
|
+
const clientY = touch?.clientY ?? event.clientY;
|
|
1298
|
+
const rect = this.el.getBoundingClientRect();
|
|
1299
|
+
const inBounds = clientY >= rect.top && clientY <= rect.bottom && clientX >= rect.left && clientX <= rect.right;
|
|
1300
|
+
return event.type.includes("leave") ? !inBounds : inBounds;
|
|
1301
|
+
}
|
|
1302
|
+
return true;
|
|
1303
|
+
}
|
|
1304
|
+
/** Validate gesture has the highest z-index in this triggered group. */
|
|
1305
|
+
#isTopLayer() {
|
|
1306
|
+
const gestures = this.#media.player.el.querySelectorAll(
|
|
1307
|
+
"[data-media-gesture][data-triggered]"
|
|
1308
|
+
);
|
|
1309
|
+
return Array.from(gestures).sort(
|
|
1310
|
+
(a, b) => +getComputedStyle(b).zIndex - +getComputedStyle(a).zIndex
|
|
1311
|
+
)[0] === this.el;
|
|
1312
|
+
}
|
|
1313
|
+
#performAction(action, trigger) {
|
|
1314
|
+
if (!action) return;
|
|
1315
|
+
const willTriggerEvent = new DOMEvent("will-trigger", {
|
|
1316
|
+
detail: action,
|
|
1317
|
+
cancelable: true,
|
|
1318
|
+
trigger
|
|
1319
|
+
});
|
|
1320
|
+
this.dispatchEvent(willTriggerEvent);
|
|
1321
|
+
if (willTriggerEvent.defaultPrevented) return;
|
|
1322
|
+
const [method, value] = action.replace(/:([a-z])/, "-$1").split(":");
|
|
1323
|
+
if (action.includes(":fullscreen")) {
|
|
1324
|
+
this.#media.remote.toggleFullscreen("prefer-media", trigger);
|
|
1325
|
+
} else if (action.includes("seek:")) {
|
|
1326
|
+
this.#media.remote.seek(peek(this.#media.$state.currentTime) + (+value || 0), trigger);
|
|
1327
|
+
} else {
|
|
1328
|
+
this.#media.remote[kebabToCamelCase(method)](trigger);
|
|
1329
|
+
}
|
|
1330
|
+
this.dispatch("trigger", {
|
|
1331
|
+
detail: action,
|
|
1332
|
+
trigger
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
class CaptionsTextRenderer {
|
|
1338
|
+
priority = 10;
|
|
1339
|
+
#track = null;
|
|
1340
|
+
#renderer;
|
|
1341
|
+
#events;
|
|
1342
|
+
constructor(renderer) {
|
|
1343
|
+
this.#renderer = renderer;
|
|
1344
|
+
}
|
|
1345
|
+
attach() {
|
|
1346
|
+
}
|
|
1347
|
+
canRender() {
|
|
1348
|
+
return true;
|
|
1349
|
+
}
|
|
1350
|
+
detach() {
|
|
1351
|
+
this.#events?.abort();
|
|
1352
|
+
this.#events = void 0;
|
|
1353
|
+
this.#renderer.reset();
|
|
1354
|
+
this.#track = null;
|
|
1355
|
+
}
|
|
1356
|
+
changeTrack(track) {
|
|
1357
|
+
if (!track || this.#track === track) return;
|
|
1358
|
+
this.#events?.abort();
|
|
1359
|
+
this.#events = new EventsController(track);
|
|
1360
|
+
if (track.readyState < 2) {
|
|
1361
|
+
this.#renderer.reset();
|
|
1362
|
+
this.#events.add("load", () => this.#changeTrack(track), { once: true });
|
|
1363
|
+
} else {
|
|
1364
|
+
this.#changeTrack(track);
|
|
1365
|
+
}
|
|
1366
|
+
this.#events.add("add-cue", (event) => {
|
|
1367
|
+
this.#renderer.addCue(event.detail);
|
|
1368
|
+
}).add("remove-cue", (event) => {
|
|
1369
|
+
this.#renderer.removeCue(event.detail);
|
|
1370
|
+
});
|
|
1371
|
+
this.#track = track;
|
|
1372
|
+
}
|
|
1373
|
+
#changeTrack(track) {
|
|
1374
|
+
this.#renderer.changeTrack({
|
|
1375
|
+
cues: [...track.cues],
|
|
1376
|
+
regions: [...track.regions]
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
class Captions extends Component {
|
|
1382
|
+
static props = {
|
|
1383
|
+
textDir: "ltr",
|
|
1384
|
+
exampleText: "Captions look like this."
|
|
1385
|
+
};
|
|
1386
|
+
#media;
|
|
1387
|
+
static lib = signal(null);
|
|
1388
|
+
onSetup() {
|
|
1389
|
+
this.#media = useMediaContext();
|
|
1390
|
+
this.setAttributes({
|
|
1391
|
+
"aria-hidden": $ariaBool(this.#isHidden.bind(this))
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
onAttach(el) {
|
|
1395
|
+
el.style.setProperty("pointer-events", "none");
|
|
1396
|
+
}
|
|
1397
|
+
onConnect(el) {
|
|
1398
|
+
if (!Captions.lib()) {
|
|
1399
|
+
import('media-captions').then((lib) => Captions.lib.set(lib));
|
|
1400
|
+
}
|
|
1401
|
+
effect(this.#watchViewType.bind(this));
|
|
1402
|
+
}
|
|
1403
|
+
#isHidden() {
|
|
1404
|
+
const { textTrack, remotePlaybackState, iOSControls } = this.#media.$state, track = textTrack();
|
|
1405
|
+
return iOSControls() || remotePlaybackState() === "connected" || !track || !isTrackCaptionKind(track);
|
|
1406
|
+
}
|
|
1407
|
+
#watchViewType() {
|
|
1408
|
+
if (!Captions.lib()) return;
|
|
1409
|
+
const { viewType } = this.#media.$state;
|
|
1410
|
+
if (viewType() === "audio") {
|
|
1411
|
+
return this.#setupAudioView();
|
|
1412
|
+
} else {
|
|
1413
|
+
return this.#setupVideoView();
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
#setupAudioView() {
|
|
1417
|
+
effect(this.#onTrackChange.bind(this));
|
|
1418
|
+
this.#listenToFontStyleChanges(null);
|
|
1419
|
+
return () => {
|
|
1420
|
+
this.el.textContent = "";
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
#onTrackChange() {
|
|
1424
|
+
if (this.#isHidden()) return;
|
|
1425
|
+
this.#onCueChange();
|
|
1426
|
+
const { textTrack } = this.#media.$state;
|
|
1427
|
+
listenEvent(textTrack(), "cue-change", this.#onCueChange.bind(this));
|
|
1428
|
+
effect(this.#onUpdateTimedNodes.bind(this));
|
|
1429
|
+
}
|
|
1430
|
+
#onCueChange() {
|
|
1431
|
+
this.el.textContent = "";
|
|
1432
|
+
if (this.#hideExampleTimer >= 0) {
|
|
1433
|
+
this.#removeExample();
|
|
1434
|
+
}
|
|
1435
|
+
const { realCurrentTime, textTrack } = this.#media.$state, { renderVTTCueString } = Captions.lib(), time = peek(realCurrentTime), activeCues = peek(textTrack).activeCues;
|
|
1436
|
+
for (const cue of activeCues) {
|
|
1437
|
+
const displayEl = this.#createCueDisplayElement(), cueEl = this.#createCueElement();
|
|
1438
|
+
cueEl.innerHTML = renderVTTCueString(cue, time);
|
|
1439
|
+
displayEl.append(cueEl);
|
|
1440
|
+
this.el.append(cueEl);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
#onUpdateTimedNodes() {
|
|
1444
|
+
const { realCurrentTime } = this.#media.$state, { updateTimedVTTCueNodes } = Captions.lib();
|
|
1445
|
+
updateTimedVTTCueNodes(this.el, realCurrentTime());
|
|
1446
|
+
}
|
|
1447
|
+
#setupVideoView() {
|
|
1448
|
+
const { CaptionsRenderer } = Captions.lib(), renderer = new CaptionsRenderer(this.el), textRenderer = new CaptionsTextRenderer(renderer);
|
|
1449
|
+
this.#media.textRenderers.add(textRenderer);
|
|
1450
|
+
effect(this.#watchTextDirection.bind(this, renderer));
|
|
1451
|
+
effect(this.#watchMediaTime.bind(this, renderer));
|
|
1452
|
+
this.#listenToFontStyleChanges(renderer);
|
|
1453
|
+
return () => {
|
|
1454
|
+
this.el.textContent = "";
|
|
1455
|
+
this.#media.textRenderers.remove(textRenderer);
|
|
1456
|
+
renderer.destroy();
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
#watchTextDirection(renderer) {
|
|
1460
|
+
renderer.dir = this.$props.textDir();
|
|
1461
|
+
}
|
|
1462
|
+
#watchMediaTime(renderer) {
|
|
1463
|
+
if (this.#isHidden()) return;
|
|
1464
|
+
const { realCurrentTime, textTrack } = this.#media.$state;
|
|
1465
|
+
renderer.currentTime = realCurrentTime();
|
|
1466
|
+
if (this.#hideExampleTimer >= 0 && textTrack()?.activeCues[0]) {
|
|
1467
|
+
this.#removeExample();
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
#listenToFontStyleChanges(renderer) {
|
|
1471
|
+
const player = this.#media.player;
|
|
1472
|
+
if (!player) return;
|
|
1473
|
+
const onChange = this.#onFontStyleChange.bind(this, renderer);
|
|
1474
|
+
listenEvent(player, "vds-font-change", onChange);
|
|
1475
|
+
}
|
|
1476
|
+
#onFontStyleChange(renderer) {
|
|
1477
|
+
if (this.#hideExampleTimer >= 0) {
|
|
1478
|
+
this.#hideExample();
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const { textTrack } = this.#media.$state;
|
|
1482
|
+
if (!textTrack()?.activeCues[0]) {
|
|
1483
|
+
this.#showExample();
|
|
1484
|
+
} else {
|
|
1485
|
+
renderer?.update(true);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
#showExample() {
|
|
1489
|
+
const display = this.#createCueDisplayElement();
|
|
1490
|
+
setAttribute(display, "data-example", "");
|
|
1491
|
+
const cue = this.#createCueElement();
|
|
1492
|
+
setAttribute(cue, "data-example", "");
|
|
1493
|
+
cue.textContent = this.$props.exampleText();
|
|
1494
|
+
display?.append(cue);
|
|
1495
|
+
this.el?.append(display);
|
|
1496
|
+
this.el?.setAttribute("data-example", "");
|
|
1497
|
+
this.#hideExample();
|
|
1498
|
+
}
|
|
1499
|
+
#hideExampleTimer = -1;
|
|
1500
|
+
#hideExample() {
|
|
1501
|
+
window.clearTimeout(this.#hideExampleTimer);
|
|
1502
|
+
this.#hideExampleTimer = window.setTimeout(this.#removeExample.bind(this), 2500);
|
|
1503
|
+
}
|
|
1504
|
+
#removeExample() {
|
|
1505
|
+
this.el?.removeAttribute("data-example");
|
|
1506
|
+
if (this.el?.querySelector("[data-example]")) this.el.textContent = "";
|
|
1507
|
+
this.#hideExampleTimer = -1;
|
|
1508
|
+
}
|
|
1509
|
+
#createCueDisplayElement() {
|
|
1510
|
+
const el = document.createElement("div");
|
|
1511
|
+
setAttribute(el, "data-part", "cue-display");
|
|
1512
|
+
return el;
|
|
1513
|
+
}
|
|
1514
|
+
#createCueElement() {
|
|
1515
|
+
const el = document.createElement("div");
|
|
1516
|
+
setAttribute(el, "data-part", "cue");
|
|
1517
|
+
return el;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
export { AudioGainRadioGroup, AudioGainSlider, Captions, ChaptersRadioGroup, Controls, ControlsGroup, DEFAULT_AUDIO_GAINS, Gesture, GoogleCastButton, MediaAnnouncer, QualitySlider, RadioGroup, SliderChapters, SliderVideo, SpeedSlider, ToggleButton, Tooltip, TooltipContent, TooltipTrigger };
|