@ovineko/spa-guard-node 0.0.1-alpha-28 → 0.0.1-alpha-29

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.
@@ -1 +1 @@
1
- var e=Object.defineProperty,t="@ovineko/spa-guard",r="__SPA_GUARD_OPTIONS__",a=Symbol.for(t+":event-subscribers"),n=Symbol.for(t+":internal-config"),o=Symbol.for(t+":initialized"),l=Symbol.for(t+":logger"),i="spaGuardRetryId",s="spaGuardRetryAttempt",d="spaGuardCacheBust",c=(Symbol.for(t+":version-check-state"),Symbol.for(t+":reload-scheduled")),m=Symbol.for(t+":in-memory-last-reload"),u=Symbol.for(t+":static-asset-recovery");Symbol.for(t+":spinner-state"),globalThis.window&&!globalThis.window[a]&&(globalThis.window[a]=new Set),globalThis.window&&!globalThis.window[n]&&(globalThis.window[n]={defaultRetryEnabled:!0,initialized:!1});var y=globalThis.window?.[a]??new Set,g=globalThis.window?.[n]??{defaultRetryEnabled:!0,initialized:!1},p=()=>globalThis.window?.[l],h=(e,t)=>{t?.silent||p()?.logEvent(e),y.forEach(t=>{try{t(e)}catch{}})};function f(e,t){let r=e.querySelectorAll("[data-spa-guard-content]");for(let e of r){let r=e.dataset.spaGuardContent;if(r&&r in t){let a=t[r];"string"==typeof a&&(e.textContent=a)}}let a=e.querySelectorAll("[data-spa-guard-action]");for(let e of a){let r=e.dataset.spaGuardAction,a="try-again"===r?"tryAgain":r;if(a&&a in t){let r=t[a];"string"==typeof r&&(e.textContent=r)}}if(t.rtl)for(let t of e.children)t instanceof HTMLElement&&"STYLE"!==t.tagName&&(t.style.direction="rtl")}function w(){try{let e=document.querySelector('meta[name="spa-guard-i18n"]');if(!e)return null;let t=e.getAttribute("content");return t?JSON.parse(t):null}catch{return null}}((t,r)=>{for(var a in r)e(t,a,{get:r[a],enumerable:!0})})({},{getOptions:()=>v,optionsWindowKey:()=>r});var b={checkVersion:{cache:"no-store",interval:3e5,mode:"html",onUpdate:"reload"},enableRetryReset:!0,errors:{forceRetry:[],ignore:[]},handleUnhandledRejections:{retry:!0,sendBeacon:!0},html:{fallback:{content:'<style>.spa-guard-error-id:has(.spa-guard-retry-id:empty){display:none}.spa-guard-error-id{font-family:ui-monospace,SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace}</style><div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center;max-width:480px"><div style="margin-bottom:1.5rem"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none" viewBox="0 0 24 24" stroke="#b0b0b0" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg></div><h1 data-spa-guard-content="heading" style="font-size:1.375rem;font-weight:600;margin:0 0 .5rem;color:#1a1a1a;line-height:1.3">Something went wrong</h1><p data-spa-guard-content="message" style="max-width:600px;margin:0 auto 1.5rem;color:#666;font-size:.9375rem;line-height:1.5">Please refresh the page to continue.</p><div style="display:flex;gap:.5rem;justify-content:center;flex-wrap:wrap"><button data-spa-guard-action="try-again" type="button" style="display:none;padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid #d0d0d0;background:#fff;color:#333;cursor:pointer;line-height:1.5">Try again</button> <button data-spa-guard-action="reload" type="button" style="padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid transparent;background:#111;color:#fff;cursor:pointer;line-height:1.5">Reload page</button></div><p class="spa-guard-error-id" style="margin-top:1.5rem;font-size:.6875rem;color:#999">Error ID: <span class="spa-guard-retry-id"></span></p></div></div>',selector:"body"},loading:{content:'<div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center"><div data-spa-guard-spinner style="margin-bottom:1.25rem"></div><h2 data-spa-guard-content="loading" style="font-size:1.125rem;font-weight:600;margin:0 0 .25rem;color:#1a1a1a">Loading...</h2><p data-spa-guard-section="retrying" style="display:none;font-size:.8125rem;color:#999;margin:.5rem 0 0"><span data-spa-guard-content="retrying">Retry attempt</span> <span data-spa-guard-content="attempt"></span></p></div></div>'},spinner:{background:"#fff",disabled:!1}},lazyRetry:{callReloadOnFailure:!0,retryDelays:[1e3,2e3]},minTimeBetweenResets:5e3,reloadDelays:[1e3,2e3,5e3],staticAssets:{autoRecover:!0,recoveryDelay:500},useRetryId:!0},v=()=>{let e=globalThis.window?.[r];return{...b,...e,checkVersion:{...b.checkVersion,...e?.checkVersion},errors:{...b.errors,...e?.errors},handleUnhandledRejections:{...b.handleUnhandledRejections,...e?.handleUnhandledRejections},html:{fallback:{...b.html?.fallback,...e?.html?.fallback},loading:{...b.html?.loading,...e?.html?.loading},spinner:{...b.html?.spinner,...e?.html?.spinner}},lazyRetry:{...b.lazyRetry,...e?.lazyRetry},reportBeacon:{...b.reportBeacon,...e?.reportBeacon},staticAssets:{...b.staticAssets,...e?.staticAssets}}},S="__SPA_GUARD_FORCE_RETRY__",T="__spa_guard_last_reload_timestamp__",R="__spa_guard_last_retry_reset__";globalThis.window&&!globalThis.window[m]&&(globalThis.window[m]={resetInfo:null,storage:null});var I=()=>{let e=globalThis.window;return e?e[m]??(e[m]={resetInfo:null,storage:null}):{resetInfo:null,storage:null}},A=()=>{try{return void 0!==globalThis.window&&typeof sessionStorage<"u"}catch{return!1}},k=()=>{if(A())try{let e=sessionStorage.getItem(T);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(T)}catch{}return I().storage}return I().storage},E=()=>{try{let e=new URLSearchParams(globalThis.window.location.search),t=e.get(i),r=e.get(s);if(t&&r){let e=parseInt(r,10);return Number.isNaN(e)||e<-1?null:{retryAttempt:e,retryId:t}}return null}catch{return null}},L=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(i),e.searchParams.delete(s),e.searchParams.delete(d),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},_=()=>{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID();if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(2);return crypto.getRandomValues(e),`${Date.now()}-${e[0].toString(36)}${e[1].toString(36)}`}return`${Date.now()}-${Math.random().toString(36).slice(2,15)}`},x=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(s),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},D=()=>{let e=E();return e?{retryAttempt:e.retryAttempt,retryId:e.retryId}:{}},N=e=>{let t=(v().errors?.ignore??[]).filter(e=>""!==e);return 0!==t.length&&e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},U=e=>{let t=[...v().errors?.forceRetry??[],S].filter(e=>""!==e);return e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},z=e=>{if((e=>N([e.errorMessage,e.eventMessage]))(e))return;let t=v();if(!t.reportBeacon?.endpoint)return void p()?.noBeaconEndpoint();let r=t.appName?{...e,appName:t.appName}:e,a=JSON.stringify(r);("function"!=typeof globalThis.window?.navigator?.sendBeacon||!globalThis.window.navigator.sendBeacon(t.reportBeacon.endpoint,a))&&"function"==typeof fetch&&fetch(t.reportBeacon.endpoint,{body:a,keepalive:!0,method:"POST"}).catch(e=>{p()?.beaconSendFailed(e)})};globalThis.window&&!globalThis.window[c]&&(globalThis.window[c]={scheduled:!1});var M=(e,t)=>{let r=void 0===globalThis.window?{scheduled:!1}:globalThis.window[c]??(globalThis.window[c]={scheduled:!1});if(r.scheduled)p()?.reloadAlreadyScheduled(e);else{r.scheduled=!0;try{let a,n=v(),o=n.reloadDelays??[1e3,2e3,5e3],l=n.useRetryId??!0,c=n.enableRetryReset??!0,m=n.minTimeBetweenResets??5e3;if(l)a=E();else{let e=(()=>{try{let e=new URLSearchParams(globalThis.window.location.search).get(s);if(e){let t=parseInt(e,10);return Number.isNaN(t)||t<-1?null:t}return null}catch{return null}})();a=null===e?null:{retryAttempt:e,retryId:_()}}let u=a?a.retryAttempt:0,y=a?.retryId??_();p()?.retryCycleStarting(y,u);let f=g.defaultRetryEnabled;if(h({error:e,isRetrying:f&&u>=0&&u<o.length,name:"chunk-error"}),!f)return void(r.scheduled=!1);if(c&&a&&a.retryAttempt>0&&((e,t,r=5e3)=>{if(0===e.retryAttempt)return!1;let a=k();if(!a||a.retryId!==e.retryId)return!1;let n=(()=>{if(A())try{let e=sessionStorage.getItem(R);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(R)}catch{}return I().resetInfo}return I().resetInfo})();return!(n&&Date.now()-n.timestamp<r)&&Date.now()-a.timestamp>(t[a.attemptNumber-1]??1e3)+3e4})(a,o,m)){let t=k(),r=t?Date.now()-t.timestamp:0;L(),(()=>{if(A())try{sessionStorage.removeItem(T)}catch{}I().storage=null})(),(e=>{let t={previousRetryId:e,timestamp:Date.now()};if(A())try{sessionStorage.setItem(R,JSON.stringify(t))}catch{I().resetInfo=t}else I().resetInfo=t})(a.retryId);let n=e+"";h({name:"retry-reset",previousAttempt:a.retryAttempt,previousRetryId:a.retryId,timeSinceReload:r},{silent:N([n])}),u=0,y=_()}if(-1===u)return N([e+""])||p()?.fallbackAlreadyShown(e),r.scheduled=!1,void j();if(u>=o.length){let t=e+"";return h({finalAttempt:u,name:"retry-exhausted",retryId:a?.retryId??""},{silent:N([t])}),z({errorMessage:"Exceeded maximum reload attempts",eventName:"chunk_error_max_reloads",retryAttempt:u,retryId:a?.retryId,serialized:JSON.stringify({error:e+"",retryAttempt:u,retryId:a?.retryId})}),l||x(),r.scheduled=!1,void j()}let w=u+1,b=o[u]??1e3;h({attempt:w,delay:b,name:"retry-attempt",retryId:y},{silent:N([e+""])}),p()?.retrySchedulingReload(y,w,b),B(w),setTimeout(()=>{let e;if(l&&c&&((e,t)=>{let r={attemptNumber:t,retryId:e,timestamp:Date.now()};if(A())try{sessionStorage.setItem(T,JSON.stringify(r))}catch{I().storage=r}else I().storage=r})(y,w),e=l?((e,t)=>{let r=new URL(globalThis.window.location.href);return r.searchParams.set(i,e),r.searchParams.set(s,t+""),r.toString()})(y,w):(e=>{let t=new URL(globalThis.window.location.href);return t.searchParams.set(s,e+""),t.toString()})(w),t?.cacheBust){let t=new URL(e);t.searchParams.set(d,Date.now()+""),e=t.toString()}globalThis.window.location.href=e},b)}catch{r.scheduled=!1}}},B=e=>{let t=v(),r=t.html?.loading?.content,a=t.html?.fallback?.selector??"body";if(r)try{let n=document.querySelector(a);if(!n)return;let o=document.createElement("div");o.innerHTML=r;let l=o.querySelector("[data-spa-guard-spinner]");l&&(t.html?.spinner?.disabled?l.remove():t.html?.spinner?.content&&(l.innerHTML=t.html.spinner.content));let i=o.querySelector('[data-spa-guard-section="retrying"]');i&&(i.style.display="block");let s=o.querySelector('[data-spa-guard-content="attempt"]');s&&(s.textContent=e+"");let d=w();d&&f(o,d),n.innerHTML=o.innerHTML}catch{}},j=()=>{let e=v(),t=e.html?.fallback?.content,r=e.html?.fallback?.selector??"body";if(t)try{let a=document.querySelector(r);if(!a)return void p()?.fallbackTargetNotFound(r);let n=document.createElement("div");n.innerHTML=t;let o=w();o&&f(n,o),a.innerHTML=n.innerHTML;let l=e.useRetryId??!0,i=E();i&&-1===i.retryAttempt?(p()?.clearingRetryState(),L()):!l&&!i&&x();let s=a.querySelector('[data-spa-guard-action="reload"]');if(s&&s.addEventListener("click",()=>location.reload()),i){let e=document.getElementsByClassName("spa-guard-retry-id");for(let t of e)t.textContent=i.retryId}h({name:"fallback-ui-shown"})}catch(e){p()?.fallbackInjectFailed(e)}else p()?.noFallbackConfigured()},P=e=>{let t=C(e);return!!t&&[/Failed to fetch dynamically imported module/i,/Importing a module script failed/i,/error loading dynamically imported module/i,/Unable to preload CSS/i,/Loading chunk \d+ failed/i,/Loading CSS chunk \d+ failed/i,/ChunkLoadError/i].some(e=>e.test(t))},C=e=>e instanceof Error?e.message:"string"==typeof e?e:e&&"object"==typeof e&&"message"in e?e.message+"":e&&"object"==typeof e&&"reason"in e?C(e.reason):null,O=/[-._][a-zA-Z0-9]{6,}\.(js|mjs|css)$/i,H=e=>{try{let t=new URL(e).pathname;return O.test(t)}catch{return O.test(e)}},q=()=>void 0===globalThis.window?{failedAssets:new Set,recoveryTimer:null}:(globalThis.window[u]||(globalThis.window[u]={failedAssets:new Set,recoveryTimer:null}),globalThis.window[u]);(()=>{if(g.initialized)return;g.initialized=!0,void 0!==globalThis.window&&(globalThis.window[o]=!0);let e=v(),t=e.reloadDelays??[],r=E();r&&r.retryAttempt>=t.length&&(p()?.retryLimitExceeded(r.retryAttempt,t.length),(e=>{try{let t=new URL(globalThis.window.location.href);t.searchParams.set(i,e),t.searchParams.set(s,"-1"),globalThis.window.history.replaceState(null,"",t.toString())}catch{}})(r.retryId)),r&&(r.retryAttempt>=t.length||-1===r.retryAttempt)&&globalThis.window.addEventListener("load",()=>{-1===E()?.retryAttempt&&L()},{once:!0});let a=globalThis.window.addEventListener.bind(globalThis.window);a("error",t=>{let r=(e=>{let t=e.target;return t instanceof HTMLScriptElement?t.src:t instanceof HTMLLinkElement?t.href:""})(t);if((e=>{let t=e.target;return t instanceof HTMLScriptElement?H(t.src):t instanceof HTMLLinkElement&&H(t.href)})(t)&&((e,t=(typeof performance>"u"?0:performance.now()))=>void 0!==e?(e=>{let t=performance.getEntriesByName(e,"resource");if(0===t.length)return!0;let r=t.at(-1);return r.responseStatus>=400||0===r.transferSize&&0===r.decodedBodySize})(e):t>3e4)(r)){if(N([r,t.message]))return;return t.preventDefault(),h({name:"static-asset-load-failed",url:r}),void(!1!==e.staticAssets?.autoRecover&&(e=>{let t=q();if(t.failedAssets.add(e),null!==t.recoveryTimer)return;let r=v().staticAssets?.recoveryDelay??500;t.recoveryTimer=setTimeout(()=>{let e=q(),t=[...e.failedAssets];e.failedAssets=new Set,e.recoveryTimer=null;let r=Error("Static asset load failed: "+t.join(", "));M(r,{cacheBust:!0})},r)})(r))}if(!N([t.message]))return p()?.capturedError("error",t),P(t)||U([t.message])?(t.preventDefault(),void M(t.error??t)):void z({errorMessage:t.message,eventName:"error",serialized:"",...D()})},!0),a("unhandledrejection",t=>{let r=t.reason+"";if(N([r]))return;if(p()?.capturedError("unhandledrejection",t),P(t.reason))return t.preventDefault(),void M(t.reason);if(U([r]))return t.preventDefault(),void M(t.reason);let a=e.handleUnhandledRejections;!1!==a?.sendBeacon&&z({errorMessage:r,eventName:"unhandledrejection",serialized:"",...D()}),!1!==a?.retry&&(t.preventDefault(),M(t.reason))}),a("securitypolicyviolation",e=>{let t=`${e.violatedDirective}: ${e.blockedURI}`;N([t])||(p()?.capturedError("csp",e.blockedURI,e.violatedDirective),z({eventMessage:t,eventName:"securitypolicyviolation",serialized:"",...D()}))}),a("vite:preloadError",e=>{N([e?.payload?.message||e?.message])||(p()?.capturedError("vite:preloadError",e),e.preventDefault(),M(e?.payload??e))})})();
1
+ var e=Object.defineProperty,t="@ovineko/spa-guard",r="__SPA_GUARD_OPTIONS__",a=Symbol.for(t+":event-subscribers"),n=Symbol.for(t+":internal-config"),o=Symbol.for(t+":initialized"),l=Symbol.for(t+":logger"),i="spaGuardRetryId",s="spaGuardRetryAttempt",d="spaGuardCacheBust",c=(Symbol.for(t+":version-check-state"),Symbol.for(t+":reload-scheduled")),u=Symbol.for(t+":in-memory-last-reload"),m=Symbol.for(t+":static-asset-recovery"),y=(Symbol.for(t+":spinner-state"),Symbol.for(t+":fallback-mode"));globalThis.window&&!globalThis.window[a]&&(globalThis.window[a]=new Set),globalThis.window&&!globalThis.window[n]&&(globalThis.window[n]={defaultRetryEnabled:!0,initialized:!1});var g=globalThis.window?.[a]??new Set,p=globalThis.window?.[n]??{defaultRetryEnabled:!0,initialized:!1},h=()=>globalThis.window?.[l],f=(e,t)=>{t?.silent||h()?.logEvent(e),g.forEach(t=>{try{t(e)}catch{}})};function w(e,t){let r=e.querySelectorAll("[data-spa-guard-content]");for(let e of r){let r=e.dataset.spaGuardContent;if(r&&r in t){let a=t[r];"string"==typeof a&&(e.textContent=a)}}let a=e.querySelectorAll("[data-spa-guard-action]");for(let e of a){let r=e.dataset.spaGuardAction,a="try-again"===r?"tryAgain":r;if(a&&a in t){let r=t[a];"string"==typeof r&&(e.textContent=r)}}if(t.rtl)for(let t of e.children)t instanceof HTMLElement&&"STYLE"!==t.tagName&&(t.style.direction="rtl")}function b(){try{let e=document.querySelector('meta[name="spa-guard-i18n"]');if(!e)return null;let t=e.getAttribute("content");return t?JSON.parse(t):null}catch{return null}}((t,r)=>{for(var a in r)e(t,a,{get:r[a],enumerable:!0})})({},{getOptions:()=>S,optionsWindowKey:()=>r});var v={checkVersion:{cache:"no-store",interval:3e5,mode:"html",onUpdate:"reload"},enableRetryReset:!0,errors:{forceRetry:[],ignore:[]},handleUnhandledRejections:{retry:!0,sendBeacon:!0},html:{fallback:{content:'<style>.spa-guard-error-id:has(.spa-guard-retry-id:empty){display:none}.spa-guard-error-id{font-family:ui-monospace,SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace}</style><div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center;max-width:480px"><div style="margin-bottom:1.5rem"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none" viewBox="0 0 24 24" stroke="#b0b0b0" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg></div><h1 data-spa-guard-content="heading" style="font-size:1.375rem;font-weight:600;margin:0 0 .5rem;color:#1a1a1a;line-height:1.3">Something went wrong</h1><p data-spa-guard-content="message" style="max-width:600px;margin:0 auto 1.5rem;color:#666;font-size:.9375rem;line-height:1.5">Please refresh the page to continue.</p><div style="display:flex;gap:.5rem;justify-content:center;flex-wrap:wrap"><button data-spa-guard-action="try-again" type="button" style="display:none;padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid #d0d0d0;background:#fff;color:#333;cursor:pointer;line-height:1.5">Try again</button> <button data-spa-guard-action="reload" type="button" style="padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid transparent;background:#111;color:#fff;cursor:pointer;line-height:1.5">Reload page</button></div><p class="spa-guard-error-id" style="margin-top:1.5rem;font-size:.6875rem;color:#999">Error ID: <span class="spa-guard-retry-id"></span></p></div></div>',selector:"body"},loading:{content:'<div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center"><div data-spa-guard-spinner style="margin-bottom:1.25rem"></div><h2 data-spa-guard-content="loading" style="font-size:1.125rem;font-weight:600;margin:0 0 .25rem;color:#1a1a1a">Loading...</h2><p data-spa-guard-section="retrying" style="display:none;font-size:.8125rem;color:#999;margin:.5rem 0 0"><span data-spa-guard-content="retrying">Retry attempt</span> <span data-spa-guard-content="attempt"></span></p></div></div>'},spinner:{background:"#fff",disabled:!1}},lazyRetry:{callReloadOnFailure:!0,retryDelays:[1e3,2e3]},minTimeBetweenResets:5e3,reloadDelays:[1e3,2e3,5e3],staticAssets:{autoRecover:!0,recoveryDelay:500},useRetryId:!0},S=()=>{let e=globalThis.window?.[r];return{...v,...e,checkVersion:{...v.checkVersion,...e?.checkVersion},errors:{...v.errors,...e?.errors},handleUnhandledRejections:{...v.handleUnhandledRejections,...e?.handleUnhandledRejections},html:{fallback:{...v.html?.fallback,...e?.html?.fallback},loading:{...v.html?.loading,...e?.html?.loading},spinner:{...v.html?.spinner,...e?.html?.spinner}},lazyRetry:{...v.lazyRetry,...e?.lazyRetry},reportBeacon:{...v.reportBeacon,...e?.reportBeacon},staticAssets:{...v.staticAssets,...e?.staticAssets}}},T="__SPA_GUARD_FORCE_RETRY__",R="__spa_guard_last_reload_timestamp__",I="__spa_guard_last_retry_reset__";globalThis.window&&!globalThis.window[u]&&(globalThis.window[u]={resetInfo:null,storage:null});var A=()=>{let e=globalThis.window;return e?e[u]??(e[u]={resetInfo:null,storage:null}):{resetInfo:null,storage:null}},k=()=>{try{return void 0!==globalThis.window&&typeof sessionStorage<"u"}catch{return!1}},E=()=>{if(k())try{let e=sessionStorage.getItem(R);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(R)}catch{}return A().storage}return A().storage},L=()=>{try{let e=new URLSearchParams(globalThis.window.location.search),t=e.get(i),r=e.get(s);if(t&&r){let e=parseInt(r,10);return Number.isNaN(e)||e<-1?null:{retryAttempt:e,retryId:t}}return null}catch{return null}},_=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(i),e.searchParams.delete(s),e.searchParams.delete(d),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},x=()=>{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID();if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(2);return crypto.getRandomValues(e),`${Date.now()}-${e[0].toString(36)}${e[1].toString(36)}`}return`${Date.now()}-${Math.random().toString(36).slice(2,15)}`},N=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(s),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},D=()=>{let e=L();return e?{retryAttempt:e.retryAttempt,retryId:e.retryId}:{}},U=()=>void 0!==globalThis.window&&!0===globalThis.window[y],z=e=>{let t=(S().errors?.ignore??[]).filter(e=>""!==e);return 0!==t.length&&e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},M=e=>{let t=[...S().errors?.forceRetry??[],T].filter(e=>""!==e);return e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},B=e=>{if((e=>z([e.errorMessage,e.eventMessage]))(e))return;let t=S();if(!t.reportBeacon?.endpoint)return void h()?.noBeaconEndpoint();let r=t.appName?{...e,appName:t.appName}:e,a=JSON.stringify(r);("function"!=typeof globalThis.window?.navigator?.sendBeacon||!globalThis.window.navigator.sendBeacon(t.reportBeacon.endpoint,a))&&"function"==typeof fetch&&fetch(t.reportBeacon.endpoint,{body:a,keepalive:!0,method:"POST"}).catch(e=>{h()?.beaconSendFailed(e)})};globalThis.window&&!globalThis.window[c]&&(globalThis.window[c]={scheduled:!1});var j=(e,t)=>{if(U())return void h()?.fallbackAlreadyShown(e);let r=void 0===globalThis.window?{scheduled:!1}:globalThis.window[c]??(globalThis.window[c]={scheduled:!1});if(r.scheduled)h()?.reloadAlreadyScheduled(e);else{r.scheduled=!0;try{let a,n=S(),o=n.reloadDelays??[1e3,2e3,5e3],l=n.useRetryId??!0,c=n.enableRetryReset??!0,u=n.minTimeBetweenResets??5e3;if(l)a=L();else{let e=(()=>{try{let e=new URLSearchParams(globalThis.window.location.search).get(s);if(e){let t=parseInt(e,10);return Number.isNaN(t)||t<-1?null:t}return null}catch{return null}})();a=null===e?null:{retryAttempt:e,retryId:x()}}let m=a?a.retryAttempt:0,y=a?.retryId??x();h()?.retryCycleStarting(y,m);let g=p.defaultRetryEnabled;if(f({error:e,isRetrying:g&&m>=0&&m<o.length,name:"chunk-error"}),!g)return void(r.scheduled=!1);if(c&&a&&a.retryAttempt>0&&((e,t,r=5e3)=>{if(0===e.retryAttempt)return!1;let a=E();if(!a||a.retryId!==e.retryId)return!1;let n=(()=>{if(k())try{let e=sessionStorage.getItem(I);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(I)}catch{}return A().resetInfo}return A().resetInfo})();return!(n&&Date.now()-n.timestamp<r)&&Date.now()-a.timestamp>(t[a.attemptNumber-1]??1e3)+3e4})(a,o,u)){let t=E(),r=t?Date.now()-t.timestamp:0;_(),(()=>{if(k())try{sessionStorage.removeItem(R)}catch{}A().storage=null})(),(e=>{let t={previousRetryId:e,timestamp:Date.now()};if(k())try{sessionStorage.setItem(I,JSON.stringify(t))}catch{A().resetInfo=t}else A().resetInfo=t})(a.retryId);let n=e+"";f({name:"retry-reset",previousAttempt:a.retryAttempt,previousRetryId:a.retryId,timeSinceReload:r},{silent:z([n])}),m=0,y=x()}if(-1===m)return z([e+""])||h()?.fallbackAlreadyShown(e),r.scheduled=!1,void C();if(m>=o.length){let t=e+"";return f({finalAttempt:m,name:"retry-exhausted",retryId:a?.retryId??""},{silent:z([t])}),B({errorMessage:"Exceeded maximum reload attempts",eventName:"chunk_error_max_reloads",retryAttempt:m,retryId:a?.retryId,serialized:JSON.stringify({error:e+"",retryAttempt:m,retryId:a?.retryId})}),l||N(),r.scheduled=!1,void C()}let w=m+1,b=o[m]??1e3;f({attempt:w,delay:b,name:"retry-attempt",retryId:y},{silent:z([e+""])}),h()?.retrySchedulingReload(y,w,b),P(w),setTimeout(()=>{let e;if(l&&c&&((e,t)=>{let r={attemptNumber:t,retryId:e,timestamp:Date.now()};if(k())try{sessionStorage.setItem(R,JSON.stringify(r))}catch{A().storage=r}else A().storage=r})(y,w),e=l?((e,t)=>{let r=new URL(globalThis.window.location.href);return r.searchParams.set(i,e),r.searchParams.set(s,t+""),r.toString()})(y,w):(e=>{let t=new URL(globalThis.window.location.href);return t.searchParams.set(s,e+""),t.toString()})(w),t?.cacheBust){let t=new URL(e);t.searchParams.set(d,Date.now()+""),e=t.toString()}globalThis.window.location.href=e},b)}catch{r.scheduled=!1}}},P=e=>{let t=S(),r=t.html?.loading?.content,a=t.html?.fallback?.selector??"body";if(r)try{let n=document.querySelector(a);if(!n)return;let o=document.createElement("div");o.innerHTML=r;let l=o.querySelector("[data-spa-guard-spinner]");l&&(t.html?.spinner?.disabled?l.remove():t.html?.spinner?.content&&(l.innerHTML=t.html.spinner.content));let i=o.querySelector('[data-spa-guard-section="retrying"]');i&&(i.style.display="block");let s=o.querySelector('[data-spa-guard-content="attempt"]');s&&(s.textContent=e+"");let d=b();d&&w(o,d),n.innerHTML=o.innerHTML}catch{}},C=()=>{if(U())return;void 0!==globalThis.window&&(globalThis.window[y]=!0);let e=S(),t=e.html?.fallback?.content,r=e.html?.fallback?.selector??"body";if(t)try{let a=document.querySelector(r);if(!a)return void h()?.fallbackTargetNotFound(r);let n=document.createElement("div");n.innerHTML=t;let o=b();o&&w(n,o),a.innerHTML=n.innerHTML;let l=e.useRetryId??!0,i=L();i&&-1===i.retryAttempt?(h()?.clearingRetryState(),_()):!l&&!i&&N();let s=a.querySelector('[data-spa-guard-action="reload"]');if(s&&s.addEventListener("click",()=>location.reload()),i){let e=document.getElementsByClassName("spa-guard-retry-id");for(let t of e)t.textContent=i.retryId}f({name:"fallback-ui-shown"})}catch(e){h()?.fallbackInjectFailed(e)}else h()?.noFallbackConfigured()},O=e=>{let t=H(e);return!!t&&[/Failed to fetch dynamically imported module/i,/Importing a module script failed/i,/error loading dynamically imported module/i,/Unable to preload CSS/i,/Loading chunk \d+ failed/i,/Loading CSS chunk \d+ failed/i,/ChunkLoadError/i].some(e=>e.test(t))},H=e=>e instanceof Error?e.message:"string"==typeof e?e:e&&"object"==typeof e&&"message"in e?e.message+"":e&&"object"==typeof e&&"reason"in e?H(e.reason):null,q=/[-._][a-zA-Z0-9]{6,}\.(js|mjs|css)$/i,F=e=>{try{let t=new URL(e).pathname;return q.test(t)}catch{return q.test(e)}},$=()=>void 0===globalThis.window?{failedAssets:new Set,recoveryTimer:null}:(globalThis.window[m]||(globalThis.window[m]={failedAssets:new Set,recoveryTimer:null}),globalThis.window[m]);(()=>{if(p.initialized)return;p.initialized=!0,void 0!==globalThis.window&&(globalThis.window[o]=!0);let e=S(),t=e.reloadDelays??[],r=L();if(r&&r.retryAttempt>=t.length&&(h()?.retryLimitExceeded(r.retryAttempt,t.length),(e=>{try{let t=new URL(globalThis.window.location.href);t.searchParams.set(i,e),t.searchParams.set(s,"-1"),globalThis.window.history.replaceState(null,"",t.toString())}catch{}})(r.retryId)),r&&(r.retryAttempt>=t.length||-1===r.retryAttempt)){let e=()=>{-1===L()?.retryAttempt&&_()};"complete"===globalThis.window.document?.readyState?e():globalThis.window.addEventListener("load",e,{once:!0})}let a=globalThis.window.addEventListener.bind(globalThis.window);a("error",t=>{let r=(e=>{let t=e.target;return t instanceof HTMLScriptElement?t.src:t instanceof HTMLLinkElement?t.href:""})(t);if((e=>{let t=e.target;return t instanceof HTMLScriptElement?F(t.src):t instanceof HTMLLinkElement&&F(t.href)})(t)&&(void 0!==(a=r)?(e=>{if(typeof performance>"u"||"function"!=typeof performance.getEntriesByName)return!0;let t=performance.getEntriesByName(e,"resource");if(0===t.length)return!0;let r=t.at(-1);return r.responseStatus>=400||0===r.transferSize&&0===r.decodedBodySize})(a):(typeof performance>"u"?0:performance.now())>3e4)){if(z([r,t.message]))return;return t.preventDefault(),f({name:"static-asset-load-failed",url:r}),void(!1!==e.staticAssets?.autoRecover&&(e=>{if(void 0===globalThis.window||U())return;let t=$();if(t.failedAssets.add(e),null!==t.recoveryTimer)return;let r=S().staticAssets?.recoveryDelay??500;t.recoveryTimer=setTimeout(()=>{let e=$();e.recoveryTimer=null;let t=[...e.failedAssets];if(e.failedAssets=new Set,U())return;let r=Error("Static asset load failed: "+t.join(", "));j(r,{cacheBust:!0})},r)})(r))}var a;if(!z([t.message]))return h()?.capturedError("error",t),O(t)||M([t.message])?(t.preventDefault(),void j(t.error??t)):void B({errorMessage:t.message,eventName:"error",serialized:"",...D()})},!0),a("unhandledrejection",t=>{let r=t.reason+"";if(z([r]))return;if(h()?.capturedError("unhandledrejection",t),O(t.reason))return t.preventDefault(),void j(t.reason);if(M([r]))return t.preventDefault(),void j(t.reason);let a=e.handleUnhandledRejections;!1!==a?.sendBeacon&&B({errorMessage:r,eventName:"unhandledrejection",serialized:"",...D()}),!1!==a?.retry&&(t.preventDefault(),j(t.reason))}),a("securitypolicyviolation",e=>{let t=`${e.violatedDirective}: ${e.blockedURI}`;z([t])||(h()?.capturedError("csp",e.blockedURI,e.violatedDirective),B({eventMessage:t,eventName:"securitypolicyviolation",serialized:"",...D()}))}),a("vite:preloadError",e=>{z([e?.payload?.message||e?.message])||(h()?.capturedError("vite:preloadError",e),e.preventDefault(),j(e?.payload??e))})})();
@@ -1 +1 @@
1
- var e=Object.defineProperty,t="@ovineko/spa-guard",r="__SPA_GUARD_OPTIONS__",a=Symbol.for(t+":event-subscribers"),n=Symbol.for(t+":internal-config"),o=Symbol.for(t+":initialized"),l=Symbol.for(t+":logger"),i="spaGuardRetryId",s="spaGuardRetryAttempt",d="spaGuardCacheBust",c=(Symbol.for(t+":version-check-state"),Symbol.for(t+":reload-scheduled")),y=Symbol.for(t+":in-memory-last-reload"),u=Symbol.for(t+":static-asset-recovery");Symbol.for(t+":spinner-state"),globalThis.window&&!globalThis.window[a]&&(globalThis.window[a]=new Set),globalThis.window&&!globalThis.window[n]&&(globalThis.window[n]={defaultRetryEnabled:!0,initialized:!1});var m=globalThis.window?.[a]??new Set,g=globalThis.window?.[n]??{defaultRetryEnabled:!0,initialized:!1},p=()=>globalThis.window?.[l],h=(e,t)=>{t?.silent||p()?.logEvent(e),m.forEach(t=>{try{t(e)}catch{}})};function f(e,t){let r=e.querySelectorAll("[data-spa-guard-content]");for(let e of r){let r=e.dataset.spaGuardContent;if(r&&r in t){let a=t[r];"string"==typeof a&&(e.textContent=a)}}let a=e.querySelectorAll("[data-spa-guard-action]");for(let e of a){let r=e.dataset.spaGuardAction,a="try-again"===r?"tryAgain":r;if(a&&a in t){let r=t[a];"string"==typeof r&&(e.textContent=r)}}if(t.rtl)for(let t of e.children)t instanceof HTMLElement&&"STYLE"!==t.tagName&&(t.style.direction="rtl")}function w(){try{let e=document.querySelector('meta[name="spa-guard-i18n"]');if(!e)return null;let t=e.getAttribute("content");return t?JSON.parse(t):null}catch{return null}}((t,r)=>{for(var a in r)e(t,a,{get:r[a],enumerable:!0})})({},{getOptions:()=>v,optionsWindowKey:()=>r});var b={checkVersion:{cache:"no-store",interval:3e5,mode:"html",onUpdate:"reload"},enableRetryReset:!0,errors:{forceRetry:[],ignore:[]},handleUnhandledRejections:{retry:!0,sendBeacon:!0},html:{fallback:{content:'<style>.spa-guard-error-id:has(.spa-guard-retry-id:empty){display:none}.spa-guard-error-id{font-family:ui-monospace,SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace}</style><div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center;max-width:480px"><div style="margin-bottom:1.5rem"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none" viewBox="0 0 24 24" stroke="#b0b0b0" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg></div><h1 data-spa-guard-content="heading" style="font-size:1.375rem;font-weight:600;margin:0 0 .5rem;color:#1a1a1a;line-height:1.3">Something went wrong</h1><p data-spa-guard-content="message" style="max-width:600px;margin:0 auto 1.5rem;color:#666;font-size:.9375rem;line-height:1.5">Please refresh the page to continue.</p><div style="display:flex;gap:.5rem;justify-content:center;flex-wrap:wrap"><button data-spa-guard-action="try-again" type="button" style="display:none;padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid #d0d0d0;background:#fff;color:#333;cursor:pointer;line-height:1.5">Try again</button> <button data-spa-guard-action="reload" type="button" style="padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid transparent;background:#111;color:#fff;cursor:pointer;line-height:1.5">Reload page</button></div><p class="spa-guard-error-id" style="margin-top:1.5rem;font-size:.6875rem;color:#999">Error ID: <span class="spa-guard-retry-id"></span></p></div></div>',selector:"body"},loading:{content:'<div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center"><div data-spa-guard-spinner style="margin-bottom:1.25rem"></div><h2 data-spa-guard-content="loading" style="font-size:1.125rem;font-weight:600;margin:0 0 .25rem;color:#1a1a1a">Loading...</h2><p data-spa-guard-section="retrying" style="display:none;font-size:.8125rem;color:#999;margin:.5rem 0 0"><span data-spa-guard-content="retrying">Retry attempt</span> <span data-spa-guard-content="attempt"></span></p></div></div>'},spinner:{background:"#fff",disabled:!1}},lazyRetry:{callReloadOnFailure:!0,retryDelays:[1e3,2e3]},minTimeBetweenResets:5e3,reloadDelays:[1e3,2e3,5e3],staticAssets:{autoRecover:!0,recoveryDelay:500},useRetryId:!0},v=()=>{let e=globalThis.window?.[r];return{...b,...e,checkVersion:{...b.checkVersion,...e?.checkVersion},errors:{...b.errors,...e?.errors},handleUnhandledRejections:{...b.handleUnhandledRejections,...e?.handleUnhandledRejections},html:{fallback:{...b.html?.fallback,...e?.html?.fallback},loading:{...b.html?.loading,...e?.html?.loading},spinner:{...b.html?.spinner,...e?.html?.spinner}},lazyRetry:{...b.lazyRetry,...e?.lazyRetry},reportBeacon:{...b.reportBeacon,...e?.reportBeacon},staticAssets:{...b.staticAssets,...e?.staticAssets}}},S="__SPA_GUARD_FORCE_RETRY__",k="__spa_guard_last_reload_timestamp__",T="__spa_guard_last_retry_reset__";globalThis.window&&!globalThis.window[y]&&(globalThis.window[y]={resetInfo:null,storage:null});var R=()=>{let e=globalThis.window;return e?e[y]??(e[y]={resetInfo:null,storage:null}):{resetInfo:null,storage:null}},I=()=>{try{return void 0!==globalThis.window&&typeof sessionStorage<"u"}catch{return!1}},$=()=>{if(I())try{let e=sessionStorage.getItem(k);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(k)}catch{}return R().storage}return R().storage},A=()=>{try{let e=new URLSearchParams(globalThis.window.location.search),t=e.get(i),r=e.get(s);if(t&&r){let e=parseInt(r,10);return Number.isNaN(e)||e<-1?null:{retryAttempt:e,retryId:t}}return null}catch{return null}},E=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(i),e.searchParams.delete(s),e.searchParams.delete(d),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},N=()=>{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID();if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(2);return crypto.getRandomValues(e),`${Date.now()}-${e[0].toString(36)}${e[1].toString(36)}`}return`${Date.now()}-${Math.random().toString(36).slice(2,15)}`},x=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(s),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},z=()=>{let e=A();return e?{retryAttempt:e.retryAttempt,retryId:e.retryId}:{}},L=e=>{let t=(v().errors?.ignore??[]).filter(e=>""!==e);return 0!==t.length&&e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},D=e=>{let t=[...v().errors?.forceRetry??[],S].filter(e=>""!==e);return e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},U=e=>{if((e=>L([e.errorMessage,e.eventMessage]))(e))return;let t=v();if(!t.reportBeacon?.endpoint)return void p()?.noBeaconEndpoint();let r=t.appName?{...e,appName:t.appName}:e,a=JSON.stringify(r);("function"!=typeof globalThis.window?.navigator?.sendBeacon||!globalThis.window.navigator.sendBeacon(t.reportBeacon.endpoint,a))&&"function"==typeof fetch&&fetch(t.reportBeacon.endpoint,{body:a,keepalive:!0,method:"POST"}).catch(e=>{p()?.beaconSendFailed(e)})};globalThis.window&&!globalThis.window[c]&&(globalThis.window[c]={scheduled:!1});var _=(e,t)=>{let r=void 0===globalThis.window?{scheduled:!1}:globalThis.window[c]??(globalThis.window[c]={scheduled:!1});if(r.scheduled)p()?.reloadAlreadyScheduled(e);else{r.scheduled=!0;try{let a,n=v(),o=n.reloadDelays??[1e3,2e3,5e3],l=n.useRetryId??!0,c=n.enableRetryReset??!0,y=n.minTimeBetweenResets??5e3;if(l)a=A();else{let e=(()=>{try{let e=new URLSearchParams(globalThis.window.location.search).get(s);if(e){let t=parseInt(e,10);return Number.isNaN(t)||t<-1?null:t}return null}catch{return null}})();a=null===e?null:{retryAttempt:e,retryId:N()}}let u=a?a.retryAttempt:0,m=a?.retryId??N();p()?.retryCycleStarting(m,u);let f=g.defaultRetryEnabled;if(h({error:e,isRetrying:f&&u>=0&&u<o.length,name:"chunk-error"}),!f)return void(r.scheduled=!1);if(c&&a&&a.retryAttempt>0&&((e,t,r=5e3)=>{if(0===e.retryAttempt)return!1;let a=$();if(!a||a.retryId!==e.retryId)return!1;let n=(()=>{if(I())try{let e=sessionStorage.getItem(T);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(T)}catch{}return R().resetInfo}return R().resetInfo})();return!(n&&Date.now()-n.timestamp<r)&&Date.now()-a.timestamp>(t[a.attemptNumber-1]??1e3)+3e4})(a,o,y)){let t=$(),r=t?Date.now()-t.timestamp:0;E(),(()=>{if(I())try{sessionStorage.removeItem(k)}catch{}R().storage=null})(),(e=>{let t={previousRetryId:e,timestamp:Date.now()};if(I())try{sessionStorage.setItem(T,JSON.stringify(t))}catch{R().resetInfo=t}else R().resetInfo=t})(a.retryId);let n=e+"";h({name:"retry-reset",previousAttempt:a.retryAttempt,previousRetryId:a.retryId,timeSinceReload:r},{silent:L([n])}),u=0,m=N()}if(-1===u)return L([e+""])||p()?.fallbackAlreadyShown(e),r.scheduled=!1,void j();if(u>=o.length){let t=e+"";return h({finalAttempt:u,name:"retry-exhausted",retryId:a?.retryId??""},{silent:L([t])}),U({errorMessage:"Exceeded maximum reload attempts",eventName:"chunk_error_max_reloads",retryAttempt:u,retryId:a?.retryId,serialized:JSON.stringify({error:e+"",retryAttempt:u,retryId:a?.retryId})}),l||x(),r.scheduled=!1,void j()}let w=u+1,b=o[u]??1e3;h({attempt:w,delay:b,name:"retry-attempt",retryId:m},{silent:L([e+""])}),p()?.retrySchedulingReload(m,w,b),C(w),setTimeout(()=>{let e;if(l&&c&&((e,t)=>{let r={attemptNumber:t,retryId:e,timestamp:Date.now()};if(I())try{sessionStorage.setItem(k,JSON.stringify(r))}catch{R().storage=r}else R().storage=r})(m,w),e=l?((e,t)=>{let r=new URL(globalThis.window.location.href);return r.searchParams.set(i,e),r.searchParams.set(s,t+""),r.toString()})(m,w):(e=>{let t=new URL(globalThis.window.location.href);return t.searchParams.set(s,e+""),t.toString()})(w),t?.cacheBust){let t=new URL(e);t.searchParams.set(d,Date.now()+""),e=t.toString()}globalThis.window.location.href=e},b)}catch{r.scheduled=!1}}},C=e=>{let t=v(),r=t.html?.loading?.content,a=t.html?.fallback?.selector??"body";if(r)try{let n=document.querySelector(a);if(!n)return;let o=document.createElement("div");o.innerHTML=r;let l=o.querySelector("[data-spa-guard-spinner]");l&&(t.html?.spinner?.disabled?l.remove():t.html?.spinner?.content&&(l.innerHTML=t.html.spinner.content));let i=o.querySelector('[data-spa-guard-section="retrying"]');i&&(i.style.display="block");let s=o.querySelector('[data-spa-guard-content="attempt"]');s&&(s.textContent=e+"");let d=w();d&&f(o,d),n.innerHTML=o.innerHTML}catch{}},j=()=>{let e=v(),t=e.html?.fallback?.content,r=e.html?.fallback?.selector??"body";if(t)try{let a=document.querySelector(r);if(!a)return void p()?.fallbackTargetNotFound(r);let n=document.createElement("div");n.innerHTML=t;let o=w();o&&f(n,o),a.innerHTML=n.innerHTML;let l=e.useRetryId??!0,i=A();i&&-1===i.retryAttempt?(p()?.clearingRetryState(),E()):!l&&!i&&x();let s=a.querySelector('[data-spa-guard-action="reload"]');if(s&&s.addEventListener("click",()=>location.reload()),i){let e=document.getElementsByClassName("spa-guard-retry-id");for(let t of e)t.textContent=i.retryId}h({name:"fallback-ui-shown"})}catch(e){p()?.fallbackInjectFailed(e)}else p()?.noFallbackConfigured()},P=e=>{let t=M(e);return!!t&&[/Failed to fetch dynamically imported module/i,/Importing a module script failed/i,/error loading dynamically imported module/i,/Unable to preload CSS/i,/Loading chunk \d+ failed/i,/Loading CSS chunk \d+ failed/i,/ChunkLoadError/i].some(e=>e.test(t))},M=e=>e instanceof Error?e.message:"string"==typeof e?e:e&&"object"==typeof e&&"message"in e?e.message+"":e&&"object"==typeof e&&"reason"in e?M(e.reason):null,B=e=>{if(null==e)return{type:"null",value:e};if("object"!=typeof e)return{type:typeof e,value:e};if(e instanceof Error)return{message:e.message,name:e.name,stack:e.stack,type:"Error",...F(e)};if("reason"in e&&"promise"in e)return{reason:B(e.reason),type:"PromiseRejectionEvent"};if("error"in e&&"message"in e&&"filename"in e)return{colno:e.colno,error:B(e.error),filename:e.filename,lineno:e.lineno,message:e.message,type:"ErrorEvent"};if("violatedDirective"in e&&"blockedURI"in e){let t=e;return{blockedURI:t.blockedURI,columnNumber:t.columnNumber,effectiveDirective:t.effectiveDirective,lineNumber:t.lineNumber,originalPolicy:t.originalPolicy,sourceFile:t.sourceFile,type:"SecurityPolicyViolationEvent",violatedDirective:t.violatedDirective}}if("type"in e&&"target"in e){let t=e;return{eventType:t.type,target:O(t.target),timeStamp:t.timeStamp,type:"Event"}}return{type:"object",value:H(e)}},F=e=>{let t={};for(let r of Object.getOwnPropertyNames(e))if(!["message","name","stack"].includes(r))try{t[r]=e[r]}catch{}return t},O=e=>e?e instanceof HTMLElement?{className:e.className,href:e.href,id:e.id,src:e.src,tagName:e.tagName}:{type:e+""}:null,H=e=>{let t={};for(let r of Object.keys(e))try{let a=e[r];t[r]="object"==typeof a?a+"":a}catch{}return t},V=/[-._][a-zA-Z0-9]{6,}\.(js|mjs|css)$/i,q=e=>{try{let t=new URL(e).pathname;return V.test(t)}catch{return V.test(e)}},J=()=>void 0===globalThis.window?{failedAssets:new Set,recoveryTimer:null}:(globalThis.window[u]||(globalThis.window[u]={failedAssets:new Set,recoveryTimer:null}),globalThis.window[u]),G="[spa-guard]",Y={"chunk-error":"error","fallback-ui-shown":"warn","lazy-retry-attempt":"warn","lazy-retry-exhausted":"error","lazy-retry-start":"log","lazy-retry-success":"log","retry-attempt":"warn","retry-exhausted":"error","retry-reset":"log","static-asset-load-failed":"error"};((e,t)=>{if(g.initialized)return;t&&(e=>{void 0!==globalThis.window&&(globalThis.window[l]=e)})(t),g.initialized=!0,void 0!==globalThis.window&&(globalThis.window[o]=!0);let r=v(),a=r.reloadDelays??[],n=A();n&&n.retryAttempt>=a.length&&(p()?.retryLimitExceeded(n.retryAttempt,a.length),(e=>{try{let t=new URL(globalThis.window.location.href);t.searchParams.set(i,e),t.searchParams.set(s,"-1"),globalThis.window.history.replaceState(null,"",t.toString())}catch{}})(n.retryId)),n&&(n.retryAttempt>=a.length||-1===n.retryAttempt)&&globalThis.window.addEventListener("load",()=>{-1===A()?.retryAttempt&&E()},{once:!0});let d=globalThis.window.addEventListener.bind(globalThis.window);d("error",t=>{let a=(e=>{let t=e.target;return t instanceof HTMLScriptElement?t.src:t instanceof HTMLLinkElement?t.href:""})(t);if((e=>{let t=e.target;return t instanceof HTMLScriptElement?q(t.src):t instanceof HTMLLinkElement&&q(t.href)})(t)&&((e,t=(typeof performance>"u"?0:performance.now()))=>void 0!==e?(e=>{let t=performance.getEntriesByName(e,"resource");if(0===t.length)return!0;let r=t.at(-1);return r.responseStatus>=400||0===r.transferSize&&0===r.decodedBodySize})(e):t>3e4)(a)){if(L([a,t.message]))return;return t.preventDefault(),h({name:"static-asset-load-failed",url:a}),void(!1!==r.staticAssets?.autoRecover&&(e=>{let t=J();if(t.failedAssets.add(e),null!==t.recoveryTimer)return;let r=v().staticAssets?.recoveryDelay??500;t.recoveryTimer=setTimeout(()=>{let e=J(),t=[...e.failedAssets];e.failedAssets=new Set,e.recoveryTimer=null;let r=Error("Static asset load failed: "+t.join(", "));_(r,{cacheBust:!0})},r)})(a))}if(L([t.message]))return;if(p()?.capturedError("error",t),P(t))return t.preventDefault(),void _(t.error??t);if(D([t.message]))return t.preventDefault(),void _(t.error??t);let n=e(t);U({errorMessage:t.message,eventName:"error",serialized:n,...z()})},!0),d("unhandledrejection",t=>{let a=t.reason+"";if(L([a]))return;if(p()?.capturedError("unhandledrejection",t),P(t.reason))return t.preventDefault(),void _(t.reason);if(D([a]))return t.preventDefault(),void _(t.reason);let n=r.handleUnhandledRejections;if(!1!==n?.sendBeacon){let r=e(t);U({errorMessage:a,eventName:"unhandledrejection",serialized:r,...z()})}!1!==n?.retry&&(t.preventDefault(),_(t.reason))}),d("securitypolicyviolation",t=>{let r=`${t.violatedDirective}: ${t.blockedURI}`;if(L([r]))return;p()?.capturedError("csp",t.blockedURI,t.violatedDirective);let a=e(t);U({eventMessage:r,eventName:"securitypolicyviolation",serialized:a,...z()})}),d("vite:preloadError",e=>{L([e?.payload?.message||e?.message])||(p()?.capturedError("vite:preloadError",e),e.preventDefault(),_(e?.payload??e))})})(e=>{try{let t=B(e);return JSON.stringify(t,null,2)}catch{return JSON.stringify({error:"Failed to serialize error",fallback:e+""})}},{beaconSendFailed(e){console.error(G+" Failed to send beacon:",e)},capturedError(e,...t){console.error(`${G} ${e}:capture:`,...t)},clearingRetryState(){console.log(G+" Clearing retry state from URL to allow clean reload attempt")},error(e,...t){console.error(`${G} ${e}`,...t)},fallbackAlreadyShown(e){console.error(G+" Fallback UI was already shown. Not retrying to prevent infinite loop.",e)},fallbackInjectFailed(e){console.error(G+" Failed to inject fallback UI",e)},fallbackTargetNotFound(e){console.error(`${G} Target element not found for selector: ${e}`)},log(e,...t){console.log(`${G} ${e}`,...t)},logEvent(e){let t=Y[e.name],r=(e=>{switch(e.name){case"chunk-error":return`${G} chunk-error: isRetrying=${e.isRetrying}`;case"fallback-ui-shown":return G+" fallback-ui-shown";case"lazy-retry-attempt":return`${G} lazy-retry-attempt: attempt ${e.attempt}/${e.totalAttempts}, delay ${e.delay}ms`;case"lazy-retry-exhausted":return`${G} lazy-retry-exhausted: ${e.totalAttempts} attempts, willReload=${e.willReload}`;case"lazy-retry-start":return`${G} lazy-retry-start: totalAttempts=${e.totalAttempts}`;case"lazy-retry-success":{let t=void 0===e.totalTime?"":`, totalTime=${e.totalTime}ms`;return`${G} lazy-retry-success: succeeded on attempt ${e.attempt}${t}`}case"retry-attempt":return`${G} retry-attempt: attempt ${e.attempt} in ${e.delay}ms (retryId: ${e.retryId})`;case"retry-exhausted":return`${G} retry-exhausted: finalAttempt=${e.finalAttempt} (retryId: ${e.retryId})`;case"retry-reset":return`${G} retry-reset: ${e.timeSinceReload}ms since last reload (retryId: ${e.previousRetryId})`;case"static-asset-load-failed":return`${G} static-asset-load-failed: ${e.url}`}})(e);"chunk-error"===e.name||"lazy-retry-attempt"===e.name||"lazy-retry-exhausted"===e.name?console[t](r,e.error):console[t](r)},noBeaconEndpoint(){console.warn(G+" Report endpoint is not configured")},noFallbackConfigured(){console.error(G+" No fallback UI configured")},reloadAlreadyScheduled(e){console.log(G+" Reload already scheduled, ignoring duplicate chunk error:",e)},retryCycleStarting(e,t){console.log(`${G} Retry cycle starting: retryId=${e}, fromAttempt=${t}`)},retryLimitExceeded(e,t){console.log(`${G} Retry limit exceeded (${e}/${t}), marking as fallback shown`)},retrySchedulingReload(e,t,r){console.log(`${G} Scheduling reload: retryId=${e}, attempt=${t}, delay=${r}ms`)},updatedRetryAttempt(e){console.log(`${G} Updated retry attempt to ${e} in URL for fallback UI`)},versionChangeDetected(e,t){console.warn(`${G} New version available (${e??"unknown"} → ${t}). Please refresh to get the latest version.`)},versionCheckAlreadyRunning(){console.warn(G+" Version check already running")},versionCheckDisabled(){console.warn(G+" Version checking disabled: no version configured")},versionCheckFailed(e){console.error(G+" Version check failed",e)},versionCheckHttpError(e){console.warn(`${G} Version check HTTP error: ${e}`)},versionCheckParseError(){console.warn(G+" Failed to parse version from HTML")},versionCheckPaused(){console.log(G+" Version check paused (tab hidden)")},versionCheckRequiresEndpoint(){console.warn(G+" JSON version check mode requires endpoint")},versionCheckResumed(){console.log(G+" Version check resumed (tab visible)")},versionCheckResumedImmediate(){console.log(G+" Version check resumed with immediate check (tab visible, interval elapsed)")},versionCheckStarted(e,t,r){console.log(`${G} Starting version check (mode: ${e}, interval: ${t}ms, current: ${r})`)},versionCheckStopped(){console.log(G+" Version check stopped")},warn(e,...t){console.warn(`${G} ${e}`,...t)}});
1
+ var e=Object.defineProperty,t="@ovineko/spa-guard",r="__SPA_GUARD_OPTIONS__",a=Symbol.for(t+":event-subscribers"),n=Symbol.for(t+":internal-config"),o=Symbol.for(t+":initialized"),l=Symbol.for(t+":logger"),i="spaGuardRetryId",s="spaGuardRetryAttempt",d="spaGuardCacheBust",c=(Symbol.for(t+":version-check-state"),Symbol.for(t+":reload-scheduled")),y=Symbol.for(t+":in-memory-last-reload"),u=Symbol.for(t+":static-asset-recovery"),m=(Symbol.for(t+":spinner-state"),Symbol.for(t+":fallback-mode"));globalThis.window&&!globalThis.window[a]&&(globalThis.window[a]=new Set),globalThis.window&&!globalThis.window[n]&&(globalThis.window[n]={defaultRetryEnabled:!0,initialized:!1});var g=globalThis.window?.[a]??new Set,p=globalThis.window?.[n]??{defaultRetryEnabled:!0,initialized:!1},f=()=>globalThis.window?.[l],h=(e,t)=>{t?.silent||f()?.logEvent(e),g.forEach(t=>{try{t(e)}catch{}})};function w(e,t){let r=e.querySelectorAll("[data-spa-guard-content]");for(let e of r){let r=e.dataset.spaGuardContent;if(r&&r in t){let a=t[r];"string"==typeof a&&(e.textContent=a)}}let a=e.querySelectorAll("[data-spa-guard-action]");for(let e of a){let r=e.dataset.spaGuardAction,a="try-again"===r?"tryAgain":r;if(a&&a in t){let r=t[a];"string"==typeof r&&(e.textContent=r)}}if(t.rtl)for(let t of e.children)t instanceof HTMLElement&&"STYLE"!==t.tagName&&(t.style.direction="rtl")}function b(){try{let e=document.querySelector('meta[name="spa-guard-i18n"]');if(!e)return null;let t=e.getAttribute("content");return t?JSON.parse(t):null}catch{return null}}((t,r)=>{for(var a in r)e(t,a,{get:r[a],enumerable:!0})})({},{getOptions:()=>S,optionsWindowKey:()=>r});var v={checkVersion:{cache:"no-store",interval:3e5,mode:"html",onUpdate:"reload"},enableRetryReset:!0,errors:{forceRetry:[],ignore:[]},handleUnhandledRejections:{retry:!0,sendBeacon:!0},html:{fallback:{content:'<style>.spa-guard-error-id:has(.spa-guard-retry-id:empty){display:none}.spa-guard-error-id{font-family:ui-monospace,SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace}</style><div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center;max-width:480px"><div style="margin-bottom:1.5rem"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none" viewBox="0 0 24 24" stroke="#b0b0b0" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg></div><h1 data-spa-guard-content="heading" style="font-size:1.375rem;font-weight:600;margin:0 0 .5rem;color:#1a1a1a;line-height:1.3">Something went wrong</h1><p data-spa-guard-content="message" style="max-width:600px;margin:0 auto 1.5rem;color:#666;font-size:.9375rem;line-height:1.5">Please refresh the page to continue.</p><div style="display:flex;gap:.5rem;justify-content:center;flex-wrap:wrap"><button data-spa-guard-action="try-again" type="button" style="display:none;padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid #d0d0d0;background:#fff;color:#333;cursor:pointer;line-height:1.5">Try again</button> <button data-spa-guard-action="reload" type="button" style="padding:.5rem 1.25rem;font-size:.875rem;font-family:inherit;border-radius:6px;border:1px solid transparent;background:#111;color:#fff;cursor:pointer;line-height:1.5">Reload page</button></div><p class="spa-guard-error-id" style="margin-top:1.5rem;font-size:.6875rem;color:#999">Error ID: <span class="spa-guard-retry-id"></span></p></div></div>',selector:"body"},loading:{content:'<div style="display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem;font-family:system-ui,sans-serif"><div style="text-align:center"><div data-spa-guard-spinner style="margin-bottom:1.25rem"></div><h2 data-spa-guard-content="loading" style="font-size:1.125rem;font-weight:600;margin:0 0 .25rem;color:#1a1a1a">Loading...</h2><p data-spa-guard-section="retrying" style="display:none;font-size:.8125rem;color:#999;margin:.5rem 0 0"><span data-spa-guard-content="retrying">Retry attempt</span> <span data-spa-guard-content="attempt"></span></p></div></div>'},spinner:{background:"#fff",disabled:!1}},lazyRetry:{callReloadOnFailure:!0,retryDelays:[1e3,2e3]},minTimeBetweenResets:5e3,reloadDelays:[1e3,2e3,5e3],staticAssets:{autoRecover:!0,recoveryDelay:500},useRetryId:!0},S=()=>{let e=globalThis.window?.[r];return{...v,...e,checkVersion:{...v.checkVersion,...e?.checkVersion},errors:{...v.errors,...e?.errors},handleUnhandledRejections:{...v.handleUnhandledRejections,...e?.handleUnhandledRejections},html:{fallback:{...v.html?.fallback,...e?.html?.fallback},loading:{...v.html?.loading,...e?.html?.loading},spinner:{...v.html?.spinner,...e?.html?.spinner}},lazyRetry:{...v.lazyRetry,...e?.lazyRetry},reportBeacon:{...v.reportBeacon,...e?.reportBeacon},staticAssets:{...v.staticAssets,...e?.staticAssets}}},k="__SPA_GUARD_FORCE_RETRY__",T="__spa_guard_last_reload_timestamp__",R="__spa_guard_last_retry_reset__";globalThis.window&&!globalThis.window[y]&&(globalThis.window[y]={resetInfo:null,storage:null});var I=()=>{let e=globalThis.window;return e?e[y]??(e[y]={resetInfo:null,storage:null}):{resetInfo:null,storage:null}},$=()=>{try{return void 0!==globalThis.window&&typeof sessionStorage<"u"}catch{return!1}},A=()=>{if($())try{let e=sessionStorage.getItem(T);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(T)}catch{}return I().storage}return I().storage},E=()=>{try{let e=new URLSearchParams(globalThis.window.location.search),t=e.get(i),r=e.get(s);if(t&&r){let e=parseInt(r,10);return Number.isNaN(e)||e<-1?null:{retryAttempt:e,retryId:t}}return null}catch{return null}},N=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(i),e.searchParams.delete(s),e.searchParams.delete(d),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},x=()=>{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID();if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(2);return crypto.getRandomValues(e),`${Date.now()}-${e[0].toString(36)}${e[1].toString(36)}`}return`${Date.now()}-${Math.random().toString(36).slice(2,15)}`},z=()=>{try{let e=new URL(globalThis.window.location.href);e.searchParams.delete(s),globalThis.window.history.replaceState(null,"",e.toString())}catch{}},L=()=>{let e=E();return e?{retryAttempt:e.retryAttempt,retryId:e.retryId}:{}},D=()=>void 0!==globalThis.window&&!0===globalThis.window[m],U=e=>{let t=(S().errors?.ignore??[]).filter(e=>""!==e);return 0!==t.length&&e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},_=e=>{let t=[...S().errors?.forceRetry??[],k].filter(e=>""!==e);return e.filter(e=>"string"==typeof e).some(e=>t.some(t=>e.includes(t)))},C=e=>{if((e=>U([e.errorMessage,e.eventMessage]))(e))return;let t=S();if(!t.reportBeacon?.endpoint)return void f()?.noBeaconEndpoint();let r=t.appName?{...e,appName:t.appName}:e,a=JSON.stringify(r);("function"!=typeof globalThis.window?.navigator?.sendBeacon||!globalThis.window.navigator.sendBeacon(t.reportBeacon.endpoint,a))&&"function"==typeof fetch&&fetch(t.reportBeacon.endpoint,{body:a,keepalive:!0,method:"POST"}).catch(e=>{f()?.beaconSendFailed(e)})};globalThis.window&&!globalThis.window[c]&&(globalThis.window[c]={scheduled:!1});var j=(e,t)=>{if(D())return void f()?.fallbackAlreadyShown(e);let r=void 0===globalThis.window?{scheduled:!1}:globalThis.window[c]??(globalThis.window[c]={scheduled:!1});if(r.scheduled)f()?.reloadAlreadyScheduled(e);else{r.scheduled=!0;try{let a,n=S(),o=n.reloadDelays??[1e3,2e3,5e3],l=n.useRetryId??!0,c=n.enableRetryReset??!0,y=n.minTimeBetweenResets??5e3;if(l)a=E();else{let e=(()=>{try{let e=new URLSearchParams(globalThis.window.location.search).get(s);if(e){let t=parseInt(e,10);return Number.isNaN(t)||t<-1?null:t}return null}catch{return null}})();a=null===e?null:{retryAttempt:e,retryId:x()}}let u=a?a.retryAttempt:0,m=a?.retryId??x();f()?.retryCycleStarting(m,u);let g=p.defaultRetryEnabled;if(h({error:e,isRetrying:g&&u>=0&&u<o.length,name:"chunk-error"}),!g)return void(r.scheduled=!1);if(c&&a&&a.retryAttempt>0&&((e,t,r=5e3)=>{if(0===e.retryAttempt)return!1;let a=A();if(!a||a.retryId!==e.retryId)return!1;let n=(()=>{if($())try{let e=sessionStorage.getItem(R);if(e)return JSON.parse(e)}catch{try{sessionStorage.removeItem(R)}catch{}return I().resetInfo}return I().resetInfo})();return!(n&&Date.now()-n.timestamp<r)&&Date.now()-a.timestamp>(t[a.attemptNumber-1]??1e3)+3e4})(a,o,y)){let t=A(),r=t?Date.now()-t.timestamp:0;N(),(()=>{if($())try{sessionStorage.removeItem(T)}catch{}I().storage=null})(),(e=>{let t={previousRetryId:e,timestamp:Date.now()};if($())try{sessionStorage.setItem(R,JSON.stringify(t))}catch{I().resetInfo=t}else I().resetInfo=t})(a.retryId);let n=e+"";h({name:"retry-reset",previousAttempt:a.retryAttempt,previousRetryId:a.retryId,timeSinceReload:r},{silent:U([n])}),u=0,m=x()}if(-1===u)return U([e+""])||f()?.fallbackAlreadyShown(e),r.scheduled=!1,void M();if(u>=o.length){let t=e+"";return h({finalAttempt:u,name:"retry-exhausted",retryId:a?.retryId??""},{silent:U([t])}),C({errorMessage:"Exceeded maximum reload attempts",eventName:"chunk_error_max_reloads",retryAttempt:u,retryId:a?.retryId,serialized:JSON.stringify({error:e+"",retryAttempt:u,retryId:a?.retryId})}),l||z(),r.scheduled=!1,void M()}let w=u+1,b=o[u]??1e3;h({attempt:w,delay:b,name:"retry-attempt",retryId:m},{silent:U([e+""])}),f()?.retrySchedulingReload(m,w,b),P(w),setTimeout(()=>{let e;if(l&&c&&((e,t)=>{let r={attemptNumber:t,retryId:e,timestamp:Date.now()};if($())try{sessionStorage.setItem(T,JSON.stringify(r))}catch{I().storage=r}else I().storage=r})(m,w),e=l?((e,t)=>{let r=new URL(globalThis.window.location.href);return r.searchParams.set(i,e),r.searchParams.set(s,t+""),r.toString()})(m,w):(e=>{let t=new URL(globalThis.window.location.href);return t.searchParams.set(s,e+""),t.toString()})(w),t?.cacheBust){let t=new URL(e);t.searchParams.set(d,Date.now()+""),e=t.toString()}globalThis.window.location.href=e},b)}catch{r.scheduled=!1}}},P=e=>{let t=S(),r=t.html?.loading?.content,a=t.html?.fallback?.selector??"body";if(r)try{let n=document.querySelector(a);if(!n)return;let o=document.createElement("div");o.innerHTML=r;let l=o.querySelector("[data-spa-guard-spinner]");l&&(t.html?.spinner?.disabled?l.remove():t.html?.spinner?.content&&(l.innerHTML=t.html.spinner.content));let i=o.querySelector('[data-spa-guard-section="retrying"]');i&&(i.style.display="block");let s=o.querySelector('[data-spa-guard-content="attempt"]');s&&(s.textContent=e+"");let d=b();d&&w(o,d),n.innerHTML=o.innerHTML}catch{}},M=()=>{if(D())return;void 0!==globalThis.window&&(globalThis.window[m]=!0);let e=S(),t=e.html?.fallback?.content,r=e.html?.fallback?.selector??"body";if(t)try{let a=document.querySelector(r);if(!a)return void f()?.fallbackTargetNotFound(r);let n=document.createElement("div");n.innerHTML=t;let o=b();o&&w(n,o),a.innerHTML=n.innerHTML;let l=e.useRetryId??!0,i=E();i&&-1===i.retryAttempt?(f()?.clearingRetryState(),N()):!l&&!i&&z();let s=a.querySelector('[data-spa-guard-action="reload"]');if(s&&s.addEventListener("click",()=>location.reload()),i){let e=document.getElementsByClassName("spa-guard-retry-id");for(let t of e)t.textContent=i.retryId}h({name:"fallback-ui-shown"})}catch(e){f()?.fallbackInjectFailed(e)}else f()?.noFallbackConfigured()},B=e=>{let t=F(e);return!!t&&[/Failed to fetch dynamically imported module/i,/Importing a module script failed/i,/error loading dynamically imported module/i,/Unable to preload CSS/i,/Loading chunk \d+ failed/i,/Loading CSS chunk \d+ failed/i,/ChunkLoadError/i].some(e=>e.test(t))},F=e=>e instanceof Error?e.message:"string"==typeof e?e:e&&"object"==typeof e&&"message"in e?e.message+"":e&&"object"==typeof e&&"reason"in e?F(e.reason):null,O=e=>{if(null==e)return{type:"null",value:e};if("object"!=typeof e)return{type:typeof e,value:e};if(e instanceof Error)return{message:e.message,name:e.name,stack:e.stack,type:"Error",...H(e)};if("reason"in e&&"promise"in e)return{reason:O(e.reason),type:"PromiseRejectionEvent"};if("error"in e&&"message"in e&&"filename"in e)return{colno:e.colno,error:O(e.error),filename:e.filename,lineno:e.lineno,message:e.message,type:"ErrorEvent"};if("violatedDirective"in e&&"blockedURI"in e){let t=e;return{blockedURI:t.blockedURI,columnNumber:t.columnNumber,effectiveDirective:t.effectiveDirective,lineNumber:t.lineNumber,originalPolicy:t.originalPolicy,sourceFile:t.sourceFile,type:"SecurityPolicyViolationEvent",violatedDirective:t.violatedDirective}}if("type"in e&&"target"in e){let t=e;return{eventType:t.type,target:V(t.target),timeStamp:t.timeStamp,type:"Event"}}return{type:"object",value:q(e)}},H=e=>{let t={};for(let r of Object.getOwnPropertyNames(e))if(!["message","name","stack"].includes(r))try{t[r]=e[r]}catch{}return t},V=e=>e?e instanceof HTMLElement?{className:e.className,href:e.href,id:e.id,src:e.src,tagName:e.tagName}:{type:e+""}:null,q=e=>{let t={};for(let r of Object.keys(e))try{let a=e[r];t[r]="object"==typeof a?a+"":a}catch{}return t},J=/[-._][a-zA-Z0-9]{6,}\.(js|mjs|css)$/i,G=e=>{try{let t=new URL(e).pathname;return J.test(t)}catch{return J.test(e)}},Y=()=>void 0===globalThis.window?{failedAssets:new Set,recoveryTimer:null}:(globalThis.window[u]||(globalThis.window[u]={failedAssets:new Set,recoveryTimer:null}),globalThis.window[u]),K="[spa-guard]",W={"chunk-error":"error","fallback-ui-shown":"warn","lazy-retry-attempt":"warn","lazy-retry-exhausted":"error","lazy-retry-start":"log","lazy-retry-success":"log","retry-attempt":"warn","retry-exhausted":"error","retry-reset":"log","static-asset-load-failed":"error"};((e,t)=>{if(p.initialized)return;t&&(e=>{void 0!==globalThis.window&&(globalThis.window[l]=e)})(t),p.initialized=!0,void 0!==globalThis.window&&(globalThis.window[o]=!0);let r=S(),a=r.reloadDelays??[],n=E();if(n&&n.retryAttempt>=a.length&&(f()?.retryLimitExceeded(n.retryAttempt,a.length),(e=>{try{let t=new URL(globalThis.window.location.href);t.searchParams.set(i,e),t.searchParams.set(s,"-1"),globalThis.window.history.replaceState(null,"",t.toString())}catch{}})(n.retryId)),n&&(n.retryAttempt>=a.length||-1===n.retryAttempt)){let e=()=>{-1===E()?.retryAttempt&&N()};"complete"===globalThis.window.document?.readyState?e():globalThis.window.addEventListener("load",e,{once:!0})}let d=globalThis.window.addEventListener.bind(globalThis.window);d("error",t=>{let a=(e=>{let t=e.target;return t instanceof HTMLScriptElement?t.src:t instanceof HTMLLinkElement?t.href:""})(t);if((e=>{let t=e.target;return t instanceof HTMLScriptElement?G(t.src):t instanceof HTMLLinkElement&&G(t.href)})(t)&&(e=>void 0!==e?(e=>{if(typeof performance>"u"||"function"!=typeof performance.getEntriesByName)return!0;let t=performance.getEntriesByName(e,"resource");if(0===t.length)return!0;let r=t.at(-1);return r.responseStatus>=400||0===r.transferSize&&0===r.decodedBodySize})(e):(typeof performance>"u"?0:performance.now())>3e4)(a)){if(U([a,t.message]))return;return t.preventDefault(),h({name:"static-asset-load-failed",url:a}),void(!1!==r.staticAssets?.autoRecover&&(e=>{if(void 0===globalThis.window||D())return;let t=Y();if(t.failedAssets.add(e),null!==t.recoveryTimer)return;let r=S().staticAssets?.recoveryDelay??500;t.recoveryTimer=setTimeout(()=>{let e=Y();e.recoveryTimer=null;let t=[...e.failedAssets];if(e.failedAssets=new Set,D())return;let r=Error("Static asset load failed: "+t.join(", "));j(r,{cacheBust:!0})},r)})(a))}if(U([t.message]))return;if(f()?.capturedError("error",t),B(t))return t.preventDefault(),void j(t.error??t);if(_([t.message]))return t.preventDefault(),void j(t.error??t);let n=e(t);C({errorMessage:t.message,eventName:"error",serialized:n,...L()})},!0),d("unhandledrejection",t=>{let a=t.reason+"";if(U([a]))return;if(f()?.capturedError("unhandledrejection",t),B(t.reason))return t.preventDefault(),void j(t.reason);if(_([a]))return t.preventDefault(),void j(t.reason);let n=r.handleUnhandledRejections;if(!1!==n?.sendBeacon){let r=e(t);C({errorMessage:a,eventName:"unhandledrejection",serialized:r,...L()})}!1!==n?.retry&&(t.preventDefault(),j(t.reason))}),d("securitypolicyviolation",t=>{let r=`${t.violatedDirective}: ${t.blockedURI}`;if(U([r]))return;f()?.capturedError("csp",t.blockedURI,t.violatedDirective);let a=e(t);C({eventMessage:r,eventName:"securitypolicyviolation",serialized:a,...L()})}),d("vite:preloadError",e=>{U([e?.payload?.message||e?.message])||(f()?.capturedError("vite:preloadError",e),e.preventDefault(),j(e?.payload??e))})})(e=>{try{let t=O(e);return JSON.stringify(t,null,2)}catch{return JSON.stringify({error:"Failed to serialize error",fallback:e+""})}},{beaconSendFailed(e){console.error(K+" Failed to send beacon:",e)},capturedError(e,...t){console.error(`${K} ${e}:capture:`,...t)},clearingRetryState(){console.log(K+" Clearing retry state from URL to allow clean reload attempt")},error(e,...t){console.error(`${K} ${e}`,...t)},fallbackAlreadyShown(e){console.error(K+" Fallback UI was already shown. Not retrying to prevent infinite loop.",e)},fallbackInjectFailed(e){console.error(K+" Failed to inject fallback UI",e)},fallbackTargetNotFound(e){console.error(`${K} Target element not found for selector: ${e}`)},log(e,...t){console.log(`${K} ${e}`,...t)},logEvent(e){let t=W[e.name],r=(e=>{switch(e.name){case"chunk-error":return`${K} chunk-error: isRetrying=${e.isRetrying}`;case"fallback-ui-shown":return K+" fallback-ui-shown";case"lazy-retry-attempt":return`${K} lazy-retry-attempt: attempt ${e.attempt}/${e.totalAttempts}, delay ${e.delay}ms`;case"lazy-retry-exhausted":return`${K} lazy-retry-exhausted: ${e.totalAttempts} attempts, willReload=${e.willReload}`;case"lazy-retry-start":return`${K} lazy-retry-start: totalAttempts=${e.totalAttempts}`;case"lazy-retry-success":{let t=void 0===e.totalTime?"":`, totalTime=${e.totalTime}ms`;return`${K} lazy-retry-success: succeeded on attempt ${e.attempt}${t}`}case"retry-attempt":return`${K} retry-attempt: attempt ${e.attempt} in ${e.delay}ms (retryId: ${e.retryId})`;case"retry-exhausted":return`${K} retry-exhausted: finalAttempt=${e.finalAttempt} (retryId: ${e.retryId})`;case"retry-reset":return`${K} retry-reset: ${e.timeSinceReload}ms since last reload (retryId: ${e.previousRetryId})`;case"static-asset-load-failed":return`${K} static-asset-load-failed: ${e.url}`}})(e);"chunk-error"===e.name||"lazy-retry-attempt"===e.name||"lazy-retry-exhausted"===e.name?console[t](r,e.error):console[t](r)},noBeaconEndpoint(){console.warn(K+" Report endpoint is not configured")},noFallbackConfigured(){console.error(K+" No fallback UI configured")},reloadAlreadyScheduled(e){console.log(K+" Reload already scheduled, ignoring duplicate chunk error:",e)},retryCycleStarting(e,t){console.log(`${K} Retry cycle starting: retryId=${e}, fromAttempt=${t}`)},retryLimitExceeded(e,t){console.log(`${K} Retry limit exceeded (${e}/${t}), marking as fallback shown`)},retrySchedulingReload(e,t,r){console.log(`${K} Scheduling reload: retryId=${e}, attempt=${t}, delay=${r}ms`)},updatedRetryAttempt(e){console.log(`${K} Updated retry attempt to ${e} in URL for fallback UI`)},versionChangeDetected(e,t){console.warn(`${K} New version available (${e??"unknown"} → ${t}). Please refresh to get the latest version.`)},versionCheckAlreadyRunning(){console.warn(K+" Version check already running")},versionCheckDisabled(){console.warn(K+" Version checking disabled: no version configured")},versionCheckFailed(e){console.error(K+" Version check failed",e)},versionCheckHttpError(e){console.warn(`${K} Version check HTTP error: ${e}`)},versionCheckParseError(){console.warn(K+" Failed to parse version from HTML")},versionCheckPaused(){console.log(K+" Version check paused (tab hidden)")},versionCheckRequiresEndpoint(){console.warn(K+" JSON version check mode requires endpoint")},versionCheckResumed(){console.log(K+" Version check resumed (tab visible)")},versionCheckResumedImmediate(){console.log(K+" Version check resumed with immediate check (tab visible, interval elapsed)")},versionCheckStarted(e,t,r){console.log(`${K} Starting version check (mode: ${e}, interval: ${t}ms, current: ${r})`)},versionCheckStopped(){console.log(K+" Version check stopped")},warn(e,...t){console.warn(`${K} ${e}`,...t)}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovineko/spa-guard-node",
3
- "version": "0.0.1-alpha-28",
3
+ "version": "0.0.1-alpha-29",
4
4
  "description": "Server-side HTML cache with ETag/304, pre-compression, and i18n for spa-guard",
5
5
  "keywords": [
6
6
  "spa",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "peerDependencies": {
49
49
  "parse5": "^8",
50
- "@ovineko/spa-guard": "0.0.1-alpha-28"
50
+ "@ovineko/spa-guard": "0.0.1-alpha-29"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22.15.0"