@superlc/md-react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Markdown.d.ts.map +1 -1
- package/dist/components/CodeBlock.d.ts +16 -0
- package/dist/components/CodeBlock.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +296 -218
- package/dist/streaming/StreamingMarkdown.d.ts.map +1 -1
- package/dist/streaming/types.d.ts +4 -0
- package/dist/streaming/types.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/Markdown.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../src/Markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../src/Markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAKhC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAmCtC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface CodeBlockProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
/** 是否显示复制按钮 */
|
|
6
|
+
showCopyButton?: boolean;
|
|
7
|
+
/** 复制成功回调 */
|
|
8
|
+
onCopy?: (code: string) => void;
|
|
9
|
+
/** 额外的 className */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 代码块组件,包装 <pre> 元素并添加复制按钮
|
|
14
|
+
*/
|
|
15
|
+
export declare const CodeBlock: React.FC<CodeBlockProps>;
|
|
16
|
+
//# sourceMappingURL=CodeBlock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.d.ts","sourceRoot":"","sources":["../../src/components/CodeBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAqDrE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,eAAe;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoC9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var G=Object.create;var J=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var ne=(e,t,c,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ee(t))!re.call(e,n)&&n!==c&&J(e,n,{get:()=>t[n],enumerable:!(u=Q(t,n))||u.enumerable});return e};var se=(e,t,c)=>(c=e!=null?G(te(e)):{},ne(t||!e||!e.__esModule?J(c,"default",{value:e,enumerable:!0}):c,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),r=require("react"),E=require("@superlc/md-core"),B=require("hast-util-to-jsx-runtime");async function ae(e){try{return await navigator.clipboard.writeText(e),!0}catch{return ce(e)}}function ce(e){const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(t)}}const ue=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:s.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})}),oe=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:s.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),I=({children:e,showCopyButton:t=!0,onCopy:c,className:u})=>{const[n,l]=r.useState(!1),o=r.useCallback(async()=>{const a=U(e);await ae(a)&&(l(!0),c==null||c(a),setTimeout(()=>l(!1),2e3))},[e,c]);return s.jsxs("div",{className:`md-code-block-wrapper${u?` ${u}`:""}`,children:[s.jsx("pre",{children:e}),t&&s.jsx("button",{type:"button",className:`md-copy-button${n?" md-copy-button--copied":""}`,onClick:o,title:n?"已复制":"复制代码","aria-label":n?"已复制":"复制代码",children:n?s.jsx(oe,{}):s.jsx(ue,{})})]})};function U(e){return typeof e=="string"?e:typeof e=="number"?String(e):Array.isArray(e)?e.map(U).join(""):r.isValidElement(e)?U(e.props.children):""}I.displayName="CodeBlock";const K=({children:e,components:t,className:c,copyButton:u=!0,onCodeCopy:n,...l})=>{const o=r.useMemo(()=>{if(!e)return null;const a=E.parseToHast(e,l),p=u?b=>s.jsx(I,{showCopyButton:u,onCopy:n,...b}):void 0,f={...p?{pre:p}:{},...t};return B.toJsxRuntime(a,{Fragment:s.Fragment,jsx:s.jsx,jsxs:s.jsxs,components:f})},[e,t,u,n,l]);return s.jsx("div",{className:c,children:o})};K.displayName="Markdown";function ie(e,t={}){const{components:c={},...u}=t;return r.useMemo(()=>{if(!e)return null;const n=E.parseToHast(e,u);return B.toJsxRuntime(n,{Fragment:s.Fragment,jsx:s.jsx,jsxs:s.jsxs,components:c})},[e,c,u])}const W=r.memo(({block:e,components:t})=>{if(!e.hast)return null;try{return B.toJsxRuntime(e.hast,{jsx:s.jsx,jsxs:s.jsxs,Fragment:s.Fragment,components:t})}catch{return null}},(e,t)=>e.block.key===t.block.key&&e.block.stable&&t.block.stable);W.displayName="StableBlock";function le(e={}){const{components:t,minUpdateInterval:c=16,immediate:u=!1,outputRate:n="medium",...l}=e,o=r.useRef(E.createStreamingParser(l)),a=r.useRef(new E.OutputRateController(n)),[p,f]=r.useState(0),[b,j]=r.useState(!1),[v,x]=r.useState(0),[g,h]=r.useState("idle"),R=r.useRef(0),d=r.useRef(null),S=r.useCallback(()=>{const k=performance.now(),A=k-R.current;u||A>=c?(R.current=k,f(D=>D+1)):d.current===null&&(d.current=window.requestAnimationFrame(()=>{d.current=null,R.current=performance.now(),f(D=>D+1)}))},[c,u]),M=r.useCallback(k=>{o.current.append(k),S()},[S]),T=r.useCallback(k=>{o.current.reset(),j(!1),x(0),h("running"),a.current.start(k,A=>{A&&o.current.append(A),x(a.current.progress),S()},()=>{o.current.finish(),j(!0),x(1),h("complete"),S()})},[S]),w=r.useCallback(()=>{a.current.pause(),h(a.current.status)},[]),F=r.useCallback(()=>{a.current.resume(),h(a.current.status)},[]),N=r.useCallback(()=>{a.current.skipToEnd(),h(a.current.status),x(1)},[]),z=r.useCallback(()=>{a.current.stop(),o.current.finish(),j(!0),h("complete"),d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),f(k=>k+1)},[]),H=r.useCallback(()=>{a.current.stop(),o.current.reset(),j(!1),x(0),h("idle"),d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),f(k=>k+1)},[]);r.useEffect(()=>{a.current.setRate(n)},[n]),r.useEffect(()=>()=>{a.current.stop(),d.current!==null&&cancelAnimationFrame(d.current)},[]);const i=o.current.getState(),m=o.current.getStats(),y=o.current.getContent(),C=r.useMemo(()=>i.blocks.map(k=>s.jsx(W,{block:k,components:t},k.key)),[i.blocks,t,p]);return{element:r.useMemo(()=>i.blocks.length===0?null:s.jsx(s.Fragment,{children:C}),[C,i.blocks.length]),append:M,start:T,pause:w,resume:F,skipToEnd:N,reset:H,finish:z,blocks:i.blocks,stats:m,isComplete:b,content:y,progress:v,outputStatus:g}}const me=16,fe="data:image/svg+xml,",de=()=>s.jsxs("svg",{width:"48",height:"36",viewBox:"0 0 48 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[s.jsx("rect",{x:"0",y:"0",width:"48",height:"36",rx:"3",className:"md-image-skeleton-icon"}),s.jsx("circle",{cx:"12",cy:"10",r:"5",className:"md-image-skeleton-icon-detail"}),s.jsx("path",{d:"M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z",className:"md-image-skeleton-icon-detail"})]}),q=r.memo(({src:e,alt:t,className:c,"data-width":u,"data-height":n,...l})=>{const a=(e==null?void 0:e.startsWith(fe))?void 0:e,p=u?Number(u):200,f=n?Number(n):120,[b,j]=r.useState(!0),v=r.useRef(null),x=r.useRef(null);r.useLayoutEffect(()=>{v.current&&a&&v.current.complete&&v.current.naturalWidth>0&&j(!1)},[a]);const g=r.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{j(!1)},me)},[]);return s.jsxs("span",{className:`md-image-container ${c||""}`,style:{width:p,height:f},children:[a&&s.jsx("img",{ref:v,src:a,alt:t,onLoad:g,className:"md-image",...l}),b&&s.jsx("span",{className:"md-image-skeleton",children:s.jsx(de,{})})]})});q.displayName="StreamingImage";let V=!1,L=null;async function _(){if(!V)return L||(L=(async()=>{await import("katex/dist/katex.min.css"),V=!0})(),L)}const pe=r.memo(({children:e})=>(r.useEffect(()=>{V||_()},[]),s.jsx(s.Fragment,{children:e})));pe.displayName="MathProvider";function xe(){return _()}const X=r.memo(({block:e,components:t})=>{if(!e.hast)return null;try{return B.toJsxRuntime(e.hast,{jsx:s.jsx,jsxs:s.jsxs,Fragment:s.Fragment,components:t})}catch{return s.jsx("div",{className:"parse-error",children:e.source})}},(e,t)=>e.block.key===t.block.key&&e.block.stable&&t.block.stable);X.displayName="StableBlock";const Y=({content:e,source:t,outputRate:c="medium",isComplete:u=!1,onComplete:n,onBlockStable:l,onProgress:o,components:a,className:p,minUpdateInterval:f=16,autoStart:b=!0,copyButton:j=!0,onCodeCopy:v,...x})=>{r.useEffect(()=>{x.math&&xe()},[x.math]);const g=r.useRef(E.createStreamingParser(x)),h=r.useRef(new E.OutputRateController(c)),R=r.useRef(""),d=r.useRef(void 0),S=r.useRef([]),[,M]=r.useReducer(i=>i+1,0),T=r.useRef(0),w=r.useRef(null),F=()=>{const i=performance.now();i-T.current>=f?(T.current=i,M()):w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null,T.current=performance.now(),M()}))};r.useEffect(()=>{t!==void 0&&t!==d.current&&(d.current=t,b&&t&&(g.current.reset(),R.current="",h.current.start(t,i=>{i&&(g.current.append(i),R.current+=i),o==null||o(h.current.progress),F()},()=>{g.current.finish(),n==null||n(),F()})))},[t,b,n,o]),r.useEffect(()=>{if(t!==void 0)return;const i=R.current,m=e||"";if(m!==i){if(m.startsWith(i)){const y=m.slice(i.length);y&&g.current.append(y)}else g.current.reset(),m&&g.current.append(m);R.current=m,F()}},[e,t]),r.useEffect(()=>{t===void 0&&u&&(g.current.finish(),w.current!==null&&(cancelAnimationFrame(w.current),w.current=null),M(),n==null||n())},[u,n,t]),r.useEffect(()=>{h.current.setRate(c)},[c]),r.useEffect(()=>{if(l){const i=g.current.getState().blocks,m=S.current;i.forEach((y,C)=>{const O=m[C];y.stable&&(!O||!O.stable)&&l(y)}),S.current=i}}),r.useEffect(()=>()=>{h.current.stop(),w.current!==null&&cancelAnimationFrame(w.current)},[]);const N=g.current.getState(),z=t!==void 0?h.current.status==="complete":u,H=r.useMemo(()=>{const i=m=>{if(j)return y=>s.jsx(I,{showCopyButton:m.stable&&j,onCopy:v,...y})};return N.blocks.map(m=>{const y=i(m),C={img:q,...y?{pre:y}:{},...a};return s.jsx(X,{block:m,components:C},m.key)})},[N.blocks,a,j,v]);return s.jsx("div",{className:p,"data-streaming":!z,children:H})};Y.displayName="StreamingMarkdown";const Z=r.memo(e=>{const{text:t,animationConfig:c}=e,{fadeDuration:u=200,easing:n="ease-in-out"}=c||{},[l,o]=r.useState([]),a=r.useRef("");r.useEffect(()=>{if(t===a.current)return;if(!(a.current&&t.indexOf(a.current)===0)){o([t]),a.current=t;return}const f=t.slice(a.current.length);f&&(o(b=>[...b,f]),a.current=t)},[t]);const p=`md-fade-in ${u}ms ${n} forwards`;return s.jsx(s.Fragment,{children:l.map((f,b)=>s.jsx("span",{className:"md-animation-text",style:{animation:p},children:f},`animation-text-${b}`))})});Z.displayName="AnimationText";let P=null;try{P=require("dompurify")}catch{}function ge(){return P!==null}function he(e,t){if(!P)return e;const c={ADD_ATTR:["target","rel","data-block-key","data-pending","data-predicted"],...t};return P.default.sanitize(e,c)}function $(e){if(e.type==="root")return{...e,children:e.children.map(n=>n.type==="element"?$(n):n)};const t=["onclick","onerror","onload","onmouseover","onfocus","onblur"],c=["javascript:","vbscript:","data:text/html"],u={};if(e.properties)for(const[n,l]of Object.entries(e.properties)){const o=n.toLowerCase();if(!(t.includes(o)||o.startsWith("on"))){if((o==="href"||o==="src")&&typeof l=="string"){const a=l.toLowerCase().trim();if(c.some(p=>a.startsWith(p)))continue}u[n]=l}}return{...e,properties:u,children:e.children.map(n=>n.type==="element"?$(n):n)}}exports.AnimationText=Z;exports.CodeBlock=I;exports.Markdown=K;exports.StreamingImage=q;exports.StreamingMarkdown=Y;exports.isDOMPurifyAvailable=ge;exports.sanitizeHast=$;exports.sanitizeHtml=he;exports.useMarkdown=ie;exports.useStreamingMarkdown=le;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { Markdown } from './Markdown';
|
|
6
6
|
export { useMarkdown } from './useMarkdown';
|
|
7
|
+
export { CodeBlock } from './components';
|
|
8
|
+
export type { CodeBlockProps } from './components';
|
|
7
9
|
export type { MarkdownProps, MarkdownComponents, UseMarkdownOptions } from './types';
|
|
8
10
|
export { useStreamingMarkdown, StreamingMarkdown, StreamingImage, AnimationText, } from './streaming';
|
|
9
11
|
export type { UseStreamingMarkdownOptions, UseStreamingMarkdownResult, StreamingMarkdownProps, AnimationConfig, StreamingConfig, } from './streaming';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGrF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC3E,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,GACxB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGrF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC3E,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,GACxB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,98 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { parseToHast as
|
|
4
|
-
import { toJsxRuntime as
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { jsxs as A, jsx as s, Fragment as E } from "react/jsx-runtime";
|
|
2
|
+
import Y, { useState as T, useCallback as S, useMemo as F, memo as z, useRef as f, useEffect as x, useLayoutEffect as se } from "react";
|
|
3
|
+
import { parseToHast as Z, createStreamingParser as G, OutputRateController as Q } from "@superlc/md-core";
|
|
4
|
+
import { toJsxRuntime as j } from "hast-util-to-jsx-runtime";
|
|
5
|
+
async function ce(e) {
|
|
6
|
+
try {
|
|
7
|
+
return await navigator.clipboard.writeText(e), !0;
|
|
8
|
+
} catch {
|
|
9
|
+
return ae(e);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function ae(e) {
|
|
13
|
+
const t = document.createElement("textarea");
|
|
14
|
+
t.value = e, t.style.position = "fixed", t.style.left = "-9999px", document.body.appendChild(t), t.select();
|
|
15
|
+
try {
|
|
16
|
+
return document.execCommand("copy"), !0;
|
|
17
|
+
} catch {
|
|
18
|
+
return !1;
|
|
19
|
+
} finally {
|
|
20
|
+
document.body.removeChild(t);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const oe = () => /* @__PURE__ */ s("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ s("path", { d: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" }) }), ie = () => /* @__PURE__ */ s("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ s("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }), J = ({
|
|
24
|
+
children: e,
|
|
25
|
+
showCopyButton: t = !0,
|
|
26
|
+
onCopy: a,
|
|
27
|
+
className: o
|
|
28
|
+
}) => {
|
|
29
|
+
const [r, u] = T(!1), c = S(async () => {
|
|
30
|
+
const n = _(e);
|
|
31
|
+
await ce(n) && (u(!0), a == null || a(n), setTimeout(() => u(!1), 2e3));
|
|
32
|
+
}, [e, a]);
|
|
33
|
+
return /* @__PURE__ */ A("div", { className: `md-code-block-wrapper${o ? ` ${o}` : ""}`, children: [
|
|
34
|
+
/* @__PURE__ */ s("pre", { children: e }),
|
|
35
|
+
t && /* @__PURE__ */ s(
|
|
36
|
+
"button",
|
|
37
|
+
{
|
|
38
|
+
type: "button",
|
|
39
|
+
className: `md-copy-button${r ? " md-copy-button--copied" : ""}`,
|
|
40
|
+
onClick: c,
|
|
41
|
+
title: r ? "已复制" : "复制代码",
|
|
42
|
+
"aria-label": r ? "已复制" : "复制代码",
|
|
43
|
+
children: r ? /* @__PURE__ */ s(ie, {}) : /* @__PURE__ */ s(oe, {})
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
] });
|
|
47
|
+
};
|
|
48
|
+
function _(e) {
|
|
49
|
+
return typeof e == "string" ? e : typeof e == "number" ? String(e) : Array.isArray(e) ? e.map(_).join("") : Y.isValidElement(e) ? _(e.props.children) : "";
|
|
17
50
|
}
|
|
18
|
-
|
|
51
|
+
J.displayName = "CodeBlock";
|
|
52
|
+
const ue = ({
|
|
19
53
|
children: e,
|
|
20
54
|
components: t,
|
|
21
|
-
className:
|
|
22
|
-
|
|
55
|
+
className: a,
|
|
56
|
+
copyButton: o = !0,
|
|
57
|
+
onCodeCopy: r,
|
|
58
|
+
...u
|
|
23
59
|
}) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
60
|
+
const c = F(() => {
|
|
61
|
+
if (!e) return null;
|
|
62
|
+
const n = Z(e, u), p = o ? (w) => /* @__PURE__ */ s(J, { showCopyButton: o, onCopy: r, ...w }) : void 0, m = {
|
|
63
|
+
...p ? { pre: p } : {},
|
|
64
|
+
...t
|
|
65
|
+
};
|
|
66
|
+
return j(n, {
|
|
67
|
+
Fragment: E,
|
|
68
|
+
jsx: s,
|
|
69
|
+
jsxs: A,
|
|
70
|
+
components: m
|
|
71
|
+
});
|
|
72
|
+
}, [e, t, o, r, u]);
|
|
73
|
+
return /* @__PURE__ */ s("div", { className: a, children: c });
|
|
26
74
|
};
|
|
27
|
-
|
|
28
|
-
|
|
75
|
+
ue.displayName = "Markdown";
|
|
76
|
+
function ve(e, t = {}) {
|
|
77
|
+
const { components: a = {}, ...o } = t;
|
|
78
|
+
return F(() => {
|
|
79
|
+
if (!e) return null;
|
|
80
|
+
const r = Z(e, o);
|
|
81
|
+
return j(r, {
|
|
82
|
+
Fragment: E,
|
|
83
|
+
jsx: s,
|
|
84
|
+
jsxs: A,
|
|
85
|
+
components: a
|
|
86
|
+
});
|
|
87
|
+
}, [e, a, o]);
|
|
88
|
+
}
|
|
89
|
+
const ee = z(
|
|
29
90
|
({ block: e, components: t }) => {
|
|
30
91
|
if (!e.hast) return null;
|
|
31
92
|
try {
|
|
32
|
-
return
|
|
33
|
-
jsx:
|
|
34
|
-
jsxs:
|
|
93
|
+
return j(e.hast, {
|
|
94
|
+
jsx: s,
|
|
95
|
+
jsxs: A,
|
|
35
96
|
Fragment: E,
|
|
36
97
|
components: t
|
|
37
98
|
});
|
|
@@ -41,307 +102,324 @@ const X = F(
|
|
|
41
102
|
},
|
|
42
103
|
(e, t) => e.block.key === t.block.key && e.block.stable && t.block.stable
|
|
43
104
|
);
|
|
44
|
-
|
|
45
|
-
function
|
|
105
|
+
ee.displayName = "StableBlock";
|
|
106
|
+
function xe(e = {}) {
|
|
46
107
|
const {
|
|
47
108
|
components: t,
|
|
48
|
-
minUpdateInterval:
|
|
49
|
-
immediate:
|
|
109
|
+
minUpdateInterval: a = 16,
|
|
110
|
+
immediate: o = !1,
|
|
50
111
|
outputRate: r = "medium",
|
|
51
|
-
...
|
|
52
|
-
} = e,
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
112
|
+
...u
|
|
113
|
+
} = e, c = f(G(u)), n = f(new Q(r)), [p, m] = T(0), [w, v] = T(!1), [C, h] = T(0), [g, k] = T("idle"), N = f(0), d = f(null), L = S(() => {
|
|
114
|
+
const y = performance.now(), U = y - N.current;
|
|
115
|
+
o || U >= a ? (N.current = y, m((W) => W + 1)) : d.current === null && (d.current = window.requestAnimationFrame(() => {
|
|
116
|
+
d.current = null, N.current = performance.now(), m((W) => W + 1);
|
|
56
117
|
}));
|
|
57
|
-
}, [
|
|
58
|
-
(
|
|
59
|
-
|
|
118
|
+
}, [a, o]), B = S(
|
|
119
|
+
(y) => {
|
|
120
|
+
c.current.append(y), L();
|
|
60
121
|
},
|
|
61
|
-
[
|
|
62
|
-
),
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
(
|
|
67
|
-
|
|
122
|
+
[L]
|
|
123
|
+
), I = S(
|
|
124
|
+
(y) => {
|
|
125
|
+
c.current.reset(), v(!1), h(0), k("running"), n.current.start(
|
|
126
|
+
y,
|
|
127
|
+
(U) => {
|
|
128
|
+
U && c.current.append(U), h(n.current.progress), L();
|
|
68
129
|
},
|
|
69
130
|
() => {
|
|
70
|
-
|
|
131
|
+
c.current.finish(), v(!0), h(1), k("complete"), L();
|
|
71
132
|
}
|
|
72
133
|
);
|
|
73
134
|
},
|
|
74
|
-
[
|
|
75
|
-
),
|
|
76
|
-
n.current.pause(),
|
|
77
|
-
}, []),
|
|
78
|
-
n.current.resume(),
|
|
79
|
-
}, []),
|
|
80
|
-
n.current.skipToEnd(),
|
|
81
|
-
}, []),
|
|
82
|
-
n.current.stop(),
|
|
83
|
-
}, []),
|
|
84
|
-
n.current.stop(),
|
|
135
|
+
[L]
|
|
136
|
+
), R = S(() => {
|
|
137
|
+
n.current.pause(), k(n.current.status);
|
|
138
|
+
}, []), P = S(() => {
|
|
139
|
+
n.current.resume(), k(n.current.status);
|
|
140
|
+
}, []), D = S(() => {
|
|
141
|
+
n.current.skipToEnd(), k(n.current.status), h(1);
|
|
142
|
+
}, []), H = S(() => {
|
|
143
|
+
n.current.stop(), c.current.finish(), v(!0), k("complete"), d.current !== null && (cancelAnimationFrame(d.current), d.current = null), m((y) => y + 1);
|
|
144
|
+
}, []), O = S(() => {
|
|
145
|
+
n.current.stop(), c.current.reset(), v(!1), h(0), k("idle"), d.current !== null && (cancelAnimationFrame(d.current), d.current = null), m((y) => y + 1);
|
|
85
146
|
}, []);
|
|
86
|
-
|
|
147
|
+
x(() => {
|
|
87
148
|
n.current.setRate(r);
|
|
88
|
-
}, [r]),
|
|
89
|
-
n.current.stop(),
|
|
149
|
+
}, [r]), x(() => () => {
|
|
150
|
+
n.current.stop(), d.current !== null && cancelAnimationFrame(d.current);
|
|
90
151
|
}, []);
|
|
91
|
-
const
|
|
92
|
-
(
|
|
93
|
-
|
|
152
|
+
const i = c.current.getState(), l = c.current.getStats(), b = c.current.getContent(), M = F(() => i.blocks.map(
|
|
153
|
+
(y) => s(
|
|
154
|
+
ee,
|
|
94
155
|
{
|
|
95
|
-
block:
|
|
156
|
+
block: y,
|
|
96
157
|
components: t
|
|
97
158
|
},
|
|
98
|
-
|
|
159
|
+
y.key
|
|
99
160
|
)
|
|
100
|
-
), [
|
|
161
|
+
), [i.blocks, t, p]);
|
|
101
162
|
return {
|
|
102
|
-
element:
|
|
103
|
-
append:
|
|
104
|
-
start:
|
|
105
|
-
pause:
|
|
106
|
-
resume:
|
|
107
|
-
skipToEnd:
|
|
108
|
-
reset:
|
|
109
|
-
finish:
|
|
110
|
-
blocks:
|
|
111
|
-
stats:
|
|
112
|
-
isComplete:
|
|
113
|
-
content:
|
|
114
|
-
progress:
|
|
115
|
-
outputStatus:
|
|
163
|
+
element: F(() => i.blocks.length === 0 ? null : s(E, { children: M }), [M, i.blocks.length]),
|
|
164
|
+
append: B,
|
|
165
|
+
start: I,
|
|
166
|
+
pause: R,
|
|
167
|
+
resume: P,
|
|
168
|
+
skipToEnd: D,
|
|
169
|
+
reset: O,
|
|
170
|
+
finish: H,
|
|
171
|
+
blocks: i.blocks,
|
|
172
|
+
stats: l,
|
|
173
|
+
isComplete: w,
|
|
174
|
+
content: b,
|
|
175
|
+
progress: C,
|
|
176
|
+
outputStatus: g
|
|
116
177
|
};
|
|
117
178
|
}
|
|
118
|
-
const
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
/* @__PURE__ */
|
|
121
|
-
/* @__PURE__ */
|
|
122
|
-
] }),
|
|
179
|
+
const le = 16, me = "data:image/svg+xml,", de = () => /* @__PURE__ */ A("svg", { width: "48", height: "36", viewBox: "0 0 48 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
180
|
+
/* @__PURE__ */ s("rect", { x: "0", y: "0", width: "48", height: "36", rx: "3", className: "md-image-skeleton-icon" }),
|
|
181
|
+
/* @__PURE__ */ s("circle", { cx: "12", cy: "10", r: "5", className: "md-image-skeleton-icon-detail" }),
|
|
182
|
+
/* @__PURE__ */ s("path", { d: "M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z", className: "md-image-skeleton-icon-detail" })
|
|
183
|
+
] }), te = z(({
|
|
123
184
|
src: e,
|
|
124
185
|
alt: t,
|
|
125
|
-
className:
|
|
126
|
-
"data-width":
|
|
186
|
+
className: a,
|
|
187
|
+
"data-width": o,
|
|
127
188
|
"data-height": r,
|
|
128
|
-
...
|
|
189
|
+
...u
|
|
129
190
|
}) => {
|
|
130
|
-
const n = (e == null ? void 0 : e.startsWith(
|
|
131
|
-
|
|
132
|
-
|
|
191
|
+
const n = (e == null ? void 0 : e.startsWith(me)) ? void 0 : e, p = o ? Number(o) : 200, m = r ? Number(r) : 120, [w, v] = T(!0), C = f(null), h = f(null);
|
|
192
|
+
se(() => {
|
|
193
|
+
C.current && n && C.current.complete && C.current.naturalWidth > 0 && v(!1);
|
|
133
194
|
}, [n]);
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
195
|
+
const g = S(() => {
|
|
196
|
+
h.current && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
197
|
+
v(!1);
|
|
198
|
+
}, le);
|
|
138
199
|
}, []);
|
|
139
|
-
return /* @__PURE__ */
|
|
200
|
+
return /* @__PURE__ */ A(
|
|
140
201
|
"span",
|
|
141
202
|
{
|
|
142
|
-
className: `md-image-container ${
|
|
143
|
-
style: { width:
|
|
203
|
+
className: `md-image-container ${a || ""}`,
|
|
204
|
+
style: { width: p, height: m },
|
|
144
205
|
children: [
|
|
145
|
-
n && /* @__PURE__ */
|
|
206
|
+
n && /* @__PURE__ */ s(
|
|
146
207
|
"img",
|
|
147
208
|
{
|
|
148
|
-
ref:
|
|
209
|
+
ref: C,
|
|
149
210
|
src: n,
|
|
150
211
|
alt: t,
|
|
151
|
-
onLoad:
|
|
212
|
+
onLoad: g,
|
|
152
213
|
className: "md-image",
|
|
153
|
-
...
|
|
214
|
+
...u
|
|
154
215
|
}
|
|
155
216
|
),
|
|
156
|
-
|
|
217
|
+
w && /* @__PURE__ */ s("span", { className: "md-image-skeleton", children: /* @__PURE__ */ s(de, {}) })
|
|
157
218
|
]
|
|
158
219
|
}
|
|
159
220
|
);
|
|
160
221
|
});
|
|
161
|
-
|
|
162
|
-
let
|
|
163
|
-
async function
|
|
164
|
-
if (!
|
|
165
|
-
return
|
|
166
|
-
await import("katex/dist/katex.min.css"),
|
|
167
|
-
})(),
|
|
222
|
+
te.displayName = "StreamingImage";
|
|
223
|
+
let q = !1, V = null;
|
|
224
|
+
async function re() {
|
|
225
|
+
if (!q)
|
|
226
|
+
return V || (V = (async () => {
|
|
227
|
+
await import("katex/dist/katex.min.css"), q = !0;
|
|
228
|
+
})(), V);
|
|
168
229
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
}, []), /* @__PURE__ */
|
|
172
|
-
|
|
173
|
-
function
|
|
174
|
-
return
|
|
230
|
+
const fe = z(({ children: e }) => (x(() => {
|
|
231
|
+
q || re();
|
|
232
|
+
}, []), /* @__PURE__ */ s(E, { children: e })));
|
|
233
|
+
fe.displayName = "MathProvider";
|
|
234
|
+
function pe() {
|
|
235
|
+
return re();
|
|
175
236
|
}
|
|
176
|
-
const
|
|
237
|
+
const ne = z(
|
|
177
238
|
({ block: e, components: t }) => {
|
|
178
239
|
if (!e.hast) return null;
|
|
179
240
|
try {
|
|
180
|
-
return
|
|
181
|
-
jsx:
|
|
182
|
-
jsxs:
|
|
241
|
+
return j(e.hast, {
|
|
242
|
+
jsx: s,
|
|
243
|
+
jsxs: A,
|
|
183
244
|
Fragment: E,
|
|
184
245
|
components: t
|
|
185
246
|
});
|
|
186
247
|
} catch {
|
|
187
|
-
return /* @__PURE__ */
|
|
248
|
+
return /* @__PURE__ */ s("div", { className: "parse-error", children: e.source });
|
|
188
249
|
}
|
|
189
250
|
},
|
|
190
251
|
(e, t) => e.block.key === t.block.key && e.block.stable && t.block.stable
|
|
191
252
|
);
|
|
192
|
-
|
|
193
|
-
const
|
|
253
|
+
ne.displayName = "StableBlock";
|
|
254
|
+
const he = ({
|
|
194
255
|
content: e,
|
|
195
256
|
source: t,
|
|
196
|
-
outputRate:
|
|
197
|
-
isComplete:
|
|
257
|
+
outputRate: a = "medium",
|
|
258
|
+
isComplete: o = !1,
|
|
198
259
|
onComplete: r,
|
|
199
|
-
onBlockStable:
|
|
200
|
-
onProgress:
|
|
260
|
+
onBlockStable: u,
|
|
261
|
+
onProgress: c,
|
|
201
262
|
components: n,
|
|
202
|
-
className:
|
|
203
|
-
minUpdateInterval:
|
|
204
|
-
autoStart:
|
|
205
|
-
|
|
263
|
+
className: p,
|
|
264
|
+
minUpdateInterval: m = 16,
|
|
265
|
+
autoStart: w = !0,
|
|
266
|
+
copyButton: v = !0,
|
|
267
|
+
onCodeCopy: C,
|
|
268
|
+
...h
|
|
206
269
|
}) => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}, [
|
|
210
|
-
const
|
|
270
|
+
x(() => {
|
|
271
|
+
h.math && pe();
|
|
272
|
+
}, [h.math]);
|
|
273
|
+
const g = f(G(h)), k = f(new Q(a)), N = f(""), d = f(void 0), L = f([]), [, B] = Y.useReducer((i) => i + 1, 0), I = f(0), R = f(null), P = () => {
|
|
211
274
|
const i = performance.now();
|
|
212
|
-
i -
|
|
213
|
-
R.current = null,
|
|
275
|
+
i - I.current >= m ? (I.current = i, B()) : R.current === null && (R.current = window.requestAnimationFrame(() => {
|
|
276
|
+
R.current = null, I.current = performance.now(), B();
|
|
214
277
|
}));
|
|
215
278
|
};
|
|
216
|
-
|
|
217
|
-
t !== void 0 && t !==
|
|
279
|
+
x(() => {
|
|
280
|
+
t !== void 0 && t !== d.current && (d.current = t, w && t && (g.current.reset(), N.current = "", k.current.start(
|
|
218
281
|
t,
|
|
219
282
|
(i) => {
|
|
220
|
-
i && (
|
|
283
|
+
i && (g.current.append(i), N.current += i), c == null || c(k.current.progress), P();
|
|
221
284
|
},
|
|
222
285
|
() => {
|
|
223
|
-
|
|
286
|
+
g.current.finish(), r == null || r(), P();
|
|
224
287
|
}
|
|
225
288
|
)));
|
|
226
|
-
}, [t,
|
|
289
|
+
}, [t, w, r, c]), x(() => {
|
|
227
290
|
if (t !== void 0)
|
|
228
291
|
return;
|
|
229
|
-
const i =
|
|
230
|
-
if (
|
|
231
|
-
if (
|
|
232
|
-
const
|
|
233
|
-
|
|
292
|
+
const i = N.current, l = e || "";
|
|
293
|
+
if (l !== i) {
|
|
294
|
+
if (l.startsWith(i)) {
|
|
295
|
+
const b = l.slice(i.length);
|
|
296
|
+
b && g.current.append(b);
|
|
234
297
|
} else
|
|
235
|
-
|
|
236
|
-
|
|
298
|
+
g.current.reset(), l && g.current.append(l);
|
|
299
|
+
N.current = l, P();
|
|
237
300
|
}
|
|
238
|
-
}, [e, t]),
|
|
239
|
-
t === void 0 &&
|
|
240
|
-
}, [
|
|
241
|
-
|
|
242
|
-
}, [
|
|
243
|
-
if (
|
|
244
|
-
const i =
|
|
245
|
-
i.forEach((
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
}),
|
|
301
|
+
}, [e, t]), x(() => {
|
|
302
|
+
t === void 0 && o && (g.current.finish(), R.current !== null && (cancelAnimationFrame(R.current), R.current = null), B(), r == null || r());
|
|
303
|
+
}, [o, r, t]), x(() => {
|
|
304
|
+
k.current.setRate(a);
|
|
305
|
+
}, [a]), x(() => {
|
|
306
|
+
if (u) {
|
|
307
|
+
const i = g.current.getState().blocks, l = L.current;
|
|
308
|
+
i.forEach((b, M) => {
|
|
309
|
+
const K = l[M];
|
|
310
|
+
b.stable && (!K || !K.stable) && u(b);
|
|
311
|
+
}), L.current = i;
|
|
249
312
|
}
|
|
250
|
-
}),
|
|
251
|
-
|
|
313
|
+
}), x(() => () => {
|
|
314
|
+
k.current.stop(), R.current !== null && cancelAnimationFrame(R.current);
|
|
252
315
|
}, []);
|
|
253
|
-
const
|
|
254
|
-
const i = {
|
|
255
|
-
|
|
256
|
-
|
|
316
|
+
const D = g.current.getState(), H = t !== void 0 ? k.current.status === "complete" : o, O = F(() => {
|
|
317
|
+
const i = (l) => {
|
|
318
|
+
if (v)
|
|
319
|
+
return (b) => /* @__PURE__ */ s(
|
|
320
|
+
J,
|
|
321
|
+
{
|
|
322
|
+
showCopyButton: l.stable && v,
|
|
323
|
+
onCopy: C,
|
|
324
|
+
...b
|
|
325
|
+
}
|
|
326
|
+
);
|
|
257
327
|
};
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
328
|
+
return D.blocks.map((l) => {
|
|
329
|
+
const b = i(l), M = {
|
|
330
|
+
img: te,
|
|
331
|
+
...b ? { pre: b } : {},
|
|
332
|
+
...n
|
|
333
|
+
};
|
|
334
|
+
return /* @__PURE__ */ s(
|
|
335
|
+
ne,
|
|
336
|
+
{
|
|
337
|
+
block: l,
|
|
338
|
+
components: M
|
|
339
|
+
},
|
|
340
|
+
l.key
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
}, [D.blocks, n, v, C]);
|
|
344
|
+
return /* @__PURE__ */ s("div", { className: p, "data-streaming": !H, children: O });
|
|
268
345
|
};
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
const { text: t, animationConfig:
|
|
272
|
-
|
|
346
|
+
he.displayName = "StreamingMarkdown";
|
|
347
|
+
const ge = z((e) => {
|
|
348
|
+
const { text: t, animationConfig: a } = e, { fadeDuration: o = 200, easing: r = "ease-in-out" } = a || {}, [u, c] = T([]), n = f("");
|
|
349
|
+
x(() => {
|
|
273
350
|
if (t === n.current) return;
|
|
274
351
|
if (!(n.current && t.indexOf(n.current) === 0)) {
|
|
275
|
-
|
|
352
|
+
c([t]), n.current = t;
|
|
276
353
|
return;
|
|
277
354
|
}
|
|
278
|
-
const
|
|
279
|
-
|
|
355
|
+
const m = t.slice(n.current.length);
|
|
356
|
+
m && (c((w) => [...w, m]), n.current = t);
|
|
280
357
|
}, [t]);
|
|
281
|
-
const
|
|
282
|
-
return /* @__PURE__ */
|
|
358
|
+
const p = `md-fade-in ${o}ms ${r} forwards`;
|
|
359
|
+
return /* @__PURE__ */ s(E, { children: u.map((m, w) => /* @__PURE__ */ s(
|
|
283
360
|
"span",
|
|
284
361
|
{
|
|
285
362
|
className: "md-animation-text",
|
|
286
|
-
style: { animation:
|
|
287
|
-
children:
|
|
363
|
+
style: { animation: p },
|
|
364
|
+
children: m
|
|
288
365
|
},
|
|
289
|
-
`animation-text-${
|
|
366
|
+
`animation-text-${w}`
|
|
290
367
|
)) });
|
|
291
368
|
});
|
|
292
|
-
|
|
293
|
-
let
|
|
369
|
+
ge.displayName = "AnimationText";
|
|
370
|
+
let $ = null;
|
|
294
371
|
try {
|
|
295
|
-
|
|
372
|
+
$ = require("dompurify");
|
|
296
373
|
} catch {
|
|
297
374
|
}
|
|
298
|
-
function
|
|
299
|
-
return
|
|
375
|
+
function Re() {
|
|
376
|
+
return $ !== null;
|
|
300
377
|
}
|
|
301
|
-
function
|
|
302
|
-
if (
|
|
378
|
+
function Se(e, t) {
|
|
379
|
+
if (!$)
|
|
303
380
|
return e;
|
|
304
|
-
const
|
|
381
|
+
const a = {
|
|
305
382
|
ADD_ATTR: ["target", "rel", "data-block-key", "data-pending", "data-predicted"],
|
|
306
383
|
...t
|
|
307
384
|
};
|
|
308
|
-
return
|
|
385
|
+
return $.default.sanitize(e, a);
|
|
309
386
|
}
|
|
310
|
-
function
|
|
387
|
+
function X(e) {
|
|
311
388
|
if (e.type === "root")
|
|
312
389
|
return {
|
|
313
390
|
...e,
|
|
314
391
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
315
|
-
children: e.children.map((r) => r.type === "element" ?
|
|
392
|
+
children: e.children.map((r) => r.type === "element" ? X(r) : r)
|
|
316
393
|
};
|
|
317
|
-
const t = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur"],
|
|
394
|
+
const t = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur"], a = ["javascript:", "vbscript:", "data:text/html"], o = {};
|
|
318
395
|
if (e.properties)
|
|
319
|
-
for (const [r,
|
|
320
|
-
const
|
|
321
|
-
if (!(t.includes(
|
|
322
|
-
if ((
|
|
323
|
-
const n =
|
|
324
|
-
if (
|
|
396
|
+
for (const [r, u] of Object.entries(e.properties)) {
|
|
397
|
+
const c = r.toLowerCase();
|
|
398
|
+
if (!(t.includes(c) || c.startsWith("on"))) {
|
|
399
|
+
if ((c === "href" || c === "src") && typeof u == "string") {
|
|
400
|
+
const n = u.toLowerCase().trim();
|
|
401
|
+
if (a.some((p) => n.startsWith(p)))
|
|
325
402
|
continue;
|
|
326
403
|
}
|
|
327
|
-
|
|
404
|
+
o[r] = u;
|
|
328
405
|
}
|
|
329
406
|
}
|
|
330
407
|
return {
|
|
331
408
|
...e,
|
|
332
|
-
properties:
|
|
409
|
+
properties: o,
|
|
333
410
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
|
-
children: e.children.map((r) => r.type === "element" ?
|
|
411
|
+
children: e.children.map((r) => r.type === "element" ? X(r) : r)
|
|
335
412
|
};
|
|
336
413
|
}
|
|
337
414
|
export {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
415
|
+
ge as AnimationText,
|
|
416
|
+
J as CodeBlock,
|
|
417
|
+
ue as Markdown,
|
|
418
|
+
te as StreamingImage,
|
|
419
|
+
he as StreamingMarkdown,
|
|
420
|
+
Re as isDOMPurifyAvailable,
|
|
421
|
+
X as sanitizeHast,
|
|
422
|
+
Se as sanitizeHtml,
|
|
423
|
+
ve as useMarkdown,
|
|
424
|
+
xe as useStreamingMarkdown
|
|
347
425
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../src/streaming/StreamingMarkdown.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,OAAO,CAAC;AAQ9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../src/streaming/StreamingMarkdown.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,OAAO,CAAC;AAQ9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAmCtD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAoNxD,CAAC"}
|
|
@@ -117,5 +117,9 @@ export interface StreamingMarkdownProps extends StreamingParserOptions {
|
|
|
117
117
|
autoStart?: boolean;
|
|
118
118
|
/** 流式渲染配置(动画等) */
|
|
119
119
|
streaming?: StreamingConfig;
|
|
120
|
+
/** 是否显示代码块复制按钮,默认 true */
|
|
121
|
+
copyButton?: boolean;
|
|
122
|
+
/** 复制成功回调 */
|
|
123
|
+
onCodeCopy?: (code: string) => void;
|
|
120
124
|
}
|
|
121
125
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/streaming/types.ts"],"names":[],"mappings":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AClB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa;IACb,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export interface MarkdownProps extends ProcessorOptions {
|
|
|
18
18
|
components?: MarkdownComponents;
|
|
19
19
|
/** 容器 className */
|
|
20
20
|
className?: string;
|
|
21
|
+
/** 是否显示代码块复制按钮,默认 true */
|
|
22
|
+
copyButton?: boolean;
|
|
23
|
+
/** 复制成功回调 */
|
|
24
|
+
onCodeCopy?: (code: string) => void;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* useMarkdown Hook 配置
|
|
@@ -25,5 +29,9 @@ export interface MarkdownProps extends ProcessorOptions {
|
|
|
25
29
|
export interface UseMarkdownOptions extends ProcessorOptions {
|
|
26
30
|
/** 自定义组件映射 */
|
|
27
31
|
components?: MarkdownComponents;
|
|
32
|
+
/** 是否显示代码块复制按钮,默认 true */
|
|
33
|
+
copyButton?: boolean;
|
|
34
|
+
/** 复制成功回调 */
|
|
35
|
+
onCodeCopy?: (code: string) => void;
|
|
28
36
|
}
|
|
29
37
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,mBAAmB;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,mBAAmB;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa;IACb,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa;IACb,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superlc/md-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "基于 @superlc/md-core 的 React Markdown 渲染组件",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,16 +17,10 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "vite build",
|
|
22
|
-
"dev": "vite build --watch",
|
|
23
|
-
"test": "vitest",
|
|
24
|
-
"test:run": "vitest run"
|
|
25
|
-
},
|
|
26
20
|
"dependencies": {
|
|
27
|
-
"@superlc/md-core": "workspace:*",
|
|
28
21
|
"hast-util-to-jsx-runtime": "^2.3.0",
|
|
29
|
-
"katex": "^0.16.28"
|
|
22
|
+
"katex": "^0.16.28",
|
|
23
|
+
"@superlc/md-core": "0.1.1"
|
|
30
24
|
},
|
|
31
25
|
"optionalDependencies": {
|
|
32
26
|
"dompurify": "^3.0.0"
|
|
@@ -48,5 +42,11 @@
|
|
|
48
42
|
"component",
|
|
49
43
|
"unified"
|
|
50
44
|
],
|
|
51
|
-
"license": "MIT"
|
|
52
|
-
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "vite build",
|
|
48
|
+
"dev": "vite build --watch",
|
|
49
|
+
"test": "vitest",
|
|
50
|
+
"test:run": "vitest run"
|
|
51
|
+
}
|
|
52
|
+
}
|