@unplugin-pwa/core 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -2
  3. package/client.d.ts +6 -0
  4. package/dist/additional-manifest-entries.d.mts +10 -0
  5. package/dist/additional-manifest-entries.mjs +60 -0
  6. package/dist/build-pwa-asset.d.mts +18 -0
  7. package/dist/build-pwa-asset.mjs +87 -0
  8. package/dist/config.d.mts +75 -0
  9. package/dist/config.mjs +293 -0
  10. package/dist/constants.d.mts +31 -0
  11. package/dist/constants.mjs +41 -0
  12. package/dist/context-types.d.mts +155 -0
  13. package/dist/context.d.mts +15 -0
  14. package/dist/context.mjs +58 -0
  15. package/dist/create-generate-register-sw-script.d.mts +15 -0
  16. package/dist/create-generate-register-sw-script.mjs +27 -0
  17. package/dist/create-web-manifest-html-link.d.mts +13 -0
  18. package/dist/create-web-manifest-html-link.mjs +21 -0
  19. package/dist/dev/prepare-sw-names-and-glob-directory.d.mts +18 -0
  20. package/dist/dev/prepare-sw-names-and-glob-directory.mjs +75 -0
  21. package/dist/dev/prepare-temp-folder.d.mts +9 -0
  22. package/dist/dev/prepare-temp-folder.mjs +44 -0
  23. package/dist/dual-sw-utilities.d.mts +9 -0
  24. package/dist/dual-sw-utilities.mjs +16 -0
  25. package/dist/generate-register-sw.d.mts +14 -0
  26. package/dist/generate-register-sw.mjs +22 -0
  27. package/dist/generate-web-manifest.d.mts +9 -0
  28. package/dist/generate-web-manifest.mjs +12 -0
  29. package/dist/helpers.d.mts +33 -0
  30. package/dist/helpers.mjs +132 -0
  31. package/dist/html.d.mts +8 -0
  32. package/dist/html.mjs +28 -0
  33. package/dist/index.d.mts +9 -0
  34. package/dist/inject-generate-register-sw.d.mts +16 -0
  35. package/dist/inject-generate-register-sw.mjs +22 -0
  36. package/dist/inject-web-manifest-html-link.d.mts +14 -0
  37. package/dist/inject-web-manifest-html-link.mjs +20 -0
  38. package/dist/inspector-utils.d.mts +26 -0
  39. package/dist/inspector-utils.mjs +47 -0
  40. package/dist/logs.d.mts +8 -0
  41. package/dist/logs.mjs +19 -0
  42. package/dist/package-DpKc2x3j.mjs +10 -0
  43. package/dist/prepare-pwa-context.d.mts +11 -0
  44. package/dist/prepare-pwa-context.mjs +135 -0
  45. package/dist/prepare-sw-names.d.mts +11 -0
  46. package/dist/prepare-sw-names.mjs +45 -0
  47. package/dist/pwa-assets/build.d.mts +9 -0
  48. package/dist/pwa-assets/build.mjs +15 -0
  49. package/dist/pwa-assets/config.d.mts +10 -0
  50. package/dist/pwa-assets/config.mjs +136 -0
  51. package/dist/pwa-assets/dev.d.mts +11 -0
  52. package/dist/pwa-assets/dev.mjs +35 -0
  53. package/dist/pwa-assets/generator.d.mts +20 -0
  54. package/dist/pwa-assets/generator.mjs +31 -0
  55. package/dist/pwa-assets/html.d.mts +11 -0
  56. package/dist/pwa-assets/html.mjs +47 -0
  57. package/dist/pwa-assets/manifest.d.mts +10 -0
  58. package/dist/pwa-assets/manifest.mjs +15 -0
  59. package/dist/pwa-assets/options.d.mts +9 -0
  60. package/dist/pwa-assets/options.mjs +34 -0
  61. package/dist/pwa-assets/types.d.mts +9 -0
  62. package/dist/pwa-assets/utils.d.mts +11 -0
  63. package/dist/pwa-assets/utils.mjs +48 -0
  64. package/dist/resolve-inspector-dist.d.mts +11 -0
  65. package/dist/resolve-inspector-dist.mjs +25 -0
  66. package/dist/types-B60e7Nq4.d.mts +67 -0
  67. package/dist/types-BhwjnGLn.d.mts +703 -0
  68. package/info.d.ts +71 -0
  69. package/package.json +133 -7
  70. package/preact.d.ts +17 -0
  71. package/pwa-assets.d.ts +40 -0
  72. package/react-legacy.d.ts +22 -0
  73. package/react.d.ts +17 -0
  74. package/solid.d.ts +17 -0
  75. package/svelte.d.ts +17 -0
  76. package/types/index.d.ts +43 -0
  77. package/types/package.json +3 -0
  78. package/vanillajs.d.ts +13 -0
  79. package/vue.d.ts +17 -0
  80. package/index.js +0 -1
package/dist/logs.mjs ADDED
@@ -0,0 +1,19 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { INSPECTOR_BASE_PATH } from "./constants.mjs";
9
+ import { errStyle } from "@vite-pwa/workbox-build/utils/colors";
10
+ // src/logs.ts
11
+ const inspectorWithInjectManifestWarning = [
12
+ `\n${errStyle(["yellow", "bold"], "[Vite PWA]")} ${errStyle("yellow", "Vite PWA Inspector won't work as expected")}:\n`,
13
+ `You are using ${errStyle("cyan", "inject-manifest")} strategy, your service worker is ${errStyle("cyan", "static")}.`,
14
+ `If you want to see ${errStyle("cyan", "Vite PWA Inspector")}, you can:`,
15
+ ` - use hard refresh when opening ${errStyle("cyan", "Vite PWA Inspector")} page to bypass the service worker interception or`,
16
+ ` - you can add ${errStyle("green", `'${INSPECTOR_BASE_PATH}'`)} to your ${errStyle("cyan", "NavigationRoute denylist option")}:`,
17
+ ` ${errStyle("green", "registerRoute(new NavigationRoute(createHandlerBoundToURL('index.html'), { denylist: [/^\\/__unplugin_pwa_inspector/] }))")}\n`
18
+ ].join("\n");
19
+ export { inspectorWithInjectManifestWarning };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ // package.json
9
+ var version = "0.0.2";
10
+ export { version as t };
@@ -0,0 +1,11 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
9
+ import { Bundler, PWAPluginContext } from "./context-types.mjs";
10
+ import { SWType } from "@vite-pwa/workbox-build/types";
11
+ export declare function preparePWAContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): PWAPluginContext<B, UserStrategy, T>;
@@ -0,0 +1,135 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { DEV_SW_NAME, FILE_SW_REGISTER } from "./constants.mjs";
9
+ import { isDualServiceWorker } from "./dual-sw-utilities.mjs";
10
+ import { createGenerateRegisterSW } from "./create-generate-register-sw-script.mjs";
11
+ import { createWebManifestHtmlLink } from "./create-web-manifest-html-link.mjs";
12
+ // src/prepare-pwa-context.ts
13
+ function preparePWAContext(ctx) {
14
+ ctx.webManifestData = () => {
15
+ const options = ctx.resolvedOptions;
16
+ if (!options.manifest) return void 0;
17
+ const url = options.manifestFilename;
18
+ const manifest = createWebManifestHtmlLink(ctx);
19
+ return {
20
+ href: `${ctx.devEnvironment ? options.base : options.buildBase}${url}`,
21
+ useCredentials: options.useCredentials,
22
+ toLinkTag: () => {
23
+ return manifest;
24
+ }
25
+ };
26
+ };
27
+ ctx.registerSWData = async () => {
28
+ const options = ctx.resolvedOptions;
29
+ if (options.disable || ctx.devEnvironment && !options.devOptions?.enabled) return void 0;
30
+ let mode = options.injectRegister;
31
+ if (!mode || ctx.useImportRegister) return;
32
+ if (mode === "auto") {
33
+ options.injectRegister = "script";
34
+ mode = "script";
35
+ }
36
+ let type = "classic";
37
+ let script;
38
+ let shouldRegisterSW = options.injectRegister === "inline" || options.injectRegister === "script" || options.injectRegister === "script-defer";
39
+ if (ctx.devEnvironment) {
40
+ if (options.devOptions?.enabled === true) {
41
+ type = options.devOptions?.type ?? "classic";
42
+ script = await createGenerateRegisterSW(ctx, true, true);
43
+ shouldRegisterSW = true;
44
+ }
45
+ } else {
46
+ script = await createGenerateRegisterSW(ctx, false, true);
47
+ shouldRegisterSW = true;
48
+ }
49
+ const base = ctx.devEnvironment ? options.base : options.buildBase;
50
+ return {
51
+ shouldRegisterSW,
52
+ module: isDualServiceWorker(ctx),
53
+ mode,
54
+ scope: options.scope,
55
+ inlinePath: `${base}${ctx.devEnvironment ? DEV_SW_NAME : FILE_SW_REGISTER}`,
56
+ registerPath: `${base}${FILE_SW_REGISTER}`,
57
+ type,
58
+ toScriptTag: () => {
59
+ return script;
60
+ }
61
+ };
62
+ };
63
+ ctx.build = {
64
+ generateSW: async () => {
65
+ switch (ctx.bundler) {
66
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(ctx.resolvedOptions.generateSW));
67
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-generate-sw").then(({ generateSWLegacy: runGenerateSWLegacy }) => runGenerateSWLegacy(ctx.resolvedOptions.generateSW));
68
+ case "rspack":
69
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(ctx.resolvedOptions.generateSW));
70
+ }
71
+ },
72
+ buildSW: async () => {
73
+ switch (ctx.bundler) {
74
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.resolvedOptions.buildSW));
75
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-build-sw").then(({ buildSWLegacy: runBuildSWLegacy }) => runBuildSWLegacy(ctx.resolvedOptions.buildSW));
76
+ case "rspack":
77
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.bundler === "webpack" ? ctx.resolvedOptions.buildSW : ctx.resolvedOptions.buildSW));
78
+ }
79
+ },
80
+ injectManifest: () => import("@vite-pwa/workbox-build/inject-manifest").then(({ injectManifest: runInjectManifest }) => runInjectManifest(ctx.resolvedOptions.injectManifest)),
81
+ selfDestroyingSW: () => import("@vite-pwa/workbox-build/self-destroying-sw").then(({ selfDestroyingSW: runSelfDestroyingSW }) => runSelfDestroyingSW(ctx.resolvedOptions.selfDestroying)).then(() => Promise.resolve(true))
82
+ };
83
+ ctx.dev = {
84
+ options: {
85
+ swName: "",
86
+ swGenerated: false,
87
+ registerSWGenerated: false,
88
+ registerVirtualSWGenerated: false,
89
+ hmrEntryPointGenerated: false,
90
+ swType: ctx.consumerOptions.devOptions?.type ?? "classic",
91
+ swAssetKeys: /* @__PURE__ */ new Set(),
92
+ swAssetsPaths: /* @__PURE__ */ new Map(),
93
+ tempFolder: void 0,
94
+ swNames: {
95
+ hasNames: false,
96
+ name: "",
97
+ classic: "",
98
+ module: "",
99
+ path: "",
100
+ classicPath: "",
101
+ modulePath: "",
102
+ devSWDest: ""
103
+ },
104
+ globDirectory: ""
105
+ },
106
+ generateSW: async (options) => {
107
+ switch (ctx.bundler) {
108
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
109
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-generate-sw").then(({ generateSWLegacy: runGenerateSWLegacy }) => runGenerateSWLegacy(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
110
+ case "rspack":
111
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
112
+ }
113
+ },
114
+ buildSW: async (options) => {
115
+ switch (ctx.bundler) {
116
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
117
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-build-sw").then(({ buildSWLegacy: runBuildSWLegacy }) => runBuildSWLegacy(Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
118
+ case "rspack":
119
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.bundler === "webpack" ? Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options) : Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
120
+ }
121
+ },
122
+ injectManifest: (options) => import("@vite-pwa/workbox-build/inject-manifest").then(({ injectManifest: runInjectManifest }) => runInjectManifest(Object.assign({}, ctx.resolvedOptions.injectManifest ?? {}, options))),
123
+ selfDestroyingSW: (options) => import("@vite-pwa/workbox-build/self-destroying-sw").then(({ selfDestroyingSW: runSelfDestroyingSW }) => runSelfDestroyingSW(options)).then(() => Promise.resolve(true))
124
+ };
125
+ ctx.runBuild = async () => {
126
+ switch (ctx.strategy) {
127
+ case "self-destroy-sw": return await ctx.build.selfDestroyingSW();
128
+ case "build-sw": return await ctx.build.buildSW();
129
+ case "generate-sw": return await ctx.build.generateSW();
130
+ case "inject-manifest": return await ctx.build.injectManifest();
131
+ }
132
+ };
133
+ return ctx;
134
+ }
135
+ export { preparePWAContext };
@@ -0,0 +1,11 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
9
+ import { Bundler, PWAPluginContext } from "./context-types.mjs";
10
+ import { SWType } from "@vite-pwa/workbox-build/types";
11
+ export declare function prepareSwNames<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): void;
@@ -0,0 +1,45 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { normalizePath as normalizePath$1 } from "./helpers.mjs";
9
+ import { extractSwDestNameFromSource, resolveSWNames } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
10
+ import path from "node:path";
11
+ // src/prepare-sw-names.ts
12
+ function prepareSwNames(ctx) {
13
+ let options;
14
+ let filename;
15
+ let swSrc;
16
+ switch (ctx.strategy) {
17
+ case "generate-sw":
18
+ swSrc = "";
19
+ options = ctx.resolvedOptions.generateSW;
20
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || "sw.js"));
21
+ ctx.resolvedOptions.generateSW.swDest = filename;
22
+ break;
23
+ case "inject-manifest":
24
+ options = ctx.resolvedOptions.injectManifest;
25
+ swSrc = ctx.resolvedOptions.injectManifest.swSrc;
26
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc)));
27
+ ctx.resolvedOptions.injectManifest.swDest = filename;
28
+ break;
29
+ case "build-sw":
30
+ options = ctx.resolvedOptions.buildSW;
31
+ swSrc = extractSwDestNameFromSource(ctx.resolvedOptions.buildSW.swSrc);
32
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc)));
33
+ ctx.resolvedOptions.buildSW.swDest = filename;
34
+ }
35
+ if (options) {
36
+ const { swDest, classicSWDest, moduleSWDest } = resolveSWNames(filename, swSrc, ctx.strategy === "generate-sw");
37
+ ctx.swNames = {
38
+ hasNames: true,
39
+ name: swDest,
40
+ classic: classicSWDest,
41
+ module: moduleSWDest
42
+ };
43
+ }
44
+ }
45
+ export { prepareSwNames };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ export declare function generate(assetsGeneratorContext: AssetsGeneratorContext): Promise<void>;
@@ -0,0 +1,15 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { mkdir } from "node:fs/promises";
9
+ import { generateAssets } from "@vite-pwa/assets-generator/api/generate-assets";
10
+ // src/pwa-assets/build.ts
11
+ async function generate(assetsGeneratorContext) {
12
+ await mkdir(assetsGeneratorContext.imageOutDir, { recursive: true });
13
+ await generateAssets(assetsGeneratorContext.assetsInstructions, true, assetsGeneratorContext.imageOutDir);
14
+ }
15
+ export { generate };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function loadAssetsGeneratorContext(ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext?: AssetsGeneratorContext): Promise<AssetsGeneratorContext | undefined>;
@@ -0,0 +1,136 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { normalizePath } from "../helpers.mjs";
9
+ import fs from "node:fs";
10
+ import { basename, dirname, relative, resolve } from "node:path";
11
+ import { errStyle } from "@vite-pwa/workbox-build/utils/colors";
12
+ import { access, readFile } from "node:fs/promises";
13
+ import { instructions } from "@vite-pwa/assets-generator/api/instructions";
14
+ import { loadConfig } from "@vite-pwa/assets-generator/config";
15
+ // src/pwa-assets/config.ts
16
+ async function loadAssetsGeneratorContext(ctx, assetsGeneratorContext) {
17
+ const root = ctx.rootDir;
18
+ const { config, sources } = await loadConfiguration(root, ctx);
19
+ if (!config.preset) {
20
+ console.error([
21
+ "",
22
+ errStyle("cyan", `PWA v${ctx.version}`),
23
+ errStyle("red", "ERROR: No preset for assets generator found")
24
+ ].join("\n"));
25
+ return;
26
+ }
27
+ const { preset, images, headLinkOptions: userHeadLinkOptions } = config;
28
+ if (!images) {
29
+ console.error([
30
+ "",
31
+ errStyle("cyan", `PWA v${ctx.version}`),
32
+ errStyle("red", "ERROR: No image provided for assets generator")
33
+ ].join("\n"));
34
+ return;
35
+ }
36
+ if (Array.isArray(images)) {
37
+ if (!images.length) {
38
+ console.error([
39
+ "",
40
+ errStyle("cyan", `PWA v${ctx.version}`),
41
+ errStyle("red", "ERROR: No image provided for assets generator")
42
+ ].join("\n"));
43
+ return;
44
+ }
45
+ if (images.length > 1) {
46
+ console.error([
47
+ "",
48
+ errStyle("cyan", `PWA v${ctx.version}`),
49
+ errStyle("red", "ERROR: Only one image is supported for assets generator")
50
+ ].join("\n"));
51
+ return;
52
+ }
53
+ }
54
+ const pwaAssets = ctx.resolvedOptions.pwaAssets;
55
+ const image = await pwaAssets.integration?.resolveImage?.(Array.isArray(images) ? images[0] : images);
56
+ const useImage = image ?? (Array.isArray(images) ? images[0] : images);
57
+ const imageFile = image ?? await tryToResolveImage(root, sources, useImage);
58
+ const publicDir = image ? dirname(image) : pwaAssets.integration?.publicDir ?? resolve(root, ctx.publicDir);
59
+ const outDir = pwaAssets.integration?.outDir ?? resolve(root, ctx.outDir);
60
+ const imageName = relative(publicDir, imageFile);
61
+ const imageOutDir = dirname(resolve(outDir, imageName));
62
+ const xhtml = userHeadLinkOptions?.xhtml === true;
63
+ const includeId = userHeadLinkOptions?.includeId === true;
64
+ const assetsInstructions = await instructions({
65
+ imageResolver: () => readFile(imageFile),
66
+ imageName,
67
+ preset,
68
+ faviconPreset: userHeadLinkOptions?.preset ?? pwaAssets.htmlPreset,
69
+ htmlLinks: {
70
+ xhtml,
71
+ includeId
72
+ },
73
+ basePath: pwaAssets.integration?.baseUrl || ctx.base,
74
+ resolveSvgName: userHeadLinkOptions?.resolveSvgName ?? ((name) => basename(name))
75
+ });
76
+ const { includeHtmlHeadLinks = true, overrideManifestIcons: useOverrideManifestIcons, injectThemeColor = false } = pwaAssets;
77
+ const overrideManifestIcons = ctx.resolvedOptions.manifest === false || !ctx.resolvedOptions.manifest ? false : "icons" in ctx.resolvedOptions.manifest ? useOverrideManifestIcons : true;
78
+ if (assetsGeneratorContext === void 0) return {
79
+ lastModified: Date.now(),
80
+ assetsInstructions,
81
+ cache: /* @__PURE__ */ new Map(),
82
+ useImage,
83
+ imageFile,
84
+ publicDir,
85
+ outDir,
86
+ imageName,
87
+ imageOutDir,
88
+ xhtml,
89
+ includeId,
90
+ sources: sources.map((source) => normalizePath(source)),
91
+ injectThemeColor,
92
+ includeHtmlHeadLinks,
93
+ overrideManifestIcons
94
+ };
95
+ assetsGeneratorContext.lastModified = Date.now();
96
+ assetsGeneratorContext.assetsInstructions = assetsInstructions;
97
+ assetsGeneratorContext.useImage = useImage;
98
+ assetsGeneratorContext.imageFile = imageFile;
99
+ assetsGeneratorContext.outDir = outDir;
100
+ assetsGeneratorContext.imageName = imageName;
101
+ assetsGeneratorContext.imageOutDir = imageOutDir;
102
+ assetsGeneratorContext.xhtml = xhtml;
103
+ assetsGeneratorContext.includeId = includeId;
104
+ assetsGeneratorContext.injectThemeColor = injectThemeColor;
105
+ assetsGeneratorContext.includeHtmlHeadLinks = includeHtmlHeadLinks;
106
+ assetsGeneratorContext.overrideManifestIcons = overrideManifestIcons;
107
+ assetsGeneratorContext.cache.clear();
108
+ }
109
+ async function loadConfiguration(root, ctx) {
110
+ const pwaAssets = ctx.resolvedOptions.pwaAssets;
111
+ if (pwaAssets.config === false) return await loadConfig(root, {
112
+ config: false,
113
+ preset: pwaAssets.preset,
114
+ images: pwaAssets.images,
115
+ logLevel: "silent"
116
+ });
117
+ return await loadConfig(root, typeof pwaAssets.config === "boolean" ? root : { config: pwaAssets.config });
118
+ }
119
+ async function checkFileExists(pathname) {
120
+ try {
121
+ await access(pathname, fs.constants.R_OK);
122
+ } catch {
123
+ return false;
124
+ }
125
+ return true;
126
+ }
127
+ async function tryToResolveImage(root, sources, image) {
128
+ const imagePath = resolve(root, image);
129
+ if (await checkFileExists(imagePath)) return imagePath;
130
+ for (const source of sources) {
131
+ const sourceImage = resolve(dirname(source), image);
132
+ if (await checkFileExists(sourceImage)) return sourceImage;
133
+ }
134
+ return imagePath;
135
+ }
136
+ export { loadAssetsGeneratorContext };
@@ -0,0 +1,11 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { s as ResolvedIconAsset, t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function findIconAsset(path: string, { assetsInstructions, cache, lastModified }: AssetsGeneratorContext): ResolvedIconAsset | undefined;
11
+ export declare function checkHotUpdate(file: string, ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext: AssetsGeneratorContext): Promise<boolean>;
@@ -0,0 +1,35 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { loadAssetsGeneratorContext } from "./config.mjs";
9
+ // src/pwa-assets/dev.ts
10
+ function findIconAsset(path, { assetsInstructions, cache, lastModified }) {
11
+ let resolved = cache.get(path);
12
+ if (resolved) {
13
+ resolved.age = Date.now() - lastModified;
14
+ return resolved;
15
+ }
16
+ const iconAsset = assetsInstructions.transparent[path] ?? assetsInstructions.maskable[path] ?? assetsInstructions.apple[path] ?? assetsInstructions.favicon[path] ?? assetsInstructions.appleSplashScreen[path];
17
+ if (!iconAsset) return;
18
+ if (iconAsset) {
19
+ resolved = {
20
+ path,
21
+ mimeType: iconAsset.mimeType,
22
+ buffer: iconAsset.buffer(),
23
+ lastModified: Date.now(),
24
+ age: 0
25
+ };
26
+ cache.set(path, resolved);
27
+ return resolved;
28
+ }
29
+ }
30
+ async function checkHotUpdate(file, ctx, assetsGeneratorContext) {
31
+ const result = assetsGeneratorContext.sources.includes(file);
32
+ if (result) await loadAssetsGeneratorContext(ctx, assetsGeneratorContext);
33
+ return result;
34
+ }
35
+ export { checkHotUpdate, findIconAsset };
@@ -0,0 +1,20 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { a as PWAHtmlAssets, i as PWAAssetsIcons, s as ResolvedIconAsset } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function loadInstructions(ctx: PWAPluginContext<any, any, any>): Promise<{
11
+ sources: () => string[];
12
+ generate: () => Promise<void>;
13
+ findIconAsset: (path: string) => ResolvedIconAsset | undefined;
14
+ resolveHtmlAssets: () => PWAHtmlAssets;
15
+ transformIndexHtml: (html: string) => string;
16
+ injectManifestIcons: () => void;
17
+ instructions: () => import("@vite-pwa/assets-generator/api").ImageAssetsInstructions;
18
+ icons: () => PWAAssetsIcons;
19
+ checkHotUpdate: (file: string) => Promise<boolean>;
20
+ } | undefined>;
@@ -0,0 +1,31 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { generate } from "./build.mjs";
9
+ import { loadAssetsGeneratorContext } from "./config.mjs";
10
+ import { checkHotUpdate, findIconAsset } from "./dev.mjs";
11
+ import { extractIcons } from "./utils.mjs";
12
+ import { resolveHtmlAssets, transformIndexHtml } from "./html.mjs";
13
+ import { injectManifestIcons } from "./manifest.mjs";
14
+ // src/pwa-assets/generator.ts
15
+ async function loadInstructions(ctx) {
16
+ const assetsGeneratorContext = await loadAssetsGeneratorContext(ctx);
17
+ if (!assetsGeneratorContext) return;
18
+ const sources = Array.from(assetsGeneratorContext.sources);
19
+ return {
20
+ sources: () => sources,
21
+ generate: () => generate(assetsGeneratorContext),
22
+ findIconAsset: (path) => findIconAsset(path, assetsGeneratorContext),
23
+ resolveHtmlAssets: () => resolveHtmlAssets(ctx, assetsGeneratorContext),
24
+ transformIndexHtml: (html) => transformIndexHtml(html, ctx, assetsGeneratorContext),
25
+ injectManifestIcons: () => injectManifestIcons(ctx, assetsGeneratorContext),
26
+ instructions: () => assetsGeneratorContext.assetsInstructions,
27
+ icons: () => extractIcons(assetsGeneratorContext.assetsInstructions),
28
+ checkHotUpdate: (file) => checkHotUpdate(file, ctx, assetsGeneratorContext)
29
+ };
30
+ }
31
+ export { loadInstructions };
@@ -0,0 +1,11 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { a as PWAHtmlAssets, t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function transformIndexHtml(html: string, ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext: AssetsGeneratorContext): string;
11
+ export declare function resolveHtmlAssets(ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext: AssetsGeneratorContext): PWAHtmlAssets;
@@ -0,0 +1,47 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { checkForHtmlHead } from "../html.mjs";
9
+ import { mapLink } from "./utils.mjs";
10
+ import { generateHtmlMarkup } from "@vite-pwa/assets-generator/api/generate-html-markup";
11
+ // src/pwa-assets/html.ts
12
+ function transformIndexHtml(html, ctx, assetsGeneratorContext) {
13
+ if (assetsGeneratorContext.injectThemeColor) {
14
+ const manifest = ctx.resolvedOptions.manifest;
15
+ if (manifest && "theme_color" in manifest && manifest.theme_color) html = checkForHtmlHead(html).replace("</head>", `\n<meta name="theme-color" content="${manifest.theme_color}"></head>`);
16
+ }
17
+ if (assetsGeneratorContext.includeHtmlHeadLinks) {
18
+ const link = generateHtmlMarkup(assetsGeneratorContext.assetsInstructions);
19
+ if (link.length) html = checkForHtmlHead(html).replace("</head>", `\n${link.join("\n")}</head>`);
20
+ }
21
+ return html;
22
+ }
23
+ function resolveHtmlAssets(ctx, assetsGeneratorContext) {
24
+ const header = {
25
+ links: [],
26
+ themeColor: void 0
27
+ };
28
+ if (assetsGeneratorContext.injectThemeColor) {
29
+ const manifest = ctx.resolvedOptions.manifest;
30
+ if (manifest && "theme_color" in manifest && manifest.theme_color) header.themeColor = {
31
+ name: "theme-color",
32
+ content: manifest.theme_color
33
+ };
34
+ }
35
+ if (assetsGeneratorContext.includeHtmlHeadLinks) {
36
+ const includeId = assetsGeneratorContext.includeId;
37
+ const instruction = assetsGeneratorContext.assetsInstructions;
38
+ const favicon = Array.from(Object.values(instruction.favicon));
39
+ const apple = Array.from(Object.values(instruction.apple));
40
+ const appleSplashScreen = Array.from(Object.values(instruction.appleSplashScreen));
41
+ favicon.forEach((icon) => icon.linkObject && header.links.push(mapLink(includeId, icon.linkObject)));
42
+ apple.forEach((icon) => icon.linkObject && header.links.push(mapLink(includeId, icon.linkObject)));
43
+ appleSplashScreen.forEach((icon) => icon.linkObject && header.links.push(mapLink(includeId, icon.linkObject)));
44
+ }
45
+ return header;
46
+ }
47
+ export { resolveHtmlAssets, transformIndexHtml };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function injectManifestIcons(ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext: AssetsGeneratorContext): void;
@@ -0,0 +1,15 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { generateManifestIconsEntry } from "@vite-pwa/assets-generator/api/generate-manifest-icons-entry";
9
+ // src/pwa-assets/manifest.ts
10
+ function injectManifestIcons(ctx, assetsGeneratorContext) {
11
+ if (!assetsGeneratorContext.overrideManifestIcons) return;
12
+ const manifest = ctx.resolvedOptions.manifest;
13
+ if (manifest) manifest.icons = generateManifestIconsEntry("object", assetsGeneratorContext.assetsInstructions).icons;
14
+ }
15
+ export { injectManifestIcons };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { p as PWAAssetsOptions, v as ResolvedPWAAssetsOptions } from "../types-BhwjnGLn.mjs";
9
+ export declare function resolvePWAAssetsOptions(options?: PWAAssetsOptions): false | ResolvedPWAAssetsOptions;
@@ -0,0 +1,34 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ // src/pwa-assets/options.ts
9
+ function resolvePWAAssetsOptions(options) {
10
+ if (!options) return false;
11
+ const { disabled, preset = "minimal-2023", image = "public/favicon.svg", htmlPreset = "2023", overrideManifestIcons = false, includeHtmlHeadLinks = true, injectThemeColor = true, integration } = options ?? {};
12
+ const resolvedConfiguration = {
13
+ disabled: true,
14
+ config: false,
15
+ preset: false,
16
+ images: [image],
17
+ htmlPreset,
18
+ overrideManifestIcons,
19
+ includeHtmlHeadLinks,
20
+ injectThemeColor,
21
+ integration
22
+ };
23
+ if (disabled === true) return resolvedConfiguration;
24
+ if ("config" in options && !!options.config) {
25
+ resolvedConfiguration.disabled = false;
26
+ resolvedConfiguration.config = options.config;
27
+ return resolvedConfiguration;
28
+ }
29
+ if (preset === false) return resolvedConfiguration;
30
+ resolvedConfiguration.disabled = false;
31
+ resolvedConfiguration.preset = preset;
32
+ return resolvedConfiguration;
33
+ }
34
+ export { resolvePWAAssetsOptions };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { a as PWAHtmlAssets, i as PWAAssetsIcons, n as ColorSchemeMeta, o as PWAHtmlLink, r as PWAAssetsGenerator, s as ResolvedIconAsset, t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ export { AssetsGeneratorContext, ColorSchemeMeta, PWAAssetsGenerator, PWAAssetsIcons, PWAHtmlAssets, PWAHtmlLink, ResolvedIconAsset };