@yuhuanowo/yunui 0.2.15 → 0.2.16
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 +2 -0
- package/dist/adapters.js +1 -1
- package/dist/ai.js +13 -9
- package/dist/ai.js.map +1 -1
- package/dist/chat.d.ts +133 -0
- package/dist/chat.js +268 -0
- package/dist/chat.js.map +1 -0
- package/dist/{chunk-U2LNRVMI.js → chunk-3RT24MSH.js} +4 -3
- package/dist/chunk-3RT24MSH.js.map +1 -0
- package/dist/chunk-5E3O6ANF.js +1154 -0
- package/dist/chunk-5E3O6ANF.js.map +1 -0
- package/dist/{chunk-6MZN3GOP.js → chunk-5TOGZTAO.js} +218 -835
- package/dist/chunk-5TOGZTAO.js.map +1 -0
- package/dist/chunk-AV5TGEJS.js +54 -0
- package/dist/chunk-AV5TGEJS.js.map +1 -0
- package/dist/{chunk-LLNTUA5K.js → chunk-GSPJ5YI6.js} +15 -56
- package/dist/chunk-GSPJ5YI6.js.map +1 -0
- package/dist/chunk-QEIBYOG2.js +188 -0
- package/dist/chunk-QEIBYOG2.js.map +1 -0
- package/dist/{chunk-N53PNMPJ.js → chunk-UYYG4XDW.js} +3 -3
- package/dist/{chunk-N53PNMPJ.js.map → chunk-UYYG4XDW.js.map} +1 -1
- package/dist/content.d.ts +144 -0
- package/dist/content.js +890 -0
- package/dist/content.js.map +1 -0
- package/dist/index.d.ts +183 -5
- package/dist/index.js +5 -3
- package/dist/patterns.d.ts +87 -1
- package/dist/patterns.js +446 -8
- package/dist/patterns.js.map +1 -1
- package/package.json +77 -5
- package/styles/content.css +129 -0
- package/styles/yunui.css +24 -4
- package/dist/chunk-6MZN3GOP.js.map +0 -1
- package/dist/chunk-LLNTUA5K.js.map +0 -1
- package/dist/chunk-U2LNRVMI.js.map +0 -1
package/dist/content.js
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContentT, ImageLightbox } from './chunk-QEIBYOG2.js';
|
|
3
|
+
export { ImageLightbox } from './chunk-QEIBYOG2.js';
|
|
4
|
+
import { Alert } from './chunk-5TOGZTAO.js';
|
|
5
|
+
import { cn } from './chunk-AV5TGEJS.js';
|
|
6
|
+
import './chunk-3RT24MSH.js';
|
|
7
|
+
import * as React2 from 'react';
|
|
8
|
+
import { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
9
|
+
import ReactMarkdown from 'react-markdown';
|
|
10
|
+
import remarkGfm from 'remark-gfm';
|
|
11
|
+
import remarkMath from 'remark-math';
|
|
12
|
+
import rehypeRaw from 'rehype-raw';
|
|
13
|
+
import rehypeKatex from 'rehype-katex';
|
|
14
|
+
import rehypeSlug from 'rehype-slug';
|
|
15
|
+
import { Edit3, Check, Copy, CheckCircle2, XOctagon, AlertTriangle, AlertCircle, Lightbulb, Info, ExternalLink, Link2 } from 'lucide-react';
|
|
16
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
17
|
+
import katex from 'katex';
|
|
18
|
+
|
|
19
|
+
var languageNames = {
|
|
20
|
+
js: "JavaScript",
|
|
21
|
+
javascript: "JavaScript",
|
|
22
|
+
ts: "TypeScript",
|
|
23
|
+
typescript: "TypeScript",
|
|
24
|
+
tsx: "TSX",
|
|
25
|
+
jsx: "JSX",
|
|
26
|
+
py: "Python",
|
|
27
|
+
python: "Python",
|
|
28
|
+
rb: "Ruby",
|
|
29
|
+
ruby: "Ruby",
|
|
30
|
+
go: "Go",
|
|
31
|
+
rust: "Rust",
|
|
32
|
+
rs: "Rust",
|
|
33
|
+
cpp: "C++",
|
|
34
|
+
c: "C",
|
|
35
|
+
java: "Java",
|
|
36
|
+
kotlin: "Kotlin",
|
|
37
|
+
kt: "Kotlin",
|
|
38
|
+
swift: "Swift",
|
|
39
|
+
php: "PHP",
|
|
40
|
+
sql: "SQL",
|
|
41
|
+
html: "HTML",
|
|
42
|
+
css: "CSS",
|
|
43
|
+
scss: "SCSS",
|
|
44
|
+
sass: "Sass",
|
|
45
|
+
json: "JSON",
|
|
46
|
+
yaml: "YAML",
|
|
47
|
+
yml: "YAML",
|
|
48
|
+
xml: "XML",
|
|
49
|
+
md: "Markdown",
|
|
50
|
+
markdown: "Markdown",
|
|
51
|
+
bash: "Bash",
|
|
52
|
+
sh: "Shell",
|
|
53
|
+
shell: "Shell",
|
|
54
|
+
zsh: "Zsh",
|
|
55
|
+
powershell: "PowerShell",
|
|
56
|
+
ps1: "PowerShell",
|
|
57
|
+
dockerfile: "Dockerfile",
|
|
58
|
+
docker: "Docker",
|
|
59
|
+
graphql: "GraphQL",
|
|
60
|
+
vue: "Vue",
|
|
61
|
+
svelte: "Svelte",
|
|
62
|
+
diff: "Diff",
|
|
63
|
+
plaintext: "Plain Text",
|
|
64
|
+
text: "Plain Text"
|
|
65
|
+
};
|
|
66
|
+
var langExtMap = {
|
|
67
|
+
typescript: "ts",
|
|
68
|
+
javascript: "js",
|
|
69
|
+
python: "py",
|
|
70
|
+
bash: "sh",
|
|
71
|
+
shell: "sh",
|
|
72
|
+
markdown: "md"
|
|
73
|
+
};
|
|
74
|
+
function useIsDarkMode() {
|
|
75
|
+
const [isDark, setIsDark] = useState(false);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const check = () => setIsDark(document.documentElement.classList.contains("dark"));
|
|
78
|
+
check();
|
|
79
|
+
const observer = new MutationObserver(check);
|
|
80
|
+
observer.observe(document.documentElement, {
|
|
81
|
+
attributes: true,
|
|
82
|
+
attributeFilter: ["class"]
|
|
83
|
+
});
|
|
84
|
+
return () => observer.disconnect();
|
|
85
|
+
}, []);
|
|
86
|
+
return isDark;
|
|
87
|
+
}
|
|
88
|
+
function CodeBlock({
|
|
89
|
+
children,
|
|
90
|
+
language = "plaintext",
|
|
91
|
+
showLineNumbers = false,
|
|
92
|
+
highlightLines = [],
|
|
93
|
+
filename,
|
|
94
|
+
className,
|
|
95
|
+
onEdit
|
|
96
|
+
}) {
|
|
97
|
+
const [copied, setCopied] = useState(false);
|
|
98
|
+
const [highlightedCode, setHighlightedCode] = useState("");
|
|
99
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
100
|
+
const isDark = useIsDarkMode();
|
|
101
|
+
const t = useContentT();
|
|
102
|
+
const code = useMemo(
|
|
103
|
+
() => typeof children === "string" ? children.trim() : String(children).trim(),
|
|
104
|
+
[children]
|
|
105
|
+
);
|
|
106
|
+
const displayLanguage = languageNames[language?.toLowerCase()] || language?.toUpperCase() || "CODE";
|
|
107
|
+
const handleEdit = useCallback(() => {
|
|
108
|
+
if (!onEdit) return;
|
|
109
|
+
const ext = langExtMap[language?.toLowerCase()] || language || "txt";
|
|
110
|
+
onEdit({ code, language, filename: filename || `snippet.${ext}` });
|
|
111
|
+
}, [onEdit, code, language, filename]);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
let cancelled = false;
|
|
114
|
+
async function highlight() {
|
|
115
|
+
setIsLoading(true);
|
|
116
|
+
try {
|
|
117
|
+
const { codeToHtml } = await import('shiki');
|
|
118
|
+
const theme = isDark ? "github-dark" : "github-light";
|
|
119
|
+
const lang = language?.toLowerCase() || "plaintext";
|
|
120
|
+
const html = await codeToHtml(code, {
|
|
121
|
+
lang,
|
|
122
|
+
theme,
|
|
123
|
+
transformers: [
|
|
124
|
+
{
|
|
125
|
+
line(node, line) {
|
|
126
|
+
if (showLineNumbers) node.properties["data-line"] = line;
|
|
127
|
+
if (highlightLines.includes(line)) {
|
|
128
|
+
node.properties["class"] = `${node.properties["class"] || ""} highlighted-line`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
if (!cancelled) {
|
|
135
|
+
setHighlightedCode(html);
|
|
136
|
+
setIsLoading(false);
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
if (!cancelled) {
|
|
140
|
+
setHighlightedCode(
|
|
141
|
+
`<pre class="shiki"><code>${escapeHtml(code)}</code></pre>`
|
|
142
|
+
);
|
|
143
|
+
setIsLoading(false);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
highlight();
|
|
148
|
+
return () => {
|
|
149
|
+
cancelled = true;
|
|
150
|
+
};
|
|
151
|
+
}, [code, language, isDark, showLineNumbers, highlightLines]);
|
|
152
|
+
const handleCopy = async () => {
|
|
153
|
+
try {
|
|
154
|
+
if (navigator.clipboard?.writeText) {
|
|
155
|
+
await navigator.clipboard.writeText(code);
|
|
156
|
+
} else {
|
|
157
|
+
const textArea = document.createElement("textarea");
|
|
158
|
+
textArea.value = code;
|
|
159
|
+
document.body.appendChild(textArea);
|
|
160
|
+
textArea.select();
|
|
161
|
+
document.execCommand("copy");
|
|
162
|
+
document.body.removeChild(textArea);
|
|
163
|
+
}
|
|
164
|
+
setCopied(true);
|
|
165
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const btnBase = "flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-all hover:bg-(--accent-subtle) outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
|
170
|
+
return /* @__PURE__ */ jsxs(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
className: cn(
|
|
174
|
+
"card group my-4 overflow-hidden max-w-full min-w-0",
|
|
175
|
+
className
|
|
176
|
+
),
|
|
177
|
+
children: [
|
|
178
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2.5 border-b border-(--border-hairline) bg-(--bg-elevated)", children: [
|
|
179
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5", children: [
|
|
180
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
|
|
181
|
+
/* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full bg-(--error) opacity-80" }),
|
|
182
|
+
/* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full bg-(--warning) opacity-80" }),
|
|
183
|
+
/* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full bg-(--success) opacity-80" })
|
|
184
|
+
] }),
|
|
185
|
+
filename ? /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-(--text-secondary) font-mono", children: filename }) : /* @__PURE__ */ jsx("span", { className: "badge text-xs", children: displayLanguage })
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
188
|
+
onEdit && /* @__PURE__ */ jsxs("button", { onClick: handleEdit, className: cn(btnBase, "text-(--text-tertiary)"), children: [
|
|
189
|
+
/* @__PURE__ */ jsx(Edit3, { className: "w-3.5 h-3.5" }),
|
|
190
|
+
t("edit", "Edit")
|
|
191
|
+
] }),
|
|
192
|
+
/* @__PURE__ */ jsx("button", { onClick: handleCopy, className: btnBase, children: copied ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
193
|
+
/* @__PURE__ */ jsx(Check, { className: "w-3.5 h-3.5 text-(--success)" }),
|
|
194
|
+
/* @__PURE__ */ jsx("span", { className: "text-(--success)", children: t("copied", "Copied") })
|
|
195
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
196
|
+
/* @__PURE__ */ jsx(Copy, { className: "w-3.5 h-3.5 text-(--text-tertiary)" }),
|
|
197
|
+
/* @__PURE__ */ jsx("span", { className: "text-(--text-tertiary)", children: t("copy", "Copy") })
|
|
198
|
+
] }) })
|
|
199
|
+
] })
|
|
200
|
+
] }),
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
"div",
|
|
203
|
+
{
|
|
204
|
+
className: cn(
|
|
205
|
+
"overflow-x-auto overflow-y-auto p-4 max-h-100 bg-(--bg-base)",
|
|
206
|
+
showLineNumbers && "code-with-line-numbers"
|
|
207
|
+
),
|
|
208
|
+
children: isLoading ? /* @__PURE__ */ jsx("pre", { className: "text-sm font-mono", children: /* @__PURE__ */ jsx("code", { children: code }) }) : /* @__PURE__ */ jsx(
|
|
209
|
+
"div",
|
|
210
|
+
{
|
|
211
|
+
className: "shiki-wrapper text-sm [&_pre]:bg-transparent! [&_code]:bg-transparent!",
|
|
212
|
+
dangerouslySetInnerHTML: { __html: highlightedCode }
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
function InlineCode({
|
|
222
|
+
children,
|
|
223
|
+
className
|
|
224
|
+
}) {
|
|
225
|
+
return /* @__PURE__ */ jsx(
|
|
226
|
+
"code",
|
|
227
|
+
{
|
|
228
|
+
className: cn(
|
|
229
|
+
"px-1.5 py-0.5 mx-0.5 rounded text-sm font-mono",
|
|
230
|
+
"bg-(--accent-subtle) text-(--text-primary) border border-(--border-hairline)",
|
|
231
|
+
"wrap-break-word",
|
|
232
|
+
className
|
|
233
|
+
),
|
|
234
|
+
children
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
function escapeHtml(str) {
|
|
239
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
240
|
+
}
|
|
241
|
+
var mermaidSeq = 0;
|
|
242
|
+
var NEEDS_MANUAL_ROUGHENING = /* @__PURE__ */ new Set([
|
|
243
|
+
"sequenceDiagram",
|
|
244
|
+
"gantt",
|
|
245
|
+
"pie",
|
|
246
|
+
"journey",
|
|
247
|
+
"gitGraph",
|
|
248
|
+
"timeline",
|
|
249
|
+
"mindmap",
|
|
250
|
+
"quadrantChart",
|
|
251
|
+
"xychart-beta",
|
|
252
|
+
"sankey-beta",
|
|
253
|
+
"packet-beta"
|
|
254
|
+
]);
|
|
255
|
+
function diagramType(chart) {
|
|
256
|
+
const lines = chart.trim().split("\n");
|
|
257
|
+
let i = 0;
|
|
258
|
+
if (lines[0]?.trim() === "---") {
|
|
259
|
+
i = 1;
|
|
260
|
+
while (i < lines.length && lines[i].trim() !== "---") i++;
|
|
261
|
+
i++;
|
|
262
|
+
}
|
|
263
|
+
for (; i < lines.length; i++) {
|
|
264
|
+
const l = lines[i].trim();
|
|
265
|
+
if (!l || l.startsWith("%%")) continue;
|
|
266
|
+
return l.split(/[\s:({]/)[0];
|
|
267
|
+
}
|
|
268
|
+
return "";
|
|
269
|
+
}
|
|
270
|
+
function needsManualRoughening(chart) {
|
|
271
|
+
return NEEDS_MANUAL_ROUGHENING.has(diagramType(chart));
|
|
272
|
+
}
|
|
273
|
+
function roughenSvg(svg, id) {
|
|
274
|
+
const vb = svg.match(/viewBox="([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)"/);
|
|
275
|
+
if (!vb) return svg;
|
|
276
|
+
const [, mx, my, w, h] = vb.map(Number);
|
|
277
|
+
const pad = 12;
|
|
278
|
+
const fid = `${id}-rough`;
|
|
279
|
+
const defs = `<defs><filter id="${fid}" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse" x="${mx - pad}" y="${my - pad}" width="${w + pad * 2}" height="${h + pad * 2}"><feTurbulence type="fractalNoise" baseFrequency="0.014" numOctaves="2" seed="7" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale="2.4" xChannelSelector="R" yChannelSelector="G"/></filter></defs><style>#${id} path,#${id} rect,#${id} circle,#${id} ellipse,#${id} line,#${id} polygon,#${id} polyline{filter:url(#${fid})}#${id} text,#${id} tspan{filter:none}</style>`;
|
|
280
|
+
return svg.replace(/(<svg\b[^>]*>)/, `$1${defs}`);
|
|
281
|
+
}
|
|
282
|
+
function MermaidDiagram({
|
|
283
|
+
chart,
|
|
284
|
+
className,
|
|
285
|
+
enableZoom = true
|
|
286
|
+
}) {
|
|
287
|
+
const containerRef = useRef(null);
|
|
288
|
+
const [svg, setSvg] = useState("");
|
|
289
|
+
const [error, setError] = useState("");
|
|
290
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
291
|
+
const [themeTick, setThemeTick] = useState(0);
|
|
292
|
+
const [zoomOpen, setZoomOpen] = useState(false);
|
|
293
|
+
const t = useContentT();
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
let cancelled = false;
|
|
296
|
+
async function renderDiagram() {
|
|
297
|
+
setIsLoading(true);
|
|
298
|
+
setError("");
|
|
299
|
+
const diagramId = `yunui-mermaid-${mermaidSeq += 1}`;
|
|
300
|
+
try {
|
|
301
|
+
const mermaid = (await import('mermaid')).default;
|
|
302
|
+
const isDark = typeof document !== "undefined" && document.documentElement.classList.contains("dark");
|
|
303
|
+
mermaid.initialize({
|
|
304
|
+
startOnLoad: false,
|
|
305
|
+
theme: isDark ? "dark" : "default",
|
|
306
|
+
// Native rough.js hand-drawn look — clean output for the types it
|
|
307
|
+
// supports (flowchart, state, class, ER, requirement, C4, block…).
|
|
308
|
+
look: "handDrawn",
|
|
309
|
+
handDrawnSeed: 1,
|
|
310
|
+
securityLevel: "loose",
|
|
311
|
+
fontFamily: '"Comic Sans MS", "Segoe Print", ui-rounded, system-ui, sans-serif',
|
|
312
|
+
flowchart: { curve: "basis", padding: 20 },
|
|
313
|
+
sequence: { diagramMarginX: 20, diagramMarginY: 20 },
|
|
314
|
+
gantt: { barHeight: 20, barGap: 4 }
|
|
315
|
+
});
|
|
316
|
+
const { svg: renderedSvg } = await mermaid.render(diagramId, chart.trim());
|
|
317
|
+
if (!cancelled) {
|
|
318
|
+
setSvg(
|
|
319
|
+
needsManualRoughening(chart) ? roughenSvg(renderedSvg, diagramId) : renderedSvg
|
|
320
|
+
);
|
|
321
|
+
setIsLoading(false);
|
|
322
|
+
}
|
|
323
|
+
} catch (err) {
|
|
324
|
+
if (!cancelled) {
|
|
325
|
+
setError(
|
|
326
|
+
err instanceof Error ? err.message : t("diagramRenderFailed", "Failed to render diagram")
|
|
327
|
+
);
|
|
328
|
+
setIsLoading(false);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
renderDiagram();
|
|
333
|
+
return () => {
|
|
334
|
+
cancelled = true;
|
|
335
|
+
};
|
|
336
|
+
}, [chart, themeTick]);
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
if (typeof document === "undefined") return;
|
|
339
|
+
const observer = new MutationObserver(() => setThemeTick((n) => n + 1));
|
|
340
|
+
observer.observe(document.documentElement, {
|
|
341
|
+
attributes: true,
|
|
342
|
+
attributeFilter: ["class"]
|
|
343
|
+
});
|
|
344
|
+
return () => observer.disconnect();
|
|
345
|
+
}, []);
|
|
346
|
+
if (error) {
|
|
347
|
+
return /* @__PURE__ */ jsx(
|
|
348
|
+
"div",
|
|
349
|
+
{
|
|
350
|
+
className: cn(
|
|
351
|
+
"my-4 p-4 rounded-xl border bg-error-soft border-error-soft",
|
|
352
|
+
className
|
|
353
|
+
),
|
|
354
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
355
|
+
/* @__PURE__ */ jsx("span", { className: "text-error", children: "\u26A0\uFE0F" }),
|
|
356
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
357
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-error", children: t("mermaidError", "Diagram error") }),
|
|
358
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-(--text-tertiary) mt-1", children: error }),
|
|
359
|
+
/* @__PURE__ */ jsxs("details", { className: "mt-2", children: [
|
|
360
|
+
/* @__PURE__ */ jsx("summary", { className: "text-xs text-(--text-tertiary) cursor-pointer hover:text-(--text-primary)", children: t("viewSource", "View source") }),
|
|
361
|
+
/* @__PURE__ */ jsx("pre", { className: "mt-2 p-2 bg-(--bg-elevated) rounded text-xs overflow-auto", children: chart })
|
|
362
|
+
] })
|
|
363
|
+
] })
|
|
364
|
+
] })
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
if (isLoading) {
|
|
369
|
+
return /* @__PURE__ */ jsx(
|
|
370
|
+
"div",
|
|
371
|
+
{
|
|
372
|
+
className: cn(
|
|
373
|
+
"card my-4 p-8 flex items-center justify-center",
|
|
374
|
+
className
|
|
375
|
+
),
|
|
376
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-(--text-tertiary)", children: [
|
|
377
|
+
/* @__PURE__ */ jsx("div", { className: "w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin" }),
|
|
378
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm", children: t("renderingDiagram", "Rendering diagram\u2026") })
|
|
379
|
+
] })
|
|
380
|
+
}
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
384
|
+
/* @__PURE__ */ jsx(
|
|
385
|
+
"div",
|
|
386
|
+
{
|
|
387
|
+
ref: containerRef,
|
|
388
|
+
onClick: enableZoom ? () => setZoomOpen(true) : void 0,
|
|
389
|
+
role: enableZoom ? "button" : void 0,
|
|
390
|
+
"aria-label": enableZoom ? t("zoomDiagram", "Zoom diagram") : void 0,
|
|
391
|
+
className: cn(
|
|
392
|
+
"card my-4 p-4 overflow-x-auto",
|
|
393
|
+
"flex items-center justify-center",
|
|
394
|
+
"[&_svg]:max-w-full [&_svg]:h-auto",
|
|
395
|
+
enableZoom && "cursor-zoom-in",
|
|
396
|
+
className
|
|
397
|
+
),
|
|
398
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
399
|
+
}
|
|
400
|
+
),
|
|
401
|
+
enableZoom && /* @__PURE__ */ jsx(ImageLightbox, { isOpen: zoomOpen, onClose: () => setZoomOpen(false), children: /* @__PURE__ */ jsx(
|
|
402
|
+
"div",
|
|
403
|
+
{
|
|
404
|
+
className: "bg-(--bg-card) rounded-2xl p-6 shadow-2xl border border-white/10 w-[86vw] max-w-[1100px] [&_svg]:!max-w-none [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-h-[80vh]",
|
|
405
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
406
|
+
}
|
|
407
|
+
) })
|
|
408
|
+
] });
|
|
409
|
+
}
|
|
410
|
+
var config = {
|
|
411
|
+
note: { variant: "info", icon: Info },
|
|
412
|
+
tip: { variant: "success", icon: Lightbulb },
|
|
413
|
+
important: { variant: "accent", icon: AlertCircle },
|
|
414
|
+
warning: { variant: "warning", icon: AlertTriangle },
|
|
415
|
+
caution: { variant: "error", icon: XOctagon },
|
|
416
|
+
success: { variant: "success", icon: CheckCircle2 }
|
|
417
|
+
};
|
|
418
|
+
var defaultTitles = {
|
|
419
|
+
note: "Note",
|
|
420
|
+
tip: "Tip",
|
|
421
|
+
important: "Important",
|
|
422
|
+
warning: "Warning",
|
|
423
|
+
caution: "Caution",
|
|
424
|
+
success: "Success"
|
|
425
|
+
};
|
|
426
|
+
function CalloutBlock({
|
|
427
|
+
type,
|
|
428
|
+
title,
|
|
429
|
+
children,
|
|
430
|
+
className
|
|
431
|
+
}) {
|
|
432
|
+
const t = useContentT();
|
|
433
|
+
const c = config[type] || config.note;
|
|
434
|
+
const Icon = c.icon;
|
|
435
|
+
const displayTitle = title || t(type, defaultTitles[type] || defaultTitles.note);
|
|
436
|
+
return /* @__PURE__ */ jsx(
|
|
437
|
+
Alert,
|
|
438
|
+
{
|
|
439
|
+
variant: c.variant,
|
|
440
|
+
title: displayTitle,
|
|
441
|
+
icon: /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }),
|
|
442
|
+
className: cn("my-4 not-prose", className),
|
|
443
|
+
children: /* @__PURE__ */ jsx("div", { className: "[&>p]:my-1 [&>p:first-child]:mt-0 [&>p:last-child]:mb-0", children })
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
function parseCalloutType(text) {
|
|
448
|
+
const match = text.match(
|
|
449
|
+
/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION|SUCCESS)\](?:\s+(.+))?$/i
|
|
450
|
+
);
|
|
451
|
+
if (match) {
|
|
452
|
+
return {
|
|
453
|
+
type: match[1].toLowerCase(),
|
|
454
|
+
title: match[2] || null
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return { type: null, title: null };
|
|
458
|
+
}
|
|
459
|
+
var ContentImage = React2.memo(function ContentImage2({
|
|
460
|
+
enableLightbox = true,
|
|
461
|
+
className,
|
|
462
|
+
alt = "",
|
|
463
|
+
src,
|
|
464
|
+
onError,
|
|
465
|
+
onLoad,
|
|
466
|
+
...rest
|
|
467
|
+
}) {
|
|
468
|
+
const [loaded, setLoaded] = useState(false);
|
|
469
|
+
const [failed, setFailed] = useState(false);
|
|
470
|
+
const [lightboxOpen, setLightboxOpen] = useState(false);
|
|
471
|
+
const imgRef = useRef(null);
|
|
472
|
+
const wrapperRef = useRef(null);
|
|
473
|
+
const t = useContentT();
|
|
474
|
+
const srcString = typeof src === "string" ? src : "";
|
|
475
|
+
const valid = srcString && srcString !== "#" && srcString !== "undefined" && srcString !== "null";
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
if (!wrapperRef.current || !valid) return;
|
|
478
|
+
const container = document.querySelector('[data-scroll-container="true"]');
|
|
479
|
+
const root = container && container.contains(wrapperRef.current) ? container : null;
|
|
480
|
+
const observer = new IntersectionObserver(
|
|
481
|
+
(entries) => {
|
|
482
|
+
entries.forEach((entry) => {
|
|
483
|
+
if (entry.isIntersecting && imgRef.current) {
|
|
484
|
+
imgRef.current.src = srcString;
|
|
485
|
+
observer.unobserve(entry.target);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
root,
|
|
491
|
+
rootMargin: "300px 0px",
|
|
492
|
+
threshold: 0.01
|
|
493
|
+
}
|
|
494
|
+
);
|
|
495
|
+
observer.observe(wrapperRef.current);
|
|
496
|
+
return () => observer.disconnect();
|
|
497
|
+
}, [srcString, valid]);
|
|
498
|
+
if (!valid) return null;
|
|
499
|
+
if (failed) {
|
|
500
|
+
return /* @__PURE__ */ jsx("span", { className: "inline-block", children: /* @__PURE__ */ jsx("span", { className: "bg-error-soft px-3 py-2 rounded-xl border border-error-soft text-center", children: /* @__PURE__ */ jsxs("span", { className: "text-error text-sm", children: [
|
|
501
|
+
"\u{1F5BC}\uFE0F ",
|
|
502
|
+
t("imageLoadingFailed", "Image failed to load")
|
|
503
|
+
] }) }) });
|
|
504
|
+
}
|
|
505
|
+
return /* @__PURE__ */ jsxs(
|
|
506
|
+
"span",
|
|
507
|
+
{
|
|
508
|
+
ref: wrapperRef,
|
|
509
|
+
className: "inline-block max-w-full overflow-hidden relative",
|
|
510
|
+
style: {
|
|
511
|
+
minHeight: loaded ? "auto" : "200px",
|
|
512
|
+
minWidth: loaded ? "auto" : "200px"
|
|
513
|
+
},
|
|
514
|
+
children: [
|
|
515
|
+
!loaded && /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center bg-(--bg-elevated) rounded-xl", children: /* @__PURE__ */ jsx("span", { className: "w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin block" }) }),
|
|
516
|
+
/* @__PURE__ */ jsx(
|
|
517
|
+
"img",
|
|
518
|
+
{
|
|
519
|
+
ref: imgRef,
|
|
520
|
+
alt,
|
|
521
|
+
className: cn(
|
|
522
|
+
"max-w-full h-auto rounded-xl shadow-sm border border-(--border-hairline) transition-opacity duration-300",
|
|
523
|
+
loaded ? "opacity-100" : "opacity-0",
|
|
524
|
+
enableLightbox && loaded && "cursor-zoom-in",
|
|
525
|
+
className
|
|
526
|
+
),
|
|
527
|
+
style: { maxHeight: "80vh" },
|
|
528
|
+
onLoad: (e) => {
|
|
529
|
+
setLoaded(true);
|
|
530
|
+
onLoad?.(e);
|
|
531
|
+
},
|
|
532
|
+
onError: (e) => {
|
|
533
|
+
setFailed(true);
|
|
534
|
+
onError?.(e);
|
|
535
|
+
},
|
|
536
|
+
onClick: enableLightbox ? () => setLightboxOpen(true) : void 0,
|
|
537
|
+
...rest
|
|
538
|
+
}
|
|
539
|
+
),
|
|
540
|
+
enableLightbox && /* @__PURE__ */ jsx(
|
|
541
|
+
ImageLightbox,
|
|
542
|
+
{
|
|
543
|
+
src: srcString,
|
|
544
|
+
alt,
|
|
545
|
+
isOpen: lightboxOpen,
|
|
546
|
+
onClose: () => setLightboxOpen(false)
|
|
547
|
+
}
|
|
548
|
+
)
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
);
|
|
552
|
+
});
|
|
553
|
+
function MarkdownRenderer({
|
|
554
|
+
content,
|
|
555
|
+
className,
|
|
556
|
+
urlTransform,
|
|
557
|
+
onCodeEdit
|
|
558
|
+
}) {
|
|
559
|
+
const components = useMemo(
|
|
560
|
+
() => ({
|
|
561
|
+
p: ({ children }) => /* @__PURE__ */ jsx("div", { className: "mb-4 last:mb-0 leading-relaxed", children }),
|
|
562
|
+
h1: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
563
|
+
"h1",
|
|
564
|
+
{
|
|
565
|
+
id,
|
|
566
|
+
className: "group flex items-center gap-2 text-2xl font-bold mt-8 mb-4 first:mt-0 scroll-mt-20",
|
|
567
|
+
children: [
|
|
568
|
+
children,
|
|
569
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
570
|
+
]
|
|
571
|
+
}
|
|
572
|
+
),
|
|
573
|
+
h2: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
574
|
+
"h2",
|
|
575
|
+
{
|
|
576
|
+
id,
|
|
577
|
+
className: "group flex items-center gap-2 text-xl font-bold mt-6 mb-3 scroll-mt-20",
|
|
578
|
+
children: [
|
|
579
|
+
children,
|
|
580
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
),
|
|
584
|
+
h3: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
585
|
+
"h3",
|
|
586
|
+
{
|
|
587
|
+
id,
|
|
588
|
+
className: "group flex items-center gap-2 text-lg font-semibold mt-5 mb-2 scroll-mt-20",
|
|
589
|
+
children: [
|
|
590
|
+
children,
|
|
591
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
),
|
|
595
|
+
h4: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
596
|
+
"h4",
|
|
597
|
+
{
|
|
598
|
+
id,
|
|
599
|
+
className: "group flex items-center gap-2 text-base font-semibold mt-4 mb-2 scroll-mt-20",
|
|
600
|
+
children: [
|
|
601
|
+
children,
|
|
602
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
),
|
|
606
|
+
h5: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
607
|
+
"h5",
|
|
608
|
+
{
|
|
609
|
+
id,
|
|
610
|
+
className: "group flex items-center gap-2 text-sm font-semibold mt-3 mb-1 scroll-mt-20",
|
|
611
|
+
children: [
|
|
612
|
+
children,
|
|
613
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
614
|
+
]
|
|
615
|
+
}
|
|
616
|
+
),
|
|
617
|
+
h6: ({ children, id }) => /* @__PURE__ */ jsxs(
|
|
618
|
+
"h6",
|
|
619
|
+
{
|
|
620
|
+
id,
|
|
621
|
+
className: "group flex items-center gap-2 text-sm font-medium mt-3 mb-1 scroll-mt-20",
|
|
622
|
+
children: [
|
|
623
|
+
children,
|
|
624
|
+
id && /* @__PURE__ */ jsx(HeadingAnchor, { id })
|
|
625
|
+
]
|
|
626
|
+
}
|
|
627
|
+
),
|
|
628
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
629
|
+
code: ({ children, className: codeClass }) => {
|
|
630
|
+
const match = /language-(\w+)/.exec(codeClass || "");
|
|
631
|
+
const language = match ? match[1] : "";
|
|
632
|
+
const codeString = String(children).replace(/\n$/, "");
|
|
633
|
+
if (language === "mermaid") {
|
|
634
|
+
return /* @__PURE__ */ jsx(MermaidDiagram, { chart: codeString });
|
|
635
|
+
}
|
|
636
|
+
if (codeClass || codeString.includes("\n")) {
|
|
637
|
+
const showLineNumbers = codeClass?.includes("showLineNumbers");
|
|
638
|
+
const highlightMatch = codeClass?.match(/\{([^}]+)\}/);
|
|
639
|
+
const highlightLines = highlightMatch ? parseLineHighlights(highlightMatch[1]) : [];
|
|
640
|
+
return /* @__PURE__ */ jsx(
|
|
641
|
+
CodeBlock,
|
|
642
|
+
{
|
|
643
|
+
language,
|
|
644
|
+
showLineNumbers,
|
|
645
|
+
highlightLines,
|
|
646
|
+
onEdit: onCodeEdit,
|
|
647
|
+
children: codeString
|
|
648
|
+
}
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
return /* @__PURE__ */ jsx(InlineCode, { children });
|
|
652
|
+
},
|
|
653
|
+
pre: ({ children }) => /* @__PURE__ */ jsx(Fragment, { children }),
|
|
654
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
655
|
+
img: ({ node, ...props }) => /* @__PURE__ */ jsx(ContentImage, { ...props }),
|
|
656
|
+
a: ({ href, children, ...props }) => {
|
|
657
|
+
const host = typeof window !== "undefined" ? window.location.host : "";
|
|
658
|
+
const isExternal = href?.startsWith("http") && !href?.includes(host);
|
|
659
|
+
return /* @__PURE__ */ jsxs(
|
|
660
|
+
"a",
|
|
661
|
+
{
|
|
662
|
+
href,
|
|
663
|
+
target: isExternal ? "_blank" : void 0,
|
|
664
|
+
rel: isExternal ? "noopener noreferrer" : void 0,
|
|
665
|
+
className: "text-(--text-primary) underline decoration-(--border-default) underline-offset-2 hover:decoration-(--text-primary) inline-flex items-center gap-0.5",
|
|
666
|
+
...props,
|
|
667
|
+
children: [
|
|
668
|
+
children,
|
|
669
|
+
isExternal && /* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3 inline-block ml-0.5" })
|
|
670
|
+
]
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
},
|
|
674
|
+
blockquote: ({ children }) => {
|
|
675
|
+
const childArray = React2.Children.toArray(children);
|
|
676
|
+
const firstEl = childArray.find((c) => React2.isValidElement(c));
|
|
677
|
+
if (React2.isValidElement(firstEl)) {
|
|
678
|
+
const paraKids = React2.Children.toArray(firstEl.props.children);
|
|
679
|
+
const leadStr = typeof paraKids[0] === "string" ? paraKids[0] : "";
|
|
680
|
+
const { type: calloutType, title } = parseCalloutType(
|
|
681
|
+
leadStr.split("\n")[0].trim()
|
|
682
|
+
);
|
|
683
|
+
if (calloutType) {
|
|
684
|
+
const rest = leadStr.includes("\n") ? leadStr.slice(leadStr.indexOf("\n") + 1) : "";
|
|
685
|
+
const body = [rest, ...paraKids.slice(1)];
|
|
686
|
+
const hasFirstPara = rest !== "" || paraKids.length > 1;
|
|
687
|
+
const otherBlocks = childArray.filter(
|
|
688
|
+
(c) => c !== firstEl && React2.isValidElement(c)
|
|
689
|
+
);
|
|
690
|
+
return /* @__PURE__ */ jsxs(CalloutBlock, { type: calloutType, title: title || void 0, children: [
|
|
691
|
+
hasFirstPara && /* @__PURE__ */ jsx("p", { children: body }),
|
|
692
|
+
otherBlocks
|
|
693
|
+
] });
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return /* @__PURE__ */ jsx("blockquote", { className: "border-l-4 border-(--border-default) pl-4 my-4 italic text-(--text-secondary)", children });
|
|
697
|
+
},
|
|
698
|
+
table: ({ children }) => /* @__PURE__ */ jsx("div", { className: "card my-4 overflow-x-auto", children: /* @__PURE__ */ jsx("table", { className: "min-w-full divide-y divide-(--border-hairline)", children }) }),
|
|
699
|
+
thead: ({ children }) => /* @__PURE__ */ jsx("thead", { className: "bg-(--bg-elevated)", children }),
|
|
700
|
+
th: ({ children }) => /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left text-sm font-semibold text-(--text-primary)", children }),
|
|
701
|
+
td: ({ children }) => /* @__PURE__ */ jsx("td", { className: "px-4 py-2 text-sm border-t border-(--border-hairline)", children }),
|
|
702
|
+
ul: ({ children }) => /* @__PURE__ */ jsx("ul", { className: "my-3 ml-6 list-disc space-y-1 [&>li]:pl-1", children }),
|
|
703
|
+
ol: ({ children }) => /* @__PURE__ */ jsx("ol", { className: "my-3 ml-6 list-decimal space-y-1 [&>li]:pl-1", children }),
|
|
704
|
+
li: ({ children, className: liClass }) => {
|
|
705
|
+
const isTaskItem = liClass?.includes("task-list-item");
|
|
706
|
+
return /* @__PURE__ */ jsx(
|
|
707
|
+
"li",
|
|
708
|
+
{
|
|
709
|
+
className: cn(
|
|
710
|
+
"leading-relaxed",
|
|
711
|
+
isTaskItem && "list-none -ml-6 flex items-start gap-2"
|
|
712
|
+
),
|
|
713
|
+
children
|
|
714
|
+
}
|
|
715
|
+
);
|
|
716
|
+
},
|
|
717
|
+
input: ({ type, checked, ...props }) => {
|
|
718
|
+
if (type === "checkbox") {
|
|
719
|
+
return /* @__PURE__ */ jsx(
|
|
720
|
+
"input",
|
|
721
|
+
{
|
|
722
|
+
type: "checkbox",
|
|
723
|
+
checked,
|
|
724
|
+
readOnly: true,
|
|
725
|
+
className: "mt-1 h-4 w-4 rounded border-(--border-hairline) accent-(--accent) focus:ring-ring",
|
|
726
|
+
...props
|
|
727
|
+
}
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
return /* @__PURE__ */ jsx("input", { type, ...props });
|
|
731
|
+
},
|
|
732
|
+
hr: () => /* @__PURE__ */ jsx("hr", { className: "my-6 border-t border-(--border-hairline)" }),
|
|
733
|
+
kbd: ({ children }) => /* @__PURE__ */ jsx("kbd", { className: "px-1.5 py-0.5 text-xs font-mono bg-(--bg-elevated) border border-(--border-default) rounded shadow-sm", children }),
|
|
734
|
+
mark: ({ children }) => /* @__PURE__ */ jsx("mark", { className: "bg-warning-soft text-(--text-primary) px-0.5 rounded", children }),
|
|
735
|
+
details: ({ children }) => /* @__PURE__ */ jsx("details", { className: "card my-4 overflow-hidden group", children }),
|
|
736
|
+
summary: ({ children }) => /* @__PURE__ */ jsx("summary", { className: "px-4 py-3 cursor-pointer select-none font-medium hover:bg-(--accent-subtle) transition-colors", children }),
|
|
737
|
+
abbr: ({ children, title }) => /* @__PURE__ */ jsx(
|
|
738
|
+
"abbr",
|
|
739
|
+
{
|
|
740
|
+
title,
|
|
741
|
+
className: "border-b border-dotted border-(--text-tertiary) cursor-help",
|
|
742
|
+
children
|
|
743
|
+
}
|
|
744
|
+
),
|
|
745
|
+
sub: ({ children }) => /* @__PURE__ */ jsx("sub", { className: "text-xs", children }),
|
|
746
|
+
sup: ({ children }) => /* @__PURE__ */ jsx("sup", { className: "text-xs", children }),
|
|
747
|
+
del: ({ children }) => /* @__PURE__ */ jsx("del", { className: "text-(--text-tertiary) line-through", children })
|
|
748
|
+
}),
|
|
749
|
+
[onCodeEdit]
|
|
750
|
+
);
|
|
751
|
+
return /* @__PURE__ */ jsx(
|
|
752
|
+
"div",
|
|
753
|
+
{
|
|
754
|
+
className: cn(
|
|
755
|
+
// NOT prose. This renderer styles every element itself via the component
|
|
756
|
+
// map below, so Tailwind Typography would double-style everything — the
|
|
757
|
+
// table got a second frame + 28px dead-space margin, callout titles got
|
|
758
|
+
// shoved off their icon, and code blocks looked different inside prose vs
|
|
759
|
+
// out. `not-prose` makes our mappings the single source of truth, even
|
|
760
|
+
// when a host app wraps the output in `.prose`.
|
|
761
|
+
"not-prose text-sm leading-relaxed text-(--text-primary)",
|
|
762
|
+
className
|
|
763
|
+
),
|
|
764
|
+
children: /* @__PURE__ */ jsx(
|
|
765
|
+
ReactMarkdown,
|
|
766
|
+
{
|
|
767
|
+
remarkPlugins: [remarkGfm, remarkMath],
|
|
768
|
+
rehypePlugins: [rehypeRaw, rehypeKatex, rehypeSlug],
|
|
769
|
+
urlTransform,
|
|
770
|
+
components,
|
|
771
|
+
children: content
|
|
772
|
+
}
|
|
773
|
+
)
|
|
774
|
+
}
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
function HeadingAnchor({ id }) {
|
|
778
|
+
const [copied, setCopied] = useState(false);
|
|
779
|
+
const t = useContentT();
|
|
780
|
+
const handleClick = async (e) => {
|
|
781
|
+
e.preventDefault();
|
|
782
|
+
const url = `${window.location.origin}${window.location.pathname}#${id}`;
|
|
783
|
+
try {
|
|
784
|
+
await navigator.clipboard.writeText(url);
|
|
785
|
+
setCopied(true);
|
|
786
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
787
|
+
} catch {
|
|
788
|
+
window.location.hash = id;
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
return /* @__PURE__ */ jsx(
|
|
792
|
+
"a",
|
|
793
|
+
{
|
|
794
|
+
href: `#${id}`,
|
|
795
|
+
onClick: handleClick,
|
|
796
|
+
className: cn(
|
|
797
|
+
"opacity-0 group-hover:opacity-100 transition-opacity",
|
|
798
|
+
"text-(--text-tertiary) hover:text-(--text-primary)",
|
|
799
|
+
copied && "text-success"
|
|
800
|
+
),
|
|
801
|
+
"aria-label": t("linkToHeading", "Copy link to this heading"),
|
|
802
|
+
children: /* @__PURE__ */ jsx(Link2, { className: "w-4 h-4" })
|
|
803
|
+
}
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
function parseLineHighlights(input) {
|
|
807
|
+
const lines = [];
|
|
808
|
+
for (const part of input.split(",")) {
|
|
809
|
+
const trimmed = part.trim();
|
|
810
|
+
if (trimmed.includes("-")) {
|
|
811
|
+
const [start, end] = trimmed.split("-").map((n) => parseInt(n.trim(), 10));
|
|
812
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
813
|
+
for (let i = start; i <= end; i++) lines.push(i);
|
|
814
|
+
}
|
|
815
|
+
} else {
|
|
816
|
+
const num = parseInt(trimmed, 10);
|
|
817
|
+
if (!isNaN(num)) lines.push(num);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return lines;
|
|
821
|
+
}
|
|
822
|
+
function MathRenderer({ math, block = false, className }) {
|
|
823
|
+
const containerRef = useRef(null);
|
|
824
|
+
const [error, setError] = useState("");
|
|
825
|
+
const t = useContentT();
|
|
826
|
+
useEffect(() => {
|
|
827
|
+
if (!containerRef.current) return;
|
|
828
|
+
try {
|
|
829
|
+
katex.render(math, containerRef.current, {
|
|
830
|
+
displayMode: block,
|
|
831
|
+
throwOnError: false,
|
|
832
|
+
errorColor: "#cc0000",
|
|
833
|
+
strict: false,
|
|
834
|
+
trust: true,
|
|
835
|
+
macros: {
|
|
836
|
+
"\\RR": "\\mathbb{R}",
|
|
837
|
+
"\\NN": "\\mathbb{N}",
|
|
838
|
+
"\\ZZ": "\\mathbb{Z}",
|
|
839
|
+
"\\QQ": "\\mathbb{Q}",
|
|
840
|
+
"\\CC": "\\mathbb{C}"
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
setError("");
|
|
844
|
+
} catch (err) {
|
|
845
|
+
setError(
|
|
846
|
+
err instanceof Error ? err.message : t("formulaRenderFailed", "Formula render failed")
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
}, [math, block]);
|
|
850
|
+
if (error) {
|
|
851
|
+
return /* @__PURE__ */ jsx(
|
|
852
|
+
"span",
|
|
853
|
+
{
|
|
854
|
+
className: cn(
|
|
855
|
+
"text-error bg-error-soft px-1 rounded",
|
|
856
|
+
block ? "block my-2 p-2 text-center" : "inline",
|
|
857
|
+
className
|
|
858
|
+
),
|
|
859
|
+
children: /* @__PURE__ */ jsxs("span", { className: "text-xs", children: [
|
|
860
|
+
"\u26A0\uFE0F ",
|
|
861
|
+
error
|
|
862
|
+
] })
|
|
863
|
+
}
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
if (block) {
|
|
867
|
+
return /* @__PURE__ */ jsx(
|
|
868
|
+
"div",
|
|
869
|
+
{
|
|
870
|
+
className: cn(
|
|
871
|
+
"my-4 py-4 overflow-x-auto text-center",
|
|
872
|
+
"[&_.katex]:text-lg",
|
|
873
|
+
className
|
|
874
|
+
),
|
|
875
|
+
children: /* @__PURE__ */ jsx("span", { ref: containerRef })
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
return /* @__PURE__ */ jsx("span", { ref: containerRef, className: cn("inline-block align-middle", className) });
|
|
880
|
+
}
|
|
881
|
+
function InlineMath({ value }) {
|
|
882
|
+
return /* @__PURE__ */ jsx(MathRenderer, { math: value, block: false });
|
|
883
|
+
}
|
|
884
|
+
function BlockMath({ value }) {
|
|
885
|
+
return /* @__PURE__ */ jsx(MathRenderer, { math: value, block: true });
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
export { BlockMath, CalloutBlock, CodeBlock, ContentImage, InlineCode, InlineMath, MarkdownRenderer, MathRenderer, MermaidDiagram, parseCalloutType };
|
|
889
|
+
//# sourceMappingURL=content.js.map
|
|
890
|
+
//# sourceMappingURL=content.js.map
|