(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>b,buildMemoryStorage:()=>v,buildStorage:()=>w,buildWebStorage:()=>C,canStale:()=>p,createCacheResponse:()=>d,createValidateStatus:()=>o,defaultHeaderInterpreter:()=>n,defaultKeyGenerator:()=>I,defaultRequestInterceptor:()=>u,defaultResponseInterceptor:()=>g,isExpired:()=>m,isMethodIn:()=>s,isStorage:()=>h,setupCache:()=>x,testCachePredicate:()=>f,updateCache:()=>l,updateStaleRequest:()=>c});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),n=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:n,noStore:i,mustRevalidate:o,maxAge:s,immutable:c}=(0,a.parse)(String(t));if(n||i)return"dont cache";if(c)return 31536e6;if(o)return 0;if(void 0!==s){const t=e[r.Age];return t?1e3*(s-Number(t)):1e3*s}}const n=e[r.Expires];if(n){const e=Date.parse(String(n))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"},i=require("fast-defer");function o(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function s(e="get",t=[]){return e=e.toLowerCase(),t.some((t=>t===e))}function c(e,t){var a;t.headers||(t.headers={});const{etag:n,modifiedSince:i}=t.cache;if(n){const i=!0===n?null===(a=e.data)||void 0===a?void 0:a.headers[r.ETag]:n;i&&(t.headers[r.IfNoneMatch]=i)}i&&(t.headers[r.IfModifiedSince]=!0===i?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())}function d(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function u(e){const t=async t=>{var a;const r=t.id=e.generateKey(t);if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!s(t.method,t.cache.methods))return t;let n,d=await e.storage.get(r,t);e:if("empty"===d.state||"stale"===d.state){if(e.waiting[r]&&(d=await e.storage.get(r,t),"empty"!==d.state)){0;break e}return e.waiting[r]=(0,i.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:d.state,data:d.data,createdAt:d.createdAt},t),"stale"===d.state&&c(d,t),t.validateStatus=o(t.validateStatus),t}if("loading"===d.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r,t),t;0;try{n=await a}catch(e){return t}}else n=d.data;return t.adapter=()=>Promise.resolve({config:t,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function f(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:n,containsHeaders:i}=t;if(r&&!await r(e.status)||n&&!await n(e))return!1;if(i)for(const[t,r]of Object.entries(i))if(!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1;return!0}async function l(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r,t.config);continue}const i=await e.get(r,t.config);if("loading"===i.state)continue;const o=await n(i,t);"delete"!==o?"ignore"!==o&&await e.set(r,o,t.config):await e.remove(r,t.config)}}function g(e){const t=async(t,a)=>{var r;await e.storage.remove(t,a),null===(r=e.waiting[t])||void 0===r||r.reject(),delete e.waiting[t]},a=async a=>{var n,i,o;const s=a.id=null!==(n=(o=a.config).id)&&void 0!==n?n:o.id=e.generateKey(a.config);if(null!==(i=a.cached)&&void 0!==i||(a.cached=!1),a.cached)return a;const c=a.config.cache;if(!c)return Object.assign(Object.assign({},a),{cached:!1});const u=a.config,g=await e.storage.get(s,u);if("loading"!==g.state)return a;if(!g.data&&!await f(a,c.cachePredicate))return await t(s,u),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];c.etag&&!0!==c.etag&&(a.headers[r.XAxiosCacheEtag]=c.etag),c.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===c.modifiedSince?"use-cache-timestamp":c.modifiedSince.toUTCString());let h=c.ttl||-1;if(null==c?void 0:c.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(s,u),a;h="not enough headers"===r?h:r}const p=d(a,g.data);"function"==typeof h&&(h=await h(a)),c.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(h)),(null==c?void 0:c.update)&&await l(e.storage,a,c.update);const m={state:"cached",ttl:h,createdAt:Date.now(),data:p},w=e.waiting[s];return w&&(w.resolve(m.data),delete e.waiting[s]),await e.storage.set(s,m,u),a},n=async a=>{var r;const n=a.config;if(!(null==n?void 0:n.cache)||!n.id)throw a;const i=await e.storage.get(n.id,n),o=n.cache;if("loading"!==i.state||"stale"!==i.previous)throw await t(n.id,n),a;if(null==o?void 0:o.staleIfError){const t="function"==typeof o.staleIfError?await o.staleIfError(a.response,i,a):o.staleIfError;if(!0===t||"number"==typeof t&&i.createdAt+t>Date.now())return null===(r=e.waiting[n.id])||void 0===r||r.resolve(i.data),delete e.waiting[n.id],await e.storage.set(n.id,{state:"stale",createdAt:Date.now(),data:i.data},n),{cached:!0,config:n,id:n.id,data:i.data.data,headers:i.data.headers,status:i.data.status,statusText:i.data.statusText}}throw a};return{onFulfilled:a,onRejected:n,apply:()=>e.interceptors.response.use(a,n)}}const h=e=>!!e&&!!e["is-storage"];function p(e){const t=e.data.headers;return r.ETag in t||r.LastModified in t||r.XAxiosCacheEtag in t||r.XAxiosCacheStaleIfError in t||r.XAxiosCacheLastModified in t}function m(e){return e.createdAt+e.ttl<=Date.now()}function w({set:e,find:t,remove:a}){return{"is-storage":1,set:e,remove:a,get:async(r,n)=>{const i=await t(r,n);if(!i)return{state:"empty"};if("cached"!==i.state||!m(i))return i;if(p(i)){const t={state:"stale",createdAt:i.createdAt,data:i.data};return await e(r,t,n),t}return await a(r,n),{state:"empty"}}}}function v(e=!1){const t=w({set:(e,a)=>{t.data[e]=a},remove:e=>{delete t.data[e]},find:a=>{const r=t.data[a];return e&&void 0!==r?"function"==typeof structuredClone?structuredClone(r):JSON.parse(JSON.stringify(r)):r}});return t.data=Object.create(null),t}const y=require("object-code"),S=/^\/|\/$/g;function b(e){return t=>{if(t.id)return t.id;const a=e(t);return"string"==typeof a||"number"==typeof a?`${a}`:`${(0,y.hash)(a)}`}}const I=b((({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>(e&&(e=e.replace(S,"")),t&&(t=t.replace(S,"")),a&&(a=a.toLowerCase()),{url:e+(e&&t?"/":"")+t,params:r,method:a,data:n})));function x(e,t={}){var a,r,i,o,s;const c=e;if(c.storage=t.storage||v(),!h(c.storage))throw new Error("Use buildStorage() function");return c.waiting=t.waiting||{},c.generateKey=t.generateKey||I,c.headerInterpreter=t.headerInterpreter||n,c.requestInterceptor=t.requestInterceptor||u(c),c.responseInterceptor=t.responseInterceptor||g(c),c.debug=t.debug,c.defaults.cache={update:t.update||{},ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null===(r=t.etag)||void 0===r||r,modifiedSince:null!==(i=t.modifiedSince)&&void 0!==i?i:!1===t.etag,interpretHeader:null===(o=t.interpretHeader)||void 0===o||o,staleIfError:null===(s=t.staleIfError)||void 0===s||s},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function C(e,t=""){return w({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},remove:a=>{e.removeItem(t+a)},set:(a,r)=>{const n=()=>e.setItem(t+a,JSON.stringify(r));try{return n()}catch(r){const i=Object.entries(e).filter((e=>e[0].startsWith(t))).map((e=>[e[0],JSON.parse(e[1])]));for(const t of i)"cached"===t[1].state&&m(t[1])&&!p(t[1])&&e.removeItem(t[0]);try{return n()}catch(t){const a=i.sort(((e,t)=>(e[1].createdAt||0)-(t[1].createdAt||0)));for(const t of a){e.removeItem(t[0]);try{return n()}catch(e){}}}e.removeItem(t+a)}}})}module.exports=t})();