@yuhuanowo/yunui 0.2.17 → 0.2.18
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 +3 -1
- package/README.zh-CN.md +5 -1
- package/README.zh-TW.md +5 -1
- package/dist/ai.d.ts +99 -3
- package/dist/ai.js +212 -104
- package/dist/ai.js.map +1 -1
- package/dist/chat.d.ts +10 -3
- package/dist/chat.js +12 -7
- package/dist/chat.js.map +1 -1
- package/dist/{chunk-HH3JBHRP.js → chunk-AFVENY4D.js} +286 -31
- package/dist/chunk-AFVENY4D.js.map +1 -0
- package/dist/{chunk-F2HG4TOQ.js → chunk-GAXVET76.js} +13 -19
- package/dist/chunk-GAXVET76.js.map +1 -0
- package/dist/{chunk-DDUP7GAX.js → chunk-LEBQPP4B.js} +69 -3
- package/dist/chunk-LEBQPP4B.js.map +1 -0
- package/dist/chunk-ST6TSBVQ.js +208 -0
- package/dist/chunk-ST6TSBVQ.js.map +1 -0
- package/dist/chunk-V7VJKZ5Q.js +254 -0
- package/dist/chunk-V7VJKZ5Q.js.map +1 -0
- package/dist/{chunk-BCOKFWXC.js → chunk-YKWRCA2S.js} +80 -156
- package/dist/chunk-YKWRCA2S.js.map +1 -0
- package/dist/content.d.ts +10 -2
- package/dist/content.js +50 -40
- package/dist/content.js.map +1 -1
- package/dist/index.d.ts +266 -16
- package/dist/index.js +4 -4
- package/dist/patterns.d.ts +471 -22
- package/dist/patterns.js +783 -131
- package/dist/patterns.js.map +1 -1
- package/icons/providers/gmi.svg +5 -0
- package/package.json +3 -4
- package/styles/content.css +3 -1
- package/styles/yunui.css +197 -84
- package/dist/chunk-BCOKFWXC.js.map +0 -1
- package/dist/chunk-DDUP7GAX.js.map +0 -1
- package/dist/chunk-F2HG4TOQ.js.map +0 -1
- package/dist/chunk-HH3JBHRP.js.map +0 -1
- package/dist/chunk-N4QO7RN5.js +0 -98
- package/dist/chunk-N4QO7RN5.js.map +0 -1
- package/dist/chunk-QEIBYOG2.js +0 -188
- package/dist/chunk-QEIBYOG2.js.map +0 -1
package/dist/content.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ interface MarkdownRendererProps {
|
|
|
40
40
|
* proxy). Defaults to identity.
|
|
41
41
|
*/
|
|
42
42
|
urlTransform?: (url: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Stable origin used to recognize same-origin absolute links, in SSR and the
|
|
45
|
+
* browser alike (e.g. "https://example.com"). Without it, absolute HTTP(S)
|
|
46
|
+
* links open externally; relative and fragment links remain internal.
|
|
47
|
+
*/
|
|
48
|
+
linkOrigin?: string;
|
|
43
49
|
/**
|
|
44
50
|
* When provided, code blocks show an "Edit" button that calls this with the
|
|
45
51
|
* code payload (e.g. open it in an editor). Hidden if unset.
|
|
@@ -62,7 +68,7 @@ interface MarkdownRendererProps {
|
|
|
62
68
|
* and lazy, zoomable images. Requires `katex/dist/katex.min.css` and the YunUI
|
|
63
69
|
* content styles to be imported by the host app.
|
|
64
70
|
*/
|
|
65
|
-
declare function MarkdownRenderer({ content, className, urlTransform, onCodeEdit, renderLink, }: MarkdownRendererProps): React.JSX.Element;
|
|
71
|
+
declare function MarkdownRenderer({ content, className, urlTransform, linkOrigin, onCodeEdit, renderLink, }: MarkdownRendererProps): React.JSX.Element;
|
|
66
72
|
|
|
67
73
|
type CalloutType = "note" | "tip" | "important" | "warning" | "caution" | "success";
|
|
68
74
|
interface CalloutBlockProps {
|
|
@@ -123,6 +129,8 @@ interface ImageLightboxProps {
|
|
|
123
129
|
/** Image URL to view. Omit when providing custom `children` (e.g. an SVG). */
|
|
124
130
|
src?: string;
|
|
125
131
|
alt?: string;
|
|
132
|
+
/** Accessible dialog name; defaults to alt or the host's content translation. */
|
|
133
|
+
label?: string;
|
|
126
134
|
isOpen: boolean;
|
|
127
135
|
onClose: () => void;
|
|
128
136
|
/**
|
|
@@ -136,7 +144,7 @@ interface ImageLightboxProps {
|
|
|
136
144
|
* (Esc / +/- / R). Views an image (`src`) or any custom `children` (e.g. an
|
|
137
145
|
* inline SVG diagram). Rendered into a portal on `document.body`.
|
|
138
146
|
*/
|
|
139
|
-
declare function ImageLightbox({ src, alt, isOpen, onClose, children }: ImageLightboxProps): React.
|
|
147
|
+
declare function ImageLightbox({ src, alt, label, isOpen, onClose, children }: ImageLightboxProps): React.JSX.Element | null;
|
|
140
148
|
|
|
141
149
|
interface ContentImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
|
|
142
150
|
/** Open a zoom/rotate/download lightbox on click. @defaultValue true */
|
package/dist/content.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useContentT, ImageLightbox } from './chunk-
|
|
3
|
-
export { ImageLightbox } from './chunk-
|
|
4
|
-
import { Alert, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from './chunk-
|
|
5
|
-
import { cn } from './chunk-
|
|
2
|
+
import { useContentT, ImageLightbox } from './chunk-ST6TSBVQ.js';
|
|
3
|
+
export { ImageLightbox } from './chunk-ST6TSBVQ.js';
|
|
4
|
+
import { Alert, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from './chunk-YKWRCA2S.js';
|
|
5
|
+
import { cn } from './chunk-V7VJKZ5Q.js';
|
|
6
6
|
import './chunk-3RT24MSH.js';
|
|
7
7
|
import * as React2 from 'react';
|
|
8
8
|
import { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
@@ -18,6 +18,21 @@ import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
|
18
18
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
19
19
|
import katex from 'katex';
|
|
20
20
|
|
|
21
|
+
function useContentDarkMode() {
|
|
22
|
+
const [dark, setDark] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const root = document.documentElement;
|
|
25
|
+
const check = () => {
|
|
26
|
+
const theme = root.getAttribute("data-theme");
|
|
27
|
+
setDark(root.classList.contains("dark") || root.classList.contains("true-black") || theme === "dark" || theme === "true-black");
|
|
28
|
+
};
|
|
29
|
+
check();
|
|
30
|
+
const observer = new MutationObserver(check);
|
|
31
|
+
observer.observe(root, { attributes: true, attributeFilter: ["class", "data-theme"] });
|
|
32
|
+
return () => observer.disconnect();
|
|
33
|
+
}, []);
|
|
34
|
+
return dark;
|
|
35
|
+
}
|
|
21
36
|
var languageNames = {
|
|
22
37
|
js: "JavaScript",
|
|
23
38
|
javascript: "JavaScript",
|
|
@@ -121,8 +136,8 @@ var shikiLanguageAliases = {
|
|
|
121
136
|
zsh: "bash"
|
|
122
137
|
};
|
|
123
138
|
var shikiThemes = {
|
|
124
|
-
"github-dark": () => import('shiki/themes/github-dark.mjs'),
|
|
125
|
-
"github-light": () => import('shiki/themes/github-light.mjs')
|
|
139
|
+
"github-dark-default": () => import('shiki/themes/github-dark-default.mjs'),
|
|
140
|
+
"github-light-default": () => import('shiki/themes/github-light-default.mjs')
|
|
126
141
|
};
|
|
127
142
|
var contentHighlighterPromise;
|
|
128
143
|
var languageLoadPromises = /* @__PURE__ */ new Map();
|
|
@@ -179,20 +194,6 @@ function resolveShikiLanguage(language) {
|
|
|
179
194
|
if (normalized in shikiLanguages) return normalized;
|
|
180
195
|
return shikiLanguageAliases[normalized] ?? "plaintext";
|
|
181
196
|
}
|
|
182
|
-
function useIsDarkMode() {
|
|
183
|
-
const [isDark, setIsDark] = useState(false);
|
|
184
|
-
useEffect(() => {
|
|
185
|
-
const check = () => setIsDark(document.documentElement.classList.contains("dark"));
|
|
186
|
-
check();
|
|
187
|
-
const observer = new MutationObserver(check);
|
|
188
|
-
observer.observe(document.documentElement, {
|
|
189
|
-
attributes: true,
|
|
190
|
-
attributeFilter: ["class"]
|
|
191
|
-
});
|
|
192
|
-
return () => observer.disconnect();
|
|
193
|
-
}, []);
|
|
194
|
-
return isDark;
|
|
195
|
-
}
|
|
196
197
|
function CodeBlock({
|
|
197
198
|
children,
|
|
198
199
|
language = "plaintext",
|
|
@@ -205,7 +206,7 @@ function CodeBlock({
|
|
|
205
206
|
const [copied, setCopied] = useState(false);
|
|
206
207
|
const [highlightedCode, setHighlightedCode] = useState("");
|
|
207
208
|
const [isLoading, setIsLoading] = useState(true);
|
|
208
|
-
const isDark =
|
|
209
|
+
const isDark = useContentDarkMode();
|
|
209
210
|
const t = useContentT();
|
|
210
211
|
const code = useMemo(
|
|
211
212
|
() => typeof children === "string" ? children.trim() : String(children).trim(),
|
|
@@ -222,7 +223,7 @@ function CodeBlock({
|
|
|
222
223
|
async function highlight() {
|
|
223
224
|
setIsLoading(true);
|
|
224
225
|
try {
|
|
225
|
-
const theme = isDark ? "github-dark" : "github-light";
|
|
226
|
+
const theme = isDark ? "github-dark-default" : "github-light-default";
|
|
226
227
|
const lang = resolveShikiLanguage(language || "plaintext");
|
|
227
228
|
const html = await highlightToHtml(code, {
|
|
228
229
|
lang,
|
|
@@ -396,7 +397,7 @@ function MermaidDiagram({
|
|
|
396
397
|
const [svg, setSvg] = useState("");
|
|
397
398
|
const [error, setError] = useState("");
|
|
398
399
|
const [isLoading, setIsLoading] = useState(true);
|
|
399
|
-
const
|
|
400
|
+
const isDark = useContentDarkMode();
|
|
400
401
|
const [zoomOpen, setZoomOpen] = useState(false);
|
|
401
402
|
const t = useContentT();
|
|
402
403
|
useEffect(() => {
|
|
@@ -407,7 +408,6 @@ function MermaidDiagram({
|
|
|
407
408
|
const diagramId = `yunui-mermaid-${mermaidSeq += 1}`;
|
|
408
409
|
try {
|
|
409
410
|
const mermaid = (await import('mermaid')).default;
|
|
410
|
-
const isDark = typeof document !== "undefined" && document.documentElement.classList.contains("dark");
|
|
411
411
|
mermaid.initialize({
|
|
412
412
|
startOnLoad: false,
|
|
413
413
|
theme: isDark ? "dark" : "default",
|
|
@@ -445,16 +445,7 @@ function MermaidDiagram({
|
|
|
445
445
|
return () => {
|
|
446
446
|
cancelled = true;
|
|
447
447
|
};
|
|
448
|
-
}, [chart,
|
|
449
|
-
useEffect(() => {
|
|
450
|
-
if (typeof document === "undefined") return;
|
|
451
|
-
const observer = new MutationObserver(() => setThemeTick((n) => n + 1));
|
|
452
|
-
observer.observe(document.documentElement, {
|
|
453
|
-
attributes: true,
|
|
454
|
-
attributeFilter: ["class"]
|
|
455
|
-
});
|
|
456
|
-
return () => observer.disconnect();
|
|
457
|
-
}, []);
|
|
448
|
+
}, [chart, isDark]);
|
|
458
449
|
if (error) {
|
|
459
450
|
return /* @__PURE__ */ jsx(
|
|
460
451
|
"div",
|
|
@@ -498,6 +489,12 @@ function MermaidDiagram({
|
|
|
498
489
|
{
|
|
499
490
|
ref: containerRef,
|
|
500
491
|
onClick: enableZoom ? () => setZoomOpen(true) : void 0,
|
|
492
|
+
onKeyDown: enableZoom ? (event) => {
|
|
493
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
494
|
+
event.preventDefault();
|
|
495
|
+
setZoomOpen(true);
|
|
496
|
+
}
|
|
497
|
+
} : void 0,
|
|
501
498
|
role: enableZoom ? "button" : void 0,
|
|
502
499
|
"aria-label": enableZoom ? t("zoomDiagram", "Zoom diagram") : void 0,
|
|
503
500
|
tabIndex: 0,
|
|
@@ -667,6 +664,7 @@ function MarkdownRenderer({
|
|
|
667
664
|
content,
|
|
668
665
|
className,
|
|
669
666
|
urlTransform,
|
|
667
|
+
linkOrigin,
|
|
670
668
|
onCodeEdit,
|
|
671
669
|
renderLink
|
|
672
670
|
}) {
|
|
@@ -767,9 +765,14 @@ function MarkdownRenderer({
|
|
|
767
765
|
pre: ({ children }) => /* @__PURE__ */ jsx(Fragment, { children }),
|
|
768
766
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
769
767
|
img: ({ node, ...props }) => /* @__PURE__ */ jsx(ContentImage, { ...props }),
|
|
770
|
-
a: ({ href, children, ...props }) => {
|
|
771
|
-
|
|
772
|
-
|
|
768
|
+
a: ({ href, children, node: _node, ...props }) => {
|
|
769
|
+
let isExternal = Boolean(href && /^(https?:)?\/\//i.test(href));
|
|
770
|
+
if (isExternal && linkOrigin) {
|
|
771
|
+
try {
|
|
772
|
+
isExternal = new URL(href, linkOrigin).origin !== new URL(linkOrigin).origin;
|
|
773
|
+
} catch {
|
|
774
|
+
}
|
|
775
|
+
}
|
|
773
776
|
const override = renderLink?.({ href, children, isExternal: Boolean(isExternal) });
|
|
774
777
|
if (override !== void 0) return override;
|
|
775
778
|
return /* @__PURE__ */ jsxs(
|
|
@@ -838,6 +841,8 @@ function MarkdownRenderer({
|
|
|
838
841
|
type: "checkbox",
|
|
839
842
|
checked,
|
|
840
843
|
readOnly: true,
|
|
844
|
+
"aria-hidden": "true",
|
|
845
|
+
tabIndex: -1,
|
|
841
846
|
className: "mt-1 h-4 w-4 rounded border-(--border-hairline) accent-(--accent) focus:ring-ring",
|
|
842
847
|
...props
|
|
843
848
|
}
|
|
@@ -862,7 +867,7 @@ function MarkdownRenderer({
|
|
|
862
867
|
sup: ({ children }) => /* @__PURE__ */ jsx("sup", { className: "text-xs", children }),
|
|
863
868
|
del: ({ children }) => /* @__PURE__ */ jsx("del", { className: "text-(--text-tertiary) line-through", children })
|
|
864
869
|
}),
|
|
865
|
-
[onCodeEdit, renderLink]
|
|
870
|
+
[onCodeEdit, renderLink, linkOrigin]
|
|
866
871
|
);
|
|
867
872
|
return /* @__PURE__ */ jsx(
|
|
868
873
|
"div",
|
|
@@ -945,7 +950,10 @@ function MathRenderer({ math, block = false, className }) {
|
|
|
945
950
|
katex.render(math, containerRef.current, {
|
|
946
951
|
displayMode: block,
|
|
947
952
|
throwOnError: false,
|
|
948
|
-
|
|
953
|
+
// KaTeX writes this straight into inline styles, so it cannot be a
|
|
954
|
+
// class. Read the live token instead of hardcoding a red that matches
|
|
955
|
+
// neither theme; fall back only if the stylesheet has not loaded.
|
|
956
|
+
errorColor: typeof window !== "undefined" && getComputedStyle(document.documentElement).getPropertyValue("--error").trim() || "#cc0000",
|
|
949
957
|
strict: false,
|
|
950
958
|
// trust:false — untrusted math must not enable \href{javascript:...},
|
|
951
959
|
// \includegraphics, \htmlData etc. (KaTeX XSS surface).
|
|
@@ -1041,7 +1049,9 @@ function InlineCitation({
|
|
|
1041
1049
|
sideOffset: 8,
|
|
1042
1050
|
className: cn(
|
|
1043
1051
|
"w-[min(340px,calc(100vw-24px))] rounded-2xl border border-border",
|
|
1044
|
-
|
|
1052
|
+
// shadow-lg shadow-black/5 is the house overlay drop; shadow-xl was
|
|
1053
|
+
// heavier than every other popover in the system.
|
|
1054
|
+
"bg-popover p-3 text-popover-foreground shadow-lg shadow-black/5"
|
|
1045
1055
|
),
|
|
1046
1056
|
children: /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-2.5", children: [
|
|
1047
1057
|
icon ? /* @__PURE__ */ jsx("span", { className: "mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-muted", children: icon }) : null,
|