@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.
- package/cdn/chunks/vidstack-8JHLDxl5.js +1 -0
- package/cdn/chunks/vidstack-Bpnl-N6k.js +1 -0
- package/cdn/chunks/vidstack-CnWKPIKT.js +16 -0
- package/cdn/chunks/vidstack-CqzAnF2W.js +16 -0
- package/cdn/vidstack.js +1 -1
- package/cdn/with-layouts/chunks/vidstack-BD5YoTt5.js +937 -0
- package/cdn/with-layouts/chunks/vidstack-DCaNJN4T.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-Dd3L-eQj.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-T2rZVigk.js +912 -0
- package/cdn/with-layouts/vidstack.js +1 -1
- package/dev/chunks/vidstack--aukHYxl.js +1520 -0
- package/dev/chunks/vidstack-B__DfQsT.js +1621 -0
- package/dev/chunks/vidstack-BoLIUOyq.js +204 -0
- package/dev/chunks/vidstack-CSryZFvY.js +1521 -0
- package/dev/chunks/vidstack-Cky9ors4.js +297 -0
- package/dev/chunks/vidstack-Crz0ROkT.js +3009 -0
- package/dev/chunks/vidstack-D-sqb6YI.js +308 -0
- package/dev/chunks/vidstack-DLXCqdYV.js +3010 -0
- package/dev/chunks/vidstack-DS7nRfge.js +204 -0
- package/dev/chunks/vidstack-Dco6kA4h.js +104 -0
- package/dev/chunks/vidstack-DpS0Kt4b.js +297 -0
- package/dev/chunks/vidstack-zJT-7ncH.js +5182 -0
- package/dev/define/plyr-layout.js +3 -4
- package/dev/define/templates/vidstack-audio-layout.js +4 -4
- package/dev/define/templates/vidstack-video-layout.js +4 -4
- package/dev/define/vidstack-player-default-layout.js +4 -4
- package/dev/define/vidstack-player-layouts.js +4 -4
- package/dev/define/vidstack-player-ui.js +5 -6
- package/dev/define/vidstack-player.js +3 -4
- package/dev/global/plyr.js +5 -6
- package/dev/global/vidstack-player.js +3 -4
- package/dev/providers/vidstack-dash.js +1 -2
- package/dev/providers/vidstack-hls.js +1 -2
- package/dev/providers/vidstack-video.js +1 -2
- package/dev/providers/vidstack-vimeo.js +1 -2
- package/dev/vidstack-elements.js +8 -9
- package/dev/vidstack.js +6 -7
- package/package.json +2 -1
- package/prod/chunks/vidstack-BVSJtdRd.js +297 -0
- package/prod/chunks/vidstack-BnEo_Sla.js +1621 -0
- package/prod/chunks/vidstack-CFXAYpuh.js +1521 -0
- package/prod/chunks/vidstack-CIvL96_j.js +297 -0
- package/prod/chunks/vidstack-CLTPjjXX.js +4772 -0
- package/prod/chunks/vidstack-CSHHV2zO.js +201 -0
- package/prod/chunks/vidstack-CYVCrFjx.js +201 -0
- package/prod/chunks/vidstack-D_atbNqH.js +3000 -0
- package/prod/chunks/vidstack-Eo46ZHu7.js +2999 -0
- package/prod/chunks/vidstack-sP7TQMB1.js +300 -0
- package/prod/chunks/vidstack-uVm3xX8H.js +104 -0
- package/prod/chunks/vidstack-zknLxihl.js +1520 -0
- package/prod/define/plyr-layout.js +3 -4
- package/prod/define/templates/vidstack-audio-layout.js +4 -4
- package/prod/define/templates/vidstack-video-layout.js +4 -4
- package/prod/define/vidstack-player-default-layout.js +4 -4
- package/prod/define/vidstack-player-layouts.js +4 -4
- package/prod/define/vidstack-player-ui.js +5 -6
- package/prod/define/vidstack-player.js +3 -4
- package/prod/global/plyr.js +5 -6
- package/prod/global/vidstack-player.js +3 -4
- package/prod/providers/vidstack-dash.js +1 -2
- package/prod/providers/vidstack-hls.js +1 -2
- package/prod/providers/vidstack-video.js +1 -2
- package/prod/providers/vidstack-vimeo.js +1 -2
- package/prod/vidstack-elements.js +8 -9
- package/prod/vidstack.js +6 -7
- package/server/chunks/vidstack-B3eA67nX.js +205 -0
- package/server/chunks/vidstack-B8P1aUCK.js +1503 -0
- package/server/chunks/vidstack-B8_v1VQn.js +3059 -0
- package/server/chunks/vidstack-BK4xGWUK.js +207 -0
- package/server/chunks/vidstack-BO8FLks6.js +295 -0
- package/server/chunks/vidstack-BaXvZgx2.js +141 -0
- package/server/chunks/vidstack-BlvJg_5A.js +4636 -0
- package/server/chunks/vidstack-CBhikwSz.js +67 -0
- package/server/chunks/vidstack-COczNXom.js +3059 -0
- package/server/chunks/vidstack-CyZPtpwO.js +1503 -0
- package/server/chunks/vidstack-Db22EuE_.js +207 -0
- package/server/chunks/vidstack-Dh1ZDEI-.js +29 -0
- package/server/chunks/vidstack-Dm-ETAZh.js +295 -0
- package/server/chunks/vidstack-NpAD9hfP.js +620 -0
- package/server/chunks/vidstack-O4BgIcQI.js +104 -0
- package/server/chunks/vidstack-n4zAyLEV.js +2139 -0
- package/server/chunks/vidstack-za5Yh5DQ.js +566 -0
- package/server/chunks/vidstack-zoXyfYxa.js +107 -0
- package/server/define/plyr-layout.js +7 -7
- package/server/define/vidstack-player-default-layout.js +3 -3
- package/server/define/vidstack-player-layouts.js +5 -5
- package/server/define/vidstack-player-ui.js +6 -6
- package/server/define/vidstack-player.js +4 -4
- package/server/global/plyr.js +9 -9
- package/server/global/vidstack-player.js +4 -4
- package/server/vidstack-elements.js +13 -13
- package/server/vidstack.js +8 -8
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
import { isString, deferredPromise, isNull, isBoolean, listenEvent, scoped, getScope, EventsTarget, DOMEvent, isArray, isNumber, useContext, createContext, EventsController, isKeyboardClick, isTouchEvent, effect, isFunction, setAttribute, setStyle, isDOMNode, onDispose, toggleClass, animationFrameThrottle, signal, computed } from './vidstack-B8LynzY5.js';
|
|
2
|
+
import { autoUpdate, computePosition, flip, shift } from '@floating-ui/dom';
|
|
3
|
+
|
|
4
|
+
const AUDIO_EXTENSIONS = /\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx|flac)($|\?)/i;
|
|
5
|
+
const AUDIO_TYPES = /* @__PURE__ */ new Set([
|
|
6
|
+
"audio/mpeg",
|
|
7
|
+
"audio/ogg",
|
|
8
|
+
"audio/3gp",
|
|
9
|
+
"audio/mp3",
|
|
10
|
+
"audio/webm",
|
|
11
|
+
"audio/flac",
|
|
12
|
+
"audio/m4a",
|
|
13
|
+
"audio/m4b",
|
|
14
|
+
"audio/mp4a",
|
|
15
|
+
"audio/mp4"
|
|
16
|
+
]);
|
|
17
|
+
const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i;
|
|
18
|
+
const VIDEO_TYPES = /* @__PURE__ */ new Set([
|
|
19
|
+
"video/mp4",
|
|
20
|
+
"video/webm",
|
|
21
|
+
"video/3gp",
|
|
22
|
+
"video/ogg",
|
|
23
|
+
"video/avi",
|
|
24
|
+
"video/mpeg"
|
|
25
|
+
]);
|
|
26
|
+
const HLS_VIDEO_EXTENSIONS = /\.(m3u8)($|\?)/i;
|
|
27
|
+
const DASH_VIDEO_EXTENSIONS = /\.(mpd)($|\?)/i;
|
|
28
|
+
const HLS_VIDEO_TYPES = /* @__PURE__ */ new Set([
|
|
29
|
+
// Apple sanctioned
|
|
30
|
+
"application/vnd.apple.mpegurl",
|
|
31
|
+
// Apple sanctioned for backwards compatibility
|
|
32
|
+
"audio/mpegurl",
|
|
33
|
+
// Very common
|
|
34
|
+
"audio/x-mpegurl",
|
|
35
|
+
// Very common
|
|
36
|
+
"application/x-mpegurl",
|
|
37
|
+
// Included for completeness
|
|
38
|
+
"video/x-mpegurl",
|
|
39
|
+
"video/mpegurl",
|
|
40
|
+
"application/mpegurl"
|
|
41
|
+
]);
|
|
42
|
+
const DASH_VIDEO_TYPES = /* @__PURE__ */ new Set(["application/dash+xml"]);
|
|
43
|
+
function isAudioSrc({ src, type }) {
|
|
44
|
+
return isString(src) ? AUDIO_EXTENSIONS.test(src) || AUDIO_TYPES.has(type) || src.startsWith("blob:") && type === "audio/object" : type === "audio/object";
|
|
45
|
+
}
|
|
46
|
+
function isVideoSrc(src) {
|
|
47
|
+
return isString(src.src) ? VIDEO_EXTENSIONS.test(src.src) || VIDEO_TYPES.has(src.type) || src.src.startsWith("blob:") && src.type === "video/object" || isHLSSrc(src) && true : src.type === "video/object";
|
|
48
|
+
}
|
|
49
|
+
function isHLSSrc({ src, type }) {
|
|
50
|
+
return isString(src) && HLS_VIDEO_EXTENSIONS.test(src) || HLS_VIDEO_TYPES.has(type);
|
|
51
|
+
}
|
|
52
|
+
function isDASHSrc({ src, type }) {
|
|
53
|
+
return isString(src) && DASH_VIDEO_EXTENSIONS.test(src) || DASH_VIDEO_TYPES.has(type);
|
|
54
|
+
}
|
|
55
|
+
function canGoogleCastSrc(src) {
|
|
56
|
+
return isString(src.src) && (isAudioSrc(src) || isVideoSrc(src) || isHLSSrc(src));
|
|
57
|
+
}
|
|
58
|
+
function isMediaStream(src) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function appendParamsToURL(baseUrl, params) {
|
|
63
|
+
const url = new URL(baseUrl);
|
|
64
|
+
for (const key of Object.keys(params)) {
|
|
65
|
+
url.searchParams.set(key, params[key] + "");
|
|
66
|
+
}
|
|
67
|
+
return url.toString();
|
|
68
|
+
}
|
|
69
|
+
function preconnect(url, rel = "preconnect") {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const pendingRequests = {};
|
|
73
|
+
function loadScript(src) {
|
|
74
|
+
if (pendingRequests[src]) return pendingRequests[src].promise;
|
|
75
|
+
const promise = deferredPromise(), exists = document.querySelector(`script[src="${src}"]`);
|
|
76
|
+
if (!isNull(exists)) {
|
|
77
|
+
promise.resolve();
|
|
78
|
+
return promise.promise;
|
|
79
|
+
}
|
|
80
|
+
pendingRequests[src] = promise;
|
|
81
|
+
const script = document.createElement("script");
|
|
82
|
+
script.src = src;
|
|
83
|
+
script.onload = () => {
|
|
84
|
+
promise.resolve();
|
|
85
|
+
delete pendingRequests[src];
|
|
86
|
+
};
|
|
87
|
+
script.onerror = () => {
|
|
88
|
+
promise.reject();
|
|
89
|
+
delete pendingRequests[src];
|
|
90
|
+
};
|
|
91
|
+
setTimeout(() => document.head.append(script), 0);
|
|
92
|
+
return promise.promise;
|
|
93
|
+
}
|
|
94
|
+
function getRequestCredentials(crossOrigin) {
|
|
95
|
+
return crossOrigin === "use-credentials" ? "include" : isString(crossOrigin) ? "same-origin" : void 0;
|
|
96
|
+
}
|
|
97
|
+
function getDownloadFile({
|
|
98
|
+
title,
|
|
99
|
+
src,
|
|
100
|
+
download
|
|
101
|
+
}) {
|
|
102
|
+
const url = isBoolean(download) || download === "" ? src.src : isString(download) ? download : download?.url;
|
|
103
|
+
if (!isValidFileDownload({ url, src, download })) return null;
|
|
104
|
+
return {
|
|
105
|
+
url,
|
|
106
|
+
name: !isBoolean(download) && !isString(download) && download?.filename || title.toLowerCase() || "media"
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function isValidFileDownload({
|
|
110
|
+
url,
|
|
111
|
+
src,
|
|
112
|
+
download
|
|
113
|
+
}) {
|
|
114
|
+
return isString(url) && (download && download !== true || isAudioSrc(src) || isVideoSrc(src));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const CROSS_ORIGIN = Symbol(0), READY_STATE = Symbol(0), UPDATE_ACTIVE_CUES = Symbol(0), CAN_LOAD = Symbol(0), ON_MODE_CHANGE = Symbol(0), NATIVE = Symbol(0), NATIVE_HLS = Symbol(0);
|
|
118
|
+
const TextTrackSymbol = {
|
|
119
|
+
crossOrigin: CROSS_ORIGIN,
|
|
120
|
+
readyState: READY_STATE,
|
|
121
|
+
updateActiveCues: UPDATE_ACTIVE_CUES,
|
|
122
|
+
canLoad: CAN_LOAD,
|
|
123
|
+
onModeChange: ON_MODE_CHANGE,
|
|
124
|
+
native: NATIVE,
|
|
125
|
+
nativeHLS: NATIVE_HLS
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
function findActiveCue(cues, time) {
|
|
129
|
+
for (let i = 0, len = cues.length; i < len; i++) {
|
|
130
|
+
if (isCueActive(cues[i], time)) return cues[i];
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
function isCueActive(cue, time) {
|
|
135
|
+
return time >= cue.startTime && time < cue.endTime;
|
|
136
|
+
}
|
|
137
|
+
function watchActiveTextTrack(tracks, kind, onChange) {
|
|
138
|
+
let currentTrack = null, scope = getScope();
|
|
139
|
+
function onModeChange() {
|
|
140
|
+
const kinds = isString(kind) ? [kind] : kind, track = tracks.toArray().find((track2) => kinds.includes(track2.kind) && track2.mode === "showing");
|
|
141
|
+
if (track === currentTrack) return;
|
|
142
|
+
if (!track) {
|
|
143
|
+
onChange(null);
|
|
144
|
+
currentTrack = null;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (track.readyState == 2) {
|
|
148
|
+
onChange(track);
|
|
149
|
+
} else {
|
|
150
|
+
onChange(null);
|
|
151
|
+
scoped(() => {
|
|
152
|
+
}, scope);
|
|
153
|
+
}
|
|
154
|
+
currentTrack = track;
|
|
155
|
+
}
|
|
156
|
+
onModeChange();
|
|
157
|
+
return listenEvent();
|
|
158
|
+
}
|
|
159
|
+
function watchCueTextChange(tracks, kind, callback) {
|
|
160
|
+
watchActiveTextTrack(tracks, kind, (track) => {
|
|
161
|
+
if (!track) {
|
|
162
|
+
callback("");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const onCueChange = () => {
|
|
166
|
+
const activeCue = track?.activeCues[0];
|
|
167
|
+
callback(activeCue?.text || "");
|
|
168
|
+
};
|
|
169
|
+
onCueChange();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
class TextTrack extends EventsTarget {
|
|
174
|
+
static createId(track) {
|
|
175
|
+
return `vds-${track.type}-${track.kind}-${track.src ?? track.label ?? "?"}`;
|
|
176
|
+
}
|
|
177
|
+
src;
|
|
178
|
+
content;
|
|
179
|
+
type;
|
|
180
|
+
encoding;
|
|
181
|
+
id = "";
|
|
182
|
+
label = "";
|
|
183
|
+
language = "";
|
|
184
|
+
kind;
|
|
185
|
+
default = false;
|
|
186
|
+
#canLoad = false;
|
|
187
|
+
#currentTime = 0;
|
|
188
|
+
#mode = "disabled";
|
|
189
|
+
#metadata = {};
|
|
190
|
+
#regions = [];
|
|
191
|
+
#cues = [];
|
|
192
|
+
#activeCues = [];
|
|
193
|
+
#cueIds = /* @__PURE__ */ new Set();
|
|
194
|
+
/** @internal */
|
|
195
|
+
[TextTrackSymbol.readyState] = 0;
|
|
196
|
+
/** @internal */
|
|
197
|
+
[TextTrackSymbol.crossOrigin];
|
|
198
|
+
/** @internal */
|
|
199
|
+
[TextTrackSymbol.onModeChange] = null;
|
|
200
|
+
/** @internal */
|
|
201
|
+
[TextTrackSymbol.native] = null;
|
|
202
|
+
get metadata() {
|
|
203
|
+
return this.#metadata;
|
|
204
|
+
}
|
|
205
|
+
get regions() {
|
|
206
|
+
return this.#regions;
|
|
207
|
+
}
|
|
208
|
+
get cues() {
|
|
209
|
+
return this.#cues;
|
|
210
|
+
}
|
|
211
|
+
get activeCues() {
|
|
212
|
+
return this.#activeCues;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* - 0: Not Loading
|
|
216
|
+
* - 1: Loading
|
|
217
|
+
* - 2: Ready
|
|
218
|
+
* - 3: Error
|
|
219
|
+
*/
|
|
220
|
+
get readyState() {
|
|
221
|
+
return this[TextTrackSymbol.readyState];
|
|
222
|
+
}
|
|
223
|
+
get mode() {
|
|
224
|
+
return this.#mode;
|
|
225
|
+
}
|
|
226
|
+
set mode(mode) {
|
|
227
|
+
this.setMode(mode);
|
|
228
|
+
}
|
|
229
|
+
constructor(init) {
|
|
230
|
+
super();
|
|
231
|
+
for (const prop of Object.keys(init)) this[prop] = init[prop];
|
|
232
|
+
if (!this.type) this.type = "vtt";
|
|
233
|
+
if (!init.src) {
|
|
234
|
+
this[TextTrackSymbol.readyState] = 2;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
addCue(cue, trigger) {
|
|
238
|
+
if (cue.id) {
|
|
239
|
+
if (this.#cueIds.has(cue.id)) return;
|
|
240
|
+
this.#cueIds.add(cue.id);
|
|
241
|
+
}
|
|
242
|
+
let i = 0, length = this.#cues.length;
|
|
243
|
+
for (i = 0; i < length; i++) if (cue.endTime <= this.#cues[i].startTime) break;
|
|
244
|
+
if (i === length) this.#cues.push(cue);
|
|
245
|
+
else this.#cues.splice(i, 0, cue);
|
|
246
|
+
if (!(cue instanceof TextTrackCue)) {
|
|
247
|
+
this[TextTrackSymbol.native]?.track.addCue(cue);
|
|
248
|
+
}
|
|
249
|
+
this.dispatchEvent(new DOMEvent("add-cue", { detail: cue, trigger }));
|
|
250
|
+
if (isCueActive(cue, this.#currentTime)) {
|
|
251
|
+
this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
removeCue(cue, trigger) {
|
|
255
|
+
const index = this.#cues.indexOf(cue);
|
|
256
|
+
if (index >= 0) {
|
|
257
|
+
const isActive = this.#activeCues.includes(cue);
|
|
258
|
+
if (cue.id) this.#cueIds.delete(cue.id);
|
|
259
|
+
this.#cues.splice(index, 1);
|
|
260
|
+
this[TextTrackSymbol.native]?.track.removeCue(cue);
|
|
261
|
+
this.dispatchEvent(new DOMEvent("remove-cue", { detail: cue, trigger }));
|
|
262
|
+
if (isActive) {
|
|
263
|
+
this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
setMode(mode, trigger) {
|
|
268
|
+
if (this.#mode === mode) return;
|
|
269
|
+
this.#mode = mode;
|
|
270
|
+
if (mode === "disabled") {
|
|
271
|
+
this.#activeCues = [];
|
|
272
|
+
this.#activeCuesChanged();
|
|
273
|
+
} else if (this.readyState === 2) {
|
|
274
|
+
this[TextTrackSymbol.updateActiveCues](this.#currentTime, trigger);
|
|
275
|
+
} else {
|
|
276
|
+
this.#load();
|
|
277
|
+
}
|
|
278
|
+
this.dispatchEvent(new DOMEvent("mode-change", { detail: this, trigger }));
|
|
279
|
+
this[TextTrackSymbol.onModeChange]?.();
|
|
280
|
+
}
|
|
281
|
+
/** @internal */
|
|
282
|
+
[TextTrackSymbol.updateActiveCues](currentTime, trigger) {
|
|
283
|
+
this.#currentTime = currentTime;
|
|
284
|
+
if (this.mode === "disabled" || !this.#cues.length) return;
|
|
285
|
+
const activeCues = [];
|
|
286
|
+
for (let i = 0, length = this.#cues.length; i < length; i++) {
|
|
287
|
+
const cue = this.#cues[i];
|
|
288
|
+
if (isCueActive(cue, currentTime)) activeCues.push(cue);
|
|
289
|
+
}
|
|
290
|
+
let changed = activeCues.length !== this.#activeCues.length;
|
|
291
|
+
if (!changed) {
|
|
292
|
+
for (let i = 0; i < activeCues.length; i++) {
|
|
293
|
+
if (!this.#activeCues.includes(activeCues[i])) {
|
|
294
|
+
changed = true;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
this.#activeCues = activeCues;
|
|
300
|
+
if (changed) this.#activeCuesChanged(trigger);
|
|
301
|
+
}
|
|
302
|
+
/** @internal */
|
|
303
|
+
[TextTrackSymbol.canLoad]() {
|
|
304
|
+
this.#canLoad = true;
|
|
305
|
+
if (this.#mode !== "disabled") this.#load();
|
|
306
|
+
}
|
|
307
|
+
#parseContent(init) {
|
|
308
|
+
import('media-captions').then(({ parseText, VTTCue, VTTRegion }) => {
|
|
309
|
+
if (!isString(init.content) || init.type === "json") {
|
|
310
|
+
this.#parseJSON(init.content, VTTCue, VTTRegion);
|
|
311
|
+
if (this.readyState !== 3) this.#ready();
|
|
312
|
+
} else {
|
|
313
|
+
const content = init.content.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
314
|
+
parseText(content, { type: init.type }).then(({ cues, regions }) => {
|
|
315
|
+
this.#cues = cues;
|
|
316
|
+
this.#regions = regions;
|
|
317
|
+
this.#ready();
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async #load() {
|
|
323
|
+
if (!this.#canLoad || this[TextTrackSymbol.readyState] > 0) return;
|
|
324
|
+
this[TextTrackSymbol.readyState] = 1;
|
|
325
|
+
this.dispatchEvent(new DOMEvent("load-start"));
|
|
326
|
+
if (!this.src) {
|
|
327
|
+
this.#ready();
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
const { parseResponse, VTTCue, VTTRegion } = await import('media-captions'), crossOrigin = this[TextTrackSymbol.crossOrigin]?.();
|
|
332
|
+
const response = fetch(this.src, {
|
|
333
|
+
headers: this.type === "json" ? { "Content-Type": "application/json" } : void 0,
|
|
334
|
+
credentials: getRequestCredentials(crossOrigin)
|
|
335
|
+
});
|
|
336
|
+
if (this.type === "json") {
|
|
337
|
+
this.#parseJSON(await (await response).text(), VTTCue, VTTRegion);
|
|
338
|
+
} else {
|
|
339
|
+
const { errors, metadata, regions, cues } = await parseResponse(response, {
|
|
340
|
+
type: this.type,
|
|
341
|
+
encoding: this.encoding
|
|
342
|
+
});
|
|
343
|
+
if (errors[0]?.code === 0) {
|
|
344
|
+
throw errors[0];
|
|
345
|
+
} else {
|
|
346
|
+
this.#metadata = metadata;
|
|
347
|
+
this.#regions = regions;
|
|
348
|
+
this.#cues = cues;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
this.#ready();
|
|
352
|
+
} catch (error) {
|
|
353
|
+
this.#error(error);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
#ready() {
|
|
357
|
+
this[TextTrackSymbol.readyState] = 2;
|
|
358
|
+
if (!this.src || this.type !== "vtt") {
|
|
359
|
+
const native = this[TextTrackSymbol.native];
|
|
360
|
+
if (native && !native.managed) {
|
|
361
|
+
for (const cue of this.#cues) native.track.addCue(cue);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const loadEvent = new DOMEvent("load");
|
|
365
|
+
this[TextTrackSymbol.updateActiveCues](this.#currentTime, loadEvent);
|
|
366
|
+
this.dispatchEvent(loadEvent);
|
|
367
|
+
}
|
|
368
|
+
#error(error) {
|
|
369
|
+
this[TextTrackSymbol.readyState] = 3;
|
|
370
|
+
this.dispatchEvent(new DOMEvent("error", { detail: error }));
|
|
371
|
+
}
|
|
372
|
+
#parseJSON(json, VTTCue, VTTRegion) {
|
|
373
|
+
try {
|
|
374
|
+
const { regions, cues } = parseJSONCaptionsFile(json, VTTCue, VTTRegion);
|
|
375
|
+
this.#regions = regions;
|
|
376
|
+
this.#cues = cues;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
this.#error(error);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
#activeCuesChanged(trigger) {
|
|
382
|
+
this.dispatchEvent(new DOMEvent("cue-change", { trigger }));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const captionRE = /captions|subtitles/;
|
|
386
|
+
function isTrackCaptionKind(track) {
|
|
387
|
+
return captionRE.test(track.kind);
|
|
388
|
+
}
|
|
389
|
+
function parseJSONCaptionsFile(json, Cue, Region) {
|
|
390
|
+
const content = isString(json) ? JSON.parse(json) : json;
|
|
391
|
+
let regions = [], cues = [];
|
|
392
|
+
if (content.regions && Region) {
|
|
393
|
+
regions = content.regions.map((region) => Object.assign(new Region(), region));
|
|
394
|
+
}
|
|
395
|
+
if (content.cues || isArray(content)) {
|
|
396
|
+
cues = (isArray(content) ? content : content.cues).filter((content2) => isNumber(content2.startTime) && isNumber(content2.endTime)).map((cue) => Object.assign(new Cue(0, 0, ""), cue));
|
|
397
|
+
}
|
|
398
|
+
return { regions, cues };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const mediaContext = createContext();
|
|
402
|
+
function useMediaContext() {
|
|
403
|
+
return useContext(mediaContext);
|
|
404
|
+
}
|
|
405
|
+
function useMediaState() {
|
|
406
|
+
return useMediaContext().$state;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function isEventInside(el, event) {
|
|
410
|
+
const target = event.composedPath()[0];
|
|
411
|
+
return isDOMNode(target) && el.contains(target);
|
|
412
|
+
}
|
|
413
|
+
const rafJobs = /* @__PURE__ */ new Set();
|
|
414
|
+
function scheduleRafJob(job) {
|
|
415
|
+
rafJobs.add(job);
|
|
416
|
+
return () => rafJobs.delete(job);
|
|
417
|
+
}
|
|
418
|
+
function setAttributeIfEmpty(target, name, value) {
|
|
419
|
+
if (!target.hasAttribute(name)) target.setAttribute(name, value);
|
|
420
|
+
}
|
|
421
|
+
function setARIALabel(target, $label) {
|
|
422
|
+
if (target.hasAttribute("aria-label") || target.hasAttribute("data-no-label")) return;
|
|
423
|
+
if (!isFunction($label)) {
|
|
424
|
+
setAttribute(target, "aria-label", $label);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
function updateAriaDescription() {
|
|
428
|
+
setAttribute(target, "aria-label", $label());
|
|
429
|
+
}
|
|
430
|
+
updateAriaDescription();
|
|
431
|
+
}
|
|
432
|
+
function isElementVisible(el) {
|
|
433
|
+
const style = getComputedStyle(el);
|
|
434
|
+
return style.display !== "none" && parseInt(style.opacity) > 0;
|
|
435
|
+
}
|
|
436
|
+
function checkVisibility(el) {
|
|
437
|
+
return !!el && ("checkVisibility" in el ? el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) : isElementVisible(el));
|
|
438
|
+
}
|
|
439
|
+
function observeVisibility(el, callback) {
|
|
440
|
+
return scheduleRafJob(() => callback(checkVisibility(el)));
|
|
441
|
+
}
|
|
442
|
+
function isElementParent(owner, node, test) {
|
|
443
|
+
while (node) {
|
|
444
|
+
if (node === owner) {
|
|
445
|
+
return true;
|
|
446
|
+
} else if (test?.(node)) {
|
|
447
|
+
break;
|
|
448
|
+
} else {
|
|
449
|
+
node = node.parentElement;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
function onPress(target, handler) {
|
|
455
|
+
return new EventsController(target).add("pointerup", (event) => {
|
|
456
|
+
if (event.button === 0 && !event.defaultPrevented) handler(event);
|
|
457
|
+
}).add("keydown", (event) => {
|
|
458
|
+
if (isKeyboardClick(event)) handler(event);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function isTouchPinchEvent(event) {
|
|
462
|
+
return isTouchEvent(event) && (event.touches.length > 1 || event.changedTouches.length > 1);
|
|
463
|
+
}
|
|
464
|
+
function requestScopedAnimationFrame(callback) {
|
|
465
|
+
return callback();
|
|
466
|
+
}
|
|
467
|
+
function cloneTemplate(template, length, onCreate) {
|
|
468
|
+
let current, prev = template, parent = template.parentElement, content = template.content.firstElementChild, elements = [];
|
|
469
|
+
if (!content && template.firstElementChild) {
|
|
470
|
+
template.innerHTML = template.firstElementChild.outerHTML;
|
|
471
|
+
template.firstElementChild.remove();
|
|
472
|
+
content = template.content.firstElementChild;
|
|
473
|
+
}
|
|
474
|
+
for (let i = 0; i < length; i++) {
|
|
475
|
+
current = document.importNode(content, true);
|
|
476
|
+
onCreate?.(current, i);
|
|
477
|
+
parent.insertBefore(current, prev.nextSibling);
|
|
478
|
+
elements.push(current);
|
|
479
|
+
prev = current;
|
|
480
|
+
}
|
|
481
|
+
onDispose(() => {
|
|
482
|
+
for (let i = 0; i < elements.length; i++) elements[i].remove();
|
|
483
|
+
});
|
|
484
|
+
return elements;
|
|
485
|
+
}
|
|
486
|
+
function createTemplate(content) {
|
|
487
|
+
const template = document.createElement("template");
|
|
488
|
+
template.innerHTML = content;
|
|
489
|
+
return template.content;
|
|
490
|
+
}
|
|
491
|
+
function cloneTemplateContent(content) {
|
|
492
|
+
const fragment = content.cloneNode(true);
|
|
493
|
+
return fragment.firstElementChild;
|
|
494
|
+
}
|
|
495
|
+
function autoPlacement(el, trigger, placement, {
|
|
496
|
+
offsetVarName,
|
|
497
|
+
xOffset,
|
|
498
|
+
yOffset,
|
|
499
|
+
...options
|
|
500
|
+
}) {
|
|
501
|
+
if (!el) return;
|
|
502
|
+
const floatingPlacement = placement.replace(" ", "-").replace("-center", "");
|
|
503
|
+
setStyle(el, "visibility", !trigger ? "hidden" : null);
|
|
504
|
+
if (!trigger) return;
|
|
505
|
+
let isTop = placement.includes("top");
|
|
506
|
+
const negateX = (x) => placement.includes("left") ? `calc(-1 * ${x})` : x, negateY = (y) => isTop ? `calc(-1 * ${y})` : y;
|
|
507
|
+
return autoUpdate(trigger, el, () => {
|
|
508
|
+
computePosition(trigger, el, {
|
|
509
|
+
placement: floatingPlacement,
|
|
510
|
+
middleware: [
|
|
511
|
+
...options.middleware ?? [],
|
|
512
|
+
flip({ fallbackAxisSideDirection: "start", crossAxis: false }),
|
|
513
|
+
shift()
|
|
514
|
+
],
|
|
515
|
+
...options
|
|
516
|
+
}).then(({ x, y, middlewareData }) => {
|
|
517
|
+
const hasFlipped = !!middlewareData.flip?.index;
|
|
518
|
+
isTop = placement.includes(hasFlipped ? "bottom" : "top");
|
|
519
|
+
el.setAttribute(
|
|
520
|
+
"data-placement",
|
|
521
|
+
hasFlipped ? placement.startsWith("top") ? placement.replace("top", "bottom") : placement.replace("bottom", "top") : placement
|
|
522
|
+
);
|
|
523
|
+
Object.assign(el.style, {
|
|
524
|
+
top: `calc(${y + "px"} + ${negateY(
|
|
525
|
+
yOffset ? yOffset + "px" : `var(--${offsetVarName}-y-offset, 0px)`
|
|
526
|
+
)})`,
|
|
527
|
+
left: `calc(${x + "px"} + ${negateX(
|
|
528
|
+
xOffset ? xOffset + "px" : `var(--${offsetVarName}-x-offset, 0px)`
|
|
529
|
+
)})`
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
function hasAnimation(el) {
|
|
535
|
+
const styles = getComputedStyle(el);
|
|
536
|
+
return styles.animationName !== "none";
|
|
537
|
+
}
|
|
538
|
+
function createSlot(name) {
|
|
539
|
+
const slot = document.createElement("slot");
|
|
540
|
+
slot.name = name;
|
|
541
|
+
return slot;
|
|
542
|
+
}
|
|
543
|
+
function useTransitionActive($el) {
|
|
544
|
+
const $active = signal(false);
|
|
545
|
+
effect(() => {
|
|
546
|
+
const el = $el();
|
|
547
|
+
if (!el) return;
|
|
548
|
+
new EventsController(el).add("transitionstart", () => $active.set(true)).add("transitionend", () => $active.set(false));
|
|
549
|
+
});
|
|
550
|
+
return $active;
|
|
551
|
+
}
|
|
552
|
+
function useResizeObserver($el, onResize) {
|
|
553
|
+
function onElementChange() {
|
|
554
|
+
const el = $el();
|
|
555
|
+
if (!el) return;
|
|
556
|
+
onResize();
|
|
557
|
+
const observer = new ResizeObserver(animationFrameThrottle());
|
|
558
|
+
observer.observe(el);
|
|
559
|
+
return () => observer.disconnect();
|
|
560
|
+
}
|
|
561
|
+
effect(onElementChange);
|
|
562
|
+
}
|
|
563
|
+
function useActive($el) {
|
|
564
|
+
const $isMouseEnter = useMouseEnter($el), $isFocusedIn = useFocusIn($el);
|
|
565
|
+
let prevMouseEnter = false;
|
|
566
|
+
return computed(() => {
|
|
567
|
+
const isMouseEnter = $isMouseEnter();
|
|
568
|
+
if (prevMouseEnter && !isMouseEnter) return false;
|
|
569
|
+
prevMouseEnter = isMouseEnter;
|
|
570
|
+
return isMouseEnter || $isFocusedIn();
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
function useMouseEnter($el) {
|
|
574
|
+
const $isMouseEnter = signal(false);
|
|
575
|
+
effect(() => {
|
|
576
|
+
const el = $el();
|
|
577
|
+
if (!el) {
|
|
578
|
+
$isMouseEnter.set(false);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
new EventsController(el).add("mouseenter", () => $isMouseEnter.set(true)).add("mouseleave", () => $isMouseEnter.set(false));
|
|
582
|
+
});
|
|
583
|
+
return $isMouseEnter;
|
|
584
|
+
}
|
|
585
|
+
function useFocusIn($el) {
|
|
586
|
+
const $isFocusIn = signal(false);
|
|
587
|
+
effect(() => {
|
|
588
|
+
const el = $el();
|
|
589
|
+
if (!el) {
|
|
590
|
+
$isFocusIn.set(false);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
new EventsController(el).add("focusin", () => $isFocusIn.set(true)).add("focusout", () => $isFocusIn.set(false));
|
|
594
|
+
});
|
|
595
|
+
return $isFocusIn;
|
|
596
|
+
}
|
|
597
|
+
function isHTMLElement(el) {
|
|
598
|
+
return el instanceof HTMLElement;
|
|
599
|
+
}
|
|
600
|
+
function useColorSchemePreference() {
|
|
601
|
+
const colorScheme = signal("dark");
|
|
602
|
+
return colorScheme;
|
|
603
|
+
}
|
|
604
|
+
function watchColorScheme(el, colorScheme) {
|
|
605
|
+
effect(() => {
|
|
606
|
+
const scheme = colorScheme();
|
|
607
|
+
if (scheme === "system") {
|
|
608
|
+
const preference = useColorSchemePreference();
|
|
609
|
+
effect(() => updateColorScheme(preference()));
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
updateColorScheme(scheme);
|
|
613
|
+
});
|
|
614
|
+
function updateColorScheme(scheme) {
|
|
615
|
+
toggleClass(el, "light", scheme === "light");
|
|
616
|
+
toggleClass(el, "dark", scheme === "dark");
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export { AUDIO_EXTENSIONS, AUDIO_TYPES, DASH_VIDEO_EXTENSIONS, DASH_VIDEO_TYPES, HLS_VIDEO_EXTENSIONS, HLS_VIDEO_TYPES, TextTrack, TextTrackSymbol, VIDEO_EXTENSIONS, VIDEO_TYPES, appendParamsToURL, autoPlacement, canGoogleCastSrc, cloneTemplate, cloneTemplateContent, createSlot, createTemplate, findActiveCue, getDownloadFile, getRequestCredentials, hasAnimation, isAudioSrc, isCueActive, isDASHSrc, isElementParent, isEventInside, isHLSSrc, isHTMLElement, isMediaStream, isTouchPinchEvent, isTrackCaptionKind, isVideoSrc, loadScript, mediaContext, observeVisibility, onPress, parseJSONCaptionsFile, preconnect, requestScopedAnimationFrame, setARIALabel, setAttributeIfEmpty, useActive, useMediaContext, useMediaState, useResizeObserver, useTransitionActive, watchActiveTextTrack, watchColorScheme, watchCueTextChange };
|