@barodoc/theme-docs 7.0.0 → 7.1.1

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/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@barodoc/theme-docs",
3
- "version": "7.0.0",
3
+ "version": "7.1.1",
4
4
  "description": "Documentation theme for Barodoc",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "exports": {
7
8
  ".": "./src/index.ts",
9
+ "./theme": "./src/theme.ts",
8
10
  "./components": "./src/components/index.ts",
9
11
  "./components/*": "./src/components/*",
10
12
  "./layouts/*": "./src/layouts/*",
@@ -12,6 +12,7 @@ export { DocTabs } from "./mdx/DocTabs.tsx";
12
12
  export { DocAccordion, SimpleAccordion } from "./mdx/DocAccordion.tsx";
13
13
 
14
14
  // New MDX Components (Mintlify-style)
15
+ export { Callout } from "./mdx/Callout.tsx";
15
16
  export { CodeGroup } from "./mdx/CodeGroup.tsx";
16
17
  export { Badge } from "./mdx/Badge.tsx";
17
18
  export { Frame } from "./mdx/Frame.tsx";
@@ -28,6 +29,11 @@ export { ImageZoom } from "./mdx/ImageZoom.tsx";
28
29
  export { Video } from "./mdx/Video.tsx";
29
30
  export { ApiPlayground } from "./mdx/ApiPlayground.tsx";
30
31
  export { ApiEndpoint } from "./mdx/ApiEndpoint.tsx";
32
+ export { Card, CardGroup } from "./mdx/Card.tsx";
33
+ export { CodeItem } from "./mdx/CodeItem.tsx";
34
+ export { ApiParams } from "./mdx/ApiParams.tsx";
35
+ export { ApiParam } from "./mdx/ApiParam.tsx";
36
+ export { ApiResponse } from "./mdx/ApiResponse.tsx";
31
37
 
32
38
  export { VersionSwitcher } from "./VersionSwitcher.tsx";
33
39
 
@@ -0,0 +1,27 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiParamProps {
4
+ name: string;
5
+ type: string;
6
+ required?: boolean;
7
+ description?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ export function ApiParam({ name, type, required = false, description, children }: ApiParamProps) {
12
+ return (
13
+ <div className="flex flex-col gap-1 py-3 border-b border-[var(--bd-border)] last:border-b-0">
14
+ <div className="flex items-center gap-2">
15
+ <code className="text-sm font-semibold text-[var(--bd-text)]">{name}</code>
16
+ <span className="text-xs text-[var(--bd-text-secondary)]">{type}</span>
17
+ {required && (
18
+ <span className="px-1.5 py-0.5 text-xs font-medium text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 rounded">
19
+ required
20
+ </span>
21
+ )}
22
+ </div>
23
+ {description && <p className="text-sm text-[var(--bd-text-secondary)]">{description}</p>}
24
+ {children}
25
+ </div>
26
+ );
27
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiParamsProps {
4
+ title?: string;
5
+ children?: ReactNode;
6
+ }
7
+
8
+ export function ApiParams({ title = "Parameters", children }: ApiParamsProps) {
9
+ return (
10
+ <div className="my-4 px-2">
11
+ <h4 className="text-sm font-semibold text-[var(--bd-text)] mb-2">{title}</h4>
12
+ <div className="border border-[var(--bd-border)] rounded-lg overflow-hidden">
13
+ <div className="divide-y divide-[var(--bd-border)] px-4">{children}</div>
14
+ </div>
15
+ </div>
16
+ );
17
+ }
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiResponseProps {
4
+ status: number;
5
+ description?: string;
6
+ children?: ReactNode;
7
+ }
8
+
9
+ const statusColors: Record<number, string> = {
10
+ 200: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
11
+ 201: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
12
+ 204: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
13
+ 400: "bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400",
14
+ 401: "bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",
15
+ 403: "bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",
16
+ 404: "bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",
17
+ 500: "bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",
18
+ };
19
+
20
+ export function ApiResponse({ status, description, children }: ApiResponseProps) {
21
+ const statusColor = statusColors[status] || "bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-400";
22
+
23
+ return (
24
+ <div className="my-4 px-2">
25
+ <div className="flex items-center gap-2 mb-2">
26
+ <span className={`px-2 py-0.5 text-xs font-bold rounded ${statusColor}`}>{status}</span>
27
+ {description && <span className="text-sm text-[var(--bd-text-secondary)]">{description}</span>}
28
+ </div>
29
+ <div className="border border-[var(--bd-border)] rounded-lg overflow-hidden px-2">{children}</div>
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,104 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ type CalloutType = "info" | "warning" | "tip" | "danger" | "note";
4
+
5
+ interface CalloutProps {
6
+ type?: CalloutType;
7
+ title?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ const styles: Record<CalloutType, { container: string; iconBg: string; icon: string; title: string }> = {
12
+ info: {
13
+ container: "bg-blue-50/70 dark:bg-blue-500/10 border-l-blue-500",
14
+ iconBg: "bg-blue-100 dark:bg-blue-500/20",
15
+ icon: "text-blue-600 dark:text-blue-400",
16
+ title: "text-blue-900 dark:text-blue-200",
17
+ },
18
+ note: {
19
+ container: "bg-gray-50/70 dark:bg-gray-500/10 border-l-gray-400",
20
+ iconBg: "bg-gray-100 dark:bg-gray-500/20",
21
+ icon: "text-gray-600 dark:text-gray-400",
22
+ title: "text-gray-900 dark:text-gray-200",
23
+ },
24
+ warning: {
25
+ container: "bg-orange-50/70 dark:bg-orange-500/10 border-l-orange-500",
26
+ iconBg: "bg-orange-100 dark:bg-orange-500/20",
27
+ icon: "text-orange-600 dark:text-orange-400",
28
+ title: "text-orange-900 dark:text-orange-200",
29
+ },
30
+ tip: {
31
+ container: "bg-green-50/70 dark:bg-green-500/10 border-l-green-500",
32
+ iconBg: "bg-green-100 dark:bg-green-500/20",
33
+ icon: "text-green-600 dark:text-green-400",
34
+ title: "text-green-900 dark:text-green-200",
35
+ },
36
+ danger: {
37
+ container: "bg-red-50/70 dark:bg-red-500/10 border-l-red-500",
38
+ iconBg: "bg-red-100 dark:bg-red-500/20",
39
+ icon: "text-red-600 dark:text-red-400",
40
+ title: "text-red-900 dark:text-red-200",
41
+ },
42
+ };
43
+
44
+ const icons: Record<CalloutType, ReactNode> = {
45
+ info: (
46
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
47
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
48
+ </svg>
49
+ ),
50
+ note: (
51
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
52
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
53
+ </svg>
54
+ ),
55
+ warning: (
56
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
57
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
58
+ </svg>
59
+ ),
60
+ tip: (
61
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
62
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
63
+ </svg>
64
+ ),
65
+ danger: (
66
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
67
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
68
+ </svg>
69
+ ),
70
+ };
71
+
72
+ const defaultTitles: Record<CalloutType, string> = {
73
+ info: "Info",
74
+ note: "Note",
75
+ warning: "Warning",
76
+ tip: "Tip",
77
+ danger: "Danger",
78
+ };
79
+
80
+ export function Callout({ type = "info", title, children }: CalloutProps) {
81
+ const style = styles[type];
82
+ const icon = icons[type];
83
+ const displayTitle = title || defaultTitles[type];
84
+
85
+ return (
86
+ <div className={`not-prose my-5 rounded-lg border-l-4 overflow-hidden ${style.container}`}>
87
+ <div className="px-4 py-3.5">
88
+ <div className="flex items-start gap-3">
89
+ <div className={`shrink-0 flex items-center justify-center w-6 h-6 rounded-md ${style.iconBg}`}>
90
+ <div className={style.icon}>{icon}</div>
91
+ </div>
92
+ <div className="flex-1 min-w-0">
93
+ {displayTitle && (
94
+ <p className={`font-semibold text-[13px] mb-1 ${style.title}`}>{displayTitle}</p>
95
+ )}
96
+ <div className="text-[13px] text-zinc-700 dark:text-zinc-300 leading-relaxed [&>p]:m-0 [&>p+p]:mt-1.5">
97
+ {children}
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ );
104
+ }
@@ -0,0 +1,66 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface CardProps {
4
+ title: string;
5
+ icon?: string;
6
+ href?: string;
7
+ children?: ReactNode;
8
+ }
9
+
10
+ export function Card({ title, icon, href, children }: CardProps) {
11
+ const Tag = href ? "a" : "div";
12
+ return (
13
+ <Tag
14
+ href={href}
15
+ className={`card-component not-prose group block p-4 rounded-lg border border-[var(--bd-border)] bg-[var(--bd-bg)] no-underline ${
16
+ href
17
+ ? "cursor-pointer hover:border-primary-300 dark:hover:border-primary-600 hover:shadow-md transition-all duration-200"
18
+ : ""
19
+ }`}
20
+ >
21
+ <div className="flex flex-col gap-3">
22
+ {icon && (
23
+ <div className="flex items-center justify-center w-10 h-10 rounded-lg bg-[var(--bd-bg-subtle)] group-hover:bg-primary-50 dark:group-hover:bg-primary-950/50 transition-colors">
24
+ <span className="text-xl">{icon}</span>
25
+ </div>
26
+ )}
27
+ <div className="flex-1 min-w-0">
28
+ <div className="flex items-center gap-2">
29
+ <h3 className="font-semibold text-[var(--bd-text)] group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors">
30
+ {title}
31
+ </h3>
32
+ {href && (
33
+ <svg
34
+ className="w-4 h-4 text-[var(--bd-text-muted)] opacity-0 -translate-x-2 group-hover:opacity-100 group-hover:translate-x-0 transition-all duration-200"
35
+ fill="none"
36
+ stroke="currentColor"
37
+ viewBox="0 0 24 24"
38
+ >
39
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
40
+ </svg>
41
+ )}
42
+ </div>
43
+ <div className="mt-1 text-sm text-[var(--bd-text-secondary)] group-hover:text-[var(--bd-text)] leading-relaxed transition-colors">
44
+ {children}
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </Tag>
49
+ );
50
+ }
51
+
52
+ interface CardGroupProps {
53
+ cols?: 1 | 2 | 3 | 4;
54
+ children?: ReactNode;
55
+ }
56
+
57
+ const gridCols: Record<number, string> = {
58
+ 1: "grid-cols-1",
59
+ 2: "grid-cols-1 sm:grid-cols-2",
60
+ 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
61
+ 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
62
+ };
63
+
64
+ export function CardGroup({ cols = 2, children }: CardGroupProps) {
65
+ return <div className={`not-prose grid gap-5 my-6 ${gridCols[cols]}`}>{children}</div>;
66
+ }
@@ -1,117 +1,18 @@
1
- import * as React from "react";
1
+ import type { ReactNode } from "react";
2
2
 
3
3
  interface CodeGroupProps {
4
- children: React.ReactNode;
4
+ children: ReactNode;
5
5
  titles?: string[];
6
6
  }
7
7
 
8
- function isCodeBlockLike(el: React.ReactElement): boolean {
9
- if (el.type === "pre") return true;
10
- const className =
11
- typeof el.props?.className === "string" ? el.props.className : "";
12
- if (
13
- className.includes("language-") ||
14
- className.includes("astro-code") ||
15
- className.includes("code-block")
16
- )
17
- return true;
18
- return false;
19
- }
20
-
21
- function collectCodeBlocks(node: React.ReactNode): React.ReactElement[] {
22
- const result: React.ReactElement[] = [];
23
- React.Children.forEach(node, (child) => {
24
- if (!React.isValidElement(child)) return;
25
- if (child.type === React.Fragment && child.props?.children != null) {
26
- result.push(...collectCodeBlocks(child.props.children));
27
- return;
28
- }
29
- if (child.type === "pre" || isCodeBlockLike(child)) {
30
- result.push(child);
31
- return;
32
- }
33
- if (child.props?.children != null) {
34
- result.push(...collectCodeBlocks(child.props.children));
35
- }
36
- });
37
- return result;
38
- }
39
-
40
8
  export function CodeGroup({ children, titles = [] }: CodeGroupProps) {
41
- const [activeIndex, setActiveIndex] = React.useState(0);
42
-
43
- const codeBlocks = React.useMemo(() => {
44
- let blocks = collectCodeBlocks(children);
45
- if (blocks.length > 0) return blocks;
46
- const direct = React.Children.toArray(children).filter(
47
- (c): c is React.ReactElement => React.isValidElement(c) && c.type != null
48
- );
49
- if (direct.length > 1) return direct;
50
- if (
51
- direct.length === 1 &&
52
- direct[0].props?.children != null
53
- ) {
54
- const inner = React.Children.toArray(direct[0].props.children).filter(
55
- (c): c is React.ReactElement =>
56
- React.isValidElement(c) && c.type != null
57
- );
58
- if (inner.length > 0) return inner;
59
- }
60
- return direct;
61
- }, [children]);
62
-
63
- const tabTitles =
64
- titles.length >= codeBlocks.length
65
- ? titles.slice(0, codeBlocks.length)
66
- : [
67
- ...titles,
68
- ...codeBlocks
69
- .slice(titles.length)
70
- .map((_, i) => `Tab ${titles.length + i + 1}`),
71
- ];
72
-
73
- if (codeBlocks.length === 0) {
74
- return (
75
- <div className="code-group not-prose my-4 rounded-lg border border-[var(--bd-border)] overflow-hidden p-4 text-[var(--bd-text-muted)] text-sm">
76
- No code blocks found inside CodeGroup.
77
- </div>
78
- );
79
- }
80
-
81
9
  return (
82
- <div className="code-group not-prose my-4 rounded-lg border border-[var(--bd-border)] overflow-hidden">
83
- {/* Tabs */}
84
- <div className="flex flex-wrap gap-0 bg-[var(--bd-bg-muted)] border-b border-[var(--bd-border)]">
85
- {tabTitles.map((title, index) => {
86
- const isActive = activeIndex === index;
87
- return (
88
- <button
89
- key={index}
90
- type="button"
91
- onClick={() => setActiveIndex(index)}
92
- className={`shrink-0 px-4 py-2 text-sm font-medium transition-colors whitespace-nowrap ${
93
- isActive
94
- ? "bg-[var(--bd-bg-subtle)] text-[var(--bd-text)] border-b-2 border-primary-500 -mb-px"
95
- : "text-[var(--bd-text-muted)] hover:text-[var(--bd-text)]"
96
- }`}
97
- >
98
- {title}
99
- </button>
100
- );
101
- })}
102
- </div>
103
-
104
- {/* Content */}
105
- <div className="bg-[var(--bd-bg-subtle)]">
106
- {codeBlocks.map((block, index) => (
107
- <div
108
- key={index}
109
- style={{ display: activeIndex === index ? "block" : "none" }}
110
- >
111
- {block}
112
- </div>
113
- ))}
114
- </div>
10
+ <div
11
+ className="code-group not-prose my-4 rounded-lg border border-[var(--bd-border)] overflow-hidden"
12
+ data-titles={JSON.stringify(titles)}
13
+ >
14
+ <div className="code-group-tabs flex flex-wrap gap-0 border-b border-[var(--bd-border)] bg-[var(--bd-bg-muted)]" />
15
+ <div className="code-group-content bg-[var(--bd-bg-subtle)]">{children}</div>
115
16
  </div>
116
17
  );
117
18
  }
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface CodeItemProps {
4
+ title?: string;
5
+ children?: ReactNode;
6
+ }
7
+
8
+ export function CodeItem({ title = "", children }: CodeItemProps) {
9
+ return (
10
+ <div className="code-item" data-title={title}>
11
+ {children}
12
+ </div>
13
+ );
14
+ }
package/src/index.ts CHANGED
@@ -1,152 +1,2 @@
1
- import type { AstroIntegration } from "astro";
2
- import type { ThemeExport, ResolvedBarodocConfig } from "@barodoc/core";
3
- import mdx from "@astrojs/mdx";
4
- import react from "@astrojs/react";
5
- import tailwindcss from "@tailwindcss/vite";
6
- import remarkMath from "remark-math";
7
- import rehypeKatex from "rehype-katex";
8
-
9
- export interface DocsThemeOptions {
10
- customCss?: string[];
11
- }
12
-
13
- /** HAST node with optional children and properties */
14
- interface HastNode {
15
- type: string;
16
- children?: HastNode[];
17
- properties?: Record<string, unknown>;
18
- tagName?: string;
19
- value?: string;
20
- }
21
-
22
- function getTextContent(node: HastNode): string {
23
- if (node.type === "text") return node.value ?? "";
24
- if (node.children?.length) return node.children.map(getTextContent).join("");
25
- return "";
26
- }
27
-
28
- function isEmptyLine(node: HastNode): boolean {
29
- if (node.type !== "element" || node.tagName !== "span") return false;
30
- const cls = node.properties?.className;
31
- const isLine =
32
- Array.isArray(cls) && cls.some((c) => c === "line" || (typeof c === "string" && c.includes("line")));
33
- if (!isLine) return false;
34
- return /^\s*$/.test(getTextContent(node));
35
- }
36
-
37
- /** Removes leading and trailing empty span.line so only the code area is visible. */
38
- function createTrimEmptyLinesTransformer() {
39
- return {
40
- name: "barodoc-trim-empty-lines",
41
- code(node: HastNode) {
42
- const lines = node.children;
43
- if (!lines?.length) return;
44
- let start = 0;
45
- let end = lines.length;
46
- while (start < end && isEmptyLine(lines[start])) start++;
47
- while (end > start && isEmptyLine(lines[end - 1])) end--;
48
- node.children = lines.slice(start, end);
49
- },
50
- };
51
- }
52
-
53
- function createLineNumbersTransformer() {
54
- return {
55
- name: "barodoc-line-numbers",
56
- pre(node: { properties?: Record<string, unknown> }) {
57
- (this as { addClassToHast: (node: unknown, cls: string) => void }).addClassToHast(node, "line-numbers");
58
- },
59
- };
60
- }
61
-
62
- function createThemeIntegration(
63
- config: ResolvedBarodocConfig,
64
- options?: DocsThemeOptions
65
- ): AstroIntegration {
66
- const lineNumbers = config?.lineNumbers === true;
67
- return {
68
- name: "@barodoc/theme-docs",
69
- hooks: {
70
- "astro:config:setup": async ({ updateConfig, injectRoute, logger }) => {
71
- logger.info("Setting up Barodoc docs theme...");
72
-
73
- // Inject routes
74
- injectRoute({
75
- pattern: "/",
76
- entrypoint: "@barodoc/theme-docs/pages/index.astro",
77
- });
78
-
79
- injectRoute({
80
- pattern: "/docs/[...slug]",
81
- entrypoint: "@barodoc/theme-docs/pages/docs/[...slug].astro",
82
- });
83
-
84
- // Blog routes
85
- if (config?.blog?.enabled !== false) {
86
- injectRoute({
87
- pattern: "/blog",
88
- entrypoint: "@barodoc/theme-docs/pages/blog/index.astro",
89
- });
90
- injectRoute({
91
- pattern: "/blog/[...slug]",
92
- entrypoint: "@barodoc/theme-docs/pages/blog/[...slug].astro",
93
- });
94
- }
95
-
96
- // Changelog route
97
- injectRoute({
98
- pattern: "/changelog",
99
- entrypoint: "@barodoc/theme-docs/pages/changelog/index.astro",
100
- });
101
-
102
- // Update Astro config with integrations and Vite plugins
103
- updateConfig({
104
- integrations: [
105
- mdx({
106
- remarkPlugins: [remarkMath],
107
- rehypePlugins: [rehypeKatex],
108
- }),
109
- react(),
110
- ],
111
- vite: {
112
- plugins: [tailwindcss()],
113
- optimizeDeps: {
114
- include: ["mermaid"],
115
- },
116
- ssr: {
117
- noExternal: [],
118
- },
119
- resolve: {
120
- dedupe: ["react", "react-dom"],
121
- },
122
- },
123
- markdown: {
124
- shikiConfig: {
125
- themes: {
126
- light: "github-light",
127
- dark: "github-dark",
128
- },
129
- transformers: [
130
- createTrimEmptyLinesTransformer(),
131
- ...(lineNumbers ? [createLineNumbersTransformer()] : []),
132
- ],
133
- },
134
- },
135
- });
136
-
137
- logger.info("Docs theme routes injected");
138
- },
139
- },
140
- };
141
- }
142
-
143
- export default function docsTheme(options?: DocsThemeOptions): ThemeExport {
144
- return {
145
- name: "@barodoc/theme-docs",
146
- integration: (config) => createThemeIntegration(config, options),
147
- styles: options?.customCss || [],
148
- };
149
- }
150
-
151
- // Re-export components for easy access
1
+ // Component exports - safe for client-side bundling
152
2
  export * from "./components/index.ts";
package/src/theme.ts ADDED
@@ -0,0 +1,145 @@
1
+ import type { AstroIntegration } from "astro";
2
+ import type { ThemeExport, ResolvedBarodocConfig } from "@barodoc/core";
3
+ import mdx from "@astrojs/mdx";
4
+ import react from "@astrojs/react";
5
+ import tailwindcss from "@tailwindcss/vite";
6
+ import remarkMath from "remark-math";
7
+ import rehypeKatex from "rehype-katex";
8
+
9
+ export interface DocsThemeOptions {
10
+ customCss?: string[];
11
+ }
12
+
13
+ /** HAST node with optional children and properties */
14
+ interface HastNode {
15
+ type: string;
16
+ children?: HastNode[];
17
+ properties?: Record<string, unknown>;
18
+ tagName?: string;
19
+ value?: string;
20
+ }
21
+
22
+ function getTextContent(node: HastNode): string {
23
+ if (node.type === "text") return node.value ?? "";
24
+ if (node.children?.length) return node.children.map(getTextContent).join("");
25
+ return "";
26
+ }
27
+
28
+ function isEmptyLine(node: HastNode): boolean {
29
+ if (node.type !== "element" || node.tagName !== "span") return false;
30
+ const cls = node.properties?.className;
31
+ const isLine =
32
+ Array.isArray(cls) && cls.some((c) => c === "line" || (typeof c === "string" && c.includes("line")));
33
+ if (!isLine) return false;
34
+ return /^\s*$/.test(getTextContent(node));
35
+ }
36
+
37
+ /** Removes leading and trailing empty span.line so only the code area is visible. */
38
+ function createTrimEmptyLinesTransformer() {
39
+ return {
40
+ name: "barodoc-trim-empty-lines",
41
+ code(node: HastNode) {
42
+ const lines = node.children;
43
+ if (!lines?.length) return;
44
+ let start = 0;
45
+ let end = lines.length;
46
+ while (start < end && isEmptyLine(lines[start])) start++;
47
+ while (end > start && isEmptyLine(lines[end - 1])) end--;
48
+ node.children = lines.slice(start, end);
49
+ },
50
+ };
51
+ }
52
+
53
+ function createLineNumbersTransformer() {
54
+ return {
55
+ name: "barodoc-line-numbers",
56
+ pre(node: { properties?: Record<string, unknown> }) {
57
+ (this as { addClassToHast: (node: unknown, cls: string) => void }).addClassToHast(node, "line-numbers");
58
+ },
59
+ };
60
+ }
61
+
62
+ function createThemeIntegration(
63
+ config: ResolvedBarodocConfig,
64
+ options?: DocsThemeOptions
65
+ ): AstroIntegration {
66
+ const lineNumbers = config?.lineNumbers === true;
67
+ return {
68
+ name: "@barodoc/theme-docs",
69
+ hooks: {
70
+ "astro:config:setup": async ({ updateConfig, injectRoute, logger }) => {
71
+ logger.info("Setting up Barodoc docs theme...");
72
+
73
+ injectRoute({
74
+ pattern: "/",
75
+ entrypoint: "@barodoc/theme-docs/pages/index.astro",
76
+ });
77
+
78
+ injectRoute({
79
+ pattern: "/docs/[...slug]",
80
+ entrypoint: "@barodoc/theme-docs/pages/docs/[...slug].astro",
81
+ });
82
+
83
+ if (config?.blog?.enabled !== false) {
84
+ injectRoute({
85
+ pattern: "/blog",
86
+ entrypoint: "@barodoc/theme-docs/pages/blog/index.astro",
87
+ });
88
+ injectRoute({
89
+ pattern: "/blog/[...slug]",
90
+ entrypoint: "@barodoc/theme-docs/pages/blog/[...slug].astro",
91
+ });
92
+ }
93
+
94
+ injectRoute({
95
+ pattern: "/changelog",
96
+ entrypoint: "@barodoc/theme-docs/pages/changelog/index.astro",
97
+ });
98
+
99
+ updateConfig({
100
+ integrations: [
101
+ mdx({
102
+ remarkPlugins: [remarkMath],
103
+ rehypePlugins: [rehypeKatex],
104
+ }),
105
+ react(),
106
+ ],
107
+ vite: {
108
+ plugins: [tailwindcss()],
109
+ optimizeDeps: {
110
+ include: ["mermaid"],
111
+ },
112
+ ssr: {
113
+ noExternal: [],
114
+ },
115
+ resolve: {
116
+ dedupe: ["react", "react-dom"],
117
+ },
118
+ },
119
+ markdown: {
120
+ shikiConfig: {
121
+ themes: {
122
+ light: "github-light",
123
+ dark: "github-dark",
124
+ },
125
+ transformers: [
126
+ createTrimEmptyLinesTransformer(),
127
+ ...(lineNumbers ? [createLineNumbersTransformer()] : []),
128
+ ],
129
+ },
130
+ },
131
+ });
132
+
133
+ logger.info("Docs theme routes injected");
134
+ },
135
+ },
136
+ };
137
+ }
138
+
139
+ export default function docsTheme(options?: DocsThemeOptions): ThemeExport {
140
+ return {
141
+ name: "@barodoc/theme-docs",
142
+ integration: (config) => createThemeIntegration(config, options),
143
+ styles: options?.customCss || [],
144
+ };
145
+ }