text: var __create = Object.create;
  var __defProp = Object.defineProperty;
  var __defProps = Object.defineProperties;
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  var __getOwnPropNames = Object.getOwnPropertyNames;
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  var __getProtoOf = Object.getPrototypeOf;
  var __hasOwnProp = Object.prototype.hasOwnProperty;
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  var __spreadValues = (a, b) => {
    for (var prop in b || (b = {}))
      if (__hasOwnProp.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    if (__getOwnPropSymbols)
      for (var prop of __getOwnPropSymbols(b)) {
        if (__propIsEnum.call(b, prop))
          __defNormalProp(a, prop, b[prop]);
      }
    return a;
  };
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
  var __export = (target, all) => {
    __markAsModule(target);
    for (var name in all)
      __defProp(target, name, { get: all[name], enumerable: true });
  };
  var __reExport = (target, module2, desc) => {
    if (module2 && typeof module2 === "object" || typeof module2 === "function") {
      for (let key of __getOwnPropNames(module2))
        if (!__hasOwnProp.call(target, key) && key !== "default")
          __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
    }
    return target;
  };
  var __toModule = (module2) => {
    return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
  };
  
  // src/index.ts
  __export(exports, {
    VitePWA: () => VitePWA,
    cachePreset: () => cachePreset
  });
  
  // node_modules/.pnpm/tsup@5.2.1_typescript@4.4.3/node_modules/tsup/assets/cjs_shims.js
  var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
  
  // src/index.ts
  var import_path5 = __toModule(require("path"));
  var import_fs4 = __toModule(require("fs"));
  
  // src/constants.ts
  var FILE_MANIFEST = "manifest.webmanifest";
  var FILE_SW_REGISTER = "registerSW.js";
  var VIRTUAL_MODULES_MAP = {
    "virtual:pwa-register": "register",
    "virtual:pwa-register/vue": "vue",
    "virtual:pwa-register/svelte": "svelte",
    "virtual:pwa-register/react": "react"
  };
  var VIRTUAL_MODULES_RESOLVE_PREFIX = "/@vite-plugin-pwa/";
  var VIRTUAL_MODULES = Object.keys(VIRTUAL_MODULES_MAP);
  
  // src/html.ts
  function generateSimpleSWRegister(options) {
    return `
  if('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
  navigator.serviceWorker.register('${options.base + options.filename}', { scope: '${options.scope}' })
  })
  }`.replace(/\n/g, "");
  }
  function injectServiceWorker(html, options) {
    const manifest = options.manifest ? `<link rel="manifest" href="${options.base + FILE_MANIFEST}">` : "";
    if (options.injectRegister === "inline") {
      return html.replace("</head>", `${manifest}<script>${generateSimpleSWRegister(options)}<\/script></head>`);
    }
    if (options.injectRegister === "script") {
      return html.replace("</head>", `${manifest}<script src="${options.base + FILE_SW_REGISTER}"><\/script></head>`);
    }
    return html.replace("</head>", `${manifest}</head>`);
  }
  
  // src/modules.ts
  var import_path2 = __toModule(require("path"));
  var import_fs = __toModule(require("fs"));
  var import_workbox_build = __toModule(require("workbox-build"));
  
  // src/log.ts
  var import_path = __toModule(require("path"));
  var import_chalk = __toModule(require("chalk"));
  
  // package.json
  var version = "0.11.3";
  
  // src/log.ts
  function logWorkboxResult(strategy, buildResult, viteOptions) {
    const { root, logLevel = "info" } = viteOptions;
    if (logLevel === "silent")
      return;
    const { count, size, filePaths, warnings } = buildResult;
    if (logLevel === "info") {
      console.info([
        "",
        `${(0, import_chalk.cyan)(`PWA v${version}`)}`,
        `mode      ${(0, import_chalk.magenta)(strategy)}`,
        `precache  ${(0, import_chalk.green)(`${count} entries`)} ${(0, import_chalk.dim)(`(${(size / 1024).toFixed(2)} KiB)`)}`,
        "files generated",
        ...filePaths.map((p) => `  ${(0, import_chalk.dim)((0, import_path.relative)(root, p))}`)
      ].join("\n"));
    }
    warnings && warnings.length > 0 && console.warn((0, import_chalk.yellow)([
      "warnings",
      ...warnings.map((w) => `  ${w}`),
      ""
    ].join("\n")));
  }
  
  // src/modules.ts
  async function generateRegisterSW(options, mode, source = "register") {
    const sw = options.base + options.filename;
    const scope = options.scope;
    const content = await import_fs.promises.readFile((0, import_path2.resolve)(__dirname, `client/${mode}/${source}.mjs`), "utf-8");
    return content.replace("__SW__", sw).replace("__SCOPE__", scope).replace("__SW_AUTO_UPDATE__", `${options.registerType === "autoUpdate"}`);
  }
  async function generateServiceWorker(options, viteOptions) {
    const buildResult = await (0, import_workbox_build.generateSW)(options.workbox);
    logWorkboxResult("generateSW", buildResult, viteOptions);
  }
  async function generateInjectManifest(options, viteOptions) {
    const rollup = require("rollup");
    const includedPluginNames = [
      "alias",
      "vite:resolve",
      "vite:esbuild",
      "replace",
      "vite:define",
      "rollup-plugin-dynamic-import-variables",
      "vite:esbuild-transpile",
      "vite:terser"
    ];
    const plugins = viteOptions.plugins.filter((p) => includedPluginNames.includes(p.name));
    const bundle = await rollup.rollup({
      input: options.swSrc,
      plugins
    });
    try {
      await bundle.write({
        format: "es",
        exports: "none",
        inlineDynamicImports: true,
        file: options.injectManifest.swDest,
        sourcemap: viteOptions.build.sourcemap
      });
    } finally {
      await bundle.close();
    }
    const injectManifestOptions = __spreadProps(__spreadValues({}, options.injectManifest), {
      swSrc: options.injectManifest.swDest
    });
    const buildResult = await (0, import_workbox_build.injectManifest)(injectManifestOptions);
    logWorkboxResult("injectManifest", buildResult, viteOptions);
  }
  
  // src/options.ts
  var import_fs3 = __toModule(require("fs"));
  var import_path4 = __toModule(require("path"));
  
  // src/assets.ts
  var import_path3 = __toModule(require("path"));
  var import_fs2 = __toModule(require("fs"));
  var import_crypto = __toModule(require("crypto"));
  var import_fast_glob = __toModule(require("fast-glob"));
  function buildManifestEntry(publicDir, url) {
    return new Promise((resolve4, reject) => {
      const cHash = import_crypto.default.createHash("MD5");
      const stream = import_fs2.default.createReadStream((0, import_path3.resolve)(publicDir, url));
      stream.on("error", (err) => {
        reject(err);
      });
      stream.on("data", (chunk) => {
        cHash.update(chunk);
      });
      stream.on("end", () => {
        return resolve4({
          url,
          revision: `${cHash.digest("hex")}`
        });
      });
    });
  }
  function lookupAdditionalManifestEntries(useInjectManifest, injectManifest2, workbox) {
    return useInjectManifest ? injectManifest2.additionalManifestEntries || [] : workbox.additionalManifestEntries || [];
  }
  async function configureStaticAssets(resolvedVitePWAOptions, viteConfig) {
    const {
      manifest,
      strategies,
      injectManifest: injectManifest2,
      workbox,
      includeAssets,
      includeManifestIcons
    } = resolvedVitePWAOptions;
    const useInjectManifest = strategies === "injectManifest";
    const { publicDir } = viteConfig;
    const globs = [];
    const manifestEntries = lookupAdditionalManifestEntries(useInjectManifest, injectManifest2, workbox);
    if (includeAssets) {
      if (Array.isArray(includeAssets))
        globs.push(...includeAssets);
      else
        globs.push(includeAssets);
    }
    if (includeManifestIcons && manifest && manifest.icons) {
      const icons = manifest.icons;
      Object.keys(icons).forEach((key) => {
        const icon = icons[key];
        globs.push(icon.src);
      });
    }
    if (globs.length > 0) {
      let assets = await (0, import_fast_glob.default)(globs.map((g) => {
        return g.startsWith("/") ? g.substring(1) : g;
      }), {
        cwd: publicDir,
        onlyFiles: true,
        unique: true
      });
      if (manifestEntries.length > 0) {
        const included = manifestEntries.map((me) => {
          if (typeof me === "string")
            return me;
          else
            return me.url;
        });
        assets = assets.filter((a) => !included.includes(a));
      }
      const assetsEntries = await Promise.all(assets.map((a) => {
        return buildManifestEntry(publicDir, a);
      }));
      manifestEntries.push(...assetsEntries);
    }
    if (manifest) {
      const cHash = import_crypto.default.createHash("MD5");
      cHash.update(generateWebManifestFile(resolvedVitePWAOptions));
      manifestEntries.push({
        url: FILE_MANIFEST,
        revision: `${cHash.digest("hex")}`
      });
    }
    if (manifestEntries.length > 0) {
      if (useInjectManifest)
        injectManifest2.additionalManifestEntries = manifestEntries;
      else
        workbox.additionalManifestEntries = manifestEntries;
    }
  }
  function generateWebManifestFile(options) {
    return `${JSON.stringify(options.manifest, null, options.minify ? 0 : 2)}
  `;
  }
  
  // src/utils.ts
  function resolveBathPath(base) {
    if (isAbsolute(base))
      return base;
    return !base.startsWith("/") && !base.startsWith("./") ? `/${base}` : base;
  }
  function isAbsolute(url) {
    return url.match(/^(?:[a-z]+:)?\/\//i);
  }
  
  // src/options.ts
  function resolveSwPaths(injectManifest2, root, srcDir, outDir, filename) {
    const swSrc = (0, import_path4.resolve)(root, srcDir, filename);
    if (injectManifest2 && (0, import_path4.extname)(filename) === ".ts" && import_fs3.default.existsSync(swSrc)) {
      const useFilename = `${filename.substring(0, filename.lastIndexOf("."))}.js`;
      return {
        swSrc,
        swDest: (0, import_path4.resolve)(root, outDir, useFilename),
        useFilename
      };
    }
    return {
      swSrc,
      swDest: (0, import_path4.resolve)(root, outDir, filename)
    };
  }
  async function resolveOptions(options, viteConfig) {
    var _a;
    const root = viteConfig.root;
    const pkg = import_fs3.default.existsSync("package.json") ? JSON.parse(import_fs3.default.readFileSync("package.json", "utf-8")) : {};
    const {
      mode = process["env"]["NODE_ENV"] || "production",
      srcDir = "public",
      outDir = viteConfig.build.outDir || "dist",
      injectRegister = "auto",
      registerType = "prompt",
      filename = "sw.js",
      strategies = "generateSW",
      minify = true,
      base = viteConfig.base,
      includeAssets = void 0,
      includeManifestIcons = true
    } = options;
    const basePath = resolveBathPath(base);
    const { swSrc, swDest, useFilename } = resolveSwPaths(strategies === "injectManifest", root, srcDir, outDir, filename);
    const outDirRoot = (0, import_path4.resolve)(root, outDir);
    const scope = options.scope || basePath;
    const defaultWorkbox = {
      swDest,
      globDirectory: outDirRoot,
      offlineGoogleAnalytics: false,
      cleanupOutdatedCaches: true,
      mode,
      navigateFallback: "index.html"
    };
    const defaultInjectManifest = {
      swSrc,
      swDest,
      globDirectory: outDirRoot,
      injectionPoint: "self.__WB_MANIFEST"
    };
    const defaultManifest = {
      name: pkg.name,
      short_name: pkg.name,
      start_url: basePath,
      display: "standalone",
      background_color: "#ffffff",
      lang: "en",
      scope
    };
    const workbox = Object.assign({}, defaultWorkbox, options.workbox || {});
    const manifest = typeof options.manifest === "boolean" && !options.manifest ? false : Object.assign({}, defaultManifest, options.manifest || {});
    const injectManifest2 = Object.assign({}, defaultInjectManifest, options.injectManifest || {});
    if ((injectRegister === "auto" || registerType == null) && registerType === "autoUpdate") {
      workbox.skipWaiting = true;
      workbox.clientsClaim = true;
    }
    if (strategies === "generateSW" && workbox.sourcemap === void 0) {
      const sourcemap = (_a = viteConfig.build) == null ? void 0 : _a.sourcemap;
      workbox.sourcemap = sourcemap === true || sourcemap === "inline" || sourcemap === "hidden";
    }
    const resolvedVitePWAOptions = {
      base: basePath,
      mode,
      swSrc,
      swDest,
      srcDir,
      outDir,
      injectRegister,
      registerType,
      filename: useFilename || filename,
      strategies,
      workbox,
      manifest,
      injectManifest: injectManifest2,
      scope,
      minify,
      includeAssets,
      includeManifestIcons
    };
    await configureStaticAssets(resolvedVitePWAOptions, viteConfig);
    return resolvedVitePWAOptions;
  }
  
  // src/cache.ts
  var cachePreset = [
    {
      urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
      handler: "CacheFirst",
      options: {
        cacheName: "google-fonts",
        expiration: {
          maxEntries: 4,
          maxAgeSeconds: 365 * 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
      handler: "StaleWhileRevalidate",
      options: {
        cacheName: "static-font-assets",
        expiration: {
          maxEntries: 4,
          maxAgeSeconds: 7 * 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
      handler: "StaleWhileRevalidate",
      options: {
        cacheName: "static-image-assets",
        expiration: {
          maxEntries: 64,
          maxAgeSeconds: 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\.(?:js)$/i,
      handler: "StaleWhileRevalidate",
      options: {
        cacheName: "static-js-assets",
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\.(?:css|less)$/i,
      handler: "StaleWhileRevalidate",
      options: {
        cacheName: "static-style-assets",
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\.(?:json|xml|csv)$/i,
      handler: "NetworkFirst",
      options: {
        cacheName: "static-data-assets",
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60
        }
      }
    },
    {
      urlPattern: /\/api\/.*$/i,
      handler: "NetworkFirst",
      method: "GET",
      options: {
        cacheName: "apis",
        expiration: {
          maxEntries: 16,
          maxAgeSeconds: 24 * 60 * 60
        },
        networkTimeoutSeconds: 10
      }
    },
    {
      urlPattern: /.*/i,
      handler: "NetworkFirst",
      options: {
        cacheName: "others",
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60
        },
        networkTimeoutSeconds: 10
      }
    }
  ];
  
  // src/index.ts
  function VitePWA(userOptions = {}) {
    let viteConfig;
    let options;
    let useImportRegister = false;
    async function _generateSW() {
      if (options.strategies === "injectManifest")
        await generateInjectManifest(options, viteConfig);
      else
        await generateServiceWorker(options, viteConfig);
    }
    function _generateBundle(bundle = {}) {
      if (options.manifest) {
        bundle[FILE_MANIFEST] = {
          isAsset: true,
          type: "asset",
          name: void 0,
          source: generateWebManifestFile(options),
          fileName: FILE_MANIFEST
        };
      }
      if (options.injectRegister === "auto")
        options.injectRegister = useImportRegister ? null : "script";
      if (options.injectRegister === "script" && !(0, import_fs4.existsSync)((0, import_path5.resolve)(viteConfig.publicDir, FILE_SW_REGISTER))) {
        bundle[FILE_SW_REGISTER] = {
          isAsset: true,
          type: "asset",
          name: void 0,
          source: generateSimpleSWRegister(options),
          fileName: FILE_SW_REGISTER
        };
      }
      return bundle;
    }
    return [
      {
        name: "vite-plugin-pwa",
        enforce: "post",
        apply: "build",
        async configResolved(config) {
          viteConfig = config;
          options = await resolveOptions(userOptions, viteConfig);
        },
        transformIndexHtml: {
          enforce: "post",
          transform(html) {
            return injectServiceWorker(html, options);
          }
        },
        generateBundle(_, bundle) {
          _generateBundle(bundle);
        },
        async closeBundle() {
          if (!viteConfig.build.ssr)
            await _generateSW();
        },
        async buildEnd(error) {
          if (error)
            throw error;
        },
        api: {
          generateBundle: _generateBundle,
          generateSW: _generateSW,
          extendManifestEntries(fn) {
            const configField = options.strategies === "generateSW" ? "workbox" : "injectManifest";
            const result = fn(options[configField].additionalManifestEntries || []);
            if (result != null)
              options[configField].additionalManifestEntries = result;
          }
        }
      },
      {
        name: "vite-plugin-pwa:virtual",
        async configResolved(config) {
          viteConfig = config;
          options = await resolveOptions(userOptions, viteConfig);
        },
        resolveId(id) {
          return VIRTUAL_MODULES.includes(id) ? VIRTUAL_MODULES_RESOLVE_PREFIX + id : void 0;
        },
        load(id) {
          if (id.startsWith(VIRTUAL_MODULES_RESOLVE_PREFIX))
            id = id.slice(VIRTUAL_MODULES_RESOLVE_PREFIX.length);
          else
            return;
          if (VIRTUAL_MODULES.includes(id)) {
            useImportRegister = true;
            return generateRegisterSW(options, viteConfig.command === "build" ? "build" : "dev", VIRTUAL_MODULES_MAP[id]);
          }
        }
      }
    ];
  }
  // Annotate the CommonJS export names for ESM import in node:
  0 && (module.exports = {
    VitePWA,
    cachePreset
  });
  