@kit-data-manager/mapping-service-input
Version:
The mapping-service-input provides a minimalistic user interface for the KIT Data Manager Mapping Service. It allows users to select an existing mapping schema and use it to map their data.
1,522 lines (1,521 loc) • 190 kB
JavaScript
const fi = `<div id="options" class="mapping-options">
<div class="container-wrapper">
<div
id="options-container"
class="options-container"
role="listbox"
aria-label="Available mappings"
aria-describedby="mapping-instructions"
></div>
</div>
</div>
<div
id="message"
class="message-area info"
role="status"
aria-live="polite"
aria-atomic="true"
>
Please select a mapping from the list above.
</div>
<p id="mapping-instructions" class="visually-hidden">
Use Arrow keys to move between mappings. Press Space or Enter to select a mapping.
</p>
<label for="fileUpload" class="visually-hidden">Select a file to be processed by the chosen mapping</label>
<input type="file" id="fileUpload" aria-describedby="file-help" />
<p id="file-help" class="visually-hidden">Only one file up to the configured maximum size is allowed.</p>
<div class="row align-items-center ms-1">
<button
type="submit"
class="btn btn-primary col-auto me-3"
id="submit"
aria-label="Execute mapping"
aria-disabled="true"
>
Execute Mapping
</button>
</div>
`;
/*!
* FilePond 4.32.8
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
const pi = (e) => e instanceof HTMLElement, ui = (e, t = [], n = []) => {
const i = {
...e
}, r = [], o = [], s = () => ({ ...i }), l = () => {
const p = [...r];
return r.length = 0, p;
}, a = () => {
const p = [...o];
o.length = 0, p.forEach(({ type: m, data: S }) => {
d(m, S);
});
}, d = (p, m, S) => {
if (S && !document.hidden) {
o.push({ type: p, data: m });
return;
}
g[p] && g[p](m), r.push({
type: p,
data: m
});
}, c = (p, ...m) => u[p] ? u[p](...m) : null, f = {
getState: s,
processActionQueue: l,
processDispatchQueue: a,
dispatch: d,
query: c
};
let u = {};
t.forEach((p) => {
u = {
...p(i),
...u
};
});
let g = {};
return n.forEach((p) => {
g = {
...p(d, c, i),
...g
};
}), f;
}, Ei = (e, t, n) => {
if (typeof n == "function") {
e[t] = n;
return;
}
Object.defineProperty(e, t, { ...n });
}, U = (e, t) => {
for (const n in e)
e.hasOwnProperty(n) && t(n, e[n]);
}, pe = (e) => {
const t = {};
return U(e, (n) => {
Ei(t, n, e[n]);
}), t;
}, q = (e, t, n = null) => {
if (n === null)
return e.getAttribute(t) || e.hasAttribute(t);
e.setAttribute(t, n);
}, mi = "http://www.w3.org/2000/svg", gi = ["svg", "path"], Ct = (e) => gi.includes(e), qe = (e, t, n = {}) => {
typeof t == "object" && (n = t, t = null);
const i = Ct(e) ? document.createElementNS(mi, e) : document.createElement(e);
return t && (Ct(e) ? q(i, "class", t) : i.className = t), U(n, (r, o) => {
q(i, r, o);
}), i;
}, Ii = (e) => (t, n) => {
typeof n < "u" && e.children[n] ? e.insertBefore(t, e.children[n]) : e.appendChild(t);
}, _i = (e, t) => (n, i) => (typeof i < "u" ? t.splice(i, 0, n) : t.push(n), n), hi = (e, t) => (n) => (t.splice(t.indexOf(n), 1), n.element.parentNode && e.removeChild(n.element), n), Ti = typeof window < "u" && typeof window.document < "u", Sn = () => Ti, Ri = Sn() ? qe("svg") : {}, bi = "children" in Ri ? (e) => e.children.length : (e) => e.childNodes.length, On = (e, t, n, i) => {
const r = n[0] || e.left, o = n[1] || e.top, s = r + e.width, l = o + e.height * (i[1] || 1), a = {
// 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: o,
right: s,
bottom: l
}
};
return t.filter((d) => !d.isRectIgnored()).map((d) => d.rect).forEach((d) => {
vt(a.inner, { ...d.inner }), vt(a.outer, { ...d.outer });
}), Nt(a.inner), a.outer.bottom += a.element.marginBottom, a.outer.right += a.element.marginRight, Nt(a.outer), a;
}, vt = (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);
}, Nt = (e) => {
e.width = e.right - e.left, e.height = e.bottom - e.top;
}, ue = (e) => typeof e == "number", Si = (e, t, n, i = 1e-3) => Math.abs(e - t) < i && Math.abs(n) < i, Oi = (
// default options
({ stiffness: e = 0.5, damping: t = 0.75, mass: n = 10 } = {}) => {
let i = null, r = null, o = 0, s = !1;
const d = pe({
interpolate: (c, f) => {
if (s) return;
if (!(ue(i) && ue(r))) {
s = !0, o = 0;
return;
}
const u = -(r - i) * e;
o += u / n, r += o, o *= t, Si(r, i, o) || f ? (r = i, o = 0, s = !0, d.onupdate(r), d.oncomplete(r)) : d.onupdate(r);
},
target: {
set: (c) => {
if (ue(c) && !ue(r) && (r = c), i === null && (i = c, r = c), i = c, r === i || typeof i > "u") {
s = !0, o = 0, d.onupdate(r), d.oncomplete(r);
return;
}
s = !1;
},
get: () => i
},
resting: {
get: () => s
},
onupdate: (c) => {
},
oncomplete: (c) => {
}
});
return d;
}
), Di = (e) => e < 0.5 ? 2 * e * e : -1 + (4 - 2 * e) * e, yi = (
// default values
({ duration: e = 500, easing: t = Di, delay: n = 0 } = {}) => {
let i = null, r, o, s = !0, l = !1, a = null;
const c = pe({
interpolate: (f, u) => {
s || a === null || (i === null && (i = f), !(f - i < n) && (r = f - i - n, r >= e || u ? (r = 1, o = l ? 0 : 1, c.onupdate(o * a), c.oncomplete(o * a), s = !0) : (o = r / e, c.onupdate((r >= 0 ? t(l ? 1 - o : o) : 0) * a))));
},
target: {
get: () => l ? 0 : a,
set: (f) => {
if (a === null) {
a = f, c.onupdate(f), c.oncomplete(f);
return;
}
f < a ? (a = 1, l = !0) : (l = !1, a = f), s = !1, i = null;
}
},
resting: {
get: () => s
},
onupdate: (f) => {
},
oncomplete: (f) => {
}
});
return c;
}
), Gt = {
spring: Oi,
tween: yi
}, Ai = (e, t, n) => {
const i = e[t] && typeof e[t][n] == "object" ? e[t][n] : e[t] || e, r = typeof i == "string" ? i : i.type, o = typeof i == "object" ? { ...i } : {};
return Gt[r] ? Gt[r](o) : null;
}, _t = (e, t, n, i = !1) => {
t = Array.isArray(t) ? t : [t], t.forEach((r) => {
e.forEach((o) => {
let s = o, l = () => n[o], a = (d) => n[o] = d;
typeof o == "object" && (s = o.key, l = o.getter || l, a = o.setter || a), !(r[s] && !i) && (r[s] = {
get: l,
set: a
});
});
});
}, Li = ({ mixinConfig: e, viewProps: t, viewInternalAPI: n, viewExternalAPI: i }) => {
const r = { ...t }, o = [];
return U(e, (s, l) => {
const a = Ai(l);
if (!a)
return;
a.onupdate = (c) => {
t[s] = c;
}, a.target = r[s], _t([{
key: s,
setter: (c) => {
a.target !== c && (a.target = c);
},
getter: () => t[s]
}], [n, i], t, !0), o.push(a);
}), {
write: (s) => {
let l = document.hidden, a = !0;
return o.forEach((d) => {
d.resting || (a = !1), d.interpolate(s, l);
}), a;
},
destroy: () => {
}
};
}, wi = (e) => (t, n) => {
e.addEventListener(t, n);
}, Mi = (e) => (t, n) => {
e.removeEventListener(t, n);
}, Pi = ({
mixinConfig: e,
viewProps: t,
viewInternalAPI: n,
viewExternalAPI: i,
viewState: r,
view: o
}) => {
const s = [], l = wi(o.element), a = Mi(o.element);
return i.on = (d, c) => {
s.push({
type: d,
fn: c
}), l(d, c);
}, i.off = (d, c) => {
s.splice(s.findIndex((f) => f.type === d && f.fn === c), 1), a(d, c);
}, {
write: () => !0,
destroy: () => {
s.forEach((d) => {
a(d.type, d.fn);
});
}
};
}, Ci = ({ mixinConfig: e, viewProps: t, viewExternalAPI: n }) => {
_t(e, n, t);
}, j = (e) => e != null, vi = {
opacity: 1,
scaleX: 1,
scaleY: 1,
translateX: 0,
translateY: 0,
rotateX: 0,
rotateY: 0,
rotateZ: 0,
originX: 0,
originY: 0
}, Ni = ({ mixinConfig: e, viewProps: t, viewInternalAPI: n, viewExternalAPI: i, view: r }) => {
const o = { ...t }, s = {};
_t(e, [n, i], t);
const l = () => [t.translateX || 0, t.translateY || 0], a = () => [t.scaleX || 0, t.scaleY || 0], d = () => r.rect ? On(r.rect, r.childViews, l(), a()) : null;
return n.rect = { get: d }, i.rect = { get: d }, e.forEach((c) => {
t[c] = typeof o[c] > "u" ? vi[c] : o[c];
}), {
write: () => {
if (Gi(s, t))
return Fi(r.element, t), Object.assign(s, { ...t }), !0;
},
destroy: () => {
}
};
}, Gi = (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;
}, Fi = (e, {
opacity: t,
perspective: n,
translateX: i,
translateY: r,
scaleX: o,
scaleY: s,
rotateX: l,
rotateY: a,
rotateZ: d,
originX: c,
originY: f,
width: u,
height: g
}) => {
let p = "", m = "";
(j(c) || j(f)) && (m += `transform-origin: ${c || 0}px ${f || 0}px;`), j(n) && (p += `perspective(${n}px) `), (j(i) || j(r)) && (p += `translate3d(${i || 0}px, ${r || 0}px, 0) `), (j(o) || j(s)) && (p += `scale3d(${j(o) ? o : 1}, ${j(s) ? s : 1}, 1) `), j(d) && (p += `rotateZ(${d}rad) `), j(l) && (p += `rotateX(${l}rad) `), j(a) && (p += `rotateY(${a}rad) `), p.length && (m += `transform:${p};`), j(t) && (m += `opacity:${t};`, t === 0 && (m += "visibility:hidden;"), t < 1 && (m += "pointer-events:none;")), j(g) && (m += `height:${g}px;`), j(u) && (m += `width:${u}px;`);
const S = e.elementCurrentStyle || "";
(m.length !== S.length || m !== S) && (e.style.cssText = m, e.elementCurrentStyle = m);
}, xi = {
styles: Ni,
listeners: Pi,
animations: Li,
apis: Ci
}, Ft = (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), k = (
// default view definition
({
// element definition
tag: e = "div",
name: t = null,
attributes: n = {},
// view interaction
read: i = () => {
},
write: r = () => {
},
create: o = () => {
},
destroy: s = () => {
},
// hooks
filterFrameActionsForChild: l = (g, p) => p,
didCreateView: a = () => {
},
didWriteView: d = () => {
},
// rect related
ignoreRect: c = !1,
ignoreRectUpdate: f = !1,
// mixins
mixins: u = []
} = {}) => (g, p = {}) => {
const m = qe(e, `filepond--${t}`, n), S = window.getComputedStyle(m, null), h = Ft();
let b = null, A = !1;
const L = [], O = [], P = {}, B = {}, R = [
r
// default writer
], M = [
i
// default reader
], F = [
s
// default destroy
], D = () => m, v = () => L.concat(), W = () => P, _ = (G) => (X, ae) => X(G, ae), x = () => b || (b = On(h, L, [0, 0], [1, 1]), b), I = () => S, T = () => {
b = null, L.forEach((ae) => ae._read()), !(f && h.width && h.height) && Ft(h, m, S);
const X = { root: de, props: p, rect: h };
M.forEach((ae) => ae(X));
}, y = (G, X, ae) => {
let be = X.length === 0;
return R.forEach((K) => {
K({
props: p,
root: de,
actions: X,
timestamp: G,
shouldOptimize: ae
}) === !1 && (be = !1);
}), O.forEach((K) => {
K.write(G) === !1 && (be = !1);
}), L.filter((K) => !!K.element.parentNode).forEach((K) => {
K._write(
G,
l(K, X),
ae
) || (be = !1);
}), L.forEach((K, Ge) => {
K.element.parentNode || (de.appendChild(K.element, Ge), K._read(), K._write(
G,
l(K, X),
ae
), be = !1);
}), A = be, d({
props: p,
root: de,
actions: X,
timestamp: G
}), be;
}, w = () => {
O.forEach((G) => G.destroy()), F.forEach((G) => {
G({ root: de, props: p });
}), L.forEach((G) => G._destroy());
}, H = {
element: {
get: D
},
style: {
get: I
},
childViews: {
get: v
}
}, N = {
...H,
rect: {
get: x
},
// access to custom children references
ref: {
get: W
},
// dom modifiers
is: (G) => t === G,
appendChild: Ii(m),
createChildView: _(g),
linkView: (G) => (L.push(G), G),
unlinkView: (G) => {
L.splice(L.indexOf(G), 1);
},
appendChildView: _i(m, L),
removeChildView: hi(m, L),
registerWriter: (G) => R.push(G),
registerReader: (G) => M.push(G),
registerDestroyer: (G) => F.push(G),
invalidateLayout: () => m.layoutCalculated = !1,
// access to data store
dispatch: g.dispatch,
query: g.query
}, Ne = {
element: {
get: D
},
childViews: {
get: v
},
rect: {
get: x
},
resting: {
get: () => A
},
isRectIgnored: () => c,
_read: T,
_write: y,
_destroy: w
}, Pt = {
...H,
rect: {
get: () => h
}
};
Object.keys(u).sort((G, X) => G === "styles" ? 1 : X === "styles" ? -1 : 0).forEach((G) => {
const X = xi[G]({
mixinConfig: u[G],
viewProps: p,
viewState: B,
viewInternalAPI: N,
viewExternalAPI: Ne,
view: pe(Pt)
});
X && O.push(X);
});
const de = pe(N);
o({
root: de,
props: p
});
const di = bi(m);
return L.forEach((G, X) => {
de.appendChild(G.element, di + X);
}), a(de), pe(Ne);
}
), Bi = (e, t, n = 60) => {
const i = "__framePainter";
if (window[i]) {
window[i].readers.push(e), window[i].writers.push(t);
return;
}
window[i] = {
readers: [e],
writers: [t]
};
const r = window[i], o = 1e3 / n;
let s = null, l = null, a = null, d = null;
const c = () => {
document.hidden ? (a = () => window.setTimeout(() => f(performance.now()), o), d = () => window.clearTimeout(l)) : (a = () => window.requestAnimationFrame(f), d = () => window.cancelAnimationFrame(l));
};
document.addEventListener("visibilitychange", () => {
d && d(), c(), f(performance.now());
});
const f = (u) => {
l = a(f), s || (s = u);
const g = u - s;
g <= o || (s = u - g % o, r.readers.forEach((p) => p()), r.writers.forEach((p) => p(u)));
};
return c(), f(performance.now()), {
pause: () => {
d(l);
}
};
}, Z = (e, t) => ({ root: n, props: i, actions: r = [], timestamp: o, shouldOptimize: s }) => {
r.filter((l) => e[l.type]).forEach(
(l) => e[l.type]({ root: n, props: i, action: l.data, timestamp: o, shouldOptimize: s })
), t && t({ root: n, props: i, actions: r, timestamp: o, shouldOptimize: s });
}, xt = (e, t) => t.parentNode.insertBefore(e, t), Bt = (e, t) => t.parentNode.insertBefore(e, t.nextSibling), Xe = (e) => Array.isArray(e), le = (e) => e == null, Ui = (e) => e.trim(), je = (e) => "" + e, Vi = (e, t = ",") => le(e) ? [] : Xe(e) ? e : je(e).split(t).map(Ui).filter((n) => n.length), Dn = (e) => typeof e == "boolean", yn = (e) => Dn(e) ? e : e === "true", Q = (e) => typeof e == "string", An = (e) => ue(e) ? e : Q(e) ? je(e).replace(/[a-z]+/gi, "") : 0, ke = (e) => parseInt(An(e), 10), Ut = (e) => parseFloat(An(e)), Ae = (e) => ue(e) && isFinite(e) && Math.floor(e) === e, Vt = (e, t = 1e3) => {
if (Ae(e))
return e;
let n = je(e).trim();
return /MB$/i.test(n) ? (n = n.replace(/MB$i/, "").trim(), ke(n) * t * t) : /KB/i.test(n) ? (n = n.replace(/KB$i/, "").trim(), ke(n) * t) : ke(n);
}, Ee = (e) => typeof e == "function", zi = (e) => {
let t = self, n = e.split("."), i = null;
for (; i = n.shift(); )
if (t = t[i], !t)
return null;
return t;
}, zt = {
process: "POST",
patch: "PATCH",
revert: "DELETE",
fetch: "GET",
restore: "GET",
load: "GET"
}, ki = (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 : {}, U(zt, (n) => {
t[n] = Hi(n, e[n], zt[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;
}, Hi = (e, t, n, i, r) => {
if (t === null)
return null;
if (typeof t == "function")
return t;
const o = {
url: n === "GET" || n === "PATCH" ? `?${e}=` : "",
method: n,
headers: r,
withCredentials: !1,
timeout: i,
onload: null,
ondata: null,
onerror: null
};
if (Q(t))
return o.url = t, o;
if (Object.assign(o, t), Q(o.headers)) {
const s = o.headers.split(/:(.+)/);
o.headers = {
header: s[0],
value: s[1]
};
}
return o.withCredentials = yn(o.withCredentials), o;
}, qi = (e) => ki(e), Yi = (e) => e === null, $ = (e) => typeof e == "object" && e !== null, $i = (e) => $(e) && Q(e.url) && $(e.process) && $(e.revert) && $(e.restore) && $(e.fetch), lt = (e) => Xe(e) ? "array" : Yi(e) ? "null" : Ae(e) ? "int" : /^[0-9]+ ?(?:GB|MB|KB)$/gi.test(e) ? "bytes" : $i(e) ? "api" : typeof e, Wi = (e) => e.replace(/{\s*'/g, '{"').replace(/'\s*}/g, '"}').replace(/'\s*:/g, '":').replace(/:\s*'/g, ':"').replace(/,\s*'/g, ',"').replace(/'\s*,/g, '",'), Xi = {
array: Vi,
boolean: yn,
int: (e) => lt(e) === "bytes" ? Vt(e) : ke(e),
number: Ut,
float: Ut,
bytes: Vt,
string: (e) => Ee(e) ? e : je(e),
function: (e) => zi(e),
serverapi: qi,
object: (e) => {
try {
return JSON.parse(Wi(e));
} catch {
return null;
}
}
}, ji = (e, t) => Xi[t](e), Ln = (e, t, n) => {
if (e === t)
return e;
let i = lt(e);
if (i !== n) {
const r = ji(e, n);
if (i = lt(r), r === null)
throw `Trying to assign value with incorrect type to "${option}", allowed type: "${n}"`;
e = r;
}
return e;
}, Qi = (e, t) => {
let n = e;
return {
enumerable: !0,
get: () => n,
set: (i) => {
n = Ln(i, e, t);
}
};
}, Zi = (e) => {
const t = {};
return U(e, (n) => {
const i = e[n];
t[n] = Qi(i[0], i[1]);
}), pe(t);
}, Ki = (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: Zi(e)
}), Qe = (e, t = "-") => e.split(/(?=[A-Z])/).map((n) => n.toLowerCase()).join(t), Ji = (e, t) => {
const n = {};
return U(t, (i) => {
n[i] = {
get: () => e.getState().options[i],
set: (r) => {
e.dispatch(`SET_${Qe(i, "_").toUpperCase()}`, {
value: r
});
}
};
}), n;
}, er = (e) => (t, n, i) => {
const r = {};
return U(e, (o) => {
const s = Qe(o, "_").toUpperCase();
r[`SET_${s}`] = (l) => {
try {
i.options[o] = l.value;
} catch {
}
t(`DID_SET_${s}`, { value: i.options[o] });
};
}), r;
}, tr = (e) => (t) => {
const n = {};
return U(e, (i) => {
n[`GET_${Qe(i, "_").toUpperCase()}`] = (r) => t.options[i];
}), n;
}, ie = {
API: 1,
DROP: 2,
BROWSE: 3,
PASTE: 4,
NONE: 5
}, ht = () => Math.random().toString(36).substring(2, 11), Tt = (e, t) => e.splice(t, 1), nr = (e, t) => {
t ? e() : document.hidden ? Promise.resolve(1).then(e) : setTimeout(e, 0);
}, Ze = () => {
const e = [], t = (i, r) => {
Tt(
e,
e.findIndex((o) => o.event === i && (o.cb === r || !r))
);
}, n = (i, r, o) => {
e.filter((s) => s.event === i).map((s) => s.cb).forEach((s) => nr(() => s(...r), o));
};
return {
fireSync: (i, ...r) => {
n(i, r, !0);
},
fire: (i, ...r) => {
n(i, r, !1);
},
on: (i, r) => {
e.push({ event: i, cb: r });
},
onOnce: (i, r) => {
e.push({
event: i,
cb: (...o) => {
t(i, r), r(...o);
}
});
},
off: t
};
}, wn = (e, t, n) => {
Object.getOwnPropertyNames(e).filter((i) => !n.includes(i)).forEach(
(i) => Object.defineProperty(t, i, Object.getOwnPropertyDescriptor(e, i))
);
}, ir = [
"fire",
"process",
"revert",
"load",
"on",
"off",
"onOnce",
"retryLoad",
"extend",
"archive",
"archived",
"release",
"released",
"requestProcessing",
"freeze"
], J = (e) => {
const t = {};
return wn(e, t, ir), t;
}, rr = (e) => {
e.forEach((t, n) => {
t.released && Tt(e, n);
});
}, C = {
INIT: 1,
IDLE: 2,
PROCESSING_QUEUED: 9,
PROCESSING: 3,
PROCESSING_COMPLETE: 5,
PROCESSING_ERROR: 6,
PROCESSING_REVERT_ERROR: 10,
LOADING: 7,
LOAD_ERROR: 8
}, Y = {
INPUT: 1,
LIMBO: 2,
LOCAL: 3
}, Mn = (e) => /[^0-9]+/.exec(e), Pn = () => Mn(1.1.toLocaleString())[0], sr = () => {
const e = Pn(), t = 1e3.toLocaleString();
return t !== "1000" ? Mn(t)[0] : e === "." ? "," : ".";
}, E = {
BOOLEAN: "boolean",
INT: "int",
NUMBER: "number",
STRING: "string",
ARRAY: "array",
OBJECT: "object",
FUNCTION: "function",
ACTION: "action",
SERVER_API: "serverapi",
REGEX: "regex"
}, Rt = [], re = (e, t, n) => new Promise((i, r) => {
const o = Rt.filter((l) => l.key === e).map((l) => l.cb);
if (o.length === 0) {
i(t);
return;
}
const s = o.shift();
o.reduce(
// loop over promises passing value to next promise
(l, a) => l.then((d) => a(d, n)),
// call initial filter, will return a promise
s(t, n)
// all executed
).then((l) => i(l)).catch((l) => r(l));
}), Te = (e, t, n) => Rt.filter((i) => i.key === e).map((i) => i.cb(t, n)), or = (e, t) => Rt.push({ key: e, cb: t }), ar = (e) => Object.assign(Se, e), Ye = () => ({ ...Se }), lr = (e) => {
U(e, (t, n) => {
Se[t] && (Se[t][0] = Ln(
n,
Se[t][0],
Se[t][1]
));
});
}, Se = {
// the id to add to the root element
id: [null, E.STRING],
// input field name to use
name: ["filepond", E.STRING],
// disable the field
disabled: [!1, E.BOOLEAN],
// classname to put on wrapper
className: [null, E.STRING],
// is the field required
required: [!1, E.BOOLEAN],
// Allow media capture when value is set
captureMethod: [null, E.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, E.BOOLEAN],
// Feature toggles
allowDrop: [!0, E.BOOLEAN],
// Allow dropping of files
allowBrowse: [!0, E.BOOLEAN],
// Allow browsing the file system
allowPaste: [!0, E.BOOLEAN],
// Allow pasting files
allowMultiple: [!1, E.BOOLEAN],
// Allow multiple files (disabled by default, as multiple attribute is also required on input to allow multiple)
allowReplace: [!0, E.BOOLEAN],
// Allow dropping a file on other file to replace it (only works when multiple is set to false)
allowRevert: [!0, E.BOOLEAN],
// Allows user to revert file upload
allowRemove: [!0, E.BOOLEAN],
// Allow user to remove a file
allowProcess: [!0, E.BOOLEAN],
// Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [!1, E.BOOLEAN],
// Allow reordering of files
allowDirectoriesOnly: [!1, E.BOOLEAN],
// Allow only selecting directories with browse (no support for filtering dnd at this point)
// Try store file if `server` not set
storeAsFile: [!1, E.BOOLEAN],
// Revert mode
forceRevert: [!1, E.BOOLEAN],
// Set to 'force' to require the file to be reverted before removal
// Input requirements
maxFiles: [null, E.INT],
// Max number of files
checkValidity: [!1, E.BOOLEAN],
// Enables custom validity messages
// Where to put file
itemInsertLocationFreedom: [!0, E.BOOLEAN],
// Set to false to always add items to begin or end of list
itemInsertLocation: ["before", E.STRING],
// Default index in list to add items that have been dropped at the top of the list
itemInsertInterval: [75, E.INT],
// Drag 'n Drop related
dropOnPage: [!1, E.BOOLEAN],
// Allow dropping of files anywhere on page (prevents browser from opening file if dropped outside of Up)
dropOnElement: [!0, E.BOOLEAN],
// Drop needs to happen on element (set to false to also load drops outside of Up)
dropValidation: [!1, E.BOOLEAN],
// Enable or disable validating files on drop
ignoredFiles: [[".ds_store", "thumbs.db", "desktop.ini"], E.ARRAY],
// Upload related
instantUpload: [!0, E.BOOLEAN],
// Should upload files immediately on drop
maxParallelUploads: [2, E.INT],
// Maximum files to upload in parallel
allowMinimumUploadDuration: [!0, E.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, E.BOOLEAN],
// Enable chunked uploads
chunkForce: [!1, E.BOOLEAN],
// Force use of chunk uploads even for files smaller than chunk size
chunkSize: [5e6, E.INT],
// Size of chunks (5MB default)
chunkRetryDelays: [[500, 1e3, 3e3], E.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, E.SERVER_API],
// File size calculations, can set to 1024, this is only used for display, properties use file size base 1000
fileSizeBase: [1e3, E.INT],
// Labels and status messages
labelFileSizeBytes: ["bytes", E.STRING],
labelFileSizeKilobytes: ["KB", E.STRING],
labelFileSizeMegabytes: ["MB", E.STRING],
labelFileSizeGigabytes: ["GB", E.STRING],
labelDecimalSeparator: [Pn(), E.STRING],
// Default is locale separator
labelThousandsSeparator: [sr(), E.STRING],
// Default is locale separator
labelIdle: [
'Drag & Drop your files or <span class="filepond--label-action">Browse</span>',
E.STRING
],
labelInvalidField: ["Field contains invalid files", E.STRING],
labelFileWaitingForSize: ["Waiting for size", E.STRING],
labelFileSizeNotAvailable: ["Size not available", E.STRING],
labelFileCountSingular: ["file in list", E.STRING],
labelFileCountPlural: ["files in list", E.STRING],
labelFileLoading: ["Loading", E.STRING],
labelFileAdded: ["Added", E.STRING],
// assistive only
labelFileLoadError: ["Error during load", E.STRING],
labelFileRemoved: ["Removed", E.STRING],
// assistive only
labelFileRemoveError: ["Error during remove", E.STRING],
labelFileProcessing: ["Uploading", E.STRING],
labelFileProcessingComplete: ["Upload complete", E.STRING],
labelFileProcessingAborted: ["Upload cancelled", E.STRING],
labelFileProcessingError: ["Error during upload", E.STRING],
labelFileProcessingRevertError: ["Error during revert", E.STRING],
labelTapToCancel: ["tap to cancel", E.STRING],
labelTapToRetry: ["tap to retry", E.STRING],
labelTapToUndo: ["tap to undo", E.STRING],
labelButtonRemoveItem: ["Remove", E.STRING],
labelButtonAbortItemLoad: ["Abort", E.STRING],
labelButtonRetryItemLoad: ["Retry", E.STRING],
labelButtonAbortItemProcessing: ["Cancel", E.STRING],
labelButtonUndoItemProcessing: ["Undo", E.STRING],
labelButtonRetryItemProcessing: ["Retry", E.STRING],
labelButtonProcessItem: ["Upload", E.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>',
E.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>',
E.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>',
E.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>',
E.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>',
E.STRING
],
// event handlers
oninit: [null, E.FUNCTION],
onwarning: [null, E.FUNCTION],
onerror: [null, E.FUNCTION],
onactivatefile: [null, E.FUNCTION],
oninitfile: [null, E.FUNCTION],
onaddfilestart: [null, E.FUNCTION],
onaddfileprogress: [null, E.FUNCTION],
onaddfile: [null, E.FUNCTION],
onprocessfilestart: [null, E.FUNCTION],
onprocessfileprogress: [null, E.FUNCTION],
onprocessfileabort: [null, E.FUNCTION],
onprocessfilerevert: [null, E.FUNCTION],
onprocessfile: [null, E.FUNCTION],
onprocessfiles: [null, E.FUNCTION],
onremovefile: [null, E.FUNCTION],
onpreparefile: [null, E.FUNCTION],
onupdatefiles: [null, E.FUNCTION],
onreorderfiles: [null, E.FUNCTION],
// hooks
beforeDropFile: [null, E.FUNCTION],
beforeAddFile: [null, E.FUNCTION],
beforeRemoveFile: [null, E.FUNCTION],
beforePrepareFile: [null, E.FUNCTION],
// styles
stylePanelLayout: [null, E.STRING],
// null 'integrated', 'compact', 'circle'
stylePanelAspectRatio: [null, E.STRING],
// null or '3:2' or 1
styleItemPanelAspectRatio: [null, E.STRING],
styleButtonRemoveItemPosition: ["left", E.STRING],
styleButtonProcessItemPosition: ["right", E.STRING],
styleLoadIndicatorPosition: ["right", E.STRING],
styleProgressIndicatorPosition: ["right", E.STRING],
styleButtonRemoveItemAlign: [!1, E.BOOLEAN],
// custom initial files array
files: [[], E.ARRAY],
// show support by displaying credits
credits: [["https://pqina.nl/", "Powered by PQINA"], E.ARRAY]
}, me = (e, t) => le(t) ? e[0] || null : Ae(t) ? e[t] || null : (typeof t == "object" && (t = t.id), e.find((n) => n.id === t) || null), Cn = (e) => {
if (le(e))
return e;
if (/:/.test(e)) {
const t = e.split(":");
return t[1] / t[0];
}
return parseFloat(e);
}, se = (e) => e.filter((t) => !t.archived), cr = {
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 Fe = null;
const dr = () => {
if (Fe === 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, Fe = t.files.length === 1;
} catch {
Fe = !1;
}
return Fe;
}, fr = [
C.LOAD_ERROR,
C.PROCESSING_ERROR,
C.PROCESSING_REVERT_ERROR
], pr = [
C.LOADING,
C.PROCESSING,
C.PROCESSING_QUEUED,
C.INIT
], ur = [C.PROCESSING_COMPLETE], Er = (e) => fr.includes(e.status), mr = (e) => pr.includes(e.status), gr = (e) => ur.includes(e.status), kt = (e) => $(e.options.server) && ($(e.options.server.process) || Ee(e.options.server.process)), Ir = (e) => ({
GET_STATUS: () => {
const t = se(e.items), { EMPTY: n, ERROR: i, BUSY: r, IDLE: o, READY: s } = cr;
return t.length === 0 ? n : t.some(Er) ? i : t.some(mr) ? r : t.some(gr) ? s : o;
},
GET_ITEM: (t) => me(e.items, t),
GET_ACTIVE_ITEM: (t) => me(se(e.items), t),
GET_ACTIVE_ITEMS: () => se(e.items),
GET_ITEMS: () => e.items,
GET_ITEM_NAME: (t) => {
const n = me(e.items, t);
return n ? n.filename : null;
},
GET_ITEM_SIZE: (t) => {
const n = me(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 : Cn(e.options.stylePanelAspectRatio),
GET_ITEM_PANEL_ASPECT_RATIO: () => e.options.styleItemPanelAspectRatio,
GET_ITEMS_BY_STATUS: (t) => se(e.items).filter((n) => n.status === t),
GET_TOTAL_ITEMS: () => se(e.items).length,
SHOULD_UPDATE_FILE_INPUT: () => e.options.storeAsFile && dr() && !kt(e),
IS_ASYNC: () => kt(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
})
}), _r = (e) => {
const t = se(e.items).length;
if (!e.options.allowMultiple)
return t === 0;
const n = e.options.maxFiles;
return n === null || t < n;
}, vn = (e, t, n) => Math.max(Math.min(n, e), t), hr = (e, t, n) => e.splice(t, 0, n), Tr = (e, t, n) => le(t) ? null : typeof n > "u" ? (e.push(t), t) : (n = vn(n, 0, e.length), hr(e, n, t), t), ct = (e) => /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*)\s*$/i.test(
e
), ve = (e) => `${e}`.split("/").pop().split("?").shift(), Ke = (e) => e.split(".").pop(), Rr = (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 : "";
}, Le = (e, t = "") => (t + e).slice(-t.length), Nn = (e = /* @__PURE__ */ new Date()) => `${e.getFullYear()}-${Le(e.getMonth() + 1, "00")}-${Le(
e.getDate(),
"00"
)}_${Le(e.getHours(), "00")}-${Le(e.getMinutes(), "00")}-${Le(
e.getSeconds(),
"00"
)}`, ye = (e, t, n = null, i = 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 = Nn()), t && i === null && Ke(t) ? r.name = t : (i = i || Rr(r.type), r.name = t + (i ? "." + i : "")), r;
}, br = () => window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder, Gn = (e, t) => {
const n = br();
if (n) {
const i = new n();
return i.append(e), i.getBlob(t);
}
return new Blob([e], {
type: t
});
}, Sr = (e, t) => {
const n = new ArrayBuffer(e.length), i = new Uint8Array(n);
for (let r = 0; r < e.length; r++)
i[r] = e.charCodeAt(r);
return Gn(n, t);
}, Fn = (e) => (/^data:(.+);/.exec(e) || [])[1] || null, Or = (e) => e.split(",")[1].replace(/\s/g, ""), Dr = (e) => atob(Or(e)), yr = (e) => {
const t = Fn(e), n = Dr(e);
return Sr(n, t);
}, Ar = (e, t, n) => ye(yr(e), t, null, n), Lr = (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;
}, wr = (e) => {
if (/content-length:/i.test(e)) {
const t = e.match(/[0-9]+/)[0];
return t ? parseInt(t, 10) : null;
}
return null;
}, Mr = (e) => /x-content-transfer-id:/i.test(e) && (e.split(":")[1] || "").trim() || null, bt = (e) => {
const t = {
source: null,
name: null,
size: null
}, n = e.split(`
`);
for (let i of n) {
const r = Lr(i);
if (r) {
t.name = r;
continue;
}
const o = wr(i);
if (o) {
t.size = o;
continue;
}
const s = Mr(i);
if (s) {
t.source = s;
continue;
}
}
return t;
}, Pr = (e) => {
const t = {
source: null,
complete: !1,
progress: 0,
size: null,
timestamp: null,
duration: 0,
request: null
}, n = () => t.progress, i = () => {
t.request && t.request.abort && t.request.abort();
}, r = () => {
const l = t.source;
s.fire("init", l), l instanceof File ? s.fire("load", l) : l instanceof Blob ? s.fire("load", ye(l, l.name)) : ct(l) ? s.fire("load", Ar(l)) : o(l);
}, o = (l) => {
if (!e) {
s.fire("error", {
type: "error",
body: "Can't load URL",
code: 400
});
return;
}
t.timestamp = Date.now(), t.request = e(
l,
(a) => {
t.duration = Date.now() - t.timestamp, t.complete = !0, a instanceof Blob && (a = ye(a, a.name || ve(l))), s.fire(
"load",
// if has received blob, we go with blob, if no response, we return null
a instanceof Blob ? a : a ? a.body : null
);
},
(a) => {
s.fire(
"error",
typeof a == "string" ? {
type: "error",
code: 0,
body: a
} : a
);
},
(a, d, c) => {
if (c && (t.size = c), t.duration = Date.now() - t.timestamp, !a) {
t.progress = null;
return;
}
t.progress = d / c, s.fire("progress", t.progress);
},
() => {
s.fire("abort");
},
(a) => {
const d = bt(
typeof a == "string" ? a : a.headers
);
s.fire("meta", {
size: t.size || d.size,
filename: d.name,
source: d.source
});
}
);
}, s = {
...Ze(),
setSource: (l) => t.source = l,
getProgress: n,
// file load progress
abort: i,
// abort file load
load: r
// start load
};
return s;
}, Ht = (e) => /GET|HEAD/.test(e), ge = (e, t, n) => {
const i = {
onheaders: () => {
},
onprogress: () => {
},
onload: () => {
},
ontimeout: () => {
},
onerror: () => {
},
onabort: () => {
},
abort: () => {
r = !0, s.abort();
}
};
let r = !1, o = !1;
n = {
method: "POST",
headers: {},
withCredentials: !1,
...n
}, t = encodeURI(t), Ht(n.method) && e && (t = `${t}${encodeURIComponent(typeof e == "string" ? e : JSON.stringify(e))}`);
const s = new XMLHttpRequest(), l = Ht(n.method) ? s : s.upload;
return l.onprogress = (a) => {
r || i.onprogress(a.lengthComputable, a.loaded, a.total);
}, s.onreadystatechange = () => {
s.readyState < 2 || s.readyState === 4 && s.status === 0 || o || (o = !0, i.onheaders(s));
}, s.onload = () => {
s.status >= 200 && s.status < 300 ? i.onload(s) : i.onerror(s);
}, s.onerror = () => i.onerror(s), s.onabort = () => {
r = !0, i.onabort();
}, s.ontimeout = () => i.ontimeout(s), s.open(n.method, t, !0), Ae(n.timeout) && (s.timeout = n.timeout), Object.keys(n.headers).forEach((a) => {
const d = unescape(encodeURIComponent(n.headers[a]));
s.setRequestHeader(a, d);
}), n.responseType && (s.responseType = n.responseType), n.withCredentials && (s.withCredentials = !0), s.send(e), i;
}, V = (e, t, n, i) => ({
type: e,
code: t,
body: n,
headers: i
}), Ie = (e) => (t) => {
e(V("error", 0, "Timeout", t.getAllResponseHeaders()));
}, qt = (e) => /\?/.test(e), Ce = (...e) => {
let t = "";
return e.forEach((n) => {
t += qt(t) && qt(n) ? n.replace(/\?/, "&") : n;
}), t;
}, tt = (e = "", t) => {
if (typeof t == "function")
return t;
if (!t || !Q(t.url))
return null;
const n = t.onload || ((r) => r), i = t.onerror || ((r) => null);
return (r, o, s, l, a, d) => {
const c = ge(r, Ce(e, t.url), {
...t,
responseType: "blob"
});
return c.onload = (f) => {
const u = f.getAllResponseHeaders(), g = bt(u).name || ve(r);
o(
V(
"load",
f.status,
t.method === "HEAD" ? null : ye(n(f.response), g),
u
)
);
}, c.onerror = (f) => {
s(
V(
"error",
f.status,
i(f.response) || f.statusText,
f.getAllResponseHeaders()
)
);
}, c.onheaders = (f) => {
d(V("headers", f.status, null, f.getAllResponseHeaders()));
}, c.ontimeout = Ie(s), c.onprogress = l, c.onabort = a, c;
};
}, te = {
QUEUED: 0,
COMPLETE: 1,
PROCESSING: 2,
ERROR: 3,
WAITING: 4
}, Cr = (e, t, n, i, r, o, s, l, a, d, c) => {
const f = [], { chunkTransferId: u, chunkServer: g, chunkSize: p, chunkRetryDelays: m } = c, S = {
serverId: u,
aborted: !1
}, h = t.ondata || ((_) => _), b = t.onload || ((_, x) => x === "HEAD" ? _.getResponseHeader("Upload-Offset") : _.response), A = t.onerror || ((_) => null), L = (_) => {
const x = new FormData();
$(r) && x.append(n, JSON.stringify(r));
const I = typeof t.headers == "function" ? t.headers(i, r) : {
...t.headers,
"Upload-Length": i.size
}, T = {
...t,
headers: I
}, y = ge(h(x), Ce(e, t.url), T);
y.onload = (w) => _(b(w, T.method)), y.onerror = (w) => s(
V(
"error",
w.status,
A(w.response) || w.statusText,
w.getAllResponseHeaders()
)
), y.ontimeout = Ie(s);
}, O = (_) => {
const x = Ce(e, g.url, S.serverId), T = {
headers: typeof t.headers == "function" ? t.headers(S.serverId) : {
...t.headers
},
method: "HEAD"
}, y = ge(null, x, T);
y.onload = (w) => _(b(w, T.method)), y.onerror = (w) => s(
V(
"error",
w.status,
A(w.response) || w.statusText,
w.getAllResponseHeaders()
)
), y.ontimeout = Ie(s);
}, P = Math.floor(i.size / p);
for (let _ = 0; _ <= P; _++) {
const x = _ * p, I = i.slice(x, x + p, "application/offset+octet-stream");
f[_] = {
index: _,
size: I.size,
offset: x,
data: I,
file: i,
progress: 0,
retries: [...m],
status: te.QUEUED,
error: null,
request: null,
timeout: null
};
}
const B = () => o(S.serverId), R = (_) => _.status === te.QUEUED || _.status === te.ERROR, M = (_) => {
if (S.aborted) return;
if (_ = _ || f.find(R), !_) {
f.every((N) => N.status === te.COMPLETE) && B();
return;
}
_.status = te.PROCESSING, _.progress = null;
const x = g.ondata || ((N) => N), I = g.onerror || ((N) => null), T = g.onload || (() => {
}), y = Ce(e, g.url, S.serverId), w = typeof g.headers == "function" ? g.headers(_) : {
...g.headers,
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": _.offset,
"Upload-Length": i.size,
"Upload-Name": i.name
}, H = _.request = ge(x(_.data), y, {
...g,
headers: w
});
H.onload = (N) => {
T(N, _.index, f.length), _.status = te.COMPLETE, _.request = null, v();
}, H.onprogress = (N, Ne, Pt) => {
_.progress = N ? Ne : null, D();
}, H.onerror = (N) => {
_.status = te.ERROR, _.request = null, _.error = I(N.response) || N.statusText, F(_) || s(
V(
"error",
N.status,
I(N.response) || N.statusText,
N.getAllResponseHeaders()
)
);
}, H.ontimeout = (N) => {
_.status = te.ERROR, _.request = null, F(_) || Ie(s)(N);
}, H.onabort = () => {
_.status = te.QUEUED, _.request = null, a();
};
}, F = (_) => _.retries.length === 0 ? !1 : (_.status = te.WAITING, clearTimeout(_.timeout), _.timeout = setTimeout(() => {
M(_);
}, _.retries.shift()), !0), D = () => {
const _ = f.reduce((I, T) => I === null || T.progress === null ? null : I + T.progress, 0);
if (_ === null) return l(!1, 0, 0);
const x = f.reduce((I, T) => I + T.size, 0);
l(!0, _, x);
}, v = () => {
f.filter((x) => x.status === te.PROCESSING).length >= 1 || M();
}, W = () => {
f.forEach((_) => {
clearTimeout(_.timeout), _.request && _.request.abort();
});
};
return S.serverId ? O((_) => {
S.aborted || (f.filter((x) => x.offset < _).forEach((x) => {
x.status = te.COMPLETE, x.progress = x.size;
}), v());
}) : L((_) => {
S.aborted || (d(_), S.serverId = _, v());
}), {
abort: () => {
S.aborted = !0, W();
}
};
}, vr = (e, t, n, i) => (r, o, s, l, a, d, c) => {
if (!r) return;
const f = i.chunkUploads, u = f && r.size > i.chunkSize, g = f && (u || i.chunkForce);
if (r instanceof Blob && g)
return Cr(
e,
t,
n,
r,
o,
s,
l,
a,
d,
c,
i
);
const p = t.ondata || ((O) => O), m = t.onload || ((O) => O), S = t.onerror || ((O) => null), h = typeof t.headers == "function" ? t.headers(r, o) || {} : {
...t.headers
}, b = {
...t,
headers: h
};
var A = new FormData();
$(o) && A.append(n, JSON.stringify(o)), (r instanceof Blob ? [{ name: null, file: r }] : r).forEach((O) => {
A.append(
n,
O.file,
O.name === null ? O.file.name : `${O.name}${O.file.name}`
);
});
const L = ge(p(A), Ce(e, t.url), b);
return L.onload = (O) => {
s(V("load", O.status, m(O.response), O.getAllResponseHeaders()));
}, L.onerror = (O) => {
l(
V(
"error",
O.status,
S(O.response) || O.statusText,
O.getAllResponseHeaders()
)
);
}, L.ontimeout = Ie(l), L.onprogress = a, L.onabort = d, L;
}, Nr = (e = "", t, n, i) => typeof t == "function" ? (...r) => t(n, ...r, i) : !t || !Q(t.url) ? null : vr(e, t, n, i), we = (e = "", t) => {
if (typeof t == "function")
return t;
if (!t || !Q(t.url))
return (r, o) => o();
const n = t.onload || ((r) => r), i = t.onerror || ((r) => null);
return (r, o, s) => {
const l = ge(
r,
e + t.url,
t
// contains method, headers and withCredentials properties
);
return l.onload = (a) => {
o(
V(
"load",
a.status,
n(a.response),
a.getAllResponseHeaders()
)
);
}, l.onerror = (a) => {
s(
V(
"error",
a.status,
i(a.response) || a.statusText,
a.getAllResponseHeaders()
)
);
}, l.ontimeout = Ie(s), l;
};
}, xn = (e = 0, t = 1) => e + Math.random() * (t - e), Gr = (e, t = 1e3, n = 0, i = 25, r = 250) => {
let o = null;
const s = Date.now(), l = () => {
let a = Date.now() - s, d = xn(i, r);
a + d > t && (d = a + d - t);
let c = a / t;
if (c >= 1 || document.hidden) {
e(1);
return;
}
e(c), o = setTimeout(l, d);
};
return t > 0 && l(), {
clear: () => {
clearTimeout(o);
}
};
}, Fr = (e, t) => {
const n = {
complete: !1,
perceivedProgress: 0,
perceivedPerformanceUpdater: null,
progress: null,
timestamp: null,
perceivedDuration: 0,
duration: 0,
request: null,
response: null
}, { allowMinimumUploadDuration: i } = t, r = (c, f) => {
const u = () => {
n.duration === 0 || n.progress === null || d.fire("progress", d.getProgress());
}, g = () => {
n.complete = !0, d.fire("load-perceived", n.response.body);
};
d.fire("start"), n.timestamp = Date.now(), n.perceivedPerformanceUpdater = Gr(
(p) => {
n.perceivedProgress = p, n.perceivedDuration = Date.now() - n.timestamp, u(), n.response && n.perceivedProgress === 1 && !n.complete && g();
},
// random delay as in a list of files you start noticing
// files uploading at the exact same speed
i ? xn(750, 1500) : 0
), n.request = e(
// the file to process
c,
// the metadata to send along
f,
// callbacks (load, error, progress, abort, transfer)
// load expects the body to be a server id if
// you want to make use of revert
(p) => {
n.response = $(p) ? p : {
type: "load",
code: 200,
body: `${p}`,
headers: {}
}, n.duration = Date.now() - n.timestamp, n.progress = 1, d.fire("load", n.response.body), (!i || i && n.perceivedProgress === 1) && g();
},
// error is expected to be an object with type, code, body
(p) => {
n.perceivedPerformanceUpdater.clear(), d.fire(
"error",
$(p) ? p : {
type: "error",
code: 0,
body: `${p}`
}
);
},
// actual processing progress
(p, m, S) => {
n.duration = Date.now() - n.timestamp, n.progress = p ? m / S : null, u();
},
// abort do