@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,3 @@
1
+ import type { CloudhalRendererConfig } from "./integration.js";
2
+ /** The next gate after `now` in the build's source (ms), if any. */
3
+ export declare function staticNextGate(config: CloudhalRendererConfig, now: number): Promise<number | undefined>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Static builds (Node, `cloudhal build`) and time gates (RFC-0008 §7): a static build renders the
3
+ * site as it is at build time — embargoed pages and entries are left out, expired ones too — but
4
+ * nothing re-renders it when a gate passes. An embargo then stays dark until the next build (safe)
5
+ * and an expiry stays online (not safe), so the build says when it must run again. The Cloudflare
6
+ * Site Worker checks gates per request and needs none of this. Node-only, loaded lazily by the
7
+ * integration's `astro:build:done`.
8
+ */
9
+ import { openLocalStore } from "@cloudhal/core-ts/local";
10
+
11
+ import { LiveSource, SnapshotSource } from "./source.js";
12
+
13
+ /** The next gate after `now` in the build's source (ms), if any. */
14
+ export async function staticNextGate(
15
+ config ,
16
+ now ,
17
+ ) {
18
+ const selector = process.env.CLOUDHAL_SOURCE ?? config.source ?? "live";
19
+ const local = await openLocalStore(config.dataDir);
20
+ try {
21
+ const source = selector.startsWith("snapshot:")
22
+ ? (await SnapshotSource.open(local.store, selector.slice("snapshot:".length))).at(now)
23
+ : new LiveSource(local.store, config.siteId, { includeDrafts: false, now: () => now });
24
+ return await source.nextGate?.();
25
+ } finally {
26
+ await local.close();
27
+ }
28
+ }
@@ -0,0 +1,30 @@
1
+ /** Where the Site Worker build writes its hashed scripts (analytics, comments). */
2
+ export declare const CLOUDHAL_ASSETS_RULE = "/_cloudhal/*";
3
+ /**
4
+ * Adds an immutable `Cache-Control` rule for `/_cloudhal/*` to the build's `_headers` (Workers
5
+ * static assets: https://developers.cloudflare.com/workers/static-assets/headers/). The scripts
6
+ * there are named by content hash, like Astro's `/_astro/*` (which the Cloudflare adapter marks
7
+ * immutable in the same file), so browsers need not revalidate them on every page view. Keeps any
8
+ * rules already in the file; idempotent.
9
+ */
10
+ export declare function writeCloudhalAssetHeaders(dir: URL | string): Promise<void>;
11
+ /** Every path of a static build (`_headers` rule). */
12
+ export declare const STATIC_SECURITY_RULE = "/*";
13
+ /**
14
+ * Static builds (`cloudhal build`) get the Site Worker's security headers through `_headers`, for
15
+ * hosts that read it (Cloudflare Workers static assets and Pages, Netlify): the same `SITE_CSP`,
16
+ * `nosniff` and referrer policy the Worker adds to HTML (`withSecurityHeaders`). Agent-written
17
+ * content gets the same defence in depth wherever the site is hosted. A `/*` rule already in the
18
+ * file (the owner's own) is kept as it is; idempotent.
19
+ */
20
+ export declare function writeStaticSecurityHeaders(dir: URL | string, options?: {
21
+ embeds?: boolean;
22
+ }): Promise<boolean>;
23
+ /** Writes the click-to-load player module (RFC-0015 §4) into the build's `/_cloudhal/`. */
24
+ export declare function writeEmbedClient(dir: URL | string): Promise<void>;
25
+ /** Writes the interaction runtime (RFC-0020 §4) into the build's `/_cloudhal/`. */
26
+ export declare function writeSurfaceClient(dir: URL | string): Promise<void>;
27
+ /** Whether any page of a static build has a live surface, motion or the chrome module (its HTML marks one). */
28
+ export declare function buildShowsLiveSurfaces(dir: URL | string): Promise<boolean>;
29
+ /** Whether any page of a static build shows a video player (its HTML marks one). */
30
+ export declare function buildShowsEmbeds(dir: URL | string): Promise<boolean>;
@@ -0,0 +1,140 @@
1
+ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { AMBIENT_SCRIPT } from "./ambient-client.js";
5
+ import { CAROUSEL_SCRIPT, CAROUSEL_SCRIPT_ALIASES } from "./carousel-client.js";
6
+ import { CHART_SCRIPT } from "./chart.js";
7
+ import { CHROME_SCRIPT, CHROME_SCRIPT_ALIASES } from "./chrome-client.js";
8
+ import { SITE_CSP } from "./csp.js";
9
+ import { EMBED_SCRIPT, withEmbedFrames } from "./embed-client.js";
10
+ import { MOTION_SCRIPT, MOTION_SCRIPT_ALIASES } from "./motion-client.js";
11
+ import { OVERLAY_SCRIPT } from "./overlay-client.js";
12
+ import { PREFS_SCRIPT } from "./prefs-client.js";
13
+ import { SEARCH_SCRIPT } from "./search-client.js";
14
+ import { SURFACE_SCRIPT, SURFACE_SCRIPT_ALIASES } from "./surface-client.js";
15
+
16
+ /** Where the Site Worker build writes its hashed scripts (analytics, comments). */
17
+ export const CLOUDHAL_ASSETS_RULE = "/_cloudhal/*";
18
+
19
+ /**
20
+ * Adds an immutable `Cache-Control` rule for `/_cloudhal/*` to the build's `_headers` (Workers
21
+ * static assets: https://developers.cloudflare.com/workers/static-assets/headers/). The scripts
22
+ * there are named by content hash, like Astro's `/_astro/*` (which the Cloudflare adapter marks
23
+ * immutable in the same file), so browsers need not revalidate them on every page view. Keeps any
24
+ * rules already in the file; idempotent.
25
+ */
26
+ export async function writeCloudhalAssetHeaders(dir ) {
27
+ const root = typeof dir === "string" ? dir : fileURLToPath(dir.href);
28
+ const file = path.join(root, "_headers");
29
+ const existing = await readFile(file, "utf8").catch(() => "");
30
+ if (existing.split("\n").some((line) => line.trim() === CLOUDHAL_ASSETS_RULE)) return;
31
+ const rule = `${CLOUDHAL_ASSETS_RULE}\n Cache-Control: public, max-age=31536000, immutable\n`;
32
+ const separator =
33
+ existing === "" || existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
34
+ await writeFile(file, `${existing}${separator}${rule}`);
35
+ }
36
+
37
+ /** Every path of a static build (`_headers` rule). */
38
+ export const STATIC_SECURITY_RULE = "/*";
39
+
40
+ /**
41
+ * Static builds (`cloudhal build`) get the Site Worker's security headers through `_headers`, for
42
+ * hosts that read it (Cloudflare Workers static assets and Pages, Netlify): the same `SITE_CSP`,
43
+ * `nosniff` and referrer policy the Worker adds to HTML (`withSecurityHeaders`). Agent-written
44
+ * content gets the same defence in depth wherever the site is hosted. A `/*` rule already in the
45
+ * file (the owner's own) is kept as it is; idempotent.
46
+ */
47
+ export async function writeStaticSecurityHeaders(
48
+ dir ,
49
+ options = {},
50
+ ) {
51
+ const root = typeof dir === "string" ? dir : fileURLToPath(dir.href);
52
+ const file = path.join(root, "_headers");
53
+ const existing = await readFile(file, "utf8").catch(() => "");
54
+ if (existing.split("\n").some((line) => line.trim() === STATIC_SECURITY_RULE)) return false;
55
+ const rule = [
56
+ STATIC_SECURITY_RULE,
57
+ ` Content-Security-Policy: ${options.embeds ? withEmbedFrames(SITE_CSP) : SITE_CSP}`,
58
+ " X-Content-Type-Options: nosniff",
59
+ " Referrer-Policy: strict-origin-when-cross-origin",
60
+ "",
61
+ ].join("\n");
62
+ const separator =
63
+ existing === "" || existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
64
+ await writeFile(file, `${existing}${separator}${rule}`);
65
+ return true;
66
+ }
67
+
68
+ const rootOf = (dir ) => (typeof dir === "string" ? dir : fileURLToPath(dir.href));
69
+
70
+ /** Writes the click-to-load player module (RFC-0015 §4) into the build's `/_cloudhal/`. */
71
+ export async function writeEmbedClient(dir ) {
72
+ const file = path.join(rootOf(dir), ...EMBED_SCRIPT.path.split("/").filter(Boolean));
73
+ await mkdir(path.dirname(file), { recursive: true });
74
+ await writeFile(file, EMBED_SCRIPT.code);
75
+ }
76
+
77
+ /** Writes the interaction runtime (RFC-0020 §4) into the build's `/_cloudhal/`. */
78
+ export async function writeSurfaceClient(dir ) {
79
+ const files = [
80
+ [SURFACE_SCRIPT.path, SURFACE_SCRIPT.code],
81
+ ...SURFACE_SCRIPT_ALIASES.map((alias) => [alias, SURFACE_SCRIPT.code] ),
82
+ // RFC-0022 §3: the chart drawer, loaded by the runtime for live charts only.
83
+ [CHART_SCRIPT.path, CHART_SCRIPT.code],
84
+ // RFC-0024 §7: the motion module, loaded by pages whose surfaces move.
85
+ [MOTION_SCRIPT.path, MOTION_SCRIPT.code],
86
+ ...MOTION_SCRIPT_ALIASES.map((alias) => [alias, MOTION_SCRIPT.code] ),
87
+ [AMBIENT_SCRIPT.path, AMBIENT_SCRIPT.code],
88
+ // RFC-0025 §2: the chrome module, loaded by pages whose header asks for it.
89
+ [CHROME_SCRIPT.path, CHROME_SCRIPT.code],
90
+ ...CHROME_SCRIPT_ALIASES.map((alias) => [alias, CHROME_SCRIPT.code] ),
91
+ // RFC-0025 25d: the bars' preferences, read in <head> before the page paints.
92
+ [PREFS_SCRIPT.path, PREFS_SCRIPT.code],
93
+ // RFC-0025 §3: the overlay module, loaded by surfaces with an overlay.
94
+ [OVERLAY_SCRIPT.path, OVERLAY_SCRIPT.code],
95
+ // RFC-0027 27b: the carousel module, loaded by surfaces with a carousel.
96
+ [CAROUSEL_SCRIPT.path, CAROUSEL_SCRIPT.code],
97
+ ...CAROUSEL_SCRIPT_ALIASES.map((alias) => [alias, CAROUSEL_SCRIPT.code] ),
98
+ // RFC-0029 §6: the search modal (static builds have no search, so they never load it).
99
+ [SEARCH_SCRIPT.path, SEARCH_SCRIPT.code],
100
+ ];
101
+ for (const [name, code] of files) {
102
+ const file = path.join(rootOf(dir), ...name.split("/").filter(Boolean));
103
+ await mkdir(path.dirname(file), { recursive: true });
104
+ await writeFile(file, code);
105
+ }
106
+ }
107
+
108
+ /** Whether any page of a static build has a live surface, motion or the chrome module (its HTML marks one). */
109
+ export async function buildShowsLiveSurfaces(dir ) {
110
+ const entries = await readdir(rootOf(dir), { recursive: true, withFileTypes: true }).catch(
111
+ () => [],
112
+ );
113
+ for (const e of entries) {
114
+ if (!e.isFile() || !e.name.endsWith(".html")) continue;
115
+ const html = await readFile(path.join(e.parentPath, e.name), "utf8");
116
+ if (
117
+ html.includes("data-ch-surface=") ||
118
+ html.includes(MOTION_SCRIPT.path) ||
119
+ html.includes(CHROME_SCRIPT.path) ||
120
+ html.includes(OVERLAY_SCRIPT.path) ||
121
+ html.includes(CAROUSEL_SCRIPT.path) ||
122
+ html.includes(PREFS_SCRIPT.path)
123
+ )
124
+ return true;
125
+ }
126
+ return false;
127
+ }
128
+
129
+ /** Whether any page of a static build shows a video player (its HTML marks one). */
130
+ export async function buildShowsEmbeds(dir ) {
131
+ const entries = await readdir(rootOf(dir), { recursive: true, withFileTypes: true }).catch(
132
+ () => [],
133
+ );
134
+ for (const e of entries) {
135
+ if (!e.isFile() || !e.name.endsWith(".html")) continue;
136
+ const html = await readFile(path.join(e.parentPath, e.name), "utf8");
137
+ if (html.includes("data-embed-src=")) return true;
138
+ }
139
+ return false;
140
+ }
@@ -0,0 +1,4 @@
1
+ import type { CloudhalRendererConfig } from "./integration.js";
2
+ export declare const HEADERS_FILE = "_headers";
3
+ /** Copies the build's media into `outDir`; returns how many files were written. */
4
+ export declare function writeStaticMedia(config: CloudhalRendererConfig, outDir: URL): Promise<number>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Static builds (`cloudhal build`, RFC-0004 §7.8): every blob asset of the built snapshot is copied
3
+ * to `dist/media/<prefix>/<slug>.<ext>` with its `.sha256` sidecar, and `dist/_headers` gets a
4
+ * `/media/*` block (immutable cache, `nosniff`) for hosts that read it. External assets link
5
+ * directly; taken-down content is not copied; transformations are off. Node-only (loaded lazily by
6
+ * the integration's `astro:build:done`).
7
+ */
8
+ import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
9
+ import path from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { mediaBlobKey } from "@cloudhal/core-ts";
12
+ import { openLocalStore } from "@cloudhal/core-ts/local";
13
+ import { mediaExtension, mediaPath } from "@cloudhal/core-ts/media";
14
+
15
+ import { LiveSource, SnapshotSource } from "./source.js";
16
+
17
+ export const HEADERS_FILE = "_headers";
18
+
19
+ const HEADERS_BLOCK = `/media/*
20
+ Cache-Control: public, max-age=31536000, immutable
21
+ X-Content-Type-Options: nosniff
22
+ `;
23
+
24
+ /** Copies the build's media into `outDir`; returns how many files were written. */
25
+ export async function writeStaticMedia(
26
+ config ,
27
+ outDir ,
28
+ ) {
29
+ const selector = process.env.CLOUDHAL_SOURCE ?? config.source ?? "live";
30
+ const local = await openLocalStore(config.dataDir);
31
+ const root = fileURLToPath(String(outDir));
32
+ try {
33
+ const source = selector.startsWith("snapshot:")
34
+ ? await SnapshotSource.open(local.store, selector.slice("snapshot:".length))
35
+ : new LiveSource(local.store, config.siteId);
36
+ const assets = source.assets ? await source.assets() : [];
37
+ let written = 0;
38
+ for (const asset of assets) {
39
+ if (asset.storage.kind !== "blob") continue;
40
+ if ((await local.store.blobState(config.siteId, asset.sha256))?.state === "purged") continue;
41
+ const bytes = await local.blobs.get(mediaBlobKey(config.siteId, asset.sha256));
42
+ if (!bytes) continue;
43
+ const file = path.join(root, ...mediaPath(asset).split("/").filter(Boolean));
44
+ await mkdir(path.dirname(file), { recursive: true });
45
+ await writeFile(file, bytes);
46
+ await writeFile(
47
+ `${file}.sha256`,
48
+ `${asset.sha256} ${asset.slug}.${mediaExtension(asset.mediaType)}\n`,
49
+ );
50
+ written++;
51
+ }
52
+ if (written > 0) {
53
+ const headers = path.join(root, HEADERS_FILE);
54
+ const existing = await readFile(headers, "utf8").catch(() => "");
55
+ if (!existing.includes("/media/*"))
56
+ await appendFile(
57
+ headers,
58
+ `${existing && !existing.endsWith("\n") ? "\n" : ""}${HEADERS_BLOCK}`,
59
+ );
60
+ }
61
+ return written;
62
+ } finally {
63
+ await local.close();
64
+ }
65
+ }
@@ -0,0 +1,4 @@
1
+ import type { CloudhalRendererConfig } from "./integration.js";
2
+ export declare const REDIRECTS_FILE = "_redirects";
3
+ /** Writes `<outDir>/_redirects` for the build's source; returns how many redirects it holds. */
4
+ export declare function writeStaticRedirects(config: CloudhalRendererConfig, outDir: URL): Promise<number>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Static builds (Node, `cloudhal build`): Astro cannot answer a prerendered path with a 301, so a
3
+ * redirect becomes a meta-refresh page (with `rel=canonical` and `noindex`) for every path
4
+ * `staticPaths` lists. This writes the same redirects as `dist/_redirects` as well, so hosts that
5
+ * read the file (Cloudflare Workers/Pages static assets, Netlify) send real 301s — including for
6
+ * prefix matches and feeds, which a meta-refresh page cannot cover. Node-only (loaded lazily by
7
+ * the integration's `astro:build:done`); the Cloudflare Site Worker answers redirects itself.
8
+ */
9
+ import { writeFile } from "node:fs/promises";
10
+ import path from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { openLocalStore } from "@cloudhal/core-ts/local";
13
+ import { redirectsFile } from "./feeds.js";
14
+
15
+ import { LiveSource, SnapshotSource } from "./source.js";
16
+
17
+ export const REDIRECTS_FILE = "_redirects";
18
+
19
+ /** Writes `<outDir>/_redirects` for the build's source; returns how many redirects it holds. */
20
+ export async function writeStaticRedirects(
21
+ config ,
22
+ outDir ,
23
+ ) {
24
+ const selector = process.env.CLOUDHAL_SOURCE ?? config.source ?? "live";
25
+ const local = await openLocalStore(config.dataDir);
26
+ try {
27
+ const source = selector.startsWith("snapshot:")
28
+ ? await SnapshotSource.open(local.store, selector.slice("snapshot:".length))
29
+ : new LiveSource(local.store, config.siteId);
30
+ const redirects = await source.redirects();
31
+ if (redirects.length > 0)
32
+ await writeFile(
33
+ path.join(fileURLToPath(String(outDir)), REDIRECTS_FILE),
34
+ redirectsFile(redirects),
35
+ );
36
+ return redirects.length;
37
+ } finally {
38
+ await local.close();
39
+ }
40
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The interaction runtime (RFC-0020 §4): one small first-party module under `/_cloudhal/`, so the
3
+ * site's `script-src 'self'` stays as it is. A surface with inputs or button actions is rendered
4
+ * complete on the server, with its data model in a `<script type="application/json"
5
+ * data-ch-state>`; this module then keeps it live:
6
+ *
7
+ * - `data-ch-model="<pointer>"` inputs (Toggle, Select, Slider) write to the data;
8
+ * - `data-ch-action='<json>'` buttons run a named action (set, toggle, increment, reset,
9
+ * navigate, copy, share, scrollTo);
10
+ * - `data-ch-text='<value>'` elements show a binding or a named function's result as text;
11
+ * - `data-ch-visible='<condition>'` elements are hidden while the condition is false;
12
+ * - RFC-0025 25d: a copy (or a share that copies the link) says so in the page's toast region
13
+ * (`[data-ch-toasts]`, a live region the theme renders with the words in `data-copied` and
14
+ * `data-link-copied`); a toast goes after four seconds.
15
+ *
16
+ * Nothing a model wrote is evaluated: values are JSON, functions are Cloudhal's fixed set (the
17
+ * same as `@cloudhal/core-ts/surfaces`; a test keeps them equal), text goes in as `textContent`,
18
+ * links must be same-site paths or https. Without JavaScript the page keeps its server state.
19
+ *
20
+ * Worker-safe: the code is a constant, written as a static asset by the build and served from
21
+ * memory by `cloudhal dev`. The file name carries a version (`/_cloudhal/*` is immutable): bump it
22
+ * with any change to the code; a test pins the code's hash to the version.
23
+ */
24
+ export declare const SURFACE_SCRIPT: {
25
+ readonly path: "/_cloudhal/surface.10.js";
26
+ readonly code: string;
27
+ };
28
+ /**
29
+ * Earlier names of the runtime, served with the current code: pages cached with them keep
30
+ * working (each version only adds to the one before; RFC-0022 §1).
31
+ */
32
+ export declare const SURFACE_SCRIPT_ALIASES: readonly ["/_cloudhal/surface.1.js", "/_cloudhal/surface.2.js", "/_cloudhal/surface.3.js", "/_cloudhal/surface.4.js", "/_cloudhal/surface.5.js", "/_cloudhal/surface.6.js", "/_cloudhal/surface.7.js", "/_cloudhal/surface.8.js", "/_cloudhal/surface.9.js"];
33
+ /** JSON for a `<script type="application/json">`: nothing in it can end the element. */
34
+ export declare function scriptJson(value: unknown): string;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The interaction runtime (RFC-0020 §4): one small first-party module under `/_cloudhal/`, so the
3
+ * site's `script-src 'self'` stays as it is. A surface with inputs or button actions is rendered
4
+ * complete on the server, with its data model in a `<script type="application/json"
5
+ * data-ch-state>`; this module then keeps it live:
6
+ *
7
+ * - `data-ch-model="<pointer>"` inputs (Toggle, Select, Slider) write to the data;
8
+ * - `data-ch-action='<json>'` buttons run a named action (set, toggle, increment, reset,
9
+ * navigate, copy, share, scrollTo);
10
+ * - `data-ch-text='<value>'` elements show a binding or a named function's result as text;
11
+ * - `data-ch-visible='<condition>'` elements are hidden while the condition is false;
12
+ * - RFC-0025 25d: a copy (or a share that copies the link) says so in the page's toast region
13
+ * (`[data-ch-toasts]`, a live region the theme renders with the words in `data-copied` and
14
+ * `data-link-copied`); a toast goes after four seconds.
15
+ *
16
+ * Nothing a model wrote is evaluated: values are JSON, functions are Cloudhal's fixed set (the
17
+ * same as `@cloudhal/core-ts/surfaces`; a test keeps them equal), text goes in as `textContent`,
18
+ * links must be same-site paths or https. Without JavaScript the page keeps its server state.
19
+ *
20
+ * Worker-safe: the code is a constant, written as a static asset by the build and served from
21
+ * memory by `cloudhal dev`. The file name carries a version (`/_cloudhal/*` is immutable): bump it
22
+ * with any change to the code; a test pins the code's hash to the version.
23
+ */
24
+
25
+ import { CHART_SCRIPT } from "./chart.js";
26
+
27
+ const code = String.raw`const toast=(k)=>{const r=document.querySelector("[data-ch-toasts]");const t=r&&r.getAttribute("data-"+k);if(!t)return;
28
+ const el=document.createElement("p");el.className="ch-toast";el.textContent=t;r.append(el);setTimeout(()=>el.remove(),4000);};
29
+ const ptr=(p)=>p===""?[]:String(p).slice(1).split("/").map((s)=>s.replace(/~1/g,"/").replace(/~0/g,"~"));
30
+ const BAD=new Set(["__proto__","prototype","constructor"]);
31
+ const own=(o,k)=>Object.prototype.hasOwnProperty.call(o,k);
32
+ const get=(d,p)=>{if(typeof p!=="string"||(p&&p[0]!=="/"))return undefined;let c=d;for(const s of ptr(p)){if(Array.isArray(c))c=/^\d+$/.test(s)?c[+s]:undefined;else if(c&&typeof c==="object"&&own(c,s))c=c[s];else return undefined;}return c;};
33
+ const put=(d,p,v)=>{if(typeof p!=="string"||p[0]!=="/")return;const k=ptr(p);if(!k.length||k.some((s)=>BAD.has(s)))return;let c=d;for(let i=0;i<k.length-1;i++){const s=k[i];if(c[s]===null||typeof c[s]!=="object")c[s]={};c=c[s];}c[k[k.length-1]]=v;};
34
+ const obj=(v)=>v!==null&&typeof v==="object"&&!Array.isArray(v);
35
+ const isPath=(v)=>obj(v)&&typeof v.path==="string"&&Object.keys(v).length===1;
36
+ const isCall=(v)=>obj(v)&&typeof v.call==="string";
37
+ const txt=(v)=>v===undefined||v===null?"":String(v);
38
+ const num=(v)=>typeof v==="number"?v:typeof v==="string"?Number(v):NaN;
39
+ const blank=(v)=>v===undefined||v===null||v==="";
40
+ const tn=(v)=>typeof v==="number"?v:typeof v==="string"?Number(/^\s*-?\d+,\d+\s*$/.test(v)?v.replace(",","."):v):NaN;
41
+ const op=(v)=>{if(blank(v))return undefined;const n=tn(v);return Number.isFinite(n)?n:undefined;};
42
+ const ns=(v)=>{const l=Array.isArray(v)?v:[];if(!l.length)return undefined;const r=l.map(op);return r.every((n)=>n!==undefined)?r:undefined;};
43
+ const fin=(n)=>Number.isFinite(n)?Number(n.toPrecision(10)):"";
44
+ const dg=(x)=>Math.min(Math.max(0,Math.trunc(num(x===undefined||x===null?0:x))||0),6);
45
+ const calc=(src,vars)=>{if(src.length>200)return"";const s=src.replace(/×/g,"*").replace(/÷/g,"/");const V=obj(vars)?vars:{};let i=0,z=0;const no=()=>{throw 0;};
46
+ const pk=()=>{while(s[i]===" "||s[i]==="\t"||s[i]==="\n")i++;return s[i];};
47
+ const at=()=>{if(++z>32)no();let v;if(pk()==="("){i++;v=ex();if(pk()!==")")no();i++;}else{const r=s.slice(i);const n=/^\d+(?:\.\d+)?/.exec(r);const m=n?null:/^[A-Za-z_][A-Za-z0-9_]{0,31}/.exec(r);if(n){i+=n[0].length;v=Number(n[0]);}else if(m&&own(V,m[0])){i+=m[0].length;const g=op(V[m[0]]);if(g===undefined)no();v=g;}else no();}z--;return v;};
48
+ const un=()=>{if(pk()==="-"){i++;return-un();}return pw();};
49
+ const pw=()=>{const b=at();if(pk()!=="^")return b;i++;const e=un();if(Math.abs(e)>1000)no();return b**e;};
50
+ const te=()=>{let v=un();for(let c=pk();c==="*"||c==="/"||c==="%";c=pk()){i++;const r=un();v=c==="*"?v*r:c==="/"?v/r:v%r;}return v;};
51
+ const ex=()=>{let v=te();for(let c=pk();c==="+"||c==="-";c=pk()){i++;const r=te();v=c==="+"?v+r:v-r;}return v;};
52
+ try{if(!pk())return"";const v=ex();return pk()===undefined?fin(v):"";}catch{return"";}};
53
+ const fn=(name,a,loc)=>{const v=a.value;switch(name){
54
+ case"formatDate":{const d=new Date(txt(v));if(Number.isNaN(d.getTime()))return"";const st=["short","medium","long","full"].includes(txt(a.style))?txt(a.style):"medium";return new Intl.DateTimeFormat(loc,{dateStyle:st,timeZone:"UTC"}).format(d);}
55
+ case"formatNumber":{if(blank(v))return"";const n=num(v);if(!Number.isFinite(n))return"";const g=Math.min(Math.max(0,Math.trunc(num(a.digits===undefined?2:a.digits))||0),6);return new Intl.NumberFormat(loc,{maximumFractionDigits:g}).format(n);}
56
+ case"formatCurrency":{if(blank(v))return"";const n=num(v);const c=txt(a.currency).toUpperCase();if(!Number.isFinite(n)||!/^[A-Z]{3}$/.test(c))return"";try{return new Intl.NumberFormat(loc,{style:"currency",currency:c}).format(n);}catch{return"";}}
57
+ case"pluralize":{const n=num(a.count);return(n===1?txt(a.one):txt(a.other)).replace(/#/g,Number.isFinite(n)?String(n):"");}
58
+ case"concat":return(Array.isArray(a.parts)?a.parts:[]).map(txt).join("");
59
+ case"length":return Array.isArray(v)||typeof v==="string"?v.length:0;
60
+ case"required":return!(v===undefined||v===null||v===""||(Array.isArray(v)&&v.length===0));
61
+ case"minLength":return txt(v).length>=num(a.min);
62
+ case"maxLength":return txt(v).length<=num(a.max);
63
+ case"email":return/^[^\s@]{1,64}@[^\s@]{1,255}\.[^\s@]{2,63}$/.test(txt(v));
64
+ case"range":{const n=num(v);return Number.isFinite(n)&&n>=num(a.min)&&n<=num(a.max);}
65
+ case"add":case"multiply":case"min":case"max":{const l=ns(a.values);if(!l)return"";if(name==="add")return fin(l.reduce((x,y)=>x+y,0));if(name==="multiply")return fin(l.reduce((x,y)=>x*y,1));return fin(name==="min"?Math.min(...l):Math.max(...l));}
66
+ case"subtract":{const x=op(a.a),y=op(a.b);return x===undefined||y===undefined?"":fin(x-y);}
67
+ case"divide":{const x=op(a.a),y=op(a.b);if(x===undefined||y===undefined)return"";return y===0?(a.fallback===undefined||a.fallback===null?"":a.fallback):fin(x/y);}
68
+ case"round":case"floor":case"ceil":{const n=op(v);if(n===undefined)return"";const f=10**dg(a.digits);return fin(Math[name](Number((n*f).toPrecision(12)))/f);}
69
+ case"abs":{const n=op(v);return n===undefined?"":fin(Math.abs(n));}
70
+ case"clamp":{const n=op(v),lo=op(a.min),hi=op(a.max);return n===undefined||lo===undefined||hi===undefined?"":fin(Math.min(Math.max(n,lo),hi));}
71
+ case"power":{const b=op(a.base),e=op(a.exponent);return b===undefined||e===undefined||Math.abs(e)>1000?"":fin(b**e);}
72
+ case"number":{const n=op(v);return n===undefined?(a.fallback===undefined||a.fallback===null?"":a.fallback):fin(n);}
73
+ case"sum":case"average":case"count":{const f=typeof a.field==="string"?a.field:undefined;const p=(Array.isArray(a.list)?a.list:[]).slice(0,1000).map((x)=>f===undefined?x:obj(x)?x[f]:undefined).filter((x)=>!blank(x));if(name==="count")return p.length;const l=p.map(tn).filter((n)=>Number.isFinite(n));if(!l.length)return name==="sum"?0:"";const t=l.reduce((x,y)=>x+y,0);return fin(name==="sum"?t:t/l.length);}
74
+ case"formatPercent":{const n=op(v);if(n===undefined)return"";return new Intl.NumberFormat(loc,{style:"percent",maximumFractionDigits:dg(a.digits)}).format(n);}
75
+ case"calculate":return calc(txt(a.expression),a.vars);}
76
+ return"";};
77
+ const nil=(o)=>o===undefined||o===null?"":o;
78
+ const val=(v,d,loc,z=0)=>{if(isPath(v))return get(d,v.path);if(isCall(v)){if(z>=8)return"";const r=obj(v.args)?v.args:{};const at=(x)=>val(x,d,loc,z+1);
79
+ if(v.call==="if")return nil(cond(r.cond,d)?at(r.ifTrue):at(r.ifFalse));
80
+ if(v.call==="calculate"&&obj(r.vars)){const vs={};for(const[k,x]of Object.entries(r.vars))vs[k]=at(x);return calc(txt(at(r.expression)),vs);}
81
+ if(v.call==="choose"){const k=txt(at(r.value));const c=obj(r.cases)?r.cases:{};return nil(own(c,k)?at(c[k]):at(r.default));}
82
+ const a={};for(const[k,x]of Object.entries(r))a[k]=Array.isArray(x)?x.map(at):at(x);return fn(v.call,a,loc);}return v;};
83
+ const truthy=(v)=>!(v===undefined||v===null||v===false||v===0||v===""||(Array.isArray(v)&&v.length===0));
84
+ const cond=(c,d)=>{if(c===undefined)return true;if(isPath(c))return truthy(get(d,c.path));if(!obj(c))return false;const[op,a]=Object.entries(c)[0]||[];const o=(x)=>isPath(x)?get(d,x.path):x;
85
+ if(["eq","ne","gt","lt","gte","lte"].includes(op)&&Array.isArray(a)){const x=o(a[0]);const y=o(a[1]);if(op==="eq")return x===y;if(op==="ne")return x!==y;if(typeof x!==typeof y||(typeof x!=="number"&&typeof x!=="string"))return false;return op==="gt"?x>y:op==="lt"?x<y:op==="gte"?x>=y:x<=y;}
86
+ if(op==="and"&&Array.isArray(a))return a.every((x)=>cond(x,d));if(op==="or"&&Array.isArray(a))return a.some((x)=>cond(x,d));if(op==="not")return!cond(a,d);return false;};
87
+ const safe=(h)=>typeof h==="string"&&/^(\/(?!\/)|#|https:\/\/)/.test(h)&&!/[\s<>"']/.test(h);
88
+ const json=(el,a)=>{try{return JSON.parse(el.getAttribute(a)||"null");}catch{return undefined;}};
89
+ let chartMod;
90
+ const charts=(root,d,loc)=>{const els=[...root.querySelectorAll("[data-ch-chart]")];if(!els.length)return;
91
+ const draw=(m)=>{for(const el of els){const raw=json(el,"data-ch-chart");const b=el.querySelector(".ch-chart__body");if(!obj(raw)||!b)continue;const sp={};for(const[k,x]of Object.entries(raw))sp[k]=val(x,d,loc);b.innerHTML=m.chartInner(sp,loc,{data:el.getAttribute("data-ch-label")||"Data"});}};
92
+ if(chartMod)draw(chartMod);else import("${CHART_SCRIPT.path}").then((m)=>{chartMod=m;draw(m);}).catch(()=>{});};
93
+ const boot=(root)=>{const s=root.querySelector("script[data-ch-state]");if(!s||root.hasAttribute("data-ch-live"))return;root.setAttribute("data-ch-live","");
94
+ let init;try{init=JSON.parse(s.textContent||"{}");}catch{return;}let d=structuredClone(init);const loc=document.documentElement.lang||"en";
95
+ const render=()=>{for(const el of root.querySelectorAll("[data-ch-text]"))el.textContent=txt(val(json(el,"data-ch-text"),d,loc));
96
+ for(const el of root.querySelectorAll("[data-ch-visible]"))el.hidden=!cond(json(el,"data-ch-visible"),d);
97
+ charts(root,d,loc);
98
+ for(const el of root.querySelectorAll("[data-ch-invalid]"))el.setAttribute("aria-invalid",truthy(val(json(el,"data-ch-invalid"),d,loc))?"true":"false");
99
+ for(const el of root.querySelectorAll("[data-ch-model]")){const v=get(d,el.getAttribute("data-ch-model"));if(el.type==="radio")el.checked=el.value===txt(v);else if(el.type==="checkbox")el.checked=truthy(v);else if(v!==undefined&&document.activeElement!==el)el.value=txt(v);}};
100
+ const write=(e)=>{const el=e.target instanceof Element?e.target.closest("[data-ch-model]"):null;if(!el||!root.contains(el)||(el.type==="radio"&&!el.checked))return;put(d,el.getAttribute("data-ch-model"),el.type==="checkbox"?el.checked:el.type==="number"?(el.value===""?"":num(el.value)):el.type==="range"?num(el.value):el.value);render();};
101
+ root.addEventListener("input",write);root.addEventListener("change",write);
102
+ root.addEventListener("ch:set",(e)=>{const a=e.detail;if(obj(a)&&typeof a.path==="string"&&a.path[0]==="/"&&(typeof a.value==="number"||typeof a.value==="string")){put(d,a.path,a.value);render();}});
103
+ root.addEventListener("click",(e)=>{const el=e.target instanceof Element?e.target.closest("[data-ch-action]"):null;if(!el||!root.contains(el))return;const a=json(el,"data-ch-action");if(!obj(a))return;e.preventDefault();
104
+ const dyn=(v)=>isPath(v)||isCall(v)?val(v,d,loc):v;
105
+ switch(a.action){case"set":put(d,a.path,dyn(a.value));break;
106
+ case"append":put(d,a.path,(txt(get(d,a.path))+txt(dyn(a.value))).slice(0,200));break;
107
+ case"toggle":put(d,a.path,!truthy(get(d,a.path)));break;
108
+ case"increment":{const n=num(get(d,a.path));const by=num(a.by);put(d,a.path,(Number.isFinite(n)?n:0)+(Number.isFinite(by)?by:1));break;}
109
+ case"reset":d=structuredClone(init);break;
110
+ case"navigate":if(safe(a.href))location.assign(a.href);return;
111
+ case"copy":navigator.clipboard?.writeText(txt(a.value)).then(()=>toast("copied")).catch(()=>{});return;
112
+ case"share":if(navigator.share)navigator.share({title:document.title,url:location.href}).catch(()=>{});else navigator.clipboard?.writeText(location.href).then(()=>toast("link-copied")).catch(()=>{});return;
113
+ case"scrollTo":document.getElementById(txt(a.anchor))?.scrollIntoView({behavior:matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth",block:"start"});return;
114
+ default:return;}
115
+ render();});
116
+ render();};
117
+ for(const root of document.querySelectorAll("[data-ch-surface]"))boot(root);
118
+ `;
119
+
120
+ export const SURFACE_SCRIPT = { path: "/_cloudhal/surface.10.js", code } ;
121
+
122
+ /**
123
+ * Earlier names of the runtime, served with the current code: pages cached with them keep
124
+ * working (each version only adds to the one before; RFC-0022 §1).
125
+ */
126
+ export const SURFACE_SCRIPT_ALIASES = [
127
+ "/_cloudhal/surface.1.js",
128
+ "/_cloudhal/surface.2.js",
129
+ "/_cloudhal/surface.3.js",
130
+ "/_cloudhal/surface.4.js",
131
+ "/_cloudhal/surface.5.js",
132
+ "/_cloudhal/surface.6.js",
133
+ "/_cloudhal/surface.7.js",
134
+ "/_cloudhal/surface.8.js",
135
+ "/_cloudhal/surface.9.js",
136
+ ] ;
137
+
138
+ /** JSON for a `<script type="application/json">`: nothing in it can end the element. */
139
+ export function scriptJson(value ) {
140
+ return JSON.stringify(value ?? {})
141
+ .replace(/</g, "\\u003c")
142
+ .replace(/>/g, "\\u003e")
143
+ .replace(/&/g, "\\u0026")
144
+ .replace(/\u2028/g, "\\u2028")
145
+ .replace(/\u2029/g, "\\u2029");
146
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A surface as HTML (RFC-0020 §1, §4): each node's markup with its wrappers (visibility, carousel
3
+ * slides, preview ids) and the surface's own wrapper with its data and runtime modules. Previews
4
+ * label unknown components and theme blocks. Worker-safe.
5
+ */
6
+ import type { SurfaceSection } from "@cloudhal/core-contracts";
7
+ import type { MediaContext } from "../media.js";
8
+ import { type SurfaceContext, type SurfaceNode } from "./tree.js";
9
+ /**
10
+ * A block component in a surface with Cloudhal's built-in markup; a theme's own type has none
11
+ * (its component draws it on the site), so a preview labels it.
12
+ */
13
+ export declare function blockNodeHtml(node: SurfaceNode, media?: MediaContext, preview?: boolean): string;
14
+ /**
15
+ * RFC-0027: the box around a Carousel's i-th child (a named slide the markers link to); nothing
16
+ * for other parents. Both renderers (`nodeHtml`, `SurfaceNode.astro`) wrap each child with it.
17
+ */
18
+ export declare function slideWrapper(parent: Pick<SurfaceNode, "id" | "component" | "children">, index: number, scope: string, media?: MediaContext): [string, string];
19
+ /**
20
+ * In a live surface, a component with a visibility condition sits in a `display: contents`
21
+ * wrapper the runtime hides and shows (`hidden` while the condition is false).
22
+ */
23
+ export declare function visibilityWrapper(node: Pick<SurfaceNode, "visible" | "hidden">): [string, string];
24
+ /** The surface's id as an HTML id scope: tab groups and labels stay unique on the page. */
25
+ export declare const surfaceScope: (section: SurfaceSection) => string;
26
+ /** Opening and closing markup of the surface's wrapper. */
27
+ export declare function surfaceWrapper(section: SurfaceSection, live?: {
28
+ data: Record<string, unknown>;
29
+ locale?: string | undefined;
30
+ }, locale?: string): [string, string];
31
+ /**
32
+ * A surface as HTML: every primitive and built-in block in Cloudhal's markup. Previews label
33
+ * unknown components and theme blocks; the site leaves them out.
34
+ */
35
+ export declare function renderSurface(section: SurfaceSection, ctx?: SurfaceContext): string;