UNPKG

react-uploadify

Version:

`ReactUploadify` is a flexible npm package that simplifies the process of uploading images from a user's device to a web browser. It offers a set of components and utilities to manage image uploads effectively within React applications.

1,354 lines (1,350 loc) 41.5 kB
import Oe, { createContext as Ze, useReducer as Pt, useEffect as re, useDebugValue as Ct, useCallback as Tt, useContext as Ft } from "react"; function It(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } var De = { exports: {} }, se = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ye; function Lt() { if (Ye) return se; Ye = 1; var t = Oe, o = Symbol.for("react.element"), s = Symbol.for("react.fragment"), p = Object.prototype.hasOwnProperty, h = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, a = { key: !0, ref: !0, __self: !0, __source: !0 }; function d(R, S, y) { var _, O = {}, V = null, N = null; y !== void 0 && (V = "" + y), S.key !== void 0 && (V = "" + S.key), S.ref !== void 0 && (N = S.ref); for (_ in S) p.call(S, _) && !a.hasOwnProperty(_) && (O[_] = S[_]); if (R && R.defaultProps) for (_ in S = R.defaultProps, S) O[_] === void 0 && (O[_] = S[_]); return { $$typeof: o, type: R, key: V, ref: N, props: O, _owner: h.current }; } return se.Fragment = s, se.jsx = d, se.jsxs = d, se; } var ie = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var qe; function Mt() { return qe || (qe = 1, process.env.NODE_ENV !== "production" && function() { var t = Oe, o = Symbol.for("react.element"), s = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), h = Symbol.for("react.strict_mode"), a = Symbol.for("react.profiler"), d = Symbol.for("react.provider"), R = Symbol.for("react.context"), S = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), _ = Symbol.for("react.suspense_list"), O = Symbol.for("react.memo"), V = Symbol.for("react.lazy"), N = Symbol.for("react.offscreen"), B = Symbol.iterator, Q = "@@iterator"; function H(e) { if (e === null || typeof e != "object") return null; var r = B && e[B] || e[Q]; return typeof r == "function" ? r : null; } var z = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function L(e) { { for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), E = 1; E < r; E++) i[E - 1] = arguments[E]; C("error", e, i); } } function C(e, r, i) { { var E = z.ReactDebugCurrentFrame, x = E.getStackAddendum(); x !== "" && (r += "%s", i = i.concat([x])); var P = i.map(function(D) { return String(D); }); P.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, P); } } var U = !1, F = !1, W = !1, J = !1, n = !1, u; u = Symbol.for("react.module.reference"); function f(e) { return !!(typeof e == "string" || typeof e == "function" || e === p || e === a || n || e === h || e === y || e === _ || J || e === N || U || F || W || typeof e == "object" && e !== null && (e.$$typeof === V || e.$$typeof === O || e.$$typeof === d || e.$$typeof === R || e.$$typeof === S || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === u || e.getModuleId !== void 0)); } function l(e, r, i) { var E = e.displayName; if (E) return E; var x = r.displayName || r.name || ""; return x !== "" ? i + "(" + x + ")" : i; } function v(e) { return e.displayName || "Context"; } function m(e) { if (e == null) return null; if (typeof e.tag == "number" && L("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case p: return "Fragment"; case s: return "Portal"; case a: return "Profiler"; case h: return "StrictMode"; case y: return "Suspense"; case _: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case R: var r = e; return v(r) + ".Consumer"; case d: var i = e; return v(i._context) + ".Provider"; case S: return l(e, e.render, "ForwardRef"); case O: var E = e.displayName || null; return E !== null ? E : m(e.type) || "Memo"; case V: { var x = e, P = x._payload, D = x._init; try { return m(D(P)); } catch { return null; } } } return null; } var c = Object.assign, g = 0, T, w, j, M, ue, xe, je; function Pe() { } Pe.__reactDisabledLog = !0; function st() { { if (g === 0) { T = console.log, w = console.info, j = console.warn, M = console.error, ue = console.group, xe = console.groupCollapsed, je = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: Pe, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } g++; } } function it() { { if (g--, g === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: c({}, e, { value: T }), info: c({}, e, { value: w }), warn: c({}, e, { value: j }), error: c({}, e, { value: M }), group: c({}, e, { value: ue }), groupCollapsed: c({}, e, { value: xe }), groupEnd: c({}, e, { value: je }) }); } g < 0 && L("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var ge = z.ReactCurrentDispatcher, he; function le(e, r, i) { { if (he === void 0) try { throw Error(); } catch (x) { var E = x.stack.trim().match(/\n( *(at )?)/); he = E && E[1] || ""; } return ` ` + he + e; } } var Ee = !1, ce; { var at = typeof WeakMap == "function" ? WeakMap : Map; ce = new at(); } function Ce(e, r) { if (!e || Ee) return ""; { var i = ce.get(e); if (i !== void 0) return i; } var E; Ee = !0; var x = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var P; P = ge.current, ge.current = null, st(); try { if (r) { var D = function() { throw Error(); }; if (Object.defineProperty(D.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(D, []); } catch (G) { E = G; } Reflect.construct(e, [], D); } else { try { D.call(); } catch (G) { E = G; } e.call(D.prototype); } } else { try { throw Error(); } catch (G) { E = G; } e(); } } catch (G) { if (G && E && typeof G.stack == "string") { for (var b = G.stack.split(` `), $ = E.stack.split(` `), I = b.length - 1, k = $.length - 1; I >= 1 && k >= 0 && b[I] !== $[k]; ) k--; for (; I >= 1 && k >= 0; I--, k--) if (b[I] !== $[k]) { if (I !== 1 || k !== 1) do if (I--, k--, k < 0 || b[I] !== $[k]) { var Y = ` ` + b[I].replace(" at new ", " at "); return e.displayName && Y.includes("<anonymous>") && (Y = Y.replace("<anonymous>", e.displayName)), typeof e == "function" && ce.set(e, Y), Y; } while (I >= 1 && k >= 0); break; } } } finally { Ee = !1, ge.current = P, it(), Error.prepareStackTrace = x; } var ee = e ? e.displayName || e.name : "", ze = ee ? le(ee) : ""; return typeof e == "function" && ce.set(e, ze), ze; } function ut(e, r, i) { return Ce(e, !1); } function lt(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function fe(e, r, i) { if (e == null) return ""; if (typeof e == "function") return Ce(e, lt(e)); if (typeof e == "string") return le(e); switch (e) { case y: return le("Suspense"); case _: return le("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case S: return ut(e.render); case O: return fe(e.type, r, i); case V: { var E = e, x = E._payload, P = E._init; try { return fe(P(x), r, i); } catch { } } } return ""; } var de = Object.prototype.hasOwnProperty, Te = {}, Fe = z.ReactDebugCurrentFrame; function ve(e) { if (e) { var r = e._owner, i = fe(e.type, e._source, r ? r.type : null); Fe.setExtraStackFrame(i); } else Fe.setExtraStackFrame(null); } function ct(e, r, i, E, x) { { var P = Function.call.bind(de); for (var D in e) if (P(e, D)) { var b = void 0; try { if (typeof e[D] != "function") { var $ = Error((E || "React class") + ": " + i + " type `" + D + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[D] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw $.name = "Invariant Violation", $; } b = e[D](r, D, E, i, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (I) { b = I; } b && !(b instanceof Error) && (ve(x), L("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", E || "React class", i, D, typeof b), ve(null)), b instanceof Error && !(b.message in Te) && (Te[b.message] = !0, ve(x), L("Failed %s type: %s", i, b.message), ve(null)); } } } var ft = Array.isArray; function Re(e) { return ft(e); } function dt(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, i = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return i; } } function vt(e) { try { return Ie(e), !1; } catch { return !0; } } function Ie(e) { return "" + e; } function Le(e) { if (vt(e)) return L("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", dt(e)), Ie(e); } var oe = z.ReactCurrentOwner, pt = { key: !0, ref: !0, __self: !0, __source: !0 }, Me, ke, Se; Se = {}; function mt(e) { if (de.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function gt(e) { if (de.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function ht(e, r) { if (typeof e.ref == "string" && oe.current && r && oe.current.stateNode !== r) { var i = m(oe.current.type); Se[i] || (L('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', m(oe.current.type), e.ref), Se[i] = !0); } } function Et(e, r) { { var i = function() { Me || (Me = !0, L("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; i.isReactWarning = !0, Object.defineProperty(e, "key", { get: i, configurable: !0 }); } } function Rt(e, r) { { var i = function() { ke || (ke = !0, L("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; i.isReactWarning = !0, Object.defineProperty(e, "ref", { get: i, configurable: !0 }); } } var St = function(e, r, i, E, x, P, D) { var b = { // This tag allows us to uniquely identify this as a React Element $$typeof: o, // Built-in properties that belong on the element type: e, key: r, ref: i, props: D, // Record the component responsible for creating this element. _owner: P }; return b._store = {}, Object.defineProperty(b._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(b, "_self", { configurable: !1, enumerable: !1, writable: !1, value: E }), Object.defineProperty(b, "_source", { configurable: !1, enumerable: !1, writable: !1, value: x }), Object.freeze && (Object.freeze(b.props), Object.freeze(b)), b; }; function yt(e, r, i, E, x) { { var P, D = {}, b = null, $ = null; i !== void 0 && (Le(i), b = "" + i), gt(r) && (Le(r.key), b = "" + r.key), mt(r) && ($ = r.ref, ht(r, x)); for (P in r) de.call(r, P) && !pt.hasOwnProperty(P) && (D[P] = r[P]); if (e && e.defaultProps) { var I = e.defaultProps; for (P in I) D[P] === void 0 && (D[P] = I[P]); } if (b || $) { var k = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; b && Et(D, k), $ && Rt(D, k); } return St(e, b, $, x, E, oe.current, D); } } var ye = z.ReactCurrentOwner, Ue = z.ReactDebugCurrentFrame; function Z(e) { if (e) { var r = e._owner, i = fe(e.type, e._source, r ? r.type : null); Ue.setExtraStackFrame(i); } else Ue.setExtraStackFrame(null); } var _e; _e = !1; function be(e) { return typeof e == "object" && e !== null && e.$$typeof === o; } function Ve() { { if (ye.current) { var e = m(ye.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function _t(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), i = e.lineNumber; return ` Check your code at ` + r + ":" + i + "."; } return ""; } } var Ne = {}; function bt(e) { { var r = Ve(); if (!r) { var i = typeof e == "string" ? e : e.displayName || e.name; i && (r = ` Check the top-level render call using <` + i + ">."); } return r; } } function Be(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var i = bt(r); if (Ne[i]) return; Ne[i] = !0; var E = ""; e && e._owner && e._owner !== ye.current && (E = " It was passed a child from " + m(e._owner.type) + "."), Z(e), L('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', i, E), Z(null); } } function We(e, r) { { if (typeof e != "object") return; if (Re(e)) for (var i = 0; i < e.length; i++) { var E = e[i]; be(E) && Be(E, r); } else if (be(e)) e._store && (e._store.validated = !0); else if (e) { var x = H(e); if (typeof x == "function" && x !== e.entries) for (var P = x.call(e), D; !(D = P.next()).done; ) be(D.value) && Be(D.value, r); } } } function wt(e) { { var r = e.type; if (r == null || typeof r == "string") return; var i; if (typeof r == "function") i = r.propTypes; else if (typeof r == "object" && (r.$$typeof === S || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === O)) i = r.propTypes; else return; if (i) { var E = m(r); ct(i, e.props, "prop", E, e); } else if (r.PropTypes !== void 0 && !_e) { _e = !0; var x = m(r); L("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", x || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && L("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function Dt(e) { { for (var r = Object.keys(e.props), i = 0; i < r.length; i++) { var E = r[i]; if (E !== "children" && E !== "key") { Z(e), L("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", E), Z(null); break; } } e.ref !== null && (Z(e), L("Invalid attribute `ref` supplied to `React.Fragment`."), Z(null)); } } function $e(e, r, i, E, x, P) { { var D = f(e); if (!D) { var b = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (b += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var $ = _t(x); $ ? b += $ : b += Ve(); var I; e === null ? I = "null" : Re(e) ? I = "array" : e !== void 0 && e.$$typeof === o ? (I = "<" + (m(e.type) || "Unknown") + " />", b = " Did you accidentally export a JSX literal instead of a component?") : I = typeof e, L("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", I, b); } var k = yt(e, r, i, x, P); if (k == null) return k; if (D) { var Y = r.children; if (Y !== void 0) if (E) if (Re(Y)) { for (var ee = 0; ee < Y.length; ee++) We(Y[ee], e); Object.freeze && Object.freeze(Y); } else L("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else We(Y, e); } return e === p ? Dt(k) : wt(k), k; } } function Ot(e, r, i) { return $e(e, r, i, !0); } function At(e, r, i) { return $e(e, r, i, !1); } var xt = At, jt = Ot; ie.Fragment = p, ie.jsx = xt, ie.jsxs = jt; }()), ie; } process.env.NODE_ENV === "production" ? De.exports = Lt() : De.exports = Mt(); var A = De.exports, et = { exports: {} }; /*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames */ (function(t) { (function() { var o = {}.hasOwnProperty; function s() { for (var a = "", d = 0; d < arguments.length; d++) { var R = arguments[d]; R && (a = h(a, p(R))); } return a; } function p(a) { if (typeof a == "string" || typeof a == "number") return a; if (typeof a != "object") return ""; if (Array.isArray(a)) return s.apply(null, a); if (a.toString !== Object.prototype.toString && !a.toString.toString().includes("[native code]")) return a.toString(); var d = ""; for (var R in a) o.call(a, R) && a[R] && (d = h(d, R)); return d; } function h(a, d) { return d ? a ? a + " " + d : a + d : a; } t.exports ? (s.default = s, t.exports = s) : window.classNames = s; })(); })(et); var kt = et.exports; const X = /* @__PURE__ */ It(kt); let Ut = 0; function K(t, o) { const s = `atom${++Ut}`, p = { toString: () => s }; return typeof t == "function" ? p.read = t : (p.init = t, p.read = function(h) { return h(this); }, p.write = function(h, a, d) { return a( this, typeof d == "function" ? d(h(this)) : d ); }), o && (p.write = o), p; } const Je = (t) => "init" in t, Ge = (t) => !!t.write, me = /* @__PURE__ */ new WeakMap(), Vt = (t, o) => { me.set(t, o), t.catch(() => { }).finally(() => me.delete(t)); }, He = (t, o) => { const s = me.get(t); s && (me.delete(t), s(o)); }, Ke = (t, o) => { t.status = "fulfilled", t.value = o; }, Qe = (t, o) => { t.status = "rejected", t.reason = o; }, Nt = (t) => typeof (t == null ? void 0 : t.then) == "function", ae = (t, o) => !!t && "v" in t && "v" in o && Object.is(t.v, o.v), Xe = (t, o) => !!t && "e" in t && "e" in o && Object.is(t.e, o.e), te = (t) => !!t && "v" in t && t.v instanceof Promise, Bt = (t, o) => "v" in t && "v" in o && t.v.orig && t.v.orig === o.v.orig, pe = (t) => { if ("e" in t) throw t.e; return t.v; }, Wt = () => { const t = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new Map(); let p, h; const a = (n) => t.get(n), d = (n, u) => { const f = t.get(n); if (t.set(n, u), s.has(n) || s.set(n, f), te(f)) { const l = "v" in u ? u.v instanceof Promise ? u.v : Promise.resolve(u.v) : Promise.reject(u.e); f.v !== l && He(f.v, l); } }, R = (n, u, f) => { const l = /* @__PURE__ */ new Map(); let v = !1; f.forEach((m, c) => { !m && c === n && (m = u), m && (l.set(c, m), u.d.get(c) !== m && (v = !0)); }), (v || u.d.size !== l.size) && (u.d = l); }, S = (n, u, f) => { const l = a(n), v = { d: (l == null ? void 0 : l.d) || /* @__PURE__ */ new Map(), v: u }; if (f && R(n, v, f), ae(l, v) && l.d === v.d) return l; if (te(l) && te(v) && Bt(l, v)) { if (l.d === v.d) return l; v.v = l.v; } return d(n, v), v; }, y = (n, u, f, l) => { if (Nt(u)) { let v; const m = () => { const g = a(n); if (!te(g) || g.v !== c) return; const T = S( n, c, f ); o.has(n) && g.d !== T.d && F(n, T, g.d); }, c = new Promise((g, T) => { let w = !1; u.then( (j) => { w || (w = !0, Ke(c, j), g(j), m()); }, (j) => { w || (w = !0, Qe(c, j), T(j), m()); } ), v = (j) => { w || (w = !0, j.then( (M) => Ke(c, M), (M) => Qe(c, M) ), g(j)); }; }); return c.orig = u, c.status = "pending", Vt(c, (g) => { g && v(g), l == null || l(); }), S(n, c, f); } return S(n, u, f); }, _ = (n, u, f) => { const l = a(n), v = { d: (l == null ? void 0 : l.d) || /* @__PURE__ */ new Map(), e: u }; return f && R(n, v, f), Xe(l, v) && l.d === v.d ? l : (d(n, v), v); }, O = (n, u) => { const f = a(n); if (!u && f && (o.has(n) || Array.from(f.d).every(([w, j]) => { if (w === n) return !0; const M = O(w); return M === j || ae(M, j); }))) return f; const l = /* @__PURE__ */ new Map(); let v = !0; const m = (w) => { if (w === n) { const M = a(w); if (M) return l.set(w, M), pe(M); if (Je(w)) return l.set(w, void 0), w.init; throw new Error("no atom init"); } const j = O(w); return l.set(w, j), pe(j); }; let c, g; const T = { get signal() { return c || (c = new AbortController()), c.signal; }, get setSelf() { return !g && Ge(n) && (g = (...w) => { if (!v) return L(n, ...w); }), g; } }; try { const w = n.read(m, T); return y( n, w, l, () => c == null ? void 0 : c.abort() ); } catch (w) { return _(n, w, l); } finally { v = !1; } }, V = (n) => pe(O(n)), N = (n) => { let u = o.get(n); return u || (u = C(n)), u; }, B = (n, u) => !u.l.size && (!u.t.size || u.t.size === 1 && u.t.has(n)), Q = (n) => { const u = o.get(n); u && B(n, u) && U(n); }, H = (n) => { const u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new WeakMap(), l = (c) => { var g; const T = new Set((g = o.get(c)) == null ? void 0 : g.t); return s.forEach((w, j) => { var M; (M = a(j)) != null && M.d.has(c) && T.add(j); }), T; }, v = (c) => { l(c).forEach((g) => { g !== c && (u.set( g, (u.get(g) || /* @__PURE__ */ new Set()).add(c) ), f.set(g, (f.get(g) || 0) + 1), v(g)); }); }; v(n); const m = (c) => { l(c).forEach((g) => { var T; if (g !== c) { let w = f.get(g); if (w && f.set(g, --w), !w) { let j = !!((T = u.get(g)) != null && T.size); if (j) { const M = a(g), ue = O(g, !0); j = !ae(M, ue); } j || u.forEach((M) => M.delete(g)); } m(g); } }); }; m(n); }, z = (n, ...u) => { let f = !0; const l = (c) => pe(O(c)), v = (c, ...g) => { let T; if (c === n) { if (!Je(c)) throw new Error("atom not writable"); const w = a(c), j = y(c, g[0]); ae(w, j) || H(c); } else T = z(c, ...g); if (!f) { const w = W(); } return T; }, m = n.write(l, v, ...u); return f = !1, m; }, L = (n, ...u) => { const f = z(n, ...u), l = W(); return f; }, C = (n, u, f) => { var l; const v = f || []; (l = a(n)) == null || l.d.forEach((c, g) => { const T = o.get(g); T ? T.t.add(n) : g !== n && C(g, n, v); }), O(n); const m = { t: new Set(u && [u]), l: /* @__PURE__ */ new Set() }; if (o.set(n, m), Ge(n) && n.onMount) { const { onMount: c } = n; v.push(() => { const g = c((...T) => L(n, ...T)); g && (m.u = g); }); } return f || v.forEach((c) => c()), m; }, U = (n) => { var u; const f = (u = o.get(n)) == null ? void 0 : u.u; f && f(), o.delete(n); const l = a(n); l && (te(l) && He(l.v), l.d.forEach((v, m) => { if (m !== n) { const c = o.get(m); c && (c.t.delete(n), B(m, c) && U(m)); } })); }, F = (n, u, f) => { const l = new Set(u.d.keys()); f == null || f.forEach((v, m) => { if (l.has(m)) { l.delete(m); return; } const c = o.get(m); c && (c.t.delete(n), B(m, c) && U(m)); }), l.forEach((v) => { const m = o.get(v); m ? m.t.add(n) : o.has(n) && C(v, n); }); }, W = () => { let n; for (; s.size; ) { const u = Array.from(s); s.clear(), u.forEach(([f, l]) => { const v = a(f); if (v) { const m = o.get(f); m && v.d !== (l == null ? void 0 : l.d) && F(f, v, l == null ? void 0 : l.d), m && !// TODO This seems pretty hacky. Hope to fix it. // Maybe we could `mountDependencies` in `setAtomState`? (!te(l) && (ae(l, v) || Xe(l, v))) && m.l.forEach((c) => c()); } }); } }; return { get: V, set: L, sub: (n, u) => { const f = N(n), l = W(), v = f.l; return v.add(u), () => { v.delete(u), Q(n); }; } }; }; let we; const $t = () => (we || (we = Wt()), we), zt = Ze(void 0), tt = (t) => { const o = Ft(zt); return (t == null ? void 0 : t.store) || o || $t(); }, Yt = (t) => typeof (t == null ? void 0 : t.then) == "function", qt = Oe.use || ((t) => { if (t.status === "pending") throw t; if (t.status === "fulfilled") return t.value; throw t.status === "rejected" ? t.reason : (t.status = "pending", t.then( (o) => { t.status = "fulfilled", t.value = o; }, (o) => { t.status = "rejected", t.reason = o; } ), t); }); function Jt(t, o) { const s = tt(o), [[p, h, a], d] = Pt( (y) => { const _ = s.get(t); return Object.is(y[0], _) && y[1] === s && y[2] === t ? y : [_, s, t]; }, void 0, () => [s.get(t), s, t] ); let R = p; (h !== s || a !== t) && (d(), R = s.get(t)); const S = o == null ? void 0 : o.delay; return re(() => { const y = s.sub(t, () => { if (typeof S == "number") { setTimeout(d, S); return; } d(); }); return d(), y; }, [s, t, S]), Ct(R), Yt(R) ? qt(R) : R; } function Gt(t, o) { const s = tt(o); return Tt( (...h) => s.set(t, ...h), [s, t] ); } function q(t, o) { return [ Jt(t, o), // We do wrong type assertion here, which results in throwing an error. Gt(t, o) ]; } const Ht = { kb: 1024, mb: 1048576 }, Kt = (t) => t === "89504E47" || t === "47494638" ? !0 : !!t.startsWith("FFD8"), Qt = (t) => new Promise((o) => { if (t) { const s = new FileReader(); s.onloadend = () => { const p = s.result, h = new Uint8Array(p).subarray(0, 4), a = Array.from(h).map((d) => d.toString(16)).join("").toUpperCase(); o(Kt(a)); }, s.readAsArrayBuffer(t); } else o(!1); }), Xt = (t) => { const o = document.createElement("canvas"), s = o.getContext("2d"); return o.width = t.width, o.height = t.height, s == null || s.drawImage(t, 0, 0), o; }, Zt = (t) => { const o = t[1], s = t[3].toLowerCase(); return { number: +o, letters: s }; }, er = (t) => { const o = /^(\d+(\.\d+)?)([km]b)$/; return t.match(o); }, tr = (t) => { if (t) { const o = er(t), s = Zt(o); if (s) { const { number: p, letters: h } = s; return Ht[h] * p; } } }, rr = async (t, o) => new Promise((s, p) => { const h = new FileReader(); h.onload = (a) => { var R; const d = new Image(); d.src = (R = a == null ? void 0 : a.target) == null ? void 0 : R.result, d.onload = () => { Xt(d).toBlob((y) => y && s(y), "image/jpeg", o); }; }, h.onerror = (a) => p(a), h.readAsDataURL(t); }), rt = async (t, o, s = 100, p = "", h) => { const a = h ? t : t.target.files; if (a) { const d = [], R = Array.from(a).map(async (O) => await Qt(O)); if (Array.from( await Promise.all(R) ).some((O) => !O)) return "Invalid image detected..."; const y = Array.from(a); let _ = !1; if (y.length <= s) { const O = y.map(async (V) => { if (p) { const N = tr(p); V.size > N && (_ = !0); } if (!_) { const N = await rr( V, o / 100 ); return d.push(N), new Promise( (B) => { if (N) { const Q = new FileReader(); Q.onload = (H) => { var z; return B((z = H == null ? void 0 : H.target) == null ? void 0 : z.result); }, Q.readAsDataURL(N); } else B(null); } ); } }); return _ ? `Maximum image size allowed is ${p.toUpperCase()}` : { images: await Promise.all(O), reducedImageQuality: d }; } return `A maximum of ${s} images is required.`; } else return { images: [], reducedImageQuality: [] }; }, nr = async (t, o, s = 100, p = "") => { t.preventDefault(); const h = [...t.dataTransfer.items].map( (a) => a.getAsFile() ); return await rt( h, o, s, p, !0 ); }, or = K([]), sr = K([]), ir = K(1), Ae = K(100), nt = K(""), ot = K(!1), ar = K({ message: "" }), ur = K([{ type: "", size: 0 }]), ne = () => { const [t] = q(Ae), [o, s] = q(ar), [p, h] = q(sr), [a, d] = q(ur), [R, S] = q(or), [y, _] = q(ir), [O, V] = q(ot); re(() => { (() => { const U = R.map( ({ size: F, type: W }) => ({ size: F, type: W }) ); d(U); })(); }, [R]); const N = (C) => { if (C) { s({ message: "" }); const { images: U, reducedImageQuality: F } = C; h((W) => [...W, ...U]), S((W) => [...W, ...F]); } else s({ message: C }); }, B = (C, U) => { U ? (s({ message: U }), _((F) => F - 1)) : (s({ message: `A maximum of ${C} images required.` }), p.length ? _(p.length + 1) : _(1)); }; return { error: o, reset: () => { h([]), _(0), S([]), V(!1), s({ message: "" }), d([{ type: "", size: 0 }]); }, images: p, details: a, setImages: h, blobImages: R, setBlobImages: S, isDraggedOver: O, handleDropFile: async (C, U, F = t, W = "") => { const J = [...C.dataTransfer.items].length; if (_((n) => n + J), y + J - 1 <= F) { const n = await nr( C, U, t, W ); typeof n == "string" ? B(F, n) : N(n); } else B(F); }, handleSelectFile: async (C, U, F = t, W = "") => { var n, u; const J = (u = (n = C == null ? void 0 : C.target) == null ? void 0 : n.files) == null ? void 0 : u.length; if (_((f) => f + J), y + J - 1 <= F) { const f = await rt( C, U, F, W ); typeof f == "string" ? B(F, f) : N(f); } else B(F); }, handleDeleteImage: (C) => { const U = p.filter((W, J) => J !== C), F = R; F.splice(C, 1), S(F), V(!1), s({ message: "" }), _(y - 1), h([...U]); } }; }, lr = ({ className: t, deleteIcon: o, imageClassName: s, deleteButtonClassName: p }) => { const { images: h, handleDeleteImage: a } = ne(); return /* @__PURE__ */ A.jsx(A.Fragment, { children: h.length ? /* @__PURE__ */ A.jsx("div", { className: X("mt-3 flex gap-2 w-full", t), children: h.map((d, R) => /* @__PURE__ */ A.jsxs("div", { className: "relative", children: [ /* @__PURE__ */ A.jsx("img", { className: X("w-20", s), src: d }), /* @__PURE__ */ A.jsx( "button", { onClick: () => a(R), className: X( "absolute top-0 right-0 opacity-50 hover:opacity-100 transition", p ), children: o || "X" } ) ] }, R)) }) : "" }); }, cr = ({ limit: t, quality: o, content: s, fileSizeLimit: p }) => { const { handleSelectFile: h } = ne(), [a, d] = q(Ae), [R, S] = q(nt); return re(() => { (() => t && d(t))(); }, []), re(() => { (() => p && S(p))(); }, []), /* @__PURE__ */ A.jsxs(A.Fragment, { children: [ /* @__PURE__ */ A.jsx( "input", { hidden: !0, multiple: !0, type: "file", id: "fileUpload", className: "w-52", name: "fileUpload", onClick: (y) => y.target.value = "", onChange: (y) => h(y, o, a, R) } ), /* @__PURE__ */ A.jsx("label", { htmlFor: "fileUpload", children: s || "Upload" }) ] }); }; Ze(null); const fr = ({ limit: t, quality: o, content: s, className: p, fileSizeLimit: h }) => { const { handleDropFile: a } = ne(), [d, R] = q(Ae), [S, y] = q(nt), [, _] = q(ot); return re(() => { (() => t && R(t))(); }, [t]), re(() => { (() => h && y(h))(); }, [h]), /* @__PURE__ */ A.jsx(A.Fragment, { children: /* @__PURE__ */ A.jsx( "div", { className: p, id: "drop_zone", onDrop: (O) => (a(O, o, d, S), O.preventDefault()), onDragOver: (O) => (O.preventDefault(), _(!0)), onDragExit: () => _(!1), onDragLeave: () => _(!1), children: s || /* @__PURE__ */ A.jsx("div", { children: /* @__PURE__ */ A.jsx("p", { children: "Drag and Drop image(s) here." }) }) } ) }); }, dr = ({ text: t, limit: o, quality: s, selectText: p, fileSizeLimit: h, selectClassName: a, errorMessageClassName: d }) => { const { error: R } = ne(); return /* @__PURE__ */ A.jsxs("div", { className: "flex flex-col justify-center items-center", children: [ /* @__PURE__ */ A.jsxs("div", { className: "text-center", children: [ t ? /* @__PURE__ */ A.jsx("p", { children: t }) : /* @__PURE__ */ A.jsx("p", { className: "text-xl text-gray-700", children: "Drag and Drop image(s) here." }), /* @__PURE__ */ A.jsx("p", { className: X("text-red-500 text-sm py-1", d), children: R.message }) ] }), /* @__PURE__ */ A.jsx( cr, { limit: o, quality: s, fileSizeLimit: h, content: /* @__PURE__ */ A.jsx( "div", { className: X( "cursor-pointer px-[16px] py-[4px] bg-gray-500 hover:bg-gray-700 transition rounded-md text-white", a ), children: p || "Browse" } ) } ) ] }); }, vr = () => /* @__PURE__ */ A.jsxs( "svg", { width: "24", fill: "none", height: "24", strokeWidth: "2", viewBox: "0 0 24 24", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", xmlns: "http://www.w3.org/2000/svg", children: [ /* @__PURE__ */ A.jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ A.jsx("path", { d: "m6 6 12 12" }) ] } ), pr = { end: "justify-end", start: "justify-start", center: "justify-center" }, gr = ({ text: t, align: o, limit: s, quality: p, className: h, selectText: a, deleteIcon: d, hideImages: R, fileSizeLimit: S, imageClassName: y, imagesClassName: _, selectClassName: O, errorMessageClassName: V, deleteButtonClassName: N }) => { const { isDraggedOver: B } = ne(); return /* @__PURE__ */ A.jsxs(A.Fragment, { children: [ /* @__PURE__ */ A.jsx( "div", { className: X( "border-2 border-dashed h-72 rounded-md p-4 m-4 relative text-gray-700 flex flex-col justify-center items-center", h, B && "border-red-500 transition" ), children: /* @__PURE__ */ A.jsx( fr, { className: "w-full h-full flex justify-center items-center", quality: p, limit: s, fileSizeLimit: S, content: /* @__PURE__ */ A.jsx( dr, { text: t, limit: s, quality: p, selectText: a, fileSizeLimit: S, selectClassName: O, errorMessageClassName: V } ) } ) } ), !R && /* @__PURE__ */ A.jsx( lr, { imageClassName: y, deleteIcon: d || /* @__PURE__ */ A.jsx(vr, {}), deleteButtonClassName: N, className: X(o && pr[o], _, "px-5") } ) ] }); }, hr = () => { const { blobImages: t, details: o, error: s, images: p, isDraggedOver: h, reset: a } = ne(); return { blobImages: t, details: o, error: s, images: p, isDraggedOver: h, reset: a }; }; export { fr as DragAndDrop, cr as ImageSelect, gr as ImageUpload, lr as Images, hr as useImageUpload }; //# sourceMappingURL=index.es.js.map