UNPKG

@huxy/router

Version:
109 lines (108 loc) 22.7 kB
import{Suspense as Qt,default as Zt,useCallback as P,useEffect as k,useRef as $,useState as L}from"react";var Kt={51(t){function e(n){var s=document.createElement("style");return n.setAttributes(s,n.attributes),n.insert(s,n.options),s}t.exports=e},85(t,e,n){t.exports=n(197)},128(t){var e={};function n(r){if(typeof e[r]>"u"){var c=document.querySelector(r);if(window.HTMLIFrameElement&&c instanceof window.HTMLIFrameElement)try{c=c.contentDocument.head}catch{c=null}e[r]=c}return e[r]}function s(r,c){var o=n(r);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(c)}t.exports=s},197(t,e){var n;var s=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function c(o,a,u){var l=null;if(u!==void 0&&(l=""+u),a.key!==void 0&&(l=""+a.key),"key"in a){u={};for(var i in a)i!=="key"&&(u[i]=a[i])}else u=a;return a=u.ref,{$$typeof:s,type:o,key:l,ref:a!==void 0?a:null,props:u}}n=r,e.jsx=c,e.jsxs=c},591(t){var e=[];function n(c){for(var o=-1,a=0;a<e.length;a++)if(e[a].identifier===c){o=a;break}return o}function s(c,o){for(var a={},u=[],l=0;l<c.length;l++){var i=c[l],p=o.base?i[0]+o.base:i[0],h=a[p]||0,f="".concat(p," ").concat(h);a[p]=h+1;var d=n(f),g={css:i[1],media:i[2],sourceMap:i[3],supports:i[4],layer:i[5]};if(d!==-1)e[d].references++,e[d].updater(g);else{var _=r(g,o);o.byIndex=l,e.splice(l,0,{identifier:f,updater:_,references:1})}u.push(f)}return u}function r(c,o){var a=o.domAPI(o);a.update(c);var u=function(i){if(i){if(i.css===c.css&&i.media===c.media&&i.sourceMap===c.sourceMap&&i.supports===c.supports&&i.layer===c.layer)return;a.update(c=i)}else a.remove()};return u}t.exports=function(c,o){o=o||{},c=c||[];var a=s(c,o);return function(l){l=l||[];for(var i=0;i<a.length;i++){var p=a[i],h=n(p);e[h].references--}for(var f=s(l,o),d=0;d<a.length;d++){var g=a[d],_=n(g);e[_].references===0&&(e[_].updater(),e.splice(_,1))}a=f}}},656(t){function e(n,s){if(s.styleSheet)s.styleSheet.cssText=n;else{for(;s.firstChild;)s.removeChild(s.firstChild);s.appendChild(document.createTextNode(n))}}t.exports=e},670(t,e,n){n.d(e,{A:()=>u});var s=n(758),r=n.n(s),c=n(935),o=n.n(c),a=o()(r());a.push([t.id,`@keyframes before { 0% { width: 0.6rem; box-shadow: 1.2rem -0.6rem #ff3e38, -1.2rem 0.6rem #318ffa; } 35% { width: 3rem; box-shadow: 0 -0.6rem #ff3e38, 0 0.6rem #318ffa; } 70% { width: 0.6rem; box-shadow: -1.2rem -0.6rem #ff3e38, 1.2rem 0.6rem #318ffa; } 100% { box-shadow: 1.2rem -0.6rem #ff3e38, -1.2rem 0.6rem #318ffa; } } @keyframes after { 0% { height: 0.6rem; box-shadow: 0.6rem 1.2rem #6ce581, -0.6rem -1.2rem #fecb2e; } 35% { height: 3rem; box-shadow: 0.6rem 0 #6ce581, -0.6rem 0 #fecb2e; } 70% { height: 0.6rem; box-shadow: 0.6rem -1.2rem #6ce581, -0.6rem 1.2rem #fecb2e; } 100% { box-shadow: 0.6rem 1.2rem #6ce581, -0.6rem -1.2rem #fecb2e; } } .spinner { position: relative; height: 100%; min-height: 100px; display: block; overflow: hidden; pointer-events: auto; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: hsla(0, 0%, 72%, 0.24); } .spinner.absolute { position: absolute; min-height: auto; } .spinner.global { position: fixed; width: 100vw; height: 100vh; } .spinner .spinning { width: 3rem; height: 3rem; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(165deg); margin: 0; } .spinner .spinning::before, .spinner .spinning::after { content: ''; position: absolute; top: 50%; left: 50%; display: block; width: 0.6rem; height: 0.6rem; border-radius: 0.3rem; transform: translate(-50%, -50%); } .spinner .spinning::before { animation: before 1.5s infinite; } .spinner .spinning::after { animation: after 1.5s infinite; } `,""]);const u=a},740(t){function e(r,c,o){var a="";o.supports&&(a+="@supports (".concat(o.supports,") {")),o.media&&(a+="@media ".concat(o.media," {"));var u=typeof o.layer<"u";u&&(a+="@layer".concat(o.layer.length>0?" ".concat(o.layer):""," {")),a+=o.css,u&&(a+="}"),o.media&&(a+="}"),o.supports&&(a+="}");var l=o.sourceMap;l&&typeof btoa<"u"&&(a+=` /*# sourceMappingURL=data:application/json;base64,`.concat(btoa(unescape(encodeURIComponent(JSON.stringify(l))))," */")),c.styleTagTransform(a,r,c.options)}function n(r){if(r.parentNode===null)return!1;r.parentNode.removeChild(r)}function s(r){if(typeof document>"u")return{update:function(){},remove:function(){}};var c=r.insertStyleElement(r);return{update:function(a){e(c,r,a)},remove:function(){n(c)}}}t.exports=s},758(t){t.exports=function(e){return e[1]}},845(t,e,n){n.d(e,{Ay:()=>i,nf:()=>u,vu:()=>l});var s=n(758),r=n.n(s),c=n(935),o=n.n(c),a=o()(r());a.push([t.id,`.Iuy_e { text-decoration: none; cursor: pointer; color: var(--linkColor); background-color: transparent; font-weight: 500; transition: color 0.3s; } .Iuy_e:active, .Iuy_e.D3oJg { color: var(--linkActiveColor, #42a5f5); } .Iuy_e:hover { color: var(--linkHoverColor, #2196f3); } .Iuy_e[disabled] { cursor: not-allowed; opacity: 0.7; } .Iuy_e[disabled]:active, .Iuy_e[disabled].D3oJg, .Iuy_e[disabled]:hover { color: var(--linkColor); } `,""]);var u="Iuy_e",l="D3oJg";const i=a},855(t,e,n){function s(r){var c=n.nc;c&&r.setAttribute("nonce",c)}t.exports=s},935(t){t.exports=function(e){var n=[];return n.toString=function(){return this.map(function(r){var c="",o=typeof r[5]<"u";return r[4]&&(c+="@supports (".concat(r[4],") {")),r[2]&&(c+="@media ".concat(r[2]," {")),o&&(c+="@layer".concat(r[5].length>0?" ".concat(r[5]):""," {")),c+=e(r),o&&(c+="}"),r[2]&&(c+="}"),r[4]&&(c+="}"),c}).join("")},n.i=function(r,c,o,a,u){typeof r=="string"&&(r=[[null,r,void 0]]);var l={};if(o)for(var i=0;i<this.length;i++){var p=this[i][0];p!=null&&(l[p]=!0)}for(var h=0;h<r.length;h++){var f=[].concat(r[h]);o&&l[f[0]]||(typeof u<"u"&&(typeof f[5]>"u"||(f[1]="@layer".concat(f[5].length>0?" ".concat(f[5]):""," {").concat(f[1],"}")),f[5]=u),c&&(f[2]&&(f[1]="@media ".concat(f[2]," {").concat(f[1],"}")),f[2]=c),a&&(f[4]?(f[1]="@supports (".concat(f[4],") {").concat(f[1],"}"),f[4]=a):f[4]="".concat(a)),n.push(f))}},n}}},bt={};function y(t){var e=bt[t];if(e!==void 0)return e.exports;var n=bt[t]={id:t,exports:{}};return Kt[t](n,n.exports,y),n.exports}y.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return y.d(e,{a:e}),e},y.d=(t,e)=>{for(var n in e)y.o(e,n)&&!y.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},y.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),y.nc=void 0;var Sr={};const te=t=>Object.prototype.toString.call(t).slice(8,-1).toLowerCase(),tt=te,ee=t=>tt(t)==="array",M=ee,re=t=>tt(t)==="object",S=re,ne=t=>t?.$$typeof&&typeof t.$$typeof=="symbol"&&t.$$typeof.description?.indexOf("react.")===0,it=ne,se=t=>t?.__v_isVNode,oe=se,ce=(t,e)=>Object.prototype.hasOwnProperty.call(t??{},e),Ct=ce,xt=t=>{if(!M(t)&&!S(t))return t;const e=M(t)?[]:{};for(const n in t)if(Ct(t,n)){const s=t[n];e[n]=it(s)||oe(s)||typeof s!="object"?s:s!==t?xt(s):"cyclic"}else Object.setPrototypeOf(e,{[n]:t[n]});return e},J=xt,ae=t=>tt(t)==="function",lt=ae,ue=t=>tt(t)==="promise"||S(t)&&lt(t.then),V=ue,ie=(t,e=12e4,n="\u8BF7\u6C42\u8D85\u65F6\uFF01")=>{if(!V(t))return{};let s=null,r=null;return{promiseFn:new Promise((o,a)=>{s=(u="canceled")=>{clearTimeout(r),o({canceled:!0,errMsg:u})},e&&(e=typeof e!="number"?12e4:e,r=setTimeout(()=>s(n),e)),t.then(u=>{clearTimeout(r),o({result:u,errMsg:!1})}).catch(u=>{clearTimeout(r),a(u)})}),cancelFn:s}},St=ie,le=t=>t?t.charAt(t.length-1)==="/"?t.slice(0,-1):t:"",Rt=le;var b=y(85);const fe=(t,e)=>(0,b.jsx)("div",{dangerouslySetInnerHTML:{__html:t},...e}),pe=fe,de=t=>{const{error:e={},info:n=""}=t||{},{message:s,stack:r,errMsg:c}=e;let o=c||r||e.toString();o=`${o} ${n}`.replace(/\r|\n|\r\n/g,"<br/>"),o=o.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;"),o=o.replace(/\s/g,"&nbsp;");const a=s?.slice(0,120).split(". ").slice(0,2).join(". ");return(0,b.jsxs)("div",{style:{padding:"15px 20px",backgroundColor:"#fff",wordWrap:"break-word"},children:[pe(o,{style:{color:"red"}}),a&&(0,b.jsxs)("a",{style:{display:"inline-block",padding:"15px",color:"#00b4cf"},href:`https://stackoverflow.com/search?q=${a}`,target:"_blank",children:[" ","--> \u53BB\u7F51\u4E0A\u67E5\u627E\u9519\u8BEF\u539F\u56E0\uFF1F"]})]})},et=de,_e=t=>/^https?:\/\/[^\s/?.#]+\.[^\s]+/.test(t),q=_e,me=()=>{const t={};return{on:(r,c)=>{t[r]||(t[r]=[]),t[r].indexOf(c)===-1&&t[r].push(c)},emit:(r,c)=>{t[r]&&t[r].map(o=>o(c))},off:(r,c=null)=>{if(t[r]){if(typeof c!="function")return delete t[r];const o=t[r].indexOf(c);o>-1&&(t[r].splice(o,1),t[r].length||delete t[r])}}}},Y=me,Pt=t=>{const e={};for(let n in t)Ct(t,n)||(e[n]=t[n]);return e},he=(t,e)=>{if(!S(t))return e;if(!S(e))return t;const n={...Pt(t),...Pt(e)},s={...t,...e};return Object.keys(n).map(r=>{Object.setPrototypeOf(s,{[r]:n[r]})}),s},ge=he,ve=(t=Y())=>{const{on:e,emit:n,off:s}=t,r={};return{getState:l=>J(r[l]),setState:(l,i=!1)=>{if(typeof l=="function"&&(l=l(J(r))),!S(l))throw TypeError("\u5FC5\u987B\u4F20\u5165object\u5BF9\u8C61\uFF01");const p=J(l);Object.keys(p).map(h=>{const f=r[h],d=p[h],g=S(d)&&S(f)?ge(f,d):d;!i&&n(h,g),r[h]=g})},subscribe:(l,i)=>(e(l,i),()=>s(l,i)),unsubscribe:s,clean:l=>{typeof l=="string"?r[l]=void 0:Array.isArray(l)?l.map(i=>r[i]=void 0):Object.keys(r).map(i=>r[i]=void 0)}}},rt=ve,ye=t=>(e,n)=>{const[s,r]=L(()=>{const u=t?.getState(e);return u!==void 0?u:(n!==void 0&&t?.setState({[e]:n},!0),n)}),c=P(u=>t?.setState({[e]:typeof u=="function"?u(t?.getState(e)):u}),[]),o=P(u=>t?.subscribe(e,u),[]),a=P((u=u)=>t?.clean(u),[]);return k(()=>{t?.subscribe(e,u=>r(u))},[]),[s,c,o,a]},Ot=ye,Ee=rt(),Rr=Ot(Ee),Pr=Y(),Or=Y(),Mr="push-emitter",Tr="replace-emitter",wr="useRoute-emitter",ft={delay:8e3,timeoutMsg:"\u8BF7\u6C42\u8D85\u65F6\uFF01",cancelMsg:"\u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF01"},pt="/404",Ae={getState:()=>history.state,go:t=>history.go(t),forward:()=>history.forward(),back:()=>history.back()},Mt=(t,e,n,s,r=[])=>{const c=u=>{for(let l=0,i=u.length;l<i;l++){const p=u[l],h=p[s].split("?")[0];if(new RegExp("^"+h.replace(/:[^/]+/g,"[^/]+")+"$").test(e)&&!p.childSameRouteLevel)return p;if(M(p[n])){const d=c(p[n]);if(d)return d}}},o=c(t);if(!o)return pt;const{redirect:a}=o;return a?q(a)?a:r.includes(a)?r:(r.push(a),Mt(t,a.split("?")[0],n,s,r)):r[r.length-1]},be=(t,e,n,s,r)=>{if(!M(t))return null;const c=i=>{const p=i.split("/"),h=e.split("/"),f={};return p.map((d,g)=>d.indexOf(":")===0&&(f[d.slice(1)]=h[g])),f},o=(i,p)=>{const h=[],f=p.split("/:")[0];for(let d=0,g=i.length;d<g;d++){const _=i[d];if(_[r]===f){_.active=!0;const{name:m,title:v,icon:A,params:E}=_;h.push({name:m,title:v,icon:A,params:E,[r]:f})}else if(p.indexOf(`${_[r]}/`)===0){_.active=!0;const m=c(_[r]),v=Object.keys(m).map(T=>m[T]).join("/"),{name:A,title:E,icon:C}=_,x=v?`${f}/${v}`:_[r];h.push({name:A,title:E,icon:C,[r]:x,params:{..._.params,...m}})}else if(_[r]===p){_.active=!0;const m=c(_[r]),{[s]:v,...A}=_;h.push({...A,[r]:e,params:{...A.params,...n,...m}})}}return h},a=(i,p)=>{for(let h=0,f=i.length;h<f;h++){const d=i[h];if(p.indexOf(`${d[r]}/`)===0){d.active=!0;return}}},u=i=>{for(let p=0,h=i.length;p<h;p++){const f=i[p],d=(f[r]||"").split("?")[0];if(d===e){if(f.childSameRouteLevel){f.active=!0,f.open=!0;const{[s]:v,...A}=f;return[A,...u(f[s])]}f.hideMenu&&a(i,f.parentPath||d),f.active=!0;const{[s]:_,...m}=f;return[{...m,params:{...m.params,...n}}]}if(new RegExp("^"+d.replace(/:[^/]+/g,"[^/]+")+"$").test(e))return o(i,d);if(M(f[s])){const _=u(f[s]);if(_){f.active=!0,f.open=!0;const{[s]:m,...v}=f;return[v,..._]}}}},l=u(t)||[];return{result:t,current:l}},Tt=(t,e,n)=>t.filter(s=>s.hideMenu||s[n].indexOf("/:")>-1?!1:(M(s[e])&&(s[e]=Tt(s[e],e,n)),!0)),Ce=(t,e,n,s="children",r="path")=>{const c=Mt(t,e,s,r);if(c)return{redirect:c};const{result:o,current:a}=be(t,e,n,s,r),u=Tt(o,s,r);return{current:a,menu:u}},xe=Ce,Se=t=>M(t)&&!!t.length,wt=Se,dt=(t,e)=>t?e||t.indexOf("#/")>-1?t:`#${t}`:["#/","/"][!!e-0],z=(t,e,n,s=!1)=>{const r=dt(e,n);return s?r:n?t&&r==="/"?t:`${t}${r}`:t?`${t}/${r}`:r},Re=(t,e,n,s,r,c)=>{if(!wt(t))return t;const o=(a,u="",l=0)=>a.filter(i=>!i.denied).map(i=>{if(!c&&!i.exact&&!q(i[s])){(!i[s]||i[s]==="javascript:;")&&(i[s]="");const p=i[s].charAt(0)==="/"&&u.charAt(u.length-1)==="/"?i[s].slice(1):i[s].charAt(0)!=="/"&&u.charAt(u.length-1)!=="/"?`/${i[s]}`:i[s];i[s]=u?u+p:z(r,p,e)}if(i.redirect&&!q(i.redirect)&&(i.redirect=z(r,i.redirect,e)),wt(i[n])&&(i[n]=o(i[n],i[s],l+1),!i.redirect)){const p=i[n].findIndex(h=>h[s]===i[s]);p&&(i.redirect=i[n][0][s]),p>-1&&(i.childSameRouteLevel=l+1)}return i});return o(t)},Pe=t=>{if(!S(t))return"";const e=[];return Object.keys(t).map((n,s)=>{const r=s>0?"&":"?";e.push(`${r}${n}=${t[n]}`)}),e.join("")},Ft=Pe,Oe=(t="")=>{const[e,n]=t.split("?");if(n){const s={};return n.split("&").map(c=>{const[o,a]=c.split("=");s[o]=a}),{path:e,params:s}}return{path:e}},_t=Oe,Me=()=>{document.documentElement.scrollTop?document.documentElement.scrollTop=0:document.body.scrollTop&&(document.body.scrollTop=0)},Te=(t,e,n={})=>{const s=n.description??"";for(let r=t.length-1,c;c=t[r--];){const{title:o,name:a}=c;if(typeof o=="string"&&o.length)return document.title=o,document.getElementsByTagName("meta").description.content=`${s??""}${o}`,o;if((o==null||o===!0)&&a){const u=e?`${a}-${e}`:a;return document.title=u,document.getElementsByTagName("meta").description.content=`${s??""}${u}`,u}if(e)return document.title=e,document.getElementsByTagName("meta").description.content=`${s??""}${e}`,e}},we=t=>{const{pathname:e,search:n,hash:s}=location;if(t){const u=dt(e,t),l=decodeURIComponent(`${u}${n}`),{params:i}=_t(l);return{path:l,params:i}}const r=decodeURIComponent(dt(s,t)),{params:c}=_t(r),o=Rt(e);return{path:o?`${o}/${r}`:r,params:c}},mt=(t,e,n)=>{typeof t=="function"&&t({...e,stay:new Date-n})},$t=(t,e,n,s)=>{let r=typeof t=="string"?t:t.path??"";const c=Ft(t.query);q(r)||(r=z(n,r,s,t.exact)),window?.open(`${r}${c}`,e)},Fe=(t,e,n,s)=>{if(t.target||q(t.path)){$t(t,t.target,e,n);return}let r,c,o;if(typeof t=="string")r=t;else if(S(t))r=t.path,c=t.params,o=t.query;else return;!r||r==="."||r==="./"?r=s:r.indexOf("./")===0?r=`${s.split("?")[0]}${r.replace("./","/")}`:r.indexOf("../")===0&&(r=`${s.split("?")[0].split("/").slice(0,-1).join("/")}${r.replace("../","/")}`),r=z(e,r,n,t?.exact);const a=_t(r);r=a.path;const u={...a.params,...o},l=Ft(u);return r=`${r}${l}`,c={...c,...u},r===s?!1:{path:r,params:c}},Dt=(t,e)=>{const n=t.split(e);return n.length>1?["","/"].includes(n[1].slice(0,1)):!1},$e=Y(),De=t=>{const{on:e,emit:n,off:s}=$e;return{on:r=>e(t,r),emit:r=>n(t,r),off:r=>s(t,r)}},It=De,Ie=(t=rt())=>(e,n)=>{const{getState:s,setState:r,subscribe:c,unsubscribe:o,clean:a}=t;return n!==void 0&&r({[e]:n},!0),{getState:()=>s(e),setState:(u,l)=>r({[e]:u},l),subscribe:u=>c(e,u),unsubscribe:()=>o(e),clean:()=>a(e)}},kt=Ie,ke=rt(),Le=kt(ke),Be=Le,ht=It("push-emitter"),Lt=It("replace-emitter"),B=Be("route-store"),Bt=Y(),jt=rt(Bt),gt=kt(jt),je=Ot(jt),Ne=()=>![typeof window,typeof document].includes("undefined"),Ue=Ne,We=t=>{if(!Ue())return;const e=document.createElement("div");return e.innerHTML=t,e.children[0]},He=We;class Xe extends Zt.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,n){const{errorReport:s}=this.props;typeof s=="function"&&s({error:e,info:n.componentStack})}componentDidUpdate(e,n){n.error&&this.setState({error:null})}render(){const{error:e}=this.state,{fallback:n,children:s}=this.props;return e?n?.(e)??e:s}}const Je=({children:t,report:e})=>(0,b.jsx)(Xe,{fallback:(n,s)=>et({error:n,info:s}),errorReport:e,children:t}),Ve=Je;var qe=y(591),Nt=y.n(qe),Ye=y(740),Ut=y.n(Ye),ze=y(128),Wt=y.n(ze),Ge=y(855),Ht=y.n(Ge),Qe=y(51),Xt=y.n(Qe),Ze=y(656),Jt=y.n(Ze),nt=y(670),j={};j.styleTagTransform=Jt(),j.setAttributes=Ht(),j.insert=Wt().bind(null,"head"),j.domAPI=Ut(),j.insertStyleElement=Xt();var Fr=Nt()(nt.A,j);const $r=nt.A&&nt.A.locals?nt.A.locals:void 0,Ke=({global:t,absolute:e})=>(0,b.jsx)("div",{className:`spinner${t?" global":""}${e?" absolute":""}`,children:(0,b.jsx)("figure",{className:"spinning"})}),tr=Ke,er=()=>{const t=$([]);return k(()=>()=>{t.current.map(e=>e.cancelFn()),t.current=[]},[]),P((e,n=!0)=>{const s=St(e,n);return t.current.indexOf(s)===-1&&t.current.push(s),s.promiseFn},[])},rr=er,nr=(t={})=>{const e=rr(),[n,s]=L(t),r=$({}),c=$({}),o=P((u=null)=>{Array.isArray(u)&&u.length?u.map(l=>r.current[l]=t[l]):r.current=t},[]),a=P((u,l,i=!1)=>{const p=Object.keys(u),h=JSON.stringify(p.sort());if(!c.current[h]){c.current[h]=!0,i&&o(Array.isArray(i)?i:p),p.map(f=>{r.current[f]||(r.current[f]={}),r.current[f].pending=!0}),s({...r.current});for(let f=0,d=p.length;f<d;f++){const g=p[f];e(u[g]).then(_=>{let{result:m,errMsg:v}=_;f===d-1&&(c.current[h]=!1),typeof l=="function"&&(m=l(m)||m),r.current[g]={...m,pending:!1},v===!1&&s({...r.current})}).catch(_=>{throw f===d-1&&(c.current[h]=!1),r.current[g]={error:_,pending:!1},s({...r.current}),_})}}},[]);return[n,a,o]},Vt=nr,st=t=>Object.keys(t).length,sr=t=>{const{Comp:e,restResolve:n,loadPromise:s,params:r,children:c}=t,[o,a]=Vt(),[u,l]=Vt();return k(()=>{st(n)&&a(n),st(s)&&l(s)},[n,s]),k(()=>{const i=st(o);i&&i===st(n)&&gt.setState(o)},[o]),(0,b.jsx)(e,{...r,...o,...u,children:c})},or=sr,cr=t=>t===!1?null:it(t)?t:lt(t)?(0,b.jsx)(t,{}):(0,b.jsx)(tr,{}),ar=({Loading:t,ErrorBoundary:e,loadedComp:n})=>{const s=(0,b.jsx)(Qt,{fallback:cr(t),children:n});return e===!1?s:lt(e)?(0,b.jsx)(e,{children:s}):(0,b.jsx)(Ve,{children:s})},ur=({Comp:t,routerProps:e,children:n})=>{const{params:s,...r}=e,{loading:c,errorBoundary:o,...a}=s,u=(0,b.jsx)(or,{Comp:t,...r,params:a,children:n});return ar({Loading:c,ErrorBoundary:o,loadedComp:u})},qt=ur,vt={},yt=(t,e,n,s)=>V(n)?n.then(r=>qt({Comp:t,routerProps:e,children:r.default??r})):qt({Comp:t,routerProps:e,children:n}),ir=(t,e)=>{const n={},s={};return S(t)?(Object.keys(t).map(r=>{const c=gt.getState(r);c==null?s[r]=t[r](e):n[r]=c}),{cachedResolve:n,restResolve:s}):{cachedResolve:n,restResolve:s}},lr=(t,e)=>{if(!S(t))return{};const n={};return Object.keys(t).map(s=>n[s]=t[s](e)),n},fr=t=>{const{current:e,menu:n,...s}=t,r=e.map(a=>{const{component:u,resolve:l,loadData:i,loading:p,errorBoundary:h,icon:f,...d}=a;return d}),c=[...e].filter(a=>a.component),o=(a=0)=>{if(!c.length)return null;const u=c.shift(),{component:l,resolve:i,loadData:p,icon:h,key:f,...d}=u;if(typeof l=="function"||V(l)){const g=`${d.path}${d.childSameRouteLevel??""}`;let _=vt[g];const{cachedResolve:m,restResolve:v}=ir(i,d),E={loadPromise:lr(p,d),restResolve:v,params:{current:r,...s,...d,...m}},C=o(a+1);if(_)return yt(_,E,C,g);try{_=l(),_=it(_)?l:_}catch{_=l}return V(_)?_.then(x=>(_=x.default??x,vt[g]=_,yt(_,E,C,g))):(vt[g]=_,yt(_,E,C,g))}return typeof l=="string"?He(l):l};return o()},pr=fr,dr=t=>{const[e,n]=L(t),[s,r]=L(),[c,o]=L(),a=$(),u=$(),l=$(),i=$(),p=()=>{typeof a.current=="function"&&(a.current({cancel:ft.cancelMsg}),a.current=null)},h=P(m=>{typeof m=="function"?n(v=>({...v,...m(v)})):S(m)&&n(v=>({...v,...m}))},[]),f=(m,v="pushState")=>{const{basepath:A,browserRouter:E}=i.current,C=l.current,x=Fe(m,A,E,C);if(!x)return;const{path:T,params:I}=x;_({inputPath:T,inputParams:I},()=>history[v](m?.state,"",T))},d=P(m=>f(m),[]),g=P(m=>f(m,"replaceState"),[]),_=P(({inputPath:m="",inputParams:v={}},A)=>{const E=+new Date,{browserRouter:C,childKey:x,idKey:T,title:I,metas:G,routers:Q,beforeRender:U,afterRender:W,basepath:H,allowedNotFound:O,...Yt}=i.current;if(!m){const{path:R,params:w}=we(C);m=R,v={...v,...w}}const ot=l.current;new Promise((R,w)=>{Q?.length||w("\u8DEF\u7531\u4E3A\u7A7A\uFF01"),m!==l.current&&typeof U=="function"?U({path:m,params:v,prevPath:ot},R,w):R()}).then(R=>{if(R===!1)return;const w=R?.path;if(w&&z(H,w,C)!==m){g(R);return}u.current=u.current??m;const{redirect:F,current:X,menu:zt}=xe(J(Q),m.split("?")[0],v,x,T);if(F){if(O&&F===pt&&(typeof O=="boolean"||typeof O=="string"&&Dt(u.current,O)||M(O)&&O.find(at=>Dt(u.current,at))))return;if(M(F)){console.error(`\u522B\u95F9\uFF0C[${[m,...F].join(" -> ")}] \u91CD\u5B9A\u5411\u6B7B\u5FAA\u73AF\uFF01\uFF01\uFF01`);return}return F===pt?g({path:F}):d({path:F,exact:!0})}A?.(),m?.split("?")[0]!==l.current?.split("?")[0]&&Me(),Te(X,I,G);const Et={...Yt,updateRouter:h,router:{push:d,replace:g},current:X,menu:zt,inputPath:u.current,prevPath:ot,browserRouter:C,basepath:H,title:I,history:{...Ae,goBack:Z=>d({...Z,path:ot})}};B.setState(Et);const ct=pr(Et);if(l.current=m,u.current=null,p(),V(ct)){const{promiseFn:Z,cancelFn:at}=St(ct,{delay:ft.delay,msg:{timeout:ft.timeoutMsg}});return a.current=at,o(!0),Z.then(K=>{a.current=null;const{result:Gt,errMsg:ut}=K,At=ut===!1?Gt:ut?.timeout?et({error:{errMsg:`${m} ${ut.timeout}`}}):null;At&&(o(!1),mt(W,X.slice(-1)[0],E),r(At))}).catch(K=>{throw a.current=null,o(!1),mt(W,X.slice(-1)[0],E),r(et({error:K})),K})}mt(W,X.slice(-1)[0],E),r(ct)}).catch(R=>{throw r(et({error:R})),R})},[]);return k(()=>{const m={description:document.getElementsByTagName("meta").description.content??""},{childKey:v="children",idKey:A="path",browserRouter:E=!1,routers:C=[],basepath:x="",exact:T=!1,inputPath:I="",inputParams:G={},...Q}=e,U=Rt(x),W=Re(J(C),E,v,A,U,T);i.current={...Q,childKey:v,idKey:A,browserRouter:E,routers:W,basepath:U,metas:m};const H=E?"popstate":"hashchange",O=()=>_({});return _({inputPath:I,inputParams:G}),ht.on(d),Lt.on(g),window.addEventListener(H,O,!1),()=>{p(),ht.off(d),Lt.off(g),window.removeEventListener(H,O,!1)}},[e]),{updateRouter:h,output:s,loading:c}},_r=dr,mr=t=>{const{to:e,onClick:n,preventDefault:s,stopPropagation:r=!0,exact:c=!0,target:o,disabled:a,...u}=t,l=()=>{const p=typeof e=="string"?{path:e}:e;ht.emit({exact:c,...u,...p})};return p=>{if(p.preventDefault(),r&&p.stopPropagation(),!a){if(!s){if(o){const{browserRouter:h,basepath:f}=B.getState();$t(e,o,f,h);return}l()}typeof n=="function"&&n()}}},hr=mr;var D=y(845),N={};N.styleTagTransform=Jt(),N.setAttributes=Ht(),N.insert=Wt().bind(null,"head"),N.domAPI=Ut(),N.insertStyleElement=Xt();var Dr=Nt()(D.Ay,N);const Ir=D.Ay&&D.Ay.locals?D.Ay.locals:void 0,gr=t=>{if(!t)return D.nf;const e=t.trim().split(" ").filter(Boolean),s=e.find(r=>r==="active")?[D.vu]:[];return[D.nf,...s,...e].join(" ")},vr=t=>{const{to:e,onClick:n,preventDefault:s,stopPropagation:r,exact:c,target:o,className:a,...u}=t;return(0,b.jsx)("span",{onClick:hr(t),className:gr(a),...u})},yr=vr,Er=()=>{const[t,e]=L(B.getState());return k(()=>B.subscribe(n=>e(n)),[]),t},Ar=Er,br=B.getState,Cr=B.subscribe;export{yr as Link,Cr as emitRoute,br as getRoute,Bt as huxyBus,gt as huxyStore,je as useHuxyStore,Ar as useRoute,_r as useRouter};