import*as e from"@preact/signals";var t={875:function(e,t,a){a.d(t,{XR:()=>r,c9:()=>n,js:()=>u,uV:()=>s});let l=()=>Math.random().toString(36).substring(2,9),r=e=>new URL(e).hash.replace(/^#\/?#?/,"")||"/",u=e=>`/${e}`,n=(e,t={},a=0)=>({url:e,key:l(),id:l(),index:a,sameDocument:!0,state:t,hash:r(e)}),s=e=>{let t,a,l=new Promise(e=>{t=e}),r=new Promise(e=>{a=e});return setTimeout(()=>t(e),0),setTimeout(()=>a(e),10),{committed:l,finished:r}}},452:function(t){t.exports=e}},a={};function l(e){var r=a[e];if(void 0!==r)return r.exports;var u=a[e]={exports:{}};return t[e](u,u.exports,l),u.exports}l.d=(e,t)=>{for(var a in t)l.o(t,a)&&!l.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{l.d(r,{A:()=>n,Z:()=>u});var e=l(452),t=l(875);let a=()=>({url:window.location.href,entries:[(0,t.c9)(window.location.href)],index:0,navigations:new Map,subscriptions:new Set}),u=()=>{let l=a(),r=(0,e.signal)(l.url),u=(0,e.signal)(l.entries),n=(0,e.signal)(l.index),s=(0,e.signal)(l.navigations),i=l.subscriptions,o=(0,e.computed)(()=>u.value[n.value]),v=(0,e.computed)(()=>[...u.value]),h=(0,e.computed)(()=>n.value>0),w=(0,e.computed)(()=>n.value<u.value.length-1),c=(0,e.computed)(()=>n.value>0?u.value[n.value-1]:null),d=()=>{let a=window.history.state,l=(0,t.c9)(window.location.href,a);(0,e.batch)(()=>{r.value=l.url,u.value=[l],n.value=0})},p=a=>{let l=a.newURL,r=window.history.state,s=u.value.findIndex(e=>e.url===l);if(s>=0){n.value=s;let e=u.value[s];if(JSON.stringify(e.state)!==JSON.stringify(r)){let t=[...u.value];t[s]={...e,state:r},u.value=t}}else{let a=(0,t.c9)(l,r,u.value.length),s=[...u.value];n.value<u.value.length-1&&s.splice(n.value+1),s.push(a),(0,e.batch)(()=>{u.value=s,n.value=s.length-1})}},f=(a,l,u)=>{let i=(0,t.uV)(a),o=new Map(s.value);return o.set(a.key,i),(0,e.batch)(()=>{u&&(r.value=u),n.value=l,s.value=o}),i},g=(e,t)=>{let a=[...u.value],l={...a[e],state:t};return a[e]=l,u.value=a,l},y=(e,a)=>{let l=[...u.value],r={...l[e],url:a,hash:(0,t.XR)(a)};return l[e]=r,u.value=l,r},b=(0,e.effect)(()=>{let e=o.value;e&&(0,t.XR)(r.value)!==(0,t.XR)(e.url)&&(r.value=e.url)});return{currentEntry:o,prevEntry:c,entries:v,canGoBack:h,canGoForward:w,navigate:(a,l={})=>{let s=o.value.hash,i=new URL(`#${(0,t.js)(a)}`,window.location.href).href;if(s!==a){let a=(0,t.c9)(i,l.state,u.value.length);window.history.pushState(l.state||null,"",i);let s=[...u.value];return n.value<u.value.length-1&&s.splice(n.value+1),s.push(a),(0,e.batch)(()=>{u.value=s,n.value=s.length-1,r.value=i}),f(a,s.length-1)}{let e=o.value;if(l.state&&JSON.stringify(e.state)!==JSON.stringify(l.state)){window.history.replaceState(l.state,"",i);let e=g(n.value,l.state);return(0,t.uV)(e)}return(0,t.uV)(e)}},traverseTo:(e,t={})=>{let a=u.value.findIndex(t=>t.key===e);if(-1===a)return null;let l=u.value[a],r=a-n.value,s=l;return t.state&&(window.history.replaceState(t.state,"",l.url),s=g(a,t.state)),window.history.go(r),f(s,a,s.url)},back:(e={})=>{if(!h.value)return window.history.back(),null;let t=n.value-1,a=u.value[t];return e.state&&(window.history.replaceState(e.state,"",a.url),a=g(t,e.state)),window.history.back(),f(a,t,a.url)},forward:(e={})=>{if(!w.value)return null;let t=n.value+1,a=u.value[t];return e.state&&(window.history.replaceState(e.state,"",a.url),a=g(t,e.state)),window.history.forward(),f(a,t,a.url)},reload:(e={})=>{let a=o.value,l=void 0!==e.state?e.state:a.state,r=(0,t.c9)(a.url,l,a.index);void 0!==e.state&&(window.history.replaceState(e.state,"",a.url),g(n.value,e.state)),window.location.hash=(0,t.XR)(a.url);let u=(0,t.uV)(r),i=new Map(s.value);return i.set(r.key,u),s.value=i,u},updateCurrentEntry:(e={})=>{let t=n.value;window.history.replaceState(e.state||null,"",window.location.hash),g(t,e.state||null)},subscribe:t=>{let a=o.value,l=a;t(a,null,a.hash);let r=(0,e.effect)(()=>{let e=o.value,a=e.hash;l!==e&&(t(e,l,a),l=e)}),u=()=>{r(),i.delete(u)};return i.add(u),u},updateCurrentEntryHash:e=>y(n.value,new URL(`#${(0,t.js)(e)}`,window.location.href).href),create:()=>{d(),window.addEventListener("hashchange",p)},destroy:()=>{window.removeEventListener("hashchange",p),i.forEach(e=>e()),i.clear();let e=a();r.value=e.url,u.value=e.entries,n.value=e.index,s.value=e.navigations,b()}}},n=u()})();var u=r.Z,n=r.A;export{u as createHashNavigation,n as hashNavigation};
//# sourceMappingURL=hashNavigation.js.map