@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.
- package/dist/module.d.mts +17 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +253 -21
- package/dist/runtime/assets/css/jun.css +1 -1
- package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
- package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
- package/dist/runtime/components/JunCollectionIntro.vue +45 -0
- package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
- package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
- package/dist/runtime/components/JunConfigRow.vue +34 -0
- package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
- package/dist/runtime/components/JunDocSurface.vue +3 -0
- package/dist/runtime/components/JunFooter.vue +1 -1
- package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
- package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
- package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
- package/dist/runtime/components/JunLinksRow.vue +17 -7
- package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
- package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunNavigation.vue +21 -4
- package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
- package/dist/runtime/components/JunNoteLinks.vue +57 -0
- package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
- package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
- package/dist/runtime/components/JunPageHero.vue +15 -3
- package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
- package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
- package/dist/runtime/components/JunReaders.vue +99 -0
- package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
- package/dist/runtime/components/JunSearch.client.vue +2 -2
- package/dist/runtime/components/JunSectionPresence.d.vue.ts +17 -0
- package/dist/runtime/components/JunSectionPresence.vue +99 -0
- package/dist/runtime/components/JunSectionPresence.vue.d.ts +17 -0
- package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
- package/dist/runtime/components/JunThreadComposer.vue +54 -0
- package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
- package/dist/runtime/components/JunTravellersChip.vue +35 -5
- package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
- package/dist/runtime/components/JunViewControl.vue +340 -0
- package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
- package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
- package/dist/runtime/components/JunViewControls.vue +94 -0
- package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
- package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
- package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
- package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
- package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
- package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
- package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunGlobeRenderer.vue +43 -26
- package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
- package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
- package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
- package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
- package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
- package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
- package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
- package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
- package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
- package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
- package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
- package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
- package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
- package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
- package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
- package/dist/runtime/composables/useJunDeck.d.ts +66 -0
- package/dist/runtime/composables/useJunDeck.js +61 -0
- package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
- package/dist/runtime/composables/useJunDocPage.js +67 -3
- package/dist/runtime/composables/useJunFollow.d.ts +65 -9
- package/dist/runtime/composables/useJunFollow.js +237 -20
- package/dist/runtime/composables/useJunGarden.d.ts +67 -0
- package/dist/runtime/composables/useJunGarden.js +92 -0
- package/dist/runtime/composables/useJunPresence.d.ts +26 -0
- package/dist/runtime/composables/useJunPresence.js +9 -2
- package/dist/runtime/composables/useJunSections.d.ts +73 -0
- package/dist/runtime/composables/useJunSections.js +117 -0
- package/dist/runtime/composables/useJunSettings.d.ts +1 -1
- package/dist/runtime/composables/useJunSettings.js +5 -1
- package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
- package/dist/runtime/composables/useJunTheme.js +40 -2
- package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
- package/dist/runtime/composables/useJunViewOptions.js +63 -0
- package/dist/runtime/pages/doc.vue +52 -42
- package/dist/runtime/pages/index.vue +61 -35
- package/dist/runtime/plugins/jun-doc-tree.d.ts +2 -0
- package/dist/runtime/plugins/jun-doc-tree.js +26 -0
- package/dist/runtime/server/api/health.get.d.ts +19 -0
- package/dist/runtime/server/api/health.get.js +40 -0
- package/dist/runtime/server/api/links.get.d.ts +19 -0
- package/dist/runtime/server/api/links.get.js +37 -0
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
- package/dist/runtime/server/api/resolve/[...slug].get.js +7 -2
- package/dist/runtime/server/api/stats.get.js +2 -1
- package/dist/runtime/server/api/tree.get.d.ts +9 -0
- package/dist/runtime/server/api/tree.get.js +23 -0
- package/dist/runtime/server/janitor/junJanitorActor.d.ts +13 -0
- package/dist/runtime/server/janitor/junJanitorActor.js +36 -5
- package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
- package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
- package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
- package/dist/runtime/server/plugins/jun-janitor.js +7 -0
- package/dist/runtime/server/plugins/jun-rpc.js +293 -0
- package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
- package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
- package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
- package/dist/runtime/server/utils/junBoot.d.ts +1 -0
- package/dist/runtime/server/utils/junBoot.js +4 -0
- package/dist/runtime/server/utils/junCache.d.ts +17 -0
- package/dist/runtime/server/utils/junCache.js +5 -0
- package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
- package/dist/runtime/server/utils/junSeedGate.js +41 -0
- package/dist/runtime/types.d.ts +57 -1
- package/dist/runtime/utils/junCourse.d.ts +106 -0
- package/dist/runtime/utils/junCourse.js +65 -0
- package/dist/runtime/utils/junGarden.d.ts +193 -0
- package/dist/runtime/utils/junGarden.js +233 -0
- package/dist/runtime/utils/junMetaSchemas.js +8 -1
- package/dist/runtime/utils/junModeration.d.ts +67 -0
- package/dist/runtime/utils/junModeration.js +20 -0
- package/dist/runtime/utils/junMotion.d.ts +26 -0
- package/dist/runtime/utils/junMotion.js +31 -0
- package/dist/runtime/utils/junPeople.d.ts +43 -0
- package/dist/runtime/utils/junPeople.js +9 -0
- package/dist/runtime/utils/junPoll.d.ts +79 -0
- package/dist/runtime/utils/junPoll.js +82 -0
- package/dist/runtime/utils/junReadiness.d.ts +131 -0
- package/dist/runtime/utils/junReadiness.js +69 -0
- package/dist/runtime/utils/junSections.d.ts +115 -0
- package/dist/runtime/utils/junSections.js +45 -0
- package/dist/runtime/utils/junSlides.d.ts +66 -0
- package/dist/runtime/utils/junSlides.js +47 -0
- package/dist/runtime/utils/junThread.d.ts +81 -0
- package/dist/runtime/utils/junThread.js +75 -0
- package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
- package/dist/runtime/utils/junViewSpecs.js +534 -0
- package/dist/runtime/utils/junViewValues.d.ts +125 -0
- package/dist/runtime/utils/junViewValues.js +104 -0
- package/dist/types.d.mts +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function junIsModerated(meta) {
|
|
2
|
+
return meta?.moderated === true;
|
|
3
|
+
}
|
|
4
|
+
export function junIsPinned(meta) {
|
|
5
|
+
return meta?.pinned === true;
|
|
6
|
+
}
|
|
7
|
+
export function junIsVisibleMessage(meta) {
|
|
8
|
+
const message = meta?.message;
|
|
9
|
+
return typeof message === "string" && !!message.trim() && !junIsModerated(meta);
|
|
10
|
+
}
|
|
11
|
+
export function junModerateList(list, options = {}) {
|
|
12
|
+
const visible = options.includeHidden ? [...list] : list.filter((entry) => !junIsModerated(entry?.meta));
|
|
13
|
+
const pinned = [];
|
|
14
|
+
const rest = [];
|
|
15
|
+
for (const entry of visible) (junIsPinned(entry?.meta) ? pinned : rest).push(entry);
|
|
16
|
+
return [...pinned, ...rest];
|
|
17
|
+
}
|
|
18
|
+
export function junToggleFlag(current) {
|
|
19
|
+
return current ? void 0 : true;
|
|
20
|
+
}
|
|
@@ -55,10 +55,36 @@ export interface JunMotionVariants {
|
|
|
55
55
|
tapped?: JunMotionState;
|
|
56
56
|
focused?: JunMotionState;
|
|
57
57
|
}
|
|
58
|
+
/** How much movement the page is allowed. */
|
|
59
|
+
export type JunMotionLevel = 'full' | 'reduced' | 'none';
|
|
60
|
+
export declare const JUN_MOTION_LEVELS: JunMotionLevel[];
|
|
61
|
+
/** Set from the site config (`useJunThemeApply`). */
|
|
62
|
+
export declare function junSetMotionLevel(level: JunMotionLevel | string | undefined): void;
|
|
63
|
+
/** Set from `prefers-reduced-motion` on the client. */
|
|
64
|
+
export declare function junSetMotionFloor(reduced: boolean): void;
|
|
65
|
+
/** What actually applies: the stricter of the two. */
|
|
66
|
+
export declare function junMotionLevel(): JunMotionLevel;
|
|
67
|
+
/**
|
|
68
|
+
* The variants with every MOVEMENT removed — opacity only, and quickly.
|
|
69
|
+
*
|
|
70
|
+
* "Reduced" is not "none": something appearing still has to announce that it
|
|
71
|
+
* appeared, and a fade does that without moving anything. This is the same
|
|
72
|
+
* distinction `jun.css` draws in its `prefers-reduced-motion` blocks, which take
|
|
73
|
+
* the transform and keep the fade.
|
|
74
|
+
*/
|
|
75
|
+
export declare function junReduceVariants(variants: JunMotionVariants): JunMotionVariants;
|
|
58
76
|
/**
|
|
59
77
|
* Pass motion variants to `v-motion` with the OBJECT type-checked and the
|
|
60
78
|
* directive value left unchecked.
|
|
61
79
|
*
|
|
80
|
+
* ── It now honours the motion level, and it never did ────────────────────────
|
|
81
|
+
*
|
|
82
|
+
* `v-motion` animates in JAVASCRIPT. Every `prefers-reduced-motion` block in
|
|
83
|
+
* `jun.css` is therefore invisible to it: a visitor who asked their system for
|
|
84
|
+
* less motion still got every card sliding up, every list staggering in and every
|
|
85
|
+
* hero rising on every page, because nothing in the JS path had ever read the
|
|
86
|
+
* preference. This function is the only place all ~20 call sites pass through.
|
|
87
|
+
*
|
|
62
88
|
* The return type is `any`, not `unknown`, and that is forced: the directive
|
|
63
89
|
* resolves to a declared `Options<any>` whose shape does not match what
|
|
64
90
|
* `v-motion` actually accepts, and `unknown` is not assignable to it
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
export const JUN_MOTION_LEVELS = ["full", "reduced", "none"];
|
|
2
|
+
let siteLevel = "full";
|
|
3
|
+
let visitorReduced = false;
|
|
4
|
+
export function junSetMotionLevel(level) {
|
|
5
|
+
siteLevel = JUN_MOTION_LEVELS.includes(level) ? level : "full";
|
|
6
|
+
}
|
|
7
|
+
export function junSetMotionFloor(reduced) {
|
|
8
|
+
visitorReduced = reduced;
|
|
9
|
+
}
|
|
10
|
+
export function junMotionLevel() {
|
|
11
|
+
if (siteLevel === "none") return "none";
|
|
12
|
+
return visitorReduced ? "reduced" : siteLevel;
|
|
13
|
+
}
|
|
14
|
+
export function junReduceVariants(variants) {
|
|
15
|
+
const fade = (state) => {
|
|
16
|
+
if (!state) return void 0;
|
|
17
|
+
const out2 = {};
|
|
18
|
+
if (state.opacity !== void 0) out2.opacity = state.opacity;
|
|
19
|
+
out2.transition = { duration: Math.min(state.transition?.duration ?? 200, 200) };
|
|
20
|
+
return out2;
|
|
21
|
+
};
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const key of Object.keys(variants)) {
|
|
24
|
+
const reduced = fade(variants[key]);
|
|
25
|
+
if (reduced) out[key] = reduced;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
1
29
|
export function junMotion(variants) {
|
|
30
|
+
const level = junMotionLevel();
|
|
31
|
+
if (level === "none") return {};
|
|
32
|
+
if (level === "reduced") return junReduceVariants(variants);
|
|
2
33
|
return variants;
|
|
3
34
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One rule, in one place: **a person is not a session.**
|
|
3
|
+
*
|
|
4
|
+
* Awareness is per tab. Anything the site COUNTS or LISTS has to collapse a
|
|
5
|
+
* peer's sessions down to the person behind them, and last round found five
|
|
6
|
+
* separate consumers each deciding that for itself — three of them wrongly, so
|
|
7
|
+
* one visitor with a second window read as two travellers in the navbar, in
|
|
8
|
+
* `byDocId` and in the travellers chip.
|
|
9
|
+
*
|
|
10
|
+
* It lived in `useJunPresence.ts` after that, which fixed the duplication but
|
|
11
|
+
* left the rule untestable: that file imports `vue` and `#imports`, so it cannot
|
|
12
|
+
* be loaded outside a Nuxt app. Here it has no imports at all, and
|
|
13
|
+
* `test/sections.test.mts` pins it — including the two tie-breaks that are easy
|
|
14
|
+
* to get subtly wrong and impossible to see on a page.
|
|
15
|
+
*
|
|
16
|
+
* Structural, not typed to `JunTraveller`: section presence deduplicates peer
|
|
17
|
+
* MARKS, which carry a different payload and the same identity.
|
|
18
|
+
*/
|
|
19
|
+
export interface JunPersonLike {
|
|
20
|
+
/** The session. Unique per tab, and never stable across a reload. */
|
|
21
|
+
clientId: number;
|
|
22
|
+
/** The person. Null only for a peer whose awareness state carries no key. */
|
|
23
|
+
publicKey?: string | null;
|
|
24
|
+
/** A background tab. */
|
|
25
|
+
idle?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One entry per person, from a list with one entry per session.
|
|
29
|
+
*
|
|
30
|
+
* Two tie-breaks, both deliberate:
|
|
31
|
+
*
|
|
32
|
+
* - **The awake session speaks for the person.** An idle background tab must
|
|
33
|
+
* not report where its owner is, and somebody present in both an idle and an
|
|
34
|
+
* active tab should read as present.
|
|
35
|
+
* - **A peer with no public key falls back to its session** rather than being
|
|
36
|
+
* dropped. That is the same tolerance rule the renderers apply to foreign
|
|
37
|
+
* children: an unrecognised shape is still somebody, and silently deleting
|
|
38
|
+
* people from a presence list is the worse failure.
|
|
39
|
+
*
|
|
40
|
+
* Order is preserved — first-seen wins position, so a list that was sorted stays
|
|
41
|
+
* sorted.
|
|
42
|
+
*/
|
|
43
|
+
export declare function junDedupePeople<T extends JunPersonLike>(list: T[]): T[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function junDedupePeople(list) {
|
|
2
|
+
const byPerson = /* @__PURE__ */ new Map();
|
|
3
|
+
for (const entry of list) {
|
|
4
|
+
const key = entry.publicKey ?? `session:${entry.clientId}`;
|
|
5
|
+
const held = byPerson.get(key);
|
|
6
|
+
if (!held || held.idle && !entry.idle) byPerson.set(key, entry);
|
|
7
|
+
}
|
|
8
|
+
return [...byPerson.values()];
|
|
9
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic behind `jun-poll` — counting votes without lying about them.
|
|
3
|
+
*
|
|
4
|
+
* No Vue, no `#imports`, **no imports at all**: the server's RPC handler and the
|
|
5
|
+
* renderer both need this, and neither may hold its own copy of the counting
|
|
6
|
+
* rules. That is not a style preference — the SERVER decides what a vote is worth
|
|
7
|
+
* and the CLIENT draws the bars, and if they disagree the page shows a total
|
|
8
|
+
* nobody cast.
|
|
9
|
+
*
|
|
10
|
+
* ── One vote per PERSON ──────────────────────────────────────────────────────
|
|
11
|
+
*
|
|
12
|
+
* Votes are stored as `meta.pollVotes: { [signerId]: number[] }` — keyed by the
|
|
13
|
+
* voter's server-stamped identity, so a second tab, a reload and a reconnect are
|
|
14
|
+
* all the same vote. That is the same rule every count in this module follows,
|
|
15
|
+
* and it is the only one a poll cannot get away with breaking: a tally that counts
|
|
16
|
+
* sessions is not a tally, it is a measure of how many windows people keep open.
|
|
17
|
+
*
|
|
18
|
+
* The server stamps the key (`ctx.from`), never the client. A client-supplied
|
|
19
|
+
* voter id would make ballot-stuffing a one-line change.
|
|
20
|
+
*/
|
|
21
|
+
/** How many voters one poll may record. Beyond this the oldest are dropped. */
|
|
22
|
+
export declare const JUN_POLL_VOTERS_MAX = 5000;
|
|
23
|
+
/** How many choices a poll may offer, and how long each may be. */
|
|
24
|
+
export declare const JUN_POLL_CHOICES_MAX = 12;
|
|
25
|
+
export declare const JUN_POLL_CHOICE_LENGTH = 80;
|
|
26
|
+
export interface JunPollTally {
|
|
27
|
+
/** Per choice index, in the choices' own order. */
|
|
28
|
+
counts: number[];
|
|
29
|
+
/** Percentages that sum to exactly 100 (or all zero when nobody has voted). */
|
|
30
|
+
percentages: number[];
|
|
31
|
+
/** Distinct people who have voted. */
|
|
32
|
+
voters: number;
|
|
33
|
+
/** The highest count, for drawing bars relative to the leader. */
|
|
34
|
+
leader: number;
|
|
35
|
+
}
|
|
36
|
+
/** The choices a poll offers, cleaned. Stored as `meta.pollOptions`. */
|
|
37
|
+
export declare function junPollChoices(raw: unknown): string[];
|
|
38
|
+
/** Every ballot, keyed by voter, with anything unparseable dropped. */
|
|
39
|
+
export declare function junPollBallots(raw: unknown, choiceCount: number): Record<string, number[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Count them.
|
|
42
|
+
*
|
|
43
|
+
* Percentages are of VOTERS, not of votes cast, so a multi-choice poll reads as
|
|
44
|
+
* "62% of people picked this" rather than as a set of fractions that mean nothing
|
|
45
|
+
* on their own. They are rounded so the visible numbers sum to exactly 100 —
|
|
46
|
+
* largest-remainder, because three equal thirds displayed as 33/33/33 makes a
|
|
47
|
+
* reader who adds them up think a vote went missing.
|
|
48
|
+
*/
|
|
49
|
+
export declare function junTallyVotes(ballots: Record<string, number[]>, choiceCount: number): JunPollTally;
|
|
50
|
+
/**
|
|
51
|
+
* Round a set of shares to whole percentages that still add up.
|
|
52
|
+
*
|
|
53
|
+
* Only when the shares CAN add up: in a multi-choice poll one person may pick
|
|
54
|
+
* three things, so the sum is meaningfully over 100 and forcing it down would be
|
|
55
|
+
* a lie of a different kind. The correction is applied only when the raw total is
|
|
56
|
+
* within a point of 100.
|
|
57
|
+
*/
|
|
58
|
+
export declare function junLargestRemainder(counts: number[], total: number): number[];
|
|
59
|
+
/** What this voter picked, or an empty list. */
|
|
60
|
+
export declare function junMyBallot(ballots: Record<string, number[]>, voter: string | null): number[];
|
|
61
|
+
/**
|
|
62
|
+
* The ballot to store after somebody picks `choice`.
|
|
63
|
+
*
|
|
64
|
+
* Three behaviours in one function, because they are one decision:
|
|
65
|
+
*
|
|
66
|
+
* - single choice → replaces whatever was there;
|
|
67
|
+
* - multiple choice → toggles that one option;
|
|
68
|
+
* - no re-voting → the existing ballot stands, and the caller says so.
|
|
69
|
+
*
|
|
70
|
+
* Returns `null` when the vote must be REFUSED, which the server turns into an
|
|
71
|
+
* error rather than a silent no-op: a button that appears to work and changes
|
|
72
|
+
* nothing is worse than one that says why it will not.
|
|
73
|
+
*/
|
|
74
|
+
export declare function junNextBallot(existing: number[], choice: number, options: {
|
|
75
|
+
multiple?: boolean;
|
|
76
|
+
revote?: boolean;
|
|
77
|
+
}): number[] | null;
|
|
78
|
+
/** Keep the stored map bounded, dropping the oldest keys first. */
|
|
79
|
+
export declare function junCapBallots(ballots: Record<string, number[]>, keep?: number): Record<string, number[]>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const JUN_POLL_VOTERS_MAX = 5e3;
|
|
2
|
+
export const JUN_POLL_CHOICES_MAX = 12;
|
|
3
|
+
export const JUN_POLL_CHOICE_LENGTH = 80;
|
|
4
|
+
export function junPollChoices(raw) {
|
|
5
|
+
if (!Array.isArray(raw)) return [];
|
|
6
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const entry of raw) {
|
|
9
|
+
if (typeof entry !== "string") continue;
|
|
10
|
+
const value = entry.replace(/\s+/g, " ").trim().slice(0, JUN_POLL_CHOICE_LENGTH);
|
|
11
|
+
const key = value.toLowerCase();
|
|
12
|
+
if (!value || seen.has(key)) continue;
|
|
13
|
+
seen.add(key);
|
|
14
|
+
out.push(value);
|
|
15
|
+
if (out.length >= JUN_POLL_CHOICES_MAX) break;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
export function junPollBallots(raw, choiceCount) {
|
|
20
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const [voter, value] of Object.entries(raw)) {
|
|
23
|
+
if (!voter) continue;
|
|
24
|
+
const list = Array.isArray(value) ? value : [value];
|
|
25
|
+
const choices = [];
|
|
26
|
+
for (const pick of list) {
|
|
27
|
+
const n = typeof pick === "number" ? pick : Number(pick);
|
|
28
|
+
if (!Number.isInteger(n) || n < 0 || n >= choiceCount) continue;
|
|
29
|
+
if (!choices.includes(n)) choices.push(n);
|
|
30
|
+
}
|
|
31
|
+
if (choices.length) out[voter] = choices;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export function junTallyVotes(ballots, choiceCount) {
|
|
36
|
+
const counts = Array.from({ length: Math.max(0, choiceCount) }, () => 0);
|
|
37
|
+
let voters = 0;
|
|
38
|
+
for (const choices of Object.values(ballots)) {
|
|
39
|
+
if (!choices.length) continue;
|
|
40
|
+
voters++;
|
|
41
|
+
for (const choice of choices) {
|
|
42
|
+
if (choice >= 0 && choice < counts.length) counts[choice] = (counts[choice] ?? 0) + 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const percentages = junLargestRemainder(counts, voters);
|
|
46
|
+
return { counts, percentages, voters, leader: counts.reduce((a, b) => Math.max(a, b), 0) };
|
|
47
|
+
}
|
|
48
|
+
export function junLargestRemainder(counts, total) {
|
|
49
|
+
if (!total) return counts.map(() => 0);
|
|
50
|
+
const exact = counts.map((c) => c / total * 100);
|
|
51
|
+
const floors = exact.map(Math.floor);
|
|
52
|
+
const sum = floors.reduce((a, b) => a + b, 0);
|
|
53
|
+
const rawTotal = exact.reduce((a, b) => a + b, 0);
|
|
54
|
+
if (rawTotal > 101) return exact.map(Math.round);
|
|
55
|
+
let remaining = 100 - sum;
|
|
56
|
+
const order = exact.map((value, index) => ({ index, remainder: value - Math.floor(value) })).sort((a, b) => b.remainder - a.remainder || a.index - b.index);
|
|
57
|
+
const out = [...floors];
|
|
58
|
+
for (const { index } of order) {
|
|
59
|
+
if (remaining <= 0) break;
|
|
60
|
+
out[index] = (out[index] ?? 0) + 1;
|
|
61
|
+
remaining--;
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
export function junMyBallot(ballots, voter) {
|
|
66
|
+
if (!voter) return [];
|
|
67
|
+
return ballots[voter] ?? [];
|
|
68
|
+
}
|
|
69
|
+
export function junNextBallot(existing, choice, options) {
|
|
70
|
+
const had = existing.length > 0;
|
|
71
|
+
if (had && options.revote === false) return null;
|
|
72
|
+
if (!options.multiple) return [choice];
|
|
73
|
+
const next = existing.includes(choice) ? existing.filter((c) => c !== choice) : [...existing, choice].sort((a, b) => a - b);
|
|
74
|
+
return next;
|
|
75
|
+
}
|
|
76
|
+
export function junCapBallots(ballots, keep = JUN_POLL_VOTERS_MAX) {
|
|
77
|
+
const keys = Object.keys(ballots);
|
|
78
|
+
if (keys.length <= keep) return ballots;
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const key of keys.slice(keys.length - keep)) out[key] = ballots[key];
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
@@ -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[]>;
|