@inertiajs/core 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +2440 -16
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +2473 -16
- package/dist/index.js.map +3 -3
- package/dist/server.esm.js +45 -1
- package/dist/server.esm.js.map +2 -2
- package/dist/server.js +76 -1
- package/dist/server.js.map +2 -2
- package/package.json +7 -9
- package/types/types.d.ts +4 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,2339 @@
|
|
|
1
|
-
function I(r,e){let t;return function(...i){clearTimeout(t),t=setTimeout(()=>r.apply(this,i),e)}}function S(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var Z=r=>S("before",{cancelable:!0,detail:{visit:r}}),de=r=>S("error",{detail:{errors:r}}),he=r=>S("exception",{cancelable:!0,detail:{exception:r}}),me=r=>S("finish",{detail:{visit:r}}),fe=r=>S("invalid",{cancelable:!0,detail:{response:r}}),q=r=>S("navigate",{detail:{page:r}}),ge=r=>S("progress",{detail:{progress:r}}),ve=r=>S("start",{detail:{visit:r}}),ye=r=>S("success",{detail:{page:r}}),be=(r,e)=>S("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),Pe=r=>S("prefetching",{detail:{visit:r}});var m=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 i=this.get(e);i===null?this.set(e,t):this.set(e,{...i,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let i=this.get(e);i!==null&&(delete i[t],this.set(e,i))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};m.locationVisitKey="inertiaLocationVisit";var we=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Ee(),t=await Re(),i=await We(t);if(!i)throw new Error("Unable to encrypt history");return await Be(e,i,r)},V={key:"historyKey",iv:"historyIv"},Se=async r=>{let e=Ee(),t=await Re();if(!t)throw new Error("Unable to decrypt history");return await Ge(e,t,r)},Be=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 i=new TextEncoder,s=JSON.stringify(t),o=new Uint8Array(s.length*3),u=i.encodeInto(s,o);return window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,o.subarray(0,u.written))},Ge=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 i=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t);return JSON.parse(new TextDecoder().decode(i))},Ee=()=>{let r=m.get(V.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return m.set(V.iv,Array.from(e)),e},Ke=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"]),je=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);m.set(V.key,Array.from(new Uint8Array(e)))},We=async r=>{if(r)return r;let e=await Ke();return e?(await je(e),e):null},Re=async()=>{let r=m.get(V.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var v=class{static save(){l.saveScrollPositions(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){this.restoreDocument(),this.regions().forEach((t,i)=>{let s=e[i];s&&(typeof t.scrollTo=="function"?t.scrollTo(s.left,s.top):(t.scrollTop=s.top,t.scrollLeft=s.left))})}static restoreDocument(){let e=l.getDocumentScrollPosition();typeof window<"u"&&window.scrollTo(e.left,e.top)}static onScroll(e){let t=e.target;typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")&&this.save()}static onWindowScroll(){l.saveDocumentScrollPosition({top:window.scrollY,left:window.scrollX})}};import{mergeWith as Xe}from"es-toolkit";import*as B from"qs";function $(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>$(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>$(e))}var ee=r=>r instanceof FormData;function te(r,e=new FormData,t=null){r=r||{};for(let i in r)Object.prototype.hasOwnProperty.call(r,i)&&xe(e,Te(t,i),r[i]);return e}function Te(r,e){return r?r+"["+e+"]":e}function xe(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(i=>xe(r,Te(e,i.toString()),t[i]));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,"");te(t,r,e)}function P(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var qe=(r,e,t,i,s)=>{let o=typeof r=="string"?P(r):r;if(($(e)||i)&&!ee(e)&&(e=te(e)),ee(e))return[o,e];let[u,p]=Ce(t,o,e,s);return[P(u),p]};function Ce(r,e,t,i="brackets"){let s=/^[a-z][a-z0-9+.-]*:\/\//i.test(e.toString()),o=s||e.toString().startsWith("/"),u=!o&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),p=e.toString().includes("?")||r==="get"&&Object.keys(t).length,d=e.toString().includes("#"),a=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(a.search=B.stringify(Xe(B.parse(a.search,{ignoreQueryPrefix:!0}),t,(h,c,b,x)=>{c===void 0&&delete x[b]}),{encodeValuesOnly:!0,arrayFormat:i}),t={}),[[s?`${a.protocol}//${a.host}`:"",o?a.pathname:"",u?a.pathname.substring(1):"",p?a.search:"",d?a.hash:""].join(""),t]}function O(r){return r=new URL(r.href),r.hash="",r}var re=(r,e)=>{r.hash&&!e.hash&&O(r).href===e.href&&(e.hash=r.hash)},L=(r,e)=>O(r).href===O(e).href;var ie=class{constructor(){this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}init({initialPage:e,swapComponent:t,resolveComponent:i}){return this.page=e,this.swapComponent=t,this.resolveComponent=i,this}set(e,{replace:t=!1,preserveScroll:i=!1,preserveState:s=!1}={}){this.componentId={};let o=this.componentId;return e.clearHistory&&l.clear(),this.resolve(e.component).then(u=>{if(o!==this.componentId)return;e.rememberedState??(e.rememberedState={});let p=typeof window<"u"?window.location:new URL(e.url);return t=t||L(P(e.url),p),new Promise(d=>{t?l.replaceState(e,()=>d(null)):l.pushState(e,()=>d(null))}).then(()=>{let d=!this.isTheSame(e);return this.page=e,this.cleared=!1,d&&this.fireEventsFor("newComponent"),this.isFirstPageLoad&&this.fireEventsFor("firstLoad"),this.isFirstPageLoad=!1,this.swap({component:u,page:e,preserveState:s}).then(()=>{i||v.reset(),E.fireInternalEvent("loadDeferredProps"),t||q(e)})})})}setQuietly(e,{preserveState:t=!1}={}){return this.resolve(e.component).then(i=>(this.page=e,this.cleared=!1,l.setCurrent(e),this.swap({component:i,page:e,preserveState:t})))}clear(){this.cleared=!0}isCleared(){return this.cleared}get(){return this.page}merge(e){this.page={...this.page,...e}}setUrlHash(e){this.page.url.includes(e)||(this.page.url+=e)}remember(e){this.page.rememberedState=e}swap({component:e,page:t,preserveState:i}){return this.swapComponent({component:e,page:t,preserveState:i})}resolve(e){return Promise.resolve(this.resolveComponent(e))}isTheSame(e){return this.page.component===e.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(i=>i.event!==e&&i.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},n=new ie;var F=class{constructor(){this.items=[];this.processingPromise=null}add(e){return this.items.push(e),this.process()}process(){return this.processingPromise??(this.processingPromise=this.processNext().then(()=>{this.processingPromise=null})),this.processingPromise}processNext(){let e=this.items.shift();return e?Promise.resolve(e()).then(()=>this.processNext()):Promise.resolve()}};var U=typeof window>"u",k=new F,Ae=!U&&/CriOS/.test(window.navigator.userAgent),se=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.initialState=null}remember(e,t){this.replaceState({...n.get(),rememberedState:{...n.get()?.rememberedState??{},[t]:e}})}restore(e){if(!U)return this.initialState?.[this.rememberedState]?.[e]}pushState(e,t=null){if(!U){if(this.preserveUrl){t&&t();return}this.current=e,k.add(()=>this.getPageData(e).then(i=>{let s=()=>{this.doPushState({page:i},e.url),t&&t()};Ae?setTimeout(s):s()}))}}getPageData(e){return new Promise(t=>e.encryptHistory?we(e).then(t):t(e))}processQueue(){return k.process()}decrypt(e=null){if(U)return Promise.resolve(e??n.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(i=>{if(!i)throw new Error("Unable to decrypt history");return this.initialState===null?this.initialState=i??void 0:this.current=i??{},i})}decryptPageData(e){return e instanceof ArrayBuffer?Se(e):Promise.resolve(e)}saveScrollPositions(e){k.add(()=>Promise.resolve().then(()=>{window.history.state?.page&&this.doReplaceState({page:window.history.state.page,scrollRegions:e})}))}saveDocumentScrollPosition(e){k.add(()=>Promise.resolve().then(()=>{window.history.state?.page&&this.doReplaceState({page:window.history.state.page,documentScrollPosition:e})}))}getScrollRegions(){return window.history.state?.scrollRegions||[]}getDocumentScrollPosition(){return window.history.state?.documentScrollPosition||{top:0,left:0}}replaceState(e,t=null){if(n.merge(e),!U){if(this.preserveUrl){t&&t();return}this.current=e,k.add(()=>this.getPageData(e).then(i=>{let s=()=>{this.doReplaceState({page:i},e.url),t&&t()};Ae?setTimeout(s):s()}))}}doReplaceState(e,t){window.history.replaceState({...e,scrollRegions:e.scrollRegions??window.history.state?.scrollRegions,documentScrollPosition:e.documentScrollPosition??window.history.state?.documentScrollPosition},"",t)}doPushState(e,t){window.history.pushState(e,"",t)}getState(e,t){return this.current?.[e]??t}deleteState(e){this.current[e]!==void 0&&(delete this.current[e],this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){m.remove(V.key),m.remove(V.iv)}setCurrent(e){this.current=e}isValidState(e){return!!e.page}getAllState(){return this.current}};typeof window<"u"&&window.history.scrollRestoration&&(window.history.scrollRestoration="manual");var l=new se;var ne=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&(window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),window.addEventListener("scroll",I(v.onWindowScroll.bind(v),100),!0)),typeof document<"u"&&document.addEventListener("scroll",I(v.onScroll.bind(v),100),!0)}onGlobalEvent(e,t){let i=s=>{let o=t(s);s.cancelable&&!s.defaultPrevented&&o===!1&&s.preventDefault()};return this.registerListener(`inertia:${e}`,i)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(i=>i.listener!==t)}}onMissingHistoryItem(){n.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 i=P(n.get().url);i.hash=window.location.hash,l.replaceState({...n.get(),url:i.href}),v.reset();return}if(!l.isValidState(t))return this.onMissingHistoryItem();l.decrypt(t.page).then(i=>{if(n.get().version!==i.version){this.onMissingHistoryItem();return}n.setQuietly(i,{preserveState:!1}).then(()=>{window.requestAnimationFrame(()=>{v.restore(l.getScrollRegions())}),q(n.get())})}).catch(()=>{this.onMissingHistoryItem()})}},E=new ne;var oe=class{constructor(){this.type=this.resolveType()}resolveType(){return typeof window>"u"?"navigate":window.performance&&window.performance.getEntriesByType&&window.performance.getEntriesByType("navigation").length>0?window.performance.getEntriesByType("navigation")[0].type:"navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},G=new oe;var K=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){G.isReload()&&l.deleteState(l.rememberedState)}static handleBackForward(){if(!G.isBackForward()||!l.hasAnyState())return!1;let e=l.getScrollRegions();return l.decrypt().then(t=>{n.set(t,{preserveScroll:!0,preserveState:!0}).then(()=>{v.restore(e),q(n.get())})}).catch(()=>{E.onMissingHistoryItem()}),!0}static handleLocation(){if(!m.exists(m.locationVisitKey))return!1;let e=m.get(m.locationVisitKey)||{};return m.remove(m.locationVisitKey),typeof window<"u"&&n.setUrlHash(window.location.hash),l.decrypt(n.get()).then(()=>{let t=l.getState(l.rememberedState,{}),i=l.getScrollRegions();n.remember(t),n.set(n.get(),{preserveScroll:e.preserveScroll,preserveState:!0}).then(()=>{e.preserveScroll&&v.restore(i),q(n.get())})}).catch(()=>{E.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&n.setUrlHash(window.location.hash),n.set(n.get(),{preserveScroll:!0,preserveState:!0}).then(()=>{G.isReload()&&v.restore(l.getScrollRegions()),q(n.get())})}};var j=class{constructor(e,t,i){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=i.keepAlive??!1,this.cb=t,this.interval=e,(i.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 ae=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,i){let s=new j(e,t,i);return this.polls.push(s),{stop:()=>s.stop(),start:()=>s.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)}},Ve=new ae;import{cloneDeep as ze}from"es-toolkit";var le=(r,e,t)=>{if(r===e)return!0;for(let i in r)if(!t.includes(i)&&r[i]!==e[i]&&!Je(r[i],e[i]))return!1;return!0},Je=(r,e)=>{switch(typeof r){case"object":return le(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},ce=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 ue=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:i}){if(this.findInFlight(e))return Promise.resolve();let o=this.findCached(e);if(!e.fresh&&o&&o.staleTimestamp>Date.now())return Promise.resolve();let[u,p]=this.extractStaleValues(i),d=new Promise((a,h)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),h()},onError:c=>{this.remove(e),e.onError(c),h()},onPrefetching(c){e.onPrefetching(c)},onPrefetched(c,b){e.onPrefetched(c,b)},onPrefetchResponse(c){a(c)}})}).then(a=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+u,response:d,singleUse:i===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,p),this.inFlightRequests=this.inFlightRequests.filter(h=>!this.paramsAreEqual(h.params,e)),a.handlePrefetch(),a));return this.inFlightRequests.push({params:{...e},response:d,staleTimestamp:null,inFlight:!0}),d}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,i]=this.cacheForToStaleAndExpires(e);return[ce(t),ce(i)]}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(i=>this.paramsAreEqual(i.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(i=>i!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let i=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:i})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let i=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=i,e.response.then(s=>{if(this.currentUseId===i)return s.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),s.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}withoutPurposePrefetchHeader(e){let t=ze(e);return t.headers.Purpose==="prefetch"&&delete t.headers.Purpose,t}paramsAreEqual(e,t){return le(this.withoutPurposePrefetchHeader(e),this.withoutPurposePrefetchHeader(t),["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},C=new ue;import{default as Ie}from"axios";var W=class r{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 r(e)}data(){return this.params.method==="get"?null: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"]=n.get().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.preserveState=this.resolvePreserveOption(this.params.preserveState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...i)=>{this.recordCallback(t,i),e[t](...i)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.props.errors||{}).length>0:e}};var Fe={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(i=>i.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 _e=new F,H=class r{constructor(e,t,i){this.requestParams=e;this.response=t;this.originatingPage=i}static create(e,t,i){return new r(e,t,i)}async handlePrefetch(){L(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return _e.add(()=>this.process())}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),be(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await l.processQueue(),l.preserveUrl=this.requestParams.all().preserveUrl,await this.setPage();let e=n.get().props.errors||{};if(Object.keys(e).length>0){let t=this.getScopedErrors(e);return de(t),this.requestParams.all().onError(t)}ye(n.get()),await this.requestParams.all().onSuccess(n.get()),l.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=P(this.getHeader("x-inertia-location"));return re(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(fe(e))return Fe.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(m.set(m.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;L(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setPage(){let e=this.getDataFromResponse(this.response.data);return this.shouldSetPage(e)?(this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=l.preserveUrl?n.get().url:this.pageUrl(e),n.set(e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,preserveState:this.requestParams.all().preserveState})):Promise.resolve()}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetPage(e){if(!this.requestParams.all().async||this.originatingPage.component!==e.component)return!0;if(this.originatingPage.component!==n.get().component)return!1;let t=P(this.originatingPage.url),i=P(n.get().url);return t.origin===i.origin&&t.pathname===i.pathname}pageUrl(e){let t=P(e.url);return re(this.requestParams.all().url,t),t.pathname+t.search+t.hash}mergeProps(e){if(!this.requestParams.isPartial()||e.component!==n.get().component)return;let t=e.mergeProps||[],i=e.deepMergeProps||[],s=e.matchPropsOn||[];t.forEach(o=>{let u=e.props[o];Array.isArray(u)?e.props[o]=this.mergeOrMatchItems(n.get().props[o]||[],u,o,s):typeof u=="object"&&u!==null&&(e.props[o]={...n.get().props[o]||[],...u})}),i.forEach(o=>{let u=e.props[o],p=n.get().props[o],d=(a,h,c)=>Array.isArray(h)?this.mergeOrMatchItems(a,h,c,s):typeof h=="object"&&h!==null?Object.keys(h).reduce((b,x)=>(b[x]=d(a?a[x]:void 0,h[x],`${c}.${x}`),b),{...a}):h;e.props[o]=d(p,u,o)}),e.props={...n.get().props,...e.props}}mergeOrMatchItems(e,t,i,s){let o=s.find(a=>a.split(".").slice(0,-1).join(".")===i);if(!o)return[...Array.isArray(e)?e:[],...t];let u=o.split(".").pop()||"",p=Array.isArray(e)?e:[],d=new Map;return p.forEach(a=>{a&&typeof a=="object"&&u in a?d.set(a[u],a):d.set(Symbol(),a)}),t.forEach(a=>{a&&typeof a=="object"&&u in a?d.set(a[u],a):d.set(Symbol(),a)}),Array.from(d.values())}async setRememberedState(e){let t=await l.getState(l.rememberedState,{});this.requestParams.all().preserveState&&t&&e.component===n.get().component&&(e.rememberedState=t)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var D=class r{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=W.create(e),this.cancelToken=new AbortController}static create(e,t){return new r(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(),Pe(this.requestParams.all()));let e=this.requestParams.all().prefetch;return Ie({method:this.requestParams.all().method,url:O(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=H.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=H.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!Ie.isCancel(t)&&he(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,me(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,ge(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};return n.get().version&&(e["X-Inertia-Version"]=n.get().version),e}};var M=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}={},i){if(!this.shouldCancel(i))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var X=class{constructor(){this.syncRequestStream=new M({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new M({maxConcurrent:1/0,interruptible:!1})}init({initialPage:e,resolveComponent:t,swapComponent:i}){n.init({initialPage:e,resolveComponent:t,swapComponent:i}),K.handle(),E.init(),E.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{preserveState:!0,preserveScroll:!0,replace:!0})}),E.on("loadDeferredProps",()=>{this.loadDeferredProps()})}get(e,t={},i={}){return this.visit(e,{...i,method:"get",data:t})}post(e,t={},i={}){return this.visit(e,{preserveState:!0,...i,method:"post",data:t})}put(e,t={},i={}){return this.visit(e,{preserveState:!0,...i,method:"put",data:t})}patch(e,t={},i={}){return this.visit(e,{preserveState:!0,...i,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{preserveState:!0,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,preserveState:!0,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){l.remember(e,t)}restore(e="default"){return l.restore(e)}on(e,t){return typeof window>"u"?()=>{}:E.onGlobalEvent(e,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},i={}){return Ve.add(e,()=>this.reload(t),{autoStart:i.autoStart??!0,keepAlive:i.keepAlive??!1})}visit(e,t={}){let i=this.getPendingVisit(e,{...t,showProgress:t.showProgress??!t.async}),s=this.getVisitEvents(t);if(s.onBefore(i)===!1||!Z(i))return;let o=i.async?this.asyncRequestStream:this.syncRequestStream;o.interruptInFlight(),!n.isCleared()&&!i.preserveUrl&&v.save();let u={...i,...s},p=C.get(u);p?(J(p.inFlight),C.use(p,u)):(J(!0),o.send(D.create(u,n.get())))}getCached(e,t={}){return C.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){C.remove(this.getPrefetchParams(e,t))}flushAll(){C.removeAll()}getPrefetching(e,t={}){return C.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:i=3e4}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let s=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),o=s.url.origin+s.url.pathname+s.url.search,u=window.location.origin+window.location.pathname+window.location.search;if(o===u)return;let p=this.getVisitEvents(t);if(p.onBefore(s)===!1||!Z(s))return;Q(),this.asyncRequestStream.interruptInFlight();let d={...s,...p};new Promise(h=>{let c=()=>{n.get()?h():setTimeout(c,50)};c()}).then(()=>{C.add(d,h=>{this.asyncRequestStream.send(D.create(h,n.get()))},{cacheFor:i})})}clearHistory(){l.clear()}decryptHistory(){return l.decrypt()}resolveComponent(e){return n.resolve(e)}replace(e){this.clientVisit(e,{replace:!0})}push(e){this.clientVisit(e)}clientVisit(e,{replace:t=!1}={}){let i=n.get(),s=typeof e.props=="function"?e.props(i.props):e.props??i.props;n.set({...i,...e,props:s},{replace:t,preserveScroll:e.preserveScroll,preserveState:e.preserveState})}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,i={}){let s={method:"get",data:{},replace:!1,preserveScroll:!1,preserveState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,...t},[o,u]=qe(e,s.data,s.method,s.forceFormData,s.queryStringArrayFormat),p={cancelled:!1,completed:!1,interrupted:!1,...s,...i,url:o,data:u};return p.prefetch&&(p.headers.Purpose="prefetch"),p}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=n.get()?.deferredProps;e&&Object.entries(e).forEach(([t,i])=>{this.reload({only:i})})}};var Ye={buildDOMElement(r){let e=document.createElement("template");e.innerHTML=r;let t=e.content.firstChild;if(!r.startsWith("<script "))return t;let i=document.createElement("script");return i.innerHTML=t.innerHTML,t.getAttributeNames().forEach(s=>{i.setAttribute(s,t.getAttribute(s)||"")}),i},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(i=>i.getAttribute("inertia")===t):-1},update:I(function(r){let e=r.map(i=>this.buildDOMElement(i));Array.from(document.head.childNodes).filter(i=>this.isInertiaManagedElement(i)).forEach(i=>{let s=this.findMatchingElementIndex(i,e);if(s===-1){i?.parentNode?.removeChild(i);return}let o=e.splice(s,1)[0];o&&!i.isEqualNode(o)&&i?.parentNode?.replaceChild(o,i)}),e.forEach(i=>document.head.appendChild(i))},1)};function Oe(r,e,t){let i={},s=0;function o(){let c=s+=1;return i[c]=[],c.toString()}function u(c){c===null||Object.keys(i).indexOf(c)===-1||(delete i[c],h())}function p(c){Object.keys(i).indexOf(c)===-1&&(i[c]=[])}function d(c,b=[]){c!==null&&Object.keys(i).indexOf(c)>-1&&(i[c]=b),h()}function a(){let c=e(""),b={...c?{title:`<title inertia="">${c}</title>`}:{}},x=Object.values(i).reduce((R,T)=>R.concat(T),[]).reduce((R,T)=>{if(T.indexOf("<")===-1)return R;if(T.indexOf("<title ")===0){let N=T.match(/(<title [^>]+>)(.*?)(<\/title>)/);return R.title=N?`${N[1]}${e(N[2])}${N[3]}`:T,R}let pe=T.match(/ inertia="[^"]+"/);return pe?R[pe[0]]=T:R[Object.keys(R).length]=T,R},b);return Object.values(x)}function h(){r?t(a()):Ye.update(a())}return h(),{forceUpdate:h,createProvider:function(){let c=o();return{reconnect:()=>p(c),update:b=>d(c,b),disconnect:()=>u(c)}}}}var f="nprogress",w,g={minimum:.08,easing:"linear",positionUsing:"translate3d",speed:200,trickle:!0,trickleSpeed:200,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",color:"#29d",includeCSS:!0,template:['<div class="bar" role="bar">','<div class="peg"></div>',"</div>",'<div class="spinner" role="spinner">','<div class="spinner-icon"></div>',"</div>"].join("")},A=null,Ze=r=>{Object.assign(g,r),g.includeCSS&&nt(g.color),w=document.createElement("div"),w.id=f,w.innerHTML=g.template},_=r=>{let e=Le();r=Me(r,g.minimum,1),A=r===1?null:r;let t=tt(!e),i=t.querySelector(g.barSelector),s=g.speed,o=g.easing;t.offsetWidth,st(u=>{let p=g.positionUsing==="translate3d"?{transition:`all ${s}ms ${o}`,transform:`translate3d(${z(r)}%,0,0)`}:g.positionUsing==="translate"?{transition:`all ${s}ms ${o}`,transform:`translate(${z(r)}%,0)`}:{marginLeft:`${z(r)}%`};for(let d in p)i.style[d]=p[d];if(r!==1)return setTimeout(u,s);t.style.transition="none",t.style.opacity="1",t.offsetWidth,setTimeout(()=>{t.style.transition=`all ${s}ms linear`,t.style.opacity="0",setTimeout(()=>{De(),t.style.transition="",t.style.opacity="",u()},s)},s)})},Le=()=>typeof A=="number",ke=()=>{A||_(0);let r=function(){setTimeout(function(){A&&(Ue(),r())},g.trickleSpeed)};g.trickle&&r()},et=r=>{!r&&!A||(Ue(.3+.5*Math.random()),_(1))},Ue=r=>{let e=A;if(e===null)return ke();if(!(e>1))return r=typeof r=="number"?r:(()=>{let t={.1:[0,.2],.04:[.2,.5],.02:[.5,.8],.005:[.8,.99]};for(let i in t)if(e>=t[i][0]&&e<t[i][1])return parseFloat(i);return 0})(),_(Me(e+r,0,.994))},tt=r=>{if(rt())return document.getElementById(f);document.documentElement.classList.add(`${f}-busy`);let e=w.querySelector(g.barSelector),t=r?"-100":z(A||0),i=He();return e.style.transition="all 0 linear",e.style.transform=`translate3d(${t}%,0,0)`,g.showSpinner||w.querySelector(g.spinnerSelector)?.remove(),i!==document.body&&i.classList.add(`${f}-custom-parent`),i.appendChild(w),w},He=()=>it(g.parent)?g.parent:document.querySelector(g.parent),De=()=>{document.documentElement.classList.remove(`${f}-busy`),He().classList.remove(`${f}-custom-parent`),w?.remove()},rt=()=>document.getElementById(f)!==null,it=r=>typeof HTMLElement=="object"?r instanceof HTMLElement:r&&typeof r=="object"&&r.nodeType===1&&typeof r.nodeName=="string";function Me(r,e,t){return r<e?e:r>t?t:r}var z=r=>(-1+r)*100,st=(()=>{let r=[],e=()=>{let t=r.shift();t&&t(e)};return t=>{r.push(t),r.length===1&&e()}})(),nt=r=>{let e=document.createElement("style");e.textContent=`
|
|
2
|
-
|
|
1
|
+
// src/debounce.ts
|
|
2
|
+
function debounce(fn, delay) {
|
|
3
|
+
let timeoutID;
|
|
4
|
+
return function(...args) {
|
|
5
|
+
clearTimeout(timeoutID);
|
|
6
|
+
timeoutID = setTimeout(() => fn.apply(this, args), delay);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/events.ts
|
|
11
|
+
function fireEvent(name, options) {
|
|
12
|
+
return document.dispatchEvent(new CustomEvent(`inertia:${name}`, options));
|
|
13
|
+
}
|
|
14
|
+
var fireBeforeEvent = (visit) => {
|
|
15
|
+
return fireEvent("before", { cancelable: true, detail: { visit } });
|
|
16
|
+
};
|
|
17
|
+
var fireErrorEvent = (errors) => {
|
|
18
|
+
return fireEvent("error", { detail: { errors } });
|
|
19
|
+
};
|
|
20
|
+
var fireExceptionEvent = (exception) => {
|
|
21
|
+
return fireEvent("exception", { cancelable: true, detail: { exception } });
|
|
22
|
+
};
|
|
23
|
+
var fireFinishEvent = (visit) => {
|
|
24
|
+
return fireEvent("finish", { detail: { visit } });
|
|
25
|
+
};
|
|
26
|
+
var fireInvalidEvent = (response) => {
|
|
27
|
+
return fireEvent("invalid", { cancelable: true, detail: { response } });
|
|
28
|
+
};
|
|
29
|
+
var fireNavigateEvent = (page2) => {
|
|
30
|
+
return fireEvent("navigate", { detail: { page: page2 } });
|
|
31
|
+
};
|
|
32
|
+
var fireProgressEvent = (progress3) => {
|
|
33
|
+
return fireEvent("progress", { detail: { progress: progress3 } });
|
|
34
|
+
};
|
|
35
|
+
var fireStartEvent = (visit) => {
|
|
36
|
+
return fireEvent("start", { detail: { visit } });
|
|
37
|
+
};
|
|
38
|
+
var fireSuccessEvent = (page2) => {
|
|
39
|
+
return fireEvent("success", { detail: { page: page2 } });
|
|
40
|
+
};
|
|
41
|
+
var firePrefetchedEvent = (response, visit) => {
|
|
42
|
+
return fireEvent("prefetched", { detail: { fetchedAt: Date.now(), response: response.data, visit } });
|
|
43
|
+
};
|
|
44
|
+
var firePrefetchingEvent = (visit) => {
|
|
45
|
+
return fireEvent("prefetching", { detail: { visit } });
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/sessionStorage.ts
|
|
49
|
+
var SessionStorage = class {
|
|
50
|
+
static set(key, value) {
|
|
51
|
+
if (typeof window !== "undefined") {
|
|
52
|
+
window.sessionStorage.setItem(key, JSON.stringify(value));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
static get(key) {
|
|
56
|
+
if (typeof window !== "undefined") {
|
|
57
|
+
return JSON.parse(window.sessionStorage.getItem(key) || "null");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static merge(key, value) {
|
|
61
|
+
const existing = this.get(key);
|
|
62
|
+
if (existing === null) {
|
|
63
|
+
this.set(key, value);
|
|
64
|
+
} else {
|
|
65
|
+
this.set(key, { ...existing, ...value });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static remove(key) {
|
|
69
|
+
if (typeof window !== "undefined") {
|
|
70
|
+
window.sessionStorage.removeItem(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static removeNested(key, nestedKey) {
|
|
74
|
+
const existing = this.get(key);
|
|
75
|
+
if (existing !== null) {
|
|
76
|
+
delete existing[nestedKey];
|
|
77
|
+
this.set(key, existing);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
static exists(key) {
|
|
81
|
+
try {
|
|
82
|
+
return this.get(key) !== null;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
static clear() {
|
|
88
|
+
if (typeof window !== "undefined") {
|
|
89
|
+
window.sessionStorage.clear();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
SessionStorage.locationVisitKey = "inertiaLocationVisit";
|
|
94
|
+
|
|
95
|
+
// src/encryption.ts
|
|
96
|
+
var encryptHistory = async (data) => {
|
|
97
|
+
if (typeof window === "undefined") {
|
|
98
|
+
throw new Error("Unable to encrypt history");
|
|
99
|
+
}
|
|
100
|
+
const iv = getIv();
|
|
101
|
+
const storedKey = await getKeyFromSessionStorage();
|
|
102
|
+
const key = await getOrCreateKey(storedKey);
|
|
103
|
+
if (!key) {
|
|
104
|
+
throw new Error("Unable to encrypt history");
|
|
105
|
+
}
|
|
106
|
+
const encrypted = await encryptData(iv, key, data);
|
|
107
|
+
return encrypted;
|
|
108
|
+
};
|
|
109
|
+
var historySessionStorageKeys = {
|
|
110
|
+
key: "historyKey",
|
|
111
|
+
iv: "historyIv"
|
|
112
|
+
};
|
|
113
|
+
var decryptHistory = async (data) => {
|
|
114
|
+
const iv = getIv();
|
|
115
|
+
const storedKey = await getKeyFromSessionStorage();
|
|
116
|
+
if (!storedKey) {
|
|
117
|
+
throw new Error("Unable to decrypt history");
|
|
118
|
+
}
|
|
119
|
+
return await decryptData(iv, storedKey, data);
|
|
120
|
+
};
|
|
121
|
+
var encryptData = async (iv, key, data) => {
|
|
122
|
+
if (typeof window === "undefined") {
|
|
123
|
+
throw new Error("Unable to encrypt history");
|
|
124
|
+
}
|
|
125
|
+
if (typeof window.crypto.subtle === "undefined") {
|
|
126
|
+
console.warn("Encryption is not supported in this environment. SSL is required.");
|
|
127
|
+
return Promise.resolve(data);
|
|
128
|
+
}
|
|
129
|
+
const textEncoder = new TextEncoder();
|
|
130
|
+
const str = JSON.stringify(data);
|
|
131
|
+
const encoded = new Uint8Array(str.length * 3);
|
|
132
|
+
const result = textEncoder.encodeInto(str, encoded);
|
|
133
|
+
return window.crypto.subtle.encrypt(
|
|
134
|
+
{
|
|
135
|
+
name: "AES-GCM",
|
|
136
|
+
iv
|
|
137
|
+
},
|
|
138
|
+
key,
|
|
139
|
+
encoded.subarray(0, result.written)
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
var decryptData = async (iv, key, data) => {
|
|
143
|
+
if (typeof window.crypto.subtle === "undefined") {
|
|
144
|
+
console.warn("Decryption is not supported in this environment. SSL is required.");
|
|
145
|
+
return Promise.resolve(data);
|
|
146
|
+
}
|
|
147
|
+
const decrypted = await window.crypto.subtle.decrypt(
|
|
148
|
+
{
|
|
149
|
+
name: "AES-GCM",
|
|
150
|
+
iv
|
|
151
|
+
},
|
|
152
|
+
key,
|
|
153
|
+
data
|
|
154
|
+
);
|
|
155
|
+
return JSON.parse(new TextDecoder().decode(decrypted));
|
|
156
|
+
};
|
|
157
|
+
var getIv = () => {
|
|
158
|
+
const ivString = SessionStorage.get(historySessionStorageKeys.iv);
|
|
159
|
+
if (ivString) {
|
|
160
|
+
return new Uint8Array(ivString);
|
|
161
|
+
}
|
|
162
|
+
const iv = window.crypto.getRandomValues(new Uint8Array(12));
|
|
163
|
+
SessionStorage.set(historySessionStorageKeys.iv, Array.from(iv));
|
|
164
|
+
return iv;
|
|
165
|
+
};
|
|
166
|
+
var createKey = async () => {
|
|
167
|
+
if (typeof window.crypto.subtle === "undefined") {
|
|
168
|
+
console.warn("Encryption is not supported in this environment. SSL is required.");
|
|
169
|
+
return Promise.resolve(null);
|
|
170
|
+
}
|
|
171
|
+
return window.crypto.subtle.generateKey(
|
|
172
|
+
{
|
|
173
|
+
name: "AES-GCM",
|
|
174
|
+
length: 256
|
|
175
|
+
},
|
|
176
|
+
true,
|
|
177
|
+
["encrypt", "decrypt"]
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
var saveKey = async (key) => {
|
|
181
|
+
if (typeof window.crypto.subtle === "undefined") {
|
|
182
|
+
console.warn("Encryption is not supported in this environment. SSL is required.");
|
|
183
|
+
return Promise.resolve();
|
|
184
|
+
}
|
|
185
|
+
const keyData = await window.crypto.subtle.exportKey("raw", key);
|
|
186
|
+
SessionStorage.set(historySessionStorageKeys.key, Array.from(new Uint8Array(keyData)));
|
|
187
|
+
};
|
|
188
|
+
var getOrCreateKey = async (key) => {
|
|
189
|
+
if (key) {
|
|
190
|
+
return key;
|
|
191
|
+
}
|
|
192
|
+
const newKey = await createKey();
|
|
193
|
+
if (!newKey) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
await saveKey(newKey);
|
|
197
|
+
return newKey;
|
|
198
|
+
};
|
|
199
|
+
var getKeyFromSessionStorage = async () => {
|
|
200
|
+
const stringKey = SessionStorage.get(historySessionStorageKeys.key);
|
|
201
|
+
if (!stringKey) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const key = await window.crypto.subtle.importKey(
|
|
205
|
+
"raw",
|
|
206
|
+
new Uint8Array(stringKey),
|
|
207
|
+
{
|
|
208
|
+
name: "AES-GCM",
|
|
209
|
+
length: 256
|
|
210
|
+
},
|
|
211
|
+
true,
|
|
212
|
+
["encrypt", "decrypt"]
|
|
213
|
+
);
|
|
214
|
+
return key;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/scroll.ts
|
|
218
|
+
var Scroll = class {
|
|
219
|
+
static save() {
|
|
220
|
+
history.saveScrollPositions(
|
|
221
|
+
Array.from(this.regions()).map((region) => ({
|
|
222
|
+
top: region.scrollTop,
|
|
223
|
+
left: region.scrollLeft
|
|
224
|
+
}))
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
static regions() {
|
|
228
|
+
return document.querySelectorAll("[scroll-region]");
|
|
229
|
+
}
|
|
230
|
+
static reset() {
|
|
231
|
+
const anchorHash = typeof window !== "undefined" ? window.location.hash : null;
|
|
232
|
+
if (!anchorHash) {
|
|
233
|
+
window.scrollTo(0, 0);
|
|
234
|
+
}
|
|
235
|
+
this.regions().forEach((region) => {
|
|
236
|
+
if (typeof region.scrollTo === "function") {
|
|
237
|
+
region.scrollTo(0, 0);
|
|
238
|
+
} else {
|
|
239
|
+
region.scrollTop = 0;
|
|
240
|
+
region.scrollLeft = 0;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
this.save();
|
|
244
|
+
if (anchorHash) {
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
const anchorElement = document.getElementById(anchorHash.slice(1));
|
|
247
|
+
anchorElement ? anchorElement.scrollIntoView() : window.scrollTo(0, 0);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
static restore(scrollRegions) {
|
|
252
|
+
this.restoreDocument();
|
|
253
|
+
this.regions().forEach((region, index) => {
|
|
254
|
+
const scrollPosition = scrollRegions[index];
|
|
255
|
+
if (!scrollPosition) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (typeof region.scrollTo === "function") {
|
|
259
|
+
region.scrollTo(scrollPosition.left, scrollPosition.top);
|
|
260
|
+
} else {
|
|
261
|
+
region.scrollTop = scrollPosition.top;
|
|
262
|
+
region.scrollLeft = scrollPosition.left;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
static restoreDocument() {
|
|
267
|
+
const scrollPosition = history.getDocumentScrollPosition();
|
|
268
|
+
if (typeof window !== "undefined") {
|
|
269
|
+
window.scrollTo(scrollPosition.left, scrollPosition.top);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
static onScroll(event) {
|
|
273
|
+
const target = event.target;
|
|
274
|
+
if (typeof target.hasAttribute === "function" && target.hasAttribute("scroll-region")) {
|
|
275
|
+
this.save();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
static onWindowScroll() {
|
|
279
|
+
history.saveDocumentScrollPosition({
|
|
280
|
+
top: window.scrollY,
|
|
281
|
+
left: window.scrollX
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/url.ts
|
|
287
|
+
import * as qs from "qs";
|
|
288
|
+
|
|
289
|
+
// src/files.ts
|
|
290
|
+
function hasFiles(data) {
|
|
291
|
+
return data instanceof File || data instanceof Blob || data instanceof FileList && data.length > 0 || data instanceof FormData && Array.from(data.values()).some((value) => hasFiles(value)) || typeof data === "object" && data !== null && Object.values(data).some((value) => hasFiles(value));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/formData.ts
|
|
295
|
+
var isFormData = (value) => value instanceof FormData;
|
|
296
|
+
function objectToFormData(source, form = new FormData(), parentKey = null) {
|
|
297
|
+
source = source || {};
|
|
298
|
+
for (const key in source) {
|
|
299
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
300
|
+
append(form, composeKey(parentKey, key), source[key]);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return form;
|
|
304
|
+
}
|
|
305
|
+
function composeKey(parent, key) {
|
|
306
|
+
return parent ? parent + "[" + key + "]" : key;
|
|
307
|
+
}
|
|
308
|
+
function append(form, key, value) {
|
|
309
|
+
if (Array.isArray(value)) {
|
|
310
|
+
return Array.from(value.keys()).forEach((index) => append(form, composeKey(key, index.toString()), value[index]));
|
|
311
|
+
} else if (value instanceof Date) {
|
|
312
|
+
return form.append(key, value.toISOString());
|
|
313
|
+
} else if (value instanceof File) {
|
|
314
|
+
return form.append(key, value, value.name);
|
|
315
|
+
} else if (value instanceof Blob) {
|
|
316
|
+
return form.append(key, value);
|
|
317
|
+
} else if (typeof value === "boolean") {
|
|
318
|
+
return form.append(key, value ? "1" : "0");
|
|
319
|
+
} else if (typeof value === "string") {
|
|
320
|
+
return form.append(key, value);
|
|
321
|
+
} else if (typeof value === "number") {
|
|
322
|
+
return form.append(key, `${value}`);
|
|
323
|
+
} else if (value === null || value === void 0) {
|
|
324
|
+
return form.append(key, "");
|
|
325
|
+
}
|
|
326
|
+
objectToFormData(value, form, key);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/url.ts
|
|
330
|
+
function hrefToUrl(href) {
|
|
331
|
+
return new URL(href.toString(), typeof window === "undefined" ? void 0 : window.location.toString());
|
|
332
|
+
}
|
|
333
|
+
var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFormat) => {
|
|
334
|
+
let url = typeof href === "string" ? hrefToUrl(href) : href;
|
|
335
|
+
if ((hasFiles(data) || forceFormData) && !isFormData(data)) {
|
|
336
|
+
data = objectToFormData(data);
|
|
337
|
+
}
|
|
338
|
+
if (isFormData(data)) {
|
|
339
|
+
return [url, data];
|
|
340
|
+
}
|
|
341
|
+
const [_href, _data] = mergeDataIntoQueryString(method, url, data, queryStringArrayFormat);
|
|
342
|
+
return [hrefToUrl(_href), _data];
|
|
343
|
+
};
|
|
344
|
+
function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets") {
|
|
345
|
+
const hasHost = /^[a-z][a-z0-9+.-]*:\/\//i.test(href.toString());
|
|
346
|
+
const hasAbsolutePath = hasHost || href.toString().startsWith("/");
|
|
347
|
+
const hasRelativePath = !hasAbsolutePath && !href.toString().startsWith("#") && !href.toString().startsWith("?");
|
|
348
|
+
const hasRelativePathWithDotPrefix = /^[.]{1,2}([/]|$)/.test(href.toString());
|
|
349
|
+
const hasSearch = href.toString().includes("?") || method === "get" && Object.keys(data).length;
|
|
350
|
+
const hasHash = href.toString().includes("#");
|
|
351
|
+
const url = new URL(href.toString(), typeof window === "undefined" ? "http://localhost" : window.location.toString());
|
|
352
|
+
if (method === "get" && Object.keys(data).length) {
|
|
353
|
+
const parseOptions = { ignoreQueryPrefix: true, parseArrays: false };
|
|
354
|
+
url.search = qs.stringify(
|
|
355
|
+
{ ...qs.parse(url.search, parseOptions), ...data },
|
|
356
|
+
{
|
|
357
|
+
encodeValuesOnly: true,
|
|
358
|
+
arrayFormat: qsArrayFormat
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
data = {};
|
|
362
|
+
}
|
|
363
|
+
return [
|
|
364
|
+
[
|
|
365
|
+
hasHost ? `${url.protocol}//${url.host}` : "",
|
|
366
|
+
hasAbsolutePath ? url.pathname : "",
|
|
367
|
+
hasRelativePath ? url.pathname.substring(hasRelativePathWithDotPrefix ? 0 : 1) : "",
|
|
368
|
+
hasSearch ? url.search : "",
|
|
369
|
+
hasHash ? url.hash : ""
|
|
370
|
+
].join(""),
|
|
371
|
+
data
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
function urlWithoutHash(url) {
|
|
375
|
+
url = new URL(url.href);
|
|
376
|
+
url.hash = "";
|
|
377
|
+
return url;
|
|
378
|
+
}
|
|
379
|
+
var setHashIfSameUrl = (originUrl, destinationUrl) => {
|
|
380
|
+
if (originUrl.hash && !destinationUrl.hash && urlWithoutHash(originUrl).href === destinationUrl.href) {
|
|
381
|
+
destinationUrl.hash = originUrl.hash;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
var isSameUrlWithoutHash = (url1, url2) => {
|
|
385
|
+
return urlWithoutHash(url1).href === urlWithoutHash(url2).href;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/page.ts
|
|
389
|
+
var CurrentPage = class {
|
|
390
|
+
constructor() {
|
|
391
|
+
this.componentId = {};
|
|
392
|
+
this.listeners = [];
|
|
393
|
+
this.isFirstPageLoad = true;
|
|
394
|
+
this.cleared = false;
|
|
395
|
+
}
|
|
396
|
+
init({ initialPage, swapComponent, resolveComponent }) {
|
|
397
|
+
this.page = initialPage;
|
|
398
|
+
this.swapComponent = swapComponent;
|
|
399
|
+
this.resolveComponent = resolveComponent;
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
set(page2, {
|
|
403
|
+
replace = false,
|
|
404
|
+
preserveScroll = false,
|
|
405
|
+
preserveState = false
|
|
406
|
+
} = {}) {
|
|
407
|
+
this.componentId = {};
|
|
408
|
+
const componentId = this.componentId;
|
|
409
|
+
if (page2.clearHistory) {
|
|
410
|
+
history.clear();
|
|
411
|
+
}
|
|
412
|
+
return this.resolve(page2.component).then((component) => {
|
|
413
|
+
if (componentId !== this.componentId) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
page2.rememberedState ?? (page2.rememberedState = {});
|
|
417
|
+
const location = typeof window !== "undefined" ? window.location : new URL(page2.url);
|
|
418
|
+
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
419
|
+
return new Promise((resolve) => {
|
|
420
|
+
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
421
|
+
}).then(() => {
|
|
422
|
+
const isNewComponent = !this.isTheSame(page2);
|
|
423
|
+
this.page = page2;
|
|
424
|
+
this.cleared = false;
|
|
425
|
+
if (isNewComponent) {
|
|
426
|
+
this.fireEventsFor("newComponent");
|
|
427
|
+
}
|
|
428
|
+
if (this.isFirstPageLoad) {
|
|
429
|
+
this.fireEventsFor("firstLoad");
|
|
430
|
+
}
|
|
431
|
+
this.isFirstPageLoad = false;
|
|
432
|
+
return this.swap({ component, page: page2, preserveState }).then(() => {
|
|
433
|
+
if (!preserveScroll) {
|
|
434
|
+
Scroll.reset();
|
|
435
|
+
}
|
|
436
|
+
eventHandler.fireInternalEvent("loadDeferredProps");
|
|
437
|
+
if (!replace) {
|
|
438
|
+
fireNavigateEvent(page2);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
setQuietly(page2, {
|
|
445
|
+
preserveState = false
|
|
446
|
+
} = {}) {
|
|
447
|
+
return this.resolve(page2.component).then((component) => {
|
|
448
|
+
this.page = page2;
|
|
449
|
+
this.cleared = false;
|
|
450
|
+
history.setCurrent(page2);
|
|
451
|
+
return this.swap({ component, page: page2, preserveState });
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
clear() {
|
|
455
|
+
this.cleared = true;
|
|
456
|
+
}
|
|
457
|
+
isCleared() {
|
|
458
|
+
return this.cleared;
|
|
459
|
+
}
|
|
460
|
+
get() {
|
|
461
|
+
return this.page;
|
|
462
|
+
}
|
|
463
|
+
merge(data) {
|
|
464
|
+
this.page = { ...this.page, ...data };
|
|
465
|
+
}
|
|
466
|
+
setUrlHash(hash) {
|
|
467
|
+
if (!this.page.url.includes(hash)) {
|
|
468
|
+
this.page.url += hash;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
remember(data) {
|
|
472
|
+
this.page.rememberedState = data;
|
|
473
|
+
}
|
|
474
|
+
swap({
|
|
475
|
+
component,
|
|
476
|
+
page: page2,
|
|
477
|
+
preserveState
|
|
478
|
+
}) {
|
|
479
|
+
return this.swapComponent({ component, page: page2, preserveState });
|
|
480
|
+
}
|
|
481
|
+
resolve(component) {
|
|
482
|
+
return Promise.resolve(this.resolveComponent(component));
|
|
483
|
+
}
|
|
484
|
+
isTheSame(page2) {
|
|
485
|
+
return this.page.component === page2.component;
|
|
486
|
+
}
|
|
487
|
+
on(event, callback) {
|
|
488
|
+
this.listeners.push({ event, callback });
|
|
489
|
+
return () => {
|
|
490
|
+
this.listeners = this.listeners.filter((listener) => listener.event !== event && listener.callback !== callback);
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
fireEventsFor(event) {
|
|
494
|
+
this.listeners.filter((listener) => listener.event === event).forEach((listener) => listener.callback());
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var page = new CurrentPage();
|
|
498
|
+
|
|
499
|
+
// src/queue.ts
|
|
500
|
+
var Queue = class {
|
|
501
|
+
constructor() {
|
|
502
|
+
this.items = [];
|
|
503
|
+
this.processingPromise = null;
|
|
504
|
+
}
|
|
505
|
+
add(item) {
|
|
506
|
+
this.items.push(item);
|
|
507
|
+
return this.process();
|
|
508
|
+
}
|
|
509
|
+
process() {
|
|
510
|
+
this.processingPromise ?? (this.processingPromise = this.processNext().then(() => {
|
|
511
|
+
this.processingPromise = null;
|
|
512
|
+
}));
|
|
513
|
+
return this.processingPromise;
|
|
514
|
+
}
|
|
515
|
+
processNext() {
|
|
516
|
+
const next = this.items.shift();
|
|
517
|
+
if (next) {
|
|
518
|
+
return Promise.resolve(next()).then(() => this.processNext());
|
|
519
|
+
}
|
|
520
|
+
return Promise.resolve();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/history.ts
|
|
525
|
+
var isServer = typeof window === "undefined";
|
|
526
|
+
var queue = new Queue();
|
|
527
|
+
var isChromeIOS = !isServer && /CriOS/.test(window.navigator.userAgent);
|
|
528
|
+
var History = class {
|
|
529
|
+
constructor() {
|
|
530
|
+
this.rememberedState = "rememberedState";
|
|
531
|
+
this.scrollRegions = "scrollRegions";
|
|
532
|
+
this.preserveUrl = false;
|
|
533
|
+
this.current = {};
|
|
534
|
+
// We need initialState for `restore`
|
|
535
|
+
this.initialState = null;
|
|
536
|
+
}
|
|
537
|
+
remember(data, key) {
|
|
538
|
+
this.replaceState({
|
|
539
|
+
...page.get(),
|
|
540
|
+
rememberedState: {
|
|
541
|
+
...page.get()?.rememberedState ?? {},
|
|
542
|
+
[key]: data
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
restore(key) {
|
|
547
|
+
if (!isServer) {
|
|
548
|
+
return this.current[this.rememberedState] ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
pushState(page2, cb = null) {
|
|
552
|
+
if (isServer) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (this.preserveUrl) {
|
|
556
|
+
cb && cb();
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
this.current = page2;
|
|
560
|
+
queue.add(() => {
|
|
561
|
+
return this.getPageData(page2).then((data) => {
|
|
562
|
+
const doPush = () => {
|
|
563
|
+
this.doPushState({ page: data }, page2.url);
|
|
564
|
+
cb && cb();
|
|
565
|
+
};
|
|
566
|
+
if (isChromeIOS) {
|
|
567
|
+
setTimeout(doPush);
|
|
568
|
+
} else {
|
|
569
|
+
doPush();
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
getPageData(page2) {
|
|
575
|
+
return new Promise((resolve) => {
|
|
576
|
+
return page2.encryptHistory ? encryptHistory(page2).then(resolve) : resolve(page2);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
processQueue() {
|
|
580
|
+
return queue.process();
|
|
581
|
+
}
|
|
582
|
+
decrypt(page2 = null) {
|
|
583
|
+
if (isServer) {
|
|
584
|
+
return Promise.resolve(page2 ?? page.get());
|
|
585
|
+
}
|
|
586
|
+
const pageData = page2 ?? window.history.state?.page;
|
|
587
|
+
return this.decryptPageData(pageData).then((data) => {
|
|
588
|
+
if (!data) {
|
|
589
|
+
throw new Error("Unable to decrypt history");
|
|
590
|
+
}
|
|
591
|
+
if (this.initialState === null) {
|
|
592
|
+
this.initialState = data ?? void 0;
|
|
593
|
+
} else {
|
|
594
|
+
this.current = data ?? {};
|
|
595
|
+
}
|
|
596
|
+
return data;
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
decryptPageData(pageData) {
|
|
600
|
+
return pageData instanceof ArrayBuffer ? decryptHistory(pageData) : Promise.resolve(pageData);
|
|
601
|
+
}
|
|
602
|
+
saveScrollPositions(scrollRegions) {
|
|
603
|
+
queue.add(() => {
|
|
604
|
+
return Promise.resolve().then(() => {
|
|
605
|
+
if (!window.history.state?.page) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
this.doReplaceState(
|
|
609
|
+
{
|
|
610
|
+
page: window.history.state.page,
|
|
611
|
+
scrollRegions
|
|
612
|
+
}
|
|
613
|
+
);
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
saveDocumentScrollPosition(scrollRegion) {
|
|
618
|
+
queue.add(() => {
|
|
619
|
+
return Promise.resolve().then(() => {
|
|
620
|
+
if (!window.history.state?.page) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
this.doReplaceState(
|
|
624
|
+
{
|
|
625
|
+
page: window.history.state.page,
|
|
626
|
+
documentScrollPosition: scrollRegion
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
getScrollRegions() {
|
|
633
|
+
return window.history.state?.scrollRegions || [];
|
|
634
|
+
}
|
|
635
|
+
getDocumentScrollPosition() {
|
|
636
|
+
return window.history.state?.documentScrollPosition || { top: 0, left: 0 };
|
|
637
|
+
}
|
|
638
|
+
replaceState(page2, cb = null) {
|
|
639
|
+
page.merge(page2);
|
|
640
|
+
if (isServer) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (this.preserveUrl) {
|
|
644
|
+
cb && cb();
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
this.current = page2;
|
|
648
|
+
queue.add(() => {
|
|
649
|
+
return this.getPageData(page2).then((data) => {
|
|
650
|
+
const doReplace = () => {
|
|
651
|
+
this.doReplaceState({ page: data }, page2.url);
|
|
652
|
+
cb && cb();
|
|
653
|
+
};
|
|
654
|
+
if (isChromeIOS) {
|
|
655
|
+
setTimeout(doReplace);
|
|
656
|
+
} else {
|
|
657
|
+
doReplace();
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
doReplaceState(data, url) {
|
|
663
|
+
window.history.replaceState(
|
|
664
|
+
{
|
|
665
|
+
...data,
|
|
666
|
+
scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
|
|
667
|
+
documentScrollPosition: data.documentScrollPosition ?? window.history.state?.documentScrollPosition
|
|
668
|
+
},
|
|
669
|
+
"",
|
|
670
|
+
url
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
doPushState(data, url) {
|
|
674
|
+
window.history.pushState(data, "", url);
|
|
675
|
+
}
|
|
676
|
+
getState(key, defaultValue) {
|
|
677
|
+
return this.current?.[key] ?? defaultValue;
|
|
678
|
+
}
|
|
679
|
+
deleteState(key) {
|
|
680
|
+
if (this.current[key] !== void 0) {
|
|
681
|
+
delete this.current[key];
|
|
682
|
+
this.replaceState(this.current);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
hasAnyState() {
|
|
686
|
+
return !!this.getAllState();
|
|
687
|
+
}
|
|
688
|
+
clear() {
|
|
689
|
+
SessionStorage.remove(historySessionStorageKeys.key);
|
|
690
|
+
SessionStorage.remove(historySessionStorageKeys.iv);
|
|
691
|
+
}
|
|
692
|
+
setCurrent(page2) {
|
|
693
|
+
this.current = page2;
|
|
694
|
+
}
|
|
695
|
+
isValidState(state) {
|
|
696
|
+
return !!state.page;
|
|
697
|
+
}
|
|
698
|
+
getAllState() {
|
|
699
|
+
return this.current;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
if (typeof window !== "undefined" && window.history.scrollRestoration) {
|
|
703
|
+
window.history.scrollRestoration = "manual";
|
|
704
|
+
}
|
|
705
|
+
var history = new History();
|
|
706
|
+
|
|
707
|
+
// src/eventHandler.ts
|
|
708
|
+
var EventHandler = class {
|
|
709
|
+
constructor() {
|
|
710
|
+
this.internalListeners = [];
|
|
711
|
+
}
|
|
712
|
+
init() {
|
|
713
|
+
if (typeof window !== "undefined") {
|
|
714
|
+
window.addEventListener("popstate", this.handlePopstateEvent.bind(this));
|
|
715
|
+
window.addEventListener("scroll", debounce(Scroll.onWindowScroll.bind(Scroll), 100), true);
|
|
716
|
+
}
|
|
717
|
+
if (typeof document !== "undefined") {
|
|
718
|
+
document.addEventListener("scroll", debounce(Scroll.onScroll.bind(Scroll), 100), true);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
onGlobalEvent(type, callback) {
|
|
722
|
+
const listener = (event) => {
|
|
723
|
+
const response = callback(event);
|
|
724
|
+
if (event.cancelable && !event.defaultPrevented && response === false) {
|
|
725
|
+
event.preventDefault();
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
return this.registerListener(`inertia:${type}`, listener);
|
|
729
|
+
}
|
|
730
|
+
on(event, callback) {
|
|
731
|
+
this.internalListeners.push({ event, listener: callback });
|
|
732
|
+
return () => {
|
|
733
|
+
this.internalListeners = this.internalListeners.filter((listener) => listener.listener !== callback);
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
onMissingHistoryItem() {
|
|
737
|
+
page.clear();
|
|
738
|
+
this.fireInternalEvent("missingHistoryItem");
|
|
739
|
+
}
|
|
740
|
+
fireInternalEvent(event) {
|
|
741
|
+
this.internalListeners.filter((listener) => listener.event === event).forEach((listener) => listener.listener());
|
|
742
|
+
}
|
|
743
|
+
registerListener(type, listener) {
|
|
744
|
+
document.addEventListener(type, listener);
|
|
745
|
+
return () => document.removeEventListener(type, listener);
|
|
746
|
+
}
|
|
747
|
+
handlePopstateEvent(event) {
|
|
748
|
+
const state = event.state || null;
|
|
749
|
+
if (state === null) {
|
|
750
|
+
const url = hrefToUrl(page.get().url);
|
|
751
|
+
url.hash = window.location.hash;
|
|
752
|
+
history.replaceState({ ...page.get(), url: url.href });
|
|
753
|
+
Scroll.reset();
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (!history.isValidState(state)) {
|
|
757
|
+
return this.onMissingHistoryItem();
|
|
758
|
+
}
|
|
759
|
+
history.decrypt(state.page).then((data) => {
|
|
760
|
+
if (page.get().version !== data.version) {
|
|
761
|
+
this.onMissingHistoryItem();
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
router.cancelAll();
|
|
765
|
+
page.setQuietly(data, { preserveState: false }).then(() => {
|
|
766
|
+
window.requestAnimationFrame(() => {
|
|
767
|
+
Scroll.restore(history.getScrollRegions());
|
|
768
|
+
});
|
|
769
|
+
fireNavigateEvent(page.get());
|
|
770
|
+
});
|
|
771
|
+
}).catch(() => {
|
|
772
|
+
this.onMissingHistoryItem();
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
var eventHandler = new EventHandler();
|
|
777
|
+
|
|
778
|
+
// src/navigationType.ts
|
|
779
|
+
var NavigationType = class {
|
|
780
|
+
constructor() {
|
|
781
|
+
this.type = this.resolveType();
|
|
782
|
+
}
|
|
783
|
+
resolveType() {
|
|
784
|
+
if (typeof window === "undefined") {
|
|
785
|
+
return "navigate";
|
|
786
|
+
}
|
|
787
|
+
if (window.performance && window.performance.getEntriesByType && window.performance.getEntriesByType("navigation").length > 0) {
|
|
788
|
+
return window.performance.getEntriesByType("navigation")[0].type;
|
|
789
|
+
}
|
|
790
|
+
return "navigate";
|
|
791
|
+
}
|
|
792
|
+
get() {
|
|
793
|
+
return this.type;
|
|
794
|
+
}
|
|
795
|
+
isBackForward() {
|
|
796
|
+
return this.type === "back_forward";
|
|
797
|
+
}
|
|
798
|
+
isReload() {
|
|
799
|
+
return this.type === "reload";
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
var navigationType = new NavigationType();
|
|
803
|
+
|
|
804
|
+
// src/initialVisit.ts
|
|
805
|
+
var InitialVisit = class {
|
|
806
|
+
static handle() {
|
|
807
|
+
this.clearRememberedStateOnReload();
|
|
808
|
+
const scenarios = [this.handleBackForward, this.handleLocation, this.handleDefault];
|
|
809
|
+
scenarios.find((handler) => handler.bind(this)());
|
|
810
|
+
}
|
|
811
|
+
static clearRememberedStateOnReload() {
|
|
812
|
+
if (navigationType.isReload()) {
|
|
813
|
+
history.deleteState(history.rememberedState);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
static handleBackForward() {
|
|
817
|
+
if (!navigationType.isBackForward() || !history.hasAnyState()) {
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
const scrollRegions = history.getScrollRegions();
|
|
821
|
+
history.decrypt().then((data) => {
|
|
822
|
+
page.set(data, { preserveScroll: true, preserveState: true }).then(() => {
|
|
823
|
+
Scroll.restore(scrollRegions);
|
|
824
|
+
fireNavigateEvent(page.get());
|
|
825
|
+
});
|
|
826
|
+
}).catch(() => {
|
|
827
|
+
eventHandler.onMissingHistoryItem();
|
|
828
|
+
});
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* @link https://inertiajs.com/redirects#external-redirects
|
|
833
|
+
*/
|
|
834
|
+
static handleLocation() {
|
|
835
|
+
if (!SessionStorage.exists(SessionStorage.locationVisitKey)) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
const locationVisit = SessionStorage.get(SessionStorage.locationVisitKey) || {};
|
|
839
|
+
SessionStorage.remove(SessionStorage.locationVisitKey);
|
|
840
|
+
if (typeof window !== "undefined") {
|
|
841
|
+
page.setUrlHash(window.location.hash);
|
|
842
|
+
}
|
|
843
|
+
history.decrypt(page.get()).then(() => {
|
|
844
|
+
const rememberedState = history.getState(history.rememberedState, {});
|
|
845
|
+
const scrollRegions = history.getScrollRegions();
|
|
846
|
+
page.remember(rememberedState);
|
|
847
|
+
page.set(page.get(), {
|
|
848
|
+
preserveScroll: locationVisit.preserveScroll,
|
|
849
|
+
preserveState: true
|
|
850
|
+
}).then(() => {
|
|
851
|
+
if (locationVisit.preserveScroll) {
|
|
852
|
+
Scroll.restore(scrollRegions);
|
|
853
|
+
}
|
|
854
|
+
fireNavigateEvent(page.get());
|
|
855
|
+
});
|
|
856
|
+
}).catch(() => {
|
|
857
|
+
eventHandler.onMissingHistoryItem();
|
|
858
|
+
});
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
static handleDefault() {
|
|
862
|
+
if (typeof window !== "undefined") {
|
|
863
|
+
page.setUrlHash(window.location.hash);
|
|
864
|
+
}
|
|
865
|
+
page.set(page.get(), { preserveScroll: true, preserveState: true }).then(() => {
|
|
866
|
+
if (navigationType.isReload()) {
|
|
867
|
+
Scroll.restore(history.getScrollRegions());
|
|
868
|
+
}
|
|
869
|
+
fireNavigateEvent(page.get());
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// src/poll.ts
|
|
875
|
+
var Poll = class {
|
|
876
|
+
constructor(interval, cb, options) {
|
|
877
|
+
this.id = null;
|
|
878
|
+
this.throttle = false;
|
|
879
|
+
this.keepAlive = false;
|
|
880
|
+
this.cbCount = 0;
|
|
881
|
+
this.keepAlive = options.keepAlive ?? false;
|
|
882
|
+
this.cb = cb;
|
|
883
|
+
this.interval = interval;
|
|
884
|
+
if (options.autoStart ?? true) {
|
|
885
|
+
this.start();
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
stop() {
|
|
889
|
+
if (this.id) {
|
|
890
|
+
clearInterval(this.id);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
start() {
|
|
894
|
+
if (typeof window === "undefined") {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
this.stop();
|
|
898
|
+
this.id = window.setInterval(() => {
|
|
899
|
+
if (!this.throttle || this.cbCount % 10 === 0) {
|
|
900
|
+
this.cb();
|
|
901
|
+
}
|
|
902
|
+
if (this.throttle) {
|
|
903
|
+
this.cbCount++;
|
|
904
|
+
}
|
|
905
|
+
}, this.interval);
|
|
906
|
+
}
|
|
907
|
+
isInBackground(hidden) {
|
|
908
|
+
this.throttle = this.keepAlive ? false : hidden;
|
|
909
|
+
if (this.throttle) {
|
|
910
|
+
this.cbCount = 0;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
// src/polls.ts
|
|
916
|
+
var Polls = class {
|
|
917
|
+
constructor() {
|
|
918
|
+
this.polls = [];
|
|
919
|
+
this.setupVisibilityListener();
|
|
920
|
+
}
|
|
921
|
+
add(interval, cb, options) {
|
|
922
|
+
const poll = new Poll(interval, cb, options);
|
|
923
|
+
this.polls.push(poll);
|
|
924
|
+
return {
|
|
925
|
+
stop: () => poll.stop(),
|
|
926
|
+
start: () => poll.start()
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
clear() {
|
|
930
|
+
this.polls.forEach((poll) => poll.stop());
|
|
931
|
+
this.polls = [];
|
|
932
|
+
}
|
|
933
|
+
setupVisibilityListener() {
|
|
934
|
+
if (typeof document === "undefined") {
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
document.addEventListener(
|
|
938
|
+
"visibilitychange",
|
|
939
|
+
() => {
|
|
940
|
+
this.polls.forEach((poll) => poll.isInBackground(document.hidden));
|
|
941
|
+
},
|
|
942
|
+
false
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
var polls = new Polls();
|
|
947
|
+
|
|
948
|
+
// src/prefetched.ts
|
|
949
|
+
import { cloneDeep } from "es-toolkit";
|
|
950
|
+
|
|
951
|
+
// src/objectUtils.ts
|
|
952
|
+
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
953
|
+
if (obj1 === obj2) {
|
|
954
|
+
return true;
|
|
955
|
+
}
|
|
956
|
+
for (const key in obj1) {
|
|
957
|
+
if (excludeKeys.includes(key)) {
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (obj1[key] === obj2[key]) {
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
if (!compareValues(obj1[key], obj2[key])) {
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return true;
|
|
968
|
+
};
|
|
969
|
+
var compareValues = (value1, value2) => {
|
|
970
|
+
switch (typeof value1) {
|
|
971
|
+
case "object":
|
|
972
|
+
return objectsAreEqual(value1, value2, []);
|
|
973
|
+
case "function":
|
|
974
|
+
return value1.toString() === value2.toString();
|
|
975
|
+
default:
|
|
976
|
+
return value1 === value2;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
// src/time.ts
|
|
981
|
+
var conversionMap = {
|
|
982
|
+
ms: 1,
|
|
983
|
+
s: 1e3,
|
|
984
|
+
m: 1e3 * 60,
|
|
985
|
+
h: 1e3 * 60 * 60,
|
|
986
|
+
d: 1e3 * 60 * 60 * 24
|
|
987
|
+
};
|
|
988
|
+
var timeToMs = (time) => {
|
|
989
|
+
if (typeof time === "number") {
|
|
990
|
+
return time;
|
|
991
|
+
}
|
|
992
|
+
for (const [unit, conversion] of Object.entries(conversionMap)) {
|
|
993
|
+
if (time.endsWith(unit)) {
|
|
994
|
+
return parseFloat(time) * conversion;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return parseInt(time);
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
// src/prefetched.ts
|
|
1001
|
+
var PrefetchedRequests = class {
|
|
1002
|
+
constructor() {
|
|
1003
|
+
this.cached = [];
|
|
1004
|
+
this.inFlightRequests = [];
|
|
1005
|
+
this.removalTimers = [];
|
|
1006
|
+
this.currentUseId = null;
|
|
1007
|
+
}
|
|
1008
|
+
add(params, sendFunc, { cacheFor }) {
|
|
1009
|
+
const inFlight = this.findInFlight(params);
|
|
1010
|
+
if (inFlight) {
|
|
1011
|
+
return Promise.resolve();
|
|
1012
|
+
}
|
|
1013
|
+
const existing = this.findCached(params);
|
|
1014
|
+
if (!params.fresh && existing && existing.staleTimestamp > Date.now()) {
|
|
1015
|
+
return Promise.resolve();
|
|
1016
|
+
}
|
|
1017
|
+
const [stale, expires] = this.extractStaleValues(cacheFor);
|
|
1018
|
+
const promise = new Promise((resolve, reject) => {
|
|
1019
|
+
sendFunc({
|
|
1020
|
+
...params,
|
|
1021
|
+
onCancel: () => {
|
|
1022
|
+
this.remove(params);
|
|
1023
|
+
params.onCancel();
|
|
1024
|
+
reject();
|
|
1025
|
+
},
|
|
1026
|
+
onError: (error) => {
|
|
1027
|
+
this.remove(params);
|
|
1028
|
+
params.onError(error);
|
|
1029
|
+
reject();
|
|
1030
|
+
},
|
|
1031
|
+
onPrefetching(visitParams) {
|
|
1032
|
+
params.onPrefetching(visitParams);
|
|
1033
|
+
},
|
|
1034
|
+
onPrefetched(response, visit) {
|
|
1035
|
+
params.onPrefetched(response, visit);
|
|
1036
|
+
},
|
|
1037
|
+
onPrefetchResponse(response) {
|
|
1038
|
+
resolve(response);
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}).then((response) => {
|
|
1042
|
+
this.remove(params);
|
|
1043
|
+
this.cached.push({
|
|
1044
|
+
params: { ...params },
|
|
1045
|
+
staleTimestamp: Date.now() + stale,
|
|
1046
|
+
response: promise,
|
|
1047
|
+
singleUse: expires === 0,
|
|
1048
|
+
timestamp: Date.now(),
|
|
1049
|
+
inFlight: false
|
|
1050
|
+
});
|
|
1051
|
+
this.scheduleForRemoval(params, expires);
|
|
1052
|
+
this.inFlightRequests = this.inFlightRequests.filter((prefetching) => {
|
|
1053
|
+
return !this.paramsAreEqual(prefetching.params, params);
|
|
1054
|
+
});
|
|
1055
|
+
response.handlePrefetch();
|
|
1056
|
+
return response;
|
|
1057
|
+
});
|
|
1058
|
+
this.inFlightRequests.push({
|
|
1059
|
+
params: { ...params },
|
|
1060
|
+
response: promise,
|
|
1061
|
+
staleTimestamp: null,
|
|
1062
|
+
inFlight: true
|
|
1063
|
+
});
|
|
1064
|
+
return promise;
|
|
1065
|
+
}
|
|
1066
|
+
removeAll() {
|
|
1067
|
+
this.cached = [];
|
|
1068
|
+
this.removalTimers.forEach((removalTimer) => {
|
|
1069
|
+
clearTimeout(removalTimer.timer);
|
|
1070
|
+
});
|
|
1071
|
+
this.removalTimers = [];
|
|
1072
|
+
}
|
|
1073
|
+
remove(params) {
|
|
1074
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
1075
|
+
return !this.paramsAreEqual(prefetched.params, params);
|
|
1076
|
+
});
|
|
1077
|
+
this.clearTimer(params);
|
|
1078
|
+
}
|
|
1079
|
+
extractStaleValues(cacheFor) {
|
|
1080
|
+
const [stale, expires] = this.cacheForToStaleAndExpires(cacheFor);
|
|
1081
|
+
return [timeToMs(stale), timeToMs(expires)];
|
|
1082
|
+
}
|
|
1083
|
+
cacheForToStaleAndExpires(cacheFor) {
|
|
1084
|
+
if (!Array.isArray(cacheFor)) {
|
|
1085
|
+
return [cacheFor, cacheFor];
|
|
1086
|
+
}
|
|
1087
|
+
switch (cacheFor.length) {
|
|
1088
|
+
case 0:
|
|
1089
|
+
return [0, 0];
|
|
1090
|
+
case 1:
|
|
1091
|
+
return [cacheFor[0], cacheFor[0]];
|
|
1092
|
+
default:
|
|
1093
|
+
return [cacheFor[0], cacheFor[1]];
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
clearTimer(params) {
|
|
1097
|
+
const timer = this.removalTimers.find((removalTimer) => {
|
|
1098
|
+
return this.paramsAreEqual(removalTimer.params, params);
|
|
1099
|
+
});
|
|
1100
|
+
if (timer) {
|
|
1101
|
+
clearTimeout(timer.timer);
|
|
1102
|
+
this.removalTimers = this.removalTimers.filter((removalTimer) => removalTimer !== timer);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
scheduleForRemoval(params, expiresIn) {
|
|
1106
|
+
if (typeof window === "undefined") {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
this.clearTimer(params);
|
|
1110
|
+
if (expiresIn > 0) {
|
|
1111
|
+
const timer = window.setTimeout(() => this.remove(params), expiresIn);
|
|
1112
|
+
this.removalTimers.push({
|
|
1113
|
+
params,
|
|
1114
|
+
timer
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
get(params) {
|
|
1119
|
+
return this.findCached(params) || this.findInFlight(params);
|
|
1120
|
+
}
|
|
1121
|
+
use(prefetched, params) {
|
|
1122
|
+
const id = `${params.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
1123
|
+
this.currentUseId = id;
|
|
1124
|
+
return prefetched.response.then((response) => {
|
|
1125
|
+
if (this.currentUseId !== id) {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
response.mergeParams({ ...params, onPrefetched: () => {
|
|
1129
|
+
} });
|
|
1130
|
+
this.removeSingleUseItems(params);
|
|
1131
|
+
return response.handle();
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
removeSingleUseItems(params) {
|
|
1135
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
1136
|
+
if (!this.paramsAreEqual(prefetched.params, params)) {
|
|
1137
|
+
return true;
|
|
1138
|
+
}
|
|
1139
|
+
return !prefetched.singleUse;
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
findCached(params) {
|
|
1143
|
+
return this.cached.find((prefetched) => {
|
|
1144
|
+
return this.paramsAreEqual(prefetched.params, params);
|
|
1145
|
+
}) || null;
|
|
1146
|
+
}
|
|
1147
|
+
findInFlight(params) {
|
|
1148
|
+
return this.inFlightRequests.find((prefetched) => {
|
|
1149
|
+
return this.paramsAreEqual(prefetched.params, params);
|
|
1150
|
+
}) || null;
|
|
1151
|
+
}
|
|
1152
|
+
withoutPurposePrefetchHeader(params) {
|
|
1153
|
+
const newParams = cloneDeep(params);
|
|
1154
|
+
if (newParams.headers["Purpose"] === "prefetch") {
|
|
1155
|
+
delete newParams.headers["Purpose"];
|
|
1156
|
+
}
|
|
1157
|
+
return newParams;
|
|
1158
|
+
}
|
|
1159
|
+
paramsAreEqual(params1, params2) {
|
|
1160
|
+
return objectsAreEqual(
|
|
1161
|
+
this.withoutPurposePrefetchHeader(params1),
|
|
1162
|
+
this.withoutPurposePrefetchHeader(params2),
|
|
1163
|
+
[
|
|
1164
|
+
"showProgress",
|
|
1165
|
+
"replace",
|
|
1166
|
+
"prefetch",
|
|
1167
|
+
"onBefore",
|
|
1168
|
+
"onStart",
|
|
1169
|
+
"onProgress",
|
|
1170
|
+
"onFinish",
|
|
1171
|
+
"onCancel",
|
|
1172
|
+
"onSuccess",
|
|
1173
|
+
"onError",
|
|
1174
|
+
"onPrefetched",
|
|
1175
|
+
"onCancelToken",
|
|
1176
|
+
"onPrefetching",
|
|
1177
|
+
"async"
|
|
1178
|
+
]
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
var prefetchedRequests = new PrefetchedRequests();
|
|
1183
|
+
|
|
1184
|
+
// src/request.ts
|
|
1185
|
+
import { default as axios } from "axios";
|
|
1186
|
+
|
|
1187
|
+
// src/requestParams.ts
|
|
1188
|
+
var RequestParams = class _RequestParams {
|
|
1189
|
+
constructor(params) {
|
|
1190
|
+
this.callbacks = [];
|
|
1191
|
+
if (!params.prefetch) {
|
|
1192
|
+
this.params = params;
|
|
1193
|
+
} else {
|
|
1194
|
+
const wrappedCallbacks = {
|
|
1195
|
+
onBefore: this.wrapCallback(params, "onBefore"),
|
|
1196
|
+
onStart: this.wrapCallback(params, "onStart"),
|
|
1197
|
+
onProgress: this.wrapCallback(params, "onProgress"),
|
|
1198
|
+
onFinish: this.wrapCallback(params, "onFinish"),
|
|
1199
|
+
onCancel: this.wrapCallback(params, "onCancel"),
|
|
1200
|
+
onSuccess: this.wrapCallback(params, "onSuccess"),
|
|
1201
|
+
onError: this.wrapCallback(params, "onError"),
|
|
1202
|
+
onCancelToken: this.wrapCallback(params, "onCancelToken"),
|
|
1203
|
+
onPrefetched: this.wrapCallback(params, "onPrefetched"),
|
|
1204
|
+
onPrefetching: this.wrapCallback(params, "onPrefetching")
|
|
1205
|
+
};
|
|
1206
|
+
this.params = {
|
|
1207
|
+
...params,
|
|
1208
|
+
...wrappedCallbacks,
|
|
1209
|
+
onPrefetchResponse: params.onPrefetchResponse || (() => {
|
|
1210
|
+
})
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
static create(params) {
|
|
1215
|
+
return new _RequestParams(params);
|
|
1216
|
+
}
|
|
1217
|
+
data() {
|
|
1218
|
+
return this.params.method === "get" ? null : this.params.data;
|
|
1219
|
+
}
|
|
1220
|
+
queryParams() {
|
|
1221
|
+
return this.params.method === "get" ? this.params.data : {};
|
|
1222
|
+
}
|
|
1223
|
+
isPartial() {
|
|
1224
|
+
return this.params.only.length > 0 || this.params.except.length > 0 || this.params.reset.length > 0;
|
|
1225
|
+
}
|
|
1226
|
+
onCancelToken(cb) {
|
|
1227
|
+
this.params.onCancelToken({
|
|
1228
|
+
cancel: cb
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
markAsFinished() {
|
|
1232
|
+
this.params.completed = true;
|
|
1233
|
+
this.params.cancelled = false;
|
|
1234
|
+
this.params.interrupted = false;
|
|
1235
|
+
}
|
|
1236
|
+
markAsCancelled({ cancelled = true, interrupted = false }) {
|
|
1237
|
+
this.params.onCancel();
|
|
1238
|
+
this.params.completed = false;
|
|
1239
|
+
this.params.cancelled = cancelled;
|
|
1240
|
+
this.params.interrupted = interrupted;
|
|
1241
|
+
}
|
|
1242
|
+
wasCancelledAtAll() {
|
|
1243
|
+
return this.params.cancelled || this.params.interrupted;
|
|
1244
|
+
}
|
|
1245
|
+
onFinish() {
|
|
1246
|
+
this.params.onFinish(this.params);
|
|
1247
|
+
}
|
|
1248
|
+
onStart() {
|
|
1249
|
+
this.params.onStart(this.params);
|
|
1250
|
+
}
|
|
1251
|
+
onPrefetching() {
|
|
1252
|
+
this.params.onPrefetching(this.params);
|
|
1253
|
+
}
|
|
1254
|
+
onPrefetchResponse(response) {
|
|
1255
|
+
if (this.params.onPrefetchResponse) {
|
|
1256
|
+
this.params.onPrefetchResponse(response);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
all() {
|
|
1260
|
+
return this.params;
|
|
1261
|
+
}
|
|
1262
|
+
headers() {
|
|
1263
|
+
const headers = {
|
|
1264
|
+
...this.params.headers
|
|
1265
|
+
};
|
|
1266
|
+
if (this.isPartial()) {
|
|
1267
|
+
headers["X-Inertia-Partial-Component"] = page.get().component;
|
|
1268
|
+
}
|
|
1269
|
+
const only = this.params.only.concat(this.params.reset);
|
|
1270
|
+
if (only.length > 0) {
|
|
1271
|
+
headers["X-Inertia-Partial-Data"] = only.join(",");
|
|
1272
|
+
}
|
|
1273
|
+
if (this.params.except.length > 0) {
|
|
1274
|
+
headers["X-Inertia-Partial-Except"] = this.params.except.join(",");
|
|
1275
|
+
}
|
|
1276
|
+
if (this.params.reset.length > 0) {
|
|
1277
|
+
headers["X-Inertia-Reset"] = this.params.reset.join(",");
|
|
1278
|
+
}
|
|
1279
|
+
if (this.params.errorBag && this.params.errorBag.length > 0) {
|
|
1280
|
+
headers["X-Inertia-Error-Bag"] = this.params.errorBag;
|
|
1281
|
+
}
|
|
1282
|
+
return headers;
|
|
1283
|
+
}
|
|
1284
|
+
setPreserveOptions(page2) {
|
|
1285
|
+
this.params.preserveScroll = this.resolvePreserveOption(this.params.preserveScroll, page2);
|
|
1286
|
+
this.params.preserveState = this.resolvePreserveOption(this.params.preserveState, page2);
|
|
1287
|
+
}
|
|
1288
|
+
runCallbacks() {
|
|
1289
|
+
this.callbacks.forEach(({ name, args }) => {
|
|
1290
|
+
this.params[name](...args);
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
merge(toMerge) {
|
|
1294
|
+
this.params = {
|
|
1295
|
+
...this.params,
|
|
1296
|
+
...toMerge
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
wrapCallback(params, name) {
|
|
1300
|
+
return (...args) => {
|
|
1301
|
+
this.recordCallback(name, args);
|
|
1302
|
+
params[name](...args);
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
recordCallback(name, args) {
|
|
1306
|
+
this.callbacks.push({ name, args });
|
|
1307
|
+
}
|
|
1308
|
+
resolvePreserveOption(value, page2) {
|
|
1309
|
+
if (typeof value === "function") {
|
|
1310
|
+
return value(page2);
|
|
1311
|
+
}
|
|
1312
|
+
if (value === "errors") {
|
|
1313
|
+
return Object.keys(page2.props.errors || {}).length > 0;
|
|
1314
|
+
}
|
|
1315
|
+
return value;
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// src/modal.ts
|
|
1320
|
+
var modal_default = {
|
|
1321
|
+
modal: null,
|
|
1322
|
+
listener: null,
|
|
1323
|
+
show(html) {
|
|
1324
|
+
if (typeof html === "object") {
|
|
1325
|
+
html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
|
|
1326
|
+
html
|
|
1327
|
+
)}`;
|
|
1328
|
+
}
|
|
1329
|
+
const page2 = document.createElement("html");
|
|
1330
|
+
page2.innerHTML = html;
|
|
1331
|
+
page2.querySelectorAll("a").forEach((a) => a.setAttribute("target", "_top"));
|
|
1332
|
+
this.modal = document.createElement("div");
|
|
1333
|
+
this.modal.style.position = "fixed";
|
|
1334
|
+
this.modal.style.width = "100vw";
|
|
1335
|
+
this.modal.style.height = "100vh";
|
|
1336
|
+
this.modal.style.padding = "50px";
|
|
1337
|
+
this.modal.style.boxSizing = "border-box";
|
|
1338
|
+
this.modal.style.backgroundColor = "rgba(0, 0, 0, .6)";
|
|
1339
|
+
this.modal.style.zIndex = 2e5;
|
|
1340
|
+
this.modal.addEventListener("click", () => this.hide());
|
|
1341
|
+
const iframe = document.createElement("iframe");
|
|
1342
|
+
iframe.style.backgroundColor = "white";
|
|
1343
|
+
iframe.style.borderRadius = "5px";
|
|
1344
|
+
iframe.style.width = "100%";
|
|
1345
|
+
iframe.style.height = "100%";
|
|
1346
|
+
this.modal.appendChild(iframe);
|
|
1347
|
+
document.body.prepend(this.modal);
|
|
1348
|
+
document.body.style.overflow = "hidden";
|
|
1349
|
+
if (!iframe.contentWindow) {
|
|
1350
|
+
throw new Error("iframe not yet ready.");
|
|
1351
|
+
}
|
|
1352
|
+
iframe.contentWindow.document.open();
|
|
1353
|
+
iframe.contentWindow.document.write(page2.outerHTML);
|
|
1354
|
+
iframe.contentWindow.document.close();
|
|
1355
|
+
this.listener = this.hideOnEscape.bind(this);
|
|
1356
|
+
document.addEventListener("keydown", this.listener);
|
|
1357
|
+
},
|
|
1358
|
+
hide() {
|
|
1359
|
+
this.modal.outerHTML = "";
|
|
1360
|
+
this.modal = null;
|
|
1361
|
+
document.body.style.overflow = "visible";
|
|
1362
|
+
document.removeEventListener("keydown", this.listener);
|
|
1363
|
+
},
|
|
1364
|
+
hideOnEscape(event) {
|
|
1365
|
+
if (event.keyCode === 27) {
|
|
1366
|
+
this.hide();
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
// src/response.ts
|
|
1372
|
+
var queue2 = new Queue();
|
|
1373
|
+
var Response = class _Response {
|
|
1374
|
+
constructor(requestParams, response, originatingPage) {
|
|
1375
|
+
this.requestParams = requestParams;
|
|
1376
|
+
this.response = response;
|
|
1377
|
+
this.originatingPage = originatingPage;
|
|
1378
|
+
}
|
|
1379
|
+
static create(params, response, originatingPage) {
|
|
1380
|
+
return new _Response(params, response, originatingPage);
|
|
1381
|
+
}
|
|
1382
|
+
async handlePrefetch() {
|
|
1383
|
+
if (isSameUrlWithoutHash(this.requestParams.all().url, window.location)) {
|
|
1384
|
+
this.handle();
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
async handle() {
|
|
1388
|
+
return queue2.add(() => this.process());
|
|
1389
|
+
}
|
|
1390
|
+
async process() {
|
|
1391
|
+
if (this.requestParams.all().prefetch) {
|
|
1392
|
+
this.requestParams.all().prefetch = false;
|
|
1393
|
+
this.requestParams.all().onPrefetched(this.response, this.requestParams.all());
|
|
1394
|
+
firePrefetchedEvent(this.response, this.requestParams.all());
|
|
1395
|
+
return Promise.resolve();
|
|
1396
|
+
}
|
|
1397
|
+
this.requestParams.runCallbacks();
|
|
1398
|
+
if (!this.isInertiaResponse()) {
|
|
1399
|
+
return this.handleNonInertiaResponse();
|
|
1400
|
+
}
|
|
1401
|
+
await history.processQueue();
|
|
1402
|
+
history.preserveUrl = this.requestParams.all().preserveUrl;
|
|
1403
|
+
await this.setPage();
|
|
1404
|
+
const errors = page.get().props.errors || {};
|
|
1405
|
+
if (Object.keys(errors).length > 0) {
|
|
1406
|
+
const scopedErrors = this.getScopedErrors(errors);
|
|
1407
|
+
fireErrorEvent(scopedErrors);
|
|
1408
|
+
return this.requestParams.all().onError(scopedErrors);
|
|
1409
|
+
}
|
|
1410
|
+
fireSuccessEvent(page.get());
|
|
1411
|
+
await this.requestParams.all().onSuccess(page.get());
|
|
1412
|
+
history.preserveUrl = false;
|
|
1413
|
+
}
|
|
1414
|
+
mergeParams(params) {
|
|
1415
|
+
this.requestParams.merge(params);
|
|
1416
|
+
}
|
|
1417
|
+
async handleNonInertiaResponse() {
|
|
1418
|
+
if (this.isLocationVisit()) {
|
|
1419
|
+
const locationUrl = hrefToUrl(this.getHeader("x-inertia-location"));
|
|
1420
|
+
setHashIfSameUrl(this.requestParams.all().url, locationUrl);
|
|
1421
|
+
return this.locationVisit(locationUrl);
|
|
1422
|
+
}
|
|
1423
|
+
const response = {
|
|
1424
|
+
...this.response,
|
|
1425
|
+
data: this.getDataFromResponse(this.response.data)
|
|
1426
|
+
};
|
|
1427
|
+
if (fireInvalidEvent(response)) {
|
|
1428
|
+
return modal_default.show(response.data);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
isInertiaResponse() {
|
|
1432
|
+
return this.hasHeader("x-inertia");
|
|
1433
|
+
}
|
|
1434
|
+
hasStatus(status2) {
|
|
1435
|
+
return this.response.status === status2;
|
|
1436
|
+
}
|
|
1437
|
+
getHeader(header) {
|
|
1438
|
+
return this.response.headers[header];
|
|
1439
|
+
}
|
|
1440
|
+
hasHeader(header) {
|
|
1441
|
+
return this.getHeader(header) !== void 0;
|
|
1442
|
+
}
|
|
1443
|
+
isLocationVisit() {
|
|
1444
|
+
return this.hasStatus(409) && this.hasHeader("x-inertia-location");
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* @link https://inertiajs.com/redirects#external-redirects
|
|
1448
|
+
*/
|
|
1449
|
+
locationVisit(url) {
|
|
1450
|
+
try {
|
|
1451
|
+
SessionStorage.set(SessionStorage.locationVisitKey, {
|
|
1452
|
+
preserveScroll: this.requestParams.all().preserveScroll === true
|
|
1453
|
+
});
|
|
1454
|
+
if (typeof window === "undefined") {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
if (isSameUrlWithoutHash(window.location, url)) {
|
|
1458
|
+
window.location.reload();
|
|
1459
|
+
} else {
|
|
1460
|
+
window.location.href = url.href;
|
|
1461
|
+
}
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
async setPage() {
|
|
1467
|
+
const pageResponse = this.getDataFromResponse(this.response.data);
|
|
1468
|
+
if (!this.shouldSetPage(pageResponse)) {
|
|
1469
|
+
return Promise.resolve();
|
|
1470
|
+
}
|
|
1471
|
+
this.mergeProps(pageResponse);
|
|
1472
|
+
await this.setRememberedState(pageResponse);
|
|
1473
|
+
this.requestParams.setPreserveOptions(pageResponse);
|
|
1474
|
+
pageResponse.url = history.preserveUrl ? page.get().url : this.pageUrl(pageResponse);
|
|
1475
|
+
return page.set(pageResponse, {
|
|
1476
|
+
replace: this.requestParams.all().replace,
|
|
1477
|
+
preserveScroll: this.requestParams.all().preserveScroll,
|
|
1478
|
+
preserveState: this.requestParams.all().preserveState
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
getDataFromResponse(response) {
|
|
1482
|
+
if (typeof response !== "string") {
|
|
1483
|
+
return response;
|
|
1484
|
+
}
|
|
1485
|
+
try {
|
|
1486
|
+
return JSON.parse(response);
|
|
1487
|
+
} catch (error) {
|
|
1488
|
+
return response;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
shouldSetPage(pageResponse) {
|
|
1492
|
+
if (!this.requestParams.all().async) {
|
|
1493
|
+
return true;
|
|
1494
|
+
}
|
|
1495
|
+
if (this.originatingPage.component !== pageResponse.component) {
|
|
1496
|
+
return true;
|
|
1497
|
+
}
|
|
1498
|
+
if (this.originatingPage.component !== page.get().component) {
|
|
1499
|
+
return false;
|
|
1500
|
+
}
|
|
1501
|
+
const originatingUrl = hrefToUrl(this.originatingPage.url);
|
|
1502
|
+
const currentPageUrl = hrefToUrl(page.get().url);
|
|
1503
|
+
return originatingUrl.origin === currentPageUrl.origin && originatingUrl.pathname === currentPageUrl.pathname;
|
|
1504
|
+
}
|
|
1505
|
+
pageUrl(pageResponse) {
|
|
1506
|
+
const responseUrl = hrefToUrl(pageResponse.url);
|
|
1507
|
+
setHashIfSameUrl(this.requestParams.all().url, responseUrl);
|
|
1508
|
+
return responseUrl.pathname + responseUrl.search + responseUrl.hash;
|
|
1509
|
+
}
|
|
1510
|
+
mergeProps(pageResponse) {
|
|
1511
|
+
if (!this.requestParams.isPartial() || pageResponse.component !== page.get().component) {
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
const propsToMerge = pageResponse.mergeProps || [];
|
|
1515
|
+
const propsToDeepMerge = pageResponse.deepMergeProps || [];
|
|
1516
|
+
const matchPropsOn = pageResponse.matchPropsOn || [];
|
|
1517
|
+
propsToMerge.forEach((prop) => {
|
|
1518
|
+
const incomingProp = pageResponse.props[prop];
|
|
1519
|
+
if (Array.isArray(incomingProp)) {
|
|
1520
|
+
pageResponse.props[prop] = this.mergeOrMatchItems(
|
|
1521
|
+
page.get().props[prop] || [],
|
|
1522
|
+
incomingProp,
|
|
1523
|
+
prop,
|
|
1524
|
+
matchPropsOn
|
|
1525
|
+
);
|
|
1526
|
+
} else if (typeof incomingProp === "object" && incomingProp !== null) {
|
|
1527
|
+
pageResponse.props[prop] = {
|
|
1528
|
+
...page.get().props[prop] || [],
|
|
1529
|
+
...incomingProp
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
propsToDeepMerge.forEach((prop) => {
|
|
1534
|
+
const incomingProp = pageResponse.props[prop];
|
|
1535
|
+
const currentProp = page.get().props[prop];
|
|
1536
|
+
const deepMerge = (target, source, currentKey) => {
|
|
1537
|
+
if (Array.isArray(source)) {
|
|
1538
|
+
return this.mergeOrMatchItems(target, source, currentKey, matchPropsOn);
|
|
1539
|
+
}
|
|
1540
|
+
if (typeof source === "object" && source !== null) {
|
|
1541
|
+
return Object.keys(source).reduce(
|
|
1542
|
+
(acc, key) => {
|
|
1543
|
+
acc[key] = deepMerge(target ? target[key] : void 0, source[key], `${currentKey}.${key}`);
|
|
1544
|
+
return acc;
|
|
1545
|
+
},
|
|
1546
|
+
{ ...target }
|
|
1547
|
+
);
|
|
1548
|
+
}
|
|
1549
|
+
return source;
|
|
1550
|
+
};
|
|
1551
|
+
pageResponse.props[prop] = deepMerge(currentProp, incomingProp, prop);
|
|
1552
|
+
});
|
|
1553
|
+
pageResponse.props = { ...page.get().props, ...pageResponse.props };
|
|
1554
|
+
}
|
|
1555
|
+
mergeOrMatchItems(target, source, currentKey, matchPropsOn) {
|
|
1556
|
+
const matchOn = matchPropsOn.find((key) => {
|
|
1557
|
+
const path = key.split(".").slice(0, -1).join(".");
|
|
1558
|
+
return path === currentKey;
|
|
1559
|
+
});
|
|
1560
|
+
if (!matchOn) {
|
|
1561
|
+
return [...Array.isArray(target) ? target : [], ...source];
|
|
1562
|
+
}
|
|
1563
|
+
const uniqueProperty = matchOn.split(".").pop() || "";
|
|
1564
|
+
const targetArray = Array.isArray(target) ? target : [];
|
|
1565
|
+
const map = /* @__PURE__ */ new Map();
|
|
1566
|
+
targetArray.forEach((item) => {
|
|
1567
|
+
if (item && typeof item === "object" && uniqueProperty in item) {
|
|
1568
|
+
map.set(item[uniqueProperty], item);
|
|
1569
|
+
} else {
|
|
1570
|
+
map.set(Symbol(), item);
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
source.forEach((item) => {
|
|
1574
|
+
if (item && typeof item === "object" && uniqueProperty in item) {
|
|
1575
|
+
map.set(item[uniqueProperty], item);
|
|
1576
|
+
} else {
|
|
1577
|
+
map.set(Symbol(), item);
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
return Array.from(map.values());
|
|
1581
|
+
}
|
|
1582
|
+
async setRememberedState(pageResponse) {
|
|
1583
|
+
const rememberedState = await history.getState(history.rememberedState, {});
|
|
1584
|
+
if (this.requestParams.all().preserveState && rememberedState && pageResponse.component === page.get().component) {
|
|
1585
|
+
pageResponse.rememberedState = rememberedState;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
getScopedErrors(errors) {
|
|
1589
|
+
if (!this.requestParams.all().errorBag) {
|
|
1590
|
+
return errors;
|
|
1591
|
+
}
|
|
1592
|
+
return errors[this.requestParams.all().errorBag || ""] || {};
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
// src/request.ts
|
|
1597
|
+
var Request = class _Request {
|
|
1598
|
+
constructor(params, page2) {
|
|
1599
|
+
this.page = page2;
|
|
1600
|
+
this.requestHasFinished = false;
|
|
1601
|
+
this.requestParams = RequestParams.create(params);
|
|
1602
|
+
this.cancelToken = new AbortController();
|
|
1603
|
+
}
|
|
1604
|
+
static create(params, page2) {
|
|
1605
|
+
return new _Request(params, page2);
|
|
1606
|
+
}
|
|
1607
|
+
async send() {
|
|
1608
|
+
this.requestParams.onCancelToken(() => this.cancel({ cancelled: true }));
|
|
1609
|
+
fireStartEvent(this.requestParams.all());
|
|
1610
|
+
this.requestParams.onStart();
|
|
1611
|
+
if (this.requestParams.all().prefetch) {
|
|
1612
|
+
this.requestParams.onPrefetching();
|
|
1613
|
+
firePrefetchingEvent(this.requestParams.all());
|
|
1614
|
+
}
|
|
1615
|
+
const originallyPrefetch = this.requestParams.all().prefetch;
|
|
1616
|
+
return axios({
|
|
1617
|
+
method: this.requestParams.all().method,
|
|
1618
|
+
url: urlWithoutHash(this.requestParams.all().url).href,
|
|
1619
|
+
data: this.requestParams.data(),
|
|
1620
|
+
params: this.requestParams.queryParams(),
|
|
1621
|
+
signal: this.cancelToken.signal,
|
|
1622
|
+
headers: this.getHeaders(),
|
|
1623
|
+
onUploadProgress: this.onProgress.bind(this),
|
|
1624
|
+
// Why text? This allows us to delay JSON.parse until we're ready to use the response,
|
|
1625
|
+
// helps with performance particularly on large responses + history encryption
|
|
1626
|
+
responseType: "text"
|
|
1627
|
+
}).then((response) => {
|
|
1628
|
+
this.response = Response.create(this.requestParams, response, this.page);
|
|
1629
|
+
return this.response.handle();
|
|
1630
|
+
}).catch((error) => {
|
|
1631
|
+
if (error?.response) {
|
|
1632
|
+
this.response = Response.create(this.requestParams, error.response, this.page);
|
|
1633
|
+
return this.response.handle();
|
|
1634
|
+
}
|
|
1635
|
+
return Promise.reject(error);
|
|
1636
|
+
}).catch((error) => {
|
|
1637
|
+
if (axios.isCancel(error)) {
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
if (fireExceptionEvent(error)) {
|
|
1641
|
+
return Promise.reject(error);
|
|
1642
|
+
}
|
|
1643
|
+
}).finally(() => {
|
|
1644
|
+
this.finish();
|
|
1645
|
+
if (originallyPrefetch && this.response) {
|
|
1646
|
+
this.requestParams.onPrefetchResponse(this.response);
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
finish() {
|
|
1651
|
+
if (this.requestParams.wasCancelledAtAll()) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
this.requestParams.markAsFinished();
|
|
1655
|
+
this.fireFinishEvents();
|
|
1656
|
+
}
|
|
1657
|
+
fireFinishEvents() {
|
|
1658
|
+
if (this.requestHasFinished) {
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
this.requestHasFinished = true;
|
|
1662
|
+
fireFinishEvent(this.requestParams.all());
|
|
1663
|
+
this.requestParams.onFinish();
|
|
1664
|
+
}
|
|
1665
|
+
cancel({ cancelled = false, interrupted = false }) {
|
|
1666
|
+
if (this.requestHasFinished) {
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
this.cancelToken.abort();
|
|
1670
|
+
this.requestParams.markAsCancelled({ cancelled, interrupted });
|
|
1671
|
+
this.fireFinishEvents();
|
|
1672
|
+
}
|
|
1673
|
+
onProgress(progress3) {
|
|
1674
|
+
if (this.requestParams.data() instanceof FormData) {
|
|
1675
|
+
progress3.percentage = progress3.progress ? Math.round(progress3.progress * 100) : 0;
|
|
1676
|
+
fireProgressEvent(progress3);
|
|
1677
|
+
this.requestParams.all().onProgress(progress3);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
getHeaders() {
|
|
1681
|
+
const headers = {
|
|
1682
|
+
...this.requestParams.headers(),
|
|
1683
|
+
Accept: "text/html, application/xhtml+xml",
|
|
1684
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
1685
|
+
"X-Inertia": true
|
|
1686
|
+
};
|
|
1687
|
+
if (page.get().version) {
|
|
1688
|
+
headers["X-Inertia-Version"] = page.get().version;
|
|
1689
|
+
}
|
|
1690
|
+
return headers;
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
// src/requestStream.ts
|
|
1695
|
+
var RequestStream = class {
|
|
1696
|
+
constructor({ maxConcurrent, interruptible }) {
|
|
1697
|
+
this.requests = [];
|
|
1698
|
+
this.maxConcurrent = maxConcurrent;
|
|
1699
|
+
this.interruptible = interruptible;
|
|
1700
|
+
}
|
|
1701
|
+
send(request) {
|
|
1702
|
+
this.requests.push(request);
|
|
1703
|
+
request.send().then(() => {
|
|
1704
|
+
this.requests = this.requests.filter((r) => r !== request);
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
interruptInFlight() {
|
|
1708
|
+
this.cancel({ interrupted: true }, false);
|
|
1709
|
+
}
|
|
1710
|
+
cancelInFlight() {
|
|
1711
|
+
this.cancel({ cancelled: true }, true);
|
|
1712
|
+
}
|
|
1713
|
+
cancel({ cancelled = false, interrupted = false } = {}, force) {
|
|
1714
|
+
if (!this.shouldCancel(force)) {
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const request = this.requests.shift();
|
|
1718
|
+
request?.cancel({ interrupted, cancelled });
|
|
1719
|
+
}
|
|
1720
|
+
shouldCancel(force) {
|
|
1721
|
+
if (force) {
|
|
1722
|
+
return true;
|
|
1723
|
+
}
|
|
1724
|
+
return this.interruptible && this.requests.length >= this.maxConcurrent;
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
// src/router.ts
|
|
1729
|
+
var Router = class {
|
|
1730
|
+
constructor() {
|
|
1731
|
+
this.syncRequestStream = new RequestStream({
|
|
1732
|
+
maxConcurrent: 1,
|
|
1733
|
+
interruptible: true
|
|
1734
|
+
});
|
|
1735
|
+
this.asyncRequestStream = new RequestStream({
|
|
1736
|
+
maxConcurrent: Infinity,
|
|
1737
|
+
interruptible: false
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
init({ initialPage, resolveComponent, swapComponent }) {
|
|
1741
|
+
page.init({
|
|
1742
|
+
initialPage,
|
|
1743
|
+
resolveComponent,
|
|
1744
|
+
swapComponent
|
|
1745
|
+
});
|
|
1746
|
+
InitialVisit.handle();
|
|
1747
|
+
eventHandler.init();
|
|
1748
|
+
eventHandler.on("missingHistoryItem", () => {
|
|
1749
|
+
if (typeof window !== "undefined") {
|
|
1750
|
+
this.visit(window.location.href, { preserveState: true, preserveScroll: true, replace: true });
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
eventHandler.on("loadDeferredProps", () => {
|
|
1754
|
+
this.loadDeferredProps();
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
get(url, data = {}, options = {}) {
|
|
1758
|
+
return this.visit(url, { ...options, method: "get", data });
|
|
1759
|
+
}
|
|
1760
|
+
post(url, data = {}, options = {}) {
|
|
1761
|
+
return this.visit(url, { preserveState: true, ...options, method: "post", data });
|
|
1762
|
+
}
|
|
1763
|
+
put(url, data = {}, options = {}) {
|
|
1764
|
+
return this.visit(url, { preserveState: true, ...options, method: "put", data });
|
|
1765
|
+
}
|
|
1766
|
+
patch(url, data = {}, options = {}) {
|
|
1767
|
+
return this.visit(url, { preserveState: true, ...options, method: "patch", data });
|
|
1768
|
+
}
|
|
1769
|
+
delete(url, options = {}) {
|
|
1770
|
+
return this.visit(url, { preserveState: true, ...options, method: "delete" });
|
|
1771
|
+
}
|
|
1772
|
+
reload(options = {}) {
|
|
1773
|
+
if (typeof window === "undefined") {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
return this.visit(window.location.href, {
|
|
1777
|
+
...options,
|
|
1778
|
+
preserveScroll: true,
|
|
1779
|
+
preserveState: true,
|
|
1780
|
+
async: true,
|
|
1781
|
+
headers: {
|
|
1782
|
+
...options.headers || {},
|
|
1783
|
+
"Cache-Control": "no-cache"
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
remember(data, key = "default") {
|
|
1788
|
+
history.remember(data, key);
|
|
1789
|
+
}
|
|
1790
|
+
restore(key = "default") {
|
|
1791
|
+
return history.restore(key);
|
|
1792
|
+
}
|
|
1793
|
+
on(type, callback) {
|
|
1794
|
+
if (typeof window === "undefined") {
|
|
1795
|
+
return () => {
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
return eventHandler.onGlobalEvent(type, callback);
|
|
1799
|
+
}
|
|
1800
|
+
cancel() {
|
|
1801
|
+
this.syncRequestStream.cancelInFlight();
|
|
1802
|
+
}
|
|
1803
|
+
cancelAll() {
|
|
1804
|
+
this.asyncRequestStream.cancelInFlight();
|
|
1805
|
+
this.syncRequestStream.cancelInFlight();
|
|
1806
|
+
}
|
|
1807
|
+
poll(interval, requestOptions = {}, options = {}) {
|
|
1808
|
+
return polls.add(interval, () => this.reload(requestOptions), {
|
|
1809
|
+
autoStart: options.autoStart ?? true,
|
|
1810
|
+
keepAlive: options.keepAlive ?? false
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
visit(href, options = {}) {
|
|
1814
|
+
const visit = this.getPendingVisit(href, {
|
|
1815
|
+
...options,
|
|
1816
|
+
showProgress: options.showProgress ?? !options.async
|
|
1817
|
+
});
|
|
1818
|
+
const events = this.getVisitEvents(options);
|
|
1819
|
+
if (events.onBefore(visit) === false || !fireBeforeEvent(visit)) {
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1822
|
+
const requestStream = visit.async ? this.asyncRequestStream : this.syncRequestStream;
|
|
1823
|
+
requestStream.interruptInFlight();
|
|
1824
|
+
if (!page.isCleared() && !visit.preserveUrl) {
|
|
1825
|
+
Scroll.save();
|
|
1826
|
+
}
|
|
1827
|
+
const requestParams = {
|
|
1828
|
+
...visit,
|
|
1829
|
+
...events
|
|
1830
|
+
};
|
|
1831
|
+
const prefetched = prefetchedRequests.get(requestParams);
|
|
1832
|
+
if (prefetched) {
|
|
1833
|
+
reveal(prefetched.inFlight);
|
|
1834
|
+
prefetchedRequests.use(prefetched, requestParams);
|
|
1835
|
+
} else {
|
|
1836
|
+
reveal(true);
|
|
1837
|
+
requestStream.send(Request.create(requestParams, page.get()));
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
getCached(href, options = {}) {
|
|
1841
|
+
return prefetchedRequests.findCached(this.getPrefetchParams(href, options));
|
|
1842
|
+
}
|
|
1843
|
+
flush(href, options = {}) {
|
|
1844
|
+
prefetchedRequests.remove(this.getPrefetchParams(href, options));
|
|
1845
|
+
}
|
|
1846
|
+
flushAll() {
|
|
1847
|
+
prefetchedRequests.removeAll();
|
|
1848
|
+
}
|
|
1849
|
+
getPrefetching(href, options = {}) {
|
|
1850
|
+
return prefetchedRequests.findInFlight(this.getPrefetchParams(href, options));
|
|
1851
|
+
}
|
|
1852
|
+
prefetch(href, options = {}, { cacheFor = 3e4 }) {
|
|
1853
|
+
if (options.method !== "get") {
|
|
1854
|
+
throw new Error("Prefetch requests must use the GET method");
|
|
1855
|
+
}
|
|
1856
|
+
const visit = this.getPendingVisit(href, {
|
|
1857
|
+
...options,
|
|
1858
|
+
async: true,
|
|
1859
|
+
showProgress: false,
|
|
1860
|
+
prefetch: true
|
|
1861
|
+
});
|
|
1862
|
+
const visitUrl = visit.url.origin + visit.url.pathname + visit.url.search;
|
|
1863
|
+
const currentUrl = window.location.origin + window.location.pathname + window.location.search;
|
|
1864
|
+
if (visitUrl === currentUrl) {
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
const events = this.getVisitEvents(options);
|
|
1868
|
+
if (events.onBefore(visit) === false || !fireBeforeEvent(visit)) {
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
hide();
|
|
1872
|
+
this.asyncRequestStream.interruptInFlight();
|
|
1873
|
+
const requestParams = {
|
|
1874
|
+
...visit,
|
|
1875
|
+
...events
|
|
1876
|
+
};
|
|
1877
|
+
const ensureCurrentPageIsSet = () => {
|
|
1878
|
+
return new Promise((resolve) => {
|
|
1879
|
+
const checkIfPageIsDefined = () => {
|
|
1880
|
+
if (page.get()) {
|
|
1881
|
+
resolve();
|
|
1882
|
+
} else {
|
|
1883
|
+
setTimeout(checkIfPageIsDefined, 50);
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
checkIfPageIsDefined();
|
|
1887
|
+
});
|
|
1888
|
+
};
|
|
1889
|
+
ensureCurrentPageIsSet().then(() => {
|
|
1890
|
+
prefetchedRequests.add(
|
|
1891
|
+
requestParams,
|
|
1892
|
+
(params) => {
|
|
1893
|
+
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
1894
|
+
},
|
|
1895
|
+
{ cacheFor }
|
|
1896
|
+
);
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
clearHistory() {
|
|
1900
|
+
history.clear();
|
|
1901
|
+
}
|
|
1902
|
+
decryptHistory() {
|
|
1903
|
+
return history.decrypt();
|
|
1904
|
+
}
|
|
1905
|
+
resolveComponent(component) {
|
|
1906
|
+
return page.resolve(component);
|
|
1907
|
+
}
|
|
1908
|
+
replace(params) {
|
|
1909
|
+
this.clientVisit(params, { replace: true });
|
|
1910
|
+
}
|
|
1911
|
+
push(params) {
|
|
1912
|
+
this.clientVisit(params);
|
|
1913
|
+
}
|
|
1914
|
+
clientVisit(params, { replace = false } = {}) {
|
|
1915
|
+
const current = page.get();
|
|
1916
|
+
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
1917
|
+
const { onError, onFinish, onSuccess, ...pageParams } = params;
|
|
1918
|
+
page.set(
|
|
1919
|
+
{
|
|
1920
|
+
...current,
|
|
1921
|
+
...pageParams,
|
|
1922
|
+
props
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
replace,
|
|
1926
|
+
preserveScroll: params.preserveScroll,
|
|
1927
|
+
preserveState: params.preserveState
|
|
1928
|
+
}
|
|
1929
|
+
).then(() => {
|
|
1930
|
+
const errors = page.get().props.errors || {};
|
|
1931
|
+
if (Object.keys(errors).length === 0) {
|
|
1932
|
+
return onSuccess?.(page.get());
|
|
1933
|
+
}
|
|
1934
|
+
const scopedErrors = params.errorBag ? errors[params.errorBag || ""] || {} : errors;
|
|
1935
|
+
return onError?.(scopedErrors);
|
|
1936
|
+
}).finally(() => onFinish?.(params));
|
|
1937
|
+
}
|
|
1938
|
+
getPrefetchParams(href, options) {
|
|
1939
|
+
return {
|
|
1940
|
+
...this.getPendingVisit(href, {
|
|
1941
|
+
...options,
|
|
1942
|
+
async: true,
|
|
1943
|
+
showProgress: false,
|
|
1944
|
+
prefetch: true
|
|
1945
|
+
}),
|
|
1946
|
+
...this.getVisitEvents(options)
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
getPendingVisit(href, options, pendingVisitOptions = {}) {
|
|
1950
|
+
const mergedOptions = {
|
|
1951
|
+
method: "get",
|
|
1952
|
+
data: {},
|
|
1953
|
+
replace: false,
|
|
1954
|
+
preserveScroll: false,
|
|
1955
|
+
preserveState: false,
|
|
1956
|
+
only: [],
|
|
1957
|
+
except: [],
|
|
1958
|
+
headers: {},
|
|
1959
|
+
errorBag: "",
|
|
1960
|
+
forceFormData: false,
|
|
1961
|
+
queryStringArrayFormat: "brackets",
|
|
1962
|
+
async: false,
|
|
1963
|
+
showProgress: true,
|
|
1964
|
+
fresh: false,
|
|
1965
|
+
reset: [],
|
|
1966
|
+
preserveUrl: false,
|
|
1967
|
+
prefetch: false,
|
|
1968
|
+
...options
|
|
1969
|
+
};
|
|
1970
|
+
const [url, _data] = transformUrlAndData(
|
|
1971
|
+
href,
|
|
1972
|
+
mergedOptions.data,
|
|
1973
|
+
mergedOptions.method,
|
|
1974
|
+
mergedOptions.forceFormData,
|
|
1975
|
+
mergedOptions.queryStringArrayFormat
|
|
1976
|
+
);
|
|
1977
|
+
const visit = {
|
|
1978
|
+
cancelled: false,
|
|
1979
|
+
completed: false,
|
|
1980
|
+
interrupted: false,
|
|
1981
|
+
...mergedOptions,
|
|
1982
|
+
...pendingVisitOptions,
|
|
1983
|
+
url,
|
|
1984
|
+
data: _data
|
|
1985
|
+
};
|
|
1986
|
+
if (visit.prefetch) {
|
|
1987
|
+
visit.headers["Purpose"] = "prefetch";
|
|
1988
|
+
}
|
|
1989
|
+
return visit;
|
|
1990
|
+
}
|
|
1991
|
+
getVisitEvents(options) {
|
|
1992
|
+
return {
|
|
1993
|
+
onCancelToken: options.onCancelToken || (() => {
|
|
1994
|
+
}),
|
|
1995
|
+
onBefore: options.onBefore || (() => {
|
|
1996
|
+
}),
|
|
1997
|
+
onStart: options.onStart || (() => {
|
|
1998
|
+
}),
|
|
1999
|
+
onProgress: options.onProgress || (() => {
|
|
2000
|
+
}),
|
|
2001
|
+
onFinish: options.onFinish || (() => {
|
|
2002
|
+
}),
|
|
2003
|
+
onCancel: options.onCancel || (() => {
|
|
2004
|
+
}),
|
|
2005
|
+
onSuccess: options.onSuccess || (() => {
|
|
2006
|
+
}),
|
|
2007
|
+
onError: options.onError || (() => {
|
|
2008
|
+
}),
|
|
2009
|
+
onPrefetched: options.onPrefetched || (() => {
|
|
2010
|
+
}),
|
|
2011
|
+
onPrefetching: options.onPrefetching || (() => {
|
|
2012
|
+
})
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
loadDeferredProps() {
|
|
2016
|
+
const deferred = page.get()?.deferredProps;
|
|
2017
|
+
if (deferred) {
|
|
2018
|
+
Object.entries(deferred).forEach(([_, group]) => {
|
|
2019
|
+
this.reload({ only: group });
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
|
|
2025
|
+
// src/head.ts
|
|
2026
|
+
var Renderer = {
|
|
2027
|
+
buildDOMElement(tag) {
|
|
2028
|
+
const template = document.createElement("template");
|
|
2029
|
+
template.innerHTML = tag;
|
|
2030
|
+
const node = template.content.firstChild;
|
|
2031
|
+
if (!tag.startsWith("<script ")) {
|
|
2032
|
+
return node;
|
|
2033
|
+
}
|
|
2034
|
+
const script = document.createElement("script");
|
|
2035
|
+
script.innerHTML = node.innerHTML;
|
|
2036
|
+
node.getAttributeNames().forEach((name) => {
|
|
2037
|
+
script.setAttribute(name, node.getAttribute(name) || "");
|
|
2038
|
+
});
|
|
2039
|
+
return script;
|
|
2040
|
+
},
|
|
2041
|
+
isInertiaManagedElement(element) {
|
|
2042
|
+
return element.nodeType === Node.ELEMENT_NODE && element.getAttribute("inertia") !== null;
|
|
2043
|
+
},
|
|
2044
|
+
findMatchingElementIndex(element, elements) {
|
|
2045
|
+
const key = element.getAttribute("inertia");
|
|
2046
|
+
if (key !== null) {
|
|
2047
|
+
return elements.findIndex((element2) => element2.getAttribute("inertia") === key);
|
|
2048
|
+
}
|
|
2049
|
+
return -1;
|
|
2050
|
+
},
|
|
2051
|
+
update: debounce(function(elements) {
|
|
2052
|
+
const sourceElements = elements.map((element) => this.buildDOMElement(element));
|
|
2053
|
+
const targetElements = Array.from(document.head.childNodes).filter(
|
|
2054
|
+
(element) => this.isInertiaManagedElement(element)
|
|
2055
|
+
);
|
|
2056
|
+
targetElements.forEach((targetElement) => {
|
|
2057
|
+
const index = this.findMatchingElementIndex(targetElement, sourceElements);
|
|
2058
|
+
if (index === -1) {
|
|
2059
|
+
targetElement?.parentNode?.removeChild(targetElement);
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
const sourceElement = sourceElements.splice(index, 1)[0];
|
|
2063
|
+
if (sourceElement && !targetElement.isEqualNode(sourceElement)) {
|
|
2064
|
+
targetElement?.parentNode?.replaceChild(sourceElement, targetElement);
|
|
2065
|
+
}
|
|
2066
|
+
});
|
|
2067
|
+
sourceElements.forEach((element) => document.head.appendChild(element));
|
|
2068
|
+
}, 1)
|
|
2069
|
+
};
|
|
2070
|
+
function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
2071
|
+
const states = {};
|
|
2072
|
+
let lastProviderId = 0;
|
|
2073
|
+
function connect() {
|
|
2074
|
+
const id = lastProviderId += 1;
|
|
2075
|
+
states[id] = [];
|
|
2076
|
+
return id.toString();
|
|
2077
|
+
}
|
|
2078
|
+
function disconnect(id) {
|
|
2079
|
+
if (id === null || Object.keys(states).indexOf(id) === -1) {
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
delete states[id];
|
|
2083
|
+
commit();
|
|
2084
|
+
}
|
|
2085
|
+
function reconnect(id) {
|
|
2086
|
+
if (Object.keys(states).indexOf(id) === -1) {
|
|
2087
|
+
states[id] = [];
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
function update(id, elements = []) {
|
|
2091
|
+
if (id !== null && Object.keys(states).indexOf(id) > -1) {
|
|
2092
|
+
states[id] = elements;
|
|
2093
|
+
}
|
|
2094
|
+
commit();
|
|
2095
|
+
}
|
|
2096
|
+
function collect() {
|
|
2097
|
+
const title = titleCallback("");
|
|
2098
|
+
const defaults = {
|
|
2099
|
+
...title ? { title: `<title inertia="">${title}</title>` } : {}
|
|
2100
|
+
};
|
|
2101
|
+
const elements = Object.values(states).reduce((carry, elements2) => carry.concat(elements2), []).reduce((carry, element) => {
|
|
2102
|
+
if (element.indexOf("<") === -1) {
|
|
2103
|
+
return carry;
|
|
2104
|
+
}
|
|
2105
|
+
if (element.indexOf("<title ") === 0) {
|
|
2106
|
+
const title2 = element.match(/(<title [^>]+>)(.*?)(<\/title>)/);
|
|
2107
|
+
carry.title = title2 ? `${title2[1]}${titleCallback(title2[2])}${title2[3]}` : element;
|
|
2108
|
+
return carry;
|
|
2109
|
+
}
|
|
2110
|
+
const match = element.match(/ inertia="[^"]+"/);
|
|
2111
|
+
if (match) {
|
|
2112
|
+
carry[match[0]] = element;
|
|
2113
|
+
} else {
|
|
2114
|
+
carry[Object.keys(carry).length] = element;
|
|
2115
|
+
}
|
|
2116
|
+
return carry;
|
|
2117
|
+
}, defaults);
|
|
2118
|
+
return Object.values(elements);
|
|
2119
|
+
}
|
|
2120
|
+
function commit() {
|
|
2121
|
+
isServer2 ? onUpdate(collect()) : Renderer.update(collect());
|
|
2122
|
+
}
|
|
2123
|
+
commit();
|
|
2124
|
+
return {
|
|
2125
|
+
forceUpdate: commit,
|
|
2126
|
+
createProvider: function() {
|
|
2127
|
+
const id = connect();
|
|
2128
|
+
return {
|
|
2129
|
+
reconnect: () => reconnect(id),
|
|
2130
|
+
update: (elements) => update(id, elements),
|
|
2131
|
+
disconnect: () => disconnect(id)
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
// src/progress-component.ts
|
|
2138
|
+
var baseComponentSelector = "nprogress";
|
|
2139
|
+
var progress;
|
|
2140
|
+
var settings = {
|
|
2141
|
+
minimum: 0.08,
|
|
2142
|
+
easing: "linear",
|
|
2143
|
+
positionUsing: "translate3d",
|
|
2144
|
+
speed: 200,
|
|
2145
|
+
trickle: true,
|
|
2146
|
+
trickleSpeed: 200,
|
|
2147
|
+
showSpinner: true,
|
|
2148
|
+
barSelector: '[role="bar"]',
|
|
2149
|
+
spinnerSelector: '[role="spinner"]',
|
|
2150
|
+
parent: "body",
|
|
2151
|
+
color: "#29d",
|
|
2152
|
+
includeCSS: true,
|
|
2153
|
+
template: [
|
|
2154
|
+
'<div class="bar" role="bar">',
|
|
2155
|
+
'<div class="peg"></div>',
|
|
2156
|
+
"</div>",
|
|
2157
|
+
'<div class="spinner" role="spinner">',
|
|
2158
|
+
'<div class="spinner-icon"></div>',
|
|
2159
|
+
"</div>"
|
|
2160
|
+
].join("")
|
|
2161
|
+
};
|
|
2162
|
+
var status = null;
|
|
2163
|
+
var configure = (options) => {
|
|
2164
|
+
Object.assign(settings, options);
|
|
2165
|
+
if (settings.includeCSS) {
|
|
2166
|
+
injectCSS(settings.color);
|
|
2167
|
+
}
|
|
2168
|
+
progress = document.createElement("div");
|
|
2169
|
+
progress.id = baseComponentSelector;
|
|
2170
|
+
progress.innerHTML = settings.template;
|
|
2171
|
+
};
|
|
2172
|
+
var set = (n) => {
|
|
2173
|
+
const started = isStarted();
|
|
2174
|
+
n = clamp(n, settings.minimum, 1);
|
|
2175
|
+
status = n === 1 ? null : n;
|
|
2176
|
+
const progress3 = render(!started);
|
|
2177
|
+
const bar = progress3.querySelector(settings.barSelector);
|
|
2178
|
+
const speed = settings.speed;
|
|
2179
|
+
const ease = settings.easing;
|
|
2180
|
+
progress3.offsetWidth;
|
|
2181
|
+
queue3((next) => {
|
|
2182
|
+
const barStyles = (() => {
|
|
2183
|
+
if (settings.positionUsing === "translate3d") {
|
|
2184
|
+
return {
|
|
2185
|
+
transition: `all ${speed}ms ${ease}`,
|
|
2186
|
+
transform: `translate3d(${toBarPercentage(n)}%,0,0)`
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
if (settings.positionUsing === "translate") {
|
|
2190
|
+
return {
|
|
2191
|
+
transition: `all ${speed}ms ${ease}`,
|
|
2192
|
+
transform: `translate(${toBarPercentage(n)}%,0)`
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
return { marginLeft: `${toBarPercentage(n)}%` };
|
|
2196
|
+
})();
|
|
2197
|
+
for (const key in barStyles) {
|
|
2198
|
+
bar.style[key] = barStyles[key];
|
|
2199
|
+
}
|
|
2200
|
+
if (n !== 1) {
|
|
2201
|
+
return setTimeout(next, speed);
|
|
2202
|
+
}
|
|
2203
|
+
progress3.style.transition = "none";
|
|
2204
|
+
progress3.style.opacity = "1";
|
|
2205
|
+
progress3.offsetWidth;
|
|
2206
|
+
setTimeout(() => {
|
|
2207
|
+
progress3.style.transition = `all ${speed}ms linear`;
|
|
2208
|
+
progress3.style.opacity = "0";
|
|
2209
|
+
setTimeout(() => {
|
|
2210
|
+
remove();
|
|
2211
|
+
progress3.style.transition = "";
|
|
2212
|
+
progress3.style.opacity = "";
|
|
2213
|
+
next();
|
|
2214
|
+
}, speed);
|
|
2215
|
+
}, speed);
|
|
2216
|
+
});
|
|
2217
|
+
};
|
|
2218
|
+
var isStarted = () => typeof status === "number";
|
|
2219
|
+
var start = () => {
|
|
2220
|
+
if (!status) {
|
|
2221
|
+
set(0);
|
|
2222
|
+
}
|
|
2223
|
+
const work = function() {
|
|
2224
|
+
setTimeout(function() {
|
|
2225
|
+
if (!status) {
|
|
2226
|
+
return;
|
|
2227
|
+
}
|
|
2228
|
+
increaseByRandom();
|
|
2229
|
+
work();
|
|
2230
|
+
}, settings.trickleSpeed);
|
|
2231
|
+
};
|
|
2232
|
+
if (settings.trickle) {
|
|
2233
|
+
work();
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
var done = (force) => {
|
|
2237
|
+
if (!force && !status) {
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
2241
|
+
set(1);
|
|
2242
|
+
};
|
|
2243
|
+
var increaseByRandom = (amount) => {
|
|
2244
|
+
const n = status;
|
|
2245
|
+
if (n === null) {
|
|
2246
|
+
return start();
|
|
2247
|
+
}
|
|
2248
|
+
if (n > 1) {
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
amount = typeof amount === "number" ? amount : (() => {
|
|
2252
|
+
const ranges = {
|
|
2253
|
+
0.1: [0, 0.2],
|
|
2254
|
+
0.04: [0.2, 0.5],
|
|
2255
|
+
0.02: [0.5, 0.8],
|
|
2256
|
+
5e-3: [0.8, 0.99]
|
|
2257
|
+
};
|
|
2258
|
+
for (const r in ranges) {
|
|
2259
|
+
if (n >= ranges[r][0] && n < ranges[r][1]) {
|
|
2260
|
+
return parseFloat(r);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
return 0;
|
|
2264
|
+
})();
|
|
2265
|
+
return set(clamp(n + amount, 0, 0.994));
|
|
2266
|
+
};
|
|
2267
|
+
var render = (fromStart) => {
|
|
2268
|
+
if (isRendered()) {
|
|
2269
|
+
return document.getElementById(baseComponentSelector);
|
|
2270
|
+
}
|
|
2271
|
+
document.documentElement.classList.add(`${baseComponentSelector}-busy`);
|
|
2272
|
+
const bar = progress.querySelector(settings.barSelector);
|
|
2273
|
+
const perc = fromStart ? "-100" : toBarPercentage(status || 0);
|
|
2274
|
+
const parent = getParent();
|
|
2275
|
+
bar.style.transition = "all 0 linear";
|
|
2276
|
+
bar.style.transform = `translate3d(${perc}%,0,0)`;
|
|
2277
|
+
if (!settings.showSpinner) {
|
|
2278
|
+
progress.querySelector(settings.spinnerSelector)?.remove();
|
|
2279
|
+
}
|
|
2280
|
+
if (parent !== document.body) {
|
|
2281
|
+
parent.classList.add(`${baseComponentSelector}-custom-parent`);
|
|
2282
|
+
}
|
|
2283
|
+
parent.appendChild(progress);
|
|
2284
|
+
return progress;
|
|
2285
|
+
};
|
|
2286
|
+
var getParent = () => {
|
|
2287
|
+
return isDOM(settings.parent) ? settings.parent : document.querySelector(settings.parent);
|
|
2288
|
+
};
|
|
2289
|
+
var remove = () => {
|
|
2290
|
+
document.documentElement.classList.remove(`${baseComponentSelector}-busy`);
|
|
2291
|
+
getParent().classList.remove(`${baseComponentSelector}-custom-parent`);
|
|
2292
|
+
progress?.remove();
|
|
2293
|
+
};
|
|
2294
|
+
var isRendered = () => {
|
|
2295
|
+
return document.getElementById(baseComponentSelector) !== null;
|
|
2296
|
+
};
|
|
2297
|
+
var isDOM = (obj) => {
|
|
2298
|
+
if (typeof HTMLElement === "object") {
|
|
2299
|
+
return obj instanceof HTMLElement;
|
|
2300
|
+
}
|
|
2301
|
+
return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
2302
|
+
};
|
|
2303
|
+
function clamp(n, min, max) {
|
|
2304
|
+
if (n < min) {
|
|
2305
|
+
return min;
|
|
2306
|
+
}
|
|
2307
|
+
if (n > max) {
|
|
2308
|
+
return max;
|
|
2309
|
+
}
|
|
2310
|
+
return n;
|
|
2311
|
+
}
|
|
2312
|
+
var toBarPercentage = (n) => (-1 + n) * 100;
|
|
2313
|
+
var queue3 = /* @__PURE__ */ (() => {
|
|
2314
|
+
const pending = [];
|
|
2315
|
+
const next = () => {
|
|
2316
|
+
const fn = pending.shift();
|
|
2317
|
+
if (fn) {
|
|
2318
|
+
fn(next);
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
return (fn) => {
|
|
2322
|
+
pending.push(fn);
|
|
2323
|
+
if (pending.length === 1) {
|
|
2324
|
+
next();
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
})();
|
|
2328
|
+
var injectCSS = (color) => {
|
|
2329
|
+
const element = document.createElement("style");
|
|
2330
|
+
element.textContent = `
|
|
2331
|
+
#${baseComponentSelector} {
|
|
3
2332
|
pointer-events: none;
|
|
4
2333
|
}
|
|
5
2334
|
|
|
6
|
-
#${
|
|
7
|
-
background: ${
|
|
2335
|
+
#${baseComponentSelector} .bar {
|
|
2336
|
+
background: ${color};
|
|
8
2337
|
|
|
9
2338
|
position: fixed;
|
|
10
2339
|
z-index: 1031;
|
|
@@ -15,19 +2344,19 @@ function I(r,e){let t;return function(...i){clearTimeout(t),t=setTimeout(()=>r.a
|
|
|
15
2344
|
height: 2px;
|
|
16
2345
|
}
|
|
17
2346
|
|
|
18
|
-
#${
|
|
2347
|
+
#${baseComponentSelector} .peg {
|
|
19
2348
|
display: block;
|
|
20
2349
|
position: absolute;
|
|
21
2350
|
right: 0px;
|
|
22
2351
|
width: 100px;
|
|
23
2352
|
height: 100%;
|
|
24
|
-
box-shadow: 0 0 10px ${
|
|
2353
|
+
box-shadow: 0 0 10px ${color}, 0 0 5px ${color};
|
|
25
2354
|
opacity: 1.0;
|
|
26
2355
|
|
|
27
2356
|
transform: rotate(3deg) translate(0px, -4px);
|
|
28
2357
|
}
|
|
29
2358
|
|
|
30
|
-
#${
|
|
2359
|
+
#${baseComponentSelector} .spinner {
|
|
31
2360
|
display: block;
|
|
32
2361
|
position: fixed;
|
|
33
2362
|
z-index: 1031;
|
|
@@ -35,34 +2364,129 @@ function I(r,e){let t;return function(...i){clearTimeout(t),t=setTimeout(()=>r.a
|
|
|
35
2364
|
right: 15px;
|
|
36
2365
|
}
|
|
37
2366
|
|
|
38
|
-
#${
|
|
2367
|
+
#${baseComponentSelector} .spinner-icon {
|
|
39
2368
|
width: 18px;
|
|
40
2369
|
height: 18px;
|
|
41
2370
|
box-sizing: border-box;
|
|
42
2371
|
|
|
43
2372
|
border: solid 2px transparent;
|
|
44
|
-
border-top-color: ${
|
|
45
|
-
border-left-color: ${
|
|
2373
|
+
border-top-color: ${color};
|
|
2374
|
+
border-left-color: ${color};
|
|
46
2375
|
border-radius: 50%;
|
|
47
2376
|
|
|
48
|
-
animation: ${
|
|
2377
|
+
animation: ${baseComponentSelector}-spinner 400ms linear infinite;
|
|
49
2378
|
}
|
|
50
2379
|
|
|
51
|
-
.${
|
|
2380
|
+
.${baseComponentSelector}-custom-parent {
|
|
52
2381
|
overflow: hidden;
|
|
53
2382
|
position: relative;
|
|
54
2383
|
}
|
|
55
2384
|
|
|
56
|
-
.${
|
|
57
|
-
.${
|
|
2385
|
+
.${baseComponentSelector}-custom-parent #${baseComponentSelector} .spinner,
|
|
2386
|
+
.${baseComponentSelector}-custom-parent #${baseComponentSelector} .bar {
|
|
58
2387
|
position: absolute;
|
|
59
2388
|
}
|
|
60
2389
|
|
|
61
|
-
@keyframes ${
|
|
2390
|
+
@keyframes ${baseComponentSelector}-spinner {
|
|
62
2391
|
0% { transform: rotate(0deg); }
|
|
63
2392
|
100% { transform: rotate(360deg); }
|
|
64
2393
|
}
|
|
65
|
-
|
|
2394
|
+
`;
|
|
2395
|
+
document.head.appendChild(element);
|
|
2396
|
+
};
|
|
2397
|
+
var show = () => {
|
|
2398
|
+
if (progress) {
|
|
2399
|
+
progress.style.display = "";
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
var hide2 = () => {
|
|
2403
|
+
if (progress) {
|
|
2404
|
+
progress.style.display = "none";
|
|
2405
|
+
}
|
|
2406
|
+
};
|
|
2407
|
+
var progress_component_default = {
|
|
2408
|
+
configure,
|
|
2409
|
+
isStarted,
|
|
2410
|
+
done,
|
|
2411
|
+
set,
|
|
2412
|
+
remove,
|
|
2413
|
+
start,
|
|
2414
|
+
status,
|
|
2415
|
+
show,
|
|
2416
|
+
hide: hide2
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
// src/progress.ts
|
|
2420
|
+
var hideCount = 0;
|
|
2421
|
+
var reveal = (force = false) => {
|
|
2422
|
+
hideCount = Math.max(0, hideCount - 1);
|
|
2423
|
+
if (force || hideCount === 0) {
|
|
2424
|
+
progress_component_default.show();
|
|
2425
|
+
}
|
|
2426
|
+
};
|
|
2427
|
+
var hide = () => {
|
|
2428
|
+
hideCount++;
|
|
2429
|
+
progress_component_default.hide();
|
|
2430
|
+
};
|
|
2431
|
+
function addEventListeners(delay) {
|
|
2432
|
+
document.addEventListener("inertia:start", (e) => start2(e, delay));
|
|
2433
|
+
document.addEventListener("inertia:progress", progress2);
|
|
2434
|
+
}
|
|
2435
|
+
function start2(event, delay) {
|
|
2436
|
+
if (!event.detail.visit.showProgress) {
|
|
2437
|
+
hide();
|
|
2438
|
+
}
|
|
2439
|
+
const timeout = setTimeout(() => progress_component_default.start(), delay);
|
|
2440
|
+
document.addEventListener("inertia:finish", (e) => finish(e, timeout), { once: true });
|
|
2441
|
+
}
|
|
2442
|
+
function progress2(event) {
|
|
2443
|
+
if (progress_component_default.isStarted() && event.detail.progress?.percentage) {
|
|
2444
|
+
progress_component_default.set(Math.max(progress_component_default.status, event.detail.progress.percentage / 100 * 0.9));
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
function finish(event, timeout) {
|
|
2448
|
+
clearTimeout(timeout);
|
|
2449
|
+
if (!progress_component_default.isStarted()) {
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
if (event.detail.visit.completed) {
|
|
2453
|
+
progress_component_default.done();
|
|
2454
|
+
} else if (event.detail.visit.interrupted) {
|
|
2455
|
+
progress_component_default.set(0);
|
|
2456
|
+
} else if (event.detail.visit.cancelled) {
|
|
2457
|
+
progress_component_default.done();
|
|
2458
|
+
progress_component_default.remove();
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
function setupProgress({
|
|
2462
|
+
delay = 250,
|
|
2463
|
+
color = "#29d",
|
|
2464
|
+
includeCSS = true,
|
|
2465
|
+
showSpinner = false
|
|
2466
|
+
} = {}) {
|
|
2467
|
+
addEventListeners(delay);
|
|
2468
|
+
progress_component_default.configure({ showSpinner, includeCSS, color });
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// src/shouldIntercept.ts
|
|
2472
|
+
function shouldIntercept(event) {
|
|
2473
|
+
const isLink = event.currentTarget.tagName.toLowerCase() === "a";
|
|
2474
|
+
return !(event.target && (event?.target).isContentEditable || event.defaultPrevented || isLink && event.altKey || isLink && event.ctrlKey || isLink && event.metaKey || isLink && event.shiftKey || isLink && "button" in event && event.button !== 0);
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
// src/index.ts
|
|
2478
|
+
var router = new Router();
|
|
2479
|
+
export {
|
|
2480
|
+
createHeadManager,
|
|
2481
|
+
hide as hideProgress,
|
|
2482
|
+
hrefToUrl,
|
|
2483
|
+
mergeDataIntoQueryString,
|
|
2484
|
+
reveal as revealProgress,
|
|
2485
|
+
router,
|
|
2486
|
+
setupProgress,
|
|
2487
|
+
shouldIntercept,
|
|
2488
|
+
urlWithoutHash
|
|
2489
|
+
};
|
|
66
2490
|
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
|
|
67
2491
|
* @license MIT */
|
|
68
2492
|
//# sourceMappingURL=index.esm.js.map
|