doccupine 0.0.137 → 0.0.139
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/index.js +27 -0
- package/dist/lib/layout.js +3 -1
- package/dist/lib/mdxToMarkdown.d.ts +1 -0
- package/dist/lib/mdxToMarkdown.js +134 -0
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +2 -2
- package/dist/templates/components/DocsSideBar.d.ts +1 -1
- package/dist/templates/components/DocsSideBar.js +1 -1
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +64 -31
- package/dist/templates/components/layout/Card.d.ts +1 -1
- package/dist/templates/components/layout/Card.js +3 -0
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +33 -2
- package/dist/templates/components/layout/Mermaid.d.ts +1 -1
- package/dist/templates/components/layout/Mermaid.js +5 -1
- package/dist/templates/llms/llmsIndex.d.ts +13 -0
- package/dist/templates/llms/llmsIndex.js +18 -10
- package/dist/templates/llms/llmsPage.js +2 -0
- package/dist/templates/llms/skillMd.d.ts +10 -0
- package/dist/templates/llms/skillMd.js +59 -0
- package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
- package/dist/templates/mdx/mermaid.mdx.js +1 -1
- package/dist/templates/next.config.js +17 -0
- package/dist/templates/package.js +1 -1
- package/dist/templates/proxy.js +30 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { sitemapTemplate } from "./templates/app/sitemap.js";
|
|
|
22
22
|
import { llmsIndexTemplate } from "./templates/llms/llmsIndex.js";
|
|
23
23
|
import { llmsFullTemplate, } from "./templates/llms/llmsFull.js";
|
|
24
24
|
import { llmsPageTemplate } from "./templates/llms/llmsPage.js";
|
|
25
|
+
import { siteDocsSlug, skillMdTemplate } from "./templates/llms/skillMd.js";
|
|
25
26
|
export { generateSlug, getFullSlug, escapeTemplateContent, toJsStringLiteral, } from "./lib/utils.js";
|
|
26
27
|
const __filename = fileURLToPath(import.meta.url);
|
|
27
28
|
const __dirname = path.dirname(__filename);
|
|
@@ -1660,6 +1661,32 @@ export default function Page() {
|
|
|
1660
1661
|
});
|
|
1661
1662
|
await fs.writeFile(path.join(publicDir, "llms.txt"), indexContent, "utf8");
|
|
1662
1663
|
await fs.writeFile(path.join(publicDir, "llms-full.txt"), fullContent, "utf8");
|
|
1664
|
+
const skillContent = skillMdTemplate({
|
|
1665
|
+
siteName: name,
|
|
1666
|
+
siteDescription: description,
|
|
1667
|
+
baseUrl,
|
|
1668
|
+
pages: resolvedPages,
|
|
1669
|
+
sectionsConfig: this.sectionsConfig,
|
|
1670
|
+
});
|
|
1671
|
+
await fs.writeFile(path.join(publicDir, "skill.md"), skillContent, "utf8");
|
|
1672
|
+
// MCP discovery manifest. Needs an absolute URL, so it only exists when
|
|
1673
|
+
// config.json declares the site url; it is pruned if the url is removed.
|
|
1674
|
+
const mcpJsonPath = path.join(publicDir, ".well-known", "mcp.json");
|
|
1675
|
+
if (baseUrl) {
|
|
1676
|
+
const mcpJson = JSON.stringify({
|
|
1677
|
+
mcpServers: {
|
|
1678
|
+
[siteDocsSlug(name)]: {
|
|
1679
|
+
url: `${baseUrl}/api/mcp`,
|
|
1680
|
+
transport: "streamable-http",
|
|
1681
|
+
},
|
|
1682
|
+
},
|
|
1683
|
+
}, null, 2) + "\n";
|
|
1684
|
+
await fs.ensureDir(path.dirname(mcpJsonPath));
|
|
1685
|
+
await fs.writeFile(mcpJsonPath, mcpJson, "utf8");
|
|
1686
|
+
}
|
|
1687
|
+
else if (await fs.pathExists(mcpJsonPath)) {
|
|
1688
|
+
await fs.remove(mcpJsonPath);
|
|
1689
|
+
}
|
|
1663
1690
|
const nextRelativePaths = new Set();
|
|
1664
1691
|
await Promise.all(pagesWithBodies.map(async (page) => {
|
|
1665
1692
|
const relPath = page.slug === "" ? "index.md" : `${page.slug}.md`;
|
package/dist/lib/layout.js
CHANGED
|
@@ -184,7 +184,7 @@ ${hasSections
|
|
|
184
184
|
? ""
|
|
185
185
|
: `import { Footer } from "@/components/layout/Footer";
|
|
186
186
|
`}import { Header } from "@/components/layout/Header";
|
|
187
|
-
import { DocsWrapper } from "@/components/layout/DocsComponents";
|
|
187
|
+
import { DocsWrapper, LlmsDirective } from "@/components/layout/DocsComponents";
|
|
188
188
|
${hasSections
|
|
189
189
|
? ""
|
|
190
190
|
: `import { SectionBarProvider } from "@/components/layout/DocsComponents";
|
|
@@ -221,6 +221,7 @@ ${hasSections
|
|
|
221
221
|
return (
|
|
222
222
|
${chtOpen}
|
|
223
223
|
<SearchProvider pages={pages} sections={doccupineSections}>
|
|
224
|
+
<LlmsDirective />
|
|
224
225
|
<Header>
|
|
225
226
|
<SectionBar sections={doccupineSections} />
|
|
226
227
|
</Header>
|
|
@@ -263,6 +264,7 @@ ${hasSections
|
|
|
263
264
|
return (
|
|
264
265
|
${chtOpen}
|
|
265
266
|
<SearchProvider pages={pages}>
|
|
267
|
+
<LlmsDirective />
|
|
266
268
|
<Header />
|
|
267
269
|
{process.env.LLM_PROVIDER && <Chat />}
|
|
268
270
|
<SectionBarProvider hasSectionBar={false}>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mdxToMarkdown(body: string): string;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Converts an MDX page body into the plain markdown its HTML render shows.
|
|
2
|
+
// The .md mirrors and llms-full.txt are built from this so agents get real
|
|
3
|
+
// text instead of raw JSX: component tags are unwrapped (children are already
|
|
4
|
+
// markdown), and text that only exists in JSX props (Card titles, Field
|
|
5
|
+
// names, Frame captions, ...) is hoisted into the output where the rendered
|
|
6
|
+
// page displays it. Unknown components fall through to "drop the tag, keep
|
|
7
|
+
// the children".
|
|
8
|
+
// Matches an open, close, or self-closing JSX/HTML tag. The (?=[\s/>])
|
|
9
|
+
// lookahead after the name keeps markdown autolinks like <https://...> from
|
|
10
|
+
// matching. Attribute text may contain quoted strings and one level of
|
|
11
|
+
// nested braces (enough for expressions like tabs={[{ ... }, { ... }]}).
|
|
12
|
+
const TAG_RE = /<(\/?)([A-Za-z][\w]*)(?=[\s/>])((?:"[^"]*"|'[^']*'|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|[^>"'{])*?)(\/?)>/g;
|
|
13
|
+
const ATTR_RE = /([A-Za-z][\w-]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}))?/g;
|
|
14
|
+
function parseAttrs(raw) {
|
|
15
|
+
const attrs = new Map();
|
|
16
|
+
for (const m of raw.matchAll(ATTR_RE)) {
|
|
17
|
+
attrs.set(m[1], m[2] ?? m[3] ?? true);
|
|
18
|
+
}
|
|
19
|
+
return attrs;
|
|
20
|
+
}
|
|
21
|
+
function str(value) {
|
|
22
|
+
return typeof value === "string" ? value : "";
|
|
23
|
+
}
|
|
24
|
+
export function mdxToMarkdown(body) {
|
|
25
|
+
const stash = [];
|
|
26
|
+
const keep = (match) => `\u0000${stash.push(match) - 1}\u0000`;
|
|
27
|
+
// Code renders verbatim in HTML, so it must survive untouched.
|
|
28
|
+
let text = body.replace(/```[\s\S]*?```/g, keep);
|
|
29
|
+
text = text.replace(/`[^`\n]+`/g, keep);
|
|
30
|
+
text = text.replace(/\{\/\*[\s\S]*?\*\/\}/g, "");
|
|
31
|
+
// Some tags emit text where their children END (a Frame caption renders
|
|
32
|
+
// under the image, a Tooltip definition follows the wrapped term), so the
|
|
33
|
+
// open tag pushes the text and the close tag pops it.
|
|
34
|
+
const pending = {};
|
|
35
|
+
const push = (name, value) => (pending[name] ??= []).push(value);
|
|
36
|
+
const pop = (name) => pending[name]?.pop() ?? "";
|
|
37
|
+
text = text.replace(TAG_RE, (_match, close, name, rawAttrs, _selfClose) => {
|
|
38
|
+
const isClose = close === "/";
|
|
39
|
+
const attrs = isClose
|
|
40
|
+
? new Map()
|
|
41
|
+
: parseAttrs(rawAttrs);
|
|
42
|
+
switch (name) {
|
|
43
|
+
// Title props render as the block's visible heading.
|
|
44
|
+
case "Card":
|
|
45
|
+
case "Accordion":
|
|
46
|
+
case "Step":
|
|
47
|
+
case "TabContent": {
|
|
48
|
+
if (isClose)
|
|
49
|
+
return "";
|
|
50
|
+
const title = str(attrs.get("title"));
|
|
51
|
+
return title ? `**${title}**\n\n` : "";
|
|
52
|
+
}
|
|
53
|
+
case "Update": {
|
|
54
|
+
if (isClose)
|
|
55
|
+
return "";
|
|
56
|
+
const label = str(attrs.get("label"));
|
|
57
|
+
const description = str(attrs.get("description"));
|
|
58
|
+
return ((label ? `## ${label}\n\n` : "") +
|
|
59
|
+
(description ? `${description}\n\n` : ""));
|
|
60
|
+
}
|
|
61
|
+
case "Field": {
|
|
62
|
+
if (isClose)
|
|
63
|
+
return "";
|
|
64
|
+
const value = str(attrs.get("value"));
|
|
65
|
+
if (!value)
|
|
66
|
+
return "";
|
|
67
|
+
const parts = [str(attrs.get("type"))].filter(Boolean);
|
|
68
|
+
if (attrs.get("required") === true)
|
|
69
|
+
parts.push("required");
|
|
70
|
+
return parts.length
|
|
71
|
+
? `**${value}** (${parts.join(", ")})\n\n`
|
|
72
|
+
: `**${value}**\n\n`;
|
|
73
|
+
}
|
|
74
|
+
case "ColorSwatch": {
|
|
75
|
+
if (isClose)
|
|
76
|
+
return "";
|
|
77
|
+
const token = str(attrs.get("token"));
|
|
78
|
+
const value = str(attrs.get("value"));
|
|
79
|
+
return token && value ? `- ${token}: ${value}\n` : "";
|
|
80
|
+
}
|
|
81
|
+
case "Prompt": {
|
|
82
|
+
if (isClose)
|
|
83
|
+
return "";
|
|
84
|
+
const description = str(attrs.get("description"));
|
|
85
|
+
return description ? `${description}\n\n` : "";
|
|
86
|
+
}
|
|
87
|
+
case "Frame": {
|
|
88
|
+
if (isClose) {
|
|
89
|
+
const caption = pop(name);
|
|
90
|
+
return caption ? `\n\n${caption}\n\n` : "";
|
|
91
|
+
}
|
|
92
|
+
const caption = [str(attrs.get("caption")), str(attrs.get("hint"))]
|
|
93
|
+
.filter(Boolean)
|
|
94
|
+
.join(" ");
|
|
95
|
+
push(name, caption);
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
case "Tooltip": {
|
|
99
|
+
if (isClose) {
|
|
100
|
+
const tip = pop(name);
|
|
101
|
+
return tip ? ` (${tip})` : "";
|
|
102
|
+
}
|
|
103
|
+
push(name, str(attrs.get("tip")));
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
case "CodeTabs": {
|
|
107
|
+
if (isClose)
|
|
108
|
+
return "";
|
|
109
|
+
const pairs = [
|
|
110
|
+
...rawAttrs.matchAll(/label:\s*"([^"]*)"\s*,\s*code:\s*"([^"]*)"/g),
|
|
111
|
+
];
|
|
112
|
+
return pairs
|
|
113
|
+
.map(([, label, code]) => `**${label}**\n\n\`\`\`\n${code}\n\`\`\`\n\n`)
|
|
114
|
+
.join("");
|
|
115
|
+
}
|
|
116
|
+
case "img": {
|
|
117
|
+
const src = str(attrs.get("src"));
|
|
118
|
+
const alt = str(attrs.get("alt"));
|
|
119
|
+
return src ? `` : "";
|
|
120
|
+
}
|
|
121
|
+
case "br":
|
|
122
|
+
return "\n";
|
|
123
|
+
// Everything else (Callout, Badge, Button, Tabs, Steps, Columns, Tree,
|
|
124
|
+
// SidePanel, iframe, ...) is presentation-only: drop the tag, keep the
|
|
125
|
+
// markdown children.
|
|
126
|
+
default:
|
|
127
|
+
return "";
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
// Collapse the gaps the removed tags leave behind, then restore code.
|
|
131
|
+
text = text.replace(/[ \t]+$/gm, "").replace(/\n{3,}/g, "\n\n");
|
|
132
|
+
text = text.replace(/\u0000(\d+)\u0000/g, (_m, i) => stash[Number(i)]);
|
|
133
|
+
return text.trim() + "\n";
|
|
134
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const chatTemplate = "\"use client\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport styled, { css, keyframes } from \"styled-components\";\nimport { Button, IconButton } from \"cherry-styled-components\";\nimport { ArrowUp, LoaderPinwheel, RotateCcw, Sparkles, X } from \"lucide-react\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport { MDXRemote, MDXRemoteSerializeResult } from \"next-mdx-remote\";\nimport { serialize } from \"next-mdx-remote/serialize\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\nimport { useMDXComponents as getMDXComponents } from \"@/components/MDXComponents\";\nimport {\n styledAnchor,\n styledTable,\n stylesLists,\n StyledSmallButton,\n interactiveStyles,\n thinScrollbar,\n} from \"@/components/layout/SharedStyled\";\n\nconst mdxComponents = getMDXComponents({});\n\nconst styledText = css<{ theme: Theme }>`\n font-size: ${({ theme }) => theme.fontSizes.text.xs};\n line-height: ${({ theme }) => theme.lineHeights.text.xs};\n\n ${mq(\"lg\")} {\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: ${({ theme }) => theme.lineHeights.small.lg};\n }\n`;\n\nconst StyledChat = styled.div<{ theme: Theme; $isVisible: boolean }>`\n margin: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 100%;\n height: calc(100dvh - 90px);\n overflow-y: scroll;\n overflow-x: hidden;\n z-index: 1000;\n padding: 0 20px;\n transition: all 0.3s ease;\n transform: translateX(0);\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n opacity: 1;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${({ $isVisible }) =>\n !$isVisible &&\n css`\n transform: translateX(100%);\n opacity: 0;\n `}\n\n ${mq(\"lg\")} {\n width: 420px;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n }\n`;\n\nconst loadingAnimation = keyframes`\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n`;\n\nconst rotateGradient = keyframes`\n 0% {\n --gradient-angle: 0deg;\n }\n 100% {\n --gradient-angle: 360deg;\n }\n`;\n\nconst pulseGlow = keyframes`\n 0%, 100% {\n opacity: 0.5;\n filter: blur(16px);\n }\n 50% {\n opacity: 1;\n filter: blur(22px);\n }\n`;\n\nconst sparkleFloat = keyframes`\n 0%, 100% {\n opacity: 0;\n transform: translateY(0) scale(0);\n }\n 50% {\n opacity: 0.9;\n transform: translateY(-20px) scale(1);\n }\n`;\n\nconst shimmer = keyframes`\n 0% {\n background-position: 0% center;\n }\n 50% {\n background-position: 100% center;\n }\n 100% {\n background-position: 0% center;\n }\n`;\n\nconst StyledRainbowInputWrapper = styled.div<{\n theme: Theme;\n $isActive: boolean;\n}>`\n @property --gradient-angle {\n syntax: \"<angle>\";\n initial-value: 0deg;\n inherits: false;\n }\n\n position: relative;\n flex: 1;\n\n &::before {\n content: \"\";\n position: absolute;\n inset: -2px;\n border-radius: 14px;\n background: conic-gradient(\n from var(--gradient-angle),\n #cc5555,\n #d9a745,\n #3ab0cc,\n #cc7fc2,\n #4380cc,\n #4c1fa3,\n #cc5555\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation: ${rotateGradient} 3s linear infinite;\n z-index: 0;\n }\n\n &::after {\n content: \"\";\n position: absolute;\n inset: -10px;\n border-radius: 20px;\n background: conic-gradient(\n from var(--gradient-angle),\n #ff6b6b66,\n #feca5766,\n #48dbfb66,\n #ff9ff366,\n #54a0ff66,\n #5f27cd66,\n #ff6b6b66\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation:\n ${rotateGradient} 3s linear infinite,\n ${pulseGlow} 2s ease-in-out infinite;\n z-index: -1;\n pointer-events: none;\n }\n\n &:hover::before,\n &:focus-within::before {\n opacity: 1;\n }\n\n &:hover::after,\n &:focus-within::after {\n opacity: 1;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n opacity: 1;\n }\n &::after {\n opacity: 1;\n }\n `}\n`;\n\nconst StyledSparkleContainer = styled.div<{ $isActive: boolean }>`\n position: absolute;\n inset: -30px;\n pointer-events: none;\n overflow: hidden;\n border-radius: 30px;\n z-index: -2;\n opacity: 0;\n transition: opacity 0.4s ease;\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n opacity: 1;\n `}\n`;\n\nconst StyledSparkle = styled.div<{\n $color: string;\n $left: number;\n $top: number;\n $delay: number;\n}>`\n position: absolute;\n width: 4px;\n height: 4px;\n border-radius: 50%;\n background: ${({ $color }) => $color};\n box-shadow: 0 0 6px ${({ $color }) => $color};\n left: ${({ $left }) => $left}%;\n top: ${({ $top }) => $top}%;\n animation: ${sparkleFloat} 2s ease-in-out infinite;\n animation-delay: ${({ $delay }) => $delay}s;\n`;\n\nconst StyledRainbowInput = styled.input<{ theme: Theme }>`\n position: relative;\n z-index: 1;\n width: 100%;\n background: ${({ theme }) => theme.colors.light};\n border: 1px solid ${({ theme }) => theme.colors.grayLight};\n border-radius: 12px;\n padding: 12px 18px;\n font-size: ${({ theme }) => theme.fontSizes.text.lg};\n font-family: inherit;\n color: ${({ theme }) => theme.colors.dark};\n outline: none;\n transition:\n border-color 0.3s ease,\n box-shadow 0.3s ease;\n\n ${mq(\"lg\")} {\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n }\n\n &::placeholder {\n color: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.dark} 40%, transparent)`};\n transition: color 0.3s ease;\n }\n\n &:focus::placeholder {\n color: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.dark} 60%, transparent)`};\n }\n\n &:focus {\n border-color: transparent;\n }\n`;\n\nconst StyledRainbowButton = styled(Button)<{\n theme: Theme;\n $hasContent: boolean;\n}>`\n padding-top: 10px;\n padding-bottom: 10px;\n position: relative;\n overflow: hidden;\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;\n color: ${({ theme }) => theme.colors.surface};\n\n &::before {\n content: \"\";\n position: absolute;\n inset: 0;\n background: linear-gradient(\n 135deg,\n #ff6b6b,\n #feca57,\n #48dbfb,\n #ff9ff3,\n #54a0ff\n );\n background-size: 300% 300%;\n opacity: 0;\n transition: opacity 0.3s ease;\n z-index: 0;\n animation: ${shimmer} 3s linear infinite;\n width: 200%;\n }\n\n ${({ $hasContent }) =>\n $hasContent &&\n css`\n &::before {\n opacity: 1;\n }\n `}\n\n &:hover::before {\n opacity: 1;\n }\n\n &:hover {\n transform: scale(1.05);\n }\n\n &:active {\n transform: scale(0.95);\n }\n\n & svg {\n position: relative;\n z-index: 1;\n transition: transform 0.3s ease;\n }\n\n &:disabled,\n &:disabled:hover {\n background: ${({ theme }) => theme.colors.primaryDark};\n transform: none;\n box-shadow: none;\n\n &::before {\n opacity: 0;\n }\n }\n`;\n\nconst StyledChatForm = styled.form<{ theme: Theme; $isVisible: boolean }>`\n display: flex;\n gap: 10px;\n justify-content: center;\n align-items: center;\n background: ${({ theme }) => theme.colors.light};\n padding: 20px;\n position: fixed;\n bottom: 0;\n right: 0;\n z-index: 1000;\n width: 100%;\n border-top: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: all 0.3s ease;\n transform: translateX(100%);\n opacity: 0;\n\n ${mq(\"lg\")} {\n width: 420px;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n }\n\n ${({ $isVisible }) =>\n $isVisible &&\n css`\n opacity: 1;\n transform: translateX(0);\n `}\n\n & .loading {\n animation: ${loadingAnimation} 1s linear infinite;\n }\n`;\n\nconst StyledGlowSmallButton = styled(StyledSmallButton)<{\n theme: Theme;\n $hasContent: boolean;\n}>`\n @property --gradient-angle {\n syntax: \"<angle>\";\n initial-value: 0deg;\n inherits: false;\n }\n\n position: relative;\n isolation: isolate;\n margin-right: 0;\n background: ${({ theme }) => theme.colors.light};\n padding: 0;\n\n &::before {\n content: \"\";\n inset: -2px;\n border-radius: 8px;\n background: conic-gradient(\n from var(--gradient-angle),\n #cc5555,\n #d9a745,\n #3ab0cc,\n #cc7fc2,\n #4380cc,\n #4c1fa3,\n #cc5555\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation: ${rotateGradient} 3s linear infinite;\n z-index: -1;\n position: absolute;\n top: -2px;\n left: -2px;\n width: calc(100% + 4px);\n height: calc(100% + 4px);\n }\n\n &::after {\n content: \"\";\n position: absolute;\n inset: -8px;\n border-radius: 14px;\n background: conic-gradient(\n from var(--gradient-angle),\n #ff6b6b66,\n #feca5766,\n #48dbfb66,\n #ff9ff366,\n #54a0ff66,\n #5f27cd66,\n #ff6b6b66\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation:\n ${rotateGradient} 3s linear infinite,\n ${pulseGlow} 2s ease-in-out infinite;\n z-index: -2;\n pointer-events: none;\n }\n\n &:hover::before,\n &:hover::after {\n opacity: 1;\n }\n\n & span {\n padding: 6px 8px;\n display: flex;\n background: ${({ theme }) => theme.colors.light};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n gap: 6px;\n }\n\n ${({ $hasContent }) =>\n $hasContent &&\n css`\n &::before {\n opacity: 1;\n }\n &::after {\n opacity: 1;\n }\n `}\n`;\n\nconst StyledError = styled.div<{ theme: Theme }>`\n overflow-x: auto;\n ${thinScrollbar};\n background: ${({ theme }) => theme.colors.error};\n color: ${({ theme }) => theme.colors.surface};\n padding: 10px;\n border-radius: 8px;\n margin: 20px 0;\n width: 100%;\n ${styledText};\n`;\n\nconst loadingDotAnimation = keyframes`\n 0% {\n opacity: 0;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n`;\n\nconst StyledLoading = styled.div<{ theme: Theme }>`\n overflow-x: auto;\n ${thinScrollbar};\n margin: 20px 0;\n width: 100%;\n font-weight: 600;\n ${styledText};\n color: ${({ theme }) => theme.colors.dark};\n\n & span {\n &:nth-child(1) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n }\n &:nth-child(2) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n animation-delay: 0.2s;\n }\n &:nth-child(3) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n animation-delay: 0.4s;\n }\n }\n`;\n\nconst StyledAnswer = styled.div<{ theme: Theme; $isAnswer: boolean }>`\n overflow-x: auto;\n ${thinScrollbar};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n padding: 9px 14px;\n border-radius: 16px 16px 4px 16px;\n margin: 20px 0 20px auto;\n width: fit-content;\n max-width: min(560px, 88%);\n font-weight: 500;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n ${styledText};\n\n & p {\n ${styledText};\n }\n\n ${({ $isAnswer }) =>\n $isAnswer &&\n css`\n background: transparent;\n color: ${({ theme }) => theme.colors.dark};\n padding: 0;\n width: 100%;\n max-width: 100%;\n margin: 20px 0;\n border-radius: 0;\n font-weight: inherit;\n white-space: normal;\n `}\n\n & code:not([class]) {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n white-space: pre;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & pre,\n & .hljs {\n margin: 10px 0;\n }\n\n & .code-wrapper pre {\n margin: 0;\n ${styledText};\n }\n\n & > *:first-child {\n margin-top: 0;\n }\n\n & > *:last-child {\n margin-bottom: 0;\n\n & > *:last-child {\n margin-bottom: 0;\n }\n }\n\n & ul,\n & ol {\n & li {\n ${styledText};\n }\n }\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n margin: 10px 0;\n display: block;\n }\n\n & h1,\n & h2,\n & h3,\n & h4,\n & h5,\n & h6 {\n margin: 10px 0;\n padding: 0;\n }\n`;\n\nconst StyledSources = styled.div`\n display: flex;\n gap: 16px;\n flex-wrap: wrap;\n margin: -5px 0 20px;\n`;\n\nconst StyledSourceLink = styled(Link)<{ theme: Theme }>`\n position: relative;\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1;\n color: ${({ theme }) => theme.colors.primary};\n display: flex;\n gap: 6px;\n transition: all 0.3s ease;\n font-weight: 600;\n white-space: nowrap;\n min-width: fit-content;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 10%, transparent)`};\n padding: 6px 8px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n ${interactiveStyles};\n\n & * {\n margin: auto 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n }\n`;\n\nconst StyledChatTitle = styled.div<{ theme: Theme }>`\n display: flex;\n flex-wrap: nowrap;\n justify-content: space-between;\n position: sticky;\n margin: 0 -20px;\n padding: 16px 20px;\n height: 62px;\n top: 0;\n background: ${({ theme }) => theme.colors.light};\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n z-index: 1000;\n`;\n\nconst StyledChatTitleIconWrapper = styled.span<{ theme: Theme }>`\n display: flex;\n align-items: center;\n gap: 12px;\n color: ${({ theme }) => theme.colors.dark};\n`;\n\ntype Source = {\n id: string;\n path: string;\n uri: string;\n score: number;\n};\n\ntype Answer = {\n text: string;\n answer?: boolean;\n mdx?: MDXRemoteSerializeResult;\n sources?: Source[];\n};\n\nconst SPARKLE_COLORS = [\n \"#ff6b6b\",\n \"#feca57\",\n \"#48dbfb\",\n \"#ff9ff3\",\n \"#54a0ff\",\n \"#5f27cd\",\n];\n\n// Deterministic sparkle positions to avoid hydration mismatch\nconst SPARKLE_POSITIONS = [\n { left: 8, top: 35 },\n { left: 17, top: 55 },\n { left: 26, top: 28 },\n { left: 35, top: 68 },\n { left: 44, top: 42 },\n { left: 53, top: 75 },\n { left: 62, top: 32 },\n { left: 71, top: 58 },\n { left: 80, top: 45 },\n { left: 89, top: 65 },\n];\n\ninterface RainbowInputProps {\n id?: string;\n value: string;\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n placeholder?: string;\n autoComplete?: string;\n \"aria-label\"?: string;\n inputRef?: React.Ref<HTMLInputElement>;\n}\n\nfunction RainbowInput({\n id,\n value,\n onChange,\n placeholder,\n autoComplete,\n \"aria-label\": ariaLabel,\n inputRef,\n}: RainbowInputProps) {\n const [isFocused, setIsFocused] = useState(false);\n const [isHovered, setIsHovered] = useState(false);\n const isActive = isFocused || isHovered;\n\n const sparkles = SPARKLE_POSITIONS.map((pos, i) => ({\n color: SPARKLE_COLORS[i % SPARKLE_COLORS.length],\n left: pos.left,\n top: pos.top,\n delay: i * 0.12,\n }));\n\n return (\n <StyledRainbowInputWrapper\n $isActive={isActive}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <StyledSparkleContainer $isActive={isActive}>\n {sparkles.map((sparkle, i) => (\n <StyledSparkle\n key={i}\n $color={sparkle.color}\n $left={sparkle.left}\n $top={sparkle.top}\n $delay={sparkle.delay}\n />\n ))}\n </StyledSparkleContainer>\n <StyledRainbowInput\n ref={inputRef}\n id={id}\n value={value}\n onChange={onChange}\n placeholder={placeholder}\n autoComplete={autoComplete}\n aria-label={ariaLabel}\n onFocus={() => setIsFocused(true)}\n onBlur={() => setIsFocused(false)}\n />\n </StyledRainbowInputWrapper>\n );\n}\n\nfunction ChatButtonCTA() {\n const { toggleChat, isOpen } = useContext(ChatContext);\n\n return (\n <StyledGlowSmallButton\n onClick={toggleChat}\n aria-label=\"Ask AI Assistant\"\n $hasContent={isOpen}\n type=\"button\"\n >\n <span>\n <Sparkles size={16} />\n Ask AI\n </span>\n </StyledGlowSmallButton>\n );\n}\n\nfunction Chat() {\n const {\n isOpen,\n question,\n setQuestion,\n loading,\n error,\n answer,\n ask,\n closeChat,\n resetChat,\n chatInputRef,\n } = useContext(ChatContext);\n const endRef = useRef<HTMLDivElement | null>(null);\n\n useLockBodyScroll(isOpen);\n\n useEffect(() => {\n endRef.current?.scrollIntoView({ behavior: \"smooth\", block: \"end\" });\n }, [answer]);\n\n useEffect(() => {\n if (answer?.length > 0) {\n chatInputRef.current?.focus();\n }\n }, [answer, chatInputRef]);\n\n return (\n <>\n <StyledChat $isVisible={isOpen}>\n <StyledChatTitle>\n <StyledChatTitleIconWrapper>\n <Sparkles />\n <h3>AI Assistant</h3>\n </StyledChatTitleIconWrapper>\n <StyledChatTitleIconWrapper>\n <IconButton\n onClick={resetChat}\n aria-label=\"Reset chat history\"\n title=\"Reset chat history\"\n >\n <RotateCcw />\n </IconButton>\n <IconButton\n onClick={closeChat}\n aria-label=\"Close chat\"\n title=\"Close chat\"\n >\n <X />\n </IconButton>\n </StyledChatTitleIconWrapper>\n </StyledChatTitle>\n {answer &&\n answer.map((a, i) => (\n <React.Fragment key={i}>\n <StyledAnswer $isAnswer={a.answer ?? false}>\n {a.answer && a.mdx ? (\n <MDXRemote {...a.mdx} components={mdxComponents} />\n ) : (\n a.text\n )}\n </StyledAnswer>\n {a.answer && a.sources && a.sources.length > 0 && (\n <StyledSources>\n {a.sources.map((src) => {\n const slug = src.uri\n .replace(\"docs://\", \"\")\n .replace(/^\\/+/, \"\");\n const href = slug ? `/${slug}/` : \"/\";\n const label = slug\n ? slug\n .split(\"/\")\n .pop()!\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (c: string) => c.toUpperCase())\n : \"Home\";\n return (\n <StyledSourceLink\n key={src.id}\n href={href}\n onClick={() => {\n if (window.innerWidth <= 992) {\n closeChat();\n }\n }}\n >\n {label}\n </StyledSourceLink>\n );\n })}\n </StyledSources>\n )}\n </React.Fragment>\n ))}\n {loading && !answer[answer.length - 1]?.answer && (\n <StyledLoading>\n Answering<span>.</span>\n <span>.</span>\n <span>.</span>\n </StyledLoading>\n )}\n {error && (\n <StyledError>\n <strong>Error:</strong> {error}\n </StyledError>\n )}\n <div ref={endRef} />\n </StyledChat>\n\n <StyledChatForm onSubmit={ask} $isVisible={isOpen}>\n <RainbowInput\n id=\"chat-bottom-input\"\n inputRef={chatInputRef}\n value={question}\n onChange={(e) => setQuestion(e.target.value)}\n placeholder=\"Ask AI Assistant...\"\n autoComplete=\"off\"\n aria-label=\"Ask a follow-up question\"\n />\n <StyledRainbowButton\n type=\"submit\"\n disabled={loading || question.trim() === \"\"}\n $hasContent={question.trim().length > 0}\n aria-label={loading ? \"Loading response\" : \"Submit question\"}\n >\n {loading ? <LoaderPinwheel className=\"loading\" /> : <ArrowUp />}\n </StyledRainbowButton>\n </StyledChatForm>\n </>\n );\n}\n\nconst ChatContext = createContext<{\n isOpen: boolean;\n setIsOpen: (isOpen: boolean) => void;\n toggleChat: () => void;\n isChatActive: boolean;\n question: string;\n setQuestion: (q: string) => void;\n loading: boolean;\n error: string | null;\n answer: Answer[];\n setAnswer: (answers: Answer[]) => void;\n ask: (e: React.FormEvent) => void;\n askAssistant: (question: string) => void;\n closeChat: () => void;\n resetChat: () => void;\n chatInputRef: React.RefObject<HTMLInputElement | null>;\n}>({\n isOpen: false,\n setIsOpen: () => {},\n toggleChat: () => {},\n isChatActive: false,\n question: \"\",\n setQuestion: () => {},\n loading: false,\n error: null,\n answer: [],\n setAnswer: () => {},\n ask: () => {},\n askAssistant: () => {},\n closeChat: () => {},\n resetChat: () => {},\n chatInputRef: { current: null },\n});\n\ninterface ChatContextProviderProps {\n children: React.ReactNode;\n isChatActive: boolean;\n}\n\nconst INITIAL_GREETING = \"Hey there, how can I assist you?\";\n\nconst ChtProvider = ({ children, isChatActive }: ChatContextProviderProps) => {\n const [isOpen, setIsOpen] = useState(false);\n const [question, setQuestion] = useState(\"\");\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [answer, setAnswer] = useState<Answer[]>([]);\n const abortRef = useRef<AbortController | null>(null);\n const chatInputRef = useRef<HTMLInputElement | null>(null);\n const isOpenRef = useRef(isOpen);\n\n useEffect(() => {\n isOpenRef.current = isOpen;\n }, [isOpen]);\n\n // Open the assistant, seeding a greeting the first time and focusing the\n // input once the panel has slid in (matches the 0.3s panel transition).\n const openChat = useCallback(() => {\n setIsOpen(true);\n setAnswer((prev) =>\n prev.length === 0 ? [{ text: INITIAL_GREETING, answer: true }] : prev,\n );\n setTimeout(() => {\n chatInputRef.current?.focus();\n }, 350);\n }, []);\n\n const toggleChat = useCallback(() => {\n if (isOpenRef.current) {\n setIsOpen(false);\n } else {\n openChat();\n }\n }, [openChat]);\n\n // Global Cmd/Ctrl+I toggles the assistant, but only when chat is enabled.\n useEffect(() => {\n if (!isChatActive) return;\n function handleKeyDown(e: KeyboardEvent) {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"i\") {\n e.preventDefault();\n toggleChat();\n }\n }\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [isChatActive, toggleChat]);\n\n async function runQuestion(currentQuestion: string) {\n setQuestion(\"\");\n setIsOpen(true);\n setLoading(true);\n setError(null);\n\n const base =\n answer.length > 0 ? answer : [{ text: INITIAL_GREETING, answer: true }];\n const mergedQuestions = [...base, { text: currentQuestion, answer: false }];\n\n setAnswer(mergedQuestions);\n\n const controller = new AbortController();\n abortRef.current = controller;\n\n try {\n const history = answer\n .filter((a) => a.text.trim() !== \"\")\n .map((a) => ({\n role: a.answer ? (\"assistant\" as const) : (\"user\" as const),\n content: a.text,\n }));\n\n const res = await fetch(\"/api/rag\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ question: currentQuestion, history }),\n signal: controller.signal,\n });\n\n if (!res.ok) {\n // The body may be a proxy/gateway HTML error page (e.g. Cloudflare\n // 524), not our JSON - never blindly JSON.parse it.\n const contentType = res.headers.get(\"content-type\") || \"\";\n let message = \"Request failed\";\n if (contentType.includes(\"application/json\")) {\n try {\n const errorData = await res.json();\n message = errorData.error || message;\n } catch {\n // Non-JSON despite the header - fall through to the default.\n }\n } else if ([502, 503, 504, 524].includes(res.status)) {\n message = \"The assistant took too long to respond. Please try again.\";\n }\n throw new Error(message);\n }\n\n const reader = res.body?.getReader();\n const decoder = new TextDecoder();\n const contentParts: string[] = [];\n let sources: Source[] = [];\n if (!reader) {\n throw new Error(\"Failed to get response reader\");\n }\n\n // Don't insert the answer bubble yet - an empty bubble renders a blank\n // gap above the \"Answering...\" loader. The bubble is created on the first\n // streamed token (or the done event) instead, so the loader stays put\n // until real text appears.\n const streamingAnswerIndex = mergedQuestions.length;\n\n let buffer = \"\";\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const parts = buffer.split(\"\\n\");\n buffer = parts.pop() ?? \"\";\n\n for (const line of parts) {\n if (line.startsWith(\"data: \")) {\n try {\n const data = JSON.parse(line.slice(6));\n\n if (data.type === \"metadata\") {\n const allSources: Source[] = data.data?.sources ?? [];\n const seen = new Set<string>();\n sources = allSources.filter((s: Source) => {\n if (s.score < 0.4 || seen.has(s.uri)) return false;\n seen.add(s.uri);\n return true;\n });\n } else if (data.type === \"content\") {\n contentParts.push(data.data);\n const streamedContent = contentParts.join(\"\");\n\n setAnswer((prev) => {\n const newAnswers = [...prev];\n newAnswers[streamingAnswerIndex] = {\n text: streamedContent,\n answer: true,\n sources,\n };\n return newAnswers;\n });\n } else if (data.type === \"error\") {\n throw new Error(data.data);\n } else if (data.type === \"done\") {\n const streamedContent = contentParts.join(\"\");\n let mdxSource: MDXRemoteSerializeResult | null = null;\n try {\n mdxSource = await serialize(streamedContent, {\n parseFrontmatter: false,\n mdxOptions: {\n remarkPlugins: [remarkGfm],\n rehypePlugins: [rehypeHighlight],\n format: \"md\",\n development: false,\n },\n });\n } catch (mdxError: unknown) {\n console.error(\"MDX serialization error:\", mdxError);\n }\n\n setAnswer((prev) => {\n const newAnswers = [...prev];\n newAnswers[streamingAnswerIndex] = {\n text: streamedContent,\n answer: true,\n mdx: mdxSource || undefined,\n sources,\n };\n return newAnswers;\n });\n }\n } catch (parseError) {\n if (\n parseError instanceof Error &&\n parseError.message !== \"Unknown error\"\n ) {\n console.error(\"Failed to parse SSE data:\", parseError);\n }\n }\n }\n }\n }\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === \"AbortError\") return;\n setError(err instanceof Error ? err.message : \"Unknown error\");\n } finally {\n abortRef.current = null;\n setLoading(false);\n }\n }\n\n async function ask(e: React.FormEvent) {\n e.preventDefault();\n if (loading || question.trim() === \"\") return;\n await runQuestion(question);\n }\n\n // Bridge from the search modal: hand the typed query to the assistant. If a\n // response is already streaming (loading), we can't submit yet - open the\n // panel and pre-fill the input so the user can send it the moment the\n // current answer finishes. Otherwise submit it right away.\n function askAssistant(rawQuestion: string) {\n const trimmed = rawQuestion.trim();\n if (trimmed === \"\") return;\n if (loading) {\n openChat();\n setQuestion(trimmed);\n } else {\n void runQuestion(trimmed);\n }\n }\n\n function closeChat() {\n setIsOpen(false);\n }\n\n function resetChat() {\n abortRef.current?.abort();\n setLoading(false);\n setError(null);\n setAnswer([{ text: INITIAL_GREETING, answer: true }]);\n }\n\n return (\n <ChatContext.Provider\n value={{\n isOpen,\n setIsOpen,\n toggleChat,\n isChatActive,\n question,\n setQuestion,\n loading,\n error,\n answer,\n setAnswer,\n ask,\n askAssistant,\n closeChat,\n resetChat,\n chatInputRef,\n }}\n >\n {children}\n </ChatContext.Provider>\n );\n};\n\nexport { Chat, ChtProvider, ChatContext, ChatButtonCTA };\n";
|
|
1
|
+
export declare const chatTemplate = "\"use client\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport styled, { css, keyframes } from \"styled-components\";\nimport { Button, IconButton } from \"cherry-styled-components\";\nimport { ArrowUp, LoaderPinwheel, RotateCcw, Sparkles, X } from \"lucide-react\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport { MDXRemote, MDXRemoteSerializeResult } from \"next-mdx-remote\";\nimport { serialize } from \"next-mdx-remote/serialize\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\nimport { useMDXComponents as getMDXComponents } from \"@/components/MDXComponents\";\nimport {\n styledAnchor,\n styledTable,\n stylesLists,\n StyledSmallButton,\n interactiveStyles,\n thinScrollbar,\n} from \"@/components/layout/SharedStyled\";\n\nconst mdxComponents = getMDXComponents({});\n\nconst styledText = css<{ theme: Theme }>`\n font-size: ${({ theme }) => theme.fontSizes.text.xs};\n line-height: ${({ theme }) => theme.lineHeights.text.xs};\n\n ${mq(\"lg\")} {\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: ${({ theme }) => theme.lineHeights.small.lg};\n }\n`;\n\nconst StyledChat = styled.div<{ theme: Theme; $isVisible: boolean }>`\n margin: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 100%;\n height: calc(100dvh - 90px);\n overflow-y: scroll;\n overflow-x: hidden;\n z-index: 1000;\n padding: 0 20px;\n transition: all 0.3s ease;\n transform: translateX(0);\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n opacity: 1;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${({ $isVisible }) =>\n !$isVisible &&\n css`\n transform: translateX(100%);\n opacity: 0;\n `}\n\n ${mq(\"lg\")} {\n width: 420px;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n }\n`;\n\nconst loadingAnimation = keyframes`\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n`;\n\nconst rotateGradient = keyframes`\n 0% {\n --gradient-angle: 0deg;\n }\n 100% {\n --gradient-angle: 360deg;\n }\n`;\n\nconst pulseGlow = keyframes`\n 0%, 100% {\n opacity: 0.5;\n filter: blur(16px);\n }\n 50% {\n opacity: 1;\n filter: blur(22px);\n }\n`;\n\nconst sparkleFloat = keyframes`\n 0%, 100% {\n opacity: 0;\n transform: translateY(0) scale(0);\n }\n 50% {\n opacity: 0.9;\n transform: translateY(-20px) scale(1);\n }\n`;\n\nconst shimmer = keyframes`\n 0% {\n background-position: 0% center;\n }\n 50% {\n background-position: 100% center;\n }\n 100% {\n background-position: 0% center;\n }\n`;\n\nconst StyledRainbowInputWrapper = styled.div<{\n theme: Theme;\n $isActive: boolean;\n}>`\n @property --gradient-angle {\n syntax: \"<angle>\";\n initial-value: 0deg;\n inherits: false;\n }\n\n position: relative;\n flex: 1;\n\n &::before {\n content: \"\";\n position: absolute;\n inset: -2px;\n border-radius: 14px;\n background: conic-gradient(\n from var(--gradient-angle),\n #cc5555,\n #d9a745,\n #3ab0cc,\n #cc7fc2,\n #4380cc,\n #4c1fa3,\n #cc5555\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation: ${rotateGradient} 3s linear infinite;\n z-index: 0;\n }\n\n &::after {\n content: \"\";\n position: absolute;\n inset: -10px;\n border-radius: 20px;\n background: conic-gradient(\n from var(--gradient-angle),\n #ff6b6b66,\n #feca5766,\n #48dbfb66,\n #ff9ff366,\n #54a0ff66,\n #5f27cd66,\n #ff6b6b66\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation:\n ${rotateGradient} 3s linear infinite,\n ${pulseGlow} 2s ease-in-out infinite;\n z-index: -1;\n pointer-events: none;\n }\n\n &:hover::before,\n &:focus-within::before {\n opacity: 1;\n }\n\n &:hover::after,\n &:focus-within::after {\n opacity: 1;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n opacity: 1;\n }\n &::after {\n opacity: 1;\n }\n `}\n`;\n\nconst StyledSparkleContainer = styled.div<{ $isActive: boolean }>`\n position: absolute;\n inset: -30px;\n pointer-events: none;\n overflow: hidden;\n border-radius: 30px;\n z-index: -2;\n opacity: 0;\n transition: opacity 0.4s ease;\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n opacity: 1;\n `}\n`;\n\nconst StyledSparkle = styled.div<{\n $color: string;\n $left: number;\n $top: number;\n $delay: number;\n}>`\n position: absolute;\n width: 4px;\n height: 4px;\n border-radius: 50%;\n background: ${({ $color }) => $color};\n box-shadow: 0 0 6px ${({ $color }) => $color};\n left: ${({ $left }) => $left}%;\n top: ${({ $top }) => $top}%;\n animation: ${sparkleFloat} 2s ease-in-out infinite;\n animation-delay: ${({ $delay }) => $delay}s;\n`;\n\nconst StyledRainbowInput = styled.input<{ theme: Theme }>`\n position: relative;\n z-index: 1;\n width: 100%;\n background: ${({ theme }) => theme.colors.light};\n border: 1px solid ${({ theme }) => theme.colors.grayLight};\n border-radius: 12px;\n padding: 12px 18px;\n font-size: ${({ theme }) => theme.fontSizes.text.lg};\n font-family: inherit;\n color: ${({ theme }) => theme.colors.dark};\n outline: none;\n transition:\n border-color 0.3s ease,\n box-shadow 0.3s ease;\n\n ${mq(\"lg\")} {\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n }\n\n &::placeholder {\n color: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.dark} 40%, transparent)`};\n transition: color 0.3s ease;\n }\n\n &:focus::placeholder {\n color: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.dark} 60%, transparent)`};\n }\n\n &:focus {\n border-color: transparent;\n }\n`;\n\nconst StyledRainbowButton = styled(Button)<{\n theme: Theme;\n $hasContent: boolean;\n}>`\n padding-top: 10px;\n padding-bottom: 10px;\n position: relative;\n overflow: hidden;\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;\n color: ${({ theme }) => theme.colors.surface};\n\n &::before {\n content: \"\";\n position: absolute;\n inset: 0;\n background: linear-gradient(\n 135deg,\n #ff6b6b,\n #feca57,\n #48dbfb,\n #ff9ff3,\n #54a0ff\n );\n background-size: 300% 300%;\n opacity: 0;\n transition: opacity 0.3s ease;\n z-index: 0;\n animation: ${shimmer} 3s linear infinite;\n width: 200%;\n }\n\n ${({ $hasContent }) =>\n $hasContent &&\n css`\n &::before {\n opacity: 1;\n }\n `}\n\n &:hover::before {\n opacity: 1;\n }\n\n &:hover {\n transform: scale(1.05);\n }\n\n &:active {\n transform: scale(0.95);\n }\n\n & svg {\n position: relative;\n z-index: 1;\n transition: transform 0.3s ease;\n }\n\n &:disabled,\n &:disabled:hover {\n background: ${({ theme }) => theme.colors.primaryDark};\n transform: none;\n box-shadow: none;\n\n &::before {\n opacity: 0;\n }\n }\n`;\n\nconst StyledChatForm = styled.form<{ theme: Theme; $isVisible: boolean }>`\n display: flex;\n gap: 10px;\n justify-content: center;\n align-items: center;\n background: ${({ theme }) => theme.colors.light};\n padding: 20px;\n position: fixed;\n bottom: 0;\n right: 0;\n z-index: 1000;\n width: 100%;\n border-top: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: all 0.3s ease;\n transform: translateX(100%);\n opacity: 0;\n\n ${mq(\"lg\")} {\n width: 420px;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n }\n\n ${({ $isVisible }) =>\n $isVisible &&\n css`\n opacity: 1;\n transform: translateX(0);\n `}\n\n & .loading {\n animation: ${loadingAnimation} 1s linear infinite;\n }\n`;\n\nconst StyledGlowSmallButton = styled(StyledSmallButton)<{\n theme: Theme;\n $hasContent: boolean;\n}>`\n @property --gradient-angle {\n syntax: \"<angle>\";\n initial-value: 0deg;\n inherits: false;\n }\n\n position: relative;\n isolation: isolate;\n margin-right: 0;\n background: ${({ theme }) => theme.colors.light};\n padding: 0;\n\n &::before {\n content: \"\";\n inset: -2px;\n border-radius: 8px;\n background: conic-gradient(\n from var(--gradient-angle),\n #cc5555,\n #d9a745,\n #3ab0cc,\n #cc7fc2,\n #4380cc,\n #4c1fa3,\n #cc5555\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation: ${rotateGradient} 3s linear infinite;\n z-index: -1;\n position: absolute;\n top: -2px;\n left: -2px;\n width: calc(100% + 4px);\n height: calc(100% + 4px);\n }\n\n &::after {\n content: \"\";\n position: absolute;\n inset: -8px;\n border-radius: 14px;\n background: conic-gradient(\n from var(--gradient-angle),\n #ff6b6b66,\n #feca5766,\n #48dbfb66,\n #ff9ff366,\n #54a0ff66,\n #5f27cd66,\n #ff6b6b66\n );\n opacity: 0;\n transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);\n animation:\n ${rotateGradient} 3s linear infinite,\n ${pulseGlow} 2s ease-in-out infinite;\n z-index: -2;\n pointer-events: none;\n }\n\n &:hover::before,\n &:hover::after {\n opacity: 1;\n }\n\n & span {\n padding: 6px 8px;\n display: flex;\n background: ${({ theme }) => theme.colors.light};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n gap: 6px;\n }\n\n ${({ $hasContent }) =>\n $hasContent &&\n css`\n &::before {\n opacity: 1;\n }\n &::after {\n opacity: 1;\n }\n `}\n`;\n\nconst StyledError = styled.div<{ theme: Theme }>`\n overflow-x: auto;\n ${thinScrollbar};\n background: ${({ theme }) => theme.colors.error};\n color: ${({ theme }) => theme.colors.surface};\n padding: 10px;\n border-radius: 8px;\n margin: 20px 0;\n width: 100%;\n ${styledText};\n`;\n\nconst loadingDotAnimation = keyframes`\n 0% {\n opacity: 0;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n`;\n\nconst StyledLoading = styled.div<{ theme: Theme }>`\n overflow-x: auto;\n ${thinScrollbar};\n margin: 20px 0;\n width: 100%;\n font-weight: 600;\n ${styledText};\n color: ${({ theme }) => theme.colors.dark};\n\n & span {\n &:nth-child(1) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n }\n &:nth-child(2) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n animation-delay: 0.2s;\n }\n &:nth-child(3) {\n animation: ${loadingDotAnimation} 1s ease infinite;\n animation-delay: 0.4s;\n }\n }\n`;\n\nconst StyledAnswer = styled.div<{ theme: Theme; $isAnswer: boolean }>`\n overflow-x: auto;\n ${thinScrollbar};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n padding: 9px 14px;\n border-radius: 16px 16px 4px 16px;\n margin: 20px 0 20px auto;\n width: fit-content;\n max-width: min(560px, 88%);\n font-weight: 500;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n ${styledText};\n\n & p {\n ${styledText};\n }\n\n ${({ $isAnswer }) =>\n $isAnswer &&\n css`\n background: transparent;\n color: ${({ theme }) => theme.colors.dark};\n padding: 0;\n width: 100%;\n max-width: 100%;\n margin: 20px 0;\n border-radius: 0;\n font-weight: inherit;\n white-space: normal;\n `}\n\n & code:not([class]) {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n white-space: pre;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & pre,\n & .hljs {\n margin: 10px 0;\n }\n\n & .code-wrapper pre {\n margin: 0;\n ${styledText};\n }\n\n & > *:first-child {\n margin-top: 0;\n }\n\n & > *:last-child {\n margin-bottom: 0;\n\n & > *:last-child {\n margin-bottom: 0;\n }\n }\n\n & ul,\n & ol {\n & li {\n ${styledText};\n }\n }\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n margin: 10px 0;\n display: block;\n }\n\n & h1,\n & h2,\n & h3,\n & h4,\n & h5,\n & h6 {\n margin: 10px 0;\n padding: 0;\n }\n`;\n\nconst StyledSources = styled.div`\n display: flex;\n gap: 16px;\n flex-wrap: wrap;\n margin: -5px 0 20px;\n`;\n\nconst StyledSourceLink = styled(Link)<{ theme: Theme }>`\n position: relative;\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1;\n color: ${({ theme }) => theme.colors.primary};\n display: flex;\n gap: 6px;\n transition: all 0.3s ease;\n font-weight: 600;\n white-space: nowrap;\n min-width: fit-content;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 10%, transparent)`};\n padding: 6px 8px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n ${interactiveStyles};\n\n & * {\n margin: auto 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n }\n`;\n\nconst StyledChatTitle = styled.div<{ theme: Theme }>`\n display: flex;\n flex-wrap: nowrap;\n justify-content: space-between;\n position: sticky;\n margin: 0 -20px;\n padding: 16px 20px;\n height: 62px;\n top: 0;\n background: ${({ theme }) => theme.colors.light};\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n z-index: 1000;\n`;\n\nconst StyledChatTitleIconWrapper = styled.span<{ theme: Theme }>`\n display: flex;\n align-items: center;\n gap: 12px;\n color: ${({ theme }) => theme.colors.dark};\n`;\n\ntype Source = {\n id: string;\n path: string;\n uri: string;\n score: number;\n};\n\ntype Answer = {\n text: string;\n answer?: boolean;\n mdx?: MDXRemoteSerializeResult;\n sources?: Source[];\n};\n\nconst SPARKLE_COLORS = [\n \"#ff6b6b\",\n \"#feca57\",\n \"#48dbfb\",\n \"#ff9ff3\",\n \"#54a0ff\",\n \"#5f27cd\",\n];\n\n// Deterministic sparkle positions to avoid hydration mismatch\nconst SPARKLE_POSITIONS = [\n { left: 8, top: 35 },\n { left: 17, top: 55 },\n { left: 26, top: 28 },\n { left: 35, top: 68 },\n { left: 44, top: 42 },\n { left: 53, top: 75 },\n { left: 62, top: 32 },\n { left: 71, top: 58 },\n { left: 80, top: 45 },\n { left: 89, top: 65 },\n];\n\ninterface RainbowInputProps {\n id?: string;\n value: string;\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n placeholder?: string;\n autoComplete?: string;\n \"aria-label\"?: string;\n inputRef?: React.Ref<HTMLInputElement>;\n}\n\nfunction RainbowInput({\n id,\n value,\n onChange,\n placeholder,\n autoComplete,\n \"aria-label\": ariaLabel,\n inputRef,\n}: RainbowInputProps) {\n const [isFocused, setIsFocused] = useState(false);\n const [isHovered, setIsHovered] = useState(false);\n const isActive = isFocused || isHovered;\n\n const sparkles = SPARKLE_POSITIONS.map((pos, i) => ({\n color: SPARKLE_COLORS[i % SPARKLE_COLORS.length],\n left: pos.left,\n top: pos.top,\n delay: i * 0.12,\n }));\n\n return (\n <StyledRainbowInputWrapper\n $isActive={isActive}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <StyledSparkleContainer $isActive={isActive}>\n {sparkles.map((sparkle, i) => (\n <StyledSparkle\n key={i}\n $color={sparkle.color}\n $left={sparkle.left}\n $top={sparkle.top}\n $delay={sparkle.delay}\n />\n ))}\n </StyledSparkleContainer>\n <StyledRainbowInput\n ref={inputRef}\n id={id}\n value={value}\n onChange={onChange}\n placeholder={placeholder}\n autoComplete={autoComplete}\n aria-label={ariaLabel}\n onFocus={() => setIsFocused(true)}\n onBlur={() => setIsFocused(false)}\n />\n </StyledRainbowInputWrapper>\n );\n}\n\nfunction ChatButtonCTA() {\n const { toggleChat, isOpen } = useContext(ChatContext);\n\n return (\n <StyledGlowSmallButton\n onClick={toggleChat}\n aria-label=\"Ask AI Assistant\"\n $hasContent={isOpen}\n type=\"button\"\n >\n <span>\n <Sparkles size={16} />\n Ask AI\n </span>\n </StyledGlowSmallButton>\n );\n}\n\nfunction Chat() {\n const {\n isOpen,\n question,\n setQuestion,\n loading,\n error,\n answer,\n ask,\n closeChat,\n resetChat,\n chatInputRef,\n } = useContext(ChatContext);\n const endRef = useRef<HTMLDivElement | null>(null);\n\n useLockBodyScroll(isOpen);\n\n useEffect(() => {\n endRef.current?.scrollIntoView({ behavior: \"smooth\", block: \"end\" });\n }, [answer]);\n\n useEffect(() => {\n if (answer?.length > 0) {\n chatInputRef.current?.focus();\n }\n }, [answer, chatInputRef]);\n\n return (\n <>\n <StyledChat $isVisible={isOpen} data-markdown-ignore>\n <StyledChatTitle>\n <StyledChatTitleIconWrapper>\n <Sparkles />\n <h3>AI Assistant</h3>\n </StyledChatTitleIconWrapper>\n <StyledChatTitleIconWrapper>\n <IconButton\n onClick={resetChat}\n aria-label=\"Reset chat history\"\n title=\"Reset chat history\"\n >\n <RotateCcw />\n </IconButton>\n <IconButton\n onClick={closeChat}\n aria-label=\"Close chat\"\n title=\"Close chat\"\n >\n <X />\n </IconButton>\n </StyledChatTitleIconWrapper>\n </StyledChatTitle>\n {answer &&\n answer.map((a, i) => (\n <React.Fragment key={i}>\n <StyledAnswer $isAnswer={a.answer ?? false}>\n {a.answer && a.mdx ? (\n <MDXRemote {...a.mdx} components={mdxComponents} />\n ) : (\n a.text\n )}\n </StyledAnswer>\n {a.answer && a.sources && a.sources.length > 0 && (\n <StyledSources>\n {a.sources.map((src) => {\n const slug = src.uri\n .replace(\"docs://\", \"\")\n .replace(/^\\/+/, \"\");\n const href = slug ? `/${slug}/` : \"/\";\n const label = slug\n ? slug\n .split(\"/\")\n .pop()!\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (c: string) => c.toUpperCase())\n : \"Home\";\n return (\n <StyledSourceLink\n key={src.id}\n href={href}\n onClick={() => {\n if (window.innerWidth <= 992) {\n closeChat();\n }\n }}\n >\n {label}\n </StyledSourceLink>\n );\n })}\n </StyledSources>\n )}\n </React.Fragment>\n ))}\n {loading && !answer[answer.length - 1]?.answer && (\n <StyledLoading>\n Answering<span>.</span>\n <span>.</span>\n <span>.</span>\n </StyledLoading>\n )}\n {error && (\n <StyledError>\n <strong>Error:</strong> {error}\n </StyledError>\n )}\n <div ref={endRef} />\n </StyledChat>\n\n <StyledChatForm onSubmit={ask} $isVisible={isOpen} data-markdown-ignore>\n <RainbowInput\n id=\"chat-bottom-input\"\n inputRef={chatInputRef}\n value={question}\n onChange={(e) => setQuestion(e.target.value)}\n placeholder=\"Ask AI Assistant...\"\n autoComplete=\"off\"\n aria-label=\"Ask a follow-up question\"\n />\n <StyledRainbowButton\n type=\"submit\"\n disabled={loading || question.trim() === \"\"}\n $hasContent={question.trim().length > 0}\n aria-label={loading ? \"Loading response\" : \"Submit question\"}\n >\n {loading ? <LoaderPinwheel className=\"loading\" /> : <ArrowUp />}\n </StyledRainbowButton>\n </StyledChatForm>\n </>\n );\n}\n\nconst ChatContext = createContext<{\n isOpen: boolean;\n setIsOpen: (isOpen: boolean) => void;\n toggleChat: () => void;\n isChatActive: boolean;\n question: string;\n setQuestion: (q: string) => void;\n loading: boolean;\n error: string | null;\n answer: Answer[];\n setAnswer: (answers: Answer[]) => void;\n ask: (e: React.FormEvent) => void;\n askAssistant: (question: string) => void;\n closeChat: () => void;\n resetChat: () => void;\n chatInputRef: React.RefObject<HTMLInputElement | null>;\n}>({\n isOpen: false,\n setIsOpen: () => {},\n toggleChat: () => {},\n isChatActive: false,\n question: \"\",\n setQuestion: () => {},\n loading: false,\n error: null,\n answer: [],\n setAnswer: () => {},\n ask: () => {},\n askAssistant: () => {},\n closeChat: () => {},\n resetChat: () => {},\n chatInputRef: { current: null },\n});\n\ninterface ChatContextProviderProps {\n children: React.ReactNode;\n isChatActive: boolean;\n}\n\nconst INITIAL_GREETING = \"Hey there, how can I assist you?\";\n\nconst ChtProvider = ({ children, isChatActive }: ChatContextProviderProps) => {\n const [isOpen, setIsOpen] = useState(false);\n const [question, setQuestion] = useState(\"\");\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [answer, setAnswer] = useState<Answer[]>([]);\n const abortRef = useRef<AbortController | null>(null);\n const chatInputRef = useRef<HTMLInputElement | null>(null);\n const isOpenRef = useRef(isOpen);\n\n useEffect(() => {\n isOpenRef.current = isOpen;\n }, [isOpen]);\n\n // Open the assistant, seeding a greeting the first time and focusing the\n // input once the panel has slid in (matches the 0.3s panel transition).\n const openChat = useCallback(() => {\n setIsOpen(true);\n setAnswer((prev) =>\n prev.length === 0 ? [{ text: INITIAL_GREETING, answer: true }] : prev,\n );\n setTimeout(() => {\n chatInputRef.current?.focus();\n }, 350);\n }, []);\n\n const toggleChat = useCallback(() => {\n if (isOpenRef.current) {\n setIsOpen(false);\n } else {\n openChat();\n }\n }, [openChat]);\n\n // Global Cmd/Ctrl+I toggles the assistant, but only when chat is enabled.\n useEffect(() => {\n if (!isChatActive) return;\n function handleKeyDown(e: KeyboardEvent) {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"i\") {\n e.preventDefault();\n toggleChat();\n }\n }\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [isChatActive, toggleChat]);\n\n async function runQuestion(currentQuestion: string) {\n setQuestion(\"\");\n setIsOpen(true);\n setLoading(true);\n setError(null);\n\n const base =\n answer.length > 0 ? answer : [{ text: INITIAL_GREETING, answer: true }];\n const mergedQuestions = [...base, { text: currentQuestion, answer: false }];\n\n setAnswer(mergedQuestions);\n\n const controller = new AbortController();\n abortRef.current = controller;\n\n try {\n const history = answer\n .filter((a) => a.text.trim() !== \"\")\n .map((a) => ({\n role: a.answer ? (\"assistant\" as const) : (\"user\" as const),\n content: a.text,\n }));\n\n const res = await fetch(\"/api/rag\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ question: currentQuestion, history }),\n signal: controller.signal,\n });\n\n if (!res.ok) {\n // The body may be a proxy/gateway HTML error page (e.g. Cloudflare\n // 524), not our JSON - never blindly JSON.parse it.\n const contentType = res.headers.get(\"content-type\") || \"\";\n let message = \"Request failed\";\n if (contentType.includes(\"application/json\")) {\n try {\n const errorData = await res.json();\n message = errorData.error || message;\n } catch {\n // Non-JSON despite the header - fall through to the default.\n }\n } else if ([502, 503, 504, 524].includes(res.status)) {\n message = \"The assistant took too long to respond. Please try again.\";\n }\n throw new Error(message);\n }\n\n const reader = res.body?.getReader();\n const decoder = new TextDecoder();\n const contentParts: string[] = [];\n let sources: Source[] = [];\n if (!reader) {\n throw new Error(\"Failed to get response reader\");\n }\n\n // Don't insert the answer bubble yet - an empty bubble renders a blank\n // gap above the \"Answering...\" loader. The bubble is created on the first\n // streamed token (or the done event) instead, so the loader stays put\n // until real text appears.\n const streamingAnswerIndex = mergedQuestions.length;\n\n let buffer = \"\";\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const parts = buffer.split(\"\\n\");\n buffer = parts.pop() ?? \"\";\n\n for (const line of parts) {\n if (line.startsWith(\"data: \")) {\n try {\n const data = JSON.parse(line.slice(6));\n\n if (data.type === \"metadata\") {\n const allSources: Source[] = data.data?.sources ?? [];\n const seen = new Set<string>();\n sources = allSources.filter((s: Source) => {\n if (s.score < 0.4 || seen.has(s.uri)) return false;\n seen.add(s.uri);\n return true;\n });\n } else if (data.type === \"content\") {\n contentParts.push(data.data);\n const streamedContent = contentParts.join(\"\");\n\n setAnswer((prev) => {\n const newAnswers = [...prev];\n newAnswers[streamingAnswerIndex] = {\n text: streamedContent,\n answer: true,\n sources,\n };\n return newAnswers;\n });\n } else if (data.type === \"error\") {\n throw new Error(data.data);\n } else if (data.type === \"done\") {\n const streamedContent = contentParts.join(\"\");\n let mdxSource: MDXRemoteSerializeResult | null = null;\n try {\n mdxSource = await serialize(streamedContent, {\n parseFrontmatter: false,\n mdxOptions: {\n remarkPlugins: [remarkGfm],\n rehypePlugins: [rehypeHighlight],\n format: \"md\",\n development: false,\n },\n });\n } catch (mdxError: unknown) {\n console.error(\"MDX serialization error:\", mdxError);\n }\n\n setAnswer((prev) => {\n const newAnswers = [...prev];\n newAnswers[streamingAnswerIndex] = {\n text: streamedContent,\n answer: true,\n mdx: mdxSource || undefined,\n sources,\n };\n return newAnswers;\n });\n }\n } catch (parseError) {\n if (\n parseError instanceof Error &&\n parseError.message !== \"Unknown error\"\n ) {\n console.error(\"Failed to parse SSE data:\", parseError);\n }\n }\n }\n }\n }\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === \"AbortError\") return;\n setError(err instanceof Error ? err.message : \"Unknown error\");\n } finally {\n abortRef.current = null;\n setLoading(false);\n }\n }\n\n async function ask(e: React.FormEvent) {\n e.preventDefault();\n if (loading || question.trim() === \"\") return;\n await runQuestion(question);\n }\n\n // Bridge from the search modal: hand the typed query to the assistant. If a\n // response is already streaming (loading), we can't submit yet - open the\n // panel and pre-fill the input so the user can send it the moment the\n // current answer finishes. Otherwise submit it right away.\n function askAssistant(rawQuestion: string) {\n const trimmed = rawQuestion.trim();\n if (trimmed === \"\") return;\n if (loading) {\n openChat();\n setQuestion(trimmed);\n } else {\n void runQuestion(trimmed);\n }\n }\n\n function closeChat() {\n setIsOpen(false);\n }\n\n function resetChat() {\n abortRef.current?.abort();\n setLoading(false);\n setError(null);\n setAnswer([{ text: INITIAL_GREETING, answer: true }]);\n }\n\n return (\n <ChatContext.Provider\n value={{\n isOpen,\n setIsOpen,\n toggleChat,\n isChatActive,\n question,\n setQuestion,\n loading,\n error,\n answer,\n setAnswer,\n ask,\n askAssistant,\n closeChat,\n resetChat,\n chatInputRef,\n }}\n >\n {children}\n </ChatContext.Provider>\n );\n};\n\nexport { Chat, ChtProvider, ChatContext, ChatButtonCTA };\n";
|
|
@@ -814,7 +814,7 @@ function Chat() {
|
|
|
814
814
|
|
|
815
815
|
return (
|
|
816
816
|
<>
|
|
817
|
-
<StyledChat $isVisible={isOpen}>
|
|
817
|
+
<StyledChat $isVisible={isOpen} data-markdown-ignore>
|
|
818
818
|
<StyledChatTitle>
|
|
819
819
|
<StyledChatTitleIconWrapper>
|
|
820
820
|
<Sparkles />
|
|
@@ -894,7 +894,7 @@ function Chat() {
|
|
|
894
894
|
<div ref={endRef} />
|
|
895
895
|
</StyledChat>
|
|
896
896
|
|
|
897
|
-
<StyledChatForm onSubmit={ask} $isVisible={isOpen}>
|
|
897
|
+
<StyledChatForm onSubmit={ask} $isVisible={isOpen} data-markdown-ignore>
|
|
898
898
|
<RainbowInput
|
|
899
899
|
id="chat-bottom-input"
|
|
900
900
|
inputRef={chatInputRef}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const docsSideBarTemplate = "\"use client\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Space } from \"cherry-styled-components\";\nimport {\n StyledIndexSidebar,\n StyledIndexSidebarLink,\n StyledIndexSidebarLabel,\n StyledIndexSidebarLi,\n} from \"@/components/layout/DocsComponents\";\n\ninterface Heading {\n id: string;\n text: string;\n level: number;\n}\n\nconst FALLBACK_OFFSET = 60;\n\nfunction getOffset() {\n const header = document.getElementById(\"header\");\n return (header ? header.offsetHeight : FALLBACK_OFFSET) + 20;\n}\n\nexport function DocsSideBar({ headings }: { headings: Heading[] }) {\n const [activeId, setActiveId] = useState<string>(\"\");\n const activeRef = useRef<HTMLLIElement>(null);\n\n const handleScroll = useCallback(() => {\n if (headings.length === 0) return;\n\n const headingElements = headings\n .map((heading) => document.getElementById(heading.id))\n .filter((el): el is HTMLElement => el !== null);\n\n if (headingElements.length === 0) return;\n\n const windowHeight = window.innerHeight;\n\n const visibleHeadings = headingElements.filter((element) => {\n const rect = element.getBoundingClientRect();\n const elementTop = rect.top;\n const elementBottom = rect.bottom;\n return elementTop < windowHeight && elementBottom > -50;\n });\n\n if (visibleHeadings.length > 0) {\n let closestHeading = visibleHeadings[0];\n let closestDistance = Math.abs(\n closestHeading.getBoundingClientRect().top - getOffset(),\n );\n for (const heading of visibleHeadings) {\n const distance = Math.abs(\n heading.getBoundingClientRect().top - getOffset(),\n );\n if (\n distance < closestDistance &&\n heading.getBoundingClientRect().top <= windowHeight * 0.3\n ) {\n closestDistance = distance;\n closestHeading = heading;\n }\n }\n setActiveId(closestHeading.id);\n return;\n }\n\n let currentActiveId = headings[0].id;\n for (const element of headingElements) {\n const rect = element.getBoundingClientRect();\n if (rect.top <= getOffset()) {\n currentActiveId = element.id;\n } else {\n break;\n }\n }\n setActiveId(currentActiveId);\n }, [headings]);\n\n useEffect(() => {\n if (headings.length === 0) return;\n // Set active heading from URL hash immediately on mount (deferred to next frame)\n const hashId = window.location.hash ? window.location.hash.slice(1) : null;\n // Run initial scroll check on next frame to avoid synchronous setState in effect\n const rafId = requestAnimationFrame(() => {\n if (hashId) {\n setActiveId(hashId);\n }\n handleScroll();\n });\n // Re-check after browser finishes scrolling to hash target on new page load\n const delayedId = setTimeout(handleScroll, 300);\n let timeoutId: NodeJS.Timeout;\n const throttledHandleScroll = () => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(handleScroll, 50);\n };\n window.addEventListener(\"scroll\", throttledHandleScroll);\n window.addEventListener(\"resize\", handleScroll);\n return () => {\n window.removeEventListener(\"scroll\", throttledHandleScroll);\n window.removeEventListener(\"resize\", handleScroll);\n cancelAnimationFrame(rafId);\n clearTimeout(delayedId);\n clearTimeout(timeoutId);\n };\n }, [handleScroll, headings]);\n\n useEffect(() => {\n const el = activeRef.current;\n const container = el?.closest(\"[data-sidebar]\") as HTMLElement | null;\n if (!el || !container) return;\n const elRect = el.getBoundingClientRect();\n const cRect = container.getBoundingClientRect();\n const pad = 140;\n // Animate the scroll, but honor users who opt out of motion.\n const behavior = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n .matches\n ? \"auto\"\n : \"smooth\";\n if (elRect.bottom + pad > cRect.bottom) {\n container.scrollBy({\n top: elRect.bottom - cRect.bottom + pad,\n behavior,\n });\n } else if (elRect.top - pad < cRect.top) {\n container.scrollBy({\n top: elRect.top - cRect.top - pad,\n behavior,\n });\n }\n }, [activeId]);\n\n const handleHeadingClick = (headingId: string) => {\n const element = document.getElementById(headingId);\n if (element) {\n const elementPosition =\n element.getBoundingClientRect().top + window.scrollY;\n window.scrollTo({\n top: elementPosition - getOffset(),\n behavior: \"smooth\",\n });\n }\n };\n\n return (\n <StyledIndexSidebar data-sidebar>\n {headings?.length > 0 && (\n <li aria-hidden=\"true\">\n <StyledIndexSidebarLabel>On this page</StyledIndexSidebarLabel>\n <Space $size={15} />\n </li>\n )}\n {headings.map((heading, index) => (\n <StyledIndexSidebarLi\n key={index}\n ref={activeId === heading.id ? activeRef : null}\n $isActive={activeId === heading.id}\n style={{ paddingLeft: `${(heading.level - 1) * 16}px` }}\n >\n <StyledIndexSidebarLink\n href={`#${heading.id}`}\n onClick={(e) => {\n e.preventDefault();\n handleHeadingClick(heading.id);\n }}\n $isActive={activeId === heading.id}\n >\n {heading.text}\n </StyledIndexSidebarLink>\n </StyledIndexSidebarLi>\n ))}\n </StyledIndexSidebar>\n );\n}\n";
|
|
1
|
+
export declare const docsSideBarTemplate = "\"use client\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Space } from \"cherry-styled-components\";\nimport {\n StyledIndexSidebar,\n StyledIndexSidebarLink,\n StyledIndexSidebarLabel,\n StyledIndexSidebarLi,\n} from \"@/components/layout/DocsComponents\";\n\ninterface Heading {\n id: string;\n text: string;\n level: number;\n}\n\nconst FALLBACK_OFFSET = 60;\n\nfunction getOffset() {\n const header = document.getElementById(\"header\");\n return (header ? header.offsetHeight : FALLBACK_OFFSET) + 20;\n}\n\nexport function DocsSideBar({ headings }: { headings: Heading[] }) {\n const [activeId, setActiveId] = useState<string>(\"\");\n const activeRef = useRef<HTMLLIElement>(null);\n\n const handleScroll = useCallback(() => {\n if (headings.length === 0) return;\n\n const headingElements = headings\n .map((heading) => document.getElementById(heading.id))\n .filter((el): el is HTMLElement => el !== null);\n\n if (headingElements.length === 0) return;\n\n const windowHeight = window.innerHeight;\n\n const visibleHeadings = headingElements.filter((element) => {\n const rect = element.getBoundingClientRect();\n const elementTop = rect.top;\n const elementBottom = rect.bottom;\n return elementTop < windowHeight && elementBottom > -50;\n });\n\n if (visibleHeadings.length > 0) {\n let closestHeading = visibleHeadings[0];\n let closestDistance = Math.abs(\n closestHeading.getBoundingClientRect().top - getOffset(),\n );\n for (const heading of visibleHeadings) {\n const distance = Math.abs(\n heading.getBoundingClientRect().top - getOffset(),\n );\n if (\n distance < closestDistance &&\n heading.getBoundingClientRect().top <= windowHeight * 0.3\n ) {\n closestDistance = distance;\n closestHeading = heading;\n }\n }\n setActiveId(closestHeading.id);\n return;\n }\n\n let currentActiveId = headings[0].id;\n for (const element of headingElements) {\n const rect = element.getBoundingClientRect();\n if (rect.top <= getOffset()) {\n currentActiveId = element.id;\n } else {\n break;\n }\n }\n setActiveId(currentActiveId);\n }, [headings]);\n\n useEffect(() => {\n if (headings.length === 0) return;\n // Set active heading from URL hash immediately on mount (deferred to next frame)\n const hashId = window.location.hash ? window.location.hash.slice(1) : null;\n // Run initial scroll check on next frame to avoid synchronous setState in effect\n const rafId = requestAnimationFrame(() => {\n if (hashId) {\n setActiveId(hashId);\n }\n handleScroll();\n });\n // Re-check after browser finishes scrolling to hash target on new page load\n const delayedId = setTimeout(handleScroll, 300);\n let timeoutId: NodeJS.Timeout;\n const throttledHandleScroll = () => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(handleScroll, 50);\n };\n window.addEventListener(\"scroll\", throttledHandleScroll);\n window.addEventListener(\"resize\", handleScroll);\n return () => {\n window.removeEventListener(\"scroll\", throttledHandleScroll);\n window.removeEventListener(\"resize\", handleScroll);\n cancelAnimationFrame(rafId);\n clearTimeout(delayedId);\n clearTimeout(timeoutId);\n };\n }, [handleScroll, headings]);\n\n useEffect(() => {\n const el = activeRef.current;\n const container = el?.closest(\"[data-sidebar]\") as HTMLElement | null;\n if (!el || !container) return;\n const elRect = el.getBoundingClientRect();\n const cRect = container.getBoundingClientRect();\n const pad = 140;\n // Animate the scroll, but honor users who opt out of motion.\n const behavior = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n .matches\n ? \"auto\"\n : \"smooth\";\n if (elRect.bottom + pad > cRect.bottom) {\n container.scrollBy({\n top: elRect.bottom - cRect.bottom + pad,\n behavior,\n });\n } else if (elRect.top - pad < cRect.top) {\n container.scrollBy({\n top: elRect.top - cRect.top - pad,\n behavior,\n });\n }\n }, [activeId]);\n\n const handleHeadingClick = (headingId: string) => {\n const element = document.getElementById(headingId);\n if (element) {\n const elementPosition =\n element.getBoundingClientRect().top + window.scrollY;\n window.scrollTo({\n top: elementPosition - getOffset(),\n behavior: \"smooth\",\n });\n }\n };\n\n return (\n <StyledIndexSidebar data-sidebar data-markdown-ignore>\n {headings?.length > 0 && (\n <li aria-hidden=\"true\">\n <StyledIndexSidebarLabel>On this page</StyledIndexSidebarLabel>\n <Space $size={15} />\n </li>\n )}\n {headings.map((heading, index) => (\n <StyledIndexSidebarLi\n key={index}\n ref={activeId === heading.id ? activeRef : null}\n $isActive={activeId === heading.id}\n style={{ paddingLeft: `${(heading.level - 1) * 16}px` }}\n >\n <StyledIndexSidebarLink\n href={`#${heading.id}`}\n onClick={(e) => {\n e.preventDefault();\n handleHeadingClick(heading.id);\n }}\n $isActive={activeId === heading.id}\n >\n {heading.text}\n </StyledIndexSidebarLink>\n </StyledIndexSidebarLi>\n ))}\n </StyledIndexSidebar>\n );\n}\n";
|
|
@@ -143,7 +143,7 @@ export function DocsSideBar({ headings }: { headings: Heading[] }) {
|
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
return (
|
|
146
|
-
<StyledIndexSidebar data-sidebar>
|
|
146
|
+
<StyledIndexSidebar data-sidebar data-markdown-ignore>
|
|
147
147
|
{headings?.length > 0 && (
|
|
148
148
|
<li aria-hidden="true">
|
|
149
149
|
<StyledIndexSidebarLabel>On this page</StyledIndexSidebarLabel>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n // When set, an RSS button linking to this page's feed renders next to the\n // copy pill.\n rssHref?: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// StyledSmallButton carries a -6px right margin for edge alignment; inside\n// the pill group that would eat into the gap, so it is neutralized here.\nconst StyledActionBarGroup = styled.div`\n display: flex;\n gap: 12px;\n\n & > * {\n margin-right: 0;\n }\n`;\n\nconst StyledRssLink = styled(StyledSmallButton)<{ theme: Theme }>`\n text-decoration: none;\n color: ${({ theme }) => theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so
|
|
1
|
+
export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n // When set, an RSS button linking to this page's feed renders next to the\n // copy pill.\n rssHref?: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n display: flex;\n gap: 12px;\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// StyledSmallButton carries a -6px right margin for edge alignment; inside\n// the pill group that would eat into the gap, so it is neutralized here.\nconst StyledActionBarGroup = styled.div`\n display: flex;\n gap: 12px;\n\n & > * {\n margin-right: 0;\n }\n`;\n\nconst StyledRssLink = styled(StyledSmallButton)<{ theme: Theme }>`\n text-decoration: none;\n color: ${({ theme }) => theme.colors.primary};\n padding: 2px 8px;\n\n & svg.lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so every pill\n// on this side of the bar looks identical: interactiveStyles supplies the\n// border highlight + focus/active rings (no scale effect), and the 30px\n// height with a fully rounded radius matches the toggle's knob track.\nconst actionPillStyles = (theme: Theme) => css`\n height: 30px;\n border-radius: 30px;\n display: flex;\n align-items: center;\n margin: auto 0;\n background: ${theme.colors.light};\n border-color: ${theme.colors.grayLight};\n\n & svg {\n width: 16px;\n height: 16px;\n object-fit: contain;\n transition: all 0.3s ease;\n position: relative;\n z-index: 2;\n }\n\n & svg[stroke] {\n stroke: ${theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${theme.colors.accent};\n }\n`;\n\nconst StyledMarkdownLink = styled.a<{ theme: Theme }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 30px;\n justify-content: center;\n text-decoration: none;\n`;\n\n// The space-between layout with 6px padding puts each 16px icon's center\n// exactly where the 24px knob's center sits in its resting (left: 2px) and\n// active (translateX(26px)) positions.\nconst StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n ${({ theme }) => actionPillStyles(theme)}\n width: 56px;\n justify-content: space-between;\n padding: 0 6px;\n position: relative;\n\n &::after {\n content: \"\";\n position: absolute;\n top: 2px;\n left: 2px;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n transition: all 0.3s ease;\n z-index: 1;\n ${({ $isActive }) =>\n !$isActive &&\n css`\n transform: translateX(26px);\n `}\n }\n`;\n\n// The raw-content view renders a full-viewport textarea. That rule is scoped to\n// the raw view (`$raw`) so it never leaks into textareas rendered inside page\n// content - e.g. the API playground's request-body editor, which sits inside\n// this same ActionBar in the normal (view) mode.\nconst StyledContent = styled.div<{\n theme: Theme;\n $hasSectionBar?: boolean;\n $raw?: boolean;\n}>`\n padding-top: 20px;\n transition: all 0.3s ease;\n\n ${({ $raw, $hasSectionBar }) =>\n $raw &&\n css`\n & textarea {\n max-width: 640px;\n margin: auto;\n width: 100%;\n height: 100%;\n min-height: calc(100vh - ${$hasSectionBar ? 202 : 160}px);\n\n ${mq(\"lg\")} {\n min-height: calc(100vh - 159px);\n }\n }\n `}\n`;\n\n// Every page ships a static markdown mirror under public/: \"/\" serves\n// \"/index.md\" and \"/{slug}\" serves \"/{slug}.md\".\nfunction toMarkdownHref(pathname: string) {\n const base = pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n return `${base === \"\" ? \"/index\" : base}.md`;\n}\n\nfunction ActionBar({ children, content, rssHref }: ActionBarProps) {\n const [isView, setIsView] = useState(true);\n const [copied, setCopied] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n\n const handleCopyContent = async () => {\n try {\n await navigator.clipboard.writeText(content);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy:\", err);\n }\n };\n\n return (\n <>\n <StyledActionBar data-markdown-ignore>\n <StyledActionBarGroup>\n <StyledCopyButton onClick={handleCopyContent} $copied={copied}>\n {copied ? (\n <>\n <Icon name=\"check\" size={16} />\n Copied!\n </>\n ) : (\n <>\n <Icon name=\"copy\" size={16} />\n Copy content\n </>\n )}\n </StyledCopyButton>\n {rssHref && (\n <StyledRssLink as=\"a\" href={rssHref} aria-label=\"RSS feed\">\n <Icon name=\"rss\" size={16} />\n RSS\n </StyledRssLink>\n )}\n </StyledActionBarGroup>\n <StyledActionBarContent>\n <StyledMarkdownLink\n href={toMarkdownHref(pathname)}\n aria-label=\"View as Markdown\"\n title=\"View as Markdown\"\n >\n <Icon name=\"FileText\" />\n </StyledMarkdownLink>\n <StyledToggle\n onClick={() => setIsView(!isView)}\n aria-label=\"Toggle View\"\n $isActive={isView}\n >\n <Icon name=\"Eye\" />\n <Icon name=\"CodeXml\" />\n </StyledToggle>\n </StyledActionBarContent>\n </StyledActionBar>\n {isView && (\n <StyledContent $hasSectionBar={hasSectionBar}>{children}</StyledContent>\n )}\n {!isView && (\n <StyledContent $hasSectionBar={hasSectionBar} $raw>\n <Textarea defaultValue={content} $fullWidth />\n </StyledContent>\n )}\n </>\n );\n}\n\nexport { ActionBar };\n";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const actionBarTemplate = `"use client";
|
|
2
2
|
import { useContext, useState } from "react";
|
|
3
|
+
import { usePathname } from "next/navigation";
|
|
3
4
|
import styled, { css } from "styled-components";
|
|
4
5
|
import { Icon } from "@/components/layout/Icon";
|
|
5
6
|
import { mq, Theme } from "@/app/theme";
|
|
@@ -39,6 +40,8 @@ const StyledActionBar = styled.div<{
|
|
|
39
40
|
\`;
|
|
40
41
|
|
|
41
42
|
const StyledActionBarContent = styled.div\`
|
|
43
|
+
display: flex;
|
|
44
|
+
gap: 12px;
|
|
42
45
|
margin: auto 0;
|
|
43
46
|
\`;
|
|
44
47
|
|
|
@@ -72,32 +75,64 @@ const StyledActionBarGroup = styled.div\`
|
|
|
72
75
|
const StyledRssLink = styled(StyledSmallButton)<{ theme: Theme }>\`
|
|
73
76
|
text-decoration: none;
|
|
74
77
|
color: \${({ theme }) => theme.colors.primary};
|
|
78
|
+
padding: 2px 8px;
|
|
75
79
|
|
|
76
80
|
& svg.lucide {
|
|
77
81
|
color: \${({ theme }) => theme.colors.primary};
|
|
78
82
|
}
|
|
79
83
|
\`;
|
|
80
84
|
|
|
81
|
-
// Mirrors the geometry and interaction of Cherry's ThemeToggle so
|
|
82
|
-
//
|
|
83
|
-
// highlight + focus/active rings (no scale effect), and the
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
// (translateX(26px)) positions.
|
|
87
|
-
const StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>\`
|
|
88
|
-
\${resetButton}
|
|
89
|
-
\${interactiveStyles}
|
|
90
|
-
width: 56px;
|
|
85
|
+
// Mirrors the geometry and interaction of Cherry's ThemeToggle so every pill
|
|
86
|
+
// on this side of the bar looks identical: interactiveStyles supplies the
|
|
87
|
+
// border highlight + focus/active rings (no scale effect), and the 30px
|
|
88
|
+
// height with a fully rounded radius matches the toggle's knob track.
|
|
89
|
+
const actionPillStyles = (theme: Theme) => css\`
|
|
91
90
|
height: 30px;
|
|
92
91
|
border-radius: 30px;
|
|
93
92
|
display: flex;
|
|
94
93
|
align-items: center;
|
|
94
|
+
margin: auto 0;
|
|
95
|
+
background: \${theme.colors.light};
|
|
96
|
+
border-color: \${theme.colors.grayLight};
|
|
97
|
+
|
|
98
|
+
& svg {
|
|
99
|
+
width: 16px;
|
|
100
|
+
height: 16px;
|
|
101
|
+
object-fit: contain;
|
|
102
|
+
transition: all 0.3s ease;
|
|
103
|
+
position: relative;
|
|
104
|
+
z-index: 2;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
& svg[stroke] {
|
|
108
|
+
stroke: \${theme.colors.primary};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&:hover svg[stroke] {
|
|
112
|
+
stroke: \${theme.colors.accent};
|
|
113
|
+
}
|
|
114
|
+
\`;
|
|
115
|
+
|
|
116
|
+
const StyledMarkdownLink = styled.a<{ theme: Theme }>\`
|
|
117
|
+
\${resetButton}
|
|
118
|
+
\${interactiveStyles}
|
|
119
|
+
\${({ theme }) => actionPillStyles(theme)}
|
|
120
|
+
width: 30px;
|
|
121
|
+
justify-content: center;
|
|
122
|
+
text-decoration: none;
|
|
123
|
+
\`;
|
|
124
|
+
|
|
125
|
+
// The space-between layout with 6px padding puts each 16px icon's center
|
|
126
|
+
// exactly where the 24px knob's center sits in its resting (left: 2px) and
|
|
127
|
+
// active (translateX(26px)) positions.
|
|
128
|
+
const StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>\`
|
|
129
|
+
\${resetButton}
|
|
130
|
+
\${interactiveStyles}
|
|
131
|
+
\${({ theme }) => actionPillStyles(theme)}
|
|
132
|
+
width: 56px;
|
|
95
133
|
justify-content: space-between;
|
|
96
134
|
padding: 0 6px;
|
|
97
135
|
position: relative;
|
|
98
|
-
margin: auto 0;
|
|
99
|
-
background: \${({ theme }) => theme.colors.light};
|
|
100
|
-
border-color: \${({ theme }) => theme.colors.grayLight};
|
|
101
136
|
|
|
102
137
|
&::after {
|
|
103
138
|
content: "";
|
|
@@ -117,23 +152,6 @@ const StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>\`
|
|
|
117
152
|
transform: translateX(26px);
|
|
118
153
|
\`}
|
|
119
154
|
}
|
|
120
|
-
|
|
121
|
-
& svg {
|
|
122
|
-
width: 16px;
|
|
123
|
-
height: 16px;
|
|
124
|
-
object-fit: contain;
|
|
125
|
-
transition: all 0.3s ease;
|
|
126
|
-
position: relative;
|
|
127
|
-
z-index: 2;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
& svg[stroke] {
|
|
131
|
-
stroke: \${({ theme }) => theme.colors.primary};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
&:hover svg[stroke] {
|
|
135
|
-
stroke: \${({ theme }) => theme.colors.accent};
|
|
136
|
-
}
|
|
137
155
|
\`;
|
|
138
156
|
|
|
139
157
|
// The raw-content view renders a full-viewport textarea. That rule is scoped to
|
|
@@ -165,10 +183,18 @@ const StyledContent = styled.div<{
|
|
|
165
183
|
\`}
|
|
166
184
|
\`;
|
|
167
185
|
|
|
186
|
+
// Every page ships a static markdown mirror under public/: "/" serves
|
|
187
|
+
// "/index.md" and "/{slug}" serves "/{slug}.md".
|
|
188
|
+
function toMarkdownHref(pathname: string) {
|
|
189
|
+
const base = pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
190
|
+
return \`\${base === "" ? "/index" : base}.md\`;
|
|
191
|
+
}
|
|
192
|
+
|
|
168
193
|
function ActionBar({ children, content, rssHref }: ActionBarProps) {
|
|
169
194
|
const [isView, setIsView] = useState(true);
|
|
170
195
|
const [copied, setCopied] = useState(false);
|
|
171
196
|
const hasSectionBar = useContext(SectionBarContext);
|
|
197
|
+
const pathname = usePathname();
|
|
172
198
|
|
|
173
199
|
const handleCopyContent = async () => {
|
|
174
200
|
try {
|
|
@@ -182,7 +208,7 @@ function ActionBar({ children, content, rssHref }: ActionBarProps) {
|
|
|
182
208
|
|
|
183
209
|
return (
|
|
184
210
|
<>
|
|
185
|
-
<StyledActionBar>
|
|
211
|
+
<StyledActionBar data-markdown-ignore>
|
|
186
212
|
<StyledActionBarGroup>
|
|
187
213
|
<StyledCopyButton onClick={handleCopyContent} $copied={copied}>
|
|
188
214
|
{copied ? (
|
|
@@ -205,6 +231,13 @@ function ActionBar({ children, content, rssHref }: ActionBarProps) {
|
|
|
205
231
|
)}
|
|
206
232
|
</StyledActionBarGroup>
|
|
207
233
|
<StyledActionBarContent>
|
|
234
|
+
<StyledMarkdownLink
|
|
235
|
+
href={toMarkdownHref(pathname)}
|
|
236
|
+
aria-label="View as Markdown"
|
|
237
|
+
title="View as Markdown"
|
|
238
|
+
>
|
|
239
|
+
<Icon name="FileText" />
|
|
240
|
+
</StyledMarkdownLink>
|
|
208
241
|
<StyledToggle
|
|
209
242
|
onClick={() => setIsView(!isView)}
|
|
210
243
|
aria-label="Toggle View"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const cardTemplate = "\"use client\";\nimport Link from \"next/link\";\nimport styled, { css, useTheme } from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon, IconProps } from \"@/components/layout/Icon\";\nimport { interactiveStyles } from \"@/components/layout/SharedStyled\";\n\nconst cardStyles = css<{ theme: Theme }>`\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)}\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nconst StyledCard = styled.div<{ theme: Theme }>`\n ${cardStyles}\n`;\n\nconst StyledCardLink = styled(Link)<{ theme: Theme }>`\n ${interactiveStyles};\n ${cardStyles}\n text-decoration: none;\n`;\n\nconst StyledCardTitle = styled.p<{ theme: Theme }>`\n font-weight: bold;\n margin: 0;\n color: ${({ theme }) => theme.colors.dark};\n ${({ theme }) => styledText(theme)};\n`;\n\ninterface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n title?: string;\n icon?: IconProps;\n href?: string;\n}\n\nfunction Card({ children, title, icon, href }: CardProps) {\n const theme = useTheme() as Theme;\n\n const content = (\n <>\n {icon && <Icon name={icon} color={theme.colors.primary} />}\n {title && <StyledCardTitle>{title}</StyledCardTitle>}\n {children}\n </>\n );\n\n if (href) {\n const isExternal = /^(https?:)?\\/\\//i.test(href);\n return (\n <StyledCardLink\n href={href}\n target={isExternal ? \"_blank\" : undefined}\n rel={isExternal ? \"noopener noreferrer\" : undefined}\n >\n {content}\n </StyledCardLink>\n );\n }\n\n return <StyledCard>{content}</StyledCard>;\n}\n\nexport { Card };\n";
|
|
1
|
+
export declare const cardTemplate = "\"use client\";\nimport Link from \"next/link\";\nimport styled, { css, useTheme } from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon, IconProps } from \"@/components/layout/Icon\";\nimport { interactiveStyles } from \"@/components/layout/SharedStyled\";\n\nconst cardStyles = css<{ theme: Theme }>`\n display: flex;\n flex-direction: column;\n gap: 12px;\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)}\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nconst StyledCard = styled.div<{ theme: Theme }>`\n ${cardStyles}\n`;\n\nconst StyledCardLink = styled(Link)<{ theme: Theme }>`\n ${interactiveStyles};\n ${cardStyles}\n text-decoration: none;\n`;\n\nconst StyledCardTitle = styled.p<{ theme: Theme }>`\n font-weight: bold;\n margin: 0;\n color: ${({ theme }) => theme.colors.dark};\n ${({ theme }) => styledText(theme)};\n`;\n\ninterface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n title?: string;\n icon?: IconProps;\n href?: string;\n}\n\nfunction Card({ children, title, icon, href }: CardProps) {\n const theme = useTheme() as Theme;\n\n const content = (\n <>\n {icon && <Icon name={icon} color={theme.colors.primary} />}\n {title && <StyledCardTitle>{title}</StyledCardTitle>}\n {children}\n </>\n );\n\n if (href) {\n const isExternal = /^(https?:)?\\/\\//i.test(href);\n return (\n <StyledCardLink\n href={href}\n target={isExternal ? \"_blank\" : undefined}\n rel={isExternal ? \"noopener noreferrer\" : undefined}\n >\n {content}\n </StyledCardLink>\n );\n }\n\n return <StyledCard>{content}</StyledCard>;\n}\n\nexport { Card };\n";
|
|
@@ -7,6 +7,9 @@ import { Icon, IconProps } from "@/components/layout/Icon";
|
|
|
7
7
|
import { interactiveStyles } from "@/components/layout/SharedStyled";
|
|
8
8
|
|
|
9
9
|
const cardStyles = css<{ theme: Theme }>\`
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
gap: 12px;
|
|
10
13
|
background: \${({ theme }) => theme.colors.light};
|
|
11
14
|
border: solid 1px \${({ theme }) => theme.colors.grayLight};
|
|
12
15
|
border-radius: \${({ theme }) => theme.spacing.radius.lg};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const docsComponentsTemplate = "\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n resetButton,\n styledSmall,\n styledStrong,\n styledText,\n} from \"cherry-styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n focusModeColumn,\n focusModeHide,\n sidePanelOffset,\n styledAnchor,\n styledTable,\n stylesLists,\n} from \"@/components/layout/SharedStyled\";\nimport { Badge } from \"@/components/layout/Badge\";\nimport { ChatContext } from \"@/components/Chat\";\n\nconst SectionBarContext = createContext(false);\n\nfunction SectionBarProvider({\n hasSectionBar,\n children,\n}: {\n hasSectionBar: boolean;\n children: React.ReactNode;\n}) {\n return (\n <SectionBarContext.Provider value={hasSectionBar}>\n {children}\n </SectionBarContext.Provider>\n );\n}\n\ninterface DocsProps {\n children: React.ReactNode;\n}\n\nconst StyledDocsWrapper = styled.main<{ theme: Theme }>`\n position: relative;\n`;\n\nconst StyledDocsSidebar = styled.div<{ theme: Theme }>`\n clear: both;\n`;\n\nconst StyledDocsContainer = styled.div<{ theme: Theme; $isChatOpen?: boolean }>`\n position: relative;\n padding: 0 20px 100px 20px;\n width: 100%;\n ${({ theme }) => styledText(theme)};\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 0 300px 80px 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 80px 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n\n & p {\n color: ${({ theme }) => theme.colors.grayDark};\n hyphens: auto;\n }\n\n & pre {\n max-width: 100%;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n\n & code:not([class]),\n & kbd {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n overflow-wrap: anywhere;\n }\n\n & .lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n & .aspect-video {\n aspect-ratio: 16 / 9;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n`;\n\nexport const StyledMarkdownContainer = styled.div`\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex: 1;\n max-width: 640px;\n margin: auto;\n`;\n\ninterface Props {\n theme?: Theme;\n $isActive?: boolean;\n $isOpen?: boolean;\n $hasSectionBar?: boolean;\n}\n\nexport const StyledSidebar = styled.nav<Props>`\n position: fixed;\n overflow-y: auto;\n max-height: calc(\n 100dvh - ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px\n );\n width: 100%;\n z-index: 99;\n top: ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px;\n height: 100%;\n padding: 20px;\n opacity: 0;\n pointer-events: none;\n transition: all 0.3s ease;\n transform: translateY(30px);\n left: 0;\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n display: flex;\n flex-direction: column;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n border-right: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: none;\n max-height: 100dvh;\n width: 220px;\n background: transparent;\n padding: 82px 20px 20px 20px;\n opacity: 1;\n pointer-events: all;\n transform: translateY(0);\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n top: 0;\n width: 280px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n transform: translateY(0);\n opacity: 1;\n pointer-events: all;\n `}\n\n ${focusModeHide(\"left\")};\n`;\n\nexport const StyledSidebarFooter = styled.div`\n padding: 22px 20px;\n position: sticky;\n border-top: 1px solid ${({ theme }) => theme.colors.grayLight};\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n margin: 0 -20px -20px;\n bottom: -20px;\n backdrop-filter: blur(10px);\n\n ${mq(\"lg\")} {\n padding: 16px 20px;\n }\n`;\n\nexport const StyledIndexSidebar = styled.ul<{ theme: Theme }>`\n display: none;\n list-style: none;\n margin: 0;\n padding: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 280px;\n height: 100dvh;\n overflow-y: auto;\n z-index: 1;\n padding: 82px 20px 20px 20px;\n background: ${({ theme }) => theme.colors.light};\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n -webkit-overflow-scrolling: touch;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n display: block;\n }\n\n & li {\n padding: 5px 0;\n }\n\n ${focusModeHide(\"right\")};\n`;\n\nexport const StyledIndexSidebarLabel = styled.span<{ theme: Theme }>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nexport const StyledIndexSidebarLi = styled.li<{\n theme: Theme;\n $isActive: boolean;\n}>`\n &::before {\n content: \"\";\n display: block;\n position: absolute;\n left: 0;\n height: 20px;\n width: 1px;\n background: transparent;\n transition: all 0.3s ease;\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n &::before {\n background: ${theme.colors.primary};\n }\n `}\n`;\n\nexport const StyledIndexSidebarLink = styled.a<{\n theme: Theme;\n $isActive: boolean;\n}>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : theme.colors.dark};\n font-weight: ${({ $isActive }) => ($isActive ? \"600\" : \"400\")};\n text-decoration: none;\n transition: all 0.3s ease;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\nexport const StyledSidebarList = styled.ul`\n list-style: none;\n margin: 0;\n padding: 0;\n\n &:last-of-type {\n margin-bottom: auto;\n }\n`;\n\nexport const StyledStrong = styled.strong<{ theme: Theme }>`\n font-weight: 600;\n ${({ theme }) => styledStrong(theme)};\n color: ${({ theme }) => theme.colors.accentStrong};\n display: inline-flex;\n align-items: center;\n gap: 8px;\n\n & svg {\n flex-shrink: 0;\n }\n`;\n\nexport const StyledSidebarListItem = styled.li`\n display: flex;\n gap: 10px;\n clear: both;\n`;\n\n// Shared appearance for every sidebar row - leaf links AND nested group\n// headers - so hover, active state, and the left rail read identically.\nconst sidebarRowStyles = css<Props>`\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1.6;\n color: ${({ theme }) => theme.colors.accentMuted};\n padding: 5px 0 5px 20px;\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n transition: all 0.3s ease;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n\n & svg {\n flex-shrink: 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n border-color: ${({ theme }) => theme.colors.primary};\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n color: ${theme.colors.accentStrong};\n border-color: ${theme.colors.primary};\n font-weight: 600;\n `};\n`;\n\n// The collapse chevron points right when closed and rotates to point down\n// when the group is open.\nconst sidebarChevron = css<Props>`\n & .lucide-chevron-right {\n margin-left: auto;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: rotate(90deg);\n `}\n }\n`;\n\nexport const StyledSidebarListItemLink = styled(Link)<Props>`\n ${sidebarRowStyles};\n`;\n\n// Compact HTTP-method label shown before a generated API endpoint link, colored\n// by verb so endpoints are scannable in the sidebar. Only rendered when a link\n// carries an `httpMethod` (endpoint pages do; hand-written pages do not).\n// The look is Badge's mono variation (tinted, solid when active); only\n// sidebar metrics are adjusted here.\nexport const StyledSidebarMethodTag = styled(Badge)`\n flex-shrink: 0;\n font-size: 9px;\n letter-spacing: 0.02em;\n padding: 1px 4px;\n border: none;\n`;\n\n// Nested navigation group. The header shares the link appearance/hover; a\n// non-navigable group is a single toggle button, while a group that is also a\n// page pairs a link with a chevron toggle. Children live in\n// StyledSidebarGroupContent, which animates open/closed via height 0 <-> auto\n// (enabled by interpolate-size in GlobalStyles, same as the Accordion).\nexport const StyledSidebarGroupButton = styled.button<Props>`\n ${resetButton};\n ${sidebarRowStyles};\n ${sidebarChevron};\n width: 100%;\n text-align: left;\n\n /* Buttons aren't covered by the global a:focus-visible ring, so this\n nav-row toggle carries its own copy of it. */\n &:focus-visible {\n outline: none;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupRow = styled.div<Props>`\n ${sidebarRowStyles};\n ${sidebarChevron};\n\n /* The row is a plain div, so it never matches :focus-visible itself. Ring the\n whole row when its inner link or chevron takes keyboard focus instead, to\n match the leaf-row focus treatment. */\n &:has(:focus-visible) {\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupLink = styled(Link)`\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n color: inherit;\n text-decoration: none;\n\n & svg {\n flex-shrink: 0;\n }\n\n /* Ring is drawn on the parent row via :has(:focus-visible); suppress the\n global a:focus-visible glow so it isn't drawn twice. */\n &:focus-visible {\n outline: none;\n box-shadow: none;\n }\n`;\n\nexport const StyledSidebarGroupChevron = styled.button`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n cursor: pointer;\n\n /* Ring is drawn on the parent row via :has(:focus-visible). */\n &:focus-visible {\n outline: none;\n }\n`;\n\nexport const StyledSidebarGroupContent = styled.ul<Props>`\n list-style: none;\n margin: 0;\n padding: 0;\n height: 0;\n overflow: clip;\n transition: all 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n height: auto;\n `}\n`;\n\nexport const StyleMobileBar = styled.button<Props>`\n ${resetButton};\n position: fixed;\n z-index: 999;\n bottom: 0;\n right: 20px;\n font-size: ${({ theme }) => theme.fontSizes.strong.lg};\n line-height: ${({ theme }) => theme.fontSizes.strong.lg};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n backdrop-filter: blur(10px);\n -webkit-backdrop-filter: blur(10px);\n padding: 10px;\n border-radius: 100px;\n margin: 0 0 20px 0;\n font-weight: 600;\n display: flex;\n justify-content: flex-start;\n width: auto;\n\n ${mq(\"lg\")} {\n display: none;\n }\n\n ${({ $isActive }) => $isActive && `position: fixed;`};\n`;\n\nexport const StyledMobileBurger = styled.span<Props>`\n display: block;\n margin: auto 0;\n width: 18px;\n height: 18px;\n position: relative;\n overflow: hidden;\n background: transparent;\n position: relative;\n transform: scale(0.8);\n\n &::before,\n &::after {\n content: \"\";\n display: block;\n position: absolute;\n width: 18px;\n height: 3px;\n border-radius: 3px;\n background: ${({ theme }) => theme.colors.surface};\n transition: all 0.3s ease;\n }\n\n &::before {\n top: 3px;\n }\n\n &::after {\n bottom: 3px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n transform: translateY(5px) rotate(45deg);\n }\n\n &::after {\n transform: translateY(-4px) rotate(-45deg);\n }\n `};\n`;\n\nexport const StyledMissingComponent = styled.div`\n background: ${({ theme }) => theme.colors.error};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n color: ${({ theme }) => theme.colors.surface};\n font-weight: 600;\n display: flex;\n gap: 10px;\n align-items: center;\n`;\n\ninterface DocsWrapperProps {\n children: React.ReactNode;\n}\n\nfunction DocsWrapper({ children }: DocsWrapperProps) {\n return <StyledDocsWrapper>{children}</StyledDocsWrapper>;\n}\n\nfunction DocsSidebar({ children }: DocsProps) {\n return <StyledDocsSidebar>{children}</StyledDocsSidebar>;\n}\n\nfunction DocsContainer({ children }: DocsProps) {\n const { isOpen } = useContext(ChatContext);\n\n return (\n <StyledDocsContainer $isChatOpen={isOpen}>{children}</StyledDocsContainer>\n );\n}\n\nexport {\n DocsWrapper,\n DocsSidebar,\n DocsContainer,\n SectionBarContext,\n SectionBarProvider,\n};\n";
|
|
1
|
+
export declare const docsComponentsTemplate = "\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport {\n resetButton,\n styledSmall,\n styledStrong,\n styledText,\n} from \"cherry-styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n focusModeColumn,\n focusModeHide,\n sidePanelOffset,\n styledAnchor,\n styledTable,\n stylesLists,\n} from \"@/components/layout/SharedStyled\";\nimport { Badge } from \"@/components/layout/Badge\";\nimport { ChatContext } from \"@/components/Chat\";\n\nconst SectionBarContext = createContext(false);\n\nfunction SectionBarProvider({\n hasSectionBar,\n children,\n}: {\n hasSectionBar: boolean;\n children: React.ReactNode;\n}) {\n return (\n <SectionBarContext.Provider value={hasSectionBar}>\n {children}\n </SectionBarContext.Provider>\n );\n}\n\ninterface DocsProps {\n children: React.ReactNode;\n}\n\nconst StyledDocsWrapper = styled.div<{ theme: Theme }>`\n position: relative;\n`;\n\nconst StyledDocsSidebar = styled.div<{ theme: Theme }>`\n clear: both;\n`;\n\n// The <main> landmark wraps only the article content: the sidebar, footer,\n// and nav render outside it so content extractors and assistive tech start at\n// the article.\nconst StyledDocsContainer = styled.main<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n position: relative;\n padding: 0 20px 100px 20px;\n width: 100%;\n ${({ theme }) => styledText(theme)};\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 0 300px 80px 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 80px 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n\n & p {\n color: ${({ theme }) => theme.colors.grayDark};\n hyphens: auto;\n }\n\n & pre {\n max-width: 100%;\n }\n\n ${styledAnchor};\n ${stylesLists};\n ${styledTable};\n\n & img,\n & video,\n & iframe {\n max-width: 100%;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n\n & code:not([class]),\n & kbd {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n color: ${({ theme }) => theme.colors.dark};\n padding: 2px 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n overflow-wrap: anywhere;\n }\n\n & .lucide {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n & .aspect-video {\n aspect-ratio: 16 / 9;\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n }\n`;\n\nexport const StyledMarkdownContainer = styled.div`\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex: 1;\n max-width: 640px;\n margin: auto;\n`;\n\ninterface Props {\n theme?: Theme;\n $isActive?: boolean;\n $isOpen?: boolean;\n $hasSectionBar?: boolean;\n}\n\nexport const StyledSidebar = styled.nav<Props>`\n position: fixed;\n overflow-y: auto;\n max-height: calc(\n 100dvh - ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px\n );\n width: 100%;\n z-index: 99;\n top: ${({ $hasSectionBar }) => ($hasSectionBar ? 104 : 62)}px;\n height: 100%;\n padding: 20px;\n opacity: 0;\n pointer-events: none;\n transition: all 0.3s ease;\n transform: translateY(30px);\n left: 0;\n background: ${({ theme }) => theme.colors.light};\n -webkit-overflow-scrolling: touch;\n display: flex;\n flex-direction: column;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n border-right: solid 1px ${({ theme }) => theme.colors.grayLight};\n transition: none;\n max-height: 100dvh;\n width: 220px;\n background: transparent;\n padding: 82px 20px 20px 20px;\n opacity: 1;\n pointer-events: all;\n transform: translateY(0);\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n top: 0;\n width: 280px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n transform: translateY(0);\n opacity: 1;\n pointer-events: all;\n `}\n\n ${focusModeHide(\"left\")};\n`;\n\nexport const StyledSidebarFooter = styled.div`\n padding: 22px 20px;\n position: sticky;\n border-top: 1px solid ${({ theme }) => theme.colors.grayLight};\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n margin: 0 -20px -20px;\n bottom: -20px;\n backdrop-filter: blur(10px);\n\n ${mq(\"lg\")} {\n padding: 16px 20px;\n }\n`;\n\nexport const StyledIndexSidebar = styled.ul<{ theme: Theme }>`\n display: none;\n list-style: none;\n margin: 0;\n padding: 0;\n position: fixed;\n top: 0;\n right: 0;\n width: 280px;\n height: 100dvh;\n overflow-y: auto;\n z-index: 1;\n padding: 82px 20px 20px 20px;\n background: ${({ theme }) => theme.colors.light};\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n -webkit-overflow-scrolling: touch;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n display: block;\n }\n\n & li {\n padding: 5px 0;\n }\n\n ${focusModeHide(\"right\")};\n`;\n\nexport const StyledIndexSidebarLabel = styled.span<{ theme: Theme }>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n`;\n\nexport const StyledIndexSidebarLi = styled.li<{\n theme: Theme;\n $isActive: boolean;\n}>`\n &::before {\n content: \"\";\n display: block;\n position: absolute;\n left: 0;\n height: 20px;\n width: 1px;\n background: transparent;\n transition: all 0.3s ease;\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n &::before {\n background: ${theme.colors.primary};\n }\n `}\n`;\n\nexport const StyledIndexSidebarLink = styled.a<{\n theme: Theme;\n $isActive: boolean;\n}>`\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : theme.colors.dark};\n font-weight: ${({ $isActive }) => ($isActive ? \"600\" : \"400\")};\n text-decoration: none;\n transition: all 0.3s ease;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\nexport const StyledSidebarList = styled.ul`\n list-style: none;\n margin: 0;\n padding: 0;\n\n &:last-of-type {\n margin-bottom: auto;\n }\n`;\n\nexport const StyledStrong = styled.strong<{ theme: Theme }>`\n font-weight: 600;\n ${({ theme }) => styledStrong(theme)};\n color: ${({ theme }) => theme.colors.accentStrong};\n display: inline-flex;\n align-items: center;\n gap: 8px;\n\n & svg {\n flex-shrink: 0;\n }\n`;\n\nexport const StyledSidebarListItem = styled.li`\n display: flex;\n gap: 10px;\n clear: both;\n`;\n\n// Shared appearance for every sidebar row - leaf links AND nested group\n// headers - so hover, active state, and the left rail read identically.\nconst sidebarRowStyles = css<Props>`\n text-decoration: none;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n line-height: 1.6;\n color: ${({ theme }) => theme.colors.accentMuted};\n padding: 5px 0 5px 20px;\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n transition: all 0.3s ease;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n\n & svg {\n flex-shrink: 0;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.accent};\n border-color: ${({ theme }) => theme.colors.primary};\n }\n\n ${({ $isActive, theme }) =>\n $isActive &&\n css`\n color: ${theme.colors.accentStrong};\n border-color: ${theme.colors.primary};\n font-weight: 600;\n `};\n`;\n\n// The collapse chevron points right when closed and rotates to point down\n// when the group is open.\nconst sidebarChevron = css<Props>`\n & .lucide-chevron-right {\n margin-left: auto;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: rotate(90deg);\n `}\n }\n`;\n\nexport const StyledSidebarListItemLink = styled(Link)<Props>`\n ${sidebarRowStyles};\n`;\n\n// Compact HTTP-method label shown before a generated API endpoint link, colored\n// by verb so endpoints are scannable in the sidebar. Only rendered when a link\n// carries an `httpMethod` (endpoint pages do; hand-written pages do not).\n// The look is Badge's mono variation (tinted, solid when active); only\n// sidebar metrics are adjusted here.\nexport const StyledSidebarMethodTag = styled(Badge)`\n flex-shrink: 0;\n font-size: 9px;\n letter-spacing: 0.02em;\n padding: 1px 4px;\n border: none;\n`;\n\n// Nested navigation group. The header shares the link appearance/hover; a\n// non-navigable group is a single toggle button, while a group that is also a\n// page pairs a link with a chevron toggle. Children live in\n// StyledSidebarGroupContent, which animates open/closed via height 0 <-> auto\n// (enabled by interpolate-size in GlobalStyles, same as the Accordion).\nexport const StyledSidebarGroupButton = styled.button<Props>`\n ${resetButton};\n ${sidebarRowStyles};\n ${sidebarChevron};\n width: 100%;\n text-align: left;\n\n /* Buttons aren't covered by the global a:focus-visible ring, so this\n nav-row toggle carries its own copy of it. */\n &:focus-visible {\n outline: none;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupRow = styled.div<Props>`\n ${sidebarRowStyles};\n ${sidebarChevron};\n\n /* The row is a plain div, so it never matches :focus-visible itself. Ring the\n whole row when its inner link or chevron takes keyboard focus instead, to\n match the leaf-row focus treatment. */\n &:has(:focus-visible) {\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nexport const StyledSidebarGroupLink = styled(Link)`\n display: flex;\n align-items: center;\n gap: 8px;\n flex: 1;\n min-width: 0;\n color: inherit;\n text-decoration: none;\n\n & svg {\n flex-shrink: 0;\n }\n\n /* Ring is drawn on the parent row via :has(:focus-visible); suppress the\n global a:focus-visible glow so it isn't drawn twice. */\n &:focus-visible {\n outline: none;\n box-shadow: none;\n }\n`;\n\nexport const StyledSidebarGroupChevron = styled.button`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n cursor: pointer;\n\n /* Ring is drawn on the parent row via :has(:focus-visible). */\n &:focus-visible {\n outline: none;\n }\n`;\n\nexport const StyledSidebarGroupContent = styled.ul<Props>`\n list-style: none;\n margin: 0;\n padding: 0;\n height: 0;\n overflow: clip;\n transition: all 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n height: auto;\n `}\n`;\n\nexport const StyleMobileBar = styled.button<Props>`\n ${resetButton};\n position: fixed;\n z-index: 999;\n bottom: 0;\n right: 20px;\n font-size: ${({ theme }) => theme.fontSizes.strong.lg};\n line-height: ${({ theme }) => theme.fontSizes.strong.lg};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n background: ${({ theme }) => theme.colors.primary};\n color: ${({ theme }) => theme.colors.surface};\n backdrop-filter: blur(10px);\n -webkit-backdrop-filter: blur(10px);\n padding: 10px;\n border-radius: 100px;\n margin: 0 0 20px 0;\n font-weight: 600;\n display: flex;\n justify-content: flex-start;\n width: auto;\n\n ${mq(\"lg\")} {\n display: none;\n }\n\n ${({ $isActive }) => $isActive && `position: fixed;`};\n`;\n\nexport const StyledMobileBurger = styled.span<Props>`\n display: block;\n margin: auto 0;\n width: 18px;\n height: 18px;\n position: relative;\n overflow: hidden;\n background: transparent;\n position: relative;\n transform: scale(0.8);\n\n &::before,\n &::after {\n content: \"\";\n display: block;\n position: absolute;\n width: 18px;\n height: 3px;\n border-radius: 3px;\n background: ${({ theme }) => theme.colors.surface};\n transition: all 0.3s ease;\n }\n\n &::before {\n top: 3px;\n }\n\n &::after {\n bottom: 3px;\n }\n\n ${({ $isActive }) =>\n $isActive &&\n css`\n &::before {\n transform: translateY(5px) rotate(45deg);\n }\n\n &::after {\n transform: translateY(-4px) rotate(-45deg);\n }\n `};\n`;\n\nexport const StyledMissingComponent = styled.div`\n background: ${({ theme }) => theme.colors.error};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n font-size: ${({ theme }) => theme.fontSizes.small.lg};\n color: ${({ theme }) => theme.colors.surface};\n font-weight: 600;\n display: flex;\n gap: 10px;\n align-items: center;\n`;\n\n// Visually hidden but present for crawlers and agents: points at llms.txt and\n// the .md mirrors. Rendered as the first element of the site layout.\nconst StyledLlmsDirective = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n border: 0;\n`;\n\nfunction LlmsDirective() {\n return (\n <StyledLlmsDirective data-markdown-ignore>\n <a href=\"/llms.txt\">Documentation index for AI agents (llms.txt)</a>.\n Markdown versions of every page are available by appending .md to the page\n URL. The full corpus is at <a href=\"/llms-full.txt\">/llms-full.txt</a>.\n </StyledLlmsDirective>\n );\n}\n\ninterface DocsWrapperProps {\n children: React.ReactNode;\n}\n\nfunction DocsWrapper({ children }: DocsWrapperProps) {\n return <StyledDocsWrapper>{children}</StyledDocsWrapper>;\n}\n\nfunction DocsSidebar({ children }: DocsProps) {\n return <StyledDocsSidebar>{children}</StyledDocsSidebar>;\n}\n\nfunction DocsContainer({ children }: DocsProps) {\n const { isOpen } = useContext(ChatContext);\n\n return (\n <StyledDocsContainer $isChatOpen={isOpen}>{children}</StyledDocsContainer>\n );\n}\n\nexport {\n DocsWrapper,\n DocsSidebar,\n DocsContainer,\n LlmsDirective,\n SectionBarContext,\n SectionBarProvider,\n};\n";
|
|
@@ -41,7 +41,7 @@ interface DocsProps {
|
|
|
41
41
|
children: React.ReactNode;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const StyledDocsWrapper = styled.
|
|
44
|
+
const StyledDocsWrapper = styled.div<{ theme: Theme }>\`
|
|
45
45
|
position: relative;
|
|
46
46
|
\`;
|
|
47
47
|
|
|
@@ -49,7 +49,13 @@ const StyledDocsSidebar = styled.div<{ theme: Theme }>\`
|
|
|
49
49
|
clear: both;
|
|
50
50
|
\`;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
// The <main> landmark wraps only the article content: the sidebar, footer,
|
|
53
|
+
// and nav render outside it so content extractors and assistive tech start at
|
|
54
|
+
// the article.
|
|
55
|
+
const StyledDocsContainer = styled.main<{
|
|
56
|
+
theme: Theme;
|
|
57
|
+
$isChatOpen?: boolean;
|
|
58
|
+
}>\`
|
|
53
59
|
position: relative;
|
|
54
60
|
padding: 0 20px 100px 20px;
|
|
55
61
|
width: 100%;
|
|
@@ -535,6 +541,30 @@ export const StyledMissingComponent = styled.div\`
|
|
|
535
541
|
align-items: center;
|
|
536
542
|
\`;
|
|
537
543
|
|
|
544
|
+
// Visually hidden but present for crawlers and agents: points at llms.txt and
|
|
545
|
+
// the .md mirrors. Rendered as the first element of the site layout.
|
|
546
|
+
const StyledLlmsDirective = styled.div\`
|
|
547
|
+
position: absolute;
|
|
548
|
+
width: 1px;
|
|
549
|
+
height: 1px;
|
|
550
|
+
padding: 0;
|
|
551
|
+
margin: -1px;
|
|
552
|
+
overflow: hidden;
|
|
553
|
+
clip: rect(0 0 0 0);
|
|
554
|
+
white-space: nowrap;
|
|
555
|
+
border: 0;
|
|
556
|
+
\`;
|
|
557
|
+
|
|
558
|
+
function LlmsDirective() {
|
|
559
|
+
return (
|
|
560
|
+
<StyledLlmsDirective data-markdown-ignore>
|
|
561
|
+
<a href="/llms.txt">Documentation index for AI agents (llms.txt)</a>.
|
|
562
|
+
Markdown versions of every page are available by appending .md to the page
|
|
563
|
+
URL. The full corpus is at <a href="/llms-full.txt">/llms-full.txt</a>.
|
|
564
|
+
</StyledLlmsDirective>
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
538
568
|
interface DocsWrapperProps {
|
|
539
569
|
children: React.ReactNode;
|
|
540
570
|
}
|
|
@@ -559,6 +589,7 @@ export {
|
|
|
559
589
|
DocsWrapper,
|
|
560
590
|
DocsSidebar,
|
|
561
591
|
DocsContainer,
|
|
592
|
+
LlmsDirective,
|
|
562
593
|
SectionBarContext,
|
|
563
594
|
SectionBarProvider,
|
|
564
595
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const mermaidViewTemplate = "\"use client\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { interactiveStyles, resetButton } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst MIN_SCALE = 0.5;\nconst MAX_SCALE = 4;\nconst SCALE_STEP = 0.25;\nconst PAN_STEP = 48;\nconst AUTO_ACTIONS_MIN_HEIGHT = 120;\n\n// Whether the Fullscreen API is available. Read via useSyncExternalStore so it\n// resolves during render (SSR-safe: false on the server) instead of via a\n// synchronous setState inside an effect. The capability never changes, so the\n// subscribe callback is a stable no-op.\nconst subscribeFullscreenCapability = () => () => {};\nconst getFullscreenCapability = () =>\n typeof document !== \"undefined\" && Boolean(document.fullscreenEnabled);\nconst getFullscreenCapabilityServer = () => false;\n\nexport type MermaidPlacement =\n \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n\ninterface MermaidViewProps {\n svg: string;\n width?: number | null;\n placement?: MermaidPlacement;\n actions?: boolean;\n theme?: Theme;\n}\n\nconst Viewport = styled.div<{ $draggable: boolean; $dragging: boolean }>`\n overflow: hidden;\n padding: 16px;\n ${({ $draggable, $dragging }) =>\n $draggable &&\n css`\n cursor: ${$dragging ? \"grabbing\" : \"grab\"};\n user-select: none;\n `}\n`;\n\nconst Stage = styled.div<{\n $scale: number;\n $x: number;\n $y: number;\n $dragging: boolean;\n}>`\n transform: translate(${({ $x }) => $x}px, ${({ $y }) => $y}px)\n scale(${({ $scale }) => $scale});\n transform-origin: center center;\n transition: ${({ $dragging }) =>\n $dragging ? \"none\" : \"transform 0.15s ease-out\"};\n margin: 0 auto;\n\n @media (prefers-reduced-motion: reduce) {\n transition: none;\n }\n\n & > svg {\n display: block;\n width: 100%;\n height: auto;\n margin: 0 auto;\n }\n`;\n\nconst Figure = styled.figure<{ theme: Theme }>`\n position: relative;\n flex-shrink: 0;\n margin: 0;\n padding: 0;\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n background: ${({ theme }) => theme.colors.light};\n overflow: hidden;\n\n &:fullscreen {\n border: none;\n border-radius: 0;\n\n ${Viewport} {\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n ${Stage} {\n width: 100%;\n height: 100%;\n }\n\n ${Stage} > svg {\n height: 100%;\n }\n }\n`;\n\nconst Controls = styled.div<{ theme: Theme; $placement: MermaidPlacement }>`\n position: absolute;\n ${({ $placement }) => {\n const [vertical, horizontal] = $placement.split(\"-\");\n return css`\n ${vertical}: 8px;\n ${horizontal}: 8px;\n `;\n }}\n display: grid;\n grid-template-columns: repeat(3, 24px);\n grid-template-rows: repeat(3, 24px);\n gap: 2px;\n padding: 4px;\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n background: ${({ theme }) => theme.colors.light};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n`;\n\nconst ControlButton = styled.button<{ theme: Theme }>`\n ${resetButton};\n ${interactiveStyles};\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: ${({ theme }) => theme.colors.grayDark};\n cursor: pointer;\n\n &:hover:not(:disabled) {\n background: ${({ theme }) => theme.colors.grayLight};\n color: ${({ theme }) => theme.colors.dark};\n }\n\n &:disabled {\n opacity: 0.4;\n cursor: not-allowed;\n }\n`;\n\nfunction MermaidView({\n svg,\n width,\n placement = \"bottom-right\",\n actions,\n ...props\n}: MermaidViewProps) {\n const [scale, setScale] = useState(1);\n const [offset, setOffset] = useState({ x: 0, y: 0 });\n const [autoShow, setAutoShow] = useState(false);\n const [dragging, setDragging] = useState(false);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const canFullscreen = useSyncExternalStore(\n subscribeFullscreenCapability,\n getFullscreenCapability,\n getFullscreenCapabilityServer,\n );\n const viewportRef = useRef<HTMLDivElement>(null);\n const figureRef = useRef<HTMLElement>(null);\n const dragStart = useRef<{\n x: number;\n y: number;\n ox: number;\n oy: number;\n } | null>(null);\n\n useEffect(() => {\n if (actions !== undefined) return;\n const element = viewportRef.current;\n if (!element || typeof ResizeObserver === \"undefined\") return;\n\n const measure = () => {\n setAutoShow(\n element.getBoundingClientRect().height > AUTO_ACTIONS_MIN_HEIGHT,\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, [actions]);\n\n useEffect(() => {\n const onChange = () =>\n setIsFullscreen(document.fullscreenElement === figureRef.current);\n document.addEventListener(\"fullscreenchange\", onChange);\n return () => document.removeEventListener(\"fullscreenchange\", onChange);\n }, []);\n\n const showControls = actions ?? autoShow;\n\n const zoom = useCallback((delta: number) => {\n setScale((current) =>\n Math.min(\n MAX_SCALE,\n Math.max(MIN_SCALE, Math.round((current + delta) * 100) / 100),\n ),\n );\n }, []);\n\n const pan = useCallback((x: number, y: number) => {\n setOffset((current) => ({ x: current.x + x, y: current.y + y }));\n }, []);\n\n const reset = useCallback(() => {\n setScale(1);\n setOffset({ x: 0, y: 0 });\n }, []);\n\n const toggleFullscreen = useCallback(() => {\n const element = figureRef.current;\n if (!element) return;\n if (document.fullscreenElement === element) {\n void document.exitFullscreen().catch(() => {});\n } else {\n void element.requestFullscreen().catch(() => {});\n }\n }, []);\n\n const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n if (!showControls || event.pointerType !== \"mouse\" || event.button !== 0) {\n return;\n }\n event.currentTarget.setPointerCapture(event.pointerId);\n dragStart.current = {\n x: event.clientX,\n y: event.clientY,\n ox: offset.x,\n oy: offset.y,\n };\n setDragging(true);\n };\n\n const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n const start = dragStart.current;\n if (!start) return;\n setOffset({\n x: start.ox + (event.clientX - start.x),\n y: start.oy + (event.clientY - start.y),\n });\n };\n\n const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {\n if (!dragStart.current) return;\n dragStart.current = null;\n setDragging(false);\n if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n };\n\n const isReset = scale === 1 && offset.x === 0 && offset.y === 0;\n\n return (\n <Figure ref={figureRef} {...props}>\n <Viewport\n ref={viewportRef}\n $draggable={showControls}\n $dragging={dragging}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n >\n <Stage\n $scale={scale}\n $x={offset.x}\n $y={offset.y}\n $dragging={dragging}\n style={\n width && !isFullscreen ? { maxWidth: `${width}px` } : undefined\n }\n dangerouslySetInnerHTML={{ __html: svg }}\n />\n </Viewport>\n\n {showControls && (\n <Controls $placement={placement}>\n <ControlButton\n type=\"button\"\n aria-label=\"Zoom out\"\n onClick={() => zoom(-SCALE_STEP)}\n disabled={scale <= MIN_SCALE}\n >\n <Icon name=\"zoom-out\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Pan up\"\n onClick={() => pan(0, -PAN_STEP)}\n >\n <Icon name=\"chevron-up\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Zoom in\"\n onClick={() => zoom(SCALE_STEP)}\n disabled={scale >= MAX_SCALE}\n >\n <Icon name=\"zoom-in\" size={14} />\n </ControlButton>\n\n <ControlButton\n type=\"button\"\n aria-label=\"Pan left\"\n onClick={() => pan(-PAN_STEP, 0)}\n >\n <Icon name=\"chevron-left\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Reset view\"\n onClick={reset}\n disabled={isReset}\n >\n <Icon name=\"rotate-ccw\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Pan right\"\n onClick={() => pan(PAN_STEP, 0)}\n >\n <Icon name=\"chevron-right\" size={14} />\n </ControlButton>\n\n {canFullscreen ? (\n <ControlButton\n type=\"button\"\n aria-label={isFullscreen ? \"Exit full screen\" : \"Full screen\"}\n onClick={toggleFullscreen}\n >\n <Icon name={isFullscreen ? \"minimize\" : \"maximize\"} size={14} />\n </ControlButton>\n ) : (\n <span />\n )}\n <ControlButton\n type=\"button\"\n aria-label=\"Pan down\"\n onClick={() => pan(0, PAN_STEP)}\n >\n <Icon name=\"chevron-down\" size={14} />\n </ControlButton>\n <span />\n </Controls>\n )}\n </Figure>\n );\n}\n\nexport { MermaidView };\n";
|
|
1
|
+
export declare const mermaidViewTemplate = "\"use client\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { interactiveStyles, resetButton } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst MIN_SCALE = 0.5;\nconst MAX_SCALE = 4;\nconst SCALE_STEP = 0.25;\nconst PAN_STEP = 48;\nconst MIN_DIAGRAM_HEIGHT = 320;\n// Must exceed MIN_DIAGRAM_HEIGHT plus the viewport padding (2 x 16px), so\n// diagrams sitting on the min-height floor don't auto-show the controls.\nconst AUTO_ACTIONS_MIN_HEIGHT = 420;\n\n// Whether the Fullscreen API is available. Read via useSyncExternalStore so it\n// resolves during render (SSR-safe: false on the server) instead of via a\n// synchronous setState inside an effect. The capability never changes, so the\n// subscribe callback is a stable no-op.\nconst subscribeFullscreenCapability = () => () => {};\nconst getFullscreenCapability = () =>\n typeof document !== \"undefined\" && Boolean(document.fullscreenEnabled);\nconst getFullscreenCapabilityServer = () => false;\n\nexport type MermaidPlacement =\n \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n\ninterface MermaidViewProps {\n svg: string;\n width?: number | null;\n placement?: MermaidPlacement;\n actions?: boolean;\n theme?: Theme;\n}\n\nconst Viewport = styled.div<{ $draggable: boolean; $dragging: boolean }>`\n overflow: hidden;\n padding: 16px;\n ${({ $draggable, $dragging }) =>\n $draggable &&\n css`\n cursor: ${$dragging ? \"grabbing\" : \"grab\"};\n user-select: none;\n `}\n`;\n\nconst Stage = styled.div<{\n $scale: number;\n $x: number;\n $y: number;\n $dragging: boolean;\n}>`\n transform: translate(${({ $x }) => $x}px, ${({ $y }) => $y}px)\n scale(${({ $scale }) => $scale});\n transform-origin: center center;\n transition: ${({ $dragging }) =>\n $dragging ? \"none\" : \"transform 0.15s ease-out\"};\n margin: 0 auto;\n\n @media (prefers-reduced-motion: reduce) {\n transition: none;\n }\n\n & > svg {\n display: block;\n width: 100%;\n height: auto;\n min-height: ${MIN_DIAGRAM_HEIGHT}px;\n margin: 0 auto;\n }\n`;\n\nconst Figure = styled.figure<{ theme: Theme }>`\n position: relative;\n flex-shrink: 0;\n margin: 0;\n padding: 0;\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n background: ${({ theme }) => theme.colors.light};\n overflow: hidden;\n\n &:fullscreen {\n border: none;\n border-radius: 0;\n\n ${Viewport} {\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n ${Stage} {\n width: 100%;\n height: 100%;\n }\n\n ${Stage} > svg {\n height: 100%;\n }\n }\n`;\n\nconst Controls = styled.div<{ theme: Theme; $placement: MermaidPlacement }>`\n position: absolute;\n ${({ $placement }) => {\n const [vertical, horizontal] = $placement.split(\"-\");\n return css`\n ${vertical}: 8px;\n ${horizontal}: 8px;\n `;\n }}\n display: grid;\n grid-template-columns: repeat(3, 24px);\n grid-template-rows: repeat(3, 24px);\n gap: 2px;\n padding: 4px;\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n background: ${({ theme }) => theme.colors.light};\n box-shadow: ${({ theme }) => theme.shadows.sm};\n`;\n\nconst ControlButton = styled.button<{ theme: Theme }>`\n ${resetButton};\n ${interactiveStyles};\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: ${({ theme }) => theme.colors.grayDark};\n cursor: pointer;\n\n &:hover:not(:disabled) {\n background: ${({ theme }) => theme.colors.grayLight};\n color: ${({ theme }) => theme.colors.dark};\n }\n\n &:disabled {\n opacity: 0.4;\n cursor: not-allowed;\n }\n`;\n\nfunction MermaidView({\n svg,\n width,\n placement = \"bottom-right\",\n actions,\n ...props\n}: MermaidViewProps) {\n const [scale, setScale] = useState(1);\n const [offset, setOffset] = useState({ x: 0, y: 0 });\n const [autoShow, setAutoShow] = useState(false);\n const [dragging, setDragging] = useState(false);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const canFullscreen = useSyncExternalStore(\n subscribeFullscreenCapability,\n getFullscreenCapability,\n getFullscreenCapabilityServer,\n );\n const viewportRef = useRef<HTMLDivElement>(null);\n const figureRef = useRef<HTMLElement>(null);\n const dragStart = useRef<{\n x: number;\n y: number;\n ox: number;\n oy: number;\n } | null>(null);\n\n useEffect(() => {\n if (actions !== undefined) return;\n const element = viewportRef.current;\n if (!element || typeof ResizeObserver === \"undefined\") return;\n\n const measure = () => {\n setAutoShow(\n element.getBoundingClientRect().height > AUTO_ACTIONS_MIN_HEIGHT,\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, [actions]);\n\n useEffect(() => {\n const onChange = () =>\n setIsFullscreen(document.fullscreenElement === figureRef.current);\n document.addEventListener(\"fullscreenchange\", onChange);\n return () => document.removeEventListener(\"fullscreenchange\", onChange);\n }, []);\n\n const showControls = actions ?? autoShow;\n\n const zoom = useCallback((delta: number) => {\n setScale((current) =>\n Math.min(\n MAX_SCALE,\n Math.max(MIN_SCALE, Math.round((current + delta) * 100) / 100),\n ),\n );\n }, []);\n\n const pan = useCallback((x: number, y: number) => {\n setOffset((current) => ({ x: current.x + x, y: current.y + y }));\n }, []);\n\n const reset = useCallback(() => {\n setScale(1);\n setOffset({ x: 0, y: 0 });\n }, []);\n\n const toggleFullscreen = useCallback(() => {\n const element = figureRef.current;\n if (!element) return;\n if (document.fullscreenElement === element) {\n void document.exitFullscreen().catch(() => {});\n } else {\n void element.requestFullscreen().catch(() => {});\n }\n }, []);\n\n const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n if (!showControls || event.pointerType !== \"mouse\" || event.button !== 0) {\n return;\n }\n event.currentTarget.setPointerCapture(event.pointerId);\n dragStart.current = {\n x: event.clientX,\n y: event.clientY,\n ox: offset.x,\n oy: offset.y,\n };\n setDragging(true);\n };\n\n const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n const start = dragStart.current;\n if (!start) return;\n setOffset({\n x: start.ox + (event.clientX - start.x),\n y: start.oy + (event.clientY - start.y),\n });\n };\n\n const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {\n if (!dragStart.current) return;\n dragStart.current = null;\n setDragging(false);\n if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n };\n\n const isReset = scale === 1 && offset.x === 0 && offset.y === 0;\n\n return (\n <Figure ref={figureRef} {...props}>\n <Viewport\n ref={viewportRef}\n $draggable={showControls}\n $dragging={dragging}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n >\n <Stage\n $scale={scale}\n $x={offset.x}\n $y={offset.y}\n $dragging={dragging}\n style={\n width && !isFullscreen ? { maxWidth: `${width}px` } : undefined\n }\n dangerouslySetInnerHTML={{ __html: svg }}\n />\n </Viewport>\n\n {showControls && (\n <Controls $placement={placement}>\n <ControlButton\n type=\"button\"\n aria-label=\"Zoom out\"\n onClick={() => zoom(-SCALE_STEP)}\n disabled={scale <= MIN_SCALE}\n >\n <Icon name=\"zoom-out\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Pan up\"\n onClick={() => pan(0, -PAN_STEP)}\n >\n <Icon name=\"chevron-up\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Zoom in\"\n onClick={() => zoom(SCALE_STEP)}\n disabled={scale >= MAX_SCALE}\n >\n <Icon name=\"zoom-in\" size={14} />\n </ControlButton>\n\n <ControlButton\n type=\"button\"\n aria-label=\"Pan left\"\n onClick={() => pan(-PAN_STEP, 0)}\n >\n <Icon name=\"chevron-left\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Reset view\"\n onClick={reset}\n disabled={isReset}\n >\n <Icon name=\"rotate-ccw\" size={14} />\n </ControlButton>\n <ControlButton\n type=\"button\"\n aria-label=\"Pan right\"\n onClick={() => pan(PAN_STEP, 0)}\n >\n <Icon name=\"chevron-right\" size={14} />\n </ControlButton>\n\n {canFullscreen ? (\n <ControlButton\n type=\"button\"\n aria-label={isFullscreen ? \"Exit full screen\" : \"Full screen\"}\n onClick={toggleFullscreen}\n >\n <Icon name={isFullscreen ? \"minimize\" : \"maximize\"} size={14} />\n </ControlButton>\n ) : (\n <span />\n )}\n <ControlButton\n type=\"button\"\n aria-label=\"Pan down\"\n onClick={() => pan(0, PAN_STEP)}\n >\n <Icon name=\"chevron-down\" size={14} />\n </ControlButton>\n <span />\n </Controls>\n )}\n </Figure>\n );\n}\n\nexport { MermaidView };\n";
|
|
@@ -15,7 +15,10 @@ const MIN_SCALE = 0.5;
|
|
|
15
15
|
const MAX_SCALE = 4;
|
|
16
16
|
const SCALE_STEP = 0.25;
|
|
17
17
|
const PAN_STEP = 48;
|
|
18
|
-
const
|
|
18
|
+
const MIN_DIAGRAM_HEIGHT = 320;
|
|
19
|
+
// Must exceed MIN_DIAGRAM_HEIGHT plus the viewport padding (2 x 16px), so
|
|
20
|
+
// diagrams sitting on the min-height floor don't auto-show the controls.
|
|
21
|
+
const AUTO_ACTIONS_MIN_HEIGHT = 420;
|
|
19
22
|
|
|
20
23
|
// Whether the Fullscreen API is available. Read via useSyncExternalStore so it
|
|
21
24
|
// resolves during render (SSR-safe: false on the server) instead of via a
|
|
@@ -69,6 +72,7 @@ const Stage = styled.div<{
|
|
|
69
72
|
display: block;
|
|
70
73
|
width: 100%;
|
|
71
74
|
height: auto;
|
|
75
|
+
min-height: \${MIN_DIAGRAM_HEIGHT}px;
|
|
72
76
|
margin: 0 auto;
|
|
73
77
|
}
|
|
74
78
|
\`;
|
|
@@ -6,4 +6,17 @@ export interface LlmsIndexArgs {
|
|
|
6
6
|
pages: PageMeta[];
|
|
7
7
|
sectionsConfig: SectionConfig[] | null;
|
|
8
8
|
}
|
|
9
|
+
export interface CategoryGroup {
|
|
10
|
+
category: string;
|
|
11
|
+
minCategoryOrder: number;
|
|
12
|
+
pages: PageMeta[];
|
|
13
|
+
}
|
|
14
|
+
export interface SectionGroup {
|
|
15
|
+
sectionSlug: string;
|
|
16
|
+
sectionLabel: string;
|
|
17
|
+
sectionOrder: number;
|
|
18
|
+
categories: CategoryGroup[];
|
|
19
|
+
}
|
|
20
|
+
export declare function pageUrl(slug: string, baseUrl: string | null): string;
|
|
21
|
+
export declare function buildSectionGroups(pages: PageMeta[], sectionsConfig: SectionConfig[] | null): SectionGroup[];
|
|
9
22
|
export declare function llmsIndexTemplate(args: LlmsIndexArgs): string;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Index links point at the static markdown mirrors (public/{slug}.md) so
|
|
2
|
+
// agents get clean markdown directly; the HTML page is the same URL without
|
|
3
|
+
// the .md suffix.
|
|
4
|
+
export function pageUrl(slug, baseUrl) {
|
|
5
|
+
const prefix = baseUrl ?? "";
|
|
6
|
+
return slug === "" ? `${prefix}/index.md` : `${prefix}/${slug}.md`;
|
|
6
7
|
}
|
|
7
8
|
function comparePages(a, b) {
|
|
8
9
|
if (a.order !== b.order)
|
|
9
10
|
return a.order - b.order;
|
|
10
11
|
return a.title.localeCompare(b.title);
|
|
11
12
|
}
|
|
12
|
-
function buildSectionGroups(pages, sectionsConfig) {
|
|
13
|
+
export function buildSectionGroups(pages, sectionsConfig) {
|
|
13
14
|
const sectionOrderIndex = new Map();
|
|
14
15
|
sectionOrderIndex.set("", 0);
|
|
15
16
|
if (sectionsConfig) {
|
|
@@ -71,12 +72,19 @@ function buildSectionGroups(pages, sectionsConfig) {
|
|
|
71
72
|
export function llmsIndexTemplate(args) {
|
|
72
73
|
const { siteName, siteDescription, baseUrl, pages, sectionsConfig } = args;
|
|
73
74
|
const lines = [];
|
|
75
|
+
const prefix = baseUrl ?? "";
|
|
74
76
|
lines.push(`# ${siteName}`);
|
|
75
77
|
lines.push("");
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
78
|
+
const summary = siteDescription && siteDescription.trim() !== ""
|
|
79
|
+
? siteDescription.trim()
|
|
80
|
+
: `Documentation for ${siteName}.`;
|
|
81
|
+
lines.push(`> ${summary}`);
|
|
82
|
+
lines.push("");
|
|
83
|
+
lines.push("Every page link below points to a markdown mirror; drop the .md suffix for the HTML version.");
|
|
84
|
+
lines.push(`Full corpus in one file: ${prefix}/llms-full.txt`);
|
|
85
|
+
lines.push(`Agent skill: ${prefix}/skill.md`);
|
|
86
|
+
lines.push(`MCP server (streamable HTTP; tools: search_docs, get_doc, list_docs): ${prefix}/api/mcp`);
|
|
87
|
+
lines.push("");
|
|
80
88
|
if (pages.length === 0) {
|
|
81
89
|
return lines.join("\n") + "\n";
|
|
82
90
|
}
|
|
@@ -14,6 +14,8 @@ export function llmsPageTemplate(page, baseUrl) {
|
|
|
14
14
|
}
|
|
15
15
|
lines.push(`Source: ${pageUrl(page.slug, baseUrl)}`);
|
|
16
16
|
lines.push("");
|
|
17
|
+
lines.push(`> For the complete documentation index, see [llms.txt](${baseUrl ?? ""}/llms.txt).`);
|
|
18
|
+
lines.push("");
|
|
17
19
|
lines.push(page.body.trim());
|
|
18
20
|
lines.push("");
|
|
19
21
|
return lines.join("\n");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PageMeta, SectionConfig } from "../../lib/types.js";
|
|
2
|
+
export interface SkillMdArgs {
|
|
3
|
+
siteName: string;
|
|
4
|
+
siteDescription?: string;
|
|
5
|
+
baseUrl: string | null;
|
|
6
|
+
pages: PageMeta[];
|
|
7
|
+
sectionsConfig: SectionConfig[] | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function siteDocsSlug(siteName: string): string;
|
|
10
|
+
export declare function skillMdTemplate(args: SkillMdArgs): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { buildSectionGroups, pageUrl } from "./llmsIndex.js";
|
|
2
|
+
const KEY_PAGE_LIMIT = 8;
|
|
3
|
+
function slugifySiteName(siteName) {
|
|
4
|
+
const slug = siteName
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
7
|
+
.replace(/^-+|-+$/g, "");
|
|
8
|
+
return slug === "" ? "docs" : slug;
|
|
9
|
+
}
|
|
10
|
+
// Identifier for the skill name and the MCP discovery manifest. Skips the
|
|
11
|
+
// -docs suffix when the site name already ends in "docs" ("Acme Docs" ->
|
|
12
|
+
// acme-docs, not acme-docs-docs).
|
|
13
|
+
export function siteDocsSlug(siteName) {
|
|
14
|
+
const slug = slugifySiteName(siteName);
|
|
15
|
+
return slug === "docs" || slug.endsWith("-docs") ? slug : `${slug}-docs`;
|
|
16
|
+
}
|
|
17
|
+
// Agent skill definition served at /skill.md: tells agents how to read the
|
|
18
|
+
// docs (llms.txt index, .md mirrors, MCP server) and lists the first pages in
|
|
19
|
+
// navigation order as entry points. A user-authored public/skill.md in the
|
|
20
|
+
// watch dir overrides this file, since public assets are copied afterwards.
|
|
21
|
+
export function skillMdTemplate(args) {
|
|
22
|
+
const { siteName, siteDescription, baseUrl, pages, sectionsConfig } = args;
|
|
23
|
+
const prefix = baseUrl ?? "";
|
|
24
|
+
const description = `Navigate and use the ${siteName} documentation. Use when answering questions about ${siteName} or working with its docs.`;
|
|
25
|
+
const keyPages = buildSectionGroups(pages, sectionsConfig)
|
|
26
|
+
.flatMap((group) => group.categories)
|
|
27
|
+
.flatMap((cat) => cat.pages)
|
|
28
|
+
.slice(0, KEY_PAGE_LIMIT);
|
|
29
|
+
const lines = [];
|
|
30
|
+
lines.push("---");
|
|
31
|
+
lines.push(`name: ${siteDocsSlug(siteName)}`);
|
|
32
|
+
lines.push(`description: ${JSON.stringify(description)}`);
|
|
33
|
+
lines.push("---");
|
|
34
|
+
lines.push("");
|
|
35
|
+
lines.push(`# ${siteName} documentation`);
|
|
36
|
+
lines.push("");
|
|
37
|
+
if (siteDescription && siteDescription.trim() !== "") {
|
|
38
|
+
lines.push(siteDescription.trim());
|
|
39
|
+
lines.push("");
|
|
40
|
+
}
|
|
41
|
+
lines.push("## Reading these docs");
|
|
42
|
+
lines.push("");
|
|
43
|
+
lines.push(`- Documentation index: ${prefix}/llms.txt (full corpus: ${prefix}/llms-full.txt)`);
|
|
44
|
+
lines.push("- Every page has a markdown mirror: append .md to the page URL");
|
|
45
|
+
lines.push(`- MCP server with search_docs, get_doc, and list_docs tools: ${prefix}/api/mcp (streamable HTTP)`);
|
|
46
|
+
lines.push("");
|
|
47
|
+
if (keyPages.length > 0) {
|
|
48
|
+
lines.push("## Key pages");
|
|
49
|
+
lines.push("");
|
|
50
|
+
for (const page of keyPages) {
|
|
51
|
+
const desc = page.description && page.description.trim() !== ""
|
|
52
|
+
? ` - ${page.description.trim()}`
|
|
53
|
+
: "";
|
|
54
|
+
lines.push(`- [${page.title}](${pageUrl(page.slug, baseUrl)})${desc}`);
|
|
55
|
+
}
|
|
56
|
+
lines.push("");
|
|
57
|
+
}
|
|
58
|
+
return lines.join("\n");
|
|
59
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const mermaidMdxTemplate = "---\ntitle: \"Mermaid\"\ndescription: \"Create flowcharts, sequence diagrams, and other visualizations using Mermaid syntax.\"\ndate: \"2026-07-16\"\ncategory: \"Components\"\ncategoryOrder: 1\norder: 23\n---\n# Mermaid\n\nCreate flowcharts, sequence diagrams, and other visualizations using Mermaid syntax with automatic rendering.\n\nWrite a diagram inside a `mermaid` code fence and it renders as an SVG:\n\n````mdx\n```mermaid\nflowchart LR\n A[Start] --> B{Decision}\n B -->|Yes| C[Action]\n B -->|No| D[End]\n```\n````\n\n```mermaid\nflowchart LR\n A[Start] --> B{Decision}\n B -->|Yes| C[Action]\n B -->|No| D[End]\n```\n\nDiagrams are rendered when your site is built, so no diagramming library is shipped to your readers' browsers. They are drawn with your theme's colors and follow the light and dark toggle automatically.\n\n## Supported diagram types\n\nDoccupine renders diagrams with [beautiful-mermaid](https://github.com/lukilabs/beautiful-mermaid), which supports six diagram types:\n\n| Type | Opening keyword |\n| --- | --- |\n| Flowchart | `flowchart` or `graph` |\n| Sequence | `sequenceDiagram` |\n| State | `stateDiagram-v2` |\n| Class | `classDiagram` |\n| Entity relationship | `erDiagram` |\n| XY chart | `xychart-beta` |\n\nOther Mermaid diagram types - including `pie`, `gantt`, `mindmap`, `journey`, and `gitGraph` - are not supported. A diagram that cannot be rendered falls back to a plain code block showing its source, and the reason is logged when your site builds. A broken diagram never breaks the page.\n\n## Examples\n\n### Sequence diagram\n\n```mermaid\nsequenceDiagram\n participant Reader\n participant Docs\n participant Search\n Reader->>Docs: Open a page\n Docs->>Search: Index the content\n Search-->>Reader: Return results\n```\n\n### Subgraphs\n\n```mermaid placement=\"top-right\"\nflowchart LR\n subgraph one\n direction TB\n top1[top] --> bottom1[bottom]\n end\n subgraph two\n direction TB\n top2[top] --> bottom2[bottom]\n end\n outside --> one\n outside --> top2\n```\n\n## Interactive controls\n\nDiagrams include zoom in and out, pan in four directions, reset the view, and full screen. You can also drag a diagram with your mouse to move it around.\n\nBy default the controls appear once a diagram is taller than 120px, since a diagram that already fits does not need them. Use the `actions` property to decide explicitly. Setting `actions={false}` turns off the whole interactive layer, including dragging.\n\n## Properties\n\n<Field value=\"placement\" type=\"string\">\n Where the controls sit. One of `top-left`, `top-right`, `bottom-left`, or `bottom-right`. Defaults to `bottom-right`.\n</Field>\n\n<Field value=\"actions\" type=\"boolean\">\n Show or hide the controls. When set, this overrides the default behavior of showing them only on diagrams
|
|
1
|
+
export declare const mermaidMdxTemplate = "---\ntitle: \"Mermaid\"\ndescription: \"Create flowcharts, sequence diagrams, and other visualizations using Mermaid syntax.\"\ndate: \"2026-07-16\"\ncategory: \"Components\"\ncategoryOrder: 1\norder: 23\n---\n# Mermaid\n\nCreate flowcharts, sequence diagrams, and other visualizations using Mermaid syntax with automatic rendering.\n\nWrite a diagram inside a `mermaid` code fence and it renders as an SVG:\n\n````mdx\n```mermaid\nflowchart LR\n A[Start] --> B{Decision}\n B -->|Yes| C[Action]\n B -->|No| D[End]\n```\n````\n\n```mermaid\nflowchart LR\n A[Start] --> B{Decision}\n B -->|Yes| C[Action]\n B -->|No| D[End]\n```\n\nDiagrams are rendered when your site is built, so no diagramming library is shipped to your readers' browsers. They are drawn with your theme's colors and follow the light and dark toggle automatically.\n\n## Supported diagram types\n\nDoccupine renders diagrams with [beautiful-mermaid](https://github.com/lukilabs/beautiful-mermaid), which supports six diagram types:\n\n| Type | Opening keyword |\n| --- | --- |\n| Flowchart | `flowchart` or `graph` |\n| Sequence | `sequenceDiagram` |\n| State | `stateDiagram-v2` |\n| Class | `classDiagram` |\n| Entity relationship | `erDiagram` |\n| XY chart | `xychart-beta` |\n\nOther Mermaid diagram types - including `pie`, `gantt`, `mindmap`, `journey`, and `gitGraph` - are not supported. A diagram that cannot be rendered falls back to a plain code block showing its source, and the reason is logged when your site builds. A broken diagram never breaks the page.\n\n## Examples\n\n### Sequence diagram\n\n```mermaid\nsequenceDiagram\n participant Reader\n participant Docs\n participant Search\n Reader->>Docs: Open a page\n Docs->>Search: Index the content\n Search-->>Reader: Return results\n```\n\n### Subgraphs\n\n```mermaid placement=\"top-right\"\nflowchart LR\n subgraph one\n direction TB\n top1[top] --> bottom1[bottom]\n end\n subgraph two\n direction TB\n top2[top] --> bottom2[bottom]\n end\n outside --> one\n outside --> top2\n```\n\n## Interactive controls\n\nDiagrams include zoom in and out, pan in four directions, reset the view, and full screen. You can also drag a diagram with your mouse to move it around.\n\nBy default the controls appear once a diagram is taller than 120px, since a diagram that already fits does not need them. Use the `actions` property to decide explicitly. Setting `actions={false}` turns off the whole interactive layer, including dragging.\n\n## Properties\n\n<Field value=\"placement\" type=\"string\">\n Where the controls sit. One of `top-left`, `top-right`, `bottom-left`, or `bottom-right`. Defaults to `bottom-right`.\n</Field>\n\n<Field value=\"actions\" type=\"boolean\">\n Show or hide the controls. When set, this overrides the default behavior of showing them only on larger diagrams.\n</Field>\n\nSet properties on the opening fence, after the language:\n\n````mdx\n```mermaid placement=\"top-left\" actions={true}\nflowchart LR\n A --> B\n```\n````\n\nTo hide the controls entirely:\n\n````mdx\n```mermaid actions={false}\nflowchart LR\n A --> B\n```\n````\n\n```mermaid actions={false}\nflowchart LR\n A --> B\n```\n\n## Layout\n\nDiagrams are laid out with the [ELK](https://eclipse.dev/elk/) engine, which arranges nodes to reduce overlapping edges and keep large diagrams readable. It is always on, so no directive is needed to enable it.\n\nIf you are porting diagrams from another tool, a `%%{init: ...}%%` directive is read as a comment and ignored rather than causing an error.\n\n## Theming\n\nDiagram colors come from CSS variables, so they follow your theme and the light/dark toggle without re-rendering. Override any of them in your own CSS to restyle diagrams:\n\n```css\n:root {\n --mermaid-bg: var(--color-light);\n --mermaid-fg: var(--color-dark);\n --mermaid-line: var(--color-grayDark);\n --mermaid-accent: var(--color-accent);\n --mermaid-muted: var(--color-grayDark);\n --mermaid-surface: var(--color-grayLight);\n --mermaid-border: var(--color-gray);\n}\n```\n\n## Syntax reference\n\nFor the syntax of each supported diagram type, see the [Mermaid documentation](https://mermaid.js.org/intro/). Keep to the six types listed above.";
|
|
@@ -88,7 +88,7 @@ By default the controls appear once a diagram is taller than 120px, since a diag
|
|
|
88
88
|
</Field>
|
|
89
89
|
|
|
90
90
|
<Field value="actions" type="boolean">
|
|
91
|
-
Show or hide the controls. When set, this overrides the default behavior of showing them only on diagrams
|
|
91
|
+
Show or hide the controls. When set, this overrides the default behavior of showing them only on larger diagrams.
|
|
92
92
|
</Field>
|
|
93
93
|
|
|
94
94
|
Set properties on the opening fence, after the language:
|
|
@@ -13,6 +13,16 @@ const nextConfig: NextConfig = {
|
|
|
13
13
|
"/api/rag": ["./services/mcp/docs-index.json"],
|
|
14
14
|
"/api/mcp": ["./services/mcp/docs-index.json"],
|
|
15
15
|
},
|
|
16
|
+
// Discovery alias: agents probe /mcp for an MCP server. Auth for the alias
|
|
17
|
+
// is handled in the middleware, which runs before this rewrite.
|
|
18
|
+
async rewrites() {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
source: "/mcp",
|
|
22
|
+
destination: "/api/mcp",
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
},
|
|
16
26
|
};
|
|
17
27
|
|
|
18
28
|
export default nextConfig;
|
|
@@ -36,8 +46,15 @@ const nextConfig: NextConfig = {
|
|
|
36
46
|
"/api/rag": ["./services/mcp/docs-index.json"],
|
|
37
47
|
"/api/mcp": ["./services/mcp/docs-index.json"],
|
|
38
48
|
},
|
|
49
|
+
// The /mcp entry is a discovery alias: agents probe /mcp for an MCP server.
|
|
50
|
+
// Auth for the alias is handled in the middleware, which runs before this
|
|
51
|
+
// rewrite.
|
|
39
52
|
async rewrites() {
|
|
40
53
|
return [
|
|
54
|
+
{
|
|
55
|
+
source: "/mcp",
|
|
56
|
+
destination: "/api/mcp",
|
|
57
|
+
},
|
|
41
58
|
{
|
|
42
59
|
source: "/ingest/static/:path*",
|
|
43
60
|
destination: "${assetsHost}/static/:path*",
|
|
@@ -24,7 +24,7 @@ export const packageJsonTemplate = JSON.stringify({
|
|
|
24
24
|
minisearch: "^7.2.0",
|
|
25
25
|
next: "16.2.12",
|
|
26
26
|
"next-mdx-remote": "^6.0.0",
|
|
27
|
-
"posthog-js": "^1.407.
|
|
27
|
+
"posthog-js": "^1.407.4",
|
|
28
28
|
"posthog-node": "^5.46.1",
|
|
29
29
|
react: "19.2.8",
|
|
30
30
|
"react-dom": "19.2.8",
|
package/dist/templates/proxy.js
CHANGED
|
@@ -255,8 +255,10 @@ ${fnSignature} {
|
|
|
255
255
|
${trackingInit} const pathname = req.nextUrl.pathname;
|
|
256
256
|
const sitePassword = process.env.SITE_PASSWORD;
|
|
257
257
|
|
|
258
|
-
// API key auth for
|
|
259
|
-
|
|
258
|
+
// API key auth for the MCP endpoint when DOCS_API_KEY is configured. Also
|
|
259
|
+
// matches /mcp, the discovery alias that next.config rewrites to /api/mcp
|
|
260
|
+
// after the middleware has run.
|
|
261
|
+
if (pathname.startsWith("/api/mcp") || pathname === "/mcp") {
|
|
260
262
|
const apiKey = process.env.DOCS_API_KEY;
|
|
261
263
|
if (apiKey) {
|
|
262
264
|
const authHeader = req.headers.get("authorization");
|
|
@@ -308,6 +310,32 @@ ${trackingInit} const pathname = req.nextUrl.pathname;
|
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
|
|
313
|
+
// Content negotiation: agents that request markdown (Accept: text/markdown)
|
|
314
|
+
// are served the page's static .md mirror from public/. Runs after the
|
|
315
|
+
// SITE_PASSWORD gate so protected sites never expose markdown around the
|
|
316
|
+
// login screen. Only extensionless GET paths are rewritten, so assets, API
|
|
317
|
+
// routes, and the MCP alias stay untouched. The rewrite target is part of
|
|
318
|
+
// the CDN cache key, so HTML responses stay cacheable without a Vary header.
|
|
319
|
+
const accept = req.headers.get("accept") ?? "";
|
|
320
|
+
if (
|
|
321
|
+
req.method === "GET" &&
|
|
322
|
+
accept.includes("text/markdown") &&
|
|
323
|
+
!pathname.startsWith("/api") &&
|
|
324
|
+
!pathname.startsWith("/_next") &&
|
|
325
|
+
pathname !== "/gate" &&
|
|
326
|
+
pathname !== "/mcp" &&
|
|
327
|
+
!/\\.[a-z0-9]+$/i.test(pathname)
|
|
328
|
+
) {
|
|
329
|
+
const url = req.nextUrl.clone();
|
|
330
|
+
url.pathname =
|
|
331
|
+
pathname === "/" ? "/index.md" : pathname.replace(/\\/$/, "") + ".md";
|
|
332
|
+
const mdRes = NextResponse.rewrite(url);
|
|
333
|
+
if (sitePassword) {
|
|
334
|
+
mdRes.headers.set("X-Robots-Tag", "noindex, nofollow");
|
|
335
|
+
}
|
|
336
|
+
return applyTracking(mdRes, tracking);
|
|
337
|
+
}
|
|
338
|
+
|
|
311
339
|
const res = NextResponse.next();
|
|
312
340
|
|
|
313
341
|
// While password protection is active, keep the whole site out of search
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doccupine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.139",
|
|
4
4
|
"description": "Free and open-source documentation platform. Write MDX, get a production-ready site with AI chat, built-in components, and an MCP server - in one command.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|