@glyphjs/components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/index.cjs +4925 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +546 -0
- package/dist/index.d.ts +546 -0
- package/dist/index.js +4855 -0
- package/dist/index.js.map +1 -0
- package/package.json +87 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4925 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var schemas = require('@glyphjs/schemas');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var d32 = require('d3');
|
|
7
|
+
var dagre = require('dagre');
|
|
8
|
+
var katex = require('katex');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var d32__namespace = /*#__PURE__*/_interopNamespace(d32);
|
|
31
|
+
var dagre__default = /*#__PURE__*/_interopDefault(dagre);
|
|
32
|
+
var katex__default = /*#__PURE__*/_interopDefault(katex);
|
|
33
|
+
|
|
34
|
+
// src/callout/index.ts
|
|
35
|
+
var CALLOUT_ICONS = {
|
|
36
|
+
info: "\u2139\uFE0F",
|
|
37
|
+
warning: "\u26A0\uFE0F",
|
|
38
|
+
error: "\u274C",
|
|
39
|
+
tip: "\u{1F4A1}"
|
|
40
|
+
};
|
|
41
|
+
var CALLOUT_LABELS = {
|
|
42
|
+
info: "Information",
|
|
43
|
+
warning: "Warning",
|
|
44
|
+
error: "Error",
|
|
45
|
+
tip: "Tip"
|
|
46
|
+
};
|
|
47
|
+
function Callout({ data }) {
|
|
48
|
+
const { type, title, content } = data;
|
|
49
|
+
const containerStyle3 = {
|
|
50
|
+
backgroundColor: `var(--glyph-callout-${type}-bg)`,
|
|
51
|
+
borderLeft: `4px solid var(--glyph-callout-${type}-border)`,
|
|
52
|
+
borderRadius: "var(--glyph-radius-md, 0.1875rem)",
|
|
53
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
54
|
+
margin: "var(--glyph-spacing-sm, 0.5rem) 0",
|
|
55
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
56
|
+
color: "var(--glyph-text, #1a2035)",
|
|
57
|
+
display: "flex",
|
|
58
|
+
gap: "var(--glyph-spacing-sm, 0.5rem)",
|
|
59
|
+
alignItems: "flex-start"
|
|
60
|
+
};
|
|
61
|
+
const iconStyle = {
|
|
62
|
+
flexShrink: 0,
|
|
63
|
+
fontSize: "1.25em",
|
|
64
|
+
lineHeight: 1
|
|
65
|
+
};
|
|
66
|
+
const bodyStyle2 = {
|
|
67
|
+
flex: 1,
|
|
68
|
+
minWidth: 0
|
|
69
|
+
};
|
|
70
|
+
const titleStyle2 = {
|
|
71
|
+
fontWeight: 700,
|
|
72
|
+
marginBottom: "var(--glyph-spacing-xs, 0.25rem)"
|
|
73
|
+
};
|
|
74
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "note", "aria-label": CALLOUT_LABELS[type], style: containerStyle3, children: [
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: iconStyle, "aria-hidden": "true", children: CALLOUT_ICONS[type] }),
|
|
76
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: bodyStyle2, children: [
|
|
77
|
+
title && /* @__PURE__ */ jsxRuntime.jsx("div", { style: titleStyle2, children: title }),
|
|
78
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: content })
|
|
79
|
+
] })
|
|
80
|
+
] });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/callout/index.ts
|
|
84
|
+
var calloutDefinition = {
|
|
85
|
+
type: "ui:callout",
|
|
86
|
+
schema: schemas.calloutSchema,
|
|
87
|
+
render: Callout
|
|
88
|
+
};
|
|
89
|
+
var DEFAULT_WIDTH = 600;
|
|
90
|
+
var DEFAULT_HEIGHT = 400;
|
|
91
|
+
var MARGIN = { top: 20, right: 30, bottom: 50, left: 60 };
|
|
92
|
+
var COLOR_SCHEME = [
|
|
93
|
+
"#00d4aa",
|
|
94
|
+
// cyan-green
|
|
95
|
+
"#b44dff",
|
|
96
|
+
// purple
|
|
97
|
+
"#22c55e",
|
|
98
|
+
// green
|
|
99
|
+
"#e040fb",
|
|
100
|
+
// magenta
|
|
101
|
+
"#00e5ff",
|
|
102
|
+
// teal
|
|
103
|
+
"#84cc16",
|
|
104
|
+
// lime
|
|
105
|
+
"#f472b6",
|
|
106
|
+
// rose
|
|
107
|
+
"#fb923c",
|
|
108
|
+
// orange
|
|
109
|
+
"#818cf8",
|
|
110
|
+
// indigo
|
|
111
|
+
"#38bdf8"
|
|
112
|
+
// sky
|
|
113
|
+
];
|
|
114
|
+
function getNumericValue(d, key) {
|
|
115
|
+
const v = d[key];
|
|
116
|
+
return typeof v === "number" ? v : Number(v);
|
|
117
|
+
}
|
|
118
|
+
function getAllNumericValues(series, key) {
|
|
119
|
+
return series.flatMap(
|
|
120
|
+
(s) => s.data.map((d) => getNumericValue(d, key))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
function renderAxes(g, xScale, yScale, xAxisConfig, yAxisConfig, innerWidth, innerHeight) {
|
|
124
|
+
const xAxisG = g.append("g").attr("class", "x-axis").attr("transform", `translate(0,${String(innerHeight)})`);
|
|
125
|
+
if ("bandwidth" in xScale) {
|
|
126
|
+
xAxisG.call(
|
|
127
|
+
d32__namespace.axisBottom(xScale)
|
|
128
|
+
);
|
|
129
|
+
} else {
|
|
130
|
+
xAxisG.call(
|
|
131
|
+
d32__namespace.axisBottom(xScale)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
xAxisG.selectAll("text, line, path").attr("fill", "var(--glyph-text, #1a2035)").attr("stroke", "var(--glyph-grid, #1a2035)");
|
|
135
|
+
if (xAxisConfig?.label) {
|
|
136
|
+
g.append("text").attr("class", "x-label").attr("x", innerWidth / 2).attr("y", innerHeight + MARGIN.bottom - 6).attr("text-anchor", "middle").attr("fill", "var(--glyph-text, #1a2035)").attr("font-size", "12px").text(xAxisConfig.label);
|
|
137
|
+
}
|
|
138
|
+
const yAxisG = g.append("g").attr("class", "y-axis");
|
|
139
|
+
yAxisG.call(
|
|
140
|
+
d32__namespace.axisLeft(yScale)
|
|
141
|
+
);
|
|
142
|
+
yAxisG.selectAll("text, line, path").attr("fill", "var(--glyph-text, #1a2035)").attr("stroke", "var(--glyph-grid, #1a2035)");
|
|
143
|
+
if (yAxisConfig?.label) {
|
|
144
|
+
g.append("text").attr("class", "y-label").attr("transform", "rotate(-90)").attr("x", -innerHeight / 2).attr("y", -MARGIN.left + 14).attr("text-anchor", "middle").attr("fill", "var(--glyph-text, #1a2035)").attr("font-size", "12px").text(yAxisConfig.label);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function renderGridLines(g, yScale, innerWidth) {
|
|
148
|
+
g.append("g").attr("class", "grid").selectAll("line").data(yScale.ticks()).join("line").attr("x1", 0).attr("x2", innerWidth).attr("y1", (d) => yScale(d)).attr("y2", (d) => yScale(d)).attr("stroke", "var(--glyph-grid, #1a2035)").attr("stroke-opacity", 0.5).attr("stroke-dasharray", "2,2");
|
|
149
|
+
}
|
|
150
|
+
function renderLineSeries(g, seriesData, xScalePoint, yScale, yKey, xKey, color3, index, seriesName, showTooltip, hideTooltip) {
|
|
151
|
+
const line6 = d32__namespace.line().x((d) => xScalePoint(d)).y((d) => yScale(getNumericValue(d, yKey)));
|
|
152
|
+
g.append("path").datum(seriesData).attr("fill", "none").attr("stroke", color3).attr("stroke-width", 2).attr("d", line6);
|
|
153
|
+
g.selectAll(`.dot-${String(index)}`).data(seriesData).join("circle").attr("class", `dot-${String(index)}`).attr("cx", (d) => xScalePoint(d)).attr("cy", (d) => yScale(getNumericValue(d, yKey))).attr("r", 3.5).attr("fill", color3).attr("cursor", "pointer").on("mouseenter", function(event, d) {
|
|
154
|
+
showTooltip(event, `${seriesName}: ${String(d[xKey] ?? "")}, ${String(d[yKey] ?? "")}`);
|
|
155
|
+
}).on("mouseleave", () => hideTooltip());
|
|
156
|
+
}
|
|
157
|
+
function renderAreaSeries(g, seriesData, xScalePoint, yScale, yKey, xKey, innerHeight, color3, index, seriesName, showTooltip, hideTooltip) {
|
|
158
|
+
const area2 = d32__namespace.area().x((d) => xScalePoint(d)).y0(innerHeight).y1((d) => yScale(getNumericValue(d, yKey)));
|
|
159
|
+
g.append("path").datum(seriesData).attr("fill", color3).attr("fill-opacity", 0.3).attr("stroke", color3).attr("stroke-width", 1.5).attr("d", area2);
|
|
160
|
+
g.selectAll(`.dot-${String(index)}`).data(seriesData).join("circle").attr("class", `dot-${String(index)}`).attr("cx", (d) => xScalePoint(d)).attr("cy", (d) => yScale(getNumericValue(d, yKey))).attr("r", 3).attr("fill", color3).attr("cursor", "pointer").on("mouseenter", function(event, d) {
|
|
161
|
+
showTooltip(event, `${seriesName}: ${String(d[xKey] ?? "")}, ${String(d[yKey] ?? "")}`);
|
|
162
|
+
}).on("mouseleave", () => hideTooltip());
|
|
163
|
+
}
|
|
164
|
+
function renderBarSeries(g, seriesData, xScale, yScale, yKey, xKey, color3, index, seriesCount, innerHeight, seriesName, showTooltip, hideTooltip) {
|
|
165
|
+
if (!("bandwidth" in xScale)) return;
|
|
166
|
+
const band = xScale;
|
|
167
|
+
const barWidth = band.bandwidth() / seriesCount;
|
|
168
|
+
g.selectAll(`.bar-${String(index)}`).data(seriesData).join("rect").attr("class", `bar-${String(index)}`).attr("x", (d) => (band(String(d[xKey] ?? "")) ?? 0) + barWidth * index).attr("y", (d) => yScale(getNumericValue(d, yKey))).attr("width", barWidth - 1).attr("height", (d) => innerHeight - yScale(getNumericValue(d, yKey))).attr("fill", color3).attr("cursor", "pointer").on("mouseenter", function(event, d) {
|
|
169
|
+
showTooltip(event, `${seriesName}: ${String(d[xKey] ?? "")}, ${String(d[yKey] ?? "")}`);
|
|
170
|
+
}).on("mouseleave", () => hideTooltip());
|
|
171
|
+
}
|
|
172
|
+
function renderOHLCSeries(g, seriesData, xScale, xScalePoint, yScale, innerWidth, seriesName, showTooltip, hideTooltip) {
|
|
173
|
+
const candleWidth = "bandwidth" in xScale ? xScale.bandwidth() * 0.6 : Math.max(4, innerWidth / (seriesData.length * 2));
|
|
174
|
+
seriesData.forEach((d) => {
|
|
175
|
+
const open = getNumericValue(d, "open");
|
|
176
|
+
const close = getNumericValue(d, "close");
|
|
177
|
+
const high = getNumericValue(d, "high");
|
|
178
|
+
const low = getNumericValue(d, "low");
|
|
179
|
+
const cx = xScalePoint(d);
|
|
180
|
+
const isBullish = close >= open;
|
|
181
|
+
const candleColor = isBullish ? "var(--glyph-chart-bullish, #22c55e)" : "var(--glyph-chart-bearish, #f87171)";
|
|
182
|
+
g.append("line").attr("x1", cx).attr("x2", cx).attr("y1", yScale(high)).attr("y2", yScale(low)).attr("stroke", candleColor).attr("stroke-width", 1);
|
|
183
|
+
const bodyTop = yScale(Math.max(open, close));
|
|
184
|
+
const bodyBottom = yScale(Math.min(open, close));
|
|
185
|
+
const bodyHeight = Math.max(1, bodyBottom - bodyTop);
|
|
186
|
+
g.append("rect").attr("x", cx - candleWidth / 2).attr("y", bodyTop).attr("width", candleWidth).attr("height", bodyHeight).attr("fill", candleColor).attr("stroke", candleColor).attr("cursor", "pointer").on("mouseenter", (event) => {
|
|
187
|
+
showTooltip(
|
|
188
|
+
event,
|
|
189
|
+
`${seriesName}: O=${String(open)} H=${String(high)} L=${String(low)} C=${String(close)}`
|
|
190
|
+
);
|
|
191
|
+
}).on("mouseleave", () => hideTooltip());
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function renderLegend(sel, series, marginLeft, marginTop, fontSize = "12px") {
|
|
195
|
+
const legendG = sel.append("g").attr("transform", `translate(${String(marginLeft + 8)},${String(marginTop)})`);
|
|
196
|
+
series.forEach((s, i) => {
|
|
197
|
+
const color3 = COLOR_SCHEME[i % COLOR_SCHEME.length] ?? "var(--glyph-text, #1a2035)";
|
|
198
|
+
const row = legendG.append("g").attr("transform", `translate(0,${String(i * 20)})`);
|
|
199
|
+
row.append("rect").attr("width", 14).attr("height", 14).attr("fill", color3).attr("rx", 2);
|
|
200
|
+
row.append("text").attr("x", 20).attr("y", 11).attr("fill", "var(--glyph-text, #1a2035)").attr("font-size", fontSize).text(s.name);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function ChartAccessibleTable({
|
|
204
|
+
type,
|
|
205
|
+
series,
|
|
206
|
+
xKey,
|
|
207
|
+
yKey,
|
|
208
|
+
xLabel,
|
|
209
|
+
yLabel
|
|
210
|
+
}) {
|
|
211
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
212
|
+
"table",
|
|
213
|
+
{
|
|
214
|
+
style: {
|
|
215
|
+
position: "absolute",
|
|
216
|
+
width: "1px",
|
|
217
|
+
height: "1px",
|
|
218
|
+
padding: 0,
|
|
219
|
+
margin: "-1px",
|
|
220
|
+
overflow: "hidden",
|
|
221
|
+
clip: "rect(0,0,0,0)",
|
|
222
|
+
whiteSpace: "nowrap",
|
|
223
|
+
border: 0
|
|
224
|
+
},
|
|
225
|
+
children: [
|
|
226
|
+
/* @__PURE__ */ jsxRuntime.jsxs("caption", { children: [
|
|
227
|
+
type,
|
|
228
|
+
" chart data"
|
|
229
|
+
] }),
|
|
230
|
+
series.map((s, si) => /* @__PURE__ */ jsxRuntime.jsxs("tbody", { children: [
|
|
231
|
+
/* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("th", { colSpan: 2, children: s.name }) }),
|
|
232
|
+
/* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
233
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { children: xLabel ?? xKey }),
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { children: yLabel ?? yKey })
|
|
235
|
+
] }),
|
|
236
|
+
s.data.map((d, di) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
237
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: String(d[xKey] ?? "") }),
|
|
238
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: type === "ohlc" ? `O=${String(d["open"] ?? "")} H=${String(d["high"] ?? "")} L=${String(d["low"] ?? "")} C=${String(d["close"] ?? "")}` : String(d[yKey] ?? "") })
|
|
239
|
+
] }, di))
|
|
240
|
+
] }, si))
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
function computeScales(width, height, type, series, xKey, yKey, margin) {
|
|
246
|
+
const innerWidth = width - margin.left - margin.right;
|
|
247
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
248
|
+
const firstRecord = series[0]?.data[0];
|
|
249
|
+
const xIsNumeric = firstRecord != null && typeof firstRecord[xKey] === "number";
|
|
250
|
+
let xScale;
|
|
251
|
+
let xScalePoint;
|
|
252
|
+
if (type === "bar" || !xIsNumeric) {
|
|
253
|
+
const allLabels = series.flatMap(
|
|
254
|
+
(s) => s.data.map((d) => String(d[xKey] ?? ""))
|
|
255
|
+
);
|
|
256
|
+
const uniqueLabels = [...new Set(allLabels)];
|
|
257
|
+
const band = d32__namespace.scaleBand().domain(uniqueLabels).range([0, innerWidth]).padding(0.2);
|
|
258
|
+
xScale = band;
|
|
259
|
+
xScalePoint = (d) => (band(String(d[xKey] ?? "")) ?? 0) + band.bandwidth() / 2;
|
|
260
|
+
} else {
|
|
261
|
+
const allX = getAllNumericValues(series, xKey);
|
|
262
|
+
const linear = d32__namespace.scaleLinear().domain(d32__namespace.extent(allX)).nice().range([0, innerWidth]);
|
|
263
|
+
xScale = linear;
|
|
264
|
+
xScalePoint = (d) => linear(getNumericValue(d, xKey));
|
|
265
|
+
}
|
|
266
|
+
let yMin;
|
|
267
|
+
let yMax;
|
|
268
|
+
if (type === "ohlc") {
|
|
269
|
+
const lows = getAllNumericValues(series, "low");
|
|
270
|
+
const highs = getAllNumericValues(series, "high");
|
|
271
|
+
yMin = d32__namespace.min(lows) ?? 0;
|
|
272
|
+
yMax = d32__namespace.max(highs) ?? 0;
|
|
273
|
+
} else {
|
|
274
|
+
const allY = getAllNumericValues(series, yKey);
|
|
275
|
+
yMin = d32__namespace.min(allY) ?? 0;
|
|
276
|
+
yMax = d32__namespace.max(allY) ?? 0;
|
|
277
|
+
}
|
|
278
|
+
const yScale = d32__namespace.scaleLinear().domain([yMin, yMax]).nice().range([innerHeight, 0]);
|
|
279
|
+
return { xScale, xScalePoint, yScale, innerWidth, innerHeight };
|
|
280
|
+
}
|
|
281
|
+
function Chart({
|
|
282
|
+
data,
|
|
283
|
+
container: containerCtx
|
|
284
|
+
}) {
|
|
285
|
+
const containerRef = react.useRef(null);
|
|
286
|
+
const svgRef = react.useRef(null);
|
|
287
|
+
const tooltipRef = react.useRef(null);
|
|
288
|
+
const [width, setWidth] = react.useState(DEFAULT_WIDTH);
|
|
289
|
+
const { type, series, xAxis, yAxis, legend } = data;
|
|
290
|
+
const xKey = xAxis?.key ?? "x";
|
|
291
|
+
const yKey = yAxis?.key ?? "y";
|
|
292
|
+
const height = DEFAULT_HEIGHT;
|
|
293
|
+
const isCompact = containerCtx.tier === "compact";
|
|
294
|
+
const margin = isCompact ? {
|
|
295
|
+
top: Math.round(MARGIN.top * 0.7),
|
|
296
|
+
right: Math.round(MARGIN.right * 0.7),
|
|
297
|
+
bottom: Math.round(MARGIN.bottom * 0.7),
|
|
298
|
+
left: Math.round(MARGIN.left * 0.7)
|
|
299
|
+
} : MARGIN;
|
|
300
|
+
react.useEffect(() => {
|
|
301
|
+
const container = containerRef.current;
|
|
302
|
+
if (!container) return;
|
|
303
|
+
const observer = new ResizeObserver((entries) => {
|
|
304
|
+
for (const entry of entries) {
|
|
305
|
+
const cr = entry.contentRect;
|
|
306
|
+
if (cr.width > 0) {
|
|
307
|
+
setWidth(cr.width);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
observer.observe(container);
|
|
312
|
+
return () => observer.disconnect();
|
|
313
|
+
}, []);
|
|
314
|
+
const showTooltip = react.useCallback((event, text) => {
|
|
315
|
+
const tip = tooltipRef.current;
|
|
316
|
+
if (!tip) return;
|
|
317
|
+
tip.textContent = text;
|
|
318
|
+
tip.style.display = "block";
|
|
319
|
+
tip.style.left = `${String(event.offsetX + 12)}px`;
|
|
320
|
+
tip.style.top = `${String(event.offsetY - 12)}px`;
|
|
321
|
+
}, []);
|
|
322
|
+
const hideTooltip = react.useCallback(() => {
|
|
323
|
+
const tip = tooltipRef.current;
|
|
324
|
+
if (!tip) return;
|
|
325
|
+
tip.style.display = "none";
|
|
326
|
+
}, []);
|
|
327
|
+
const scales = react.useMemo(
|
|
328
|
+
() => computeScales(width, height, type, series, xKey, yKey, margin),
|
|
329
|
+
[width, height, type, series, xKey, yKey, margin]
|
|
330
|
+
);
|
|
331
|
+
react.useEffect(() => {
|
|
332
|
+
const svg = svgRef.current;
|
|
333
|
+
if (!svg || series.length === 0) return;
|
|
334
|
+
const sel = d32__namespace.select(svg);
|
|
335
|
+
sel.selectAll("*").remove();
|
|
336
|
+
const { xScale, xScalePoint, yScale, innerWidth, innerHeight } = scales;
|
|
337
|
+
const g = sel.append("g").attr("transform", `translate(${String(margin.left)},${String(margin.top)})`);
|
|
338
|
+
renderAxes(g, xScale, yScale, xAxis, yAxis, innerWidth, innerHeight);
|
|
339
|
+
renderGridLines(g, yScale, innerWidth);
|
|
340
|
+
series.forEach((s, i) => {
|
|
341
|
+
const color3 = COLOR_SCHEME[i % COLOR_SCHEME.length] ?? "#333";
|
|
342
|
+
switch (type) {
|
|
343
|
+
case "line":
|
|
344
|
+
renderLineSeries(
|
|
345
|
+
g,
|
|
346
|
+
s.data,
|
|
347
|
+
xScalePoint,
|
|
348
|
+
yScale,
|
|
349
|
+
yKey,
|
|
350
|
+
xKey,
|
|
351
|
+
color3,
|
|
352
|
+
i,
|
|
353
|
+
s.name,
|
|
354
|
+
showTooltip,
|
|
355
|
+
hideTooltip
|
|
356
|
+
);
|
|
357
|
+
break;
|
|
358
|
+
case "area":
|
|
359
|
+
renderAreaSeries(
|
|
360
|
+
g,
|
|
361
|
+
s.data,
|
|
362
|
+
xScalePoint,
|
|
363
|
+
yScale,
|
|
364
|
+
yKey,
|
|
365
|
+
xKey,
|
|
366
|
+
innerHeight,
|
|
367
|
+
color3,
|
|
368
|
+
i,
|
|
369
|
+
s.name,
|
|
370
|
+
showTooltip,
|
|
371
|
+
hideTooltip
|
|
372
|
+
);
|
|
373
|
+
break;
|
|
374
|
+
case "bar":
|
|
375
|
+
renderBarSeries(
|
|
376
|
+
g,
|
|
377
|
+
s.data,
|
|
378
|
+
xScale,
|
|
379
|
+
yScale,
|
|
380
|
+
yKey,
|
|
381
|
+
xKey,
|
|
382
|
+
color3,
|
|
383
|
+
i,
|
|
384
|
+
series.length,
|
|
385
|
+
innerHeight,
|
|
386
|
+
s.name,
|
|
387
|
+
showTooltip,
|
|
388
|
+
hideTooltip
|
|
389
|
+
);
|
|
390
|
+
break;
|
|
391
|
+
case "ohlc":
|
|
392
|
+
renderOHLCSeries(
|
|
393
|
+
g,
|
|
394
|
+
s.data,
|
|
395
|
+
xScale,
|
|
396
|
+
xScalePoint,
|
|
397
|
+
yScale,
|
|
398
|
+
innerWidth,
|
|
399
|
+
s.name,
|
|
400
|
+
showTooltip,
|
|
401
|
+
hideTooltip
|
|
402
|
+
);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
if (legend) {
|
|
407
|
+
renderLegend(sel, series, margin.left, margin.top, isCompact ? "10px" : void 0);
|
|
408
|
+
}
|
|
409
|
+
}, [
|
|
410
|
+
scales,
|
|
411
|
+
type,
|
|
412
|
+
series,
|
|
413
|
+
xKey,
|
|
414
|
+
yKey,
|
|
415
|
+
xAxis,
|
|
416
|
+
yAxis,
|
|
417
|
+
legend,
|
|
418
|
+
margin,
|
|
419
|
+
isCompact,
|
|
420
|
+
showTooltip,
|
|
421
|
+
hideTooltip
|
|
422
|
+
]);
|
|
423
|
+
const ariaLabel = `${type} chart with ${String(series.length)} series: ${series.map((s) => s.name).join(", ")}`;
|
|
424
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
425
|
+
"div",
|
|
426
|
+
{
|
|
427
|
+
ref: containerRef,
|
|
428
|
+
style: {
|
|
429
|
+
position: "relative",
|
|
430
|
+
width: "100%",
|
|
431
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)"
|
|
432
|
+
},
|
|
433
|
+
children: [
|
|
434
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
435
|
+
"svg",
|
|
436
|
+
{
|
|
437
|
+
ref: svgRef,
|
|
438
|
+
role: "img",
|
|
439
|
+
"aria-label": ariaLabel,
|
|
440
|
+
width,
|
|
441
|
+
height,
|
|
442
|
+
viewBox: `0 0 ${String(width)} ${String(height)}`,
|
|
443
|
+
style: { display: "block", maxWidth: "100%", height: "auto" }
|
|
444
|
+
}
|
|
445
|
+
),
|
|
446
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
447
|
+
"div",
|
|
448
|
+
{
|
|
449
|
+
ref: tooltipRef,
|
|
450
|
+
role: "tooltip",
|
|
451
|
+
"aria-live": "polite",
|
|
452
|
+
style: {
|
|
453
|
+
display: "none",
|
|
454
|
+
position: "absolute",
|
|
455
|
+
pointerEvents: "none",
|
|
456
|
+
backgroundColor: "var(--glyph-tooltip-bg, rgba(0,0,0,0.8))",
|
|
457
|
+
color: "var(--glyph-tooltip-text, #d4dae3)",
|
|
458
|
+
padding: "4px 8px",
|
|
459
|
+
borderRadius: "3px",
|
|
460
|
+
fontSize: "12px",
|
|
461
|
+
whiteSpace: "nowrap",
|
|
462
|
+
zIndex: 10
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
),
|
|
466
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
467
|
+
ChartAccessibleTable,
|
|
468
|
+
{
|
|
469
|
+
type,
|
|
470
|
+
series,
|
|
471
|
+
xKey,
|
|
472
|
+
yKey,
|
|
473
|
+
xLabel: xAxis?.label,
|
|
474
|
+
yLabel: yAxis?.label
|
|
475
|
+
}
|
|
476
|
+
)
|
|
477
|
+
]
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/chart/index.ts
|
|
483
|
+
var chartDefinition = {
|
|
484
|
+
type: "ui:chart",
|
|
485
|
+
schema: schemas.chartSchema,
|
|
486
|
+
render: Chart
|
|
487
|
+
};
|
|
488
|
+
var STATUS_LABELS = {
|
|
489
|
+
pending: "Pending",
|
|
490
|
+
active: "Active",
|
|
491
|
+
completed: "Completed"
|
|
492
|
+
};
|
|
493
|
+
function Steps({ data }) {
|
|
494
|
+
const { steps } = data;
|
|
495
|
+
const listStyle = {
|
|
496
|
+
listStyle: "none",
|
|
497
|
+
padding: 0,
|
|
498
|
+
margin: "var(--glyph-spacing-sm, 0.5rem) 0",
|
|
499
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
500
|
+
color: "var(--glyph-text, #1a2035)"
|
|
501
|
+
};
|
|
502
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ol", { role: "list", style: listStyle, children: steps.map((step, index) => {
|
|
503
|
+
const status = step.status ?? "pending";
|
|
504
|
+
const isLast = index === steps.length - 1;
|
|
505
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
506
|
+
"li",
|
|
507
|
+
{
|
|
508
|
+
"aria-label": `Step ${String(index + 1)}: ${step.title} \u2014 ${STATUS_LABELS[status]}`,
|
|
509
|
+
...status === "active" ? { "aria-current": "step" } : {},
|
|
510
|
+
style: itemStyle(isLast),
|
|
511
|
+
children: [
|
|
512
|
+
!isLast && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", style: connectorStyle(status) }),
|
|
513
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", style: indicatorStyle(status), children: status === "completed" ? "\u2713" : "" }),
|
|
514
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: bodyStyle, children: [
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: titleStyle(status), children: step.title }),
|
|
516
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: contentStyle(status), children: step.content })
|
|
517
|
+
] })
|
|
518
|
+
]
|
|
519
|
+
},
|
|
520
|
+
index
|
|
521
|
+
);
|
|
522
|
+
}) });
|
|
523
|
+
}
|
|
524
|
+
var INDICATOR_SIZE = "1.5rem";
|
|
525
|
+
var CONNECTOR_WIDTH = "2px";
|
|
526
|
+
function colorForStatus(status) {
|
|
527
|
+
switch (status) {
|
|
528
|
+
case "pending":
|
|
529
|
+
return "var(--glyph-steps-pending-color, #7a8599)";
|
|
530
|
+
case "active":
|
|
531
|
+
return "var(--glyph-steps-active-color, #00d4aa)";
|
|
532
|
+
case "completed":
|
|
533
|
+
return "var(--glyph-steps-completed-color, #22c55e)";
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function itemStyle(isLast) {
|
|
537
|
+
return {
|
|
538
|
+
position: "relative",
|
|
539
|
+
display: "flex",
|
|
540
|
+
gap: "var(--glyph-spacing-sm, 0.75rem)",
|
|
541
|
+
alignItems: "flex-start",
|
|
542
|
+
paddingBottom: isLast ? 0 : "var(--glyph-spacing-md, 1.25rem)"
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function connectorStyle(status) {
|
|
546
|
+
return {
|
|
547
|
+
position: "absolute",
|
|
548
|
+
left: `calc(${INDICATOR_SIZE} / 2 - ${CONNECTOR_WIDTH} / 2)`,
|
|
549
|
+
top: INDICATOR_SIZE,
|
|
550
|
+
bottom: 0,
|
|
551
|
+
width: CONNECTOR_WIDTH,
|
|
552
|
+
backgroundColor: status === "completed" ? "var(--glyph-steps-completed-color, #22c55e)" : "var(--glyph-steps-connector-color, #d0d8e4)"
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function indicatorStyle(status) {
|
|
556
|
+
const color3 = colorForStatus(status);
|
|
557
|
+
return {
|
|
558
|
+
flexShrink: 0,
|
|
559
|
+
width: INDICATOR_SIZE,
|
|
560
|
+
height: INDICATOR_SIZE,
|
|
561
|
+
borderRadius: "50%",
|
|
562
|
+
display: "flex",
|
|
563
|
+
alignItems: "center",
|
|
564
|
+
justifyContent: "center",
|
|
565
|
+
fontSize: "0.85rem",
|
|
566
|
+
fontWeight: 700,
|
|
567
|
+
lineHeight: 1,
|
|
568
|
+
color: status === "completed" ? "#fff" : color3,
|
|
569
|
+
backgroundColor: status === "completed" ? color3 : "transparent",
|
|
570
|
+
border: status === "completed" ? "none" : `${CONNECTOR_WIDTH} solid ${color3}`,
|
|
571
|
+
boxSizing: "border-box"
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
var bodyStyle = {
|
|
575
|
+
flex: 1,
|
|
576
|
+
minWidth: 0,
|
|
577
|
+
paddingTop: "0.1rem"
|
|
578
|
+
};
|
|
579
|
+
function titleStyle(status) {
|
|
580
|
+
return {
|
|
581
|
+
fontWeight: 600,
|
|
582
|
+
color: status === "pending" ? "var(--glyph-steps-pending-color, #7a8599)" : "var(--glyph-text, #1a2035)"
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function contentStyle(status) {
|
|
586
|
+
return {
|
|
587
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
588
|
+
fontSize: "0.9em",
|
|
589
|
+
color: status === "pending" ? "var(--glyph-steps-pending-color, #7a8599)" : "var(--glyph-text-muted, #7a8599)"
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/steps/index.ts
|
|
594
|
+
var stepsDefinition = {
|
|
595
|
+
type: "ui:steps",
|
|
596
|
+
schema: schemas.stepsSchema,
|
|
597
|
+
render: Steps
|
|
598
|
+
};
|
|
599
|
+
function nextDirection(current) {
|
|
600
|
+
if (current === "none") return "ascending";
|
|
601
|
+
if (current === "ascending") return "descending";
|
|
602
|
+
return "none";
|
|
603
|
+
}
|
|
604
|
+
function computeAggregation(rows, column, fn) {
|
|
605
|
+
if (fn === "count") {
|
|
606
|
+
return String(rows.length);
|
|
607
|
+
}
|
|
608
|
+
const values = rows.map((r) => r[column]).filter((v) => typeof v === "number" && !Number.isNaN(v));
|
|
609
|
+
if (values.length === 0) return "";
|
|
610
|
+
switch (fn) {
|
|
611
|
+
case "sum":
|
|
612
|
+
return String(values.reduce((a, b) => a + b, 0));
|
|
613
|
+
case "avg":
|
|
614
|
+
return String(values.reduce((a, b) => a + b, 0) / values.length);
|
|
615
|
+
case "min":
|
|
616
|
+
return String(Math.min(...values));
|
|
617
|
+
case "max":
|
|
618
|
+
return String(Math.max(...values));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function sortIndicator(direction) {
|
|
622
|
+
if (direction === "ascending") return " \u25B2";
|
|
623
|
+
if (direction === "descending") return " \u25BC";
|
|
624
|
+
return "";
|
|
625
|
+
}
|
|
626
|
+
function TableAggregationFooter({
|
|
627
|
+
columns,
|
|
628
|
+
aggMap,
|
|
629
|
+
rows
|
|
630
|
+
}) {
|
|
631
|
+
return /* @__PURE__ */ jsxRuntime.jsx("tfoot", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => {
|
|
632
|
+
const agg = aggMap.get(col.key);
|
|
633
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
634
|
+
"td",
|
|
635
|
+
{
|
|
636
|
+
style: {
|
|
637
|
+
padding: "var(--glyph-table-cell-padding, 8px 12px)",
|
|
638
|
+
borderTop: "2px solid var(--glyph-table-border, #d0d8e4)",
|
|
639
|
+
fontWeight: "bold",
|
|
640
|
+
background: "var(--glyph-table-footer-bg, #e8ecf3)",
|
|
641
|
+
color: "var(--glyph-table-footer-color, inherit)"
|
|
642
|
+
},
|
|
643
|
+
children: agg ? computeAggregation(rows, col.key, agg.fn) : ""
|
|
644
|
+
},
|
|
645
|
+
col.key
|
|
646
|
+
);
|
|
647
|
+
}) }) });
|
|
648
|
+
}
|
|
649
|
+
function Table({ data, container }) {
|
|
650
|
+
const { columns, rows, aggregation } = data;
|
|
651
|
+
const [sort, setSort] = react.useState({ column: "", direction: "none" });
|
|
652
|
+
const [filters, setFilters] = react.useState({});
|
|
653
|
+
const filteredRows = react.useMemo(() => {
|
|
654
|
+
return rows.filter((row) => {
|
|
655
|
+
return columns.every((col) => {
|
|
656
|
+
if (!col.filterable) return true;
|
|
657
|
+
const filterValue = filters[col.key];
|
|
658
|
+
if (!filterValue) return true;
|
|
659
|
+
const cellValue = String(row[col.key] ?? "").toLowerCase();
|
|
660
|
+
return cellValue.includes(filterValue.toLowerCase());
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}, [rows, columns, filters]);
|
|
664
|
+
const sortedRows = react.useMemo(() => {
|
|
665
|
+
if (sort.direction === "none" || !sort.column) return filteredRows;
|
|
666
|
+
return [...filteredRows].sort((a, b) => {
|
|
667
|
+
const aVal = a[sort.column];
|
|
668
|
+
const bVal = b[sort.column];
|
|
669
|
+
if (aVal == null && bVal == null) return 0;
|
|
670
|
+
if (aVal == null) return 1;
|
|
671
|
+
if (bVal == null) return -1;
|
|
672
|
+
let cmp = 0;
|
|
673
|
+
if (typeof aVal === "number" && typeof bVal === "number") {
|
|
674
|
+
cmp = aVal - bVal;
|
|
675
|
+
} else {
|
|
676
|
+
cmp = String(aVal).localeCompare(String(bVal));
|
|
677
|
+
}
|
|
678
|
+
return sort.direction === "ascending" ? cmp : -cmp;
|
|
679
|
+
});
|
|
680
|
+
}, [filteredRows, sort]);
|
|
681
|
+
const handleSort = (columnKey) => {
|
|
682
|
+
setSort((prev) => {
|
|
683
|
+
if (prev.column === columnKey) {
|
|
684
|
+
return { column: columnKey, direction: nextDirection(prev.direction) };
|
|
685
|
+
}
|
|
686
|
+
return { column: columnKey, direction: "ascending" };
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
const handleHeaderKeyDown = (e, columnKey) => {
|
|
690
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
691
|
+
e.preventDefault();
|
|
692
|
+
handleSort(columnKey);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
const handleFilterChange = (columnKey, value) => {
|
|
696
|
+
setFilters((prev) => ({ ...prev, [columnKey]: value }));
|
|
697
|
+
};
|
|
698
|
+
const hasFilters = columns.some((c) => c.filterable);
|
|
699
|
+
const aggMap = react.useMemo(() => {
|
|
700
|
+
if (!aggregation) return null;
|
|
701
|
+
const map = /* @__PURE__ */ new Map();
|
|
702
|
+
for (const agg of aggregation) {
|
|
703
|
+
map.set(agg.column, { fn: agg.function });
|
|
704
|
+
}
|
|
705
|
+
return map;
|
|
706
|
+
}, [aggregation]);
|
|
707
|
+
const isCompact = container.tier === "compact";
|
|
708
|
+
const tableEl = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
709
|
+
"table",
|
|
710
|
+
{
|
|
711
|
+
role: "grid",
|
|
712
|
+
style: {
|
|
713
|
+
width: "100%",
|
|
714
|
+
borderCollapse: "collapse",
|
|
715
|
+
border: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
716
|
+
fontFamily: "var(--glyph-font-body, inherit)",
|
|
717
|
+
fontSize: isCompact ? "0.8125rem" : "var(--glyph-table-font-size, 0.9rem)"
|
|
718
|
+
},
|
|
719
|
+
children: [
|
|
720
|
+
/* @__PURE__ */ jsxRuntime.jsxs("thead", { children: [
|
|
721
|
+
/* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => {
|
|
722
|
+
const isSorted = sort.column === col.key;
|
|
723
|
+
const direction = isSorted ? sort.direction : "none";
|
|
724
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
725
|
+
"th",
|
|
726
|
+
{
|
|
727
|
+
scope: "col",
|
|
728
|
+
"aria-sort": col.sortable ? direction : void 0,
|
|
729
|
+
tabIndex: col.sortable ? 0 : void 0,
|
|
730
|
+
role: col.sortable ? "columnheader" : void 0,
|
|
731
|
+
onClick: col.sortable ? () => handleSort(col.key) : void 0,
|
|
732
|
+
onKeyDown: col.sortable ? (e) => handleHeaderKeyDown(e, col.key) : void 0,
|
|
733
|
+
style: {
|
|
734
|
+
padding: "var(--glyph-table-cell-padding, 8px 12px)",
|
|
735
|
+
textAlign: "left",
|
|
736
|
+
borderBottom: "2px solid var(--glyph-table-border, #d0d8e4)",
|
|
737
|
+
background: "var(--glyph-table-header-bg, #e8ecf3)",
|
|
738
|
+
color: "var(--glyph-table-header-color, inherit)",
|
|
739
|
+
cursor: col.sortable ? "pointer" : "default",
|
|
740
|
+
userSelect: col.sortable ? "none" : void 0,
|
|
741
|
+
whiteSpace: "nowrap"
|
|
742
|
+
},
|
|
743
|
+
children: [
|
|
744
|
+
col.label,
|
|
745
|
+
col.sortable ? sortIndicator(direction) : ""
|
|
746
|
+
]
|
|
747
|
+
},
|
|
748
|
+
col.key
|
|
749
|
+
);
|
|
750
|
+
}) }),
|
|
751
|
+
hasFilters && /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
752
|
+
"th",
|
|
753
|
+
{
|
|
754
|
+
scope: "col",
|
|
755
|
+
style: { padding: "4px 8px", fontWeight: "normal" },
|
|
756
|
+
children: col.filterable ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
757
|
+
"input",
|
|
758
|
+
{
|
|
759
|
+
type: "text",
|
|
760
|
+
"aria-label": `Filter ${col.label}`,
|
|
761
|
+
placeholder: `Filter ${col.label}...`,
|
|
762
|
+
value: filters[col.key] ?? "",
|
|
763
|
+
onChange: (e) => handleFilterChange(col.key, e.target.value),
|
|
764
|
+
style: {
|
|
765
|
+
width: "100%",
|
|
766
|
+
padding: "4px 6px",
|
|
767
|
+
border: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
768
|
+
borderRadius: "3px",
|
|
769
|
+
fontSize: "inherit",
|
|
770
|
+
boxSizing: "border-box",
|
|
771
|
+
background: "var(--glyph-surface, #e8ecf3)",
|
|
772
|
+
color: "var(--glyph-text, inherit)"
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
776
|
+
"span",
|
|
777
|
+
{
|
|
778
|
+
style: {
|
|
779
|
+
position: "absolute",
|
|
780
|
+
width: "1px",
|
|
781
|
+
height: "1px",
|
|
782
|
+
overflow: "hidden",
|
|
783
|
+
clip: "rect(0,0,0,0)",
|
|
784
|
+
whiteSpace: "nowrap"
|
|
785
|
+
},
|
|
786
|
+
children: `No filter for ${col.label}`
|
|
787
|
+
}
|
|
788
|
+
)
|
|
789
|
+
},
|
|
790
|
+
`filter-${col.key}`
|
|
791
|
+
)) })
|
|
792
|
+
] }),
|
|
793
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: sortedRows.map((row, rowIdx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
794
|
+
"tr",
|
|
795
|
+
{
|
|
796
|
+
style: {
|
|
797
|
+
background: rowIdx % 2 === 0 ? "var(--glyph-table-row-bg, transparent)" : "var(--glyph-table-row-alt-bg, #f4f6fa)"
|
|
798
|
+
},
|
|
799
|
+
children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
800
|
+
"td",
|
|
801
|
+
{
|
|
802
|
+
style: {
|
|
803
|
+
padding: "var(--glyph-table-cell-padding, 8px 12px)",
|
|
804
|
+
borderBottom: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
805
|
+
color: "var(--glyph-table-cell-color, inherit)"
|
|
806
|
+
},
|
|
807
|
+
children: String(row[col.key] ?? "")
|
|
808
|
+
},
|
|
809
|
+
col.key
|
|
810
|
+
))
|
|
811
|
+
},
|
|
812
|
+
rowIdx
|
|
813
|
+
)) }),
|
|
814
|
+
aggMap && aggMap.size > 0 && /* @__PURE__ */ jsxRuntime.jsx(TableAggregationFooter, { columns, aggMap, rows: sortedRows })
|
|
815
|
+
]
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
if (isCompact) {
|
|
819
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflowX: "auto" }, children: tableEl });
|
|
820
|
+
}
|
|
821
|
+
return tableEl;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/table/index.ts
|
|
825
|
+
var tableDefinition = {
|
|
826
|
+
type: "ui:table",
|
|
827
|
+
schema: schemas.tableSchema,
|
|
828
|
+
render: Table
|
|
829
|
+
};
|
|
830
|
+
function Tabs({ data, block }) {
|
|
831
|
+
const [activeIndex, setActiveIndex] = react.useState(0);
|
|
832
|
+
const tabRefs = react.useRef([]);
|
|
833
|
+
const tabs = data.tabs;
|
|
834
|
+
const baseId = `glyph-tabs-${block.id}`;
|
|
835
|
+
const focusTab = react.useCallback(
|
|
836
|
+
(index) => {
|
|
837
|
+
const clampedIndex = Math.max(0, Math.min(index, tabs.length - 1));
|
|
838
|
+
setActiveIndex(clampedIndex);
|
|
839
|
+
tabRefs.current[clampedIndex]?.focus();
|
|
840
|
+
},
|
|
841
|
+
[tabs.length]
|
|
842
|
+
);
|
|
843
|
+
const handleKeyDown = react.useCallback(
|
|
844
|
+
(e) => {
|
|
845
|
+
switch (e.key) {
|
|
846
|
+
case "ArrowRight": {
|
|
847
|
+
e.preventDefault();
|
|
848
|
+
const next = (activeIndex + 1) % tabs.length;
|
|
849
|
+
focusTab(next);
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
case "ArrowLeft": {
|
|
853
|
+
e.preventDefault();
|
|
854
|
+
const prev = (activeIndex - 1 + tabs.length) % tabs.length;
|
|
855
|
+
focusTab(prev);
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
case "Home": {
|
|
859
|
+
e.preventDefault();
|
|
860
|
+
focusTab(0);
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
case "End": {
|
|
864
|
+
e.preventDefault();
|
|
865
|
+
focusTab(tabs.length - 1);
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
[activeIndex, focusTab, tabs.length]
|
|
871
|
+
);
|
|
872
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
873
|
+
"div",
|
|
874
|
+
{
|
|
875
|
+
style: {
|
|
876
|
+
fontFamily: 'var(--glyph-font-body, "Inter", system-ui, sans-serif)',
|
|
877
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
878
|
+
borderRadius: "var(--glyph-radius-lg, 0.25rem)",
|
|
879
|
+
overflow: "hidden"
|
|
880
|
+
},
|
|
881
|
+
children: [
|
|
882
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
883
|
+
"div",
|
|
884
|
+
{
|
|
885
|
+
role: "tablist",
|
|
886
|
+
"aria-label": "Tabs",
|
|
887
|
+
style: {
|
|
888
|
+
display: "flex",
|
|
889
|
+
borderBottom: "1px solid var(--glyph-border, #d0d8e4)",
|
|
890
|
+
backgroundColor: "var(--glyph-surface, #e8ecf3)",
|
|
891
|
+
margin: 0,
|
|
892
|
+
padding: 0
|
|
893
|
+
},
|
|
894
|
+
children: tabs.map((tab, index) => {
|
|
895
|
+
const isActive = index === activeIndex;
|
|
896
|
+
const tabId = `${baseId}-tab-${String(index)}`;
|
|
897
|
+
const panelId = `${baseId}-panel-${String(index)}`;
|
|
898
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
899
|
+
"button",
|
|
900
|
+
{
|
|
901
|
+
id: tabId,
|
|
902
|
+
ref: (el) => {
|
|
903
|
+
tabRefs.current[index] = el;
|
|
904
|
+
},
|
|
905
|
+
role: "tab",
|
|
906
|
+
"aria-selected": isActive,
|
|
907
|
+
"aria-controls": panelId,
|
|
908
|
+
tabIndex: isActive ? 0 : -1,
|
|
909
|
+
onClick: () => setActiveIndex(index),
|
|
910
|
+
onKeyDown: handleKeyDown,
|
|
911
|
+
style: {
|
|
912
|
+
padding: "10px 18px",
|
|
913
|
+
border: "none",
|
|
914
|
+
borderBottom: isActive ? "2px solid var(--glyph-accent, #00d4aa)" : "2px solid transparent",
|
|
915
|
+
background: isActive ? "var(--glyph-surface-raised, #f4f6fa)" : "transparent",
|
|
916
|
+
color: isActive ? "var(--glyph-heading, #0a0e1a)" : "var(--glyph-text-muted, #7a8599)",
|
|
917
|
+
cursor: "pointer",
|
|
918
|
+
fontFamily: "inherit",
|
|
919
|
+
fontSize: "0.9rem",
|
|
920
|
+
fontWeight: isActive ? 600 : 400,
|
|
921
|
+
transition: "color 0.15s, border-color 0.15s, background 0.15s",
|
|
922
|
+
outline: "revert",
|
|
923
|
+
outlineOffset: "2px"
|
|
924
|
+
},
|
|
925
|
+
children: tab.label
|
|
926
|
+
},
|
|
927
|
+
tabId
|
|
928
|
+
);
|
|
929
|
+
})
|
|
930
|
+
}
|
|
931
|
+
),
|
|
932
|
+
tabs.map((tab, index) => {
|
|
933
|
+
const isActive = index === activeIndex;
|
|
934
|
+
const tabId = `${baseId}-tab-${String(index)}`;
|
|
935
|
+
const panelId = `${baseId}-panel-${String(index)}`;
|
|
936
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
937
|
+
"div",
|
|
938
|
+
{
|
|
939
|
+
id: panelId,
|
|
940
|
+
role: "tabpanel",
|
|
941
|
+
"aria-labelledby": tabId,
|
|
942
|
+
"aria-live": "polite",
|
|
943
|
+
hidden: !isActive,
|
|
944
|
+
tabIndex: 0,
|
|
945
|
+
style: {
|
|
946
|
+
padding: "16px",
|
|
947
|
+
backgroundColor: "var(--glyph-surface-raised, #f4f6fa)",
|
|
948
|
+
color: "var(--glyph-heading, #0a0e1a)",
|
|
949
|
+
lineHeight: 1.6
|
|
950
|
+
},
|
|
951
|
+
children: tab.content
|
|
952
|
+
},
|
|
953
|
+
panelId
|
|
954
|
+
);
|
|
955
|
+
})
|
|
956
|
+
]
|
|
957
|
+
}
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/tabs/index.ts
|
|
962
|
+
var tabsDefinition = {
|
|
963
|
+
type: "ui:tabs",
|
|
964
|
+
schema: schemas.tabsSchema,
|
|
965
|
+
render: Tabs
|
|
966
|
+
};
|
|
967
|
+
var MARKER_RADIUS = 8;
|
|
968
|
+
var LINE_THICKNESS = 2;
|
|
969
|
+
var EVENT_SPACING_MIN = 80;
|
|
970
|
+
var TYPE_PALETTE = [
|
|
971
|
+
"var(--glyph-timeline-color-1, #00d4aa)",
|
|
972
|
+
"var(--glyph-timeline-color-2, #b44dff)",
|
|
973
|
+
"var(--glyph-timeline-color-3, #22c55e)",
|
|
974
|
+
"var(--glyph-timeline-color-4, #e040fb)",
|
|
975
|
+
"var(--glyph-timeline-color-5, #00e5ff)",
|
|
976
|
+
"var(--glyph-timeline-color-6, #84cc16)",
|
|
977
|
+
"var(--glyph-timeline-color-7, #f472b6)",
|
|
978
|
+
"var(--glyph-timeline-color-8, #fb923c)"
|
|
979
|
+
];
|
|
980
|
+
function parseDate(raw) {
|
|
981
|
+
const d = new Date(raw);
|
|
982
|
+
if (!isNaN(d.getTime())) return d;
|
|
983
|
+
const ym = raw.match(/^(\d{4})-(\d{1,2})$/);
|
|
984
|
+
if (ym && ym[1] && ym[2]) return new Date(+ym[1], +ym[2] - 1, 1);
|
|
985
|
+
const q1 = raw.match(/^Q([1-4])\s+(\d{4})$/i);
|
|
986
|
+
if (q1 && q1[1] && q1[2]) return new Date(+q1[2], (+q1[1] - 1) * 3, 1);
|
|
987
|
+
const q2 = raw.match(/^(\d{4})-Q([1-4])$/i);
|
|
988
|
+
if (q2 && q2[1] && q2[2]) return new Date(+q2[1], (+q2[2] - 1) * 3, 1);
|
|
989
|
+
return /* @__PURE__ */ new Date(0);
|
|
990
|
+
}
|
|
991
|
+
function formatDate(raw) {
|
|
992
|
+
const d = parseDate(raw);
|
|
993
|
+
if (d.getTime() === 0) return raw;
|
|
994
|
+
return d.toLocaleDateString(void 0, {
|
|
995
|
+
year: "numeric",
|
|
996
|
+
month: "short",
|
|
997
|
+
day: "numeric"
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
function isoDate(raw) {
|
|
1001
|
+
return parseDate(raw).toISOString().slice(0, 10);
|
|
1002
|
+
}
|
|
1003
|
+
function Timeline({ data }) {
|
|
1004
|
+
const { events, orientation = "vertical" } = data;
|
|
1005
|
+
const containerRef = react.useRef(null);
|
|
1006
|
+
const isVertical = orientation === "vertical";
|
|
1007
|
+
const sorted = [...events].map((e) => ({ ...e, _parsed: parseDate(e.date) })).sort((a, b) => a._parsed.getTime() - b._parsed.getTime());
|
|
1008
|
+
const dates = sorted.map((e) => e._parsed);
|
|
1009
|
+
const minDate = dates[0] ?? /* @__PURE__ */ new Date();
|
|
1010
|
+
const maxDate = dates[dates.length - 1] ?? /* @__PURE__ */ new Date();
|
|
1011
|
+
const totalLength = Math.max(sorted.length * EVENT_SPACING_MIN, 400);
|
|
1012
|
+
const timeScale = d32.scaleTime().domain([minDate, maxDate]).range([MARKER_RADIUS + 20, totalLength - MARKER_RADIUS - 20]);
|
|
1013
|
+
const typeValues = [...new Set(events.map((e) => e.type ?? "_default"))];
|
|
1014
|
+
const colorScale = d32.scaleOrdinal().domain(typeValues).range(TYPE_PALETTE);
|
|
1015
|
+
const positioned = sorted.map((e, i) => ({
|
|
1016
|
+
event: e,
|
|
1017
|
+
parsed: e._parsed,
|
|
1018
|
+
position: dates.length === 1 ? totalLength / 2 : timeScale(e._parsed),
|
|
1019
|
+
side: isVertical ? i % 2 === 0 ? "left" : "right" : i % 2 === 0 ? "top" : "bottom"
|
|
1020
|
+
}));
|
|
1021
|
+
const containerStyle3 = {
|
|
1022
|
+
position: "relative",
|
|
1023
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
1024
|
+
color: "var(--glyph-text, #1a2035)",
|
|
1025
|
+
...isVertical ? { width: "100%", minHeight: totalLength } : { minHeight: 300, minWidth: totalLength }
|
|
1026
|
+
};
|
|
1027
|
+
const lineStyle = isVertical ? {
|
|
1028
|
+
position: "absolute",
|
|
1029
|
+
left: "50%",
|
|
1030
|
+
top: 0,
|
|
1031
|
+
bottom: 0,
|
|
1032
|
+
width: LINE_THICKNESS,
|
|
1033
|
+
backgroundColor: "var(--glyph-timeline-line, #d0d8e4)",
|
|
1034
|
+
transform: "translateX(-50%)"
|
|
1035
|
+
} : {
|
|
1036
|
+
position: "absolute",
|
|
1037
|
+
top: "50%",
|
|
1038
|
+
left: 0,
|
|
1039
|
+
right: 0,
|
|
1040
|
+
height: LINE_THICKNESS,
|
|
1041
|
+
backgroundColor: "var(--glyph-timeline-line, #d0d8e4)",
|
|
1042
|
+
transform: "translateY(-50%)"
|
|
1043
|
+
};
|
|
1044
|
+
const inner = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1045
|
+
"div",
|
|
1046
|
+
{
|
|
1047
|
+
ref: containerRef,
|
|
1048
|
+
style: containerStyle3,
|
|
1049
|
+
role: "img",
|
|
1050
|
+
"aria-label": `Timeline with ${events.length} events`,
|
|
1051
|
+
children: [
|
|
1052
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: lineStyle, "aria-hidden": "true" }),
|
|
1053
|
+
positioned.map((pe, idx) => {
|
|
1054
|
+
const color3 = colorScale(pe.event.type ?? "_default");
|
|
1055
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: eventContainerStyle(pe, isVertical), "aria-hidden": "true", children: [
|
|
1056
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: connectorStyle2(pe, isVertical), "aria-hidden": "true" }),
|
|
1057
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1058
|
+
"div",
|
|
1059
|
+
{
|
|
1060
|
+
style: {
|
|
1061
|
+
width: MARKER_RADIUS * 2,
|
|
1062
|
+
height: MARKER_RADIUS * 2,
|
|
1063
|
+
borderRadius: "50%",
|
|
1064
|
+
backgroundColor: color3,
|
|
1065
|
+
border: "2px solid var(--glyph-timeline-marker-border, var(--glyph-bg, #f4f6fa))",
|
|
1066
|
+
boxShadow: "0 0 0 2px var(--glyph-border, #d0d8e4)",
|
|
1067
|
+
flexShrink: 0,
|
|
1068
|
+
zIndex: 1
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
),
|
|
1072
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: labelStyle(pe, isVertical), children: [
|
|
1073
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1074
|
+
"div",
|
|
1075
|
+
{
|
|
1076
|
+
style: {
|
|
1077
|
+
fontSize: "var(--glyph-timeline-date-size, 0.75rem)",
|
|
1078
|
+
color: "var(--glyph-timeline-date-color, #7a8599)",
|
|
1079
|
+
fontWeight: 600
|
|
1080
|
+
},
|
|
1081
|
+
children: formatDate(pe.event.date)
|
|
1082
|
+
}
|
|
1083
|
+
),
|
|
1084
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1085
|
+
"div",
|
|
1086
|
+
{
|
|
1087
|
+
style: {
|
|
1088
|
+
fontSize: "var(--glyph-timeline-title-size, 0.9rem)",
|
|
1089
|
+
fontWeight: 700,
|
|
1090
|
+
marginTop: 2
|
|
1091
|
+
},
|
|
1092
|
+
children: pe.event.title
|
|
1093
|
+
}
|
|
1094
|
+
),
|
|
1095
|
+
pe.event.description && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1096
|
+
"div",
|
|
1097
|
+
{
|
|
1098
|
+
style: {
|
|
1099
|
+
fontSize: "var(--glyph-timeline-desc-size, 0.8rem)",
|
|
1100
|
+
color: "var(--glyph-timeline-desc-color, #7a8599)",
|
|
1101
|
+
marginTop: 2
|
|
1102
|
+
},
|
|
1103
|
+
children: pe.event.description
|
|
1104
|
+
}
|
|
1105
|
+
)
|
|
1106
|
+
] })
|
|
1107
|
+
] }, idx);
|
|
1108
|
+
}),
|
|
1109
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1110
|
+
"ol",
|
|
1111
|
+
{
|
|
1112
|
+
style: {
|
|
1113
|
+
position: "absolute",
|
|
1114
|
+
width: 1,
|
|
1115
|
+
height: 1,
|
|
1116
|
+
overflow: "hidden",
|
|
1117
|
+
clip: "rect(0 0 0 0)",
|
|
1118
|
+
clipPath: "inset(50%)",
|
|
1119
|
+
whiteSpace: "nowrap"
|
|
1120
|
+
},
|
|
1121
|
+
children: sorted.map((e, idx) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
1122
|
+
/* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: isoDate(e.date), children: formatDate(e.date) }),
|
|
1123
|
+
" \u2014 ",
|
|
1124
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: e.title }),
|
|
1125
|
+
e.description ? `: ${e.description}` : ""
|
|
1126
|
+
] }, idx))
|
|
1127
|
+
}
|
|
1128
|
+
)
|
|
1129
|
+
]
|
|
1130
|
+
}
|
|
1131
|
+
);
|
|
1132
|
+
if (!isVertical) {
|
|
1133
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflowX: "auto", width: "100%" }, children: inner });
|
|
1134
|
+
}
|
|
1135
|
+
return inner;
|
|
1136
|
+
}
|
|
1137
|
+
function eventContainerStyle(pe, isVertical) {
|
|
1138
|
+
if (isVertical) {
|
|
1139
|
+
const isLeft = pe.side === "left";
|
|
1140
|
+
return {
|
|
1141
|
+
position: "absolute",
|
|
1142
|
+
top: pe.position,
|
|
1143
|
+
left: isLeft ? 0 : "50%",
|
|
1144
|
+
right: isLeft ? "50%" : 0,
|
|
1145
|
+
display: "flex",
|
|
1146
|
+
flexDirection: isLeft ? "row-reverse" : "row",
|
|
1147
|
+
alignItems: "center",
|
|
1148
|
+
gap: 8,
|
|
1149
|
+
transform: "translateY(-50%)"
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
const isTop = pe.side === "top";
|
|
1153
|
+
return {
|
|
1154
|
+
position: "absolute",
|
|
1155
|
+
left: pe.position,
|
|
1156
|
+
top: isTop ? 0 : "50%",
|
|
1157
|
+
bottom: isTop ? "50%" : 0,
|
|
1158
|
+
display: "flex",
|
|
1159
|
+
flexDirection: isTop ? "column-reverse" : "column",
|
|
1160
|
+
alignItems: "center",
|
|
1161
|
+
gap: 8,
|
|
1162
|
+
transform: "translateX(-50%)"
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
function connectorStyle2(_pe, isVertical) {
|
|
1166
|
+
if (isVertical) {
|
|
1167
|
+
return {
|
|
1168
|
+
flex: "0 0 20px",
|
|
1169
|
+
height: LINE_THICKNESS,
|
|
1170
|
+
backgroundColor: "var(--glyph-timeline-line, #d0d8e4)"
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
return {
|
|
1174
|
+
flex: "0 0 20px",
|
|
1175
|
+
width: LINE_THICKNESS,
|
|
1176
|
+
backgroundColor: "var(--glyph-timeline-line, #d0d8e4)"
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
function labelStyle(pe, isVertical) {
|
|
1180
|
+
if (isVertical) {
|
|
1181
|
+
return {
|
|
1182
|
+
textAlign: pe.side === "left" ? "right" : "left",
|
|
1183
|
+
maxWidth: 200
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
return {
|
|
1187
|
+
textAlign: "center",
|
|
1188
|
+
maxWidth: 160
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// src/timeline/index.ts
|
|
1193
|
+
var timelineDefinition = {
|
|
1194
|
+
type: "ui:timeline",
|
|
1195
|
+
schema: schemas.timelineSchema,
|
|
1196
|
+
render: Timeline
|
|
1197
|
+
};
|
|
1198
|
+
var RANKDIR_MAP = {
|
|
1199
|
+
"top-down": "TB",
|
|
1200
|
+
"left-right": "LR",
|
|
1201
|
+
"bottom-up": "BT",
|
|
1202
|
+
radial: "TB"
|
|
1203
|
+
};
|
|
1204
|
+
var DEFAULT_NODE_WIDTH = 160;
|
|
1205
|
+
var DEFAULT_NODE_HEIGHT = 40;
|
|
1206
|
+
var NODE_SEP = 50;
|
|
1207
|
+
var RANK_SEP = 70;
|
|
1208
|
+
var EDGE_SEP = 10;
|
|
1209
|
+
var LAYOUT_PADDING = 40;
|
|
1210
|
+
function computeDagreLayout(nodes, edges, direction = "top-down") {
|
|
1211
|
+
const g = new dagre__default.default.graphlib.Graph();
|
|
1212
|
+
g.setGraph({
|
|
1213
|
+
rankdir: RANKDIR_MAP[direction] ?? "TB",
|
|
1214
|
+
nodesep: NODE_SEP,
|
|
1215
|
+
ranksep: RANK_SEP,
|
|
1216
|
+
edgesep: EDGE_SEP
|
|
1217
|
+
});
|
|
1218
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
1219
|
+
for (const node of nodes) {
|
|
1220
|
+
g.setNode(node.id, {
|
|
1221
|
+
label: node.label,
|
|
1222
|
+
width: DEFAULT_NODE_WIDTH,
|
|
1223
|
+
height: DEFAULT_NODE_HEIGHT
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
for (const edge of edges) {
|
|
1227
|
+
g.setEdge(edge.from, edge.to);
|
|
1228
|
+
}
|
|
1229
|
+
dagre__default.default.layout(g);
|
|
1230
|
+
const positionedNodes = nodes.map((node) => {
|
|
1231
|
+
const dagreNode = g.node(node.id);
|
|
1232
|
+
return {
|
|
1233
|
+
...node,
|
|
1234
|
+
x: dagreNode.x,
|
|
1235
|
+
y: dagreNode.y,
|
|
1236
|
+
width: dagreNode.width,
|
|
1237
|
+
height: dagreNode.height
|
|
1238
|
+
};
|
|
1239
|
+
});
|
|
1240
|
+
const positionedEdges = edges.map((edge) => {
|
|
1241
|
+
const dagreEdge = g.edge(edge.from, edge.to);
|
|
1242
|
+
return {
|
|
1243
|
+
...edge,
|
|
1244
|
+
points: dagreEdge.points
|
|
1245
|
+
};
|
|
1246
|
+
});
|
|
1247
|
+
let maxX = 0;
|
|
1248
|
+
let maxY = 0;
|
|
1249
|
+
for (const n of positionedNodes) {
|
|
1250
|
+
const right = n.x + n.width / 2;
|
|
1251
|
+
const bottom = n.y + n.height / 2;
|
|
1252
|
+
if (right > maxX) maxX = right;
|
|
1253
|
+
if (bottom > maxY) maxY = bottom;
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
nodes: positionedNodes,
|
|
1257
|
+
edges: positionedEdges,
|
|
1258
|
+
width: maxX + LAYOUT_PADDING,
|
|
1259
|
+
height: maxY + LAYOUT_PADDING
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
function computeForceLayout(nodes, edges) {
|
|
1263
|
+
const simNodes = nodes.map((n) => ({
|
|
1264
|
+
...n,
|
|
1265
|
+
x: void 0,
|
|
1266
|
+
y: void 0
|
|
1267
|
+
}));
|
|
1268
|
+
const simLinks = edges.map((e) => ({
|
|
1269
|
+
source: e.from,
|
|
1270
|
+
target: e.to
|
|
1271
|
+
}));
|
|
1272
|
+
const simulation = d32__namespace.forceSimulation(simNodes).force(
|
|
1273
|
+
"link",
|
|
1274
|
+
d32__namespace.forceLink(simLinks).id((d) => d.id).distance(120)
|
|
1275
|
+
).force("charge", d32__namespace.forceManyBody().strength(-300)).force("center", d32__namespace.forceCenter(400, 300)).force("collision", d32__namespace.forceCollide().radius(DEFAULT_NODE_WIDTH / 2 + 10)).stop();
|
|
1276
|
+
const tickCount = 300;
|
|
1277
|
+
for (let i = 0; i < tickCount; i++) {
|
|
1278
|
+
simulation.tick();
|
|
1279
|
+
}
|
|
1280
|
+
let minX = Infinity;
|
|
1281
|
+
let minY = Infinity;
|
|
1282
|
+
for (const sn of simNodes) {
|
|
1283
|
+
if ((sn.x ?? 0) < minX) minX = sn.x ?? 0;
|
|
1284
|
+
if ((sn.y ?? 0) < minY) minY = sn.y ?? 0;
|
|
1285
|
+
}
|
|
1286
|
+
const offsetX = -minX + LAYOUT_PADDING + DEFAULT_NODE_WIDTH / 2;
|
|
1287
|
+
const offsetY = -minY + LAYOUT_PADDING + DEFAULT_NODE_HEIGHT / 2;
|
|
1288
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
1289
|
+
const positionedNodes = simNodes.map((sn) => {
|
|
1290
|
+
const pn = {
|
|
1291
|
+
id: sn.id,
|
|
1292
|
+
label: sn.label,
|
|
1293
|
+
type: sn.type,
|
|
1294
|
+
style: sn.style,
|
|
1295
|
+
group: sn.group,
|
|
1296
|
+
x: (sn.x ?? 0) + offsetX,
|
|
1297
|
+
y: (sn.y ?? 0) + offsetY,
|
|
1298
|
+
width: DEFAULT_NODE_WIDTH,
|
|
1299
|
+
height: DEFAULT_NODE_HEIGHT
|
|
1300
|
+
};
|
|
1301
|
+
nodeMap.set(sn.id, pn);
|
|
1302
|
+
return pn;
|
|
1303
|
+
});
|
|
1304
|
+
const positionedEdges = edges.map((edge) => {
|
|
1305
|
+
const source = nodeMap.get(edge.from);
|
|
1306
|
+
const target = nodeMap.get(edge.to);
|
|
1307
|
+
return {
|
|
1308
|
+
...edge,
|
|
1309
|
+
points: [
|
|
1310
|
+
{ x: source?.x ?? 0, y: source?.y ?? 0 },
|
|
1311
|
+
{ x: target?.x ?? 0, y: target?.y ?? 0 }
|
|
1312
|
+
]
|
|
1313
|
+
};
|
|
1314
|
+
});
|
|
1315
|
+
let maxX = 0;
|
|
1316
|
+
let maxY = 0;
|
|
1317
|
+
for (const n of positionedNodes) {
|
|
1318
|
+
const right = n.x + n.width / 2;
|
|
1319
|
+
const bottom = n.y + n.height / 2;
|
|
1320
|
+
if (right > maxX) maxX = right;
|
|
1321
|
+
if (bottom > maxY) maxY = bottom;
|
|
1322
|
+
}
|
|
1323
|
+
return {
|
|
1324
|
+
nodes: positionedNodes,
|
|
1325
|
+
edges: positionedEdges,
|
|
1326
|
+
width: maxX + LAYOUT_PADDING,
|
|
1327
|
+
height: maxY + LAYOUT_PADDING
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
var GROUP_PALETTE = [
|
|
1331
|
+
"#00d4aa",
|
|
1332
|
+
// cyan-green
|
|
1333
|
+
"#b44dff",
|
|
1334
|
+
// purple
|
|
1335
|
+
"#22c55e",
|
|
1336
|
+
// green
|
|
1337
|
+
"#e040fb",
|
|
1338
|
+
// magenta
|
|
1339
|
+
"#00e5ff",
|
|
1340
|
+
// teal
|
|
1341
|
+
"#84cc16",
|
|
1342
|
+
// lime
|
|
1343
|
+
"#f472b6",
|
|
1344
|
+
// rose
|
|
1345
|
+
"#fb923c",
|
|
1346
|
+
// orange
|
|
1347
|
+
"#818cf8",
|
|
1348
|
+
// indigo
|
|
1349
|
+
"#38bdf8"
|
|
1350
|
+
// sky
|
|
1351
|
+
];
|
|
1352
|
+
var DEFAULT_NODE_COLOR = "#00d4aa";
|
|
1353
|
+
function getGroupColor(group, groupIndex) {
|
|
1354
|
+
if (!group) return GROUP_PALETTE[0];
|
|
1355
|
+
let idx = groupIndex.get(group);
|
|
1356
|
+
if (idx === void 0) {
|
|
1357
|
+
idx = groupIndex.size;
|
|
1358
|
+
groupIndex.set(group, idx);
|
|
1359
|
+
}
|
|
1360
|
+
return GROUP_PALETTE[idx % GROUP_PALETTE.length] ?? DEFAULT_NODE_COLOR;
|
|
1361
|
+
}
|
|
1362
|
+
var TYPE_LAYOUT_DEFAULTS = {
|
|
1363
|
+
dag: "top-down",
|
|
1364
|
+
flowchart: "top-down",
|
|
1365
|
+
mindmap: "left-right",
|
|
1366
|
+
force: "force"
|
|
1367
|
+
};
|
|
1368
|
+
function resolveLayout(data) {
|
|
1369
|
+
if (data.layout) return data.layout;
|
|
1370
|
+
return TYPE_LAYOUT_DEFAULTS[data.type] ?? "top-down";
|
|
1371
|
+
}
|
|
1372
|
+
function getThemeVar(container, varName, fallback) {
|
|
1373
|
+
return getComputedStyle(container).getPropertyValue(varName).trim() || fallback;
|
|
1374
|
+
}
|
|
1375
|
+
var ARROW_MARKER_ID = "glyph-graph-arrowhead";
|
|
1376
|
+
function renderGraph(svgElement, layout, groupIndex, outgoingRefs, onNavigate) {
|
|
1377
|
+
const svg = d32__namespace.select(svgElement);
|
|
1378
|
+
svg.selectAll("*").remove();
|
|
1379
|
+
const width = Math.max(layout.width, 200);
|
|
1380
|
+
const height = Math.max(layout.height, 200);
|
|
1381
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
1382
|
+
const defs = svg.append("defs");
|
|
1383
|
+
defs.append("marker").attr("id", ARROW_MARKER_ID).attr("viewBox", "0 0 10 10").attr("refX", 10).attr("refY", 5).attr("markerWidth", 8).attr("markerHeight", 8).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 Z").attr("fill", "var(--glyph-edge-color, #6b7a94)");
|
|
1384
|
+
const container = svgElement.parentElement ?? svgElement;
|
|
1385
|
+
const nodeRadius = getThemeVar(container, "--glyph-node-radius", "3");
|
|
1386
|
+
const nodeStrokeWidth = getThemeVar(container, "--glyph-node-stroke-width", "1.5");
|
|
1387
|
+
const nodeFillOpacity = getThemeVar(container, "--glyph-node-fill-opacity", "0.85");
|
|
1388
|
+
const root = svg.append("g").attr("class", "glyph-graph-root");
|
|
1389
|
+
const zoomBehavior = d32__namespace.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
|
|
1390
|
+
root.attr("transform", event.transform.toString());
|
|
1391
|
+
});
|
|
1392
|
+
svg.call(zoomBehavior);
|
|
1393
|
+
const navigableNodes = /* @__PURE__ */ new Set();
|
|
1394
|
+
const refByAnchor = /* @__PURE__ */ new Map();
|
|
1395
|
+
for (const ref of outgoingRefs) {
|
|
1396
|
+
if (ref.sourceAnchor) {
|
|
1397
|
+
navigableNodes.add(ref.sourceAnchor);
|
|
1398
|
+
refByAnchor.set(ref.sourceAnchor, ref);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const lineGen = d32__namespace.line().x((d) => d.x).y((d) => d.y).curve(d32__namespace.curveBasis);
|
|
1402
|
+
const edgeGroup = root.append("g").attr("class", "glyph-graph-edges");
|
|
1403
|
+
for (const edge of layout.edges) {
|
|
1404
|
+
const edgeG = edgeGroup.append("g").attr("class", "glyph-graph-edge");
|
|
1405
|
+
edgeG.append("path").attr("d", lineGen(edge.points) ?? "").attr("fill", "none").attr("stroke", edge.style?.["stroke"] ?? "var(--glyph-edge-color, #6b7a94)").attr("stroke-width", edge.style?.["stroke-width"] ?? nodeStrokeWidth).attr("marker-end", `url(#${ARROW_MARKER_ID})`).attr("stroke-dasharray", edge.type === "dashed" ? "5,5" : null);
|
|
1406
|
+
if (edge.label) {
|
|
1407
|
+
const mid = edge.points[Math.floor(edge.points.length / 2)];
|
|
1408
|
+
if (mid) {
|
|
1409
|
+
edgeG.append("text").attr("x", mid.x).attr("y", mid.y - 8).attr("text-anchor", "middle").attr("font-size", "11px").attr("fill", "var(--glyph-edge-color, #6b7a94)").text(edge.label);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
const nodeGroup = root.append("g").attr("class", "glyph-graph-nodes");
|
|
1414
|
+
for (const node of layout.nodes) {
|
|
1415
|
+
const nodeG = nodeGroup.append("g").attr("class", "glyph-graph-node");
|
|
1416
|
+
const color3 = getGroupColor(node.group, groupIndex);
|
|
1417
|
+
const isNavigable = navigableNodes.has(node.id);
|
|
1418
|
+
const nodeX = node.x - node.width / 2;
|
|
1419
|
+
const nodeY = node.y - node.height / 2;
|
|
1420
|
+
const defaultStroke = d32__namespace.color(color3)?.darker(0.5)?.toString() ?? "var(--glyph-edge-color, #6b7a94)";
|
|
1421
|
+
if (node.type === "circle") {
|
|
1422
|
+
nodeG.append("circle").attr("cx", node.x).attr("cy", node.y).attr("r", Math.min(node.width, node.height) / 2).attr("fill", node.style?.["fill"] ?? color3).attr("stroke", node.style?.["stroke"] ?? defaultStroke).attr("stroke-width", node.style?.["stroke-width"] ?? nodeStrokeWidth).attr("opacity", nodeFillOpacity);
|
|
1423
|
+
} else {
|
|
1424
|
+
nodeG.append("rect").attr("x", nodeX).attr("y", nodeY).attr("width", node.width).attr("height", node.height).attr("rx", nodeRadius).attr("ry", nodeRadius).attr("fill", node.style?.["fill"] ?? color3).attr("stroke", node.style?.["stroke"] ?? defaultStroke).attr("stroke-width", node.style?.["stroke-width"] ?? nodeStrokeWidth).attr("opacity", nodeFillOpacity);
|
|
1425
|
+
}
|
|
1426
|
+
nodeG.append("text").attr("x", node.x).attr("y", node.y).attr("dy", "0.35em").attr("text-anchor", "middle").attr("font-size", "13px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-node-label-color, #fff)").attr("pointer-events", "none").text(node.label);
|
|
1427
|
+
if (isNavigable) {
|
|
1428
|
+
nodeG.attr("cursor", "pointer");
|
|
1429
|
+
nodeG.on("click", () => {
|
|
1430
|
+
const ref = refByAnchor.get(node.id);
|
|
1431
|
+
if (ref) onNavigate(ref);
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
function Graph({
|
|
1437
|
+
data,
|
|
1438
|
+
outgoingRefs,
|
|
1439
|
+
onNavigate,
|
|
1440
|
+
container
|
|
1441
|
+
}) {
|
|
1442
|
+
const svgRef = react.useRef(null);
|
|
1443
|
+
const groupIndex = react.useRef(/* @__PURE__ */ new Map());
|
|
1444
|
+
const layoutResult = react.useMemo(() => {
|
|
1445
|
+
const direction = resolveLayout(data);
|
|
1446
|
+
if (direction === "force") {
|
|
1447
|
+
return computeForceLayout(data.nodes, data.edges);
|
|
1448
|
+
}
|
|
1449
|
+
return computeDagreLayout(data.nodes, data.edges, direction);
|
|
1450
|
+
}, [data]);
|
|
1451
|
+
react.useEffect(() => {
|
|
1452
|
+
if (!svgRef.current) return;
|
|
1453
|
+
renderGraph(svgRef.current, layoutResult, groupIndex.current, outgoingRefs, onNavigate);
|
|
1454
|
+
}, [layoutResult, outgoingRefs, onNavigate]);
|
|
1455
|
+
const ariaLabel = `${data.type} graph with ${data.nodes.length} nodes and ${data.edges.length} edges`;
|
|
1456
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-graph-container", children: [
|
|
1457
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1458
|
+
"svg",
|
|
1459
|
+
{
|
|
1460
|
+
ref: svgRef,
|
|
1461
|
+
role: "img",
|
|
1462
|
+
"aria-label": ariaLabel,
|
|
1463
|
+
width: "100%",
|
|
1464
|
+
height: "100%",
|
|
1465
|
+
style: {
|
|
1466
|
+
minHeight: container.tier === "compact" ? 200 : 300,
|
|
1467
|
+
maxHeight: container.tier === "compact" ? 500 : 700,
|
|
1468
|
+
display: "block"
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
),
|
|
1472
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Graph data", style: SR_ONLY_STYLE, children: [
|
|
1473
|
+
/* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Graph nodes and connections" }),
|
|
1474
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
1475
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Node" }),
|
|
1476
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Group" }),
|
|
1477
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Connections" })
|
|
1478
|
+
] }) }),
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.nodes.map((node) => {
|
|
1480
|
+
const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
|
|
1481
|
+
const target = e.from === node.id ? e.to : e.from;
|
|
1482
|
+
const dir = e.from === node.id ? "->" : "<-";
|
|
1483
|
+
return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
|
|
1484
|
+
}).join(", ");
|
|
1485
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
1486
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.label }),
|
|
1487
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.group ?? "" }),
|
|
1488
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: connections })
|
|
1489
|
+
] }, node.id);
|
|
1490
|
+
}) })
|
|
1491
|
+
] })
|
|
1492
|
+
] });
|
|
1493
|
+
}
|
|
1494
|
+
var SR_ONLY_STYLE = {
|
|
1495
|
+
position: "absolute",
|
|
1496
|
+
width: "1px",
|
|
1497
|
+
height: "1px",
|
|
1498
|
+
padding: 0,
|
|
1499
|
+
margin: "-1px",
|
|
1500
|
+
overflow: "hidden",
|
|
1501
|
+
clip: "rect(0, 0, 0, 0)",
|
|
1502
|
+
whiteSpace: "nowrap",
|
|
1503
|
+
border: 0
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
// src/graph/index.ts
|
|
1507
|
+
var graphDefinition = {
|
|
1508
|
+
type: "ui:graph",
|
|
1509
|
+
schema: schemas.graphSchema,
|
|
1510
|
+
render: Graph
|
|
1511
|
+
};
|
|
1512
|
+
var ENTITY_MIN_WIDTH = 180;
|
|
1513
|
+
var ENTITY_HEADER_HEIGHT = 32;
|
|
1514
|
+
var ENTITY_ATTR_HEIGHT = 22;
|
|
1515
|
+
var ENTITY_PADDING = 12;
|
|
1516
|
+
var NODE_SEP2 = 60;
|
|
1517
|
+
var RANK_SEP2 = 80;
|
|
1518
|
+
var EDGE_SEP2 = 10;
|
|
1519
|
+
var LAYOUT_PADDING2 = 40;
|
|
1520
|
+
var CHAR_WIDTH = 7.5;
|
|
1521
|
+
function computeEntitySize(entity) {
|
|
1522
|
+
const attrs = entity.attributes ?? [];
|
|
1523
|
+
const height = ENTITY_HEADER_HEIGHT + attrs.length * ENTITY_ATTR_HEIGHT + ENTITY_PADDING;
|
|
1524
|
+
let maxTextWidth = entity.label.length * (CHAR_WIDTH + 1);
|
|
1525
|
+
for (const attr of attrs) {
|
|
1526
|
+
const attrText = `${attr.name}: ${attr.type}`;
|
|
1527
|
+
maxTextWidth = Math.max(maxTextWidth, attrText.length * CHAR_WIDTH);
|
|
1528
|
+
}
|
|
1529
|
+
const width = Math.max(ENTITY_MIN_WIDTH, maxTextWidth + ENTITY_PADDING * 2 + 16);
|
|
1530
|
+
return { width, height };
|
|
1531
|
+
}
|
|
1532
|
+
function computeRelationLayout(data) {
|
|
1533
|
+
const direction = data.layout ?? "top-down";
|
|
1534
|
+
const rankdir = direction === "left-right" ? "LR" : "TB";
|
|
1535
|
+
const g = new dagre__default.default.graphlib.Graph();
|
|
1536
|
+
g.setGraph({
|
|
1537
|
+
rankdir,
|
|
1538
|
+
nodesep: NODE_SEP2,
|
|
1539
|
+
ranksep: RANK_SEP2,
|
|
1540
|
+
edgesep: EDGE_SEP2
|
|
1541
|
+
});
|
|
1542
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
1543
|
+
const sizeMap = /* @__PURE__ */ new Map();
|
|
1544
|
+
for (const entity of data.entities) {
|
|
1545
|
+
const size = computeEntitySize(entity);
|
|
1546
|
+
sizeMap.set(entity.id, size);
|
|
1547
|
+
g.setNode(entity.id, {
|
|
1548
|
+
label: entity.label,
|
|
1549
|
+
width: size.width,
|
|
1550
|
+
height: size.height
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
for (const rel of data.relationships) {
|
|
1554
|
+
g.setEdge(rel.from, rel.to);
|
|
1555
|
+
}
|
|
1556
|
+
dagre__default.default.layout(g);
|
|
1557
|
+
const positionedEntities = data.entities.map((entity) => {
|
|
1558
|
+
const dagreNode = g.node(entity.id);
|
|
1559
|
+
const size = sizeMap.get(entity.id) ?? {
|
|
1560
|
+
width: ENTITY_MIN_WIDTH,
|
|
1561
|
+
height: ENTITY_HEADER_HEIGHT
|
|
1562
|
+
};
|
|
1563
|
+
return {
|
|
1564
|
+
...entity,
|
|
1565
|
+
x: dagreNode.x,
|
|
1566
|
+
y: dagreNode.y,
|
|
1567
|
+
width: size.width,
|
|
1568
|
+
height: size.height
|
|
1569
|
+
};
|
|
1570
|
+
});
|
|
1571
|
+
const positionedRelationships = data.relationships.map((rel) => {
|
|
1572
|
+
const dagreEdge = g.edge(rel.from, rel.to);
|
|
1573
|
+
return {
|
|
1574
|
+
...rel,
|
|
1575
|
+
points: dagreEdge.points
|
|
1576
|
+
};
|
|
1577
|
+
});
|
|
1578
|
+
let maxX = 0;
|
|
1579
|
+
let maxY = 0;
|
|
1580
|
+
for (const e of positionedEntities) {
|
|
1581
|
+
const right = e.x + e.width / 2;
|
|
1582
|
+
const bottom = e.y + e.height / 2;
|
|
1583
|
+
if (right > maxX) maxX = right;
|
|
1584
|
+
if (bottom > maxY) maxY = bottom;
|
|
1585
|
+
}
|
|
1586
|
+
return {
|
|
1587
|
+
entities: positionedEntities,
|
|
1588
|
+
relationships: positionedRelationships,
|
|
1589
|
+
width: maxX + LAYOUT_PADDING2,
|
|
1590
|
+
height: maxY + LAYOUT_PADDING2
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
function parseCardinality(cardinality) {
|
|
1594
|
+
const parts = cardinality.split(":");
|
|
1595
|
+
return { fromSymbol: parts[0] ?? "1", toSymbol: parts[1] ?? "1" };
|
|
1596
|
+
}
|
|
1597
|
+
function drawCrowsFoot(g, x, y, angle, symbol) {
|
|
1598
|
+
const len = 12;
|
|
1599
|
+
const spread = Math.PI / 6;
|
|
1600
|
+
if (symbol === "N" || symbol === "M") {
|
|
1601
|
+
const cx = x + Math.cos(angle) * len;
|
|
1602
|
+
const cy = y + Math.sin(angle) * len;
|
|
1603
|
+
g.append("line").attr("x1", x).attr("y1", y).attr("x2", cx).attr("y2", cy).attr("stroke", "var(--glyph-relation-line, #6b7a94)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1604
|
+
const lx = x + Math.cos(angle + spread) * len;
|
|
1605
|
+
const ly = y + Math.sin(angle + spread) * len;
|
|
1606
|
+
g.append("line").attr("x1", x).attr("y1", y).attr("x2", lx).attr("y2", ly).attr("stroke", "var(--glyph-relation-line, #6b7a94)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1607
|
+
const rx = x + Math.cos(angle - spread) * len;
|
|
1608
|
+
const ry = y + Math.sin(angle - spread) * len;
|
|
1609
|
+
g.append("line").attr("x1", x).attr("y1", y).attr("x2", rx).attr("y2", ry).attr("stroke", "var(--glyph-relation-line, #6b7a94)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1610
|
+
} else {
|
|
1611
|
+
const perpAngle = angle + Math.PI / 2;
|
|
1612
|
+
const halfLen = 8;
|
|
1613
|
+
const tx = x + Math.cos(angle) * 6;
|
|
1614
|
+
const ty = y + Math.sin(angle) * 6;
|
|
1615
|
+
g.append("line").attr("x1", tx - Math.cos(perpAngle) * halfLen).attr("y1", ty - Math.sin(perpAngle) * halfLen).attr("x2", tx + Math.cos(perpAngle) * halfLen).attr("y2", ty + Math.sin(perpAngle) * halfLen).attr("stroke", "var(--glyph-relation-line, #6b7a94)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function renderRelation(svgElement, layout) {
|
|
1619
|
+
const svg = d32__namespace.select(svgElement);
|
|
1620
|
+
svg.selectAll("*").remove();
|
|
1621
|
+
const width = Math.max(layout.width, 200);
|
|
1622
|
+
const height = Math.max(layout.height, 200);
|
|
1623
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
1624
|
+
const root = svg.append("g").attr("class", "glyph-relation-root");
|
|
1625
|
+
const zoomBehavior = d32__namespace.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
|
|
1626
|
+
root.attr("transform", event.transform.toString());
|
|
1627
|
+
});
|
|
1628
|
+
svg.call(zoomBehavior);
|
|
1629
|
+
const entityMap = /* @__PURE__ */ new Map();
|
|
1630
|
+
for (const entity of layout.entities) {
|
|
1631
|
+
entityMap.set(entity.id, entity);
|
|
1632
|
+
}
|
|
1633
|
+
const lineGen = d32__namespace.line().x((d) => d.x).y((d) => d.y).curve(d32__namespace.curveBasis);
|
|
1634
|
+
const edgeGroup = root.append("g").attr("class", "glyph-relation-edges");
|
|
1635
|
+
for (const rel of layout.relationships) {
|
|
1636
|
+
const edgeG = edgeGroup.append("g").attr("class", "glyph-relation-edge");
|
|
1637
|
+
edgeG.append("path").attr("d", lineGen(rel.points) ?? "").attr("fill", "none").attr("stroke", "var(--glyph-relation-line, #6b7a94)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1638
|
+
const { fromSymbol, toSymbol } = parseCardinality(rel.cardinality);
|
|
1639
|
+
const p0 = rel.points[0];
|
|
1640
|
+
const p1 = rel.points[1];
|
|
1641
|
+
if (p0 && p1) {
|
|
1642
|
+
const angleFrom = Math.atan2(p1.y - p0.y, p1.x - p0.x);
|
|
1643
|
+
drawCrowsFoot(edgeG, p0.x, p0.y, angleFrom, fromSymbol);
|
|
1644
|
+
}
|
|
1645
|
+
const pLast = rel.points[rel.points.length - 1];
|
|
1646
|
+
const pPrev = rel.points[rel.points.length - 2];
|
|
1647
|
+
if (pLast && pPrev) {
|
|
1648
|
+
const angleTo = Math.atan2(pPrev.y - pLast.y, pPrev.x - pLast.x);
|
|
1649
|
+
drawCrowsFoot(edgeG, pLast.x, pLast.y, angleTo, toSymbol);
|
|
1650
|
+
}
|
|
1651
|
+
if (rel.label) {
|
|
1652
|
+
const mid = rel.points[Math.floor(rel.points.length / 2)];
|
|
1653
|
+
if (mid) {
|
|
1654
|
+
edgeG.append("text").attr("x", mid.x).attr("y", mid.y - 10).attr("text-anchor", "middle").attr("font-size", "11px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-relation-label, #6b7a94)").text(rel.label);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
const pFirst = rel.points[0];
|
|
1658
|
+
const pSecond = rel.points[1];
|
|
1659
|
+
if (pFirst && pSecond) {
|
|
1660
|
+
const fromLabelX = pFirst.x + (pSecond.x - pFirst.x) * 0.15;
|
|
1661
|
+
const fromLabelY = pFirst.y + (pSecond.y - pFirst.y) * 0.15 - 10;
|
|
1662
|
+
edgeG.append("text").attr("x", fromLabelX).attr("y", fromLabelY).attr("text-anchor", "middle").attr("font-size", "10px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-relation-cardinality, #6b7a94)").text(fromSymbol);
|
|
1663
|
+
}
|
|
1664
|
+
const pEnd = rel.points[rel.points.length - 1];
|
|
1665
|
+
const pBeforeEnd = rel.points[rel.points.length - 2];
|
|
1666
|
+
if (pEnd && pBeforeEnd) {
|
|
1667
|
+
const toLabelX = pEnd.x + (pBeforeEnd.x - pEnd.x) * 0.15;
|
|
1668
|
+
const toLabelY = pEnd.y + (pBeforeEnd.y - pEnd.y) * 0.15 - 10;
|
|
1669
|
+
edgeG.append("text").attr("x", toLabelX).attr("y", toLabelY).attr("text-anchor", "middle").attr("font-size", "10px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-relation-cardinality, #6b7a94)").text(toSymbol);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
const entityGroup = root.append("g").attr("class", "glyph-relation-entities");
|
|
1673
|
+
for (const entity of layout.entities) {
|
|
1674
|
+
const entityG = entityGroup.append("g").attr("class", "glyph-relation-entity");
|
|
1675
|
+
const x = entity.x - entity.width / 2;
|
|
1676
|
+
const y = entity.y - entity.height / 2;
|
|
1677
|
+
const attrs = entity.attributes ?? [];
|
|
1678
|
+
entityG.append("rect").attr("x", x).attr("y", y).attr("width", entity.width).attr("height", entity.height).attr("rx", 4).attr("ry", 4).attr("fill", "var(--glyph-relation-entity-bg, #f4f6fa)").attr("stroke", "var(--glyph-relation-entity-border, #a8b5c8)").attr("stroke-width", "var(--glyph-node-stroke-width, 1.5)");
|
|
1679
|
+
const headerHeight = ENTITY_HEADER_HEIGHT;
|
|
1680
|
+
entityG.append("rect").attr("x", x).attr("y", y).attr("width", entity.width).attr("height", headerHeight).attr("rx", 4).attr("ry", 4).attr("fill", "var(--glyph-relation-header-bg, #00d4aa)");
|
|
1681
|
+
entityG.append("rect").attr("x", x).attr("y", y + headerHeight - 4).attr("width", entity.width).attr("height", 4).attr("fill", "var(--glyph-relation-header-bg, #00d4aa)");
|
|
1682
|
+
entityG.append("text").attr("x", entity.x).attr("y", y + headerHeight / 2).attr("dy", "0.35em").attr("text-anchor", "middle").attr("font-size", "13px").attr("font-weight", "bold").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-relation-header-text, #fff)").text(entity.label);
|
|
1683
|
+
if (attrs.length > 0) {
|
|
1684
|
+
entityG.append("line").attr("x1", x).attr("y1", y + headerHeight).attr("x2", x + entity.width).attr("y2", y + headerHeight).attr("stroke", "var(--glyph-relation-entity-border, #a8b5c8)").attr("stroke-width", 1);
|
|
1685
|
+
}
|
|
1686
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
1687
|
+
const attr = attrs[i];
|
|
1688
|
+
if (!attr) continue;
|
|
1689
|
+
const attrY = y + headerHeight + i * ENTITY_ATTR_HEIGHT + ENTITY_ATTR_HEIGHT / 2 + 4;
|
|
1690
|
+
const textEl = entityG.append("text").attr("x", x + ENTITY_PADDING).attr("y", attrY).attr("dy", "0.35em").attr("font-size", "12px").attr("font-family", "system-ui, -apple-system, monospace").attr("fill", "var(--glyph-relation-attr-text, #1a2035)");
|
|
1691
|
+
const nameSpan = textEl.append("tspan").text(attr.name);
|
|
1692
|
+
if (attr.primaryKey) {
|
|
1693
|
+
nameSpan.attr("font-weight", "bold").attr("text-decoration", "underline");
|
|
1694
|
+
}
|
|
1695
|
+
textEl.append("tspan").attr("fill", "var(--glyph-relation-attr-type, #6b7a94)").text(`: ${attr.type}`);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
function Relation({ data }) {
|
|
1700
|
+
const svgRef = react.useRef(null);
|
|
1701
|
+
const layoutResult = react.useMemo(() => {
|
|
1702
|
+
return computeRelationLayout(data);
|
|
1703
|
+
}, [data]);
|
|
1704
|
+
react.useEffect(() => {
|
|
1705
|
+
if (!svgRef.current) return;
|
|
1706
|
+
renderRelation(svgRef.current, layoutResult);
|
|
1707
|
+
}, [layoutResult]);
|
|
1708
|
+
const ariaLabel = `Entity-relationship diagram with ${data.entities.length} entities and ${data.relationships.length} relationships`;
|
|
1709
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-relation-container", children: [
|
|
1710
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1711
|
+
"svg",
|
|
1712
|
+
{
|
|
1713
|
+
ref: svgRef,
|
|
1714
|
+
role: "img",
|
|
1715
|
+
"aria-label": ariaLabel,
|
|
1716
|
+
width: "100%",
|
|
1717
|
+
height: "100%",
|
|
1718
|
+
style: { minHeight: 300, maxHeight: 700, display: "block" }
|
|
1719
|
+
}
|
|
1720
|
+
),
|
|
1721
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Entity-relationship data", style: SR_ONLY_STYLE2, children: [
|
|
1722
|
+
/* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Entities and relationships" }),
|
|
1723
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
1724
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Entity" }),
|
|
1725
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Attributes" }),
|
|
1726
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Relationships" })
|
|
1727
|
+
] }) }),
|
|
1728
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.entities.map((entity) => {
|
|
1729
|
+
const attrs = (entity.attributes ?? []).map((a) => `${a.name}: ${a.type}${a.primaryKey ? " (PK)" : ""}`).join(", ");
|
|
1730
|
+
const rels = data.relationships.filter((r) => r.from === entity.id || r.to === entity.id).map((r) => {
|
|
1731
|
+
const target = r.from === entity.id ? r.to : r.from;
|
|
1732
|
+
const dir = r.from === entity.id ? "->" : "<-";
|
|
1733
|
+
return `${dir} ${target} [${r.cardinality}]${r.label ? ` (${r.label})` : ""}`;
|
|
1734
|
+
}).join(", ");
|
|
1735
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
1736
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: entity.label }),
|
|
1737
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: attrs }),
|
|
1738
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: rels })
|
|
1739
|
+
] }, entity.id);
|
|
1740
|
+
}) })
|
|
1741
|
+
] })
|
|
1742
|
+
] });
|
|
1743
|
+
}
|
|
1744
|
+
var SR_ONLY_STYLE2 = {
|
|
1745
|
+
position: "absolute",
|
|
1746
|
+
width: "1px",
|
|
1747
|
+
height: "1px",
|
|
1748
|
+
padding: 0,
|
|
1749
|
+
margin: "-1px",
|
|
1750
|
+
overflow: "hidden",
|
|
1751
|
+
clip: "rect(0, 0, 0, 0)",
|
|
1752
|
+
whiteSpace: "nowrap",
|
|
1753
|
+
border: 0
|
|
1754
|
+
};
|
|
1755
|
+
|
|
1756
|
+
// src/relation/index.ts
|
|
1757
|
+
var relationDefinition = {
|
|
1758
|
+
type: "ui:relation",
|
|
1759
|
+
schema: schemas.relationSchema,
|
|
1760
|
+
render: Relation
|
|
1761
|
+
};
|
|
1762
|
+
var TREND_SYMBOLS = {
|
|
1763
|
+
up: "\u25B2",
|
|
1764
|
+
down: "\u25BC",
|
|
1765
|
+
flat: "\u2014"
|
|
1766
|
+
};
|
|
1767
|
+
function resolveSentiment(metric) {
|
|
1768
|
+
if (metric.sentiment) return metric.sentiment;
|
|
1769
|
+
if (metric.trend === "up") return "positive";
|
|
1770
|
+
if (metric.trend === "down") return "negative";
|
|
1771
|
+
return "neutral";
|
|
1772
|
+
}
|
|
1773
|
+
function buildAriaLabel(metric) {
|
|
1774
|
+
let label = `${metric.label}: ${metric.value}`;
|
|
1775
|
+
if (metric.unit) label += ` ${metric.unit}`;
|
|
1776
|
+
if (metric.delta && metric.trend) {
|
|
1777
|
+
label += `, ${metric.trend} ${metric.delta}`;
|
|
1778
|
+
} else if (metric.delta) {
|
|
1779
|
+
label += `, ${metric.delta}`;
|
|
1780
|
+
}
|
|
1781
|
+
return label;
|
|
1782
|
+
}
|
|
1783
|
+
function Kpi({ data, block, container }) {
|
|
1784
|
+
const { title, metrics, columns } = data;
|
|
1785
|
+
const baseId = `glyph-kpi-${block.id}`;
|
|
1786
|
+
const authorCols = columns ?? Math.min(metrics.length, 4);
|
|
1787
|
+
let colCount;
|
|
1788
|
+
switch (container.tier) {
|
|
1789
|
+
case "compact":
|
|
1790
|
+
colCount = Math.min(metrics.length, 2);
|
|
1791
|
+
break;
|
|
1792
|
+
case "standard":
|
|
1793
|
+
colCount = Math.min(authorCols, 3);
|
|
1794
|
+
break;
|
|
1795
|
+
default:
|
|
1796
|
+
colCount = authorCols;
|
|
1797
|
+
}
|
|
1798
|
+
const containerStyle3 = {
|
|
1799
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
1800
|
+
color: "var(--glyph-text, #1a2035)"
|
|
1801
|
+
};
|
|
1802
|
+
const gapCount = colCount - 1;
|
|
1803
|
+
const gridStyle = {
|
|
1804
|
+
display: "grid",
|
|
1805
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(max(120px, calc((100% - ${String(gapCount)}rem) / ${String(colCount)})), 1fr))`,
|
|
1806
|
+
gap: "var(--glyph-spacing-md, 1rem)"
|
|
1807
|
+
};
|
|
1808
|
+
const cardStyle = {
|
|
1809
|
+
background: "var(--glyph-surface-raised, #f4f6fa)",
|
|
1810
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
1811
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
1812
|
+
padding: "var(--glyph-spacing-md, 1rem)"
|
|
1813
|
+
};
|
|
1814
|
+
const labelStyle3 = {
|
|
1815
|
+
fontSize: "0.8125rem",
|
|
1816
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
1817
|
+
marginBottom: "var(--glyph-spacing-xs, 0.25rem)"
|
|
1818
|
+
};
|
|
1819
|
+
const valueStyle = {
|
|
1820
|
+
fontSize: "1.75rem",
|
|
1821
|
+
fontWeight: 700,
|
|
1822
|
+
color: "var(--glyph-heading, #0a0e1a)",
|
|
1823
|
+
lineHeight: 1.2
|
|
1824
|
+
};
|
|
1825
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Key metrics", style: containerStyle3, children: [
|
|
1826
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1827
|
+
"div",
|
|
1828
|
+
{
|
|
1829
|
+
style: {
|
|
1830
|
+
fontWeight: 700,
|
|
1831
|
+
fontSize: "1.125rem",
|
|
1832
|
+
marginBottom: "var(--glyph-spacing-sm, 0.5rem)",
|
|
1833
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
1834
|
+
},
|
|
1835
|
+
children: title
|
|
1836
|
+
}
|
|
1837
|
+
),
|
|
1838
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: gridStyle, children: metrics.map((metric, i) => {
|
|
1839
|
+
const sentiment = resolveSentiment(metric);
|
|
1840
|
+
const deltaStyle = {
|
|
1841
|
+
fontSize: "0.875rem",
|
|
1842
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
1843
|
+
color: `var(--glyph-kpi-${sentiment}, inherit)`
|
|
1844
|
+
};
|
|
1845
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "group", "aria-label": buildAriaLabel(metric), style: cardStyle, children: [
|
|
1846
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: labelStyle3, children: metric.label }),
|
|
1847
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: valueStyle, children: [
|
|
1848
|
+
metric.value,
|
|
1849
|
+
metric.unit && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "0.875rem", fontWeight: 400, marginLeft: "0.25rem" }, children: metric.unit })
|
|
1850
|
+
] }),
|
|
1851
|
+
(metric.delta || metric.trend) && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: deltaStyle, children: [
|
|
1852
|
+
metric.trend && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", style: { marginRight: "0.25rem" }, children: TREND_SYMBOLS[metric.trend] }),
|
|
1853
|
+
metric.delta
|
|
1854
|
+
] })
|
|
1855
|
+
] }, i);
|
|
1856
|
+
}) })
|
|
1857
|
+
] });
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
// src/kpi/index.ts
|
|
1861
|
+
var kpiDefinition = {
|
|
1862
|
+
type: "ui:kpi",
|
|
1863
|
+
schema: schemas.kpiSchema,
|
|
1864
|
+
render: Kpi
|
|
1865
|
+
};
|
|
1866
|
+
function Accordion({ data, block }) {
|
|
1867
|
+
const { title, sections, defaultOpen = [], multiple = true } = data;
|
|
1868
|
+
const baseId = `glyph-accordion-${block.id}`;
|
|
1869
|
+
const containerRef = react.useRef(null);
|
|
1870
|
+
const handleToggle = react.useCallback(
|
|
1871
|
+
(e) => {
|
|
1872
|
+
if (multiple) return;
|
|
1873
|
+
const target = e.currentTarget;
|
|
1874
|
+
if (!target.open || !containerRef.current) return;
|
|
1875
|
+
const allDetails = containerRef.current.querySelectorAll("details");
|
|
1876
|
+
for (const details of allDetails) {
|
|
1877
|
+
if (details !== target && details.open) {
|
|
1878
|
+
details.open = false;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
[multiple]
|
|
1883
|
+
);
|
|
1884
|
+
const containerStyle3 = {
|
|
1885
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
1886
|
+
color: "var(--glyph-text, #1a2035)",
|
|
1887
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
1888
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
1889
|
+
overflow: "hidden"
|
|
1890
|
+
};
|
|
1891
|
+
const sectionStyle = (isLast) => ({
|
|
1892
|
+
borderBottom: isLast ? "none" : "1px solid var(--glyph-border, #d0d8e4)"
|
|
1893
|
+
});
|
|
1894
|
+
const summaryStyle = {
|
|
1895
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
1896
|
+
cursor: "pointer",
|
|
1897
|
+
fontWeight: 600,
|
|
1898
|
+
fontSize: "0.9375rem",
|
|
1899
|
+
background: "var(--glyph-surface, #e8ecf3)",
|
|
1900
|
+
listStyle: "none",
|
|
1901
|
+
display: "flex",
|
|
1902
|
+
alignItems: "center",
|
|
1903
|
+
gap: "0.5rem",
|
|
1904
|
+
userSelect: "none"
|
|
1905
|
+
};
|
|
1906
|
+
const contentStyle2 = {
|
|
1907
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
1908
|
+
fontSize: "0.875rem",
|
|
1909
|
+
lineHeight: 1.6
|
|
1910
|
+
};
|
|
1911
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1912
|
+
"div",
|
|
1913
|
+
{
|
|
1914
|
+
id: baseId,
|
|
1915
|
+
ref: containerRef,
|
|
1916
|
+
role: "region",
|
|
1917
|
+
"aria-label": title ?? "Accordion",
|
|
1918
|
+
style: containerStyle3,
|
|
1919
|
+
children: [
|
|
1920
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1921
|
+
"div",
|
|
1922
|
+
{
|
|
1923
|
+
style: {
|
|
1924
|
+
fontWeight: 700,
|
|
1925
|
+
fontSize: "1.125rem",
|
|
1926
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
1927
|
+
borderBottom: "1px solid var(--glyph-border, #d0d8e4)",
|
|
1928
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
1929
|
+
},
|
|
1930
|
+
children: title
|
|
1931
|
+
}
|
|
1932
|
+
),
|
|
1933
|
+
sections.map((section, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1934
|
+
"details",
|
|
1935
|
+
{
|
|
1936
|
+
open: defaultOpen.includes(i),
|
|
1937
|
+
onToggle: handleToggle,
|
|
1938
|
+
style: sectionStyle(i === sections.length - 1),
|
|
1939
|
+
children: [
|
|
1940
|
+
/* @__PURE__ */ jsxRuntime.jsxs("summary", { style: summaryStyle, children: [
|
|
1941
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", style: { fontSize: "0.75rem", width: "1rem", flexShrink: 0 }, children: "\u25B8" }),
|
|
1942
|
+
section.title
|
|
1943
|
+
] }),
|
|
1944
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: contentStyle2, children: section.content })
|
|
1945
|
+
]
|
|
1946
|
+
},
|
|
1947
|
+
i
|
|
1948
|
+
))
|
|
1949
|
+
]
|
|
1950
|
+
}
|
|
1951
|
+
);
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// src/accordion/index.ts
|
|
1955
|
+
var accordionDefinition = {
|
|
1956
|
+
type: "ui:accordion",
|
|
1957
|
+
schema: schemas.accordionSchema,
|
|
1958
|
+
render: Accordion
|
|
1959
|
+
};
|
|
1960
|
+
var YES_VALUES = /* @__PURE__ */ new Set(["yes", "true", "full"]);
|
|
1961
|
+
var NO_VALUES = /* @__PURE__ */ new Set(["no", "false", "none"]);
|
|
1962
|
+
function classifyValue(value) {
|
|
1963
|
+
const lower = value.toLowerCase().trim();
|
|
1964
|
+
if (YES_VALUES.has(lower)) return "yes";
|
|
1965
|
+
if (NO_VALUES.has(lower)) return "no";
|
|
1966
|
+
if (lower === "partial") return "partial";
|
|
1967
|
+
return "text";
|
|
1968
|
+
}
|
|
1969
|
+
function renderValue(value) {
|
|
1970
|
+
const kind = classifyValue(value);
|
|
1971
|
+
switch (kind) {
|
|
1972
|
+
case "yes":
|
|
1973
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1974
|
+
"span",
|
|
1975
|
+
{
|
|
1976
|
+
"aria-label": "Supported",
|
|
1977
|
+
style: { color: "var(--glyph-comparison-yes, #16a34a)", fontSize: "1.25rem" },
|
|
1978
|
+
children: "\u2713"
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1981
|
+
case "no":
|
|
1982
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1983
|
+
"span",
|
|
1984
|
+
{
|
|
1985
|
+
"aria-label": "Not supported",
|
|
1986
|
+
style: { color: "var(--glyph-comparison-no, #dc2626)", fontSize: "1.25rem" },
|
|
1987
|
+
children: "\u2717"
|
|
1988
|
+
}
|
|
1989
|
+
);
|
|
1990
|
+
case "partial":
|
|
1991
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1992
|
+
"span",
|
|
1993
|
+
{
|
|
1994
|
+
"aria-label": "Partially supported",
|
|
1995
|
+
style: { color: "var(--glyph-comparison-partial, #d97706)", fontSize: "1.25rem" },
|
|
1996
|
+
children: "\u25D0"
|
|
1997
|
+
}
|
|
1998
|
+
);
|
|
1999
|
+
default:
|
|
2000
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { children: value });
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
function Comparison({
|
|
2004
|
+
data,
|
|
2005
|
+
block,
|
|
2006
|
+
container
|
|
2007
|
+
}) {
|
|
2008
|
+
const { title, options, features } = data;
|
|
2009
|
+
const baseId = `glyph-comparison-${block.id}`;
|
|
2010
|
+
const isCompact = container.tier === "compact";
|
|
2011
|
+
const cellPadding = isCompact ? "var(--glyph-spacing-xs, 0.25rem) var(--glyph-spacing-sm, 0.5rem)" : "var(--glyph-spacing-sm, 0.5rem) var(--glyph-spacing-md, 1rem)";
|
|
2012
|
+
const containerStyle3 = {
|
|
2013
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
2014
|
+
color: "var(--glyph-text, #1a2035)"
|
|
2015
|
+
};
|
|
2016
|
+
const tableStyle = {
|
|
2017
|
+
width: "100%",
|
|
2018
|
+
borderCollapse: "collapse",
|
|
2019
|
+
border: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
2020
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
2021
|
+
overflow: "hidden",
|
|
2022
|
+
fontSize: isCompact ? "0.8125rem" : "0.875rem"
|
|
2023
|
+
};
|
|
2024
|
+
const thStyle = {
|
|
2025
|
+
padding: cellPadding,
|
|
2026
|
+
textAlign: "center",
|
|
2027
|
+
fontWeight: 600,
|
|
2028
|
+
background: "var(--glyph-table-header-bg, #e8ecf3)",
|
|
2029
|
+
borderBottom: "2px solid var(--glyph-table-border, #d0d8e4)",
|
|
2030
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
2031
|
+
};
|
|
2032
|
+
const featureThStyle = {
|
|
2033
|
+
...thStyle,
|
|
2034
|
+
textAlign: "left"
|
|
2035
|
+
};
|
|
2036
|
+
const rowThStyle = {
|
|
2037
|
+
padding: cellPadding,
|
|
2038
|
+
textAlign: "left",
|
|
2039
|
+
fontWeight: 600,
|
|
2040
|
+
borderBottom: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
2041
|
+
fontSize: "0.8125rem"
|
|
2042
|
+
};
|
|
2043
|
+
const cellStyle = (rowIndex) => ({
|
|
2044
|
+
padding: cellPadding,
|
|
2045
|
+
textAlign: "center",
|
|
2046
|
+
borderBottom: "1px solid var(--glyph-table-border, #d0d8e4)",
|
|
2047
|
+
background: rowIndex % 2 === 1 ? "var(--glyph-table-row-alt-bg, transparent)" : "transparent"
|
|
2048
|
+
});
|
|
2049
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Comparison", style: containerStyle3, children: [
|
|
2050
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2051
|
+
"div",
|
|
2052
|
+
{
|
|
2053
|
+
style: {
|
|
2054
|
+
fontWeight: 700,
|
|
2055
|
+
fontSize: "1.125rem",
|
|
2056
|
+
marginBottom: "var(--glyph-spacing-sm, 0.5rem)",
|
|
2057
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
2058
|
+
},
|
|
2059
|
+
children: title
|
|
2060
|
+
}
|
|
2061
|
+
),
|
|
2062
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { role: "grid", style: tableStyle, children: [
|
|
2063
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
2064
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: featureThStyle, scope: "col", children: "Feature" }),
|
|
2065
|
+
options.map((option, i) => /* @__PURE__ */ jsxRuntime.jsxs("th", { style: thStyle, scope: "col", children: [
|
|
2066
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: option.name }),
|
|
2067
|
+
option.description && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2068
|
+
"div",
|
|
2069
|
+
{
|
|
2070
|
+
style: {
|
|
2071
|
+
fontWeight: 400,
|
|
2072
|
+
fontSize: "0.75rem",
|
|
2073
|
+
color: "var(--glyph-text-muted, #6b7a94)"
|
|
2074
|
+
},
|
|
2075
|
+
children: option.description
|
|
2076
|
+
}
|
|
2077
|
+
)
|
|
2078
|
+
] }, i))
|
|
2079
|
+
] }) }),
|
|
2080
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: features.map((feature, rowIndex) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
2081
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2082
|
+
"th",
|
|
2083
|
+
{
|
|
2084
|
+
scope: "row",
|
|
2085
|
+
style: {
|
|
2086
|
+
...rowThStyle,
|
|
2087
|
+
background: rowIndex % 2 === 1 ? "var(--glyph-table-row-alt-bg, transparent)" : "transparent"
|
|
2088
|
+
},
|
|
2089
|
+
children: feature.name
|
|
2090
|
+
}
|
|
2091
|
+
),
|
|
2092
|
+
options.map((_, colIndex) => {
|
|
2093
|
+
const value = feature.values[colIndex] ?? "";
|
|
2094
|
+
return /* @__PURE__ */ jsxRuntime.jsx("td", { style: cellStyle(rowIndex), children: value ? renderValue(value) : null }, colIndex);
|
|
2095
|
+
})
|
|
2096
|
+
] }, rowIndex)) })
|
|
2097
|
+
] }) })
|
|
2098
|
+
] });
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
// src/comparison/index.ts
|
|
2102
|
+
var comparisonDefinition = {
|
|
2103
|
+
type: "ui:comparison",
|
|
2104
|
+
schema: schemas.comparisonSchema,
|
|
2105
|
+
render: Comparison
|
|
2106
|
+
};
|
|
2107
|
+
|
|
2108
|
+
// src/codediff/diff.ts
|
|
2109
|
+
function dpGet(dp, i, j) {
|
|
2110
|
+
const row = dp[i];
|
|
2111
|
+
if (!row) return 0;
|
|
2112
|
+
return row[j] ?? 0;
|
|
2113
|
+
}
|
|
2114
|
+
function lineAt(arr, i) {
|
|
2115
|
+
return arr[i] ?? "";
|
|
2116
|
+
}
|
|
2117
|
+
function computeDiff(before, after) {
|
|
2118
|
+
const a = before.split("\n");
|
|
2119
|
+
const b = after.split("\n");
|
|
2120
|
+
const n = a.length;
|
|
2121
|
+
const m = b.length;
|
|
2122
|
+
const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
2123
|
+
for (let i2 = 1; i2 <= n; i2++) {
|
|
2124
|
+
for (let j2 = 1; j2 <= m; j2++) {
|
|
2125
|
+
const row = dp[i2];
|
|
2126
|
+
if (!row) continue;
|
|
2127
|
+
if (lineAt(a, i2 - 1) === lineAt(b, j2 - 1)) {
|
|
2128
|
+
row[j2] = dpGet(dp, i2 - 1, j2 - 1) + 1;
|
|
2129
|
+
} else {
|
|
2130
|
+
row[j2] = Math.max(dpGet(dp, i2 - 1, j2), dpGet(dp, i2, j2 - 1));
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
const edits = [];
|
|
2135
|
+
let i = n;
|
|
2136
|
+
let j = m;
|
|
2137
|
+
while (i > 0 || j > 0) {
|
|
2138
|
+
if (i > 0 && j > 0 && lineAt(a, i - 1) === lineAt(b, j - 1)) {
|
|
2139
|
+
edits.unshift({ kind: "eq", text: lineAt(a, i - 1), oldLineNo: i, newLineNo: j });
|
|
2140
|
+
i--;
|
|
2141
|
+
j--;
|
|
2142
|
+
} else if (j > 0 && (i === 0 || dpGet(dp, i, j - 1) >= dpGet(dp, i - 1, j))) {
|
|
2143
|
+
edits.unshift({ kind: "add", text: lineAt(b, j - 1), newLineNo: j });
|
|
2144
|
+
j--;
|
|
2145
|
+
} else {
|
|
2146
|
+
edits.unshift({ kind: "del", text: lineAt(a, i - 1), oldLineNo: i });
|
|
2147
|
+
i--;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return edits;
|
|
2151
|
+
}
|
|
2152
|
+
function summarizeDiff(lines) {
|
|
2153
|
+
const added = lines.filter((l) => l.kind === "add").length;
|
|
2154
|
+
const removed = lines.filter((l) => l.kind === "del").length;
|
|
2155
|
+
return `Code diff: ${String(added)} line${added !== 1 ? "s" : ""} added, ${String(removed)} line${removed !== 1 ? "s" : ""} removed`;
|
|
2156
|
+
}
|
|
2157
|
+
var GUTTER_MARKERS = {
|
|
2158
|
+
add: "+",
|
|
2159
|
+
del: "-",
|
|
2160
|
+
eq: " "
|
|
2161
|
+
};
|
|
2162
|
+
var ARIA_LABELS = {
|
|
2163
|
+
add: "added",
|
|
2164
|
+
del: "removed",
|
|
2165
|
+
eq: "unchanged"
|
|
2166
|
+
};
|
|
2167
|
+
function CodeDiff({ data, block }) {
|
|
2168
|
+
const { before, after, beforeLabel, afterLabel } = data;
|
|
2169
|
+
const baseId = `glyph-codediff-${block.id}`;
|
|
2170
|
+
const diffLines = react.useMemo(() => computeDiff(before, after), [before, after]);
|
|
2171
|
+
const summary = react.useMemo(() => summarizeDiff(diffLines), [diffLines]);
|
|
2172
|
+
const containerStyle3 = {
|
|
2173
|
+
fontFamily: 'var(--glyph-font-mono, ui-monospace, "Cascadia Code", "Fira Code", monospace)',
|
|
2174
|
+
fontSize: "0.8125rem",
|
|
2175
|
+
lineHeight: 1.5,
|
|
2176
|
+
color: "var(--glyph-text, #1a2035)",
|
|
2177
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
2178
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
2179
|
+
overflow: "hidden"
|
|
2180
|
+
};
|
|
2181
|
+
const labelBarStyle = {
|
|
2182
|
+
display: "flex",
|
|
2183
|
+
gap: "1rem",
|
|
2184
|
+
padding: "var(--glyph-spacing-xs, 0.25rem) var(--glyph-spacing-md, 1rem)",
|
|
2185
|
+
background: "var(--glyph-codediff-gutter-bg, var(--glyph-surface, #e8ecf3))",
|
|
2186
|
+
borderBottom: "1px solid var(--glyph-border, #d0d8e4)",
|
|
2187
|
+
fontSize: "0.75rem",
|
|
2188
|
+
fontWeight: 600,
|
|
2189
|
+
color: "var(--glyph-text-muted, #6b7a94)"
|
|
2190
|
+
};
|
|
2191
|
+
const tableStyle = {
|
|
2192
|
+
width: "100%",
|
|
2193
|
+
borderCollapse: "collapse",
|
|
2194
|
+
tableLayout: "fixed"
|
|
2195
|
+
};
|
|
2196
|
+
const gutterStyle = {
|
|
2197
|
+
width: "1.5rem",
|
|
2198
|
+
textAlign: "center",
|
|
2199
|
+
userSelect: "none",
|
|
2200
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
2201
|
+
background: "var(--glyph-codediff-gutter-bg, var(--glyph-surface, #e8ecf3))",
|
|
2202
|
+
borderRight: "1px solid var(--glyph-border, #d0d8e4)",
|
|
2203
|
+
verticalAlign: "top",
|
|
2204
|
+
padding: "0 0.25rem"
|
|
2205
|
+
};
|
|
2206
|
+
const lineNoStyle = {
|
|
2207
|
+
width: "2.5rem",
|
|
2208
|
+
textAlign: "right",
|
|
2209
|
+
userSelect: "none",
|
|
2210
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
2211
|
+
paddingRight: "0.5rem",
|
|
2212
|
+
verticalAlign: "top"
|
|
2213
|
+
};
|
|
2214
|
+
const codeStyle = {
|
|
2215
|
+
paddingLeft: "0.5rem",
|
|
2216
|
+
whiteSpace: "pre",
|
|
2217
|
+
overflowX: "auto",
|
|
2218
|
+
verticalAlign: "top"
|
|
2219
|
+
};
|
|
2220
|
+
function rowBg(kind) {
|
|
2221
|
+
if (kind === "add") return "var(--glyph-codediff-add-bg, rgba(22, 163, 106, 0.1))";
|
|
2222
|
+
if (kind === "del") return "var(--glyph-codediff-del-bg, rgba(220, 38, 38, 0.1))";
|
|
2223
|
+
return void 0;
|
|
2224
|
+
}
|
|
2225
|
+
function rowColor(kind) {
|
|
2226
|
+
if (kind === "add") return "var(--glyph-codediff-add-color, inherit)";
|
|
2227
|
+
if (kind === "del") return "var(--glyph-codediff-del-color, inherit)";
|
|
2228
|
+
return void 0;
|
|
2229
|
+
}
|
|
2230
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": summary, style: containerStyle3, children: [
|
|
2231
|
+
(beforeLabel || afterLabel) && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: labelBarStyle, children: [
|
|
2232
|
+
beforeLabel && /* @__PURE__ */ jsxRuntime.jsx("span", { children: beforeLabel }),
|
|
2233
|
+
beforeLabel && afterLabel && /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2192" }),
|
|
2234
|
+
afterLabel && /* @__PURE__ */ jsxRuntime.jsx("span", { children: afterLabel })
|
|
2235
|
+
] }),
|
|
2236
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsx("table", { role: "grid", style: tableStyle, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: diffLines.map((line6, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2237
|
+
"tr",
|
|
2238
|
+
{
|
|
2239
|
+
"aria-label": ARIA_LABELS[line6.kind],
|
|
2240
|
+
style: { background: rowBg(line6.kind), color: rowColor(line6.kind) },
|
|
2241
|
+
children: [
|
|
2242
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: gutterStyle, children: GUTTER_MARKERS[line6.kind] }),
|
|
2243
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: lineNoStyle, children: line6.oldLineNo ?? "" }),
|
|
2244
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: lineNoStyle, children: line6.newLineNo ?? "" }),
|
|
2245
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: codeStyle, children: line6.text })
|
|
2246
|
+
]
|
|
2247
|
+
},
|
|
2248
|
+
i
|
|
2249
|
+
)) }) }) })
|
|
2250
|
+
] });
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
// src/codediff/index.ts
|
|
2254
|
+
var codeDiffDefinition = {
|
|
2255
|
+
type: "ui:codediff",
|
|
2256
|
+
schema: schemas.codediffSchema,
|
|
2257
|
+
render: CodeDiff
|
|
2258
|
+
};
|
|
2259
|
+
var NODE_WIDTH = 160;
|
|
2260
|
+
var NODE_HEIGHT = 40;
|
|
2261
|
+
var DECISION_WIDTH = 170;
|
|
2262
|
+
var DECISION_HEIGHT = 70;
|
|
2263
|
+
var NODE_SEP3 = 50;
|
|
2264
|
+
var RANK_SEP3 = 70;
|
|
2265
|
+
var LAYOUT_PADDING3 = 40;
|
|
2266
|
+
function computeLayout(nodes, edges, direction) {
|
|
2267
|
+
const g = new dagre__default.default.graphlib.Graph();
|
|
2268
|
+
g.setGraph({
|
|
2269
|
+
rankdir: direction === "left-right" ? "LR" : "TB",
|
|
2270
|
+
nodesep: NODE_SEP3,
|
|
2271
|
+
ranksep: RANK_SEP3,
|
|
2272
|
+
edgesep: 10
|
|
2273
|
+
});
|
|
2274
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
2275
|
+
for (const node of nodes) {
|
|
2276
|
+
const isDecision = node.type === "decision";
|
|
2277
|
+
g.setNode(node.id, {
|
|
2278
|
+
label: node.label,
|
|
2279
|
+
width: isDecision ? DECISION_WIDTH : NODE_WIDTH,
|
|
2280
|
+
height: isDecision ? DECISION_HEIGHT : NODE_HEIGHT
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
for (const edge of edges) {
|
|
2284
|
+
g.setEdge(edge.from, edge.to);
|
|
2285
|
+
}
|
|
2286
|
+
dagre__default.default.layout(g);
|
|
2287
|
+
const positionedNodes = nodes.map((node) => {
|
|
2288
|
+
const d = g.node(node.id);
|
|
2289
|
+
return { ...node, x: d.x, y: d.y, width: d.width, height: d.height };
|
|
2290
|
+
});
|
|
2291
|
+
const positionedEdges = edges.map((edge) => {
|
|
2292
|
+
const d = g.edge(edge.from, edge.to);
|
|
2293
|
+
return { ...edge, points: d.points };
|
|
2294
|
+
});
|
|
2295
|
+
let maxX = 0;
|
|
2296
|
+
let maxY = 0;
|
|
2297
|
+
for (const n of positionedNodes) {
|
|
2298
|
+
maxX = Math.max(maxX, n.x + n.width / 2);
|
|
2299
|
+
maxY = Math.max(maxY, n.y + n.height / 2);
|
|
2300
|
+
}
|
|
2301
|
+
return {
|
|
2302
|
+
nodes: positionedNodes,
|
|
2303
|
+
edges: positionedEdges,
|
|
2304
|
+
width: maxX + LAYOUT_PADDING3,
|
|
2305
|
+
height: maxY + LAYOUT_PADDING3
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
function getThemeVar2(container, varName, fallback) {
|
|
2309
|
+
return getComputedStyle(container).getPropertyValue(varName).trim() || fallback;
|
|
2310
|
+
}
|
|
2311
|
+
var ARROW_MARKER_ID2 = "glyph-flowchart-arrowhead";
|
|
2312
|
+
function renderNodeShape(nodeG, node, fillOpacity, strokeWidth) {
|
|
2313
|
+
const cx = node.x;
|
|
2314
|
+
const cy = node.y;
|
|
2315
|
+
const w = node.width;
|
|
2316
|
+
const h = node.height;
|
|
2317
|
+
switch (node.type) {
|
|
2318
|
+
case "start":
|
|
2319
|
+
case "end": {
|
|
2320
|
+
nodeG.append("rect").attr("x", cx - w / 2).attr("y", cy - h / 2).attr("width", w).attr("height", h).attr("rx", h / 2).attr("ry", h / 2).attr("fill", "var(--glyph-accent, #00d4aa)").attr("stroke", "var(--glyph-accent-hover, #33e0be)").attr("stroke-width", strokeWidth).attr("opacity", fillOpacity);
|
|
2321
|
+
break;
|
|
2322
|
+
}
|
|
2323
|
+
case "decision": {
|
|
2324
|
+
const top = `${cx},${cy - h / 2}`;
|
|
2325
|
+
const right = `${cx + w / 2},${cy}`;
|
|
2326
|
+
const bottom = `${cx},${cy + h / 2}`;
|
|
2327
|
+
const left = `${cx - w / 2},${cy}`;
|
|
2328
|
+
nodeG.append("polygon").attr("points", `${top} ${right} ${bottom} ${left}`).attr("fill", "var(--glyph-surface-raised, #162038)").attr("stroke", "var(--glyph-accent, #00d4aa)").attr("stroke-width", strokeWidth).attr("opacity", fillOpacity);
|
|
2329
|
+
break;
|
|
2330
|
+
}
|
|
2331
|
+
case "process":
|
|
2332
|
+
default: {
|
|
2333
|
+
nodeG.append("rect").attr("x", cx - w / 2).attr("y", cy - h / 2).attr("width", w).attr("height", h).attr("rx", 3).attr("ry", 3).attr("fill", "var(--glyph-surface-raised, #162038)").attr("stroke", "var(--glyph-border-strong, #2a3550)").attr("stroke-width", strokeWidth).attr("opacity", fillOpacity);
|
|
2334
|
+
break;
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
function renderFlowchart(svgElement, layout) {
|
|
2339
|
+
const svg = d32__namespace.select(svgElement);
|
|
2340
|
+
svg.selectAll("*").remove();
|
|
2341
|
+
const width = Math.max(layout.width, 200);
|
|
2342
|
+
const height = Math.max(layout.height, 200);
|
|
2343
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
2344
|
+
const defs = svg.append("defs");
|
|
2345
|
+
defs.append("marker").attr("id", ARROW_MARKER_ID2).attr("viewBox", "0 0 10 10").attr("refX", 10).attr("refY", 5).attr("markerWidth", 8).attr("markerHeight", 8).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 Z").attr("fill", "var(--glyph-edge-color, #6b7a94)");
|
|
2346
|
+
const container = svgElement.parentElement ?? svgElement;
|
|
2347
|
+
const nodeStrokeWidth = getThemeVar2(container, "--glyph-node-stroke-width", "1.5");
|
|
2348
|
+
const nodeFillOpacity = getThemeVar2(container, "--glyph-node-fill-opacity", "0.85");
|
|
2349
|
+
const root = svg.append("g").attr("class", "glyph-flowchart-root");
|
|
2350
|
+
const zoomBehavior = d32__namespace.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
|
|
2351
|
+
root.attr("transform", event.transform.toString());
|
|
2352
|
+
});
|
|
2353
|
+
svg.call(zoomBehavior);
|
|
2354
|
+
const lineGen = d32__namespace.line().x((d) => d.x).y((d) => d.y).curve(d32__namespace.curveBasis);
|
|
2355
|
+
const edgeGroup = root.append("g").attr("class", "glyph-flowchart-edges");
|
|
2356
|
+
for (const edge of layout.edges) {
|
|
2357
|
+
const edgeG = edgeGroup.append("g").attr("class", "glyph-flowchart-edge");
|
|
2358
|
+
edgeG.append("path").attr("d", lineGen(edge.points) ?? "").attr("fill", "none").attr("stroke", "var(--glyph-edge-color, #6b7a94)").attr("stroke-width", nodeStrokeWidth).attr("marker-end", `url(#${ARROW_MARKER_ID2})`);
|
|
2359
|
+
if (edge.label) {
|
|
2360
|
+
const mid = edge.points[Math.floor(edge.points.length / 2)];
|
|
2361
|
+
if (mid) {
|
|
2362
|
+
edgeG.append("text").attr("x", mid.x).attr("y", mid.y - 8).attr("text-anchor", "middle").attr("font-size", "11px").attr("fill", "var(--glyph-text-muted, #6b7a94)").text(edge.label);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
const nodeGroup = root.append("g").attr("class", "glyph-flowchart-nodes");
|
|
2367
|
+
for (const node of layout.nodes) {
|
|
2368
|
+
const nodeG = nodeGroup.append("g").attr("class", "glyph-flowchart-node");
|
|
2369
|
+
renderNodeShape(nodeG, node, nodeFillOpacity, nodeStrokeWidth);
|
|
2370
|
+
nodeG.append("text").attr("x", node.x).attr("y", node.y).attr("dy", "0.35em").attr("text-anchor", "middle").attr("font-size", "13px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-node-label-color, #fff)").attr("pointer-events", "none").text(node.label);
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
function Flowchart({ data, container }) {
|
|
2374
|
+
const svgRef = react.useRef(null);
|
|
2375
|
+
const layoutResult = react.useMemo(() => computeLayout(data.nodes, data.edges, data.direction), [data]);
|
|
2376
|
+
react.useEffect(() => {
|
|
2377
|
+
if (!svgRef.current) return;
|
|
2378
|
+
renderFlowchart(svgRef.current, layoutResult);
|
|
2379
|
+
}, [layoutResult]);
|
|
2380
|
+
const nodeCount = data.nodes.length;
|
|
2381
|
+
const edgeCount = data.edges.length;
|
|
2382
|
+
const ariaLabel = data.title ? `${data.title}: flowchart with ${nodeCount} nodes and ${edgeCount} edges` : `Flowchart with ${nodeCount} nodes and ${edgeCount} edges`;
|
|
2383
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-flowchart-container", children: [
|
|
2384
|
+
data.title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2385
|
+
"div",
|
|
2386
|
+
{
|
|
2387
|
+
style: {
|
|
2388
|
+
fontFamily: "var(--glyph-font-heading, Inter, system-ui, sans-serif)",
|
|
2389
|
+
fontWeight: 600,
|
|
2390
|
+
fontSize: "1rem",
|
|
2391
|
+
color: "var(--glyph-heading, #edf0f5)",
|
|
2392
|
+
marginBottom: "0.5rem"
|
|
2393
|
+
},
|
|
2394
|
+
children: data.title
|
|
2395
|
+
}
|
|
2396
|
+
),
|
|
2397
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2398
|
+
"svg",
|
|
2399
|
+
{
|
|
2400
|
+
ref: svgRef,
|
|
2401
|
+
role: "img",
|
|
2402
|
+
"aria-label": ariaLabel,
|
|
2403
|
+
width: "100%",
|
|
2404
|
+
height: "100%",
|
|
2405
|
+
style: {
|
|
2406
|
+
minHeight: container.tier === "compact" ? 200 : 300,
|
|
2407
|
+
maxHeight: container.tier === "compact" ? 500 : 700,
|
|
2408
|
+
display: "block"
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
),
|
|
2412
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Flowchart data", style: SR_ONLY_STYLE3, children: [
|
|
2413
|
+
/* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Flowchart nodes and connections" }),
|
|
2414
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
2415
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Node" }),
|
|
2416
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Type" }),
|
|
2417
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Connections" })
|
|
2418
|
+
] }) }),
|
|
2419
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.nodes.map((node) => {
|
|
2420
|
+
const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
|
|
2421
|
+
const target = e.from === node.id ? e.to : e.from;
|
|
2422
|
+
const dir = e.from === node.id ? "->" : "<-";
|
|
2423
|
+
return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
|
|
2424
|
+
}).join(", ");
|
|
2425
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
2426
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.label }),
|
|
2427
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.type }),
|
|
2428
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: connections })
|
|
2429
|
+
] }, node.id);
|
|
2430
|
+
}) })
|
|
2431
|
+
] })
|
|
2432
|
+
] });
|
|
2433
|
+
}
|
|
2434
|
+
var SR_ONLY_STYLE3 = {
|
|
2435
|
+
position: "absolute",
|
|
2436
|
+
width: "1px",
|
|
2437
|
+
height: "1px",
|
|
2438
|
+
padding: 0,
|
|
2439
|
+
margin: "-1px",
|
|
2440
|
+
overflow: "hidden",
|
|
2441
|
+
clip: "rect(0, 0, 0, 0)",
|
|
2442
|
+
whiteSpace: "nowrap",
|
|
2443
|
+
border: 0
|
|
2444
|
+
};
|
|
2445
|
+
|
|
2446
|
+
// src/flowchart/index.ts
|
|
2447
|
+
var flowchartDefinition = {
|
|
2448
|
+
type: "ui:flowchart",
|
|
2449
|
+
schema: schemas.flowchartSchema,
|
|
2450
|
+
render: Flowchart
|
|
2451
|
+
};
|
|
2452
|
+
function getFileIcon(name) {
|
|
2453
|
+
const ext = name.split(".").pop()?.toLowerCase() ?? "";
|
|
2454
|
+
switch (ext) {
|
|
2455
|
+
case "ts":
|
|
2456
|
+
case "tsx":
|
|
2457
|
+
return "\u{1F1F9}";
|
|
2458
|
+
// 🇹 — TS indicator
|
|
2459
|
+
case "js":
|
|
2460
|
+
case "jsx":
|
|
2461
|
+
return "\u{1F1EF}";
|
|
2462
|
+
// 🇯 — JS indicator
|
|
2463
|
+
case "json":
|
|
2464
|
+
return "\u{1F4CB}";
|
|
2465
|
+
// 📋
|
|
2466
|
+
case "md":
|
|
2467
|
+
case "mdx":
|
|
2468
|
+
return "\u{1F4DD}";
|
|
2469
|
+
// 📝
|
|
2470
|
+
case "css":
|
|
2471
|
+
case "scss":
|
|
2472
|
+
case "less":
|
|
2473
|
+
return "\u{1F3A8}";
|
|
2474
|
+
// 🎨
|
|
2475
|
+
case "html":
|
|
2476
|
+
return "\u{1F310}";
|
|
2477
|
+
// 🌐
|
|
2478
|
+
case "svg":
|
|
2479
|
+
case "png":
|
|
2480
|
+
case "jpg":
|
|
2481
|
+
case "jpeg":
|
|
2482
|
+
case "gif":
|
|
2483
|
+
return "\u{1F5BC}";
|
|
2484
|
+
// 🖼
|
|
2485
|
+
case "yml":
|
|
2486
|
+
case "yaml":
|
|
2487
|
+
return "\u2699";
|
|
2488
|
+
// ⚙
|
|
2489
|
+
default:
|
|
2490
|
+
return "\u{1F4C4}";
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
function TreeItem({
|
|
2494
|
+
node,
|
|
2495
|
+
level,
|
|
2496
|
+
defaultExpanded,
|
|
2497
|
+
flatIndex,
|
|
2498
|
+
focusedIndex,
|
|
2499
|
+
setSize,
|
|
2500
|
+
posInSet,
|
|
2501
|
+
onFocusChange,
|
|
2502
|
+
flatItems
|
|
2503
|
+
}) {
|
|
2504
|
+
const [expanded, setExpanded] = react.useState(defaultExpanded);
|
|
2505
|
+
const itemRef = react.useRef(null);
|
|
2506
|
+
const isDir = Array.isArray(node.children) && node.children.length > 0;
|
|
2507
|
+
const isFocused = flatIndex === focusedIndex;
|
|
2508
|
+
const handleToggle = react.useCallback(() => {
|
|
2509
|
+
if (isDir) setExpanded((prev) => !prev);
|
|
2510
|
+
}, [isDir]);
|
|
2511
|
+
const handleKeyDown = react.useCallback(
|
|
2512
|
+
(e) => {
|
|
2513
|
+
let handled = true;
|
|
2514
|
+
switch (e.key) {
|
|
2515
|
+
case "ArrowDown": {
|
|
2516
|
+
const next = flatIndex + 1;
|
|
2517
|
+
if (next < flatItems.length) onFocusChange(next);
|
|
2518
|
+
break;
|
|
2519
|
+
}
|
|
2520
|
+
case "ArrowUp": {
|
|
2521
|
+
const prev = flatIndex - 1;
|
|
2522
|
+
if (prev >= 0) onFocusChange(prev);
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
case "ArrowRight":
|
|
2526
|
+
if (isDir && !expanded) {
|
|
2527
|
+
setExpanded(true);
|
|
2528
|
+
} else if (isDir && expanded) {
|
|
2529
|
+
const next = flatIndex + 1;
|
|
2530
|
+
if (next < flatItems.length) onFocusChange(next);
|
|
2531
|
+
}
|
|
2532
|
+
break;
|
|
2533
|
+
case "ArrowLeft":
|
|
2534
|
+
if (isDir && expanded) {
|
|
2535
|
+
setExpanded(false);
|
|
2536
|
+
} else if (level > 0) {
|
|
2537
|
+
for (let idx = flatIndex - 1; idx >= 0; idx--) {
|
|
2538
|
+
const item = flatItems[idx];
|
|
2539
|
+
if (item && item.level < level && item.isDir) {
|
|
2540
|
+
onFocusChange(idx);
|
|
2541
|
+
break;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
break;
|
|
2546
|
+
case "Enter":
|
|
2547
|
+
case " ":
|
|
2548
|
+
handleToggle();
|
|
2549
|
+
break;
|
|
2550
|
+
case "Home":
|
|
2551
|
+
onFocusChange(0);
|
|
2552
|
+
break;
|
|
2553
|
+
case "End":
|
|
2554
|
+
onFocusChange(flatItems.length - 1);
|
|
2555
|
+
break;
|
|
2556
|
+
default:
|
|
2557
|
+
handled = false;
|
|
2558
|
+
}
|
|
2559
|
+
if (handled) {
|
|
2560
|
+
e.preventDefault();
|
|
2561
|
+
e.stopPropagation();
|
|
2562
|
+
}
|
|
2563
|
+
},
|
|
2564
|
+
[flatIndex, flatItems, isDir, expanded, level, onFocusChange, handleToggle]
|
|
2565
|
+
);
|
|
2566
|
+
const icon = isDir ? expanded ? "\u{1F4C2}" : "\u{1F4C1}" : getFileIcon(node.name);
|
|
2567
|
+
const ariaLabel = node.annotation ? `${node.name}, ${node.annotation}` : node.name;
|
|
2568
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2569
|
+
"li",
|
|
2570
|
+
{
|
|
2571
|
+
ref: itemRef,
|
|
2572
|
+
role: "treeitem",
|
|
2573
|
+
"aria-expanded": isDir ? expanded : void 0,
|
|
2574
|
+
"aria-label": ariaLabel,
|
|
2575
|
+
"aria-level": level + 1,
|
|
2576
|
+
"aria-setsize": setSize,
|
|
2577
|
+
"aria-posinset": posInSet,
|
|
2578
|
+
tabIndex: isFocused ? 0 : -1,
|
|
2579
|
+
onKeyDown: handleKeyDown,
|
|
2580
|
+
onClick: (e) => {
|
|
2581
|
+
e.stopPropagation();
|
|
2582
|
+
onFocusChange(flatIndex);
|
|
2583
|
+
handleToggle();
|
|
2584
|
+
},
|
|
2585
|
+
style: {
|
|
2586
|
+
listStyle: "none",
|
|
2587
|
+
cursor: isDir ? "pointer" : "default",
|
|
2588
|
+
padding: "2px 0",
|
|
2589
|
+
outline: "none",
|
|
2590
|
+
borderRadius: "var(--glyph-radius-sm, 0.375rem)",
|
|
2591
|
+
background: isFocused ? "var(--glyph-accent-subtle, rgba(0,212,170,0.1))" : "transparent"
|
|
2592
|
+
},
|
|
2593
|
+
"data-flat-index": flatIndex,
|
|
2594
|
+
children: [
|
|
2595
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2596
|
+
"div",
|
|
2597
|
+
{
|
|
2598
|
+
style: {
|
|
2599
|
+
display: "flex",
|
|
2600
|
+
alignItems: "center",
|
|
2601
|
+
gap: "0.25rem",
|
|
2602
|
+
paddingLeft: `${level * 1.25}rem`,
|
|
2603
|
+
fontFamily: "var(--glyph-font-mono, monospace)",
|
|
2604
|
+
fontSize: "0.875rem",
|
|
2605
|
+
lineHeight: "1.6",
|
|
2606
|
+
color: "var(--glyph-text, #d4dae3)",
|
|
2607
|
+
userSelect: "none"
|
|
2608
|
+
},
|
|
2609
|
+
children: [
|
|
2610
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { width: "1.25rem", textAlign: "center", flexShrink: 0 }, children: icon }),
|
|
2611
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: isDir ? 600 : 400 }, children: node.name }),
|
|
2612
|
+
node.annotation && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2613
|
+
"span",
|
|
2614
|
+
{
|
|
2615
|
+
style: {
|
|
2616
|
+
fontSize: "0.75rem",
|
|
2617
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
2618
|
+
background: "var(--glyph-surface, #0f1526)",
|
|
2619
|
+
padding: "0 0.375rem",
|
|
2620
|
+
borderRadius: "var(--glyph-radius-sm, 0.375rem)",
|
|
2621
|
+
marginLeft: "0.25rem"
|
|
2622
|
+
},
|
|
2623
|
+
children: node.annotation
|
|
2624
|
+
}
|
|
2625
|
+
)
|
|
2626
|
+
]
|
|
2627
|
+
}
|
|
2628
|
+
),
|
|
2629
|
+
isDir && expanded && node.children && /* @__PURE__ */ jsxRuntime.jsx("ul", { role: "group", style: { margin: 0, padding: 0 }, children: node.children.map((child, childIdx) => {
|
|
2630
|
+
const childFlatIndex = getChildFlatIndex(flatItems, flatIndex, childIdx, node.children);
|
|
2631
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2632
|
+
TreeItem,
|
|
2633
|
+
{
|
|
2634
|
+
node: child,
|
|
2635
|
+
level: level + 1,
|
|
2636
|
+
defaultExpanded,
|
|
2637
|
+
flatIndex: childFlatIndex,
|
|
2638
|
+
focusedIndex,
|
|
2639
|
+
setSize: node.children?.length ?? 0,
|
|
2640
|
+
posInSet: childIdx + 1,
|
|
2641
|
+
onFocusChange,
|
|
2642
|
+
flatItems
|
|
2643
|
+
},
|
|
2644
|
+
child.name
|
|
2645
|
+
);
|
|
2646
|
+
}) })
|
|
2647
|
+
]
|
|
2648
|
+
}
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
function flattenTree(nodes, level) {
|
|
2652
|
+
const result = [];
|
|
2653
|
+
for (const node of nodes) {
|
|
2654
|
+
const isDir = Array.isArray(node.children) && node.children.length > 0;
|
|
2655
|
+
result.push({ node, level, isDir });
|
|
2656
|
+
if (isDir && node.children) {
|
|
2657
|
+
result.push(...flattenTree(node.children, level + 1));
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return result;
|
|
2661
|
+
}
|
|
2662
|
+
function getChildFlatIndex(flatItems, parentFlatIndex, childIdx, children) {
|
|
2663
|
+
if (!children) return parentFlatIndex + 1;
|
|
2664
|
+
let count = 0;
|
|
2665
|
+
for (let i = parentFlatIndex + 1; i < flatItems.length; i++) {
|
|
2666
|
+
const item = flatItems[i];
|
|
2667
|
+
if (!item) continue;
|
|
2668
|
+
if (item.node === children[count]) {
|
|
2669
|
+
if (count === childIdx) return i;
|
|
2670
|
+
count++;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
return parentFlatIndex + childIdx + 1;
|
|
2674
|
+
}
|
|
2675
|
+
function FileTree({ data }) {
|
|
2676
|
+
const [focusedIndex, setFocusedIndex] = react.useState(0);
|
|
2677
|
+
const containerRef = react.useRef(null);
|
|
2678
|
+
const flatItems = flattenTree(data.tree, data.root ? 1 : 0);
|
|
2679
|
+
const handleFocusChange = react.useCallback((index) => {
|
|
2680
|
+
setFocusedIndex(index);
|
|
2681
|
+
const container = containerRef.current;
|
|
2682
|
+
if (!container) return;
|
|
2683
|
+
const el = container.querySelector(`[data-flat-index="${String(index)}"]`);
|
|
2684
|
+
el?.focus();
|
|
2685
|
+
}, []);
|
|
2686
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2687
|
+
"div",
|
|
2688
|
+
{
|
|
2689
|
+
ref: containerRef,
|
|
2690
|
+
className: "glyph-filetree-container",
|
|
2691
|
+
style: {
|
|
2692
|
+
border: "1px solid var(--glyph-border, #1a2035)",
|
|
2693
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
2694
|
+
padding: "0.75rem",
|
|
2695
|
+
background: "var(--glyph-surface, #0f1526)"
|
|
2696
|
+
},
|
|
2697
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("ul", { role: "tree", "aria-label": data.root ?? "File tree", style: { margin: 0, padding: 0 }, children: [
|
|
2698
|
+
data.root && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2699
|
+
"li",
|
|
2700
|
+
{
|
|
2701
|
+
role: "treeitem",
|
|
2702
|
+
"aria-expanded": true,
|
|
2703
|
+
"aria-level": 1,
|
|
2704
|
+
"aria-setsize": 1,
|
|
2705
|
+
"aria-posinset": 1,
|
|
2706
|
+
style: {
|
|
2707
|
+
listStyle: "none",
|
|
2708
|
+
padding: "2px 0"
|
|
2709
|
+
},
|
|
2710
|
+
children: [
|
|
2711
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2712
|
+
"div",
|
|
2713
|
+
{
|
|
2714
|
+
style: {
|
|
2715
|
+
display: "flex",
|
|
2716
|
+
alignItems: "center",
|
|
2717
|
+
gap: "0.25rem",
|
|
2718
|
+
fontFamily: "var(--glyph-font-mono, monospace)",
|
|
2719
|
+
fontSize: "0.875rem",
|
|
2720
|
+
fontWeight: 700,
|
|
2721
|
+
color: "var(--glyph-heading, #edf0f5)"
|
|
2722
|
+
},
|
|
2723
|
+
children: [
|
|
2724
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { width: "1.25rem", textAlign: "center" }, children: "\u{1F4C2}" }),
|
|
2725
|
+
data.root
|
|
2726
|
+
]
|
|
2727
|
+
}
|
|
2728
|
+
),
|
|
2729
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { role: "group", style: { margin: 0, padding: 0 }, children: data.tree.map((node, idx) => {
|
|
2730
|
+
const flatIndex = getFlatIndexForTopLevel(flatItems, idx, data.tree);
|
|
2731
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2732
|
+
TreeItem,
|
|
2733
|
+
{
|
|
2734
|
+
node,
|
|
2735
|
+
level: 1,
|
|
2736
|
+
defaultExpanded: data.defaultExpanded,
|
|
2737
|
+
flatIndex,
|
|
2738
|
+
focusedIndex,
|
|
2739
|
+
setSize: data.tree.length,
|
|
2740
|
+
posInSet: idx + 1,
|
|
2741
|
+
onFocusChange: handleFocusChange,
|
|
2742
|
+
flatItems
|
|
2743
|
+
},
|
|
2744
|
+
node.name
|
|
2745
|
+
);
|
|
2746
|
+
}) })
|
|
2747
|
+
]
|
|
2748
|
+
}
|
|
2749
|
+
),
|
|
2750
|
+
!data.root && data.tree.map((node, idx) => {
|
|
2751
|
+
const flatIndex = getFlatIndexForTopLevel(flatItems, idx, data.tree);
|
|
2752
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2753
|
+
TreeItem,
|
|
2754
|
+
{
|
|
2755
|
+
node,
|
|
2756
|
+
level: 0,
|
|
2757
|
+
defaultExpanded: data.defaultExpanded,
|
|
2758
|
+
flatIndex,
|
|
2759
|
+
focusedIndex,
|
|
2760
|
+
setSize: data.tree.length,
|
|
2761
|
+
posInSet: idx + 1,
|
|
2762
|
+
onFocusChange: handleFocusChange,
|
|
2763
|
+
flatItems
|
|
2764
|
+
},
|
|
2765
|
+
node.name
|
|
2766
|
+
);
|
|
2767
|
+
})
|
|
2768
|
+
] })
|
|
2769
|
+
}
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2772
|
+
function getFlatIndexForTopLevel(flatItems, idx, tree) {
|
|
2773
|
+
let count = 0;
|
|
2774
|
+
for (let i = 0; i < flatItems.length; i++) {
|
|
2775
|
+
const item = flatItems[i];
|
|
2776
|
+
if (item && item.node === tree[count]) {
|
|
2777
|
+
if (count === idx) return i;
|
|
2778
|
+
count++;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
return idx;
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
// src/filetree/index.ts
|
|
2785
|
+
var fileTreeDefinition = {
|
|
2786
|
+
type: "ui:filetree",
|
|
2787
|
+
schema: schemas.filetreeSchema,
|
|
2788
|
+
render: FileTree
|
|
2789
|
+
};
|
|
2790
|
+
var ACTOR_WIDTH = 120;
|
|
2791
|
+
var ACTOR_HEIGHT = 40;
|
|
2792
|
+
var ACTOR_GAP = 160;
|
|
2793
|
+
var TOP_MARGIN = 20;
|
|
2794
|
+
var MSG_SPACING = 50;
|
|
2795
|
+
var SELF_ARC_WIDTH = 30;
|
|
2796
|
+
var SELF_ARC_HEIGHT = 30;
|
|
2797
|
+
var BOTTOM_PADDING = 40;
|
|
2798
|
+
var SIDE_PADDING = 40;
|
|
2799
|
+
var ARROW_SIZE = 8;
|
|
2800
|
+
function renderActorBox(actor, cx, y, keyPrefix, width = ACTOR_WIDTH, height = ACTOR_HEIGHT, fontSize = "13px") {
|
|
2801
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2802
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2803
|
+
"rect",
|
|
2804
|
+
{
|
|
2805
|
+
x: cx - width / 2,
|
|
2806
|
+
y,
|
|
2807
|
+
width,
|
|
2808
|
+
height,
|
|
2809
|
+
rx: 4,
|
|
2810
|
+
ry: 4,
|
|
2811
|
+
fill: "var(--glyph-surface-raised, #162038)",
|
|
2812
|
+
stroke: "var(--glyph-border-strong, #2a3550)",
|
|
2813
|
+
strokeWidth: 1.5
|
|
2814
|
+
}
|
|
2815
|
+
),
|
|
2816
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2817
|
+
"text",
|
|
2818
|
+
{
|
|
2819
|
+
x: cx,
|
|
2820
|
+
y: y + height / 2,
|
|
2821
|
+
dy: "0.35em",
|
|
2822
|
+
textAnchor: "middle",
|
|
2823
|
+
fontSize,
|
|
2824
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
2825
|
+
fontWeight: 600,
|
|
2826
|
+
fill: "var(--glyph-text, #d4dae3)",
|
|
2827
|
+
children: actor.label
|
|
2828
|
+
}
|
|
2829
|
+
)
|
|
2830
|
+
] }, `${keyPrefix}-${actor.id}`);
|
|
2831
|
+
}
|
|
2832
|
+
function renderSelfMessage(x, y, label, idx, fontSize = "12px") {
|
|
2833
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2834
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2835
|
+
"path",
|
|
2836
|
+
{
|
|
2837
|
+
d: `M ${x} ${y} L ${x + SELF_ARC_WIDTH} ${y} L ${x + SELF_ARC_WIDTH} ${y + SELF_ARC_HEIGHT} L ${x} ${y + SELF_ARC_HEIGHT}`,
|
|
2838
|
+
fill: "none",
|
|
2839
|
+
stroke: "var(--glyph-text, #d4dae3)",
|
|
2840
|
+
strokeWidth: 1.5,
|
|
2841
|
+
markerEnd: "url(#seq-arrow-solid)"
|
|
2842
|
+
}
|
|
2843
|
+
),
|
|
2844
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2845
|
+
"text",
|
|
2846
|
+
{
|
|
2847
|
+
x: x + SELF_ARC_WIDTH + 6,
|
|
2848
|
+
y: y + SELF_ARC_HEIGHT / 2,
|
|
2849
|
+
dy: "0.35em",
|
|
2850
|
+
fontSize,
|
|
2851
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
2852
|
+
fill: "var(--glyph-text, #d4dae3)",
|
|
2853
|
+
children: label
|
|
2854
|
+
}
|
|
2855
|
+
)
|
|
2856
|
+
] }, `msg-${idx}`);
|
|
2857
|
+
}
|
|
2858
|
+
function renderStandardMessage(fromX, toX, y, label, isDashed, idx, fontSize = "12px") {
|
|
2859
|
+
const markerId = isDashed ? "seq-arrow-dashed" : "seq-arrow-solid";
|
|
2860
|
+
const midX = (fromX + toX) / 2;
|
|
2861
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2862
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2863
|
+
"line",
|
|
2864
|
+
{
|
|
2865
|
+
x1: fromX,
|
|
2866
|
+
y1: y,
|
|
2867
|
+
x2: toX,
|
|
2868
|
+
y2: y,
|
|
2869
|
+
stroke: isDashed ? "var(--glyph-text-muted, #6b7a94)" : "var(--glyph-text, #d4dae3)",
|
|
2870
|
+
strokeWidth: 1.5,
|
|
2871
|
+
strokeDasharray: isDashed ? "6,4" : void 0,
|
|
2872
|
+
markerEnd: `url(#${markerId})`
|
|
2873
|
+
}
|
|
2874
|
+
),
|
|
2875
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2876
|
+
"text",
|
|
2877
|
+
{
|
|
2878
|
+
x: midX,
|
|
2879
|
+
y: y - 8,
|
|
2880
|
+
textAnchor: "middle",
|
|
2881
|
+
fontSize,
|
|
2882
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
2883
|
+
fill: "var(--glyph-text, #d4dae3)",
|
|
2884
|
+
children: label
|
|
2885
|
+
}
|
|
2886
|
+
)
|
|
2887
|
+
] }, `msg-${idx}`);
|
|
2888
|
+
}
|
|
2889
|
+
function Sequence({ data, container }) {
|
|
2890
|
+
const actorCount = data.actors.length;
|
|
2891
|
+
const messageCount = data.messages.length;
|
|
2892
|
+
const isCompact = container.tier === "compact";
|
|
2893
|
+
const effectiveActorGap = isCompact ? Math.round(ACTOR_GAP * 0.6) : ACTOR_GAP;
|
|
2894
|
+
const effectiveActorWidth = isCompact ? Math.round(ACTOR_WIDTH * 0.7) : ACTOR_WIDTH;
|
|
2895
|
+
const effectiveActorHeight = isCompact ? Math.round(ACTOR_HEIGHT * 0.85) : ACTOR_HEIGHT;
|
|
2896
|
+
const actorFontSize = isCompact ? "11px" : "13px";
|
|
2897
|
+
const msgFontSize = isCompact ? "10px" : "12px";
|
|
2898
|
+
const actorX = /* @__PURE__ */ new Map();
|
|
2899
|
+
for (let i = 0; i < actorCount; i++) {
|
|
2900
|
+
const actor = data.actors[i];
|
|
2901
|
+
if (actor) {
|
|
2902
|
+
actorX.set(actor.id, SIDE_PADDING + i * effectiveActorGap + effectiveActorWidth / 2);
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
const svgWidth = SIDE_PADDING * 2 + (actorCount - 1) * effectiveActorGap + effectiveActorWidth;
|
|
2906
|
+
const actorBoxY = TOP_MARGIN;
|
|
2907
|
+
const lifelineStartY = actorBoxY + effectiveActorHeight;
|
|
2908
|
+
const firstMsgY = lifelineStartY + MSG_SPACING;
|
|
2909
|
+
const lastMsgY = firstMsgY + (messageCount - 1) * MSG_SPACING;
|
|
2910
|
+
const svgHeight = lastMsgY + BOTTOM_PADDING + effectiveActorHeight;
|
|
2911
|
+
const ariaLabel = data.title ? `${data.title}: sequence diagram with ${actorCount} actors and ${messageCount} messages` : `Sequence diagram with ${actorCount} actors and ${messageCount} messages`;
|
|
2912
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-sequence-container", children: [
|
|
2913
|
+
data.title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2914
|
+
"div",
|
|
2915
|
+
{
|
|
2916
|
+
style: {
|
|
2917
|
+
fontFamily: "var(--glyph-font-heading, Inter, system-ui, sans-serif)",
|
|
2918
|
+
fontWeight: 600,
|
|
2919
|
+
fontSize: "1rem",
|
|
2920
|
+
color: "var(--glyph-heading, #edf0f5)",
|
|
2921
|
+
marginBottom: "0.5rem"
|
|
2922
|
+
},
|
|
2923
|
+
children: data.title
|
|
2924
|
+
}
|
|
2925
|
+
),
|
|
2926
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2927
|
+
"svg",
|
|
2928
|
+
{
|
|
2929
|
+
role: "img",
|
|
2930
|
+
"aria-label": ariaLabel,
|
|
2931
|
+
viewBox: `0 0 ${svgWidth} ${svgHeight}`,
|
|
2932
|
+
width: "100%",
|
|
2933
|
+
style: { minHeight: 200, maxHeight: 800, display: "block" },
|
|
2934
|
+
children: [
|
|
2935
|
+
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
2936
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2937
|
+
"marker",
|
|
2938
|
+
{
|
|
2939
|
+
id: "seq-arrow-solid",
|
|
2940
|
+
viewBox: "0 0 10 10",
|
|
2941
|
+
refX: 10,
|
|
2942
|
+
refY: 5,
|
|
2943
|
+
markerWidth: ARROW_SIZE,
|
|
2944
|
+
markerHeight: ARROW_SIZE,
|
|
2945
|
+
orient: "auto-start-reverse",
|
|
2946
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M 0 0 L 10 5 L 0 10 Z", fill: "var(--glyph-text, #d4dae3)" })
|
|
2947
|
+
}
|
|
2948
|
+
),
|
|
2949
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2950
|
+
"marker",
|
|
2951
|
+
{
|
|
2952
|
+
id: "seq-arrow-dashed",
|
|
2953
|
+
viewBox: "0 0 10 10",
|
|
2954
|
+
refX: 10,
|
|
2955
|
+
refY: 5,
|
|
2956
|
+
markerWidth: ARROW_SIZE,
|
|
2957
|
+
markerHeight: ARROW_SIZE,
|
|
2958
|
+
orient: "auto-start-reverse",
|
|
2959
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M 0 0 L 10 5 L 0 10 Z", fill: "var(--glyph-text-muted, #6b7a94)" })
|
|
2960
|
+
}
|
|
2961
|
+
)
|
|
2962
|
+
] }),
|
|
2963
|
+
data.actors.map((actor) => {
|
|
2964
|
+
const cx = actorX.get(actor.id) ?? 0;
|
|
2965
|
+
return renderActorBox(
|
|
2966
|
+
actor,
|
|
2967
|
+
cx,
|
|
2968
|
+
actorBoxY,
|
|
2969
|
+
"actor-top",
|
|
2970
|
+
effectiveActorWidth,
|
|
2971
|
+
effectiveActorHeight,
|
|
2972
|
+
actorFontSize
|
|
2973
|
+
);
|
|
2974
|
+
}),
|
|
2975
|
+
data.actors.map((actor) => {
|
|
2976
|
+
const cx = actorX.get(actor.id) ?? 0;
|
|
2977
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2978
|
+
"line",
|
|
2979
|
+
{
|
|
2980
|
+
x1: cx,
|
|
2981
|
+
y1: lifelineStartY,
|
|
2982
|
+
x2: cx,
|
|
2983
|
+
y2: lastMsgY + BOTTOM_PADDING / 2,
|
|
2984
|
+
stroke: "var(--glyph-border, #1a2035)",
|
|
2985
|
+
strokeWidth: 1,
|
|
2986
|
+
strokeDasharray: "6,4"
|
|
2987
|
+
},
|
|
2988
|
+
`lifeline-${actor.id}`
|
|
2989
|
+
);
|
|
2990
|
+
}),
|
|
2991
|
+
data.actors.map((actor) => {
|
|
2992
|
+
const cx = actorX.get(actor.id) ?? 0;
|
|
2993
|
+
const bottomY = lastMsgY + BOTTOM_PADDING / 2;
|
|
2994
|
+
return renderActorBox(
|
|
2995
|
+
actor,
|
|
2996
|
+
cx,
|
|
2997
|
+
bottomY,
|
|
2998
|
+
"actor-bottom",
|
|
2999
|
+
effectiveActorWidth,
|
|
3000
|
+
effectiveActorHeight,
|
|
3001
|
+
actorFontSize
|
|
3002
|
+
);
|
|
3003
|
+
}),
|
|
3004
|
+
data.messages.map((msg, idx) => {
|
|
3005
|
+
const y = firstMsgY + idx * MSG_SPACING;
|
|
3006
|
+
const fromX = actorX.get(msg.from) ?? 0;
|
|
3007
|
+
const toX = actorX.get(msg.to) ?? 0;
|
|
3008
|
+
if (msg.type === "self") {
|
|
3009
|
+
return renderSelfMessage(fromX, y, msg.label, idx, msgFontSize);
|
|
3010
|
+
}
|
|
3011
|
+
return renderStandardMessage(
|
|
3012
|
+
fromX,
|
|
3013
|
+
toX,
|
|
3014
|
+
y,
|
|
3015
|
+
msg.label,
|
|
3016
|
+
msg.type === "reply",
|
|
3017
|
+
idx,
|
|
3018
|
+
msgFontSize
|
|
3019
|
+
);
|
|
3020
|
+
})
|
|
3021
|
+
]
|
|
3022
|
+
}
|
|
3023
|
+
),
|
|
3024
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Sequence data", style: SR_ONLY_STYLE4, children: [
|
|
3025
|
+
/* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Sequence messages in order" }),
|
|
3026
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
3027
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "#" }),
|
|
3028
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "From" }),
|
|
3029
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "To" }),
|
|
3030
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Message" }),
|
|
3031
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Type" })
|
|
3032
|
+
] }) }),
|
|
3033
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.messages.map((msg, idx) => {
|
|
3034
|
+
const fromActor = data.actors.find((a) => a.id === msg.from);
|
|
3035
|
+
const toActor = data.actors.find((a) => a.id === msg.to);
|
|
3036
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
3037
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: idx + 1 }),
|
|
3038
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: fromActor?.label ?? msg.from }),
|
|
3039
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: toActor?.label ?? msg.to }),
|
|
3040
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: msg.label }),
|
|
3041
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: msg.type })
|
|
3042
|
+
] }, idx);
|
|
3043
|
+
}) })
|
|
3044
|
+
] })
|
|
3045
|
+
] });
|
|
3046
|
+
}
|
|
3047
|
+
var SR_ONLY_STYLE4 = {
|
|
3048
|
+
position: "absolute",
|
|
3049
|
+
width: "1px",
|
|
3050
|
+
height: "1px",
|
|
3051
|
+
padding: 0,
|
|
3052
|
+
margin: "-1px",
|
|
3053
|
+
overflow: "hidden",
|
|
3054
|
+
clip: "rect(0, 0, 0, 0)",
|
|
3055
|
+
whiteSpace: "nowrap",
|
|
3056
|
+
border: 0
|
|
3057
|
+
};
|
|
3058
|
+
|
|
3059
|
+
// src/sequence/index.ts
|
|
3060
|
+
var sequenceDefinition = {
|
|
3061
|
+
type: "ui:sequence",
|
|
3062
|
+
schema: schemas.sequenceSchema,
|
|
3063
|
+
render: Sequence
|
|
3064
|
+
};
|
|
3065
|
+
|
|
3066
|
+
// src/architecture/layout.ts
|
|
3067
|
+
var NODE_WIDTH2 = 120;
|
|
3068
|
+
var NODE_HEIGHT_WITH_ICON = 60;
|
|
3069
|
+
var NODE_HEIGHT_NO_ICON = 40;
|
|
3070
|
+
var ZONE_PADDING_TOP = 30;
|
|
3071
|
+
var ZONE_PADDING_SIDES = 15;
|
|
3072
|
+
var ZONE_PADDING_BOTTOM = 15;
|
|
3073
|
+
var LAYOUT_PADDING4 = 20;
|
|
3074
|
+
var DIRECTION_MAP = {
|
|
3075
|
+
"top-down": "DOWN",
|
|
3076
|
+
"left-right": "RIGHT",
|
|
3077
|
+
"bottom-up": "UP"
|
|
3078
|
+
};
|
|
3079
|
+
function buildElkNode(node) {
|
|
3080
|
+
if (node.type === "zone" && node.children?.length) {
|
|
3081
|
+
return {
|
|
3082
|
+
id: node.id,
|
|
3083
|
+
labels: [{ text: node.label }],
|
|
3084
|
+
children: node.children.map(buildElkNode),
|
|
3085
|
+
layoutOptions: {
|
|
3086
|
+
"elk.padding": `[top=${ZONE_PADDING_TOP},left=${ZONE_PADDING_SIDES},bottom=${ZONE_PADDING_BOTTOM},right=${ZONE_PADDING_SIDES}]`
|
|
3087
|
+
}
|
|
3088
|
+
};
|
|
3089
|
+
}
|
|
3090
|
+
return {
|
|
3091
|
+
id: node.id,
|
|
3092
|
+
width: NODE_WIDTH2,
|
|
3093
|
+
height: node.icon ? NODE_HEIGHT_WITH_ICON : NODE_HEIGHT_NO_ICON,
|
|
3094
|
+
labels: [{ text: node.label }]
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
function buildElkGraph(data) {
|
|
3098
|
+
const direction = DIRECTION_MAP[data.layout ?? "top-down"] ?? "DOWN";
|
|
3099
|
+
return {
|
|
3100
|
+
id: "root",
|
|
3101
|
+
children: data.children.map(buildElkNode),
|
|
3102
|
+
edges: data.edges.map((e, i) => ({
|
|
3103
|
+
id: `e${i}`,
|
|
3104
|
+
sources: [e.from],
|
|
3105
|
+
targets: [e.to],
|
|
3106
|
+
labels: e.label ? [{ text: e.label }] : []
|
|
3107
|
+
})),
|
|
3108
|
+
layoutOptions: {
|
|
3109
|
+
"elk.algorithm": "layered",
|
|
3110
|
+
"elk.hierarchyHandling": "INCLUDE_CHILDREN",
|
|
3111
|
+
"elk.edgeRouting": "ORTHOGONAL",
|
|
3112
|
+
"elk.direction": direction,
|
|
3113
|
+
"elk.spacing.nodeNode": "20",
|
|
3114
|
+
"elk.layered.spacing.nodeNodeBetweenLayers": "30",
|
|
3115
|
+
"elk.spacing.edgeNode": "10",
|
|
3116
|
+
"elk.spacing.edgeEdge": "8"
|
|
3117
|
+
}
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
function collectNodes(elkNode, nodeMap, offsetX, offsetY, nodes, zones, depth, zoneId) {
|
|
3121
|
+
const absX = offsetX + (elkNode.x ?? 0);
|
|
3122
|
+
const absY = offsetY + (elkNode.y ?? 0);
|
|
3123
|
+
const original = nodeMap.get(elkNode.id);
|
|
3124
|
+
if (original?.type === "zone" && elkNode.children?.length) {
|
|
3125
|
+
zones.push({
|
|
3126
|
+
id: elkNode.id,
|
|
3127
|
+
label: original.label,
|
|
3128
|
+
x: absX,
|
|
3129
|
+
y: absY,
|
|
3130
|
+
width: elkNode.width,
|
|
3131
|
+
height: elkNode.height,
|
|
3132
|
+
depth
|
|
3133
|
+
});
|
|
3134
|
+
for (const child of elkNode.children) {
|
|
3135
|
+
collectNodes(child, nodeMap, absX, absY, nodes, zones, depth + 1, elkNode.id);
|
|
3136
|
+
}
|
|
3137
|
+
} else {
|
|
3138
|
+
nodes.push({
|
|
3139
|
+
id: elkNode.id,
|
|
3140
|
+
label: original?.label ?? elkNode.id,
|
|
3141
|
+
icon: original?.icon,
|
|
3142
|
+
x: absX,
|
|
3143
|
+
y: absY,
|
|
3144
|
+
width: elkNode.width,
|
|
3145
|
+
height: elkNode.height,
|
|
3146
|
+
zoneId
|
|
3147
|
+
});
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
function flattenNodeMap(children, map) {
|
|
3151
|
+
for (const node of children) {
|
|
3152
|
+
map.set(node.id, node);
|
|
3153
|
+
if (node.children) {
|
|
3154
|
+
flattenNodeMap(node.children, map);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
function buildAncestorMap(children, ancestors, map) {
|
|
3159
|
+
for (const node of children) {
|
|
3160
|
+
map.set(node.id, [...ancestors]);
|
|
3161
|
+
if (node.type === "zone" && node.children) {
|
|
3162
|
+
buildAncestorMap(node.children, [...ancestors, node.id], map);
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
function findLCA(ancestorsA, ancestorsB) {
|
|
3167
|
+
let lca;
|
|
3168
|
+
const len = Math.min(ancestorsA.length, ancestorsB.length);
|
|
3169
|
+
for (let i = 0; i < len; i++) {
|
|
3170
|
+
if (ancestorsA[i] === ancestorsB[i]) {
|
|
3171
|
+
lca = ancestorsA[i];
|
|
3172
|
+
} else {
|
|
3173
|
+
break;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
return lca;
|
|
3177
|
+
}
|
|
3178
|
+
function extractEdges(elkEdges, dataEdges, ancestorMap, zoneAbsOffsets) {
|
|
3179
|
+
if (!elkEdges) return [];
|
|
3180
|
+
return elkEdges.map((elkEdge, i) => {
|
|
3181
|
+
const dataEdge = dataEdges[i];
|
|
3182
|
+
if (!dataEdge) {
|
|
3183
|
+
return { from: "", to: "", points: [] };
|
|
3184
|
+
}
|
|
3185
|
+
const srcAncestors = ancestorMap.get(dataEdge.from) ?? [];
|
|
3186
|
+
const tgtAncestors = ancestorMap.get(dataEdge.to) ?? [];
|
|
3187
|
+
const lca = findLCA(srcAncestors, tgtAncestors);
|
|
3188
|
+
const offset = lca ? zoneAbsOffsets.get(lca) ?? { x: 0, y: 0 } : { x: 0, y: 0 };
|
|
3189
|
+
const points = [];
|
|
3190
|
+
if (elkEdge.sections) {
|
|
3191
|
+
for (const section of elkEdge.sections) {
|
|
3192
|
+
points.push({ x: section.startPoint.x + offset.x, y: section.startPoint.y + offset.y });
|
|
3193
|
+
if (section.bendPoints) {
|
|
3194
|
+
for (const bp of section.bendPoints) {
|
|
3195
|
+
points.push({ x: bp.x + offset.x, y: bp.y + offset.y });
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
points.push({ x: section.endPoint.x + offset.x, y: section.endPoint.y + offset.y });
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
return {
|
|
3202
|
+
from: dataEdge.from,
|
|
3203
|
+
to: dataEdge.to,
|
|
3204
|
+
label: dataEdge.label,
|
|
3205
|
+
type: dataEdge.type,
|
|
3206
|
+
style: dataEdge.style,
|
|
3207
|
+
points
|
|
3208
|
+
};
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3211
|
+
async function computeArchitectureLayout(data) {
|
|
3212
|
+
const ELK = await import('elkjs/lib/elk.bundled.js');
|
|
3213
|
+
const elk = new ELK.default();
|
|
3214
|
+
const elkGraph = buildElkGraph(data);
|
|
3215
|
+
const result = await elk.layout(
|
|
3216
|
+
elkGraph
|
|
3217
|
+
);
|
|
3218
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
3219
|
+
flattenNodeMap(data.children, nodeMap);
|
|
3220
|
+
const nodes = [];
|
|
3221
|
+
const zones = [];
|
|
3222
|
+
if (result.children) {
|
|
3223
|
+
for (const child of result.children) {
|
|
3224
|
+
collectNodes(child, nodeMap, 0, 0, nodes, zones, 0);
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
const zoneAbsOffsets = /* @__PURE__ */ new Map();
|
|
3228
|
+
for (const z of zones) {
|
|
3229
|
+
zoneAbsOffsets.set(z.id, { x: z.x, y: z.y });
|
|
3230
|
+
}
|
|
3231
|
+
const ancestorMap = /* @__PURE__ */ new Map();
|
|
3232
|
+
buildAncestorMap(data.children, [], ancestorMap);
|
|
3233
|
+
const edges = extractEdges(result.edges, data.edges, ancestorMap, zoneAbsOffsets);
|
|
3234
|
+
let maxX = 0;
|
|
3235
|
+
let maxY = 0;
|
|
3236
|
+
for (const n of nodes) {
|
|
3237
|
+
const right = n.x + n.width;
|
|
3238
|
+
const bottom = n.y + n.height;
|
|
3239
|
+
if (right > maxX) maxX = right;
|
|
3240
|
+
if (bottom > maxY) maxY = bottom;
|
|
3241
|
+
}
|
|
3242
|
+
for (const z of zones) {
|
|
3243
|
+
const right = z.x + z.width;
|
|
3244
|
+
const bottom = z.y + z.height;
|
|
3245
|
+
if (right > maxX) maxX = right;
|
|
3246
|
+
if (bottom > maxY) maxY = bottom;
|
|
3247
|
+
}
|
|
3248
|
+
for (const e of edges) {
|
|
3249
|
+
for (const p of e.points) {
|
|
3250
|
+
if (p.x > maxX) maxX = p.x;
|
|
3251
|
+
if (p.y > maxY) maxY = p.y;
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
return {
|
|
3255
|
+
nodes,
|
|
3256
|
+
zones,
|
|
3257
|
+
edges,
|
|
3258
|
+
width: maxX + LAYOUT_PADDING4,
|
|
3259
|
+
height: maxY + LAYOUT_PADDING4
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
// src/architecture/icons.ts
|
|
3264
|
+
var ICON_PATHS = {
|
|
3265
|
+
// Rack server
|
|
3266
|
+
server: "M4 4h16v4H4zm0 6h16v4H4zm0 6h16v4H4zM6 6h1v0.5H6zm0 6h1v0.5H6zm0 6h1v0.5H6z",
|
|
3267
|
+
// Cylinder
|
|
3268
|
+
database: "M12 2C7.58 2 4 3.34 4 5v14c0 1.66 3.58 3 8 3s8-1.34 8-3V5c0-1.66-3.58-3-8-3zm0 2c3.87 0 6 1.12 6 1s-2.13 1-6 1-6-0.12-6-1 2.13-1 6-1zM6 7.26C7.53 7.83 9.64 8 12 8s4.47-0.17 6-0.74V10c0 0.88-2.13 2-6 2s-6-1.12-6-2V7.26zm0 5C7.53 12.83 9.64 13 12 13s4.47-0.17 6-0.74V15c0 0.88-2.13 2-6 2s-6-1.12-6-2v-2.74zM12 20c-3.87 0-6-1.12-6-2v-2.74C7.53 15.83 9.64 16 12 16s4.47-0.17 6-0.74V18c0 0.88-2.13 2-6 2z",
|
|
3269
|
+
// Horizontal arrows/bars
|
|
3270
|
+
queue: "M2 7h14l-4-3.5M2 12h18l-4-3.5M2 17h14l-4-3.5",
|
|
3271
|
+
// Lightning bolt
|
|
3272
|
+
cache: "M13 2L3 14h7l-2 8 10-12h-7z",
|
|
3273
|
+
// Branching arrows
|
|
3274
|
+
loadbalancer: "M12 2v6m0 0l-6 6m6-6l6 6m-6-6v0M6 14v4h4m4 0h4v-4M12 8a2 2 0 100-4 2 2 0 000 4z",
|
|
3275
|
+
// Lambda symbol
|
|
3276
|
+
function: "M7 4l5 16M12 4l5 16M5 10h14M5 14h14",
|
|
3277
|
+
// Disk/bucket
|
|
3278
|
+
storage: "M4 6a8 3 0 0116 0v12a8 3 0 01-16 0V6zm0 0a8 3 0 0016 0",
|
|
3279
|
+
// Gateway arch
|
|
3280
|
+
gateway: "M3 21V8a9 9 0 0118 0v13M7 21v-8a5 5 0 0110 0v8M11 3v2m-4 1l1 1m8-1l-1 1",
|
|
3281
|
+
// Person silhouette
|
|
3282
|
+
user: "M12 4a4 4 0 110 8 4 4 0 010-8zm0 10c-4.42 0-8 1.79-8 4v2h16v-2c0-2.21-3.58-4-8-4z",
|
|
3283
|
+
// Cloud shape
|
|
3284
|
+
cloud: "M19.35 10.04A7.49 7.49 0 0012 4C9.11 4 6.6 5.64 5.35 8.04A5.994 5.994 0 000 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z",
|
|
3285
|
+
// Box with lid
|
|
3286
|
+
container: "M2 8l10-5 10 5v10l-10 5-10-5V8zm10-5v20M2 8l10 5 10-5",
|
|
3287
|
+
// Connected nodes
|
|
3288
|
+
network: "M12 2a2 2 0 110 4 2 2 0 010-4zM4 10a2 2 0 110 4 2 2 0 010-4zM20 10a2 2 0 110 4 2 2 0 010-4zM12 18a2 2 0 110 4 2 2 0 010-4zM12 6v12M4 12h16M6 11l5-5M18 11l-5-5M6 13l5 5M18 13l-5 5"
|
|
3289
|
+
};
|
|
3290
|
+
function renderIcon(g, iconName, x, y, size = 20) {
|
|
3291
|
+
const d = ICON_PATHS[iconName];
|
|
3292
|
+
if (!d) return;
|
|
3293
|
+
const iconG = g.append("g").attr("transform", `translate(${x - size / 2}, ${y - size / 2}) scale(${size / 24})`);
|
|
3294
|
+
iconG.append("path").attr("d", d).attr("fill", "none").attr("stroke", "var(--glyph-icon-stroke, #fff)").attr("stroke-width", "var(--glyph-icon-stroke-width, 1.5)").attr("stroke-linecap", "round").attr("stroke-linejoin", "round");
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
// src/architecture/render.ts
|
|
3298
|
+
var NODE_PALETTE = [
|
|
3299
|
+
"#00d4aa",
|
|
3300
|
+
"#b44dff",
|
|
3301
|
+
"#22c55e",
|
|
3302
|
+
"#e040fb",
|
|
3303
|
+
"#00e5ff",
|
|
3304
|
+
"#84cc16",
|
|
3305
|
+
"#f472b6",
|
|
3306
|
+
"#fb923c",
|
|
3307
|
+
"#818cf8",
|
|
3308
|
+
"#38bdf8"
|
|
3309
|
+
];
|
|
3310
|
+
function zoneBackground(depth) {
|
|
3311
|
+
const alphas = [0.06, 0.1, 0.14, 0.18];
|
|
3312
|
+
const alpha = alphas[Math.min(depth, alphas.length - 1)] ?? 0.18;
|
|
3313
|
+
return `rgba(0,212,170,${alpha})`;
|
|
3314
|
+
}
|
|
3315
|
+
function getThemeVar3(container, varName, fallback) {
|
|
3316
|
+
return getComputedStyle(container).getPropertyValue(varName).trim() || fallback;
|
|
3317
|
+
}
|
|
3318
|
+
var ARROW_MARKER_ID3 = "glyph-arch-arrowhead";
|
|
3319
|
+
function renderArchitecture(svgElement, layout) {
|
|
3320
|
+
const svg = d32__namespace.select(svgElement);
|
|
3321
|
+
svg.selectAll("*").remove();
|
|
3322
|
+
const width = Math.max(layout.width, 200);
|
|
3323
|
+
const height = Math.max(layout.height, 200);
|
|
3324
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
3325
|
+
const defs = svg.append("defs");
|
|
3326
|
+
defs.append("marker").attr("id", ARROW_MARKER_ID3).attr("viewBox", "0 0 10 10").attr("refX", 10).attr("refY", 5).attr("markerWidth", 8).attr("markerHeight", 8).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 Z").attr("fill", "var(--glyph-edge-color, #6b7a94)");
|
|
3327
|
+
const container = svgElement.parentElement ?? svgElement;
|
|
3328
|
+
const nodeRadius = getThemeVar3(container, "--glyph-node-radius", "3");
|
|
3329
|
+
const nodeStrokeWidth = getThemeVar3(container, "--glyph-node-stroke-width", "1.5");
|
|
3330
|
+
const nodeFillOpacity = getThemeVar3(container, "--glyph-node-fill-opacity", "0.85");
|
|
3331
|
+
const root = svg.append("g").attr("class", "glyph-architecture-root");
|
|
3332
|
+
const zoomBehavior = d32__namespace.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
|
|
3333
|
+
root.attr("transform", event.transform.toString());
|
|
3334
|
+
});
|
|
3335
|
+
svg.call(zoomBehavior);
|
|
3336
|
+
const sortedZones = [...layout.zones].sort((a, b) => a.depth - b.depth);
|
|
3337
|
+
const zoneGroup = root.append("g").attr("class", "glyph-architecture-zones");
|
|
3338
|
+
for (const zone of sortedZones) {
|
|
3339
|
+
const zoneG = zoneGroup.append("g").attr("class", "glyph-architecture-zone");
|
|
3340
|
+
zoneG.append("rect").attr("x", zone.x).attr("y", zone.y).attr("width", zone.width).attr("height", zone.height).attr("rx", nodeRadius).attr("ry", nodeRadius).attr("fill", zoneBackground(zone.depth)).attr("stroke", "var(--glyph-accent-muted, #1a4a3a)").attr("stroke-width", 1).attr("stroke-dasharray", "6,3");
|
|
3341
|
+
zoneG.append("text").attr("x", zone.x + 10).attr("y", zone.y + 18).attr("font-size", "12px").attr("font-weight", "bold").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-text-muted, #7a8599)").text(zone.label);
|
|
3342
|
+
}
|
|
3343
|
+
const edgeGroup = root.append("g").attr("class", "glyph-architecture-edges");
|
|
3344
|
+
for (const edge of layout.edges) {
|
|
3345
|
+
if (edge.points.length === 0) continue;
|
|
3346
|
+
const edgeG = edgeGroup.append("g").attr("class", "glyph-architecture-edge");
|
|
3347
|
+
const lineGen = d32__namespace.line().x((d) => d.x).y((d) => d.y);
|
|
3348
|
+
const strokeWidth = edge.type === "data" ? 2.5 : 1.5;
|
|
3349
|
+
const dashArray = edge.type === "async" ? "5,5" : null;
|
|
3350
|
+
edgeG.append("path").attr("d", lineGen(edge.points) ?? "").attr("fill", "none").attr("stroke", edge.style?.["stroke"] ?? "var(--glyph-edge-color, #6b7a94)").attr("stroke-width", edge.style?.["stroke-width"] ?? String(strokeWidth)).attr("marker-end", `url(#${ARROW_MARKER_ID3})`).attr("stroke-dasharray", dashArray);
|
|
3351
|
+
if (edge.label && edge.points.length > 1) {
|
|
3352
|
+
let totalLen = 0;
|
|
3353
|
+
const segments = [];
|
|
3354
|
+
for (let i = 1; i < edge.points.length; i++) {
|
|
3355
|
+
const prev = edge.points[i - 1];
|
|
3356
|
+
const curr = edge.points[i];
|
|
3357
|
+
if (prev && curr) {
|
|
3358
|
+
const dx = curr.x - prev.x;
|
|
3359
|
+
const dy = curr.y - prev.y;
|
|
3360
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
3361
|
+
segments.push(len);
|
|
3362
|
+
totalLen += len;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
let remaining = totalLen / 2;
|
|
3366
|
+
let labelX = edge.points[0]?.x ?? 0;
|
|
3367
|
+
let labelY = edge.points[0]?.y ?? 0;
|
|
3368
|
+
for (let i = 0; i < segments.length; i++) {
|
|
3369
|
+
const segLen = segments[i] ?? 0;
|
|
3370
|
+
const prev = edge.points[i];
|
|
3371
|
+
const curr = edge.points[i + 1];
|
|
3372
|
+
if (prev && curr) {
|
|
3373
|
+
if (remaining <= segLen && segLen > 0) {
|
|
3374
|
+
const t = remaining / segLen;
|
|
3375
|
+
labelX = prev.x + t * (curr.x - prev.x);
|
|
3376
|
+
labelY = prev.y + t * (curr.y - prev.y);
|
|
3377
|
+
break;
|
|
3378
|
+
}
|
|
3379
|
+
remaining -= segLen;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
edgeG.append("text").attr("x", labelX).attr("y", labelY - 8).attr("text-anchor", "middle").attr("font-size", "11px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-text-muted, #7a8599)").text(edge.label);
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
const nodeGroup = root.append("g").attr("class", "glyph-architecture-nodes");
|
|
3386
|
+
for (let nodeIdx = 0; nodeIdx < layout.nodes.length; nodeIdx++) {
|
|
3387
|
+
const node = layout.nodes[nodeIdx];
|
|
3388
|
+
if (!node) continue;
|
|
3389
|
+
const nodeG = nodeGroup.append("g").attr("class", "glyph-architecture-node");
|
|
3390
|
+
const color3 = NODE_PALETTE[nodeIdx % NODE_PALETTE.length] ?? "#00d4aa";
|
|
3391
|
+
const defaultStroke = d32__namespace.color(color3)?.darker(0.5)?.toString() ?? "var(--glyph-edge-color, #6b7a94)";
|
|
3392
|
+
nodeG.append("rect").attr("x", node.x).attr("y", node.y).attr("width", node.width).attr("height", node.height).attr("rx", nodeRadius).attr("ry", nodeRadius).attr("fill", color3).attr("stroke", defaultStroke).attr("stroke-width", nodeStrokeWidth).attr("opacity", nodeFillOpacity);
|
|
3393
|
+
if (node.icon) {
|
|
3394
|
+
renderIcon(nodeG, node.icon, node.x + node.width / 2, node.y + 20, 18);
|
|
3395
|
+
nodeG.append("text").attr("x", node.x + node.width / 2).attr("y", node.y + node.height - 10).attr("text-anchor", "middle").attr("font-size", "11px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-node-label-color, #fff)").attr("pointer-events", "none").text(node.label);
|
|
3396
|
+
} else {
|
|
3397
|
+
nodeG.append("text").attr("x", node.x + node.width / 2).attr("y", node.y + node.height / 2).attr("dy", "0.35em").attr("text-anchor", "middle").attr("font-size", "13px").attr("font-family", "Inter, system-ui, sans-serif").attr("fill", "var(--glyph-node-label-color, #fff)").attr("pointer-events", "none").text(node.label);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
function Architecture({
|
|
3402
|
+
data,
|
|
3403
|
+
container
|
|
3404
|
+
}) {
|
|
3405
|
+
const svgRef = react.useRef(null);
|
|
3406
|
+
const [layout, setLayout] = react.useState(null);
|
|
3407
|
+
react.useEffect(() => {
|
|
3408
|
+
let cancelled = false;
|
|
3409
|
+
computeArchitectureLayout(data).then((result) => {
|
|
3410
|
+
if (!cancelled) setLayout(result);
|
|
3411
|
+
});
|
|
3412
|
+
return () => {
|
|
3413
|
+
cancelled = true;
|
|
3414
|
+
};
|
|
3415
|
+
}, [data]);
|
|
3416
|
+
react.useEffect(() => {
|
|
3417
|
+
if (!svgRef.current || !layout) return;
|
|
3418
|
+
renderArchitecture(svgRef.current, layout);
|
|
3419
|
+
}, [layout]);
|
|
3420
|
+
const nodeCount = countLeafNodes(data.children);
|
|
3421
|
+
const edgeCount = data.edges.length;
|
|
3422
|
+
const ariaLabel = data.title ? `${data.title}: architecture diagram with ${nodeCount} nodes and ${edgeCount} connections` : `Architecture diagram with ${nodeCount} nodes and ${edgeCount} connections`;
|
|
3423
|
+
const flatNodes = flattenNodes(data.children);
|
|
3424
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-architecture-container", children: [
|
|
3425
|
+
!layout && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3426
|
+
"div",
|
|
3427
|
+
{
|
|
3428
|
+
style: {
|
|
3429
|
+
padding: "2rem",
|
|
3430
|
+
textAlign: "center",
|
|
3431
|
+
color: "var(--glyph-text-muted, #7a8599)",
|
|
3432
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
3433
|
+
fontSize: "13px"
|
|
3434
|
+
},
|
|
3435
|
+
children: "Computing layout..."
|
|
3436
|
+
}
|
|
3437
|
+
),
|
|
3438
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3439
|
+
"svg",
|
|
3440
|
+
{
|
|
3441
|
+
ref: svgRef,
|
|
3442
|
+
role: "img",
|
|
3443
|
+
"aria-label": ariaLabel,
|
|
3444
|
+
width: "100%",
|
|
3445
|
+
height: "100%",
|
|
3446
|
+
style: {
|
|
3447
|
+
minHeight: container.tier === "compact" ? 200 : 300,
|
|
3448
|
+
maxHeight: container.tier === "compact" ? 500 : 700,
|
|
3449
|
+
display: layout ? "block" : "none"
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
),
|
|
3453
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Architecture data", style: SR_ONLY_STYLE5, children: [
|
|
3454
|
+
/* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Architecture nodes and connections" }),
|
|
3455
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
3456
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Node" }),
|
|
3457
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Zone" }),
|
|
3458
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Connections" })
|
|
3459
|
+
] }) }),
|
|
3460
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: flatNodes.map((node) => {
|
|
3461
|
+
const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
|
|
3462
|
+
const target = e.from === node.id ? e.to : e.from;
|
|
3463
|
+
const dir = e.from === node.id ? "->" : "<-";
|
|
3464
|
+
return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
|
|
3465
|
+
}).join(", ");
|
|
3466
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
3467
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.label }),
|
|
3468
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: node.zone ?? "" }),
|
|
3469
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: connections })
|
|
3470
|
+
] }, node.id);
|
|
3471
|
+
}) })
|
|
3472
|
+
] })
|
|
3473
|
+
] });
|
|
3474
|
+
}
|
|
3475
|
+
function flattenNodes(children, zone) {
|
|
3476
|
+
const result = [];
|
|
3477
|
+
for (const child of children) {
|
|
3478
|
+
if (child.type === "zone" && child.children) {
|
|
3479
|
+
result.push(...flattenNodes(child.children, child.label));
|
|
3480
|
+
} else {
|
|
3481
|
+
result.push({ id: child.id, label: child.label, zone });
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
return result;
|
|
3485
|
+
}
|
|
3486
|
+
function countLeafNodes(children) {
|
|
3487
|
+
let count = 0;
|
|
3488
|
+
for (const child of children) {
|
|
3489
|
+
if (child.type === "zone" && child.children) {
|
|
3490
|
+
count += countLeafNodes(child.children);
|
|
3491
|
+
} else {
|
|
3492
|
+
count++;
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
return count;
|
|
3496
|
+
}
|
|
3497
|
+
var SR_ONLY_STYLE5 = {
|
|
3498
|
+
position: "absolute",
|
|
3499
|
+
width: "1px",
|
|
3500
|
+
height: "1px",
|
|
3501
|
+
padding: 0,
|
|
3502
|
+
margin: "-1px",
|
|
3503
|
+
overflow: "hidden",
|
|
3504
|
+
clip: "rect(0, 0, 0, 0)",
|
|
3505
|
+
whiteSpace: "nowrap",
|
|
3506
|
+
border: 0
|
|
3507
|
+
};
|
|
3508
|
+
|
|
3509
|
+
// src/architecture/index.ts
|
|
3510
|
+
var architectureDefinition = {
|
|
3511
|
+
type: "ui:architecture",
|
|
3512
|
+
schema: schemas.architectureSchema,
|
|
3513
|
+
render: Architecture
|
|
3514
|
+
};
|
|
3515
|
+
var MAX_VISIBLE_DEPTH = 4;
|
|
3516
|
+
var NODE_RADIUS = 28;
|
|
3517
|
+
var ROOT_RADIUS = 34;
|
|
3518
|
+
var RADIAL_LEVEL_RADIUS = 130;
|
|
3519
|
+
var TREE_LEVEL_HEIGHT = 90;
|
|
3520
|
+
var TREE_NODE_HGAP = 140;
|
|
3521
|
+
var SVG_PADDING = 60;
|
|
3522
|
+
var FONT_SIZE = 12;
|
|
3523
|
+
var FONT_FAMILY = "Inter, system-ui, sans-serif";
|
|
3524
|
+
var BADGE_FONT_SIZE = 10;
|
|
3525
|
+
function countHiddenDescendants(node, currentDepth) {
|
|
3526
|
+
if (currentDepth >= MAX_VISIBLE_DEPTH) {
|
|
3527
|
+
return countAllDescendants(node);
|
|
3528
|
+
}
|
|
3529
|
+
let count = 0;
|
|
3530
|
+
for (const child of node.children ?? []) {
|
|
3531
|
+
count += countHiddenDescendants(child, currentDepth + 1);
|
|
3532
|
+
}
|
|
3533
|
+
return count;
|
|
3534
|
+
}
|
|
3535
|
+
function countAllDescendants(node) {
|
|
3536
|
+
let count = 1;
|
|
3537
|
+
for (const child of node.children ?? []) {
|
|
3538
|
+
count += countAllDescendants(child);
|
|
3539
|
+
}
|
|
3540
|
+
return count;
|
|
3541
|
+
}
|
|
3542
|
+
function layoutRadial(data) {
|
|
3543
|
+
const nodes = [];
|
|
3544
|
+
const cx = 0;
|
|
3545
|
+
const cy = 0;
|
|
3546
|
+
nodes.push({
|
|
3547
|
+
label: data.root,
|
|
3548
|
+
x: cx,
|
|
3549
|
+
y: cy,
|
|
3550
|
+
depth: 0,
|
|
3551
|
+
hiddenCount: 0
|
|
3552
|
+
});
|
|
3553
|
+
function placeChildren(children, parentX, parentY, depth, startAngle, endAngle) {
|
|
3554
|
+
if (depth > MAX_VISIBLE_DEPTH) return;
|
|
3555
|
+
const count = children.length;
|
|
3556
|
+
if (count === 0) return;
|
|
3557
|
+
const radius = RADIAL_LEVEL_RADIUS * depth;
|
|
3558
|
+
for (let i = 0; i < count; i++) {
|
|
3559
|
+
const child = children[i];
|
|
3560
|
+
if (!child) continue;
|
|
3561
|
+
const angle = count === 1 ? (startAngle + endAngle) / 2 : startAngle + (endAngle - startAngle) * i / (count - 1);
|
|
3562
|
+
const x = cx + radius * Math.cos(angle);
|
|
3563
|
+
const y = cy + radius * Math.sin(angle);
|
|
3564
|
+
const hidden = countHiddenDescendants(child, depth);
|
|
3565
|
+
nodes.push({
|
|
3566
|
+
label: child.label,
|
|
3567
|
+
x,
|
|
3568
|
+
y,
|
|
3569
|
+
depth,
|
|
3570
|
+
parentX,
|
|
3571
|
+
parentY,
|
|
3572
|
+
hiddenCount: hidden
|
|
3573
|
+
});
|
|
3574
|
+
const childChildren = child.children ?? [];
|
|
3575
|
+
if (childChildren.length > 0 && depth < MAX_VISIBLE_DEPTH) {
|
|
3576
|
+
const spreadAngle = Math.PI / Math.max(count, 2);
|
|
3577
|
+
placeChildren(
|
|
3578
|
+
childChildren,
|
|
3579
|
+
x,
|
|
3580
|
+
y,
|
|
3581
|
+
depth + 1,
|
|
3582
|
+
angle - spreadAngle / 2,
|
|
3583
|
+
angle + spreadAngle / 2
|
|
3584
|
+
);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
const topChildren = data.children;
|
|
3589
|
+
placeChildren(topChildren, cx, cy, 1, 0, 2 * Math.PI * (1 - 1 / Math.max(topChildren.length, 2)));
|
|
3590
|
+
let minX = 0;
|
|
3591
|
+
let maxX = 0;
|
|
3592
|
+
let minY = 0;
|
|
3593
|
+
let maxY = 0;
|
|
3594
|
+
for (const n of nodes) {
|
|
3595
|
+
if (n.x - ROOT_RADIUS < minX) minX = n.x - ROOT_RADIUS;
|
|
3596
|
+
if (n.x + ROOT_RADIUS > maxX) maxX = n.x + ROOT_RADIUS;
|
|
3597
|
+
if (n.y - ROOT_RADIUS < minY) minY = n.y - ROOT_RADIUS;
|
|
3598
|
+
if (n.y + ROOT_RADIUS > maxY) maxY = n.y + ROOT_RADIUS;
|
|
3599
|
+
}
|
|
3600
|
+
const offsetX = -minX + SVG_PADDING;
|
|
3601
|
+
const offsetY = -minY + SVG_PADDING;
|
|
3602
|
+
for (const n of nodes) {
|
|
3603
|
+
n.x += offsetX;
|
|
3604
|
+
n.y += offsetY;
|
|
3605
|
+
if (n.parentX !== void 0) n.parentX += offsetX;
|
|
3606
|
+
if (n.parentY !== void 0) n.parentY += offsetY;
|
|
3607
|
+
}
|
|
3608
|
+
return {
|
|
3609
|
+
nodes,
|
|
3610
|
+
width: maxX - minX + SVG_PADDING * 2,
|
|
3611
|
+
height: maxY - minY + SVG_PADDING * 2
|
|
3612
|
+
};
|
|
3613
|
+
}
|
|
3614
|
+
function layoutTree(data) {
|
|
3615
|
+
const nodes = [];
|
|
3616
|
+
function countLeaves(children, depth) {
|
|
3617
|
+
if (depth >= MAX_VISIBLE_DEPTH) return 1;
|
|
3618
|
+
let total = 0;
|
|
3619
|
+
for (const child of children) {
|
|
3620
|
+
const childChildren = child.children ?? [];
|
|
3621
|
+
if (childChildren.length === 0 || depth + 1 >= MAX_VISIBLE_DEPTH) {
|
|
3622
|
+
total += 1;
|
|
3623
|
+
} else {
|
|
3624
|
+
total += countLeaves(childChildren, depth + 1);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
return Math.max(total, 1);
|
|
3628
|
+
}
|
|
3629
|
+
const totalLeaves = Math.max(countLeaves(data.children, 1), 1);
|
|
3630
|
+
const totalWidth = totalLeaves * TREE_NODE_HGAP;
|
|
3631
|
+
const rootX = totalWidth / 2 + SVG_PADDING;
|
|
3632
|
+
const rootY = SVG_PADDING;
|
|
3633
|
+
nodes.push({
|
|
3634
|
+
label: data.root,
|
|
3635
|
+
x: rootX,
|
|
3636
|
+
y: rootY,
|
|
3637
|
+
depth: 0,
|
|
3638
|
+
hiddenCount: 0
|
|
3639
|
+
});
|
|
3640
|
+
function placeTreeChildren(children, parentX, parentY, depth, leftBound, rightBound) {
|
|
3641
|
+
if (depth > MAX_VISIBLE_DEPTH) return;
|
|
3642
|
+
const count = children.length;
|
|
3643
|
+
if (count === 0) return;
|
|
3644
|
+
const y = parentY + TREE_LEVEL_HEIGHT;
|
|
3645
|
+
const slotWidth = (rightBound - leftBound) / count;
|
|
3646
|
+
for (let i = 0; i < count; i++) {
|
|
3647
|
+
const child = children[i];
|
|
3648
|
+
if (!child) continue;
|
|
3649
|
+
const x = leftBound + slotWidth * (i + 0.5);
|
|
3650
|
+
const hidden = countHiddenDescendants(child, depth);
|
|
3651
|
+
nodes.push({
|
|
3652
|
+
label: child.label,
|
|
3653
|
+
x,
|
|
3654
|
+
y,
|
|
3655
|
+
depth,
|
|
3656
|
+
parentX,
|
|
3657
|
+
parentY,
|
|
3658
|
+
hiddenCount: hidden
|
|
3659
|
+
});
|
|
3660
|
+
const childChildren = child.children ?? [];
|
|
3661
|
+
if (childChildren.length > 0 && depth < MAX_VISIBLE_DEPTH) {
|
|
3662
|
+
placeTreeChildren(
|
|
3663
|
+
childChildren,
|
|
3664
|
+
x,
|
|
3665
|
+
y,
|
|
3666
|
+
depth + 1,
|
|
3667
|
+
leftBound + slotWidth * i,
|
|
3668
|
+
leftBound + slotWidth * (i + 1)
|
|
3669
|
+
);
|
|
3670
|
+
}
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
placeTreeChildren(data.children, rootX, rootY, 1, SVG_PADDING, totalWidth + SVG_PADDING);
|
|
3674
|
+
let maxY = rootY;
|
|
3675
|
+
for (const n of nodes) {
|
|
3676
|
+
if (n.y > maxY) maxY = n.y;
|
|
3677
|
+
}
|
|
3678
|
+
return {
|
|
3679
|
+
nodes,
|
|
3680
|
+
width: totalWidth + SVG_PADDING * 2,
|
|
3681
|
+
height: maxY + SVG_PADDING + NODE_RADIUS
|
|
3682
|
+
};
|
|
3683
|
+
}
|
|
3684
|
+
function renderAccessibleList(root, children) {
|
|
3685
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { style: SR_ONLY_STYLE6, role: "list", "aria-label": "Mind map structure", children: /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
3686
|
+
root,
|
|
3687
|
+
children.length > 0 && renderAccessibleChildren(children)
|
|
3688
|
+
] }) });
|
|
3689
|
+
}
|
|
3690
|
+
function renderAccessibleChildren(children) {
|
|
3691
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { children: children.map((child, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
3692
|
+
child.label,
|
|
3693
|
+
(child.children ?? []).length > 0 && renderAccessibleChildren(child.children ?? [])
|
|
3694
|
+
] }, i)) });
|
|
3695
|
+
}
|
|
3696
|
+
function nodeColor(depth) {
|
|
3697
|
+
if (depth === 0) return "var(--glyph-accent, #6c8aff)";
|
|
3698
|
+
if (depth === 1) return "var(--glyph-surface-raised, #162038)";
|
|
3699
|
+
return "var(--glyph-surface, #0f1526)";
|
|
3700
|
+
}
|
|
3701
|
+
function nodeStroke(depth) {
|
|
3702
|
+
if (depth === 0) return "var(--glyph-accent, #6c8aff)";
|
|
3703
|
+
return "var(--glyph-border-strong, #2a3550)";
|
|
3704
|
+
}
|
|
3705
|
+
function countAllNodes(children) {
|
|
3706
|
+
let count = 0;
|
|
3707
|
+
for (const child of children) {
|
|
3708
|
+
count += 1;
|
|
3709
|
+
count += countAllNodes(child.children ?? []);
|
|
3710
|
+
}
|
|
3711
|
+
return count;
|
|
3712
|
+
}
|
|
3713
|
+
function MindMap({ data, container }) {
|
|
3714
|
+
const isTree = data.layout === "tree";
|
|
3715
|
+
const { nodes, width, height } = isTree ? layoutTree(data) : layoutRadial(data);
|
|
3716
|
+
const totalNodes = 1 + countAllNodes(data.children);
|
|
3717
|
+
const ariaLabel = `Mind map: ${data.root} with ${String(totalNodes)} nodes`;
|
|
3718
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-mindmap-container", children: [
|
|
3719
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3720
|
+
"svg",
|
|
3721
|
+
{
|
|
3722
|
+
role: "img",
|
|
3723
|
+
"aria-label": ariaLabel,
|
|
3724
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
3725
|
+
width: "100%",
|
|
3726
|
+
style: {
|
|
3727
|
+
minHeight: container.tier === "compact" ? 150 : 200,
|
|
3728
|
+
maxHeight: container.tier === "compact" ? 500 : 800,
|
|
3729
|
+
display: "block"
|
|
3730
|
+
},
|
|
3731
|
+
children: [
|
|
3732
|
+
nodes.map((node, idx) => {
|
|
3733
|
+
if (node.parentX === void 0 || node.parentY === void 0) return null;
|
|
3734
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3735
|
+
"line",
|
|
3736
|
+
{
|
|
3737
|
+
x1: node.parentX,
|
|
3738
|
+
y1: node.parentY,
|
|
3739
|
+
x2: node.x,
|
|
3740
|
+
y2: node.y,
|
|
3741
|
+
stroke: "var(--glyph-border, #1a2035)",
|
|
3742
|
+
strokeWidth: 1.5
|
|
3743
|
+
},
|
|
3744
|
+
`edge-${idx}`
|
|
3745
|
+
);
|
|
3746
|
+
}),
|
|
3747
|
+
nodes.map((node, idx) => {
|
|
3748
|
+
const r = node.depth === 0 ? ROOT_RADIUS : NODE_RADIUS;
|
|
3749
|
+
const isRoot = node.depth === 0;
|
|
3750
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
3751
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3752
|
+
"circle",
|
|
3753
|
+
{
|
|
3754
|
+
cx: node.x,
|
|
3755
|
+
cy: node.y,
|
|
3756
|
+
r,
|
|
3757
|
+
fill: nodeColor(node.depth),
|
|
3758
|
+
stroke: nodeStroke(node.depth),
|
|
3759
|
+
strokeWidth: isRoot ? 2 : 1.5
|
|
3760
|
+
}
|
|
3761
|
+
),
|
|
3762
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3763
|
+
"text",
|
|
3764
|
+
{
|
|
3765
|
+
x: node.x,
|
|
3766
|
+
y: node.y,
|
|
3767
|
+
dy: "0.35em",
|
|
3768
|
+
textAnchor: "middle",
|
|
3769
|
+
fontSize: isRoot ? FONT_SIZE + 1 : FONT_SIZE,
|
|
3770
|
+
fontFamily: FONT_FAMILY,
|
|
3771
|
+
fontWeight: isRoot ? 700 : 500,
|
|
3772
|
+
fill: isRoot ? "var(--glyph-text-on-accent, #ffffff)" : "var(--glyph-text, #d4dae3)",
|
|
3773
|
+
children: node.label.length > 12 ? `${node.label.slice(0, 11)}...` : node.label
|
|
3774
|
+
}
|
|
3775
|
+
),
|
|
3776
|
+
node.hiddenCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
3777
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3778
|
+
"circle",
|
|
3779
|
+
{
|
|
3780
|
+
cx: node.x + r * 0.7,
|
|
3781
|
+
cy: node.y - r * 0.7,
|
|
3782
|
+
r: 10,
|
|
3783
|
+
fill: "var(--glyph-accent, #6c8aff)"
|
|
3784
|
+
}
|
|
3785
|
+
),
|
|
3786
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3787
|
+
"text",
|
|
3788
|
+
{
|
|
3789
|
+
x: node.x + r * 0.7,
|
|
3790
|
+
y: node.y - r * 0.7,
|
|
3791
|
+
dy: "0.35em",
|
|
3792
|
+
textAnchor: "middle",
|
|
3793
|
+
fontSize: BADGE_FONT_SIZE,
|
|
3794
|
+
fontFamily: FONT_FAMILY,
|
|
3795
|
+
fontWeight: 600,
|
|
3796
|
+
fill: "var(--glyph-text-on-accent, #ffffff)",
|
|
3797
|
+
children: [
|
|
3798
|
+
"+",
|
|
3799
|
+
node.hiddenCount
|
|
3800
|
+
]
|
|
3801
|
+
}
|
|
3802
|
+
)
|
|
3803
|
+
] })
|
|
3804
|
+
] }, `node-${idx}`);
|
|
3805
|
+
})
|
|
3806
|
+
]
|
|
3807
|
+
}
|
|
3808
|
+
),
|
|
3809
|
+
renderAccessibleList(data.root, data.children)
|
|
3810
|
+
] });
|
|
3811
|
+
}
|
|
3812
|
+
var SR_ONLY_STYLE6 = {
|
|
3813
|
+
position: "absolute",
|
|
3814
|
+
width: "1px",
|
|
3815
|
+
height: "1px",
|
|
3816
|
+
padding: 0,
|
|
3817
|
+
margin: "-1px",
|
|
3818
|
+
overflow: "hidden",
|
|
3819
|
+
clip: "rect(0, 0, 0, 0)",
|
|
3820
|
+
whiteSpace: "nowrap",
|
|
3821
|
+
border: 0
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3824
|
+
// src/mindmap/index.ts
|
|
3825
|
+
var mindMapDefinition = {
|
|
3826
|
+
type: "ui:mindmap",
|
|
3827
|
+
schema: schemas.mindmapSchema,
|
|
3828
|
+
render: MindMap
|
|
3829
|
+
};
|
|
3830
|
+
function renderLatex(expression) {
|
|
3831
|
+
try {
|
|
3832
|
+
const html = katex__default.default.renderToString(expression, {
|
|
3833
|
+
throwOnError: false,
|
|
3834
|
+
displayMode: true
|
|
3835
|
+
});
|
|
3836
|
+
return { html, error: false };
|
|
3837
|
+
} catch {
|
|
3838
|
+
return { html: "", error: true };
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
var containerStyle = {
|
|
3842
|
+
display: "flex",
|
|
3843
|
+
flexDirection: "column",
|
|
3844
|
+
alignItems: "center",
|
|
3845
|
+
gap: "0.5rem",
|
|
3846
|
+
padding: "1rem",
|
|
3847
|
+
fontFamily: "Inter, system-ui, sans-serif"
|
|
3848
|
+
};
|
|
3849
|
+
var labelStyle2 = {
|
|
3850
|
+
fontSize: "0.875rem",
|
|
3851
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
3852
|
+
marginTop: "0.25rem"
|
|
3853
|
+
};
|
|
3854
|
+
var stepsContainerStyle = {
|
|
3855
|
+
display: "flex",
|
|
3856
|
+
flexDirection: "column",
|
|
3857
|
+
gap: "0.75rem",
|
|
3858
|
+
width: "100%"
|
|
3859
|
+
};
|
|
3860
|
+
var stepRowStyle = {
|
|
3861
|
+
display: "flex",
|
|
3862
|
+
alignItems: "center",
|
|
3863
|
+
justifyContent: "center",
|
|
3864
|
+
gap: "1.5rem"
|
|
3865
|
+
};
|
|
3866
|
+
var annotationStyle = {
|
|
3867
|
+
fontSize: "0.875rem",
|
|
3868
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
3869
|
+
fontStyle: "italic",
|
|
3870
|
+
minWidth: "120px"
|
|
3871
|
+
};
|
|
3872
|
+
var fallbackStyle = {
|
|
3873
|
+
fontFamily: '"Fira Code", "Cascadia Code", Consolas, monospace',
|
|
3874
|
+
fontSize: "0.875rem",
|
|
3875
|
+
padding: "0.5rem 1rem",
|
|
3876
|
+
borderRadius: "4px",
|
|
3877
|
+
background: "var(--glyph-surface-raised, #162038)",
|
|
3878
|
+
color: "var(--glyph-text, #d4dae3)",
|
|
3879
|
+
border: "1px solid var(--glyph-border, #1a2035)"
|
|
3880
|
+
};
|
|
3881
|
+
function Equation({ data }) {
|
|
3882
|
+
if (data.expression !== void 0) {
|
|
3883
|
+
const { html, error } = renderLatex(data.expression);
|
|
3884
|
+
const ariaLabel = `Equation: ${data.expression}`;
|
|
3885
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyle, role: "math", "aria-label": ariaLabel, children: [
|
|
3886
|
+
error || html === "" ? /* @__PURE__ */ jsxRuntime.jsx("code", { style: fallbackStyle, children: data.expression }) : /* @__PURE__ */ jsxRuntime.jsx("span", { dangerouslySetInnerHTML: { __html: html } }),
|
|
3887
|
+
data.label !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: labelStyle2, children: data.label })
|
|
3888
|
+
] });
|
|
3889
|
+
}
|
|
3890
|
+
if (data.steps !== void 0 && data.steps.length > 0) {
|
|
3891
|
+
const allExpressions = data.steps.map((s) => s.expression).join("; ");
|
|
3892
|
+
const ariaLabel = `Equation steps: ${allExpressions}`;
|
|
3893
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyle, role: "math", "aria-label": ariaLabel, children: [
|
|
3894
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: stepsContainerStyle, children: data.steps.map((step, idx) => {
|
|
3895
|
+
const { html, error } = renderLatex(step.expression);
|
|
3896
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: stepRowStyle, children: [
|
|
3897
|
+
error || html === "" ? /* @__PURE__ */ jsxRuntime.jsx("code", { style: fallbackStyle, children: step.expression }) : /* @__PURE__ */ jsxRuntime.jsx("span", { dangerouslySetInnerHTML: { __html: html } }),
|
|
3898
|
+
step.annotation !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { style: annotationStyle, children: step.annotation })
|
|
3899
|
+
] }, idx);
|
|
3900
|
+
}) }),
|
|
3901
|
+
data.label !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: labelStyle2, children: data.label })
|
|
3902
|
+
] });
|
|
3903
|
+
}
|
|
3904
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: containerStyle, role: "math", "aria-label": "Empty equation", children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "var(--glyph-text-muted, #6b7a94)" }, children: "No equation provided" }) });
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
// src/equation/index.ts
|
|
3908
|
+
var equationDefinition = {
|
|
3909
|
+
type: "ui:equation",
|
|
3910
|
+
schema: schemas.equationSchema,
|
|
3911
|
+
render: Equation
|
|
3912
|
+
};
|
|
3913
|
+
|
|
3914
|
+
// src/quiz/styles.ts
|
|
3915
|
+
var containerStyle2 = {
|
|
3916
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
3917
|
+
color: "var(--glyph-text, #1a2035)",
|
|
3918
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
3919
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
3920
|
+
overflow: "hidden"
|
|
3921
|
+
};
|
|
3922
|
+
var headerStyle = {
|
|
3923
|
+
fontWeight: 700,
|
|
3924
|
+
fontSize: "1.125rem",
|
|
3925
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
3926
|
+
borderBottom: "1px solid var(--glyph-border, #d0d8e4)",
|
|
3927
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
3928
|
+
};
|
|
3929
|
+
function questionGroupStyle(isLast) {
|
|
3930
|
+
return {
|
|
3931
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
3932
|
+
borderBottom: isLast ? "none" : "1px solid var(--glyph-border, #d0d8e4)"
|
|
3933
|
+
};
|
|
3934
|
+
}
|
|
3935
|
+
var questionTextStyle = {
|
|
3936
|
+
fontWeight: 600,
|
|
3937
|
+
fontSize: "0.9375rem",
|
|
3938
|
+
marginBottom: "0.75rem"
|
|
3939
|
+
};
|
|
3940
|
+
function optionLabelStyle(isSelected, submitted, isCorrectOption, isIncorrectSelection) {
|
|
3941
|
+
return {
|
|
3942
|
+
display: "flex",
|
|
3943
|
+
alignItems: "center",
|
|
3944
|
+
gap: "0.5rem",
|
|
3945
|
+
padding: "0.5rem 0.75rem",
|
|
3946
|
+
marginBottom: "0.375rem",
|
|
3947
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
3948
|
+
cursor: submitted ? "default" : "pointer",
|
|
3949
|
+
background: submitted ? isCorrectOption ? "var(--glyph-quiz-correct-bg, #dcfce7)" : isIncorrectSelection ? "var(--glyph-quiz-incorrect-bg, #fee2e2)" : "transparent" : isSelected ? "var(--glyph-surface, #e8ecf3)" : "transparent",
|
|
3950
|
+
border: "1px solid",
|
|
3951
|
+
borderColor: submitted ? isCorrectOption ? "var(--glyph-quiz-correct, #16a34a)" : isIncorrectSelection ? "var(--glyph-quiz-incorrect, #dc2626)" : "var(--glyph-border, #d0d8e4)" : isSelected ? "var(--glyph-border, #d0d8e4)" : "transparent",
|
|
3952
|
+
fontSize: "0.875rem",
|
|
3953
|
+
lineHeight: 1.6
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
function buttonStyle(disabled) {
|
|
3957
|
+
return {
|
|
3958
|
+
marginTop: "0.75rem",
|
|
3959
|
+
padding: "0.5rem 1.25rem",
|
|
3960
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
3961
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
3962
|
+
background: disabled ? "var(--glyph-surface, #e8ecf3)" : "var(--glyph-surface, #e8ecf3)",
|
|
3963
|
+
color: disabled ? "var(--glyph-border, #d0d8e4)" : "var(--glyph-text, #1a2035)",
|
|
3964
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
3965
|
+
fontWeight: 600,
|
|
3966
|
+
fontSize: "0.875rem"
|
|
3967
|
+
};
|
|
3968
|
+
}
|
|
3969
|
+
function feedbackStyle(correct) {
|
|
3970
|
+
return {
|
|
3971
|
+
marginTop: "0.75rem",
|
|
3972
|
+
padding: "0.5rem 0.75rem",
|
|
3973
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
3974
|
+
background: correct ? "var(--glyph-quiz-correct-bg, #dcfce7)" : "var(--glyph-quiz-incorrect-bg, #fee2e2)",
|
|
3975
|
+
color: correct ? "var(--glyph-quiz-correct, #16a34a)" : "var(--glyph-quiz-incorrect, #dc2626)",
|
|
3976
|
+
fontWeight: 600,
|
|
3977
|
+
fontSize: "0.875rem"
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
var explanationStyle = {
|
|
3981
|
+
marginTop: "0.5rem",
|
|
3982
|
+
padding: "0.5rem 0.75rem",
|
|
3983
|
+
fontSize: "0.8125rem",
|
|
3984
|
+
lineHeight: 1.6,
|
|
3985
|
+
color: "var(--glyph-text, #1a2035)",
|
|
3986
|
+
background: "var(--glyph-surface, #e8ecf3)",
|
|
3987
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)"
|
|
3988
|
+
};
|
|
3989
|
+
var scoreStyle = {
|
|
3990
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
3991
|
+
borderTop: "1px solid var(--glyph-border, #d0d8e4)",
|
|
3992
|
+
fontWeight: 700,
|
|
3993
|
+
fontSize: "1rem",
|
|
3994
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
3995
|
+
};
|
|
3996
|
+
function isCorrect(question, selected) {
|
|
3997
|
+
if (selected === null) return false;
|
|
3998
|
+
switch (question.type) {
|
|
3999
|
+
case "multiple-choice":
|
|
4000
|
+
return selected === question.answer;
|
|
4001
|
+
case "true-false":
|
|
4002
|
+
return selected === question.answer;
|
|
4003
|
+
case "multi-select": {
|
|
4004
|
+
if (!Array.isArray(selected)) return false;
|
|
4005
|
+
const sorted = [...selected].sort();
|
|
4006
|
+
const expected = [...question.answer].sort();
|
|
4007
|
+
return sorted.length === expected.length && sorted.every((v, i) => v === expected[i]);
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
function Quiz({ data, block }) {
|
|
4012
|
+
const { questions, showScore = true, title } = data;
|
|
4013
|
+
const baseId = `glyph-quiz-${block.id}`;
|
|
4014
|
+
const [states, setStates] = react.useState(
|
|
4015
|
+
() => questions.map((q) => ({
|
|
4016
|
+
selected: q.type === "multi-select" ? [] : null,
|
|
4017
|
+
submitted: false
|
|
4018
|
+
}))
|
|
4019
|
+
);
|
|
4020
|
+
const updateState = (index, patch) => {
|
|
4021
|
+
setStates((prev) => prev.map((s, i) => i === index ? { ...s, ...patch } : s));
|
|
4022
|
+
};
|
|
4023
|
+
const score = states.reduce((acc, s, i) => {
|
|
4024
|
+
const q = questions[i];
|
|
4025
|
+
if (!q || !s.submitted) return acc;
|
|
4026
|
+
return acc + (isCorrect(q, s.selected) ? 1 : 0);
|
|
4027
|
+
}, 0);
|
|
4028
|
+
const submittedCount = states.filter((s) => s.submitted).length;
|
|
4029
|
+
function renderMultipleChoice(question, qIndex, state) {
|
|
4030
|
+
const selected = typeof state.selected === "number" ? state.selected : null;
|
|
4031
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { role: "radiogroup", "aria-label": question.question, children: question.options.map((option, oIndex) => {
|
|
4032
|
+
const isSelected = selected === oIndex;
|
|
4033
|
+
const isCorrectOption = state.submitted && oIndex === question.answer;
|
|
4034
|
+
const isIncorrectSelection = state.submitted && isSelected && oIndex !== question.answer;
|
|
4035
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4036
|
+
"label",
|
|
4037
|
+
{
|
|
4038
|
+
style: optionLabelStyle(
|
|
4039
|
+
isSelected,
|
|
4040
|
+
state.submitted,
|
|
4041
|
+
isCorrectOption,
|
|
4042
|
+
isIncorrectSelection
|
|
4043
|
+
),
|
|
4044
|
+
children: [
|
|
4045
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4046
|
+
"input",
|
|
4047
|
+
{
|
|
4048
|
+
type: "radio",
|
|
4049
|
+
role: "radio",
|
|
4050
|
+
name: `${baseId}-q${String(qIndex)}`,
|
|
4051
|
+
checked: isSelected,
|
|
4052
|
+
disabled: state.submitted,
|
|
4053
|
+
onChange: () => updateState(qIndex, { selected: oIndex }),
|
|
4054
|
+
"aria-checked": isSelected
|
|
4055
|
+
}
|
|
4056
|
+
),
|
|
4057
|
+
option
|
|
4058
|
+
]
|
|
4059
|
+
},
|
|
4060
|
+
oIndex
|
|
4061
|
+
);
|
|
4062
|
+
}) });
|
|
4063
|
+
}
|
|
4064
|
+
function renderTrueFalse(question, qIndex, state) {
|
|
4065
|
+
const selected = typeof state.selected === "boolean" ? state.selected : null;
|
|
4066
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { role: "radiogroup", "aria-label": question.question, children: [true, false].map((value) => {
|
|
4067
|
+
const isSelected = selected === value;
|
|
4068
|
+
const isCorrectOption = state.submitted && value === question.answer;
|
|
4069
|
+
const isIncorrectSelection = state.submitted && isSelected && value !== question.answer;
|
|
4070
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4071
|
+
"label",
|
|
4072
|
+
{
|
|
4073
|
+
style: optionLabelStyle(
|
|
4074
|
+
isSelected,
|
|
4075
|
+
state.submitted,
|
|
4076
|
+
isCorrectOption,
|
|
4077
|
+
isIncorrectSelection
|
|
4078
|
+
),
|
|
4079
|
+
children: [
|
|
4080
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4081
|
+
"input",
|
|
4082
|
+
{
|
|
4083
|
+
type: "radio",
|
|
4084
|
+
role: "radio",
|
|
4085
|
+
name: `${baseId}-q${String(qIndex)}`,
|
|
4086
|
+
checked: isSelected,
|
|
4087
|
+
disabled: state.submitted,
|
|
4088
|
+
onChange: () => updateState(qIndex, { selected: value }),
|
|
4089
|
+
"aria-checked": isSelected
|
|
4090
|
+
}
|
|
4091
|
+
),
|
|
4092
|
+
value ? "True" : "False"
|
|
4093
|
+
]
|
|
4094
|
+
},
|
|
4095
|
+
String(value)
|
|
4096
|
+
);
|
|
4097
|
+
}) });
|
|
4098
|
+
}
|
|
4099
|
+
function renderMultiSelect(question, qIndex, state) {
|
|
4100
|
+
const selected = Array.isArray(state.selected) ? state.selected : [];
|
|
4101
|
+
const toggleOption = (oIndex) => {
|
|
4102
|
+
const next = selected.includes(oIndex) ? selected.filter((v) => v !== oIndex) : [...selected, oIndex];
|
|
4103
|
+
updateState(qIndex, { selected: next });
|
|
4104
|
+
};
|
|
4105
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: question.options.map((option, oIndex) => {
|
|
4106
|
+
const isSelected = selected.includes(oIndex);
|
|
4107
|
+
const isCorrectOption = state.submitted && question.answer.includes(oIndex);
|
|
4108
|
+
const isIncorrectSelection = state.submitted && isSelected && !question.answer.includes(oIndex);
|
|
4109
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4110
|
+
"label",
|
|
4111
|
+
{
|
|
4112
|
+
style: optionLabelStyle(
|
|
4113
|
+
isSelected,
|
|
4114
|
+
state.submitted,
|
|
4115
|
+
isCorrectOption,
|
|
4116
|
+
isIncorrectSelection
|
|
4117
|
+
),
|
|
4118
|
+
children: [
|
|
4119
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4120
|
+
"input",
|
|
4121
|
+
{
|
|
4122
|
+
type: "checkbox",
|
|
4123
|
+
role: "checkbox",
|
|
4124
|
+
checked: isSelected,
|
|
4125
|
+
disabled: state.submitted,
|
|
4126
|
+
onChange: () => toggleOption(oIndex),
|
|
4127
|
+
"aria-checked": isSelected
|
|
4128
|
+
}
|
|
4129
|
+
),
|
|
4130
|
+
option
|
|
4131
|
+
]
|
|
4132
|
+
},
|
|
4133
|
+
oIndex
|
|
4134
|
+
);
|
|
4135
|
+
}) });
|
|
4136
|
+
}
|
|
4137
|
+
function renderQuestion(question, qIndex) {
|
|
4138
|
+
const state = states[qIndex] ?? { selected: null, submitted: false };
|
|
4139
|
+
const isLast = qIndex === questions.length - 1;
|
|
4140
|
+
const hasSelection = question.type === "multi-select" ? Array.isArray(state.selected) && state.selected.length > 0 : state.selected !== null;
|
|
4141
|
+
const correct = state.submitted ? isCorrect(question, state.selected) : false;
|
|
4142
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4143
|
+
"div",
|
|
4144
|
+
{
|
|
4145
|
+
role: "group",
|
|
4146
|
+
"aria-label": `Question ${String(qIndex + 1)}`,
|
|
4147
|
+
style: questionGroupStyle(isLast && !(showScore && submittedCount > 0)),
|
|
4148
|
+
children: [
|
|
4149
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: questionTextStyle, children: [
|
|
4150
|
+
questions.length > 1 ? `${String(qIndex + 1)}. ` : "",
|
|
4151
|
+
question.question
|
|
4152
|
+
] }),
|
|
4153
|
+
question.type === "multiple-choice" && renderMultipleChoice(question, qIndex, state),
|
|
4154
|
+
question.type === "true-false" && renderTrueFalse(question, qIndex, state),
|
|
4155
|
+
question.type === "multi-select" && renderMultiSelect(question, qIndex, state),
|
|
4156
|
+
!state.submitted && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4157
|
+
"button",
|
|
4158
|
+
{
|
|
4159
|
+
type: "button",
|
|
4160
|
+
disabled: !hasSelection,
|
|
4161
|
+
style: buttonStyle(!hasSelection),
|
|
4162
|
+
onClick: () => updateState(qIndex, { submitted: true }),
|
|
4163
|
+
children: "Submit"
|
|
4164
|
+
}
|
|
4165
|
+
),
|
|
4166
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { "aria-live": "polite", children: [
|
|
4167
|
+
state.submitted && /* @__PURE__ */ jsxRuntime.jsx("div", { style: feedbackStyle(correct), children: correct ? "Correct!" : "Incorrect" }),
|
|
4168
|
+
state.submitted && question.explanation && /* @__PURE__ */ jsxRuntime.jsx("div", { style: explanationStyle, children: question.explanation })
|
|
4169
|
+
] })
|
|
4170
|
+
]
|
|
4171
|
+
},
|
|
4172
|
+
qIndex
|
|
4173
|
+
);
|
|
4174
|
+
}
|
|
4175
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Quiz", style: containerStyle2, children: [
|
|
4176
|
+
title && /* @__PURE__ */ jsxRuntime.jsx("div", { style: headerStyle, children: title }),
|
|
4177
|
+
questions.map((q, i) => renderQuestion(q, i)),
|
|
4178
|
+
showScore && submittedCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: scoreStyle, children: [
|
|
4179
|
+
"Score: ",
|
|
4180
|
+
String(score),
|
|
4181
|
+
" / ",
|
|
4182
|
+
String(questions.length)
|
|
4183
|
+
] })
|
|
4184
|
+
] });
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
// src/quiz/index.ts
|
|
4188
|
+
var quizDefinition = {
|
|
4189
|
+
type: "ui:quiz",
|
|
4190
|
+
schema: schemas.quizSchema,
|
|
4191
|
+
render: Quiz
|
|
4192
|
+
};
|
|
4193
|
+
function getVariantStyle(variant) {
|
|
4194
|
+
switch (variant) {
|
|
4195
|
+
case "outlined":
|
|
4196
|
+
return {
|
|
4197
|
+
border: "2px solid var(--glyph-accent, #0a9d7c)"
|
|
4198
|
+
};
|
|
4199
|
+
case "elevated":
|
|
4200
|
+
return {
|
|
4201
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
4202
|
+
boxShadow: "var(--glyph-shadow-md, 0 4px 12px rgba(0,0,0,0.15))"
|
|
4203
|
+
};
|
|
4204
|
+
default:
|
|
4205
|
+
return {
|
|
4206
|
+
border: "1px solid var(--glyph-border, #d0d8e4)"
|
|
4207
|
+
};
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
function Card({ data, block, container }) {
|
|
4211
|
+
const { title, cards, variant = "default", columns } = data;
|
|
4212
|
+
const baseId = `glyph-card-${block.id}`;
|
|
4213
|
+
const authorCols = columns ?? Math.min(cards.length, 3);
|
|
4214
|
+
let colCount;
|
|
4215
|
+
switch (container.tier) {
|
|
4216
|
+
case "compact":
|
|
4217
|
+
colCount = 1;
|
|
4218
|
+
break;
|
|
4219
|
+
case "standard":
|
|
4220
|
+
colCount = Math.min(authorCols, 2);
|
|
4221
|
+
break;
|
|
4222
|
+
default:
|
|
4223
|
+
colCount = authorCols;
|
|
4224
|
+
}
|
|
4225
|
+
const containerStyle3 = {
|
|
4226
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
4227
|
+
color: "var(--glyph-text, #1a2035)"
|
|
4228
|
+
};
|
|
4229
|
+
const gapCount = colCount - 1;
|
|
4230
|
+
const gridStyle = {
|
|
4231
|
+
display: "grid",
|
|
4232
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(max(200px, calc((100% - ${String(gapCount)}rem) / ${String(colCount)})), 1fr))`,
|
|
4233
|
+
gap: "var(--glyph-spacing-md, 1rem)"
|
|
4234
|
+
};
|
|
4235
|
+
const cardBaseStyle = {
|
|
4236
|
+
...getVariantStyle(variant),
|
|
4237
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
4238
|
+
overflow: "hidden",
|
|
4239
|
+
background: "var(--glyph-surface, #e8ecf3)",
|
|
4240
|
+
display: "flex",
|
|
4241
|
+
flexDirection: "column"
|
|
4242
|
+
};
|
|
4243
|
+
const cardBodyStyle = {
|
|
4244
|
+
padding: "var(--glyph-spacing-md, 1rem)",
|
|
4245
|
+
flex: 1,
|
|
4246
|
+
display: "flex",
|
|
4247
|
+
flexDirection: "column"
|
|
4248
|
+
};
|
|
4249
|
+
const imageStyle = {
|
|
4250
|
+
width: "100%",
|
|
4251
|
+
aspectRatio: "16 / 9",
|
|
4252
|
+
objectFit: "cover",
|
|
4253
|
+
display: "block"
|
|
4254
|
+
};
|
|
4255
|
+
const iconStyle = {
|
|
4256
|
+
fontSize: "1.5rem",
|
|
4257
|
+
marginBottom: "var(--glyph-spacing-xs, 0.25rem)"
|
|
4258
|
+
};
|
|
4259
|
+
const titleStyle2 = {
|
|
4260
|
+
fontWeight: 700,
|
|
4261
|
+
fontSize: "1rem",
|
|
4262
|
+
color: "var(--glyph-heading, #0a0e1a)",
|
|
4263
|
+
margin: 0
|
|
4264
|
+
};
|
|
4265
|
+
const subtitleStyle = {
|
|
4266
|
+
fontSize: "0.8125rem",
|
|
4267
|
+
color: "var(--glyph-text-muted, #6b7a94)",
|
|
4268
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)"
|
|
4269
|
+
};
|
|
4270
|
+
const bodyStyle2 = {
|
|
4271
|
+
fontSize: "0.875rem",
|
|
4272
|
+
lineHeight: 1.6,
|
|
4273
|
+
marginTop: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4274
|
+
flex: 1
|
|
4275
|
+
};
|
|
4276
|
+
const actionsStyle = {
|
|
4277
|
+
display: "flex",
|
|
4278
|
+
gap: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4279
|
+
marginTop: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4280
|
+
flexWrap: "wrap"
|
|
4281
|
+
};
|
|
4282
|
+
const linkStyle = {
|
|
4283
|
+
fontSize: "0.8125rem",
|
|
4284
|
+
fontWeight: 600,
|
|
4285
|
+
color: "var(--glyph-link, #0a9d7c)",
|
|
4286
|
+
textDecoration: "none"
|
|
4287
|
+
};
|
|
4288
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Cards", style: containerStyle3, children: [
|
|
4289
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4290
|
+
"div",
|
|
4291
|
+
{
|
|
4292
|
+
style: {
|
|
4293
|
+
fontWeight: 700,
|
|
4294
|
+
fontSize: "1.125rem",
|
|
4295
|
+
marginBottom: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4296
|
+
color: "var(--glyph-heading, #0a0e1a)"
|
|
4297
|
+
},
|
|
4298
|
+
children: title
|
|
4299
|
+
}
|
|
4300
|
+
),
|
|
4301
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { role: "list", style: gridStyle, children: cards.map((card, i) => /* @__PURE__ */ jsxRuntime.jsxs("article", { role: "listitem", style: cardBaseStyle, children: [
|
|
4302
|
+
card.image && /* @__PURE__ */ jsxRuntime.jsx("img", { src: card.image, alt: card.title, loading: "lazy", style: imageStyle }),
|
|
4303
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: cardBodyStyle, children: [
|
|
4304
|
+
card.icon && /* @__PURE__ */ jsxRuntime.jsx("div", { style: iconStyle, children: card.icon }),
|
|
4305
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: titleStyle2, children: card.title }),
|
|
4306
|
+
card.subtitle && /* @__PURE__ */ jsxRuntime.jsx("div", { style: subtitleStyle, children: card.subtitle }),
|
|
4307
|
+
card.body && /* @__PURE__ */ jsxRuntime.jsx("div", { style: bodyStyle2, children: card.body }),
|
|
4308
|
+
card.actions && card.actions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: actionsStyle, children: card.actions.map((action, j) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4309
|
+
"a",
|
|
4310
|
+
{
|
|
4311
|
+
href: action.url,
|
|
4312
|
+
target: "_blank",
|
|
4313
|
+
rel: "noopener noreferrer",
|
|
4314
|
+
style: linkStyle,
|
|
4315
|
+
children: action.label
|
|
4316
|
+
},
|
|
4317
|
+
j
|
|
4318
|
+
)) })
|
|
4319
|
+
] })
|
|
4320
|
+
] }, i)) })
|
|
4321
|
+
] });
|
|
4322
|
+
}
|
|
4323
|
+
|
|
4324
|
+
// src/card/index.ts
|
|
4325
|
+
var cardDefinition = {
|
|
4326
|
+
type: "ui:card",
|
|
4327
|
+
schema: schemas.cardSchema,
|
|
4328
|
+
render: Card
|
|
4329
|
+
};
|
|
4330
|
+
function groupConsecutiveItems(items) {
|
|
4331
|
+
const groups = [];
|
|
4332
|
+
for (const item of items) {
|
|
4333
|
+
const last = groups.length > 0 ? groups[groups.length - 1] : void 0;
|
|
4334
|
+
if (last && last.type === item.type) {
|
|
4335
|
+
last.items.push(item);
|
|
4336
|
+
} else {
|
|
4337
|
+
groups.push({ type: item.type, items: [item] });
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
return groups;
|
|
4341
|
+
}
|
|
4342
|
+
function classifySectionWidth(section) {
|
|
4343
|
+
let textCount = 0;
|
|
4344
|
+
let progressCount = 0;
|
|
4345
|
+
let pieCount = 0;
|
|
4346
|
+
let statCount = 0;
|
|
4347
|
+
for (const item of section.items) {
|
|
4348
|
+
switch (item.type) {
|
|
4349
|
+
case "text":
|
|
4350
|
+
textCount++;
|
|
4351
|
+
break;
|
|
4352
|
+
case "progress":
|
|
4353
|
+
progressCount++;
|
|
4354
|
+
break;
|
|
4355
|
+
case "pie":
|
|
4356
|
+
pieCount++;
|
|
4357
|
+
break;
|
|
4358
|
+
case "stat":
|
|
4359
|
+
statCount++;
|
|
4360
|
+
break;
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4363
|
+
if (textCount > 0) return "wide";
|
|
4364
|
+
if (progressCount >= 4) return "wide";
|
|
4365
|
+
if (pieCount >= 3) return "wide";
|
|
4366
|
+
if (statCount >= 4) return "wide";
|
|
4367
|
+
return "narrow";
|
|
4368
|
+
}
|
|
4369
|
+
function computeSectionLayout(sections) {
|
|
4370
|
+
return sections.map((section) => {
|
|
4371
|
+
const width = classifySectionWidth(section);
|
|
4372
|
+
return width === "wide" ? "1 / -1" : void 0;
|
|
4373
|
+
});
|
|
4374
|
+
}
|
|
4375
|
+
var PROGRESS_COLORS = [
|
|
4376
|
+
"var(--glyph-infographic-color-1, #3b82f6)",
|
|
4377
|
+
"var(--glyph-infographic-color-2, #22c55e)",
|
|
4378
|
+
"var(--glyph-infographic-color-3, #f59e0b)",
|
|
4379
|
+
"var(--glyph-infographic-color-4, #ef4444)"
|
|
4380
|
+
];
|
|
4381
|
+
function renderStatGroup(items, keyPrefix) {
|
|
4382
|
+
const rowStyle = {
|
|
4383
|
+
display: "flex",
|
|
4384
|
+
flexWrap: "wrap",
|
|
4385
|
+
gap: "var(--glyph-spacing-md, 1rem)"
|
|
4386
|
+
};
|
|
4387
|
+
const statStyle = {
|
|
4388
|
+
flex: "1 1 120px",
|
|
4389
|
+
minWidth: 0
|
|
4390
|
+
};
|
|
4391
|
+
const valueStyle = {
|
|
4392
|
+
fontSize: "1.75rem",
|
|
4393
|
+
fontWeight: 700,
|
|
4394
|
+
color: "var(--glyph-infographic-value-color, #1d4ed8)",
|
|
4395
|
+
lineHeight: 1.2
|
|
4396
|
+
};
|
|
4397
|
+
const labelStyle3 = {
|
|
4398
|
+
fontSize: "0.8125rem",
|
|
4399
|
+
color: "var(--glyph-infographic-label-color, #475569)",
|
|
4400
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4401
|
+
textTransform: "uppercase",
|
|
4402
|
+
letterSpacing: "0.06em",
|
|
4403
|
+
fontWeight: 600
|
|
4404
|
+
};
|
|
4405
|
+
const descStyle = {
|
|
4406
|
+
fontSize: "0.75rem",
|
|
4407
|
+
color: "var(--glyph-infographic-desc-color, #64748b)",
|
|
4408
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4409
|
+
fontStyle: "italic"
|
|
4410
|
+
};
|
|
4411
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: rowStyle, "data-group": "stat", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: statStyle, children: [
|
|
4412
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: valueStyle, children: item.value }),
|
|
4413
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: labelStyle3, children: item.label }),
|
|
4414
|
+
item.description && /* @__PURE__ */ jsxRuntime.jsx("div", { style: descStyle, children: item.description })
|
|
4415
|
+
] }, `${keyPrefix}-${String(i)}`)) }, keyPrefix);
|
|
4416
|
+
}
|
|
4417
|
+
function renderProgressGroup(items, keyPrefix, colorOffset) {
|
|
4418
|
+
const trackStyle = {
|
|
4419
|
+
height: "0.5rem",
|
|
4420
|
+
borderRadius: "var(--glyph-radius-sm, 0.375rem)",
|
|
4421
|
+
background: "var(--glyph-infographic-track, #e0e4ea)",
|
|
4422
|
+
overflow: "hidden"
|
|
4423
|
+
};
|
|
4424
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-group": "progress", children: items.map((item, i) => {
|
|
4425
|
+
const colorIndex = (colorOffset + i) % PROGRESS_COLORS.length;
|
|
4426
|
+
const fillColor = item.color ?? PROGRESS_COLORS[colorIndex];
|
|
4427
|
+
const fillStyle = {
|
|
4428
|
+
height: "100%",
|
|
4429
|
+
width: `${String(item.value)}%`,
|
|
4430
|
+
borderRadius: "var(--glyph-radius-sm, 0.375rem)",
|
|
4431
|
+
background: fillColor,
|
|
4432
|
+
transition: "width 0.3s ease"
|
|
4433
|
+
};
|
|
4434
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4435
|
+
"div",
|
|
4436
|
+
{
|
|
4437
|
+
style: { marginBottom: "var(--glyph-spacing-sm, 0.5rem)" },
|
|
4438
|
+
children: [
|
|
4439
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4440
|
+
"div",
|
|
4441
|
+
{
|
|
4442
|
+
style: {
|
|
4443
|
+
display: "flex",
|
|
4444
|
+
justifyContent: "space-between",
|
|
4445
|
+
marginBottom: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4446
|
+
fontSize: "0.875rem"
|
|
4447
|
+
},
|
|
4448
|
+
children: [
|
|
4449
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "var(--glyph-text, #1a2035)", fontWeight: 600 }, children: item.label }),
|
|
4450
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4451
|
+
"span",
|
|
4452
|
+
{
|
|
4453
|
+
style: {
|
|
4454
|
+
color: "var(--glyph-infographic-value-color, #1d4ed8)",
|
|
4455
|
+
fontWeight: 700
|
|
4456
|
+
},
|
|
4457
|
+
children: [
|
|
4458
|
+
String(item.value),
|
|
4459
|
+
"%"
|
|
4460
|
+
]
|
|
4461
|
+
}
|
|
4462
|
+
)
|
|
4463
|
+
]
|
|
4464
|
+
}
|
|
4465
|
+
),
|
|
4466
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: trackStyle, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4467
|
+
"div",
|
|
4468
|
+
{
|
|
4469
|
+
role: "progressbar",
|
|
4470
|
+
"aria-valuenow": item.value,
|
|
4471
|
+
"aria-valuemin": 0,
|
|
4472
|
+
"aria-valuemax": 100,
|
|
4473
|
+
"aria-label": `${item.label}: ${String(item.value)}%`,
|
|
4474
|
+
style: fillStyle
|
|
4475
|
+
}
|
|
4476
|
+
) })
|
|
4477
|
+
]
|
|
4478
|
+
},
|
|
4479
|
+
`${keyPrefix}-${String(i)}`
|
|
4480
|
+
);
|
|
4481
|
+
}) }, keyPrefix);
|
|
4482
|
+
}
|
|
4483
|
+
function renderFactGroup(items, keyPrefix) {
|
|
4484
|
+
const listStyle = {
|
|
4485
|
+
listStyle: "none",
|
|
4486
|
+
margin: 0,
|
|
4487
|
+
padding: 0
|
|
4488
|
+
};
|
|
4489
|
+
const itemStyle2 = {
|
|
4490
|
+
padding: "var(--glyph-spacing-xs, 0.25rem) 0",
|
|
4491
|
+
fontSize: "0.875rem",
|
|
4492
|
+
color: "var(--glyph-text, #1a2035)",
|
|
4493
|
+
fontWeight: 500
|
|
4494
|
+
};
|
|
4495
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { style: listStyle, "data-group": "fact", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { style: itemStyle2, children: [
|
|
4496
|
+
item.icon && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4497
|
+
"span",
|
|
4498
|
+
{
|
|
4499
|
+
style: {
|
|
4500
|
+
marginRight: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4501
|
+
color: "var(--glyph-infographic-accent, #3b82f6)"
|
|
4502
|
+
},
|
|
4503
|
+
"aria-hidden": "true",
|
|
4504
|
+
children: item.icon
|
|
4505
|
+
}
|
|
4506
|
+
),
|
|
4507
|
+
item.text
|
|
4508
|
+
] }, `${keyPrefix}-${String(i)}`)) }, keyPrefix);
|
|
4509
|
+
}
|
|
4510
|
+
function renderTextGroup(items, keyPrefix) {
|
|
4511
|
+
const pStyle = {
|
|
4512
|
+
margin: "0 0 var(--glyph-spacing-sm, 0.5rem) 0",
|
|
4513
|
+
fontSize: "0.875rem",
|
|
4514
|
+
lineHeight: 1.6,
|
|
4515
|
+
color: "var(--glyph-text, #1a2035)",
|
|
4516
|
+
borderLeft: "3px solid var(--glyph-infographic-accent, #3b82f6)",
|
|
4517
|
+
paddingLeft: "var(--glyph-spacing-sm, 0.5rem)"
|
|
4518
|
+
};
|
|
4519
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-group": "text", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx("p", { style: pStyle, children: item.content }, `${keyPrefix}-${String(i)}`)) }, keyPrefix);
|
|
4520
|
+
}
|
|
4521
|
+
function renderPieGroup(items, keyPrefix, colorOffset) {
|
|
4522
|
+
const wrapperStyle = {
|
|
4523
|
+
display: "flex",
|
|
4524
|
+
flexWrap: "wrap",
|
|
4525
|
+
gap: "var(--glyph-spacing-md, 1rem)"
|
|
4526
|
+
};
|
|
4527
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: wrapperStyle, "data-group": "pie", children: items.map((item, i) => {
|
|
4528
|
+
const size = item.size ?? 160;
|
|
4529
|
+
const outerRadius = size / 2;
|
|
4530
|
+
const innerRadius = item.donut ?? true ? outerRadius * 0.55 : 0;
|
|
4531
|
+
const cx = outerRadius;
|
|
4532
|
+
const cy = outerRadius;
|
|
4533
|
+
const total = item.slices.reduce((sum, s) => sum + s.value, 0);
|
|
4534
|
+
let cumAngle = -Math.PI / 2;
|
|
4535
|
+
const paths = [];
|
|
4536
|
+
for (let si = 0; si < item.slices.length; si++) {
|
|
4537
|
+
const slice = item.slices[si];
|
|
4538
|
+
if (!slice) continue;
|
|
4539
|
+
const sliceAngle = slice.value / total * 2 * Math.PI;
|
|
4540
|
+
const startAngle = cumAngle;
|
|
4541
|
+
const endAngle = cumAngle + sliceAngle;
|
|
4542
|
+
cumAngle = endAngle;
|
|
4543
|
+
const sliceColorIndex = (colorOffset + si) % PROGRESS_COLORS.length;
|
|
4544
|
+
const fillColor = slice.color ?? PROGRESS_COLORS[sliceColorIndex];
|
|
4545
|
+
const x1 = cx + outerRadius * Math.cos(startAngle);
|
|
4546
|
+
const y1 = cy + outerRadius * Math.sin(startAngle);
|
|
4547
|
+
const x2 = cx + outerRadius * Math.cos(endAngle);
|
|
4548
|
+
const y2 = cy + outerRadius * Math.sin(endAngle);
|
|
4549
|
+
const largeArc = sliceAngle > Math.PI ? 1 : 0;
|
|
4550
|
+
let d;
|
|
4551
|
+
if (innerRadius > 0) {
|
|
4552
|
+
const ix1 = cx + innerRadius * Math.cos(endAngle);
|
|
4553
|
+
const iy1 = cy + innerRadius * Math.sin(endAngle);
|
|
4554
|
+
const ix2 = cx + innerRadius * Math.cos(startAngle);
|
|
4555
|
+
const iy2 = cy + innerRadius * Math.sin(startAngle);
|
|
4556
|
+
d = [
|
|
4557
|
+
`M ${String(x1)} ${String(y1)}`,
|
|
4558
|
+
`A ${String(outerRadius)} ${String(outerRadius)} 0 ${String(largeArc)} 1 ${String(x2)} ${String(y2)}`,
|
|
4559
|
+
`L ${String(ix1)} ${String(iy1)}`,
|
|
4560
|
+
`A ${String(innerRadius)} ${String(innerRadius)} 0 ${String(largeArc)} 0 ${String(ix2)} ${String(iy2)}`,
|
|
4561
|
+
"Z"
|
|
4562
|
+
].join(" ");
|
|
4563
|
+
} else {
|
|
4564
|
+
d = [
|
|
4565
|
+
`M ${String(cx)} ${String(cy)}`,
|
|
4566
|
+
`L ${String(x1)} ${String(y1)}`,
|
|
4567
|
+
`A ${String(outerRadius)} ${String(outerRadius)} 0 ${String(largeArc)} 1 ${String(x2)} ${String(y2)}`,
|
|
4568
|
+
"Z"
|
|
4569
|
+
].join(" ");
|
|
4570
|
+
}
|
|
4571
|
+
paths.push(/* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: fillColor }, si));
|
|
4572
|
+
}
|
|
4573
|
+
const ariaLabel = item.label ? `${item.label}: ${item.slices.map((s) => `${s.label} ${String(s.value)}`).join(", ")}` : `Pie chart: ${item.slices.map((s) => `${s.label} ${String(s.value)}`).join(", ")}`;
|
|
4574
|
+
const legendStyle = {
|
|
4575
|
+
display: "flex",
|
|
4576
|
+
flexWrap: "wrap",
|
|
4577
|
+
gap: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4578
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4579
|
+
fontSize: "0.75rem",
|
|
4580
|
+
color: "var(--glyph-text-muted, #6b7a94)"
|
|
4581
|
+
};
|
|
4582
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center" }, children: [
|
|
4583
|
+
item.label && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4584
|
+
"div",
|
|
4585
|
+
{
|
|
4586
|
+
style: {
|
|
4587
|
+
fontSize: "0.875rem",
|
|
4588
|
+
fontWeight: 600,
|
|
4589
|
+
color: "var(--glyph-infographic-heading-color, #1e293b)",
|
|
4590
|
+
marginBottom: "var(--glyph-spacing-xs, 0.25rem)"
|
|
4591
|
+
},
|
|
4592
|
+
children: item.label
|
|
4593
|
+
}
|
|
4594
|
+
),
|
|
4595
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4596
|
+
"svg",
|
|
4597
|
+
{
|
|
4598
|
+
width: size,
|
|
4599
|
+
height: size,
|
|
4600
|
+
viewBox: `0 0 ${String(size)} ${String(size)}`,
|
|
4601
|
+
role: "img",
|
|
4602
|
+
"aria-label": ariaLabel,
|
|
4603
|
+
children: paths
|
|
4604
|
+
}
|
|
4605
|
+
),
|
|
4606
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: legendStyle, children: item.slices.map((slice, si) => {
|
|
4607
|
+
const sliceColorIndex = (colorOffset + si) % PROGRESS_COLORS.length;
|
|
4608
|
+
const legendColor = slice.color ?? PROGRESS_COLORS[sliceColorIndex];
|
|
4609
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4610
|
+
"span",
|
|
4611
|
+
{
|
|
4612
|
+
style: {
|
|
4613
|
+
display: "inline-flex",
|
|
4614
|
+
alignItems: "center",
|
|
4615
|
+
gap: "0.25rem",
|
|
4616
|
+
fontWeight: 500
|
|
4617
|
+
},
|
|
4618
|
+
children: [
|
|
4619
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4620
|
+
"span",
|
|
4621
|
+
{
|
|
4622
|
+
style: {
|
|
4623
|
+
display: "inline-block",
|
|
4624
|
+
width: "0.625rem",
|
|
4625
|
+
height: "0.625rem",
|
|
4626
|
+
borderRadius: "2px",
|
|
4627
|
+
background: legendColor
|
|
4628
|
+
},
|
|
4629
|
+
"aria-hidden": "true"
|
|
4630
|
+
}
|
|
4631
|
+
),
|
|
4632
|
+
slice.label
|
|
4633
|
+
]
|
|
4634
|
+
},
|
|
4635
|
+
si
|
|
4636
|
+
);
|
|
4637
|
+
}) })
|
|
4638
|
+
] }, `${keyPrefix}-${String(i)}`);
|
|
4639
|
+
}) }, keyPrefix);
|
|
4640
|
+
}
|
|
4641
|
+
function renderDividerGroup(items, keyPrefix) {
|
|
4642
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-group": "divider", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4643
|
+
"hr",
|
|
4644
|
+
{
|
|
4645
|
+
role: "separator",
|
|
4646
|
+
style: {
|
|
4647
|
+
border: "none",
|
|
4648
|
+
borderTop: `1px ${item.style ?? "solid"} var(--glyph-infographic-section-divider, #d0d8e4)`,
|
|
4649
|
+
margin: "var(--glyph-spacing-sm, 0.5rem) 0"
|
|
4650
|
+
}
|
|
4651
|
+
},
|
|
4652
|
+
`${keyPrefix}-${String(i)}`
|
|
4653
|
+
)) }, keyPrefix);
|
|
4654
|
+
}
|
|
4655
|
+
function renderRatingGroup(items, keyPrefix) {
|
|
4656
|
+
const starColor = "var(--glyph-infographic-star, #f59e0b)";
|
|
4657
|
+
const emptyColor = "var(--glyph-text-muted, #6b7a94)";
|
|
4658
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-group": "rating", children: items.map((item, i) => {
|
|
4659
|
+
const max2 = item.max ?? 5;
|
|
4660
|
+
const fullStars = Math.floor(item.value);
|
|
4661
|
+
const hasHalf = item.value - fullStars >= 0.5;
|
|
4662
|
+
const stars = [];
|
|
4663
|
+
for (let s = 0; s < max2; s++) {
|
|
4664
|
+
if (s < fullStars) {
|
|
4665
|
+
stars.push(
|
|
4666
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: starColor }, "aria-hidden": "true", children: "\u2605" }, s)
|
|
4667
|
+
);
|
|
4668
|
+
} else if (s === fullStars && hasHalf) {
|
|
4669
|
+
stars.push(
|
|
4670
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4671
|
+
"span",
|
|
4672
|
+
{
|
|
4673
|
+
style: { position: "relative", display: "inline-block" },
|
|
4674
|
+
"aria-hidden": "true",
|
|
4675
|
+
children: [
|
|
4676
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: emptyColor }, children: "\u2605" }),
|
|
4677
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4678
|
+
"span",
|
|
4679
|
+
{
|
|
4680
|
+
style: {
|
|
4681
|
+
position: "absolute",
|
|
4682
|
+
left: 0,
|
|
4683
|
+
top: 0,
|
|
4684
|
+
overflow: "hidden",
|
|
4685
|
+
width: "50%",
|
|
4686
|
+
color: starColor
|
|
4687
|
+
},
|
|
4688
|
+
children: "\u2605"
|
|
4689
|
+
}
|
|
4690
|
+
)
|
|
4691
|
+
]
|
|
4692
|
+
},
|
|
4693
|
+
s
|
|
4694
|
+
)
|
|
4695
|
+
);
|
|
4696
|
+
} else {
|
|
4697
|
+
stars.push(
|
|
4698
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: emptyColor }, "aria-hidden": "true", children: "\u2605" }, s)
|
|
4699
|
+
);
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4703
|
+
"div",
|
|
4704
|
+
{
|
|
4705
|
+
style: {
|
|
4706
|
+
display: "flex",
|
|
4707
|
+
alignItems: "baseline",
|
|
4708
|
+
gap: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4709
|
+
marginBottom: "var(--glyph-spacing-sm, 0.5rem)"
|
|
4710
|
+
},
|
|
4711
|
+
children: [
|
|
4712
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4713
|
+
"span",
|
|
4714
|
+
{
|
|
4715
|
+
style: {
|
|
4716
|
+
fontSize: "1.5rem",
|
|
4717
|
+
fontWeight: 700,
|
|
4718
|
+
color: "var(--glyph-heading, #0a0e1a)",
|
|
4719
|
+
lineHeight: 1
|
|
4720
|
+
},
|
|
4721
|
+
children: String(item.value)
|
|
4722
|
+
}
|
|
4723
|
+
),
|
|
4724
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4725
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4726
|
+
"div",
|
|
4727
|
+
{
|
|
4728
|
+
style: {
|
|
4729
|
+
fontSize: "0.875rem",
|
|
4730
|
+
color: "var(--glyph-text, #1a2035)",
|
|
4731
|
+
fontWeight: 600
|
|
4732
|
+
},
|
|
4733
|
+
children: item.label
|
|
4734
|
+
}
|
|
4735
|
+
),
|
|
4736
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4737
|
+
"div",
|
|
4738
|
+
{
|
|
4739
|
+
style: { fontSize: "1.125rem", letterSpacing: "0.05em" },
|
|
4740
|
+
"aria-label": `${String(item.value)} out of ${String(max2)} stars`,
|
|
4741
|
+
children: stars
|
|
4742
|
+
}
|
|
4743
|
+
),
|
|
4744
|
+
item.description && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4745
|
+
"div",
|
|
4746
|
+
{
|
|
4747
|
+
style: {
|
|
4748
|
+
fontSize: "0.75rem",
|
|
4749
|
+
color: "var(--glyph-infographic-desc-color, #64748b)",
|
|
4750
|
+
marginTop: "var(--glyph-spacing-xs, 0.25rem)",
|
|
4751
|
+
fontStyle: "italic"
|
|
4752
|
+
},
|
|
4753
|
+
children: item.description
|
|
4754
|
+
}
|
|
4755
|
+
)
|
|
4756
|
+
] })
|
|
4757
|
+
]
|
|
4758
|
+
},
|
|
4759
|
+
`${keyPrefix}-${String(i)}`
|
|
4760
|
+
);
|
|
4761
|
+
}) }, keyPrefix);
|
|
4762
|
+
}
|
|
4763
|
+
function Infographic({
|
|
4764
|
+
data,
|
|
4765
|
+
block,
|
|
4766
|
+
container
|
|
4767
|
+
}) {
|
|
4768
|
+
const { title, sections } = data;
|
|
4769
|
+
const baseId = `glyph-infographic-${block.id}`;
|
|
4770
|
+
const useGrid = sections.length >= 2 && container.tier !== "compact";
|
|
4771
|
+
const sectionLayouts = react.useMemo(() => computeSectionLayout(sections), [sections]);
|
|
4772
|
+
const containerStyle3 = {
|
|
4773
|
+
fontFamily: "var(--glyph-font-body, system-ui, sans-serif)",
|
|
4774
|
+
color: "var(--glyph-text, #1a2035)",
|
|
4775
|
+
background: "var(--glyph-surface, #e8ecf3)",
|
|
4776
|
+
border: "1px solid var(--glyph-border, #d0d8e4)",
|
|
4777
|
+
borderRadius: "var(--glyph-radius-md, 0.5rem)",
|
|
4778
|
+
padding: "var(--glyph-spacing-md, 1rem)"
|
|
4779
|
+
};
|
|
4780
|
+
const titleStyle2 = {
|
|
4781
|
+
fontFamily: "var(--glyph-font-heading, system-ui, sans-serif)",
|
|
4782
|
+
fontWeight: 700,
|
|
4783
|
+
fontSize: "1.25rem",
|
|
4784
|
+
color: "var(--glyph-heading, #0a0e1a)",
|
|
4785
|
+
margin: 0,
|
|
4786
|
+
paddingBottom: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4787
|
+
marginBottom: "var(--glyph-spacing-md, 1rem)",
|
|
4788
|
+
borderBottom: "2px solid var(--glyph-infographic-accent, #3b82f6)",
|
|
4789
|
+
...useGrid ? { gridColumn: "1 / -1" } : {}
|
|
4790
|
+
};
|
|
4791
|
+
const sectionDividerStyle = {
|
|
4792
|
+
borderTop: "1px solid var(--glyph-infographic-section-divider, #d0d8e4)",
|
|
4793
|
+
paddingTop: "var(--glyph-spacing-md, 1rem)",
|
|
4794
|
+
marginTop: "var(--glyph-spacing-md, 1rem)"
|
|
4795
|
+
};
|
|
4796
|
+
const sectionsGridStyle = {
|
|
4797
|
+
display: "grid",
|
|
4798
|
+
gridTemplateColumns: "repeat(2, 1fr)",
|
|
4799
|
+
gap: "var(--glyph-spacing-md, 1rem)",
|
|
4800
|
+
alignItems: "start"
|
|
4801
|
+
};
|
|
4802
|
+
const sectionCardStyle = {
|
|
4803
|
+
background: "var(--glyph-infographic-section-bg, rgba(255, 255, 255, 0.5))",
|
|
4804
|
+
borderRadius: "var(--glyph-radius-sm, 0.375rem)",
|
|
4805
|
+
padding: "var(--glyph-spacing-sm, 0.5rem)"
|
|
4806
|
+
};
|
|
4807
|
+
const headingStyle = {
|
|
4808
|
+
fontWeight: 700,
|
|
4809
|
+
fontSize: "1rem",
|
|
4810
|
+
color: "var(--glyph-infographic-heading-color, #1e293b)",
|
|
4811
|
+
marginBottom: "var(--glyph-spacing-sm, 0.5rem)",
|
|
4812
|
+
borderLeft: "3px solid var(--glyph-infographic-accent, #3b82f6)",
|
|
4813
|
+
paddingLeft: "var(--glyph-spacing-sm, 0.5rem)"
|
|
4814
|
+
};
|
|
4815
|
+
const printCss = useGrid ? `@media print { #${CSS.escape(baseId)} [data-layout="grid"] { display: grid !important; grid-template-columns: repeat(2, 1fr) !important; gap: 0.5rem !important; } #${CSS.escape(baseId)} [data-layout="grid"] > div { break-inside: avoid; } }` : "";
|
|
4816
|
+
let progressColorOffset = 0;
|
|
4817
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Infographic", style: containerStyle3, children: [
|
|
4818
|
+
printCss && /* @__PURE__ */ jsxRuntime.jsx("style", { children: printCss }),
|
|
4819
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { "data-layout": useGrid ? "grid" : "stack", style: useGrid ? sectionsGridStyle : void 0, children: [
|
|
4820
|
+
title && /* @__PURE__ */ jsxRuntime.jsx("div", { style: titleStyle2, children: title }),
|
|
4821
|
+
sections.map((section, si) => {
|
|
4822
|
+
const groups = groupConsecutiveItems(section.items);
|
|
4823
|
+
const gridColumn = sectionLayouts[si];
|
|
4824
|
+
const sectionStyle = {
|
|
4825
|
+
...useGrid ? sectionCardStyle : {},
|
|
4826
|
+
...gridColumn ? { gridColumn } : {},
|
|
4827
|
+
...!useGrid && si > 0 ? sectionDividerStyle : {}
|
|
4828
|
+
};
|
|
4829
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: Object.keys(sectionStyle).length > 0 ? sectionStyle : void 0, children: [
|
|
4830
|
+
section.heading && /* @__PURE__ */ jsxRuntime.jsx("div", { style: headingStyle, children: section.heading }),
|
|
4831
|
+
groups.map((group, gi) => {
|
|
4832
|
+
const key = `s${String(si)}-g${String(gi)}`;
|
|
4833
|
+
switch (group.type) {
|
|
4834
|
+
case "stat":
|
|
4835
|
+
return renderStatGroup(group.items, key);
|
|
4836
|
+
case "progress": {
|
|
4837
|
+
const el = renderProgressGroup(
|
|
4838
|
+
group.items,
|
|
4839
|
+
key,
|
|
4840
|
+
progressColorOffset
|
|
4841
|
+
);
|
|
4842
|
+
progressColorOffset += group.items.length;
|
|
4843
|
+
return el;
|
|
4844
|
+
}
|
|
4845
|
+
case "fact":
|
|
4846
|
+
return renderFactGroup(group.items, key);
|
|
4847
|
+
case "text":
|
|
4848
|
+
return renderTextGroup(group.items, key);
|
|
4849
|
+
case "pie": {
|
|
4850
|
+
const el = renderPieGroup(group.items, key, progressColorOffset);
|
|
4851
|
+
progressColorOffset += group.items.reduce(
|
|
4852
|
+
(sum, item) => sum + item.slices.length,
|
|
4853
|
+
0
|
|
4854
|
+
);
|
|
4855
|
+
return el;
|
|
4856
|
+
}
|
|
4857
|
+
case "divider":
|
|
4858
|
+
return renderDividerGroup(group.items, key);
|
|
4859
|
+
case "rating":
|
|
4860
|
+
return renderRatingGroup(group.items, key);
|
|
4861
|
+
default:
|
|
4862
|
+
return null;
|
|
4863
|
+
}
|
|
4864
|
+
})
|
|
4865
|
+
] }, si);
|
|
4866
|
+
})
|
|
4867
|
+
] })
|
|
4868
|
+
] });
|
|
4869
|
+
}
|
|
4870
|
+
|
|
4871
|
+
// src/infographic/index.ts
|
|
4872
|
+
var infographicDefinition = {
|
|
4873
|
+
type: "ui:infographic",
|
|
4874
|
+
schema: schemas.infographicSchema,
|
|
4875
|
+
render: Infographic
|
|
4876
|
+
};
|
|
4877
|
+
|
|
4878
|
+
exports.Accordion = Accordion;
|
|
4879
|
+
exports.Architecture = Architecture;
|
|
4880
|
+
exports.Callout = Callout;
|
|
4881
|
+
exports.Card = Card;
|
|
4882
|
+
exports.Chart = Chart;
|
|
4883
|
+
exports.CodeDiff = CodeDiff;
|
|
4884
|
+
exports.Comparison = Comparison;
|
|
4885
|
+
exports.Equation = Equation;
|
|
4886
|
+
exports.FileTree = FileTree;
|
|
4887
|
+
exports.Flowchart = Flowchart;
|
|
4888
|
+
exports.Graph = Graph;
|
|
4889
|
+
exports.Infographic = Infographic;
|
|
4890
|
+
exports.Kpi = Kpi;
|
|
4891
|
+
exports.MindMap = MindMap;
|
|
4892
|
+
exports.Quiz = Quiz;
|
|
4893
|
+
exports.Relation = Relation;
|
|
4894
|
+
exports.Sequence = Sequence;
|
|
4895
|
+
exports.Steps = Steps;
|
|
4896
|
+
exports.Table = Table;
|
|
4897
|
+
exports.Tabs = Tabs;
|
|
4898
|
+
exports.Timeline = Timeline;
|
|
4899
|
+
exports.accordionDefinition = accordionDefinition;
|
|
4900
|
+
exports.architectureDefinition = architectureDefinition;
|
|
4901
|
+
exports.calloutDefinition = calloutDefinition;
|
|
4902
|
+
exports.cardDefinition = cardDefinition;
|
|
4903
|
+
exports.chartDefinition = chartDefinition;
|
|
4904
|
+
exports.codeDiffDefinition = codeDiffDefinition;
|
|
4905
|
+
exports.comparisonDefinition = comparisonDefinition;
|
|
4906
|
+
exports.computeArchitectureLayout = computeArchitectureLayout;
|
|
4907
|
+
exports.computeDagreLayout = computeDagreLayout;
|
|
4908
|
+
exports.computeDiff = computeDiff;
|
|
4909
|
+
exports.computeForceLayout = computeForceLayout;
|
|
4910
|
+
exports.equationDefinition = equationDefinition;
|
|
4911
|
+
exports.fileTreeDefinition = fileTreeDefinition;
|
|
4912
|
+
exports.flowchartDefinition = flowchartDefinition;
|
|
4913
|
+
exports.graphDefinition = graphDefinition;
|
|
4914
|
+
exports.infographicDefinition = infographicDefinition;
|
|
4915
|
+
exports.kpiDefinition = kpiDefinition;
|
|
4916
|
+
exports.mindMapDefinition = mindMapDefinition;
|
|
4917
|
+
exports.quizDefinition = quizDefinition;
|
|
4918
|
+
exports.relationDefinition = relationDefinition;
|
|
4919
|
+
exports.sequenceDefinition = sequenceDefinition;
|
|
4920
|
+
exports.stepsDefinition = stepsDefinition;
|
|
4921
|
+
exports.tableDefinition = tableDefinition;
|
|
4922
|
+
exports.tabsDefinition = tabsDefinition;
|
|
4923
|
+
exports.timelineDefinition = timelineDefinition;
|
|
4924
|
+
//# sourceMappingURL=index.cjs.map
|
|
4925
|
+
//# sourceMappingURL=index.cjs.map
|