@locpd/vidstack 1.12.14

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