@hanifhan1f/vidstack 1.12.19 → 1.12.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/cdn/chunks/vidstack-BF7lZRtq.js +3 -0
  2. package/cdn/chunks/vidstack-BYpysj84.js +1 -0
  3. package/cdn/chunks/vidstack-C1FlyyzK.js +1 -0
  4. package/cdn/chunks/vidstack-Cj0I-Rec.js +1 -0
  5. package/cdn/chunks/vidstack-D84Fzc__.js +16 -0
  6. package/cdn/chunks/vidstack-DQvyz7Mm.js +1 -0
  7. package/cdn/chunks/vidstack-Dd9fqVv6.js +1 -0
  8. package/cdn/chunks/vidstack-uMxrPflF.js +1 -0
  9. package/cdn/chunks/vidstack-zemsqC5d.js +1 -0
  10. package/cdn/providers/vidstack-audio-BOGYlExy.js +1 -0
  11. package/cdn/providers/vidstack-dash-D4ZARr66.js +1 -0
  12. package/cdn/providers/vidstack-hls-8-552IuX.js +1 -0
  13. package/cdn/providers/vidstack-html-BvVaN2VT.js +1 -0
  14. package/cdn/providers/vidstack-video-BnwQZKER.js +1 -0
  15. package/cdn/providers/vidstack-vimeo-gJmBqtLK.js +1 -0
  16. package/cdn/providers/vidstack-youtube-Chl_dTAz.js +1 -0
  17. package/cdn/vidstack.js +1 -1
  18. package/cdn/with-layouts/chunks/vidstack-4liSokT6.js +1 -0
  19. package/cdn/with-layouts/chunks/vidstack-B97B8XDc.js +3 -0
  20. package/cdn/with-layouts/chunks/vidstack-BbFHhcVG.js +1 -0
  21. package/cdn/with-layouts/chunks/vidstack-CXEcXyBI.js +1 -0
  22. package/cdn/with-layouts/chunks/vidstack-Ciq-n5rg.js +1 -0
  23. package/cdn/with-layouts/chunks/vidstack-CmuGllcj.js +1 -0
  24. package/cdn/with-layouts/chunks/vidstack-CyNByJUW.js +912 -0
  25. package/cdn/with-layouts/chunks/vidstack-DhNpv7SU.js +1 -0
  26. package/cdn/with-layouts/providers/vidstack-audio-CwoQJvl2.js +1 -0
  27. package/cdn/with-layouts/providers/vidstack-dash-CJsKJfLI.js +1 -0
  28. package/cdn/with-layouts/providers/vidstack-hls-ji26kFdQ.js +1 -0
  29. package/cdn/with-layouts/providers/vidstack-html-BvHMxtoe.js +1 -0
  30. package/cdn/with-layouts/providers/vidstack-video-1Uj5cNP2.js +1 -0
  31. package/cdn/with-layouts/providers/vidstack-vimeo-DACTbJaQ.js +1 -0
  32. package/cdn/with-layouts/providers/vidstack-youtube-RoLp-I6u.js +1 -0
  33. package/cdn/with-layouts/vidstack.js +1 -1
  34. package/dev/chunks/vidstack-0XhA3AD_.js +5181 -0
  35. package/dev/chunks/vidstack-5oWWZmVl.js +58 -0
  36. package/dev/chunks/vidstack-BnBLcaA5.js +115 -0
  37. package/dev/chunks/vidstack-Bo8BNFJ2.js +2986 -0
  38. package/dev/chunks/vidstack-C3N4zIuV.js +254 -0
  39. package/dev/chunks/vidstack-CAL4iu_K.js +1482 -0
  40. package/dev/chunks/vidstack-CGyAjz8G.js +58 -0
  41. package/dev/chunks/vidstack-CJCnHmKE.js +104 -0
  42. package/dev/chunks/vidstack-CzCQJ29U.js +107 -0
  43. package/dev/chunks/vidstack-DD_3HszA.js +1520 -0
  44. package/dev/chunks/vidstack-DV4g4XvL.js +33 -0
  45. package/dev/chunks/vidstack-D_LvMxPr.js +204 -0
  46. package/dev/chunks/vidstack-DdTXMZro.js +66 -0
  47. package/dev/chunks/vidstack-DrczgsqN.js +297 -0
  48. package/dev/chunks/vidstack-gF_qqvCK.js +109 -0
  49. package/dev/define/plyr-layout.js +7 -7
  50. package/dev/define/templates/plyr-layout.js +2 -2
  51. package/dev/define/templates/vidstack-audio-layout.js +3 -3
  52. package/dev/define/templates/vidstack-video-layout.js +7 -9
  53. package/dev/define/vidstack-player-default-layout.js +3 -3
  54. package/dev/define/vidstack-player-layouts.js +3 -3
  55. package/dev/define/vidstack-player-ui.js +9 -9
  56. package/dev/define/vidstack-player.js +5 -5
  57. package/dev/global/plyr.js +9 -9
  58. package/dev/global/vidstack-player.js +6 -6
  59. package/dev/providers/vidstack-audio.js +2 -2
  60. package/dev/providers/vidstack-dash.js +4 -4
  61. package/dev/providers/vidstack-hls.js +4 -4
  62. package/dev/providers/vidstack-html.js +1 -1
  63. package/dev/providers/vidstack-video.js +4 -4
  64. package/dev/providers/vidstack-vimeo.js +4 -4
  65. package/dev/providers/vidstack-youtube.js +3 -3
  66. package/dev/vidstack-elements.js +12 -12
  67. package/dev/vidstack.js +9 -9
  68. package/package.json +1 -1
  69. package/player/styles/default/layouts/video.css +113 -79
  70. package/prod/chunks/vidstack-BAqdCFIm.js +4771 -0
  71. package/prod/chunks/vidstack-BRnfTkxi.js +297 -0
  72. package/prod/chunks/vidstack-BexQYZop.js +2976 -0
  73. package/prod/chunks/vidstack-Bf1Q6kqO.js +109 -0
  74. package/prod/chunks/vidstack-Bn9yLryd.js +58 -0
  75. package/prod/chunks/vidstack-C4PTiuot.js +107 -0
  76. package/prod/chunks/vidstack-DMDDSV3t.js +104 -0
  77. package/prod/chunks/vidstack-Dg71uhRc.js +58 -0
  78. package/prod/chunks/vidstack-DlLwMLBL.js +33 -0
  79. package/prod/chunks/vidstack-KShKSmYu.js +66 -0
  80. package/prod/chunks/vidstack-ShUhyBfI.js +201 -0
  81. package/prod/chunks/vidstack-V9U6gsde.js +1482 -0
  82. package/prod/chunks/vidstack-kdaDngIm.js +1520 -0
  83. package/prod/chunks/vidstack-oNEzlviH.js +246 -0
  84. package/prod/chunks/vidstack-wTTCvdqe.js +115 -0
  85. package/prod/define/plyr-layout.js +7 -7
  86. package/prod/define/templates/plyr-layout.js +2 -2
  87. package/prod/define/templates/vidstack-audio-layout.js +3 -3
  88. package/prod/define/templates/vidstack-video-layout.js +7 -9
  89. package/prod/define/vidstack-player-default-layout.js +3 -3
  90. package/prod/define/vidstack-player-layouts.js +3 -3
  91. package/prod/define/vidstack-player-ui.js +9 -9
  92. package/prod/define/vidstack-player.js +5 -5
  93. package/prod/global/plyr.js +9 -9
  94. package/prod/global/vidstack-player.js +6 -6
  95. package/prod/providers/vidstack-audio.js +2 -2
  96. package/prod/providers/vidstack-dash.js +4 -4
  97. package/prod/providers/vidstack-hls.js +4 -4
  98. package/prod/providers/vidstack-html.js +1 -1
  99. package/prod/providers/vidstack-video.js +4 -4
  100. package/prod/providers/vidstack-vimeo.js +4 -4
  101. package/prod/providers/vidstack-youtube.js +3 -3
  102. package/prod/vidstack-elements.js +12 -12
  103. package/prod/vidstack.js +9 -9
  104. package/server/chunks/vidstack-B2Bc9g7_.js +2000 -0
  105. package/server/define/vidstack-player-default-layout.js +1 -1
  106. package/server/define/vidstack-player-layouts.js +1 -1
  107. package/server/vidstack-elements.js +1 -1
@@ -0,0 +1,1520 @@
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-Bo8BNFJ2.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 } = quality(), bitrateText = bitrate && bitrate > 0 ? `${(bitrate / 1e6).toFixed(2)} Mbps` : null;
681
+ return height ? `${height}p${bitrateText ? ` (${bitrateText})` : ""}` : "Auto";
682
+ }
683
+ #watchMax() {
684
+ const $qualities = this.#sortedQualities();
685
+ this.$state.max.set(Math.max(0, $qualities.length - 1));
686
+ }
687
+ #watchQuality() {
688
+ let { quality } = this.#media.$state, $qualities = this.#sortedQualities(), value = Math.max(0, $qualities.indexOf(quality()));
689
+ this.$state.value.set(value);
690
+ this.dispatch("value-change", { detail: value });
691
+ }
692
+ #isDisabled() {
693
+ const { disabled } = this.$props, { canSetQuality, qualities } = this.#media.$state;
694
+ return disabled() || qualities().length <= 1 || !canSetQuality();
695
+ }
696
+ #throttledQualityChange = functionThrottle(this.#onQualityChange.bind(this), 25);
697
+ #onQualityChange(event) {
698
+ if (!event.trigger) return;
699
+ const { qualities } = this.#media, quality = peek(this.#sortedQualities)[event.detail];
700
+ this.#media.remote.changeQuality(qualities.indexOf(quality), event);
701
+ }
702
+ #onValueChange(event) {
703
+ this.#throttledQualityChange(event);
704
+ }
705
+ #onDragValueChange(event) {
706
+ this.#throttledQualityChange(event);
707
+ }
708
+ }
709
+
710
+ class SliderChapters extends Component {
711
+ static props = {
712
+ disabled: false
713
+ };
714
+ #media;
715
+ #sliderState;
716
+ #updateScope;
717
+ #titleRef = null;
718
+ #refs = [];
719
+ #$track = signal(null);
720
+ #$cues = signal([]);
721
+ #activeIndex = signal(-1);
722
+ #activePointerIndex = signal(-1);
723
+ #bufferedIndex = 0;
724
+ get cues() {
725
+ return this.#$cues();
726
+ }
727
+ get activeCue() {
728
+ return this.#$cues()[this.#activeIndex()] || null;
729
+ }
730
+ get activePointerCue() {
731
+ return this.#$cues()[this.#activePointerIndex()] || null;
732
+ }
733
+ onSetup() {
734
+ this.#media = useMediaContext();
735
+ this.#sliderState = useState(TimeSlider.state);
736
+ }
737
+ onAttach(el) {
738
+ watchActiveTextTrack(this.#media.textTracks, "chapters", this.#setTrack.bind(this));
739
+ effect(this.#watchSource.bind(this));
740
+ }
741
+ onConnect() {
742
+ onDispose(() => this.#reset.bind(this));
743
+ }
744
+ onDestroy() {
745
+ this.#setTrack(null);
746
+ }
747
+ setRefs(refs) {
748
+ this.#refs = refs;
749
+ this.#updateScope?.dispose();
750
+ if (this.#refs.length === 1) {
751
+ const el = this.#refs[0];
752
+ el.style.width = "100%";
753
+ el.style.setProperty("--chapter-fill", "var(--slider-fill)");
754
+ el.style.setProperty("--chapter-progress", "var(--slider-progress)");
755
+ } else if (this.#refs.length > 0) {
756
+ scoped(() => this.#watch(), this.#updateScope = createScope());
757
+ }
758
+ }
759
+ #setTrack(track) {
760
+ if (peek(this.#$track) === track) return;
761
+ this.#reset();
762
+ this.#$track.set(track);
763
+ }
764
+ #reset() {
765
+ this.#refs = [];
766
+ this.#$cues.set([]);
767
+ this.#activeIndex.set(-1);
768
+ this.#activePointerIndex.set(-1);
769
+ this.#bufferedIndex = 0;
770
+ this.#updateScope?.dispose();
771
+ }
772
+ #watch() {
773
+ if (!this.#refs.length) return;
774
+ effect(this.#watchUpdates.bind(this));
775
+ }
776
+ #watchUpdates() {
777
+ const { hidden } = this.#sliderState;
778
+ if (hidden()) return;
779
+ effect(this.#watchContainerWidths.bind(this));
780
+ effect(this.#watchFillPercent.bind(this));
781
+ effect(this.#watchPointerPercent.bind(this));
782
+ effect(this.#watchBufferedPercent.bind(this));
783
+ }
784
+ #watchContainerWidths() {
785
+ const cues = this.#$cues();
786
+ if (!cues.length) return;
787
+ let cue, { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd() || cues[cues.length - 1].endTime, duration = endTime - startTime, remainingWidth = 100;
788
+ for (let i = 0; i < cues.length; i++) {
789
+ cue = cues[i];
790
+ if (this.#refs[i]) {
791
+ const width = i === cues.length - 1 ? remainingWidth : round((cue.endTime - Math.max(startTime, cue.startTime)) / duration * 100, 3);
792
+ this.#refs[i].style.width = width + "%";
793
+ remainingWidth -= width;
794
+ }
795
+ }
796
+ }
797
+ #watchFillPercent() {
798
+ let { liveEdge, seekableStart, seekableEnd } = this.#media.$state, { fillPercent, value } = this.#sliderState, cues = this.#$cues(), isLiveEdge = liveEdge(), prevActiveIndex = peek(this.#activeIndex), currentChapter = cues[prevActiveIndex];
799
+ let currentActiveIndex = isLiveEdge ? this.#$cues.length - 1 : this.#findActiveChapterIndex(
800
+ currentChapter ? currentChapter.startTime / seekableEnd() * 100 <= peek(value) ? prevActiveIndex : 0 : 0,
801
+ fillPercent()
802
+ );
803
+ if (isLiveEdge || !currentChapter) {
804
+ this.#updateFillPercents(0, cues.length, 100);
805
+ } else if (currentActiveIndex > prevActiveIndex) {
806
+ this.#updateFillPercents(prevActiveIndex, currentActiveIndex, 100);
807
+ } else if (currentActiveIndex < prevActiveIndex) {
808
+ this.#updateFillPercents(currentActiveIndex + 1, prevActiveIndex + 1, 0);
809
+ }
810
+ const percent = isLiveEdge ? 100 : this.#calcPercent(
811
+ cues[currentActiveIndex],
812
+ fillPercent(),
813
+ seekableStart(),
814
+ this.#getEndTime(cues)
815
+ );
816
+ this.#updateFillPercent(this.#refs[currentActiveIndex], percent);
817
+ this.#activeIndex.set(currentActiveIndex);
818
+ }
819
+ #watchPointerPercent() {
820
+ let { hidden, pointerPercent } = this.#sliderState;
821
+ if (hidden()) {
822
+ this.#activePointerIndex.set(-1);
823
+ return;
824
+ }
825
+ const activeIndex = this.#findActiveChapterIndex(0, pointerPercent());
826
+ this.#activePointerIndex.set(activeIndex);
827
+ }
828
+ #updateFillPercents(start, end, percent) {
829
+ for (let i = start; i < end; i++) this.#updateFillPercent(this.#refs[i], percent);
830
+ }
831
+ #updateFillPercent(ref, percent) {
832
+ if (!ref) return;
833
+ ref.style.setProperty("--chapter-fill", percent + "%");
834
+ setAttribute(ref, "data-active", percent > 0 && percent < 100);
835
+ setAttribute(ref, "data-ended", percent === 100);
836
+ }
837
+ #findActiveChapterIndex(startIndex, percent) {
838
+ let chapterPercent = 0, cues = this.#$cues();
839
+ if (percent === 0) return 0;
840
+ else if (percent === 100) return cues.length - 1;
841
+ let { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
842
+ for (let i = startIndex; i < cues.length; i++) {
843
+ chapterPercent = this.#calcPercent(cues[i], percent, startTime, endTime);
844
+ if (chapterPercent >= 0 && chapterPercent < 100) return i;
845
+ }
846
+ return 0;
847
+ }
848
+ #watchBufferedPercent() {
849
+ this.#updateBufferedPercent(this.#bufferedPercent());
850
+ }
851
+ #updateBufferedPercent = animationFrameThrottle((bufferedPercent) => {
852
+ let percent, cues = this.#$cues(), { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
853
+ for (let i = this.#bufferedIndex; i < this.#refs.length; i++) {
854
+ percent = this.#calcPercent(cues[i], bufferedPercent, startTime, endTime);
855
+ this.#refs[i]?.style.setProperty("--chapter-progress", percent + "%");
856
+ if (percent < 100) {
857
+ this.#bufferedIndex = i;
858
+ break;
859
+ }
860
+ }
861
+ });
862
+ #bufferedPercent = computed(this.#calcMediaBufferedPercent.bind(this));
863
+ #calcMediaBufferedPercent() {
864
+ const { bufferedEnd, duration } = this.#media.$state;
865
+ return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1), 3) * 100;
866
+ }
867
+ #getEndTime(cues) {
868
+ const { seekableEnd } = this.#media.$state, endTime = seekableEnd();
869
+ return Number.isFinite(endTime) ? endTime : cues[cues.length - 1]?.endTime || 0;
870
+ }
871
+ #calcPercent(cue, percent, startTime, endTime) {
872
+ if (!cue) return 0;
873
+ const cues = this.#$cues();
874
+ if (cues.length === 0) return 0;
875
+ const duration = endTime - startTime, cueStartTime = Math.max(0, cue.startTime - startTime), cueEndTime = Math.min(endTime, cue.endTime) - startTime;
876
+ const startRatio = cueStartTime / duration, startPercent = startRatio * 100, endPercent = Math.min(1, startRatio + (cueEndTime - cueStartTime) / duration) * 100;
877
+ return Math.max(
878
+ 0,
879
+ round(
880
+ percent >= endPercent ? 100 : (percent - startPercent) / (endPercent - startPercent) * 100,
881
+ 3
882
+ )
883
+ );
884
+ }
885
+ #fillGaps(cues) {
886
+ let chapters = [], { seekableStart, seekableEnd, duration } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
887
+ cues = cues.filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime);
888
+ const firstCue = cues[0];
889
+ if (firstCue && firstCue.startTime > startTime) {
890
+ chapters.push(new window.VTTCue(startTime, firstCue.startTime, ""));
891
+ }
892
+ for (let i = 0; i < cues.length - 1; i++) {
893
+ const currentCue = cues[i], nextCue = cues[i + 1];
894
+ chapters.push(currentCue);
895
+ if (nextCue) {
896
+ const timeDiff = nextCue.startTime - currentCue.endTime;
897
+ if (timeDiff > 0) {
898
+ chapters.push(new window.VTTCue(currentCue.endTime, currentCue.endTime + timeDiff, ""));
899
+ }
900
+ }
901
+ }
902
+ const lastCue = cues[cues.length - 1];
903
+ if (lastCue) {
904
+ chapters.push(lastCue);
905
+ const endTime2 = duration();
906
+ if (endTime2 >= 0 && endTime2 - lastCue.endTime > 1) {
907
+ chapters.push(new window.VTTCue(lastCue.endTime, duration(), ""));
908
+ }
909
+ }
910
+ return chapters;
911
+ }
912
+ #watchSource() {
913
+ const { source } = this.#media.$state;
914
+ source();
915
+ this.#onTrackChange();
916
+ }
917
+ #onTrackChange() {
918
+ if (!this.scope) return;
919
+ const { disabled } = this.$props;
920
+ if (disabled()) {
921
+ this.#$cues.set([]);
922
+ this.#activeIndex.set(0);
923
+ this.#bufferedIndex = 0;
924
+ return;
925
+ }
926
+ const track = this.#$track();
927
+ if (track) {
928
+ const onCuesChange = this.#onCuesChange.bind(this);
929
+ onCuesChange();
930
+ new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
931
+ effect(this.#watchMediaDuration.bind(this));
932
+ }
933
+ this.#titleRef = this.#findChapterTitleRef();
934
+ if (this.#titleRef) effect(this.#onChapterTitleChange.bind(this));
935
+ return () => {
936
+ if (this.#titleRef) {
937
+ this.#titleRef.textContent = "";
938
+ this.#titleRef = null;
939
+ }
940
+ };
941
+ }
942
+ #watchMediaDuration() {
943
+ this.#media.$state.duration();
944
+ this.#onCuesChange();
945
+ }
946
+ #onCuesChange = functionDebounce(
947
+ () => {
948
+ const track = peek(this.#$track);
949
+ if (!this.scope || !track || !track.cues.length) return;
950
+ this.#$cues.set(this.#fillGaps(track.cues));
951
+ this.#activeIndex.set(0);
952
+ this.#bufferedIndex = 0;
953
+ },
954
+ 150,
955
+ true
956
+ );
957
+ #onChapterTitleChange() {
958
+ const cue = this.activePointerCue || this.activeCue;
959
+ if (this.#titleRef) this.#titleRef.textContent = cue?.text || "";
960
+ }
961
+ #findParentSlider() {
962
+ let node = this.el;
963
+ while (node && node.getAttribute("role") !== "slider") {
964
+ node = node.parentElement;
965
+ }
966
+ return node;
967
+ }
968
+ #findChapterTitleRef() {
969
+ const slider = this.#findParentSlider();
970
+ return slider ? slider.querySelector('[data-part="chapter-title"]') : null;
971
+ }
972
+ }
973
+ const sliderchapters__proto = SliderChapters.prototype;
974
+ prop(sliderchapters__proto, "cues");
975
+ prop(sliderchapters__proto, "activeCue");
976
+ prop(sliderchapters__proto, "activePointerCue");
977
+ method(sliderchapters__proto, "setRefs");
978
+
979
+ class RadioGroup extends Component {
980
+ static props = {
981
+ value: ""
982
+ };
983
+ #controller;
984
+ /**
985
+ * A list of radio values that belong this group.
986
+ */
987
+ get values() {
988
+ return this.#controller.values;
989
+ }
990
+ /**
991
+ * The radio value that is checked in this group.
992
+ */
993
+ get value() {
994
+ return this.#controller.value;
995
+ }
996
+ set value(newValue) {
997
+ this.#controller.value = newValue;
998
+ }
999
+ constructor() {
1000
+ super();
1001
+ this.#controller = new RadioGroupController();
1002
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
1003
+ }
1004
+ onSetup() {
1005
+ effect(this.#watchValue.bind(this));
1006
+ }
1007
+ #watchValue() {
1008
+ this.#controller.value = this.$props.value();
1009
+ }
1010
+ #onValueChange(value, trigger) {
1011
+ const event = this.createEvent("change", { detail: value, trigger });
1012
+ this.dispatch(event);
1013
+ }
1014
+ }
1015
+ const radiogroup__proto = RadioGroup.prototype;
1016
+ prop(radiogroup__proto, "values");
1017
+ prop(radiogroup__proto, "value");
1018
+
1019
+ var __defProp = Object.defineProperty;
1020
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1021
+ var __decorateClass = (decorators, target, key, kind) => {
1022
+ var result = __getOwnPropDesc(target, key) ;
1023
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1024
+ if (decorator = decorators[i])
1025
+ result = (decorator(target, key, result) ) || result;
1026
+ if (result) __defProp(target, key, result);
1027
+ return result;
1028
+ };
1029
+ class ChaptersRadioGroup extends Component {
1030
+ static props = {
1031
+ thumbnails: null
1032
+ };
1033
+ #media;
1034
+ #menu;
1035
+ #controller;
1036
+ #track = signal(null);
1037
+ #cues = signal([]);
1038
+ get value() {
1039
+ return this.#controller.value;
1040
+ }
1041
+ get disabled() {
1042
+ return !this.#cues()?.length;
1043
+ }
1044
+ constructor() {
1045
+ super();
1046
+ this.#controller = new RadioGroupController();
1047
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
1048
+ }
1049
+ onSetup() {
1050
+ this.#media = useMediaContext();
1051
+ if (hasProvidedContext(menuContext)) {
1052
+ this.#menu = useContext(menuContext);
1053
+ }
1054
+ const { thumbnails } = this.$props;
1055
+ this.setAttributes({
1056
+ "data-thumbnails": () => !!thumbnails()
1057
+ });
1058
+ }
1059
+ onAttach(el) {
1060
+ this.#menu?.attachObserver({
1061
+ onOpen: this.#onOpen.bind(this)
1062
+ });
1063
+ }
1064
+ getOptions() {
1065
+ const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1066
+ return this.#cues().map((cue, i) => ({
1067
+ cue,
1068
+ value: i.toString(),
1069
+ label: cue.text,
1070
+ startTime: formatTime(Math.max(0, cue.startTime - startTime)),
1071
+ duration: formatSpokenTime(
1072
+ Math.min(endTime, cue.endTime) - Math.max(startTime, cue.startTime)
1073
+ )
1074
+ }));
1075
+ }
1076
+ #onOpen() {
1077
+ peek(() => this.#watchCurrentTime());
1078
+ }
1079
+ onConnect(el) {
1080
+ effect(this.#watchCurrentTime.bind(this));
1081
+ effect(this.#watchControllerDisabled.bind(this));
1082
+ effect(this.#watchTrack.bind(this));
1083
+ watchActiveTextTrack(this.#media.textTracks, "chapters", this.#track.set);
1084
+ }
1085
+ #watchTrack() {
1086
+ const track = this.#track();
1087
+ if (!track) return;
1088
+ const onCuesChange = this.#onCuesChange.bind(this, track);
1089
+ onCuesChange();
1090
+ new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
1091
+ return () => {
1092
+ this.#cues.set([]);
1093
+ };
1094
+ }
1095
+ #onCuesChange(track) {
1096
+ const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1097
+ this.#cues.set(
1098
+ [...track.cues].filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime)
1099
+ );
1100
+ }
1101
+ #watchCurrentTime() {
1102
+ if (!this.#menu?.expanded()) return;
1103
+ const track = this.#track();
1104
+ if (!track) {
1105
+ this.#controller.value = "-1";
1106
+ return;
1107
+ }
1108
+ const { realCurrentTime, seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd(), time = realCurrentTime(), activeCueIndex = this.#cues().findIndex((cue) => isCueActive(cue, time));
1109
+ this.#controller.value = activeCueIndex.toString();
1110
+ if (activeCueIndex >= 0) {
1111
+ requestScopedAnimationFrame(() => {
1112
+ if (!this.connectScope) return;
1113
+ 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;
1114
+ radio && setStyle(radio, "--progress", round(playedPercent, 3) + "%");
1115
+ });
1116
+ }
1117
+ }
1118
+ #watchControllerDisabled() {
1119
+ this.#menu?.disable(this.disabled);
1120
+ }
1121
+ #onValueChange(value, trigger) {
1122
+ if (this.disabled || !trigger) return;
1123
+ const index = +value, cues = this.#cues(), { clipStartTime } = this.#media.$state;
1124
+ if (isNumber(index) && cues?.[index]) {
1125
+ this.#controller.value = index.toString();
1126
+ this.#media.remote.seek(cues[index].startTime - clipStartTime(), trigger);
1127
+ this.dispatch("change", { detail: cues[index], trigger });
1128
+ }
1129
+ }
1130
+ }
1131
+ __decorateClass([
1132
+ prop
1133
+ ], ChaptersRadioGroup.prototype, "value");
1134
+ __decorateClass([
1135
+ prop
1136
+ ], ChaptersRadioGroup.prototype, "disabled");
1137
+ __decorateClass([
1138
+ method
1139
+ ], ChaptersRadioGroup.prototype, "getOptions");
1140
+
1141
+ const DEFAULT_AUDIO_GAINS = [1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4];
1142
+ class AudioGainRadioGroup extends Component {
1143
+ static props = {
1144
+ normalLabel: "Disabled",
1145
+ gains: DEFAULT_AUDIO_GAINS
1146
+ };
1147
+ #media;
1148
+ #menu;
1149
+ #controller;
1150
+ get value() {
1151
+ return this.#controller.value;
1152
+ }
1153
+ get disabled() {
1154
+ const { gains } = this.$props, { canSetAudioGain } = this.#media.$state;
1155
+ return !canSetAudioGain() || gains().length === 0;
1156
+ }
1157
+ constructor() {
1158
+ super();
1159
+ this.#controller = new RadioGroupController();
1160
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
1161
+ }
1162
+ onSetup() {
1163
+ this.#media = useMediaContext();
1164
+ if (hasProvidedContext(menuContext)) {
1165
+ this.#menu = useContext(menuContext);
1166
+ }
1167
+ }
1168
+ onConnect(el) {
1169
+ effect(this.#watchValue.bind(this));
1170
+ effect(this.#watchHintText.bind(this));
1171
+ effect(this.#watchControllerDisabled.bind(this));
1172
+ }
1173
+ getOptions() {
1174
+ const { gains, normalLabel } = this.$props;
1175
+ return gains().map((gain) => ({
1176
+ label: gain === 1 || gain === null ? normalLabel : String(gain * 100) + "%",
1177
+ value: gain.toString()
1178
+ }));
1179
+ }
1180
+ #watchValue() {
1181
+ this.#controller.value = this.#getValue();
1182
+ }
1183
+ #watchHintText() {
1184
+ const { normalLabel } = this.$props, { audioGain } = this.#media.$state, gain = audioGain();
1185
+ this.#menu?.hint.set(gain === 1 || gain == null ? normalLabel() : String(gain * 100) + "%");
1186
+ }
1187
+ #watchControllerDisabled() {
1188
+ this.#menu?.disable(this.disabled);
1189
+ }
1190
+ #getValue() {
1191
+ const { audioGain } = this.#media.$state;
1192
+ return audioGain()?.toString() ?? "1";
1193
+ }
1194
+ #onValueChange(value, trigger) {
1195
+ if (this.disabled) return;
1196
+ const gain = +value;
1197
+ this.#media.remote.changeAudioGain(gain, trigger);
1198
+ this.dispatch("change", { detail: gain, trigger });
1199
+ }
1200
+ }
1201
+ const audiogainradiogroup__proto = AudioGainRadioGroup.prototype;
1202
+ prop(audiogainradiogroup__proto, "value");
1203
+ prop(audiogainradiogroup__proto, "disabled");
1204
+ method(audiogainradiogroup__proto, "getOptions");
1205
+
1206
+ class Gesture extends Component {
1207
+ static props = {
1208
+ disabled: false,
1209
+ event: void 0,
1210
+ action: void 0
1211
+ };
1212
+ #media;
1213
+ #provider = null;
1214
+ onSetup() {
1215
+ this.#media = useMediaContext();
1216
+ const { event, action } = this.$props;
1217
+ this.setAttributes({
1218
+ event,
1219
+ action
1220
+ });
1221
+ }
1222
+ onAttach(el) {
1223
+ el.setAttribute("data-media-gesture", "");
1224
+ el.style.setProperty("pointer-events", "none");
1225
+ }
1226
+ onConnect(el) {
1227
+ this.#provider = this.#media.player.el?.querySelector(
1228
+ "[data-media-provider]"
1229
+ );
1230
+ effect(this.#attachListener.bind(this));
1231
+ }
1232
+ #attachListener() {
1233
+ let eventType = this.$props.event(), disabled = this.$props.disabled();
1234
+ if (!this.#provider || !eventType || disabled) return;
1235
+ if (/^dbl/.test(eventType)) {
1236
+ eventType = eventType.split(/^dbl/)[1];
1237
+ }
1238
+ if (eventType === "pointerup" || eventType === "pointerdown") {
1239
+ const pointer = this.#media.$state.pointer();
1240
+ if (pointer === "coarse") {
1241
+ eventType = eventType === "pointerup" ? "touchend" : "touchstart";
1242
+ }
1243
+ }
1244
+ listenEvent(
1245
+ this.#provider,
1246
+ eventType,
1247
+ this.#acceptEvent.bind(this),
1248
+ { passive: false }
1249
+ );
1250
+ }
1251
+ #presses = 0;
1252
+ #pressTimerId = -1;
1253
+ #acceptEvent(event) {
1254
+ if (this.$props.disabled() || isPointerEvent(event) && (event.button !== 0 || this.#media.activeMenu) || isTouchEvent(event) && this.#media.activeMenu || isTouchPinchEvent(event) || !this.#inBounds(event)) {
1255
+ return;
1256
+ }
1257
+ event.MEDIA_GESTURE = true;
1258
+ event.preventDefault();
1259
+ const eventType = peek(this.$props.event), isDblEvent = eventType?.startsWith("dbl");
1260
+ if (!isDblEvent) {
1261
+ if (this.#presses === 0) {
1262
+ setTimeout(() => {
1263
+ if (this.#presses === 1) this.#handleEvent(event);
1264
+ }, 250);
1265
+ }
1266
+ } else if (this.#presses === 1) {
1267
+ queueMicrotask(() => this.#handleEvent(event));
1268
+ clearTimeout(this.#pressTimerId);
1269
+ this.#presses = 0;
1270
+ return;
1271
+ }
1272
+ if (this.#presses === 0) {
1273
+ this.#pressTimerId = window.setTimeout(() => {
1274
+ this.#presses = 0;
1275
+ }, 275);
1276
+ }
1277
+ this.#presses++;
1278
+ }
1279
+ #handleEvent(event) {
1280
+ this.el.setAttribute("data-triggered", "");
1281
+ requestAnimationFrame(() => {
1282
+ if (this.#isTopLayer()) {
1283
+ this.#performAction(peek(this.$props.action), event);
1284
+ }
1285
+ requestAnimationFrame(() => {
1286
+ this.el.removeAttribute("data-triggered");
1287
+ });
1288
+ });
1289
+ }
1290
+ /** Validate event occurred in gesture bounds. */
1291
+ #inBounds(event) {
1292
+ if (!this.el) return false;
1293
+ if (isPointerEvent(event) || isMouseEvent(event) || isTouchEvent(event)) {
1294
+ const touch = isTouchEvent(event) ? event.changedTouches[0] ?? event.touches[0] : void 0;
1295
+ const clientX = touch?.clientX ?? event.clientX;
1296
+ const clientY = touch?.clientY ?? event.clientY;
1297
+ const rect = this.el.getBoundingClientRect();
1298
+ const inBounds = clientY >= rect.top && clientY <= rect.bottom && clientX >= rect.left && clientX <= rect.right;
1299
+ return event.type.includes("leave") ? !inBounds : inBounds;
1300
+ }
1301
+ return true;
1302
+ }
1303
+ /** Validate gesture has the highest z-index in this triggered group. */
1304
+ #isTopLayer() {
1305
+ const gestures = this.#media.player.el.querySelectorAll(
1306
+ "[data-media-gesture][data-triggered]"
1307
+ );
1308
+ return Array.from(gestures).sort(
1309
+ (a, b) => +getComputedStyle(b).zIndex - +getComputedStyle(a).zIndex
1310
+ )[0] === this.el;
1311
+ }
1312
+ #performAction(action, trigger) {
1313
+ if (!action) return;
1314
+ const willTriggerEvent = new DOMEvent("will-trigger", {
1315
+ detail: action,
1316
+ cancelable: true,
1317
+ trigger
1318
+ });
1319
+ this.dispatchEvent(willTriggerEvent);
1320
+ if (willTriggerEvent.defaultPrevented) return;
1321
+ const [method, value] = action.replace(/:([a-z])/, "-$1").split(":");
1322
+ if (action.includes(":fullscreen")) {
1323
+ this.#media.remote.toggleFullscreen("prefer-media", trigger);
1324
+ } else if (action.includes("seek:")) {
1325
+ this.#media.remote.seek(peek(this.#media.$state.currentTime) + (+value || 0), trigger);
1326
+ } else {
1327
+ this.#media.remote[kebabToCamelCase(method)](trigger);
1328
+ }
1329
+ this.dispatch("trigger", {
1330
+ detail: action,
1331
+ trigger
1332
+ });
1333
+ }
1334
+ }
1335
+
1336
+ class CaptionsTextRenderer {
1337
+ priority = 10;
1338
+ #track = null;
1339
+ #renderer;
1340
+ #events;
1341
+ constructor(renderer) {
1342
+ this.#renderer = renderer;
1343
+ }
1344
+ attach() {
1345
+ }
1346
+ canRender() {
1347
+ return true;
1348
+ }
1349
+ detach() {
1350
+ this.#events?.abort();
1351
+ this.#events = void 0;
1352
+ this.#renderer.reset();
1353
+ this.#track = null;
1354
+ }
1355
+ changeTrack(track) {
1356
+ if (!track || this.#track === track) return;
1357
+ this.#events?.abort();
1358
+ this.#events = new EventsController(track);
1359
+ if (track.readyState < 2) {
1360
+ this.#renderer.reset();
1361
+ this.#events.add("load", () => this.#changeTrack(track), { once: true });
1362
+ } else {
1363
+ this.#changeTrack(track);
1364
+ }
1365
+ this.#events.add("add-cue", (event) => {
1366
+ this.#renderer.addCue(event.detail);
1367
+ }).add("remove-cue", (event) => {
1368
+ this.#renderer.removeCue(event.detail);
1369
+ });
1370
+ this.#track = track;
1371
+ }
1372
+ #changeTrack(track) {
1373
+ this.#renderer.changeTrack({
1374
+ cues: [...track.cues],
1375
+ regions: [...track.regions]
1376
+ });
1377
+ }
1378
+ }
1379
+
1380
+ class Captions extends Component {
1381
+ static props = {
1382
+ textDir: "ltr",
1383
+ exampleText: "Captions look like this."
1384
+ };
1385
+ #media;
1386
+ static lib = signal(null);
1387
+ onSetup() {
1388
+ this.#media = useMediaContext();
1389
+ this.setAttributes({
1390
+ "aria-hidden": $ariaBool(this.#isHidden.bind(this))
1391
+ });
1392
+ }
1393
+ onAttach(el) {
1394
+ el.style.setProperty("pointer-events", "none");
1395
+ }
1396
+ onConnect(el) {
1397
+ if (!Captions.lib()) {
1398
+ import('media-captions').then((lib) => Captions.lib.set(lib));
1399
+ }
1400
+ effect(this.#watchViewType.bind(this));
1401
+ }
1402
+ #isHidden() {
1403
+ const { textTrack, remotePlaybackState, iOSControls } = this.#media.$state, track = textTrack();
1404
+ return iOSControls() || remotePlaybackState() === "connected" || !track || !isTrackCaptionKind(track);
1405
+ }
1406
+ #watchViewType() {
1407
+ if (!Captions.lib()) return;
1408
+ const { viewType } = this.#media.$state;
1409
+ if (viewType() === "audio") {
1410
+ return this.#setupAudioView();
1411
+ } else {
1412
+ return this.#setupVideoView();
1413
+ }
1414
+ }
1415
+ #setupAudioView() {
1416
+ effect(this.#onTrackChange.bind(this));
1417
+ this.#listenToFontStyleChanges(null);
1418
+ return () => {
1419
+ this.el.textContent = "";
1420
+ };
1421
+ }
1422
+ #onTrackChange() {
1423
+ if (this.#isHidden()) return;
1424
+ this.#onCueChange();
1425
+ const { textTrack } = this.#media.$state;
1426
+ listenEvent(textTrack(), "cue-change", this.#onCueChange.bind(this));
1427
+ effect(this.#onUpdateTimedNodes.bind(this));
1428
+ }
1429
+ #onCueChange() {
1430
+ this.el.textContent = "";
1431
+ if (this.#hideExampleTimer >= 0) {
1432
+ this.#removeExample();
1433
+ }
1434
+ const { realCurrentTime, textTrack } = this.#media.$state, { renderVTTCueString } = Captions.lib(), time = peek(realCurrentTime), activeCues = peek(textTrack).activeCues;
1435
+ for (const cue of activeCues) {
1436
+ const displayEl = this.#createCueDisplayElement(), cueEl = this.#createCueElement();
1437
+ cueEl.innerHTML = renderVTTCueString(cue, time);
1438
+ displayEl.append(cueEl);
1439
+ this.el.append(cueEl);
1440
+ }
1441
+ }
1442
+ #onUpdateTimedNodes() {
1443
+ const { realCurrentTime } = this.#media.$state, { updateTimedVTTCueNodes } = Captions.lib();
1444
+ updateTimedVTTCueNodes(this.el, realCurrentTime());
1445
+ }
1446
+ #setupVideoView() {
1447
+ const { CaptionsRenderer } = Captions.lib(), renderer = new CaptionsRenderer(this.el), textRenderer = new CaptionsTextRenderer(renderer);
1448
+ this.#media.textRenderers.add(textRenderer);
1449
+ effect(this.#watchTextDirection.bind(this, renderer));
1450
+ effect(this.#watchMediaTime.bind(this, renderer));
1451
+ this.#listenToFontStyleChanges(renderer);
1452
+ return () => {
1453
+ this.el.textContent = "";
1454
+ this.#media.textRenderers.remove(textRenderer);
1455
+ renderer.destroy();
1456
+ };
1457
+ }
1458
+ #watchTextDirection(renderer) {
1459
+ renderer.dir = this.$props.textDir();
1460
+ }
1461
+ #watchMediaTime(renderer) {
1462
+ if (this.#isHidden()) return;
1463
+ const { realCurrentTime, textTrack } = this.#media.$state;
1464
+ renderer.currentTime = realCurrentTime();
1465
+ if (this.#hideExampleTimer >= 0 && textTrack()?.activeCues[0]) {
1466
+ this.#removeExample();
1467
+ }
1468
+ }
1469
+ #listenToFontStyleChanges(renderer) {
1470
+ const player = this.#media.player;
1471
+ if (!player) return;
1472
+ const onChange = this.#onFontStyleChange.bind(this, renderer);
1473
+ listenEvent(player, "vds-font-change", onChange);
1474
+ }
1475
+ #onFontStyleChange(renderer) {
1476
+ if (this.#hideExampleTimer >= 0) {
1477
+ this.#hideExample();
1478
+ return;
1479
+ }
1480
+ const { textTrack } = this.#media.$state;
1481
+ if (!textTrack()?.activeCues[0]) {
1482
+ this.#showExample();
1483
+ } else {
1484
+ renderer?.update(true);
1485
+ }
1486
+ }
1487
+ #showExample() {
1488
+ const display = this.#createCueDisplayElement();
1489
+ setAttribute(display, "data-example", "");
1490
+ const cue = this.#createCueElement();
1491
+ setAttribute(cue, "data-example", "");
1492
+ cue.textContent = this.$props.exampleText();
1493
+ display?.append(cue);
1494
+ this.el?.append(display);
1495
+ this.el?.setAttribute("data-example", "");
1496
+ this.#hideExample();
1497
+ }
1498
+ #hideExampleTimer = -1;
1499
+ #hideExample() {
1500
+ window.clearTimeout(this.#hideExampleTimer);
1501
+ this.#hideExampleTimer = window.setTimeout(this.#removeExample.bind(this), 2500);
1502
+ }
1503
+ #removeExample() {
1504
+ this.el?.removeAttribute("data-example");
1505
+ if (this.el?.querySelector("[data-example]")) this.el.textContent = "";
1506
+ this.#hideExampleTimer = -1;
1507
+ }
1508
+ #createCueDisplayElement() {
1509
+ const el = document.createElement("div");
1510
+ setAttribute(el, "data-part", "cue-display");
1511
+ return el;
1512
+ }
1513
+ #createCueElement() {
1514
+ const el = document.createElement("div");
1515
+ setAttribute(el, "data-part", "cue");
1516
+ return el;
1517
+ }
1518
+ }
1519
+
1520
+ export { AudioGainRadioGroup, AudioGainSlider, Captions, ChaptersRadioGroup, Controls, ControlsGroup, DEFAULT_AUDIO_GAINS, Gesture, GoogleCastButton, MediaAnnouncer, QualitySlider, RadioGroup, SliderChapters, SliderVideo, SpeedSlider, ToggleButton, Tooltip, TooltipContent, TooltipTrigger };