/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/axios-etag-cache@1.4.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";function __awaiter(e,t,a,s){return new(a||(a=Promise))((function(c,o){function n(e){try{i(s.next(e))}catch(e){o(e)}}function r(e){try{i(s.throw(e))}catch(e){o(e)}}function i(e){var t;e.done?c(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(n,r)}i((s=s.apply(e,t||[])).next())}))}Object.defineProperty(exports,"__esModule",{value:!0});const byLowerCase=e=>t=>toLowerCase(t)===e,toLowerCase=e=>e.toLowerCase(),getKeys=e=>Object.keys(e),getHeaderCaseInsensitive=(e,t={})=>{const a=getKeys(t).find(byLowerCase(e));return a?t[a]:void 0},cyrb53=(e,t=0)=>{let a=3735928559^t,s=1103547991^t;for(let t,c=0;c<e.length;c++)t=e.charCodeAt(c),a=Math.imul(a^t,2654435761),s=Math.imul(s^t,1597334677);return a=Math.imul(a^a>>>16,2246822507)^Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507)^Math.imul(a^a>>>13,3266489909),4294967296*(2097151&s)+(a>>>0)};class BaseCache{}class DefaultCache extends BaseCache{constructor(){super(...arguments),this.cache={}}get(e){return Promise.resolve(this.cache[e])}set(e,t){this.cache[e]=t}flushAll(){this.cache={}}}class LocalStorageCache extends BaseCache{flushAll(){for(let e=0;e<localStorage.length;e++){const t=localStorage.key(e);null!==t&&t.startsWith("aec-")&&localStorage.removeItem(t)}}get(e){return new Promise((t=>{try{const a=localStorage.getItem("aec-"+e);t(null!==a?JSON.parse(a):void 0)}catch(e){t(void 0)}}))}set(e,t){try{const a=JSON.stringify(t);localStorage.setItem("aec-"+e,a)}catch(e){console.log(e)}}}let instance,cache;const makeSingleton=e=>(cache=new e,{get(e){return __awaiter(this,void 0,void 0,(function*(){let t=yield cache.get(e);return t&&(t=Object.assign(Object.assign({},t),{lastHitAt:Date.now()}),cache.set(e,t)),t}))},set:(e,t,a)=>cache.set(e,{etag:t,value:a,createdAt:Date.now(),lastHitAt:0}),reset(){cache.flushAll()}}),getCacheInstance=e=>instance||(instance=makeSingleton(e),instance);let Cache,cacheableMethods=["GET","HEAD"];function isCacheableMethod(e){return!!e.method&&~cacheableMethods.indexOf(e.method.toUpperCase())}function getUrlByAxiosConfig(e){return e.url}const getCacheByAxiosConfig=e=>__awaiter(void 0,void 0,void 0,(function*(){const t=getUrlByAxiosConfig(e);if(t){if(e.data){const a=cyrb53(e.data);return yield Cache.get(a+t)}return yield Cache.get(t)}}));function requestInterceptor(e){return new Promise(((t,a)=>__awaiter(this,void 0,void 0,(function*(){if(isCacheableMethod(e)){const t=getUrlByAxiosConfig(e);if(!t)return void a(e);let s;if(e.data)try{const a=cyrb53(JSON.stringify(e.data));s=yield Cache.get(a+t)}catch(e){console.error(e)}else s=yield Cache.get(t);s&&(e.headers=Object.assign(Object.assign({},e.headers),{"If-None-Match":s.etag}))}t(e)}))))}function responseInterceptor(e){return new Promise(((t,a)=>{if(isCacheableMethod(e.config)){const t=getHeaderCaseInsensitive("etag",e.headers);if(t){const s=getUrlByAxiosConfig(e.config);if(!s)return void a(null);if(e.config.data)try{const a=cyrb53(e.config.data);Cache.set(a+s,t,e.data)}catch(e){console.error(e)}else Cache.set(s,t,e.data)}}t(e)}))}function responseErrorInterceptor(e){return new Promise(((t,a)=>__awaiter(this,void 0,void 0,(function*(){if(e.response&&304===e.response.status){const s=yield getCacheByAxiosConfig(e.response.config);if(!s)return void a(e);const c=e.response;return c.status=200,c.data=s.value,void t(c)}a(e)}))))}function resetCache(){return __awaiter(this,void 0,void 0,(function*(){yield Cache.reset()}))}function axiosETAGCache(e,t){return Cache=(null==t?void 0:t.cacheClass)?getCacheInstance(t.cacheClass):getCacheInstance(DefaultCache),!0===(null==t?void 0:t.enablePost)&&cacheableMethods.push("POST"),e.interceptors.request.use(requestInterceptor),e.interceptors.response.use(responseInterceptor,responseErrorInterceptor),e}exports.BaseCache=BaseCache,exports.DefaultCache=DefaultCache,exports.LocalStorageCache=LocalStorageCache,exports.axiosETAGCache=axiosETAGCache,exports.getCacheByAxiosConfig=getCacheByAxiosConfig,exports.getCacheInstance=getCacheInstance,exports.resetCache=resetCache;
//# sourceMappingURL=/sm/c3e32697d7584be5fa0d48557769637f014f91629dd51bf8bb94d3c8cf5742e2.map