@spinacia_/file-viewer
Version:
A file viewer component.
1,313 lines (1,312 loc) • 1.92 MB
JavaScript
import { defineComponent as hl, ref as w, computed as El, watch as Vl, onMounted as kl, onUnmounted as XU, openBlock as K, createElementBlock as g, createBlock as ol, mergeProps as il, createCommentVNode as pl, createVNode as YU, withDirectives as SU, createElementVNode as S, renderSlot as BU, vShow as hU, shallowRef as Sl, isRef as zU, toRaw as Bl, useCssVars as aU, nextTick as lU, unref as Xl, Fragment as nl, normalizeStyle as UU, renderList as yU, toDisplayString as Cl, pushScopeId as nU, popScopeId as LU } from "vue";
import { renderAsync as ZU } from "docx-preview";
import * as Rl from "pdfjs-dist";
var Hl = {}, Dl = {};
Dl.byteLength = DU;
Dl.toByteArray = uU;
Dl.fromByteArray = iU;
var Ql = [], $ = [], pU = typeof Uint8Array < "u" ? Uint8Array : Array, tl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for (var Jl = 0, kU = tl.length; Jl < kU; ++Jl)
Ql[Jl] = tl[Jl], $[tl.charCodeAt(Jl)] = Jl;
$[45] = 62;
$[95] = 63;
function RU(Q) {
var V = Q.length;
if (V % 4 > 0)
throw new Error("Invalid string. Length must be a multiple of 4");
var d = Q.indexOf("=");
d === -1 && (d = V);
var N = d === V ? 0 : 4 - d % 4;
return [d, N];
}
function DU(Q) {
var V = RU(Q), d = V[0], N = V[1];
return (d + N) * 3 / 4 - N;
}
function IU(Q, V, d) {
return (V + d) * 3 / 4 - d;
}
function uU(Q) {
var V, d = RU(Q), N = d[0], W = d[1], b = new pU(IU(Q, N, W)), M = 0, z = W > 0 ? N - 4 : N, T;
for (T = 0; T < z; T += 4)
V = $[Q.charCodeAt(T)] << 18 | $[Q.charCodeAt(T + 1)] << 12 | $[Q.charCodeAt(T + 2)] << 6 | $[Q.charCodeAt(T + 3)], b[M++] = V >> 16 & 255, b[M++] = V >> 8 & 255, b[M++] = V & 255;
return W === 2 && (V = $[Q.charCodeAt(T)] << 2 | $[Q.charCodeAt(T + 1)] >> 4, b[M++] = V & 255), W === 1 && (V = $[Q.charCodeAt(T)] << 10 | $[Q.charCodeAt(T + 1)] << 4 | $[Q.charCodeAt(T + 2)] >> 2, b[M++] = V >> 8 & 255, b[M++] = V & 255), b;
}
function sU(Q) {
return Ql[Q >> 18 & 63] + Ql[Q >> 12 & 63] + Ql[Q >> 6 & 63] + Ql[Q & 63];
}
function EU(Q, V, d) {
for (var N, W = [], b = V; b < d; b += 3)
N = (Q[b] << 16 & 16711680) + (Q[b + 1] << 8 & 65280) + (Q[b + 2] & 255), W.push(sU(N));
return W.join("");
}
function iU(Q) {
for (var V, d = Q.length, N = d % 3, W = [], b = 16383, M = 0, z = d - N; M < z; M += b)
W.push(EU(Q, M, M + b > z ? z : M + b));
return N === 1 ? (V = Q[d - 1], W.push(
Ql[V >> 2] + Ql[V << 4 & 63] + "=="
)) : N === 2 && (V = (Q[d - 2] << 8) + Q[d - 1], W.push(
Ql[V >> 10] + Ql[V >> 4 & 63] + Ql[V << 2 & 63] + "="
)), W.join("");
}
var gl = {};
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
gl.read = function(Q, V, d, N, W) {
var b, M, z = W * 8 - N - 1, T = (1 << z) - 1, B = T >> 1, c = -7, Y = d ? W - 1 : 0, m = d ? -1 : 1, X = Q[V + Y];
for (Y += m, b = X & (1 << -c) - 1, X >>= -c, c += z; c > 0; b = b * 256 + Q[V + Y], Y += m, c -= 8)
;
for (M = b & (1 << -c) - 1, b >>= -c, c += N; c > 0; M = M * 256 + Q[V + Y], Y += m, c -= 8)
;
if (b === 0)
b = 1 - B;
else {
if (b === T)
return M ? NaN : (X ? -1 : 1) * (1 / 0);
M = M + Math.pow(2, N), b = b - B;
}
return (X ? -1 : 1) * M * Math.pow(2, b - N);
};
gl.write = function(Q, V, d, N, W, b) {
var M, z, T, B = b * 8 - W - 1, c = (1 << B) - 1, Y = c >> 1, m = W === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, X = N ? 0 : b - 1, y = N ? 1 : -1, n = V < 0 || V === 0 && 1 / V < 0 ? 1 : 0;
for (V = Math.abs(V), isNaN(V) || V === 1 / 0 ? (z = isNaN(V) ? 1 : 0, M = c) : (M = Math.floor(Math.log(V) / Math.LN2), V * (T = Math.pow(2, -M)) < 1 && (M--, T *= 2), M + Y >= 1 ? V += m / T : V += m * Math.pow(2, 1 - Y), V * T >= 2 && (M++, T /= 2), M + Y >= c ? (z = 0, M = c) : M + Y >= 1 ? (z = (V * T - 1) * Math.pow(2, W), M = M + Y) : (z = V * Math.pow(2, Y - 1) * Math.pow(2, W), M = 0)); W >= 8; Q[d + X] = z & 255, X += y, z /= 256, W -= 8)
;
for (M = M << W | z, B += W; B > 0; Q[d + X] = M & 255, X += y, M /= 256, B -= 8)
;
Q[d + X - y] |= n * 128;
};
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
(function(Q) {
const V = Dl, d = gl, N = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
Q.Buffer = c, Q.SlowBuffer = f, Q.INSPECT_MAX_BYTES = 50;
const W = 2147483647;
Q.kMaxLength = W;
const { Uint8Array: b, ArrayBuffer: M, SharedArrayBuffer: z } = globalThis;
c.TYPED_ARRAY_SUPPORT = T(), !c.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error(
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
);
function T() {
try {
const Z = new b(1), l = { foo: function() {
return 42;
} };
return Object.setPrototypeOf(l, b.prototype), Object.setPrototypeOf(Z, l), Z.foo() === 42;
} catch {
return !1;
}
}
Object.defineProperty(c.prototype, "parent", {
enumerable: !0,
get: function() {
if (c.isBuffer(this))
return this.buffer;
}
}), Object.defineProperty(c.prototype, "offset", {
enumerable: !0,
get: function() {
if (c.isBuffer(this))
return this.byteOffset;
}
});
function B(Z) {
if (Z > W)
throw new RangeError('The value "' + Z + '" is invalid for option "size"');
const l = new b(Z);
return Object.setPrototypeOf(l, c.prototype), l;
}
function c(Z, l, U) {
if (typeof Z == "number") {
if (typeof l == "string")
throw new TypeError(
'The "string" argument must be of type string. Received type number'
);
return y(Z);
}
return Y(Z, l, U);
}
c.poolSize = 8192;
function Y(Z, l, U) {
if (typeof Z == "string")
return n(Z, l);
if (M.isView(Z))
return s(Z);
if (Z == null)
throw new TypeError(
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof Z
);
if (dl(Z, M) || Z && dl(Z.buffer, M) || typeof z < "u" && (dl(Z, z) || Z && dl(Z.buffer, z)))
return C(Z, l, U);
if (typeof Z == "number")
throw new TypeError(
'The "value" argument must not be of type number. Received type number'
);
const F = Z.valueOf && Z.valueOf();
if (F != null && F !== Z)
return c.from(F, l, U);
const R = H(Z);
if (R) return R;
if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof Z[Symbol.toPrimitive] == "function")
return c.from(Z[Symbol.toPrimitive]("string"), l, U);
throw new TypeError(
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof Z
);
}
c.from = function(Z, l, U) {
return Y(Z, l, U);
}, Object.setPrototypeOf(c.prototype, b.prototype), Object.setPrototypeOf(c, b);
function m(Z) {
if (typeof Z != "number")
throw new TypeError('"size" argument must be of type number');
if (Z < 0)
throw new RangeError('The value "' + Z + '" is invalid for option "size"');
}
function X(Z, l, U) {
return m(Z), Z <= 0 ? B(Z) : l !== void 0 ? typeof U == "string" ? B(Z).fill(l, U) : B(Z).fill(l) : B(Z);
}
c.alloc = function(Z, l, U) {
return X(Z, l, U);
};
function y(Z) {
return m(Z), B(Z < 0 ? 0 : I(Z) | 0);
}
c.allocUnsafe = function(Z) {
return y(Z);
}, c.allocUnsafeSlow = function(Z) {
return y(Z);
};
function n(Z, l) {
if ((typeof l != "string" || l === "") && (l = "utf8"), !c.isEncoding(l))
throw new TypeError("Unknown encoding: " + l);
const U = P(Z, l) | 0;
let F = B(U);
const R = F.write(Z, l);
return R !== U && (F = F.slice(0, R)), F;
}
function k(Z) {
const l = Z.length < 0 ? 0 : I(Z.length) | 0, U = B(l);
for (let F = 0; F < l; F += 1)
U[F] = Z[F] & 255;
return U;
}
function s(Z) {
if (dl(Z, b)) {
const l = new b(Z);
return C(l.buffer, l.byteOffset, l.byteLength);
}
return k(Z);
}
function C(Z, l, U) {
if (l < 0 || Z.byteLength < l)
throw new RangeError('"offset" is outside of buffer bounds');
if (Z.byteLength < l + (U || 0))
throw new RangeError('"length" is outside of buffer bounds');
let F;
return l === void 0 && U === void 0 ? F = new b(Z) : U === void 0 ? F = new b(Z, l) : F = new b(Z, l, U), Object.setPrototypeOf(F, c.prototype), F;
}
function H(Z) {
if (c.isBuffer(Z)) {
const l = I(Z.length) | 0, U = B(l);
return U.length === 0 || Z.copy(U, 0, 0, l), U;
}
if (Z.length !== void 0)
return typeof Z.length != "number" || sl(Z.length) ? B(0) : k(Z);
if (Z.type === "Buffer" && Array.isArray(Z.data))
return k(Z.data);
}
function I(Z) {
if (Z >= W)
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + W.toString(16) + " bytes");
return Z | 0;
}
function f(Z) {
return +Z != Z && (Z = 0), c.alloc(+Z);
}
c.isBuffer = function(l) {
return l != null && l._isBuffer === !0 && l !== c.prototype;
}, c.compare = function(l, U) {
if (dl(l, b) && (l = c.from(l, l.offset, l.byteLength)), dl(U, b) && (U = c.from(U, U.offset, U.byteLength)), !c.isBuffer(l) || !c.isBuffer(U))
throw new TypeError(
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
);
if (l === U) return 0;
let F = l.length, R = U.length;
for (let J = 0, G = Math.min(F, R); J < G; ++J)
if (l[J] !== U[J]) {
F = l[J], R = U[J];
break;
}
return F < R ? -1 : R < F ? 1 : 0;
}, c.isEncoding = function(l) {
switch (String(l).toLowerCase()) {
case "hex":
case "utf8":
case "utf-8":
case "ascii":
case "latin1":
case "binary":
case "base64":
case "ucs2":
case "ucs-2":
case "utf16le":
case "utf-16le":
return !0;
default:
return !1;
}
}, c.concat = function(l, U) {
if (!Array.isArray(l))
throw new TypeError('"list" argument must be an Array of Buffers');
if (l.length === 0)
return c.alloc(0);
let F;
if (U === void 0)
for (U = 0, F = 0; F < l.length; ++F)
U += l[F].length;
const R = c.allocUnsafe(U);
let J = 0;
for (F = 0; F < l.length; ++F) {
let G = l[F];
if (dl(G, b))
J + G.length > R.length ? (c.isBuffer(G) || (G = c.from(G)), G.copy(R, J)) : b.prototype.set.call(
R,
G,
J
);
else if (c.isBuffer(G))
G.copy(R, J);
else
throw new TypeError('"list" argument must be an Array of Buffers');
J += G.length;
}
return R;
};
function P(Z, l) {
if (c.isBuffer(Z))
return Z.length;
if (M.isView(Z) || dl(Z, M))
return Z.byteLength;
if (typeof Z != "string")
throw new TypeError(
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof Z
);
const U = Z.length, F = arguments.length > 2 && arguments[2] === !0;
if (!F && U === 0) return 0;
let R = !1;
for (; ; )
switch (l) {
case "ascii":
case "latin1":
case "binary":
return U;
case "utf8":
case "utf-8":
return ul(Z).length;
case "ucs2":
case "ucs-2":
case "utf16le":
case "utf-16le":
return U * 2;
case "hex":
return U >>> 1;
case "base64":
return $l(Z).length;
default:
if (R)
return F ? -1 : ul(Z).length;
l = ("" + l).toLowerCase(), R = !0;
}
}
c.byteLength = P;
function e(Z, l, U) {
let F = !1;
if ((l === void 0 || l < 0) && (l = 0), l > this.length || ((U === void 0 || U > this.length) && (U = this.length), U <= 0) || (U >>>= 0, l >>>= 0, U <= l))
return "";
for (Z || (Z = "utf8"); ; )
switch (Z) {
case "hex":
return zl(this, l, U);
case "utf8":
case "utf-8":
return p(this, l, U);
case "ascii":
return Ul(this, l, U);
case "latin1":
case "binary":
return ml(this, l, U);
case "base64":
return _(this, l, U);
case "ucs2":
case "ucs-2":
case "utf16le":
case "utf-16le":
return al(this, l, U);
default:
if (F) throw new TypeError("Unknown encoding: " + Z);
Z = (Z + "").toLowerCase(), F = !0;
}
}
c.prototype._isBuffer = !0;
function h(Z, l, U) {
const F = Z[l];
Z[l] = Z[U], Z[U] = F;
}
c.prototype.swap16 = function() {
const l = this.length;
if (l % 2 !== 0)
throw new RangeError("Buffer size must be a multiple of 16-bits");
for (let U = 0; U < l; U += 2)
h(this, U, U + 1);
return this;
}, c.prototype.swap32 = function() {
const l = this.length;
if (l % 4 !== 0)
throw new RangeError("Buffer size must be a multiple of 32-bits");
for (let U = 0; U < l; U += 4)
h(this, U, U + 3), h(this, U + 1, U + 2);
return this;
}, c.prototype.swap64 = function() {
const l = this.length;
if (l % 8 !== 0)
throw new RangeError("Buffer size must be a multiple of 64-bits");
for (let U = 0; U < l; U += 8)
h(this, U, U + 7), h(this, U + 1, U + 6), h(this, U + 2, U + 5), h(this, U + 3, U + 4);
return this;
}, c.prototype.toString = function() {
const l = this.length;
return l === 0 ? "" : arguments.length === 0 ? p(this, 0, l) : e.apply(this, arguments);
}, c.prototype.toLocaleString = c.prototype.toString, c.prototype.equals = function(l) {
if (!c.isBuffer(l)) throw new TypeError("Argument must be a Buffer");
return this === l ? !0 : c.compare(this, l) === 0;
}, c.prototype.inspect = function() {
let l = "";
const U = Q.INSPECT_MAX_BYTES;
return l = this.toString("hex", 0, U).replace(/(.{2})/g, "$1 ").trim(), this.length > U && (l += " ... "), "<Buffer " + l + ">";
}, N && (c.prototype[N] = c.prototype.inspect), c.prototype.compare = function(l, U, F, R, J) {
if (dl(l, b) && (l = c.from(l, l.offset, l.byteLength)), !c.isBuffer(l))
throw new TypeError(
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof l
);
if (U === void 0 && (U = 0), F === void 0 && (F = l ? l.length : 0), R === void 0 && (R = 0), J === void 0 && (J = this.length), U < 0 || F > l.length || R < 0 || J > this.length)
throw new RangeError("out of range index");
if (R >= J && U >= F)
return 0;
if (R >= J)
return -1;
if (U >= F)
return 1;
if (U >>>= 0, F >>>= 0, R >>>= 0, J >>>= 0, this === l) return 0;
let G = J - R, D = F - U;
const x = Math.min(G, D), t = this.slice(R, J), j = l.slice(U, F);
for (let E = 0; E < x; ++E)
if (t[E] !== j[E]) {
G = t[E], D = j[E];
break;
}
return G < D ? -1 : D < G ? 1 : 0;
};
function L(Z, l, U, F, R) {
if (Z.length === 0) return -1;
if (typeof U == "string" ? (F = U, U = 0) : U > 2147483647 ? U = 2147483647 : U < -2147483648 && (U = -2147483648), U = +U, sl(U) && (U = R ? 0 : Z.length - 1), U < 0 && (U = Z.length + U), U >= Z.length) {
if (R) return -1;
U = Z.length - 1;
} else if (U < 0)
if (R) U = 0;
else return -1;
if (typeof l == "string" && (l = c.from(l, F)), c.isBuffer(l))
return l.length === 0 ? -1 : a(Z, l, U, F, R);
if (typeof l == "number")
return l = l & 255, typeof b.prototype.indexOf == "function" ? R ? b.prototype.indexOf.call(Z, l, U) : b.prototype.lastIndexOf.call(Z, l, U) : a(Z, [l], U, F, R);
throw new TypeError("val must be string, number or Buffer");
}
function a(Z, l, U, F, R) {
let J = 1, G = Z.length, D = l.length;
if (F !== void 0 && (F = String(F).toLowerCase(), F === "ucs2" || F === "ucs-2" || F === "utf16le" || F === "utf-16le")) {
if (Z.length < 2 || l.length < 2)
return -1;
J = 2, G /= 2, D /= 2, U /= 2;
}
function x(j, E) {
return J === 1 ? j[E] : j.readUInt16BE(E * J);
}
let t;
if (R) {
let j = -1;
for (t = U; t < G; t++)
if (x(Z, t) === x(l, j === -1 ? 0 : t - j)) {
if (j === -1 && (j = t), t - j + 1 === D) return j * J;
} else
j !== -1 && (t -= t - j), j = -1;
} else
for (U + D > G && (U = G - D), t = U; t >= 0; t--) {
let j = !0;
for (let E = 0; E < D; E++)
if (x(Z, t + E) !== x(l, E)) {
j = !1;
break;
}
if (j) return t;
}
return -1;
}
c.prototype.includes = function(l, U, F) {
return this.indexOf(l, U, F) !== -1;
}, c.prototype.indexOf = function(l, U, F) {
return L(this, l, U, F, !0);
}, c.prototype.lastIndexOf = function(l, U, F) {
return L(this, l, U, F, !1);
};
function O(Z, l, U, F) {
U = Number(U) || 0;
const R = Z.length - U;
F ? (F = Number(F), F > R && (F = R)) : F = R;
const J = l.length;
F > J / 2 && (F = J / 2);
let G;
for (G = 0; G < F; ++G) {
const D = parseInt(l.substr(G * 2, 2), 16);
if (sl(D)) return G;
Z[U + G] = D;
}
return G;
}
function ll(Z, l, U, F) {
return yl(ul(l, Z.length - U), Z, U, F);
}
function q(Z, l, U, F) {
return yl(GU(l), Z, U, F);
}
function A(Z, l, U, F) {
return yl($l(l), Z, U, F);
}
function Wl(Z, l, U, F) {
return yl(MU(l, Z.length - U), Z, U, F);
}
c.prototype.write = function(l, U, F, R) {
if (U === void 0)
R = "utf8", F = this.length, U = 0;
else if (F === void 0 && typeof U == "string")
R = U, F = this.length, U = 0;
else if (isFinite(U))
U = U >>> 0, isFinite(F) ? (F = F >>> 0, R === void 0 && (R = "utf8")) : (R = F, F = void 0);
else
throw new Error(
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
);
const J = this.length - U;
if ((F === void 0 || F > J) && (F = J), l.length > 0 && (F < 0 || U < 0) || U > this.length)
throw new RangeError("Attempt to write outside buffer bounds");
R || (R = "utf8");
let G = !1;
for (; ; )
switch (R) {
case "hex":
return O(this, l, U, F);
case "utf8":
case "utf-8":
return ll(this, l, U, F);
case "ascii":
case "latin1":
case "binary":
return q(this, l, U, F);
case "base64":
return A(this, l, U, F);
case "ucs2":
case "ucs-2":
case "utf16le":
case "utf-16le":
return Wl(this, l, U, F);
default:
if (G) throw new TypeError("Unknown encoding: " + R);
R = ("" + R).toLowerCase(), G = !0;
}
}, c.prototype.toJSON = function() {
return {
type: "Buffer",
data: Array.prototype.slice.call(this._arr || this, 0)
};
};
function _(Z, l, U) {
return l === 0 && U === Z.length ? V.fromByteArray(Z) : V.fromByteArray(Z.slice(l, U));
}
function p(Z, l, U) {
U = Math.min(Z.length, U);
const F = [];
let R = l;
for (; R < U; ) {
const J = Z[R];
let G = null, D = J > 239 ? 4 : J > 223 ? 3 : J > 191 ? 2 : 1;
if (R + D <= U) {
let x, t, j, E;
switch (D) {
case 1:
J < 128 && (G = J);
break;
case 2:
x = Z[R + 1], (x & 192) === 128 && (E = (J & 31) << 6 | x & 63, E > 127 && (G = E));
break;
case 3:
x = Z[R + 1], t = Z[R + 2], (x & 192) === 128 && (t & 192) === 128 && (E = (J & 15) << 12 | (x & 63) << 6 | t & 63, E > 2047 && (E < 55296 || E > 57343) && (G = E));
break;
case 4:
x = Z[R + 1], t = Z[R + 2], j = Z[R + 3], (x & 192) === 128 && (t & 192) === 128 && (j & 192) === 128 && (E = (J & 15) << 18 | (x & 63) << 12 | (t & 63) << 6 | j & 63, E > 65535 && E < 1114112 && (G = E));
}
}
G === null ? (G = 65533, D = 1) : G > 65535 && (G -= 65536, F.push(G >>> 10 & 1023 | 55296), G = 56320 | G & 1023), F.push(G), R += D;
}
return i(F);
}
const u = 4096;
function i(Z) {
const l = Z.length;
if (l <= u)
return String.fromCharCode.apply(String, Z);
let U = "", F = 0;
for (; F < l; )
U += String.fromCharCode.apply(
String,
Z.slice(F, F += u)
);
return U;
}
function Ul(Z, l, U) {
let F = "";
U = Math.min(Z.length, U);
for (let R = l; R < U; ++R)
F += String.fromCharCode(Z[R] & 127);
return F;
}
function ml(Z, l, U) {
let F = "";
U = Math.min(Z.length, U);
for (let R = l; R < U; ++R)
F += String.fromCharCode(Z[R]);
return F;
}
function zl(Z, l, U) {
const F = Z.length;
(!l || l < 0) && (l = 0), (!U || U < 0 || U > F) && (U = F);
let R = "";
for (let J = l; J < U; ++J)
R += mU[Z[J]];
return R;
}
function al(Z, l, U) {
const F = Z.slice(l, U);
let R = "";
for (let J = 0; J < F.length - 1; J += 2)
R += String.fromCharCode(F[J] + F[J + 1] * 256);
return R;
}
c.prototype.slice = function(l, U) {
const F = this.length;
l = ~~l, U = U === void 0 ? F : ~~U, l < 0 ? (l += F, l < 0 && (l = 0)) : l > F && (l = F), U < 0 ? (U += F, U < 0 && (U = 0)) : U > F && (U = F), U < l && (U = l);
const R = this.subarray(l, U);
return Object.setPrototypeOf(R, c.prototype), R;
};
function o(Z, l, U) {
if (Z % 1 !== 0 || Z < 0) throw new RangeError("offset is not uint");
if (Z + l > U) throw new RangeError("Trying to access beyond buffer length");
}
c.prototype.readUintLE = c.prototype.readUIntLE = function(l, U, F) {
l = l >>> 0, U = U >>> 0, F || o(l, U, this.length);
let R = this[l], J = 1, G = 0;
for (; ++G < U && (J *= 256); )
R += this[l + G] * J;
return R;
}, c.prototype.readUintBE = c.prototype.readUIntBE = function(l, U, F) {
l = l >>> 0, U = U >>> 0, F || o(l, U, this.length);
let R = this[l + --U], J = 1;
for (; U > 0 && (J *= 256); )
R += this[l + --U] * J;
return R;
}, c.prototype.readUint8 = c.prototype.readUInt8 = function(l, U) {
return l = l >>> 0, U || o(l, 1, this.length), this[l];
}, c.prototype.readUint16LE = c.prototype.readUInt16LE = function(l, U) {
return l = l >>> 0, U || o(l, 2, this.length), this[l] | this[l + 1] << 8;
}, c.prototype.readUint16BE = c.prototype.readUInt16BE = function(l, U) {
return l = l >>> 0, U || o(l, 2, this.length), this[l] << 8 | this[l + 1];
}, c.prototype.readUint32LE = c.prototype.readUInt32LE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), (this[l] | this[l + 1] << 8 | this[l + 2] << 16) + this[l + 3] * 16777216;
}, c.prototype.readUint32BE = c.prototype.readUInt32BE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), this[l] * 16777216 + (this[l + 1] << 16 | this[l + 2] << 8 | this[l + 3]);
}, c.prototype.readBigUInt64LE = Nl(function(l) {
l = l >>> 0, bl(l, "offset");
const U = this[l], F = this[l + 7];
(U === void 0 || F === void 0) && Tl(l, this.length - 8);
const R = U + this[++l] * 2 ** 8 + this[++l] * 2 ** 16 + this[++l] * 2 ** 24, J = this[++l] + this[++l] * 2 ** 8 + this[++l] * 2 ** 16 + F * 2 ** 24;
return BigInt(R) + (BigInt(J) << BigInt(32));
}), c.prototype.readBigUInt64BE = Nl(function(l) {
l = l >>> 0, bl(l, "offset");
const U = this[l], F = this[l + 7];
(U === void 0 || F === void 0) && Tl(l, this.length - 8);
const R = U * 2 ** 24 + this[++l] * 2 ** 16 + this[++l] * 2 ** 8 + this[++l], J = this[++l] * 2 ** 24 + this[++l] * 2 ** 16 + this[++l] * 2 ** 8 + F;
return (BigInt(R) << BigInt(32)) + BigInt(J);
}), c.prototype.readIntLE = function(l, U, F) {
l = l >>> 0, U = U >>> 0, F || o(l, U, this.length);
let R = this[l], J = 1, G = 0;
for (; ++G < U && (J *= 256); )
R += this[l + G] * J;
return J *= 128, R >= J && (R -= Math.pow(2, 8 * U)), R;
}, c.prototype.readIntBE = function(l, U, F) {
l = l >>> 0, U = U >>> 0, F || o(l, U, this.length);
let R = U, J = 1, G = this[l + --R];
for (; R > 0 && (J *= 256); )
G += this[l + --R] * J;
return J *= 128, G >= J && (G -= Math.pow(2, 8 * U)), G;
}, c.prototype.readInt8 = function(l, U) {
return l = l >>> 0, U || o(l, 1, this.length), this[l] & 128 ? (255 - this[l] + 1) * -1 : this[l];
}, c.prototype.readInt16LE = function(l, U) {
l = l >>> 0, U || o(l, 2, this.length);
const F = this[l] | this[l + 1] << 8;
return F & 32768 ? F | 4294901760 : F;
}, c.prototype.readInt16BE = function(l, U) {
l = l >>> 0, U || o(l, 2, this.length);
const F = this[l + 1] | this[l] << 8;
return F & 32768 ? F | 4294901760 : F;
}, c.prototype.readInt32LE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), this[l] | this[l + 1] << 8 | this[l + 2] << 16 | this[l + 3] << 24;
}, c.prototype.readInt32BE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), this[l] << 24 | this[l + 1] << 16 | this[l + 2] << 8 | this[l + 3];
}, c.prototype.readBigInt64LE = Nl(function(l) {
l = l >>> 0, bl(l, "offset");
const U = this[l], F = this[l + 7];
(U === void 0 || F === void 0) && Tl(l, this.length - 8);
const R = this[l + 4] + this[l + 5] * 2 ** 8 + this[l + 6] * 2 ** 16 + (F << 24);
return (BigInt(R) << BigInt(32)) + BigInt(U + this[++l] * 2 ** 8 + this[++l] * 2 ** 16 + this[++l] * 2 ** 24);
}), c.prototype.readBigInt64BE = Nl(function(l) {
l = l >>> 0, bl(l, "offset");
const U = this[l], F = this[l + 7];
(U === void 0 || F === void 0) && Tl(l, this.length - 8);
const R = (U << 24) + // Overflow
this[++l] * 2 ** 16 + this[++l] * 2 ** 8 + this[++l];
return (BigInt(R) << BigInt(32)) + BigInt(this[++l] * 2 ** 24 + this[++l] * 2 ** 16 + this[++l] * 2 ** 8 + F);
}), c.prototype.readFloatLE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), d.read(this, l, !0, 23, 4);
}, c.prototype.readFloatBE = function(l, U) {
return l = l >>> 0, U || o(l, 4, this.length), d.read(this, l, !1, 23, 4);
}, c.prototype.readDoubleLE = function(l, U) {
return l = l >>> 0, U || o(l, 8, this.length), d.read(this, l, !0, 52, 8);
}, c.prototype.readDoubleBE = function(l, U) {
return l = l >>> 0, U || o(l, 8, this.length), d.read(this, l, !1, 52, 8);
};
function v(Z, l, U, F, R, J) {
if (!c.isBuffer(Z)) throw new TypeError('"buffer" argument must be a Buffer instance');
if (l > R || l < J) throw new RangeError('"value" argument is out of bounds');
if (U + F > Z.length) throw new RangeError("Index out of range");
}
c.prototype.writeUintLE = c.prototype.writeUIntLE = function(l, U, F, R) {
if (l = +l, U = U >>> 0, F = F >>> 0, !R) {
const D = Math.pow(2, 8 * F) - 1;
v(this, l, U, F, D, 0);
}
let J = 1, G = 0;
for (this[U] = l & 255; ++G < F && (J *= 256); )
this[U + G] = l / J & 255;
return U + F;
}, c.prototype.writeUintBE = c.prototype.writeUIntBE = function(l, U, F, R) {
if (l = +l, U = U >>> 0, F = F >>> 0, !R) {
const D = Math.pow(2, 8 * F) - 1;
v(this, l, U, F, D, 0);
}
let J = F - 1, G = 1;
for (this[U + J] = l & 255; --J >= 0 && (G *= 256); )
this[U + J] = l / G & 255;
return U + F;
}, c.prototype.writeUint8 = c.prototype.writeUInt8 = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 1, 255, 0), this[U] = l & 255, U + 1;
}, c.prototype.writeUint16LE = c.prototype.writeUInt16LE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 2, 65535, 0), this[U] = l & 255, this[U + 1] = l >>> 8, U + 2;
}, c.prototype.writeUint16BE = c.prototype.writeUInt16BE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 2, 65535, 0), this[U] = l >>> 8, this[U + 1] = l & 255, U + 2;
}, c.prototype.writeUint32LE = c.prototype.writeUInt32LE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 4, 4294967295, 0), this[U + 3] = l >>> 24, this[U + 2] = l >>> 16, this[U + 1] = l >>> 8, this[U] = l & 255, U + 4;
}, c.prototype.writeUint32BE = c.prototype.writeUInt32BE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 4, 4294967295, 0), this[U] = l >>> 24, this[U + 1] = l >>> 16, this[U + 2] = l >>> 8, this[U + 3] = l & 255, U + 4;
};
function Pl(Z, l, U, F, R) {
_l(l, F, R, Z, U, 7);
let J = Number(l & BigInt(4294967295));
Z[U++] = J, J = J >> 8, Z[U++] = J, J = J >> 8, Z[U++] = J, J = J >> 8, Z[U++] = J;
let G = Number(l >> BigInt(32) & BigInt(4294967295));
return Z[U++] = G, G = G >> 8, Z[U++] = G, G = G >> 8, Z[U++] = G, G = G >> 8, Z[U++] = G, U;
}
function el(Z, l, U, F, R) {
_l(l, F, R, Z, U, 7);
let J = Number(l & BigInt(4294967295));
Z[U + 7] = J, J = J >> 8, Z[U + 6] = J, J = J >> 8, Z[U + 5] = J, J = J >> 8, Z[U + 4] = J;
let G = Number(l >> BigInt(32) & BigInt(4294967295));
return Z[U + 3] = G, G = G >> 8, Z[U + 2] = G, G = G >> 8, Z[U + 1] = G, G = G >> 8, Z[U] = G, U + 8;
}
c.prototype.writeBigUInt64LE = Nl(function(l, U = 0) {
return Pl(this, l, U, BigInt(0), BigInt("0xffffffffffffffff"));
}), c.prototype.writeBigUInt64BE = Nl(function(l, U = 0) {
return el(this, l, U, BigInt(0), BigInt("0xffffffffffffffff"));
}), c.prototype.writeIntLE = function(l, U, F, R) {
if (l = +l, U = U >>> 0, !R) {
const x = Math.pow(2, 8 * F - 1);
v(this, l, U, F, x - 1, -x);
}
let J = 0, G = 1, D = 0;
for (this[U] = l & 255; ++J < F && (G *= 256); )
l < 0 && D === 0 && this[U + J - 1] !== 0 && (D = 1), this[U + J] = (l / G >> 0) - D & 255;
return U + F;
}, c.prototype.writeIntBE = function(l, U, F, R) {
if (l = +l, U = U >>> 0, !R) {
const x = Math.pow(2, 8 * F - 1);
v(this, l, U, F, x - 1, -x);
}
let J = F - 1, G = 1, D = 0;
for (this[U + J] = l & 255; --J >= 0 && (G *= 256); )
l < 0 && D === 0 && this[U + J + 1] !== 0 && (D = 1), this[U + J] = (l / G >> 0) - D & 255;
return U + F;
}, c.prototype.writeInt8 = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 1, 127, -128), l < 0 && (l = 255 + l + 1), this[U] = l & 255, U + 1;
}, c.prototype.writeInt16LE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 2, 32767, -32768), this[U] = l & 255, this[U + 1] = l >>> 8, U + 2;
}, c.prototype.writeInt16BE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 2, 32767, -32768), this[U] = l >>> 8, this[U + 1] = l & 255, U + 2;
}, c.prototype.writeInt32LE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 4, 2147483647, -2147483648), this[U] = l & 255, this[U + 1] = l >>> 8, this[U + 2] = l >>> 16, this[U + 3] = l >>> 24, U + 4;
}, c.prototype.writeInt32BE = function(l, U, F) {
return l = +l, U = U >>> 0, F || v(this, l, U, 4, 2147483647, -2147483648), l < 0 && (l = 4294967295 + l + 1), this[U] = l >>> 24, this[U + 1] = l >>> 16, this[U + 2] = l >>> 8, this[U + 3] = l & 255, U + 4;
}, c.prototype.writeBigInt64LE = Nl(function(l, U = 0) {
return Pl(this, l, U, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
}), c.prototype.writeBigInt64BE = Nl(function(l, U = 0) {
return el(this, l, U, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
});
function Al(Z, l, U, F, R, J) {
if (U + F > Z.length) throw new RangeError("Index out of range");
if (U < 0) throw new RangeError("Index out of range");
}
function rl(Z, l, U, F, R) {
return l = +l, U = U >>> 0, R || Al(Z, l, U, 4), d.write(Z, l, U, F, 23, 4), U + 4;
}
c.prototype.writeFloatLE = function(l, U, F) {
return rl(this, l, U, !0, F);
}, c.prototype.writeFloatBE = function(l, U, F) {
return rl(this, l, U, !1, F);
};
function fl(Z, l, U, F, R) {
return l = +l, U = U >>> 0, R || Al(Z, l, U, 8), d.write(Z, l, U, F, 52, 8), U + 8;
}
c.prototype.writeDoubleLE = function(l, U, F) {
return fl(this, l, U, !0, F);
}, c.prototype.writeDoubleBE = function(l, U, F) {
return fl(this, l, U, !1, F);
}, c.prototype.copy = function(l, U, F, R) {
if (!c.isBuffer(l)) throw new TypeError("argument should be a Buffer");
if (F || (F = 0), !R && R !== 0 && (R = this.length), U >= l.length && (U = l.length), U || (U = 0), R > 0 && R < F && (R = F), R === F || l.length === 0 || this.length === 0) return 0;
if (U < 0)
throw new RangeError("targetStart out of bounds");
if (F < 0 || F >= this.length) throw new RangeError("Index out of range");
if (R < 0) throw new RangeError("sourceEnd out of bounds");
R > this.length && (R = this.length), l.length - U < R - F && (R = l.length - U + F);
const J = R - F;
return this === l && typeof b.prototype.copyWithin == "function" ? this.copyWithin(U, F, R) : b.prototype.set.call(
l,
this.subarray(F, R),
U
), J;
}, c.prototype.fill = function(l, U, F, R) {
if (typeof l == "string") {
if (typeof U == "string" ? (R = U, U = 0, F = this.length) : typeof F == "string" && (R = F, F = this.length), R !== void 0 && typeof R != "string")
throw new TypeError("encoding must be a string");
if (typeof R == "string" && !c.isEncoding(R))
throw new TypeError("Unknown encoding: " + R);
if (l.length === 1) {
const G = l.charCodeAt(0);
(R === "utf8" && G < 128 || R === "latin1") && (l = G);
}
} else typeof l == "number" ? l = l & 255 : typeof l == "boolean" && (l = Number(l));
if (U < 0 || this.length < U || this.length < F)
throw new RangeError("Out of range index");
if (F <= U)
return this;
U = U >>> 0, F = F === void 0 ? this.length : F >>> 0, l || (l = 0);
let J;
if (typeof l == "number")
for (J = U; J < F; ++J)
this[J] = l;
else {
const G = c.isBuffer(l) ? l : c.from(l, R), D = G.length;
if (D === 0)
throw new TypeError('The value "' + l + '" is invalid for argument "value"');
for (J = 0; J < F - U; ++J)
this[J + U] = G[J % D];
}
return this;
};
const cl = {};
function Il(Z, l, U) {
cl[Z] = class extends U {
constructor() {
super(), Object.defineProperty(this, "message", {
value: l.apply(this, arguments),
writable: !0,
configurable: !0
}), this.name = `${this.name} [${Z}]`, this.stack, delete this.name;
}
get code() {
return Z;
}
set code(R) {
Object.defineProperty(this, "code", {
configurable: !0,
enumerable: !0,
value: R,
writable: !0
});
}
toString() {
return `${this.name} [${Z}]: ${this.message}`;
}
};
}
Il(
"ERR_BUFFER_OUT_OF_BOUNDS",
function(Z) {
return Z ? `${Z} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
},
RangeError
), Il(
"ERR_INVALID_ARG_TYPE",
function(Z, l) {
return `The "${Z}" argument must be of type number. Received type ${typeof l}`;
},
TypeError
), Il(
"ERR_OUT_OF_RANGE",
function(Z, l, U) {
let F = `The value of "${Z}" is out of range.`, R = U;
return Number.isInteger(U) && Math.abs(U) > 2 ** 32 ? R = ql(String(U)) : typeof U == "bigint" && (R = String(U), (U > BigInt(2) ** BigInt(32) || U < -(BigInt(2) ** BigInt(32))) && (R = ql(R)), R += "n"), F += ` It must be ${l}. Received ${R}`, F;
},
RangeError
);
function ql(Z) {
let l = "", U = Z.length;
const F = Z[0] === "-" ? 1 : 0;
for (; U >= F + 4; U -= 3)
l = `_${Z.slice(U - 3, U)}${l}`;
return `${Z.slice(0, U)}${l}`;
}
function cU(Z, l, U) {
bl(l, "offset"), (Z[l] === void 0 || Z[l + U] === void 0) && Tl(l, Z.length - (U + 1));
}
function _l(Z, l, U, F, R, J) {
if (Z > U || Z < l) {
const G = typeof l == "bigint" ? "n" : "";
let D;
throw l === 0 || l === BigInt(0) ? D = `>= 0${G} and < 2${G} ** ${(J + 1) * 8}${G}` : D = `>= -(2${G} ** ${(J + 1) * 8 - 1}${G}) and < 2 ** ${(J + 1) * 8 - 1}${G}`, new cl.ERR_OUT_OF_RANGE("value", D, Z);
}
cU(F, R, J);
}
function bl(Z, l) {
if (typeof Z != "number")
throw new cl.ERR_INVALID_ARG_TYPE(l, "number", Z);
}
function Tl(Z, l, U) {
throw Math.floor(Z) !== Z ? (bl(Z, U), new cl.ERR_OUT_OF_RANGE("offset", "an integer", Z)) : l < 0 ? new cl.ERR_BUFFER_OUT_OF_BOUNDS() : new cl.ERR_OUT_OF_RANGE(
"offset",
`>= 0 and <= ${l}`,
Z
);
}
const bU = /[^+/0-9A-Za-z-_]/g;
function JU(Z) {
if (Z = Z.split("=")[0], Z = Z.trim().replace(bU, ""), Z.length < 2) return "";
for (; Z.length % 4 !== 0; )
Z = Z + "=";
return Z;
}
function ul(Z, l) {
l = l || 1 / 0;
let U;
const F = Z.length;
let R = null;
const J = [];
for (let G = 0; G < F; ++G) {
if (U = Z.charCodeAt(G), U > 55295 && U < 57344) {
if (!R) {
if (U > 56319) {
(l -= 3) > -1 && J.push(239, 191, 189);
continue;
} else if (G + 1 === F) {
(l -= 3) > -1 && J.push(239, 191, 189);
continue;
}
R = U;
continue;
}
if (U < 56320) {
(l -= 3) > -1 && J.push(239, 191, 189), R = U;
continue;
}
U = (R - 55296 << 10 | U - 56320) + 65536;
} else R && (l -= 3) > -1 && J.push(239, 191, 189);
if (R = null, U < 128) {
if ((l -= 1) < 0) break;
J.push(U);
} else if (U < 2048) {
if ((l -= 2) < 0) break;
J.push(
U >> 6 | 192,
U & 63 | 128
);
} else if (U < 65536) {
if ((l -= 3) < 0) break;
J.push(
U >> 12 | 224,
U >> 6 & 63 | 128,
U & 63 | 128
);
} else if (U < 1114112) {
if ((l -= 4) < 0) break;
J.push(
U >> 18 | 240,
U >> 12 & 63 | 128,
U >> 6 & 63 | 128,
U & 63 | 128
);
} else
throw new Error("Invalid code point");
}
return J;
}
function GU(Z) {
const l = [];
for (let U = 0; U < Z.length; ++U)
l.push(Z.charCodeAt(U) & 255);
return l;
}
function MU(Z, l) {
let U, F, R;
const J = [];
for (let G = 0; G < Z.length && !((l -= 2) < 0); ++G)
U = Z.charCodeAt(G), F = U >> 8, R = U % 256, J.push(R), J.push(F);
return J;
}
function $l(Z) {
return V.toByteArray(JU(Z));
}
function yl(Z, l, U, F) {
let R;
for (R = 0; R < F && !(R + U >= l.length || R >= Z.length); ++R)
l[R + U] = Z[R];
return R;
}
function dl(Z, l) {
return Z instanceof l || Z != null && Z.constructor != null && Z.constructor.name != null && Z.constructor.name === l.name;
}
function sl(Z) {
return Z !== Z;
}
const mU = function() {
const Z = "0123456789abcdef", l = new Array(256);
for (let U = 0; U < 16; ++U) {
const F = U * 16;
for (let R = 0; R < 16; ++R)
l[F + R] = Z[U] + Z[R];
}
return l;
}();
function Nl(Z) {
return typeof BigInt > "u" ? TU : Z;
}
function TU() {
throw new Error("BigInt not supported");
}
})(Hl);
const CU = Hl.Buffer, Kl = Hl.Buffer, tU = "End-Of-Stream";
class Ml extends Error {
constructor() {
super(tU);
}
}
class wU {
constructor(V) {
this.position = 0, this.numBuffer = new Uint8Array(8), this.fileInfo = V || {};
}
/**
* Read a token from the tokenizer-stream
* @param token - The token to read
* @param position - If provided, the desired position in the tokenizer-stream
* @returns Promise with token data
*/
async readToken(V, d = this.position) {
const N = Kl.alloc(V.len);
if (await this.readBuffer(N, { position: d }) < V.len)
throw new Ml();
return V.get(N, 0);
}
/**
* Peek a token from the tokenizer-stream.
* @param token - Token to peek from the tokenizer-stream.
* @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
* @returns Promise with token data
*/
async peekToken(V, d = this.position) {
const N = Kl.alloc(V.len);
if (await this.peekBuffer(N, { position: d }) < V.len)
throw new Ml();
return V.get(N, 0);
}
/**
* Read a numeric token from the stream
* @param token - Numeric token
* @returns Promise with number
*/
async readNumber(V) {
if (await this.readBuffer(this.numBuffer, { length: V.len }) < V.len)
throw new Ml();
return V.get(this.numBuffer, 0);
}
/**
* Read a numeric token from the stream
* @param token - Numeric token
* @returns Promise with number
*/
async peekNumber(V) {
if (await this.peekBuffer(this.numBuffer, { length: V.len }) < V.len)
throw new Ml();
return V.get(this.numBuffer, 0);
}
/**
* Ignore number of bytes, advances the pointer in under tokenizer-stream.
* @param length - Number of bytes to ignore
* @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
*/
async ignore(V) {
if (this.fileInfo.size !== void 0) {
const d = this.fileInfo.size - this.position;
if (V > d)
return this.position += d, d;
}
return this.position += V, V;
}
async close() {
}
normalizeOptions(V, d) {
if (d && d.position !== void 0 && d.position < this.position)
throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
return d ? {
mayBeLess: d.mayBeLess === !0,
offset: d.offset ? d.offset : 0,
length: d.length ? d.length : V.length - (d.offset ? d.offset : 0),
position: d.position ? d.position : this.position
} : {
mayBeLess: !1,
offset: 0,
length: V.length,
position: this.position
};
}
}
class xU extends wU {
/**
* Construct BufferTokenizer
* @param uint8Array - Uint8Array to tokenize
* @param fileInfo - Pass additional file information to the tokenizer
*/
constructor(V, d) {
super(d), this.uint8Array = V, this.fileInfo.size = this.fileInfo.size ? this.fileInfo.size : V.length;
}
/**
* Read buffer from tokenizer
* @param uint8Array - Uint8Array to tokenize
* @param options - Read behaviour options
* @returns {Promise<number>}
*/
async readBuffer(V, d) {
if (d && d.position) {
if (d.position < this.position)
throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
this.position = d.position;
}
const N = await this.peekBuffer(V, d);
return this.position += N, N;
}
/**
* Peek (read ahead) buffer from tokenizer
* @param uint8Array
* @param options - Read behaviour options
* @returns {Promise<number>}
*/
async peekBuffer(V, d) {
const N = this.normalizeOptions(V, d), W = Math.min(this.uint8Array.length - N.position, N.length);
if (!N.mayBeLess && W < N.length)
throw new Ml();
return V.set(this.uint8Array.subarray(N.position, N.position + W), N.offset), W;
}
async close() {
}
}
function jU(Q, V) {
return new xU(Q, V);
}
class FU {
constructor(V, d) {
this.len = V, this.encoding = d;
}
get(V, d) {
return Kl.from(V).toString(this.encoding, d, d + this.len);
}
}
const OU = 4100, oU = [137, 80, 78, 71, 13, 10, 26, 10], KU = [255, 216, 255], HU = [66, 77], gU = [71, 73, 70], vU = [77, 90], PU = [80, 75, 3, 4], eU = [39, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], AU = [0, 0, 1, 0], vl = (Q) => [...Q].map((V) => V.charCodeAt(0)), rU = vl("WEBP"), fU = vl("%PDF"), qU = vl("SCRM"), _U = (Q, V = 0, d = 2) => new Promise((N, W) => {
const b = new FileReader();
b.onload = () => {
N(b.result);
}, b.onerror = W, b.readAsArrayBuffer(Q.slice(V, d));
}), $U = (Q) => new Promise((V, d) => {
const N = new FileReader();
N.onload = () => {
V(N.result);
}, N.onerror = d, N.readAsArrayBuffer(Q);
}), Zl = async (Q, V, d = 0) => {
const N = await _U(Q, d, V.length + d), W = new Uint8Array(N);
return V.every((b, M) => b === W[M]);
}, dU = async (Q) => {
if (await Zl(Q, oU))
return { ext: "png", mime: "image/png" };
if (await Zl(Q, KU))
return { ext: "jpg", mime: "image/jpeg" };
if (await Zl(Q, rU, 8))
return { ext: "webp", mime: "image/webp" };
if (await Zl(Q, HU))
return { ext: "bmp", mime: "image/bmp" };
if (await Zl(Q, gU))
return { ext: "gif", mime: "image/gif" };
if (await Zl(Q, fU))
return { ext: "pdf", mime: "application/pdf" };
if (await Zl(Q, AU))
return { ext: "ico", mime: "image/x-icon" };
if (await Zl(Q, PU)) {
const V = CU.alloc(OU), d = new Uint8Array(await $U(Q)), N = jU(d);
N.fileInfo.size === void 0 && (N.fileInfo.size = Number.MAX_SAFE_INTEGER), await N.peekBuffer(V, { length: 12, mayBeLess: !0 });
try {
for (; N.position + 30 < N.fileInfo.size; ) {
await N.readBuffer(V, { length: 30 });
const W = {
compressedSize: V.readUInt32LE(18),
uncompressedSize: V.readUInt32LE(22),
filenameLength: V.readUInt16LE(26),
extraFieldLength: V.readUInt16LE(28),
filename: ""
};
if (W.filename = await N.readToken(new FU(W.filenameLength, "utf-8")), await N.ignore(W.extraFieldLength), W.filename === "META-INF/mozilla.rsa")
return { ext: "xpi", mime: "application/x-xpinstall" };
if (W.filename.endsWith(".rels") || W.filename.endsWith(".xml"))
switch (W.filename.split("/")[0]) {
case "_rels":
break;
case "word":
return {
ext: "docx",
mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
};
case "ppt":
return {
ext: "pptx",
mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
};
case "xl":
return {
ext: "xlsx",
mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
};
default:
break;
}
if (W.filename.startsWith("xl/"))
return {
ext: "xlsx",
mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
};
if (W.filename.startsWith("3D/") && W.filename.endsWith(".model"))
return {
ext: "3mf",
mime: "model/3mf"
};
if (W.filename === "mimetype" && W.compressedSize === W.uncompressedSize) {
let b = await N.readToken(new FU(W.compressedSize, "utf-8"));
switch (b = b.trim(), b) {
case "application/epub+zip":
return {
ext: "epub",
mime: "application/epub+zip"
};
case "application/vnd.oasis.opendocument.text":
return {
ext: "odt",
mime: "application/vnd.oasis.opendocument.text"
};
case "application/vnd.oasis.opendocument.spreadsheet":
return {
ext: "ods",
mime: "application/vnd.oasis.opendocument.spreadsheet"
};
case "application/vnd.oasis.opendocument.presentation":
return {
ext: "odp",
mime: "application/vnd.oasis.opendocument.presentation"
};
default:
break;
}
}
if (W.compressedSize === 0) {
let b = -1;
for (; b < 0 && N.position < N.fileInfo.size; )
await N.peekBuffer(V, { mayBeLess: !0 }), b = V.indexOf("504B0304", 0, "hex"), await N.ignore(b >= 0 ? b : V.length);
} else
await N.ignore(W.compressedSize);
}
} catch (W) {
if (!(W instanceof Ml))
throw W;
}
return { ext: "zip", mime: "application/zip" };
}
if (await Zl(Q, vU))
return { ext: "exe", mime: "application/x-msdownload" };
if (await Zl(Q, qU))
return { ext: "s3m", mime: "audio/x-s3m" };
if (await Zl(Q, eU, 2))
return { ext: "shp", mime: "application/x-esri-shape" };
switch (Q.type) {
case "text/plain":
return { ext: "txt", mime: "text/plain" };
case "image/svg+xml":
return { ext: "svg", mime: "image/svg+xml" };
}
return { ext: "unknown", mime: "unknown" };
}, wl = ["png", "jpg", "webp", "bmp", "gif", "svg", "ico"], xl = ["pdf"], jl = ["docx"], uF = ["xlsx", "csv"], Ol = ["txt"], sF = ["zip"];
var lZ = Object.defineProperty, UZ = (Q, V, d) => V in Q ? lZ(Q, V, { enumerable: !0, configurable: !0, writable: !0, value: d }) : Q[V] = d, ZZ = (Q, V, d) => (UZ(Q, V + "", d), d);
const Ll = "internal-link", FZ = "link", dZ = "file-attachment", QZ = "form-text", VZ = "form-select", WZ = "form-checkbox", RZ = "form-radio", NZ = "form-button", QU = ["click", "dblclick", "mouseover", "input", "change"];
function Yl(Q, V, d) {
const N = [];
if (d)
for (const W of d)
W[Q] === V && N.push(W);
return N;
}
function Fl(Q, V) {
return { type: Q, data: V };
}
function Gl(Q, V) {
switch (Q.type) {
case "textarea":
case "text":
return Fl(QZ, {
fieldName: Q.name,
value: Q.value
});
case "select-one":
case "select-multiple":
const d = [];
for (const W of Q.options)
d.push({
value: W.value,