@robert-stackflow/oneui 0.6.8 → 0.6.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +255 -188
  3. package/components/AccountItem.module.css +103 -103
  4. package/components/Alert.d.ts +2 -9
  5. package/components/Alert.js +2 -40
  6. package/components/AppShell.d.ts +7 -7
  7. package/components/AppShell.js +37 -33
  8. package/components/AppShell.module.css +223 -271
  9. package/components/AppearanceSettings.js +25 -32
  10. package/components/Badge.module.css +30 -30
  11. package/components/Banner.d.ts +17 -0
  12. package/components/Banner.js +99 -0
  13. package/components/Banner.module.css +143 -0
  14. package/components/BarChart.module.css +35 -34
  15. package/components/Breadcrumb.module.css +97 -97
  16. package/components/Button.module.css +120 -120
  17. package/components/Cascader.js +1 -0
  18. package/components/CharacterPicker.js +2 -0
  19. package/components/Checkbox.module.css +95 -95
  20. package/components/Combobox.js +1 -0
  21. package/components/Combobox.module.css +6 -1
  22. package/components/CommandPalette.js +2 -2
  23. package/components/ContributionCalendar.module.css +121 -121
  24. package/components/Control.module.css +86 -86
  25. package/components/DataTable.d.ts +3 -2
  26. package/components/DataTable.js +92 -66
  27. package/components/DataTable.module.css +3 -31
  28. package/components/DatePicker.js +1 -0
  29. package/components/DateRangePicker.js +1 -0
  30. package/components/Dialog.d.ts +3 -1
  31. package/components/Dialog.js +11 -4
  32. package/components/Dialog.module.css +139 -97
  33. package/components/DialogVariants.d.ts +2 -1
  34. package/components/DialogVariants.js +35 -7
  35. package/components/HierarchyPicker.module.css +185 -181
  36. package/components/IconPicker.js +2 -0
  37. package/components/Indicator.module.css +83 -83
  38. package/components/Layout.module.css +82 -82
  39. package/components/Markdown.d.ts +13 -0
  40. package/components/Markdown.js +164 -0
  41. package/components/Markdown.module.css +227 -0
  42. package/components/MenuItem.module.css +172 -172
  43. package/components/MultiSelect.js +1 -0
  44. package/components/MultiSelect.module.css +2 -0
  45. package/components/NavBar.d.ts +20 -0
  46. package/components/NavBar.js +197 -0
  47. package/components/NavBar.module.css +130 -0
  48. package/components/NavigationSurface.module.css +27 -0
  49. package/components/Picker.module.css +7 -0
  50. package/components/Popover.d.ts +6 -1
  51. package/components/Popover.js +39 -13
  52. package/components/Popover.module.css +8 -0
  53. package/components/Progress.module.css +33 -33
  54. package/components/RadioGroup.module.css +87 -87
  55. package/components/RangeSlider.module.css +141 -141
  56. package/components/ResizablePanel.module.css +101 -101
  57. package/components/ResourceCard.module.css +98 -98
  58. package/components/SelectSettingRow.d.ts +7 -0
  59. package/components/SelectSettingRow.js +58 -0
  60. package/components/SettingRow.d.ts +9 -3
  61. package/components/SettingRow.js +32 -8
  62. package/components/SettingRow.module.css +17 -0
  63. package/components/SettingsLayout.d.ts +15 -3
  64. package/components/SettingsLayout.js +46 -29
  65. package/components/SideBar.d.ts +9 -0
  66. package/components/SideBar.js +30 -0
  67. package/components/SidebarNavigation.d.ts +24 -3
  68. package/components/SidebarNavigation.js +274 -47
  69. package/components/SidebarNavigation.module.css +352 -130
  70. package/components/Slider.module.css +19 -19
  71. package/components/Steps.module.css +176 -176
  72. package/components/Switch.d.ts +3 -1
  73. package/components/Switch.js +5 -1
  74. package/components/Switch.module.css +59 -59
  75. package/components/SwitchSettingRow.d.ts +7 -0
  76. package/components/SwitchSettingRow.js +45 -0
  77. package/components/Table.d.ts +8 -1
  78. package/components/Table.js +34 -17
  79. package/components/Table.module.css +87 -48
  80. package/components/TableMarkup.d.ts +2 -1
  81. package/components/TableMarkup.js +18 -1
  82. package/components/TableOfContents.d.ts +22 -0
  83. package/components/TableOfContents.js +462 -0
  84. package/components/TableOfContents.module.css +252 -0
  85. package/components/TextAreaSettingRow.d.ts +9 -0
  86. package/components/TextAreaSettingRow.js +47 -0
  87. package/components/TextSettingRow.d.ts +9 -0
  88. package/components/TextSettingRow.js +45 -0
  89. package/components/ThemePicker.module.css +178 -178
  90. package/components/ThemeProvider.js +2 -0
  91. package/components/TimeColumns.module.css +47 -47
  92. package/components/Timeline.module.css +202 -202
  93. package/components/Toast.d.ts +8 -1
  94. package/components/Toast.js +49 -17
  95. package/components/Toast.module.css +25 -0
  96. package/components/ToastProvider.d.ts +4 -1
  97. package/components/ToastProvider.js +67 -12
  98. package/components/TreeSelect.js +1 -0
  99. package/components/TreeTable.d.ts +3 -3
  100. package/components/TreeTable.js +12 -2
  101. package/components/TreeTable.module.css +57 -53
  102. package/components/createToaster.d.ts +2 -1
  103. package/components/createToaster.js +28 -14
  104. package/components/index.d.ts +18 -1
  105. package/components/index.js +24 -0
  106. package/components/motion.d.ts +1 -0
  107. package/components/motion.js +18 -6
  108. package/components/settingRowControl.d.ts +7 -0
  109. package/components/settingRowControl.js +15 -0
  110. package/package.json +57 -3
  111. package/styles/base.css +206 -206
  112. package/styles/blue.css +270 -268
  113. package/styles/minimal.css +1 -0
@@ -1,48 +1,87 @@
1
- .scroll {
2
- overflow-x: auto;
3
- border-radius: inherit;
4
- max-width: 100%;
5
- }
6
- .table {
7
- border-collapse: collapse;
8
- width: 100%;
9
- font-size: 13px;
10
- text-align: left;
11
- white-space: nowrap;
12
- }
13
- .table th {
14
- color: var(--muted);
15
- font-size: 12px;
16
- font-weight: 500;
17
- background: var(--canvas);
18
- padding: 12px 16px;
19
- }
20
- .table td {
21
- padding: 15px 16px;
22
- border-bottom: 1px solid var(--line);
23
- }
24
- .table tbody tr:last-child td {
25
- border-bottom: 0;
26
- }
27
- .table tbody tr {
28
- transition: background var(--motion-hover);
29
- }
30
- .table tbody tr:hover {
31
- background: var(--hover);
32
- }
33
- .empty {
34
- text-align: center;
35
- height: 150px;
36
- color: var(--muted);
37
- }
38
- .caption {
39
- position: absolute;
40
- width: 1px;
41
- height: 1px;
42
- padding: 0;
43
- margin: -1px;
44
- overflow: hidden;
45
- clip: rect(0, 0, 0, 0);
46
- white-space: nowrap;
47
- border: 0;
48
- }
1
+ .scroll {
2
+ max-width: 100%;
3
+ min-width: 0;
4
+ overflow: auto;
5
+ border: 1px solid var(--line);
6
+ border-radius: var(--table-radius, var(--radius));
7
+ overscroll-behavior: contain;
8
+ }
9
+ .scroll:focus-visible {
10
+ outline: 2px solid var(--accent-ink, var(--accent));
11
+ outline-offset: 2px;
12
+ }
13
+ .table {
14
+ width: 100%;
15
+ border-collapse: separate;
16
+ border-spacing: 0;
17
+ text-align: left;
18
+ white-space: nowrap;
19
+ font-size: 13px;
20
+ line-height: 1.55;
21
+ background: var(--surface);
22
+ }
23
+ .table :is(th, td) {
24
+ height: 48px;
25
+ padding: 12px 16px;
26
+ border: 0;
27
+ border-bottom: 1px solid var(--line);
28
+ vertical-align: middle;
29
+ font-variant-numeric: tabular-nums;
30
+ }
31
+ .table th {
32
+ color: var(--muted);
33
+ background: var(--canvas);
34
+ font-size: 12px;
35
+ font-weight: 500;
36
+ }
37
+ .table tbody tr:last-child td {
38
+ border-bottom: 0;
39
+ }
40
+ .table tbody tr {
41
+ transition: background-color var(--motion-hover);
42
+ }
43
+ .table[data-striped="true"] tbody tr:nth-child(even) {
44
+ background: color-mix(in srgb, var(--fg) 3%, var(--surface));
45
+ }
46
+ .table:not([data-hoverable="false"]) tbody tr:hover,
47
+ .table tbody tr:focus-within {
48
+ background: var(--hover);
49
+ }
50
+ .table.table tbody tr:is([data-selected="true"], [aria-selected="true"]) {
51
+ background: var(--selected);
52
+ }
53
+ .table[data-density="compact"] :is(th, td) {
54
+ height: 36px;
55
+ padding: 7px 12px;
56
+ font-size: 12px;
57
+ }
58
+ .table[data-bordered="true"] tr > :is(th, td) + :is(th, td) {
59
+ border-left: 1px solid var(--line);
60
+ }
61
+ .table[data-sticky-header="true"] thead th {
62
+ position: sticky;
63
+ top: 0;
64
+ z-index: 1;
65
+ box-shadow: 0 1px 0 var(--line);
66
+ }
67
+ .empty {
68
+ text-align: center;
69
+ height: 150px;
70
+ color: var(--muted);
71
+ }
72
+ .caption {
73
+ position: absolute;
74
+ width: 1px;
75
+ height: 1px;
76
+ padding: 0;
77
+ margin: -1px;
78
+ overflow: hidden;
79
+ clip: rect(0, 0, 0, 0);
80
+ white-space: nowrap;
81
+ border: 0;
82
+ }
83
+ @media (prefers-reduced-motion: reduce) {
84
+ .table tbody tr {
85
+ transition: none;
86
+ }
87
+ }
@@ -1,6 +1,7 @@
1
1
  import type { HTMLAttributes, TdHTMLAttributes, ThHTMLAttributes, CSSProperties, ReactNode } from "react";
2
+ import type { TableAppearance } from "./Table";
2
3
  /** Semantic table composition for cells with forms, selection and nested content. */
3
- declare function Markup({ children, className, ...props }: HTMLAttributes<HTMLTableElement>): import("react").JSX.Element;
4
+ declare function Markup({ children, className, striped, density, hoverable, bordered, stickyHeader, ...props }: HTMLAttributes<HTMLTableElement> & TableAppearance): import("react").JSX.Element;
4
5
  declare function ScrollContainer({ children, minWidth, }: {
5
6
  children: ReactNode;
6
7
  minWidth?: number;
@@ -3,9 +3,26 @@ import s from "./Table.module.css";
3
3
  function Markup({
4
4
  children,
5
5
  className = "",
6
+ striped = false,
7
+ density = "comfortable",
8
+ hoverable = true,
9
+ bordered = false,
10
+ stickyHeader = false,
6
11
  ...props
7
12
  }) {
8
- return /* @__PURE__ */ jsx("table", { ...props, className: `${s.table} ${className}`, children });
13
+ return /* @__PURE__ */ jsx(
14
+ "table",
15
+ {
16
+ ...props,
17
+ className: `${s.table} ${className}`,
18
+ "data-striped": striped,
19
+ "data-density": density,
20
+ "data-hoverable": hoverable,
21
+ "data-bordered": bordered,
22
+ "data-sticky-header": stickyHeader,
23
+ children
24
+ }
25
+ );
9
26
  }
10
27
  function ScrollContainer({
11
28
  children,
@@ -0,0 +1,22 @@
1
+ import { type RefObject } from "react";
2
+ export type TableOfContentsItem = {
3
+ id: string;
4
+ label: string;
5
+ level?: number;
6
+ description?: string;
7
+ };
8
+ export type TableOfContentsProps = {
9
+ items?: readonly TableOfContentsItem[];
10
+ contentRef?: RefObject<HTMLElement | null>;
11
+ variant?: "tree" | "rail";
12
+ hoverMode?: "single" | "nearby" | "all";
13
+ previewCount?: number;
14
+ depthBasedLength?: boolean;
15
+ label?: string;
16
+ activeId?: string;
17
+ onActiveChange?(id: string): void;
18
+ maxLevel?: number;
19
+ scrollOffset?: number;
20
+ className?: string;
21
+ };
22
+ export declare function TableOfContents({ items, contentRef, variant, hoverMode, previewCount, depthBasedLength, label, activeId, onActiveChange, maxLevel, scrollOffset, className, }: TableOfContentsProps): import("react").JSX.Element | null;
@@ -0,0 +1,462 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ useEffect,
4
+ useId,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useMemo,
8
+ useState
9
+ } from "react";
10
+ import { ListFilter } from "lucide-react";
11
+ import { Popover } from "./Popover.js";
12
+ import { reducedMotion } from "./motion.js";
13
+ import s from "./TableOfContents.module.css";
14
+ function scrollParent(node) {
15
+ for (let parent = node.parentElement; parent && parent !== document.body; parent = parent.parentElement)
16
+ if (/(auto|scroll)/.test(getComputedStyle(parent).overflowY)) return parent;
17
+ return null;
18
+ }
19
+ function TableOfContents({
20
+ items,
21
+ contentRef,
22
+ variant = "tree",
23
+ hoverMode = "nearby",
24
+ previewCount = 5,
25
+ depthBasedLength = false,
26
+ label = "\u672C\u9875\u76EE\u5F55",
27
+ activeId,
28
+ onActiveChange,
29
+ maxLevel = 4,
30
+ scrollOffset = 24,
31
+ className = ""
32
+ }) {
33
+ const id = useId();
34
+ const [discovered, setDiscovered] = useState([]);
35
+ const [internal, setInternal] = useState("");
36
+ const [visible, setVisible] = useState([]);
37
+ const [up, setUp] = useState(false);
38
+ const [open, setOpen] = useState(false);
39
+ const [hovered, setHovered] = useState(-1);
40
+ const [railHovered, setRailHovered] = useState(false);
41
+ const [diagram, setDiagram] = useState({ path: "", height: 0, positions: [] });
42
+ const entries = items ?? discovered;
43
+ const current = activeId ?? internal;
44
+ const active = activeId ? [activeId] : visible;
45
+ const railRoot = useRef(null);
46
+ const lineNodes = useRef(/* @__PURE__ */ new Map());
47
+ const suppressFocus = useRef(false);
48
+ const list = useRef(null);
49
+ const timer = useRef(void 0);
50
+ const change = useRef(onActiveChange);
51
+ const lastActive = useRef("");
52
+ const measuredPath = useRef("");
53
+ change.current = onActiveChange;
54
+ const previewIndex = hovered >= 0 && hovered < entries.length ? hovered : Math.max(
55
+ 0,
56
+ entries.findIndex((entry) => entry.id === current)
57
+ );
58
+ const popupAnchor = useMemo(
59
+ () => ({
60
+ current: lineNodes.current.get(entries[previewIndex]?.id ?? "") ?? railRoot.current
61
+ }),
62
+ [previewIndex, entries, open]
63
+ );
64
+ const count = Number.isFinite(previewCount) ? Math.max(1, Math.floor(previewCount)) : 5;
65
+ const windowStart = Math.max(
66
+ 0,
67
+ Math.min(entries.length - count, previewIndex - Math.floor(count / 2))
68
+ );
69
+ const previewEntries = hoverMode === "all" ? entries : hoverMode === "single" ? entries.slice(previewIndex, previewIndex + 1) : entries.slice(windowStart, windowStart + count);
70
+ const minimum = Math.min(...entries.map((entry) => entry.level ?? 2), 6);
71
+ const depth = (entry) => Math.max(0, Math.min(3, (entry.level ?? 2) - minimum));
72
+ useEffect(() => {
73
+ const content = contentRef?.current;
74
+ if (items || !content) return;
75
+ const read = () => {
76
+ const next = [
77
+ ...content.querySelectorAll("h1,h2,h3,h4,h5,h6")
78
+ ].filter(
79
+ (node) => Number(node.tagName[1]) <= maxLevel && !node.closest("[data-footnotes]")
80
+ ).map((node, index) => {
81
+ if (!node.id)
82
+ node.id = `oneui-toc-${id.replaceAll(":", "")}-${index}`;
83
+ return {
84
+ id: node.id,
85
+ label: node.textContent?.trim() ?? "",
86
+ level: Number(node.tagName[1]),
87
+ description: (() => {
88
+ let next2 = node.nextElementSibling;
89
+ for (let count2 = 0; next2 && count2 < 4; count2++, next2 = next2.nextElementSibling) {
90
+ if (/^H[1-6]$/.test(next2.tagName)) break;
91
+ if (next2.tagName === "P")
92
+ return next2.textContent?.trim().slice(0, 160);
93
+ }
94
+ return void 0;
95
+ })()
96
+ };
97
+ }).filter((entry) => entry.label);
98
+ setDiscovered(
99
+ (previous) => JSON.stringify(previous) === JSON.stringify(next) ? previous : next
100
+ );
101
+ };
102
+ read();
103
+ const observer = new MutationObserver(read);
104
+ observer.observe(content, {
105
+ childList: true,
106
+ subtree: true,
107
+ characterData: true
108
+ });
109
+ return () => observer.disconnect();
110
+ }, [contentRef, items, maxLevel, id]);
111
+ useEffect(() => {
112
+ const headings = entries.map((entry) => document.getElementById(entry.id)).filter((node) => Boolean(node));
113
+ if (!headings.length) return;
114
+ const root = scrollParent(headings[0]);
115
+ const intersections = /* @__PURE__ */ new Set();
116
+ let previous = { first: 0, last: 0, up: false };
117
+ const observer = new IntersectionObserver(
118
+ (changes) => {
119
+ for (const entry of changes) {
120
+ if (entry.isIntersecting) intersections.add(entry.target.id);
121
+ else intersections.delete(entry.target.id);
122
+ }
123
+ let ids = headings.filter((heading) => intersections.has(heading.id)).map((heading) => heading.id);
124
+ if (!ids.length) {
125
+ const top = (root?.getBoundingClientRect().top ?? 0) + scrollOffset;
126
+ const nearest = headings.reduce(
127
+ (best, heading) => Math.abs(heading.getBoundingClientRect().top - top) < Math.abs(best.getBoundingClientRect().top - top) ? heading : best
128
+ );
129
+ ids = [nearest.id];
130
+ }
131
+ const first2 = entries.findIndex((entry) => entry.id === ids[0]);
132
+ const last2 = entries.findIndex((entry) => entry.id === ids.at(-1));
133
+ const isUp = first2 < previous.first || last2 < previous.last || first2 === previous.first && last2 === previous.last && previous.up;
134
+ previous = { first: first2, last: last2, up: isUp };
135
+ setUp(isUp);
136
+ setVisible((old) => old.join("\0") === ids.join("\0") ? old : ids);
137
+ const viewTop = (root?.getBoundingClientRect().top ?? 0) + scrollOffset + 2;
138
+ let primary = headings[0].id;
139
+ for (const heading of headings) {
140
+ if (heading.getBoundingClientRect().top <= viewTop)
141
+ primary = heading.id;
142
+ }
143
+ if (root && root.scrollHeight > root.clientHeight + 1 && root.scrollTop + root.clientHeight >= root.scrollHeight - 2)
144
+ primary = headings.at(-1).id;
145
+ setInternal(primary);
146
+ if (lastActive.current !== primary) {
147
+ lastActive.current = primary;
148
+ change.current?.(primary);
149
+ }
150
+ },
151
+ { root, rootMargin: `-${scrollOffset}px 0px -12px 0px`, threshold: 0 }
152
+ );
153
+ headings.forEach((heading) => observer.observe(heading));
154
+ return () => observer.disconnect();
155
+ }, [entries, scrollOffset]);
156
+ useLayoutEffect(() => {
157
+ const node = list.current;
158
+ if (!node || variant === "rail") return;
159
+ const measure = () => {
160
+ const links = [...node.querySelectorAll("a")];
161
+ if (!links.length || !node.offsetWidth) return;
162
+ let path = "", distance2 = 0;
163
+ const positions = [];
164
+ const segment = document.createElementNS(
165
+ "http://www.w3.org/2000/svg",
166
+ "path"
167
+ );
168
+ links.forEach((link, index) => {
169
+ const style = getComputedStyle(link);
170
+ const x = 6 + depth(entries[index]) * 8;
171
+ const top = link.offsetTop + parseFloat(style.paddingTop);
172
+ const bottom = link.offsetTop + link.offsetHeight - parseFloat(style.paddingBottom);
173
+ const previous = positions.at(-1);
174
+ if (previous) {
175
+ const curve = `C${previous.x} ${top - 4} ${x} ${previous.bottom + 4} ${x} ${top}`;
176
+ segment.setAttribute(
177
+ "d",
178
+ `M${previous.x} ${previous.bottom} ${curve}`
179
+ );
180
+ distance2 += segment.getTotalLength();
181
+ path += ` ${curve} L${x} ${bottom}`;
182
+ } else path = `M${x} ${top} L${x} ${bottom}`;
183
+ positions.push({ x, top, bottom, distance: distance2 });
184
+ distance2 += bottom - top;
185
+ });
186
+ const next = {
187
+ path,
188
+ height: links.at(-1).offsetTop + links.at(-1).offsetHeight,
189
+ positions
190
+ };
191
+ setDiagram(
192
+ (old) => JSON.stringify(old) === JSON.stringify(next) ? old : next
193
+ );
194
+ };
195
+ measure();
196
+ const observer = new ResizeObserver(measure);
197
+ observer.observe(node);
198
+ return () => observer.disconnect();
199
+ }, [entries, open, variant]);
200
+ const indices = entries.flatMap(
201
+ (entry, index) => active.includes(entry.id) ? [index] : []
202
+ );
203
+ const first = diagram.positions[indices[0] ?? 0];
204
+ const last = diagram.positions[indices.at(-1) ?? 0];
205
+ const clip = first && last ? `polygon(0 ${first.top}px, 100% ${first.top}px, 100% ${last.bottom}px, 0 ${last.bottom}px)` : "polygon(0 0,100% 0,100% 0,0 0)";
206
+ const distance = first && last ? up ? first.distance : last.distance + last.bottom - last.top : 0;
207
+ useLayoutEffect(() => {
208
+ const node = list.current;
209
+ if (!node || variant !== "tree" || !diagram.path) return;
210
+ if (!node.dataset.ready || measuredPath.current !== diagram.path) {
211
+ node.dataset.ready = "false";
212
+ node.getBoundingClientRect();
213
+ node.dataset.ready = "true";
214
+ measuredPath.current = diagram.path;
215
+ }
216
+ }, [diagram.path, variant]);
217
+ useLayoutEffect(() => {
218
+ const node = list.current, viewport = node?.parentElement;
219
+ if (!viewport || !first || !last || !open && variant === "rail") return;
220
+ if (first.top < viewport.scrollTop)
221
+ viewport.scrollTo({
222
+ top: Math.max(0, first.top - 12),
223
+ behavior: reducedMotion() ? "auto" : "smooth"
224
+ });
225
+ else if (last.bottom > viewport.scrollTop + viewport.clientHeight)
226
+ viewport.scrollTo({
227
+ top: last.bottom - viewport.clientHeight + 12,
228
+ behavior: reducedMotion() ? "auto" : "smooth"
229
+ });
230
+ }, [first, last, open, variant]);
231
+ useLayoutEffect(() => {
232
+ if (variant !== "rail" || !open) return;
233
+ const node = list.current, viewport = node?.parentElement;
234
+ const selected = node?.querySelector(
235
+ '[data-preview-target="true"]'
236
+ );
237
+ if (!selected || !viewport) return;
238
+ if (selected.offsetTop < viewport.scrollTop)
239
+ viewport.scrollTop = selected.offsetTop;
240
+ else if (selected.offsetTop + selected.offsetHeight > viewport.scrollTop + viewport.clientHeight)
241
+ viewport.scrollTop = selected.offsetTop + selected.offsetHeight - viewport.clientHeight;
242
+ }, [current, open, variant, previewIndex, hoverMode]);
243
+ useEffect(() => () => clearTimeout(timer.current), []);
244
+ const keepOpen = () => clearTimeout(timer.current);
245
+ const closeSoon = () => {
246
+ clearTimeout(timer.current);
247
+ timer.current = setTimeout(() => setOpen(false), 150);
248
+ };
249
+ const jump = (entry, event) => {
250
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0)
251
+ return;
252
+ const heading = document.getElementById(entry.id);
253
+ if (!heading) return;
254
+ event.preventDefault();
255
+ const parent = scrollParent(heading);
256
+ const top = heading.getBoundingClientRect().top - (parent?.getBoundingClientRect().top ?? 0) + (parent?.scrollTop ?? window.scrollY) - scrollOffset;
257
+ (parent ?? window).scrollTo({
258
+ top,
259
+ behavior: reducedMotion() ? "auto" : "smooth"
260
+ });
261
+ setOpen(false);
262
+ };
263
+ const contents = () => variant === "rail" ? /* @__PURE__ */ jsxs(
264
+ "nav",
265
+ {
266
+ className: s.flatMenu,
267
+ "aria-label": label,
268
+ "data-toc-variant": "rail",
269
+ "data-preview-mode": hoverMode,
270
+ children: [
271
+ hoverMode !== "single" && /* @__PURE__ */ jsxs("div", { className: s.title, children: [
272
+ /* @__PURE__ */ jsx(ListFilter, { size: 16, "aria-hidden": "true" }),
273
+ label
274
+ ] }),
275
+ /* @__PURE__ */ jsx("div", { className: s.scroll, children: /* @__PURE__ */ jsx("div", { ref: list, className: s.flatList, children: previewEntries.map((entry) => /* @__PURE__ */ jsx(
276
+ "a",
277
+ {
278
+ className: s.flatLink,
279
+ href: `#${encodeURIComponent(entry.id)}`,
280
+ "aria-label": entry.label,
281
+ "data-active": current === entry.id,
282
+ "data-preview-target": entries[previewIndex]?.id === entry.id,
283
+ "aria-current": current === entry.id ? "location" : void 0,
284
+ onClick: (event) => jump(entry, event),
285
+ children: /* @__PURE__ */ jsxs("span", { children: [
286
+ hoverMode === "single" ? /* @__PURE__ */ jsx("strong", { className: s.previewTitle, children: entry.label }) : entry.label,
287
+ hoverMode === "single" && entry.description && /* @__PURE__ */ jsx("small", { className: s.excerpt, children: entry.description })
288
+ ] })
289
+ },
290
+ entry.id
291
+ )) }) })
292
+ ]
293
+ }
294
+ ) : /* @__PURE__ */ jsxs(
295
+ "nav",
296
+ {
297
+ className: `${s.tree} ${variant === "tree" ? className : ""}`,
298
+ "aria-label": label,
299
+ children: [
300
+ /* @__PURE__ */ jsxs("div", { className: s.title, children: [
301
+ /* @__PURE__ */ jsx(ListFilter, { size: 16, "aria-hidden": "true" }),
302
+ label
303
+ ] }),
304
+ /* @__PURE__ */ jsx("div", { className: s.scroll, children: /* @__PURE__ */ jsxs("div", { className: s.list, ref: list, children: [
305
+ /* @__PURE__ */ jsx(
306
+ "svg",
307
+ {
308
+ className: s.guides,
309
+ width: "48",
310
+ height: diagram.height,
311
+ "aria-hidden": "true",
312
+ children: /* @__PURE__ */ jsx("path", { d: diagram.path })
313
+ }
314
+ ),
315
+ /* @__PURE__ */ jsx(
316
+ "svg",
317
+ {
318
+ className: `${s.guides} ${s.activeGuide}`,
319
+ "data-toc-range": true,
320
+ width: "48",
321
+ height: diagram.height,
322
+ style: { clipPath: clip },
323
+ "aria-hidden": "true",
324
+ children: /* @__PURE__ */ jsx("path", { d: diagram.path })
325
+ }
326
+ ),
327
+ /* @__PURE__ */ jsx(
328
+ "span",
329
+ {
330
+ className: s.thumb,
331
+ "data-toc-thumb": true,
332
+ "aria-hidden": "true",
333
+ style: {
334
+ offsetPath: diagram.path ? `path("${diagram.path}")` : void 0,
335
+ offsetDistance: `${distance}px`,
336
+ opacity: first ? 1 : 0
337
+ }
338
+ }
339
+ ),
340
+ entries.map((entry) => /* @__PURE__ */ jsx(
341
+ "a",
342
+ {
343
+ className: s.link,
344
+ href: `#${encodeURIComponent(entry.id)}`,
345
+ "data-active": active.includes(entry.id),
346
+ "aria-current": current === entry.id ? "location" : void 0,
347
+ style: { "--toc-depth": depth(entry) },
348
+ onClick: (event) => jump(entry, event),
349
+ children: entry.label
350
+ },
351
+ entry.id
352
+ ))
353
+ ] }) })
354
+ ]
355
+ }
356
+ );
357
+ if (!entries.length) return null;
358
+ return variant === "tree" ? contents() : /* @__PURE__ */ jsxs(
359
+ "nav",
360
+ {
361
+ ref: railRoot,
362
+ className: `${s.rail} ${className}`,
363
+ "aria-label": `${label}\u5FEB\u6377\u5B9A\u4F4D`,
364
+ onPointerEnter: () => {
365
+ keepOpen();
366
+ setRailHovered(true);
367
+ setOpen(true);
368
+ },
369
+ onPointerLeave: () => {
370
+ setRailHovered(false);
371
+ closeSoon();
372
+ },
373
+ onBlurCapture: (event) => {
374
+ if (!event.currentTarget.contains(event.relatedTarget)) {
375
+ setRailHovered(false);
376
+ closeSoon();
377
+ }
378
+ },
379
+ children: [
380
+ /* @__PURE__ */ jsx("div", { className: s.trigger, children: entries.map((entry, index) => {
381
+ const near = railHovered && hovered >= 0 ? Math.abs(hovered - index) : 99;
382
+ const scale = near === 0 ? 1.8 : near === 1 ? 1.2 : current === entry.id ? 1.5 : 1;
383
+ const length = depthBasedLength ? Math.max(7, 15 - depth(entry) * 3) : 12;
384
+ return /* @__PURE__ */ jsx(
385
+ "a",
386
+ {
387
+ href: `#${encodeURIComponent(entry.id)}`,
388
+ "aria-label": entry.label,
389
+ ref: (node) => {
390
+ if (node) lineNodes.current.set(entry.id, node);
391
+ else lineNodes.current.delete(entry.id);
392
+ },
393
+ className: s.railItem,
394
+ "data-toc-line": true,
395
+ "data-active": current === entry.id,
396
+ "aria-current": current === entry.id ? "location" : void 0,
397
+ "aria-expanded": open && previewIndex === index,
398
+ onPointerEnter: () => {
399
+ setHovered(index);
400
+ keepOpen();
401
+ setOpen(true);
402
+ },
403
+ onFocus: () => {
404
+ if (suppressFocus.current) return;
405
+ setHovered(index);
406
+ setRailHovered(true);
407
+ keepOpen();
408
+ setOpen(true);
409
+ },
410
+ onClick: (event) => jump(entry, event),
411
+ style: {
412
+ "--toc-line-scale": scale,
413
+ "--toc-line-length": `${length}px`
414
+ },
415
+ children: /* @__PURE__ */ jsx("i", {})
416
+ },
417
+ entry.id
418
+ );
419
+ }) }),
420
+ /* @__PURE__ */ jsx(
421
+ Popover,
422
+ {
423
+ open,
424
+ onClose: () => {
425
+ suppressFocus.current = true;
426
+ setOpen(false);
427
+ queueMicrotask(() => {
428
+ suppressFocus.current = false;
429
+ });
430
+ },
431
+ anchor: popupAnchor,
432
+ side: "left",
433
+ align: "start",
434
+ label,
435
+ width: hoverMode === "single" ? 320 : 290,
436
+ className: s.previewSurface,
437
+ maxHeight: Infinity,
438
+ scrollable: false,
439
+ autoFocus: false,
440
+ children: /* @__PURE__ */ jsx(
441
+ "div",
442
+ {
443
+ className: s.card,
444
+ onPointerEnter: keepOpen,
445
+ onPointerLeave: closeSoon,
446
+ onFocusCapture: keepOpen,
447
+ onBlurCapture: (event) => {
448
+ if (!event.currentTarget.contains(event.relatedTarget) && event.relatedTarget !== popupAnchor.current)
449
+ closeSoon();
450
+ },
451
+ children: contents()
452
+ }
453
+ )
454
+ }
455
+ )
456
+ ]
457
+ }
458
+ );
459
+ }
460
+ export {
461
+ TableOfContents
462
+ };