UNPKG

@acrool/react-modal

Version:
1,174 lines (1,170 loc) 36.5 kB
var Kr = Object.defineProperty; var Xr = (t, r, a) => r in t ? Kr(t, r, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[r] = a; var F = (t, r, a) => (Xr(t, typeof r != "symbol" ? r + "" : r, a), a); import V, { useState as Be, useEffect as de, createContext as Ue, useContext as Ze, useId as Vr, useRef as Br, useCallback as Ur } from "react"; import qe from "react-dom"; import { AnimatePresence as Ge, motion as We } from "framer-motion"; var ue = { exports: {} }, Y = {}; /** * @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 Zr() { if (Ye) return Y; Ye = 1; var t = V, r = Symbol.for("react.element"), a = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, f = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 }; function h(g, v, C) { var b, P = {}, j = null, D = null; C !== void 0 && (j = "" + C), v.key !== void 0 && (j = "" + v.key), v.ref !== void 0 && (D = v.ref); for (b in v) i.call(v, b) && !p.hasOwnProperty(b) && (P[b] = v[b]); if (g && g.defaultProps) for (b in v = g.defaultProps, v) P[b] === void 0 && (P[b] = v[b]); return { $$typeof: r, type: g, key: j, ref: D, props: P, _owner: f.current }; } return Y.Fragment = a, Y.jsx = h, Y.jsxs = h, Y; } var L = {}; /** * @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 Le; function qr() { return Le || (Le = 1, process.env.NODE_ENV !== "production" && function() { var t = V, r = Symbol.for("react.element"), a = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), f = Symbol.for("react.strict_mode"), p = Symbol.for("react.profiler"), h = Symbol.for("react.provider"), g = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), b = Symbol.for("react.suspense_list"), P = Symbol.for("react.memo"), j = Symbol.for("react.lazy"), D = Symbol.for("react.offscreen"), ve = Symbol.iterator, or = "@@iterator"; function ir(e) { if (e === null || typeof e != "object") return null; var n = ve && e[ve] || e[or]; return typeof n == "function" ? n : null; } var I = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function _(e) { { for (var n = arguments.length, o = new Array(n > 1 ? n - 1 : 0), s = 1; s < n; s++) o[s - 1] = arguments[s]; sr("error", e, o); } } function sr(e, n, o) { { var s = I.ReactDebugCurrentFrame, u = s.getStackAddendum(); u !== "" && (n += "%s", o = o.concat([u])); var d = o.map(function(l) { return String(l); }); d.unshift("Warning: " + n), Function.prototype.apply.call(console[e], console, d); } } var cr = !1, lr = !1, ur = !1, fr = !1, dr = !1, me; me = Symbol.for("react.module.reference"); function pr(e) { return !!(typeof e == "string" || typeof e == "function" || e === i || e === p || dr || e === f || e === C || e === b || fr || e === D || cr || lr || ur || typeof e == "object" && e !== null && (e.$$typeof === j || e.$$typeof === P || e.$$typeof === h || e.$$typeof === g || e.$$typeof === v || // 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 === me || e.getModuleId !== void 0)); } function vr(e, n, o) { var s = e.displayName; if (s) return s; var u = n.displayName || n.name || ""; return u !== "" ? o + "(" + u + ")" : o; } function ye(e) { return e.displayName || "Context"; } function S(e) { if (e == null) return null; if (typeof e.tag == "number" && _("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 i: return "Fragment"; case a: return "Portal"; case p: return "Profiler"; case f: return "StrictMode"; case C: return "Suspense"; case b: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case g: var n = e; return ye(n) + ".Consumer"; case h: var o = e; return ye(o._context) + ".Provider"; case v: return vr(e, e.render, "ForwardRef"); case P: var s = e.displayName || null; return s !== null ? s : S(e.type) || "Memo"; case j: { var u = e, d = u._payload, l = u._init; try { return S(l(d)); } catch { return null; } } } return null; } var k = Object.assign, O = 0, he, ge, be, _e, Ee, we, Re; function xe() { } xe.__reactDisabledLog = !0; function mr() { { if (O === 0) { he = console.log, ge = console.info, be = console.warn, _e = console.error, Ee = console.group, we = console.groupCollapsed, Re = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: xe, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } O++; } } function yr() { { if (O--, O === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: k({}, e, { value: he }), info: k({}, e, { value: ge }), warn: k({}, e, { value: be }), error: k({}, e, { value: _e }), group: k({}, e, { value: Ee }), groupCollapsed: k({}, e, { value: we }), groupEnd: k({}, e, { value: Re }) }); } O < 0 && _("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var re = I.ReactCurrentDispatcher, te; function q(e, n, o) { { if (te === void 0) try { throw Error(); } catch (u) { var s = u.stack.trim().match(/\n( *(at )?)/); te = s && s[1] || ""; } return ` ` + te + e; } } var ne = !1, G; { var hr = typeof WeakMap == "function" ? WeakMap : Map; G = new hr(); } function Ce(e, n) { if (!e || ne) return ""; { var o = G.get(e); if (o !== void 0) return o; } var s; ne = !0; var u = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var d; d = re.current, re.current = null, mr(); try { if (n) { var l = function() { throw Error(); }; if (Object.defineProperty(l.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(l, []); } catch (R) { s = R; } Reflect.construct(e, [], l); } else { try { l.call(); } catch (R) { s = R; } e.call(l.prototype); } } else { try { throw Error(); } catch (R) { s = R; } e(); } } catch (R) { if (R && s && typeof R.stack == "string") { for (var c = R.stack.split(` `), E = s.stack.split(` `), m = c.length - 1, y = E.length - 1; m >= 1 && y >= 0 && c[m] !== E[y]; ) y--; for (; m >= 1 && y >= 0; m--, y--) if (c[m] !== E[y]) { if (m !== 1 || y !== 1) do if (m--, y--, y < 0 || c[m] !== E[y]) { var x = ` ` + c[m].replace(" at new ", " at "); return e.displayName && x.includes("<anonymous>") && (x = x.replace("<anonymous>", e.displayName)), typeof e == "function" && G.set(e, x), x; } while (m >= 1 && y >= 0); break; } } } finally { ne = !1, re.current = d, yr(), Error.prepareStackTrace = u; } var $ = e ? e.displayName || e.name : "", M = $ ? q($) : ""; return typeof e == "function" && G.set(e, M), M; } function gr(e, n, o) { return Ce(e, !1); } function br(e) { var n = e.prototype; return !!(n && n.isReactComponent); } function H(e, n, o) { if (e == null) return ""; if (typeof e == "function") return Ce(e, br(e)); if (typeof e == "string") return q(e); switch (e) { case C: return q("Suspense"); case b: return q("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case v: return gr(e.render); case P: return H(e.type, n, o); case j: { var s = e, u = s._payload, d = s._init; try { return H(d(u), n, o); } catch { } } } return ""; } var N = Object.prototype.hasOwnProperty, Pe = {}, Se = I.ReactDebugCurrentFrame; function J(e) { if (e) { var n = e._owner, o = H(e.type, e._source, n ? n.type : null); Se.setExtraStackFrame(o); } else Se.setExtraStackFrame(null); } function _r(e, n, o, s, u) { { var d = Function.call.bind(N); for (var l in e) if (d(e, l)) { var c = void 0; try { if (typeof e[l] != "function") { var E = Error((s || "React class") + ": " + o + " type `" + l + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[l] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw E.name = "Invariant Violation", E; } c = e[l](n, l, s, o, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (m) { c = m; } c && !(c instanceof Error) && (J(u), _("%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).", s || "React class", o, l, typeof c), J(null)), c instanceof Error && !(c.message in Pe) && (Pe[c.message] = !0, J(u), _("Failed %s type: %s", o, c.message), J(null)); } } } var Er = Array.isArray; function ae(e) { return Er(e); } function wr(e) { { var n = typeof Symbol == "function" && Symbol.toStringTag, o = n && e[Symbol.toStringTag] || e.constructor.name || "Object"; return o; } } function Rr(e) { try { return je(e), !1; } catch { return !0; } } function je(e) { return "" + e; } function Te(e) { if (Rr(e)) return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", wr(e)), je(e); } var W = I.ReactCurrentOwner, xr = { key: !0, ref: !0, __self: !0, __source: !0 }, ke, Me, oe; oe = {}; function Cr(e) { if (N.call(e, "ref")) { var n = Object.getOwnPropertyDescriptor(e, "ref").get; if (n && n.isReactWarning) return !1; } return e.ref !== void 0; } function Pr(e) { if (N.call(e, "key")) { var n = Object.getOwnPropertyDescriptor(e, "key").get; if (n && n.isReactWarning) return !1; } return e.key !== void 0; } function Sr(e, n) { if (typeof e.ref == "string" && W.current && n && W.current.stateNode !== n) { var o = S(W.current.type); oe[o] || (_('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', S(W.current.type), e.ref), oe[o] = !0); } } function jr(e, n) { { var o = function() { ke || (ke = !0, _("%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)", n)); }; o.isReactWarning = !0, Object.defineProperty(e, "key", { get: o, configurable: !0 }); } } function Tr(e, n) { { var o = function() { Me || (Me = !0, _("%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)", n)); }; o.isReactWarning = !0, Object.defineProperty(e, "ref", { get: o, configurable: !0 }); } } var kr = function(e, n, o, s, u, d, l) { var c = { // This tag allows us to uniquely identify this as a React Element $$typeof: r, // Built-in properties that belong on the element type: e, key: n, ref: o, props: l, // Record the component responsible for creating this element. _owner: d }; return c._store = {}, Object.defineProperty(c._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(c, "_self", { configurable: !1, enumerable: !1, writable: !1, value: s }), Object.defineProperty(c, "_source", { configurable: !1, enumerable: !1, writable: !1, value: u }), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c; }; function Mr(e, n, o, s, u) { { var d, l = {}, c = null, E = null; o !== void 0 && (Te(o), c = "" + o), Pr(n) && (Te(n.key), c = "" + n.key), Cr(n) && (E = n.ref, Sr(n, u)); for (d in n) N.call(n, d) && !xr.hasOwnProperty(d) && (l[d] = n[d]); if (e && e.defaultProps) { var m = e.defaultProps; for (d in m) l[d] === void 0 && (l[d] = m[d]); } if (c || E) { var y = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; c && jr(l, y), E && Tr(l, y); } return kr(e, c, E, u, s, W.current, l); } } var ie = I.ReactCurrentOwner, De = I.ReactDebugCurrentFrame; function A(e) { if (e) { var n = e._owner, o = H(e.type, e._source, n ? n.type : null); De.setExtraStackFrame(o); } else De.setExtraStackFrame(null); } var se; se = !1; function ce(e) { return typeof e == "object" && e !== null && e.$$typeof === r; } function Ie() { { if (ie.current) { var e = S(ie.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function Dr(e) { { if (e !== void 0) { var n = e.fileName.replace(/^.*[\\\/]/, ""), o = e.lineNumber; return ` Check your code at ` + n + ":" + o + "."; } return ""; } } var Ae = {}; function Ir(e) { { var n = Ie(); if (!n) { var o = typeof e == "string" ? e : e.displayName || e.name; o && (n = ` Check the top-level render call using <` + o + ">."); } return n; } } function $e(e, n) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var o = Ir(n); if (Ae[o]) return; Ae[o] = !0; var s = ""; e && e._owner && e._owner !== ie.current && (s = " It was passed a child from " + S(e._owner.type) + "."), A(e), _('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', o, s), A(null); } } function Fe(e, n) { { if (typeof e != "object") return; if (ae(e)) for (var o = 0; o < e.length; o++) { var s = e[o]; ce(s) && $e(s, n); } else if (ce(e)) e._store && (e._store.validated = !0); else if (e) { var u = ir(e); if (typeof u == "function" && u !== e.entries) for (var d = u.call(e), l; !(l = d.next()).done; ) ce(l.value) && $e(l.value, n); } } } function Ar(e) { { var n = e.type; if (n == null || typeof n == "string") return; var o; if (typeof n == "function") o = n.propTypes; else if (typeof n == "object" && (n.$$typeof === v || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. n.$$typeof === P)) o = n.propTypes; else return; if (o) { var s = S(n); _r(o, e.props, "prop", s, e); } else if (n.PropTypes !== void 0 && !se) { se = !0; var u = S(n); _("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown"); } typeof n.getDefaultProps == "function" && !n.getDefaultProps.isReactClassApproved && _("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function $r(e) { { for (var n = Object.keys(e.props), o = 0; o < n.length; o++) { var s = n[o]; if (s !== "children" && s !== "key") { A(e), _("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", s), A(null); break; } } e.ref !== null && (A(e), _("Invalid attribute `ref` supplied to `React.Fragment`."), A(null)); } } var Oe = {}; function Ne(e, n, o, s, u, d) { { var l = pr(e); if (!l) { var c = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (c += " 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 E = Dr(u); E ? c += E : c += Ie(); var m; e === null ? m = "null" : ae(e) ? m = "array" : e !== void 0 && e.$$typeof === r ? (m = "<" + (S(e.type) || "Unknown") + " />", c = " Did you accidentally export a JSX literal instead of a component?") : m = typeof e, _("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", m, c); } var y = Mr(e, n, o, u, d); if (y == null) return y; if (l) { var x = n.children; if (x !== void 0) if (s) if (ae(x)) { for (var $ = 0; $ < x.length; $++) Fe(x[$], e); Object.freeze && Object.freeze(x); } else _("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 Fe(x, e); } if (N.call(n, "key")) { var M = S(e), R = Object.keys(n).filter(function(Lr) { return Lr !== "key"; }), le = R.length > 0 ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!Oe[M + le]) { var Yr = R.length > 0 ? "{" + R.join(": ..., ") + ": ...}" : "{}"; _(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, le, M, Yr, M), Oe[M + le] = !0; } } return e === i ? $r(y) : Ar(y), y; } } function Fr(e, n, o) { return Ne(e, n, o, !0); } function Or(e, n, o) { return Ne(e, n, o, !1); } var Nr = Or, Wr = Fr; L.Fragment = i, L.jsx = Nr, L.jsxs = Wr; }()), L; } process.env.NODE_ENV === "production" ? ue.exports = Zr() : ue.exports = qr(); var w = ue.exports; var Gr = Object.defineProperty, Hr = (t, r, a) => r in t ? Gr(t, r, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[r] = a, fe = (t, r, a) => (Hr(t, typeof r != "symbol" ? r + "" : r, a), a); class He extends V.Component { constructor(r) { super(r), fe(this, "_el"), fe(this, "renderPortal", () => qe.createPortal( this.props.children, this._el )); const a = document.createElement("div"); a.id = r.id, r.className && (a.className = r.className), this._el = a; } get typeProps() { return this.props; } componentDidMount() { const r = this.typeProps.containerSelector(); r == null || r.appendChild(this._el); } componentWillUnmount() { const r = this.typeProps.containerSelector(); r == null || r.removeChild(this._el); } render() { return this.renderPortal(); } } fe(He, "defaultProps", { containerSelector: () => document.body }); const Jr = ({ children: t, containerSelector: r = () => document.body }) => { const [a, i] = Be(!1); return de(() => { i(!0); }, []), (() => { const f = r(); return a && f ? qe.createPortal(t, f) : null; })(); }, Je = "acrool-react-modal", B = [ "color: #fff", "display: inline-block", "font-size: 11px", "line-height: 20px", "padding-right: 8px", "border-radius: 4px" ], U = { primary: "#0055a9", success: "#009422", info: "#17a2b8", warning: "#d7a000", danger: "#ec2127" }; function Z(t, r, ...a) { console.log(`%c ${t}`, r, ...a); } function zr(t, ...r) { const a = B.concat([ `background-color: ${U.primary}` ]).join(";"); Z(t, a, ...r); } function Qr(t, ...r) { const a = B.concat([ `background-color: ${U.success}` ]).join(";"); Z(t, a, ...r); } function et(t, ...r) { const a = B.concat([ `background-color: ${U.info}` ]).join(";"); Z(t, a, ...r); } function rt(t, ...r) { const a = B.concat([ `background-color: ${U.warning}` ]).join(";"); Z(t, a, ...r); } function tt(t, ...r) { const a = B.concat([ `background-color: ${U.danger}` ]).join(";"); Z(t, a, ...r); } const ze = { primary: zr, success: Qr, info: et, warning: rt, danger: tt }, Qe = Ue({ hide: () => ze.warning("No GlobalModal/hide method detected, did you embed your app with Acrool/ModalPortal?") }), Yt = () => Ze(Qe), nt = "acrool-react-modal__root", at = { root: nt }, ee = Ue({ hide: async () => ze.warning("No Modal/hide method detected, did you embed your app with Acrool/ModalPortal?") }); ee.Consumer; const ot = () => Ze(ee); function Q(t) { var r = new Error(t); return r.source = "ulid", r; } var pe = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", X = pe.length, Ke = Math.pow(2, 48) - 1, it = 10, st = 16; function ct(t) { var r = Math.floor(t() * X); return r === X && (r = X - 1), pe.charAt(r); } function lt(t, r) { if (isNaN(t)) throw new Error(t + " must be a number"); if (t > Ke) throw Q("cannot encode time greater than " + Ke); if (t < 0) throw Q("time must be positive"); if (Number.isInteger(t) === !1) throw Q("time must be an integer"); for (var a = void 0, i = ""; r > 0; r--) a = t % X, i = pe.charAt(a) + i, t = (t - a) / X; return i; } function ut(t, r) { for (var a = ""; t > 0; t--) a = ct(r) + a; return a; } function ft() { var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !1, r = arguments[1]; r || (r = typeof window < "u" ? window : null); var a = r && (r.crypto || r.msCrypto); if (a) return function() { var f = new Uint8Array(1); return a.getRandomValues(f), f[0] / 255; }; try { var i = require("crypto"); return function() { return i.randomBytes(1).readUInt8() / 255; }; } catch { } if (t) { try { console.error("secure crypto unusable, falling back to insecure Math.random()!"); } catch { } return function() { return Math.random(); }; } throw Q("secure crypto unusable, insecure Math.random not allowed"); } function dt(t) { return t || (t = ft()), function(a) { return isNaN(a) && (a = Date.now()), lt(a, it) + ut(st, t); }; } var pt = dt(); function vt(t, r) { return r === -1 || r > t.length - 1 ? t : [...t.slice(0, r), ...t.slice(r + 1)]; } function mt(t, r) { return !!t.className.match(new RegExp(`(\\s|^)${r}(\\s|$)`)); } function yt(t, r) { mt(t, r) || t.classList.add(r); } function ht(t, r) { t.classList.remove(r); } function er() { return pt().toLowerCase(); } function gt(t, r) { const a = { isZero: (r == null ? void 0 : r.isZero) ?? !0, isFalse: (r == null ? void 0 : r.isFalse) ?? !0 }; return t == null || a.isFalse && (t === !1 || t === "false") || a.isZero && (t === 0 || t === "0") || !(t instanceof Date) && typeof t == "object" && Object.keys(t).length === 0 || typeof t == "string" && t.trim().length === 0; } let K; class bt extends V.Component { constructor(a) { super(a); F(this, "state", { rows: [] }); /** * 顯示 Toaster * (自動 QueueKey) * @param ModalComponent * @param args */ F(this, "show", (a, i) => { const f = er(); this.showWithKey(a, f, i); }); /** * 顯示 Toaster * (手動 QueueKey) * @param ModalComponent * @param queueKey * @param args */ F(this, "showWithKey", (a, i, f) => { this.setState((p) => { this.typeProps._onShow && this.typeProps._onShow(i); const h = p.rows.findIndex((v) => v.queueKey === i); if (h === -1) return { rows: [...p.rows, { queueKey: i, ModalComponent: a, args: f }] }; const g = [...p.rows]; return g[h] = { queueKey: i, ModalComponent: a, args: f }, { rows: g }; }); }); /** * 隱藏 Toaster * @param queueKey */ F(this, "hide", (a) => { this.setState((i) => { const f = i.rows.findIndex((p) => p.queueKey === a); return { rows: vt(i.rows, f) }; }), this.typeProps._onHide && this.typeProps._onHide(a); }); K = { show: this.show, showWithKey: this.showWithKey, hide: this.hide }; } get typeProps() { return this.props; } /** * 渲染項目 */ renderItems() { const { rows: a } = this.state; return a.map((i) => /* @__PURE__ */ w.jsx( ee.Provider, { value: { queueKey: i.queueKey, hide: async () => { this.hide(i.queueKey); } }, children: /* @__PURE__ */ w.jsx( i.ModalComponent, { ...i.args }, i.queueKey ) }, i.queueKey )); } render() { return /* @__PURE__ */ w.jsxs( Qe.Provider, { value: { hide: this.hide }, children: [ this.props.children, /* @__PURE__ */ w.jsx( He, { id: this.typeProps.id, className: at.root, containerSelector: this.typeProps.containerSelector, children: /* @__PURE__ */ w.jsx(Ge, { mode: this.typeProps.animatePresenceMode, children: this.renderItems() }) } ) ] } ); } } F(bt, "defaultProps", { id: Je }); const rr = "acrool__modal-open", tr = "acrool__modal-open-fixed"; function _t(t, r = !1) { yt(document.body, r ? `${tr}__${t}` : `${rr}__${t}`); } function Et(t, r = !1) { ht(document.body, r ? `${tr}__${t}` : `${rr}__${t}`); } const Xe = { disableBodyScroll: _t, enableBodyScroll: Et }; function nr(t) { var r, a, i = ""; if (typeof t == "string" || typeof t == "number") i += t; else if (typeof t == "object") if (Array.isArray(t)) { var f = t.length; for (r = 0; r < f; r++) t[r] && (a = nr(t[r])) && (i && (i += " "), i += a); } else for (a in t) t[a] && (i && (i += " "), i += a); return i; } function Ve() { for (var t, r, a = 0, i = "", f = arguments.length; a < f; a++) (t = arguments[a]) && (r = nr(t)) && (i && (i += " "), i += r); return i; } const wt = "acrool-react-modal__motion-drawer", Rt = "acrool-react-modal__fixedDisabled", xt = "acrool-react-modal__motion-mask-wrapper", Ct = "acrool-react-modal__motion-animation-wrapper", z = { "motion-drawer": "acrool-react-modal__motion-drawer", motionDrawer: wt, fixedDisabled: Rt, "motion-mask-wrapper": "acrool-react-modal__motion-mask-wrapper", motionMaskWrapper: xt, "motion-animation-wrapper": "acrool-react-modal__motion-animation-wrapper", motionAnimationWrapper: Ct }, Pt = { animation: { variants: { initial: { opacity: 0, transition: { type: "spring" } }, animate: { opacity: 1 }, exit: { opacity: 0 } }, transition: { duration: 0.2 } } }, St = ({ modalOptions: t, children: r }, a) => { const { style: i, className: f, isMaskHidden: p, isHideWithMaskClick: h, isBodyScrollEnable: g, isFixedDisabled: v, animation: C } = t ?? { className: "" }, b = Vr(), { hide: P } = ot(); de(() => (g || Xe.disableBodyScroll(b), () => { g || Xe.enableBodyScroll(b); }), [g]); const j = () => gt(C) ? r : /* @__PURE__ */ w.jsx( We.div, { transition: { type: "spring", duration: 0.2 }, className: Ve(z.motionAnimationWrapper, f), style: i, ...C, initial: "initial", animate: "animate", exit: "exit", children: r } ), D = () => { if (!p) return /* @__PURE__ */ w.jsx( We.div, { className: z.motionMaskWrapper, ...Pt.animation, initial: "initial", animate: "animate", exit: "exit", "data-enable-click": h, onClick: h ? P : void 0 } ); }; return /* @__PURE__ */ w.jsxs("div", { className: Ve(z.motionDrawer, { [z.fixedDisabled]: v }), ref: a, children: [ D(), j() ] }); }, ar = V.forwardRef(St); function Lt(t, r) { return (i) => { const [f, p] = Be(!0), h = Br(), g = (r == null ? void 0 : r.queueKey) ?? er(); de(() => (r != null && r._onShow && r._onShow(g), () => { r != null && r._onHide && r._onHide(g); }), []); const v = () => { h.current && h.current(); }, C = Ur(async () => new Promise((b) => { h.current = b, p(!1); }), []); return /* @__PURE__ */ w.jsx( ee.Provider, { value: { hide: C, queueKey: g }, children: /* @__PURE__ */ w.jsx( Jr, { containerSelector: () => document.getElementById(Je), children: /* @__PURE__ */ w.jsx( Ge, { mode: r == null ? void 0 : r.animatePresenceMode, onExitComplete: v, children: f && /* @__PURE__ */ w.jsx(ar, { modalOptions: r, children: /* @__PURE__ */ w.jsx(t, { ...i }) }) } ) } ) } ); }; } function Kt(t, r) { const a = (p) => /* @__PURE__ */ w.jsx(ar, { modalOptions: r, children: /* @__PURE__ */ w.jsx(t, { ...p }) }); function i(p) { p ? K.show(a, p) : K.show(a); } function f(p, h) { h ? K.showWithKey(a, p, h) : K.showWithKey(a, p); } return a.show = i, a.showWithKey = f, a; } const T = { initial: "initial", animate: "animate", exit: "exit" }, jt = (t = 20, r = 40) => ({ ...T, variants: { initial: { position: "absolute", left: "50%", opacity: 0, x: "-50%", y: t }, animate: { opacity: 1, y: r, transition: { type: "just", duration: 0.2 } }, exit: { opacity: 0, y: t } } }), Tt = (t = 20) => ({ ...T, variants: { initial: { position: "absolute", left: "50%", top: "50%", opacity: 0, x: "-50%", y: `calc(-50% - ${t}px)` }, animate: { opacity: 1, y: "-50%", transition: { type: "just", duration: 0.2 } }, exit: { opacity: 0, y: "-50%" } } }), kt = { ...T, variants: { initial: { scaleX: 0.5, scaleY: 0.5, scaleZ: 0.8, translateX: 0, translateY: 20, translateZ: 0, opacity: 0 }, animate: { scaleX: 1, scaleY: 1, scaleZ: 1, translateX: 0, translateY: 40, translateZ: 0, opacity: 1, transition: { type: "just", duration: 0.2 } }, exit: { scaleX: 0.8, scaleY: 0.8, scaleZ: 0.8, translateX: 0, translateY: 20, translateZ: 0, opacity: 0, transition: { type: "spring" } } } }, Mt = { ...T, variants: { initial: { position: "absolute", top: "50%", left: "50%", scaleX: 0.5, scaleY: 0.5, scaleZ: 0.8, translateX: "-50%", translateY: "-50%", translateZ: 0, opacity: 0 }, animate: { scaleX: 1, scaleY: 1, scaleZ: 1, translateZ: 0, opacity: 1, transition: { type: "spring", duration: 0.4 } }, exit: { scaleX: 0.8, scaleY: 0.8, scaleZ: 0.8, translateZ: 0, opacity: 0 } }, transition: { damping: 0, duration: 0.2 } }, Dt = { ...T, variants: { initial: { position: "fixed", top: 0, bottom: 0, right: 0, translateX: "100%", opacity: 0.9 }, animate: { translateX: 0, opacity: 1 }, exit: { translateX: "100%", opacity: 0.9 } }, transition: { damping: 0 } }, It = { ...T, variants: { initial: { position: "fixed", top: 0, bottom: 0, left: 0, translateX: "-100%", opacity: 0.9 }, animate: { translateX: 0, opacity: 1 }, exit: { translateX: "-100%", opacity: 0.9 } }, transition: { damping: 0 } }, At = { ...T, variants: { initial: { position: "fixed", bottom: 0, left: 0, right: 0, translateY: "100%", opacity: 0.9 }, animate: { translateY: 0, opacity: 1 }, exit: { translateY: "100%", opacity: 0.9 } }, transition: { damping: 0, duration: 0.2 } }, $t = { ...T, variants: { initial: { position: "fixed", top: "100%", left: 0, right: 0, opacity: 0.9 }, animate: { top: 0, opacity: 1, transition: { type: "just" } }, exit: { top: "100%", opacity: 0.9 } }, transition: { damping: 0 } }, Xt = { zoomInDown: kt, zoomInCenter: Mt, generateFadeInFromTop: jt, generateFadeInFromTopCentered: Tt, slideRightInLeft: It, slideLeftInRight: Dt, slideUpInBottom: At, slideUpEndInBottom: $t }; export { Xe as BodyScroll, bt as ModalProvider, Xt as animation, Kt as createModal, Lt as createStateModal, K as modal, Yt as useGlobalModal, ot as useModal };