@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,3009 @@
1
+ import { ViewController, onDispose, isArray, isString, isNull, effect, peek, listenEvent, ariaBool, isWriteSignal, Component, State, createContext, hasProvidedContext, useContext, EventsController, isNumber, functionThrottle, signal, provideContext, animationFrameThrottle, isObject, method, useState, computed, setAttribute, r, wasEnterKeyPressed, setStyle, isKeyboardEvent, tick, prop, scoped } from './vidstack-C1PwJD_4.js';
2
+ import { useMediaContext } from './vidstack-BjxlZzGu.js';
3
+ import { hasAnimation, setAttributeIfEmpty, onPress, $ariaBool, setARIALabel, isTouchPinchEvent, observeVisibility, isHTMLElement, isElementParent, isEventInside, isElementVisible, requestScopedAnimationFrame, autoPlacement } from './vidstack-C0SWkbs7.js';
4
+ import { isTrackCaptionKind, watchActiveTextTrack } from './vidstack-D-sqb6YI.js';
5
+ import { FocusVisibleController } from './vidstack-Bur7I7Vy.js';
6
+ import { clampNumber, round, getNumberOfDecimalPlaces } from './vidstack-Dihypf8P.js';
7
+ import { assert } from './vidstack-DbBJlz7I.js';
8
+ import { getRequestCredentials } from './vidstack-DdTXMZro.js';
9
+ import { sortVideoQualities } from './vidstack-BTM4ERc7.js';
10
+
11
+ class ARIAKeyShortcuts extends ViewController {
12
+ #shortcut;
13
+ constructor(shortcut) {
14
+ super();
15
+ this.#shortcut = shortcut;
16
+ }
17
+ onAttach(el) {
18
+ const { $props, ariaKeys } = useMediaContext(), keys = el.getAttribute("aria-keyshortcuts");
19
+ if (keys) {
20
+ ariaKeys[this.#shortcut] = keys;
21
+ {
22
+ onDispose(() => {
23
+ delete ariaKeys[this.#shortcut];
24
+ });
25
+ }
26
+ return;
27
+ }
28
+ const shortcuts = $props.keyShortcuts()[this.#shortcut];
29
+ if (shortcuts) {
30
+ const keys2 = isArray(shortcuts) ? shortcuts.join(" ") : isString(shortcuts) ? shortcuts : shortcuts?.keys;
31
+ el.setAttribute("aria-keyshortcuts", isArray(keys2) ? keys2.join(" ") : keys2);
32
+ }
33
+ }
34
+ }
35
+
36
+ function padNumberWithZeroes(num, expectedLength) {
37
+ const str = String(num);
38
+ const actualLength = str.length;
39
+ const shouldPad = actualLength < expectedLength;
40
+ if (shouldPad) {
41
+ const padLength = expectedLength - actualLength;
42
+ const padding = `0`.repeat(padLength);
43
+ return `${padding}${num}`;
44
+ }
45
+ return str;
46
+ }
47
+ function parseTime(duration) {
48
+ const hours = Math.trunc(duration / 3600);
49
+ const minutes = Math.trunc(duration % 3600 / 60);
50
+ const seconds = Math.trunc(duration % 60);
51
+ const fraction = Number((duration - Math.trunc(duration)).toPrecision(3));
52
+ return {
53
+ hours,
54
+ minutes,
55
+ seconds,
56
+ fraction
57
+ };
58
+ }
59
+ function formatTime(duration, { padHrs = null, padMins = null, showHrs = false, showMs = false } = {}) {
60
+ const { hours, minutes, seconds, fraction } = parseTime(duration), paddedHours = padHrs ? padNumberWithZeroes(hours, 2) : hours, paddedMinutes = padMins || isNull(padMins) && duration >= 3600 ? padNumberWithZeroes(minutes, 2) : minutes, paddedSeconds = padNumberWithZeroes(seconds, 2), paddedMs = showMs && fraction > 0 ? `.${String(fraction).replace(/^0?\./, "")}` : "", time = `${paddedMinutes}:${paddedSeconds}${paddedMs}`;
61
+ return hours > 0 || showHrs ? `${paddedHours}:${time}` : time;
62
+ }
63
+ function formatSpokenTime(duration) {
64
+ const spokenParts = [];
65
+ const { hours, minutes, seconds } = parseTime(duration);
66
+ if (hours > 0) {
67
+ spokenParts.push(`${hours} hour`);
68
+ }
69
+ if (minutes > 0) {
70
+ spokenParts.push(`${minutes} min`);
71
+ }
72
+ if (seconds > 0 || spokenParts.length === 0) {
73
+ spokenParts.push(`${seconds} sec`);
74
+ }
75
+ return spokenParts.join(" ");
76
+ }
77
+
78
+ class Popper extends ViewController {
79
+ #delegate;
80
+ constructor(delegate) {
81
+ super();
82
+ this.#delegate = delegate;
83
+ effect(this.#watchTrigger.bind(this));
84
+ }
85
+ onDestroy() {
86
+ this.#stopAnimationEndListener?.();
87
+ this.#stopAnimationEndListener = null;
88
+ }
89
+ #watchTrigger() {
90
+ const trigger = this.#delegate.trigger();
91
+ if (!trigger) {
92
+ this.hide();
93
+ return;
94
+ }
95
+ const show = this.show.bind(this), hide = this.hide.bind(this);
96
+ this.#delegate.listen(trigger, show, hide);
97
+ }
98
+ #showTimerId = -1;
99
+ #hideRafId = -1;
100
+ #stopAnimationEndListener = null;
101
+ show(trigger) {
102
+ this.#cancelShowing();
103
+ window.cancelAnimationFrame(this.#hideRafId);
104
+ this.#hideRafId = -1;
105
+ this.#stopAnimationEndListener?.();
106
+ this.#stopAnimationEndListener = null;
107
+ this.#showTimerId = window.setTimeout(() => {
108
+ this.#showTimerId = -1;
109
+ const content = this.#delegate.content();
110
+ if (content) content.style.removeProperty("display");
111
+ peek(() => this.#delegate.onChange(true, trigger));
112
+ }, this.#delegate.showDelay?.() ?? 0);
113
+ }
114
+ hide(trigger) {
115
+ this.#cancelShowing();
116
+ peek(() => this.#delegate.onChange(false, trigger));
117
+ this.#hideRafId = requestAnimationFrame(() => {
118
+ this.#cancelShowing();
119
+ this.#hideRafId = -1;
120
+ const content = this.#delegate.content();
121
+ if (content) {
122
+ const onHide = () => {
123
+ content.style.display = "none";
124
+ this.#stopAnimationEndListener = null;
125
+ };
126
+ const isAnimated = hasAnimation(content);
127
+ if (isAnimated) {
128
+ this.#stopAnimationEndListener?.();
129
+ const stop = listenEvent(content, "animationend", onHide, { once: true });
130
+ this.#stopAnimationEndListener = stop;
131
+ } else {
132
+ onHide();
133
+ }
134
+ }
135
+ });
136
+ }
137
+ #cancelShowing() {
138
+ window.clearTimeout(this.#showTimerId);
139
+ this.#showTimerId = -1;
140
+ }
141
+ }
142
+
143
+ class ToggleButtonController extends ViewController {
144
+ static props = {
145
+ disabled: false
146
+ };
147
+ #delegate;
148
+ constructor(delegate) {
149
+ super();
150
+ this.#delegate = delegate;
151
+ new FocusVisibleController();
152
+ if (delegate.keyShortcut) {
153
+ new ARIAKeyShortcuts(delegate.keyShortcut);
154
+ }
155
+ }
156
+ onSetup() {
157
+ const { disabled } = this.$props;
158
+ this.setAttributes({
159
+ "data-pressed": this.#delegate.isPresssed,
160
+ "aria-pressed": this.#isARIAPressed.bind(this),
161
+ "aria-disabled": () => disabled() ? "true" : null
162
+ });
163
+ }
164
+ onAttach(el) {
165
+ setAttributeIfEmpty(el, "tabindex", "0");
166
+ setAttributeIfEmpty(el, "role", "button");
167
+ setAttributeIfEmpty(el, "type", "button");
168
+ }
169
+ onConnect(el) {
170
+ const events = onPress(el, this.#onMaybePress.bind(this));
171
+ for (const type of ["click", "touchstart"]) {
172
+ events.add(type, this.#onInteraction.bind(this), {
173
+ passive: true
174
+ });
175
+ }
176
+ }
177
+ #isARIAPressed() {
178
+ return ariaBool(this.#delegate.isPresssed());
179
+ }
180
+ #onPressed(event) {
181
+ if (isWriteSignal(this.#delegate.isPresssed)) {
182
+ this.#delegate.isPresssed.set((p) => !p);
183
+ }
184
+ }
185
+ #onMaybePress(event) {
186
+ const disabled = this.$props.disabled() || this.el.hasAttribute("data-disabled");
187
+ if (disabled) {
188
+ event.preventDefault();
189
+ event.stopImmediatePropagation();
190
+ return;
191
+ }
192
+ event.preventDefault();
193
+ (this.#delegate.onPress ?? this.#onPressed).call(this, event);
194
+ }
195
+ #onInteraction(event) {
196
+ if (this.$props.disabled()) {
197
+ event.preventDefault();
198
+ event.stopImmediatePropagation();
199
+ }
200
+ }
201
+ }
202
+
203
+ class AirPlayButton extends Component {
204
+ static props = ToggleButtonController.props;
205
+ #media;
206
+ constructor() {
207
+ super();
208
+ new ToggleButtonController({
209
+ isPresssed: this.#isPressed.bind(this),
210
+ onPress: this.#onPress.bind(this)
211
+ });
212
+ }
213
+ onSetup() {
214
+ this.#media = useMediaContext();
215
+ const { canAirPlay, isAirPlayConnected } = this.#media.$state;
216
+ this.setAttributes({
217
+ "data-active": isAirPlayConnected,
218
+ "data-supported": canAirPlay,
219
+ "data-state": this.#getState.bind(this),
220
+ "aria-hidden": $ariaBool(() => !canAirPlay())
221
+ });
222
+ }
223
+ onAttach(el) {
224
+ el.setAttribute("data-media-tooltip", "airplay");
225
+ setARIALabel(el, this.#getDefaultLabel.bind(this));
226
+ }
227
+ #onPress(event) {
228
+ const remote = this.#media.remote;
229
+ remote.requestAirPlay(event);
230
+ }
231
+ #isPressed() {
232
+ const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
233
+ return remotePlaybackType() === "airplay" && remotePlaybackState() !== "disconnected";
234
+ }
235
+ #getState() {
236
+ const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
237
+ return remotePlaybackType() === "airplay" && remotePlaybackState();
238
+ }
239
+ #getDefaultLabel() {
240
+ const { remotePlaybackState } = this.#media.$state;
241
+ return `AirPlay ${remotePlaybackState()}`;
242
+ }
243
+ }
244
+
245
+ class PlayButton extends Component {
246
+ static props = ToggleButtonController.props;
247
+ #media;
248
+ constructor() {
249
+ super();
250
+ new ToggleButtonController({
251
+ isPresssed: this.#isPressed.bind(this),
252
+ keyShortcut: "togglePaused",
253
+ onPress: this.#onPress.bind(this)
254
+ });
255
+ }
256
+ onSetup() {
257
+ this.#media = useMediaContext();
258
+ const { paused, ended } = this.#media.$state;
259
+ this.setAttributes({
260
+ "data-paused": paused,
261
+ "data-ended": ended
262
+ });
263
+ }
264
+ onAttach(el) {
265
+ el.setAttribute("data-media-tooltip", "play");
266
+ setARIALabel(el, "Play");
267
+ }
268
+ #onPress(event) {
269
+ const remote = this.#media.remote;
270
+ this.#isPressed() ? remote.pause(event) : remote.play(event);
271
+ }
272
+ #isPressed() {
273
+ const { paused } = this.#media.$state;
274
+ return !paused();
275
+ }
276
+ }
277
+
278
+ class CaptionButton extends Component {
279
+ static props = ToggleButtonController.props;
280
+ #media;
281
+ constructor() {
282
+ super();
283
+ new ToggleButtonController({
284
+ isPresssed: this.#isPressed.bind(this),
285
+ keyShortcut: "toggleCaptions",
286
+ onPress: this.#onPress.bind(this)
287
+ });
288
+ }
289
+ onSetup() {
290
+ this.#media = useMediaContext();
291
+ this.setAttributes({
292
+ "data-active": this.#isPressed.bind(this),
293
+ "data-supported": () => !this.#isHidden(),
294
+ "aria-hidden": $ariaBool(this.#isHidden.bind(this))
295
+ });
296
+ }
297
+ onAttach(el) {
298
+ el.setAttribute("data-media-tooltip", "caption");
299
+ setARIALabel(el, "Captions");
300
+ }
301
+ #onPress(event) {
302
+ this.#media.remote.toggleCaptions(event);
303
+ }
304
+ #isPressed() {
305
+ const { textTrack } = this.#media.$state, track = textTrack();
306
+ return !!track && isTrackCaptionKind(track);
307
+ }
308
+ #isHidden() {
309
+ const { hasCaptions } = this.#media.$state;
310
+ return !hasCaptions();
311
+ }
312
+ }
313
+
314
+ class FullscreenButton extends Component {
315
+ static props = {
316
+ ...ToggleButtonController.props,
317
+ target: "prefer-media"
318
+ };
319
+ #media;
320
+ constructor() {
321
+ super();
322
+ new ToggleButtonController({
323
+ isPresssed: this.#isPressed.bind(this),
324
+ keyShortcut: "toggleFullscreen",
325
+ onPress: this.#onPress.bind(this)
326
+ });
327
+ }
328
+ onSetup() {
329
+ this.#media = useMediaContext();
330
+ const { fullscreen } = this.#media.$state, isSupported = this.#isSupported.bind(this);
331
+ this.setAttributes({
332
+ "data-active": fullscreen,
333
+ "data-supported": isSupported,
334
+ "aria-hidden": $ariaBool(() => !isSupported())
335
+ });
336
+ }
337
+ onAttach(el) {
338
+ el.setAttribute("data-media-tooltip", "fullscreen");
339
+ setARIALabel(el, "Fullscreen");
340
+ }
341
+ #onPress(event) {
342
+ const remote = this.#media.remote, target = this.$props.target();
343
+ this.#isPressed() ? remote.exitFullscreen(target, event) : remote.enterFullscreen(target, event);
344
+ }
345
+ #isPressed() {
346
+ const { fullscreen } = this.#media.$state;
347
+ return fullscreen();
348
+ }
349
+ #isSupported() {
350
+ const { canFullscreen } = this.#media.$state;
351
+ return canFullscreen();
352
+ }
353
+ }
354
+
355
+ class MuteButton extends Component {
356
+ static props = ToggleButtonController.props;
357
+ #media;
358
+ constructor() {
359
+ super();
360
+ new ToggleButtonController({
361
+ isPresssed: this.#isPressed.bind(this),
362
+ keyShortcut: "toggleMuted",
363
+ onPress: this.#onPress.bind(this)
364
+ });
365
+ }
366
+ onSetup() {
367
+ this.#media = useMediaContext();
368
+ this.setAttributes({
369
+ "data-muted": this.#isPressed.bind(this),
370
+ "data-state": this.#getState.bind(this)
371
+ });
372
+ }
373
+ onAttach(el) {
374
+ el.setAttribute("data-media-mute-button", "");
375
+ el.setAttribute("data-media-tooltip", "mute");
376
+ setARIALabel(el, "Mute");
377
+ }
378
+ #onPress(event) {
379
+ const remote = this.#media.remote;
380
+ this.#isPressed() ? remote.unmute(event) : remote.mute(event);
381
+ }
382
+ #isPressed() {
383
+ const { muted, volume } = this.#media.$state;
384
+ return muted() || volume() === 0;
385
+ }
386
+ #getState() {
387
+ const { muted, volume } = this.#media.$state, $volume = volume();
388
+ if (muted() || $volume === 0) return "muted";
389
+ else if ($volume >= 0.5) return "high";
390
+ else if ($volume < 0.5) return "low";
391
+ }
392
+ }
393
+
394
+ class PIPButton extends Component {
395
+ static props = ToggleButtonController.props;
396
+ #media;
397
+ constructor() {
398
+ super();
399
+ new ToggleButtonController({
400
+ isPresssed: this.#isPressed.bind(this),
401
+ keyShortcut: "togglePictureInPicture",
402
+ onPress: this.#onPress.bind(this)
403
+ });
404
+ }
405
+ onSetup() {
406
+ this.#media = useMediaContext();
407
+ const { pictureInPicture } = this.#media.$state, isSupported = this.#isSupported.bind(this);
408
+ this.setAttributes({
409
+ "data-active": pictureInPicture,
410
+ "data-supported": isSupported,
411
+ "aria-hidden": $ariaBool(() => !isSupported())
412
+ });
413
+ }
414
+ onAttach(el) {
415
+ el.setAttribute("data-media-tooltip", "pip");
416
+ setARIALabel(el, "PiP");
417
+ }
418
+ #onPress(event) {
419
+ const remote = this.#media.remote;
420
+ this.#isPressed() ? remote.exitPictureInPicture(event) : remote.enterPictureInPicture(event);
421
+ }
422
+ #isPressed() {
423
+ const { pictureInPicture } = this.#media.$state;
424
+ return pictureInPicture();
425
+ }
426
+ #isSupported() {
427
+ const { canPictureInPicture } = this.#media.$state;
428
+ return canPictureInPicture();
429
+ }
430
+ }
431
+
432
+ class SeekButton extends Component {
433
+ static props = {
434
+ disabled: false,
435
+ seconds: 30
436
+ };
437
+ #media;
438
+ constructor() {
439
+ super();
440
+ new FocusVisibleController();
441
+ }
442
+ onSetup() {
443
+ this.#media = useMediaContext();
444
+ const { seeking } = this.#media.$state, { seconds } = this.$props, isSupported = this.#isSupported.bind(this);
445
+ this.setAttributes({
446
+ seconds,
447
+ "data-seeking": seeking,
448
+ "data-supported": isSupported,
449
+ "aria-hidden": $ariaBool(() => !isSupported())
450
+ });
451
+ }
452
+ onAttach(el) {
453
+ setAttributeIfEmpty(el, "tabindex", "0");
454
+ setAttributeIfEmpty(el, "role", "button");
455
+ setAttributeIfEmpty(el, "type", "button");
456
+ el.setAttribute("data-media-tooltip", "seek");
457
+ setARIALabel(el, this.#getDefaultLabel.bind(this));
458
+ }
459
+ onConnect(el) {
460
+ onPress(el, this.#onPress.bind(this));
461
+ }
462
+ #isSupported() {
463
+ const { canSeek } = this.#media.$state;
464
+ return canSeek();
465
+ }
466
+ #getDefaultLabel() {
467
+ const { seconds } = this.$props;
468
+ return `Seek ${seconds() > 0 ? "forward" : "backward"} ${seconds()} seconds`;
469
+ }
470
+ #onPress(event) {
471
+ const { seconds, disabled } = this.$props;
472
+ if (disabled()) return;
473
+ const { currentTime } = this.#media.$state, seekTo = currentTime() + seconds();
474
+ this.#media.remote.seek(seekTo, event);
475
+ }
476
+ }
477
+
478
+ class LiveButton extends Component {
479
+ static props = {
480
+ disabled: false
481
+ };
482
+ #media;
483
+ constructor() {
484
+ super();
485
+ new FocusVisibleController();
486
+ }
487
+ onSetup() {
488
+ this.#media = useMediaContext();
489
+ const { disabled } = this.$props, { live, liveEdge } = this.#media.$state, isHidden = () => !live();
490
+ this.setAttributes({
491
+ "data-edge": liveEdge,
492
+ "data-hidden": isHidden,
493
+ "aria-disabled": $ariaBool(() => disabled() || liveEdge()),
494
+ "aria-hidden": $ariaBool(isHidden)
495
+ });
496
+ }
497
+ onAttach(el) {
498
+ setAttributeIfEmpty(el, "tabindex", "0");
499
+ setAttributeIfEmpty(el, "role", "button");
500
+ setAttributeIfEmpty(el, "type", "button");
501
+ el.setAttribute("data-media-tooltip", "live");
502
+ }
503
+ onConnect(el) {
504
+ onPress(el, this.#onPress.bind(this));
505
+ }
506
+ #onPress(event) {
507
+ const { disabled } = this.$props, { liveEdge } = this.#media.$state;
508
+ if (disabled() || liveEdge()) return;
509
+ this.#media.remote.seekToLiveEdge(event);
510
+ }
511
+ }
512
+
513
+ const sliderState = new State({
514
+ min: 0,
515
+ max: 100,
516
+ value: 0,
517
+ step: 1,
518
+ pointerValue: 0,
519
+ focused: false,
520
+ dragging: false,
521
+ pointing: false,
522
+ hidden: false,
523
+ get active() {
524
+ return this.dragging || this.focused || this.pointing;
525
+ },
526
+ get fillRate() {
527
+ return calcRate(this.min, this.max, this.value);
528
+ },
529
+ get fillPercent() {
530
+ return this.fillRate * 100;
531
+ },
532
+ get pointerRate() {
533
+ return calcRate(this.min, this.max, this.pointerValue);
534
+ },
535
+ get pointerPercent() {
536
+ return this.pointerRate * 100;
537
+ }
538
+ });
539
+ function calcRate(min, max, value) {
540
+ const range = max - min, offset = value - min;
541
+ return range > 0 ? offset / range : 0;
542
+ }
543
+
544
+ class IntersectionObserverController extends ViewController {
545
+ #init;
546
+ #observer;
547
+ constructor(init) {
548
+ super();
549
+ this.#init = init;
550
+ }
551
+ onConnect(el) {
552
+ this.#observer = new IntersectionObserver((entries) => {
553
+ this.#init.callback?.(entries, this.#observer);
554
+ }, this.#init);
555
+ this.#observer.observe(el);
556
+ onDispose(this.#onDisconnect.bind(this));
557
+ }
558
+ /**
559
+ * Disconnect any active intersection observers.
560
+ */
561
+ #onDisconnect() {
562
+ this.#observer?.disconnect();
563
+ this.#observer = void 0;
564
+ }
565
+ }
566
+
567
+ const sliderContext = createContext();
568
+ const sliderObserverContext = createContext();
569
+
570
+ function getClampedValue(min, max, value, step) {
571
+ return clampNumber(min, round(value, getNumberOfDecimalPlaces(step)), max);
572
+ }
573
+ function getValueFromRate(min, max, rate, step) {
574
+ const boundRate = clampNumber(0, rate, 1), range = max - min, fill = range * boundRate, stepRatio = fill / step, steps = step * Math.round(stepRatio);
575
+ return min + steps;
576
+ }
577
+
578
+ const SliderKeyDirection = {
579
+ Left: -1,
580
+ ArrowLeft: -1,
581
+ Up: 1,
582
+ ArrowUp: 1,
583
+ Right: 1,
584
+ ArrowRight: 1,
585
+ Down: -1,
586
+ ArrowDown: -1
587
+ };
588
+ class SliderEventsController extends ViewController {
589
+ #delegate;
590
+ #media;
591
+ #observer;
592
+ constructor(delegate, media) {
593
+ super();
594
+ this.#delegate = delegate;
595
+ this.#media = media;
596
+ }
597
+ onSetup() {
598
+ if (hasProvidedContext(sliderObserverContext)) {
599
+ this.#observer = useContext(sliderObserverContext);
600
+ }
601
+ }
602
+ onConnect(el) {
603
+ effect(this.#attachEventListeners.bind(this, el));
604
+ effect(this.#attachPointerListeners.bind(this, el));
605
+ if (this.#delegate.swipeGesture) effect(this.#watchSwipeGesture.bind(this));
606
+ }
607
+ #watchSwipeGesture() {
608
+ const { pointer } = this.#media.$state;
609
+ if (pointer() !== "coarse" || !this.#delegate.swipeGesture()) {
610
+ this.#provider = null;
611
+ return;
612
+ }
613
+ this.#provider = this.#media.player.el?.querySelector(
614
+ "media-provider,[data-media-provider]"
615
+ );
616
+ if (!this.#provider) return;
617
+ new EventsController(this.#provider).add("touchstart", this.#onTouchStart.bind(this), {
618
+ passive: true
619
+ }).add("touchmove", this.#onTouchMove.bind(this), { passive: false });
620
+ }
621
+ #provider = null;
622
+ #touch = null;
623
+ #touchStartValue = null;
624
+ #onTouchStart(event) {
625
+ this.#touch = event.touches[0];
626
+ }
627
+ #onTouchMove(event) {
628
+ if (isNull(this.#touch) || isTouchPinchEvent(event)) return;
629
+ const touch = event.touches[0], xDiff = touch.clientX - this.#touch.clientX, yDiff = touch.clientY - this.#touch.clientY, isDragging = this.$state.dragging();
630
+ if (!isDragging && Math.abs(yDiff) > 5) {
631
+ return;
632
+ }
633
+ if (isDragging) return;
634
+ event.preventDefault();
635
+ if (Math.abs(xDiff) > 20) {
636
+ this.#touch = touch;
637
+ this.#touchStartValue = this.$state.value();
638
+ this.#onStartDragging(this.#touchStartValue, event);
639
+ }
640
+ }
641
+ #attachEventListeners(el) {
642
+ const { hidden } = this.$props;
643
+ listenEvent(el, "focus", this.#onFocus.bind(this));
644
+ if (hidden() || this.#delegate.isDisabled()) return;
645
+ new EventsController(el).add("keyup", this.#onKeyUp.bind(this)).add("keydown", this.#onKeyDown.bind(this)).add("pointerenter", this.#onPointerEnter.bind(this)).add("pointermove", this.#onPointerMove.bind(this)).add("pointerleave", this.#onPointerLeave.bind(this)).add("pointerdown", this.#onPointerDown.bind(this));
646
+ }
647
+ #attachPointerListeners(el) {
648
+ if (this.#delegate.isDisabled() || !this.$state.dragging()) return;
649
+ new EventsController(document).add("pointerup", this.#onDocumentPointerUp.bind(this), { capture: true }).add("pointermove", this.#onDocumentPointerMove.bind(this)).add("touchmove", this.#onDocumentTouchMove.bind(this), {
650
+ passive: false
651
+ });
652
+ }
653
+ #onFocus() {
654
+ this.#updatePointerValue(this.$state.value());
655
+ }
656
+ #updateValue(newValue, trigger) {
657
+ const { value, min, max, dragging } = this.$state;
658
+ const clampedValue = Math.max(min(), Math.min(newValue, max()));
659
+ value.set(clampedValue);
660
+ const event = this.createEvent("value-change", { detail: clampedValue, trigger });
661
+ this.dispatch(event);
662
+ this.#delegate.onValueChange?.(event);
663
+ if (dragging()) {
664
+ const event2 = this.createEvent("drag-value-change", { detail: clampedValue, trigger });
665
+ this.dispatch(event2);
666
+ this.#delegate.onDragValueChange?.(event2);
667
+ }
668
+ }
669
+ #updatePointerValue(value, trigger) {
670
+ const { pointerValue, dragging } = this.$state;
671
+ pointerValue.set(value);
672
+ this.dispatch("pointer-value-change", { detail: value, trigger });
673
+ if (dragging()) {
674
+ this.#updateValue(value, trigger);
675
+ }
676
+ }
677
+ #getPointerValue(event) {
678
+ let thumbPositionRate, rect = this.el.getBoundingClientRect(), { min, max } = this.$state;
679
+ if (this.$props.orientation() === "vertical") {
680
+ const { bottom: trackBottom, height: trackHeight } = rect;
681
+ thumbPositionRate = (trackBottom - event.clientY) / trackHeight;
682
+ } else {
683
+ if (this.#touch && isNumber(this.#touchStartValue)) {
684
+ const { width } = this.#provider.getBoundingClientRect(), rate = (event.clientX - this.#touch.clientX) / width, range = max() - min(), diff = range * Math.abs(rate);
685
+ thumbPositionRate = (rate < 0 ? this.#touchStartValue - diff : this.#touchStartValue + diff) / range;
686
+ } else {
687
+ const { left: trackLeft, width: trackWidth } = rect;
688
+ thumbPositionRate = (event.clientX - trackLeft) / trackWidth;
689
+ }
690
+ }
691
+ return Math.max(
692
+ min(),
693
+ Math.min(
694
+ max(),
695
+ this.#delegate.roundValue(
696
+ getValueFromRate(min(), max(), thumbPositionRate, this.#delegate.getStep())
697
+ )
698
+ )
699
+ );
700
+ }
701
+ #onPointerEnter(event) {
702
+ this.$state.pointing.set(true);
703
+ }
704
+ #onPointerMove(event) {
705
+ const { dragging } = this.$state;
706
+ if (dragging()) return;
707
+ this.#updatePointerValue(this.#getPointerValue(event), event);
708
+ }
709
+ #onPointerLeave(event) {
710
+ this.$state.pointing.set(false);
711
+ }
712
+ #onPointerDown(event) {
713
+ if (event.button !== 0) return;
714
+ const value = this.#getPointerValue(event);
715
+ this.#onStartDragging(value, event);
716
+ this.#updatePointerValue(value, event);
717
+ }
718
+ #onStartDragging(value, trigger) {
719
+ const { dragging } = this.$state;
720
+ if (dragging()) return;
721
+ dragging.set(true);
722
+ this.#media.remote.pauseControls(trigger);
723
+ const event = this.createEvent("drag-start", { detail: value, trigger });
724
+ this.dispatch(event);
725
+ this.#delegate.onDragStart?.(event);
726
+ this.#observer?.onDragStart?.();
727
+ }
728
+ #onStopDragging(value, trigger) {
729
+ const { dragging } = this.$state;
730
+ if (!dragging()) return;
731
+ dragging.set(false);
732
+ this.#media.remote.resumeControls(trigger);
733
+ const event = this.createEvent("drag-end", { detail: value, trigger });
734
+ this.dispatch(event);
735
+ this.#delegate.onDragEnd?.(event);
736
+ this.#touch = null;
737
+ this.#touchStartValue = null;
738
+ this.#observer?.onDragEnd?.();
739
+ }
740
+ // -------------------------------------------------------------------------------------------
741
+ // Keyboard Events
742
+ // -------------------------------------------------------------------------------------------
743
+ #lastDownKey;
744
+ #repeatedKeys = false;
745
+ #onKeyDown(event) {
746
+ const isValidKey = Object.keys(SliderKeyDirection).includes(event.key);
747
+ if (!isValidKey) return;
748
+ const { key } = event, jumpValue = this.#calcJumpValue(event);
749
+ if (!isNull(jumpValue)) {
750
+ this.#updatePointerValue(jumpValue, event);
751
+ this.#updateValue(jumpValue, event);
752
+ return;
753
+ }
754
+ const newValue = this.#calcNewKeyValue(event);
755
+ if (!this.#repeatedKeys) {
756
+ this.#repeatedKeys = key === this.#lastDownKey;
757
+ if (!this.$state.dragging() && this.#repeatedKeys) {
758
+ this.#onStartDragging(newValue, event);
759
+ }
760
+ }
761
+ this.#updatePointerValue(newValue, event);
762
+ this.#lastDownKey = key;
763
+ }
764
+ #onKeyUp(event) {
765
+ const isValidKey = Object.keys(SliderKeyDirection).includes(event.key);
766
+ if (!isValidKey || !isNull(this.#calcJumpValue(event))) return;
767
+ const newValue = this.#repeatedKeys ? this.$state.pointerValue() : this.#calcNewKeyValue(event);
768
+ this.#updateValue(newValue, event);
769
+ this.#onStopDragging(newValue, event);
770
+ this.#lastDownKey = "";
771
+ this.#repeatedKeys = false;
772
+ }
773
+ #calcJumpValue(event) {
774
+ let key = event.key, { min, max } = this.$state;
775
+ if (key === "Home" || key === "PageUp") {
776
+ return min();
777
+ } else if (key === "End" || key === "PageDown") {
778
+ return max();
779
+ } else if (!event.metaKey && /^[0-9]$/.test(key)) {
780
+ return (max() - min()) / 10 * Number(key);
781
+ }
782
+ return null;
783
+ }
784
+ #calcNewKeyValue(event) {
785
+ const { key, shiftKey } = event;
786
+ event.preventDefault();
787
+ event.stopPropagation();
788
+ const { shiftKeyMultiplier } = this.$props;
789
+ const { min, max, value, pointerValue } = this.$state, step = this.#delegate.getStep(), keyStep = this.#delegate.getKeyStep();
790
+ const modifiedStep = !shiftKey ? keyStep : keyStep * shiftKeyMultiplier(), direction = Number(SliderKeyDirection[key]), diff = modifiedStep * direction, currentValue = this.#repeatedKeys ? pointerValue() : this.#delegate.getValue?.() ?? value(), steps = (currentValue + diff) / step;
791
+ return Math.max(min(), Math.min(max(), Number((step * steps).toFixed(3))));
792
+ }
793
+ // -------------------------------------------------------------------------------------------
794
+ // Document (Pointer Events)
795
+ // -------------------------------------------------------------------------------------------
796
+ #onDocumentPointerUp(event) {
797
+ if (event.button !== 0) return;
798
+ event.preventDefault();
799
+ event.stopImmediatePropagation();
800
+ const value = this.#getPointerValue(event);
801
+ this.#updatePointerValue(value, event);
802
+ this.#onStopDragging(value, event);
803
+ }
804
+ #onDocumentTouchMove(event) {
805
+ event.preventDefault();
806
+ }
807
+ #onDocumentPointerMove = functionThrottle(
808
+ (event) => {
809
+ this.#updatePointerValue(this.#getPointerValue(event), event);
810
+ },
811
+ 20,
812
+ { leading: true }
813
+ );
814
+ }
815
+
816
+ const sliderValueFormatContext = createContext(() => ({}));
817
+
818
+ class SliderController extends ViewController {
819
+ static props = {
820
+ hidden: false,
821
+ disabled: false,
822
+ step: 1,
823
+ keyStep: 1,
824
+ orientation: "horizontal",
825
+ shiftKeyMultiplier: 5
826
+ };
827
+ #media;
828
+ #delegate;
829
+ #isVisible = signal(true);
830
+ #isIntersecting = signal(true);
831
+ constructor(delegate) {
832
+ super();
833
+ this.#delegate = delegate;
834
+ }
835
+ onSetup() {
836
+ this.#media = useMediaContext();
837
+ const focus = new FocusVisibleController();
838
+ focus.attach(this);
839
+ this.$state.focused = focus.focused.bind(focus);
840
+ if (!hasProvidedContext(sliderValueFormatContext)) {
841
+ provideContext(sliderValueFormatContext, {
842
+ default: "value"
843
+ });
844
+ }
845
+ provideContext(sliderContext, {
846
+ orientation: this.$props.orientation,
847
+ disabled: this.#delegate.isDisabled,
848
+ preview: signal(null)
849
+ });
850
+ effect(this.#watchValue.bind(this));
851
+ effect(this.#watchStep.bind(this));
852
+ effect(this.#watchDisabled.bind(this));
853
+ this.#setupAttrs();
854
+ new SliderEventsController(this.#delegate, this.#media).attach(this);
855
+ new IntersectionObserverController({
856
+ callback: this.#onIntersectionChange.bind(this)
857
+ }).attach(this);
858
+ }
859
+ onAttach(el) {
860
+ setAttributeIfEmpty(el, "role", "slider");
861
+ setAttributeIfEmpty(el, "tabindex", "0");
862
+ setAttributeIfEmpty(el, "autocomplete", "off");
863
+ effect(this.#watchCSSVars.bind(this));
864
+ }
865
+ onConnect(el) {
866
+ onDispose(observeVisibility(el, this.#isVisible.set));
867
+ effect(this.#watchHidden.bind(this));
868
+ }
869
+ #onIntersectionChange(entries) {
870
+ this.#isIntersecting.set(entries[0].isIntersecting);
871
+ }
872
+ // -------------------------------------------------------------------------------------------
873
+ // Watch
874
+ // -------------------------------------------------------------------------------------------
875
+ #watchHidden() {
876
+ const { hidden } = this.$props;
877
+ this.$state.hidden.set(hidden() || !this.#isVisible() || !this.#isIntersecting.bind(this));
878
+ }
879
+ #watchValue() {
880
+ const { dragging, value, min, max } = this.$state;
881
+ if (peek(dragging)) return;
882
+ value.set(getClampedValue(min(), max(), value(), this.#delegate.getStep()));
883
+ }
884
+ #watchStep() {
885
+ this.$state.step.set(this.#delegate.getStep());
886
+ }
887
+ #watchDisabled() {
888
+ if (!this.#delegate.isDisabled()) return;
889
+ const { dragging, pointing } = this.$state;
890
+ dragging.set(false);
891
+ pointing.set(false);
892
+ }
893
+ // -------------------------------------------------------------------------------------------
894
+ // ARIA
895
+ // -------------------------------------------------------------------------------------------
896
+ #getARIADisabled() {
897
+ return ariaBool(this.#delegate.isDisabled());
898
+ }
899
+ // -------------------------------------------------------------------------------------------
900
+ // Attributes
901
+ // -------------------------------------------------------------------------------------------
902
+ #setupAttrs() {
903
+ const { orientation } = this.$props, { dragging, active, pointing } = this.$state;
904
+ this.setAttributes({
905
+ "data-dragging": dragging,
906
+ "data-pointing": pointing,
907
+ "data-active": active,
908
+ "aria-disabled": this.#getARIADisabled.bind(this),
909
+ "aria-valuemin": this.#delegate.aria.valueMin ?? this.$state.min,
910
+ "aria-valuemax": this.#delegate.aria.valueMax ?? this.$state.max,
911
+ "aria-valuenow": this.#delegate.aria.valueNow,
912
+ "aria-valuetext": this.#delegate.aria.valueText,
913
+ "aria-orientation": orientation
914
+ });
915
+ }
916
+ #watchCSSVars() {
917
+ const { fillPercent, pointerPercent } = this.$state;
918
+ this.#updateSliderVars(round(fillPercent(), 3), round(pointerPercent(), 3));
919
+ }
920
+ #updateSliderVars = animationFrameThrottle((fillPercent, pointerPercent) => {
921
+ this.el?.style.setProperty("--slider-fill", fillPercent + "%");
922
+ this.el?.style.setProperty("--slider-pointer", pointerPercent + "%");
923
+ });
924
+ }
925
+
926
+ class Slider extends Component {
927
+ static props = {
928
+ ...SliderController.props,
929
+ min: 0,
930
+ max: 100,
931
+ value: 0
932
+ };
933
+ static state = sliderState;
934
+ constructor() {
935
+ super();
936
+ new SliderController({
937
+ getStep: this.$props.step,
938
+ getKeyStep: this.$props.keyStep,
939
+ roundValue: Math.round,
940
+ isDisabled: this.$props.disabled,
941
+ aria: {
942
+ valueNow: this.#getARIAValueNow.bind(this),
943
+ valueText: this.#getARIAValueText.bind(this)
944
+ }
945
+ });
946
+ }
947
+ onSetup() {
948
+ effect(this.#watchValue.bind(this));
949
+ effect(this.#watchMinMax.bind(this));
950
+ }
951
+ // -------------------------------------------------------------------------------------------
952
+ // Props
953
+ // -------------------------------------------------------------------------------------------
954
+ #getARIAValueNow() {
955
+ const { value } = this.$state;
956
+ return Math.round(value());
957
+ }
958
+ #getARIAValueText() {
959
+ const { value, max } = this.$state;
960
+ return round(value() / max() * 100, 2) + "%";
961
+ }
962
+ // -------------------------------------------------------------------------------------------
963
+ // Watch
964
+ // -------------------------------------------------------------------------------------------
965
+ #watchValue() {
966
+ const { value } = this.$props;
967
+ this.$state.value.set(value());
968
+ }
969
+ #watchMinMax() {
970
+ const { min, max } = this.$props;
971
+ this.$state.min.set(min());
972
+ this.$state.max.set(max());
973
+ }
974
+ }
975
+
976
+ const cache = /* @__PURE__ */ new Map(), pending = /* @__PURE__ */ new Map(), warned = /* @__PURE__ */ new Set() ;
977
+ class ThumbnailsLoader {
978
+ #media;
979
+ #src;
980
+ #crossOrigin;
981
+ $images = signal([]);
982
+ static create(src, crossOrigin) {
983
+ const media = useMediaContext();
984
+ return new ThumbnailsLoader(src, crossOrigin, media);
985
+ }
986
+ constructor(src, crossOrigin, media) {
987
+ this.#src = src;
988
+ this.#crossOrigin = crossOrigin;
989
+ this.#media = media;
990
+ effect(this.#onLoadCues.bind(this));
991
+ }
992
+ #onLoadCues() {
993
+ const { canLoad } = this.#media.$state;
994
+ if (!canLoad()) return;
995
+ const src = this.#src();
996
+ if (!src) return;
997
+ if (isString(src) && cache.has(src)) {
998
+ const cues = cache.get(src);
999
+ cache.delete(src);
1000
+ cache.set(src, cues);
1001
+ if (cache.size > 99) {
1002
+ const firstKey = cache.keys().next().value;
1003
+ cache.delete(firstKey);
1004
+ }
1005
+ this.$images.set(cache.get(src));
1006
+ } else if (isString(src)) {
1007
+ const crossOrigin = this.#crossOrigin(), currentKey = src + "::" + crossOrigin;
1008
+ if (!pending.has(currentKey)) {
1009
+ const promise = new Promise(async (resolve, reject) => {
1010
+ try {
1011
+ const response = await fetch(src, {
1012
+ credentials: getRequestCredentials(crossOrigin)
1013
+ }), isJSON = response.headers.get("content-type") === "application/json";
1014
+ if (isJSON) {
1015
+ const json = await response.json();
1016
+ if (isArray(json)) {
1017
+ if (json[0] && "text" in json[0]) {
1018
+ resolve(this.#processVTTCues(json));
1019
+ } else {
1020
+ for (let i = 0; i < json.length; i++) {
1021
+ const image = json[i];
1022
+ assert(isObject(image), `Item not an object at index ${i}`);
1023
+ assert(
1024
+ "url" in image && isString(image.url),
1025
+ `Invalid or missing \`url\` property at index ${i}`
1026
+ );
1027
+ assert(
1028
+ "startTime" in image && isNumber(image.startTime),
1029
+ `Invalid or missing \`startTime\` property at index ${i}`
1030
+ );
1031
+ }
1032
+ resolve(json);
1033
+ }
1034
+ } else {
1035
+ resolve(this.#processStoryboard(json));
1036
+ }
1037
+ return;
1038
+ }
1039
+ import('media-captions').then(async ({ parseResponse }) => {
1040
+ try {
1041
+ const { cues } = await parseResponse(response);
1042
+ resolve(this.#processVTTCues(cues));
1043
+ } catch (e) {
1044
+ reject(e);
1045
+ }
1046
+ });
1047
+ } catch (e) {
1048
+ reject(e);
1049
+ }
1050
+ }).then((images) => {
1051
+ cache.set(currentKey, images);
1052
+ return images;
1053
+ }).catch((error) => {
1054
+ this.#onError(src, error);
1055
+ }).finally(() => {
1056
+ if (isString(currentKey)) pending.delete(currentKey);
1057
+ });
1058
+ pending.set(currentKey, promise);
1059
+ }
1060
+ pending.get(currentKey)?.then((images) => {
1061
+ this.$images.set(images || []);
1062
+ });
1063
+ } else if (isArray(src)) {
1064
+ try {
1065
+ this.$images.set(this.#processImages(src));
1066
+ } catch (error) {
1067
+ this.#onError(src, error);
1068
+ }
1069
+ } else {
1070
+ try {
1071
+ this.$images.set(this.#processStoryboard(src));
1072
+ } catch (error) {
1073
+ this.#onError(src, error);
1074
+ }
1075
+ }
1076
+ return () => {
1077
+ this.$images.set([]);
1078
+ };
1079
+ }
1080
+ #processImages(images) {
1081
+ const baseURL = this.#resolveBaseUrl();
1082
+ return images.map((img, i) => {
1083
+ assert(
1084
+ img.url && isString(img.url),
1085
+ `Invalid or missing \`url\` property at index ${i}`
1086
+ );
1087
+ assert(
1088
+ "startTime" in img && isNumber(img.startTime),
1089
+ `Invalid or missing \`startTime\` property at index ${i}`
1090
+ );
1091
+ return {
1092
+ ...img,
1093
+ url: isString(img.url) ? this.#resolveURL(img.url, baseURL) : img.url
1094
+ };
1095
+ });
1096
+ }
1097
+ #processStoryboard(board) {
1098
+ assert(isString(board.url), "Missing `url` in storyboard object");
1099
+ assert(isArray(board.tiles) && board.tiles?.length, `Empty tiles in storyboard`);
1100
+ const url = new URL(board.url), images = [];
1101
+ const tileWidth = "tile_width" in board ? board.tile_width : board.tileWidth, tileHeight = "tile_height" in board ? board.tile_height : board.tileHeight;
1102
+ for (const tile of board.tiles) {
1103
+ images.push({
1104
+ url,
1105
+ startTime: "start" in tile ? tile.start : tile.startTime,
1106
+ width: tileWidth,
1107
+ height: tileHeight,
1108
+ coords: { x: tile.x, y: tile.y }
1109
+ });
1110
+ }
1111
+ return images;
1112
+ }
1113
+ #processVTTCues(cues) {
1114
+ for (let i = 0; i < cues.length; i++) {
1115
+ const cue = cues[i];
1116
+ assert(
1117
+ "startTime" in cue && isNumber(cue.startTime),
1118
+ `Invalid or missing \`startTime\` property at index ${i}`
1119
+ );
1120
+ assert(
1121
+ "text" in cue && isString(cue.text),
1122
+ `Invalid or missing \`text\` property at index ${i}`
1123
+ );
1124
+ }
1125
+ const images = [], baseURL = this.#resolveBaseUrl();
1126
+ for (const cue of cues) {
1127
+ const [url, hash] = cue.text.split("#"), data = this.#resolveData(hash);
1128
+ images.push({
1129
+ url: this.#resolveURL(url, baseURL),
1130
+ startTime: cue.startTime,
1131
+ endTime: cue.endTime,
1132
+ width: data?.w,
1133
+ height: data?.h,
1134
+ coords: data && isNumber(data.x) && isNumber(data.y) ? { x: data.x, y: data.y } : void 0
1135
+ });
1136
+ }
1137
+ return images;
1138
+ }
1139
+ #resolveBaseUrl() {
1140
+ let baseURL = peek(this.#src);
1141
+ if (!isString(baseURL) || !/^https?:/.test(baseURL)) {
1142
+ return location.href;
1143
+ }
1144
+ return baseURL;
1145
+ }
1146
+ #resolveURL(src, baseURL) {
1147
+ return /^https?:/.test(src) ? new URL(src) : new URL(src, baseURL);
1148
+ }
1149
+ #resolveData(hash) {
1150
+ if (!hash) return {};
1151
+ const [hashProps, values] = hash.split("="), hashValues = values?.split(","), data = {};
1152
+ if (!hashProps || !hashValues) {
1153
+ return null;
1154
+ }
1155
+ for (let i = 0; i < hashProps.length; i++) {
1156
+ const value = +hashValues[i];
1157
+ if (!isNaN(value)) data[hashProps[i]] = value;
1158
+ }
1159
+ return data;
1160
+ }
1161
+ #onError(src, error) {
1162
+ if (warned?.has(src)) return;
1163
+ this.#media.logger?.errorGroup("[vidstack] failed to load thumbnails").labelledLog("Src", src).labelledLog("Error", error).dispatch();
1164
+ warned?.add(src);
1165
+ }
1166
+ }
1167
+
1168
+ class Thumbnail extends Component {
1169
+ static props = {
1170
+ src: null,
1171
+ time: 0,
1172
+ crossOrigin: null
1173
+ };
1174
+ static state = new State({
1175
+ src: "",
1176
+ img: null,
1177
+ thumbnails: [],
1178
+ activeThumbnail: null,
1179
+ crossOrigin: null,
1180
+ loading: false,
1181
+ error: null,
1182
+ hidden: false
1183
+ });
1184
+ media;
1185
+ #loader;
1186
+ #styleResets = [];
1187
+ onSetup() {
1188
+ this.media = useMediaContext();
1189
+ this.#loader = ThumbnailsLoader.create(this.$props.src, this.$state.crossOrigin);
1190
+ this.#watchCrossOrigin();
1191
+ this.setAttributes({
1192
+ "data-loading": this.#isLoading.bind(this),
1193
+ "data-error": this.#hasError.bind(this),
1194
+ "data-hidden": this.$state.hidden,
1195
+ "aria-hidden": $ariaBool(this.$state.hidden)
1196
+ });
1197
+ }
1198
+ onConnect(el) {
1199
+ effect(this.#watchImg.bind(this));
1200
+ effect(this.#watchHidden.bind(this));
1201
+ effect(this.#watchCrossOrigin.bind(this));
1202
+ effect(this.#onLoadStart.bind(this));
1203
+ effect(this.#onFindActiveThumbnail.bind(this));
1204
+ effect(this.#resize.bind(this));
1205
+ }
1206
+ #watchImg() {
1207
+ const img = this.$state.img();
1208
+ if (!img) return;
1209
+ new EventsController(img).add("load", this.#onLoaded.bind(this)).add("error", this.#onError.bind(this));
1210
+ }
1211
+ #watchCrossOrigin() {
1212
+ const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin } = this.media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
1213
+ crossOriginState.set(crossOrigin === true ? "anonymous" : crossOrigin);
1214
+ }
1215
+ #onLoadStart() {
1216
+ const { src, loading, error } = this.$state;
1217
+ if (src()) {
1218
+ loading.set(true);
1219
+ error.set(null);
1220
+ }
1221
+ return () => {
1222
+ this.#resetStyles();
1223
+ loading.set(false);
1224
+ error.set(null);
1225
+ };
1226
+ }
1227
+ #onLoaded() {
1228
+ const { loading, error } = this.$state;
1229
+ this.#resize();
1230
+ loading.set(false);
1231
+ error.set(null);
1232
+ }
1233
+ #onError(event) {
1234
+ const { loading, error } = this.$state;
1235
+ loading.set(false);
1236
+ error.set(event);
1237
+ }
1238
+ #isLoading() {
1239
+ const { loading, hidden } = this.$state;
1240
+ return !hidden() && loading();
1241
+ }
1242
+ #hasError() {
1243
+ const { error } = this.$state;
1244
+ return !isNull(error());
1245
+ }
1246
+ #watchHidden() {
1247
+ const { hidden } = this.$state, { duration } = this.media.$state, images = this.#loader.$images();
1248
+ hidden.set(this.#hasError() || !Number.isFinite(duration()) || images.length === 0);
1249
+ }
1250
+ getTime() {
1251
+ return this.$props.time();
1252
+ }
1253
+ #onFindActiveThumbnail() {
1254
+ let images = this.#loader.$images();
1255
+ if (!images.length) return;
1256
+ let time = this.getTime(), { src, activeThumbnail } = this.$state, activeIndex = -1, activeImage = null;
1257
+ for (let i = images.length - 1; i >= 0; i--) {
1258
+ const image = images[i];
1259
+ if (time >= image.startTime && (!image.endTime || time < image.endTime)) {
1260
+ activeIndex = i;
1261
+ break;
1262
+ }
1263
+ }
1264
+ if (images[activeIndex]) {
1265
+ activeImage = images[activeIndex];
1266
+ }
1267
+ activeThumbnail.set(activeImage);
1268
+ src.set(activeImage?.url.href || "");
1269
+ }
1270
+ #resize() {
1271
+ if (!this.scope || this.$state.hidden()) return;
1272
+ const rootEl = this.el, imgEl = this.$state.img(), thumbnail = this.$state.activeThumbnail();
1273
+ if (!imgEl || !thumbnail || !rootEl) return;
1274
+ let width = thumbnail.width ?? imgEl.naturalWidth, height = thumbnail?.height ?? imgEl.naturalHeight, {
1275
+ maxWidth,
1276
+ maxHeight,
1277
+ minWidth,
1278
+ minHeight,
1279
+ width: elWidth,
1280
+ height: elHeight
1281
+ } = getComputedStyle(this.el);
1282
+ if (minWidth === "100%") minWidth = parseFloat(elWidth) + "";
1283
+ if (minHeight === "100%") minHeight = parseFloat(elHeight) + "";
1284
+ let minRatio = Math.max(parseInt(minWidth) / width, parseInt(minHeight) / height), maxRatio = Math.min(
1285
+ Math.max(parseInt(minWidth), parseInt(maxWidth)) / width,
1286
+ Math.max(parseInt(minHeight), parseInt(maxHeight)) / height
1287
+ ), scale = !isNaN(maxRatio) && maxRatio < 1 ? maxRatio : minRatio > 1 ? minRatio : 1;
1288
+ this.#style(rootEl, "--thumbnail-width", `${width * scale}px`);
1289
+ this.#style(rootEl, "--thumbnail-height", `${height * scale}px`);
1290
+ this.#style(rootEl, "--thumbnail-aspect-ratio", String(round(width / height, 5)));
1291
+ this.#style(imgEl, "width", `${imgEl.naturalWidth * scale}px`);
1292
+ this.#style(imgEl, "height", `${imgEl.naturalHeight * scale}px`);
1293
+ this.#style(
1294
+ imgEl,
1295
+ "transform",
1296
+ thumbnail.coords ? `translate(-${thumbnail.coords.x * scale}px, -${thumbnail.coords.y * scale}px)` : ""
1297
+ );
1298
+ this.#style(imgEl, "max-width", "none");
1299
+ }
1300
+ #style(el, name, value) {
1301
+ el.style.setProperty(name, value);
1302
+ this.#styleResets.push(() => el.style.removeProperty(name));
1303
+ }
1304
+ #resetStyles() {
1305
+ for (const reset of this.#styleResets) reset();
1306
+ this.#styleResets = [];
1307
+ }
1308
+ }
1309
+
1310
+ class SliderValue extends Component {
1311
+ static props = {
1312
+ type: "pointer",
1313
+ format: null,
1314
+ showHours: false,
1315
+ showMs: false,
1316
+ padHours: null,
1317
+ padMinutes: null,
1318
+ decimalPlaces: 2
1319
+ };
1320
+ #format;
1321
+ #text;
1322
+ #slider;
1323
+ onSetup() {
1324
+ this.#slider = useState(Slider.state);
1325
+ this.#format = useContext(sliderValueFormatContext);
1326
+ this.#text = computed(this.getValueText.bind(this));
1327
+ }
1328
+ /**
1329
+ * Returns the current value formatted as text based on prop settings.
1330
+ */
1331
+ getValueText() {
1332
+ const {
1333
+ type,
1334
+ format: $format,
1335
+ decimalPlaces,
1336
+ padHours,
1337
+ padMinutes,
1338
+ showHours,
1339
+ showMs
1340
+ } = this.$props, { value: sliderValue, pointerValue, min, max } = this.#slider, format = $format?.() ?? this.#format.default;
1341
+ const value = type() === "current" ? sliderValue() : pointerValue();
1342
+ if (format === "percent") {
1343
+ const range = max() - min();
1344
+ const percent = value / range * 100;
1345
+ return (this.#format.percent ?? round)(percent, decimalPlaces()) + "%";
1346
+ } else if (format === "time") {
1347
+ return (this.#format.time ?? formatTime)(value, {
1348
+ padHrs: padHours(),
1349
+ padMins: padMinutes(),
1350
+ showHrs: showHours(),
1351
+ showMs: showMs()
1352
+ });
1353
+ } else {
1354
+ return (this.#format.value?.(value) ?? value.toFixed(2)) + "";
1355
+ }
1356
+ }
1357
+ }
1358
+ const slidervalue__proto = SliderValue.prototype;
1359
+ method(slidervalue__proto, "getValueText");
1360
+
1361
+ class SliderPreview extends Component {
1362
+ static props = {
1363
+ offset: 0,
1364
+ noClamp: false
1365
+ };
1366
+ #slider;
1367
+ onSetup() {
1368
+ this.#slider = useContext(sliderContext);
1369
+ const { active } = useState(Slider.state);
1370
+ this.setAttributes({
1371
+ "data-visible": active
1372
+ });
1373
+ }
1374
+ onAttach(el) {
1375
+ Object.assign(el.style, {
1376
+ position: "absolute",
1377
+ top: 0,
1378
+ left: 0,
1379
+ width: "max-content"
1380
+ });
1381
+ }
1382
+ onConnect(el) {
1383
+ const { preview } = this.#slider;
1384
+ preview.set(el);
1385
+ onDispose(() => preview.set(null));
1386
+ effect(this.#updatePlacement.bind(this));
1387
+ const resize = new ResizeObserver(this.#updatePlacement.bind(this));
1388
+ resize.observe(el);
1389
+ onDispose(() => resize.disconnect());
1390
+ }
1391
+ #updatePlacement = animationFrameThrottle(() => {
1392
+ const { disabled, orientation } = this.#slider;
1393
+ if (disabled()) return;
1394
+ const el = this.el, { offset, noClamp } = this.$props;
1395
+ if (!el) return;
1396
+ updateSliderPreviewPlacement(el, {
1397
+ clamp: !noClamp(),
1398
+ offset: offset(),
1399
+ orientation: orientation()
1400
+ });
1401
+ });
1402
+ }
1403
+ function updateSliderPreviewPlacement(el, {
1404
+ clamp,
1405
+ offset,
1406
+ orientation
1407
+ }) {
1408
+ const computedStyle = getComputedStyle(el), width = parseFloat(computedStyle.width), height = parseFloat(computedStyle.height), styles = {
1409
+ top: null,
1410
+ right: null,
1411
+ bottom: null,
1412
+ left: null
1413
+ };
1414
+ styles[orientation === "horizontal" ? "bottom" : "left"] = `calc(100% + var(--media-slider-preview-offset, ${offset}px))`;
1415
+ if (orientation === "horizontal") {
1416
+ const widthHalf = width / 2;
1417
+ if (!clamp) {
1418
+ styles.left = `calc(var(--slider-pointer) - ${widthHalf}px)`;
1419
+ } else {
1420
+ const leftClamp = `max(0px, calc(var(--slider-pointer) - ${widthHalf}px))`, rightClamp = `calc(100% - ${width}px)`;
1421
+ styles.left = `min(${leftClamp}, ${rightClamp})`;
1422
+ }
1423
+ } else {
1424
+ const heightHalf = height / 2;
1425
+ if (!clamp) {
1426
+ styles.bottom = `calc(var(--slider-pointer) - ${heightHalf}px)`;
1427
+ } else {
1428
+ const topClamp = `max(${heightHalf}px, calc(var(--slider-pointer) - ${heightHalf}px))`, bottomClamp = `calc(100% - ${height}px)`;
1429
+ styles.bottom = `min(${topClamp}, ${bottomClamp})`;
1430
+ }
1431
+ }
1432
+ Object.assign(el.style, styles);
1433
+ }
1434
+
1435
+ class VolumeSlider extends Component {
1436
+ static props = {
1437
+ ...SliderController.props,
1438
+ keyStep: 5,
1439
+ shiftKeyMultiplier: 2
1440
+ };
1441
+ static state = sliderState;
1442
+ #media;
1443
+ onSetup() {
1444
+ this.#media = useMediaContext();
1445
+ const { audioGain } = this.#media.$state;
1446
+ provideContext(sliderValueFormatContext, {
1447
+ default: "percent",
1448
+ value(value) {
1449
+ return (value * (audioGain() ?? 1)).toFixed(2);
1450
+ },
1451
+ percent(value) {
1452
+ return Math.round(value * (audioGain() ?? 1));
1453
+ }
1454
+ });
1455
+ new SliderController({
1456
+ getStep: this.$props.step,
1457
+ getKeyStep: this.$props.keyStep,
1458
+ roundValue: Math.round,
1459
+ isDisabled: this.#isDisabled.bind(this),
1460
+ aria: {
1461
+ valueMax: this.#getARIAValueMax.bind(this),
1462
+ valueNow: this.#getARIAValueNow.bind(this),
1463
+ valueText: this.#getARIAValueText.bind(this)
1464
+ },
1465
+ onDragValueChange: this.#onDragValueChange.bind(this),
1466
+ onValueChange: this.#onValueChange.bind(this)
1467
+ }).attach(this);
1468
+ effect(this.#watchVolume.bind(this));
1469
+ }
1470
+ onAttach(el) {
1471
+ el.setAttribute("data-media-volume-slider", "");
1472
+ setAttributeIfEmpty(el, "aria-label", "Volume");
1473
+ const { canSetVolume } = this.#media.$state;
1474
+ this.setAttributes({
1475
+ "data-supported": canSetVolume,
1476
+ "aria-hidden": $ariaBool(() => !canSetVolume())
1477
+ });
1478
+ }
1479
+ #getARIAValueNow() {
1480
+ const { value } = this.$state, { audioGain } = this.#media.$state;
1481
+ return Math.round(value() * (audioGain() ?? 1));
1482
+ }
1483
+ #getARIAValueText() {
1484
+ const { value, max } = this.$state, { audioGain } = this.#media.$state;
1485
+ return round(value() / max() * (audioGain() ?? 1) * 100, 2) + "%";
1486
+ }
1487
+ #getARIAValueMax() {
1488
+ const { audioGain } = this.#media.$state;
1489
+ return this.$state.max() * (audioGain() ?? 1);
1490
+ }
1491
+ #isDisabled() {
1492
+ const { disabled } = this.$props, { canSetVolume } = this.#media.$state;
1493
+ return disabled() || !canSetVolume();
1494
+ }
1495
+ #watchVolume() {
1496
+ const { muted, volume } = this.#media.$state;
1497
+ const newValue = muted() ? 0 : volume() * 100;
1498
+ this.$state.value.set(newValue);
1499
+ this.dispatch("value-change", { detail: newValue });
1500
+ }
1501
+ #throttleVolumeChange = functionThrottle(this.#onVolumeChange.bind(this), 25);
1502
+ #onVolumeChange(event) {
1503
+ if (!event.trigger) return;
1504
+ const mediaVolume = round(event.detail / 100, 3);
1505
+ this.#media.remote.changeVolume(mediaVolume, event);
1506
+ }
1507
+ #onValueChange(event) {
1508
+ this.#throttleVolumeChange(event);
1509
+ }
1510
+ #onDragValueChange(event) {
1511
+ this.#throttleVolumeChange(event);
1512
+ }
1513
+ }
1514
+
1515
+ class TimeSlider extends Component {
1516
+ static props = {
1517
+ ...SliderController.props,
1518
+ step: 0.1,
1519
+ keyStep: 5,
1520
+ shiftKeyMultiplier: 2,
1521
+ pauseWhileDragging: false,
1522
+ noSwipeGesture: false,
1523
+ seekingRequestThrottle: 100
1524
+ };
1525
+ static state = sliderState;
1526
+ #media;
1527
+ #dispatchSeeking;
1528
+ #chapter = signal(null);
1529
+ constructor() {
1530
+ super();
1531
+ const { noSwipeGesture } = this.$props;
1532
+ new SliderController({
1533
+ swipeGesture: () => !noSwipeGesture(),
1534
+ getValue: this.#getValue.bind(this),
1535
+ getStep: this.#getStep.bind(this),
1536
+ getKeyStep: this.#getKeyStep.bind(this),
1537
+ roundValue: this.#roundValue,
1538
+ isDisabled: this.#isDisabled.bind(this),
1539
+ aria: {
1540
+ valueNow: this.#getARIAValueNow.bind(this),
1541
+ valueText: this.#getARIAValueText.bind(this)
1542
+ },
1543
+ onDragStart: this.#onDragStart.bind(this),
1544
+ onDragValueChange: this.#onDragValueChange.bind(this),
1545
+ onDragEnd: this.#onDragEnd.bind(this),
1546
+ onValueChange: this.#onValueChange.bind(this)
1547
+ });
1548
+ }
1549
+ onSetup() {
1550
+ this.#media = useMediaContext();
1551
+ provideContext(sliderValueFormatContext, {
1552
+ default: "time",
1553
+ value: this.#formatValue.bind(this),
1554
+ time: this.#formatTime.bind(this)
1555
+ });
1556
+ this.setAttributes({
1557
+ "data-chapters": this.#hasChapters.bind(this)
1558
+ });
1559
+ this.setStyles({
1560
+ "--slider-progress": this.#calcBufferedPercent.bind(this)
1561
+ });
1562
+ effect(this.#watchCurrentTime.bind(this));
1563
+ effect(this.#watchSeekingThrottle.bind(this));
1564
+ }
1565
+ onAttach(el) {
1566
+ el.setAttribute("data-media-time-slider", "");
1567
+ setAttributeIfEmpty(el, "aria-label", "Seek");
1568
+ }
1569
+ onConnect(el) {
1570
+ effect(this.#watchPreviewing.bind(this));
1571
+ watchActiveTextTrack(this.#media.textTracks, "chapters", this.#chapter.set);
1572
+ }
1573
+ #calcBufferedPercent() {
1574
+ const { bufferedEnd, duration } = this.#media.$state;
1575
+ return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1) * 100, 3) + "%";
1576
+ }
1577
+ #hasChapters() {
1578
+ const { duration } = this.#media.$state;
1579
+ return this.#chapter()?.cues.length && Number.isFinite(duration()) && duration() > 0;
1580
+ }
1581
+ #watchSeekingThrottle() {
1582
+ this.#dispatchSeeking = functionThrottle(
1583
+ this.#seeking.bind(this),
1584
+ this.$props.seekingRequestThrottle()
1585
+ );
1586
+ }
1587
+ #watchCurrentTime() {
1588
+ if (this.$state.hidden()) return;
1589
+ const { value, dragging } = this.$state, newValue = this.#getValue();
1590
+ if (!peek(dragging)) {
1591
+ value.set(newValue);
1592
+ this.dispatch("value-change", { detail: newValue });
1593
+ }
1594
+ }
1595
+ #watchPreviewing() {
1596
+ const player = this.#media.player.el, { preview } = useContext(sliderContext);
1597
+ player && preview() && setAttribute(player, "data-preview", this.$state.active());
1598
+ }
1599
+ #seeking(time, event) {
1600
+ this.#media.remote.seeking(time, event);
1601
+ }
1602
+ #seek(time, percent, event) {
1603
+ this.#dispatchSeeking.cancel();
1604
+ const { live } = this.#media.$state;
1605
+ if (live() && percent >= 99) {
1606
+ this.#media.remote.seekToLiveEdge(event);
1607
+ return;
1608
+ }
1609
+ this.#media.remote.seek(time, event);
1610
+ }
1611
+ #playingBeforeDragStart = false;
1612
+ #onDragStart(event) {
1613
+ const { pauseWhileDragging } = this.$props;
1614
+ if (pauseWhileDragging()) {
1615
+ const { paused } = this.#media.$state;
1616
+ this.#playingBeforeDragStart = !paused();
1617
+ this.#media.remote.pause(event);
1618
+ }
1619
+ }
1620
+ #onDragValueChange(event) {
1621
+ this.#dispatchSeeking(this.#percentToTime(event.detail), event);
1622
+ }
1623
+ #onDragEnd(event) {
1624
+ const { seeking } = this.#media.$state;
1625
+ if (!peek(seeking)) this.#seeking(this.#percentToTime(event.detail), event);
1626
+ const percent = event.detail;
1627
+ this.#seek(this.#percentToTime(percent), percent, event);
1628
+ const { pauseWhileDragging } = this.$props;
1629
+ if (pauseWhileDragging() && this.#playingBeforeDragStart) {
1630
+ this.#media.remote.play(event);
1631
+ this.#playingBeforeDragStart = false;
1632
+ }
1633
+ }
1634
+ #onValueChange(event) {
1635
+ const { dragging } = this.$state;
1636
+ if (dragging() || !event.trigger) return;
1637
+ this.#onDragEnd(event);
1638
+ }
1639
+ // -------------------------------------------------------------------------------------------
1640
+ // Props
1641
+ // -------------------------------------------------------------------------------------------
1642
+ #getValue() {
1643
+ const { currentTime } = this.#media.$state;
1644
+ return this.#timeToPercent(currentTime());
1645
+ }
1646
+ #getStep() {
1647
+ const value = this.$props.step() / this.#media.$state.duration() * 100;
1648
+ return Number.isFinite(value) ? value : 1;
1649
+ }
1650
+ #getKeyStep() {
1651
+ const value = this.$props.keyStep() / this.#media.$state.duration() * 100;
1652
+ return Number.isFinite(value) ? value : 1;
1653
+ }
1654
+ #roundValue(value) {
1655
+ return round(value, 3);
1656
+ }
1657
+ #isDisabled() {
1658
+ const { disabled } = this.$props, { canSeek } = this.#media.$state;
1659
+ return disabled() || !canSeek();
1660
+ }
1661
+ // -------------------------------------------------------------------------------------------
1662
+ // ARIA
1663
+ // -------------------------------------------------------------------------------------------
1664
+ #getARIAValueNow() {
1665
+ const { value } = this.$state;
1666
+ return Math.round(value());
1667
+ }
1668
+ #getARIAValueText() {
1669
+ const time = this.#percentToTime(this.$state.value()), { duration } = this.#media.$state;
1670
+ return Number.isFinite(time) ? `${formatSpokenTime(time)} out of ${formatSpokenTime(duration())}` : "live";
1671
+ }
1672
+ // -------------------------------------------------------------------------------------------
1673
+ // Format
1674
+ // -------------------------------------------------------------------------------------------
1675
+ #percentToTime(percent) {
1676
+ const { duration } = this.#media.$state;
1677
+ return round(percent / 100 * duration(), 5);
1678
+ }
1679
+ #timeToPercent(time) {
1680
+ const { liveEdge, duration } = this.#media.$state, rate = Math.max(0, Math.min(1, liveEdge() ? 1 : Math.min(time, duration()) / duration()));
1681
+ return Number.isNaN(rate) ? 0 : Number.isFinite(rate) ? rate * 100 : 100;
1682
+ }
1683
+ #formatValue(percent) {
1684
+ const time = this.#percentToTime(percent), { live, duration } = this.#media.$state;
1685
+ return Number.isFinite(time) ? (live() ? time - duration() : time).toFixed(0) : "LIVE";
1686
+ }
1687
+ #formatTime(percent, options) {
1688
+ const time = this.#percentToTime(percent), { live, duration } = this.#media.$state, value = live() ? time - duration() : time;
1689
+ return Number.isFinite(time) ? `${value < 0 ? "-" : ""}${formatTime(Math.abs(value), options)}` : "LIVE";
1690
+ }
1691
+ }
1692
+
1693
+ const menuContext = createContext();
1694
+
1695
+ function scrollIntoView(el, options) {
1696
+ const scrolls = r(el, options);
1697
+ for (const { el: el2, top, left } of scrolls) {
1698
+ el2.scroll({ top, left, behavior: options.behavior });
1699
+ }
1700
+ }
1701
+ function scrollIntoCenter(el, options = {}) {
1702
+ scrollIntoView(el, {
1703
+ scrollMode: "if-needed",
1704
+ block: "center",
1705
+ inline: "center",
1706
+ ...options
1707
+ });
1708
+ }
1709
+
1710
+ const FOCUSABLE_ELEMENTS_SELECTOR = /* @__PURE__ */ [
1711
+ "a[href]",
1712
+ "[tabindex]",
1713
+ "input",
1714
+ "select",
1715
+ "button"
1716
+ ].map((selector) => `${selector}:not([aria-hidden='true'])`).join(",");
1717
+ const VALID_KEYS = /* @__PURE__ */ new Set([
1718
+ "Escape",
1719
+ "Tab",
1720
+ "ArrowUp",
1721
+ "ArrowDown",
1722
+ "Home",
1723
+ "PageUp",
1724
+ "End",
1725
+ "PageDown",
1726
+ "Enter",
1727
+ " "
1728
+ ]);
1729
+ class MenuFocusController {
1730
+ #index = -1;
1731
+ #el = null;
1732
+ #elements = [];
1733
+ #delegate;
1734
+ get items() {
1735
+ return this.#elements;
1736
+ }
1737
+ constructor(delegate) {
1738
+ this.#delegate = delegate;
1739
+ }
1740
+ attachMenu(el) {
1741
+ listenEvent(el, "focus", this.#onFocus.bind(this));
1742
+ this.#el = el;
1743
+ onDispose(() => {
1744
+ this.#el = null;
1745
+ });
1746
+ }
1747
+ listen() {
1748
+ if (!this.#el) return;
1749
+ this.update();
1750
+ new EventsController(this.#el).add("keyup", this.#onKeyUp.bind(this)).add("keydown", this.#onKeyDown.bind(this));
1751
+ onDispose(() => {
1752
+ this.#index = -1;
1753
+ this.#elements = [];
1754
+ });
1755
+ }
1756
+ update() {
1757
+ this.#index = 0;
1758
+ this.#elements = this.#getFocusableElements();
1759
+ }
1760
+ scroll(index = this.#findActiveIndex()) {
1761
+ const element = this.#elements[index];
1762
+ if (element) {
1763
+ requestAnimationFrame(() => {
1764
+ requestAnimationFrame(() => {
1765
+ scrollIntoCenter(element, {
1766
+ behavior: "smooth",
1767
+ boundary: (el) => {
1768
+ return !el.hasAttribute("data-root");
1769
+ }
1770
+ });
1771
+ });
1772
+ });
1773
+ }
1774
+ }
1775
+ focusActive(scroll = true) {
1776
+ const index = this.#findActiveIndex();
1777
+ this.#focusAt(index >= 0 ? index : 0, scroll);
1778
+ }
1779
+ #focusAt(index, scroll = true) {
1780
+ this.#index = index;
1781
+ if (this.#elements[index]) {
1782
+ this.#elements[index].focus({ preventScroll: true });
1783
+ if (scroll) this.scroll(index);
1784
+ } else {
1785
+ this.#el?.focus({ preventScroll: true });
1786
+ }
1787
+ }
1788
+ #findActiveIndex() {
1789
+ return this.#elements.findIndex(
1790
+ (el) => document.activeElement === el || el.getAttribute("role") === "menuitemradio" && el.getAttribute("aria-checked") === "true"
1791
+ );
1792
+ }
1793
+ #onFocus() {
1794
+ if (this.#index >= 0) return;
1795
+ this.update();
1796
+ this.focusActive();
1797
+ }
1798
+ #validateKeyEvent(event) {
1799
+ const el = event.target;
1800
+ if (wasEnterKeyPressed(event) && el instanceof Element) {
1801
+ const role = el.getAttribute("role");
1802
+ return !/a|input|select|button/.test(el.localName) && !role;
1803
+ }
1804
+ return VALID_KEYS.has(event.key);
1805
+ }
1806
+ #onKeyUp(event) {
1807
+ if (!this.#validateKeyEvent(event)) return;
1808
+ event.stopPropagation();
1809
+ event.preventDefault();
1810
+ }
1811
+ #onKeyDown(event) {
1812
+ if (!this.#validateKeyEvent(event)) return;
1813
+ event.stopPropagation();
1814
+ event.preventDefault();
1815
+ switch (event.key) {
1816
+ case "Escape":
1817
+ this.#delegate.closeMenu(event);
1818
+ break;
1819
+ case "Tab":
1820
+ this.#focusAt(this.#nextIndex(event.shiftKey ? -1 : 1));
1821
+ break;
1822
+ case "ArrowUp":
1823
+ this.#focusAt(this.#nextIndex(-1));
1824
+ break;
1825
+ case "ArrowDown":
1826
+ this.#focusAt(this.#nextIndex(1));
1827
+ break;
1828
+ case "Home":
1829
+ case "PageUp":
1830
+ this.#focusAt(0);
1831
+ break;
1832
+ case "End":
1833
+ case "PageDown":
1834
+ this.#focusAt(this.#elements.length - 1);
1835
+ break;
1836
+ }
1837
+ }
1838
+ #nextIndex(delta) {
1839
+ let index = this.#index;
1840
+ do {
1841
+ index = (index + delta + this.#elements.length) % this.#elements.length;
1842
+ } while (this.#elements[index]?.offsetParent === null);
1843
+ return index;
1844
+ }
1845
+ #getFocusableElements() {
1846
+ if (!this.#el) return [];
1847
+ const focusableElements = this.#el.querySelectorAll(FOCUSABLE_ELEMENTS_SELECTOR), elements = [];
1848
+ const is = (node) => {
1849
+ return node.getAttribute("role") === "menu";
1850
+ };
1851
+ for (const el of focusableElements) {
1852
+ if (isHTMLElement(el) && el.offsetParent !== null && // does not have display: none
1853
+ isElementParent(this.#el, el, is)) {
1854
+ elements.push(el);
1855
+ }
1856
+ }
1857
+ return elements;
1858
+ }
1859
+ }
1860
+
1861
+ var __defProp = Object.defineProperty;
1862
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1863
+ var __decorateClass = (decorators, target, key, kind) => {
1864
+ var result = __getOwnPropDesc(target, key) ;
1865
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1866
+ if (decorator = decorators[i])
1867
+ result = (decorator(target, key, result) ) || result;
1868
+ if (result) __defProp(target, key, result);
1869
+ return result;
1870
+ };
1871
+ let idCount = 0;
1872
+ class Menu extends Component {
1873
+ static props = {
1874
+ showDelay: 0
1875
+ };
1876
+ #media;
1877
+ #menuId;
1878
+ #menuButtonId;
1879
+ #expanded = signal(false);
1880
+ #disabled = signal(false);
1881
+ #trigger = signal(null);
1882
+ #content = signal(null);
1883
+ #parentMenu;
1884
+ #submenus = /* @__PURE__ */ new Set();
1885
+ #menuObserver = null;
1886
+ #popper;
1887
+ #focus;
1888
+ #isSliderActive = false;
1889
+ #isTriggerDisabled = signal(false);
1890
+ #transitionCallbacks = /* @__PURE__ */ new Set();
1891
+ get triggerElement() {
1892
+ return this.#trigger();
1893
+ }
1894
+ get contentElement() {
1895
+ return this.#content();
1896
+ }
1897
+ get isSubmenu() {
1898
+ return !!this.#parentMenu;
1899
+ }
1900
+ constructor() {
1901
+ super();
1902
+ const { showDelay } = this.$props;
1903
+ this.#popper = new Popper({
1904
+ trigger: this.#trigger,
1905
+ content: this.#content,
1906
+ showDelay,
1907
+ listen: (trigger, show, hide) => {
1908
+ onPress(trigger, (event) => {
1909
+ if (this.#expanded()) hide(event);
1910
+ else show(event);
1911
+ });
1912
+ const closeTarget = this.#getCloseTarget();
1913
+ if (closeTarget) {
1914
+ onPress(closeTarget, (event) => {
1915
+ event.stopPropagation();
1916
+ hide(event);
1917
+ });
1918
+ }
1919
+ },
1920
+ onChange: this.#onExpandedChange.bind(this)
1921
+ });
1922
+ }
1923
+ onSetup() {
1924
+ this.#media = useMediaContext();
1925
+ const currentIdCount = ++idCount;
1926
+ this.#menuId = `media-menu-${currentIdCount}`;
1927
+ this.#menuButtonId = `media-menu-button-${currentIdCount}`;
1928
+ this.#focus = new MenuFocusController({
1929
+ closeMenu: this.close.bind(this)
1930
+ });
1931
+ if (hasProvidedContext(menuContext)) {
1932
+ this.#parentMenu = useContext(menuContext);
1933
+ }
1934
+ this.#observeSliders();
1935
+ this.setAttributes({
1936
+ "data-open": this.#expanded,
1937
+ "data-root": !this.isSubmenu,
1938
+ "data-submenu": this.isSubmenu,
1939
+ "data-disabled": this.#isDisabled.bind(this)
1940
+ });
1941
+ provideContext(menuContext, {
1942
+ button: this.#trigger,
1943
+ content: this.#content,
1944
+ expanded: this.#expanded,
1945
+ hint: signal(""),
1946
+ submenu: !!this.#parentMenu,
1947
+ disable: this.#disable.bind(this),
1948
+ attachMenuButton: this.#attachMenuButton.bind(this),
1949
+ attachMenuItems: this.#attachMenuItems.bind(this),
1950
+ attachObserver: this.#attachObserver.bind(this),
1951
+ disableMenuButton: this.#disableMenuButton.bind(this),
1952
+ addSubmenu: this.#addSubmenu.bind(this),
1953
+ onTransitionEvent: (callback) => {
1954
+ this.#transitionCallbacks.add(callback);
1955
+ onDispose(() => {
1956
+ this.#transitionCallbacks.delete(callback);
1957
+ });
1958
+ }
1959
+ });
1960
+ }
1961
+ onAttach(el) {
1962
+ el.style.setProperty("display", "contents");
1963
+ }
1964
+ onConnect(el) {
1965
+ effect(this.#watchExpanded.bind(this));
1966
+ if (this.isSubmenu) {
1967
+ this.#parentMenu?.addSubmenu(this);
1968
+ }
1969
+ }
1970
+ onDestroy() {
1971
+ this.#trigger.set(null);
1972
+ this.#content.set(null);
1973
+ this.#menuObserver = null;
1974
+ this.#transitionCallbacks.clear();
1975
+ }
1976
+ #observeSliders() {
1977
+ let sliderActiveTimer = -1, parentSliderObserver = hasProvidedContext(sliderObserverContext) ? useContext(sliderObserverContext) : null;
1978
+ provideContext(sliderObserverContext, {
1979
+ onDragStart: () => {
1980
+ parentSliderObserver?.onDragStart?.();
1981
+ window.clearTimeout(sliderActiveTimer);
1982
+ sliderActiveTimer = -1;
1983
+ this.#isSliderActive = true;
1984
+ },
1985
+ onDragEnd: () => {
1986
+ parentSliderObserver?.onDragEnd?.();
1987
+ sliderActiveTimer = window.setTimeout(() => {
1988
+ this.#isSliderActive = false;
1989
+ sliderActiveTimer = -1;
1990
+ }, 300);
1991
+ }
1992
+ });
1993
+ }
1994
+ #watchExpanded() {
1995
+ const expanded = this.#isExpanded();
1996
+ if (!this.isSubmenu) this.#onResize();
1997
+ this.#updateMenuItemsHidden(expanded);
1998
+ if (!expanded) return;
1999
+ effect(() => {
2000
+ const { height } = this.#media.$state, content = this.#content();
2001
+ content && setStyle(content, "--player-height", height() + "px");
2002
+ });
2003
+ this.#focus.listen();
2004
+ this.listen("pointerup", this.#onPointerUp.bind(this));
2005
+ listenEvent(window, "pointerup", this.#onWindowPointerUp.bind(this));
2006
+ }
2007
+ #attachMenuButton(button) {
2008
+ const el = button.el, isMenuItem = this.isSubmenu, isARIADisabled = $ariaBool(this.#isDisabled.bind(this));
2009
+ setAttributeIfEmpty(el, "tabindex", isMenuItem ? "-1" : "0");
2010
+ setAttributeIfEmpty(el, "role", isMenuItem ? "menuitem" : "button");
2011
+ setAttribute(el, "id", this.#menuButtonId);
2012
+ setAttribute(el, "aria-haspopup", "menu");
2013
+ setAttribute(el, "aria-expanded", "false");
2014
+ setAttribute(el, "data-root", !this.isSubmenu);
2015
+ setAttribute(el, "data-submenu", this.isSubmenu);
2016
+ const watchAttrs = () => {
2017
+ setAttribute(el, "data-open", this.#expanded());
2018
+ setAttribute(el, "aria-disabled", isARIADisabled());
2019
+ };
2020
+ effect(watchAttrs);
2021
+ this.#trigger.set(el);
2022
+ onDispose(() => {
2023
+ this.#trigger.set(null);
2024
+ });
2025
+ }
2026
+ #attachMenuItems(items) {
2027
+ const el = items.el;
2028
+ el.style.setProperty("display", "none");
2029
+ setAttribute(el, "id", this.#menuId);
2030
+ setAttributeIfEmpty(el, "role", "menu");
2031
+ setAttributeIfEmpty(el, "tabindex", "-1");
2032
+ setAttribute(el, "data-root", !this.isSubmenu);
2033
+ setAttribute(el, "data-submenu", this.isSubmenu);
2034
+ this.#content.set(el);
2035
+ onDispose(() => this.#content.set(null));
2036
+ const watchAttrs = () => setAttribute(el, "data-open", this.#expanded());
2037
+ effect(watchAttrs);
2038
+ this.#focus.attachMenu(el);
2039
+ this.#updateMenuItemsHidden(false);
2040
+ const onTransition = this.#onResizeTransition.bind(this);
2041
+ if (!this.isSubmenu) {
2042
+ items.listen("transitionstart", onTransition);
2043
+ items.listen("transitionend", onTransition);
2044
+ items.listen("animationend", this.#onResize);
2045
+ items.listen("vds-menu-resize", this.#onResize);
2046
+ } else {
2047
+ this.#parentMenu?.onTransitionEvent(onTransition);
2048
+ }
2049
+ }
2050
+ #attachObserver(observer) {
2051
+ this.#menuObserver = observer;
2052
+ }
2053
+ #updateMenuItemsHidden(expanded) {
2054
+ const content = peek(this.#content);
2055
+ if (content) setAttribute(content, "aria-hidden", ariaBool(!expanded));
2056
+ }
2057
+ #disableMenuButton(disabled) {
2058
+ this.#isTriggerDisabled.set(disabled);
2059
+ }
2060
+ #wasKeyboardExpand = false;
2061
+ #onExpandedChange(isExpanded, event) {
2062
+ this.#wasKeyboardExpand = isKeyboardEvent(event);
2063
+ event?.stopPropagation();
2064
+ if (this.#expanded() === isExpanded) return;
2065
+ if (this.#isDisabled()) {
2066
+ if (isExpanded) this.#popper.hide(event);
2067
+ return;
2068
+ }
2069
+ this.el?.dispatchEvent(
2070
+ new Event("vds-menu-resize", {
2071
+ bubbles: true,
2072
+ composed: true
2073
+ })
2074
+ );
2075
+ const trigger = this.#trigger(), content = this.#content();
2076
+ if (trigger) {
2077
+ setAttribute(trigger, "aria-controls", isExpanded && this.#menuId);
2078
+ setAttribute(trigger, "aria-expanded", ariaBool(isExpanded));
2079
+ }
2080
+ if (content) setAttribute(content, "aria-labelledby", isExpanded && this.#menuButtonId);
2081
+ this.#expanded.set(isExpanded);
2082
+ this.#toggleMediaControls(event);
2083
+ tick();
2084
+ if (this.#wasKeyboardExpand) {
2085
+ if (isExpanded) content?.focus();
2086
+ else trigger?.focus();
2087
+ for (const el of [this.el, content]) {
2088
+ el && el.setAttribute("data-keyboard", "");
2089
+ }
2090
+ } else {
2091
+ for (const el of [this.el, content]) {
2092
+ el && el.removeAttribute("data-keyboard");
2093
+ }
2094
+ }
2095
+ this.dispatch(isExpanded ? "open" : "close", { trigger: event });
2096
+ if (isExpanded) {
2097
+ if (!this.isSubmenu && this.#media.activeMenu !== this) {
2098
+ this.#media.activeMenu?.close(event);
2099
+ this.#media.activeMenu = this;
2100
+ }
2101
+ this.#menuObserver?.onOpen?.(event);
2102
+ } else {
2103
+ if (this.isSubmenu) {
2104
+ for (const el of this.#submenus) el.close(event);
2105
+ } else {
2106
+ this.#media.activeMenu = null;
2107
+ }
2108
+ this.#menuObserver?.onClose?.(event);
2109
+ }
2110
+ if (isExpanded) {
2111
+ requestAnimationFrame(this.#updateFocus.bind(this));
2112
+ }
2113
+ }
2114
+ #updateFocus() {
2115
+ if (this.#isTransitionActive || this.#isSubmenuOpen) return;
2116
+ this.#focus.update();
2117
+ requestAnimationFrame(() => {
2118
+ if (this.#wasKeyboardExpand) {
2119
+ this.#focus.focusActive();
2120
+ } else {
2121
+ this.#focus.scroll();
2122
+ }
2123
+ });
2124
+ }
2125
+ #isExpanded() {
2126
+ return !this.#isDisabled() && this.#expanded();
2127
+ }
2128
+ #isDisabled() {
2129
+ return this.#disabled() || this.#isTriggerDisabled();
2130
+ }
2131
+ #disable(disabled) {
2132
+ this.#disabled.set(disabled);
2133
+ }
2134
+ #onPointerUp(event) {
2135
+ const content = this.#content();
2136
+ if (this.#isSliderActive || content && isEventInside(content, event)) {
2137
+ return;
2138
+ }
2139
+ event.stopPropagation();
2140
+ }
2141
+ #onWindowPointerUp(event) {
2142
+ const content = this.#content();
2143
+ if (this.#isSliderActive || content && isEventInside(content, event)) {
2144
+ return;
2145
+ }
2146
+ this.close(event);
2147
+ }
2148
+ #getCloseTarget() {
2149
+ const target = this.el?.querySelector('[data-part="close-target"]');
2150
+ return this.el && target && isElementParent(this.el, target, (node) => node.getAttribute("role") === "menu") ? target : null;
2151
+ }
2152
+ #toggleMediaControls(trigger) {
2153
+ if (this.isSubmenu) return;
2154
+ if (this.#expanded()) this.#media.remote.pauseControls(trigger);
2155
+ else this.#media.remote.resumeControls(trigger);
2156
+ }
2157
+ #addSubmenu(menu) {
2158
+ this.#submenus.add(menu);
2159
+ new EventsController(menu).add("open", this.#onSubmenuOpenBind).add("close", this.#onSubmenuCloseBind);
2160
+ onDispose(this.#removeSubmenuBind);
2161
+ }
2162
+ #removeSubmenuBind = this.#removeSubmenu.bind(this);
2163
+ #removeSubmenu(menu) {
2164
+ this.#submenus.delete(menu);
2165
+ }
2166
+ #isSubmenuOpen = false;
2167
+ #onSubmenuOpenBind = this.#onSubmenuOpen.bind(this);
2168
+ #onSubmenuOpen(event) {
2169
+ this.#isSubmenuOpen = true;
2170
+ const content = this.#content();
2171
+ if (this.isSubmenu) {
2172
+ this.triggerElement?.setAttribute("aria-hidden", "true");
2173
+ }
2174
+ for (const target of this.#submenus) {
2175
+ if (target !== event.target) {
2176
+ for (const el of [target.el, target.triggerElement]) {
2177
+ el?.setAttribute("aria-hidden", "true");
2178
+ }
2179
+ }
2180
+ }
2181
+ if (content) {
2182
+ const el = event.target.el;
2183
+ for (const child of content.children) {
2184
+ if (child.contains(el)) {
2185
+ child.setAttribute("data-open", "");
2186
+ } else if (child !== el) {
2187
+ child.setAttribute("data-hidden", "");
2188
+ }
2189
+ }
2190
+ }
2191
+ }
2192
+ #onSubmenuCloseBind = this.#onSubmenuClose.bind(this);
2193
+ #onSubmenuClose(event) {
2194
+ this.#isSubmenuOpen = false;
2195
+ const content = this.#content();
2196
+ if (this.isSubmenu) {
2197
+ this.triggerElement?.setAttribute("aria-hidden", "false");
2198
+ }
2199
+ for (const target of this.#submenus) {
2200
+ for (const el of [target.el, target.triggerElement]) {
2201
+ el?.setAttribute("aria-hidden", "false");
2202
+ }
2203
+ }
2204
+ if (content) {
2205
+ for (const child of content.children) {
2206
+ child.removeAttribute("data-open");
2207
+ child.removeAttribute("data-hidden");
2208
+ }
2209
+ }
2210
+ }
2211
+ #onResize = animationFrameThrottle(() => {
2212
+ const content = peek(this.#content);
2213
+ if (!content || false) return;
2214
+ let height = 0, styles = getComputedStyle(content), children = [...content.children];
2215
+ for (const prop2 of ["paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"]) {
2216
+ height += parseFloat(styles[prop2]) || 0;
2217
+ }
2218
+ for (const child of children) {
2219
+ if (isHTMLElement(child) && child.style.display === "contents") {
2220
+ children.push(...child.children);
2221
+ } else if (child.nodeType === 3) {
2222
+ height += parseFloat(getComputedStyle(child).fontSize);
2223
+ } else if (isHTMLElement(child)) {
2224
+ if (!isElementVisible(child)) continue;
2225
+ const style = getComputedStyle(child);
2226
+ height += child.offsetHeight + (parseFloat(style.marginTop) || 0) + (parseFloat(style.marginBottom) || 0);
2227
+ }
2228
+ }
2229
+ setStyle(content, "--menu-height", height + "px");
2230
+ });
2231
+ #isTransitionActive = false;
2232
+ #onResizeTransition(event) {
2233
+ const content = this.#content();
2234
+ if (content && event.propertyName === "height") {
2235
+ this.#isTransitionActive = event.type === "transitionstart";
2236
+ setAttribute(content, "data-transition", this.#isTransitionActive ? "height" : null);
2237
+ if (this.#expanded()) this.#updateFocus();
2238
+ }
2239
+ for (const callback of this.#transitionCallbacks) callback(event);
2240
+ }
2241
+ open(trigger) {
2242
+ if (peek(this.#expanded)) return;
2243
+ this.#popper.show(trigger);
2244
+ tick();
2245
+ }
2246
+ close(trigger) {
2247
+ if (!peek(this.#expanded)) return;
2248
+ this.#popper.hide(trigger);
2249
+ tick();
2250
+ }
2251
+ }
2252
+ __decorateClass([
2253
+ prop
2254
+ ], Menu.prototype, "triggerElement");
2255
+ __decorateClass([
2256
+ prop
2257
+ ], Menu.prototype, "contentElement");
2258
+ __decorateClass([
2259
+ prop
2260
+ ], Menu.prototype, "isSubmenu");
2261
+ __decorateClass([
2262
+ method
2263
+ ], Menu.prototype, "open");
2264
+ __decorateClass([
2265
+ method
2266
+ ], Menu.prototype, "close");
2267
+
2268
+ class MenuButton extends Component {
2269
+ static props = {
2270
+ disabled: false
2271
+ };
2272
+ #menu;
2273
+ #hintEl = signal(null);
2274
+ get expanded() {
2275
+ return this.#menu?.expanded() ?? false;
2276
+ }
2277
+ constructor() {
2278
+ super();
2279
+ new FocusVisibleController();
2280
+ }
2281
+ onSetup() {
2282
+ this.#menu = useContext(menuContext);
2283
+ }
2284
+ onAttach(el) {
2285
+ this.#menu.attachMenuButton(this);
2286
+ effect(this.#watchDisabled.bind(this));
2287
+ setAttributeIfEmpty(el, "type", "button");
2288
+ }
2289
+ onConnect(el) {
2290
+ effect(this.#watchHintEl.bind(this));
2291
+ this.#onMutation();
2292
+ const mutations = new MutationObserver(this.#onMutation.bind(this));
2293
+ mutations.observe(el, { attributeFilter: ["data-part"], childList: true, subtree: true });
2294
+ onDispose(() => mutations.disconnect());
2295
+ onPress(el, (trigger) => {
2296
+ this.dispatch("select", { trigger });
2297
+ });
2298
+ }
2299
+ #watchDisabled() {
2300
+ this.#menu.disableMenuButton(this.$props.disabled());
2301
+ }
2302
+ #watchHintEl() {
2303
+ const el = this.#hintEl();
2304
+ if (!el) return;
2305
+ effect(() => {
2306
+ const text = this.#menu.hint();
2307
+ if (text) el.textContent = text;
2308
+ });
2309
+ }
2310
+ #onMutation() {
2311
+ const hintEl = this.el?.querySelector('[data-part="hint"]');
2312
+ this.#hintEl.set(hintEl ?? null);
2313
+ }
2314
+ }
2315
+ const menubutton__proto = MenuButton.prototype;
2316
+ prop(menubutton__proto, "expanded");
2317
+
2318
+ class MenuItem extends MenuButton {
2319
+ }
2320
+
2321
+ class MenuPortal extends Component {
2322
+ static props = {
2323
+ container: null,
2324
+ disabled: false
2325
+ };
2326
+ #target = null;
2327
+ #media;
2328
+ onSetup() {
2329
+ this.#media = useMediaContext();
2330
+ provideContext(menuPortalContext, {
2331
+ attach: this.#attachElement.bind(this)
2332
+ });
2333
+ }
2334
+ onAttach(el) {
2335
+ el.style.setProperty("display", "contents");
2336
+ }
2337
+ // Need this so connect scope is defined.
2338
+ onConnect(el) {
2339
+ }
2340
+ onDestroy() {
2341
+ this.#target?.remove();
2342
+ this.#target = null;
2343
+ }
2344
+ #attachElement(el) {
2345
+ this.#portal(false);
2346
+ this.#target = el;
2347
+ requestScopedAnimationFrame(() => {
2348
+ requestScopedAnimationFrame(() => {
2349
+ if (!this.connectScope) return;
2350
+ effect(this.#watchDisabled.bind(this));
2351
+ });
2352
+ });
2353
+ }
2354
+ #watchDisabled() {
2355
+ const { fullscreen } = this.#media.$state, { disabled } = this.$props;
2356
+ this.#portal(disabled() === "fullscreen" ? !fullscreen() : !disabled());
2357
+ }
2358
+ #portal(shouldPortal) {
2359
+ if (!this.#target) return;
2360
+ let container = this.#getContainer(this.$props.container());
2361
+ if (!container) return;
2362
+ const isPortalled = this.#target.parentElement === container;
2363
+ setAttribute(this.#target, "data-portal", shouldPortal);
2364
+ if (shouldPortal) {
2365
+ if (!isPortalled) {
2366
+ this.#target.remove();
2367
+ container.append(this.#target);
2368
+ }
2369
+ } else if (isPortalled && this.#target.parentElement === container) {
2370
+ this.#target.remove();
2371
+ this.el?.append(this.#target);
2372
+ }
2373
+ }
2374
+ #getContainer(selector) {
2375
+ if (isHTMLElement(selector)) return selector;
2376
+ return selector ? document.querySelector(selector) : document.body;
2377
+ }
2378
+ }
2379
+ const menuPortalContext = createContext();
2380
+
2381
+ class MenuItems extends Component {
2382
+ static props = {
2383
+ placement: null,
2384
+ offset: 0,
2385
+ alignOffset: 0
2386
+ };
2387
+ #menu;
2388
+ constructor() {
2389
+ super();
2390
+ new FocusVisibleController();
2391
+ const { placement } = this.$props;
2392
+ this.setAttributes({
2393
+ "data-placement": placement
2394
+ });
2395
+ }
2396
+ onAttach(el) {
2397
+ this.#menu = useContext(menuContext);
2398
+ this.#menu.attachMenuItems(this);
2399
+ if (hasProvidedContext(menuPortalContext)) {
2400
+ const portal = useContext(menuPortalContext);
2401
+ if (portal) {
2402
+ provideContext(menuPortalContext, null);
2403
+ portal.attach(el);
2404
+ onDispose(() => portal.attach(null));
2405
+ }
2406
+ }
2407
+ }
2408
+ onConnect(el) {
2409
+ effect(this.#watchPlacement.bind(this));
2410
+ }
2411
+ #watchPlacement() {
2412
+ const { expanded } = this.#menu;
2413
+ if (!this.el || !expanded()) return;
2414
+ const placement = this.$props.placement();
2415
+ if (!placement) return;
2416
+ Object.assign(this.el.style, {
2417
+ position: "absolute",
2418
+ top: 0,
2419
+ left: 0,
2420
+ width: "max-content"
2421
+ });
2422
+ const { offset: mainOffset, alignOffset } = this.$props;
2423
+ onDispose(
2424
+ autoPlacement(this.el, this.#getButton(), placement, {
2425
+ offsetVarName: "media-menu",
2426
+ xOffset: alignOffset(),
2427
+ yOffset: mainOffset()
2428
+ })
2429
+ );
2430
+ onDispose(this.#hide.bind(this));
2431
+ }
2432
+ #hide() {
2433
+ if (!this.el) return;
2434
+ this.el.removeAttribute("style");
2435
+ this.el.style.display = "none";
2436
+ }
2437
+ #getButton() {
2438
+ return this.#menu.button();
2439
+ }
2440
+ }
2441
+
2442
+ const radioControllerContext = createContext();
2443
+
2444
+ class RadioGroupController extends ViewController {
2445
+ #group = /* @__PURE__ */ new Set();
2446
+ #value = signal("");
2447
+ #controller = null;
2448
+ onValueChange;
2449
+ get values() {
2450
+ return Array.from(this.#group).map((radio) => radio.value());
2451
+ }
2452
+ get value() {
2453
+ return this.#value();
2454
+ }
2455
+ set value(value) {
2456
+ this.#onChange(value);
2457
+ }
2458
+ onSetup() {
2459
+ provideContext(radioControllerContext, {
2460
+ add: this.#addRadio.bind(this),
2461
+ remove: this.#removeRadio.bind(this)
2462
+ });
2463
+ }
2464
+ onAttach(el) {
2465
+ const isMenuItem = hasProvidedContext(menuContext);
2466
+ if (!isMenuItem) setAttributeIfEmpty(el, "role", "radiogroup");
2467
+ this.setAttributes({ value: this.#value });
2468
+ }
2469
+ onDestroy() {
2470
+ this.#group.clear();
2471
+ }
2472
+ #addRadio(radio) {
2473
+ if (this.#group.has(radio)) return;
2474
+ this.#group.add(radio);
2475
+ radio.onCheck = this.#onChangeBind;
2476
+ radio.check(radio.value() === this.#value());
2477
+ }
2478
+ #removeRadio(radio) {
2479
+ radio.onCheck = null;
2480
+ this.#group.delete(radio);
2481
+ }
2482
+ #onChangeBind = this.#onChange.bind(this);
2483
+ #onChange(newValue, trigger) {
2484
+ const currentValue = peek(this.#value);
2485
+ if (!newValue || newValue === currentValue) return;
2486
+ const currentRadio = this.#findRadio(currentValue), newRadio = this.#findRadio(newValue);
2487
+ currentRadio?.check(false, trigger);
2488
+ newRadio?.check(true, trigger);
2489
+ this.#value.set(newValue);
2490
+ this.onValueChange?.(newValue, trigger);
2491
+ }
2492
+ #findRadio(newValue) {
2493
+ for (const radio of this.#group) {
2494
+ if (newValue === peek(radio.value)) return radio;
2495
+ }
2496
+ return null;
2497
+ }
2498
+ }
2499
+
2500
+ class Radio extends Component {
2501
+ static props = {
2502
+ value: ""
2503
+ };
2504
+ #checked = signal(false);
2505
+ #controller = {
2506
+ value: this.$props.value,
2507
+ check: this.#check.bind(this),
2508
+ onCheck: null
2509
+ };
2510
+ /**
2511
+ * Whether this radio is currently checked.
2512
+ */
2513
+ get checked() {
2514
+ return this.#checked();
2515
+ }
2516
+ constructor() {
2517
+ super();
2518
+ new FocusVisibleController();
2519
+ }
2520
+ onSetup() {
2521
+ this.setAttributes({
2522
+ value: this.$props.value,
2523
+ "data-checked": this.#checked,
2524
+ "aria-checked": $ariaBool(this.#checked)
2525
+ });
2526
+ }
2527
+ onAttach(el) {
2528
+ const isMenuItem = hasProvidedContext(menuContext);
2529
+ setAttributeIfEmpty(el, "tabindex", isMenuItem ? "-1" : "0");
2530
+ setAttributeIfEmpty(el, "role", isMenuItem ? "menuitemradio" : "radio");
2531
+ effect(this.#watchValue.bind(this));
2532
+ }
2533
+ onConnect(el) {
2534
+ this.#addToGroup();
2535
+ onPress(el, this.#onPress.bind(this));
2536
+ onDispose(this.#onDisconnect.bind(this));
2537
+ }
2538
+ #onDisconnect() {
2539
+ scoped(() => {
2540
+ const group = useContext(radioControllerContext);
2541
+ group.remove(this.#controller);
2542
+ }, this.connectScope);
2543
+ }
2544
+ #addToGroup() {
2545
+ const group = useContext(radioControllerContext);
2546
+ group.add(this.#controller);
2547
+ }
2548
+ #watchValue() {
2549
+ const { value } = this.$props, newValue = value();
2550
+ if (peek(this.#checked)) {
2551
+ this.#controller.onCheck?.(newValue);
2552
+ }
2553
+ }
2554
+ #onPress(event) {
2555
+ if (peek(this.#checked)) return;
2556
+ this.#onChange(true, event);
2557
+ this.#onSelect(event);
2558
+ this.#controller.onCheck?.(peek(this.$props.value), event);
2559
+ }
2560
+ #check(value, trigger) {
2561
+ if (peek(this.#checked) === value) return;
2562
+ this.#onChange(value, trigger);
2563
+ }
2564
+ #onChange(value, trigger) {
2565
+ this.#checked.set(value);
2566
+ this.dispatch("change", { detail: value, trigger });
2567
+ }
2568
+ #onSelect(trigger) {
2569
+ this.dispatch("select", { trigger });
2570
+ }
2571
+ }
2572
+ const radio__proto = Radio.prototype;
2573
+ prop(radio__proto, "checked");
2574
+
2575
+ class AudioRadioGroup extends Component {
2576
+ static props = {
2577
+ emptyLabel: "Default"
2578
+ };
2579
+ #menu;
2580
+ #media;
2581
+ #controller;
2582
+ get value() {
2583
+ return this.#controller.value;
2584
+ }
2585
+ get disabled() {
2586
+ const { audioTracks } = this.#media.$state;
2587
+ return audioTracks().length <= 1;
2588
+ }
2589
+ constructor() {
2590
+ super();
2591
+ this.#controller = new RadioGroupController();
2592
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2593
+ }
2594
+ onSetup() {
2595
+ this.#media = useMediaContext();
2596
+ if (hasProvidedContext(menuContext)) {
2597
+ this.#menu = useContext(menuContext);
2598
+ }
2599
+ }
2600
+ onConnect(el) {
2601
+ effect(this.#watchValue.bind(this));
2602
+ effect(this.#watchControllerDisabled.bind(this));
2603
+ effect(this.#watchHintText.bind(this));
2604
+ }
2605
+ getOptions() {
2606
+ const { audioTracks } = this.#media.$state;
2607
+ return audioTracks().map((track) => ({
2608
+ track,
2609
+ label: track.label,
2610
+ value: track.label.toLowerCase()
2611
+ }));
2612
+ }
2613
+ #watchValue() {
2614
+ this.#controller.value = this.#getValue();
2615
+ }
2616
+ #watchHintText() {
2617
+ const { emptyLabel } = this.$props, { audioTrack } = this.#media.$state, track = audioTrack();
2618
+ this.#menu?.hint.set(track?.label ?? emptyLabel());
2619
+ }
2620
+ #watchControllerDisabled() {
2621
+ this.#menu?.disable(this.disabled);
2622
+ }
2623
+ #getValue() {
2624
+ const { audioTrack } = this.#media.$state;
2625
+ const track = audioTrack();
2626
+ return track ? track.label.toLowerCase() : "";
2627
+ }
2628
+ #onValueChange(value, trigger) {
2629
+ if (this.disabled) return;
2630
+ const index = this.#media.audioTracks.toArray().findIndex((track) => track.label.toLowerCase() === value);
2631
+ if (index >= 0) {
2632
+ const track = this.#media.audioTracks[index];
2633
+ this.#media.remote.changeAudioTrack(index, trigger);
2634
+ this.dispatch("change", { detail: track, trigger });
2635
+ }
2636
+ }
2637
+ }
2638
+ const audioradiogroup__proto = AudioRadioGroup.prototype;
2639
+ prop(audioradiogroup__proto, "value");
2640
+ prop(audioradiogroup__proto, "disabled");
2641
+ method(audioradiogroup__proto, "getOptions");
2642
+
2643
+ class CaptionsRadioGroup extends Component {
2644
+ static props = {
2645
+ offLabel: "Off"
2646
+ };
2647
+ #media;
2648
+ #menu;
2649
+ #controller;
2650
+ get value() {
2651
+ return this.#controller.value;
2652
+ }
2653
+ get disabled() {
2654
+ const { hasCaptions } = this.#media.$state;
2655
+ return !hasCaptions();
2656
+ }
2657
+ constructor() {
2658
+ super();
2659
+ this.#controller = new RadioGroupController();
2660
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2661
+ }
2662
+ onSetup() {
2663
+ this.#media = useMediaContext();
2664
+ if (hasProvidedContext(menuContext)) {
2665
+ this.#menu = useContext(menuContext);
2666
+ }
2667
+ }
2668
+ onConnect(el) {
2669
+ super.onConnect?.(el);
2670
+ effect(this.#watchValue.bind(this));
2671
+ effect(this.#watchControllerDisabled.bind(this));
2672
+ effect(this.#watchHintText.bind(this));
2673
+ }
2674
+ getOptions() {
2675
+ const { offLabel } = this.$props, { textTracks } = this.#media.$state;
2676
+ const tracks = textTracks().filter(isTrackCaptionKind);
2677
+ const priorities = ["indonesian", "english", "japanese", "korean", "chinese"];
2678
+ const getPriority = (label) => {
2679
+ const lower = label.toLowerCase();
2680
+ const pIndex = priorities.findIndex((p) => lower.includes(p));
2681
+ return pIndex !== -1 ? pIndex : 999;
2682
+ };
2683
+ const sortedTracks = [...tracks].sort((a, b) => {
2684
+ const pa = getPriority(a.label);
2685
+ const pb = getPriority(b.label);
2686
+ if (pa !== pb) return pa - pb;
2687
+ return a.label.localeCompare(b.label);
2688
+ });
2689
+ const labelCounts = /* @__PURE__ */ new Map();
2690
+ const trackOptions = sortedTracks.map((track) => {
2691
+ const count = (labelCounts.get(track.label) || 0) + 1;
2692
+ labelCounts.set(track.label, count);
2693
+ const total = sortedTracks.filter((t) => t.label === track.label).length;
2694
+ let displayLabel = track.label;
2695
+ if (total > 1) {
2696
+ displayLabel = `${track.label} ${count}`;
2697
+ }
2698
+ return {
2699
+ track,
2700
+ label: displayLabel,
2701
+ value: this.#getTrackValue(track)
2702
+ };
2703
+ });
2704
+ return [
2705
+ { value: "off", label: offLabel },
2706
+ ...trackOptions
2707
+ ];
2708
+ }
2709
+ #watchValue() {
2710
+ this.#controller.value = this.#getValue();
2711
+ }
2712
+ #watchHintText() {
2713
+ const { offLabel } = this.$props, { textTrack } = this.#media.$state, track = textTrack();
2714
+ this.#menu?.hint.set(
2715
+ track && isTrackCaptionKind(track) && track.mode === "showing" ? track.label : offLabel()
2716
+ );
2717
+ }
2718
+ #watchControllerDisabled() {
2719
+ this.#menu?.disable(this.disabled);
2720
+ }
2721
+ #getValue() {
2722
+ const { textTrack } = this.#media.$state, track = textTrack();
2723
+ return track && isTrackCaptionKind(track) && track.mode === "showing" ? this.#getTrackValue(track) : "off";
2724
+ }
2725
+ #onValueChange(value, trigger) {
2726
+ if (this.disabled) return;
2727
+ if (value === "off") {
2728
+ const track = this.#media.textTracks.selected;
2729
+ if (track) {
2730
+ const index2 = this.#media.textTracks.indexOf(track);
2731
+ this.#media.remote.changeTextTrackMode(index2, "disabled", trigger);
2732
+ this.dispatch("change", { detail: null, trigger });
2733
+ }
2734
+ return;
2735
+ }
2736
+ const index = this.#media.textTracks.toArray().findIndex((track) => this.#getTrackValue(track) === value);
2737
+ if (index >= 0) {
2738
+ const track = this.#media.textTracks[index];
2739
+ this.#media.remote.changeTextTrackMode(index, "showing", trigger);
2740
+ this.dispatch("change", { detail: track, trigger });
2741
+ }
2742
+ }
2743
+ #getTrackValue(track) {
2744
+ return track.id + ":" + track.kind + "-" + track.label.toLowerCase();
2745
+ }
2746
+ }
2747
+ const captionsradiogroup__proto = CaptionsRadioGroup.prototype;
2748
+ prop(captionsradiogroup__proto, "value");
2749
+ prop(captionsradiogroup__proto, "disabled");
2750
+ method(captionsradiogroup__proto, "getOptions");
2751
+
2752
+ const DEFAULT_PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
2753
+ class SpeedRadioGroup extends Component {
2754
+ static props = {
2755
+ normalLabel: "Normal",
2756
+ rates: DEFAULT_PLAYBACK_RATES
2757
+ };
2758
+ #media;
2759
+ #menu;
2760
+ #controller;
2761
+ get value() {
2762
+ return this.#controller.value;
2763
+ }
2764
+ get disabled() {
2765
+ const { rates } = this.$props, { canSetPlaybackRate } = this.#media.$state;
2766
+ return !canSetPlaybackRate() || rates().length === 0;
2767
+ }
2768
+ constructor() {
2769
+ super();
2770
+ this.#controller = new RadioGroupController();
2771
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2772
+ }
2773
+ onSetup() {
2774
+ this.#media = useMediaContext();
2775
+ if (hasProvidedContext(menuContext)) {
2776
+ this.#menu = useContext(menuContext);
2777
+ }
2778
+ }
2779
+ onConnect(el) {
2780
+ effect(this.#watchValue.bind(this));
2781
+ effect(this.#watchHintText.bind(this));
2782
+ effect(this.#watchControllerDisabled.bind(this));
2783
+ }
2784
+ getOptions() {
2785
+ const { rates, normalLabel } = this.$props;
2786
+ return rates().map((rate) => ({
2787
+ label: rate === 1 ? normalLabel : rate + "\xD7",
2788
+ value: rate.toString()
2789
+ }));
2790
+ }
2791
+ #watchValue() {
2792
+ this.#controller.value = this.#getValue();
2793
+ }
2794
+ #watchHintText() {
2795
+ const { normalLabel } = this.$props, { playbackRate } = this.#media.$state, rate = playbackRate();
2796
+ this.#menu?.hint.set(rate === 1 ? normalLabel() : rate + "\xD7");
2797
+ }
2798
+ #watchControllerDisabled() {
2799
+ this.#menu?.disable(this.disabled);
2800
+ }
2801
+ #getValue() {
2802
+ const { playbackRate } = this.#media.$state;
2803
+ return playbackRate().toString();
2804
+ }
2805
+ #onValueChange(value, trigger) {
2806
+ if (this.disabled) return;
2807
+ const rate = +value;
2808
+ this.#media.remote.changePlaybackRate(rate, trigger);
2809
+ this.dispatch("change", { detail: rate, trigger });
2810
+ }
2811
+ }
2812
+ const speedradiogroup__proto = SpeedRadioGroup.prototype;
2813
+ prop(speedradiogroup__proto, "value");
2814
+ prop(speedradiogroup__proto, "disabled");
2815
+ method(speedradiogroup__proto, "getOptions");
2816
+
2817
+ class QualityRadioGroup extends Component {
2818
+ static props = {
2819
+ autoLabel: "Auto",
2820
+ hideBitrate: false,
2821
+ sort: "descending"
2822
+ };
2823
+ #media;
2824
+ #menu;
2825
+ #controller;
2826
+ get value() {
2827
+ return this.#controller.value;
2828
+ }
2829
+ get disabled() {
2830
+ const { canSetQuality, qualities } = this.#media.$state;
2831
+ return !canSetQuality() || qualities().length <= 1;
2832
+ }
2833
+ #sortedQualities = computed(() => {
2834
+ const { sort } = this.$props, { qualities } = this.#media.$state;
2835
+ return sortVideoQualities(qualities(), sort() === "descending");
2836
+ });
2837
+ constructor() {
2838
+ super();
2839
+ this.#controller = new RadioGroupController();
2840
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2841
+ }
2842
+ onSetup() {
2843
+ this.#media = useMediaContext();
2844
+ if (hasProvidedContext(menuContext)) {
2845
+ this.#menu = useContext(menuContext);
2846
+ }
2847
+ }
2848
+ onConnect(el) {
2849
+ effect(this.#watchValue.bind(this));
2850
+ effect(this.#watchControllerDisabled.bind(this));
2851
+ effect(this.#watchHintText.bind(this));
2852
+ }
2853
+ getOptions() {
2854
+ const { autoLabel, hideBitrate } = this.$props;
2855
+ return [
2856
+ { value: "auto", label: autoLabel },
2857
+ ...this.#sortedQualities().map((quality) => {
2858
+ const bitrate = quality.bitrate && quality.bitrate >= 0 ? `${round(quality.bitrate / 1e6, 2)} Mbps` : null;
2859
+ return {
2860
+ quality,
2861
+ label: quality.label ?? (quality.height ? quality.height + "p" : "Unknown"),
2862
+ value: this.#getQualityId(quality),
2863
+ bitrate: () => !hideBitrate() ? bitrate : null
2864
+ };
2865
+ })
2866
+ ];
2867
+ }
2868
+ #watchValue() {
2869
+ this.#controller.value = this.#getValue();
2870
+ }
2871
+ #watchHintText() {
2872
+ const { autoLabel } = this.$props, { autoQuality, quality } = this.#media.$state, q = quality(), qualityText = q ? q.label ?? (q.height ? q.height + "p" : "") : "";
2873
+ this.#menu?.hint.set(
2874
+ !autoQuality() ? qualityText : autoLabel() + (qualityText ? ` (${qualityText})` : "")
2875
+ );
2876
+ }
2877
+ #watchControllerDisabled() {
2878
+ this.#menu?.disable(this.disabled);
2879
+ }
2880
+ #onValueChange(value, trigger) {
2881
+ if (this.disabled) return;
2882
+ if (value === "auto") {
2883
+ this.#media.remote.changeQuality(-1, trigger);
2884
+ this.dispatch("change", { detail: "auto", trigger });
2885
+ return;
2886
+ }
2887
+ const { qualities } = this.#media.$state, index = peek(qualities).findIndex((quality) => this.#getQualityId(quality) === value);
2888
+ if (index >= 0) {
2889
+ const quality = peek(qualities)[index];
2890
+ this.#media.remote.changeQuality(index, trigger);
2891
+ this.dispatch("change", { detail: quality, trigger });
2892
+ }
2893
+ }
2894
+ #getValue() {
2895
+ const { quality, autoQuality } = this.#media.$state;
2896
+ if (autoQuality()) return "auto";
2897
+ const currentQuality = quality();
2898
+ return currentQuality ? this.#getQualityId(currentQuality) : "auto";
2899
+ }
2900
+ #getQualityId(quality) {
2901
+ return quality.id;
2902
+ }
2903
+ }
2904
+ const qualityradiogroup__proto = QualityRadioGroup.prototype;
2905
+ prop(qualityradiogroup__proto, "value");
2906
+ prop(qualityradiogroup__proto, "disabled");
2907
+ method(qualityradiogroup__proto, "getOptions");
2908
+
2909
+ class Time extends Component {
2910
+ static props = {
2911
+ type: "current",
2912
+ showHours: false,
2913
+ padHours: null,
2914
+ padMinutes: null,
2915
+ remainder: false,
2916
+ toggle: false,
2917
+ hidden: false
2918
+ };
2919
+ static state = new State({
2920
+ timeText: "",
2921
+ hidden: false
2922
+ });
2923
+ #media;
2924
+ #invert = signal(null);
2925
+ #isVisible = signal(true);
2926
+ #isIntersecting = signal(true);
2927
+ onSetup() {
2928
+ this.#media = useMediaContext();
2929
+ this.#watchTime();
2930
+ const { type } = this.$props;
2931
+ this.setAttributes({
2932
+ "data-type": type,
2933
+ "data-remainder": this.#shouldInvert.bind(this)
2934
+ });
2935
+ new IntersectionObserverController({
2936
+ callback: this.#onIntersectionChange.bind(this)
2937
+ }).attach(this);
2938
+ }
2939
+ onAttach(el) {
2940
+ if (!el.hasAttribute("role")) effect(this.#watchRole.bind(this));
2941
+ effect(this.#watchTime.bind(this));
2942
+ }
2943
+ onConnect(el) {
2944
+ onDispose(observeVisibility(el, this.#isVisible.set));
2945
+ effect(this.#watchHidden.bind(this));
2946
+ effect(this.#watchToggle.bind(this));
2947
+ }
2948
+ #onIntersectionChange(entries) {
2949
+ this.#isIntersecting.set(entries[0].isIntersecting);
2950
+ }
2951
+ #watchHidden() {
2952
+ const { hidden } = this.$props;
2953
+ this.$state.hidden.set(hidden() || !this.#isVisible() || !this.#isIntersecting());
2954
+ }
2955
+ #watchToggle() {
2956
+ if (!this.$props.toggle()) {
2957
+ this.#invert.set(null);
2958
+ return;
2959
+ }
2960
+ if (this.el) {
2961
+ onPress(this.el, this.#onToggle.bind(this));
2962
+ }
2963
+ }
2964
+ #watchTime() {
2965
+ const { hidden, timeText } = this.$state, { duration } = this.#media.$state;
2966
+ if (hidden()) return;
2967
+ const { type, padHours, padMinutes, showHours } = this.$props, seconds = this.#getSeconds(type()), $duration = duration(), shouldInvert = this.#shouldInvert();
2968
+ if (!Number.isFinite(seconds + $duration)) {
2969
+ timeText.set("LIVE");
2970
+ return;
2971
+ }
2972
+ const time = shouldInvert ? Math.max(0, $duration - seconds) : seconds, formattedTime = formatTime(time, {
2973
+ padHrs: padHours(),
2974
+ padMins: padMinutes(),
2975
+ showHrs: showHours()
2976
+ });
2977
+ timeText.set((shouldInvert ? "-" : "") + formattedTime);
2978
+ }
2979
+ #watchRole() {
2980
+ if (!this.el) return;
2981
+ const { toggle } = this.$props;
2982
+ setAttribute(this.el, "role", toggle() ? "timer" : null);
2983
+ setAttribute(this.el, "tabindex", toggle() ? 0 : null);
2984
+ }
2985
+ #getSeconds(type) {
2986
+ const { bufferedEnd, duration, currentTime } = this.#media.$state;
2987
+ switch (type) {
2988
+ case "buffered":
2989
+ return bufferedEnd();
2990
+ case "duration":
2991
+ return duration();
2992
+ default:
2993
+ return currentTime();
2994
+ }
2995
+ }
2996
+ #shouldInvert() {
2997
+ return this.$props.remainder() && this.#invert() !== false;
2998
+ }
2999
+ #onToggle(event) {
3000
+ event.preventDefault();
3001
+ if (this.#invert() === null) {
3002
+ this.#invert.set(!this.$props.remainder());
3003
+ return;
3004
+ }
3005
+ this.#invert.set((v) => !v);
3006
+ }
3007
+ }
3008
+
3009
+ export { ARIAKeyShortcuts, AirPlayButton, AudioRadioGroup, CaptionButton, CaptionsRadioGroup, DEFAULT_PLAYBACK_RATES, FullscreenButton, LiveButton, Menu, MenuButton, MenuItem, MenuItems, MenuPortal, MuteButton, PIPButton, PlayButton, Popper, QualityRadioGroup, Radio, RadioGroupController, SeekButton, Slider, SliderController, SliderPreview, SliderValue, SpeedRadioGroup, Thumbnail, ThumbnailsLoader, Time, TimeSlider, ToggleButtonController, VolumeSlider, formatSpokenTime, formatTime, menuContext, menuPortalContext, sliderContext, sliderState, sliderValueFormatContext, updateSliderPreviewPlacement };