@robert-stackflow/oneui 0.6.7 → 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 (114) hide show
  1. package/CHANGELOG.md +63 -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/Tab.module.css +148 -148
  78. package/components/Table.d.ts +8 -1
  79. package/components/Table.js +34 -17
  80. package/components/Table.module.css +87 -48
  81. package/components/TableMarkup.d.ts +2 -1
  82. package/components/TableMarkup.js +18 -1
  83. package/components/TableOfContents.d.ts +22 -0
  84. package/components/TableOfContents.js +462 -0
  85. package/components/TableOfContents.module.css +252 -0
  86. package/components/TextAreaSettingRow.d.ts +9 -0
  87. package/components/TextAreaSettingRow.js +47 -0
  88. package/components/TextSettingRow.d.ts +9 -0
  89. package/components/TextSettingRow.js +45 -0
  90. package/components/ThemePicker.module.css +178 -178
  91. package/components/ThemeProvider.js +2 -0
  92. package/components/TimeColumns.module.css +47 -47
  93. package/components/Timeline.module.css +202 -202
  94. package/components/Toast.d.ts +8 -1
  95. package/components/Toast.js +49 -17
  96. package/components/Toast.module.css +25 -0
  97. package/components/ToastProvider.d.ts +4 -1
  98. package/components/ToastProvider.js +67 -12
  99. package/components/TreeSelect.js +1 -0
  100. package/components/TreeTable.d.ts +3 -3
  101. package/components/TreeTable.js +12 -2
  102. package/components/TreeTable.module.css +57 -53
  103. package/components/createToaster.d.ts +2 -1
  104. package/components/createToaster.js +28 -14
  105. package/components/index.d.ts +18 -1
  106. package/components/index.js +24 -0
  107. package/components/motion.d.ts +1 -0
  108. package/components/motion.js +18 -6
  109. package/components/settingRowControl.d.ts +7 -0
  110. package/components/settingRowControl.js +15 -0
  111. package/package.json +57 -3
  112. package/styles/base.css +206 -206
  113. package/styles/blue.css +270 -268
  114. package/styles/minimal.css +4 -25
@@ -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
+ };
@@ -0,0 +1,252 @@
1
+ .tree {
2
+ min-width: 0;
3
+ color: var(--muted);
4
+ font-size: 13px;
5
+ }
6
+ .title {
7
+ display: flex;
8
+ align-items: center;
9
+ gap: 8px;
10
+ min-height: 28px;
11
+ margin-bottom: 8px;
12
+ padding-left: 3px;
13
+ font-size: 12px;
14
+ }
15
+ .scroll {
16
+ min-height: 0;
17
+ max-height: min(480px, 65vh);
18
+ overflow-y: auto;
19
+ overscroll-behavior: contain;
20
+ }
21
+ .list {
22
+ position: relative;
23
+ min-width: 0;
24
+ }
25
+ .guides {
26
+ position: absolute;
27
+ left: 0;
28
+ top: 0;
29
+ pointer-events: none;
30
+ overflow: visible;
31
+ }
32
+ .guides > path {
33
+ fill: none;
34
+ stroke: var(--line);
35
+ stroke-width: 1;
36
+ }
37
+ .list[data-ready="true"] .activeGuide {
38
+ transition: clip-path var(--motion-segment, 240ms) var(--ease);
39
+ }
40
+ .activeGuide > path {
41
+ stroke: var(--fg);
42
+ stroke-linecap: round;
43
+ }
44
+ .thumb {
45
+ position: absolute;
46
+ left: 0;
47
+ top: 0;
48
+ width: 4px;
49
+ height: 4px;
50
+ border-radius: 50%;
51
+ background: var(--fg);
52
+ offset-anchor: center;
53
+ offset-rotate: 0deg;
54
+ pointer-events: none;
55
+ }
56
+ .link {
57
+ position: relative;
58
+ display: block;
59
+ min-height: 32px;
60
+ padding: 6px 8px 6px calc(20px + var(--toc-depth) * 8px);
61
+ color: var(--muted);
62
+ font: inherit;
63
+ line-height: 1.6;
64
+ text-decoration: none;
65
+ overflow-wrap: anywhere;
66
+ transition: color var(--motion-hover);
67
+ }
68
+ .link:hover,
69
+ .link[data-active="true"] {
70
+ color: var(--fg);
71
+ }
72
+ .link:focus-visible {
73
+ outline: 2px solid var(--accent-ink, var(--accent));
74
+ outline-offset: -2px;
75
+ border-radius: 5px;
76
+ }
77
+ .rail {
78
+ display: inline-flex;
79
+ align-items: center;
80
+ }
81
+ .trigger {
82
+ display: flex;
83
+ flex-direction: column;
84
+ align-items: flex-end;
85
+ gap: 0;
86
+ padding: 8px 5px;
87
+ border: 0;
88
+ border-radius: 8px;
89
+ background: transparent;
90
+ cursor: pointer;
91
+ }
92
+ .railItem {
93
+ display: flex;
94
+ align-items: center;
95
+ justify-content: flex-end;
96
+ width: 26px;
97
+ height: 8px;
98
+ padding-right: 3px;
99
+ text-decoration: none;
100
+ }
101
+ .railItem > i {
102
+ width: var(--toc-line-length, 12px);
103
+ height: 2px;
104
+ border-radius: 999px;
105
+ background: var(--muted);
106
+ opacity: 0.22;
107
+ transform-origin: right center;
108
+ transform: scaleX(var(--toc-line-scale, 1));
109
+ transition:
110
+ transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1),
111
+ opacity 180ms var(--ease),
112
+ background-color 180ms var(--ease);
113
+ }
114
+ .railItem[data-active="true"] > i {
115
+ background: var(--fg);
116
+ opacity: 1;
117
+ }
118
+ .railItem:not([data-active="true"]):hover > i {
119
+ opacity: 0.65;
120
+ }
121
+ .trigger:focus-visible {
122
+ outline: 2px solid var(--accent-ink, var(--accent));
123
+ outline-offset: 2px;
124
+ }
125
+ .card {
126
+ padding: 12px;
127
+ min-height: 0;
128
+ flex-shrink: 1;
129
+ }
130
+ .card .scroll {
131
+ max-height: min(440px, calc(100dvh - 110px));
132
+ }
133
+ @media (prefers-reduced-motion: reduce) {
134
+ .activeGuide,
135
+ .thumb,
136
+ .link,
137
+ .railItem > i {
138
+ transition: none;
139
+ }
140
+ }
141
+
142
+ .flatMenu {
143
+ min-width: 0;
144
+ color: var(--fg);
145
+ font-size: 13px;
146
+ }
147
+ .flatMenu .title {
148
+ padding: 0 8px;
149
+ margin-bottom: 10px;
150
+ }
151
+ .flatList {
152
+ position: relative;
153
+ display: flex;
154
+ flex-direction: column;
155
+ gap: 3px;
156
+ }
157
+ .flatLink {
158
+ display: flex;
159
+ align-items: baseline;
160
+ gap: 12px;
161
+ min-width: 0;
162
+ padding: 9px 10px;
163
+ border-radius: 7px;
164
+ color: var(--muted);
165
+ line-height: 1.5;
166
+ text-decoration: none;
167
+ transition:
168
+ background-color var(--motion-hover),
169
+ color var(--motion-hover);
170
+ }
171
+ .flatLink:hover {
172
+ background: var(--hover);
173
+ color: var(--fg);
174
+ }
175
+ .flatLink[data-active="true"] {
176
+ color: var(--fg);
177
+ }
178
+ .flatLink[aria-current] {
179
+ background: var(--selected);
180
+ }
181
+ .flatLink:focus-visible {
182
+ outline: 2px solid var(--accent-ink, var(--accent));
183
+ outline-offset: -2px;
184
+ }
185
+ .number {
186
+ flex: 0 0 18px;
187
+ color: var(--muted);
188
+ font-size: 10px;
189
+ font-variant-numeric: tabular-nums;
190
+ opacity: 0.7;
191
+ }
192
+ .flatLink > span:last-child {
193
+ min-width: 0;
194
+ overflow-wrap: anywhere;
195
+ }
196
+ .card .flatMenu .scroll {
197
+ max-height: min(380px, calc(100dvh - 110px));
198
+ }
199
+
200
+ .list[data-ready="true"] .thumb {
201
+ transition:
202
+ offset-distance var(--motion-segment, 240ms) var(--ease),
203
+ opacity var(--motion-hover);
204
+ }
205
+ @media (prefers-reduced-motion: reduce) {
206
+ .list[data-ready="true"] .thumb,
207
+ .list[data-ready="true"] .activeGuide {
208
+ transition: none;
209
+ }
210
+ }
211
+
212
+ .railItem:focus-visible {
213
+ outline: 2px solid var(--accent-ink, var(--accent));
214
+ outline-offset: 1px;
215
+ border-radius: 4px;
216
+ }
217
+ .excerpt {
218
+ display: -webkit-box;
219
+ -webkit-box-orient: vertical;
220
+ -webkit-line-clamp: 3;
221
+ overflow: hidden;
222
+ margin-top: 6px;
223
+ color: var(--muted);
224
+ font-size: 12px;
225
+ line-height: 1.6;
226
+ font-weight: 400;
227
+ }
228
+
229
+ .previewSurface[data-motion-phase="visible"] {
230
+ transition:
231
+ top 160ms var(--ease),
232
+ left 160ms var(--ease);
233
+ }
234
+ .previewTitle {
235
+ display: -webkit-box;
236
+ -webkit-box-orient: vertical;
237
+ -webkit-line-clamp: 2;
238
+ overflow: hidden;
239
+ color: var(--fg);
240
+ font-size: 13px;
241
+ font-weight: 600;
242
+ line-height: 1.5;
243
+ }
244
+ .flatMenu[data-preview-mode="single"] .flatLink {
245
+ padding: 2px;
246
+ background: transparent;
247
+ }
248
+ @media (prefers-reduced-motion: reduce) {
249
+ .previewSurface[data-motion-phase="visible"] {
250
+ transition: none;
251
+ }
252
+ }