@littlepress/renderer-web 0.0.0-stage → 1.0.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/NOTICE +20 -0
- package/README.md +229 -2
- package/dist/answer/answerComponents.d.ts +107 -0
- package/dist/answer/answerComponents.js +637 -0
- package/dist/answer/download.d.ts +63 -0
- package/dist/answer/download.js +109 -0
- package/dist/answer/downloadExport.d.ts +44 -0
- package/dist/answer/downloadExport.js +266 -0
- package/dist/answer/hostValues.d.ts +28 -0
- package/dist/answer/hostValues.js +379 -0
- package/dist/answer/mapComponent.d.ts +6 -0
- package/dist/answer/mapComponent.js +213 -0
- package/dist/answer/math.d.ts +57 -0
- package/dist/answer/math.js +168 -0
- package/dist/answer/surfaceStream.d.ts +51 -0
- package/dist/answer/surfaceStream.js +260 -0
- package/dist/answer/tableLayout.d.ts +42 -0
- package/dist/answer/tableLayout.js +89 -0
- package/dist/controls/ActionFeedback.d.ts +5 -0
- package/dist/controls/ActionFeedback.js +43 -0
- package/dist/controls/actionDispatch.d.ts +51 -0
- package/dist/controls/actionDispatch.js +211 -0
- package/dist/controls/actionOutcome.generated.d.ts +64 -0
- package/dist/controls/actionOutcome.generated.js +64 -0
- package/dist/controls/calculationPublisher.d.ts +14 -0
- package/dist/controls/calculationPublisher.js +6 -0
- package/dist/controls/calculations.d.ts +20 -0
- package/dist/controls/calculations.generated.d.ts +73 -0
- package/dist/controls/calculations.generated.js +85 -0
- package/dist/controls/calculations.js +208 -0
- package/dist/controls/controlState.d.ts +84 -0
- package/dist/controls/controlState.js +256 -0
- package/dist/controls/fieldMessages.d.ts +41 -0
- package/dist/controls/fieldMessages.js +81 -0
- package/dist/controls/fieldValidation.d.ts +19 -0
- package/dist/controls/fieldValidation.js +98 -0
- package/dist/controls/formComponents.d.ts +23 -0
- package/dist/controls/formComponents.js +738 -0
- package/dist/controls/formProgress.d.ts +63 -0
- package/dist/controls/formProgress.js +122 -0
- package/dist/controls/inputDrafts.d.ts +55 -0
- package/dist/controls/inputDrafts.js +183 -0
- package/dist/controls/inputValidation.d.ts +33 -0
- package/dist/controls/inputValidation.js +119 -0
- package/dist/controls/localWrites.d.ts +9 -0
- package/dist/controls/localWrites.js +29 -0
- package/dist/core/A2uiSurface.d.ts +13 -0
- package/dist/core/A2uiSurface.js +15 -0
- package/dist/core/AtlasIcon.d.ts +18 -0
- package/dist/core/AtlasIcon.js +22 -0
- package/dist/core/AtlasMedia.d.ts +22 -0
- package/dist/core/AtlasMedia.js +45 -0
- package/dist/core/Carousel.d.ts +61 -0
- package/dist/core/Carousel.js +183 -0
- package/dist/core/CoreMedia.d.ts +19 -0
- package/dist/core/CoreMedia.js +25 -0
- package/dist/core/FoundationA2uiSurface.d.ts +86 -0
- package/dist/core/FoundationA2uiSurface.js +440 -0
- package/dist/core/ImagePreview.d.ts +42 -0
- package/dist/core/ImagePreview.js +73 -0
- package/dist/core/LucideIcon.d.ts +19 -0
- package/dist/core/LucideIcon.js +42 -0
- package/dist/core/SurfaceLink.d.ts +35 -0
- package/dist/core/SurfaceLink.js +60 -0
- package/dist/core/appearance/aegis.d.ts +49 -0
- package/dist/core/appearance/aegis.js +34 -0
- package/dist/core/appearance/colour.d.ts +24 -0
- package/dist/core/appearance/colour.js +103 -0
- package/dist/core/appearance/css.d.ts +17 -0
- package/dist/core/appearance/css.js +153 -0
- package/dist/core/appearance/presets.generated.d.ts +4 -0
- package/dist/core/appearance/presets.generated.js +1184 -0
- package/dist/core/appearance/react.d.ts +29 -0
- package/dist/core/appearance/react.js +110 -0
- package/dist/core/appearance/resolve.d.ts +76 -0
- package/dist/core/appearance/resolve.js +127 -0
- package/dist/core/appearance/textScale.d.ts +11 -0
- package/dist/core/appearance/textScale.js +51 -0
- package/dist/core/appearance/theme.d.ts +138 -0
- package/dist/core/appearance/theme.js +274 -0
- package/dist/core/baseComponents.d.ts +53 -0
- package/dist/core/baseComponents.js +480 -0
- package/dist/core/binding.d.ts +46 -0
- package/dist/core/binding.js +118 -0
- package/dist/core/bundle.d.ts +23 -0
- package/dist/core/bundle.js +75 -0
- package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
- package/dist/core/catalog/catalog-index.generated.js +79 -0
- package/dist/core/catalog/icons.generated.d.ts +6 -0
- package/dist/core/catalog/icons.generated.js +1788 -0
- package/dist/core/catalog.d.ts +6 -0
- package/dist/core/catalog.generated.d.ts +50 -0
- package/dist/core/catalog.generated.js +2174 -0
- package/dist/core/catalog.js +8 -0
- package/dist/core/chartRows.d.ts +7 -0
- package/dist/core/chartRows.js +38 -0
- package/dist/core/component-support.d.ts +39 -0
- package/dist/core/component-support.js +127 -0
- package/dist/core/components/actions.d.ts +4 -0
- package/dist/core/components/actions.js +21 -0
- package/dist/core/components/cards.d.ts +9 -0
- package/dist/core/components/cards.js +227 -0
- package/dist/core/components/charts.d.ts +18 -0
- package/dist/core/components/charts.js +412 -0
- package/dist/core/components/comparisonTable.d.ts +50 -0
- package/dist/core/components/comparisonTable.js +89 -0
- package/dist/core/components/content.d.ts +13 -0
- package/dist/core/components/content.js +108 -0
- package/dist/core/components/seriesCharts.d.ts +531 -0
- package/dist/core/components/seriesCharts.js +1053 -0
- package/dist/core/components/stepFlow.d.ts +7 -0
- package/dist/core/components/stepFlow.js +13 -0
- package/dist/core/components.full.d.ts +10 -0
- package/dist/core/components.full.js +41 -0
- package/dist/core/context.d.ts +207 -0
- package/dist/core/context.js +172 -0
- package/dist/core/coverage.d.ts +30 -0
- package/dist/core/coverage.js +93 -0
- package/dist/core/foundation.d.ts +21 -0
- package/dist/core/foundation.js +22 -0
- package/dist/core/fullTheme.d.ts +5 -0
- package/dist/core/fullTheme.js +9 -0
- package/dist/core/iconNodes.generated.d.ts +7 -0
- package/dist/core/iconNodes.generated.js +5 -0
- package/dist/core/lucideIcons.d.ts +5 -0
- package/dist/core/lucideIcons.js +7 -0
- package/dist/core/messages.d.ts +111 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/pointer.d.ts +17 -0
- package/dist/core/pointer.js +104 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +114 -0
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +6 -0
- package/dist/core/state.d.ts +73 -0
- package/dist/core/state.js +274 -0
- package/dist/core/surfaceMotion.d.ts +5 -0
- package/dist/core/surfaceMotion.js +46 -0
- package/dist/core/theme.d.ts +5 -0
- package/dist/core/theme.js +7 -0
- package/dist/core/useSurfaceImage.d.ts +20 -0
- package/dist/core/useSurfaceImage.js +65 -0
- package/dist/graph/RelationshipGraph.d.ts +14 -0
- package/dist/graph/RelationshipGraph.js +206 -0
- package/dist/graph/model.d.ts +20 -0
- package/dist/graph/model.js +36 -0
- package/dist/graph/program/assets.d.ts +3 -0
- package/dist/graph/program/assets.js +3 -0
- package/dist/graph/program/bridge.d.ts +6 -0
- package/dist/graph/program/bridge.generated.d.ts +136 -0
- package/dist/graph/program/bridge.generated.js +1 -0
- package/dist/graph/program/bridge.js +24 -0
- package/dist/graph/program/bridge.schema.json +717 -0
- package/dist/graph/program/bridgeValidator.cjs +2 -0
- package/dist/graph/program/bridgeValidator.d.cts +4 -0
- package/dist/graph/program/runner.d.ts +1 -0
- package/dist/graph/program/runner.html +2193 -0
- package/dist/graph/program/runner.js +157 -0
- package/dist/graph/program/runtime-manifest.json +1 -0
- package/dist/graph/program/view.d.ts +11 -0
- package/dist/graph/program/view.js +210 -0
- package/dist/graph/program/worker.d.ts +1 -0
- package/dist/graph/program/worker.js +2186 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/dist/internal/dsh.d.ts +4 -0
- package/dist/internal/dsh.js +3 -0
- package/dist/internal/relationship-graph.d.ts +4 -0
- package/dist/internal/relationship-graph.js +7202 -0
- package/dist/page/layoutComponents.d.ts +6 -0
- package/dist/page/layoutComponents.js +123 -0
- package/dist/page/layoutGeometry.d.ts +68 -0
- package/dist/page/layoutGeometry.js +174 -0
- package/dist/page/pageFormat.d.ts +34 -0
- package/dist/page/pageFormat.js +119 -0
- package/dist/page/printFit.d.ts +81 -0
- package/dist/page/printFit.js +338 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +2 -0
- package/dist/report/locate.d.ts +42 -0
- package/dist/report/locate.js +34 -0
- package/dist/styles/renderer.css +4580 -0
- package/licenses/LUCIDE-LICENSE.txt +43 -0
- package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
- package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
- package/package.json +68 -3
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { calculationMessage, isCalculationCall, isCalculationFailure } from "../controls/calculations.js";
|
|
3
|
+
import { amountsUnavailable, fieldCopy, isChineseLanguage, surfaceLanguage } from "../controls/fieldMessages.js";
|
|
4
|
+
import { isChildTemplate, isRecord, } from "./messages.js";
|
|
5
|
+
import { readBindingPointer, resolveBoolean, resolveRecordList, resolveString, resolveValue, resolvedString, } from "./binding.js";
|
|
6
|
+
import { chartRowText } from "./chartRows.js";
|
|
7
|
+
import { componentAnchorId } from "../report/locate.js";
|
|
8
|
+
import { surfaceIsStreaming } from "../controls/actionDispatch.js";
|
|
9
|
+
import { validDisplayText, validImageUrl, validLinkUrl, validStableId } from "../answer/hostValues.js";
|
|
10
|
+
import { LucideIcon, isLucideIconName } from "./LucideIcon.js";
|
|
11
|
+
import { CoreMedia, readMediaValue } from "./CoreMedia.js";
|
|
12
|
+
import { Carousel } from "./Carousel.js";
|
|
13
|
+
import { ImageAction, ImagePreview } from "./ImagePreview.js";
|
|
14
|
+
import { useSurfaceImage } from "./useSurfaceImage.js";
|
|
15
|
+
import { actionHandler, childContext, readFallback, resolveAction, } from "./context.js";
|
|
16
|
+
import { RenderComponent } from "./registry.js";
|
|
17
|
+
/** The surface language, tolerating the partial contexts some renderers are tested with. */
|
|
18
|
+
export function surfaceLocale(context) {
|
|
19
|
+
return surfaceLanguage(context.state?.rendererHints);
|
|
20
|
+
}
|
|
21
|
+
export function text(component, key, context) {
|
|
22
|
+
const value = resolveValue(component[key], context.binding, context.valueFunctions);
|
|
23
|
+
return isCalculationFailure(value) ? calculationMessage(value, surfaceLocale(context)) : resolvedString(value);
|
|
24
|
+
}
|
|
25
|
+
export function calculationAttributes(component, expression, value, label, context, failureMessage) {
|
|
26
|
+
if (!isCalculationCall(expression) || !value)
|
|
27
|
+
return {};
|
|
28
|
+
return {
|
|
29
|
+
"data-calculation-identity": JSON.stringify([context.ancestors, component.id, context.itemId ?? context.binding.itemPointer]),
|
|
30
|
+
// Amounts that fail together share one phrase, so a live region reports the state once
|
|
31
|
+
// instead of repeating it for every dependent amount.
|
|
32
|
+
"data-calculation-announcement": failureMessage ?? [label, value].filter(Boolean).join(": "),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function numberValue(component, key, context) {
|
|
36
|
+
const value = resolveValue(component[key], context.binding, context.valueFunctions);
|
|
37
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
38
|
+
}
|
|
39
|
+
export function records(component, key, context) {
|
|
40
|
+
return resolveRecordList(component[key], context.binding, context.valueFunctions);
|
|
41
|
+
}
|
|
42
|
+
export function accessibilityLabel(component, context) {
|
|
43
|
+
return resolveString(component.accessibility?.label, context.binding, context.valueFunctions) ?? undefined;
|
|
44
|
+
}
|
|
45
|
+
export function intentClass(value) {
|
|
46
|
+
return value === "accent" || value === "ghost" || value === "danger" ? value : "";
|
|
47
|
+
}
|
|
48
|
+
export function EmptyComponent({ component }) {
|
|
49
|
+
return (_jsxs("div", { className: "a2ui-empty", "data-a2ui-component": component.component, children: [_jsx("p", { className: "lp-kicker default", children: "No bound content" }), _jsx("p", { className: "lp-caption", children: component.component })] }));
|
|
50
|
+
}
|
|
51
|
+
export function withFallback(component, hasContent, node) {
|
|
52
|
+
if (hasContent)
|
|
53
|
+
return node;
|
|
54
|
+
const fallback = readFallback(component);
|
|
55
|
+
if (fallback?.strategy === "hide")
|
|
56
|
+
return null;
|
|
57
|
+
if (fallback?.strategy === "replace_with_text") {
|
|
58
|
+
return _jsx("p", { className: "lp-body a2ui-fallback-text", children: fallback.text ?? "Content unavailable." });
|
|
59
|
+
}
|
|
60
|
+
return fallback?.strategy === "render_degraded" ? node : _jsx(EmptyComponent, { component: component });
|
|
61
|
+
}
|
|
62
|
+
export function renderChildren(component, context) {
|
|
63
|
+
const children = component.children;
|
|
64
|
+
if (Array.isArray(children)) {
|
|
65
|
+
return children
|
|
66
|
+
.filter((id) => typeof id === "string")
|
|
67
|
+
.map((id, index) => _jsx(RenderComponent, { componentId: id, context: childContext(context, component.id, undefined, index) }, id));
|
|
68
|
+
}
|
|
69
|
+
if (!isChildTemplate(children))
|
|
70
|
+
return [];
|
|
71
|
+
const resolved = resolveValue(children, context.binding, context.valueFunctions);
|
|
72
|
+
const list = Array.isArray(resolved)
|
|
73
|
+
? resolved
|
|
74
|
+
: resolveRecordList({ path: children.path }, context.binding, context.valueFunctions);
|
|
75
|
+
const basePointer = readBindingPointer({ path: children.path }, context.binding);
|
|
76
|
+
const template = context.state.components[children.componentId];
|
|
77
|
+
// A list row keeps its own layout; any other repeated template is a composed row.
|
|
78
|
+
const composedRow = Boolean(template) && !listRowComponents.has(template.component);
|
|
79
|
+
return list.map((_entry, index) => {
|
|
80
|
+
const itemPointer = basePointer ? `${basePointer}/${index}` : null;
|
|
81
|
+
const repeatedContext = {
|
|
82
|
+
...childContext(context, component.id, itemPointer, index),
|
|
83
|
+
composedRow,
|
|
84
|
+
composedRowRoot: composedRow ? children.componentId : undefined,
|
|
85
|
+
};
|
|
86
|
+
const itemId = template
|
|
87
|
+
? resolveValue(template.itemId, repeatedContext.binding, repeatedContext.valueFunctions)
|
|
88
|
+
: null;
|
|
89
|
+
repeatedContext.itemId = typeof itemId === "string" && itemId.trim() ? itemId : undefined;
|
|
90
|
+
return (_jsx(RenderComponent, { componentId: children.componentId, context: repeatedContext }, `${children.componentId}-${repeatedContext.itemId ?? index}`));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Composed list rows (`docs/architecture/renderer-visual-contract.md`). In a horizontal stack of a
|
|
94
|
+
// composed row, these share the spare width and wrap; every other child keeps its own width.
|
|
95
|
+
const listRowComponents = new Set(["lp.list-row", "LPListRow_Default"]);
|
|
96
|
+
const stackComponents = new Set(["lp.stack", "LPStack_Default"]);
|
|
97
|
+
const flexibleRowComponents = new Set([
|
|
98
|
+
...stackComponents, "lp.text", "LPText_Default", "lp.meta-row", "LPMetaRow_Default",
|
|
99
|
+
"lp.kicker", "LPKicker_Default", "lp.progress", "LPProgress_Default",
|
|
100
|
+
]);
|
|
101
|
+
function composedRowLayout(component, context, axis) {
|
|
102
|
+
const children = component.children;
|
|
103
|
+
const template = isChildTemplate(children) ? context.state.components[children.componentId] : undefined;
|
|
104
|
+
// Plain composed rows are separated by the surface's item dividers; cards carry their own frame.
|
|
105
|
+
const dividers = Boolean(template) && stackComponents.has(template.component)
|
|
106
|
+
&& context.state.rendererHints?.itemDividers !== "none";
|
|
107
|
+
const kinds = context.composedRow === true && axis === "horizontal" && component.wrap !== true && Array.isArray(children)
|
|
108
|
+
? children.filter((id) => typeof id === "string").map(id => flexibleRowComponents.has(context.state.components[id]?.component ?? ""))
|
|
109
|
+
: [];
|
|
110
|
+
// R2: text shares the width with fixed parts. R2b: a row of text parts alone flows and wraps
|
|
111
|
+
// like text, so a short "Gion · 4.6" line is never split in halves and broken mid-word.
|
|
112
|
+
const split = kinds.includes(true) && kinds.includes(false);
|
|
113
|
+
const flow = kinds.length > 0 && kinds.every(Boolean);
|
|
114
|
+
return { dividers, split, flow };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* R8: a horizontal stack of a composed row that holds the item's title (a heading or title text)
|
|
118
|
+
* beside a stat is a title row ("Cedar Lantern House ...... 148 USD"). Its stats draw on one line
|
|
119
|
+
* at the title's size, so the row stays one line tall instead of opening a gap under the name.
|
|
120
|
+
*/
|
|
121
|
+
const textComponents = new Set(["lp.text", "LPText_Default"]);
|
|
122
|
+
const statComponents = new Set(["lp.stat", "LPStat_Default"]);
|
|
123
|
+
const titleRoles = new Set(["heading", "title"]);
|
|
124
|
+
function isTitleRow(component, context, axis) {
|
|
125
|
+
if (context.composedRow !== true || axis !== "horizontal" || !Array.isArray(component.children))
|
|
126
|
+
return false;
|
|
127
|
+
const children = component.children
|
|
128
|
+
.filter((id) => typeof id === "string")
|
|
129
|
+
.map((id) => context.state.components[id])
|
|
130
|
+
.filter((child) => Boolean(child));
|
|
131
|
+
return children.some((child) => textComponents.has(child.component) && titleRoles.has(String(child.role)))
|
|
132
|
+
&& children.some((child) => statComponents.has(child.component));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* R7: the outermost component of a composed row that carries `tapAction` is one button for its
|
|
136
|
+
* item. Its name is the row's own text, so no label overrides it; Enter and Space activate it.
|
|
137
|
+
* Anywhere else a `tapAction` on a stack or card is ignored.
|
|
138
|
+
*/
|
|
139
|
+
function rowTap(component, context) {
|
|
140
|
+
if (!context.composedRow || context.composedRowRoot !== component.id || !isRecord(component.tapAction))
|
|
141
|
+
return null;
|
|
142
|
+
const activate = actionHandler(component.tapAction, component, context);
|
|
143
|
+
const disabled = !activate || activate.disabled === true;
|
|
144
|
+
const pending = activate?.pending === true;
|
|
145
|
+
return {
|
|
146
|
+
props: {
|
|
147
|
+
role: "button",
|
|
148
|
+
tabIndex: 0,
|
|
149
|
+
"data-row-tap": "true",
|
|
150
|
+
"aria-disabled": disabled ? true : undefined,
|
|
151
|
+
"aria-busy": pending ? true : undefined,
|
|
152
|
+
onClick: disabled ? undefined : () => activate?.(),
|
|
153
|
+
onKeyDown: (event) => {
|
|
154
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
155
|
+
return;
|
|
156
|
+
// Space would otherwise scroll the page.
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
if (!disabled)
|
|
159
|
+
activate?.();
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
trailing: (_jsx("span", { className: "lp-row-tap-trailing", "aria-hidden": "true", children: _jsx(LucideIcon, { name: pending ? "loader-circle" : "chevron-right", size: "sm" }) })),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const stackPaddings = new Set(["none", "sm", "md", "lg"]);
|
|
166
|
+
const stackBackgrounds = new Set(["none", "surface", "muted", "accent", "info", "positive", "warning", "danger"]);
|
|
167
|
+
const stackBorders = new Set(["none", "subtle", "strong"]);
|
|
168
|
+
const radiusTokens = new Set(["none", "sm", "md", "lg", "full"]);
|
|
169
|
+
const cardVariants = new Set(["flat", "outline", "elevated"]);
|
|
170
|
+
const cardTones = new Set(["tonal", "accent", "info", "positive", "warning", "danger"]);
|
|
171
|
+
const textTones = new Set(["default", "muted", "accent", "info", "positive", "warning", "danger"]);
|
|
172
|
+
const textAligns = new Set(["start", "center", "end"]);
|
|
173
|
+
const chipVariants = new Set(["soft", "solid", "outline"]);
|
|
174
|
+
const chipSizes = new Set(["sm", "md"]);
|
|
175
|
+
const buttonSizes = new Set(["sm", "md", "lg"]);
|
|
176
|
+
const dividerSpacings = new Set(["sm", "md", "lg"]);
|
|
177
|
+
export const renderStack = (component, context) => {
|
|
178
|
+
const axis = component.axis === "horizontal" ? "horizontal" : component.axis === "vertical" ? "vertical" : null;
|
|
179
|
+
const row = composedRowLayout(component, context, axis);
|
|
180
|
+
const tap = rowTap(component, context);
|
|
181
|
+
const padding = typeof component.padding === "string" && stackPaddings.has(component.padding) ? component.padding : undefined;
|
|
182
|
+
const background = typeof component.background === "string" && stackBackgrounds.has(component.background) && component.background !== "none"
|
|
183
|
+
? component.background : undefined;
|
|
184
|
+
const border = typeof component.border === "string" && stackBorders.has(component.border) && component.border !== "none"
|
|
185
|
+
? component.border : undefined;
|
|
186
|
+
const radius = typeof component.radius === "string" && radiusTokens.has(component.radius) ? component.radius : undefined;
|
|
187
|
+
return (_jsxs("div", { ...tap?.props, className: "lp-stack", "data-rhythm": typeof component.rhythm === "string" ? component.rhythm : "editorial", "data-axis": axis ?? undefined, "data-gap": typeof component.gap === "string" ? component.gap : undefined, "data-align": typeof component.align === "string" ? component.align : undefined, "data-justify": typeof component.justify === "string" ? component.justify : undefined, "data-wrap": axis ? String(component.wrap === true) : undefined, "data-padding": padding, "data-background": background, "data-border": border, "data-radius": radius, "data-composed-row": context.composedRow ? "true" : undefined, "data-row-split": row.split ? "true" : undefined, "data-row-flow": row.flow ? "true" : undefined, "data-row-dividers": row.dividers ? "true" : undefined, "data-title-row": isTitleRow(component, context, axis) ? "true" : undefined, "aria-label": tap ? undefined : accessibilityLabel(component, context), children: [renderChildren(component, context), tap?.trailing] }));
|
|
188
|
+
};
|
|
189
|
+
export const renderCard = (component, context) => {
|
|
190
|
+
const tone = typeof component.tone === "string" && cardTones.has(component.tone) ? component.tone : "default";
|
|
191
|
+
const padding = component.padding === "compact" || component.padding === "spacious" ? component.padding : "standard";
|
|
192
|
+
const variant = typeof component.variant === "string" && cardVariants.has(component.variant) ? component.variant : undefined;
|
|
193
|
+
const radius = typeof component.radius === "string" && radiusTokens.has(component.radius) ? component.radius : undefined;
|
|
194
|
+
const tap = rowTap(component, context);
|
|
195
|
+
return (_jsxs("section", { ...tap?.props, className: `lp-card lp-container-card ${tone}`.trim(), "data-padding": padding, "data-variant": variant, "data-radius": radius, "aria-label": tap ? undefined : accessibilityLabel(component, context), children: [renderChildren(component, context), tap?.trailing] }));
|
|
196
|
+
};
|
|
197
|
+
/** The columns and rows each child of a grid spans, in `children` order: 1 to 4 each, no wider than the grid. */
|
|
198
|
+
export function gridItemSpans(component, columns) {
|
|
199
|
+
const children = Array.isArray(component.children) ? component.children : [];
|
|
200
|
+
const spans = Array.isArray(component.itemSpans) ? component.itemSpans : [];
|
|
201
|
+
const read = (value, most) => typeof value === "number" && Number.isInteger(value) ? Math.min(Math.max(value, 1), most) : 1;
|
|
202
|
+
return children.map((_child, index) => {
|
|
203
|
+
const span = isRecord(spans[index]) ? spans[index] : {};
|
|
204
|
+
return { columns: read(span.columns, columns), rows: read(span.rows, 4) };
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
export const renderGrid = (component, context) => {
|
|
208
|
+
const columns = typeof component.columns === "number" && Number.isInteger(component.columns)
|
|
209
|
+
? Math.min(Math.max(component.columns, 1), 4) : 2;
|
|
210
|
+
const spans = gridItemSpans(component, columns);
|
|
211
|
+
const spanned = spans.some((span) => span.columns > 1 || span.rows > 1);
|
|
212
|
+
const children = renderChildren(component, context);
|
|
213
|
+
// `renderChildren` skips entries that are not ids; keep each id with its span the same way.
|
|
214
|
+
const cells = (Array.isArray(component.children) ? component.children : [])
|
|
215
|
+
.map((id, index) => ({ id, span: spans[index] }))
|
|
216
|
+
.filter((cell) => typeof cell.id === "string");
|
|
217
|
+
return (_jsx("div", { className: "lp-grid", "data-columns": columns, "data-gap": typeof component.gap === "string" ? component.gap : "sm", "data-min-item-width": typeof component.minItemWidth === "string" ? component.minItemWidth : "medium", "data-spans": spanned ? "true" : undefined, "aria-label": accessibilityLabel(component, context), children: spanned
|
|
218
|
+
? cells.map(({ id, span }, index) => {
|
|
219
|
+
const child = context.state.components[id];
|
|
220
|
+
const hidden = child?.visible !== undefined
|
|
221
|
+
&& resolveBoolean(child.visible, context.binding, context.valueFunctions) === false;
|
|
222
|
+
// A spanning cell is wrapped so the grid can place it; a hidden one takes no cell at all.
|
|
223
|
+
if (hidden || (span.columns === 1 && span.rows === 1))
|
|
224
|
+
return children[index];
|
|
225
|
+
return (_jsx("div", { className: "lp-grid-item", "data-column-span": span.columns, "data-row-span": span.rows, children: children[index] }, id));
|
|
226
|
+
})
|
|
227
|
+
: children }));
|
|
228
|
+
};
|
|
229
|
+
const flowAspectRatios = new Set(["square", "portrait", "wide", "feature"]);
|
|
230
|
+
/** A masonry (LPFlow_Default): CSS multi-column layout fills each column in `children` order and
|
|
231
|
+
* balances their heights, the rule Compose and SwiftUI compute; every item is wrapped so it never
|
|
232
|
+
* breaks across columns. A full-width item spans every column. */
|
|
233
|
+
export const renderFlow = (component, context) => {
|
|
234
|
+
const columns = typeof component.columns === "number" && Number.isInteger(component.columns)
|
|
235
|
+
? Math.min(Math.max(component.columns, 1), 4) : 2;
|
|
236
|
+
const layouts = Array.isArray(component.itemLayouts) ? component.itemLayouts : [];
|
|
237
|
+
const children = renderChildren(component, context);
|
|
238
|
+
const items = (Array.isArray(component.children) ? component.children : [])
|
|
239
|
+
.map((id, index) => ({ id, layout: isRecord(layouts[index]) ? layouts[index] : {} }))
|
|
240
|
+
.filter((item) => typeof item.id === "string");
|
|
241
|
+
return (_jsx("div", { className: "lp-flow", "data-columns": columns, "data-gap": typeof component.gap === "string" ? component.gap : "sm", "data-min-item-width": typeof component.minItemWidth === "string" ? component.minItemWidth : "medium", "aria-label": accessibilityLabel(component, context), children: items.map(({ id, layout }, index) => {
|
|
242
|
+
const child = context.state.components[id];
|
|
243
|
+
if (child?.visible !== undefined && resolveBoolean(child.visible, context.binding, context.valueFunctions) === false)
|
|
244
|
+
return null;
|
|
245
|
+
const ratio = typeof layout.aspectRatio === "string" && flowAspectRatios.has(layout.aspectRatio) ? layout.aspectRatio : undefined;
|
|
246
|
+
return (_jsx("div", { className: "lp-flow-item", "data-full-width": layout.fullWidth === true ? "true" : undefined, "data-aspect-ratio": ratio, children: children[index] }, id));
|
|
247
|
+
}) }));
|
|
248
|
+
};
|
|
249
|
+
export const renderText = (component, context) => {
|
|
250
|
+
const value = text(component, "text", context) ?? text(component, "value", context);
|
|
251
|
+
const role = typeof component.role === "string" ? component.role : "body";
|
|
252
|
+
const tone = typeof component.tone === "string" && textTones.has(component.tone) && component.tone !== "default"
|
|
253
|
+
? component.tone : undefined;
|
|
254
|
+
const align = typeof component.align === "string" && textAligns.has(component.align) && component.align !== "start"
|
|
255
|
+
? component.align : undefined;
|
|
256
|
+
const Tag = role === "title" || role === "headline" ? "h2" : "p";
|
|
257
|
+
// Headings drawn once get a surface-scoped id so a Host can locate them.
|
|
258
|
+
const id = Tag === "h2" && context.anchorPrefix ? componentAnchorId(context.anchorPrefix, component.id) : undefined;
|
|
259
|
+
return withFallback(component, Boolean(value), (_jsx(Tag, { id: id, className: `lp-${role}`, "data-tone": tone, "data-align": align, ...calculationAttributes(component, component.text ?? component.value, value, text(component, "label", context), context), children: value })));
|
|
260
|
+
};
|
|
261
|
+
export const renderKicker = (component, context) => {
|
|
262
|
+
const value = text(component, "text", context) ?? text(component, "label", context);
|
|
263
|
+
return withFallback(component, Boolean(value), _jsx("p", { className: `lp-kicker ${component.tone === "default" ? "default" : ""}`.trim(), children: value }));
|
|
264
|
+
};
|
|
265
|
+
/** The tones a chip draws. Any other resolved value, written out or bound, draws `default`. */
|
|
266
|
+
const chipTones = new Set(["default", "accent", "info", "positive", "warning", "danger"]);
|
|
267
|
+
/** The tones an icon draws. Any other resolved value draws `default`. */
|
|
268
|
+
const iconTones = new Set(["default", "muted", "accent", "info", "positive", "warning", "danger"]);
|
|
269
|
+
/**
|
|
270
|
+
* The icon a status chip draws when its author named none. It follows the resolved tone, so a
|
|
271
|
+
* bound tone's icon changes with a data refresh; Compose and SwiftUI draw the same pairs
|
|
272
|
+
* (`contracts/fixtures/renderer/status-tone.json`).
|
|
273
|
+
*/
|
|
274
|
+
const chipDefaultIcons = {
|
|
275
|
+
info: "info", positive: "circle-check", warning: "triangle-alert", danger: "circle-x",
|
|
276
|
+
};
|
|
277
|
+
export const renderIcon = (component, context) => {
|
|
278
|
+
const name = text(component, "name", context);
|
|
279
|
+
const label = text(component, "label", context) ?? undefined;
|
|
280
|
+
const decorative = resolveBoolean(component.decorative, context.binding, context.valueFunctions) ?? !label;
|
|
281
|
+
const tone = text(component, "tone", context);
|
|
282
|
+
return withFallback(component, isLucideIconName(name) || (!decorative && Boolean(label)), _jsx(LucideIcon, { name: name, size: component.size === "sm" || component.size === "lg" ? component.size : "md", tone: tone !== null && iconTones.has(tone) ? tone : "default", label: label, decorative: decorative }));
|
|
283
|
+
};
|
|
284
|
+
export const renderMetaRow = (component, context) => {
|
|
285
|
+
const value = text(component, "text", context) ?? text(component, "value", context);
|
|
286
|
+
const icon = text(component, "leadingIcon", context);
|
|
287
|
+
return withFallback(component, Boolean(value), (_jsxs("p", { className: "lp-meta-row", children: [isLucideIconName(icon) ? _jsx(LucideIcon, { name: icon, size: "sm", tone: "muted" }) : null, _jsx("span", { className: "lp-meta", children: value })] })));
|
|
288
|
+
};
|
|
289
|
+
export const renderImage = (component, context) => {
|
|
290
|
+
const media = readMediaValue(resolveValue(component.media ?? component.source ?? component.url, context.binding, context.valueFunctions));
|
|
291
|
+
if (media && !media.alt)
|
|
292
|
+
media.alt = text(component, "alt", context) ?? undefined;
|
|
293
|
+
const caption = text(component, "caption", context);
|
|
294
|
+
const locked = surfaceIsStreaming(context.state);
|
|
295
|
+
const drawn = media ? _jsx(CoreMedia, { media: media, ratio: component.ratio, context: context, streaming: locked }) : null;
|
|
296
|
+
// A tap opens the renderer's preview (`preview`) or runs `tapAction`; nothing while the answer streams.
|
|
297
|
+
const alt = media?.alt ?? "";
|
|
298
|
+
const image = drawn && isRecord(component.tapAction)
|
|
299
|
+
? _jsx(ImageAction, { alt: alt, caption: caption, activate: actionHandler(component.tapAction, component, context), locked: locked, children: drawn })
|
|
300
|
+
: drawn && component.preview === true
|
|
301
|
+
? _jsx(ImagePreview, { url: media?.url, alt: alt, caption: caption, locked: locked, context: context, media: media ?? undefined, ratio: component.ratio, children: drawn })
|
|
302
|
+
: drawn;
|
|
303
|
+
// `caption` sits under the image in the caption role, as `lp.media-frame` draws its title.
|
|
304
|
+
return withFallback(component, Boolean(media), image && caption
|
|
305
|
+
? _jsxs("figure", { className: "lp-figure", children: [image, _jsx("figcaption", { className: "lp-caption", children: caption })] })
|
|
306
|
+
: image);
|
|
307
|
+
};
|
|
308
|
+
export const renderChip = (component, context) => {
|
|
309
|
+
const label = text(component, "label", context);
|
|
310
|
+
const resolvedTone = text(component, "tone", context);
|
|
311
|
+
const tone = resolvedTone !== null && chipTones.has(resolvedTone) ? resolvedTone : "default";
|
|
312
|
+
const variant = typeof component.variant === "string" && chipVariants.has(component.variant) && component.variant !== "soft"
|
|
313
|
+
? component.variant : undefined;
|
|
314
|
+
const size = typeof component.size === "string" && chipSizes.has(component.size) && component.size !== "md"
|
|
315
|
+
? component.size : undefined;
|
|
316
|
+
const icon = text(component, "leadingIcon", context) ?? chipDefaultIcons[tone] ?? null;
|
|
317
|
+
return withFallback(component, Boolean(label), (_jsxs("span", { className: `lp-pill lp-chip ${tone}`, "data-variant": variant, "data-size": size, children: [isLucideIconName(icon) ? _jsx(LucideIcon, { name: icon, size: "sm" }) : null, _jsx("span", { children: label })] })));
|
|
318
|
+
};
|
|
319
|
+
export const renderButton = (component, context) => {
|
|
320
|
+
const label = text(component, "label", context);
|
|
321
|
+
const activate = actionHandler(component.action ?? component.tapAction, component, context);
|
|
322
|
+
const explicitDisabled = resolveBoolean(component.disabled, context.binding, context.valueFunctions) === true;
|
|
323
|
+
const streaming = surfaceIsStreaming(context.state);
|
|
324
|
+
const isDisabled = !activate || activate.disabled === true || explicitDisabled || streaming;
|
|
325
|
+
const size = typeof component.size === "string" && buttonSizes.has(component.size) && component.size !== "md"
|
|
326
|
+
? component.size : undefined;
|
|
327
|
+
const fullWidth = component.fullWidth === true ? "true" : undefined;
|
|
328
|
+
const icon = text(component, "leadingIcon", context);
|
|
329
|
+
// `trailingIcon` is declared alongside `leadingIcon`; Compose and SwiftUI draw both.
|
|
330
|
+
const trailing = text(component, "trailingIcon", context);
|
|
331
|
+
// In a composed row, `accessibility.description` (A2UI common property) is read after the
|
|
332
|
+
// label, so a button repeated in every row says which item it acts on: "View, Hanami Machiya Inn".
|
|
333
|
+
const description = context.composedRow
|
|
334
|
+
? resolveString(component.accessibility?.description, context.binding, context.valueFunctions)
|
|
335
|
+
: null;
|
|
336
|
+
return withFallback(component, Boolean(label), (_jsxs("button", { type: "button", className: `lp-btn ${intentClass(component.intent)}`.trim(), "data-size": size, "data-full-width": fullWidth, onClick: isDisabled ? undefined : activate, "aria-disabled": isDisabled || undefined, "aria-busy": activate?.pending, disabled: isDisabled, children: [isLucideIconName(icon) ? _jsx(LucideIcon, { name: icon, size: "sm" }) : null, _jsx("span", { children: label }), description ? _jsxs("span", { className: "lp-visually-hidden", children: [", ", description] }) : null, isLucideIconName(trailing) ? _jsx(LucideIcon, { name: trailing, size: "sm" }) : null] })));
|
|
337
|
+
};
|
|
338
|
+
/** `lp.pager` draws a carousel (`Carousel.tsx`); a hidden child is not one of its items. */
|
|
339
|
+
export const renderPager = (component, context) => {
|
|
340
|
+
const ids = Array.isArray(component.children)
|
|
341
|
+
? component.children.filter((id) => typeof id === "string")
|
|
342
|
+
: [];
|
|
343
|
+
const items = ids.flatMap((id, index) => {
|
|
344
|
+
const child = context.state.components[id];
|
|
345
|
+
if (child?.visible !== undefined && resolveBoolean(child.visible, context.binding, context.valueFunctions) === false)
|
|
346
|
+
return [];
|
|
347
|
+
return [{ key: id, node: _jsx(RenderComponent, { componentId: id, context: childContext(context, component.id, undefined, index) }) }];
|
|
348
|
+
});
|
|
349
|
+
const label = text(component, "label", context) ?? accessibilityLabel(component, context);
|
|
350
|
+
return withFallback(component, items.length > 0, (_jsx(Carousel, { items: items, label: label ?? undefined, gap: component.gap, visibleItems: component.visibleItems, showArrows: component.showArrows, locked: surfaceIsStreaming(context.state) })));
|
|
351
|
+
};
|
|
352
|
+
export const renderListRow = (component, context) => {
|
|
353
|
+
const title = text(component, "title", context) ?? text(component, "label", context);
|
|
354
|
+
const subtitle = text(component, "subtitle", context) ?? text(component, "detail", context);
|
|
355
|
+
// `lp.list-row` declares no `value`; Web no longer reads one, as Compose and SwiftUI never did.
|
|
356
|
+
// `leadingIcon` is declared on lp.list-row in the base catalog; dropping it
|
|
357
|
+
// silently left Web without the icon that Compose and SwiftUI both drew.
|
|
358
|
+
const icon = text(component, "leadingIcon", context);
|
|
359
|
+
const tap = actionHandler(component.tapAction ?? component.action, component, context);
|
|
360
|
+
// The icon is a sibling of the copy, not a grid cell inside it: `.lp-row-main`
|
|
361
|
+
// is a two-column grid, and `.lp-row-leading` is what the inset divider offset
|
|
362
|
+
// keys on.
|
|
363
|
+
const leading = isLucideIconName(icon)
|
|
364
|
+
? _jsx("span", { className: "lp-row-leading", children: _jsx(LucideIcon, { name: icon, size: "sm", tone: "muted" }) })
|
|
365
|
+
: null;
|
|
366
|
+
const body = (_jsx("span", { className: `lp-row-main ${tap ? "is-actionable" : ""}`.trim(), children: _jsxs("span", { className: "lp-row-copy", children: [title ? _jsx("span", { className: "lp-body", children: title }) : null, subtitle ? _jsx("span", { className: "lp-caption", children: subtitle }) : null] }) }));
|
|
367
|
+
// A row that does something says so at its end, and while its action runs the chevron turns into
|
|
368
|
+
// a spinner, as Compose and SwiftUI draw it.
|
|
369
|
+
const trailing = tap
|
|
370
|
+
? _jsx("span", { className: "lp-row-trailing", children: tap.pending
|
|
371
|
+
? _jsx(LucideIcon, { name: "loader-circle", size: "sm", tone: "muted", className: "lp-row-spinner" })
|
|
372
|
+
: _jsx(LucideIcon, { name: "chevron-right", size: "sm", tone: "muted" }) })
|
|
373
|
+
: null;
|
|
374
|
+
return withFallback(component, Boolean(title || subtitle), tap
|
|
375
|
+
? _jsxs("button", { type: "button", className: "lp-row", onClick: tap.disabled ? undefined : tap, "aria-disabled": tap.disabled || undefined, "aria-busy": tap.pending || undefined, children: [leading, body, trailing] })
|
|
376
|
+
: _jsxs("div", { className: "lp-row", children: [leading, body] }));
|
|
377
|
+
};
|
|
378
|
+
export const renderDivider = (component) => {
|
|
379
|
+
const spacing = typeof component.spacing === "string" && dividerSpacings.has(component.spacing)
|
|
380
|
+
? component.spacing : undefined;
|
|
381
|
+
return _jsx("hr", { className: `lp-rule ${component.emphasis === "strong" ? "strong" : ""}`.trim(), "data-spacing": spacing });
|
|
382
|
+
};
|
|
383
|
+
/** One space between a stat's value and its unit ("148 USD"), none before a symbol unit ("45%"). */
|
|
384
|
+
const symbolUnit = /^[%‰°×′″]/;
|
|
385
|
+
const unitGap = (unit) => (symbolUnit.test(unit) ? null : " ");
|
|
386
|
+
export const renderStat = (component, context) => {
|
|
387
|
+
const resolved = resolveValue(component.value, context.binding, context.valueFunctions);
|
|
388
|
+
const invalid = isCalculationFailure(resolved);
|
|
389
|
+
const label = text(component, "label", context) ?? text(component, "caption", context);
|
|
390
|
+
const unit = invalid ? null : text(component, "unit", context);
|
|
391
|
+
// A failed amount keeps its place with a neutral marker. Field errors stay at
|
|
392
|
+
// their controls; the surface summarizes other runtime reasons once.
|
|
393
|
+
const value = invalid ? "—" : resolvedString(resolved);
|
|
394
|
+
const unavailable = fieldCopy(surfaceLocale(context)).unavailable;
|
|
395
|
+
// Field validation already explains invalid drafts. Pure runtime failures have no
|
|
396
|
+
// field error, so the surface shows their distinct reasons once and announces them.
|
|
397
|
+
const fieldExplained = invalid && resolved.code === "invalid_input" && Boolean(resolved.message);
|
|
398
|
+
const reason = invalid && !fieldExplained ? calculationMessage(resolved, surfaceLocale(context)) : undefined;
|
|
399
|
+
const announcement = invalid ? reason ?? amountsUnavailable(surfaceLocale(context)) : undefined;
|
|
400
|
+
return withFallback(component, Boolean(value), (_jsxs("div", { className: "lp-stat", ...calculationAttributes(component, component.value, value, label, context, announcement), "data-calculation-failure": reason, "data-calculation-error": invalid ? "true" : undefined, role: "group", "aria-label": [label, invalid ? unavailable : value, unit].filter(Boolean).join(" "), children: [_jsxs("p", { children: [invalid ? value : _jsx("strong", { children: value }), unit ? _jsxs(_Fragment, { children: [unitGap(unit), _jsx("span", { children: unit })] }) : null] }), label ? _jsx("p", { className: "lp-caption", children: label }) : null] })));
|
|
401
|
+
};
|
|
402
|
+
export const renderProgress = (component, context) => {
|
|
403
|
+
const value = numberValue(component, "value", context) ?? numberValue(component, "current", context) ?? 0;
|
|
404
|
+
const max = Math.max(1, numberValue(component, "max", context) ?? numberValue(component, "total", context) ?? 100);
|
|
405
|
+
const label = text(component, "label", context) ?? "Progress";
|
|
406
|
+
const clamped = Math.max(0, Math.min(value, max));
|
|
407
|
+
const valueText = `${progressPercent(clamped, max)}%`;
|
|
408
|
+
// Both variants show the label and the value. `bar` puts the value at the end of the
|
|
409
|
+
// label line; `compact` gives the label its own line and puts the value at the end of
|
|
410
|
+
// the track, so a long label never squeezes it. Compose and SwiftUI draw the same.
|
|
411
|
+
// The progressbar is one element named by the label with the drawn value as its value
|
|
412
|
+
// text, so the visible copies are hidden from assistive technology.
|
|
413
|
+
const compact = component.variant === "compact";
|
|
414
|
+
const labelText = _jsx("span", { className: "lp-caption lp-progress-meter-label", "aria-hidden": "true", children: label });
|
|
415
|
+
const valueLabel = _jsx("b", { className: "lp-caption lp-progress-meter-value", "aria-hidden": "true", children: _jsx("span", { children: valueText }) });
|
|
416
|
+
const track = _jsx("span", { className: "lp-progress-meter-track", "aria-hidden": "true", children: _jsx("i", { style: { width: `${(clamped / max) * 100}%` } }) });
|
|
417
|
+
return (_jsx("div", { className: `lp-progress-meter ${compact ? "compact" : ""}`.trim(), role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": clamped, "aria-valuetext": valueText, children: compact
|
|
418
|
+
? _jsxs(_Fragment, { children: [labelText, _jsxs("span", { className: "lp-progress-meter-row", children: [track, valueLabel] })] })
|
|
419
|
+
: _jsxs(_Fragment, { children: [_jsxs("span", { className: "lp-progress-meter-head", children: [labelText, valueLabel] }), track] }) }));
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Whole percent drawn beside `lp.progress`, rounded down so an unfinished task never
|
|
423
|
+
* reads 100%. Multiplying before dividing keeps 29 of 100 at 29 rather than 28.99…;
|
|
424
|
+
* the epsilon absorbs the same error for fractional values. Compose and SwiftUI copy it.
|
|
425
|
+
*/
|
|
426
|
+
function progressPercent(value, max) {
|
|
427
|
+
return Math.floor((value * 100) / max + 1e-9);
|
|
428
|
+
}
|
|
429
|
+
function SurfaceAvatarView({ name, media, context, }) {
|
|
430
|
+
const streaming = surfaceIsStreaming(context.state);
|
|
431
|
+
const { src, onError } = useSurfaceImage(media?.url, context, { streaming });
|
|
432
|
+
return src
|
|
433
|
+
? _jsx("img", { className: "lp-avatar", src: src, alt: media?.alt ?? name, referrerPolicy: "no-referrer", onError: onError, loading: "lazy" })
|
|
434
|
+
: _jsx("span", { className: "lp-avatar lp-avatar-fallback", role: "img", "aria-label": name, children: name.slice(0, 1).toUpperCase() });
|
|
435
|
+
}
|
|
436
|
+
export const renderAvatar = (component, context) => {
|
|
437
|
+
const name = text(component, "name", context) ?? text(component, "label", context) ?? "Profile";
|
|
438
|
+
const media = readMediaValue(resolveValue(component.media ?? component.image, context.binding, context.valueFunctions));
|
|
439
|
+
return _jsx(SurfaceAvatarView, { name: name, media: media, context: context });
|
|
440
|
+
};
|
|
441
|
+
export const renderMediaFrame = (component, context) => {
|
|
442
|
+
const source = resolveValue(component.media ?? component.source, context.binding, context.valueFunctions);
|
|
443
|
+
const title = text(component, "title", context);
|
|
444
|
+
const streaming = surfaceIsStreaming(context.state);
|
|
445
|
+
if (isRecord(component.tapAction)) {
|
|
446
|
+
const poster = validImageUrl(source);
|
|
447
|
+
const videoTitle = validDisplayText(title, 200);
|
|
448
|
+
const play = resolveAction(component.tapAction, component, context);
|
|
449
|
+
const playHandler = play?.kind === "event" && play.name === "playVideo" && validStableId(play.payload.id)
|
|
450
|
+
&& context.actionSession?.hostAccepts(play)
|
|
451
|
+
? actionHandler(component.tapAction, component, context)
|
|
452
|
+
: undefined;
|
|
453
|
+
const url = validLinkUrl(resolveValue(component.fallbackUrl, context.binding, context.valueFunctions));
|
|
454
|
+
const activate = playHandler ?? (url
|
|
455
|
+
? actionHandler({ functionCall: { call: "openUrl", args: { url } } }, component, context)
|
|
456
|
+
: undefined);
|
|
457
|
+
const zh = isChineseLanguage(surfaceLocale(context));
|
|
458
|
+
const label = playHandler ? (zh ? "播放" : "Play") : (zh ? "打开" : "Open");
|
|
459
|
+
return withFallback(component, Boolean(videoTitle), (_jsxs("figure", { className: "lp-figure", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(CoreMedia, { media: { url: poster ?? undefined, alt: "" }, ratio: "wide", context: context, streaming: streaming }, poster) }), videoTitle ? _jsx("figcaption", { className: "lp-caption", children: videoTitle }) : null, activate && videoTitle ? (_jsxs("button", { type: "button", className: `lp-btn ${intentClass("ghost")}`, "aria-label": `${label} ${videoTitle}`, disabled: activate.disabled, "aria-busy": activate.pending, onClick: activate.disabled ? undefined : activate, children: [_jsx(LucideIcon, { name: playHandler ? "play" : "external-link", size: "sm" }), _jsx("span", { children: label })] })) : null] })));
|
|
460
|
+
}
|
|
461
|
+
const media = readMediaValue(source);
|
|
462
|
+
return withFallback(component, Boolean(media || title), (_jsxs("figure", { className: "lp-figure", children: [media ? _jsx(CoreMedia, { media: media, ratio: "wide", context: context, streaming: streaming }) : null, title ? _jsx("figcaption", { className: "lp-caption", children: title }) : null] })));
|
|
463
|
+
};
|
|
464
|
+
export const renderActionRow = (component, context) => _jsx("div", { className: "lp-action-row", children: renderChildren(component, context) });
|
|
465
|
+
export const renderAdContainer = (component, context) => {
|
|
466
|
+
const disclosure = text(component, "disclosureLabel", context) ?? "Sponsored";
|
|
467
|
+
return _jsxs("aside", { className: "lp-card lp-ad", "aria-label": disclosure, children: [_jsx("p", { className: "lp-kicker default", children: disclosure }), renderChildren(component, context)] });
|
|
468
|
+
};
|
|
469
|
+
export const renderChartElements = (component, context) => {
|
|
470
|
+
const summary = text(component, "summary", context) ?? text(component, "takeaway", context);
|
|
471
|
+
const values = records(component, "values", context);
|
|
472
|
+
return withFallback(component, Boolean(summary || values.length), (_jsxs("figure", { className: "lp-chart-elements", children: [summary ? _jsx("figcaption", { className: "lp-body", children: summary }) : null, values.length ? _jsx("ul", { className: "lp-list", children: values.map((entry, index) => _jsx("li", { children: chartRowText(entry) }, index)) }) : null] })));
|
|
473
|
+
};
|
|
474
|
+
export const renderAsyncState = (component, context) => {
|
|
475
|
+
const state = text(component, "state", context) ?? "loading";
|
|
476
|
+
const title = text(component, "title", context) ?? (state === "loading" ? "Loading" : "Content unavailable");
|
|
477
|
+
const detail = text(component, "detail", context);
|
|
478
|
+
const retry = actionHandler(component.retryAction, component, context);
|
|
479
|
+
return (_jsxs("section", { className: "lp-card lp-async", "aria-live": state === "error" ? "polite" : undefined, "aria-busy": state === "loading", children: [_jsx("p", { className: "lp-title", children: title }), detail ? _jsx("p", { className: "lp-body", children: detail }) : null, retry ? _jsx("button", { type: "button", className: "lp-btn ghost", onClick: retry, "aria-disabled": retry?.disabled, "aria-busy": retry?.pending, children: "Retry" }) : null] }));
|
|
480
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-binding resolution for A2UI dynamic values.
|
|
3
|
+
*
|
|
4
|
+
* Three shapes reach a component property:
|
|
5
|
+
* - literal -> used as is
|
|
6
|
+
* - `{"path": "/data/..."}` -> JSON Pointer into the data model
|
|
7
|
+
* - `{"call": "fn", "args": {...}}` -> a catalog client function in a value slot
|
|
8
|
+
*
|
|
9
|
+
* Inside a `{componentId, path}` child template the pointers are *relative*
|
|
10
|
+
* (`title`, not `/data/related/0/title`), so every resolve carries the item
|
|
11
|
+
* pointer of the row being drawn.
|
|
12
|
+
*
|
|
13
|
+
* v1.0 has no `DynamicObject`: whole-object bindings (cover image, chapter
|
|
14
|
+
* list) arrive as `DynamicValue`, which also accepts scalars. Type safety is
|
|
15
|
+
* the governance layer's job at compile time; the renderer does defensive
|
|
16
|
+
* checks here (ADR 0004, N1 disposition 3).
|
|
17
|
+
*/
|
|
18
|
+
import { type CalculationSession } from "../controls/calculations.ts";
|
|
19
|
+
import { type A2uiFunctionCall } from "./messages.ts";
|
|
20
|
+
export type BindingContext = {
|
|
21
|
+
/** `{data: ..., runtimeState: ...}` — the whole surface data model. */
|
|
22
|
+
dataModel: unknown;
|
|
23
|
+
/** Pointer of the current template row, e.g. `/data/related/0`. */
|
|
24
|
+
itemPointer: string | null;
|
|
25
|
+
/** A cache and evaluation budget owned by the current merged input snapshot. */
|
|
26
|
+
calculations?: CalculationSession;
|
|
27
|
+
};
|
|
28
|
+
export type ValueFunction = (args: Record<string, unknown>, context: BindingContext) => unknown;
|
|
29
|
+
export declare function resolvePointerIn(context: BindingContext, path: string): unknown;
|
|
30
|
+
/**
|
|
31
|
+
* `formatDuration(ms)` is the only catalog function that returns a value; the
|
|
32
|
+
* other three (`openUrl`, `openHostAdapter`, `toggleLocalFlag`) are void
|
|
33
|
+
* client effects and are dispatched through the action channel instead.
|
|
34
|
+
*/
|
|
35
|
+
export declare const defaultValueFunctions: Readonly<Record<string, ValueFunction>>;
|
|
36
|
+
export declare function callValueFunction(call: A2uiFunctionCall, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): unknown;
|
|
37
|
+
export declare function resolveValue(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): unknown;
|
|
38
|
+
/** Display text for one already-resolved value. Empty strings fall back to nothing. */
|
|
39
|
+
export declare function resolvedString(resolved: unknown): string | null;
|
|
40
|
+
export declare function resolveString(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): string | null;
|
|
41
|
+
export declare function resolveNumber(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): number | null;
|
|
42
|
+
export declare function resolveBoolean(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): boolean | null;
|
|
43
|
+
export declare function resolveStringList(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): string[];
|
|
44
|
+
export declare function resolveRecordList(value: unknown, context: BindingContext, functions?: Readonly<Record<string, ValueFunction>>): Record<string, unknown>[];
|
|
45
|
+
/** Pointer of an array binding, needed to address rows in `itemAction` context. */
|
|
46
|
+
export declare function readBindingPointer(value: unknown, context: BindingContext): string | null;
|