@hanifhan1f/vidstack 1.12.33 → 1.12.35

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 (210) hide show
  1. package/cdn/with-layouts/chunks/{vidstack-BCLumCST.js → vidstack-BEgmmcDO.js} +56 -52
  2. package/cdn/with-layouts/chunks/{vidstack-DJyGEdCH.js → vidstack-t3PBZMbl.js} +1 -1
  3. package/cdn/with-layouts/vidstack.js +1 -1
  4. package/dev/chunks/{vidstack-B__DfQsT.js → vidstack-BReSQAMt.js} +10 -6
  5. package/dev/define/templates/vidstack-audio-layout.js +1 -1
  6. package/dev/define/templates/vidstack-video-layout.js +7 -5
  7. package/dev/define/vidstack-player-default-layout.js +1 -1
  8. package/dev/define/vidstack-player-layouts.js +1 -1
  9. package/dev/vidstack-elements.js +1 -1
  10. package/dev/vidstack.js +0 -4
  11. package/elements.d.ts +1 -1
  12. package/global/player.d.ts +1 -1
  13. package/global/plyr.d.ts +2 -2
  14. package/index.d.ts +2 -2
  15. package/package.json +1 -1
  16. package/prod/chunks/{vidstack-BnEo_Sla.js → vidstack-B0glDgAI.js} +10 -6
  17. package/prod/define/templates/vidstack-audio-layout.js +1 -1
  18. package/prod/define/templates/vidstack-video-layout.js +7 -5
  19. package/prod/define/vidstack-player-default-layout.js +1 -1
  20. package/prod/define/vidstack-player-layouts.js +1 -1
  21. package/prod/vidstack-elements.js +1 -1
  22. package/server/chunks/{vidstack-BIGdJnUK.js → vidstack-nANS1jfu.js} +16 -10
  23. package/server/define/vidstack-player-default-layout.js +1 -1
  24. package/server/define/vidstack-player-layouts.js +1 -1
  25. package/server/vidstack-elements.js +1 -1
  26. package/types/{vidstack-DYLKXUvI.d.ts → vidstack-CZqFq0VF.d.ts} +13 -1
  27. package/cdn/chunks/vidstack-8JHLDxl5.js +0 -1
  28. package/cdn/chunks/vidstack-BF7lZRtq.js +0 -3
  29. package/cdn/chunks/vidstack-BYgY9wmd.js +0 -1
  30. package/cdn/chunks/vidstack-BYpysj84.js +0 -1
  31. package/cdn/chunks/vidstack-Bjo5esRp.js +0 -1
  32. package/cdn/chunks/vidstack-BkxGdzTJ.js +0 -16
  33. package/cdn/chunks/vidstack-BuL67v3q.js +0 -1
  34. package/cdn/chunks/vidstack-Bzk6lVKb.js +0 -1
  35. package/cdn/chunks/vidstack-C0msPRTd.js +0 -3
  36. package/cdn/chunks/vidstack-C1FlyyzK.js +0 -1
  37. package/cdn/chunks/vidstack-CIjxJCz3.js +0 -1
  38. package/cdn/chunks/vidstack-CioT3Yw2.js +0 -1
  39. package/cdn/chunks/vidstack-Cj0I-Rec.js +0 -1
  40. package/cdn/chunks/vidstack-CmpbA3Yd.js +0 -16
  41. package/cdn/chunks/vidstack-CnWKPIKT.js +0 -16
  42. package/cdn/chunks/vidstack-CrqkytHl.js +0 -1
  43. package/cdn/chunks/vidstack-D0M8R0ZU.js +0 -1
  44. package/cdn/chunks/vidstack-D40FSa5B.js +0 -3
  45. package/cdn/chunks/vidstack-D84Fzc__.js +0 -16
  46. package/cdn/chunks/vidstack-DD2JwFVU.js +0 -1
  47. package/cdn/chunks/vidstack-DQvyz7Mm.js +0 -1
  48. package/cdn/chunks/vidstack-Dd9fqVv6.js +0 -1
  49. package/cdn/chunks/vidstack-DfDZuHNP.js +0 -1
  50. package/cdn/chunks/vidstack-uMxrPflF.js +0 -1
  51. package/cdn/chunks/vidstack-xjJ-ui_l.js +0 -1
  52. package/cdn/chunks/vidstack-zemsqC5d.js +0 -1
  53. package/cdn/providers/vidstack-audio-2Dt_Ivbp.js +0 -1
  54. package/cdn/providers/vidstack-audio-BOGYlExy.js +0 -1
  55. package/cdn/providers/vidstack-dash-CUtD4e6q.js +0 -1
  56. package/cdn/providers/vidstack-dash-D4ZARr66.js +0 -1
  57. package/cdn/providers/vidstack-google-cast-BdORATUX.js +0 -1
  58. package/cdn/providers/vidstack-hls-8-552IuX.js +0 -1
  59. package/cdn/providers/vidstack-hls-R25Kb6DP.js +0 -1
  60. package/cdn/providers/vidstack-html-BvVaN2VT.js +0 -1
  61. package/cdn/providers/vidstack-html-DaAUJYsD.js +0 -1
  62. package/cdn/providers/vidstack-video-BnwQZKER.js +0 -1
  63. package/cdn/providers/vidstack-video-Csvox7SO.js +0 -1
  64. package/cdn/providers/vidstack-vimeo-D4Z96kg2.js +0 -1
  65. package/cdn/providers/vidstack-vimeo-gJmBqtLK.js +0 -1
  66. package/cdn/providers/vidstack-youtube-Chl_dTAz.js +0 -1
  67. package/cdn/providers/vidstack-youtube-DiND6h3s.js +0 -1
  68. package/cdn/with-layouts/chunks/vidstack-4liSokT6.js +0 -1
  69. package/cdn/with-layouts/chunks/vidstack-B97B8XDc.js +0 -3
  70. package/cdn/with-layouts/chunks/vidstack-BD5YoTt5.js +0 -937
  71. package/cdn/with-layouts/chunks/vidstack-BGhRKayG.js +0 -914
  72. package/cdn/with-layouts/chunks/vidstack-BL_lNyW_.js +0 -1
  73. package/cdn/with-layouts/chunks/vidstack-BMhNagfl.js +0 -1
  74. package/cdn/with-layouts/chunks/vidstack-BP3ybDy9.js +0 -912
  75. package/cdn/with-layouts/chunks/vidstack-BbFHhcVG.js +0 -1
  76. package/cdn/with-layouts/chunks/vidstack-BjOOdDcQ.js +0 -1
  77. package/cdn/with-layouts/chunks/vidstack-C5AP9wid.js +0 -1
  78. package/cdn/with-layouts/chunks/vidstack-CS2aNc61.js +0 -1
  79. package/cdn/with-layouts/chunks/vidstack-CXEcXyBI.js +0 -1
  80. package/cdn/with-layouts/chunks/vidstack-Ciq-n5rg.js +0 -1
  81. package/cdn/with-layouts/chunks/vidstack-CmuGllcj.js +0 -1
  82. package/cdn/with-layouts/chunks/vidstack-CyNByJUW.js +0 -912
  83. package/cdn/with-layouts/chunks/vidstack-D-3_fAsK.js +0 -1
  84. package/cdn/with-layouts/chunks/vidstack-DCaNJN4T.js +0 -1
  85. package/cdn/with-layouts/chunks/vidstack-DKqYI_HJ.js +0 -1
  86. package/cdn/with-layouts/chunks/vidstack-DLGH9jfs.js +0 -1
  87. package/cdn/with-layouts/chunks/vidstack-DLVdcWrK.js +0 -3
  88. package/cdn/with-layouts/chunks/vidstack-DPO7J4-v.js +0 -3
  89. package/cdn/with-layouts/chunks/vidstack-DWjB11vV.js +0 -1
  90. package/cdn/with-layouts/chunks/vidstack-Dd3L-eQj.js +0 -1
  91. package/cdn/with-layouts/chunks/vidstack-Dh2GOjra.js +0 -1
  92. package/cdn/with-layouts/chunks/vidstack-DhNpv7SU.js +0 -1
  93. package/cdn/with-layouts/chunks/vidstack-QW5tTAS4.js +0 -897
  94. package/cdn/with-layouts/chunks/vidstack-T2rZVigk.js +0 -912
  95. package/cdn/with-layouts/chunks/vidstack-Xe_d7ovA.js +0 -1
  96. package/cdn/with-layouts/chunks/vidstack-wt2OT4N7.js +0 -1
  97. package/cdn/with-layouts/providers/vidstack-audio-Bw1csc6N.js +0 -1
  98. package/cdn/with-layouts/providers/vidstack-audio-CwoQJvl2.js +0 -1
  99. package/cdn/with-layouts/providers/vidstack-dash-CJsKJfLI.js +0 -1
  100. package/cdn/with-layouts/providers/vidstack-dash-DHRMFG4Y.js +0 -1
  101. package/cdn/with-layouts/providers/vidstack-google-cast-BSYJYn-o.js +0 -1
  102. package/cdn/with-layouts/providers/vidstack-hls-DG1rTEqu.js +0 -1
  103. package/cdn/with-layouts/providers/vidstack-hls-ji26kFdQ.js +0 -1
  104. package/cdn/with-layouts/providers/vidstack-html-BvHMxtoe.js +0 -1
  105. package/cdn/with-layouts/providers/vidstack-html-CoKFAYW5.js +0 -1
  106. package/cdn/with-layouts/providers/vidstack-video-1Uj5cNP2.js +0 -1
  107. package/cdn/with-layouts/providers/vidstack-video-CIxFJ9Z1.js +0 -1
  108. package/cdn/with-layouts/providers/vidstack-vimeo-CNLKOGMa.js +0 -1
  109. package/cdn/with-layouts/providers/vidstack-vimeo-DACTbJaQ.js +0 -1
  110. package/cdn/with-layouts/providers/vidstack-youtube-D1e-LE-8.js +0 -1
  111. package/cdn/with-layouts/providers/vidstack-youtube-RoLp-I6u.js +0 -1
  112. package/dev/chunks/vidstack-03oQOdB7.js +0 -58
  113. package/dev/chunks/vidstack-0XhA3AD_.js +0 -5181
  114. package/dev/chunks/vidstack-44ILR0Cb.js +0 -1521
  115. package/dev/chunks/vidstack-B4XOm7dP.js +0 -104
  116. package/dev/chunks/vidstack-BJsZjPkB.js +0 -204
  117. package/dev/chunks/vidstack-BXSB7eI9.js +0 -58
  118. package/dev/chunks/vidstack-BaGbgcvz.js +0 -107
  119. package/dev/chunks/vidstack-Blfm1k-4.js +0 -1520
  120. package/dev/chunks/vidstack-Bo8BNFJ2.js +0 -2986
  121. package/dev/chunks/vidstack-Bs54kFSz.js +0 -66
  122. package/dev/chunks/vidstack-C3N4zIuV.js +0 -254
  123. package/dev/chunks/vidstack-C4aPQ7hZ.js +0 -1482
  124. package/dev/chunks/vidstack-C6OqdJO7.js +0 -114
  125. package/dev/chunks/vidstack-CAL4iu_K.js +0 -1482
  126. package/dev/chunks/vidstack-CEjYxSqZ.js +0 -297
  127. package/dev/chunks/vidstack-CJCnHmKE.js +0 -104
  128. package/dev/chunks/vidstack-CQdFhXSo.js +0 -204
  129. package/dev/chunks/vidstack-CSryZFvY.js +0 -1521
  130. package/dev/chunks/vidstack-C_rvOKWp.js +0 -33
  131. package/dev/chunks/vidstack-CaudO1jl.js +0 -109
  132. package/dev/chunks/vidstack-CcQdBWil.js +0 -58
  133. package/dev/chunks/vidstack-Cky9ors4.js +0 -297
  134. package/dev/chunks/vidstack-DAOcbKGP.js +0 -254
  135. package/dev/chunks/vidstack-DD_3HszA.js +0 -1520
  136. package/dev/chunks/vidstack-DKaohJzR.js +0 -5181
  137. package/dev/chunks/vidstack-DLXCqdYV.js +0 -3010
  138. package/dev/chunks/vidstack-DS7nRfge.js +0 -204
  139. package/dev/chunks/vidstack-DWtK42Sh.js +0 -1483
  140. package/dev/chunks/vidstack-D_LvMxPr.js +0 -204
  141. package/dev/chunks/vidstack-Db1-Hg_U.js +0 -297
  142. package/dev/chunks/vidstack-DrczgsqN.js +0 -297
  143. package/dev/chunks/vidstack-EoLRQZbs.js +0 -2986
  144. package/dev/chunks/vidstack-FKkY62Dr.js +0 -104
  145. package/dev/chunks/vidstack-el2dbO0m.js +0 -5181
  146. package/dev/chunks/vidstack-rvhuswgi.js +0 -2986
  147. package/prod/chunks/vidstack-BAqdCFIm.js +0 -4771
  148. package/prod/chunks/vidstack-BHqGlnGz.js +0 -1482
  149. package/prod/chunks/vidstack-BP49Gz0m.js +0 -58
  150. package/prod/chunks/vidstack-BRZe2BNi.js +0 -107
  151. package/prod/chunks/vidstack-BRnfTkxi.js +0 -297
  152. package/prod/chunks/vidstack-BaaRY-9x.js +0 -201
  153. package/prod/chunks/vidstack-BexQYZop.js +0 -2976
  154. package/prod/chunks/vidstack-BpLd9ASW.js +0 -246
  155. package/prod/chunks/vidstack-C-yd_bAJ.js +0 -4771
  156. package/prod/chunks/vidstack-C05ipjAK.js +0 -1520
  157. package/prod/chunks/vidstack-CA4tDJdF.js +0 -33
  158. package/prod/chunks/vidstack-CFXAYpuh.js +0 -1521
  159. package/prod/chunks/vidstack-CIvL96_j.js +0 -297
  160. package/prod/chunks/vidstack-CYVCrFjx.js +0 -201
  161. package/prod/chunks/vidstack-Cs0fH84E.js +0 -1521
  162. package/prod/chunks/vidstack-D7hJcnN-.js +0 -297
  163. package/prod/chunks/vidstack-DDePVDjt.js +0 -2976
  164. package/prod/chunks/vidstack-DESBVLFp.js +0 -104
  165. package/prod/chunks/vidstack-DMDDSV3t.js +0 -104
  166. package/prod/chunks/vidstack-DXfGRhxZ.js +0 -201
  167. package/prod/chunks/vidstack-D_atbNqH.js +0 -3000
  168. package/prod/chunks/vidstack-DcMkaIHJ.js +0 -2976
  169. package/prod/chunks/vidstack-DnRxQoqP.js +0 -104
  170. package/prod/chunks/vidstack-DwenML7x.js +0 -4771
  171. package/prod/chunks/vidstack-IDWYvfna.js +0 -58
  172. package/prod/chunks/vidstack-Ko2EJadT.js +0 -1483
  173. package/prod/chunks/vidstack-MbEMbVfP.js +0 -109
  174. package/prod/chunks/vidstack-ShUhyBfI.js +0 -201
  175. package/prod/chunks/vidstack-SnIdjCkV.js +0 -58
  176. package/prod/chunks/vidstack-V1jwkH0s.js +0 -66
  177. package/prod/chunks/vidstack-V9U6gsde.js +0 -1482
  178. package/prod/chunks/vidstack-XA3zT5W9.js +0 -297
  179. package/prod/chunks/vidstack-bdt7uOlN.js +0 -114
  180. package/prod/chunks/vidstack-kdaDngIm.js +0 -1520
  181. package/prod/chunks/vidstack-oNEzlviH.js +0 -246
  182. package/server/chunks/vidstack-B2Bc9g7_.js +0 -2000
  183. package/server/chunks/vidstack-B4CWj0Hp.js +0 -381
  184. package/server/chunks/vidstack-B8P1aUCK.js +0 -1503
  185. package/server/chunks/vidstack-B8_v1VQn.js +0 -3059
  186. package/server/chunks/vidstack-BGgfNYAH.js +0 -141
  187. package/server/chunks/vidstack-BGmwlunt.js +0 -3035
  188. package/server/chunks/vidstack-BO8FLks6.js +0 -295
  189. package/server/chunks/vidstack-BosyhF3p.js +0 -207
  190. package/server/chunks/vidstack-C19bj3Wq.js +0 -307
  191. package/server/chunks/vidstack-C8F1EUBn.js +0 -104
  192. package/server/chunks/vidstack-CFTkUXGK.js +0 -295
  193. package/server/chunks/vidstack-CQMB7Msg.js +0 -1502
  194. package/server/chunks/vidstack-CWho6PlG.js +0 -141
  195. package/server/chunks/vidstack-CdBfecZT.js +0 -205
  196. package/server/chunks/vidstack-Cv_Art04.js +0 -4635
  197. package/server/chunks/vidstack-DE4b5Bgx.js +0 -2002
  198. package/server/chunks/vidstack-Db22EuE_.js +0 -207
  199. package/server/chunks/vidstack-DbvCOsqU.js +0 -107
  200. package/server/chunks/vidstack-DgHfFDiw.js +0 -1962
  201. package/server/chunks/vidstack-DhF59-Up.js +0 -4635
  202. package/server/chunks/vidstack-DnkB7eGO.js +0 -207
  203. package/server/chunks/vidstack-DoHmOxNm.js +0 -295
  204. package/server/chunks/vidstack-DsnTqzpL.js +0 -29
  205. package/server/chunks/vidstack-DzWvfg1d.js +0 -1503
  206. package/server/chunks/vidstack-FHGkN5xj.js +0 -566
  207. package/server/chunks/vidstack-PnFpou7g.js +0 -3035
  208. package/server/chunks/vidstack-f5-aflD2.js +0 -104
  209. package/server/chunks/vidstack-gEJMQpTE.js +0 -2001
  210. package/server/chunks/vidstack-n4zAyLEV.js +0 -2139
@@ -1,1520 +0,0 @@
1
- import { Component, State, effect, tick, peek, setAttribute, isString, setStyle, createContext, signal, listenEvent, EventsController, provideContext, onDispose, useContext, prop, useState, isNull, functionThrottle, computed, method, scoped, createScope, animationFrameThrottle, functionDebounce, hasProvidedContext, isNumber, isPointerEvent, isTouchEvent, isMouseEvent, DOMEvent, kebabToCamelCase } from './vidstack-C1PwJD_4.js';
2
- import { useMediaContext } from './vidstack-BjxlZzGu.js';
3
- import { setAttributeIfEmpty, requestScopedAnimationFrame, autoPlacement, $ariaBool, setARIALabel, isTouchPinchEvent } from './vidstack-C0SWkbs7.js';
4
- import { formatSpokenTime, Popper, ToggleButtonController, Slider, SliderController, sliderState, sliderValueFormatContext, TimeSlider, RadioGroupController, menuContext, formatTime } from './vidstack-Bo8BNFJ2.js';
5
- import { FocusVisibleController, $keyboard } from './vidstack-Bur7I7Vy.js';
6
- import { round } from './vidstack-Dihypf8P.js';
7
- import { sortVideoQualities } from './vidstack-BTM4ERc7.js';
8
- import { watchActiveTextTrack, isCueActive } from './vidstack-CcQdBWil.js';
9
- import { isTrackCaptionKind } from './vidstack-C3N4zIuV.js';
10
-
11
- class MediaAnnouncer extends Component {
12
- static props = {
13
- translations: null
14
- };
15
- static state = new State({
16
- label: null,
17
- busy: false
18
- });
19
- #media;
20
- #initializing = false;
21
- onSetup() {
22
- this.#media = useMediaContext();
23
- }
24
- onAttach(el) {
25
- el.style.display = "contents";
26
- }
27
- onConnect(el) {
28
- el.setAttribute("data-media-announcer", "");
29
- setAttributeIfEmpty(el, "role", "status");
30
- setAttributeIfEmpty(el, "aria-live", "polite");
31
- const { busy } = this.$state;
32
- this.setAttributes({
33
- "aria-busy": () => busy() ? "true" : null
34
- });
35
- this.#initializing = true;
36
- effect(this.#watchPaused.bind(this));
37
- effect(this.#watchVolume.bind(this));
38
- effect(this.#watchCaptions.bind(this));
39
- effect(this.#watchFullscreen.bind(this));
40
- effect(this.#watchPiP.bind(this));
41
- effect(this.#watchSeeking.bind(this));
42
- effect(this.#watchLabel.bind(this));
43
- tick();
44
- this.#initializing = false;
45
- }
46
- #watchPaused() {
47
- const { paused } = this.#media.$state;
48
- this.#setLabel(!paused() ? "Play" : "Pause");
49
- }
50
- #watchFullscreen() {
51
- const { fullscreen } = this.#media.$state;
52
- this.#setLabel(fullscreen() ? "Enter Fullscreen" : "Exit Fullscreen");
53
- }
54
- #watchPiP() {
55
- const { pictureInPicture } = this.#media.$state;
56
- this.#setLabel(pictureInPicture() ? "Enter PiP" : "Exit PiP");
57
- }
58
- #watchCaptions() {
59
- const { textTrack } = this.#media.$state;
60
- this.#setLabel(textTrack() ? "Closed-Captions On" : "Closed-Captions Off");
61
- }
62
- #watchVolume() {
63
- const { muted, volume, audioGain } = this.#media.$state;
64
- this.#setLabel(
65
- muted() || volume() === 0 ? "Mute" : `${Math.round(volume() * (audioGain() ?? 1) * 100)}% ${this.#translate("Volume")}`
66
- );
67
- }
68
- #startedSeekingAt = -1;
69
- #seekTimer = -1;
70
- #watchSeeking() {
71
- const { seeking, currentTime } = this.#media.$state, isSeeking = seeking();
72
- if (this.#startedSeekingAt > 0) {
73
- window.clearTimeout(this.#seekTimer);
74
- this.#seekTimer = window.setTimeout(() => {
75
- if (!this.scope) return;
76
- const newTime = peek(currentTime), seconds = Math.abs(newTime - this.#startedSeekingAt);
77
- if (seconds >= 1) {
78
- const isForward = newTime >= this.#startedSeekingAt, spokenTime = formatSpokenTime(seconds);
79
- this.#setLabel(
80
- `${this.#translate(isForward ? "Seek Forward" : "Seek Backward")} ${spokenTime}`
81
- );
82
- }
83
- this.#startedSeekingAt = -1;
84
- this.#seekTimer = -1;
85
- }, 300);
86
- } else if (isSeeking) {
87
- this.#startedSeekingAt = peek(currentTime);
88
- }
89
- }
90
- #translate(word) {
91
- const { translations } = this.$props;
92
- return translations?.()?.[word || ""] ?? word;
93
- }
94
- #watchLabel() {
95
- const { label, busy } = this.$state, $label = this.#translate(label());
96
- if (this.#initializing) return;
97
- busy.set(true);
98
- const id = window.setTimeout(() => void busy.set(false), 150);
99
- this.el && setAttribute(this.el, "aria-label", $label);
100
- if (isString($label)) {
101
- this.dispatch("change", { detail: $label });
102
- }
103
- return () => window.clearTimeout(id);
104
- }
105
- #setLabel(word) {
106
- const { label } = this.$state;
107
- label.set(word);
108
- }
109
- }
110
-
111
- class Controls extends Component {
112
- static props = {
113
- hideDelay: 2e3,
114
- hideOnMouseLeave: false
115
- };
116
- #media;
117
- onSetup() {
118
- this.#media = useMediaContext();
119
- effect(this.#watchProps.bind(this));
120
- }
121
- onAttach(el) {
122
- const { pictureInPicture, fullscreen } = this.#media.$state;
123
- setStyle(el, "pointer-events", "none");
124
- setAttributeIfEmpty(el, "role", "group");
125
- this.setAttributes({
126
- "data-visible": this.#isShowing.bind(this),
127
- "data-fullscreen": fullscreen,
128
- "data-pip": pictureInPicture
129
- });
130
- effect(() => {
131
- this.dispatch("change", { detail: this.#isShowing() });
132
- });
133
- effect(this.#hideControls.bind(this));
134
- effect(() => {
135
- const isFullscreen = fullscreen();
136
- for (const side of ["top", "right", "bottom", "left"]) {
137
- setStyle(el, `padding-${side}`, isFullscreen && `env(safe-area-inset-${side})`);
138
- }
139
- });
140
- }
141
- #hideControls() {
142
- if (!this.el) return;
143
- const { nativeControls } = this.#media.$state, isHidden = nativeControls();
144
- setAttribute(this.el, "aria-hidden", isHidden ? "true" : null);
145
- setStyle(this.el, "display", isHidden ? "none" : null);
146
- }
147
- #watchProps() {
148
- const { controls } = this.#media.player, { hideDelay, hideOnMouseLeave } = this.$props;
149
- controls.defaultDelay = hideDelay() === 2e3 ? this.#media.$props.controlsDelay() : hideDelay();
150
- controls.hideOnMouseLeave = hideOnMouseLeave();
151
- }
152
- #isShowing() {
153
- const { controlsVisible } = this.#media.$state;
154
- return controlsVisible();
155
- }
156
- }
157
-
158
- class ControlsGroup extends Component {
159
- onAttach(el) {
160
- if (!el.style.pointerEvents) setStyle(el, "pointer-events", "auto");
161
- }
162
- }
163
-
164
- const tooltipContext = createContext();
165
-
166
- let id = 0;
167
- class Tooltip extends Component {
168
- static props = {
169
- showDelay: 700
170
- };
171
- #id = `media-tooltip-${++id}`;
172
- #trigger = signal(null);
173
- #content = signal(null);
174
- #showing = signal(false);
175
- constructor() {
176
- super();
177
- new FocusVisibleController();
178
- const { showDelay } = this.$props;
179
- new Popper({
180
- trigger: this.#trigger,
181
- content: this.#content,
182
- showDelay,
183
- listen(trigger, show, hide) {
184
- effect(() => {
185
- if ($keyboard()) listenEvent(trigger, "focus", show);
186
- listenEvent(trigger, "blur", hide);
187
- });
188
- new EventsController(trigger).add("touchstart", (e) => e.preventDefault(), { passive: false }).add("mouseenter", show).add("mouseleave", hide);
189
- },
190
- onChange: this.#onShowingChange.bind(this)
191
- });
192
- }
193
- onAttach(el) {
194
- el.style.setProperty("display", "contents");
195
- }
196
- onSetup() {
197
- provideContext(tooltipContext, {
198
- trigger: this.#trigger,
199
- content: this.#content,
200
- showing: this.#showing,
201
- attachTrigger: this.#attachTrigger.bind(this),
202
- detachTrigger: this.#detachTrigger.bind(this),
203
- attachContent: this.#attachContent.bind(this),
204
- detachContent: this.#detachContent.bind(this)
205
- });
206
- }
207
- #attachTrigger(el) {
208
- this.#trigger.set(el);
209
- let tooltipName = el.getAttribute("data-media-tooltip");
210
- if (tooltipName) {
211
- this.el?.setAttribute(`data-media-${tooltipName}-tooltip`, "");
212
- }
213
- setAttribute(el, "data-describedby", this.#id);
214
- }
215
- #detachTrigger(el) {
216
- el.removeAttribute("data-describedby");
217
- el.removeAttribute("aria-describedby");
218
- this.#trigger.set(null);
219
- }
220
- #attachContent(el) {
221
- el.setAttribute("id", this.#id);
222
- el.style.display = "none";
223
- setAttributeIfEmpty(el, "role", "tooltip");
224
- this.#content.set(el);
225
- }
226
- #detachContent(el) {
227
- el.removeAttribute("id");
228
- el.removeAttribute("role");
229
- this.#content.set(null);
230
- }
231
- #onShowingChange(isShowing) {
232
- const trigger = this.#trigger(), content = this.#content();
233
- if (trigger) {
234
- setAttribute(trigger, "aria-describedby", isShowing ? this.#id : null);
235
- }
236
- for (const el of [this.el, trigger, content]) {
237
- el && setAttribute(el, "data-visible", isShowing);
238
- }
239
- this.#showing.set(isShowing);
240
- }
241
- }
242
-
243
- class TooltipTrigger extends Component {
244
- constructor() {
245
- super();
246
- new FocusVisibleController();
247
- }
248
- onConnect(el) {
249
- onDispose(
250
- requestScopedAnimationFrame(() => {
251
- if (!this.connectScope) return;
252
- this.#attach();
253
- const tooltip = useContext(tooltipContext);
254
- onDispose(() => {
255
- const button = this.#getButton();
256
- button && tooltip.detachTrigger(button);
257
- });
258
- })
259
- );
260
- }
261
- #attach() {
262
- const button = this.#getButton(), tooltip = useContext(tooltipContext);
263
- button && tooltip.attachTrigger(button);
264
- }
265
- #getButton() {
266
- const candidate = this.el.firstElementChild;
267
- return candidate?.localName === "button" || candidate?.getAttribute("role") === "button" ? candidate : this.el;
268
- }
269
- }
270
-
271
- class TooltipContent extends Component {
272
- static props = {
273
- placement: "top center",
274
- offset: 0,
275
- alignOffset: 0
276
- };
277
- constructor() {
278
- super();
279
- new FocusVisibleController();
280
- const { placement } = this.$props;
281
- this.setAttributes({
282
- "data-placement": placement
283
- });
284
- }
285
- onAttach(el) {
286
- this.#attach(el);
287
- Object.assign(el.style, {
288
- position: "absolute",
289
- top: 0,
290
- left: 0,
291
- width: "max-content"
292
- });
293
- }
294
- onConnect(el) {
295
- this.#attach(el);
296
- const tooltip = useContext(tooltipContext);
297
- onDispose(() => tooltip.detachContent(el));
298
- onDispose(
299
- requestScopedAnimationFrame(() => {
300
- if (!this.connectScope) return;
301
- effect(this.#watchPlacement.bind(this));
302
- })
303
- );
304
- }
305
- #attach(el) {
306
- const tooltip = useContext(tooltipContext);
307
- tooltip.attachContent(el);
308
- }
309
- #watchPlacement() {
310
- const { showing } = useContext(tooltipContext);
311
- if (!showing()) return;
312
- const { placement, offset: mainOffset, alignOffset } = this.$props;
313
- return autoPlacement(this.el, this.#getTrigger(), placement(), {
314
- offsetVarName: "media-tooltip",
315
- xOffset: alignOffset(),
316
- yOffset: mainOffset()
317
- });
318
- }
319
- #getTrigger() {
320
- return useContext(tooltipContext).trigger();
321
- }
322
- }
323
-
324
- class ToggleButton extends Component {
325
- static props = {
326
- disabled: false,
327
- defaultPressed: false
328
- };
329
- #pressed = signal(false);
330
- /**
331
- * Whether the toggle is currently in a `pressed` state.
332
- */
333
- get pressed() {
334
- return this.#pressed();
335
- }
336
- constructor() {
337
- super();
338
- new ToggleButtonController({
339
- isPresssed: this.#pressed
340
- });
341
- }
342
- }
343
- const togglebutton__proto = ToggleButton.prototype;
344
- prop(togglebutton__proto, "pressed");
345
-
346
- class GoogleCastButton extends Component {
347
- static props = ToggleButtonController.props;
348
- #media;
349
- constructor() {
350
- super();
351
- new ToggleButtonController({
352
- isPresssed: this.#isPressed.bind(this),
353
- onPress: this.#onPress.bind(this)
354
- });
355
- }
356
- onSetup() {
357
- this.#media = useMediaContext();
358
- const { canGoogleCast, isGoogleCastConnected } = this.#media.$state;
359
- this.setAttributes({
360
- "data-active": isGoogleCastConnected,
361
- "data-supported": canGoogleCast,
362
- "data-state": this.#getState.bind(this),
363
- "aria-hidden": $ariaBool(() => !canGoogleCast())
364
- });
365
- }
366
- onAttach(el) {
367
- el.setAttribute("data-media-tooltip", "google-cast");
368
- setARIALabel(el, this.#getDefaultLabel.bind(this));
369
- }
370
- #onPress(event) {
371
- const remote = this.#media.remote;
372
- remote.requestGoogleCast(event);
373
- }
374
- #isPressed() {
375
- const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
376
- return remotePlaybackType() === "google-cast" && remotePlaybackState() !== "disconnected";
377
- }
378
- #getState() {
379
- const { remotePlaybackType, remotePlaybackState } = this.#media.$state;
380
- return remotePlaybackType() === "google-cast" && remotePlaybackState();
381
- }
382
- #getDefaultLabel() {
383
- const { remotePlaybackState } = this.#media.$state;
384
- return `Google Cast ${remotePlaybackState()}`;
385
- }
386
- }
387
-
388
- class SliderVideo extends Component {
389
- static props = {
390
- src: null,
391
- crossOrigin: null
392
- };
393
- static state = new State({
394
- video: null,
395
- src: null,
396
- crossOrigin: null,
397
- canPlay: false,
398
- error: null,
399
- hidden: false
400
- });
401
- #media;
402
- #slider;
403
- get video() {
404
- return this.$state.video();
405
- }
406
- onSetup() {
407
- this.#media = useMediaContext();
408
- this.#slider = useState(Slider.state);
409
- this.#watchCrossOrigin();
410
- this.setAttributes({
411
- "data-loading": this.#isLoading.bind(this),
412
- "data-hidden": this.$state.hidden,
413
- "data-error": this.#hasError.bind(this),
414
- "aria-hidden": $ariaBool(this.$state.hidden)
415
- });
416
- }
417
- onAttach(el) {
418
- effect(this.#watchVideo.bind(this));
419
- effect(this.#watchSrc.bind(this));
420
- effect(this.#watchCrossOrigin.bind(this));
421
- effect(this.#watchHidden.bind(this));
422
- effect(this.#onSrcChange.bind(this));
423
- effect(this.#onUpdateTime.bind(this));
424
- }
425
- #watchVideo() {
426
- const video = this.$state.video();
427
- if (!video) return;
428
- if (video.readyState >= 2) this.#onCanPlay();
429
- new EventsController(video).add("canplay", this.#onCanPlay.bind(this)).add("error", this.#onError.bind(this));
430
- }
431
- #watchSrc() {
432
- const { src } = this.$state, { canLoad } = this.#media.$state;
433
- src.set(canLoad() ? this.$props.src() : null);
434
- }
435
- #watchCrossOrigin() {
436
- const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin } = this.#media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
437
- crossOriginState.set(crossOrigin === true ? "anonymous" : crossOrigin);
438
- }
439
- #isLoading() {
440
- const { canPlay, hidden } = this.$state;
441
- return !canPlay() && !hidden();
442
- }
443
- #hasError() {
444
- const { error } = this.$state;
445
- return !isNull(error);
446
- }
447
- #watchHidden() {
448
- const { src, hidden } = this.$state, { canLoad, duration } = this.#media.$state;
449
- hidden.set(canLoad() && (!src() || this.#hasError() || !Number.isFinite(duration())));
450
- }
451
- #onSrcChange() {
452
- const { src, canPlay, error } = this.$state;
453
- src();
454
- canPlay.set(false);
455
- error.set(null);
456
- }
457
- #onCanPlay(event) {
458
- const { canPlay, error } = this.$state;
459
- canPlay.set(true);
460
- error.set(null);
461
- this.dispatch("can-play", { trigger: event });
462
- }
463
- #onError(event) {
464
- const { canPlay, error } = this.$state;
465
- canPlay.set(false);
466
- error.set(event);
467
- this.dispatch("error", { trigger: event });
468
- }
469
- #onUpdateTime() {
470
- const { video, canPlay } = this.$state, { duration } = this.#media.$state, { pointerRate } = this.#slider, media = video(), canUpdate = canPlay() && media && Number.isFinite(duration()) && Number.isFinite(pointerRate());
471
- if (canUpdate) {
472
- media.currentTime = pointerRate() * duration();
473
- }
474
- }
475
- }
476
- const slidervideo__proto = SliderVideo.prototype;
477
- prop(slidervideo__proto, "video");
478
-
479
- class AudioGainSlider extends Component {
480
- static props = {
481
- ...SliderController.props,
482
- step: 25,
483
- keyStep: 25,
484
- shiftKeyMultiplier: 2,
485
- min: 0,
486
- max: 300
487
- };
488
- static state = sliderState;
489
- #media;
490
- onSetup() {
491
- this.#media = useMediaContext();
492
- provideContext(sliderValueFormatContext, {
493
- default: "percent",
494
- percent: (_, decimalPlaces) => {
495
- return round(this.$state.value(), decimalPlaces) + "%";
496
- }
497
- });
498
- new SliderController({
499
- getStep: this.$props.step,
500
- getKeyStep: this.$props.keyStep,
501
- roundValue: Math.round,
502
- isDisabled: this.#isDisabled.bind(this),
503
- aria: {
504
- valueNow: this.#getARIAValueNow.bind(this),
505
- valueText: this.#getARIAValueText.bind(this)
506
- },
507
- onDragValueChange: this.#onDragValueChange.bind(this),
508
- onValueChange: this.#onValueChange.bind(this)
509
- }).attach(this);
510
- effect(this.#watchMinMax.bind(this));
511
- effect(this.#watchAudioGain.bind(this));
512
- }
513
- onAttach(el) {
514
- el.setAttribute("data-media-audio-gain-slider", "");
515
- setAttributeIfEmpty(el, "aria-label", "Audio Boost");
516
- const { canSetAudioGain } = this.#media.$state;
517
- this.setAttributes({
518
- "data-supported": canSetAudioGain,
519
- "aria-hidden": $ariaBool(() => !canSetAudioGain())
520
- });
521
- }
522
- #getARIAValueNow() {
523
- const { value } = this.$state;
524
- return Math.round(value());
525
- }
526
- #getARIAValueText() {
527
- const { value } = this.$state;
528
- return value() + "%";
529
- }
530
- #watchMinMax() {
531
- const { min, max } = this.$props;
532
- this.$state.min.set(min());
533
- this.$state.max.set(max());
534
- }
535
- #watchAudioGain() {
536
- const { audioGain } = this.#media.$state, value = ((audioGain() ?? 1) - 1) * 100;
537
- this.$state.value.set(value);
538
- this.dispatch("value-change", { detail: value });
539
- }
540
- #isDisabled() {
541
- const { disabled } = this.$props, { canSetAudioGain } = this.#media.$state;
542
- return disabled() || !canSetAudioGain();
543
- }
544
- #onAudioGainChange(event) {
545
- if (!event.trigger) return;
546
- const gain = round(1 + event.detail / 100, 2);
547
- this.#media.remote.changeAudioGain(gain, event);
548
- }
549
- #onValueChange(event) {
550
- this.#onAudioGainChange(event);
551
- }
552
- #onDragValueChange(event) {
553
- this.#onAudioGainChange(event);
554
- }
555
- }
556
-
557
- class SpeedSlider extends Component {
558
- static props = {
559
- ...SliderController.props,
560
- step: 0.25,
561
- keyStep: 0.25,
562
- shiftKeyMultiplier: 2,
563
- min: 0,
564
- max: 2
565
- };
566
- static state = sliderState;
567
- #media;
568
- onSetup() {
569
- this.#media = useMediaContext();
570
- new SliderController({
571
- getStep: this.$props.step,
572
- getKeyStep: this.$props.keyStep,
573
- roundValue: this.#roundValue,
574
- isDisabled: this.#isDisabled.bind(this),
575
- aria: {
576
- valueNow: this.#getARIAValueNow.bind(this),
577
- valueText: this.#getARIAValueText.bind(this)
578
- },
579
- onDragValueChange: this.#onDragValueChange.bind(this),
580
- onValueChange: this.#onValueChange.bind(this)
581
- }).attach(this);
582
- effect(this.#watchMinMax.bind(this));
583
- effect(this.#watchPlaybackRate.bind(this));
584
- }
585
- onAttach(el) {
586
- el.setAttribute("data-media-speed-slider", "");
587
- setAttributeIfEmpty(el, "aria-label", "Speed");
588
- const { canSetPlaybackRate } = this.#media.$state;
589
- this.setAttributes({
590
- "data-supported": canSetPlaybackRate,
591
- "aria-hidden": $ariaBool(() => !canSetPlaybackRate())
592
- });
593
- }
594
- #getARIAValueNow() {
595
- const { value } = this.$state;
596
- return value();
597
- }
598
- #getARIAValueText() {
599
- const { value } = this.$state;
600
- return value() + "x";
601
- }
602
- #watchMinMax() {
603
- const { min, max } = this.$props;
604
- this.$state.min.set(min());
605
- this.$state.max.set(max());
606
- }
607
- #watchPlaybackRate() {
608
- const { playbackRate } = this.#media.$state;
609
- const newValue = playbackRate();
610
- this.$state.value.set(newValue);
611
- this.dispatch("value-change", { detail: newValue });
612
- }
613
- #roundValue(value) {
614
- return round(value, 2);
615
- }
616
- #isDisabled() {
617
- const { disabled } = this.$props, { canSetPlaybackRate } = this.#media.$state;
618
- return disabled() || !canSetPlaybackRate();
619
- }
620
- #throttledSpeedChange = functionThrottle(this.#onPlaybackRateChange.bind(this), 25);
621
- #onPlaybackRateChange(event) {
622
- if (!event.trigger) return;
623
- const rate = event.detail;
624
- this.#media.remote.changePlaybackRate(rate, event);
625
- }
626
- #onValueChange(event) {
627
- this.#throttledSpeedChange(event);
628
- }
629
- #onDragValueChange(event) {
630
- this.#throttledSpeedChange(event);
631
- }
632
- }
633
-
634
- class QualitySlider extends Component {
635
- static props = {
636
- ...SliderController.props,
637
- step: 1,
638
- keyStep: 1,
639
- shiftKeyMultiplier: 1
640
- };
641
- static state = sliderState;
642
- #media;
643
- #sortedQualities = computed(() => {
644
- const { qualities } = this.#media.$state;
645
- return sortVideoQualities(qualities());
646
- });
647
- onSetup() {
648
- this.#media = useMediaContext();
649
- new SliderController({
650
- getStep: this.$props.step,
651
- getKeyStep: this.$props.keyStep,
652
- roundValue: Math.round,
653
- isDisabled: this.#isDisabled.bind(this),
654
- aria: {
655
- valueNow: this.#getARIAValueNow.bind(this),
656
- valueText: this.#getARIAValueText.bind(this)
657
- },
658
- onDragValueChange: this.#onDragValueChange.bind(this),
659
- onValueChange: this.#onValueChange.bind(this)
660
- }).attach(this);
661
- effect(this.#watchMax.bind(this));
662
- effect(this.#watchQuality.bind(this));
663
- }
664
- onAttach(el) {
665
- el.setAttribute("data-media-quality-slider", "");
666
- setAttributeIfEmpty(el, "aria-label", "Video Quality");
667
- const { qualities, canSetQuality } = this.#media.$state, $supported = computed(() => canSetQuality() && qualities().length > 0);
668
- this.setAttributes({
669
- "data-supported": $supported,
670
- "aria-hidden": $ariaBool(() => !$supported())
671
- });
672
- }
673
- #getARIAValueNow() {
674
- const { value } = this.$state;
675
- return value();
676
- }
677
- #getARIAValueText() {
678
- const { quality } = this.#media.$state;
679
- if (!quality()) return "";
680
- const { height, bitrate } = quality(), bitrateText = bitrate && bitrate > 0 ? `${(bitrate / 1e6).toFixed(2)} Mbps` : null;
681
- return height ? `${height}p${bitrateText ? ` (${bitrateText})` : ""}` : "Auto";
682
- }
683
- #watchMax() {
684
- const $qualities = this.#sortedQualities();
685
- this.$state.max.set(Math.max(0, $qualities.length - 1));
686
- }
687
- #watchQuality() {
688
- let { quality } = this.#media.$state, $qualities = this.#sortedQualities(), value = Math.max(0, $qualities.indexOf(quality()));
689
- this.$state.value.set(value);
690
- this.dispatch("value-change", { detail: value });
691
- }
692
- #isDisabled() {
693
- const { disabled } = this.$props, { canSetQuality, qualities } = this.#media.$state;
694
- return disabled() || qualities().length <= 1 || !canSetQuality();
695
- }
696
- #throttledQualityChange = functionThrottle(this.#onQualityChange.bind(this), 25);
697
- #onQualityChange(event) {
698
- if (!event.trigger) return;
699
- const { qualities } = this.#media, quality = peek(this.#sortedQualities)[event.detail];
700
- this.#media.remote.changeQuality(qualities.indexOf(quality), event);
701
- }
702
- #onValueChange(event) {
703
- this.#throttledQualityChange(event);
704
- }
705
- #onDragValueChange(event) {
706
- this.#throttledQualityChange(event);
707
- }
708
- }
709
-
710
- class SliderChapters extends Component {
711
- static props = {
712
- disabled: false
713
- };
714
- #media;
715
- #sliderState;
716
- #updateScope;
717
- #titleRef = null;
718
- #refs = [];
719
- #$track = signal(null);
720
- #$cues = signal([]);
721
- #activeIndex = signal(-1);
722
- #activePointerIndex = signal(-1);
723
- #bufferedIndex = 0;
724
- get cues() {
725
- return this.#$cues();
726
- }
727
- get activeCue() {
728
- return this.#$cues()[this.#activeIndex()] || null;
729
- }
730
- get activePointerCue() {
731
- return this.#$cues()[this.#activePointerIndex()] || null;
732
- }
733
- onSetup() {
734
- this.#media = useMediaContext();
735
- this.#sliderState = useState(TimeSlider.state);
736
- }
737
- onAttach(el) {
738
- watchActiveTextTrack(this.#media.textTracks, "chapters", this.#setTrack.bind(this));
739
- effect(this.#watchSource.bind(this));
740
- }
741
- onConnect() {
742
- onDispose(() => this.#reset.bind(this));
743
- }
744
- onDestroy() {
745
- this.#setTrack(null);
746
- }
747
- setRefs(refs) {
748
- this.#refs = refs;
749
- this.#updateScope?.dispose();
750
- if (this.#refs.length === 1) {
751
- const el = this.#refs[0];
752
- el.style.width = "100%";
753
- el.style.setProperty("--chapter-fill", "var(--slider-fill)");
754
- el.style.setProperty("--chapter-progress", "var(--slider-progress)");
755
- } else if (this.#refs.length > 0) {
756
- scoped(() => this.#watch(), this.#updateScope = createScope());
757
- }
758
- }
759
- #setTrack(track) {
760
- if (peek(this.#$track) === track) return;
761
- this.#reset();
762
- this.#$track.set(track);
763
- }
764
- #reset() {
765
- this.#refs = [];
766
- this.#$cues.set([]);
767
- this.#activeIndex.set(-1);
768
- this.#activePointerIndex.set(-1);
769
- this.#bufferedIndex = 0;
770
- this.#updateScope?.dispose();
771
- }
772
- #watch() {
773
- if (!this.#refs.length) return;
774
- effect(this.#watchUpdates.bind(this));
775
- }
776
- #watchUpdates() {
777
- const { hidden } = this.#sliderState;
778
- if (hidden()) return;
779
- effect(this.#watchContainerWidths.bind(this));
780
- effect(this.#watchFillPercent.bind(this));
781
- effect(this.#watchPointerPercent.bind(this));
782
- effect(this.#watchBufferedPercent.bind(this));
783
- }
784
- #watchContainerWidths() {
785
- const cues = this.#$cues();
786
- if (!cues.length) return;
787
- let cue, { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd() || cues[cues.length - 1].endTime, duration = endTime - startTime, remainingWidth = 100;
788
- for (let i = 0; i < cues.length; i++) {
789
- cue = cues[i];
790
- if (this.#refs[i]) {
791
- const width = i === cues.length - 1 ? remainingWidth : round((cue.endTime - Math.max(startTime, cue.startTime)) / duration * 100, 3);
792
- this.#refs[i].style.width = width + "%";
793
- remainingWidth -= width;
794
- }
795
- }
796
- }
797
- #watchFillPercent() {
798
- let { liveEdge, seekableStart, seekableEnd } = this.#media.$state, { fillPercent, value } = this.#sliderState, cues = this.#$cues(), isLiveEdge = liveEdge(), prevActiveIndex = peek(this.#activeIndex), currentChapter = cues[prevActiveIndex];
799
- let currentActiveIndex = isLiveEdge ? this.#$cues.length - 1 : this.#findActiveChapterIndex(
800
- currentChapter ? currentChapter.startTime / seekableEnd() * 100 <= peek(value) ? prevActiveIndex : 0 : 0,
801
- fillPercent()
802
- );
803
- if (isLiveEdge || !currentChapter) {
804
- this.#updateFillPercents(0, cues.length, 100);
805
- } else if (currentActiveIndex > prevActiveIndex) {
806
- this.#updateFillPercents(prevActiveIndex, currentActiveIndex, 100);
807
- } else if (currentActiveIndex < prevActiveIndex) {
808
- this.#updateFillPercents(currentActiveIndex + 1, prevActiveIndex + 1, 0);
809
- }
810
- const percent = isLiveEdge ? 100 : this.#calcPercent(
811
- cues[currentActiveIndex],
812
- fillPercent(),
813
- seekableStart(),
814
- this.#getEndTime(cues)
815
- );
816
- this.#updateFillPercent(this.#refs[currentActiveIndex], percent);
817
- this.#activeIndex.set(currentActiveIndex);
818
- }
819
- #watchPointerPercent() {
820
- let { hidden, pointerPercent } = this.#sliderState;
821
- if (hidden()) {
822
- this.#activePointerIndex.set(-1);
823
- return;
824
- }
825
- const activeIndex = this.#findActiveChapterIndex(0, pointerPercent());
826
- this.#activePointerIndex.set(activeIndex);
827
- }
828
- #updateFillPercents(start, end, percent) {
829
- for (let i = start; i < end; i++) this.#updateFillPercent(this.#refs[i], percent);
830
- }
831
- #updateFillPercent(ref, percent) {
832
- if (!ref) return;
833
- ref.style.setProperty("--chapter-fill", percent + "%");
834
- setAttribute(ref, "data-active", percent > 0 && percent < 100);
835
- setAttribute(ref, "data-ended", percent === 100);
836
- }
837
- #findActiveChapterIndex(startIndex, percent) {
838
- let chapterPercent = 0, cues = this.#$cues();
839
- if (percent === 0) return 0;
840
- else if (percent === 100) return cues.length - 1;
841
- let { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
842
- for (let i = startIndex; i < cues.length; i++) {
843
- chapterPercent = this.#calcPercent(cues[i], percent, startTime, endTime);
844
- if (chapterPercent >= 0 && chapterPercent < 100) return i;
845
- }
846
- return 0;
847
- }
848
- #watchBufferedPercent() {
849
- this.#updateBufferedPercent(this.#bufferedPercent());
850
- }
851
- #updateBufferedPercent = animationFrameThrottle((bufferedPercent) => {
852
- let percent, cues = this.#$cues(), { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
853
- for (let i = this.#bufferedIndex; i < this.#refs.length; i++) {
854
- percent = this.#calcPercent(cues[i], bufferedPercent, startTime, endTime);
855
- this.#refs[i]?.style.setProperty("--chapter-progress", percent + "%");
856
- if (percent < 100) {
857
- this.#bufferedIndex = i;
858
- break;
859
- }
860
- }
861
- });
862
- #bufferedPercent = computed(this.#calcMediaBufferedPercent.bind(this));
863
- #calcMediaBufferedPercent() {
864
- const { bufferedEnd, duration } = this.#media.$state;
865
- return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1), 3) * 100;
866
- }
867
- #getEndTime(cues) {
868
- const { seekableEnd } = this.#media.$state, endTime = seekableEnd();
869
- return Number.isFinite(endTime) ? endTime : cues[cues.length - 1]?.endTime || 0;
870
- }
871
- #calcPercent(cue, percent, startTime, endTime) {
872
- if (!cue) return 0;
873
- const cues = this.#$cues();
874
- if (cues.length === 0) return 0;
875
- const duration = endTime - startTime, cueStartTime = Math.max(0, cue.startTime - startTime), cueEndTime = Math.min(endTime, cue.endTime) - startTime;
876
- const startRatio = cueStartTime / duration, startPercent = startRatio * 100, endPercent = Math.min(1, startRatio + (cueEndTime - cueStartTime) / duration) * 100;
877
- return Math.max(
878
- 0,
879
- round(
880
- percent >= endPercent ? 100 : (percent - startPercent) / (endPercent - startPercent) * 100,
881
- 3
882
- )
883
- );
884
- }
885
- #fillGaps(cues) {
886
- let chapters = [], { seekableStart, seekableEnd, duration } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
887
- cues = cues.filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime);
888
- const firstCue = cues[0];
889
- if (firstCue && firstCue.startTime > startTime) {
890
- chapters.push(new window.VTTCue(startTime, firstCue.startTime, ""));
891
- }
892
- for (let i = 0; i < cues.length - 1; i++) {
893
- const currentCue = cues[i], nextCue = cues[i + 1];
894
- chapters.push(currentCue);
895
- if (nextCue) {
896
- const timeDiff = nextCue.startTime - currentCue.endTime;
897
- if (timeDiff > 0) {
898
- chapters.push(new window.VTTCue(currentCue.endTime, currentCue.endTime + timeDiff, ""));
899
- }
900
- }
901
- }
902
- const lastCue = cues[cues.length - 1];
903
- if (lastCue) {
904
- chapters.push(lastCue);
905
- const endTime2 = duration();
906
- if (endTime2 >= 0 && endTime2 - lastCue.endTime > 1) {
907
- chapters.push(new window.VTTCue(lastCue.endTime, duration(), ""));
908
- }
909
- }
910
- return chapters;
911
- }
912
- #watchSource() {
913
- const { source } = this.#media.$state;
914
- source();
915
- this.#onTrackChange();
916
- }
917
- #onTrackChange() {
918
- if (!this.scope) return;
919
- const { disabled } = this.$props;
920
- if (disabled()) {
921
- this.#$cues.set([]);
922
- this.#activeIndex.set(0);
923
- this.#bufferedIndex = 0;
924
- return;
925
- }
926
- const track = this.#$track();
927
- if (track) {
928
- const onCuesChange = this.#onCuesChange.bind(this);
929
- onCuesChange();
930
- new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
931
- effect(this.#watchMediaDuration.bind(this));
932
- }
933
- this.#titleRef = this.#findChapterTitleRef();
934
- if (this.#titleRef) effect(this.#onChapterTitleChange.bind(this));
935
- return () => {
936
- if (this.#titleRef) {
937
- this.#titleRef.textContent = "";
938
- this.#titleRef = null;
939
- }
940
- };
941
- }
942
- #watchMediaDuration() {
943
- this.#media.$state.duration();
944
- this.#onCuesChange();
945
- }
946
- #onCuesChange = functionDebounce(
947
- () => {
948
- const track = peek(this.#$track);
949
- if (!this.scope || !track || !track.cues.length) return;
950
- this.#$cues.set(this.#fillGaps(track.cues));
951
- this.#activeIndex.set(0);
952
- this.#bufferedIndex = 0;
953
- },
954
- 150,
955
- true
956
- );
957
- #onChapterTitleChange() {
958
- const cue = this.activePointerCue || this.activeCue;
959
- if (this.#titleRef) this.#titleRef.textContent = cue?.text || "";
960
- }
961
- #findParentSlider() {
962
- let node = this.el;
963
- while (node && node.getAttribute("role") !== "slider") {
964
- node = node.parentElement;
965
- }
966
- return node;
967
- }
968
- #findChapterTitleRef() {
969
- const slider = this.#findParentSlider();
970
- return slider ? slider.querySelector('[data-part="chapter-title"]') : null;
971
- }
972
- }
973
- const sliderchapters__proto = SliderChapters.prototype;
974
- prop(sliderchapters__proto, "cues");
975
- prop(sliderchapters__proto, "activeCue");
976
- prop(sliderchapters__proto, "activePointerCue");
977
- method(sliderchapters__proto, "setRefs");
978
-
979
- class RadioGroup extends Component {
980
- static props = {
981
- value: ""
982
- };
983
- #controller;
984
- /**
985
- * A list of radio values that belong this group.
986
- */
987
- get values() {
988
- return this.#controller.values;
989
- }
990
- /**
991
- * The radio value that is checked in this group.
992
- */
993
- get value() {
994
- return this.#controller.value;
995
- }
996
- set value(newValue) {
997
- this.#controller.value = newValue;
998
- }
999
- constructor() {
1000
- super();
1001
- this.#controller = new RadioGroupController();
1002
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1003
- }
1004
- onSetup() {
1005
- effect(this.#watchValue.bind(this));
1006
- }
1007
- #watchValue() {
1008
- this.#controller.value = this.$props.value();
1009
- }
1010
- #onValueChange(value, trigger) {
1011
- const event = this.createEvent("change", { detail: value, trigger });
1012
- this.dispatch(event);
1013
- }
1014
- }
1015
- const radiogroup__proto = RadioGroup.prototype;
1016
- prop(radiogroup__proto, "values");
1017
- prop(radiogroup__proto, "value");
1018
-
1019
- var __defProp = Object.defineProperty;
1020
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1021
- var __decorateClass = (decorators, target, key, kind) => {
1022
- var result = __getOwnPropDesc(target, key) ;
1023
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1024
- if (decorator = decorators[i])
1025
- result = (decorator(target, key, result) ) || result;
1026
- if (result) __defProp(target, key, result);
1027
- return result;
1028
- };
1029
- class ChaptersRadioGroup extends Component {
1030
- static props = {
1031
- thumbnails: null
1032
- };
1033
- #media;
1034
- #menu;
1035
- #controller;
1036
- #track = signal(null);
1037
- #cues = signal([]);
1038
- get value() {
1039
- return this.#controller.value;
1040
- }
1041
- get disabled() {
1042
- return !this.#cues()?.length;
1043
- }
1044
- constructor() {
1045
- super();
1046
- this.#controller = new RadioGroupController();
1047
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1048
- }
1049
- onSetup() {
1050
- this.#media = useMediaContext();
1051
- if (hasProvidedContext(menuContext)) {
1052
- this.#menu = useContext(menuContext);
1053
- }
1054
- const { thumbnails } = this.$props;
1055
- this.setAttributes({
1056
- "data-thumbnails": () => !!thumbnails()
1057
- });
1058
- }
1059
- onAttach(el) {
1060
- this.#menu?.attachObserver({
1061
- onOpen: this.#onOpen.bind(this)
1062
- });
1063
- }
1064
- getOptions() {
1065
- const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1066
- return this.#cues().map((cue, i) => ({
1067
- cue,
1068
- value: i.toString(),
1069
- label: cue.text,
1070
- startTime: formatTime(Math.max(0, cue.startTime - startTime)),
1071
- duration: formatSpokenTime(
1072
- Math.min(endTime, cue.endTime) - Math.max(startTime, cue.startTime)
1073
- )
1074
- }));
1075
- }
1076
- #onOpen() {
1077
- peek(() => this.#watchCurrentTime());
1078
- }
1079
- onConnect(el) {
1080
- effect(this.#watchCurrentTime.bind(this));
1081
- effect(this.#watchControllerDisabled.bind(this));
1082
- effect(this.#watchTrack.bind(this));
1083
- watchActiveTextTrack(this.#media.textTracks, "chapters", this.#track.set);
1084
- }
1085
- #watchTrack() {
1086
- const track = this.#track();
1087
- if (!track) return;
1088
- const onCuesChange = this.#onCuesChange.bind(this, track);
1089
- onCuesChange();
1090
- new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
1091
- return () => {
1092
- this.#cues.set([]);
1093
- };
1094
- }
1095
- #onCuesChange(track) {
1096
- const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1097
- this.#cues.set(
1098
- [...track.cues].filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime)
1099
- );
1100
- }
1101
- #watchCurrentTime() {
1102
- if (!this.#menu?.expanded()) return;
1103
- const track = this.#track();
1104
- if (!track) {
1105
- this.#controller.value = "-1";
1106
- return;
1107
- }
1108
- const { realCurrentTime, seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd(), time = realCurrentTime(), activeCueIndex = this.#cues().findIndex((cue) => isCueActive(cue, time));
1109
- this.#controller.value = activeCueIndex.toString();
1110
- if (activeCueIndex >= 0) {
1111
- requestScopedAnimationFrame(() => {
1112
- if (!this.connectScope) return;
1113
- const cue = this.#cues()[activeCueIndex], radio = this.el.querySelector(`[aria-checked='true']`), cueStartTime = Math.max(startTime, cue.startTime), duration = Math.min(endTime, cue.endTime) - cueStartTime, playedPercent = Math.max(0, time - cueStartTime) / duration * 100;
1114
- radio && setStyle(radio, "--progress", round(playedPercent, 3) + "%");
1115
- });
1116
- }
1117
- }
1118
- #watchControllerDisabled() {
1119
- this.#menu?.disable(this.disabled);
1120
- }
1121
- #onValueChange(value, trigger) {
1122
- if (this.disabled || !trigger) return;
1123
- const index = +value, cues = this.#cues(), { clipStartTime } = this.#media.$state;
1124
- if (isNumber(index) && cues?.[index]) {
1125
- this.#controller.value = index.toString();
1126
- this.#media.remote.seek(cues[index].startTime - clipStartTime(), trigger);
1127
- this.dispatch("change", { detail: cues[index], trigger });
1128
- }
1129
- }
1130
- }
1131
- __decorateClass([
1132
- prop
1133
- ], ChaptersRadioGroup.prototype, "value");
1134
- __decorateClass([
1135
- prop
1136
- ], ChaptersRadioGroup.prototype, "disabled");
1137
- __decorateClass([
1138
- method
1139
- ], ChaptersRadioGroup.prototype, "getOptions");
1140
-
1141
- const DEFAULT_AUDIO_GAINS = [1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4];
1142
- class AudioGainRadioGroup extends Component {
1143
- static props = {
1144
- normalLabel: "Disabled",
1145
- gains: DEFAULT_AUDIO_GAINS
1146
- };
1147
- #media;
1148
- #menu;
1149
- #controller;
1150
- get value() {
1151
- return this.#controller.value;
1152
- }
1153
- get disabled() {
1154
- const { gains } = this.$props, { canSetAudioGain } = this.#media.$state;
1155
- return !canSetAudioGain() || gains().length === 0;
1156
- }
1157
- constructor() {
1158
- super();
1159
- this.#controller = new RadioGroupController();
1160
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1161
- }
1162
- onSetup() {
1163
- this.#media = useMediaContext();
1164
- if (hasProvidedContext(menuContext)) {
1165
- this.#menu = useContext(menuContext);
1166
- }
1167
- }
1168
- onConnect(el) {
1169
- effect(this.#watchValue.bind(this));
1170
- effect(this.#watchHintText.bind(this));
1171
- effect(this.#watchControllerDisabled.bind(this));
1172
- }
1173
- getOptions() {
1174
- const { gains, normalLabel } = this.$props;
1175
- return gains().map((gain) => ({
1176
- label: gain === 1 || gain === null ? normalLabel : String(gain * 100) + "%",
1177
- value: gain.toString()
1178
- }));
1179
- }
1180
- #watchValue() {
1181
- this.#controller.value = this.#getValue();
1182
- }
1183
- #watchHintText() {
1184
- const { normalLabel } = this.$props, { audioGain } = this.#media.$state, gain = audioGain();
1185
- this.#menu?.hint.set(gain === 1 || gain == null ? normalLabel() : String(gain * 100) + "%");
1186
- }
1187
- #watchControllerDisabled() {
1188
- this.#menu?.disable(this.disabled);
1189
- }
1190
- #getValue() {
1191
- const { audioGain } = this.#media.$state;
1192
- return audioGain()?.toString() ?? "1";
1193
- }
1194
- #onValueChange(value, trigger) {
1195
- if (this.disabled) return;
1196
- const gain = +value;
1197
- this.#media.remote.changeAudioGain(gain, trigger);
1198
- this.dispatch("change", { detail: gain, trigger });
1199
- }
1200
- }
1201
- const audiogainradiogroup__proto = AudioGainRadioGroup.prototype;
1202
- prop(audiogainradiogroup__proto, "value");
1203
- prop(audiogainradiogroup__proto, "disabled");
1204
- method(audiogainradiogroup__proto, "getOptions");
1205
-
1206
- class Gesture extends Component {
1207
- static props = {
1208
- disabled: false,
1209
- event: void 0,
1210
- action: void 0
1211
- };
1212
- #media;
1213
- #provider = null;
1214
- onSetup() {
1215
- this.#media = useMediaContext();
1216
- const { event, action } = this.$props;
1217
- this.setAttributes({
1218
- event,
1219
- action
1220
- });
1221
- }
1222
- onAttach(el) {
1223
- el.setAttribute("data-media-gesture", "");
1224
- el.style.setProperty("pointer-events", "none");
1225
- }
1226
- onConnect(el) {
1227
- this.#provider = this.#media.player.el?.querySelector(
1228
- "[data-media-provider]"
1229
- );
1230
- effect(this.#attachListener.bind(this));
1231
- }
1232
- #attachListener() {
1233
- let eventType = this.$props.event(), disabled = this.$props.disabled();
1234
- if (!this.#provider || !eventType || disabled) return;
1235
- if (/^dbl/.test(eventType)) {
1236
- eventType = eventType.split(/^dbl/)[1];
1237
- }
1238
- if (eventType === "pointerup" || eventType === "pointerdown") {
1239
- const pointer = this.#media.$state.pointer();
1240
- if (pointer === "coarse") {
1241
- eventType = eventType === "pointerup" ? "touchend" : "touchstart";
1242
- }
1243
- }
1244
- listenEvent(
1245
- this.#provider,
1246
- eventType,
1247
- this.#acceptEvent.bind(this),
1248
- { passive: false }
1249
- );
1250
- }
1251
- #presses = 0;
1252
- #pressTimerId = -1;
1253
- #acceptEvent(event) {
1254
- if (this.$props.disabled() || isPointerEvent(event) && (event.button !== 0 || this.#media.activeMenu) || isTouchEvent(event) && this.#media.activeMenu || isTouchPinchEvent(event) || !this.#inBounds(event)) {
1255
- return;
1256
- }
1257
- event.MEDIA_GESTURE = true;
1258
- event.preventDefault();
1259
- const eventType = peek(this.$props.event), isDblEvent = eventType?.startsWith("dbl");
1260
- if (!isDblEvent) {
1261
- if (this.#presses === 0) {
1262
- setTimeout(() => {
1263
- if (this.#presses === 1) this.#handleEvent(event);
1264
- }, 250);
1265
- }
1266
- } else if (this.#presses === 1) {
1267
- queueMicrotask(() => this.#handleEvent(event));
1268
- clearTimeout(this.#pressTimerId);
1269
- this.#presses = 0;
1270
- return;
1271
- }
1272
- if (this.#presses === 0) {
1273
- this.#pressTimerId = window.setTimeout(() => {
1274
- this.#presses = 0;
1275
- }, 275);
1276
- }
1277
- this.#presses++;
1278
- }
1279
- #handleEvent(event) {
1280
- this.el.setAttribute("data-triggered", "");
1281
- requestAnimationFrame(() => {
1282
- if (this.#isTopLayer()) {
1283
- this.#performAction(peek(this.$props.action), event);
1284
- }
1285
- requestAnimationFrame(() => {
1286
- this.el.removeAttribute("data-triggered");
1287
- });
1288
- });
1289
- }
1290
- /** Validate event occurred in gesture bounds. */
1291
- #inBounds(event) {
1292
- if (!this.el) return false;
1293
- if (isPointerEvent(event) || isMouseEvent(event) || isTouchEvent(event)) {
1294
- const touch = isTouchEvent(event) ? event.changedTouches[0] ?? event.touches[0] : void 0;
1295
- const clientX = touch?.clientX ?? event.clientX;
1296
- const clientY = touch?.clientY ?? event.clientY;
1297
- const rect = this.el.getBoundingClientRect();
1298
- const inBounds = clientY >= rect.top && clientY <= rect.bottom && clientX >= rect.left && clientX <= rect.right;
1299
- return event.type.includes("leave") ? !inBounds : inBounds;
1300
- }
1301
- return true;
1302
- }
1303
- /** Validate gesture has the highest z-index in this triggered group. */
1304
- #isTopLayer() {
1305
- const gestures = this.#media.player.el.querySelectorAll(
1306
- "[data-media-gesture][data-triggered]"
1307
- );
1308
- return Array.from(gestures).sort(
1309
- (a, b) => +getComputedStyle(b).zIndex - +getComputedStyle(a).zIndex
1310
- )[0] === this.el;
1311
- }
1312
- #performAction(action, trigger) {
1313
- if (!action) return;
1314
- const willTriggerEvent = new DOMEvent("will-trigger", {
1315
- detail: action,
1316
- cancelable: true,
1317
- trigger
1318
- });
1319
- this.dispatchEvent(willTriggerEvent);
1320
- if (willTriggerEvent.defaultPrevented) return;
1321
- const [method, value] = action.replace(/:([a-z])/, "-$1").split(":");
1322
- if (action.includes(":fullscreen")) {
1323
- this.#media.remote.toggleFullscreen("prefer-media", trigger);
1324
- } else if (action.includes("seek:")) {
1325
- this.#media.remote.seek(peek(this.#media.$state.currentTime) + (+value || 0), trigger);
1326
- } else {
1327
- this.#media.remote[kebabToCamelCase(method)](trigger);
1328
- }
1329
- this.dispatch("trigger", {
1330
- detail: action,
1331
- trigger
1332
- });
1333
- }
1334
- }
1335
-
1336
- class CaptionsTextRenderer {
1337
- priority = 10;
1338
- #track = null;
1339
- #renderer;
1340
- #events;
1341
- constructor(renderer) {
1342
- this.#renderer = renderer;
1343
- }
1344
- attach() {
1345
- }
1346
- canRender() {
1347
- return true;
1348
- }
1349
- detach() {
1350
- this.#events?.abort();
1351
- this.#events = void 0;
1352
- this.#renderer.reset();
1353
- this.#track = null;
1354
- }
1355
- changeTrack(track) {
1356
- if (!track || this.#track === track) return;
1357
- this.#events?.abort();
1358
- this.#events = new EventsController(track);
1359
- if (track.readyState < 2) {
1360
- this.#renderer.reset();
1361
- this.#events.add("load", () => this.#changeTrack(track), { once: true });
1362
- } else {
1363
- this.#changeTrack(track);
1364
- }
1365
- this.#events.add("add-cue", (event) => {
1366
- this.#renderer.addCue(event.detail);
1367
- }).add("remove-cue", (event) => {
1368
- this.#renderer.removeCue(event.detail);
1369
- });
1370
- this.#track = track;
1371
- }
1372
- #changeTrack(track) {
1373
- this.#renderer.changeTrack({
1374
- cues: [...track.cues],
1375
- regions: [...track.regions]
1376
- });
1377
- }
1378
- }
1379
-
1380
- class Captions extends Component {
1381
- static props = {
1382
- textDir: "ltr",
1383
- exampleText: "Captions look like this."
1384
- };
1385
- #media;
1386
- static lib = signal(null);
1387
- onSetup() {
1388
- this.#media = useMediaContext();
1389
- this.setAttributes({
1390
- "aria-hidden": $ariaBool(this.#isHidden.bind(this))
1391
- });
1392
- }
1393
- onAttach(el) {
1394
- el.style.setProperty("pointer-events", "none");
1395
- }
1396
- onConnect(el) {
1397
- if (!Captions.lib()) {
1398
- import('media-captions').then((lib) => Captions.lib.set(lib));
1399
- }
1400
- effect(this.#watchViewType.bind(this));
1401
- }
1402
- #isHidden() {
1403
- const { textTrack, remotePlaybackState, iOSControls } = this.#media.$state, track = textTrack();
1404
- return iOSControls() || remotePlaybackState() === "connected" || !track || !isTrackCaptionKind(track);
1405
- }
1406
- #watchViewType() {
1407
- if (!Captions.lib()) return;
1408
- const { viewType } = this.#media.$state;
1409
- if (viewType() === "audio") {
1410
- return this.#setupAudioView();
1411
- } else {
1412
- return this.#setupVideoView();
1413
- }
1414
- }
1415
- #setupAudioView() {
1416
- effect(this.#onTrackChange.bind(this));
1417
- this.#listenToFontStyleChanges(null);
1418
- return () => {
1419
- this.el.textContent = "";
1420
- };
1421
- }
1422
- #onTrackChange() {
1423
- if (this.#isHidden()) return;
1424
- this.#onCueChange();
1425
- const { textTrack } = this.#media.$state;
1426
- listenEvent(textTrack(), "cue-change", this.#onCueChange.bind(this));
1427
- effect(this.#onUpdateTimedNodes.bind(this));
1428
- }
1429
- #onCueChange() {
1430
- this.el.textContent = "";
1431
- if (this.#hideExampleTimer >= 0) {
1432
- this.#removeExample();
1433
- }
1434
- const { realCurrentTime, textTrack } = this.#media.$state, { renderVTTCueString } = Captions.lib(), time = peek(realCurrentTime), activeCues = peek(textTrack).activeCues;
1435
- for (const cue of activeCues) {
1436
- const displayEl = this.#createCueDisplayElement(), cueEl = this.#createCueElement();
1437
- cueEl.innerHTML = renderVTTCueString(cue, time);
1438
- displayEl.append(cueEl);
1439
- this.el.append(cueEl);
1440
- }
1441
- }
1442
- #onUpdateTimedNodes() {
1443
- const { realCurrentTime } = this.#media.$state, { updateTimedVTTCueNodes } = Captions.lib();
1444
- updateTimedVTTCueNodes(this.el, realCurrentTime());
1445
- }
1446
- #setupVideoView() {
1447
- const { CaptionsRenderer } = Captions.lib(), renderer = new CaptionsRenderer(this.el), textRenderer = new CaptionsTextRenderer(renderer);
1448
- this.#media.textRenderers.add(textRenderer);
1449
- effect(this.#watchTextDirection.bind(this, renderer));
1450
- effect(this.#watchMediaTime.bind(this, renderer));
1451
- this.#listenToFontStyleChanges(renderer);
1452
- return () => {
1453
- this.el.textContent = "";
1454
- this.#media.textRenderers.remove(textRenderer);
1455
- renderer.destroy();
1456
- };
1457
- }
1458
- #watchTextDirection(renderer) {
1459
- renderer.dir = this.$props.textDir();
1460
- }
1461
- #watchMediaTime(renderer) {
1462
- if (this.#isHidden()) return;
1463
- const { realCurrentTime, textTrack } = this.#media.$state;
1464
- renderer.currentTime = realCurrentTime();
1465
- if (this.#hideExampleTimer >= 0 && textTrack()?.activeCues[0]) {
1466
- this.#removeExample();
1467
- }
1468
- }
1469
- #listenToFontStyleChanges(renderer) {
1470
- const player = this.#media.player;
1471
- if (!player) return;
1472
- const onChange = this.#onFontStyleChange.bind(this, renderer);
1473
- listenEvent(player, "vds-font-change", onChange);
1474
- }
1475
- #onFontStyleChange(renderer) {
1476
- if (this.#hideExampleTimer >= 0) {
1477
- this.#hideExample();
1478
- return;
1479
- }
1480
- const { textTrack } = this.#media.$state;
1481
- if (!textTrack()?.activeCues[0]) {
1482
- this.#showExample();
1483
- } else {
1484
- renderer?.update(true);
1485
- }
1486
- }
1487
- #showExample() {
1488
- const display = this.#createCueDisplayElement();
1489
- setAttribute(display, "data-example", "");
1490
- const cue = this.#createCueElement();
1491
- setAttribute(cue, "data-example", "");
1492
- cue.textContent = this.$props.exampleText();
1493
- display?.append(cue);
1494
- this.el?.append(display);
1495
- this.el?.setAttribute("data-example", "");
1496
- this.#hideExample();
1497
- }
1498
- #hideExampleTimer = -1;
1499
- #hideExample() {
1500
- window.clearTimeout(this.#hideExampleTimer);
1501
- this.#hideExampleTimer = window.setTimeout(this.#removeExample.bind(this), 2500);
1502
- }
1503
- #removeExample() {
1504
- this.el?.removeAttribute("data-example");
1505
- if (this.el?.querySelector("[data-example]")) this.el.textContent = "";
1506
- this.#hideExampleTimer = -1;
1507
- }
1508
- #createCueDisplayElement() {
1509
- const el = document.createElement("div");
1510
- setAttribute(el, "data-part", "cue-display");
1511
- return el;
1512
- }
1513
- #createCueElement() {
1514
- const el = document.createElement("div");
1515
- setAttribute(el, "data-part", "cue");
1516
- return el;
1517
- }
1518
- }
1519
-
1520
- export { AudioGainRadioGroup, AudioGainSlider, Captions, ChaptersRadioGroup, Controls, ControlsGroup, DEFAULT_AUDIO_GAINS, Gesture, GoogleCastButton, MediaAnnouncer, QualitySlider, RadioGroup, SliderChapters, SliderVideo, SpeedSlider, ToggleButton, Tooltip, TooltipContent, TooltipTrigger };