@hanifhan1f/vidstack 1.12.25 → 1.12.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/cdn/chunks/vidstack-8JHLDxl5.js +1 -0
  2. package/cdn/chunks/vidstack-Bpnl-N6k.js +1 -0
  3. package/cdn/chunks/vidstack-CnWKPIKT.js +16 -0
  4. package/cdn/chunks/vidstack-CqzAnF2W.js +16 -0
  5. package/cdn/vidstack.js +1 -1
  6. package/cdn/with-layouts/chunks/vidstack-BD5YoTt5.js +937 -0
  7. package/cdn/with-layouts/chunks/vidstack-DCaNJN4T.js +1 -0
  8. package/cdn/with-layouts/chunks/vidstack-Dd3L-eQj.js +1 -0
  9. package/cdn/with-layouts/chunks/vidstack-T2rZVigk.js +912 -0
  10. package/cdn/with-layouts/vidstack.js +1 -1
  11. package/dev/chunks/vidstack--aukHYxl.js +1520 -0
  12. package/dev/chunks/vidstack-B__DfQsT.js +1621 -0
  13. package/dev/chunks/vidstack-BoLIUOyq.js +204 -0
  14. package/dev/chunks/vidstack-CSryZFvY.js +1521 -0
  15. package/dev/chunks/vidstack-Cky9ors4.js +297 -0
  16. package/dev/chunks/vidstack-Crz0ROkT.js +3009 -0
  17. package/dev/chunks/vidstack-D-sqb6YI.js +308 -0
  18. package/dev/chunks/vidstack-DLXCqdYV.js +3010 -0
  19. package/dev/chunks/vidstack-DS7nRfge.js +204 -0
  20. package/dev/chunks/vidstack-Dco6kA4h.js +104 -0
  21. package/dev/chunks/vidstack-DpS0Kt4b.js +297 -0
  22. package/dev/chunks/vidstack-zJT-7ncH.js +5182 -0
  23. package/dev/define/plyr-layout.js +3 -4
  24. package/dev/define/templates/vidstack-audio-layout.js +4 -4
  25. package/dev/define/templates/vidstack-video-layout.js +4 -4
  26. package/dev/define/vidstack-player-default-layout.js +4 -4
  27. package/dev/define/vidstack-player-layouts.js +4 -4
  28. package/dev/define/vidstack-player-ui.js +5 -6
  29. package/dev/define/vidstack-player.js +3 -4
  30. package/dev/global/plyr.js +5 -6
  31. package/dev/global/vidstack-player.js +3 -4
  32. package/dev/providers/vidstack-dash.js +1 -2
  33. package/dev/providers/vidstack-hls.js +1 -2
  34. package/dev/providers/vidstack-video.js +1 -2
  35. package/dev/providers/vidstack-vimeo.js +1 -2
  36. package/dev/vidstack-elements.js +8 -9
  37. package/dev/vidstack.js +6 -7
  38. package/package.json +2 -1
  39. package/prod/chunks/vidstack-BVSJtdRd.js +297 -0
  40. package/prod/chunks/vidstack-BnEo_Sla.js +1621 -0
  41. package/prod/chunks/vidstack-CFXAYpuh.js +1521 -0
  42. package/prod/chunks/vidstack-CIvL96_j.js +297 -0
  43. package/prod/chunks/vidstack-CLTPjjXX.js +4772 -0
  44. package/prod/chunks/vidstack-CSHHV2zO.js +201 -0
  45. package/prod/chunks/vidstack-CYVCrFjx.js +201 -0
  46. package/prod/chunks/vidstack-D_atbNqH.js +3000 -0
  47. package/prod/chunks/vidstack-Eo46ZHu7.js +2999 -0
  48. package/prod/chunks/vidstack-sP7TQMB1.js +300 -0
  49. package/prod/chunks/vidstack-uVm3xX8H.js +104 -0
  50. package/prod/chunks/vidstack-zknLxihl.js +1520 -0
  51. package/prod/define/plyr-layout.js +3 -4
  52. package/prod/define/templates/vidstack-audio-layout.js +4 -4
  53. package/prod/define/templates/vidstack-video-layout.js +4 -4
  54. package/prod/define/vidstack-player-default-layout.js +4 -4
  55. package/prod/define/vidstack-player-layouts.js +4 -4
  56. package/prod/define/vidstack-player-ui.js +5 -6
  57. package/prod/define/vidstack-player.js +3 -4
  58. package/prod/global/plyr.js +5 -6
  59. package/prod/global/vidstack-player.js +3 -4
  60. package/prod/providers/vidstack-dash.js +1 -2
  61. package/prod/providers/vidstack-hls.js +1 -2
  62. package/prod/providers/vidstack-video.js +1 -2
  63. package/prod/providers/vidstack-vimeo.js +1 -2
  64. package/prod/vidstack-elements.js +8 -9
  65. package/prod/vidstack.js +6 -7
  66. package/server/chunks/vidstack-B3eA67nX.js +205 -0
  67. package/server/chunks/vidstack-B8P1aUCK.js +1503 -0
  68. package/server/chunks/vidstack-B8_v1VQn.js +3059 -0
  69. package/server/chunks/vidstack-BK4xGWUK.js +207 -0
  70. package/server/chunks/vidstack-BO8FLks6.js +295 -0
  71. package/server/chunks/vidstack-BaXvZgx2.js +141 -0
  72. package/server/chunks/vidstack-BlvJg_5A.js +4636 -0
  73. package/server/chunks/vidstack-CBhikwSz.js +67 -0
  74. package/server/chunks/vidstack-COczNXom.js +3059 -0
  75. package/server/chunks/vidstack-CyZPtpwO.js +1503 -0
  76. package/server/chunks/vidstack-Db22EuE_.js +207 -0
  77. package/server/chunks/vidstack-Dh1ZDEI-.js +29 -0
  78. package/server/chunks/vidstack-Dm-ETAZh.js +295 -0
  79. package/server/chunks/vidstack-NpAD9hfP.js +620 -0
  80. package/server/chunks/vidstack-O4BgIcQI.js +104 -0
  81. package/server/chunks/vidstack-n4zAyLEV.js +2139 -0
  82. package/server/chunks/vidstack-za5Yh5DQ.js +566 -0
  83. package/server/chunks/vidstack-zoXyfYxa.js +107 -0
  84. package/server/define/plyr-layout.js +7 -7
  85. package/server/define/vidstack-player-default-layout.js +3 -3
  86. package/server/define/vidstack-player-layouts.js +5 -5
  87. package/server/define/vidstack-player-ui.js +6 -6
  88. package/server/define/vidstack-player.js +4 -4
  89. package/server/global/plyr.js +9 -9
  90. package/server/global/vidstack-player.js +4 -4
  91. package/server/vidstack-elements.js +13 -13
  92. package/server/vidstack.js +8 -8
@@ -0,0 +1,308 @@
1
+ import { listenEvent, scoped, isString, getScope, EventsTarget, DOMEvent, isArray, isNumber } from './vidstack-C1PwJD_4.js';
2
+ import { getRequestCredentials } from './vidstack-DdTXMZro.js';
3
+
4
+ const CROSS_ORIGIN = Symbol("TEXT_TRACK_CROSS_ORIGIN" ), READY_STATE = Symbol("TEXT_TRACK_READY_STATE" ), UPDATE_ACTIVE_CUES = Symbol("TEXT_TRACK_UPDATE_ACTIVE_CUES" ), CAN_LOAD = Symbol("TEXT_TRACK_CAN_LOAD" ), ON_MODE_CHANGE = Symbol("TEXT_TRACK_ON_MODE_CHANGE" ), NATIVE = Symbol("TEXT_TRACK_NATIVE" ), NATIVE_HLS = Symbol("TEXT_TRACK_NATIVE_HLS" );
5
+ const TextTrackSymbol = {
6
+ crossOrigin: CROSS_ORIGIN,
7
+ readyState: READY_STATE,
8
+ updateActiveCues: UPDATE_ACTIVE_CUES,
9
+ canLoad: CAN_LOAD,
10
+ onModeChange: ON_MODE_CHANGE,
11
+ native: NATIVE,
12
+ nativeHLS: NATIVE_HLS
13
+ };
14
+
15
+ function findActiveCue(cues, time) {
16
+ for (let i = 0, len = cues.length; i < len; i++) {
17
+ if (isCueActive(cues[i], time)) return cues[i];
18
+ }
19
+ return null;
20
+ }
21
+ function isCueActive(cue, time) {
22
+ return time >= cue.startTime && time < cue.endTime;
23
+ }
24
+ function watchActiveTextTrack(tracks, kind, onChange) {
25
+ let currentTrack = null, scope = getScope();
26
+ function onModeChange() {
27
+ const kinds = isString(kind) ? [kind] : kind, track = tracks.toArray().find((track2) => kinds.includes(track2.kind) && track2.mode === "showing");
28
+ if (track === currentTrack) return;
29
+ if (!track) {
30
+ onChange(null);
31
+ currentTrack = null;
32
+ return;
33
+ }
34
+ if (track.readyState == 2) {
35
+ onChange(track);
36
+ } else {
37
+ onChange(null);
38
+ scoped(() => {
39
+ const off = listenEvent(
40
+ track,
41
+ "load",
42
+ () => {
43
+ onChange(track);
44
+ off();
45
+ },
46
+ { once: true }
47
+ );
48
+ }, scope);
49
+ }
50
+ currentTrack = track;
51
+ }
52
+ onModeChange();
53
+ return listenEvent(tracks, "mode-change", onModeChange);
54
+ }
55
+ function watchCueTextChange(tracks, kind, callback) {
56
+ watchActiveTextTrack(tracks, kind, (track) => {
57
+ if (!track) {
58
+ callback("");
59
+ return;
60
+ }
61
+ const onCueChange = () => {
62
+ const activeCue = track?.activeCues[0];
63
+ callback(activeCue?.text || "");
64
+ };
65
+ onCueChange();
66
+ listenEvent(track, "cue-change", onCueChange);
67
+ });
68
+ }
69
+
70
+ class TextTrack extends EventsTarget {
71
+ static createId(track) {
72
+ return `vds-${track.type}-${track.kind}-${track.src ?? track.label ?? "?"}`;
73
+ }
74
+ src;
75
+ content;
76
+ type;
77
+ encoding;
78
+ id = "";
79
+ label = "";
80
+ language = "";
81
+ kind;
82
+ default = false;
83
+ #canLoad = false;
84
+ #currentTime = 0;
85
+ #mode = "disabled";
86
+ #metadata = {};
87
+ #regions = [];
88
+ #cues = [];
89
+ #activeCues = [];
90
+ #cueIds = /* @__PURE__ */ new Set();
91
+ /** @internal */
92
+ [TextTrackSymbol.readyState] = 0;
93
+ /** @internal */
94
+ [TextTrackSymbol.crossOrigin];
95
+ /** @internal */
96
+ [TextTrackSymbol.onModeChange] = null;
97
+ /** @internal */
98
+ [TextTrackSymbol.native] = null;
99
+ get metadata() {
100
+ return this.#metadata;
101
+ }
102
+ get regions() {
103
+ return this.#regions;
104
+ }
105
+ get cues() {
106
+ return this.#cues;
107
+ }
108
+ get activeCues() {
109
+ return this.#activeCues;
110
+ }
111
+ /**
112
+ * - 0: Not Loading
113
+ * - 1: Loading
114
+ * - 2: Ready
115
+ * - 3: Error
116
+ */
117
+ get readyState() {
118
+ return this[TextTrackSymbol.readyState];
119
+ }
120
+ get mode() {
121
+ return this.#mode;
122
+ }
123
+ set mode(mode) {
124
+ this.setMode(mode);
125
+ }
126
+ constructor(init) {
127
+ super();
128
+ for (const prop of Object.keys(init)) this[prop] = init[prop];
129
+ if (!this.type) this.type = "vtt";
130
+ if (init.content) {
131
+ this.#parseContent(init);
132
+ } else if (!init.src) {
133
+ this[TextTrackSymbol.readyState] = 2;
134
+ }
135
+ if (isTrackCaptionKind(this) && !this.label) {
136
+ console.warn(`[vidstack] captions text track created without label: \`${this.src}\``);
137
+ }
138
+ }
139
+ addCue(cue, trigger) {
140
+ if (cue.id) {
141
+ if (this.#cueIds.has(cue.id)) return;
142
+ this.#cueIds.add(cue.id);
143
+ }
144
+ let i = 0, length = this.#cues.length;
145
+ for (i = 0; i < length; i++) if (cue.endTime <= this.#cues[i].startTime) break;
146
+ if (i === length) this.#cues.push(cue);
147
+ else this.#cues.splice(i, 0, cue);
148
+ if (!(cue instanceof TextTrackCue)) {
149
+ this[TextTrackSymbol.native]?.track.addCue(cue);
150
+ }
151
+ this.dispatchEvent(new DOMEvent("add-cue", { detail: cue, trigger }));
152
+ if (isCueActive(cue, this.#currentTime)) {
153
+ this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
154
+ }
155
+ }
156
+ removeCue(cue, trigger) {
157
+ const index = this.#cues.indexOf(cue);
158
+ if (index >= 0) {
159
+ const isActive = this.#activeCues.includes(cue);
160
+ if (cue.id) this.#cueIds.delete(cue.id);
161
+ this.#cues.splice(index, 1);
162
+ this[TextTrackSymbol.native]?.track.removeCue(cue);
163
+ this.dispatchEvent(new DOMEvent("remove-cue", { detail: cue, trigger }));
164
+ if (isActive) {
165
+ this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
166
+ }
167
+ }
168
+ }
169
+ setMode(mode, trigger) {
170
+ if (this.#mode === mode) return;
171
+ this.#mode = mode;
172
+ if (mode === "disabled") {
173
+ this.#activeCues = [];
174
+ this.#activeCuesChanged();
175
+ } else if (this.readyState === 2) {
176
+ this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
177
+ } else {
178
+ this.#load();
179
+ }
180
+ this.dispatchEvent(new DOMEvent("mode-change", { detail: this, trigger }));
181
+ this[TextTrackSymbol.onModeChange]?.();
182
+ }
183
+ /** @internal */
184
+ [TextTrackSymbol.updateActiveCues](currentTime, trigger) {
185
+ this.#currentTime = currentTime;
186
+ if (this.mode === "disabled" || !this.#cues.length) return;
187
+ const activeCues = [];
188
+ for (let i = 0, length = this.#cues.length; i < length; i++) {
189
+ const cue = this.#cues[i];
190
+ if (isCueActive(cue, currentTime)) activeCues.push(cue);
191
+ }
192
+ let changed = activeCues.length !== this.#activeCues.length;
193
+ if (!changed) {
194
+ for (let i = 0; i < activeCues.length; i++) {
195
+ if (!this.#activeCues.includes(activeCues[i])) {
196
+ changed = true;
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ this.#activeCues = activeCues;
202
+ if (changed) this.#activeCuesChanged(trigger);
203
+ }
204
+ /** @internal */
205
+ [TextTrackSymbol.canLoad]() {
206
+ this.#canLoad = true;
207
+ if (this.#mode !== "disabled") this.#load();
208
+ }
209
+ #parseContent(init) {
210
+ import('media-captions').then(({ parseText, VTTCue, VTTRegion }) => {
211
+ if (!isString(init.content) || init.type === "json") {
212
+ this.#parseJSON(init.content, VTTCue, VTTRegion);
213
+ if (this.readyState !== 3) this.#ready();
214
+ } else {
215
+ const content = init.content.split("\n").map((line) => line.trim()).join("\n").trim();
216
+ parseText(content, { type: init.type }).then(({ cues, regions }) => {
217
+ this.#cues = cues;
218
+ this.#regions = regions;
219
+ this.#ready();
220
+ });
221
+ }
222
+ });
223
+ }
224
+ async #load() {
225
+ if (!this.#canLoad || this[TextTrackSymbol.readyState] > 0) return;
226
+ this[TextTrackSymbol.readyState] = 1;
227
+ this.dispatchEvent(new DOMEvent("load-start"));
228
+ if (!this.src) {
229
+ this.#ready();
230
+ return;
231
+ }
232
+ try {
233
+ const { parseResponse, VTTCue, VTTRegion } = await import('media-captions'), crossOrigin = this[TextTrackSymbol.crossOrigin]?.();
234
+ const response = fetch(this.src, {
235
+ headers: this.type === "json" ? { "Content-Type": "application/json" } : void 0,
236
+ credentials: getRequestCredentials(crossOrigin)
237
+ });
238
+ if (this.type === "json") {
239
+ this.#parseJSON(await (await response).text(), VTTCue, VTTRegion);
240
+ } else {
241
+ const { errors, metadata, regions, cues } = await parseResponse(response, {
242
+ type: this.type,
243
+ encoding: this.encoding
244
+ });
245
+ if (errors[0]?.code === 0) {
246
+ throw errors[0];
247
+ } else {
248
+ this.#metadata = metadata;
249
+ this.#regions = regions;
250
+ this.#cues = cues;
251
+ }
252
+ }
253
+ this.#ready();
254
+ } catch (error) {
255
+ this.#error(error);
256
+ }
257
+ }
258
+ #ready() {
259
+ this[TextTrackSymbol.readyState] = 2;
260
+ if (!this.src || this.type !== "vtt") {
261
+ const native = this[TextTrackSymbol.native];
262
+ if (native && !native.managed) {
263
+ for (const cue of this.#cues) native.track.addCue(cue);
264
+ }
265
+ }
266
+ const loadEvent = new DOMEvent("load");
267
+ this[TextTrackSymbol.updateActiveCues](this.#currentTime, loadEvent);
268
+ this.dispatchEvent(loadEvent);
269
+ }
270
+ #error(error) {
271
+ this[TextTrackSymbol.readyState] = 3;
272
+ this.dispatchEvent(new DOMEvent("error", { detail: error }));
273
+ }
274
+ #parseJSON(json, VTTCue, VTTRegion) {
275
+ try {
276
+ const { regions, cues } = parseJSONCaptionsFile(json, VTTCue, VTTRegion);
277
+ this.#regions = regions;
278
+ this.#cues = cues;
279
+ } catch (error) {
280
+ {
281
+ console.error(`[vidstack] failed to parse JSON captions at: \`${this.src}\`
282
+
283
+ `, error);
284
+ }
285
+ this.#error(error);
286
+ }
287
+ }
288
+ #activeCuesChanged(trigger) {
289
+ this.dispatchEvent(new DOMEvent("cue-change", { trigger }));
290
+ }
291
+ }
292
+ const captionRE = /captions|subtitles/;
293
+ function isTrackCaptionKind(track) {
294
+ return captionRE.test(track.kind);
295
+ }
296
+ function parseJSONCaptionsFile(json, Cue, Region) {
297
+ const content = isString(json) ? JSON.parse(json) : json;
298
+ let regions = [], cues = [];
299
+ if (content.regions && Region) {
300
+ regions = content.regions.map((region) => Object.assign(new Region(), region));
301
+ }
302
+ if (content.cues || isArray(content)) {
303
+ cues = (isArray(content) ? content : content.cues).filter((content2) => isNumber(content2.startTime) && isNumber(content2.endTime)).map((cue) => Object.assign(new Cue(0, 0, ""), cue));
304
+ }
305
+ return { regions, cues };
306
+ }
307
+
308
+ export { TextTrack, TextTrackSymbol, findActiveCue, isCueActive, isTrackCaptionKind, parseJSONCaptionsFile, watchActiveTextTrack, watchCueTextChange };