dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
1,476 lines (1,475 loc) • 199 kB
JavaScript
import { G as Be, l as Ue, u as Ve, a as Ce, d as ue, f as ft, c as ge, R as Kt, _ as Jt, k as en, t as ot, I as tn } from "../../MyInput-qse97Dxt.js";
import { M as Pc, y as Cc, K as bc, b as Nc, L as vc, o as Gc } from "../../MyInput-qse97Dxt.js";
import { M as Fc } from "../../MySelect-U6BUrvYu.js";
import { j as L } from "../../jsx-runtime-C5mzlN2N.js";
import { O as ks, _ as js, u as Xs } from "../../popover-DDxpKohG-BbuLlzlz.js";
import { u as Zs } from "../../check-DE-1lGDl-24KCJ29m.js";
import { n as Qs, G as Ks, L as nn, Z as Js } from "../../timepicker-CVwZY2bQ-6XH6bbfh.js";
import { a as er } from "../../dayjs.min-DQzb66fB.js";
import { m as xe } from "../../utils-D0f6bOsw-HrLsble-.js";
import { c as tr } from "../../createLucideIcon-B950nf2d.js";
import nr, { createElement as sn } from "react";
import { I as Uc, A as Vc, j as Hc, x as Yc, $ as Wc, Q as qc, E as $c, S as zc, K as kc, U as jc, y as Xc } from "../../select-BehdTDP2-BxIxRb2_.js";
/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/
const sr = [
["path", { d: "M8 2v4", key: "1cmpym" }],
["path", { d: "M16 2v4", key: "4m81vk" }],
["rect", { width: "18", height: "18", x: "3", y: "4", rx: "2", key: "1hopcy" }],
["path", { d: "M3 10h18", key: "8toen8" }]
], rr = tr("calendar", sr), Rc = ({
control: e,
name: t,
label: n,
helperText: s,
required: r,
rules: a,
format: i = Qs,
placeholder: l
}) => {
const o = n && /* @__PURE__ */ L.jsxs(ge, { className: "my-3 text-body-xs-medium", children: [
n,
" ",
r && /* @__PURE__ */ L.jsx("span", { className: "text-red-600", children: "*" })
] });
return /* @__PURE__ */ L.jsx(L.Fragment, { children: t && e && /* @__PURE__ */ L.jsx(
Be,
{
control: e,
name: t,
rules: a,
render: ({ field: d, formState: c }) => /* @__PURE__ */ L.jsxs(Ue, { className: "flex flex-col relative", children: [
o,
/* @__PURE__ */ L.jsxs(ks, { children: [
/* @__PURE__ */ L.jsx(js, { asChild: !0, children: /* @__PURE__ */ L.jsx(Ve, { children: /* @__PURE__ */ L.jsxs(
Zs,
{
variant: "secondary",
className: xe(
"pl-3 mb-0 text-left text-secondary !text-body-sm-regular font-normal border-alpha-strong bg-transparent hover:bg-transparent focus:ring-item-primary",
Ce.get(c.errors, `${t}`) && "focus:ring-item-destructive border-item-destructive bg-item-destructive-focus text-item-destructive hover:bg-item-destructive-focus dark:bg-transparent",
d.value && "text-primary"
),
children: [
d.value ? er(d.value).format(i) : l && l,
/* @__PURE__ */ L.jsx(rr, { className: "ml-auto h-4 w-4" })
]
}
) }) }),
/* @__PURE__ */ L.jsx(Xs, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ L.jsx(
Ks,
{
mode: "single",
selected: d.value,
onSelect: (f) => d.onChange(f ? new Date(f) : void 0),
disabled: (f) => f > /* @__PURE__ */ new Date() || f < /* @__PURE__ */ new Date("1900-01-01")
}
) })
] }),
/* @__PURE__ */ L.jsx(ue, { children: s }),
/* @__PURE__ */ L.jsx("div", { className: "relative", children: /* @__PURE__ */ L.jsx(ft, {}) })
] })
}
) });
}, Oc = ({
control: e,
name: t,
label: n,
rules: s,
helperText: r,
...a
}) => t && e ? /* @__PURE__ */ L.jsx(
Be,
{
control: e,
name: t,
rules: s,
render: ({ field: i }) => /* @__PURE__ */ L.jsxs(Ue, { className: "flex flex-row items-start space-x-3", children: [
/* @__PURE__ */ L.jsx(Ve, { children: /* @__PURE__ */ L.jsx(
Kt,
{
checked: i.value,
onCheckedChange: i.onChange,
...a
}
) }),
/* @__PURE__ */ L.jsxs("div", { className: "space-y-1 leading-none", children: [
n && /* @__PURE__ */ L.jsx(ge, { children: n }),
/* @__PURE__ */ L.jsx(ue, { children: r })
] })
] })
}
) : /* @__PURE__ */ L.jsxs("div", { className: "flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4", children: [
/* @__PURE__ */ L.jsx(Kt, { ...a }),
/* @__PURE__ */ L.jsxs("div", { className: "space-y-1 leading-none", children: [
n && /* @__PURE__ */ L.jsx(ge, { children: n }),
/* @__PURE__ */ L.jsx(ue, { children: r })
] })
] }), Sc = ({
control: e,
name: t,
label: n,
helperText: s,
rules: r,
...a
}) => t && e ? /* @__PURE__ */ L.jsx(
Be,
{
control: e,
name: t,
rules: r,
render: ({ field: i }) => /* @__PURE__ */ L.jsxs(Ue, { className: "flex items-center gap-2", children: [
/* @__PURE__ */ L.jsx(Ve, { children: /* @__PURE__ */ L.jsx(
Jt,
{
className: "m-0",
checked: i.value,
onCheckedChange: i.onChange,
...a
}
) }),
/* @__PURE__ */ L.jsxs("div", { className: "space-y-1 leading-none mb-1", children: [
n && /* @__PURE__ */ L.jsx(
ge,
{
className: xe("text-primary", a.disabled && "opacity-40"),
children: n
}
),
/* @__PURE__ */ L.jsx(ue, { children: s })
] })
] })
}
) : /* @__PURE__ */ L.jsxs("div", { className: "flex flex-row items-center space-x-3", children: [
/* @__PURE__ */ L.jsx(Jt, { ...a }),
/* @__PURE__ */ L.jsxs("div", { className: "space-y-1 leading-none mb-1", children: [
n && /* @__PURE__ */ L.jsx(
ge,
{
className: xe("text-primary", a.disabled && "opacity-40"),
children: n
}
),
/* @__PURE__ */ L.jsx(ue, { children: s })
] })
] });
/*!
* FilePond 4.32.8
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
const ir = (e) => e instanceof HTMLElement, ar = (e, t = [], n = []) => {
const s = {
...e
}, r = [], a = [], i = () => ({ ...s }), l = () => {
const u = [...r];
return r.length = 0, u;
}, o = () => {
const u = [...a];
a.length = 0, u.forEach(({ type: _, data: T }) => {
d(_, T);
});
}, d = (u, _, T) => {
if (T && !document.hidden) {
a.push({ type: u, data: _ });
return;
}
p[u] && p[u](_), r.push({
type: u,
data: _
});
}, c = (u, ..._) => I[u] ? I[u](..._) : null, f = {
getState: i,
processActionQueue: l,
processDispatchQueue: o,
dispatch: d,
query: c
};
let I = {};
t.forEach((u) => {
I = {
...u(s),
...I
};
});
let p = {};
return n.forEach((u) => {
p = {
...u(d, c, s),
...p
};
}), f;
}, or = (e, t, n) => {
if (typeof n == "function") {
e[t] = n;
return;
}
Object.defineProperty(e, t, { ...n });
}, Y = (e, t) => {
for (const n in e)
e.hasOwnProperty(n) && t(n, e[n]);
}, Te = (e) => {
const t = {};
return Y(e, (n) => {
or(t, n, e[n]);
}), t;
}, z = (e, t, n = null) => {
if (n === null)
return e.getAttribute(t) || e.hasAttribute(t);
e.setAttribute(t, n);
}, lr = "http://www.w3.org/2000/svg", cr = ["svg", "path"], rn = (e) => cr.includes(e), lt = (e, t, n = {}) => {
typeof t == "object" && (n = t, t = null);
const s = rn(e) ? document.createElementNS(lr, e) : document.createElement(e);
return t && (rn(e) ? z(s, "class", t) : s.className = t), Y(n, (r, a) => {
z(s, r, a);
}), s;
}, dr = (e) => (t, n) => {
typeof n < "u" && e.children[n] ? e.insertBefore(t, e.children[n]) : e.appendChild(t);
}, ur = (e, t) => (n, s) => (typeof s < "u" ? t.splice(s, 0, n) : t.push(n), n), fr = (e, t) => (n) => (t.splice(t.indexOf(n), 1), n.element.parentNode && e.removeChild(n.element), n), Er = typeof window < "u" && typeof window.document < "u", ts = () => Er, pr = ts() ? lt("svg") : {}, Ir = "children" in pr ? (e) => e.children.length : (e) => e.childNodes.length, ns = (e, t, n, s) => {
const r = n[0] || e.left, a = n[1] || e.top, i = r + e.width, l = a + e.height * (s[1] || 1), o = {
// the rectangle of the element itself
element: {
...e
},
// the rectangle of the element expanded to contain its children, does not include any margins
inner: {
left: e.left,
top: e.top,
right: e.right,
bottom: e.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: r,
top: a,
right: i,
bottom: l
}
};
return t.filter((d) => !d.isRectIgnored()).map((d) => d.rect).forEach((d) => {
an(o.inner, { ...d.inner }), an(o.outer, { ...d.outer });
}), on(o.inner), o.outer.bottom += o.element.marginBottom, o.outer.right += o.element.marginRight, on(o.outer), o;
}, an = (e, t) => {
t.top += e.top, t.right += e.left, t.bottom += e.top, t.left += e.left, t.bottom > e.bottom && (e.bottom = t.bottom), t.right > e.right && (e.right = t.right);
}, on = (e) => {
e.width = e.right - e.left, e.height = e.bottom - e.top;
}, Re = (e) => typeof e == "number", _r = (e, t, n, s = 1e-3) => Math.abs(e - t) < s && Math.abs(n) < s, mr = (
// default options
({ stiffness: e = 0.5, damping: t = 0.75, mass: n = 10 } = {}) => {
let s = null, r = null, a = 0, i = !1;
const d = Te({
interpolate: (c, f) => {
if (i) return;
if (!(Re(s) && Re(r))) {
i = !0, a = 0;
return;
}
const I = -(r - s) * e;
a += I / n, r += a, a *= t, _r(r, s, a) || f ? (r = s, a = 0, i = !0, d.onupdate(r), d.oncomplete(r)) : d.onupdate(r);
},
target: {
set: (c) => {
if (Re(c) && !Re(r) && (r = c), s === null && (s = c, r = c), s = c, r === s || typeof s > "u") {
i = !0, a = 0, d.onupdate(r), d.oncomplete(r);
return;
}
i = !1;
},
get: () => s
},
resting: {
get: () => i
},
onupdate: (c) => {
},
oncomplete: (c) => {
}
});
return d;
}
), Tr = (e) => e < 0.5 ? 2 * e * e : -1 + (4 - 2 * e) * e, gr = (
// default values
({ duration: e = 500, easing: t = Tr, delay: n = 0 } = {}) => {
let s = null, r, a, i = !0, l = !1, o = null;
const c = Te({
interpolate: (f, I) => {
i || o === null || (s === null && (s = f), !(f - s < n) && (r = f - s - n, r >= e || I ? (r = 1, a = l ? 0 : 1, c.onupdate(a * o), c.oncomplete(a * o), i = !0) : (a = r / e, c.onupdate((r >= 0 ? t(l ? 1 - a : a) : 0) * o))));
},
target: {
get: () => l ? 0 : o,
set: (f) => {
if (o === null) {
o = f, c.onupdate(f), c.oncomplete(f);
return;
}
f < o ? (o = 1, l = !0) : (l = !1, o = f), i = !1, s = null;
}
},
resting: {
get: () => i
},
onupdate: (f) => {
},
oncomplete: (f) => {
}
});
return c;
}
), ln = {
spring: mr,
tween: gr
}, hr = (e, t, n) => {
const s = e[t] && typeof e[t][n] == "object" ? e[t][n] : e[t] || e, r = typeof s == "string" ? s : s.type, a = typeof s == "object" ? { ...s } : {};
return ln[r] ? ln[r](a) : null;
}, Ut = (e, t, n, s = !1) => {
t = Array.isArray(t) ? t : [t], t.forEach((r) => {
e.forEach((a) => {
let i = a, l = () => n[a], o = (d) => n[a] = d;
typeof a == "object" && (i = a.key, l = a.getter || l, o = a.setter || o), !(r[i] && !s) && (r[i] = {
get: l,
set: o
});
});
});
}, Rr = ({ mixinConfig: e, viewProps: t, viewInternalAPI: n, viewExternalAPI: s }) => {
const r = { ...t }, a = [];
return Y(e, (i, l) => {
const o = hr(l);
if (!o)
return;
o.onupdate = (c) => {
t[i] = c;
}, o.target = r[i], Ut([{
key: i,
setter: (c) => {
o.target !== c && (o.target = c);
},
getter: () => t[i]
}], [n, s], t, !0), a.push(o);
}), {
write: (i) => {
let l = document.hidden, o = !0;
return a.forEach((d) => {
d.resting || (o = !1), d.interpolate(i, l);
}), o;
},
destroy: () => {
}
};
}, Or = (e) => (t, n) => {
e.addEventListener(t, n);
}, Sr = (e) => (t, n) => {
e.removeEventListener(t, n);
}, Dr = ({
mixinConfig: e,
viewProps: t,
viewInternalAPI: n,
viewExternalAPI: s,
viewState: r,
view: a
}) => {
const i = [], l = Or(a.element), o = Sr(a.element);
return s.on = (d, c) => {
i.push({
type: d,
fn: c
}), l(d, c);
}, s.off = (d, c) => {
i.splice(i.findIndex((f) => f.type === d && f.fn === c), 1), o(d, c);
}, {
write: () => !0,
destroy: () => {
i.forEach((d) => {
o(d.type, d.fn);
});
}
};
}, yr = ({ mixinConfig: e, viewProps: t, viewExternalAPI: n }) => {
Ut(e, n, t);
}, Z = (e) => e != null, Ar = {
opacity: 1,
scaleX: 1,
scaleY: 1,
translateX: 0,
translateY: 0,
rotateX: 0,
rotateY: 0,
rotateZ: 0,
originX: 0,
originY: 0
}, Mr = ({ mixinConfig: e, viewProps: t, viewInternalAPI: n, viewExternalAPI: s, view: r }) => {
const a = { ...t }, i = {};
Ut(e, [n, s], t);
const l = () => [t.translateX || 0, t.translateY || 0], o = () => [t.scaleX || 0, t.scaleY || 0], d = () => r.rect ? ns(r.rect, r.childViews, l(), o()) : null;
return n.rect = { get: d }, s.rect = { get: d }, e.forEach((c) => {
t[c] = typeof a[c] > "u" ? Ar[c] : a[c];
}), {
write: () => {
if (Lr(i, t))
return wr(r.element, t), Object.assign(i, { ...t }), !0;
},
destroy: () => {
}
};
}, Lr = (e, t) => {
if (Object.keys(e).length !== Object.keys(t).length)
return !0;
for (const n in t)
if (t[n] !== e[n])
return !0;
return !1;
}, wr = (e, {
opacity: t,
perspective: n,
translateX: s,
translateY: r,
scaleX: a,
scaleY: i,
rotateX: l,
rotateY: o,
rotateZ: d,
originX: c,
originY: f,
width: I,
height: p
}) => {
let u = "", _ = "";
(Z(c) || Z(f)) && (_ += `transform-origin: ${c || 0}px ${f || 0}px;`), Z(n) && (u += `perspective(${n}px) `), (Z(s) || Z(r)) && (u += `translate3d(${s || 0}px, ${r || 0}px, 0) `), (Z(a) || Z(i)) && (u += `scale3d(${Z(a) ? a : 1}, ${Z(i) ? i : 1}, 1) `), Z(d) && (u += `rotateZ(${d}rad) `), Z(l) && (u += `rotateX(${l}rad) `), Z(o) && (u += `rotateY(${o}rad) `), u.length && (_ += `transform:${u};`), Z(t) && (_ += `opacity:${t};`, t === 0 && (_ += "visibility:hidden;"), t < 1 && (_ += "pointer-events:none;")), Z(p) && (_ += `height:${p}px;`), Z(I) && (_ += `width:${I}px;`);
const T = e.elementCurrentStyle || "";
(_.length !== T.length || _ !== T) && (e.style.cssText = _, e.elementCurrentStyle = _);
}, Pr = {
styles: Mr,
listeners: Dr,
animations: Rr,
apis: yr
}, cn = (e = {}, t = {}, n = {}) => (t.layoutCalculated || (e.paddingTop = parseInt(n.paddingTop, 10) || 0, e.marginTop = parseInt(n.marginTop, 10) || 0, e.marginRight = parseInt(n.marginRight, 10) || 0, e.marginBottom = parseInt(n.marginBottom, 10) || 0, e.marginLeft = parseInt(n.marginLeft, 10) || 0, t.layoutCalculated = !0), e.left = t.offsetLeft || 0, e.top = t.offsetTop || 0, e.width = t.offsetWidth || 0, e.height = t.offsetHeight || 0, e.right = e.left + e.width, e.bottom = e.top + e.height, e.scrollTop = t.scrollTop, e.hidden = t.offsetParent === null, e), $ = (
// default view definition
({
// element definition
tag: e = "div",
name: t = null,
attributes: n = {},
// view interaction
read: s = () => {
},
write: r = () => {
},
create: a = () => {
},
destroy: i = () => {
},
// hooks
filterFrameActionsForChild: l = (p, u) => u,
didCreateView: o = () => {
},
didWriteView: d = () => {
},
// rect related
ignoreRect: c = !1,
ignoreRectUpdate: f = !1,
// mixins
mixins: I = []
} = {}) => (p, u = {}) => {
const _ = lt(e, `filepond--${t}`, n), T = window.getComputedStyle(_, null), h = cn();
let E = null, m = !1;
const R = [], S = [], M = {}, N = {}, D = [
r
// default writer
], w = [
s
// default reader
], G = [
i
// default destroy
], P = () => _, C = () => R.concat(), V = () => M, A = (U) => (X, pe) => X(U, pe), B = () => E || (E = ns(h, R, [0, 0], [1, 1]), E), O = () => T, y = () => {
E = null, R.forEach((pe) => pe._read()), !(f && h.width && h.height) && cn(h, _, T);
const X = { root: oe, props: u, rect: h };
w.forEach((pe) => pe(X));
}, b = (U, X, pe) => {
let Pe = X.length === 0;
return D.forEach((J) => {
J({
props: u,
root: oe,
actions: X,
timestamp: U,
shouldOptimize: pe
}) === !1 && (Pe = !1);
}), S.forEach((J) => {
J.write(U) === !1 && (Pe = !1);
}), R.filter((J) => !!J.element.parentNode).forEach((J) => {
J._write(
U,
l(J, X),
pe
) || (Pe = !1);
}), R.forEach((J, Ze) => {
J.element.parentNode || (oe.appendChild(J.element, Ze), J._read(), J._write(
U,
l(J, X),
pe
), Pe = !1);
}), m = Pe, d({
props: u,
root: oe,
actions: X,
timestamp: U
}), Pe;
}, v = () => {
S.forEach((U) => U.destroy()), G.forEach((U) => {
U({ root: oe, props: u });
}), R.forEach((U) => U._destroy());
}, H = {
element: {
get: P
},
style: {
get: O
},
childViews: {
get: C
}
}, F = {
...H,
rect: {
get: B
},
// access to custom children references
ref: {
get: V
},
// dom modifiers
is: (U) => t === U,
appendChild: dr(_),
createChildView: A(p),
linkView: (U) => (R.push(U), U),
unlinkView: (U) => {
R.splice(R.indexOf(U), 1);
},
appendChildView: ur(_, R),
removeChildView: fr(_, R),
registerWriter: (U) => D.push(U),
registerReader: (U) => w.push(U),
registerDestroyer: (U) => G.push(U),
invalidateLayout: () => _.layoutCalculated = !1,
// access to data store
dispatch: p.dispatch,
query: p.query
}, he = {
element: {
get: P
},
childViews: {
get: C
},
rect: {
get: B
},
resting: {
get: () => m
},
isRectIgnored: () => c,
_read: y,
_write: b,
_destroy: v
}, Ye = {
...H,
rect: {
get: () => h
}
};
Object.keys(I).sort((U, X) => U === "styles" ? 1 : X === "styles" ? -1 : 0).forEach((U) => {
const X = Pr[U]({
mixinConfig: I[U],
viewProps: u,
viewState: N,
viewInternalAPI: F,
viewExternalAPI: he,
view: Te(Ye)
});
X && S.push(X);
});
const oe = Te(F);
a({
root: oe,
props: u
});
const ht = Ir(_);
return R.forEach((U, X) => {
oe.appendChild(U.element, ht + X);
}), o(oe), Te(he);
}
), Cr = (e, t, n = 60) => {
const s = "__framePainter";
if (window[s]) {
window[s].readers.push(e), window[s].writers.push(t);
return;
}
window[s] = {
readers: [e],
writers: [t]
};
const r = window[s], a = 1e3 / n;
let i = null, l = null, o = null, d = null;
const c = () => {
document.hidden ? (o = () => window.setTimeout(() => f(performance.now()), a), d = () => window.clearTimeout(l)) : (o = () => window.requestAnimationFrame(f), d = () => window.cancelAnimationFrame(l));
};
document.addEventListener("visibilitychange", () => {
d && d(), c(), f(performance.now());
});
const f = (I) => {
l = o(f), i || (i = I);
const p = I - i;
p <= a || (i = I - p % a, r.readers.forEach((u) => u()), r.writers.forEach((u) => u(I)));
};
return c(), f(performance.now()), {
pause: () => {
d(l);
}
};
}, K = (e, t) => ({ root: n, props: s, actions: r = [], timestamp: a, shouldOptimize: i }) => {
r.filter((l) => e[l.type]).forEach(
(l) => e[l.type]({ root: n, props: s, action: l.data, timestamp: a, shouldOptimize: i })
), t && t({ root: n, props: s, actions: r, timestamp: a, shouldOptimize: i });
}, dn = (e, t) => t.parentNode.insertBefore(e, t), un = (e, t) => t.parentNode.insertBefore(e, t.nextSibling), Et = (e) => Array.isArray(e), Ie = (e) => e == null, br = (e) => e.trim(), pt = (e) => "" + e, Nr = (e, t = ",") => Ie(e) ? [] : Et(e) ? e : pt(e).split(t).map(br).filter((n) => n.length), ss = (e) => typeof e == "boolean", rs = (e) => ss(e) ? e : e === "true", Q = (e) => typeof e == "string", is = (e) => Re(e) ? e : Q(e) ? pt(e).replace(/[a-z]+/gi, "") : 0, it = (e) => parseInt(is(e), 10), fn = (e) => parseFloat(is(e)), He = (e) => Re(e) && isFinite(e) && Math.floor(e) === e, En = (e, t = 1e3) => {
if (He(e))
return e;
let n = pt(e).trim();
return /MB$/i.test(n) ? (n = n.replace(/MB$i/, "").trim(), it(n) * t * t) : /KB/i.test(n) ? (n = n.replace(/KB$i/, "").trim(), it(n) * t) : it(n);
}, Oe = (e) => typeof e == "function", vr = (e) => {
let t = self, n = e.split("."), s = null;
for (; s = n.shift(); )
if (t = t[s], !t)
return null;
return t;
}, pn = {
process: "POST",
patch: "PATCH",
revert: "DELETE",
fetch: "GET",
restore: "GET",
load: "GET"
}, Gr = (e) => {
const t = {};
return t.url = Q(e) ? e : e.url || "", t.timeout = e.timeout ? parseInt(e.timeout, 10) : 0, t.headers = e.headers ? e.headers : {}, Y(pn, (n) => {
t[n] = xr(n, e[n], pn[n], t.timeout, t.headers);
}), t.process = e.process || Q(e) || e.url ? t.process : null, t.remove = e.remove || null, delete t.headers, t;
}, xr = (e, t, n, s, r) => {
if (t === null)
return null;
if (typeof t == "function")
return t;
const a = {
url: n === "GET" || n === "PATCH" ? `?${e}=` : "",
method: n,
headers: r,
withCredentials: !1,
timeout: s,
onload: null,
ondata: null,
onerror: null
};
if (Q(t))
return a.url = t, a;
if (Object.assign(a, t), Q(a.headers)) {
const i = a.headers.split(/:(.+)/);
a.headers = {
header: i[0],
value: i[1]
};
}
return a.withCredentials = rs(a.withCredentials), a;
}, Fr = (e) => Gr(e), Br = (e) => e === null, j = (e) => typeof e == "object" && e !== null, Ur = (e) => j(e) && Q(e.url) && j(e.process) && j(e.revert) && j(e.restore) && j(e.fetch), wt = (e) => Et(e) ? "array" : Br(e) ? "null" : He(e) ? "int" : /^[0-9]+ ?(?:GB|MB|KB)$/gi.test(e) ? "bytes" : Ur(e) ? "api" : typeof e, Vr = (e) => e.replace(/{\s*'/g, '{"').replace(/'\s*}/g, '"}').replace(/'\s*:/g, '":').replace(/:\s*'/g, ':"').replace(/,\s*'/g, ',"').replace(/'\s*,/g, '",'), Hr = {
array: Nr,
boolean: rs,
int: (e) => wt(e) === "bytes" ? En(e) : it(e),
number: fn,
float: fn,
bytes: En,
string: (e) => Oe(e) ? e : pt(e),
function: (e) => vr(e),
serverapi: Fr,
object: (e) => {
try {
return JSON.parse(Vr(e));
} catch {
return null;
}
}
}, Yr = (e, t) => Hr[t](e), as = (e, t, n) => {
if (e === t)
return e;
let s = wt(e);
if (s !== n) {
const r = Yr(e, n);
if (s = wt(r), r === null)
throw `Trying to assign value with incorrect type to "${option}", allowed type: "${n}"`;
e = r;
}
return e;
}, Wr = (e, t) => {
let n = e;
return {
enumerable: !0,
get: () => n,
set: (s) => {
n = as(s, e, t);
}
};
}, qr = (e) => {
const t = {};
return Y(e, (n) => {
const s = e[n];
t[n] = Wr(s[0], s[1]);
}), Te(t);
}, $r = (e) => ({
// 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: qr(e)
}), It = (e, t = "-") => e.split(/(?=[A-Z])/).map((n) => n.toLowerCase()).join(t), zr = (e, t) => {
const n = {};
return Y(t, (s) => {
n[s] = {
get: () => e.getState().options[s],
set: (r) => {
e.dispatch(`SET_${It(s, "_").toUpperCase()}`, {
value: r
});
}
};
}), n;
}, kr = (e) => (t, n, s) => {
const r = {};
return Y(e, (a) => {
const i = It(a, "_").toUpperCase();
r[`SET_${i}`] = (l) => {
try {
s.options[a] = l.value;
} catch {
}
t(`DID_SET_${i}`, { value: s.options[a] });
};
}), r;
}, jr = (e) => (t) => {
const n = {};
return Y(e, (s) => {
n[`GET_${It(s, "_").toUpperCase()}`] = (r) => t.options[s];
}), n;
}, ae = {
API: 1,
DROP: 2,
BROWSE: 3,
PASTE: 4,
NONE: 5
}, Vt = () => Math.random().toString(36).substring(2, 11), Ht = (e, t) => e.splice(t, 1), Xr = (e, t) => {
t ? e() : document.hidden ? Promise.resolve(1).then(e) : setTimeout(e, 0);
}, _t = () => {
const e = [], t = (s, r) => {
Ht(
e,
e.findIndex((a) => a.event === s && (a.cb === r || !r))
);
}, n = (s, r, a) => {
e.filter((i) => i.event === s).map((i) => i.cb).forEach((i) => Xr(() => i(...r), a));
};
return {
fireSync: (s, ...r) => {
n(s, r, !0);
},
fire: (s, ...r) => {
n(s, r, !1);
},
on: (s, r) => {
e.push({ event: s, cb: r });
},
onOnce: (s, r) => {
e.push({
event: s,
cb: (...a) => {
t(s, r), r(...a);
}
});
},
off: t
};
}, os = (e, t, n) => {
Object.getOwnPropertyNames(e).filter((s) => !n.includes(s)).forEach(
(s) => Object.defineProperty(t, s, Object.getOwnPropertyDescriptor(e, s))
);
}, Zr = [
"fire",
"process",
"revert",
"load",
"on",
"off",
"onOnce",
"retryLoad",
"extend",
"archive",
"archived",
"release",
"released",
"requestProcessing",
"freeze"
], ee = (e) => {
const t = {};
return os(e, t, Zr), t;
}, Qr = (e) => {
e.forEach((t, n) => {
t.released && Ht(e, n);
});
}, x = {
INIT: 1,
IDLE: 2,
PROCESSING_QUEUED: 9,
PROCESSING: 3,
PROCESSING_COMPLETE: 5,
PROCESSING_ERROR: 6,
PROCESSING_REVERT_ERROR: 10,
LOADING: 7,
LOAD_ERROR: 8
}, k = {
INPUT: 1,
LIMBO: 2,
LOCAL: 3
}, ls = (e) => /[^0-9]+/.exec(e), cs = () => ls(1.1.toLocaleString())[0], Kr = () => {
const e = cs(), t = 1e3.toLocaleString();
return t !== "1000" ? ls(t)[0] : e === "." ? "," : ".";
}, g = {
BOOLEAN: "boolean",
INT: "int",
NUMBER: "number",
STRING: "string",
ARRAY: "array",
OBJECT: "object",
FUNCTION: "function",
ACTION: "action",
SERVER_API: "serverapi",
REGEX: "regex"
}, Yt = [], le = (e, t, n) => new Promise((s, r) => {
const a = Yt.filter((l) => l.key === e).map((l) => l.cb);
if (a.length === 0) {
s(t);
return;
}
const i = a.shift();
a.reduce(
// loop over promises passing value to next promise
(l, o) => l.then((d) => o(d, n)),
// call initial filter, will return a promise
i(t, n)
// all executed
).then((l) => s(l)).catch((l) => r(l));
}), Le = (e, t, n) => Yt.filter((s) => s.key === e).map((s) => s.cb(t, n)), Jr = (e, t) => Yt.push({ key: e, cb: t }), ei = (e) => Object.assign(be, e), ct = () => ({ ...be }), ti = (e) => {
Y(e, (t, n) => {
be[t] && (be[t][0] = as(
n,
be[t][0],
be[t][1]
));
});
}, be = {
// the id to add to the root element
id: [null, g.STRING],
// input field name to use
name: ["filepond", g.STRING],
// disable the field
disabled: [!1, g.BOOLEAN],
// classname to put on wrapper
className: [null, g.STRING],
// is the field required
required: [!1, g.BOOLEAN],
// Allow media capture when value is set
captureMethod: [null, g.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, g.BOOLEAN],
// Feature toggles
allowDrop: [!0, g.BOOLEAN],
// Allow dropping of files
allowBrowse: [!0, g.BOOLEAN],
// Allow browsing the file system
allowPaste: [!0, g.BOOLEAN],
// Allow pasting files
allowMultiple: [!1, g.BOOLEAN],
// Allow multiple files (disabled by default, as multiple attribute is also required on input to allow multiple)
allowReplace: [!0, g.BOOLEAN],
// Allow dropping a file on other file to replace it (only works when multiple is set to false)
allowRevert: [!0, g.BOOLEAN],
// Allows user to revert file upload
allowRemove: [!0, g.BOOLEAN],
// Allow user to remove a file
allowProcess: [!0, g.BOOLEAN],
// Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [!1, g.BOOLEAN],
// Allow reordering of files
allowDirectoriesOnly: [!1, g.BOOLEAN],
// Allow only selecting directories with browse (no support for filtering dnd at this point)
// Try store file if `server` not set
storeAsFile: [!1, g.BOOLEAN],
// Revert mode
forceRevert: [!1, g.BOOLEAN],
// Set to 'force' to require the file to be reverted before removal
// Input requirements
maxFiles: [null, g.INT],
// Max number of files
checkValidity: [!1, g.BOOLEAN],
// Enables custom validity messages
// Where to put file
itemInsertLocationFreedom: [!0, g.BOOLEAN],
// Set to false to always add items to begin or end of list
itemInsertLocation: ["before", g.STRING],
// Default index in list to add items that have been dropped at the top of the list
itemInsertInterval: [75, g.INT],
// Drag 'n Drop related
dropOnPage: [!1, g.BOOLEAN],
// Allow dropping of files anywhere on page (prevents browser from opening file if dropped outside of Up)
dropOnElement: [!0, g.BOOLEAN],
// Drop needs to happen on element (set to false to also load drops outside of Up)
dropValidation: [!1, g.BOOLEAN],
// Enable or disable validating files on drop
ignoredFiles: [[".ds_store", "thumbs.db", "desktop.ini"], g.ARRAY],
// Upload related
instantUpload: [!0, g.BOOLEAN],
// Should upload files immediately on drop
maxParallelUploads: [2, g.INT],
// Maximum files to upload in parallel
allowMinimumUploadDuration: [!0, g.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, g.BOOLEAN],
// Enable chunked uploads
chunkForce: [!1, g.BOOLEAN],
// Force use of chunk uploads even for files smaller than chunk size
chunkSize: [5e6, g.INT],
// Size of chunks (5MB default)
chunkRetryDelays: [[500, 1e3, 3e3], g.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, g.SERVER_API],
// File size calculations, can set to 1024, this is only used for display, properties use file size base 1000
fileSizeBase: [1e3, g.INT],
// Labels and status messages
labelFileSizeBytes: ["bytes", g.STRING],
labelFileSizeKilobytes: ["KB", g.STRING],
labelFileSizeMegabytes: ["MB", g.STRING],
labelFileSizeGigabytes: ["GB", g.STRING],
labelDecimalSeparator: [cs(), g.STRING],
// Default is locale separator
labelThousandsSeparator: [Kr(), g.STRING],
// Default is locale separator
labelIdle: [
'Drag & Drop your files or <span class="filepond--label-action">Browse</span>',
g.STRING
],
labelInvalidField: ["Field contains invalid files", g.STRING],
labelFileWaitingForSize: ["Waiting for size", g.STRING],
labelFileSizeNotAvailable: ["Size not available", g.STRING],
labelFileCountSingular: ["file in list", g.STRING],
labelFileCountPlural: ["files in list", g.STRING],
labelFileLoading: ["Loading", g.STRING],
labelFileAdded: ["Added", g.STRING],
// assistive only
labelFileLoadError: ["Error during load", g.STRING],
labelFileRemoved: ["Removed", g.STRING],
// assistive only
labelFileRemoveError: ["Error during remove", g.STRING],
labelFileProcessing: ["Uploading", g.STRING],
labelFileProcessingComplete: ["Upload complete", g.STRING],
labelFileProcessingAborted: ["Upload cancelled", g.STRING],
labelFileProcessingError: ["Error during upload", g.STRING],
labelFileProcessingRevertError: ["Error during revert", g.STRING],
labelTapToCancel: ["tap to cancel", g.STRING],
labelTapToRetry: ["tap to retry", g.STRING],
labelTapToUndo: ["tap to undo", g.STRING],
labelButtonRemoveItem: ["Remove", g.STRING],
labelButtonAbortItemLoad: ["Abort", g.STRING],
labelButtonRetryItemLoad: ["Retry", g.STRING],
labelButtonAbortItemProcessing: ["Cancel", g.STRING],
labelButtonUndoItemProcessing: ["Undo", g.STRING],
labelButtonRetryItemProcessing: ["Retry", g.STRING],
labelButtonProcessItem: ["Upload", g.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>',
g.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>',
g.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>',
g.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>',
g.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>',
g.STRING
],
// event handlers
oninit: [null, g.FUNCTION],
onwarning: [null, g.FUNCTION],
onerror: [null, g.FUNCTION],
onactivatefile: [null, g.FUNCTION],
oninitfile: [null, g.FUNCTION],
onaddfilestart: [null, g.FUNCTION],
onaddfileprogress: [null, g.FUNCTION],
onaddfile: [null, g.FUNCTION],
onprocessfilestart: [null, g.FUNCTION],
onprocessfileprogress: [null, g.FUNCTION],
onprocessfileabort: [null, g.FUNCTION],
onprocessfilerevert: [null, g.FUNCTION],
onprocessfile: [null, g.FUNCTION],
onprocessfiles: [null, g.FUNCTION],
onremovefile: [null, g.FUNCTION],
onpreparefile: [null, g.FUNCTION],
onupdatefiles: [null, g.FUNCTION],
onreorderfiles: [null, g.FUNCTION],
// hooks
beforeDropFile: [null, g.FUNCTION],
beforeAddFile: [null, g.FUNCTION],
beforeRemoveFile: [null, g.FUNCTION],
beforePrepareFile: [null, g.FUNCTION],
// styles
stylePanelLayout: [null, g.STRING],
// null 'integrated', 'compact', 'circle'
stylePanelAspectRatio: [null, g.STRING],
// null or '3:2' or 1
styleItemPanelAspectRatio: [null, g.STRING],
styleButtonRemoveItemPosition: ["left", g.STRING],
styleButtonProcessItemPosition: ["right", g.STRING],
styleLoadIndicatorPosition: ["right", g.STRING],
styleProgressIndicatorPosition: ["right", g.STRING],
styleButtonRemoveItemAlign: [!1, g.BOOLEAN],
// custom initial files array
files: [[], g.ARRAY],
// show support by displaying credits
credits: [["https://pqina.nl/", "Powered by PQINA"], g.ARRAY]
}, Se = (e, t) => Ie(t) ? e[0] || null : He(t) ? e[t] || null : (typeof t == "object" && (t = t.id), e.find((n) => n.id === t) || null), ds = (e) => {
if (Ie(e))
return e;
if (/:/.test(e)) {
const t = e.split(":");
return t[1] / t[0];
}
return parseFloat(e);
}, ce = (e) => e.filter((t) => !t.archived), ni = {
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 Qe = null;
const si = () => {
if (Qe === null)
try {
const e = new DataTransfer();
e.items.add(new File(["hello world"], "This_Works.txt"));
const t = document.createElement("input");
t.setAttribute("type", "file"), t.files = e.files, Qe = t.files.length === 1;
} catch {
Qe = !1;
}
return Qe;
}, ri = [
x.LOAD_ERROR,
x.PROCESSING_ERROR,
x.PROCESSING_REVERT_ERROR
], ii = [
x.LOADING,
x.PROCESSING,
x.PROCESSING_QUEUED,
x.INIT
], ai = [x.PROCESSING_COMPLETE], oi = (e) => ri.includes(e.status), li = (e) => ii.includes(e.status), ci = (e) => ai.includes(e.status), In = (e) => j(e.options.server) && (j(e.options.server.process) || Oe(e.options.server.process)), di = (e) => ({
GET_STATUS: () => {
const t = ce(e.items), { EMPTY: n, ERROR: s, BUSY: r, IDLE: a, READY: i } = ni;
return t.length === 0 ? n : t.some(oi) ? s : t.some(li) ? r : t.some(ci) ? i : a;
},
GET_ITEM: (t) => Se(e.items, t),
GET_ACTIVE_ITEM: (t) => Se(ce(e.items), t),
GET_ACTIVE_ITEMS: () => ce(e.items),
GET_ITEMS: () => e.items,
GET_ITEM_NAME: (t) => {
const n = Se(e.items, t);
return n ? n.filename : null;
},
GET_ITEM_SIZE: (t) => {
const n = Se(e.items, t);
return n ? n.fileSize : null;
},
GET_STYLES: () => Object.keys(e.options).filter((t) => /^style/.test(t)).map((t) => ({
name: t,
value: e.options[t]
})),
GET_PANEL_ASPECT_RATIO: () => /circle/.test(e.options.stylePanelLayout) ? 1 : ds(e.options.stylePanelAspectRatio),
GET_ITEM_PANEL_ASPECT_RATIO: () => e.options.styleItemPanelAspectRatio,
GET_ITEMS_BY_STATUS: (t) => ce(e.items).filter((n) => n.status === t),
GET_TOTAL_ITEMS: () => ce(e.items).length,
SHOULD_UPDATE_FILE_INPUT: () => e.options.storeAsFile && si() && !In(e),
IS_ASYNC: () => In(e),
GET_FILE_SIZE_LABELS: (t) => ({
labelBytes: t("GET_LABEL_FILE_SIZE_BYTES") || void 0,
labelKilobytes: t("GET_LABEL_FILE_SIZE_KILOBYTES") || void 0,
labelMegabytes: t("GET_LABEL_FILE_SIZE_MEGABYTES") || void 0,
labelGigabytes: t("GET_LABEL_FILE_SIZE_GIGABYTES") || void 0
})
}), ui = (e) => {
const t = ce(e.items).length;
if (!e.options.allowMultiple)
return t === 0;
const n = e.options.maxFiles;
return n === null || t < n;
}, us = (e, t, n) => Math.max(Math.min(n, e), t), fi = (e, t, n) => e.splice(t, 0, n), Ei = (e, t, n) => Ie(t) ? null : typeof n > "u" ? (e.push(t), t) : (n = us(n, 0, e.length), fi(e, n, t), t), Pt = (e) => /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*)\s*$/i.test(
e
), Xe = (e) => `${e}`.split("/").pop().split("?").shift(), mt = (e) => e.split(".").pop(), pi = (e) => {
if (typeof e != "string")
return "";
const t = e.split("/").pop();
return /svg/.test(t) ? "svg" : /zip|compressed/.test(t) ? "zip" : /plain/.test(t) ? "txt" : /msword/.test(t) ? "doc" : /[a-z]+/.test(t) ? t === "jpeg" ? "jpg" : t : "";
}, We = (e, t = "") => (t + e).slice(-t.length), fs = (e = /* @__PURE__ */ new Date()) => `${e.getFullYear()}-${We(e.getMonth() + 1, "00")}-${We(
e.getDate(),
"00"
)}_${We(e.getHours(), "00")}-${We(e.getMinutes(), "00")}-${We(
e.getSeconds(),
"00"
)}`, Fe = (e, t, n = null, s = null) => {
const r = typeof n == "string" ? e.slice(0, e.size, n) : e.slice(0, e.size, e.type);
return r.lastModifiedDate = /* @__PURE__ */ new Date(), e._relativePath && (r._relativePath = e._relativePath), Q(t) || (t = fs()), t && s === null && mt(t) ? r.name = t : (s = s || pi(r.type), r.name = t + (s ? "." + s : "")), r;
}, Ii = () => window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder, Es = (e, t) => {
const n = Ii();
if (n) {
const s = new n();
return s.append(e), s.getBlob(t);
}
return new Blob([e], {
type: t
});
}, _i = (e, t) => {
const n = new ArrayBuffer(e.length), s = new Uint8Array(n);
for (let r = 0; r < e.length; r++)
s[r] = e.charCodeAt(r);
return Es(n, t);
}, ps = (e) => (/^data:(.+);/.exec(e) || [])[1] || null, mi = (e) => e.split(",")[1].replace(/\s/g, ""), Ti = (e) => atob(mi(e)), gi = (e) => {
const t = ps(e), n = Ti(e);
return _i(n, t);
}, hi = (e, t, n) => Fe(gi(e), t, null, n), Ri = (e) => {
if (!/^content-disposition:/i.test(e)) return null;
const t = e.split(/filename=|filename\*=.+''/).splice(1).map((n) => n.trim().replace(/^["']|[;"']{0,2}$/g, "")).filter((n) => n.length);
return t.length ? decodeURI(t[t.length - 1]) : null;
}, Oi = (e) => {
if (/content-length:/i.test(e)) {
const t = e.match(/[0-9]+/)[0];
return t ? parseInt(t, 10) : null;
}
return null;
}, Si = (e) => /x-content-transfer-id:/i.test(e) && (e.split(":")[1] || "").trim() || null, Wt = (e) => {
const t = {
source: null,
name: null,
size: null
}, n = e.split(`
`);
for (let s of n) {
const r = Ri(s);
if (r) {
t.name = r;
continue;
}
const a = Oi(s);
if (a) {
t.size = a;
continue;
}
const i = Si(s);
if (i) {
t.source = i;
continue;
}
}
return t;
}, Di = (e) => {
const t = {
source: null,
complete: !1,
progress: 0,
size: null,
timestamp: null,
duration: 0,
request: null
}, n = () => t.progress, s = () => {
t.request && t.request.abort && t.request.abort();
}, r = () => {
const l = t.source;
i.fire("init", l), l instanceof File ? i.fire("load", l) : l instanceof Blob ? i.fire("load", Fe(l, l.name)) : Pt(l) ? i.fire("load", hi(l)) : a(l);
}, a = (l) => {
if (!e) {
i.fire("error", {
type: "error",
body: "Can't load URL",
code: 400
});
return;
}
t.timestamp = Date.now(), t.request = e(
l,
(o) => {
t.duration = Date.now() - t.timestamp, t.complete = !0, o instanceof Blob && (o = Fe(o, o.name || Xe(l))), i.fire(
"load",
// if has received blob, we go with blob, if no response, we return null
o instanceof Blob ? o : o ? o.body : null
);
},
(o) => {
i.fire(
"error",
typeof o == "string" ? {
type: "error",
code: 0,
body: o
} : o
);
},
(o, d, c) => {
if (c && (t.size = c), t.duration = Date.now() - t.timestamp, !o) {
t.progress = null;
return;
}
t.progress = d / c, i.fire("progress", t.progress);
},
() => {
i.fire("abort");
},
(o) => {
const d = Wt(
typeof o == "string" ? o : o.headers
);
i.fire("meta", {
size: t.size || d.size,
filename: d.name,
source: d.source
});
}
);
}, i = {
..._t(),
setSource: (l) => t.source = l,
getProgress: n,
// file load progress
abort: s,
// abort file load
load: r
// start load
};
return i;
}, _n = (e) => /GET|HEAD/.test(e), De = (e, t, n) => {
const s = {
onheaders: () => {
},
onprogress: () => {
},
onload: () => {
},
ontimeout: () => {
},
onerror: () => {
},
onabort: () => {
},
abort: () => {
r = !0, i.abort();
}
};
let r = !1, a = !1;
n = {
method: "POST",
headers: {},
withCredentials: !1,
...n
}, t = encodeURI(t), _n(n.method) && e && (t = `${t}${encodeURIComponent(typeof e == "string" ? e : JSON.stringify(e))}`);
const i = new XMLHttpRequest(), l = _n(n.method) ? i : i.upload;
return l.onprogress = (o) => {
r || s.onprogress(o.lengthComputable, o.loaded, o.total);
}, i.onreadystatechange = () => {
i.readyState < 2 || i.readyState === 4 && i.status === 0 || a || (a = !0, s.onheaders(i));
}, i.onload = () => {
i.status >= 200 && i.status < 300 ? s.onload(i) : s.onerror(i);
}, i.onerror = () => s.onerror(i), i.onabort = () => {
r = !0, s.onabort();
}, i.ontimeout = () => s.ontimeout(i), i.open(n.method, t, !0), He(n.timeout) && (i.timeout = n.timeout), Object.keys(n.headers).forEach((o) => {
const d = unescape(encodeURIComponent(n.headers[o]));
i.setRequestHeader(o, d);
}), n.responseType && (i.responseType = n.responseType), n.withCredentials && (i.withCredentials = !0), i.send(e), s;
}, W = (e, t, n, s) => ({
type: e,
code: t,
body: n,
headers: s
}), ye = (e) => (t) => {
e(W("error", 0, "Timeout", t.getAllResponseHeaders()));
}, mn = (e) => /\?/.test(e), ze = (...e) => {
let t = "";
return e.forEach((n) => {
t += mn(t) && mn(n) ? n.replace(/\?/, "&") : n;
}), t;
}, Rt = (e = "", t) => {
if (typeof t == "function")
return t;
if (!t || !Q(t.url))
return null;
const n = t.onload || ((r) => r), s = t.onerror || ((r) => null);
return (r, a, i, l, o, d) => {
const c = De(r, ze(e, t.url), {
...t,
responseType: "blob"
});
return c.onload = (f) => {
const I = f.getAllResponseHeaders(), p = Wt(I).name || Xe(r);
a(
W(
"load",
f.status,
t.method === "HEAD" ? null : Fe(n(f.response), p),
I
)
);
}, c.onerror = (f) => {
i(
W(
"error",
f.status,
s(f.response) || f.statusText,
f.getAllResponseHeaders()
)
);
}, c.onheaders = (f) => {
d(W("headers", f.status, null, f.getAllResponseHeaders()));
}, c.ontimeout = ye(i), c.onprogress = l, c.onabort = o, c;
};
}, se = {
QUEUED: 0,
COMPLETE: 1,
PROCESSING: 2,
ERROR: 3,
WAITING: 4
}, yi = (e, t, n, s, r, a, i, l, o, d, c) => {
const f = [], { chunkTransferId: I, chunkServer: p, chunkSize: u, chunkRetryDelays: _ } = c, T = {
serverId: I,
aborted: !1
}, h = t.ondata || ((A) => A), E = t.onload || ((A, B) => B === "HEAD" ? A.getResponseHeader("Upload-Offset") : A.response), m = t.onerror || ((A) => null), R = (A) => {
const B = new FormData();
j(r) && B.append(n, JSON.stringify(r));
const O = typeof t.headers == "function" ? t.headers(s, r) : {
...t.headers,
"Upload-Length": s.size
}, y = {
...t,
headers: O
}, b = De(h(B), ze(e, t.url), y);
b.onload = (v) => A(E(v, y.method)), b.onerror = (v) => i(
W(
"error",
v.status,
m(v.response) || v.statusText,
v.getAllResponseHeaders()
)
), b.ontimeout = ye(i);
}, S = (A) => {
const B = ze(e, p.url, T.serverId), y = {
headers: typeof t.headers == "function" ? t.headers(T.serverId) : {
...t.headers
},
method: "HEAD"
}, b = De(null, B, y);
b.onload = (v) => A(E(v, y.method)), b.onerror = (v) => i(
W(
"error",
v.status,
m(v.response) || v.statusText,
v.getAllResponseHeaders()
)
), b.ontimeout = ye(i);
}, M = Math.floor(s.size / u);
for (let A = 0; A <= M; A++) {
const B = A * u, O = s.slice(B, B + u, "application/offset+octet-stream");
f[A] = {
index: A,
size: O.size,
offset: B,
data: O,
file: s,
progress: 0,
retries: [..._],
status: se.QUEUED,
error: null,
request: null,
timeout: null
};
}
const N = () => a(T.serverId), D = (A) => A.status === se.QUEUED || A.status === se.ERROR, w = (A) => {
if (T.aborted) return;
if (A = A || f.find(D), !A) {
f.every((F) => F.status === se.COMPLETE) && N();
return;
}
A.status = se.PROCESSING, A.progress = null;
const B = p.ondata || ((F) => F), O = p.onerror || ((F) => null), y = p.onload || (() => {
}), b = ze(e, p.url, T.serverId), v = typeof p.headers == "function" ? p.headers(A) : {
...p.headers,
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": A.offset,
"Upload-Length": s.size,
"Upload-Name": s.name
}, H = A.request = De(B(A.data), b, {
...p,
headers: v
});
H.onload = (F) => {
y(F, A.index, f.length), A.status = se.COMPLETE, A.request = null, C();
}, H.onprogress = (F, he, Ye) => {
A.progress = F ? he : null, P();
}, H.onerror = (F) => {
A.status = se.ERROR, A.request = null, A.error = O(F.response) || F.statusText, G(A) || i(
W(
"error",
F.status,
O(F.response) || F.statusText,
F.getAllResponseHeaders()
)
);
}, H.ontimeout = (F) => {
A.status = se.ERROR, A.request = null, G(A) || ye(i)(F);
}, H.onabort = () => {
A.status = se.QUEUED, A.request = null, o();
};
}, G = (A) => A.retries.length === 0 ? !1 : (A.status = se.WAITING, clearTimeout(A.timeout), A.timeout = setTimeout(() => {
w(A);
}, A.retries.shift()), !0), P = () => {
const A = f.reduce((O, y) => O === null || y.progress === null ? null : O + y.progress, 0);
if (A === null) return l(!1, 0, 0);
const B = f.reduce((O, y) => O + y.size, 0);
l(!0, A, B);
}, C = () => {