@publish.os/nextjs 0.0.1-alpha.81 → 0.0.1-alpha.91
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/compiler-assets/nextjs/defaults/app/globals.css +1 -0
- package/compiler-assets/nextjs/defaults/group/index.tsx +50 -0
- package/compiler-assets/nextjs/defaults/group/layout.tsx +8 -8
- package/compiler-assets/nextjs/defaults/group/page.tsx +44 -43
- package/compiler-assets/nextjs/defaults/project/next.config.mjs +33 -13
- package/compiler-assets/nextjs/defaults/project/tsconfig.json.template +10 -3
- package/compiler-assets/nextjs/defaults/root/css/animation.css +131 -0
- package/compiler-assets/nextjs/defaults/root/css/components/code-block.css +18 -0
- package/compiler-assets/nextjs/defaults/root/css/components/dialog.css +4 -1
- package/compiler-assets/nextjs/defaults/root/css/components/menu.css +1 -1
- package/compiler-assets/nextjs/defaults/root/css/components/navigation-menu.css +1 -1
- package/compiler-assets/nextjs/defaults/root/css/components/popover.css +1 -1
- package/compiler-assets/nextjs/defaults/root/css/components/select.css +1 -1
- package/compiler-assets/nextjs/defaults/root/css/components/tooltip.css +1 -1
- package/compiler-assets/nextjs/defaults/root/css/shadow.css +6 -25
- package/compiler-assets/nextjs/defaults/root/css/typography.css +51 -68
- package/compiler-assets/nextjs/defaults/root/globals.css +25 -0
- package/compiler-assets/nextjs/defaults/root/{page.tsx → index.tsx} +6 -2
- package/compiler-assets/nextjs/defaults/root/layout.tsx +7 -1
- package/compiler-assets/nextjs/defaults/root/theme.css +22 -22
- package/compiler-assets/nextjs/shims/document.tsx +38 -0
- package/compiler-assets/nextjs/shims/generated-group-page.tsx +19 -2
- package/compiler-assets/nextjs/shims/generated-leaf-page.tsx +18 -2
- package/compiler-assets/nextjs/shims/global-layout.tsx +19 -85
- package/compiler-assets/nextjs/shims/global-not-found.tsx +69 -0
- package/compiler-assets/nextjs/shims/markdown-route.ts +2 -0
- package/compiler-assets/nextjs/shims/metadata-icons.tsx +39 -0
- package/compiler-assets/nextjs/shims/not-found-content.tsx +53 -0
- package/compiler-assets/nextjs/shims/not-found-navigation.tsx +60 -0
- package/compiler-assets/nextjs/shims/proxy.ts +143 -65
- package/compiler-assets/nextjs/shims/publish-os-theme-provider.tsx +76 -15
- package/compiler-assets/nextjs/shims/root-page.tsx +7 -1
- package/compiler-assets/nextjs/shims/site-fenced-code-block.tsx +30 -0
- package/compiler-assets/nextjs/shims/site-heading-level.tsx +14 -0
- package/compiler-assets/nextjs/shims/site-mdx-components.tsx +112 -0
- package/compiler-assets/nextjs/shims/site-mdx.tsx +17 -0
- package/compiler-assets/nextjs/shims/theme-defaults.css +41 -25
- package/dist/build-operation-5QMLXF7N.js +89 -0
- package/dist/{button-CFdx-ohV.d.ts → button-BdCScEKi.d.ts} +6 -6
- package/dist/capture-local-source-WGGDIUU2.js +258 -0
- package/dist/chunk-22RSSUNV.js +13 -0
- package/dist/chunk-4BC2L2KA.js +620 -0
- package/dist/chunk-5J3YUNRY.js +121 -0
- package/dist/chunk-5KAD7W53.js +248 -0
- package/dist/chunk-6C65KV7O.js +142 -0
- package/dist/chunk-6D2E6UMD.js +695 -0
- package/dist/chunk-7NY22B5U.js +161 -0
- package/dist/chunk-AI2UULNX.js +9 -0
- package/dist/chunk-EFO6AWXN.js +19 -0
- package/dist/chunk-F3AGNDF4.js +2377 -0
- package/dist/chunk-GBPLER5H.js +426 -0
- package/dist/chunk-IL4RJOKI.js +186 -0
- package/dist/chunk-NNBJZPFM.js +193 -0
- package/dist/chunk-ORIUWJBQ.js +58 -0
- package/dist/chunk-OXOFRXEI.js +7129 -0
- package/dist/chunk-UYGCOWRF.js +1709 -0
- package/dist/chunk-WL75GQ5M.js +80 -0
- package/dist/compiler.d.ts +54 -7
- package/dist/compiler.js +121 -13147
- package/dist/components/blocks/agent-actions.d.ts +81 -0
- package/dist/components/blocks/agent-actions.js +594 -0
- package/dist/components/blocks/toc.d.ts +43 -0
- package/dist/components/blocks/toc.js +136 -0
- package/dist/components/ui/button.d.ts +5 -0
- package/dist/components/ui/button.js +94 -0
- package/dist/compose-CVBJRAF6.js +16 -0
- package/dist/config/createNextConfig.js +27 -0
- package/dist/dev-operation-OSHHWRWK.js +1095 -0
- package/dist/framework-selection-ZVO323PK.js +11 -0
- package/dist/ide-support-CU6Z5PVR.js +16 -0
- package/dist/index.d.ts +55 -4
- package/dist/jsx-dev-runtime.d.ts +6 -0
- package/dist/jsx-dev-runtime.js +100 -0
- package/dist/jsx-runtime.d.ts +7 -0
- package/dist/jsx-runtime.js +97 -0
- package/dist/kernel/components/blocks/AgentActions.d.ts +35 -6
- package/dist/kernel/components/blocks/AgentActions.js +401 -150
- package/dist/kernel/components/blocks/agent-actions.d.ts +5 -0
- package/dist/kernel/components/blocks/agent-actions.js +594 -0
- package/dist/kernel/components/blocks/animated-icon-swap.js +1 -1
- package/dist/kernel/components/blocks/color-palette.js +4 -4
- package/dist/kernel/components/blocks/logo-block.js +3 -3
- package/dist/kernel/components/blocks/nav-breadcrumb.d.ts +10 -2
- package/dist/kernel/components/blocks/nav-breadcrumb.js +22 -7
- package/dist/kernel/components/blocks/navbar.d.ts +2 -2
- package/dist/kernel/components/blocks/navbar.js +406 -65
- package/dist/kernel/components/blocks/navigation-progress.js +6 -3
- package/dist/kernel/components/blocks/next-prev.d.ts +1 -1
- package/dist/kernel/components/blocks/next-prev.js +12 -24
- package/dist/kernel/components/blocks/page-list.d.ts +1 -1
- package/dist/kernel/components/blocks/page-list.js +7 -6
- package/dist/kernel/components/blocks/search.d.ts +83 -58
- package/dist/kernel/components/blocks/search.js +554 -428
- package/dist/kernel/components/blocks/sidebar-node.d.ts +2 -2
- package/dist/kernel/components/blocks/sidebar-node.js +12 -10
- package/dist/kernel/components/blocks/sidebar.d.ts +3 -3
- package/dist/kernel/components/blocks/sidebar.js +24 -14
- package/dist/kernel/components/blocks/theme-toggle.d.ts +2 -2
- package/dist/kernel/components/blocks/theme-toggle.js +47 -1
- package/dist/kernel/components/blocks/toc-client.d.ts +40 -0
- package/dist/kernel/components/blocks/toc-client.js +495 -0
- package/dist/kernel/components/blocks/toc.d.ts +19 -1
- package/dist/kernel/components/blocks/toc.js +122 -180
- package/dist/kernel/components/mdx/components/blockquote.js +2 -2
- package/dist/kernel/components/mdx/components/callout.d.ts +5 -7
- package/dist/kernel/components/mdx/components/callout.js +67 -36
- package/dist/kernel/components/mdx/components/code-block.d.ts +5 -2
- package/dist/kernel/components/mdx/components/code-block.js +106 -5
- package/dist/kernel/components/mdx/components/copy-code-button.d.ts +8 -0
- package/dist/kernel/components/mdx/components/copy-code-button.js +61 -0
- package/dist/kernel/components/mdx/components/figure-caption.d.ts +1 -1
- package/dist/kernel/components/mdx/components/figure-caption.js +4 -3
- package/dist/kernel/components/mdx/components/figure.d.ts +6 -2
- package/dist/kernel/components/mdx/components/figure.js +24 -14
- package/dist/kernel/components/mdx/components/footnotes.js +1 -1
- package/dist/kernel/components/mdx/components/heading-copy-link.js +4 -4
- package/dist/kernel/components/mdx/components/heading.js +6 -3
- package/dist/kernel/components/mdx/components/hr.js +2 -2
- package/dist/kernel/components/mdx/components/image-zoom.js +2 -2
- package/dist/kernel/components/mdx/components/image.d.ts +1 -1
- package/dist/kernel/components/mdx/components/image.js +94 -68
- package/dist/kernel/components/mdx/components/inline-code.js +2 -2
- package/dist/kernel/components/mdx/components/kbd.d.ts +2 -2
- package/dist/kernel/components/mdx/components/kbd.js +5 -4
- package/dist/kernel/components/mdx/components/link.d.ts +35 -4
- package/dist/kernel/components/mdx/components/link.js +3 -3
- package/dist/kernel/components/mdx/components/paragraph.js +2 -5
- package/dist/kernel/components/mdx/components/strikethrough.js +1 -1
- package/dist/kernel/components/mdx/components/table.js +2 -2
- package/dist/kernel/components/mdx/components/task-list.js +2 -2
- package/dist/kernel/components/mdx/components/video-player.d.ts +6 -2
- package/dist/kernel/components/mdx/components/video-player.js +8 -4
- package/dist/kernel/components/mdx/components/video.d.ts +5 -3
- package/dist/kernel/components/mdx/components/video.js +8 -6
- package/dist/kernel/components/mdx/error-boundary.js +2 -2
- package/dist/kernel/components/mdx/error-fallback.js +1 -1
- package/dist/kernel/components/mdx/mdx.d.ts +28 -14
- package/dist/kernel/components/mdx/mdx.js +336 -63
- package/dist/kernel/components/mdx/rehype-heading-ids.d.ts +1 -0
- package/dist/kernel/components/mdx/rehype-heading-ids.js +6 -4
- package/dist/kernel/components/next-image.d.ts +12 -0
- package/dist/kernel/components/next-image.js +61 -0
- package/dist/kernel/components/ui/accordion.js +1 -1
- package/dist/kernel/components/ui/breadcrumb-trail.d.ts +6 -23
- package/dist/kernel/components/ui/breadcrumb-trail.js +2 -2
- package/dist/kernel/components/ui/breadcrumb.d.ts +11 -3
- package/dist/kernel/components/ui/breadcrumb.js +10 -8
- package/dist/kernel/components/ui/button-group.js +8 -7
- package/dist/kernel/components/ui/button.d.ts +58 -6
- package/dist/kernel/components/ui/button.js +43 -39
- package/dist/kernel/components/ui/card.d.ts +2 -2
- package/dist/kernel/components/ui/card.js +1 -1
- package/dist/kernel/components/ui/dialog.js +1 -1
- package/dist/kernel/components/ui/drawer.d.ts +3 -1
- package/dist/kernel/components/ui/drawer.js +6 -2
- package/dist/kernel/components/ui/input.d.ts +2 -2
- package/dist/kernel/components/ui/input.js +1 -1
- package/dist/kernel/components/ui/kbd.js +10 -17
- package/dist/kernel/components/ui/link.d.ts +11 -3
- package/dist/kernel/components/ui/link.js +12 -11
- package/dist/kernel/components/ui/menu.js +6 -6
- package/dist/kernel/components/ui/mod-key.d.ts +10 -0
- package/dist/kernel/components/ui/mod-key.js +36 -0
- package/dist/kernel/components/ui/navigation-menu.js +3 -3
- package/dist/kernel/components/ui/popover.js +1 -1
- package/dist/kernel/components/ui/progress.js +2 -2
- package/dist/kernel/components/ui/scroll-area.js +5 -5
- package/dist/kernel/components/ui/select.js +8 -11
- package/dist/kernel/components/ui/separator.js +1 -1
- package/dist/kernel/components/ui/table.js +1 -1
- package/dist/kernel/components/ui/tabs.js +1 -1
- package/dist/kernel/components/ui/tag.js +1 -1
- package/dist/kernel/components/ui/text.d.ts +2 -2
- package/dist/kernel/components/ui/text.js +1 -1
- package/dist/kernel/components/ui/toast.js +1 -1
- package/dist/kernel/components/ui/tooltip.js +1 -1
- package/dist/kernel/defaults.registry.d.ts +11 -24
- package/dist/kernel/defaults.registry.js +11 -26
- package/dist/kernel/routes/agent/markdown.d.ts +3 -1
- package/dist/kernel/routes/agent/markdown.js +219 -48
- package/dist/kernel/routes/layouts/group.d.ts +1 -1
- package/dist/kernel/routes/layouts/group.js +5 -7
- package/dist/kernel/routes/metadata/feed.d.ts +1 -1
- package/dist/kernel/routes/metadata/feed.js +111 -81
- package/dist/kernel/routes/metadata/llms.d.ts +12 -3
- package/dist/kernel/routes/metadata/llms.js +156 -59
- package/dist/kernel/routes/metadata/og-image.js +1 -1
- package/dist/kernel/routes/metadata/robots.d.ts +1 -1
- package/dist/kernel/routes/metadata/robots.js +2 -2
- package/dist/kernel/routes/metadata/sitemap.d.ts +26 -4
- package/dist/kernel/routes/metadata/sitemap.js +206 -38
- package/dist/kernel/routes/not-found.d.ts +34 -0
- package/dist/kernel/routes/not-found.js +213 -0
- package/dist/kernel/routes/pages/group.d.ts +2 -2
- package/dist/kernel/routes/pages/group.js +21 -13
- package/dist/kernel/routes/pages/leaf.d.ts +28 -1
- package/dist/kernel/routes/pages/leaf.js +25 -16
- package/dist/kernel/routes/pages/root.js +19 -13
- package/dist/keyboard-shortcuts.js +1 -1
- package/dist/resolvers/manifest-resolver.js +29 -6
- package/dist/search.d.ts +6 -7
- package/dist/search.js +52 -29
- package/dist/{sidebar-types-Bgchdfd6.d.ts → sidebar-types-DKpR27II.d.ts} +1 -1
- package/dist/theme-scope.js +1 -1
- package/dist/{types-DHBm7-j6.d.ts → types-CJWRG05y.d.ts} +20 -1
- package/dist/{types-B_b3C0U6.d.ts → types-CUtrppxt.d.ts} +8 -2
- package/dist/{types-CIwwieNw.d.ts → types-J2w_puPF.d.ts} +11 -10
- package/dist/types.d.ts +15 -6
- package/dist/utils/heading-ids.js +30 -11
- package/dist/utils/toc-selection.d.ts +7 -0
- package/dist/utils/toc-selection.js +14 -0
- package/dist/validate-local-source-SV44DBQT.js +16 -0
- package/dist/validate-publish-os-source-NZJF3TB2.js +14 -0
- package/init/seed/minimal/.gitignore +1 -0
- package/init/seed/minimal/publish.os/assets/blog/hello-world.svg +13 -0
- package/init/seed/minimal/publish.os/assets/favicon.dark.svg +13 -0
- package/init/seed/minimal/publish.os/assets/favicon.svg +13 -0
- package/init/seed/minimal/publish.os/blog/content/hello-world.mdx +48 -0
- package/init/seed/minimal/publish.os/blog/content/series-a.mdx +11 -0
- package/init/seed/minimal/publish.os/blog/index.tsx +82 -0
- package/init/seed/minimal/publish.os/blog/layout.tsx +13 -0
- package/init/seed/minimal/publish.os/blog/page.tsx +76 -0
- package/init/seed/minimal/publish.os/components/blog/copy-link.tsx +64 -0
- package/init/seed/minimal/publish.os/docs/content/get-started.mdx +6 -11
- package/init/seed/minimal/publish.os/docs/content/groups.mdx +6 -7
- package/init/seed/minimal/publish.os/docs/content/{theme.mdx → themes.mdx} +14 -12
- package/init/seed/minimal/publish.os/publish.os.config.json +7 -7
- package/init/seed/minimal/publish.os/theme.css +52 -24
- package/init/seed/minimal/publish.os/tsconfig.json +3 -0
- package/init/seed/minimal/seed.json +12 -2
- package/init/seed/scratch/publish.os/docs/content/get-started.mdx +6 -0
- package/init/seed/scratch/publish.os/publish.os.config.json +4 -0
- package/init/seed/scratch/seed.json +5 -0
- package/package.json +55 -44
- package/release/app/phosphor/package.json +5 -5
- package/release/app/phosphor/pnpm-lock.yaml.template +553 -377
- package/release/app/phosphor/pnpm-workspace.yaml +3 -0
- package/release/compiler/package.json +5 -3
- package/release/compiler/pnpm-lock.yaml.template +500 -303
- package/release/compiler/pnpm-workspace.yaml +3 -0
- package/release/release.json +8 -37
- package/compiler-assets/nextjs/defaults/group/leaf.tsx +0 -48
- package/dist/icons.d.ts +0 -1
- package/dist/icons.js +0 -2
- package/dist/kernel/components/blocks/design-system-preview.d.ts +0 -61
- package/dist/kernel/components/blocks/design-system-preview.js +0 -648
- package/dist/kernel/components/blocks/link-playground.d.ts +0 -5
- package/dist/kernel/components/blocks/link-playground.js +0 -744
- package/dist/kernel/components/blocks/navigation-progress-playground.d.ts +0 -5
- package/dist/kernel/components/blocks/navigation-progress-playground.js +0 -629
- package/dist/kernel/components/mdx/components/pre.d.ts +0 -6
- package/dist/kernel/components/mdx/components/pre.js +0 -18
- package/dist/kernel/components/ui/meta-key.d.ts +0 -17
- package/dist/kernel/components/ui/meta-key.js +0 -9
- package/dist/kernel/components/ui/theme-toggle.d.ts +0 -24
- package/dist/kernel/components/ui/theme-toggle.js +0 -58
- package/dist/kernel/framework-icons.d.ts +0 -1
- package/dist/kernel/framework-icons.js +0 -39
- package/dist/link-CYaCRDb6.d.ts +0 -35
- package/release/app/lucide/package.json +0 -30
- package/release/app/lucide/pnpm-lock.yaml.template +0 -2905
- package/release/app/lucide/pnpm-workspace.yaml +0 -11
- package/release/app/tabler/package.json +0 -30
- package/release/app/tabler/pnpm-lock.yaml.template +0 -2911
- package/release/app/tabler/pnpm-workspace.yaml +0 -11
|
@@ -1,194 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// src/components/block/navigation/toc.tsx
|
|
4
|
-
import { cn } from "@publish.os/nextjs/utils/cn";
|
|
1
|
+
// src/components/block/toc/toc.tsx
|
|
5
2
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
TocClientProvider,
|
|
4
|
+
TocDesktop,
|
|
5
|
+
TocLinksSlot,
|
|
6
|
+
TocMobile,
|
|
7
|
+
TocMobileHeader,
|
|
8
|
+
TocTitle
|
|
9
|
+
} from "@publish.os/nextjs/kernel/components/blocks/toc-client";
|
|
10
|
+
import { cn } from "@publish.os/nextjs/utils/cn";
|
|
11
|
+
|
|
12
|
+
// src/components/block/toc/extract-headings.ts
|
|
13
|
+
import remarkGfm from "remark-gfm";
|
|
14
|
+
import remarkMdx from "remark-mdx";
|
|
15
|
+
import remarkParse from "remark-parse";
|
|
16
|
+
import { unified } from "unified";
|
|
17
|
+
|
|
18
|
+
// src/components/mdx/heading-string.ts
|
|
19
|
+
var SELF_CLOSING_TAG_RE = /<[^>]+\/>/g, PAIRED_TAG_RE = /<\/?\w[^>]*>/g, MDX_BOLD_RE = /\*\*(.*?)\*\*/g, MDX_ITALIC_RE = /\*(.*?)\*/g, MDX_UNDERLINE_BOLD_RE = /__(.*?)__/g, MDX_UNDERLINE_ITALIC_RE = /_(.*?)_/g, MDX_STRIKETHROUGH_RE = /~~(.*?)~~/g, MDX_INLINE_CODE_RE = /`(.*?)`/g, MDX_LINK_RE = /\[(.*?)\]\(.*?\)/g, NON_ALPHANUMERIC_RE = /[^a-z0-9]+/g, LEADING_TRAILING_HYPHEN_RE = /^-+|-+$/g, LEADING_DIGIT_RE = /^(\d)/;
|
|
20
|
+
function cleanHeadingString(input) {
|
|
21
|
+
return input.replace(SELF_CLOSING_TAG_RE, "").replace(PAIRED_TAG_RE, "").replace(MDX_BOLD_RE, "$1").replace(MDX_ITALIC_RE, "$1").replace(MDX_UNDERLINE_BOLD_RE, "$1").replace(MDX_UNDERLINE_ITALIC_RE, "$1").replace(MDX_STRIKETHROUGH_RE, "$1").replace(MDX_INLINE_CODE_RE, "$1").replace(MDX_LINK_RE, "$1").trim();
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (let element of elements)
|
|
27
|
-
if (element.getBoundingClientRect().top <= ACTIVATION_OFFSET)
|
|
28
|
-
nextActiveId = element.id;
|
|
29
|
-
else
|
|
30
|
-
break;
|
|
31
|
-
return nextActiveId;
|
|
23
|
+
function headingStringToHTMLId(input) {
|
|
24
|
+
let text = cleanHeadingString(input);
|
|
25
|
+
return text ? text.toLowerCase().replace(NON_ALPHANUMERIC_RE, "-").replace(LEADING_TRAILING_HYPHEN_RE, "").replace(LEADING_DIGIT_RE, "id-$1") || "heading" : "empty-heading";
|
|
32
26
|
}
|
|
33
|
-
function
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, []), updateActiveHeading = useCallback(() => {
|
|
43
|
-
if (clickedIdRef.current) {
|
|
44
|
-
setActiveId(
|
|
45
|
-
(current) => current === clickedIdRef.current ? current : clickedIdRef.current ?? ""
|
|
46
|
-
);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let elements = headingIds.map((id) => document.getElementById(id)).filter((element) => !!element);
|
|
50
|
-
if (elements.length === 0) return;
|
|
51
|
-
let nextActiveId = resolveActiveHeading(elements);
|
|
52
|
-
setActiveId(
|
|
53
|
-
(current) => current === nextActiveId ? current : nextActiveId
|
|
54
|
-
);
|
|
55
|
-
}, [headingIds]), updateIndicator = useCallback(() => {
|
|
56
|
-
let container = contentRef.current;
|
|
57
|
-
if (!container || !activeId) {
|
|
58
|
-
setIndicatorStyle({ height: 0, transform: 0 });
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
let activeLink = Array.from(
|
|
62
|
-
container.querySelectorAll("[data-toc-link]")
|
|
63
|
-
).find((link) => link.dataset.tocId === activeId);
|
|
64
|
-
if (!activeLink) {
|
|
65
|
-
setIndicatorStyle({ height: 0, transform: 0 });
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
let containerRect = container.getBoundingClientRect(), activeRect = activeLink.getBoundingClientRect(), nextStyle = {
|
|
69
|
-
height: activeRect.height,
|
|
70
|
-
transform: activeRect.top - containerRect.top
|
|
71
|
-
};
|
|
72
|
-
setIndicatorStyle(
|
|
73
|
-
(current) => current.height === nextStyle.height && current.transform === nextStyle.transform ? current : nextStyle
|
|
74
|
-
);
|
|
75
|
-
}, [activeId]), updateViewport = useCallback(() => {
|
|
76
|
-
updateIndicator();
|
|
77
|
-
let viewport = viewportRef.current;
|
|
78
|
-
if (!viewport) return;
|
|
79
|
-
let hasOverflow = viewport.scrollHeight > viewport.clientHeight + 1, nextMask = {
|
|
80
|
-
bottom: hasOverflow && viewport.scrollTop + viewport.clientHeight < viewport.scrollHeight - 1,
|
|
81
|
-
top: hasOverflow && viewport.scrollTop > 0
|
|
82
|
-
};
|
|
83
|
-
setScrollMask(
|
|
84
|
-
(current) => current.top === nextMask.top && current.bottom === nextMask.bottom ? current : nextMask
|
|
85
|
-
);
|
|
86
|
-
}, [updateIndicator]);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
let scheduleUpdate = () => {
|
|
89
|
-
frameRef.current === null && (frameRef.current = window.requestAnimationFrame(() => {
|
|
90
|
-
frameRef.current = null, updateActiveHeading(), updateViewport();
|
|
91
|
-
}));
|
|
92
|
-
}, handleKeyDown = (event) => {
|
|
93
|
-
SCROLL_KEYS.has(event.key) && clearClickedId();
|
|
94
|
-
};
|
|
95
|
-
return scheduleUpdate(), window.addEventListener("scroll", scheduleUpdate, { passive: !0 }), window.addEventListener("resize", scheduleUpdate), window.addEventListener("hashchange", scheduleUpdate), window.addEventListener("wheel", clearClickedId, { passive: !0 }), window.addEventListener("touchstart", clearClickedId, { passive: !0 }), window.addEventListener("keydown", handleKeyDown), () => {
|
|
96
|
-
window.removeEventListener("scroll", scheduleUpdate), window.removeEventListener("resize", scheduleUpdate), window.removeEventListener("hashchange", scheduleUpdate), window.removeEventListener("wheel", clearClickedId), window.removeEventListener("touchstart", clearClickedId), window.removeEventListener("keydown", handleKeyDown), frameRef.current !== null && (window.cancelAnimationFrame(frameRef.current), frameRef.current = null);
|
|
97
|
-
};
|
|
98
|
-
}, [clearClickedId, updateActiveHeading, updateViewport]), useEffect(() => {
|
|
99
|
-
updateViewport();
|
|
100
|
-
}, [updateViewport]);
|
|
101
|
-
let handleTocClick = useCallback((id) => {
|
|
102
|
-
clickedIdRef.current = id, setActiveId(id);
|
|
103
|
-
}, []);
|
|
104
|
-
return {
|
|
105
|
-
activeId,
|
|
106
|
-
contentRef,
|
|
107
|
-
handleTocClick,
|
|
108
|
-
indicatorStyle,
|
|
109
|
-
scrollMask,
|
|
110
|
-
updateViewport,
|
|
111
|
-
viewportRef
|
|
27
|
+
function createHeadingStringIdGenerator() {
|
|
28
|
+
let nextSuffix = /* @__PURE__ */ new Map(), usedIds = /* @__PURE__ */ new Set();
|
|
29
|
+
return (input) => {
|
|
30
|
+
let baseId = headingStringToHTMLId(input);
|
|
31
|
+
if (baseId === "empty-heading") return baseId;
|
|
32
|
+
let suffix = nextSuffix.get(baseId) ?? 0, id = suffix === 0 ? baseId : `${baseId}-${suffix}`;
|
|
33
|
+
for (; usedIds.has(id); )
|
|
34
|
+
suffix += 1, id = `${baseId}-${suffix}`;
|
|
35
|
+
return nextSuffix.set(baseId, suffix + 1), usedIds.add(id), id;
|
|
112
36
|
};
|
|
113
37
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
|
|
38
|
+
|
|
39
|
+
// src/components/block/toc/extract-headings.ts
|
|
40
|
+
var parser = unified().use(remarkParse).use(remarkMdx).use(remarkGfm);
|
|
41
|
+
function nodeText(node) {
|
|
42
|
+
return node.type === "text" || node.type === "inlineCode" ? typeof node.value == "string" ? node.value : "" : node.type === "image" || node.type === "imageReference" ? node.alt ?? "" : node.type === "break" || node.name === "br" ? " " : node.type === "mdxTextExpression" || node.type === "mdxFlowExpression" ? "" : (node.children ?? []).map(nodeText).join("");
|
|
43
|
+
}
|
|
44
|
+
function extractTocHeadings(content, levels) {
|
|
45
|
+
let [minDepth, maxDepth] = levels, headingId = createHeadingStringIdGenerator(), headings = [], tree = parser.parse(content);
|
|
46
|
+
function visit(node) {
|
|
47
|
+
if (node.type === "heading" && node.depth) {
|
|
48
|
+
let text = nodeText(node).trim();
|
|
49
|
+
if (text) {
|
|
50
|
+
let id = headingId(text);
|
|
51
|
+
node.depth >= minDepth && node.depth <= maxDepth && headings.push({ id, level: node.depth, text });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (let child of node.children ?? []) visit(child);
|
|
55
|
+
}
|
|
56
|
+
return visit(tree), headings;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/components/block/toc/toc.tsx
|
|
60
|
+
import { Fragment, jsx, jsxs } from "@publish.os/nextjs/jsx-runtime";
|
|
61
|
+
var DEFAULT_LEVELS = [2, 3];
|
|
62
|
+
function TocRoot({
|
|
63
|
+
className,
|
|
64
|
+
content = "",
|
|
65
|
+
desktopClassName,
|
|
66
|
+
desktopListClassName,
|
|
67
|
+
levels = DEFAULT_LEVELS,
|
|
68
|
+
listClassName,
|
|
69
|
+
mobileClassName,
|
|
70
|
+
mobileQuery = "(max-width: 1279px)",
|
|
71
|
+
readingOffset,
|
|
72
|
+
title = "On this page",
|
|
73
|
+
children
|
|
74
|
+
}) {
|
|
75
|
+
let headings = extractTocHeadings(content, levels);
|
|
76
|
+
return headings.length <= 1 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
134
77
|
/* @__PURE__ */ jsx(
|
|
135
|
-
|
|
78
|
+
TocClientProvider,
|
|
136
79
|
{
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
className: "absolute left-0 w-px rounded-full bg-accent-1 transition-all duration-300 ease-out will-change-transform",
|
|
151
|
-
style: {
|
|
152
|
-
height: indicatorStyle.height,
|
|
153
|
-
transform: `translateY(${indicatorStyle.transform}px) scaleY(${activeId ? 1 : 0.5})`,
|
|
154
|
-
transformOrigin: "top"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
),
|
|
158
|
-
/* @__PURE__ */ jsx("ol", { className: "flex min-w-0 flex-col gap-0.5 pl-3", children: headings.map((heading, index) => {
|
|
159
|
-
let active = activeId === heading.id;
|
|
160
|
-
return /* @__PURE__ */ jsx(
|
|
161
|
-
"li",
|
|
162
|
-
{
|
|
163
|
-
style: {
|
|
164
|
-
marginLeft: Math.max(heading.level - levels[0], 0) * 12,
|
|
165
|
-
marginTop: heading.level === levels[0] && index > 0 ? 4 : 0
|
|
166
|
-
},
|
|
167
|
-
children: /* @__PURE__ */ jsx(
|
|
168
|
-
"a",
|
|
169
|
-
{
|
|
170
|
-
"aria-current": active ? "location" : void 0,
|
|
171
|
-
className: cn(
|
|
172
|
-
"block rounded-button px-2 py-1 text-[13px] leading-snug text-foreground-3 no-underline transition-[background-color,color,font-weight] duration-200 hover:bg-surface-hover hover:text-foreground-1 hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-stroke",
|
|
173
|
-
active && "bg-surface-active font-medium text-accent-1 shadow-xs"
|
|
174
|
-
),
|
|
175
|
-
"data-state": active ? "heading-active" : void 0,
|
|
176
|
-
"data-toc-id": heading.id,
|
|
177
|
-
"data-toc-link": "",
|
|
178
|
-
href: `#${heading.id}`,
|
|
179
|
-
onClick: () => handleTocClick(heading.id),
|
|
180
|
-
children: /* @__PURE__ */ jsx("span", { className: "block min-w-0 text-wrap break-words", children: heading.text })
|
|
181
|
-
}
|
|
182
|
-
)
|
|
183
|
-
},
|
|
184
|
-
heading.id
|
|
185
|
-
);
|
|
186
|
-
}) })
|
|
80
|
+
className: cn("text-xs leading-5", className),
|
|
81
|
+
desktopClassName: cn("hidden xl:block", desktopClassName),
|
|
82
|
+
desktopListClassName,
|
|
83
|
+
headings,
|
|
84
|
+
levels,
|
|
85
|
+
listClassName,
|
|
86
|
+
mobileClassName: cn("xl:hidden", mobileClassName),
|
|
87
|
+
mobileQuery,
|
|
88
|
+
readingOffset,
|
|
89
|
+
title,
|
|
90
|
+
children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ jsx(TocDesktop, {}),
|
|
92
|
+
/* @__PURE__ */ jsx(TocMobile, {})
|
|
187
93
|
] })
|
|
188
94
|
}
|
|
189
|
-
)
|
|
95
|
+
),
|
|
96
|
+
/* @__PURE__ */ jsxs("noscript", { children: [
|
|
97
|
+
/* @__PURE__ */ jsx("style", { children: "[data-toc-mobile-trigger]{display:none}" }),
|
|
98
|
+
/* @__PURE__ */ jsx(
|
|
99
|
+
"nav",
|
|
100
|
+
{
|
|
101
|
+
"aria-label": title,
|
|
102
|
+
className: cn(
|
|
103
|
+
"xl:hidden max-h-[calc(100dvh-2rem)] overflow-y-auto overscroll-contain border-b border-stroke-3 px-6 py-4 text-xs leading-5",
|
|
104
|
+
mobileClassName
|
|
105
|
+
),
|
|
106
|
+
children: /* @__PURE__ */ jsx("ol", { className: cn("space-y-1", listClassName), children: headings.map((heading) => /* @__PURE__ */ jsx(
|
|
107
|
+
"li",
|
|
108
|
+
{
|
|
109
|
+
className: heading.level === levels[0] + 1 ? "ps-3" : void 0,
|
|
110
|
+
children: /* @__PURE__ */ jsx(
|
|
111
|
+
"a",
|
|
112
|
+
{
|
|
113
|
+
className: "block min-h-6 whitespace-normal break-words text-foreground-3 no-underline hover:text-foreground-1 hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-stroke",
|
|
114
|
+
href: `#${heading.id}`,
|
|
115
|
+
children: heading.text
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
},
|
|
119
|
+
heading.id
|
|
120
|
+
)) })
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
] })
|
|
190
124
|
] });
|
|
191
125
|
}
|
|
126
|
+
var Toc = Object.assign(TocRoot, {
|
|
127
|
+
Desktop: TocDesktop,
|
|
128
|
+
Links: TocLinksSlot,
|
|
129
|
+
Mobile: TocMobile,
|
|
130
|
+
MobileHeader: TocMobileHeader,
|
|
131
|
+
Root: TocRoot,
|
|
132
|
+
Title: TocTitle
|
|
133
|
+
});
|
|
192
134
|
export {
|
|
193
135
|
Toc
|
|
194
136
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/components/mdx/blockquote.tsx
|
|
2
2
|
import { cn } from "@publish.os/nextjs/utils/cn";
|
|
3
|
-
import { jsx } from "
|
|
3
|
+
import { jsx } from "@publish.os/nextjs/jsx-runtime";
|
|
4
4
|
function Blockquote({ className, ...props }) {
|
|
5
5
|
return /* @__PURE__ */ jsx(
|
|
6
6
|
"blockquote",
|
|
7
7
|
{
|
|
8
8
|
className: cn(
|
|
9
|
-
"my-6 border-l-2 border-typography-quote-stroke pl-4 text-
|
|
9
|
+
"my-6 border-l-2 border-typography-quote-stroke pl-4 text-typography-quote-foreground",
|
|
10
10
|
className
|
|
11
11
|
),
|
|
12
12
|
...props
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
3
|
import { VariantProps } from 'class-variance-authority';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
4
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
declare const calloutVariants: (props?: ({
|
|
7
|
-
color?: "
|
|
8
|
-
variant?: "
|
|
7
|
+
color?: "neutral" | "info" | "warning" | "danger" | "success" | null | undefined;
|
|
8
|
+
variant?: "solid" | "soft" | "outline" | null | undefined;
|
|
9
9
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
10
|
-
type CalloutProps = VariantProps<typeof calloutVariants> & {
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
className?: string;
|
|
10
|
+
type CalloutProps = Omit<ComponentPropsWithoutRef<"aside">, "color" | "title" | "role" | "style"> & VariantProps<typeof calloutVariants> & {
|
|
13
11
|
icon?: ReactNode;
|
|
14
12
|
title?: ReactNode;
|
|
15
13
|
};
|
|
16
|
-
declare function Callout({ children, className, color, icon, title, variant, }: CalloutProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare function Callout({ children, className, color, icon, title, variant, ...props }: CalloutProps): react_jsx_runtime.JSX.Element;
|
|
17
15
|
|
|
18
16
|
export { Callout, type CalloutProps, calloutVariants };
|
|
@@ -1,29 +1,55 @@
|
|
|
1
1
|
// src/components/mdx/callout.tsx
|
|
2
2
|
import { cn } from "@publish.os/nextjs/utils/cn";
|
|
3
3
|
import { cva } from "class-variance-authority";
|
|
4
|
-
import {
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { jsx, jsxs } from "@publish.os/nextjs/jsx-runtime";
|
|
5
6
|
var calloutVariants = cva(
|
|
6
|
-
"my-6
|
|
7
|
+
"not-markdown-prose my-6 grid min-w-0 items-start gap-2.5 rounded-callout p-3 [&_[data-slot=callout-icon]_svg]:size-[1.125em]",
|
|
7
8
|
{
|
|
8
9
|
variants: {
|
|
9
10
|
color: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
success: "
|
|
15
|
-
warning: "[--callout-emphasis-foreground:var(--warning-1100)] [--callout-foreground:var(--warning-1100)] [--callout-solid-foreground:var(--warning-100)] [--callout-solid-surface:var(--warning-900)] [--callout-stroke:var(--warning-600)] [--callout-surface:var(--warning-200)]"
|
|
11
|
+
neutral: "text-foreground-2 selection:bg-surface-4 selection:text-foreground-1",
|
|
12
|
+
info: "text-info-1200 selection:bg-info-400 selection:text-info-1200",
|
|
13
|
+
warning: "text-warning-1200 selection:bg-warning-400 selection:text-warning-1200",
|
|
14
|
+
danger: "text-danger-1200 selection:bg-danger-400 selection:text-danger-1200",
|
|
15
|
+
success: "text-success-1200 selection:bg-success-400 selection:text-success-1200"
|
|
16
16
|
},
|
|
17
17
|
variant: {
|
|
18
|
-
|
|
19
|
-
soft: "border-
|
|
20
|
-
|
|
18
|
+
solid: "border-0 border-shadow-3",
|
|
19
|
+
soft: "border-0 shadow-none",
|
|
20
|
+
outline: "border bg-transparent shadow-none"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
|
|
24
|
-
color: "
|
|
25
|
-
variant: "
|
|
26
|
-
|
|
23
|
+
compoundVariants: [
|
|
24
|
+
{ color: "neutral", variant: "solid", className: "bg-surface-3" },
|
|
25
|
+
{ color: "info", variant: "solid", className: "bg-info-300" },
|
|
26
|
+
{ color: "warning", variant: "solid", className: "bg-warning-300" },
|
|
27
|
+
{ color: "danger", variant: "solid", className: "bg-danger-300" },
|
|
28
|
+
{ color: "success", variant: "solid", className: "bg-success-300" },
|
|
29
|
+
{ color: "neutral", variant: "soft", className: "bg-surface-3/50" },
|
|
30
|
+
{ color: "info", variant: "soft", className: "bg-info-300/50" },
|
|
31
|
+
{ color: "warning", variant: "soft", className: "bg-warning-300/50" },
|
|
32
|
+
{ color: "danger", variant: "soft", className: "bg-danger-300/50" },
|
|
33
|
+
{ color: "success", variant: "soft", className: "bg-success-300/50" },
|
|
34
|
+
{ color: "neutral", variant: "outline", className: "border-stroke-3" },
|
|
35
|
+
{ color: "info", variant: "outline", className: "border-info-1100/25" },
|
|
36
|
+
{
|
|
37
|
+
color: "warning",
|
|
38
|
+
variant: "outline",
|
|
39
|
+
className: "border-warning-1100/25"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
color: "danger",
|
|
43
|
+
variant: "outline",
|
|
44
|
+
className: "border-danger-1100/25"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
color: "success",
|
|
48
|
+
variant: "outline",
|
|
49
|
+
className: "border-success-1100/25"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
defaultVariants: { color: "neutral", variant: "solid" }
|
|
27
53
|
}
|
|
28
54
|
);
|
|
29
55
|
function Callout({
|
|
@@ -32,42 +58,47 @@ function Callout({
|
|
|
32
58
|
color,
|
|
33
59
|
icon,
|
|
34
60
|
title,
|
|
35
|
-
variant
|
|
61
|
+
variant,
|
|
62
|
+
...props
|
|
36
63
|
}) {
|
|
37
|
-
let
|
|
38
|
-
return /* @__PURE__ */
|
|
64
|
+
let titleId = useId(), hasTitle = title != null && title !== !1;
|
|
65
|
+
return /* @__PURE__ */ jsxs(
|
|
39
66
|
"aside",
|
|
40
67
|
{
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
className: cn(
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
...props,
|
|
69
|
+
"aria-labelledby": hasTitle ? titleId : props["aria-labelledby"],
|
|
70
|
+
className: cn(
|
|
71
|
+
calloutVariants({ color, variant }),
|
|
72
|
+
icon ? "grid-cols-[auto_minmax(0,1fr)]" : "grid-cols-1",
|
|
73
|
+
className
|
|
74
|
+
),
|
|
75
|
+
"data-color": color ?? "neutral",
|
|
76
|
+
"data-slot": "callout",
|
|
77
|
+
"data-variant": variant ?? "solid",
|
|
78
|
+
role: "note",
|
|
79
|
+
children: [
|
|
80
|
+
icon ? /* @__PURE__ */ jsx(
|
|
46
81
|
"span",
|
|
47
82
|
{
|
|
48
83
|
"aria-hidden": "true",
|
|
49
|
-
className:
|
|
50
|
-
|
|
51
|
-
resolvedVariant === "solid" ? "text-inherit" : "text-[var(--callout-emphasis-foreground)]",
|
|
52
|
-
"[&_svg]:size-4 [&_svg]:shrink-0"
|
|
53
|
-
),
|
|
84
|
+
className: "flex h-lh shrink-0 items-center justify-center [&_svg]:shrink-0",
|
|
85
|
+
"data-slot": "callout-icon",
|
|
54
86
|
children: icon
|
|
55
87
|
}
|
|
56
88
|
) : null,
|
|
57
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
89
|
+
/* @__PURE__ */ jsxs("div", { className: "grid min-w-0 gap-1", "data-slot": "callout-body", children: [
|
|
58
90
|
hasTitle ? /* @__PURE__ */ jsx(
|
|
59
|
-
"
|
|
91
|
+
"div",
|
|
60
92
|
{
|
|
61
|
-
className:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
),
|
|
93
|
+
className: "min-w-0 wrap-break-word font-semibold text-pretty",
|
|
94
|
+
"data-slot": "callout-title",
|
|
95
|
+
id: titleId,
|
|
65
96
|
children: title
|
|
66
97
|
}
|
|
67
98
|
) : null,
|
|
68
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
99
|
+
children != null ? /* @__PURE__ */ jsx("div", { className: "min-w-0 wrap-break-word", "data-slot": "callout-content", children }) : null
|
|
69
100
|
] })
|
|
70
|
-
]
|
|
101
|
+
]
|
|
71
102
|
}
|
|
72
103
|
);
|
|
73
104
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { BundledTheme } from 'shiki';
|
|
2
3
|
|
|
3
|
-
type CodeBlockProps = React.ComponentPropsWithoutRef<"
|
|
4
|
+
type CodeBlockProps = Omit<React.ComponentPropsWithoutRef<"div">, "style"> & {
|
|
4
5
|
code?: string;
|
|
5
6
|
language?: string;
|
|
7
|
+
lightTheme?: BundledTheme;
|
|
8
|
+
darkTheme?: BundledTheme;
|
|
6
9
|
};
|
|
7
|
-
declare function CodeBlock({ children, code, language, ...props }: CodeBlockProps): react_jsx_runtime.JSX.Element
|
|
10
|
+
declare function CodeBlock({ children, className, code, language, lightTheme, darkTheme, title, ...props }: CodeBlockProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
8
11
|
|
|
9
12
|
export { CodeBlock, type CodeBlockProps };
|
|
@@ -1,13 +1,114 @@
|
|
|
1
|
-
// src/components/mdx/code-block.tsx
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
// src/components/mdx/code-block/code-block.tsx
|
|
2
|
+
import { CopyCodeButton } from "@components/mdx/components/copy-code-button";
|
|
3
|
+
import { cn } from "@publish.os/nextjs/utils/cn";
|
|
4
|
+
import { isValidElement } from "react";
|
|
5
|
+
import {
|
|
6
|
+
bundledLanguages,
|
|
7
|
+
codeToHtml
|
|
8
|
+
} from "shiki";
|
|
9
|
+
import { jsx, jsxs } from "@publish.os/nextjs/jsx-runtime";
|
|
10
|
+
var copyButtonRadius = "rounded-[max(calc(var(--radius-codeblock)-0.5rem),0px)]";
|
|
11
|
+
function codeChild(children) {
|
|
12
|
+
if (!isValidElement(children))
|
|
13
|
+
return { code: typeof children == "string" ? children : "" };
|
|
14
|
+
let { className, title } = children.props, language = /(?:^|\s)language-([^\s]+)/.exec(className ?? "")?.[1], value = children.props.children;
|
|
15
|
+
return { code: typeof value == "string" ? value : "", language, title };
|
|
16
|
+
}
|
|
17
|
+
function breakableTitle(title) {
|
|
18
|
+
let parts = [], start = 0;
|
|
19
|
+
for (let separator of title.matchAll(/[/\\]/g)) {
|
|
20
|
+
let end = separator.index + 1;
|
|
21
|
+
parts.push(title.slice(start, end), /* @__PURE__ */ jsx("wbr", {}, end)), start = end;
|
|
22
|
+
}
|
|
23
|
+
return parts.push(title.slice(start)), parts;
|
|
24
|
+
}
|
|
25
|
+
function isCssDeclarationFragment(code) {
|
|
26
|
+
let source = code.replace(/^(?:\s|\/\*[\s\S]*?\*\/)*\s*/, "");
|
|
27
|
+
if (!/^(?:--[\w-]+|[a-zA-Z-]+)\s*:/.test(source)) return !1;
|
|
28
|
+
let firstBlock = source.indexOf("{"), firstDeclarationEnd = source.indexOf(";");
|
|
29
|
+
return firstBlock === -1 || firstDeclarationEnd !== -1 && firstDeclarationEnd < firstBlock;
|
|
30
|
+
}
|
|
31
|
+
async function CodeBlock({
|
|
5
32
|
children,
|
|
33
|
+
className,
|
|
6
34
|
code,
|
|
7
35
|
language,
|
|
36
|
+
lightTheme = "github-light",
|
|
37
|
+
darkTheme = "github-dark",
|
|
38
|
+
title,
|
|
8
39
|
...props
|
|
9
40
|
}) {
|
|
10
|
-
|
|
41
|
+
let child = codeChild(children), displayedCode = code ?? child.code, displayLanguage = language ?? child.language, displayTitle = title ?? child.title, token = displayLanguage?.toLowerCase() ?? "txt", highlightedLanguage = Object.hasOwn(bundledLanguages, token) ? token : "txt", html = await codeToHtml(displayedCode.replace(/\r?\n$/, ""), {
|
|
42
|
+
lang: highlightedLanguage,
|
|
43
|
+
themes: { light: lightTheme, dark: darkTheme },
|
|
44
|
+
defaultColor: !1,
|
|
45
|
+
transformers: highlightedLanguage === "css" && isCssDeclarationFragment(displayedCode) ? [
|
|
46
|
+
{
|
|
47
|
+
preprocess(source) {
|
|
48
|
+
return `:root {
|
|
49
|
+
${source}
|
|
50
|
+
}`;
|
|
51
|
+
},
|
|
52
|
+
tokens(lines) {
|
|
53
|
+
return lines.slice(1, -1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
] : []
|
|
57
|
+
});
|
|
58
|
+
return /* @__PURE__ */ jsxs(
|
|
59
|
+
"div",
|
|
60
|
+
{
|
|
61
|
+
className: cn(
|
|
62
|
+
"not-markdown-prose relative my-6 min-w-0 overflow-hidden rounded-codeblock border border-typography-pre-stroke bg-typography-pre-surface text-typography-pre-foreground",
|
|
63
|
+
className
|
|
64
|
+
),
|
|
65
|
+
"data-slot": "code-block",
|
|
66
|
+
...props,
|
|
67
|
+
children: [
|
|
68
|
+
displayTitle ? /* @__PURE__ */ jsxs(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
className: "flex min-h-11 min-w-0 items-center gap-3 border-b border-typography-pre-stroke bg-surface-2 py-2 ps-4 pe-2",
|
|
72
|
+
"data-slot": "code-block-header",
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
"span",
|
|
76
|
+
{
|
|
77
|
+
className: "min-w-0 flex-1 [overflow-wrap:anywhere] text-sm font-medium leading-5 text-foreground-2",
|
|
78
|
+
dir: "auto",
|
|
79
|
+
children: breakableTitle(displayTitle)
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx(CopyCodeButton, { className: copyButtonRadius, code: displayedCode })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
) : null,
|
|
86
|
+
/* @__PURE__ */ jsxs(
|
|
87
|
+
"div",
|
|
88
|
+
{
|
|
89
|
+
className: cn(
|
|
90
|
+
"flex min-w-0 items-start gap-2 py-2 ps-4 pe-2",
|
|
91
|
+
displayTitle && "py-3 pe-4"
|
|
92
|
+
),
|
|
93
|
+
"data-slot": "code-block-content",
|
|
94
|
+
children: [
|
|
95
|
+
/* @__PURE__ */ jsx(
|
|
96
|
+
"div",
|
|
97
|
+
{
|
|
98
|
+
className: cn(
|
|
99
|
+
"code-block-highlight min-w-0 flex-1 overflow-x-auto overscroll-x-contain font-mono text-sm leading-6 [&_pre]:m-0 [&_pre]:min-w-max [&_pre]:overflow-visible [&_pre]:bg-transparent! [&_pre]:p-0 [&_pre]:text-inherit [&_pre]:font-inherit [&_pre]:outline-none [&_code]:block [&_code]:font-inherit",
|
|
100
|
+
!displayTitle && "[&_pre]:py-1"
|
|
101
|
+
),
|
|
102
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
displayTitle ? null : /* @__PURE__ */ jsx(CopyCodeButton, { className: copyButtonRadius, code: displayedCode })
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
);
|
|
11
112
|
}
|
|
12
113
|
export {
|
|
13
114
|
CodeBlock
|