@abraca/junis 2.85.0 → 2.87.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 (161) hide show
  1. package/dist/module.d.mts +17 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +253 -21
  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/JunDocSurface.vue +3 -0
  13. package/dist/runtime/components/JunFooter.vue +1 -1
  14. package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
  15. package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
  16. package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
  17. package/dist/runtime/components/JunLinksRow.vue +17 -7
  18. package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
  19. package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
  20. package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
  21. package/dist/runtime/components/JunNavigation.vue +21 -4
  22. package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
  23. package/dist/runtime/components/JunNoteLinks.vue +57 -0
  24. package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
  25. package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
  26. package/dist/runtime/components/JunPageHero.vue +15 -3
  27. package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
  28. package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
  29. package/dist/runtime/components/JunReaders.vue +99 -0
  30. package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
  31. package/dist/runtime/components/JunSearch.client.vue +2 -2
  32. package/dist/runtime/components/JunSectionPresence.d.vue.ts +17 -0
  33. package/dist/runtime/components/JunSectionPresence.vue +99 -0
  34. package/dist/runtime/components/JunSectionPresence.vue.d.ts +17 -0
  35. package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
  36. package/dist/runtime/components/JunThreadComposer.vue +54 -0
  37. package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
  38. package/dist/runtime/components/JunTravellersChip.vue +35 -5
  39. package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
  40. package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
  41. package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
  42. package/dist/runtime/components/JunViewControl.vue +340 -0
  43. package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
  44. package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
  45. package/dist/runtime/components/JunViewControls.vue +94 -0
  46. package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
  47. package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
  48. package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
  49. package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
  50. package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
  51. package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
  52. package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
  53. package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
  54. package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
  55. package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
  56. package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
  57. package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
  58. package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
  59. package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
  60. package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
  61. package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
  62. package/dist/runtime/components/renderers/JunGlobeRenderer.vue +43 -26
  63. package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
  64. package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
  65. package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
  66. package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
  67. package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
  68. package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
  69. package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
  70. package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
  71. package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
  72. package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
  73. package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
  74. package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
  75. package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
  76. package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
  77. package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
  78. package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
  79. package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
  80. package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
  81. package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
  82. package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
  83. package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
  84. package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
  85. package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
  86. package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
  87. package/dist/runtime/composables/useJunDeck.d.ts +66 -0
  88. package/dist/runtime/composables/useJunDeck.js +61 -0
  89. package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
  90. package/dist/runtime/composables/useJunDocPage.js +67 -3
  91. package/dist/runtime/composables/useJunFollow.d.ts +65 -9
  92. package/dist/runtime/composables/useJunFollow.js +237 -20
  93. package/dist/runtime/composables/useJunGarden.d.ts +67 -0
  94. package/dist/runtime/composables/useJunGarden.js +92 -0
  95. package/dist/runtime/composables/useJunPresence.d.ts +26 -0
  96. package/dist/runtime/composables/useJunPresence.js +9 -2
  97. package/dist/runtime/composables/useJunSections.d.ts +73 -0
  98. package/dist/runtime/composables/useJunSections.js +117 -0
  99. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  100. package/dist/runtime/composables/useJunSettings.js +5 -1
  101. package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
  102. package/dist/runtime/composables/useJunTheme.js +40 -2
  103. package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
  104. package/dist/runtime/composables/useJunViewOptions.js +63 -0
  105. package/dist/runtime/pages/doc.vue +52 -42
  106. package/dist/runtime/pages/index.vue +61 -35
  107. package/dist/runtime/plugins/jun-doc-tree.d.ts +2 -0
  108. package/dist/runtime/plugins/jun-doc-tree.js +26 -0
  109. package/dist/runtime/server/api/health.get.d.ts +19 -0
  110. package/dist/runtime/server/api/health.get.js +40 -0
  111. package/dist/runtime/server/api/links.get.d.ts +19 -0
  112. package/dist/runtime/server/api/links.get.js +37 -0
  113. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
  114. package/dist/runtime/server/api/resolve/[...slug].get.js +7 -2
  115. package/dist/runtime/server/api/stats.get.js +2 -1
  116. package/dist/runtime/server/api/tree.get.d.ts +9 -0
  117. package/dist/runtime/server/api/tree.get.js +23 -0
  118. package/dist/runtime/server/janitor/junJanitorActor.d.ts +13 -0
  119. package/dist/runtime/server/janitor/junJanitorActor.js +36 -5
  120. package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
  121. package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
  122. package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
  123. package/dist/runtime/server/plugins/jun-janitor.js +7 -0
  124. package/dist/runtime/server/plugins/jun-rpc.js +293 -0
  125. package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
  126. package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
  127. package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
  128. package/dist/runtime/server/utils/junBoot.d.ts +1 -0
  129. package/dist/runtime/server/utils/junBoot.js +4 -0
  130. package/dist/runtime/server/utils/junCache.d.ts +17 -0
  131. package/dist/runtime/server/utils/junCache.js +5 -0
  132. package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
  133. package/dist/runtime/server/utils/junSeedGate.js +41 -0
  134. package/dist/runtime/types.d.ts +57 -1
  135. package/dist/runtime/utils/junCourse.d.ts +106 -0
  136. package/dist/runtime/utils/junCourse.js +65 -0
  137. package/dist/runtime/utils/junGarden.d.ts +193 -0
  138. package/dist/runtime/utils/junGarden.js +233 -0
  139. package/dist/runtime/utils/junMetaSchemas.js +8 -1
  140. package/dist/runtime/utils/junModeration.d.ts +67 -0
  141. package/dist/runtime/utils/junModeration.js +20 -0
  142. package/dist/runtime/utils/junMotion.d.ts +26 -0
  143. package/dist/runtime/utils/junMotion.js +31 -0
  144. package/dist/runtime/utils/junPeople.d.ts +43 -0
  145. package/dist/runtime/utils/junPeople.js +9 -0
  146. package/dist/runtime/utils/junPoll.d.ts +79 -0
  147. package/dist/runtime/utils/junPoll.js +82 -0
  148. package/dist/runtime/utils/junReadiness.d.ts +131 -0
  149. package/dist/runtime/utils/junReadiness.js +69 -0
  150. package/dist/runtime/utils/junSections.d.ts +115 -0
  151. package/dist/runtime/utils/junSections.js +45 -0
  152. package/dist/runtime/utils/junSlides.d.ts +66 -0
  153. package/dist/runtime/utils/junSlides.js +47 -0
  154. package/dist/runtime/utils/junThread.d.ts +81 -0
  155. package/dist/runtime/utils/junThread.js +75 -0
  156. package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
  157. package/dist/runtime/utils/junViewSpecs.js +534 -0
  158. package/dist/runtime/utils/junViewValues.d.ts +125 -0
  159. package/dist/runtime/utils/junViewValues.js +104 -0
  160. package/dist/types.d.mts +1 -1
  161. package/package.json +5 -1
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The arithmetic behind `jun-course` — a page you get THROUGH.
3
+ *
4
+ * No Vue, no `#imports`, **no imports at all**: the server validates a step and
5
+ * writes progress, the page draws two progress figures from the same data, and a
6
+ * test runs both without a Nuxt app. The server and the page must never disagree
7
+ * about how far somebody is.
8
+ *
9
+ * ── Progress is per PERSON, and the server writes it ─────────────────────────
10
+ *
11
+ * A visitor has no CRDT write access, so ticking a step goes through RPC v1 and
12
+ * lands under the identity the SERVER stamped (`meta.courseProgress[from]`). The
13
+ * same rule as the poll's ballots, for a stronger reason: progress is a claim
14
+ * about a person, so a second tab, a reload and a reconnect are one learner.
15
+ *
16
+ * ── Two numbers, and they answer different questions ─────────────────────────
17
+ *
18
+ * **How far YOU are** is the one a learner came for. **How far the ROOM is** is
19
+ * the one only a live document can offer — "nine people have finished this, you
20
+ * are on step three" is a fact about a shared page, not a progress bar.
21
+ *
22
+ * ── What it must not do ──────────────────────────────────────────────────────
23
+ *
24
+ * **No gating.** `junNextStep` says where to go next; nothing here says a step may
25
+ * not be opened. The steps are pages with their own URLs on a public website, so a
26
+ * lock a reader walks around by typing a path is theatre — and a lock that worked
27
+ * would mean hiding documents from the tree, which breaks search, the feed and the
28
+ * sitemap.
29
+ */
30
+ /** How many people's progress one course may hold. */
31
+ export declare const JUN_COURSE_MAX_PEOPLE = 5000;
32
+ /** How many steps one person's progress may name. */
33
+ export declare const JUN_COURSE_MAX_STEPS = 200;
34
+ export interface JunCourseStepInput {
35
+ id: string;
36
+ label?: string;
37
+ order?: number;
38
+ trashed?: boolean;
39
+ meta?: Record<string, unknown> | null;
40
+ }
41
+ export interface JunCourseStep {
42
+ id: string;
43
+ label: string;
44
+ /** 1-based, for display — a step called "0" reads as an error. */
45
+ number: number;
46
+ done: boolean;
47
+ /** How many people have finished this one. */
48
+ finishedBy: number;
49
+ }
50
+ /**
51
+ * The steps, in the owner's order.
52
+ *
53
+ * Trashed children drop out; a child with no label is still a step (an owner mid
54
+ * -typing must not see the list renumber itself), and hidden ones stay, because
55
+ * `meta.hidden` means "not in navigation" and never "not there".
56
+ */
57
+ export declare function junCourseSteps(children: JunCourseStepInput[]): JunCourseStepInput[];
58
+ /**
59
+ * `meta.courseProgress`, validated.
60
+ *
61
+ * Every layer is checked because this is stored data a newer build may have
62
+ * written: a non-object, a non-array value, a non-string step id and a step that
63
+ * is not in this course are all dropped rather than counted. An uncounted step
64
+ * would inflate somebody's progress past 100%.
65
+ */
66
+ export declare function junCourseProgress(meta: Record<string, unknown> | null | undefined, stepIds: string[]): Record<string, string[]>;
67
+ export interface JunCourseView {
68
+ steps: JunCourseStep[];
69
+ /** Steps this person has finished. */
70
+ done: number;
71
+ total: number;
72
+ /** 0–100, rounded. 100 only when every step is done. */
73
+ percent: number;
74
+ /** The first unfinished step, or `null` when there are none left. */
75
+ next: JunCourseStep | null;
76
+ /** People who have finished at least one step. */
77
+ people: number;
78
+ /** People who have finished every step. */
79
+ finished: number;
80
+ }
81
+ /**
82
+ * Everything a course page draws, from the steps and the stored progress.
83
+ *
84
+ * One function rather than six, because the figures have to be consistent with
85
+ * each other: a bar at 100% beside a "continue" button pointing at step three is
86
+ * the failure this shape makes impossible.
87
+ */
88
+ export declare function junCourseView(children: JunCourseStepInput[], meta: Record<string, unknown> | null | undefined, selfId: string | null | undefined): JunCourseView;
89
+ /**
90
+ * One person's next progress list after ticking a step.
91
+ *
92
+ * Returns `null` to REFUSE — an unknown step id, which is the server's check as
93
+ * well as the page's. Ticking is a toggle: a learner who marked a step by mistake
94
+ * must be able to unmark it, and a course that only counts up is a course people
95
+ * stop trusting.
96
+ */
97
+ export declare function junNextProgress(current: string[] | undefined, stepIds: string[], stepId: string): string[] | null;
98
+ /**
99
+ * Cap the number of PEOPLE a course remembers.
100
+ *
101
+ * Unbounded growth in one document's meta is the hazard the poll's ballots have
102
+ * too: every visitor's progress lives in the course's own entry, which every
103
+ * client syncs. Past the cap, new people are not recorded — their progress still
104
+ * works for the session, and the alternative (dropping somebody else's) is worse.
105
+ */
106
+ export declare function junCapProgress(progress: Record<string, string[]>, person: string, max?: number): boolean;
@@ -0,0 +1,65 @@
1
+ export const JUN_COURSE_MAX_PEOPLE = 5e3;
2
+ export const JUN_COURSE_MAX_STEPS = 200;
3
+ export function junCourseSteps(children) {
4
+ return children.filter((child) => !!child?.id && !child.trashed).slice().sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
5
+ }
6
+ export function junCourseProgress(meta, stepIds) {
7
+ const raw = meta?.courseProgress;
8
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
9
+ const known = new Set(stepIds);
10
+ const out = {};
11
+ for (const [person, value] of Object.entries(raw)) {
12
+ if (!person || !Array.isArray(value)) continue;
13
+ const seen = /* @__PURE__ */ new Set();
14
+ for (const id of value) {
15
+ if (typeof id !== "string" || !known.has(id) || seen.has(id)) continue;
16
+ seen.add(id);
17
+ if (seen.size >= JUN_COURSE_MAX_STEPS) break;
18
+ }
19
+ if (seen.size) out[person] = [...seen];
20
+ }
21
+ return out;
22
+ }
23
+ export function junCourseView(children, meta, selfId) {
24
+ const ordered = junCourseSteps(children);
25
+ const ids = ordered.map((step) => step.id);
26
+ const progress = junCourseProgress(meta, ids);
27
+ const mine = new Set(selfId ? progress[selfId] ?? [] : []);
28
+ const finishedBy = /* @__PURE__ */ new Map();
29
+ let finished = 0;
30
+ for (const list of Object.values(progress)) {
31
+ for (const id of list) finishedBy.set(id, (finishedBy.get(id) ?? 0) + 1);
32
+ if (ids.length > 0 && list.length === ids.length) finished++;
33
+ }
34
+ const steps = ordered.map((step, i) => ({
35
+ id: step.id,
36
+ label: (step.label ?? "").trim() || `Step ${i + 1}`,
37
+ number: i + 1,
38
+ done: mine.has(step.id),
39
+ finishedBy: finishedBy.get(step.id) ?? 0
40
+ }));
41
+ const done = steps.filter((step) => step.done).length;
42
+ const total = steps.length;
43
+ return {
44
+ steps,
45
+ done,
46
+ total,
47
+ // Rounded, but never 99 for a finished course and never 100 for an unfinished
48
+ // one: `Math.round` alone would report 100% at 199 of 200 steps.
49
+ percent: total === 0 ? 0 : done === total ? 100 : Math.min(99, Math.round(done / total * 100)),
50
+ next: steps.find((step) => !step.done) ?? null,
51
+ people: Object.keys(progress).length,
52
+ finished
53
+ };
54
+ }
55
+ export function junNextProgress(current, stepIds, stepId) {
56
+ if (!stepIds.includes(stepId)) return null;
57
+ const seen = new Set((current ?? []).filter((id) => stepIds.includes(id)));
58
+ if (seen.has(stepId)) seen.delete(stepId);
59
+ else if (seen.size >= JUN_COURSE_MAX_STEPS) return null;
60
+ else seen.add(stepId);
61
+ return stepIds.filter((id) => seen.has(id));
62
+ }
63
+ export function junCapProgress(progress, person, max = JUN_COURSE_MAX_PEOPLE) {
64
+ return person in progress || Object.keys(progress).length < max;
65
+ }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The arithmetic behind `jun-garden` — a document tree read as a graph.
3
+ *
4
+ * No Vue, no `#imports`, **no imports at all**: the endpoint builds the edges in
5
+ * Nitro, the renderer draws them in a browser, and a test runs both without a
6
+ * Nuxt app anywhere. Three things live here.
7
+ *
8
+ * ── 1. Two kinds of link, and the second one is the common case ──────────────
9
+ *
10
+ * The platform has a wiki-style reference: `[[doc]]` in the editor becomes a link
11
+ * to `/doc/<id>` (or a `docLink` / `docEmbed` node carrying `data-doc-id`). That
12
+ * is the one a graph view is obviously supposed to follow.
13
+ *
14
+ * It is not the one people write. Somebody linking one note to another usually
15
+ * writes an ordinary link to the other page's PATH, because that is what a link
16
+ * is. A garden that understood only its own syntax would show an empty graph on a
17
+ * site full of cross-references — so a path resolves too, through the slug map
18
+ * the site already keeps for routing.
19
+ *
20
+ * An external link is not an edge, and neither is a path this site does not have:
21
+ * a graph must not invent a node for `/notes/something-i-never-wrote`.
22
+ *
23
+ * ── 2. Maturity is a claim, and an unstated one is not `seedling` ────────────
24
+ *
25
+ * `junMaturityOf` returns **null** for a note whose author never said. Defaulting
26
+ * to `seedling` would print a judgement on every page that predates the setting —
27
+ * the site would appear to claim that a decade of tended writing is rough drafts.
28
+ *
29
+ * ── 3. The layout has to be deterministic ────────────────────────────────────
30
+ *
31
+ * The same graph is drawn during SSR and again after hydration. A force layout
32
+ * seeded from `Math.random()` is therefore a hydration mismatch BY CONSTRUCTION —
33
+ * every node in a different place on the client than the server sent. So: fixed
34
+ * starting positions, a fixed iteration count, no randomness anywhere, and the
35
+ * same input gives the same picture on both sides and in a test.
36
+ */
37
+ export type JunMaturity = 'seedling' | 'budding' | 'evergreen';
38
+ /**
39
+ * The three states, in growing order — the ONE copy. The leaf page's `select`
40
+ * control, the garden's badges and its filter all read this list, and a fourth
41
+ * state added in two of the three places is how a note becomes unfilterable.
42
+ */
43
+ export declare const JUN_MATURITIES: readonly [{
44
+ readonly value: "seedling";
45
+ readonly label: "Seedling";
46
+ readonly icon: "i-lucide-sprout";
47
+ readonly hint: "Rough, and says so";
48
+ }, {
49
+ readonly value: "budding";
50
+ readonly label: "Budding";
51
+ readonly icon: "i-lucide-flower-2";
52
+ readonly hint: "Taking shape";
53
+ }, {
54
+ readonly value: "evergreen";
55
+ readonly label: "Evergreen";
56
+ readonly icon: "i-lucide-trees";
57
+ readonly hint: "Tended, and holds up";
58
+ }];
59
+ /**
60
+ * A note's stated maturity, or `null` when its author never stated one.
61
+ *
62
+ * An unknown value — written by a newer build with a fourth state — reads as
63
+ * unstated rather than rendering a badge with no label, the same rule every view
64
+ * option here follows.
65
+ */
66
+ export declare function junMaturityOf(meta: Record<string, unknown> | undefined | null): JunMaturity | null;
67
+ /**
68
+ * Every link target in a rendered body, in document order, duplicates included.
69
+ *
70
+ * Both shapes: an `<a href>` (which is what a `[[doc]]` reference and an ordinary
71
+ * internal link both become) and a `data-doc-id` attribute (which is what an
72
+ * embed node renders as). Duplicates are kept — how MANY times one note points at
73
+ * another is a real quantity, and de-duplication is the edge builder's job.
74
+ */
75
+ export declare function junScanLinkTargets(html: string | null | undefined): string[];
76
+ /**
77
+ * Resolve one link target to a document id in THIS site, or `null`.
78
+ *
79
+ * `null` covers four separate cases on purpose, because all four mean "not an
80
+ * edge": an external URL, an in-page anchor, a `/doc/<id>` for a document this
81
+ * site does not have, and a path that resolves to nothing. A graph that guessed
82
+ * on any of them would draw a node for a page that does not exist.
83
+ */
84
+ export declare function junResolveLinkTarget(target: string, slugToId: Record<string, string>, knownIds: ReadonlySet<string>): string | null;
85
+ export interface JunGardenEdge {
86
+ source: string;
87
+ target: string;
88
+ /** How many links point that way. A note cited three times is not cited once. */
89
+ weight: number;
90
+ }
91
+ export interface JunGardenSource {
92
+ id: string;
93
+ /** The rendered body, as the doc cache holds it. */
94
+ html?: string | null;
95
+ /** Already-scanned targets, for a caller that has them (the live client). */
96
+ targets?: string[];
97
+ }
98
+ /**
99
+ * Every edge in the site, deduplicated and weighted.
100
+ *
101
+ * A self-link is dropped: a note that mentions its own path is not connected to
102
+ * itself, and drawing that would put a loop on the busiest node on every site
103
+ * with a "back to the top" link.
104
+ */
105
+ export declare function junGardenEdges(sources: JunGardenSource[], slugToId: Record<string, string>, knownIds: ReadonlySet<string>): JunGardenEdge[];
106
+ export interface JunGardenEntryInput {
107
+ id: string;
108
+ label?: string;
109
+ href?: string;
110
+ type?: string;
111
+ updatedAt?: number;
112
+ createdAt?: number;
113
+ meta?: Record<string, unknown> | null;
114
+ }
115
+ export interface JunGardenRef {
116
+ id: string;
117
+ label: string;
118
+ href?: string;
119
+ weight: number;
120
+ }
121
+ export interface JunGardenNote {
122
+ id: string;
123
+ label: string;
124
+ href?: string;
125
+ type?: string;
126
+ maturity: JunMaturity | null;
127
+ updatedAt: number;
128
+ /** What points HERE — the thing a garden owner opens the page for. */
129
+ inbound: JunGardenRef[];
130
+ /** What this note points at. */
131
+ outbound: JunGardenRef[];
132
+ /** Both directions, which is what the graph draws a node's size from. */
133
+ degree: number;
134
+ }
135
+ /**
136
+ * Shape the graph into notes.
137
+ *
138
+ * `scope` is which documents the garden OWNS — its own notes. Inbound links are
139
+ * resolved against every entry in the site, because a note being cited from
140
+ * outside the garden is still a citation, and a garden that only counted its own
141
+ * children would call a widely-linked note an orphan.
142
+ */
143
+ export declare function junGardenNotes(entries: JunGardenEntryInput[], edges: JunGardenEdge[], scope: ReadonlySet<string>): JunGardenNote[];
144
+ /**
145
+ * The notes nothing points at.
146
+ *
147
+ * Outbound links do not save a note from this list — a page that links out and is
148
+ * never linked to is exactly the page an owner has lost track of, which is the
149
+ * one question a garden exists to answer.
150
+ */
151
+ export declare function junGardenOrphans(notes: JunGardenNote[]): JunGardenNote[];
152
+ export type JunGardenSort = 'links' | 'recent' | 'alpha';
153
+ /** Order the notes. Ties break on the label, so the list never shuffles. */
154
+ export declare function junGardenSort(notes: JunGardenNote[], key: JunGardenSort): JunGardenNote[];
155
+ /** The one-line summary above the graph. */
156
+ export declare function junGardenCounts(notes: JunGardenNote[]): {
157
+ notes: number;
158
+ links: number;
159
+ orphans: number;
160
+ evergreen: number;
161
+ };
162
+ export interface JunGardenPoint {
163
+ id: string;
164
+ x: number;
165
+ y: number;
166
+ }
167
+ export interface JunGardenLayoutOptions {
168
+ width?: number;
169
+ height?: number;
170
+ /** Ideal edge length, as a multiple of the natural spacing. */
171
+ spread?: number;
172
+ /** Fixed, and part of the contract: the count is what makes this repeatable. */
173
+ iterations?: number;
174
+ padding?: number;
175
+ }
176
+ /**
177
+ * A force-directed layout, hand-rolled and deterministic.
178
+ *
179
+ * Fruchterman-Reingold: every pair of nodes repels, every edge attracts, and a
180
+ * cooling schedule stops the whole thing oscillating. ~60 lines, which is why
181
+ * this is written here rather than taken as a dependency — `d3-force` is a
182
+ * playground dependency and must stay one, the same way this repo writes its own
183
+ * rasteriser and its own TOML reader.
184
+ *
185
+ * **Nothing random.** Starting positions come off a golden-angle spiral (an even
186
+ * spread with no clumps to unstick) and the iteration count is fixed, so the
187
+ * server and the client draw the same picture and a test can assert positions.
188
+ *
189
+ * Coincident nodes are nudged apart by a value derived from their INDEX rather
190
+ * than a random jitter: two nodes at the same point produce a zero-length vector,
191
+ * and dividing by it is how a layout fills with `NaN` and paints nothing.
192
+ */
193
+ export declare function junGardenLayout(ids: string[], edges: JunGardenEdge[], options?: JunGardenLayoutOptions): JunGardenPoint[];
@@ -0,0 +1,233 @@
1
+ export const JUN_MATURITIES = [
2
+ { value: "seedling", label: "Seedling", icon: "i-lucide-sprout", hint: "Rough, and says so" },
3
+ { value: "budding", label: "Budding", icon: "i-lucide-flower-2", hint: "Taking shape" },
4
+ { value: "evergreen", label: "Evergreen", icon: "i-lucide-trees", hint: "Tended, and holds up" }
5
+ ];
6
+ const MATURITY_VALUES = JUN_MATURITIES.map((m) => m.value);
7
+ export function junMaturityOf(meta) {
8
+ const raw = meta?.maturity;
9
+ return typeof raw === "string" && MATURITY_VALUES.includes(raw) ? raw : null;
10
+ }
11
+ const HREF_RE = /<a\s[^>]*?href\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
12
+ const DOC_ID_ATTR_RE = /\bdata-doc-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
13
+ const DOC_PATH_RE = /^\/doc\/([\w-]+)/;
14
+ function unescapeAttr(value) {
15
+ return value.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)));
16
+ }
17
+ export function junScanLinkTargets(html) {
18
+ if (!html) return [];
19
+ const out = [];
20
+ for (const re of [HREF_RE, DOC_ID_ATTR_RE]) {
21
+ re.lastIndex = 0;
22
+ let m;
23
+ while (m = re.exec(html)) {
24
+ const raw = m[1] ?? m[2] ?? m[3] ?? "";
25
+ if (raw) out.push(unescapeAttr(raw).trim());
26
+ }
27
+ }
28
+ return out;
29
+ }
30
+ export function junResolveLinkTarget(target, slugToId, knownIds) {
31
+ const raw = (target ?? "").trim();
32
+ if (!raw) return null;
33
+ if (knownIds.has(raw)) return raw;
34
+ if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("//")) return null;
35
+ if (raw.startsWith("#")) return null;
36
+ const path = raw.replace(/[?#].*$/, "");
37
+ const doc = DOC_PATH_RE.exec(path);
38
+ if (doc) return knownIds.has(doc[1]) ? doc[1] : null;
39
+ let slug = path;
40
+ try {
41
+ slug = decodeURIComponent(path);
42
+ } catch {
43
+ }
44
+ slug = slug.replace(/^\/+/, "").replace(/\/+$/, "").toLowerCase();
45
+ const id = slugToId[slug];
46
+ return id && knownIds.has(id) ? id : null;
47
+ }
48
+ export function junGardenEdges(sources, slugToId, knownIds) {
49
+ const edges = [];
50
+ const seen = /* @__PURE__ */ new Map();
51
+ for (const source of sources) {
52
+ if (!source?.id || !knownIds.has(source.id)) continue;
53
+ const targets = source.targets ?? junScanLinkTargets(source.html);
54
+ for (const target of targets) {
55
+ const id = junResolveLinkTarget(target, slugToId, knownIds);
56
+ if (!id || id === source.id) continue;
57
+ const key = `${source.id}\0${id}`;
58
+ const existing = seen.get(key);
59
+ if (existing) {
60
+ existing.weight++;
61
+ continue;
62
+ }
63
+ const edge = { source: source.id, target: id, weight: 1 };
64
+ seen.set(key, edge);
65
+ edges.push(edge);
66
+ }
67
+ }
68
+ return edges;
69
+ }
70
+ export function junGardenNotes(entries, edges, scope) {
71
+ const byId = /* @__PURE__ */ new Map();
72
+ for (const entry of entries) if (entry?.id) byId.set(entry.id, entry);
73
+ const refOf = (id, weight) => {
74
+ const entry = byId.get(id);
75
+ return {
76
+ id,
77
+ label: (entry?.label ?? "").trim() || "Untitled",
78
+ href: entry?.href,
79
+ weight
80
+ };
81
+ };
82
+ const notes = /* @__PURE__ */ new Map();
83
+ for (const id of scope) {
84
+ const entry = byId.get(id);
85
+ if (!entry) continue;
86
+ notes.set(id, {
87
+ id,
88
+ label: (entry.label ?? "").trim() || "Untitled",
89
+ href: entry.href,
90
+ type: entry.type,
91
+ maturity: junMaturityOf(entry.meta),
92
+ updatedAt: entry.updatedAt ?? entry.createdAt ?? 0,
93
+ inbound: [],
94
+ outbound: [],
95
+ degree: 0
96
+ });
97
+ }
98
+ for (const edge of edges) {
99
+ const from = notes.get(edge.source);
100
+ const to = notes.get(edge.target);
101
+ if (from && byId.has(edge.target)) from.outbound.push(refOf(edge.target, edge.weight));
102
+ if (to && byId.has(edge.source)) to.inbound.push(refOf(edge.source, edge.weight));
103
+ }
104
+ for (const note of notes.values()) {
105
+ note.inbound.sort((a, b) => b.weight - a.weight || a.label.localeCompare(b.label));
106
+ note.outbound.sort((a, b) => b.weight - a.weight || a.label.localeCompare(b.label));
107
+ note.degree = note.inbound.length + note.outbound.length;
108
+ }
109
+ return [...notes.values()];
110
+ }
111
+ export function junGardenOrphans(notes) {
112
+ return notes.filter((n) => n.inbound.length === 0);
113
+ }
114
+ export function junGardenSort(notes, key) {
115
+ const byLabel = (a, b) => a.label.localeCompare(b.label);
116
+ const list = [...notes];
117
+ if (key === "alpha") return list.sort(byLabel);
118
+ if (key === "recent") return list.sort((a, b) => b.updatedAt - a.updatedAt || byLabel(a, b));
119
+ return list.sort((a, b) => b.inbound.length - a.inbound.length || b.degree - a.degree || byLabel(a, b));
120
+ }
121
+ export function junGardenCounts(notes) {
122
+ let links = 0;
123
+ let orphans = 0;
124
+ let evergreen = 0;
125
+ for (const note of notes) {
126
+ links += note.outbound.length;
127
+ if (note.inbound.length === 0) orphans++;
128
+ if (note.maturity === "evergreen") evergreen++;
129
+ }
130
+ return { notes: notes.length, links, orphans, evergreen };
131
+ }
132
+ const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
133
+ const GRAVITY = 0.035;
134
+ export function junGardenLayout(ids, edges, options = {}) {
135
+ const width = options.width ?? 1e3;
136
+ const height = options.height ?? 640;
137
+ const padding = options.padding ?? 28;
138
+ const iterations = options.iterations ?? 240;
139
+ const spread = options.spread ?? 1;
140
+ const n = ids.length;
141
+ if (n === 0) return [];
142
+ if (n === 1) return [{ id: ids[0], x: width / 2, y: height / 2 }];
143
+ const index = /* @__PURE__ */ new Map();
144
+ ids.forEach((id, i) => index.set(id, i));
145
+ const xs = new Float64Array(n);
146
+ const ys = new Float64Array(n);
147
+ for (let i = 0; i < n; i++) {
148
+ const r = 0.5 * Math.sqrt((i + 0.5) / n);
149
+ const a = i * GOLDEN_ANGLE;
150
+ xs[i] = 0.5 + r * Math.cos(a);
151
+ ys[i] = 0.5 + r * Math.sin(a);
152
+ }
153
+ const links = [];
154
+ for (const edge of edges) {
155
+ const a = index.get(edge.source);
156
+ const b = index.get(edge.target);
157
+ if (a === void 0 || b === void 0 || a === b) continue;
158
+ links.push([a, b, Math.min(edge.weight || 1, 4)]);
159
+ }
160
+ const k = spread * Math.sqrt(1 / n);
161
+ const dx = new Float64Array(n);
162
+ const dy = new Float64Array(n);
163
+ for (let step = 0; step < iterations; step++) {
164
+ const temp = 0.1 * (1 - step / iterations);
165
+ dx.fill(0);
166
+ dy.fill(0);
167
+ for (let i = 0; i < n; i++) {
168
+ for (let j = i + 1; j < n; j++) {
169
+ let vx = xs[i] - xs[j];
170
+ let vy = ys[i] - ys[j];
171
+ let dist = Math.sqrt(vx * vx + vy * vy);
172
+ if (dist < 1e-9) {
173
+ vx = ((i * 7 + j * 3) % 11 - 5) * 1e-4 || 1e-4;
174
+ vy = ((i * 5 + j * 9) % 13 - 6) * 1e-4 || 1e-4;
175
+ dist = Math.sqrt(vx * vx + vy * vy);
176
+ }
177
+ const force = k * k / dist;
178
+ const fx = vx / dist * force;
179
+ const fy = vy / dist * force;
180
+ dx[i] += fx;
181
+ dy[i] += fy;
182
+ dx[j] -= fx;
183
+ dy[j] -= fy;
184
+ }
185
+ }
186
+ for (const [a, b, weight] of links) {
187
+ const vx = xs[a] - xs[b];
188
+ const vy = ys[a] - ys[b];
189
+ const dist = Math.max(Math.sqrt(vx * vx + vy * vy), 1e-9);
190
+ const force = dist * dist / k * weight;
191
+ const fx = vx / dist * force;
192
+ const fy = vy / dist * force;
193
+ dx[a] -= fx;
194
+ dy[a] -= fy;
195
+ dx[b] += fx;
196
+ dy[b] += fy;
197
+ }
198
+ for (let i = 0; i < n; i++) {
199
+ dx[i] += (0.5 - xs[i]) * GRAVITY;
200
+ dy[i] += (0.5 - ys[i]) * GRAVITY;
201
+ const len = Math.sqrt(dx[i] * dx[i] + dy[i] * dy[i]);
202
+ if (len > 1e-12) {
203
+ const move = Math.min(len, temp);
204
+ xs[i] += dx[i] / len * move;
205
+ ys[i] += dy[i] / len * move;
206
+ }
207
+ xs[i] = Math.min(1.2, Math.max(-0.2, xs[i]));
208
+ ys[i] = Math.min(1.2, Math.max(-0.2, ys[i]));
209
+ }
210
+ }
211
+ let minX = Infinity;
212
+ let maxX = -Infinity;
213
+ let minY = Infinity;
214
+ let maxY = -Infinity;
215
+ for (let i = 0; i < n; i++) {
216
+ minX = Math.min(minX, xs[i]);
217
+ maxX = Math.max(maxX, xs[i]);
218
+ minY = Math.min(minY, ys[i]);
219
+ maxY = Math.max(maxY, ys[i]);
220
+ }
221
+ const spanX = Math.max(maxX - minX, 1e-6);
222
+ const spanY = Math.max(maxY - minY, 1e-6);
223
+ const boxW = Math.max(width - padding * 2, 1);
224
+ const boxH = Math.max(height - padding * 2, 1);
225
+ return ids.map((id, i) => ({
226
+ id,
227
+ x: round(padding + (xs[i] - minX) / spanX * boxW),
228
+ y: round(padding + (ys[i] - minY) / spanY * boxH)
229
+ }));
230
+ }
231
+ function round(value) {
232
+ return Math.round(value * 100) / 100;
233
+ }
@@ -43,10 +43,17 @@ const SCHEMAS = {
43
43
  { type: "icon", key: "icon", label: "Icon" },
44
44
  { type: "text", key: "description", label: "Description" }
45
45
  ],
46
+ // `rating` and `description` are declared even though the SHELF edits both
47
+ // (stars on the row, a chip beside them). This schema is what a book's OWN
48
+ // page offers, and a field a page type stores but cannot be given from the
49
+ // document holding it is a field that only exists where somebody happens to
50
+ // be standing.
46
51
  library: [
47
52
  { type: "select", key: "status", options: [...JUN_LIBRARY_STATUSES], label: "Status" },
48
53
  { type: "text", key: "author", label: "Author" },
49
- { type: "url", key: "url", label: "URL" }
54
+ { type: "rating", key: "rating", label: "Rating" },
55
+ { type: "url", key: "url", label: "URL" },
56
+ { type: "text", key: "description", label: "Description" }
50
57
  ],
51
58
  apps: [
52
59
  { type: "select", key: "status", options: [...JUN_APP_STATUSES], label: "Status" },
@@ -0,0 +1,67 @@
1
+ /**
2
+ * What an owner can do to something a visitor wrote — the two meta keys, once.
3
+ *
4
+ * No Vue, no `#imports`, **no imports at all**: three surfaces read these keys
5
+ * (the conversation, the guestbook, and the server when it refuses to post into a
6
+ * closed thread), and a second spelling of "removed" would mean a post hidden on
7
+ * one page and visible on another.
8
+ *
9
+ * ── Removing is not deleting ─────────────────────────────────────────────────
10
+ *
11
+ * `meta.moderated` takes something out of the conversation and KEEPS the
12
+ * document: the owner still sees it, greyed, and can put it back. Destroying
13
+ * somebody's words is the trash — deliberately a second, separate act, with its
14
+ * own undo.
15
+ *
16
+ * ── Pinning is an owner saying "read this one" ────────────────────────────────
17
+ *
18
+ * So it wins over every ordering. An order that could bury a pinned item makes
19
+ * the act meaningless, which is why this is a sort rather than a flag the
20
+ * renderers each apply in their own way.
21
+ */
22
+ export interface JunModeratable {
23
+ meta?: Record<string, unknown> | null;
24
+ }
25
+ /** Removed by the owner: out of the list, still a document. */
26
+ export declare function junIsModerated(meta: Record<string, unknown> | null | undefined): boolean;
27
+ /** Held at the top by the owner. */
28
+ export declare function junIsPinned(meta: Record<string, unknown> | null | undefined): boolean;
29
+ /**
30
+ * Does this document count as something a visitor said?
31
+ *
32
+ * The predicate behind the Pulse page's *Signatures*, and it lives here because
33
+ * **two separate computations use it** — `stats.get` in Nitro and the live
34
+ * recompute in `JunStatsRenderer` — and the two must never disagree about the same
35
+ * number. That is not hypothetical: for one release the pair counted removed
36
+ * signatures, because the count predates moderation and neither half had heard of
37
+ * `meta.moderated`.
38
+ *
39
+ * A removed signature does NOT count. The Pulse page is public, the number is what
40
+ * a visitor is told the site holds, and telling them about a line the owner took
41
+ * down is the one reading that is definitely wrong. The document still exists — the
42
+ * owner can still see it and restore it.
43
+ */
44
+ export declare function junIsVisibleMessage(meta: Record<string, unknown> | null | undefined): boolean;
45
+ /**
46
+ * A visitor-written list, moderated: hidden entries dropped, pinned ones first.
47
+ *
48
+ * `includeHidden` is the OWNER's view — they must be able to see what they have
49
+ * removed, or "restore" is a button for something invisible. It is never derived
50
+ * from anything but edit mode: a reader must not be able to ask for the hidden
51
+ * ones.
52
+ *
53
+ * The incoming order is otherwise preserved exactly. Deciding the sort here would
54
+ * mean this function owned two decisions, and every caller already has its own
55
+ * (newest first, oldest first, by weight).
56
+ */
57
+ export declare function junModerateList<T extends JunModeratable>(list: T[], options?: {
58
+ includeHidden?: boolean;
59
+ }): T[];
60
+ /**
61
+ * The next value for a toggled flag.
62
+ *
63
+ * `undefined` rather than `false`, because that is what CLEARS the key — the same
64
+ * rule every setting in this module follows, and the reason a restored post is
65
+ * indistinguishable from one that was never removed.
66
+ */
67
+ export declare function junToggleFlag(current: boolean): true | undefined;