react-modal-navigation 1.1.10 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,1040 +1,1789 @@
1
- import { jsx as s, jsxs as ce } from "react/jsx-runtime";
2
- import be, { createContext as ie, useRef as l, useState as pe, useEffect as Q, useCallback as w, useMemo as K, useSyncExternalStore as fe, useLayoutEffect as He, Suspense as bn, useReducer as qn, useInsertionEffect as zn, useContext as oe } from "react";
3
- import { createPortal as On } from "react-dom";
4
- const yn = ie(null), vn = ie(null), je = ie(null), Me = ie(null), tn = ie(null), rn = ie(null), _e = ie(null), We = ie(null), Ue = ie(null), xn = ie(null), wn = ie(null), on = ie(null);
5
- function kn(e) {
6
- let n = e;
7
- const r = /* @__PURE__ */ new Set();
1
+ import { jsx as p, jsxs as be } from "react/jsx-runtime";
2
+ import Se, { createContext as we, useState as xe, useEffect as U, useRef as P, useMemo as Q, useSyncExternalStore as Oe, useContext as ee, memo as rt, useCallback as _, useReducer as dn, useLayoutEffect as Ae, Suspense as Wt, useInsertionEffect as mn } from "react";
3
+ import { createPortal as pn } from "react-dom";
4
+ function je(e) {
5
+ let t = e;
6
+ const n = /* @__PURE__ */ new Set();
7
+ let r = !1;
8
8
  return {
9
- getSnapshot: () => n,
10
- subscribe: (t) => (r.add(t), () => r.delete(t)),
11
- publish(t) {
12
- if (n !== t) {
13
- n = t;
14
- for (const i of [...r]) i();
9
+ getSnapshot: () => t,
10
+ subscribe: (o) => (r || n.add(o), () => n.delete(o)),
11
+ publish(o) {
12
+ if (!(r || Object.is(t, o))) {
13
+ t = o;
14
+ for (const a of [...n])
15
+ if (!(r || !n.has(a)))
16
+ try {
17
+ const l = a();
18
+ l && typeof l.then == "function" && Promise.resolve(l).catch((f) => console.error(f));
19
+ } catch (l) {
20
+ console.error(l);
21
+ }
15
22
  }
16
23
  },
17
- listenerCount: () => r.size
18
- };
19
- }
20
- function Te(e) {
21
- let n = e;
22
- const r = /* @__PURE__ */ new Set();
23
- return {
24
- getSnapshot: () => n,
25
- subscribe: (t) => (r.add(t), () => r.delete(t)),
26
- publish(t) {
27
- if (!Object.is(n, t)) {
28
- n = t;
29
- for (const i of [...r]) i();
30
- }
24
+ destroy(...o) {
25
+ r = !0, n.clear(), o.length && (t = o[0]);
31
26
  },
32
- listenerCount: () => r.size
27
+ listenerCount: () => n.size
33
28
  };
34
29
  }
35
- let Fn = 0;
36
- const nn = (e, n) => ({ key: `modal-route-${++Fn}`, name: e, params: n ?? {} }), Sn = (e, n) => [nn(e, n)];
37
- function Ke(e, n) {
38
- switch (n.type) {
30
+ const yt = we(null), Gt = we(null), _t = we(null), ot = we(null), Ue = we(null), Pt = we(null), Tt = we(null), vt = we(null), bt = we(null), wt = we(null), Ut = we(null), Vt = we(null), Ve = we(null), Lt = we(null), zt = we(null), at = we(null);
31
+ let fn = 0;
32
+ const ht = (e, t) => ({ key: `modal-route-${++fn}`, name: e, params: t ?? {} }), Yt = (e, t) => [ht(e, t)];
33
+ function mt(e, t) {
34
+ switch (t.type) {
35
+ case "COMMIT":
36
+ return t.stack;
37
+ case "PUSH":
38
+ return [...e, ht(t.name, t.params)];
39
+ case "POP":
40
+ return e.slice(0, Math.max(1, e.length - t.count));
39
41
  case "RESET":
40
- return Sn(n.name, n.params);
42
+ return Yt(t.name, t.params);
41
43
  case "NAVIGATE": {
42
- const r = e.findIndex((t) => t.name === n.name);
43
- return r < 0 ? [...e, nn(n.name, n.params)] : e.slice(0, r + 1).map((t, i) => i === r ? { ...t, params: n.params ?? {} } : t);
44
+ const n = e.findIndex((r) => r.name === t.name);
45
+ return n < 0 ? [...e, ht(t.name, t.params)] : e.slice(0, n + 1).map((r, o) => o === n ? { ...r, params: t.params ?? {} } : r);
44
46
  }
45
47
  case "SET_OPTIONS":
46
- return e.map((r, t) => t === e.length - 1 ? { ...r, options: { ...r.options ?? {}, ...n.options ?? {} } } : r);
48
+ return e.map((n, r) => r === e.length - 1 ? { ...n, options: { ...n.options ?? {}, ...t.options ?? {} } } : n);
47
49
  case "SET_PARAMS":
48
- return e.map((r, t) => t === e.length - 1 ? { ...r, params: { ...r.params ?? {}, ...n.params ?? {} } } : r);
50
+ return e.map((n, r) => r === e.length - 1 ? { ...n, params: { ...n.params ?? {}, ...t.params ?? {} } } : n);
49
51
  case "BACK":
50
52
  return e.length > 1 ? e.slice(0, -1) : e;
51
53
  case "REPLACE":
52
- return e.length ? [...e.slice(0, -1), nn(n.name, n.params)] : e;
54
+ return e.length ? [...e.slice(0, -1), ht(t.name, t.params)] : e;
53
55
  default:
54
56
  return e;
55
57
  }
56
58
  }
57
- function $n(e, n, r = 1 / 0) {
58
- const t = r === 1 / 0 ? 1 / 0 : Math.max(0, Math.floor(Number(r) || 0)), i = e.slice(0, -1).filter((p) => n[p.name]?.keepAlive !== !1), g = new Set((t === 0 ? [] : i.slice(-t)).map((p) => p.key));
59
- return e.filter((p, f) => f === e.length - 1 || g.has(p.key));
59
+ function $t(e, t, n = 1 / 0, r = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set()) {
60
+ const a = n === 1 / 0 ? 1 / 0 : Math.max(0, Math.floor(Number(n) || 0)), l = e.slice(0, -1).filter((u) => t[u.name]?.keepAlive !== !1), f = new Set((a === 0 ? [] : l.slice(-a)).map((u) => u.key));
61
+ return e.filter((u, i) => i === e.length - 1 || (f.has(u.key) || o.has(u.key)) && !r.has(u.key));
62
+ }
63
+ function hn(e, t, n) {
64
+ const r = new Set(t.map((a) => a.key)), o = new Set(e.slice(0, -1).filter((a) => n.has(a.key) || !r.has(a.key)).map((a) => a.key));
65
+ return o.size === n.size && [...o].every((a) => n.has(a)) ? n : o;
60
66
  }
61
- const jn = Object.freeze({ sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }), Fe = (e) => typeof e == "number" ? `${e}px` : e, pn = () => {
67
+ function gn(e, t) {
68
+ const n = e.responsive;
69
+ if (!n) return e;
70
+ const { sm: r, md: o, lg: a, xl: l } = n;
71
+ return { ...e, ...t < 768 ? r : t < 1024 ? o : t < 1280 ? a : l, ...e.runtimeLayout };
72
+ }
73
+ function yn(e, t, n, r) {
74
+ const o = Math.max(0, Math.min(n ?? 1 / 0, r));
75
+ return Math.min(o, Math.max(Math.min(t ?? 240, o), e));
76
+ }
77
+ const vn = Object.freeze({ sm: 400, md: 560, lg: 720, xl: 960, full: "100%" }), Ie = (e) => typeof e == "number" ? `${e}px` : e, It = () => {
62
78
  if (typeof document > "u") return "light";
63
- const e = document.documentElement, n = document.body;
64
- return e.classList.contains("dark") || n.classList.contains("dark") || e.dataset.theme === "dark" || n.dataset.theme === "dark" ? "dark" : e.classList.contains("light") || n.classList.contains("light") || e.dataset.theme === "light" || n.dataset.theme === "light" ? "light" : window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
79
+ const e = document.documentElement, t = document.body;
80
+ return e.classList.contains("dark") || t.classList.contains("dark") || e.dataset.theme === "dark" || t.dataset.theme === "dark" ? "dark" : e.classList.contains("light") || t.classList.contains("light") || e.dataset.theme === "light" || t.dataset.theme === "light" ? "light" : window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
65
81
  };
66
- let $e = 0;
67
- const xe = [];
68
- let Xe = null;
69
- function In() {
70
- if ($e++, $e === 1) {
71
- const n = document.documentElement, r = document.body, t = { html: n.style.overflow, body: r.style.overflow, padding: r.style.paddingRight, width: r.style.getPropertyValue("--modal-scrollbar-width") }, i = Math.max(0, window.innerWidth - n.clientWidth), g = parseFloat(getComputedStyle(r).paddingRight) || 0;
72
- i && (r.style.paddingRight = `${g + i}px`), r.style.setProperty("--modal-scrollbar-width", `${i}px`), n.style.overflow = "hidden", r.style.overflow = "hidden", Xe = () => {
73
- n.style.overflow = t.html, r.style.overflow = t.body, r.style.paddingRight = t.padding, t.width ? r.style.setProperty("--modal-scrollbar-width", t.width) : r.style.removeProperty("--modal-scrollbar-width");
82
+ let tt = 0;
83
+ const Ke = [];
84
+ let Mt = null;
85
+ function bn() {
86
+ if (tt++, tt === 1) {
87
+ const t = document.documentElement, n = document.body, r = { html: t.style.overflow, body: n.style.overflow, padding: n.style.paddingRight, width: n.style.getPropertyValue("--modal-scrollbar-width") }, o = Math.max(0, window.innerWidth - t.clientWidth), a = parseFloat(getComputedStyle(n).paddingRight) || 0;
88
+ o && (n.style.paddingRight = `${a + o}px`), n.style.setProperty("--modal-scrollbar-width", `${o}px`), t.style.overflow = "hidden", n.style.overflow = "hidden", Mt = () => {
89
+ t.style.overflow = r.html, n.style.overflow = r.body, n.style.paddingRight = r.padding, r.width ? n.style.setProperty("--modal-scrollbar-width", r.width) : n.style.removeProperty("--modal-scrollbar-width");
74
90
  };
75
91
  }
76
92
  let e = !1;
77
93
  return () => {
78
- e || (e = !0, $e = Math.max(0, $e - 1), $e || (Xe?.(), Xe = null));
94
+ e || (e = !0, tt = Math.max(0, tt - 1), tt || (Mt?.(), Mt = null));
79
95
  };
80
96
  }
81
- const Dn = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', Kn = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
82
- function En({ dialogRef: e, options: n, requestClose: r, children: t, exiting: i = !1 }) {
83
- const g = l(null), p = l(null), f = l(r);
84
- f.current = r;
85
- const u = l(n.closeOnEsc);
86
- u.current = n.closeOnEsc;
87
- const [y, M] = pe(pn), k = n.theme === "light" || n.theme === "dark" ? n.theme : y;
88
- Q(() => {
89
- if (n.theme === "light" || n.theme === "dark") return;
90
- const O = () => M(pn()), F = new MutationObserver(O);
91
- for (const J of [document.documentElement, document.body]) F.observe(J, { attributes: !0, attributeFilter: ["class", "data-theme"] });
92
- const U = window.matchMedia?.("(prefers-color-scheme: dark)");
93
- return U?.addEventListener?.("change", O), O(), () => {
94
- F.disconnect(), U?.removeEventListener?.("change", O);
97
+ const wn = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])', kn = (e) => !e.closest('[inert], [hidden], [aria-hidden="true"]') && e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden" && getComputedStyle(e).display !== "none";
98
+ function xn({ dialogRef: e, options: t, requestClose: n, children: r, exiting: o = !1 }) {
99
+ const [a, l] = xe(() => typeof window > "u" ? 1024 : window.innerWidth), f = !!t.responsive;
100
+ U(() => {
101
+ if (!f) return;
102
+ const O = () => l(window.innerWidth < 768 ? 0 : window.innerWidth < 1024 ? 768 : window.innerWidth < 1280 ? 1024 : 1280);
103
+ return window.addEventListener("resize", O), O(), () => window.removeEventListener("resize", O);
104
+ }, [f]), t = gn(t, a);
105
+ const [u, i] = xe(null);
106
+ U(() => i(null), [t.width, t.placement]);
107
+ const d = P(null), g = P(0);
108
+ U(() => () => {
109
+ g.current && cancelAnimationFrame(g.current);
110
+ }, []);
111
+ const b = P(null), x = P(null), h = P(n);
112
+ h.current = n;
113
+ const s = P(t.closeOnEsc);
114
+ s.current = t.closeOnEsc;
115
+ const [v, I] = xe(It), z = t.theme === "light" || t.theme === "dark" ? t.theme : v;
116
+ U(() => {
117
+ if (t.theme === "light" || t.theme === "dark") return;
118
+ const O = () => I(It()), G = new MutationObserver(O);
119
+ for (const Ce of [document.documentElement, document.body]) G.observe(Ce, { attributes: !0, attributeFilter: ["class", "data-theme"] });
120
+ const ke = window.matchMedia?.("(prefers-color-scheme: dark)");
121
+ return ke?.addEventListener?.("change", O), O(), () => {
122
+ G.disconnect(), ke?.removeEventListener?.("change", O);
95
123
  };
96
- }, [n.theme]), Q(() => {
97
- p.current = document.activeElement;
98
- const O = In(), F = g.current;
99
- xe.push(F), e.current?.focus({ preventScroll: !0 });
100
- const U = (E) => {
101
- const _ = e.current;
102
- if (!_ || xe.at(-1) !== F) return;
103
- if (E.key === "Escape" && u.current !== !1) {
104
- E.preventDefault(), f.current("escape");
124
+ }, [t.theme]), U(() => {
125
+ x.current = document.activeElement;
126
+ const O = bn(), G = b.current;
127
+ Ke.push(G), e.current?.focus({ preventScroll: !0 });
128
+ const ke = (K) => {
129
+ const de = e.current;
130
+ if (!de || Ke.at(-1) !== G) return;
131
+ if (K.key === "Escape" && s.current !== !1) {
132
+ K.preventDefault(), h.current("escape");
105
133
  return;
106
134
  }
107
- if (E.key !== "Tab") return;
108
- const q = [..._.querySelectorAll(Dn)].filter(Kn);
109
- if (!q.length) {
110
- E.preventDefault(), _.focus();
135
+ if (K.key !== "Tab") return;
136
+ const k = [...de.querySelectorAll(wn)].filter(kn);
137
+ if (!k.length) {
138
+ K.preventDefault(), de.focus();
111
139
  return;
112
140
  }
113
- const re = q[0], X = q.at(-1);
114
- _.contains(document.activeElement) ? E.shiftKey && (document.activeElement === re || document.activeElement === _) ? (E.preventDefault(), X.focus()) : !E.shiftKey && (document.activeElement === X || document.activeElement === _) && (E.preventDefault(), re.focus()) : (E.preventDefault(), (E.shiftKey ? X : re).focus());
115
- }, J = (E) => {
116
- xe.at(-1) === F && e.current && !e.current.contains(E.target) && e.current.focus({ preventScroll: !0 });
141
+ const ce = k[0], ne = k.at(-1);
142
+ de.contains(document.activeElement) ? K.shiftKey && (document.activeElement === ce || document.activeElement === de) ? (K.preventDefault(), ne.focus()) : !K.shiftKey && (document.activeElement === ne || document.activeElement === de) && (K.preventDefault(), ce.focus()) : (K.preventDefault(), (K.shiftKey ? ne : ce).focus());
143
+ }, Ce = (K) => {
144
+ Ke.at(-1) === G && e.current && !e.current.contains(K.target) && e.current.focus({ preventScroll: !0 });
117
145
  };
118
- return document.addEventListener("keydown", U), document.addEventListener("focusin", J), () => {
119
- document.removeEventListener("keydown", U), document.removeEventListener("focusin", J);
120
- const E = xe.at(-1) === F, _ = xe.indexOf(F);
121
- if (_ !== -1 && xe.splice(_, 1), O(), E) {
122
- const q = p.current;
123
- q?.isConnected && !q.closest("[inert], [hidden]") ? q.focus?.({ preventScroll: !0 }) : xe.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
146
+ return document.addEventListener("keydown", ke), document.addEventListener("focusin", Ce), () => {
147
+ document.removeEventListener("keydown", ke), document.removeEventListener("focusin", Ce);
148
+ const K = Ke.at(-1) === G, de = Ke.indexOf(G);
149
+ if (de !== -1 && Ke.splice(de, 1), O(), K) {
150
+ const k = x.current;
151
+ k?.isConnected && !k.closest("[inert], [hidden]") ? k.focus?.({ preventScroll: !0 }) : Ke.at(-1)?.querySelector("[role=dialog]")?.focus?.({ preventScroll: !0 });
124
152
  }
125
153
  };
126
154
  }, [e]);
127
- const d = n.backgroundColor ?? n.backgroudColor, m = typeof d == "string" ? d : d?.[k], a = typeof m == "string" && /^(#|(?:rgb|rgba|hsl|hsla|hwb|oklch|oklab|lab|lch|color|color-mix|light-dark|var)\(|transparent$|currentColor$|[a-z]+$)/i.test(m.trim()) ? m.trim() : null, P = typeof m == "string" && !a ? m.trim() : "", N = !!(a || P), D = ["center", "left", "right", "top", "bottom"].includes(n.placement) ? n.placement : "right", L = Fe(n.width ?? jn[n.size] ?? 460), G = Fe(n.height), x = Fe(n.maxHeight), B = Fe(n.maxWidth), $ = Number(n.viewportGap ?? 5), H = Number.isFinite($) ? Math.max(0, $) : 5, T = n.top == null ? null : Fe(n.top), v = D === "top" && T !== null ? T : null, j = typeof n.borderRadius == "number" ? `${n.borderRadius}px` : n.borderRadius ?? "12px";
128
- return On(/* @__PURE__ */ s(
155
+ const T = t.backgroundColor ?? t.backgroudColor, E = typeof T == "string" ? T : T?.[z], D = typeof E == "string" && /^(#|(?:rgb|rgba|hsl|hsla|hwb|oklch|oklab|lab|lch|color|color-mix|light-dark|var)\(|transparent$|currentColor$|[a-z]+$)/i.test(E.trim()) ? E.trim() : null, L = typeof E == "string" && !D ? E.trim() : "", A = !!(D || L), q = ["center", "left", "right", "top", "bottom"].includes(t.placement) ? t.placement : "right", N = Ie(u ?? t.width ?? vn[t.size] ?? 460), Z = Ie(t.height), ue = Ie(t.maxHeight), C = Ie(t.maxWidth), F = Number(t.viewportGap ?? 5), $ = Number.isFinite(F) ? Math.max(0, F) : 5, X = t.top == null ? null : Ie(t.top), B = q !== "bottom" && X !== null ? X : null, te = typeof t.borderRadius == "number" ? `${t.borderRadius}px` : t.borderRadius ?? "12px", V = t.resizable && !t.fullscreen && ["left", "right"].includes(q), oe = (O) => yn(O, t.minWidth, typeof t.maxWidth == "number" ? t.maxWidth : void 0, b.current?.clientWidth - $ * 2 || window.innerWidth), J = (O) => {
156
+ !d.current || d.current.id !== O.pointerId || (cancelAnimationFrame(g.current), i(d.current.width), e.current?.style.removeProperty("--pmn-drag-width"), d.current = null);
157
+ };
158
+ return pn(/* @__PURE__ */ p(
129
159
  "div",
130
160
  {
131
- ref: g,
132
- className: `pmn-overlay ${i ? "pmn-exiting" : "pmn-entering"} ${n.animation === !1 ? "pmn-no-animation" : ""} pmn-place-${D} ${n.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
133
- style: { padding: H, ...v !== null ? { paddingTop: v, "--pmn-top-offset": v } : {}, "--pmn-animation-duration": `${Math.min(1e3, Math.max(0, Number(n.animationDuration ?? 220) || 0))}ms` },
161
+ ref: b,
162
+ className: `pmn-overlay ${o ? "pmn-exiting" : "pmn-entering"} ${t.animation === !1 ? "pmn-no-animation" : ""} pmn-place-${q} ${t.fullscreen ? "pmn-fullscreen" : ""} ${t.mobileFullscreen ? "pmn-mobile-fullscreen" : ""}`,
163
+ style: { padding: $, ...t.bottom != null ? { paddingBottom: Ie(t.bottom) } : {}, ...t.left != null ? { paddingLeft: Ie(t.left) } : {}, ...t.right != null ? { paddingRight: Ie(t.right) } : {}, ...B !== null ? { paddingTop: B, "--pmn-top-offset": B } : {}, "--pmn-animation-duration": `${Math.min(1e3, Math.max(0, Number(t.animationDuration ?? 220) || 0))}ms` },
134
164
  onMouseDown: (O) => {
135
- O.target === O.currentTarget && n.closeOnOverlay === !0 && f.current("overlay");
165
+ O.target === O.currentTarget && t.closeOnOverlay === !0 && h.current("overlay");
136
166
  },
137
- children: /* @__PURE__ */ ce(
167
+ children: /* @__PURE__ */ be(
138
168
  "section",
139
169
  {
140
170
  ref: e,
141
171
  tabIndex: -1,
142
172
  role: "dialog",
143
173
  "aria-modal": "true",
144
- "aria-label": n.ariaLabel ?? "Dialog",
145
- "data-modal-theme": k,
146
- className: `pmn-dialog ${k === "dark" ? "dark" : ""} ${N ? "pmn-has-custom-background" : ""} ${n.className ?? ""}`,
147
- style: { "--pmn-width": L, "--pmn-gap": `${H}px`, ...v !== null ? { "--pmn-top-offset": v } : {}, ...G !== void 0 ? { "--pmn-height": G } : {}, ...x !== void 0 ? { "--pmn-max-height": x } : {}, ...B !== void 0 ? { "--pmn-max-width": B } : {}, borderRadius: j },
174
+ "aria-label": t.ariaLabel ?? "Dialog",
175
+ "data-modal-theme": z,
176
+ className: `pmn-dialog ${z === "dark" ? "dark" : ""} ${A ? "pmn-has-custom-background" : ""} ${t.className ?? ""}`,
177
+ style: { "--pmn-width": N, "--pmn-gap": `${$}px`, ...B !== null ? { "--pmn-top-offset": B } : {}, ...Z !== void 0 ? { "--pmn-height": Z } : {}, ...ue !== void 0 ? { "--pmn-max-height": ue } : {}, ...C !== void 0 ? { "--pmn-max-width": C } : {}, borderRadius: te },
148
178
  children: [
149
- N && /* @__PURE__ */ s("div", { "aria-hidden": "true", className: `pmn-custom-background-layer ${P}`, style: a ? { backgroundColor: a } : void 0 }),
150
- t
179
+ A && /* @__PURE__ */ p("div", { "aria-hidden": "true", className: `pmn-custom-background-layer ${L}`, style: D ? { backgroundColor: D } : void 0 }),
180
+ r,
181
+ V && /* @__PURE__ */ p(
182
+ "div",
183
+ {
184
+ role: "separator",
185
+ "aria-label": "调整弹窗宽度",
186
+ "aria-orientation": "vertical",
187
+ tabIndex: 0,
188
+ className: `pmn-resize-handle pmn-resize-${q}`,
189
+ onKeyDown: (O) => {
190
+ ["ArrowLeft", "ArrowRight"].includes(O.key) && (O.preventDefault(), i(oe(e.current.getBoundingClientRect().width + (O.key === "ArrowRight" ? 16 : -16) * (q === "left" ? 1 : -1))));
191
+ },
192
+ onPointerDown: (O) => {
193
+ if (O.button !== 0) return;
194
+ O.preventDefault(), O.currentTarget.setPointerCapture(O.pointerId);
195
+ const G = e.current.getBoundingClientRect().width;
196
+ d.current = { id: O.pointerId, x: O.clientX, start: G, width: G };
197
+ },
198
+ onPointerMove: (O) => {
199
+ const G = d.current;
200
+ !G || G.id !== O.pointerId || (G.width = oe(G.start + (O.clientX - G.x) * (q === "left" ? 1 : -1)), cancelAnimationFrame(g.current), g.current = requestAnimationFrame(() => e.current?.style.setProperty("--pmn-drag-width", `${G.width}px`)));
201
+ },
202
+ onPointerUp: J,
203
+ onPointerCancel: J,
204
+ onLostPointerCapture: J
205
+ }
206
+ )
151
207
  ]
152
208
  }
153
209
  )
154
210
  }
155
211
  ), document.body);
156
212
  }
157
- function fn({ back: e }) {
158
- return /* @__PURE__ */ s("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ s("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ s("path", { d: "M18 6 6 18M6 6l12 12" }) });
213
+ const Sn = (e) => e;
214
+ function Pe(e, t = Sn, n = Object.is) {
215
+ const r = P({ store: null, initialized: !1, selection: void 0 }), o = Q(() => {
216
+ let l = !1, f, u;
217
+ return () => {
218
+ const i = e.getSnapshot();
219
+ if (l && Object.is(f, i)) return u;
220
+ const d = t(i);
221
+ if (l)
222
+ n(u, d) || (u = d);
223
+ else {
224
+ const g = r.current;
225
+ u = g.initialized && g.store === e && n(g.selection, d) ? g.selection : d;
226
+ }
227
+ return f = i, l = !0, u;
228
+ };
229
+ }, [e, t, n]), a = Oe(e.subscribe, o, o);
230
+ return U(() => {
231
+ r.current = { store: e, initialized: !0, selection: a };
232
+ }, [e, a]), a;
233
+ }
234
+ function He(e, t) {
235
+ if (Object.is(e, t)) return !0;
236
+ if (!e || !t || typeof e != "object" || typeof t != "object") return !1;
237
+ const n = Object.keys(e);
238
+ return n.length === Object.keys(t).length && n.every((r) => Object.hasOwn(t, r) && Object.is(e[r], t[r]));
239
+ }
240
+ const Ye = (e) => (t) => Object.fromEntries(e.map((n) => [n, t[n]])), Cn = Ye(["pageAnimationDuration", "pageAnimationDistance", "pageAnimation", "animation", "lockCloseWhileLoading", "maxCachedScreens", "bodyClassName", "lazyFallback", "onBlur", "onNavigate", "onRouteChange", "onFocus"]), En = Ye(["bodyClassName", "lazyFallback"]), Rn = Ye(["showHeader", "showTitle", "renderHeader", "renderHeaderRight", "showHeaderBorder", "headerClassName", "showBackButton", "showCloseButton"]), Qt = Ye(["showFooter", "renderFooter", "done", "cancel", "cancle", "showFooterBorder", "footerClassName", "actions", "loadingText", "cancelText", "doneText", "doneDisabled"]), Mn = Ye(["fullscreenable", "fullscreen"]), At = ["responsive", "width", "height", "maxWidth", "maxHeight", "minWidth", "size", "placement", "viewportGap", "top", "bottom", "left", "right", "borderRadius", "resizable", "fullscreen", "mobileFullscreen", "animation", "animationDuration", "closeOnEsc", "closeOnOverlay", "theme", "backgroundColor", "backgroudColor", "ariaLabel", "className"], On = Ye(At);
241
+ function Pn(e, t) {
242
+ const n = { ...e, ...t, ...e.runtimeLayout };
243
+ return { ...On(n), runtimeLayout: Object.fromEntries(At.filter((r) => Object.hasOwn(e.runtimeLayout ?? {}, r)).map((r) => [r, e.runtimeLayout[r]])) };
244
+ }
245
+ function Tn(e, t) {
246
+ return He(e.runtimeLayout, t.runtimeLayout) && At.every((n) => Object.is(e[n], t[n]));
159
247
  }
160
- function Rn({ options: e, screen: n, route: r, navigation: t, requestClose: i, translate: g, canGoBack: p }) {
248
+ const Zt = {}, Ln = () => Zt, zn = () => () => {
249
+ }, An = Se.memo(function({ action: t, context: n }) {
250
+ const r = P(!1), [o, a] = xe(!1), l = P(!1);
251
+ return U(() => (l.current = !0, () => {
252
+ l.current = !1;
253
+ }), []), /* @__PURE__ */ p("button", { type: "button", className: "pmn-icon-button", "aria-label": t.tooltip ?? t.key, title: t.tooltip, disabled: o || t.disabled || t.loading, onClick: async () => {
254
+ if (!(r.current || !l.current || t.disabled || t.loading)) {
255
+ r.current = !0, a(!0);
256
+ try {
257
+ await t.onClick?.(n);
258
+ } catch (f) {
259
+ console.error("[react-modal-navigation] header action", f);
260
+ } finally {
261
+ r.current = !1, l.current && a(!1);
262
+ }
263
+ }
264
+ }, children: o ? "…" : t.icon ?? t.label });
265
+ });
266
+ function Dt({ back: e }) {
267
+ return /* @__PURE__ */ p("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: e ? /* @__PURE__ */ p("path", { d: "m15 18-6-6 6-6" }) : /* @__PURE__ */ p("path", { d: "M18 6 6 18M6 6l12 12" }) });
268
+ }
269
+ function Nn({ options: e, screen: t, route: n, navigation: r, requestClose: o, translate: a, canGoBack: l }) {
270
+ const f = ee(yt), u = () => f?.getSnapshot()[n.key] ?? Zt, i = Oe(f?.subscribe ?? zn, u, Ln);
271
+ t = { ...t, ...i };
272
+ const d = a ?? ((v) => v), g = t.showTitle ?? e.showTitle ?? !0, b = typeof t.title == "function" ? t.title({ t: d, route: n, navigation: r }) : t.title ?? n.name, x = Q(() => ({ route: n, navigation: r, close: o, canGoBack: l, title: b, t: d }), [n, r, o, l, b, d]);
161
273
  if (e.showHeader === !1) return null;
162
- const f = g ?? ((m) => m), u = n.showTitle ?? e.showTitle ?? !0, y = typeof n.title == "function" ? n.title({ t: f, route: r, navigation: t }) : n.title ?? r.name, M = { route: r, navigation: t, close: i, canGoBack: p, title: y, t: f }, k = n.renderHeader ?? e.renderHeader;
163
- if (k) return k(M);
164
- const d = n.renderHeaderRight ?? e.renderHeaderRight;
165
- return /* @__PURE__ */ ce("header", { className: `pmn-header ${n.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
166
- (n.showBackButton ?? e.showBackButton) !== !1 && p && /* @__PURE__ */ s("button", { type: "button", className: "pmn-icon-button", "aria-label": f("modal.back"), onClick: () => t.goBack(), children: /* @__PURE__ */ s(fn, { back: !0 }) }),
167
- u ? /* @__PURE__ */ s("h2", { children: y }) : /* @__PURE__ */ s("div", { className: "pmn-header-spacer" }),
168
- d?.(M),
169
- e.showCloseButton !== !1 && /* @__PURE__ */ s("button", { type: "button", className: "pmn-icon-button", "aria-label": f("modal.close"), onClick: () => i("header"), children: /* @__PURE__ */ s(fn, {}) })
274
+ const h = t.renderHeader ?? e.renderHeader;
275
+ if (h) return h(x);
276
+ const s = t.renderHeaderRight ?? e.renderHeaderRight;
277
+ return /* @__PURE__ */ be("header", { className: `pmn-header ${t.showHeaderBorder ?? e.showHeaderBorder ? "pmn-border-bottom" : ""} ${e.headerClassName ?? ""}`, children: [
278
+ (t.showBackButton ?? e.showBackButton) !== !1 && l && /* @__PURE__ */ p("button", { type: "button", className: "pmn-icon-button", "aria-label": d("modal.back"), onClick: () => r.goBack(), children: /* @__PURE__ */ p(Dt, { back: !0 }) }),
279
+ g ? /* @__PURE__ */ p("h2", { children: b }) : /* @__PURE__ */ p("div", { className: "pmn-header-spacer" }),
280
+ s?.(x),
281
+ i.actions?.filter((v) => !v.hidden).map((v) => /* @__PURE__ */ p(An, { action: v, context: x }, `${n.key}:${v.key}`)),
282
+ /* @__PURE__ */ p(jn, { hidden: t.showFullscreenButton === !1 }),
283
+ (t.showCloseButton ?? e.showCloseButton) !== !1 && /* @__PURE__ */ p("button", { type: "button", className: "pmn-icon-button", "aria-label": d("modal.close"), onClick: () => o("header"), children: /* @__PURE__ */ p(Dt, {}) })
170
284
  ] });
171
285
  }
172
- function Cn({ screen: e, options: n, override: r, route: t, navigation: i, requestClose: g, translate: p, onError: f, loadingApi: u }) {
173
- const [y, M] = pe(null), k = l(/* @__PURE__ */ new Set()), d = l(!0);
174
- Q(() => (d.current = !0, () => {
175
- d.current = !1;
286
+ const jn = Se.memo(function({ hidden: t }) {
287
+ const n = ee(Lt), r = ee(at), o = Pe(r.stores.layout, Mn, He);
288
+ return t || !o.fullscreenable ? null : /* @__PURE__ */ p("button", { type: "button", className: "pmn-icon-button", "aria-label": o.fullscreen ? "还原" : "全屏", onClick: n?.toggleFullscreen, children: /* @__PURE__ */ p("svg", { "aria-hidden": "true", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ p("path", { d: o.fullscreen ? "M3 9h6V3 M21 9h-6V3 M3 15h6v6 M21 15h-6v6" : "M3 9V3h6 M15 3h6v6 M3 15v6h6 M15 21h6v-6" }) }) });
289
+ }), Xt = rt(function({ store: t, screenOptions: n, ...r }) {
290
+ const o = _((l) => Pn(l, n), [n]), a = Pe(t, o, Tn);
291
+ return /* @__PURE__ */ p(xn, { ...r, options: a });
292
+ }), Jt = rt(function({ store: t, ...n }) {
293
+ const r = Pe(t, Rn, He);
294
+ return /* @__PURE__ */ p(Nn, { ...n, options: r });
295
+ }), Bn = Se.memo(function({ action: t, context: n, loadingApi: r, onError: o, loadingText: a }) {
296
+ const l = P(!1), [f, u] = xe(!1), i = P(!1);
297
+ U(() => (i.current = !0, () => {
298
+ i.current = !1;
176
299
  }), []);
177
- const m = p ?? ((v) => v), a = { ...n, ...e, ...r }, { showFooter: P, renderFooter: N, done: D, cancel: L, cancle: G } = a, x = L ?? G, B = { route: t, navigation: i, close: g, t: m };
178
- if (P === !1) return null;
179
- const $ = `pmn-footer ${a.showFooterBorder ? "pmn-border-top" : ""} ${a.footerClassName ?? ""}`;
180
- if (typeof N == "function") return /* @__PURE__ */ s("footer", { className: $, children: N({ ...B, pending: k.current.size > 0 }) });
181
- const H = Array.isArray(a.actions) ? a.actions : null;
182
- if (!H && typeof D != "function" && typeof x != "function") return null;
183
- const T = async (v, j, O) => {
184
- if (k.current.has(v) || typeof j != "function") return;
185
- k.current.add(v), M(v);
186
- const F = u?.begin(t.key, O ?? a.loadingText ?? m("modal.processing"));
300
+ const d = f || t.loading === !0, g = t.loadingText ?? a ?? n.t("modal.processing"), b = async () => {
301
+ if (!i.current || l.current || t.disabled || t.loading || typeof t.onClick != "function") return;
302
+ l.current = !0, u(!0);
303
+ const x = r?.begin(n.route.key, g);
187
304
  try {
188
- await j(B);
189
- } catch (U) {
190
- f?.(U, { phase: "footer", action: v, route: t });
305
+ await t.onClick(n);
306
+ } catch (h) {
307
+ o?.(h, { phase: "footer", action: t.key, route: n.route });
191
308
  } finally {
192
- u?.end(t.key, F), k.current.delete(v), d.current && M((U) => U === v ? null : U);
309
+ x != null && r?.end(n.route.key, x), l.current = !1, i.current && u(!1);
193
310
  }
194
311
  };
195
- return H ? /* @__PURE__ */ s("footer", { className: $, children: H.filter((v) => !v.hidden).map((v) => {
196
- const j = k.current.has(v.key) || v.loading === !0;
197
- return /* @__PURE__ */ s(
198
- "button",
199
- {
200
- type: "button",
201
- disabled: v.disabled === !0 || j,
202
- className: `pmn-button ${v.variant === "primary" || v.variant === "danger" ? "pmn-button-primary" : "pmn-button-secondary"} ${v.variant === "danger" ? "pmn-button-danger" : ""}`,
203
- onClick: () => T(v.key, v.onClick, v.loadingText),
204
- children: j ? v.loadingText ?? a.loadingText ?? m("modal.processing") : v.label
205
- },
206
- v.key
207
- );
208
- }) }) : /* @__PURE__ */ ce("footer", { className: $, children: [
209
- typeof x == "function" && /* @__PURE__ */ s("button", { type: "button", disabled: y !== null, onClick: () => T("cancel", x), className: "pmn-button pmn-button-secondary", children: a.cancelText ?? m("modal.cancel") }),
210
- typeof D == "function" && /* @__PURE__ */ s("button", { type: "button", disabled: y !== null || a.doneDisabled === !0, onClick: () => T("done", D), className: "pmn-button pmn-button-primary", children: y === "done" ? a.loadingText ?? m("modal.processing") : a.doneText ?? m("modal.done") })
312
+ return /* @__PURE__ */ p(
313
+ "button",
314
+ {
315
+ type: "button",
316
+ disabled: t.disabled === !0 || d,
317
+ className: `pmn-button ${t.variant === "primary" || t.variant === "danger" ? "pmn-button-primary" : "pmn-button-secondary"} ${t.variant === "danger" ? "pmn-button-danger" : ""}`,
318
+ onClick: b,
319
+ children: d ? g : t.label
320
+ }
321
+ );
322
+ });
323
+ function en({ screen: e, options: t, override: n, route: r, navigation: o, requestClose: a, translate: l, onError: f, loadingApi: u }) {
324
+ const [i, d] = xe(null), g = P(/* @__PURE__ */ new Set()), b = P(!0);
325
+ U(() => (b.current = !0, () => {
326
+ b.current = !1;
327
+ }), []);
328
+ const x = l ?? ((N) => N), h = { ...t, ...e, ...n }, { showFooter: s, renderFooter: v, done: I, cancel: z, cancle: T } = h, E = z ?? T, D = Q(() => ({ route: r, navigation: o, close: a, t: x }), [r, o, a, x]);
329
+ if (s === !1) return null;
330
+ const L = `pmn-footer ${h.showFooterBorder ? "pmn-border-top" : ""} ${h.footerClassName ?? ""}`;
331
+ if (typeof v == "function") return /* @__PURE__ */ p("footer", { className: L, children: v({ ...D, pending: g.current.size > 0 }) });
332
+ const A = Array.isArray(h.actions) ? h.actions : null;
333
+ if (!A && typeof I != "function" && typeof E != "function") return null;
334
+ const q = async (N, Z, ue) => {
335
+ if (!b.current || g.current.size > 0 || g.current.has(N) || typeof Z != "function") return;
336
+ g.current.add(N), d(N);
337
+ const C = u?.begin(r.key, h.loadingText ?? x("modal.processing"));
338
+ try {
339
+ await Z(D);
340
+ } catch (F) {
341
+ f?.(F, { phase: "footer", action: N, route: r });
342
+ } finally {
343
+ C != null && u?.end(r.key, C), g.current.delete(N), b.current && d((F) => F === N ? null : F);
344
+ }
345
+ };
346
+ return A ? /* @__PURE__ */ p("footer", { className: L, children: A.filter((N) => !N.hidden).map(
347
+ (N) => /* @__PURE__ */ p(Bn, { action: N, context: D, loadingApi: u, onError: f, loadingText: h.loadingText }, `${r.key}:${N.key}`)
348
+ ) }) : /* @__PURE__ */ be("footer", { className: L, children: [
349
+ typeof E == "function" && /* @__PURE__ */ p("button", { type: "button", disabled: i !== null, onClick: () => q("cancel", E), className: "pmn-button pmn-button-secondary", children: h.cancelText ?? x("modal.cancel") }),
350
+ typeof I == "function" && /* @__PURE__ */ p("button", { type: "button", disabled: i !== null || h.doneDisabled === !0, onClick: () => q("done", I), className: "pmn-button pmn-button-primary", children: i === "done" ? h.loadingText ?? x("modal.processing") : h.doneText ?? x("modal.done") })
211
351
  ] });
212
352
  }
213
- function Tn({ loading: e, translate: n }) {
353
+ function tn({ loading: e, translate: t }) {
214
354
  if (!e.visible) return null;
215
- const t = (n ?? ((g) => g))("modal.loading"), i = e.text ?? (t === "modal.loading" ? "加载中..." : t);
216
- return /* @__PURE__ */ s("div", { className: "pmn-loading-overlay", role: "status", "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ ce("div", { className: "pmn-loading-content", children: [
217
- /* @__PURE__ */ s("span", { className: "pmn-spinner", "aria-hidden": "true" }),
218
- i && /* @__PURE__ */ s("span", { className: "pmn-loading-text", children: i })
355
+ const r = (t ?? ((a) => a))("modal.loading"), o = e.text ?? (r === "modal.loading" ? "加载中..." : r);
356
+ return /* @__PURE__ */ p("div", { className: "pmn-loading-overlay", role: "status", "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ be("div", { className: "pmn-loading-content", children: [
357
+ /* @__PURE__ */ p("span", { className: "pmn-spinner", "aria-hidden": "true" }),
358
+ o && /* @__PURE__ */ p("span", { className: "pmn-loading-text", children: o })
219
359
  ] }) });
220
360
  }
221
- class Mn extends be.Component {
361
+ class Nt extends Se.Component {
222
362
  state = { error: null };
223
- static getDerivedStateFromError(n) {
224
- return { error: n };
363
+ static getDerivedStateFromError(t) {
364
+ return { error: t };
225
365
  }
226
- componentDidCatch(n, r) {
227
- this.props.onError?.(n, { phase: "render", route: this.props.route, componentStack: r.componentStack });
366
+ componentDidCatch(t, n) {
367
+ this.props.onError?.(t, { phase: "render", route: this.props.route, componentStack: n.componentStack });
228
368
  }
229
- componentDidUpdate(n) {
230
- n.route?.key !== this.props.route?.key && this.state.error && this.setState({ error: null });
369
+ componentDidUpdate(t) {
370
+ t.route?.key !== this.props.route?.key && this.state.error && this.setState({ error: null });
231
371
  }
232
372
  render() {
233
- return this.state.error ? /* @__PURE__ */ ce("div", { role: "alert", className: "pmn-error-screen", children: [
234
- /* @__PURE__ */ s("strong", { children: "页面加载失败" }),
235
- /* @__PURE__ */ s("p", { children: this.state.error.message }),
236
- /* @__PURE__ */ s("button", { type: "button", className: "pmn-button pmn-button-secondary", onClick: () => this.setState({ error: null }), children: "重试" })
373
+ return this.state.error ? /* @__PURE__ */ be("div", { role: "alert", className: "pmn-error-screen", children: [
374
+ /* @__PURE__ */ p("strong", { children: "页面加载失败" }),
375
+ /* @__PURE__ */ p("p", { children: this.state.error.message }),
376
+ /* @__PURE__ */ p("button", { type: "button", className: "pmn-button pmn-button-secondary", onClick: () => {
377
+ this.props.onRetry?.(), this.setState({ error: null });
378
+ }, children: "重试" })
237
379
  ] }) : this.props.children;
238
380
  }
239
381
  }
240
- const Gn = { success: "✓", error: "×", warning: "!", info: "i" };
241
- function Pn({ items: e, dismiss: n }) {
242
- return e.length ? /* @__PURE__ */ s("div", { className: "pmn-toast-region", "aria-label": "Notifications", children: e.map((r) => /* @__PURE__ */ ce("div", { className: `pmn-toast pmn-toast-${r.type}`, role: r.type === "error" || r.type === "warning" ? "alert" : "status", children: [
243
- /* @__PURE__ */ s("span", { className: "pmn-toast-symbol", "aria-hidden": "true", children: Gn[r.type] }),
244
- /* @__PURE__ */ s("span", { className: "pmn-toast-message", children: r.message }),
245
- r.dismissible && /* @__PURE__ */ s("button", { type: "button", className: "pmn-toast-close", "aria-label": "Dismiss notification", onClick: () => n(r.id), children: "×" })
246
- ] }, r.id)) }) : null;
247
- }
248
- function Nn(e, n) {
249
- const r = l(0), t = l(/* @__PURE__ */ new Map()), i = w((f) => {
250
- clearTimeout(t.current.get(f)), t.current.delete(f), n.current && e.current.publish(e.current.getSnapshot().filter((u) => u.id !== f));
251
- }, []), g = w((f, u = {}) => {
252
- if (typeof f != "string" || !f.trim()) throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");
253
- const y = typeof u == "string" ? { type: u } : u ?? {}, M = ["success", "error", "warning", "info"].includes(y.type) ? y.type : "info", k = ++r.current, d = Number.isFinite(y.duration) ? Math.max(0, y.duration) : 3e3;
254
- if (!n.current) return null;
255
- const m = e.current.getSnapshot(), a = m.slice(0, Math.max(0, m.length - 4));
256
- for (const P of a)
257
- clearTimeout(t.current.get(P.id)), t.current.delete(P.id);
258
- return e.current.publish([...m.slice(-4), { id: k, message: f, type: M, dismissible: y.dismissible !== !1 }]), d > 0 && t.current.set(k, setTimeout(() => i(k), d)), k;
259
- }, [i]), p = K(() => {
260
- const f = (u, y) => g(u, y);
261
- for (const u of ["success", "error", "warning", "info"]) f[u] = (y, M = {}) => g(y, { ...M, type: u });
262
- return f.promise = async (u, y, M = {}) => {
263
- const k = g(y.loading, { ...M, type: "info", duration: 0 });
382
+ const qn = { success: "✓", error: "×", warning: "!", info: "i" };
383
+ function nn({ items: e, dismiss: t }) {
384
+ return e.length ? /* @__PURE__ */ p("div", { className: "pmn-toast-region", "aria-label": "Notifications", children: e.map((n) => /* @__PURE__ */ be("div", { className: `pmn-toast pmn-toast-${n.type}`, role: n.type === "error" || n.type === "warning" ? "alert" : "status", children: [
385
+ /* @__PURE__ */ p("span", { className: "pmn-toast-symbol", "aria-hidden": "true", children: qn[n.type] }),
386
+ /* @__PURE__ */ p("span", { className: "pmn-toast-message", children: n.message }),
387
+ n.dismissible && /* @__PURE__ */ p("button", { type: "button", className: "pmn-toast-close", "aria-label": "Dismiss notification", onClick: () => t(n.id), children: "×" })
388
+ ] }, n.id)) }) : null;
389
+ }
390
+ function rn(e, t, n) {
391
+ const r = P(0), o = P(/* @__PURE__ */ new Map()), a = _((u) => {
392
+ clearTimeout(o.current.get(u)), o.current.delete(u), t.current && e.current.publish(e.current.getSnapshot().filter((i) => i.id !== u));
393
+ }, []), l = _((u, i = {}) => {
394
+ if (typeof u != "string" || !u.trim()) throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");
395
+ const d = typeof i == "string" ? { type: i } : i ?? {}, g = ["success", "error", "warning", "info"].includes(d.type) ? d.type : "info", b = ++r.current, x = Number.isFinite(d.duration) ? Math.max(0, d.duration) : 3e3;
396
+ if (!t.current) return null;
397
+ const h = e.current.getSnapshot(), s = h.slice(0, Math.max(0, h.length - 4));
398
+ for (const v of s)
399
+ clearTimeout(o.current.get(v.id)), o.current.delete(v.id);
400
+ return e.current.publish([...h.slice(-4), { id: b, message: u, type: g, dismissible: d.dismissible !== !1 }]), x > 0 && o.current.set(b, setTimeout(() => a(b), x)), b;
401
+ }, [a]), f = Q(() => {
402
+ const u = (i, d) => l(i, d);
403
+ for (const i of ["success", "error", "warning", "info"]) u[i] = (d, g = {}) => l(d, { ...g, type: i });
404
+ return u.promise = async (i, d, g = {}) => {
405
+ const b = l(d.loading, { ...g, type: "info", duration: 0 });
264
406
  try {
265
- const d = await (typeof u == "function" ? u() : u);
266
- k != null && i(k);
267
- const m = typeof y.success == "function" ? y.success(d) : y.success;
268
- return m && g(m, { ...M, type: "success" }), d;
269
- } catch (d) {
270
- k != null && i(k);
271
- const m = typeof y.error == "function" ? y.error(d) : y.error;
272
- throw m && g(m, { ...M, type: "error" }), d;
407
+ const x = await (typeof i == "function" ? i() : i);
408
+ b != null && a(b);
409
+ const h = typeof d.success == "function" ? d.success(x) : d.success;
410
+ return h && l(h, { ...g, type: "success" }), x;
411
+ } catch (x) {
412
+ b != null && a(b);
413
+ const h = typeof d.error == "function" ? d.error(x) : d.error;
414
+ throw h && l(h, { ...g, type: "error" }), x;
415
+ }
416
+ }, u.dismiss = a, u.clear = () => {
417
+ for (const i of o.current.values()) clearTimeout(i);
418
+ o.current.clear(), e.current.publish([]);
419
+ }, u;
420
+ }, [l, a]);
421
+ return U(() => {
422
+ const u = () => {
423
+ for (const d of o.current.values()) clearTimeout(d);
424
+ o.current.clear();
425
+ }, i = n?.addCleanup(u);
426
+ return () => {
427
+ i?.(), u();
428
+ };
429
+ }, [n]), { toast: f, dismissToast: a };
430
+ }
431
+ function Fn(e) {
432
+ let t;
433
+ return {
434
+ added(n) {
435
+ t = n;
436
+ },
437
+ read() {
438
+ if (!e.has(t)) {
439
+ t = void 0;
440
+ for (const n of e.keys()) t = n;
273
441
  }
274
- }, f.dismiss = i, f.clear = () => {
275
- for (const u of t.current.values()) clearTimeout(u);
276
- t.current.clear(), e.current.publish([]);
277
- }, f;
278
- }, [g, i]);
279
- return Q(() => () => {
280
- for (const f of t.current.values()) clearTimeout(f);
281
- t.current.clear();
282
- }, []), { toast: p, dismissToast: i };
283
- }
284
- function An(e, n, r) {
285
- const t = l(/* @__PURE__ */ new Map()), i = l(0), g = w(() => {
286
- if (!n.current) return;
287
- const d = [...t.current.values()], m = { visible: d.length > 0, text: d.at(-1)?.text ?? null, count: d.length }, a = e.current.getSnapshot();
288
- (a.visible !== m.visible || a.text !== m.text || a.count !== m.count) && e.current.publish(m);
289
- }, []), p = w((d, m) => {
290
- if (!n.current || d !== "global" && r.current !== d) return null;
291
- const a = ++i.current;
292
- return t.current.set(a, { owner: d, text: m }), g(), a;
293
- }, [g]), f = w((d, m) => {
294
- if (m != null)
295
- t.current.get(m)?.owner === d && t.current.delete(m);
442
+ return { visible: e.size > 0, text: e.get(t)?.text ?? null, count: e.size };
443
+ }
444
+ };
445
+ }
446
+ function on(e, t, n, r) {
447
+ const o = r.loadingTasks, a = r.loadingSequence, l = Q(() => Fn(o.current), [o]), f = _(() => {
448
+ if (!t.current) return;
449
+ const h = l.read(), s = e.current.getSnapshot();
450
+ (s.visible !== h.visible || s.text !== h.text || s.count !== h.count) && e.current.publish(h);
451
+ }, [l]), u = _((h, s) => {
452
+ if (!t.current || h !== "global" && n.current !== h) return null;
453
+ const v = ++a.current;
454
+ return o.current.set(v, { owner: h, text: s }), l.added(v), f(), v;
455
+ }, [f, l]), i = _((h, s) => {
456
+ if (s != null)
457
+ o.current.get(s)?.owner === h && o.current.delete(s);
296
458
  else
297
- for (const [a, P] of t.current) P.owner === d && t.current.delete(a);
298
- g();
299
- }, [g]), u = w((d, m) => {
300
- d ? (f("global"), p("global", m)) : f("global");
301
- }, [p, f]), y = w((d, m, a) => {
302
- m ? (f(d), p(d, a)) : f(d);
303
- }, [p, f]);
304
- return { loadingApi: K(() => ({ setLoading: u, setScreenLoading: y, begin: p, end: f }), [u, y, p, f]), refreshLoading: g, loadingTasks: t, setLoading: u };
305
- }
306
- const Hn = be.memo(function({ store: n, translate: r }) {
307
- const t = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
308
- return /* @__PURE__ */ s(Tn, { loading: t, translate: r });
309
- }), _n = be.memo(function({ store: n, dismiss: r }) {
310
- const t = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
311
- return /* @__PURE__ */ s(Pn, { items: t, dismiss: r });
312
- }), Wn = be.memo(function({ store: n, routeKey: r, ...t }) {
313
- const i = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
314
- return /* @__PURE__ */ s(Cn, { ...t, override: i[r] });
315
- }), Un = be.memo(function({ route: n, screen: r, navigation: t, focused: i, resultEvent: g, setFooter: p, loadingApi: f, loadingStore: u, bodyClassName: y, notifyError: M, registerDirtyGuard: k, pageMotion: d, lazyFallback: m }) {
316
- const a = r.component, P = l(null), N = l(!1);
317
- He(() => {
318
- const x = i && !N.current;
319
- if (N.current = i, !x || !d?.enabled || !P.current?.animate) return;
320
- const B = d.direction === "back" ? -100 : 100;
321
- P.current.style.zIndex = "2";
322
- const $ = P.current.animate([
323
- { opacity: 1, transform: `translate3d(${B}%,0,0)` },
459
+ for (const [v, I] of o.current) I.owner === h && o.current.delete(v);
460
+ f();
461
+ }, [f]), d = _((h, s) => {
462
+ h ? (i("global"), u("global", s)) : i("global");
463
+ }, [u, i]), g = _((h, s, v) => {
464
+ s ? (i(h), u(h, v)) : i(h);
465
+ }, [u, i]);
466
+ return { loadingApi: Q(() => ({ setLoading: d, setScreenLoading: g, begin: u, end: i }), [d, g, u, i]), refreshLoading: f, loadingTasks: o, setLoading: d };
467
+ }
468
+ const $n = Se.memo(function({ store: t, translate: n }) {
469
+ const r = Oe(t.subscribe, t.getSnapshot, t.getSnapshot);
470
+ return /* @__PURE__ */ p(tn, { loading: r, translate: n });
471
+ }), In = Se.memo(function({ store: t, dismiss: n }) {
472
+ const r = Oe(t.subscribe, t.getSnapshot, t.getSnapshot);
473
+ return /* @__PURE__ */ p(nn, { items: r, dismiss: n });
474
+ }), Dn = Se.memo(function({ store: t, layoutStore: n, routeKey: r, ...o }) {
475
+ const a = () => t.getSnapshot()[r], l = Oe(t.subscribe, a, a), f = Pe(n, Qt, He);
476
+ return /* @__PURE__ */ p(en, { ...o, options: f, override: l });
477
+ }), Kn = Se.memo(function({ route: t, screen: n, navigation: r, focused: o, resultEvent: a, setFooter: l, loadingApi: f, loadingStore: u, bodyClassName: i, notifyError: d, registerDirtyGuard: g, pageMotion: b, lazyFallback: x }) {
478
+ const h = n.component, s = P(null), v = P(!1);
479
+ Ae(() => {
480
+ const E = o && !v.current;
481
+ if (v.current = o, !E || !b?.enabled || !s.current?.animate) return;
482
+ const D = b.direction === "back" ? -100 : 100;
483
+ s.current.style.zIndex = "2";
484
+ const L = s.current.animate([
485
+ { opacity: 1, transform: `translate3d(${D}%,0,0)` },
324
486
  { opacity: 1, transform: "translate3d(0,0,0)" }
325
- ], { duration: d.duration, easing: "cubic-bezier(.22,1,.36,1)" });
487
+ ], { duration: b.duration, easing: "cubic-bezier(.22,1,.36,1)" });
326
488
  return () => {
327
- $.cancel(), P.current && (P.current.style.zIndex = "");
489
+ L.cancel(), s.current && (s.current.style.zIndex = "");
328
490
  };
329
- }, [i, d?.enabled, d?.direction, d?.duration, d?.distance]);
330
- const D = K(() => ({ isFocused: i, resultEvent: g, routeKey: n.key, setFooter: p }), [i, g, n.key, p]), L = K(() => ({
331
- setLoading: (x, B) => f.setScreenLoading(n.key, x, B),
332
- showLoading: (x) => f.begin(n.key, x),
333
- hideLoading: (x) => f.end(n.key, x)
334
- }), [f, n.key]), G = K(() => ({ routeKey: n.key, registerDirtyGuard: k }), [n.key, k]);
335
- return /* @__PURE__ */ s(on.Provider, { value: n, children: /* @__PURE__ */ s(tn.Provider, { value: G, children: /* @__PURE__ */ s(je.Provider, { value: D, children: /* @__PURE__ */ s(Me.Provider, { value: L, children: /* @__PURE__ */ s(Ue.Provider, { value: u, children: /* @__PURE__ */ s("div", { ref: P, hidden: !i, inert: !i, "data-modal-route-key": n.key, tabIndex: -1, className: `pmn-body ${i && d?.enabled && typeof Element < "u" && !Element.prototype.animate ? `pmn-page-enter pmn-page-${d.direction}` : ""} ${y ?? ""}`, style: i && d?.enabled ? { "--pmn-page-duration": `${d.duration}ms`, "--pmn-page-distance": `${d.distance}px` } : void 0, children: /* @__PURE__ */ s(Mn, { route: n, onError: M, children: /* @__PURE__ */ s(bn, { fallback: m ?? /* @__PURE__ */ s("div", { className: "pmn-lazy-loading", role: "status", "aria-live": "polite", children: "加载中..." }), children: /* @__PURE__ */ s(a, { route: n, navigation: t }) }) }) }) }) }) }) }) });
491
+ }, [o, b?.enabled, b?.direction, b?.duration, b?.distance]);
492
+ const I = Q(() => ({ isFocused: o, resultEvent: a, routeKey: t.key, setFooter: l }), [o, a, t.key, l]), z = Q(() => ({
493
+ setLoading: (E, D) => f.setScreenLoading(t.key, E, D),
494
+ showLoading: (E) => f.begin(t.key, E),
495
+ hideLoading: (E) => f.end(t.key, E)
496
+ }), [f, t.key]), T = Q(() => ({ routeKey: t.key, registerDirtyGuard: g }), [t.key, g]);
497
+ return /* @__PURE__ */ p(Ve.Provider, { value: t, children: /* @__PURE__ */ p(Pt.Provider, { value: T, children: /* @__PURE__ */ p(ot.Provider, { value: I, children: /* @__PURE__ */ p(Ue.Provider, { value: z, children: /* @__PURE__ */ p(wt.Provider, { value: u, children: /* @__PURE__ */ p("div", { ref: s, hidden: !o, inert: !o, "data-modal-route-key": t.key, tabIndex: -1, className: `pmn-body ${o && b?.enabled && typeof Element < "u" && !Element.prototype.animate ? `pmn-page-enter pmn-page-${b.direction}` : ""} ${i ?? ""}`, style: o && b?.enabled ? { "--pmn-page-duration": `${b.duration}ms`, "--pmn-page-distance": `${b.distance}px` } : void 0, children: /* @__PURE__ */ p(Nt, { route: t, onError: d, children: /* @__PURE__ */ p(Wt, { fallback: x ?? /* @__PURE__ */ p("div", { className: "pmn-lazy-loading", role: "status", "aria-live": "polite", children: "加载中..." }), children: /* @__PURE__ */ p(h, { route: t, navigation: r }) }) }) }) }) }) }) }) });
336
498
  });
337
- function Yn({ config: e, initialScreen: n, params: r, options: t, translate: i, onRequestClose: g, onOpened: p, registerLoading: f, notifyError: u, error: y, clearError: M, registerDirtyGuard: k, canNavigate: d, exiting: m = !1 }) {
338
- const [a, P] = qn(Ke, null, () => Sn(n ?? e.initialRoute, r)), N = l(null);
339
- N.current || (N.current = kn({ canGoBack: a.length > 1, stack: a, currentRoute: a.at(-1) }));
340
- const D = l(null), L = l(null), G = l(null);
341
- D.current || (D.current = Te({ visible: !1, text: null, count: 0 })), L.current || (L.current = Te({})), G.current || (G.current = Te([]));
342
- const x = l(!0), B = l(0), { toast: $, dismissToast: H } = Nn(G, x);
343
- Q(() => (x.current = !0, () => {
344
- x.current = !1, B.current++;
345
- }), []);
346
- const [T, v] = pe({}), j = l(/* @__PURE__ */ new Map()), O = l(null), F = l(null), U = l(null), J = l(null), E = l(null), _ = l(!1), q = l(!1), re = l(/* @__PURE__ */ new Map()), X = l(0), ge = w((o, S, z) => {
347
- for (const [I, ae] of re.current)
348
- o.includes(ae.key) && (re.current.delete(I), ae.resolve({ status: S, ...S === "returned" ? { value: z } : {} }));
349
- }, []), V = l(a);
350
- V.current = a;
351
- const le = l(d);
352
- le.current = d;
353
- const ye = l(!1), b = l(0), C = a.at(-1), W = C.key, ue = l({ key: W, depth: a.length }), he = ue.current, we = he.key !== W, Ie = a.length < he.depth ? "back" : "forward";
354
- we && (ue.current = { key: W, depth: a.length });
355
- const Pe = Math.min(1e3, Math.max(0, Number(t.pageAnimationDuration ?? 360) || 0)), de = { distance: Math.min(300, Math.max(0, Number(t.pageAnimationDistance ?? 96) || 0)), enabled: t.pageAnimation !== !1 && t.animation !== !1 && Pe > 0 && we, direction: Ie, duration: Pe }, Ne = l(W);
356
- Ne.current = W;
357
- const { loadingApi: ke, refreshLoading: Ae, loadingTasks: Le, setLoading: Se } = An(D, x, Ne), c = e.screens, h = D, A = l(f);
358
- A.current = f, Q(() => (A.current?.({ setLoading: Se }), () => A.current?.(null)), [Se]);
359
- const R = w((o, S) => {
360
- if (!x.current) return;
361
- const z = L.current.getSnapshot();
362
- if (S === null) {
363
- if (!(o in z)) return;
364
- const I = { ...z };
365
- delete I[o], L.current.publish(I);
499
+ function Hn({ runtime: e, config: t, initialScreen: n, params: r, translate: o, onRequestClose: a, onOpened: l, registerLoading: f, notifyError: u, error: i, clearError: d, registerDirtyGuard: g, getProtectedCacheKeys: b, canNavigate: x, exiting: h = !1 }) {
500
+ const s = Pe(e.stores.layout, Cn, He), [v, I] = dn(mt, e.stores.navigation.getSnapshot().stack), { navigation: z, loading: T, footer: E, toast: D } = e.refs, L = e.alive, A = P(0), { toast: q, dismissToast: N } = rn(D, L, e);
501
+ U(() => () => {
502
+ A.current++;
503
+ }, []);
504
+ const [Z, ue] = xe({}), [C, F] = xe(() => /* @__PURE__ */ new Set()), $ = P(/* @__PURE__ */ new Map()), X = P(null), B = P(null), te = P(null), V = P(null), oe = P(null), J = P(!1), O = P(!1), G = e.pageRequests, ke = P(0), Ce = _((m, M, j) => {
505
+ for (const [Y, fe] of G.current)
506
+ m.includes(fe.key) && (G.current.delete(Y), fe.resolve({ status: M, ...M === "returned" ? { value: j } : {} }));
507
+ }, []), K = P(v);
508
+ K.current = v;
509
+ const de = P(x);
510
+ de.current = x;
511
+ const k = P(!1), ce = P(0), ne = v.at(-1), re = ne.key, Be = P({ key: re, depth: v.length }), st = Be.current, We = st.key !== re, it = v.length < st.depth ? "back" : "forward";
512
+ We && (Be.current = { key: re, depth: v.length });
513
+ const Qe = Math.min(1e3, Math.max(0, Number(s.pageAnimationDuration ?? 360) || 0)), ct = Math.min(300, Math.max(0, Number(s.pageAnimationDistance ?? 96) || 0)), Ne = Q(() => ({ distance: ct, enabled: s.pageAnimation !== !1 && s.animation !== !1 && Qe > 0 && We, direction: it, duration: Qe }), [ct, s.pageAnimation, s.animation, Qe, We, it]), lt = P(re);
514
+ lt.current = re;
515
+ const { loadingApi: Ze, refreshLoading: Ge, loadingTasks: ut, setLoading: De } = on(T, L, lt, e), Ee = t.screens, Te = T, _e = P(f);
516
+ _e.current = f, U(() => (_e.current?.({ setLoading: De }), () => _e.current?.(null)), [De]);
517
+ const qt = _((m, M) => {
518
+ if (!L.current) return;
519
+ const j = E.current.getSnapshot();
520
+ if (M === null) {
521
+ if (!(m in j)) return;
522
+ const Y = { ...j };
523
+ delete Y[m], E.current.publish(Y);
366
524
  return;
367
525
  }
368
- z[o] !== S && L.current.publish({ ...z, [o]: S });
369
- }, []), ee = w(() => {
526
+ j[m] !== M && E.current.publish({ ...j, [m]: M });
527
+ }, []), kt = _(() => {
370
528
  if (typeof document > "u") return;
371
- const o = document.activeElement;
372
- if (!(o instanceof HTMLElement) || !O.current?.contains(o)) return;
373
- const S = o.closest("[data-modal-route-key]");
374
- S && j.current.set(S.dataset.modalRouteKey, o), O.current.focus({ preventScroll: !0 });
375
- }, []), Z = w((o) => {
376
- if (!Object.prototype.hasOwnProperty.call(c, o)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${o}`);
377
- }, [c]), ne = w((o, S) => {
529
+ const m = document.activeElement;
530
+ if (!(m instanceof HTMLElement) || !X.current?.contains(m)) return;
531
+ const M = m.closest("[data-modal-route-key]");
532
+ M && $.current.set(M.dataset.modalRouteKey, m), X.current.focus({ preventScroll: !0 });
533
+ }, []), xt = _((m) => {
534
+ if (!Object.prototype.hasOwnProperty.call(Ee, m)) throw new Error(`[react-modal-navigation] Unknown modal screen: ${m}`);
535
+ }, [Ee]), c = _((m, M) => {
378
536
  try {
379
- Promise.resolve(t[o]?.(S)).catch((z) => u(z, { phase: o }));
380
- } catch (z) {
381
- u(z, { phase: o });
537
+ Promise.resolve(s[m]?.(M)).catch((j) => u(j, { phase: m }));
538
+ } catch (j) {
539
+ u(j, { phase: m });
382
540
  }
383
- }, [t, u]), te = w(async (o, S, z, I) => {
384
- if (!x.current || q.current) return !1;
385
- const ae = B.current, Y = V.current, se = Y.at(-1);
386
- if (o !== "BACK" && Z(S), o === "BACK" && Y.length <= 1) return !1;
387
- const dn = o === "NAVIGATE" ? Y.findIndex((Oe) => Oe.name === S) : -1, Qe = o === "RESET" ? Y : o === "BACK" || o === "REPLACE" ? [se] : dn >= 0 ? Y.slice(dn + 1) : [];
388
- q.current = !0;
541
+ }, [s, u]), y = _(async (m, M, j, Y, fe) => {
542
+ if (!L.current || O.current) return !1;
543
+ const ve = A.current, se = K.current, Xe = se.at(-1);
544
+ if (m !== "BACK" && m !== "POP" && xt(M), m === "POP" && (!Number.isInteger(j) || j < 1 || se.length <= 1) || m === "BACK" && se.length <= 1) return !1;
545
+ const Ft = m === "NAVIGATE" ? se.findIndex((Je) => Je.name === M) : -1, $e = m === "POP" ? se.slice(Math.max(1, se.length - j)) : m === "RESET" ? se : m === "BACK" || m === "REPLACE" ? [Xe] : Ft >= 0 ? se.slice(Ft + 1) : [];
546
+ O.current = !0;
389
547
  try {
390
- if (Qe.length && le.current && !await le.current(Qe.map((Je) => Je.key), {
548
+ if ($e.length && de.current && !await de.current($e.map((Me) => Me.key), {
391
549
  reason: "navigation",
392
- action: o,
393
- from: se,
394
- to: o === "BACK" ? Y.at(-2)?.name : S
395
- }) || !x.current || ae !== B.current || V.current.at(-1)?.key !== se.key) return !1;
396
- if (o === "BACK" && I !== void 0) {
397
- const Ce = Y.at(-2);
398
- v((Je) => ({ ...Je, [Ce.key]: { id: ++b.current, data: I } }));
550
+ action: m,
551
+ from: Xe,
552
+ to: m === "POP" ? se[Math.max(0, se.length - j - 1)]?.name : m === "BACK" ? se.at(-2)?.name : M
553
+ }) || $e.length && !await e.canRemove($e.map((ge) => ge.key), { reason: "navigation", action: m, from: Xe, to: M }) || !L.current || ve !== A.current || K.current.at(-1)?.key !== Xe.key) return !1;
554
+ if (m === "BACK" && Y !== void 0) {
555
+ const ge = se.at(-2);
556
+ ue((Me) => ({ ...Me, [ge.key]: { id: ++ce.current, data: Y } }));
557
+ }
558
+ if ($e.length) {
559
+ const ge = new Set($e.map((Me) => Me.key));
560
+ ge.forEach((Me) => $.current.delete(Me)), ue((Me) => Object.fromEntries(Object.entries(Me).filter(([et]) => !ge.has(et))));
399
561
  }
400
- o === "RESET" && v({}), ge(Qe.map((Ce) => Ce.key), o === "BACK" ? "returned" : "removed", I);
401
- const Oe = [...F.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((Ce) => Ce.dataset.modalRouteKey === se.key);
402
- U.current = Oe?.cloneNode(!0) ?? null, ee();
403
- const mn = { type: o, name: S, params: z };
404
- return V.current = Ke(V.current, mn), P(mn), !0;
405
- } catch (Oe) {
406
- return x.current && u(Oe, { phase: "navigationGuard", action: o }), !1;
562
+ e.tasks.cancelRoutes($e.map((ge) => ge.key)), Ce($e.map((ge) => ge.key), m === "BACK" ? "returned" : "removed", Y);
563
+ const Je = [...B.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((ge) => ge.dataset.modalRouteKey === Xe.key);
564
+ te.current = Je?.cloneNode(!0) ?? null, kt();
565
+ const un = { type: m, name: M, params: j, count: j };
566
+ K.current = mt(K.current, un);
567
+ const Rt = K.current;
568
+ return F((ge) => {
569
+ const Me = new Set(Rt.slice(0, -1).filter((et) => ge.has(et.key)).map((et) => et.key));
570
+ return Me.size === ge.size ? ge : Me;
571
+ }), fe?.(Rt.at(-1)), I({ type: "COMMIT", stack: Rt }), !0;
572
+ } catch (Je) {
573
+ return L.current && u(Je, { phase: "navigationGuard", action: m }), !1;
407
574
  } finally {
408
- q.current = !1;
575
+ O.current = !1;
409
576
  }
410
- }, [Z, ee, u, ge]), Be = w((o, S) => te("NAVIGATE", o, S), [te]), me = w(async (o, S) => {
411
- if (!x.current) return { status: "cancelled" };
412
- if (V.current, !await te("NAVIGATE", o, S) || !x.current) return { status: "cancelled" };
413
- const I = V.current.at(-1);
414
- return !I || I.name !== o ? { status: "cancelled" } : new Promise((ae) => {
415
- const Y = ++X.current;
416
- re.current.set(Y, { key: I.key, resolve: ae });
417
- });
418
- }, [te]), ve = w((o, S) => te("REPLACE", o, S), [te]), qe = w((o, S) => te("RESET", o, S), [te]), Ee = w((o) => {
419
- if (!o || typeof o != "object" || Array.isArray(o)) throw new TypeError("[react-modal-navigation] setParams expects an object");
420
- if (!x.current) return;
421
- const S = { type: "SET_PARAMS", params: o };
422
- V.current = Ke(V.current, S), P(S);
423
- }, []), Re = w((o) => {
424
- if (!o || typeof o != "object" || Array.isArray(o)) throw new TypeError("[react-modal-navigation] setOptions expects an object");
425
- if (!x.current) return;
426
- const S = { type: "SET_OPTIONS", options: o };
427
- V.current = Ke(V.current, S), P(S);
428
- }, []), an = w((o) => te("BACK", null, void 0, o), [te]), ze = w((o, S) => !x.current || h.current.getSnapshot().visible && t.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : g(o, S, { route: C, stack: a }), [t.lockCloseWhileLoading, g, C, a]), sn = l(ze);
429
- sn.current = ze;
430
- const cn = w((o) => sn.current("api", o), []), Ve = K(() => ({ navigate: Be, navigateAsync: me, replace: ve, reset: qe, setParams: Ee, setOptions: Re, goBack: an, close: cn, setLoading: Se }), [Be, me, ve, qe, Ee, Re, an, cn, Se]), ln = K(() => ({ canGoBack: a.length > 1, stack: a, currentRoute: C }), [a]);
431
- He(() => N.current.publish(ln), [ln]);
432
- const Ze = l(null);
433
- Ze.current || (Ze.current = Object.defineProperties({}, {
434
- canGoBack: { enumerable: !0, get: () => N.current.getSnapshot().canGoBack },
435
- stack: { enumerable: !0, get: () => N.current.getSnapshot().stack },
436
- currentRoute: { enumerable: !0, get: () => N.current.getSnapshot().currentRoute }
577
+ }, [xt, kt, u, Ce]), R = _((m, M) => y("NAVIGATE", m, M), [y]), w = _((m, M) => y("PUSH", m, M), [y]), H = _((m = 1) => y("POP", null, m), [y]), W = _(() => H(K.current.length - 1), [H]), ae = _((m) => {
578
+ const M = K.current.findLastIndex((j) => j.name === m);
579
+ return M < 0 ? Promise.resolve(!1) : H(K.current.length - M - 1);
580
+ }, [H]), me = _(async (m, M) => {
581
+ if (!L.current) return { status: "cancelled" };
582
+ let j;
583
+ return await y("NAVIGATE", m, M, void 0, (fe) => {
584
+ j = new Promise((ve) => {
585
+ const se = ++ke.current;
586
+ G.current.set(se, { key: fe.key, resolve: ve });
587
+ });
588
+ }) && j ? j : { status: "cancelled" };
589
+ }, [y]), ie = _((m, M) => y("REPLACE", m, M), [y]), pe = _((m, M) => y("RESET", m, M), [y]), Re = _((m) => {
590
+ if (!m || typeof m != "object" || Array.isArray(m)) throw new TypeError("[react-modal-navigation] setParams expects an object");
591
+ if (!L.current) return;
592
+ const M = { type: "SET_PARAMS", params: m };
593
+ K.current = mt(K.current, M), I({ type: "COMMIT", stack: K.current });
594
+ }, []), S = _((m) => {
595
+ if (!m || typeof m != "object" || Array.isArray(m)) throw new TypeError("[react-modal-navigation] setOptions expects an object");
596
+ if (!L.current) return;
597
+ const M = { type: "SET_OPTIONS", options: m };
598
+ K.current = mt(K.current, M), I({ type: "COMMIT", stack: K.current });
599
+ }, []), le = _((m) => y("BACK", null, void 0, m), [y]), Le = _((m, M) => !L.current || Te.current.getSnapshot().visible && s.lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : a(m, M, { route: ne, stack: v }), [s.lockCloseWhileLoading, a, ne, v]), ye = P(Le);
600
+ ye.current = Le;
601
+ const he = _((m) => ye.current("api", m), []), ze = _(async (m) => {
602
+ if (!L.current || O.current) return !1;
603
+ const M = K.current, j = $t(M, Ee, s.maxCachedScreens, C, b?.()).slice(0, -1).filter((Y) => m === void 0 || Y.name === m).map((Y) => Y.key);
604
+ if (!j.length) return !1;
605
+ O.current = !0;
606
+ try {
607
+ const Y = { reason: "cache", action: "CLEAR_CACHE", from: M.at(-1) };
608
+ return de.current && !await de.current(j, Y) || !await e.canRemove(j, Y) || !L.current || K.current !== M ? !1 : (e.tasks.cancelRoutes(j), j.forEach((fe) => $.current.delete(fe)), F((fe) => /* @__PURE__ */ new Set([...fe, ...j])), !0);
609
+ } catch (Y) {
610
+ return L.current && u(Y, { phase: "clearCache" }), !1;
611
+ } finally {
612
+ O.current = !1;
613
+ }
614
+ }, [e, u, Ee, s.maxCachedScreens, C, b]), qe = Q(() => ({ navigate: R, navigateAsync: me, push: w, pop: H, popTo: ae, popToTop: W, replace: ie, reset: pe, setParams: Re, setOptions: S, goBack: le, close: he, setLoading: De, clearCache: ze }), [R, me, w, H, ae, W, ie, pe, Re, S, le, he, De, ze]);
615
+ Ae(() => e.registerNavigation(qe), [e, qe]);
616
+ const Fe = Q(() => ({ canGoBack: v.length > 1, stack: v, currentRoute: ne }), [v]);
617
+ Ae(() => z.current.publish(Fe), [Fe]);
618
+ const St = P(null);
619
+ St.current || (St.current = Object.defineProperties({}, {
620
+ canGoBack: { enumerable: !0, get: () => z.current.getSnapshot().canGoBack },
621
+ stack: { enumerable: !0, get: () => z.current.getSnapshot().stack },
622
+ currentRoute: { enumerable: !0, get: () => z.current.getSnapshot().currentRoute }
437
623
  }));
438
- const De = K(() => Object.assign(Ze.current, Ve), [Ve]);
439
- He(() => {
440
- const o = U.current;
441
- if (U.current = null, J.current?.cancel?.(), J.current = null, F.current?.querySelectorAll("[data-pmn-outgoing]").forEach((se) => se.remove()), !we || !de.enabled || !o || !F.current || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
442
- const S = F.current;
443
- o.removeAttribute("hidden"), o.removeAttribute("tabindex"), o.setAttribute("aria-hidden", "true"), o.setAttribute("inert", ""), o.dataset.pmnOutgoing = "true", o.querySelectorAll("[id]").forEach((se) => se.removeAttribute("id")), o.querySelectorAll("[autofocus]").forEach((se) => se.removeAttribute("autofocus")), o.style.cssText += ";position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none;overflow:hidden;background:var(--pmn-body);", S.appendChild(o);
444
- const z = de.direction === "back" ? 1 : -1, I = [...S.querySelectorAll("[data-modal-route-key]")].find((se) => se.dataset.modalRouteKey === W);
445
- I && (I.style.zIndex = "2");
446
- const ae = () => {
447
- o.remove(), I && (I.style.zIndex = ""), J.current === Y && (J.current = null);
624
+ const dt = Q(() => Object.assign(St.current, qe), [qe]);
625
+ Ae(() => {
626
+ const m = te.current;
627
+ if (te.current = null, V.current?.cancel?.(), V.current = null, B.current?.querySelectorAll("[data-pmn-outgoing]").forEach((se) => se.remove()), !We || !Ne.enabled || !m || !B.current || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
628
+ const M = B.current;
629
+ m.removeAttribute("hidden"), m.removeAttribute("tabindex"), m.setAttribute("aria-hidden", "true"), m.setAttribute("inert", ""), m.dataset.pmnOutgoing = "true", m.querySelectorAll("[id]").forEach((se) => se.removeAttribute("id")), m.querySelectorAll("[autofocus]").forEach((se) => se.removeAttribute("autofocus")), m.style.cssText += ";position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none;overflow:hidden;background:var(--pmn-body);", M.appendChild(m);
630
+ const j = Ne.direction === "back" ? 1 : -1, Y = [...M.querySelectorAll("[data-modal-route-key]")].find((se) => se.dataset.modalRouteKey === re);
631
+ Y && (Y.style.zIndex = "2");
632
+ const fe = () => {
633
+ m.remove(), Y && (Y.style.zIndex = ""), V.current === ve && (V.current = null);
448
634
  };
449
- let Y;
450
- if (o.animate)
451
- Y = o.animate([
635
+ let ve;
636
+ if (m.animate)
637
+ ve = m.animate([
452
638
  { opacity: 1, transform: "translate3d(0,0,0)" },
453
- { opacity: 1, transform: `translate3d(${z * 100}%,0,0)` }
454
- ], { duration: de.duration, easing: "cubic-bezier(.22,1,.36,1)", fill: "forwards" }), Y.addEventListener("finish", ae, { once: !0 }), Y.addEventListener("cancel", ae, { once: !0 }), J.current = Y;
639
+ { opacity: 1, transform: `translate3d(${j * 100}%,0,0)` }
640
+ ], { duration: Ne.duration, easing: "cubic-bezier(.22,1,.36,1)", fill: "forwards" }), ve.addEventListener("finish", fe, { once: !0 }), ve.addEventListener("cancel", fe, { once: !0 }), V.current = ve;
455
641
  else {
456
- o.classList.add("pmn-page-exit", `pmn-page-exit-${de.direction}`), o.style.setProperty("--pmn-page-duration", `${de.duration}ms`), o.style.setProperty("--pmn-page-distance", "100%");
457
- const se = setTimeout(ae, de.duration + 40);
458
- Y = { cancel: () => {
459
- clearTimeout(se), ae();
460
- } }, J.current = Y;
642
+ m.classList.add("pmn-page-exit", `pmn-page-exit-${Ne.direction}`), m.style.setProperty("--pmn-page-duration", `${Ne.duration}ms`), m.style.setProperty("--pmn-page-distance", "100%");
643
+ const se = setTimeout(fe, Ne.duration + 40);
644
+ ve = { cancel: () => {
645
+ clearTimeout(se), fe();
646
+ } }, V.current = ve;
461
647
  }
462
648
  return () => {
463
- Y?.cancel?.(), o.remove();
649
+ ve?.cancel?.(), m.remove();
464
650
  };
465
- }, [W]), He(() => {
466
- _.current = !1;
467
- const o = [...O.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((I) => I.dataset.modalRouteKey === W);
468
- if (!o) return;
469
- const S = j.current.get(W);
470
- (S?.isConnected && o.contains(S) && !S.matches(":disabled") && !S.closest("[inert], [hidden]") ? S : o).focus({ preventScroll: !0 });
471
- }, [W]), Q(() => {
472
- let o = !1;
473
- for (const [z, I] of Le.current)
474
- I.owner !== "global" && I.owner !== W && (Le.current.delete(z), o = !0);
475
- o && Ae();
476
- const S = new Set(a.map((z) => z.key));
477
- v((z) => {
478
- const I = Object.keys(z).filter((Y) => !S.has(Y));
479
- if (!I.length) return z;
480
- const ae = { ...z };
481
- return I.forEach((Y) => delete ae[Y]), ae;
651
+ }, [re]), Ae(() => {
652
+ J.current = !1;
653
+ const m = [...X.current?.querySelectorAll("[data-modal-route-key]") ?? []].find((Y) => Y.dataset.modalRouteKey === re);
654
+ if (!m) return;
655
+ const M = $.current.get(re);
656
+ (M?.isConnected && m.contains(M) && !M.matches(":disabled") && !M.closest("[inert], [hidden]") ? M : m).focus({ preventScroll: !0 });
657
+ }, [re]), U(() => {
658
+ let m = !1;
659
+ for (const [j, Y] of ut.current)
660
+ Y.owner !== "global" && Y.owner !== re && (ut.current.delete(j), m = !0);
661
+ m && Ge();
662
+ const M = new Set(v.map((j) => j.key));
663
+ ue((j) => {
664
+ const Y = Object.keys(j).filter((ve) => !M.has(ve));
665
+ if (!Y.length) return j;
666
+ const fe = { ...j };
667
+ return Y.forEach((ve) => delete fe[ve]), fe;
482
668
  });
483
- for (const z of j.current.keys()) S.has(z) || j.current.delete(z);
484
- }, [W, a, Ae]), Q(() => {
485
- if (E.current?.key !== W) {
486
- if (E.current) {
487
- const o = { from: E.current, to: C, stack: a };
488
- ne("onBlur", { route: E.current, ...o }), ne("onNavigate", o), ne("onRouteChange", o);
669
+ for (const j of $.current.keys()) M.has(j) || $.current.delete(j);
670
+ }, [re, v, Ge]), U(() => {
671
+ if (oe.current?.key !== re) {
672
+ if (oe.current) {
673
+ const m = { from: oe.current, to: ne, stack: v };
674
+ c("onBlur", { route: oe.current, ...m }), c("onNavigate", m), c("onRouteChange", m);
489
675
  }
490
- ne("onFocus", { route: C, stack: a }), E.current = C;
676
+ c("onFocus", { route: ne, stack: v }), oe.current = ne;
491
677
  }
492
- }, [C, W, a, ne]), Q(() => () => {
493
- Le.current.clear(), j.current.clear();
494
- for (const o of re.current.values()) o.resolve({ status: "dismissed" });
495
- re.current.clear();
496
- }, []), Q(() => {
497
- ye.current || (ye.current = !0, p?.({ route: C, stack: a }));
678
+ }, [ne, re, v, c]), U(() => () => {
679
+ ut.current.clear(), $.current.clear();
680
+ for (const m of G.current.values()) m.resolve({ status: "dismissed" });
681
+ G.current.clear();
682
+ }, []), U(() => {
683
+ k.current || (k.current = !0, l?.({ route: ne, stack: v }));
498
684
  }, []);
499
- const Bn = K(() => $n(a, c, t.maxCachedScreens), [a, c, t.maxCachedScreens]), un = K(() => ({ ...c[C.name], ...C.options ?? {} }), [c, C.name, C.options]);
500
- return /* @__PURE__ */ s(rn.Provider, { value: $, children: /* @__PURE__ */ s(wn.Provider, { value: G.current, children: /* @__PURE__ */ s(xn.Provider, { value: L.current, children: /* @__PURE__ */ s(vn.Provider, { value: De, children: /* @__PURE__ */ s(_e.Provider, { value: Ve, children: /* @__PURE__ */ s(We.Provider, { value: N.current, children: /* @__PURE__ */ s(Me.Provider, { value: ke, children: /* @__PURE__ */ ce(En, { dialogRef: O, options: t, requestClose: ze, exiting: m, children: [
501
- /* @__PURE__ */ s(Rn, { options: t, screen: un, route: C, navigation: De, requestClose: ze, translate: i, canGoBack: a.length > 1 }),
502
- /* @__PURE__ */ s("main", { ref: F, className: "pmn-main", children: Bn.map((o) => /* @__PURE__ */ s(
503
- Un,
685
+ const Ct = $t(v, Ee, s.maxCachedScreens, C, b?.());
686
+ Ae(() => {
687
+ F((m) => hn(v, Ct, m));
688
+ }, [v, Ct]);
689
+ const Et = Q(() => ({ ...Ee[ne.name], ...ne.options ?? {} }), [Ee, ne.name, ne.options]), ln = e.refs.header;
690
+ return /* @__PURE__ */ p(yt.Provider, { value: ln.current, children: /* @__PURE__ */ p(Tt.Provider, { value: q, children: /* @__PURE__ */ p(Vt.Provider, { value: D.current, children: /* @__PURE__ */ p(Ut.Provider, { value: E.current, children: /* @__PURE__ */ p(_t.Provider, { value: dt, children: /* @__PURE__ */ p(vt.Provider, { value: qe, children: /* @__PURE__ */ p(bt.Provider, { value: z.current, children: /* @__PURE__ */ p(Ue.Provider, { value: Ze, children: /* @__PURE__ */ be(Xt, { store: e.stores.layout, screenOptions: Et.modalOptions, dialogRef: X, requestClose: Le, exiting: h, children: [
691
+ /* @__PURE__ */ p(Jt, { store: e.stores.layout, screen: Et, route: ne, navigation: dt, requestClose: Le, translate: o, canGoBack: v.length > 1 }),
692
+ /* @__PURE__ */ p("main", { ref: B, className: "pmn-main", children: Ct.map((m) => /* @__PURE__ */ p(
693
+ Kn,
504
694
  {
505
- route: o,
506
- screen: c[o.name],
507
- navigation: De,
508
- focused: o.key === W,
509
- resultEvent: T[o.key] ?? null,
510
- bodyClassName: t.bodyClassName,
511
- setFooter: R,
512
- loadingApi: ke,
513
- loadingStore: D.current,
695
+ route: m,
696
+ screen: Ee[m.name],
697
+ navigation: dt,
698
+ focused: m.key === re,
699
+ resultEvent: Z[m.key] ?? null,
700
+ bodyClassName: s.bodyClassName,
701
+ setFooter: qt,
702
+ loadingApi: Ze,
703
+ loadingStore: T.current,
514
704
  notifyError: u,
515
- registerDirtyGuard: k,
516
- pageMotion: de,
517
- lazyFallback: t.lazyFallback
705
+ registerDirtyGuard: g,
706
+ pageMotion: m.key === re ? Ne : null,
707
+ lazyFallback: s.lazyFallback
518
708
  },
519
- o.key
709
+ m.key
520
710
  )) }),
521
- /* @__PURE__ */ s(
522
- Wn,
711
+ /* @__PURE__ */ p(
712
+ Dn,
523
713
  {
524
- store: L.current,
525
- routeKey: W,
526
- screen: un,
527
- options: t,
528
- route: C,
529
- navigation: De,
530
- requestClose: ze,
531
- translate: i,
714
+ store: E.current,
715
+ routeKey: re,
716
+ screen: Et,
717
+ layoutStore: e.stores.layout,
718
+ route: ne,
719
+ navigation: dt,
720
+ requestClose: Le,
721
+ translate: o,
532
722
  onError: u,
533
- loadingApi: ke
723
+ loadingApi: Ze
534
724
  },
535
- W
725
+ re
536
726
  ),
537
- /* @__PURE__ */ s(Hn, { store: D.current, translate: i }),
538
- /* @__PURE__ */ s(_n, { store: G.current, dismiss: H }),
539
- y && /* @__PURE__ */ ce("div", { className: "pmn-error", role: "alert", children: [
540
- /* @__PURE__ */ s("span", { children: y.message || String(y) }),
541
- /* @__PURE__ */ s("button", { type: "button", onClick: M, "aria-label": "Dismiss error", children: "×" })
727
+ /* @__PURE__ */ p($n, { store: T.current, translate: o }),
728
+ /* @__PURE__ */ p(In, { store: D.current, dismiss: N }),
729
+ i && /* @__PURE__ */ be("div", { className: "pmn-error", role: "alert", children: [
730
+ /* @__PURE__ */ p("span", { children: i.message || String(i) }),
731
+ /* @__PURE__ */ p("button", { type: "button", onClick: d, "aria-label": "Dismiss error", children: "×" })
542
732
  ] })
543
- ] }) }) }) }) }) }) }) });
544
- }
545
- const Vn = be.memo(function({ store: n, route: r, ...t }) {
546
- const i = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
547
- return /* @__PURE__ */ s(Cn, { ...t, route: r, override: i[r.key] });
548
- }), Zn = be.memo(function({ store: n, translate: r }) {
549
- const t = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
550
- return /* @__PURE__ */ s(Tn, { loading: t, translate: r });
551
- }), Qn = be.memo(function({ store: n, dismiss: r }) {
552
- const t = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
553
- return /* @__PURE__ */ s(Pn, { items: t, dismiss: r });
554
- });
555
- function Jn({ config: e, initialScreen: n, params: r, options: t, translate: i, onRequestClose: g, onOpened: p, registerLoading: f, notifyError: u, error: y, clearError: M, registerDirtyGuard: k, exiting: d = !1 }) {
556
- const m = n ?? e.initialRoute ?? Object.keys(e.screens)[0], [a, P] = pe(() => ({ key: "single", name: m, params: r ?? {}, options: {} })), N = l(a);
557
- N.current = a;
558
- const D = e.screens[m], L = l(!0), G = l(null), x = l(null), B = l(null), $ = l(null), H = l(null);
559
- x.current || (x.current = kn({ canGoBack: !1, stack: [a], currentRoute: a })), B.current || (B.current = Te({})), $.current || ($.current = Te({ visible: !1, text: null, count: 0 })), H.current || (H.current = Te([]));
560
- const T = l("single"), { loadingApi: v, setLoading: j } = An($, L, T), { toast: O, dismissToast: F } = Nn(H, L), U = w((b, C) => {
561
- const W = B.current, ue = W.getSnapshot();
562
- if (C === null) {
563
- if (ue[b] !== void 0) {
564
- const he = { ...ue };
565
- delete he[b], W.publish(he);
733
+ ] }) }) }) }) }) }) }) }) });
734
+ }
735
+ const Or = (e) => e, Pr = (e) => ({ definitionLoader: e }), pt = /* @__PURE__ */ new WeakMap();
736
+ function gt(e) {
737
+ if (!pt.has(e)) {
738
+ const t = Promise.resolve().then(e).catch((n) => {
739
+ throw pt.delete(e), n;
740
+ });
741
+ pt.set(e, t);
742
+ }
743
+ return pt.get(e);
744
+ }
745
+ async function an(e, t) {
746
+ let n = typeof e == "string" ? t && Object.hasOwn(t, e) ? t[e] : void 0 : e;
747
+ if (n?.definitionLoader) {
748
+ const r = await gt(n.definitionLoader);
749
+ n = r.default ?? r;
750
+ }
751
+ if (!n || !(n.component || n.loader || n.screens)) throw new Error(`[react-modal-navigation] Unknown or invalid modal: ${typeof e == "string" ? e : "inline"}`);
752
+ return n;
753
+ }
754
+ async function Wn(e, t, n) {
755
+ const r = await an(e, t), a = (Array.isArray(n) ? n : [n ?? r.initialRoute ?? Object.keys(r.screens ?? {})[0]]).map((l) => r.screens ? Object.hasOwn(r.screens, l) ? r.screens[l] : null : r);
756
+ if (a.some((l) => !l)) throw new Error("[react-modal-navigation] Unknown preload screen");
757
+ return await Promise.all(a.map((l) => l.loader ? gt(l.loader) : void 0)), r;
758
+ }
759
+ function Gn(e) {
760
+ return function(n) {
761
+ const [r, o] = xe(() => Se.lazy(() => gt(e)));
762
+ return /* @__PURE__ */ p(Nt, { route: n.route, onRetry: () => o(() => Se.lazy(() => gt(e))), children: /* @__PURE__ */ p(r, { ...n }) });
763
+ };
764
+ }
765
+ function _n(e, { limit: t = 100 } = {}) {
766
+ const n = Number.isFinite(t) ? Math.max(1, Math.min(1e3, Math.floor(t))) : 100, r = je({ active: null, queueSize: 0, events: [] });
767
+ let o, a = 0, l = !1, f = [];
768
+ const u = (g, b) => {
769
+ if (l) return;
770
+ const x = r.getSnapshot(), h = e.hostStore.getSnapshot().active, s = h?.runtime.alive.current ? h : null, v = s?.runtime.stores.navigation.getSnapshot(), I = s?.runtime.stores.loading.getSnapshot();
771
+ let z = s ? { id: s.id, name: s.name, routes: v.stack.map(({ key: L, name: A }) => ({ key: L, name: A })), focusedKey: v.currentRoute?.key, loadingCount: I.count, taskCount: s.runtime.tasks.count() } : null;
772
+ const T = g ? [...x.events, { sequence: ++a, time: Date.now(), type: g, id: b }].slice(-n) : x.events, E = x.active;
773
+ z && E && z.id === E.id && z.name === E.name && z.focusedKey === E.focusedKey && z.loadingCount === E.loadingCount && z.taskCount === E.taskCount && z.routes.length === E.routes.length && z.routes.every((L, A) => L.key === E.routes[A].key && L.name === E.routes[A].name) && (z = E);
774
+ const D = e.statusStore.getSnapshot().queueSize;
775
+ z === E && D === x.queueSize && T === x.events || r.publish({ active: z, queueSize: D, events: T });
776
+ }, i = () => {
777
+ const g = e.hostStore.getSnapshot().active?.runtime;
778
+ g !== o && (f.forEach((b) => b()), o = g, f = g ? ["ready", "destroy", "change", "routeChange", "routeRemove", "routeBlur", "routeFocus"].map((b) => g.events.on(b, (x) => u(b === "change" ? `store.${x.store}` : `instance.${b}`, x.id))) : []), u();
779
+ }, d = [e.hostStore.subscribe(i), e.statusStore.subscribe(() => u()), ...["open", "close", "queueChange"].map((g) => e.commands.on(g, (b) => u(`manager.${g}`, b.id)))];
780
+ return i(), {
781
+ getSnapshot: r.getSnapshot,
782
+ subscribe: r.subscribe,
783
+ refresh: () => u(),
784
+ clear() {
785
+ !l && r.getSnapshot().events.length && r.publish({ ...r.getSnapshot(), events: [] });
786
+ },
787
+ dispose() {
788
+ l || (l = !0, d.forEach((g) => g()), f.forEach((g) => g()), f = [], o = null, r.publish({ active: null, queueSize: 0, events: [] }), r.destroy());
789
+ }
790
+ };
791
+ }
792
+ function sn() {
793
+ const e = /* @__PURE__ */ new Map();
794
+ let t = !1;
795
+ const n = (r, o) => {
796
+ const a = e.get(r);
797
+ a?.delete(o), a?.size || e.delete(r);
798
+ };
799
+ return {
800
+ on(r, o) {
801
+ if (t) return () => {
802
+ };
803
+ const a = e.get(r) ?? /* @__PURE__ */ new Set();
804
+ return e.set(r, a), a.add(o), () => n(r, o);
805
+ },
806
+ off: n,
807
+ emit(r, o) {
808
+ if (!t) {
809
+ for (const a of [...e.get(r) ?? []])
810
+ if (!(t || !e.get(r)?.has(a)))
811
+ try {
812
+ Promise.resolve(a(o)).catch((l) => console.error(l));
813
+ } catch (l) {
814
+ console.error(l);
815
+ }
566
816
  }
567
- } else ue[b] !== C && W.publish({ ...ue, [b]: C });
568
- }, []), J = w((b = "api", C) => g(b, C), [g]), E = w(() => Promise.resolve(!1), []), _ = K(() => ({
569
- navigate: E,
570
- navigateAsync: async () => ({ status: "cancelled" }),
571
- replace: E,
572
- reset: E,
573
- goBack: E,
574
- popToTop: E,
575
- popTo: E,
576
- setParams: (b) => (P((C) => ({ ...C, params: { ...C.params, ...typeof b == "function" ? b(C.params) : b } })), !0),
577
- setOptions: (b) => (P((C) => ({ ...C, options: { ...C.options, ...b } })), !0),
578
- close: J,
579
- setLoading: j,
580
- canGoBack: !1,
581
- stack: [a],
582
- currentRoute: a
583
- }), [J, a, j, E]), q = l(_);
584
- q.current = _;
585
- const re = K(() => ({
586
- navigate: (...b) => q.current.navigate(...b),
587
- navigateAsync: (...b) => q.current.navigateAsync(...b),
588
- replace: (...b) => q.current.replace(...b),
589
- reset: (...b) => q.current.reset(...b),
590
- goBack: (...b) => q.current.goBack(...b),
591
- popToTop: (...b) => q.current.popToTop(...b),
592
- popTo: (...b) => q.current.popTo(...b),
593
- setParams: (...b) => q.current.setParams(...b),
594
- setOptions: (...b) => q.current.setOptions(...b),
595
- close: (...b) => q.current.close(...b),
596
- setLoading: (...b) => q.current.setLoading(...b)
597
- }), []), X = K(() => ({
598
- setLoading: (b, C) => v.setScreenLoading("single", b, C),
599
- showLoading: (b) => v.begin("single", b),
600
- hideLoading: (b) => v.end("single", b)
601
- }), [v]), ge = K(() => ({ isFocused: !0, resultEvent: null, routeKey: "single", setFooter: U }), [U]), V = K(() => ({ routeKey: "single", registerDirtyGuard: k }), [k]);
602
- Q(() => {
603
- x.current.publish({ canGoBack: !1, stack: [a], currentRoute: a });
604
- }, [a]), Q(() => (L.current = !0, f?.({ setLoading: j }), p?.({ route: N.current, stack: [N.current] }), () => {
605
- L.current = !1;
606
- }), []);
607
- const le = { ...D, ...a.options }, ye = D.component;
608
- return /* @__PURE__ */ s(rn.Provider, { value: O, children: /* @__PURE__ */ s(wn.Provider, { value: H.current, children: /* @__PURE__ */ s(xn.Provider, { value: B.current, children: /* @__PURE__ */ s(vn.Provider, { value: _, children: /* @__PURE__ */ s(_e.Provider, { value: re, children: /* @__PURE__ */ s(We.Provider, { value: x.current, children: /* @__PURE__ */ s(Me.Provider, { value: v, children: /* @__PURE__ */ ce(En, { dialogRef: G, options: t, requestClose: J, exiting: d, children: [
609
- /* @__PURE__ */ s(Rn, { options: t, screen: le, route: a, navigation: _, requestClose: J, translate: i, canGoBack: !1 }),
610
- /* @__PURE__ */ s("main", { className: "pmn-main", children: /* @__PURE__ */ s(on.Provider, { value: a, children: /* @__PURE__ */ s(tn.Provider, { value: V, children: /* @__PURE__ */ s(je.Provider, { value: ge, children: /* @__PURE__ */ s(Me.Provider, { value: X, children: /* @__PURE__ */ s(Ue.Provider, { value: $.current, children: /* @__PURE__ */ s("div", { className: `pmn-body ${t.bodyClassName ?? ""}`, "data-modal-route-key": "single", tabIndex: -1, children: /* @__PURE__ */ s(Mn, { route: a, onError: u, children: /* @__PURE__ */ s(bn, { fallback: t.lazyFallback ?? /* @__PURE__ */ s("div", { className: "pmn-lazy-loading", role: "status", "aria-live": "polite", children: "加载中..." }), children: /* @__PURE__ */ s(ye, { route: a, navigation: _ }) }) }) }) }) }) }) }) }) }),
611
- /* @__PURE__ */ s(Vn, { store: B.current, route: a, screen: le, options: t, navigation: _, requestClose: J, translate: i, onError: u, loadingApi: v }),
612
- /* @__PURE__ */ s(Zn, { store: $.current, translate: i }),
613
- /* @__PURE__ */ s(Qn, { store: H.current, dismiss: F }),
614
- y && /* @__PURE__ */ ce("div", { className: "pmn-error", role: "alert", children: [
615
- /* @__PURE__ */ s("span", { children: y.message || String(y) }),
616
- /* @__PURE__ */ s("button", { type: "button", onClick: M, children: "×" })
617
- ] })
618
- ] }) }) }) }) }) }) }) });
817
+ },
818
+ clear() {
819
+ e.clear();
820
+ },
821
+ destroy() {
822
+ t = !0, e.clear();
823
+ }
824
+ };
619
825
  }
620
- const Xn = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:#ffffffb8;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:#0f172ab8}.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}.pmn-toast-region{position:absolute;top:56px;left:12px;right:12px;z-index:80;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;max-height:calc(100% - 72px);overflow:hidden}.pmn-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:100%;min-width:min(260px,100%);padding:11px 13px;border:1px solid var(--pmn-border);border-radius:9px;background:var(--pmn-surface);color:var(--pmn-text);box-shadow:0 5px 18px #0000001a;font-size:13px;line-height:1.5;overflow-wrap:anywhere}.pmn-toast-symbol{flex:0 0 20px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;font-size:13px;font-weight:700;background:var(--pmn-hover);color:var(--pmn-muted)}.pmn-toast-success .pmn-toast-symbol{background:#dcfce7;color:#15803d}.pmn-toast-error .pmn-toast-symbol{background:#fee2e2;color:#b91c1c}.pmn-toast-warning .pmn-toast-symbol{background:#fef3c7;color:#b45309}.pmn-toast-info .pmn-toast-symbol{background:#dbeafe;color:#1d4ed8}.pmn-toast-message{flex:1;min-width:0;white-space:pre-wrap}.pmn-toast-close{border:0;background:transparent;color:var(--pmn-muted);cursor:pointer;font-size:19px;line-height:18px;padding:0 1px}.pmn-toast-close:hover{color:var(--pmn-text)}.pmn-button-danger{background:#dc2626!important;color:#fff!important;border-color:#dc2626!important}@keyframes pmn-page-forward-in{0%{opacity:.18;transform:translate3d(var(--pmn-page-distance,96px),0,0) scale(.985)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-back-in{0%{opacity:.18;transform:translate3d(calc(-1 * var(--pmn-page-distance,96px)),0,0) scale(.985)}to{opacity:1;transform:translateZ(0)}}.pmn-page-enter{animation-duration:var(--pmn-page-duration,.36s);animation-timing-function:cubic-bezier(.2,.8,.2,1);animation-fill-mode:both;will-change:transform,opacity}.pmn-page-forward{animation-name:pmn-page-forward-in}.pmn-page-back{animation-name:pmn-page-back-in}@media(prefers-reduced-motion:reduce){.pmn-page-enter{animation:none!important;will-change:auto}}.pmn-main{position:relative;isolation:isolate}.pmn-page-exit{animation-duration:var(--pmn-page-duration,.36s);animation-timing-function:cubic-bezier(.22,1,.36,1);animation-fill-mode:forwards}@keyframes pmn-page-forward-out{to{opacity:.45;transform:translate3d(calc(-1 * var(--pmn-page-distance,96px)),0,0) scale(.985)}}@keyframes pmn-page-back-out{to{opacity:.45;transform:translate3d(var(--pmn-page-distance,96px),0,0) scale(.985)}}.pmn-page-exit-forward{animation-name:pmn-page-forward-out}.pmn-page-exit-back{animation-name:pmn-page-back-out}@media(prefers-reduced-motion:reduce){.pmn-page-exit{animation:none!important}}.pmn-main>.pmn-body{position:relative;width:100%;flex:1 0 100%;background:var(--pmn-body)}.pmn-page-forward,.pmn-page-back{z-index:2}@keyframes pmn-page-forward-in{0%{opacity:1;transform:translate3d(100%,0,0)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-back-in{0%{opacity:1;transform:translate3d(-100%,0,0)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-forward-out{to{opacity:1;transform:translate3d(-100%,0,0)}}@keyframes pmn-page-back-out{to{opacity:1;transform:translate3d(100%,0,0)}}.pmn-lazy-loading{display:flex;min-height:80px;align-items:center;justify-content:center;color:var(--pmn-muted);font-size:14px}.pmn-place-top .pmn-dialog{max-height:min(calc(100dvh - var(--pmn-top-offset, var(--pmn-gap)) - var(--pmn-gap)),var(--pmn-max-height,100dvh))}.pmn-dialog.pmn-has-custom-background{isolation:isolate;--pmn-body:transparent}.pmn-custom-background-layer{position:absolute;inset:0;z-index:0;pointer-events:none}.pmn-dialog.pmn-has-custom-background>:not(.pmn-custom-background-layer){position:relative;z-index:1}.pmn-dialog.pmn-has-custom-background .pmn-main>.pmn-body{background:transparent}", gn = "react-modal-navigation-styles", en = /* @__PURE__ */ new WeakMap();
621
- function et() {
622
- zn(() => {
623
- if (typeof document > "u") return;
624
- const e = document;
625
- let n = en.get(e);
626
- if (!n) {
627
- let r = e.getElementById(gn);
628
- const t = !r;
629
- r || (r = e.createElement("style"), r.id = gn, r.setAttribute("data-react-modal-navigation", ""), r.textContent = Xn, e.head.appendChild(r)), n = { element: r, owned: t, count: 0 }, en.set(e, n);
826
+ function Un(e, t, n, r) {
827
+ const o = n.currentRoute, a = r.currentRoute;
828
+ if (o?.key === a?.key && n.stack.length === r.stack.length && n.stack.every((g, b) => g.key === r.stack[b].key)) return;
829
+ const l = new Set(n.stack.map((g) => g.key)), f = new Set(r.stack.map((g) => g.key)), u = n.stack.filter((g) => !f.has(g.key)), i = r.stack.filter((g) => !l.has(g.key));
830
+ if (o?.key === a?.key && !u.length && !i.length) return;
831
+ const d = { id: t, from: o, to: a, added: i, removed: u, stack: r.stack };
832
+ e.emit("routeChange", d), u.length && e.emit("routeRemove", d), o?.key !== a?.key && (o && e.emit("routeBlur", { ...d, route: o }), a && e.emit("routeFocus", { ...d, route: a }));
833
+ }
834
+ function Vn() {
835
+ const e = /* @__PURE__ */ new Map();
836
+ let t = !1;
837
+ const n = /* @__PURE__ */ new Set(), r = (a) => {
838
+ try {
839
+ Promise.resolve(a.cancel()).catch((l) => console.error(l));
840
+ } catch (l) {
841
+ console.error(l);
630
842
  }
631
- return n.count += 1, () => {
632
- n.count -= 1, n.count === 0 && (n.owned && n.element.remove(), en.delete(e));
843
+ }, o = (a) => {
844
+ for (const [l, f] of [...e])
845
+ !a(f) || !e.delete(l) || r(l);
846
+ };
847
+ return {
848
+ register(a, l) {
849
+ return t || n.has(a) ? (r(l), () => {
850
+ }) : (e.set(l, a), () => e.delete(l));
851
+ },
852
+ cancelRoutes(a) {
853
+ const l = new Set(a), f = [...l].filter((u) => !n.has(u));
854
+ f.forEach((u) => n.add(u));
855
+ try {
856
+ o((u) => l.has(u));
857
+ } finally {
858
+ f.forEach((u) => n.delete(u));
859
+ }
860
+ },
861
+ destroy() {
862
+ t || (t = !0, o(() => !0));
863
+ },
864
+ count: () => e.size
865
+ };
866
+ }
867
+ function Yn(e, t) {
868
+ const n = e.config.singlePage || Object.keys(e.config.screens).length === 1, r = n ? [{ key: "single", name: e.screen, params: e.params ?? {}, options: {} }] : Yt(e.screen, e.params), o = je({});
869
+ o.set = (C, F) => {
870
+ const $ = o.getSnapshot();
871
+ if (F == null && !(C in $) || Object.is($[C], F)) return;
872
+ const X = { ...$ };
873
+ F == null ? delete X[C] : X[C] = F, o.publish(X);
874
+ };
875
+ const a = {
876
+ layout: je(t),
877
+ navigation: je({ canGoBack: !1, stack: r, currentRoute: r[0] }),
878
+ header: o,
879
+ footer: je({}),
880
+ loading: je({ visible: !1, text: null, count: 0 }),
881
+ toast: je([])
882
+ }, l = Object.fromEntries(Object.entries(a).map(([C, F]) => [C, { current: F }])), f = sn();
883
+ let u;
884
+ const i = () => {
885
+ const C = Object.entries(a);
886
+ return (!u || C.some(([F, $]) => !Object.is(u[F], $.getSnapshot()))) && (u = Object.freeze(Object.fromEntries(C.map(([F, $]) => [F, $.getSnapshot()])))), u;
887
+ }, d = (C, F, $ = Object.is, X) => {
888
+ if (!s.current) return () => {
633
889
  };
634
- }, []);
890
+ const B = X === void 0 ? Object.values(a) : [...new Set(X)].map((J) => {
891
+ if (!Object.hasOwn(a, J)) throw new Error(`Unknown runtime store: ${J}`);
892
+ return a[J];
893
+ });
894
+ let te = C(i());
895
+ const V = () => {
896
+ try {
897
+ const J = C(i());
898
+ if ($(te, J)) return;
899
+ const O = te;
900
+ te = J, Promise.resolve(F(J, O)).catch((G) => console.error(G));
901
+ } catch (J) {
902
+ console.error(J);
903
+ }
904
+ }, oe = B.map((J) => J.subscribe(V));
905
+ return () => oe.forEach((J) => J());
906
+ }, g = Vn(), b = /* @__PURE__ */ new Map(), x = (C, F) => {
907
+ if (!s.current) return () => {
908
+ };
909
+ const $ = b.get(C) ?? /* @__PURE__ */ new Set();
910
+ return b.set(C, $), $.add(F), () => {
911
+ $.delete(F), !$.size && b.get(C) === $ && b.delete(C);
912
+ };
913
+ }, h = async (C, F) => {
914
+ for (const $ of C) for (const X of [...b.get($) ?? []]) {
915
+ if (!s.current) return !1;
916
+ if (b.get($)?.has(X) && await X(F) === !1)
917
+ return !1;
918
+ }
919
+ return s.current;
920
+ }, s = { current: !0 };
921
+ let v;
922
+ const I = new Promise((C) => {
923
+ v = C;
924
+ }), z = (C) => s.current ? (N.navigationCommands = C, v(!0), N.hasRegistered || (N.hasRegistered = !0, f.emit("ready", { id: e.id })), () => {
925
+ N.navigationCommands === C && (N.navigationCommands = null);
926
+ }) : () => {
927
+ }, T = /* @__PURE__ */ new Set(), E = { current: /* @__PURE__ */ new Map() }, D = { current: /* @__PURE__ */ new Map() }, L = { current: 0 }, A = (C) => s.current ? (T.add(C), () => T.delete(C)) : (C(), () => {
928
+ }), q = () => {
929
+ if (s.current) {
930
+ s.current = !1, v(!1), N.navigationCommands = null, g.destroy(), b.clear();
931
+ for (const C of T)
932
+ try {
933
+ C();
934
+ } catch (F) {
935
+ console.error(F);
936
+ }
937
+ T.clear(), E.current.clear();
938
+ for (const C of D.current.values()) C.resolve({ status: "dismissed" });
939
+ D.current.clear(), a.layout.destroy({}), a.navigation.destroy({ canGoBack: !1, stack: [], currentRoute: null }), a.header.destroy({}), a.footer.destroy({}), a.loading.destroy({ visible: !1, text: null, count: 0 }), a.toast.destroy([]), u = void 0, f.emit("destroy", { id: e.id }), f.destroy();
940
+ }
941
+ }, N = { events: f, getSnapshot: i, subscribeState: d, ready: I, registerNavigation: z, id: e.id, single: n, stores: a, refs: l, alive: s, loadingTasks: E, loadingSequence: L, pageRequests: D, tasks: g, registerRemovalGuard: x, canRemove: h, addCleanup: A, destroy: q }, Z = [];
942
+ let ue = !1;
943
+ for (const [C, F] of Object.entries(a)) {
944
+ let $ = F.getSnapshot();
945
+ F.subscribe(() => {
946
+ const X = F.getSnapshot(), B = $;
947
+ if ($ = X, Z.push({ key: C, old: B, next: X }), !ue) {
948
+ ue = !0;
949
+ try {
950
+ for (let te = 0; te < Z.length && s.current; te++) {
951
+ const { key: V, old: oe, next: J } = Z[te];
952
+ f.emit("change", { id: e.id, store: V, previous: oe, current: J }), V === "navigation" && s.current && Un(f, e.id, oe, J);
953
+ }
954
+ } finally {
955
+ Z.length = 0, ue = !1;
956
+ }
957
+ }
958
+ });
959
+ }
960
+ return N;
635
961
  }
636
- function Ge(e, n, r) {
962
+ function nt(e, t, n) {
637
963
  if (typeof e == "string") {
638
964
  if (!e.trim()) throw new TypeError("[react-modal-navigation] modal name must not be empty");
639
- return { name: e, params: n ?? {}, options: r ?? {} };
965
+ return { name: e, params: t ?? {}, options: n ?? {} };
640
966
  }
641
967
  if (e === null || typeof e != "object" || Array.isArray(e))
642
968
  throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");
643
- const { name: t, screen: i, params: g = {}, options: p = {}, ...f } = e;
644
- if (typeof t != "string" || !t.trim())
969
+ if (e.component || e.loader || e.screens || e.definitionLoader) {
970
+ const { params: u, options: i, screen: d, ...g } = e;
971
+ return { name: g, params: t ?? u ?? {}, options: { ...i, ...n }, screen: d };
972
+ }
973
+ const { name: r, screen: o, params: a = {}, options: l = {}, ...f } = e;
974
+ if (typeof r != "string" || !r.trim())
645
975
  throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");
646
- if (p === null || typeof p != "object" || Array.isArray(p))
976
+ if (l === null || typeof l != "object" || Array.isArray(l))
647
977
  throw new TypeError("[react-modal-navigation] open config options must be an object");
648
- if (i !== void 0 && (typeof i != "string" || !i.trim()))
978
+ if (o !== void 0 && (typeof o != "string" || !o.trim()))
649
979
  throw new TypeError("[react-modal-navigation] screen must be a non-empty string");
650
- return { name: t, ...i === void 0 ? {} : { screen: i }, params: g, options: { ...f, ...p } };
980
+ return { name: r, ...o === void 0 ? {} : { screen: o }, params: a, options: { ...f, ...l } };
651
981
  }
652
- function nt() {
982
+ function Qn() {
653
983
  const e = /* @__PURE__ */ new Map();
654
984
  return {
655
- wait(n) {
656
- return new Promise((r) => {
657
- const t = setTimeout(() => {
658
- e.delete(t), r();
659
- }, Math.max(0, n));
660
- e.set(t, r);
985
+ wait(t) {
986
+ return t <= 0 ? Promise.resolve() : new Promise((n) => {
987
+ const r = setTimeout(() => {
988
+ e.delete(r), n();
989
+ }, Math.max(0, t));
990
+ e.set(r, n);
661
991
  });
662
992
  },
663
993
  cancelAll() {
664
- for (const [n, r] of e)
665
- clearTimeout(n), r();
994
+ for (const [t, n] of e)
995
+ clearTimeout(t), n();
666
996
  e.clear();
667
997
  },
668
998
  pendingCount: () => e.size
669
999
  };
670
1000
  }
671
- const tt = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 }, rt = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
672
- function pt({ registry: e, children: n, defaultOptions: r = {}, backgroundColor: t, theme: i, translate: g = rt, onError: p, confirmDiscard: f }) {
673
- et();
674
- const [u, y] = pe(null), [M, k] = pe(null), [d, m] = pe(0), a = l(null), P = l(/* @__PURE__ */ new Map()), N = l([]), D = l(null), L = l(null), G = l(0), x = l(null), B = l(!1), $ = l(0), H = l(null), T = l(/* @__PURE__ */ new Map()), [v, j] = pe(!1), O = l(f);
675
- O.current = f;
676
- const F = w((c, h) => (T.current.set(c, h), () => {
677
- T.current.get(c) === h && T.current.delete(c);
678
- }), []), U = w(async (c) => {
679
- for (const h of T.current.values()) {
680
- if (!h.dirty) continue;
681
- if ((h.onBeforeDiscard ? await h.onBeforeDiscard(c) : O.current ? await O.current(c) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(h.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
682
- }
683
- return !0;
684
- }, []), J = w(async (c, h) => {
685
- for (const A of c) {
686
- const R = T.current.get(A);
687
- if (!R?.dirty) continue;
688
- if ((R.onBeforeDiscard ? await R.onBeforeDiscard(h) : O.current ? await O.current(h) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(R.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
1001
+ const Zn = { placement: "right", showHeader: !0, showBackButton: !0, showCloseButton: !0, viewportGap: 5, borderRadius: 12, closeOnOverlay: !1, closeOnEsc: !0 };
1002
+ function Xn(e, t) {
1003
+ let n = e;
1004
+ const r = sn(), o = /* @__PURE__ */ new Set(), { confirmDiscard: a, onError: l } = n, f = je({ isOpen: !1, activeName: null, isFullscreen: !1, queueSize: 0, error: null }), u = je({ active: null, options: null, exiting: !1, error: null, translate: n.translate });
1005
+ let i = null;
1006
+ const d = (c) => {
1007
+ i = c, Te();
1008
+ };
1009
+ let g = null;
1010
+ const b = (c) => {
1011
+ g = c, Te();
1012
+ };
1013
+ let x = 0;
1014
+ const h = (c) => {
1015
+ x = c, Te();
1016
+ }, s = { current: null }, v = { current: /* @__PURE__ */ new Map() }, I = { current: [] }, z = { current: null }, T = { current: null }, E = { current: 0 }, D = { current: null }, L = { current: !1 }, A = { current: 0 }, q = { current: null }, N = { current: /* @__PURE__ */ new Map() };
1017
+ let Z = !1;
1018
+ const ue = (c) => {
1019
+ Z = c, Te();
1020
+ }, C = { current: a }, F = (c, y) => {
1021
+ const R = N.current.get(c) ?? /* @__PURE__ */ new Set();
1022
+ return N.current.set(c, R), R.add(y), () => {
1023
+ R.delete(y), !R.size && N.current.get(c) === R && N.current.delete(c);
1024
+ };
1025
+ }, $ = async (c, y) => {
1026
+ for (const R of c) for (const w of [...N.current.get(R) ?? []]) {
1027
+ if (!N.current.get(R)?.has(w) || !w.dirty) continue;
1028
+ if ((w.onBeforeDiscard ? await w.onBeforeDiscard(y) : C.current ? await C.current(y) : typeof window < "u" && typeof window.confirm == "function" ? window.confirm(w.message || "有未保存的修改,确定放弃吗?") : !1) === !1) return !1;
689
1029
  }
690
1030
  return !0;
691
- }, []), E = l(!0), _ = l(null);
692
- _.current || (_.current = nt());
693
- const q = l(null), re = l(p);
694
- re.current = p;
695
- const X = w((c, h) => {
696
- E.current && k(c);
1031
+ }, X = (c) => $([...N.current.keys()], c), B = { current: !0 }, te = { current: null };
1032
+ te.current || (te.current = Qn());
1033
+ const V = { current: l }, oe = ((c, y) => {
1034
+ B.current && b(c);
697
1035
  try {
698
- re.current ? re.current(c, h) : console.error("[react-modal-navigation]", c);
699
- } catch (A) {
700
- console.error("[react-modal-navigation] onError failed", A);
1036
+ V.current ? V.current(c, y) : console.error("[react-modal-navigation]", c);
1037
+ } catch (R) {
1038
+ console.error("[react-modal-navigation] onError failed", R);
701
1039
  }
702
- }, []), ge = w((c, h) => {
703
- const A = P.current.get(c);
704
- P.current.delete(c), A?.(h);
705
- }, []), V = w((c) => ({ ...tt, ...r, ...i !== void 0 ? { theme: i } : {}, ...t !== void 0 ? { backgroundColor: t } : {}, ...c.config.modalOptions, ...c.overrides }), [r, i, t]), le = u ? V(u) : null, ye = l(null);
706
- ye.current = le, q.current = le;
707
- const b = w(async (c = "api", h, A = {}) => {
708
- const R = a.current;
709
- if (!R || x.current || B.current) return !1;
710
- x.current = R.id, B.current = !0;
711
- const ee = q.current ?? V(R), Z = { ...A, reason: c, result: h, name: R.name };
1040
+ }), J = ((c, y) => {
1041
+ const R = v.current.get(c);
1042
+ v.current.delete(c);
1043
+ for (const w of R ?? []) w(y);
1044
+ }), O = ((c) => ({ ...Zn, ...n.defaultOptions, ...n.theme !== void 0 ? { theme: n.theme } : {}, ...n.backgroundColor !== void 0 ? { backgroundColor: n.backgroundColor } : {}, ...c.config.modalOptions, ...c.overrides, runtimeLayout: c.runtimeLayout })), G = (async (c = "api", y, R = {}) => {
1045
+ const w = s.current;
1046
+ if (!w || D.current || L.current) return !1;
1047
+ const H = A.current;
1048
+ D.current = w.id, L.current = !0;
1049
+ const W = O(w), ae = { ...R, reason: c, result: y, name: w.name };
712
1050
  try {
713
- if (!await U(Z) || await ee.onBeforeClose?.(Z) === !1 || a.current?.id !== R.id || !E.current) return !1;
714
- j(!0);
715
- const ne = ee.animation === !1 || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? 0 : Math.max(0, Number(ee.animationDuration ?? 220) || 0);
716
- if (await _.current.wait(Math.min(ne, 1e3)), !E.current || a.current?.id !== R.id) return !1;
717
- a.current = null, H.current = null, y(null), j(!1), T.current.clear(), ge(R.id, A.confirmed || h !== void 0 ? { status: "confirmed", value: h, reason: c } : { status: "dismissed", reason: c });
1051
+ if (!await X(ae) || H !== A.current || s.current?.id !== w.id || !await w.runtime.canRemove(w.runtime.stores.navigation.getSnapshot().stack.map((pe) => pe.key), ae) || H !== A.current || s.current?.id !== w.id || await W.onBeforeClose?.(ae) === !1 || H !== A.current || s.current?.id !== w.id || !B.current) return !1;
1052
+ ue(!0);
1053
+ const me = W.animation === !1 || typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? 0 : Math.max(0, Number(W.animationDuration ?? 220) || 0);
1054
+ if (await te.current.wait(Math.min(me, 1e3)), !B.current || s.current?.id !== w.id) return !1;
1055
+ w.runtime.destroy(), s.current = null, q.current = null, Z = !1, d(null), N.current.clear();
1056
+ const ie = R.confirmed || y !== void 0 ? { status: "confirmed", value: y, reason: c } : { status: "dismissed", reason: c };
1057
+ J(w.id, ie), r.emit("close", { id: w.id, name: w.name, result: ie });
718
1058
  try {
719
- await ee.onClose?.(Z);
720
- } catch (te) {
721
- X(te, { phase: "onClose", name: R.name });
1059
+ (R.confirmed || y !== void 0) && await W.onConfirmed?.(y), await W.onClose?.(ae), await W.onClosed?.(ae);
1060
+ } catch (pe) {
1061
+ H === A.current && oe(pe, { phase: "onClose", name: w.name });
722
1062
  }
723
1063
  return !0;
724
- } catch (ne) {
725
- return X(ne, { phase: "onBeforeClose", name: R.name }), !1;
1064
+ } catch (me) {
1065
+ return H === A.current && s.current?.id === w.id && oe(me, { phase: "onBeforeClose", name: w.name }), !1;
726
1066
  } finally {
727
- x.current === R.id && (x.current = null), B.current = !1, !a.current && E.current && queueMicrotask(() => L.current?.());
1067
+ D.current === w.id && (D.current = null), H === A.current && (L.current = !1), !s.current && B.current && queueMicrotask(() => T.current?.());
728
1068
  }
729
- }, [V, X, ge, U]), C = w(async (c, h = {}, A = {}, R, ee) => {
730
- const Z = e?.[c], ne = Z?.component && !Z.screens ? { ...Z, singlePage: !0, initialRoute: "__single__", screens: { __single__: { component: Z.component, title: Z.title, ...Z.screenOptions ?? {} } } } : Z;
731
- if (!ne) throw new Error(`[react-modal-navigation] Unknown modal: ${c}`);
732
- const te = ee ?? ne.initialRoute ?? Object.keys(ne.screens ?? {})[0];
733
- if (!ne.screens?.[te]) throw new Error(`[react-modal-navigation] Unknown initial screen '${te}' in modal '${c}'`);
734
- if (!E.current || B.current || x.current) return null;
735
- B.current = !0;
736
- const Be = $.current;
1069
+ }), ke = (async (c, y = {}, R = {}, w, H) => {
1070
+ if (!B.current || L.current || D.current) return null;
1071
+ L.current = !0;
1072
+ const W = A.current;
737
1073
  try {
738
- const me = a.current;
739
- if (me) {
740
- const qe = q.current ?? V(me), Ee = { reason: "replace", name: me.name, nextName: c };
1074
+ const ae = await an(c, n.registry);
1075
+ if (!B.current || W !== A.current) return null;
1076
+ const me = (he) => he.loader && !he.component ? { ...he, component: t(he.loader) } : he, ie = ae.screens ? { ...ae, screens: Object.fromEntries(Object.entries(ae.screens).map(([he, ze]) => [he, me(ze)])) } : me(ae);
1077
+ c = typeof c == "string" ? c : ae.name ?? "inline";
1078
+ const pe = ie?.component && !ie.screens ? { ...ie, singlePage: !0, initialRoute: "__single__", screens: { __single__: { component: ie.component, title: ie.title, ...ae.screenOptions ?? {} } } } : ie;
1079
+ if (!pe) throw new Error(`[react-modal-navigation] Unknown modal: ${c}`);
1080
+ const Re = H ?? pe.initialRoute ?? Object.keys(pe.screens ?? {})[0];
1081
+ if (!pe.screens || !Object.hasOwn(pe.screens, Re) || !pe.screens[Re]) throw new Error(`[react-modal-navigation] Unknown initial screen '${Re}' in modal '${c}'`);
1082
+ const S = s.current, le = R.instanceKey ?? pe.modalOptions?.instanceKey, Le = R.duplicateStrategy ?? pe.modalOptions?.duplicateStrategy;
1083
+ if (S && le != null && S.instanceKey === le) {
1084
+ if (Le === "ignore") return null;
1085
+ if (Le === "reuse") {
1086
+ if (w) {
1087
+ const he = v.current.get(S.id) ?? [];
1088
+ he.push(w), v.current.set(S.id, he);
1089
+ }
1090
+ return S.id;
1091
+ }
1092
+ }
1093
+ if (S) {
1094
+ const he = O(S), ze = { reason: "replace", name: S.name, nextName: c };
741
1095
  try {
742
- if (!await U(Ee) || await qe.onBeforeClose?.(Ee) === !1) return null;
743
- } catch (Re) {
744
- return X(Re, { phase: "onBeforeClose", name: me.name }), null;
1096
+ if (!await X(ze) || W !== A.current || s.current?.id !== S.id || !await S.runtime.canRemove(S.runtime.stores.navigation.getSnapshot().stack.map((Fe) => Fe.key), ze) || W !== A.current || s.current?.id !== S.id || await he.onBeforeClose?.(ze) === !1) return null;
1097
+ } catch (Fe) {
1098
+ return W === A.current && s.current?.id === S.id && oe(Fe, { phase: "onBeforeClose", name: S.name }), null;
745
1099
  }
746
- if (!E.current || Be !== $.current || a.current?.id !== me.id) return null;
747
- a.current = null, H.current = null, y(null), T.current.clear(), ge(me.id, { status: "replaced", reason: "replace" });
1100
+ if (!B.current || W !== A.current || s.current?.id !== S.id) return null;
1101
+ S.runtime.destroy(), s.current = null, q.current = null, d(null), N.current.clear();
1102
+ const qe = { status: "replaced", reason: "replace" };
1103
+ J(S.id, qe), r.emit("close", { id: S.id, name: S.name, result: qe });
748
1104
  try {
749
- await qe.onClose?.(Ee);
750
- } catch (Re) {
751
- X(Re, { phase: "onClose", name: me.name });
1105
+ await he.onClose?.(ze), await he.onClosed?.(ze);
1106
+ } catch (Fe) {
1107
+ W === A.current && oe(Fe, { phase: "onClose", name: S.name });
752
1108
  }
753
- if (!E.current || Be !== $.current) return null;
1109
+ if (!B.current || W !== A.current) return null;
754
1110
  }
755
- const ve = { id: ++G.current, name: c, screen: te, params: h, config: ne, overrides: A };
756
- return a.current = ve, H.current = null, R && P.current.set(ve.id, R), k(null), y(ve), ve.id;
1111
+ const ye = { id: ++E.current, name: c, screen: Re, params: y, config: pe, overrides: R, instanceKey: le };
1112
+ return ye.runtime = Yn(ye, O(ye)), ye.runtime.bindings = _e(ye.id), s.current = ye, q.current = null, w && v.current.set(ye.id, [w]), g = null, d(ye), r.emit("open", { id: ye.id, name: ye.name }), ye.id;
757
1113
  } finally {
758
- B.current = !1;
1114
+ W === A.current && (L.current = !1), !s.current && B.current && queueMicrotask(() => T.current?.());
759
1115
  }
760
- }, [e, V, X, ge, U]);
761
- D.current = C;
762
- const W = w(async () => {
763
- if (!E.current || a.current || B.current || x.current) return;
764
- const c = N.current.shift();
1116
+ });
1117
+ z.current = ke;
1118
+ const Ce = (async () => {
1119
+ if (!B.current || s.current || L.current || D.current) return;
1120
+ const c = I.current.shift();
765
1121
  if (c) {
766
- m(N.current.length);
1122
+ o.add(c), h(I.current.length);
767
1123
  try {
768
- const h = await D.current(c.args.name, c.args.params, c.args.options, c.resolveResult, c.args.screen);
769
- h === null ? (c.resolveResult?.({ status: "dismissed", reason: "blocked" }), c.resolveId?.(null), queueMicrotask(() => L.current?.())) : c.resolveId?.(h);
770
- } catch (h) {
771
- c.reject?.(h), queueMicrotask(() => L.current?.());
1124
+ const y = await z.current(c.args.name, c.args.params, c.args.options, c.resolveResult, c.args.screen);
1125
+ y === null ? (c.resolveResult?.({ status: "dismissed", reason: "blocked" }), c.resolveId?.(null), queueMicrotask(() => T.current?.())) : c.resolveId?.(y);
1126
+ } catch (y) {
1127
+ c.reject?.(y), queueMicrotask(() => T.current?.());
1128
+ } finally {
1129
+ o.delete(c);
772
1130
  }
773
1131
  }
774
- }, []);
775
- L.current = W;
776
- const ue = w((c, h, A) => {
777
- const R = Ge(c, h, A);
778
- return e?.[R.name] ? new Promise((ee, Z) => {
779
- N.current.push({ args: R, resolveId: ee, reject: Z }), m(N.current.length), queueMicrotask(() => L.current?.());
780
- }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${R.name}`));
781
- }, [e]), he = w((c, h, A) => {
782
- const R = Ge(c, h, A);
783
- return e?.[R.name] ? new Promise((ee, Z) => {
784
- N.current.push({ args: R, resolveResult: ee, reject: Z }), m(N.current.length), queueMicrotask(() => L.current?.());
785
- }) : Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${R.name}`));
786
- }, [e]), we = w((c) => {
1132
+ });
1133
+ T.current = Ce;
1134
+ const K = ((c, y, R) => {
1135
+ if (!B.current) return Promise.resolve(null);
1136
+ const w = nt(c, y, R);
1137
+ return typeof w.name == "string" && !n.registry?.[w.name] ? Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`)) : new Promise((H, W) => {
1138
+ I.current.push({ args: w, resolveId: H, reject: W }), h(I.current.length), queueMicrotask(() => T.current?.());
1139
+ });
1140
+ }), de = ((c, y, R) => {
1141
+ if (!B.current) return Promise.resolve({ status: "dismissed", reason: "unmount" });
1142
+ const w = nt(c, y, R);
1143
+ return typeof w.name == "string" && !n.registry?.[w.name] ? Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`)) : new Promise((H, W) => {
1144
+ I.current.push({ args: w, resolveResult: H, reject: W }), h(I.current.length), queueMicrotask(() => T.current?.());
1145
+ });
1146
+ }), k = ((c) => {
787
1147
  if (!c || typeof c != "object" || Array.isArray(c)) throw new TypeError("[react-modal-navigation] update expects an options object");
788
- const h = a.current;
789
- if (!h || B.current) return !1;
790
- const A = { ...h, overrides: { ...h.overrides, ...c } };
791
- return a.current = A, y(A), q.current = V(A), !0;
792
- }, [V]), Ie = w((c = "queue-cleared") => {
793
- const h = N.current.splice(0);
794
- m(0);
795
- for (const A of h)
796
- A.resolveId?.(null), A.resolveResult?.({ status: "dismissed", reason: c });
797
- return h.length;
798
- }, []), Pe = w((c, h, A) => {
799
- const R = Ge(c, h, A);
800
- return C(R.name, R.params, R.options, void 0, R.screen);
801
- }, [C]), Ye = w((c, h, A) => {
802
- const R = Ge(c, h, A);
803
- return new Promise((ee, Z) => {
804
- C(R.name, R.params, R.options, ee, R.screen).then((ne) => {
805
- ne === null && ee({ status: "dismissed", reason: "blocked" });
806
- }, Z);
1148
+ const y = s.current;
1149
+ return !y || L.current ? !1 : (Object.keys(c).every((R) => Object.is(O(y)[R], c[R])) || (y.overrides = { ...y.overrides, ...c }, y.runtimeLayout = { ...y.runtimeLayout, ...c }, Te()), !0);
1150
+ }), ce = ((c, y) => Wn(c, n.registry, y)), ne = ((c) => k({ fullscreen: !!c })), re = (() => ne(!(s.current && O(s.current).fullscreen))), Be = ((c = "queue-cleared") => {
1151
+ const y = I.current.splice(0);
1152
+ h(0);
1153
+ for (const R of y)
1154
+ R.resolveId?.(null), R.resolveResult?.({ status: "dismissed", reason: c });
1155
+ return y.length;
1156
+ }), st = ((c, y, R) => {
1157
+ const w = nt(c, y, R);
1158
+ return ke(w.name, w.params, w.options, void 0, w.screen);
1159
+ }), We = ((c, y, R) => {
1160
+ const w = nt(c, y, R);
1161
+ return new Promise((H, W) => {
1162
+ ke(w.name, w.params, w.options, H, w.screen).then((ae) => {
1163
+ ae === null && H({ status: "dismissed", reason: "blocked" });
1164
+ }, W);
807
1165
  });
808
- }, [C]), de = w((c) => b("api", c), [b]), Ne = w((c = "api") => b(c), [b]), ke = w((c) => b("confirm", c, { confirmed: !0 }), [b]), Ae = w((c, h) => H.current?.setLoading(c, h), []), Le = K(() => ({ open: Pe, openAsync: Ye, enqueue: ue, enqueueAsync: he, update: we, clearQueue: Ie, close: de, dismiss: Ne, confirm: ke, setLoading: Ae, queueSize: d, isOpen: !!u, activeName: u?.name ?? null, error: M, clearError: () => k(null) }), [Pe, Ye, ue, he, we, Ie, de, Ne, ke, Ae, u, M, d]);
809
- Q(() => (E.current = !0, () => {
810
- E.current = !1, _.current.cancelAll(), $.current += 1, a.current = null;
811
- for (const h of P.current.values()) h({ status: "dismissed", reason: "unmount" });
812
- P.current.clear(), T.current.clear();
813
- const c = N.current.splice(0);
814
- for (const h of c)
815
- h.resolveId?.(null), h.resolveResult?.({ status: "dismissed", reason: "unmount" });
816
- }), []);
817
- const Se = u?.config.singlePage || u && Object.keys(u.config.screens ?? {}).length === 1 ? Jn : Yn;
818
- return /* @__PURE__ */ ce(yn.Provider, { value: Le, children: [
819
- n,
820
- u && /* @__PURE__ */ s(
821
- Se,
822
- {
823
- config: u.config,
824
- initialScreen: u.screen,
825
- params: u.params,
826
- options: le,
827
- translate: g,
828
- notifyError: X,
829
- error: M,
830
- clearError: () => k(null),
831
- registerLoading: (c) => {
832
- H.current = c;
833
- },
834
- registerDirtyGuard: F,
835
- canNavigate: J,
836
- exiting: v,
837
- onRequestClose: b,
838
- onOpened: (c) => {
839
- try {
840
- const h = ye.current?.onOpen?.(c);
841
- Promise.resolve(h).catch((A) => X(A, { phase: "onOpen" }));
842
- } catch (h) {
843
- X(h, { phase: "onOpen" });
844
- }
845
- }
1166
+ }), it = (async (c, y, R) => {
1167
+ const w = nt(c, y, R);
1168
+ let H;
1169
+ const W = new Promise((S) => {
1170
+ H = S;
1171
+ }), ae = await ke(w.name, w.params, w.options, H, w.screen);
1172
+ ae === null && H({ status: "dismissed", reason: "blocked" });
1173
+ const me = () => ae !== null && s.current?.id === ae && s.current.runtime.alive.current, ie = () => me() ? s.current.runtime : null, pe = ie()?.ready.then((S) => S && me()) ?? Promise.resolve(!1), Re = (S, ...le) => ie()?.navigationCommands?.[S]?.(...le) ?? !1;
1174
+ return {
1175
+ id: ae,
1176
+ result: W,
1177
+ isActive: me,
1178
+ replaceOptions: (S) => {
1179
+ if (!me() || L.current) return !1;
1180
+ const le = s.current;
1181
+ return le.overrides = { ...S }, le.runtimeLayout = void 0, Te(), !0;
846
1182
  },
847
- u.id
848
- )
849
- ] });
1183
+ dispose: () => {
1184
+ if (!me()) return !1;
1185
+ const S = s.current;
1186
+ A.current++, te.current.cancelAll(), s.current = null, q.current = null, D.current = null, L.current = !1, Z = !1, N.current.clear(), S.runtime.destroy(), d(null);
1187
+ const le = { status: "dismissed", reason: "unmount" };
1188
+ return J(ae, le), r.emit("close", { id: ae, name: S.name, result: le }), queueMicrotask(() => T.current?.()), !0;
1189
+ },
1190
+ ready: pe,
1191
+ on: (S, le) => ie()?.events.on(S, le) ?? (() => {
1192
+ }),
1193
+ off: (S, le) => ie()?.events.off(S, le),
1194
+ getSnapshot: () => ie()?.getSnapshot() ?? null,
1195
+ subscribeState: (S, le, Le, ye) => ie()?.subscribeState(S, le, Le, ye) ?? (() => {
1196
+ }),
1197
+ getState: () => ie()?.stores.navigation.getSnapshot() ?? null,
1198
+ subscribe: (S) => ie()?.stores.navigation.subscribe(S) ?? (() => {
1199
+ }),
1200
+ clearCache: async (S) => !!await Re("clearCache", S),
1201
+ navigate: async (...S) => !!await Re("navigate", ...S),
1202
+ setParams: (S) => ie()?.navigationCommands ? (Re("setParams", S), !0) : !1,
1203
+ setLoading: (S, le) => ie()?.navigationCommands?.setLoading ? (Re("setLoading", S, le), !0) : !1,
1204
+ setOptions: (S) => me() && k(S),
1205
+ setFullscreen: (S) => me() && k({ fullscreen: !!S }),
1206
+ close: (S) => me() ? G("api", S) : Promise.resolve(!1),
1207
+ confirm: (S) => me() ? G("confirm", S, { confirmed: !0 }) : Promise.resolve(!1)
1208
+ };
1209
+ }), Qe = ((c) => G("api", c)), ct = ((c = "api") => G(c)), Ne = ((c) => G("confirm", c, { confirmed: !0 })), lt = ((c, y) => q.current?.setLoading(c, y)), Ze = () => b(null), Ge = /* @__PURE__ */ new Set(), De = { inspect: (c) => {
1210
+ const y = _n({ hostStore: u, statusStore: f, commands: De }, c), R = y.dispose;
1211
+ return y.dispose = () => {
1212
+ Ge.delete(y), R();
1213
+ }, Ge.add(y), B.current || y.dispose(), y;
1214
+ }, on: r.on, off: r.off, open: st, openInstance: it, openAsync: We, enqueue: K, enqueueAsync: de, update: k, setOptions: k, preload: ce, setFullscreen: ne, toggleFullscreen: re, clearQueue: Be, close: Qe, dismiss: ct, confirm: Ne, setLoading: lt, clearError: Ze }, Ee = (c, y) => Object.keys(c).length === Object.keys(y).length && Object.keys(c).every((R) => Object.is(c[R], y[R]));
1215
+ function Te() {
1216
+ const c = i ? O(i) : null, y = u.getSnapshot();
1217
+ i && !Ee(c, i.runtime.stores.layout.getSnapshot()) && i.runtime.stores.layout.publish(c);
1218
+ const R = i ? y.active === i ? y.options : c : null, w = { isOpen: !!i, activeName: i?.name ?? null, isFullscreen: !!c?.fullscreen, queueSize: x, error: g }, H = { active: i, options: R, exiting: Z, error: g, translate: n.translate }, W = f.getSnapshot();
1219
+ Ee(w, W) || f.publish(w), Ee(H, y) || u.publish(H), W.queueSize !== w.queueSize && r.emit("queueChange", { previous: W.queueSize, current: w.queueSize });
1220
+ }
1221
+ const _e = (c) => ({
1222
+ registerLoading: (y) => {
1223
+ s.current?.id === c && (q.current = y);
1224
+ },
1225
+ registerDirtyGuard: (y, R) => s.current?.id === c ? F(y, R) : () => {
1226
+ },
1227
+ getProtectedCacheKeys: () => s.current?.id === c ? new Set([...N.current].filter(([, y]) => [...y].some((R) => R.dirty)).map(([y]) => y)) : /* @__PURE__ */ new Set(),
1228
+ canNavigate: (y, R) => s.current?.id === c ? $(y, R) : Promise.resolve(!1),
1229
+ onRequestClose: (...y) => s.current?.id === c ? G(...y) : Promise.resolve(!1),
1230
+ onOpened: (y) => {
1231
+ if (s.current?.id !== c) return;
1232
+ const R = O(s.current), w = (H, W) => {
1233
+ s.current?.id === c && oe(H, { phase: W });
1234
+ };
1235
+ for (const H of ["onOpen", "onOpened"])
1236
+ try {
1237
+ Promise.resolve(R[H]?.(y)).catch((W) => w(W, H));
1238
+ } catch (W) {
1239
+ w(W, H);
1240
+ }
1241
+ }
1242
+ });
1243
+ return { commands: De, statusStore: f, hostStore: u, bindInstance: _e, configure: (c) => {
1244
+ n = c, C.current = c.confirmDiscard, V.current = c.onError, Te();
1245
+ }, mount: () => {
1246
+ B.current = !0;
1247
+ }, destroy: () => {
1248
+ B.current = !1;
1249
+ for (const c of Ge) c.dispose();
1250
+ r.clear(), A.current += 1, te.current.cancelAll(), s.current?.runtime.destroy(), s.current = null, q.current = null, D.current = null, L.current = !1;
1251
+ for (const c of v.current.keys()) J(c, { status: "dismissed", reason: "unmount" });
1252
+ v.current.clear(), N.current.clear(), i = null, Z = !1, g = null;
1253
+ for (const c of o)
1254
+ c.resolveId?.(null), c.resolveResult?.({ status: "dismissed", reason: "unmount" });
1255
+ o.clear(), Be("unmount"), Te();
1256
+ }, reportError: oe };
1257
+ }
1258
+ const Jn = Se.memo(function({ Screen: t, route: n, navigation: r }) {
1259
+ return /* @__PURE__ */ p(t, { route: n, navigation: r });
1260
+ }), er = Se.memo(function({ store: t, layoutStore: n, route: r, ...o }) {
1261
+ const a = () => t.getSnapshot()[r.key], l = Oe(t.subscribe, a, a), f = Pe(n, Qt, He);
1262
+ return /* @__PURE__ */ p(en, { ...o, options: f, route: r, override: l });
1263
+ }), tr = Se.memo(function({ store: t, translate: n }) {
1264
+ const r = Oe(t.subscribe, t.getSnapshot, t.getSnapshot);
1265
+ return /* @__PURE__ */ p(tn, { loading: r, translate: n });
1266
+ }), nr = Se.memo(function({ store: t, dismiss: n }) {
1267
+ const r = Oe(t.subscribe, t.getSnapshot, t.getSnapshot);
1268
+ return /* @__PURE__ */ p(nn, { items: r, dismiss: n });
1269
+ });
1270
+ function rr({ runtime: e, config: t, initialScreen: n, params: r, translate: o, onRequestClose: a, onOpened: l, registerLoading: f, notifyError: u, error: i, clearError: d, registerDirtyGuard: g, exiting: b = !1 }) {
1271
+ const x = Pe(e.stores.layout, En, He), h = n ?? t.initialRoute ?? Object.keys(t.screens)[0], [s, v] = xe(() => e.stores.navigation.getSnapshot().currentRoute), I = P(s);
1272
+ I.current = s;
1273
+ const z = t.screens[h], T = e.alive, E = P(null), { navigation: D, footer: L, loading: A, toast: q } = e.refs, N = P("single"), { loadingApi: Z, setLoading: ue } = on(A, T, N, e), { toast: C, dismissToast: F } = rn(q, T, e), $ = _((k, ce) => {
1274
+ const ne = L.current, re = ne.getSnapshot();
1275
+ if (ce === null) {
1276
+ if (re[k] !== void 0) {
1277
+ const Be = { ...re };
1278
+ delete Be[k], ne.publish(Be);
1279
+ }
1280
+ } else re[k] !== ce && ne.publish({ ...re, [k]: ce });
1281
+ }, []), X = _((k = "api", ce) => !T.current || A.current.getSnapshot().visible && e.stores.layout.getSnapshot().lockCloseWhileLoading !== !1 ? Promise.resolve(!1) : a(k, ce), [a, e]), B = _(() => Promise.resolve(!1), []), te = Q(() => ({
1282
+ navigate: B,
1283
+ navigateAsync: async () => ({ status: "cancelled" }),
1284
+ replace: B,
1285
+ reset: B,
1286
+ clearCache: B,
1287
+ goBack: B,
1288
+ push: B,
1289
+ pop: B,
1290
+ popToTop: B,
1291
+ popTo: B,
1292
+ setParams: (k) => T.current ? (v((ce) => ({ ...ce, params: { ...ce.params, ...typeof k == "function" ? k(ce.params) : k } })), !0) : !1,
1293
+ setOptions: (k) => T.current ? (v((ce) => ({ ...ce, options: { ...ce.options, ...k } })), !0) : !1,
1294
+ close: X,
1295
+ setLoading: ue,
1296
+ canGoBack: !1,
1297
+ stack: [s],
1298
+ currentRoute: s
1299
+ }), [X, s, ue, B]), V = P(te);
1300
+ V.current = te;
1301
+ const oe = Q(() => ({
1302
+ clearCache: (...k) => V.current.clearCache(...k),
1303
+ navigate: (...k) => V.current.navigate(...k),
1304
+ navigateAsync: (...k) => V.current.navigateAsync(...k),
1305
+ replace: (...k) => V.current.replace(...k),
1306
+ reset: (...k) => V.current.reset(...k),
1307
+ goBack: (...k) => V.current.goBack(...k),
1308
+ push: (...k) => V.current.push(...k),
1309
+ pop: (...k) => V.current.pop(...k),
1310
+ popToTop: (...k) => V.current.popToTop(...k),
1311
+ popTo: (...k) => V.current.popTo(...k),
1312
+ setParams: (...k) => V.current.setParams(...k),
1313
+ setOptions: (...k) => V.current.setOptions(...k),
1314
+ close: (...k) => V.current.close(...k),
1315
+ setLoading: (...k) => V.current.setLoading(...k)
1316
+ }), []);
1317
+ Ae(() => e.registerNavigation(oe), [e, oe]);
1318
+ const J = Q(() => ({
1319
+ setLoading: (k, ce) => Z.setScreenLoading("single", k, ce),
1320
+ showLoading: (k) => Z.begin("single", k),
1321
+ hideLoading: (k) => Z.end("single", k)
1322
+ }), [Z]), O = Q(() => ({ isFocused: !0, resultEvent: null, routeKey: "single", setFooter: $ }), [$]), G = Q(() => ({ routeKey: "single", registerDirtyGuard: g }), [g]);
1323
+ U(() => {
1324
+ D.current.publish({ canGoBack: !1, stack: [s], currentRoute: s });
1325
+ }, [s]);
1326
+ const ke = P(!1);
1327
+ U(() => (f?.({ setLoading: ue }), ke.current || (ke.current = !0, l?.({ route: I.current, stack: [I.current] })), () => {
1328
+ f?.(null);
1329
+ }), []);
1330
+ const Ce = Q(() => ({ ...z, ...s.options }), [z, s.options]), K = z.component, de = e.refs.header;
1331
+ return /* @__PURE__ */ p(yt.Provider, { value: de.current, children: /* @__PURE__ */ p(Tt.Provider, { value: C, children: /* @__PURE__ */ p(Vt.Provider, { value: q.current, children: /* @__PURE__ */ p(Ut.Provider, { value: L.current, children: /* @__PURE__ */ p(_t.Provider, { value: te, children: /* @__PURE__ */ p(vt.Provider, { value: oe, children: /* @__PURE__ */ p(bt.Provider, { value: D.current, children: /* @__PURE__ */ p(Ue.Provider, { value: Z, children: /* @__PURE__ */ be(Xt, { store: e.stores.layout, screenOptions: Ce.modalOptions, dialogRef: E, requestClose: X, exiting: b, children: [
1332
+ /* @__PURE__ */ p(Jt, { store: e.stores.layout, screen: Ce, route: s, navigation: te, requestClose: X, translate: o, canGoBack: !1 }),
1333
+ /* @__PURE__ */ p("main", { className: "pmn-main", children: /* @__PURE__ */ p(Ve.Provider, { value: s, children: /* @__PURE__ */ p(Pt.Provider, { value: G, children: /* @__PURE__ */ p(ot.Provider, { value: O, children: /* @__PURE__ */ p(Ue.Provider, { value: J, children: /* @__PURE__ */ p(wt.Provider, { value: A.current, children: /* @__PURE__ */ p("div", { className: `pmn-body ${x.bodyClassName ?? ""}`, "data-modal-route-key": "single", tabIndex: -1, children: /* @__PURE__ */ p(Nt, { route: s, onError: u, children: /* @__PURE__ */ p(Wt, { fallback: x.lazyFallback ?? /* @__PURE__ */ p("div", { className: "pmn-lazy-loading", role: "status", "aria-live": "polite", children: "加载中..." }), children: /* @__PURE__ */ p(Jn, { Screen: K, route: s, navigation: te }) }) }) }) }) }) }) }) }) }),
1334
+ /* @__PURE__ */ p(er, { store: L.current, route: s, screen: Ce, layoutStore: e.stores.layout, navigation: te, requestClose: X, translate: o, onError: u, loadingApi: Z }),
1335
+ /* @__PURE__ */ p(tr, { store: A.current, translate: o }),
1336
+ /* @__PURE__ */ p(nr, { store: q.current, dismiss: F }),
1337
+ i && /* @__PURE__ */ be("div", { className: "pmn-error", role: "alert", children: [
1338
+ /* @__PURE__ */ p("span", { children: i.message || String(i) }),
1339
+ /* @__PURE__ */ p("button", { type: "button", onClick: d, children: "×" })
1340
+ ] })
1341
+ ] }) }) }) }) }) }) }) }) });
1342
+ }
1343
+ const or = rt(Hn), ar = rt(rr), sr = rt(function({ manager: t }) {
1344
+ const { active: n, options: r, exiting: o, error: a, translate: l } = Oe(t.hostStore.subscribe, t.hostStore.getSnapshot, t.hostStore.getSnapshot), f = n?.id, u = n?.runtime.bindings, i = Q(() => (g, b) => {
1345
+ n?.runtime.alive.current && t.hostStore.getSnapshot().active?.id === f && t.reportError(g, b);
1346
+ }, [t, n, f]);
1347
+ if (!n) return null;
1348
+ const d = n.config.singlePage || Object.keys(n.config.screens ?? {}).length === 1 ? ar : or;
1349
+ return /* @__PURE__ */ p(at.Provider, { value: n.runtime, children: /* @__PURE__ */ p(d, { runtime: n.runtime, config: n.config, initialScreen: n.screen, params: n.params, options: r, translate: l, notifyError: i, error: a, clearError: t.commands.clearError, exiting: o, ...u }, f) });
1350
+ }), ir = ".pmn-overlay,.pmn-dialog,.pmn-dialog *{box-sizing:border-box}.pmn-overlay{position:fixed;inset:0;z-index:1000;display:flex;overscroll-behavior:none;background:#00000073}.pmn-place-right{justify-content:flex-end;align-items:stretch}.pmn-place-left{justify-content:flex-start;align-items:stretch}.pmn-place-center{justify-content:center;align-items:center}.pmn-place-top{justify-content:center;align-items:flex-start}.pmn-place-bottom{justify-content:center;align-items:flex-end}.pmn-dialog{--pmn-surface:#fff;--pmn-body:#fff;--pmn-text:#0f172a;--pmn-muted:#475569;--pmn-border:#e2e8f0;--pmn-hover:#f1f5f9;--pmn-overlay-card:rgba(255,255,255,.92);color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;width:100%;max-width:min(calc(100vw - var(--pmn-gap)*2),var(--pmn-max-width, var(--pmn-width)));max-height:min(calc(100dvh - var(--pmn-gap)*2),var(--pmn-max-height, 100dvh));height:var(--pmn-height, 100%);overflow:hidden;outline:none;box-shadow:0 25px 50px -12px #00000040;background:var(--pmn-surface);color:var(--pmn-text)}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:calc(100dvh - var(--pmn-gap)*2);max-height:calc(100dvh - var(--pmn-gap)*2)}.pmn-place-center .pmn-dialog{height:var(--pmn-height, auto);min-height:150px}.pmn-place-top .pmn-dialog,.pmn-place-bottom .pmn-dialog{height:var(--pmn-height, auto);min-height:0}.pmn-dialog[data-modal-theme=dark]{--pmn-surface:#334155;--pmn-body:#334155;--pmn-text:#f1f5f9;--pmn-muted:#cbd5e1;--pmn-border:#475569;--pmn-hover:#1e293b;--pmn-overlay-card:rgba(51,65,85,.94);color-scheme:dark}.pmn-main{min-height:0;flex:1;overflow:hidden;display:flex;flex-direction:column;background:transparent}.pmn-body{height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;flex:1}.pmn-body[hidden]{display:none!important}.pmn-header{display:flex;flex-shrink:0;height:64px;align-items:center;gap:12px;padding:0 20px;background:transparent}.pmn-header h2{font-size:18px;font-weight:600;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0}.pmn-header-spacer{flex:1}.pmn-border-bottom{border-bottom:1px solid var(--pmn-border)}.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:#fff}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:#ffffffb8;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:#0f172ab8}.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}.pmn-error-screen{padding:24px;color:var(--pmn-text)}.pmn-error-screen p{color:#dc2626;overflow-wrap:anywhere}@media(max-width:640px){.pmn-overlay.pmn-mobile-fullscreen{padding:0!important}.pmn-mobile-fullscreen .pmn-dialog{max-width:100%;width:100%;height:100dvh;max-height:100dvh;border-radius:0!important}}@media(prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:2s}}@keyframes pmn-fade-in{0%{opacity:0}to{opacity:1}}@keyframes pmn-fade-out{0%{opacity:1}to{opacity:0}}@keyframes pmn-scale-in{0%{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}@keyframes pmn-scale-out{0%{opacity:1;transform:none}to{opacity:0;transform:translateY(10px) scale(.97)}}@keyframes pmn-right-in{0%{transform:translate(105%)}to{transform:none}}@keyframes pmn-right-out{0%{transform:none}to{transform:translate(105%)}}@keyframes pmn-left-in{0%{transform:translate(-105%)}to{transform:none}}@keyframes pmn-left-out{0%{transform:none}to{transform:translate(-105%)}}@keyframes pmn-top-in{0%{transform:translateY(-105%)}to{transform:none}}@keyframes pmn-top-out{0%{transform:none}to{transform:translateY(-105%)}}@keyframes pmn-bottom-in{0%{transform:translateY(105%)}to{transform:none}}@keyframes pmn-bottom-out{0%{transform:none}to{transform:translateY(105%)}}.pmn-entering{animation:pmn-fade-in var(--pmn-animation-duration) ease-out both}.pmn-exiting{animation:pmn-fade-out var(--pmn-animation-duration) ease-in both;pointer-events:none}.pmn-entering .pmn-dialog{animation:pmn-scale-in var(--pmn-animation-duration) cubic-bezier(.2,.8,.2,1) both}.pmn-exiting .pmn-dialog{animation:pmn-scale-out var(--pmn-animation-duration) ease-in both}.pmn-entering.pmn-place-right .pmn-dialog{animation-name:pmn-right-in}.pmn-exiting.pmn-place-right .pmn-dialog{animation-name:pmn-right-out}.pmn-entering.pmn-place-left .pmn-dialog{animation-name:pmn-left-in}.pmn-exiting.pmn-place-left .pmn-dialog{animation-name:pmn-left-out}.pmn-entering.pmn-place-top .pmn-dialog{animation-name:pmn-top-in}.pmn-exiting.pmn-place-top .pmn-dialog{animation-name:pmn-top-out}.pmn-entering.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-in}.pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}.pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}@media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}.pmn-toast-region{position:absolute;top:56px;left:12px;right:12px;z-index:80;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;max-height:calc(100% - 72px);overflow:hidden}.pmn-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:100%;min-width:min(260px,100%);padding:11px 13px;border:1px solid var(--pmn-border);border-radius:9px;background:var(--pmn-surface);color:var(--pmn-text);box-shadow:0 5px 18px #0000001a;font-size:13px;line-height:1.5;overflow-wrap:anywhere}.pmn-toast-symbol{flex:0 0 20px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;font-size:13px;font-weight:700;background:var(--pmn-hover);color:var(--pmn-muted)}.pmn-toast-success .pmn-toast-symbol{background:#dcfce7;color:#15803d}.pmn-toast-error .pmn-toast-symbol{background:#fee2e2;color:#b91c1c}.pmn-toast-warning .pmn-toast-symbol{background:#fef3c7;color:#b45309}.pmn-toast-info .pmn-toast-symbol{background:#dbeafe;color:#1d4ed8}.pmn-toast-message{flex:1;min-width:0;white-space:pre-wrap}.pmn-toast-close{border:0;background:transparent;color:var(--pmn-muted);cursor:pointer;font-size:19px;line-height:18px;padding:0 1px}.pmn-toast-close:hover{color:var(--pmn-text)}.pmn-button-danger{background:#dc2626!important;color:#fff!important;border-color:#dc2626!important}@keyframes pmn-page-forward-in{0%{opacity:.18;transform:translate3d(var(--pmn-page-distance,96px),0,0) scale(.985)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-back-in{0%{opacity:.18;transform:translate3d(calc(-1 * var(--pmn-page-distance,96px)),0,0) scale(.985)}to{opacity:1;transform:translateZ(0)}}.pmn-page-enter{animation-duration:var(--pmn-page-duration,.36s);animation-timing-function:cubic-bezier(.2,.8,.2,1);animation-fill-mode:both;will-change:transform,opacity}.pmn-page-forward{animation-name:pmn-page-forward-in}.pmn-page-back{animation-name:pmn-page-back-in}@media(prefers-reduced-motion:reduce){.pmn-page-enter{animation:none!important;will-change:auto}}.pmn-main{position:relative;isolation:isolate}.pmn-page-exit{animation-duration:var(--pmn-page-duration,.36s);animation-timing-function:cubic-bezier(.22,1,.36,1);animation-fill-mode:forwards}@keyframes pmn-page-forward-out{to{opacity:.45;transform:translate3d(calc(-1 * var(--pmn-page-distance,96px)),0,0) scale(.985)}}@keyframes pmn-page-back-out{to{opacity:.45;transform:translate3d(var(--pmn-page-distance,96px),0,0) scale(.985)}}.pmn-page-exit-forward{animation-name:pmn-page-forward-out}.pmn-page-exit-back{animation-name:pmn-page-back-out}@media(prefers-reduced-motion:reduce){.pmn-page-exit{animation:none!important}}.pmn-main>.pmn-body{position:relative;width:100%;flex:1 0 100%;background:var(--pmn-body)}.pmn-page-forward,.pmn-page-back{z-index:2}@keyframes pmn-page-forward-in{0%{opacity:1;transform:translate3d(100%,0,0)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-back-in{0%{opacity:1;transform:translate3d(-100%,0,0)}to{opacity:1;transform:translateZ(0)}}@keyframes pmn-page-forward-out{to{opacity:1;transform:translate3d(-100%,0,0)}}@keyframes pmn-page-back-out{to{opacity:1;transform:translate3d(100%,0,0)}}.pmn-lazy-loading{display:flex;min-height:80px;align-items:center;justify-content:center;color:var(--pmn-muted);font-size:14px}.pmn-place-top .pmn-dialog{max-height:min(calc(100dvh - var(--pmn-top-offset, var(--pmn-gap)) - var(--pmn-gap)),var(--pmn-max-height,100dvh))}.pmn-dialog.pmn-has-custom-background{isolation:isolate;--pmn-body:transparent}.pmn-custom-background-layer{position:absolute;inset:0;z-index:0;pointer-events:none}.pmn-dialog.pmn-has-custom-background>:not(.pmn-custom-background-layer){position:relative;z-index:1}.pmn-dialog.pmn-has-custom-background .pmn-main>.pmn-body{background:transparent}.pmn-overlay.pmn-fullscreen{padding:0!important;align-items:stretch;justify-content:stretch}.pmn-overlay.pmn-fullscreen .pmn-dialog{width:100%;max-width:100%;height:100%;max-height:100%;border-radius:0!important}.pmn-place-left .pmn-dialog,.pmn-place-right .pmn-dialog{height:100%;max-height:100%}.pmn-place-center .pmn-dialog{max-height:100%}.pmn-dialog{max-width:min(100%,var(--pmn-drag-width,var(--pmn-max-width,var(--pmn-width))));max-height:min(100%,var(--pmn-max-height,100dvh))}.pmn-dialog .pmn-resize-handle{position:absolute;z-index:5;top:0;bottom:0;width:10px;cursor:ew-resize;touch-action:none;-webkit-user-select:none;user-select:none}.pmn-resize-left{right:0}.pmn-resize-right{left:0}.pmn-resize-handle:hover,.pmn-resize-handle:focus-visible{background:var(--pmn-border)}@media(max-width:640px){.pmn-mobile-fullscreen .pmn-resize-handle{display:none}}.pmn-dialog{max-width:min(100%,var(--pmn-max-width,100%),var(--pmn-drag-width,var(--pmn-width)))}.pmn-overlay.pmn-fullscreen .pmn-dialog{max-width:100%}", Kt = "react-modal-navigation-styles", Ot = /* @__PURE__ */ new WeakMap();
1351
+ function cr() {
1352
+ mn(() => {
1353
+ if (typeof document > "u") return;
1354
+ const e = document;
1355
+ let t = Ot.get(e);
1356
+ if (!t) {
1357
+ let n = e.getElementById(Kt);
1358
+ const r = !n;
1359
+ n || (n = e.createElement("style"), n.id = Kt, n.setAttribute("data-react-modal-navigation", ""), n.textContent = ir, e.head.appendChild(n)), t = { element: n, owned: r, count: 0 }, Ot.set(e, t);
1360
+ }
1361
+ return t.count += 1, () => {
1362
+ t.count -= 1, t.count === 0 && (t.owned && t.element.remove(), Ot.delete(e));
1363
+ };
1364
+ }, []);
1365
+ }
1366
+ const lr = Object.freeze({}), ur = (e) => ({ "modal.loading": "加载中...", "modal.processing": "处理中...", "modal.back": "返回", "modal.close": "关闭", "modal.cancel": "取消", "modal.done": "完成" })[e] ?? e;
1367
+ function Tr({ children: e, registry: t, defaultOptions: n = lr, backgroundColor: r, theme: o, translate: a = ur, onError: l, confirmDiscard: f }) {
1368
+ cr();
1369
+ const u = { registry: t, defaultOptions: n, backgroundColor: r, theme: o, translate: a, onError: l, confirmDiscard: f }, [i] = xe(() => Xn(u, Gn));
1370
+ return Ae(() => (i.mount(), i.destroy), [i]), Ae(() => {
1371
+ i.configure(u);
1372
+ }, [i, t, n, r, o, a, l, f]), /* @__PURE__ */ p(Lt.Provider, { value: i.commands, children: /* @__PURE__ */ p(zt.Provider, { value: i.statusStore, children: /* @__PURE__ */ be(Gt.Provider, { value: i.commands, children: [
1373
+ e,
1374
+ /* @__PURE__ */ p(sr, { manager: i })
1375
+ ] }) }) });
850
1376
  }
851
- const ot = Object.freeze({ canGoBack: !1, stack: [], currentRoute: null }), at = () => () => {
852
- }, hn = () => ot;
853
- function ft() {
854
- const e = oe(yn), n = oe(_e), r = oe(We), t = fe(r?.subscribe ?? at, r?.getSnapshot ?? hn, r?.getSnapshot ?? hn);
855
- if (!e) throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");
856
- const i = K(() => {
857
- const g = () => {
858
- if (!n) throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");
859
- return n;
1377
+ const dr = Object.freeze({ canGoBack: !1, stack: [], currentRoute: null }), Ht = () => () => {
1378
+ }, ft = () => dr;
1379
+ function Lr({ subscribe: e = !0 } = {}) {
1380
+ const t = ee(Gt), n = ee(zt), r = Oe(e && n?.subscribe || Ht, e && n?.getSnapshot || ft, e && n?.getSnapshot || ft), o = Q(() => t ? e ? { ...t, ...r } : t : null, [t, r, e]), a = ee(vt), l = ee(bt), f = Oe(e && l?.subscribe || Ht, e && l?.getSnapshot || ft, e && l?.getSnapshot || ft);
1381
+ if (!o) throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");
1382
+ const u = Q(() => {
1383
+ const i = () => {
1384
+ if (!a) throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");
1385
+ return a;
860
1386
  };
861
1387
  return {
862
- navigate: (...p) => g().navigate(...p),
863
- replace: (...p) => g().replace(...p),
864
- reset: (...p) => g().reset(...p),
865
- setParams: (...p) => g().setParams(...p),
866
- setOptions: (...p) => g().setOptions(...p),
867
- goBack: (...p) => g().goBack(...p),
868
- close: (...p) => g().close(...p),
869
- setLoading: (...p) => g().setLoading(...p),
870
- canGoBack: t.canGoBack,
871
- stack: t.stack,
872
- currentRoute: t.currentRoute
1388
+ clearCache: (...d) => i().clearCache(...d),
1389
+ navigateAsync: (...d) => i().navigateAsync(...d),
1390
+ navigate: (...d) => i().navigate(...d),
1391
+ push: (...d) => i().push(...d),
1392
+ pop: (...d) => i().pop(...d),
1393
+ popTo: (...d) => i().popTo(...d),
1394
+ popToTop: (...d) => i().popToTop(...d),
1395
+ replace: (...d) => i().replace(...d),
1396
+ reset: (...d) => i().reset(...d),
1397
+ setParams: (...d) => i().setParams(...d),
1398
+ setOptions: (...d) => i().setOptions(...d),
1399
+ goBack: (...d) => i().goBack(...d),
1400
+ close: (...d) => i().close(...d),
1401
+ setLoading: (...d) => i().setLoading(...d),
1402
+ ...e ? { canGoBack: f.canGoBack, stack: f.stack, currentRoute: f.currentRoute } : {}
873
1403
  };
874
- }, [n, t]);
875
- return K(() => ({ ...e, modal: e, navigation: i }), [e, i]);
1404
+ }, [a, f, e]);
1405
+ return Q(() => ({ ...o, modal: o, navigation: u }), [o, u]);
876
1406
  }
877
- function st() {
878
- const e = oe(_e);
1407
+ function cn() {
1408
+ const e = ee(vt);
879
1409
  if (!e) throw new Error("useModalNavigationCommands requires an active modal screen");
880
1410
  return e;
881
1411
  }
882
- function it() {
883
- const e = oe(We);
884
- if (!e) throw new Error("useModalNavigationState requires an active modal screen");
885
- return fe(e.subscribe, e.getSnapshot, e.getSnapshot);
1412
+ function mr(e, t) {
1413
+ const n = ee(bt);
1414
+ if (!n) throw new Error("useModalNavigationState requires an active modal screen");
1415
+ return Pe(n, e, t);
886
1416
  }
887
- function gt() {
888
- const e = st(), n = it();
889
- return K(() => ({ ...e, ...n }), [e, n]);
1417
+ function zr() {
1418
+ const e = cn(), t = mr();
1419
+ return Q(() => ({ ...e, ...t }), [e, t]);
890
1420
  }
891
- function Ln() {
892
- const e = oe(je);
1421
+ function jt() {
1422
+ const e = ee(ot);
893
1423
  if (!e) throw new Error("useIsFocused must be called inside a modal screen");
894
1424
  return e.isFocused;
895
1425
  }
896
- function ht(e) {
897
- const n = Ln();
898
- Q(() => {
899
- if (n)
1426
+ function Ar(e) {
1427
+ const t = jt();
1428
+ U(() => {
1429
+ if (t)
900
1430
  return e();
901
- }, [n, e]);
902
- }
903
- function bt(e) {
904
- const n = oe(je);
905
- if (!n) throw new Error("useNavigationResult requires an active modal screen");
906
- const r = l(e), t = l(null);
907
- Q(() => {
908
- r.current = e;
909
- }, [e]), Q(() => {
910
- !n.isFocused || !n.resultEvent || t.current !== n.resultEvent.id && (t.current = n.resultEvent.id, r.current(n.resultEvent.data));
911
- }, [n.isFocused, n.resultEvent]);
912
- }
913
- function yt(e = {}) {
914
- const n = oe(je);
915
- if (!n) throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");
916
- const { setFooter: r, routeKey: t } = n, i = l(e);
917
- i.current = e;
918
- const g = K(() => (...T) => i.current.done?.(...T), []), p = K(() => (...T) => (i.current.cancel ?? i.current.cancle)?.(...T), []), f = K(() => (...T) => i.current.renderFooter?.(...T), []), u = typeof e.done == "function", y = typeof (e.cancel ?? e.cancle) == "function", M = typeof e.renderFooter == "function", { showFooter: k, showFooterBorder: d, doneDisabled: m, doneText: a, cancelText: P, loadingText: N, footerClassName: D } = e, L = l({ source: null, normalized: void 0 }), G = Array.isArray(e.actions) ? e.actions : null, x = L.current.source;
919
- G === x || G && x && G.length === x.length && G.every((T, v) => {
920
- const j = x[v];
921
- return [.../* @__PURE__ */ new Set([...Object.keys(T), ...Object.keys(j)])].every((F) => F === "onClick" || Object.is(T[F], j[F]));
922
- }) || (L.current = {
923
- source: G?.map((T) => ({ ...T })) ?? null,
924
- normalized: G?.map((T, v) => ({
925
- ...T,
926
- onClick: (...j) => (i.current.actions?.find((F) => F.key === T.key) ?? i.current.actions?.[v])?.onClick?.(...j)
1431
+ }, [t, e]);
1432
+ }
1433
+ function Nr(e) {
1434
+ const t = ee(ot);
1435
+ if (!t) throw new Error("useNavigationResult requires an active modal screen");
1436
+ const n = P(e), r = P(null);
1437
+ U(() => {
1438
+ n.current = e;
1439
+ }, [e]), U(() => {
1440
+ !t.isFocused || !t.resultEvent || r.current !== t.resultEvent.id && (r.current = t.resultEvent.id, n.current(t.resultEvent.data));
1441
+ }, [t.isFocused, t.resultEvent]);
1442
+ }
1443
+ function jr(e = {}) {
1444
+ const t = ee(ot);
1445
+ if (!t) throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");
1446
+ const { setFooter: n, routeKey: r } = t, o = P(e);
1447
+ o.current = e;
1448
+ const a = Q(() => (...q) => o.current.done?.(...q), []), l = Q(() => (...q) => (o.current.cancel ?? o.current.cancle)?.(...q), []), f = Q(() => (...q) => o.current.renderFooter?.(...q), []), u = typeof e.done == "function", i = typeof (e.cancel ?? e.cancle) == "function", d = typeof e.renderFooter == "function", { showFooter: g, showFooterBorder: b, doneDisabled: x, doneText: h, cancelText: s, loadingText: v, footerClassName: I } = e, z = P({ source: null, normalized: void 0 }), T = Array.isArray(e.actions) ? e.actions : null, E = z.current.source;
1449
+ T === E || T && E && T.length === E.length && T.every((q, N) => {
1450
+ const Z = E[N];
1451
+ return [.../* @__PURE__ */ new Set([...Object.keys(q), ...Object.keys(Z)])].every((C) => C === "onClick" || Object.is(q[C], Z[C]));
1452
+ }) || (z.current = {
1453
+ source: T?.map((q) => ({ ...q })) ?? null,
1454
+ normalized: T?.map((q, N) => ({
1455
+ ...q,
1456
+ onClick: (...Z) => (o.current.actions?.find((C) => C.key === q.key) ?? o.current.actions?.[N])?.onClick?.(...Z)
927
1457
  }))
928
1458
  });
929
- const $ = L.current.normalized, H = K(() => ({
930
- showFooter: k,
931
- showFooterBorder: d,
932
- doneDisabled: m,
933
- doneText: a,
934
- cancelText: P,
935
- loadingText: N,
936
- footerClassName: D,
937
- ...$ !== void 0 ? { actions: $ } : {},
938
- ...u ? { done: g } : {},
939
- ...y ? { cancel: p } : {},
940
- ...M ? { renderFooter: f } : {}
941
- }), [k, d, m, a, P, N, D, $, u, y, M, g, p, f]);
942
- Q(() => {
943
- r(t, H);
944
- }, [t, r, H]), Q(() => () => r(t, null), [t, r]);
945
- }
946
- function ct() {
947
- const e = oe(Me), n = oe(Ue);
948
- if (!e || !n) throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");
949
- const r = fe(n.subscribe, n.getSnapshot, n.getSnapshot);
950
- return K(() => ({ ...e, isLoading: r.visible }), [e, r.visible]);
951
- }
952
- function vt() {
953
- const e = oe(Me);
1459
+ const L = z.current.normalized, A = Q(() => ({
1460
+ showFooter: g,
1461
+ showFooterBorder: b,
1462
+ doneDisabled: x,
1463
+ doneText: h,
1464
+ cancelText: s,
1465
+ loadingText: v,
1466
+ footerClassName: I,
1467
+ ...L !== void 0 ? { actions: L } : {},
1468
+ ...u ? { done: a } : {},
1469
+ ...i ? { cancel: l } : {},
1470
+ ...d ? { renderFooter: f } : {}
1471
+ }), [g, b, x, h, s, v, I, L, u, i, d, a, l, f]);
1472
+ U(() => {
1473
+ n(r, A);
1474
+ }, [r, n, A]), U(() => () => n(r, null), [r, n]);
1475
+ }
1476
+ const pr = (e) => e.visible;
1477
+ function Br() {
1478
+ const e = ee(Ue), t = ee(wt);
1479
+ if (!e || !t) throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");
1480
+ const n = Pe(t, pr);
1481
+ return Q(() => ({ ...e, isLoading: n }), [e, n]);
1482
+ }
1483
+ function fr() {
1484
+ const e = ee(Ue);
954
1485
  if (!e) throw new Error("[react-modal-navigation] useModalLoadingCommands requires an active modal screen");
955
1486
  return e;
956
1487
  }
957
- function xt() {
958
- const e = oe(Ue);
959
- if (!e) throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");
960
- return fe(e.subscribe, e.getSnapshot, e.getSnapshot);
961
- }
962
- function wt() {
963
- const e = ct(), n = Ln(), r = l(!0), t = l(!1), [i, g] = pe(!1), [p, f] = pe(null), u = l(e);
964
- return u.current = e, Q(() => (r.current = !0, () => {
965
- r.current = !1;
966
- }), []), { run: w(async (M, k = {}) => {
967
- if (t.current) return { status: "busy" };
968
- if (typeof M != "function") throw new TypeError("[react-modal-navigation] run requires a function");
969
- t.current = !0, r.current && (g(!0), f(null));
970
- const d = u.current.showLoading(k.loadingText);
1488
+ function qr(e, t) {
1489
+ const n = ee(wt);
1490
+ if (!n) throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");
1491
+ return Pe(n, e, t);
1492
+ }
1493
+ function Fr() {
1494
+ const e = ee(at), t = ee(Ve), n = fr(), r = jt(), o = P(!0), a = P(null), [l, f] = xe(!1), [u, i] = xe(null), d = _((x) => {
1495
+ if (!x || a.current !== x) return !1;
1496
+ a.current = null, x.unregister?.(), o.current && f(!1);
971
1497
  try {
972
- const m = await M();
973
- return r.current && await k.onSuccess?.(m), { status: "success", value: m };
974
- } catch (m) {
975
- if (r.current) {
976
- f(m);
977
- try {
978
- await k.onError?.(m);
979
- } catch (a) {
980
- console.error("[react-modal-navigation] onError failed", a);
981
- }
1498
+ x.controller.abort();
1499
+ } finally {
1500
+ x.release();
1501
+ }
1502
+ return !0;
1503
+ }, []), g = _(() => d(a.current), [d]);
1504
+ return U(() => (o.current = !0, () => {
1505
+ o.current = !1, g();
1506
+ }), [g]), { run: _(async (x, h = {}) => {
1507
+ if (!o.current || e && !e.alive.current) return { status: "cancelled" };
1508
+ if (a.current) return { status: "busy" };
1509
+ if (typeof x != "function") throw new TypeError("[react-modal-navigation] run requires a function");
1510
+ const s = new AbortController();
1511
+ let v, I = !1;
1512
+ const z = { controller: s, release: () => {
1513
+ I || (I = !0, v != null && n.hideLoading(v));
1514
+ } };
1515
+ a.current = z, z.cancel = () => d(z), z.unregister = e?.tasks.register(t?.key, z);
1516
+ const T = () => o.current && a.current === z && !s.signal.aborted;
1517
+ try {
1518
+ if (!T()) return { status: "cancelled" };
1519
+ if (f(!0), i(null), v = n.showLoading(h.loadingText), !T())
1520
+ return v != null && I && n.hideLoading(v), { status: "cancelled" };
1521
+ const E = await x({ signal: s.signal });
1522
+ return T() ? (await h.onSuccess?.(E), T() ? { status: "success", value: E } : { status: "cancelled" }) : { status: "cancelled" };
1523
+ } catch (E) {
1524
+ if (!T()) return { status: "cancelled" };
1525
+ i(E);
1526
+ try {
1527
+ await h.onError?.(E);
1528
+ } catch (D) {
1529
+ console.error("[react-modal-navigation] onError failed", D);
982
1530
  }
983
- if (k.throwOnError) throw m;
984
- return { status: "error", error: m };
1531
+ if (!T()) return { status: "cancelled" };
1532
+ if (h.throwOnError) throw E;
1533
+ return { status: "error", error: E };
985
1534
  } finally {
986
- d != null && u.current.hideLoading(d), t.current = !1, r.current && g(!1);
1535
+ z.unregister?.(), z.release(), a.current === z && (a.current = null, o.current && f(!1));
987
1536
  }
988
- }, []), pending: i, error: p, clearError: () => f(null), isFocused: n };
989
- }
990
- function kt(e, n = {}) {
991
- const r = oe(tn);
992
- if (!r) throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");
993
- const t = l({ dirty: e, ...n });
994
- t.current = { dirty: e, ...n };
995
- const { routeKey: i, registerDirtyGuard: g } = r;
996
- Q(() => g(i, {
1537
+ }, [n, e, t?.key, d]), cancel: g, pending: l, error: u, clearError: () => i(null), isFocused: r };
1538
+ }
1539
+ function hr(e, t = {}) {
1540
+ const n = ee(Pt);
1541
+ if (!n) throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");
1542
+ const r = P({ dirty: e, ...t });
1543
+ r.current = { dirty: e, ...t };
1544
+ const { routeKey: o, registerDirtyGuard: a } = n;
1545
+ U(() => a(o, {
997
1546
  get dirty() {
998
- return !!t.current.dirty;
1547
+ return !!r.current.dirty;
999
1548
  },
1000
1549
  get message() {
1001
- return t.current.message;
1550
+ return r.current.message;
1002
1551
  },
1003
1552
  get onBeforeDiscard() {
1004
- return t.current.onBeforeDiscard;
1553
+ return r.current.onBeforeDiscard;
1005
1554
  }
1006
- }), [i, g]);
1555
+ }), [o, a]);
1007
1556
  }
1008
- const St = () => {
1009
- const e = oe(rn);
1557
+ const $r = () => {
1558
+ const e = ee(Tt);
1010
1559
  if (!e) throw new Error("[react-modal-navigation] useToast requires an active modal");
1011
1560
  return e;
1012
1561
  };
1013
- function lt() {
1014
- const e = oe(on);
1562
+ function gr() {
1563
+ const e = ee(Ve);
1015
1564
  if (!e) throw new Error("[react-modal-navigation] useModalRoute requires a modal screen");
1016
1565
  return e;
1017
1566
  }
1018
- function Et() {
1019
- return lt().params;
1567
+ function yr() {
1568
+ return gr().params;
1569
+ }
1570
+ function Bt() {
1571
+ const e = ee(Lt);
1572
+ if (!e) throw new Error("[react-modal-navigation] ModalProvider required");
1573
+ return e;
1574
+ }
1575
+ const vr = (e) => e;
1576
+ function br(e = vr, t = Object.is) {
1577
+ const n = ee(zt);
1578
+ if (!n) throw new Error("[react-modal-navigation] ModalProvider required");
1579
+ return Pe(n, e, t);
1580
+ }
1581
+ const wr = (e) => e.isFullscreen;
1582
+ function Ir() {
1583
+ const { setFullscreen: e, toggleFullscreen: t } = Bt();
1584
+ return { isFullscreen: br(wr), setFullscreen: e, toggleFullscreen: t };
1585
+ }
1586
+ function Dr(e = {}) {
1587
+ const t = ee(yt), n = ee(Ve);
1588
+ if (!t || !n) throw new Error("[react-modal-navigation] useModalHeader requires a modal screen");
1589
+ const r = P(e);
1590
+ r.current = e, U(() => {
1591
+ t.set(n.key, r.current);
1592
+ }), U(() => () => t.set(n.key, null), [t, n.key]);
1593
+ }
1594
+ function Kr(e, t) {
1595
+ const n = ee(at);
1596
+ if (!n) throw new Error("[react-modal-navigation] useModalLayout requires an active modal");
1597
+ return Pe(n.stores.layout, e, t);
1598
+ }
1599
+ function Hr(e = {}) {
1600
+ const t = ee(at), n = ee(Ve), r = jt(), o = P(e);
1601
+ U(() => {
1602
+ o.current = e;
1603
+ }), U(() => (o.current.onMount?.(), () => o.current.onDestroy?.()), []), U(() => {
1604
+ if (r)
1605
+ return o.current.onFocus?.(), () => o.current.onBlur?.();
1606
+ }, [r]), U(() => t?.registerRemovalGuard(n?.key, (a) => o.current.onBeforeRemove?.(a)), [t, n?.key]);
1607
+ }
1608
+ function Wr({ values: e, initialValues: t, equals: n = Object.is, message: r, onBeforeDiscard: o }) {
1609
+ const [a, l] = xe(() => t), f = !n(a, e);
1610
+ hr(f, { message: r, onBeforeDiscard: o });
1611
+ const u = _((i = e) => l(() => i), [e]);
1612
+ return { dirty: f, markSaved: u };
1613
+ }
1614
+ const kr = (e, t) => e && t && Object.keys(e).length === Object.keys(t).length && Object.keys(e).every((n) => Object.hasOwn(t, n) && Object.is(e[n], t[n]));
1615
+ function xr(e, t) {
1616
+ let n, r, o, a = !1, l = !1, f = !1, u = 0, i = -1;
1617
+ const d = (h) => {
1618
+ try {
1619
+ a && n?.onError ? Promise.resolve(n.onError(h)).catch((s) => console.error(s)) : console.error(h);
1620
+ } catch (s) {
1621
+ console.error(s);
1622
+ }
1623
+ }, g = (h, ...s) => {
1624
+ if (a)
1625
+ try {
1626
+ Promise.resolve(n[h]?.(...s)).catch(d);
1627
+ } catch (v) {
1628
+ d(v);
1629
+ }
1630
+ }, b = () => {
1631
+ f = !0, l || x();
1632
+ };
1633
+ async function x() {
1634
+ l = !0;
1635
+ try {
1636
+ for (; f; ) {
1637
+ if (f = !1, !a) {
1638
+ r?.dispose();
1639
+ continue;
1640
+ }
1641
+ const h = n;
1642
+ if (!h) continue;
1643
+ const s = u;
1644
+ if (!h.open) {
1645
+ r?.isActive() && i !== s && (i = s, !await r.close() && u === s && g("onBlocked", "close"));
1646
+ continue;
1647
+ }
1648
+ if (!r?.isActive()) {
1649
+ if (i === s) continue;
1650
+ i = s;
1651
+ const v = await e.openInstance(
1652
+ { component: t, title: h.title },
1653
+ { children: h.children, title: h.title },
1654
+ h.options
1655
+ );
1656
+ if (r = v, o = h, !v.isActive()) {
1657
+ u === s && g("onBlocked", "open");
1658
+ continue;
1659
+ }
1660
+ if (v.result.then((I) => {
1661
+ r === v && (r = null, o = null, n.open && u === i && g("onOpenChange", !1, I), b());
1662
+ }).catch(d), !a) {
1663
+ v.dispose();
1664
+ continue;
1665
+ }
1666
+ if (!n.open) {
1667
+ f = !0;
1668
+ continue;
1669
+ }
1670
+ if (!await v.ready || !v.isActive()) continue;
1671
+ f = !0;
1672
+ continue;
1673
+ }
1674
+ i = s, !(!kr(o?.options, h.options) && !r.replaceOptions(h.options)) && ((!o || !Object.is(o.children, h.children) || !Object.is(o.title, h.title)) && !r.setParams({ children: h.children, title: h.title }) || (o = h));
1675
+ }
1676
+ } catch (h) {
1677
+ d(h);
1678
+ } finally {
1679
+ l = !1, f && b();
1680
+ }
1681
+ }
1682
+ return {
1683
+ mount() {
1684
+ a = !0;
1685
+ },
1686
+ update(h) {
1687
+ (!n || n.open !== h.open) && u++, n = h, b();
1688
+ },
1689
+ unmount() {
1690
+ a = !1, queueMicrotask(() => {
1691
+ a || (r?.dispose(), b());
1692
+ });
1693
+ }
1694
+ };
1695
+ }
1696
+ function Sr() {
1697
+ const { children: e, title: t } = yr(), n = cn();
1698
+ return Ae(() => {
1699
+ n.setOptions({ title: t });
1700
+ }, [n, t]), e;
1701
+ }
1702
+ function Gr({ open: e, onOpenChange: t, onBlocked: n, onError: r, children: o, title: a, ...l }) {
1703
+ const f = Bt(), u = Q(() => xr(f, Sr), [f]);
1704
+ return U(() => (u.mount(), u.unmount), [u]), U(() => {
1705
+ u.update({
1706
+ open: e,
1707
+ onOpenChange: t,
1708
+ onBlocked: n,
1709
+ onError: r,
1710
+ children: o,
1711
+ title: a,
1712
+ options: { ...l, instanceKey: void 0, duplicateStrategy: "allow" }
1713
+ });
1714
+ }), null;
1715
+ }
1716
+ function Cr({ inspector: e }) {
1717
+ const { active: t, queueSize: n, events: r } = Oe(e.subscribe, e.getSnapshot, e.getSnapshot);
1718
+ return /* @__PURE__ */ be("details", { style: { font: "12px monospace", padding: 12, border: "1px solid #888", borderRadius: 8 }, children: [
1719
+ /* @__PURE__ */ be("summary", { children: [
1720
+ "Modal DevTools · ",
1721
+ t?.name ?? "Idle"
1722
+ ] }),
1723
+ /* @__PURE__ */ be("p", { children: [
1724
+ "Queue: ",
1725
+ n,
1726
+ " · Loading: ",
1727
+ t?.loadingCount ?? 0,
1728
+ " · Tasks: ",
1729
+ t?.taskCount ?? 0
1730
+ ] }),
1731
+ /* @__PURE__ */ p("button", { type: "button", onClick: e.refresh, children: "Refresh" }),
1732
+ " ",
1733
+ /* @__PURE__ */ p("button", { type: "button", onClick: e.clear, children: "Clear events" }),
1734
+ /* @__PURE__ */ p("ol", { children: t?.routes.map((o) => /* @__PURE__ */ be("li", { children: [
1735
+ o.name,
1736
+ o.key === t.focusedKey ? " (focused)" : ""
1737
+ ] }, o.key)) }),
1738
+ /* @__PURE__ */ p("ol", { style: { maxHeight: 240, overflow: "auto" }, children: r.map((o) => /* @__PURE__ */ be("li", { children: [
1739
+ o.sequence,
1740
+ " · ",
1741
+ o.type,
1742
+ " ",
1743
+ o.id ?? ""
1744
+ ] }, o.sequence)) })
1745
+ ] });
1746
+ }
1747
+ function _r({ enabled: e = !1, limit: t = 100 }) {
1748
+ const n = Bt(), [r, o] = xe(null);
1749
+ return U(() => {
1750
+ if (!e) {
1751
+ o(null);
1752
+ return;
1753
+ }
1754
+ const a = n.inspect({ limit: t });
1755
+ return o(a), a.dispose;
1756
+ }, [n, e, t]), e && r ? /* @__PURE__ */ p(Cr, { inspector: r }) : null;
1020
1757
  }
1021
1758
  export {
1022
- Yn as ModalNavigator,
1023
- pt as ModalProvider,
1024
- ht as useFocusEffect,
1025
- Ln as useIsFocused,
1026
- ft as useModal,
1027
- yt as useModalFooter,
1028
- ct as useModalLoading,
1029
- vt as useModalLoadingCommands,
1030
- xt as useModalLoadingState,
1031
- gt as useModalNavigation,
1032
- st as useModalNavigationCommands,
1033
- it as useModalNavigationState,
1034
- Et as useModalParams,
1035
- lt as useModalRoute,
1036
- wt as useModalTask,
1037
- kt as useModalUnsavedChanges,
1038
- bt as useNavigationResult,
1039
- St as useToast
1759
+ Gr as Modal,
1760
+ _r as ModalDevTools,
1761
+ Hn as ModalNavigator,
1762
+ Tr as ModalProvider,
1763
+ Or as defineModal,
1764
+ Pr as lazyModal,
1765
+ He as shallowEqual,
1766
+ Ar as useFocusEffect,
1767
+ jt as useIsFocused,
1768
+ Lr as useModal,
1769
+ Bt as useModalCommands,
1770
+ jr as useModalFooter,
1771
+ Wr as useModalFormGuard,
1772
+ Ir as useModalFullscreen,
1773
+ Dr as useModalHeader,
1774
+ Kr as useModalLayout,
1775
+ Hr as useModalLifecycle,
1776
+ Br as useModalLoading,
1777
+ fr as useModalLoadingCommands,
1778
+ qr as useModalLoadingState,
1779
+ zr as useModalNavigation,
1780
+ cn as useModalNavigationCommands,
1781
+ mr as useModalNavigationState,
1782
+ yr as useModalParams,
1783
+ gr as useModalRoute,
1784
+ br as useModalStatus,
1785
+ Fr as useModalTask,
1786
+ hr as useModalUnsavedChanges,
1787
+ Nr as useNavigationResult,
1788
+ $r as useToast
1040
1789
  };