@abraca/junis 2.84.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.
- package/dist/module.d.mts +17 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +270 -22
- package/dist/runtime/assets/css/jun.css +1 -1
- package/dist/runtime/components/JunBlobBackdrop.client.vue +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/JunFooter.vue +1 -1
- package/dist/runtime/components/JunHead.vue +37 -5
- 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/JunLogo.vue +10 -45
- 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/JunPatternBackdrop.client.vue +1 -1
- 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.client.d.vue.ts +17 -0
- package/dist/runtime/components/JunSectionPresence.client.vue +99 -0
- package/dist/runtime/components/JunSectionPresence.client.vue.d.ts +17 -0
- package/dist/runtime/components/JunShaderBackdrop.client.vue +1 -1
- 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 +362 -239
- 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 +157 -31
- package/dist/runtime/components/renderers/JunFestivalRenderer.vue +42 -5
- 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/JunGuestbookRenderer.vue +96 -14
- package/dist/runtime/components/renderers/JunHomeRenderer.vue +31 -132
- 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 +38 -2
- 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 +40 -7
- 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 +57 -13
- 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/useJunOptions.d.ts +1 -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 +49 -50
- package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
- package/dist/runtime/composables/useJunViewOptions.js +63 -0
- package/dist/runtime/pages/doc.vue +14 -8
- package/dist/runtime/plugins/jun-sw.client.d.ts +2 -0
- package/dist/runtime/plugins/jun-sw.client.js +36 -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 +5 -0
- package/dist/runtime/server/api/stats.get.js +2 -1
- 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 +9 -1
- 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/jun-icon.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-icon.png.get.js +25 -0
- package/dist/runtime/server/routes/jun-icon.svg.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-icon.svg.get.js +9 -0
- package/dist/runtime/server/routes/jun-splash.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-splash.png.get.js +37 -0
- package/dist/runtime/server/routes/jun-sw.js.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-sw.js.get.js +126 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +24 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.js +51 -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/junBrand.d.ts +4 -0
- package/dist/runtime/server/utils/junBrand.js +9 -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/junIcon.d.ts +44 -0
- package/dist/runtime/server/utils/junIcon.js +374 -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 +82 -3
- 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/junIdentity.d.ts +121 -0
- package/dist/runtime/utils/junIdentity.js +115 -0
- package/dist/runtime/utils/junMark.d.ts +254 -0
- package/dist/runtime/utils/junMark.js +169 -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 @@
|
|
|
1
|
+
export declare function junBootedAt(): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
2
|
+
import { junIdentity } from "../../utils/junIdentity.js";
|
|
3
|
+
import { junSiteConfigMeta } from "./junCache.js";
|
|
4
|
+
export { junIconScale, junIconUrls } from "../../utils/junIdentity.js";
|
|
5
|
+
export async function junBrandIdentity() {
|
|
6
|
+
const jun = useRuntimeConfig().public.jun;
|
|
7
|
+
const cfg = await junSiteConfigMeta().catch(() => ({}));
|
|
8
|
+
return junIdentity(jun?.brand, cfg);
|
|
9
|
+
}
|
|
@@ -33,6 +33,23 @@ export declare function junDocTree(): Promise<Record<string, JunTreeEntry>>;
|
|
|
33
33
|
* disagreeing about what a page is.
|
|
34
34
|
*/
|
|
35
35
|
export declare function junCountedDocIds(tree: Record<string, JunTreeEntry>, rootDocId: string): Set<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Where the doc-cache runner stamps that it is alive.
|
|
38
|
+
*
|
|
39
|
+
* A cache is not a runner: `/app/.data` persists across container restarts, so a
|
|
40
|
+
* complete cache can outlive the process that filled it — and a deployment whose
|
|
41
|
+
* runners never booted then looks perfectly healthy while serving a frozen
|
|
42
|
+
* snapshot. `junReadiness` treats a missing or stale stamp as dead however
|
|
43
|
+
* complete the cache looks. Found by reproducing the jun.is failure, not by
|
|
44
|
+
* reading the code.
|
|
45
|
+
*/
|
|
46
|
+
export declare const JUN_HEARTBEAT_KEY = "doc-cache:jun-heartbeat";
|
|
47
|
+
export interface JunHeartbeat {
|
|
48
|
+
at: number;
|
|
49
|
+
docs: number;
|
|
50
|
+
}
|
|
51
|
+
/** The last sweep's stamp, or `null` when this process has never swept. */
|
|
52
|
+
export declare function junHeartbeat(): Promise<JunHeartbeat | null>;
|
|
36
53
|
/** Document id → canonical slug, as persisted by the doc-tree-cache runner. */
|
|
37
54
|
export declare function junSlugMap(): Promise<Record<string, string>>;
|
|
38
55
|
/** A document's cached HTML body, or `null` if it has not been rendered yet. */
|
|
@@ -20,6 +20,11 @@ export function junCountedDocIds(tree, rootDocId) {
|
|
|
20
20
|
}
|
|
21
21
|
return out;
|
|
22
22
|
}
|
|
23
|
+
export const JUN_HEARTBEAT_KEY = "doc-cache:jun-heartbeat";
|
|
24
|
+
export async function junHeartbeat() {
|
|
25
|
+
const beat = await useStorage().getItem(JUN_HEARTBEAT_KEY);
|
|
26
|
+
return beat && typeof beat.at === "number" ? beat : null;
|
|
27
|
+
}
|
|
23
28
|
export async function junSlugMap() {
|
|
24
29
|
const map = await useStorage().getItem(
|
|
25
30
|
"doc-cache:slug-map"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { JunMarkColors, JunMarkName } from '../../utils/junMark.js';
|
|
2
|
+
type Segment = [number, number, number, number];
|
|
3
|
+
/**
|
|
4
|
+
* Flatten one `d` attribute into line segments.
|
|
5
|
+
*
|
|
6
|
+
* Cubics are sampled at a fixed 24 steps. That is not adaptive, and it does not
|
|
7
|
+
* need to be: the largest icon is 512px and the longest curve in any mark spans
|
|
8
|
+
* about a third of the box, so 24 steps puts the chord error well under a
|
|
9
|
+
* device pixel.
|
|
10
|
+
*/
|
|
11
|
+
export declare function junFlattenPath(d: string): Segment[];
|
|
12
|
+
export interface JunIconRequest {
|
|
13
|
+
mark: JunMarkName;
|
|
14
|
+
/** Image width in device pixels. Also the height unless one is given. */
|
|
15
|
+
size: number;
|
|
16
|
+
/** Image height. Differs only for a launch image, which is device-shaped. */
|
|
17
|
+
height?: number;
|
|
18
|
+
colors: JunMarkColors;
|
|
19
|
+
/** Tile colour. `null` renders on transparency. */
|
|
20
|
+
background?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* How much of the SHORTER side the mark fills. `1` is edge to edge — right
|
|
23
|
+
* for `sun`, which IS a disc. A maskable icon passes ~0.6 so the mark
|
|
24
|
+
* survives Android's circular crop; a launch image passes something much
|
|
25
|
+
* smaller, because a logo filling a phone screen is a loading spinner.
|
|
26
|
+
*/
|
|
27
|
+
scale?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Render the mark to a PNG.
|
|
31
|
+
*
|
|
32
|
+
* Supersampled 3× per axis below 256px and 2× above it — the visible quality
|
|
33
|
+
* ceiling is the small sizes (a 32px favicon and a 180px touch icon are where
|
|
34
|
+
* a jagged edge shows), while the 512 tile is displayed small enough that 2× is
|
|
35
|
+
* indistinguishable and four times cheaper.
|
|
36
|
+
*
|
|
37
|
+
* The mark occupies a CENTRED SQUARE of `min(width, height) × scale`, and every
|
|
38
|
+
* pixel outside that square is a straight fill. That is what makes a 1290×2796
|
|
39
|
+
* launch image cheap: the shape loop runs over the mark's own box (a few
|
|
40
|
+
* hundred pixels a side) rather than over three and a half million pixels of
|
|
41
|
+
* flat colour.
|
|
42
|
+
*/
|
|
43
|
+
export declare function junRenderIcon(req: JunIconRequest): Promise<Uint8Array>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { JUN_MARKS, JUN_MARK_VIEWBOX, JUN_SUN, junHexToRgb } from "../../utils/junMark.js";
|
|
2
|
+
const CMD_RE = /[MmLlHhVvCcZz]|-?\d*\.?\d+(?:e[-+]?\d+)?/g;
|
|
3
|
+
export function junFlattenPath(d) {
|
|
4
|
+
const tokens = d.match(CMD_RE) ?? [];
|
|
5
|
+
const segs = [];
|
|
6
|
+
let i = 0;
|
|
7
|
+
let cmd = "";
|
|
8
|
+
let x = 0;
|
|
9
|
+
let y = 0;
|
|
10
|
+
let startX = 0;
|
|
11
|
+
let startY = 0;
|
|
12
|
+
let started = false;
|
|
13
|
+
const num = () => Number.parseFloat(tokens[i++] ?? "0");
|
|
14
|
+
const lineTo = (nx, ny) => {
|
|
15
|
+
segs.push([x, y, nx, ny]);
|
|
16
|
+
x = nx;
|
|
17
|
+
y = ny;
|
|
18
|
+
};
|
|
19
|
+
const cubicTo = (x1, y1, x2, y2, ex, ey) => {
|
|
20
|
+
const px = x;
|
|
21
|
+
const py = y;
|
|
22
|
+
const STEPS = 24;
|
|
23
|
+
for (let s = 1; s <= STEPS; s++) {
|
|
24
|
+
const t = s / STEPS;
|
|
25
|
+
const u = 1 - t;
|
|
26
|
+
const bx = u * u * u * px + 3 * u * u * t * x1 + 3 * u * t * t * x2 + t * t * t * ex;
|
|
27
|
+
const by = u * u * u * py + 3 * u * u * t * y1 + 3 * u * t * t * y2 + t * t * t * ey;
|
|
28
|
+
segs.push([x, y, bx, by]);
|
|
29
|
+
x = bx;
|
|
30
|
+
y = by;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
while (i < tokens.length) {
|
|
34
|
+
const tok = tokens[i];
|
|
35
|
+
if (/[a-z]/i.test(tok)) {
|
|
36
|
+
cmd = tok;
|
|
37
|
+
i++;
|
|
38
|
+
} else if (cmd === "M") {
|
|
39
|
+
cmd = "L";
|
|
40
|
+
continue;
|
|
41
|
+
} else if (cmd === "m") {
|
|
42
|
+
cmd = "l";
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
switch (cmd) {
|
|
46
|
+
case "M":
|
|
47
|
+
case "m": {
|
|
48
|
+
const nx = num();
|
|
49
|
+
const ny = num();
|
|
50
|
+
x = cmd === "m" && started ? x + nx : nx;
|
|
51
|
+
y = cmd === "m" && started ? y + ny : ny;
|
|
52
|
+
startX = x;
|
|
53
|
+
startY = y;
|
|
54
|
+
started = true;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "L":
|
|
58
|
+
case "l": {
|
|
59
|
+
const nx = num();
|
|
60
|
+
const ny = num();
|
|
61
|
+
lineTo(cmd === "l" ? x + nx : nx, cmd === "l" ? y + ny : ny);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case "H":
|
|
65
|
+
case "h": {
|
|
66
|
+
const nx = num();
|
|
67
|
+
lineTo(cmd === "h" ? x + nx : nx, y);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "V":
|
|
71
|
+
case "v": {
|
|
72
|
+
const ny = num();
|
|
73
|
+
lineTo(x, cmd === "v" ? y + ny : ny);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "C":
|
|
77
|
+
case "c": {
|
|
78
|
+
const rel = cmd === "c";
|
|
79
|
+
const x1 = num() + (rel ? x : 0);
|
|
80
|
+
const y1 = num() + (rel ? y : 0);
|
|
81
|
+
const x2 = num() + (rel ? x : 0);
|
|
82
|
+
const y2 = num() + (rel ? y : 0);
|
|
83
|
+
const ex = num() + (rel ? x : 0);
|
|
84
|
+
const ey = num() + (rel ? y : 0);
|
|
85
|
+
cubicTo(x1, y1, x2, y2, ex, ey);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "Z":
|
|
89
|
+
case "z":
|
|
90
|
+
lineTo(startX, startY);
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
i++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return segs;
|
|
97
|
+
}
|
|
98
|
+
function distSqToSegment(px, py, s) {
|
|
99
|
+
const [ax, ay, bx, by] = s;
|
|
100
|
+
const dx = bx - ax;
|
|
101
|
+
const dy = by - ay;
|
|
102
|
+
const len = dx * dx + dy * dy;
|
|
103
|
+
let t = len === 0 ? 0 : ((px - ax) * dx + (py - ay) * dy) / len;
|
|
104
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
105
|
+
const cx = ax + t * dx - px;
|
|
106
|
+
const cy = ay + t * dy - py;
|
|
107
|
+
return cx * cx + cy * cy;
|
|
108
|
+
}
|
|
109
|
+
function mixRgb(a, b, t) {
|
|
110
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
111
|
+
}
|
|
112
|
+
function circleShape(cx, cy, r, rgb, alpha = 1) {
|
|
113
|
+
const r2 = r * r;
|
|
114
|
+
return {
|
|
115
|
+
bb: [cx - r, cy - r, cx + r, cy + r],
|
|
116
|
+
at: (x, y) => {
|
|
117
|
+
const dx = x - cx;
|
|
118
|
+
const dy = y - cy;
|
|
119
|
+
return dx * dx + dy * dy <= r2 ? [rgb[0], rgb[1], rgb[2], alpha] : null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function strokeShape(segs, width, rgb) {
|
|
124
|
+
const half = width / 2;
|
|
125
|
+
const halfSq = half * half;
|
|
126
|
+
let x0 = Infinity;
|
|
127
|
+
let y0 = Infinity;
|
|
128
|
+
let x1 = -Infinity;
|
|
129
|
+
let y1 = -Infinity;
|
|
130
|
+
for (const s of segs) {
|
|
131
|
+
x0 = Math.min(x0, s[0], s[2]);
|
|
132
|
+
y0 = Math.min(y0, s[1], s[3]);
|
|
133
|
+
x1 = Math.max(x1, s[0], s[2]);
|
|
134
|
+
y1 = Math.max(y1, s[1], s[3]);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
bb: [x0 - half, y0 - half, x1 + half, y1 + half],
|
|
138
|
+
at: (x, y) => {
|
|
139
|
+
for (const s of segs) {
|
|
140
|
+
if (distSqToSegment(x, y, s) <= halfSq) return [rgb[0], rgb[1], rgb[2], 1];
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function markShapes(mark, c) {
|
|
147
|
+
if (mark !== "sun") {
|
|
148
|
+
const geom = JUN_MARKS[mark] ?? JUN_MARKS.sprout;
|
|
149
|
+
const ink = junHexToRgb(c.ink);
|
|
150
|
+
return [
|
|
151
|
+
...geom.paths.map((p) => strokeShape(junFlattenPath(p.d), p.w, ink)),
|
|
152
|
+
...geom.dots.map((dot) => circleShape(dot.cx, dot.cy, dot.r, ink))
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
const { body, core, glow, halo } = JUN_SUN;
|
|
156
|
+
const from = junHexToRgb(c.sunFrom);
|
|
157
|
+
const to = junHexToRgb(c.sunTo);
|
|
158
|
+
const coreRgb = junHexToRgb(c.sunCore);
|
|
159
|
+
const glowRgb = junHexToRgb(c.sunGlow);
|
|
160
|
+
const vb = JUN_MARK_VIEWBOX;
|
|
161
|
+
const bodyR2 = body.r * body.r;
|
|
162
|
+
const coreR2 = core.r * core.r;
|
|
163
|
+
const haloR2 = halo.r * halo.r;
|
|
164
|
+
const haloInnerStop = core.r / halo.r;
|
|
165
|
+
return [
|
|
166
|
+
// Body: `linearGradient x1/y1 0 → x2/y2 1` on a square box is exactly
|
|
167
|
+
// corner to corner, so the parameter is (x + y) over twice the box.
|
|
168
|
+
{
|
|
169
|
+
bb: [body.cx - body.r, body.cy - body.r, body.cx + body.r, body.cy + body.r],
|
|
170
|
+
at: (x, y) => {
|
|
171
|
+
const dx = x - body.cx;
|
|
172
|
+
const dy = y - body.cy;
|
|
173
|
+
if (dx * dx + dy * dy > bodyR2) return null;
|
|
174
|
+
const t = Math.max(0, Math.min(1, (x + y) / (2 * vb)));
|
|
175
|
+
const [r, g, b] = mixRgb(from, to, t);
|
|
176
|
+
return [r, g, b, 1];
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
// Halo: black, flat out to the core's edge, then falling away.
|
|
180
|
+
{
|
|
181
|
+
bb: [halo.cx - halo.r, halo.cy - halo.r, halo.cx + halo.r, halo.cy + halo.r],
|
|
182
|
+
at: (x, y) => {
|
|
183
|
+
const dx = x - halo.cx;
|
|
184
|
+
const dy = y - halo.cy;
|
|
185
|
+
const d2 = dx * dx + dy * dy;
|
|
186
|
+
if (d2 > haloR2) return null;
|
|
187
|
+
const t = Math.sqrt(d2) / halo.r;
|
|
188
|
+
let a;
|
|
189
|
+
if (t <= haloInnerStop) a = halo.inner;
|
|
190
|
+
else if (t <= 0.84) a = halo.inner + (halo.mid - halo.inner) * ((t - haloInnerStop) / (0.84 - haloInnerStop));
|
|
191
|
+
else a = halo.mid * (1 - (t - 0.84) / 0.16);
|
|
192
|
+
return [0, 0, 0, a];
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
circleShape(core.cx, core.cy, core.r, coreRgb),
|
|
196
|
+
// Glow: a radial gradient centred well outside the mark and CLIPPED by the
|
|
197
|
+
// core, which is what puts it in the core's lower right and leaves the
|
|
198
|
+
// upper left clean.
|
|
199
|
+
{
|
|
200
|
+
bb: [core.cx - core.r, core.cy - core.r, core.cx + core.r, core.cy + core.r],
|
|
201
|
+
at: (x, y) => {
|
|
202
|
+
const dx = x - core.cx;
|
|
203
|
+
const dy = y - core.cy;
|
|
204
|
+
if (dx * dx + dy * dy > coreR2) return null;
|
|
205
|
+
const gx = x - glow.cx;
|
|
206
|
+
const gy = y - glow.cy;
|
|
207
|
+
const a = 1 - Math.sqrt(gx * gx + gy * gy) / glow.r;
|
|
208
|
+
if (a <= 0) return null;
|
|
209
|
+
return [glowRgb[0], glowRgb[1], glowRgb[2], a];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
let crcTable = null;
|
|
215
|
+
function crc32(buf) {
|
|
216
|
+
if (!crcTable) {
|
|
217
|
+
crcTable = new Uint32Array(256);
|
|
218
|
+
for (let n = 0; n < 256; n++) {
|
|
219
|
+
let c2 = n;
|
|
220
|
+
for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
|
|
221
|
+
crcTable[n] = c2 >>> 0;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
let c = 4294967295;
|
|
225
|
+
for (let i = 0; i < buf.length; i++) c = crcTable[(c ^ buf[i]) & 255] ^ c >>> 8;
|
|
226
|
+
return (c ^ 4294967295) >>> 0;
|
|
227
|
+
}
|
|
228
|
+
function pngChunk(type, data) {
|
|
229
|
+
const typeBytes = new TextEncoder().encode(type);
|
|
230
|
+
const body = new Uint8Array(typeBytes.length + data.length);
|
|
231
|
+
body.set(typeBytes);
|
|
232
|
+
body.set(data, typeBytes.length);
|
|
233
|
+
const out = new Uint8Array(8 + data.length + 4);
|
|
234
|
+
const view = new DataView(out.buffer);
|
|
235
|
+
view.setUint32(0, data.length);
|
|
236
|
+
out.set(body, 4);
|
|
237
|
+
view.setUint32(4 + body.length, crc32(body));
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
async function encodePng(rgba, width, height) {
|
|
241
|
+
const { deflateSync } = await import("node:zlib");
|
|
242
|
+
const stride = width * 4;
|
|
243
|
+
const raw = new Uint8Array(height * (1 + stride));
|
|
244
|
+
for (let y = 0; y < height; y++) {
|
|
245
|
+
const at2 = y * (1 + stride);
|
|
246
|
+
if (y === 0) {
|
|
247
|
+
raw[at2] = 0;
|
|
248
|
+
raw.set(rgba.subarray(0, stride), at2 + 1);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
raw[at2] = 2;
|
|
252
|
+
const row = y * stride;
|
|
253
|
+
const prev = row - stride;
|
|
254
|
+
for (let i = 0; i < stride; i++) {
|
|
255
|
+
raw[at2 + 1 + i] = rgba[row + i] - rgba[prev + i] & 255;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const ihdr = new Uint8Array(13);
|
|
259
|
+
const iv = new DataView(ihdr.buffer);
|
|
260
|
+
iv.setUint32(0, width);
|
|
261
|
+
iv.setUint32(4, height);
|
|
262
|
+
ihdr[8] = 8;
|
|
263
|
+
ihdr[9] = 6;
|
|
264
|
+
const parts = [
|
|
265
|
+
new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
266
|
+
pngChunk("IHDR", ihdr),
|
|
267
|
+
pngChunk("IDAT", new Uint8Array(deflateSync(Buffer.from(raw), { level: 6 }))),
|
|
268
|
+
pngChunk("IEND", new Uint8Array(0))
|
|
269
|
+
];
|
|
270
|
+
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
271
|
+
const png = new Uint8Array(total);
|
|
272
|
+
let at = 0;
|
|
273
|
+
for (const p of parts) {
|
|
274
|
+
png.set(p, at);
|
|
275
|
+
at += p.length;
|
|
276
|
+
}
|
|
277
|
+
return png;
|
|
278
|
+
}
|
|
279
|
+
const cache = /* @__PURE__ */ new Map();
|
|
280
|
+
function cacheKey(req) {
|
|
281
|
+
const c = req.colors;
|
|
282
|
+
return [
|
|
283
|
+
req.mark,
|
|
284
|
+
req.size,
|
|
285
|
+
req.height ?? req.size,
|
|
286
|
+
req.background ?? "-",
|
|
287
|
+
req.scale ?? 1,
|
|
288
|
+
c.ink,
|
|
289
|
+
c.sunFrom,
|
|
290
|
+
c.sunTo,
|
|
291
|
+
c.sunCore,
|
|
292
|
+
c.sunGlow
|
|
293
|
+
].join("|");
|
|
294
|
+
}
|
|
295
|
+
export async function junRenderIcon(req) {
|
|
296
|
+
const key = cacheKey(req);
|
|
297
|
+
const hit = cache.get(key);
|
|
298
|
+
if (hit) return hit;
|
|
299
|
+
const width = Math.max(16, Math.min(4096, Math.round(req.size)));
|
|
300
|
+
const height = Math.max(16, Math.min(4096, Math.round(req.height ?? req.size)));
|
|
301
|
+
const scale = req.scale ?? 1;
|
|
302
|
+
const shorter = Math.min(width, height);
|
|
303
|
+
const ss = shorter < 256 ? 3 : 2;
|
|
304
|
+
const vb = JUN_MARK_VIEWBOX;
|
|
305
|
+
const shapes = markShapes(req.mark, req.colors);
|
|
306
|
+
const bg = req.background ? junHexToRgb(req.background) : null;
|
|
307
|
+
const box = shorter * scale;
|
|
308
|
+
const boxX = (width - box) / 2;
|
|
309
|
+
const boxY = (height - box) / 2;
|
|
310
|
+
const step = vb / box;
|
|
311
|
+
const sub = step / ss;
|
|
312
|
+
const offset = sub / 2;
|
|
313
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
314
|
+
if (bg) {
|
|
315
|
+
for (let i = 0; i < rgba.length; i += 4) {
|
|
316
|
+
rgba[i] = bg[0];
|
|
317
|
+
rgba[i + 1] = bg[1];
|
|
318
|
+
rgba[i + 2] = bg[2];
|
|
319
|
+
rgba[i + 3] = 255;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const x0 = Math.max(0, Math.floor(boxX));
|
|
323
|
+
const y0 = Math.max(0, Math.floor(boxY));
|
|
324
|
+
const x1 = Math.min(width, Math.ceil(boxX + box));
|
|
325
|
+
const y1 = Math.min(height, Math.ceil(boxY + box));
|
|
326
|
+
const inv = 1 / (ss * ss);
|
|
327
|
+
for (let py = y0; py < y1; py++) {
|
|
328
|
+
for (let px = x0; px < x1; px++) {
|
|
329
|
+
let ar = 0;
|
|
330
|
+
let ag = 0;
|
|
331
|
+
let ab = 0;
|
|
332
|
+
let aa = 0;
|
|
333
|
+
for (let sy = 0; sy < ss; sy++) {
|
|
334
|
+
const uy = (py - boxY) * step + sy * sub + offset;
|
|
335
|
+
for (let sx = 0; sx < ss; sx++) {
|
|
336
|
+
const ux = (px - boxX) * step + sx * sub + offset;
|
|
337
|
+
let r = bg ? bg[0] : 0;
|
|
338
|
+
let g = bg ? bg[1] : 0;
|
|
339
|
+
let b = bg ? bg[2] : 0;
|
|
340
|
+
let a = bg ? 1 : 0;
|
|
341
|
+
for (const shape of shapes) {
|
|
342
|
+
if (ux < shape.bb[0] || ux > shape.bb[2] || uy < shape.bb[1] || uy > shape.bb[3]) continue;
|
|
343
|
+
const s = shape.at(ux, uy);
|
|
344
|
+
if (!s) continue;
|
|
345
|
+
const sa = s[3];
|
|
346
|
+
if (sa <= 0) continue;
|
|
347
|
+
const outA = sa + a * (1 - sa);
|
|
348
|
+
if (outA <= 0) continue;
|
|
349
|
+
r = (s[0] * sa + r * a * (1 - sa)) / outA;
|
|
350
|
+
g = (s[1] * sa + g * a * (1 - sa)) / outA;
|
|
351
|
+
b = (s[2] * sa + b * a * (1 - sa)) / outA;
|
|
352
|
+
a = outA;
|
|
353
|
+
}
|
|
354
|
+
ar += r * a;
|
|
355
|
+
ag += g * a;
|
|
356
|
+
ab += b * a;
|
|
357
|
+
aa += a;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const o = (py * width + px) * 4;
|
|
361
|
+
const alpha = aa * inv;
|
|
362
|
+
if (alpha > 0) {
|
|
363
|
+
rgba[o] = Math.round(Math.max(0, Math.min(255, ar / aa)));
|
|
364
|
+
rgba[o + 1] = Math.round(Math.max(0, Math.min(255, ag / aa)));
|
|
365
|
+
rgba[o + 2] = Math.round(Math.max(0, Math.min(255, ab / aa)));
|
|
366
|
+
}
|
|
367
|
+
rgba[o + 3] = Math.round(Math.max(0, Math.min(255, alpha * 255)));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const png = await encodePng(rgba, width, height);
|
|
371
|
+
if (cache.size > 48) cache.clear();
|
|
372
|
+
cache.set(key, png);
|
|
373
|
+
return png;
|
|
374
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One signal, from the seeder to the janitor: **the site is finished being
|
|
3
|
+
* built.**
|
|
4
|
+
*
|
|
5
|
+
* ── The bug this replaces ────────────────────────────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* The janitor waited a flat `BOOT_DELAY_MS` (20s) before capturing its
|
|
8
|
+
* baseline, with a comment saying exactly why — *"capturing a baseline mid-seed
|
|
9
|
+
* would record a half-built site as the clean state"* — and a guess in place of
|
|
10
|
+
* a signal.
|
|
11
|
+
*
|
|
12
|
+
* The guess loses on a first boot. Measured on the playground: 127 documents,
|
|
13
|
+
* 117 bodies and then four generated PNGs uploaded over HTTP, and the upload
|
|
14
|
+
* pass is the one that finishes last because it is the only part waiting on a
|
|
15
|
+
* network round trip per item. The janitor's baseline landed BETWEEN the tree
|
|
16
|
+
* write and the photo patch, so `coverUploadId` on every wall photograph looked
|
|
17
|
+
* like something a visitor had added — and in `clean` mode it was reverted,
|
|
18
|
+
* once, permanently, before anybody ever saw the Wall.
|
|
19
|
+
*
|
|
20
|
+
* The symptom is not janitor-shaped at all: **the Wall renders its title and no
|
|
21
|
+
* photographs**, on a site whose seeder logged `uploaded 4 wall photo(s)`. The
|
|
22
|
+
* tell is a tree entry that still carries `seedWallPhoto: true` — the seeder
|
|
23
|
+
* deletes that key in the same write that adds the cover — and a
|
|
24
|
+
* `janitor:inspect` that reports the site matching its baseline exactly, because
|
|
25
|
+
* by then it does.
|
|
26
|
+
*
|
|
27
|
+
* ── Why a module-scoped promise ──────────────────────────────────────────────
|
|
28
|
+
*
|
|
29
|
+
* Both plugins live in ONE Nitro process, so the simplest correct channel is a
|
|
30
|
+
* shared module. Either side may touch it first: whoever does creates the
|
|
31
|
+
* promise, the seeder resolves it, the janitor awaits it. Nitro's plugin order
|
|
32
|
+
* therefore does not matter, which is the property a storage key or a hook would
|
|
33
|
+
* not have given without more ceremony.
|
|
34
|
+
*
|
|
35
|
+
* The wait is BOUNDED and the caller passes the bound. A seeder that dies
|
|
36
|
+
* without settling must not leave the janitor asleep forever — it would present
|
|
37
|
+
* as "the janitor never starts", which is the single hardest failure to read in
|
|
38
|
+
* this subsystem.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Called by the seeder as it starts, so a janitor that asks first has something
|
|
42
|
+
* to wait on rather than resolving immediately.
|
|
43
|
+
*/
|
|
44
|
+
export declare function junSeedStarted(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Called by the seeder when the tree, the bodies AND the uploads are all in.
|
|
47
|
+
* Idempotent, and safe to call from a `finally` — a seed that failed halfway is
|
|
48
|
+
* still a seed that is no longer writing, which is what the janitor is waiting
|
|
49
|
+
* to know.
|
|
50
|
+
*/
|
|
51
|
+
export declare function junSeedFinished(): void;
|
|
52
|
+
/** Has the seeder already finished (or never started) in this process? */
|
|
53
|
+
export declare function junSeedSettled(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Is there a seeder in this process at all?
|
|
56
|
+
*
|
|
57
|
+
* The janitor must not wait on a gate nobody will open — a site with
|
|
58
|
+
* `seed.enabled: false` has no seeder, and waiting out the full bound there
|
|
59
|
+
* would delay the baseline for no reason. Safe to call after the janitor's own
|
|
60
|
+
* boot delay: both plugins register their runners in the same tick, so a seeder
|
|
61
|
+
* that exists has claimed the gate long before anybody asks.
|
|
62
|
+
*/
|
|
63
|
+
export declare function junSeedExpected(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Wait for the seed to finish, or for `timeoutMs`, whichever comes first.
|
|
66
|
+
* Resolves immediately when the seed has already settled.
|
|
67
|
+
*/
|
|
68
|
+
export declare function junWaitForSeed(timeoutMs: number): Promise<boolean>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
let settled = false;
|
|
2
|
+
let resolveGate = null;
|
|
3
|
+
let gate = null;
|
|
4
|
+
function ensure() {
|
|
5
|
+
if (!gate) {
|
|
6
|
+
gate = new Promise((resolve) => {
|
|
7
|
+
resolveGate = resolve;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return gate;
|
|
11
|
+
}
|
|
12
|
+
export function junSeedStarted() {
|
|
13
|
+
if (settled) return;
|
|
14
|
+
ensure();
|
|
15
|
+
}
|
|
16
|
+
export function junSeedFinished() {
|
|
17
|
+
settled = true;
|
|
18
|
+
ensure();
|
|
19
|
+
resolveGate?.();
|
|
20
|
+
resolveGate = null;
|
|
21
|
+
}
|
|
22
|
+
export function junSeedSettled() {
|
|
23
|
+
return settled;
|
|
24
|
+
}
|
|
25
|
+
export function junSeedExpected() {
|
|
26
|
+
return gate !== null;
|
|
27
|
+
}
|
|
28
|
+
export async function junWaitForSeed(timeoutMs) {
|
|
29
|
+
if (settled) return true;
|
|
30
|
+
const promise = ensure();
|
|
31
|
+
let timer;
|
|
32
|
+
const timeout = new Promise((resolve) => {
|
|
33
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
const won = await Promise.race([promise.then(() => true), timeout]);
|
|
37
|
+
return won;
|
|
38
|
+
} finally {
|
|
39
|
+
if (timer) clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|