@abraca/junis 2.88.0 → 2.90.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.
Files changed (30) hide show
  1. package/dist/module.d.mts +39 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +57 -0
  4. package/dist/runtime/components/JunNavMenu.client.vue +24 -1
  5. package/dist/runtime/components/JunOfflinePanel.client.d.vue.ts +3 -0
  6. package/dist/runtime/components/JunOfflinePanel.client.vue +293 -0
  7. package/dist/runtime/components/JunOfflinePanel.client.vue.d.ts +3 -0
  8. package/dist/runtime/components/renderers/JunConfigRenderer.vue +132 -0
  9. package/dist/runtime/composables/useJunCommands.d.ts +1 -1
  10. package/dist/runtime/composables/useJunCommands.js +14 -1
  11. package/dist/runtime/composables/useJunOffline.d.ts +109 -0
  12. package/dist/runtime/composables/useJunOffline.js +294 -0
  13. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  14. package/dist/runtime/composables/useJunSettings.js +2 -0
  15. package/dist/runtime/composables/useJunSiteConfig.d.ts +19 -0
  16. package/dist/runtime/layouts/jun.vue +12 -2
  17. package/dist/runtime/server/api/offline.get.d.ts +10 -0
  18. package/dist/runtime/server/api/offline.get.js +13 -0
  19. package/dist/runtime/server/plugins/jun-compress.d.ts +2 -0
  20. package/dist/runtime/server/plugins/jun-compress.js +76 -0
  21. package/dist/runtime/server/routes/jun-sw.js.get.js +66 -13
  22. package/dist/runtime/server/routes/sitemap.xml.get.js +5 -18
  23. package/dist/runtime/server/utils/junPages.d.ts +51 -0
  24. package/dist/runtime/server/utils/junPages.js +70 -0
  25. package/dist/runtime/types.d.ts +70 -0
  26. package/dist/runtime/utils/junOffline.d.ts +138 -0
  27. package/dist/runtime/utils/junOffline.js +73 -0
  28. package/dist/runtime/utils/junViewSpecs.d.ts +1 -1
  29. package/dist/types.d.mts +1 -1
  30. package/package.json +10 -8
@@ -1,10 +1,12 @@
1
1
  import { defineEventHandler, setResponseHeader } from "h3";
2
2
  import { useRuntimeConfig } from "nitropack/runtime";
3
+ import { junOfflineCacheName, JUN_OFFLINE_MODE_URL } from "../../utils/junOffline.js";
3
4
  export default defineEventHandler((event) => {
4
5
  const config = useRuntimeConfig();
5
6
  const jun = config.public.jun;
6
7
  const build = config.app?.buildId ?? "dev";
7
8
  const apiBase = jun?.apiBase ?? "/api/_jun";
9
+ const cache = junOfflineCacheName(build);
8
10
  setResponseHeader(event, "content-type", "text/javascript; charset=utf-8");
9
11
  setResponseHeader(event, "service-worker-allowed", "/");
10
12
  setResponseHeader(event, "cache-control", "no-cache");
@@ -25,8 +27,30 @@ self.addEventListener('activate', (event) => {
25
27
  `;
26
28
  }
27
29
  return `/* @abraca/junis service worker \u2014 generated, do not edit */
28
- const CACHE = 'jun-${build}'
30
+ const CACHE = ${JSON.stringify(cache)}
29
31
  const API_BASE = ${JSON.stringify(apiBase)}
32
+ const MODE_URL = ${JSON.stringify(JUN_OFFLINE_MODE_URL)}
33
+
34
+ /**
35
+ * How much of the site this visitor keeps: 'off' | 'visited' | 'site'.
36
+ *
37
+ * Read from the CACHE, not from localStorage, which does not exist in a worker
38
+ * \u2014 and a worker restarts independently of the tab that configured it, so a
39
+ * value held only in memory is a setting that lasts until the browser feels
40
+ * like evicting this thread. Memoised, and dropped when the page says so.
41
+ */
42
+ let modePromise = null
43
+
44
+ function readMode() {
45
+ if (!modePromise) {
46
+ modePromise = caches.open(CACHE)
47
+ .then(c => c.match(MODE_URL))
48
+ .then(hit => (hit ? hit.json() : null))
49
+ .then(body => (body && body.mode) || 'visited')
50
+ .catch(() => 'visited')
51
+ }
52
+ return modePromise
53
+ }
30
54
 
31
55
  /** Immutable by construction: content-hashed, or fingerprinted in ?v=. */
32
56
  function isImmutable(url) {
@@ -41,7 +65,6 @@ function isImmutable(url) {
41
65
  function isPassThrough(url) {
42
66
  return url.pathname.startsWith(API_BASE)
43
67
  || url.pathname.startsWith('/api/')
44
- || url.pathname.startsWith('/uploads/')
45
68
  || url.pathname === '/manifest.webmanifest'
46
69
  || url.pathname === '/feed.xml'
47
70
  || url.pathname === '/feed.json'
@@ -49,8 +72,8 @@ function isPassThrough(url) {
49
72
  }
50
73
 
51
74
  self.addEventListener('install', () => {
52
- // No precache \u2014 see the header. Take over immediately so a deploy does not
53
- // wait for every tab to close.
75
+ // No precache \u2014 a copy is something a visitor ASKS for. Take over
76
+ // immediately so a deploy does not wait for every tab to close.
54
77
  self.skipWaiting()
55
78
  })
56
79
 
@@ -64,15 +87,18 @@ self.addEventListener('activate', (event) => {
64
87
 
65
88
  self.addEventListener('message', (event) => {
66
89
  if (event.data === 'jun:skip-waiting') self.skipWaiting()
90
+ // The page changed the mode, or emptied the cache. Either way this worker's
91
+ // memoised answer is stale and re-reading it costs one cache match.
92
+ if (event.data === 'jun:mode-changed') modePromise = null
67
93
  })
68
94
 
69
- async function networkFirst(request) {
95
+ async function networkFirst(request, keep) {
70
96
  const cache = await caches.open(CACHE)
71
97
  try {
72
98
  const response = await fetch(request)
73
99
  // Only a real, complete answer is worth keeping. An opaque or errored
74
100
  // response cached here would be served back as the offline page.
75
- if (response && response.ok && response.type === 'basic') {
101
+ if (keep && response && response.ok && response.type === 'basic') {
76
102
  cache.put(request, response.clone())
77
103
  }
78
104
  return response
@@ -100,6 +126,27 @@ async function cacheFirst(request) {
100
126
  return response
101
127
  }
102
128
 
129
+ /**
130
+ * An upload is served from a saved copy and NEVER added to one by browsing.
131
+ *
132
+ * Images are the heavy half \u2014 the one part of a site whose size is a property
133
+ * of its content rather than of its page count \u2014 so filling the cache with
134
+ * them as a reader scrolls is exactly the silent download this whole surface
135
+ * exists to prevent. If a copy holds this image, offline shows it; otherwise
136
+ * offline shows a broken image, which is what it honestly is.
137
+ */
138
+ async function cachedOnlyFallback(request) {
139
+ try {
140
+ return await fetch(request)
141
+ }
142
+ catch (err) {
143
+ const cache = await caches.open(CACHE)
144
+ const hit = await cache.match(request)
145
+ if (hit) return hit
146
+ throw err
147
+ }
148
+ }
149
+
103
150
  self.addEventListener('fetch', (event) => {
104
151
  const request = event.request
105
152
  if (request.method !== 'GET') return
@@ -113,14 +160,20 @@ self.addEventListener('fetch', (event) => {
113
160
  if (url.origin !== self.location.origin) return
114
161
  if (isPassThrough(url)) return
115
162
 
116
- if (isImmutable(url)) {
117
- event.respondWith(cacheFirst(request))
118
- return
119
- }
163
+ const isNav = request.mode === 'navigate'
164
+ const isUpload = url.pathname.startsWith('/uploads/')
165
+ if (!isNav && !isUpload && !isImmutable(url)) return
120
166
 
121
- if (request.mode === 'navigate') {
122
- event.respondWith(networkFirst(request))
123
- }
167
+ event.respondWith((async () => {
168
+ const mode = await readMode()
169
+ // 'off' is a visitor who would rather no storage were used, and it has to
170
+ // mean that on the way IN as well as on the way out \u2014 a worker that keeps
171
+ // filling a cache it refuses to read is the worst of both.
172
+ if (mode === 'off') return fetch(request)
173
+ if (isUpload) return cachedOnlyFallback(request)
174
+ if (isImmutable(url)) return cacheFirst(request)
175
+ return networkFirst(request, true)
176
+ })())
124
177
  })
125
178
  `;
126
179
  });
@@ -1,29 +1,16 @@
1
1
  import { defineEventHandler, setResponseHeader } from "h3";
2
- import { junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
2
+ import { junPublicPages } from "../utils/junPages.js";
3
3
  import { junSiteUrl } from "../utils/junFeed.js";
4
- import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
5
4
  export default defineEventHandler(async (event) => {
6
5
  const site = junSiteUrl();
7
- const rootDocId = junRootDocId();
8
- const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
9
- const urls = Object.entries(idToSlug).filter(([id]) => {
10
- if (id === rootDocId) return false;
11
- const e = tree[id];
12
- if (!e || e.trashed) return false;
13
- if (isJunOwnerOnlyDoc(e)) return false;
14
- if (e.meta?.draft === true) return false;
15
- if (e.meta?.signerId) return false;
16
- if ((e.type ?? "").endsWith("-redirect")) return false;
17
- if (e.meta?.paneDoc || e.meta?.paneWidget) return false;
18
- if (e.meta?.t != null) return false;
19
- return true;
20
- }).map(([, slug]) => `${site}/${slug}`);
6
+ const pages = await junPublicPages();
21
7
  setResponseHeader(event, "content-type", "application/xml; charset=utf-8");
22
8
  return [
23
9
  '<?xml version="1.0" encoding="UTF-8"?>',
24
10
  '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
25
- ` <url><loc>${site}/</loc></url>`,
26
- ...urls.map((u) => ` <url><loc>${u}</loc></url>`),
11
+ // `/` is `junPublicPages`'s first entry, so the root is emitted once,
12
+ // by the same loop as everything else.
13
+ ...pages.map((p) => ` <url><loc>${site}${p.path === "/" ? "/" : p.path}</loc></url>`),
27
14
  "</urlset>"
28
15
  ].join("\n");
29
16
  });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The site's public pages — one list, from the doc cache.
3
+ *
4
+ * ## Why this is a util and not two filters
5
+ *
6
+ * The sitemap and the offline manifest answer the same question — *which pages
7
+ * does this site have that a stranger may see?* — and they answered it with two
8
+ * copies of an eleven-clause filter. The clauses are not obvious ones: mosaic
9
+ * panes that are references, film CHAPTERS whose `meta.t` may legitimately be
10
+ * `0`, guestbook signatures, redirect documents. Every one of those was learned
11
+ * from a page that turned up somewhere it should not have.
12
+ *
13
+ * A second copy of a filter like that does not drift all at once. It drifts by
14
+ * one clause, in the direction of exposing something — which is precisely the
15
+ * failure the clauses exist to prevent. So: one list, two readers.
16
+ *
17
+ * ## The section
18
+ *
19
+ * Each page carries the TOP-LEVEL page it sits under, which the sitemap has no
20
+ * use for and the offline panel is built on: "136 pages" is a number a visitor
21
+ * either accepts or does not, and "136 pages across 9 sections" is a sentence
22
+ * they can read. Computed by walking `parentId` to the root, with a hop limit —
23
+ * a cycle in the tree would otherwise hang the request rather than mislabel a
24
+ * page, and this runs on the server for every visitor.
25
+ */
26
+ import { type JunTreeEntry } from './junCache.js';
27
+ export interface JunPublicPage {
28
+ id: string;
29
+ /** Rooted path, always leading-slash. `/` for the site's own front page. */
30
+ path: string;
31
+ label: string;
32
+ type: string;
33
+ /** Path of the top-level page this one lives under; `''` when it IS one. */
34
+ section: string;
35
+ }
36
+ /**
37
+ * Is this entry a page a visitor may reach?
38
+ *
39
+ * Exported because the tests read it directly — the clauses below are each a
40
+ * page that once appeared somewhere it should not have, and a rule learned that
41
+ * way is worth being able to state on its own.
42
+ */
43
+ export declare function junIsPublicPage(entry: JunTreeEntry | undefined | null): boolean;
44
+ /**
45
+ * Every public page, in tree order, with the front page first.
46
+ *
47
+ * Order is the tree's own `order` within each parent, walked depth-first, so
48
+ * the list reads the way the navigation does. The sitemap does not care; the
49
+ * offline panel shows this list to a person.
50
+ */
51
+ export declare function junPublicPages(): Promise<JunPublicPage[]>;
@@ -0,0 +1,70 @@
1
+ import { junDocTree, junRootDocId, junSlugMap } from "./junCache.js";
2
+ import { isJunOwnerOnlyDoc } from "./junVisibility.js";
3
+ const MAX_DEPTH = 32;
4
+ export function junIsPublicPage(entry) {
5
+ if (!entry || entry.trashed) return false;
6
+ if (isJunOwnerOnlyDoc(entry)) return false;
7
+ if (entry.meta?.draft === true) return false;
8
+ if (entry.meta?.signerId) return false;
9
+ if ((entry.type ?? "").endsWith("-redirect")) return false;
10
+ if (entry.meta?.paneDoc || entry.meta?.paneWidget) return false;
11
+ if (entry.meta?.t != null) return false;
12
+ return true;
13
+ }
14
+ export async function junPublicPages() {
15
+ const rootDocId = junRootDocId();
16
+ const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
17
+ function sectionOf(id) {
18
+ let cursor = tree[id]?.parentId;
19
+ let child = id;
20
+ for (let hop = 0; hop < MAX_DEPTH; hop++) {
21
+ if (!cursor || cursor === rootDocId) return child === id ? "" : child;
22
+ child = cursor;
23
+ cursor = tree[cursor]?.parentId;
24
+ }
25
+ return "";
26
+ }
27
+ const children = /* @__PURE__ */ new Map();
28
+ for (const [id, entry] of Object.entries(tree)) {
29
+ if (id === rootDocId) continue;
30
+ const parent = entry?.parentId || rootDocId;
31
+ const bucket = children.get(parent);
32
+ if (bucket) bucket.push(id);
33
+ else children.set(parent, [id]);
34
+ }
35
+ for (const bucket of children.values()) {
36
+ bucket.sort((a, b) => (tree[a]?.order ?? 0) - (tree[b]?.order ?? 0));
37
+ }
38
+ const pages = [];
39
+ const rootEntry = tree[rootDocId];
40
+ pages.push({
41
+ id: rootDocId,
42
+ path: "/",
43
+ label: rootEntry?.label || "Home",
44
+ type: rootEntry?.type ?? "doc",
45
+ section: ""
46
+ });
47
+ const seen = /* @__PURE__ */ new Set([rootDocId]);
48
+ const walk = (parentId, depth) => {
49
+ if (depth > MAX_DEPTH) return;
50
+ for (const id of children.get(parentId) ?? []) {
51
+ if (seen.has(id)) continue;
52
+ seen.add(id);
53
+ const entry = tree[id];
54
+ const slug = idToSlug[id];
55
+ if (slug && junIsPublicPage(entry)) {
56
+ const section = sectionOf(id);
57
+ pages.push({
58
+ id,
59
+ path: `/${slug}`,
60
+ label: entry?.label || "Untitled",
61
+ type: entry?.type ?? "doc",
62
+ section: section ? `/${idToSlug[section] ?? section}` : ""
63
+ });
64
+ }
65
+ walk(id, depth + 1);
66
+ }
67
+ };
68
+ walk(rootDocId, 0);
69
+ return pages;
70
+ }
@@ -1003,6 +1003,71 @@ export interface JunMosaicOptions {
1003
1003
  */
1004
1004
  maxDepth?: number;
1005
1005
  }
1006
+ /**
1007
+ * What an offline copy of this site may contain — the BUILD's answer.
1008
+ *
1009
+ * Every key here is a ceiling the Site Config can lower and an owner can see;
1010
+ * none of them is a promise that anything is downloaded. The default posture is
1011
+ * the conservative one throughout: a visitor gets the pages they actually
1012
+ * opened, and everything beyond that is something they pressed a button for.
1013
+ *
1014
+ * See `runtime/utils/junOffline.ts` for the tiers themselves.
1015
+ */
1016
+ /**
1017
+ * When a link fetches the page behind it.
1018
+ *
1019
+ * - `'interaction'` — on hover or keyboard focus. The module's default.
1020
+ * - `'visibility'` — when the link scrolls into view. Nuxt's own default, and
1021
+ * the reason a jun-is site shipped 160 unasked-for chunks after first paint.
1022
+ * - `false` — never; a navigation pays its own cost.
1023
+ */
1024
+ export type JunPrefetchPolicy = 'interaction' | 'visibility';
1025
+ export interface JunOfflineOptions {
1026
+ /**
1027
+ * Offer a saved copy at all.
1028
+ *
1029
+ * Off means the panel does not exist and the worker keeps only what a
1030
+ * navigation happened to fill — which is still an offline site, just not a
1031
+ * configurable one.
1032
+ */
1033
+ enabled?: boolean;
1034
+ /**
1035
+ * What a device that has never chosen gets.
1036
+ *
1037
+ * `visited` — keep the pages this reader opens. The default, and the only
1038
+ * setting that downloads nothing on its own.
1039
+ * `off` — hold no cache at all. For a site whose readers should never have
1040
+ * its content sitting on their device.
1041
+ *
1042
+ * Note there is deliberately no `site` here: a whole-site copy is 26 MB on
1043
+ * the playground, and a DEFAULT that spends somebody's data allowance is the
1044
+ * behaviour this whole surface exists to prevent.
1045
+ */
1046
+ defaultMode?: 'off' | 'visited';
1047
+ /** May a visitor save the whole site in one press? */
1048
+ fullSite?: boolean;
1049
+ /**
1050
+ * May images be part of a saved copy?
1051
+ *
1052
+ * **Off.** This is the half that turns a copy of the writing into a copy of
1053
+ * the photographs, and its size is a property of the site's content rather
1054
+ * than of its page count — so it is the one thing here nobody can estimate
1055
+ * for an owner in advance.
1056
+ */
1057
+ media?: boolean;
1058
+ /** Ceiling on ONE saved copy, in megabytes. The save stops and says so. */
1059
+ budgetMb?: number;
1060
+ /**
1061
+ * Offer the CRDT half — every document synced into IndexedDB, so the site is
1062
+ * EDITABLE offline rather than merely readable.
1063
+ *
1064
+ * Owner-only and off by default. `@abraca/nuxt` will do this automatically
1065
+ * (`features.backgroundSync` defaults to on and its plugin calls `syncAll()`
1066
+ * on first sync); this module contributes `false` so a consumer inherits the
1067
+ * conservative half, and turns it back on for one person who asked.
1068
+ */
1069
+ docSync?: boolean;
1070
+ }
1006
1071
  /**
1007
1072
  * The site's house style for its renderers — page-type KEY → option key →
1008
1073
  * value, e.g. `{ library: { variant: 'grid', covers: true } }`.
@@ -1118,6 +1183,11 @@ export interface JunRuntimeOptions {
1118
1183
  embeds: Required<JunEmbedOptions>;
1119
1184
  /** Mosaic guard rails. See `JunMosaicOptions`. */
1120
1185
  mosaic: Required<JunMosaicOptions>;
1186
+ /**
1187
+ * What an offline copy may contain. Read at RUNTIME by the offline panel and
1188
+ * the save routine, which cannot see module options. See `JunOfflineOptions`.
1189
+ */
1190
+ offline: Required<JunOfflineOptions>;
1121
1191
  /** Enabled service adapters + their cache TTL. See `JunServicesOptions`. */
1122
1192
  services: Required<JunServicesOptions>;
1123
1193
  /**
@@ -0,0 +1,138 @@
1
+ /**
2
+ * What an offline copy of a site IS — the arithmetic and the rules, with no
3
+ * imports, so every one of them can be checked without a browser.
4
+ *
5
+ * The service worker is the module's least testable surface by a wide margin:
6
+ * it only exists in a production build (dev serves a tombstone — see
7
+ * `jun-sw.js.get.ts`), it runs in a context with no DOM, and its failures look
8
+ * like a site that is merely slow. So as little as possible lives in it. The
9
+ * worker answers requests; **the page decides what a copy contains and does the
10
+ * saving itself**, through the same Cache Storage API, which is available in a
11
+ * window context and not only in a worker.
12
+ *
13
+ * That split is the reason this file can exist at all. Everything below is
14
+ * exercised by `test/offline.test.mts`.
15
+ */
16
+ /**
17
+ * How much of the site this device keeps.
18
+ *
19
+ * `visited` is the default and it is the only one of the three that downloads
20
+ * NOTHING on its own: it keeps the pages the reader opened anyway, so that the
21
+ * moment the signal drops they are still there. `site` is a copy the visitor
22
+ * asked for out loud. `off` is a visitor who would rather no storage were used.
23
+ */
24
+ export type JunOfflineMode = 'off' | 'visited' | 'site';
25
+ export declare const JUN_OFFLINE_MODES: JunOfflineMode[];
26
+ /** `localStorage`, per device — an offline copy belongs to the phone, not the site. */
27
+ export declare const JUN_OFFLINE_MODE_KEY = "jun_offline_mode";
28
+ export declare const JUN_OFFLINE_MEDIA_KEY = "jun_offline_media";
29
+ export declare const JUN_OFFLINE_SAVED_KEY = "jun_offline_saved";
30
+ /**
31
+ * Where the worker reads the mode from.
32
+ *
33
+ * A path inside the worker's scope, holding a synthetic `Response` the page
34
+ * writes. It is NOT a route — nothing serves it — and the double underscore is
35
+ * there so it can never collide with a slug: `junSlugify` cannot produce a
36
+ * leading underscore.
37
+ *
38
+ * The mode has to live somewhere the WORKER can read, and `localStorage` is not
39
+ * that place: it is unavailable in a worker context entirely. Cache Storage is
40
+ * the one store both sides can see.
41
+ */
42
+ export declare const JUN_OFFLINE_MODE_URL = "/__jun-offline-mode";
43
+ /**
44
+ * The cache a saved copy lives in.
45
+ *
46
+ * Keyed on the BUILD, so a deploy orphans the previous one and the worker's
47
+ * `activate` deletes it. The page and the worker have to agree on this string
48
+ * or the page saves into a cache nothing reads — which is why it is computed
49
+ * here and imported by both rather than written out twice.
50
+ */
51
+ export declare function junOfflineCacheName(buildId: string | undefined): string;
52
+ /** A stored preference, validated. Anything unrecognised means "never chose". */
53
+ export declare function junReadOfflineMode(stored: string | null | undefined, fallback?: JunOfflineMode): JunOfflineMode;
54
+ /**
55
+ * The assets a saved page needs in order to be a PAGE when it is served back.
56
+ *
57
+ * A cached HTML document whose modules are missing hydrates into nothing: the
58
+ * markup paints, and then every interactive surface on it is dead. So saving a
59
+ * page means saving what its HTML asks for.
60
+ *
61
+ * Two families, and the second is optional because it is the heavy one:
62
+ *
63
+ * - `/_nuxt/*` — the build's modules and styles. Content-hashed, so a stale
64
+ * entry is unreachable rather than wrong, and shared across pages: the
65
+ * hundredth page saved adds almost none.
66
+ * - `/uploads/*` — the site's images. Only when the visitor asked for media,
67
+ * and only when the OWNER allows it. This is what turns a text copy into a
68
+ * copy that weighs whatever the photographs weigh.
69
+ *
70
+ * Same-origin only, and by construction: both patterns are rooted paths. A
71
+ * cross-origin URL in the markup (an embed, a font CDN) is not matched, which
72
+ * is the same boundary the worker's fetch handler draws.
73
+ */
74
+ export declare function junPageAssets(html: string, options?: {
75
+ media?: boolean;
76
+ }): string[];
77
+ /** Megabytes as a byte count. `0` and nonsense mean the built-in ceiling. */
78
+ export declare function junOfflineBudgetBytes(mb: number | undefined, fallbackMb?: number): number;
79
+ /**
80
+ * A size a person can read.
81
+ *
82
+ * Decimal units on purpose — a phone's storage settings say MB meaning
83
+ * 1,000,000, and a copy this reports as 24 MB sitting beside a system figure of
84
+ * 25 MB reads as a bug in one of them.
85
+ */
86
+ export declare function junFormatBytes(bytes: number | null | undefined): string;
87
+ /**
88
+ * What a whole-site copy will cost, from ONE page.
89
+ *
90
+ * Every page on a jun site carries the same Nuxt payload — the doc tree, the
91
+ * site config, the nav — and on the playground that shared part is 66.7 KB of a
92
+ * 199 KB page. So pages are close enough in size that one measured sample times
93
+ * the count is a better estimate than anything short of downloading them, and
94
+ * it costs one request instead of 136.
95
+ *
96
+ * It is an ESTIMATE and the UI must say so. Compression is the reason: this
97
+ * measures the decompressed body, and what the copy occupies on disk is
98
+ * whatever the browser decides to store.
99
+ */
100
+ export declare function junEstimateCopyBytes(sampleBytes: number, pages: number): number;
101
+ /** Fraction complete, clamped, safe on an empty plan. */
102
+ export declare function junOfflineProgress(done: number, total: number): number;
103
+ export interface JunOfflinePage {
104
+ path: string;
105
+ label: string;
106
+ /** The top-level page this one sits under — `''` for a top-level page itself. */
107
+ section: string;
108
+ }
109
+ export interface JunOfflineSection {
110
+ /** Top-level path, `/` for the ones that hang off the root. */
111
+ path: string;
112
+ label: string;
113
+ pages: JunOfflinePage[];
114
+ }
115
+ /**
116
+ * The site's pages, grouped by the section a reader would name.
117
+ *
118
+ * "The whole site" is 136 pages on the playground, and a reader who wants the
119
+ * writing does not want the film chapters. The panel does not offer per-section
120
+ * saving yet (`ROUND-11.md` §8), but the grouping is what makes the SIZE of the
121
+ * ask legible — "136 pages across 9 sections" is a sentence; "136 pages" is a
122
+ * number you either accept or do not.
123
+ *
124
+ * Order is the order the pages arrive in, which is the tree's own `order` —
125
+ * the same sequence the navigation shows. Sorting alphabetically here would
126
+ * make the panel disagree with the navbar for no gain.
127
+ */
128
+ export declare function junGroupOfflinePages(pages: JunOfflinePage[]): JunOfflineSection[];
129
+ /**
130
+ * Should this URL be saved at all?
131
+ *
132
+ * The worker's pass-through list, restated for the SAVING side — the two have
133
+ * to agree or the page writes entries the worker will never read. Live data
134
+ * (`/api/`), the feeds and the manifest are all things whose freshness is the
135
+ * whole point; a saved copy of them is worse than no copy, because it would be
136
+ * served in preference to a network that had come back.
137
+ */
138
+ export declare function junOfflineSavable(path: string): boolean;
@@ -0,0 +1,73 @@
1
+ export const JUN_OFFLINE_MODES = ["off", "visited", "site"];
2
+ export const JUN_OFFLINE_MODE_KEY = "jun_offline_mode";
3
+ export const JUN_OFFLINE_MEDIA_KEY = "jun_offline_media";
4
+ export const JUN_OFFLINE_SAVED_KEY = "jun_offline_saved";
5
+ export const JUN_OFFLINE_MODE_URL = "/__jun-offline-mode";
6
+ export function junOfflineCacheName(buildId) {
7
+ return `jun-${buildId || "dev"}`;
8
+ }
9
+ export function junReadOfflineMode(stored, fallback = "visited") {
10
+ return JUN_OFFLINE_MODES.includes(stored ?? "") ? stored : fallback;
11
+ }
12
+ export function junPageAssets(html, options) {
13
+ const out = /* @__PURE__ */ new Set();
14
+ for (const m of html.matchAll(/["'(]([^"'()\s]*\/_nuxt\/[^"'()\s]+)["')]/g)) {
15
+ const url = m[1];
16
+ if (url.startsWith("/")) out.add(url);
17
+ }
18
+ if (options?.media) {
19
+ for (const m of html.matchAll(/["'(\s]([^"'()\s,]*\/uploads\/[^"'()\s,]+)["')\s,]/g)) {
20
+ const url = m[1];
21
+ if (url.startsWith("/")) out.add(url);
22
+ }
23
+ }
24
+ return [...out];
25
+ }
26
+ export function junOfflineBudgetBytes(mb, fallbackMb = 60) {
27
+ const value = typeof mb === "number" && Number.isFinite(mb) && mb > 0 ? mb : fallbackMb;
28
+ return Math.round(value * 1024 * 1024);
29
+ }
30
+ export function junFormatBytes(bytes) {
31
+ if (typeof bytes !== "number" || !Number.isFinite(bytes) || bytes < 0) return "\u2014";
32
+ if (bytes < 1e3) return `${Math.round(bytes)} B`;
33
+ const units = ["kB", "MB", "GB"];
34
+ let value = bytes / 1e3;
35
+ let unit = 0;
36
+ while (value >= 1e3 && unit < units.length - 1) {
37
+ value /= 1e3;
38
+ unit++;
39
+ }
40
+ return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
41
+ }
42
+ export function junEstimateCopyBytes(sampleBytes, pages) {
43
+ if (!(sampleBytes > 0) || !(pages > 0)) return 0;
44
+ return Math.round(sampleBytes * pages);
45
+ }
46
+ export function junOfflineProgress(done, total) {
47
+ if (!(total > 0)) return 0;
48
+ return Math.max(0, Math.min(1, done / total));
49
+ }
50
+ export function junGroupOfflinePages(pages) {
51
+ const sections = [];
52
+ const index = /* @__PURE__ */ new Map();
53
+ for (const page of pages) {
54
+ const key = page.section || page.path;
55
+ let section = index.get(key);
56
+ if (!section) {
57
+ section = { path: key, label: page.section ? key.replace(/^\//, "") : page.label, pages: [] };
58
+ index.set(key, section);
59
+ sections.push(section);
60
+ }
61
+ if (!page.section) section.label = page.label;
62
+ section.pages.push(page);
63
+ }
64
+ return sections;
65
+ }
66
+ export function junOfflineSavable(path) {
67
+ if (!path.startsWith("/")) return false;
68
+ if (path.startsWith("/api/")) return false;
69
+ if (path === JUN_OFFLINE_MODE_URL) return false;
70
+ if (path === "/manifest.webmanifest") return false;
71
+ if (path === "/feed.xml" || path === "/feed.json" || path === "/sitemap.xml") return false;
72
+ return true;
73
+ }
@@ -363,7 +363,7 @@ export declare const JUN_VIEW_SPECS: {
363
363
  metaKey: string;
364
364
  default: string[];
365
365
  choices: {
366
- value: "links" | "now" | "prose" | "hero" | "latest" | "projects" | "pages";
366
+ value: "links" | "now" | "prose" | "pages" | "hero" | "latest" | "projects";
367
367
  label: "Hero" | "Latest writing" | "Projects" | "Now" | "Links" | "Pages" | "Page content";
368
368
  icon: "i-lucide-text" | "i-lucide-box" | "i-lucide-link" | "i-lucide-feather" | "i-lucide-radio" | "i-lucide-user-round" | "i-lucide-layout-grid";
369
369
  }[];
package/dist/types.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { type JunBackdropKind, type JunBrand, type JunCampfireOptions, type JunCampfirePillMode, type JunCampfirePlacement, type JunCampfireRosterStyle, type JunCampfireSize, type JunCampfireTab, type JunContextMenuOptions, type JunEmbedOptions, type JunFeatures, type JunGuestNames, type JunJanitorBaselineMode, type JunJanitorIdentity, type JunJanitorIdentityMode, type JunJanitorMode, type JunJanitorOptions, type JunJsonLdSpec, type JunLayoutPolicy, type JunMosaicOptions, type JunNavActiveStyle, type JunNavItemMode, type JunNavPlacement, type JunNavShape, type JunNavSize, type JunNavigationOptions, type JunPageTypeKey, type JunPageTypeOverride, type JunPageTypesOption, type JunPalette, type JunPaletteSet, type JunRendererDefaults, type JunRuntimeOptions, type JunSeedNode, type JunSeedOptions, type JunServicesOptions, type JunSiteConfigDefaults } from '../dist/runtime/types.js'
1
+ export { type JunBackdropKind, type JunBrand, type JunCampfireOptions, type JunCampfirePillMode, type JunCampfirePlacement, type JunCampfireRosterStyle, type JunCampfireSize, type JunCampfireTab, type JunContextMenuOptions, type JunEmbedOptions, type JunFeatures, type JunGuestNames, type JunJanitorBaselineMode, type JunJanitorIdentity, type JunJanitorIdentityMode, type JunJanitorMode, type JunJanitorOptions, type JunJsonLdSpec, type JunLayoutPolicy, type JunMosaicOptions, type JunNavActiveStyle, type JunNavItemMode, type JunNavPlacement, type JunNavShape, type JunNavSize, type JunNavigationOptions, type JunOfflineOptions, type JunPageTypeKey, type JunPageTypeOverride, type JunPageTypesOption, type JunPalette, type JunPaletteSet, type JunPrefetchPolicy, type JunRendererDefaults, type JunRuntimeOptions, type JunSeedNode, type JunSeedOptions, type JunServicesOptions, type JunSiteConfigDefaults } from '../dist/runtime/types.js'
2
2
 
3
3
  export { default } from './module.mjs'
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/junis",
3
- "version": "2.88.0",
3
+ "version": "2.90.0",
4
4
  "description": "Website-builder Nuxt module for the Abracadabra CRDT platform — page-type renderers, presence chrome, studio editing and SSR, all driven by documents",
5
5
  "repository": "abracadabra/jun-is",
6
6
  "license": "MIT",
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "//deps": "SINGLETONS ARE PEERS, NEVER DEPENDENCIES. @abraca/convert was a dependency until 2.79.0 and had to move: it peers on yjs, and a nested second copy of it means a Y.XmlElement built by one yjs crossing into a fragment owned by another — 'Unexpected content type in insert operation', which no bundler config fixes. Same reason @tiptap/core, vue and yjs are peers. Anything holding global identity or editor/CRDT state belongs here so the app resolves exactly one copy; wand.toml [pins] + `wand doctor` enforce the versions.",
35
35
  "peerDependencies": {
36
- "@abraca/convert": "^2.87.0",
37
- "@abraca/dabra": "^2.87.0",
38
- "@abraca/nuxt": "^2.87.0",
36
+ "@abraca/convert": "^2.88.0",
37
+ "@abraca/dabra": "^2.88.0",
38
+ "@abraca/nuxt": "^2.88.0",
39
39
  "@nuxt/fonts": "^0.14.0",
40
40
  "@nuxt/icon": "^2.0.0",
41
41
  "@nuxt/image": "^2.0.0",
@@ -64,9 +64,9 @@
64
64
  }
65
65
  },
66
66
  "devDependencies": {
67
- "@abraca/convert": "^2.87.0",
68
- "@abraca/dabra": "^2.87.0",
69
- "@abraca/nuxt": "^2.87.0",
67
+ "@abraca/convert": "^2.88.0",
68
+ "@abraca/dabra": "^2.88.0",
69
+ "@abraca/nuxt": "^2.88.0",
70
70
  "@iconify-json/lucide": "^1.2.108",
71
71
  "@iconify-json/simple-icons": "^1.2.83",
72
72
  "@nuxt/eslint-config": "^1.15.2",
@@ -106,10 +106,12 @@
106
106
  "parity:follow": "node scripts/parity-follow.mjs",
107
107
  "parity:studio": "node scripts/parity-studio.mjs",
108
108
  "parity:touch": "node scripts/parity-touch.mjs",
109
+ "parity:offline": "node scripts/parity-offline.mjs",
110
+ "parity:weight": "node scripts/parity-weight.mjs",
109
111
  "deploy:check": "node scripts/deploy-check.mjs",
110
112
  "pins:check": "node scripts/pins-check.mjs",
111
113
  "typecheck": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
112
- "release": "npm run lint && npm run prepack",
114
+ "release": "npm run lint && npm run deps:check && npm run pins:check && npm run prepack",
113
115
  "docker:up": "docker compose up -d --build",
114
116
  "docker:down": "docker compose down",
115
117
  "docker:logs": "docker compose logs -f",