// @bun
var{defineProperty:I,getOwnPropertyNames:X,getOwnPropertyDescriptor:Y}=Object,Z=Object.prototype.hasOwnProperty;function _(j){return this[j]}var C=(j)=>{var q=(L??=new WeakMap).get(j),z;if(q)return q;if(q=I({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var G of X(j))if(!Z.call(q,G))I(q,G,{get:_.bind(j,G),enumerable:!(z=Y(j,G))||z.enumerable})}return L.set(j,q),q},L;var $=(j)=>j;function v(j,q){this[j]=$.bind(null,q)}var E=(j,q)=>{for(var z in q)I(j,z,{get:q[z],enumerable:!0,configurable:!0,set:v.bind(q,z)})};var M=(j,q)=>()=>(j&&(q=j(j=0)),q);var W=import.meta.require;function O(j){let q={"cache-first":{className:"CacheFirst",importFrom:"workbox-strategies"},"network-first":{className:"NetworkFirst",importFrom:"workbox-strategies"},"stale-while-revalidate":{className:"StaleWhileRevalidate",importFrom:"workbox-strategies"},"network-only":{className:"NetworkOnly",importFrom:"workbox-strategies"},"cache-only":{className:"CacheOnly",importFrom:"workbox-strategies"}};return q[j]||q["network-first"]}function F(j){return O(j).className}function d(j){return{className:"ExpirationPlugin",importFrom:"workbox-expiration",options:{...j.maxEntries&&{maxEntries:j.maxEntries},...j.maxAgeSeconds&&{maxAgeSeconds:j.maxAgeSeconds},...j.purgeOnQuotaError!==void 0&&{purgeOnQuotaError:j.purgeOnQuotaError}}}}function A(j){return{className:"CacheableResponsePlugin",importFrom:"workbox-cacheable-response",options:{...j.statuses&&{statuses:j.statuses},...j.headers&&{headers:j.headers}}}}function b(j){return{className:"BackgroundSyncPlugin",importFrom:"workbox-background-sync",options:{name:j.name,...j.maxRetentionTime&&{maxRetentionTime:j.maxRetentionTime},...j.forceSyncFallback!==void 0&&{forceSyncFallback:j.forceSyncFallback}}}}function N(j){let q=O(j.strategy),z=[];if(j.maxAgeSeconds||j.maxEntries)z.push(d({maxAgeSeconds:j.maxAgeSeconds,maxEntries:j.maxEntries,purgeOnQuotaError:!0}));if(j.strategy==="network-first"||j.strategy==="stale-while-revalidate")z.push(A({statuses:[0,200]}));return{urlPattern:j.pattern,handler:q.className,options:{cacheName:j.cacheName,...z.length>0&&{plugins:z}}}}function f(j){return j.map((q)=>N(q))}function m(j){let q=j.pwa;if(!q?.enabled)return"";let z=q.routes||[],G=q.cacheStorage,J=[];for(let B of z){let Q=F(B.strategy),H=[];if(B.maxAgeSeconds||B.maxEntries||G?.maxEntries){let V=B.maxEntries||G?.maxEntries||100,K=B.maxAgeSeconds||(G?.maxAge?G.maxAge*24*60*60:void 0);H.push(`new ExpirationPlugin({
      maxEntries: ${V},
      ${K?`maxAgeSeconds: ${K},`:""}
      purgeOnQuotaError: true,
    })`)}if(B.strategy==="network-first"||B.strategy==="stale-while-revalidate")H.push(`new CacheableResponsePlugin({
      statuses: [0, 200],
    })`);let U=P(B.pattern);J.push(`
// ${B.pattern}
registerRoute(
  ${U},
  new ${Q}({
    cacheName: '${B.cacheName||T(B.pattern)}',
    ${H.length>0?`plugins: [
      ${H.join(`,
      `)}
    ],`:""}
  })
);`)}return J.join(`
`)}function P(j){if(j.startsWith("*.")){let q=j.slice(2);return`({ request }) => request.destination === '${R(q)}'`}if(j.endsWith("/**"))return`({ url }) => url.pathname.startsWith('${j.slice(0,-3)}')`;if(j.endsWith("/*")){let q=j.slice(0,-2);return`({ url }) => url.pathname.startsWith('${q}') && !url.pathname.slice(${q.length+1}).includes('/')`}if(j.includes("*")&&!j.startsWith("*")){let[q,z]=j.split("*");return`({ url }) => url.pathname.startsWith('${q}') && url.pathname.endsWith('${z}')`}if(j==="/"||!j.includes("*"))return`({ url }) => url.pathname === '${j}'`;return`new RegExp('${w(j).replace(/\\\*/g,".*")}')`}function R(j){return{js:"script",mjs:"script",css:"style",html:"document",htm:"document",png:"image",jpg:"image",jpeg:"image",gif:"image",svg:"image",webp:"image",avif:"image",ico:"image",woff:"font",woff2:"font",ttf:"font",eot:"font",otf:"font"}[j.toLowerCase()]||"empty"}function T(j){return"stx-"+j.replace(/[^\w]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").toLowerCase().slice(0,30)+"-cache"}function w(j){return j.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}export{O as mapStrategyToWorkbox,F as getWorkboxStrategyName,m as generateRuntimeCachingCode,f as generateRuntimeCaching,P as generatePatternMatcher,d as createExpirationPlugin,A as createCacheableResponsePlugin,b as createBackgroundSyncPlugin,N as convertRouteToWorkbox};
