@abraca/junis 2.87.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 (109) hide show
  1. package/dist/module.d.mts +43 -4
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +121 -6
  4. package/dist/runtime/assets/css/jun.css +2 -2
  5. package/dist/runtime/components/JunDocSurface.d.vue.ts +20 -2
  6. package/dist/runtime/components/JunDocSurface.vue +27 -2
  7. package/dist/runtime/components/JunDocSurface.vue.d.ts +20 -2
  8. package/dist/runtime/components/JunHead.vue +16 -4
  9. package/dist/runtime/components/JunNavDock.d.vue.ts +15 -0
  10. package/dist/runtime/components/JunNavDock.vue +94 -0
  11. package/dist/runtime/components/JunNavDock.vue.d.ts +15 -0
  12. package/dist/runtime/components/JunNavMenu.client.d.vue.ts +15 -0
  13. package/dist/runtime/components/JunNavMenu.client.vue +501 -0
  14. package/dist/runtime/components/JunNavMenu.client.vue.d.ts +15 -0
  15. package/dist/runtime/components/JunNavPreview.d.vue.ts +17 -0
  16. package/dist/runtime/components/JunNavPreview.vue +169 -0
  17. package/dist/runtime/components/JunNavPreview.vue.d.ts +17 -0
  18. package/dist/runtime/components/JunNavigation.d.vue.ts +4 -11
  19. package/dist/runtime/components/JunNavigation.vue +813 -138
  20. package/dist/runtime/components/JunNavigation.vue.d.ts +4 -11
  21. package/dist/runtime/components/JunNoteLinks.vue +1 -1
  22. package/dist/runtime/components/JunOfflinePanel.client.d.vue.ts +3 -0
  23. package/dist/runtime/components/JunOfflinePanel.client.vue +293 -0
  24. package/dist/runtime/components/JunOfflinePanel.client.vue.d.ts +3 -0
  25. package/dist/runtime/components/JunPageHero.vue +3 -3
  26. package/dist/runtime/components/JunSectionBar.d.vue.ts +41 -0
  27. package/dist/runtime/components/JunSectionBar.vue +144 -0
  28. package/dist/runtime/components/JunSectionBar.vue.d.ts +41 -0
  29. package/dist/runtime/components/renderers/JunConfigRenderer.vue +618 -6
  30. package/dist/runtime/components/renderers/JunEntryRenderer.vue +48 -0
  31. package/dist/runtime/composables/useJunCommands.d.ts +1 -1
  32. package/dist/runtime/composables/useJunCommands.js +14 -1
  33. package/dist/runtime/composables/useJunCreatePage.js +7 -1
  34. package/dist/runtime/composables/useJunDocPage.d.ts +28 -0
  35. package/dist/runtime/composables/useJunDocPage.js +111 -20
  36. package/dist/runtime/composables/useJunGarden.d.ts +1 -1
  37. package/dist/runtime/composables/useJunGarden.js +3 -2
  38. package/dist/runtime/composables/useJunGestures.d.ts +53 -0
  39. package/dist/runtime/composables/useJunGestures.js +89 -0
  40. package/dist/runtime/composables/useJunMenuState.d.ts +4 -0
  41. package/dist/runtime/composables/useJunMenuState.js +5 -0
  42. package/dist/runtime/composables/useJunNavItems.d.ts +50 -0
  43. package/dist/runtime/composables/useJunNavItems.js +188 -0
  44. package/dist/runtime/composables/useJunNavSettings.d.ts +58 -1
  45. package/dist/runtime/composables/useJunNavSettings.js +110 -8
  46. package/dist/runtime/composables/useJunOffline.d.ts +109 -0
  47. package/dist/runtime/composables/useJunOffline.js +294 -0
  48. package/dist/runtime/composables/useJunOptions.d.ts +1 -0
  49. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  50. package/dist/runtime/composables/useJunSettings.js +2 -0
  51. package/dist/runtime/composables/useJunSiblings.d.ts +30 -0
  52. package/dist/runtime/composables/useJunSiblings.js +38 -0
  53. package/dist/runtime/composables/useJunSiteConfig.d.ts +70 -3
  54. package/dist/runtime/composables/useJunTheme.js +4 -1
  55. package/dist/runtime/composables/useJunViewingAccent.js +10 -0
  56. package/dist/runtime/layouts/jun.vue +32 -2
  57. package/dist/runtime/pages/doc.vue +2 -0
  58. package/dist/runtime/pages/index.vue +2 -0
  59. package/dist/runtime/server/api/health.get.d.ts +15 -0
  60. package/dist/runtime/server/api/health.get.js +7 -2
  61. package/dist/runtime/server/api/links.get.js +27 -3
  62. package/dist/runtime/server/api/offline.get.d.ts +10 -0
  63. package/dist/runtime/server/api/offline.get.js +13 -0
  64. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +20 -0
  65. package/dist/runtime/server/api/resolve/[...slug].get.js +31 -0
  66. package/dist/runtime/server/api/search.get.d.ts +1 -1
  67. package/dist/runtime/server/api/search.get.js +42 -39
  68. package/dist/runtime/server/api/tree.get.js +3 -1
  69. package/dist/runtime/server/janitor/junJanitorChores.d.ts +14 -7
  70. package/dist/runtime/server/janitor/junJanitorChores.js +21 -3
  71. package/dist/runtime/server/janitor/junJanitorMachine.js +36 -4
  72. package/dist/runtime/server/janitor/junJanitorPerform.d.ts +15 -1
  73. package/dist/runtime/server/janitor/junJanitorPerform.js +13 -5
  74. package/dist/runtime/server/janitor/junJanitorYText.d.ts +40 -3
  75. package/dist/runtime/server/janitor/junJanitorYText.js +60 -14
  76. package/dist/runtime/server/plugins/jun-compress.d.ts +2 -0
  77. package/dist/runtime/server/plugins/jun-compress.js +76 -0
  78. package/dist/runtime/server/plugins/jun-janitor.js +132 -81
  79. package/dist/runtime/server/routes/jun-card.png.get.d.ts +2 -0
  80. package/dist/runtime/server/routes/jun-card.png.get.js +40 -0
  81. package/dist/runtime/server/routes/jun-sw.js.get.js +66 -13
  82. package/dist/runtime/server/routes/sitemap.xml.get.js +5 -18
  83. package/dist/runtime/server/utils/junCard.d.ts +39 -0
  84. package/dist/runtime/server/utils/junCard.js +159 -0
  85. package/dist/runtime/server/utils/junIcon.d.ts +27 -2
  86. package/dist/runtime/server/utils/junIcon.js +5 -5
  87. package/dist/runtime/server/utils/junJanitorStatus.d.ts +59 -0
  88. package/dist/runtime/server/utils/junJanitorStatus.js +27 -0
  89. package/dist/runtime/server/utils/junPages.d.ts +51 -0
  90. package/dist/runtime/server/utils/junPages.js +70 -0
  91. package/dist/runtime/types.d.ts +295 -0
  92. package/dist/runtime/utils/junAdopt.d.ts +43 -0
  93. package/dist/runtime/utils/junAdopt.js +7 -0
  94. package/dist/runtime/utils/junGesture.d.ts +84 -0
  95. package/dist/runtime/utils/junGesture.js +40 -0
  96. package/dist/runtime/utils/junLetters.d.ts +86 -0
  97. package/dist/runtime/utils/junLetters.js +173 -0
  98. package/dist/runtime/utils/junNavValue.d.ts +56 -0
  99. package/dist/runtime/utils/junNavValue.js +36 -0
  100. package/dist/runtime/utils/junOffline.d.ts +138 -0
  101. package/dist/runtime/utils/junOffline.js +73 -0
  102. package/dist/runtime/utils/junSearchRank.d.ts +79 -0
  103. package/dist/runtime/utils/junSearchRank.js +73 -0
  104. package/dist/runtime/utils/junSocial.d.ts +59 -0
  105. package/dist/runtime/utils/junSocial.js +56 -0
  106. package/dist/runtime/utils/junViewSpecs.d.ts +39 -1
  107. package/dist/runtime/utils/junViewSpecs.js +92 -1
  108. package/dist/types.d.mts +1 -1
  109. package/package.json +13 -9
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The link-preview card, drawn per page.
3
+ *
4
+ * A social card is the one piece of a site most of its readers see FIRST — in
5
+ * a chat window, before they have decided whether to click. Until now every
6
+ * page here shared one image, or had none, so a link to a journal entry looked
7
+ * exactly like a link to the home page.
8
+ *
9
+ * This draws the page's own: the site's mark in the site's accent, the page
10
+ * title set in `junLetters`' stroke alphabet, the kind of page it is, and a
11
+ * rule in the accent colour. Same rasteriser as the favicon and the launch
12
+ * screens — no native image dependency, nothing committed to the repo, and the
13
+ * card follows the owner's colours because it is built from the same identity.
14
+ *
15
+ * Rendering is memoised by everything the drawing reads. The route on top of
16
+ * that is immutable for a year and carries a fingerprint in its URL, so an
17
+ * edited title produces a new address rather than a stale image.
18
+ */
19
+ import type { JunIdentity } from '../../utils/junIdentity.js';
20
+ /** Facebook, Slack, X and iMessage all read this size. */
21
+ export declare const JUN_CARD_WIDTH = 1200;
22
+ export declare const JUN_CARD_HEIGHT = 630;
23
+ export interface JunCardRequest {
24
+ identity: JunIdentity;
25
+ /** The page's own title. Empty falls back to the site name. */
26
+ title: string;
27
+ /** What kind of page it is, in words — "Journal entry", "Photograph". */
28
+ kind?: string;
29
+ /** One line under the title. Trimmed to fit; never wrapped past two lines. */
30
+ excerpt?: string;
31
+ }
32
+ /**
33
+ * Draw the card.
34
+ *
35
+ * The layout is fixed and the TYPE SIZE is not: a long title steps down
36
+ * through three sizes before it is allowed to wrap to a third line, because a
37
+ * card whose title is cut off is worse than one whose title is small.
38
+ */
39
+ export declare function junRenderCard(req: JunCardRequest): Promise<Uint8Array>;
@@ -0,0 +1,159 @@
1
+ import { junHexToRgb, JUN_MARK_VIEWBOX } from "../../utils/junMark.js";
2
+ import { junCanDraw, junTextStrokes, junWrapInfo, junWrapText } from "../../utils/junLetters.js";
3
+ import { encodePng, junMarkShapeSet, strokeShape } from "./junIcon.js";
4
+ export const JUN_CARD_WIDTH = 1200;
5
+ export const JUN_CARD_HEIGHT = 630;
6
+ const PAD = 78;
7
+ const cache = /* @__PURE__ */ new Map();
8
+ const CACHE_MAX = 96;
9
+ function mix(a, b, t) {
10
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
11
+ }
12
+ function glowShape(cx, cy, radius, rgb, alpha) {
13
+ return {
14
+ bb: [cx - radius, cy - radius, cx + radius, cy + radius],
15
+ at: (x, y) => {
16
+ const d = Math.hypot(x - cx, y - cy);
17
+ if (d >= radius) return null;
18
+ const t = 1 - d / radius;
19
+ return [rgb[0], rgb[1], rgb[2], alpha * t * t];
20
+ }
21
+ };
22
+ }
23
+ function placed(shape, x, y, scale) {
24
+ const [bx0, by0, bx1, by1] = shape.bb;
25
+ return {
26
+ bb: [x + bx0 * scale, y + by0 * scale, x + bx1 * scale, y + by1 * scale],
27
+ at: (px, py) => shape.at((px - x) / scale, (py - y) / scale)
28
+ };
29
+ }
30
+ function textShapes(groups, width, rgb) {
31
+ return groups.map((segs) => strokeShape(segs, width, rgb));
32
+ }
33
+ function paint(width, height, background, shapes) {
34
+ const rgba = new Uint8Array(width * height * 4);
35
+ for (let i = 0; i < width * height; i++) {
36
+ rgba[i * 4] = background[0];
37
+ rgba[i * 4 + 1] = background[1];
38
+ rgba[i * 4 + 2] = background[2];
39
+ rgba[i * 4 + 3] = 255;
40
+ }
41
+ const ss = 2;
42
+ const sub = 1 / ss;
43
+ const offset = sub / 2;
44
+ for (const shape of shapes) {
45
+ const x0 = Math.max(0, Math.floor(shape.bb[0]));
46
+ const y0 = Math.max(0, Math.floor(shape.bb[1]));
47
+ const x1 = Math.min(width - 1, Math.ceil(shape.bb[2]));
48
+ const y1 = Math.min(height - 1, Math.ceil(shape.bb[3]));
49
+ for (let py = y0; py <= y1; py++) {
50
+ for (let px = x0; px <= x1; px++) {
51
+ let r = 0;
52
+ let g = 0;
53
+ let b = 0;
54
+ let a = 0;
55
+ for (let sy = 0; sy < ss; sy++) {
56
+ for (let sx = 0; sx < ss; sx++) {
57
+ const hit = shape.at(px + sx * sub + offset, py + sy * sub + offset);
58
+ if (!hit) continue;
59
+ r += hit[0] * hit[3];
60
+ g += hit[1] * hit[3];
61
+ b += hit[2] * hit[3];
62
+ a += hit[3];
63
+ }
64
+ }
65
+ if (!a) continue;
66
+ const coverage = a / (ss * ss);
67
+ const idx = (py * width + px) * 4;
68
+ const src = [r / a, g / a, b / a];
69
+ const dst = [rgba[idx], rgba[idx + 1], rgba[idx + 2]];
70
+ const out = mix(dst, src, coverage);
71
+ rgba[idx] = out[0];
72
+ rgba[idx + 1] = out[1];
73
+ rgba[idx + 2] = out[2];
74
+ }
75
+ }
76
+ }
77
+ return rgba;
78
+ }
79
+ function cacheKey(req) {
80
+ return [req.identity.version, req.identity.mark, req.title, req.kind ?? "", req.excerpt ?? ""].join("|");
81
+ }
82
+ export async function junRenderCard(req) {
83
+ const key = cacheKey(req);
84
+ const hit = cache.get(key);
85
+ if (hit) return hit;
86
+ const { identity } = req;
87
+ const bg = junHexToRgb(identity.tile);
88
+ const ink = junHexToRgb(identity.dark.ink);
89
+ const muted = mix(bg, ink, 0.62);
90
+ const accent = junHexToRgb(identity.dark.sunFrom ?? identity.dark.ink);
91
+ const shapes = [];
92
+ shapes.push(glowShape(JUN_CARD_WIDTH - 60, JUN_CARD_HEIGHT + 40, 520, accent, 0.3));
93
+ const markSize = 66;
94
+ for (const shape of junMarkShapeSet(identity.mark, identity.dark)) {
95
+ shapes.push(placed(shape, PAD, PAD, markSize / JUN_MARK_VIEWBOX));
96
+ }
97
+ const nameSize = 26;
98
+ shapes.push(...textShapes(
99
+ junTextStrokes(identity.name, PAD + markSize + 26, PAD + markSize * 0.74, nameSize),
100
+ nameSize * 0.1,
101
+ muted
102
+ ));
103
+ const requested = req.title.trim();
104
+ const title = (junCanDraw(requested) ? requested : "") || identity.name;
105
+ const maxWidth = JUN_CARD_WIDTH - PAD * 2;
106
+ const ladder = [[92, 2], [78, 2], [66, 3], [56, 3]];
107
+ let titleSize = ladder[0][0];
108
+ let lines = junWrapText(title, maxWidth / (titleSize / 10), ladder[0][1]);
109
+ for (const [size, maxLines] of ladder) {
110
+ const attempt = junWrapInfo(title, maxWidth / (size / 10), maxLines);
111
+ titleSize = size;
112
+ lines = attempt.lines;
113
+ if (!attempt.truncated) break;
114
+ }
115
+ const leading = titleSize * 1.32;
116
+ const footerY = JUN_CARD_HEIGHT - PAD;
117
+ const excerptY = footerY - 96;
118
+ const titleBottom = req.excerpt ? excerptY - 74 : footerY - 92;
119
+ const titleTop = titleBottom - leading * (lines.length - 1);
120
+ for (const [i, line] of lines.entries()) {
121
+ shapes.push(...textShapes(
122
+ junTextStrokes(line, PAD, titleTop + leading * i, titleSize),
123
+ titleSize * 0.085,
124
+ ink
125
+ ));
126
+ }
127
+ if (req.excerpt && junCanDraw(req.excerpt)) {
128
+ const size = 28;
129
+ const [line] = junWrapText(req.excerpt, maxWidth / (size / 10), 1);
130
+ if (line) {
131
+ shapes.push(...textShapes(
132
+ junTextStrokes(line, PAD, excerptY, size),
133
+ size * 0.1,
134
+ muted
135
+ ));
136
+ }
137
+ }
138
+ shapes.push(strokeShape(
139
+ [[PAD, footerY - 34, PAD + 96, footerY - 34]],
140
+ 5,
141
+ accent
142
+ ));
143
+ if (req.kind) {
144
+ const size = 24;
145
+ shapes.push(...textShapes(
146
+ junTextStrokes(req.kind, PAD, footerY, size),
147
+ size * 0.11,
148
+ muted
149
+ ));
150
+ }
151
+ const png = await encodePng(
152
+ paint(JUN_CARD_WIDTH, JUN_CARD_HEIGHT, bg, shapes),
153
+ JUN_CARD_WIDTH,
154
+ JUN_CARD_HEIGHT
155
+ );
156
+ if (cache.size >= CACHE_MAX) cache.delete(cache.keys().next().value);
157
+ cache.set(key, png);
158
+ return png;
159
+ }
@@ -1,5 +1,5 @@
1
1
  import type { JunMarkColors, JunMarkName } from '../../utils/junMark.js';
2
- type Segment = [number, number, number, number];
2
+ export type Segment = [number, number, number, number];
3
3
  /**
4
4
  * Flatten one `d` attribute into line segments.
5
5
  *
@@ -9,6 +9,32 @@ type Segment = [number, number, number, number];
9
9
  * device pixel.
10
10
  */
11
11
  export declare function junFlattenPath(d: string): Segment[];
12
+ /** A shape returns premultiplied-free RGBA at a point, or null for "not me". */
13
+ export interface Shape {
14
+ /** Bounding box in user units — the fast reject that makes this affordable. */
15
+ bb: [number, number, number, number];
16
+ at: (x: number, y: number) => [number, number, number, number] | null;
17
+ }
18
+ export type RGB = [number, number, number];
19
+ export declare function circleShape(cx: number, cy: number, r: number, rgb: RGB, alpha?: number): Shape;
20
+ export declare function strokeShape(segs: Segment[], width: number, rgb: RGB): Shape;
21
+ /**
22
+ * Build the mark's shapes, bottom to top, in the same order the SVG stacks
23
+ * them. `sun`'s four layers ARE the four layers of `<JunLogo>`'s template —
24
+ * body, halo, disc, glow — and the arithmetic for each is the SVG gradient
25
+ * evaluated by hand.
26
+ */
27
+ export declare function junMarkShapeSet(mark: JunMarkName, c: JunMarkColors): Shape[];
28
+ /**
29
+ * RGBA scanlines → a PNG file. Colour type 6.
30
+ *
31
+ * Filter 2 (Up) on every row but the first, not filter 0. It costs one
32
+ * subtraction per byte and it is what makes a launch image affordable: a splash
33
+ * is mostly one flat colour, so every row after the first differences to zeros
34
+ * and deflate takes 14MB of raw pixels down to a few kilobytes. With filter 0
35
+ * the same image spends seconds in `deflateSync` and comes out far larger.
36
+ */
37
+ export declare function encodePng(rgba: Uint8Array, width: number, height: number): Promise<Uint8Array>;
12
38
  export interface JunIconRequest {
13
39
  mark: JunMarkName;
14
40
  /** Image width in device pixels. Also the height unless one is given. */
@@ -41,4 +67,3 @@ export interface JunIconRequest {
41
67
  * flat colour.
42
68
  */
43
69
  export declare function junRenderIcon(req: JunIconRequest): Promise<Uint8Array>;
44
- export {};
@@ -109,7 +109,7 @@ function distSqToSegment(px, py, s) {
109
109
  function mixRgb(a, b, t) {
110
110
  return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
111
111
  }
112
- function circleShape(cx, cy, r, rgb, alpha = 1) {
112
+ export function circleShape(cx, cy, r, rgb, alpha = 1) {
113
113
  const r2 = r * r;
114
114
  return {
115
115
  bb: [cx - r, cy - r, cx + r, cy + r],
@@ -120,7 +120,7 @@ function circleShape(cx, cy, r, rgb, alpha = 1) {
120
120
  }
121
121
  };
122
122
  }
123
- function strokeShape(segs, width, rgb) {
123
+ export function strokeShape(segs, width, rgb) {
124
124
  const half = width / 2;
125
125
  const halfSq = half * half;
126
126
  let x0 = Infinity;
@@ -143,7 +143,7 @@ function strokeShape(segs, width, rgb) {
143
143
  }
144
144
  };
145
145
  }
146
- function markShapes(mark, c) {
146
+ export function junMarkShapeSet(mark, c) {
147
147
  if (mark !== "sun") {
148
148
  const geom = JUN_MARKS[mark] ?? JUN_MARKS.sprout;
149
149
  const ink = junHexToRgb(c.ink);
@@ -237,7 +237,7 @@ function pngChunk(type, data) {
237
237
  view.setUint32(4 + body.length, crc32(body));
238
238
  return out;
239
239
  }
240
- async function encodePng(rgba, width, height) {
240
+ export async function encodePng(rgba, width, height) {
241
241
  const { deflateSync } = await import("node:zlib");
242
242
  const stride = width * 4;
243
243
  const raw = new Uint8Array(height * (1 + stride));
@@ -302,7 +302,7 @@ export async function junRenderIcon(req) {
302
302
  const shorter = Math.min(width, height);
303
303
  const ss = shorter < 256 ? 3 : 2;
304
304
  const vb = JUN_MARK_VIEWBOX;
305
- const shapes = markShapes(req.mark, req.colors);
305
+ const shapes = junMarkShapeSet(req.mark, req.colors);
306
306
  const bg = req.background ? junHexToRgb(req.background) : null;
307
307
  const box = shorter * scale;
308
308
  const boxX = (width - box) / 2;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * What the janitor is doing, readable over HTTP.
3
+ *
4
+ * ── Why this file exists ────────────────────────────────────────────────────
5
+ * A janitor that never boots looks EXACTLY like a janitor with nothing to do:
6
+ * the site renders, the SSR cache is warm, `/health` says `ready`, and the only
7
+ * evidence of the failure is one line in a container log nobody is tailing.
8
+ * jun.is ran for weeks in that state — the plugin catching its own start error
9
+ * ("a janitor that cannot start must never take the site with it") is right
10
+ * about the site and wrong about the operator, who is then told nothing at all.
11
+ *
12
+ * So every transition the runner makes is recorded here and reported by
13
+ * `<apiBase>/health`. "Is the janitor on duty, and if not, why" becomes one
14
+ * curl against the deployment instead of an argument about what the source
15
+ * tree says — which is the actual failure this file is meant to end: the source
16
+ * tree was right, and the running image was four commits behind it.
17
+ *
18
+ * Module-scoped, like `junBoot`: it is a fact about THIS process, and a
19
+ * persistent store would let the previous container answer for this one.
20
+ */
21
+ /**
22
+ * Where the runner is, in the order it moves through them.
23
+ *
24
+ * `absent` is the one that matters most: the plugin never ran at all, which is
25
+ * what a build without the feature compiled in looks like from outside.
26
+ */
27
+ export type JunJanitorPhase = 'absent'
28
+ /** Registered, waiting out the boot delay or the seeder. */
29
+ | 'waiting'
30
+ /** Logging in and syncing the root document. */
31
+ | 'connecting'
32
+ /** Connected, machine running. The only healthy end state. */
33
+ | 'on-duty'
34
+ /** Failed and scheduled to try again — `lastError` says why. */
35
+ | 'retrying'
36
+ /** Sent home deliberately (shutdown). */
37
+ | 'off-duty';
38
+ export interface JunJanitorStatus {
39
+ phase: JunJanitorPhase;
40
+ /** Why it is in that phase, in one human sentence. */
41
+ detail: string;
42
+ /** `observe` | `clean`, as configured — null while the plugin is absent. */
43
+ mode: string | null;
44
+ /** How many times `hire()` has been attempted in this process. */
45
+ attempts: number;
46
+ /** The last start failure, kept even after a later attempt succeeds. */
47
+ lastError: string | null;
48
+ /** The janitor's own account key, once it has one. */
49
+ publicKey: string | null;
50
+ /** Whether it has a baseline — `null` until it has looked. */
51
+ hasBaseline: boolean | null;
52
+ /** When the current phase was entered. */
53
+ since: number;
54
+ }
55
+ /** Record a transition. `detail` is what a reader gets instead of a log line. */
56
+ export declare function junJanitorPhase(phase: JunJanitorPhase, detail: string): void;
57
+ /** Everything that is not a phase, patched as it becomes known. */
58
+ export declare function junJanitorNote(patch: Partial<Omit<JunJanitorStatus, 'phase' | 'since'>>): void;
59
+ export declare function junJanitorStatus(): JunJanitorStatus;
@@ -0,0 +1,27 @@
1
+ const status = {
2
+ phase: "absent",
3
+ detail: "no janitor plugin in this build",
4
+ mode: null,
5
+ attempts: 0,
6
+ lastError: null,
7
+ publicKey: null,
8
+ hasBaseline: null,
9
+ since: Date.now()
10
+ };
11
+ const DETAIL_MAX = 300;
12
+ function clamp(text) {
13
+ const flat = text.replace(/\s+/g, " ").trim();
14
+ return flat.length > DETAIL_MAX ? `${flat.slice(0, DETAIL_MAX - 1)}\u2026` : flat;
15
+ }
16
+ export function junJanitorPhase(phase, detail) {
17
+ status.phase = phase;
18
+ status.detail = clamp(detail);
19
+ status.since = Date.now();
20
+ }
21
+ export function junJanitorNote(patch) {
22
+ Object.assign(status, patch);
23
+ if (typeof status.lastError === "string") status.lastError = clamp(status.lastError);
24
+ }
25
+ export function junJanitorStatus() {
26
+ return { ...status };
27
+ }
@@ -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
+ }