@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.
- package/LICENSE +202 -0
- package/README.md +36 -2
- package/dist/src/ambient-client.d.ts +17 -0
- package/dist/src/ambient-client.js +55 -0
- package/dist/src/analytics-client.d.ts +17 -0
- package/dist/src/analytics-client.js +96 -0
- package/dist/src/analytics-middleware.d.ts +6 -0
- package/dist/src/analytics-middleware.js +43 -0
- package/dist/src/analytics-node.d.ts +46 -0
- package/dist/src/analytics-node.js +134 -0
- package/dist/src/analytics.d.ts +117 -0
- package/dist/src/analytics.js +372 -0
- package/dist/src/archive.d.ts +106 -0
- package/dist/src/archive.js +207 -0
- package/dist/src/astro-env.d.ts +21 -0
- package/dist/src/block-html.d.ts +14 -0
- package/dist/src/block-html.js +103 -0
- package/dist/src/blocks.d.ts +24 -0
- package/dist/src/blocks.js +66 -0
- package/dist/src/cache-tags.d.ts +25 -0
- package/dist/src/cache-tags.js +59 -0
- package/dist/src/carousel-client.d.ts +28 -0
- package/dist/src/carousel-client.js +67 -0
- package/dist/src/chart.d.ts +34 -0
- package/dist/src/chart.js +182 -0
- package/dist/src/chrome-client.d.ts +27 -0
- package/dist/src/chrome-client.js +64 -0
- package/dist/src/cloudflare-entry.d.ts +87 -0
- package/dist/src/cloudflare-entry.js +548 -0
- package/dist/src/comments-client.d.ts +11 -0
- package/dist/src/comments-client.js +58 -0
- package/dist/src/comments-html.d.ts +42 -0
- package/dist/src/comments-html.js +303 -0
- package/dist/src/comments-middleware.d.ts +6 -0
- package/dist/src/comments-middleware.js +38 -0
- package/dist/src/comments-node.d.ts +42 -0
- package/dist/src/comments-node.js +112 -0
- package/dist/src/comments-view.d.ts +68 -0
- package/dist/src/comments-view.js +174 -0
- package/dist/src/comments.d.ts +66 -0
- package/dist/src/comments.js +258 -0
- package/dist/src/components/Block.astro +39 -0
- package/dist/src/components/Body.astro +43 -0
- package/dist/src/components/Comments.astro +19 -0
- package/dist/src/components/ContentList.astro +31 -0
- package/dist/src/components/EntryArticle.astro +31 -0
- package/dist/src/components/Hero.astro +36 -0
- package/dist/src/components/Image.astro +36 -0
- package/dist/src/components/RichText.astro +19 -0
- package/dist/src/components/Sections.astro +66 -0
- package/dist/src/components/SeoHead.astro +22 -0
- package/dist/src/components/Surface.astro +36 -0
- package/dist/src/components/SurfaceNode.astro +82 -0
- package/dist/src/components/index.d.ts +12 -0
- package/dist/src/components/index.js +12 -0
- package/dist/src/csp.d.ts +20 -0
- package/dist/src/csp.js +28 -0
- package/dist/src/embed-client.d.ts +38 -0
- package/dist/src/embed-client.js +98 -0
- package/dist/src/embed-middleware.d.ts +9 -0
- package/dist/src/embed-middleware.js +49 -0
- package/dist/src/feeds.d.ts +72 -0
- package/dist/src/feeds.js +246 -0
- package/dist/src/gates.d.ts +25 -0
- package/dist/src/gates.js +63 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +17 -0
- package/dist/src/integration.d.ts +55 -0
- package/dist/src/integration.js +244 -0
- package/dist/src/kit.d.ts +48 -0
- package/dist/src/kit.js +83 -0
- package/dist/src/locale-feeds.d.ts +29 -0
- package/dist/src/locale-feeds.js +152 -0
- package/dist/src/locale-middleware.d.ts +5 -0
- package/dist/src/locale-middleware.js +26 -0
- package/dist/src/locales.d.ts +87 -0
- package/dist/src/locales.js +336 -0
- package/dist/src/markdown.d.ts +83 -0
- package/dist/src/markdown.js +533 -0
- package/dist/src/media-middleware.d.ts +5 -0
- package/dist/src/media-middleware.js +18 -0
- package/dist/src/media-route.d.ts +47 -0
- package/dist/src/media-route.js +238 -0
- package/dist/src/media.d.ts +109 -0
- package/dist/src/media.js +298 -0
- package/dist/src/motion-client.d.ts +39 -0
- package/dist/src/motion-client.js +115 -0
- package/dist/src/navigation.d.ts +127 -0
- package/dist/src/navigation.js +382 -0
- package/dist/src/not-found.d.ts +16 -0
- package/dist/src/not-found.js +41 -0
- package/dist/src/overlay-client.d.ts +20 -0
- package/dist/src/overlay-client.js +49 -0
- package/dist/src/prefs-client.d.ts +14 -0
- package/dist/src/prefs-client.js +18 -0
- package/dist/src/preview.d.ts +70 -0
- package/dist/src/preview.js +551 -0
- package/dist/src/resolver.d.ts +71 -0
- package/dist/src/resolver.js +206 -0
- package/dist/src/routing.d.ts +108 -0
- package/dist/src/routing.js +285 -0
- package/dist/src/runtime-workerd.d.ts +87 -0
- package/dist/src/runtime-workerd.js +275 -0
- package/dist/src/runtime.d.ts +59 -0
- package/dist/src/runtime.js +153 -0
- package/dist/src/safe-urls.d.ts +13 -0
- package/dist/src/safe-urls.js +35 -0
- package/dist/src/sanitize.d.ts +7 -0
- package/dist/src/sanitize.js +217 -0
- package/dist/src/search-client.d.ts +29 -0
- package/dist/src/search-client.js +92 -0
- package/dist/src/search-limit.d.ts +36 -0
- package/dist/src/search-limit.js +66 -0
- package/dist/src/search.d.ts +64 -0
- package/dist/src/search.js +155 -0
- package/dist/src/seo.d.ts +85 -0
- package/dist/src/seo.js +468 -0
- package/dist/src/site-dispatch.d.ts +37 -0
- package/dist/src/site-dispatch.js +86 -0
- package/dist/src/site-hosts.d.ts +35 -0
- package/dist/src/site-hosts.js +110 -0
- package/dist/src/source.d.ts +227 -0
- package/dist/src/source.js +794 -0
- package/dist/src/static-gates.d.ts +3 -0
- package/dist/src/static-gates.js +28 -0
- package/dist/src/static-headers.d.ts +30 -0
- package/dist/src/static-headers.js +140 -0
- package/dist/src/static-media.d.ts +4 -0
- package/dist/src/static-media.js +65 -0
- package/dist/src/static-redirects.d.ts +4 -0
- package/dist/src/static-redirects.js +40 -0
- package/dist/src/surface-client.d.ts +34 -0
- package/dist/src/surface-client.js +146 -0
- package/dist/src/surfaces/html.d.ts +35 -0
- package/dist/src/surfaces/html.js +184 -0
- package/dist/src/surfaces/markup.d.ts +57 -0
- package/dist/src/surfaces/markup.js +135 -0
- package/dist/src/surfaces/motion.d.ts +33 -0
- package/dist/src/surfaces/motion.js +132 -0
- package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
- package/dist/src/surfaces/primitives/carousel.js +95 -0
- package/dist/src/surfaces/primitives/content.d.ts +13 -0
- package/dist/src/surfaces/primitives/content.js +159 -0
- package/dist/src/surfaces/primitives/data.d.ts +5 -0
- package/dist/src/surfaces/primitives/data.js +80 -0
- package/dist/src/surfaces/primitives/index.d.ts +54 -0
- package/dist/src/surfaces/primitives/index.js +106 -0
- package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
- package/dist/src/surfaces/primitives/inputs.js +68 -0
- package/dist/src/surfaces/primitives/layout.d.ts +14 -0
- package/dist/src/surfaces/primitives/layout.js +61 -0
- package/dist/src/surfaces/primitives/motion.d.ts +9 -0
- package/dist/src/surfaces/primitives/motion.js +45 -0
- package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
- package/dist/src/surfaces/primitives/overlays.js +79 -0
- package/dist/src/surfaces/tree.d.ts +107 -0
- package/dist/src/surfaces/tree.js +321 -0
- package/dist/src/surfaces.d.ts +14 -0
- package/dist/src/surfaces.js +33 -0
- package/dist/src/taxonomy.d.ts +86 -0
- package/dist/src/taxonomy.js +268 -0
- package/dist/src/theme-settings.d.ts +24 -0
- package/dist/src/theme-settings.js +111 -0
- package/package.json +219 -3
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content primitives (RFC-0020 §2): headings, text, images, buttons and links, badges, icons,
|
|
3
|
+
* stats, quotes and lists.
|
|
4
|
+
*/
|
|
5
|
+
import { escapeHtml, renderMarkdown, safeHref } from "../../markdown.js";
|
|
6
|
+
import { IMAGE_FITS, imageAttributes, imgHtml } from "../../media.js";
|
|
7
|
+
import {
|
|
8
|
+
ALIGN,
|
|
9
|
+
attr,
|
|
10
|
+
iconOf,
|
|
11
|
+
isBinding,
|
|
12
|
+
json,
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
str,
|
|
16
|
+
text,
|
|
17
|
+
} from "../markup.js";
|
|
18
|
+
import { headingInner, splitHtml } from "../motion.js";
|
|
19
|
+
|
|
20
|
+
export const headingHtml = (node) => {
|
|
21
|
+
const p = node.props;
|
|
22
|
+
const level = [1, 2, 3, 4].includes(Number(p.level)) ? Number(p.level) : 2;
|
|
23
|
+
return `<h${level} class="ch-heading"${attr("align", p.align, ALIGN)}>${headingInner(node)}</h${level}>`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const textHtml = (node, { media }) => {
|
|
27
|
+
const p = node.props;
|
|
28
|
+
// A bound or computed text in a live surface is plain text the runtime keeps in step
|
|
29
|
+
// (RFC-0022: a keypad's display, a result); otherwise it is markdown.
|
|
30
|
+
const live = node.live && isBinding(node.raw?.text);
|
|
31
|
+
const body = node.split
|
|
32
|
+
? `<p>${splitHtml(str(p.text).replace(/[*_`#>]+/g, ""), node.split)}</p>`
|
|
33
|
+
: live
|
|
34
|
+
? `<p>${text(node, "text")}</p>`
|
|
35
|
+
: renderMarkdown(str(p.text), media);
|
|
36
|
+
return `<div class="ch-text"${attr("size", p.size, ["s", "m", "l"])}${p.muted === true ? ' data-muted="yes"' : ""}${attr("align", p.align, ALIGN)}>${body}</div>`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const markdownHtml = ({ props: p }, { media }) =>
|
|
40
|
+
`<div class="ch-markdown ch-richtext">${renderMarkdown(str(p.content), media)}</div>`;
|
|
41
|
+
|
|
42
|
+
export const imageHtml = (node, { media }) => {
|
|
43
|
+
const p = node.props;
|
|
44
|
+
const m = /^asset:([a-z]+_[A-Za-z0-9]{6,32})$/.exec(str(p.asset));
|
|
45
|
+
const asset = m ? media?.assets?.get(m[1] ) : undefined;
|
|
46
|
+
if (!asset) {
|
|
47
|
+
if (m) media?.onMiss?.(m[1] );
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en";
|
|
51
|
+
const fit = (IMAGE_FITS ).includes(str(p.fit))
|
|
52
|
+
? (str(p.fit) )
|
|
53
|
+
: undefined;
|
|
54
|
+
const img = imgHtml(
|
|
55
|
+
imageAttributes(
|
|
56
|
+
asset,
|
|
57
|
+
{ alt: str(p.alt) },
|
|
58
|
+
{
|
|
59
|
+
locale: media?.locale ?? defaultLocale,
|
|
60
|
+
defaultLocale,
|
|
61
|
+
transform: media?.transform ?? "none",
|
|
62
|
+
...(media?.budget ? { budget: media.budget } : {}),
|
|
63
|
+
sizes: "(min-width: 64rem) 64rem, 100vw",
|
|
64
|
+
...(media?.preview ? { preview: true } : {}),
|
|
65
|
+
...(node.priority ? { priority: true } : {}),
|
|
66
|
+
...(fit ? { fit } : {}),
|
|
67
|
+
},
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
const caption = str(p.caption);
|
|
71
|
+
return `<figure class="ch-figure"${attr("ratio", p.ratio, ["auto", "16:9", "4:3", "1:1", "3:4"])}${fit ? ` data-fit="${fit}"` : ""}>${img}${caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : ""}</figure>`;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* RFC-0025 §3: a Button that opens or closes an overlay, the browser's own way (Invoker Commands;
|
|
76
|
+
* popovers through popovertarget); a Dialog with a fallback page opens from a real link.
|
|
77
|
+
*/
|
|
78
|
+
function overlayButtonHtml(
|
|
79
|
+
node ,
|
|
80
|
+
scope ,
|
|
81
|
+
parts ,
|
|
82
|
+
) {
|
|
83
|
+
const { cls, tip, label } = parts;
|
|
84
|
+
const o = node.overlay;
|
|
85
|
+
const dom = escapeHtml(`${scope}-${o.target}`);
|
|
86
|
+
const opens = (node.props.onClick )?.action === "open";
|
|
87
|
+
if (o.kind === "Popover")
|
|
88
|
+
return `<button type="button" class="${cls}" popovertarget="${dom}"${opens ? "" : ' popovertargetaction="hide"'}${tip}>${label}</button>`;
|
|
89
|
+
if (!opens)
|
|
90
|
+
return `<button type="button" class="${cls}" command="close" commandfor="${dom}"${tip}>${label}</button>`;
|
|
91
|
+
const fallback = o.fallback ? safeHref(o.fallback) : undefined;
|
|
92
|
+
if (fallback)
|
|
93
|
+
return `<a class="${cls}" href="${escapeHtml(fallback)}" data-ch-open="${dom}" aria-haspopup="dialog" aria-controls="${dom}"${tip}>${label}</a>`;
|
|
94
|
+
return `<button type="button" class="${cls}" command="show-modal" commandfor="${dom}" aria-haspopup="dialog" aria-controls="${dom}"${tip}>${label}</button>`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Button and Link: a link, an action the runtime runs, or an overlay's opener. */
|
|
98
|
+
export const buttonLinkHtml = (node, { scope, media }) => {
|
|
99
|
+
const p = node.props;
|
|
100
|
+
// RFC-0026: a button's icon, decorative (its label names it), before or after the label.
|
|
101
|
+
const glyph =
|
|
102
|
+
node.component === "Button" ? iconOf(str(p.icon), media, { className: "ch-button__icon" }) : "";
|
|
103
|
+
const label = glyph
|
|
104
|
+
? p.iconPosition === "end"
|
|
105
|
+
? `${text(node, "label")}${glyph}`
|
|
106
|
+
: `${glyph}${text(node, "label")}`
|
|
107
|
+
: text(node, "label");
|
|
108
|
+
const cls =
|
|
109
|
+
node.component === "Link"
|
|
110
|
+
? "ch-link"
|
|
111
|
+
: `ch-button ch-button--${["primary", "secondary", "ghost"].includes(str(p.variant)) ? str(p.variant) : "primary"}`;
|
|
112
|
+
// RFC-0025 §3: a tooltip's trigger, described by it.
|
|
113
|
+
const tip = node.tip
|
|
114
|
+
? ` interestfor="${escapeHtml(`${scope}-${node.tip}`)}" aria-describedby="${escapeHtml(`${scope}-${node.tip}`)}"`
|
|
115
|
+
: "";
|
|
116
|
+
if (node.component === "Button" && node.overlay)
|
|
117
|
+
return overlayButtonHtml({ ...node, overlay: node.overlay }, scope, { cls, tip, label });
|
|
118
|
+
// An action (RFC-0020 §4): a button the runtime acts on; without JavaScript it does nothing.
|
|
119
|
+
const action = node.component === "Button" ? p.onClick : undefined;
|
|
120
|
+
if (action && typeof action === "object" && !Array.isArray(action)) {
|
|
121
|
+
const a = action ;
|
|
122
|
+
const safe = a.action !== "navigate" || (typeof a.href === "string" && safeHref(a.href));
|
|
123
|
+
if (!safe) return "";
|
|
124
|
+
return `<button type="button" class="${cls}" data-ch-action="${json(a)}"${tip}>${label}</button>`;
|
|
125
|
+
}
|
|
126
|
+
const href = typeof p.href === "string" ? safeHref(p.href) : undefined;
|
|
127
|
+
if (!href) return "";
|
|
128
|
+
return `<a class="${cls}" href="${escapeHtml(href)}"${tip}>${label}</a>`;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const badgeHtml = (node, { media }) =>
|
|
132
|
+
`<span class="ch-badge"${attr("tone", node.props.tone, ["neutral", "info", "success", "warning", "danger"])}>${iconOf(str(node.props.icon), media)}${text(node, "label")}</span>`;
|
|
133
|
+
|
|
134
|
+
/** RFC-0026: an icon on its own; named only when it carries meaning alone. */
|
|
135
|
+
export const iconHtml = ({ props: p }, { media }) => {
|
|
136
|
+
const glyph = iconOf(str(p.name), media, { label: str(p.label) || undefined });
|
|
137
|
+
return glyph
|
|
138
|
+
? `<span class="ch-icon-box"${attr("size", p.size, ["s", "m", "l", "xl"])}${attr("tone", p.tone, ["neutral", "brand", "accent", "success", "warning", "danger"])}>${glyph}</span>`
|
|
139
|
+
: "";
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const statHtml = (node, { media }) => {
|
|
143
|
+
const p = node.props;
|
|
144
|
+
return `<div class="ch-stat">${p.icon ? `<span class="ch-stat__icon">${iconOf(str(p.icon), media)}</span>` : ""}<span class="ch-stat__value">${text(node, "value")}</span><span class="ch-stat__label">${text(node, "label")}</span>${p.detail ? `<span class="ch-stat__detail">${text(node, "detail")}</span>` : ""}</div>`;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const quoteHtml = ({ props: p }, { media }) => {
|
|
148
|
+
const cite = str(p.cite);
|
|
149
|
+
const role = str(p.role);
|
|
150
|
+
return `<figure class="ch-quote"><blockquote>${renderMarkdown(str(p.text), media)}</blockquote>${cite || role ? `<figcaption>${cite ? `<cite>${escapeHtml(cite)}</cite>` : ""}${role ? ` <span>${escapeHtml(role)}</span>` : ""}</figcaption>` : ""}</figure>`;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const listHtml = ({ props: p }, { media }) => {
|
|
154
|
+
const items = Array.isArray(p.items) ? p.items.slice(0, 50) : [];
|
|
155
|
+
const tag = p.ordered === true ? "ol" : "ul";
|
|
156
|
+
// RFC-0026: an icon of the set as the bullet (decorative), drawn on each item.
|
|
157
|
+
const glyph = iconOf(str(p.marker), media, { className: "ch-list__marker" });
|
|
158
|
+
return `<${tag} class="ch-list"${glyph ? ' data-marker="icon"' : attr("marker", p.marker, ["bullet", "none"])}>${items.map((i) => `<li>${glyph}${escapeHtml(str(i))}</li>`).join("")}</${tag}>`;
|
|
159
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PrimitiveRenderer } from "../markup.js";
|
|
2
|
+
/** RFC-0022 §3: drawn here as SVG; a live surface redraws it when its data changes. */
|
|
3
|
+
export declare const chartHtml: PrimitiveRenderer;
|
|
4
|
+
/** RFC-0022 §4: a real table; `data-label` lets the theme stack rows into cards on phones. */
|
|
5
|
+
export declare const tableHtml: PrimitiveRenderer;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Data primitives (RFC-0022 §3–§4): charts drawn as SVG and real tables. */
|
|
2
|
+
import { chartInner } from "../../chart.js";
|
|
3
|
+
import { escapeHtml } from "../../markdown.js";
|
|
4
|
+
import { json, str } from "../markup.js";
|
|
5
|
+
|
|
6
|
+
/** RFC-0022 §3: drawn here as SVG; a live surface redraws it when its data changes. */
|
|
7
|
+
export const chartHtml = (node, { media }) => {
|
|
8
|
+
const p = node.props;
|
|
9
|
+
const locale = media?.locale ?? "en";
|
|
10
|
+
const dataLabel = locale.startsWith("tr") ? "Verileri göster" : "Show the data";
|
|
11
|
+
const live =
|
|
12
|
+
node.live && node.raw
|
|
13
|
+
? ` data-ch-chart="${json(node.raw)}" data-ch-label="${escapeHtml(dataLabel)}"`
|
|
14
|
+
: "";
|
|
15
|
+
const rows = Array.isArray(p.data) ? p.data : [];
|
|
16
|
+
const caption = str(p.caption);
|
|
17
|
+
return `<figure class="ch-chart"${live}${rows.length === 0 ? " data-ch-chart-empty" : ""}><figcaption class="ch-chart__title">${escapeHtml(str(p.title))}</figcaption><div class="ch-chart__body">${chartInner(p, locale, { data: dataLabel })}</div>${caption ? `<p class="ch-chart__caption">${escapeHtml(caption)}</p>` : ""}</figure>`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const isRow = (r ) =>
|
|
21
|
+
typeof r === "object" && r !== null && !Array.isArray(r);
|
|
22
|
+
|
|
23
|
+
/** A table cell in its column's format (numbers, currency, percent, dates in UTC). */
|
|
24
|
+
function cellText(v , c , locale ) {
|
|
25
|
+
if (v === undefined || v === null || v === "") return "";
|
|
26
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
27
|
+
const digits = Number.isInteger(c.digits) ? Number(c.digits) : undefined;
|
|
28
|
+
try {
|
|
29
|
+
if (c.format === "number" && Number.isFinite(n))
|
|
30
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: digits ?? 2 }).format(n);
|
|
31
|
+
if (c.format === "currency" && Number.isFinite(n) && /^[A-Z]{3}$/.test(str(c.currency)))
|
|
32
|
+
return new Intl.NumberFormat(locale, {
|
|
33
|
+
style: "currency",
|
|
34
|
+
currency: str(c.currency),
|
|
35
|
+
...(digits !== undefined ? { maximumFractionDigits: digits } : {}),
|
|
36
|
+
}).format(n);
|
|
37
|
+
if (c.format === "percent" && Number.isFinite(n))
|
|
38
|
+
return new Intl.NumberFormat(locale, {
|
|
39
|
+
style: "percent",
|
|
40
|
+
maximumFractionDigits: digits ?? 0,
|
|
41
|
+
}).format(n);
|
|
42
|
+
if (c.format === "date") {
|
|
43
|
+
const d = new Date(str(v));
|
|
44
|
+
if (!Number.isNaN(d.getTime()))
|
|
45
|
+
return new Intl.DateTimeFormat(locale, {
|
|
46
|
+
dateStyle: "medium",
|
|
47
|
+
timeZone: "UTC",
|
|
48
|
+
}).format(d);
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
// an unknown currency or locale: show the value as it is
|
|
52
|
+
}
|
|
53
|
+
return str(v);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** RFC-0022 §4: a real table; `data-label` lets the theme stack rows into cards on phones. */
|
|
57
|
+
export const tableHtml = ({ props: p }, { media }) => {
|
|
58
|
+
const locale = media?.locale ?? "en";
|
|
59
|
+
const rows = (Array.isArray(p.rows) ? p.rows : []).filter(isRow).slice(0, 200);
|
|
60
|
+
const columns = (Array.isArray(p.columns) ? p.columns : []).filter(isRow).slice(0, 8);
|
|
61
|
+
const hl = isRow(p.highlight) ? p.highlight : undefined;
|
|
62
|
+
const head = columns
|
|
63
|
+
.map(
|
|
64
|
+
(c) =>
|
|
65
|
+
`<th scope="col"${c.align === "end" ? ' data-align="end"' : ""}>${escapeHtml(str(c.label))}</th>`,
|
|
66
|
+
)
|
|
67
|
+
.join("");
|
|
68
|
+
const body = rows
|
|
69
|
+
.map((r) => {
|
|
70
|
+
const marked = hl && str(r[str(hl.field)]) === str(hl.equals);
|
|
71
|
+
return `<tr${marked ? ' data-highlight="yes"' : ""}>${columns
|
|
72
|
+
.map(
|
|
73
|
+
(c) =>
|
|
74
|
+
`<td data-label="${escapeHtml(str(c.label))}"${c.align === "end" ? ' data-align="end"' : ""}>${escapeHtml(cellText(r[str(c.field)], c, locale))}</td>`,
|
|
75
|
+
)
|
|
76
|
+
.join("")}</tr>`;
|
|
77
|
+
})
|
|
78
|
+
.join("");
|
|
79
|
+
return `<div class="ch-table-wrap"><table class="ch-table"${p.striped === true ? ' data-striped="yes"' : ""}><caption>${escapeHtml(str(p.caption))}</caption><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table></div>`;
|
|
80
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MediaContext } from "../../media.js";
|
|
2
|
+
import type { PrimitiveNode, PrimitiveRenderer } from "../markup.js";
|
|
3
|
+
export declare const PRIMITIVE_HTML: {
|
|
4
|
+
readonly Stack: PrimitiveRenderer;
|
|
5
|
+
readonly Row: PrimitiveRenderer;
|
|
6
|
+
readonly Grid: PrimitiveRenderer;
|
|
7
|
+
readonly Columns: PrimitiveRenderer;
|
|
8
|
+
readonly Band: PrimitiveRenderer;
|
|
9
|
+
readonly Card: PrimitiveRenderer;
|
|
10
|
+
readonly Spacer: PrimitiveRenderer;
|
|
11
|
+
readonly Divider: PrimitiveRenderer;
|
|
12
|
+
readonly Heading: PrimitiveRenderer;
|
|
13
|
+
readonly Text: PrimitiveRenderer;
|
|
14
|
+
readonly Markdown: PrimitiveRenderer;
|
|
15
|
+
readonly Image: PrimitiveRenderer;
|
|
16
|
+
readonly Button: PrimitiveRenderer;
|
|
17
|
+
readonly Link: PrimitiveRenderer;
|
|
18
|
+
readonly Badge: PrimitiveRenderer;
|
|
19
|
+
readonly Icon: PrimitiveRenderer;
|
|
20
|
+
readonly Stat: PrimitiveRenderer;
|
|
21
|
+
readonly Toggle: PrimitiveRenderer;
|
|
22
|
+
readonly Select: PrimitiveRenderer;
|
|
23
|
+
readonly Slider: PrimitiveRenderer;
|
|
24
|
+
readonly Chart: PrimitiveRenderer;
|
|
25
|
+
readonly Table: PrimitiveRenderer;
|
|
26
|
+
readonly NumberField: PrimitiveRenderer;
|
|
27
|
+
readonly TextField: PrimitiveRenderer;
|
|
28
|
+
readonly Checkbox: PrimitiveRenderer;
|
|
29
|
+
readonly RadioGroup: PrimitiveRenderer;
|
|
30
|
+
readonly Quote: PrimitiveRenderer;
|
|
31
|
+
readonly List: PrimitiveRenderer;
|
|
32
|
+
readonly Tabs: PrimitiveRenderer;
|
|
33
|
+
readonly TabPanel: PrimitiveRenderer;
|
|
34
|
+
readonly Accordion: PrimitiveRenderer;
|
|
35
|
+
readonly Marquee: PrimitiveRenderer;
|
|
36
|
+
readonly Counter: PrimitiveRenderer;
|
|
37
|
+
readonly Scrolly: PrimitiveRenderer;
|
|
38
|
+
readonly Step: PrimitiveRenderer;
|
|
39
|
+
readonly ScrollProgress: PrimitiveRenderer;
|
|
40
|
+
readonly Carousel: PrimitiveRenderer;
|
|
41
|
+
readonly Dialog: PrimitiveRenderer;
|
|
42
|
+
readonly Drawer: PrimitiveRenderer;
|
|
43
|
+
readonly Popover: PrimitiveRenderer;
|
|
44
|
+
readonly Tooltip: PrimitiveRenderer;
|
|
45
|
+
readonly Lightbox: PrimitiveRenderer;
|
|
46
|
+
readonly Disclosure: PrimitiveRenderer;
|
|
47
|
+
};
|
|
48
|
+
/** A primitive's name, as the table knows it. */
|
|
49
|
+
export type PrimitiveName = keyof typeof PRIMITIVE_HTML;
|
|
50
|
+
/**
|
|
51
|
+
* A primitive's markup around `CHILDREN`, from resolved props (escaped here); `""` for a name
|
|
52
|
+
* the table does not know. `Tabs` reads its children's labels for the tab buttons.
|
|
53
|
+
*/
|
|
54
|
+
export declare function primitiveHtml(node: PrimitiveNode, scope: string, media?: MediaContext): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The primitives' renderers by component name (docs/engineering/code-structure.md §5). Its keys
|
|
3
|
+
* are the catalog's primitives (`PRIMITIVES` in `@cloudhal/core-ts/surfaces`; a test keeps them
|
|
4
|
+
* equal).
|
|
5
|
+
*/
|
|
6
|
+
import { escapeHtml } from "../../markdown.js";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import { carouselHtml } from "./carousel.js";
|
|
10
|
+
import {
|
|
11
|
+
badgeHtml,
|
|
12
|
+
buttonLinkHtml,
|
|
13
|
+
headingHtml,
|
|
14
|
+
iconHtml,
|
|
15
|
+
imageHtml,
|
|
16
|
+
listHtml,
|
|
17
|
+
markdownHtml,
|
|
18
|
+
quoteHtml,
|
|
19
|
+
statHtml,
|
|
20
|
+
textHtml,
|
|
21
|
+
} from "./content.js";
|
|
22
|
+
import { chartHtml, tableHtml } from "./data.js";
|
|
23
|
+
import {
|
|
24
|
+
checkboxHtml,
|
|
25
|
+
numberFieldHtml,
|
|
26
|
+
radioGroupHtml,
|
|
27
|
+
selectHtml,
|
|
28
|
+
sliderHtml,
|
|
29
|
+
textFieldHtml,
|
|
30
|
+
toggleHtml,
|
|
31
|
+
} from "./inputs.js";
|
|
32
|
+
import {
|
|
33
|
+
accordionHtml,
|
|
34
|
+
bandHtml,
|
|
35
|
+
cardHtml,
|
|
36
|
+
columnsHtml,
|
|
37
|
+
disclosureHtml,
|
|
38
|
+
dividerHtml,
|
|
39
|
+
gridHtml,
|
|
40
|
+
rowHtml,
|
|
41
|
+
spacerHtml,
|
|
42
|
+
stackHtml,
|
|
43
|
+
tabPanelHtml,
|
|
44
|
+
tabsHtml,
|
|
45
|
+
} from "./layout.js";
|
|
46
|
+
import { counterHtml, marqueeHtml, scrollProgressHtml, scrollyHtml, stepHtml } from "./motion.js";
|
|
47
|
+
import { dialogHtml, lightboxNodeHtml, popoverHtml, tooltipHtml } from "./overlays.js";
|
|
48
|
+
|
|
49
|
+
export const PRIMITIVE_HTML = {
|
|
50
|
+
Stack: stackHtml,
|
|
51
|
+
Row: rowHtml,
|
|
52
|
+
Grid: gridHtml,
|
|
53
|
+
Columns: columnsHtml,
|
|
54
|
+
Band: bandHtml,
|
|
55
|
+
Card: cardHtml,
|
|
56
|
+
Spacer: spacerHtml,
|
|
57
|
+
Divider: dividerHtml,
|
|
58
|
+
Heading: headingHtml,
|
|
59
|
+
Text: textHtml,
|
|
60
|
+
Markdown: markdownHtml,
|
|
61
|
+
Image: imageHtml,
|
|
62
|
+
Button: buttonLinkHtml,
|
|
63
|
+
Link: buttonLinkHtml,
|
|
64
|
+
Badge: badgeHtml,
|
|
65
|
+
Icon: iconHtml,
|
|
66
|
+
Stat: statHtml,
|
|
67
|
+
Toggle: toggleHtml,
|
|
68
|
+
Select: selectHtml,
|
|
69
|
+
Slider: sliderHtml,
|
|
70
|
+
Chart: chartHtml,
|
|
71
|
+
Table: tableHtml,
|
|
72
|
+
NumberField: numberFieldHtml,
|
|
73
|
+
TextField: textFieldHtml,
|
|
74
|
+
Checkbox: checkboxHtml,
|
|
75
|
+
RadioGroup: radioGroupHtml,
|
|
76
|
+
Quote: quoteHtml,
|
|
77
|
+
List: listHtml,
|
|
78
|
+
Tabs: tabsHtml,
|
|
79
|
+
TabPanel: tabPanelHtml,
|
|
80
|
+
Accordion: accordionHtml,
|
|
81
|
+
Marquee: marqueeHtml,
|
|
82
|
+
Counter: counterHtml,
|
|
83
|
+
Scrolly: scrollyHtml,
|
|
84
|
+
Step: stepHtml,
|
|
85
|
+
ScrollProgress: scrollProgressHtml,
|
|
86
|
+
Carousel: carouselHtml,
|
|
87
|
+
Dialog: dialogHtml,
|
|
88
|
+
Drawer: dialogHtml,
|
|
89
|
+
Popover: popoverHtml,
|
|
90
|
+
Tooltip: tooltipHtml,
|
|
91
|
+
Lightbox: lightboxNodeHtml,
|
|
92
|
+
Disclosure: disclosureHtml,
|
|
93
|
+
} ;
|
|
94
|
+
|
|
95
|
+
/** A primitive's name, as the table knows it. */
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A primitive's markup around `CHILDREN`, from resolved props (escaped here); `""` for a name
|
|
100
|
+
* the table does not know. `Tabs` reads its children's labels for the tab buttons.
|
|
101
|
+
*/
|
|
102
|
+
export function primitiveHtml(node , scope , media ) {
|
|
103
|
+
if (!Object.hasOwn(PRIMITIVE_HTML, node.component)) return "";
|
|
104
|
+
const render = PRIMITIVE_HTML[node.component ];
|
|
105
|
+
return render(node, { id: escapeHtml(`${scope}-${node.id}`), scope, media });
|
|
106
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PrimitiveRenderer } from "../markup.js";
|
|
2
|
+
export declare const toggleHtml: PrimitiveRenderer;
|
|
3
|
+
export declare const selectHtml: PrimitiveRenderer;
|
|
4
|
+
export declare const sliderHtml: PrimitiveRenderer;
|
|
5
|
+
export declare const numberFieldHtml: PrimitiveRenderer;
|
|
6
|
+
export declare const textFieldHtml: PrimitiveRenderer;
|
|
7
|
+
export declare const checkboxHtml: PrimitiveRenderer;
|
|
8
|
+
export declare const radioGroupHtml: PrimitiveRenderer;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input primitives (RFC-0020 §2, RFC-0022 §2): local inputs; values stay in the reader's browser,
|
|
3
|
+
* and a live surface's runtime writes them to the data they are bound to.
|
|
4
|
+
*/
|
|
5
|
+
import { escapeHtml } from "../../markdown.js";
|
|
6
|
+
import { fieldExtras, isBinding, json, model, str } from "../markup.js";
|
|
7
|
+
|
|
8
|
+
export const toggleHtml = (node, { id }) => {
|
|
9
|
+
const p = node.props;
|
|
10
|
+
const options = Array.isArray(p.options) ? p.options.slice(0, 8).map(str) : [];
|
|
11
|
+
const radios = options
|
|
12
|
+
.map(
|
|
13
|
+
(o) =>
|
|
14
|
+
`<label class="ch-toggle__option"><input type="radio" name="${id}" value="${escapeHtml(o)}"${model(node)}${o === str(p.value) ? " checked" : ""}><span>${escapeHtml(o)}</span></label>`,
|
|
15
|
+
)
|
|
16
|
+
.join("");
|
|
17
|
+
return `<div class="ch-toggle" role="radiogroup"${p.label ? ` aria-label="${escapeHtml(str(p.label))}"` : ""}>${radios}</div>`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const selectHtml = (node) => {
|
|
21
|
+
const p = node.props;
|
|
22
|
+
const options = Array.isArray(p.options) ? p.options.slice(0, 50).map(str) : [];
|
|
23
|
+
return `<label class="ch-field"><span class="ch-field__label">${escapeHtml(str(p.label))}</span><select class="ch-select"${model(node)}>${options.map((o) => `<option value="${escapeHtml(o)}"${o === str(p.value) ? " selected" : ""}>${escapeHtml(o)}</option>`).join("")}</select></label>`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const sliderHtml = (node) => {
|
|
27
|
+
const p = node.props;
|
|
28
|
+
const n = (v , d ) => (Number.isFinite(Number(v)) ? Number(v) : d);
|
|
29
|
+
const out =
|
|
30
|
+
node.live && isBinding(node.raw?.value)
|
|
31
|
+
? `<output class="ch-slider__value" data-ch-text="${json(node.raw?.value)}">${escapeHtml(str(p.value))}</output>`
|
|
32
|
+
: `<output class="ch-slider__value">${escapeHtml(str(p.value))}</output>`;
|
|
33
|
+
return `<label class="ch-field"><span class="ch-field__label">${escapeHtml(str(p.label))}</span><span class="ch-slider"><input type="range" min="${n(p.min, 0)}" max="${n(p.max, 100)}" step="${n(p.step, 1) || "any"}" value="${n(p.value, 0)}"${model(node)}>${out}</span></label>`;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const numberFieldHtml = (node, { id }) => {
|
|
37
|
+
const p = node.props;
|
|
38
|
+
const x = fieldExtras(node, id);
|
|
39
|
+
const n = (v ) => (Number.isFinite(Number(v)) && v !== "" ? ` ${String(Number(v))}` : "");
|
|
40
|
+
const bound = (k ) => (n(p[k]) ? ` ${k}="${n(p[k]).trim()}"` : "");
|
|
41
|
+
const unit = str(p.unit);
|
|
42
|
+
return `<label class="ch-field"><span class="ch-field__label">${escapeHtml(str(p.label))}</span><span class="ch-input-wrap"><input class="ch-input" type="number" inputmode="decimal" id="${id}"${bound("min")}${bound("max")}${p.step === undefined ? ' step="any"' : bound("step")}${p.placeholder ? ` placeholder="${escapeHtml(str(p.placeholder))}"` : ""} value="${escapeHtml(str(p.value))}"${model(node)}${x.attrs}>${unit ? `<span class="ch-input__unit">${escapeHtml(unit)}</span>` : ""}</span>${x.help}</label>`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const textFieldHtml = (node, { id }) => {
|
|
46
|
+
const p = node.props;
|
|
47
|
+
const x = fieldExtras(node, id);
|
|
48
|
+
const max = Number.isInteger(p.maxLength) ? Math.min(500, Number(p.maxLength)) : 500;
|
|
49
|
+
return `<label class="ch-field"><span class="ch-field__label">${escapeHtml(str(p.label))}</span><input class="ch-input" type="${p.kind === "email" ? "email" : "text"}" id="${id}" maxlength="${max}"${p.placeholder ? ` placeholder="${escapeHtml(str(p.placeholder))}"` : ""} value="${escapeHtml(str(p.value))}"${model(node)}${x.attrs}>${x.help}</label>`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const checkboxHtml = (node) =>
|
|
53
|
+
`<label class="ch-check"><input type="checkbox"${node.props.checked === true ? " checked" : ""}${model(node, "checked")}><span>${escapeHtml(str(node.props.label))}</span></label>`;
|
|
54
|
+
|
|
55
|
+
export const radioGroupHtml = (node, { id }) => {
|
|
56
|
+
const p = node.props;
|
|
57
|
+
const x = fieldExtras(node, id);
|
|
58
|
+
const options = (Array.isArray(p.options) ? p.options : [])
|
|
59
|
+
.slice(0, 8)
|
|
60
|
+
.filter((o) => typeof o === "object" && o !== null);
|
|
61
|
+
const radios = options
|
|
62
|
+
.map(
|
|
63
|
+
(o) =>
|
|
64
|
+
`<label class="ch-radio__option"><input type="radio" name="${id}" value="${escapeHtml(str(o.value))}"${model(node)}${str(o.value) === str(p.value) ? " checked" : ""}><span>${escapeHtml(str(o.label))}</span></label>`,
|
|
65
|
+
)
|
|
66
|
+
.join("");
|
|
67
|
+
return `<fieldset class="ch-radio" data-variant="${p.variant === "buttons" ? "buttons" : "list"}"${x.attrs}><legend class="ch-field__label">${escapeHtml(str(p.label))}</legend><span class="ch-radio__options">${radios}</span>${x.help}</fieldset>`;
|
|
68
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PrimitiveRenderer } from "../markup.js";
|
|
2
|
+
export declare const stackHtml: PrimitiveRenderer;
|
|
3
|
+
export declare const rowHtml: PrimitiveRenderer;
|
|
4
|
+
export declare const gridHtml: PrimitiveRenderer;
|
|
5
|
+
export declare const columnsHtml: PrimitiveRenderer;
|
|
6
|
+
export declare const bandHtml: PrimitiveRenderer;
|
|
7
|
+
export declare const cardHtml: PrimitiveRenderer;
|
|
8
|
+
export declare const spacerHtml: PrimitiveRenderer;
|
|
9
|
+
export declare const dividerHtml: PrimitiveRenderer;
|
|
10
|
+
/** No JavaScript: one radio per panel; the theme's CSS shows the checked one's panel. */
|
|
11
|
+
export declare const tabsHtml: PrimitiveRenderer;
|
|
12
|
+
export declare const tabPanelHtml: PrimitiveRenderer;
|
|
13
|
+
export declare const accordionHtml: PrimitiveRenderer;
|
|
14
|
+
export declare const disclosureHtml: PrimitiveRenderer;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Layout primitives (RFC-0020 §2): stacks, rows, grids, bands, cards, tabs and disclosures. */
|
|
2
|
+
import { escapeHtml, safeHref } from "../../markdown.js";
|
|
3
|
+
import {
|
|
4
|
+
ALIGN,
|
|
5
|
+
ambientOf,
|
|
6
|
+
anchor,
|
|
7
|
+
attr,
|
|
8
|
+
CHILDREN,
|
|
9
|
+
|
|
10
|
+
paint,
|
|
11
|
+
SPACE,
|
|
12
|
+
str,
|
|
13
|
+
} from "../markup.js";
|
|
14
|
+
|
|
15
|
+
export const stackHtml = ({ props: p }) =>
|
|
16
|
+
`<div class="ch-stack"${attr("gap", p.gap, SPACE)}${attr("align", p.align, ALIGN)}>${CHILDREN}</div>`;
|
|
17
|
+
|
|
18
|
+
export const rowHtml = ({ props: p }) =>
|
|
19
|
+
`<div class="ch-row"${attr("gap", p.gap, SPACE)}${attr("align", p.align, ALIGN)}${attr("justify", p.justify, ["start", "center", "end", "between"])}${p.wrap === false ? ' data-wrap="no"' : ""}>${CHILDREN}</div>`;
|
|
20
|
+
|
|
21
|
+
export const gridHtml = ({ props: p }) =>
|
|
22
|
+
`<div class="ch-grid"${attr("cols", p.columns, ["1", "2", "3", "4", "5", "6"])}${attr("gap", p.gap, SPACE)}>${CHILDREN}</div>`;
|
|
23
|
+
|
|
24
|
+
export const columnsHtml = ({ props: p }) =>
|
|
25
|
+
`<div class="ch-columns"${attr("ratio", p.ratio, ["1-1", "2-1", "1-2", "1-1-1", "1-2-1"])}${attr("gap", p.gap, SPACE)}>${CHILDREN}</div>`;
|
|
26
|
+
|
|
27
|
+
export const bandHtml = ({ props: p }) =>
|
|
28
|
+
`<div class="ch-band"${anchor(p.anchor)}${paint(p)}${ambientOf(p).attrs}${attr("width", p.width, ["narrow", "wide", "full"])}${attr("spacing", p.spacing, SPACE)}>${ambientOf(p).canvas}<div class="ch-band__inner">${CHILDREN}</div></div>`;
|
|
29
|
+
|
|
30
|
+
export const cardHtml = ({ props: p }) => {
|
|
31
|
+
const href = typeof p.href === "string" ? safeHref(p.href) : undefined;
|
|
32
|
+
return href
|
|
33
|
+
? `<a class="ch-card" href="${escapeHtml(href)}"${paint(p)}${ambientOf(p, true).attrs}>${CHILDREN}</a>`
|
|
34
|
+
: `<div class="ch-card"${paint(p)}${ambientOf(p, true).attrs}>${CHILDREN}</div>`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const spacerHtml = ({ props: p }) =>
|
|
38
|
+
`<div class="ch-spacer"${attr("size", p.size, SPACE)} aria-hidden="true"></div>`;
|
|
39
|
+
|
|
40
|
+
export const dividerHtml = () => `<hr class="ch-divider">`;
|
|
41
|
+
|
|
42
|
+
/** No JavaScript: one radio per panel; the theme's CSS shows the checked one's panel. */
|
|
43
|
+
export const tabsHtml = (node, { id }) => {
|
|
44
|
+
const panels = node.children.filter((c) => c.component === "TabPanel");
|
|
45
|
+
const radios = panels
|
|
46
|
+
.map(
|
|
47
|
+
(c, i) =>
|
|
48
|
+
`<input class="ch-tabs__radio" type="radio" name="${id}" id="${id}-${i}"${i === 0 ? " checked" : ""}><label class="ch-tabs__tab" for="${id}-${i}">${escapeHtml(str(c.props.label))}</label>`,
|
|
49
|
+
)
|
|
50
|
+
.join("");
|
|
51
|
+
return `<div class="ch-tabs" data-count="${panels.length}">${radios}<div class="ch-tabs__panels">${CHILDREN}</div></div>`;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const tabPanelHtml = ({ props: p }) =>
|
|
55
|
+
`<div class="ch-tabs__panel" role="group" aria-label="${escapeHtml(str(p.label))}">${CHILDREN}</div>`;
|
|
56
|
+
|
|
57
|
+
export const accordionHtml = (_node, { id }) =>
|
|
58
|
+
`<div class="ch-accordion" data-group="${id}">${CHILDREN}</div>`;
|
|
59
|
+
|
|
60
|
+
export const disclosureHtml = ({ props: p }) =>
|
|
61
|
+
`<details class="ch-disclosure"${p.open === true ? " open" : ""}><summary>${escapeHtml(str(p.summary))}</summary><div class="ch-disclosure__body">${CHILDREN}</div></details>`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PrimitiveRenderer } from "../markup.js";
|
|
2
|
+
/** RFC-0024 24c: a row the motion module sets moving (a still, wrapping row until then). */
|
|
3
|
+
export declare const marqueeHtml: PrimitiveRenderer;
|
|
4
|
+
/** RFC-0024 24c: the final number is in the page; the motion module counts up to it once. */
|
|
5
|
+
export declare const counterHtml: PrimitiveRenderer;
|
|
6
|
+
/** RFC-0024 §3: scroll storytelling; the motion module writes the step being read to `step`. */
|
|
7
|
+
export declare const scrollyHtml: PrimitiveRenderer;
|
|
8
|
+
export declare const stepHtml: PrimitiveRenderer;
|
|
9
|
+
export declare const scrollProgressHtml: PrimitiveRenderer;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Motion primitives (RFC-0024 §3, 24c): marquees, counters, scroll stories and progress. */
|
|
2
|
+
import { escapeHtml } from "../../markdown.js";
|
|
3
|
+
import { attr, CHILDREN, isBinding, SPACE, str, text } from "../markup.js";
|
|
4
|
+
|
|
5
|
+
/** RFC-0024 24c: a row the motion module sets moving (a still, wrapping row until then). */
|
|
6
|
+
export const marqueeHtml = ({ props: p }) =>
|
|
7
|
+
`<div class="ch-marquee"${attr("speed", p.speed, ["slow", "normal", "fast"])}${attr("direction", p.direction, ["start", "end"])}${p.pauseOnHover === false ? "" : " data-hover-pause"}${attr("gap", p.gap, SPACE)}><div class="ch-marquee__track">${CHILDREN}</div></div>`;
|
|
8
|
+
|
|
9
|
+
/** RFC-0024 24c: the final number is in the page; the motion module counts up to it once. */
|
|
10
|
+
export const counterHtml = (node, { media }) => {
|
|
11
|
+
const p = node.props;
|
|
12
|
+
const bound = node.live && isBinding(node.raw?.value);
|
|
13
|
+
const to = Number(p.value);
|
|
14
|
+
const decimals = Number.isInteger(p.decimals)
|
|
15
|
+
? Math.min(3, Math.max(0, p.decimals ))
|
|
16
|
+
: 0;
|
|
17
|
+
const shown = Number.isFinite(to)
|
|
18
|
+
? new Intl.NumberFormat(media?.locale ?? "en", {
|
|
19
|
+
minimumFractionDigits: decimals,
|
|
20
|
+
maximumFractionDigits: decimals,
|
|
21
|
+
}).format(to)
|
|
22
|
+
: "";
|
|
23
|
+
const from = Number.isFinite(Number(p.from)) ? Number(p.from) : 0;
|
|
24
|
+
const prefix = escapeHtml(str(p.prefix));
|
|
25
|
+
const suffix = escapeHtml(str(p.suffix));
|
|
26
|
+
const value = bound
|
|
27
|
+
? text(node, "value")
|
|
28
|
+
: // The final number twice in one grid cell: a hidden copy holds the width while the
|
|
29
|
+
// other counts (no layout shift, whatever the font's digits and separators).
|
|
30
|
+
`<span class="sr-only">${escapeHtml(shown)}</span><span class="ch-counter__num" aria-hidden="true"><span class="ch-counter__hold">${escapeHtml(shown)}</span><span class="ch-counter__live"${Number.isFinite(to) ? ` data-ch-count="${to}" data-ch-from="${from}" data-ch-decimals="${decimals}"` : ""}${attr("ch-speed", p.duration, ["fast", "normal", "slow"])}>${escapeHtml(shown)}</span></span>`;
|
|
31
|
+
return `<div class="ch-counter"><span class="ch-counter__value">${prefix}${value}${suffix}</span>${p.label ? `<span class="ch-counter__label">${text(node, "label")}</span>` : ""}</div>`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** RFC-0024 §3: scroll storytelling; the motion module writes the step being read to `step`. */
|
|
35
|
+
export const scrollyHtml = (node) => {
|
|
36
|
+
const p = node.props;
|
|
37
|
+
const bound = node.raw?.step ;
|
|
38
|
+
const step = bound && typeof bound === "object" ? str(bound.path) : "";
|
|
39
|
+
return `<div class="ch-scrolly"${attr("side", p.side, ["start", "end"])}${attr("ratio", p.ratio, ["1-1", "2-1", "1-2"])}${/^\/[^\s"<>]{0,199}$/.test(step) ? ` data-ch-step-path="${escapeHtml(step)}"` : ""}>${CHILDREN}</div>`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const stepHtml = () => `<div class="ch-step">${CHILDREN}</div>`;
|
|
43
|
+
|
|
44
|
+
export const scrollProgressHtml = ({ props: p }) =>
|
|
45
|
+
`<div class="ch-progress"${attr("placement", p.placement ?? "page", ["page", "section"])}${attr("tone", p.tone, ["brand", "accent", "neutral"])} aria-hidden="true"><span class="ch-progress__bar"></span></div>`;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type PrimitiveRenderer } from "../markup.js";
|
|
2
|
+
/** Dialog and Drawer: a modal `<dialog>` with a title and a close button. */
|
|
3
|
+
export declare const dialogHtml: PrimitiveRenderer;
|
|
4
|
+
export declare const popoverHtml: PrimitiveRenderer;
|
|
5
|
+
export declare const tooltipHtml: PrimitiveRenderer;
|
|
6
|
+
export declare const lightboxNodeHtml: PrimitiveRenderer;
|