@xuda.io/xuda-widget-plugin-xuda-drive
Version:
Xuda Drive widget plugin
1,338 lines • 2.79 MB
JavaScript
/*!
* FilePond 4.32.4
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
const isNode$2 = (I) => I instanceof HTMLElement, createStore$2 = (I, M = [], N = []) => {
const V = {
...I
}, U = [], j = [], J = () => ({ ...V }), ne = () => {
const ke = [...U];
return U.length = 0, ke;
}, se = () => {
const ke = [...j];
j.length = 0, ke.forEach(({ type: Fe, data: Je }) => {
ve(Fe, Je);
});
}, ve = (ke, Fe, Je) => {
if (Je && !document.hidden) {
j.push({ type: ke, data: Fe });
return;
}
Le[ke] && Le[ke](Fe), U.push({
type: ke,
data: Fe
});
}, Ee = (ke, ...Fe) => Ue[ke] ? Ue[ke](...Fe) : null, Ie = {
getState: J,
processActionQueue: ne,
processDispatchQueue: se,
dispatch: ve,
query: Ee
};
let Ue = {};
M.forEach((ke) => {
Ue = {
...ke(V),
...Ue
};
});
let Le = {};
return N.forEach((ke) => {
Le = {
...ke(ve, Ee, V),
...Le
};
}), Ie;
}, defineProperty = (I, M, N) => {
if (typeof N == "function") {
I[M] = N;
return;
}
Object.defineProperty(I, M, { ...N });
}, forin = (I, M) => {
for (const N in I)
I.hasOwnProperty(N) && M(N, I[N]);
}, createObject = (I) => {
const M = {};
return forin(I, (N) => {
defineProperty(M, N, I[N]);
}), M;
}, attr$1 = (I, M, N = null) => {
if (N === null)
return I.getAttribute(M) || I.hasAttribute(M);
I.setAttribute(M, N);
}, ns = "http://www.w3.org/2000/svg", svgElements = ["svg", "path"], isSVGElement = (I) => svgElements.includes(I), createElement$1 = (I, M, N = {}) => {
typeof M == "object" && (N = M, M = null);
const V = isSVGElement(I) ? document.createElementNS(ns, I) : document.createElement(I);
return M && (isSVGElement(I) ? attr$1(V, "class", M) : V.className = M), forin(N, (U, j) => {
attr$1(V, U, j);
}), V;
}, appendChild = (I) => (M, N) => {
typeof N < "u" && I.children[N] ? I.insertBefore(M, I.children[N]) : I.appendChild(M);
}, appendChildView = (I, M) => (N, V) => (typeof V < "u" ? M.splice(V, 0, N) : M.push(N), N), removeChildView = (I, M) => (N) => (M.splice(M.indexOf(N), 1), N.element.parentNode && I.removeChild(N.element), N), IS_BROWSER = typeof window < "u" && typeof window.document < "u", isBrowser$3 = () => IS_BROWSER, testElement = isBrowser$3() ? createElement$1("svg") : {}, getChildCount = "children" in testElement ? (I) => I.children.length : (I) => I.childNodes.length, getViewRect = (I, M, N, V) => {
const U = N[0] || I.left, j = N[1] || I.top, J = U + I.width, ne = j + I.height * (V[1] || 1), se = {
// the rectangle of the element itself
element: {
...I
},
// the rectangle of the element expanded to contain its children, does not include any margins
inner: {
left: I.left,
top: I.top,
right: I.right,
bottom: I.bottom
},
// the rectangle of the element expanded to contain its children including own margin and child margins
// margins will be added after we've recalculated the size
outer: {
left: U,
top: j,
right: J,
bottom: ne
}
};
return M.filter((ve) => !ve.isRectIgnored()).map((ve) => ve.rect).forEach((ve) => {
expandRect(se.inner, { ...ve.inner }), expandRect(se.outer, { ...ve.outer });
}), calculateRectSize(se.inner), se.outer.bottom += se.element.marginBottom, se.outer.right += se.element.marginRight, calculateRectSize(se.outer), se;
}, expandRect = (I, M) => {
M.top += I.top, M.right += I.left, M.bottom += I.top, M.left += I.left, M.bottom > I.bottom && (I.bottom = M.bottom), M.right > I.right && (I.right = M.right);
}, calculateRectSize = (I) => {
I.width = I.right - I.left, I.height = I.bottom - I.top;
}, isNumber$2 = (I) => typeof I == "number", thereYet = (I, M, N, V = 1e-3) => Math.abs(I - M) < V && Math.abs(N) < V, spring$1 = (
// default options
({ stiffness: I = 0.5, damping: M = 0.75, mass: N = 10 } = {}) => {
let V = null, U = null, j = 0, J = !1;
const ve = createObject({
interpolate: (Ee, Ie) => {
if (J) return;
if (!(isNumber$2(V) && isNumber$2(U))) {
J = !0, j = 0;
return;
}
const Ue = -(U - V) * I;
j += Ue / N, U += j, j *= M, thereYet(U, V, j) || Ie ? (U = V, j = 0, J = !0, ve.onupdate(U), ve.oncomplete(U)) : ve.onupdate(U);
},
target: {
set: (Ee) => {
if (isNumber$2(Ee) && !isNumber$2(U) && (U = Ee), V === null && (V = Ee, U = Ee), V = Ee, U === V || typeof V > "u") {
J = !0, j = 0, ve.onupdate(U), ve.oncomplete(U);
return;
}
J = !1;
},
get: () => V
},
resting: {
get: () => J
},
onupdate: (Ee) => {
},
oncomplete: (Ee) => {
}
});
return ve;
}
), easeInOutQuad = (I) => I < 0.5 ? 2 * I * I : -1 + (4 - 2 * I) * I, tween = (
// default values
({ duration: I = 500, easing: M = easeInOutQuad, delay: N = 0 } = {}) => {
let V = null, U, j, J = !0, ne = !1, se = null;
const Ee = createObject({
interpolate: (Ie, Ue) => {
J || se === null || (V === null && (V = Ie), !(Ie - V < N) && (U = Ie - V - N, U >= I || Ue ? (U = 1, j = ne ? 0 : 1, Ee.onupdate(j * se), Ee.oncomplete(j * se), J = !0) : (j = U / I, Ee.onupdate((U >= 0 ? M(ne ? 1 - j : j) : 0) * se))));
},
target: {
get: () => ne ? 0 : se,
set: (Ie) => {
if (se === null) {
se = Ie, Ee.onupdate(Ie), Ee.oncomplete(Ie);
return;
}
Ie < se ? (se = 1, ne = !0) : (ne = !1, se = Ie), J = !1, V = null;
}
},
resting: {
get: () => J
},
onupdate: (Ie) => {
},
oncomplete: (Ie) => {
}
});
return Ee;
}
), animator = {
spring: spring$1,
tween
}, createAnimator = (I, M, N) => {
const V = I[M] && typeof I[M][N] == "object" ? I[M][N] : I[M] || I, U = typeof V == "string" ? V : V.type, j = typeof V == "object" ? { ...V } : {};
return animator[U] ? animator[U](j) : null;
}, addGetSet = (I, M, N, V = !1) => {
M = Array.isArray(M) ? M : [M], M.forEach((U) => {
I.forEach((j) => {
let J = j, ne = () => N[j], se = (ve) => N[j] = ve;
typeof j == "object" && (J = j.key, ne = j.getter || ne, se = j.setter || se), !(U[J] && !V) && (U[J] = {
get: ne,
set: se
});
});
});
}, animations = ({ mixinConfig: I, viewProps: M, viewInternalAPI: N, viewExternalAPI: V }) => {
const U = { ...M }, j = [];
return forin(I, (J, ne) => {
const se = createAnimator(ne);
if (!se)
return;
se.onupdate = (Ee) => {
M[J] = Ee;
}, se.target = U[J], addGetSet([{
key: J,
setter: (Ee) => {
se.target !== Ee && (se.target = Ee);
},
getter: () => M[J]
}], [N, V], M, !0), j.push(se);
}), {
write: (J) => {
let ne = document.hidden, se = !0;
return j.forEach((ve) => {
ve.resting || (se = !1), ve.interpolate(J, ne);
}), se;
},
destroy: () => {
}
};
}, addEvent = (I) => (M, N) => {
I.addEventListener(M, N);
}, removeEvent = (I) => (M, N) => {
I.removeEventListener(M, N);
}, listeners = ({
mixinConfig: I,
viewProps: M,
viewInternalAPI: N,
viewExternalAPI: V,
viewState: U,
view: j
}) => {
const J = [], ne = addEvent(j.element), se = removeEvent(j.element);
return V.on = (ve, Ee) => {
J.push({
type: ve,
fn: Ee
}), ne(ve, Ee);
}, V.off = (ve, Ee) => {
J.splice(J.findIndex((Ie) => Ie.type === ve && Ie.fn === Ee), 1), se(ve, Ee);
}, {
write: () => !0,
destroy: () => {
J.forEach((ve) => {
se(ve.type, ve.fn);
});
}
};
}, apis = ({ mixinConfig: I, viewProps: M, viewExternalAPI: N }) => {
addGetSet(I, N, M);
}, isDefined = (I) => I != null, defaults$2 = {
opacity: 1,
scaleX: 1,
scaleY: 1,
translateX: 0,
translateY: 0,
rotateX: 0,
rotateY: 0,
rotateZ: 0,
originX: 0,
originY: 0
}, styles = ({ mixinConfig: I, viewProps: M, viewInternalAPI: N, viewExternalAPI: V, view: U }) => {
const j = { ...M }, J = {};
addGetSet(I, [N, V], M);
const ne = () => [M.translateX || 0, M.translateY || 0], se = () => [M.scaleX || 0, M.scaleY || 0], ve = () => U.rect ? getViewRect(U.rect, U.childViews, ne(), se()) : null;
return N.rect = { get: ve }, V.rect = { get: ve }, I.forEach((Ee) => {
M[Ee] = typeof j[Ee] > "u" ? defaults$2[Ee] : j[Ee];
}), {
write: () => {
if (propsHaveChanged(J, M))
return applyStyles(U.element, M), Object.assign(J, { ...M }), !0;
},
destroy: () => {
}
};
}, propsHaveChanged = (I, M) => {
if (Object.keys(I).length !== Object.keys(M).length)
return !0;
for (const N in M)
if (M[N] !== I[N])
return !0;
return !1;
}, applyStyles = (I, {
opacity: M,
perspective: N,
translateX: V,
translateY: U,
scaleX: j,
scaleY: J,
rotateX: ne,
rotateY: se,
rotateZ: ve,
originX: Ee,
originY: Ie,
width: Ue,
height: Le
}) => {
let ke = "", Fe = "";
(isDefined(Ee) || isDefined(Ie)) && (Fe += `transform-origin: ${Ee || 0}px ${Ie || 0}px;`), isDefined(N) && (ke += `perspective(${N}px) `), (isDefined(V) || isDefined(U)) && (ke += `translate3d(${V || 0}px, ${U || 0}px, 0) `), (isDefined(j) || isDefined(J)) && (ke += `scale3d(${isDefined(j) ? j : 1}, ${isDefined(J) ? J : 1}, 1) `), isDefined(ve) && (ke += `rotateZ(${ve}rad) `), isDefined(ne) && (ke += `rotateX(${ne}rad) `), isDefined(se) && (ke += `rotateY(${se}rad) `), ke.length && (Fe += `transform:${ke};`), isDefined(M) && (Fe += `opacity:${M};`, M === 0 && (Fe += "visibility:hidden;"), M < 1 && (Fe += "pointer-events:none;")), isDefined(Le) && (Fe += `height:${Le}px;`), isDefined(Ue) && (Fe += `width:${Ue}px;`);
const Je = I.elementCurrentStyle || "";
(Fe.length !== Je.length || Fe !== Je) && (I.style.cssText = Fe, I.elementCurrentStyle = Fe);
}, Mixins = {
styles,
listeners,
animations,
apis
}, updateRect = (I = {}, M = {}, N = {}) => (M.layoutCalculated || (I.paddingTop = parseInt(N.paddingTop, 10) || 0, I.marginTop = parseInt(N.marginTop, 10) || 0, I.marginRight = parseInt(N.marginRight, 10) || 0, I.marginBottom = parseInt(N.marginBottom, 10) || 0, I.marginLeft = parseInt(N.marginLeft, 10) || 0, M.layoutCalculated = !0), I.left = M.offsetLeft || 0, I.top = M.offsetTop || 0, I.width = M.offsetWidth || 0, I.height = M.offsetHeight || 0, I.right = I.left + I.width, I.bottom = I.top + I.height, I.scrollTop = M.scrollTop, I.hidden = M.offsetParent === null, I), createView = (
// default view definition
({
// element definition
tag: I = "div",
name: M = null,
attributes: N = {},
// view interaction
read: V = () => {
},
write: U = () => {
},
create: j = () => {
},
destroy: J = () => {
},
// hooks
filterFrameActionsForChild: ne = (Le, ke) => ke,
didCreateView: se = () => {
},
didWriteView: ve = () => {
},
// rect related
ignoreRect: Ee = !1,
ignoreRectUpdate: Ie = !1,
// mixins
mixins: Ue = []
} = {}) => (Le, ke = {}) => {
const Fe = createElement$1(I, `filepond--${M}`, N), Je = window.getComputedStyle(Fe, null), Qe = updateRect();
let $e = null, Ke = !1;
const It = [], Mt = [], Bt = {}, Wt = {}, Ft = [
U
// default writer
], Vt = [
V
// default reader
], Kt = [
J
// default destroy
], Qt = () => Fe, qt = () => It.concat(), Yt = () => Bt, Zt = (Cn) => (Sn, er) => Sn(Cn, er), Nt = () => $e || ($e = getViewRect(Qe, It, [0, 0], [1, 1]), $e), en = () => Je, tn = () => {
$e = null, It.forEach((er) => er._read()), !(Ie && Qe.width && Qe.height) && updateRect(Qe, Fe, Je);
const Sn = { root: kn, props: ke, rect: Qe };
Vt.forEach((er) => er(Sn));
}, nn = (Cn, Sn, er) => {
let hr = Sn.length === 0;
return Ft.forEach((Jn) => {
Jn({
props: ke,
root: kn,
actions: Sn,
timestamp: Cn,
shouldOptimize: er
}) === !1 && (hr = !1);
}), Mt.forEach((Jn) => {
Jn.write(Cn) === !1 && (hr = !1);
}), It.filter((Jn) => !!Jn.element.parentNode).forEach((Jn) => {
Jn._write(
Cn,
ne(Jn, Sn),
er
) || (hr = !1);
}), It.forEach((Jn, wr) => {
Jn.element.parentNode || (kn.appendChild(Jn.element, wr), Jn._read(), Jn._write(
Cn,
ne(Jn, Sn),
er
), hr = !1);
}), Ke = hr, ve({
props: ke,
root: kn,
actions: Sn,
timestamp: Cn
}), hr;
}, gn = () => {
Mt.forEach((Cn) => Cn.destroy()), Kt.forEach((Cn) => {
Cn({ root: kn, props: ke });
}), It.forEach((Cn) => Cn._destroy());
}, Gn = {
element: {
get: Qt
},
style: {
get: en
},
childViews: {
get: qt
}
}, An = {
...Gn,
rect: {
get: Nt
},
// access to custom children references
ref: {
get: Yt
},
// dom modifiers
is: (Cn) => M === Cn,
appendChild: appendChild(Fe),
createChildView: Zt(Le),
linkView: (Cn) => (It.push(Cn), Cn),
unlinkView: (Cn) => {
It.splice(It.indexOf(Cn), 1);
},
appendChildView: appendChildView(Fe, It),
removeChildView: removeChildView(Fe, It),
registerWriter: (Cn) => Ft.push(Cn),
registerReader: (Cn) => Vt.push(Cn),
registerDestroyer: (Cn) => Kt.push(Cn),
invalidateLayout: () => Fe.layoutCalculated = !1,
// access to data store
dispatch: Le.dispatch,
query: Le.query
}, Ln = {
element: {
get: Qt
},
childViews: {
get: qt
},
rect: {
get: Nt
},
resting: {
get: () => Ke
},
isRectIgnored: () => Ee,
_read: tn,
_write: nn,
_destroy: gn
}, or = {
...Gn,
rect: {
get: () => Qe
}
};
Object.keys(Ue).sort((Cn, Sn) => Cn === "styles" ? 1 : Sn === "styles" ? -1 : 0).forEach((Cn) => {
const Sn = Mixins[Cn]({
mixinConfig: Ue[Cn],
viewProps: ke,
viewState: Wt,
viewInternalAPI: An,
viewExternalAPI: Ln,
view: createObject(or)
});
Sn && Mt.push(Sn);
});
const kn = createObject(An);
j({
root: kn,
props: ke
});
const vn = getChildCount(Fe);
return It.forEach((Cn, Sn) => {
kn.appendChild(Cn.element, vn + Sn);
}), se(kn), createObject(Ln);
}
), createPainter = (I, M, N = 60) => {
const V = "__framePainter";
if (window[V]) {
window[V].readers.push(I), window[V].writers.push(M);
return;
}
window[V] = {
readers: [I],
writers: [M]
};
const U = window[V], j = 1e3 / N;
let J = null, ne = null, se = null, ve = null;
const Ee = () => {
document.hidden ? (se = () => window.setTimeout(() => Ie(performance.now()), j), ve = () => window.clearTimeout(ne)) : (se = () => window.requestAnimationFrame(Ie), ve = () => window.cancelAnimationFrame(ne));
};
document.addEventListener("visibilitychange", () => {
ve && ve(), Ee(), Ie(performance.now());
});
const Ie = (Ue) => {
ne = se(Ie), J || (J = Ue);
const Le = Ue - J;
Le <= j || (J = Ue - Le % j, U.readers.forEach((ke) => ke()), U.writers.forEach((ke) => ke(Ue)));
};
return Ee(), Ie(performance.now()), {
pause: () => {
ve(ne);
}
};
}, createRoute = (I, M) => ({ root: N, props: V, actions: U = [], timestamp: j, shouldOptimize: J }) => {
U.filter((ne) => I[ne.type]).forEach(
(ne) => I[ne.type]({ root: N, props: V, action: ne.data, timestamp: j, shouldOptimize: J })
), M && M({ root: N, props: V, actions: U, timestamp: j, shouldOptimize: J });
}, insertBefore = (I, M) => M.parentNode.insertBefore(I, M), insertAfter = (I, M) => M.parentNode.insertBefore(I, M.nextSibling), isArray$3 = (I) => Array.isArray(I), isEmpty = (I) => I == null, trim = (I) => I.trim(), toString$2 = (I) => "" + I, toArray$1 = (I, M = ",") => isEmpty(I) ? [] : isArray$3(I) ? I : toString$2(I).split(M).map(trim).filter((N) => N.length), isBoolean = (I) => typeof I == "boolean", toBoolean = (I) => isBoolean(I) ? I : I === "true", isString$4 = (I) => typeof I == "string", toNumber$1 = (I) => isNumber$2(I) ? I : isString$4(I) ? toString$2(I).replace(/[a-z]+/gi, "") : 0, toInt$1 = (I) => parseInt(toNumber$1(I), 10), toFloat = (I) => parseFloat(toNumber$1(I)), isInt = (I) => isNumber$2(I) && isFinite(I) && Math.floor(I) === I, toBytes = (I, M = 1e3) => {
if (isInt(I))
return I;
let N = toString$2(I).trim();
return /MB$/i.test(N) ? (N = N.replace(/MB$i/, "").trim(), toInt$1(N) * M * M) : /KB/i.test(N) ? (N = N.replace(/KB$i/, "").trim(), toInt$1(N) * M) : toInt$1(N);
}, isFunction$3 = (I) => typeof I == "function", toFunctionReference = (I) => {
let M = self, N = I.split("."), V = null;
for (; V = N.shift(); )
if (M = M[V], !M)
return null;
return M;
}, methods = {
process: "POST",
patch: "PATCH",
revert: "DELETE",
fetch: "GET",
restore: "GET",
load: "GET"
}, createServerAPI = (I) => {
const M = {};
return M.url = isString$4(I) ? I : I.url || "", M.timeout = I.timeout ? parseInt(I.timeout, 10) : 0, M.headers = I.headers ? I.headers : {}, forin(methods, (N) => {
M[N] = createAction(N, I[N], methods[N], M.timeout, M.headers);
}), M.process = I.process || isString$4(I) || I.url ? M.process : null, M.remove = I.remove || null, delete M.headers, M;
}, createAction = (I, M, N, V, U) => {
if (M === null)
return null;
if (typeof M == "function")
return M;
const j = {
url: N === "GET" || N === "PATCH" ? `?${I}=` : "",
method: N,
headers: U,
withCredentials: !1,
timeout: V,
onload: null,
ondata: null,
onerror: null
};
if (isString$4(M))
return j.url = M, j;
if (Object.assign(j, M), isString$4(j.headers)) {
const J = j.headers.split(/:(.+)/);
j.headers = {
header: J[0],
value: J[1]
};
}
return j.withCredentials = toBoolean(j.withCredentials), j;
}, toServerAPI = (I) => createServerAPI(I), isNull = (I) => I === null, isObject$6 = (I) => typeof I == "object" && I !== null, isAPI = (I) => isObject$6(I) && isString$4(I.url) && isObject$6(I.process) && isObject$6(I.revert) && isObject$6(I.restore) && isObject$6(I.fetch), getType = (I) => isArray$3(I) ? "array" : isNull(I) ? "null" : isInt(I) ? "int" : /^[0-9]+ ?(?:GB|MB|KB)$/gi.test(I) ? "bytes" : isAPI(I) ? "api" : typeof I, replaceSingleQuotes = (I) => I.replace(/{\s*'/g, '{"').replace(/'\s*}/g, '"}').replace(/'\s*:/g, '":').replace(/:\s*'/g, ':"').replace(/,\s*'/g, ',"').replace(/'\s*,/g, '",'), conversionTable = {
array: toArray$1,
boolean: toBoolean,
int: (I) => getType(I) === "bytes" ? toBytes(I) : toInt$1(I),
number: toFloat,
float: toFloat,
bytes: toBytes,
string: (I) => isFunction$3(I) ? I : toString$2(I),
function: (I) => toFunctionReference(I),
serverapi: toServerAPI,
object: (I) => {
try {
return JSON.parse(replaceSingleQuotes(I));
} catch {
return null;
}
}
}, convertTo = (I, M) => conversionTable[M](I), getValueByType = (I, M, N) => {
if (I === M)
return I;
let V = getType(I);
if (V !== N) {
const U = convertTo(I, N);
if (V = getType(U), U === null)
throw `Trying to assign value with incorrect type to "${option}", allowed type: "${N}"`;
I = U;
}
return I;
}, createOption = (I, M) => {
let N = I;
return {
enumerable: !0,
get: () => N,
set: (V) => {
N = getValueByType(V, I, M);
}
};
}, createOptions = (I) => {
const M = {};
return forin(I, (N) => {
const V = I[N];
M[N] = createOption(V[0], V[1]);
}), createObject(M);
}, createInitialState = (I) => ({
// model
items: [],
// timeout used for calling update items
listUpdateTimeout: null,
// timeout used for stacking metadata updates
itemUpdateTimeout: null,
// queue of items waiting to be processed
processingQueue: [],
// options
options: createOptions(I)
}), fromCamels = (I, M = "-") => I.split(/(?=[A-Z])/).map((N) => N.toLowerCase()).join(M), createOptionAPI = (I, M) => {
const N = {};
return forin(M, (V) => {
N[V] = {
get: () => I.getState().options[V],
set: (U) => {
I.dispatch(`SET_${fromCamels(V, "_").toUpperCase()}`, {
value: U
});
}
};
}), N;
}, createOptionActions = (I) => (M, N, V) => {
const U = {};
return forin(I, (j) => {
const J = fromCamels(j, "_").toUpperCase();
U[`SET_${J}`] = (ne) => {
try {
V.options[j] = ne.value;
} catch {
}
M(`DID_SET_${J}`, { value: V.options[j] });
};
}), U;
}, createOptionQueries = (I) => (M) => {
const N = {};
return forin(I, (V) => {
N[`GET_${fromCamels(V, "_").toUpperCase()}`] = (U) => M.options[V];
}), N;
}, InteractionMethod = {
API: 1,
DROP: 2,
BROWSE: 3,
PASTE: 4,
NONE: 5
}, getUniqueId$1 = () => Math.random().toString(36).substring(2, 11), arrayRemove$1 = (I, M) => I.splice(M, 1), run$1 = (I, M) => {
M ? I() : document.hidden ? Promise.resolve(1).then(I) : setTimeout(I, 0);
}, on = () => {
const I = [], M = (V, U) => {
arrayRemove$1(
I,
I.findIndex((j) => j.event === V && (j.cb === U || !U))
);
}, N = (V, U, j) => {
I.filter((J) => J.event === V).map((J) => J.cb).forEach((J) => run$1(() => J(...U), j));
};
return {
fireSync: (V, ...U) => {
N(V, U, !0);
},
fire: (V, ...U) => {
N(V, U, !1);
},
on: (V, U) => {
I.push({ event: V, cb: U });
},
onOnce: (V, U) => {
I.push({
event: V,
cb: (...j) => {
M(V, U), U(...j);
}
});
},
off: M
};
}, copyObjectPropertiesToObject = (I, M, N) => {
Object.getOwnPropertyNames(I).filter((V) => !N.includes(V)).forEach(
(V) => Object.defineProperty(M, V, Object.getOwnPropertyDescriptor(I, V))
);
}, PRIVATE = [
"fire",
"process",
"revert",
"load",
"on",
"off",
"onOnce",
"retryLoad",
"extend",
"archive",
"archived",
"release",
"released",
"requestProcessing",
"freeze"
], createItemAPI = (I) => {
const M = {};
return copyObjectPropertiesToObject(I, M, PRIVATE), M;
}, removeReleasedItems = (I) => {
I.forEach((M, N) => {
M.released && arrayRemove$1(I, N);
});
}, ItemStatus = {
INIT: 1,
IDLE: 2,
PROCESSING_QUEUED: 9,
PROCESSING: 3,
PROCESSING_COMPLETE: 5,
PROCESSING_ERROR: 6,
PROCESSING_REVERT_ERROR: 10,
LOADING: 7,
LOAD_ERROR: 8
}, FileOrigin = {
INPUT: 1,
LIMBO: 2,
LOCAL: 3
}, getNonNumeric = (I) => /[^0-9]+/.exec(I), getDecimalSeparator = () => getNonNumeric(1.1.toLocaleString())[0], getThousandsSeparator = () => {
const I = getDecimalSeparator(), M = 1e3.toLocaleString();
return M !== "1000" ? getNonNumeric(M)[0] : I === "." ? "," : ".";
}, Type = {
BOOLEAN: "boolean",
INT: "int",
NUMBER: "number",
STRING: "string",
ARRAY: "array",
OBJECT: "object",
FUNCTION: "function",
ACTION: "action",
SERVER_API: "serverapi",
REGEX: "regex"
}, filters = [], applyFilterChain = (I, M, N) => new Promise((V, U) => {
const j = filters.filter((ne) => ne.key === I).map((ne) => ne.cb);
if (j.length === 0) {
V(M);
return;
}
const J = j.shift();
j.reduce(
// loop over promises passing value to next promise
(ne, se) => ne.then((ve) => se(ve, N)),
// call initial filter, will return a promise
J(M, N)
// all executed
).then((ne) => V(ne)).catch((ne) => U(ne));
}), applyFilters = (I, M, N) => filters.filter((V) => V.key === I).map((V) => V.cb(M, N)), addFilter = (I, M) => filters.push({ key: I, cb: M }), extendDefaultOptions = (I) => Object.assign(defaultOptions, I), getOptions = () => ({ ...defaultOptions }), setOptions = (I) => {
forin(I, (M, N) => {
defaultOptions[M] && (defaultOptions[M][0] = getValueByType(
N,
defaultOptions[M][0],
defaultOptions[M][1]
));
});
}, defaultOptions = {
// the id to add to the root element
id: [null, Type.STRING],
// input field name to use
name: ["filepond", Type.STRING],
// disable the field
disabled: [!1, Type.BOOLEAN],
// classname to put on wrapper
className: [null, Type.STRING],
// is the field required
required: [!1, Type.BOOLEAN],
// Allow media capture when value is set
captureMethod: [null, Type.STRING],
// - "camera", "microphone" or "camcorder",
// - Does not work with multiple on apple devices
// - If set, acceptedFileTypes must be made to match with media wildcard "image/*", "audio/*" or "video/*"
// sync `acceptedFileTypes` property with `accept` attribute
allowSyncAcceptAttribute: [!0, Type.BOOLEAN],
// Feature toggles
allowDrop: [!0, Type.BOOLEAN],
// Allow dropping of files
allowBrowse: [!0, Type.BOOLEAN],
// Allow browsing the file system
allowPaste: [!0, Type.BOOLEAN],
// Allow pasting files
allowMultiple: [!1, Type.BOOLEAN],
// Allow multiple files (disabled by default, as multiple attribute is also required on input to allow multiple)
allowReplace: [!0, Type.BOOLEAN],
// Allow dropping a file on other file to replace it (only works when multiple is set to false)
allowRevert: [!0, Type.BOOLEAN],
// Allows user to revert file upload
allowRemove: [!0, Type.BOOLEAN],
// Allow user to remove a file
allowProcess: [!0, Type.BOOLEAN],
// Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [!1, Type.BOOLEAN],
// Allow reordering of files
allowDirectoriesOnly: [!1, Type.BOOLEAN],
// Allow only selecting directories with browse (no support for filtering dnd at this point)
// Try store file if `server` not set
storeAsFile: [!1, Type.BOOLEAN],
// Revert mode
forceRevert: [!1, Type.BOOLEAN],
// Set to 'force' to require the file to be reverted before removal
// Input requirements
maxFiles: [null, Type.INT],
// Max number of files
checkValidity: [!1, Type.BOOLEAN],
// Enables custom validity messages
// Where to put file
itemInsertLocationFreedom: [!0, Type.BOOLEAN],
// Set to false to always add items to begin or end of list
itemInsertLocation: ["before", Type.STRING],
// Default index in list to add items that have been dropped at the top of the list
itemInsertInterval: [75, Type.INT],
// Drag 'n Drop related
dropOnPage: [!1, Type.BOOLEAN],
// Allow dropping of files anywhere on page (prevents browser from opening file if dropped outside of Up)
dropOnElement: [!0, Type.BOOLEAN],
// Drop needs to happen on element (set to false to also load drops outside of Up)
dropValidation: [!1, Type.BOOLEAN],
// Enable or disable validating files on drop
ignoredFiles: [[".ds_store", "thumbs.db", "desktop.ini"], Type.ARRAY],
// Upload related
instantUpload: [!0, Type.BOOLEAN],
// Should upload files immediately on drop
maxParallelUploads: [2, Type.INT],
// Maximum files to upload in parallel
allowMinimumUploadDuration: [!0, Type.BOOLEAN],
// if true uploads take at least 750 ms, this ensures the user sees the upload progress giving trust the upload actually happened
// Chunks
chunkUploads: [!1, Type.BOOLEAN],
// Enable chunked uploads
chunkForce: [!1, Type.BOOLEAN],
// Force use of chunk uploads even for files smaller than chunk size
chunkSize: [5e6, Type.INT],
// Size of chunks (5MB default)
chunkRetryDelays: [[500, 1e3, 3e3], Type.ARRAY],
// Amount of times to retry upload of a chunk when it fails
// The server api end points to use for uploading (see docs)
server: [null, Type.SERVER_API],
// File size calculations, can set to 1024, this is only used for display, properties use file size base 1000
fileSizeBase: [1e3, Type.INT],
// Labels and status messages
labelFileSizeBytes: ["bytes", Type.STRING],
labelFileSizeKilobytes: ["KB", Type.STRING],
labelFileSizeMegabytes: ["MB", Type.STRING],
labelFileSizeGigabytes: ["GB", Type.STRING],
labelDecimalSeparator: [getDecimalSeparator(), Type.STRING],
// Default is locale separator
labelThousandsSeparator: [getThousandsSeparator(), Type.STRING],
// Default is locale separator
labelIdle: [
'Drag & Drop your files or <span class="filepond--label-action">Browse</span>',
Type.STRING
],
labelInvalidField: ["Field contains invalid files", Type.STRING],
labelFileWaitingForSize: ["Waiting for size", Type.STRING],
labelFileSizeNotAvailable: ["Size not available", Type.STRING],
labelFileCountSingular: ["file in list", Type.STRING],
labelFileCountPlural: ["files in list", Type.STRING],
labelFileLoading: ["Loading", Type.STRING],
labelFileAdded: ["Added", Type.STRING],
// assistive only
labelFileLoadError: ["Error during load", Type.STRING],
labelFileRemoved: ["Removed", Type.STRING],
// assistive only
labelFileRemoveError: ["Error during remove", Type.STRING],
labelFileProcessing: ["Uploading", Type.STRING],
labelFileProcessingComplete: ["Upload complete", Type.STRING],
labelFileProcessingAborted: ["Upload cancelled", Type.STRING],
labelFileProcessingError: ["Error during upload", Type.STRING],
labelFileProcessingRevertError: ["Error during revert", Type.STRING],
labelTapToCancel: ["tap to cancel", Type.STRING],
labelTapToRetry: ["tap to retry", Type.STRING],
labelTapToUndo: ["tap to undo", Type.STRING],
labelButtonRemoveItem: ["Remove", Type.STRING],
labelButtonAbortItemLoad: ["Abort", Type.STRING],
labelButtonRetryItemLoad: ["Retry", Type.STRING],
labelButtonAbortItemProcessing: ["Cancel", Type.STRING],
labelButtonUndoItemProcessing: ["Undo", Type.STRING],
labelButtonRetryItemProcessing: ["Retry", Type.STRING],
labelButtonProcessItem: ["Upload", Type.STRING],
// make sure width and height plus viewpox are even numbers so icons are nicely centered
iconRemove: [
'<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path d="M11.586 13l-2.293 2.293a1 1 0 0 0 1.414 1.414L13 14.414l2.293 2.293a1 1 0 0 0 1.414-1.414L14.414 13l2.293-2.293a1 1 0 0 0-1.414-1.414L13 11.586l-2.293-2.293a1 1 0 0 0-1.414 1.414L11.586 13z" fill="currentColor" fill-rule="nonzero"/></svg>',
Type.STRING
],
iconProcess: [
'<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path d="M14 10.414v3.585a1 1 0 0 1-2 0v-3.585l-1.293 1.293a1 1 0 0 1-1.414-1.415l3-3a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1-1.414 1.415L14 10.414zM9 18a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2H9z" fill="currentColor" fill-rule="evenodd"/></svg>',
Type.STRING
],
iconRetry: [
'<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path d="M10.81 9.185l-.038.02A4.997 4.997 0 0 0 8 13.683a5 5 0 0 0 5 5 5 5 0 0 0 5-5 1 1 0 0 1 2 0A7 7 0 1 1 9.722 7.496l-.842-.21a.999.999 0 1 1 .484-1.94l3.23.806c.535.133.86.675.73 1.21l-.804 3.233a.997.997 0 0 1-1.21.73.997.997 0 0 1-.73-1.21l.23-.928v-.002z" fill="currentColor" fill-rule="nonzero"/></svg>',
Type.STRING
],
iconUndo: [
'<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path d="M9.185 10.81l.02-.038A4.997 4.997 0 0 1 13.683 8a5 5 0 0 1 5 5 5 5 0 0 1-5 5 1 1 0 0 0 0 2A7 7 0 1 0 7.496 9.722l-.21-.842a.999.999 0 1 0-1.94.484l.806 3.23c.133.535.675.86 1.21.73l3.233-.803a.997.997 0 0 0 .73-1.21.997.997 0 0 0-1.21-.73l-.928.23-.002-.001z" fill="currentColor" fill-rule="nonzero"/></svg>',
Type.STRING
],
iconDone: [
'<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path d="M18.293 9.293a1 1 0 0 1 1.414 1.414l-7.002 7a1 1 0 0 1-1.414 0l-3.998-4a1 1 0 1 1 1.414-1.414L12 15.586l6.294-6.293z" fill="currentColor" fill-rule="nonzero"/></svg>',
Type.STRING
],
// event handlers
oninit: [null, Type.FUNCTION],
onwarning: [null, Type.FUNCTION],
onerror: [null, Type.FUNCTION],
onactivatefile: [null, Type.FUNCTION],
oninitfile: [null, Type.FUNCTION],
onaddfilestart: [null, Type.FUNCTION],
onaddfileprogress: [null, Type.FUNCTION],
onaddfile: [null, Type.FUNCTION],
onprocessfilestart: [null, Type.FUNCTION],
onprocessfileprogress: [null, Type.FUNCTION],
onprocessfileabort: [null, Type.FUNCTION],
onprocessfilerevert: [null, Type.FUNCTION],
onprocessfile: [null, Type.FUNCTION],
onprocessfiles: [null, Type.FUNCTION],
onremovefile: [null, Type.FUNCTION],
onpreparefile: [null, Type.FUNCTION],
onupdatefiles: [null, Type.FUNCTION],
onreorderfiles: [null, Type.FUNCTION],
// hooks
beforeDropFile: [null, Type.FUNCTION],
beforeAddFile: [null, Type.FUNCTION],
beforeRemoveFile: [null, Type.FUNCTION],
beforePrepareFile: [null, Type.FUNCTION],
// styles
stylePanelLayout: [null, Type.STRING],
// null 'integrated', 'compact', 'circle'
stylePanelAspectRatio: [null, Type.STRING],
// null or '3:2' or 1
styleItemPanelAspectRatio: [null, Type.STRING],
styleButtonRemoveItemPosition: ["left", Type.STRING],
styleButtonProcessItemPosition: ["right", Type.STRING],
styleLoadIndicatorPosition: ["right", Type.STRING],
styleProgressIndicatorPosition: ["right", Type.STRING],
styleButtonRemoveItemAlign: [!1, Type.BOOLEAN],
// custom initial files array
files: [[], Type.ARRAY],
// show support by displaying credits
credits: [["https://pqina.nl/", "Powered by PQINA"], Type.ARRAY]
}, getItemByQuery = (I, M) => isEmpty(M) ? I[0] || null : isInt(M) ? I[M] || null : (typeof M == "object" && (M = M.id), I.find((N) => N.id === M) || null), getNumericAspectRatioFromString = (I) => {
if (isEmpty(I))
return I;
if (/:/.test(I)) {
const M = I.split(":");
return M[1] / M[0];
}
return parseFloat(I);
}, getActiveItems = (I) => I.filter((M) => !M.archived), Status = {
EMPTY: 0,
IDLE: 1,
// waiting
ERROR: 2,
// a file is in error state
BUSY: 3,
// busy processing or loading
READY: 4
// all files uploaded
};
let res = null;
const canUpdateFileInput = () => {
if (res === null)
try {
const I = new DataTransfer();
I.items.add(new File(["hello world"], "This_Works.txt"));
const M = document.createElement("input");
M.setAttribute("type", "file"), M.files = I.files, res = M.files.length === 1;
} catch {
res = !1;
}
return res;
}, ITEM_ERROR = [
ItemStatus.LOAD_ERROR,
ItemStatus.PROCESSING_ERROR,
ItemStatus.PROCESSING_REVERT_ERROR
], ITEM_BUSY = [
ItemStatus.LOADING,
ItemStatus.PROCESSING,
ItemStatus.PROCESSING_QUEUED,
ItemStatus.INIT
], ITEM_READY = [ItemStatus.PROCESSING_COMPLETE], isItemInErrorState = (I) => ITEM_ERROR.includes(I.status), isItemInBusyState = (I) => ITEM_BUSY.includes(I.status), isItemInReadyState = (I) => ITEM_READY.includes(I.status), isAsync = (I) => isObject$6(I.options.server) && (isObject$6(I.options.server.process) || isFunction$3(I.options.server.process)), queries = (I) => ({
GET_STATUS: () => {
const M = getActiveItems(I.items), { EMPTY: N, ERROR: V, BUSY: U, IDLE: j, READY: J } = Status;
return M.length === 0 ? N : M.some(isItemInErrorState) ? V : M.some(isItemInBusyState) ? U : M.some(isItemInReadyState) ? J : j;
},
GET_ITEM: (M) => getItemByQuery(I.items, M),
GET_ACTIVE_ITEM: (M) => getItemByQuery(getActiveItems(I.items), M),
GET_ACTIVE_ITEMS: () => getActiveItems(I.items),
GET_ITEMS: () => I.items,
GET_ITEM_NAME: (M) => {
const N = getItemByQuery(I.items, M);
return N ? N.filename : null;
},
GET_ITEM_SIZE: (M) => {
const N = getItemByQuery(I.items, M);
return N ? N.fileSize : null;
},
GET_STYLES: () => Object.keys(I.options).filter((M) => /^style/.test(M)).map((M) => ({
name: M,
value: I.options[M]
})),
GET_PANEL_ASPECT_RATIO: () => /circle/.test(I.options.stylePanelLayout) ? 1 : getNumericAspectRatioFromString(I.options.stylePanelAspectRatio),
GET_ITEM_PANEL_ASPECT_RATIO: () => I.options.styleItemPanelAspectRatio,
GET_ITEMS_BY_STATUS: (M) => getActiveItems(I.items).filter((N) => N.status === M),
GET_TOTAL_ITEMS: () => getActiveItems(I.items).length,
SHOULD_UPDATE_FILE_INPUT: () => I.options.storeAsFile && canUpdateFileInput() && !isAsync(I),
IS_ASYNC: () => isAsync(I),
GET_FILE_SIZE_LABELS: (M) => ({
labelBytes: M("GET_LABEL_FILE_SIZE_BYTES") || void 0,
labelKilobytes: M("GET_LABEL_FILE_SIZE_KILOBYTES") || void 0,
labelMegabytes: M("GET_LABEL_FILE_SIZE_MEGABYTES") || void 0,
labelGigabytes: M("GET_LABEL_FILE_SIZE_GIGABYTES") || void 0
})
}), hasRoomForItem = (I) => {
const M = getActiveItems(I.items).length;
if (!I.options.allowMultiple)
return M === 0;
const N = I.options.maxFiles;
return N === null || M < N;
}, limit$1 = (I, M, N) => Math.max(Math.min(N, I), M), arrayInsert = (I, M, N) => I.splice(M, 0, N), insertItem = (I, M, N) => isEmpty(M) ? null : typeof N > "u" ? (I.push(M), M) : (N = limit$1(N, 0, I.length), arrayInsert(I, N, M), M), isBase64DataURI = (I) => /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*)\s*$/i.test(
I
), getFilenameFromURL$1 = (I) => `${I}`.split("/").pop().split("?").shift(), getExtensionFromFilename$1 = (I) => I.split(".").pop(), guesstimateExtension = (I) => {
if (typeof I != "string")
return "";
const M = I.split("/").pop();
return /svg/.test(M) ? "svg" : /zip|compressed/.test(M) ? "zip" : /plain/.test(M) ? "txt" : /msword/.test(M) ? "doc" : /[a-z]+/.test(M) ? M === "jpeg" ? "jpg" : M : "";
}, leftPad = (I, M = "") => (M + I).slice(-M.length), getDateString = (I = /* @__PURE__ */ new Date()) => `${I.getFullYear()}-${leftPad(I.getMonth() + 1, "00")}-${leftPad(
I.getDate(),
"00"
)}_${leftPad(I.getHours(), "00")}-${leftPad(I.getMinutes(), "00")}-${leftPad(
I.getSeconds(),
"00"
)}`, getFileFromBlob = (I, M, N = null, V = null) => {
const U = typeof N == "string" ? I.slice(0, I.size, N) : I.slice(0, I.size, I.type);
return U.lastModifiedDate = /* @__PURE__ */ new Date(), I._relativePath && (U._relativePath = I._relativePath), isString$4(M) || (M = getDateString()), M && V === null && getExtensionFromFilename$1(M) ? U.name = M : (V = V || guesstimateExtension(U.type), U.name = M + (V ? "." + V : "")), U;
}, getBlobBuilder = () => window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder, createBlob = (I, M) => {
const N = getBlobBuilder();
if (N) {
const V = new N();
return V.append(I), V.getBlob(M);
}
return new Blob([I], {
type: M
});
}, getBlobFromByteStringWithMimeType = (I, M) => {
const N = new ArrayBuffer(I.length), V = new Uint8Array(N);
for (let U = 0; U < I.length; U++)
V[U] = I.charCodeAt(U);
return createBlob(N, M);
}, getMimeTypeFromBase64DataURI = (I) => (/^data:(.+);/.exec(I) || [])[1] || null, getBase64DataFromBase64DataURI = (I) => I.split(",")[1].replace(/\s/g, ""), getByteStringFromBase64DataURI = (I) => atob(getBase64DataFromBase64DataURI(I)), getBlobFromBase64DataURI = (I) => {
const M = getMimeTypeFromBase64DataURI(I), N = getByteStringFromBase64DataURI(I);
return getBlobFromByteStringWithMimeType(N, M);
}, getFileFromBase64DataURI = (I, M, N) => getFileFromBlob(getBlobFromBase64DataURI(I), M, null, N), getFileNameFromHeader = (I) => {
if (!/^content-disposition:/i.test(I)) return null;
const M = I.split(/filename=|filename\*=.+''/).splice(1).map((N) => N.trim().replace(/^["']|[;"']{0,2}$/g, "")).filter((N) => N.length);
return M.length ? decodeURI(M[M.length - 1]) : null;
}, getFileSizeFromHeader = (I) => {
if (/content-length:/i.test(I)) {
const M = I.match(/[0-9]+/)[0];
return M ? parseInt(M, 10) : null;
}
return null;
}, getTranfserIdFromHeader = (I) => /x-content-transfer-id:/i.test(I) && (I.split(":")[1] || "").trim() || null, getFileInfoFromHeaders = (I) => {
const M = {
source: null,
name: null,
size: null
}, N = I.split(`
`);
for (let V of N) {
const U = getFileNameFromHeader(V);
if (U) {
M.name = U;
continue;
}
const j = getFileSizeFromHeader(V);
if (j) {
M.size = j;
continue;
}
const J = getTranfserIdFromHeader(V);
if (J) {
M.source = J;
continue;
}
}
return M;
}, createFileLoader = (I) => {
const M = {
source: null,
complete: !1,
progress: 0,
size: null,
timestamp: null,
duration: 0,
request: null
}, N = () => M.progress, V = () => {
M.request && M.request.abort && M.request.abort();
}, U = () => {
const ne = M.source;
J.fire("init", ne), ne instanceof File ? J.fire("load", ne) : ne instanceof Blob ? J.fire("load", getFileFromBlob(ne, ne.name)) : isBase64DataURI(ne) ? J.fire("load", getFileFromBase64DataURI(ne)) : j(ne);
}, j = (ne) => {
if (!I) {
J.fire("error", {
type: "error",
body: "Can't load URL",
code: 400
});
return;
}
M.timestamp = Date.now(), M.request = I(
ne,
(se) => {
M.duration = Date.now() - M.timestamp, M.complete = !0, se instanceof Blob && (se = getFileFromBlob(se, se.name || getFilenameFromURL$1(ne))), J.fire(
"load",
// if has received blob, we go with blob, if no response, we return null
se instanceof Blob ? se : se ? se.body : null
);
},
(se) => {
J.fire(
"error",
typeof se == "string" ? {
type: "error",
code: 0,
body: se
} : se
);
},
(se, ve, Ee) => {
if (Ee && (M.size = Ee), M.duration = Date.now() - M.timestamp, !se) {
M.progress = null;
return;
}
M.progress = ve / Ee, J.fire("progress", M.progress);
},
() => {
J.fire("abort");
},
(se) => {
const ve = getFileInfoFromHeaders(
typeof se == "string" ? se : se.headers
);
J.fire("meta", {
size: M.size || ve.size,
filename: ve.name,
source: ve.source
});
}
);
}, J = {
...on(),
setSource: (ne) => M.source = ne,
getProgress: N,
// file load progress
abort: V,
// abort file load
load: U
// start load
};
return J;
}, isGet = (I) => /GET|HEAD/.test(I), sendRequest = (I, M, N) => {
const V = {
onheaders: () => {
},
onprogress: () => {
},
onload: () => {
},
ontimeout: () => {
},
onerror: () => {
},
onabort: () => {
},
abort: () => {
U = !0, J.abort();
}
};
let U = !1, j = !1;
N = {
method: "POST",
headers: {},
withCredentials: !1,
...N
}, M = encodeURI(M), isGet(N.method) && I && (M = `${M}${encodeURIComponent(typeof I == "string" ? I : JSON.stringify(I))}`);
const J = new XMLHttpRequest(), ne = isGet(N.method) ? J : J.upload;
return ne.onprogress = (se) => {
U || V.onprogress(se.lengthComputable, se.loaded, se.total);
}, J.onreadystatechange = () => {
J.readyState < 2 || J.readyState === 4 && J.status === 0 || j || (j = !0, V.onheaders(J));
}, J.onload = () => {
J.status >= 200 && J.status < 300 ? V.onload(J) : V.onerror(J);
}, J.onerror = () => V.onerror(J), J.onabort = () => {
U = !0, V.onabort();
}, J.ontimeout = () => V.ontimeout(J), J.open(N.method, M, !0), isInt(N.timeout) && (J.timeout = N.timeout), Object.keys(N.headers).forEach((se) => {
const ve = unescape(encodeURIComponent(N.headers[se]));
J.setRequestHeader(se, ve);
}), N.responseType && (J.responseType = N.responseType), N.withCredentials && (J.withCredentials = !0), J.send(I), V;
}, createResponse = (I, M, N, V) => ({
type: I,
code: M,
body: N,
headers: V
}), createTimeoutResponse = (I) => (M) => {
I(createResponse("error", 0, "Timeout", M.getAllResponseHeaders()));
}, hasQS = (I) => /\?/.test(I), buildURL = (...I) => {
let M = "";
return I.forEach((N) => {
M += hasQS(M) && hasQS(N) ? N.replace(/\?/, "&") : N;
}), M;
}, createFetchFunction = (I = "", M) => {
if (typeof M == "function")
return M;
if (!M || !isString$4(M.url))
return null;
const N = M.onload || ((U) => U), V = M.onerror || ((U) => null);
return (U, j, J, ne, se, ve) => {
const Ee = sendRequest(U, buildURL(I, M.url), {
...M,
responseType: "blob"
});
return Ee.onload = (Ie) => {
const Ue = Ie.getAllResponseHeaders(), Le = getFileInfoFromHeaders(Ue).name || getFilenameFromURL$1(U);
j(
createResponse(
"load",
Ie.status,
M.method === "HEAD" ? null : getFileFromBlob(N(Ie.response), Le),
Ue
)
);
}, Ee.onerror = (Ie) => {
J(
createResponse(
"error",
Ie.status,
V(Ie.response) || Ie.statusText,
Ie.getAllResponseHeaders()
)
);
}, Ee.onheaders = (Ie) => {
ve(createResponse("headers", Ie.status, null, Ie.getAllResponseHeaders()));
}, Ee.ontimeout = createTimeoutResponse(J), Ee.onprogress = ne, Ee.onabort = se, Ee;
};
}, ChunkStatus = {
QUEUED: 0,
COMPLETE: 1,
PROCESSING: 2,
ERROR: 3,
WAITING: 4
}, processFileChunked = (I, M, N, V, U, j, J, ne, se, ve, Ee) => {
const Ie = [], { chunkTransferId: Ue, chunkServer: Le, chunkSize: ke, chunkRetryDelays: Fe } = Ee, Je = {
serverId: Ue,
aborted: !1
}, Qe = M.ondata || ((Zt) => Zt), $e = M.onload || ((Zt, Nt) => Nt === "HEAD" ? Zt.getResponseHeader("Upload-Offset") : Zt.response), Ke = M.onerror || ((Zt) => null), It = (Zt) => {
const Nt = new FormData();
isObject$6(U) && Nt.append(N, JSON.stringify(U));
const en = typeof M.headers == "function" ? M.headers(V, U) : {
...M.headers,
"Upload-Length": V.size
}, tn = {
...M,
headers: en
}, nn = sendRequest(Qe(Nt), buildURL(I, M.url), tn);
nn.onload = (gn) => Zt($e(gn, tn.method)), nn.onerror = (gn) => J(
createResponse(
"error",
gn.status,
Ke(gn.response) || gn.statusText,
gn.getAllResponseHeaders()
)
), nn.ontimeout = createTimeoutResponse(J);
}, Mt = (Zt) => {
const Nt = buildURL(I, Le.url, Je.serverId), tn = {
headers: typeof M.headers == "function" ? M.headers(Je.serverId) : {
...M.headers
},
method: "HEAD"
}, nn = sendRequest(null, Nt, tn);
nn.onload = (gn) => Zt($e(gn, tn.method)), nn.onerror = (gn) => J(
createResponse(
"error",
gn.status,
Ke(gn.response) || gn.statusText,
gn.getAllResponseHeaders()
)
), nn.ontimeout = createTimeoutResponse(J);
}, Bt = Math.floor(V.size / ke);
for (let Zt = 0; Zt <= Bt; Zt++) {
const Nt = Zt * ke, en = V.slice(Nt, Nt + ke, "application/offset+octet-stream");
Ie[Zt] = {
index: Zt,
size: en.size,
offset: Nt,
data: en,
file: V,
progress: 0,
retries: [...Fe],
status: ChunkStatus.QUEUED,
error: null,
request: null,
timeout: null
};
}
const Wt = () => j(Je.serverId), Ft = (Zt) => Zt.status === ChunkStatus.QUEUED || Zt.status === ChunkStatus.ERROR, Vt = (Zt) => {
if (Je.aborted) return;
if (Zt = Zt || Ie.find(Ft), !Zt) {
Ie.every((An) => An.status === ChunkStatus.COMPLETE) && Wt();
return;
}
Zt.status = ChunkStatus.PROCESSING, Zt.progress = null;
const Nt = Le.ondata || ((An) => An), en = Le.onerror || ((An) => null), tn = Le.onload || (() => {
}), nn = buildURL(I, Le.url, Je.serverId), gn = typeof Le.headers == "function" ? Le.headers(Zt) : {
...Le.headers,
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": Zt.offset,
"Upload-Length": V.size,
"Upload-Name": V.name
}, Gn = Zt.request = sendRequest(Nt(Zt.data), nn, {
...Le,
headers: gn
});
Gn.onload = (An) => {
tn(An, Zt.index, Ie.length), Zt.status = ChunkStatus.COMPLETE, Zt.request = null, qt();
}, Gn.onprogress = (An, Ln, or) => {
Zt.progress = An ? Ln : null, Qt();
}, Gn.onerror = (An) => {
Zt.status = ChunkStatus.ERROR, Zt.request = null, Zt.error = en(An.response) || An.statusText, Kt(Zt) || J(
createResponse(
"error",
An.status,
en(An.response) || An.statusText,
An.getAllResponseHeaders()
)
);
}, Gn.ontimeout = (An) => {
Zt.status = ChunkStatus.ERROR, Zt.request = null, Kt(Zt) || createTimeoutResponse(J)(An);
}, Gn.onabort = () => {
Zt.status = ChunkStatus.QUEUED, Zt.request = null, se();
};
}, Kt = (Zt) => Zt.retries.length === 0 ? !1 : (Zt.status = ChunkStatus.WAITING, clearTimeout(Zt.timeout), Zt.timeout = setTimeout(() => {
Vt(Zt);
}, Zt.retries.shift()), !0), Qt = () => {
const Zt = Ie.reduce((en, tn) => en === null || tn.progress === null ? null : en + tn.progress, 0);
if (Zt === null) return ne(!1, 0, 0);
const Nt = Ie.reduce((en, tn) => en + tn.size, 0);
ne(!0, Zt, Nt);
}, qt = () => {
Ie.filter((Nt) => Nt.status === ChunkStatus.PROCESSING).length >= 1 || Vt();
}, Yt = () => {
Ie.forEach((Zt) => {
clearTimeout(Zt.timeout), Zt.request && Zt.request.abort();
});
};
return Je.serverId ? Mt((Zt) => {
Je.aborted || (Ie.filter((Nt) => Nt.offset < Zt).forEach((Nt) => {
Nt.status = ChunkStatus.COMPLETE, Nt.progress = Nt.size;
}), qt());
}) : It((Zt) => {
Je.aborted || (ve(Zt), Je.serverId = Zt, qt());
}), {
abort: () => {
Je.aborted = !0, Yt();
}
};
}, createFileProcessorFunction = (I, M, N, V) => (U, j, J, ne, se, ve, Ee) => {
if (!U) return;
const Ie = V.chunkUploads, Ue = Ie && U.size > V.chunkSize, Le = Ie && (Ue || V.chunkForce);
if (U instanceof Blob && Le)
return processFileChu