@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.
Files changed (92) hide show
  1. package/cdn/chunks/vidstack-8JHLDxl5.js +1 -0
  2. package/cdn/chunks/vidstack-Bpnl-N6k.js +1 -0
  3. package/cdn/chunks/vidstack-CnWKPIKT.js +16 -0
  4. package/cdn/chunks/vidstack-CqzAnF2W.js +16 -0
  5. package/cdn/vidstack.js +1 -1
  6. package/cdn/with-layouts/chunks/vidstack-BD5YoTt5.js +937 -0
  7. package/cdn/with-layouts/chunks/vidstack-DCaNJN4T.js +1 -0
  8. package/cdn/with-layouts/chunks/vidstack-Dd3L-eQj.js +1 -0
  9. package/cdn/with-layouts/chunks/vidstack-T2rZVigk.js +912 -0
  10. package/cdn/with-layouts/vidstack.js +1 -1
  11. package/dev/chunks/vidstack--aukHYxl.js +1520 -0
  12. package/dev/chunks/vidstack-B__DfQsT.js +1621 -0
  13. package/dev/chunks/vidstack-BoLIUOyq.js +204 -0
  14. package/dev/chunks/vidstack-CSryZFvY.js +1521 -0
  15. package/dev/chunks/vidstack-Cky9ors4.js +297 -0
  16. package/dev/chunks/vidstack-Crz0ROkT.js +3009 -0
  17. package/dev/chunks/vidstack-D-sqb6YI.js +308 -0
  18. package/dev/chunks/vidstack-DLXCqdYV.js +3010 -0
  19. package/dev/chunks/vidstack-DS7nRfge.js +204 -0
  20. package/dev/chunks/vidstack-Dco6kA4h.js +104 -0
  21. package/dev/chunks/vidstack-DpS0Kt4b.js +297 -0
  22. package/dev/chunks/vidstack-zJT-7ncH.js +5182 -0
  23. package/dev/define/plyr-layout.js +3 -4
  24. package/dev/define/templates/vidstack-audio-layout.js +4 -4
  25. package/dev/define/templates/vidstack-video-layout.js +4 -4
  26. package/dev/define/vidstack-player-default-layout.js +4 -4
  27. package/dev/define/vidstack-player-layouts.js +4 -4
  28. package/dev/define/vidstack-player-ui.js +5 -6
  29. package/dev/define/vidstack-player.js +3 -4
  30. package/dev/global/plyr.js +5 -6
  31. package/dev/global/vidstack-player.js +3 -4
  32. package/dev/providers/vidstack-dash.js +1 -2
  33. package/dev/providers/vidstack-hls.js +1 -2
  34. package/dev/providers/vidstack-video.js +1 -2
  35. package/dev/providers/vidstack-vimeo.js +1 -2
  36. package/dev/vidstack-elements.js +8 -9
  37. package/dev/vidstack.js +6 -7
  38. package/package.json +2 -1
  39. package/prod/chunks/vidstack-BVSJtdRd.js +297 -0
  40. package/prod/chunks/vidstack-BnEo_Sla.js +1621 -0
  41. package/prod/chunks/vidstack-CFXAYpuh.js +1521 -0
  42. package/prod/chunks/vidstack-CIvL96_j.js +297 -0
  43. package/prod/chunks/vidstack-CLTPjjXX.js +4772 -0
  44. package/prod/chunks/vidstack-CSHHV2zO.js +201 -0
  45. package/prod/chunks/vidstack-CYVCrFjx.js +201 -0
  46. package/prod/chunks/vidstack-D_atbNqH.js +3000 -0
  47. package/prod/chunks/vidstack-Eo46ZHu7.js +2999 -0
  48. package/prod/chunks/vidstack-sP7TQMB1.js +300 -0
  49. package/prod/chunks/vidstack-uVm3xX8H.js +104 -0
  50. package/prod/chunks/vidstack-zknLxihl.js +1520 -0
  51. package/prod/define/plyr-layout.js +3 -4
  52. package/prod/define/templates/vidstack-audio-layout.js +4 -4
  53. package/prod/define/templates/vidstack-video-layout.js +4 -4
  54. package/prod/define/vidstack-player-default-layout.js +4 -4
  55. package/prod/define/vidstack-player-layouts.js +4 -4
  56. package/prod/define/vidstack-player-ui.js +5 -6
  57. package/prod/define/vidstack-player.js +3 -4
  58. package/prod/global/plyr.js +5 -6
  59. package/prod/global/vidstack-player.js +3 -4
  60. package/prod/providers/vidstack-dash.js +1 -2
  61. package/prod/providers/vidstack-hls.js +1 -2
  62. package/prod/providers/vidstack-video.js +1 -2
  63. package/prod/providers/vidstack-vimeo.js +1 -2
  64. package/prod/vidstack-elements.js +8 -9
  65. package/prod/vidstack.js +6 -7
  66. package/server/chunks/vidstack-B3eA67nX.js +205 -0
  67. package/server/chunks/vidstack-B8P1aUCK.js +1503 -0
  68. package/server/chunks/vidstack-B8_v1VQn.js +3059 -0
  69. package/server/chunks/vidstack-BK4xGWUK.js +207 -0
  70. package/server/chunks/vidstack-BO8FLks6.js +295 -0
  71. package/server/chunks/vidstack-BaXvZgx2.js +141 -0
  72. package/server/chunks/vidstack-BlvJg_5A.js +4636 -0
  73. package/server/chunks/vidstack-CBhikwSz.js +67 -0
  74. package/server/chunks/vidstack-COczNXom.js +3059 -0
  75. package/server/chunks/vidstack-CyZPtpwO.js +1503 -0
  76. package/server/chunks/vidstack-Db22EuE_.js +207 -0
  77. package/server/chunks/vidstack-Dh1ZDEI-.js +29 -0
  78. package/server/chunks/vidstack-Dm-ETAZh.js +295 -0
  79. package/server/chunks/vidstack-NpAD9hfP.js +620 -0
  80. package/server/chunks/vidstack-O4BgIcQI.js +104 -0
  81. package/server/chunks/vidstack-n4zAyLEV.js +2139 -0
  82. package/server/chunks/vidstack-za5Yh5DQ.js +566 -0
  83. package/server/chunks/vidstack-zoXyfYxa.js +107 -0
  84. package/server/define/plyr-layout.js +7 -7
  85. package/server/define/vidstack-player-default-layout.js +3 -3
  86. package/server/define/vidstack-player-layouts.js +5 -5
  87. package/server/define/vidstack-player-ui.js +6 -6
  88. package/server/define/vidstack-player.js +4 -4
  89. package/server/global/plyr.js +9 -9
  90. package/server/global/vidstack-player.js +4 -4
  91. package/server/vidstack-elements.js +13 -13
  92. package/server/vidstack.js +8 -8
@@ -0,0 +1,1520 @@
1
+ import { Component, State, effect, tick, peek, setAttribute, isString, setStyle, createContext, signal, EventsController, provideContext, listenEvent, onDispose, useContext, prop, useState, isNull, functionThrottle, computed, method, scoped, createScope, animationFrameThrottle, functionDebounce, hasProvidedContext, isNumber, isPointerEvent, isTouchEvent, isMouseEvent, DOMEvent, kebabToCamelCase } from './vidstack-BNpgCJJ1.js';
2
+ import { useMediaContext } from './vidstack-tt3O1zL6.js';
3
+ import { setAttributeIfEmpty, requestScopedAnimationFrame, autoPlacement, $ariaBool, setARIALabel, isTouchPinchEvent } from './vidstack-DB9WDRL5.js';
4
+ import { formatSpokenTime, Popper, ToggleButtonController, Slider, SliderController, sliderState, sliderValueFormatContext, TimeSlider, RadioGroupController, menuContext, formatTime } from './vidstack-Eo46ZHu7.js';
5
+ import { FocusVisibleController, $keyboard } from './vidstack-COLU-zPZ.js';
6
+ import { round } from './vidstack-Dihypf8P.js';
7
+ import { sortVideoQualities } from './vidstack-BTM4ERc7.js';
8
+ import { watchActiveTextTrack, isCueActive, isTrackCaptionKind } from './vidstack-sP7TQMB1.js';
9
+
10
+ class MediaAnnouncer extends Component {
11
+ static props = {
12
+ translations: null
13
+ };
14
+ static state = new State({
15
+ label: null,
16
+ busy: false
17
+ });
18
+ #media;
19
+ #initializing = false;
20
+ onSetup() {
21
+ this.#media = useMediaContext();
22
+ }
23
+ onAttach(el) {
24
+ el.style.display = "contents";
25
+ }
26
+ onConnect(el) {
27
+ el.setAttribute("data-media-announcer", "");
28
+ setAttributeIfEmpty(el, "role", "status");
29
+ setAttributeIfEmpty(el, "aria-live", "polite");
30
+ const { busy } = this.$state;
31
+ this.setAttributes({
32
+ "aria-busy": () => busy() ? "true" : null
33
+ });
34
+ this.#initializing = true;
35
+ effect(this.#watchPaused.bind(this));
36
+ effect(this.#watchVolume.bind(this));
37
+ effect(this.#watchCaptions.bind(this));
38
+ effect(this.#watchFullscreen.bind(this));
39
+ effect(this.#watchPiP.bind(this));
40
+ effect(this.#watchSeeking.bind(this));
41
+ effect(this.#watchLabel.bind(this));
42
+ tick();
43
+ this.#initializing = false;
44
+ }
45
+ #watchPaused() {
46
+ const { paused } = this.#media.$state;
47
+ this.#setLabel(!paused() ? "Play" : "Pause");
48
+ }
49
+ #watchFullscreen() {
50
+ const { fullscreen } = this.#media.$state;
51
+ this.#setLabel(fullscreen() ? "Enter Fullscreen" : "Exit Fullscreen");
52
+ }
53
+ #watchPiP() {
54
+ const { pictureInPicture } = this.#media.$state;
55
+ this.#setLabel(pictureInPicture() ? "Enter PiP" : "Exit PiP");
56
+ }
57
+ #watchCaptions() {
58
+ const { textTrack } = this.#media.$state;
59
+ this.#setLabel(textTrack() ? "Closed-Captions On" : "Closed-Captions Off");
60
+ }
61
+ #watchVolume() {
62
+ const { muted, volume, audioGain } = this.#media.$state;
63
+ this.#setLabel(
64
+ muted() || volume() === 0 ? "Mute" : `${Math.round(volume() * (audioGain() ?? 1) * 100)}% ${this.#translate("Volume")}`
65
+ );
66
+ }
67
+ #startedSeekingAt = -1;
68
+ #seekTimer = -1;
69
+ #watchSeeking() {
70
+ const { seeking, currentTime } = this.#media.$state, isSeeking = seeking();
71
+ if (this.#startedSeekingAt > 0) {
72
+ window.clearTimeout(this.#seekTimer);
73
+ this.#seekTimer = window.setTimeout(() => {
74
+ if (!this.scope) return;
75
+ const newTime = peek(currentTime), seconds = Math.abs(newTime - this.#startedSeekingAt);
76
+ if (seconds >= 1) {
77
+ const isForward = newTime >= this.#startedSeekingAt, spokenTime = formatSpokenTime(seconds);
78
+ this.#setLabel(
79
+ `${this.#translate(isForward ? "Seek Forward" : "Seek Backward")} ${spokenTime}`
80
+ );
81
+ }
82
+ this.#startedSeekingAt = -1;
83
+ this.#seekTimer = -1;
84
+ }, 300);
85
+ } else if (isSeeking) {
86
+ this.#startedSeekingAt = peek(currentTime);
87
+ }
88
+ }
89
+ #translate(word) {
90
+ const { translations } = this.$props;
91
+ return translations?.()?.[word || ""] ?? word;
92
+ }
93
+ #watchLabel() {
94
+ const { label, busy } = this.$state, $label = this.#translate(label());
95
+ if (this.#initializing) return;
96
+ busy.set(true);
97
+ const id = window.setTimeout(() => void busy.set(false), 150);
98
+ this.el && setAttribute(this.el, "aria-label", $label);
99
+ if (isString($label)) {
100
+ this.dispatch("change", { detail: $label });
101
+ }
102
+ return () => window.clearTimeout(id);
103
+ }
104
+ #setLabel(word) {
105
+ const { label } = this.$state;
106
+ label.set(word);
107
+ }
108
+ }
109
+
110
+ class Controls extends Component {
111
+ static props = {
112
+ hideDelay: 2e3,
113
+ hideOnMouseLeave: false
114
+ };
115
+ #media;
116
+ onSetup() {
117
+ this.#media = useMediaContext();
118
+ effect(this.#watchProps.bind(this));
119
+ }
120
+ onAttach(el) {
121
+ const { pictureInPicture, fullscreen } = this.#media.$state;
122
+ setStyle(el, "pointer-events", "none");
123
+ setAttributeIfEmpty(el, "role", "group");
124
+ this.setAttributes({
125
+ "data-visible": this.#isShowing.bind(this),
126
+ "data-fullscreen": fullscreen,
127
+ "data-pip": pictureInPicture
128
+ });
129
+ effect(() => {
130
+ this.dispatch("change", { detail: this.#isShowing() });
131
+ });
132
+ effect(this.#hideControls.bind(this));
133
+ effect(() => {
134
+ const isFullscreen = fullscreen();
135
+ for (const side of ["top", "right", "bottom", "left"]) {
136
+ setStyle(el, `padding-${side}`, isFullscreen && `env(safe-area-inset-${side})`);
137
+ }
138
+ });
139
+ }
140
+ #hideControls() {
141
+ if (!this.el) return;
142
+ const { nativeControls } = this.#media.$state, isHidden = nativeControls();
143
+ setAttribute(this.el, "aria-hidden", isHidden ? "true" : null);
144
+ setStyle(this.el, "display", isHidden ? "none" : null);
145
+ }
146
+ #watchProps() {
147
+ const { controls } = this.#media.player, { hideDelay, hideOnMouseLeave } = this.$props;
148
+ controls.defaultDelay = hideDelay() === 2e3 ? this.#media.$props.controlsDelay() : hideDelay();
149
+ controls.hideOnMouseLeave = hideOnMouseLeave();
150
+ }
151
+ #isShowing() {
152
+ const { controlsVisible } = this.#media.$state;
153
+ return controlsVisible();
154
+ }
155
+ }
156
+
157
+ class ControlsGroup extends Component {
158
+ onAttach(el) {
159
+ if (!el.style.pointerEvents) setStyle(el, "pointer-events", "auto");
160
+ }
161
+ }
162
+
163
+ const tooltipContext = createContext();
164
+
165
+ let id = 0;
166
+ class Tooltip extends Component {
167
+ static props = {
168
+ showDelay: 700
169
+ };
170
+ #id = `media-tooltip-${++id}`;
171
+ #trigger = signal(null);
172
+ #content = signal(null);
173
+ #showing = signal(false);
174
+ constructor() {
175
+ super();
176
+ new FocusVisibleController();
177
+ const { showDelay } = this.$props;
178
+ new Popper({
179
+ trigger: this.#trigger,
180
+ content: this.#content,
181
+ showDelay,
182
+ listen(trigger, show, hide) {
183
+ effect(() => {
184
+ if ($keyboard()) listenEvent(trigger, "focus", show);
185
+ listenEvent(trigger, "blur", hide);
186
+ });
187
+ new EventsController(trigger).add("touchstart", (e) => e.preventDefault(), { passive: false }).add("mouseenter", show).add("mouseleave", hide);
188
+ },
189
+ onChange: this.#onShowingChange.bind(this)
190
+ });
191
+ }
192
+ onAttach(el) {
193
+ el.style.setProperty("display", "contents");
194
+ }
195
+ onSetup() {
196
+ provideContext(tooltipContext, {
197
+ trigger: this.#trigger,
198
+ content: this.#content,
199
+ showing: this.#showing,
200
+ attachTrigger: this.#attachTrigger.bind(this),
201
+ detachTrigger: this.#detachTrigger.bind(this),
202
+ attachContent: this.#attachContent.bind(this),
203
+ detachContent: this.#detachContent.bind(this)
204
+ });
205
+ }
206
+ #attachTrigger(el) {
207
+ this.#trigger.set(el);
208
+ let tooltipName = el.getAttribute("data-media-tooltip");
209
+ if (tooltipName) {
210
+ this.el?.setAttribute(`data-media-${tooltipName}-tooltip`, "");
211
+ }
212
+ setAttribute(el, "data-describedby", this.#id);
213
+ }
214
+ #detachTrigger(el) {
215
+ el.removeAttribute("data-describedby");
216
+ el.removeAttribute("aria-describedby");
217
+ this.#trigger.set(null);
218
+ }
219
+ #attachContent(el) {
220
+ el.setAttribute("id", this.#id);
221
+ el.style.display = "none";
222
+ setAttributeIfEmpty(el, "role", "tooltip");
223
+ this.#content.set(el);
224
+ }
225
+ #detachContent(el) {
226
+ el.removeAttribute("id");
227
+ el.removeAttribute("role");
228
+ this.#content.set(null);
229
+ }
230
+ #onShowingChange(isShowing) {
231
+ const trigger = this.#trigger(), content = this.#content();
232
+ if (trigger) {
233
+ setAttribute(trigger, "aria-describedby", isShowing ? this.#id : null);
234
+ }
235
+ for (const el of [this.el, trigger, content]) {
236
+ el && setAttribute(el, "data-visible", isShowing);
237
+ }
238
+ this.#showing.set(isShowing);
239
+ }
240
+ }
241
+
242
+ class TooltipTrigger extends Component {
243
+ constructor() {
244
+ super();
245
+ new FocusVisibleController();
246
+ }
247
+ onConnect(el) {
248
+ onDispose(
249
+ requestScopedAnimationFrame(() => {
250
+ if (!this.connectScope) return;
251
+ this.#attach();
252
+ const tooltip = useContext(tooltipContext);
253
+ onDispose(() => {
254
+ const button = this.#getButton();
255
+ button && tooltip.detachTrigger(button);
256
+ });
257
+ })
258
+ );
259
+ }
260
+ #attach() {
261
+ const button = this.#getButton(), tooltip = useContext(tooltipContext);
262
+ button && tooltip.attachTrigger(button);
263
+ }
264
+ #getButton() {
265
+ const candidate = this.el.firstElementChild;
266
+ return candidate?.localName === "button" || candidate?.getAttribute("role") === "button" ? candidate : this.el;
267
+ }
268
+ }
269
+
270
+ class TooltipContent extends Component {
271
+ static props = {
272
+ placement: "top center",
273
+ offset: 0,
274
+ alignOffset: 0
275
+ };
276
+ constructor() {
277
+ super();
278
+ new FocusVisibleController();
279
+ const { placement } = this.$props;
280
+ this.setAttributes({
281
+ "data-placement": placement
282
+ });
283
+ }
284
+ onAttach(el) {
285
+ this.#attach(el);
286
+ Object.assign(el.style, {
287
+ position: "absolute",
288
+ top: 0,
289
+ left: 0,
290
+ width: "max-content"
291
+ });
292
+ }
293
+ onConnect(el) {
294
+ this.#attach(el);
295
+ const tooltip = useContext(tooltipContext);
296
+ onDispose(() => tooltip.detachContent(el));
297
+ onDispose(
298
+ requestScopedAnimationFrame(() => {
299
+ if (!this.connectScope) return;
300
+ effect(this.#watchPlacement.bind(this));
301
+ })
302
+ );
303
+ }
304
+ #attach(el) {
305
+ const tooltip = useContext(tooltipContext);
306
+ tooltip.attachContent(el);
307
+ }
308
+ #watchPlacement() {
309
+ const { showing } = useContext(tooltipContext);
310
+ if (!showing()) return;
311
+ const { placement, offset: mainOffset, alignOffset } = this.$props;
312
+ return autoPlacement(this.el, this.#getTrigger(), placement(), {
313
+ offsetVarName: "media-tooltip",
314
+ xOffset: alignOffset(),
315
+ yOffset: mainOffset()
316
+ });
317
+ }
318
+ #getTrigger() {
319
+ return useContext(tooltipContext).trigger();
320
+ }
321
+ }
322
+
323
+ class ToggleButton extends Component {
324
+ static props = {
325
+ disabled: false,
326
+ defaultPressed: false
327
+ };
328
+ #pressed = signal(false);
329
+ /**
330
+ * Whether the toggle is currently in a `pressed` state.
331
+ */
332
+ get pressed() {
333
+ return this.#pressed();
334
+ }
335
+ constructor() {
336
+ super();
337
+ new ToggleButtonController({
338
+ isPresssed: this.#pressed
339
+ });
340
+ }
341
+ }
342
+ const togglebutton__proto = ToggleButton.prototype;
343
+ prop(togglebutton__proto, "pressed");
344
+
345
+ class GoogleCastButton extends Component {
346
+ static props = ToggleButtonController.props;
347
+ #media;
348
+ constructor() {
349
+ super();
350
+ new ToggleButtonController({
351
+ isPresssed: this.#isPressed.bind(this),
352
+ onPress: this.#onPress.bind(this)
353
+ });
354
+ }
355
+ onSetup() {
356
+ this.#media = useMediaContext();
357
+ const { canGoogleCast, isGoogleCastConnected } = this.#media.$state;
358
+ this.setAttributes({
359
+ "data-active": isGoogleCastConnected,
360
+ "data-supported": canGoogleCast,
361
+ "data-state": this.#getState.bind(this),
362
+ "aria-hidden": $ariaBool(() => !canGoogleCast())
363
+ });
364
+ }
365
+ onAttach(el) {
366
+ el.setAttribute("data-media-tooltip", "google-cast");
367
+ setARIALabel(el, this.#getDefaultLabel.bind(this));
368
+ }
369
+ #onPress(event) {
370
+ const remote = this.#media.remote;
371
+ remote.requestGoogleCast(event);
372
+ }
373
+ #isPressed() {
374
+ const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
375
+ return remotePlaybackType() === "google-cast" && remotePlaybackState() !== "disconnected";
376
+ }
377
+ #getState() {
378
+ const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
379
+ return remotePlaybackType() === "google-cast" && remotePlaybackState();
380
+ }
381
+ #getDefaultLabel() {
382
+ const { remotePlaybackState } = this.#media.$state;
383
+ return `Google Cast ${remotePlaybackState()}`;
384
+ }
385
+ }
386
+
387
+ class SliderVideo extends Component {
388
+ static props = {
389
+ src: null,
390
+ crossOrigin: null
391
+ };
392
+ static state = new State({
393
+ video: null,
394
+ src: null,
395
+ crossOrigin: null,
396
+ canPlay: false,
397
+ error: null,
398
+ hidden: false
399
+ });
400
+ #media;
401
+ #slider;
402
+ get video() {
403
+ return this.$state.video();
404
+ }
405
+ onSetup() {
406
+ this.#media = useMediaContext();
407
+ this.#slider = useState(Slider.state);
408
+ this.#watchCrossOrigin();
409
+ this.setAttributes({
410
+ "data-loading": this.#isLoading.bind(this),
411
+ "data-hidden": this.$state.hidden,
412
+ "data-error": this.#hasError.bind(this),
413
+ "aria-hidden": $ariaBool(this.$state.hidden)
414
+ });
415
+ }
416
+ onAttach(el) {
417
+ effect(this.#watchVideo.bind(this));
418
+ effect(this.#watchSrc.bind(this));
419
+ effect(this.#watchCrossOrigin.bind(this));
420
+ effect(this.#watchHidden.bind(this));
421
+ effect(this.#onSrcChange.bind(this));
422
+ effect(this.#onUpdateTime.bind(this));
423
+ }
424
+ #watchVideo() {
425
+ const video = this.$state.video();
426
+ if (!video) return;
427
+ if (video.readyState >= 2) this.#onCanPlay();
428
+ new EventsController(video).add("canplay", this.#onCanPlay.bind(this)).add("error", this.#onError.bind(this));
429
+ }
430
+ #watchSrc() {
431
+ const { src } = this.$state, { canLoad } = this.#media.$state;
432
+ src.set(canLoad() ? this.$props.src() : null);
433
+ }
434
+ #watchCrossOrigin() {
435
+ const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin } = this.#media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
436
+ crossOriginState.set(crossOrigin === true ? "anonymous" : crossOrigin);
437
+ }
438
+ #isLoading() {
439
+ const { canPlay, hidden } = this.$state;
440
+ return !canPlay() && !hidden();
441
+ }
442
+ #hasError() {
443
+ const { error } = this.$state;
444
+ return !isNull(error);
445
+ }
446
+ #watchHidden() {
447
+ const { src, hidden } = this.$state, { canLoad, duration } = this.#media.$state;
448
+ hidden.set(canLoad() && (!src() || this.#hasError() || !Number.isFinite(duration())));
449
+ }
450
+ #onSrcChange() {
451
+ const { src, canPlay, error } = this.$state;
452
+ src();
453
+ canPlay.set(false);
454
+ error.set(null);
455
+ }
456
+ #onCanPlay(event) {
457
+ const { canPlay, error } = this.$state;
458
+ canPlay.set(true);
459
+ error.set(null);
460
+ this.dispatch("can-play", { trigger: event });
461
+ }
462
+ #onError(event) {
463
+ const { canPlay, error } = this.$state;
464
+ canPlay.set(false);
465
+ error.set(event);
466
+ this.dispatch("error", { trigger: event });
467
+ }
468
+ #onUpdateTime() {
469
+ const { video, canPlay } = this.$state, { duration } = this.#media.$state, { pointerRate } = this.#slider, media = video(), canUpdate = canPlay() && media && Number.isFinite(duration()) && Number.isFinite(pointerRate());
470
+ if (canUpdate) {
471
+ media.currentTime = pointerRate() * duration();
472
+ }
473
+ }
474
+ }
475
+ const slidervideo__proto = SliderVideo.prototype;
476
+ prop(slidervideo__proto, "video");
477
+
478
+ class AudioGainSlider extends Component {
479
+ static props = {
480
+ ...SliderController.props,
481
+ step: 25,
482
+ keyStep: 25,
483
+ shiftKeyMultiplier: 2,
484
+ min: 0,
485
+ max: 300
486
+ };
487
+ static state = sliderState;
488
+ #media;
489
+ onSetup() {
490
+ this.#media = useMediaContext();
491
+ provideContext(sliderValueFormatContext, {
492
+ default: "percent",
493
+ percent: (_, decimalPlaces) => {
494
+ return round(this.$state.value(), decimalPlaces) + "%";
495
+ }
496
+ });
497
+ new SliderController({
498
+ getStep: this.$props.step,
499
+ getKeyStep: this.$props.keyStep,
500
+ roundValue: Math.round,
501
+ isDisabled: this.#isDisabled.bind(this),
502
+ aria: {
503
+ valueNow: this.#getARIAValueNow.bind(this),
504
+ valueText: this.#getARIAValueText.bind(this)
505
+ },
506
+ onDragValueChange: this.#onDragValueChange.bind(this),
507
+ onValueChange: this.#onValueChange.bind(this)
508
+ }).attach(this);
509
+ effect(this.#watchMinMax.bind(this));
510
+ effect(this.#watchAudioGain.bind(this));
511
+ }
512
+ onAttach(el) {
513
+ el.setAttribute("data-media-audio-gain-slider", "");
514
+ setAttributeIfEmpty(el, "aria-label", "Audio Boost");
515
+ const { canSetAudioGain } = this.#media.$state;
516
+ this.setAttributes({
517
+ "data-supported": canSetAudioGain,
518
+ "aria-hidden": $ariaBool(() => !canSetAudioGain())
519
+ });
520
+ }
521
+ #getARIAValueNow() {
522
+ const { value } = this.$state;
523
+ return Math.round(value());
524
+ }
525
+ #getARIAValueText() {
526
+ const { value } = this.$state;
527
+ return value() + "%";
528
+ }
529
+ #watchMinMax() {
530
+ const { min, max } = this.$props;
531
+ this.$state.min.set(min());
532
+ this.$state.max.set(max());
533
+ }
534
+ #watchAudioGain() {
535
+ const { audioGain } = this.#media.$state, value = ((audioGain() ?? 1) - 1) * 100;
536
+ this.$state.value.set(value);
537
+ this.dispatch("value-change", { detail: value });
538
+ }
539
+ #isDisabled() {
540
+ const { disabled } = this.$props, { canSetAudioGain } = this.#media.$state;
541
+ return disabled() || !canSetAudioGain();
542
+ }
543
+ #onAudioGainChange(event) {
544
+ if (!event.trigger) return;
545
+ const gain = round(1 + event.detail / 100, 2);
546
+ this.#media.remote.changeAudioGain(gain, event);
547
+ }
548
+ #onValueChange(event) {
549
+ this.#onAudioGainChange(event);
550
+ }
551
+ #onDragValueChange(event) {
552
+ this.#onAudioGainChange(event);
553
+ }
554
+ }
555
+
556
+ class SpeedSlider extends Component {
557
+ static props = {
558
+ ...SliderController.props,
559
+ step: 0.25,
560
+ keyStep: 0.25,
561
+ shiftKeyMultiplier: 2,
562
+ min: 0,
563
+ max: 2
564
+ };
565
+ static state = sliderState;
566
+ #media;
567
+ onSetup() {
568
+ this.#media = useMediaContext();
569
+ new SliderController({
570
+ getStep: this.$props.step,
571
+ getKeyStep: this.$props.keyStep,
572
+ roundValue: this.#roundValue,
573
+ isDisabled: this.#isDisabled.bind(this),
574
+ aria: {
575
+ valueNow: this.#getARIAValueNow.bind(this),
576
+ valueText: this.#getARIAValueText.bind(this)
577
+ },
578
+ onDragValueChange: this.#onDragValueChange.bind(this),
579
+ onValueChange: this.#onValueChange.bind(this)
580
+ }).attach(this);
581
+ effect(this.#watchMinMax.bind(this));
582
+ effect(this.#watchPlaybackRate.bind(this));
583
+ }
584
+ onAttach(el) {
585
+ el.setAttribute("data-media-speed-slider", "");
586
+ setAttributeIfEmpty(el, "aria-label", "Speed");
587
+ const { canSetPlaybackRate } = this.#media.$state;
588
+ this.setAttributes({
589
+ "data-supported": canSetPlaybackRate,
590
+ "aria-hidden": $ariaBool(() => !canSetPlaybackRate())
591
+ });
592
+ }
593
+ #getARIAValueNow() {
594
+ const { value } = this.$state;
595
+ return value();
596
+ }
597
+ #getARIAValueText() {
598
+ const { value } = this.$state;
599
+ return value() + "x";
600
+ }
601
+ #watchMinMax() {
602
+ const { min, max } = this.$props;
603
+ this.$state.min.set(min());
604
+ this.$state.max.set(max());
605
+ }
606
+ #watchPlaybackRate() {
607
+ const { playbackRate } = this.#media.$state;
608
+ const newValue = playbackRate();
609
+ this.$state.value.set(newValue);
610
+ this.dispatch("value-change", { detail: newValue });
611
+ }
612
+ #roundValue(value) {
613
+ return round(value, 2);
614
+ }
615
+ #isDisabled() {
616
+ const { disabled } = this.$props, { canSetPlaybackRate } = this.#media.$state;
617
+ return disabled() || !canSetPlaybackRate();
618
+ }
619
+ #throttledSpeedChange = functionThrottle(this.#onPlaybackRateChange.bind(this), 25);
620
+ #onPlaybackRateChange(event) {
621
+ if (!event.trigger) return;
622
+ const rate = event.detail;
623
+ this.#media.remote.changePlaybackRate(rate, event);
624
+ }
625
+ #onValueChange(event) {
626
+ this.#throttledSpeedChange(event);
627
+ }
628
+ #onDragValueChange(event) {
629
+ this.#throttledSpeedChange(event);
630
+ }
631
+ }
632
+
633
+ class QualitySlider extends Component {
634
+ static props = {
635
+ ...SliderController.props,
636
+ step: 1,
637
+ keyStep: 1,
638
+ shiftKeyMultiplier: 1
639
+ };
640
+ static state = sliderState;
641
+ #media;
642
+ #sortedQualities = computed(() => {
643
+ const { qualities } = this.#media.$state;
644
+ return sortVideoQualities(qualities());
645
+ });
646
+ onSetup() {
647
+ this.#media = useMediaContext();
648
+ new SliderController({
649
+ getStep: this.$props.step,
650
+ getKeyStep: this.$props.keyStep,
651
+ roundValue: Math.round,
652
+ isDisabled: this.#isDisabled.bind(this),
653
+ aria: {
654
+ valueNow: this.#getARIAValueNow.bind(this),
655
+ valueText: this.#getARIAValueText.bind(this)
656
+ },
657
+ onDragValueChange: this.#onDragValueChange.bind(this),
658
+ onValueChange: this.#onValueChange.bind(this)
659
+ }).attach(this);
660
+ effect(this.#watchMax.bind(this));
661
+ effect(this.#watchQuality.bind(this));
662
+ }
663
+ onAttach(el) {
664
+ el.setAttribute("data-media-quality-slider", "");
665
+ setAttributeIfEmpty(el, "aria-label", "Video Quality");
666
+ const { qualities, canSetQuality } = this.#media.$state, $supported = computed(() => canSetQuality() && qualities().length > 0);
667
+ this.setAttributes({
668
+ "data-supported": $supported,
669
+ "aria-hidden": $ariaBool(() => !$supported())
670
+ });
671
+ }
672
+ #getARIAValueNow() {
673
+ const { value } = this.$state;
674
+ return value();
675
+ }
676
+ #getARIAValueText() {
677
+ const { quality } = this.#media.$state;
678
+ if (!quality()) return "";
679
+ const { height, bitrate, label } = quality(), bitrateText = bitrate && bitrate > 0 ? `${(bitrate / 1e6).toFixed(2)} Mbps` : null;
680
+ const rootText = label ?? (height ? `${height}p` : "");
681
+ return rootText ? `${rootText}${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 };