import{SvelteComponent as tt,check_outros as et,create_slot as rt,detach as at,empty as nt,group_outros as it,init as lt,insert as st,safe_not_equal as ct,transition_in as k,transition_out as x,update_slot as ot}from"svelte/internal";import{getContext as K}from"svelte";import{writable as L}from"svelte/store";import{hasContext as D,getContext as S,setContext as N,onMount as P,tick as H}from"svelte";import{writable as Q}from"svelte/store";function _(e,a=!1){return e=e.slice(e.startsWith("/#")?2:0,e.endsWith("/*")?-2:void 0),e.startsWith("/")||(e="/"+e),e==="/"&&(e=""),a&&!e.endsWith("/")&&(e+="/"),e}function O(e,a){e=_(e,!0),a=_(a,!0);let n=[],r={},t=!0,i=e.split("/").map(s=>s.startsWith(":")?(n.push(s.slice(1)),"([^\\/]+)"):s).join("\\/"),l=a.match(new RegExp(`^${i}$`));return l||(t=!1,l=a.match(new RegExp(`^${i}`))),l?(n.forEach((s,h)=>r[s]=l[h+1]),{exact:t,params:r,part:l[0].slice(0,-1)}):null}function A(e,a,n){if(n==="")return e;if(n[0]==="/")return n;let r=l=>l.split("/").filter(s=>s!==""),t=r(e),i=a?r(a):[];return"/"+i.map((l,s)=>t[s]).join("/")+"/"+n}function g(e,a,n,r){let t=[a,"data-"+a].reduce((i,l)=>{let s=e.getAttribute(l);return n&&e.removeAttribute(l),s===null?i:s},!1);return!r&&t===""?!0:t||r||!1}function U(e){let a=e.split("&").map(n=>n.split("=")).reduce((n,r)=>{let t=r[0];if(!t)return n;let i=r.length>1?r[r.length-1]:!0;return typeof i=="string"&&i.includes(",")&&(i=i.split(",")),n[t]===void 0?n[t]=[i]:n[t].push(i),n},{});return Object.entries(a).reduce((n,r)=>(n[r[0]]=r[1].length>1?r[1]:r[1][0],n),{})}function Z(e){return Object.entries(e).map(([a,n])=>n?n===!0?a:`${a}=${Array.isArray(n)?n.join(","):n}`:null).filter(a=>a).join("&")}function C(e,a){return e?a+e:""}function E(e){throw new Error("[Tinro] "+e)}var f={HISTORY:1,HASH:2,MEMORY:3,OFF:4,run(e,a,n,r){return e===this.HISTORY?a&&a():e===this.HASH?n&&n():r&&r()},getDefault(){return!window||window.location.pathname==="srcdoc"?this.MEMORY:this.HISTORY}},y,j,M,m=B();function B(){let e=f.getDefault(),a,n=l=>window.onhashchange=window.onpopstate=y=null,r=l=>a&&a(v(e)),t=l=>{l&&(e=l),n(),e!==f.OFF&&f.run(e,s=>window.onpopstate=r,s=>window.onhashchange=r)&&r()},i=l=>{let s=Object.assign(v(e),l);return s.path+C(Z(s.query),"?")+C(s.hash,"#")};return{mode:t,get:l=>v(e),go(l,s){G(e,l,s),r()},start(l){a=l,t()},stop(){a=null,t(f.OFF)},set(l){this.go(i(l),!l.path)},methods(){return J(this)}}}function G(e,a,n){!n&&(j=M);let r=t=>history[`${n?"replace":"push"}State`]({},"",t);f.run(e,t=>r(a),t=>r(`#${a}`),t=>y=a)}function v(e){let a=window.location,n=f.run(e,t=>a.pathname+a.search+a.hash,t=>String(a.hash.slice(1)||"/"),t=>y||"/"),r=n.match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);return M=n,{url:n,from:j,path:r[1]||"",query:U(r[2]||""),hash:r[3]||""}}function J(e){let a=()=>e.get().query,n=l=>e.set({query:l}),r=l=>n(l(a())),t=()=>e.get().hash,i=l=>e.set({hash:l});return{hash:{get:t,set:i,clear:()=>i("")},query:{replace:n,clear:()=>n(""),get(l){return l?a()[l]:a()},set(l,s){r(h=>(h[l]=s,h))},delete(l){r(s=>(s[l]&&delete s[l],s))}}}}var w="tinro";function Y(e){let a=S(w);a&&(a.exact||a.fallback)&&E(`${e.fallback?"":``} can't be inside ${a.fallback?"":` with exact path`}`);let n=e.fallback?"fallbacks":"childs",r=Q({}),t={router:{},exact:!1,pattern:null,meta:{},parent:a,fallback:e.fallback,redirect:!1,firstmatch:!1,breadcrumb:null,matched:!1,childs:new Set,activeChilds:new Set,fallbacks:new Set,update(i){t.exact=!i.path.endsWith("/*"),t.pattern=_(`${t.parent&&t.parent.pattern||""}${i.path}`),t.redirect=i.redirect,t.firstmatch=i.firstmatch,t.breadcrumb=i.breadcrumb,t.match()},register:()=>{if(t.parent)return t.parent[n].add(t),()=>{t.parent[n].delete(t),t.router.un&&t.router.un()}},show:()=>{e.onShow(),!t.fallback&&t.parent&&t.parent.activeChilds.add(t)},hide:()=>{e.onHide(),!t.fallback&&t.parent&&t.parent.activeChilds.delete(t)},match:async()=>{t.matched=!1;let{path:i,url:l,from:s,query:h}=t.router.location,o=O(t.pattern,i);if(!t.fallback&&o&&t.redirect&&(!t.exact||t.exact&&o.exact)){await H();let u=A(i,t.parent&&t.parent.pattern,t.redirect);return d.goto(u,!0)}if(t.meta=o&&{from:s,url:l,query:h,match:o.part,pattern:t.pattern,breadcrumbs:t.parent&&t.parent.meta&&t.parent.meta.breadcrumbs.slice()||[],params:o.params,subscribe:r.subscribe},t.breadcrumb&&t.meta&&t.meta.breadcrumbs.push({name:t.breadcrumb,path:o.part}),r.set(t.meta),o&&!t.fallback&&(!t.exact||t.exact&&o.exact)&&(!t.parent||!t.parent.firstmatch||!t.parent.matched)?(e.onMeta(t.meta),t.parent&&(t.parent.matched=!0),t.show()):t.hide(),await H(),o&&!t.fallback&&(t.childs.size>0&&t.activeChilds.size==0||t.childs.size==0&&t.fallbacks.size>0)){let u=t;for(;u.fallbacks.size==0;)if(u=u.parent,!u)return;u&&u.fallbacks.forEach(p=>{if(p.redirect){let b=A("/",p.parent&&p.parent.pattern,p.redirect);d.goto(b,!0)}else p.show()})}}};return N(w,t),P(()=>t.register()),t.router.un=d.subscribe(i=>{t.router.location=i,t.pattern!==null&&t.match()}),t}function R(){return D(w)?S(w).meta:E("meta() function must be run inside any `` child component only")}var d=V();function V(){let{subscribe:e}=L(m.get(),a=>{m.start(a);let n=X(m.go);return()=>{m.stop(),n()}});return{subscribe:e,goto:m.go,params:$,meta:R,useHashNavigation:a=>m.mode(a?f.HASH:f.HISTORY),mode:{hash:()=>m.mode(f.HASH),history:()=>m.mode(f.HISTORY),memory:()=>m.mode(f.MEMORY)},location:m.methods()}}function q(e){let a=g(e,"href"),n=g(e,"exact",!0),r=g(e,"active-class",!0,"active");return{destroy:d.subscribe(t=>{let i=O(a,t.path);i&&(i.exact&&n||!n)?e.classList.add(r):e.classList.remove(r)})}}function X(e){let a=n=>{let r=n.target.closest("a[href]"),t=r&&g(r,"target",!1,"_self"),i=r&&g(r,"tinro-ignore"),l=n.ctrlKey||n.metaKey||n.altKey||n.shiftKey;if(t=="_self"&&!i&&!l&&r){let s=r.getAttribute("href").replace(/^\/#/,"");/^\/\/|^[a-zA-Z]+:/.test(s)||(n.preventDefault(),e(s.startsWith("/")?s:r.href.replace(window.location.origin,"")))}};return addEventListener("click",a),()=>removeEventListener("click",a)}function $(){return K("tinro").meta.params}var ut=e=>({params:e&2,meta:e&4}),W=e=>({params:e[1],meta:e[2]});function z(e){let a,n=e[9].default,r=rt(n,e,e[8],W);return{c(){r&&r.c()},m(t,i){r&&r.m(t,i),a=!0},p(t,i){r&&r.p&&i&262&&ot(r,n,t,t[8],i,ut,W)},i(t){a||(k(r,t),a=!0)},o(t){x(r,t),a=!1},d(t){r&&r.d(t)}}}function ft(e){let a,n,r=e[0]&&z(e);return{c(){r&&r.c(),a=nt()},m(t,i){r&&r.m(t,i),st(t,a,i),n=!0},p(t,[i]){t[0]?r?(r.p(t,i),i&1&&k(r,1)):(r=z(t),r.c(),k(r,1),r.m(a.parentNode,a)):r&&(it(),x(r,1,1,()=>{r=null}),et())},i(t){n||(k(r),n=!0)},o(t){x(r),n=!1},d(t){r&&r.d(t),t&&at(a)}}}function ht(e,a,n){let{$$slots:r={},$$scope:t}=a,{path:i="/*"}=a,{fallback:l=!1}=a,{redirect:s=!1}=a,{firstmatch:h=!1}=a,{breadcrumb:o=null}=a,u=!1,p={},b={},I=Y({fallback:l,onShow(){n(0,u=!0)},onHide(){n(0,u=!1)},onMeta(c){n(2,b=c),n(1,p=b.params)}});return e.$$set=c=>{"path"in c&&n(3,i=c.path),"fallback"in c&&n(4,l=c.fallback),"redirect"in c&&n(5,s=c.redirect),"firstmatch"in c&&n(6,h=c.firstmatch),"breadcrumb"in c&&n(7,o=c.breadcrumb),"$$scope"in c&&n(8,t=c.$$scope)},e.$$.update=()=>{if(e.$$.dirty&232){t:I.update({path:i,redirect:s,firstmatch:h,breadcrumb:o})}},[u,p,b,i,l,s,h,o,t,r]}var F=class extends tt{constructor(a){super();lt(this,a,ht,ft,ct,{path:3,fallback:4,redirect:5,firstmatch:6,breadcrumb:7})}},T=F;export{T as Route,q as active,R as meta,d as router};