@cloudhal/astro-renderer 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +36 -2
- package/dist/src/ambient-client.d.ts +17 -0
- package/dist/src/ambient-client.js +55 -0
- package/dist/src/analytics-client.d.ts +17 -0
- package/dist/src/analytics-client.js +96 -0
- package/dist/src/analytics-middleware.d.ts +6 -0
- package/dist/src/analytics-middleware.js +43 -0
- package/dist/src/analytics-node.d.ts +46 -0
- package/dist/src/analytics-node.js +134 -0
- package/dist/src/analytics.d.ts +117 -0
- package/dist/src/analytics.js +372 -0
- package/dist/src/archive.d.ts +106 -0
- package/dist/src/archive.js +207 -0
- package/dist/src/astro-env.d.ts +21 -0
- package/dist/src/block-html.d.ts +14 -0
- package/dist/src/block-html.js +103 -0
- package/dist/src/blocks.d.ts +24 -0
- package/dist/src/blocks.js +66 -0
- package/dist/src/cache-tags.d.ts +25 -0
- package/dist/src/cache-tags.js +59 -0
- package/dist/src/carousel-client.d.ts +28 -0
- package/dist/src/carousel-client.js +67 -0
- package/dist/src/chart.d.ts +34 -0
- package/dist/src/chart.js +182 -0
- package/dist/src/chrome-client.d.ts +27 -0
- package/dist/src/chrome-client.js +64 -0
- package/dist/src/cloudflare-entry.d.ts +87 -0
- package/dist/src/cloudflare-entry.js +548 -0
- package/dist/src/comments-client.d.ts +11 -0
- package/dist/src/comments-client.js +58 -0
- package/dist/src/comments-html.d.ts +42 -0
- package/dist/src/comments-html.js +303 -0
- package/dist/src/comments-middleware.d.ts +6 -0
- package/dist/src/comments-middleware.js +38 -0
- package/dist/src/comments-node.d.ts +42 -0
- package/dist/src/comments-node.js +112 -0
- package/dist/src/comments-view.d.ts +68 -0
- package/dist/src/comments-view.js +174 -0
- package/dist/src/comments.d.ts +66 -0
- package/dist/src/comments.js +258 -0
- package/dist/src/components/Block.astro +39 -0
- package/dist/src/components/Body.astro +43 -0
- package/dist/src/components/Comments.astro +19 -0
- package/dist/src/components/ContentList.astro +31 -0
- package/dist/src/components/EntryArticle.astro +31 -0
- package/dist/src/components/Hero.astro +36 -0
- package/dist/src/components/Image.astro +36 -0
- package/dist/src/components/RichText.astro +19 -0
- package/dist/src/components/Sections.astro +66 -0
- package/dist/src/components/SeoHead.astro +22 -0
- package/dist/src/components/Surface.astro +36 -0
- package/dist/src/components/SurfaceNode.astro +82 -0
- package/dist/src/components/index.d.ts +12 -0
- package/dist/src/components/index.js +12 -0
- package/dist/src/csp.d.ts +20 -0
- package/dist/src/csp.js +28 -0
- package/dist/src/embed-client.d.ts +38 -0
- package/dist/src/embed-client.js +98 -0
- package/dist/src/embed-middleware.d.ts +9 -0
- package/dist/src/embed-middleware.js +49 -0
- package/dist/src/feeds.d.ts +72 -0
- package/dist/src/feeds.js +246 -0
- package/dist/src/gates.d.ts +25 -0
- package/dist/src/gates.js +63 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +17 -0
- package/dist/src/integration.d.ts +55 -0
- package/dist/src/integration.js +244 -0
- package/dist/src/kit.d.ts +48 -0
- package/dist/src/kit.js +83 -0
- package/dist/src/locale-feeds.d.ts +29 -0
- package/dist/src/locale-feeds.js +152 -0
- package/dist/src/locale-middleware.d.ts +5 -0
- package/dist/src/locale-middleware.js +26 -0
- package/dist/src/locales.d.ts +87 -0
- package/dist/src/locales.js +336 -0
- package/dist/src/markdown.d.ts +83 -0
- package/dist/src/markdown.js +533 -0
- package/dist/src/media-middleware.d.ts +5 -0
- package/dist/src/media-middleware.js +18 -0
- package/dist/src/media-route.d.ts +47 -0
- package/dist/src/media-route.js +238 -0
- package/dist/src/media.d.ts +109 -0
- package/dist/src/media.js +298 -0
- package/dist/src/motion-client.d.ts +39 -0
- package/dist/src/motion-client.js +115 -0
- package/dist/src/navigation.d.ts +127 -0
- package/dist/src/navigation.js +382 -0
- package/dist/src/not-found.d.ts +16 -0
- package/dist/src/not-found.js +41 -0
- package/dist/src/overlay-client.d.ts +20 -0
- package/dist/src/overlay-client.js +49 -0
- package/dist/src/prefs-client.d.ts +14 -0
- package/dist/src/prefs-client.js +18 -0
- package/dist/src/preview.d.ts +70 -0
- package/dist/src/preview.js +551 -0
- package/dist/src/resolver.d.ts +71 -0
- package/dist/src/resolver.js +206 -0
- package/dist/src/routing.d.ts +108 -0
- package/dist/src/routing.js +285 -0
- package/dist/src/runtime-workerd.d.ts +87 -0
- package/dist/src/runtime-workerd.js +275 -0
- package/dist/src/runtime.d.ts +59 -0
- package/dist/src/runtime.js +153 -0
- package/dist/src/safe-urls.d.ts +13 -0
- package/dist/src/safe-urls.js +35 -0
- package/dist/src/sanitize.d.ts +7 -0
- package/dist/src/sanitize.js +217 -0
- package/dist/src/search-client.d.ts +29 -0
- package/dist/src/search-client.js +92 -0
- package/dist/src/search-limit.d.ts +36 -0
- package/dist/src/search-limit.js +66 -0
- package/dist/src/search.d.ts +64 -0
- package/dist/src/search.js +155 -0
- package/dist/src/seo.d.ts +85 -0
- package/dist/src/seo.js +468 -0
- package/dist/src/site-dispatch.d.ts +37 -0
- package/dist/src/site-dispatch.js +86 -0
- package/dist/src/site-hosts.d.ts +35 -0
- package/dist/src/site-hosts.js +110 -0
- package/dist/src/source.d.ts +227 -0
- package/dist/src/source.js +794 -0
- package/dist/src/static-gates.d.ts +3 -0
- package/dist/src/static-gates.js +28 -0
- package/dist/src/static-headers.d.ts +30 -0
- package/dist/src/static-headers.js +140 -0
- package/dist/src/static-media.d.ts +4 -0
- package/dist/src/static-media.js +65 -0
- package/dist/src/static-redirects.d.ts +4 -0
- package/dist/src/static-redirects.js +40 -0
- package/dist/src/surface-client.d.ts +34 -0
- package/dist/src/surface-client.js +146 -0
- package/dist/src/surfaces/html.d.ts +35 -0
- package/dist/src/surfaces/html.js +184 -0
- package/dist/src/surfaces/markup.d.ts +57 -0
- package/dist/src/surfaces/markup.js +135 -0
- package/dist/src/surfaces/motion.d.ts +33 -0
- package/dist/src/surfaces/motion.js +132 -0
- package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
- package/dist/src/surfaces/primitives/carousel.js +95 -0
- package/dist/src/surfaces/primitives/content.d.ts +13 -0
- package/dist/src/surfaces/primitives/content.js +159 -0
- package/dist/src/surfaces/primitives/data.d.ts +5 -0
- package/dist/src/surfaces/primitives/data.js +80 -0
- package/dist/src/surfaces/primitives/index.d.ts +54 -0
- package/dist/src/surfaces/primitives/index.js +106 -0
- package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
- package/dist/src/surfaces/primitives/inputs.js +68 -0
- package/dist/src/surfaces/primitives/layout.d.ts +14 -0
- package/dist/src/surfaces/primitives/layout.js +61 -0
- package/dist/src/surfaces/primitives/motion.d.ts +9 -0
- package/dist/src/surfaces/primitives/motion.js +45 -0
- package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
- package/dist/src/surfaces/primitives/overlays.js +79 -0
- package/dist/src/surfaces/tree.d.ts +107 -0
- package/dist/src/surfaces/tree.js +321 -0
- package/dist/src/surfaces.d.ts +14 -0
- package/dist/src/surfaces.js +33 -0
- package/dist/src/taxonomy.d.ts +86 -0
- package/dist/src/taxonomy.js +268 -0
- package/dist/src/theme-settings.d.ts +24 -0
- package/dist/src/theme-settings.js +111 -0
- package/package.json +219 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0025 §3: overlays, closed until the reader opens them (top layer when open): dialogs and
|
|
3
|
+
* drawers, popovers, tooltips and lightboxes.
|
|
4
|
+
*/
|
|
5
|
+
import { escapeHtml } from "../../markdown.js";
|
|
6
|
+
import { imageAttributes, imgHtml, } from "../../media.js";
|
|
7
|
+
import { attr, CHILDREN, closeButton, iconOf, str } from "../markup.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* RFC-0025 §3: a Lightbox's thumbnails, each a link to its image (the way in without JavaScript),
|
|
11
|
+
* and its modal dialog with every image, one shown at a time (the overlay module moves through them).
|
|
12
|
+
*/
|
|
13
|
+
function lightboxHtml(id , p , media ) {
|
|
14
|
+
const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en";
|
|
15
|
+
const locale = media?.locale ?? defaultLocale;
|
|
16
|
+
const tr = locale.startsWith("tr");
|
|
17
|
+
const opts = {
|
|
18
|
+
locale,
|
|
19
|
+
defaultLocale,
|
|
20
|
+
transform: media?.transform ?? "none",
|
|
21
|
+
...(media?.budget ? { budget: media.budget } : {}),
|
|
22
|
+
...(media?.preview ? { preview: true } : {}),
|
|
23
|
+
} ;
|
|
24
|
+
const items = (Array.isArray(p.items) ? p.items : []).slice(0, 24).flatMap((raw) => {
|
|
25
|
+
const it = (raw ?? {}) ;
|
|
26
|
+
const m = /^asset:([a-z]+_[A-Za-z0-9]{6,32})$/.exec(str(it.asset));
|
|
27
|
+
const asset = m ? media?.assets?.get(m[1] ) : undefined;
|
|
28
|
+
if (!asset) {
|
|
29
|
+
if (m) media?.onMiss?.(m[1] );
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
return [{ asset, alt: str(it.alt), caption: str(it.caption) }];
|
|
33
|
+
});
|
|
34
|
+
if (items.length === 0) return "";
|
|
35
|
+
const start = Math.min(Math.max(Number(p.start) || 0, 0), items.length - 1);
|
|
36
|
+
const title = str(p.title) || (tr ? "Görseller" : "Images");
|
|
37
|
+
const thumbs = items
|
|
38
|
+
.map((it, i) => {
|
|
39
|
+
const full = imageAttributes(it.asset, { alt: it.alt }, { ...opts, sizes: "100vw" });
|
|
40
|
+
const thumb = imgHtml(
|
|
41
|
+
imageAttributes(it.asset, { alt: it.alt }, { ...opts, sizes: "12rem" }),
|
|
42
|
+
);
|
|
43
|
+
return `<li><a class="ch-lightbox__thumb" href="${escapeHtml(full.src)}" data-ch-lightbox="${id}" data-index="${i}">${thumb}</a></li>`;
|
|
44
|
+
})
|
|
45
|
+
.join("");
|
|
46
|
+
const figures = items
|
|
47
|
+
.map((it, i) => {
|
|
48
|
+
const img = imgHtml(
|
|
49
|
+
imageAttributes(it.asset, { alt: it.alt }, { ...opts, sizes: "100vw", fit: "blur-fill" }),
|
|
50
|
+
);
|
|
51
|
+
return `<figure class="ch-lightbox__item" data-index="${i}"${i === start ? "" : " hidden"}>${img}${it.caption ? `<figcaption>${escapeHtml(it.caption)}</figcaption>` : ""}</figure>`;
|
|
52
|
+
})
|
|
53
|
+
.join("");
|
|
54
|
+
const nav =
|
|
55
|
+
items.length > 1
|
|
56
|
+
? `<div class="ch-lightbox__nav"><button type="button" class="ch-lightbox__prev" command="--prev" commandfor="${id}" aria-label="${tr ? "Önceki" : "Previous"}">${iconOf("chevron-left", media)}</button><button type="button" class="ch-lightbox__next" command="--next" commandfor="${id}" aria-label="${tr ? "Sonraki" : "Next"}">${iconOf("chevron-right", media)}</button></div>`
|
|
57
|
+
: "";
|
|
58
|
+
return `<div class="ch-lightbox"><ul class="ch-lightbox__grid" aria-label="${escapeHtml(title)}">${thumbs}</ul><dialog id="${id}" class="ch-dialog ch-lightbox__dialog" closedby="any" aria-label="${escapeHtml(title)}"><header class="ch-dialog__head"><span class="ch-lightbox__count" aria-live="polite">${start + 1} / ${items.length}</span>${closeButton(id, tr, media)}</header><div class="ch-lightbox__stage">${figures}</div>${nav}</dialog></div>`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Dialog and Drawer: a modal `<dialog>` with a title and a close button. */
|
|
62
|
+
export const dialogHtml = (node, { id, media }) => {
|
|
63
|
+
const p = node.props;
|
|
64
|
+
const tr = (media?.locale ?? "en").startsWith("tr");
|
|
65
|
+
const closedby = { any: "any", closerequest: "closerequest", explicit: "none" }[
|
|
66
|
+
str(p.dismiss)
|
|
67
|
+
];
|
|
68
|
+
const drawer = node.component === "Drawer";
|
|
69
|
+
return `<dialog id="${id}" class="ch-dialog${drawer ? " ch-drawer" : ""}"${attr("size", p.size, ["s", "m", "l"])}${drawer ? attr("placement", p.placement ?? "end", ["start", "end", "bottom"]) : ""} closedby="${closedby ?? "any"}" aria-labelledby="${id}-title"><header class="ch-dialog__head"><h2 class="ch-dialog__title" id="${id}-title">${escapeHtml(str(p.title))}</h2>${closeButton(id, tr, media)}</header><div class="ch-dialog__body">${CHILDREN}</div></dialog>`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const popoverHtml = ({ props: p }, { id }) =>
|
|
73
|
+
`<div popover="auto" id="${id}" class="ch-popover"${attr("placement", p.placement ?? "bottom", ["bottom", "top", "start", "end"])}${attr("width", p.width, ["s", "m", "l"])}>${CHILDREN}</div>`;
|
|
74
|
+
|
|
75
|
+
export const tooltipHtml = ({ props: p }, { id }) =>
|
|
76
|
+
`<div popover="hint" id="${id}" class="ch-tooltip" role="tooltip">${escapeHtml(str(p.text))}</div>`;
|
|
77
|
+
|
|
78
|
+
export const lightboxNodeHtml = ({ props: p }, { id, media }) =>
|
|
79
|
+
lightboxHtml(id, p, media);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A surface as a tree to draw (RFC-0020 §1–§3): bindings and named functions applied, visibility
|
|
3
|
+
* evaluated against the initial data, entry sources loaded; unknown and hidden components left
|
|
4
|
+
* out. Worker-safe.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentEntry, SurfaceSection } from "@cloudhal/core-contracts";
|
|
7
|
+
import type { BlockRegistry } from "@cloudhal/core-ts/blocks";
|
|
8
|
+
import { type CatalogEntry } from "@cloudhal/core-ts/surfaces";
|
|
9
|
+
import type { MediaContext } from "../media.js";
|
|
10
|
+
/** One component of a surface, ready to draw. */
|
|
11
|
+
export interface SurfaceNode {
|
|
12
|
+
id: string;
|
|
13
|
+
component: string;
|
|
14
|
+
entry: CatalogEntry;
|
|
15
|
+
/** Props with bindings and functions resolved against the surface's data. */
|
|
16
|
+
props: Record<string, unknown>;
|
|
17
|
+
/** The props as written (bindings kept), for the interaction runtime's attributes. */
|
|
18
|
+
raw: Record<string, unknown>;
|
|
19
|
+
/** In a live surface: the node's visibility condition, and whether it starts hidden. */
|
|
20
|
+
visible?: unknown;
|
|
21
|
+
hidden?: boolean;
|
|
22
|
+
/** The surface loads the interaction runtime (RFC-0020 §4). */
|
|
23
|
+
live?: boolean;
|
|
24
|
+
/** RFC-0024: the node's motion as `data-ch-*` attributes for its outer element (or ""). */
|
|
25
|
+
motion?: string;
|
|
26
|
+
/** RFC-0024 24c: a Heading or Text revealed piece by piece. */
|
|
27
|
+
split?: "words" | "chars" | "lines";
|
|
28
|
+
/**
|
|
29
|
+
* RFC-0025 §3: the overlay a Button opens or closes (its component, and a Dialog's fallback
|
|
30
|
+
* page), and the tooltip a Button or Link shows (component ids).
|
|
31
|
+
*/
|
|
32
|
+
overlay?: {
|
|
33
|
+
target: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
fallback?: string;
|
|
36
|
+
};
|
|
37
|
+
tip?: string;
|
|
38
|
+
/** RFC-0027: on a hero carousel's first slide, its images load first (not lazy). */
|
|
39
|
+
priority?: boolean;
|
|
40
|
+
children: SurfaceNode[];
|
|
41
|
+
}
|
|
42
|
+
export interface SurfaceTree {
|
|
43
|
+
section: SurfaceSection;
|
|
44
|
+
/** `undefined` when the surface has no root yet (still arriving) or the root is hidden. */
|
|
45
|
+
root: SurfaceNode | undefined;
|
|
46
|
+
/** It has inputs or button actions: the page carries its data and the interaction runtime. */
|
|
47
|
+
live: boolean;
|
|
48
|
+
/** Ids of components the catalog does not know: kept, not drawn (a preview labels them). */
|
|
49
|
+
unknown: string[];
|
|
50
|
+
data: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/** What an entry looks like inside a surface's data (`$source: "entries"`, RFC-0020 §3). */
|
|
53
|
+
export interface SurfaceEntryCard {
|
|
54
|
+
id: string;
|
|
55
|
+
href: string;
|
|
56
|
+
title: string;
|
|
57
|
+
summary?: string;
|
|
58
|
+
published?: string;
|
|
59
|
+
collection: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function surfaceEntryCard(e: ContentEntry): SurfaceEntryCard;
|
|
62
|
+
/** The entry queries in a surface's data, by data key (`$source: "entries"`). */
|
|
63
|
+
export declare function surfaceSources(section: SurfaceSection): {
|
|
64
|
+
key: string;
|
|
65
|
+
collection: string;
|
|
66
|
+
filter?: string;
|
|
67
|
+
sort: string;
|
|
68
|
+
limit: number;
|
|
69
|
+
}[];
|
|
70
|
+
/** Sorts and trims a source's entries the way the query asks. */
|
|
71
|
+
export declare function pickEntries(entries: readonly ContentEntry[], q: {
|
|
72
|
+
sort: string;
|
|
73
|
+
limit: number;
|
|
74
|
+
}): SurfaceEntryCard[];
|
|
75
|
+
export interface SurfaceContext {
|
|
76
|
+
readonly media?: MediaContext | undefined;
|
|
77
|
+
/** The deployment's registry; defaults to `media.blocks`, else the built-ins. */
|
|
78
|
+
readonly registry?: BlockRegistry | undefined;
|
|
79
|
+
/** Entry sources already loaded by the page, by data key (`surfaceSources`). */
|
|
80
|
+
readonly sources?: Readonly<Record<string, readonly SurfaceEntryCard[]>> | undefined;
|
|
81
|
+
readonly preview?: boolean | undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What keeps a surface from drawing, as "path message" lines (fence problems first): a preview
|
|
85
|
+
* shows them where an invalid ```surface would otherwise draw nothing.
|
|
86
|
+
*/
|
|
87
|
+
export declare function surfaceProblems(section: SurfaceSection, fenceIssues?: readonly {
|
|
88
|
+
path: string;
|
|
89
|
+
message: string;
|
|
90
|
+
}[], registry?: BlockRegistry): string[];
|
|
91
|
+
/**
|
|
92
|
+
* The surface as a tree to draw: unknown, unreachable and hidden components are left out, props
|
|
93
|
+
* resolved against the data with the page's entry sources in place of their queries.
|
|
94
|
+
*/
|
|
95
|
+
export declare function surfaceTree(section: SurfaceSection, ctx?: SurfaceContext): SurfaceTree;
|
|
96
|
+
/** What a page's source offers for entry sources (`GraphSource`). */
|
|
97
|
+
export interface SurfaceEntrySource {
|
|
98
|
+
entries(collection: string): Promise<ContentEntry[]>;
|
|
99
|
+
entriesByFilter(filter: string): Promise<ContentEntry[]>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Loads every entry source of the page's surfaces, by section id then data key. A filter that no
|
|
103
|
+
* longer parses (a term was removed) lists nothing rather than failing the page.
|
|
104
|
+
*/
|
|
105
|
+
export declare function loadSurfaceSources(source: SurfaceEntrySource, sections: readonly {
|
|
106
|
+
kind: string;
|
|
107
|
+
}[]): Promise<Record<string, Record<string, SurfaceEntryCard[]>>>;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A surface as a tree to draw (RFC-0020 §1–§3): bindings and named functions applied, visibility
|
|
3
|
+
* evaluated against the initial data, entry sources loaded; unknown and hidden components left
|
|
4
|
+
* out. Worker-safe.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
checkSurface,
|
|
12
|
+
createCatalog,
|
|
13
|
+
evaluateCondition,
|
|
14
|
+
isInteractive,
|
|
15
|
+
MOTION_STAGGER,
|
|
16
|
+
OVERLAY_COMPONENTS,
|
|
17
|
+
resolveProps,
|
|
18
|
+
} from "@cloudhal/core-ts/surfaces";
|
|
19
|
+
|
|
20
|
+
import { motionAttrs } from "./motion.js";
|
|
21
|
+
|
|
22
|
+
/** One component of a surface, ready to draw. */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/** What an entry looks like inside a surface's data (`$source: "entries"`, RFC-0020 §3). */
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export function surfaceEntryCard(e ) {
|
|
73
|
+
return {
|
|
74
|
+
id: e.id,
|
|
75
|
+
href: `/${e.collection}/${e.slug}`,
|
|
76
|
+
title: e.title,
|
|
77
|
+
collection: e.collection,
|
|
78
|
+
...(e.summary ? { summary: e.summary } : {}),
|
|
79
|
+
...(e.publishedAt ? { published: e.publishedAt } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The entry queries in a surface's data, by data key (`$source: "entries"`). */
|
|
84
|
+
export function surfaceSources(
|
|
85
|
+
section ,
|
|
86
|
+
) {
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const [key, v] of Object.entries(section.data ?? {})) {
|
|
89
|
+
if (typeof v !== "object" || v === null || (v ).$source !== "entries")
|
|
90
|
+
continue;
|
|
91
|
+
const q = (v ).query ?? {};
|
|
92
|
+
out.push({
|
|
93
|
+
key,
|
|
94
|
+
collection: String(q.collection ?? "posts"),
|
|
95
|
+
...(typeof q.filter === "string" ? { filter: q.filter } : {}),
|
|
96
|
+
sort: typeof q.sort === "string" ? q.sort : "newest",
|
|
97
|
+
limit: Math.min(Math.max(Number(q.limit) || 10, 1), 50),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Sorts and trims a source's entries the way the query asks. */
|
|
104
|
+
export function pickEntries(
|
|
105
|
+
entries ,
|
|
106
|
+
q ,
|
|
107
|
+
) {
|
|
108
|
+
const at = (e ) => e.publishedAt ?? e.createdAt;
|
|
109
|
+
// The page's source already holds only what this response may show (published, or the draft
|
|
110
|
+
// in a preview), so no status filter here.
|
|
111
|
+
return [...entries]
|
|
112
|
+
.sort((a, b) =>
|
|
113
|
+
q.sort === "title"
|
|
114
|
+
? a.title.localeCompare(b.title)
|
|
115
|
+
: q.sort === "oldest"
|
|
116
|
+
? at(a).localeCompare(at(b))
|
|
117
|
+
: at(b).localeCompare(at(a)),
|
|
118
|
+
)
|
|
119
|
+
.slice(0, q.limit)
|
|
120
|
+
.map(surfaceEntryCard);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const catalogs = new WeakMap ();
|
|
133
|
+
const defaultCatalog = createCatalog();
|
|
134
|
+
/**
|
|
135
|
+
* What keeps a surface from drawing, as "path message" lines (fence problems first): a preview
|
|
136
|
+
* shows them where an invalid ```surface would otherwise draw nothing.
|
|
137
|
+
*/
|
|
138
|
+
export function surfaceProblems(
|
|
139
|
+
section ,
|
|
140
|
+
fenceIssues = [],
|
|
141
|
+
registry ,
|
|
142
|
+
) {
|
|
143
|
+
const check = checkSurface(section, catalogFor(registry));
|
|
144
|
+
return [...fenceIssues, ...check.issues]
|
|
145
|
+
.map((i) => `${i.path} ${i.message}`)
|
|
146
|
+
.concat(check.unknown.map((id) => `/components/${id} unknown component`));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function catalogFor(registry ) {
|
|
150
|
+
if (!registry) return defaultCatalog;
|
|
151
|
+
let c = catalogs.get(registry);
|
|
152
|
+
if (!c) {
|
|
153
|
+
c = createCatalog({ blocks: registry });
|
|
154
|
+
catalogs.set(registry, c);
|
|
155
|
+
}
|
|
156
|
+
return c;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The surface as a tree to draw: unknown, unreachable and hidden components are left out, props
|
|
161
|
+
* resolved against the data with the page's entry sources in place of their queries.
|
|
162
|
+
*/
|
|
163
|
+
export function surfaceTree(section , ctx = {}) {
|
|
164
|
+
const catalog = catalogFor(ctx.registry ?? ctx.media?.blocks);
|
|
165
|
+
const check = checkSurface(section, catalog);
|
|
166
|
+
const data = { ...(section.data ?? {}) };
|
|
167
|
+
for (const s of surfaceSources(section)) data[s.key] = ctx.sources?.[s.key] ?? [];
|
|
168
|
+
const locale = ctx.media?.locale ?? "en";
|
|
169
|
+
const byId = new Map(section.components.map((c) => [c.id, c]));
|
|
170
|
+
const unknown = new Set(check.unknown);
|
|
171
|
+
const live = isInteractive(section);
|
|
172
|
+
// A surface with structural problems (a stored one never has them) draws nothing.
|
|
173
|
+
// A component's motion that does not check is left out; the component still draws.
|
|
174
|
+
const issues = check.issues.filter((i) => !i.path.includes("/motion"));
|
|
175
|
+
if (issues.some((i) => !i.path.includes("/props/") && !i.path.includes("/visible")))
|
|
176
|
+
return { section, root: undefined, unknown: check.unknown, data, live: false };
|
|
177
|
+
const invalidProps = new Set(
|
|
178
|
+
issues.map((i) => /^\/components\/(\d+)\//.exec(i.path)?.[1]).filter(Boolean),
|
|
179
|
+
);
|
|
180
|
+
const badMotion = new Set(
|
|
181
|
+
check.issues
|
|
182
|
+
.filter((i) => i.path.includes("/motion"))
|
|
183
|
+
.map((i) => /^\/components\/(\d+)\//.exec(i.path)?.[1]),
|
|
184
|
+
);
|
|
185
|
+
// RFC-0025 §3: tooltips by the component they describe.
|
|
186
|
+
const tips = new Map ();
|
|
187
|
+
for (const c of section.components)
|
|
188
|
+
if (c.component === "Tooltip" && typeof c.props?.for === "string") tips.set(c.props.for, c.id);
|
|
189
|
+
// What a parent hands its child: a staggered reveal, the overlay it sits in, image priority.
|
|
190
|
+
const node = (
|
|
191
|
+
id ,
|
|
192
|
+
depth ,
|
|
193
|
+
from
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
= {},
|
|
198
|
+
) => {
|
|
199
|
+
const { stagger, within, priority } = from;
|
|
200
|
+
const c = byId.get(id);
|
|
201
|
+
if (!c || unknown.has(id) || depth > 8) return undefined;
|
|
202
|
+
const index = section.components.indexOf(c);
|
|
203
|
+
if (invalidProps.has(String(index))) return undefined;
|
|
204
|
+
// A live surface keeps hidden components (the runtime shows them when their condition holds).
|
|
205
|
+
const shown = evaluateCondition(c.visible, data);
|
|
206
|
+
if (!shown && !live) return undefined;
|
|
207
|
+
const entry = catalog.get(c.component);
|
|
208
|
+
if (!entry) return undefined;
|
|
209
|
+
const motion = badMotion.has(String(index))
|
|
210
|
+
? undefined
|
|
211
|
+
: (c.motion );
|
|
212
|
+
// RFC-0024 §2: a staggered parent hands its reveal to its children, each a step later.
|
|
213
|
+
const staggers =
|
|
214
|
+
motion?.stagger === true && (MOTION_STAGGER ).includes(c.component);
|
|
215
|
+
let i = 0;
|
|
216
|
+
const inside = OVERLAY_COMPONENTS.has(c.component) && c.component !== "Tooltip" ? id : within;
|
|
217
|
+
const children = (c.children ?? [])
|
|
218
|
+
.map((k) =>
|
|
219
|
+
node(k, depth + 1, {
|
|
220
|
+
stagger: staggers
|
|
221
|
+
? { reveal: motion?.reveal ?? "rise", index: Math.min(i++, 12) }
|
|
222
|
+
: undefined,
|
|
223
|
+
within: inside,
|
|
224
|
+
// RFC-0027: a hero carousel's first slide is what the reader sees first.
|
|
225
|
+
priority:
|
|
226
|
+
priority ||
|
|
227
|
+
(c.component === "Carousel" && c.props?.variant === "hero" && k === c.children?.[0]),
|
|
228
|
+
}),
|
|
229
|
+
)
|
|
230
|
+
.filter((n) => n !== undefined);
|
|
231
|
+
const attrs = motionAttrs(staggers ? { ...motion, reveal: undefined } : motion, stagger);
|
|
232
|
+
const reveal = motion?.reveal;
|
|
233
|
+
const split =
|
|
234
|
+
typeof reveal === "string" &&
|
|
235
|
+
reveal.startsWith("split-") &&
|
|
236
|
+
(c.component === "Heading" || c.component === "Text") &&
|
|
237
|
+
typeof c.props?.text === "string"
|
|
238
|
+
? (reveal.slice(6) )
|
|
239
|
+
: undefined;
|
|
240
|
+
// RFC-0025 §3: what a Button opens or closes (a close without target closes its own overlay).
|
|
241
|
+
const click =
|
|
242
|
+
c.component === "Button"
|
|
243
|
+
? (c.props?.onClick )
|
|
244
|
+
: undefined;
|
|
245
|
+
const target =
|
|
246
|
+
click?.action === "open" || click?.action === "close"
|
|
247
|
+
? typeof click.target === "string"
|
|
248
|
+
? click.target
|
|
249
|
+
: click.action === "close"
|
|
250
|
+
? within
|
|
251
|
+
: undefined
|
|
252
|
+
: undefined;
|
|
253
|
+
const targetC = target ? byId.get(target) : undefined;
|
|
254
|
+
const fallback = targetC?.component === "Dialog" ? targetC.props?.fallbackHref : undefined;
|
|
255
|
+
const overlay = targetC
|
|
256
|
+
? {
|
|
257
|
+
target: targetC.id,
|
|
258
|
+
kind: targetC.component,
|
|
259
|
+
...(typeof fallback === "string" ? { fallback } : {}),
|
|
260
|
+
}
|
|
261
|
+
: undefined;
|
|
262
|
+
const tip = c.component === "Button" || c.component === "Link" ? tips.get(id) : undefined;
|
|
263
|
+
return {
|
|
264
|
+
id,
|
|
265
|
+
component: c.component,
|
|
266
|
+
entry,
|
|
267
|
+
...(overlay ? { overlay } : {}),
|
|
268
|
+
...(tip ? { tip } : {}),
|
|
269
|
+
...(priority ? { priority: true } : {}),
|
|
270
|
+
props: resolveProps(c.props, data, { locale }),
|
|
271
|
+
raw: { ...(c.props ?? {}) },
|
|
272
|
+
...(live ? { live: true } : {}),
|
|
273
|
+
...(live && c.visible !== undefined ? { visible: c.visible, hidden: !shown } : {}),
|
|
274
|
+
...(attrs ? { motion: attrs } : {}),
|
|
275
|
+
...(split ? { split } : {}),
|
|
276
|
+
children,
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
const root = node("root", 1);
|
|
280
|
+
// RFC-0028 §3: a gallery's images show whole, their sides filled with themselves blurred.
|
|
281
|
+
const galleryFit = (n , inGallery ) => {
|
|
282
|
+
if (inGallery && n.component === "Image" && n.props.fit === undefined)
|
|
283
|
+
n.props = { ...n.props, fit: "blur-fill" };
|
|
284
|
+
const g = inGallery || (n.component === "Carousel" && n.props.variant === "gallery");
|
|
285
|
+
for (const k of n.children) galleryFit(k, g);
|
|
286
|
+
};
|
|
287
|
+
if (root) galleryFit(root, false);
|
|
288
|
+
return { section, root, unknown: check.unknown, data, live };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** What a page's source offers for entry sources (`GraphSource`). */
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Loads every entry source of the page's surfaces, by section id then data key. A filter that no
|
|
299
|
+
* longer parses (a term was removed) lists nothing rather than failing the page.
|
|
300
|
+
*/
|
|
301
|
+
export async function loadSurfaceSources(
|
|
302
|
+
source ,
|
|
303
|
+
sections ,
|
|
304
|
+
) {
|
|
305
|
+
const out = {};
|
|
306
|
+
for (const s of sections) {
|
|
307
|
+
if (s.kind !== "surface") continue;
|
|
308
|
+
const section = s ;
|
|
309
|
+
const loaded = {};
|
|
310
|
+
for (const q of surfaceSources(section)) {
|
|
311
|
+
const list = q.filter
|
|
312
|
+
? await source
|
|
313
|
+
.entriesByFilter(`collection:${q.collection}+${q.filter}`)
|
|
314
|
+
.catch(() => [] )
|
|
315
|
+
: await source.entries(q.collection);
|
|
316
|
+
loaded[q.key] = pickEntries(list, q);
|
|
317
|
+
}
|
|
318
|
+
out[section.id] = loaded;
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surfaces on the page (RFC-0020 §1–§4): a surface section becomes a resolved tree (bindings and
|
|
3
|
+
* named functions applied, visibility evaluated against the initial data, entry sources loaded),
|
|
4
|
+
* then HTML. `renderSurface` gives framework-free markup for previews and themes without their
|
|
5
|
+
* own components; `Surface.astro` walks the same tree so a theme can draw any component itself.
|
|
6
|
+
* Every value reaches the page escaped; nothing a model wrote is executed. Worker-safe.
|
|
7
|
+
*
|
|
8
|
+
* The public `@cloudhal/astro-renderer/surfaces` path: named re-exports of `./surfaces/*` only.
|
|
9
|
+
*/
|
|
10
|
+
export { blockNodeHtml, renderSurface, slideWrapper, surfaceScope, surfaceWrapper, visibilityWrapper, } from "./surfaces/html.js";
|
|
11
|
+
export { CHILDREN } from "./surfaces/markup.js";
|
|
12
|
+
export { motionAttrs, splitHtml, withMotion } from "./surfaces/motion.js";
|
|
13
|
+
export { primitiveHtml } from "./surfaces/primitives/index.js";
|
|
14
|
+
export { loadSurfaceSources, pickEntries, type SurfaceContext, type SurfaceEntryCard, type SurfaceEntrySource, type SurfaceNode, type SurfaceTree, surfaceEntryCard, surfaceProblems, surfaceSources, surfaceTree, } from "./surfaces/tree.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surfaces on the page (RFC-0020 §1–§4): a surface section becomes a resolved tree (bindings and
|
|
3
|
+
* named functions applied, visibility evaluated against the initial data, entry sources loaded),
|
|
4
|
+
* then HTML. `renderSurface` gives framework-free markup for previews and themes without their
|
|
5
|
+
* own components; `Surface.astro` walks the same tree so a theme can draw any component itself.
|
|
6
|
+
* Every value reaches the page escaped; nothing a model wrote is executed. Worker-safe.
|
|
7
|
+
*
|
|
8
|
+
* The public `@cloudhal/astro-renderer/surfaces` path: named re-exports of `./surfaces/*` only.
|
|
9
|
+
*/
|
|
10
|
+
export {
|
|
11
|
+
blockNodeHtml,
|
|
12
|
+
renderSurface,
|
|
13
|
+
slideWrapper,
|
|
14
|
+
surfaceScope,
|
|
15
|
+
surfaceWrapper,
|
|
16
|
+
visibilityWrapper,
|
|
17
|
+
} from "./surfaces/html.js";
|
|
18
|
+
export { CHILDREN } from "./surfaces/markup.js";
|
|
19
|
+
export { motionAttrs, splitHtml, withMotion } from "./surfaces/motion.js";
|
|
20
|
+
export { primitiveHtml } from "./surfaces/primitives/index.js";
|
|
21
|
+
export {
|
|
22
|
+
loadSurfaceSources,
|
|
23
|
+
pickEntries,
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
surfaceEntryCard,
|
|
30
|
+
surfaceProblems,
|
|
31
|
+
surfaceSources,
|
|
32
|
+
surfaceTree,
|
|
33
|
+
} from "./surfaces/tree.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Taxonomy as the public site shows it (RFC-0002 §7): which terms an entry displays, their names in
|
|
3
|
+
* the entry's locale, archive links, breadcrumbs, related posts and archive membership. Pure
|
|
4
|
+
* functions over graph nodes, so heads, feeds, sitemaps and themes agree on one set of rules:
|
|
5
|
+
*
|
|
6
|
+
* - only `active` + `public` terms are shown or linked (proposed and internal terms never are);
|
|
7
|
+
* - names come from the term's label in the locale (`termName`, default-locale fallback);
|
|
8
|
+
* - entries written before the tags → terms migration still show their deprecated `tags`.
|
|
9
|
+
*/
|
|
10
|
+
import type { ContentEntry, Taxonomy, Term } from "@cloudhal/core-contracts";
|
|
11
|
+
import type { GraphSource } from "./source.js";
|
|
12
|
+
/** Everything needed to show terms: the site's taxonomies and every term, by id. */
|
|
13
|
+
export interface TaxonomyIndex {
|
|
14
|
+
readonly locale: string;
|
|
15
|
+
/** The site's default locale, whose archive slugs are the terms' own (RFC-0033). */
|
|
16
|
+
readonly defaultLocale?: string;
|
|
17
|
+
/** In display order: the section taxonomy (categories) first, then the others by key. */
|
|
18
|
+
readonly taxonomies: readonly Taxonomy[];
|
|
19
|
+
readonly byKey: ReadonlyMap<string, Taxonomy>;
|
|
20
|
+
readonly byId: ReadonlyMap<string, Taxonomy>;
|
|
21
|
+
/** Every term of the site in any status, by id. */
|
|
22
|
+
readonly terms: ReadonlyMap<string, Term>;
|
|
23
|
+
}
|
|
24
|
+
export declare function taxonomyIndex(taxonomies: readonly Taxonomy[], terms: readonly Term[], locale: string, defaultLocale?: string): TaxonomyIndex;
|
|
25
|
+
/** Loads the index from a source, in `locale` (default: the site's). */
|
|
26
|
+
export declare function loadTaxonomyIndex(source: GraphSource, locale?: string): Promise<TaxonomyIndex>;
|
|
27
|
+
export declare function sectionTaxonomy(index: TaxonomyIndex): Taxonomy | undefined;
|
|
28
|
+
/** Shown on the public site: active and public (RFC-0002 invariant 11). */
|
|
29
|
+
export declare function isPublicTerm(term: Pick<Term, "status" | "visibility">): boolean;
|
|
30
|
+
/** `/<basePath>/<slug>`. */
|
|
31
|
+
export declare function archivePath(taxonomy: Pick<Taxonomy, "archive">, slug: string): string;
|
|
32
|
+
/** Page `n` of an archive: the root for page 1, `<root>/page/<n>` after it. */
|
|
33
|
+
export declare function archivePagePath(root: string, page: number): string;
|
|
34
|
+
/** `<archive>/rss.xml`. */
|
|
35
|
+
export declare function archiveFeedPath(root: string): string;
|
|
36
|
+
/** A term as the site shows it. */
|
|
37
|
+
export interface ShownTerm {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly slug: string;
|
|
40
|
+
/** Label in the index locale (default-locale fallback). */
|
|
41
|
+
readonly name: string;
|
|
42
|
+
/** The archive URL path, when the taxonomy publishes archives. */
|
|
43
|
+
readonly href?: string;
|
|
44
|
+
readonly taxonomy: Taxonomy;
|
|
45
|
+
readonly term: Term;
|
|
46
|
+
}
|
|
47
|
+
export declare function shownTerm(index: TaxonomyIndex, term: Term): ShownTerm | undefined;
|
|
48
|
+
/** Ancestors of a term, root first (any status; cycles and dangling parents end the walk). */
|
|
49
|
+
export declare function termAncestors(index: TaxonomyIndex, term: Term): Term[];
|
|
50
|
+
/** The public ancestors of a term as breadcrumb items, root first. */
|
|
51
|
+
export declare function publicTrail(index: TaxonomyIndex, term: Term): ShownTerm[];
|
|
52
|
+
/** The terms one entry shows. */
|
|
53
|
+
export interface EntryTaxonomy {
|
|
54
|
+
/** Public terms per taxonomy, in assignment order; taxonomies without shown terms are left out. */
|
|
55
|
+
readonly groups: ReadonlyArray<{
|
|
56
|
+
readonly taxonomy: Taxonomy;
|
|
57
|
+
readonly terms: ShownTerm[];
|
|
58
|
+
}>;
|
|
59
|
+
/** The primary term of the section taxonomy (categories), when public. */
|
|
60
|
+
readonly section?: ShownTerm;
|
|
61
|
+
/** Breadcrumb: the section's public ancestors, then the section. */
|
|
62
|
+
readonly trail: ShownTerm[];
|
|
63
|
+
/** Public `tag` terms. */
|
|
64
|
+
readonly tags: ShownTerm[];
|
|
65
|
+
/** The byline (RFC-0019 §1): public `author` terms, the primary author first. */
|
|
66
|
+
readonly authors: ShownTerm[];
|
|
67
|
+
/**
|
|
68
|
+
* Keyword names (`article:tag`, JSON-LD `keywords`, RSS categories): the names of `tags`, or the
|
|
69
|
+
* deprecated `ContentEntry.tags` slugs for an entry that has no `terms.tag` yet (un-migrated).
|
|
70
|
+
*/
|
|
71
|
+
readonly keywords: string[];
|
|
72
|
+
}
|
|
73
|
+
export declare function entryTaxonomy(index: TaxonomyIndex | undefined, entry: Pick<ContentEntry, "tags" | "terms">): EntryTaxonomy;
|
|
74
|
+
/** Term ids an entry belongs to for archives: its assignments plus, in hierarchical taxonomies, their ancestors. */
|
|
75
|
+
export declare function archiveTermIds(index: TaxonomyIndex, entry: Pick<ContentEntry, "terms">): Set<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Archive membership in one pass: term id → the entries its archive lists (category archives
|
|
78
|
+
* include their sub-categories' entries, RFC-0002 answer 9), in the order given (newest first).
|
|
79
|
+
*/
|
|
80
|
+
export declare function archiveMembers(index: TaxonomyIndex, entries: readonly ContentEntry[]): Map<string, ContentEntry[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Up to `limit` published entries related to `entry`: sharing its primary category scores 2,
|
|
83
|
+
* every other shared term (or legacy tag) 1. Highest score first, then newest; never the entry
|
|
84
|
+
* itself, never another locale, never zero-score entries.
|
|
85
|
+
*/
|
|
86
|
+
export declare function relatedEntries(entry: ContentEntry, candidates: readonly ContentEntry[], index: TaxonomyIndex | undefined, limit?: number): ContentEntry[];
|