@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.
@@ -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;AAEhC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAStC,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,2 @@
1
+ export { CodeBlock, type CodeBlockProps } from './CodeBlock';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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 Y=Object.create;var H=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(e,t,c,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of G(t))!ee.call(e,n)&&n!==c&&H(e,n,{get:()=>t[n],enumerable:!(i=Z(t,n))||i.enumerable});return e};var re=(e,t,c)=>(c=e!=null?Y(Q(e)):{},te(t||!e||!e.__esModule?H(c,"default",{value:e,enumerable:!0}):c,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),r=require("react"),M=require("@superlc/md-core"),U=require("hast-util-to-jsx-runtime");function $(e,t={}){const{components:c={},...i}=t;return r.useMemo(()=>{if(!e)return null;const n=M.parseToHast(e,i);return U.toJsxRuntime(n,{Fragment:a.Fragment,jsx:a.jsx,jsxs:a.jsxs,components:c})},[e,c,i])}const J=({children:e,components:t,className:c,...i})=>{const n=$(e,{components:t,...i});return a.jsx("div",{className:c,children:n})};J.displayName="Markdown";const K=r.memo(({block:e,components:t})=>{if(!e.hast)return null;try{return U.toJsxRuntime(e.hast,{jsx:a.jsx,jsxs:a.jsxs,Fragment:a.Fragment,components:t})}catch{return null}},(e,t)=>e.block.key===t.block.key&&e.block.stable&&t.block.stable);K.displayName="StableBlock";function ne(e={}){const{components:t,minUpdateInterval:c=16,immediate:i=!1,outputRate:n="medium",...k}=e,u=r.useRef(M.createStreamingParser(k)),s=r.useRef(new M.OutputRateController(n)),[y,p]=r.useState(0),[w,h]=r.useState(!1),[l,f]=r.useState(0),[S,R]=r.useState("idle"),v=r.useRef(0),m=r.useRef(null),j=r.useCallback(()=>{const g=performance.now(),A=g-v.current;i||A>=c?(v.current=g,p(B=>B+1)):m.current===null&&(m.current=window.requestAnimationFrame(()=>{m.current=null,v.current=performance.now(),p(B=>B+1)}))},[c,i]),b=r.useCallback(g=>{u.current.append(g),j()},[j]),E=r.useCallback(g=>{u.current.reset(),h(!1),f(0),R("running"),s.current.start(g,A=>{A&&u.current.append(A),f(s.current.progress),j()},()=>{u.current.finish(),h(!0),f(1),R("complete"),j()})},[j]),C=r.useCallback(()=>{s.current.pause(),R(s.current.status)},[]),T=r.useCallback(()=>{s.current.resume(),R(s.current.status)},[]),O=r.useCallback(()=>{s.current.skipToEnd(),R(s.current.status),f(1)},[]),o=r.useCallback(()=>{s.current.stop(),u.current.finish(),h(!0),R("complete"),m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),p(g=>g+1)},[]),d=r.useCallback(()=>{s.current.stop(),u.current.reset(),h(!1),f(0),R("idle"),m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),p(g=>g+1)},[]);r.useEffect(()=>{s.current.setRate(n)},[n]),r.useEffect(()=>()=>{s.current.stop(),m.current!==null&&cancelAnimationFrame(m.current)},[]);const x=u.current.getState(),P=u.current.getStats(),N=u.current.getContent(),z=r.useMemo(()=>x.blocks.map(g=>a.jsx(K,{block:g,components:t},g.key)),[x.blocks,t,y]);return{element:r.useMemo(()=>x.blocks.length===0?null:a.jsx(a.Fragment,{children:z}),[z,x.blocks.length]),append:b,start:E,pause:C,resume:T,skipToEnd:O,reset:d,finish:o,blocks:x.blocks,stats:P,isComplete:w,content:N,progress:l,outputStatus:S}}const se=16,ae="data:image/svg+xml,",ce=()=>a.jsxs("svg",{width:"48",height:"36",viewBox:"0 0 48 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("rect",{x:"0",y:"0",width:"48",height:"36",rx:"3",className:"md-image-skeleton-icon"}),a.jsx("circle",{cx:"12",cy:"10",r:"5",className:"md-image-skeleton-icon-detail"}),a.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":i,"data-height":n,...k})=>{const s=(e==null?void 0:e.startsWith(ae))?void 0:e,y=i?Number(i):200,p=n?Number(n):120,[w,h]=r.useState(!0),l=r.useRef(null),f=r.useRef(null);r.useLayoutEffect(()=>{l.current&&s&&l.current.complete&&l.current.naturalWidth>0&&h(!1)},[s]);const S=r.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{h(!1)},se)},[]);return a.jsxs("span",{className:`md-image-container ${c||""}`,style:{width:y,height:p},children:[s&&a.jsx("img",{ref:l,src:s,alt:t,onLoad:S,className:"md-image",...k}),w&&a.jsx("span",{className:"md-image-skeleton",children:a.jsx(ce,{})})]})});q.displayName="StreamingImage";let I=!1,F=null;async function W(){if(!I)return F||(F=(async()=>{await import("katex/dist/katex.min.css"),I=!0})(),F)}const ue=r.memo(({children:e})=>(r.useEffect(()=>{I||W()},[]),a.jsx(a.Fragment,{children:e})));ue.displayName="MathProvider";function ie(){return W()}const _=r.memo(({block:e,components:t})=>{if(!e.hast)return null;try{return U.toJsxRuntime(e.hast,{jsx:a.jsx,jsxs:a.jsxs,Fragment:a.Fragment,components:t})}catch{return a.jsx("div",{className:"parse-error",children:e.source})}},(e,t)=>e.block.key===t.block.key&&e.block.stable&&t.block.stable);_.displayName="StableBlock";const V=({content:e,source:t,outputRate:c="medium",isComplete:i=!1,onComplete:n,onBlockStable:k,onProgress:u,components:s,className:y,minUpdateInterval:p=16,autoStart:w=!0,...h})=>{r.useEffect(()=>{h.math&&ie()},[h.math]);const l=r.useRef(M.createStreamingParser(h)),f=r.useRef(new M.OutputRateController(c)),S=r.useRef(""),R=r.useRef(void 0),v=r.useRef([]),[,m]=r.useReducer(o=>o+1,0),j=r.useRef(0),b=r.useRef(null),E=()=>{const o=performance.now();o-j.current>=p?(j.current=o,m()):b.current===null&&(b.current=window.requestAnimationFrame(()=>{b.current=null,j.current=performance.now(),m()}))};r.useEffect(()=>{t!==void 0&&t!==R.current&&(R.current=t,w&&t&&(l.current.reset(),S.current="",f.current.start(t,o=>{o&&(l.current.append(o),S.current+=o),u==null||u(f.current.progress),E()},()=>{l.current.finish(),n==null||n(),E()})))},[t,w,n,u]),r.useEffect(()=>{if(t!==void 0)return;const o=S.current,d=e||"";if(d!==o){if(d.startsWith(o)){const x=d.slice(o.length);x&&l.current.append(x)}else l.current.reset(),d&&l.current.append(d);S.current=d,E()}},[e,t]),r.useEffect(()=>{t===void 0&&i&&(l.current.finish(),b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),m(),n==null||n())},[i,n,t]),r.useEffect(()=>{f.current.setRate(c)},[c]),r.useEffect(()=>{if(k){const o=l.current.getState().blocks,d=v.current;o.forEach((x,P)=>{const N=d[P];x.stable&&(!N||!N.stable)&&k(x)}),v.current=o}}),r.useEffect(()=>()=>{f.current.stop(),b.current!==null&&cancelAnimationFrame(b.current)},[]);const C=l.current.getState(),T=t!==void 0?f.current.status==="complete":i,O=r.useMemo(()=>{const o={img:q,...s};return C.blocks.map(d=>a.jsx(_,{block:d,components:o},d.key))},[C.blocks,s]);return a.jsx("div",{className:y,"data-streaming":!T,children:O})};V.displayName="StreamingMarkdown";const X=r.memo(e=>{const{text:t,animationConfig:c}=e,{fadeDuration:i=200,easing:n="ease-in-out"}=c||{},[k,u]=r.useState([]),s=r.useRef("");r.useEffect(()=>{if(t===s.current)return;if(!(s.current&&t.indexOf(s.current)===0)){u([t]),s.current=t;return}const p=t.slice(s.current.length);p&&(u(w=>[...w,p]),s.current=t)},[t]);const y=`md-fade-in ${i}ms ${n} forwards`;return a.jsx(a.Fragment,{children:k.map((p,w)=>a.jsx("span",{className:"md-animation-text",style:{animation:y},children:p},`animation-text-${w}`))})});X.displayName="AnimationText";let L=null;try{L=require("dompurify")}catch{}function oe(){return L!==null}function le(e,t){if(!L)return e;const c={ADD_ATTR:["target","rel","data-block-key","data-pending","data-predicted"],...t};return L.default.sanitize(e,c)}function D(e){if(e.type==="root")return{...e,children:e.children.map(n=>n.type==="element"?D(n):n)};const t=["onclick","onerror","onload","onmouseover","onfocus","onblur"],c=["javascript:","vbscript:","data:text/html"],i={};if(e.properties)for(const[n,k]of Object.entries(e.properties)){const u=n.toLowerCase();if(!(t.includes(u)||u.startsWith("on"))){if((u==="href"||u==="src")&&typeof k=="string"){const s=k.toLowerCase().trim();if(c.some(y=>s.startsWith(y)))continue}i[n]=k}}return{...e,properties:i,children:e.children.map(n=>n.type==="element"?D(n):n)}}exports.AnimationText=X;exports.Markdown=J;exports.StreamingImage=q;exports.StreamingMarkdown=V;exports.isDOMPurifyAvailable=oe;exports.sanitizeHast=D;exports.sanitizeHtml=le;exports.useMarkdown=$;exports.useStreamingMarkdown=ne;
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';
@@ -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 B, jsx as o, Fragment as E } from "react/jsx-runtime";
2
- import Q, { useMemo as P, memo as F, useRef as d, useState as T, useCallback as N, useEffect as y, useLayoutEffect as ee } from "react";
3
- import { parseToHast as te, createStreamingParser as V, OutputRateController as J } from "@superlc/md-core";
4
- import { toJsxRuntime as W } from "hast-util-to-jsx-runtime";
5
- function re(e, t = {}) {
6
- const { components: c = {}, ...a } = t;
7
- return P(() => {
8
- if (!e) return null;
9
- const r = te(e, a);
10
- return W(r, {
11
- Fragment: E,
12
- jsx: o,
13
- jsxs: B,
14
- components: c
15
- });
16
- }, [e, c, a]);
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
- const ne = ({
51
+ J.displayName = "CodeBlock";
52
+ const ue = ({
19
53
  children: e,
20
54
  components: t,
21
- className: c,
22
- ...a
55
+ className: a,
56
+ copyButton: o = !0,
57
+ onCodeCopy: r,
58
+ ...u
23
59
  }) => {
24
- const r = re(e, { components: t, ...a });
25
- return /* @__PURE__ */ o("div", { className: c, children: r });
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
- ne.displayName = "Markdown";
28
- const X = F(
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 W(e.hast, {
33
- jsx: o,
34
- jsxs: B,
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
- X.displayName = "StableBlock";
45
- function ge(e = {}) {
105
+ ee.displayName = "StableBlock";
106
+ function xe(e = {}) {
46
107
  const {
47
108
  components: t,
48
- minUpdateInterval: c = 16,
49
- immediate: a = !1,
109
+ minUpdateInterval: a = 16,
110
+ immediate: o = !1,
50
111
  outputRate: r = "medium",
51
- ...g
52
- } = e, s = d(V(g)), n = d(new J(r)), [x, p] = T(0), [b, k] = T(!1), [u, l] = T(0), [L, v] = T("idle"), A = d(0), m = d(null), S = N(() => {
53
- const h = performance.now(), D = h - A.current;
54
- a || D >= c ? (A.current = h, p((H) => H + 1)) : m.current === null && (m.current = window.requestAnimationFrame(() => {
55
- m.current = null, A.current = performance.now(), p((H) => H + 1);
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
- }, [c, a]), R = N(
58
- (h) => {
59
- s.current.append(h), S();
118
+ }, [a, o]), B = S(
119
+ (y) => {
120
+ c.current.append(y), L();
60
121
  },
61
- [S]
62
- ), M = N(
63
- (h) => {
64
- s.current.reset(), k(!1), l(0), v("running"), n.current.start(
65
- h,
66
- (D) => {
67
- D && s.current.append(D), l(n.current.progress), S();
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
- s.current.finish(), k(!0), l(1), v("complete"), S();
131
+ c.current.finish(), v(!0), h(1), k("complete"), L();
71
132
  }
72
133
  );
73
134
  },
74
- [S]
75
- ), I = N(() => {
76
- n.current.pause(), v(n.current.status);
77
- }, []), j = N(() => {
78
- n.current.resume(), v(n.current.status);
79
- }, []), $ = N(() => {
80
- n.current.skipToEnd(), v(n.current.status), l(1);
81
- }, []), i = N(() => {
82
- n.current.stop(), s.current.finish(), k(!0), v("complete"), m.current !== null && (cancelAnimationFrame(m.current), m.current = null), p((h) => h + 1);
83
- }, []), f = N(() => {
84
- n.current.stop(), s.current.reset(), k(!1), l(0), v("idle"), m.current !== null && (cancelAnimationFrame(m.current), m.current = null), p((h) => h + 1);
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
- y(() => {
147
+ x(() => {
87
148
  n.current.setRate(r);
88
- }, [r]), y(() => () => {
89
- n.current.stop(), m.current !== null && cancelAnimationFrame(m.current);
149
+ }, [r]), x(() => () => {
150
+ n.current.stop(), d.current !== null && cancelAnimationFrame(d.current);
90
151
  }, []);
91
- const w = s.current.getState(), z = s.current.getStats(), C = s.current.getContent(), _ = P(() => w.blocks.map(
92
- (h) => o(
93
- X,
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: h,
156
+ block: y,
96
157
  components: t
97
158
  },
98
- h.key
159
+ y.key
99
160
  )
100
- ), [w.blocks, t, x]);
161
+ ), [i.blocks, t, p]);
101
162
  return {
102
- element: P(() => w.blocks.length === 0 ? null : o(E, { children: _ }), [_, w.blocks.length]),
103
- append: R,
104
- start: M,
105
- pause: I,
106
- resume: j,
107
- skipToEnd: $,
108
- reset: f,
109
- finish: i,
110
- blocks: w.blocks,
111
- stats: z,
112
- isComplete: b,
113
- content: C,
114
- progress: u,
115
- outputStatus: L
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 se = 16, ce = "data:image/svg+xml,", ae = () => /* @__PURE__ */ B("svg", { width: "48", height: "36", viewBox: "0 0 48 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
119
- /* @__PURE__ */ o("rect", { x: "0", y: "0", width: "48", height: "36", rx: "3", className: "md-image-skeleton-icon" }),
120
- /* @__PURE__ */ o("circle", { cx: "12", cy: "10", r: "5", className: "md-image-skeleton-icon-detail" }),
121
- /* @__PURE__ */ o("path", { d: "M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z", className: "md-image-skeleton-icon-detail" })
122
- ] }), Y = F(({
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: c,
126
- "data-width": a,
186
+ className: a,
187
+ "data-width": o,
127
188
  "data-height": r,
128
- ...g
189
+ ...u
129
190
  }) => {
130
- const n = (e == null ? void 0 : e.startsWith(ce)) ? void 0 : e, x = a ? Number(a) : 200, p = r ? Number(r) : 120, [b, k] = T(!0), u = d(null), l = d(null);
131
- ee(() => {
132
- u.current && n && u.current.complete && u.current.naturalWidth > 0 && k(!1);
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 L = N(() => {
135
- l.current && clearTimeout(l.current), l.current = setTimeout(() => {
136
- k(!1);
137
- }, se);
195
+ const g = S(() => {
196
+ h.current && clearTimeout(h.current), h.current = setTimeout(() => {
197
+ v(!1);
198
+ }, le);
138
199
  }, []);
139
- return /* @__PURE__ */ B(
200
+ return /* @__PURE__ */ A(
140
201
  "span",
141
202
  {
142
- className: `md-image-container ${c || ""}`,
143
- style: { width: x, height: p },
203
+ className: `md-image-container ${a || ""}`,
204
+ style: { width: p, height: m },
144
205
  children: [
145
- n && /* @__PURE__ */ o(
206
+ n && /* @__PURE__ */ s(
146
207
  "img",
147
208
  {
148
- ref: u,
209
+ ref: C,
149
210
  src: n,
150
211
  alt: t,
151
- onLoad: L,
212
+ onLoad: g,
152
213
  className: "md-image",
153
- ...g
214
+ ...u
154
215
  }
155
216
  ),
156
- b && /* @__PURE__ */ o("span", { className: "md-image-skeleton", children: /* @__PURE__ */ o(ae, {}) })
217
+ w && /* @__PURE__ */ s("span", { className: "md-image-skeleton", children: /* @__PURE__ */ s(de, {}) })
157
218
  ]
158
219
  }
159
220
  );
160
221
  });
161
- Y.displayName = "StreamingImage";
162
- let K = !1, O = null;
163
- async function Z() {
164
- if (!K)
165
- return O || (O = (async () => {
166
- await import("katex/dist/katex.min.css"), K = !0;
167
- })(), O);
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 ie = F(({ children: e }) => (y(() => {
170
- K || Z();
171
- }, []), /* @__PURE__ */ o(E, { children: e })));
172
- ie.displayName = "MathProvider";
173
- function oe() {
174
- return Z();
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 G = F(
237
+ const ne = z(
177
238
  ({ block: e, components: t }) => {
178
239
  if (!e.hast) return null;
179
240
  try {
180
- return W(e.hast, {
181
- jsx: o,
182
- jsxs: B,
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__ */ o("div", { className: "parse-error", children: e.source });
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
- G.displayName = "StableBlock";
193
- const ue = ({
253
+ ne.displayName = "StableBlock";
254
+ const he = ({
194
255
  content: e,
195
256
  source: t,
196
- outputRate: c = "medium",
197
- isComplete: a = !1,
257
+ outputRate: a = "medium",
258
+ isComplete: o = !1,
198
259
  onComplete: r,
199
- onBlockStable: g,
200
- onProgress: s,
260
+ onBlockStable: u,
261
+ onProgress: c,
201
262
  components: n,
202
- className: x,
203
- minUpdateInterval: p = 16,
204
- autoStart: b = !0,
205
- ...k
263
+ className: p,
264
+ minUpdateInterval: m = 16,
265
+ autoStart: w = !0,
266
+ copyButton: v = !0,
267
+ onCodeCopy: C,
268
+ ...h
206
269
  }) => {
207
- y(() => {
208
- k.math && oe();
209
- }, [k.math]);
210
- const u = d(V(k)), l = d(new J(c)), L = d(""), v = d(void 0), A = d([]), [, m] = Q.useReducer((i) => i + 1, 0), S = d(0), R = d(null), M = () => {
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 - S.current >= p ? (S.current = i, m()) : R.current === null && (R.current = window.requestAnimationFrame(() => {
213
- R.current = null, S.current = performance.now(), m();
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
- y(() => {
217
- t !== void 0 && t !== v.current && (v.current = t, b && t && (u.current.reset(), L.current = "", l.current.start(
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 && (u.current.append(i), L.current += i), s == null || s(l.current.progress), M();
283
+ i && (g.current.append(i), N.current += i), c == null || c(k.current.progress), P();
221
284
  },
222
285
  () => {
223
- u.current.finish(), r == null || r(), M();
286
+ g.current.finish(), r == null || r(), P();
224
287
  }
225
288
  )));
226
- }, [t, b, r, s]), y(() => {
289
+ }, [t, w, r, c]), x(() => {
227
290
  if (t !== void 0)
228
291
  return;
229
- const i = L.current, f = e || "";
230
- if (f !== i) {
231
- if (f.startsWith(i)) {
232
- const w = f.slice(i.length);
233
- w && u.current.append(w);
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
- u.current.reset(), f && u.current.append(f);
236
- L.current = f, M();
298
+ g.current.reset(), l && g.current.append(l);
299
+ N.current = l, P();
237
300
  }
238
- }, [e, t]), y(() => {
239
- t === void 0 && a && (u.current.finish(), R.current !== null && (cancelAnimationFrame(R.current), R.current = null), m(), r == null || r());
240
- }, [a, r, t]), y(() => {
241
- l.current.setRate(c);
242
- }, [c]), y(() => {
243
- if (g) {
244
- const i = u.current.getState().blocks, f = A.current;
245
- i.forEach((w, z) => {
246
- const C = f[z];
247
- w.stable && (!C || !C.stable) && g(w);
248
- }), A.current = i;
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
- }), y(() => () => {
251
- l.current.stop(), R.current !== null && cancelAnimationFrame(R.current);
313
+ }), x(() => () => {
314
+ k.current.stop(), R.current !== null && cancelAnimationFrame(R.current);
252
315
  }, []);
253
- const I = u.current.getState(), j = t !== void 0 ? l.current.status === "complete" : a, $ = P(() => {
254
- const i = {
255
- img: Y,
256
- ...n
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 I.blocks.map((f) => /* @__PURE__ */ o(
259
- G,
260
- {
261
- block: f,
262
- components: i
263
- },
264
- f.key
265
- ));
266
- }, [I.blocks, n]);
267
- return /* @__PURE__ */ o("div", { className: x, "data-streaming": !j, children: $ });
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
- ue.displayName = "StreamingMarkdown";
270
- const le = F((e) => {
271
- const { text: t, animationConfig: c } = e, { fadeDuration: a = 200, easing: r = "ease-in-out" } = c || {}, [g, s] = T([]), n = d("");
272
- y(() => {
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
- s([t]), n.current = t;
352
+ c([t]), n.current = t;
276
353
  return;
277
354
  }
278
- const p = t.slice(n.current.length);
279
- p && (s((b) => [...b, p]), n.current = t);
355
+ const m = t.slice(n.current.length);
356
+ m && (c((w) => [...w, m]), n.current = t);
280
357
  }, [t]);
281
- const x = `md-fade-in ${a}ms ${r} forwards`;
282
- return /* @__PURE__ */ o(E, { children: g.map((p, b) => /* @__PURE__ */ o(
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: x },
287
- children: p
363
+ style: { animation: p },
364
+ children: m
288
365
  },
289
- `animation-text-${b}`
366
+ `animation-text-${w}`
290
367
  )) });
291
368
  });
292
- le.displayName = "AnimationText";
293
- let U = null;
369
+ ge.displayName = "AnimationText";
370
+ let $ = null;
294
371
  try {
295
- U = require("dompurify");
372
+ $ = require("dompurify");
296
373
  } catch {
297
374
  }
298
- function ke() {
299
- return U !== null;
375
+ function Re() {
376
+ return $ !== null;
300
377
  }
301
- function we(e, t) {
302
- if (!U)
378
+ function Se(e, t) {
379
+ if (!$)
303
380
  return e;
304
- const c = {
381
+ const a = {
305
382
  ADD_ATTR: ["target", "rel", "data-block-key", "data-pending", "data-predicted"],
306
383
  ...t
307
384
  };
308
- return U.default.sanitize(e, c);
385
+ return $.default.sanitize(e, a);
309
386
  }
310
- function q(e) {
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" ? q(r) : r)
392
+ children: e.children.map((r) => r.type === "element" ? X(r) : r)
316
393
  };
317
- const t = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur"], c = ["javascript:", "vbscript:", "data:text/html"], a = {};
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, g] of Object.entries(e.properties)) {
320
- const s = r.toLowerCase();
321
- if (!(t.includes(s) || s.startsWith("on"))) {
322
- if ((s === "href" || s === "src") && typeof g == "string") {
323
- const n = g.toLowerCase().trim();
324
- if (c.some((x) => n.startsWith(x)))
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
- a[r] = g;
404
+ o[r] = u;
328
405
  }
329
406
  }
330
407
  return {
331
408
  ...e,
332
- properties: a,
409
+ properties: o,
333
410
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
- children: e.children.map((r) => r.type === "element" ? q(r) : r)
411
+ children: e.children.map((r) => r.type === "element" ? X(r) : r)
335
412
  };
336
413
  }
337
414
  export {
338
- le as AnimationText,
339
- ne as Markdown,
340
- Y as StreamingImage,
341
- ue as StreamingMarkdown,
342
- ke as isDOMPurifyAvailable,
343
- q as sanitizeHast,
344
- we as sanitizeHtml,
345
- re as useMarkdown,
346
- ge as useStreamingMarkdown
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;AAkCtD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAkMxD,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":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACrH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM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 @@ 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
@@ -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;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC"}
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.0",
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
+ }