@unplugin-pwa/core 0.0.1 → 0.0.3
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.
- package/dist/additional-manifest-entries.d.mts +10 -0
- package/dist/additional-manifest-entries.mjs +60 -0
- package/dist/build-pwa-asset.d.mts +18 -0
- package/dist/build-pwa-asset.mjs +87 -0
- package/dist/config.d.mts +75 -0
- package/dist/config.mjs +293 -0
- package/dist/constants.d.mts +31 -0
- package/dist/constants.mjs +41 -0
- package/dist/context-types.d.mts +155 -0
- package/dist/context.d.mts +15 -0
- package/dist/context.mjs +58 -0
- package/dist/create-generate-register-sw-script.d.mts +15 -0
- package/dist/create-generate-register-sw-script.mjs +27 -0
- package/dist/create-web-manifest-html-link.d.mts +13 -0
- package/dist/create-web-manifest-html-link.mjs +21 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.d.mts +18 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.mjs +75 -0
- package/dist/dev/prepare-temp-folder.d.mts +9 -0
- package/dist/dev/prepare-temp-folder.mjs +44 -0
- package/dist/dual-sw-utilities.d.mts +9 -0
- package/dist/dual-sw-utilities.mjs +16 -0
- package/dist/generate-register-sw.d.mts +14 -0
- package/dist/generate-register-sw.mjs +22 -0
- package/dist/generate-web-manifest.d.mts +9 -0
- package/dist/generate-web-manifest.mjs +12 -0
- package/dist/helpers.d.mts +33 -0
- package/dist/helpers.mjs +132 -0
- package/dist/html.d.mts +8 -0
- package/dist/html.mjs +28 -0
- package/dist/index.d.mts +9 -0
- package/dist/inject-generate-register-sw.d.mts +16 -0
- package/dist/inject-generate-register-sw.mjs +22 -0
- package/dist/inject-web-manifest-html-link.d.mts +14 -0
- package/dist/inject-web-manifest-html-link.mjs +20 -0
- package/dist/inspector-utils.d.mts +26 -0
- package/dist/inspector-utils.mjs +47 -0
- package/dist/logs.d.mts +8 -0
- package/dist/logs.mjs +19 -0
- package/dist/package-zuOn_aH6.mjs +10 -0
- package/dist/prepare-pwa-context.d.mts +11 -0
- package/dist/prepare-pwa-context.mjs +135 -0
- package/dist/prepare-sw-names.d.mts +11 -0
- package/dist/prepare-sw-names.mjs +45 -0
- package/dist/pwa-assets/build.d.mts +9 -0
- package/dist/pwa-assets/build.mjs +15 -0
- package/dist/pwa-assets/config.d.mts +10 -0
- package/dist/pwa-assets/config.mjs +136 -0
- package/dist/pwa-assets/dev.d.mts +11 -0
- package/dist/pwa-assets/dev.mjs +35 -0
- package/dist/pwa-assets/generator.d.mts +20 -0
- package/dist/pwa-assets/generator.mjs +31 -0
- package/dist/pwa-assets/html.d.mts +11 -0
- package/dist/pwa-assets/html.mjs +47 -0
- package/dist/pwa-assets/manifest.d.mts +10 -0
- package/dist/pwa-assets/manifest.mjs +15 -0
- package/dist/pwa-assets/options.d.mts +9 -0
- package/dist/pwa-assets/options.mjs +34 -0
- package/dist/pwa-assets/types.d.mts +9 -0
- package/dist/pwa-assets/utils.d.mts +11 -0
- package/dist/pwa-assets/utils.mjs +48 -0
- package/dist/resolve-inspector-dist.d.mts +11 -0
- package/dist/resolve-inspector-dist.mjs +25 -0
- package/dist/types-B60e7Nq4.d.mts +67 -0
- package/dist/types-BhwjnGLn.d.mts +703 -0
- package/package.json +1 -1
|
@@ -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 };
|
|
@@ -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 { i as PWAAssetsIcons, o as PWAHtmlLink } from "../types-B60e7Nq4.mjs";
|
|
9
|
+
import { AppleSplashScreenLink, FaviconLink, HtmlLink, ImageAssetsInstructions } from "@vite-pwa/assets-generator/api";
|
|
10
|
+
export declare function mapLink(includeId: boolean, link: HtmlLink | FaviconLink | AppleSplashScreenLink): PWAHtmlLink;
|
|
11
|
+
export declare function extractIcons(instructions?: ImageAssetsInstructions): PWAAssetsIcons;
|
|
@@ -0,0 +1,48 @@
|
|
|
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/utils.ts
|
|
9
|
+
function mapLink(includeId, link) {
|
|
10
|
+
const linkObject = {
|
|
11
|
+
href: link.href,
|
|
12
|
+
rel: link.rel
|
|
13
|
+
};
|
|
14
|
+
if (includeId && link.id) linkObject.id = link.id;
|
|
15
|
+
if ("media" in link && link.media) linkObject.media = link.media;
|
|
16
|
+
linkObject.href = link.href;
|
|
17
|
+
if ("sizes" in link && link.sizes) linkObject.sizes = link.sizes;
|
|
18
|
+
if ("type" in link && link.type) linkObject.type = link.type;
|
|
19
|
+
return linkObject;
|
|
20
|
+
}
|
|
21
|
+
function extractIcons(instructions) {
|
|
22
|
+
const icons = {
|
|
23
|
+
favicon: {},
|
|
24
|
+
transparent: {},
|
|
25
|
+
maskable: {},
|
|
26
|
+
apple: {},
|
|
27
|
+
appleSplashScreen: {}
|
|
28
|
+
};
|
|
29
|
+
if (instructions) {
|
|
30
|
+
Array.from(Object.values(instructions.favicon)).forEach(({ buffer: _buffer, ...rest }) => {
|
|
31
|
+
if (rest.url) icons.favicon[rest.url] = { ...rest };
|
|
32
|
+
});
|
|
33
|
+
Array.from(Object.values(instructions.transparent)).forEach(({ buffer: _buffer, ...rest }) => {
|
|
34
|
+
if (rest.url) icons.transparent[rest.url] = { ...rest };
|
|
35
|
+
});
|
|
36
|
+
Array.from(Object.values(instructions.maskable)).forEach(({ buffer: _buffer, ...rest }) => {
|
|
37
|
+
if (rest.url) icons.maskable[rest.url] = { ...rest };
|
|
38
|
+
});
|
|
39
|
+
Array.from(Object.values(instructions.apple)).forEach(({ buffer: _buffer, ...rest }) => {
|
|
40
|
+
if (rest.url) icons.apple[rest.url] = { ...rest };
|
|
41
|
+
});
|
|
42
|
+
Array.from(Object.values(instructions.appleSplashScreen)).forEach(({ buffer: _buffer, ...rest }) => {
|
|
43
|
+
if (rest.url) icons.appleSplashScreen[rest.url] = { ...rest };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return icons;
|
|
47
|
+
}
|
|
48
|
+
export { extractIcons, mapLink };
|
|
@@ -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
|
+
/**
|
|
9
|
+
* Locate the built-in inspector folder.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveInspectorDist(): string | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { createRequire, findPackageJSON } from "node:module";
|
|
9
|
+
import { dirname, resolve } from "node:path";
|
|
10
|
+
// src/resolve-inspector-dist.ts
|
|
11
|
+
/**
|
|
12
|
+
* Locate the built-in inspector folder.
|
|
13
|
+
*/
|
|
14
|
+
function resolveInspectorDist() {
|
|
15
|
+
let inspectorJSON;
|
|
16
|
+
try {
|
|
17
|
+
inspectorJSON = findPackageJSON("@unplugin-pwa/inspector", import.meta.url);
|
|
18
|
+
} catch {
|
|
19
|
+
try {
|
|
20
|
+
inspectorJSON = createRequire(import.meta.url).resolve("@unplugin-pwa/inspector/package.json");
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
return inspectorJSON ? resolve(dirname(inspectorJSON), "dist") : void 0;
|
|
24
|
+
}
|
|
25
|
+
export { resolveInspectorDist };
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { AppleSplashScreenLink, FaviconLink, HtmlLink, IconAsset, ImageAssetsInstructions } from "@vite-pwa/assets-generator/api";
|
|
9
|
+
interface PWAHtmlLink {
|
|
10
|
+
id?: string;
|
|
11
|
+
rel: 'apple-touch-startup-image' | 'apple-touch-icon' | 'icon';
|
|
12
|
+
href: string;
|
|
13
|
+
media?: string;
|
|
14
|
+
sizes?: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ColorSchemeMeta {
|
|
18
|
+
name: string;
|
|
19
|
+
content: string;
|
|
20
|
+
}
|
|
21
|
+
interface ResolvedIconAsset {
|
|
22
|
+
path: string;
|
|
23
|
+
mimeType: string;
|
|
24
|
+
buffer: Promise<Buffer>;
|
|
25
|
+
age: number;
|
|
26
|
+
lastModified: number;
|
|
27
|
+
}
|
|
28
|
+
interface PWAHtmlAssets {
|
|
29
|
+
links: PWAHtmlLink[];
|
|
30
|
+
themeColor?: ColorSchemeMeta;
|
|
31
|
+
}
|
|
32
|
+
interface AssetsGeneratorContext {
|
|
33
|
+
lastModified: number;
|
|
34
|
+
assetsInstructions: ImageAssetsInstructions;
|
|
35
|
+
cache: Map<string, ResolvedIconAsset>;
|
|
36
|
+
useImage: string;
|
|
37
|
+
imageFile: string;
|
|
38
|
+
publicDir: string;
|
|
39
|
+
outDir: string;
|
|
40
|
+
imageName: string;
|
|
41
|
+
imageOutDir: string;
|
|
42
|
+
xhtml: boolean;
|
|
43
|
+
includeId: boolean;
|
|
44
|
+
sources: string[];
|
|
45
|
+
injectThemeColor: boolean;
|
|
46
|
+
includeHtmlHeadLinks: boolean;
|
|
47
|
+
overrideManifestIcons: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface PWAAssetsIcons {
|
|
50
|
+
favicon: Record<string, Omit<IconAsset<FaviconLink>, 'buffer'>>;
|
|
51
|
+
transparent: Record<string, Omit<IconAsset<HtmlLink>, 'buffer'>>;
|
|
52
|
+
maskable: Record<string, Omit<IconAsset<HtmlLink>, 'buffer'>>;
|
|
53
|
+
apple: Record<string, Omit<IconAsset<HtmlLink>, 'buffer'>>;
|
|
54
|
+
appleSplashScreen: Record<string, Omit<IconAsset<AppleSplashScreenLink>, 'buffer'>>;
|
|
55
|
+
}
|
|
56
|
+
interface PWAAssetsGenerator {
|
|
57
|
+
sources: () => string[];
|
|
58
|
+
generate: () => Promise<void>;
|
|
59
|
+
findIconAsset: (path: string) => ResolvedIconAsset | undefined;
|
|
60
|
+
resolveHtmlAssets: () => PWAHtmlAssets;
|
|
61
|
+
transformIndexHtml: (html: string) => string;
|
|
62
|
+
injectManifestIcons: () => void;
|
|
63
|
+
instructions: () => ImageAssetsInstructions;
|
|
64
|
+
icons: () => PWAAssetsIcons;
|
|
65
|
+
checkHotUpdate: (path: string) => Promise<boolean>;
|
|
66
|
+
}
|
|
67
|
+
export { PWAHtmlAssets as a, PWAAssetsIcons as i, ColorSchemeMeta as n, PWAHtmlLink as o, PWAAssetsGenerator as r, ResolvedIconAsset as s, AssetsGeneratorContext as t };
|