@vite-pwa/nuxt 1.1.0 → 2.0.1

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 (50) hide show
  1. package/README.md +28 -59
  2. package/config/index.d.mts +1 -0
  3. package/config/index.mjs +3 -0
  4. package/configuration.d.ts +3 -0
  5. package/dist/chunks/create-nuxt-pwa-context.mjs +27 -0
  6. package/dist/chunks/prepare-module.mjs +871 -0
  7. package/dist/chunks/prepare-pwa-icons.mjs +161 -0
  8. package/dist/module.d.mts +42 -89
  9. package/dist/module.json +5 -5
  10. package/dist/module.mjs +40 -8
  11. package/dist/runtime/components/NuxtPwaAssets.d.ts +1 -1
  12. package/dist/runtime/components/NuxtPwaAssets.js +8 -4
  13. package/dist/runtime/components/{VitePwaManifest.d.ts → NuxtPwaManifest.d.ts} +1 -1
  14. package/dist/runtime/components/{VitePwaManifest.js → NuxtPwaManifest.js} +2 -2
  15. package/dist/runtime/{composables/index.d.ts → composables.d.ts} +12 -28
  16. package/dist/runtime/{composables/index.js → composables.js} +1 -11
  17. package/dist/runtime/plugins/pwa-install.client.d.ts +6 -0
  18. package/dist/runtime/plugins/pwa-install.client.js +70 -0
  19. package/dist/runtime/plugins/pwa.client.d.ts +1 -1
  20. package/dist/runtime/plugins/pwa.client.js +90 -77
  21. package/dist/runtime/plugins/types.d.ts +70 -129
  22. package/dist/runtime/plugins/types.js +0 -0
  23. package/dist/types.d.mts +5 -5
  24. package/package.json +40 -59
  25. package/dist/chunks/dev.mjs +0 -37
  26. package/dist/chunks/pwa-icons.mjs +0 -155
  27. package/dist/module.cjs +0 -5
  28. package/dist/module.d.ts +0 -110
  29. package/dist/runtime/components/PwaAppleImage.vue +0 -12
  30. package/dist/runtime/components/PwaAppleImage.vue.d.ts +0 -2
  31. package/dist/runtime/components/PwaAppleSplashScreenImage.vue +0 -12
  32. package/dist/runtime/components/PwaAppleSplashScreenImage.vue.d.ts +0 -2
  33. package/dist/runtime/components/PwaFaviconImage.vue +0 -12
  34. package/dist/runtime/components/PwaFaviconImage.vue.d.ts +0 -2
  35. package/dist/runtime/components/PwaMaskableImage.vue +0 -12
  36. package/dist/runtime/components/PwaMaskableImage.vue.d.ts +0 -2
  37. package/dist/runtime/components/PwaTransparentImage.vue +0 -12
  38. package/dist/runtime/components/PwaTransparentImage.vue.d.ts +0 -2
  39. package/dist/runtime/components/nuxt4/PwaAppleImage.d.ts +0 -4
  40. package/dist/runtime/components/nuxt4/PwaAppleImage.js +0 -15
  41. package/dist/runtime/components/nuxt4/PwaAppleSplashScreenImage.d.ts +0 -4
  42. package/dist/runtime/components/nuxt4/PwaAppleSplashScreenImage.js +0 -15
  43. package/dist/runtime/components/nuxt4/PwaFaviconImage.d.ts +0 -4
  44. package/dist/runtime/components/nuxt4/PwaFaviconImage.js +0 -15
  45. package/dist/runtime/components/nuxt4/PwaMaskableImage.d.ts +0 -4
  46. package/dist/runtime/components/nuxt4/PwaMaskableImage.js +0 -15
  47. package/dist/runtime/components/nuxt4/PwaTransparentImage.d.ts +0 -4
  48. package/dist/runtime/components/nuxt4/PwaTransparentImage.js +0 -15
  49. package/dist/shared/nuxt.00c26fe8.mjs +0 -734
  50. package/dist/types.d.ts +0 -15
@@ -0,0 +1,161 @@
1
+ import { addTemplate, addComponent } from '@nuxt/kit';
2
+ import { normalizePath } from '@vite-pwa/workbox-build/utils/resolve-sw-names';
3
+ import { g as generatePwaImageType, p as pwaIcons } from './prepare-module.mjs';
4
+ import 'node:fs';
5
+ import '@unplugin-pwa/core/config';
6
+ import '@unplugin-pwa/core/helpers';
7
+ import '@vite-pwa/nuxt-core';
8
+ import 'node:path';
9
+ import '@unplugin-pwa/core/generate-web-manifest';
10
+ import '@unplugin-pwa/core/constants';
11
+ import 'defu';
12
+ import 'node:fs/promises';
13
+ import '@unplugin-pwa/core/dev/prepare-sw-names-and-glob-directory';
14
+ import 'node:process';
15
+ import 'node:crypto';
16
+ import 'verkit';
17
+ import 'node:module';
18
+
19
+ async function preparePWAIcons(nuxt, ctx) {
20
+ const pwaAssetsContext = await ctx.pwaAssetsGenerator;
21
+ if (!pwaAssetsContext) {
22
+ return void 0;
23
+ }
24
+ const assetsInstructions = pwaAssetsContext.instructions();
25
+ const transparentNames = Object.values(assetsInstructions.transparent).map(({ name }) => name);
26
+ const maskableNames = Object.values(assetsInstructions.maskable).map(({ name }) => name);
27
+ const faviconNames = Object.values(assetsInstructions.favicon).map(({ name }) => name);
28
+ const appleNames = Object.values(assetsInstructions.apple).map(({ name }) => name);
29
+ const appleSplashScreenNames = Object.values(assetsInstructions.appleSplashScreen).map(({ name }) => name);
30
+ const dts = {
31
+ dts: pwaIcons({
32
+ transparent: transparentNames,
33
+ maskable: maskableNames,
34
+ favicon: faviconNames,
35
+ apple: appleNames,
36
+ appleSplashScreen: appleSplashScreenNames
37
+ }),
38
+ transparent: generatePwaImageType("PwaTransparentImageProps", transparentNames),
39
+ maskable: generatePwaImageType("PwaMaskableImageProps", maskableNames),
40
+ favicon: generatePwaImageType("PwaFaviconImageProps", faviconNames),
41
+ apple: generatePwaImageType("PwaAppleImageProps", appleNames),
42
+ appleSplashScreen: generatePwaImageType("PwaAppleSplashScreenImageProps", appleSplashScreenNames)
43
+ };
44
+ const components = [];
45
+ const names = [];
46
+ const mapTypes = {
47
+ apple: {
48
+ union: appleNames.length > 0 ? appleNames.map((name) => `'${name}'`).join(" | ") : "string",
49
+ validator: appleNames.length > 0 ? `(value) => [${appleNames.map((name) => `'${name}'`).join(", ")}].includes(value)` : "(value) => true"
50
+ },
51
+ appleSplashScreen: {
52
+ union: appleSplashScreenNames.length > 0 ? appleSplashScreenNames.map((name) => `'${name}'`).join(" | ") : "string",
53
+ validator: appleSplashScreenNames.length > 0 ? `(value) => [${appleSplashScreenNames.map((name) => `'${name}'`).join(", ")}].includes(value)` : "(value) => true"
54
+ },
55
+ favicon: {
56
+ union: faviconNames.length > 0 ? faviconNames.map((name) => `'${name}'`).join(" | ") : "string",
57
+ validator: faviconNames.length > 0 ? `(value) => [${faviconNames.map((name) => `'${name}'`).join(", ")}].includes(value)` : "(value) => true"
58
+ },
59
+ maskable: {
60
+ union: maskableNames.length > 0 ? maskableNames.map((name) => `'${name}'`).join(" | ") : "string",
61
+ validator: maskableNames.length > 0 ? `(value) => [${maskableNames.map((name) => `'${name}'`).join(", ")}].includes(value)` : "(value) => true"
62
+ },
63
+ transparent: {
64
+ union: transparentNames.length > 0 ? transparentNames.map((name) => `'${name}'`).join(" | ") : "string",
65
+ validator: transparentNames.length > 0 ? `(value) => [${transparentNames.map((name) => `'${name}'`).join(", ")}].includes(value)` : "(value) => true"
66
+ }
67
+ };
68
+ for (const [name, composable, map] of [
69
+ ["PwaAppleImage", "useApplePwaIcon", "apple"],
70
+ ["PwaAppleSplashScreenImage", "useAppleSplashScreenPwaIcon", "appleSplashScreen"],
71
+ ["PwaFaviconImage", "useFaviconPwaIcon", "favicon"],
72
+ ["PwaMaskableImage", "useMaskablePwaIcon", "maskable"],
73
+ ["PwaTransparentImage", "useTransparentPwaIcon", "transparent"]
74
+ ]) {
75
+ names.push(name);
76
+ components.push(addTemplate({
77
+ write: true,
78
+ filename: `pwa-icons/${name}.js`,
79
+ getContents: () => `// Generated by @vite-pwa/nuxt
80
+ import { defineComponent, h } from 'vue'
81
+ import { ${composable} } from '#pwa'
82
+
83
+ const ${name} = /* #__PURE__ */ defineComponent({
84
+ name: '${name}',
85
+ inheritAttrs: false,
86
+ props: {
87
+ image: {
88
+ required: true,
89
+ type: String,
90
+ validator: ${mapTypes[map].validator}
91
+ },
92
+ width: {
93
+ type: [Number, String],
94
+ required: false
95
+ },
96
+ height: {
97
+ type: [Number, String],
98
+ required: false
99
+ }
100
+ },
101
+ setup(props, { attrs = {} }) {
102
+ const { icon } = ${composable}(props)
103
+ return () => {
104
+ const data = icon.value
105
+ if (!data) {
106
+ return
107
+ }
108
+
109
+ return h('img', Object.assign({}, attrs, data))
110
+ }
111
+ }
112
+ })
113
+
114
+ export default ${name}
115
+ `
116
+ }).filename);
117
+ components.push(addTemplate({
118
+ write: true,
119
+ filename: `pwa-icons/${name}.d.ts`,
120
+ getContents: () => `// Generated by @vite-pwa/nuxt
121
+ import type { AllowedComponentProps, ComponentCustomProps, ImgHTMLAttributes, VNodeProps } from 'vue'
122
+
123
+ export interface ${name}Props extends Omit<ImgHTMLAttributes, 'src'> {
124
+ /**
125
+ * Name of the PWA icon to render.
126
+ * @type {${mapTypes[map].union}}
127
+ */
128
+ image: ${mapTypes[map].union}
129
+ }
130
+
131
+ declare const _default: {
132
+ new (): {
133
+ $props: AllowedComponentProps & ComponentCustomProps & VNodeProps & ${name}Props;
134
+ };
135
+ };
136
+
137
+ export default _default
138
+ `
139
+ }).filename);
140
+ }
141
+ nuxt.options.alias["#pwa-components"] = addTemplate({
142
+ write: true,
143
+ filename: "pwa-icons/components.ts",
144
+ getContents: () => names.map((name) => `export { default as ${name} } from './${name}.js'`).join("\n")
145
+ }).dst;
146
+ nuxt.options.build.transpile.push("#pwa-components");
147
+ for (const name of names) {
148
+ addComponent({
149
+ name,
150
+ filePath: `#build/pwa-icons/${name}`
151
+ });
152
+ }
153
+ if (nuxt.options.dev) {
154
+ for (const source of pwaAssetsContext.sources()) {
155
+ nuxt.options.watch.push(normalizePath(source));
156
+ }
157
+ }
158
+ return dts;
159
+ }
160
+
161
+ export { preparePWAIcons };
package/dist/module.d.mts CHANGED
@@ -1,110 +1,63 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { HookResult } from '@nuxt/schema';
3
- import { VitePWAOptions, ResolvedVitePWAOptions } from 'vite-plugin-pwa';
3
+ import { ResolvedVitePWAOptions, VitePWAStrategy } from '@unplugin-pwa/core';
4
+ import { TrustedScriptURL, PWATrustedScriptURL } from '@unplugin-pwa/core/types';
5
+ import { PwaOptions } from '@vite-pwa/nuxt-core/types';
6
+ import { Strategy } from '@vite-pwa/workbox-build/config/types';
7
+ import { SWType } from '@vite-pwa/workbox-build/types';
8
+ export { definePwaConfig } from '@vite-pwa/nuxt-core/config';
4
9
 
5
- interface ClientOptions {
6
- /**
7
- * Exposes the plugin: defaults to true.
8
- */
9
- registerPlugin?: boolean;
10
- /**
11
- * Registers a periodic sync for updates interval: value in seconds.
12
- */
13
- periodicSyncForUpdates?: number;
14
- /**
15
- * Will prevent showing native PWA install prompt: defaults to false.
16
- *
17
- * When set to true or no empty string, the native PWA install prompt will be prevented.
18
- *
19
- * When set to a string, it will be used as the key in `localStorage` to prevent show the PWA install prompt widget.
20
- *
21
- * When set to true, the key used will be `vite-pwa:hide-install`.
22
- */
23
- installPrompt?: boolean | string;
24
- }
25
- interface PwaModuleOptions extends Partial<VitePWAOptions> {
26
- /**
27
- * Experimental features.
28
- */
29
- experimental?: {
30
- /**
31
- * NOTE: this option will be ignored if using the `injectManifest` strategy or when Nuxt experimental payload
32
- * extraction is disabled.
33
- *
34
- * Enable custom runtime caching to resolve the payload.json requests with query parameters when offline:
35
- * - Workbox doesn't allow to configure `precacheAndRoute` `urlManipulation` option when using the `generateSW` strategy.
36
- * - Nuxt SSG will generate a payload.json file and will fetch it with a query parameter.
37
- * - The service worker cannot resolve the payload.json request with query parameters, and you won't get the payload when offline.
38
- *
39
- * Enabling this option will add a custom runtime caching handler to the service worker to resolve the payload files
40
- * with query parameters when offline: the runtime caching handler will redirect to the payload.json file without
41
- * query parameters when the original request fails.
42
- *
43
- * If you're using `injectManifest` strategy, you can fix the issue in your custom service worker adding the
44
- * following `urlManipulation` callback to the `precacheAndRouter` call:
45
- * ```ts
46
- * // self.__WB_MANIFEST is the default injection point
47
- * precacheAndRoute(
48
- * self.__WB_MANIFEST,
49
- * {
50
- * urlManipulation: ({ url }) => {
51
- * const urls: URL[] = []
52
- * if (url.pathname.endsWith('_payload.json')) {
53
- * const newUrl = new URL(url.href)
54
- * newUrl.search = ''
55
- * urls.push(newUrl)
56
- * }
57
- * return urls
58
- * }
59
- * }
60
- * )
61
- * ```
62
- */
63
- enableWorkboxPayloadQueryParams?: true;
64
- };
65
- registerWebManifestInRouteRules?: boolean;
66
- /**
67
- * Writes the plugin to disk: defaults to false (debug).
68
- */
69
- writePlugin?: boolean;
70
- /**
71
- * Options for plugin.
72
- */
73
- client?: ClientOptions;
74
- }
10
+ type ModuleOptions = PwaOptions<VitePWAStrategy, SWType>;
11
+ /**
12
+ * @deprecated Use `ModuleOptions` instead.
13
+ */
14
+ type PwaModuleOptions = ModuleOptions;
75
15
  interface PwaModuleHooks {
76
- 'pwa:beforeBuildServiceWorker': (options: ResolvedVitePWAOptions) => HookResult;
16
+ 'pwa:beforeBuildServiceWorker': BeforeBuildServiceWorkerHook;
77
17
  }
78
-
79
- interface ModuleOptions extends PwaModuleOptions {
18
+ type ModuleHooks = PwaModuleHooks;
19
+ type BeforeBuildServiceWorkerHook<S extends Strategy = 'generate-sw', T extends SWType = 'classic'> = (options: ResolvedVitePWAOptions<S, T>) => HookResult;
20
+ interface ServiceWorkerRuntimeHooksOptions {
21
+ url: string;
22
+ registration?: ServiceWorkerRegistration;
80
23
  }
81
- interface ModuleHooks extends PwaModuleHooks {
24
+ interface ServiceWorkerRegistrationErrorOptions {
25
+ error?: unknown;
82
26
  }
83
- interface ModuleRuntimeHooks {
27
+ interface ServiceWorkerPeriodicSyncUpdateError {
28
+ url: string;
29
+ error?: unknown;
30
+ registration: ServiceWorkerRegistration;
31
+ }
32
+ interface PWAModuleRuntimeHooks {
33
+ /**
34
+ * Emitted before service worker registration to allow use `TrustedScriptURL`
35
+ * @param withTrustedScriptUrl The callback to change the configuration.
36
+ */
37
+ 'service-worker:before-register': (withTrustedScriptUrl: (trustedScriptUrl?: TrustedScriptURL | PWATrustedScriptURL) => void) => HookResult;
84
38
  /**
85
39
  * Emitted when the service worker is registered
86
40
  * @param data The url and the optional service worker registration object
87
41
  */
88
- 'service-worker:registered': (data: {
89
- url: string;
90
- registration?: ServiceWorkerRegistration;
91
- }) => HookResult;
42
+ 'service-worker:registered': (data: ServiceWorkerRuntimeHooksOptions) => HookResult;
92
43
  /**
93
44
  * Emitted when the service worker registration fails
94
45
  * @param data The optional error object
95
46
  */
96
- 'service-worker:registration-failed': (data: {
97
- error?: unknown;
98
- }) => HookResult;
47
+ 'service-worker:registration-failed': (data: ServiceWorkerRegistrationErrorOptions) => HookResult;
99
48
  /**
100
49
  * Emitted when the service worker is activated
101
50
  * @param data The url and the service worker registration object
102
51
  */
103
- 'service-worker:activated': (data: {
104
- url: string;
105
- registration: ServiceWorkerRegistration;
106
- }) => HookResult;
52
+ 'service-worker:activated': (data: ServiceWorkerRuntimeHooksOptions) => HookResult;
53
+ /**
54
+ * Emitted when the service worker fails to update.
55
+ * @param data The url, the error and the service worker registration object.
56
+ */
57
+ 'service-worker:periodic-sync-update-failed': (data: ServiceWorkerPeriodicSyncUpdateError) => HookResult;
107
58
  }
108
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
59
+ type ModuleRuntimeHooks = PWAModuleRuntimeHooks;
60
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
109
61
 
110
- export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, _default as default };
62
+ export { _default as default };
63
+ export type { BeforeBuildServiceWorkerHook, ModuleHooks, ModuleOptions, ModuleRuntimeHooks, PWAModuleRuntimeHooks, PwaModuleHooks, PwaModuleOptions, ServiceWorkerPeriodicSyncUpdateError, ServiceWorkerRegistrationErrorOptions, ServiceWorkerRuntimeHooksOptions };
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
- "name": "pwa",
2
+ "name": "@vite-pwa/nuxt",
3
3
  "configKey": "pwa",
4
4
  "compatibility": {
5
- "nuxt": ">=3.6.5"
5
+ "nuxt": ">=3.9.0"
6
6
  },
7
- "version": "1.1.0",
7
+ "version": "2.0.1",
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.3",
10
- "unbuild": "2.0.0"
9
+ "@nuxt/module-builder": "1.0.3",
10
+ "unbuild": "3.6.1"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -1,8 +1,40 @@
1
- import '@nuxt/kit';
2
- export { m as default } from './shared/nuxt.00c26fe8.mjs';
3
- import 'node:fs/promises';
4
- import 'node:path';
5
- import 'vite-plugin-pwa';
6
- import 'node:crypto';
7
- import 'node:fs';
8
- import 'pathe';
1
+ import { defineNuxtModule, createResolver } from '@nuxt/kit';
2
+ export { definePwaConfig } from '@vite-pwa/nuxt-core/config';
3
+
4
+ const module$1 = defineNuxtModule({
5
+ meta: {
6
+ name: "@vite-pwa/nuxt",
7
+ configKey: "pwa",
8
+ compatibility: {
9
+ nuxt: ">=3.9.0"
10
+ }
11
+ },
12
+ defaults: (nuxt) => ({
13
+ base: nuxt.options.app.baseURL,
14
+ scope: nuxt.options.app.baseURL,
15
+ injectRegister: false,
16
+ includeManifestIcons: false,
17
+ writePlugin: false,
18
+ client: {
19
+ registerPlugin: true,
20
+ installPrompt: false,
21
+ periodicSyncForUpdates: 0
22
+ }
23
+ }),
24
+ async setup(options, nuxt) {
25
+ const [{ createNuxtPwaContext }, { prepareModule }] = await Promise.all([
26
+ import('./chunks/create-nuxt-pwa-context.mjs'),
27
+ import('./chunks/prepare-module.mjs').then(function (n) { return n.a; })
28
+ ]);
29
+ const ctx = await createNuxtPwaContext(
30
+ options,
31
+ nuxt,
32
+ createResolver(import.meta.url)
33
+ );
34
+ if (ctx) {
35
+ await prepareModule(ctx, nuxt);
36
+ }
37
+ }
38
+ });
39
+
40
+ export { module$1 as default };
@@ -1,2 +1,2 @@
1
- declare const _default: import("vue").DefineComponent<{}, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("#imports").ExtractPropTypes<{}>>, {}, {}>;
1
+ declare const _default: import("vue").DefineComponent<{}, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
2
  export default _default;
@@ -1,15 +1,19 @@
1
- import { useHead } from "#imports";
2
1
  import { pwaAssetsHead } from "virtual:pwa-assets/head";
3
2
  import { pwaInfo } from "virtual:pwa-info";
4
3
  import { defineComponent, ref } from "vue";
4
+ import { useHead } from "#imports";
5
5
  export default defineComponent({
6
6
  setup() {
7
7
  const meta = ref({ link: [] });
8
8
  useHead(meta);
9
- if (pwaAssetsHead.themeColor)
10
- meta.value.meta = [{ name: "theme-color", content: pwaAssetsHead.themeColor.content }];
11
- if (pwaAssetsHead.links.length)
9
+ if (pwaAssetsHead.themeColor) {
10
+ meta.value.meta = [
11
+ { name: "theme-color", content: pwaAssetsHead.themeColor.content }
12
+ ];
13
+ }
14
+ if (pwaAssetsHead.links.length) {
12
15
  meta.value.link.push(...pwaAssetsHead.links);
16
+ }
13
17
  if (pwaInfo) {
14
18
  const { webManifest } = pwaInfo;
15
19
  if (webManifest) {
@@ -1,2 +1,2 @@
1
- declare const _default: import("vue").DefineComponent<{}, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("#imports").ExtractPropTypes<{}>>, {}, {}>;
1
+ declare const _default: import("vue").DefineComponent<{}, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
2
  export default _default;
@@ -1,8 +1,8 @@
1
- import { useHead } from "#imports";
2
1
  import { pwaInfo } from "virtual:pwa-info";
3
2
  import { defineComponent, ref } from "vue";
3
+ import { useHead } from "#imports";
4
4
  export default defineComponent({
5
- async setup() {
5
+ setup() {
6
6
  if (pwaInfo) {
7
7
  const meta = ref({ link: [] });
8
8
  useHead(meta);
@@ -1,33 +1,17 @@
1
- import type { PwaAppleImageProps } from '#build/pwa-icons/PwaAppleImage';
2
- import type { PwaAppleSplashScreenImageProps } from '#build/pwa-icons/PwaAppleSplashScreenImage';
3
- import type { PwaFaviconImageProps } from '#build/pwa-icons/PwaFaviconImage';
4
- import type { PwaMaskableImageProps } from '#build/pwa-icons/PwaMaskableImage';
5
- import type { PwaTransparentImageProps } from '#build/pwa-icons/PwaTransparentImage';
6
- import type { MaybeRef, UnwrapNestedRefs } from 'vue';
7
- import type { PwaInjection } from '../plugins/types.js';
8
- export interface PWAImage {
1
+ import type { ImgHTMLAttributes, MaybeRef, UnwrapNestedRefs } from 'vue';
2
+ import type { PwaAppleImageProps } from '#build/pwa-icons/PwaAppleImageProps';
3
+ import type { PwaAppleSplashScreenImageProps } from '#build/pwa-icons/PwaAppleSplashScreenImageProps';
4
+ import type { PwaFaviconImageProps } from '#build/pwa-icons/PwaFaviconImageProps';
5
+ import type { PwaMaskableImageProps } from '#build/pwa-icons/PwaMaskableImageProps';
6
+ import type { PwaTransparentImageProps } from '#build/pwa-icons/PwaTransparentImageProps';
7
+ import type { PwaInjection } from './plugins/types.js';
8
+ export type PWAVueImageType = Omit<ImgHTMLAttributes, 'src'>;
9
+ export type PWAImage = PWAVueImageType & {
9
10
  image: string;
10
- alt?: string;
11
- width?: number;
12
- height?: number;
13
- crossorigin?: '' | 'anonymous' | 'use-credentials';
14
- loading?: 'lazy' | 'eager';
15
- decoding?: 'async' | 'auto' | 'sync';
16
- nonce?: string;
17
- [key: string]: any;
18
- }
19
- export interface PWAIcon {
20
- src: string;
11
+ };
12
+ export type PWAIcon = ImgHTMLAttributes & {
21
13
  key: any;
22
- alt?: string;
23
- width?: number;
24
- height?: number;
25
- crossorigin?: '' | 'anonymous' | 'use-credentials';
26
- loading?: 'lazy' | 'eager';
27
- decoding?: 'async' | 'auto' | 'sync';
28
- nonce?: string;
29
- [key: string]: any;
30
- }
14
+ };
31
15
  export type PWAImageType<T> = T extends 'transparent' ? PwaTransparentImageProps['image'] | (Omit<PWAImage, 'image'> & {
32
16
  image: PwaTransparentImageProps['image'];
33
17
  }) : T extends 'maskable' ? PwaMaskableImageProps['image'] | Omit<PWAImage, 'image'> & {
@@ -1,5 +1,5 @@
1
- import { useNuxtApp } from "#imports";
2
1
  import { computed, toValue } from "vue";
2
+ import { useNuxtApp } from "#imports";
3
3
  export function useTransparentPwaIcon(image) {
4
4
  return usePWAIcon("transparent", image);
5
5
  }
@@ -35,24 +35,14 @@ function usePWAIcon(type, pwaImage) {
35
35
  };
36
36
  }
37
37
  const {
38
- alt,
39
38
  width,
40
39
  height,
41
- crossorigin,
42
- loading,
43
- decoding,
44
- nonce,
45
40
  image: _image,
46
41
  ...rest
47
42
  } = pwaIcon;
48
43
  return {
49
- alt,
50
44
  width: width ?? image.width,
51
45
  height: height ?? image.height,
52
- crossorigin,
53
- loading,
54
- decoding,
55
- nonce,
56
46
  ...rest,
57
47
  key: image.key,
58
48
  src: image.src
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '#app';
2
+ import type { PwaInstallPromptInjection } from './types.js';
3
+ declare const plugin: Plugin<{
4
+ pwaInstallPrompt: PwaInstallPromptInjection;
5
+ }>;
6
+ export default plugin;
@@ -0,0 +1,70 @@
1
+ import {
2
+ display,
3
+ installPrompt
4
+ } from "virtual:nuxt-pwa-configuration";
5
+ import { defineNuxtPlugin, nextTick, ref } from "#imports";
6
+ const plugin = defineNuxtPlugin({
7
+ name: "vite-pwa:nuxt:client:install-prompt-plugin",
8
+ enforce: "pre",
9
+ setup() {
10
+ const showInstallPrompt = ref(false);
11
+ const hideInstall = ref(
12
+ !installPrompt ? true : localStorage.getItem(installPrompt) === "true"
13
+ );
14
+ const ua = navigator.userAgent;
15
+ const ios = ua.match(/iPhone|iPad|iPod/);
16
+ const useDisplay = display === "standalone" || display === "minimal-ui" ? `${display}` : "standalone";
17
+ const standalone = window.matchMedia(`(display-mode: ${useDisplay})`).matches;
18
+ const isInstalled = ref(!!(standalone || ios && !ua.match(/Safari/)));
19
+ const isPWAInstalled = ref(isInstalled.value);
20
+ window.matchMedia(`(display-mode: ${useDisplay})`).addEventListener("change", (e) => {
21
+ if (!isPWAInstalled.value && e.matches) {
22
+ isPWAInstalled.value = true;
23
+ }
24
+ });
25
+ let install = () => Promise.resolve(void 0);
26
+ let cancelInstall = () => {
27
+ };
28
+ if (!hideInstall.value) {
29
+ let deferredPrompt;
30
+ const beforeInstallPrompt = (e) => {
31
+ e.preventDefault();
32
+ deferredPrompt = e;
33
+ showInstallPrompt.value = true;
34
+ };
35
+ window.addEventListener("beforeinstallprompt", beforeInstallPrompt);
36
+ window.addEventListener("appinstalled", () => {
37
+ deferredPrompt = void 0;
38
+ showInstallPrompt.value = false;
39
+ });
40
+ cancelInstall = () => {
41
+ deferredPrompt = void 0;
42
+ showInstallPrompt.value = false;
43
+ window.removeEventListener("beforeinstallprompt", beforeInstallPrompt);
44
+ hideInstall.value = true;
45
+ localStorage.setItem(installPrompt, "true");
46
+ };
47
+ install = async () => {
48
+ if (!showInstallPrompt.value || !deferredPrompt) {
49
+ showInstallPrompt.value = false;
50
+ return void 0;
51
+ }
52
+ showInstallPrompt.value = false;
53
+ await nextTick();
54
+ deferredPrompt.prompt();
55
+ return await deferredPrompt.userChoice;
56
+ };
57
+ }
58
+ return {
59
+ provide: {
60
+ pwaInstallPrompt: {
61
+ isPWAInstalled,
62
+ showInstallPrompt,
63
+ cancelInstall,
64
+ install
65
+ }
66
+ }
67
+ };
68
+ }
69
+ });
70
+ export default plugin;
@@ -1,5 +1,5 @@
1
- import type { Plugin } from '#app';
2
1
  import type { UnwrapNestedRefs } from 'vue';
2
+ import type { Plugin } from '#app';
3
3
  import type { PwaInjection } from './types.js';
4
4
  declare const plugin: Plugin<{
5
5
  pwa?: UnwrapNestedRefs<PwaInjection>;