react-modal-navigation 1.1.7 → 1.1.9

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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 1.1.9 — Balanced performance and layout maintenance
2
+
3
+ - Bump package version to 1.1.9 without changing the public API.
4
+ - Constrain top-positioned dialog height by its `top` offset and viewport gap, including responsive CSS lengths.
5
+ - Hoist immutable size presets and length conversion out of the dialog render path.
6
+ - Retain isolated stores, lazy screen boundaries, single-page rendering, and existing lifecycle guards; avoid unnecessary architectural churn.
7
+ - Add regression coverage for package metadata and top positioning.
8
+ - No measured browser speedup is claimed until a production browser benchmark is run.
9
+
10
+ ## v1.1.6 — Single-page lightweight mode
11
+
12
+ - Add automatic single-page rendering with a dedicated `SingleModalNavigator`.
13
+ - Preserve modal open/close, Footer, Loading, Toast, Header, guards and modal styling.
14
+ - Accept `{component, title, modalOptions}` registry entries and legacy one-screen registry.
15
+ - Keep multi-screen navigation unchanged.
16
+
17
+ ## 1.1.6 — stronger page transitions
18
+ - Increase default page slide from 22px/240ms to 96px/360ms.
19
+ - Add configurable `pageAnimationDistance` with matching CSS and Web Animations behavior.
20
+
1
21
  ## 1.1.6 — Architecture maintenance
2
22
 
3
23
  - Extracted Loading and Toast controllers from ModalNavigator.
@@ -78,3 +98,13 @@
78
98
  - No Context API redesign in this change; performance refactors await measured results.
79
99
 
80
100
  - Fix: Default Header back button now follows the current render stack depth; per-screen `showBackButton` is respected.
101
+
102
+ ### Page navigation animation (1.1.6 compatibility update)
103
+ - Added opt-out internal route slide/fade transitions, reverse direction on back navigation.
104
+ - Added `pageAnimation` and `pageAnimationDuration` modal options.
105
+ - Respects reduced-motion preferences and avoids retriggering on unrelated updates.
106
+
107
+ ### Full-width page transition correction
108
+ - Incoming page now animates above outgoing snapshot to prevent visual occlusion.
109
+ - Both pages travel 100% of the content width during push/pop.
110
+ - Preserves navigation APIs and respects reduced-motion preference.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ > 当前版本:**1.1.9**。单页面轻量模式、React.lazy、`placement: "top"` 和 `top` 偏移继续支持。顶部偏移现在会同时约束弹窗的可用高度,避免超出视口。
2
+
1
3
  # react-modal-navigation
2
4
 
3
5
  React 19 多页面弹窗导航组件库。支持 **Modal / Drawer / Sheet**、页面堆栈、KeepAlive、Promise 返回结果、异步关闭守卫、Footer、Loading、暗黑主题与自动注入样式。
@@ -714,3 +716,68 @@ function LoadingIndicator() {
714
716
  ### 返回按钮显示规则(1.1.6 修复)
715
717
 
716
718
  默认 Header 在导航栈超过一页时自动显示返回按钮。使用 `navigation.navigate('Detail')` 推入页面;`replace` / `reset` 不增加可返回的历史。可通过 `showBackButton: false` 隐藏,页面 `setOptions({ showBackButton: true })` 可覆盖默认设置。如果使用 `renderHeader` 自定义整个 Header,需要自行渲染返回按钮。
719
+
720
+ ## 页面跳转动画
721
+
722
+ `navigation.navigate()` 进入新页面时默认从右侧轻滑入,`navigation.goBack()` 返回时从左侧轻滑入,动画时长默认为 **240ms**。仅页面路由发生变化时触发,修改参数、Toast 或 Footer 不会重复触发。系统启用减少动态效果时会自动关闭动画。
723
+
724
+ ```jsx
725
+ const registry = {
726
+ device: {
727
+ initialRoute: 'List',
728
+ modalOptions: { pageAnimation: true, pageAnimationDuration: 260 },
729
+ screens: { List: { component: List }, Detail: { component: Detail } },
730
+ },
731
+ };
732
+
733
+ // 页面内
734
+ navigation.navigate('Detail', { id: 1 });
735
+ navigation.goBack();
736
+ ```
737
+
738
+ 不需要动画时传入 `pageAnimation: false`。`animation: false` 同时禁用弹窗和页面动画。
739
+
740
+
741
+ ### 更明显的页面滑动效果
742
+
743
+ 默认页面滑动距离由 22px 提高到 96px,动画时长由 240ms 提高到 360ms,并增加淡入和轻微缩放。可通过以下选项调整:
744
+
745
+ ```jsx
746
+ modalOptions: {
747
+ pageAnimation: true,
748
+ pageAnimationDuration: 420,
749
+ pageAnimationDistance: 140,
750
+ }
751
+ ```
752
+
753
+ `pageAnimationDistance` 范围为 0–300px;`pageAnimationDuration` 范围为 0–1000ms。系统启用减少动态效果时仍尊重该设置。
754
+
755
+ ### Full-width page transitions
756
+
757
+ `navigation.navigate()` and `navigation.goBack()` now slide both incoming and outgoing content pages in opposite directions across the full content width. Header and Footer stay fixed. Configure `pageAnimationDuration` (default 360ms) and disable via `pageAnimation: false`. Motion is suppressed when the user prefers reduced motion.
758
+
759
+
760
+ ## 单页面弹窗(自动轻量模式)
761
+
762
+ 注册单个页面时,无需定义路由栈;继续使用同一个 `ModalProvider`、`modal.open()`、`modal.openAsync()`、Footer、Toast、Loading、关闭守卫和弹窗样式。
763
+
764
+ ```jsx
765
+ import { lazy } from 'react';
766
+ const AddDevice = lazy(() => import('./AddDevice'));
767
+
768
+ export const registry = {
769
+ addDevice: {
770
+ component: AddDevice,
771
+ title: '添加设备',
772
+ modalOptions: { placement: 'center', width: 480 },
773
+ },
774
+ };
775
+
776
+ // 与多页面弹窗完全一致
777
+ const result = await modal.openAsync('addDevice');
778
+ if (result.status === 'confirmed') await refreshDevices();
779
+ ```
780
+
781
+ 旧版 `screens: { AddDevice: { component: AddDevice } }` 只有一个页面时也自动进入轻量模式。两个及以上页面继续使用完整路由导航。单页面模式不会创建导航 reducer、页面缓存或页面切换动画;`navigation.navigate()`、`goBack()` 等路由操作返回 `false`,`navigateAsync()` 返回 `{status:'cancelled'}`。仍可调用 `navigation.setParams()`、`navigation.setOptions()`、`navigation.close()`。
782
+
783
+ 单页表单建议使用 `modal.confirm({success:true})` 结束 `openAsync`;取消则使用 `modal.dismiss()`。
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("react"),rt=require("react-dom"),We=e.createContext(null),ot=e.createContext(null),Me=e.createContext(null),je=e.createContext(null),Ye=e.createContext(null),_e=e.createContext(null),Fe=e.createContext(null),Oe=e.createContext(null),De=e.createContext(null),at=e.createContext(null),st=e.createContext(null),Ve=e.createContext(null);function ct(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(n!==r){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}function Pe(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(!Object.is(n,r)){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}let it=0;const qe=(t,n)=>({key:`modal-route-${++it}`,name:t,params:n??{}}),Qe=(t,n)=>[qe(t,n)];function Ee(t,n){switch(n.type){case"RESET":return Qe(n.name,n.params);case"NAVIGATE":{const o=t.findIndex(r=>r.name===n.name);return o<0?[...t,qe(n.name,n.params)]:t.slice(0,o+1).map((r,i)=>i===o?{...r,params:n.params??{}}:r)}case"SET_OPTIONS":return t.map((o,r)=>r===t.length-1?{...o,options:{...o.options??{},...n.options??{}}}:o);case"SET_PARAMS":return t.map((o,r)=>r===t.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return t.length>1?t.slice(0,-1):t;case"REPLACE":return t.length?[...t.slice(0,-1),qe(n.name,n.params)]:t;default:return t}}function ut(t,n,o=1/0){const r=o===1/0?1/0:Math.max(0,Math.floor(Number(o)||0)),i=t.slice(0,-1).filter(d=>n[d.name]?.keepAlive!==!1),g=new Set((r===0?[]:i.slice(-r)).map(d=>d.key));return t.filter((d,m)=>m===t.length-1||g.has(d.key))}const Ke=()=>{if(typeof document>"u")return"light";const t=document.documentElement,n=document.body;return t.classList.contains("dark")||n.classList.contains("dark")||t.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":t.classList.contains("light")||n.classList.contains("light")||t.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let ve=0;const ue=[];let Be=null;function lt(){if(ve++,ve===1){const n=document.documentElement,o=document.body,r={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},i=Math.max(0,window.innerWidth-n.clientWidth),g=parseFloat(getComputedStyle(o).paddingRight)||0;i&&(o.style.paddingRight=`${g+i}px`),o.style.setProperty("--modal-scrollbar-width",`${i}px`),n.style.overflow="hidden",o.style.overflow="hidden",Be=()=>{n.style.overflow=r.html,o.style.overflow=r.body,o.style.paddingRight=r.padding,r.width?o.style.setProperty("--modal-scrollbar-width",r.width):o.style.removeProperty("--modal-scrollbar-width")}}let t=!1;return()=>{t||(t=!0,ve=Math.max(0,ve-1),ve||(Be?.(),Be=null))}}const dt='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',mt=t=>!t.closest('[inert], [hidden], [aria-hidden="true"]')&&t.getClientRects().length>0&&getComputedStyle(t).visibility!=="hidden"&&getComputedStyle(t).display!=="none";function ft({dialogRef:t,options:n,requestClose:o,children:r,exiting:i=!1}){const g=e.useRef(null),d=e.useRef(null),m=e.useRef(o);m.current=o;const f=e.useRef(n.closeOnEsc);f.current=n.closeOnEsc;const[x,R]=e.useState(Ke),y=n.theme==="light"||n.theme==="dark"?n.theme:x;e.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const b=()=>R(Ke()),M=new MutationObserver(b);for(const F of[document.documentElement,document.body])M.observe(F,{attributes:!0,attributeFilter:["class","data-theme"]});const q=window.matchMedia?.("(prefers-color-scheme: dark)");return q?.addEventListener?.("change",b),b(),()=>{M.disconnect(),q?.removeEventListener?.("change",b)}},[n.theme]),e.useEffect(()=>{d.current=document.activeElement;const b=lt(),M=g.current;ue.push(M),t.current?.focus({preventScroll:!0});const q=j=>{const W=t.current;if(!W||ue.at(-1)!==M)return;if(j.key==="Escape"&&f.current!==!1){j.preventDefault(),m.current("escape");return}if(j.key!=="Tab")return;const N=[...W.querySelectorAll(dt)].filter(mt);if(!N.length){j.preventDefault(),W.focus();return}const Q=N[0],J=N.at(-1);W.contains(document.activeElement)?j.shiftKey&&(document.activeElement===Q||document.activeElement===W)?(j.preventDefault(),J.focus()):!j.shiftKey&&(document.activeElement===J||document.activeElement===W)&&(j.preventDefault(),Q.focus()):(j.preventDefault(),(j.shiftKey?J:Q).focus())},F=j=>{ue.at(-1)===M&&t.current&&!t.current.contains(j.target)&&t.current.focus({preventScroll:!0})};return document.addEventListener("keydown",q),document.addEventListener("focusin",F),()=>{document.removeEventListener("keydown",q),document.removeEventListener("focusin",F);const j=ue.at(-1)===M,W=ue.indexOf(M);if(W!==-1&&ue.splice(W,1),b(),j){const N=d.current;N?.isConnected&&!N.closest("[inert], [hidden]")?N.focus?.({preventScroll:!0}):ue.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[t]);const h=n.backgroundColor??n.backgroudColor,l=typeof h=="string"?h:h?.[y],c=typeof l=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(l.trim())?l:null,L={sm:400,md:560,lg:720,xl:960,full:"100%"},E=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",P=b=>typeof b=="number"?`${b}px`:b,B=P(n.width??L[n.size]??460),I=P(n.height),k=P(n.maxHeight),$=P(n.maxWidth),K=Number(n.viewportGap??5),G=Number.isFinite(K)?Math.max(0,K):5,S=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return rt.createPortal(u.jsx("div",{ref:g,className:`pmn-overlay ${i?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${E} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:G,"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:b=>{b.target===b.currentTarget&&n.closeOnOverlay===!0&&m.current("overlay")},children:u.jsx("section",{ref:t,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":y,className:`pmn-dialog ${y==="dark"?"dark":""} ${!c&&l?l:""} ${n.className??""}`,style:{"--pmn-width":B,"--pmn-gap":`${G}px`,...I!==void 0?{"--pmn-height":I}:{},...k!==void 0?{"--pmn-max-height":k}:{},...$!==void 0?{"--pmn-max-width":$}:{},borderRadius:S,...c?{backgroundColor:c}:{}},children:r})}),document.body)}function Ge({back:t}){return u.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t?u.jsx("path",{d:"m15 18-6-6 6-6"}):u.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function pt({options:t,screen:n,route:o,navigation:r,requestClose:i,translate:g,canGoBack:d}){if(t.showHeader===!1)return null;const m=g??(l=>l),f=n.showTitle??t.showTitle??!0,x=typeof n.title=="function"?n.title({t:m,route:o,navigation:r}):n.title??o.name,R={route:o,navigation:r,close:i,canGoBack:d,title:x,t:m},y=n.renderHeader??t.renderHeader;if(y)return y(R);const h=n.renderHeaderRight??t.renderHeaderRight;return u.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??t.showHeaderBorder?"pmn-border-bottom":""} ${t.headerClassName??""}`,children:[(n.showBackButton??t.showBackButton)!==!1&&d&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":m("modal.back"),onClick:()=>r.goBack(),children:u.jsx(Ge,{back:!0})}),f?u.jsx("h2",{children:x}):u.jsx("div",{className:"pmn-header-spacer"}),h?.(R),t.showCloseButton!==!1&&u.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":m("modal.close"),onClick:()=>i("header"),children:u.jsx(Ge,{})})]})}function gt({screen:t,options:n,override:o,route:r,navigation:i,requestClose:g,translate:d,onError:m,loadingApi:f}){const[x,R]=e.useState(null),y=e.useRef(new Set),h=e.useRef(!0);e.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const l=d??(b=>b),c={...n,...t,...o},{showFooter:L,renderFooter:E,done:P,cancel:B,cancle:I}=c,k=B??I,$={route:r,navigation:i,close:g,t:l};if(L===!1)return null;const K=`pmn-footer ${c.showFooterBorder?"pmn-border-top":""} ${c.footerClassName??""}`;if(typeof E=="function")return u.jsx("footer",{className:K,children:E({...$,pending:y.current.size>0})});const G=Array.isArray(c.actions)?c.actions:null;if(!G&&typeof P!="function"&&typeof k!="function")return null;const S=async(b,M,q)=>{if(y.current.has(b)||typeof M!="function")return;y.current.add(b),R(b);const F=f?.begin(r.key,q??c.loadingText??l("modal.processing"));try{await M($)}catch(j){m?.(j,{phase:"footer",action:b,route:r})}finally{f?.end(r.key,F),y.current.delete(b),h.current&&R(j=>j===b?null:j)}};return G?u.jsx("footer",{className:K,children:G.filter(b=>!b.hidden).map(b=>{const M=y.current.has(b.key)||b.loading===!0;return u.jsx("button",{type:"button",disabled:b.disabled===!0||M,className:`pmn-button ${b.variant==="primary"||b.variant==="danger"?"pmn-button-primary":"pmn-button-secondary"} ${b.variant==="danger"?"pmn-button-danger":""}`,onClick:()=>S(b.key,b.onClick,b.loadingText),children:M?b.loadingText??c.loadingText??l("modal.processing"):b.label},b.key)})}):u.jsxs("footer",{className:K,children:[typeof k=="function"&&u.jsx("button",{type:"button",disabled:x!==null,onClick:()=>S("cancel",k),className:"pmn-button pmn-button-secondary",children:c.cancelText??l("modal.cancel")}),typeof P=="function"&&u.jsx("button",{type:"button",disabled:x!==null||c.doneDisabled===!0,onClick:()=>S("done",P),className:"pmn-button pmn-button-primary",children:x==="done"?c.loadingText??l("modal.processing"):c.doneText??l("modal.done")})]})}function ht({loading:t,translate:n}){if(!t.visible)return null;const r=(n??(g=>g))("modal.loading"),i=t.text??(r==="modal.loading"?"加载中...":r);return u.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:u.jsxs("div",{className:"pmn-loading-content",children:[u.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),i&&u.jsx("span",{className:"pmn-loading-text",children:i})]})})}class bt extends e.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,o){this.props.onError?.(n,{phase:"render",route:this.props.route,componentStack:o.componentStack})}componentDidUpdate(n){n.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?u.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[u.jsx("strong",{children:"页面加载失败"}),u.jsx("p",{children:this.state.error.message}),u.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}const xt={success:"✓",error:"×",warning:"!",info:"i"};function yt({items:t,dismiss:n}){return t.length?u.jsx("div",{className:"pmn-toast-region","aria-label":"Notifications",children:t.map(o=>u.jsxs("div",{className:`pmn-toast pmn-toast-${o.type}`,role:o.type==="error"||o.type==="warning"?"alert":"status",children:[u.jsx("span",{className:"pmn-toast-symbol","aria-hidden":"true",children:xt[o.type]}),u.jsx("span",{className:"pmn-toast-message",children:o.message}),o.dismissible&&u.jsx("button",{type:"button",className:"pmn-toast-close","aria-label":"Dismiss notification",onClick:()=>n(o.id),children:"×"})]},o.id))}):null}function vt(t,n){const o=e.useRef(0),r=e.useRef(new Map),i=e.useCallback(m=>{clearTimeout(r.current.get(m)),r.current.delete(m),n.current&&t.current.publish(t.current.getSnapshot().filter(f=>f.id!==m))},[]),g=e.useCallback((m,f={})=>{if(typeof m!="string"||!m.trim())throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");const x=typeof f=="string"?{type:f}:f??{},R=["success","error","warning","info"].includes(x.type)?x.type:"info",y=++o.current,h=Number.isFinite(x.duration)?Math.max(0,x.duration):3e3;if(!n.current)return null;const l=t.current.getSnapshot(),c=l.slice(0,Math.max(0,l.length-4));for(const L of c)clearTimeout(r.current.get(L.id)),r.current.delete(L.id);return t.current.publish([...l.slice(-4),{id:y,message:m,type:R,dismissible:x.dismissible!==!1}]),h>0&&r.current.set(y,setTimeout(()=>i(y),h)),y},[i]),d=e.useMemo(()=>{const m=(f,x)=>g(f,x);for(const f of["success","error","warning","info"])m[f]=(x,R={})=>g(x,{...R,type:f});return m.promise=async(f,x,R={})=>{const y=g(x.loading,{...R,type:"info",duration:0});try{const h=await(typeof f=="function"?f():f);y!=null&&i(y);const l=typeof x.success=="function"?x.success(h):x.success;return l&&g(l,{...R,type:"success"}),h}catch(h){y!=null&&i(y);const l=typeof x.error=="function"?x.error(h):x.error;throw l&&g(l,{...R,type:"error"}),h}},m.dismiss=i,m.clear=()=>{for(const f of r.current.values())clearTimeout(f);r.current.clear(),t.current.publish([])},m},[g,i]);return e.useEffect(()=>()=>{for(const m of r.current.values())clearTimeout(m);r.current.clear()},[]),{toast:d,dismissToast:i}}function wt(t,n,o){const r=e.useRef(new Map),i=e.useRef(0),g=e.useCallback(()=>{if(!n.current)return;const h=[...r.current.values()],l={visible:h.length>0,text:h.at(-1)?.text??null,count:h.length},c=t.current.getSnapshot();(c.visible!==l.visible||c.text!==l.text||c.count!==l.count)&&t.current.publish(l)},[]),d=e.useCallback((h,l)=>{if(!n.current||h!=="global"&&o.current!==h)return null;const c=++i.current;return r.current.set(c,{owner:h,text:l}),g(),c},[g]),m=e.useCallback((h,l)=>{if(l!=null)r.current.get(l)?.owner===h&&r.current.delete(l);else for(const[c,L]of r.current)L.owner===h&&r.current.delete(c);g()},[g]),f=e.useCallback((h,l)=>{h?(m("global"),d("global",l)):m("global")},[d,m]),x=e.useCallback((h,l,c)=>{l?(m(h),d(h,c)):m(h)},[d,m]);return{loadingApi:e.useMemo(()=>({setLoading:f,setScreenLoading:x,begin:d,end:m}),[f,x,d,m]),refreshLoading:g,loadingTasks:r,setLoading:f}}const kt=e.memo(function({store:n,translate:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(ht,{loading:r,translate:o})}),Ct=e.memo(function({store:n,dismiss:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(yt,{items:r,dismiss:o})}),Rt=e.memo(function({store:n,routeKey:o,...r}){const i=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return u.jsx(gt,{...r,override:i[o]})}),Et=e.memo(function({route:n,screen:o,navigation:r,focused:i,resultEvent:g,setFooter:d,loadingApi:m,loadingStore:f,bodyClassName:x,notifyError:R,registerDirtyGuard:y}){const h=o.component,l=e.useMemo(()=>({isFocused:i,resultEvent:g,routeKey:n.key,setFooter:d}),[i,g,n.key,d]),c=e.useMemo(()=>({setLoading:(E,P)=>m.setScreenLoading(n.key,E,P),showLoading:E=>m.begin(n.key,E),hideLoading:E=>m.end(n.key,E)}),[m,n.key]),L=e.useMemo(()=>({routeKey:n.key,registerDirtyGuard:y}),[n.key,y]);return u.jsx(Ve.Provider,{value:n,children:u.jsx(Ye.Provider,{value:L,children:u.jsx(Me.Provider,{value:l,children:u.jsx(je.Provider,{value:c,children:u.jsx(De.Provider,{value:f,children:u.jsx("div",{hidden:!i,inert:!i,"data-modal-route-key":n.key,tabIndex:-1,className:`pmn-body ${x??""}`,children:u.jsx(bt,{route:n,onError:R,children:u.jsx(h,{route:n,navigation:r})})})})})})})})});function Je({config:t,initialScreen:n,params:o,options:r,translate:i,onRequestClose:g,onOpened:d,registerLoading:m,notifyError:f,error:x,clearError:R,registerDirtyGuard:y,canNavigate:h,exiting:l=!1}){const[c,L]=e.useReducer(Ee,null,()=>Qe(n??t.initialRoute,o)),E=e.useRef(null);E.current||(E.current=ct({canGoBack:c.length>1,stack:c,currentRoute:c.at(-1)}));const P=e.useRef(null),B=e.useRef(null),I=e.useRef(null);P.current||(P.current=Pe({visible:!1,text:null,count:0})),B.current||(B.current=Pe({})),I.current||(I.current=Pe([]));const k=e.useRef(!0),$=e.useRef(0),{toast:K,dismissToast:G}=vt(I,k);e.useEffect(()=>(k.current=!0,()=>{k.current=!1,$.current++}),[]);const[S,b]=e.useState({}),M=e.useRef(new Map),q=e.useRef(null),F=e.useRef(null),j=e.useRef(!1),W=e.useRef(!1),N=e.useRef(new Map),Q=e.useRef(0),J=e.useCallback((a,v,T)=>{for(const[D,ne]of N.current)a.includes(ne.key)&&(N.current.delete(D),ne.resolve({status:v,...v==="returned"?{value:T}:{}}))},[]),A=e.useRef(c);A.current=c;const re=e.useRef(h);re.current=h;const X=e.useRef(!1),ge=e.useRef(0),z=c.at(-1),O=z.key,oe=e.useRef(O);oe.current=O;const{loadingApi:he,refreshLoading:be,loadingTasks:le,setLoading:se}=wt(P,k,oe),Z=t.screens,we=P,de=e.useRef(m);de.current=m,e.useEffect(()=>(de.current?.({setLoading:se}),()=>de.current?.(null)),[se]);const ke=e.useCallback((a,v)=>{if(!k.current)return;const T=B.current.getSnapshot();if(v===null){if(!(a in T))return;const D={...T};delete D[a],B.current.publish(D);return}T[a]!==v&&B.current.publish({...T,[a]:v})},[]),xe=e.useCallback(()=>{if(typeof document>"u")return;const a=document.activeElement;if(!(a instanceof HTMLElement)||!q.current?.contains(a))return;const v=a.closest("[data-modal-route-key]");v&&M.current.set(v.dataset.modalRouteKey,a),q.current.focus({preventScroll:!0})},[]),ye=e.useCallback(a=>{if(!Object.prototype.hasOwnProperty.call(Z,a))throw new Error(`[react-modal-navigation] Unknown modal screen: ${a}`)},[Z]),ae=e.useCallback((a,v)=>{try{Promise.resolve(r[a]?.(v)).catch(T=>f(T,{phase:a}))}catch(T){f(T,{phase:a})}},[r,f]),V=e.useCallback(async(a,v,T,D)=>{if(!k.current||W.current)return!1;const ne=$.current,_=A.current,Te=_.at(-1);if(a!=="BACK"&&ye(v),a==="BACK"&&_.length<=1)return!1;const ze=a==="NAVIGATE"?_.findIndex(pe=>pe.name===v):-1,Ne=a==="RESET"?_:a==="BACK"||a==="REPLACE"?[Te]:ze>=0?_.slice(ze+1):[];W.current=!0;try{if(Ne.length&&re.current&&!await re.current(Ne.map(Le=>Le.key),{reason:"navigation",action:a,from:Te,to:a==="BACK"?_.at(-2)?.name:v})||!k.current||ne!==$.current||A.current.at(-1)?.key!==Te.key)return!1;if(a==="BACK"&&D!==void 0){const Re=_.at(-2);b(Le=>({...Le,[Re.key]:{id:++ge.current,data:D}}))}a==="RESET"&&b({}),J(Ne.map(Re=>Re.key),a==="BACK"?"returned":"removed",D),xe();const pe={type:a,name:v,params:T};return A.current=Ee(A.current,pe),L(pe),!0}catch(pe){return k.current&&f(pe,{phase:"navigationGuard",action:a}),!1}finally{W.current=!1}},[ye,xe,f,J]),s=e.useCallback((a,v)=>V("NAVIGATE",a,v),[V]),p=e.useCallback(async(a,v)=>{if(!k.current)return{status:"cancelled"};if(A.current,!await V("NAVIGATE",a,v)||!k.current)return{status:"cancelled"};const D=A.current.at(-1);return!D||D.name!==a?{status:"cancelled"}:new Promise(ne=>{const _=++Q.current;N.current.set(_,{key:D.key,resolve:ne})})},[V]),C=e.useCallback((a,v)=>V("REPLACE",a,v),[V]),w=e.useCallback((a,v)=>V("RESET",a,v),[V]),H=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setParams expects an object");if(!k.current)return;const v={type:"SET_PARAMS",params:a};A.current=Ee(A.current,v),L(v)},[]),U=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setOptions expects an object");if(!k.current)return;const v={type:"SET_OPTIONS",options:a};A.current=Ee(A.current,v),L(v)},[]),Y=e.useCallback(a=>V("BACK",null,void 0,a),[V]),ee=e.useCallback((a,v)=>!k.current||we.current.getSnapshot().visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):g(a,v,{route:z,stack:c}),[r.lockCloseWhileLoading,g,z,c]),te=e.useRef(ee);te.current=ee;const ce=e.useCallback(a=>te.current("api",a),[]),me=e.useMemo(()=>({navigate:s,navigateAsync:p,replace:C,reset:w,setParams:H,setOptions:U,goBack:Y,close:ce,setLoading:se}),[s,p,C,w,H,U,Y,ce,se]),fe=e.useMemo(()=>({canGoBack:c.length>1,stack:c,currentRoute:z}),[c]);e.useLayoutEffect(()=>E.current.publish(fe),[fe]);const ie=e.useRef(null);ie.current||(ie.current=Object.defineProperties({},{canGoBack:{enumerable:!0,get:()=>E.current.getSnapshot().canGoBack},stack:{enumerable:!0,get:()=>E.current.getSnapshot().stack},currentRoute:{enumerable:!0,get:()=>E.current.getSnapshot().currentRoute}}));const Ce=e.useMemo(()=>Object.assign(ie.current,me),[me]);e.useLayoutEffect(()=>{j.current=!1;const a=[...q.current?.querySelectorAll("[data-modal-route-key]")??[]].find(D=>D.dataset.modalRouteKey===O);if(!a)return;const v=M.current.get(O);(v?.isConnected&&a.contains(v)&&!v.matches(":disabled")&&!v.closest("[inert], [hidden]")?v:a).focus({preventScroll:!0})},[O]),e.useEffect(()=>{let a=!1;for(const[T,D]of le.current)D.owner!=="global"&&D.owner!==O&&(le.current.delete(T),a=!0);a&&be();const v=new Set(c.map(T=>T.key));b(T=>{const D=Object.keys(T).filter(_=>!v.has(_));if(!D.length)return T;const ne={...T};return D.forEach(_=>delete ne[_]),ne});for(const T of M.current.keys())v.has(T)||M.current.delete(T)},[O,c,be]),e.useEffect(()=>{if(F.current?.key!==O){if(F.current){const a={from:F.current,to:z,stack:c};ae("onBlur",{route:F.current,...a}),ae("onNavigate",a),ae("onRouteChange",a)}ae("onFocus",{route:z,stack:c}),F.current=z}},[z,O,c,ae]),e.useEffect(()=>()=>{le.current.clear(),M.current.clear();for(const a of N.current.values())a.resolve({status:"dismissed"});N.current.clear()},[]),e.useEffect(()=>{X.current||(X.current=!0,d?.({route:z,stack:c}))},[]);const nt=e.useMemo(()=>ut(c,Z,r.maxCachedScreens),[c,Z,r.maxCachedScreens]),$e=e.useMemo(()=>({...Z[z.name],...z.options??{}}),[Z,z.name,z.options]);return u.jsx(_e.Provider,{value:K,children:u.jsx(st.Provider,{value:I.current,children:u.jsx(at.Provider,{value:B.current,children:u.jsx(ot.Provider,{value:Ce,children:u.jsx(Fe.Provider,{value:me,children:u.jsx(Oe.Provider,{value:E.current,children:u.jsx(je.Provider,{value:he,children:u.jsxs(ft,{dialogRef:q,options:r,requestClose:ee,exiting:l,children:[u.jsx(pt,{options:r,screen:$e,route:z,navigation:Ce,requestClose:ee,translate:i,canGoBack:c.length>1}),u.jsx("main",{className:"pmn-main",children:nt.map(a=>u.jsx(Et,{route:a,screen:Z[a.name],navigation:Ce,focused:a.key===O,resultEvent:S[a.key]??null,bodyClassName:r.bodyClassName,setFooter:ke,loadingApi:he,loadingStore:P.current,notifyError:f,registerDirtyGuard:y},a.key))}),u.jsx(Rt,{store:B.current,routeKey:O,screen:$e,options:r,route:z,navigation:Ce,requestClose:ee,translate:i,onError:f,loadingApi:he},O),u.jsx(kt,{store:P.current,translate:i}),u.jsx(Ct,{store:I.current,dismiss:G}),x&&u.jsxs("div",{className:"pmn-error",role:"alert",children:[u.jsx("span",{children:x.message||String(x)}),u.jsx("button",{type:"button",onClick:R,"aria-label":"Dismiss error",children:"×"})]})]})})})})})})})})}const St=".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}",He="react-modal-navigation-styles",Ae=new WeakMap;function Mt(){e.useInsertionEffect(()=>{if(typeof document>"u")return;const t=document;let n=Ae.get(t);if(!n){let o=t.getElementById(He);const r=!o;o||(o=t.createElement("style"),o.id=He,o.setAttribute("data-react-modal-navigation",""),o.textContent=St,t.head.appendChild(o)),n={element:o,owned:r,count:0},Ae.set(t,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),Ae.delete(t))}},[])}function Se(t,n,o){if(typeof t=="string"){if(!t.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:t,params:n??{},options:o??{}}}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:r,screen:i,params:g={},options:d={},...m}=t;if(typeof r!="string"||!r.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(d===null||typeof d!="object"||Array.isArray(d))throw new TypeError("[react-modal-navigation] open config options must be an object");if(i!==void 0&&(typeof i!="string"||!i.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:r,...i===void 0?{}:{screen:i},params:g,options:{...m,...d}}}const jt={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Tt=t=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[t]??t;function Nt({registry:t,children:n,defaultOptions:o={},backgroundColor:r,theme:i,translate:g=Tt,onError:d,confirmDiscard:m}){Mt();const[f,x]=e.useState(null),[R,y]=e.useState(null),[h,l]=e.useState(0),c=e.useRef(null),L=e.useRef(new Map),E=e.useRef([]),P=e.useRef(null),B=e.useRef(null),I=e.useRef(0),k=e.useRef(null),$=e.useRef(!1),K=e.useRef(0),G=e.useRef(null),S=e.useRef(new Map),[b,M]=e.useState(!1),q=e.useRef(m);q.current=m;const F=e.useCallback((s,p)=>(S.current.set(s,p),()=>{S.current.get(s)===p&&S.current.delete(s)}),[]),j=e.useCallback(async s=>{for(const p of S.current.values()){if(!p.dirty)continue;if((p.onBeforeDiscard?await p.onBeforeDiscard(s):q.current?await q.current(s):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(p.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),W=e.useCallback(async(s,p)=>{for(const C of s){const w=S.current.get(C);if(!w?.dirty)continue;if((w.onBeforeDiscard?await w.onBeforeDiscard(p):q.current?await q.current(p):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(w.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),N=e.useRef(!0),Q=e.useRef(null),J=e.useRef(d);J.current=d;const A=e.useCallback((s,p)=>{N.current&&y(s);try{J.current?J.current(s,p):console.error("[react-modal-navigation]",s)}catch(C){console.error("[react-modal-navigation] onError failed",C)}},[]),re=e.useCallback((s,p)=>{const C=L.current.get(s);L.current.delete(s),C?.(p)},[]),X=e.useCallback(s=>({...jt,...o,...i!==void 0?{theme:i}:{},...r!==void 0?{backgroundColor:r}:{},...s.config.modalOptions,...s.overrides}),[o,i,r]),ge=f?X(f):null,z=e.useRef(null);z.current=ge,Q.current=ge;const O=e.useCallback(async(s="api",p,C={})=>{const w=c.current;if(!w||k.current||$.current)return!1;k.current=w.id,$.current=!0;const H=Q.current??X(w),U={...C,reason:s,result:p,name:w.name};try{if(!await j(U)||await H.onBeforeClose?.(U)===!1||c.current?.id!==w.id||!N.current||(M(!0),await new Promise(Y=>{const ee=H.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(H.animationDuration??220)||0);setTimeout(Y,Math.min(ee,1e3))}),!N.current||c.current?.id!==w.id))return!1;c.current=null,G.current=null,x(null),M(!1),S.current.clear(),re(w.id,C.confirmed||p!==void 0?{status:"confirmed",value:p,reason:s}:{status:"dismissed",reason:s});try{await H.onClose?.(U)}catch(Y){A(Y,{phase:"onClose",name:w.name})}return!0}catch(Y){return A(Y,{phase:"onBeforeClose",name:w.name}),!1}finally{k.current===w.id&&(k.current=null),$.current=!1,!c.current&&N.current&&queueMicrotask(()=>B.current?.())}},[X,A,re,j]),oe=e.useCallback(async(s,p={},C={},w,H)=>{const U=t?.[s];if(!U)throw new Error(`[react-modal-navigation] Unknown modal: ${s}`);const Y=H??U.initialRoute;if(!U.screens?.[Y])throw new Error(`[react-modal-navigation] Unknown initial screen '${Y}' in modal '${s}'`);if(!N.current||$.current||k.current)return null;$.current=!0;const ee=K.current;try{const te=c.current;if(te){const me=Q.current??X(te),fe={reason:"replace",name:te.name,nextName:s};try{if(!await j(fe)||await me.onBeforeClose?.(fe)===!1)return null}catch(ie){return A(ie,{phase:"onBeforeClose",name:te.name}),null}if(!N.current||ee!==K.current||c.current?.id!==te.id)return null;c.current=null,G.current=null,x(null),S.current.clear(),re(te.id,{status:"replaced",reason:"replace"});try{await me.onClose?.(fe)}catch(ie){A(ie,{phase:"onClose",name:te.name})}if(!N.current||ee!==K.current)return null}const ce={id:++I.current,name:s,screen:Y,params:p,config:U,overrides:C};return c.current=ce,G.current=null,w&&L.current.set(ce.id,w),y(null),x(ce),ce.id}finally{$.current=!1}},[t,X,A,re,j]);P.current=oe;const he=e.useCallback(async()=>{if(!N.current||c.current||$.current||k.current)return;const s=E.current.shift();if(s){l(E.current.length);try{const p=await P.current(s.args.name,s.args.params,s.args.options,s.resolveResult,s.args.screen);p===null?(s.resolveResult?.({status:"dismissed",reason:"blocked"}),s.resolveId?.(null),queueMicrotask(()=>B.current?.())):s.resolveId?.(p)}catch(p){s.reject?.(p),queueMicrotask(()=>B.current?.())}}},[]);B.current=he;const be=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveId:H,reject:U}),l(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),le=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return t?.[w.name]?new Promise((H,U)=>{E.current.push({args:w,resolveResult:H,reject:U}),l(E.current.length),queueMicrotask(()=>B.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${w.name}`))},[t]),se=e.useCallback(s=>{if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("[react-modal-navigation] update expects an options object");const p=c.current;if(!p||$.current)return!1;const C={...p,overrides:{...p.overrides,...s}};return c.current=C,x(C),Q.current=X(C),!0},[X]),Z=e.useCallback((s="queue-cleared")=>{const p=E.current.splice(0);l(0);for(const C of p)C.resolveId?.(null),C.resolveResult?.({status:"dismissed",reason:s});return p.length},[]),we=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return oe(w.name,w.params,w.options,void 0,w.screen)},[oe]),de=e.useCallback((s,p,C)=>{const w=Se(s,p,C);return new Promise((H,U)=>{oe(w.name,w.params,w.options,H,w.screen).then(Y=>{Y===null&&H({status:"dismissed",reason:"blocked"})},U)})},[oe]),ke=e.useCallback(s=>O("api",s),[O]),xe=e.useCallback((s="api")=>O(s),[O]),ye=e.useCallback(s=>O("confirm",s,{confirmed:!0}),[O]),ae=e.useCallback((s,p)=>G.current?.setLoading(s,p),[]),V=e.useMemo(()=>({open:we,openAsync:de,enqueue:be,enqueueAsync:le,update:se,clearQueue:Z,close:ke,dismiss:xe,confirm:ye,setLoading:ae,queueSize:h,isOpen:!!f,activeName:f?.name??null,error:R,clearError:()=>y(null)}),[we,de,be,le,se,Z,ke,xe,ye,ae,f,R,h]);return e.useEffect(()=>(N.current=!0,()=>{N.current=!1,K.current+=1,c.current=null;for(const p of L.current.values())p({status:"dismissed",reason:"unmount"});L.current.clear(),S.current.clear();const s=E.current.splice(0);for(const p of s)p.resolveId?.(null),p.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]),u.jsxs(We.Provider,{value:V,children:[n,f&&u.jsx(Je,{config:f.config,initialScreen:f.screen,params:f.params,options:ge,translate:g,notifyError:A,error:R,clearError:()=>y(null),registerLoading:s=>{G.current=s},registerDirtyGuard:F,canNavigate:W,exiting:b,onRequestClose:O,onOpened:s=>{try{const p=z.current?.onOpen?.(s);Promise.resolve(p).catch(C=>A(C,{phase:"onOpen"}))}catch(p){A(p,{phase:"onOpen"})}}},f.id)]})}const Lt=Object.freeze({canGoBack:!1,stack:[],currentRoute:null}),Pt=()=>()=>{},Ue=()=>Lt;function Bt(){const t=e.useContext(We),n=e.useContext(Fe),o=e.useContext(Oe),r=e.useSyncExternalStore(o?.subscribe??Pt,o?.getSnapshot??Ue,o?.getSnapshot??Ue);if(!t)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");const i=e.useMemo(()=>{const g=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{navigate:(...d)=>g().navigate(...d),replace:(...d)=>g().replace(...d),reset:(...d)=>g().reset(...d),setParams:(...d)=>g().setParams(...d),setOptions:(...d)=>g().setOptions(...d),goBack:(...d)=>g().goBack(...d),close:(...d)=>g().close(...d),setLoading:(...d)=>g().setLoading(...d),canGoBack:r.canGoBack,stack:r.stack,currentRoute:r.currentRoute}},[n,r]);return e.useMemo(()=>({...t,modal:t,navigation:i}),[t,i])}function Xe(){const t=e.useContext(Fe);if(!t)throw new Error("useModalNavigationCommands requires an active modal screen");return t}function Ze(){const t=e.useContext(Oe);if(!t)throw new Error("useModalNavigationState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function At(){const t=Xe(),n=Ze();return e.useMemo(()=>({...t,...n}),[t,n])}function Ie(){const t=e.useContext(Me);if(!t)throw new Error("useIsFocused must be called inside a modal screen");return t.isFocused}function qt(t){const n=Ie();e.useEffect(()=>{if(n)return t()},[n,t])}function Ft(t){const n=e.useContext(Me);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=e.useRef(t),r=e.useRef(null);e.useEffect(()=>{o.current=t},[t]),e.useEffect(()=>{!n.isFocused||!n.resultEvent||r.current!==n.resultEvent.id&&(r.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function Ot(t={}){const n=e.useContext(Me);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:r}=n,i=e.useRef(t);i.current=t;const g=e.useMemo(()=>(...S)=>i.current.done?.(...S),[]),d=e.useMemo(()=>(...S)=>(i.current.cancel??i.current.cancle)?.(...S),[]),m=e.useMemo(()=>(...S)=>i.current.renderFooter?.(...S),[]),f=typeof t.done=="function",x=typeof(t.cancel??t.cancle)=="function",R=typeof t.renderFooter=="function",{showFooter:y,showFooterBorder:h,doneDisabled:l,doneText:c,cancelText:L,loadingText:E,footerClassName:P}=t,B=e.useRef({source:null,normalized:void 0}),I=Array.isArray(t.actions)?t.actions:null,k=B.current.source;I===k||I&&k&&I.length===k.length&&I.every((S,b)=>{const M=k[b];return[...new Set([...Object.keys(S),...Object.keys(M)])].every(F=>F==="onClick"||Object.is(S[F],M[F]))})||(B.current={source:I?.map(S=>({...S}))??null,normalized:I?.map((S,b)=>({...S,onClick:(...M)=>(i.current.actions?.find(F=>F.key===S.key)??i.current.actions?.[b])?.onClick?.(...M)}))});const K=B.current.normalized,G=e.useMemo(()=>({showFooter:y,showFooterBorder:h,doneDisabled:l,doneText:c,cancelText:L,loadingText:E,footerClassName:P,...K!==void 0?{actions:K}:{},...f?{done:g}:{},...x?{cancel:d}:{},...R?{renderFooter:m}:{}}),[y,h,l,c,L,E,P,K,f,x,R,g,d,m]);e.useEffect(()=>{o(r,G)},[r,o,G]),e.useEffect(()=>()=>o(r,null),[r,o])}function et(){const t=e.useContext(je),n=e.useContext(De);if(!t||!n)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");const o=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return e.useMemo(()=>({...t,isLoading:o.visible}),[t,o.visible])}function Dt(){const t=e.useContext(je);if(!t)throw new Error("[react-modal-navigation] useModalLoadingCommands requires an active modal screen");return t}function It(){const t=e.useContext(De);if(!t)throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function $t(){const t=et(),n=Ie(),o=e.useRef(!0),r=e.useRef(!1),[i,g]=e.useState(!1),[d,m]=e.useState(null),f=e.useRef(t);return f.current=t,e.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:e.useCallback(async(R,y={})=>{if(r.current)return{status:"busy"};if(typeof R!="function")throw new TypeError("[react-modal-navigation] run requires a function");r.current=!0,o.current&&(g(!0),m(null));const h=f.current.showLoading(y.loadingText);try{const l=await R();return o.current&&await y.onSuccess?.(l),{status:"success",value:l}}catch(l){if(o.current){m(l);try{await y.onError?.(l)}catch(c){console.error("[react-modal-navigation] onError failed",c)}}if(y.throwOnError)throw l;return{status:"error",error:l}}finally{h!=null&&f.current.hideLoading(h),r.current=!1,o.current&&g(!1)}},[]),pending:i,error:d,clearError:()=>m(null),isFocused:n}}function zt(t,n={}){const o=e.useContext(Ye);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const r=e.useRef({dirty:t,...n});r.current={dirty:t,...n};const{routeKey:i,registerDirtyGuard:g}=o;e.useEffect(()=>g(i,{get dirty(){return!!r.current.dirty},get message(){return r.current.message},get onBeforeDiscard(){return r.current.onBeforeDiscard}}),[i,g])}const Kt=()=>{const t=e.useContext(_e);if(!t)throw new Error("[react-modal-navigation] useToast requires an active modal");return t};function tt(){const t=e.useContext(Ve);if(!t)throw new Error("[react-modal-navigation] useModalRoute requires a modal screen");return t}function Gt(){return tt().params}exports.ModalNavigator=Je;exports.ModalProvider=Nt;exports.useFocusEffect=qt;exports.useIsFocused=Ie;exports.useModal=Bt;exports.useModalFooter=Ot;exports.useModalLoading=et;exports.useModalLoadingCommands=Dt;exports.useModalLoadingState=It;exports.useModalNavigation=At;exports.useModalNavigationCommands=Xe;exports.useModalNavigationState=Ze;exports.useModalParams=Gt;exports.useModalRoute=tt;exports.useModalTask=$t;exports.useModalUnsavedChanges=zt;exports.useNavigationResult=Ft;exports.useToast=Kt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),e=require("react"),jt=require("react-dom"),ct=e.createContext(null),it=e.createContext(null),Ne=e.createContext(null),xe=e.createContext(null),Ue=e.createContext(null),We=e.createContext(null),qe=e.createContext(null),Oe=e.createContext(null),Fe=e.createContext(null),lt=e.createContext(null),ut=e.createContext(null),Ye=e.createContext(null);function dt(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(n!==r){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}function ye(t){let n=t;const o=new Set;return{getSnapshot:()=>n,subscribe:r=>(o.add(r),()=>o.delete(r)),publish(r){if(!Object.is(n,r)){n=r;for(const i of[...o])i()}},listenerCount:()=>o.size}}let Mt=0;const _e=(t,n)=>({key:`modal-route-${++Mt}`,name:t,params:n??{}}),mt=(t,n)=>[_e(t,n)];function Ae(t,n){switch(n.type){case"RESET":return mt(n.name,n.params);case"NAVIGATE":{const o=t.findIndex(r=>r.name===n.name);return o<0?[...t,_e(n.name,n.params)]:t.slice(0,o+1).map((r,i)=>i===o?{...r,params:n.params??{}}:r)}case"SET_OPTIONS":return t.map((o,r)=>r===t.length-1?{...o,options:{...o.options??{},...n.options??{}}}:o);case"SET_PARAMS":return t.map((o,r)=>r===t.length-1?{...o,params:{...o.params??{},...n.params??{}}}:o);case"BACK":return t.length>1?t.slice(0,-1):t;case"REPLACE":return t.length?[...t.slice(0,-1),_e(n.name,n.params)]:t;default:return t}}function Tt(t,n,o=1/0){const r=o===1/0?1/0:Math.max(0,Math.floor(Number(o)||0)),i=t.slice(0,-1).filter(p=>n[p.name]?.keepAlive!==!1),g=new Set((r===0?[]:i.slice(-r)).map(p=>p.key));return t.filter((p,f)=>f===t.length-1||g.has(p.key))}const Nt=Object.freeze({sm:400,md:560,lg:720,xl:960,full:"100%"}),Me=t=>typeof t=="number"?`${t}px`:t,rt=()=>{if(typeof document>"u")return"light";const t=document.documentElement,n=document.body;return t.classList.contains("dark")||n.classList.contains("dark")||t.dataset.theme==="dark"||n.dataset.theme==="dark"?"dark":t.classList.contains("light")||n.classList.contains("light")||t.dataset.theme==="light"||n.dataset.theme==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};let Te=0;const de=[];let Ge=null;function Pt(){if(Te++,Te===1){const n=document.documentElement,o=document.body,r={html:n.style.overflow,body:o.style.overflow,padding:o.style.paddingRight,width:o.style.getPropertyValue("--modal-scrollbar-width")},i=Math.max(0,window.innerWidth-n.clientWidth),g=parseFloat(getComputedStyle(o).paddingRight)||0;i&&(o.style.paddingRight=`${g+i}px`),o.style.setProperty("--modal-scrollbar-width",`${i}px`),n.style.overflow="hidden",o.style.overflow="hidden",Ge=()=>{n.style.overflow=r.html,o.style.overflow=r.body,o.style.paddingRight=r.padding,r.width?o.style.setProperty("--modal-scrollbar-width",r.width):o.style.removeProperty("--modal-scrollbar-width")}}let t=!1;return()=>{t||(t=!0,Te=Math.max(0,Te-1),Te||(Ge?.(),Ge=null))}}const Lt='a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])',At=t=>!t.closest('[inert], [hidden], [aria-hidden="true"]')&&t.getClientRects().length>0&&getComputedStyle(t).visibility!=="hidden"&&getComputedStyle(t).display!=="none";function pt({dialogRef:t,options:n,requestClose:o,children:r,exiting:i=!1}){const g=e.useRef(null),p=e.useRef(null),f=e.useRef(o);f.current=o;const u=e.useRef(n.closeOnEsc);u.current=n.closeOnEsc;const[x,S]=e.useState(rt),k=n.theme==="light"||n.theme==="dark"?n.theme:x;e.useEffect(()=>{if(n.theme==="light"||n.theme==="dark")return;const b=()=>S(rt()),M=new MutationObserver(b);for(const _ of[document.documentElement,document.body])M.observe(_,{attributes:!0,attributeFilter:["class","data-theme"]});const H=window.matchMedia?.("(prefers-color-scheme: dark)");return H?.addEventListener?.("change",b),b(),()=>{M.disconnect(),H?.removeEventListener?.("change",b)}},[n.theme]),e.useEffect(()=>{p.current=document.activeElement;const b=Pt(),M=g.current;de.push(M),t.current?.focus({preventScroll:!0});const H=L=>{const D=t.current;if(!D||de.at(-1)!==M)return;if(L.key==="Escape"&&u.current!==!1){L.preventDefault(),f.current("escape");return}if(L.key!=="Tab")return;const T=[...D.querySelectorAll(Lt)].filter(At);if(!T.length){L.preventDefault(),D.focus();return}const V=T[0],z=T.at(-1);D.contains(document.activeElement)?L.shiftKey&&(document.activeElement===V||document.activeElement===D)?(L.preventDefault(),z.focus()):!L.shiftKey&&(document.activeElement===z||document.activeElement===D)&&(L.preventDefault(),V.focus()):(L.preventDefault(),(L.shiftKey?z:V).focus())},_=L=>{de.at(-1)===M&&t.current&&!t.current.contains(L.target)&&t.current.focus({preventScroll:!0})};return document.addEventListener("keydown",H),document.addEventListener("focusin",_),()=>{document.removeEventListener("keydown",H),document.removeEventListener("focusin",_);const L=de.at(-1)===M,D=de.indexOf(M);if(D!==-1&&de.splice(D,1),b(),L){const T=p.current;T?.isConnected&&!T.closest("[inert], [hidden]")?T.focus?.({preventScroll:!0}):de.at(-1)?.querySelector("[role=dialog]")?.focus?.({preventScroll:!0})}}},[t]);const d=n.backgroundColor??n.backgroudColor,m=typeof d=="string"?d:d?.[k],c=typeof m=="string"&&/^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|color\(|var\()/.test(m.trim())?m:null,E=["center","left","right","top","bottom"].includes(n.placement)?n.placement:"right",P=Me(n.width??Nt[n.size]??460),I=Me(n.height),A=Me(n.maxHeight),K=Me(n.maxWidth),v=Number(n.viewportGap??5),B=Number.isFinite(v)?Math.max(0,v):5,F=n.top==null?null:Me(n.top),O=E==="top"&&F!==null?F:null,j=typeof n.borderRadius=="number"?`${n.borderRadius}px`:n.borderRadius??"12px";return jt.createPortal(s.jsx("div",{ref:g,className:`pmn-overlay ${i?"pmn-exiting":"pmn-entering"} ${n.animation===!1?"pmn-no-animation":""} pmn-place-${E} ${n.mobileFullscreen?"pmn-mobile-fullscreen":""}`,style:{padding:B,...O!==null?{paddingTop:O,"--pmn-top-offset":O}:{},"--pmn-animation-duration":`${Math.min(1e3,Math.max(0,Number(n.animationDuration??220)||0))}ms`},onMouseDown:b=>{b.target===b.currentTarget&&n.closeOnOverlay===!0&&f.current("overlay")},children:s.jsx("section",{ref:t,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":n.ariaLabel??"Dialog","data-modal-theme":k,className:`pmn-dialog ${k==="dark"?"dark":""} ${!c&&m?m:""} ${n.className??""}`,style:{"--pmn-width":P,"--pmn-gap":`${B}px`,...O!==null?{"--pmn-top-offset":O}:{},...I!==void 0?{"--pmn-height":I}:{},...A!==void 0?{"--pmn-max-height":A}:{},...K!==void 0?{"--pmn-max-width":K}:{},borderRadius:j,...c?{backgroundColor:c}:{}},children:r})}),document.body)}function ot({back:t}){return s.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t?s.jsx("path",{d:"m15 18-6-6 6-6"}):s.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function ft({options:t,screen:n,route:o,navigation:r,requestClose:i,translate:g,canGoBack:p}){if(t.showHeader===!1)return null;const f=g??(m=>m),u=n.showTitle??t.showTitle??!0,x=typeof n.title=="function"?n.title({t:f,route:o,navigation:r}):n.title??o.name,S={route:o,navigation:r,close:i,canGoBack:p,title:x,t:f},k=n.renderHeader??t.renderHeader;if(k)return k(S);const d=n.renderHeaderRight??t.renderHeaderRight;return s.jsxs("header",{className:`pmn-header ${n.showHeaderBorder??t.showHeaderBorder?"pmn-border-bottom":""} ${t.headerClassName??""}`,children:[(n.showBackButton??t.showBackButton)!==!1&&p&&s.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":f("modal.back"),onClick:()=>r.goBack(),children:s.jsx(ot,{back:!0})}),u?s.jsx("h2",{children:x}):s.jsx("div",{className:"pmn-header-spacer"}),d?.(S),t.showCloseButton!==!1&&s.jsx("button",{type:"button",className:"pmn-icon-button","aria-label":f("modal.close"),onClick:()=>i("header"),children:s.jsx(ot,{})})]})}function gt({screen:t,options:n,override:o,route:r,navigation:i,requestClose:g,translate:p,onError:f,loadingApi:u}){const[x,S]=e.useState(null),k=e.useRef(new Set),d=e.useRef(!0);e.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const m=p??(b=>b),c={...n,...t,...o},{showFooter:E,renderFooter:P,done:I,cancel:A,cancle:K}=c,v=A??K,B={route:r,navigation:i,close:g,t:m};if(E===!1)return null;const F=`pmn-footer ${c.showFooterBorder?"pmn-border-top":""} ${c.footerClassName??""}`;if(typeof P=="function")return s.jsx("footer",{className:F,children:P({...B,pending:k.current.size>0})});const O=Array.isArray(c.actions)?c.actions:null;if(!O&&typeof I!="function"&&typeof v!="function")return null;const j=async(b,M,H)=>{if(k.current.has(b)||typeof M!="function")return;k.current.add(b),S(b);const _=u?.begin(r.key,H??c.loadingText??m("modal.processing"));try{await M(B)}catch(L){f?.(L,{phase:"footer",action:b,route:r})}finally{u?.end(r.key,_),k.current.delete(b),d.current&&S(L=>L===b?null:L)}};return O?s.jsx("footer",{className:F,children:O.filter(b=>!b.hidden).map(b=>{const M=k.current.has(b.key)||b.loading===!0;return s.jsx("button",{type:"button",disabled:b.disabled===!0||M,className:`pmn-button ${b.variant==="primary"||b.variant==="danger"?"pmn-button-primary":"pmn-button-secondary"} ${b.variant==="danger"?"pmn-button-danger":""}`,onClick:()=>j(b.key,b.onClick,b.loadingText),children:M?b.loadingText??c.loadingText??m("modal.processing"):b.label},b.key)})}):s.jsxs("footer",{className:F,children:[typeof v=="function"&&s.jsx("button",{type:"button",disabled:x!==null,onClick:()=>j("cancel",v),className:"pmn-button pmn-button-secondary",children:c.cancelText??m("modal.cancel")}),typeof I=="function"&&s.jsx("button",{type:"button",disabled:x!==null||c.doneDisabled===!0,onClick:()=>j("done",I),className:"pmn-button pmn-button-primary",children:x==="done"?c.loadingText??m("modal.processing"):c.doneText??m("modal.done")})]})}function ht({loading:t,translate:n}){if(!t.visible)return null;const r=(n??(g=>g))("modal.loading"),i=t.text??(r==="modal.loading"?"加载中...":r);return s.jsx("div",{className:"pmn-loading-overlay",role:"status","aria-live":"polite","aria-busy":"true",children:s.jsxs("div",{className:"pmn-loading-content",children:[s.jsx("span",{className:"pmn-spinner","aria-hidden":"true"}),i&&s.jsx("span",{className:"pmn-loading-text",children:i})]})})}class bt extends e.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,o){this.props.onError?.(n,{phase:"render",route:this.props.route,componentStack:o.componentStack})}componentDidUpdate(n){n.route?.key!==this.props.route?.key&&this.state.error&&this.setState({error:null})}render(){return this.state.error?s.jsxs("div",{role:"alert",className:"pmn-error-screen",children:[s.jsx("strong",{children:"页面加载失败"}),s.jsx("p",{children:this.state.error.message}),s.jsx("button",{type:"button",className:"pmn-button pmn-button-secondary",onClick:()=>this.setState({error:null}),children:"重试"})]}):this.props.children}}const Bt={success:"✓",error:"×",warning:"!",info:"i"};function yt({items:t,dismiss:n}){return t.length?s.jsx("div",{className:"pmn-toast-region","aria-label":"Notifications",children:t.map(o=>s.jsxs("div",{className:`pmn-toast pmn-toast-${o.type}`,role:o.type==="error"||o.type==="warning"?"alert":"status",children:[s.jsx("span",{className:"pmn-toast-symbol","aria-hidden":"true",children:Bt[o.type]}),s.jsx("span",{className:"pmn-toast-message",children:o.message}),o.dismissible&&s.jsx("button",{type:"button",className:"pmn-toast-close","aria-label":"Dismiss notification",onClick:()=>n(o.id),children:"×"})]},o.id))}):null}function xt(t,n){const o=e.useRef(0),r=e.useRef(new Map),i=e.useCallback(f=>{clearTimeout(r.current.get(f)),r.current.delete(f),n.current&&t.current.publish(t.current.getSnapshot().filter(u=>u.id!==f))},[]),g=e.useCallback((f,u={})=>{if(typeof f!="string"||!f.trim())throw new TypeError("[react-modal-navigation] toast message must be a non-empty string");const x=typeof u=="string"?{type:u}:u??{},S=["success","error","warning","info"].includes(x.type)?x.type:"info",k=++o.current,d=Number.isFinite(x.duration)?Math.max(0,x.duration):3e3;if(!n.current)return null;const m=t.current.getSnapshot(),c=m.slice(0,Math.max(0,m.length-4));for(const E of c)clearTimeout(r.current.get(E.id)),r.current.delete(E.id);return t.current.publish([...m.slice(-4),{id:k,message:f,type:S,dismissible:x.dismissible!==!1}]),d>0&&r.current.set(k,setTimeout(()=>i(k),d)),k},[i]),p=e.useMemo(()=>{const f=(u,x)=>g(u,x);for(const u of["success","error","warning","info"])f[u]=(x,S={})=>g(x,{...S,type:u});return f.promise=async(u,x,S={})=>{const k=g(x.loading,{...S,type:"info",duration:0});try{const d=await(typeof u=="function"?u():u);k!=null&&i(k);const m=typeof x.success=="function"?x.success(d):x.success;return m&&g(m,{...S,type:"success"}),d}catch(d){k!=null&&i(k);const m=typeof x.error=="function"?x.error(d):x.error;throw m&&g(m,{...S,type:"error"}),d}},f.dismiss=i,f.clear=()=>{for(const u of r.current.values())clearTimeout(u);r.current.clear(),t.current.publish([])},f},[g,i]);return e.useEffect(()=>()=>{for(const f of r.current.values())clearTimeout(f);r.current.clear()},[]),{toast:p,dismissToast:i}}function vt(t,n,o){const r=e.useRef(new Map),i=e.useRef(0),g=e.useCallback(()=>{if(!n.current)return;const d=[...r.current.values()],m={visible:d.length>0,text:d.at(-1)?.text??null,count:d.length},c=t.current.getSnapshot();(c.visible!==m.visible||c.text!==m.text||c.count!==m.count)&&t.current.publish(m)},[]),p=e.useCallback((d,m)=>{if(!n.current||d!=="global"&&o.current!==d)return null;const c=++i.current;return r.current.set(c,{owner:d,text:m}),g(),c},[g]),f=e.useCallback((d,m)=>{if(m!=null)r.current.get(m)?.owner===d&&r.current.delete(m);else for(const[c,E]of r.current)E.owner===d&&r.current.delete(c);g()},[g]),u=e.useCallback((d,m)=>{d?(f("global"),p("global",m)):f("global")},[p,f]),x=e.useCallback((d,m,c)=>{m?(f(d),p(d,c)):f(d)},[p,f]);return{loadingApi:e.useMemo(()=>({setLoading:u,setScreenLoading:x,begin:p,end:f}),[u,x,p,f]),refreshLoading:g,loadingTasks:r,setLoading:u}}const qt=e.memo(function({store:n,translate:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(ht,{loading:r,translate:o})}),Ot=e.memo(function({store:n,dismiss:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(yt,{items:r,dismiss:o})}),Ft=e.memo(function({store:n,routeKey:o,...r}){const i=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(gt,{...r,override:i[o]})}),zt=e.memo(function({route:n,screen:o,navigation:r,focused:i,resultEvent:g,setFooter:p,loadingApi:f,loadingStore:u,bodyClassName:x,notifyError:S,registerDirtyGuard:k,pageMotion:d,lazyFallback:m}){const c=o.component,E=e.useRef(null),P=e.useRef(!1);e.useLayoutEffect(()=>{const v=i&&!P.current;if(P.current=i,!v||!d?.enabled||!E.current?.animate)return;const B=d.direction==="back"?-100:100;E.current.style.zIndex="2";const F=E.current.animate([{opacity:1,transform:`translate3d(${B}%,0,0)`},{opacity:1,transform:"translate3d(0,0,0)"}],{duration:d.duration,easing:"cubic-bezier(.22,1,.36,1)"});return()=>{F.cancel(),E.current&&(E.current.style.zIndex="")}},[i,d?.enabled,d?.direction,d?.duration,d?.distance]);const I=e.useMemo(()=>({isFocused:i,resultEvent:g,routeKey:n.key,setFooter:p}),[i,g,n.key,p]),A=e.useMemo(()=>({setLoading:(v,B)=>f.setScreenLoading(n.key,v,B),showLoading:v=>f.begin(n.key,v),hideLoading:v=>f.end(n.key,v)}),[f,n.key]),K=e.useMemo(()=>({routeKey:n.key,registerDirtyGuard:k}),[n.key,k]);return s.jsx(Ye.Provider,{value:n,children:s.jsx(Ue.Provider,{value:K,children:s.jsx(Ne.Provider,{value:I,children:s.jsx(xe.Provider,{value:A,children:s.jsx(Fe.Provider,{value:u,children:s.jsx("div",{ref:E,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}`:""} ${x??""}`,style:i&&d?.enabled?{"--pmn-page-duration":`${d.duration}ms`,"--pmn-page-distance":`${d.distance}px`}:void 0,children:s.jsx(bt,{route:n,onError:S,children:s.jsx(e.Suspense,{fallback:m??s.jsx("div",{className:"pmn-lazy-loading",role:"status","aria-live":"polite",children:"加载中..."}),children:s.jsx(c,{route:n,navigation:r})})})})})})})})})});function kt({config:t,initialScreen:n,params:o,options:r,translate:i,onRequestClose:g,onOpened:p,registerLoading:f,notifyError:u,error:x,clearError:S,registerDirtyGuard:k,canNavigate:d,exiting:m=!1}){const[c,E]=e.useReducer(Ae,null,()=>mt(n??t.initialRoute,o)),P=e.useRef(null);P.current||(P.current=dt({canGoBack:c.length>1,stack:c,currentRoute:c.at(-1)}));const I=e.useRef(null),A=e.useRef(null),K=e.useRef(null);I.current||(I.current=ye({visible:!1,text:null,count:0})),A.current||(A.current=ye({})),K.current||(K.current=ye([]));const v=e.useRef(!0),B=e.useRef(0),{toast:F,dismissToast:O}=xt(K,v);e.useEffect(()=>(v.current=!0,()=>{v.current=!1,B.current++}),[]);const[j,b]=e.useState({}),M=e.useRef(new Map),H=e.useRef(null),_=e.useRef(null),L=e.useRef(null),D=e.useRef(null),T=e.useRef(null),V=e.useRef(!1),z=e.useRef(!1),ne=e.useRef(new Map),te=e.useRef(0),ce=e.useCallback((a,w,q)=>{for(const[$,X]of ne.current)a.includes(X.key)&&(ne.current.delete($),X.resolve({status:w,...w==="returned"?{value:q}:{}}))},[]),W=e.useRef(c);W.current=c;const re=e.useRef(d);re.current=d;const le=e.useRef(!1),y=e.useRef(0),C=c.at(-1),G=C.key,oe=e.useRef({key:G,depth:c.length}),ie=oe.current,me=ie.key!==G,Pe=c.length<ie.depth?"back":"forward";me&&(oe.current={key:G,depth:c.length});const ve=Math.min(1e3,Math.max(0,Number(r.pageAnimationDuration??360)||0)),ae={distance:Math.min(300,Math.max(0,Number(r.pageAnimationDistance??96)||0)),enabled:r.pageAnimation!==!1&&r.animation!==!1&&ve>0&&me,direction:Pe,duration:ve},ke=e.useRef(G);ke.current=G;const{loadingApi:pe,refreshLoading:we,loadingTasks:Re,setLoading:fe}=vt(I,v,ke),l=t.screens,h=I,N=e.useRef(f);N.current=f,e.useEffect(()=>(N.current?.({setLoading:fe}),()=>N.current?.(null)),[fe]);const R=e.useCallback((a,w)=>{if(!v.current)return;const q=A.current.getSnapshot();if(w===null){if(!(a in q))return;const $={...q};delete $[a],A.current.publish($);return}q[a]!==w&&A.current.publish({...q,[a]:w})},[]),Z=e.useCallback(()=>{if(typeof document>"u")return;const a=document.activeElement;if(!(a instanceof HTMLElement)||!H.current?.contains(a))return;const w=a.closest("[data-modal-route-key]");w&&M.current.set(w.dataset.modalRouteKey,a),H.current.focus({preventScroll:!0})},[]),Y=e.useCallback(a=>{if(!Object.prototype.hasOwnProperty.call(l,a))throw new Error(`[react-modal-navigation] Unknown modal screen: ${a}`)},[l]),Q=e.useCallback((a,w)=>{try{Promise.resolve(r[a]?.(w)).catch(q=>u(q,{phase:a}))}catch(q){u(q,{phase:a})}},[r,u]),J=e.useCallback(async(a,w,q,$)=>{if(!v.current||z.current)return!1;const X=B.current,U=W.current,ee=U.at(-1);if(a!=="BACK"&&Y(w),a==="BACK"&&U.length<=1)return!1;const tt=a==="NAVIGATE"?U.findIndex(je=>je.name===w):-1,De=a==="RESET"?U:a==="BACK"||a==="REPLACE"?[ee]:tt>=0?U.slice(tt+1):[];z.current=!0;try{if(De.length&&re.current&&!await re.current(De.map(Ke=>Ke.key),{reason:"navigation",action:a,from:ee,to:a==="BACK"?U.at(-2)?.name:w})||!v.current||X!==B.current||W.current.at(-1)?.key!==ee.key)return!1;if(a==="BACK"&&$!==void 0){const be=U.at(-2);b(Ke=>({...Ke,[be.key]:{id:++y.current,data:$}}))}a==="RESET"&&b({}),ce(De.map(be=>be.key),a==="BACK"?"returned":"removed",$);const je=[..._.current?.querySelectorAll("[data-modal-route-key]")??[]].find(be=>be.dataset.modalRouteKey===ee.key);L.current=je?.cloneNode(!0)??null,Z();const nt={type:a,name:w,params:q};return W.current=Ae(W.current,nt),E(nt),!0}catch(je){return v.current&&u(je,{phase:"navigationGuard",action:a}),!1}finally{z.current=!1}},[Y,Z,u,ce]),Ce=e.useCallback((a,w)=>J("NAVIGATE",a,w),[J]),se=e.useCallback(async(a,w)=>{if(!v.current)return{status:"cancelled"};if(W.current,!await J("NAVIGATE",a,w)||!v.current)return{status:"cancelled"};const $=W.current.at(-1);return!$||$.name!==a?{status:"cancelled"}:new Promise(X=>{const U=++te.current;ne.current.set(U,{key:$.key,resolve:X})})},[J]),ue=e.useCallback((a,w)=>J("REPLACE",a,w),[J]),Se=e.useCallback((a,w)=>J("RESET",a,w),[J]),ge=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setParams expects an object");if(!v.current)return;const w={type:"SET_PARAMS",params:a};W.current=Ae(W.current,w),E(w)},[]),he=e.useCallback(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new TypeError("[react-modal-navigation] setOptions expects an object");if(!v.current)return;const w={type:"SET_OPTIONS",options:a};W.current=Ae(W.current,w),E(w)},[]),Ze=e.useCallback(a=>J("BACK",null,void 0,a),[J]),Ee=e.useCallback((a,w)=>!v.current||h.current.getSnapshot().visible&&r.lockCloseWhileLoading!==!1?Promise.resolve(!1):g(a,w,{route:C,stack:c}),[r.lockCloseWhileLoading,g,C,c]),Qe=e.useRef(Ee);Qe.current=Ee;const Je=e.useCallback(a=>Qe.current("api",a),[]),$e=e.useMemo(()=>({navigate:Ce,navigateAsync:se,replace:ue,reset:Se,setParams:ge,setOptions:he,goBack:Ze,close:Je,setLoading:fe}),[Ce,se,ue,Se,ge,he,Ze,Je,fe]),Xe=e.useMemo(()=>({canGoBack:c.length>1,stack:c,currentRoute:C}),[c]);e.useLayoutEffect(()=>P.current.publish(Xe),[Xe]);const Ie=e.useRef(null);Ie.current||(Ie.current=Object.defineProperties({},{canGoBack:{enumerable:!0,get:()=>P.current.getSnapshot().canGoBack},stack:{enumerable:!0,get:()=>P.current.getSnapshot().stack},currentRoute:{enumerable:!0,get:()=>P.current.getSnapshot().currentRoute}}));const Le=e.useMemo(()=>Object.assign(Ie.current,$e),[$e]);e.useLayoutEffect(()=>{const a=L.current;if(L.current=null,D.current?.cancel?.(),D.current=null,_.current?.querySelectorAll("[data-pmn-outgoing]").forEach(ee=>ee.remove()),!me||!ae.enabled||!a||!_.current||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const w=_.current;a.removeAttribute("hidden"),a.removeAttribute("tabindex"),a.setAttribute("aria-hidden","true"),a.setAttribute("inert",""),a.dataset.pmnOutgoing="true",a.querySelectorAll("[id]").forEach(ee=>ee.removeAttribute("id")),a.querySelectorAll("[autofocus]").forEach(ee=>ee.removeAttribute("autofocus")),a.style.cssText+=";position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none;overflow:hidden;background:var(--pmn-body);",w.appendChild(a);const q=ae.direction==="back"?1:-1,$=[...w.querySelectorAll("[data-modal-route-key]")].find(ee=>ee.dataset.modalRouteKey===G);$&&($.style.zIndex="2");const X=()=>{a.remove(),$&&($.style.zIndex=""),D.current===U&&(D.current=null)};let U;if(a.animate)U=a.animate([{opacity:1,transform:"translate3d(0,0,0)"},{opacity:1,transform:`translate3d(${q*100}%,0,0)`}],{duration:ae.duration,easing:"cubic-bezier(.22,1,.36,1)",fill:"forwards"}),U.addEventListener("finish",X,{once:!0}),U.addEventListener("cancel",X,{once:!0}),D.current=U;else{a.classList.add("pmn-page-exit",`pmn-page-exit-${ae.direction}`),a.style.setProperty("--pmn-page-duration",`${ae.duration}ms`),a.style.setProperty("--pmn-page-distance","100%");const ee=setTimeout(X,ae.duration+40);U={cancel:()=>{clearTimeout(ee),X()}},D.current=U}return()=>{U?.cancel?.(),a.remove()}},[G]),e.useLayoutEffect(()=>{V.current=!1;const a=[...H.current?.querySelectorAll("[data-modal-route-key]")??[]].find($=>$.dataset.modalRouteKey===G);if(!a)return;const w=M.current.get(G);(w?.isConnected&&a.contains(w)&&!w.matches(":disabled")&&!w.closest("[inert], [hidden]")?w:a).focus({preventScroll:!0})},[G]),e.useEffect(()=>{let a=!1;for(const[q,$]of Re.current)$.owner!=="global"&&$.owner!==G&&(Re.current.delete(q),a=!0);a&&we();const w=new Set(c.map(q=>q.key));b(q=>{const $=Object.keys(q).filter(U=>!w.has(U));if(!$.length)return q;const X={...q};return $.forEach(U=>delete X[U]),X});for(const q of M.current.keys())w.has(q)||M.current.delete(q)},[G,c,we]),e.useEffect(()=>{if(T.current?.key!==G){if(T.current){const a={from:T.current,to:C,stack:c};Q("onBlur",{route:T.current,...a}),Q("onNavigate",a),Q("onRouteChange",a)}Q("onFocus",{route:C,stack:c}),T.current=C}},[C,G,c,Q]),e.useEffect(()=>()=>{Re.current.clear(),M.current.clear();for(const a of ne.current.values())a.resolve({status:"dismissed"});ne.current.clear()},[]),e.useEffect(()=>{le.current||(le.current=!0,p?.({route:C,stack:c}))},[]);const Et=e.useMemo(()=>Tt(c,l,r.maxCachedScreens),[c,l,r.maxCachedScreens]),et=e.useMemo(()=>({...l[C.name],...C.options??{}}),[l,C.name,C.options]);return s.jsx(We.Provider,{value:F,children:s.jsx(ut.Provider,{value:K.current,children:s.jsx(lt.Provider,{value:A.current,children:s.jsx(it.Provider,{value:Le,children:s.jsx(qe.Provider,{value:$e,children:s.jsx(Oe.Provider,{value:P.current,children:s.jsx(xe.Provider,{value:pe,children:s.jsxs(pt,{dialogRef:H,options:r,requestClose:Ee,exiting:m,children:[s.jsx(ft,{options:r,screen:et,route:C,navigation:Le,requestClose:Ee,translate:i,canGoBack:c.length>1}),s.jsx("main",{ref:_,className:"pmn-main",children:Et.map(a=>s.jsx(zt,{route:a,screen:l[a.name],navigation:Le,focused:a.key===G,resultEvent:j[a.key]??null,bodyClassName:r.bodyClassName,setFooter:R,loadingApi:pe,loadingStore:I.current,notifyError:u,registerDirtyGuard:k,pageMotion:ae,lazyFallback:r.lazyFallback},a.key))}),s.jsx(Ft,{store:A.current,routeKey:G,screen:et,options:r,route:C,navigation:Le,requestClose:Ee,translate:i,onError:u,loadingApi:pe},G),s.jsx(qt,{store:I.current,translate:i}),s.jsx(Ot,{store:K.current,dismiss:O}),x&&s.jsxs("div",{className:"pmn-error",role:"alert",children:[s.jsx("span",{children:x.message||String(x)}),s.jsx("button",{type:"button",onClick:S,"aria-label":"Dismiss error",children:"×"})]})]})})})})})})})})}const $t=e.memo(function({store:n,route:o,...r}){const i=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(gt,{...r,route:o,override:i[o.key]})}),It=e.memo(function({store:n,translate:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(ht,{loading:r,translate:o})}),Dt=e.memo(function({store:n,dismiss:o}){const r=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return s.jsx(yt,{items:r,dismiss:o})});function Kt({config:t,initialScreen:n,params:o,options:r,translate:i,onRequestClose:g,onOpened:p,registerLoading:f,notifyError:u,error:x,clearError:S,registerDirtyGuard:k,exiting:d=!1}){const m=n??t.initialRoute??Object.keys(t.screens)[0],[c,E]=e.useState(()=>({key:"single",name:m,params:o??{},options:{}})),P=e.useRef(c);P.current=c;const I=t.screens[m],A=e.useRef(!0),K=e.useRef(null),v=e.useRef(null),B=e.useRef(null),F=e.useRef(null),O=e.useRef(null);v.current||(v.current=dt({canGoBack:!1,stack:[c],currentRoute:c})),B.current||(B.current=ye({})),F.current||(F.current=ye({visible:!1,text:null,count:0})),O.current||(O.current=ye([]));const j=e.useRef("single"),{loadingApi:b,setLoading:M}=vt(F,A,j),{toast:H,dismissToast:_}=xt(O,A),L=e.useCallback((y,C)=>{const G=B.current,oe=G.getSnapshot();if(C===null){if(oe[y]!==void 0){const ie={...oe};delete ie[y],G.publish(ie)}}else oe[y]!==C&&G.publish({...oe,[y]:C})},[]),D=e.useCallback((y="api",C)=>g(y,C),[g]),T=e.useCallback(()=>Promise.resolve(!1),[]),V=e.useMemo(()=>({navigate:T,navigateAsync:async()=>({status:"cancelled"}),replace:T,reset:T,goBack:T,popToTop:T,popTo:T,setParams:y=>(E(C=>({...C,params:{...C.params,...typeof y=="function"?y(C.params):y}})),!0),setOptions:y=>(E(C=>({...C,options:{...C.options,...y}})),!0),close:D,setLoading:M,canGoBack:!1,stack:[c],currentRoute:c}),[D,c,M,T]),z=e.useRef(V);z.current=V;const ne=e.useMemo(()=>({navigate:(...y)=>z.current.navigate(...y),navigateAsync:(...y)=>z.current.navigateAsync(...y),replace:(...y)=>z.current.replace(...y),reset:(...y)=>z.current.reset(...y),goBack:(...y)=>z.current.goBack(...y),popToTop:(...y)=>z.current.popToTop(...y),popTo:(...y)=>z.current.popTo(...y),setParams:(...y)=>z.current.setParams(...y),setOptions:(...y)=>z.current.setOptions(...y),close:(...y)=>z.current.close(...y),setLoading:(...y)=>z.current.setLoading(...y)}),[]),te=e.useMemo(()=>({setLoading:(y,C)=>b.setScreenLoading("single",y,C),showLoading:y=>b.begin("single",y),hideLoading:y=>b.end("single",y)}),[b]),ce=e.useMemo(()=>({isFocused:!0,resultEvent:null,routeKey:"single",setFooter:L}),[L]),W=e.useMemo(()=>({routeKey:"single",registerDirtyGuard:k}),[k]);e.useEffect(()=>{v.current.publish({canGoBack:!1,stack:[c],currentRoute:c})},[c]),e.useEffect(()=>(A.current=!0,f?.({setLoading:M}),p?.({route:P.current,stack:[P.current]}),()=>{A.current=!1}),[]);const re={...I,...c.options},le=I.component;return s.jsx(We.Provider,{value:H,children:s.jsx(ut.Provider,{value:O.current,children:s.jsx(lt.Provider,{value:B.current,children:s.jsx(it.Provider,{value:V,children:s.jsx(qe.Provider,{value:ne,children:s.jsx(Oe.Provider,{value:v.current,children:s.jsx(xe.Provider,{value:b,children:s.jsxs(pt,{dialogRef:K,options:r,requestClose:D,exiting:d,children:[s.jsx(ft,{options:r,screen:re,route:c,navigation:V,requestClose:D,translate:i,canGoBack:!1}),s.jsx("main",{className:"pmn-main",children:s.jsx(Ye.Provider,{value:c,children:s.jsx(Ue.Provider,{value:W,children:s.jsx(Ne.Provider,{value:ce,children:s.jsx(xe.Provider,{value:te,children:s.jsx(Fe.Provider,{value:F.current,children:s.jsx("div",{className:`pmn-body ${r.bodyClassName??""}`,"data-modal-route-key":"single",tabIndex:-1,children:s.jsx(bt,{route:c,onError:u,children:s.jsx(e.Suspense,{fallback:r.lazyFallback??s.jsx("div",{className:"pmn-lazy-loading",role:"status","aria-live":"polite",children:"加载中..."}),children:s.jsx(le,{route:c,navigation:V})})})})})})})})})}),s.jsx($t,{store:B.current,route:c,screen:re,options:r,navigation:V,requestClose:D,translate:i,onError:u,loadingApi:b}),s.jsx(It,{store:F.current,translate:i}),s.jsx(Dt,{store:O.current,dismiss:_}),x&&s.jsxs("div",{className:"pmn-error",role:"alert",children:[s.jsx("span",{children:x.message||String(x)}),s.jsx("button",{type:"button",onClick:S,children:"×"})]})]})})})})})})})})}const Gt=".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))}",at="react-modal-navigation-styles",He=new WeakMap;function Ht(){e.useInsertionEffect(()=>{if(typeof document>"u")return;const t=document;let n=He.get(t);if(!n){let o=t.getElementById(at);const r=!o;o||(o=t.createElement("style"),o.id=at,o.setAttribute("data-react-modal-navigation",""),o.textContent=Gt,t.head.appendChild(o)),n={element:o,owned:r,count:0},He.set(t,n)}return n.count+=1,()=>{n.count-=1,n.count===0&&(n.owned&&n.element.remove(),He.delete(t))}},[])}function Be(t,n,o){if(typeof t=="string"){if(!t.trim())throw new TypeError("[react-modal-navigation] modal name must not be empty");return{name:t,params:n??{},options:o??{}}}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("[react-modal-navigation] open expects a modal name or a configuration object");const{name:r,screen:i,params:g={},options:p={},...f}=t;if(typeof r!="string"||!r.trim())throw new TypeError("[react-modal-navigation] open config requires a non-empty string name");if(p===null||typeof p!="object"||Array.isArray(p))throw new TypeError("[react-modal-navigation] open config options must be an object");if(i!==void 0&&(typeof i!="string"||!i.trim()))throw new TypeError("[react-modal-navigation] screen must be a non-empty string");return{name:r,...i===void 0?{}:{screen:i},params:g,options:{...f,...p}}}function _t(){const t=new Map;return{wait(n){return new Promise(o=>{const r=setTimeout(()=>{t.delete(r),o()},Math.max(0,n));t.set(r,o)})},cancelAll(){for(const[n,o]of t)clearTimeout(n),o();t.clear()},pendingCount:()=>t.size}}const Ut={placement:"right",showHeader:!0,showBackButton:!0,showCloseButton:!0,viewportGap:5,borderRadius:12,closeOnOverlay:!1,closeOnEsc:!0},Wt=t=>({"modal.loading":"加载中...","modal.processing":"处理中...","modal.back":"返回","modal.close":"关闭","modal.cancel":"取消","modal.done":"完成"})[t]??t;function Yt({registry:t,children:n,defaultOptions:o={},backgroundColor:r,theme:i,translate:g=Wt,onError:p,confirmDiscard:f}){Ht();const[u,x]=e.useState(null),[S,k]=e.useState(null),[d,m]=e.useState(0),c=e.useRef(null),E=e.useRef(new Map),P=e.useRef([]),I=e.useRef(null),A=e.useRef(null),K=e.useRef(0),v=e.useRef(null),B=e.useRef(!1),F=e.useRef(0),O=e.useRef(null),j=e.useRef(new Map),[b,M]=e.useState(!1),H=e.useRef(f);H.current=f;const _=e.useCallback((l,h)=>(j.current.set(l,h),()=>{j.current.get(l)===h&&j.current.delete(l)}),[]),L=e.useCallback(async l=>{for(const h of j.current.values()){if(!h.dirty)continue;if((h.onBeforeDiscard?await h.onBeforeDiscard(l):H.current?await H.current(l):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(h.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),D=e.useCallback(async(l,h)=>{for(const N of l){const R=j.current.get(N);if(!R?.dirty)continue;if((R.onBeforeDiscard?await R.onBeforeDiscard(h):H.current?await H.current(h):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(R.message||"有未保存的修改,确定放弃吗?"):!1)===!1)return!1}return!0},[]),T=e.useRef(!0),V=e.useRef(null);V.current||(V.current=_t());const z=e.useRef(null),ne=e.useRef(p);ne.current=p;const te=e.useCallback((l,h)=>{T.current&&k(l);try{ne.current?ne.current(l,h):console.error("[react-modal-navigation]",l)}catch(N){console.error("[react-modal-navigation] onError failed",N)}},[]),ce=e.useCallback((l,h)=>{const N=E.current.get(l);E.current.delete(l),N?.(h)},[]),W=e.useCallback(l=>({...Ut,...o,...i!==void 0?{theme:i}:{},...r!==void 0?{backgroundColor:r}:{},...l.config.modalOptions,...l.overrides}),[o,i,r]),re=u?W(u):null,le=e.useRef(null);le.current=re,z.current=re;const y=e.useCallback(async(l="api",h,N={})=>{const R=c.current;if(!R||v.current||B.current)return!1;v.current=R.id,B.current=!0;const Z=z.current??W(R),Y={...N,reason:l,result:h,name:R.name};try{if(!await L(Y)||await Z.onBeforeClose?.(Y)===!1||c.current?.id!==R.id||!T.current)return!1;M(!0);const Q=Z.animation===!1||typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?0:Math.max(0,Number(Z.animationDuration??220)||0);if(await V.current.wait(Math.min(Q,1e3)),!T.current||c.current?.id!==R.id)return!1;c.current=null,O.current=null,x(null),M(!1),j.current.clear(),ce(R.id,N.confirmed||h!==void 0?{status:"confirmed",value:h,reason:l}:{status:"dismissed",reason:l});try{await Z.onClose?.(Y)}catch(J){te(J,{phase:"onClose",name:R.name})}return!0}catch(Q){return te(Q,{phase:"onBeforeClose",name:R.name}),!1}finally{v.current===R.id&&(v.current=null),B.current=!1,!c.current&&T.current&&queueMicrotask(()=>A.current?.())}},[W,te,ce,L]),C=e.useCallback(async(l,h={},N={},R,Z)=>{const Y=t?.[l],Q=Y?.component&&!Y.screens?{...Y,singlePage:!0,initialRoute:"__single__",screens:{__single__:{component:Y.component,title:Y.title,...Y.screenOptions??{}}}}:Y;if(!Q)throw new Error(`[react-modal-navigation] Unknown modal: ${l}`);const J=Z??Q.initialRoute??Object.keys(Q.screens??{})[0];if(!Q.screens?.[J])throw new Error(`[react-modal-navigation] Unknown initial screen '${J}' in modal '${l}'`);if(!T.current||B.current||v.current)return null;B.current=!0;const Ce=F.current;try{const se=c.current;if(se){const Se=z.current??W(se),ge={reason:"replace",name:se.name,nextName:l};try{if(!await L(ge)||await Se.onBeforeClose?.(ge)===!1)return null}catch(he){return te(he,{phase:"onBeforeClose",name:se.name}),null}if(!T.current||Ce!==F.current||c.current?.id!==se.id)return null;c.current=null,O.current=null,x(null),j.current.clear(),ce(se.id,{status:"replaced",reason:"replace"});try{await Se.onClose?.(ge)}catch(he){te(he,{phase:"onClose",name:se.name})}if(!T.current||Ce!==F.current)return null}const ue={id:++K.current,name:l,screen:J,params:h,config:Q,overrides:N};return c.current=ue,O.current=null,R&&E.current.set(ue.id,R),k(null),x(ue),ue.id}finally{B.current=!1}},[t,W,te,ce,L]);I.current=C;const G=e.useCallback(async()=>{if(!T.current||c.current||B.current||v.current)return;const l=P.current.shift();if(l){m(P.current.length);try{const h=await I.current(l.args.name,l.args.params,l.args.options,l.resolveResult,l.args.screen);h===null?(l.resolveResult?.({status:"dismissed",reason:"blocked"}),l.resolveId?.(null),queueMicrotask(()=>A.current?.())):l.resolveId?.(h)}catch(h){l.reject?.(h),queueMicrotask(()=>A.current?.())}}},[]);A.current=G;const oe=e.useCallback((l,h,N)=>{const R=Be(l,h,N);return t?.[R.name]?new Promise((Z,Y)=>{P.current.push({args:R,resolveId:Z,reject:Y}),m(P.current.length),queueMicrotask(()=>A.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${R.name}`))},[t]),ie=e.useCallback((l,h,N)=>{const R=Be(l,h,N);return t?.[R.name]?new Promise((Z,Y)=>{P.current.push({args:R,resolveResult:Z,reject:Y}),m(P.current.length),queueMicrotask(()=>A.current?.())}):Promise.reject(new Error(`[react-modal-navigation] Unknown modal: ${R.name}`))},[t]),me=e.useCallback(l=>{if(!l||typeof l!="object"||Array.isArray(l))throw new TypeError("[react-modal-navigation] update expects an options object");const h=c.current;if(!h||B.current)return!1;const N={...h,overrides:{...h.overrides,...l}};return c.current=N,x(N),z.current=W(N),!0},[W]),Pe=e.useCallback((l="queue-cleared")=>{const h=P.current.splice(0);m(0);for(const N of h)N.resolveId?.(null),N.resolveResult?.({status:"dismissed",reason:l});return h.length},[]),ve=e.useCallback((l,h,N)=>{const R=Be(l,h,N);return C(R.name,R.params,R.options,void 0,R.screen)},[C]),ze=e.useCallback((l,h,N)=>{const R=Be(l,h,N);return new Promise((Z,Y)=>{C(R.name,R.params,R.options,Z,R.screen).then(Q=>{Q===null&&Z({status:"dismissed",reason:"blocked"})},Y)})},[C]),ae=e.useCallback(l=>y("api",l),[y]),ke=e.useCallback((l="api")=>y(l),[y]),pe=e.useCallback(l=>y("confirm",l,{confirmed:!0}),[y]),we=e.useCallback((l,h)=>O.current?.setLoading(l,h),[]),Re=e.useMemo(()=>({open:ve,openAsync:ze,enqueue:oe,enqueueAsync:ie,update:me,clearQueue:Pe,close:ae,dismiss:ke,confirm:pe,setLoading:we,queueSize:d,isOpen:!!u,activeName:u?.name??null,error:S,clearError:()=>k(null)}),[ve,ze,oe,ie,me,Pe,ae,ke,pe,we,u,S,d]);e.useEffect(()=>(T.current=!0,()=>{T.current=!1,V.current.cancelAll(),F.current+=1,c.current=null;for(const h of E.current.values())h({status:"dismissed",reason:"unmount"});E.current.clear(),j.current.clear();const l=P.current.splice(0);for(const h of l)h.resolveId?.(null),h.resolveResult?.({status:"dismissed",reason:"unmount"})}),[]);const fe=u?.config.singlePage||u&&Object.keys(u.config.screens??{}).length===1?Kt:kt;return s.jsxs(ct.Provider,{value:Re,children:[n,u&&s.jsx(fe,{config:u.config,initialScreen:u.screen,params:u.params,options:re,translate:g,notifyError:te,error:S,clearError:()=>k(null),registerLoading:l=>{O.current=l},registerDirtyGuard:_,canNavigate:D,exiting:b,onRequestClose:y,onOpened:l=>{try{const h=le.current?.onOpen?.(l);Promise.resolve(h).catch(N=>te(N,{phase:"onOpen"}))}catch(h){te(h,{phase:"onOpen"})}}},u.id)]})}const Vt=Object.freeze({canGoBack:!1,stack:[],currentRoute:null}),Zt=()=>()=>{},st=()=>Vt;function Qt(){const t=e.useContext(ct),n=e.useContext(qe),o=e.useContext(Oe),r=e.useSyncExternalStore(o?.subscribe??Zt,o?.getSnapshot??st,o?.getSnapshot??st);if(!t)throw new Error("[react-modal-navigation] useModal requires <ModalProvider>");const i=e.useMemo(()=>{const g=()=>{if(!n)throw new Error("[react-modal-navigation] navigation requires an active modal screen; use modal.open() outside a modal");return n};return{navigate:(...p)=>g().navigate(...p),replace:(...p)=>g().replace(...p),reset:(...p)=>g().reset(...p),setParams:(...p)=>g().setParams(...p),setOptions:(...p)=>g().setOptions(...p),goBack:(...p)=>g().goBack(...p),close:(...p)=>g().close(...p),setLoading:(...p)=>g().setLoading(...p),canGoBack:r.canGoBack,stack:r.stack,currentRoute:r.currentRoute}},[n,r]);return e.useMemo(()=>({...t,modal:t,navigation:i}),[t,i])}function wt(){const t=e.useContext(qe);if(!t)throw new Error("useModalNavigationCommands requires an active modal screen");return t}function Rt(){const t=e.useContext(Oe);if(!t)throw new Error("useModalNavigationState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function Jt(){const t=wt(),n=Rt();return e.useMemo(()=>({...t,...n}),[t,n])}function Ve(){const t=e.useContext(Ne);if(!t)throw new Error("useIsFocused must be called inside a modal screen");return t.isFocused}function Xt(t){const n=Ve();e.useEffect(()=>{if(n)return t()},[n,t])}function en(t){const n=e.useContext(Ne);if(!n)throw new Error("useNavigationResult requires an active modal screen");const o=e.useRef(t),r=e.useRef(null);e.useEffect(()=>{o.current=t},[t]),e.useEffect(()=>{!n.isFocused||!n.resultEvent||r.current!==n.resultEvent.id&&(r.current=n.resultEvent.id,o.current(n.resultEvent.data))},[n.isFocused,n.resultEvent])}function tn(t={}){const n=e.useContext(Ne);if(!n)throw new Error("[react-modal-navigation] useModalFooter requires an active modal screen");const{setFooter:o,routeKey:r}=n,i=e.useRef(t);i.current=t;const g=e.useMemo(()=>(...j)=>i.current.done?.(...j),[]),p=e.useMemo(()=>(...j)=>(i.current.cancel??i.current.cancle)?.(...j),[]),f=e.useMemo(()=>(...j)=>i.current.renderFooter?.(...j),[]),u=typeof t.done=="function",x=typeof(t.cancel??t.cancle)=="function",S=typeof t.renderFooter=="function",{showFooter:k,showFooterBorder:d,doneDisabled:m,doneText:c,cancelText:E,loadingText:P,footerClassName:I}=t,A=e.useRef({source:null,normalized:void 0}),K=Array.isArray(t.actions)?t.actions:null,v=A.current.source;K===v||K&&v&&K.length===v.length&&K.every((j,b)=>{const M=v[b];return[...new Set([...Object.keys(j),...Object.keys(M)])].every(_=>_==="onClick"||Object.is(j[_],M[_]))})||(A.current={source:K?.map(j=>({...j}))??null,normalized:K?.map((j,b)=>({...j,onClick:(...M)=>(i.current.actions?.find(_=>_.key===j.key)??i.current.actions?.[b])?.onClick?.(...M)}))});const F=A.current.normalized,O=e.useMemo(()=>({showFooter:k,showFooterBorder:d,doneDisabled:m,doneText:c,cancelText:E,loadingText:P,footerClassName:I,...F!==void 0?{actions:F}:{},...u?{done:g}:{},...x?{cancel:p}:{},...S?{renderFooter:f}:{}}),[k,d,m,c,E,P,I,F,u,x,S,g,p,f]);e.useEffect(()=>{o(r,O)},[r,o,O]),e.useEffect(()=>()=>o(r,null),[r,o])}function Ct(){const t=e.useContext(xe),n=e.useContext(Fe);if(!t||!n)throw new Error("[react-modal-navigation] useModalLoading requires an active modal screen");const o=e.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return e.useMemo(()=>({...t,isLoading:o.visible}),[t,o.visible])}function nn(){const t=e.useContext(xe);if(!t)throw new Error("[react-modal-navigation] useModalLoadingCommands requires an active modal screen");return t}function rn(){const t=e.useContext(Fe);if(!t)throw new Error("[react-modal-navigation] useModalLoadingState requires an active modal screen");return e.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)}function on(){const t=Ct(),n=Ve(),o=e.useRef(!0),r=e.useRef(!1),[i,g]=e.useState(!1),[p,f]=e.useState(null),u=e.useRef(t);return u.current=t,e.useEffect(()=>(o.current=!0,()=>{o.current=!1}),[]),{run:e.useCallback(async(S,k={})=>{if(r.current)return{status:"busy"};if(typeof S!="function")throw new TypeError("[react-modal-navigation] run requires a function");r.current=!0,o.current&&(g(!0),f(null));const d=u.current.showLoading(k.loadingText);try{const m=await S();return o.current&&await k.onSuccess?.(m),{status:"success",value:m}}catch(m){if(o.current){f(m);try{await k.onError?.(m)}catch(c){console.error("[react-modal-navigation] onError failed",c)}}if(k.throwOnError)throw m;return{status:"error",error:m}}finally{d!=null&&u.current.hideLoading(d),r.current=!1,o.current&&g(!1)}},[]),pending:i,error:p,clearError:()=>f(null),isFocused:n}}function an(t,n={}){const o=e.useContext(Ue);if(!o)throw new Error("[react-modal-navigation] useModalUnsavedChanges must be used inside a modal screen");const r=e.useRef({dirty:t,...n});r.current={dirty:t,...n};const{routeKey:i,registerDirtyGuard:g}=o;e.useEffect(()=>g(i,{get dirty(){return!!r.current.dirty},get message(){return r.current.message},get onBeforeDiscard(){return r.current.onBeforeDiscard}}),[i,g])}const sn=()=>{const t=e.useContext(We);if(!t)throw new Error("[react-modal-navigation] useToast requires an active modal");return t};function St(){const t=e.useContext(Ye);if(!t)throw new Error("[react-modal-navigation] useModalRoute requires a modal screen");return t}function cn(){return St().params}exports.ModalNavigator=kt;exports.ModalProvider=Yt;exports.useFocusEffect=Xt;exports.useIsFocused=Ve;exports.useModal=Qt;exports.useModalFooter=tn;exports.useModalLoading=Ct;exports.useModalLoadingCommands=nn;exports.useModalLoadingState=rn;exports.useModalNavigation=Jt;exports.useModalNavigationCommands=wt;exports.useModalNavigationState=Rt;exports.useModalParams=cn;exports.useModalRoute=St;exports.useModalTask=on;exports.useModalUnsavedChanges=an;exports.useNavigationResult=en;exports.useToast=sn;
package/dist/index.d.ts CHANGED
@@ -58,8 +58,18 @@ export interface ModalOptions {
58
58
  animation?: boolean;
59
59
  /** Animation duration in ms (default 220, maximum effective 1000). */
60
60
  animationDuration?: number;
61
+ /** Animate route changes inside the modal; default true. */
62
+ pageAnimation?: boolean;
63
+ /** Internal route animation duration in milliseconds; default 240. */
64
+ pageAnimationDuration?: number;
65
+ /** Slide distance in pixels (0–300, default 96). */
66
+ pageAnimationDistance?: number;
61
67
  /** Position: centered modal, side drawer, or top/bottom sheet. Default: right. */
62
68
  placement?: 'left' | 'right' | 'center' | 'top' | 'bottom';
69
+ /** Offset from the viewport top for placement='top' (pixels or CSS length). */
70
+ top?: number | string;
71
+ /** Suspense fallback rendered while a React.lazy modal screen loads. */
72
+ lazyFallback?: React.ReactNode;
63
73
  theme?: ModalTheme;
64
74
  backgroundColor?: ModalBackground;
65
75
  /** @deprecated Use backgroundColor */
@@ -113,7 +123,18 @@ export interface ModalScreen extends ModalOptions {
113
123
  component: ComponentType<any>;
114
124
  title?: string | ((context: { t: (key: string) => string; route: ModalRoute; navigation: ModalNavigation }) => ReactNode);
115
125
  }
116
- export interface ModalRegistryItem { initialRoute: string; modalOptions?: ModalOptions; screens: Record<string, ModalScreen> }
126
+ export interface MultiPageModalRegistryItem { initialRoute: string; modalOptions?: ModalOptions; screens: Record<string, ModalScreen>; singlePage?: false }
127
+ /** Single-page mode skips navigation history, reducer and page transition effects. */
128
+ export interface SinglePageModalRegistryItem {
129
+ component: React.ComponentType<any>;
130
+ title?: string;
131
+ screenOptions?: ModalScreenOptions;
132
+ modalOptions?: ModalOptions;
133
+ singlePage?: true;
134
+ }
135
+ /** A one-entry screens registry is also automatically rendered in single-page mode. */
136
+ export interface OneScreenModalRegistryItem { initialRoute?: string; modalOptions?: ModalOptions; screens: Record<string, ModalScreen>; singlePage?: boolean }
137
+ export type ModalRegistryItem = MultiPageModalRegistryItem | SinglePageModalRegistryItem | OneScreenModalRegistryItem;
117
138
  export type ModalRegistry = Record<string, ModalRegistryItem>;
118
139
  export interface ModalProviderProps {
119
140
  registry: ModalRegistry;