reallysimpledocs 1.0.0-beta.4 → 1.0.0
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/README.md +59 -39
- package/package.json +11 -11
- package/src/astro/index.js +64 -98
- package/src/astro/preview-scripts.js +140 -0
- package/src/astro/preview-source.js +150 -0
- package/src/astro/rehype-basecoat-tables.js +62 -0
- package/src/components/index.js +1 -0
- package/src/css/custom.css +197 -58
- package/src/css/styles/luma.css +9 -0
- package/src/css/styles/lyra.css +9 -0
- package/src/css/styles/maia.css +9 -0
- package/src/css/styles/mira.css +9 -0
- package/src/css/styles/nova.css +9 -0
- package/src/css/styles/rhea.css +9 -0
- package/src/css/styles/sera.css +9 -0
- package/src/css/styles/vega.css +9 -0
- package/src/runtime/components/BaseLayout.astro +22 -28
- package/src/runtime/components/CommandDialog.astro +52 -35
- package/src/runtime/components/DefaultContentHeader.astro +0 -17
- package/src/runtime/components/DefaultHead.astro +110 -0
- package/src/runtime/components/DefaultHeadContent.astro +2 -0
- package/src/runtime/components/DefaultSidebarHeader.astro +1 -1
- package/src/runtime/components/DocsLayout.astro +99 -166
- package/src/runtime/components/DropdownMenu.astro +1 -1
- package/src/runtime/components/ThemeToggle.astro +21 -0
- package/src/runtime/components/mdx/Callout.astro +2 -32
- package/src/runtime/components/mdx/Card.astro +3 -8
- package/src/runtime/components/mdx/CardGrid.astro +1 -1
- package/src/runtime/components/mdx/Code.astro +21 -27
- package/src/runtime/components/mdx/CodeGroup.astro +114 -24
- package/src/runtime/components/mdx/Preview.astro +7 -13
- package/src/runtime/components/mdx/Steps.astro +1 -5
- package/src/runtime/components/mdx/Tab.astro +6 -0
- package/src/runtime/components/mdx/Tabs.astro +7 -7
- package/src/runtime/lib/code-meta.js +8 -0
- package/src/runtime/lib/docs.js +141 -119
- package/src/runtime/lib/highlight.js +1 -14
- package/src/runtime/lib/html.js +9 -0
- package/src/runtime/lib/macros.js +10 -5
- package/src/runtime/lib/markdown-export.js +240 -169
- package/src/runtime/pages/doc.astro +1 -3
- package/src/runtime/pages/llms-full.txt.ts +2 -2
- package/src/runtime/pages/llms.txt.ts +2 -2
- package/src/runtime/pages/markdown.ts +2 -2
- package/src/runtime/pages/search-index.ts +12 -3
- package/CHANGELOG.md +0 -35
- package/src/css/overrides.css +0 -1
- package/src/css/sources.css +0 -1
- package/src/runtime/lib/markdown-exporters/index.js +0 -144
- package/src/runtime/lib/mdx-source.js +0 -19
- package/src/runtime/lib/preview-source-plugin.js +0 -33
- package/src/runtime/scripts/copy-code.js +0 -130
- package/src/site/ContentHeader.astro +0 -33
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const serializers = {
|
|
2
|
-
Callout: renderCallout,
|
|
3
|
-
Code: renderCode,
|
|
4
|
-
CodeGroup: renderCodeGroup,
|
|
5
|
-
Preview: renderPreview,
|
|
6
|
-
Steps: renderSteps,
|
|
7
|
-
Tabs: renderChildren,
|
|
8
|
-
Card: renderCard,
|
|
9
|
-
CardGrid: renderCardGrid,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export async function serializeComponent(node, context, customSerializers = {}) {
|
|
13
|
-
if (customSerializers[node.name]) return await customSerializers[node.name](node, context);
|
|
14
|
-
return serializers[node.name]?.(node, context) || null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function renderChildren(node, context) {
|
|
18
|
-
return await context.transformBlocks(node.children || []);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function renderCallout(node, context) {
|
|
22
|
-
const title = context.getAttr(node, "title");
|
|
23
|
-
const action = context.getAttr(node, "action");
|
|
24
|
-
const children = await context.transformBlocks(node.children || []);
|
|
25
|
-
const quoteChildren = [];
|
|
26
|
-
if (title) quoteChildren.push(strongParagraph(title));
|
|
27
|
-
quoteChildren.push(...children);
|
|
28
|
-
if (action?.label) {
|
|
29
|
-
quoteChildren.push({
|
|
30
|
-
type: "paragraph",
|
|
31
|
-
children: action.href
|
|
32
|
-
? [{ type: "link", url: action.href, children: [{ type: "text", value: action.label }] }]
|
|
33
|
-
: [{ type: "strong", children: [{ type: "text", value: action.label }] }],
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return [{ type: "blockquote", children: quoteChildren }];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function renderCode(node, context) {
|
|
40
|
-
const title = context.getAttr(node, "title") || context.getAttr(node, "slot");
|
|
41
|
-
const lang = context.getAttr(node, "lang") || "text";
|
|
42
|
-
const value = context.getCodeValue(node);
|
|
43
|
-
const blocks = [];
|
|
44
|
-
if (title) blocks.push(strongParagraph(title));
|
|
45
|
-
blocks.push({ type: "code", lang, value });
|
|
46
|
-
return blocks;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function renderCodeGroup(node, context) {
|
|
50
|
-
const codeNodes = collectCodeChildren(node, context);
|
|
51
|
-
if (!codeNodes.length) return renderChildren(node, context);
|
|
52
|
-
return codeNodes.flatMap((child, index) => {
|
|
53
|
-
const blocks = renderCode(child, context);
|
|
54
|
-
return index === 0 ? blocks : [{ type: "thematicBreak" }, ...blocks];
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function renderPreview(node, context) {
|
|
59
|
-
const value = context.getAttr(node, "code") || context.getChildrenSource(node);
|
|
60
|
-
if (value) {
|
|
61
|
-
return [{ type: "code", lang: context.getAttr(node, "lang") || "mdx", value }];
|
|
62
|
-
}
|
|
63
|
-
return await renderChildren(node, context);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function renderSteps(node, context) {
|
|
67
|
-
const steps = (node.children || []).filter((child) => context.isNamedElement(child, "Step"));
|
|
68
|
-
if (!steps.length) return await renderChildren(node, context);
|
|
69
|
-
const children = [];
|
|
70
|
-
for (const step of steps) {
|
|
71
|
-
children.push({
|
|
72
|
-
type: "listItem",
|
|
73
|
-
spread: true,
|
|
74
|
-
children: await stepToBlocks(step, context),
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return [
|
|
78
|
-
{
|
|
79
|
-
type: "list",
|
|
80
|
-
ordered: true,
|
|
81
|
-
spread: true,
|
|
82
|
-
children,
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function renderCard(node, context) {
|
|
88
|
-
return [cardList([node], context)];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function renderCardGrid(node, context) {
|
|
92
|
-
return [cardList((node.children || []).filter((child) => context.isNamedElement(child, "Card")), context)];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async function stepToBlocks(node, context) {
|
|
96
|
-
const title = context.getAttr(node, "title");
|
|
97
|
-
const children = await context.transformBlocks(node.children || []);
|
|
98
|
-
if (!title) return children;
|
|
99
|
-
return [strongParagraph(title), ...children];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function cardList(cards, context) {
|
|
103
|
-
return {
|
|
104
|
-
type: "list",
|
|
105
|
-
ordered: false,
|
|
106
|
-
spread: true,
|
|
107
|
-
children: cards.map((card) => ({
|
|
108
|
-
type: "listItem",
|
|
109
|
-
spread: false,
|
|
110
|
-
children: [cardParagraph(card, context)],
|
|
111
|
-
})),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function cardParagraph(node, context) {
|
|
116
|
-
const title = context.getAttr(node, "title") || "Card";
|
|
117
|
-
const description = context.getAttr(node, "description");
|
|
118
|
-
const href = context.getAttr(node, "href");
|
|
119
|
-
const titleNode =
|
|
120
|
-
href && href !== "#"
|
|
121
|
-
? { type: "link", url: href, children: [{ type: "text", value: title }] }
|
|
122
|
-
: { type: "strong", children: [{ type: "text", value: title }] };
|
|
123
|
-
return {
|
|
124
|
-
type: "paragraph",
|
|
125
|
-
children: description ? [titleNode, { type: "text", value: `: ${description}` }] : [titleNode],
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function collectCodeChildren(node, context) {
|
|
130
|
-
return (node.children || []).flatMap((child) => {
|
|
131
|
-
if (context.isNamedElement(child, "Code")) return [child];
|
|
132
|
-
if (child.type === "paragraph") {
|
|
133
|
-
return context.significantChildren(child.children || []).filter((entry) => context.isNamedElement(entry, "Code"));
|
|
134
|
-
}
|
|
135
|
-
return [];
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function strongParagraph(value) {
|
|
140
|
-
return {
|
|
141
|
-
type: "paragraph",
|
|
142
|
-
children: [{ type: "strong", children: [{ type: "text", value }] }],
|
|
143
|
-
};
|
|
144
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function getMdxChildrenSource(node, source) {
|
|
2
|
-
const children = node?.children || [];
|
|
3
|
-
const first = children[0];
|
|
4
|
-
const last = children.at(-1);
|
|
5
|
-
const start = first?.position?.start?.offset;
|
|
6
|
-
const end = last?.position?.end?.offset;
|
|
7
|
-
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return "";
|
|
8
|
-
return trimCode(String(source || "").slice(start, end));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function trimCode(value) {
|
|
12
|
-
const lines = String(value || "").replace(/\r\n/g, "\n").split("\n");
|
|
13
|
-
while (lines.length && !lines[0].trim()) lines.shift();
|
|
14
|
-
while (lines.length && !lines.at(-1).trim()) lines.pop();
|
|
15
|
-
const indent = lines
|
|
16
|
-
.filter((line) => line.trim())
|
|
17
|
-
.reduce((min, line) => Math.min(min, line.match(/^\s*/)[0].length), Infinity);
|
|
18
|
-
return lines.map((line) => line.slice(Number.isFinite(indent) ? indent : 0)).join("\n");
|
|
19
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { getMdxChildrenSource } from "./mdx-source.js";
|
|
2
|
-
|
|
3
|
-
export function previewSourceRemarkPlugin() {
|
|
4
|
-
return (tree, file) => {
|
|
5
|
-
const source = String(file.value || "");
|
|
6
|
-
walk(tree, (node) => {
|
|
7
|
-
if (!isPreview(node) || hasAttribute(node, "code")) return;
|
|
8
|
-
const code = getMdxChildrenSource(node, source);
|
|
9
|
-
node.attributes = [
|
|
10
|
-
...(node.attributes || []),
|
|
11
|
-
{
|
|
12
|
-
type: "mdxJsxAttribute",
|
|
13
|
-
name: "code",
|
|
14
|
-
value: code,
|
|
15
|
-
},
|
|
16
|
-
];
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function walk(node, callback) {
|
|
22
|
-
if (!node || typeof node !== "object") return;
|
|
23
|
-
callback(node);
|
|
24
|
-
for (const child of node.children || []) walk(child, callback);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isPreview(node) {
|
|
28
|
-
return node?.type === "mdxJsxFlowElement" && node.name === "Preview";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function hasAttribute(node, name) {
|
|
32
|
-
return (node.attributes || []).some((attr) => attr.type === "mdxJsxAttribute" && attr.name === name);
|
|
33
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import Copy from "lucide-static/icons/copy.svg?raw";
|
|
2
|
-
import Check from "lucide-static/icons/check.svg?raw";
|
|
3
|
-
|
|
4
|
-
const copyText = async (text) => {
|
|
5
|
-
if (window.isSecureContext && navigator.clipboard?.writeText) {
|
|
6
|
-
return navigator.clipboard.writeText(text);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const textarea = document.createElement("textarea");
|
|
10
|
-
textarea.value = text;
|
|
11
|
-
textarea.setAttribute("readonly", "");
|
|
12
|
-
textarea.style.position = "fixed";
|
|
13
|
-
textarea.style.top = "-9999px";
|
|
14
|
-
textarea.style.left = "-9999px";
|
|
15
|
-
document.body.appendChild(textarea);
|
|
16
|
-
textarea.select();
|
|
17
|
-
const ok = document.execCommand("copy");
|
|
18
|
-
textarea.remove();
|
|
19
|
-
if (!ok) throw new Error("Copy failed");
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const activePanelCode = (root) =>
|
|
23
|
-
root.querySelector(':scope > [role="tabpanel"]:not([hidden]) code');
|
|
24
|
-
const codeFrameClass =
|
|
25
|
-
"relative my-6 w-full max-w-full overflow-hidden rounded-lg";
|
|
26
|
-
const codePreClasses = [
|
|
27
|
-
"!my-0",
|
|
28
|
-
"max-w-full",
|
|
29
|
-
"overflow-x-auto",
|
|
30
|
-
"!rounded-none",
|
|
31
|
-
"!border-0",
|
|
32
|
-
];
|
|
33
|
-
const codeContentClasses = [
|
|
34
|
-
"block",
|
|
35
|
-
"min-w-full",
|
|
36
|
-
"w-max",
|
|
37
|
-
"px-4",
|
|
38
|
-
"py-3",
|
|
39
|
-
"text-[13px]",
|
|
40
|
-
];
|
|
41
|
-
const copyButtonClass =
|
|
42
|
-
"flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 dark:hover:bg-accent/50 [&_svg]:size-4";
|
|
43
|
-
|
|
44
|
-
const initCopyCode = (codeBlock) => {
|
|
45
|
-
const codeEl = codeBlock.querySelector(":scope > code");
|
|
46
|
-
if (!codeEl) return;
|
|
47
|
-
|
|
48
|
-
codeBlock.classList.add(...codePreClasses);
|
|
49
|
-
codeEl.classList.add(...codeContentClasses);
|
|
50
|
-
|
|
51
|
-
let target = null;
|
|
52
|
-
let frame = codeBlock.closest("[data-code-group]");
|
|
53
|
-
let getCode = frame ? () => activePanelCode(frame) || codeEl : () => codeEl;
|
|
54
|
-
if (frame) target = frame.querySelector(":scope > header");
|
|
55
|
-
|
|
56
|
-
const preview = codeBlock.closest("[data-preview]");
|
|
57
|
-
const previewCodePanel = preview?.querySelector(":scope > [data-code-panel]");
|
|
58
|
-
if (!frame && previewCodePanel?.contains(codeBlock)) {
|
|
59
|
-
frame = preview;
|
|
60
|
-
target = frame.querySelector(":scope > header");
|
|
61
|
-
getCode = () => codeEl;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!frame) {
|
|
65
|
-
frame = codeBlock.parentElement?.hasAttribute("data-code-block")
|
|
66
|
-
? codeBlock.parentElement
|
|
67
|
-
: null;
|
|
68
|
-
if (!frame) {
|
|
69
|
-
frame = document.createElement("div");
|
|
70
|
-
frame.dataset.codeBlock = "";
|
|
71
|
-
frame.className = codeFrameClass;
|
|
72
|
-
codeBlock.parentNode.insertBefore(frame, codeBlock);
|
|
73
|
-
frame.appendChild(codeBlock);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
target ||= frame.querySelector(":scope > header") || frame;
|
|
78
|
-
|
|
79
|
-
if (target.querySelector(":scope > button[aria-label='Copy code']")) {
|
|
80
|
-
codeBlock.dataset.copyCodeInitialized = true;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const button = document.createElement("button");
|
|
85
|
-
button.type = "button";
|
|
86
|
-
button.setAttribute("aria-label", "Copy code");
|
|
87
|
-
button.className = `${copyButtonClass} ${
|
|
88
|
-
target === frame
|
|
89
|
-
? "absolute right-2.5 top-2.5 bg-muted/50 backdrop-blur-sm"
|
|
90
|
-
: "ml-auto"
|
|
91
|
-
}`;
|
|
92
|
-
button.innerHTML = Copy;
|
|
93
|
-
|
|
94
|
-
button.addEventListener("click", async () => {
|
|
95
|
-
const text = (getCode()?.textContent || "").replace(/\n$/, "");
|
|
96
|
-
if (!text) return;
|
|
97
|
-
|
|
98
|
-
button.disabled = true;
|
|
99
|
-
try {
|
|
100
|
-
await copyText(text);
|
|
101
|
-
button.innerHTML = Check;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
console.error("[copy] Failed to copy:", error);
|
|
104
|
-
button.textContent = "Failed";
|
|
105
|
-
}
|
|
106
|
-
window.setTimeout(() => {
|
|
107
|
-
button.disabled = false;
|
|
108
|
-
button.innerHTML = Copy;
|
|
109
|
-
}, 1200);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
target.appendChild(button);
|
|
113
|
-
if (previewCodePanel?.contains(codeBlock)) {
|
|
114
|
-
const syncPreviewCopyButton = () => {
|
|
115
|
-
button.hidden = previewCodePanel.hidden;
|
|
116
|
-
};
|
|
117
|
-
syncPreviewCopyButton();
|
|
118
|
-
new MutationObserver(syncPreviewCopyButton).observe(previewCodePanel, {
|
|
119
|
-
attributes: true,
|
|
120
|
-
attributeFilter: ["hidden"],
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
codeBlock.dataset.copyCodeInitialized = true;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
window.basecoat?.register(
|
|
127
|
-
"copy-code",
|
|
128
|
-
"pre:has(> code):not([data-copy-code-initialized])",
|
|
129
|
-
initCopyCode,
|
|
130
|
-
);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Moon from "lucide-static/icons/moon.svg?raw";
|
|
3
|
-
import Sun from "lucide-static/icons/sun.svg?raw";
|
|
4
|
-
|
|
5
|
-
const github = `<svg role="img" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>`;
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
<nav class="hidden items-center gap-2 sm:flex">
|
|
9
|
-
<a
|
|
10
|
-
class="btn-sm"
|
|
11
|
-
href="https://github.com/hunvreus/reallysimpledocs"
|
|
12
|
-
target="_blank"
|
|
13
|
-
rel="noopener"
|
|
14
|
-
aria-label="GitHub"
|
|
15
|
-
data-tooltip="GitHub"
|
|
16
|
-
data-side="bottom"
|
|
17
|
-
>
|
|
18
|
-
<Fragment set:html={github} />
|
|
19
|
-
GitHub
|
|
20
|
-
</a>
|
|
21
|
-
<button
|
|
22
|
-
type="button"
|
|
23
|
-
aria-label="Toggle dark mode"
|
|
24
|
-
data-tooltip="Toggle dark mode"
|
|
25
|
-
data-side="bottom"
|
|
26
|
-
data-align="end"
|
|
27
|
-
onclick="document.dispatchEvent(new CustomEvent('basecoat:theme'))"
|
|
28
|
-
class="btn-sm-icon-ghost"
|
|
29
|
-
>
|
|
30
|
-
<span class="hidden dark:block"><Fragment set:html={Sun} /></span>
|
|
31
|
-
<span class="block dark:hidden"><Fragment set:html={Moon} /></span>
|
|
32
|
-
</button>
|
|
33
|
-
</nav>
|