@cloudhal/astro-renderer 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +36 -2
  3. package/dist/src/ambient-client.d.ts +17 -0
  4. package/dist/src/ambient-client.js +55 -0
  5. package/dist/src/analytics-client.d.ts +17 -0
  6. package/dist/src/analytics-client.js +96 -0
  7. package/dist/src/analytics-middleware.d.ts +6 -0
  8. package/dist/src/analytics-middleware.js +43 -0
  9. package/dist/src/analytics-node.d.ts +46 -0
  10. package/dist/src/analytics-node.js +134 -0
  11. package/dist/src/analytics.d.ts +117 -0
  12. package/dist/src/analytics.js +372 -0
  13. package/dist/src/archive.d.ts +106 -0
  14. package/dist/src/archive.js +207 -0
  15. package/dist/src/astro-env.d.ts +21 -0
  16. package/dist/src/block-html.d.ts +14 -0
  17. package/dist/src/block-html.js +103 -0
  18. package/dist/src/blocks.d.ts +24 -0
  19. package/dist/src/blocks.js +66 -0
  20. package/dist/src/cache-tags.d.ts +25 -0
  21. package/dist/src/cache-tags.js +59 -0
  22. package/dist/src/carousel-client.d.ts +28 -0
  23. package/dist/src/carousel-client.js +67 -0
  24. package/dist/src/chart.d.ts +34 -0
  25. package/dist/src/chart.js +182 -0
  26. package/dist/src/chrome-client.d.ts +27 -0
  27. package/dist/src/chrome-client.js +64 -0
  28. package/dist/src/cloudflare-entry.d.ts +87 -0
  29. package/dist/src/cloudflare-entry.js +548 -0
  30. package/dist/src/comments-client.d.ts +11 -0
  31. package/dist/src/comments-client.js +58 -0
  32. package/dist/src/comments-html.d.ts +42 -0
  33. package/dist/src/comments-html.js +303 -0
  34. package/dist/src/comments-middleware.d.ts +6 -0
  35. package/dist/src/comments-middleware.js +38 -0
  36. package/dist/src/comments-node.d.ts +42 -0
  37. package/dist/src/comments-node.js +112 -0
  38. package/dist/src/comments-view.d.ts +68 -0
  39. package/dist/src/comments-view.js +174 -0
  40. package/dist/src/comments.d.ts +66 -0
  41. package/dist/src/comments.js +258 -0
  42. package/dist/src/components/Block.astro +39 -0
  43. package/dist/src/components/Body.astro +43 -0
  44. package/dist/src/components/Comments.astro +19 -0
  45. package/dist/src/components/ContentList.astro +31 -0
  46. package/dist/src/components/EntryArticle.astro +31 -0
  47. package/dist/src/components/Hero.astro +36 -0
  48. package/dist/src/components/Image.astro +36 -0
  49. package/dist/src/components/RichText.astro +19 -0
  50. package/dist/src/components/Sections.astro +66 -0
  51. package/dist/src/components/SeoHead.astro +22 -0
  52. package/dist/src/components/Surface.astro +36 -0
  53. package/dist/src/components/SurfaceNode.astro +82 -0
  54. package/dist/src/components/index.d.ts +12 -0
  55. package/dist/src/components/index.js +12 -0
  56. package/dist/src/csp.d.ts +20 -0
  57. package/dist/src/csp.js +28 -0
  58. package/dist/src/embed-client.d.ts +38 -0
  59. package/dist/src/embed-client.js +98 -0
  60. package/dist/src/embed-middleware.d.ts +9 -0
  61. package/dist/src/embed-middleware.js +49 -0
  62. package/dist/src/feeds.d.ts +72 -0
  63. package/dist/src/feeds.js +246 -0
  64. package/dist/src/gates.d.ts +25 -0
  65. package/dist/src/gates.js +63 -0
  66. package/dist/src/index.d.ts +17 -0
  67. package/dist/src/index.js +17 -0
  68. package/dist/src/integration.d.ts +55 -0
  69. package/dist/src/integration.js +244 -0
  70. package/dist/src/kit.d.ts +48 -0
  71. package/dist/src/kit.js +83 -0
  72. package/dist/src/locale-feeds.d.ts +29 -0
  73. package/dist/src/locale-feeds.js +152 -0
  74. package/dist/src/locale-middleware.d.ts +5 -0
  75. package/dist/src/locale-middleware.js +26 -0
  76. package/dist/src/locales.d.ts +87 -0
  77. package/dist/src/locales.js +336 -0
  78. package/dist/src/markdown.d.ts +83 -0
  79. package/dist/src/markdown.js +533 -0
  80. package/dist/src/media-middleware.d.ts +5 -0
  81. package/dist/src/media-middleware.js +18 -0
  82. package/dist/src/media-route.d.ts +47 -0
  83. package/dist/src/media-route.js +238 -0
  84. package/dist/src/media.d.ts +109 -0
  85. package/dist/src/media.js +298 -0
  86. package/dist/src/motion-client.d.ts +39 -0
  87. package/dist/src/motion-client.js +115 -0
  88. package/dist/src/navigation.d.ts +127 -0
  89. package/dist/src/navigation.js +382 -0
  90. package/dist/src/not-found.d.ts +16 -0
  91. package/dist/src/not-found.js +41 -0
  92. package/dist/src/overlay-client.d.ts +20 -0
  93. package/dist/src/overlay-client.js +49 -0
  94. package/dist/src/prefs-client.d.ts +14 -0
  95. package/dist/src/prefs-client.js +18 -0
  96. package/dist/src/preview.d.ts +70 -0
  97. package/dist/src/preview.js +551 -0
  98. package/dist/src/resolver.d.ts +71 -0
  99. package/dist/src/resolver.js +206 -0
  100. package/dist/src/routing.d.ts +108 -0
  101. package/dist/src/routing.js +285 -0
  102. package/dist/src/runtime-workerd.d.ts +87 -0
  103. package/dist/src/runtime-workerd.js +275 -0
  104. package/dist/src/runtime.d.ts +59 -0
  105. package/dist/src/runtime.js +153 -0
  106. package/dist/src/safe-urls.d.ts +13 -0
  107. package/dist/src/safe-urls.js +35 -0
  108. package/dist/src/sanitize.d.ts +7 -0
  109. package/dist/src/sanitize.js +217 -0
  110. package/dist/src/search-client.d.ts +29 -0
  111. package/dist/src/search-client.js +92 -0
  112. package/dist/src/search-limit.d.ts +36 -0
  113. package/dist/src/search-limit.js +66 -0
  114. package/dist/src/search.d.ts +64 -0
  115. package/dist/src/search.js +155 -0
  116. package/dist/src/seo.d.ts +85 -0
  117. package/dist/src/seo.js +468 -0
  118. package/dist/src/site-dispatch.d.ts +37 -0
  119. package/dist/src/site-dispatch.js +86 -0
  120. package/dist/src/site-hosts.d.ts +35 -0
  121. package/dist/src/site-hosts.js +110 -0
  122. package/dist/src/source.d.ts +227 -0
  123. package/dist/src/source.js +794 -0
  124. package/dist/src/static-gates.d.ts +3 -0
  125. package/dist/src/static-gates.js +28 -0
  126. package/dist/src/static-headers.d.ts +30 -0
  127. package/dist/src/static-headers.js +140 -0
  128. package/dist/src/static-media.d.ts +4 -0
  129. package/dist/src/static-media.js +65 -0
  130. package/dist/src/static-redirects.d.ts +4 -0
  131. package/dist/src/static-redirects.js +40 -0
  132. package/dist/src/surface-client.d.ts +34 -0
  133. package/dist/src/surface-client.js +146 -0
  134. package/dist/src/surfaces/html.d.ts +35 -0
  135. package/dist/src/surfaces/html.js +184 -0
  136. package/dist/src/surfaces/markup.d.ts +57 -0
  137. package/dist/src/surfaces/markup.js +135 -0
  138. package/dist/src/surfaces/motion.d.ts +33 -0
  139. package/dist/src/surfaces/motion.js +132 -0
  140. package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
  141. package/dist/src/surfaces/primitives/carousel.js +95 -0
  142. package/dist/src/surfaces/primitives/content.d.ts +13 -0
  143. package/dist/src/surfaces/primitives/content.js +159 -0
  144. package/dist/src/surfaces/primitives/data.d.ts +5 -0
  145. package/dist/src/surfaces/primitives/data.js +80 -0
  146. package/dist/src/surfaces/primitives/index.d.ts +54 -0
  147. package/dist/src/surfaces/primitives/index.js +106 -0
  148. package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
  149. package/dist/src/surfaces/primitives/inputs.js +68 -0
  150. package/dist/src/surfaces/primitives/layout.d.ts +14 -0
  151. package/dist/src/surfaces/primitives/layout.js +61 -0
  152. package/dist/src/surfaces/primitives/motion.d.ts +9 -0
  153. package/dist/src/surfaces/primitives/motion.js +45 -0
  154. package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
  155. package/dist/src/surfaces/primitives/overlays.js +79 -0
  156. package/dist/src/surfaces/tree.d.ts +107 -0
  157. package/dist/src/surfaces/tree.js +321 -0
  158. package/dist/src/surfaces.d.ts +14 -0
  159. package/dist/src/surfaces.js +33 -0
  160. package/dist/src/taxonomy.d.ts +86 -0
  161. package/dist/src/taxonomy.js +268 -0
  162. package/dist/src/theme-settings.d.ts +24 -0
  163. package/dist/src/theme-settings.js +111 -0
  164. package/package.json +219 -3
@@ -0,0 +1,336 @@
1
+ /**
2
+ * RFC-0033 §4 / ADR-0035: a site's locales on the web. The locale is in the path
3
+ * (`prefix-except-default`: the default locale at the root, the others under `/<locale>`;
4
+ * `prefix-all`: every locale prefixed) or in the host (`localization.domains`), never in a cookie
5
+ * or `Accept-Language`. This module splits a request into locale and graph path, builds localized
6
+ * URLs, lists a node's language versions for `hreflang`, and rewrites a localized page's internal
7
+ * links to the same locale. Worker-safe.
8
+ */
9
+
10
+ import { termSlug } from "@cloudhal/core-ts";
11
+
12
+
13
+
14
+ /** Scripts written right to left, by primary language subtag (CLDR). */
15
+ const RTL = new Set([
16
+ "ar",
17
+ "arc",
18
+ "ckb",
19
+ "dv",
20
+ "fa",
21
+ "he",
22
+ "ks",
23
+ "ku",
24
+ "ps",
25
+ "sd",
26
+ "syr",
27
+ "ug",
28
+ "ur",
29
+ "yi",
30
+ ]);
31
+
32
+ /** `<html dir>` for a locale. Kurdish written in Latin (`ku-Latn`) is the one exception handled. */
33
+ export function textDirection(locale ) {
34
+ const [language = "", script] = locale.toLowerCase().split("-");
35
+ if (script === "latn" || script === "cyrl") return "ltr";
36
+ return RTL.has(language) ? "rtl" : "ltr";
37
+ }
38
+
39
+
40
+
41
+ export function localeRouting(site ) {
42
+ return site.localization?.routing ?? "prefix-except-default";
43
+ }
44
+
45
+ /** The locale a host serves on its own (`localization.domains`), if any. */
46
+ export function hostLocale(site , host ) {
47
+ const bare = host.toLowerCase().replace(/:\d+$/, "");
48
+ const domains = site.localization?.domains ?? {};
49
+ return Object.keys(domains).find((l) => domains[l]?.toLowerCase() === bare);
50
+ }
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ /**
62
+ * Splits a request path (no trailing slash, `/` for the root) into locale and graph path. A
63
+ * default-locale prefix under `prefix-except-default` and an unprefixed path under `prefix-all`
64
+ * redirect to the canonical URL; a locale served by its own domain is never a prefix.
65
+ */
66
+ export function localeRequest(site , host , path ) {
67
+ const own = hostLocale(site, host);
68
+ if (own) return { locale: own, path };
69
+ const segment = path.split("/")[1] ?? "";
70
+ const domains = site.localization?.domains ?? {};
71
+ const locale = site.locales.find(
72
+ (l) => l.toLowerCase() === segment.toLowerCase() && domains[l] === undefined,
73
+ );
74
+ const routing = localeRouting(site);
75
+ if (locale && segment) {
76
+ const rest = path.slice(segment.length + 1) || "/";
77
+ if (locale === site.defaultLocale && routing === "prefix-except-default")
78
+ return { locale, path: rest, redirect: rest };
79
+ if (segment !== locale)
80
+ return { locale, path: rest, redirect: localizedPath(site, locale, rest) };
81
+ return { locale, path: rest };
82
+ }
83
+ if (routing === "prefix-all")
84
+ return {
85
+ locale: site.defaultLocale,
86
+ path,
87
+ redirect: localizedPath(site, site.defaultLocale, path),
88
+ };
89
+ return { locale: site.defaultLocale, path };
90
+ }
91
+
92
+ /** A graph path as a URL path of `locale` on the site's own host (no domain mapping). */
93
+ export function localizedPath(site , locale , path ) {
94
+ const prefixed = localeRouting(site) === "prefix-all" || locale !== site.defaultLocale;
95
+ if (!prefixed) return path;
96
+ return path === "/" ? `/${locale}` : `/${locale}${path}`;
97
+ }
98
+
99
+ /** The absolute URL of a graph path in `locale`: its own domain when it has one. */
100
+ export function localeUrl(site , locale , path , origin ) {
101
+ const domain = site.localization?.domains?.[locale];
102
+ return domain ? `https://${domain}${path}` : `${origin}${localizedPath(site, locale, path)}`;
103
+ }
104
+
105
+ /** One language version of a page or entry for `hreflang` and the language switcher. */
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ const pathOf = (n ) => ("path" in n ? n.path : `/${n.collection}/${n.slug}`);
118
+
119
+ /** The visible members of `group` in this source (pages, or entries in the site's locales). */
120
+ async function groupMembers(
121
+ source ,
122
+ site ,
123
+ group ,
124
+ pages ,
125
+ ) {
126
+ const inGroup = (n ) => n.id === group || n.translation?.group === group;
127
+ if (pages) return (await source.pages()).filter(inGroup);
128
+ const all = await Promise.all(site.locales.map((l) => source.allEntries(l)));
129
+ return all.flat().filter(inGroup);
130
+ }
131
+
132
+ /**
133
+ * RFC-0034 §6: another site of the project holding versions of the same work (a language
134
+ * edition): its published source and the origin it is served on.
135
+ */
136
+
137
+
138
+
139
+
140
+
141
+ /**
142
+ * RFC-0033 invariant 7: every visible version of the node (itself included), plus `x-default`
143
+ * (the default locale's version). Empty when the node has no other version — `hreflang` needs two.
144
+ * `peers` adds the versions published by other sites of the project (RFC-0034 §6), each on its
145
+ * own host; a locale this site serves itself is not taken from a peer.
146
+ */
147
+ export async function alternatesFor(
148
+ source ,
149
+ node ,
150
+ origin ,
151
+ peers = [],
152
+ ) {
153
+ const site = await source.site();
154
+ const group = node.translation?.group ?? (peers.length > 0 ? node.id : undefined);
155
+ if (!group) return [];
156
+ const pages = "path" in node;
157
+ const own = (await groupMembers(source, site, group, pages)).filter((m) =>
158
+ site.locales.includes(m.locale),
159
+ );
160
+ const out = own.map((m) => ({
161
+ locale: m.locale,
162
+ href: localeUrl(site, m.locale, pathOf(m), origin),
163
+ current: m.id === node.id,
164
+ ...(m.id === group ? { original: true } : {}),
165
+ }));
166
+ for (const peer of peers) {
167
+ const peerSite = await peer.source.site();
168
+ for (const m of await groupMembers(peer.source, peerSite, group, pages))
169
+ if (peerSite.locales.includes(m.locale) && !out.some((a) => a.locale === m.locale))
170
+ out.push({
171
+ locale: m.locale,
172
+ href: localeUrl(peerSite, m.locale, pathOf(m), peer.origin),
173
+ current: false,
174
+ ...(m.id === group ? { original: true } : {}),
175
+ });
176
+ }
177
+ if (out.length < 2) return [];
178
+ const rank = (l ) => {
179
+ const i = site.locales.indexOf(l);
180
+ return i === -1 ? site.locales.length : i;
181
+ };
182
+ out.sort((a, b) => rank(a.locale) - rank(b.locale) || a.locale.localeCompare(b.locale));
183
+ // One x-default for the whole set: across editions, the group's original (every site agrees);
184
+ // within one site, its default locale's version.
185
+ const spans = out.some((a) => !site.locales.includes(a.locale));
186
+ const fallback = spans
187
+ ? (out.find((a) => a.original) ?? out.find((a) => a.locale === site.defaultLocale))
188
+ : out.find((a) => a.locale === site.defaultLocale);
189
+ return fallback ? [...out, { locale: "x-default", href: fallback.href, current: false }] : out;
190
+ }
191
+
192
+ /**
193
+ * Internal links of a page in `locale` (`origin`: the site's primary origin, for links back from a
194
+ * locale's own domain): a path that leads to a page, entry or archive with a
195
+ * version in `locale` goes there; one that leads to a default-locale node without such a version
196
+ * stays in the default locale (a reader may still follow it); anything else — search, feeds,
197
+ * unknown paths — stays in `locale`.
198
+ */
199
+ export async function linkLocalizer(
200
+ source ,
201
+ locale ,
202
+ origin ,
203
+ ) {
204
+ const site = await source.site();
205
+ const def = site.defaultLocale;
206
+ const prefixAll = localeRouting(site) === "prefix-all";
207
+ if (locale === def && !prefixAll) return undefined;
208
+ const own = site.localization?.domains?.[locale] !== undefined;
209
+ const here = (p ) => (own ? p : localizedPath(site, locale, p));
210
+ const home = (p ) => (own ? localeUrl(site, def, p, origin) : localizedPath(site, def, p));
211
+ const [pages, entries, translated, taxonomies, terms] = await Promise.all([
212
+ source.pages(),
213
+ source.allEntries(def),
214
+ source.allEntries(locale),
215
+ source.taxonomies(),
216
+ source.vocabulary(),
217
+ ]);
218
+ const byGroup = new Map ();
219
+ for (const n of [...pages, ...translated])
220
+ if (n.locale === locale && n.translation)
221
+ byGroup.set(`${"path" in n ? "p" : "e"}:${n.translation.group}`, n);
222
+ const map = new Map ();
223
+ for (const n of [...pages.filter((p) => p.locale === def), ...entries]) {
224
+ const twin = byGroup.get(`${"path" in n ? "p" : "e"}:${n.translation?.group ?? n.id}`);
225
+ map.set(pathOf(n), twin ? here(pathOf(twin)) : home(pathOf(n)));
226
+ }
227
+ const archive = archiveLocalizer(taxonomies, terms, locale, def);
228
+ return (path) => map.get(path) ?? (archive(path) ? here(archive(path) ) : here(path));
229
+ }
230
+
231
+ /** `<basePath>/<slug>[/…]` with the term's slug in `locale`; undefined for other paths. */
232
+ function archiveLocalizer(
233
+ taxonomies ,
234
+ terms ,
235
+ locale ,
236
+ def ,
237
+ ) {
238
+ return (path) => {
239
+ for (const tax of taxonomies) {
240
+ if (!tax.archive.enabled || !path.startsWith(`${tax.archive.basePath}/`)) continue;
241
+ const [slug = "", ...rest] = path.slice(tax.archive.basePath.length + 1).split("/");
242
+ const term = terms.find((t) => t.taxonomyId === tax.id && t.slug === slug);
243
+ if (term)
244
+ return [`${tax.archive.basePath}/${termSlug(term, locale, def)}`, ...rest].join("/");
245
+ }
246
+ return undefined;
247
+ };
248
+ }
249
+
250
+ /** Paths that are never a page: platform endpoints and media. */
251
+ const PLATFORM = /^\/(?:_|media\/)/;
252
+
253
+ /**
254
+ * Rewrites root-relative `href`s of `<a>`, `action`s of `<form>` and the search dialog's
255
+ * `data-endpoint`/`data-page` in rendered HTML through `localize` (query and fragment kept).
256
+ * Platform paths are left alone.
257
+ */
258
+ export function localizeLinks(html , localize ) {
259
+ const swap = (all , head , url , tail ) => {
260
+ if (url.startsWith("//") || PLATFORM.test(url)) return all;
261
+ const cut = url.search(/[?#]/);
262
+ const path = cut < 0 ? url : url.slice(0, cut);
263
+ const suffix = cut < 0 ? "" : url.slice(cut);
264
+ return `${head}${localize(path.length > 1 ? path.replace(/\/+$/, "") : path)}${suffix}${tail}`;
265
+ };
266
+ return html
267
+ .replace(/(<(?:a|form)\b[^>]*?\s(?:href|action)=")(\/[^"]*)(")/gi, swap)
268
+ .replace(/(\sdata-(?:endpoint|page)=")(\/[^"]*)(")/gi, swap);
269
+ }
270
+
271
+ /**
272
+ * The head of a page rendered in `locale`: its canonical, `og:url` and feed links on the locale's
273
+ * URLs (each version is self-canonical, never pointing at another language), `lang`/`dir`, the
274
+ * `hreflang` set and `og:locale:alternate`.
275
+ */
276
+ export function localizeHead(
277
+ meta ,
278
+ site ,
279
+ input
280
+
281
+
282
+
283
+
284
+ ,
285
+ ) {
286
+ const { locale, origin, alternates } = input;
287
+ const here = (url ) =>
288
+ url.startsWith(origin) ? localeUrl(site, locale, url.slice(origin.length) || "/", origin) : url;
289
+ const canonical = here(meta.canonical);
290
+ const others = alternates.filter((a) => !a.current && a.locale !== "x-default");
291
+ return {
292
+ ...meta,
293
+ canonical,
294
+ lang: locale,
295
+ dir: textDirection(locale),
296
+ feeds: meta.feeds.map((f) => ({ ...f, href: here(f.href) })),
297
+ openGraph: [
298
+ ...meta.openGraph.map(([k, v]) => [k, k === "og:url" ? canonical : v]),
299
+ ...others.map((a) => ["og:locale:alternate", a.locale.replace("-", "_")]),
300
+ ],
301
+ jsonLd: meta.jsonLd.map((doc, i) =>
302
+ i === 0 ? translationLd(doc, alternates, input.translation) : doc,
303
+ ),
304
+ ...(alternates.length
305
+ ? { alternates: alternates.map(({ locale: l, href }) => ({ locale: l, href })) }
306
+ : {}),
307
+ };
308
+ }
309
+
310
+ /**
311
+ * schema.org links between versions (RFC-0033 §4): the original lists its `workTranslation`s, a
312
+ * translation names its `translationOfWork`; `translator` is the reviewer, or the engine
313
+ * (a `SoftwareApplication`) for machine output nobody has reviewed yet.
314
+ */
315
+ function translationLd(
316
+ doc ,
317
+ alternates ,
318
+ translation ,
319
+ ) {
320
+ const self = alternates.find((a) => a.current);
321
+ const original = alternates.find((a) => a.original);
322
+ const others = alternates.filter((a) => !a.current && a.locale !== "x-default");
323
+ const links =
324
+ !self || !original
325
+ ? {}
326
+ : self.original
327
+ ? { workTranslation: others.map((a) => ({ "@id": a.href, inLanguage: a.locale })) }
328
+ : { translationOfWork: { "@id": original.href, inLanguage: original.locale } };
329
+ const by = translation?.review?.by;
330
+ const translator = by
331
+ ? { translator: { "@type": "Person", name: by.name ?? by.id } }
332
+ : translation?.method === "machine" && translation.provenance
333
+ ? { translator: { "@type": "SoftwareApplication", name: translation.provenance.engine } }
334
+ : {};
335
+ return { ...doc, ...links, ...translator };
336
+ }
@@ -0,0 +1,83 @@
1
+ import type { ContentEntry } from "@cloudhal/core-contracts";
2
+ import { type BlockRegistry } from "@cloudhal/core-ts/blocks";
3
+ import { mediaPath } from "@cloudhal/core-ts/media";
4
+ import { type MediaContext } from "./media.js";
5
+ import { safeHref, safeSrc } from "./safe-urls.js";
6
+ export type { MediaContext } from "./media.js";
7
+ export declare const escapeHtml: (s: string) => string;
8
+ export { safeHref, safeSrc };
9
+ /**
10
+ * A heading's anchor (RFC-0018 §3): ASCII slug of its text, unique in the document. Text without
11
+ * Latin letters or digits falls back to `section`; repeats get `-2`, `-3`, ….
12
+ */
13
+ export declare function headingSlug(text: string, taken?: Map<string, number>): string;
14
+ /** A body slot holding a ```surface fence (RFC-0020 §5); not a block type name (those are kebab). */
15
+ export declare const SURFACE_SLOT = "@surface";
16
+ /**
17
+ * Renders markdown safely. With `ctx.assets`, `asset:<id>` references become images, players and
18
+ * download links (RFC-0004 §7.6); without it they degrade to their text, like any unsafe URL.
19
+ */
20
+ export declare function renderMarkdown(source: string, ctx?: MediaContext): string;
21
+ /**
22
+ * Inline markdown, for short notes such as corrections (RFC-0019 §2): emphasis, code and safe
23
+ * links; images become their text, and nothing block-level is produced.
24
+ */
25
+ export declare function renderInlineMarkdown(source: string): string;
26
+ /** Markdown as plain text (meta descriptions): rendered safely, then tags dropped and entities decoded. */
27
+ export declare function markdownText(source: string): string;
28
+ /** Inline markdown as plain text: inline tags go without leaving gaps ("**537**," → "537,"). */
29
+ export declare function inlineMarkdownText(source: string): string;
30
+ /** Text of HTML this module produced: tags dropped, entities decoded, whitespace collapsed. */
31
+ export declare function htmlText(html: string): string;
32
+ /**
33
+ * `markdown` bodies are rendered as data; `html` bodies go through the allowlist sanitizer
34
+ * (RFC-0012): any writer can store them — agent keys over REST, `cloudhal push`, every role — so
35
+ * pages, previews, feeds and static builds never publish them as stored. Neither resolves
36
+ * `asset:` inside HTML (RFC-0004 §2.3).
37
+ */
38
+ export declare function renderBody(body: {
39
+ format: "markdown" | "html";
40
+ value: string;
41
+ }, ctx?: MediaContext): string;
42
+ /** A theme block in a body (RFC-0015 §5): its type, props and, for a container, its text. */
43
+ export interface BlockSlot {
44
+ type: string;
45
+ props: Record<string, unknown>;
46
+ /** A container's inner markdown. */
47
+ content?: string;
48
+ /** The same, rendered by the safe renderer. */
49
+ contentHtml?: string;
50
+ }
51
+ /** A body as HTML runs and the theme blocks between them, in order. */
52
+ export type BodyPart = {
53
+ html: string;
54
+ } | {
55
+ slot: BlockSlot;
56
+ };
57
+ /**
58
+ * A body for a theme that renders some block types with its own components (`Body.astro`): the
59
+ * HTML is cut where each such block goes. `registry` holds the theme's types (validation);
60
+ * `components` names the types the theme renders. Without any, it is `renderBody` in one part.
61
+ */
62
+ export declare function renderBodyParts(body: {
63
+ format: "markdown" | "html";
64
+ value: string;
65
+ }, ctx: MediaContext | undefined, blocks: {
66
+ registry: BlockRegistry;
67
+ components: ReadonlySet<string>;
68
+ } | undefined): BodyPart[];
69
+ /** An article's pieces: the body to render (a leading H1 repeating the title dropped) and the HTML around it. */
70
+ export declare function entryArticleParts(entry: Pick<ContentEntry, "id" | "title" | "summary" | "body" | "publishedAt" | "createdAt" | "coverImage">, locale?: string, ctx?: MediaContext): {
71
+ body: ContentEntry["body"];
72
+ header: string;
73
+ cover: string;
74
+ media: MediaContext;
75
+ };
76
+ /**
77
+ * An article: a header (title, summary, publication date) followed by the body. A leading `# H1`
78
+ * that repeats the title is dropped so authors may write it either way. Themes with their own
79
+ * block components use `EntryArticle.astro`, which has the same markup.
80
+ */
81
+ export declare function renderEntryArticle(entry: Pick<ContentEntry, "id" | "title" | "summary" | "body" | "publishedAt" | "createdAt" | "coverImage">, locale?: string, ctx?: MediaContext): string;
82
+ /** The media path of an asset (re-exported for themes). */
83
+ export { mediaPath };