@xuda.io/xuda-widget-plugin-xuda-drive
Version:
Xuda Drive widget plugin
1,338 lines • 2.8 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 Re = [...U];
return U.length = 0, Re;
}, se = () => {
const Re = [...j];
j.length = 0, Re.forEach(({ type: Ue, data: Qe }) => {
ve(Ue, Qe);
});
}, ve = (Re, Ue, Qe) => {
if (Qe && !document.hidden) {
j.push({ type: Re, data: Ue });
return;
}
Fe[Re] && Fe[Re](Ue), U.push({
type: Re,
data: Ue
});
}, Ee = (Re, ...Ue) => Le[Re] ? Le[Re](...Ue) : null, xe = {
getState: J,
processActionQueue: ne,
processDispatchQueue: se,
dispatch: ve,
query: Ee
};
let Le = {};
M.forEach((Re) => {
Le = {
...Re(V),
...Le
};
});
let Fe = {};
return N.forEach((Re) => {
Fe = {
...Re(ve, Ee, V),
...Fe
};
}), xe;
}, 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$5 = () => IS_BROWSER, testElement = isBrowser$5() ? 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, xe) => {
if (J) return;
if (!(isNumber$2(V) && isNumber$2(U))) {
J = !0, j = 0;
return;
}
const Le = -(U - V) * I;
j += Le / N, U += j, j *= M, thereYet(U, V, j) || xe ? (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: (xe, Le) => {
J || se === null || (V === null && (V = xe), !(xe - V < N) && (U = xe - V - N, U >= I || Le ? (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: (xe) => {
if (se === null) {
se = xe, Ee.onupdate(xe), Ee.oncomplete(xe);
return;
}
xe < se ? (se = 1, ne = !0) : (ne = !1, se = xe), J = !1, V = null;
}
},
resting: {
get: () => J
},
onupdate: (xe) => {
},
oncomplete: (xe) => {
}
});
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((xe) => xe.type === ve && xe.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: xe,
width: Le,
height: Fe
}) => {
let Re = "", Ue = "";
(isDefined(Ee) || isDefined(xe)) && (Ue += `transform-origin: ${Ee || 0}px ${xe || 0}px;`), isDefined(N) && (Re += `perspective(${N}px) `), (isDefined(V) || isDefined(U)) && (Re += `translate3d(${V || 0}px, ${U || 0}px, 0) `), (isDefined(j) || isDefined(J)) && (Re += `scale3d(${isDefined(j) ? j : 1}, ${isDefined(J) ? J : 1}, 1) `), isDefined(ve) && (Re += `rotateZ(${ve}rad) `), isDefined(ne) && (Re += `rotateX(${ne}rad) `), isDefined(se) && (Re += `rotateY(${se}rad) `), Re.length && (Ue += `transform:${Re};`), isDefined(M) && (Ue += `opacity:${M};`, M === 0 && (Ue += "visibility:hidden;"), M < 1 && (Ue += "pointer-events:none;")), isDefined(Fe) && (Ue += `height:${Fe}px;`), isDefined(Le) && (Ue += `width:${Le}px;`);
const Qe = I.elementCurrentStyle || "";
(Ue.length !== Qe.length || Ue !== Qe) && (I.style.cssText = Ue, I.elementCurrentStyle = Ue);
}, 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 = (Fe, Re) => Re,
didCreateView: se = () => {
},
didWriteView: ve = () => {
},
// rect related
ignoreRect: Ee = !1,
ignoreRectUpdate: xe = !1,
// mixins
mixins: Le = []
} = {}) => (Fe, Re = {}) => {
const Ue = createElement$1(I, `filepond--${M}`, N), Qe = window.getComputedStyle(Ue, null), Je = updateRect();
let $e = null, Ke = !1;
const It = [], Mt = [], zt = {}, Yt = {}, Nt = [
U
// default writer
], Vt = [
V
// default reader
], Zt = [
J
// default destroy
], Jt = () => Ue, qt = () => It.concat(), Wt = () => zt, Kt = (Wn) => (Nn, pr) => Nn(Wn, pr), Ft = () => $e || ($e = getViewRect(Je, It, [0, 0], [1, 1]), $e), nn = () => Qe, tn = () => {
$e = null, It.forEach((pr) => pr._read()), !(xe && Je.width && Je.height) && updateRect(Je, Ue, Qe);
const Nn = { root: Sn, props: Re, rect: Je };
Vt.forEach((pr) => pr(Nn));
}, en = (Wn, Nn, pr) => {
let mr = Nn.length === 0;
return Nt.forEach(($n) => {
$n({
props: Re,
root: Sn,
actions: Nn,
timestamp: Wn,
shouldOptimize: pr
}) === !1 && (mr = !1);
}), Mt.forEach(($n) => {
$n.write(Wn) === !1 && (mr = !1);
}), It.filter(($n) => !!$n.element.parentNode).forEach(($n) => {
$n._write(
Wn,
ne($n, Nn),
pr
) || (mr = !1);
}), It.forEach(($n, Sr) => {
$n.element.parentNode || (Sn.appendChild($n.element, Sr), $n._read(), $n._write(
Wn,
ne($n, Nn),
pr
), mr = !1);
}), Ke = mr, ve({
props: Re,
root: Sn,
actions: Nn,
timestamp: Wn
}), mr;
}, _n = () => {
Mt.forEach((Wn) => Wn.destroy()), Zt.forEach((Wn) => {
Wn({ root: Sn, props: Re });
}), It.forEach((Wn) => Wn._destroy());
}, Gn = {
element: {
get: Jt
},
style: {
get: nn
},
childViews: {
get: qt
}
}, mn = {
...Gn,
rect: {
get: Ft
},
// access to custom children references
ref: {
get: Wt
},
// dom modifiers
is: (Wn) => M === Wn,
appendChild: appendChild(Ue),
createChildView: Kt(Fe),
linkView: (Wn) => (It.push(Wn), Wn),
unlinkView: (Wn) => {
It.splice(It.indexOf(Wn), 1);
},
appendChildView: appendChildView(Ue, It),
removeChildView: removeChildView(Ue, It),
registerWriter: (Wn) => Nt.push(Wn),
registerReader: (Wn) => Vt.push(Wn),
registerDestroyer: (Wn) => Zt.push(Wn),
invalidateLayout: () => Ue.layoutCalculated = !1,
// access to data store
dispatch: Fe.dispatch,
query: Fe.query
}, En = {
element: {
get: Jt
},
childViews: {
get: qt
},
rect: {
get: Ft
},
resting: {
get: () => Ke
},
isRectIgnored: () => Ee,
_read: tn,
_write: en,
_destroy: _n
}, Hn = {
...Gn,
rect: {
get: () => Je
}
};
Object.keys(Le).sort((Wn, Nn) => Wn === "styles" ? 1 : Nn === "styles" ? -1 : 0).forEach((Wn) => {
const Nn = Mixins[Wn]({
mixinConfig: Le[Wn],
viewProps: Re,
viewState: Yt,
viewInternalAPI: mn,
viewExternalAPI: En,
view: createObject(Hn)
});
Nn && Mt.push(Nn);
});
const Sn = createObject(mn);
j({
root: Sn,
props: Re
});
const kn = getChildCount(Ue);
return It.forEach((Wn, Nn) => {
Sn.appendChild(Wn.element, kn + Nn);
}), se(Sn), createObject(En);
}
), 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(() => xe(performance.now()), j), ve = () => window.clearTimeout(ne)) : (se = () => window.requestAnimationFrame(xe), ve = () => window.cancelAnimationFrame(ne));
};
document.addEventListener("visibilitychange", () => {
ve && ve(), Ee(), xe(performance.now());
});
const xe = (Le) => {
ne = se(xe), J || (J = Le);
const Fe = Le - J;
Fe <= j || (J = Le - Fe % j, U.readers.forEach((Re) => Re()), U.writers.forEach((Re) => Re(Le)));
};
return Ee(), xe(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 = (xe) => {
const Le = xe.getAllResponseHeaders(), Fe = getFileInfoFromHeaders(Le).name || getFilenameFromURL$1(U);
j(
createResponse(
"load",
xe.status,
M.method === "HEAD" ? null : getFileFromBlob(N(xe.response), Fe),
Le
)
);
}, Ee.onerror = (xe) => {
J(
createResponse(
"error",
xe.status,
V(xe.response) || xe.statusText,
xe.getAllResponseHeaders()
)
);
}, Ee.onheaders = (xe) => {
ve(createResponse("headers", xe.status, null, xe.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 xe = [], { chunkTransferId: Le, chunkServer: Fe, chunkSize: Re, chunkRetryDelays: Ue } = Ee, Qe = {
serverId: Le,
aborted: !1
}, Je = M.ondata || ((Kt) => Kt), $e = M.onload || ((Kt, Ft) => Ft === "HEAD" ? Kt.getResponseHeader("Upload-Offset") : Kt.response), Ke = M.onerror || ((Kt) => null), It = (Kt) => {
const Ft = new FormData();
isObject$6(U) && Ft.append(N, JSON.stringify(U));
const nn = typeof M.headers == "function" ? M.headers(V, U) : {
...M.headers,
"Upload-Length": V.size
}, tn = {
...M,
headers: nn
}, en = sendRequest(Je(Ft), buildURL(I, M.url), tn);
en.onload = (_n) => Kt($e(_n, tn.method)), en.onerror = (_n) => J(
createResponse(
"error",
_n.status,
Ke(_n.response) || _n.statusText,
_n.getAllResponseHeaders()
)
), en.ontimeout = createTimeoutResponse(J);
}, Mt = (Kt) => {
const Ft = buildURL(I, Fe.url, Qe.serverId), tn = {
headers: typeof M.headers == "function" ? M.headers(Qe.serverId) : {
...M.headers
},
method: "HEAD"
}, en = sendRequest(null, Ft, tn);
en.onload = (_n) => Kt($e(_n, tn.method)), en.onerror = (_n) => J(
createResponse(
"error",
_n.status,
Ke(_n.response) || _n.statusText,
_n.getAllResponseHeaders()
)
), en.ontimeout = createTimeoutResponse(J);
}, zt = Math.floor(V.size / Re);
for (let Kt = 0; Kt <= zt; Kt++) {
const Ft = Kt * Re, nn = V.slice(Ft, Ft + Re, "application/offset+octet-stream");
xe[Kt] = {
index: Kt,
size: nn.size,
offset: Ft,
data: nn,
file: V,
progress: 0,
retries: [...Ue],
status: ChunkStatus.QUEUED,
error: null,
request: null,
timeout: null
};
}
const Yt = () => j(Qe.serverId), Nt = (Kt) => Kt.status === ChunkStatus.QUEUED || Kt.status === ChunkStatus.ERROR, Vt = (Kt) => {
if (Qe.aborted) return;
if (Kt = Kt || xe.find(Nt), !Kt) {
xe.every((mn) => mn.status === ChunkStatus.COMPLETE) && Yt();
return;
}
Kt.status = ChunkStatus.PROCESSING, Kt.progress = null;
const Ft = Fe.ondata || ((mn) => mn), nn = Fe.onerror || ((mn) => null), tn = Fe.onload || (() => {
}), en = buildURL(I, Fe.url, Qe.serverId), _n = typeof Fe.headers == "function" ? Fe.headers(Kt) : {
...Fe.headers,
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": Kt.offset,
"Upload-Length": V.size,
"Upload-Name": V.name
}, Gn = Kt.request = sendRequest(Ft(Kt.data), en, {
...Fe,
headers: _n
});
Gn.onload = (mn) => {
tn(mn, Kt.index, xe.length), Kt.status = ChunkStatus.COMPLETE, Kt.request = null, qt();
}, Gn.onprogress = (mn, En, Hn) => {
Kt.progress = mn ? En : null, Jt();
}, Gn.onerror = (mn) => {
Kt.status = ChunkStatus.ERROR, Kt.request = null, Kt.error = nn(mn.response) || mn.statusText, Zt(Kt) || J(
createResponse(
"error",
mn.status,
nn(mn.response) || mn.statusText,
mn.getAllResponseHeaders()
)
);
}, Gn.ontimeout = (mn) => {
Kt.status = ChunkStatus.ERROR, Kt.request = null, Zt(Kt) || createTimeoutResponse(J)(mn);
}, Gn.onabort = () => {
Kt.status = ChunkStatus.QUEUED, Kt.request = null, se();
};
}, Zt = (Kt) => Kt.retries.length === 0 ? !1 : (Kt.status = ChunkStatus.WAITING, clearTimeout(Kt.timeout), Kt.timeout = setTimeout(() => {
Vt(Kt);
}, Kt.retries.shift()), !0), Jt = () => {
const Kt = xe.reduce((nn, tn) => nn === null || tn.progress === null ? null : nn + tn.progress, 0);
if (Kt === null) return ne(!1, 0, 0);
const Ft = xe.reduce((nn, tn) => nn + tn.size, 0);
ne(!0, Kt, Ft);
}, qt = () => {
xe.filter((Ft) => Ft.status === ChunkStatus.PROCESSING).length >= 1 || Vt();
}, Wt = () => {
xe.forEach((Kt) => {
clearTimeout(Kt.timeout), Kt.request && Kt.request.abort();
});
};
return Qe.serverId ? Mt((Kt) => {
Qe.aborted || (xe.filter((Ft) => Ft.offset < Kt).forEach((Ft) => {
Ft.status = ChunkStatus.COMPLETE, Ft.progress = Ft.size;
}), qt());
}) : It((Kt) => {
Qe.aborted || (ve(Kt), Qe.serverId = Kt, qt());
}), {
abort: () => {
Qe.aborted = !0, Wt();
}
};
}, createFileProcessorFunction = (I, M, N, V) => (U, j, J, ne, se, ve, Ee) => {
if (!U) return;
const xe = V.chunkUploads, Le = xe && U.size > V.chunkSize, Fe = xe && (Le || V.chunkForce);
if (U instanceof Blob && Fe)
return processFileChu