ain-ui 0.2.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/NOTICE +37 -0
  2. package/README.md +179 -76
  3. package/dist/agent.d.ts +131 -0
  4. package/dist/agent.js +802 -0
  5. package/dist/ainui.d.ts +15 -1
  6. package/dist/ainui.js +59 -16
  7. package/dist/basic.d.ts +5 -47
  8. package/dist/basic.js +11 -25
  9. package/dist/catalog/standard.gen.d.ts +5 -0
  10. package/dist/catalog/standard.gen.js +6 -0
  11. package/dist/catalog-v1.json +2560 -0
  12. package/dist/catalog.json +19924 -2047
  13. package/dist/chat.js +6 -7
  14. package/dist/expression.d.ts +23 -0
  15. package/dist/expression.js +222 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +2 -0
  18. package/dist/macros.d.ts +12 -0
  19. package/dist/macros.js +57 -0
  20. package/dist/payment.js +6 -7
  21. package/dist/pickers.d.ts +158 -0
  22. package/dist/pickers.js +110 -0
  23. package/dist/protocol.d.ts +100 -0
  24. package/dist/protocol.js +232 -0
  25. package/dist/react/ain.d.ts +1 -0
  26. package/dist/react/ain.js +225 -0
  27. package/dist/react/catalog.d.ts +9 -0
  28. package/dist/react/catalog.js +23 -0
  29. package/dist/react/core.d.ts +84 -0
  30. package/dist/react/core.js +158 -0
  31. package/dist/react/functions.d.ts +2 -0
  32. package/dist/react/functions.js +29 -0
  33. package/dist/react/standard/composites.d.ts +1 -0
  34. package/dist/react/standard/composites.js +110 -0
  35. package/dist/react/standard/data.d.ts +1 -0
  36. package/dist/react/standard/data.js +481 -0
  37. package/dist/react/standard/feedback.d.ts +11 -0
  38. package/dist/react/standard/feedback.js +111 -0
  39. package/dist/react/standard/inputs.d.ts +5 -0
  40. package/dist/react/standard/inputs.js +467 -0
  41. package/dist/react/standard/layout.d.ts +5 -0
  42. package/dist/react/standard/layout.js +104 -0
  43. package/dist/react/standard/media.d.ts +33 -0
  44. package/dist/react/standard/media.js +208 -0
  45. package/dist/react/standard/rich.d.ts +1 -0
  46. package/dist/react/standard/rich.js +146 -0
  47. package/dist/react/standard/text.d.ts +9 -0
  48. package/dist/react/standard/text.js +209 -0
  49. package/dist/react/surface.d.ts +44 -0
  50. package/dist/react/surface.js +134 -0
  51. package/dist/react.d.ts +3 -36
  52. package/dist/react.js +3 -240
  53. package/dist/renderer.d.ts +1 -1
  54. package/dist/renderer.js +307 -4
  55. package/dist/styles.css +850 -0
  56. package/package.json +28 -11
@@ -0,0 +1,481 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ /** Standard catalog — data: tables, lists, charts and maps. Charts and maps are drawn here, without a library. */
4
+ import React, { createContext, useContext, useEffect, useId, useRef, useState } from "react";
5
+ import { Kids, color, cx, fire, kid, px, safeUrl, space, standard, useHost } from "../core.js";
6
+ import { IconGlyph } from "./media.js";
7
+ const str = (v) => (typeof v === "string" ? v : typeof v === "number" && Number.isFinite(v) ? String(v) : "");
8
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
9
+ const list = (v) => (Array.isArray(v) ? v : []);
10
+ const obj = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : {});
11
+ const refKey = (ref, i) => (typeof ref === "string" ? ref : `${ref.id}:${ref.basePath ?? i}`);
12
+ const refId = (ref) => (typeof ref === "string" ? ref : ref?.id);
13
+ /** The width the element has on screen, so an SVG can be drawn at real pixel size. */
14
+ function useWidth(fallback) {
15
+ const ref = useRef(null);
16
+ const [width, setWidth] = useState(fallback);
17
+ useEffect(() => {
18
+ const el = ref.current;
19
+ if (!el)
20
+ return;
21
+ const measure = () => { const w = el.clientWidth; if (w > 0)
22
+ setWidth(w); };
23
+ measure();
24
+ if (typeof ResizeObserver === "undefined")
25
+ return;
26
+ const ro = new ResizeObserver(measure);
27
+ ro.observe(el);
28
+ return () => ro.disconnect();
29
+ }, []);
30
+ return [ref, width];
31
+ }
32
+ /* ---------- Table ---------- */
33
+ const ALIGNS = ["start", "center", "end"];
34
+ const VALIGN = { start: "top", center: "middle", end: "bottom" };
35
+ const span = (v) => (typeof v === "number" && v > 1 ? Math.floor(v) : undefined);
36
+ const TableContext = createContext({ header: false });
37
+ /** A cell value of the `columns`/`rows` form: text, or a component by `{componentId}`. */
38
+ function cellContent(cell, buildChild) {
39
+ if (cell == null || typeof cell === "boolean")
40
+ return cell === true ? "Yes" : cell === false ? "No" : null;
41
+ if (typeof cell === "string" || typeof cell === "number")
42
+ return cell;
43
+ const c = obj(cell);
44
+ const id = typeof c.componentId === "string" ? c.componentId : typeof c.id === "string" ? c.id : "";
45
+ if (id)
46
+ return kid(buildChild, typeof c.basePath === "string" ? { id, basePath: c.basePath } : id);
47
+ return str(c.label ?? c.text ?? c.value);
48
+ }
49
+ const Table = standard("Table", ({ props, buildChild, context }) => {
50
+ const columns = list(props.columns);
51
+ const rows = list(props.rows).filter(Array.isArray);
52
+ const children = list(props.children);
53
+ const emptyLabel = str(props.emptyLabel) || "No rows";
54
+ const className = cx("ainui-table", props.dividers !== false && "ainui-table-dividers", props.stickyHeader && "ainui-table-sticky", props.columnSizing === "equal" && "ainui-table-equal");
55
+ const caption = str(props.caption) ? _jsx("caption", { className: "ainui-table-caption", children: str(props.caption) }) : null;
56
+ const width = Math.max(columns.length, ...rows.map((r) => r.length), 1);
57
+ const align = (i) => (ALIGNS.includes(obj(columns[i]).align) ? obj(columns[i]).align : undefined);
58
+ let body;
59
+ if (children.length) {
60
+ // Rows given straight to the table are gathered into a body, as HTML requires.
61
+ const groups = [];
62
+ // The binder hands back node ids; the component each one is comes from the ids as written.
63
+ const written = context.componentModel.properties.children;
64
+ children.forEach((ref, at) => {
65
+ const id = Array.isArray(written) ? String(written[at]) : written?.componentId ?? refId(ref);
66
+ const row = context.surfaceComponents?.get?.(id)?.type !== "TableSection";
67
+ const last = groups[groups.length - 1];
68
+ if (row && last?.row)
69
+ last.refs.push(ref);
70
+ else
71
+ groups.push({ row, refs: [ref] });
72
+ });
73
+ body = groups.map((g, i) => (g.row
74
+ ? _jsx("div", { role: "rowgroup", className: "ainui-table-section ainui-table-body", children: _jsx(Kids, { of: g.refs, buildChild: buildChild }) }, `rows${i}`)
75
+ : _jsx(React.Fragment, { children: kid(buildChild, g.refs[0]) }, refKey(g.refs[0], i))));
76
+ }
77
+ else {
78
+ body = _jsxs(_Fragment, { children: [columns.length > 0 && _jsx("thead", { className: "ainui-table-section ainui-table-head", children: _jsx("tr", { className: "ainui-table-row", children: columns.map((c, i) => _jsx("th", { scope: "col", className: "ainui-table-cell", style: { textAlign: align(i), width: px(obj(c).width) }, children: typeof c === "string" || typeof c === "number" ? c : typeof obj(c).componentId === "string" || (typeof obj(c).id === "string" && obj(c).label === undefined) ? cellContent(c, buildChild) : str(obj(c).label) }, i)) }) }), _jsxs("tbody", { className: "ainui-table-section ainui-table-body", children: [rows.map((r, y) => _jsx("tr", { className: "ainui-table-row", children: Array.from({ length: width }, (_, x) => _jsx("td", { className: "ainui-table-cell", style: { textAlign: align(x) }, children: cellContent(r[x], buildChild) }, x)) }, y)), rows.length === 0 && _jsx("tr", { className: "ainui-table-row", children: _jsx("td", { className: "ainui-table-cell ainui-table-empty", colSpan: width, children: emptyLabel }) })] })] });
79
+ }
80
+ // Built from children, every part sits inside its own wrapper element, which HTML does not allow between
81
+ // <table>, <tbody>, <tr> and <td>. So that form is the same table by role and by CSS (display: table-*).
82
+ return _jsx("div", { className: cx("ainui-table-wrap", props.stickyHeader && "ainui-table-wrap-sticky"), children: children.length
83
+ ? _jsx("div", { role: "table", "aria-label": str(props.caption) || undefined, className: cx(className, "ainui-table-grid"), children: body })
84
+ : _jsxs("table", { className: className, children: [caption, body] }) });
85
+ });
86
+ const TableSection = standard("TableSection", ({ props, buildChild }) => {
87
+ const header = !!props.header;
88
+ return _jsx("div", { role: "rowgroup", className: cx("ainui-table-section", header ? "ainui-table-head" : "ainui-table-body", props.rowDivider === false && "ainui-table-section-plain", props.rowDivider === true && "ainui-table-section-divided"), children: _jsx(TableContext.Provider, { value: { header }, children: _jsx(Kids, { of: props.children, buildChild: buildChild }) }) });
89
+ });
90
+ const TableRow = standard("TableRow", ({ props, buildChild }) => {
91
+ const inherited = useContext(TableContext);
92
+ const header = !!props.header || inherited.header;
93
+ const label = str(props.label);
94
+ return _jsxs("div", { role: "row", className: cx("ainui-table-row", header && "ainui-table-row-header"), children: [label && _jsx("div", { role: header ? "columnheader" : "rowheader", className: "ainui-table-cell ainui-table-th ainui-table-row-label", children: label }), _jsx(TableContext.Provider, { value: { header }, children: _jsx(Kids, { of: props.children, buildChild: buildChild }) })] });
95
+ });
96
+ const TableCell = standard("TableCell", ({ props, buildChild }) => {
97
+ const inherited = useContext(TableContext);
98
+ const header = !!props.header || inherited.header;
99
+ return _jsxs("div", { role: header ? (inherited.header ? "columnheader" : "rowheader") : "cell", className: cx("ainui-table-cell", header && "ainui-table-th"), "aria-colspan": span(props.colSpan), "aria-rowspan": span(props.rowSpan), style: { textAlign: ALIGNS.includes(props.align) ? props.align : undefined, verticalAlign: VALIGN[props.vAlign] ?? "top", width: px(props.width), padding: space(props.padding) }, children: [str(props.text), _jsx(Kids, { of: props.children, buildChild: buildChild })] });
100
+ });
101
+ const ListContext = createContext({ marker: "bullet", index: 0, start: 1 });
102
+ const MARKERS = ["bullet", "number", "rich", "none"];
103
+ const LIST_ALIGN = { start: "flex-start", center: "center", end: "flex-end", stretch: "stretch" };
104
+ function ListRow({ scope, label, value, description, icon, marker, markerSize, disabled, onPick, children }) {
105
+ const shown = scope.marker === "none" ? null
106
+ : marker ? marker
107
+ : scope.marker === "number" ? `${scope.start + scope.index}.`
108
+ : scope.marker === "rich" ? (icon ? _jsx(IconGlyph, { name: icon, size: 16 }) : `${scope.start + scope.index}`)
109
+ : "•";
110
+ const size = markerSize ?? scope.markerSize;
111
+ const side = str(value);
112
+ const text = _jsxs("span", { className: "ainui-list-item-text", children: [_jsxs("span", { className: "ainui-list-item-line", children: [icon && scope.marker !== "rich" && _jsx(IconGlyph, { name: icon, size: 16, className: "ainui-list-item-icon" }), _jsx("span", { className: "ainui-list-item-label", children: label }), side && !onPick && _jsx("span", { className: "ainui-list-item-value", children: side })] }), description && _jsx("span", { className: "ainui-list-item-description", children: description })] });
113
+ // A div with the list item role: an item built from a ListItem child sits in its own wrapper element, which <ul> does not allow.
114
+ return _jsxs("div", { role: "listitem", className: cx("ainui-list-item", scope.last && "ainui-list-item-last", disabled && "ainui-list-item-disabled", side && !onPick && "ainui-list-item-fact"), "aria-disabled": disabled || undefined, children: [shown != null && _jsx("span", { className: cx("ainui-list-marker", scope.marker === "rich" && "ainui-list-marker-rich"), "aria-hidden": "true", style: size ? { width: size, flexBasis: size } : undefined, children: shown }), _jsxs("span", { className: "ainui-list-item-body", children: [onPick ? _jsx("button", { type: "button", className: "ainui-list-item-button", disabled: disabled, onClick: onPick, children: text }) : text, children] })] });
115
+ }
116
+ const List = standard("List", ({ props, buildChild, context }) => {
117
+ const marker = MARKERS.includes(props.marker) ? props.marker : "bullet";
118
+ const horizontal = props.direction === "horizontal";
119
+ const start = num(props.start) ?? 1;
120
+ const pick = props.action ? (item) => void fire(context, "action", item) : undefined;
121
+ const scope = (index, count) => ({ marker, index, start, last: index === count - 1, markerSize: num(props.maxMarkerSize), pick });
122
+ const children = list(props.children);
123
+ const items = list(props.items).filter((it) => typeof it === "string" || typeof it === "number" || str(obj(it).label));
124
+ return _jsx("div", { role: "list", className: cx("ainui-list", `ainui-list-${marker}`, horizontal && "ainui-list-horizontal", props.connector === "solid" && "ainui-list-connector"), style: { gap: space(props.gap), alignItems: LIST_ALIGN[props.align] }, children: children.length > 0
125
+ ? children.map((ref, i) => _jsx(ListContext.Provider, { value: scope(i, children.length), children: kid(buildChild, ref) }, refKey(ref, i)))
126
+ : items.map((it, i) => {
127
+ const label = typeof it === "object" ? str(it.label) : str(it);
128
+ const value = typeof it === "object" ? it.value : undefined;
129
+ return _jsx(ListRow, { scope: scope(i, items.length), label: label, value: value, description: str(obj(it).description), icon: str(obj(it).icon), onPick: pick ? () => pick({ index: i, label, value: value ?? label }) : undefined }, i);
130
+ }) });
131
+ });
132
+ const ListItem = standard("ListItem", ({ props, buildChild }) => {
133
+ const scope = useContext(ListContext);
134
+ const label = str(props.label);
135
+ const disabled = !!props.disabled;
136
+ const onPick = disabled ? undefined
137
+ : props.action ? () => void props.action()
138
+ : scope.pick ? () => scope.pick?.({ index: scope.index, label, value: props.value ?? label })
139
+ : undefined;
140
+ return _jsx(ListRow, { scope: scope, label: label, value: props.value, description: str(props.description), icon: str(props.icon), marker: str(props.marker), markerSize: num(props.markerSize), disabled: disabled, onPick: onPick ?? (disabled && (props.action || scope.pick) ? () => undefined : undefined), children: list(props.children).length > 0 && _jsx("span", { className: "ainui-list-item-children", children: _jsx(Kids, { of: props.children, buildChild: buildChild }) }) });
141
+ });
142
+ /* ---------- Chart ---------- */
143
+ const TONES = ["chart-1", "chart-2", "chart-3", "chart-4", "chart-5", "chart-6"];
144
+ const tone = (i) => `var(--ainui-${TONES[i % TONES.length]})`;
145
+ const CHART_TYPES = ["bar", "line", "area", "scatter", "pie", "donut"];
146
+ function numberFormat(format, currency) {
147
+ const options = format === "currency" ? { style: "currency", currency: str(currency) || "USD", maximumFractionDigits: 2, trailingZeroDisplay: "stripIfInteger" }
148
+ : format === "percent" ? { style: "percent", maximumFractionDigits: 1 } : { maximumFractionDigits: 2 };
149
+ const build = (o) => {
150
+ try {
151
+ return new Intl.NumberFormat(undefined, o);
152
+ }
153
+ catch {
154
+ return new Intl.NumberFormat(undefined, format === "currency" ? { ...o, currency: "USD" } : {});
155
+ }
156
+ };
157
+ const full = build(options), compact = build({ ...options, notation: "compact" });
158
+ return { value: (v) => full.format(v), tick: (v) => (Math.abs(v) >= 10000 ? compact.format(v) : full.format(v)) };
159
+ }
160
+ /** Round tick values covering min..max. */
161
+ function niceTicks(min, max, count = 5) {
162
+ if (!(max > min))
163
+ max = min + (Math.abs(min) || 1);
164
+ const raw = (max - min) / count;
165
+ const mag = 10 ** Math.floor(Math.log10(raw));
166
+ const norm = raw / mag;
167
+ const step = (norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 5 ? 5 : 10) * mag;
168
+ const out = [];
169
+ for (let v = Math.floor(min / step) * step; v <= max + step * 0.999 && out.length < 50; v += step)
170
+ out.push(Number(v.toPrecision(12)));
171
+ return out;
172
+ }
173
+ function axis(values, lo, hi, zero) {
174
+ let min = Math.min(...values), max = Math.max(...values);
175
+ if (zero) {
176
+ min = Math.min(0, min);
177
+ max = Math.max(0, max);
178
+ }
179
+ const fixedMin = num(lo), fixedMax = num(hi);
180
+ if (fixedMin !== undefined)
181
+ min = fixedMin;
182
+ if (fixedMax !== undefined)
183
+ max = fixedMax;
184
+ if (!(max > min))
185
+ max = min + (Math.abs(min) || 1);
186
+ let ticks = niceTicks(min, max);
187
+ const from = fixedMin ?? ticks[0], to = fixedMax ?? ticks[ticks.length - 1];
188
+ ticks = ticks.filter((t) => t >= from - 1e-9 && t <= to + 1e-9);
189
+ return { from, to, ticks, at: (v) => (to === from ? 0 : (Math.max(from, Math.min(to, v)) - from) / (to - from)) };
190
+ }
191
+ const clip = (s, n) => (s.length > n ? `${s.slice(0, Math.max(1, n - 1))}…` : s);
192
+ const polar = (cx0, cy0, r, deg) => [cx0 + r * Math.cos((deg * Math.PI) / 180), cy0 - r * Math.sin((deg * Math.PI) / 180)];
193
+ const f = (n) => Number(n.toFixed(2));
194
+ function slicePath(cx0, cy0, inner, outer, a0, a1) {
195
+ if (Math.abs(a1 - a0) >= 360)
196
+ a1 = a0 + Math.sign(a1 - a0) * 359.99;
197
+ const large = Math.abs(a1 - a0) > 180 ? 1 : 0, sweep = a1 < a0 ? 1 : 0;
198
+ const [x0, y0] = polar(cx0, cy0, outer, a0), [x1, y1] = polar(cx0, cy0, outer, a1);
199
+ if (inner <= 0)
200
+ return `M${f(cx0)},${f(cy0)}L${f(x0)},${f(y0)}A${f(outer)},${f(outer)} 0 ${large} ${sweep} ${f(x1)},${f(y1)}Z`;
201
+ const [x2, y2] = polar(cx0, cy0, inner, a1), [x3, y3] = polar(cx0, cy0, inner, a0);
202
+ return `M${f(x0)},${f(y0)}A${f(outer)},${f(outer)} 0 ${large} ${sweep} ${f(x1)},${f(y1)}L${f(x2)},${f(y2)}A${f(inner)},${f(inner)} 0 ${large} ${1 - sweep} ${f(x3)},${f(y3)}Z`;
203
+ }
204
+ const radiusOf = (v, max, fallback) => {
205
+ const n = num(v);
206
+ if (n !== undefined)
207
+ return Math.max(0, Math.min(max, n));
208
+ const pct = typeof v === "string" ? /^\s*(\d+(?:\.\d+)?)\s*%\s*$/.exec(v) : null;
209
+ return pct ? Math.max(0, Math.min(max, (max * Number(pct[1])) / 100)) : fallback;
210
+ };
211
+ const Chart = standard("Chart", ({ props }) => {
212
+ const gradientId = `ainui-chart-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
213
+ const [ref, width] = useWidth(640);
214
+ const height = Math.max(120, num(props.height) ?? 240);
215
+ const type = CHART_TYPES.includes(props.chartType) ? props.chartType : "bar";
216
+ const title = str(props.title);
217
+ const rows = list(props.data).filter((r) => r && typeof r === "object" && !Array.isArray(r));
218
+ const keys = [...new Set(rows.flatMap((r) => Object.keys(r)))];
219
+ const xKey = str(props.xKey) || keys.find((k) => rows.some((r) => typeof r[k] === "string")) || keys[0] || "";
220
+ const declared = list(props.series).map((s) => (typeof s === "string" ? { key: s } : obj(s))).filter((s) => typeof s.key === "string" && s.key);
221
+ const series = (declared.length ? declared : keys.filter((k) => k !== xKey && rows.some((r) => num(r[k]) !== undefined)).map((key) => ({ key })))
222
+ .map((s, i) => ({ key: s.key, label: str(s.label) || s.key, color: color(s.color) ?? tone(i) }));
223
+ const val = (r, key) => num(r[key]) ?? (typeof r[key] === "string" && r[key] !== "" && Number.isFinite(Number(r[key])) ? Number(r[key]) : undefined);
224
+ const fmt = numberFormat(props.format, props.currency);
225
+ const cat = (r, i) => str(r[xKey]) || `${i + 1}`;
226
+ const round = type === "pie" || type === "donut";
227
+ const usable = rows.length > 0 && series.length > 0 && rows.some((r) => series.some((s) => val(r, s.key) !== undefined));
228
+ const slices = round && usable ? rows.map((r, i) => ({ name: cat(r, i), value: Math.max(0, val(r, series[0].key) ?? 0), color: tone(i) })).filter((s) => s.value > 0) : [];
229
+ const total = slices.reduce((a, s) => a + s.value, 0);
230
+ if (!usable || (round && total <= 0)) {
231
+ return _jsxs("figure", { className: "ainui-chart ainui-chart-empty", ref: ref, children: [title && _jsx("figcaption", { className: "ainui-chart-title", children: title }), _jsx("p", { className: "ainui-chart-message", style: { minHeight: Math.min(height, 120) }, children: "No data" })] });
232
+ }
233
+ const tip = (text) => (props.showTooltip === false ? null : _jsx("title", { children: text }));
234
+ const labels = !!props.showValueLabels;
235
+ const yAxis = obj(props.yAxis);
236
+ const marks = [];
237
+ let legend = series.map((s) => ({ label: s.label, color: s.color }));
238
+ let showLegend = props.showLegend !== false && (series.length > 1 || props.showLegend === true);
239
+ if (round) {
240
+ legend = slices.map((s) => ({ label: s.name, color: s.color }));
241
+ showLegend = props.showLegend !== false;
242
+ const cx0 = width / 2, cy0 = height / 2;
243
+ const maxR = Math.max(10, Math.min(width, height) / 2 - 4);
244
+ const outer = radiusOf(props.outerRadius, maxR, maxR * (labels ? 0.72 : 0.96));
245
+ const inner = Math.min(outer - 1, radiusOf(props.innerRadius, maxR, type === "donut" ? outer * 0.6 : 0));
246
+ const start = num(props.startAngle) ?? 90, end = num(props.endAngle) ?? -270;
247
+ const sweep = end - start || -360;
248
+ const pad = slices.length > 1 ? Math.max(0, Math.min(20, num(props.paddingAngle) ?? 0)) : 0;
249
+ const corner = Math.max(0, Math.min(12, num(props.cornerRadius) ?? 0));
250
+ let acc = 0;
251
+ slices.forEach((s, i) => {
252
+ const dir = Math.sign(sweep);
253
+ const a0 = start + (sweep * acc) / total + (dir * pad) / 2;
254
+ acc += s.value;
255
+ const a1 = start + (sweep * acc) / total - (dir * pad) / 2;
256
+ if ((a1 - a0) * dir <= 0)
257
+ return;
258
+ const text = `${s.name}: ${fmt.value(s.value)} (${Math.round((s.value / total) * 1000) / 10}%)`;
259
+ // Rounded corners are approximated by a round-joined outline of the slice's own colour.
260
+ marks.push(_jsx("path", { className: "ainui-chart-slice", d: slicePath(cx0, cy0, inner + corner / 2, outer - corner / 2, a0, a1), style: { fill: s.color, stroke: corner ? s.color : undefined, strokeWidth: corner || undefined, strokeLinejoin: corner ? "round" : undefined }, children: tip(text) }, `s${i}`));
261
+ if (labels) {
262
+ const mid = (a0 + a1) / 2;
263
+ const [lx, ly] = polar(cx0, cy0, outer + 14, mid), [x0, y0] = polar(cx0, cy0, outer + 2, mid), [x1, y1] = polar(cx0, cy0, outer + 10, mid);
264
+ const side = Math.cos((mid * Math.PI) / 180);
265
+ if (props.showLabelLines !== false)
266
+ marks.push(_jsx("line", { className: "ainui-chart-label-line", x1: f(x0), y1: f(y0), x2: f(x1), y2: f(y1) }, `l${i}`));
267
+ marks.push(_jsx("text", { className: "ainui-chart-value", x: f(lx), y: f(ly), dominantBaseline: "middle", textAnchor: Math.abs(side) < 0.2 ? "middle" : side > 0 ? "start" : "end", children: fmt.value(s.value) }, `t${i}`));
268
+ }
269
+ });
270
+ }
271
+ else {
272
+ const horizontal = props.layout === "horizontal" && type === "bar";
273
+ const stacked = !!props.stacked && (type === "bar" || type === "area");
274
+ const n = rows.length;
275
+ const names = rows.map(cat);
276
+ const numericX = type === "scatter" && rows.every((r) => val(r, xKey) !== undefined);
277
+ const extents = [];
278
+ rows.forEach((r) => {
279
+ if (stacked) {
280
+ let pos = 0, neg = 0;
281
+ series.forEach((s) => { const v = val(r, s.key) ?? 0; if (v >= 0)
282
+ pos += v;
283
+ else
284
+ neg += v; });
285
+ extents.push(pos, neg);
286
+ }
287
+ else
288
+ series.forEach((s) => { const v = val(r, s.key); if (v !== undefined)
289
+ extents.push(v); });
290
+ });
291
+ const scale = axis(extents, yAxis.min, yAxis.max, type !== "scatter");
292
+ const tickText = scale.ticks.map(fmt.tick);
293
+ const axisLabel = str(yAxis.label);
294
+ const longest = (texts) => texts.reduce((a, t) => Math.max(a, t.length), 0);
295
+ const top = labels ? 18 : 8, right = 14;
296
+ const left = horizontal ? Math.max(24, Math.min(width * 0.4, num(yAxis.width) ?? Math.min(160, longest(names.map((t) => clip(t, 22))) * 6.6 + 14)))
297
+ : Math.max(24, Math.min(width * 0.4, (num(yAxis.width) ?? Math.min(96, longest(tickText) * 6.6 + 12)) + (axisLabel ? 16 : 0)));
298
+ const bottom = 26 + (horizontal && axisLabel ? 16 : 0);
299
+ const pw = Math.max(10, width - left - right), ph = Math.max(10, height - top - bottom);
300
+ const vy = (v) => top + ph * (1 - scale.at(v));
301
+ const vx = (v) => left + pw * scale.at(v);
302
+ const base = Math.max(scale.from, Math.min(scale.to, 0));
303
+ const xs = numericX ? axis(rows.map((r) => val(r, xKey)), undefined, undefined, false) : undefined;
304
+ const band = (horizontal ? ph : pw) / n;
305
+ const px0 = (i) => (xs ? left + pw * xs.at(val(rows[i], xKey)) : left + band * (i + 0.5));
306
+ // Grid and value axis.
307
+ scale.ticks.forEach((t, i) => {
308
+ if (horizontal) {
309
+ if (props.showGrid !== false)
310
+ marks.push(_jsx("line", { className: "ainui-chart-grid", x1: f(vx(t)), x2: f(vx(t)), y1: top, y2: top + ph }, `g${i}`));
311
+ marks.push(_jsx("text", { className: "ainui-chart-tick", x: f(vx(t)), y: top + ph + 16, textAnchor: "middle", children: tickText[i] }, `a${i}`));
312
+ }
313
+ else {
314
+ if (props.showGrid !== false)
315
+ marks.push(_jsx("line", { className: "ainui-chart-grid", x1: left, x2: left + pw, y1: f(vy(t)), y2: f(vy(t)) }, `g${i}`));
316
+ marks.push(_jsx("text", { className: "ainui-chart-tick", x: left - 6, y: f(vy(t)), textAnchor: "end", dominantBaseline: "middle", children: tickText[i] }, `a${i}`));
317
+ }
318
+ });
319
+ if (axisLabel) {
320
+ marks.push(horizontal
321
+ ? _jsx("text", { className: "ainui-chart-axis-label", x: left + pw / 2, y: height - 4, textAnchor: "middle", children: axisLabel }, "al")
322
+ : _jsx("text", { className: "ainui-chart-axis-label", transform: `translate(11 ${f(top + ph / 2)}) rotate(-90)`, textAnchor: "middle", children: axisLabel }, "al"));
323
+ }
324
+ // Category axis.
325
+ if (xs) {
326
+ xs.ticks.forEach((t, i) => marks.push(_jsx("text", { className: "ainui-chart-tick", x: f(left + pw * xs.at(t)), y: top + ph + 16, textAnchor: "middle", children: fmt.tick(t) }, `c${i}`)));
327
+ }
328
+ else if (horizontal) {
329
+ const every = Math.max(1, Math.ceil(n / Math.max(1, Math.floor(ph / 16))));
330
+ names.forEach((name, i) => { if (i % every === 0)
331
+ marks.push(_jsx("text", { className: "ainui-chart-tick", x: left - 6, y: f(top + band * (i + 0.5)), textAnchor: "end", dominantBaseline: "middle", children: clip(name, Math.max(3, Math.floor((left - 10) / 6.6))) }, `c${i}`)); });
332
+ }
333
+ else {
334
+ const every = Math.max(1, Math.ceil(n / Math.max(1, Math.floor(pw / 64))));
335
+ names.forEach((name, i) => { if (i % every === 0)
336
+ marks.push(_jsx("text", { className: "ainui-chart-tick", x: f(px0(i)), y: top + ph + 16, textAnchor: "middle", children: clip(name, Math.max(4, Math.floor((band * every) / 6.6))) }, `c${i}`)); });
337
+ }
338
+ marks.push(horizontal
339
+ ? _jsx("line", { className: "ainui-chart-axis", x1: f(vx(base)), x2: f(vx(base)), y1: top, y2: top + ph }, "base")
340
+ : _jsx("line", { className: "ainui-chart-axis", x1: left, x2: left + pw, y1: f(vy(base)), y2: f(vy(base)) }, "base"));
341
+ const text = (s, i, v) => `${names[i]} · ${s.label}: ${fmt.value(v)}`;
342
+ if (type === "bar") {
343
+ const group = band * 0.72;
344
+ const each = stacked ? group : group / series.length;
345
+ const r = Math.max(0, num(props.barRadius) ?? 5);
346
+ rows.forEach((row, i) => {
347
+ let pos = 0, neg = 0;
348
+ series.forEach((s, j) => {
349
+ const v = val(row, s.key);
350
+ if (v === undefined)
351
+ return;
352
+ let from = base, to = v;
353
+ if (stacked) {
354
+ if (v >= 0) {
355
+ from = pos;
356
+ pos += v;
357
+ to = pos;
358
+ }
359
+ else {
360
+ from = neg;
361
+ neg += v;
362
+ to = neg;
363
+ }
364
+ }
365
+ const offset = band * i + (band - group) / 2 + (stacked ? 0 : each * j);
366
+ const a = horizontal ? vx(from) : vy(from), b = horizontal ? vx(to) : vy(to);
367
+ const lo = Math.min(a, b), size = Math.max(Math.abs(a - b), v === 0 ? 0 : 1);
368
+ const gap = stacked ? 0 : Math.min(1, each * 0.1);
369
+ const rect = horizontal ? { x: lo, y: top + offset + gap, width: size, height: Math.max(1, each - gap * 2) } : { x: left + offset + gap, y: lo, width: Math.max(1, each - gap * 2), height: size };
370
+ marks.push(_jsx("rect", { className: "ainui-chart-bar", x: f(rect.x), y: f(rect.y), width: f(rect.width), height: f(rect.height), rx: Math.min(r, rect.width / 2, rect.height / 2), style: { fill: stacked ? s.color : `url(#${gradientId}-${j})` }, children: tip(text(s, i, v)) }, `b${i}:${j}`));
371
+ if (labels) {
372
+ marks.push(horizontal
373
+ ? _jsx("text", { className: "ainui-chart-value", x: f(v >= 0 ? rect.x + rect.width + 4 : rect.x - 4), y: f(rect.y + rect.height / 2), textAnchor: v >= 0 ? "start" : "end", dominantBaseline: "middle", children: fmt.tick(v) }, `v${i}:${j}`)
374
+ : _jsx("text", { className: "ainui-chart-value", x: f(rect.x + rect.width / 2), y: f(v >= 0 ? rect.y - 4 : rect.y + rect.height + 12), textAnchor: "middle", children: fmt.tick(v) }, `v${i}:${j}`));
375
+ }
376
+ });
377
+ });
378
+ }
379
+ else {
380
+ const floor = rows.map(() => 0);
381
+ series.forEach((s, j) => {
382
+ const points = [];
383
+ rows.forEach((row, i) => {
384
+ const v = val(row, s.key);
385
+ if (v === undefined)
386
+ return;
387
+ const from = stacked ? floor[i] : base, to = stacked ? floor[i] + v : v;
388
+ if (stacked)
389
+ floor[i] = to;
390
+ points.push({ i, x: px0(i), y: vy(to), y0: vy(from), v });
391
+ });
392
+ if (!points.length)
393
+ return;
394
+ const line = points.map((p, k) => `${k ? "L" : "M"}${f(p.x)},${f(p.y)}`).join("");
395
+ if (type === "area") {
396
+ const back = [...points].reverse().map((p) => `L${f(p.x)},${f(p.y0)}`).join("");
397
+ marks.push(_jsx("path", { className: "ainui-chart-area", d: `${line}${back}Z`, style: { fill: s.color } }, `f${j}`));
398
+ }
399
+ if (type !== "scatter")
400
+ marks.push(_jsx("path", { className: "ainui-chart-line", d: line, style: { stroke: s.color } }, `p${j}`));
401
+ const dots = type === "scatter" || (props.showDots ?? (type === "line" && points.length <= 40)) || points.length === 1;
402
+ points.forEach((p) => {
403
+ // Without dots, an invisible target still carries the tooltip.
404
+ marks.push(_jsx("circle", { className: cx("ainui-chart-dot", !dots && "ainui-chart-dot-hidden"), cx: f(p.x), cy: f(p.y), r: type === "scatter" ? 4 : dots ? 3 : 6, style: dots ? { fill: s.color } : undefined, children: tip(text(s, p.i, p.v)) }, `d${j}:${p.i}`));
405
+ if (labels)
406
+ marks.push(_jsx("text", { className: "ainui-chart-value", x: f(p.x), y: f(p.y - 8), textAnchor: "middle", children: fmt.tick(p.v) }, `v${j}:${p.i}`));
407
+ });
408
+ });
409
+ }
410
+ }
411
+ const shownSeries = round ? [series[0]] : series;
412
+ const summary = `${title ? `${title}. ` : ""}${type[0].toUpperCase()}${type.slice(1)} chart of ${shownSeries.map((s) => s.label).join(", ")}${xKey ? ` by ${xKey}` : ""}, ${rows.length} ${rows.length === 1 ? "point" : "points"}.`;
413
+ return _jsxs("figure", { className: cx("ainui-chart", `ainui-chart-${type}`), ref: ref, children: [title && _jsx("figcaption", { className: "ainui-chart-title", children: title }), _jsxs("svg", { className: "ainui-chart-svg", role: "img", "aria-label": summary, viewBox: `0 0 ${width} ${height}`, width: "100%", height: height, preserveAspectRatio: "xMidYMid meet", children: [_jsx("defs", { children: series.map((sr, j) => _jsxs("linearGradient", { id: `${gradientId}-${j}`, x1: "0", y1: "0", x2: props.layout === "horizontal" && type === "bar" ? "1" : "0", y2: props.layout === "horizontal" && type === "bar" ? "0" : "1", children: [_jsx("stop", { offset: "0%", stopColor: sr.color, stopOpacity: 1 }), _jsx("stop", { offset: "100%", stopColor: sr.color, stopOpacity: 0.55 })] }, j)) }), marks] }), showLegend && _jsx("ul", { className: "ainui-chart-legend", "aria-hidden": "true", children: legend.map((l, i) => _jsxs("li", { children: [_jsx("span", { className: "ainui-chart-swatch", style: { background: l.color } }), l.label] }, i)) }), _jsxs("table", { className: "ainui-chart-table", children: [_jsx("caption", { children: title || "Chart data" }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: xKey || "Item" }), shownSeries.map((s) => _jsx("th", { scope: "col", children: s.label }, s.key))] }) }), _jsx("tbody", { children: rows.map((r, i) => _jsxs("tr", { children: [_jsx("th", { scope: "row", children: cat(r, i) }), shownSeries.map((s) => { const v = val(r, s.key); return _jsx("td", { children: v === undefined ? "" : fmt.value(v) }, s.key); })] }, i)) })] })] });
414
+ });
415
+ /* ---------- Map ---------- */
416
+ const TILE = 256;
417
+ const DEFAULT_TILES = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
418
+ const MAX_ZOOM = 19;
419
+ const coordinate = (v) => (typeof v === "number" ? v : typeof v === "string" && v.trim() !== "" ? Number(v) : NaN);
420
+ /** Web Mercator: world pixel position at a zoom level. */
421
+ function project(lat, lng, zoom) {
422
+ const size = TILE * 2 ** zoom;
423
+ const s = Math.sin((Math.max(-85.0511, Math.min(85.0511, lat)) * Math.PI) / 180);
424
+ return [((lng + 180) / 360) * size, (0.5 - Math.log((1 + s) / (1 - s)) / (4 * Math.PI)) * size];
425
+ }
426
+ function unproject(x, y, zoom) {
427
+ const size = TILE * 2 ** zoom;
428
+ return { lng: (x / size) * 360 - 180, lat: (Math.atan(Math.sinh(Math.PI * (1 - (2 * y) / size))) * 180) / Math.PI };
429
+ }
430
+ const MapView = standard("Map", ({ props }) => {
431
+ const host = useHost();
432
+ const [ref, width] = useWidth(640);
433
+ const [local, setLocal] = useState(undefined);
434
+ const [nudge, setNudge] = useState(0);
435
+ const height = Math.max(120, num(props.height) ?? 240);
436
+ const places = list(props.markers).map((m) => obj(m)).map((m) => ({
437
+ label: str(m.label), lat: coordinate(m.lat), lng: coordinate(m.lng), description: str(m.description), category: str(m.category), icon: str(m.icon),
438
+ })).filter((m) => Number.isFinite(m.lat) && Number.isFinite(m.lng) && Math.abs(m.lat) <= 90 && Math.abs(m.lng) <= 180);
439
+ const selected = typeof props.selected === "string" ? props.selected : local;
440
+ const select = (label) => { setLocal(label); props.setSelected?.(label); };
441
+ const given = obj(props.center);
442
+ const hasCenter = Number.isFinite(coordinate(given.lat)) && Number.isFinite(coordinate(given.lng));
443
+ const names = _jsx("ol", { className: "ainui-map-places", children: places.map((p, i) => _jsx("li", { children: _jsxs("button", { type: "button", className: cx("ainui-map-place", selected === p.label && "ainui-map-place-selected"), "aria-pressed": selected === p.label, onClick: () => select(p.label), children: [_jsx("span", { className: "ainui-map-place-index", "aria-hidden": "true", children: p.icon ? _jsx(IconGlyph, { name: p.icon, size: 12 }) : i + 1 }), _jsxs("span", { className: "ainui-map-place-text", children: [_jsx("span", { className: "ainui-map-place-label", children: p.label || `${p.lat.toFixed(4)}, ${p.lng.toFixed(4)}` }), (p.description || p.category) && _jsx("span", { className: "ainui-map-place-description", children: p.description || p.category })] })] }) }, i)) });
444
+ if (!places.length && !hasCenter)
445
+ return _jsx("div", { className: "ainui-map", ref: ref, children: _jsx("p", { className: "ainui-map-empty", children: "No places" }) });
446
+ // Fit: the highest zoom at which every marker is inside the frame, with room for the pins.
447
+ let fit = 14;
448
+ if (places.length > 1) {
449
+ for (fit = 18; fit > 0; fit--) {
450
+ const pts = places.map((p) => project(p.lat, p.lng, fit));
451
+ const dx = Math.max(...pts.map((p) => p[0])) - Math.min(...pts.map((p) => p[0])), dy = Math.max(...pts.map((p) => p[1])) - Math.min(...pts.map((p) => p[1]));
452
+ if (dx <= Math.max(32, width - 72) && dy <= Math.max(32, height - 72))
453
+ break;
454
+ }
455
+ }
456
+ const asked = num(props.zoom);
457
+ const zoom = Math.max(0, Math.min(MAX_ZOOM, Math.round(asked === undefined ? fit : places.length > 1 ? Math.min(fit, asked) : asked) + nudge));
458
+ let center;
459
+ if (hasCenter)
460
+ center = project(coordinate(given.lat), coordinate(given.lng), zoom);
461
+ else {
462
+ const pts = places.map((p) => project(p.lat, p.lng, zoom));
463
+ center = [(Math.max(...pts.map((p) => p[0])) + Math.min(...pts.map((p) => p[0]))) / 2, (Math.max(...pts.map((p) => p[1])) + Math.min(...pts.map((p) => p[1]))) / 2];
464
+ }
465
+ const left = center[0] - width / 2, top = center[1] - height / 2;
466
+ const world = 2 ** zoom;
467
+ const template = typeof host?.mapTileUrl === "string" && host.mapTileUrl ? host.mapTileUrl : DEFAULT_TILES;
468
+ const tiles = [];
469
+ for (let ty = Math.max(0, Math.floor(top / TILE)); ty <= Math.min(world - 1, Math.floor((top + height) / TILE)); ty++) {
470
+ for (let tx = Math.floor(left / TILE); tx <= Math.floor((left + width) / TILE) && tiles.length < 200; tx++) {
471
+ const wrapped = ((tx % world) + world) % world;
472
+ const src = safeUrl(template.replace(/\{s\}/g, "a").replace(/\{z\}/g, String(zoom)).replace(/\{x\}/g, String(wrapped)).replace(/\{y\}/g, String(ty)).replace(/\{r\}/g, ""));
473
+ if (src)
474
+ tiles.push({ key: `${zoom}/${tx}/${ty}`, src, x: tx * TILE - left, y: ty * TILE - top });
475
+ }
476
+ }
477
+ const pins = places.map((p) => { const [x, y] = project(p.lat, p.lng, zoom); return { ...p, x: x - left, y: y - top }; });
478
+ const middle = unproject(center[0], center[1], zoom);
479
+ return _jsxs("div", { className: "ainui-map", ref: ref, children: [_jsxs("div", { className: "ainui-map-view", role: "group", "aria-label": `Map of ${places.length} ${places.length === 1 ? "place" : "places"}`, style: { height }, "data-zoom": zoom, "data-center": `${middle.lat.toFixed(5)},${middle.lng.toFixed(5)}`, children: [_jsx("div", { className: "ainui-map-tiles", "aria-hidden": "true", children: tiles.map((t) => _jsx("img", { src: t.src, alt: "", width: TILE, height: TILE, loading: "lazy", draggable: false, referrerPolicy: "strict-origin-when-cross-origin", onError: (e) => { e.currentTarget.style.visibility = "hidden"; }, style: { left: Math.round(t.x), top: Math.round(t.y) } }, t.key)) }), props.route && pins.length > 1 && _jsx("svg", { className: "ainui-map-route", "aria-hidden": "true", width: width, height: height, viewBox: `0 0 ${width} ${height}`, children: _jsx("polyline", { points: pins.map((p) => `${f(p.x)},${f(p.y)}`).join(" ") }) }), pins.map((p, i) => _jsx("button", { type: "button", className: cx("ainui-map-marker", selected === p.label && "ainui-map-marker-selected"), title: p.label, "aria-label": p.label || `Place ${i + 1}`, "aria-pressed": selected === p.label, onClick: () => select(p.label), style: { left: f(p.x), top: f(p.y), ...(color(p.category) && /^(info|success|warning|caution|danger|discovery|secondary)$/.test(p.category) ? { background: color(p.category) } : {}) }, children: p.icon ? _jsx(IconGlyph, { name: p.icon, size: 12 }) : i + 1 }, i)), _jsxs("div", { className: "ainui-map-zoom", children: [_jsx("button", { type: "button", "aria-label": "Zoom in", disabled: zoom >= MAX_ZOOM, onClick: () => setNudge((n) => n + 1), children: "+" }), _jsx("button", { type: "button", "aria-label": "Zoom out", disabled: zoom <= 0, onClick: () => setNudge((n) => n - 1), children: "\u2212" })] }), _jsx("span", { className: "ainui-map-attribution", children: "\u00A9 OpenStreetMap contributors" })] }), places.length ? names : _jsx("p", { className: "ainui-map-empty", children: "No places" })] });
480
+ });
481
+ export const data = [Table, TableSection, TableRow, TableCell, List, ListItem, Chart, MapView];
@@ -0,0 +1,11 @@
1
+ /** Standard catalog — feedback: pulse dot, flashcard, popover, modal. */
2
+ import React from "react";
3
+ export type PopoverState = {
4
+ open: boolean;
5
+ setOpen: (next: boolean) => void;
6
+ contentId: string;
7
+ hover: boolean;
8
+ };
9
+ /** What a Popover shares with its PopoverTrigger and PopoverContent. Null outside a Popover. */
10
+ export declare const PopoverContext: React.Context<PopoverState | null>;
11
+ export declare const feedback: import("@a2ui/react").ReactComponentImplementation<import("zod").ZodTypeAny>[];
@@ -0,0 +1,111 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /** Standard catalog — feedback: pulse dot, flashcard, popover, modal. */
4
+ import { createContext, useContext, useEffect, useId, useRef, useState } from "react";
5
+ import { Kids, color, cx, kid, px, space, standard } from "../core.js";
6
+ import { InlineContext } from "./text.js";
7
+ const num = (v, fallback) => (typeof v === "number" && Number.isFinite(v) ? v : fallback);
8
+ const str = (v) => (typeof v === "string" ? v : typeof v === "number" ? String(v) : "");
9
+ /** Open state that follows the bound `open` and writes back through `setOpen`; local when nothing is bound. */
10
+ function useOpen(props) {
11
+ const [open, setLocal] = useState(props.open === true);
12
+ useEffect(() => { setLocal(props.open === true); }, [props.open]);
13
+ const set = (next) => {
14
+ setLocal(next);
15
+ try {
16
+ props.setOpen?.(next);
17
+ }
18
+ catch { /* a literal `open` has nowhere to write */ }
19
+ };
20
+ return [open, set];
21
+ }
22
+ const PulseIndicator = standard("PulseIndicator", ({ props }) => {
23
+ const label = str(props.label);
24
+ const dot = color(props.color) ?? "var(--ainui-success)";
25
+ const style = {
26
+ "--ainui-pulse-size": `${Math.max(1, num(props.size, 12))}px`, "--ainui-pulse-color": dot, "--ainui-pulse-ring": color(props.pulseColor) ?? dot,
27
+ "--ainui-pulse-duration": `${Math.max(0, num(props.duration, 1500))}ms`, "--ainui-pulse-scale": num(props.endScale, 2.4), "--ainui-pulse-opacity": num(props.startOpacity, 0.6),
28
+ };
29
+ return _jsxs("span", { className: "ainui-pulse-indicator", style: style, ...(label ? { role: "img", "aria-label": label, title: label } : { "aria-hidden": true }), children: [_jsx("span", { className: "ainui-pulse-indicator-ring" }), _jsx("span", { className: "ainui-pulse-indicator-dot" })] });
30
+ });
31
+ const FlashcardFlip = standard("FlashcardFlip", ({ props }) => {
32
+ const [flipped, setFlipped] = useState(false);
33
+ const hint = str(props.hint);
34
+ return _jsx("button", { type: "button", className: cx("ainui-flashcard-flip", flipped && "ainui-flashcard-flip-flipped"), "aria-pressed": flipped, onClick: () => setFlipped((f) => !f), children: _jsxs("span", { className: cx("ainui-flashcard-flip-face", flipped ? "ainui-flashcard-flip-back" : "ainui-flashcard-flip-front"), "aria-live": "polite", children: [_jsx("span", { className: "ainui-flashcard-flip-text", children: str(flipped ? props.back : props.front) }), !flipped && hint && _jsx("span", { className: "ainui-flashcard-flip-hint", children: hint })] }, flipped ? "back" : "front") });
35
+ });
36
+ /** What a Popover shares with its PopoverTrigger and PopoverContent. Null outside a Popover. */
37
+ export const PopoverContext = createContext(null);
38
+ const Popover = standard("Popover", ({ props, buildChild }) => {
39
+ const [open, setOpen] = useOpen(props);
40
+ const root = useRef(null);
41
+ const timer = useRef(undefined);
42
+ const contentId = useId();
43
+ const hover = !!props.showOnHover;
44
+ const latest = useRef(setOpen);
45
+ latest.current = setOpen;
46
+ useEffect(() => () => clearTimeout(timer.current), []);
47
+ useEffect(() => {
48
+ if (!open || typeof document === "undefined")
49
+ return;
50
+ const outside = (e) => { if (root.current && !root.current.contains(e.target))
51
+ latest.current(false); };
52
+ const key = (e) => {
53
+ if (e.key !== "Escape")
54
+ return;
55
+ latest.current(false);
56
+ root.current?.querySelector(".ainui-popover-trigger")?.focus?.();
57
+ };
58
+ document.addEventListener("pointerdown", outside);
59
+ document.addEventListener("keydown", key);
60
+ return () => { document.removeEventListener("pointerdown", outside); document.removeEventListener("keydown", key); };
61
+ }, [open]);
62
+ const later = (next, ms) => { clearTimeout(timer.current); timer.current = setTimeout(() => latest.current(next), ms); };
63
+ return _jsx("div", { ref: root, className: cx("ainui-popover", open && "ainui-popover-open"), onMouseEnter: hover ? () => later(true, Math.max(0, num(props.hoverOpenDelay, 0))) : undefined,
64
+ // The short grace period lets the pointer cross the gap between trigger and content.
65
+ onMouseLeave: hover ? () => later(false, 150) : undefined, children: _jsx(PopoverContext.Provider, { value: { open, setOpen, contentId, hover }, children: _jsx(Kids, { of: props.children, buildChild: buildChild }) }) });
66
+ });
67
+ const PopoverTrigger = standard("PopoverTrigger", ({ props, buildChild }) => {
68
+ const popover = useContext(PopoverContext);
69
+ return _jsx("button", { type: "button", className: cx("ainui-popover-trigger", props.block && "ainui-popover-trigger-block"), "aria-haspopup": "dialog", "aria-expanded": popover?.open ?? false, "aria-controls": popover?.open ? popover.contentId : undefined, onClick: () => popover?.setOpen(popover.hover ? true : !popover.open), children: _jsx(InlineContext.Provider, { value: true, children: _jsx(Kids, { of: props.children, buildChild: buildChild }) }) });
70
+ });
71
+ const pick = (v, of, fallback) => (typeof v === "string" && of.includes(v) ? v : fallback);
72
+ const PopoverContent = standard("PopoverContent", ({ props, buildChild }) => {
73
+ const popover = useContext(PopoverContext);
74
+ if (!popover?.open)
75
+ return null;
76
+ return _jsx("div", { id: popover.contentId, role: "dialog", className: cx("ainui-popover-content", `ainui-popover-content-${pick(props.side, ["top", "bottom", "left", "right"], "bottom")}`, `ainui-popover-content-align-${pick(props.align, ["start", "center", "end"], "center")}`), style: { "--ainui-popover-offset": `${num(props.sideOffset, 6)}px`, width: space(props.width) }, children: _jsx(Kids, { of: props.children, buildChild: buildChild }) });
77
+ });
78
+ const FOCUSABLE = "button, a[href], input, select, textarea, [tabindex]";
79
+ const Modal = standard("Modal", ({ props, buildChild }) => {
80
+ const [open, setOpen] = useOpen(props);
81
+ const trigger = useRef(null), dialog = useRef(null);
82
+ const titleId = useId();
83
+ const title = str(props.title);
84
+ // A trigger that is not focusable itself (a Text) becomes a button; a Button keeps its own semantics.
85
+ const [bare, setBare] = useState(false);
86
+ useEffect(() => { setBare(!!trigger.current && !trigger.current.querySelector(FOCUSABLE)); }, [props.trigger]);
87
+ const latest = useRef(setOpen);
88
+ latest.current = setOpen;
89
+ const wasOpen = useRef(false);
90
+ useEffect(() => {
91
+ if (open)
92
+ dialog.current?.focus?.();
93
+ else if (wasOpen.current)
94
+ (trigger.current?.querySelector(FOCUSABLE) ?? trigger.current)?.focus?.();
95
+ wasOpen.current = open;
96
+ if (!open || typeof document === "undefined")
97
+ return;
98
+ const key = (e) => { if (e.key === "Escape") {
99
+ e.stopPropagation();
100
+ latest.current(false);
101
+ } };
102
+ document.addEventListener("keydown", key);
103
+ return () => document.removeEventListener("keydown", key);
104
+ }, [open]);
105
+ return _jsxs("div", { className: "ainui-modal", style: typeof props.weight === "number" ? { flex: `${props.weight} 1 0%`, minWidth: 0 } : undefined, children: [_jsx("span", { ref: trigger, className: "ainui-modal-trigger", "aria-haspopup": "dialog", ...(bare ? { role: "button", tabIndex: 0, "aria-expanded": open } : {}), onClick: () => setOpen(true), onKeyDown: (e) => { if (bare && e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
106
+ e.preventDefault();
107
+ setOpen(true);
108
+ } }, children: _jsx(InlineContext.Provider, { value: bare, children: kid(buildChild, props.trigger) }) }), open && _jsx("div", { className: "ainui-modal-backdrop", onClick: (e) => { if (e.target === e.currentTarget)
109
+ setOpen(false); }, children: _jsxs("div", { ref: dialog, role: "dialog", "aria-modal": "true", "aria-labelledby": title ? titleId : undefined, "aria-label": title ? undefined : "Dialog", tabIndex: -1, className: "ainui-modal-dialog", style: { maxWidth: px(props.maxWidth) ?? "480px" }, children: [_jsxs("div", { className: "ainui-modal-header", children: [title ? _jsx("h2", { id: titleId, className: "ainui-modal-title", children: title }) : _jsx("span", {}), _jsx("button", { type: "button", className: "ainui-modal-close", "aria-label": "Close", onClick: () => setOpen(false), children: "×" })] }), _jsx("div", { className: "ainui-modal-body", children: kid(buildChild, props.content) })] }) })] });
110
+ });
111
+ export const feedback = [PulseIndicator, FlashcardFlip, Popover, PopoverTrigger, PopoverContent, Modal];
@@ -0,0 +1,5 @@
1
+ /** Standard catalog — inputs: buttons, forms and the controls that write a value back to the data model. */
2
+ import React from "react";
3
+ /** True inside a Form, so a Button with `submit` becomes its submit button. */
4
+ export declare const FormContext: React.Context<boolean>;
5
+ export declare const inputs: import("@a2ui/react").ReactComponentImplementation<import("zod").ZodTypeAny>[];