manim-web 0.10.0 → 0.12.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 (69) hide show
  1. package/dist/GLTFLoader-CisHz7tR.js +1381 -0
  2. package/dist/GLTFLoader-DMbWuMln.js +1381 -0
  3. package/dist/OBJLoader-Clh2POv9.js +287 -0
  4. package/dist/OBJLoader-kkTsEhJf.js +287 -0
  5. package/dist/audio/Voiceover.d.ts +95 -0
  6. package/dist/audio/Voiceover.d.ts.map +1 -0
  7. package/dist/audio/VoiceoverScene.d.ts +28 -0
  8. package/dist/audio/VoiceoverScene.d.ts.map +1 -0
  9. package/dist/audio/bookmarks.d.ts +40 -0
  10. package/dist/audio/bookmarks.d.ts.map +1 -0
  11. package/dist/audio/speechSynthesizer.d.ts +95 -0
  12. package/dist/audio/speechSynthesizer.d.ts.map +1 -0
  13. package/dist/core/Mobject.d.ts +31 -0
  14. package/dist/core/Mobject.d.ts.map +1 -1
  15. package/dist/core/Scene.d.ts +9 -0
  16. package/dist/core/Scene.d.ts.map +1 -1
  17. package/dist/export/FrameExporter.d.ts +86 -0
  18. package/dist/export/FrameExporter.d.ts.map +1 -0
  19. package/dist/export/WebCodecsExporter.d.ts +108 -0
  20. package/dist/export/WebCodecsExporter.d.ts.map +1 -0
  21. package/dist/export/index.d.ts +2 -0
  22. package/dist/export/index.d.ts.map +1 -1
  23. package/dist/index.d.ts +12 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -2
  26. package/dist/integrations/react.js +17 -16
  27. package/dist/integrations/vue.js +16 -15
  28. package/dist/integrations/webcomponent.d.ts +65 -0
  29. package/dist/integrations/webcomponent.d.ts.map +1 -0
  30. package/dist/integrations/webcomponent.js +2 -0
  31. package/dist/interaction/MovablePoint.d.ts +127 -0
  32. package/dist/interaction/MovablePoint.d.ts.map +1 -0
  33. package/dist/interaction/Slider.d.ts +125 -0
  34. package/dist/interaction/Slider.d.ts.map +1 -0
  35. package/dist/interaction/index.d.ts +2 -0
  36. package/dist/interaction/index.d.ts.map +1 -1
  37. package/dist/manim-web.browser.js +10073 -20358
  38. package/dist/mobjects/svg/SVGMobject.d.ts +29 -0
  39. package/dist/mobjects/svg/SVGMobject.d.ts.map +1 -1
  40. package/dist/mobjects/svg/index.d.ts +3 -1
  41. package/dist/mobjects/svg/index.d.ts.map +1 -1
  42. package/dist/mobjects/svg/svgFill.d.ts +42 -0
  43. package/dist/mobjects/svg/svgFill.d.ts.map +1 -0
  44. package/dist/mobjects/svg/svgGradients.d.ts +68 -0
  45. package/dist/mobjects/svg/svgGradients.d.ts.map +1 -0
  46. package/dist/mobjects/svg/svgImage.d.ts +9 -0
  47. package/dist/mobjects/svg/svgImage.d.ts.map +1 -0
  48. package/dist/mobjects/svg/svgLoader.d.ts +35 -0
  49. package/dist/mobjects/svg/svgLoader.d.ts.map +1 -0
  50. package/dist/mobjects/svg/svgText.d.ts +15 -0
  51. package/dist/mobjects/svg/svgText.d.ts.map +1 -0
  52. package/dist/mobjects/three-d/ModelMobject.d.ts +122 -0
  53. package/dist/mobjects/three-d/ModelMobject.d.ts.map +1 -0
  54. package/dist/mobjects/video/VideoMobject.d.ts +126 -0
  55. package/dist/mobjects/video/VideoMobject.d.ts.map +1 -0
  56. package/dist/mobjects/video/index.d.ts +2 -0
  57. package/dist/mobjects/video/index.d.ts.map +1 -0
  58. package/dist/mp4-muxer-5DGKGEJk.js +900 -0
  59. package/dist/player/Player.d.ts +4 -0
  60. package/dist/player/Player.d.ts.map +1 -1
  61. package/dist/rendering/blendModes.d.ts +38 -0
  62. package/dist/rendering/blendModes.d.ts.map +1 -0
  63. package/dist/{src-D29Z9zIa.js → src-BQF5-SG7.js} +6853 -6218
  64. package/dist/three.core-1aHSpGwp.js +11626 -0
  65. package/dist/utils/ThemeManager.d.ts +79 -0
  66. package/dist/utils/ThemeManager.d.ts.map +1 -0
  67. package/dist/webcomponent-BS5WnkDO.js +707 -0
  68. package/dist/webm-muxer-BGY-Mgbp.js +857 -0
  69. package/package.json +9 -2
@@ -0,0 +1,900 @@
1
+ //#region node_modules/mp4-muxer/build/mp4-muxer.mjs
2
+ var e = (e, t, n) => {
3
+ if (!t.has(e)) throw TypeError("Cannot " + n);
4
+ }, t = (t, n, r) => (e(t, n, "read from private field"), r ? r.call(t) : n.get(t)), n = (e, t, n) => {
5
+ if (t.has(e)) throw TypeError("Cannot add the same private member more than once");
6
+ t instanceof WeakSet ? t.add(e) : t.set(e, n);
7
+ }, r = (t, n, r, i) => (e(t, n, "write to private field"), i ? i.call(t, r) : n.set(t, r), r), i = (e, n, i, a) => ({
8
+ set _(t) {
9
+ r(e, n, t, i);
10
+ },
11
+ get _() {
12
+ return t(e, n, a);
13
+ }
14
+ }), a = (t, n, r) => (e(t, n, "access private method"), r), o = /* @__PURE__ */ new Uint8Array(8), s = new DataView(o.buffer), c = (e) => [(e % 256 + 256) % 256], l = (e) => (s.setUint16(0, e, !1), [o[0], o[1]]), u = (e) => (s.setInt16(0, e, !1), [o[0], o[1]]), d = (e) => (s.setUint32(0, e, !1), [
15
+ o[1],
16
+ o[2],
17
+ o[3]
18
+ ]), f = (e) => (s.setUint32(0, e, !1), [
19
+ o[0],
20
+ o[1],
21
+ o[2],
22
+ o[3]
23
+ ]), ee = (e) => (s.setInt32(0, e, !1), [
24
+ o[0],
25
+ o[1],
26
+ o[2],
27
+ o[3]
28
+ ]), p = (e) => (s.setUint32(0, Math.floor(e / 2 ** 32), !1), s.setUint32(4, e, !1), [
29
+ o[0],
30
+ o[1],
31
+ o[2],
32
+ o[3],
33
+ o[4],
34
+ o[5],
35
+ o[6],
36
+ o[7]
37
+ ]), m = (e) => (s.setInt16(0, 2 ** 8 * e, !1), [o[0], o[1]]), h = (e) => (s.setInt32(0, 2 ** 16 * e, !1), [
38
+ o[0],
39
+ o[1],
40
+ o[2],
41
+ o[3]
42
+ ]), te = (e) => (s.setInt32(0, 2 ** 30 * e, !1), [
43
+ o[0],
44
+ o[1],
45
+ o[2],
46
+ o[3]
47
+ ]), g = (e, t = !1) => {
48
+ let n = Array(e.length).fill(null).map((t, n) => e.charCodeAt(n));
49
+ return t && n.push(0), n;
50
+ }, _ = (e) => e && e[e.length - 1], ne = (e) => {
51
+ let t;
52
+ for (let n of e) (!t || n.presentationTimestamp > t.presentationTimestamp) && (t = n);
53
+ return t;
54
+ }, v = (e, t, n = !0) => {
55
+ let r = e * t;
56
+ return n ? Math.round(r) : r;
57
+ }, re = (e) => {
58
+ let t = Math.PI / 180 * e, n = Math.cos(t), r = Math.sin(t);
59
+ return [
60
+ n,
61
+ r,
62
+ 0,
63
+ -r,
64
+ n,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 1
69
+ ];
70
+ }, ie = re(0), ae = (e) => [
71
+ h(e[0]),
72
+ h(e[1]),
73
+ te(e[2]),
74
+ h(e[3]),
75
+ h(e[4]),
76
+ te(e[5]),
77
+ h(e[6]),
78
+ h(e[7]),
79
+ te(e[8])
80
+ ], y = (e) => !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(y) : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, y(t)])), b = (e) => e >= 0 && e < 2 ** 32, x = (e, t, n) => ({
81
+ type: e,
82
+ contents: t && new Uint8Array(t.flat(10)),
83
+ children: n
84
+ }), S = (e, t, n, r, i) => x(e, [
85
+ c(t),
86
+ d(n),
87
+ r ?? []
88
+ ], i), oe = (e) => e.fragmented ? x("ftyp", [
89
+ g("iso5"),
90
+ f(512),
91
+ g("iso5"),
92
+ g("iso6"),
93
+ g("mp41")
94
+ ]) : x("ftyp", [
95
+ g("isom"),
96
+ f(512),
97
+ g("isom"),
98
+ e.holdsAvc ? g("avc1") : [],
99
+ g("mp41")
100
+ ]), se = (e) => ({
101
+ type: "mdat",
102
+ largeSize: e
103
+ }), ce = (e) => ({
104
+ type: "free",
105
+ size: e
106
+ }), le = (e, t, n = !1) => x("moov", null, [
107
+ ue(t, e),
108
+ ...e.map((e) => de(e, t)),
109
+ n ? He(e) : null
110
+ ]), ue = (e, t) => {
111
+ let n = v(Math.max(0, ...t.filter((e) => e.samples.length > 0).map((e) => {
112
+ let t = ne(e.samples);
113
+ return t.presentationTimestamp + t.duration;
114
+ })), bt), r = Math.max(...t.map((e) => e.id)) + 1, i = !b(e) || !b(n), a = i ? p : f;
115
+ return S("mvhd", +i, 0, [
116
+ a(e),
117
+ a(e),
118
+ f(bt),
119
+ a(n),
120
+ h(1),
121
+ m(1),
122
+ Array(10).fill(0),
123
+ ae(ie),
124
+ Array(24).fill(0),
125
+ f(r)
126
+ ]);
127
+ }, de = (e, t) => x("trak", null, [fe(e, t), pe(e, t)]), fe = (e, t) => {
128
+ let n = ne(e.samples), r = v(n ? n.presentationTimestamp + n.duration : 0, bt), i = !b(t) || !b(r), a = i ? p : f, o;
129
+ return o = e.info.type === "video" ? typeof e.info.rotation == "number" ? re(e.info.rotation) : e.info.rotation : ie, S("tkhd", +i, 3, [
130
+ a(t),
131
+ a(t),
132
+ f(e.id),
133
+ f(0),
134
+ a(r),
135
+ Array(8).fill(0),
136
+ l(0),
137
+ l(0),
138
+ m(+(e.info.type === "audio")),
139
+ l(0),
140
+ ae(o),
141
+ h(e.info.type === "video" ? e.info.width : 0),
142
+ h(e.info.type === "video" ? e.info.height : 0)
143
+ ]);
144
+ }, pe = (e, t) => x("mdia", null, [
145
+ me(e, t),
146
+ he(e.info.type === "video" ? "vide" : "soun"),
147
+ ge(e)
148
+ ]), me = (e, t) => {
149
+ let n = ne(e.samples), r = v(n ? n.presentationTimestamp + n.duration : 0, e.timescale), i = !b(t) || !b(r), a = i ? p : f;
150
+ return S("mdhd", +i, 0, [
151
+ a(t),
152
+ a(t),
153
+ f(e.timescale),
154
+ a(r),
155
+ l(21956),
156
+ l(0)
157
+ ]);
158
+ }, he = (e) => S("hdlr", 0, 0, [
159
+ g("mhlr"),
160
+ g(e),
161
+ f(0),
162
+ f(0),
163
+ f(0),
164
+ g("mp4-muxer-hdlr", !0)
165
+ ]), ge = (e) => x("minf", null, [
166
+ e.info.type === "video" ? _e() : ve(),
167
+ ye(),
168
+ Se(e)
169
+ ]), _e = () => S("vmhd", 0, 1, [
170
+ l(0),
171
+ l(0),
172
+ l(0),
173
+ l(0)
174
+ ]), ve = () => S("smhd", 0, 0, [l(0), l(0)]), ye = () => x("dinf", null, [be()]), be = () => S("dref", 0, 0, [f(1)], [xe()]), xe = () => S("url ", 0, 1), Se = (e) => {
175
+ let t = e.compositionTimeOffsetTable.length > 1 || e.compositionTimeOffsetTable.some((e) => e.sampleCompositionTimeOffset !== 0);
176
+ return x("stbl", null, [
177
+ Ce(e),
178
+ Ie(e),
179
+ Le(e),
180
+ Re(e),
181
+ ze(e),
182
+ Be(e),
183
+ t ? Ve(e) : null
184
+ ]);
185
+ }, Ce = (e) => S("stsd", 0, 0, [f(1)], [e.info.type === "video" ? we(et[e.info.codec], e) : Ne(nt[e.info.codec], e)]), we = (e, t) => x(e, [
186
+ [
187
+ ,
188
+ ,
189
+ ,
190
+ ,
191
+ ,
192
+ ,
193
+ ].fill(0),
194
+ l(1),
195
+ l(0),
196
+ l(0),
197
+ Array(12).fill(0),
198
+ l(t.info.width),
199
+ l(t.info.height),
200
+ f(4718592),
201
+ f(4718592),
202
+ f(0),
203
+ l(1),
204
+ Array(32).fill(0),
205
+ l(24),
206
+ u(65535)
207
+ ], [tt[t.info.codec](t), t.info.decoderConfig.colorSpace ? Oe(t) : null]), Te = {
208
+ bt709: 1,
209
+ bt470bg: 5,
210
+ smpte170m: 6
211
+ }, Ee = {
212
+ bt709: 1,
213
+ smpte170m: 6,
214
+ "iec61966-2-1": 13
215
+ }, De = {
216
+ rgb: 0,
217
+ bt709: 1,
218
+ bt470bg: 5,
219
+ smpte170m: 6
220
+ }, Oe = (e) => x("colr", [
221
+ g("nclx"),
222
+ l(Te[e.info.decoderConfig.colorSpace.primaries]),
223
+ l(Ee[e.info.decoderConfig.colorSpace.transfer]),
224
+ l(De[e.info.decoderConfig.colorSpace.matrix]),
225
+ c(!!e.info.decoderConfig.colorSpace.fullRange << 7)
226
+ ]), ke = (e) => e.info.decoderConfig && x("avcC", [...new Uint8Array(e.info.decoderConfig.description)]), Ae = (e) => e.info.decoderConfig && x("hvcC", [...new Uint8Array(e.info.decoderConfig.description)]), je = (e) => {
227
+ if (!e.info.decoderConfig) return null;
228
+ let t = e.info.decoderConfig;
229
+ if (!t.colorSpace) throw Error("'colorSpace' is required in the decoder config for VP9.");
230
+ let n = t.codec.split("."), r = Number(n[1]), i = Number(n[2]), a = (Number(n[3]) << 4) + 0 + Number(t.colorSpace.fullRange);
231
+ return S("vpcC", 1, 0, [
232
+ c(r),
233
+ c(i),
234
+ c(a),
235
+ c(2),
236
+ c(2),
237
+ c(2),
238
+ l(0)
239
+ ]);
240
+ }, Me = () => x("av1C", [
241
+ 129,
242
+ 0,
243
+ 0,
244
+ 0
245
+ ]), Ne = (e, t) => x(e, [
246
+ [
247
+ ,
248
+ ,
249
+ ,
250
+ ,
251
+ ,
252
+ ,
253
+ ].fill(0),
254
+ l(1),
255
+ l(0),
256
+ l(0),
257
+ f(0),
258
+ l(t.info.numberOfChannels),
259
+ l(16),
260
+ l(0),
261
+ l(0),
262
+ h(t.info.sampleRate)
263
+ ], [rt[t.info.codec](t)]), Pe = (e) => {
264
+ let t = new Uint8Array(e.info.decoderConfig.description);
265
+ return S("esds", 0, 0, [
266
+ f(58753152),
267
+ c(32 + t.byteLength),
268
+ l(1),
269
+ c(0),
270
+ f(75530368),
271
+ c(18 + t.byteLength),
272
+ c(64),
273
+ c(21),
274
+ d(0),
275
+ f(130071),
276
+ f(130071),
277
+ f(92307584),
278
+ c(t.byteLength),
279
+ ...t,
280
+ f(109084800),
281
+ c(1),
282
+ c(2)
283
+ ]);
284
+ }, Fe = (e) => {
285
+ let t = 3840, n = 0, r = e.info.decoderConfig?.description;
286
+ if (r) {
287
+ if (r.byteLength < 18) throw TypeError("Invalid decoder description provided for Opus; must be at least 18 bytes long.");
288
+ let e = ArrayBuffer.isView(r) ? new DataView(r.buffer, r.byteOffset, r.byteLength) : new DataView(r);
289
+ t = e.getUint16(10, !0), n = e.getInt16(14, !0);
290
+ }
291
+ return x("dOps", [
292
+ c(0),
293
+ c(e.info.numberOfChannels),
294
+ l(t),
295
+ f(e.info.sampleRate),
296
+ m(n),
297
+ c(0)
298
+ ]);
299
+ }, Ie = (e) => S("stts", 0, 0, [f(e.timeToSampleTable.length), e.timeToSampleTable.map((e) => [f(e.sampleCount), f(e.sampleDelta)])]), Le = (e) => {
300
+ if (e.samples.every((e) => e.type === "key")) return null;
301
+ let t = [...e.samples.entries()].filter(([, e]) => e.type === "key");
302
+ return S("stss", 0, 0, [f(t.length), t.map(([e]) => f(e + 1))]);
303
+ }, Re = (e) => S("stsc", 0, 0, [f(e.compactlyCodedChunkTable.length), e.compactlyCodedChunkTable.map((e) => [
304
+ f(e.firstChunk),
305
+ f(e.samplesPerChunk),
306
+ f(1)
307
+ ])]), ze = (e) => S("stsz", 0, 0, [
308
+ f(0),
309
+ f(e.samples.length),
310
+ e.samples.map((e) => f(e.size))
311
+ ]), Be = (e) => e.finalizedChunks.length > 0 && _(e.finalizedChunks).offset >= 2 ** 32 ? S("co64", 0, 0, [f(e.finalizedChunks.length), e.finalizedChunks.map((e) => p(e.offset))]) : S("stco", 0, 0, [f(e.finalizedChunks.length), e.finalizedChunks.map((e) => f(e.offset))]), Ve = (e) => S("ctts", 0, 0, [f(e.compositionTimeOffsetTable.length), e.compositionTimeOffsetTable.map((e) => [f(e.sampleCount), f(e.sampleCompositionTimeOffset)])]), He = (e) => x("mvex", null, e.map(Ue)), Ue = (e) => S("trex", 0, 0, [
312
+ f(e.id),
313
+ f(1),
314
+ f(0),
315
+ f(0),
316
+ f(0)
317
+ ]), We = (e, t) => x("moof", null, [Ge(e), ...t.map(qe)]), Ge = (e) => S("mfhd", 0, 0, [f(e)]), Ke = (e) => {
318
+ let t = 0, n = 0, r = e.type === "delta";
319
+ return n |= +r, r ? t |= 1 : t |= 2, t << 24 | n << 16 | 0;
320
+ }, qe = (e) => x("traf", null, [
321
+ Je(e),
322
+ Ye(e),
323
+ Xe(e)
324
+ ]), Je = (e) => {
325
+ let t = 0;
326
+ t |= 8, t |= 16, t |= 32, t |= 131072;
327
+ let n = e.currentChunk.samples[1] ?? e.currentChunk.samples[0], r = {
328
+ duration: n.timescaleUnitsToNextSample,
329
+ size: n.size,
330
+ flags: Ke(n)
331
+ };
332
+ return S("tfhd", 0, t, [
333
+ f(e.id),
334
+ f(r.duration),
335
+ f(r.size),
336
+ f(r.flags)
337
+ ]);
338
+ }, Ye = (e) => S("tfdt", 1, 0, [p(v(e.currentChunk.startTimestamp, e.timescale))]), Xe = (e) => {
339
+ let t = e.currentChunk.samples.map((e) => e.timescaleUnitsToNextSample), n = e.currentChunk.samples.map((e) => e.size), r = e.currentChunk.samples.map(Ke), i = e.currentChunk.samples.map((t) => v(t.presentationTimestamp - t.decodeTimestamp, e.timescale)), a = new Set(t), o = new Set(n), s = new Set(r), c = new Set(i), l = s.size === 2 && r[0] !== r[1], u = a.size > 1, d = o.size > 1, p = !l && s.size > 1, m = c.size > 1 || [...c].some((e) => e !== 0), h = 0;
340
+ return h |= 1, h |= 4 * l, h |= 256 * u, h |= 512 * d, h |= 1024 * p, h |= 2048 * m, S("trun", 1, h, [
341
+ f(e.currentChunk.samples.length),
342
+ f(e.currentChunk.offset - e.currentChunk.moofOffset || 0),
343
+ l ? f(r[0]) : [],
344
+ e.currentChunk.samples.map((e, a) => [
345
+ u ? f(t[a]) : [],
346
+ d ? f(n[a]) : [],
347
+ p ? f(r[a]) : [],
348
+ m ? ee(i[a]) : []
349
+ ])
350
+ ]);
351
+ }, Ze = (e) => x("mfra", null, [...e.map(Qe), $e()]), Qe = (e, t) => S("tfra", 1, 0, [
352
+ f(e.id),
353
+ f(63),
354
+ f(e.finalizedChunks.length),
355
+ e.finalizedChunks.map((n) => [
356
+ p(v(n.startTimestamp, e.timescale)),
357
+ p(n.moofOffset),
358
+ f(t + 1),
359
+ f(1),
360
+ f(1)
361
+ ])
362
+ ]), $e = () => S("mfro", 0, 0, [f(0)]), et = {
363
+ avc: "avc1",
364
+ hevc: "hvc1",
365
+ vp9: "vp09",
366
+ av1: "av01"
367
+ }, tt = {
368
+ avc: ke,
369
+ hevc: Ae,
370
+ vp9: je,
371
+ av1: Me
372
+ }, nt = {
373
+ aac: "mp4a",
374
+ opus: "Opus"
375
+ }, rt = {
376
+ aac: Pe,
377
+ opus: Fe
378
+ }, C = class {}, it = class extends C {
379
+ constructor() {
380
+ super(...arguments), this.buffer = null;
381
+ }
382
+ }, at = class extends C {
383
+ constructor(e) {
384
+ if (super(), this.options = e, typeof e != "object") throw TypeError("StreamTarget requires an options object to be passed to its constructor.");
385
+ if (e.onData) {
386
+ if (typeof e.onData != "function") throw TypeError("options.onData, when provided, must be a function.");
387
+ if (e.onData.length < 2) throw TypeError("options.onData, when provided, must be a function that takes in at least two arguments (data and position). Ignoring the position argument, which specifies the byte offset at which the data is to be written, can lead to broken outputs.");
388
+ }
389
+ if (e.chunked !== void 0 && typeof e.chunked != "boolean") throw TypeError("options.chunked, when provided, must be a boolean.");
390
+ if (e.chunkSize !== void 0 && (!Number.isInteger(e.chunkSize) || e.chunkSize < 1024)) throw TypeError("options.chunkSize, when provided, must be an integer and not smaller than 1024.");
391
+ }
392
+ }, ot = class extends C {
393
+ constructor(e, t) {
394
+ if (super(), this.stream = e, this.options = t, !(e instanceof FileSystemWritableFileStream)) throw TypeError("FileSystemWritableFileStreamTarget requires a FileSystemWritableFileStream instance.");
395
+ if (t !== void 0 && typeof t != "object") throw TypeError("FileSystemWritableFileStreamTarget's options, when provided, must be an object.");
396
+ if (t && t.chunkSize !== void 0 && (!Number.isInteger(t.chunkSize) || t.chunkSize <= 0)) throw TypeError("options.chunkSize, when provided, must be a positive integer");
397
+ }
398
+ }, w, T, st = class {
399
+ constructor() {
400
+ this.pos = 0, n(this, w, /* @__PURE__ */ new Uint8Array(8)), n(this, T, new DataView(t(this, w).buffer)), this.offsets = /* @__PURE__ */ new WeakMap();
401
+ }
402
+ seek(e) {
403
+ this.pos = e;
404
+ }
405
+ writeU32(e) {
406
+ t(this, T).setUint32(0, e, !1), this.write(t(this, w).subarray(0, 4));
407
+ }
408
+ writeU64(e) {
409
+ t(this, T).setUint32(0, Math.floor(e / 2 ** 32), !1), t(this, T).setUint32(4, e, !1), this.write(t(this, w).subarray(0, 8));
410
+ }
411
+ writeAscii(e) {
412
+ for (let n = 0; n < e.length; n++) t(this, T).setUint8(n % 8, e.charCodeAt(n)), n % 8 == 7 && this.write(t(this, w));
413
+ e.length % 8 != 0 && this.write(t(this, w).subarray(0, e.length % 8));
414
+ }
415
+ writeBox(e) {
416
+ if (this.offsets.set(e, this.pos), e.contents && !e.children) this.writeBoxHeader(e, e.size ?? e.contents.byteLength + 8), this.write(e.contents);
417
+ else {
418
+ let t = this.pos;
419
+ if (this.writeBoxHeader(e, 0), e.contents && this.write(e.contents), e.children) for (let t of e.children) t && this.writeBox(t);
420
+ let n = this.pos, r = e.size ?? n - t;
421
+ this.seek(t), this.writeBoxHeader(e, r), this.seek(n);
422
+ }
423
+ }
424
+ writeBoxHeader(e, t) {
425
+ this.writeU32(e.largeSize ? 1 : t), this.writeAscii(e.type), e.largeSize && this.writeU64(t);
426
+ }
427
+ measureBoxHeader(e) {
428
+ return 8 + (e.largeSize ? 8 : 0);
429
+ }
430
+ patchBox(e) {
431
+ let t = this.pos;
432
+ this.seek(this.offsets.get(e)), this.writeBox(e), this.seek(t);
433
+ }
434
+ measureBox(e) {
435
+ if (e.contents && !e.children) return this.measureBoxHeader(e) + e.contents.byteLength;
436
+ {
437
+ let t = this.measureBoxHeader(e);
438
+ if (e.contents && (t += e.contents.byteLength), e.children) for (let n of e.children) n && (t += this.measureBox(n));
439
+ return t;
440
+ }
441
+ }
442
+ };
443
+ w = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap();
444
+ var E, D, O, k, A, ct, lt = class extends st {
445
+ constructor(e) {
446
+ super(), n(this, A), n(this, E, void 0), n(this, D, /* @__PURE__ */ new ArrayBuffer(2 ** 16)), n(this, O, new Uint8Array(t(this, D))), n(this, k, 0), r(this, E, e);
447
+ }
448
+ write(e) {
449
+ a(this, A, ct).call(this, this.pos + e.byteLength), t(this, O).set(e, this.pos), this.pos += e.byteLength, r(this, k, Math.max(t(this, k), this.pos));
450
+ }
451
+ finalize() {
452
+ a(this, A, ct).call(this, this.pos), t(this, E).buffer = t(this, D).slice(0, Math.max(t(this, k), this.pos));
453
+ }
454
+ };
455
+ E = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakSet(), ct = function(e) {
456
+ let n = t(this, D).byteLength;
457
+ for (; n < e;) n *= 2;
458
+ if (n === t(this, D).byteLength) return;
459
+ let i = new ArrayBuffer(n), a = new Uint8Array(i);
460
+ a.set(t(this, O), 0), r(this, D, i), r(this, O, a);
461
+ };
462
+ var ut = 2 ** 24, dt = 2, j, M, N, P, F, I, ft, pt, mt, ht, gt, L, _t, vt = class extends st {
463
+ constructor(e) {
464
+ super(), n(this, I), n(this, pt), n(this, ht), n(this, L), n(this, j, void 0), n(this, M, []), n(this, N, void 0), n(this, P, void 0), n(this, F, []), r(this, j, e), r(this, N, e.options?.chunked ?? !1), r(this, P, e.options?.chunkSize ?? ut);
465
+ }
466
+ write(e) {
467
+ t(this, M).push({
468
+ data: e.slice(),
469
+ start: this.pos
470
+ }), this.pos += e.byteLength;
471
+ }
472
+ flush() {
473
+ if (t(this, M).length === 0) return;
474
+ let e = [], n = [...t(this, M)].sort((e, t) => e.start - t.start);
475
+ e.push({
476
+ start: n[0].start,
477
+ size: n[0].data.byteLength
478
+ });
479
+ for (let t = 1; t < n.length; t++) {
480
+ let r = e[e.length - 1], i = n[t];
481
+ i.start <= r.start + r.size ? r.size = Math.max(r.size, i.start + i.data.byteLength - r.start) : e.push({
482
+ start: i.start,
483
+ size: i.data.byteLength
484
+ });
485
+ }
486
+ for (let n of e) {
487
+ n.data = new Uint8Array(n.size);
488
+ for (let e of t(this, M)) n.start <= e.start && e.start < n.start + n.size && n.data.set(e.data, e.start - n.start);
489
+ t(this, N) ? (a(this, I, ft).call(this, n.data, n.start), a(this, L, _t).call(this)) : t(this, j).options.onData?.(n.data, n.start);
490
+ }
491
+ t(this, M).length = 0;
492
+ }
493
+ finalize() {
494
+ t(this, N) && a(this, L, _t).call(this, !0);
495
+ }
496
+ };
497
+ j = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakSet(), ft = function(e, n) {
498
+ let r = t(this, F).findIndex((e) => e.start <= n && n < e.start + t(this, P));
499
+ r === -1 && (r = a(this, ht, gt).call(this, n));
500
+ let i = t(this, F)[r], o = n - i.start, s = e.subarray(0, Math.min(t(this, P) - o, e.byteLength));
501
+ i.data.set(s, o);
502
+ let c = {
503
+ start: o,
504
+ end: o + s.byteLength
505
+ };
506
+ if (a(this, pt, mt).call(this, i, c), i.written[0].start === 0 && i.written[0].end === t(this, P) && (i.shouldFlush = !0), t(this, F).length > dt) {
507
+ for (let e = 0; e < t(this, F).length - 1; e++) t(this, F)[e].shouldFlush = !0;
508
+ a(this, L, _t).call(this);
509
+ }
510
+ s.byteLength < e.byteLength && a(this, I, ft).call(this, e.subarray(s.byteLength), n + s.byteLength);
511
+ }, pt = /* @__PURE__ */ new WeakSet(), mt = function(e, t) {
512
+ let n = 0, r = e.written.length - 1, i = -1;
513
+ for (; n <= r;) {
514
+ let a = Math.floor(n + (r - n + 1) / 2);
515
+ e.written[a].start <= t.start ? (n = a + 1, i = a) : r = a - 1;
516
+ }
517
+ for (e.written.splice(i + 1, 0, t), (i === -1 || e.written[i].end < t.start) && i++; i < e.written.length - 1 && e.written[i].end >= e.written[i + 1].start;) e.written[i].end = Math.max(e.written[i].end, e.written[i + 1].end), e.written.splice(i + 1, 1);
518
+ }, ht = /* @__PURE__ */ new WeakSet(), gt = function(e) {
519
+ let n = {
520
+ start: Math.floor(e / t(this, P)) * t(this, P),
521
+ data: new Uint8Array(t(this, P)),
522
+ written: [],
523
+ shouldFlush: !1
524
+ };
525
+ return t(this, F).push(n), t(this, F).sort((e, t) => e.start - t.start), t(this, F).indexOf(n);
526
+ }, L = /* @__PURE__ */ new WeakSet(), _t = function(e = !1) {
527
+ for (let n = 0; n < t(this, F).length; n++) {
528
+ let r = t(this, F)[n];
529
+ if (!(!r.shouldFlush && !e)) {
530
+ for (let e of r.written) t(this, j).options.onData?.(r.data.subarray(e.start, e.end), r.start + e.start);
531
+ t(this, F).splice(n--, 1);
532
+ }
533
+ }
534
+ };
535
+ var yt = class extends vt {
536
+ constructor(e) {
537
+ super(new at({
538
+ onData: (t, n) => e.stream.write({
539
+ type: "write",
540
+ data: t,
541
+ position: n
542
+ }),
543
+ chunked: !0,
544
+ chunkSize: e.options?.chunkSize
545
+ }));
546
+ }
547
+ }, bt = 1e3, xt = [
548
+ "avc",
549
+ "hevc",
550
+ "vp9",
551
+ "av1"
552
+ ], St = ["aac", "opus"], Ct = 2082844800, wt = [
553
+ "strict",
554
+ "offset",
555
+ "cross-track-offset"
556
+ ], R, z, Tt, B, V, H, U, W, Et, G, K, q, Dt, Ot, kt, At, jt, Mt, Nt, Pt, Ft, It, Lt, Rt, J, Y, zt, Bt, X, Vt, Z, Ht, Q, $, Ut, Wt, Gt = class {
557
+ constructor(e) {
558
+ if (n(this, Dt), n(this, kt), n(this, jt), n(this, Nt), n(this, Ft), n(this, Lt), n(this, J), n(this, zt), n(this, X), n(this, Z), n(this, Q), n(this, Ut), n(this, R, void 0), n(this, z, void 0), n(this, Tt, void 0), n(this, B, void 0), n(this, V, null), n(this, H, null), n(this, U, Math.floor(Date.now() / 1e3) + Ct), n(this, W, []), n(this, Et, 1), n(this, G, []), n(this, K, []), n(this, q, !1), a(this, Dt, Ot).call(this, e), e.video = y(e.video), e.audio = y(e.audio), e.fastStart = y(e.fastStart), this.target = e.target, r(this, R, {
559
+ firstTimestampBehavior: "strict",
560
+ ...e
561
+ }), e.target instanceof it) r(this, z, new lt(e.target));
562
+ else if (e.target instanceof at) r(this, z, new vt(e.target));
563
+ else if (e.target instanceof ot) r(this, z, new yt(e.target));
564
+ else throw Error(`Invalid target: ${e.target}`);
565
+ a(this, Nt, Pt).call(this), a(this, kt, At).call(this);
566
+ }
567
+ addVideoChunk(e, t, n, r) {
568
+ if (!(e instanceof EncodedVideoChunk)) throw TypeError("addVideoChunk's first argument (sample) must be of type EncodedVideoChunk.");
569
+ if (t && typeof t != "object") throw TypeError("addVideoChunk's second argument (meta), when provided, must be an object.");
570
+ if (n !== void 0 && (!Number.isFinite(n) || n < 0)) throw TypeError("addVideoChunk's third argument (timestamp), when provided, must be a non-negative real number.");
571
+ if (r !== void 0 && !Number.isFinite(r)) throw TypeError("addVideoChunk's fourth argument (compositionTimeOffset), when provided, must be a real number.");
572
+ let i = new Uint8Array(e.byteLength);
573
+ e.copyTo(i), this.addVideoChunkRaw(i, e.type, n ?? e.timestamp, e.duration, t, r);
574
+ }
575
+ addVideoChunkRaw(e, n, r, i, o, s) {
576
+ if (!(e instanceof Uint8Array)) throw TypeError("addVideoChunkRaw's first argument (data) must be an instance of Uint8Array.");
577
+ if (n !== "key" && n !== "delta") throw TypeError("addVideoChunkRaw's second argument (type) must be either 'key' or 'delta'.");
578
+ if (!Number.isFinite(r) || r < 0) throw TypeError("addVideoChunkRaw's third argument (timestamp) must be a non-negative real number.");
579
+ if (!Number.isFinite(i) || i < 0) throw TypeError("addVideoChunkRaw's fourth argument (duration) must be a non-negative real number.");
580
+ if (o && typeof o != "object") throw TypeError("addVideoChunkRaw's fifth argument (meta), when provided, must be an object.");
581
+ if (s !== void 0 && !Number.isFinite(s)) throw TypeError("addVideoChunkRaw's sixth argument (compositionTimeOffset), when provided, must be a real number.");
582
+ if (a(this, Ut, Wt).call(this), !t(this, R).video) throw Error("No video track declared.");
583
+ if (typeof t(this, R).fastStart == "object" && t(this, V).samples.length === t(this, R).fastStart.expectedVideoChunks) throw Error(`Cannot add more video chunks than specified in 'fastStart' (${t(this, R).fastStart.expectedVideoChunks}).`);
584
+ let c = a(this, Lt, Rt).call(this, t(this, V), e, n, r, i, o, s);
585
+ if (t(this, R).fastStart === "fragmented" && t(this, H)) {
586
+ for (; t(this, K).length > 0 && t(this, K)[0].decodeTimestamp <= c.decodeTimestamp;) {
587
+ let e = t(this, K).shift();
588
+ a(this, J, Y).call(this, t(this, H), e);
589
+ }
590
+ c.decodeTimestamp <= t(this, H).lastDecodeTimestamp ? a(this, J, Y).call(this, t(this, V), c) : t(this, G).push(c);
591
+ } else a(this, J, Y).call(this, t(this, V), c);
592
+ }
593
+ addAudioChunk(e, t, n) {
594
+ if (!(e instanceof EncodedAudioChunk)) throw TypeError("addAudioChunk's first argument (sample) must be of type EncodedAudioChunk.");
595
+ if (t && typeof t != "object") throw TypeError("addAudioChunk's second argument (meta), when provided, must be an object.");
596
+ if (n !== void 0 && (!Number.isFinite(n) || n < 0)) throw TypeError("addAudioChunk's third argument (timestamp), when provided, must be a non-negative real number.");
597
+ let r = new Uint8Array(e.byteLength);
598
+ e.copyTo(r), this.addAudioChunkRaw(r, e.type, n ?? e.timestamp, e.duration, t);
599
+ }
600
+ addAudioChunkRaw(e, n, r, i, o) {
601
+ if (!(e instanceof Uint8Array)) throw TypeError("addAudioChunkRaw's first argument (data) must be an instance of Uint8Array.");
602
+ if (n !== "key" && n !== "delta") throw TypeError("addAudioChunkRaw's second argument (type) must be either 'key' or 'delta'.");
603
+ if (!Number.isFinite(r) || r < 0) throw TypeError("addAudioChunkRaw's third argument (timestamp) must be a non-negative real number.");
604
+ if (!Number.isFinite(i) || i < 0) throw TypeError("addAudioChunkRaw's fourth argument (duration) must be a non-negative real number.");
605
+ if (o && typeof o != "object") throw TypeError("addAudioChunkRaw's fifth argument (meta), when provided, must be an object.");
606
+ if (a(this, Ut, Wt).call(this), !t(this, R).audio) throw Error("No audio track declared.");
607
+ if (typeof t(this, R).fastStart == "object" && t(this, H).samples.length === t(this, R).fastStart.expectedAudioChunks) throw Error(`Cannot add more audio chunks than specified in 'fastStart' (${t(this, R).fastStart.expectedAudioChunks}).`);
608
+ let s = a(this, Lt, Rt).call(this, t(this, H), e, n, r, i, o);
609
+ if (t(this, R).fastStart === "fragmented" && t(this, V)) {
610
+ for (; t(this, G).length > 0 && t(this, G)[0].decodeTimestamp <= s.decodeTimestamp;) {
611
+ let e = t(this, G).shift();
612
+ a(this, J, Y).call(this, t(this, V), e);
613
+ }
614
+ s.decodeTimestamp <= t(this, V).lastDecodeTimestamp ? a(this, J, Y).call(this, t(this, H), s) : t(this, K).push(s);
615
+ } else a(this, J, Y).call(this, t(this, H), s);
616
+ }
617
+ finalize() {
618
+ if (t(this, q)) throw Error("Cannot finalize a muxer more than once.");
619
+ if (t(this, R).fastStart === "fragmented") {
620
+ for (let e of t(this, G)) a(this, J, Y).call(this, t(this, V), e);
621
+ for (let e of t(this, K)) a(this, J, Y).call(this, t(this, H), e);
622
+ a(this, Z, Ht).call(this, !1);
623
+ } else t(this, V) && a(this, X, Vt).call(this, t(this, V)), t(this, H) && a(this, X, Vt).call(this, t(this, H));
624
+ let e = [t(this, V), t(this, H)].filter(Boolean);
625
+ if (t(this, R).fastStart === "in-memory") {
626
+ let n;
627
+ for (let r = 0; r < 2; r++) {
628
+ let r = le(e, t(this, U)), i = t(this, z).measureBox(r);
629
+ n = t(this, z).measureBox(t(this, B));
630
+ let a = t(this, z).pos + i + n;
631
+ for (let e of t(this, W)) {
632
+ e.offset = a;
633
+ for (let { data: t } of e.samples) a += t.byteLength, n += t.byteLength;
634
+ }
635
+ if (a < 2 ** 32) break;
636
+ n >= 2 ** 32 && (t(this, B).largeSize = !0);
637
+ }
638
+ let r = le(e, t(this, U));
639
+ t(this, z).writeBox(r), t(this, B).size = n, t(this, z).writeBox(t(this, B));
640
+ for (let e of t(this, W)) for (let n of e.samples) t(this, z).write(n.data), n.data = null;
641
+ } else if (t(this, R).fastStart === "fragmented") {
642
+ let n = t(this, z).pos, r = Ze(e);
643
+ t(this, z).writeBox(r);
644
+ let i = t(this, z).pos - n;
645
+ t(this, z).seek(t(this, z).pos - 4), t(this, z).writeU32(i);
646
+ } else {
647
+ let n = t(this, z).offsets.get(t(this, B)), r = t(this, z).pos - n;
648
+ t(this, B).size = r, t(this, B).largeSize = r >= 2 ** 32, t(this, z).patchBox(t(this, B));
649
+ let i = le(e, t(this, U));
650
+ if (typeof t(this, R).fastStart == "object") {
651
+ t(this, z).seek(t(this, Tt)), t(this, z).writeBox(i);
652
+ let e = n - t(this, z).pos;
653
+ t(this, z).writeBox(ce(e));
654
+ } else t(this, z).writeBox(i);
655
+ }
656
+ a(this, Q, $).call(this), t(this, z).finalize(), r(this, q, !0);
657
+ }
658
+ };
659
+ R = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), Tt = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), Et = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), Dt = /* @__PURE__ */ new WeakSet(), Ot = function(e) {
660
+ if (typeof e != "object") throw TypeError("The muxer requires an options object to be passed to its constructor.");
661
+ if (!(e.target instanceof C)) throw TypeError("The target must be provided and an instance of Target.");
662
+ if (e.video) {
663
+ if (!xt.includes(e.video.codec)) throw TypeError(`Unsupported video codec: ${e.video.codec}`);
664
+ if (!Number.isInteger(e.video.width) || e.video.width <= 0) throw TypeError(`Invalid video width: ${e.video.width}. Must be a positive integer.`);
665
+ if (!Number.isInteger(e.video.height) || e.video.height <= 0) throw TypeError(`Invalid video height: ${e.video.height}. Must be a positive integer.`);
666
+ let t = e.video.rotation;
667
+ if (typeof t == "number" && ![
668
+ 0,
669
+ 90,
670
+ 180,
671
+ 270
672
+ ].includes(t)) throw TypeError(`Invalid video rotation: ${t}. Has to be 0, 90, 180 or 270.`);
673
+ if (Array.isArray(t) && (t.length !== 9 || t.some((e) => typeof e != "number"))) throw TypeError(`Invalid video transformation matrix: ${t.join()}`);
674
+ if (e.video.frameRate !== void 0 && (!Number.isInteger(e.video.frameRate) || e.video.frameRate <= 0)) throw TypeError(`Invalid video frame rate: ${e.video.frameRate}. Must be a positive integer.`);
675
+ }
676
+ if (e.audio) {
677
+ if (!St.includes(e.audio.codec)) throw TypeError(`Unsupported audio codec: ${e.audio.codec}`);
678
+ if (!Number.isInteger(e.audio.numberOfChannels) || e.audio.numberOfChannels <= 0) throw TypeError(`Invalid number of audio channels: ${e.audio.numberOfChannels}. Must be a positive integer.`);
679
+ if (!Number.isInteger(e.audio.sampleRate) || e.audio.sampleRate <= 0) throw TypeError(`Invalid audio sample rate: ${e.audio.sampleRate}. Must be a positive integer.`);
680
+ }
681
+ if (e.firstTimestampBehavior && !wt.includes(e.firstTimestampBehavior)) throw TypeError(`Invalid first timestamp behavior: ${e.firstTimestampBehavior}`);
682
+ if (typeof e.fastStart == "object") {
683
+ if (e.video) {
684
+ if (e.fastStart.expectedVideoChunks === void 0) throw TypeError("'fastStart' is an object but is missing property 'expectedVideoChunks'.");
685
+ if (!Number.isInteger(e.fastStart.expectedVideoChunks) || e.fastStart.expectedVideoChunks < 0) throw TypeError("'expectedVideoChunks' must be a non-negative integer.");
686
+ }
687
+ if (e.audio) {
688
+ if (e.fastStart.expectedAudioChunks === void 0) throw TypeError("'fastStart' is an object but is missing property 'expectedAudioChunks'.");
689
+ if (!Number.isInteger(e.fastStart.expectedAudioChunks) || e.fastStart.expectedAudioChunks < 0) throw TypeError("'expectedAudioChunks' must be a non-negative integer.");
690
+ }
691
+ } else if (![
692
+ !1,
693
+ "in-memory",
694
+ "fragmented"
695
+ ].includes(e.fastStart)) throw TypeError("'fastStart' option must be false, 'in-memory', 'fragmented' or an object.");
696
+ if (e.minFragmentDuration !== void 0 && (!Number.isFinite(e.minFragmentDuration) || e.minFragmentDuration < 0)) throw TypeError("'minFragmentDuration' must be a non-negative number.");
697
+ }, kt = /* @__PURE__ */ new WeakSet(), At = function() {
698
+ if (t(this, z).writeBox(oe({
699
+ holdsAvc: t(this, R).video?.codec === "avc",
700
+ fragmented: t(this, R).fastStart === "fragmented"
701
+ })), r(this, Tt, t(this, z).pos), t(this, R).fastStart === "in-memory") r(this, B, se(!1));
702
+ else if (t(this, R).fastStart !== "fragmented") {
703
+ if (typeof t(this, R).fastStart == "object") {
704
+ let e = a(this, jt, Mt).call(this);
705
+ t(this, z).seek(t(this, z).pos + e);
706
+ }
707
+ r(this, B, se(!0)), t(this, z).writeBox(t(this, B));
708
+ }
709
+ a(this, Q, $).call(this);
710
+ }, jt = /* @__PURE__ */ new WeakSet(), Mt = function() {
711
+ if (typeof t(this, R).fastStart != "object") return;
712
+ let e = 0, n = [t(this, R).fastStart.expectedVideoChunks, t(this, R).fastStart.expectedAudioChunks];
713
+ for (let t of n) t && (e += 8 * Math.ceil(2 / 3 * t), e += 4 * t, e += 12 * Math.ceil(2 / 3 * t), e += 4 * t, e += 8 * t);
714
+ return e += 4096, e;
715
+ }, Nt = /* @__PURE__ */ new WeakSet(), Pt = function() {
716
+ if (t(this, R).video && r(this, V, {
717
+ id: 1,
718
+ info: {
719
+ type: "video",
720
+ codec: t(this, R).video.codec,
721
+ width: t(this, R).video.width,
722
+ height: t(this, R).video.height,
723
+ rotation: t(this, R).video.rotation ?? 0,
724
+ decoderConfig: null
725
+ },
726
+ timescale: t(this, R).video.frameRate ?? 57600,
727
+ samples: [],
728
+ finalizedChunks: [],
729
+ currentChunk: null,
730
+ firstDecodeTimestamp: void 0,
731
+ lastDecodeTimestamp: -1,
732
+ timeToSampleTable: [],
733
+ compositionTimeOffsetTable: [],
734
+ lastTimescaleUnits: null,
735
+ lastSample: null,
736
+ compactlyCodedChunkTable: []
737
+ }), t(this, R).audio && (r(this, H, {
738
+ id: t(this, R).video ? 2 : 1,
739
+ info: {
740
+ type: "audio",
741
+ codec: t(this, R).audio.codec,
742
+ numberOfChannels: t(this, R).audio.numberOfChannels,
743
+ sampleRate: t(this, R).audio.sampleRate,
744
+ decoderConfig: null
745
+ },
746
+ timescale: t(this, R).audio.sampleRate,
747
+ samples: [],
748
+ finalizedChunks: [],
749
+ currentChunk: null,
750
+ firstDecodeTimestamp: void 0,
751
+ lastDecodeTimestamp: -1,
752
+ timeToSampleTable: [],
753
+ compositionTimeOffsetTable: [],
754
+ lastTimescaleUnits: null,
755
+ lastSample: null,
756
+ compactlyCodedChunkTable: []
757
+ }), t(this, R).audio.codec === "aac")) {
758
+ let e = a(this, Ft, It).call(this, 2, t(this, R).audio.sampleRate, t(this, R).audio.numberOfChannels);
759
+ t(this, H).info.decoderConfig = {
760
+ codec: t(this, R).audio.codec,
761
+ description: e,
762
+ numberOfChannels: t(this, R).audio.numberOfChannels,
763
+ sampleRate: t(this, R).audio.sampleRate
764
+ };
765
+ }
766
+ }, Ft = /* @__PURE__ */ new WeakSet(), It = function(e, t, n) {
767
+ let r = [
768
+ 96e3,
769
+ 88200,
770
+ 64e3,
771
+ 48e3,
772
+ 44100,
773
+ 32e3,
774
+ 24e3,
775
+ 22050,
776
+ 16e3,
777
+ 12e3,
778
+ 11025,
779
+ 8e3,
780
+ 7350
781
+ ].indexOf(t), i = n, a = "";
782
+ a += e.toString(2).padStart(5, "0"), a += r.toString(2).padStart(4, "0"), r === 15 && (a += t.toString(2).padStart(24, "0")), a += i.toString(2).padStart(4, "0");
783
+ let o = Math.ceil(a.length / 8) * 8;
784
+ a = a.padEnd(o, "0");
785
+ let s = new Uint8Array(a.length / 8);
786
+ for (let e = 0; e < a.length; e += 8) s[e / 8] = parseInt(a.slice(e, e + 8), 2);
787
+ return s;
788
+ }, Lt = /* @__PURE__ */ new WeakSet(), Rt = function(e, t, n, r, i, o, s) {
789
+ let c = r / 1e6, l = (r - (s ?? 0)) / 1e6, u = i / 1e6, d = a(this, zt, Bt).call(this, c, l, e);
790
+ return c = d.presentationTimestamp, l = d.decodeTimestamp, o?.decoderConfig && (e.info.decoderConfig === null ? e.info.decoderConfig = o.decoderConfig : Object.assign(e.info.decoderConfig, o.decoderConfig)), {
791
+ presentationTimestamp: c,
792
+ decodeTimestamp: l,
793
+ duration: u,
794
+ data: t,
795
+ size: t.byteLength,
796
+ type: n,
797
+ timescaleUnitsToNextSample: v(u, e.timescale)
798
+ };
799
+ }, J = /* @__PURE__ */ new WeakSet(), Y = function(e, n) {
800
+ t(this, R).fastStart !== "fragmented" && e.samples.push(n);
801
+ let r = v(n.presentationTimestamp - n.decodeTimestamp, e.timescale);
802
+ if (e.lastTimescaleUnits !== null) {
803
+ let i = v(n.decodeTimestamp, e.timescale, !1), a = Math.round(i - e.lastTimescaleUnits);
804
+ if (e.lastTimescaleUnits += a, e.lastSample.timescaleUnitsToNextSample = a, t(this, R).fastStart !== "fragmented") {
805
+ let t = _(e.timeToSampleTable);
806
+ t.sampleCount === 1 ? (t.sampleDelta = a, t.sampleCount++) : t.sampleDelta === a ? t.sampleCount++ : (t.sampleCount--, e.timeToSampleTable.push({
807
+ sampleCount: 2,
808
+ sampleDelta: a
809
+ }));
810
+ let n = _(e.compositionTimeOffsetTable);
811
+ n.sampleCompositionTimeOffset === r ? n.sampleCount++ : e.compositionTimeOffsetTable.push({
812
+ sampleCount: 1,
813
+ sampleCompositionTimeOffset: r
814
+ });
815
+ }
816
+ } else e.lastTimescaleUnits = 0, t(this, R).fastStart !== "fragmented" && (e.timeToSampleTable.push({
817
+ sampleCount: 1,
818
+ sampleDelta: v(n.duration, e.timescale)
819
+ }), e.compositionTimeOffsetTable.push({
820
+ sampleCount: 1,
821
+ sampleCompositionTimeOffset: r
822
+ }));
823
+ e.lastSample = n;
824
+ let i = !1;
825
+ if (!e.currentChunk) i = !0;
826
+ else {
827
+ let r = n.presentationTimestamp - e.currentChunk.startTimestamp;
828
+ if (t(this, R).fastStart === "fragmented") {
829
+ let o = t(this, V) ?? t(this, H), s = t(this, R).minFragmentDuration ?? 1;
830
+ e === o && n.type === "key" && r >= s && (i = !0, a(this, Z, Ht).call(this));
831
+ } else i = r >= .5;
832
+ }
833
+ i && (e.currentChunk && a(this, X, Vt).call(this, e), e.currentChunk = {
834
+ startTimestamp: n.presentationTimestamp,
835
+ samples: []
836
+ }), e.currentChunk.samples.push(n);
837
+ }, zt = /* @__PURE__ */ new WeakSet(), Bt = function(e, n, r) {
838
+ let i = t(this, R).firstTimestampBehavior === "strict", a = r.lastDecodeTimestamp === -1;
839
+ if (i && a && n !== 0) throw Error(`The first chunk for your media track must have a timestamp of 0 (received DTS=${n}).Non-zero first timestamps are often caused by directly piping frames or audio data from a MediaStreamTrack into the encoder. Their timestamps are typically relative to the age of thedocument, which is probably what you want.
840
+
841
+ If you want to offset all timestamps of a track such that the first one is zero, set firstTimestampBehavior: 'offset' in the options.
842
+ `);
843
+ if (t(this, R).firstTimestampBehavior === "offset" || t(this, R).firstTimestampBehavior === "cross-track-offset") {
844
+ r.firstDecodeTimestamp === void 0 && (r.firstDecodeTimestamp = n);
845
+ let i;
846
+ i = t(this, R).firstTimestampBehavior === "offset" ? r.firstDecodeTimestamp : Math.min(t(this, V)?.firstDecodeTimestamp ?? Infinity, t(this, H)?.firstDecodeTimestamp ?? Infinity), n -= i, e -= i;
847
+ }
848
+ if (n < r.lastDecodeTimestamp) throw Error(`Timestamps must be monotonically increasing (DTS went from ${r.lastDecodeTimestamp * 1e6} to ${n * 1e6}).`);
849
+ return r.lastDecodeTimestamp = n, {
850
+ presentationTimestamp: e,
851
+ decodeTimestamp: n
852
+ };
853
+ }, X = /* @__PURE__ */ new WeakSet(), Vt = function(e) {
854
+ if (t(this, R).fastStart === "fragmented") throw Error("Can't finalize individual chunks if 'fastStart' is set to 'fragmented'.");
855
+ if (e.currentChunk) {
856
+ if (e.finalizedChunks.push(e.currentChunk), t(this, W).push(e.currentChunk), (e.compactlyCodedChunkTable.length === 0 || _(e.compactlyCodedChunkTable).samplesPerChunk !== e.currentChunk.samples.length) && e.compactlyCodedChunkTable.push({
857
+ firstChunk: e.finalizedChunks.length,
858
+ samplesPerChunk: e.currentChunk.samples.length
859
+ }), t(this, R).fastStart === "in-memory") {
860
+ e.currentChunk.offset = 0;
861
+ return;
862
+ }
863
+ e.currentChunk.offset = t(this, z).pos;
864
+ for (let n of e.currentChunk.samples) t(this, z).write(n.data), n.data = null;
865
+ a(this, Q, $).call(this);
866
+ }
867
+ }, Z = /* @__PURE__ */ new WeakSet(), Ht = function(e = !0) {
868
+ if (t(this, R).fastStart !== "fragmented") throw Error("Can't finalize a fragment unless 'fastStart' is set to 'fragmented'.");
869
+ let n = [t(this, V), t(this, H)].filter((e) => e && e.currentChunk);
870
+ if (n.length === 0) return;
871
+ let r = i(this, Et)._++;
872
+ if (r === 1) {
873
+ let e = le(n, t(this, U), !0);
874
+ t(this, z).writeBox(e);
875
+ }
876
+ let o = t(this, z).pos, s = We(r, n);
877
+ t(this, z).writeBox(s);
878
+ {
879
+ let e = se(!1), r = 0;
880
+ for (let e of n) for (let t of e.currentChunk.samples) r += t.size;
881
+ let i = t(this, z).measureBox(e) + r;
882
+ i >= 2 ** 32 && (e.largeSize = !0, i = t(this, z).measureBox(e) + r), e.size = i, t(this, z).writeBox(e);
883
+ }
884
+ for (let e of n) {
885
+ e.currentChunk.offset = t(this, z).pos, e.currentChunk.moofOffset = o;
886
+ for (let n of e.currentChunk.samples) t(this, z).write(n.data), n.data = null;
887
+ }
888
+ let c = t(this, z).pos;
889
+ t(this, z).seek(t(this, z).offsets.get(s));
890
+ let l = We(r, n);
891
+ t(this, z).writeBox(l), t(this, z).seek(c);
892
+ for (let e of n) e.finalizedChunks.push(e.currentChunk), t(this, W).push(e.currentChunk), e.currentChunk = null;
893
+ e && a(this, Q, $).call(this);
894
+ }, Q = /* @__PURE__ */ new WeakSet(), $ = function() {
895
+ t(this, z) instanceof vt && t(this, z).flush();
896
+ }, Ut = /* @__PURE__ */ new WeakSet(), Wt = function() {
897
+ if (t(this, q)) throw Error("Cannot add new video or audio chunks after the file has been finalized.");
898
+ };
899
+ //#endregion
900
+ export { it as ArrayBufferTarget, Gt as Muxer };