shlink-web-client/dependabot/npm_and_yarn/workbox-routing-7.1.0/service-worker.js

3 lines
34 KiB
JavaScript
Raw Normal View History

try{self["workbox:core:7.0.0"]&&_()}catch{}const Y=(s,...e)=>{let t=s;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t},Z=Y;let u=class extends Error{constructor(e,t){const n=Z(e,t);super(n),this.name=e,this.details=t}};const ee=new Set,f={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:typeof registration<"u"?registration.scope:""},D=s=>[f.prefix,s,f.suffix].filter(e=>e&&e.length>0).join("-"),te=s=>{for(const e of Object.keys(f))s(e)},K={updateDetails:s=>{te(e=>{typeof s[e]=="string"&&(f[e]=s[e])})},getGoogleAnalyticsName:s=>s||D(f.googleAnalytics),getPrecacheName:s=>s||D(f.precache),getPrefix:()=>f.prefix,getRuntimeName:s=>s||D(f.runtime),getSuffix:()=>f.suffix};function q(s,e){const t=new URL(s);for(const n of e)t.searchParams.delete(n);return t.href}async function se(s,e,t,n){const a=q(e.url,t);if(e.url===a)return s.match(e,n);const i=Object.assign(Object.assign({},n),{ignoreSearch:!0}),r=await s.keys(e,i);for(const c of r){const o=q(c.url,t);if(a===o)return s.match(c,n)}}let y;function ne(){if(y===void 0){const s=new Response("");if("body"in s)try{new Response(s.body),y=!0}catch{y=!1}y=!1}return y}let ae=class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};async function re(){for(const s of ee)await s()}const ie=s=>new URL(String(s),location.href).href.replace(new RegExp(`^${location.origin}`),"");function ce(s){return new Promise(e=>setTimeout(e,s))}function $(s,e){const t=e();return s.waitUntil(t),t}async function oe(s,e){let t=null;if(s.url&&(t=new URL(s.url).origin),t!==self.location.origin)throw new u("cross-origin-copy-response",{origin:t});const n=s.clone(),a={headers:new Headers(n.headers),status:n.status,statusText:n.statusText},i=e?e(a):a,r=ne()?n.body:await n.blob();return new Response(r,i)}function le(){self.addEventListener("activate",()=>self.clients.claim())}try{self["workbox:core:7.0.0"]&&_()}catch{}const he=(s,...e)=>{let t=s;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t},ue=he;let fe=class extends Error{constructor(e,t){const n=ue(e,t);super(n),this.name=e,this.details=t}};function Q(s){s.then(()=>{})}const de=(s,e)=>e.some(t=>s instanceof t);let B,F;function pe(){return B||(B=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function ge(){return F||(F=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const J=new WeakMap,M=new WeakMap,z=new WeakMap,U=new WeakMap,S=new WeakMap;function me(s){const e=new Promise((t,n)=>{const a=()=>{s.removeEventListener("success",i),s.removeEventListener("error",r)},i=()=>{t(g(s.result)),a()},r=()=>{n(s.error),a()};s.addEventListener("success",i),s.addEventListener("error",r)});return e.then(t=>{t instanceof IDBCursor&&J.set(t,s)}).catch(()=>{}),S.set(e,s),e}function we(s){if(M.has(s))return;const e=new Promise((t,n)=>{const a=()=>{s.removeEventListener("complete",i),s.removeEventListener("error",r),s.removeEventListener("abort",r)},i=()=>{t(),a()},r=()=>{n(s.error||new DOMException("AbortError","AbortError")),a()};s.addEventListener("complete",i),s.addEventListener("error",r),s.addEventListener("abort",r)});M.set(s,e)}let I={get(s,e,t){if(s instanceof IDBTransaction){if(e==="done")return M.get(s);if(e==="objectStoreNames")return s.objectStoreNames||z.get(s);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return g(s[e])},set(s,e,t){return s[e]=t,!0},has(s,e){return s instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in s}};function ye(s){I=s(I)}function be(s){return s===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const n=s.call(L(this),e,...t);return z.set(n,e.sort?e.sort():[e]),g(n)}:ge().includes(s)?function(...e){return s.apply(L(this),e),g(J.get(this))}:function(...e){return g(s.apply(L(this),e))}}function _e(s){return typeof s=="function"?be(s):(s instanceof IDBTransaction&&we(s),de(s,pe())?new Proxy(s,I):s)}function g(s){if(s instanceof IDBRequest)return me(s);if(U.has(s))return U.get(s);const e=_e(s)
This is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(c)}}}install(e){return $(e,async()=>{const t=new Ie;this.strategy.plugins.push(t);for(const[i,r]of this._urlsToCacheKeys){const c=this._cacheKeysToIntegrities.get(r),o=this._urlsToCacheModes.get(i),l=new Request(i,{integrity:c,cache:o,credentials:"same-origin"});await Promise.all(this.strategy.handleAll({params:{cacheKey:r},request:l,event:e}))}const{updatedURLs:n,notUpdatedURLs:a}=t;return{updatedURLs:n,notUpdatedURLs:a}})}activate(e){return $(e,async()=>{const t=await self.caches.open(this.strategy.cacheName),n=await t.keys(),a=new Set(this._urlsToCacheKeys.values()),i=[];for(const r of n)a.has(r.url)||(await t.delete(r),i.push(r.url));return{deletedURLs:i}})}getURLsToCacheKeys(){return this._urlsToCacheKeys}getCachedURLs(){return[...this._urlsToCacheKeys.keys()]}getCacheKeyForURL(e){const t=new URL(e,location.href);return this._urlsToCacheKeys.get(t.href)}getIntegrityForCacheKey(e){return this._cacheKeysToIntegrities.get(e)}async matchPrecache(e){const t=e instanceof Request?e.url:e,n=this.getCacheKeyForURL(t);if(n)return(await self.caches.open(this.strategy.cacheName)).match(n)}createHandlerBoundToURL(e){const t=this.getCacheKeyForURL(e);if(!t)throw new u("non-precached-url",{url:e});return n=>(n.request=new Request(e),n.params=Object.assign({cacheKey:t},n.params),this.strategy.handle(n))}}let T;const A=()=>(T||(T=new je),T);try{self["workbox:routing:7.0.0"]&&_()}catch{}const X="GET",v=s=>s&&typeof s=="object"?s:{handle:s};class C{constructor(e,t,n=X){this.handler=v(t),this.match=e,this.method=n}setCatchHandler(e){this.catchHandler=v(e)}}class We extends C{constructor(e,t,n){const a=({url:i})=>{const r=e.exec(i.href);if(r&&!(i.origin!==location.origin&&r.index!==0))return r.slice(1)};super(a,t,n)}}class qe{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener("fetch",e=>{const{request:t}=e,n=this.handleRequest({request:t,event:e});n&&e.respondWith(n)})}addCacheListener(){self.addEventListener("message",e=>{if(e.data&&e.data.type==="CACHE_URLS"){const{payload:t}=e.data,n=Promise.all(t.urlsToCache.map(a=>{typeof a=="string"&&(a=[a]);const i=new Request(...a);return this.handleRequest({request:i,event:e})}));e.waitUntil(n),e.ports&&e.ports[0]&&n.then(()=>e.ports[0].postMessage(!0))}})}handleRequest({request:e,event:t}){const n=new URL(e.url,location.href);if(!n.protocol.startsWith("http"))return;const a=n.origin===location.origin,{params:i,route:r}=this.findMatchingRoute({event:t,request:e,sameOrigin:a,url:n});let c=r&&r.handler;const o=e.method;if(!c&&this._defaultHandlerMap.has(o)&&(c=this._defaultHandlerMap.get(o)),!c)return;let l;try{l=c.handle({url:n,request:e,event:t,params:i})}catch(h){l=Promise.reject(h)}const w=r&&r.catchHandler;return l instanceof Promise&&(this._catchHandler||w)&&(l=l.catch(async h=>{if(w)try{return await w.handle({url:n,request:e,event:t,params:i})}catch(W){W instanceof Error&&(h=W)}if(this._catchHandler)return this._catchHandler.handle({url:n,request:e,event:t});throw h})),l}findMatchingRoute({url:e,sameOrigin:t,request:n,event:a}){const i=this._routes.get(n.method)||[];for(const r of i){let c;const o=r.match({url:e,sameOrigin:t,request:n,event:a});if(o)return c=o,(Array.isArray(c)&&c.length===0||o.constructor===Object&&Object.keys(o).length===0||typeof o=="boolean")&&(c=void 0),{route:r,params:c}}return{}}setDefaultHandler(e,t=X){this._defaultHandlerMap.set(t,v(e))}setCatchHandler(e){this._catchHandler=v(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new u("unregister-route-but-not-found-with-method",{method:e.method});const t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new u("unregister-route-route-not-registered")}}let R;const $e=()=>(R||(R=new qe,R.addFetchListener(),R.addCacheListener()),R);function j(s,e,t){let n;if(typeof s=="string"){const i=ne