fromsrc 0.0.2 → 0.0.21
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/access.d.ts +7 -7
- package/dist/access.js +12 -5
- package/dist/adapter.js +8 -16
- package/dist/adapterbrowser.js +6 -10
- package/dist/adapternext.js +7 -18
- package/dist/adapterreactrouter.js +5 -9
- package/dist/adapterremix.js +8 -17
- package/dist/adaptertanstack.js +6 -10
- package/dist/algolia.js +43 -21
- package/dist/analytics.d.ts +1 -1
- package/dist/analytics.js +16 -10
- package/dist/ansi.js +76 -37
- package/dist/api.d.ts +10 -10
- package/dist/api.js +14 -11
- package/dist/audit.d.ts +6 -6
- package/dist/audit.js +29 -10
- package/dist/autotype.js +20 -10
- package/dist/batch.d.ts +6 -6
- package/dist/batch.js +16 -9
- package/dist/changelog.js +28 -14
- package/dist/changelogutil.d.ts +4 -4
- package/dist/changelogutil.js +33 -13
- package/dist/cli.d.ts +6 -6
- package/dist/cli.js +7 -3
- package/dist/client.d.ts +1 -1
- package/dist/codesample.d.ts +4 -4
- package/dist/codesample.js +63 -24
- package/dist/collapse.js +31 -13
- package/dist/collections.js +36 -16
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +5 -1
- package/dist/components/alert.d.ts +1 -1
- package/dist/components/alert.js +24 -13
- package/dist/components/announce.js +40 -17
- package/dist/components/autofill.js +17 -7
- package/dist/components/avatar.js +4 -4
- package/dist/components/avatarstack.js +2 -2
- package/dist/components/backtotop.d.ts +1 -1
- package/dist/components/backtotop.js +17 -4
- package/dist/components/badge.js +9 -4
- package/dist/components/banner.js +22 -5
- package/dist/components/breadcrumb.js +11 -4
- package/dist/components/breadcrumbnav.js +37 -21
- package/dist/components/button.js +23 -8
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/callout.js +33 -29
- package/dist/components/changelog.js +21 -8
- package/dist/components/checkbox.js +32 -19
- package/dist/components/code.d.ts +1 -1
- package/dist/components/code.js +6 -3
- package/dist/components/codeblock.js +157 -39
- package/dist/components/codecopy.d.ts +1 -1
- package/dist/components/codecopy.js +36 -13
- package/dist/components/codegroup.js +87 -25
- package/dist/components/collapsible.d.ts +1 -1
- package/dist/components/collapsible.js +5 -1
- package/dist/components/command.d.ts +1 -1
- package/dist/components/command.js +42 -15
- package/dist/components/compare.js +20 -8
- package/dist/components/content.js +121 -79
- package/dist/components/copybutton.d.ts +1 -1
- package/dist/components/copybutton.js +14 -7
- package/dist/components/countdown.js +9 -3
- package/dist/components/create.js +34 -24
- package/dist/components/definition.js +11 -4
- package/dist/components/diffview.js +63 -29
- package/dist/components/divider.js +5 -1
- package/dist/components/docheader.js +8 -1
- package/dist/components/doclinkcard.js +27 -3
- package/dist/components/dropdown.d.ts +1 -1
- package/dist/components/dropdown.js +32 -11
- package/dist/components/dynamiccode.js +5 -3
- package/dist/components/editlink.js +35 -23
- package/dist/components/embed.js +15 -7
- package/dist/components/endpoint.d.ts +3 -3
- package/dist/components/endpoint.js +24 -9
- package/dist/components/errormessage.d.ts +1 -1
- package/dist/components/errormessage.js +4 -1
- package/dist/components/expandcode.d.ts +1 -1
- package/dist/components/expandcode.js +6 -2
- package/dist/components/feature.js +8 -1
- package/dist/components/featuregrid.d.ts +4 -4
- package/dist/components/featuregrid.js +7 -1
- package/dist/components/feedback.js +6 -2
- package/dist/components/feedbackwidget.js +10 -4
- package/dist/components/files.d.ts +1 -1
- package/dist/components/files.js +52 -18
- package/dist/components/folder.d.ts +1 -1
- package/dist/components/folder.js +21 -4
- package/dist/components/footer.js +5 -1
- package/dist/components/formlabel.d.ts +1 -1
- package/dist/components/formlabel.js +31 -18
- package/dist/components/github.js +43 -14
- package/dist/components/graph.js +38 -14
- package/dist/components/heading.js +36 -29
- package/dist/components/headingcopy.js +13 -5
- package/dist/components/hero.js +20 -14
- package/dist/components/highlight.d.ts +2 -2
- package/dist/components/highlight.js +14 -8
- package/dist/components/hover.d.ts +2 -2
- package/dist/components/hover.js +11 -4
- package/dist/components/icons.js +4 -1
- package/dist/components/inlinetoc.js +3 -1
- package/dist/components/input.js +13 -3
- package/dist/components/install.js +34 -24
- package/dist/components/kbd.js +19 -11
- package/dist/components/langicon.d.ts +1 -1
- package/dist/components/langicon.js +22 -17
- package/dist/components/language.d.ts +1 -1
- package/dist/components/language.js +12 -4
- package/dist/components/lastupdated.d.ts +2 -2
- package/dist/components/lastupdated.js +36 -12
- package/dist/components/link.d.ts +1 -1
- package/dist/components/linkcard.js +3 -1
- package/dist/components/list.d.ts +1 -1
- package/dist/components/list.js +4 -1
- package/dist/components/math.js +33 -8
- package/dist/components/mermaid.js +3 -3
- package/dist/components/mobilenav.d.ts +2 -1
- package/dist/components/mobilenav.js +116 -47
- package/dist/components/modal.d.ts +1 -1
- package/dist/components/modal.js +9 -2
- package/dist/components/navlink.js +17 -3
- package/dist/components/openapi.d.ts +1 -1
- package/dist/components/openapi.js +102 -32
- package/dist/components/openapischema.d.ts +1 -1
- package/dist/components/openapischema.js +29 -9
- package/dist/components/openapitags.js +6 -2
- package/dist/components/pagetransition.js +5 -3
- package/dist/components/pagination.js +3 -2
- package/dist/components/panel.js +91 -15
- package/dist/components/playground.d.ts +1 -1
- package/dist/components/playground.js +153 -50
- package/dist/components/popover.js +9 -7
- package/dist/components/prelink.js +40 -9
- package/dist/components/prevnext.d.ts +1 -1
- package/dist/components/prevnext.js +36 -16
- package/dist/components/progress.js +2 -2
- package/dist/components/property.js +3 -1
- package/dist/components/quote.d.ts +2 -2
- package/dist/components/quote.js +32 -4
- package/dist/components/radio.js +36 -18
- package/dist/components/rating.js +14 -3
- package/dist/components/recent.d.ts +1 -1
- package/dist/components/recent.js +26 -10
- package/dist/components/responsive.js +21 -13
- package/dist/components/results.js +8 -4
- package/dist/components/screenshot.js +61 -21
- package/dist/components/scrollprogress.js +9 -5
- package/dist/components/scrollspy.d.ts +2 -2
- package/dist/components/scrollspy.js +9 -3
- package/dist/components/search.js +47 -18
- package/dist/components/searchbutton.js +3 -1
- package/dist/components/searchdialog.js +35 -22
- package/dist/components/searcher.d.ts +1 -1
- package/dist/components/searcher.js +51 -26
- package/dist/components/select.js +27 -13
- package/dist/components/shortcuts.d.ts +1 -1
- package/dist/components/shortcuts.js +57 -38
- package/dist/components/sidebar.d.ts +2 -1
- package/dist/components/sidebar.js +221 -56
- package/dist/components/sidebarfilter.d.ts +1 -1
- package/dist/components/sidebarfilter.js +30 -6
- package/dist/components/sidebarscript.d.ts +5 -0
- package/dist/components/sidebarscript.js +18 -0
- package/dist/components/skeleton.js +15 -3
- package/dist/components/spinner.js +13 -3
- package/dist/components/status.js +20 -8
- package/dist/components/steps.js +3 -1
- package/dist/components/switch.js +4 -4
- package/dist/components/table.js +37 -12
- package/dist/components/tabnav.d.ts +1 -1
- package/dist/components/tabnav.js +48 -36
- package/dist/components/tabs.d.ts +1 -1
- package/dist/components/tabs.js +56 -40
- package/dist/components/tag.js +8 -3
- package/dist/components/terminal.js +14 -4
- package/dist/components/textarea.js +96 -82
- package/dist/components/theme.d.ts +1 -1
- package/dist/components/theme.js +25 -3
- package/dist/components/themeprovider.d.ts +4 -4
- package/dist/components/themeprovider.js +16 -5
- package/dist/components/toast.d.ts +1 -1
- package/dist/components/toast.js +23 -14
- package/dist/components/toc/default.d.ts +1 -1
- package/dist/components/toc/default.js +28 -13
- package/dist/components/toc/hook.js +28 -14
- package/dist/components/toc/index.js +8 -4
- package/dist/components/toc/inline.js +12 -2
- package/dist/components/toc/minimal.js +11 -5
- package/dist/components/toc/zigzag.d.ts +1 -1
- package/dist/components/toc/zigzag.js +37 -17
- package/dist/components/tocprogress.d.ts +1 -1
- package/dist/components/tocprogress.js +66 -34
- package/dist/components/tooltip.d.ts +1 -1
- package/dist/components/tooltip.js +20 -8
- package/dist/components/trigger.js +13 -5
- package/dist/components/twoslash.js +49 -26
- package/dist/components/typetable.js +23 -4
- package/dist/components/typewriter.js +6 -2
- package/dist/components/version.js +40 -14
- package/dist/components/video.js +25 -15
- package/dist/components/zoom.js +6 -2
- package/dist/config.d.ts +2 -2
- package/dist/config.js +56 -30
- package/dist/content.d.ts +5 -5
- package/dist/content.js +121 -57
- package/dist/contentcache.d.ts +10 -10
- package/dist/contentcache.js +9 -5
- package/dist/contentdiff.d.ts +4 -4
- package/dist/contentdiff.js +16 -8
- package/dist/contributors.d.ts +4 -4
- package/dist/contributors.js +49 -19
- package/dist/diff.d.ts +6 -6
- package/dist/diff.js +37 -16
- package/dist/draft.d.ts +11 -11
- package/dist/draft.js +9 -5
- package/dist/env.js +21 -7
- package/dist/export.js +4 -4
- package/dist/frontmatter.js +11 -9
- package/dist/github.js +60 -30
- package/dist/gitsource.d.ts +1 -1
- package/dist/gitsource.js +16 -9
- package/dist/hash.d.ts +6 -6
- package/dist/hash.js +19 -7
- package/dist/highlight.d.ts +4 -4
- package/dist/highlight.js +34 -14
- package/dist/hooks/anchor.js +26 -14
- package/dist/hooks/arrownav.js +25 -7
- package/dist/hooks/async.js +3 -3
- package/dist/hooks/battery.js +11 -3
- package/dist/hooks/breakpoint.js +10 -2
- package/dist/hooks/clickoutside.js +10 -3
- package/dist/hooks/clipboard-paste.js +7 -3
- package/dist/hooks/clipboard.d.ts +2 -2
- package/dist/hooks/clipboard.js +21 -15
- package/dist/hooks/copy.js +11 -6
- package/dist/hooks/countdown.js +1 -1
- package/dist/hooks/counter.js +1 -1
- package/dist/hooks/escapekey.js +6 -1
- package/dist/hooks/eventlistener.js +3 -1
- package/dist/hooks/eventsource.js +4 -2
- package/dist/hooks/eyedropper.js +7 -3
- package/dist/hooks/favicon.js +1 -1
- package/dist/hooks/fetch.js +12 -4
- package/dist/hooks/focustrap.js +20 -8
- package/dist/hooks/focuswithin.js +6 -2
- package/dist/hooks/form.d.ts +2 -2
- package/dist/hooks/form.js +15 -2
- package/dist/hooks/fullscreen.js +1 -1
- package/dist/hooks/geolocation.js +8 -8
- package/dist/hooks/hotkeys.js +19 -7
- package/dist/hooks/hover.d.ts +4 -1
- package/dist/hooks/hover.js +3 -1
- package/dist/hooks/idle.js +13 -3
- package/dist/hooks/infinitescroll.js +4 -2
- package/dist/hooks/interval.js +3 -1
- package/dist/hooks/inview.js +7 -3
- package/dist/hooks/keyboard.js +36 -12
- package/dist/hooks/keypress.js +6 -2
- package/dist/hooks/list.js +11 -1
- package/dist/hooks/longpress.js +3 -3
- package/dist/hooks/map.js +1 -1
- package/dist/hooks/measure.js +16 -7
- package/dist/hooks/mediarecorder.js +7 -3
- package/dist/hooks/networkstate.js +4 -2
- package/dist/hooks/os.js +12 -4
- package/dist/hooks/pagination.js +6 -4
- package/dist/hooks/permission.js +6 -2
- package/dist/hooks/queue.js +4 -2
- package/dist/hooks/readprogress.js +6 -2
- package/dist/hooks/resizeobserver.js +6 -4
- package/dist/hooks/script.js +1 -1
- package/dist/hooks/scrolllock.js +6 -2
- package/dist/hooks/scrollspy.js +4 -2
- package/dist/hooks/selection.js +6 -3
- package/dist/hooks/share.js +18 -9
- package/dist/hooks/speechrecognition.js +7 -3
- package/dist/hooks/stepper.js +4 -4
- package/dist/hooks/storage.js +9 -3
- package/dist/hooks/stylesheet.js +4 -2
- package/dist/hooks/textselection.js +6 -3
- package/dist/hooks/throttle.js +6 -2
- package/dist/hooks/undoredo.js +19 -11
- package/dist/hooks/vibrate.js +3 -1
- package/dist/hooks/viewtransition.js +8 -4
- package/dist/hooks/wakelock.js +12 -7
- package/dist/hooks/websocket.js +4 -2
- package/dist/hooks/windowsize.js +2 -2
- package/dist/i18n.d.ts +2 -2
- package/dist/i18n.js +27 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lastmodified.js +11 -5
- package/dist/linkcheck.d.ts +6 -6
- package/dist/linkcheck.js +55 -14
- package/dist/llms.js +20 -4
- package/dist/manifest.js +7 -7
- package/dist/mcp.js +28 -22
- package/dist/mdtoc.d.ts +4 -4
- package/dist/mdtoc.js +11 -5
- package/dist/mdxscope.d.ts +2 -2
- package/dist/mdxscope.js +3 -1
- package/dist/meta.js +19 -7
- package/dist/migrate.js +35 -25
- package/dist/navgen.d.ts +8 -8
- package/dist/navgen.js +73 -30
- package/dist/navtree.d.ts +1 -1
- package/dist/navtree.js +39 -19
- package/dist/oembed.d.ts +4 -4
- package/dist/oembed.js +24 -18
- package/dist/ogimage.d.ts +11 -11
- package/dist/ogimage.js +24 -24
- package/dist/openapi.js +60 -33
- package/dist/openapiguard.js +21 -11
- package/dist/openapiutil.js +66 -20
- package/dist/orama.js +52 -34
- package/dist/pipeline.d.ts +4 -4
- package/dist/pipeline.js +4 -4
- package/dist/preload.d.ts +2 -2
- package/dist/preload.js +4 -4
- package/dist/ranking.d.ts +6 -6
- package/dist/ranking.js +39 -13
- package/dist/readtime.js +3 -1
- package/dist/redirects.d.ts +2 -2
- package/dist/redirects.js +20 -12
- package/dist/rehype.js +16 -9
- package/dist/rehypeautolink.d.ts +2 -2
- package/dist/rehypeautolink.js +25 -23
- package/dist/rehypecode.js +38 -28
- package/dist/rehypecopy.js +17 -13
- package/dist/rehypeinline.js +33 -27
- package/dist/rehypelinks.js +28 -20
- package/dist/rehyperaw.js +9 -3
- package/dist/rehypeslug.d.ts +1 -1
- package/dist/rehypeslug.js +23 -19
- package/dist/rehypetablewrap.d.ts +2 -2
- package/dist/rehypetablewrap.js +9 -5
- package/dist/rehypetoc.d.ts +1 -1
- package/dist/rehypetoc.js +15 -7
- package/dist/remark.js +28 -13
- package/dist/remarkadmonition.js +40 -14
- package/dist/remarkannotation.d.ts +2 -2
- package/dist/remarkannotation.js +26 -10
- package/dist/remarkbadge.js +43 -31
- package/dist/remarkblockmath.js +29 -15
- package/dist/remarkcallout.js +32 -14
- package/dist/remarkcaption.js +28 -16
- package/dist/remarkcodetitle.js +29 -13
- package/dist/remarkcolumns.js +22 -10
- package/dist/remarkdetails.js +34 -14
- package/dist/remarkdirective.js +47 -20
- package/dist/remarkembed.js +38 -22
- package/dist/remarkfiletree.js +29 -19
- package/dist/remarkfootnote.js +46 -18
- package/dist/remarkgfm.js +13 -8
- package/dist/remarkheadingid.js +16 -6
- package/dist/remarkimage.js +54 -34
- package/dist/remarkinclude.js +20 -8
- package/dist/remarkinstall.js +20 -12
- package/dist/remarklinkcard.js +33 -14
- package/dist/remarkmath.js +34 -15
- package/dist/remarkmermaid.js +10 -6
- package/dist/remarkmeta.d.ts +2 -2
- package/dist/remarkmeta.js +15 -5
- package/dist/remarkreadingtime.d.ts +2 -2
- package/dist/remarkreadingtime.js +3 -1
- package/dist/remarksteps.js +26 -14
- package/dist/remarkstructure.js +16 -10
- package/dist/remarktabs.js +31 -14
- package/dist/remarktoc.js +40 -24
- package/dist/remarkts2js.js +51 -40
- package/dist/remarktwoslash.d.ts +4 -4
- package/dist/remarktwoslash.js +24 -14
- package/dist/remarkvideo.d.ts +4 -4
- package/dist/remarkvideo.js +42 -16
- package/dist/schema.d.ts +14 -14
- package/dist/schema.js +2 -2
- package/dist/search.js +106 -48
- package/dist/searchindex.js +86 -34
- package/dist/searchpolicy.js +1 -1
- package/dist/searchscore.js +5 -5
- package/dist/searchtypo.js +30 -10
- package/dist/seo.d.ts +2 -2
- package/dist/seo.js +14 -14
- package/dist/shortcodes.d.ts +4 -4
- package/dist/shortcodes.js +25 -20
- package/dist/sitemap.js +18 -8
- package/dist/snippets.js +26 -18
- package/dist/source.js +75 -41
- package/dist/stats.d.ts +4 -4
- package/dist/stats.js +18 -12
- package/dist/testing.d.ts +7 -7
- package/dist/testing.js +74 -29
- package/dist/themeutil.d.ts +6 -6
- package/dist/themeutil.js +145 -27
- package/dist/typegen.js +31 -12
- package/dist/validate.js +19 -7
- package/dist/validator.d.ts +11 -11
- package/dist/validator.js +68 -19
- package/dist/versioning.d.ts +7 -7
- package/dist/versioning.js +27 -11
- package/dist/watcher.js +39 -15
- package/dist/webhook.d.ts +6 -6
- package/dist/webhook.js +34 -12
- package/dist/workspace.js +26 -12
- package/package.json +137 -137
- package/styles/reset.css +1 -1
|
@@ -2,17 +2,17 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type ThemeMode = "light" | "dark" | "system";
|
|
5
|
-
|
|
5
|
+
interface ThemeContextValue {
|
|
6
6
|
theme: ThemeMode;
|
|
7
7
|
resolved: "light" | "dark";
|
|
8
8
|
setTheme: (theme: ThemeMode) => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
9
|
+
}
|
|
10
|
+
interface ThemeProviderProps {
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
defaultTheme?: ThemeMode;
|
|
13
13
|
storageKey?: string;
|
|
14
14
|
attribute?: string;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
declare function ThemeProvider({ children, defaultTheme, storageKey, attribute, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
|
|
17
17
|
declare function useTheme(): ThemeContextValue;
|
|
18
18
|
|
|
@@ -19,12 +19,16 @@ function ThemeProvider({
|
|
|
19
19
|
attribute = "data-theme"
|
|
20
20
|
}) {
|
|
21
21
|
const [theme, setTheme] = useState(() => {
|
|
22
|
-
if (typeof window === "undefined")
|
|
22
|
+
if (typeof window === "undefined") {
|
|
23
|
+
return defaultTheme;
|
|
24
|
+
}
|
|
23
25
|
const stored = localStorage.getItem(storageKey);
|
|
24
26
|
return istheme(stored) ? stored : defaultTheme;
|
|
25
27
|
});
|
|
26
28
|
const [resolved, setResolved] = useState(() => {
|
|
27
|
-
if (typeof window === "undefined")
|
|
29
|
+
if (typeof window === "undefined") {
|
|
30
|
+
return "light";
|
|
31
|
+
}
|
|
28
32
|
return resolve(theme);
|
|
29
33
|
});
|
|
30
34
|
useEffect(() => {
|
|
@@ -35,7 +39,9 @@ function ThemeProvider({
|
|
|
35
39
|
localStorage.setItem(storageKey, theme);
|
|
36
40
|
}, [theme, attribute, storageKey]);
|
|
37
41
|
useEffect(() => {
|
|
38
|
-
if (theme !== "system")
|
|
42
|
+
if (theme !== "system") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
39
45
|
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
40
46
|
const handler = () => {
|
|
41
47
|
const r = resolve(theme);
|
|
@@ -46,12 +52,17 @@ function ThemeProvider({
|
|
|
46
52
|
media.addEventListener("change", handler);
|
|
47
53
|
return () => media.removeEventListener("change", handler);
|
|
48
54
|
}, [theme, attribute]);
|
|
49
|
-
const value = useMemo(
|
|
55
|
+
const value = useMemo(
|
|
56
|
+
() => ({ resolved, setTheme, theme }),
|
|
57
|
+
[theme, resolved]
|
|
58
|
+
);
|
|
50
59
|
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children });
|
|
51
60
|
}
|
|
52
61
|
function useTheme() {
|
|
53
62
|
const context = useContext(ThemeContext);
|
|
54
|
-
if (!context)
|
|
63
|
+
if (!context) {
|
|
64
|
+
throw new Error("useTheme must be used within ThemeProvider");
|
|
65
|
+
}
|
|
55
66
|
return context;
|
|
56
67
|
}
|
|
57
68
|
|
package/dist/components/toast.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { createContext, useState, useRef, useCallback, useEffect, useContext } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { IconAlertCircle, IconCheckCircle, IconInfo, IconXCircle, IconX } from './icons';
|
|
5
5
|
|
|
6
6
|
const ToastContext = createContext(null);
|
|
7
|
-
function ToastProvider({
|
|
7
|
+
function ToastProvider({
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
8
10
|
const [toasts, setToasts] = useState([]);
|
|
9
11
|
const timers = useRef(/* @__PURE__ */ new Map());
|
|
10
12
|
const counter = useRef(0);
|
|
@@ -27,33 +29,38 @@ function ToastProvider({ children }) {
|
|
|
27
29
|
}, duration);
|
|
28
30
|
timers.current.set(id, timer);
|
|
29
31
|
}, []);
|
|
30
|
-
useEffect(
|
|
31
|
-
|
|
32
|
-
for (const timer of timers.current.values())
|
|
32
|
+
useEffect(
|
|
33
|
+
() => () => {
|
|
34
|
+
for (const timer of timers.current.values()) {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
}
|
|
33
37
|
timers.current.clear();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
},
|
|
39
|
+
[]
|
|
40
|
+
);
|
|
41
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: { add, remove, toasts }, children: [
|
|
37
42
|
children,
|
|
38
43
|
/* @__PURE__ */ jsx(ToastContainer, {})
|
|
39
44
|
] });
|
|
40
45
|
}
|
|
41
46
|
function useToast() {
|
|
42
47
|
const ctx = useContext(ToastContext);
|
|
43
|
-
if (!ctx)
|
|
48
|
+
if (!ctx) {
|
|
49
|
+
throw new Error("useToast must be used within ToastProvider");
|
|
50
|
+
}
|
|
44
51
|
return ctx;
|
|
45
52
|
}
|
|
46
53
|
const icons = {
|
|
54
|
+
error: IconXCircle,
|
|
47
55
|
info: IconInfo,
|
|
48
56
|
success: IconCheckCircle,
|
|
49
|
-
warning: IconAlertCircle
|
|
50
|
-
error: IconXCircle
|
|
57
|
+
warning: IconAlertCircle
|
|
51
58
|
};
|
|
52
59
|
const styles = {
|
|
60
|
+
error: "border-red-500/30 bg-red-500/10",
|
|
53
61
|
info: "border-blue-500/30 bg-blue-500/10",
|
|
54
62
|
success: "border-green-500/30 bg-green-500/10",
|
|
55
|
-
warning: "border-yellow-500/30 bg-yellow-500/10"
|
|
56
|
-
error: "border-red-500/30 bg-red-500/10"
|
|
63
|
+
warning: "border-yellow-500/30 bg-yellow-500/10"
|
|
57
64
|
};
|
|
58
65
|
function ToastContainer() {
|
|
59
66
|
const { toasts, remove } = useToast();
|
|
@@ -63,7 +70,9 @@ function ToastContainer() {
|
|
|
63
70
|
},
|
|
64
71
|
[remove]
|
|
65
72
|
);
|
|
66
|
-
if (toasts.length === 0)
|
|
73
|
+
if (toasts.length === 0) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
67
76
|
return /* @__PURE__ */ jsx(
|
|
68
77
|
"div",
|
|
69
78
|
{
|
|
@@ -15,7 +15,7 @@ interface Props {
|
|
|
15
15
|
/** Enable zigzag line decoration */
|
|
16
16
|
zigzag?: boolean;
|
|
17
17
|
}
|
|
18
|
-
declare function TocDefaultBase({ headings, active, activeRange, zigzag }: Props): JSX.Element;
|
|
18
|
+
declare function TocDefaultBase({ headings, active, activeRange, zigzag, }: Props): JSX.Element;
|
|
19
19
|
declare const TocDefault: react.MemoExoticComponent<typeof TocDefaultBase>;
|
|
20
20
|
|
|
21
21
|
export { TocDefault };
|
|
@@ -3,18 +3,27 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { memo, useRef, useState, useEffect } from 'react';
|
|
4
4
|
import { ZigzagLine, getItemOffset, buildZigzagPath } from './zigzag';
|
|
5
5
|
|
|
6
|
-
function TocDefaultBase({
|
|
6
|
+
function TocDefaultBase({
|
|
7
|
+
headings,
|
|
8
|
+
active,
|
|
9
|
+
activeRange,
|
|
10
|
+
zigzag
|
|
11
|
+
}) {
|
|
7
12
|
const containerRef = useRef(null);
|
|
8
13
|
const [svg, setSvg] = useState(null);
|
|
9
|
-
const [thumb, setThumb] = useState({
|
|
14
|
+
const [thumb, setThumb] = useState({ height: 0, top: 0 });
|
|
10
15
|
const range = activeRange.length > 0 ? activeRange : active ? [active] : [];
|
|
11
16
|
const isActive = (id) => range.includes(id);
|
|
12
17
|
useEffect(() => {
|
|
13
|
-
if (!zigzag || !containerRef.current || headings.length === 0)
|
|
18
|
+
if (!zigzag || !containerRef.current || headings.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
14
21
|
const container = containerRef.current;
|
|
15
22
|
function update() {
|
|
16
23
|
const result = buildZigzagPath(headings, container);
|
|
17
|
-
if (result)
|
|
24
|
+
if (result) {
|
|
25
|
+
setSvg(result);
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
const observer = new ResizeObserver(update);
|
|
20
29
|
update();
|
|
@@ -22,21 +31,27 @@ function TocDefaultBase({ headings, active, activeRange, zigzag }) {
|
|
|
22
31
|
return () => observer.disconnect();
|
|
23
32
|
}, [headings, zigzag]);
|
|
24
33
|
useEffect(() => {
|
|
25
|
-
if (!zigzag || !containerRef.current || range.length === 0)
|
|
34
|
+
if (!zigzag || !containerRef.current || range.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
26
37
|
const container = containerRef.current;
|
|
27
38
|
let upper = Infinity;
|
|
28
39
|
let lower = 0;
|
|
29
40
|
for (const id of range) {
|
|
30
|
-
const element = container.querySelector(
|
|
31
|
-
|
|
41
|
+
const element = container.querySelector(
|
|
42
|
+
`a[href="#${id}"]`
|
|
43
|
+
);
|
|
44
|
+
if (!element) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
32
47
|
const styles = getComputedStyle(element);
|
|
33
|
-
const top = element.offsetTop + parseFloat(styles.paddingTop);
|
|
34
|
-
const bottom = element.offsetTop + element.clientHeight - parseFloat(styles.paddingBottom);
|
|
48
|
+
const top = element.offsetTop + Number.parseFloat(styles.paddingTop);
|
|
49
|
+
const bottom = element.offsetTop + element.clientHeight - Number.parseFloat(styles.paddingBottom);
|
|
35
50
|
upper = Math.min(upper, top);
|
|
36
51
|
lower = Math.max(lower, bottom);
|
|
37
52
|
}
|
|
38
53
|
if (upper !== Infinity) {
|
|
39
|
-
setThumb({
|
|
54
|
+
setThumb({ height: lower - upper, top: upper });
|
|
40
55
|
}
|
|
41
56
|
}, [range, zigzag]);
|
|
42
57
|
if (zigzag) {
|
|
@@ -47,17 +62,17 @@ function TocDefaultBase({ headings, active, activeRange, zigzag }) {
|
|
|
47
62
|
"aria-hidden": "true",
|
|
48
63
|
className: "absolute left-0 top-0 pointer-events-none z-10",
|
|
49
64
|
style: {
|
|
50
|
-
width: svg.width,
|
|
51
65
|
height: svg.height,
|
|
52
66
|
maskImage: `url("data:image/svg+xml,${encodeURIComponent(
|
|
53
67
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${svg.width} ${svg.height}"><path d="${svg.path}" stroke="black" stroke-width="1" fill="none" /></svg>`
|
|
54
|
-
)}")
|
|
68
|
+
)}")`,
|
|
69
|
+
width: svg.width
|
|
55
70
|
},
|
|
56
71
|
children: /* @__PURE__ */ jsx(
|
|
57
72
|
"div",
|
|
58
73
|
{
|
|
59
74
|
className: "absolute w-full bg-fg transition-[top,height] duration-150",
|
|
60
|
-
style: {
|
|
75
|
+
style: { height: thumb.height, top: thumb.top }
|
|
61
76
|
}
|
|
62
77
|
)
|
|
63
78
|
}
|
|
@@ -10,15 +10,17 @@ function useToc(multi = false) {
|
|
|
10
10
|
const [activeRange, setActiveRange] = useState([]);
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
function scan() {
|
|
13
|
-
const elements = document.querySelectorAll(
|
|
13
|
+
const elements = document.querySelectorAll(
|
|
14
|
+
"article h2, article h3, article h4, article h5, article h6"
|
|
15
|
+
);
|
|
14
16
|
const items = [];
|
|
15
17
|
elements.forEach((el) => {
|
|
16
18
|
if (el.id) {
|
|
17
19
|
const level = Number(el.tagName.replace("H", ""));
|
|
18
20
|
items.push({
|
|
19
21
|
id: el.id,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
level: Number.isFinite(level) ? level : 2,
|
|
23
|
+
text: cleanheading(el.textContent || "")
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
});
|
|
@@ -37,13 +39,17 @@ function useToc(multi = false) {
|
|
|
37
39
|
return () => observer.disconnect();
|
|
38
40
|
}, []);
|
|
39
41
|
useEffect(() => {
|
|
40
|
-
if (headings.length === 0)
|
|
42
|
+
if (headings.length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
41
45
|
function findClosest() {
|
|
42
46
|
let closest = headings[0]?.id || "";
|
|
43
47
|
let minDistance = Infinity;
|
|
44
48
|
for (const { id } of headings) {
|
|
45
|
-
const el = document.
|
|
46
|
-
if (!el)
|
|
49
|
+
const el = document.querySelector(`#${id}`);
|
|
50
|
+
if (!el) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
47
53
|
const rect = el.getBoundingClientRect();
|
|
48
54
|
const distance = Math.abs(rect.top);
|
|
49
55
|
if (distance < minDistance) {
|
|
@@ -77,8 +83,10 @@ function useToc(multi = false) {
|
|
|
77
83
|
{ rootMargin: "0px", threshold: 0.9 }
|
|
78
84
|
);
|
|
79
85
|
for (const { id } of headings) {
|
|
80
|
-
const el = document.
|
|
81
|
-
if (el)
|
|
86
|
+
const el = document.querySelector(`#${id}`);
|
|
87
|
+
if (el) {
|
|
88
|
+
observer.observe(el);
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
91
|
return () => observer.disconnect();
|
|
84
92
|
}
|
|
@@ -86,23 +94,29 @@ function useToc(multi = false) {
|
|
|
86
94
|
function update() {
|
|
87
95
|
const atBottom = window.innerHeight + Math.ceil(window.scrollY) >= document.documentElement.scrollHeight;
|
|
88
96
|
if (atBottom && headings.length > 0) {
|
|
89
|
-
const last = headings
|
|
90
|
-
if (last)
|
|
97
|
+
const last = headings.at(-1);
|
|
98
|
+
if (last) {
|
|
99
|
+
setActive(last.id);
|
|
100
|
+
}
|
|
91
101
|
return;
|
|
92
102
|
}
|
|
93
103
|
const offset = 100;
|
|
94
104
|
let current = "";
|
|
95
105
|
const items = headings.slice(0, -1);
|
|
96
106
|
for (const { id } of items) {
|
|
97
|
-
const el = document.
|
|
98
|
-
if (!el)
|
|
107
|
+
const el = document.querySelector(`#${id}`);
|
|
108
|
+
if (!el) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
99
111
|
if (el.getBoundingClientRect().top <= offset) {
|
|
100
112
|
current = id;
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
if (!current && headings.length > 0) {
|
|
104
116
|
const first = headings[0];
|
|
105
|
-
if (first)
|
|
117
|
+
if (first) {
|
|
118
|
+
current = first.id;
|
|
119
|
+
}
|
|
106
120
|
}
|
|
107
121
|
setActive(current);
|
|
108
122
|
}
|
|
@@ -119,7 +133,7 @@ function useToc(multi = false) {
|
|
|
119
133
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
120
134
|
return () => window.removeEventListener("scroll", onScroll);
|
|
121
135
|
}, [headings, multi]);
|
|
122
|
-
return {
|
|
136
|
+
return { active, activeRange, headings };
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
export { useToc };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { TocDefault } from './default';
|
|
3
4
|
import { useToc } from './hook';
|
|
4
5
|
export { useToc } from './hook';
|
|
5
|
-
import { TocDefault } from './default';
|
|
6
|
-
import { TocMinimal } from './minimal';
|
|
7
6
|
import { TocInline } from './inline';
|
|
7
|
+
import { TocMinimal } from './minimal';
|
|
8
8
|
|
|
9
9
|
function Toc({
|
|
10
10
|
variant = "default",
|
|
@@ -14,8 +14,12 @@ function Toc({
|
|
|
14
14
|
collapsible = true,
|
|
15
15
|
defaultOpen = false
|
|
16
16
|
}) {
|
|
17
|
-
const { headings, active, activeRange } = useToc(
|
|
18
|
-
|
|
17
|
+
const { headings, active, activeRange } = useToc(
|
|
18
|
+
variant !== "minimal" && multi
|
|
19
|
+
);
|
|
20
|
+
if (headings.length === 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
19
23
|
if (variant === "inline") {
|
|
20
24
|
return /* @__PURE__ */ jsx(
|
|
21
25
|
TocInline,
|
|
@@ -12,7 +12,9 @@ function TocInlineBase({
|
|
|
12
12
|
const toggle = useCallback(() => {
|
|
13
13
|
setOpen((prev) => !prev);
|
|
14
14
|
}, []);
|
|
15
|
-
if (headings.length === 0)
|
|
15
|
+
if (headings.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
16
18
|
const content = /* @__PURE__ */ jsx("div", { className: "flex flex-col text-sm text-muted", children: headings.map((heading) => /* @__PURE__ */ jsx(
|
|
17
19
|
"a",
|
|
18
20
|
{
|
|
@@ -59,7 +61,15 @@ function TocInlineBase({
|
|
|
59
61
|
viewBox: "0 0 24 24",
|
|
60
62
|
stroke: "currentColor",
|
|
61
63
|
"aria-hidden": "true",
|
|
62
|
-
children: /* @__PURE__ */ jsx(
|
|
64
|
+
children: /* @__PURE__ */ jsx(
|
|
65
|
+
"path",
|
|
66
|
+
{
|
|
67
|
+
strokeLinecap: "round",
|
|
68
|
+
strokeLinejoin: "round",
|
|
69
|
+
strokeWidth: 2,
|
|
70
|
+
d: "M19 9l-7 7-7-7"
|
|
71
|
+
}
|
|
72
|
+
)
|
|
63
73
|
}
|
|
64
74
|
)
|
|
65
75
|
]
|
|
@@ -9,11 +9,15 @@ function TocMinimalBase({ headings, active, zigzag }) {
|
|
|
9
9
|
const progressRef = useRef(null);
|
|
10
10
|
const [svg, setSvg] = useState(null);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
if (!zigzag || !containerRef.current || headings.length === 0)
|
|
12
|
+
if (!zigzag || !containerRef.current || headings.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
13
15
|
const container = containerRef.current;
|
|
14
16
|
function update() {
|
|
15
17
|
const result = buildZigzagPath(headings, container);
|
|
16
|
-
if (result)
|
|
18
|
+
if (result) {
|
|
19
|
+
setSvg(result);
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
const observer = new ResizeObserver(update);
|
|
19
23
|
update();
|
|
@@ -24,7 +28,9 @@ function TocMinimalBase({ headings, active, zigzag }) {
|
|
|
24
28
|
const container = containerRef.current;
|
|
25
29
|
const thumb = thumbRef.current;
|
|
26
30
|
const progress = progressRef.current;
|
|
27
|
-
if (!container)
|
|
31
|
+
if (!container) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
28
34
|
let ticking = false;
|
|
29
35
|
function update() {
|
|
30
36
|
const scrollTop = window.scrollY;
|
|
@@ -64,11 +70,11 @@ function TocMinimalBase({ headings, active, zigzag }) {
|
|
|
64
70
|
{
|
|
65
71
|
className: "absolute left-0 top-0 pointer-events-none z-10",
|
|
66
72
|
style: {
|
|
67
|
-
width: svg.width,
|
|
68
73
|
height: svg.height,
|
|
69
74
|
maskImage: `url("data:image/svg+xml,${encodeURIComponent(
|
|
70
75
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${svg.width} ${svg.height}"><path d="${svg.path}" stroke="black" stroke-width="1" fill="none" /></svg>`
|
|
71
|
-
)}")
|
|
76
|
+
)}")`,
|
|
77
|
+
width: svg.width
|
|
72
78
|
},
|
|
73
79
|
children: /* @__PURE__ */ jsx(
|
|
74
80
|
"div",
|
|
@@ -6,7 +6,7 @@ interface Props {
|
|
|
6
6
|
upper?: number;
|
|
7
7
|
lower?: number;
|
|
8
8
|
}
|
|
9
|
-
declare function ZigzagLine({ heading, upper, lower }: Props): react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare function ZigzagLine({ heading, upper, lower, }: Props): react_jsx_runtime.JSX.Element;
|
|
10
10
|
declare function getItemOffset(level: number): number;
|
|
11
11
|
interface ZigzagPath {
|
|
12
12
|
path: string;
|
|
@@ -4,22 +4,34 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
|
4
4
|
function getLineOffset(level) {
|
|
5
5
|
return level >= 3 ? 10 : 0;
|
|
6
6
|
}
|
|
7
|
-
function ZigzagLine({
|
|
7
|
+
function ZigzagLine({
|
|
8
|
+
heading,
|
|
9
|
+
upper = heading.level,
|
|
10
|
+
lower = heading.level
|
|
11
|
+
}) {
|
|
8
12
|
const offset = getLineOffset(heading.level);
|
|
9
13
|
const upperOffset = getLineOffset(upper);
|
|
10
14
|
const lowerOffset = getLineOffset(lower);
|
|
11
15
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
12
|
-
offset !== upperOffset && /* @__PURE__ */ jsx(
|
|
13
|
-
"
|
|
16
|
+
offset !== upperOffset && /* @__PURE__ */ jsx(
|
|
17
|
+
"svg",
|
|
14
18
|
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
viewBox: "0 0 16 16",
|
|
20
|
+
className: "absolute -top-1.5 left-0 size-4",
|
|
21
|
+
"aria-hidden": "true",
|
|
22
|
+
children: /* @__PURE__ */ jsx(
|
|
23
|
+
"line",
|
|
24
|
+
{
|
|
25
|
+
x1: upperOffset,
|
|
26
|
+
y1: "0",
|
|
27
|
+
x2: offset,
|
|
28
|
+
y2: "12",
|
|
29
|
+
className: "stroke-line",
|
|
30
|
+
strokeWidth: "1"
|
|
31
|
+
}
|
|
32
|
+
)
|
|
21
33
|
}
|
|
22
|
-
)
|
|
34
|
+
),
|
|
23
35
|
/* @__PURE__ */ jsx(
|
|
24
36
|
"div",
|
|
25
37
|
{
|
|
@@ -33,25 +45,33 @@ function getItemOffset(level) {
|
|
|
33
45
|
return level >= 3 ? 26 : 14;
|
|
34
46
|
}
|
|
35
47
|
function buildZigzagPath(headings, container) {
|
|
36
|
-
if (container.clientHeight === 0)
|
|
48
|
+
if (container.clientHeight === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
37
51
|
let w = 0;
|
|
38
52
|
let h = 0;
|
|
39
53
|
const d = [];
|
|
40
54
|
for (let i = 0; i < headings.length; i++) {
|
|
41
55
|
const item = headings[i];
|
|
42
|
-
if (!item)
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
if (!item) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const element = container.querySelector(
|
|
60
|
+
`a[href="#${item.id}"]`
|
|
61
|
+
);
|
|
62
|
+
if (!element) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
45
65
|
const styles = getComputedStyle(element);
|
|
46
66
|
const offset = item.level >= 3 ? 10.5 : 0.5;
|
|
47
|
-
const top = element.offsetTop + parseFloat(styles.paddingTop);
|
|
48
|
-
const bottom = element.offsetTop + element.clientHeight - parseFloat(styles.paddingBottom);
|
|
67
|
+
const top = element.offsetTop + Number.parseFloat(styles.paddingTop);
|
|
68
|
+
const bottom = element.offsetTop + element.clientHeight - Number.parseFloat(styles.paddingBottom);
|
|
49
69
|
w = Math.max(offset, w);
|
|
50
70
|
h = Math.max(h, bottom);
|
|
51
71
|
d.push(`${i === 0 ? "M" : "L"}${offset} ${top}`);
|
|
52
72
|
d.push(`L${offset} ${bottom}`);
|
|
53
73
|
}
|
|
54
|
-
return { path: d.join(" "), width: w + 1
|
|
74
|
+
return { height: h, path: d.join(" "), width: w + 1 };
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
export { ZigzagLine, buildZigzagPath, getItemOffset };
|
|
@@ -11,7 +11,7 @@ interface TocProgressProps {
|
|
|
11
11
|
activeClassName?: string;
|
|
12
12
|
lineColor?: string;
|
|
13
13
|
}
|
|
14
|
-
declare function TocProgressBase({ headings, className, activeClassName, lineColor }: TocProgressProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare function TocProgressBase({ headings, className, activeClassName, lineColor, }: TocProgressProps): react_jsx_runtime.JSX.Element;
|
|
15
15
|
declare const TocProgress: react.MemoExoticComponent<typeof TocProgressBase>;
|
|
16
16
|
|
|
17
17
|
export { TocProgress, type TocProgressProps };
|