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