@tinyuploader/react
Version:
1,279 lines • 70.9 kB
JavaScript
import _e, { useState as ue, createContext as je, useContext as Pe, useRef as Fe, useEffect as I, forwardRef as Ue, useImperativeHandle as ze } from "react";
function Te(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
var V = { exports: {} }, q = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ye;
function Ne() {
if (ye) return q;
ye = 1;
var n = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
function i(o, u, d) {
var g = null;
if (d !== void 0 && (g = "" + d), u.key !== void 0 && (g = "" + u.key), "key" in u) {
d = {};
for (var y in u)
y !== "key" && (d[y] = u[y]);
} else d = u;
return u = d.ref, {
$$typeof: n,
type: o,
key: g,
ref: u !== void 0 ? u : null,
props: d
};
}
return q.Fragment = e, q.jsx = i, q.jsxs = i, q;
}
var $ = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ve;
function Le() {
return ve || (ve = 1, process.env.NODE_ENV !== "production" && function() {
function n(c) {
if (c == null) return null;
if (typeof c == "function")
return c.$$typeof === Y ? null : c.displayName || c.name || null;
if (typeof c == "string") return c;
switch (c) {
case _:
return "Fragment";
case l:
return "Profiler";
case F:
return "StrictMode";
case a:
return "Suspense";
case r:
return "SuspenseList";
case T:
return "Activity";
}
if (typeof c == "object")
switch (typeof c.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), c.$$typeof) {
case z:
return "Portal";
case s:
return (c.displayName || "Context") + ".Provider";
case h:
return (c._context.displayName || "Context") + ".Consumer";
case t:
var b = c.render;
return c = c.displayName, c || (c = b.displayName || b.name || "", c = c !== "" ? "ForwardRef(" + c + ")" : "ForwardRef"), c;
case w:
return b = c.displayName || null, b !== null ? b : n(c.type) || "Memo";
case x:
b = c._payload, c = c._init;
try {
return n(c(b));
} catch {
}
}
return null;
}
function e(c) {
return "" + c;
}
function i(c) {
try {
e(c);
var b = !1;
} catch {
b = !0;
}
if (b) {
b = console;
var k = b.error, j = typeof Symbol == "function" && Symbol.toStringTag && c[Symbol.toStringTag] || c.constructor.name || "Object";
return k.call(
b,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
j
), e(c);
}
}
function o(c) {
if (c === _) return "<>";
if (typeof c == "object" && c !== null && c.$$typeof === x)
return "<...>";
try {
var b = n(c);
return b ? "<" + b + ">" : "<...>";
} catch {
return "<...>";
}
}
function u() {
var c = Z.A;
return c === null ? null : c.getOwner();
}
function d() {
return Error("react-stack-top-frame");
}
function g(c) {
if (ce.call(c, "key")) {
var b = Object.getOwnPropertyDescriptor(c, "key").get;
if (b && b.isReactWarning) return !1;
}
return c.key !== void 0;
}
function y(c, b) {
function k() {
de || (de = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
b
));
}
k.isReactWarning = !0, Object.defineProperty(c, "key", {
get: k,
configurable: !0
});
}
function S() {
var c = n(this.type);
return pe[c] || (pe[c] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), c = this.props.ref, c !== void 0 ? c : null;
}
function C(c, b, k, j, B, M, K, ee) {
return k = M.ref, c = {
$$typeof: U,
type: c,
key: b,
props: M,
_owner: B
}, (k !== void 0 ? k : null) !== null ? Object.defineProperty(c, "ref", {
enumerable: !1,
get: S
}) : Object.defineProperty(c, "ref", { enumerable: !1, value: null }), c._store = {}, Object.defineProperty(c._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(c, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(c, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: K
}), Object.defineProperty(c, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: ee
}), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c;
}
function v(c, b, k, j, B, M, K, ee) {
var P = b.children;
if (P !== void 0)
if (j)
if (Ae(P)) {
for (j = 0; j < P.length; j++)
E(P[j]);
Object.freeze && Object.freeze(P);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else E(P);
if (ce.call(b, "key")) {
P = n(c);
var O = Object.keys(b).filter(function(ke) {
return ke !== "key";
});
j = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", ge[P + j] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
j,
P,
O,
P
), ge[P + j] = !0);
}
if (P = null, k !== void 0 && (i(k), P = "" + k), g(b) && (i(b.key), P = "" + b.key), "key" in b) {
k = {};
for (var te in b)
te !== "key" && (k[te] = b[te]);
} else k = b;
return P && y(
k,
typeof c == "function" ? c.displayName || c.name || "Unknown" : c
), C(
c,
P,
M,
B,
u(),
k,
K,
ee
);
}
function E(c) {
typeof c == "object" && c !== null && c.$$typeof === U && c._store && (c._store.validated = 1);
}
var A = _e, U = Symbol.for("react.transitional.element"), z = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), F = Symbol.for("react.strict_mode"), l = Symbol.for("react.profiler"), h = Symbol.for("react.consumer"), s = Symbol.for("react.context"), t = Symbol.for("react.forward_ref"), a = Symbol.for("react.suspense"), r = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), x = Symbol.for("react.lazy"), T = Symbol.for("react.activity"), Y = Symbol.for("react.client.reference"), Z = A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, ce = Object.prototype.hasOwnProperty, Ae = Array.isArray, Q = console.createTask ? console.createTask : function() {
return null;
};
A = {
"react-stack-bottom-frame": function(c) {
return c();
}
};
var de, pe = {}, fe = A["react-stack-bottom-frame"].bind(
A,
d
)(), me = Q(o(d)), ge = {};
$.Fragment = _, $.jsx = function(c, b, k, j, B) {
var M = 1e4 > Z.recentlyCreatedOwnerStacks++;
return v(
c,
b,
k,
!1,
j,
B,
M ? Error("react-stack-top-frame") : fe,
M ? Q(o(c)) : me
);
}, $.jsxs = function(c, b, k, j, B) {
var M = 1e4 > Z.recentlyCreatedOwnerStacks++;
return v(
c,
b,
k,
!0,
j,
B,
M ? Error("react-stack-top-frame") : fe,
M ? Q(o(c)) : me
);
};
}()), $;
}
var be;
function Me() {
return be || (be = 1, process.env.NODE_ENV === "production" ? V.exports = Ne() : V.exports = Le()), V.exports;
}
var p = Me(), se = { exports: {} }, we;
function Be() {
return we || (we = 1, function(n, e) {
(function(i) {
n.exports = i();
})(function(i) {
var o = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
function u(l, h) {
var s = l[0], t = l[1], a = l[2], r = l[3];
s += (t & a | ~t & r) + h[0] - 680876936 | 0, s = (s << 7 | s >>> 25) + t | 0, r += (s & t | ~s & a) + h[1] - 389564586 | 0, r = (r << 12 | r >>> 20) + s | 0, a += (r & s | ~r & t) + h[2] + 606105819 | 0, a = (a << 17 | a >>> 15) + r | 0, t += (a & r | ~a & s) + h[3] - 1044525330 | 0, t = (t << 22 | t >>> 10) + a | 0, s += (t & a | ~t & r) + h[4] - 176418897 | 0, s = (s << 7 | s >>> 25) + t | 0, r += (s & t | ~s & a) + h[5] + 1200080426 | 0, r = (r << 12 | r >>> 20) + s | 0, a += (r & s | ~r & t) + h[6] - 1473231341 | 0, a = (a << 17 | a >>> 15) + r | 0, t += (a & r | ~a & s) + h[7] - 45705983 | 0, t = (t << 22 | t >>> 10) + a | 0, s += (t & a | ~t & r) + h[8] + 1770035416 | 0, s = (s << 7 | s >>> 25) + t | 0, r += (s & t | ~s & a) + h[9] - 1958414417 | 0, r = (r << 12 | r >>> 20) + s | 0, a += (r & s | ~r & t) + h[10] - 42063 | 0, a = (a << 17 | a >>> 15) + r | 0, t += (a & r | ~a & s) + h[11] - 1990404162 | 0, t = (t << 22 | t >>> 10) + a | 0, s += (t & a | ~t & r) + h[12] + 1804603682 | 0, s = (s << 7 | s >>> 25) + t | 0, r += (s & t | ~s & a) + h[13] - 40341101 | 0, r = (r << 12 | r >>> 20) + s | 0, a += (r & s | ~r & t) + h[14] - 1502002290 | 0, a = (a << 17 | a >>> 15) + r | 0, t += (a & r | ~a & s) + h[15] + 1236535329 | 0, t = (t << 22 | t >>> 10) + a | 0, s += (t & r | a & ~r) + h[1] - 165796510 | 0, s = (s << 5 | s >>> 27) + t | 0, r += (s & a | t & ~a) + h[6] - 1069501632 | 0, r = (r << 9 | r >>> 23) + s | 0, a += (r & t | s & ~t) + h[11] + 643717713 | 0, a = (a << 14 | a >>> 18) + r | 0, t += (a & s | r & ~s) + h[0] - 373897302 | 0, t = (t << 20 | t >>> 12) + a | 0, s += (t & r | a & ~r) + h[5] - 701558691 | 0, s = (s << 5 | s >>> 27) + t | 0, r += (s & a | t & ~a) + h[10] + 38016083 | 0, r = (r << 9 | r >>> 23) + s | 0, a += (r & t | s & ~t) + h[15] - 660478335 | 0, a = (a << 14 | a >>> 18) + r | 0, t += (a & s | r & ~s) + h[4] - 405537848 | 0, t = (t << 20 | t >>> 12) + a | 0, s += (t & r | a & ~r) + h[9] + 568446438 | 0, s = (s << 5 | s >>> 27) + t | 0, r += (s & a | t & ~a) + h[14] - 1019803690 | 0, r = (r << 9 | r >>> 23) + s | 0, a += (r & t | s & ~t) + h[3] - 187363961 | 0, a = (a << 14 | a >>> 18) + r | 0, t += (a & s | r & ~s) + h[8] + 1163531501 | 0, t = (t << 20 | t >>> 12) + a | 0, s += (t & r | a & ~r) + h[13] - 1444681467 | 0, s = (s << 5 | s >>> 27) + t | 0, r += (s & a | t & ~a) + h[2] - 51403784 | 0, r = (r << 9 | r >>> 23) + s | 0, a += (r & t | s & ~t) + h[7] + 1735328473 | 0, a = (a << 14 | a >>> 18) + r | 0, t += (a & s | r & ~s) + h[12] - 1926607734 | 0, t = (t << 20 | t >>> 12) + a | 0, s += (t ^ a ^ r) + h[5] - 378558 | 0, s = (s << 4 | s >>> 28) + t | 0, r += (s ^ t ^ a) + h[8] - 2022574463 | 0, r = (r << 11 | r >>> 21) + s | 0, a += (r ^ s ^ t) + h[11] + 1839030562 | 0, a = (a << 16 | a >>> 16) + r | 0, t += (a ^ r ^ s) + h[14] - 35309556 | 0, t = (t << 23 | t >>> 9) + a | 0, s += (t ^ a ^ r) + h[1] - 1530992060 | 0, s = (s << 4 | s >>> 28) + t | 0, r += (s ^ t ^ a) + h[4] + 1272893353 | 0, r = (r << 11 | r >>> 21) + s | 0, a += (r ^ s ^ t) + h[7] - 155497632 | 0, a = (a << 16 | a >>> 16) + r | 0, t += (a ^ r ^ s) + h[10] - 1094730640 | 0, t = (t << 23 | t >>> 9) + a | 0, s += (t ^ a ^ r) + h[13] + 681279174 | 0, s = (s << 4 | s >>> 28) + t | 0, r += (s ^ t ^ a) + h[0] - 358537222 | 0, r = (r << 11 | r >>> 21) + s | 0, a += (r ^ s ^ t) + h[3] - 722521979 | 0, a = (a << 16 | a >>> 16) + r | 0, t += (a ^ r ^ s) + h[6] + 76029189 | 0, t = (t << 23 | t >>> 9) + a | 0, s += (t ^ a ^ r) + h[9] - 640364487 | 0, s = (s << 4 | s >>> 28) + t | 0, r += (s ^ t ^ a) + h[12] - 421815835 | 0, r = (r << 11 | r >>> 21) + s | 0, a += (r ^ s ^ t) + h[15] + 530742520 | 0, a = (a << 16 | a >>> 16) + r | 0, t += (a ^ r ^ s) + h[2] - 995338651 | 0, t = (t << 23 | t >>> 9) + a | 0, s += (a ^ (t | ~r)) + h[0] - 198630844 | 0, s = (s << 6 | s >>> 26) + t | 0, r += (t ^ (s | ~a)) + h[7] + 1126891415 | 0, r = (r << 10 | r >>> 22) + s | 0, a += (s ^ (r | ~t)) + h[14] - 1416354905 | 0, a = (a << 15 | a >>> 17) + r | 0, t += (r ^ (a | ~s)) + h[5] - 57434055 | 0, t = (t << 21 | t >>> 11) + a | 0, s += (a ^ (t | ~r)) + h[12] + 1700485571 | 0, s = (s << 6 | s >>> 26) + t | 0, r += (t ^ (s | ~a)) + h[3] - 1894986606 | 0, r = (r << 10 | r >>> 22) + s | 0, a += (s ^ (r | ~t)) + h[10] - 1051523 | 0, a = (a << 15 | a >>> 17) + r | 0, t += (r ^ (a | ~s)) + h[1] - 2054922799 | 0, t = (t << 21 | t >>> 11) + a | 0, s += (a ^ (t | ~r)) + h[8] + 1873313359 | 0, s = (s << 6 | s >>> 26) + t | 0, r += (t ^ (s | ~a)) + h[15] - 30611744 | 0, r = (r << 10 | r >>> 22) + s | 0, a += (s ^ (r | ~t)) + h[6] - 1560198380 | 0, a = (a << 15 | a >>> 17) + r | 0, t += (r ^ (a | ~s)) + h[13] + 1309151649 | 0, t = (t << 21 | t >>> 11) + a | 0, s += (a ^ (t | ~r)) + h[4] - 145523070 | 0, s = (s << 6 | s >>> 26) + t | 0, r += (t ^ (s | ~a)) + h[11] - 1120210379 | 0, r = (r << 10 | r >>> 22) + s | 0, a += (s ^ (r | ~t)) + h[2] + 718787259 | 0, a = (a << 15 | a >>> 17) + r | 0, t += (r ^ (a | ~s)) + h[9] - 343485551 | 0, t = (t << 21 | t >>> 11) + a | 0, l[0] = s + l[0] | 0, l[1] = t + l[1] | 0, l[2] = a + l[2] | 0, l[3] = r + l[3] | 0;
}
function d(l) {
var h = [], s;
for (s = 0; s < 64; s += 4)
h[s >> 2] = l.charCodeAt(s) + (l.charCodeAt(s + 1) << 8) + (l.charCodeAt(s + 2) << 16) + (l.charCodeAt(s + 3) << 24);
return h;
}
function g(l) {
var h = [], s;
for (s = 0; s < 64; s += 4)
h[s >> 2] = l[s] + (l[s + 1] << 8) + (l[s + 2] << 16) + (l[s + 3] << 24);
return h;
}
function y(l) {
var h = l.length, s = [1732584193, -271733879, -1732584194, 271733878], t, a, r, w, x, T;
for (t = 64; t <= h; t += 64)
u(s, d(l.substring(t - 64, t)));
for (l = l.substring(t - 64), a = l.length, r = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = 0; t < a; t += 1)
r[t >> 2] |= l.charCodeAt(t) << (t % 4 << 3);
if (r[t >> 2] |= 128 << (t % 4 << 3), t > 55)
for (u(s, r), t = 0; t < 16; t += 1)
r[t] = 0;
return w = h * 8, w = w.toString(16).match(/(.*?)(.{0,8})$/), x = parseInt(w[2], 16), T = parseInt(w[1], 16) || 0, r[14] = x, r[15] = T, u(s, r), s;
}
function S(l) {
var h = l.length, s = [1732584193, -271733879, -1732584194, 271733878], t, a, r, w, x, T;
for (t = 64; t <= h; t += 64)
u(s, g(l.subarray(t - 64, t)));
for (l = t - 64 < h ? l.subarray(t - 64) : new Uint8Array(0), a = l.length, r = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = 0; t < a; t += 1)
r[t >> 2] |= l[t] << (t % 4 << 3);
if (r[t >> 2] |= 128 << (t % 4 << 3), t > 55)
for (u(s, r), t = 0; t < 16; t += 1)
r[t] = 0;
return w = h * 8, w = w.toString(16).match(/(.*?)(.{0,8})$/), x = parseInt(w[2], 16), T = parseInt(w[1], 16) || 0, r[14] = x, r[15] = T, u(s, r), s;
}
function C(l) {
var h = "", s;
for (s = 0; s < 4; s += 1)
h += o[l >> s * 8 + 4 & 15] + o[l >> s * 8 & 15];
return h;
}
function v(l) {
var h;
for (h = 0; h < l.length; h += 1)
l[h] = C(l[h]);
return l.join("");
}
v(y("hello")), typeof ArrayBuffer < "u" && !ArrayBuffer.prototype.slice && function() {
function l(h, s) {
return h = h | 0 || 0, h < 0 ? Math.max(h + s, 0) : Math.min(h, s);
}
ArrayBuffer.prototype.slice = function(h, s) {
var t = this.byteLength, a = l(h, t), r = t, w, x, T, Y;
return s !== i && (r = l(s, t)), a > r ? new ArrayBuffer(0) : (w = r - a, x = new ArrayBuffer(w), T = new Uint8Array(x), Y = new Uint8Array(this, a, w), T.set(Y), x);
};
}();
function E(l) {
return /[\u0080-\uFFFF]/.test(l) && (l = unescape(encodeURIComponent(l))), l;
}
function A(l, h) {
var s = l.length, t = new ArrayBuffer(s), a = new Uint8Array(t), r;
for (r = 0; r < s; r += 1)
a[r] = l.charCodeAt(r);
return h ? a : t;
}
function U(l) {
return String.fromCharCode.apply(null, new Uint8Array(l));
}
function z(l, h, s) {
var t = new Uint8Array(l.byteLength + h.byteLength);
return t.set(new Uint8Array(l)), t.set(new Uint8Array(h), l.byteLength), t;
}
function _(l) {
var h = [], s = l.length, t;
for (t = 0; t < s - 1; t += 2)
h.push(parseInt(l.substr(t, 2), 16));
return String.fromCharCode.apply(String, h);
}
function F() {
this.reset();
}
return F.prototype.append = function(l) {
return this.appendBinary(E(l)), this;
}, F.prototype.appendBinary = function(l) {
this._buff += l, this._length += l.length;
var h = this._buff.length, s;
for (s = 64; s <= h; s += 64)
u(this._hash, d(this._buff.substring(s - 64, s)));
return this._buff = this._buff.substring(s - 64), this;
}, F.prototype.end = function(l) {
var h = this._buff, s = h.length, t, a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], r;
for (t = 0; t < s; t += 1)
a[t >> 2] |= h.charCodeAt(t) << (t % 4 << 3);
return this._finish(a, s), r = v(this._hash), l && (r = _(r)), this.reset(), r;
}, F.prototype.reset = function() {
return this._buff = "", this._length = 0, this._hash = [1732584193, -271733879, -1732584194, 271733878], this;
}, F.prototype.getState = function() {
return {
buff: this._buff,
length: this._length,
hash: this._hash.slice()
};
}, F.prototype.setState = function(l) {
return this._buff = l.buff, this._length = l.length, this._hash = l.hash, this;
}, F.prototype.destroy = function() {
delete this._hash, delete this._buff, delete this._length;
}, F.prototype._finish = function(l, h) {
var s = h, t, a, r;
if (l[s >> 2] |= 128 << (s % 4 << 3), s > 55)
for (u(this._hash, l), s = 0; s < 16; s += 1)
l[s] = 0;
t = this._length * 8, t = t.toString(16).match(/(.*?)(.{0,8})$/), a = parseInt(t[2], 16), r = parseInt(t[1], 16) || 0, l[14] = a, l[15] = r, u(this._hash, l);
}, F.hash = function(l, h) {
return F.hashBinary(E(l), h);
}, F.hashBinary = function(l, h) {
var s = y(l), t = v(s);
return h ? _(t) : t;
}, F.ArrayBuffer = function() {
this.reset();
}, F.ArrayBuffer.prototype.append = function(l) {
var h = z(this._buff.buffer, l), s = h.length, t;
for (this._length += l.byteLength, t = 64; t <= s; t += 64)
u(this._hash, g(h.subarray(t - 64, t)));
return this._buff = t - 64 < s ? new Uint8Array(h.buffer.slice(t - 64)) : new Uint8Array(0), this;
}, F.ArrayBuffer.prototype.end = function(l) {
var h = this._buff, s = h.length, t = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], a, r;
for (a = 0; a < s; a += 1)
t[a >> 2] |= h[a] << (a % 4 << 3);
return this._finish(t, s), r = v(this._hash), l && (r = _(r)), this.reset(), r;
}, F.ArrayBuffer.prototype.reset = function() {
return this._buff = new Uint8Array(0), this._length = 0, this._hash = [1732584193, -271733879, -1732584194, 271733878], this;
}, F.ArrayBuffer.prototype.getState = function() {
var l = F.prototype.getState.call(this);
return l.buff = U(l.buff), l;
}, F.ArrayBuffer.prototype.setState = function(l) {
return l.buff = A(l.buff, !0), F.prototype.setState.call(this, l);
}, F.ArrayBuffer.prototype.destroy = F.prototype.destroy, F.ArrayBuffer.prototype._finish = F.prototype._finish, F.ArrayBuffer.hash = function(l, h) {
var s = S(new Uint8Array(l)), t = v(s);
return h ? _(t) : t;
}, F;
});
}(se)), se.exports;
}
var Oe = Be();
const Ie = /* @__PURE__ */ Te(Oe);
var De = Object.defineProperty, qe = (n, e, i) => e in n ? De(n, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[e] = i, m = (n, e, i) => qe(n, typeof e != "symbol" ? e + "" : e, i);
const J = (n, e) => toString.call(n).slice(8, -1).toLowerCase() === e, L = function(n) {
return typeof n == "function";
}, $e = (n) => J(n, "object"), re = (n) => $e(n) && n !== null, ae = (n) => J(n, "array"), He = (n) => n && L(n.then), We = function(n) {
return J(n, "string");
}, Ye = function(n) {
return J(n, "boolean");
};
let Ve = 0;
const ne = (n = "id") => `${n}-${+/* @__PURE__ */ new Date()}-${Ve++}`;
function G(n, e, i) {
if (ae(n)) {
const d = n;
for (var o = 0, u = d.length; o < u && e.call(i, d[o], o, d) !== !1; o++)
;
} else {
const d = n;
for (const g in d)
if (Object.prototype.hasOwnProperty.call(d, g) && e.call(i, d[g], g, d) === !1)
break;
}
}
function W() {
var n, e, i, o, u, d, g = arguments[0] || {}, y = 1, S = arguments.length, C = !1;
for (typeof g == "boolean" && (C = g, g = arguments[1] || {}, y++), typeof g != "object" && !L(g) && (g = {}), y === S && (g = this, y--); y < S; y++)
if ((n = arguments[y]) != null)
for (e in n)
i = g[e], o = n[e], g !== o && (C && o && (re(o) || (u = ae(o))) ? (u ? (u = !1, d = i && ae(i) ? i : []) : d = i && re(i) ? i : {}, g[e] = W(C, d, o)) : o !== void 0 && (g[e] = o));
return g;
}
const D = (n) => typeof n == "function" ? n() || {} : re(n) ? n : {}, Ge = (n) => {
if (!n || isNaN(Number(n)) || Number(n) <= 0 || n === "") return "0 B";
const e = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], i = 1024, o = Number(n), u = Math.floor(Math.log(o) / Math.log(i));
return `${(o / Math.pow(i, u)).toFixed(2)} ${e[Math.min(u, e.length - 1)]}`;
}, Je = (n, e = 300) => {
let i = 0;
return function(...o) {
let u = +/* @__PURE__ */ new Date();
u - i > e && (i = u, n.apply(this, o));
};
};
class Xe {
constructor(e) {
m(this, "uploader"), m(this, "listeners"), m(this, "inputs"), this.uploader = e, this.listeners = [], this.inputs = [];
}
assignBrowse(e, i = {}) {
if (!e) {
console.warn("DOM 节点不存在");
return;
}
const o = this.createOrGetInput(e);
this.setInputAttributes(o, i), this.attachBrowseEvents(e, o);
}
assignDrop(e) {
if (!e) {
console.warn("DOM 节点不存在");
return;
}
const i = (u) => u.preventDefault(), o = {
dragover: i,
dragenter: i,
dragleave: i,
drop: this.handleDrop.bind(this)
};
G(o, (u, d) => {
e.addEventListener(d, u, { passive: !1 }), this.listeners.push({ node: e, event: d, handler: u });
});
}
createOrGetInput(e) {
if (e instanceof HTMLInputElement && e.tagName === "INPUT" && e.type === "file")
return e;
const i = document.createElement("input");
return i.type = "file", W(i.style, {
visibility: "hidden",
position: "absolute",
width: "1px",
height: "1px"
}), e.appendChild(i), this.inputs.push(i), i;
}
setInputAttributes(e, i) {
G(i, (o, u) => e.setAttribute(u, o)), e.toggleAttribute("multiple", !!i.multiple);
}
attachBrowseEvents(e, i) {
const o = () => i.click(), u = (d) => {
const g = d.target;
this.uploader.addFiles(g.files), g.value = "";
};
e.addEventListener("click", o, { passive: !0 }), i.addEventListener("change", u, { passive: !0 }), this.listeners.push(
{ node: e, event: "click", handler: o },
{ node: i, event: "change", handler: u }
);
}
handleDrop(e) {
var i;
e.preventDefault(), e.stopPropagation(), e instanceof DragEvent && this.uploader.addFiles((i = e.dataTransfer) == null ? void 0 : i.files);
}
destroy() {
return this.listeners.forEach(({ node: e, event: i, handler: o }) => {
e.removeEventListener(i, o);
}), this.listeners = [], this.inputs.forEach((e) => {
e.parentNode && e.parentNode.removeChild(e);
}), this.inputs = [], this;
}
}
class Ze {
constructor() {
m(this, "events"), this.events = /* @__PURE__ */ new Map();
}
on(e, i) {
if (!L(i)) return;
const o = this.events.get(e) || [];
o.includes(i) || (o.push(i), this.events.set(e, o));
}
off(e, i) {
var o;
if (!this.events.has(e)) return;
if (!i) {
this.events.set(e, []);
return;
}
const u = (o = this.events.get(e)) == null ? void 0 : o.filter((d) => d !== i);
this.events.set(e, u);
}
emit(e, ...i) {
const o = this.events.get(e);
o && o.length && o.forEach((u) => u(...i));
}
once(e, i) {
if (!L(i)) return;
const o = (...u) => {
i(...u), this.off(e, o);
};
this.on(e, o);
}
clear(e) {
if (!e) {
this.events.clear();
return;
}
this.events.has(e) && this.events.set(e, []);
}
}
const f = {
/** 文件初始化状态 */
Init: "init",
/** 文件添加失败, 添加文件时允许beforeAdd中失败的文件添加到列表,但是状态为AddFail */
AddFail: "addFail",
/** 文件读取中(计算hash中) */
Reading: "reading",
/** 文件hash计算完成;准备上传 */
Ready: "ready",
/** checkRequest 存在时,切checkRequest失败 */
CheckFail: "checkFail",
/** 文件上传中 */
Uploading: "uploading",
/** 文件上传完成;所有chunk上传完成,准备合并文件 */
UploadSuccess: "uploadSuccess",
/** 文件上传失败;有chunk上传失败 */
UploadFail: "uploadFail",
/** 文件上传成功 且 合并成功 */
Success: "success",
/** 文件合并失败 */
Fail: "fail",
/** 文件暂停上传 */
Pause: "pause",
/** 文件恢复上传 */
Resume: "resume"
}, N = {
/** chunk初始化状态是Ready */
Ready: "ready",
/** chunk创建请求成功,Promise处于Pending状态 */
Pending: "pending",
/** chunk上传中 */
Uploading: "uploading",
/** chunk上传成功 */
Success: "success",
/** chunk上传失败(所有重试次数完成后 都不成功) */
Fail: "fail"
}, R = {
/** 文件超出limit限制 */
Exceed: "exceed",
/** 单个文件添加成功 */
FileAdded: "fileAdded",
/** 文件添加失败 */
FileAddFail: "fileAddFail",
/** 所有文件添加成功 */
FilesAdded: "filesAdded",
/** 文件状态改变 */
FileChange: "fileChange",
/** 文件删除 */
FileRemove: "fileRemove",
/** 文件开始计算hash */
FileReadStart: "fileReadStart",
/** 文件计算进度 */
FileReadProgress: "fileReadProgress",
/** 文件hash计算完成 */
FileReadEnd: "fileReadEnd",
FileReadFail: "fileReadFail",
/** 暂停操作 */
FilePause: "filePause",
/** 重新上传操作 */
FileResume: "fileResume",
/** 文件上传进度 */
FileProgress: "fileProgress",
/** 文件上传成功 */
FileUploadSuccess: "fileUploadSuccess",
/** 文件上传失败 */
FileUploadFail: "fileUploadFail",
/** 文件合并成功 */
FileSuccess: "fileSuccess",
/** 文件上传失败合并失败 */
FileFail: "fileFail",
/** 所有文件上传成功 */
AllFileSuccess: "allFileSuccess"
}, H = {
/** 文件还没上传 */
None: "none",
/** 部分上传成功 */
Part: "part",
/** 准备合并 */
WaitMerge: "waitMerge",
/** 上传成功 */
Success: "success"
}, oe = {
/** check接口 */
Check: "check",
/** upload chunk接口 */
Upload: "upload",
/** merge接口 */
Merge: "merge"
};
function Qe(n) {
const {
method: e = "POST",
withCredentials: i = !0,
responseType: o = "json",
action: u,
data: d,
// query,
headers: g,
onSuccess: y,
onFail: S,
onProgress: C
} = n;
let v = new XMLHttpRequest();
v.responseType = o, v.withCredentials = i, v.open(e, u, !0);
const E = new FormData();
return Object.entries(d).forEach(([A, U]) => E.append(A, U)), "setRequestHeader" in v && Object.entries(g).forEach(([A, U]) => v.setRequestHeader(A, U)), v.addEventListener("timeout", () => {
S && S(new Error("Request timed out"), v);
}), v.upload.addEventListener("progress", (A) => {
C && C(A);
}), v.addEventListener(
"error",
(A) => {
S && S(A, v);
},
!1
), v.addEventListener("readystatechange", (A) => {
if (v.readyState === 4) {
if (v.status < 200 || v.status >= 300) {
S && S(new Error(`xhr: status === ${v.status}`), v);
return;
}
y && y(A, v);
}
}), v.send(E), {
abort() {
v.abort(), v = null;
}
};
}
class Ke {
constructor(e, i) {
m(this, "uploader"), m(this, "options"), m(this, "file"), m(this, "fileId"), m(this, "rawFile"), m(this, "fileHash"), m(this, "filename"), m(this, "totalSize"), m(this, "chunkSize"), m(this, "totalChunks"), m(this, "uid"), m(this, "chunkIndex"), m(this, "status"), m(this, "startByte"), m(this, "endByte"), m(this, "size"), m(this, "maxRetries"), m(this, "progress"), m(this, "fakeProgress"), m(this, "timer"), m(this, "request"), m(this, "customRequest"), this.uploader = e.uploader, this.options = e.uploader.options, this.file = e, this.rawFile = e.rawFile, this.fileId = e.uid, this.fileHash = e.hash, this.filename = e.name, this.totalSize = e.size, this.chunkSize = this.options.chunkSize, this.totalChunks = e.totalChunks, this.uid = ne(), this.chunkIndex = i, this.status = N.Ready, this.startByte = this.chunkSize * i, this.endByte = Math.min(this.startByte + this.chunkSize, this.totalSize), this.size = this.endByte - this.startByte, this.maxRetries = this.options.maxRetries, this.progress = 0, this.fakeProgress = 0, this.timer = null, this.request = null, this.customRequest = this.options.customRequest || Qe;
}
onSuccess(e, i, o, u) {
this.options.requestSucceed(i) ? (this.status = N.Success, this.file.removeUploadingChunk(this), this.file.isUploading() && this.file.upload(), o(this)) : this.onFail(e, u);
}
onFail(e, i) {
var o;
this.progress = 0, this.file.setProgress(), !((o = this.request) != null && o.canceled) && (this.maxRetries <= 0 ? (this.file.removeUploadingChunk(this), this.status = N.Fail, this.file.isUploading() && this.file.upload(), i(e, this)) : this.timer = setTimeout(() => {
this.send(), this.maxRetries--, clearTimeout(this.timer);
}, this.options.retryInterval));
}
onProgress(e) {
this.progress = Math.min(1, e.loaded / e.total), this.fakeProgress = Math.max(this.progress, this.fakeProgress), this.status = N.Uploading, this.file.changeStatus(f.Uploading), this.file.setProgress();
}
prepare() {
const { name: e, data: i, processData: o } = this.options, { data: u } = this.file, d = {
[e]: this.file.rawFile.slice(this.startByte, this.endByte),
hash: this.fileHash,
id: this.uid,
fileId: this.fileId,
index: this.chunkIndex,
filename: this.filename,
size: this.size,
totalSize: this.totalSize,
totalChunks: this.totalChunks,
...D(i),
...u
};
return L(o) && o(d, oe.Upload) || d;
}
send() {
this.status = N.Pending;
const { action: e, headers: i, withCredentials: o, name: u } = this.options;
return new Promise((d, g) => {
this.request = this.customRequest({
action: e,
name: u,
withCredentials: o,
headers: D(i),
data: this.prepare(),
query: {
...D(this.options.data),
...this.file.data
},
onSuccess: (y, S) => this.onSuccess(y, S, d, g),
onFail: (y) => this.onFail(y, g),
onProgress: (y) => this.onProgress(y)
}), this.request.canceled = !1;
});
}
abort() {
this.status = N.Ready, this.request && (this.request.canceled = !0, this.request.abort()), this.timer && clearTimeout(this.timer);
}
}
class ie {
constructor(e, i, o) {
m(this, "uploader"), m(this, "options"), m(this, "hasher"), m(this, "id"), m(this, "uid"), m(this, "status"), m(this, "prevStatusLastRecord"), m(this, "rawFile"), m(this, "name"), m(this, "size"), m(this, "type"), m(this, "hash"), m(this, "url"), m(this, "progress"), m(this, "chunkSize"), m(this, "chunks"), m(this, "totalChunks"), m(this, "uploadingChunks"), m(this, "readProgress"), m(this, "errorMessage"), m(this, "data"), m(this, "abortRead"), this.uploader = i, this.options = this.uploader.options, this.hasher = this.uploader.hasher, this.prevStatusLastRecord = [], this.rawFile = e, this.name = e.name, this.size = e.size, this.type = e.type, this.hash = "", this.url = "", this.status = "", this.progress = 0, this.chunkSize = this.options.chunkSize, this.chunks = [], this.totalChunks = 0, this.uploadingChunks = /* @__PURE__ */ new Set(), this.readProgress = 0, this.errorMessage = "", this.data = {}, this.uid = this.generateId(), o ? (Object.keys(o).forEach((u) => {
this[u] = o[u];
}), this.name = o.name, this.url = o.url, this.readProgress = 1, this.progress = 1, this.changeStatus(f.Success)) : this.changeStatus(f.Init);
}
generateId() {
const { customGenerateUid: e } = this.options;
return !e || !L(e) ? ne() : e(this) || ne();
}
setErrorMessage(e) {
return this.errorMessage = String(e), this;
}
setData(e) {
return this.data = { ...this.data, ...e }, this;
}
get renderSize() {
return Ge(this.size);
}
changeStatus(e) {
(e !== this.status || e === f.Reading) && (this.prevStatusLastRecord.push(this.status), this.status = e, this.uploader && this.uploader.emitCallback && this.uploader.emitCallback(R.FileChange, this));
}
isInit() {
return this.status === f.Init;
}
isAddFail() {
return this.status === f.AddFail;
}
isReading() {
return this.status === f.Reading;
}
isReady() {
return this.status === f.Ready;
}
isCheckFail() {
return this.status === f.CheckFail;
}
isUploading() {
return this.status === f.Uploading;
}
isUploadSuccess() {
return this.status === f.UploadSuccess;
}
isUploadFail() {
return this.status === f.UploadFail;
}
isSuccess() {
return this.status === f.Success;
}
isFail() {
return this.status === f.Fail;
}
isPause() {
return this.status === f.Pause;
}
isResume() {
return this.status === f.Resume;
}
createChunks() {
this.totalChunks = Math.ceil(this.size / this.chunkSize) || 1, this.chunks = Array.from({ length: this.totalChunks }, (e, i) => new Ke(this, i));
}
async read() {
if (!this.options.withHash) {
this.createChunks(), this.changeStatus(f.Ready);
return;
}
this.uploader.emitCallback(R.FileReadStart, this), this.changeStatus(f.Reading);
try {
const e = Date.now(), { hash: i, progress: o } = await this._computeHash();
this.hash = i, this.readProgress = o, this.uploader.emitCallback(R.FileReadEnd, this), console.log(
`${this.options.useWebWoker ? "Web Worker" : "Main Thread"} read file took`,
(Date.now() - e) / 1e3,
"s"
), this.abortRead = null;
} catch (e) {
throw console.warn(e.message), e && e.message && e.message.toLowerCase().includes("cancel") || this.setErrorMessage("File read failed"), this.changeStatus(f.Init), this.uploader.emitCallback(R.FileReadFail, this), new Error("File read failed");
}
this.createChunks(), this.changeStatus(f.Ready);
}
async _computeHash() {
try {
const e = Je((d) => {
this.readProgress = d, this.uploader.emitCallback(R.FileReadProgress, this);
}, 200);
if (this.options.useWebWoker && this.hasher.hashionName !== "sparkMd5Webworker")
throw new Error(`
Please install "SparkWorker" plugin -> npm i hashion;
https://www.npmjs.com/package/hashion
`);
const { promise: i, abort: o } = this.hasher.computedHash(
{
file: this.rawFile,
chunkSize: this.chunkSize
// useWebWoker: this.options.useWebWoker
},
({ progress: d }) => e(d)
);
this.abortRead = o;
const u = await i;
return e(u.progress), u;
} catch (e) {
throw e;
}
}
_processData(e) {
const { data: i, processData: o } = this.options, u = { ...D(i), ...this.data };
return L(o) && o(u, e) || u;
}
async checkRequest() {
const { checkRequest: e } = this.options;
if (!L(e))
return Promise.resolve();
const i = (u) => {
this.chunks.forEach((d) => {
d.status = u, d.progress = 1, d.fakeProgress = 1;
});
}, o = {
[H.Part]: (u) => {
this.chunks.forEach((d) => {
u.includes(d.chunkIndex) && (d.status = N.Success, d.progress = 1, d.fakeProgress = 1);
});
},
[H.WaitMerge]: () => {
this.changeStatus(f.UploadSuccess), i(N.Success);
},
[H.Success]: (u) => {
this.changeStatus(f.Success), i(N.Success), this.url = u;
},
[H.None]: () => {
}
};
try {
const u = await Promise.resolve(
e(this, this._processData(oe.Check), D(this.options.headers))
);
if (!u || !u.status)
throw new Error("Invalid check response format");
const d = o[u.status];
if (!d)
throw new Error(`Unknown check status: ${u.status}`);
return d(u.data), Promise.resolve();
} catch (u) {
this.changeStatus(f.CheckFail), this.uploader.upload();
const d = new Error(`Check request failed: ${u.message}`);
throw d.originalError = u, d;
}
}
addUploadingChunk(e) {
this.uploadingChunks.add(e);
}
removeUploadingChunk(e) {
this.uploadingChunks.delete(e);
}
async upload() {
if (this.isInit() && await this.read(), this.isReady() && this.options.checkRequest && (await this.checkRequest(), this.status === f.Pause))
return;
if (this.isUploadSuccess())
return this.merge();
if (this.isSuccess())
return this.success();
const e = this.chunks.filter((i) => i.status === N.Ready);
if (G(e, () => {
if (this.uploadingChunks.size >= this.options.maxConcurrency)
return !1;
const i = e.shift();
if (i)
this.addUploadingChunk(i);
else
return !1;
}), this.uploadingChunks.size > 0) {
const i = [...this.uploadingChunks].filter(
(o) => o.status === N.Ready
);
Promise.race(i.map((o) => o.send()));
return;
}
this.chunks.some((i) => i.status === N.Fail) ? this.uploadFail() : (this.uploadSuccess(), this.setProgress(), this.merge());
}
setProgress() {
const e = this.chunks.reduce((i, o) => {
const u = this.options.fakeProgress ? o.fakeProgress : o.progress;
return i += u * (o.size / this.size);
}, 0);
this.progress = Math.min(1, e), (this.isUploadSuccess() || this.isSuccess()) && (this.progress = 1), this.uploader.emitCallback(R.FileProgress, this);
}
uploadFail() {
this.changeStatus(f.UploadFail), this.uploader.emitCallback(R.FileUploadFail, this), this._continueUpload();
}
uploadSuccess() {
this.changeStatus(f.UploadSuccess), this.uploader.emitCallback(R.FileUploadSuccess, this);
}
async merge() {
const { mergeRequest: e } = this.options;
if (!L(e))
return this.success();
try {
const i = e(
this,
this._processData(oe.Merge),
D(this.options.headers)
), o = await Promise.resolve(i);
Ye(o) ? o ? this.success() : this.mergeFail() : (this.url = o, this.success());
} catch (i) {
console.log(i), this.mergeFail();
}
}
mergeFail() {
this.changeStatus(f.Fail), this.uploader.emitCallback(R.FileFail, this), this._continueUpload();
}
success() {
this.changeStatus(f.Success), this.progress = 1, this.uploader.emitCallback(R.FileSuccess, this), this._continueUpload();
}
_continueUpload() {
const e = this.uploader.fileList.find((i) => i.isPause());
e && e.resume(), this.uploader.upload();
}
cancel() {
this.uploadingChunks.forEach((e) => e.abort()), this.uploadingChunks.clear();
}
async remove() {
this.abortRead && this.abortRead(), setTimeout(() => {
this.cancel(), this.chunks = [], this.changeStatus("removed");
const e = this.uploader.fileList.indexOf(this);
e > -1 && this.uploader.fileList.splice(e, 1), this.uploader.emitCallback(R.FileRemove, this), this.uploader.upload();
}, 0);
}
pause() {
this.abortRead && this.abortRead(), setTimeout(() => {
this.cancel(), this.changeStatus(f.Pause), this.uploader.emitCallback(R.FilePause, this), this.uploader.upload();
}, 0);
}
resume() {
this.isPause() && (this.changeStatus(f.Resume), this.uploader.emitCallback(R.FileResume, this), this.uploader.upload());
}
retry() {
if (!this.isAddFail()) {
if (this.isCheckFail()) {
this.changeStatus(f.Ready), this.upload();
return;
}
if (this.isUploadSuccess() || this.isFail()) {
this.merge();
return;
}
this.isUploadFail() && (G(this.chunks, (e) => {
e.status === N.Fail && (e.status = N.Ready, e.maxRetries = e.options.maxRetries);
}), this.upload());
}
}
}
const xe = {
// input 属性相关
accept: "*",
multiple: !0,
// 文件相关
fileList: [],
limit: 10,
autoUpload: !0,
customGenerateUid: void 0,
beforeAdd: (n) => !0,
beforeRemove: (n) => !0,
addFailToRemove: !0,
chunkSize: 2 * 1024 * 1024,
// 2M
fakeProgress: !0,
withHash: !0,
useWebWoker: !1,
// 上传逻辑相关
name: "file",
action: "",
customRequest: null,
withCredentials: !0,
headers: {},
data: {},
requestSucceed: (n) => [200, 201, 202, 206].includes(n.status),
maxConcurrency: 6,
maxRetries: 3,
retryInterval: 1e3,
checkRequest: (n) => ({ status: H.None }),
mergeRequest: (n) => !0,
processData: (n, e) => n
};
var et = Object.defineProperty, tt = (n, e, i) => e in n ? et(n, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[e] = i, Re = (n, e, i) => tt(n, typeof e != "symbol" ? e + "" : e, i);
class st {
constructor(e, i) {
Re(this, "hashCarrier"), Re(this, "hashionName"), this.hashionName = e.name, this.hashCarrier = new e(i);
}
computedHash({ file: e, chunkSize: i }, o) {
let u;
return {
promise: new Promise((d, g) => {
Promise.resolve(
this.hashCarrier.computeHash(
{
file: e,
chunkSize: i
},
(y, { progress: S, hash: C, time: v }) => {
y && g(y), S === 100 && d({ progress: S, hash: C, time: v }), o && o({ progress: S });
}
)
).then((y) => {
u = { abort: y == null ? void 0 : y.abort, reject: g };
});
}),
abort: () => {
u && (u.abort && u.abort(), u.reject(new Error("Canceled promise to rejected")));
}
};
}
}
var it = Object.defineProperty, rt = (n, e, i) => e in n ? it(n, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[e] = i, le = (n, e, i) => rt(n, typeof e != "symbol" ? e + "" : e, i);
const at = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
class he {
constructor() {
le(this, "name"), this.name = "spark-md5";
}
async computeHash(e, i) {
const { file: o, chunkSize: u } = e;
let d = !1;
const g = new Ie.ArrayBuffer(), y = new FileReader(), S = Math.ceil(o.size / u), C = Date.now();
let v = 0;
const E = new AbortController(), A = E.signal;
A.addEventListener("abort", () => {
d || (y.abort(), i(new Error("Hash calculation cancelled"), { progress: 0 }));
}), y.onload = function(z) {
var _;
if (!A.aborted)
if (g.append((_ = z.target) == null ? void 0 : _.result), v++, v < S)
U(), i(null, {
progress: v / S * 100
});
else {
d = !0, i(null, {
hash: g.end(),
time: Date.now() - C,
progress: 100
});
return;
}
}, y.onerror = function(z) {
A.aborted || (console.warn("spark-md5: Hash calculation error"), i(z, { progress: 0 }));
};
function U() {
if (A.aborted) return;
const z = v * u, _ = z + u >= o.size ? o.size : z + u;
y.readAsArrayBuffer(at.call(o, z, _));
}
return U(), {
abort: () => E.abort()
};
}
}
le(he, "pluginName", "hash-plugin"), le(he, "name", "spark-md5");
class nt {
constructor(e) {
m(this, "container"), m(this, "event"), m(this, "options"), m(this, "hasher"), m(this, "fileList"), this.container = new Xe(this), this.event = new Ze(), this.options = W(xe, e), this.hasher = null, this.fileList = (this.options.fileList || []).map((i) => new ie(i, this, i)), this._setupFileListeners(), this.use(he);
}
on(e, i) {
this.event.on(e, i);
}
emit(e, ...i) {
this.event.emit(e, ...i);
}
emitCallback(e, ...i) {
this.emit(e, ...i, this.fileList);
}
updateData(e) {
this.options.data = e;
}
updateHeaders(e) {
this.options.headers = e;
}
setOption(e) {
this.options = W(this.options, e);
}
use(e) {
e.pluginName === "hash-plugin" && (this.hasher = new st(e));
}
formatAccept(e) {
return We(e) ? e : Array.isArray(e) ? e.join(",") : "";
}
assignBrowse(e, i = {}) {
const { accept: o, ...u } = i, d = {
multiple: this.options.multiple,
accept: this.formatAccept(o || this.options.accept)
};
this.container.assignBrowse(e, W({}, d, u));
}
assignDrop(e) {
this.container.assignDrop(e);
}
_setupFileListeners() {
const e = (i, o) => {
o.length && o.every((u) => u.isSuccess()) && this.emit(R.AllFileSuccess, this.fileList);
};
this.on(R.FileSuccess, e), this.on(R.FileRemove, e);
}
setDefaultFileList(e) {
e.forEach((i) => {
this.fileList.push(new ie(i, this, i));
});
}
async addFiles(e) {
const { limit: i, multiple: o, addFailToRemove: u, beforeAdd: d, autoUpload: g } = this.options;
let y = [...e];
if (y.length === 0) return;
if (i > 0 && y.length + this.fileList.length > i) {
this.emitCallback(R.Exceed, y);
return;
}
o || (y = y.slice(0, 1));
const S = y.map((C) => new ie(C, this, null));
await Promise.all(S.map((C) => this._handleFileAdd(C, d))), this.fileList = this.fileList.filter((C) => C.isAddFail() && u ? (this.doRemove(C), !1) : !0), S.length > 0 && this.emitCallback(R.FilesAdded, this.fileList), g && this.submit();
}
async _handleFileAdd(e, i) {
try {
if (L(i) && await i(e) === !1)
throw new Error("Before add rejected");
this.emitCallback(R.FileAdded, e);
} catch {
e.changeStatus(f.AddFail), this.emitCallback(R.FileAddFail, e);
}
this.fileList.push(e);
}
async upload() {
if (this.fileList.length !== 0)
for (let e = 0; e < this.fileList.length; e++) {
const i = this.fileList[e];
if (!(i.isAddFail() || i.isCheckFail())) {
if (i.isUploading() || i.isReading())
return;
if (i.isResume()) {
const o = i.prevStatusLastRecord[i.prevStatusLastRecord.length - 2];
o && i.changeStatus(o), i.upload();
return;
}
if (i.isReady() || i.isInit()) {
i.upload();
return;
}
}
}
}
submit() {
this.upload();
}
remove(e) {
const { beforeRemove: i } = this.options;
if (!i)
this.doRemove(e);
else if (L(i)) {
const o = i(e);
He(o) ? o.then(() => {
this.doRemove(e);
}) : o !== !1 && this.doRemove(e);
}
}
clear() {
for (let e = this.fileList.length - 1; e >= 0; e--)
this.fileList[e].remove();
this.fileList = [];
}
doRemove(e) {
if (!e) {
this.clear();
return;
}
e.remove();
}
pause(e) {
e && this.fileList.indexOf(e) > -1 && e.pause();
}
resume(e) {
e && (this.fileList.filter((i) => i.isUploading() || i.isReading()).forEach((i) => {
i.pause();
}), e.resume());
}
retry(e) {
e && (this.fileList.filter((i) => i.isUploading() || i.isReading()).forEach((i) => {
i.pause();
}), this.fileList.indexOf(e) > -1 && e.retry());
}
destroy() {
this.clear(), this.event.clear(), this.container.destroy();
}
}
const ot = (n) => new nt(n), lt = {
sdk: null,
setUploader: () => null
}, Ce = je(lt);
function ht({ children: n }) {
const [e, i] = ue(null), o = {
sdk: e,
setUploader: (u) => i(u)
};
return /* @__PURE__ */ p.jsx(Ce.Provider, { value: o, children: n });
}
const X = () => Pe(Ce), ut = ({ size: n = 32, style: e }) => /* @__PURE__ */ p.jsxs(
"svg",
{
style: e,
className: "tiny-uploader-icon tiny-uploader-icon-upload",
viewBox: "0 0 1024 1024",
version: "1.1",
xmlns: "http://www.w3.org/2000/svg",
"p-id": "20916",
width: n,
height: n,
children: [
/* @__PURE__ */ p.jsx(
"path",
{
d: "M789.464615 885.799385h-168.448c-70.025846 0-125.794462-58.958769-125.794461-130.244923v-243.239385c0-9.846154 8.310154-18.432 17.801846-18.432 9.491692 0 17.801846 8.585846 17.801846 18.432v242.018461c0 51.593846 40.329846 93.380923 90.1