@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.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/client.d.ts +6 -0
- 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-DpKc2x3j.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/info.d.ts +71 -0
- package/package.json +133 -7
- package/preact.d.ts +17 -0
- package/pwa-assets.d.ts +40 -0
- package/react-legacy.d.ts +22 -0
- package/react.d.ts +17 -0
- package/solid.d.ts +17 -0
- package/svelte.d.ts +17 -0
- package/types/index.d.ts +43 -0
- package/types/package.json +3 -0
- package/vanillajs.d.ts +13 -0
- package/vue.d.ts +17 -0
- package/index.js +0 -1
package/info.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
declare module 'virtual:pwa-info' {
|
|
2
|
+
export interface PwaInfo {
|
|
3
|
+
pwaInDevEnvironment: boolean
|
|
4
|
+
/**
|
|
5
|
+
* The web manifest will be always here.
|
|
6
|
+
*/
|
|
7
|
+
webManifest: {
|
|
8
|
+
href: string
|
|
9
|
+
useCredentials: boolean
|
|
10
|
+
/**
|
|
11
|
+
* The link tag with or without `crossorigin`:
|
|
12
|
+
* - `<link rel="manifest" href="<webManifestUrl>" />`.
|
|
13
|
+
* - `<link rel="manifest" href="<webManifestUrl>" crossorigin="use-credentials" />`.
|
|
14
|
+
*/
|
|
15
|
+
linkTag: string
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The service worker data will be exposed only if required, that's, will **NOT** be exposed if:
|
|
19
|
+
* - not using `pwaPluginOptions.injectRegister` with `script`, `script-defer` or `inline` values
|
|
20
|
+
* - if using `pwaPluginOptions.injectRegister` with `auto` (default) and importing any of the virtual modules
|
|
21
|
+
*
|
|
22
|
+
* **NOTE**: `registerSW` will be `undefined` if:
|
|
23
|
+
* - SSR build (only if required)
|
|
24
|
+
* - PWA is disabled: `pwaPluginOptions.disable = true`
|
|
25
|
+
* - running `Dev Server` and `pwaPluginOptions.devOptions.enabled = false` (default).
|
|
26
|
+
*/
|
|
27
|
+
registerSW?: {
|
|
28
|
+
/**
|
|
29
|
+
* Should use `type="module"?
|
|
30
|
+
*
|
|
31
|
+
* **NOTE**: `module` will be `true` **ONLY** at `Dev server` and using dual service worker workers: `classic-and-module`.
|
|
32
|
+
*/
|
|
33
|
+
module: boolean
|
|
34
|
+
/**
|
|
35
|
+
* When this flag is `inline` the service worker must be registered via inline script otherwise registered via script with src attribute `registerSW.js`.
|
|
36
|
+
*/
|
|
37
|
+
mode: 'inline' | 'script' | 'script-defer'
|
|
38
|
+
/**
|
|
39
|
+
* The path for the inline script: will contain the service worker url.
|
|
40
|
+
*/
|
|
41
|
+
inlinePath: string
|
|
42
|
+
/**
|
|
43
|
+
* The path for the src script for `registerSW.js`.
|
|
44
|
+
*/
|
|
45
|
+
registerPath: string
|
|
46
|
+
/**
|
|
47
|
+
* The scope for the service worker: only required for `inline: true`.
|
|
48
|
+
*/
|
|
49
|
+
scope: string
|
|
50
|
+
/**
|
|
51
|
+
* The type for the service worker: only required for `inline: true`.
|
|
52
|
+
*/
|
|
53
|
+
type: 'classic' | 'module'
|
|
54
|
+
/**
|
|
55
|
+
* The script tag if `shouldRegisterSW` returns `true`.
|
|
56
|
+
*/
|
|
57
|
+
scriptTag?: string
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Return the PWA information if available.
|
|
62
|
+
*
|
|
63
|
+
* This property will be `undefined` if:
|
|
64
|
+
* - SSR build
|
|
65
|
+
* - PWA is disabled: `pwaPluginOptions.disable = true`
|
|
66
|
+
* - running `Dev Server` and `pwaPluginOptions.devOptions.enabled = false` (default).
|
|
67
|
+
*
|
|
68
|
+
* @returns The PWA information.
|
|
69
|
+
*/
|
|
70
|
+
export const pwaInfo: PwaInfo | undefined
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unplugin-pwa/core",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "PWA bundler-agnostic core logic and utilities",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
6
|
"author": "Vite PWA's Team",
|
|
7
|
+
"maintainers": [
|
|
8
|
+
"userquin <userquin@gmail.com>"
|
|
9
|
+
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"funding": "https://github.com/sponsors/antfu",
|
|
11
12
|
"homepage": "https://github.com/vite-pwa/unplugin-pwa#readme",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -25,5 +26,130 @@
|
|
|
25
26
|
"agnostic",
|
|
26
27
|
"configuration",
|
|
27
28
|
"helpers"
|
|
28
|
-
]
|
|
29
|
-
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.mts"
|
|
34
|
+
},
|
|
35
|
+
"./additional-manifest-entries": "./dist/additional-manifest-entries.mjs",
|
|
36
|
+
"./build-pwa-asset": "./dist/build-pwa-asset.mjs",
|
|
37
|
+
"./config": "./dist/config.mjs",
|
|
38
|
+
"./constants": "./dist/constants.mjs",
|
|
39
|
+
"./context": "./dist/context.mjs",
|
|
40
|
+
"./context-types": {
|
|
41
|
+
"types": "./dist/context-types.d.mts"
|
|
42
|
+
},
|
|
43
|
+
"./create-generate-register-sw-script": "./dist/create-generate-register-sw-script.mjs",
|
|
44
|
+
"./create-web-manifest-html-link": "./dist/create-web-manifest-html-link.mjs",
|
|
45
|
+
"./dual-sw-utilities": "./dist/dual-sw-utilities.mjs",
|
|
46
|
+
"./generate-register-sw": "./dist/generate-register-sw.mjs",
|
|
47
|
+
"./generate-web-manifest": "./dist/generate-web-manifest.mjs",
|
|
48
|
+
"./html": "./dist/html.mjs",
|
|
49
|
+
"./helpers": "./dist/helpers.mjs",
|
|
50
|
+
"./inject-generate-register-sw": "./dist/inject-generate-register-sw.mjs",
|
|
51
|
+
"./inject-web-manifest-html-link": "./dist/inject-web-manifest-html-link.mjs",
|
|
52
|
+
"./inspector-utils": "./dist/inspector-utils.mjs",
|
|
53
|
+
"./logs": "./dist/logs.mjs",
|
|
54
|
+
"./prepare-pwa-context": "./dist/prepare-pwa-context.mjs",
|
|
55
|
+
"./prepare-sw-names": "./dist/prepare-sw-names.mjs",
|
|
56
|
+
"./resolve-inspector-dist": "./dist/resolve-inspector-dist.mjs",
|
|
57
|
+
"./dev/prepare-sw-names-and-glob-directory": "./dist/dev/prepare-sw-names-and-glob-directory.mjs",
|
|
58
|
+
"./dev/prepare-temp-folder": "./dist/dev/prepare-temp-folder.mjs",
|
|
59
|
+
"./pwa-assets/build": "./dist/pwa-assets/build.mjs",
|
|
60
|
+
"./pwa-assets/config": "./dist/pwa-assets/config.mjs",
|
|
61
|
+
"./pwa-assets/dev": "./dist/pwa-assets/dev.mjs",
|
|
62
|
+
"./pwa-assets/generator": "./dist/pwa-assets/generator.mjs",
|
|
63
|
+
"./pwa-assets/html": "./dist/pwa-assets/html.mjs",
|
|
64
|
+
"./pwa-assets/manifest": "./dist/pwa-assets/manifest.mjs",
|
|
65
|
+
"./pwa-assets/options": "./dist/pwa-assets/options.mjs",
|
|
66
|
+
"./pwa-assets/types": {
|
|
67
|
+
"types": "./dist/pwa-assets/types.d.mts"
|
|
68
|
+
},
|
|
69
|
+
"./pwa-assets/utils": "./dist/pwa-assets/utils.mjs",
|
|
70
|
+
"./types": {
|
|
71
|
+
"types": "./types/index.d.ts"
|
|
72
|
+
},
|
|
73
|
+
"./preact": {
|
|
74
|
+
"types": "./preact.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./react": {
|
|
77
|
+
"types": "./react.d.ts"
|
|
78
|
+
},
|
|
79
|
+
"./react-legacy": {
|
|
80
|
+
"types": "./react-legacy.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./solid": {
|
|
83
|
+
"types": "./solid.d.ts"
|
|
84
|
+
},
|
|
85
|
+
"./svelte": {
|
|
86
|
+
"types": "./svelte.d.ts"
|
|
87
|
+
},
|
|
88
|
+
"./vanillajs": {
|
|
89
|
+
"types": "./vanillajs.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./vue": {
|
|
92
|
+
"types": "./vue.d.ts"
|
|
93
|
+
},
|
|
94
|
+
"./client": {
|
|
95
|
+
"types": "./client.d.ts"
|
|
96
|
+
},
|
|
97
|
+
"./info": {
|
|
98
|
+
"types": "./info.d.ts"
|
|
99
|
+
},
|
|
100
|
+
"./pwa-assets": {
|
|
101
|
+
"types": "./pwa-assets.d.ts"
|
|
102
|
+
},
|
|
103
|
+
"./package.json": "./package.json"
|
|
104
|
+
},
|
|
105
|
+
"files": [
|
|
106
|
+
"*.d.ts",
|
|
107
|
+
"dist",
|
|
108
|
+
"types"
|
|
109
|
+
],
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">=22.14.0"
|
|
112
|
+
},
|
|
113
|
+
"peerDependencies": {
|
|
114
|
+
"@vite-pwa/assets-generator": "^1.0.0 || ^2.0.0",
|
|
115
|
+
"rolldown": "^1.0.0-0",
|
|
116
|
+
"vite": "^3.1.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
117
|
+
},
|
|
118
|
+
"peerDependenciesMeta": {
|
|
119
|
+
"@vite-pwa/assets-generator": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"rolldown": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"vite": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"dependencies": {
|
|
130
|
+
"@vite-pwa/workbox-build": "^8.0.13",
|
|
131
|
+
"hookable": "^6.1.2"
|
|
132
|
+
},
|
|
133
|
+
"devDependencies": {
|
|
134
|
+
"@types/react": "^19.3.0",
|
|
135
|
+
"@vite-pwa/assets-generator": "^2.0.0",
|
|
136
|
+
"preact": "^10.29.8",
|
|
137
|
+
"react": "^19.3.1",
|
|
138
|
+
"rolldown": "^1.2.14",
|
|
139
|
+
"solid-js": "^1.9.17",
|
|
140
|
+
"svelte": "^5.57.2",
|
|
141
|
+
"vite": "^8.3.5",
|
|
142
|
+
"vue": "^3.5.44"
|
|
143
|
+
},
|
|
144
|
+
"publishConfig": {
|
|
145
|
+
"access": "public",
|
|
146
|
+
"provenance": true
|
|
147
|
+
},
|
|
148
|
+
"scripts": {
|
|
149
|
+
"build": "tsdown --config-loader unrun",
|
|
150
|
+
"test:typecheck": "tsc --noEmit",
|
|
151
|
+
"test:ci": "vitest run --coverage",
|
|
152
|
+
"test": "vitest",
|
|
153
|
+
"test:ui": "vitest --ui --open --coverage"
|
|
154
|
+
}
|
|
155
|
+
}
|
package/preact.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/preact' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when preact/hooks is not installed
|
|
5
|
+
import type { Dispatch, StateUpdater } from 'preact/hooks'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [boolean, Dispatch<StateUpdater<boolean>>]
|
|
11
|
+
offlineReady: [boolean, Dispatch<StateUpdater<boolean>>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/pwa-assets.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* WARNING: these virtual modules are meant to be used by integrations and not being consumed directly from applications */
|
|
2
|
+
|
|
3
|
+
declare module 'virtual:pwa-assets/head' {
|
|
4
|
+
export interface PWAAssetHeadLink {
|
|
5
|
+
id?: string
|
|
6
|
+
rel: 'apple-touch-startup-image' | 'apple-touch-icon' | 'icon'
|
|
7
|
+
href: string
|
|
8
|
+
media?: string
|
|
9
|
+
sizes?: string
|
|
10
|
+
type?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ColorSchemeMeta {
|
|
14
|
+
name: string
|
|
15
|
+
content: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PWAAssetsHead {
|
|
19
|
+
links: PWAAssetHeadLink[]
|
|
20
|
+
themeColor?: ColorSchemeMeta
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const pwaAssetsHead: PWAAssetsHead
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module 'virtual:pwa-assets/icons' {
|
|
27
|
+
import type { AppleSplashScreenLink, FaviconLink, HtmlLink, IconAsset } from '@vite-pwa/assets-generator/api'
|
|
28
|
+
|
|
29
|
+
export type PWAAssetIcon<T extends HtmlLink> = Omit<IconAsset<T>, 'buffer'>
|
|
30
|
+
|
|
31
|
+
export interface PWAAssetsIcons {
|
|
32
|
+
favicon: Record<string, PWAAssetIcon<FaviconLink>>
|
|
33
|
+
transparent: Record<string, PWAAssetIcon<HtmlLink>>
|
|
34
|
+
maskable: Record<string, PWAAssetIcon<HtmlLink>>
|
|
35
|
+
apple: Record<string, PWAAssetIcon<HtmlLink>>
|
|
36
|
+
appleSplashScreen: Record<string, PWAAssetIcon<AppleSplashScreenLink>>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const pwaAssetsIcons: PWAAssetsIcons
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module is a legacy version of the PWA register hook for React and will
|
|
3
|
+
* be removed in the next major version.
|
|
4
|
+
* @deprecated use `virtual:pwa-register/react` instead
|
|
5
|
+
*/
|
|
6
|
+
declare module 'virtual:pwa-register/react-legacy' {
|
|
7
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
8
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
9
|
+
// @ts-ignore ignore when react is not installed
|
|
10
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
11
|
+
|
|
12
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
13
|
+
|
|
14
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
15
|
+
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
16
|
+
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
17
|
+
/**
|
|
18
|
+
* Reloads the current window to allow the service worker take the control.
|
|
19
|
+
*/
|
|
20
|
+
updateServiceWorker: () => Promise<void>
|
|
21
|
+
}
|
|
22
|
+
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/react' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when react is not installed
|
|
5
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
11
|
+
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/solid.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/solid' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when solid-js is not installed
|
|
5
|
+
import type { Accessor, Setter } from 'solid-js'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [Accessor<boolean>, Setter<boolean>]
|
|
11
|
+
offlineReady: [Accessor<boolean>, Setter<boolean>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/svelte.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/svelte' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when svelte is not installed
|
|
5
|
+
import type { Writable } from 'svelte/store'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: Writable<boolean>
|
|
11
|
+
offlineReady: Writable<boolean>
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { TrustedScriptURL } from 'trusted-types/lib'
|
|
2
|
+
|
|
3
|
+
export type { TrustedScriptURL } from 'trusted-types/lib'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A function that returns the service worker trusted script url.
|
|
7
|
+
*
|
|
8
|
+
* @param classic Whether the browser is in legacy mode (i.e. not supporting ES modules in service workers).
|
|
9
|
+
* @param swUrl The url for the service worker.
|
|
10
|
+
* @returns The service worker script url.
|
|
11
|
+
*/
|
|
12
|
+
export type PWATrustedScriptURL = (classic: boolean, swUrl: string) => TrustedScriptURL
|
|
13
|
+
|
|
14
|
+
export interface RegisterSWOptions {
|
|
15
|
+
immediate?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* Called when the service worker has taken control and the page would normally reload.
|
|
18
|
+
*
|
|
19
|
+
* Useful to fully control the reload flow (for example, to defer reload until the next
|
|
20
|
+
* SPA navigation).
|
|
21
|
+
*/
|
|
22
|
+
onNeedReload?: () => void
|
|
23
|
+
onNeedRefresh?: () => void
|
|
24
|
+
onOfflineReady?: () => void
|
|
25
|
+
/**
|
|
26
|
+
* Service worker trusted script url.
|
|
27
|
+
*
|
|
28
|
+
* @since 2.0.0
|
|
29
|
+
*/
|
|
30
|
+
trustedScriptUrl?: TrustedScriptURL | PWATrustedScriptURL
|
|
31
|
+
/**
|
|
32
|
+
* Called once the service worker is registered (requires version `0.12.8+`).
|
|
33
|
+
*
|
|
34
|
+
* @param swScriptUrl The service worker script url.
|
|
35
|
+
* @param registration The service worker registration if available.
|
|
36
|
+
*/
|
|
37
|
+
onRegisteredSW?: (swScriptUrl: string, registration: ServiceWorkerRegistration | undefined) => void
|
|
38
|
+
onRegisterError?: (error: unknown) => void
|
|
39
|
+
/**
|
|
40
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/updateViaCache
|
|
41
|
+
*/
|
|
42
|
+
updateViaCache?: ServiceWorkerUpdateViaCache
|
|
43
|
+
}
|
package/vanillajs.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
|
|
4
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers the service worker returning a callback to reload the current page when an update is found.
|
|
8
|
+
*
|
|
9
|
+
* @param options the options to register the service worker.
|
|
10
|
+
* @return The callback to activate the new service worker.
|
|
11
|
+
*/
|
|
12
|
+
export function registerSW(options?: RegisterSWOptions): () => Promise<void>
|
|
13
|
+
}
|
package/vue.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/vue' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions, TrustedScriptURL } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when vue is not installed
|
|
5
|
+
import type { Ref } from 'vue'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions, TrustedScriptURL }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: Ref<boolean>
|
|
11
|
+
offlineReady: Ref<boolean>
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|