@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,184 @@
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
+
7
+ import {
8
+ INPUT_MODEL,
9
+ OVERLAY_COMPONENTS,
10
+ surfaceLoops,
11
+ usesMotion,
12
+ } from "@cloudhal/core-ts/surfaces";
13
+ import { builtInBlockHtml, isBuiltInBlock, missingBlockHtml } from "../block-html.js";
14
+ import { CAROUSEL_SCRIPT } from "../carousel-client.js";
15
+ import { escapeHtml, renderMarkdown } from "../markdown.js";
16
+
17
+ import { MOTION_SCRIPT } from "../motion-client.js";
18
+ import { OVERLAY_SCRIPT } from "../overlay-client.js";
19
+ import { SURFACE_SCRIPT, scriptJson } from "../surface-client.js";
20
+ import { CHILDREN, json } from "./markup.js";
21
+ import { withMotion } from "./motion.js";
22
+ import { primitiveHtml } from "./primitives/index.js";
23
+ import { surfaceTree } from "./tree.js";
24
+
25
+ /**
26
+ * A block component in a surface with Cloudhal's built-in markup; a theme's own type has none
27
+ * (its component draws it on the site), so a preview labels it.
28
+ */
29
+ export function blockNodeHtml(node , media , preview ) {
30
+ const attrs = `data-block-type="${escapeHtml(node.component)}"`;
31
+ if (isBuiltInBlock(node.component))
32
+ return `<div class="ch-block" ${attrs}>${builtInBlockHtml(node.component, node.props, {
33
+ markdown: (source) => renderMarkdown(source, media),
34
+ })}</div>`;
35
+ return preview
36
+ ? missingBlockHtml("div", attrs, node.component, "shown by the theme on the site")
37
+ : "";
38
+ }
39
+
40
+ /**
41
+ * RFC-0027: the box around a Carousel's i-th child (a named slide the markers link to); nothing
42
+ * for other parents. Both renderers (`nodeHtml`, `SurfaceNode.astro`) wrap each child with it.
43
+ */
44
+ export function slideWrapper(
45
+ parent ,
46
+ index ,
47
+ scope ,
48
+ media ,
49
+ ) {
50
+ if (parent.component !== "Carousel") return ["", ""];
51
+ const tr = (media?.locale ?? "en").startsWith("tr");
52
+ const n = parent.children.length;
53
+ const id = escapeHtml(`${scope}-${parent.id}-${index + 1}`);
54
+ return [
55
+ `<div class="ch-carousel__slide" id="${id}" role="group" aria-roledescription="${tr ? "slayt" : "slide"}" aria-label="${tr ? `${index + 1} / ${n}` : `${index + 1} of ${n}`}">`,
56
+ "</div>",
57
+ ];
58
+ }
59
+
60
+ /**
61
+ * In a live surface, a component with a visibility condition sits in a `display: contents`
62
+ * wrapper the runtime hides and shows (`hidden` while the condition is false).
63
+ */
64
+ export function visibilityWrapper(node ) {
65
+ if (node.visible === undefined) return ["", ""];
66
+ return [
67
+ `<div class="ch-node" data-ch-visible="${json(node.visible)}"${node.hidden ? " hidden" : ""}>`,
68
+ "</div>",
69
+ ];
70
+ }
71
+
72
+ /**
73
+ * Previews mark each component's outer element with its id, so Studio's Build view can tell which
74
+ * component the pointer is on (RFC-0020 §6 click-to-scope). The public site's markup is unchanged.
75
+ */
76
+ function markComponent(html , id , ctx ) {
77
+ if (!ctx.preview) return html;
78
+ return html.replace(/^<([a-z][a-z0-9-]*)(?=[\s>/])/, `<$1 data-component-id="${escapeHtml(id)}"`);
79
+ }
80
+
81
+ function nodeHtml(node , scope , ctx ) {
82
+ const [open, close] = visibilityWrapper(node);
83
+ if (node.entry.kind === "block")
84
+ return (
85
+ open +
86
+ markComponent(
87
+ withMotion(blockNodeHtml(node, ctx.media, ctx.preview), node.motion),
88
+ node.id,
89
+ ctx,
90
+ ) +
91
+ close
92
+ );
93
+ const inner = node.children
94
+ .map((c, i) => {
95
+ const [open, close] = slideWrapper(node, i, scope, ctx.media);
96
+ return open + nodeHtml(c, scope, ctx) + close;
97
+ })
98
+ .join("");
99
+ return (
100
+ open +
101
+ markComponent(
102
+ withMotion(primitiveHtml(node, scope, ctx.media), node.motion),
103
+ node.id,
104
+ ctx,
105
+ ).replace(CHILDREN, inner) +
106
+ close
107
+ );
108
+ }
109
+
110
+ /** The surface's id as an HTML id scope: tab groups and labels stay unique on the page. */
111
+ export const surfaceScope = (section ) => `ch-${section.id}`;
112
+
113
+ /** Opening and closing markup of the surface's wrapper. */
114
+ export function surfaceWrapper(
115
+ section ,
116
+ live ,
117
+ locale ,
118
+ ) {
119
+ const scope = surfaceScope(section);
120
+ // RFC-0022 §2: fields need the runtime to compute; say so only when it cannot run.
121
+ const fields = live && section.components.some((c) => INPUT_MODEL[c.component]);
122
+ const noscript = fields
123
+ ? `<noscript><p class="ch-noscript">${
124
+ live?.locale?.startsWith("tr")
125
+ ? "Bu araç hesaplamak için JavaScript gerektirir."
126
+ : "This tool needs JavaScript to calculate."
127
+ }</p></noscript>`
128
+ : "";
129
+ // RFC-0024 §7: the motion module, only for surfaces that move (a module runs once per page).
130
+ // RFC-0024 §1: anything that moves on its own for long gets the reader's pause control (WCAG
131
+ // 2.2.2); it shows only where motion plays.
132
+ const lang = locale ?? live?.locale ?? "en";
133
+ const pause = surfaceLoops(section)
134
+ ? `<button type="button" class="ch-motion-toggle" data-ch-motion-toggle aria-pressed="false">${lang.startsWith("tr") ? "Hareketi duraklat" : "Pause motion"}</button>`
135
+ : "";
136
+ const motion =
137
+ (usesMotion(section)
138
+ ? `${pause}<script type="module" src="${MOTION_SCRIPT.path}"></script>`
139
+ : "") +
140
+ // RFC-0025 §3: the overlay module, only for surfaces with an overlay.
141
+ (section.components.some((c) => OVERLAY_COMPONENTS.has(c.component))
142
+ ? `<script type="module" src="${OVERLAY_SCRIPT.path}"></script>`
143
+ : "") +
144
+ // RFC-0027 27b: the carousel module, only for surfaces with a carousel.
145
+ (section.components.some((c) => c.component === "Carousel")
146
+ ? `<script type="module" src="${CAROUSEL_SCRIPT.path}"></script>`
147
+ : "");
148
+ return [
149
+ `<section class="ch-surface" data-section-id="${escapeHtml(section.id)}" data-kind="surface" data-catalog="${escapeHtml(section.catalog)}"${live ? ` data-ch-surface="${escapeHtml(scope)}"` : ""}>`,
150
+ live
151
+ ? // RFC-0020 §4: the data as inert JSON, then Cloudhal's runtime (one module per page).
152
+ `${noscript}<script type="application/json" data-ch-state>${scriptJson(live.data)}</script><script type="module" src="${SURFACE_SCRIPT.path}"></script>${motion}</section>`
153
+ : `${motion}</section>`,
154
+ ];
155
+ }
156
+
157
+ /**
158
+ * A surface as HTML: every primitive and built-in block in Cloudhal's markup. Previews label
159
+ * unknown components and theme blocks; the site leaves them out.
160
+ */
161
+ export function renderSurface(section , ctx = {}) {
162
+ const tree = surfaceTree(section, ctx);
163
+ const [open, close] = surfaceWrapper(
164
+ section,
165
+ tree.live ? { data: tree.data, locale: ctx.media?.locale } : undefined,
166
+ ctx.media?.locale,
167
+ );
168
+ const body = tree.root ? nodeHtml(tree.root, surfaceScope(section), ctx) : "";
169
+ const missing = ctx.preview
170
+ ? tree.unknown
171
+ .map((id) => {
172
+ const c = section.components.find((x) => x.id === id);
173
+ return missingBlockHtml(
174
+ "div",
175
+ `data-component-id="${escapeHtml(id)}"`,
176
+ c?.component ?? id,
177
+ "unknown block type",
178
+ );
179
+ })
180
+ .join("")
181
+ : "";
182
+ if (!body && !missing) return ctx.preview ? `${open}${close}` : "";
183
+ return `${open}${body}${missing}${close}`;
184
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Markup helpers the surface renderers share (RFC-0020): escaped values, allow-listed `data-*`
3
+ * attributes, paint and ambient backgrounds, live bindings, field extras and icons. Worker-safe.
4
+ */
5
+ import { type IconOptions } from "@cloudhal/core-ts/icons";
6
+ import type { MediaContext } from "../media.js";
7
+ import type { SurfaceNode } from "./tree.js";
8
+ /** What a primitive's renderer reads of its node. */
9
+ export type PrimitiveNode = Pick<SurfaceNode, "id" | "component" | "props" | "children"> & Partial<Pick<SurfaceNode, "raw" | "live" | "split" | "overlay" | "tip" | "priority">>;
10
+ /** Where a primitive draws: its HTML id (scoped, escaped), the surface's scope, the media. */
11
+ export interface PrimitiveContext {
12
+ readonly id: string;
13
+ readonly scope: string;
14
+ readonly media?: MediaContext | undefined;
15
+ }
16
+ /** A primitive's markup around `CHILDREN`, from resolved props (escaped here). */
17
+ export type PrimitiveRenderer = (node: PrimitiveNode, ctx: PrimitiveContext) => string;
18
+ /** Where a primitive's children go in its markup. */
19
+ export declare const CHILDREN = "<!--ch-children-->";
20
+ export declare const str: (v: unknown) => string;
21
+ export declare const attr: (name: string, v: unknown, allowed?: readonly string[]) => string;
22
+ export declare const SPACE: string[];
23
+ /**
24
+ * RFC-0023 §4: a band's or card's paint as `data-surface` (the theme draws it from the color
25
+ * roles); an old `tone` maps to its surface and also stays as `data-tone` for themes that style it.
26
+ */
27
+ export declare const paint: (p: Record<string, unknown>) => string;
28
+ /**
29
+ * RFC-0024 §4: a moving background as attributes the theme draws from the color roles, and for
30
+ * particles the canvas the ambient module paints (hidden from assistive technology, under the
31
+ * content). Only known values pass.
32
+ */
33
+ export declare const ambientOf: (p: Record<string, unknown>, cards?: boolean) => {
34
+ attrs: string;
35
+ canvas: string;
36
+ };
37
+ /** An anchor for `#links`; never one of the ids the renderer makes itself (`ch-…`). */
38
+ export declare const anchor: (v: unknown) => string;
39
+ export declare const ALIGN: string[];
40
+ export declare const isBinding: (v: unknown) => boolean;
41
+ export declare const json: (v: unknown) => string;
42
+ /** A text prop: escaped, and kept live by the runtime when it is bound in a live surface. */
43
+ export declare function text(node: Pick<SurfaceNode, "props"> & Partial<Pick<SurfaceNode, "raw" | "live">>, name: string): string;
44
+ /** The pointer an input writes to (its `value` bound with {path}), in a live surface. */
45
+ export declare function model(node: Partial<Pick<SurfaceNode, "raw" | "live">>, prop?: string): string;
46
+ /**
47
+ * RFC-0022 §2: a field's help text (linked with `aria-describedby`) and its invalid state, which
48
+ * the runtime keeps in step when `invalid` is bound or computed.
49
+ */
50
+ export declare function fieldExtras(node: Pick<SurfaceNode, "props"> & Partial<Pick<SurfaceNode, "raw" | "live">>, id: string): {
51
+ attrs: string;
52
+ help: string;
53
+ };
54
+ /** An overlay's close button (Invoker Commands; the overlay module where they are missing). */
55
+ export declare function closeButton(id: string, tr: boolean, media?: MediaContext): string;
56
+ /** RFC-0026: an icon in the site's weight and the theme's drawings. */
57
+ export declare function iconOf(name: string, media?: MediaContext, o?: IconOptions): string;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Markup helpers the surface renderers share (RFC-0020): escaped values, allow-listed `data-*`
3
+ * attributes, paint and ambient backgrounds, live bindings, field extras and icons. Worker-safe.
4
+ */
5
+ import { renderIcon } from "@cloudhal/core-ts/icons";
6
+ import {
7
+ AMBIENT_KINDS,
8
+ PARTICLE_PRESETS,
9
+ SURFACE_STYLES,
10
+ TONE_SURFACE,
11
+ } from "@cloudhal/core-ts/surfaces";
12
+ import { escapeHtml } from "../markdown.js";
13
+
14
+
15
+
16
+ /** What a primitive's renderer reads of its node. */
17
+
18
+
19
+
20
+ /** Where a primitive draws: its HTML id (scoped, escaped), the surface's scope, the media. */
21
+
22
+
23
+
24
+
25
+
26
+
27
+ /** A primitive's markup around `CHILDREN`, from resolved props (escaped here). */
28
+
29
+
30
+ /** Where a primitive's children go in its markup. */
31
+ export const CHILDREN = "<!--ch-children-->";
32
+
33
+ export const str = (v ) => (v === undefined || v === null ? "" : String(v));
34
+ export const attr = (name , v , allowed ) => {
35
+ const s = str(v);
36
+ if (!s || (allowed && !allowed.includes(s))) return "";
37
+ return ` data-${name}="${escapeHtml(s)}"`;
38
+ };
39
+ export const SPACE = ["none", "s", "m", "l", "xl"];
40
+ const TONE = ["surface", "muted", "brand", "inverse"];
41
+ /**
42
+ * RFC-0023 §4: a band's or card's paint as `data-surface` (the theme draws it from the color
43
+ * roles); an old `tone` maps to its surface and also stays as `data-tone` for themes that style it.
44
+ */
45
+ export const paint = (p ) => {
46
+ const surface = str(p.surface);
47
+ if (surface && (SURFACE_STYLES ).includes(surface))
48
+ return ` data-surface="${surface}"`;
49
+ const tone = str(p.tone);
50
+ return tone && TONE.includes(tone)
51
+ ? ` data-surface="${TONE_SURFACE[tone ]}" data-tone="${tone}"`
52
+ : "";
53
+ };
54
+ /**
55
+ * RFC-0024 §4: a moving background as attributes the theme draws from the color roles, and for
56
+ * particles the canvas the ambient module paints (hidden from assistive technology, under the
57
+ * content). Only known values pass.
58
+ */
59
+ export const ambientOf = (
60
+ p ,
61
+ cards = false,
62
+ ) => {
63
+ const a = p.ambient;
64
+ if (typeof a !== "object" || a === null) return { attrs: "", canvas: "" };
65
+ const amb = a ;
66
+ const kind = str(amb.kind);
67
+ if (!(AMBIENT_KINDS ).includes(kind) || (cards && kind === "particles"))
68
+ return { attrs: "", canvas: "" };
69
+ const preset =
70
+ kind === "particles" && (PARTICLE_PRESETS ).includes(str(amb.preset))
71
+ ? str(amb.preset)
72
+ : kind === "particles"
73
+ ? "dots"
74
+ : "";
75
+ return {
76
+ attrs: ` data-ch-ambient="${kind}"${preset ? ` data-ch-preset="${preset}"` : ""}${attr("ch-density", amb.density, ["low", "medium", "high"])}${attr("ch-colors", amb.colors, ["brand", "accent", "brand-accent", "neutral"])}${kind === "particles" && amb.interactive === true ? " data-ch-interactive" : ""}`,
77
+ canvas: kind === "particles" ? '<canvas class="ch-ambient" aria-hidden="true"></canvas>' : "",
78
+ };
79
+ };
80
+ /** An anchor for `#links`; never one of the ids the renderer makes itself (`ch-…`). */
81
+ export const anchor = (v ) => {
82
+ const s = str(v);
83
+ return s && /^[a-z][a-z0-9-]{0,40}$/.test(s) && !s.startsWith("ch-") ? ` id="${s}"` : "";
84
+ };
85
+ export const ALIGN = ["start", "center", "end", "stretch"];
86
+
87
+ export const isBinding = (v ) =>
88
+ typeof v === "object" && v !== null && !Array.isArray(v) && ("path" in v || "call" in v);
89
+ export const json = (v ) => escapeHtml(JSON.stringify(v));
90
+
91
+ /** A text prop: escaped, and kept live by the runtime when it is bound in a live surface. */
92
+ export function text(
93
+ node ,
94
+ name ,
95
+ ) {
96
+ const value = escapeHtml(str(node.props[name]));
97
+ return node.live && isBinding(node.raw?.[name])
98
+ ? `<span data-ch-text="${json(node.raw?.[name])}">${value}</span>`
99
+ : value;
100
+ }
101
+
102
+ /** The pointer an input writes to (its `value` bound with {path}), in a live surface. */
103
+ export function model(node , prop = "value") {
104
+ const v = node.raw?.[prop] ;
105
+ return node.live && typeof v?.path === "string" ? ` data-ch-model="${escapeHtml(v.path)}"` : "";
106
+ }
107
+
108
+ /**
109
+ * RFC-0022 §2: a field's help text (linked with `aria-describedby`) and its invalid state, which
110
+ * the runtime keeps in step when `invalid` is bound or computed.
111
+ */
112
+ export function fieldExtras(
113
+ node ,
114
+ id ,
115
+ ) {
116
+ const help = str(node.props.help);
117
+ const raw = node.raw?.invalid;
118
+ const invalid = node.props.invalid === true;
119
+ return {
120
+ attrs: `${help ? ` aria-describedby="${id}-help"` : ""}${invalid ? ' aria-invalid="true"' : ""}${
121
+ node.live && isBinding(raw) ? ` data-ch-invalid="${json(raw)}"` : ""
122
+ }`,
123
+ help: help ? `<span class="ch-field__help" id="${id}-help">${escapeHtml(help)}</span>` : "",
124
+ };
125
+ }
126
+
127
+ /** An overlay's close button (Invoker Commands; the overlay module where they are missing). */
128
+ export function closeButton(id , tr , media ) {
129
+ return `<button type="button" class="ch-dialog__close" command="close" commandfor="${id}" aria-label="${tr ? "Kapat" : "Close"}">${iconOf("close", media)}</button>`;
130
+ }
131
+
132
+ /** RFC-0026: an icon in the site's weight and the theme's drawings. */
133
+ export function iconOf(name , media , o = {}) {
134
+ return renderIcon(name, { ...o, weight: media?.icons?.weight, set: media?.icons?.set });
135
+ }
@@ -0,0 +1,33 @@
1
+ import type { SurfaceNode } from "./tree.js";
2
+ export interface MotionFields {
3
+ morph?: string;
4
+ reveal?: string | undefined;
5
+ scroll?: string;
6
+ depth?: number;
7
+ loop?: string;
8
+ hover?: string;
9
+ speed?: string;
10
+ delay?: number;
11
+ stagger?: boolean;
12
+ replay?: boolean;
13
+ }
14
+ /**
15
+ * A component's motion as attributes the theme's motion layer styles: the reveal (its own, or
16
+ * the one a staggered parent hands down), speed, delay in stagger steps (`data-ch-d`), hover and
17
+ * replay. Only known values pass, so nothing a model wrote reaches the page as free text.
18
+ */
19
+ export declare function motionAttrs(motion: MotionFields | undefined, stagger?: {
20
+ reveal: string;
21
+ index: number;
22
+ }): string;
23
+ /**
24
+ * RFC-0024 24c: a text split into pieces for kinetic type: words (or, for `chars`, words of
25
+ * characters), each with its place in the sequence as `--ch-i`, hidden from screen readers,
26
+ * which read the whole text once from a visually hidden copy. `lines` are numbered in the page,
27
+ * once the line breaks are known (the motion module).
28
+ */
29
+ export declare function splitHtml(text: string, mode: "words" | "chars" | "lines"): string;
30
+ /** RFC-0024 24c: a heading's text with its effect (highlight, gradient text or rotating words). */
31
+ export declare function headingInner(node: Pick<SurfaceNode, "props"> & Partial<Pick<SurfaceNode, "raw" | "live" | "split">>): string;
32
+ /** The node's motion attributes on the outer element of its markup. */
33
+ export declare function withMotion(html: string, motion: string | undefined): string;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Motion on a surface (RFC-0024 §2, §7): a component's motion as `data-ch-*` attributes, kinetic
3
+ * type (split text, heading effects) and placing the attributes on a markup's outer element.
4
+ * Worker-safe.
5
+ */
6
+ import {
7
+ MOTION_HOVERS,
8
+ MOTION_LOOPS,
9
+ MOTION_REVEALS,
10
+ MOTION_SCROLLS,
11
+ MOTION_SPEEDS,
12
+ } from "@cloudhal/core-ts/surfaces";
13
+ import { escapeHtml } from "../markdown.js";
14
+ import { str, text } from "./markup.js";
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ /**
31
+ * A component's motion as attributes the theme's motion layer styles: the reveal (its own, or
32
+ * the one a staggered parent hands down), speed, delay in stagger steps (`data-ch-d`), hover and
33
+ * replay. Only known values pass, so nothing a model wrote reaches the page as free text.
34
+ */
35
+ export function motionAttrs(
36
+ motion ,
37
+ stagger ,
38
+ ) {
39
+ const out = [];
40
+ const reveal = motion?.reveal ?? stagger?.reveal;
41
+ if (reveal && (MOTION_REVEALS ).includes(reveal))
42
+ out.push(` data-ch-reveal="${reveal}"`);
43
+ if (motion?.speed && (MOTION_SPEEDS ).includes(motion.speed))
44
+ out.push(` data-ch-speed="${motion.speed}"`);
45
+ const delay =
46
+ (Number.isInteger(motion?.delay) ? Math.min(4, Math.max(0, motion?.delay )) : 0) +
47
+ (stagger?.index ?? 0);
48
+ if (reveal && delay > 0) out.push(` data-ch-d="${Math.min(delay, 16)}"`);
49
+ if (motion?.hover && (MOTION_HOVERS ).includes(motion.hover))
50
+ out.push(` data-ch-hover="${motion.hover}"`);
51
+ if (reveal && motion?.replay === true) out.push(" data-ch-replay");
52
+ // RFC-0024 24b: moves with the scroll instead (never together with a reveal).
53
+ if (!reveal && motion?.scroll && (MOTION_SCROLLS ).includes(motion.scroll)) {
54
+ out.push(` data-ch-scroll="${motion.scroll}"`);
55
+ const depth = motion.depth;
56
+ if (Number.isInteger(depth) && depth !== 0 && Math.abs(depth ) <= 3)
57
+ out.push(` data-ch-dep="${depth}"`);
58
+ }
59
+ // RFC-0024 §5: a morph key becomes the element's view-transition name (the same key on two
60
+ // pages moves one into the other on navigation).
61
+ if (typeof motion?.morph === "string" && /^[a-z][a-z0-9-]{0,30}$/.test(motion.morph))
62
+ out.push(` style="view-transition-name:ch-m-${motion.morph}"`);
63
+ // RFC-0024 24c: a loop decorates on its own (never with a reveal or a scroll effect).
64
+ if (
65
+ !reveal &&
66
+ !motion?.scroll &&
67
+ motion?.loop &&
68
+ (MOTION_LOOPS ).includes(motion.loop)
69
+ )
70
+ out.push(` data-ch-loop="${motion.loop}"`);
71
+ return out.join("");
72
+ }
73
+
74
+ /**
75
+ * RFC-0024 24c: a text split into pieces for kinetic type: words (or, for `chars`, words of
76
+ * characters), each with its place in the sequence as `--ch-i`, hidden from screen readers,
77
+ * which read the whole text once from a visually hidden copy. `lines` are numbered in the page,
78
+ * once the line breaks are known (the motion module).
79
+ */
80
+ export function splitHtml(text , mode ) {
81
+ const words = text.split(/\s+/).filter(Boolean);
82
+ let i = 0;
83
+ const pieces = words.map((w) => {
84
+ if (mode !== "chars")
85
+ return `<span class="ch-w"${mode === "words" ? ` style="--ch-i:${i++}"` : ""}>${escapeHtml(w)}</span>`;
86
+ const chars = Array.from(w)
87
+ .map((c) => `<span class="ch-c" style="--ch-i:${i++}">${escapeHtml(c)}</span>`)
88
+ .join("");
89
+ return `<span class="ch-w">${chars}</span>`;
90
+ });
91
+ return `<span class="sr-only">${escapeHtml(text)}</span><span class="ch-split" data-mode="${mode}" aria-hidden="true">${pieces.join(" ")}</span>`;
92
+ }
93
+
94
+ /** RFC-0024 24c: a heading's text with its effect (highlight, gradient text or rotating words). */
95
+ export function headingInner(
96
+ node ,
97
+ ) {
98
+ const p = node.props;
99
+ const raw = str(p.text);
100
+ if (node.split) return splitHtml(raw.replace(/\*/g, ""), node.split);
101
+ const words = Array.isArray(p.words) ? p.words.slice(0, 6).map(str).filter(Boolean) : [];
102
+ if (p.effect === "rotate-words" && words.length >= 2) {
103
+ const [before, after = ""] = raw.includes("{words}")
104
+ ? raw.split("{words}", 2)
105
+ : [`${raw} `, ""];
106
+ const turns = words
107
+ .map(
108
+ (w, i) =>
109
+ `<span class="ch-rotate__word"${i === 0 ? " data-active" : ""}>${escapeHtml(w)}</span>`,
110
+ )
111
+ .join("");
112
+ return `${escapeHtml(before ?? "")}<span class="sr-only">${escapeHtml(words.join(", "))}</span><span class="ch-rotate" data-ch-rotate aria-hidden="true">${turns}</span>${escapeHtml(after)}`;
113
+ }
114
+ if (p.effect === "highlight") {
115
+ const marked = /\*([^*]+)\*/.exec(raw);
116
+ if (marked)
117
+ return `${escapeHtml(raw.slice(0, marked.index))}<span class="ch-hl">${escapeHtml(marked[1] )}</span>${escapeHtml(raw.slice(marked.index + marked[0].length).replace(/\*/g, ""))}`;
118
+ const at = raw.trimEnd().lastIndexOf(" ");
119
+ return at < 0
120
+ ? `<span class="ch-hl">${escapeHtml(raw)}</span>`
121
+ : `${escapeHtml(raw.slice(0, at + 1))}<span class="ch-hl">${escapeHtml(raw.slice(at + 1))}</span>`;
122
+ }
123
+ if (p.effect === "gradient-text")
124
+ return `<span class="ch-gradient-text">${escapeHtml(raw)}</span>`;
125
+ return text(node, "text");
126
+ }
127
+
128
+ /** The node's motion attributes on the outer element of its markup. */
129
+ export function withMotion(html , motion ) {
130
+ if (!motion) return html;
131
+ return html.replace(/^<([a-z][a-z0-9-]*)(?=[\s>/])/, `<$1${motion}`);
132
+ }
@@ -0,0 +1,2 @@
1
+ import { type PrimitiveRenderer } from "../markup.js";
2
+ export declare const carouselHtml: PrimitiveRenderer;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * RFC-0027: a Carousel, a scroll-snap track of slides (each child wrapped by `slideWrapper`),
3
+ * markers as links to the slides and arrows the carousel module reveals; all of it works without
4
+ * it.
5
+ */
6
+ import { escapeHtml } from "../../markdown.js";
7
+ import { imageAttributes, imgHtml, } from "../../media.js";
8
+ import { attr, CHILDREN, iconOf, SPACE, str } from "../markup.js";
9
+
10
+
11
+ /** RFC-0027 27c: a gallery's markers can be its slides' first images, small. */
12
+ function thumbHtml(slide , i , media ) {
13
+ const find = (n , depth ) =>
14
+ !n || depth > 3
15
+ ? undefined
16
+ : n.component === "Image"
17
+ ? n
18
+ : n.children.map((c) => find(c, depth + 1)).find(Boolean);
19
+ const img = find(slide, 0);
20
+ const m = /^asset:([a-z]+_[A-Za-z0-9]{6,32})$/.exec(str(img?.props.asset));
21
+ const asset = m ? media?.assets?.get(m[1] ) : undefined;
22
+ if (!asset) return String(i + 1);
23
+ const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en";
24
+ return imgHtml(
25
+ imageAttributes(
26
+ asset,
27
+ { alt: "" },
28
+ {
29
+ locale: media?.locale ?? defaultLocale,
30
+ defaultLocale,
31
+ transform: media?.transform ?? "none",
32
+ ...(media?.budget ? { budget: media.budget } : {}),
33
+ sizes: "5rem",
34
+ ...(media?.preview ? { preview: true } : {}),
35
+ },
36
+ ),
37
+ ).replace(/ alt="[^"]*"/, ' alt=""');
38
+ }
39
+
40
+ /** The markers: links to the slides, as dots, numbers or (a gallery's) thumbnails. */
41
+ function markersHtml(
42
+ slides ,
43
+ o ,
44
+ ) {
45
+ const { id, style, tr, media } = o;
46
+ return `<nav class="ch-carousel__markers" data-style="${style}" aria-label="${tr ? "Slaytlar" : "Slides"}">${slides
47
+ .map(
48
+ (c, i) =>
49
+ `<a href="#${id}-${i + 1}" aria-label="${tr ? "Slayt" : "Slide"} ${i + 1}">${style === "dots" ? "" : style === "thumbs" ? thumbHtml(c, i, media) : i + 1}</a>`,
50
+ )
51
+ .join("")}</nav>`;
52
+ }
53
+
54
+ /**
55
+ * RFC-0027 27d: a hero that plays on its own puts its rotation control first in Tab order; the
56
+ * module shows it only where motion may play, and swaps its words and icon.
57
+ */
58
+ function rotateHtml(tr , media ) {
59
+ const stopWord = tr ? "Slayt geçişini durdur" : "Stop slide rotation";
60
+ const startWord = tr ? "Slayt geçişini başlat" : "Start slide rotation";
61
+ return `<button type="button" class="ch-carousel__rotate" data-ch-carousel="rotate" data-ch-pending data-state="playing" data-stop="${stopWord}" data-start="${startWord}" aria-label="${stopWord}"><span data-when="playing">${iconOf("pause", media)}</span><span data-when="stopped">${iconOf("play", media)}</span></button>`;
62
+ }
63
+
64
+ export const carouselHtml = (node, { id, media }) => {
65
+ const p = node.props;
66
+ const tr = (media?.locale ?? "en").startsWith("tr");
67
+ const n = node.children.length;
68
+ const variant = ["hero", "gallery", "testimonials"].includes(str(p.variant))
69
+ ? str(p.variant)
70
+ : "rail";
71
+ const controls = ["arrows", "markers", "none"].includes(str(p.controls))
72
+ ? str(p.controls)
73
+ : "both";
74
+ const arrows = controls === "both" || controls === "arrows";
75
+ const arrow = (dir ) =>
76
+ `<button type="button" class="ch-carousel__arrow" data-ch-carousel="${dir}" data-ch-pending aria-controls="${id}-track" aria-label="${dir === "prev" ? (tr ? "Önceki slayt" : "Previous slide") : tr ? "Sonraki slayt" : "Next slide"}">${iconOf(dir === "prev" ? "chevron-left" : "chevron-right", media)}</button>`;
77
+ const style =
78
+ p.markers === "dots"
79
+ ? "dots"
80
+ : p.markers === "thumbs" && variant === "gallery"
81
+ ? "thumbs"
82
+ : "numbers";
83
+ const markers =
84
+ controls === "both" || controls === "markers"
85
+ ? markersHtml(node.children, { id, style, tr, media })
86
+ : "";
87
+ const autoplay =
88
+ variant === "hero" && (p.autoplay === "slow" || p.autoplay === "normal") ? str(p.autoplay) : "";
89
+ const rotate = autoplay ? rotateHtml(tr, media) : "";
90
+ const bar =
91
+ arrows || markers
92
+ ? `<div class="ch-carousel__controls">${arrows ? arrow("prev") : ""}${markers}${arrows ? arrow("next") : ""}</div>`
93
+ : "";
94
+ return `<section class="ch-carousel" id="${id}" data-variant="${variant}"${attr("per-view", p.perView === undefined ? undefined : String(p.perView), ["1", "2", "3", "4"])}${attr("item", p.itemWidth, ["s", "m", "l"])}${attr("peek", p.peek, ["none", "s", "m"])}${attr("align", p.align, ["start", "center"])}${attr("gap", p.gap, SPACE)}${attr("aspect", p.aspect, ["16:9", "21:9", "4:3", "1:1", "3:4"])}${variant === "hero" && p.loop === true ? " data-loop" : ""}${autoplay ? ` data-autoplay="${autoplay}"` : ""} data-count="${n}" role="region" aria-roledescription="${tr ? "kaydırmalı alan" : "carousel"}" aria-label="${escapeHtml(str(p.label))}">${rotate}<div class="ch-carousel__track" id="${id}-track" tabindex="0">${CHILDREN}</div>${bar}</section>`;
95
+ };
@@ -0,0 +1,13 @@
1
+ import { type PrimitiveRenderer } from "../markup.js";
2
+ export declare const headingHtml: PrimitiveRenderer;
3
+ export declare const textHtml: PrimitiveRenderer;
4
+ export declare const markdownHtml: PrimitiveRenderer;
5
+ export declare const imageHtml: PrimitiveRenderer;
6
+ /** Button and Link: a link, an action the runtime runs, or an overlay's opener. */
7
+ export declare const buttonLinkHtml: PrimitiveRenderer;
8
+ export declare const badgeHtml: PrimitiveRenderer;
9
+ /** RFC-0026: an icon on its own; named only when it carries meaning alone. */
10
+ export declare const iconHtml: PrimitiveRenderer;
11
+ export declare const statHtml: PrimitiveRenderer;
12
+ export declare const quoteHtml: PrimitiveRenderer;
13
+ export declare const listHtml: PrimitiveRenderer;