@lincyaw/aegis-ui 0.7.0 → 0.9.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/dist/components/ui/AgentHud.cjs +2 -0
- package/dist/components/ui/AgentHud.cjs.map +1 -0
- package/dist/components/ui/AgentHud.d.ts +23 -0
- package/dist/components/ui/AgentHud.js +45 -0
- package/dist/components/ui/AgentHud.js.map +1 -0
- package/dist/components/ui/ChartLegend.cjs +2 -0
- package/dist/components/ui/ChartLegend.cjs.map +1 -0
- package/dist/components/ui/ChartLegend.d.ts +17 -0
- package/dist/components/ui/ChartLegend.js +37 -0
- package/dist/components/ui/ChartLegend.js.map +1 -0
- package/dist/components/ui/ColumnChart.cjs +2 -0
- package/dist/components/ui/ColumnChart.cjs.map +1 -0
- package/dist/components/ui/ColumnChart.d.ts +46 -0
- package/dist/components/ui/ColumnChart.js +154 -0
- package/dist/components/ui/ColumnChart.js.map +1 -0
- package/dist/components/ui/DataTable.cjs +1 -1
- package/dist/components/ui/DataTable.cjs.map +1 -1
- package/dist/components/ui/DataTable.d.ts +25 -1
- package/dist/components/ui/DataTable.js +305 -231
- package/dist/components/ui/DataTable.js.map +1 -1
- package/dist/components/ui/DotRangeChart.cjs +2 -0
- package/dist/components/ui/DotRangeChart.cjs.map +1 -0
- package/dist/components/ui/DotRangeChart.d.ts +44 -0
- package/dist/components/ui/DotRangeChart.js +80 -0
- package/dist/components/ui/DotRangeChart.js.map +1 -0
- package/dist/components/ui/HeadlineStat.cjs +2 -0
- package/dist/components/ui/HeadlineStat.cjs.map +1 -0
- package/dist/components/ui/HeadlineStat.d.ts +10 -0
- package/dist/components/ui/HeadlineStat.js +22 -0
- package/dist/components/ui/HeadlineStat.js.map +1 -0
- package/dist/components/ui/Heatmap.cjs +2 -0
- package/dist/components/ui/Heatmap.cjs.map +1 -0
- package/dist/components/ui/Heatmap.d.ts +52 -0
- package/dist/components/ui/Heatmap.js +82 -0
- package/dist/components/ui/Heatmap.js.map +1 -0
- package/dist/components/ui/KeyMomentCard.cjs +2 -0
- package/dist/components/ui/KeyMomentCard.cjs.map +1 -0
- package/dist/components/ui/KeyMomentCard.d.ts +19 -0
- package/dist/components/ui/KeyMomentCard.js +45 -0
- package/dist/components/ui/KeyMomentCard.js.map +1 -0
- package/dist/components/ui/LineChart.cjs +2 -0
- package/dist/components/ui/LineChart.cjs.map +1 -0
- package/dist/components/ui/LineChart.d.ts +48 -0
- package/dist/components/ui/LineChart.js +199 -0
- package/dist/components/ui/LineChart.js.map +1 -0
- package/dist/components/ui/ParetoChart.cjs +1 -1
- package/dist/components/ui/ParetoChart.cjs.map +1 -1
- package/dist/components/ui/ParetoChart.d.ts +44 -5
- package/dist/components/ui/ParetoChart.js +261 -170
- package/dist/components/ui/ParetoChart.js.map +1 -1
- package/dist/components/ui/RankBar.cjs +1 -1
- package/dist/components/ui/RankBar.cjs.map +1 -1
- package/dist/components/ui/RankBar.d.ts +21 -2
- package/dist/components/ui/RankBar.js +76 -42
- package/dist/components/ui/RankBar.js.map +1 -1
- package/dist/components/ui/ReplayScrubber.cjs +2 -0
- package/dist/components/ui/ReplayScrubber.cjs.map +1 -0
- package/dist/components/ui/ReplayScrubber.d.ts +35 -0
- package/dist/components/ui/ReplayScrubber.js +119 -0
- package/dist/components/ui/ReplayScrubber.js.map +1 -0
- package/dist/components/ui/ReplayStepStrip.cjs +2 -0
- package/dist/components/ui/ReplayStepStrip.cjs.map +1 -0
- package/dist/components/ui/ReplayStepStrip.d.ts +45 -0
- package/dist/components/ui/ReplayStepStrip.js +142 -0
- package/dist/components/ui/ReplayStepStrip.js.map +1 -0
- package/dist/components/ui/ReplayTransport.cjs +2 -0
- package/dist/components/ui/ReplayTransport.cjs.map +1 -0
- package/dist/components/ui/ReplayTransport.d.ts +25 -0
- package/dist/components/ui/ReplayTransport.js +103 -0
- package/dist/components/ui/ReplayTransport.js.map +1 -0
- package/dist/components/ui/ResultMatrix.cjs +2 -0
- package/dist/components/ui/ResultMatrix.cjs.map +1 -0
- package/dist/components/ui/ResultMatrix.d.ts +23 -0
- package/dist/components/ui/ResultMatrix.js +53 -0
- package/dist/components/ui/ResultMatrix.js.map +1 -0
- package/dist/components/ui/ScrollStory.cjs +2 -2
- package/dist/components/ui/ScrollStory.cjs.map +1 -1
- package/dist/components/ui/ScrollStory.d.ts +3 -1
- package/dist/components/ui/ScrollStory.js +34 -32
- package/dist/components/ui/ScrollStory.js.map +1 -1
- package/dist/components/ui/SeriesLabel.cjs +2 -0
- package/dist/components/ui/SeriesLabel.cjs.map +1 -0
- package/dist/components/ui/SeriesLabel.d.ts +21 -0
- package/dist/components/ui/SeriesLabel.js +38 -0
- package/dist/components/ui/SeriesLabel.js.map +1 -0
- package/dist/components/ui/StackedBar.cjs +1 -1
- package/dist/components/ui/StackedBar.cjs.map +1 -1
- package/dist/components/ui/StackedBar.d.ts +21 -8
- package/dist/components/ui/StackedBar.js +110 -74
- package/dist/components/ui/StackedBar.js.map +1 -1
- package/dist/components/ui/TableOfContents.cjs +1 -1
- package/dist/components/ui/TableOfContents.cjs.map +1 -1
- package/dist/components/ui/TableOfContents.js +31 -89
- package/dist/components/ui/TableOfContents.js.map +1 -1
- package/dist/components/ui/ThoughtCard.cjs +2 -0
- package/dist/components/ui/ThoughtCard.cjs.map +1 -0
- package/dist/components/ui/ThoughtCard.d.ts +23 -0
- package/dist/components/ui/ThoughtCard.js +55 -0
- package/dist/components/ui/ThoughtCard.js.map +1 -0
- package/dist/components/ui/TimelineChart.cjs +1 -1
- package/dist/components/ui/TimelineChart.cjs.map +1 -1
- package/dist/components/ui/TimelineChart.d.ts +12 -15
- package/dist/components/ui/TimelineChart.js +160 -150
- package/dist/components/ui/TimelineChart.js.map +1 -1
- package/dist/components/ui/TraceSpanInspector.cjs +1 -1
- package/dist/components/ui/TraceSpanInspector.cjs.map +1 -1
- package/dist/components/ui/TraceSpanInspector.js +25 -25
- package/dist/components/ui/TraceSpanInspector.js.map +1 -1
- package/dist/components/ui/TraceTree.cjs +1 -1
- package/dist/components/ui/TraceTree.cjs.map +1 -1
- package/dist/components/ui/TraceTree.d.ts +13 -2
- package/dist/components/ui/TraceTree.js +22 -22
- package/dist/components/ui/TraceTree.js.map +1 -1
- package/dist/components/ui/index.d.ts +31 -5
- package/dist/components/ui/traceFormat.cjs +1 -1
- package/dist/components/ui/traceFormat.cjs.map +1 -1
- package/dist/components/ui/traceFormat.d.ts +0 -2
- package/dist/components/ui/traceFormat.js +2 -6
- package/dist/components/ui/traceFormat.js.map +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useReplayPlayback.cjs +2 -0
- package/dist/hooks/useReplayPlayback.cjs.map +1 -0
- package/dist/hooks/useReplayPlayback.d.ts +44 -0
- package/dist/hooks/useReplayPlayback.js +73 -0
- package/dist/hooks/useReplayPlayback.js.map +1 -0
- package/dist/hooks/useSectionSpy.cjs +2 -0
- package/dist/hooks/useSectionSpy.cjs.map +1 -0
- package/dist/hooks/useSectionSpy.d.ts +23 -0
- package/dist/hooks/useSectionSpy.js +78 -0
- package/dist/hooks/useSectionSpy.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +339 -300
- package/dist/index.js.map +1 -1
- package/dist/layouts/SkipLink.cjs +2 -0
- package/dist/layouts/SkipLink.cjs.map +1 -0
- package/dist/layouts/SkipLink.d.ts +13 -0
- package/dist/layouts/SkipLink.js +21 -0
- package/dist/layouts/SkipLink.js.map +1 -0
- package/dist/layouts/shell/AegisShell.cjs +1 -1
- package/dist/layouts/shell/AegisShell.cjs.map +1 -1
- package/dist/layouts/shell/AegisShell.js +174 -193
- package/dist/layouts/shell/AegisShell.js.map +1 -1
- package/dist/layouts/site/SiteAnchorNav.cjs +2 -0
- package/dist/layouts/site/SiteAnchorNav.cjs.map +1 -0
- package/dist/layouts/site/SiteAnchorNav.d.ts +22 -0
- package/dist/layouts/site/SiteAnchorNav.js +51 -0
- package/dist/layouts/site/SiteAnchorNav.js.map +1 -0
- package/dist/layouts/site/SiteLayout.cjs +1 -1
- package/dist/layouts/site/SiteLayout.cjs.map +1 -1
- package/dist/layouts/site/SiteLayout.js +18 -28
- package/dist/layouts/site/SiteLayout.js.map +1 -1
- package/dist/layouts/site/SiteNav.cjs +1 -1
- package/dist/layouts/site/SiteNav.cjs.map +1 -1
- package/dist/layouts/site/SiteNav.js +50 -48
- package/dist/layouts/site/SiteNav.js.map +1 -1
- package/dist/layouts/site/SiteSectionHeader.cjs +2 -0
- package/dist/layouts/site/SiteSectionHeader.cjs.map +1 -0
- package/dist/layouts/site/SiteSectionHeader.d.ts +20 -0
- package/dist/layouts/site/SiteSectionHeader.js +30 -0
- package/dist/layouts/site/SiteSectionHeader.js.map +1 -0
- package/dist/layouts/site/index.d.ts +4 -0
- package/dist/lib/chart.cjs +2 -0
- package/dist/lib/chart.cjs.map +1 -0
- package/dist/lib/chart.d.ts +39 -0
- package/dist/lib/chart.js +51 -0
- package/dist/lib/chart.js.map +1 -0
- package/dist/locale/strings.cjs +1 -1
- package/dist/locale/strings.cjs.map +1 -1
- package/dist/locale/strings.d.ts +11 -8
- package/dist/locale/strings.js +38 -34
- package/dist/locale/strings.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/dist/components/ui/SessionRunView.cjs +0 -4
- package/dist/components/ui/SessionRunView.cjs.map +0 -1
- package/dist/components/ui/SessionRunView.d.ts +0 -50
- package/dist/components/ui/SessionRunView.js +0 -379
- package/dist/components/ui/SessionRunView.js.map +0 -1
|
@@ -1,110 +1,146 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as l, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import { zeroAnchoredDomain as x, chartColorValue as D, staggeredProgress as T } from "../../lib/chart.js";
|
|
3
|
+
import { ChartLegend as z } from "./ChartLegend.js";
|
|
4
|
+
import { DataTable as A } from "./DataTable.js";
|
|
3
5
|
/* empty css */
|
|
4
|
-
function
|
|
5
|
-
series:
|
|
6
|
-
rows:
|
|
7
|
-
max:
|
|
8
|
-
direction:
|
|
9
|
-
format:
|
|
10
|
-
view:
|
|
11
|
-
labelHeader:
|
|
12
|
-
totalHeader:
|
|
13
|
-
|
|
6
|
+
function V({
|
|
7
|
+
series: n,
|
|
8
|
+
rows: t,
|
|
9
|
+
max: m,
|
|
10
|
+
direction: b,
|
|
11
|
+
format: c = String,
|
|
12
|
+
view: N = "chart",
|
|
13
|
+
labelHeader: $,
|
|
14
|
+
totalHeader: f,
|
|
15
|
+
normalize: g = !1,
|
|
16
|
+
onSegmentSelect: i,
|
|
17
|
+
isSegmentSelectable: j = () => !0,
|
|
18
|
+
progress: o,
|
|
19
|
+
className: B
|
|
14
20
|
}) {
|
|
15
|
-
const _ = (
|
|
21
|
+
const _ = (e) => n.reduce((s, r) => s + e.values[r.key], 0), u = t.some((e) => e.note !== void 0), y = [
|
|
16
22
|
"aegis-stacked-bar",
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
u ? "aegis-stacked-bar--noted" : "",
|
|
24
|
+
o === void 0 ? "" : "aegis-stacked-bar--scroll",
|
|
25
|
+
B ?? ""
|
|
19
26
|
].filter(Boolean).join(" ");
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
{ key: "label", header:
|
|
23
|
-
...
|
|
24
|
-
(
|
|
25
|
-
key: `series:${
|
|
26
|
-
header:
|
|
27
|
+
if (N === "table") {
|
|
28
|
+
const e = [
|
|
29
|
+
{ key: "label", header: $, render: (s) => s.label },
|
|
30
|
+
...n.map(
|
|
31
|
+
(s) => ({
|
|
32
|
+
key: `series:${s.key}`,
|
|
33
|
+
header: s.label,
|
|
27
34
|
numeric: !0,
|
|
28
|
-
render: (
|
|
35
|
+
render: (r) => c(r.values[s.key])
|
|
29
36
|
})
|
|
30
37
|
),
|
|
31
38
|
{
|
|
32
39
|
key: "total",
|
|
33
|
-
header:
|
|
40
|
+
header: f,
|
|
34
41
|
numeric: !0,
|
|
35
|
-
render: (
|
|
42
|
+
render: (s) => c(_(s))
|
|
36
43
|
}
|
|
37
44
|
];
|
|
38
|
-
return /* @__PURE__ */
|
|
39
|
-
|
|
45
|
+
return /* @__PURE__ */ l("div", { className: y, children: /* @__PURE__ */ l(
|
|
46
|
+
A,
|
|
40
47
|
{
|
|
41
|
-
columns:
|
|
42
|
-
data:
|
|
43
|
-
rowKey: (
|
|
48
|
+
columns: e,
|
|
49
|
+
data: t,
|
|
50
|
+
rowKey: (s) => s.key,
|
|
44
51
|
framed: !1
|
|
45
52
|
}
|
|
46
53
|
) });
|
|
47
54
|
}
|
|
48
|
-
const
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
/* @__PURE__ */
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/* @__PURE__ */
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
return /* @__PURE__ */
|
|
64
|
-
/* @__PURE__ */
|
|
65
|
-
/* @__PURE__ */
|
|
55
|
+
const h = t.map(_), [, k] = x(h, m), C = (e) => `${(k > 0 ? Math.min(e / k, 1) * 100 : 0).toString()}%`;
|
|
56
|
+
return /* @__PURE__ */ d("div", { className: y, children: [
|
|
57
|
+
/* @__PURE__ */ l(
|
|
58
|
+
z,
|
|
59
|
+
{
|
|
60
|
+
items: n.map((e) => ({
|
|
61
|
+
key: e.key,
|
|
62
|
+
label: e.label,
|
|
63
|
+
color: e.color
|
|
64
|
+
}))
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ d("div", { className: "aegis-stacked-bar__rows", children: [
|
|
68
|
+
t.map((e, s) => {
|
|
69
|
+
const r = h[s];
|
|
70
|
+
return /* @__PURE__ */ d("div", { className: "aegis-stacked-bar__row", children: [
|
|
71
|
+
/* @__PURE__ */ l("div", { className: "aegis-stacked-bar__label", children: e.label }),
|
|
72
|
+
/* @__PURE__ */ l(
|
|
66
73
|
"div",
|
|
67
74
|
{
|
|
68
75
|
className: "aegis-stacked-bar__track",
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
...i ? {} : {
|
|
77
|
+
role: "img",
|
|
78
|
+
"aria-label": n.map(
|
|
79
|
+
(a) => `${a.label} ${c(e.values[a.key])}`
|
|
80
|
+
).join(", ")
|
|
81
|
+
},
|
|
82
|
+
children: /* @__PURE__ */ l(
|
|
74
83
|
"div",
|
|
75
84
|
{
|
|
76
|
-
className:
|
|
85
|
+
className: r === 0 ? "aegis-stacked-bar__bar aegis-stacked-bar__bar--zero" : "aegis-stacked-bar__bar",
|
|
77
86
|
style: {
|
|
78
|
-
width:
|
|
79
|
-
"--aegis-stacked-bar-index":
|
|
87
|
+
width: g && r > 0 ? "100%" : C(r),
|
|
88
|
+
"--aegis-stacked-bar-index": s,
|
|
89
|
+
...o === void 0 ? {} : {
|
|
90
|
+
"--aegis-stacked-bar-progress": T(
|
|
91
|
+
o,
|
|
92
|
+
s,
|
|
93
|
+
t.length
|
|
94
|
+
)
|
|
95
|
+
}
|
|
80
96
|
},
|
|
81
|
-
children:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
children: /* @__PURE__ */ l("div", { className: "aegis-stacked-bar__segments", children: n.filter((a) => e.values[a.key] > 0).map((a) => {
|
|
98
|
+
const v = [
|
|
99
|
+
"aegis-stacked-bar__segment",
|
|
100
|
+
a.color === "unknown" ? "aegis-stacked-bar__segment--unknown" : ""
|
|
101
|
+
].filter(Boolean).join(" "), p = {
|
|
102
|
+
width: `${(e.values[a.key] / r * 100).toString()}%`,
|
|
103
|
+
background: D(a.color)
|
|
104
|
+
};
|
|
105
|
+
return i && j(e.key, a.key) ? /* @__PURE__ */ l(
|
|
106
|
+
"button",
|
|
107
|
+
{
|
|
108
|
+
type: "button",
|
|
109
|
+
className: `${v} aegis-stacked-bar__segment--button`,
|
|
110
|
+
style: p,
|
|
111
|
+
"aria-label": `${a.label} ${c(e.values[a.key])}`,
|
|
112
|
+
title: `${a.label} ${c(e.values[a.key])}`,
|
|
113
|
+
onClick: () => {
|
|
114
|
+
i(e.key, a.key);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
a.key
|
|
118
|
+
) : /* @__PURE__ */ l(
|
|
119
|
+
"span",
|
|
120
|
+
{
|
|
121
|
+
className: v,
|
|
122
|
+
style: p
|
|
123
|
+
},
|
|
124
|
+
a.key
|
|
125
|
+
);
|
|
126
|
+
}) })
|
|
91
127
|
}
|
|
92
128
|
)
|
|
93
129
|
}
|
|
94
130
|
),
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
|
|
97
|
-
] },
|
|
131
|
+
/* @__PURE__ */ l("span", { className: "aegis-stacked-bar__value", children: c(r) }),
|
|
132
|
+
u && /* @__PURE__ */ l("span", { className: "aegis-stacked-bar__note", children: e.note })
|
|
133
|
+
] }, e.key);
|
|
98
134
|
}),
|
|
99
|
-
/* @__PURE__ */
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
|
|
102
|
-
/* @__PURE__ */
|
|
135
|
+
!g && /* @__PURE__ */ d("div", { className: "aegis-stacked-bar__scale", children: [
|
|
136
|
+
/* @__PURE__ */ l("span", { children: c(0) }),
|
|
137
|
+
b !== void 0 && /* @__PURE__ */ l("span", { className: "aegis-stacked-bar__direction", children: b }),
|
|
138
|
+
/* @__PURE__ */ l("span", { children: c(k) })
|
|
103
139
|
] })
|
|
104
140
|
] })
|
|
105
141
|
] });
|
|
106
142
|
}
|
|
107
143
|
export {
|
|
108
|
-
|
|
144
|
+
V as StackedBar
|
|
109
145
|
};
|
|
110
146
|
//# sourceMappingURL=StackedBar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StackedBar.js","sources":["../../../src/components/ui/StackedBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport { DataTable, type DataTableColumn } from './DataTable';\nimport './StackedBar.css';\n\n/**\n * Segment colour from the data palette: `seq` for a single magnitude,\n * `cat-1`…`cat-6` to tell categories apart, `unknown` a neutral muted fill\n * with a hairline edge for a share not classified yet.\n */\nexport type StackedBarColor =\n | 'seq'\n | 'cat-1'\n | 'cat-2'\n | 'cat-3'\n | 'cat-4'\n | 'cat-5'\n | 'cat-6'\n | 'unknown';\n\n/** One category stacked in every bar, listed in the legend. */\nexport interface StackedBarSeries<K extends string> {\n key: K;\n /** Legend text; also names the segment in each bar's accessible label. */\n label: string;\n color: StackedBarColor;\n}\n\nexport interface StackedBarRow<K extends string> {\n key: string;\n label: ReactNode;\n /** Every series' value in this row, keyed by series key. */\n values: Readonly<Record<K, number>>;\n /** Muted text after the row total, e.g. \"已复核 30\". */\n note?: ReactNode;\n}\n\nexport interface StackedBarProps<K extends string> {\n /** Categories, stacked left to right in this order. */\n series: Array<StackedBarSeries<K>>;\n rows: Array<StackedBarRow<K>>;\n /** Upper bound of the scale. Defaults to the largest row total, or 1 when all are 0. */\n max?: number;\n /** Scale hint between the 0 and maximum ticks, e.g. \"越低越好\". */\n direction?: ReactNode;\n format?: (value: number) => string;\n /**\n * `table` lists the same rows as a data table in place of the bars, for\n * the host's \"查看数据表\" control.\n */\n view?: 'chart' | 'table';\n /** Table header of the row label column, e.g. \"模型\". */\n labelHeader: ReactNode;\n /** Table header of the row total column, e.g. \"合计\". */\n totalHeader: ReactNode;\n className?: string;\n}\n\n/**\n * Horizontal stacked bars on one shared scale: a label, the series\n * segments of each row drawn in from the left, and the row total.\n */\nexport function StackedBar<K extends string>({\n series,\n rows,\n max,\n direction,\n format = String,\n view = 'chart',\n labelHeader,\n totalHeader,\n className,\n}: StackedBarProps<K>) {\n const rowTotal = (row: StackedBarRow<K>): number =>\n series.reduce((sum, item) => sum + row.values[item.key], 0);\n const noted = rows.some((row) => row.note !== undefined);\n const cls = [\n 'aegis-stacked-bar',\n noted ? 'aegis-stacked-bar--noted' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n if (view === 'table') {\n const columns: Array<DataTableColumn<StackedBarRow<K>>> = [\n { key: 'label', header: labelHeader, render: (row) => row.label },\n ...series.map(\n (item): DataTableColumn<StackedBarRow<K>> => ({\n key: `series:${item.key}`,\n header: item.label,\n numeric: true,\n render: (row) => format(row.values[item.key]),\n }),\n ),\n {\n key: 'total',\n header: totalHeader,\n numeric: true,\n render: (row) => format(rowTotal(row)),\n },\n ];\n return (\n <div className={cls}>\n <DataTable\n columns={columns}\n data={rows}\n rowKey={(row) => row.key}\n framed={false}\n />\n </div>\n );\n }\n\n const totals = rows.map(rowTotal);\n const upperBound = max ?? (Math.max(0, ...totals) || 1);\n const scaleWidth = (value: number): string =>\n `${(upperBound > 0 ? Math.min(value / upperBound, 1) * 100 : 0).toString()}%`;\n return (\n <div className={cls}>\n <ul className=\"aegis-stacked-bar__legend\">\n {series.map((item) => (\n <li key={item.key} className=\"aegis-stacked-bar__legend-item\">\n <span\n className={`aegis-stacked-bar__swatch aegis-stacked-bar__mark--${item.color}`}\n aria-hidden=\"true\"\n />\n {item.label}\n </li>\n ))}\n </ul>\n <div className=\"aegis-stacked-bar__rows\">\n {rows.map((row, index) => {\n const total = totals[index];\n return (\n <div className=\"aegis-stacked-bar__row\" key={row.key}>\n <div className=\"aegis-stacked-bar__label\">{row.label}</div>\n <div\n className=\"aegis-stacked-bar__track\"\n role=\"img\"\n aria-label={series\n .map(\n (item) => `${item.label} ${format(row.values[item.key])}`,\n )\n .join(', ')}\n >\n <div\n className={\n total === 0\n ? 'aegis-stacked-bar__bar aegis-stacked-bar__bar--zero'\n : 'aegis-stacked-bar__bar'\n }\n style={\n {\n width: scaleWidth(total),\n '--aegis-stacked-bar-index': index,\n } as CSSProperties\n }\n >\n {series\n .filter((item) => row.values[item.key] > 0)\n .map((item) => (\n <span\n key={item.key}\n className={`aegis-stacked-bar__segment aegis-stacked-bar__mark--${item.color}`}\n style={{\n width: `${((row.values[item.key] / total) * 100).toString()}%`,\n }}\n />\n ))}\n </div>\n </div>\n <span className=\"aegis-stacked-bar__value\">{format(total)}</span>\n {noted && (\n <span className=\"aegis-stacked-bar__note\">{row.note}</span>\n )}\n </div>\n );\n })}\n <div className=\"aegis-stacked-bar__scale\">\n <span>{format(0)}</span>\n {direction !== undefined && (\n <span className=\"aegis-stacked-bar__direction\">{direction}</span>\n )}\n <span>{format(upperBound)}</span>\n </div>\n </div>\n </div>\n );\n}\n"],"names":["StackedBar","series","rows","max","direction","format","view","labelHeader","totalHeader","className","rowTotal","row","sum","item","noted","cls","columns","jsx","DataTable","totals","upperBound","scaleWidth","value","jsxs","index","total"],"mappings":";;;AA8DO,SAASA,EAA6B;AAAA,EAC3C,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,KAAAC;AAAA,EACA,WAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,MAAAC,IAAO;AAAA,EACP,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AACF,GAAuB;AACrB,QAAMC,IAAW,CAACC,MAChBV,EAAO,OAAO,CAACW,GAAKC,MAASD,IAAMD,EAAI,OAAOE,EAAK,GAAG,GAAG,CAAC,GACtDC,IAAQZ,EAAK,KAAK,CAACS,MAAQA,EAAI,SAAS,MAAS,GACjDI,IAAM;AAAA,IACV;AAAA,IACAD,IAAQ,6BAA6B;AAAA,IACrCL,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,MAAIH,MAAS,SAAS;AACpB,UAAMU,IAAoD;AAAA,MACxD,EAAE,KAAK,SAAS,QAAQT,GAAa,QAAQ,CAACI,MAAQA,EAAI,MAAA;AAAA,MAC1D,GAAGV,EAAO;AAAA,QACR,CAACY,OAA6C;AAAA,UAC5C,KAAK,UAAUA,EAAK,GAAG;AAAA,UACvB,QAAQA,EAAK;AAAA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AAAA,QAChBD,MAAc,UACb,gBAAAa,EAAC,QAAA,EAAK,WAAU,gCAAgC,UAAAb,GAAU;AAAA,QAE5D,gBAAAa,EAAC,QAAA,EAAM,UAAAZ,EAAOe,CAAU,EAAA,CAAE;AAAA,MAAA,EAAA,CAC5B;AAAA,IAAA,EAAA,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"StackedBar.js","sources":["../../../src/components/ui/StackedBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { ChartLegend } from './ChartLegend';\nimport { DataTable, type DataTableColumn } from './DataTable';\nimport './StackedBar.css';\n\n/** One category stacked in every bar, listed in the legend. */\nexport interface StackedBarSeries<K extends string> {\n key: K;\n /** Legend text; also names the segment in each bar's accessible label. */\n label: string;\n color: ChartColor;\n}\n\nexport interface StackedBarRow<K extends string> {\n key: string;\n label: ReactNode;\n /** Every series' value in this row, keyed by series key. */\n values: Readonly<Record<K, number>>;\n /** Muted text after the row total, e.g. \"已复核 30\". */\n note?: ReactNode;\n}\n\nexport interface StackedBarProps<K extends string> {\n /** Categories, stacked left to right in this order. */\n series: Array<StackedBarSeries<K>>;\n rows: Array<StackedBarRow<K>>;\n /** Upper bound of the scale. Defaults to the largest row total, or 1 when all are 0. */\n max?: number;\n /** Scale hint between the 0 and maximum ticks, e.g. \"越低越好\". */\n direction?: ReactNode;\n format?: (value: number) => string;\n /**\n * `table` lists the same rows as a data table in place of the bars, for\n * the host's \"查看数据表\" control.\n */\n view?: 'chart' | 'table';\n /** Table header of the row label column, e.g. \"模型\". */\n labelHeader: ReactNode;\n /** Table header of the row total column, e.g. \"合计\". */\n totalHeader: ReactNode;\n /**\n * Draws every bar across the full width, so a row reads as its own\n * composition rather than against the others; the scale is left out.\n */\n normalize?: boolean;\n /** Makes each segment a button, e.g. one that opens that row's runs of the series. */\n onSegmentSelect?: (rowKey: string, seriesKey: K) => void;\n /**\n * Whether a segment has something to open; the rest stay plain bars, so\n * no button leads nowhere. Defaults to every segment.\n */\n isSegmentSelectable?: (rowKey: string, seriesKey: K) => boolean;\n /**\n * How far the bars are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, the bars draw in\n * once when they mount.\n */\n progress?: number;\n className?: string;\n}\n\n/**\n * Horizontal stacked bars on one shared scale: a label, the series\n * segments of each row drawn in from the left, and the row total.\n */\nexport function StackedBar<K extends string>({\n series,\n rows,\n max,\n direction,\n format = String,\n view = 'chart',\n labelHeader,\n totalHeader,\n normalize = false,\n onSegmentSelect,\n isSegmentSelectable = () => true,\n progress,\n className,\n}: StackedBarProps<K>) {\n const rowTotal = (row: StackedBarRow<K>): number =>\n series.reduce((sum, item) => sum + row.values[item.key], 0);\n const noted = rows.some((row) => row.note !== undefined);\n const cls = [\n 'aegis-stacked-bar',\n noted ? 'aegis-stacked-bar--noted' : '',\n progress === undefined ? '' : 'aegis-stacked-bar--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n if (view === 'table') {\n const columns: Array<DataTableColumn<StackedBarRow<K>>> = [\n { key: 'label', header: labelHeader, render: (row) => row.label },\n ...series.map(\n (item): DataTableColumn<StackedBarRow<K>> => ({\n key: `series:${item.key}`,\n header: item.label,\n numeric: true,\n render: (row) => format(row.values[item.key]),\n }),\n ),\n {\n key: 'total',\n header: totalHeader,\n numeric: true,\n render: (row) => format(rowTotal(row)),\n },\n ];\n return (\n <div className={cls}>\n <DataTable\n columns={columns}\n data={rows}\n rowKey={(row) => row.key}\n framed={false}\n />\n </div>\n );\n }\n\n const totals = rows.map(rowTotal);\n const [, upperBound] = zeroAnchoredDomain(totals, max);\n const scaleWidth = (value: number): string =>\n `${(upperBound > 0 ? Math.min(value / upperBound, 1) * 100 : 0).toString()}%`;\n return (\n <div className={cls}>\n <ChartLegend\n items={series.map((item) => ({\n key: item.key,\n label: item.label,\n color: item.color,\n }))}\n />\n <div className=\"aegis-stacked-bar__rows\">\n {rows.map((row, index) => {\n const total = totals[index];\n return (\n <div className=\"aegis-stacked-bar__row\" key={row.key}>\n <div className=\"aegis-stacked-bar__label\">{row.label}</div>\n <div\n className=\"aegis-stacked-bar__track\"\n {...(onSegmentSelect\n ? {}\n : {\n role: 'img',\n 'aria-label': series\n .map(\n (item) =>\n `${item.label} ${format(row.values[item.key])}`,\n )\n .join(', '),\n })}\n >\n <div\n className={\n total === 0\n ? 'aegis-stacked-bar__bar aegis-stacked-bar__bar--zero'\n : 'aegis-stacked-bar__bar'\n }\n style={\n {\n width:\n normalize && total > 0 ? '100%' : scaleWidth(total),\n '--aegis-stacked-bar-index': index,\n ...(progress === undefined\n ? {}\n : {\n '--aegis-stacked-bar-progress': staggeredProgress(\n progress,\n index,\n rows.length,\n ),\n }),\n } as CSSProperties\n }\n >\n <div className=\"aegis-stacked-bar__segments\">\n {series\n .filter((item) => row.values[item.key] > 0)\n .map((item) => {\n const segmentClass = [\n 'aegis-stacked-bar__segment',\n item.color === 'unknown'\n ? 'aegis-stacked-bar__segment--unknown'\n : '',\n ]\n .filter(Boolean)\n .join(' ');\n const segmentStyle = {\n width: `${((row.values[item.key] / total) * 100).toString()}%`,\n background: chartColorValue(item.color),\n };\n return onSegmentSelect &&\n isSegmentSelectable(row.key, item.key) ? (\n <button\n key={item.key}\n type=\"button\"\n className={`${segmentClass} aegis-stacked-bar__segment--button`}\n style={segmentStyle}\n aria-label={`${item.label} ${format(row.values[item.key])}`}\n title={`${item.label} ${format(row.values[item.key])}`}\n onClick={() => {\n onSegmentSelect(row.key, item.key);\n }}\n />\n ) : (\n <span\n key={item.key}\n className={segmentClass}\n style={segmentStyle}\n />\n );\n })}\n </div>\n </div>\n </div>\n <span className=\"aegis-stacked-bar__value\">{format(total)}</span>\n {noted && (\n <span className=\"aegis-stacked-bar__note\">{row.note}</span>\n )}\n </div>\n );\n })}\n {!normalize && (\n <div className=\"aegis-stacked-bar__scale\">\n <span>{format(0)}</span>\n {direction !== undefined && (\n <span className=\"aegis-stacked-bar__direction\">{direction}</span>\n )}\n <span>{format(upperBound)}</span>\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"names":["StackedBar","series","rows","max","direction","format","view","labelHeader","totalHeader","normalize","onSegmentSelect","isSegmentSelectable","progress","className","rowTotal","row","sum","item","noted","cls","columns","jsx","DataTable","totals","upperBound","zeroAnchoredDomain","scaleWidth","value","jsxs","ChartLegend","index","total","staggeredProgress","segmentClass","segmentStyle","chartColorValue"],"mappings":";;;;;AAwEO,SAASA,EAA6B;AAAA,EAC3C,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,KAAAC;AAAA,EACA,WAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,MAAAC,IAAO;AAAA,EACP,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,iBAAAC;AAAA,EACA,qBAAAC,IAAsB,MAAM;AAAA,EAC5B,UAAAC;AAAA,EACA,WAAAC;AACF,GAAuB;AACrB,QAAMC,IAAW,CAACC,MAChBd,EAAO,OAAO,CAACe,GAAKC,MAASD,IAAMD,EAAI,OAAOE,EAAK,GAAG,GAAG,CAAC,GACtDC,IAAQhB,EAAK,KAAK,CAACa,MAAQA,EAAI,SAAS,MAAS,GACjDI,IAAM;AAAA,IACV;AAAA,IACAD,IAAQ,6BAA6B;AAAA,IACrCN,MAAa,SAAY,KAAK;AAAA,IAC9BC,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,MAAIP,MAAS,SAAS;AACpB,UAAMc,IAAoD;AAAA,MACxD,EAAE,KAAK,SAAS,QAAQb,GAAa,QAAQ,CAACQ,MAAQA,EAAI,MAAA;AAAA,MAC1D,GAAGd,EAAO;AAAA,QACR,CAACgB,OAA6C;AAAA,UAC5C,KAAK,UAAUA,EAAK,GAAG;AAAA,UACvB,QAAQA,EAAK;AAAA,UACb,S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OE,EAAK,GAAG,CAAC,CAAC;AAAA,wBACzD,OAAO,GAAGA,EAAK,KAAK,IAAIZ,EAAOU,EAAI,OAAOE,EAAK,GAAG,CAAC,CAAC;AAAA,wBACpD,SAAS,MAAM;AACb,0BAAAP,EAAgBK,EAAI,KAAKE,EAAK,GAAG;AAAA,wBACnC;AAAA,sBAAA;AAAA,sBARKA,EAAK;AAAA,oBAAA,IAWZ,gBAAAI;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBAEC,WAAWY;AAAA,wBACX,OAAOC;AAAA,sBAAA;AAAA,sBAFFjB,EAAK;AAAA,oBAAA;AAAA,kBAKhB,CAAC,EAAA,CACL;AAAA,gBAAA;AAAA,cAAA;AAAA,YACF;AAAA,UAAA;AAAA,4BAED,QAAA,EAAK,WAAU,4BAA4B,UAAAZ,EAAO0B,CAAK,GAAE;AAAA,UACzDb,KACC,gBAAAG,EAAC,QAAA,EAAK,WAAU,2BAA2B,YAAI,KAAA,CAAK;AAAA,QAAA,EAAA,GAjFXN,EAAI,GAmFjD;AAAA,MAEJ,CAAC;AAAA,MACA,CAACN,KACA,gBAAAmB,EAAC,OAAA,EAAI,WAAU,4BACb,UAAA;AAAA,QAAA,gBAAAP,EAAC,QAAA,EAAM,UAAAhB,EAAO,CAAC,EAAA,CAAE;AAAA,QAChBD,MAAc,UACb,gBAAAiB,EAAC,QAAA,EAAK,WAAU,gCAAgC,UAAAjB,GAAU;AAAA,QAE5D,gBAAAiB,EAAC,QAAA,EAAM,UAAAhB,EAAOmB,CAAU,EAAA,CAAE;AAAA,MAAA,EAAA,CAC5B;AAAA,IAAA,EAAA,CAEJ;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),b=require("../../hooks/useSectionSpy.cjs");;/* empty css */const f=require("../../locale/useStrings.cjs"),v=25;function C({items:s,currentId:t,onCurrentChange:a,scrollContainer:c=null,className:o}){const r=f.useStrings(),{activeId:u,onLinkClick:d}=b.useSectionSpy({ids:s.map(e=>e.id),activationPercent:v,currentId:t,onCurrentChange:a,scrollContainer:c}),_=["aegis-toc",o??""].filter(Boolean).join(" ");return n.jsx("nav",{"aria-label":r.tableOfContents,className:_,children:n.jsx("ol",{className:"aegis-toc__list",children:s.map(e=>{const i=e.id===u,l=e.level??1,g=["aegis-toc__link",i?"aegis-toc__link--current":"",l>1?`aegis-toc__link--level-${l}`:""].filter(Boolean).join(" ");return n.jsx("li",{children:n.jsxs("a",{href:`#${e.id}`,className:g,"aria-current":i?"location":void 0,onClick:j=>{d(j,e.id)},children:[n.jsx("span",{className:"aegis-toc__indicator","aria-hidden":"true"}),n.jsx("span",{className:"aegis-toc__label",children:e.label})]})},e.id)})})})}exports.TableOfContents=C;
|
|
2
2
|
//# sourceMappingURL=TableOfContents.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableOfContents.cjs","sources":["../../../src/components/ui/TableOfContents.tsx"],"sourcesContent":["import {\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n activationRootMargin,\n findCurrentIndex,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport { useStrings } from '../../locale';\nimport './TableOfContents.css';\n\nexport interface TableOfContentsItem {\n /** The id of the section element, already in the document, the item links to. */\n id: string;\n label: ReactNode;\n /** Nesting depth of the section; 2 and 3 indent the label. Defaults to 1. */\n level?: 1 | 2 | 3;\n}\n\nexport interface TableOfContentsProps {\n /** The sections in document order. */\n items: TableOfContentsItem[];\n /** Controls the current item; omit it to follow the scroll position. */\n currentId?: string;\n /** Called with the id that scrolling or a click makes current. */\n onCurrentChange?: (id: string) => void;\n /** The element that scrolls the sections; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\n/** A section becomes current once its top passes this share of the view. */\nconst ACTIVATION_PERCENT = 25;\nconst REDUCED_MOTION = '(prefers-reduced-motion: reduce)';\n\n/**\n * The section a click scrolled to keeps the highlight while the scroll\n * runs (`settled` false until scrollend) and afterwards for as long as the\n * view stays at `top`, even if the geometry would pick another section.\n */\ninterface ClickScroll {\n top: number;\n settled: boolean;\n}\n\nfunction isScrolledTo(container: HTMLElement | null, top: number): boolean {\n return Math.abs(scrollerOf(container).scrollTop - top) < 1;\n}\n\n/** The scroll offset that puts the section's top, less its scroll-margin, at the top of the view. */\nfunction sectionScrollTop(\n section: HTMLElement,\n container: HTMLElement | null,\n): number {\n const scroller = scrollerOf(container);\n const margin = parseFloat(getComputedStyle(section).scrollMarginTop);\n const top =\n section.getBoundingClientRect().top -\n viewBoundsOf(container).top +\n scroller.scrollTop -\n margin;\n return Math.min(\n Math.max(top, 0),\n scroller.scrollHeight - scroller.clientHeight,\n );\n}\n\nexport function TableOfContents({\n items,\n currentId,\n onCurrentChange,\n scrollContainer = null,\n className,\n}: TableOfContentsProps): ReactElement {\n const strings = useStrings();\n const [trackedId, setTrackedId] = useState(() => items[0]?.id);\n const trackedIdRef = useRef(trackedId);\n const onCurrentChangeRef = useRef(onCurrentChange);\n const clickScrollRef = useRef<ClickScroll | null>(null);\n const activeId = currentId ?? trackedId;\n const sectionIds = items.map((item) => item.id).join(' ');\n\n useEffect(() => {\n onCurrentChangeRef.current = onCurrentChange;\n }, [onCurrentChange]);\n\n const track = useCallback((id: string): void => {\n if (id === trackedIdRef.current) {\n return;\n }\n trackedIdRef.current = id;\n setTrackedId(id);\n onCurrentChangeRef.current?.(id);\n }, []);\n\n useEffect(() => {\n const sections = sectionIds.split(' ').flatMap((id) => {\n const section = document.getElementById(id);\n return section ? [section] : [];\n });\n if (sections.length === 0) {\n return undefined;\n }\n const sync = (): void => {\n const clickScroll = clickScrollRef.current;\n if (clickScroll) {\n if (\n !clickScroll.settled ||\n isScrolledTo(scrollContainer, clickScroll.top)\n ) {\n return;\n }\n clickScrollRef.current = null;\n }\n track(\n sections[\n findCurrentIndex(sections, scrollContainer, ACTIVATION_PERCENT)\n ].id,\n );\n };\n /* A jump can skip the activation band without an intersection change,\n * so the settled position is checked again. */\n const handleScrollEnd = (): void => {\n if (clickScrollRef.current) {\n clickScrollRef.current = { ...clickScrollRef.current, settled: true };\n }\n sync();\n };\n const observer = new IntersectionObserver(sync, {\n root: scrollContainer,\n rootMargin: activationRootMargin(ACTIVATION_PERCENT),\n });\n for (const section of sections) {\n observer.observe(section);\n }\n const scrollEvents: EventTarget = scrollContainer ?? document;\n scrollEvents.addEventListener('scrollend', handleScrollEnd);\n return () => {\n observer.disconnect();\n scrollEvents.removeEventListener('scrollend', handleScrollEnd);\n };\n }, [sectionIds, scrollContainer, track]);\n\n const handleClick = (\n event: MouseEvent<HTMLAnchorElement>,\n id: string,\n ): void => {\n if (\n event.button !== 0 ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey\n ) {\n return;\n }\n event.preventDefault();\n if (id !== activeId) {\n onCurrentChange?.(id);\n }\n trackedIdRef.current = id;\n setTrackedId(id);\n const section = document.getElementById(id);\n if (!section) {\n return;\n }\n // As an in-page link does: the URL names the section, and the next Tab\n // continues from the section rather than from the contents.\n window.history.replaceState(window.history.state, '', `#${id}`);\n if (!section.hasAttribute('tabindex')) {\n section.tabIndex = -1;\n }\n section.focus({ preventScroll: true });\n const top = sectionScrollTop(section, scrollContainer);\n const arrived = isScrolledTo(scrollContainer, top);\n /* Without scrollend support nothing would settle the click. */\n clickScrollRef.current = {\n top,\n settled: arrived || !('onscrollend' in window),\n };\n if (arrived) {\n return;\n }\n scrollerOf(scrollContainer).scrollTo({\n top,\n behavior: window.matchMedia(REDUCED_MOTION).matches\n ? 'instant'\n : 'smooth',\n });\n };\n\n const cls = ['aegis-toc', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <nav aria-label={strings.tableOfContents} className={cls}>\n <ol className=\"aegis-toc__list\">\n {items.map((item) => {\n const current = item.id === activeId;\n const level = item.level ?? 1;\n const linkCls = [\n 'aegis-toc__link',\n current ? 'aegis-toc__link--current' : '',\n level > 1 ? `aegis-toc__link--level-${level}` : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <li key={item.id}>\n <a\n href={`#${item.id}`}\n className={linkCls}\n aria-current={current ? 'location' : undefined}\n onClick={(event) => {\n handleClick(event, item.id);\n }}\n >\n <span className=\"aegis-toc__indicator\" aria-hidden=\"true\" />\n <span className=\"aegis-toc__label\">{item.label}</span>\n </a>\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["ACTIVATION_PERCENT","REDUCED_MOTION","isScrolledTo","container","top","scrollerOf","sectionScrollTop","section","scroller","margin","viewBoundsOf","TableOfContents","items","currentId","onCurrentChange","scrollContainer","className","strings","useStrings","trackedId","setTrackedId","useState","trackedIdRef","useRef","onCurrentChangeRef","clickScrollRef","activeId","sectionIds","item","useEffect","track","useCallback","id","sections","sync","clickScroll","findCurrentIndex","handleScrollEnd","observer","activationRootMargin","scrollEvents","handleClick","event","arrived","cls","jsx","current","level","linkCls","jsxs"],"mappings":"kQAwCMA,EAAqB,GACrBC,EAAiB,mCAYvB,SAASC,EAAaC,EAA+BC,EAAsB,CACzE,OAAO,KAAK,IAAIC,EAAAA,WAAWF,CAAS,EAAE,UAAYC,CAAG,EAAI,CAC3D,CAGA,SAASE,EACPC,EACAJ,EACQ,CACR,MAAMK,EAAWH,EAAAA,WAAWF,CAAS,EAC/BM,EAAS,WAAW,iBAAiBF,CAAO,EAAE,eAAe,EAC7DH,EACJG,EAAQ,sBAAA,EAAwB,IAChCG,eAAaP,CAAS,EAAE,IACxBK,EAAS,UACTC,EACF,OAAO,KAAK,IACV,KAAK,IAAIL,EAAK,CAAC,EACfI,EAAS,aAAeA,EAAS,YAAA,CAErC,CAEO,SAASG,EAAgB,CAC9B,MAAAC,EACA,UAAAC,EACA,gBAAAC,EACA,gB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K,KAAOF,EACtBqB,EAAQnB,EAAK,OAAS,EACtBoB,EAAU,CACd,kBACAF,EAAU,2BAA6B,GACvCC,EAAQ,EAAI,0BAA0BA,CAAK,GAAK,EAAA,EAE/C,OAAO,OAAO,EACd,KAAK,GAAG,EACX,aACG,KAAA,CACC,SAAAE,EAAAA,KAAC,IAAA,CACC,KAAM,IAAIrB,EAAK,EAAE,GACjB,UAAWoB,EACX,eAAcF,EAAU,WAAa,OACrC,QAAUJ,GAAU,CAClBD,EAAYC,EAAOd,EAAK,EAAE,CAC5B,EAEA,SAAA,CAAAiB,EAAAA,IAAC,OAAA,CAAK,UAAU,uBAAuB,cAAY,OAAO,EAC1DA,EAAAA,IAAC,OAAA,CAAK,UAAU,mBAAoB,WAAK,KAAA,CAAM,CAAA,CAAA,CAAA,CACjD,EAXOjB,EAAK,EAYd,CAEJ,CAAC,EACH,EACF,CAEJ"}
|
|
1
|
+
{"version":3,"file":"TableOfContents.cjs","sources":["../../../src/components/ui/TableOfContents.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport { useSectionSpy } from '../../hooks/useSectionSpy';\nimport { useStrings } from '../../locale';\nimport './TableOfContents.css';\n\nexport interface TableOfContentsItem {\n /** The id of the section element, already in the document, the item links to. */\n id: string;\n label: ReactNode;\n /** Nesting depth of the section; 2 and 3 indent the label. Defaults to 1. */\n level?: 1 | 2 | 3;\n}\n\nexport interface TableOfContentsProps {\n /** The sections in document order. */\n items: TableOfContentsItem[];\n /** Controls the current item; omit it to follow the scroll position. */\n currentId?: string;\n /** Called with the id that scrolling or a click makes current. */\n onCurrentChange?: (id: string) => void;\n /** The element that scrolls the sections; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\n/** A section becomes current once its top passes this share of the view. */\nconst ACTIVATION_PERCENT = 25;\n\nexport function TableOfContents({\n items,\n currentId,\n onCurrentChange,\n scrollContainer = null,\n className,\n}: TableOfContentsProps): ReactElement {\n const strings = useStrings();\n const { activeId, onLinkClick } = useSectionSpy({\n ids: items.map((item) => item.id),\n activationPercent: ACTIVATION_PERCENT,\n currentId,\n onCurrentChange,\n scrollContainer,\n });\n\n const cls = ['aegis-toc', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <nav aria-label={strings.tableOfContents} className={cls}>\n <ol className=\"aegis-toc__list\">\n {items.map((item) => {\n const current = item.id === activeId;\n const level = item.level ?? 1;\n const linkCls = [\n 'aegis-toc__link',\n current ? 'aegis-toc__link--current' : '',\n level > 1 ? `aegis-toc__link--level-${level}` : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <li key={item.id}>\n <a\n href={`#${item.id}`}\n className={linkCls}\n aria-current={current ? 'location' : undefined}\n onClick={(event) => {\n onLinkClick(event, item.id);\n }}\n >\n <span className=\"aegis-toc__indicator\" aria-hidden=\"true\" />\n <span className=\"aegis-toc__label\">{item.label}</span>\n </a>\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["ACTIVATION_PERCENT","TableOfContents","items","currentId","onCurrentChange","scrollContainer","className","strings","useStrings","activeId","onLinkClick","useSectionSpy","item","cls","jsx","current","level","linkCls","jsxs","event"],"mappings":"oPA2BMA,EAAqB,GAEpB,SAASC,EAAgB,CAC9B,MAAAC,EACA,UAAAC,EACA,gBAAAC,EACA,gBAAAC,EAAkB,KAClB,UAAAC,CACF,EAAuC,CACrC,MAAMC,EAAUC,EAAAA,WAAA,EACV,CAAE,SAAAC,EAAU,YAAAC,CAAA,EAAgBC,gBAAc,CAC9C,IAAKT,EAAM,IAAKU,GAASA,EAAK,EAAE,EAChC,kBAAmBZ,EACnB,UAAAG,EACA,gBAAAC,EACA,gBAAAC,CAAA,CACD,EAEKQ,EAAM,CAAC,YAAaP,GAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAEnE,OACEQ,EAAAA,IAAC,MAAA,CAAI,aAAYP,EAAQ,gBAAiB,UAAWM,EACnD,SAAAC,EAAAA,IAAC,KAAA,CAAG,UAAU,kBACX,SAAAZ,EAAM,IAAKU,GAAS,CACnB,MAAMG,EAAUH,EAAK,KAAOH,EACtBO,EAAQJ,EAAK,OAAS,EACtBK,EAAU,CACd,kBACAF,EAAU,2BAA6B,GACvCC,EAAQ,EAAI,0BAA0BA,CAAK,GAAK,EAAA,EAE/C,OAAO,OAAO,EACd,KAAK,GAAG,EACX,aACG,KAAA,CACC,SAAAE,EAAAA,KAAC,IAAA,CACC,KAAM,IAAIN,EAAK,EAAE,GACjB,UAAWK,EACX,eAAcF,EAAU,WAAa,OACrC,QAAUI,GAAU,CAClBT,EAAYS,EAAOP,EAAK,EAAE,CAC5B,EAEA,SAAA,CAAAE,EAAAA,IAAC,OAAA,CAAK,UAAU,uBAAuB,cAAY,OAAO,EAC1DA,EAAAA,IAAC,OAAA,CAAK,UAAU,mBAAoB,WAAK,KAAA,CAAM,CAAA,CAAA,CAAA,CACjD,EAXOF,EAAK,EAYd,CAEJ,CAAC,EACH,EACF,CAEJ"}
|
|
@@ -1,104 +1,46 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import { activationRootMargin as B, findCurrentIndex as j, scrollerOf as h, viewBoundsOf as K } from "../../lib/scrollView.js";
|
|
1
|
+
import { jsx as i, jsxs as g } from "react/jsx-runtime";
|
|
2
|
+
import { useSectionSpy as m } from "../../hooks/useSectionSpy.js";
|
|
4
3
|
/* empty css */
|
|
5
|
-
import { useStrings as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Math.max(f, 0),
|
|
14
|
-
c.scrollHeight - c.clientHeight
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
function U({
|
|
18
|
-
items: r,
|
|
19
|
-
currentId: a,
|
|
20
|
-
onCurrentChange: c,
|
|
21
|
-
scrollContainer: o = null,
|
|
22
|
-
className: f
|
|
4
|
+
import { useStrings as h } from "../../locale/useStrings.js";
|
|
5
|
+
const k = 25;
|
|
6
|
+
function j({
|
|
7
|
+
items: e,
|
|
8
|
+
currentId: o,
|
|
9
|
+
onCurrentChange: s,
|
|
10
|
+
scrollContainer: c = null,
|
|
11
|
+
className: t
|
|
23
12
|
}) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, []);
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const T = document.getElementById(i);
|
|
34
|
-
return T ? [T] : [];
|
|
35
|
-
});
|
|
36
|
-
if (t.length === 0)
|
|
37
|
-
return;
|
|
38
|
-
const e = () => {
|
|
39
|
-
const i = d.current;
|
|
40
|
-
if (i) {
|
|
41
|
-
if (!i.settled || y(o, i.top))
|
|
42
|
-
return;
|
|
43
|
-
d.current = null;
|
|
44
|
-
}
|
|
45
|
-
I(
|
|
46
|
-
t[j(t, o, w)].id
|
|
47
|
-
);
|
|
48
|
-
}, n = () => {
|
|
49
|
-
d.current && (d.current = { ...d.current, settled: !0 }), e();
|
|
50
|
-
}, s = new IntersectionObserver(e, {
|
|
51
|
-
root: o,
|
|
52
|
-
rootMargin: B(w)
|
|
53
|
-
});
|
|
54
|
-
for (const i of t)
|
|
55
|
-
s.observe(i);
|
|
56
|
-
const l = o ?? document;
|
|
57
|
-
return l.addEventListener("scrollend", n), () => {
|
|
58
|
-
s.disconnect(), l.removeEventListener("scrollend", n);
|
|
59
|
-
};
|
|
60
|
-
}, [k, o, I]);
|
|
61
|
-
const M = (t, e) => {
|
|
62
|
-
if (t.button !== 0 || t.metaKey || t.ctrlKey || t.shiftKey || t.altKey)
|
|
63
|
-
return;
|
|
64
|
-
t.preventDefault(), e !== _ && c?.(e), p.current = e, b(e);
|
|
65
|
-
const n = document.getElementById(e);
|
|
66
|
-
if (!n)
|
|
67
|
-
return;
|
|
68
|
-
window.history.replaceState(window.history.state, "", `#${e}`), n.hasAttribute("tabindex") || (n.tabIndex = -1), n.focus({ preventScroll: !0 });
|
|
69
|
-
const s = $(n, o), l = y(o, s);
|
|
70
|
-
d.current = {
|
|
71
|
-
top: s,
|
|
72
|
-
settled: l || !("onscrollend" in window)
|
|
73
|
-
}, !l && h(o).scrollTo({
|
|
74
|
-
top: s,
|
|
75
|
-
behavior: window.matchMedia(D).matches ? "instant" : "smooth"
|
|
76
|
-
});
|
|
77
|
-
}, N = ["aegis-toc", f ?? ""].filter(Boolean).join(" ");
|
|
78
|
-
return /* @__PURE__ */ u("nav", { "aria-label": S.tableOfContents, className: N, children: /* @__PURE__ */ u("ol", { className: "aegis-toc__list", children: r.map((t) => {
|
|
79
|
-
const e = t.id === _, n = t.level ?? 1, s = [
|
|
13
|
+
const r = h(), { activeId: d, onLinkClick: _ } = m({
|
|
14
|
+
ids: e.map((n) => n.id),
|
|
15
|
+
activationPercent: k,
|
|
16
|
+
currentId: o,
|
|
17
|
+
onCurrentChange: s,
|
|
18
|
+
scrollContainer: c
|
|
19
|
+
}), p = ["aegis-toc", t ?? ""].filter(Boolean).join(" ");
|
|
20
|
+
return /* @__PURE__ */ i("nav", { "aria-label": r.tableOfContents, className: p, children: /* @__PURE__ */ i("ol", { className: "aegis-toc__list", children: e.map((n) => {
|
|
21
|
+
const l = n.id === d, a = n.level ?? 1, u = [
|
|
80
22
|
"aegis-toc__link",
|
|
81
|
-
|
|
82
|
-
|
|
23
|
+
l ? "aegis-toc__link--current" : "",
|
|
24
|
+
a > 1 ? `aegis-toc__link--level-${a}` : ""
|
|
83
25
|
].filter(Boolean).join(" ");
|
|
84
|
-
return /* @__PURE__ */
|
|
26
|
+
return /* @__PURE__ */ i("li", { children: /* @__PURE__ */ g(
|
|
85
27
|
"a",
|
|
86
28
|
{
|
|
87
|
-
href: `#${
|
|
88
|
-
className:
|
|
89
|
-
"aria-current":
|
|
90
|
-
onClick: (
|
|
91
|
-
|
|
29
|
+
href: `#${n.id}`,
|
|
30
|
+
className: u,
|
|
31
|
+
"aria-current": l ? "location" : void 0,
|
|
32
|
+
onClick: (f) => {
|
|
33
|
+
_(f, n.id);
|
|
92
34
|
},
|
|
93
35
|
children: [
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
/* @__PURE__ */
|
|
36
|
+
/* @__PURE__ */ i("span", { className: "aegis-toc__indicator", "aria-hidden": "true" }),
|
|
37
|
+
/* @__PURE__ */ i("span", { className: "aegis-toc__label", children: n.label })
|
|
96
38
|
]
|
|
97
39
|
}
|
|
98
|
-
) },
|
|
40
|
+
) }, n.id);
|
|
99
41
|
}) }) });
|
|
100
42
|
}
|
|
101
43
|
export {
|
|
102
|
-
|
|
44
|
+
j as TableOfContents
|
|
103
45
|
};
|
|
104
46
|
//# sourceMappingURL=TableOfContents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableOfContents.js","sources":["../../../src/components/ui/TableOfContents.tsx"],"sourcesContent":["import {\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n activationRootMargin,\n findCurrentIndex,\n scrollerOf,\n viewBoundsOf,\n} from '../../lib/scrollView';\nimport { useStrings } from '../../locale';\nimport './TableOfContents.css';\n\nexport interface TableOfContentsItem {\n /** The id of the section element, already in the document, the item links to. */\n id: string;\n label: ReactNode;\n /** Nesting depth of the section; 2 and 3 indent the label. Defaults to 1. */\n level?: 1 | 2 | 3;\n}\n\nexport interface TableOfContentsProps {\n /** The sections in document order. */\n items: TableOfContentsItem[];\n /** Controls the current item; omit it to follow the scroll position. */\n currentId?: string;\n /** Called with the id that scrolling or a click makes current. */\n onCurrentChange?: (id: string) => void;\n /** The element that scrolls the sections; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\n/** A section becomes current once its top passes this share of the view. */\nconst ACTIVATION_PERCENT = 25;\nconst REDUCED_MOTION = '(prefers-reduced-motion: reduce)';\n\n/**\n * The section a click scrolled to keeps the highlight while the scroll\n * runs (`settled` false until scrollend) and afterwards for as long as the\n * view stays at `top`, even if the geometry would pick another section.\n */\ninterface ClickScroll {\n top: number;\n settled: boolean;\n}\n\nfunction isScrolledTo(container: HTMLElement | null, top: number): boolean {\n return Math.abs(scrollerOf(container).scrollTop - top) < 1;\n}\n\n/** The scroll offset that puts the section's top, less its scroll-margin, at the top of the view. */\nfunction sectionScrollTop(\n section: HTMLElement,\n container: HTMLElement | null,\n): number {\n const scroller = scrollerOf(container);\n const margin = parseFloat(getComputedStyle(section).scrollMarginTop);\n const top =\n section.getBoundingClientRect().top -\n viewBoundsOf(container).top +\n scroller.scrollTop -\n margin;\n return Math.min(\n Math.max(top, 0),\n scroller.scrollHeight - scroller.clientHeight,\n );\n}\n\nexport function TableOfContents({\n items,\n currentId,\n onCurrentChange,\n scrollContainer = null,\n className,\n}: TableOfContentsProps): ReactElement {\n const strings = useStrings();\n const [trackedId, setTrackedId] = useState(() => items[0]?.id);\n const trackedIdRef = useRef(trackedId);\n const onCurrentChangeRef = useRef(onCurrentChange);\n const clickScrollRef = useRef<ClickScroll | null>(null);\n const activeId = currentId ?? trackedId;\n const sectionIds = items.map((item) => item.id).join(' ');\n\n useEffect(() => {\n onCurrentChangeRef.current = onCurrentChange;\n }, [onCurrentChange]);\n\n const track = useCallback((id: string): void => {\n if (id === trackedIdRef.current) {\n return;\n }\n trackedIdRef.current = id;\n setTrackedId(id);\n onCurrentChangeRef.current?.(id);\n }, []);\n\n useEffect(() => {\n const sections = sectionIds.split(' ').flatMap((id) => {\n const section = document.getElementById(id);\n return section ? [section] : [];\n });\n if (sections.length === 0) {\n return undefined;\n }\n const sync = (): void => {\n const clickScroll = clickScrollRef.current;\n if (clickScroll) {\n if (\n !clickScroll.settled ||\n isScrolledTo(scrollContainer, clickScroll.top)\n ) {\n return;\n }\n clickScrollRef.current = null;\n }\n track(\n sections[\n findCurrentIndex(sections, scrollContainer, ACTIVATION_PERCENT)\n ].id,\n );\n };\n /* A jump can skip the activation band without an intersection change,\n * so the settled position is checked again. */\n const handleScrollEnd = (): void => {\n if (clickScrollRef.current) {\n clickScrollRef.current = { ...clickScrollRef.current, settled: true };\n }\n sync();\n };\n const observer = new IntersectionObserver(sync, {\n root: scrollContainer,\n rootMargin: activationRootMargin(ACTIVATION_PERCENT),\n });\n for (const section of sections) {\n observer.observe(section);\n }\n const scrollEvents: EventTarget = scrollContainer ?? document;\n scrollEvents.addEventListener('scrollend', handleScrollEnd);\n return () => {\n observer.disconnect();\n scrollEvents.removeEventListener('scrollend', handleScrollEnd);\n };\n }, [sectionIds, scrollContainer, track]);\n\n const handleClick = (\n event: MouseEvent<HTMLAnchorElement>,\n id: string,\n ): void => {\n if (\n event.button !== 0 ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey\n ) {\n return;\n }\n event.preventDefault();\n if (id !== activeId) {\n onCurrentChange?.(id);\n }\n trackedIdRef.current = id;\n setTrackedId(id);\n const section = document.getElementById(id);\n if (!section) {\n return;\n }\n // As an in-page link does: the URL names the section, and the next Tab\n // continues from the section rather than from the contents.\n window.history.replaceState(window.history.state, '', `#${id}`);\n if (!section.hasAttribute('tabindex')) {\n section.tabIndex = -1;\n }\n section.focus({ preventScroll: true });\n const top = sectionScrollTop(section, scrollContainer);\n const arrived = isScrolledTo(scrollContainer, top);\n /* Without scrollend support nothing would settle the click. */\n clickScrollRef.current = {\n top,\n settled: arrived || !('onscrollend' in window),\n };\n if (arrived) {\n return;\n }\n scrollerOf(scrollContainer).scrollTo({\n top,\n behavior: window.matchMedia(REDUCED_MOTION).matches\n ? 'instant'\n : 'smooth',\n });\n };\n\n const cls = ['aegis-toc', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <nav aria-label={strings.tableOfContents} className={cls}>\n <ol className=\"aegis-toc__list\">\n {items.map((item) => {\n const current = item.id === activeId;\n const level = item.level ?? 1;\n const linkCls = [\n 'aegis-toc__link',\n current ? 'aegis-toc__link--current' : '',\n level > 1 ? `aegis-toc__link--level-${level}` : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <li key={item.id}>\n <a\n href={`#${item.id}`}\n className={linkCls}\n aria-current={current ? 'location' : undefined}\n onClick={(event) => {\n handleClick(event, item.id);\n }}\n >\n <span className=\"aegis-toc__indicator\" aria-hidden=\"true\" />\n <span className=\"aegis-toc__label\">{item.label}</span>\n </a>\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["ACTIVATION_PERCENT","REDUCED_MOTION","isScrolledTo","container","top","scrollerOf","sectionScrollTop","section","scroller","margin","viewBoundsOf","TableOfContents","items","currentId","onCurrentChange","scrollContainer","className","strings","useStrings","trackedId","setTrackedId","useState","trackedIdRef","useRef","onCurrentChangeRef","clickScrollRef","activeId","sectionIds","item","useEffect","track","useCallback","id","sections","sync","clickScroll","findCurrentIndex","handleScrollEnd","observer","activationRootMargin","scrollEvents","handleClick","event","arrived","cls","jsx","current","level","linkCls","jsxs"],"mappings":";;;;;AAwCA,MAAMA,IAAqB,IACrBC,IAAiB;AAYvB,SAASC,EAAaC,GAA+BC,GAAsB;AACzE,SAAO,KAAK,IAAIC,EAAWF,CAAS,EAAE,YAAYC,CAAG,IAAI;AAC3D;AAGA,SAASE,EACPC,GACAJ,GACQ;AACR,QAAMK,IAAWH,EAAWF,CAAS,GAC/BM,IAAS,WAAW,iBAAiBF,CAAO,EAAE,eAAe,GAC7DH,IACJG,EAAQ,sBAAA,EAAwB,MAChCG,EAAaP,CAAS,EAAE,MACxBK,EAAS,YACTC;AACF,SAAO,KAAK;AAAA,IACV,KAAK,IAAIL,GAAK,CAAC;AAAA,IACfI,EAAS,eAAeA,EAAS;AAAA,EAAA;AAErC;AAEO,SAASG,EAAgB;AAAA,EAC9B,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,WAAAC;AACF,GAAuC;AACrC,QAAMC,IAAUC,EAAA,GACV,CAACC,GAAWC,CAAY,IAAIC,EAAS,MAAMT,EAAM,CAAC,GAAG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B,IAAUlB,EAAK,OAAOF,GACtBqB,IAAQnB,EAAK,SAAS,GACtBoB,IAAU;AAAA,MACd;AAAA,MACAF,IAAU,6BAA6B;AAAA,MACvCC,IAAQ,IAAI,0BAA0BA,CAAK,KAAK;AAAA,IAAA,EAE/C,OAAO,OAAO,EACd,KAAK,GAAG;AACX,6BACG,MAAA,EACC,UAAA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,MAAM,IAAIrB,EAAK,EAAE;AAAA,QACjB,WAAWoB;AAAA,QACX,gBAAcF,IAAU,aAAa;AAAA,QACrC,SAAS,CAACJ,MAAU;AAClB,UAAAD,EAAYC,GAAOd,EAAK,EAAE;AAAA,QAC5B;AAAA,QAEA,UAAA;AAAA,UAAA,gBAAAiB,EAAC,QAAA,EAAK,WAAU,wBAAuB,eAAY,QAAO;AAAA,UAC1D,gBAAAA,EAAC,QAAA,EAAK,WAAU,oBAAoB,YAAK,MAAA,CAAM;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EACjD,GAXOjB,EAAK,EAYd;AAAA,EAEJ,CAAC,GACH,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"TableOfContents.js","sources":["../../../src/components/ui/TableOfContents.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport { useSectionSpy } from '../../hooks/useSectionSpy';\nimport { useStrings } from '../../locale';\nimport './TableOfContents.css';\n\nexport interface TableOfContentsItem {\n /** The id of the section element, already in the document, the item links to. */\n id: string;\n label: ReactNode;\n /** Nesting depth of the section; 2 and 3 indent the label. Defaults to 1. */\n level?: 1 | 2 | 3;\n}\n\nexport interface TableOfContentsProps {\n /** The sections in document order. */\n items: TableOfContentsItem[];\n /** Controls the current item; omit it to follow the scroll position. */\n currentId?: string;\n /** Called with the id that scrolling or a click makes current. */\n onCurrentChange?: (id: string) => void;\n /** The element that scrolls the sections; omitted or null means the viewport. */\n scrollContainer?: HTMLElement | null;\n className?: string;\n}\n\n/** A section becomes current once its top passes this share of the view. */\nconst ACTIVATION_PERCENT = 25;\n\nexport function TableOfContents({\n items,\n currentId,\n onCurrentChange,\n scrollContainer = null,\n className,\n}: TableOfContentsProps): ReactElement {\n const strings = useStrings();\n const { activeId, onLinkClick } = useSectionSpy({\n ids: items.map((item) => item.id),\n activationPercent: ACTIVATION_PERCENT,\n currentId,\n onCurrentChange,\n scrollContainer,\n });\n\n const cls = ['aegis-toc', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <nav aria-label={strings.tableOfContents} className={cls}>\n <ol className=\"aegis-toc__list\">\n {items.map((item) => {\n const current = item.id === activeId;\n const level = item.level ?? 1;\n const linkCls = [\n 'aegis-toc__link',\n current ? 'aegis-toc__link--current' : '',\n level > 1 ? `aegis-toc__link--level-${level}` : '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <li key={item.id}>\n <a\n href={`#${item.id}`}\n className={linkCls}\n aria-current={current ? 'location' : undefined}\n onClick={(event) => {\n onLinkClick(event, item.id);\n }}\n >\n <span className=\"aegis-toc__indicator\" aria-hidden=\"true\" />\n <span className=\"aegis-toc__label\">{item.label}</span>\n </a>\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"names":["ACTIVATION_PERCENT","TableOfContents","items","currentId","onCurrentChange","scrollContainer","className","strings","useStrings","activeId","onLinkClick","useSectionSpy","item","cls","jsx","current","level","linkCls","jsxs","event"],"mappings":";;;;AA2BA,MAAMA,IAAqB;AAEpB,SAASC,EAAgB;AAAA,EAC9B,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,WAAAC;AACF,GAAuC;AACrC,QAAMC,IAAUC,EAAA,GACV,EAAE,UAAAC,GAAU,aAAAC,EAAA,IAAgBC,EAAc;AAAA,IAC9C,KAAKT,EAAM,IAAI,CAACU,MAASA,EAAK,EAAE;AAAA,IAChC,mBAAmBZ;AAAA,IACnB,WAAAG;AAAA,IACA,iBAAAC;AAAA,IACA,iBAAAC;AAAA,EAAA,CACD,GAEKQ,IAAM,CAAC,aAAaP,KAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAEnE,SACE,gBAAAQ,EAAC,OAAA,EAAI,cAAYP,EAAQ,iBAAiB,WAAWM,GACnD,UAAA,gBAAAC,EAAC,MAAA,EAAG,WAAU,mBACX,UAAAZ,EAAM,IAAI,CAACU,MAAS;AACnB,UAAMG,IAAUH,EAAK,OAAOH,GACtBO,IAAQJ,EAAK,SAAS,GACtBK,IAAU;AAAA,MACd;AAAA,MACAF,IAAU,6BAA6B;AAAA,MACvCC,IAAQ,IAAI,0BAA0BA,CAAK,KAAK;AAAA,IAAA,EAE/C,OAAO,OAAO,EACd,KAAK,GAAG;AACX,6BACG,MAAA,EACC,UAAA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,MAAM,IAAIN,EAAK,EAAE;AAAA,QACjB,WAAWK;AAAA,QACX,gBAAcF,IAAU,aAAa;AAAA,QACrC,SAAS,CAACI,MAAU;AAClB,UAAAT,EAAYS,GAAOP,EAAK,EAAE;AAAA,QAC5B;AAAA,QAEA,UAAA;AAAA,UAAA,gBAAAE,EAAC,QAAA,EAAK,WAAU,wBAAuB,eAAY,QAAO;AAAA,UAC1D,gBAAAA,EAAC,QAAA,EAAK,WAAU,oBAAoB,YAAK,MAAA,CAAM;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EACjD,GAXOF,EAAK,EAYd;AAAA,EAEJ,CAAC,GACH,GACF;AAEJ;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),g=require("../../lib/chart.cjs");;/* empty css */function l({turn:o,clock:e,thought:d,action:t,outcome:r,outcomeColor:n="var(--text-muted)",current:c=!1,onSelect:s,className:u}){const h=["aegis-thought-card",c?"aegis-thought-card--current":"",s?"aegis-thought-card--interactive":"",u??""].filter(Boolean).join(" "),i=a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"aegis-thought-card__head",children:[a.jsx("span",{className:"aegis-thought-card__turn",children:o}),e!==void 0&&a.jsx("span",{className:"aegis-thought-card__clock",children:e})]}),a.jsx("span",{className:"aegis-thought-card__thought",children:d}),t!==void 0&&a.jsx("code",{className:"aegis-thought-card__action",children:t}),r!==void 0&&a.jsxs("span",{className:"aegis-thought-card__outcome",children:[a.jsx("span",{className:"aegis-thought-card__dot",style:{"--aegis-thought-card-color":g.chartColorValue(n)},"aria-hidden":"true"}),r]})]});return s?a.jsx("button",{type:"button",className:h,"aria-current":c?"step":void 0,onClick:s,children:i}):a.jsx("div",{className:h,children:i})}exports.ThoughtCard=l;
|
|
2
|
+
//# sourceMappingURL=ThoughtCard.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThoughtCard.cjs","sources":["../../../src/components/ui/ThoughtCard.tsx"],"sourcesContent":["import type { CSSProperties, ReactElement, ReactNode } from 'react';\n\nimport { type ChartColor, chartColorValue } from '../../lib/chart';\nimport './ThoughtCard.css';\n\nexport interface ThoughtCardProps {\n /** The turn or step, e.g. \"T42\". */\n turn: ReactNode;\n /** When in the replay it happened, e.g. \"06:12\". */\n clock?: ReactNode;\n /** What the agent reasoned. */\n thought: ReactNode;\n /** What it did, as recorded, e.g. `move(unit=7, to=\"E5\")`. */\n action?: ReactNode;\n /** What came of it, e.g. \"占领 E5 · +12 分\". */\n outcome?: ReactNode;\n /** The outcome's colour, the same as its kind on the replay's strip. */\n outcomeColor?: ChartColor;\n /** The turn the replay is on; earlier turns read quieter. */\n current?: boolean;\n /** Makes the card a button, e.g. one that moves the replay to the turn. */\n onSelect?: () => void;\n className?: string;\n}\n\n/** One turn of an agent's reasoning beside a replay: its thought, action and outcome. */\nexport function ThoughtCard({\n turn,\n clock,\n thought,\n action,\n outcome,\n outcomeColor = 'var(--text-muted)',\n current = false,\n onSelect,\n className,\n}: ThoughtCardProps): ReactElement {\n const cls = [\n 'aegis-thought-card',\n current ? 'aegis-thought-card--current' : '',\n onSelect ? 'aegis-thought-card--interactive' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n const body = (\n <>\n <span className=\"aegis-thought-card__head\">\n <span className=\"aegis-thought-card__turn\">{turn}</span>\n {clock !== undefined && (\n <span className=\"aegis-thought-card__clock\">{clock}</span>\n )}\n </span>\n <span className=\"aegis-thought-card__thought\">{thought}</span>\n {action !== undefined && (\n <code className=\"aegis-thought-card__action\">{action}</code>\n )}\n {outcome !== undefined && (\n <span className=\"aegis-thought-card__outcome\">\n <span\n className=\"aegis-thought-card__dot\"\n style={\n {\n '--aegis-thought-card-color': chartColorValue(outcomeColor),\n } as CSSProperties\n }\n aria-hidden=\"true\"\n />\n {outcome}\n </span>\n )}\n </>\n );\n return onSelect ? (\n <button\n type=\"button\"\n className={cls}\n aria-current={current ? 'step' : undefined}\n onClick={onSelect}\n >\n {body}\n </button>\n ) : (\n <div className={cls}>{body}</div>\n );\n}\n"],"names":["ThoughtCard","turn","clock","thought","action","outcome","outcomeColor","current","onSelect","className","cls","body","jsxs","Fragment","jsx","chartColorValue"],"mappings":"uLA0BO,SAASA,EAAY,CAC1B,KAAAC,EACA,MAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,EACA,aAAAC,EAAe,oBACf,QAAAC,EAAU,GACV,SAAAC,EACA,UAAAC,CACF,EAAmC,CACjC,MAAMC,EAAM,CACV,qBACAH,EAAU,8BAAgC,GAC1CC,EAAW,kCAAoC,GAC/CC,GAAa,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,EACLE,EACJC,EAAAA,KAAAC,EAAAA,SAAA,CACE,SAAA,CAAAD,EAAAA,KAAC,OAAA,CAAK,UAAU,2BACd,SAAA,CAAAE,EAAAA,IAAC,OAAA,CAAK,UAAU,2BAA4B,SAAAb,EAAK,EAChDC,IAAU,QACTY,EAAAA,IAAC,OAAA,CAAK,UAAU,4BAA6B,SAAAZ,CAAA,CAAM,CAAA,EAEvD,EACAY,EAAAA,IAAC,OAAA,CAAK,UAAU,8BAA+B,SAAAX,EAAQ,EACtDC,IAAW,QACVU,EAAAA,IAAC,OAAA,CAAK,UAAU,6BAA8B,SAAAV,EAAO,EAEtDC,IAAY,QACXO,OAAC,OAAA,CAAK,UAAU,8BACd,SAAA,CAAAE,EAAAA,IAAC,OAAA,CACC,UAAU,0BACV,MACE,CACE,6BAA8BC,EAAAA,gBAAgBT,CAAY,CAAA,EAG9D,cAAY,MAAA,CAAA,EAEbD,CAAA,CAAA,CACH,CAAA,EAEJ,EAEF,OAAOG,EACLM,EAAAA,IAAC,SAAA,CACC,KAAK,SACL,UAAWJ,EACX,eAAcH,EAAU,OAAS,OACjC,QAASC,EAER,SAAAG,CAAA,CAAA,EAGHG,EAAAA,IAAC,MAAA,CAAI,UAAWJ,EAAM,SAAAC,EAAK,CAE/B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { ChartColor } from '../../lib/chart';
|
|
3
|
+
export interface ThoughtCardProps {
|
|
4
|
+
/** The turn or step, e.g. "T42". */
|
|
5
|
+
turn: ReactNode;
|
|
6
|
+
/** When in the replay it happened, e.g. "06:12". */
|
|
7
|
+
clock?: ReactNode;
|
|
8
|
+
/** What the agent reasoned. */
|
|
9
|
+
thought: ReactNode;
|
|
10
|
+
/** What it did, as recorded, e.g. `move(unit=7, to="E5")`. */
|
|
11
|
+
action?: ReactNode;
|
|
12
|
+
/** What came of it, e.g. "占领 E5 · +12 分". */
|
|
13
|
+
outcome?: ReactNode;
|
|
14
|
+
/** The outcome's colour, the same as its kind on the replay's strip. */
|
|
15
|
+
outcomeColor?: ChartColor;
|
|
16
|
+
/** The turn the replay is on; earlier turns read quieter. */
|
|
17
|
+
current?: boolean;
|
|
18
|
+
/** Makes the card a button, e.g. one that moves the replay to the turn. */
|
|
19
|
+
onSelect?: () => void;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/** One turn of an agent's reasoning beside a replay: its thought, action and outcome. */
|
|
23
|
+
export declare function ThoughtCard({ turn, clock, thought, action, outcome, outcomeColor, current, onSelect, className, }: ThoughtCardProps): ReactElement;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsxs as e, Fragment as u, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { chartColorValue as m } from "../../lib/chart.js";
|
|
3
|
+
/* empty css */
|
|
4
|
+
function v({
|
|
5
|
+
turn: d,
|
|
6
|
+
clock: s,
|
|
7
|
+
thought: n,
|
|
8
|
+
action: r,
|
|
9
|
+
outcome: h,
|
|
10
|
+
outcomeColor: g = "var(--text-muted)",
|
|
11
|
+
current: c = !1,
|
|
12
|
+
onSelect: t,
|
|
13
|
+
className: l
|
|
14
|
+
}) {
|
|
15
|
+
const i = [
|
|
16
|
+
"aegis-thought-card",
|
|
17
|
+
c ? "aegis-thought-card--current" : "",
|
|
18
|
+
t ? "aegis-thought-card--interactive" : "",
|
|
19
|
+
l ?? ""
|
|
20
|
+
].filter(Boolean).join(" "), o = /* @__PURE__ */ e(u, { children: [
|
|
21
|
+
/* @__PURE__ */ e("span", { className: "aegis-thought-card__head", children: [
|
|
22
|
+
/* @__PURE__ */ a("span", { className: "aegis-thought-card__turn", children: d }),
|
|
23
|
+
s !== void 0 && /* @__PURE__ */ a("span", { className: "aegis-thought-card__clock", children: s })
|
|
24
|
+
] }),
|
|
25
|
+
/* @__PURE__ */ a("span", { className: "aegis-thought-card__thought", children: n }),
|
|
26
|
+
r !== void 0 && /* @__PURE__ */ a("code", { className: "aegis-thought-card__action", children: r }),
|
|
27
|
+
h !== void 0 && /* @__PURE__ */ e("span", { className: "aegis-thought-card__outcome", children: [
|
|
28
|
+
/* @__PURE__ */ a(
|
|
29
|
+
"span",
|
|
30
|
+
{
|
|
31
|
+
className: "aegis-thought-card__dot",
|
|
32
|
+
style: {
|
|
33
|
+
"--aegis-thought-card-color": m(g)
|
|
34
|
+
},
|
|
35
|
+
"aria-hidden": "true"
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
h
|
|
39
|
+
] })
|
|
40
|
+
] });
|
|
41
|
+
return t ? /* @__PURE__ */ a(
|
|
42
|
+
"button",
|
|
43
|
+
{
|
|
44
|
+
type: "button",
|
|
45
|
+
className: i,
|
|
46
|
+
"aria-current": c ? "step" : void 0,
|
|
47
|
+
onClick: t,
|
|
48
|
+
children: o
|
|
49
|
+
}
|
|
50
|
+
) : /* @__PURE__ */ a("div", { className: i, children: o });
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
v as ThoughtCard
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=ThoughtCard.js.map
|