@dskripchenko/ui 1.13.0 → 1.15.0

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 (46) hide show
  1. package/README.md +5 -2
  2. package/dist/components/Audio/UidAudio.vue.d.ts +127 -0
  3. package/dist/components/Audio/index.d.ts +2 -0
  4. package/dist/components/Gauge/UidGauge.vue.d.ts +1 -1
  5. package/dist/components/Grid/UidGrid.vue.d.ts +1 -1
  6. package/dist/components/Markdown/UidMarkdownLiveBlock.vue.d.ts +10 -0
  7. package/dist/components/Markdown/blockRenderers.d.ts +21 -0
  8. package/dist/components/Markdown/index.d.ts +1 -1
  9. package/dist/components/Media/UidMediaMenu.vue.d.ts +63 -0
  10. package/dist/components/Media/UidMediaScrubber.vue.d.ts +38 -0
  11. package/dist/components/Media/index.d.ts +6 -0
  12. package/dist/components/Media/mediaUtils.d.ts +47 -0
  13. package/dist/components/Media/useMediaController.d.ts +80 -0
  14. package/dist/components/Media/useMediaLocale.d.ts +3 -0
  15. package/dist/components/Media/waveform.d.ts +27 -0
  16. package/dist/components/Menu/UidMenu.vue.d.ts +17 -3
  17. package/dist/components/Pagination/UidPaginationCursor.vue.d.ts +2 -2
  18. package/dist/components/Progress/UidProgress.vue.d.ts +1 -1
  19. package/dist/components/ProgressRing/UidProgressRing.vue.d.ts +1 -1
  20. package/dist/components/Stack/UidStack.vue.d.ts +1 -1
  21. package/dist/components/Video/UidVideo.vue.d.ts +106 -0
  22. package/dist/components/Video/index.d.ts +2 -0
  23. package/dist/composables/useLocale.d.ts +2 -1
  24. package/dist/hls/abr.d.ts +36 -0
  25. package/dist/hls/aes.d.ts +5 -0
  26. package/dist/hls/engine.d.ts +86 -0
  27. package/dist/hls/index.cjs +3 -0
  28. package/dist/hls/index.d.ts +11 -0
  29. package/dist/hls/index.mjs +1500 -0
  30. package/dist/hls/mp4.d.ts +21 -0
  31. package/dist/hls/playlist.d.ts +76 -0
  32. package/dist/hls/transmux.d.ts +27 -0
  33. package/dist/hls/ts/adts.d.ts +16 -0
  34. package/dist/hls/ts/demux.d.ts +26 -0
  35. package/dist/hls/ts/h264.d.ts +30 -0
  36. package/dist/hls/ts/id3.d.ts +10 -0
  37. package/dist/hls/ts/mp4mux.d.ts +32 -0
  38. package/dist/hls/ts/transmuxer.d.ts +22 -0
  39. package/dist/index.cjs +12 -8
  40. package/dist/index.d.ts +7 -1
  41. package/dist/index.mjs +4537 -2398
  42. package/dist/locales/index.d.ts +1 -1
  43. package/dist/locales/types.d.ts +46 -0
  44. package/dist/styles/all.css +1 -1
  45. package/dist/styles/index.css +1 -1
  46. package/package.json +9 -1
@@ -0,0 +1,1500 @@
1
+ //#region src/hls/abr.ts
2
+ var e = class {
3
+ constructor(e = 1e6, t = 3, n = 9, r = 16e3) {
4
+ this.fastHalfLife = t, this.slowHalfLife = n, this.minBytes = r, this.fastWeight = 0, this.slowWeight = 0, this.defaultEstimate = e, this.fast = 0, this.slow = 0;
5
+ }
6
+ sample({ bytes: e, ms: t }) {
7
+ if (e < this.minBytes || t <= 0) return;
8
+ let n = e * 8 * 1e3 / t, r = Math.max(t / 1e3, .05), i = Math.exp(Math.log(.5) / this.fastHalfLife * r), a = Math.exp(Math.log(.5) / this.slowHalfLife * r);
9
+ this.fast = n * (1 - i) + i * this.fast, this.fastWeight = 1 - i + i * this.fastWeight, this.slow = n * (1 - a) + a * this.slow, this.slowWeight = 1 - a + a * this.slowWeight;
10
+ }
11
+ get hasSamples() {
12
+ return this.fastWeight > 0;
13
+ }
14
+ get estimate() {
15
+ return this.fastWeight ? Math.min(this.fast / this.fastWeight, this.slow / this.slowWeight) : this.defaultEstimate;
16
+ }
17
+ };
18
+ function t(e, t, n = {}) {
19
+ if (!e.length) return -1;
20
+ let r = n.safety ?? .8;
21
+ n.bufferAhead !== void 0 && n.bufferAhead < 4 && (r *= .7);
22
+ let i = t * r, a = 0;
23
+ for (let t = 0; t < e.length; t++) {
24
+ let r = e[t], o = e[t - 1];
25
+ if (n.maxHeight && o?.height && o.height >= n.maxHeight) break;
26
+ r.bandwidth <= i && (a = t);
27
+ }
28
+ let o = n.current;
29
+ return o !== void 0 && o >= 0 && a > o + 1 && (a = o + 1), a;
30
+ }
31
+ //#endregion
32
+ //#region src/hls/playlist.ts
33
+ var n = class extends Error {
34
+ constructor(e) {
35
+ super(e), this.name = "HlsParseError";
36
+ }
37
+ };
38
+ function r(e) {
39
+ let t = {}, n = /([A-Z0-9-]+)=("[^"]*"|[^,]*)/g, r;
40
+ for (; r = n.exec(e);) {
41
+ let e = r[2];
42
+ e.startsWith("\"") && (e = e.slice(1, -1)), t[r[1]] = e;
43
+ }
44
+ return t;
45
+ }
46
+ function i(e, t) {
47
+ try {
48
+ return new URL(e, t).href;
49
+ } catch {
50
+ return e;
51
+ }
52
+ }
53
+ function a(e, t) {
54
+ let [n, r] = e.split("@");
55
+ return {
56
+ length: parseInt(n, 10),
57
+ offset: r === void 0 ? t : parseInt(r, 10)
58
+ };
59
+ }
60
+ function o(e) {
61
+ let t = e.replace(/^0x/i, "").padStart(32, "0"), n = new Uint8Array(16);
62
+ for (let e = 0; e < 16; e++) n[e] = parseInt(t.substr(e * 2, 2), 16);
63
+ return n;
64
+ }
65
+ function s(e, t) {
66
+ let r = e.replace(/\r\n?/g, "\n").split("\n").map((e) => e.trim());
67
+ if (r[0]?.replace(/^/, "") !== "#EXTM3U") throw new n("Not an M3U8 playlist");
68
+ return r.some((e) => e.startsWith("#EXT-X-STREAM-INF")) ? c(r, t) : l(r, t);
69
+ }
70
+ function c(e, t) {
71
+ let a = [], o = [];
72
+ for (let n = 0; n < e.length; n++) {
73
+ let s = e[n];
74
+ if (s.startsWith("#EXT-X-STREAM-INF:")) {
75
+ let o = r(s.slice(18)), c = "";
76
+ for (; n + 1 < e.length;) {
77
+ let t = e[++n];
78
+ if (t && !t.startsWith("#")) {
79
+ c = t;
80
+ break;
81
+ }
82
+ }
83
+ if (!c) continue;
84
+ let l = o.RESOLUTION?.split("x").map(Number);
85
+ a.push({
86
+ uri: i(c, t),
87
+ bandwidth: Number(o.BANDWIDTH) || 0,
88
+ averageBandwidth: o["AVERAGE-BANDWIDTH"] ? Number(o["AVERAGE-BANDWIDTH"]) : void 0,
89
+ width: l?.[0] || void 0,
90
+ height: l?.[1] || void 0,
91
+ codecs: o.CODECS || void 0,
92
+ frameRate: o["FRAME-RATE"] ? Number(o["FRAME-RATE"]) : void 0,
93
+ name: o.NAME || void 0,
94
+ audio: o.AUDIO || void 0
95
+ });
96
+ } else if (s.startsWith("#EXT-X-MEDIA:")) {
97
+ let e = r(s.slice(13));
98
+ o.push({
99
+ type: e.TYPE,
100
+ groupId: e["GROUP-ID"],
101
+ name: e.NAME,
102
+ language: e.LANGUAGE,
103
+ uri: e.URI ? i(e.URI, t) : void 0,
104
+ default: e.DEFAULT === "YES",
105
+ autoselect: e.AUTOSELECT === "YES",
106
+ channels: e.CHANNELS
107
+ });
108
+ }
109
+ }
110
+ if (!a.length) throw new n("Master playlist without variants");
111
+ return {
112
+ type: "master",
113
+ url: t,
114
+ variants: a,
115
+ media: o
116
+ };
117
+ }
118
+ function l(e, t) {
119
+ let n = {
120
+ type: "media",
121
+ url: t,
122
+ targetDuration: 0,
123
+ mediaSequence: 0,
124
+ discontinuitySequence: 0,
125
+ endList: !1,
126
+ segments: [],
127
+ totalDuration: 0
128
+ }, s = 0, c, l, u = 0, d, f, p = !1, m = 0, h = 0;
129
+ for (let g of e) if (g) {
130
+ if (g.startsWith("#EXTINF:")) {
131
+ let e = g.slice(8), t = e.indexOf(",");
132
+ s = parseFloat(t === -1 ? e : e.slice(0, t)), c = t === -1 ? void 0 : e.slice(t + 1) || void 0;
133
+ } else if (g.startsWith("#EXT-X-TARGETDURATION:")) n.targetDuration = parseFloat(g.slice(22));
134
+ else if (g.startsWith("#EXT-X-MEDIA-SEQUENCE:")) n.mediaSequence = parseInt(g.slice(22), 10);
135
+ else if (g.startsWith("#EXT-X-DISCONTINUITY-SEQUENCE:")) n.discontinuitySequence = parseInt(g.slice(30), 10), m = n.discontinuitySequence;
136
+ else if (g === "#EXT-X-DISCONTINUITY") p = !0;
137
+ else if (g === "#EXT-X-ENDLIST") n.endList = !0;
138
+ else if (g.startsWith("#EXT-X-PLAYLIST-TYPE:")) n.playlistType = g.slice(21);
139
+ else if (g.startsWith("#EXT-X-BYTERANGE:")) l = a(g.slice(17), u);
140
+ else if (g.startsWith("#EXT-X-KEY:")) {
141
+ let e = r(g.slice(11));
142
+ d = e.METHOD === "NONE" ? void 0 : {
143
+ method: e.METHOD,
144
+ uri: e.URI ? i(e.URI, t) : void 0,
145
+ iv: e.IV ? o(e.IV) : void 0
146
+ };
147
+ } else if (g.startsWith("#EXT-X-MAP:")) {
148
+ let e = r(g.slice(11));
149
+ f = {
150
+ uri: i(e.URI, t),
151
+ byteRange: e.BYTERANGE ? a(e.BYTERANGE, 0) : void 0,
152
+ key: d
153
+ };
154
+ } else if (!g.startsWith("#")) {
155
+ p && m++;
156
+ let e = {
157
+ uri: i(g, t),
158
+ duration: s,
159
+ start: h,
160
+ sn: n.mediaSequence + n.segments.length,
161
+ cc: m,
162
+ title: c,
163
+ byteRange: l,
164
+ key: d,
165
+ map: f
166
+ };
167
+ n.segments.push(e), h += s, l && (u = l.offset + l.length), s = 0, c = void 0, l = void 0, p = !1;
168
+ }
169
+ }
170
+ return n.totalDuration = h, !n.targetDuration && n.segments.length && (n.targetDuration = Math.ceil(Math.max(...n.segments.map((e) => e.duration)))), n;
171
+ }
172
+ function u(e) {
173
+ let t = new Uint8Array(16), n = e;
174
+ for (let e = 15; e >= 8 && n > 0; e--) t[e] = n % 256, n = Math.floor(n / 256);
175
+ return t;
176
+ }
177
+ //#endregion
178
+ //#region src/hls/aes.ts
179
+ var d = /* @__PURE__ */ new Map();
180
+ function f() {
181
+ return typeof crypto < "u" && !!crypto.subtle;
182
+ }
183
+ function p(e, t) {
184
+ let n = d.get(e);
185
+ return n || (n = t(e).then((e) => {
186
+ if (e.byteLength !== 16) throw Error(`AES-128 key must be 16 bytes, got ${e.byteLength}`);
187
+ return crypto.subtle.importKey("raw", e, { name: "AES-CBC" }, !1, ["decrypt"]);
188
+ }), n.catch(() => d.delete(e)), d.set(e, n)), n;
189
+ }
190
+ async function m(e, t, n, r) {
191
+ if (!t.uri) throw Error("EXT-X-KEY without URI");
192
+ let i = await p(t.uri, r), a = t.iv ?? u(n);
193
+ return crypto.subtle.decrypt({
194
+ name: "AES-CBC",
195
+ iv: a
196
+ }, i, e);
197
+ }
198
+ //#endregion
199
+ //#region src/hls/mp4.ts
200
+ function h(e, t) {
201
+ return (e[t] << 24 >>> 0) + (e[t + 1] << 16) + (e[t + 2] << 8) + e[t + 3];
202
+ }
203
+ function g(e, t) {
204
+ return String.fromCharCode(e[t], e[t + 1], e[t + 2], e[t + 3]);
205
+ }
206
+ function _(e, t = 0, n = e.length) {
207
+ let r = [], i = t;
208
+ for (; i + 8 <= n;) {
209
+ let t = h(e, i), a = g(e, i + 4), o = 8;
210
+ if (t === 1 ? (t = h(e, i + 8) * 4294967296 + h(e, i + 12), o = 16) : t === 0 && (t = n - i), t < o || i + t > n) break;
211
+ r.push({
212
+ type: a,
213
+ start: i,
214
+ data: i + o,
215
+ end: i + t
216
+ }), i += t;
217
+ }
218
+ return r;
219
+ }
220
+ function v(e, t, n = 0, r = e.length) {
221
+ if (!t.length) return [];
222
+ let [i, ...a] = t, o = _(e, n, r).filter((e) => e.type === i);
223
+ return a.length ? o.flatMap((t) => v(e, a, t.data, t.end)) : o;
224
+ }
225
+ var ee = [
226
+ "ftyp",
227
+ "styp",
228
+ "moof",
229
+ "sidx",
230
+ "moov",
231
+ "emsg",
232
+ "prft",
233
+ "free"
234
+ ];
235
+ function y(e) {
236
+ return e.length >= 8 && ee.includes(g(e, 4));
237
+ }
238
+ function b(e) {
239
+ return e.length < 188 || e[0] !== 71 ? !1 : e.length < 376 || e[188] === 71;
240
+ }
241
+ function x(e) {
242
+ return e.toString(16).padStart(2, "0");
243
+ }
244
+ function S(e, t) {
245
+ let n = e[t], r = 0, i = t + 1;
246
+ for (let t = 0; t < 4; t++) {
247
+ let t = e[i++];
248
+ if (r = r << 7 | t & 127, !(t & 128)) break;
249
+ }
250
+ return {
251
+ tag: n,
252
+ data: i,
253
+ end: i + r
254
+ };
255
+ }
256
+ function te(e, t, n) {
257
+ let r = S(e, t);
258
+ if (r.tag !== 3 || r.end > n) return;
259
+ let i = e[r.data + 2], a = r.data + 3;
260
+ i & 128 && (a += 2), i & 64 && (a += e[a] + 1), i & 32 && (a += 2);
261
+ let o = S(e, a);
262
+ if (o.tag !== 4 || e[o.data] !== 64) return;
263
+ let s = S(e, o.data + 13);
264
+ if (s.tag !== 5) return;
265
+ let c = e[s.data] >> 3;
266
+ return c > 0 && c < 31 ? c : void 0;
267
+ }
268
+ function ne(e, t) {
269
+ let n = t.type;
270
+ if (n === "avc1" || n === "avc3") {
271
+ let r = _(e, t.data + 78, t.end).find((e) => e.type === "avcC");
272
+ return r ? `${n}.${x(e[r.data + 1])}${x(e[r.data + 2])}${x(e[r.data + 3])}` : `${n}.42e01e`;
273
+ }
274
+ if (n === "mp4a") {
275
+ let n = _(e, t.data + 28, t.end).find((e) => e.type === "esds"), r = n ? te(e, n.data + 4, n.end) : void 0;
276
+ return r ? `mp4a.40.${r}` : "mp4a.40.2";
277
+ }
278
+ if (n === "hvc1" || n === "hev1") return `${n}.1.6.L93.B0`;
279
+ if (n === "Opus") return "opus";
280
+ if (n === "fLaC") return "flac";
281
+ if (n === "vp09") return "vp09.00.10.08";
282
+ if (n === "av01") return "av01.0.04M.08";
283
+ if (n === "ac-3") return "ac-3";
284
+ if (n === "ec-3") return "ec-3";
285
+ }
286
+ function C(e) {
287
+ return v(e, ["moov", "trak"]).map((t) => {
288
+ let n = v(e, ["tkhd"], t.data, t.end)[0], r = v(e, ["mdia", "mdhd"], t.data, t.end)[0], i = v(e, ["mdia", "hdlr"], t.data, t.end)[0], a = v(e, [
289
+ "mdia",
290
+ "minf",
291
+ "stbl",
292
+ "stsd"
293
+ ], t.data, t.end)[0], o = n ? h(e, n.data + (e[n.data] === 1 ? 20 : 12)) : 0, s = r ? h(e, r.data + (e[r.data] === 1 ? 20 : 12)) : 9e4, c = i ? g(e, i.data + 8) : "", l = a ? _(e, a.data + 8, a.end)[0] : void 0;
294
+ return {
295
+ id: o,
296
+ timescale: s,
297
+ kind: c === "vide" ? "video" : c === "soun" ? "audio" : "other",
298
+ codec: l ? ne(e, l) : void 0
299
+ };
300
+ });
301
+ }
302
+ function w(e, t) {
303
+ let n = null;
304
+ for (let r of v(e, ["moof", "traf"])) {
305
+ let i = v(e, ["tfhd"], r.data, r.end)[0], a = v(e, ["tfdt"], r.data, r.end)[0];
306
+ if (!i || !a) continue;
307
+ let o = h(e, i.data + 4), s = t.find((e) => e.id === o)?.timescale ?? 9e4, c = (e[a.data] === 1 ? h(e, a.data + 4) * 4294967296 + h(e, a.data + 8) : h(e, a.data + 4)) / s;
308
+ (n === null || c < n) && (n = c);
309
+ }
310
+ return n;
311
+ }
312
+ //#endregion
313
+ //#region src/hls/transmux.ts
314
+ var T = class extends Error {
315
+ constructor(e, t) {
316
+ super(e), this.code = t, this.name = "TransmuxError";
317
+ }
318
+ }, re = "com.apple.streaming.transportStreamTimestamp";
319
+ function E(e, t) {
320
+ return (e[t] & 127) << 21 | (e[t + 1] & 127) << 14 | (e[t + 2] & 127) << 7 | e[t + 3] & 127;
321
+ }
322
+ function D(e, t) {
323
+ return e.length >= t + 10 && e[t] === 73 && e[t + 1] === 68 && e[t + 2] === 51 && e[t + 3] < 255 && e[t + 4] < 255;
324
+ }
325
+ function ie(e, t = 0) {
326
+ return e.length > t + 1 && e[t] === 255 && (e[t + 1] & 246) == 240;
327
+ }
328
+ function O(e) {
329
+ return D(e, 0) || ie(e, 0);
330
+ }
331
+ function k(e) {
332
+ let t = 0, n;
333
+ for (; D(e, t);) {
334
+ let r = e[t + 3], i = E(e, t + 6), a = t + 10 + i, o = t + 10;
335
+ for (; o + 10 <= a;) {
336
+ let t = String.fromCharCode(e[o], e[o + 1], e[o + 2], e[o + 3]), i = r >= 4 ? E(e, o + 4) : (e[o + 4] << 24 >>> 0) + (e[o + 5] << 16) + (e[o + 6] << 8) + e[o + 7];
337
+ if (!t.trim() || i <= 0) break;
338
+ let a = o + 10;
339
+ if (t === "PRIV") {
340
+ let t = a;
341
+ for (; t < a + i && e[t] !== 0;) t++;
342
+ if (String.fromCharCode(...e.subarray(a, t)) === re && t + 9 <= a + i) {
343
+ let r = t + 1;
344
+ n = (e[r + 3] & 1) * 4294967296 + (e[r + 4] << 24 >>> 0) + (e[r + 5] << 16) + (e[r + 6] << 8) + e[r + 7];
345
+ }
346
+ }
347
+ o = a + i;
348
+ }
349
+ t = a;
350
+ }
351
+ return {
352
+ pts: n,
353
+ data: e.subarray(t)
354
+ };
355
+ }
356
+ //#endregion
357
+ //#region src/hls/ts/adts.ts
358
+ var ae = [
359
+ 96e3,
360
+ 88200,
361
+ 64e3,
362
+ 48e3,
363
+ 44100,
364
+ 32e3,
365
+ 24e3,
366
+ 22050,
367
+ 16e3,
368
+ 12e3,
369
+ 11025,
370
+ 8e3,
371
+ 7350
372
+ ];
373
+ function oe(e) {
374
+ let t = [], n, r = 0;
375
+ for (; r + 7 <= e.length;) {
376
+ if (e[r] !== 255 || (e[r + 1] & 246) != 240) {
377
+ r++;
378
+ continue;
379
+ }
380
+ let i = e[r + 1] & 1 ? 7 : 9, a = (e[r + 3] & 3) << 11 | e[r + 4] << 3 | e[r + 5] >> 5;
381
+ if (a < i) {
382
+ r++;
383
+ continue;
384
+ }
385
+ if (r + a > e.length) break;
386
+ if (!n) {
387
+ let t = e[r + 2] >> 2 & 15;
388
+ n = {
389
+ objectType: (e[r + 2] >> 6) + 1,
390
+ rateIndex: t,
391
+ sampleRate: ae[t] ?? 44100,
392
+ channels: (e[r + 2] & 1) << 2 | e[r + 3] >> 6
393
+ };
394
+ }
395
+ t.push(e.subarray(r + i, r + a)), r += a;
396
+ }
397
+ return {
398
+ config: n,
399
+ frames: t,
400
+ rest: e.subarray(r)
401
+ };
402
+ }
403
+ function se(e) {
404
+ return new Uint8Array([e.objectType << 3 | e.rateIndex >> 1, (e.rateIndex & 1) << 7 | e.channels << 3]);
405
+ }
406
+ var ce = [3, 4], le = [129, 135];
407
+ function A(e, t) {
408
+ return (e[t] & 14) * 536870912 + e[t + 1] * 4194304 + (e[t + 2] & 254) * 16384 + e[t + 3] * 128 + (e[t + 4] & 254) / 2;
409
+ }
410
+ function ue(e) {
411
+ if (e.length < 9 || e[0] !== 0 || e[1] !== 0 || e[2] !== 1) return null;
412
+ let t = e[7], n = e[8], r, i;
413
+ t & 128 && (r = A(e, 9), i = (t & 192) == 192 ? A(e, 14) : r);
414
+ let a = 9 + n;
415
+ return a > e.length ? null : {
416
+ pts: r,
417
+ dts: i,
418
+ data: e.subarray(a)
419
+ };
420
+ }
421
+ function de(e) {
422
+ if (e.length === 1) return e[0];
423
+ let t = 0;
424
+ for (let n of e) t += n.length;
425
+ let n = new Uint8Array(t), r = 0;
426
+ for (let t of e) n.set(t, r), r += t.length;
427
+ return n;
428
+ }
429
+ function fe(e, t) {
430
+ let n = (e[t + 1] & 15) << 8 | e[t + 2], r = Math.min(e.length, t + 3 + n - 4);
431
+ for (let n = t + 8; n + 4 <= r; n += 4) if (e[n] << 8 | e[n + 1]) return (e[n + 2] & 31) << 8 | e[n + 3];
432
+ }
433
+ function pe(e, t, n) {
434
+ let r = (e[t + 1] & 15) << 8 | e[t + 2], i = Math.min(e.length, t + 3 + r - 4), a = (e[t + 10] & 15) << 8 | e[t + 11], o = t + 12 + a;
435
+ for (; o + 5 <= i;) {
436
+ let t = e[o], r = (e[o + 1] & 31) << 8 | e[o + 2], i = (e[o + 3] & 15) << 8 | e[o + 4], a = t === 27 || t === 36, s = t === 15 || ce.includes(t) || le.includes(t);
437
+ a && n.videoPid === void 0 ? (n.videoPid = r, n.videoType = t) : s && n.audioPid === void 0 && (n.audioPid = r, n.audioType = t), o += 5 + i;
438
+ }
439
+ }
440
+ function me(e, t = {}) {
441
+ let n = { ...t }, r = /* @__PURE__ */ new Map(), i = [], a = [], o = !1, s = (e) => {
442
+ let t = r.get(e);
443
+ if (r.delete(e), !t?.length) return;
444
+ let o = ue(de(t));
445
+ o && (e === n.videoPid ? i.push(o) : e === n.audioPid && a.push(o));
446
+ }, c = 0;
447
+ for (; c < e.length && e[c] !== 71;) c++;
448
+ for (let t = c; t + 188 <= e.length; t += 188) {
449
+ if (e[t] !== 71) continue;
450
+ let i = (e[t + 1] & 64) != 0, a = (e[t + 1] & 31) << 8 | e[t + 2], c = (e[t + 3] & 48) >> 4, l = t + 4;
451
+ if (c === 2 || (c === 3 && (l += e[l] + 1), l >= t + 188)) continue;
452
+ if (a === 0) {
453
+ i && (l += e[l] + 1), n.pmtPid = fe(e, l);
454
+ continue;
455
+ }
456
+ if (a === n.pmtPid) {
457
+ o ||= (i && (l += e[l] + 1), n.videoPid = n.audioPid = n.videoType = n.audioType = void 0, pe(e, l, n), !0);
458
+ continue;
459
+ }
460
+ if (a !== n.videoPid && a !== n.audioPid) continue;
461
+ i && s(a);
462
+ let u = r.get(a);
463
+ if (!u) {
464
+ if (!i) continue;
465
+ u = [], r.set(a, u);
466
+ }
467
+ u.push(e.subarray(l, t + 188));
468
+ }
469
+ for (let e of Array.from(r.keys())) s(e);
470
+ return {
471
+ ...n,
472
+ video: i,
473
+ audio: a
474
+ };
475
+ }
476
+ //#endregion
477
+ //#region src/hls/ts/h264.ts
478
+ function he(e) {
479
+ let t = [], n = -1, r = 0, i = e.length;
480
+ for (; r + 2 < i;) e[r + 2] > 1 ? r += 3 : e[r] === 0 && e[r + 1] === 0 && e[r + 2] === 1 ? (n >= 0 && t.push(ge(e.subarray(n, r))), r += 3, n = r) : r++;
481
+ return n >= 0 && n < i && t.push(e.subarray(n)), t.filter((e) => e.length > 0);
482
+ }
483
+ function ge(e) {
484
+ let t = e.length;
485
+ for (; t > 0 && e[t - 1] === 0;) t--;
486
+ return e.subarray(0, t);
487
+ }
488
+ function _e(e) {
489
+ return e[0] & 31;
490
+ }
491
+ function ve(e) {
492
+ let t = new Uint8Array(e.length), n = 0, r = 0;
493
+ for (let i = 0; i < e.length; i++) {
494
+ let a = e[i];
495
+ if (r >= 2 && a === 3) {
496
+ r = 0;
497
+ continue;
498
+ }
499
+ t[n++] = a, r = a === 0 ? r + 1 : 0;
500
+ }
501
+ return t.subarray(0, n);
502
+ }
503
+ var ye = class {
504
+ constructor(e) {
505
+ this.d = e, this.pos = 0;
506
+ }
507
+ bit() {
508
+ let e = (this.d[this.pos >> 3] ?? 0) >> 7 - (this.pos & 7) & 1;
509
+ return this.pos++, e;
510
+ }
511
+ bits(e) {
512
+ let t = 0;
513
+ for (let n = 0; n < e; n++) t = t * 2 + this.bit();
514
+ return t;
515
+ }
516
+ ue() {
517
+ let e = 0;
518
+ for (; this.bit() === 0 && e < 32;) e++;
519
+ return 2 ** e - 1 + this.bits(e);
520
+ }
521
+ se() {
522
+ let e = this.ue();
523
+ return e & 1 ? (e + 1) / 2 : -e / 2;
524
+ }
525
+ }, be = [
526
+ 100,
527
+ 110,
528
+ 122,
529
+ 244,
530
+ 44,
531
+ 83,
532
+ 86,
533
+ 118,
534
+ 128,
535
+ 138,
536
+ 139,
537
+ 134,
538
+ 135
539
+ ];
540
+ function xe(e, t) {
541
+ let n = 8, r = 8;
542
+ for (let i = 0; i < t; i++) r !== 0 && (r = (n + e.se() + 256) % 256), n = r === 0 ? n : r;
543
+ }
544
+ function Se(e) {
545
+ let t = new ye(ve(e.subarray(1))), n = t.bits(8), r = t.bits(8), i = t.bits(8);
546
+ t.ue();
547
+ let a = 1, o = 1;
548
+ if (be.includes(n) && (a = t.ue(), a === 3 && t.bit(), t.ue(), t.ue(), t.bit(), t.bit())) for (let e = 0; e < (a === 3 ? 12 : 8); e++) t.bit() && xe(t, e < 6 ? 16 : 64);
549
+ t.ue();
550
+ let s = t.ue();
551
+ if (s === 0) t.ue();
552
+ else if (s === 1) {
553
+ t.bit(), t.se(), t.se();
554
+ let e = t.ue();
555
+ for (let n = 0; n < e; n++) t.se();
556
+ }
557
+ t.ue(), t.bit();
558
+ let c = t.ue() + 1, l = t.ue() + 1;
559
+ o = t.bit(), o || t.bit(), t.bit();
560
+ let u = 0, d = 0, f = 0, p = 0;
561
+ t.bit() && (u = t.ue(), d = t.ue(), f = t.ue(), p = t.ue());
562
+ let m = a === 1 || a === 2 ? 2 : 1, h = a === 1 ? 2 : 1, g = a === 0 ? 1 : m, _ = (a === 0 ? 1 : h) * (2 - o);
563
+ return {
564
+ profile: n,
565
+ compatibility: r,
566
+ level: i,
567
+ width: c * 16 - (u + d) * g,
568
+ height: (2 - o) * l * 16 - (f + p) * _
569
+ };
570
+ }
571
+ function Ce(e) {
572
+ let t = (e) => e.toString(16).padStart(2, "0");
573
+ return `avc1.${t(e[1])}${t(e[2])}${t(e[3])}`;
574
+ }
575
+ function we(e) {
576
+ let t = 0;
577
+ for (let n of e) t += 4 + n.length;
578
+ let n = new Uint8Array(t), r = 0;
579
+ for (let t of e) {
580
+ let e = t.length;
581
+ n[r] = e >>> 24 & 255, n[r + 1] = e >>> 16 & 255, n[r + 2] = e >>> 8 & 255, n[r + 3] = e & 255, n.set(t, r + 4), r += 4 + e;
582
+ }
583
+ return n;
584
+ }
585
+ //#endregion
586
+ //#region src/hls/ts/mp4mux.ts
587
+ function j(e) {
588
+ return [
589
+ e.charCodeAt(0),
590
+ e.charCodeAt(1),
591
+ e.charCodeAt(2),
592
+ e.charCodeAt(3)
593
+ ];
594
+ }
595
+ function M(e) {
596
+ return [
597
+ e >>> 24 & 255,
598
+ e >>> 16 & 255,
599
+ e >>> 8 & 255,
600
+ e & 255
601
+ ];
602
+ }
603
+ function N(e) {
604
+ return [e >>> 8 & 255, e & 255];
605
+ }
606
+ function Te(e) {
607
+ let t = Math.floor(e / 4294967296);
608
+ return [...M(t), ...M(e - t * 4294967296)];
609
+ }
610
+ function P(e, ...t) {
611
+ let n = 8;
612
+ for (let e of t) n += e.length;
613
+ let r = new Uint8Array(n);
614
+ r.set(M(n), 0), r.set(j(e), 4);
615
+ let i = 8;
616
+ for (let e of t) r.set(e, i), i += e.length;
617
+ return r;
618
+ }
619
+ function F(e, t) {
620
+ return [
621
+ e,
622
+ t >> 16 & 255,
623
+ t >> 8 & 255,
624
+ t & 255
625
+ ];
626
+ }
627
+ var I = [
628
+ ...M(65536),
629
+ ...M(0),
630
+ ...M(0),
631
+ ...M(0),
632
+ ...M(65536),
633
+ ...M(0),
634
+ ...M(0),
635
+ ...M(0),
636
+ ...M(1073741824)
637
+ ];
638
+ function L(e) {
639
+ return Array(e).fill(0);
640
+ }
641
+ function Ee(e, t) {
642
+ return P("mvhd", F(0, 0), M(0), M(0), M(e), M(0), M(65536), N(256), L(10), I, L(24), M(t));
643
+ }
644
+ function De(e) {
645
+ let t = e.kind === "video" ? e.width : 0, n = e.kind === "video" ? e.height : 0;
646
+ return P("tkhd", F(0, 3), M(0), M(0), M(e.id), M(0), M(0), L(8), N(0), N(0), N(e.kind === "audio" ? 256 : 0), N(0), I, M(t * 65536), M(n * 65536));
647
+ }
648
+ function Oe(e) {
649
+ return P("mdhd", F(0, 0), M(0), M(0), M(e), M(0), N(21956), N(0));
650
+ }
651
+ function ke(e) {
652
+ let t = e === "video" ? "VideoHandler" : "SoundHandler";
653
+ return P("hdlr", F(0, 0), M(0), j(e === "video" ? "vide" : "soun"), L(12), [...Array.from(t, (e) => e.charCodeAt(0)), 0]);
654
+ }
655
+ function Ae(e) {
656
+ let t = P("avcC", [
657
+ 1,
658
+ e.sps[1],
659
+ e.sps[2],
660
+ e.sps[3],
661
+ 255,
662
+ 225
663
+ ], N(e.sps.length), e.sps, [1], N(e.pps.length), e.pps);
664
+ return P("avc1", L(6), N(1), N(0), N(0), L(12), N(e.width), N(e.height), M(4718592), M(4718592), M(0), N(1), L(32), N(24), N(65535), t);
665
+ }
666
+ function R(e) {
667
+ return [
668
+ 128 | e >> 21 & 127,
669
+ 128 | e >> 14 & 127,
670
+ 128 | e >> 7 & 127,
671
+ e & 127
672
+ ];
673
+ }
674
+ function je(e) {
675
+ let t = [
676
+ 5,
677
+ ...R(e.config.length),
678
+ ...e.config
679
+ ], n = [
680
+ 4,
681
+ ...R(13 + t.length),
682
+ 64,
683
+ 21,
684
+ 0,
685
+ 0,
686
+ 0,
687
+ ...M(0),
688
+ ...M(0),
689
+ ...t
690
+ ], r = [
691
+ 6,
692
+ ...R(1),
693
+ 2
694
+ ], i = [
695
+ 3,
696
+ ...R(3 + n.length + r.length),
697
+ ...N(e.id),
698
+ 0,
699
+ ...n,
700
+ ...r
701
+ ], a = P("esds", F(0, 0), i);
702
+ return P("mp4a", L(6), N(1), L(8), N(e.channels), N(16), N(0), N(0), M(Math.min(e.sampleRate, 65535) * 65536), a);
703
+ }
704
+ function Me(e) {
705
+ let t = e.kind === "video" ? Ae(e) : je(e);
706
+ return P("stbl", P("stsd", F(0, 0), M(1), t), P("stts", F(0, 0), M(0)), P("stsc", F(0, 0), M(0)), P("stsz", F(0, 0), M(0), M(0)), P("stco", F(0, 0), M(0)));
707
+ }
708
+ function Ne(e) {
709
+ let t = e.kind === "video" ? P("vmhd", F(0, 1), L(8)) : P("smhd", F(0, 0), L(4)), n = P("dinf", P("dref", F(0, 0), M(1), P("url ", F(0, 1))));
710
+ return P("trak", De(e), P("mdia", Oe(e.timescale), ke(e.kind), P("minf", t, n, Me(e))));
711
+ }
712
+ function Pe(e) {
713
+ let t = P("ftyp", j("isom"), M(1), j("isom"), j("iso5"), j("avc1"), j("mp41")), n = e.map((e) => P("trex", F(0, 0), M(e.id), M(1), M(0), M(0), M(65537)));
714
+ return B([t, P("moov", Ee(1e3, e.length + 1), ...e.map(Ne), P("mvex", ...n))]);
715
+ }
716
+ function z(e, t, n, r, i) {
717
+ let a = [];
718
+ for (let e of r) a.push(...M(e.duration), ...M(e.size), ...M(e.key ? 33554432 : 16842752), ...M(e.cts | 0));
719
+ let o = P("trun", F(1, 3841), M(r.length), M(0), a), s = P("traf", P("tfhd", F(0, 131072), M(t)), P("tfdt", F(1, 0), Te(Math.max(0, Math.round(n)))), o), c = P("moof", P("mfhd", F(0, 0), M(e)), s);
720
+ return c.set(M(c.length + 8), 84), B([c, P("mdat", i)]);
721
+ }
722
+ function B(e) {
723
+ let t = 0;
724
+ for (let n of e) t += n.length;
725
+ let n = new Uint8Array(t), r = 0;
726
+ for (let t of e) n.set(t, r), r += t.length;
727
+ return n;
728
+ }
729
+ //#endregion
730
+ //#region src/hls/ts/transmuxer.ts
731
+ var V = 1, H = 2, U = 8589934592, W = 1024;
732
+ function Fe(e, t) {
733
+ if (e.length !== t.length) return !1;
734
+ for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
735
+ return !0;
736
+ }
737
+ var G = class {
738
+ constructor() {
739
+ this.demux = {}, this.initKey = "", this.seq = 1, this.ref = null, this.nextVideoDts = null, this.nextAudioDts = null, this.videoDuration = 3e3;
740
+ }
741
+ canHandle(e) {
742
+ return b(e) || O(e);
743
+ }
744
+ reset() {
745
+ this.demux = {}, this.initKey = "", this.ref = null, this.nextVideoDts = null, this.nextAudioDts = null;
746
+ }
747
+ unwrap(e) {
748
+ for (this.ref === null && (this.ref = e); e - this.ref > U / 2;) e -= U;
749
+ for (; this.ref - e > U / 2;) e += U;
750
+ return this.ref = e, e;
751
+ }
752
+ push(e, t) {
753
+ if (t.discontinuity && (this.ref = null, this.nextVideoDts = null, this.nextAudioDts = null), !b(e)) return this.pushPacked(e);
754
+ let n = me(e, this.demux);
755
+ if (this.demux = n, n.videoType !== void 0 && n.videoType !== 27) throw new T(`Unsupported video stream type 0x${n.videoType.toString(16)}`, "codec");
756
+ if (n.audioType !== void 0 && n.audioType !== 15) throw new T(`Unsupported audio stream type 0x${n.audioType.toString(16)}`, "codec");
757
+ if (n.videoPid === void 0 && n.audioPid === void 0) throw new T("No program map in the transport stream", "format");
758
+ let r = n.video.length ? this.videoSamples(n.video) : null, i = n.audio.length ? this.audioSamples(n.audio) : null;
759
+ return this.output(r, i);
760
+ }
761
+ pushPacked(e) {
762
+ let t = k(e);
763
+ if (t.pts === void 0 && this.nextAudioDts === null) throw new T("Packed audio segment without an ID3 timestamp", "format");
764
+ let n = t.pts ?? Math.round(this.nextAudioDts * 9e4 / (this.audio?.sampleRate ?? 9e4)), r = this.audioSamples([{
765
+ pts: n,
766
+ dts: n,
767
+ data: t.data
768
+ }]);
769
+ if (!r) throw new T("No AAC frames in the packed audio segment", "format");
770
+ return this.output(null, r);
771
+ }
772
+ output(e, t) {
773
+ let n = [], r = [], i = [];
774
+ if (this.video && (n.push({
775
+ id: V,
776
+ kind: "video",
777
+ timescale: 9e4,
778
+ ...this.video
779
+ }), r.push({
780
+ id: V,
781
+ kind: "video",
782
+ timescale: 9e4,
783
+ codec: this.video.codec
784
+ }), i.push(this.video.codec)), this.audio) {
785
+ let e = se(this.audio);
786
+ n.push({
787
+ id: H,
788
+ kind: "audio",
789
+ timescale: this.audio.sampleRate,
790
+ channels: this.audio.channels,
791
+ sampleRate: this.audio.sampleRate,
792
+ config: e
793
+ }), r.push({
794
+ id: H,
795
+ kind: "audio",
796
+ timescale: this.audio.sampleRate,
797
+ codec: `mp4a.40.${this.audio.objectType}`
798
+ }), i.push(`mp4a.40.${this.audio.objectType}`);
799
+ }
800
+ if (!n.length) throw new T("No decodable samples in the segment", "format");
801
+ let a = i.join(",") + (this.video ? `|${this.video.width}x${this.video.height}|${this.video.sps.join(".")}` : ""), o;
802
+ a !== this.initKey && (o = Pe(n), this.initKey = a);
803
+ let s = [], c = [];
804
+ return e && this.video && (s.push(z(this.seq++, V, e.base, e.samples, e.payload)), c.push(e.base / 9e4)), t && this.audio && (s.push(z(this.seq++, H, t.base, t.samples, t.payload)), c.push(t.base / this.audio.sampleRate)), {
805
+ init: o,
806
+ data: B(s),
807
+ mimeType: `${this.video ? "video" : "audio"}/mp4; codecs="${i.join(",")}"`,
808
+ tracks: r,
809
+ startTime: c.length ? Math.min(...c) : 0
810
+ };
811
+ }
812
+ videoSamples(e) {
813
+ let t = [], n = null;
814
+ for (let r of e) {
815
+ let e = he(r.data), i = [], a = !1;
816
+ for (let t of e) {
817
+ let e = _e(t);
818
+ if (e === 7) {
819
+ let e = Se(t);
820
+ (!this.video || !Fe(this.video.sps, t)) && (this.video = {
821
+ sps: t.slice(),
822
+ pps: this.video?.pps ?? new Uint8Array(),
823
+ width: e.width,
824
+ height: e.height,
825
+ codec: Ce(t)
826
+ });
827
+ } else e === 8 ? this.video && (this.video.pps = t.slice()) : e !== 9 && (e === 5 && (a = !0), i.push(t));
828
+ }
829
+ if (!i.length) continue;
830
+ let o = r.dts === void 0 ? n === null ? null : n + this.videoDuration : this.unwrap(r.dts);
831
+ if (o === null) continue;
832
+ let s = r.pts === void 0 ? o : this.unwrap(r.pts);
833
+ t.push({
834
+ dts: o,
835
+ pts: s,
836
+ key: a,
837
+ data: we(i)
838
+ }), n = o;
839
+ }
840
+ if (!t.length || !this.video?.pps.length) return null;
841
+ if (this.nextVideoDts !== null) {
842
+ let e = t[0].dts - this.nextVideoDts;
843
+ Math.abs(e) < this.videoDuration * 1.5 && e !== 0 && (t[0].pts -= e, t[0].dts -= e);
844
+ }
845
+ let r = [];
846
+ for (let e = 0; e < t.length; e++) {
847
+ let n = t[e], i = e + 1 < t.length ? t[e + 1].dts - n.dts : this.videoDuration;
848
+ i <= 0 ? i = this.videoDuration : e + 1 < t.length && (this.videoDuration = i), r.push({
849
+ size: n.data.length,
850
+ duration: i,
851
+ cts: Math.max(0, n.pts - n.dts),
852
+ key: n.key
853
+ });
854
+ }
855
+ let i = t[t.length - 1];
856
+ return this.nextVideoDts = i.dts + r[r.length - 1].duration, {
857
+ base: t[0].dts,
858
+ samples: r,
859
+ payload: B(t.map((e) => e.data))
860
+ };
861
+ }
862
+ audioSamples(e) {
863
+ let t = [], n = null, r = new Uint8Array();
864
+ for (let i of e) {
865
+ let e = oe(r.length ? B([r, i.data]) : i.data);
866
+ (e.config && !this.audio || e.config && this.audio && (e.config.sampleRate !== this.audio.sampleRate || e.config.channels !== this.audio.channels)) && (this.audio = e.config), n === null && i.pts !== void 0 && (n = this.unwrap(i.pts)), t.push(...e.frames), r = e.rest;
867
+ }
868
+ if (!t.length || !this.audio || n === null) return null;
869
+ let i = this.audio.sampleRate, a = Math.round(n * i / 9e4);
870
+ this.nextAudioDts !== null && Math.abs(a - this.nextAudioDts) < W * 2 && (a = this.nextAudioDts), this.nextAudioDts = a + t.length * W;
871
+ let o = t.map((e) => ({
872
+ size: e.length,
873
+ duration: W,
874
+ cts: 0,
875
+ key: !0
876
+ }));
877
+ return {
878
+ base: a,
879
+ samples: o,
880
+ payload: B(t)
881
+ };
882
+ }
883
+ };
884
+ function K() {
885
+ return new G();
886
+ }
887
+ //#endregion
888
+ //#region src/hls/engine.ts
889
+ var q = class extends Error {
890
+ constructor(e, t) {
891
+ super(t), this.code = e, this.name = "HlsError";
892
+ }
893
+ };
894
+ function J() {
895
+ if (typeof window > "u") return;
896
+ let e = window;
897
+ return e.MediaSource ?? e.ManagedMediaSource;
898
+ }
899
+ function Y(e) {
900
+ return !!e.canPlayType("application/vnd.apple.mpegurl") || !!e.canPlayType("application/x-mpegURL");
901
+ }
902
+ function Ie(e) {
903
+ return !!J() || !!e && Y(e);
904
+ }
905
+ function Le(e) {
906
+ return e.height ? `${e.height}p` : e.name ? e.name : `${Math.round(e.bandwidth / 1e3)} kbps`;
907
+ }
908
+ var Re = (e) => e >= 500 || e === 429 || e === 0;
909
+ function ze(e, t) {
910
+ return new Promise((n, r) => {
911
+ let i = setTimeout(n, e);
912
+ t?.addEventListener("abort", () => {
913
+ clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
914
+ }, { once: !0 });
915
+ });
916
+ }
917
+ function X(e) {
918
+ let t = [];
919
+ if (!e) return t;
920
+ for (let n = 0; n < e.length; n++) t.push([e.start(n), e.end(n)]);
921
+ return t;
922
+ }
923
+ function Be(e, t) {
924
+ let n = t;
925
+ for (let [t, r] of e) t - .3 <= n && r > n && (n = r);
926
+ return n;
927
+ }
928
+ function Z(e) {
929
+ return e?.name === "AbortError";
930
+ }
931
+ function Q(e, t) {
932
+ if (!e.length) return -1;
933
+ let n = (e) => (e ?? "").toLowerCase(), r = (e, t) => !!t && (n(e) === t || n(e).startsWith(`${t}-`) || t.startsWith(`${n(e)}-`));
934
+ if (t) {
935
+ let i = e.findIndex((e) => r(e.language, n(t)));
936
+ if (i >= 0) return i;
937
+ }
938
+ let i = e.findIndex((e) => e.default);
939
+ if (i >= 0) return i;
940
+ let a = typeof navigator < "u" ? n(navigator.language) : "", o = e.findIndex((e) => e.autoselect && r(e.language, a));
941
+ return o >= 0 ? o : 0;
942
+ }
943
+ var Ve = class {
944
+ constructor(e, t, n) {
945
+ this.engine = e, this.kind = t, this.sb = null, this.ended = !1, this.mime = "", this.queue = [], this.running = null, this.loading = !1, this.segmentAbort = null, this.last = null, this.appendedInit = "", this.tracks = [], this.transmuxer = null, this.reloadTimer = null, this.onUpdateEnd = () => {
946
+ let e = this.running;
947
+ this.running = null, e?.resolve(), this.pump(), this.engine.maybeEndOfStream();
948
+ }, this.onBufferError = () => {
949
+ let e = this.running;
950
+ this.running = null, e?.reject(new q("codec", "SourceBuffer error"));
951
+ }, this.source = n;
952
+ }
953
+ get idle() {
954
+ return !this.loading && !this.running && !this.queue.length && !this.sb?.updating;
955
+ }
956
+ buffered() {
957
+ try {
958
+ return X(this.sb?.buffered);
959
+ } catch {
960
+ return [];
961
+ }
962
+ }
963
+ bufferedEnd(e) {
964
+ return Be(this.buffered(), e);
965
+ }
966
+ loadPlaylist(e = this.source, t = !1) {
967
+ return e.playlist && !t ? Promise.resolve(e.playlist) : (e.loading ||= this.engine.fetchText(e.uri).then((t) => {
968
+ let r = s(t, e.uri);
969
+ if (r.type !== "media") throw new n("Expected a media playlist");
970
+ let i = e.playlist ?? this.source.playlist;
971
+ return i && i !== r && $(i, r), e.playlist = r, r;
972
+ }).finally(() => {
973
+ e.loading = void 0;
974
+ }), e.loading);
975
+ }
976
+ scheduleReload(e) {
977
+ this.engine.destroyed || (this.reloadTimer && clearTimeout(this.reloadTimer), this.reloadTimer = setTimeout(async () => {
978
+ try {
979
+ let e = this.source.playlist, t = await this.loadPlaylist(this.source, !0), n = (e) => e?.segments[e.segments.length - 1]?.sn;
980
+ if (t.endList) {
981
+ this.kind === "main" && (this.engine.live = !1);
982
+ return;
983
+ }
984
+ this.kind === "main" && this.engine.updateSeekable(t), this.scheduleReload(n(e) === n(t) ? t.targetDuration / 2 : t.targetDuration), this.tick();
985
+ } catch (e) {
986
+ this.engine.fail(e);
987
+ }
988
+ }, Math.max(1, e) * 1e3));
989
+ }
990
+ switchSource(e, t) {
991
+ let n = this.source.playlist;
992
+ if (this.source = e, this.segmentAbort?.abort(), this.last = null, this.ended = !1, t !== "none" && this.sb) {
993
+ let e = this.engine.media.currentTime, n = t === "all" ? 0 : e + 1;
994
+ (t === "all" || this.bufferedEnd(e) > n) && this.enqueue({
995
+ kind: "remove",
996
+ start: n,
997
+ end: Infinity
998
+ }).catch(() => {});
999
+ }
1000
+ this.loadPlaylist(e).then((t) => {
1001
+ n && n !== t && this.kind === "audio" && !e.playlist?.endList && $(n, t), this.engine.live && this.scheduleReload(t.targetDuration), this.tick();
1002
+ }, (e) => this.engine.fail(e));
1003
+ }
1004
+ ensureBuffer(e) {
1005
+ let t = this.engine.ms;
1006
+ if (t) {
1007
+ if (!this.sb) {
1008
+ try {
1009
+ this.sb = t.addSourceBuffer(e);
1010
+ } catch (t) {
1011
+ throw new q("codec", `${e}: ${t.message}`);
1012
+ }
1013
+ this.mime = e, this.sb.addEventListener("updateend", this.onUpdateEnd), this.sb.addEventListener("error", this.onBufferError), this.engine.bufferCreated();
1014
+ return;
1015
+ }
1016
+ e !== this.mime && (this.mime = e, typeof this.sb.changeType == "function" && this.enqueue({
1017
+ kind: "changeType",
1018
+ mime: e
1019
+ }).catch(() => {}));
1020
+ }
1021
+ }
1022
+ enqueue(e) {
1023
+ return new Promise((t, n) => {
1024
+ this.queue.push({
1025
+ op: e,
1026
+ resolve: t,
1027
+ reject: n
1028
+ }), this.pump();
1029
+ });
1030
+ }
1031
+ async append(e) {
1032
+ await this.engine.buffersReady(), await this.enqueue({
1033
+ kind: "append",
1034
+ data: e
1035
+ });
1036
+ }
1037
+ pump() {
1038
+ let e = this.sb, t = this.engine.ms;
1039
+ if (!(!e || !t || this.running || e.updating)) for (; this.queue.length;) {
1040
+ let t = this.queue.shift(), { op: n } = t;
1041
+ try {
1042
+ if (n.kind === "append") {
1043
+ this.running = t, e.appendBuffer(n.data);
1044
+ return;
1045
+ }
1046
+ if (n.kind === "remove") {
1047
+ if (this.buffered().some(([, e]) => e > n.start)) {
1048
+ this.running = t, e.remove(n.start, n.end);
1049
+ return;
1050
+ }
1051
+ t.resolve();
1052
+ } else n.kind === "offset" ? (e.timestampOffset = n.value, t.resolve()) : n.kind === "changeType" && (e.changeType(n.mime), t.resolve());
1053
+ } catch (e) {
1054
+ if (this.running = null, e?.name === "QuotaExceededError" && n.kind === "append") {
1055
+ let e = this.engine.media.currentTime - 5;
1056
+ if (e > 0) {
1057
+ this.queue.unshift({
1058
+ op: {
1059
+ kind: "remove",
1060
+ start: 0,
1061
+ end: e
1062
+ },
1063
+ resolve: () => {},
1064
+ reject: () => {}
1065
+ }, t);
1066
+ continue;
1067
+ }
1068
+ }
1069
+ t.reject(e);
1070
+ }
1071
+ }
1072
+ }
1073
+ onSeeking(e) {
1074
+ this.bufferedEnd(e) - e > .1 || (this.segmentAbort?.abort(), this.last = null, this.ended = !1);
1075
+ }
1076
+ nextSegment(e) {
1077
+ let t = e.segments;
1078
+ if (!t.length) return;
1079
+ let n = this.last;
1080
+ if (n && n.source === this.source.id) {
1081
+ let e = t.find((e) => e.sn === n.sn + 1);
1082
+ if (e) return e;
1083
+ if (t[t.length - 1].sn <= n.sn) return;
1084
+ }
1085
+ if (this.engine.live && !this.engine.startPositioned && !n && this.kind === "main") return t[Math.max(0, t.length - 3)];
1086
+ let r = this.bufferedEnd(this.engine.targetTime());
1087
+ return r < t[0].start ? t[0] : t.find((e) => r >= e.start - .05 && r < e.start + e.duration - .05);
1088
+ }
1089
+ tick() {
1090
+ let e = this.engine;
1091
+ if (e.destroyed || e.failed || this.loading || !e.ms || this.kind === "audio" && e.live && !e.startPositioned) return;
1092
+ let t = this.source.playlist;
1093
+ if (!t) return;
1094
+ let n = e.media.currentTime;
1095
+ if (this.evict(n), this.bufferedEnd(n) - n >= e.opts.maxBufferAhead) return;
1096
+ let r = this.nextSegment(t);
1097
+ if (!r) {
1098
+ t.endList && this.last && (this.ended = !0), e.maybeEndOfStream();
1099
+ return;
1100
+ }
1101
+ this.ended = !1, this.loading = !0;
1102
+ let i = this.source.id;
1103
+ this.loadSegment(r, i).catch((t) => {
1104
+ Z(t) || e.fail(t);
1105
+ }).finally(() => {
1106
+ this.loading = !1, e.destroyed || setTimeout(() => this.tick(), 0);
1107
+ });
1108
+ }
1109
+ evict(e) {
1110
+ let t = this.buffered();
1111
+ if (!t.length || !this.sb || this.queue.some((e) => e.op.kind === "remove")) return;
1112
+ let n = e - this.engine.opts.maxBufferBehind;
1113
+ t[0][0] < n - 1 && this.enqueue({
1114
+ kind: "remove",
1115
+ start: 0,
1116
+ end: n
1117
+ }).catch(() => {});
1118
+ }
1119
+ async loadInit(e, t) {
1120
+ let n = `${this.source.id}|${e.uri}|${e.byteRange?.offset ?? ""}`;
1121
+ if (n === this.appendedInit) return;
1122
+ let { data: r } = await this.engine.fetchBytes(e.uri, e.byteRange, t);
1123
+ e.key?.method === "AES-128" && !y(r) && (r = new Uint8Array(await m(r.slice().buffer, e.key, 0, this.engine.loadKey))), this.tracks = C(r);
1124
+ let i = this.tracks.map((e) => e.codec).filter(Boolean).join(",") || this.source.codecs || "", a = this.tracks.some((e) => e.kind === "video") ? "video" : this.tracks.length || this.kind === "audio" ? "audio" : "video";
1125
+ this.ensureBuffer(`${a}/mp4; codecs="${i}"`), await this.append(r), this.appendedInit = n;
1126
+ }
1127
+ async loadSegment(e, t) {
1128
+ let n = this.engine, r = new AbortController();
1129
+ this.segmentAbort = r;
1130
+ let i = () => r.abort();
1131
+ n.abort.signal.addEventListener("abort", i, { once: !0 });
1132
+ try {
1133
+ if (e.key && e.key.method !== "AES-128") throw new q("encrypted", `${e.key.method} encryption is not supported`);
1134
+ if (e.key && !f()) throw new q("encrypted", "WebCrypto is not available");
1135
+ e.map && await this.loadInit(e.map, r.signal);
1136
+ let { data: i, ms: a } = await n.fetchBytes(e.uri, e.byteRange, r.signal);
1137
+ this.kind === "main" && n.est.sample({
1138
+ bytes: i.length,
1139
+ ms: a
1140
+ });
1141
+ let o = i;
1142
+ if (e.key && (o = new Uint8Array(await m(i.slice().buffer, e.key, e.sn, n.loadKey))), r.signal.aborted) return;
1143
+ let s = !!this.last && this.last.source === t && this.last.sn + 1 === e.sn && this.last.cc === e.cc, c;
1144
+ if (b(o) || !y(o) && O(o)) {
1145
+ if (n.opts.transmuxer === null) throw new q("codec", "MPEG-TS segments need a transmuxer");
1146
+ if (this.transmuxer ??= (n.opts.transmuxer ?? K)(), !this.transmuxer.canHandle(o)) throw new q("codec", "The transmuxer cannot read this segment");
1147
+ let e = this.transmuxer.push(o, { discontinuity: !s });
1148
+ e.init && (this.ensureBuffer(e.mimeType), await this.append(e.init), this.appendedInit = ""), this.tracks = e.tracks, o = e.data, c = e.startTime;
1149
+ } else if (y(o)) {
1150
+ if (!this.sb) throw new q("codec", "fMP4 segment without an initialization section");
1151
+ c = w(o, this.tracks);
1152
+ } else throw new q("codec", "Unknown segment container");
1153
+ if (c !== null) {
1154
+ let t = n.offsetFor(e, c);
1155
+ this.sb && Math.abs(this.sb.timestampOffset - t) > .001 && await this.enqueue({
1156
+ kind: "offset",
1157
+ value: t
1158
+ });
1159
+ let r = c + t - e.start;
1160
+ if (this.kind === "audio" && Math.abs(r) > Math.max(.5, e.duration / 2) && this.source.playlist) for (let e of this.source.playlist.segments) e.start += r;
1161
+ }
1162
+ if (r.signal.aborted) return;
1163
+ await this.append(o), this.last = {
1164
+ source: t,
1165
+ sn: e.sn,
1166
+ cc: e.cc
1167
+ }, this.kind === "main" && !n.startPositioned && (n.startPositioned = !0, n.live && (n.media.currentTime = e.start + .01, n.updateSeekable(this.source.playlist)), n.tickAll()), this.kind === "main" && n.afterMainSegment();
1168
+ } finally {
1169
+ n.abort.signal.removeEventListener("abort", i), this.segmentAbort === r && (this.segmentAbort = null);
1170
+ }
1171
+ }
1172
+ destroy() {
1173
+ this.segmentAbort?.abort(), this.reloadTimer && clearTimeout(this.reloadTimer);
1174
+ for (let e of this.queue) e.reject(new DOMException("Aborted", "AbortError"));
1175
+ this.queue = [], this.sb = null;
1176
+ }
1177
+ stopTimers() {
1178
+ this.reloadTimer && clearTimeout(this.reloadTimer);
1179
+ }
1180
+ }, He = class {
1181
+ constructor(t, n, r) {
1182
+ this.media = t, this.url = n, this.native = !1, this.live = !1, this.levels = [], this.level = -1, this.autoLevel = !0, this.audioTracks = [], this.audioTrack = -1, this.abort = new AbortController(), this.ms = null, this.destroyed = !1, this.failed = !1, this.startPositioned = !1, this.all = [], this.renditions = [], this.audioSources = [], this.streams = [], this.main = null, this.audio = null, this.objectUrl = "", this.offsets = /* @__PURE__ */ new Map(), this.timer = null, this.created = 0, this.readyWaiters = [], this.stallPos = -1, this.stallSince = 0, this.loadKey = async (e) => {
1183
+ let { data: t } = await this.fetchBytes(e, void 0, this.abort.signal);
1184
+ return t.slice().buffer;
1185
+ }, this.onSeeking = () => {
1186
+ let e = this.media.currentTime;
1187
+ for (let t of this.streams) t.onSeeking(e);
1188
+ setTimeout(() => this.tickAll(), 0);
1189
+ }, this.opts = {
1190
+ maxBufferAhead: 30,
1191
+ maxBufferBehind: 30,
1192
+ retries: 3,
1193
+ ...r
1194
+ }, this.est = new e(r.initialBandwidth ?? 1e6), this.fetchFn = r.fetch ?? ((...e) => fetch(...e)), this.media.addEventListener("seeking", this.onSeeking), this.start().catch((e) => this.fail(e));
1195
+ }
1196
+ get bandwidth() {
1197
+ return this.est.estimate;
1198
+ }
1199
+ async start() {
1200
+ let e = J();
1201
+ if (!e) throw new q("mse", "MediaSource is not available");
1202
+ let t = s(await this.fetchText(this.url), this.url);
1203
+ if (t.type === "master") {
1204
+ let n = (t) => e.isTypeSupported(`video/mp4; codecs="${t}"`) || e.isTypeSupported(`audio/mp4; codecs="${t}"`), r = t.variants.filter((e) => !e.codecs || n(e.codecs)).sort((e, t) => e.bandwidth - t.bandwidth);
1205
+ if (!r.length) throw new q("codec", "No variant has codecs this browser supports");
1206
+ this.all = r.map((e, t) => ({
1207
+ id: t,
1208
+ uri: e.uri,
1209
+ codecs: e.codecs,
1210
+ variant: e,
1211
+ info: {
1212
+ index: t,
1213
+ bandwidth: e.bandwidth,
1214
+ width: e.width,
1215
+ height: e.height,
1216
+ codecs: e.codecs,
1217
+ label: Le(e)
1218
+ }
1219
+ })), this.renditions = t.media.filter((e) => e.type === "AUDIO");
1220
+ } else {
1221
+ let e = {
1222
+ uri: this.url,
1223
+ bandwidth: 0
1224
+ };
1225
+ this.all = [{
1226
+ id: 0,
1227
+ uri: this.url,
1228
+ variant: e,
1229
+ playlist: t,
1230
+ info: {
1231
+ index: 0,
1232
+ bandwidth: 0,
1233
+ label: "auto"
1234
+ }
1235
+ }];
1236
+ }
1237
+ this.levels = this.all.map((e) => e.info), this.opts.onLevels?.(this.levels);
1238
+ let n = this.opts.startLevel ?? -1;
1239
+ this.autoLevel = n < 0, this.level = n >= 0 && n < this.all.length ? n : this.pickLevel(), this.buildAudioTracks(this.all[this.level].variant.audio);
1240
+ let r = new e();
1241
+ this.ms = r, "disableRemotePlayback" in this.media && window.ManagedMediaSource === e && (this.media.disableRemotePlayback = !0), this.objectUrl = URL.createObjectURL(r);
1242
+ let i = new Promise((e) => r.addEventListener("sourceopen", () => e(), { once: !0 }));
1243
+ if (this.media.src = this.objectUrl, await i, this.destroyed) return;
1244
+ this.main = new Ve(this, "main", this.all[this.level]), this.streams = [this.main];
1245
+ let a = this.audioSources[this.audioTrack];
1246
+ a && (this.audio = new Ve(this, "audio", a), this.streams.push(this.audio));
1247
+ let [o] = await Promise.all(this.streams.map((e) => e.loadPlaylist()));
1248
+ if (this.live = !o.endList, this.live || (r.duration = o.totalDuration), this.opts.onLevelSwitched?.(this.level), this.audio && this.opts.onAudioTrackSwitched?.(this.audioTrack), this.live) for (let e of this.streams) e.scheduleReload(e.source.playlist.targetDuration);
1249
+ this.timer = setInterval(() => this.tickAll(), 250), this.tickAll();
1250
+ }
1251
+ buildAudioTracks(e) {
1252
+ let t = e ? this.renditions.filter((t) => t.groupId === e && t.uri) : [];
1253
+ this.audioSources = t.map((e, t) => ({
1254
+ id: 1e3 + t,
1255
+ uri: e.uri,
1256
+ rendition: e,
1257
+ info: {
1258
+ index: t,
1259
+ label: e.name || e.language || `#${t + 1}`,
1260
+ language: e.language,
1261
+ default: !!e.default
1262
+ }
1263
+ })), this.audioTracks = this.audioSources.map((e) => e.info);
1264
+ let n = this.audioTrack >= 0 ? this.audioSources[this.audioTrack]?.rendition.language ?? this.opts.audioLanguage : this.opts.audioLanguage;
1265
+ this.audioTrack = Q(t, n), this.opts.onAudioTracks?.(this.audioTracks);
1266
+ }
1267
+ destroy() {
1268
+ if (!this.destroyed) {
1269
+ this.destroyed = !0, this.abort.abort(), this.timer && clearInterval(this.timer), this.media.removeEventListener("seeking", this.onSeeking);
1270
+ for (let e of this.streams) e.destroy();
1271
+ this.objectUrl && (this.media.removeAttribute("src"), this.media.load(), URL.revokeObjectURL(this.objectUrl)), this.ms = null;
1272
+ }
1273
+ }
1274
+ fail(e) {
1275
+ if (this.destroyed || Z(e) || this.failed) return;
1276
+ this.failed = !0;
1277
+ let t;
1278
+ t = e instanceof q ? e : e instanceof n ? new q("manifest", e.message) : e instanceof T || e?.name === "NotSupportedError" ? new q("codec", e.message) : new q("network", e?.message ?? String(e)), this.timer && clearInterval(this.timer);
1279
+ for (let e of this.streams) e.stopTimers();
1280
+ this.opts.onError?.(t);
1281
+ }
1282
+ bufferCreated() {
1283
+ this.created++, this.created >= this.streams.length && this.readyWaiters.splice(0).forEach((e) => e());
1284
+ }
1285
+ buffersReady() {
1286
+ return this.created >= this.streams.length ? Promise.resolve() : new Promise((e) => this.readyWaiters.push(e));
1287
+ }
1288
+ offsetFor(e, t) {
1289
+ let n = this.offsets.get(e.cc);
1290
+ return n === void 0 && (n = e.start - t, this.offsets.set(e.cc, n)), n;
1291
+ }
1292
+ targetTime() {
1293
+ return this.media.currentTime;
1294
+ }
1295
+ tickAll() {
1296
+ if (!(this.destroyed || this.failed)) {
1297
+ this.jumpGap(this.media.currentTime);
1298
+ for (let e of this.streams) e.tick();
1299
+ }
1300
+ }
1301
+ maybeEndOfStream() {
1302
+ let e = this.ms;
1303
+ if (!(!e || e.readyState !== "open" || this.live) && this.streams.length && this.streams.every((e) => e.ended && e.idle)) try {
1304
+ e.endOfStream();
1305
+ } catch {}
1306
+ }
1307
+ async request(e, t, n) {
1308
+ let r = {};
1309
+ t && (r.Range = `bytes=${t.offset}-${t.offset + t.length - 1}`);
1310
+ let i = 0;
1311
+ for (;;) {
1312
+ try {
1313
+ let t = await this.fetchFn(e, {
1314
+ headers: r,
1315
+ signal: n
1316
+ });
1317
+ if (t.ok) return t;
1318
+ if (!Re(t.status) || i >= this.opts.retries) throw new q("network", `HTTP ${t.status} for ${e}`);
1319
+ } catch (e) {
1320
+ if (Z(e) || e instanceof q || i >= this.opts.retries) throw e;
1321
+ }
1322
+ await ze(500 * 2 ** i, n), i++;
1323
+ }
1324
+ }
1325
+ async fetchText(e) {
1326
+ return (await this.request(e, void 0, this.abort.signal)).text();
1327
+ }
1328
+ async fetchBytes(e, t, n) {
1329
+ let r = performance.now(), i = await this.request(e, t, n), a = await i.arrayBuffer(), o = new Uint8Array(a);
1330
+ return t && i.status === 200 && o.length > t.length && (o = o.subarray(t.offset, t.offset + t.length)), {
1331
+ data: o,
1332
+ ms: performance.now() - r
1333
+ };
1334
+ }
1335
+ updateSeekable(e) {
1336
+ let t = this.ms;
1337
+ if (!t || t.readyState !== "open" || !e.segments.length) return;
1338
+ let n = e.segments[0], r = e.segments[e.segments.length - 1];
1339
+ try {
1340
+ t.duration !== Infinity && !this.streams.some((e) => e.sb?.updating) && (t.duration = Infinity), t.setLiveSeekableRange?.(n.start, r.start + r.duration);
1341
+ } catch {}
1342
+ }
1343
+ pickLevel() {
1344
+ let e = this.all.map((e) => e.info), n = this.opts.capToPlayerSize === !1 ? void 0 : Math.round((this.media.clientHeight || 0) * (window.devicePixelRatio || 1)) || void 0, r = this.media.currentTime, i = this.main ? this.main.bufferedEnd(r) - r : 0;
1345
+ return t(e, this.est.estimate, {
1346
+ maxHeight: n,
1347
+ bufferAhead: this.est.hasSamples ? i : void 0,
1348
+ current: this.level >= 0 ? this.level : void 0
1349
+ });
1350
+ }
1351
+ afterMainSegment() {
1352
+ if (this.autoLevel && this.all.length > 1) {
1353
+ let e = this.pickLevel();
1354
+ e !== this.level && this.switchTo(e, !1);
1355
+ }
1356
+ }
1357
+ setLevel(e) {
1358
+ if (e < 0) {
1359
+ this.autoLevel = !0;
1360
+ return;
1361
+ }
1362
+ e >= this.all.length || (this.autoLevel = !1, e !== this.level && this.switchTo(e, !0));
1363
+ }
1364
+ switchTo(e, t) {
1365
+ let n = this.all[this.level]?.variant.audio;
1366
+ this.level = e, this.opts.onLevelSwitched?.(e), this.main?.switchSource(this.all[e], t ? "ahead" : "none");
1367
+ let r = this.all[e].variant.audio;
1368
+ if (r !== n && this.audio) {
1369
+ let e = this.audioSources[this.audioTrack]?.rendition;
1370
+ this.buildAudioTracks(r);
1371
+ let t = this.audioSources.findIndex((t) => t.rendition.language === e?.language && t.rendition.name === e?.name);
1372
+ t >= 0 && (this.audioTrack = t);
1373
+ let n = this.audioSources[this.audioTrack];
1374
+ n && this.audio.switchSource(n, "all"), this.opts.onAudioTrackSwitched?.(this.audioTrack);
1375
+ }
1376
+ }
1377
+ stats() {
1378
+ return {
1379
+ buffered: {
1380
+ main: this.main?.buffered() ?? [],
1381
+ ...this.audio ? { audio: this.audio.buffered() } : {}
1382
+ },
1383
+ level: this.level,
1384
+ audioTrack: this.audioTrack,
1385
+ bandwidth: this.est.estimate
1386
+ };
1387
+ }
1388
+ setAudioTrack(e) {
1389
+ let t = this.audioSources[e];
1390
+ !t || e === this.audioTrack || !this.audio || (this.audioTrack = e, this.audio.switchSource(t, "all"), this.opts.onAudioTrackSwitched?.(e));
1391
+ }
1392
+ jumpGap(e) {
1393
+ let t = X(this.media.buffered);
1394
+ if (!t.length || this.media.seeking) return;
1395
+ let n = t.find(([t, n]) => e >= t && e < n), r = t.find(([t]) => t > e);
1396
+ if (!n) {
1397
+ r && (r[0] - e < 1 || !this.startPositioned && this.live) && (this.media.currentTime = r[0] + .01);
1398
+ return;
1399
+ }
1400
+ if (!(!this.media.paused && this.media.readyState < 3)) {
1401
+ this.stallPos = -1;
1402
+ return;
1403
+ }
1404
+ if (this.stallPos !== e) {
1405
+ this.stallPos = e, this.stallSince = performance.now();
1406
+ return;
1407
+ }
1408
+ performance.now() - this.stallSince < 500 || r && n[1] - e < .5 && r[0] - n[1] < 1 && (this.media.currentTime = r[0] + .01);
1409
+ }
1410
+ };
1411
+ function $(e, t) {
1412
+ if (!e.segments.length || !t.segments.length) return;
1413
+ let n = new Map(e.segments.map((e) => [e.sn, e])), r = null;
1414
+ for (let e of t.segments) {
1415
+ let t = n.get(e.sn);
1416
+ if (t) {
1417
+ r = t.start - e.start;
1418
+ break;
1419
+ }
1420
+ }
1421
+ if (r === null) {
1422
+ let n = e.segments[e.segments.length - 1], i = t.segments[0];
1423
+ if (i.sn <= n.sn) return;
1424
+ let a = (i.sn - n.sn - 1) * (t.targetDuration || n.duration);
1425
+ r = n.start + n.duration + a - i.start;
1426
+ }
1427
+ if (r) for (let e of t.segments) e.start += r;
1428
+ }
1429
+ function Ue(e, t, n) {
1430
+ e.src = t;
1431
+ let r = e.audioTracks, i = {
1432
+ native: !0,
1433
+ get live() {
1434
+ return e.duration === Infinity;
1435
+ },
1436
+ levels: [],
1437
+ level: -1,
1438
+ autoLevel: !0,
1439
+ audioTracks: [],
1440
+ audioTrack: -1,
1441
+ bandwidth: 0,
1442
+ setLevel: () => {},
1443
+ stats: () => ({
1444
+ buffered: { main: X(e.buffered) },
1445
+ level: -1,
1446
+ audioTrack: i.audioTrack,
1447
+ bandwidth: 0
1448
+ }),
1449
+ setAudioTrack(e) {
1450
+ if (!(!r || e < 0 || e >= r.length)) for (let t = 0; t < r.length; t++) r[t].enabled = t === e;
1451
+ },
1452
+ destroy() {
1453
+ r?.removeEventListener("addtrack", a), r?.removeEventListener("removetrack", a), r?.removeEventListener("change", a), e.removeAttribute("src"), e.load();
1454
+ }
1455
+ };
1456
+ function a() {
1457
+ if (!r) return;
1458
+ let e = [], t = -1;
1459
+ for (let n = 0; n < r.length; n++) {
1460
+ let i = r[n];
1461
+ e.push({
1462
+ index: n,
1463
+ label: i.label || i.language || `#${n + 1}`,
1464
+ language: i.language || void 0,
1465
+ default: i.kind === "main"
1466
+ }), i.enabled && (t = n);
1467
+ }
1468
+ let a = e.length !== i.audioTracks.length;
1469
+ i.audioTracks = e, a && n.onAudioTracks?.(e), t !== i.audioTrack && (i.audioTrack = t, n.onAudioTrackSwitched?.(t));
1470
+ }
1471
+ return r?.addEventListener("addtrack", a), r?.addEventListener("removetrack", a), r?.addEventListener("change", a), i;
1472
+ }
1473
+ function We(e, t, n = {}) {
1474
+ if (n.preferNative !== !1 && Y(e)) return Ue(e, t, n);
1475
+ if (!J()) {
1476
+ let e = new q("mse", "MediaSource is not available");
1477
+ return queueMicrotask(() => n.onError?.(e)), {
1478
+ native: !1,
1479
+ live: !1,
1480
+ levels: [],
1481
+ level: -1,
1482
+ autoLevel: !0,
1483
+ audioTracks: [],
1484
+ audioTrack: -1,
1485
+ bandwidth: 0,
1486
+ setLevel: () => {},
1487
+ setAudioTrack: () => {},
1488
+ destroy: () => {},
1489
+ stats: () => ({
1490
+ buffered: { main: [] },
1491
+ level: -1,
1492
+ audioTrack: -1,
1493
+ bandwidth: 0
1494
+ })
1495
+ };
1496
+ }
1497
+ return new He(e, typeof location < "u" ? new URL(t, location.href).href : t, n);
1498
+ }
1499
+ //#endregion
1500
+ export { e as BandwidthEstimator, q as HlsError, n as HlsParseError, T as TransmuxError, G as TsTransmuxer, $ as alignTimes, We as attachHls, Y as canPlayNativeHls, t as chooseLevel, K as createTsTransmuxer, w as fragmentStart, J as getMediaSource, y as isFmp4, Ie as isHlsSupported, b as isMpegTs, O as isPackedAudio, r as parseAttributes, C as parseInit, k as parsePackedAudio, s as parsePlaylist, Q as pickAudioRendition, u as sequenceIv };