/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/universal-router@10.0.3/universal-router.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{match}from"./path-to-regexp.js";function decode(t){try{return decodeURIComponent(t)}catch{return t}}function matchRoute(t,e,r,o,n){let s,a,u=0;return{next(i){if(t===i)return{done:!0,value:!1};if(!s){const a=t,u=!a.children;if(a.match||(a.match=match(a.path||"",{end:u,...r})),s=a.match(o),s){const{path:r}=s;return s.path=u||"/"!==r.charAt(r.length-1)?r:r.substr(1),s.params={...n,...s.params},{done:!1,value:{route:t,baseUrl:e,path:s.path,params:s.params}}}}if(s&&t.children)for(;u<t.children.length;){if(!a){const n=t.children[u];n.parent=t,a=matchRoute(n,e+s.path,r,o.substr(s.path.length),s.params)}const n=a.next(i);if(!n.done)return{done:!1,value:n.value};a=null,u++}return{done:!0,value:!1}}}}function resolveRoute(t,e){if("function"==typeof t.route.action)return t.route.action(t,e)}function isChildRoute(t,e){let r=e;for(;r;)if(r=r.parent,r===t)return!0;return!1}class UniversalRouter{constructor(t,e){if(!t||"object"!=typeof t)throw new TypeError("Invalid routes");this.options={decode:decode,...e},this.baseUrl=this.options.baseUrl||"",this.root=Array.isArray(t)?{path:"",children:t,parent:null}:t,this.root.parent=null}resolve(t){const e={router:this,...this.options.context,..."string"==typeof t?{pathname:t}:t},r=matchRoute(this.root,this.baseUrl,this.options,e.pathname.substr(this.baseUrl.length)),o=this.options.resolveRoute||resolveRoute;let n,s,a=e;function u(t,i=!n.done&&n.value.route,l){const h=null===l&&!n.done&&n.value.route;if(n=s||r.next(h),s=null,!t&&(n.done||!isChildRoute(i,n.value.route)))return s=n,Promise.resolve(null);if(n.done){const t=new Error("Route not found");return t.status=404,Promise.reject(t)}return a={...e,...n.value},Promise.resolve(o(a,n.value.params)).then((e=>null!=e?e:u(t,i,e)))}return e.next=u,Promise.resolve().then((()=>u(!0,this.root))).catch((t=>{if(this.options.errorHandler)return this.options.errorHandler(t,a);throw t}))}}export default UniversalRouter;
//# sourceMappingURL=/sm/201b50ff9d9ef80de975227b5c9127751df7524908c27a285f72ef08353c5563.map