@abraca/junis 2.85.0 → 2.86.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 (152) hide show
  1. package/dist/module.d.mts +17 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +235 -19
  4. package/dist/runtime/assets/css/jun.css +1 -1
  5. package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
  6. package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
  7. package/dist/runtime/components/JunCollectionIntro.vue +45 -0
  8. package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
  9. package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
  10. package/dist/runtime/components/JunConfigRow.vue +34 -0
  11. package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
  12. package/dist/runtime/components/JunFooter.vue +1 -1
  13. package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
  14. package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
  15. package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
  16. package/dist/runtime/components/JunLinksRow.vue +17 -7
  17. package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
  18. package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
  19. package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
  20. package/dist/runtime/components/JunNavigation.vue +21 -4
  21. package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
  22. package/dist/runtime/components/JunNoteLinks.vue +57 -0
  23. package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
  24. package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
  25. package/dist/runtime/components/JunPageHero.vue +15 -3
  26. package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
  27. package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
  28. package/dist/runtime/components/JunReaders.vue +99 -0
  29. package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
  30. package/dist/runtime/components/JunSearch.client.vue +2 -2
  31. package/dist/runtime/components/JunSectionPresence.client.d.vue.ts +17 -0
  32. package/dist/runtime/components/JunSectionPresence.client.vue +99 -0
  33. package/dist/runtime/components/JunSectionPresence.client.vue.d.ts +17 -0
  34. package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
  35. package/dist/runtime/components/JunThreadComposer.vue +54 -0
  36. package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
  37. package/dist/runtime/components/JunTravellersChip.vue +35 -5
  38. package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
  39. package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
  40. package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
  41. package/dist/runtime/components/JunViewControl.vue +340 -0
  42. package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
  43. package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
  44. package/dist/runtime/components/JunViewControls.vue +94 -0
  45. package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
  46. package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
  47. package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
  48. package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
  49. package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
  50. package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
  51. package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
  52. package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
  53. package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
  54. package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
  55. package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
  56. package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
  57. package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
  58. package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
  59. package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
  60. package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
  61. package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
  62. package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
  63. package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
  64. package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
  65. package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
  66. package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
  67. package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
  68. package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
  69. package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
  70. package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
  71. package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
  72. package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
  73. package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
  74. package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
  75. package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
  76. package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
  77. package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
  78. package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
  79. package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
  80. package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
  81. package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
  82. package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
  83. package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
  84. package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
  85. package/dist/runtime/composables/useJunDeck.d.ts +66 -0
  86. package/dist/runtime/composables/useJunDeck.js +61 -0
  87. package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
  88. package/dist/runtime/composables/useJunDocPage.js +67 -3
  89. package/dist/runtime/composables/useJunFollow.d.ts +65 -9
  90. package/dist/runtime/composables/useJunFollow.js +237 -20
  91. package/dist/runtime/composables/useJunGarden.d.ts +67 -0
  92. package/dist/runtime/composables/useJunGarden.js +92 -0
  93. package/dist/runtime/composables/useJunPresence.d.ts +26 -0
  94. package/dist/runtime/composables/useJunPresence.js +9 -2
  95. package/dist/runtime/composables/useJunSections.d.ts +73 -0
  96. package/dist/runtime/composables/useJunSections.js +117 -0
  97. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  98. package/dist/runtime/composables/useJunSettings.js +5 -1
  99. package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
  100. package/dist/runtime/composables/useJunTheme.js +40 -2
  101. package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
  102. package/dist/runtime/composables/useJunViewOptions.js +63 -0
  103. package/dist/runtime/pages/doc.vue +14 -8
  104. package/dist/runtime/server/api/health.get.d.ts +19 -0
  105. package/dist/runtime/server/api/health.get.js +40 -0
  106. package/dist/runtime/server/api/links.get.d.ts +19 -0
  107. package/dist/runtime/server/api/links.get.js +37 -0
  108. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
  109. package/dist/runtime/server/api/resolve/[...slug].get.js +5 -0
  110. package/dist/runtime/server/api/stats.get.js +2 -1
  111. package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
  112. package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
  113. package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
  114. package/dist/runtime/server/plugins/jun-janitor.js +7 -0
  115. package/dist/runtime/server/plugins/jun-rpc.js +293 -0
  116. package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
  117. package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
  118. package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
  119. package/dist/runtime/server/utils/junBoot.d.ts +1 -0
  120. package/dist/runtime/server/utils/junBoot.js +4 -0
  121. package/dist/runtime/server/utils/junCache.d.ts +17 -0
  122. package/dist/runtime/server/utils/junCache.js +5 -0
  123. package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
  124. package/dist/runtime/server/utils/junSeedGate.js +41 -0
  125. package/dist/runtime/types.d.ts +57 -1
  126. package/dist/runtime/utils/junCourse.d.ts +106 -0
  127. package/dist/runtime/utils/junCourse.js +65 -0
  128. package/dist/runtime/utils/junGarden.d.ts +193 -0
  129. package/dist/runtime/utils/junGarden.js +233 -0
  130. package/dist/runtime/utils/junMetaSchemas.js +8 -1
  131. package/dist/runtime/utils/junModeration.d.ts +67 -0
  132. package/dist/runtime/utils/junModeration.js +20 -0
  133. package/dist/runtime/utils/junMotion.d.ts +26 -0
  134. package/dist/runtime/utils/junMotion.js +31 -0
  135. package/dist/runtime/utils/junPeople.d.ts +43 -0
  136. package/dist/runtime/utils/junPeople.js +9 -0
  137. package/dist/runtime/utils/junPoll.d.ts +79 -0
  138. package/dist/runtime/utils/junPoll.js +82 -0
  139. package/dist/runtime/utils/junReadiness.d.ts +131 -0
  140. package/dist/runtime/utils/junReadiness.js +69 -0
  141. package/dist/runtime/utils/junSections.d.ts +115 -0
  142. package/dist/runtime/utils/junSections.js +45 -0
  143. package/dist/runtime/utils/junSlides.d.ts +66 -0
  144. package/dist/runtime/utils/junSlides.js +47 -0
  145. package/dist/runtime/utils/junThread.d.ts +81 -0
  146. package/dist/runtime/utils/junThread.js +75 -0
  147. package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
  148. package/dist/runtime/utils/junViewSpecs.js +534 -0
  149. package/dist/runtime/utils/junViewValues.d.ts +125 -0
  150. package/dist/runtime/utils/junViewValues.js +104 -0
  151. package/dist/types.d.mts +1 -1
  152. package/package.json +5 -1
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Is this deployment actually able to SERVER-RENDER? — the arithmetic.
3
+ *
4
+ * No Vue, no `#imports`, **no imports at all**: the health route decides with it in
5
+ * Nitro, the watchdog logs with it, and a test runs both without an app.
6
+ *
7
+ * ── Why this exists ──────────────────────────────────────────────────────────
8
+ *
9
+ * On 2026-08-12 jun.is served every page with a 200 and an empty SSR payload for
10
+ * an hour before anybody noticed. Nav was `[]`, the sitemap held one URL, every
11
+ * page's `<title>` was the site name, the feed was empty and `resolve` answered
12
+ * `cacheReady: false` — while the site looked completely fine in a browser,
13
+ * because the CLIENT syncs the tree itself and does not need the cache at all.
14
+ *
15
+ * The cause was the one this repo has already paid 39 hours for: the runner's
16
+ * service identity did not match what the backend registered, `/auth/verify`
17
+ * answered 401, and `requireServiceRole` refused to boot every runner — the SSR
18
+ * cache, the RPC handlers, the seeder and the janitor, all of it, silently.
19
+ *
20
+ * Silence is the bug this file is about. The container's healthcheck was
21
+ * `GET / → status < 500`, which a site with no runners passes perfectly.
22
+ *
23
+ * ── The four states, and why "degraded" is not "dead" ────────────────────────
24
+ *
25
+ * `starting` — nothing yet, and not enough time has passed to call it. A cold
26
+ * boot legitimately has an empty cache: the runner authenticates, syncs the root
27
+ * document, then renders every page through a bounded pool. Calling that dead
28
+ * would crash-loop every deploy.
29
+ *
30
+ * `ready` — the tree is there and bodies are rendering.
31
+ *
32
+ * `degraded` — the tree arrived and the BODIES did not. Pages have titles and no
33
+ * prose. Worth shouting about, not worth killing a container over: this is also
34
+ * what a very large site looks like halfway through its first render pass.
35
+ *
36
+ * `dead` — past the deadline with nothing at all, OR a cache nothing is keeping
37
+ * fresh. There is no site in this state, only a client-side app pretending to be
38
+ * one, and the healthcheck must fail so an orchestrator does something.
39
+ *
40
+ * ── A warm cache is not a live runner, and that nearly slipped through ───────
41
+ *
42
+ * The first version of this asked only "is there cache". Reproducing the jun.is
43
+ * failure locally — a deliberately wrong service key, so `/auth/verify` answered
44
+ * 401 and no runner booted — reported **ready**, because the doc cache persists on
45
+ * disk (`/app/.data`) and the previous process had filled it. A restarted container
46
+ * with a stale volume would therefore look healthy while serving a frozen snapshot
47
+ * of a site nobody can update: every owner edit invisible to crawlers, forever.
48
+ *
49
+ * So readiness needs a HEARTBEAT — a stamp the doc-cache runner writes on every
50
+ * sweep. Cache with no recent heartbeat is dead, whatever the cache holds.
51
+ */
52
+ export type JunReadinessState = 'starting' | 'ready' | 'degraded' | 'dead';
53
+ export interface JunReadinessFacts {
54
+ /** Documents in the cached root `doc-tree`. The single most telling number. */
55
+ treeSize: number;
56
+ /** Entries in the persisted slug map — written by `@abraca/nuxt`'s own runner. */
57
+ slugCount: number;
58
+ /** How many documents have a cached HTML body. */
59
+ bodyCount: number;
60
+ /** Milliseconds since this process started serving. */
61
+ ageMs: number;
62
+ /**
63
+ * Milliseconds since the doc-cache runner last swept, or `null` when it has
64
+ * never stamped one in this process's lifetime.
65
+ */
66
+ heartbeatAgeMs?: number | null;
67
+ /**
68
+ * Whether a heartbeat is expected at all. `false` on a site that switched the
69
+ * doc cache off (`jun.features.docCache: false`) — a check that screams about a
70
+ * runner nobody asked for is a check people learn to ignore.
71
+ */
72
+ expectHeartbeat?: boolean;
73
+ }
74
+ export interface JunReadinessVerdict {
75
+ state: JunReadinessState;
76
+ /** True when a healthcheck should pass. `degraded` still serves a real site. */
77
+ healthy: boolean;
78
+ /** One line, for a log or a JSON body. */
79
+ reason: string;
80
+ /** What to check, when it is not healthy. Named causes beat "something failed". */
81
+ hint?: string;
82
+ }
83
+ /**
84
+ * How long a cold boot may take before an empty cache is a failure.
85
+ *
86
+ * Generous on purpose. The runner authenticates, waits for the root document to
87
+ * sync (its own bounded retry), then renders documents through a pool of six
88
+ * short-lived providers — and on a first-ever boot the SEEDER runs first, writing
89
+ * a tree, then bodies, then uploads. Two minutes is comfortably past all of that
90
+ * and still fast enough that a broken deploy is caught while somebody is watching
91
+ * it.
92
+ */
93
+ export declare const JUN_READY_DEADLINE_MS = 120000;
94
+ /**
95
+ * How long a heartbeat may be missing before the runner counts as gone.
96
+ *
97
+ * The doc-cache runner re-renders every 120s, so three missed sweeps is the floor
98
+ * for "not merely slow". Much higher and a frozen site can serve stale HTML to
99
+ * crawlers for a quarter of an hour before anything says so.
100
+ */
101
+ export declare const JUN_HEARTBEAT_DEADLINE_MS = 420000;
102
+ /** Why a warm cache with no heartbeat is the worst of the failure modes. */
103
+ export declare const JUN_STALE_HINT: string;
104
+ /**
105
+ * The things to check when a deployment is `dead`, in the order they fail.
106
+ *
107
+ * Stated here rather than in the log line because the health ENDPOINT should say
108
+ * it too — the whole point is that the next person does not have to know this
109
+ * repo's history to read the symptom.
110
+ *
111
+ * ⚠️ **This list was wrong once, and the cost was days.** On 2026-08-13 a deploy
112
+ * failed with `POST /auth/verify: challenge expired (410)` and the hint named
113
+ * three causes, none of which was that one — so every diagnostic attempt went
114
+ * hunting a key mismatch that did not exist. The 410 is now (1), because it is
115
+ * both the most likely on a container platform and the one nothing else names.
116
+ *
117
+ * **Distinguish the two auth failures by STATUS, they are opposites:**
118
+ * • **410** → transient. The backend process that answered `/auth/verify` is
119
+ * not the one that answered `/auth/challenge`. Nothing is misconfigured.
120
+ * • **401** → permanent. The key really is not registered. No retry fixes it.
121
+ */
122
+ export declare const JUN_DEAD_HINT: string;
123
+ export declare function junReadiness(facts: JunReadinessFacts): JunReadinessVerdict;
124
+ /**
125
+ * Should the watchdog say something at this tick?
126
+ *
127
+ * A dead deployment must be loud — but a line every two seconds is a log nobody
128
+ * reads, which is the same failure in a different costume. Once when it turns
129
+ * dead, then every `intervalMs`, and never while it is healthy.
130
+ */
131
+ export declare function junShouldWarn(state: JunReadinessState, lastWarnedAt: number | null, now: number, intervalMs?: number): boolean;
@@ -0,0 +1,69 @@
1
+ export const JUN_READY_DEADLINE_MS = 12e4;
2
+ export const JUN_HEARTBEAT_DEADLINE_MS = 42e4;
3
+ export const JUN_STALE_HINT = "The cache is warm but NOTHING IS KEEPING IT FRESH \u2014 the doc-cache runner has not swept. A persisted cache (/app/.data) outlives the process that filled it, so a restarted container serves a frozen snapshot: every edit since is invisible to crawlers and to first paint. Same three causes as an empty cache, and the same first check \u2014 401s on POST /auth/verify in the backend's metrics mean the service identity no longer matches.";
4
+ export const JUN_DEAD_HINT = `No server runner booted. In order of likelihood: (1) a SPLIT HANDSHAKE \u2014 the runner's POST /auth/verify reached a different backend process than its POST /auth/challenge did, which answers 410 "challenge expired" even though nothing expired (the challenge store is per-process). Normal while a deploy is swapping containers; needs @abraca/nuxt >= the release that retries, and Abracadabra >= the release whose challenges any replica can verify. The tell is 410s \u2014 not 401s \u2014 on POST /auth/verify in the backend's metrics; (2) the service identity \u2014 the runner's NUXT_ABRACADABRA_SERVICE_PUBLIC_KEY/_PRIVATE_KEY must match the key the backend registered for ABRA_USERS_SYSTEM_USERNAME, and the backend only registers a key at ITS boot, so recreate both containers after a rotation (the tell is 401s on POST /auth/verify); (3) the runner's own backend URL (NUXT_ABRACADABRA_SERVICE_SERVER_URL, internal container DNS \u2014 the browser's public URL working proves nothing about it); (4) a throw in an app Nitro plugin's before-runners hook, which @abraca/nuxt logs as "[abracadabra-service] Failed to initialize".`;
5
+ export function junReadiness(facts) {
6
+ const { treeSize, slugCount, bodyCount, ageMs } = facts;
7
+ const expectHeartbeat = facts.expectHeartbeat !== false;
8
+ const heartbeatAgeMs = facts.heartbeatAgeMs ?? null;
9
+ const nothing = treeSize === 0 && slugCount === 0 && bodyCount === 0;
10
+ if (nothing) {
11
+ return ageMs < JUN_READY_DEADLINE_MS ? {
12
+ state: "starting",
13
+ healthy: true,
14
+ reason: `the SSR cache is empty ${Math.round(ageMs / 1e3)}s into boot \u2014 still filling`
15
+ } : {
16
+ state: "dead",
17
+ healthy: false,
18
+ reason: `the SSR cache is still EMPTY ${Math.round(ageMs / 1e3)}s after boot: no document tree, no slug map, no rendered bodies`,
19
+ hint: JUN_DEAD_HINT
20
+ };
21
+ }
22
+ if (expectHeartbeat && heartbeatAgeMs === null && ageMs < JUN_READY_DEADLINE_MS) {
23
+ return {
24
+ state: "starting",
25
+ healthy: true,
26
+ reason: `${treeSize} document(s) cached, waiting for this process's first sweep`
27
+ };
28
+ }
29
+ if (expectHeartbeat && ageMs >= JUN_READY_DEADLINE_MS) {
30
+ if (heartbeatAgeMs === null) {
31
+ return {
32
+ state: "dead",
33
+ healthy: false,
34
+ reason: `the cache holds ${treeSize} document(s) and the doc-cache runner has NEVER swept in this process \u2014 the cache is left over from an earlier one`,
35
+ hint: JUN_STALE_HINT
36
+ };
37
+ }
38
+ if (heartbeatAgeMs >= JUN_HEARTBEAT_DEADLINE_MS) {
39
+ return {
40
+ state: "dead",
41
+ healthy: false,
42
+ reason: `the doc-cache runner last swept ${Math.round(heartbeatAgeMs / 1e3)}s ago \u2014 the ${treeSize}-document cache is frozen`,
43
+ hint: JUN_STALE_HINT
44
+ };
45
+ }
46
+ }
47
+ if (bodyCount === 0) {
48
+ return ageMs < JUN_READY_DEADLINE_MS ? {
49
+ state: "starting",
50
+ healthy: true,
51
+ reason: `${treeSize} document(s) cached, bodies still rendering`
52
+ } : {
53
+ state: "degraded",
54
+ healthy: true,
55
+ reason: `${treeSize} document(s) cached and NO rendered bodies \u2014 every page will server-render a title with no prose`,
56
+ hint: "The tree arrived, so the runner authenticated. Check the doc-cache runner: a per-IP WebSocket cap (server.max_ws_connections_per_ip) gives 429 to sockets past it and those documents render empty."
57
+ };
58
+ }
59
+ return {
60
+ state: "ready",
61
+ healthy: true,
62
+ reason: `${treeSize} document(s), ${slugCount} slug(s), ${bodyCount} rendered body(ies)` + (heartbeatAgeMs === null ? "" : `, swept ${Math.round(heartbeatAgeMs / 1e3)}s ago`)
63
+ };
64
+ }
65
+ export function junShouldWarn(state, lastWarnedAt, now, intervalMs = 6e4) {
66
+ if (state === "ready" || state === "starting") return false;
67
+ if (lastWarnedAt === null) return true;
68
+ return now - lastWarnedAt >= intervalMs;
69
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The arithmetic behind section presence — *which part of a long page is this
3
+ * person reading.* No Vue, no `#imports`, **no imports at all**, for the same
4
+ * reason `junViewValues.ts` has none: this is the half worth pinning, and the
5
+ * composable around it cannot load outside a Nuxt app.
6
+ *
7
+ * ── Why jun computes this itself ─────────────────────────────────────────────
8
+ *
9
+ * `@abraca/nuxt` ships `useAAViewport`, and it matches on `data-section`
10
+ * attributes. On the pages where knowing the section is actually worth
11
+ * something — an entry, a project, a doc page — the sections are **headings
12
+ * inside ProseMirror-managed DOM**, and this module may not put an attribute
13
+ * there: writing into PM's DOM triggers the re-parse loop the standing rule in
14
+ * `CLAUDE.md` exists to prevent. Measured on the demo's `/docs/*` pages: an `h1`
15
+ * plus two to four `h2`s, **none of them carrying an id**. There is nothing to
16
+ * key on that exists already, and nothing may be added.
17
+ *
18
+ * So the identity of a section is its own text, and its position is measured.
19
+ * Reading rects and `textContent` is not mutation.
20
+ *
21
+ * ── Why not an IntersectionObserver ─────────────────────────────────────────
22
+ *
23
+ * Which is what the deferral note in `FOLLOW-UP.md` assumed. IO fires on
24
+ * threshold CROSSINGS, so a reader who stops moving produces no event at all —
25
+ * and this question has to be answerable at an arbitrary moment: when a second
26
+ * reader loads the page, when somebody starts following, when a peer's chip is
27
+ * first rendered. A crossing log cannot answer "where are you now"; a rect read
28
+ * against a reading line always can.
29
+ */
30
+ /** What one peer broadcasts. Short keys — this rides on every awareness update. */
31
+ export interface JunSectionMark {
32
+ /** Which document, so a peer reading elsewhere is never drawn on this page. */
33
+ d: string;
34
+ /** Index into the page's heading list, in document order. */
35
+ i: number;
36
+ /** The heading's text, so a peer on an older build still reads as SOMEWHERE. */
37
+ t: string;
38
+ }
39
+ /** A heading found in the rendered page, with where it sits inside its box. */
40
+ export interface JunHeading {
41
+ index: number;
42
+ level: number;
43
+ text: string;
44
+ slug: string;
45
+ /** Pixels from the top of the container that owns the markers. */
46
+ offset: number;
47
+ }
48
+ /**
49
+ * Where in the viewport counts as "what you are reading".
50
+ *
51
+ * A third of the way down, not the top edge: the line you are actually reading
52
+ * on a page you have scrolled to is below the fold's start, and anchoring at 0
53
+ * makes the current section flip to the next one the instant its heading appears
54
+ * at the bottom of the screen — while it is still off the page as far as the
55
+ * reader is concerned.
56
+ */
57
+ export declare const JUN_READING_LINE = 0.35;
58
+ /** A stable, human-readable id for a heading, derived only from its text. */
59
+ export declare function junSlugSection(text: string): string;
60
+ /**
61
+ * A heading shortened for a chip, on a word boundary where there is one.
62
+ *
63
+ * Headings are prose and prose is not short. `truncate` in CSS would do this
64
+ * visually, but the same string goes into `title` and `aria-label`, where a
65
+ * screen reader would read all 140 characters of it.
66
+ *
67
+ * Three cases, and the middle one is the reason this is not a one-liner:
68
+ *
69
+ * - the cut lands mid-word → back up to the last space;
70
+ * - the cut does not split a word at all — the next character is a space or
71
+ * punctuation → keep it. Backing up here threw away a word that fitted
72
+ * ("…is not a data-loss" for a heading whose 43rd character was the space
73
+ * after "button,");
74
+ * - there is no space to back up to → cut anyway. A 60-character single token
75
+ * must not be allowed to overflow just because it is one word.
76
+ */
77
+ export declare function junSectionLabel(text: string, max?: number): string;
78
+ /**
79
+ * The section a reader is in, given every heading's viewport-relative top.
80
+ *
81
+ * The last heading at or above the reading line. Returns **-1** when every
82
+ * heading is still below it — a reader in a hero, above the first heading, is
83
+ * honestly nowhere yet, and inventing section 0 for them would put a dot beside
84
+ * a heading nobody has reached.
85
+ *
86
+ * Defensive about order: the maximum top at or above the line, not "the last one
87
+ * I walked past", so a page whose headings measure out of document order (a
88
+ * two-column layout, a float) still resolves to the nearest one above.
89
+ */
90
+ export declare function junCurrentSectionIndex(tops: number[], readingLine: number): number;
91
+ /** Has the mark changed in a way worth putting on the wire? */
92
+ export declare function junSectionMarkChanged(a: JunSectionMark | null, b: JunSectionMark | null): boolean;
93
+ /**
94
+ * Whether to broadcast at all.
95
+ *
96
+ * The same rule follow-mode's scroll broadcast already follows: **write nothing
97
+ * when nobody can see it.** Most page views on most sites are one person alone,
98
+ * and a section field updating on every scroll would put an awareness write on
99
+ * the wire for every one of them, forever, for no reader.
100
+ *
101
+ * `followers` counts too, and separately: somebody travelling with you is
102
+ * watching your position even when they are not counted among the page's readers
103
+ * yet — they arrive a moment after you do.
104
+ */
105
+ export declare function junShouldBroadcastSection(readers: number, followers: number): boolean;
106
+ /**
107
+ * Bucket peers by the section they are in, dropping anyone reading a different
108
+ * document or nowhere in particular.
109
+ *
110
+ * Takes an ALREADY DEDUPLICATED list — `junDedupePeople` owns that rule, and a
111
+ * second copy of it here is how the counting bug got into five places last time.
112
+ */
113
+ export declare function junGroupBySection<T extends {
114
+ mark: JunSectionMark;
115
+ }>(peers: T[], docId: string): Map<number, T[]>;
@@ -0,0 +1,45 @@
1
+ export const JUN_READING_LINE = 0.35;
2
+ export function junSlugSection(text) {
3
+ return text.toLowerCase().normalize("NFKD").replace(/[\u0300-\u036F]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
4
+ }
5
+ export function junSectionLabel(text, max = 42) {
6
+ const clean = text.replace(/\s+/g, " ").trim();
7
+ if (clean.length <= max) return clean;
8
+ const cut = clean.slice(0, max);
9
+ const atWordEnd = !/[\p{L}\p{N}]/u.test(clean[max] ?? "");
10
+ const space = cut.lastIndexOf(" ");
11
+ const kept = atWordEnd || space <= max * 0.6 ? cut : cut.slice(0, space);
12
+ return `${kept.replace(/[\s,;:.–—-]+$/, "")}\u2026`;
13
+ }
14
+ export function junCurrentSectionIndex(tops, readingLine) {
15
+ let best = -1;
16
+ let bestTop = -Infinity;
17
+ for (let i = 0; i < tops.length; i++) {
18
+ const top = tops[i];
19
+ if (top > readingLine) continue;
20
+ if (top >= bestTop) {
21
+ bestTop = top;
22
+ best = i;
23
+ }
24
+ }
25
+ return best;
26
+ }
27
+ export function junSectionMarkChanged(a, b) {
28
+ if (!a || !b) return a !== b;
29
+ return a.d !== b.d || a.i !== b.i || a.t !== b.t;
30
+ }
31
+ export function junShouldBroadcastSection(readers, followers) {
32
+ return readers > 0 || followers > 0;
33
+ }
34
+ export function junGroupBySection(peers, docId) {
35
+ const out = /* @__PURE__ */ new Map();
36
+ if (!docId) return out;
37
+ for (const peer of peers) {
38
+ if (peer.mark.d !== docId) continue;
39
+ if (!Number.isInteger(peer.mark.i) || peer.mark.i < 0) continue;
40
+ const held = out.get(peer.mark.i);
41
+ if (held) held.push(peer);
42
+ else out.set(peer.mark.i, [peer]);
43
+ }
44
+ return out;
45
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The arithmetic behind `jun-deck` — turning a document into slides.
3
+ *
4
+ * No Vue, no `#imports`, **no imports at all**, for the same reason the other
5
+ * three utils here have none: this is the half worth pinning, and the renderer
6
+ * around it cannot be loaded outside a Nuxt app.
7
+ *
8
+ * ── A deck is a document, not a new content model ────────────────────────────
9
+ *
10
+ * The whole point of this page type is that a talk is *already written*: an entry
11
+ * with headings IS an outline, and an outline IS a deck. So there is no slide
12
+ * editor, no slide array in meta, and nothing to migrate — an `h2` starts a
13
+ * slide, everything under it belongs to that slide, and anything before the first
14
+ * `h2` is the title slide.
15
+ *
16
+ * That also means converting a page type never loses anything, which is the rule
17
+ * every renderer here follows: a deck turned back into an entry is the same prose.
18
+ *
19
+ * ── Why it splits HTML rather than the CRDT fragment ─────────────────────────
20
+ *
21
+ * Because the module must never mutate ProseMirror's DOM, and reading it is
22
+ * explicitly fine (see `junSections.ts`). The renderer reads the rendered prose
23
+ * container's `innerHTML` — one read, re-run when a `MutationObserver` says the
24
+ * document changed — and presents its OWN elements built from the result. The
25
+ * alternative, hiding every node that is not the current slide, would style
26
+ * PM-managed DOM and trip the re-parse loop.
27
+ */
28
+ /** One slide: its heading, and the markup that belongs under it. */
29
+ export interface JunSlide {
30
+ /** Heading text, or `''` for the title slide when it has none. */
31
+ title: string;
32
+ /** The heading's own level, so a deck can render `h1` differently from `h2`. */
33
+ level: number;
34
+ /** Inner HTML for the slide's body — everything up to the next heading. */
35
+ html: string;
36
+ }
37
+ /**
38
+ * Split a document's rendered HTML into slides at every `h1`/`h2`.
39
+ *
40
+ * Anything before the first heading becomes the TITLE slide, which is what makes
41
+ * a deck out of a page that opens with a paragraph — the common case, since the
42
+ * document's own title is rendered by the page above the prose.
43
+ *
44
+ * Empty slides are dropped: a heading typed a moment ago with nothing under it
45
+ * yet should not put a blank screen in the middle of a talk. A heading with no
46
+ * body but a following heading is kept — that is a section divider, deliberately.
47
+ */
48
+ export declare function junSplitSlides(html: string): JunSlide[];
49
+ /**
50
+ * Keep a slide index inside a deck that may have changed under you.
51
+ *
52
+ * The deck is a live document: a co-author can delete the slide you are on while
53
+ * you are on it, and a viewer following a presenter can receive an index from a
54
+ * longer version than they have synced. Clamping is what keeps that from being a
55
+ * blank screen.
56
+ */
57
+ export declare function junClampSlide(index: number, count: number): number;
58
+ /**
59
+ * Advance by `delta`, stopping at the ends rather than wrapping.
60
+ *
61
+ * Not a carousel: wrapping from the last slide to the first mid-talk looks
62
+ * exactly like a crash, and the audience cannot tell which it was.
63
+ */
64
+ export declare function junStepSlide(index: number, delta: number, count: number): number;
65
+ /** `3 / 12`, and the fraction a progress bar wants. */
66
+ export declare function junSlideProgress(index: number, count: number): number;
@@ -0,0 +1,47 @@
1
+ const SLIDE_HEADING = /<(?<tag>h[12])\b[^>]*>(?<text>[\s\S]*?)<\/\k<tag>>/gi;
2
+ const TAGS = /<[^>]*>/g;
3
+ function plain(html) {
4
+ return html.replace(TAGS, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
5
+ }
6
+ function hasContent(html) {
7
+ return plain(html).length > 0 || /<(?:img|video|iframe|figure|table|ul|ol|pre|blockquote)\b/i.test(html);
8
+ }
9
+ export function junSplitSlides(html) {
10
+ const source = String(html ?? "");
11
+ if (!source.trim()) return [];
12
+ const marks = [];
13
+ SLIDE_HEADING.lastIndex = 0;
14
+ for (; ; ) {
15
+ const match = SLIDE_HEADING.exec(source);
16
+ if (!match) break;
17
+ marks.push({
18
+ index: match.index,
19
+ length: match[0].length,
20
+ level: Number(match.groups.tag.slice(1)) || 2,
21
+ title: plain(match.groups.text ?? "")
22
+ });
23
+ }
24
+ const out = [];
25
+ const firstAt = marks.length ? marks[0].index : source.length;
26
+ const opening = source.slice(0, firstAt);
27
+ if (hasContent(opening)) out.push({ title: "", level: 1, html: opening.trim() });
28
+ marks.forEach((mark, i) => {
29
+ const from = mark.index + mark.length;
30
+ const to = i + 1 < marks.length ? marks[i + 1].index : source.length;
31
+ const body = source.slice(from, to).trim();
32
+ if (!mark.title && !hasContent(body)) return;
33
+ out.push({ title: mark.title, level: mark.level, html: body });
34
+ });
35
+ return out;
36
+ }
37
+ export function junClampSlide(index, count) {
38
+ if (!Number.isFinite(index) || count <= 0) return 0;
39
+ return Math.min(Math.max(0, Math.trunc(index)), count - 1);
40
+ }
41
+ export function junStepSlide(index, delta, count) {
42
+ return junClampSlide(index + delta, count);
43
+ }
44
+ export function junSlideProgress(index, count) {
45
+ if (count <= 1) return 1;
46
+ return junClampSlide(index, count) / (count - 1);
47
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The arithmetic behind `jun-thread` — flat documents into a conversation.
3
+ *
4
+ * No Vue and no `#imports`. Its ONE import is `junModeration` — what "removed"
5
+ * and "pinned" mean is shared with the guestbook, and two spellings of removed
6
+ * would mean a post hidden on one page and visible on another.
7
+ *
8
+ * ── Posts are documents, and replies are meta ────────────────────────────────
9
+ *
10
+ * Every post is a hidden child document of the thread — the same shape the
11
+ * guestbook's signatures have, so moderation, trash, search exclusion and the
12
+ * permission cascade all work without inventing anything. A reply carries
13
+ * `meta.replyTo`, the id of the post it answers.
14
+ *
15
+ * That is deliberately NOT a nested data structure in one document: a thread that
16
+ * lived in a single meta blob would rewrite every reply on every post, which is
17
+ * both a merge conflict waiting to happen and a way to lose somebody else's words
18
+ * while adding your own.
19
+ *
20
+ * ── Two rules a conversation needs and a list does not ───────────────────────
21
+ *
22
+ * **A cycle is not a conversation.** `meta.replyTo` is a string somebody wrote:
23
+ * two posts can point at each other, and a naive walk would recurse until the
24
+ * stack gave out. Anything unreachable from the root is re-parented to the top
25
+ * rather than dropped — losing a reply because its parent was deleted is worse
26
+ * than showing it in the wrong place.
27
+ *
28
+ * **Depth has to stop.** Not for looks: each level costs indentation, and past
29
+ * three or four a reply on a phone is a column one word wide.
30
+ */
31
+ /** How deep a rendered conversation may nest before replies flatten. */
32
+ export declare const JUN_THREAD_DEPTH_MAX = 6;
33
+ export interface JunThreadPostInput {
34
+ id: string;
35
+ label: string;
36
+ parentId?: string | null;
37
+ trashed?: boolean;
38
+ meta?: Record<string, unknown>;
39
+ }
40
+ export interface JunThreadPost {
41
+ id: string;
42
+ /** The handle the server stamped, falling back to the document's label. */
43
+ handle: string;
44
+ message: string;
45
+ date: number;
46
+ /** The signer id, so a reader can be shown their own posts. */
47
+ signerId: string | null;
48
+ hidden: boolean;
49
+ pinned: boolean;
50
+ depth: number;
51
+ replies: JunThreadPost[];
52
+ }
53
+ /**
54
+ * Build the conversation.
55
+ *
56
+ * `newest` orders siblings at every level, including the root, because a thread
57
+ * read newest-first is a different thing from one read in order and both are
58
+ * legitimate — an announcement wants oldest first, a question wants newest.
59
+ *
60
+ * Pinned posts always come first at the root, whatever the order: pinning is an
61
+ * owner saying "read this one", and an order that could bury it makes the act
62
+ * meaningless.
63
+ */
64
+ export declare function junThreadTree(posts: JunThreadPostInput[], options?: {
65
+ threadId: string;
66
+ newest?: boolean;
67
+ depthMax?: number;
68
+ includeHidden?: boolean;
69
+ }): JunThreadPost[];
70
+ /** How many posts a conversation has, replies and all. */
71
+ export declare function junThreadCount(list: JunThreadPost[]): number;
72
+ /**
73
+ * Is `replyTo` a legal parent for a new post in this thread?
74
+ *
75
+ * The server's check. A reply may only answer a post in the SAME thread — without
76
+ * this, a `replyTo` pointing at any document id would let somebody graft a
77
+ * conversation onto a page that is not a thread at all.
78
+ */
79
+ export declare function junCanReplyTo(
80
+ /** Only identity and parentage matter here — the server has no labels to hand. */
81
+ posts: Pick<JunThreadPostInput, 'id' | 'parentId' | 'trashed'>[], threadId: string, replyTo: string | null | undefined): boolean;
@@ -0,0 +1,75 @@
1
+ import { junIsModerated, junIsPinned } from "./junModeration.js";
2
+ export const JUN_THREAD_DEPTH_MAX = 6;
3
+ function text(value) {
4
+ return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
5
+ }
6
+ export function junThreadTree(posts, options = { threadId: "" }) {
7
+ const depthMax = Math.max(1, Math.min(options.depthMax ?? 4, JUN_THREAD_DEPTH_MAX));
8
+ const flat = /* @__PURE__ */ new Map();
9
+ const replyTo = /* @__PURE__ */ new Map();
10
+ for (const entry of posts) {
11
+ if (!entry?.id || entry.trashed) continue;
12
+ if (options.threadId && entry.parentId !== options.threadId) continue;
13
+ const meta = entry.meta ?? {};
14
+ const message = text(meta.message);
15
+ if (!message) continue;
16
+ const hidden = junIsModerated(meta);
17
+ if (hidden && !options.includeHidden) continue;
18
+ flat.set(entry.id, {
19
+ id: entry.id,
20
+ handle: text(meta.signerHandle) || text(entry.label) || "Traveller",
21
+ message,
22
+ date: typeof meta.date === "number" ? meta.date : 0,
23
+ signerId: typeof meta.signerId === "string" ? meta.signerId : null,
24
+ hidden,
25
+ pinned: junIsPinned(meta),
26
+ depth: 0,
27
+ replies: []
28
+ });
29
+ const parent = text(meta.replyTo);
30
+ if (parent && parent !== entry.id) replyTo.set(entry.id, parent);
31
+ }
32
+ function reaches(id, parent) {
33
+ let at = parent;
34
+ let steps = 0;
35
+ while (at && steps++ < flat.size + 1) {
36
+ if (at === id) return true;
37
+ at = replyTo.get(at);
38
+ }
39
+ return false;
40
+ }
41
+ const roots = [];
42
+ for (const post of flat.values()) {
43
+ const parentId = replyTo.get(post.id);
44
+ const parent = parentId ? flat.get(parentId) : void 0;
45
+ if (!parent || reaches(post.id, parentId)) {
46
+ roots.push(post);
47
+ continue;
48
+ }
49
+ parent.replies.push(post);
50
+ }
51
+ const sort = (a, b) => options.newest ? b.date - a.date : a.date - b.date;
52
+ function settle(list, depth) {
53
+ list.sort(sort);
54
+ for (const post of list) {
55
+ post.depth = depth;
56
+ const replies = settle(post.replies, Math.min(depth + 1, depthMax));
57
+ if (depth + 1 > depthMax) {
58
+ post.replies = [];
59
+ list.push(...replies.map((r) => ({ ...r, depth })));
60
+ } else {
61
+ post.replies = replies;
62
+ }
63
+ }
64
+ return list;
65
+ }
66
+ const settled = settle(roots, 0);
67
+ return [...settled].sort((a, b) => Number(b.pinned) - Number(a.pinned));
68
+ }
69
+ export function junThreadCount(list) {
70
+ return list.reduce((total, post) => total + 1 + junThreadCount(post.replies), 0);
71
+ }
72
+ export function junCanReplyTo(posts, threadId, replyTo) {
73
+ if (!replyTo) return true;
74
+ return posts.some((p) => p.id === replyTo && p.parentId === threadId && !p.trashed);
75
+ }