@drjaat/react-video-editor
Version:
A React video editor component that can be integrated into any React application
1,432 lines • 229 kB
JavaScript
var Ce = Object.defineProperty, _e = (l) => {
throw TypeError(l);
}, Te = (l, n, h) => n in l ? Ce(l, n, { enumerable: !0, configurable: !0, writable: !0, value: h }) : l[n] = h, et = (l, n, h) => Te(l, typeof n != "symbol" ? n + "" : n, h), me = (l, n, h) => n.has(l) || _e("Cannot " + h), m = (l, n, h) => (me(l, n, "read from private field"), h ? h.call(l) : n.get(l)), A = (l, n, h) => n.has(l) ? _e("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(l) : n.set(l, h), E = (l, n, h, o) => (me(l, n, "write to private field"), n.set(l, h), h), ge = (l) => {
throw TypeError(l);
}, ye = (l, n, h) => n.has(l) || ge("Cannot " + h), z = (l, n, h) => (ye(l, n, "read from private field"), h ? h.call(l) : n.get(l)), D = (l, n, h) => n.has(l) ? ge("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(l) : n.set(l, h), R = (l, n, h, o) => (ye(l, n, "write to private field"), n.set(l, h), h);
const be = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHUobil7aWYobj09PSIvIilyZXR1cm57cGFyZW50Om51bGwsbmFtZToiIn07Y29uc3QgZT1uLnNwbGl0KCIvIikuZmlsdGVyKGk9PmkubGVuZ3RoPjApO2lmKGUubGVuZ3RoPT09MCl0aHJvdyBFcnJvcigiSW52YWxpZCBwYXRoIik7Y29uc3QgYT1lW2UubGVuZ3RoLTFdLHI9Ii8iK2Uuc2xpY2UoMCwtMSkuam9pbigiLyIpO3JldHVybntuYW1lOmEscGFyZW50OnJ9fWFzeW5jIGZ1bmN0aW9uIHcobixlKXtjb25zdHtwYXJlbnQ6YSxuYW1lOnJ9PXUobik7aWYoYT09bnVsbClyZXR1cm4gYXdhaXQgbmF2aWdhdG9yLnN0b3JhZ2UuZ2V0RGlyZWN0b3J5KCk7Y29uc3QgaT1hLnNwbGl0KCIvIikuZmlsdGVyKHQ9PnQubGVuZ3RoPjApO3RyeXtsZXQgdD1hd2FpdCBuYXZpZ2F0b3Iuc3RvcmFnZS5nZXREaXJlY3RvcnkoKTtmb3IoY29uc3QgcyBvZiBpKXQ9YXdhaXQgdC5nZXREaXJlY3RvcnlIYW5kbGUocyx7Y3JlYXRlOmUuY3JlYXRlfSk7aWYoZS5pc0ZpbGUpcmV0dXJuIGF3YWl0IHQuZ2V0RmlsZUhhbmRsZShyLHtjcmVhdGU6ZS5jcmVhdGV9KX1jYXRjaCh0KXtpZih0Lm5hbWU9PT0iTm90Rm91bmRFcnJvciIpcmV0dXJuIG51bGw7dGhyb3cgdH19Y29uc3QgZj17fTtzZWxmLm9ubWVzc2FnZT1hc3luYyBuPT57dmFyIGk7Y29uc3R7ZXZ0VHlwZTplLGFyZ3M6YX09bi5kYXRhO2xldCByPWZbYS5maWxlSWRdO3RyeXtsZXQgdDtjb25zdCBzPVtdO2lmKGU9PT0icmVnaXN0ZXIiKXtjb25zdCBsPWF3YWl0IHcoYS5maWxlUGF0aCx7Y3JlYXRlOiEwLGlzRmlsZTohMH0pO2lmKGw9PW51bGwpdGhyb3cgRXJyb3IoYG5vdCBmb3VuZCBmaWxlOiAke2EuZmlsZUlkfWApO3I9YXdhaXQgbC5jcmVhdGVTeW5jQWNjZXNzSGFuZGxlKHttb2RlOmEubW9kZX0pLGZbYS5maWxlSWRdPXJ9ZWxzZSBpZihlPT09ImNsb3NlIilhd2FpdCByLmNsb3NlKCksZGVsZXRlIGZbYS5maWxlSWRdO2Vsc2UgaWYoZT09PSJ0cnVuY2F0ZSIpYXdhaXQgci50cnVuY2F0ZShhLm5ld1NpemUpO2Vsc2UgaWYoZT09PSJ3cml0ZSIpe2NvbnN0e2RhdGE6bCxvcHRzOm99PW4uZGF0YS5hcmdzO3Q9YXdhaXQgci53cml0ZShsLG8pfWVsc2UgaWYoZT09PSJyZWFkIil7Y29uc3R7b2Zmc2V0Omwsc2l6ZTpvfT1uLmRhdGEuYXJncyxnPW5ldyBVaW50OEFycmF5KG8pLGQ9YXdhaXQgci5yZWFkKGcse2F0Omx9KSxjPWcuYnVmZmVyO3Q9ZD09PW8/YzooKGk9Yy50cmFuc2Zlcik9PW51bGw/dm9pZCAwOmkuY2FsbChjLGQpKT8/Yy5zbGljZSgwLGQpLHMucHVzaCh0KX1lbHNlIGU9PT0iZ2V0U2l6ZSI/dD1hd2FpdCByLmdldFNpemUoKTplPT09ImZsdXNoIiYmYXdhaXQgci5mbHVzaCgpO3NlbGYucG9zdE1lc3NhZ2Uoe2V2dFR5cGU6ImNhbGxiYWNrIixjYklkOm4uZGF0YS5jYklkLHJldHVyblZhbDp0fSxzKX1jYXRjaCh0KXtjb25zdCBzPXQ7c2VsZi5wb3N0TWVzc2FnZSh7ZXZ0VHlwZToidGhyb3dFcnJvciIsY2JJZDpuLmRhdGEuY2JJZCxlcnJNc2c6cy5uYW1lKyI6ICIrcy5tZXNzYWdlK2AKYCtKU09OLnN0cmluZ2lmeShuLmRhdGEpfSl9fX0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPW9wZnMtd29ya2VyLUY0UldscWNfLmpzLm1hcAo=", ke = (l) => Uint8Array.from(atob(l), (n) => n.charCodeAt(0)), ae = typeof self < "u" && self.Blob && new Blob([ke(be)], { type: "text/javascript;charset=utf-8" });
function Fe(l) {
let n;
try {
if (n = ae && (self.URL || self.webkitURL).createObjectURL(ae), !n) throw "";
const h = new Worker(n, {
name: l == null ? void 0 : l.name
});
return h.addEventListener("error", () => {
(self.URL || self.webkitURL).revokeObjectURL(n);
}), h;
} catch {
return new Worker(
"data:text/javascript;base64," + be,
{
name: l == null ? void 0 : l.name
}
);
} finally {
n && (self.URL || self.webkitURL).revokeObjectURL(n);
}
}
async function Pe(l, n, h) {
const o = Le();
return await o("register", { fileId: l, filePath: n, mode: h }), {
read: async (d, u) => await o("read", {
fileId: l,
offset: d,
size: u
}),
write: async (d, u) => await o(
"write",
{
fileId: l,
data: d,
opts: u
},
[ArrayBuffer.isView(d) ? d.buffer : d]
),
close: async () => await o("close", {
fileId: l
}),
truncate: async (d) => await o("truncate", {
fileId: l,
newSize: d
}),
getSize: async () => await o("getSize", {
fileId: l
}),
flush: async () => await o("flush", {
fileId: l
})
};
}
const Tt = [];
let Xt = 0;
function Le() {
if (Tt.length < 3) {
const n = l();
return Tt.push(n), n;
} else {
const n = Tt[Xt];
return Xt = (Xt + 1) % Tt.length, n;
}
function l() {
const n = new Fe();
let h = 0, o = {};
return n.onmessage = ({
data: d
}) => {
var u, _;
d.evtType === "callback" ? (u = o[d.cbId]) == null || u.resolve(d.returnVal) : d.evtType === "throwError" && ((_ = o[d.cbId]) == null || _.reject(Error(d.errMsg))), delete o[d.cbId];
}, async function(d, u, _ = []) {
h += 1;
const s = new Promise((b, x) => {
o[h] = { resolve: b, reject: x };
});
return n.postMessage(
{
cbId: h,
evtType: d,
args: u
},
_
), s;
};
}
}
function Zt(l) {
if (l === "/") return { parent: null, name: "" };
const n = l.split("/").filter((d) => d.length > 0);
if (n.length === 0) throw Error("Invalid path");
const h = n[n.length - 1], o = "/" + n.slice(0, -1).join("/");
return { name: h, parent: o };
}
async function tt(l, n) {
const { parent: h, name: o } = Zt(l);
if (h == null) return await navigator.storage.getDirectory();
const d = h.split("/").filter((u) => u.length > 0);
try {
let u = await navigator.storage.getDirectory();
for (const _ of d)
u = await u.getDirectoryHandle(_, {
create: n.create
});
return n.isFile ? await u.getFileHandle(o, {
create: n.create
}) : await u.getDirectoryHandle(o, {
create: n.create
});
} catch (u) {
if (u.name === "NotFoundError")
return null;
throw u;
}
}
async function ve(l) {
const { parent: n, name: h } = Zt(l);
if (n == null) {
const d = await navigator.storage.getDirectory();
for await (const u of d.keys())
await d.removeEntry(u, { recursive: !0 });
return;
}
const o = await tt(n, {
create: !1,
isFile: !1
});
o != null && await o.removeEntry(h, { recursive: !0 });
}
function Qt(l, n) {
return `${l}/${n}`.replace("//", "/");
}
function ct(l) {
return new we(l);
}
var N, kt, bt;
class we {
constructor(n) {
D(this, N), D(this, kt), D(this, bt), R(this, N, n);
const { parent: h, name: o } = Zt(n);
R(this, kt, o), R(this, bt, h);
}
get kind() {
return "dir";
}
get name() {
return z(this, kt);
}
get path() {
return z(this, N);
}
get parent() {
return z(this, bt) == null ? null : ct(z(this, bt));
}
/**
* Creates the directory.
* return A promise that resolves when the directory is created.
*/
async create() {
return await tt(z(this, N), {
create: !0,
isFile: !1
}), ct(z(this, N));
}
/**
* Checks if the directory exists.
* return A promise that resolves to true if the directory exists, otherwise false.
*/
async exists() {
return await tt(z(this, N), {
create: !1,
isFile: !1
}) instanceof FileSystemDirectoryHandle;
}
/**
* Removes the directory.
* return A promise that resolves when the directory is removed.
*/
async remove() {
for (const n of await this.children())
try {
await n.remove();
} catch (h) {
console.warn(h);
}
try {
await ve(z(this, N));
} catch (n) {
console.warn(n);
}
}
/**
* Retrieves the children of the directory.
* return A promise that resolves to an array of objects representing the children.
*/
async children() {
const n = await tt(z(this, N), {
create: !1,
isFile: !1
});
if (n == null) return [];
const h = [];
for await (const o of n.values())
h.push((o.kind === "file" ? at : ct)(Qt(z(this, N), o.name)));
return h;
}
/**
* If the dest folder exists, copy the current directory into the dest folder;
* if the dest folder does not exist, rename the current directory to dest name.
*/
async copyTo(n) {
if (!await this.exists())
throw Error(`dir ${this.path} not exists`);
const h = await n.exists() ? ct(Qt(n.path, this.name)) : n;
return await h.create(), await Promise.all((await this.children()).map((o) => o.copyTo(h))), h;
}
/**
* move directory, copy then remove current
*/
async moveTo(n) {
const h = await this.copyTo(n);
return await this.remove(), h;
}
}
N = /* @__PURE__ */ new WeakMap(), kt = /* @__PURE__ */ new WeakMap(), bt = /* @__PURE__ */ new WeakMap();
const oe = /* @__PURE__ */ new Map();
function at(l, n = "rw") {
if (n === "rw") {
const h = oe.get(l) ?? new Vt(l, n);
return oe.set(l, h), h;
}
return new Vt(l, n);
}
async function re(l, n, h = { overwrite: !0 }) {
if (n instanceof Vt) {
await re(l, await n.stream(), h);
return;
}
const o = await (l instanceof Vt ? l : at(l, "rw")).createWriter();
try {
if (h.overwrite && await o.truncate(0), n instanceof ReadableStream) {
const d = n.getReader();
for (; ; ) {
const { done: u, value: _ } = await d.read();
if (u) break;
await o.write(_);
}
} else
await o.write(n);
} catch (d) {
throw d;
} finally {
await o.close();
}
}
let Re = 0;
const De = () => ++Re;
var O, vt, Ft, wt, Pt, K, Lt, St;
const Me = class Se {
constructor(n, h) {
D(this, O), D(this, vt), D(this, Ft), D(this, wt), D(this, Pt), D(this, K, 0), D(this, Lt, /* @__PURE__ */ (() => {
let u = null;
return () => (R(this, K, z(this, K) + 1), u ?? (u = new Promise(async (_, s) => {
try {
const b = await Pe(
z(this, Pt),
z(this, O),
z(this, wt)
);
_([
b,
async () => {
R(this, K, z(this, K) - 1), !(z(this, K) > 0) && (u = null, await b.close());
}
]);
} catch (b) {
s(b);
}
})));
})()), D(this, St, !1), R(this, Pt, De()), R(this, O, n), R(this, wt, {
r: "read-only",
rw: "readwrite",
"rw-unsafe": "readwrite-unsafe"
}[h]);
const { parent: o, name: d } = Zt(n);
R(this, Ft, d), R(this, vt, o);
}
get kind() {
return "file";
}
get path() {
return z(this, O);
}
get name() {
return z(this, Ft);
}
get parent() {
return z(this, vt) == null ? null : ct(z(this, vt));
}
/**
* Random write to file
*/
async createWriter() {
if (z(this, wt) === "read-only") throw Error("file is read-only");
if (z(this, St)) throw Error("Other writer have not been closed");
R(this, St, !0);
const n = new TextEncoder(), [h, o] = await z(this, Lt).call(this);
let d = await h.getSize(), u = !1;
return {
write: async (_, s = {}) => {
if (u) throw Error("Writer is closed");
const b = typeof _ == "string" ? n.encode(_) : _, x = s.at ?? d, y = b.byteLength;
return d = x + y, await h.write(b, { at: x });
},
truncate: async (_) => {
if (u) throw Error("Writer is closed");
await h.truncate(_), d > _ && (d = _);
},
flush: async () => {
if (u) throw Error("Writer is closed");
await h.flush();
},
close: async () => {
if (u) throw Error("Writer is closed");
u = !0, R(this, St, !1), await o();
}
};
}
/**
* Random access to file
*/
async createReader() {
const [n, h] = await z(this, Lt).call(this);
let o = !1, d = 0;
return {
read: async (u, _ = {}) => {
if (o) throw Error("Reader is closed");
const s = _.at ?? d, b = await n.read(s, u);
return d = s + b.byteLength, b;
},
getSize: async () => {
if (o) throw Error("Reader is closed");
return await n.getSize();
},
close: async () => {
o || (o = !0, await h());
}
};
}
async text() {
return new TextDecoder().decode(await this.arrayBuffer());
}
async arrayBuffer() {
const n = await tt(z(this, O), { create: !1, isFile: !0 });
return n == null ? new ArrayBuffer(0) : (await n.getFile()).arrayBuffer();
}
async stream() {
const n = await this.getOriginFile();
return n == null ? new ReadableStream({
pull: (h) => {
h.close();
}
}) : n.stream();
}
async getOriginFile() {
var n;
return (n = await tt(z(this, O), { create: !1, isFile: !0 })) == null ? void 0 : n.getFile();
}
async getSize() {
const n = await tt(z(this, O), { create: !1, isFile: !0 });
return n == null ? 0 : (await n.getFile()).size;
}
async exists() {
return await tt(z(this, O), {
create: !1,
isFile: !0
}) instanceof FileSystemFileHandle;
}
async remove() {
if (z(this, K)) throw Error("exists unclosed reader/writer");
await ve(z(this, O));
}
/**
* If the target is a file, use current overwrite the target;
* if the target is a folder, copy the current file into that folder.
*/
async copyTo(n) {
if (!await this.exists())
throw Error(`file ${this.path} not exists`);
if (n instanceof Se)
return at(n.path) === this ? this : (await re(n.path, this), at(n.path));
if (n instanceof we)
return await this.copyTo(at(Qt(n.path, this.name)));
throw Error("Illegal target type");
}
/**
* move file, copy then remove current
*/
async moveTo(n) {
const h = await this.copyTo(n);
return await this.remove(), h;
}
};
O = /* @__PURE__ */ new WeakMap(), vt = /* @__PURE__ */ new WeakMap(), Ft = /* @__PURE__ */ new WeakMap(), wt = /* @__PURE__ */ new WeakMap(), Pt = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), Lt = /* @__PURE__ */ new WeakMap(), St = /* @__PURE__ */ new WeakMap();
let Vt = Me;
const ne = "/.opfs-tools-temp-dir";
async function Ue(l) {
try {
if (l.kind === "file") {
if (!await l.exists()) return !0;
const n = await l.createWriter();
await n.truncate(0), await n.close(), await l.remove();
} else
await l.remove();
return !0;
} catch (n) {
return console.warn(n), !1;
}
}
function Ne() {
setInterval(async () => {
for (const l of await ct(ne).children()) {
const n = /^\d+-(\d+)$/.exec(l.name);
(n == null || Date.now() - Number(n[1]) > 2592e5) && await Ue(l);
}
}, 60 * 1e3);
}
const Jt = [];
let he = !1;
async function Oe() {
if (globalThis.localStorage == null) return;
const l = "OPFS_TOOLS_EXPIRES_TMP_FILES";
he || (he = !0, globalThis.addEventListener("unload", () => {
Jt.length !== 0 && localStorage.setItem(
l,
`${localStorage.getItem(l) ?? ""},${Jt.join(",")}`
);
}));
let n = localStorage.getItem(l) ?? "";
for (const h of n.split(","))
h.length !== 0 && await Ue(at(`${ne}/${h}`)) && (n = n.replace(h, ""));
localStorage.setItem(l, n.replace(/,{2,}/g, ","));
}
(async function() {
var l;
globalThis.__opfs_tools_tmpfile_init__ !== !0 && (globalThis.__opfs_tools_tmpfile_init__ = !0, !(globalThis.FileSystemDirectoryHandle == null || globalThis.FileSystemFileHandle == null || ((l = globalThis.navigator) == null ? void 0 : l.storage.getDirectory) == null) && (Ne(), await Oe()));
})();
function xe() {
const l = `${Math.random().toString().slice(2)}-${Date.now()}`;
return Jt.push(l), at(`${ne}/${l}`);
}
function Ge(l) {
return l instanceof Error ? String(l) : typeof l == "object" ? JSON.stringify(l, (n, h) => h instanceof Error ? String(h) : h) : String(l);
}
function Ye() {
const l = /* @__PURE__ */ new Date();
return `${l.getHours()}:${l.getMinutes()}:${l.getSeconds()}.${l.getMilliseconds()}`;
}
let Ee = 1;
const Ae = xe();
let zt = null;
const le = ["debug", "info", "warn", "error"].reduce(
(l, n, h) => Object.assign(l, {
[n]: (...o) => {
Ee <= h && (console[n](...o), zt == null || zt.write(
`[${n}][${Ye()}] ${o.map((d) => Ge(d)).join(" ")}
`
));
}
}),
{}
), It = /* @__PURE__ */ new Map(), k = {
setLogLevel: (l) => {
Ee = It.get(l) ?? 1;
},
...le,
create: (l) => Object.fromEntries(
Object.entries(le).map(([n, h]) => [
n,
(...o) => h(l, ...o)
])
),
async dump() {
return await We, await (zt == null ? void 0 : zt.flush()), await Ae.text();
}
};
It.set(k.debug, 0);
It.set(k.info, 1);
It.set(k.warn, 2);
It.set(k.error, 3);
async function He() {
try {
zt = await Ae.createWriter(), k.info(navigator.userAgent), k.info("date: " + (/* @__PURE__ */ new Date()).toLocaleDateString());
} catch (l) {
if (!(l instanceof Error)) throw l;
if (l.message.includes("createSyncAccessHandle is not a function"))
console.warn(l);
else
throw l;
}
}
const We = globalThis.navigator == null ? null : He(), Ve = () => {
let l, n = 16.6;
self.onmessage = (h) => {
h.data.event === "start" && (self.clearInterval(l), l = self.setInterval(() => {
self.postMessage({});
}, n)), h.data.event === "stop" && self.clearInterval(l);
};
}, Ze = () => {
const l = new Blob([`(${Ve.toString()})()`]), n = URL.createObjectURL(l);
return new Worker(n);
}, ht = /* @__PURE__ */ new Map();
let qt = 1, _t = null;
globalThis.Worker != null && (_t = Ze(), _t.onmessage = () => {
qt += 1;
for (const [l, n] of ht)
if (qt % l === 0) for (const h of n) h();
});
const je = (l, n) => {
const h = Math.round(n / 16.6), o = ht.get(h) ?? /* @__PURE__ */ new Set();
return o.add(l), ht.set(h, o), ht.size === 1 && o.size === 1 && (_t == null || _t.postMessage({ event: "start" })), () => {
o.delete(l), o.size === 0 && ht.delete(h), ht.size === 0 && (qt = 0, _t == null || _t.postMessage({ event: "stop" }));
};
};
class Xe {
/**
* @param {number} scaleFrom the length of the original array.
* @param {number} scaleTo The length of the new array.
* @param {?Object} details The extra configuration, if needed.
*/
constructor(n, h, o) {
this.length_ = n, this.scaleFactor_ = (n - 1) / h, this.interpolate = this.cubic, o.method === "point" ? this.interpolate = this.point : o.method === "linear" ? this.interpolate = this.linear : o.method === "sinc" && (this.interpolate = this.sinc), this.tangentFactor_ = 1 - Math.max(0, Math.min(1, o.tension || 0)), this.sincFilterSize_ = o.sincFilterSize || 1, this.kernel_ = Qe(o.sincWindow || Ke);
}
/**
* @param {number} t The index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The interpolated value.
*/
point(n, h) {
return this.getClippedInput_(Math.round(this.scaleFactor_ * n), h);
}
/**
* @param {number} t The index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The interpolated value.
*/
linear(n, h) {
n = this.scaleFactor_ * n;
let o = Math.floor(n);
return n -= o, (1 - n) * this.getClippedInput_(o, h) + n * this.getClippedInput_(o + 1, h);
}
/**
* @param {number} t The index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The interpolated value.
*/
cubic(n, h) {
n = this.scaleFactor_ * n;
let o = Math.floor(n), d = [this.getTangent_(o, h), this.getTangent_(o + 1, h)], u = [
this.getClippedInput_(o, h),
this.getClippedInput_(o + 1, h)
];
n -= o;
let _ = n * n, s = n * _;
return (2 * s - 3 * _ + 1) * u[0] + (s - 2 * _ + n) * d[0] + (-2 * s + 3 * _) * u[1] + (s - _) * d[1];
}
/**
* @param {number} t The index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The interpolated value.
*/
sinc(n, h) {
n = this.scaleFactor_ * n;
let o = Math.floor(n), d = o - this.sincFilterSize_ + 1, u = o + this.sincFilterSize_, _ = 0;
for (let s = d; s <= u; s++)
_ += this.kernel_(n - s) * this.getClippedInput_(s, h);
return _;
}
/**
* @param {number} k The scaled index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The tangent.
* @private
*/
getTangent_(n, h) {
return this.tangentFactor_ * (this.getClippedInput_(n + 1, h) - this.getClippedInput_(n - 1, h)) / 2;
}
/**
* @param {number} t The scaled index to interpolate.
* @param {Array|TypedArray} samples the original array.
* @return {number} The interpolated value.
* @private
*/
getClippedInput_(n, h) {
return 0 <= n && n < this.length_ ? h[n] : 0;
}
}
function Ke(l) {
return Math.exp(-l / 2 * l / 2);
}
function Qe(l) {
return function(n) {
return Je(n) * l(n);
};
}
function Je(l) {
return l === 0 ? 1 : Math.sin(Math.PI * l) / (Math.PI * l);
}
class qe {
/**
* @param {number} order The order of the filter.
* @param {number} sampleRate The sample rate.
* @param {number} cutOff The cut off frequency.
*/
constructor(n, h, o) {
let d = 2 * Math.PI * o / h, u = 0;
this.filters = [];
for (let _ = 0; _ <= n; _++)
_ - n / 2 === 0 ? this.filters[_] = d : (this.filters[_] = Math.sin(d * (_ - n / 2)) / (_ - n / 2), this.filters[_] *= 0.54 - 0.46 * Math.cos(2 * Math.PI * _ / n)), u = u + this.filters[_];
for (let _ = 0; _ <= n; _++)
this.filters[_] /= u;
this.z = this.initZ_();
}
/**
* @param {number} sample A sample of a sequence.
* @return {number}
*/
filter(n) {
this.z.buf[this.z.pointer] = n;
let h = 0;
for (let o = 0, d = this.z.buf.length; o < d; o++)
h += this.filters[o] * this.z.buf[(this.z.pointer + o) % this.z.buf.length];
return this.z.pointer = (this.z.pointer + 1) % this.z.buf.length, h;
}
/**
* Reset the filter.
*/
reset() {
this.z = this.initZ_();
}
/**
* Return the default value for z.
* @private
*/
initZ_() {
let n = [];
for (let h = 0; h < this.filters.length - 1; h++)
n.push(0);
return {
buf: n,
pointer: 0
};
}
}
class $e {
/**
* @param {number} order The order of the filter.
* @param {number} sampleRate The sample rate.
* @param {number} cutOff The cut off frequency.
*/
constructor(n, h, o) {
let d = [];
for (let u = 0; u < n; u++)
d.push(this.getCoeffs_({
Fs: h,
Fc: o,
Q: 0.5 / Math.sin(Math.PI / (n * 2) * (u + 0.5))
}));
this.stages = [];
for (let u = 0; u < d.length; u++)
this.stages[u] = {
b0: d[u].b[0],
b1: d[u].b[1],
b2: d[u].b[2],
a1: d[u].a[0],
a2: d[u].a[1],
k: d[u].k,
z: [0, 0]
};
}
/**
* @param {number} sample A sample of a sequence.
* @return {number}
*/
filter(n) {
let h = n;
for (let o = 0, d = this.stages.length; o < d; o++)
h = this.runStage_(o, h);
return h;
}
getCoeffs_(n) {
let h = {};
h.z = [0, 0], h.a = [], h.b = [];
let o = this.preCalc_(n, h);
return h.k = 1, h.b.push((1 - o.cw) / (2 * o.a0)), h.b.push(2 * h.b[0]), h.b.push(h.b[0]), h;
}
preCalc_(n, h) {
let o = {}, d = 2 * Math.PI * n.Fc / n.Fs;
return o.alpha = Math.sin(d) / (2 * n.Q), o.cw = Math.cos(d), o.a0 = 1 + o.alpha, h.a0 = o.a0, h.a.push(-2 * o.cw / o.a0), h.k = 1, h.a.push((1 - o.alpha) / o.a0), o;
}
runStage_(n, h) {
let o = h * this.stages[n].k - this.stages[n].a1 * this.stages[n].z[0] - this.stages[n].a2 * this.stages[n].z[1], d = this.stages[n].b0 * o + this.stages[n].b1 * this.stages[n].z[0] + this.stages[n].b2 * this.stages[n].z[1];
return this.stages[n].z[1] = this.stages[n].z[0], this.stages[n].z[0] = o, d;
}
/**
* Reset the filter.
*/
reset() {
for (let n = 0; n < this.stages.length; n++)
this.stages[n].z = [0, 0];
}
}
const ti = {
point: !1,
linear: !1,
cubic: !0,
sinc: !0
}, de = {
IIR: 16,
FIR: 71
}, ei = {
IIR: $e,
FIR: qe
};
function ii(l, n, h, o = {}) {
let d = (h - n) / n + 1, u = new Float64Array(l.length * d);
o.method = o.method || "cubic";
let _ = new Xe(
l.length,
u.length,
{
method: o.method,
tension: o.tension || 0,
sincFilterSize: o.sincFilterSize || 6,
sincWindow: o.sincWindow || void 0
}
);
if (o.LPF === void 0 && (o.LPF = ti[o.method]), o.LPF) {
o.LPFType = o.LPFType || "IIR";
const s = ei[o.LPFType];
if (h > n) {
let b = new s(
o.LPFOrder || de[o.LPFType],
h,
n / 2
);
si(
l,
u,
_,
b
);
} else {
let b = new s(
o.LPFOrder || de[o.LPFType],
n,
h / 2
);
ri(
l,
u,
_,
b
);
}
} else
Be(l, u, _);
return u;
}
function Be(l, n, h) {
for (let o = 0, d = n.length; o < d; o++)
n[o] = h.interpolate(o, l);
}
function si(l, n, h, o) {
for (let d = 0, u = n.length; d < u; d++)
n[d] = o.filter(h.interpolate(d, l));
o.reset();
for (let d = n.length - 1; d >= 0; d--)
n[d] = o.filter(n[d]);
}
function ri(l, n, h, o) {
for (let d = 0, u = l.length; d < u; d++)
l[d] = o.filter(l[d]);
o.reset();
for (let d = l.length - 1; d >= 0; d--)
l[d] = o.filter(l[d]);
Be(l, n, h);
}
function ni(l) {
if (l.format === "f32-planar") {
const n = [];
for (let h = 0; h < l.numberOfChannels; h += 1) {
const o = l.allocationSize({ planeIndex: h }), d = new ArrayBuffer(o);
l.copyTo(d, { planeIndex: h }), n.push(new Float32Array(d));
}
return n;
} else if (l.format === "f32") {
const n = new ArrayBuffer(l.allocationSize({ planeIndex: 0 }));
return l.copyTo(n, { planeIndex: 0 }), oi(new Float32Array(n), l.numberOfChannels);
} else if (l.format === "s16") {
const n = new ArrayBuffer(l.allocationSize({ planeIndex: 0 }));
return l.copyTo(n, { planeIndex: 0 }), ai(new Int16Array(n), l.numberOfChannels);
}
throw Error("Unsupported audio data format");
}
function ai(l, n) {
const h = l.length / n, o = Array.from(
{ length: n },
() => new Float32Array(h)
);
for (let d = 0; d < h; d++)
for (let u = 0; u < n; u++) {
const _ = l[d * n + u];
o[u][d] = _ / 32768;
}
return o;
}
function oi(l, n) {
const h = l.length / n, o = Array.from(
{ length: n },
() => new Float32Array(h)
);
for (let d = 0; d < h; d++)
for (let u = 0; u < n; u++)
o[u][d] = l[d * n + u];
return o;
}
function hi(l) {
return Array(l.numberOfChannels).fill(0).map((n, h) => l.getChannelData(h));
}
async function li(l, n, h) {
const o = l.length, d = Array(h.chanCount).fill(0).map(() => new Float32Array(0));
if (o === 0) return d;
const u = Math.max(...l.map((x) => x.length));
if (u === 0) return d;
if (globalThis.OfflineAudioContext == null)
return l.map(
(x) => new Float32Array(
ii(x, n, h.rate, { method: "sinc", LPF: !1 })
)
);
const _ = new globalThis.OfflineAudioContext(
h.chanCount,
u * h.rate / n,
h.rate
), s = _.createBufferSource(), b = _.createBuffer(o, u, n);
return l.forEach((x, y) => b.copyToChannel(x, y)), s.buffer = b, s.connect(_.destination), s.start(), hi(await _.startRendering());
}
function ze(l) {
return new Promise((n) => {
const h = je(() => {
h(), n();
}, l);
});
}
function di(l, n) {
let h = !1;
async function o() {
const d = l.getReader();
for (; !h; ) {
const { value: u, done: _ } = await d.read();
if (_) {
n.onDone();
return;
}
await n.onChunk(u);
}
d.releaseLock(), await l.cancel();
}
return o().catch(k.error), () => {
h = !0;
};
}
function pi(l) {
return l && l.__esModule && Object.prototype.hasOwnProperty.call(l, "default") ? l.default : l;
}
var Ie = {};
(function(l) {
var n = /* @__PURE__ */ function() {
var t = /* @__PURE__ */ new Date(), e = 4, i = 3, r = 2, a = 1, p = e, f = {
setLogLevel: function(c) {
c == this.debug ? p = a : c == this.info ? p = r : c == this.warn ? p = i : (c == this.error, p = e);
},
debug: function(c, g) {
console.debug === void 0 && (console.debug = console.log), a >= p && console.debug("[" + n.getDurationString(/* @__PURE__ */ new Date() - t, 1e3) + "]", "[" + c + "]", g);
},
log: function(c, g) {
this.debug(c.msg);
},
info: function(c, g) {
r >= p && console.info("[" + n.getDurationString(/* @__PURE__ */ new Date() - t, 1e3) + "]", "[" + c + "]", g);
},
warn: function(c, g) {
i >= p && console.warn("[" + n.getDurationString(/* @__PURE__ */ new Date() - t, 1e3) + "]", "[" + c + "]", g);
},
error: function(c, g) {
e >= p && console.error("[" + n.getDurationString(/* @__PURE__ */ new Date() - t, 1e3) + "]", "[" + c + "]", g);
}
};
return f;
}();
n.getDurationString = function(t, e) {
var i;
function r(w, v) {
for (var U = "" + w, I = U.split("."); I[0].length < v; )
I[0] = "0" + I[0];
return I.join(".");
}
t < 0 ? (i = !0, t = -t) : i = !1;
var a = e || 1, p = t / a, f = Math.floor(p / 3600);
p -= f * 3600;
var c = Math.floor(p / 60);
p -= c * 60;
var g = p * 1e3;
return p = Math.floor(p), g -= p * 1e3, g = Math.floor(g), (i ? "-" : "") + f + ":" + r(c, 2) + ":" + r(p, 2) + "." + r(g, 3);
}, n.printRanges = function(t) {
var e = t.length;
if (e > 0) {
for (var i = "", r = 0; r < e; r++)
r > 0 && (i += ","), i += "[" + n.getDurationString(t.start(r)) + "," + n.getDurationString(t.end(r)) + "]";
return i;
} else
return "(empty)";
}, l.Log = n;
var h = function(t) {
if (t instanceof ArrayBuffer)
this.buffer = t, this.dataview = new DataView(t);
else
throw "Needs an array buffer";
this.position = 0;
};
h.prototype.getPosition = function() {
return this.position;
}, h.prototype.getEndPosition = function() {
return this.buffer.byteLength;
}, h.prototype.getLength = function() {
return this.buffer.byteLength;
}, h.prototype.seek = function(t) {
var e = Math.max(0, Math.min(this.buffer.byteLength, t));
return this.position = isNaN(e) || !isFinite(e) ? 0 : e, !0;
}, h.prototype.isEos = function() {
return this.getPosition() >= this.getEndPosition();
}, h.prototype.readAnyInt = function(t, e) {
var i = 0;
if (this.position + t <= this.buffer.byteLength) {
switch (t) {
case 1:
e ? i = this.dataview.getInt8(this.position) : i = this.dataview.getUint8(this.position);
break;
case 2:
e ? i = this.dataview.getInt16(this.position) : i = this.dataview.getUint16(this.position);
break;
case 3:
if (e)
throw "No method for reading signed 24 bits values";
i = this.dataview.getUint8(this.position) << 16, i |= this.dataview.getUint8(this.position + 1) << 8, i |= this.dataview.getUint8(this.position + 2);
break;
case 4:
e ? i = this.dataview.getInt32(this.position) : i = this.dataview.getUint32(this.position);
break;
case 8:
if (e)
throw "No method for reading signed 64 bits values";
i = this.dataview.getUint32(this.position) << 32, i |= this.dataview.getUint32(this.position + 4);
break;
default:
throw "readInt method not implemented for size: " + t;
}
return this.position += t, i;
} else
throw "Not enough bytes in buffer";
}, h.prototype.readUint8 = function() {
return this.readAnyInt(1, !1);
}, h.prototype.readUint16 = function() {
return this.readAnyInt(2, !1);
}, h.prototype.readUint24 = function() {
return this.readAnyInt(3, !1);
}, h.prototype.readUint32 = function() {
return this.readAnyInt(4, !1);
}, h.prototype.readUint64 = function() {
return this.readAnyInt(8, !1);
}, h.prototype.readString = function(t) {
if (this.position + t <= this.buffer.byteLength) {
for (var e = "", i = 0; i < t; i++)
e += String.fromCharCode(this.readUint8());
return e;
} else
throw "Not enough bytes in buffer";
}, h.prototype.readCString = function() {
for (var t = []; ; ) {
var e = this.readUint8();
if (e !== 0)
t.push(e);
else
break;
}
return String.fromCharCode.apply(null, t);
}, h.prototype.readInt8 = function() {
return this.readAnyInt(1, !0);
}, h.prototype.readInt16 = function() {
return this.readAnyInt(2, !0);
}, h.prototype.readInt32 = function() {
return this.readAnyInt(4, !0);
}, h.prototype.readInt64 = function() {
return this.readAnyInt(8, !1);
}, h.prototype.readUint8Array = function(t) {
for (var e = new Uint8Array(t), i = 0; i < t; i++)
e[i] = this.readUint8();
return e;
}, h.prototype.readInt16Array = function(t) {
for (var e = new Int16Array(t), i = 0; i < t; i++)
e[i] = this.readInt16();
return e;
}, h.prototype.readUint16Array = function(t) {
for (var e = new Int16Array(t), i = 0; i < t; i++)
e[i] = this.readUint16();
return e;
}, h.prototype.readUint32Array = function(t) {
for (var e = new Uint32Array(t), i = 0; i < t; i++)
e[i] = this.readUint32();
return e;
}, h.prototype.readInt32Array = function(t) {
for (var e = new Int32Array(t), i = 0; i < t; i++)
e[i] = this.readInt32();
return e;
}, l.MP4BoxStream = h;
var o = function(t, e, i) {
this._byteOffset = e || 0, t instanceof ArrayBuffer ? this.buffer = t : typeof t == "object" ? (this.dataView = t, e && (this._byteOffset += e)) : this.buffer = new ArrayBuffer(t || 0), this.position = 0, this.endianness = i ?? o.LITTLE_ENDIAN;
};
o.prototype = {}, o.prototype.getPosition = function() {
return this.position;
}, o.prototype._realloc = function(t) {
if (this._dynamicSize) {
var e = this._byteOffset + this.position + t, i = this._buffer.byteLength;
if (e <= i) {
e > this._byteLength && (this._byteLength = e);
return;
}
for (i < 1 && (i = 1); e > i; )
i *= 2;
var r = new ArrayBuffer(i), a = new Uint8Array(this._buffer), p = new Uint8Array(r, 0, a.length);
p.set(a), this.buffer = r, this._byteLength = e;
}
}, o.prototype._trimAlloc = function() {
if (this._byteLength != this._buffer.byteLength) {
var t = new ArrayBuffer(this._byteLength), e = new Uint8Array(t), i = new Uint8Array(this._buffer, 0, e.length);
e.set(i), this.buffer = t;
}
}, o.BIG_ENDIAN = !1, o.LITTLE_ENDIAN = !0, o.prototype._byteLength = 0, Object.defineProperty(
o.prototype,
"byteLength",
{ get: function() {
return this._byteLength - this._byteOffset;
} }
), Object.defineProperty(
o.prototype,
"buffer",
{
get: function() {
return this._trimAlloc(), this._buffer;
},
set: function(t) {
this._buffer = t, this._dataView = new DataView(this._buffer, this._byteOffset), this._byteLength = this._buffer.byteLength;
}
}
), Object.defineProperty(
o.prototype,
"byteOffset",
{
get: function() {
return this._byteOffset;
},
set: function(t) {
this._byteOffset = t, this._dataView = new DataView(this._buffer, this._byteOffset), this._byteLength = this._buffer.byteLength;
}
}
), Object.defineProperty(
o.prototype,
"dataView",
{
get: function() {
return this._dataView;
},
set: function(t) {
this._byteOffset = t.byteOffset, this._buffer = t.buffer, this._dataView = new DataView(this._buffer, this._byteOffset), this._byteLength = this._byteOffset + t.byteLength;
}
}
), o.prototype.seek = function(t) {
var e = Math.max(0, Math.min(this.byteLength, t));
this.position = isNaN(e) || !isFinite(e) ? 0 : e;
}, o.prototype.isEof = function() {
return this.position >= this._byteLength;
}, o.prototype.mapUint8Array = function(t) {
this._realloc(t * 1);
var e = new Uint8Array(this._buffer, this.byteOffset + this.position, t);
return this.position += t * 1, e;
}, o.prototype.readInt32Array = function(t, e) {
t = t ?? this.byteLength - this.position / 4;
var i = new Int32Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readInt16Array = function(t, e) {
t = t ?? this.byteLength - this.position / 2;
var i = new Int16Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readInt8Array = function(t) {
t = t ?? this.byteLength - this.position;
var e = new Int8Array(t);
return o.memcpy(
e.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * e.BYTES_PER_ELEMENT
), this.position += e.byteLength, e;
}, o.prototype.readUint32Array = function(t, e) {
t = t ?? this.byteLength - this.position / 4;
var i = new Uint32Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readUint16Array = function(t, e) {
t = t ?? this.byteLength - this.position / 2;
var i = new Uint16Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readUint8Array = function(t) {
t = t ?? this.byteLength - this.position;
var e = new Uint8Array(t);
return o.memcpy(
e.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * e.BYTES_PER_ELEMENT
), this.position += e.byteLength, e;
}, o.prototype.readFloat64Array = function(t, e) {
t = t ?? this.byteLength - this.position / 8;
var i = new Float64Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readFloat32Array = function(t, e) {
t = t ?? this.byteLength - this.position / 4;
var i = new Float32Array(t);
return o.memcpy(
i.buffer,
0,
this.buffer,
this.byteOffset + this.position,
t * i.BYTES_PER_ELEMENT
), o.arrayToNative(i, e ?? this.endianness), this.position += i.byteLength, i;
}, o.prototype.readInt32 = function(t) {
var e = this._dataView.getInt32(this.position, t ?? this.endianness);
return this.position += 4, e;
}, o.prototype.readInt16 = function(t) {
var e = this._dataView.getInt16(this.position, t ?? this.endianness);
return this.position += 2, e;
}, o.prototype.readInt8 = function() {
var t = this._dataView.getInt8(this.position);
return this.position += 1, t;
}, o.prototype.readUint32 = function(t) {
var e = this._dataView.getUint32(this.position, t ?? this.endianness);
return this.position += 4, e;
}, o.prototype.readUint16 = function(t) {
var e = this._dataView.getUint16(this.position, t ?? this.endianness);
return this.position += 2, e;
}, o.prototype.readUint8 = function() {
var t = this._dataView.getUint8(this.position);
return this.position += 1, t;
}, o.prototype.readFloat32 = function(t) {
var e = this._dataView.getFloat32(this.position, t ?? this.endianness);
return this.position += 4, e;
}, o.prototype.readFloat64 = function(t) {
var e = this._dataView.getFloat64(this.position, t ?? this.endianness);
return this.position += 8, e;
}, o.endianness = new Int8Array(new Int16Array([1]).buffer)[0] > 0, o.memcpy = function(t, e, i, r, a) {
var p = new Uint8Array(t, e, a), f = new Uint8Array(i, r, a);
p.set(f);
}, o.arrayToNative = function(t, e) {
return e == this.endianness ? t : this.flipArrayEndianness(t);
}, o.nativeToEndian = function(t, e) {
return this.endianness == e ? t : this.flipArrayEndianness(t);
}, o.flipArrayEndianness = function(t) {
for (var e = new Uint8Array(t.buffer, t.byteOffset, t.byteLength), i = 0; i < t.byteLength; i += t.BYTES_PER_ELEMENT)
for (var r = i + t.BYTES_PER_ELEMENT - 1, a = i; r > a; r--, a++) {
var p = e[a];
e[a] = e[r], e[r] = p;
}
return t;
}, o.prototype.failurePosition = 0, String.fromCharCodeUint8 = function(t) {
for (var e = [], i = 0; i < t.length; i++)
e[i] = t[i];
return String.fromCharCode.apply(null, e);
}, o.prototype.readString = function(t, e) {
return e == null || e == "ASCII" ? String.fromCharCodeUint8.apply(null, [this.mapUint8Array(t ?? this.byteLength - this.position)]) : new TextDecoder(e).decode(this.mapUint8Array(t));
}, o.prototype.readCString = function(t) {
var e = this.byteLength - this.position, i = new Uint8Array(this._buffer, this._byteOffset + this.position), r = e;
t != null && (r = Math.min(t, e));
for (var a = 0; a < r && i[a] !== 0; a++) ;
var p = String.fromCharCodeUint8.apply(null, [this.mapUint8Array(a)]);
return t != null ? this.position += r - a : a != e && (this.position += 1), p;
};
var d = Math.pow(2, 32);
o.prototype.readInt64 = function() {
return this.readInt32() * d + this.readUint32();
}, o.prototype.readUint64 = function() {
return this.readUint32() * d + this.readUint32();
}, o.prototype.readInt64 = function() {
return this.readUint32() * d + this.readUint32();
}, o.prototype.readUint24 = function() {
return (this.readUint8() << 16) + (this.readUint8() << 8) + this.readUint8();
}, l.DataStream = o, o.prototype.save = function(t) {
var e = new Blob([this.buffer]);
if (window.URL && URL.createObjectURL) {
var i = window.URL.createObjectURL(e), r = document.createElement("a");
document.body.appendChild(r), r.setAttribute("href", i), r.setAttribute("download", t), r.setAttribute("target", "_self"), r.click(), window.URL.revokeObjectURL(i);
} else
throw "DataStream.save: Can't create object URL.";
}, o.prototype._dynamicSize = !0, Object.defineProperty(
o.prototype,
"dynamicSize",
{
get: function() {
return this._dynamicSize;
},
set: function(t) {
t || this._trimAlloc(), this._dynamicSize = t;
}
}
), o.prototype.shift = function(t) {
var e = new ArrayBuffer(this._byteLength - t), i = new Uint8Array(e), r = new Uint8Array(this._buffer, t, i.length);
i.set(r), this.buffer = e, this.position -= t;
}, o.prototype.writeInt32Array = function(t, e) {
if (this._realloc(t.length * 4), t instanceof Int32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapInt32Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeInt32(t[i], e);
}, o.prototype.writeInt16Array = function(t, e) {
if (this._realloc(t.length * 2), t instanceof Int16Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapInt16Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeInt16(t[i], e);
}, o.prototype.writeInt8Array = function(t) {
if (this._realloc(t.length * 1), t instanceof Int8Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapInt8Array(t.length);
else
for (var e = 0; e < t.length; e++)
this.writeInt8(t[e]);
}, o.prototype.writeUint32Array = function(t, e) {
if (this._realloc(t.length * 4), t instanceof Uint32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapUint32Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeUint32(t[i], e);
}, o.prototype.writeUint16Array = function(t, e) {
if (this._realloc(t.length * 2), t instanceof Uint16Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapUint16Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeUint16(t[i], e);
}, o.prototype.writeUint8Array = function(t) {
if (this._realloc(t.length * 1), t instanceof Uint8Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapUint8Array(t.length);
else
for (var e = 0; e < t.length; e++)
this.writeUint8(t[e]);
}, o.prototype.writeFloat64Array = function(t, e) {
if (this._realloc(t.length * 8), t instanceof Float64Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapFloat64Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeFloat64(t[i], e);
}, o.prototype.writeFloat32Array = function(t, e) {
if (this._realloc(t.length * 4), t instanceof Float32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0)
o.memcpy(
this._buffer,
this.byteOffset + this.position,
t.buffer,
0,
t.byteLength
), this.mapFloat32Array(t.length, e);
else
for (var i = 0; i < t.length; i++)
this.writeFloat32(t[i], e);
}, o.prototype.writeInt32 = function(t, e) {
this._realloc(4), this._dataView.setInt32(this.position, t, e ?? this.endianness), this.position += 4;
}, o.prototype.writeInt16 = function(t, e) {
this._realloc(2), this._dataView.setInt16(this.position, t, e ?? this.endianness), this.position += 2;
}, o.prototype.writeInt8 = function(t) {
this._realloc(1), this._dataView.setInt8(this.position, t), this.position += 1;
}, o.prototype.writeUint32 = function(t, e) {
this._realloc(4), this._dataView.setUint32(this.position, t, e ?? this.endianness), this.position += 4;
}, o.prototype.writeUint16 = function(t, e) {
this._realloc(2), this._dataView.setUint16(this.position, t, e ?? this.endianness), this.position += 2;
}, o.prototype.writeUint8 = function(t) {
this._realloc(1), this._dataView.setUint8(this.position, t), this.position += 1;
}, o.prototype.writeFloat32 = function(t, e) {
this._realloc(4), this._dataView.setFloat32(this.position, t, e ?? this.endianness), this.position += 4;
}, o.prototype.writeFloat64 = function(t, e) {
this._realloc(8), this._dataView.setFloat64(this.position, t, e ?? this.endianness), this.position += 8;
}, o.prototype.writeUCS2String = function(t, e, i) {
i == null && (i = t.length);
for (var r = 0; r < t.length && r < i; r++)
this.writeUint16(t.charCodeAt(r), e);
for (; r < i; r++)
this.writeUint16(0);
}, o.prototype.writeString = function(t, e, i) {
var r = 0;
if (e == null || e == "ASCII")
if (i != null) {
var a = Math.min(t.length, i);
for (r = 0; r < a; r++)
this.writeUint8(t.charCodeAt(r));
for (; r < i; r++)
this.writeUint8(0);
} else
for (r = 0; r < t.length; r++)
this.writeUint8(t.charCodeAt(r));
else
this.writeUint8Array(new TextEncoder(e).encode(t.substring(0, i)));
}, o.prototype.writeCString = function(t, e) {
var i = 0;
if (e != null) {
var r = Math.min(t.length, e);
for (i = 0; i < r; i++)
this.writeUint8(t.charCodeAt(i));
for (; i < e; i++)
this.writeUint8(0);
} else {
for (i = 0; i < t.length; i++)
this.writeUint8(t.charCodeAt(i));
this.writeUint8(0);
}
}, o.prototype.writeStruct = function(t, e) {
for (var i = 0; i < t.length; i += 2) {
var r = t[i + 1];
this.writeType(r, e[t[i]], e);
}
}, o.prototype.writeType = function(t, e, i) {
var r;
if (typeof t == "function")
return t(this, e);
if (typeof t == "object" && !(t instanceof Array))
return t.set(this, e, i);
var a = null, p = "ASCII", f = this.position;
switch (typeof t == "string" && /:/.test(t) && (r = t.split(":"), t = r[0], a = parseInt(r[1])), typeof t == "string" && /,/.test(t) && (r = t.split(","), t = r[0], p = parseInt(r[1])), t) {
case "uint8":
this.writeUint8(e);
break;
case "int8":
this.writeInt8(e);
break;
case "uint16":
this.writeUint16(e, this.endianness);
break;
case "int16":
this.writ