inertiax-core
Advanced tools
Comparing version 5.0.35 to 5.0.36
@@ -72,3 +72,3 @@ function V(r,e){let t;return function(...s){clearTimeout(t),t=setTimeout(()=>r.apply(this,s),e)}}var Ve={buildDOMElement(r){let e=document.createElement("template");e.innerHTML=r;let t=e.content.firstChild;if(!r.startsWith("<script "))return t;let s=document.createElement("script");return s.innerHTML=t.innerHTML,t.getAttributeNames().forEach(i=>{s.setAttribute(i,t.getAttribute(i)||"")}),s},isInertiaManagedElement(r){return r.nodeType===Node.ELEMENT_NODE&&r.getAttribute("inertia")!==null},findMatchingElementIndex(r,e){let t=r.getAttribute("inertia");return t!==null?e.findIndex(s=>s.getAttribute("inertia")===t):-1},update:V(function(r){let e=r.map(s=>this.buildDOMElement(s));Array.from(document.head.childNodes).filter(s=>this.isInertiaManagedElement(s)).forEach(s=>{let i=this.findMatchingElementIndex(s,e);if(i===-1){s?.parentNode?.removeChild(s);return}let n=e.splice(i,1)[0];n&&!s.isEqualNode(n)&&s?.parentNode?.replaceChild(n,s)}),e.forEach(s=>document.head.appendChild(s))},1)};function oe(r,e,t){let s={},i=0;function n(){let c=i+=1;return s[c]=[],c.toString()}function l(c){c===null||Object.keys(s).indexOf(c)===-1||(delete s[c],u())}function d(c,g=[]){c!==null&&Object.keys(s).indexOf(c)>-1&&(s[c]=g),u()}function b(){let c=e(""),g={...c?{title:`<title inertia="">${c}</title>`}:{}},j=Object.values(s).reduce((P,w)=>P.concat(w),[]).reduce((P,w)=>{if(w.indexOf("<")===-1)return P;if(w.indexOf("<title ")===0){let L=w.match(/(<title [^>]+>)(.*?)(<\/title>)/);return P.title=L?`${L[1]}${e(L[2])}${L[3]}`:w,P}let ne=w.match(/ inertia="[^"]+"/);return ne?P[ne[0]]=w:P[Object.keys(P).length]=w,P},g);return Object.values(j)}function u(){r?t(b()):Ve.update(b())}return u(),{forceUpdate:u,createProvider:function(){let c=n();return{update:g=>d(c,g),disconnect:()=>l(c)}}}}import v from"nprogress";var C=(()=>{if(typeof document>"u")return null;let r=document.createElement("style");return r.innerHTML="#nprogress { display: none; }",r})(),U=0,ke=()=>{if(C&&document.head.contains(C))return document.head.removeChild(C)},H=(r=!1)=>{U=Math.max(0,U-1),(r||U===0)&&ke()},D=()=>{U++,C&&!document.head.contains(C)&&document.head.appendChild(C)};function Ie(r){document.addEventListener("inertia:start",e=>Oe(e,r)),document.addEventListener("inertia:progress",Le)}function Oe(r,e){r.detail.visit.showProgress||D();let t=setTimeout(()=>v.start(),e);document.addEventListener("inertia:finish",s=>Ue(s,t),{once:!0})}function Le(r){v.isStarted()&&r.detail.progress?.percentage&&v.set(Math.max(v.status,r.detail.progress.percentage/100*.9))}function Ue(r,e){clearTimeout(e),v.isStarted()&&(r.detail.visit.completed?v.done():r.detail.visit.interrupted?v.set(0):r.detail.visit.cancelled&&(v.done(),v.remove()))}function He(r){let e=document.createElement("style");e.textContent=` | ||
} | ||
`,document.head.appendChild(e)}function ae({delay:r=250,color:e="#29d",includeCSS:t=!0,showSpinner:s=!1}={}){Ie(r),v.configure({showSpinner:s}),t&&He(e)}function le(r){let e=r.currentTarget.tagName.toLowerCase()==="a";return!(r.target&&(r?.target).isContentEditable||r.defaultPrevented||e&&r.which>1||e&&r.altKey||e&&r.ctrlKey||e&&r.metaKey||e&&r.shiftKey||e&&"button"in r&&r.button!==0)}import De from"deepmerge";import*as M from"qs";function N(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>N(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>N(e))}var $=r=>r instanceof FormData;function _(r,e=new FormData,t=null){r=r||{};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&pe(e,ce(t,s),r[s]);return e}function ce(r,e){return r?r+"["+e+"]":e}function pe(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(s=>pe(r,ce(e,s.toString()),t[s]));if(t instanceof Date)return r.append(e,t.toISOString());if(t instanceof File)return r.append(e,t,t.name);if(t instanceof Blob)return r.append(e,t);if(typeof t=="boolean")return r.append(e,t?"1":"0");if(typeof t=="string")return r.append(e,t);if(typeof t=="number")return r.append(e,`${t}`);if(t==null)return r.append(e,"");_(t,r,e)}function m(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var ue=(r,e,t,s,i)=>{let n=typeof r=="string"?m(r):r;if((N(e)||s)&&!$(e)&&(e=_(e)),$(e))return[n,e];let[l,d]=de(t,n,e,i);return[m(l),d]};function de(r,e,t,s="brackets"){let i=/^https?:\/\//.test(e.toString()),n=i||e.toString().startsWith("/"),l=!n&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),d=e.toString().includes("?")||r==="get"&&Object.keys(t).length,b=e.toString().includes("#"),u=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(u.search=M.stringify(De(M.parse(u.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:s}),t={}),[[i?`${u.protocol}//${u.host}`:"",n?u.pathname:"",l?u.pathname.substring(1):"",d?u.search:"",b?u.hash:""].join(""),t]}function F(r){return r=new URL(r.href),r.hash="",r}var W=(r,e)=>{r.hash&&!e.hash&&F(r).href===e.href&&(e.hash=r.hash)},k=(r,e)=>F(r).href===F(e).href;import{BROWSER as Te}from"esm-env";import _e from"deepmerge";function h(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var Q=r=>(h(`${r.frame}:before`,{detail:{visit:r}}),h("before",{cancelable:!0,detail:{visit:r}})),he=r=>h("error",{detail:{errors:r}}),me=r=>h("exception",{cancelable:!0,detail:{exception:r}}),fe=r=>(h(`${r.frame}:finish`,{detail:{visit:r}}),h("finish",{detail:{visit:r}})),ge=r=>h("invalid",{cancelable:!0,detail:{response:r}}),E=r=>h("navigate",{detail:{page:r}}),be=r=>h("progress",{detail:{progress:r}}),ve=r=>(h(`${r.frame}:start`,{detail:{visit:r}}),h("start",{detail:{visit:r}})),ye=r=>h("success",{detail:{page:r}}),Pe=(r,e)=>h("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),we=r=>(h(`${r.frame}:prefetching`,{detail:{visit:r}}),h("prefetching",{detail:{visit:r}}));import $e from"deepmerge";var p=class{static set(e,t){typeof window<"u"&&window.sessionStorage.setItem(e,JSON.stringify(t))}static get(e){if(typeof window<"u")return JSON.parse(window.sessionStorage.getItem(e)||"null")}static merge(e,t){let s=this.get(e);s===null?this.set(e,t):this.set(e,{...s,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let s=this.get(e);s!==null&&(delete s[t],this.set(e,s))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};p.locationVisitKey="inertiaLocationVisit";var Ee=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Fe(),t=await Re(),s=await Ke(t);if(!s)throw new Error("Unable to encrypt history");return await Ne(e,s,r)},R={key:"historyKey",iv:"historyIv"},Se=async r=>{let e=Fe(),t=await Re();if(!t)throw new Error("Unable to decrypt history");return await Me(e,t,r)},Ne=async(r,e,t)=>{if(typeof window>"u")throw new Error("Unable to encrypt history");if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=new TextEncoder,i=JSON.stringify(t),n=new Uint8Array(i.length*3),l=s.encodeInto(i,n);return window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,n.subarray(0,l.written))},Me=async(r,e,t)=>{if(typeof window.crypto.subtle>"u")return console.warn("Decryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t),i=new TextDecoder().decode(s);return JSON.parse(i)},Fe=()=>{let r=p.get(R.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return p.set(R.iv,Array.from(e)),e},Ge=async()=>typeof window.crypto.subtle>"u"?(console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(null)):window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),Be=async r=>{if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve();let e=await window.crypto.subtle.exportKey("raw",r);p.set(R.key,Array.from(new Uint8Array(e)))},Ke=async r=>{if(r)return r;let e=await Ge();return e?(await Be(e),e):null},Re=async()=>{let r=p.get(R.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var f=class{static save(){a.saveScrollRegions(Array.from(this.regions()).map(e=>({top:e.scrollTop,left:e.scrollLeft})))}static regions(){return document.querySelectorAll("[scroll-region]")}static reset(){typeof window<"u"&&window.scrollTo(0,0),this.regions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.save(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}static restore(e){e.scrollRegions&&this.regions().forEach((t,s)=>{let i=e.scrollRegions[s];i&&(typeof t.scrollTo=="function"?t.scrollTo(i.left,i.top):(t.scrollTop=i.top,t.scrollLeft=i.left))})}static onScroll(e){let t=e.target;(typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")||t==document)&&this.save()}};import je from"deepmerge";var X=class{constructor(){this.page={frames:{},version:null,scrollRegions:[]};this.ignoredFrames=[];this.swappers={};this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}initFrame(e,{frame:t,initialState:s,swapComponent:i}){var l;(l=this.page).version||(l.version=s?.version);let n=this.page.frames?.[t];return s?.component&&e&&this.merge({frames:{[t]:s,...this.page.frames}}),this.swappers[t]=i,e||this.ignoredFrames.push(t),n}async set(e,{replace:t,preserveScroll:s=!1,forgetState:i=!1,frame:n}={}){this.componentId={};let l=this.componentId;return this.resolve(e.frames).then(d=>{if(l===this.componentId){if(e.scrollRegions??(e.scrollRegions=[]),e.frames._top?.url===void 0){let b=typeof window<"u"?window.location:new URL(e.frames._top.url);t=t||k(m(e.frames._top?.url),b)}if(n&&!this.ignoredFrames.includes(n)&&(t?a.replaceState(e):a.pushState(e,n)),this.page=e,this.cleared=!1,this.isFirstPageLoad){this.isFirstPageLoad=!1,this.fireEventsFor("firstLoad");return}return this.swap({components:d,page:e,forgetState:i,frame:n}).then(()=>{s||f.reset(),y.fireInternalEvent("loadDeferredProps"),t||E(e)})}})}destroy(e){delete this.page.frames[e],delete this.swappers[e],this.ignoredFrames.includes(e)||a.replaceState(this.page),this.ignoredFrames=this.ignoredFrames.filter(t=>t!==e)}async setQuietly(e,{forgetState:t=!1}={}){return this.resolve(e.frames).then(s=>(this.page=e,this.cleared=!1,this.swap({components:s,page:e,forgetState:t})))}async setFrame(e,t,s={}){return this.set({...this.page,frames:{...this.page.frames,[e]:t}},{frame:e,...s})}clear(){this.cleared=!0}isCleared(){return this.cleared}frame(e){return this.page.frames[e]||{}}get(){return this.page}merge(e){this.page=je(this.page,e,{arrayMerge:(t,s)=>s})}setUrlHash(e){this.page.frames._top.url+=e}remember(e,t){this.page.frames[e].rememberedState=t}scrollRegions(e){this.page.scrollRegions=e}swap({components:e,page:t,forgetState:s,frame:i}){return Promise.all(Object.entries(e).map(([n,l])=>{if(i&&i!==n)return Promise.resolve();if(this.swappers[n])return this.swappers[n]({component:l,frame:t.frames[n],forgetState:s})}))}async resolve(e){let t={};return await Promise.all(Object.keys(e).map(async s=>{let i=e[s];t[s]=await I.resolveComponent(i.component)})),t}isTheSame(e,t){return this.page.frames[e].component===t.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(s=>s.event!==e&&s.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},o=new X;var G=typeof window>"u",J=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.queue=[]}remember(e,t,s){let i=o.get(),n=$e(i,{frames:{[e]:{rememberedState:{[s]:t}}}},{arrayMerge:(l,d)=>d});this.replaceState(n)}restore(e,t){if(!G)return this.current?.frames?.[e]?.rememberedState?.[t]}pushState(e,t){G||this.preserveUrl||(this.current=e,this.lastUpdatedFrame=t,this.addToQueue(()=>this.getPageData(e).then(s=>{window.history.pushState({page:s,timestamp:Date.now(),updatedFrame:t},"",e.frames._top.url)})))}getPageData(e){return new Promise(t=>J.encryptHistory?Ee(e).then(t):t(e))}processQueue(){let e=this.queue.shift();return e?e().then(()=>this.processQueue()):Promise.resolve()}decrypt(e=null){if(G)return Promise.resolve(e??o.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(s=>{if(!s)throw new Error("Unable to decrypt history");return this.current=s??{},{...s,scrollRegions:window.history.state?.scrollRegions??[]}})}decryptPageData(e){return e instanceof ArrayBuffer?Se(e):Promise.resolve(e)}saveScrollRegions(e){window.history.replaceState({...window.history.state,scrollRegions:e},"")}replaceState(e){o.merge(e),!(G||this.preserveUrl)&&(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.replaceState({...window.history.state,page:t,timestamp:Date.now()},"",e.frames._top.url)})))}addToQueue(e){this.queue.push(e),this.processQueue()}getState(e,t){return this.current?.[e]??t}deleteRememberedState(){this.current.frames&&(Object.values(this.current.frames).forEach(e=>{delete e.rememberedState}),this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){p.remove(R.key),p.remove(R.iv)}isValidState(e){return!!e.page}getAllState(){return this.current}},x=J;x.encryptHistory=!1;var a=new x;var z=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),typeof document<"u"&&document.addEventListener("scroll",V(f.onScroll.bind(f),100),!0)}onGlobalEvent(e,t){let s=i=>{let n=t(i);i.cancelable&&!i.defaultPrevented&&n===!1&&i.preventDefault()};return this.registerListener(`inertia:${e}`,s)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(s=>s.listener!==t)}}onMissingHistoryItem(){o.clear(),this.fireInternalEvent("missingHistoryItem")}fireInternalEvent(e){this.internalListeners.filter(t=>t.event===e).forEach(t=>t.listener())}registerListener(e,t){return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}handlePopstateEvent(e){let t=e.state||null;if(t===null){let s=m(o.frame("_top").url);s.hash=window.location.hash,a.replaceState(_e(o.get(),{frames:{_top:{url:s.href}}},{arrayMerge:(i,n)=>n})),f.reset();return}if(a.isValidState(t)){a.decrypt(t.page).then(s=>{o.setQuietly(s,{forgetState:a.lastUpdatedFrame}).then(()=>{f.restore(o.get()),E(o.get())}),a.lastUpdatedFrame=window.history.state?.updatedFrame}).catch(()=>{this.onMissingHistoryItem()});return}}},y=new z;var Y=class{constructor(){typeof window<"u"&&window?.performance.getEntriesByType("navigation").length>0?this.type=window.performance.getEntriesByType("navigation")[0].type:this.type="navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},Z=new Y;var B=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){Z.isReload()&&a.deleteRememberedState()}static handleBackForward(){return!Z.isBackForward()||!a.hasAnyState()||!window.history.state?.page?!1:(a.decrypt().then(e=>{o.set(e,{preserveScroll:!0,forgetState:!1,replace:!0}).then(()=>{f.restore(o.get()),E(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0)}static handleLocation(){if(!p.exists(p.locationVisitKey))return!1;let e=p.get(p.locationVisitKey)||{};return p.remove(p.locationVisitKey),typeof window<"u"&&o.setUrlHash(window.location.hash),a.decrypt().then(()=>{let t=a.getState("frames",{}),s=a.getState(a.scrollRegions,[]);Object.entries(t).forEach(([i,n])=>{o.remember(i,n.rememberedState)}),o.scrollRegions(s),o.set(o.get(),{preserveScroll:e.preserveScroll,forgetState:!1}).then(()=>{e.preserveScroll||f.restore(o.get()),E(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&o.setUrlHash(window.location.hash),o.set(o.get(),{frame:"_top",forgetState:!1,replace:!0}).then(()=>{E(o.get())})}};var K=class{constructor(e,t,s){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=s.keepAlive??!1,this.cb=t,this.interval=e,(s.autoStart??!0)&&this.start()}stop(){this.id&&clearInterval(this.id)}start(){typeof window>"u"||(this.stop(),this.id=window.setInterval(()=>{(!this.throttle||this.cbCount%10===0)&&this.cb(),this.throttle&&this.cbCount++},this.interval))}isInBackground(e){this.throttle=this.keepAlive?!1:e,this.throttle&&(this.cbCount=0)}};var ee=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,s){let i=new K(e,t,s);return this.polls.push(i),{stop:()=>i.stop(),start:()=>i.start()}}clear(){this.polls.forEach(e=>e.stop()),this.polls=[]}setupVisibilityListener(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{this.polls.forEach(e=>e.isInBackground(document.hidden))},!1)}},xe=new ee;var te=(r,e,t)=>{if(r===e)return!0;for(let s in r)if(!t.includes(s)&&r[s]!==e[s]&&!We(r[s],e[s]))return!1;return!0},We=(r,e)=>{switch(typeof r){case"object":return te(r,e,[]);case"function":return r.toString()===e.toString();default:return r===e}};var Qe={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},re=r=>{if(typeof r=="number")return r;for(let[e,t]of Object.entries(Qe))if(r.endsWith(e))return parseFloat(r)*t;return parseInt(r)};var se=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:s}){if(this.findInFlight(e))return Promise.resolve();let n=this.findCached(e);if(!e.fresh&&n&&n.staleTimestamp>Date.now())return Promise.resolve();let[l,d]=this.extractStaleValues(s),b=new Promise((u,c)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),c()},onError:g=>{this.remove(e),e.onError(g),c()},onPrefetching(g){e.onPrefetching(g)},onPrefetched(g,j){e.onPrefetched(g,j)},onPrefetchResponse(g){u(g)}})}).then(u=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+l,response:b,singleUse:s===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,d),this.inFlightRequests=this.inFlightRequests.filter(c=>!this.paramsAreEqual(c.params,e)),u.handlePrefetch(),u));return this.inFlightRequests.push({params:{...e},response:b,staleTimestamp:null,inFlight:!0}),b}removeAll(){this.cached=[],this.removalTimers.forEach(e=>{clearTimeout(e.timer)}),this.removalTimers=[]}remove(e){this.cached=this.cached.filter(t=>!this.paramsAreEqual(t.params,e)),this.clearTimer(e)}extractStaleValues(e){let[t,s]=this.cacheForToStaleAndExpires(e);return[re(t),re(s)]}cacheForToStaleAndExpires(e){if(!Array.isArray(e))return[e,e];switch(e.length){case 0:return[0,0];case 1:return[e[0],e[0]];default:return[e[0],e[1]]}}clearTimer(e){let t=this.removalTimers.find(s=>this.paramsAreEqual(s.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(s=>s!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let s=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:s})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let s=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=s,e.response.then(i=>{if(this.currentUseId===s)return i.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),i.handle()})}removeSingleUseItems(e){this.cached=this.cached.filter(t=>this.paramsAreEqual(t.params,e)?!t.singleUse:!0)}findCached(e){return this.cached.find(t=>this.paramsAreEqual(t.params,e))||null}findInFlight(e){return this.inFlightRequests.find(t=>this.paramsAreEqual(t.params,e))||null}paramsAreEqual(e,t){return te(e,t,["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},S=new se;import{default as Ce}from"axios";var T=class{constructor(e){this.callbacks=[];if(!e.prefetch)this.params=e;else{let t={onBefore:this.wrapCallback(e,"onBefore"),onStart:this.wrapCallback(e,"onStart"),onProgress:this.wrapCallback(e,"onProgress"),onFinish:this.wrapCallback(e,"onFinish"),onCancel:this.wrapCallback(e,"onCancel"),onSuccess:this.wrapCallback(e,"onSuccess"),onError:this.wrapCallback(e,"onError"),onCancelToken:this.wrapCallback(e,"onCancelToken"),onPrefetched:this.wrapCallback(e,"onPrefetched"),onPrefetching:this.wrapCallback(e,"onPrefetching")};this.params={...e,...t,onPrefetchResponse:e.onPrefetchResponse||(()=>{})}}}static create(e){return new T(e)}data(){return this.params.method==="get"?{}:this.params.data}queryParams(){return this.params.method==="get"?this.params.data:{}}isPartial(){return this.params.only.length>0||this.params.except.length>0||this.params.reset.length>0}onCancelToken(e){this.params.onCancelToken({cancel:e})}markAsFinished(){this.params.completed=!0,this.params.cancelled=!1,this.params.interrupted=!1}markAsCancelled({cancelled:e=!0,interrupted:t=!1}){this.params.onCancel(),this.params.completed=!1,this.params.cancelled=e,this.params.interrupted=t}wasCancelledAtAll(){return this.params.cancelled||this.params.interrupted}onFinish(){this.params.onFinish(this.params)}onStart(){this.params.onStart(this.params)}onPrefetching(){this.params.onPrefetching(this.params)}onPrefetchResponse(e){this.params.onPrefetchResponse&&this.params.onPrefetchResponse(e)}all(){return this.params}headers(){let e={...this.params.headers};this.isPartial()&&(e["X-Inertia-Partial-Component"]=o.frame(this.params.frame).component);let t=this.params.only.concat(this.params.reset);return t.length>0&&(e["X-Inertia-Partial-Data"]=t.join(",")),this.params.except.length>0&&(e["X-Inertia-Partial-Except"]=this.params.except.join(",")),this.params.reset.length>0&&(e["X-Inertia-Reset"]=this.params.reset.join(",")),this.params.errorBag&&this.params.errorBag.length>0&&(e["X-Inertia-Error-Bag"]=this.params.errorBag),e}setPreserveOptions(e){this.params.preserveScroll=this.resolvePreserveOption(this.params.preserveScroll,e),this.params.forgetState=this.resolvePreserveOption(this.params.forgetState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...s)=>{this.recordCallback(t,s),e[t](...s)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.frames[this.params.frame].props.errors||{}).length>0:e}};var qe={modal:null,listener:null,show(r){typeof r=="object"&&(r=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(r)}`);let e=document.createElement("html");e.innerHTML=r,e.querySelectorAll("a").forEach(s=>s.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(r){r.keyCode===27&&this.hide()}};var ie=class{constructor(){this.queue=[];this.processing=!1}add(e){this.queue.push(e)}async process(){return this.processing||(this.processing=!0,await this.processQueue(),this.processing=!1),Promise.resolve()}async processQueue(){let e=this.queue.shift();return e?(await e.process(),this.processQueue()):Promise.resolve()}},Ae=new ie,q=class{constructor(e,t,s){this.requestParams=e;this.response=t;this.originatingPage=s}static create(e,t,s){return new q(e,t,s)}async handlePrefetch(){k(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return Ae.add(this),Ae.process()}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),Pe(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await a.processQueue(),a.preserveUrl=this.requestParams.all().preserveUrl,await this.setFrame();let e=this.requestParams.all().frame,t=o.frame(e).props.errors||{};if(Object.keys(t).length>0){let s=this.getScopedErrors(t);return he(s),this.requestParams.all().onError(s)}ye(o.get()),await this.requestParams.all().onSuccess(o.get()),a.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=m(this.getHeader("x-inertia-location"));return W(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(ge(e))return qe.show(e.data)}isInertiaResponse(){return this.hasHeader("x-inertia")}hasStatus(e){return this.response.status===e}getHeader(e){return this.response.headers[e]}hasHeader(e){return this.getHeader(e)!==void 0}isLocationVisit(){return this.hasStatus(409)&&this.hasHeader("x-inertia-location")}locationVisit(e){try{if(p.set(p.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;k(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setFrame(){let e=this.getDataFromResponse(this.response.data);return this.shouldSetFrame(e)?(this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=a.preserveUrl?o.frame("_top").url:this.pageUrl(e),delete e.version,x.encryptHistory=e.encryptHistory,e.clearHistory&&a.clear(),o.setFrame(this.requestParams.all().frame,e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,forgetState:this.requestParams.all().forgetState})):Promise.resolve()}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetFrame(e){let t=this.requestParams.all().frame;if(!this.requestParams.all().async||this.originatingPage.frames[t]?.component!==e.component)return!0;if(this.originatingPage.frames[t]?.component!==o.frame(t).component)return!1;let s=m(this.originatingPage.frames._top.url),i=m(o.frame("_top").url);return s.origin===i.origin&&s.pathname===i.pathname}pageUrl(e){let t=m(e.url);return W(this.requestParams.all().url,t),t.href.split(t.host).pop()}mergeProps(e){let t=this.requestParams.all().frame;this.requestParams.isPartial()&&e.component===o.frame(t).component&&((e.mergeProps||[]).forEach(i=>{let n=e.props[i];Array.isArray(n)?e.props[i]=[...o.frame(t).props[i]||[],...n]:typeof n=="object"&&(e.props[i]={...o.frame(t).props[i]||[],...n})}),e.props={...o.frame(t).props,...e.props})}async setRememberedState(e){let t=await a.getState("frames",{}),s=this.requestParams.all().frame,i=t[s]?.rememberedState||{};this.requestParams.all().forgetState&&i&&e.component===o.frame(s).component&&(e.rememberedState=i)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var A=class{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=T.create(e),this.cancelToken=new AbortController}static create(e,t){return new A(e,t)}async send(){this.requestParams.onCancelToken(()=>this.cancel({cancelled:!0})),ve(this.requestParams.all()),this.requestParams.onStart(),this.requestParams.all().prefetch&&(this.requestParams.onPrefetching(),we(this.requestParams.all()));let e=this.requestParams.all().prefetch;return Ce({method:this.requestParams.all().method,url:F(this.requestParams.all().url).href,data:this.requestParams.data(),params:this.requestParams.queryParams(),signal:this.cancelToken.signal,headers:this.getHeaders(),onUploadProgress:this.onProgress.bind(this),responseType:"text"}).then(t=>(this.response=q.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=q.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!Ce.isCancel(t)&&me(t))return Promise.reject(t)}).finally(()=>{this.finish(),e&&this.response&&this.requestParams.onPrefetchResponse(this.response)})}finish(){this.requestParams.wasCancelledAtAll()||(this.requestParams.markAsFinished(),this.fireFinishEvents())}fireFinishEvents(){this.requestHasFinished||(this.requestHasFinished=!0,fe(this.requestParams.all()),this.requestParams.onFinish())}cancel({cancelled:e=!1,interrupted:t=!1}){this.requestHasFinished||(this.cancelToken.abort(),this.requestParams.markAsCancelled({cancelled:e,interrupted:t}),this.fireFinishEvents())}onProgress(e){this.requestParams.data()instanceof FormData&&(e.percentage=e.progress?Math.round(e.progress*100):0,be(e),this.requestParams.all().onProgress(e))}getHeaders(){let e={...this.requestParams.headers(),Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},t=this.requestParams.all().frame,s=o.frame(t).url;return s&&(e["X-Inertia-Referer"]=F(m(s)).href),o.get().version&&(e["X-Inertia-Version"]=o.get().version),e}};var O=class{constructor({maxConcurrent:e,interruptible:t}){this.requests=[];this.maxConcurrent=e,this.interruptible=t}send(e){this.requests.push(e),e.send().then(()=>{this.requests=this.requests.filter(t=>t!==e)})}interruptInFlight(){this.cancel({interrupted:!0},!1)}cancelInFlight(){this.cancel({cancelled:!0},!0)}cancel({cancelled:e=!1,interrupted:t=!1}={},s){if(!this.shouldCancel(s))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var I=class{constructor(){this.frame="_top";this.syncRequestStream=new O({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new O({maxConcurrent:1/0,interruptible:!1})}init(e,{frame:t,initialState:s,swapComponent:i}){if(this.frame=t,!Te)return;let n=o.initFrame(e,{frame:t,initialState:s,swapComponent:i});return t!=="_top"||(B.handle(),y.init(),y.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{forgetState:!1,preserveScroll:!0,replace:!0})}),y.on("loadDeferredProps",()=>{this.loadDeferredProps()})),n}destroy(){o.destroy(this.frame)}get(e,t={},s={}){return this.visit(e,{...s,method:"get",data:t})}post(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"post",data:t})}put(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"put",data:t})}patch(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{forgetState:!1,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,forgetState:this.frame,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){a.remember(this.frame,e,t)}restore(e="default"){return a.restore(this.frame,e)}on(e,t){return y.onGlobalEvent(`${this.frame}:${e}`,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},s={}){return xe.add(e,()=>this.reload(t),{autoStart:s.autoStart??!0,keepAlive:s.keepAlive??!1})}visit(e,t={}){if(!Te)return;let s=this.getPendingVisit(e,{...t,preserveScroll:t.preserveScroll??this.frame!=="_top",forgetState:t.forgetState??this.frame,showProgress:t.showProgress??!t.async}),i=this.getVisitEvents(t);if(i.onBefore(s)===!1||!Q(s))return;let n=s.async?this.asyncRequestStream:this.syncRequestStream;n.interruptInFlight(),!o.isCleared()&&!s.preserveUrl&&f.save();let l={...s,...i},d=S.get(l);d?(H(d.inFlight),S.use(d,l)):(H(!0),n.send(A.create(l,o.get())))}getCached(e,t={}){return S.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){S.remove(this.getPrefetchParams(e,t))}flushAll(){S.removeAll()}getPrefetching(e,t={}){return S.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:s}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let i=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),n=this.getVisitEvents(t);if(n.onBefore(i)===!1||!Q(i))return;D(),this.asyncRequestStream.interruptInFlight();let l={...i,...n};S.add(l,d=>{this.asyncRequestStream.send(A.create(d,o.get()))},{cacheFor:s})}clearHistory(){a.clear()}decryptHistory(){return a.decrypt()}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,s={}){let i={method:"get",data:{},replace:!1,preserveScroll:!1,forgetState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,frame:this.frame,...t},[n,l]=ue(e,i.data,i.method,i.forceFormData,i.queryStringArrayFormat);return{cancelled:!1,completed:!1,interrupted:!1,...i,...s,url:n,data:l}}getVisitEvents(e){return{onCancelToken:e.onCancelToken||(()=>{}),onBefore:e.onBefore||(()=>{}),onStart:e.onStart||(()=>{}),onProgress:e.onProgress||(()=>{}),onFinish:e.onFinish||(()=>{}),onCancel:e.onCancel||(()=>{}),onSuccess:e.onSuccess||(()=>{}),onError:e.onError||(()=>{}),onPrefetched:e.onPrefetched||(()=>{}),onPrefetching:e.onPrefetching||(()=>{})}}loadDeferredProps(){let e=o.frame(this.frame)?.deferredProps;e&&Object.entries(e).forEach(([t,s])=>{this.reload({only:s})})}};export{x as History,I as Router,oe as createHeadManager,D as hideProgress,a as history,m as hrefToUrl,de as mergeDataIntoQueryString,H as revealProgress,ae as setupProgress,le as shouldIntercept,F as urlWithoutHash}; | ||
`,document.head.appendChild(e)}function ae({delay:r=250,color:e="#29d",includeCSS:t=!0,showSpinner:s=!1}={}){Ie(r),v.configure({showSpinner:s}),t&&He(e)}function le(r){let e=r.currentTarget.tagName.toLowerCase()==="a";return!(r.target&&(r?.target).isContentEditable||r.defaultPrevented||e&&r.which>1||e&&r.altKey||e&&r.ctrlKey||e&&r.metaKey||e&&r.shiftKey||e&&"button"in r&&r.button!==0)}import De from"deepmerge";import*as M from"qs";function N(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>N(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>N(e))}var $=r=>r instanceof FormData;function _(r,e=new FormData,t=null){r=r||{};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&pe(e,ce(t,s),r[s]);return e}function ce(r,e){return r?r+"["+e+"]":e}function pe(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(s=>pe(r,ce(e,s.toString()),t[s]));if(t instanceof Date)return r.append(e,t.toISOString());if(t instanceof File)return r.append(e,t,t.name);if(t instanceof Blob)return r.append(e,t);if(typeof t=="boolean")return r.append(e,t?"1":"0");if(typeof t=="string")return r.append(e,t);if(typeof t=="number")return r.append(e,`${t}`);if(t==null)return r.append(e,"");_(t,r,e)}function m(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var ue=(r,e,t,s,i)=>{let n=typeof r=="string"?m(r):r;if((N(e)||s)&&!$(e)&&(e=_(e)),$(e))return[n,e];let[l,d]=de(t,n,e,i);return[m(l),d]};function de(r,e,t,s="brackets"){let i=/^https?:\/\//.test(e.toString()),n=i||e.toString().startsWith("/"),l=!n&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),d=e.toString().includes("?")||r==="get"&&Object.keys(t).length,b=e.toString().includes("#"),u=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(u.search=M.stringify(De(M.parse(u.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:s}),t={}),[[i?`${u.protocol}//${u.host}`:"",n?u.pathname:"",l?u.pathname.substring(1):"",d?u.search:"",b?u.hash:""].join(""),t]}function F(r){return r=new URL(r.href),r.hash="",r}var W=(r,e)=>{r.hash&&!e.hash&&F(r).href===e.href&&(e.hash=r.hash)},k=(r,e)=>F(r).href===F(e).href;import{BROWSER as Te}from"esm-env";import _e from"deepmerge";function h(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var Q=r=>(h(`${r.frame}:before`,{detail:{visit:r}}),h("before",{cancelable:!0,detail:{visit:r}})),he=r=>h("error",{detail:{errors:r}}),me=r=>h("exception",{cancelable:!0,detail:{exception:r}}),fe=r=>(h(`${r.frame}:finish`,{detail:{visit:r}}),h("finish",{detail:{visit:r}})),ge=r=>h("invalid",{cancelable:!0,detail:{response:r}}),E=r=>h("navigate",{detail:{page:r}}),be=r=>h("progress",{detail:{progress:r}}),ve=r=>(h(`${r.frame}:start`,{detail:{visit:r}}),h("start",{detail:{visit:r}})),ye=r=>h("success",{detail:{page:r}}),Pe=(r,e)=>h("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),we=r=>(h(`${r.frame}:prefetching`,{detail:{visit:r}}),h("prefetching",{detail:{visit:r}}));import $e from"deepmerge";var p=class{static set(e,t){typeof window<"u"&&window.sessionStorage.setItem(e,JSON.stringify(t))}static get(e){if(typeof window<"u")return JSON.parse(window.sessionStorage.getItem(e)||"null")}static merge(e,t){let s=this.get(e);s===null?this.set(e,t):this.set(e,{...s,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let s=this.get(e);s!==null&&(delete s[t],this.set(e,s))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};p.locationVisitKey="inertiaLocationVisit";var Ee=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Fe(),t=await Re(),s=await Ke(t);if(!s)throw new Error("Unable to encrypt history");return await Ne(e,s,r)},R={key:"historyKey",iv:"historyIv"},Se=async r=>{let e=Fe(),t=await Re();if(!t)throw new Error("Unable to decrypt history");return await Me(e,t,r)},Ne=async(r,e,t)=>{if(typeof window>"u")throw new Error("Unable to encrypt history");if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=new TextEncoder,i=JSON.stringify(t),n=new Uint8Array(i.length*3),l=s.encodeInto(i,n);return window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,n.subarray(0,l.written))},Me=async(r,e,t)=>{if(typeof window.crypto.subtle>"u")return console.warn("Decryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t),i=new TextDecoder().decode(s);return JSON.parse(i)},Fe=()=>{let r=p.get(R.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return p.set(R.iv,Array.from(e)),e},Ge=async()=>typeof window.crypto.subtle>"u"?(console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(null)):window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),Be=async r=>{if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve();let e=await window.crypto.subtle.exportKey("raw",r);p.set(R.key,Array.from(new Uint8Array(e)))},Ke=async r=>{if(r)return r;let e=await Ge();return e?(await Be(e),e):null},Re=async()=>{let r=p.get(R.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var f=class{static save(){a.saveScrollRegions(Array.from(this.regions()).map(e=>({top:e.scrollTop,left:e.scrollLeft})))}static regions(){return document.querySelectorAll("[scroll-region]")}static reset(){typeof window<"u"&&window.scrollTo(0,0),this.regions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.save(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}static restore(e){e.scrollRegions&&this.regions().forEach((t,s)=>{let i=e.scrollRegions[s];i&&(typeof t.scrollTo=="function"?t.scrollTo(i.left,i.top):(t.scrollTop=i.top,t.scrollLeft=i.left))})}static onScroll(e){let t=e.target;(typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")||t==document)&&this.save()}};import je from"deepmerge";var X=class{constructor(){this.page={frames:{},version:null,scrollRegions:[]};this.ignoredFrames=[];this.swappers={};this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}initFrame(e,{frame:t,initialState:s,swapComponent:i}){var l;(l=this.page).version||(l.version=s?.version);let n=this.page.frames?.[t];return s?.component&&e&&this.merge({frames:{[t]:s,...this.page.frames}}),this.swappers[t]=i,e||this.ignoredFrames.push(t),n}async set(e,{replace:t,preserveScroll:s=!1,forgetState:i=!1,frame:n}={}){this.componentId={};let l=this.componentId;return this.resolve(e.frames).then(d=>{if(l===this.componentId){if(e.scrollRegions??(e.scrollRegions=[]),e.frames._top?.url===void 0){let b=typeof window<"u"?window.location:new URL(e.frames._top.url);t=t||k(m(e.frames._top?.url),b)}if(n&&!this.ignoredFrames.includes(n)&&(t?a.replaceState(e):a.pushState(e,n)),this.page=e,this.cleared=!1,this.isFirstPageLoad){this.isFirstPageLoad=!1,this.fireEventsFor("firstLoad");return}return this.swap({components:d,page:e,forgetState:i,frame:n}).then(()=>{s||f.reset(),y.fireInternalEvent("loadDeferredProps"),t||E(e)})}})}destroy(e){delete this.page.frames[e],delete this.swappers[e],this.ignoredFrames.includes(e)||a.replaceState(this.page),this.ignoredFrames=this.ignoredFrames.filter(t=>t!==e)}async setQuietly(e,{forgetState:t=!1}={}){return this.resolve(e.frames).then(s=>(this.page=e,this.cleared=!1,this.swap({components:s,page:e,forgetState:t})))}async setFrame(e,t,s={}){return this.set({...this.page,frames:{...this.page.frames,[e]:t}},{frame:e,...s})}clear(){this.cleared=!0}isCleared(){return this.cleared}frame(e){return this.page.frames[e]||{}}get(){return this.page}merge(e){this.page=je(this.page,e,{arrayMerge:(t,s)=>s})}setUrlHash(e){this.page.frames._top.url+=e}remember(e,t){this.page.frames[e].rememberedState=t}scrollRegions(e){this.page.scrollRegions=e}swap({components:e,page:t,forgetState:s,frame:i}){return Promise.all(Object.entries(e).map(([n,l])=>{if(i&&i!==n)return Promise.resolve();if(this.swappers[n])return this.swappers[n]({component:l,frame:t.frames[n],forgetState:s})}))}async resolve(e){let t={};return await Promise.all(Object.keys(e).map(async s=>{let i=e[s];t[s]=await I.resolveComponent(i.component)})),t}isTheSame(e,t){return this.page.frames[e].component===t.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(s=>s.event!==e&&s.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},o=new X;var G=typeof window>"u",J=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.queue=[]}remember(e,t,s){let i=o.get(),n=$e(i,{frames:{[e]:{rememberedState:{[s]:t}}}},{arrayMerge:(l,d)=>d});this.replaceState(n)}restore(e,t){if(!G)return this.current?.frames?.[e]?.rememberedState?.[t]}pushState(e,t){G||this.preserveUrl||(this.current=e,this.lastUpdatedFrame=t,this.addToQueue(()=>this.getPageData(e).then(s=>{window.history.pushState({page:s,timestamp:Date.now(),updatedFrame:t},"",e.frames._top.url)})))}getPageData(e){return new Promise(t=>J.encryptHistory?Ee(e).then(t):t(e))}processQueue(){let e=this.queue.shift();return e?e().then(()=>this.processQueue()):Promise.resolve()}decrypt(e=null){if(G)return Promise.resolve(e??o.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(s=>{if(!s)throw new Error("Unable to decrypt history");return this.current=s??{},{...s,scrollRegions:window.history.state?.scrollRegions??[]}})}decryptPageData(e){return e instanceof ArrayBuffer?Se(e):Promise.resolve(e)}saveScrollRegions(e){window.history.replaceState({...window.history.state,scrollRegions:e},"")}replaceState(e){o.merge(e),!(G||this.preserveUrl)&&(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.replaceState({...window.history.state,page:t,timestamp:Date.now()},"",e.frames._top.url)})))}addToQueue(e){this.queue.push(e),this.processQueue()}getState(e,t){return this.current?.[e]??t}deleteRememberedState(){this.current.frames&&(Object.values(this.current.frames).forEach(e=>{delete e.rememberedState}),this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){p.remove(R.key),p.remove(R.iv)}isValidState(e){return!!e.page}getAllState(){return this.current}},x=J;x.encryptHistory=!1;var a=new x;var z=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),typeof document<"u"&&document.addEventListener("scroll",V(f.onScroll.bind(f),100),!0)}onGlobalEvent(e,t){let s=i=>{let n=t(i);i.cancelable&&!i.defaultPrevented&&n===!1&&i.preventDefault()};return this.registerListener(`inertia:${e}`,s)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(s=>s.listener!==t)}}onMissingHistoryItem(){o.clear(),this.fireInternalEvent("missingHistoryItem")}fireInternalEvent(e){this.internalListeners.filter(t=>t.event===e).forEach(t=>t.listener())}registerListener(e,t){return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}handlePopstateEvent(e){let t=e.state||null;if(t===null){let s=m(o.frame("_top").url);s.hash=window.location.hash,a.replaceState(_e(o.get(),{frames:{_top:{url:s.href}}},{arrayMerge:(i,n)=>n})),f.reset();return}if(a.isValidState(t)){a.decrypt(t.page).then(s=>{o.setQuietly(s,{forgetState:a.lastUpdatedFrame}).then(()=>{f.restore(o.get()),E(o.get())}),a.lastUpdatedFrame=window.history.state?.updatedFrame}).catch(()=>{this.onMissingHistoryItem()});return}}},y=new z;var Y=class{constructor(){typeof window<"u"&&window?.performance.getEntriesByType("navigation").length>0?this.type=window.performance.getEntriesByType("navigation")[0].type:this.type="navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},Z=new Y;var B=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){Z.isReload()&&a.deleteRememberedState()}static handleBackForward(){return!Z.isBackForward()||!a.hasAnyState()||!window.history.state?.page?!1:(a.decrypt().then(e=>{o.set(e,{preserveScroll:!0,forgetState:!1,replace:!0}).then(()=>{f.restore(o.get()),E(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0)}static handleLocation(){if(!p.exists(p.locationVisitKey))return!1;let e=p.get(p.locationVisitKey)||{};return p.remove(p.locationVisitKey),typeof window<"u"&&o.setUrlHash(window.location.hash),a.decrypt().then(()=>{let t=a.getState("frames",{}),s=a.getState(a.scrollRegions,[]);Object.entries(t).forEach(([i,n])=>{o.remember(i,n.rememberedState)}),o.scrollRegions(s),o.set(o.get(),{preserveScroll:e.preserveScroll,forgetState:!1}).then(()=>{e.preserveScroll||f.restore(o.get()),E(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&o.setUrlHash(window.location.hash),o.set(o.get(),{frame:"_top",forgetState:!1,replace:!0}).then(()=>{E(o.get())})}};var K=class{constructor(e,t,s){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=s.keepAlive??!1,this.cb=t,this.interval=e,(s.autoStart??!0)&&this.start()}stop(){this.id&&clearInterval(this.id)}start(){typeof window>"u"||(this.stop(),this.id=window.setInterval(()=>{(!this.throttle||this.cbCount%10===0)&&this.cb(),this.throttle&&this.cbCount++},this.interval))}isInBackground(e){this.throttle=this.keepAlive?!1:e,this.throttle&&(this.cbCount=0)}};var ee=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,s){let i=new K(e,t,s);return this.polls.push(i),{stop:()=>i.stop(),start:()=>i.start()}}clear(){this.polls.forEach(e=>e.stop()),this.polls=[]}setupVisibilityListener(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{this.polls.forEach(e=>e.isInBackground(document.hidden))},!1)}},xe=new ee;var te=(r,e,t)=>{if(r===e)return!0;for(let s in r)if(!t.includes(s)&&r[s]!==e[s]&&!We(r[s],e[s]))return!1;return!0},We=(r,e)=>{switch(typeof r){case"object":return te(r,e,[]);case"function":return r.toString()===e.toString();default:return r===e}};var Qe={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},re=r=>{if(typeof r=="number")return r;for(let[e,t]of Object.entries(Qe))if(r.endsWith(e))return parseFloat(r)*t;return parseInt(r)};var se=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:s}){if(this.findInFlight(e))return Promise.resolve();let n=this.findCached(e);if(!e.fresh&&n&&n.staleTimestamp>Date.now())return Promise.resolve();let[l,d]=this.extractStaleValues(s),b=new Promise((u,c)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),c()},onError:g=>{this.remove(e),e.onError(g),c()},onPrefetching(g){e.onPrefetching(g)},onPrefetched(g,j){e.onPrefetched(g,j)},onPrefetchResponse(g){u(g)}})}).then(u=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+l,response:b,singleUse:s===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,d),this.inFlightRequests=this.inFlightRequests.filter(c=>!this.paramsAreEqual(c.params,e)),u.handlePrefetch(),u));return this.inFlightRequests.push({params:{...e},response:b,staleTimestamp:null,inFlight:!0}),b}removeAll(){this.cached=[],this.removalTimers.forEach(e=>{clearTimeout(e.timer)}),this.removalTimers=[]}remove(e){this.cached=this.cached.filter(t=>!this.paramsAreEqual(t.params,e)),this.clearTimer(e)}extractStaleValues(e){let[t,s]=this.cacheForToStaleAndExpires(e);return[re(t),re(s)]}cacheForToStaleAndExpires(e){if(!Array.isArray(e))return[e,e];switch(e.length){case 0:return[0,0];case 1:return[e[0],e[0]];default:return[e[0],e[1]]}}clearTimer(e){let t=this.removalTimers.find(s=>this.paramsAreEqual(s.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(s=>s!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let s=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:s})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let s=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=s,e.response.then(i=>{if(this.currentUseId===s)return i.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),i.handle()})}removeSingleUseItems(e){this.cached=this.cached.filter(t=>this.paramsAreEqual(t.params,e)?!t.singleUse:!0)}findCached(e){return this.cached.find(t=>this.paramsAreEqual(t.params,e))||null}findInFlight(e){return this.inFlightRequests.find(t=>this.paramsAreEqual(t.params,e))||null}paramsAreEqual(e,t){return te(e,t,["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},S=new se;import{default as Ce}from"axios";var T=class{constructor(e){this.callbacks=[];if(!e.prefetch)this.params=e;else{let t={onBefore:this.wrapCallback(e,"onBefore"),onStart:this.wrapCallback(e,"onStart"),onProgress:this.wrapCallback(e,"onProgress"),onFinish:this.wrapCallback(e,"onFinish"),onCancel:this.wrapCallback(e,"onCancel"),onSuccess:this.wrapCallback(e,"onSuccess"),onError:this.wrapCallback(e,"onError"),onCancelToken:this.wrapCallback(e,"onCancelToken"),onPrefetched:this.wrapCallback(e,"onPrefetched"),onPrefetching:this.wrapCallback(e,"onPrefetching")};this.params={...e,...t,onPrefetchResponse:e.onPrefetchResponse||(()=>{})}}}static create(e){return new T(e)}data(){return this.params.method==="get"?{}:this.params.data}queryParams(){return this.params.method==="get"?this.params.data:{}}isPartial(){return this.params.only.length>0||this.params.except.length>0||this.params.reset.length>0}onCancelToken(e){this.params.onCancelToken({cancel:e})}markAsFinished(){this.params.completed=!0,this.params.cancelled=!1,this.params.interrupted=!1}markAsCancelled({cancelled:e=!0,interrupted:t=!1}){this.params.onCancel(),this.params.completed=!1,this.params.cancelled=e,this.params.interrupted=t}wasCancelledAtAll(){return this.params.cancelled||this.params.interrupted}onFinish(){this.params.onFinish(this.params)}onStart(){this.params.onStart(this.params)}onPrefetching(){this.params.onPrefetching(this.params)}onPrefetchResponse(e){this.params.onPrefetchResponse&&this.params.onPrefetchResponse(e)}all(){return this.params}headers(){let e={...this.params.headers};this.isPartial()&&(e["X-Inertia-Partial-Component"]=o.frame(this.params.frame).component);let t=this.params.only.concat(this.params.reset);return t.length>0&&(e["X-Inertia-Partial-Data"]=t.join(",")),this.params.except.length>0&&(e["X-Inertia-Partial-Except"]=this.params.except.join(",")),this.params.reset.length>0&&(e["X-Inertia-Reset"]=this.params.reset.join(",")),this.params.errorBag&&this.params.errorBag.length>0&&(e["X-Inertia-Error-Bag"]=this.params.errorBag),e}setPreserveOptions(e){this.params.preserveScroll=this.resolvePreserveOption(this.params.preserveScroll,e),this.params.forgetState=this.resolvePreserveOption(this.params.forgetState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...s)=>{this.recordCallback(t,s),e[t](...s)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.frames[this.params.frame].props.errors||{}).length>0:e}};var qe={modal:null,listener:null,show(r){typeof r=="object"&&(r=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(r)}`);let e=document.createElement("html");e.innerHTML=r,e.querySelectorAll("a").forEach(s=>s.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(r){r.keyCode===27&&this.hide()}};var ie=class{constructor(){this.queue=[];this.processing=!1}add(e){this.queue.push(e)}async process(){return this.processing||(this.processing=!0,await this.processQueue(),this.processing=!1),Promise.resolve()}async processQueue(){let e=this.queue.shift();return e?(await e.process(),this.processQueue()):Promise.resolve()}},Ae=new ie,q=class{constructor(e,t,s){this.requestParams=e;this.response=t;this.originatingPage=s}static create(e,t,s){return new q(e,t,s)}async handlePrefetch(){k(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return Ae.add(this),Ae.process()}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),Pe(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await a.processQueue(),a.preserveUrl=this.requestParams.all().preserveUrl,await this.setFrame();let e=this.response.headers["x-inertia-frame"]||this.requestParams.all().frame,t=o.frame(e).props.errors||{};if(Object.keys(t).length>0){let s=this.getScopedErrors(t);return he(s),this.requestParams.all().onError(s)}ye(o.get()),await this.requestParams.all().onSuccess(o.get()),a.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=m(this.getHeader("x-inertia-location"));return W(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(ge(e))return qe.show(e.data)}isInertiaResponse(){return this.hasHeader("x-inertia")}hasStatus(e){return this.response.status===e}getHeader(e){return this.response.headers[e]}hasHeader(e){return this.getHeader(e)!==void 0}isLocationVisit(){return this.hasStatus(409)&&this.hasHeader("x-inertia-location")}locationVisit(e){try{if(p.set(p.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;k(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setFrame(){let e=this.getDataFromResponse(this.response.data);if(!this.shouldSetFrame(e))return Promise.resolve();this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=a.preserveUrl?o.frame("_top").url:this.pageUrl(e),delete e.version;let t=this.response.headers["x-inertia-frame"]||this.requestParams.all().frame;return x.encryptHistory=e.encryptHistory,e.clearHistory&&a.clear(),o.setFrame(t,e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,forgetState:this.requestParams.all().forgetState})}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetFrame(e){let t=this.requestParams.all().frame;if(!this.requestParams.all().async||this.originatingPage.frames[t]?.component!==e.component)return!0;if(this.originatingPage.frames[t]?.component!==o.frame(t).component)return!1;let s=m(this.originatingPage.frames._top.url),i=m(o.frame("_top").url);return s.origin===i.origin&&s.pathname===i.pathname}pageUrl(e){let t=m(e.url);return W(this.requestParams.all().url,t),t.href.split(t.host).pop()}mergeProps(e){let t=this.requestParams.all().frame;this.requestParams.isPartial()&&e.component===o.frame(t).component&&((e.mergeProps||[]).forEach(i=>{let n=e.props[i];Array.isArray(n)?e.props[i]=[...o.frame(t).props[i]||[],...n]:typeof n=="object"&&(e.props[i]={...o.frame(t).props[i]||[],...n})}),e.props={...o.frame(t).props,...e.props})}async setRememberedState(e){let t=await a.getState("frames",{}),s=this.requestParams.all().frame,i=t[s]?.rememberedState||{};this.requestParams.all().forgetState&&i&&e.component===o.frame(s).component&&(e.rememberedState=i)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var A=class{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=T.create(e),this.cancelToken=new AbortController}static create(e,t){return new A(e,t)}async send(){this.requestParams.onCancelToken(()=>this.cancel({cancelled:!0})),ve(this.requestParams.all()),this.requestParams.onStart(),this.requestParams.all().prefetch&&(this.requestParams.onPrefetching(),we(this.requestParams.all()));let e=this.requestParams.all().prefetch;return Ce({method:this.requestParams.all().method,url:F(this.requestParams.all().url).href,data:this.requestParams.data(),params:this.requestParams.queryParams(),signal:this.cancelToken.signal,headers:this.getHeaders(),onUploadProgress:this.onProgress.bind(this),responseType:"text"}).then(t=>(this.response=q.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=q.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!Ce.isCancel(t)&&me(t))return Promise.reject(t)}).finally(()=>{this.finish(),e&&this.response&&this.requestParams.onPrefetchResponse(this.response)})}finish(){this.requestParams.wasCancelledAtAll()||(this.requestParams.markAsFinished(),this.fireFinishEvents())}fireFinishEvents(){this.requestHasFinished||(this.requestHasFinished=!0,fe(this.requestParams.all()),this.requestParams.onFinish())}cancel({cancelled:e=!1,interrupted:t=!1}){this.requestHasFinished||(this.cancelToken.abort(),this.requestParams.markAsCancelled({cancelled:e,interrupted:t}),this.fireFinishEvents())}onProgress(e){this.requestParams.data()instanceof FormData&&(e.percentage=e.progress?Math.round(e.progress*100):0,be(e),this.requestParams.all().onProgress(e))}getHeaders(){let e={...this.requestParams.headers(),Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},t=this.requestParams.all().frame,s=o.frame(t).url;return s&&(e["X-Inertia-Referer"]=F(m(s)).href),o.get().version&&(e["X-Inertia-Version"]=o.get().version),e}};var O=class{constructor({maxConcurrent:e,interruptible:t}){this.requests=[];this.maxConcurrent=e,this.interruptible=t}send(e){this.requests.push(e),e.send().then(()=>{this.requests=this.requests.filter(t=>t!==e)})}interruptInFlight(){this.cancel({interrupted:!0},!1)}cancelInFlight(){this.cancel({cancelled:!0},!0)}cancel({cancelled:e=!1,interrupted:t=!1}={},s){if(!this.shouldCancel(s))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var I=class{constructor(){this.frame="_top";this.syncRequestStream=new O({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new O({maxConcurrent:1/0,interruptible:!1})}init(e,{frame:t,initialState:s,swapComponent:i}){if(this.frame=t,!Te)return;let n=o.initFrame(e,{frame:t,initialState:s,swapComponent:i});return t!=="_top"||(B.handle(),y.init(),y.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{forgetState:!1,preserveScroll:!0,replace:!0})}),y.on("loadDeferredProps",()=>{this.loadDeferredProps()})),n}destroy(){o.destroy(this.frame)}get(e,t={},s={}){return this.visit(e,{...s,method:"get",data:t})}post(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"post",data:t})}put(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"put",data:t})}patch(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{forgetState:!1,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,forgetState:this.frame,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){a.remember(this.frame,e,t)}restore(e="default"){return a.restore(this.frame,e)}on(e,t){return y.onGlobalEvent(`${this.frame}:${e}`,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},s={}){return xe.add(e,()=>this.reload(t),{autoStart:s.autoStart??!0,keepAlive:s.keepAlive??!1})}visit(e,t={}){if(!Te)return;let s=this.getPendingVisit(e,{...t,preserveScroll:t.preserveScroll??this.frame!=="_top",forgetState:t.forgetState??this.frame,showProgress:t.showProgress??!t.async}),i=this.getVisitEvents(t);if(i.onBefore(s)===!1||!Q(s))return;let n=s.async?this.asyncRequestStream:this.syncRequestStream;n.interruptInFlight(),!o.isCleared()&&!s.preserveUrl&&f.save();let l={...s,...i},d=S.get(l);d?(H(d.inFlight),S.use(d,l)):(H(!0),n.send(A.create(l,o.get())))}getCached(e,t={}){return S.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){S.remove(this.getPrefetchParams(e,t))}flushAll(){S.removeAll()}getPrefetching(e,t={}){return S.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:s}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let i=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),n=this.getVisitEvents(t);if(n.onBefore(i)===!1||!Q(i))return;D(),this.asyncRequestStream.interruptInFlight();let l={...i,...n};S.add(l,d=>{this.asyncRequestStream.send(A.create(d,o.get()))},{cacheFor:s})}clearHistory(){a.clear()}decryptHistory(){return a.decrypt()}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,s={}){let i={method:"get",data:{},replace:!1,preserveScroll:!1,forgetState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,frame:this.frame,...t},[n,l]=ue(e,i.data,i.method,i.forceFormData,i.queryStringArrayFormat);return{cancelled:!1,completed:!1,interrupted:!1,...i,...s,url:n,data:l}}getVisitEvents(e){return{onCancelToken:e.onCancelToken||(()=>{}),onBefore:e.onBefore||(()=>{}),onStart:e.onStart||(()=>{}),onProgress:e.onProgress||(()=>{}),onFinish:e.onFinish||(()=>{}),onCancel:e.onCancel||(()=>{}),onSuccess:e.onSuccess||(()=>{}),onError:e.onError||(()=>{}),onPrefetched:e.onPrefetched||(()=>{}),onPrefetching:e.onPrefetching||(()=>{})}}loadDeferredProps(){let e=o.frame(this.frame)?.deferredProps;e&&Object.entries(e).forEach(([t,s])=>{this.reload({only:s})})}};export{x as History,I as Router,oe as createHeadManager,D as hideProgress,a as history,m as hrefToUrl,de as mergeDataIntoQueryString,H as revealProgress,ae as setupProgress,le as shouldIntercept,F as urlWithoutHash}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -72,3 +72,3 @@ "use strict";var De=Object.create;var N=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Ge=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var Ke=(r,e)=>{for(var t in e)N(r,t,{get:e[t],enumerable:!0})},me=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Me(e))!Be.call(r,i)&&i!==t&&N(r,i,{get:()=>e[i],enumerable:!(s=Ne(e,i))||s.enumerable});return r};var x=(r,e,t)=>(t=r!=null?De(Ge(r)):{},me(e||!r||!r.__esModule?N(t,"default",{value:r,enumerable:!0}):t,r)),je=r=>me(N({},"__esModule",{value:!0}),r);var nt={};Ke(nt,{History:()=>F,Router:()=>V,createHeadManager:()=>W,hideProgress:()=>L,history:()=>a,hrefToUrl:()=>h,mergeDataIntoQueryString:()=>Y,revealProgress:()=>O,setupProgress:()=>Q,shouldIntercept:()=>X,urlWithoutHash:()=>E});module.exports=je(nt);function I(r,e){let t;return function(...s){clearTimeout(t),t=setTimeout(()=>r.apply(this,s),e)}}var $e={buildDOMElement(r){let e=document.createElement("template");e.innerHTML=r;let t=e.content.firstChild;if(!r.startsWith("<script "))return t;let s=document.createElement("script");return s.innerHTML=t.innerHTML,t.getAttributeNames().forEach(i=>{s.setAttribute(i,t.getAttribute(i)||"")}),s},isInertiaManagedElement(r){return r.nodeType===Node.ELEMENT_NODE&&r.getAttribute("inertia")!==null},findMatchingElementIndex(r,e){let t=r.getAttribute("inertia");return t!==null?e.findIndex(s=>s.getAttribute("inertia")===t):-1},update:I(function(r){let e=r.map(s=>this.buildDOMElement(s));Array.from(document.head.childNodes).filter(s=>this.isInertiaManagedElement(s)).forEach(s=>{let i=this.findMatchingElementIndex(s,e);if(i===-1){s?.parentNode?.removeChild(s);return}let n=e.splice(i,1)[0];n&&!s.isEqualNode(n)&&s?.parentNode?.replaceChild(n,s)}),e.forEach(s=>document.head.appendChild(s))},1)};function W(r,e,t){let s={},i=0;function n(){let c=i+=1;return s[c]=[],c.toString()}function l(c){c===null||Object.keys(s).indexOf(c)===-1||(delete s[c],u())}function d(c,g=[]){c!==null&&Object.keys(s).indexOf(c)>-1&&(s[c]=g),u()}function v(){let c=e(""),g={...c?{title:`<title inertia="">${c}</title>`}:{}},_=Object.values(s).reduce((P,w)=>P.concat(w),[]).reduce((P,w)=>{if(w.indexOf("<")===-1)return P;if(w.indexOf("<title ")===0){let D=w.match(/(<title [^>]+>)(.*?)(<\/title>)/);return P.title=D?`${D[1]}${e(D[2])}${D[3]}`:w,P}let he=w.match(/ inertia="[^"]+"/);return he?P[he[0]]=w:P[Object.keys(P).length]=w,P},g);return Object.values(_)}function u(){r?t(v()):$e.update(v())}return u(),{forceUpdate:u,createProvider:function(){let c=n();return{update:g=>d(c,g),disconnect:()=>l(c)}}}}var b=x(require("nprogress"),1),T=(()=>{if(typeof document>"u")return null;let r=document.createElement("style");return r.innerHTML="#nprogress { display: none; }",r})(),M=0,_e=()=>{if(T&&document.head.contains(T))return document.head.removeChild(T)},O=(r=!1)=>{M=Math.max(0,M-1),(r||M===0)&&_e()},L=()=>{M++,T&&!document.head.contains(T)&&document.head.appendChild(T)};function We(r){document.addEventListener("inertia:start",e=>Qe(e,r)),document.addEventListener("inertia:progress",Xe)}function Qe(r,e){r.detail.visit.showProgress||L();let t=setTimeout(()=>b.default.start(),e);document.addEventListener("inertia:finish",s=>Je(s,t),{once:!0})}function Xe(r){b.default.isStarted()&&r.detail.progress?.percentage&&b.default.set(Math.max(b.default.status,r.detail.progress.percentage/100*.9))}function Je(r,e){clearTimeout(e),b.default.isStarted()&&(r.detail.visit.completed?b.default.done():r.detail.visit.interrupted?b.default.set(0):r.detail.visit.cancelled&&(b.default.done(),b.default.remove()))}function ze(r){let e=document.createElement("style");e.textContent=` | ||
} | ||
`,document.head.appendChild(e)}function Q({delay:r=250,color:e="#29d",includeCSS:t=!0,showSpinner:s=!1}={}){We(r),b.default.configure({showSpinner:s}),t&&ze(e)}function X(r){let e=r.currentTarget.tagName.toLowerCase()==="a";return!(r.target&&(r?.target).isContentEditable||r.defaultPrevented||e&&r.which>1||e&&r.altKey||e&&r.ctrlKey||e&&r.metaKey||e&&r.shiftKey||e&&"button"in r&&r.button!==0)}var be=x(require("deepmerge"),1),B=x(require("qs"),1);function G(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>G(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>G(e))}var J=r=>r instanceof FormData;function z(r,e=new FormData,t=null){r=r||{};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&ge(e,fe(t,s),r[s]);return e}function fe(r,e){return r?r+"["+e+"]":e}function ge(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(s=>ge(r,fe(e,s.toString()),t[s]));if(t instanceof Date)return r.append(e,t.toISOString());if(t instanceof File)return r.append(e,t,t.name);if(t instanceof Blob)return r.append(e,t);if(typeof t=="boolean")return r.append(e,t?"1":"0");if(typeof t=="string")return r.append(e,t);if(typeof t=="number")return r.append(e,`${t}`);if(t==null)return r.append(e,"");z(t,r,e)}function h(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var ve=(r,e,t,s,i)=>{let n=typeof r=="string"?h(r):r;if((G(e)||s)&&!J(e)&&(e=z(e)),J(e))return[n,e];let[l,d]=Y(t,n,e,i);return[h(l),d]};function Y(r,e,t,s="brackets"){let i=/^https?:\/\//.test(e.toString()),n=i||e.toString().startsWith("/"),l=!n&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),d=e.toString().includes("?")||r==="get"&&Object.keys(t).length,v=e.toString().includes("#"),u=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(u.search=B.stringify((0,be.default)(B.parse(u.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:s}),t={}),[[i?`${u.protocol}//${u.host}`:"",n?u.pathname:"",l?u.pathname.substring(1):"",d?u.search:"",v?u.hash:""].join(""),t]}function E(r){return r=new URL(r.href),r.hash="",r}var Z=(r,e)=>{r.hash&&!e.hash&&E(r).href===e.href&&(e.hash=r.hash)},U=(r,e)=>E(r).href===E(e).href;var de=require("esm-env");var Oe=x(require("deepmerge"),1);function m(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var ee=r=>(m(`${r.frame}:before`,{detail:{visit:r}}),m("before",{cancelable:!0,detail:{visit:r}})),ye=r=>m("error",{detail:{errors:r}}),Pe=r=>m("exception",{cancelable:!0,detail:{exception:r}}),we=r=>(m(`${r.frame}:finish`,{detail:{visit:r}}),m("finish",{detail:{visit:r}})),Ee=r=>m("invalid",{cancelable:!0,detail:{response:r}}),S=r=>m("navigate",{detail:{page:r}}),Se=r=>m("progress",{detail:{progress:r}}),Fe=r=>(m(`${r.frame}:start`,{detail:{visit:r}}),m("start",{detail:{visit:r}})),Re=r=>m("success",{detail:{page:r}}),xe=(r,e)=>m("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),qe=r=>(m(`${r.frame}:prefetching`,{detail:{visit:r}}),m("prefetching",{detail:{visit:r}}));var Ie=x(require("deepmerge"),1);var p=class{static set(e,t){typeof window<"u"&&window.sessionStorage.setItem(e,JSON.stringify(t))}static get(e){if(typeof window<"u")return JSON.parse(window.sessionStorage.getItem(e)||"null")}static merge(e,t){let s=this.get(e);s===null?this.set(e,t):this.set(e,{...s,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let s=this.get(e);s!==null&&(delete s[t],this.set(e,s))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};p.locationVisitKey="inertiaLocationVisit";var Ae=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Te(),t=await Ve(),s=await rt(t);if(!s)throw new Error("Unable to encrypt history");return await Ye(e,s,r)},q={key:"historyKey",iv:"historyIv"},Ce=async r=>{let e=Te(),t=await Ve();if(!t)throw new Error("Unable to decrypt history");return await Ze(e,t,r)},Ye=async(r,e,t)=>{if(typeof window>"u")throw new Error("Unable to encrypt history");if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=new TextEncoder,i=JSON.stringify(t),n=new Uint8Array(i.length*3),l=s.encodeInto(i,n);return window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,n.subarray(0,l.written))},Ze=async(r,e,t)=>{if(typeof window.crypto.subtle>"u")return console.warn("Decryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t),i=new TextDecoder().decode(s);return JSON.parse(i)},Te=()=>{let r=p.get(q.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return p.set(q.iv,Array.from(e)),e},et=async()=>typeof window.crypto.subtle>"u"?(console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(null)):window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),tt=async r=>{if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve();let e=await window.crypto.subtle.exportKey("raw",r);p.set(q.key,Array.from(new Uint8Array(e)))},rt=async r=>{if(r)return r;let e=await et();return e?(await tt(e),e):null},Ve=async()=>{let r=p.get(q.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var f=class{static save(){a.saveScrollRegions(Array.from(this.regions()).map(e=>({top:e.scrollTop,left:e.scrollLeft})))}static regions(){return document.querySelectorAll("[scroll-region]")}static reset(){typeof window<"u"&&window.scrollTo(0,0),this.regions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.save(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}static restore(e){e.scrollRegions&&this.regions().forEach((t,s)=>{let i=e.scrollRegions[s];i&&(typeof t.scrollTo=="function"?t.scrollTo(i.left,i.top):(t.scrollTop=i.top,t.scrollLeft=i.left))})}static onScroll(e){let t=e.target;(typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")||t==document)&&this.save()}};var ke=x(require("deepmerge"),1),te=class{constructor(){this.page={frames:{},version:null,scrollRegions:[]};this.ignoredFrames=[];this.swappers={};this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}initFrame(e,{frame:t,initialState:s,swapComponent:i}){var l;(l=this.page).version||(l.version=s?.version);let n=this.page.frames?.[t];return s?.component&&e&&this.merge({frames:{[t]:s,...this.page.frames}}),this.swappers[t]=i,e||this.ignoredFrames.push(t),n}async set(e,{replace:t,preserveScroll:s=!1,forgetState:i=!1,frame:n}={}){this.componentId={};let l=this.componentId;return this.resolve(e.frames).then(d=>{if(l===this.componentId){if(e.scrollRegions??(e.scrollRegions=[]),e.frames._top?.url===void 0){let v=typeof window<"u"?window.location:new URL(e.frames._top.url);t=t||U(h(e.frames._top?.url),v)}if(n&&!this.ignoredFrames.includes(n)&&(t?a.replaceState(e):a.pushState(e,n)),this.page=e,this.cleared=!1,this.isFirstPageLoad){this.isFirstPageLoad=!1,this.fireEventsFor("firstLoad");return}return this.swap({components:d,page:e,forgetState:i,frame:n}).then(()=>{s||f.reset(),y.fireInternalEvent("loadDeferredProps"),t||S(e)})}})}destroy(e){delete this.page.frames[e],delete this.swappers[e],this.ignoredFrames.includes(e)||a.replaceState(this.page),this.ignoredFrames=this.ignoredFrames.filter(t=>t!==e)}async setQuietly(e,{forgetState:t=!1}={}){return this.resolve(e.frames).then(s=>(this.page=e,this.cleared=!1,this.swap({components:s,page:e,forgetState:t})))}async setFrame(e,t,s={}){return this.set({...this.page,frames:{...this.page.frames,[e]:t}},{frame:e,...s})}clear(){this.cleared=!0}isCleared(){return this.cleared}frame(e){return this.page.frames[e]||{}}get(){return this.page}merge(e){this.page=(0,ke.default)(this.page,e,{arrayMerge:(t,s)=>s})}setUrlHash(e){this.page.frames._top.url+=e}remember(e,t){this.page.frames[e].rememberedState=t}scrollRegions(e){this.page.scrollRegions=e}swap({components:e,page:t,forgetState:s,frame:i}){return Promise.all(Object.entries(e).map(([n,l])=>{if(i&&i!==n)return Promise.resolve();if(this.swappers[n])return this.swappers[n]({component:l,frame:t.frames[n],forgetState:s})}))}async resolve(e){let t={};return await Promise.all(Object.keys(e).map(async s=>{let i=e[s];t[s]=await V.resolveComponent(i.component)})),t}isTheSame(e,t){return this.page.frames[e].component===t.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(s=>s.event!==e&&s.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},o=new te;var K=typeof window>"u",re=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.queue=[]}remember(e,t,s){let i=o.get(),n=(0,Ie.default)(i,{frames:{[e]:{rememberedState:{[s]:t}}}},{arrayMerge:(l,d)=>d});this.replaceState(n)}restore(e,t){if(!K)return this.current?.frames?.[e]?.rememberedState?.[t]}pushState(e,t){K||this.preserveUrl||(this.current=e,this.lastUpdatedFrame=t,this.addToQueue(()=>this.getPageData(e).then(s=>{window.history.pushState({page:s,timestamp:Date.now(),updatedFrame:t},"",e.frames._top.url)})))}getPageData(e){return new Promise(t=>re.encryptHistory?Ae(e).then(t):t(e))}processQueue(){let e=this.queue.shift();return e?e().then(()=>this.processQueue()):Promise.resolve()}decrypt(e=null){if(K)return Promise.resolve(e??o.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(s=>{if(!s)throw new Error("Unable to decrypt history");return this.current=s??{},{...s,scrollRegions:window.history.state?.scrollRegions??[]}})}decryptPageData(e){return e instanceof ArrayBuffer?Ce(e):Promise.resolve(e)}saveScrollRegions(e){window.history.replaceState({...window.history.state,scrollRegions:e},"")}replaceState(e){o.merge(e),!(K||this.preserveUrl)&&(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.replaceState({...window.history.state,page:t,timestamp:Date.now()},"",e.frames._top.url)})))}addToQueue(e){this.queue.push(e),this.processQueue()}getState(e,t){return this.current?.[e]??t}deleteRememberedState(){this.current.frames&&(Object.values(this.current.frames).forEach(e=>{delete e.rememberedState}),this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){p.remove(q.key),p.remove(q.iv)}isValidState(e){return!!e.page}getAllState(){return this.current}},F=re;F.encryptHistory=!1;var a=new F;var se=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),typeof document<"u"&&document.addEventListener("scroll",I(f.onScroll.bind(f),100),!0)}onGlobalEvent(e,t){let s=i=>{let n=t(i);i.cancelable&&!i.defaultPrevented&&n===!1&&i.preventDefault()};return this.registerListener(`inertia:${e}`,s)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(s=>s.listener!==t)}}onMissingHistoryItem(){o.clear(),this.fireInternalEvent("missingHistoryItem")}fireInternalEvent(e){this.internalListeners.filter(t=>t.event===e).forEach(t=>t.listener())}registerListener(e,t){return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}handlePopstateEvent(e){let t=e.state||null;if(t===null){let s=h(o.frame("_top").url);s.hash=window.location.hash,a.replaceState((0,Oe.default)(o.get(),{frames:{_top:{url:s.href}}},{arrayMerge:(i,n)=>n})),f.reset();return}if(a.isValidState(t)){a.decrypt(t.page).then(s=>{o.setQuietly(s,{forgetState:a.lastUpdatedFrame}).then(()=>{f.restore(o.get()),S(o.get())}),a.lastUpdatedFrame=window.history.state?.updatedFrame}).catch(()=>{this.onMissingHistoryItem()});return}}},y=new se;var ie=class{constructor(){typeof window<"u"&&window?.performance.getEntriesByType("navigation").length>0?this.type=window.performance.getEntriesByType("navigation")[0].type:this.type="navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},ne=new ie;var j=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){ne.isReload()&&a.deleteRememberedState()}static handleBackForward(){return!ne.isBackForward()||!a.hasAnyState()||!window.history.state?.page?!1:(a.decrypt().then(e=>{o.set(e,{preserveScroll:!0,forgetState:!1,replace:!0}).then(()=>{f.restore(o.get()),S(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0)}static handleLocation(){if(!p.exists(p.locationVisitKey))return!1;let e=p.get(p.locationVisitKey)||{};return p.remove(p.locationVisitKey),typeof window<"u"&&o.setUrlHash(window.location.hash),a.decrypt().then(()=>{let t=a.getState("frames",{}),s=a.getState(a.scrollRegions,[]);Object.entries(t).forEach(([i,n])=>{o.remember(i,n.rememberedState)}),o.scrollRegions(s),o.set(o.get(),{preserveScroll:e.preserveScroll,forgetState:!1}).then(()=>{e.preserveScroll||f.restore(o.get()),S(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&o.setUrlHash(window.location.hash),o.set(o.get(),{frame:"_top",forgetState:!1,replace:!0}).then(()=>{S(o.get())})}};var $=class{constructor(e,t,s){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=s.keepAlive??!1,this.cb=t,this.interval=e,(s.autoStart??!0)&&this.start()}stop(){this.id&&clearInterval(this.id)}start(){typeof window>"u"||(this.stop(),this.id=window.setInterval(()=>{(!this.throttle||this.cbCount%10===0)&&this.cb(),this.throttle&&this.cbCount++},this.interval))}isInBackground(e){this.throttle=this.keepAlive?!1:e,this.throttle&&(this.cbCount=0)}};var oe=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,s){let i=new $(e,t,s);return this.polls.push(i),{stop:()=>i.stop(),start:()=>i.start()}}clear(){this.polls.forEach(e=>e.stop()),this.polls=[]}setupVisibilityListener(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{this.polls.forEach(e=>e.isInBackground(document.hidden))},!1)}},Le=new oe;var ae=(r,e,t)=>{if(r===e)return!0;for(let s in r)if(!t.includes(s)&&r[s]!==e[s]&&!st(r[s],e[s]))return!1;return!0},st=(r,e)=>{switch(typeof r){case"object":return ae(r,e,[]);case"function":return r.toString()===e.toString();default:return r===e}};var it={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},le=r=>{if(typeof r=="number")return r;for(let[e,t]of Object.entries(it))if(r.endsWith(e))return parseFloat(r)*t;return parseInt(r)};var ce=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:s}){if(this.findInFlight(e))return Promise.resolve();let n=this.findCached(e);if(!e.fresh&&n&&n.staleTimestamp>Date.now())return Promise.resolve();let[l,d]=this.extractStaleValues(s),v=new Promise((u,c)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),c()},onError:g=>{this.remove(e),e.onError(g),c()},onPrefetching(g){e.onPrefetching(g)},onPrefetched(g,_){e.onPrefetched(g,_)},onPrefetchResponse(g){u(g)}})}).then(u=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+l,response:v,singleUse:s===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,d),this.inFlightRequests=this.inFlightRequests.filter(c=>!this.paramsAreEqual(c.params,e)),u.handlePrefetch(),u));return this.inFlightRequests.push({params:{...e},response:v,staleTimestamp:null,inFlight:!0}),v}removeAll(){this.cached=[],this.removalTimers.forEach(e=>{clearTimeout(e.timer)}),this.removalTimers=[]}remove(e){this.cached=this.cached.filter(t=>!this.paramsAreEqual(t.params,e)),this.clearTimer(e)}extractStaleValues(e){let[t,s]=this.cacheForToStaleAndExpires(e);return[le(t),le(s)]}cacheForToStaleAndExpires(e){if(!Array.isArray(e))return[e,e];switch(e.length){case 0:return[0,0];case 1:return[e[0],e[0]];default:return[e[0],e[1]]}}clearTimer(e){let t=this.removalTimers.find(s=>this.paramsAreEqual(s.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(s=>s!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let s=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:s})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let s=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=s,e.response.then(i=>{if(this.currentUseId===s)return i.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),i.handle()})}removeSingleUseItems(e){this.cached=this.cached.filter(t=>this.paramsAreEqual(t.params,e)?!t.singleUse:!0)}findCached(e){return this.cached.find(t=>this.paramsAreEqual(t.params,e))||null}findInFlight(e){return this.inFlightRequests.find(t=>this.paramsAreEqual(t.params,e))||null}paramsAreEqual(e,t){return ae(e,t,["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},R=new ce;var ue=x(require("axios"),1);var k=class{constructor(e){this.callbacks=[];if(!e.prefetch)this.params=e;else{let t={onBefore:this.wrapCallback(e,"onBefore"),onStart:this.wrapCallback(e,"onStart"),onProgress:this.wrapCallback(e,"onProgress"),onFinish:this.wrapCallback(e,"onFinish"),onCancel:this.wrapCallback(e,"onCancel"),onSuccess:this.wrapCallback(e,"onSuccess"),onError:this.wrapCallback(e,"onError"),onCancelToken:this.wrapCallback(e,"onCancelToken"),onPrefetched:this.wrapCallback(e,"onPrefetched"),onPrefetching:this.wrapCallback(e,"onPrefetching")};this.params={...e,...t,onPrefetchResponse:e.onPrefetchResponse||(()=>{})}}}static create(e){return new k(e)}data(){return this.params.method==="get"?{}:this.params.data}queryParams(){return this.params.method==="get"?this.params.data:{}}isPartial(){return this.params.only.length>0||this.params.except.length>0||this.params.reset.length>0}onCancelToken(e){this.params.onCancelToken({cancel:e})}markAsFinished(){this.params.completed=!0,this.params.cancelled=!1,this.params.interrupted=!1}markAsCancelled({cancelled:e=!0,interrupted:t=!1}){this.params.onCancel(),this.params.completed=!1,this.params.cancelled=e,this.params.interrupted=t}wasCancelledAtAll(){return this.params.cancelled||this.params.interrupted}onFinish(){this.params.onFinish(this.params)}onStart(){this.params.onStart(this.params)}onPrefetching(){this.params.onPrefetching(this.params)}onPrefetchResponse(e){this.params.onPrefetchResponse&&this.params.onPrefetchResponse(e)}all(){return this.params}headers(){let e={...this.params.headers};this.isPartial()&&(e["X-Inertia-Partial-Component"]=o.frame(this.params.frame).component);let t=this.params.only.concat(this.params.reset);return t.length>0&&(e["X-Inertia-Partial-Data"]=t.join(",")),this.params.except.length>0&&(e["X-Inertia-Partial-Except"]=this.params.except.join(",")),this.params.reset.length>0&&(e["X-Inertia-Reset"]=this.params.reset.join(",")),this.params.errorBag&&this.params.errorBag.length>0&&(e["X-Inertia-Error-Bag"]=this.params.errorBag),e}setPreserveOptions(e){this.params.preserveScroll=this.resolvePreserveOption(this.params.preserveScroll,e),this.params.forgetState=this.resolvePreserveOption(this.params.forgetState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...s)=>{this.recordCallback(t,s),e[t](...s)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.frames[this.params.frame].props.errors||{}).length>0:e}};var Ue={modal:null,listener:null,show(r){typeof r=="object"&&(r=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(r)}`);let e=document.createElement("html");e.innerHTML=r,e.querySelectorAll("a").forEach(s=>s.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(r){r.keyCode===27&&this.hide()}};var pe=class{constructor(){this.queue=[];this.processing=!1}add(e){this.queue.push(e)}async process(){return this.processing||(this.processing=!0,await this.processQueue(),this.processing=!1),Promise.resolve()}async processQueue(){let e=this.queue.shift();return e?(await e.process(),this.processQueue()):Promise.resolve()}},He=new pe,A=class{constructor(e,t,s){this.requestParams=e;this.response=t;this.originatingPage=s}static create(e,t,s){return new A(e,t,s)}async handlePrefetch(){U(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return He.add(this),He.process()}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),xe(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await a.processQueue(),a.preserveUrl=this.requestParams.all().preserveUrl,await this.setFrame();let e=this.requestParams.all().frame,t=o.frame(e).props.errors||{};if(Object.keys(t).length>0){let s=this.getScopedErrors(t);return ye(s),this.requestParams.all().onError(s)}Re(o.get()),await this.requestParams.all().onSuccess(o.get()),a.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=h(this.getHeader("x-inertia-location"));return Z(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(Ee(e))return Ue.show(e.data)}isInertiaResponse(){return this.hasHeader("x-inertia")}hasStatus(e){return this.response.status===e}getHeader(e){return this.response.headers[e]}hasHeader(e){return this.getHeader(e)!==void 0}isLocationVisit(){return this.hasStatus(409)&&this.hasHeader("x-inertia-location")}locationVisit(e){try{if(p.set(p.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;U(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setFrame(){let e=this.getDataFromResponse(this.response.data);return this.shouldSetFrame(e)?(this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=a.preserveUrl?o.frame("_top").url:this.pageUrl(e),delete e.version,F.encryptHistory=e.encryptHistory,e.clearHistory&&a.clear(),o.setFrame(this.requestParams.all().frame,e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,forgetState:this.requestParams.all().forgetState})):Promise.resolve()}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetFrame(e){let t=this.requestParams.all().frame;if(!this.requestParams.all().async||this.originatingPage.frames[t]?.component!==e.component)return!0;if(this.originatingPage.frames[t]?.component!==o.frame(t).component)return!1;let s=h(this.originatingPage.frames._top.url),i=h(o.frame("_top").url);return s.origin===i.origin&&s.pathname===i.pathname}pageUrl(e){let t=h(e.url);return Z(this.requestParams.all().url,t),t.href.split(t.host).pop()}mergeProps(e){let t=this.requestParams.all().frame;this.requestParams.isPartial()&&e.component===o.frame(t).component&&((e.mergeProps||[]).forEach(i=>{let n=e.props[i];Array.isArray(n)?e.props[i]=[...o.frame(t).props[i]||[],...n]:typeof n=="object"&&(e.props[i]={...o.frame(t).props[i]||[],...n})}),e.props={...o.frame(t).props,...e.props})}async setRememberedState(e){let t=await a.getState("frames",{}),s=this.requestParams.all().frame,i=t[s]?.rememberedState||{};this.requestParams.all().forgetState&&i&&e.component===o.frame(s).component&&(e.rememberedState=i)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var C=class{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=k.create(e),this.cancelToken=new AbortController}static create(e,t){return new C(e,t)}async send(){this.requestParams.onCancelToken(()=>this.cancel({cancelled:!0})),Fe(this.requestParams.all()),this.requestParams.onStart(),this.requestParams.all().prefetch&&(this.requestParams.onPrefetching(),qe(this.requestParams.all()));let e=this.requestParams.all().prefetch;return(0,ue.default)({method:this.requestParams.all().method,url:E(this.requestParams.all().url).href,data:this.requestParams.data(),params:this.requestParams.queryParams(),signal:this.cancelToken.signal,headers:this.getHeaders(),onUploadProgress:this.onProgress.bind(this),responseType:"text"}).then(t=>(this.response=A.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=A.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!ue.default.isCancel(t)&&Pe(t))return Promise.reject(t)}).finally(()=>{this.finish(),e&&this.response&&this.requestParams.onPrefetchResponse(this.response)})}finish(){this.requestParams.wasCancelledAtAll()||(this.requestParams.markAsFinished(),this.fireFinishEvents())}fireFinishEvents(){this.requestHasFinished||(this.requestHasFinished=!0,we(this.requestParams.all()),this.requestParams.onFinish())}cancel({cancelled:e=!1,interrupted:t=!1}){this.requestHasFinished||(this.cancelToken.abort(),this.requestParams.markAsCancelled({cancelled:e,interrupted:t}),this.fireFinishEvents())}onProgress(e){this.requestParams.data()instanceof FormData&&(e.percentage=e.progress?Math.round(e.progress*100):0,Se(e),this.requestParams.all().onProgress(e))}getHeaders(){let e={...this.requestParams.headers(),Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},t=this.requestParams.all().frame,s=o.frame(t).url;return s&&(e["X-Inertia-Referer"]=E(h(s)).href),o.get().version&&(e["X-Inertia-Version"]=o.get().version),e}};var H=class{constructor({maxConcurrent:e,interruptible:t}){this.requests=[];this.maxConcurrent=e,this.interruptible=t}send(e){this.requests.push(e),e.send().then(()=>{this.requests=this.requests.filter(t=>t!==e)})}interruptInFlight(){this.cancel({interrupted:!0},!1)}cancelInFlight(){this.cancel({cancelled:!0},!0)}cancel({cancelled:e=!1,interrupted:t=!1}={},s){if(!this.shouldCancel(s))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var V=class{constructor(){this.frame="_top";this.syncRequestStream=new H({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new H({maxConcurrent:1/0,interruptible:!1})}init(e,{frame:t,initialState:s,swapComponent:i}){if(this.frame=t,!de.BROWSER)return;let n=o.initFrame(e,{frame:t,initialState:s,swapComponent:i});return t!=="_top"||(j.handle(),y.init(),y.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{forgetState:!1,preserveScroll:!0,replace:!0})}),y.on("loadDeferredProps",()=>{this.loadDeferredProps()})),n}destroy(){o.destroy(this.frame)}get(e,t={},s={}){return this.visit(e,{...s,method:"get",data:t})}post(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"post",data:t})}put(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"put",data:t})}patch(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{forgetState:!1,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,forgetState:this.frame,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){a.remember(this.frame,e,t)}restore(e="default"){return a.restore(this.frame,e)}on(e,t){return y.onGlobalEvent(`${this.frame}:${e}`,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},s={}){return Le.add(e,()=>this.reload(t),{autoStart:s.autoStart??!0,keepAlive:s.keepAlive??!1})}visit(e,t={}){if(!de.BROWSER)return;let s=this.getPendingVisit(e,{...t,preserveScroll:t.preserveScroll??this.frame!=="_top",forgetState:t.forgetState??this.frame,showProgress:t.showProgress??!t.async}),i=this.getVisitEvents(t);if(i.onBefore(s)===!1||!ee(s))return;let n=s.async?this.asyncRequestStream:this.syncRequestStream;n.interruptInFlight(),!o.isCleared()&&!s.preserveUrl&&f.save();let l={...s,...i},d=R.get(l);d?(O(d.inFlight),R.use(d,l)):(O(!0),n.send(C.create(l,o.get())))}getCached(e,t={}){return R.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){R.remove(this.getPrefetchParams(e,t))}flushAll(){R.removeAll()}getPrefetching(e,t={}){return R.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:s}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let i=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),n=this.getVisitEvents(t);if(n.onBefore(i)===!1||!ee(i))return;L(),this.asyncRequestStream.interruptInFlight();let l={...i,...n};R.add(l,d=>{this.asyncRequestStream.send(C.create(d,o.get()))},{cacheFor:s})}clearHistory(){a.clear()}decryptHistory(){return a.decrypt()}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,s={}){let i={method:"get",data:{},replace:!1,preserveScroll:!1,forgetState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,frame:this.frame,...t},[n,l]=ve(e,i.data,i.method,i.forceFormData,i.queryStringArrayFormat);return{cancelled:!1,completed:!1,interrupted:!1,...i,...s,url:n,data:l}}getVisitEvents(e){return{onCancelToken:e.onCancelToken||(()=>{}),onBefore:e.onBefore||(()=>{}),onStart:e.onStart||(()=>{}),onProgress:e.onProgress||(()=>{}),onFinish:e.onFinish||(()=>{}),onCancel:e.onCancel||(()=>{}),onSuccess:e.onSuccess||(()=>{}),onError:e.onError||(()=>{}),onPrefetched:e.onPrefetched||(()=>{}),onPrefetching:e.onPrefetching||(()=>{})}}loadDeferredProps(){let e=o.frame(this.frame)?.deferredProps;e&&Object.entries(e).forEach(([t,s])=>{this.reload({only:s})})}}; | ||
`,document.head.appendChild(e)}function Q({delay:r=250,color:e="#29d",includeCSS:t=!0,showSpinner:s=!1}={}){We(r),b.default.configure({showSpinner:s}),t&&ze(e)}function X(r){let e=r.currentTarget.tagName.toLowerCase()==="a";return!(r.target&&(r?.target).isContentEditable||r.defaultPrevented||e&&r.which>1||e&&r.altKey||e&&r.ctrlKey||e&&r.metaKey||e&&r.shiftKey||e&&"button"in r&&r.button!==0)}var be=x(require("deepmerge"),1),B=x(require("qs"),1);function G(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>G(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>G(e))}var J=r=>r instanceof FormData;function z(r,e=new FormData,t=null){r=r||{};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&ge(e,fe(t,s),r[s]);return e}function fe(r,e){return r?r+"["+e+"]":e}function ge(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(s=>ge(r,fe(e,s.toString()),t[s]));if(t instanceof Date)return r.append(e,t.toISOString());if(t instanceof File)return r.append(e,t,t.name);if(t instanceof Blob)return r.append(e,t);if(typeof t=="boolean")return r.append(e,t?"1":"0");if(typeof t=="string")return r.append(e,t);if(typeof t=="number")return r.append(e,`${t}`);if(t==null)return r.append(e,"");z(t,r,e)}function h(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var ve=(r,e,t,s,i)=>{let n=typeof r=="string"?h(r):r;if((G(e)||s)&&!J(e)&&(e=z(e)),J(e))return[n,e];let[l,d]=Y(t,n,e,i);return[h(l),d]};function Y(r,e,t,s="brackets"){let i=/^https?:\/\//.test(e.toString()),n=i||e.toString().startsWith("/"),l=!n&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),d=e.toString().includes("?")||r==="get"&&Object.keys(t).length,v=e.toString().includes("#"),u=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(u.search=B.stringify((0,be.default)(B.parse(u.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:s}),t={}),[[i?`${u.protocol}//${u.host}`:"",n?u.pathname:"",l?u.pathname.substring(1):"",d?u.search:"",v?u.hash:""].join(""),t]}function E(r){return r=new URL(r.href),r.hash="",r}var Z=(r,e)=>{r.hash&&!e.hash&&E(r).href===e.href&&(e.hash=r.hash)},U=(r,e)=>E(r).href===E(e).href;var de=require("esm-env");var Oe=x(require("deepmerge"),1);function m(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var ee=r=>(m(`${r.frame}:before`,{detail:{visit:r}}),m("before",{cancelable:!0,detail:{visit:r}})),ye=r=>m("error",{detail:{errors:r}}),Pe=r=>m("exception",{cancelable:!0,detail:{exception:r}}),we=r=>(m(`${r.frame}:finish`,{detail:{visit:r}}),m("finish",{detail:{visit:r}})),Ee=r=>m("invalid",{cancelable:!0,detail:{response:r}}),S=r=>m("navigate",{detail:{page:r}}),Se=r=>m("progress",{detail:{progress:r}}),Fe=r=>(m(`${r.frame}:start`,{detail:{visit:r}}),m("start",{detail:{visit:r}})),Re=r=>m("success",{detail:{page:r}}),xe=(r,e)=>m("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),qe=r=>(m(`${r.frame}:prefetching`,{detail:{visit:r}}),m("prefetching",{detail:{visit:r}}));var Ie=x(require("deepmerge"),1);var p=class{static set(e,t){typeof window<"u"&&window.sessionStorage.setItem(e,JSON.stringify(t))}static get(e){if(typeof window<"u")return JSON.parse(window.sessionStorage.getItem(e)||"null")}static merge(e,t){let s=this.get(e);s===null?this.set(e,t):this.set(e,{...s,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let s=this.get(e);s!==null&&(delete s[t],this.set(e,s))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};p.locationVisitKey="inertiaLocationVisit";var Ae=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Te(),t=await Ve(),s=await rt(t);if(!s)throw new Error("Unable to encrypt history");return await Ye(e,s,r)},q={key:"historyKey",iv:"historyIv"},Ce=async r=>{let e=Te(),t=await Ve();if(!t)throw new Error("Unable to decrypt history");return await Ze(e,t,r)},Ye=async(r,e,t)=>{if(typeof window>"u")throw new Error("Unable to encrypt history");if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=new TextEncoder,i=JSON.stringify(t),n=new Uint8Array(i.length*3),l=s.encodeInto(i,n);return window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,n.subarray(0,l.written))},Ze=async(r,e,t)=>{if(typeof window.crypto.subtle>"u")return console.warn("Decryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t),i=new TextDecoder().decode(s);return JSON.parse(i)},Te=()=>{let r=p.get(q.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return p.set(q.iv,Array.from(e)),e},et=async()=>typeof window.crypto.subtle>"u"?(console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(null)):window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),tt=async r=>{if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve();let e=await window.crypto.subtle.exportKey("raw",r);p.set(q.key,Array.from(new Uint8Array(e)))},rt=async r=>{if(r)return r;let e=await et();return e?(await tt(e),e):null},Ve=async()=>{let r=p.get(q.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var f=class{static save(){a.saveScrollRegions(Array.from(this.regions()).map(e=>({top:e.scrollTop,left:e.scrollLeft})))}static regions(){return document.querySelectorAll("[scroll-region]")}static reset(){typeof window<"u"&&window.scrollTo(0,0),this.regions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.save(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}static restore(e){e.scrollRegions&&this.regions().forEach((t,s)=>{let i=e.scrollRegions[s];i&&(typeof t.scrollTo=="function"?t.scrollTo(i.left,i.top):(t.scrollTop=i.top,t.scrollLeft=i.left))})}static onScroll(e){let t=e.target;(typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")||t==document)&&this.save()}};var ke=x(require("deepmerge"),1),te=class{constructor(){this.page={frames:{},version:null,scrollRegions:[]};this.ignoredFrames=[];this.swappers={};this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}initFrame(e,{frame:t,initialState:s,swapComponent:i}){var l;(l=this.page).version||(l.version=s?.version);let n=this.page.frames?.[t];return s?.component&&e&&this.merge({frames:{[t]:s,...this.page.frames}}),this.swappers[t]=i,e||this.ignoredFrames.push(t),n}async set(e,{replace:t,preserveScroll:s=!1,forgetState:i=!1,frame:n}={}){this.componentId={};let l=this.componentId;return this.resolve(e.frames).then(d=>{if(l===this.componentId){if(e.scrollRegions??(e.scrollRegions=[]),e.frames._top?.url===void 0){let v=typeof window<"u"?window.location:new URL(e.frames._top.url);t=t||U(h(e.frames._top?.url),v)}if(n&&!this.ignoredFrames.includes(n)&&(t?a.replaceState(e):a.pushState(e,n)),this.page=e,this.cleared=!1,this.isFirstPageLoad){this.isFirstPageLoad=!1,this.fireEventsFor("firstLoad");return}return this.swap({components:d,page:e,forgetState:i,frame:n}).then(()=>{s||f.reset(),y.fireInternalEvent("loadDeferredProps"),t||S(e)})}})}destroy(e){delete this.page.frames[e],delete this.swappers[e],this.ignoredFrames.includes(e)||a.replaceState(this.page),this.ignoredFrames=this.ignoredFrames.filter(t=>t!==e)}async setQuietly(e,{forgetState:t=!1}={}){return this.resolve(e.frames).then(s=>(this.page=e,this.cleared=!1,this.swap({components:s,page:e,forgetState:t})))}async setFrame(e,t,s={}){return this.set({...this.page,frames:{...this.page.frames,[e]:t}},{frame:e,...s})}clear(){this.cleared=!0}isCleared(){return this.cleared}frame(e){return this.page.frames[e]||{}}get(){return this.page}merge(e){this.page=(0,ke.default)(this.page,e,{arrayMerge:(t,s)=>s})}setUrlHash(e){this.page.frames._top.url+=e}remember(e,t){this.page.frames[e].rememberedState=t}scrollRegions(e){this.page.scrollRegions=e}swap({components:e,page:t,forgetState:s,frame:i}){return Promise.all(Object.entries(e).map(([n,l])=>{if(i&&i!==n)return Promise.resolve();if(this.swappers[n])return this.swappers[n]({component:l,frame:t.frames[n],forgetState:s})}))}async resolve(e){let t={};return await Promise.all(Object.keys(e).map(async s=>{let i=e[s];t[s]=await V.resolveComponent(i.component)})),t}isTheSame(e,t){return this.page.frames[e].component===t.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(s=>s.event!==e&&s.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},o=new te;var K=typeof window>"u",re=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.queue=[]}remember(e,t,s){let i=o.get(),n=(0,Ie.default)(i,{frames:{[e]:{rememberedState:{[s]:t}}}},{arrayMerge:(l,d)=>d});this.replaceState(n)}restore(e,t){if(!K)return this.current?.frames?.[e]?.rememberedState?.[t]}pushState(e,t){K||this.preserveUrl||(this.current=e,this.lastUpdatedFrame=t,this.addToQueue(()=>this.getPageData(e).then(s=>{window.history.pushState({page:s,timestamp:Date.now(),updatedFrame:t},"",e.frames._top.url)})))}getPageData(e){return new Promise(t=>re.encryptHistory?Ae(e).then(t):t(e))}processQueue(){let e=this.queue.shift();return e?e().then(()=>this.processQueue()):Promise.resolve()}decrypt(e=null){if(K)return Promise.resolve(e??o.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(s=>{if(!s)throw new Error("Unable to decrypt history");return this.current=s??{},{...s,scrollRegions:window.history.state?.scrollRegions??[]}})}decryptPageData(e){return e instanceof ArrayBuffer?Ce(e):Promise.resolve(e)}saveScrollRegions(e){window.history.replaceState({...window.history.state,scrollRegions:e},"")}replaceState(e){o.merge(e),!(K||this.preserveUrl)&&(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.replaceState({...window.history.state,page:t,timestamp:Date.now()},"",e.frames._top.url)})))}addToQueue(e){this.queue.push(e),this.processQueue()}getState(e,t){return this.current?.[e]??t}deleteRememberedState(){this.current.frames&&(Object.values(this.current.frames).forEach(e=>{delete e.rememberedState}),this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){p.remove(q.key),p.remove(q.iv)}isValidState(e){return!!e.page}getAllState(){return this.current}},F=re;F.encryptHistory=!1;var a=new F;var se=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),typeof document<"u"&&document.addEventListener("scroll",I(f.onScroll.bind(f),100),!0)}onGlobalEvent(e,t){let s=i=>{let n=t(i);i.cancelable&&!i.defaultPrevented&&n===!1&&i.preventDefault()};return this.registerListener(`inertia:${e}`,s)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(s=>s.listener!==t)}}onMissingHistoryItem(){o.clear(),this.fireInternalEvent("missingHistoryItem")}fireInternalEvent(e){this.internalListeners.filter(t=>t.event===e).forEach(t=>t.listener())}registerListener(e,t){return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}handlePopstateEvent(e){let t=e.state||null;if(t===null){let s=h(o.frame("_top").url);s.hash=window.location.hash,a.replaceState((0,Oe.default)(o.get(),{frames:{_top:{url:s.href}}},{arrayMerge:(i,n)=>n})),f.reset();return}if(a.isValidState(t)){a.decrypt(t.page).then(s=>{o.setQuietly(s,{forgetState:a.lastUpdatedFrame}).then(()=>{f.restore(o.get()),S(o.get())}),a.lastUpdatedFrame=window.history.state?.updatedFrame}).catch(()=>{this.onMissingHistoryItem()});return}}},y=new se;var ie=class{constructor(){typeof window<"u"&&window?.performance.getEntriesByType("navigation").length>0?this.type=window.performance.getEntriesByType("navigation")[0].type:this.type="navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},ne=new ie;var j=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){ne.isReload()&&a.deleteRememberedState()}static handleBackForward(){return!ne.isBackForward()||!a.hasAnyState()||!window.history.state?.page?!1:(a.decrypt().then(e=>{o.set(e,{preserveScroll:!0,forgetState:!1,replace:!0}).then(()=>{f.restore(o.get()),S(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0)}static handleLocation(){if(!p.exists(p.locationVisitKey))return!1;let e=p.get(p.locationVisitKey)||{};return p.remove(p.locationVisitKey),typeof window<"u"&&o.setUrlHash(window.location.hash),a.decrypt().then(()=>{let t=a.getState("frames",{}),s=a.getState(a.scrollRegions,[]);Object.entries(t).forEach(([i,n])=>{o.remember(i,n.rememberedState)}),o.scrollRegions(s),o.set(o.get(),{preserveScroll:e.preserveScroll,forgetState:!1}).then(()=>{e.preserveScroll||f.restore(o.get()),S(o.get())})}).catch(()=>{y.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&o.setUrlHash(window.location.hash),o.set(o.get(),{frame:"_top",forgetState:!1,replace:!0}).then(()=>{S(o.get())})}};var $=class{constructor(e,t,s){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=s.keepAlive??!1,this.cb=t,this.interval=e,(s.autoStart??!0)&&this.start()}stop(){this.id&&clearInterval(this.id)}start(){typeof window>"u"||(this.stop(),this.id=window.setInterval(()=>{(!this.throttle||this.cbCount%10===0)&&this.cb(),this.throttle&&this.cbCount++},this.interval))}isInBackground(e){this.throttle=this.keepAlive?!1:e,this.throttle&&(this.cbCount=0)}};var oe=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,s){let i=new $(e,t,s);return this.polls.push(i),{stop:()=>i.stop(),start:()=>i.start()}}clear(){this.polls.forEach(e=>e.stop()),this.polls=[]}setupVisibilityListener(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{this.polls.forEach(e=>e.isInBackground(document.hidden))},!1)}},Le=new oe;var ae=(r,e,t)=>{if(r===e)return!0;for(let s in r)if(!t.includes(s)&&r[s]!==e[s]&&!st(r[s],e[s]))return!1;return!0},st=(r,e)=>{switch(typeof r){case"object":return ae(r,e,[]);case"function":return r.toString()===e.toString();default:return r===e}};var it={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},le=r=>{if(typeof r=="number")return r;for(let[e,t]of Object.entries(it))if(r.endsWith(e))return parseFloat(r)*t;return parseInt(r)};var ce=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:s}){if(this.findInFlight(e))return Promise.resolve();let n=this.findCached(e);if(!e.fresh&&n&&n.staleTimestamp>Date.now())return Promise.resolve();let[l,d]=this.extractStaleValues(s),v=new Promise((u,c)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),c()},onError:g=>{this.remove(e),e.onError(g),c()},onPrefetching(g){e.onPrefetching(g)},onPrefetched(g,_){e.onPrefetched(g,_)},onPrefetchResponse(g){u(g)}})}).then(u=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+l,response:v,singleUse:s===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,d),this.inFlightRequests=this.inFlightRequests.filter(c=>!this.paramsAreEqual(c.params,e)),u.handlePrefetch(),u));return this.inFlightRequests.push({params:{...e},response:v,staleTimestamp:null,inFlight:!0}),v}removeAll(){this.cached=[],this.removalTimers.forEach(e=>{clearTimeout(e.timer)}),this.removalTimers=[]}remove(e){this.cached=this.cached.filter(t=>!this.paramsAreEqual(t.params,e)),this.clearTimer(e)}extractStaleValues(e){let[t,s]=this.cacheForToStaleAndExpires(e);return[le(t),le(s)]}cacheForToStaleAndExpires(e){if(!Array.isArray(e))return[e,e];switch(e.length){case 0:return[0,0];case 1:return[e[0],e[0]];default:return[e[0],e[1]]}}clearTimer(e){let t=this.removalTimers.find(s=>this.paramsAreEqual(s.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(s=>s!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let s=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:s})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let s=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=s,e.response.then(i=>{if(this.currentUseId===s)return i.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),i.handle()})}removeSingleUseItems(e){this.cached=this.cached.filter(t=>this.paramsAreEqual(t.params,e)?!t.singleUse:!0)}findCached(e){return this.cached.find(t=>this.paramsAreEqual(t.params,e))||null}findInFlight(e){return this.inFlightRequests.find(t=>this.paramsAreEqual(t.params,e))||null}paramsAreEqual(e,t){return ae(e,t,["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},R=new ce;var ue=x(require("axios"),1);var k=class{constructor(e){this.callbacks=[];if(!e.prefetch)this.params=e;else{let t={onBefore:this.wrapCallback(e,"onBefore"),onStart:this.wrapCallback(e,"onStart"),onProgress:this.wrapCallback(e,"onProgress"),onFinish:this.wrapCallback(e,"onFinish"),onCancel:this.wrapCallback(e,"onCancel"),onSuccess:this.wrapCallback(e,"onSuccess"),onError:this.wrapCallback(e,"onError"),onCancelToken:this.wrapCallback(e,"onCancelToken"),onPrefetched:this.wrapCallback(e,"onPrefetched"),onPrefetching:this.wrapCallback(e,"onPrefetching")};this.params={...e,...t,onPrefetchResponse:e.onPrefetchResponse||(()=>{})}}}static create(e){return new k(e)}data(){return this.params.method==="get"?{}:this.params.data}queryParams(){return this.params.method==="get"?this.params.data:{}}isPartial(){return this.params.only.length>0||this.params.except.length>0||this.params.reset.length>0}onCancelToken(e){this.params.onCancelToken({cancel:e})}markAsFinished(){this.params.completed=!0,this.params.cancelled=!1,this.params.interrupted=!1}markAsCancelled({cancelled:e=!0,interrupted:t=!1}){this.params.onCancel(),this.params.completed=!1,this.params.cancelled=e,this.params.interrupted=t}wasCancelledAtAll(){return this.params.cancelled||this.params.interrupted}onFinish(){this.params.onFinish(this.params)}onStart(){this.params.onStart(this.params)}onPrefetching(){this.params.onPrefetching(this.params)}onPrefetchResponse(e){this.params.onPrefetchResponse&&this.params.onPrefetchResponse(e)}all(){return this.params}headers(){let e={...this.params.headers};this.isPartial()&&(e["X-Inertia-Partial-Component"]=o.frame(this.params.frame).component);let t=this.params.only.concat(this.params.reset);return t.length>0&&(e["X-Inertia-Partial-Data"]=t.join(",")),this.params.except.length>0&&(e["X-Inertia-Partial-Except"]=this.params.except.join(",")),this.params.reset.length>0&&(e["X-Inertia-Reset"]=this.params.reset.join(",")),this.params.errorBag&&this.params.errorBag.length>0&&(e["X-Inertia-Error-Bag"]=this.params.errorBag),e}setPreserveOptions(e){this.params.preserveScroll=this.resolvePreserveOption(this.params.preserveScroll,e),this.params.forgetState=this.resolvePreserveOption(this.params.forgetState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...s)=>{this.recordCallback(t,s),e[t](...s)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.frames[this.params.frame].props.errors||{}).length>0:e}};var Ue={modal:null,listener:null,show(r){typeof r=="object"&&(r=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(r)}`);let e=document.createElement("html");e.innerHTML=r,e.querySelectorAll("a").forEach(s=>s.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(r){r.keyCode===27&&this.hide()}};var pe=class{constructor(){this.queue=[];this.processing=!1}add(e){this.queue.push(e)}async process(){return this.processing||(this.processing=!0,await this.processQueue(),this.processing=!1),Promise.resolve()}async processQueue(){let e=this.queue.shift();return e?(await e.process(),this.processQueue()):Promise.resolve()}},He=new pe,A=class{constructor(e,t,s){this.requestParams=e;this.response=t;this.originatingPage=s}static create(e,t,s){return new A(e,t,s)}async handlePrefetch(){U(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return He.add(this),He.process()}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),xe(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await a.processQueue(),a.preserveUrl=this.requestParams.all().preserveUrl,await this.setFrame();let e=this.response.headers["x-inertia-frame"]||this.requestParams.all().frame,t=o.frame(e).props.errors||{};if(Object.keys(t).length>0){let s=this.getScopedErrors(t);return ye(s),this.requestParams.all().onError(s)}Re(o.get()),await this.requestParams.all().onSuccess(o.get()),a.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=h(this.getHeader("x-inertia-location"));return Z(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(Ee(e))return Ue.show(e.data)}isInertiaResponse(){return this.hasHeader("x-inertia")}hasStatus(e){return this.response.status===e}getHeader(e){return this.response.headers[e]}hasHeader(e){return this.getHeader(e)!==void 0}isLocationVisit(){return this.hasStatus(409)&&this.hasHeader("x-inertia-location")}locationVisit(e){try{if(p.set(p.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;U(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setFrame(){let e=this.getDataFromResponse(this.response.data);if(!this.shouldSetFrame(e))return Promise.resolve();this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=a.preserveUrl?o.frame("_top").url:this.pageUrl(e),delete e.version;let t=this.response.headers["x-inertia-frame"]||this.requestParams.all().frame;return F.encryptHistory=e.encryptHistory,e.clearHistory&&a.clear(),o.setFrame(t,e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,forgetState:this.requestParams.all().forgetState})}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetFrame(e){let t=this.requestParams.all().frame;if(!this.requestParams.all().async||this.originatingPage.frames[t]?.component!==e.component)return!0;if(this.originatingPage.frames[t]?.component!==o.frame(t).component)return!1;let s=h(this.originatingPage.frames._top.url),i=h(o.frame("_top").url);return s.origin===i.origin&&s.pathname===i.pathname}pageUrl(e){let t=h(e.url);return Z(this.requestParams.all().url,t),t.href.split(t.host).pop()}mergeProps(e){let t=this.requestParams.all().frame;this.requestParams.isPartial()&&e.component===o.frame(t).component&&((e.mergeProps||[]).forEach(i=>{let n=e.props[i];Array.isArray(n)?e.props[i]=[...o.frame(t).props[i]||[],...n]:typeof n=="object"&&(e.props[i]={...o.frame(t).props[i]||[],...n})}),e.props={...o.frame(t).props,...e.props})}async setRememberedState(e){let t=await a.getState("frames",{}),s=this.requestParams.all().frame,i=t[s]?.rememberedState||{};this.requestParams.all().forgetState&&i&&e.component===o.frame(s).component&&(e.rememberedState=i)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var C=class{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=k.create(e),this.cancelToken=new AbortController}static create(e,t){return new C(e,t)}async send(){this.requestParams.onCancelToken(()=>this.cancel({cancelled:!0})),Fe(this.requestParams.all()),this.requestParams.onStart(),this.requestParams.all().prefetch&&(this.requestParams.onPrefetching(),qe(this.requestParams.all()));let e=this.requestParams.all().prefetch;return(0,ue.default)({method:this.requestParams.all().method,url:E(this.requestParams.all().url).href,data:this.requestParams.data(),params:this.requestParams.queryParams(),signal:this.cancelToken.signal,headers:this.getHeaders(),onUploadProgress:this.onProgress.bind(this),responseType:"text"}).then(t=>(this.response=A.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=A.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!ue.default.isCancel(t)&&Pe(t))return Promise.reject(t)}).finally(()=>{this.finish(),e&&this.response&&this.requestParams.onPrefetchResponse(this.response)})}finish(){this.requestParams.wasCancelledAtAll()||(this.requestParams.markAsFinished(),this.fireFinishEvents())}fireFinishEvents(){this.requestHasFinished||(this.requestHasFinished=!0,we(this.requestParams.all()),this.requestParams.onFinish())}cancel({cancelled:e=!1,interrupted:t=!1}){this.requestHasFinished||(this.cancelToken.abort(),this.requestParams.markAsCancelled({cancelled:e,interrupted:t}),this.fireFinishEvents())}onProgress(e){this.requestParams.data()instanceof FormData&&(e.percentage=e.progress?Math.round(e.progress*100):0,Se(e),this.requestParams.all().onProgress(e))}getHeaders(){let e={...this.requestParams.headers(),Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},t=this.requestParams.all().frame,s=o.frame(t).url;return s&&(e["X-Inertia-Referer"]=E(h(s)).href),o.get().version&&(e["X-Inertia-Version"]=o.get().version),e}};var H=class{constructor({maxConcurrent:e,interruptible:t}){this.requests=[];this.maxConcurrent=e,this.interruptible=t}send(e){this.requests.push(e),e.send().then(()=>{this.requests=this.requests.filter(t=>t!==e)})}interruptInFlight(){this.cancel({interrupted:!0},!1)}cancelInFlight(){this.cancel({cancelled:!0},!0)}cancel({cancelled:e=!1,interrupted:t=!1}={},s){if(!this.shouldCancel(s))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var V=class{constructor(){this.frame="_top";this.syncRequestStream=new H({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new H({maxConcurrent:1/0,interruptible:!1})}init(e,{frame:t,initialState:s,swapComponent:i}){if(this.frame=t,!de.BROWSER)return;let n=o.initFrame(e,{frame:t,initialState:s,swapComponent:i});return t!=="_top"||(j.handle(),y.init(),y.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{forgetState:!1,preserveScroll:!0,replace:!0})}),y.on("loadDeferredProps",()=>{this.loadDeferredProps()})),n}destroy(){o.destroy(this.frame)}get(e,t={},s={}){return this.visit(e,{...s,method:"get",data:t})}post(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"post",data:t})}put(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"put",data:t})}patch(e,t={},s={}){return this.visit(e,{forgetState:!1,...s,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{forgetState:!1,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,forgetState:this.frame,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){a.remember(this.frame,e,t)}restore(e="default"){return a.restore(this.frame,e)}on(e,t){return y.onGlobalEvent(`${this.frame}:${e}`,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},s={}){return Le.add(e,()=>this.reload(t),{autoStart:s.autoStart??!0,keepAlive:s.keepAlive??!1})}visit(e,t={}){if(!de.BROWSER)return;let s=this.getPendingVisit(e,{...t,preserveScroll:t.preserveScroll??this.frame!=="_top",forgetState:t.forgetState??this.frame,showProgress:t.showProgress??!t.async}),i=this.getVisitEvents(t);if(i.onBefore(s)===!1||!ee(s))return;let n=s.async?this.asyncRequestStream:this.syncRequestStream;n.interruptInFlight(),!o.isCleared()&&!s.preserveUrl&&f.save();let l={...s,...i},d=R.get(l);d?(O(d.inFlight),R.use(d,l)):(O(!0),n.send(C.create(l,o.get())))}getCached(e,t={}){return R.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){R.remove(this.getPrefetchParams(e,t))}flushAll(){R.removeAll()}getPrefetching(e,t={}){return R.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:s}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let i=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),n=this.getVisitEvents(t);if(n.onBefore(i)===!1||!ee(i))return;L(),this.asyncRequestStream.interruptInFlight();let l={...i,...n};R.add(l,d=>{this.asyncRequestStream.send(C.create(d,o.get()))},{cacheFor:s})}clearHistory(){a.clear()}decryptHistory(){return a.decrypt()}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,s={}){let i={method:"get",data:{},replace:!1,preserveScroll:!1,forgetState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,frame:this.frame,...t},[n,l]=ve(e,i.data,i.method,i.forceFormData,i.queryStringArrayFormat);return{cancelled:!1,completed:!1,interrupted:!1,...i,...s,url:n,data:l}}getVisitEvents(e){return{onCancelToken:e.onCancelToken||(()=>{}),onBefore:e.onBefore||(()=>{}),onStart:e.onStart||(()=>{}),onProgress:e.onProgress||(()=>{}),onFinish:e.onFinish||(()=>{}),onCancel:e.onCancel||(()=>{}),onSuccess:e.onSuccess||(()=>{}),onError:e.onError||(()=>{}),onPrefetched:e.onPrefetched||(()=>{}),onPrefetching:e.onPrefetching||(()=>{})}}loadDeferredProps(){let e=o.frame(this.frame)?.deferredProps;e&&Object.entries(e).forEach(([t,s])=>{this.reload({only:s})})}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "inertiax-core", | ||
"version": "5.0.35", | ||
"version": "5.0.36", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A framework for creating server-driven single page apps.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
368200
1049