@barodoc/plugin-pwa 6.0.0 → 8.0.0

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.
@@ -0,0 +1,13 @@
1
+ import * as _barodoc_core from '@barodoc/core';
2
+
3
+ interface PwaPluginOptions {
4
+ name?: string;
5
+ shortName?: string;
6
+ themeColor?: string;
7
+ backgroundColor?: string;
8
+ display?: "standalone" | "fullscreen" | "minimal-ui" | "browser";
9
+ offlineFallback?: string;
10
+ }
11
+ declare const _default: (options: PwaPluginOptions) => _barodoc_core.BarodocPlugin;
12
+
13
+ export { type PwaPluginOptions, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ // src/index.ts
2
+ import { definePlugin } from "@barodoc/core";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ var index_default = definePlugin((options = {}) => {
6
+ const {
7
+ display = "standalone",
8
+ themeColor = "#2563eb",
9
+ backgroundColor = "#ffffff",
10
+ offlineFallback = "/404"
11
+ } = options;
12
+ return {
13
+ name: "@barodoc/plugin-pwa",
14
+ astroIntegration: (context) => {
15
+ const siteName = options.name || context.config.name;
16
+ const shortName = options.shortName || siteName;
17
+ const integration = {
18
+ name: "@barodoc/plugin-pwa",
19
+ hooks: {
20
+ "astro:config:setup": ({ injectScript }) => {
21
+ injectScript(
22
+ "head-inline",
23
+ `document.head.insertAdjacentHTML('beforeend', '<link rel="manifest" href="/manifest.json" />');`
24
+ );
25
+ injectScript(
26
+ "page",
27
+ `
28
+ if ("serviceWorker" in navigator) {
29
+ navigator.serviceWorker.register("/sw.js").catch(() => {});
30
+ }
31
+ `
32
+ );
33
+ },
34
+ "astro:build:done": async ({ dir }) => {
35
+ const outDir = dir.pathname;
36
+ const manifest = {
37
+ name: siteName,
38
+ short_name: shortName,
39
+ start_url: "/",
40
+ display,
41
+ theme_color: themeColor,
42
+ background_color: backgroundColor,
43
+ icons: [
44
+ { src: "/favicon.ico", sizes: "64x64", type: "image/x-icon" }
45
+ ]
46
+ };
47
+ fs.writeFileSync(
48
+ path.join(outDir, "manifest.json"),
49
+ JSON.stringify(manifest, null, 2)
50
+ );
51
+ const sw = `
52
+ const CACHE_NAME = "barodoc-v1";
53
+ const OFFLINE_URL = "${offlineFallback}";
54
+
55
+ self.addEventListener("install", (event) => {
56
+ event.waitUntil(
57
+ caches.open(CACHE_NAME).then((cache) => cache.add(OFFLINE_URL))
58
+ );
59
+ self.skipWaiting();
60
+ });
61
+
62
+ self.addEventListener("activate", (event) => {
63
+ event.waitUntil(
64
+ caches.keys().then((keys) =>
65
+ Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
66
+ )
67
+ );
68
+ self.clients.claim();
69
+ });
70
+
71
+ self.addEventListener("fetch", (event) => {
72
+ if (event.request.mode !== "navigate") return;
73
+ event.respondWith(
74
+ fetch(event.request).catch(() =>
75
+ caches.match(OFFLINE_URL).then((r) => r || new Response("Offline", { status: 503 }))
76
+ )
77
+ );
78
+ });
79
+ `;
80
+ fs.writeFileSync(path.join(outDir, "sw.js"), sw.trim());
81
+ }
82
+ }
83
+ };
84
+ return integration;
85
+ }
86
+ };
87
+ });
88
+ export {
89
+ index_default as default
90
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barodoc/plugin-pwa",
3
- "version": "6.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "PWA and offline support plugin for Barodoc",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,14 +16,14 @@
16
16
  ],
17
17
  "peerDependencies": {
18
18
  "astro": "^5.0.0",
19
- "@barodoc/core": "6.0.0"
19
+ "@barodoc/core": "8.0.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",
23
23
  "astro": "^5.0.0",
24
24
  "tsup": "^8.3.0",
25
25
  "typescript": "^5.7.0",
26
- "@barodoc/core": "6.0.0"
26
+ "@barodoc/core": "8.0.0"
27
27
  },
28
28
  "license": "MIT",
29
29
  "scripts": {