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