@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,2999 @@
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, isKeyboardEvent, tick, setStyle, prop, scoped } from './vidstack-BNpgCJJ1.js';
2
+ import { useMediaContext } from './vidstack-tt3O1zL6.js';
3
+ import { hasAnimation, setAttributeIfEmpty, onPress, $ariaBool, setARIALabel, isTouchPinchEvent, observeVisibility, isHTMLElement, isElementParent, isEventInside, isElementVisible, requestScopedAnimationFrame, autoPlacement } from './vidstack-DB9WDRL5.js';
4
+ import { isTrackCaptionKind, watchActiveTextTrack } from './vidstack-sP7TQMB1.js';
5
+ import { FocusVisibleController } from './vidstack-COLU-zPZ.js';
6
+ import { clampNumber, round, getNumberOfDecimalPlaces } from './vidstack-Dihypf8P.js';
7
+ import { assert } from './vidstack-C9vIqaYT.js';
8
+ import { getRequestCredentials } from './vidstack-KShKSmYu.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();
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), false);
1023
+ assert(
1024
+ "url" in image && isString(image.url),
1025
+ false
1026
+ );
1027
+ assert(
1028
+ "startTime" in image && isNumber(image.startTime),
1029
+ false
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
+ assert(
1086
+ "startTime" in img && isNumber(img.startTime));
1087
+ return {
1088
+ ...img,
1089
+ url: isString(img.url) ? this.#resolveURL(img.url, baseURL) : img.url
1090
+ };
1091
+ });
1092
+ }
1093
+ #processStoryboard(board) {
1094
+ assert(isString(board.url));
1095
+ assert(isArray(board.tiles) && board.tiles?.length);
1096
+ const url = new URL(board.url), images = [];
1097
+ const tileWidth = "tile_width" in board ? board.tile_width : board.tileWidth, tileHeight = "tile_height" in board ? board.tile_height : board.tileHeight;
1098
+ for (const tile of board.tiles) {
1099
+ images.push({
1100
+ url,
1101
+ startTime: "start" in tile ? tile.start : tile.startTime,
1102
+ width: tileWidth,
1103
+ height: tileHeight,
1104
+ coords: { x: tile.x, y: tile.y }
1105
+ });
1106
+ }
1107
+ return images;
1108
+ }
1109
+ #processVTTCues(cues) {
1110
+ for (let i = 0; i < cues.length; i++) {
1111
+ const cue = cues[i];
1112
+ assert(
1113
+ "startTime" in cue && isNumber(cue.startTime));
1114
+ assert(
1115
+ "text" in cue && isString(cue.text));
1116
+ }
1117
+ const images = [], baseURL = this.#resolveBaseUrl();
1118
+ for (const cue of cues) {
1119
+ const [url, hash] = cue.text.split("#"), data = this.#resolveData(hash);
1120
+ images.push({
1121
+ url: this.#resolveURL(url, baseURL),
1122
+ startTime: cue.startTime,
1123
+ endTime: cue.endTime,
1124
+ width: data?.w,
1125
+ height: data?.h,
1126
+ coords: data && isNumber(data.x) && isNumber(data.y) ? { x: data.x, y: data.y } : void 0
1127
+ });
1128
+ }
1129
+ return images;
1130
+ }
1131
+ #resolveBaseUrl() {
1132
+ let baseURL = peek(this.#src);
1133
+ if (!isString(baseURL) || !/^https?:/.test(baseURL)) {
1134
+ return location.href;
1135
+ }
1136
+ return baseURL;
1137
+ }
1138
+ #resolveURL(src, baseURL) {
1139
+ return /^https?:/.test(src) ? new URL(src) : new URL(src, baseURL);
1140
+ }
1141
+ #resolveData(hash) {
1142
+ if (!hash) return {};
1143
+ const [hashProps, values] = hash.split("="), hashValues = values?.split(","), data = {};
1144
+ if (!hashProps || !hashValues) {
1145
+ return null;
1146
+ }
1147
+ for (let i = 0; i < hashProps.length; i++) {
1148
+ const value = +hashValues[i];
1149
+ if (!isNaN(value)) data[hashProps[i]] = value;
1150
+ }
1151
+ return data;
1152
+ }
1153
+ #onError(src, error) {
1154
+ return;
1155
+ }
1156
+ }
1157
+
1158
+ class Thumbnail extends Component {
1159
+ static props = {
1160
+ src: null,
1161
+ time: 0,
1162
+ crossOrigin: null
1163
+ };
1164
+ static state = new State({
1165
+ src: "",
1166
+ img: null,
1167
+ thumbnails: [],
1168
+ activeThumbnail: null,
1169
+ crossOrigin: null,
1170
+ loading: false,
1171
+ error: null,
1172
+ hidden: false
1173
+ });
1174
+ media;
1175
+ #loader;
1176
+ #styleResets = [];
1177
+ onSetup() {
1178
+ this.media = useMediaContext();
1179
+ this.#loader = ThumbnailsLoader.create(this.$props.src, this.$state.crossOrigin);
1180
+ this.#watchCrossOrigin();
1181
+ this.setAttributes({
1182
+ "data-loading": this.#isLoading.bind(this),
1183
+ "data-error": this.#hasError.bind(this),
1184
+ "data-hidden": this.$state.hidden,
1185
+ "aria-hidden": $ariaBool(this.$state.hidden)
1186
+ });
1187
+ }
1188
+ onConnect(el) {
1189
+ effect(this.#watchImg.bind(this));
1190
+ effect(this.#watchHidden.bind(this));
1191
+ effect(this.#watchCrossOrigin.bind(this));
1192
+ effect(this.#onLoadStart.bind(this));
1193
+ effect(this.#onFindActiveThumbnail.bind(this));
1194
+ effect(this.#resize.bind(this));
1195
+ }
1196
+ #watchImg() {
1197
+ const img = this.$state.img();
1198
+ if (!img) return;
1199
+ new EventsController(img).add("load", this.#onLoaded.bind(this)).add("error", this.#onError.bind(this));
1200
+ }
1201
+ #watchCrossOrigin() {
1202
+ const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin } = this.media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
1203
+ crossOriginState.set(crossOrigin === true ? "anonymous" : crossOrigin);
1204
+ }
1205
+ #onLoadStart() {
1206
+ const { src, loading, error } = this.$state;
1207
+ if (src()) {
1208
+ loading.set(true);
1209
+ error.set(null);
1210
+ }
1211
+ return () => {
1212
+ this.#resetStyles();
1213
+ loading.set(false);
1214
+ error.set(null);
1215
+ };
1216
+ }
1217
+ #onLoaded() {
1218
+ const { loading, error } = this.$state;
1219
+ this.#resize();
1220
+ loading.set(false);
1221
+ error.set(null);
1222
+ }
1223
+ #onError(event) {
1224
+ const { loading, error } = this.$state;
1225
+ loading.set(false);
1226
+ error.set(event);
1227
+ }
1228
+ #isLoading() {
1229
+ const { loading, hidden } = this.$state;
1230
+ return !hidden() && loading();
1231
+ }
1232
+ #hasError() {
1233
+ const { error } = this.$state;
1234
+ return !isNull(error());
1235
+ }
1236
+ #watchHidden() {
1237
+ const { hidden } = this.$state, { duration } = this.media.$state, images = this.#loader.$images();
1238
+ hidden.set(this.#hasError() || !Number.isFinite(duration()) || images.length === 0);
1239
+ }
1240
+ getTime() {
1241
+ return this.$props.time();
1242
+ }
1243
+ #onFindActiveThumbnail() {
1244
+ let images = this.#loader.$images();
1245
+ if (!images.length) return;
1246
+ let time = this.getTime(), { src, activeThumbnail } = this.$state, activeIndex = -1, activeImage = null;
1247
+ for (let i = images.length - 1; i >= 0; i--) {
1248
+ const image = images[i];
1249
+ if (time >= image.startTime && (!image.endTime || time < image.endTime)) {
1250
+ activeIndex = i;
1251
+ break;
1252
+ }
1253
+ }
1254
+ if (images[activeIndex]) {
1255
+ activeImage = images[activeIndex];
1256
+ }
1257
+ activeThumbnail.set(activeImage);
1258
+ src.set(activeImage?.url.href || "");
1259
+ }
1260
+ #resize() {
1261
+ if (!this.scope || this.$state.hidden()) return;
1262
+ const rootEl = this.el, imgEl = this.$state.img(), thumbnail = this.$state.activeThumbnail();
1263
+ if (!imgEl || !thumbnail || !rootEl) return;
1264
+ let width = thumbnail.width ?? imgEl.naturalWidth, height = thumbnail?.height ?? imgEl.naturalHeight, {
1265
+ maxWidth,
1266
+ maxHeight,
1267
+ minWidth,
1268
+ minHeight,
1269
+ width: elWidth,
1270
+ height: elHeight
1271
+ } = getComputedStyle(this.el);
1272
+ if (minWidth === "100%") minWidth = parseFloat(elWidth) + "";
1273
+ if (minHeight === "100%") minHeight = parseFloat(elHeight) + "";
1274
+ let minRatio = Math.max(parseInt(minWidth) / width, parseInt(minHeight) / height), maxRatio = Math.min(
1275
+ Math.max(parseInt(minWidth), parseInt(maxWidth)) / width,
1276
+ Math.max(parseInt(minHeight), parseInt(maxHeight)) / height
1277
+ ), scale = !isNaN(maxRatio) && maxRatio < 1 ? maxRatio : minRatio > 1 ? minRatio : 1;
1278
+ this.#style(rootEl, "--thumbnail-width", `${width * scale}px`);
1279
+ this.#style(rootEl, "--thumbnail-height", `${height * scale}px`);
1280
+ this.#style(rootEl, "--thumbnail-aspect-ratio", String(round(width / height, 5)));
1281
+ this.#style(imgEl, "width", `${imgEl.naturalWidth * scale}px`);
1282
+ this.#style(imgEl, "height", `${imgEl.naturalHeight * scale}px`);
1283
+ this.#style(
1284
+ imgEl,
1285
+ "transform",
1286
+ thumbnail.coords ? `translate(-${thumbnail.coords.x * scale}px, -${thumbnail.coords.y * scale}px)` : ""
1287
+ );
1288
+ this.#style(imgEl, "max-width", "none");
1289
+ }
1290
+ #style(el, name, value) {
1291
+ el.style.setProperty(name, value);
1292
+ this.#styleResets.push(() => el.style.removeProperty(name));
1293
+ }
1294
+ #resetStyles() {
1295
+ for (const reset of this.#styleResets) reset();
1296
+ this.#styleResets = [];
1297
+ }
1298
+ }
1299
+
1300
+ class SliderValue extends Component {
1301
+ static props = {
1302
+ type: "pointer",
1303
+ format: null,
1304
+ showHours: false,
1305
+ showMs: false,
1306
+ padHours: null,
1307
+ padMinutes: null,
1308
+ decimalPlaces: 2
1309
+ };
1310
+ #format;
1311
+ #text;
1312
+ #slider;
1313
+ onSetup() {
1314
+ this.#slider = useState(Slider.state);
1315
+ this.#format = useContext(sliderValueFormatContext);
1316
+ this.#text = computed(this.getValueText.bind(this));
1317
+ }
1318
+ /**
1319
+ * Returns the current value formatted as text based on prop settings.
1320
+ */
1321
+ getValueText() {
1322
+ const {
1323
+ type,
1324
+ format: $format,
1325
+ decimalPlaces,
1326
+ padHours,
1327
+ padMinutes,
1328
+ showHours,
1329
+ showMs
1330
+ } = this.$props, { value: sliderValue, pointerValue, min, max } = this.#slider, format = $format?.() ?? this.#format.default;
1331
+ const value = type() === "current" ? sliderValue() : pointerValue();
1332
+ if (format === "percent") {
1333
+ const range = max() - min();
1334
+ const percent = value / range * 100;
1335
+ return (this.#format.percent ?? round)(percent, decimalPlaces()) + "%";
1336
+ } else if (format === "time") {
1337
+ return (this.#format.time ?? formatTime)(value, {
1338
+ padHrs: padHours(),
1339
+ padMins: padMinutes(),
1340
+ showHrs: showHours(),
1341
+ showMs: showMs()
1342
+ });
1343
+ } else {
1344
+ return (this.#format.value?.(value) ?? value.toFixed(2)) + "";
1345
+ }
1346
+ }
1347
+ }
1348
+ const slidervalue__proto = SliderValue.prototype;
1349
+ method(slidervalue__proto, "getValueText");
1350
+
1351
+ class SliderPreview extends Component {
1352
+ static props = {
1353
+ offset: 0,
1354
+ noClamp: false
1355
+ };
1356
+ #slider;
1357
+ onSetup() {
1358
+ this.#slider = useContext(sliderContext);
1359
+ const { active } = useState(Slider.state);
1360
+ this.setAttributes({
1361
+ "data-visible": active
1362
+ });
1363
+ }
1364
+ onAttach(el) {
1365
+ Object.assign(el.style, {
1366
+ position: "absolute",
1367
+ top: 0,
1368
+ left: 0,
1369
+ width: "max-content"
1370
+ });
1371
+ }
1372
+ onConnect(el) {
1373
+ const { preview } = this.#slider;
1374
+ preview.set(el);
1375
+ onDispose(() => preview.set(null));
1376
+ effect(this.#updatePlacement.bind(this));
1377
+ const resize = new ResizeObserver(this.#updatePlacement.bind(this));
1378
+ resize.observe(el);
1379
+ onDispose(() => resize.disconnect());
1380
+ }
1381
+ #updatePlacement = animationFrameThrottle(() => {
1382
+ const { disabled, orientation } = this.#slider;
1383
+ if (disabled()) return;
1384
+ const el = this.el, { offset, noClamp } = this.$props;
1385
+ if (!el) return;
1386
+ updateSliderPreviewPlacement(el, {
1387
+ clamp: !noClamp(),
1388
+ offset: offset(),
1389
+ orientation: orientation()
1390
+ });
1391
+ });
1392
+ }
1393
+ function updateSliderPreviewPlacement(el, {
1394
+ clamp,
1395
+ offset,
1396
+ orientation
1397
+ }) {
1398
+ const computedStyle = getComputedStyle(el), width = parseFloat(computedStyle.width), height = parseFloat(computedStyle.height), styles = {
1399
+ top: null,
1400
+ right: null,
1401
+ bottom: null,
1402
+ left: null
1403
+ };
1404
+ styles[orientation === "horizontal" ? "bottom" : "left"] = `calc(100% + var(--media-slider-preview-offset, ${offset}px))`;
1405
+ if (orientation === "horizontal") {
1406
+ const widthHalf = width / 2;
1407
+ if (!clamp) {
1408
+ styles.left = `calc(var(--slider-pointer) - ${widthHalf}px)`;
1409
+ } else {
1410
+ const leftClamp = `max(0px, calc(var(--slider-pointer) - ${widthHalf}px))`, rightClamp = `calc(100% - ${width}px)`;
1411
+ styles.left = `min(${leftClamp}, ${rightClamp})`;
1412
+ }
1413
+ } else {
1414
+ const heightHalf = height / 2;
1415
+ if (!clamp) {
1416
+ styles.bottom = `calc(var(--slider-pointer) - ${heightHalf}px)`;
1417
+ } else {
1418
+ const topClamp = `max(${heightHalf}px, calc(var(--slider-pointer) - ${heightHalf}px))`, bottomClamp = `calc(100% - ${height}px)`;
1419
+ styles.bottom = `min(${topClamp}, ${bottomClamp})`;
1420
+ }
1421
+ }
1422
+ Object.assign(el.style, styles);
1423
+ }
1424
+
1425
+ class VolumeSlider extends Component {
1426
+ static props = {
1427
+ ...SliderController.props,
1428
+ keyStep: 5,
1429
+ shiftKeyMultiplier: 2
1430
+ };
1431
+ static state = sliderState;
1432
+ #media;
1433
+ onSetup() {
1434
+ this.#media = useMediaContext();
1435
+ const { audioGain } = this.#media.$state;
1436
+ provideContext(sliderValueFormatContext, {
1437
+ default: "percent",
1438
+ value(value) {
1439
+ return (value * (audioGain() ?? 1)).toFixed(2);
1440
+ },
1441
+ percent(value) {
1442
+ return Math.round(value * (audioGain() ?? 1));
1443
+ }
1444
+ });
1445
+ new SliderController({
1446
+ getStep: this.$props.step,
1447
+ getKeyStep: this.$props.keyStep,
1448
+ roundValue: Math.round,
1449
+ isDisabled: this.#isDisabled.bind(this),
1450
+ aria: {
1451
+ valueMax: this.#getARIAValueMax.bind(this),
1452
+ valueNow: this.#getARIAValueNow.bind(this),
1453
+ valueText: this.#getARIAValueText.bind(this)
1454
+ },
1455
+ onDragValueChange: this.#onDragValueChange.bind(this),
1456
+ onValueChange: this.#onValueChange.bind(this)
1457
+ }).attach(this);
1458
+ effect(this.#watchVolume.bind(this));
1459
+ }
1460
+ onAttach(el) {
1461
+ el.setAttribute("data-media-volume-slider", "");
1462
+ setAttributeIfEmpty(el, "aria-label", "Volume");
1463
+ const { canSetVolume } = this.#media.$state;
1464
+ this.setAttributes({
1465
+ "data-supported": canSetVolume,
1466
+ "aria-hidden": $ariaBool(() => !canSetVolume())
1467
+ });
1468
+ }
1469
+ #getARIAValueNow() {
1470
+ const { value } = this.$state, { audioGain } = this.#media.$state;
1471
+ return Math.round(value() * (audioGain() ?? 1));
1472
+ }
1473
+ #getARIAValueText() {
1474
+ const { value, max } = this.$state, { audioGain } = this.#media.$state;
1475
+ return round(value() / max() * (audioGain() ?? 1) * 100, 2) + "%";
1476
+ }
1477
+ #getARIAValueMax() {
1478
+ const { audioGain } = this.#media.$state;
1479
+ return this.$state.max() * (audioGain() ?? 1);
1480
+ }
1481
+ #isDisabled() {
1482
+ const { disabled } = this.$props, { canSetVolume } = this.#media.$state;
1483
+ return disabled() || !canSetVolume();
1484
+ }
1485
+ #watchVolume() {
1486
+ const { muted, volume } = this.#media.$state;
1487
+ const newValue = muted() ? 0 : volume() * 100;
1488
+ this.$state.value.set(newValue);
1489
+ this.dispatch("value-change", { detail: newValue });
1490
+ }
1491
+ #throttleVolumeChange = functionThrottle(this.#onVolumeChange.bind(this), 25);
1492
+ #onVolumeChange(event) {
1493
+ if (!event.trigger) return;
1494
+ const mediaVolume = round(event.detail / 100, 3);
1495
+ this.#media.remote.changeVolume(mediaVolume, event);
1496
+ }
1497
+ #onValueChange(event) {
1498
+ this.#throttleVolumeChange(event);
1499
+ }
1500
+ #onDragValueChange(event) {
1501
+ this.#throttleVolumeChange(event);
1502
+ }
1503
+ }
1504
+
1505
+ class TimeSlider extends Component {
1506
+ static props = {
1507
+ ...SliderController.props,
1508
+ step: 0.1,
1509
+ keyStep: 5,
1510
+ shiftKeyMultiplier: 2,
1511
+ pauseWhileDragging: false,
1512
+ noSwipeGesture: false,
1513
+ seekingRequestThrottle: 100
1514
+ };
1515
+ static state = sliderState;
1516
+ #media;
1517
+ #dispatchSeeking;
1518
+ #chapter = signal(null);
1519
+ constructor() {
1520
+ super();
1521
+ const { noSwipeGesture } = this.$props;
1522
+ new SliderController({
1523
+ swipeGesture: () => !noSwipeGesture(),
1524
+ getValue: this.#getValue.bind(this),
1525
+ getStep: this.#getStep.bind(this),
1526
+ getKeyStep: this.#getKeyStep.bind(this),
1527
+ roundValue: this.#roundValue,
1528
+ isDisabled: this.#isDisabled.bind(this),
1529
+ aria: {
1530
+ valueNow: this.#getARIAValueNow.bind(this),
1531
+ valueText: this.#getARIAValueText.bind(this)
1532
+ },
1533
+ onDragStart: this.#onDragStart.bind(this),
1534
+ onDragValueChange: this.#onDragValueChange.bind(this),
1535
+ onDragEnd: this.#onDragEnd.bind(this),
1536
+ onValueChange: this.#onValueChange.bind(this)
1537
+ });
1538
+ }
1539
+ onSetup() {
1540
+ this.#media = useMediaContext();
1541
+ provideContext(sliderValueFormatContext, {
1542
+ default: "time",
1543
+ value: this.#formatValue.bind(this),
1544
+ time: this.#formatTime.bind(this)
1545
+ });
1546
+ this.setAttributes({
1547
+ "data-chapters": this.#hasChapters.bind(this)
1548
+ });
1549
+ this.setStyles({
1550
+ "--slider-progress": this.#calcBufferedPercent.bind(this)
1551
+ });
1552
+ effect(this.#watchCurrentTime.bind(this));
1553
+ effect(this.#watchSeekingThrottle.bind(this));
1554
+ }
1555
+ onAttach(el) {
1556
+ el.setAttribute("data-media-time-slider", "");
1557
+ setAttributeIfEmpty(el, "aria-label", "Seek");
1558
+ }
1559
+ onConnect(el) {
1560
+ effect(this.#watchPreviewing.bind(this));
1561
+ watchActiveTextTrack(this.#media.textTracks, "chapters", this.#chapter.set);
1562
+ }
1563
+ #calcBufferedPercent() {
1564
+ const { bufferedEnd, duration } = this.#media.$state;
1565
+ return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1) * 100, 3) + "%";
1566
+ }
1567
+ #hasChapters() {
1568
+ const { duration } = this.#media.$state;
1569
+ return this.#chapter()?.cues.length && Number.isFinite(duration()) && duration() > 0;
1570
+ }
1571
+ #watchSeekingThrottle() {
1572
+ this.#dispatchSeeking = functionThrottle(
1573
+ this.#seeking.bind(this),
1574
+ this.$props.seekingRequestThrottle()
1575
+ );
1576
+ }
1577
+ #watchCurrentTime() {
1578
+ if (this.$state.hidden()) return;
1579
+ const { value, dragging } = this.$state, newValue = this.#getValue();
1580
+ if (!peek(dragging)) {
1581
+ value.set(newValue);
1582
+ this.dispatch("value-change", { detail: newValue });
1583
+ }
1584
+ }
1585
+ #watchPreviewing() {
1586
+ const player = this.#media.player.el, { preview } = useContext(sliderContext);
1587
+ player && preview() && setAttribute(player, "data-preview", this.$state.active());
1588
+ }
1589
+ #seeking(time, event) {
1590
+ this.#media.remote.seeking(time, event);
1591
+ }
1592
+ #seek(time, percent, event) {
1593
+ this.#dispatchSeeking.cancel();
1594
+ const { live } = this.#media.$state;
1595
+ if (live() && percent >= 99) {
1596
+ this.#media.remote.seekToLiveEdge(event);
1597
+ return;
1598
+ }
1599
+ this.#media.remote.seek(time, event);
1600
+ }
1601
+ #playingBeforeDragStart = false;
1602
+ #onDragStart(event) {
1603
+ const { pauseWhileDragging } = this.$props;
1604
+ if (pauseWhileDragging()) {
1605
+ const { paused } = this.#media.$state;
1606
+ this.#playingBeforeDragStart = !paused();
1607
+ this.#media.remote.pause(event);
1608
+ }
1609
+ }
1610
+ #onDragValueChange(event) {
1611
+ this.#dispatchSeeking(this.#percentToTime(event.detail), event);
1612
+ }
1613
+ #onDragEnd(event) {
1614
+ const { seeking } = this.#media.$state;
1615
+ if (!peek(seeking)) this.#seeking(this.#percentToTime(event.detail), event);
1616
+ const percent = event.detail;
1617
+ this.#seek(this.#percentToTime(percent), percent, event);
1618
+ const { pauseWhileDragging } = this.$props;
1619
+ if (pauseWhileDragging() && this.#playingBeforeDragStart) {
1620
+ this.#media.remote.play(event);
1621
+ this.#playingBeforeDragStart = false;
1622
+ }
1623
+ }
1624
+ #onValueChange(event) {
1625
+ const { dragging } = this.$state;
1626
+ if (dragging() || !event.trigger) return;
1627
+ this.#onDragEnd(event);
1628
+ }
1629
+ // -------------------------------------------------------------------------------------------
1630
+ // Props
1631
+ // -------------------------------------------------------------------------------------------
1632
+ #getValue() {
1633
+ const { currentTime } = this.#media.$state;
1634
+ return this.#timeToPercent(currentTime());
1635
+ }
1636
+ #getStep() {
1637
+ const value = this.$props.step() / this.#media.$state.duration() * 100;
1638
+ return Number.isFinite(value) ? value : 1;
1639
+ }
1640
+ #getKeyStep() {
1641
+ const value = this.$props.keyStep() / this.#media.$state.duration() * 100;
1642
+ return Number.isFinite(value) ? value : 1;
1643
+ }
1644
+ #roundValue(value) {
1645
+ return round(value, 3);
1646
+ }
1647
+ #isDisabled() {
1648
+ const { disabled } = this.$props, { canSeek } = this.#media.$state;
1649
+ return disabled() || !canSeek();
1650
+ }
1651
+ // -------------------------------------------------------------------------------------------
1652
+ // ARIA
1653
+ // -------------------------------------------------------------------------------------------
1654
+ #getARIAValueNow() {
1655
+ const { value } = this.$state;
1656
+ return Math.round(value());
1657
+ }
1658
+ #getARIAValueText() {
1659
+ const time = this.#percentToTime(this.$state.value()), { duration } = this.#media.$state;
1660
+ return Number.isFinite(time) ? `${formatSpokenTime(time)} out of ${formatSpokenTime(duration())}` : "live";
1661
+ }
1662
+ // -------------------------------------------------------------------------------------------
1663
+ // Format
1664
+ // -------------------------------------------------------------------------------------------
1665
+ #percentToTime(percent) {
1666
+ const { duration } = this.#media.$state;
1667
+ return round(percent / 100 * duration(), 5);
1668
+ }
1669
+ #timeToPercent(time) {
1670
+ const { liveEdge, duration } = this.#media.$state, rate = Math.max(0, Math.min(1, liveEdge() ? 1 : Math.min(time, duration()) / duration()));
1671
+ return Number.isNaN(rate) ? 0 : Number.isFinite(rate) ? rate * 100 : 100;
1672
+ }
1673
+ #formatValue(percent) {
1674
+ const time = this.#percentToTime(percent), { live, duration } = this.#media.$state;
1675
+ return Number.isFinite(time) ? (live() ? time - duration() : time).toFixed(0) : "LIVE";
1676
+ }
1677
+ #formatTime(percent, options) {
1678
+ const time = this.#percentToTime(percent), { live, duration } = this.#media.$state, value = live() ? time - duration() : time;
1679
+ return Number.isFinite(time) ? `${value < 0 ? "-" : ""}${formatTime(Math.abs(value), options)}` : "LIVE";
1680
+ }
1681
+ }
1682
+
1683
+ const menuContext = createContext();
1684
+
1685
+ function scrollIntoView(el, options) {
1686
+ const scrolls = r(el, options);
1687
+ for (const { el: el2, top, left } of scrolls) {
1688
+ el2.scroll({ top, left, behavior: options.behavior });
1689
+ }
1690
+ }
1691
+ function scrollIntoCenter(el, options = {}) {
1692
+ scrollIntoView(el, {
1693
+ scrollMode: "if-needed",
1694
+ block: "center",
1695
+ inline: "center",
1696
+ ...options
1697
+ });
1698
+ }
1699
+
1700
+ const FOCUSABLE_ELEMENTS_SELECTOR = /* @__PURE__ */ [
1701
+ "a[href]",
1702
+ "[tabindex]",
1703
+ "input",
1704
+ "select",
1705
+ "button"
1706
+ ].map((selector) => `${selector}:not([aria-hidden='true'])`).join(",");
1707
+ const VALID_KEYS = /* @__PURE__ */ new Set([
1708
+ "Escape",
1709
+ "Tab",
1710
+ "ArrowUp",
1711
+ "ArrowDown",
1712
+ "Home",
1713
+ "PageUp",
1714
+ "End",
1715
+ "PageDown",
1716
+ "Enter",
1717
+ " "
1718
+ ]);
1719
+ class MenuFocusController {
1720
+ #index = -1;
1721
+ #el = null;
1722
+ #elements = [];
1723
+ #delegate;
1724
+ get items() {
1725
+ return this.#elements;
1726
+ }
1727
+ constructor(delegate) {
1728
+ this.#delegate = delegate;
1729
+ }
1730
+ attachMenu(el) {
1731
+ listenEvent(el, "focus", this.#onFocus.bind(this));
1732
+ this.#el = el;
1733
+ onDispose(() => {
1734
+ this.#el = null;
1735
+ });
1736
+ }
1737
+ listen() {
1738
+ if (!this.#el) return;
1739
+ this.update();
1740
+ new EventsController(this.#el).add("keyup", this.#onKeyUp.bind(this)).add("keydown", this.#onKeyDown.bind(this));
1741
+ onDispose(() => {
1742
+ this.#index = -1;
1743
+ this.#elements = [];
1744
+ });
1745
+ }
1746
+ update() {
1747
+ this.#index = 0;
1748
+ this.#elements = this.#getFocusableElements();
1749
+ }
1750
+ scroll(index = this.#findActiveIndex()) {
1751
+ const element = this.#elements[index];
1752
+ if (element) {
1753
+ requestAnimationFrame(() => {
1754
+ requestAnimationFrame(() => {
1755
+ scrollIntoCenter(element, {
1756
+ behavior: "smooth",
1757
+ boundary: (el) => {
1758
+ return !el.hasAttribute("data-root");
1759
+ }
1760
+ });
1761
+ });
1762
+ });
1763
+ }
1764
+ }
1765
+ focusActive(scroll = true) {
1766
+ const index = this.#findActiveIndex();
1767
+ this.#focusAt(index >= 0 ? index : 0, scroll);
1768
+ }
1769
+ #focusAt(index, scroll = true) {
1770
+ this.#index = index;
1771
+ if (this.#elements[index]) {
1772
+ this.#elements[index].focus({ preventScroll: true });
1773
+ if (scroll) this.scroll(index);
1774
+ } else {
1775
+ this.#el?.focus({ preventScroll: true });
1776
+ }
1777
+ }
1778
+ #findActiveIndex() {
1779
+ return this.#elements.findIndex(
1780
+ (el) => document.activeElement === el || el.getAttribute("role") === "menuitemradio" && el.getAttribute("aria-checked") === "true"
1781
+ );
1782
+ }
1783
+ #onFocus() {
1784
+ if (this.#index >= 0) return;
1785
+ this.update();
1786
+ this.focusActive();
1787
+ }
1788
+ #validateKeyEvent(event) {
1789
+ const el = event.target;
1790
+ if (wasEnterKeyPressed(event) && el instanceof Element) {
1791
+ const role = el.getAttribute("role");
1792
+ return !/a|input|select|button/.test(el.localName) && !role;
1793
+ }
1794
+ return VALID_KEYS.has(event.key);
1795
+ }
1796
+ #onKeyUp(event) {
1797
+ if (!this.#validateKeyEvent(event)) return;
1798
+ event.stopPropagation();
1799
+ event.preventDefault();
1800
+ }
1801
+ #onKeyDown(event) {
1802
+ if (!this.#validateKeyEvent(event)) return;
1803
+ event.stopPropagation();
1804
+ event.preventDefault();
1805
+ switch (event.key) {
1806
+ case "Escape":
1807
+ this.#delegate.closeMenu(event);
1808
+ break;
1809
+ case "Tab":
1810
+ this.#focusAt(this.#nextIndex(event.shiftKey ? -1 : 1));
1811
+ break;
1812
+ case "ArrowUp":
1813
+ this.#focusAt(this.#nextIndex(-1));
1814
+ break;
1815
+ case "ArrowDown":
1816
+ this.#focusAt(this.#nextIndex(1));
1817
+ break;
1818
+ case "Home":
1819
+ case "PageUp":
1820
+ this.#focusAt(0);
1821
+ break;
1822
+ case "End":
1823
+ case "PageDown":
1824
+ this.#focusAt(this.#elements.length - 1);
1825
+ break;
1826
+ }
1827
+ }
1828
+ #nextIndex(delta) {
1829
+ let index = this.#index;
1830
+ do {
1831
+ index = (index + delta + this.#elements.length) % this.#elements.length;
1832
+ } while (this.#elements[index]?.offsetParent === null);
1833
+ return index;
1834
+ }
1835
+ #getFocusableElements() {
1836
+ if (!this.#el) return [];
1837
+ const focusableElements = this.#el.querySelectorAll(FOCUSABLE_ELEMENTS_SELECTOR), elements = [];
1838
+ const is = (node) => {
1839
+ return node.getAttribute("role") === "menu";
1840
+ };
1841
+ for (const el of focusableElements) {
1842
+ if (isHTMLElement(el) && el.offsetParent !== null && // does not have display: none
1843
+ isElementParent(this.#el, el, is)) {
1844
+ elements.push(el);
1845
+ }
1846
+ }
1847
+ return elements;
1848
+ }
1849
+ }
1850
+
1851
+ var __defProp = Object.defineProperty;
1852
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1853
+ var __decorateClass = (decorators, target, key, kind) => {
1854
+ var result = __getOwnPropDesc(target, key) ;
1855
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1856
+ if (decorator = decorators[i])
1857
+ result = (decorator(target, key, result) ) || result;
1858
+ if (result) __defProp(target, key, result);
1859
+ return result;
1860
+ };
1861
+ let idCount = 0;
1862
+ class Menu extends Component {
1863
+ static props = {
1864
+ showDelay: 0
1865
+ };
1866
+ #media;
1867
+ #menuId;
1868
+ #menuButtonId;
1869
+ #expanded = signal(false);
1870
+ #disabled = signal(false);
1871
+ #trigger = signal(null);
1872
+ #content = signal(null);
1873
+ #parentMenu;
1874
+ #submenus = /* @__PURE__ */ new Set();
1875
+ #menuObserver = null;
1876
+ #popper;
1877
+ #focus;
1878
+ #isSliderActive = false;
1879
+ #isTriggerDisabled = signal(false);
1880
+ #transitionCallbacks = /* @__PURE__ */ new Set();
1881
+ get triggerElement() {
1882
+ return this.#trigger();
1883
+ }
1884
+ get contentElement() {
1885
+ return this.#content();
1886
+ }
1887
+ get isSubmenu() {
1888
+ return !!this.#parentMenu;
1889
+ }
1890
+ constructor() {
1891
+ super();
1892
+ const { showDelay } = this.$props;
1893
+ this.#popper = new Popper({
1894
+ trigger: this.#trigger,
1895
+ content: this.#content,
1896
+ showDelay,
1897
+ listen: (trigger, show, hide) => {
1898
+ onPress(trigger, (event) => {
1899
+ if (this.#expanded()) hide(event);
1900
+ else show(event);
1901
+ });
1902
+ const closeTarget = this.#getCloseTarget();
1903
+ if (closeTarget) {
1904
+ onPress(closeTarget, (event) => {
1905
+ event.stopPropagation();
1906
+ hide(event);
1907
+ });
1908
+ }
1909
+ },
1910
+ onChange: this.#onExpandedChange.bind(this)
1911
+ });
1912
+ }
1913
+ onSetup() {
1914
+ this.#media = useMediaContext();
1915
+ const currentIdCount = ++idCount;
1916
+ this.#menuId = `media-menu-${currentIdCount}`;
1917
+ this.#menuButtonId = `media-menu-button-${currentIdCount}`;
1918
+ this.#focus = new MenuFocusController({
1919
+ closeMenu: this.close.bind(this)
1920
+ });
1921
+ if (hasProvidedContext(menuContext)) {
1922
+ this.#parentMenu = useContext(menuContext);
1923
+ }
1924
+ this.#observeSliders();
1925
+ this.setAttributes({
1926
+ "data-open": this.#expanded,
1927
+ "data-root": !this.isSubmenu,
1928
+ "data-submenu": this.isSubmenu,
1929
+ "data-disabled": this.#isDisabled.bind(this)
1930
+ });
1931
+ provideContext(menuContext, {
1932
+ button: this.#trigger,
1933
+ content: this.#content,
1934
+ expanded: this.#expanded,
1935
+ hint: signal(""),
1936
+ submenu: !!this.#parentMenu,
1937
+ disable: this.#disable.bind(this),
1938
+ attachMenuButton: this.#attachMenuButton.bind(this),
1939
+ attachMenuItems: this.#attachMenuItems.bind(this),
1940
+ attachObserver: this.#attachObserver.bind(this),
1941
+ disableMenuButton: this.#disableMenuButton.bind(this),
1942
+ addSubmenu: this.#addSubmenu.bind(this),
1943
+ onTransitionEvent: (callback) => {
1944
+ this.#transitionCallbacks.add(callback);
1945
+ onDispose(() => {
1946
+ this.#transitionCallbacks.delete(callback);
1947
+ });
1948
+ }
1949
+ });
1950
+ }
1951
+ onAttach(el) {
1952
+ el.style.setProperty("display", "contents");
1953
+ }
1954
+ onConnect(el) {
1955
+ effect(this.#watchExpanded.bind(this));
1956
+ if (this.isSubmenu) {
1957
+ this.#parentMenu?.addSubmenu(this);
1958
+ }
1959
+ }
1960
+ onDestroy() {
1961
+ this.#trigger.set(null);
1962
+ this.#content.set(null);
1963
+ this.#menuObserver = null;
1964
+ this.#transitionCallbacks.clear();
1965
+ }
1966
+ #observeSliders() {
1967
+ let sliderActiveTimer = -1, parentSliderObserver = hasProvidedContext(sliderObserverContext) ? useContext(sliderObserverContext) : null;
1968
+ provideContext(sliderObserverContext, {
1969
+ onDragStart: () => {
1970
+ parentSliderObserver?.onDragStart?.();
1971
+ window.clearTimeout(sliderActiveTimer);
1972
+ sliderActiveTimer = -1;
1973
+ this.#isSliderActive = true;
1974
+ },
1975
+ onDragEnd: () => {
1976
+ parentSliderObserver?.onDragEnd?.();
1977
+ sliderActiveTimer = window.setTimeout(() => {
1978
+ this.#isSliderActive = false;
1979
+ sliderActiveTimer = -1;
1980
+ }, 300);
1981
+ }
1982
+ });
1983
+ }
1984
+ #watchExpanded() {
1985
+ const expanded = this.#isExpanded();
1986
+ if (!this.isSubmenu) this.#onResize();
1987
+ this.#updateMenuItemsHidden(expanded);
1988
+ if (!expanded) return;
1989
+ effect(() => {
1990
+ const { height } = this.#media.$state, content = this.#content();
1991
+ content && setStyle(content, "--player-height", height() + "px");
1992
+ });
1993
+ this.#focus.listen();
1994
+ this.listen("pointerup", this.#onPointerUp.bind(this));
1995
+ listenEvent(window, "pointerup", this.#onWindowPointerUp.bind(this));
1996
+ }
1997
+ #attachMenuButton(button) {
1998
+ const el = button.el, isMenuItem = this.isSubmenu, isARIADisabled = $ariaBool(this.#isDisabled.bind(this));
1999
+ setAttributeIfEmpty(el, "tabindex", isMenuItem ? "-1" : "0");
2000
+ setAttributeIfEmpty(el, "role", isMenuItem ? "menuitem" : "button");
2001
+ setAttribute(el, "id", this.#menuButtonId);
2002
+ setAttribute(el, "aria-haspopup", "menu");
2003
+ setAttribute(el, "aria-expanded", "false");
2004
+ setAttribute(el, "data-root", !this.isSubmenu);
2005
+ setAttribute(el, "data-submenu", this.isSubmenu);
2006
+ const watchAttrs = () => {
2007
+ setAttribute(el, "data-open", this.#expanded());
2008
+ setAttribute(el, "aria-disabled", isARIADisabled());
2009
+ };
2010
+ effect(watchAttrs);
2011
+ this.#trigger.set(el);
2012
+ onDispose(() => {
2013
+ this.#trigger.set(null);
2014
+ });
2015
+ }
2016
+ #attachMenuItems(items) {
2017
+ const el = items.el;
2018
+ el.style.setProperty("display", "none");
2019
+ setAttribute(el, "id", this.#menuId);
2020
+ setAttributeIfEmpty(el, "role", "menu");
2021
+ setAttributeIfEmpty(el, "tabindex", "-1");
2022
+ setAttribute(el, "data-root", !this.isSubmenu);
2023
+ setAttribute(el, "data-submenu", this.isSubmenu);
2024
+ this.#content.set(el);
2025
+ onDispose(() => this.#content.set(null));
2026
+ const watchAttrs = () => setAttribute(el, "data-open", this.#expanded());
2027
+ effect(watchAttrs);
2028
+ this.#focus.attachMenu(el);
2029
+ this.#updateMenuItemsHidden(false);
2030
+ const onTransition = this.#onResizeTransition.bind(this);
2031
+ if (!this.isSubmenu) {
2032
+ items.listen("transitionstart", onTransition);
2033
+ items.listen("transitionend", onTransition);
2034
+ items.listen("animationend", this.#onResize);
2035
+ items.listen("vds-menu-resize", this.#onResize);
2036
+ } else {
2037
+ this.#parentMenu?.onTransitionEvent(onTransition);
2038
+ }
2039
+ }
2040
+ #attachObserver(observer) {
2041
+ this.#menuObserver = observer;
2042
+ }
2043
+ #updateMenuItemsHidden(expanded) {
2044
+ const content = peek(this.#content);
2045
+ if (content) setAttribute(content, "aria-hidden", ariaBool(!expanded));
2046
+ }
2047
+ #disableMenuButton(disabled) {
2048
+ this.#isTriggerDisabled.set(disabled);
2049
+ }
2050
+ #wasKeyboardExpand = false;
2051
+ #onExpandedChange(isExpanded, event) {
2052
+ this.#wasKeyboardExpand = isKeyboardEvent(event);
2053
+ event?.stopPropagation();
2054
+ if (this.#expanded() === isExpanded) return;
2055
+ if (this.#isDisabled()) {
2056
+ if (isExpanded) this.#popper.hide(event);
2057
+ return;
2058
+ }
2059
+ this.el?.dispatchEvent(
2060
+ new Event("vds-menu-resize", {
2061
+ bubbles: true,
2062
+ composed: true
2063
+ })
2064
+ );
2065
+ const trigger = this.#trigger(), content = this.#content();
2066
+ if (trigger) {
2067
+ setAttribute(trigger, "aria-controls", isExpanded && this.#menuId);
2068
+ setAttribute(trigger, "aria-expanded", ariaBool(isExpanded));
2069
+ }
2070
+ if (content) setAttribute(content, "aria-labelledby", isExpanded && this.#menuButtonId);
2071
+ this.#expanded.set(isExpanded);
2072
+ this.#toggleMediaControls(event);
2073
+ tick();
2074
+ if (this.#wasKeyboardExpand) {
2075
+ if (isExpanded) content?.focus();
2076
+ else trigger?.focus();
2077
+ for (const el of [this.el, content]) {
2078
+ el && el.setAttribute("data-keyboard", "");
2079
+ }
2080
+ } else {
2081
+ for (const el of [this.el, content]) {
2082
+ el && el.removeAttribute("data-keyboard");
2083
+ }
2084
+ }
2085
+ this.dispatch(isExpanded ? "open" : "close", { trigger: event });
2086
+ if (isExpanded) {
2087
+ if (!this.isSubmenu && this.#media.activeMenu !== this) {
2088
+ this.#media.activeMenu?.close(event);
2089
+ this.#media.activeMenu = this;
2090
+ }
2091
+ this.#menuObserver?.onOpen?.(event);
2092
+ } else {
2093
+ if (this.isSubmenu) {
2094
+ for (const el of this.#submenus) el.close(event);
2095
+ } else {
2096
+ this.#media.activeMenu = null;
2097
+ }
2098
+ this.#menuObserver?.onClose?.(event);
2099
+ }
2100
+ if (isExpanded) {
2101
+ requestAnimationFrame(this.#updateFocus.bind(this));
2102
+ }
2103
+ }
2104
+ #updateFocus() {
2105
+ if (this.#isTransitionActive || this.#isSubmenuOpen) return;
2106
+ this.#focus.update();
2107
+ requestAnimationFrame(() => {
2108
+ if (this.#wasKeyboardExpand) {
2109
+ this.#focus.focusActive();
2110
+ } else {
2111
+ this.#focus.scroll();
2112
+ }
2113
+ });
2114
+ }
2115
+ #isExpanded() {
2116
+ return !this.#isDisabled() && this.#expanded();
2117
+ }
2118
+ #isDisabled() {
2119
+ return this.#disabled() || this.#isTriggerDisabled();
2120
+ }
2121
+ #disable(disabled) {
2122
+ this.#disabled.set(disabled);
2123
+ }
2124
+ #onPointerUp(event) {
2125
+ const content = this.#content();
2126
+ if (this.#isSliderActive || content && isEventInside(content, event)) {
2127
+ return;
2128
+ }
2129
+ event.stopPropagation();
2130
+ }
2131
+ #onWindowPointerUp(event) {
2132
+ const content = this.#content();
2133
+ if (this.#isSliderActive || content && isEventInside(content, event)) {
2134
+ return;
2135
+ }
2136
+ this.close(event);
2137
+ }
2138
+ #getCloseTarget() {
2139
+ const target = this.el?.querySelector('[data-part="close-target"]');
2140
+ return this.el && target && isElementParent(this.el, target, (node) => node.getAttribute("role") === "menu") ? target : null;
2141
+ }
2142
+ #toggleMediaControls(trigger) {
2143
+ if (this.isSubmenu) return;
2144
+ if (this.#expanded()) this.#media.remote.pauseControls(trigger);
2145
+ else this.#media.remote.resumeControls(trigger);
2146
+ }
2147
+ #addSubmenu(menu) {
2148
+ this.#submenus.add(menu);
2149
+ new EventsController(menu).add("open", this.#onSubmenuOpenBind).add("close", this.#onSubmenuCloseBind);
2150
+ onDispose(this.#removeSubmenuBind);
2151
+ }
2152
+ #removeSubmenuBind = this.#removeSubmenu.bind(this);
2153
+ #removeSubmenu(menu) {
2154
+ this.#submenus.delete(menu);
2155
+ }
2156
+ #isSubmenuOpen = false;
2157
+ #onSubmenuOpenBind = this.#onSubmenuOpen.bind(this);
2158
+ #onSubmenuOpen(event) {
2159
+ this.#isSubmenuOpen = true;
2160
+ const content = this.#content();
2161
+ if (this.isSubmenu) {
2162
+ this.triggerElement?.setAttribute("aria-hidden", "true");
2163
+ }
2164
+ for (const target of this.#submenus) {
2165
+ if (target !== event.target) {
2166
+ for (const el of [target.el, target.triggerElement]) {
2167
+ el?.setAttribute("aria-hidden", "true");
2168
+ }
2169
+ }
2170
+ }
2171
+ if (content) {
2172
+ const el = event.target.el;
2173
+ for (const child of content.children) {
2174
+ if (child.contains(el)) {
2175
+ child.setAttribute("data-open", "");
2176
+ } else if (child !== el) {
2177
+ child.setAttribute("data-hidden", "");
2178
+ }
2179
+ }
2180
+ }
2181
+ }
2182
+ #onSubmenuCloseBind = this.#onSubmenuClose.bind(this);
2183
+ #onSubmenuClose(event) {
2184
+ this.#isSubmenuOpen = false;
2185
+ const content = this.#content();
2186
+ if (this.isSubmenu) {
2187
+ this.triggerElement?.setAttribute("aria-hidden", "false");
2188
+ }
2189
+ for (const target of this.#submenus) {
2190
+ for (const el of [target.el, target.triggerElement]) {
2191
+ el?.setAttribute("aria-hidden", "false");
2192
+ }
2193
+ }
2194
+ if (content) {
2195
+ for (const child of content.children) {
2196
+ child.removeAttribute("data-open");
2197
+ child.removeAttribute("data-hidden");
2198
+ }
2199
+ }
2200
+ }
2201
+ #onResize = animationFrameThrottle(() => {
2202
+ const content = peek(this.#content);
2203
+ if (!content || false) return;
2204
+ let height = 0, styles = getComputedStyle(content), children = [...content.children];
2205
+ for (const prop2 of ["paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"]) {
2206
+ height += parseFloat(styles[prop2]) || 0;
2207
+ }
2208
+ for (const child of children) {
2209
+ if (isHTMLElement(child) && child.style.display === "contents") {
2210
+ children.push(...child.children);
2211
+ } else if (child.nodeType === 3) {
2212
+ height += parseFloat(getComputedStyle(child).fontSize);
2213
+ } else if (isHTMLElement(child)) {
2214
+ if (!isElementVisible(child)) continue;
2215
+ const style = getComputedStyle(child);
2216
+ height += child.offsetHeight + (parseFloat(style.marginTop) || 0) + (parseFloat(style.marginBottom) || 0);
2217
+ }
2218
+ }
2219
+ setStyle(content, "--menu-height", height + "px");
2220
+ });
2221
+ #isTransitionActive = false;
2222
+ #onResizeTransition(event) {
2223
+ const content = this.#content();
2224
+ if (content && event.propertyName === "height") {
2225
+ this.#isTransitionActive = event.type === "transitionstart";
2226
+ setAttribute(content, "data-transition", this.#isTransitionActive ? "height" : null);
2227
+ if (this.#expanded()) this.#updateFocus();
2228
+ }
2229
+ for (const callback of this.#transitionCallbacks) callback(event);
2230
+ }
2231
+ open(trigger) {
2232
+ if (peek(this.#expanded)) return;
2233
+ this.#popper.show(trigger);
2234
+ tick();
2235
+ }
2236
+ close(trigger) {
2237
+ if (!peek(this.#expanded)) return;
2238
+ this.#popper.hide(trigger);
2239
+ tick();
2240
+ }
2241
+ }
2242
+ __decorateClass([
2243
+ prop
2244
+ ], Menu.prototype, "triggerElement");
2245
+ __decorateClass([
2246
+ prop
2247
+ ], Menu.prototype, "contentElement");
2248
+ __decorateClass([
2249
+ prop
2250
+ ], Menu.prototype, "isSubmenu");
2251
+ __decorateClass([
2252
+ method
2253
+ ], Menu.prototype, "open");
2254
+ __decorateClass([
2255
+ method
2256
+ ], Menu.prototype, "close");
2257
+
2258
+ class MenuButton extends Component {
2259
+ static props = {
2260
+ disabled: false
2261
+ };
2262
+ #menu;
2263
+ #hintEl = signal(null);
2264
+ get expanded() {
2265
+ return this.#menu?.expanded() ?? false;
2266
+ }
2267
+ constructor() {
2268
+ super();
2269
+ new FocusVisibleController();
2270
+ }
2271
+ onSetup() {
2272
+ this.#menu = useContext(menuContext);
2273
+ }
2274
+ onAttach(el) {
2275
+ this.#menu.attachMenuButton(this);
2276
+ effect(this.#watchDisabled.bind(this));
2277
+ setAttributeIfEmpty(el, "type", "button");
2278
+ }
2279
+ onConnect(el) {
2280
+ effect(this.#watchHintEl.bind(this));
2281
+ this.#onMutation();
2282
+ const mutations = new MutationObserver(this.#onMutation.bind(this));
2283
+ mutations.observe(el, { attributeFilter: ["data-part"], childList: true, subtree: true });
2284
+ onDispose(() => mutations.disconnect());
2285
+ onPress(el, (trigger) => {
2286
+ this.dispatch("select", { trigger });
2287
+ });
2288
+ }
2289
+ #watchDisabled() {
2290
+ this.#menu.disableMenuButton(this.$props.disabled());
2291
+ }
2292
+ #watchHintEl() {
2293
+ const el = this.#hintEl();
2294
+ if (!el) return;
2295
+ effect(() => {
2296
+ const text = this.#menu.hint();
2297
+ if (text) el.textContent = text;
2298
+ });
2299
+ }
2300
+ #onMutation() {
2301
+ const hintEl = this.el?.querySelector('[data-part="hint"]');
2302
+ this.#hintEl.set(hintEl ?? null);
2303
+ }
2304
+ }
2305
+ const menubutton__proto = MenuButton.prototype;
2306
+ prop(menubutton__proto, "expanded");
2307
+
2308
+ class MenuItem extends MenuButton {
2309
+ }
2310
+
2311
+ class MenuPortal extends Component {
2312
+ static props = {
2313
+ container: null,
2314
+ disabled: false
2315
+ };
2316
+ #target = null;
2317
+ #media;
2318
+ onSetup() {
2319
+ this.#media = useMediaContext();
2320
+ provideContext(menuPortalContext, {
2321
+ attach: this.#attachElement.bind(this)
2322
+ });
2323
+ }
2324
+ onAttach(el) {
2325
+ el.style.setProperty("display", "contents");
2326
+ }
2327
+ // Need this so connect scope is defined.
2328
+ onConnect(el) {
2329
+ }
2330
+ onDestroy() {
2331
+ this.#target?.remove();
2332
+ this.#target = null;
2333
+ }
2334
+ #attachElement(el) {
2335
+ this.#portal(false);
2336
+ this.#target = el;
2337
+ requestScopedAnimationFrame(() => {
2338
+ requestScopedAnimationFrame(() => {
2339
+ if (!this.connectScope) return;
2340
+ effect(this.#watchDisabled.bind(this));
2341
+ });
2342
+ });
2343
+ }
2344
+ #watchDisabled() {
2345
+ const { fullscreen } = this.#media.$state, { disabled } = this.$props;
2346
+ this.#portal(disabled() === "fullscreen" ? !fullscreen() : !disabled());
2347
+ }
2348
+ #portal(shouldPortal) {
2349
+ if (!this.#target) return;
2350
+ let container = this.#getContainer(this.$props.container());
2351
+ if (!container) return;
2352
+ const isPortalled = this.#target.parentElement === container;
2353
+ setAttribute(this.#target, "data-portal", shouldPortal);
2354
+ if (shouldPortal) {
2355
+ if (!isPortalled) {
2356
+ this.#target.remove();
2357
+ container.append(this.#target);
2358
+ }
2359
+ } else if (isPortalled && this.#target.parentElement === container) {
2360
+ this.#target.remove();
2361
+ this.el?.append(this.#target);
2362
+ }
2363
+ }
2364
+ #getContainer(selector) {
2365
+ if (isHTMLElement(selector)) return selector;
2366
+ return selector ? document.querySelector(selector) : document.body;
2367
+ }
2368
+ }
2369
+ const menuPortalContext = createContext();
2370
+
2371
+ class MenuItems extends Component {
2372
+ static props = {
2373
+ placement: null,
2374
+ offset: 0,
2375
+ alignOffset: 0
2376
+ };
2377
+ #menu;
2378
+ constructor() {
2379
+ super();
2380
+ new FocusVisibleController();
2381
+ const { placement } = this.$props;
2382
+ this.setAttributes({
2383
+ "data-placement": placement
2384
+ });
2385
+ }
2386
+ onAttach(el) {
2387
+ this.#menu = useContext(menuContext);
2388
+ this.#menu.attachMenuItems(this);
2389
+ if (hasProvidedContext(menuPortalContext)) {
2390
+ const portal = useContext(menuPortalContext);
2391
+ if (portal) {
2392
+ provideContext(menuPortalContext, null);
2393
+ portal.attach(el);
2394
+ onDispose(() => portal.attach(null));
2395
+ }
2396
+ }
2397
+ }
2398
+ onConnect(el) {
2399
+ effect(this.#watchPlacement.bind(this));
2400
+ }
2401
+ #watchPlacement() {
2402
+ const { expanded } = this.#menu;
2403
+ if (!this.el || !expanded()) return;
2404
+ const placement = this.$props.placement();
2405
+ if (!placement) return;
2406
+ Object.assign(this.el.style, {
2407
+ position: "absolute",
2408
+ top: 0,
2409
+ left: 0,
2410
+ width: "max-content"
2411
+ });
2412
+ const { offset: mainOffset, alignOffset } = this.$props;
2413
+ onDispose(
2414
+ autoPlacement(this.el, this.#getButton(), placement, {
2415
+ offsetVarName: "media-menu",
2416
+ xOffset: alignOffset(),
2417
+ yOffset: mainOffset()
2418
+ })
2419
+ );
2420
+ onDispose(this.#hide.bind(this));
2421
+ }
2422
+ #hide() {
2423
+ if (!this.el) return;
2424
+ this.el.removeAttribute("style");
2425
+ this.el.style.display = "none";
2426
+ }
2427
+ #getButton() {
2428
+ return this.#menu.button();
2429
+ }
2430
+ }
2431
+
2432
+ const radioControllerContext = createContext();
2433
+
2434
+ class RadioGroupController extends ViewController {
2435
+ #group = /* @__PURE__ */ new Set();
2436
+ #value = signal("");
2437
+ #controller = null;
2438
+ onValueChange;
2439
+ get values() {
2440
+ return Array.from(this.#group).map((radio) => radio.value());
2441
+ }
2442
+ get value() {
2443
+ return this.#value();
2444
+ }
2445
+ set value(value) {
2446
+ this.#onChange(value);
2447
+ }
2448
+ onSetup() {
2449
+ provideContext(radioControllerContext, {
2450
+ add: this.#addRadio.bind(this),
2451
+ remove: this.#removeRadio.bind(this)
2452
+ });
2453
+ }
2454
+ onAttach(el) {
2455
+ const isMenuItem = hasProvidedContext(menuContext);
2456
+ if (!isMenuItem) setAttributeIfEmpty(el, "role", "radiogroup");
2457
+ this.setAttributes({ value: this.#value });
2458
+ }
2459
+ onDestroy() {
2460
+ this.#group.clear();
2461
+ }
2462
+ #addRadio(radio) {
2463
+ if (this.#group.has(radio)) return;
2464
+ this.#group.add(radio);
2465
+ radio.onCheck = this.#onChangeBind;
2466
+ radio.check(radio.value() === this.#value());
2467
+ }
2468
+ #removeRadio(radio) {
2469
+ radio.onCheck = null;
2470
+ this.#group.delete(radio);
2471
+ }
2472
+ #onChangeBind = this.#onChange.bind(this);
2473
+ #onChange(newValue, trigger) {
2474
+ const currentValue = peek(this.#value);
2475
+ if (!newValue || newValue === currentValue) return;
2476
+ const currentRadio = this.#findRadio(currentValue), newRadio = this.#findRadio(newValue);
2477
+ currentRadio?.check(false, trigger);
2478
+ newRadio?.check(true, trigger);
2479
+ this.#value.set(newValue);
2480
+ this.onValueChange?.(newValue, trigger);
2481
+ }
2482
+ #findRadio(newValue) {
2483
+ for (const radio of this.#group) {
2484
+ if (newValue === peek(radio.value)) return radio;
2485
+ }
2486
+ return null;
2487
+ }
2488
+ }
2489
+
2490
+ class Radio extends Component {
2491
+ static props = {
2492
+ value: ""
2493
+ };
2494
+ #checked = signal(false);
2495
+ #controller = {
2496
+ value: this.$props.value,
2497
+ check: this.#check.bind(this),
2498
+ onCheck: null
2499
+ };
2500
+ /**
2501
+ * Whether this radio is currently checked.
2502
+ */
2503
+ get checked() {
2504
+ return this.#checked();
2505
+ }
2506
+ constructor() {
2507
+ super();
2508
+ new FocusVisibleController();
2509
+ }
2510
+ onSetup() {
2511
+ this.setAttributes({
2512
+ value: this.$props.value,
2513
+ "data-checked": this.#checked,
2514
+ "aria-checked": $ariaBool(this.#checked)
2515
+ });
2516
+ }
2517
+ onAttach(el) {
2518
+ const isMenuItem = hasProvidedContext(menuContext);
2519
+ setAttributeIfEmpty(el, "tabindex", isMenuItem ? "-1" : "0");
2520
+ setAttributeIfEmpty(el, "role", isMenuItem ? "menuitemradio" : "radio");
2521
+ effect(this.#watchValue.bind(this));
2522
+ }
2523
+ onConnect(el) {
2524
+ this.#addToGroup();
2525
+ onPress(el, this.#onPress.bind(this));
2526
+ onDispose(this.#onDisconnect.bind(this));
2527
+ }
2528
+ #onDisconnect() {
2529
+ scoped(() => {
2530
+ const group = useContext(radioControllerContext);
2531
+ group.remove(this.#controller);
2532
+ }, this.connectScope);
2533
+ }
2534
+ #addToGroup() {
2535
+ const group = useContext(radioControllerContext);
2536
+ group.add(this.#controller);
2537
+ }
2538
+ #watchValue() {
2539
+ const { value } = this.$props, newValue = value();
2540
+ if (peek(this.#checked)) {
2541
+ this.#controller.onCheck?.(newValue);
2542
+ }
2543
+ }
2544
+ #onPress(event) {
2545
+ if (peek(this.#checked)) return;
2546
+ this.#onChange(true, event);
2547
+ this.#onSelect(event);
2548
+ this.#controller.onCheck?.(peek(this.$props.value), event);
2549
+ }
2550
+ #check(value, trigger) {
2551
+ if (peek(this.#checked) === value) return;
2552
+ this.#onChange(value, trigger);
2553
+ }
2554
+ #onChange(value, trigger) {
2555
+ this.#checked.set(value);
2556
+ this.dispatch("change", { detail: value, trigger });
2557
+ }
2558
+ #onSelect(trigger) {
2559
+ this.dispatch("select", { trigger });
2560
+ }
2561
+ }
2562
+ const radio__proto = Radio.prototype;
2563
+ prop(radio__proto, "checked");
2564
+
2565
+ class AudioRadioGroup extends Component {
2566
+ static props = {
2567
+ emptyLabel: "Default"
2568
+ };
2569
+ #menu;
2570
+ #media;
2571
+ #controller;
2572
+ get value() {
2573
+ return this.#controller.value;
2574
+ }
2575
+ get disabled() {
2576
+ const { audioTracks } = this.#media.$state;
2577
+ return audioTracks().length <= 1;
2578
+ }
2579
+ constructor() {
2580
+ super();
2581
+ this.#controller = new RadioGroupController();
2582
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2583
+ }
2584
+ onSetup() {
2585
+ this.#media = useMediaContext();
2586
+ if (hasProvidedContext(menuContext)) {
2587
+ this.#menu = useContext(menuContext);
2588
+ }
2589
+ }
2590
+ onConnect(el) {
2591
+ effect(this.#watchValue.bind(this));
2592
+ effect(this.#watchControllerDisabled.bind(this));
2593
+ effect(this.#watchHintText.bind(this));
2594
+ }
2595
+ getOptions() {
2596
+ const { audioTracks } = this.#media.$state;
2597
+ return audioTracks().map((track) => ({
2598
+ track,
2599
+ label: track.label,
2600
+ value: track.label.toLowerCase()
2601
+ }));
2602
+ }
2603
+ #watchValue() {
2604
+ this.#controller.value = this.#getValue();
2605
+ }
2606
+ #watchHintText() {
2607
+ const { emptyLabel } = this.$props, { audioTrack } = this.#media.$state, track = audioTrack();
2608
+ this.#menu?.hint.set(track?.label ?? emptyLabel());
2609
+ }
2610
+ #watchControllerDisabled() {
2611
+ this.#menu?.disable(this.disabled);
2612
+ }
2613
+ #getValue() {
2614
+ const { audioTrack } = this.#media.$state;
2615
+ const track = audioTrack();
2616
+ return track ? track.label.toLowerCase() : "";
2617
+ }
2618
+ #onValueChange(value, trigger) {
2619
+ if (this.disabled) return;
2620
+ const index = this.#media.audioTracks.toArray().findIndex((track) => track.label.toLowerCase() === value);
2621
+ if (index >= 0) {
2622
+ const track = this.#media.audioTracks[index];
2623
+ this.#media.remote.changeAudioTrack(index, trigger);
2624
+ this.dispatch("change", { detail: track, trigger });
2625
+ }
2626
+ }
2627
+ }
2628
+ const audioradiogroup__proto = AudioRadioGroup.prototype;
2629
+ prop(audioradiogroup__proto, "value");
2630
+ prop(audioradiogroup__proto, "disabled");
2631
+ method(audioradiogroup__proto, "getOptions");
2632
+
2633
+ class CaptionsRadioGroup extends Component {
2634
+ static props = {
2635
+ offLabel: "Off"
2636
+ };
2637
+ #media;
2638
+ #menu;
2639
+ #controller;
2640
+ get value() {
2641
+ return this.#controller.value;
2642
+ }
2643
+ get disabled() {
2644
+ const { hasCaptions } = this.#media.$state;
2645
+ return !hasCaptions();
2646
+ }
2647
+ constructor() {
2648
+ super();
2649
+ this.#controller = new RadioGroupController();
2650
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2651
+ }
2652
+ onSetup() {
2653
+ this.#media = useMediaContext();
2654
+ if (hasProvidedContext(menuContext)) {
2655
+ this.#menu = useContext(menuContext);
2656
+ }
2657
+ }
2658
+ onConnect(el) {
2659
+ super.onConnect?.(el);
2660
+ effect(this.#watchValue.bind(this));
2661
+ effect(this.#watchControllerDisabled.bind(this));
2662
+ effect(this.#watchHintText.bind(this));
2663
+ }
2664
+ getOptions() {
2665
+ const { offLabel } = this.$props, { textTracks } = this.#media.$state;
2666
+ const tracks = textTracks().filter(isTrackCaptionKind);
2667
+ const priorities = ["indonesian", "english", "japanese", "korean", "chinese"];
2668
+ const getPriority = (label) => {
2669
+ const lower = label.toLowerCase();
2670
+ const pIndex = priorities.findIndex((p) => lower.includes(p));
2671
+ return pIndex !== -1 ? pIndex : 999;
2672
+ };
2673
+ const sortedTracks = [...tracks].sort((a, b) => {
2674
+ const pa = getPriority(a.label);
2675
+ const pb = getPriority(b.label);
2676
+ if (pa !== pb) return pa - pb;
2677
+ return a.label.localeCompare(b.label);
2678
+ });
2679
+ const labelCounts = /* @__PURE__ */ new Map();
2680
+ const trackOptions = sortedTracks.map((track) => {
2681
+ const count = (labelCounts.get(track.label) || 0) + 1;
2682
+ labelCounts.set(track.label, count);
2683
+ const total = sortedTracks.filter((t) => t.label === track.label).length;
2684
+ let displayLabel = track.label;
2685
+ if (total > 1) {
2686
+ displayLabel = `${track.label} ${count}`;
2687
+ }
2688
+ return {
2689
+ track,
2690
+ label: displayLabel,
2691
+ value: this.#getTrackValue(track)
2692
+ };
2693
+ });
2694
+ return [
2695
+ { value: "off", label: offLabel },
2696
+ ...trackOptions
2697
+ ];
2698
+ }
2699
+ #watchValue() {
2700
+ this.#controller.value = this.#getValue();
2701
+ }
2702
+ #watchHintText() {
2703
+ const { offLabel } = this.$props, { textTrack } = this.#media.$state, track = textTrack();
2704
+ this.#menu?.hint.set(
2705
+ track && isTrackCaptionKind(track) && track.mode === "showing" ? track.label : offLabel()
2706
+ );
2707
+ }
2708
+ #watchControllerDisabled() {
2709
+ this.#menu?.disable(this.disabled);
2710
+ }
2711
+ #getValue() {
2712
+ const { textTrack } = this.#media.$state, track = textTrack();
2713
+ return track && isTrackCaptionKind(track) && track.mode === "showing" ? this.#getTrackValue(track) : "off";
2714
+ }
2715
+ #onValueChange(value, trigger) {
2716
+ if (this.disabled) return;
2717
+ if (value === "off") {
2718
+ const track = this.#media.textTracks.selected;
2719
+ if (track) {
2720
+ const index2 = this.#media.textTracks.indexOf(track);
2721
+ this.#media.remote.changeTextTrackMode(index2, "disabled", trigger);
2722
+ this.dispatch("change", { detail: null, trigger });
2723
+ }
2724
+ return;
2725
+ }
2726
+ const index = this.#media.textTracks.toArray().findIndex((track) => this.#getTrackValue(track) === value);
2727
+ if (index >= 0) {
2728
+ const track = this.#media.textTracks[index];
2729
+ this.#media.remote.changeTextTrackMode(index, "showing", trigger);
2730
+ this.dispatch("change", { detail: track, trigger });
2731
+ }
2732
+ }
2733
+ #getTrackValue(track) {
2734
+ return track.id + ":" + track.kind + "-" + track.label.toLowerCase();
2735
+ }
2736
+ }
2737
+ const captionsradiogroup__proto = CaptionsRadioGroup.prototype;
2738
+ prop(captionsradiogroup__proto, "value");
2739
+ prop(captionsradiogroup__proto, "disabled");
2740
+ method(captionsradiogroup__proto, "getOptions");
2741
+
2742
+ const DEFAULT_PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
2743
+ class SpeedRadioGroup extends Component {
2744
+ static props = {
2745
+ normalLabel: "Normal",
2746
+ rates: DEFAULT_PLAYBACK_RATES
2747
+ };
2748
+ #media;
2749
+ #menu;
2750
+ #controller;
2751
+ get value() {
2752
+ return this.#controller.value;
2753
+ }
2754
+ get disabled() {
2755
+ const { rates } = this.$props, { canSetPlaybackRate } = this.#media.$state;
2756
+ return !canSetPlaybackRate() || rates().length === 0;
2757
+ }
2758
+ constructor() {
2759
+ super();
2760
+ this.#controller = new RadioGroupController();
2761
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2762
+ }
2763
+ onSetup() {
2764
+ this.#media = useMediaContext();
2765
+ if (hasProvidedContext(menuContext)) {
2766
+ this.#menu = useContext(menuContext);
2767
+ }
2768
+ }
2769
+ onConnect(el) {
2770
+ effect(this.#watchValue.bind(this));
2771
+ effect(this.#watchHintText.bind(this));
2772
+ effect(this.#watchControllerDisabled.bind(this));
2773
+ }
2774
+ getOptions() {
2775
+ const { rates, normalLabel } = this.$props;
2776
+ return rates().map((rate) => ({
2777
+ label: rate === 1 ? normalLabel : rate + "\xD7",
2778
+ value: rate.toString()
2779
+ }));
2780
+ }
2781
+ #watchValue() {
2782
+ this.#controller.value = this.#getValue();
2783
+ }
2784
+ #watchHintText() {
2785
+ const { normalLabel } = this.$props, { playbackRate } = this.#media.$state, rate = playbackRate();
2786
+ this.#menu?.hint.set(rate === 1 ? normalLabel() : rate + "\xD7");
2787
+ }
2788
+ #watchControllerDisabled() {
2789
+ this.#menu?.disable(this.disabled);
2790
+ }
2791
+ #getValue() {
2792
+ const { playbackRate } = this.#media.$state;
2793
+ return playbackRate().toString();
2794
+ }
2795
+ #onValueChange(value, trigger) {
2796
+ if (this.disabled) return;
2797
+ const rate = +value;
2798
+ this.#media.remote.changePlaybackRate(rate, trigger);
2799
+ this.dispatch("change", { detail: rate, trigger });
2800
+ }
2801
+ }
2802
+ const speedradiogroup__proto = SpeedRadioGroup.prototype;
2803
+ prop(speedradiogroup__proto, "value");
2804
+ prop(speedradiogroup__proto, "disabled");
2805
+ method(speedradiogroup__proto, "getOptions");
2806
+
2807
+ class QualityRadioGroup extends Component {
2808
+ static props = {
2809
+ autoLabel: "Auto",
2810
+ hideBitrate: false,
2811
+ sort: "descending"
2812
+ };
2813
+ #media;
2814
+ #menu;
2815
+ #controller;
2816
+ get value() {
2817
+ return this.#controller.value;
2818
+ }
2819
+ get disabled() {
2820
+ const { canSetQuality, qualities } = this.#media.$state;
2821
+ return !canSetQuality() || qualities().length <= 1;
2822
+ }
2823
+ #sortedQualities = computed(() => {
2824
+ const { sort } = this.$props, { qualities } = this.#media.$state;
2825
+ return sortVideoQualities(qualities(), sort() === "descending");
2826
+ });
2827
+ constructor() {
2828
+ super();
2829
+ this.#controller = new RadioGroupController();
2830
+ this.#controller.onValueChange = this.#onValueChange.bind(this);
2831
+ }
2832
+ onSetup() {
2833
+ this.#media = useMediaContext();
2834
+ if (hasProvidedContext(menuContext)) {
2835
+ this.#menu = useContext(menuContext);
2836
+ }
2837
+ }
2838
+ onConnect(el) {
2839
+ effect(this.#watchValue.bind(this));
2840
+ effect(this.#watchControllerDisabled.bind(this));
2841
+ effect(this.#watchHintText.bind(this));
2842
+ }
2843
+ getOptions() {
2844
+ const { autoLabel, hideBitrate } = this.$props;
2845
+ return [
2846
+ { value: "auto", label: autoLabel },
2847
+ ...this.#sortedQualities().map((quality) => {
2848
+ const bitrate = quality.bitrate && quality.bitrate >= 0 ? `${round(quality.bitrate / 1e6, 2)} Mbps` : null;
2849
+ return {
2850
+ quality,
2851
+ label: quality.label ?? (quality.height ? quality.height + "p" : "Unknown"),
2852
+ value: this.#getQualityId(quality),
2853
+ bitrate: () => !hideBitrate() ? bitrate : null
2854
+ };
2855
+ })
2856
+ ];
2857
+ }
2858
+ #watchValue() {
2859
+ this.#controller.value = this.#getValue();
2860
+ }
2861
+ #watchHintText() {
2862
+ const { autoLabel } = this.$props, { autoQuality, quality } = this.#media.$state, q = quality(), qualityText = q ? q.label ?? (q.height ? q.height + "p" : "") : "";
2863
+ this.#menu?.hint.set(
2864
+ !autoQuality() ? qualityText : autoLabel() + (qualityText ? ` (${qualityText})` : "")
2865
+ );
2866
+ }
2867
+ #watchControllerDisabled() {
2868
+ this.#menu?.disable(this.disabled);
2869
+ }
2870
+ #onValueChange(value, trigger) {
2871
+ if (this.disabled) return;
2872
+ if (value === "auto") {
2873
+ this.#media.remote.changeQuality(-1, trigger);
2874
+ this.dispatch("change", { detail: "auto", trigger });
2875
+ return;
2876
+ }
2877
+ const { qualities } = this.#media.$state, index = peek(qualities).findIndex((quality) => this.#getQualityId(quality) === value);
2878
+ if (index >= 0) {
2879
+ const quality = peek(qualities)[index];
2880
+ this.#media.remote.changeQuality(index, trigger);
2881
+ this.dispatch("change", { detail: quality, trigger });
2882
+ }
2883
+ }
2884
+ #getValue() {
2885
+ const { quality, autoQuality } = this.#media.$state;
2886
+ if (autoQuality()) return "auto";
2887
+ const currentQuality = quality();
2888
+ return currentQuality ? this.#getQualityId(currentQuality) : "auto";
2889
+ }
2890
+ #getQualityId(quality) {
2891
+ return quality.id;
2892
+ }
2893
+ }
2894
+ const qualityradiogroup__proto = QualityRadioGroup.prototype;
2895
+ prop(qualityradiogroup__proto, "value");
2896
+ prop(qualityradiogroup__proto, "disabled");
2897
+ method(qualityradiogroup__proto, "getOptions");
2898
+
2899
+ class Time extends Component {
2900
+ static props = {
2901
+ type: "current",
2902
+ showHours: false,
2903
+ padHours: null,
2904
+ padMinutes: null,
2905
+ remainder: false,
2906
+ toggle: false,
2907
+ hidden: false
2908
+ };
2909
+ static state = new State({
2910
+ timeText: "",
2911
+ hidden: false
2912
+ });
2913
+ #media;
2914
+ #invert = signal(null);
2915
+ #isVisible = signal(true);
2916
+ #isIntersecting = signal(true);
2917
+ onSetup() {
2918
+ this.#media = useMediaContext();
2919
+ this.#watchTime();
2920
+ const { type } = this.$props;
2921
+ this.setAttributes({
2922
+ "data-type": type,
2923
+ "data-remainder": this.#shouldInvert.bind(this)
2924
+ });
2925
+ new IntersectionObserverController({
2926
+ callback: this.#onIntersectionChange.bind(this)
2927
+ }).attach(this);
2928
+ }
2929
+ onAttach(el) {
2930
+ if (!el.hasAttribute("role")) effect(this.#watchRole.bind(this));
2931
+ effect(this.#watchTime.bind(this));
2932
+ }
2933
+ onConnect(el) {
2934
+ onDispose(observeVisibility(el, this.#isVisible.set));
2935
+ effect(this.#watchHidden.bind(this));
2936
+ effect(this.#watchToggle.bind(this));
2937
+ }
2938
+ #onIntersectionChange(entries) {
2939
+ this.#isIntersecting.set(entries[0].isIntersecting);
2940
+ }
2941
+ #watchHidden() {
2942
+ const { hidden } = this.$props;
2943
+ this.$state.hidden.set(hidden() || !this.#isVisible() || !this.#isIntersecting());
2944
+ }
2945
+ #watchToggle() {
2946
+ if (!this.$props.toggle()) {
2947
+ this.#invert.set(null);
2948
+ return;
2949
+ }
2950
+ if (this.el) {
2951
+ onPress(this.el, this.#onToggle.bind(this));
2952
+ }
2953
+ }
2954
+ #watchTime() {
2955
+ const { hidden, timeText } = this.$state, { duration } = this.#media.$state;
2956
+ if (hidden()) return;
2957
+ const { type, padHours, padMinutes, showHours } = this.$props, seconds = this.#getSeconds(type()), $duration = duration(), shouldInvert = this.#shouldInvert();
2958
+ if (!Number.isFinite(seconds + $duration)) {
2959
+ timeText.set("LIVE");
2960
+ return;
2961
+ }
2962
+ const time = shouldInvert ? Math.max(0, $duration - seconds) : seconds, formattedTime = formatTime(time, {
2963
+ padHrs: padHours(),
2964
+ padMins: padMinutes(),
2965
+ showHrs: showHours()
2966
+ });
2967
+ timeText.set((shouldInvert ? "-" : "") + formattedTime);
2968
+ }
2969
+ #watchRole() {
2970
+ if (!this.el) return;
2971
+ const { toggle } = this.$props;
2972
+ setAttribute(this.el, "role", toggle() ? "timer" : null);
2973
+ setAttribute(this.el, "tabindex", toggle() ? 0 : null);
2974
+ }
2975
+ #getSeconds(type) {
2976
+ const { bufferedEnd, duration, currentTime } = this.#media.$state;
2977
+ switch (type) {
2978
+ case "buffered":
2979
+ return bufferedEnd();
2980
+ case "duration":
2981
+ return duration();
2982
+ default:
2983
+ return currentTime();
2984
+ }
2985
+ }
2986
+ #shouldInvert() {
2987
+ return this.$props.remainder() && this.#invert() !== false;
2988
+ }
2989
+ #onToggle(event) {
2990
+ event.preventDefault();
2991
+ if (this.#invert() === null) {
2992
+ this.#invert.set(!this.$props.remainder());
2993
+ return;
2994
+ }
2995
+ this.#invert.set((v) => !v);
2996
+ }
2997
+ }
2998
+
2999
+ 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 };