@hanifhan1f/vidstack 1.12.34 → 1.12.36

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,1521 +0,0 @@
1
- import { Component, State, effect, tick, peek, setAttribute, isString, setStyle, createContext, signal, EventsController, provideContext, listenEvent, onDispose, useContext, prop, useState, isNull, functionThrottle, computed, method, scoped, createScope, animationFrameThrottle, functionDebounce, hasProvidedContext, isNumber, isPointerEvent, isTouchEvent, isMouseEvent, DOMEvent, kebabToCamelCase } from './vidstack-BNpgCJJ1.js';
2
- import { useMediaContext } from './vidstack-tt3O1zL6.js';
3
- import { setAttributeIfEmpty, requestScopedAnimationFrame, autoPlacement, $ariaBool, setARIALabel, isTouchPinchEvent } from './vidstack-DB9WDRL5.js';
4
- import { formatSpokenTime, Popper, ToggleButtonController, Slider, SliderController, sliderState, sliderValueFormatContext, TimeSlider, RadioGroupController, menuContext, formatTime } from './vidstack-D_atbNqH.js';
5
- import { FocusVisibleController, $keyboard } from './vidstack-COLU-zPZ.js';
6
- import { round } from './vidstack-Dihypf8P.js';
7
- import { sortVideoQualities } from './vidstack-BTM4ERc7.js';
8
- import { watchActiveTextTrack, isCueActive } from './vidstack-BP49Gz0m.js';
9
- import { isTrackCaptionKind } from './vidstack-oNEzlviH.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, label } = quality(), bitrateText = bitrate && bitrate > 0 ? `${(bitrate / 1e6).toFixed(2)} Mbps` : null;
681
- const rootText = label ?? (height ? `${height}p` : "");
682
- return rootText ? `${rootText}${bitrateText ? ` (${bitrateText})` : ""}` : "Auto";
683
- }
684
- #watchMax() {
685
- const $qualities = this.#sortedQualities();
686
- this.$state.max.set(Math.max(0, $qualities.length - 1));
687
- }
688
- #watchQuality() {
689
- let { quality } = this.#media.$state, $qualities = this.#sortedQualities(), value = Math.max(0, $qualities.indexOf(quality()));
690
- this.$state.value.set(value);
691
- this.dispatch("value-change", { detail: value });
692
- }
693
- #isDisabled() {
694
- const { disabled } = this.$props, { canSetQuality, qualities } = this.#media.$state;
695
- return disabled() || qualities().length <= 1 || !canSetQuality();
696
- }
697
- #throttledQualityChange = functionThrottle(this.#onQualityChange.bind(this), 25);
698
- #onQualityChange(event) {
699
- if (!event.trigger) return;
700
- const { qualities } = this.#media, quality = peek(this.#sortedQualities)[event.detail];
701
- this.#media.remote.changeQuality(qualities.indexOf(quality), event);
702
- }
703
- #onValueChange(event) {
704
- this.#throttledQualityChange(event);
705
- }
706
- #onDragValueChange(event) {
707
- this.#throttledQualityChange(event);
708
- }
709
- }
710
-
711
- class SliderChapters extends Component {
712
- static props = {
713
- disabled: false
714
- };
715
- #media;
716
- #sliderState;
717
- #updateScope;
718
- #titleRef = null;
719
- #refs = [];
720
- #$track = signal(null);
721
- #$cues = signal([]);
722
- #activeIndex = signal(-1);
723
- #activePointerIndex = signal(-1);
724
- #bufferedIndex = 0;
725
- get cues() {
726
- return this.#$cues();
727
- }
728
- get activeCue() {
729
- return this.#$cues()[this.#activeIndex()] || null;
730
- }
731
- get activePointerCue() {
732
- return this.#$cues()[this.#activePointerIndex()] || null;
733
- }
734
- onSetup() {
735
- this.#media = useMediaContext();
736
- this.#sliderState = useState(TimeSlider.state);
737
- }
738
- onAttach(el) {
739
- watchActiveTextTrack(this.#media.textTracks, "chapters", this.#setTrack.bind(this));
740
- effect(this.#watchSource.bind(this));
741
- }
742
- onConnect() {
743
- onDispose(() => this.#reset.bind(this));
744
- }
745
- onDestroy() {
746
- this.#setTrack(null);
747
- }
748
- setRefs(refs) {
749
- this.#refs = refs;
750
- this.#updateScope?.dispose();
751
- if (this.#refs.length === 1) {
752
- const el = this.#refs[0];
753
- el.style.width = "100%";
754
- el.style.setProperty("--chapter-fill", "var(--slider-fill)");
755
- el.style.setProperty("--chapter-progress", "var(--slider-progress)");
756
- } else if (this.#refs.length > 0) {
757
- scoped(() => this.#watch(), this.#updateScope = createScope());
758
- }
759
- }
760
- #setTrack(track) {
761
- if (peek(this.#$track) === track) return;
762
- this.#reset();
763
- this.#$track.set(track);
764
- }
765
- #reset() {
766
- this.#refs = [];
767
- this.#$cues.set([]);
768
- this.#activeIndex.set(-1);
769
- this.#activePointerIndex.set(-1);
770
- this.#bufferedIndex = 0;
771
- this.#updateScope?.dispose();
772
- }
773
- #watch() {
774
- if (!this.#refs.length) return;
775
- effect(this.#watchUpdates.bind(this));
776
- }
777
- #watchUpdates() {
778
- const { hidden } = this.#sliderState;
779
- if (hidden()) return;
780
- effect(this.#watchContainerWidths.bind(this));
781
- effect(this.#watchFillPercent.bind(this));
782
- effect(this.#watchPointerPercent.bind(this));
783
- effect(this.#watchBufferedPercent.bind(this));
784
- }
785
- #watchContainerWidths() {
786
- const cues = this.#$cues();
787
- if (!cues.length) return;
788
- let cue, { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd() || cues[cues.length - 1].endTime, duration = endTime - startTime, remainingWidth = 100;
789
- for (let i = 0; i < cues.length; i++) {
790
- cue = cues[i];
791
- if (this.#refs[i]) {
792
- const width = i === cues.length - 1 ? remainingWidth : round((cue.endTime - Math.max(startTime, cue.startTime)) / duration * 100, 3);
793
- this.#refs[i].style.width = width + "%";
794
- remainingWidth -= width;
795
- }
796
- }
797
- }
798
- #watchFillPercent() {
799
- let { liveEdge, seekableStart, seekableEnd } = this.#media.$state, { fillPercent, value } = this.#sliderState, cues = this.#$cues(), isLiveEdge = liveEdge(), prevActiveIndex = peek(this.#activeIndex), currentChapter = cues[prevActiveIndex];
800
- let currentActiveIndex = isLiveEdge ? this.#$cues.length - 1 : this.#findActiveChapterIndex(
801
- currentChapter ? currentChapter.startTime / seekableEnd() * 100 <= peek(value) ? prevActiveIndex : 0 : 0,
802
- fillPercent()
803
- );
804
- if (isLiveEdge || !currentChapter) {
805
- this.#updateFillPercents(0, cues.length, 100);
806
- } else if (currentActiveIndex > prevActiveIndex) {
807
- this.#updateFillPercents(prevActiveIndex, currentActiveIndex, 100);
808
- } else if (currentActiveIndex < prevActiveIndex) {
809
- this.#updateFillPercents(currentActiveIndex + 1, prevActiveIndex + 1, 0);
810
- }
811
- const percent = isLiveEdge ? 100 : this.#calcPercent(
812
- cues[currentActiveIndex],
813
- fillPercent(),
814
- seekableStart(),
815
- this.#getEndTime(cues)
816
- );
817
- this.#updateFillPercent(this.#refs[currentActiveIndex], percent);
818
- this.#activeIndex.set(currentActiveIndex);
819
- }
820
- #watchPointerPercent() {
821
- let { hidden, pointerPercent } = this.#sliderState;
822
- if (hidden()) {
823
- this.#activePointerIndex.set(-1);
824
- return;
825
- }
826
- const activeIndex = this.#findActiveChapterIndex(0, pointerPercent());
827
- this.#activePointerIndex.set(activeIndex);
828
- }
829
- #updateFillPercents(start, end, percent) {
830
- for (let i = start; i < end; i++) this.#updateFillPercent(this.#refs[i], percent);
831
- }
832
- #updateFillPercent(ref, percent) {
833
- if (!ref) return;
834
- ref.style.setProperty("--chapter-fill", percent + "%");
835
- setAttribute(ref, "data-active", percent > 0 && percent < 100);
836
- setAttribute(ref, "data-ended", percent === 100);
837
- }
838
- #findActiveChapterIndex(startIndex, percent) {
839
- let chapterPercent = 0, cues = this.#$cues();
840
- if (percent === 0) return 0;
841
- else if (percent === 100) return cues.length - 1;
842
- let { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
843
- for (let i = startIndex; i < cues.length; i++) {
844
- chapterPercent = this.#calcPercent(cues[i], percent, startTime, endTime);
845
- if (chapterPercent >= 0 && chapterPercent < 100) return i;
846
- }
847
- return 0;
848
- }
849
- #watchBufferedPercent() {
850
- this.#updateBufferedPercent(this.#bufferedPercent());
851
- }
852
- #updateBufferedPercent = animationFrameThrottle((bufferedPercent) => {
853
- let percent, cues = this.#$cues(), { seekableStart } = this.#media.$state, startTime = seekableStart(), endTime = this.#getEndTime(cues);
854
- for (let i = this.#bufferedIndex; i < this.#refs.length; i++) {
855
- percent = this.#calcPercent(cues[i], bufferedPercent, startTime, endTime);
856
- this.#refs[i]?.style.setProperty("--chapter-progress", percent + "%");
857
- if (percent < 100) {
858
- this.#bufferedIndex = i;
859
- break;
860
- }
861
- }
862
- });
863
- #bufferedPercent = computed(this.#calcMediaBufferedPercent.bind(this));
864
- #calcMediaBufferedPercent() {
865
- const { bufferedEnd, duration } = this.#media.$state;
866
- return round(Math.min(bufferedEnd() / Math.max(duration(), 1), 1), 3) * 100;
867
- }
868
- #getEndTime(cues) {
869
- const { seekableEnd } = this.#media.$state, endTime = seekableEnd();
870
- return Number.isFinite(endTime) ? endTime : cues[cues.length - 1]?.endTime || 0;
871
- }
872
- #calcPercent(cue, percent, startTime, endTime) {
873
- if (!cue) return 0;
874
- const cues = this.#$cues();
875
- if (cues.length === 0) return 0;
876
- const duration = endTime - startTime, cueStartTime = Math.max(0, cue.startTime - startTime), cueEndTime = Math.min(endTime, cue.endTime) - startTime;
877
- const startRatio = cueStartTime / duration, startPercent = startRatio * 100, endPercent = Math.min(1, startRatio + (cueEndTime - cueStartTime) / duration) * 100;
878
- return Math.max(
879
- 0,
880
- round(
881
- percent >= endPercent ? 100 : (percent - startPercent) / (endPercent - startPercent) * 100,
882
- 3
883
- )
884
- );
885
- }
886
- #fillGaps(cues) {
887
- let chapters = [], { seekableStart, seekableEnd, duration } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
888
- cues = cues.filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime);
889
- const firstCue = cues[0];
890
- if (firstCue && firstCue.startTime > startTime) {
891
- chapters.push(new window.VTTCue(startTime, firstCue.startTime, ""));
892
- }
893
- for (let i = 0; i < cues.length - 1; i++) {
894
- const currentCue = cues[i], nextCue = cues[i + 1];
895
- chapters.push(currentCue);
896
- if (nextCue) {
897
- const timeDiff = nextCue.startTime - currentCue.endTime;
898
- if (timeDiff > 0) {
899
- chapters.push(new window.VTTCue(currentCue.endTime, currentCue.endTime + timeDiff, ""));
900
- }
901
- }
902
- }
903
- const lastCue = cues[cues.length - 1];
904
- if (lastCue) {
905
- chapters.push(lastCue);
906
- const endTime2 = duration();
907
- if (endTime2 >= 0 && endTime2 - lastCue.endTime > 1) {
908
- chapters.push(new window.VTTCue(lastCue.endTime, duration(), ""));
909
- }
910
- }
911
- return chapters;
912
- }
913
- #watchSource() {
914
- const { source } = this.#media.$state;
915
- source();
916
- this.#onTrackChange();
917
- }
918
- #onTrackChange() {
919
- if (!this.scope) return;
920
- const { disabled } = this.$props;
921
- if (disabled()) {
922
- this.#$cues.set([]);
923
- this.#activeIndex.set(0);
924
- this.#bufferedIndex = 0;
925
- return;
926
- }
927
- const track = this.#$track();
928
- if (track) {
929
- const onCuesChange = this.#onCuesChange.bind(this);
930
- onCuesChange();
931
- new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
932
- effect(this.#watchMediaDuration.bind(this));
933
- }
934
- this.#titleRef = this.#findChapterTitleRef();
935
- if (this.#titleRef) effect(this.#onChapterTitleChange.bind(this));
936
- return () => {
937
- if (this.#titleRef) {
938
- this.#titleRef.textContent = "";
939
- this.#titleRef = null;
940
- }
941
- };
942
- }
943
- #watchMediaDuration() {
944
- this.#media.$state.duration();
945
- this.#onCuesChange();
946
- }
947
- #onCuesChange = functionDebounce(
948
- () => {
949
- const track = peek(this.#$track);
950
- if (!this.scope || !track || !track.cues.length) return;
951
- this.#$cues.set(this.#fillGaps(track.cues));
952
- this.#activeIndex.set(0);
953
- this.#bufferedIndex = 0;
954
- },
955
- 150,
956
- true
957
- );
958
- #onChapterTitleChange() {
959
- const cue = this.activePointerCue || this.activeCue;
960
- if (this.#titleRef) this.#titleRef.textContent = cue?.text || "";
961
- }
962
- #findParentSlider() {
963
- let node = this.el;
964
- while (node && node.getAttribute("role") !== "slider") {
965
- node = node.parentElement;
966
- }
967
- return node;
968
- }
969
- #findChapterTitleRef() {
970
- const slider = this.#findParentSlider();
971
- return slider ? slider.querySelector('[data-part="chapter-title"]') : null;
972
- }
973
- }
974
- const sliderchapters__proto = SliderChapters.prototype;
975
- prop(sliderchapters__proto, "cues");
976
- prop(sliderchapters__proto, "activeCue");
977
- prop(sliderchapters__proto, "activePointerCue");
978
- method(sliderchapters__proto, "setRefs");
979
-
980
- class RadioGroup extends Component {
981
- static props = {
982
- value: ""
983
- };
984
- #controller;
985
- /**
986
- * A list of radio values that belong this group.
987
- */
988
- get values() {
989
- return this.#controller.values;
990
- }
991
- /**
992
- * The radio value that is checked in this group.
993
- */
994
- get value() {
995
- return this.#controller.value;
996
- }
997
- set value(newValue) {
998
- this.#controller.value = newValue;
999
- }
1000
- constructor() {
1001
- super();
1002
- this.#controller = new RadioGroupController();
1003
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1004
- }
1005
- onSetup() {
1006
- effect(this.#watchValue.bind(this));
1007
- }
1008
- #watchValue() {
1009
- this.#controller.value = this.$props.value();
1010
- }
1011
- #onValueChange(value, trigger) {
1012
- const event = this.createEvent("change", { detail: value, trigger });
1013
- this.dispatch(event);
1014
- }
1015
- }
1016
- const radiogroup__proto = RadioGroup.prototype;
1017
- prop(radiogroup__proto, "values");
1018
- prop(radiogroup__proto, "value");
1019
-
1020
- var __defProp = Object.defineProperty;
1021
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1022
- var __decorateClass = (decorators, target, key, kind) => {
1023
- var result = __getOwnPropDesc(target, key) ;
1024
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1025
- if (decorator = decorators[i])
1026
- result = (decorator(target, key, result) ) || result;
1027
- if (result) __defProp(target, key, result);
1028
- return result;
1029
- };
1030
- class ChaptersRadioGroup extends Component {
1031
- static props = {
1032
- thumbnails: null
1033
- };
1034
- #media;
1035
- #menu;
1036
- #controller;
1037
- #track = signal(null);
1038
- #cues = signal([]);
1039
- get value() {
1040
- return this.#controller.value;
1041
- }
1042
- get disabled() {
1043
- return !this.#cues()?.length;
1044
- }
1045
- constructor() {
1046
- super();
1047
- this.#controller = new RadioGroupController();
1048
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1049
- }
1050
- onSetup() {
1051
- this.#media = useMediaContext();
1052
- if (hasProvidedContext(menuContext)) {
1053
- this.#menu = useContext(menuContext);
1054
- }
1055
- const { thumbnails } = this.$props;
1056
- this.setAttributes({
1057
- "data-thumbnails": () => !!thumbnails()
1058
- });
1059
- }
1060
- onAttach(el) {
1061
- this.#menu?.attachObserver({
1062
- onOpen: this.#onOpen.bind(this)
1063
- });
1064
- }
1065
- getOptions() {
1066
- const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1067
- return this.#cues().map((cue, i) => ({
1068
- cue,
1069
- value: i.toString(),
1070
- label: cue.text,
1071
- startTime: formatTime(Math.max(0, cue.startTime - startTime)),
1072
- duration: formatSpokenTime(
1073
- Math.min(endTime, cue.endTime) - Math.max(startTime, cue.startTime)
1074
- )
1075
- }));
1076
- }
1077
- #onOpen() {
1078
- peek(() => this.#watchCurrentTime());
1079
- }
1080
- onConnect(el) {
1081
- effect(this.#watchCurrentTime.bind(this));
1082
- effect(this.#watchControllerDisabled.bind(this));
1083
- effect(this.#watchTrack.bind(this));
1084
- watchActiveTextTrack(this.#media.textTracks, "chapters", this.#track.set);
1085
- }
1086
- #watchTrack() {
1087
- const track = this.#track();
1088
- if (!track) return;
1089
- const onCuesChange = this.#onCuesChange.bind(this, track);
1090
- onCuesChange();
1091
- new EventsController(track).add("add-cue", onCuesChange).add("remove-cue", onCuesChange);
1092
- return () => {
1093
- this.#cues.set([]);
1094
- };
1095
- }
1096
- #onCuesChange(track) {
1097
- const { seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd();
1098
- this.#cues.set(
1099
- [...track.cues].filter((cue) => cue.startTime <= endTime && cue.endTime >= startTime)
1100
- );
1101
- }
1102
- #watchCurrentTime() {
1103
- if (!this.#menu?.expanded()) return;
1104
- const track = this.#track();
1105
- if (!track) {
1106
- this.#controller.value = "-1";
1107
- return;
1108
- }
1109
- const { realCurrentTime, seekableStart, seekableEnd } = this.#media.$state, startTime = seekableStart(), endTime = seekableEnd(), time = realCurrentTime(), activeCueIndex = this.#cues().findIndex((cue) => isCueActive(cue, time));
1110
- this.#controller.value = activeCueIndex.toString();
1111
- if (activeCueIndex >= 0) {
1112
- requestScopedAnimationFrame(() => {
1113
- if (!this.connectScope) return;
1114
- 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;
1115
- radio && setStyle(radio, "--progress", round(playedPercent, 3) + "%");
1116
- });
1117
- }
1118
- }
1119
- #watchControllerDisabled() {
1120
- this.#menu?.disable(this.disabled);
1121
- }
1122
- #onValueChange(value, trigger) {
1123
- if (this.disabled || !trigger) return;
1124
- const index = +value, cues = this.#cues(), { clipStartTime } = this.#media.$state;
1125
- if (isNumber(index) && cues?.[index]) {
1126
- this.#controller.value = index.toString();
1127
- this.#media.remote.seek(cues[index].startTime - clipStartTime(), trigger);
1128
- this.dispatch("change", { detail: cues[index], trigger });
1129
- }
1130
- }
1131
- }
1132
- __decorateClass([
1133
- prop
1134
- ], ChaptersRadioGroup.prototype, "value");
1135
- __decorateClass([
1136
- prop
1137
- ], ChaptersRadioGroup.prototype, "disabled");
1138
- __decorateClass([
1139
- method
1140
- ], ChaptersRadioGroup.prototype, "getOptions");
1141
-
1142
- const DEFAULT_AUDIO_GAINS = [1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4];
1143
- class AudioGainRadioGroup extends Component {
1144
- static props = {
1145
- normalLabel: "Disabled",
1146
- gains: DEFAULT_AUDIO_GAINS
1147
- };
1148
- #media;
1149
- #menu;
1150
- #controller;
1151
- get value() {
1152
- return this.#controller.value;
1153
- }
1154
- get disabled() {
1155
- const { gains } = this.$props, { canSetAudioGain } = this.#media.$state;
1156
- return !canSetAudioGain() || gains().length === 0;
1157
- }
1158
- constructor() {
1159
- super();
1160
- this.#controller = new RadioGroupController();
1161
- this.#controller.onValueChange = this.#onValueChange.bind(this);
1162
- }
1163
- onSetup() {
1164
- this.#media = useMediaContext();
1165
- if (hasProvidedContext(menuContext)) {
1166
- this.#menu = useContext(menuContext);
1167
- }
1168
- }
1169
- onConnect(el) {
1170
- effect(this.#watchValue.bind(this));
1171
- effect(this.#watchHintText.bind(this));
1172
- effect(this.#watchControllerDisabled.bind(this));
1173
- }
1174
- getOptions() {
1175
- const { gains, normalLabel } = this.$props;
1176
- return gains().map((gain) => ({
1177
- label: gain === 1 || gain === null ? normalLabel : String(gain * 100) + "%",
1178
- value: gain.toString()
1179
- }));
1180
- }
1181
- #watchValue() {
1182
- this.#controller.value = this.#getValue();
1183
- }
1184
- #watchHintText() {
1185
- const { normalLabel } = this.$props, { audioGain } = this.#media.$state, gain = audioGain();
1186
- this.#menu?.hint.set(gain === 1 || gain == null ? normalLabel() : String(gain * 100) + "%");
1187
- }
1188
- #watchControllerDisabled() {
1189
- this.#menu?.disable(this.disabled);
1190
- }
1191
- #getValue() {
1192
- const { audioGain } = this.#media.$state;
1193
- return audioGain()?.toString() ?? "1";
1194
- }
1195
- #onValueChange(value, trigger) {
1196
- if (this.disabled) return;
1197
- const gain = +value;
1198
- this.#media.remote.changeAudioGain(gain, trigger);
1199
- this.dispatch("change", { detail: gain, trigger });
1200
- }
1201
- }
1202
- const audiogainradiogroup__proto = AudioGainRadioGroup.prototype;
1203
- prop(audiogainradiogroup__proto, "value");
1204
- prop(audiogainradiogroup__proto, "disabled");
1205
- method(audiogainradiogroup__proto, "getOptions");
1206
-
1207
- class Gesture extends Component {
1208
- static props = {
1209
- disabled: false,
1210
- event: void 0,
1211
- action: void 0
1212
- };
1213
- #media;
1214
- #provider = null;
1215
- onSetup() {
1216
- this.#media = useMediaContext();
1217
- const { event, action } = this.$props;
1218
- this.setAttributes({
1219
- event,
1220
- action
1221
- });
1222
- }
1223
- onAttach(el) {
1224
- el.setAttribute("data-media-gesture", "");
1225
- el.style.setProperty("pointer-events", "none");
1226
- }
1227
- onConnect(el) {
1228
- this.#provider = this.#media.player.el?.querySelector(
1229
- "[data-media-provider]"
1230
- );
1231
- effect(this.#attachListener.bind(this));
1232
- }
1233
- #attachListener() {
1234
- let eventType = this.$props.event(), disabled = this.$props.disabled();
1235
- if (!this.#provider || !eventType || disabled) return;
1236
- if (/^dbl/.test(eventType)) {
1237
- eventType = eventType.split(/^dbl/)[1];
1238
- }
1239
- if (eventType === "pointerup" || eventType === "pointerdown") {
1240
- const pointer = this.#media.$state.pointer();
1241
- if (pointer === "coarse") {
1242
- eventType = eventType === "pointerup" ? "touchend" : "touchstart";
1243
- }
1244
- }
1245
- listenEvent(
1246
- this.#provider,
1247
- eventType,
1248
- this.#acceptEvent.bind(this),
1249
- { passive: false }
1250
- );
1251
- }
1252
- #presses = 0;
1253
- #pressTimerId = -1;
1254
- #acceptEvent(event) {
1255
- if (this.$props.disabled() || isPointerEvent(event) && (event.button !== 0 || this.#media.activeMenu) || isTouchEvent(event) && this.#media.activeMenu || isTouchPinchEvent(event) || !this.#inBounds(event)) {
1256
- return;
1257
- }
1258
- event.MEDIA_GESTURE = true;
1259
- event.preventDefault();
1260
- const eventType = peek(this.$props.event), isDblEvent = eventType?.startsWith("dbl");
1261
- if (!isDblEvent) {
1262
- if (this.#presses === 0) {
1263
- setTimeout(() => {
1264
- if (this.#presses === 1) this.#handleEvent(event);
1265
- }, 250);
1266
- }
1267
- } else if (this.#presses === 1) {
1268
- queueMicrotask(() => this.#handleEvent(event));
1269
- clearTimeout(this.#pressTimerId);
1270
- this.#presses = 0;
1271
- return;
1272
- }
1273
- if (this.#presses === 0) {
1274
- this.#pressTimerId = window.setTimeout(() => {
1275
- this.#presses = 0;
1276
- }, 275);
1277
- }
1278
- this.#presses++;
1279
- }
1280
- #handleEvent(event) {
1281
- this.el.setAttribute("data-triggered", "");
1282
- requestAnimationFrame(() => {
1283
- if (this.#isTopLayer()) {
1284
- this.#performAction(peek(this.$props.action), event);
1285
- }
1286
- requestAnimationFrame(() => {
1287
- this.el.removeAttribute("data-triggered");
1288
- });
1289
- });
1290
- }
1291
- /** Validate event occurred in gesture bounds. */
1292
- #inBounds(event) {
1293
- if (!this.el) return false;
1294
- if (isPointerEvent(event) || isMouseEvent(event) || isTouchEvent(event)) {
1295
- const touch = isTouchEvent(event) ? event.changedTouches[0] ?? event.touches[0] : void 0;
1296
- const clientX = touch?.clientX ?? event.clientX;
1297
- const clientY = touch?.clientY ?? event.clientY;
1298
- const rect = this.el.getBoundingClientRect();
1299
- const inBounds = clientY >= rect.top && clientY <= rect.bottom && clientX >= rect.left && clientX <= rect.right;
1300
- return event.type.includes("leave") ? !inBounds : inBounds;
1301
- }
1302
- return true;
1303
- }
1304
- /** Validate gesture has the highest z-index in this triggered group. */
1305
- #isTopLayer() {
1306
- const gestures = this.#media.player.el.querySelectorAll(
1307
- "[data-media-gesture][data-triggered]"
1308
- );
1309
- return Array.from(gestures).sort(
1310
- (a, b) => +getComputedStyle(b).zIndex - +getComputedStyle(a).zIndex
1311
- )[0] === this.el;
1312
- }
1313
- #performAction(action, trigger) {
1314
- if (!action) return;
1315
- const willTriggerEvent = new DOMEvent("will-trigger", {
1316
- detail: action,
1317
- cancelable: true,
1318
- trigger
1319
- });
1320
- this.dispatchEvent(willTriggerEvent);
1321
- if (willTriggerEvent.defaultPrevented) return;
1322
- const [method, value] = action.replace(/:([a-z])/, "-$1").split(":");
1323
- if (action.includes(":fullscreen")) {
1324
- this.#media.remote.toggleFullscreen("prefer-media", trigger);
1325
- } else if (action.includes("seek:")) {
1326
- this.#media.remote.seek(peek(this.#media.$state.currentTime) + (+value || 0), trigger);
1327
- } else {
1328
- this.#media.remote[kebabToCamelCase(method)](trigger);
1329
- }
1330
- this.dispatch("trigger", {
1331
- detail: action,
1332
- trigger
1333
- });
1334
- }
1335
- }
1336
-
1337
- class CaptionsTextRenderer {
1338
- priority = 10;
1339
- #track = null;
1340
- #renderer;
1341
- #events;
1342
- constructor(renderer) {
1343
- this.#renderer = renderer;
1344
- }
1345
- attach() {
1346
- }
1347
- canRender() {
1348
- return true;
1349
- }
1350
- detach() {
1351
- this.#events?.abort();
1352
- this.#events = void 0;
1353
- this.#renderer.reset();
1354
- this.#track = null;
1355
- }
1356
- changeTrack(track) {
1357
- if (!track || this.#track === track) return;
1358
- this.#events?.abort();
1359
- this.#events = new EventsController(track);
1360
- if (track.readyState < 2) {
1361
- this.#renderer.reset();
1362
- this.#events.add("load", () => this.#changeTrack(track), { once: true });
1363
- } else {
1364
- this.#changeTrack(track);
1365
- }
1366
- this.#events.add("add-cue", (event) => {
1367
- this.#renderer.addCue(event.detail);
1368
- }).add("remove-cue", (event) => {
1369
- this.#renderer.removeCue(event.detail);
1370
- });
1371
- this.#track = track;
1372
- }
1373
- #changeTrack(track) {
1374
- this.#renderer.changeTrack({
1375
- cues: [...track.cues],
1376
- regions: [...track.regions]
1377
- });
1378
- }
1379
- }
1380
-
1381
- class Captions extends Component {
1382
- static props = {
1383
- textDir: "ltr",
1384
- exampleText: "Captions look like this."
1385
- };
1386
- #media;
1387
- static lib = signal(null);
1388
- onSetup() {
1389
- this.#media = useMediaContext();
1390
- this.setAttributes({
1391
- "aria-hidden": $ariaBool(this.#isHidden.bind(this))
1392
- });
1393
- }
1394
- onAttach(el) {
1395
- el.style.setProperty("pointer-events", "none");
1396
- }
1397
- onConnect(el) {
1398
- if (!Captions.lib()) {
1399
- import('media-captions').then((lib) => Captions.lib.set(lib));
1400
- }
1401
- effect(this.#watchViewType.bind(this));
1402
- }
1403
- #isHidden() {
1404
- const { textTrack, remotePlaybackState, iOSControls } = this.#media.$state, track = textTrack();
1405
- return iOSControls() || remotePlaybackState() === "connected" || !track || !isTrackCaptionKind(track);
1406
- }
1407
- #watchViewType() {
1408
- if (!Captions.lib()) return;
1409
- const { viewType } = this.#media.$state;
1410
- if (viewType() === "audio") {
1411
- return this.#setupAudioView();
1412
- } else {
1413
- return this.#setupVideoView();
1414
- }
1415
- }
1416
- #setupAudioView() {
1417
- effect(this.#onTrackChange.bind(this));
1418
- this.#listenToFontStyleChanges(null);
1419
- return () => {
1420
- this.el.textContent = "";
1421
- };
1422
- }
1423
- #onTrackChange() {
1424
- if (this.#isHidden()) return;
1425
- this.#onCueChange();
1426
- const { textTrack } = this.#media.$state;
1427
- listenEvent(textTrack(), "cue-change", this.#onCueChange.bind(this));
1428
- effect(this.#onUpdateTimedNodes.bind(this));
1429
- }
1430
- #onCueChange() {
1431
- this.el.textContent = "";
1432
- if (this.#hideExampleTimer >= 0) {
1433
- this.#removeExample();
1434
- }
1435
- const { realCurrentTime, textTrack } = this.#media.$state, { renderVTTCueString } = Captions.lib(), time = peek(realCurrentTime), activeCues = peek(textTrack).activeCues;
1436
- for (const cue of activeCues) {
1437
- const displayEl = this.#createCueDisplayElement(), cueEl = this.#createCueElement();
1438
- cueEl.innerHTML = renderVTTCueString(cue, time);
1439
- displayEl.append(cueEl);
1440
- this.el.append(cueEl);
1441
- }
1442
- }
1443
- #onUpdateTimedNodes() {
1444
- const { realCurrentTime } = this.#media.$state, { updateTimedVTTCueNodes } = Captions.lib();
1445
- updateTimedVTTCueNodes(this.el, realCurrentTime());
1446
- }
1447
- #setupVideoView() {
1448
- const { CaptionsRenderer } = Captions.lib(), renderer = new CaptionsRenderer(this.el), textRenderer = new CaptionsTextRenderer(renderer);
1449
- this.#media.textRenderers.add(textRenderer);
1450
- effect(this.#watchTextDirection.bind(this, renderer));
1451
- effect(this.#watchMediaTime.bind(this, renderer));
1452
- this.#listenToFontStyleChanges(renderer);
1453
- return () => {
1454
- this.el.textContent = "";
1455
- this.#media.textRenderers.remove(textRenderer);
1456
- renderer.destroy();
1457
- };
1458
- }
1459
- #watchTextDirection(renderer) {
1460
- renderer.dir = this.$props.textDir();
1461
- }
1462
- #watchMediaTime(renderer) {
1463
- if (this.#isHidden()) return;
1464
- const { realCurrentTime, textTrack } = this.#media.$state;
1465
- renderer.currentTime = realCurrentTime();
1466
- if (this.#hideExampleTimer >= 0 && textTrack()?.activeCues[0]) {
1467
- this.#removeExample();
1468
- }
1469
- }
1470
- #listenToFontStyleChanges(renderer) {
1471
- const player = this.#media.player;
1472
- if (!player) return;
1473
- const onChange = this.#onFontStyleChange.bind(this, renderer);
1474
- listenEvent(player, "vds-font-change", onChange);
1475
- }
1476
- #onFontStyleChange(renderer) {
1477
- if (this.#hideExampleTimer >= 0) {
1478
- this.#hideExample();
1479
- return;
1480
- }
1481
- const { textTrack } = this.#media.$state;
1482
- if (!textTrack()?.activeCues[0]) {
1483
- this.#showExample();
1484
- } else {
1485
- renderer?.update(true);
1486
- }
1487
- }
1488
- #showExample() {
1489
- const display = this.#createCueDisplayElement();
1490
- setAttribute(display, "data-example", "");
1491
- const cue = this.#createCueElement();
1492
- setAttribute(cue, "data-example", "");
1493
- cue.textContent = this.$props.exampleText();
1494
- display?.append(cue);
1495
- this.el?.append(display);
1496
- this.el?.setAttribute("data-example", "");
1497
- this.#hideExample();
1498
- }
1499
- #hideExampleTimer = -1;
1500
- #hideExample() {
1501
- window.clearTimeout(this.#hideExampleTimer);
1502
- this.#hideExampleTimer = window.setTimeout(this.#removeExample.bind(this), 2500);
1503
- }
1504
- #removeExample() {
1505
- this.el?.removeAttribute("data-example");
1506
- if (this.el?.querySelector("[data-example]")) this.el.textContent = "";
1507
- this.#hideExampleTimer = -1;
1508
- }
1509
- #createCueDisplayElement() {
1510
- const el = document.createElement("div");
1511
- setAttribute(el, "data-part", "cue-display");
1512
- return el;
1513
- }
1514
- #createCueElement() {
1515
- const el = document.createElement("div");
1516
- setAttribute(el, "data-part", "cue");
1517
- return el;
1518
- }
1519
- }
1520
-
1521
- export { AudioGainRadioGroup, AudioGainSlider, Captions, ChaptersRadioGroup, Controls, ControlsGroup, DEFAULT_AUDIO_GAINS, Gesture, GoogleCastButton, MediaAnnouncer, QualitySlider, RadioGroup, SliderChapters, SliderVideo, SpeedSlider, ToggleButton, Tooltip, TooltipContent, TooltipTrigger };