@superlc/md-react 0.2.0 → 0.2.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":"MermaidBlock.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/MermaidBlock.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAmD,MAAM,OAAO,CAAC;AASxE,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,SAAS,CAAC;AAmD3D,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAuPpD,CAAC"}
1
+ {"version":3,"file":"MermaidBlock.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/MermaidBlock.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAmD,MAAM,OAAO,CAAC;AASxE,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,SAAS,CAAC;AAsD3D,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAiUpD,CAAC"}
@@ -4,5 +4,5 @@
4
4
  export { MermaidBlock } from './MermaidBlock';
5
5
  export { MermaidFullscreenViewer } from './MermaidFullscreenViewer';
6
6
  export { useZoom } from './useZoom';
7
- export type { MermaidBlockProps, MermaidFullscreenViewerProps, ViewMode, ZoomConfig, ZoomState, } from './types';
7
+ export type { MermaidBlockProps, MermaidFullscreenViewerProps, ViewMode, ZoomConfig, ZoomState, StreamStatus, } from './types';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,iBAAiB,EACjB,4BAA4B,EAC5B,QAAQ,EACR,UAAU,EACV,SAAS,GACV,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,iBAAiB,EACjB,4BAA4B,EAC5B,QAAQ,EACR,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,SAAS,CAAC"}
@@ -15,6 +15,8 @@ export interface ZoomState {
15
15
  translateX: number;
16
16
  translateY: number;
17
17
  }
18
+ /** 流式状态 */
19
+ export type StreamStatus = 'loading' | 'done';
18
20
  /** MermaidBlock Props */
19
21
  export interface MermaidBlockProps {
20
22
  /** Mermaid 源代码 */
@@ -27,6 +29,13 @@ export interface MermaidBlockProps {
27
29
  onCopy?: (code: string) => void;
28
30
  /** 额外的 className */
29
31
  className?: string;
32
+ /**
33
+ * 流式状态
34
+ * - 'loading': 正在流式输入,代码块可能不完整
35
+ * - 'done': 流式输入完成,代码块已完整
36
+ * 用于优化流式渲染体验:loading 状态下会延迟渲染并保留上次有效结果
37
+ */
38
+ streamStatus?: StreamStatus;
30
39
  }
31
40
  /** MermaidFullscreenViewer Props */
32
41
  export interface MermaidFullscreenViewerProps {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,WAAW;AACX,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1C,WAAW;AACX,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,WAAW;AACX,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,yBAAyB;AACzB,MAAM,WAAW,iBAAiB;IAChC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS;IACT,KAAK,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC9B,cAAc;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,4BAA4B;IAC3C,aAAa;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW;IACX,IAAI,EAAE,OAAO,CAAC;IACd,WAAW;IACX,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,WAAW;AACX,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1C,WAAW;AACX,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,WAAW;AACX,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,WAAW;AACX,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9C,yBAAyB;AACzB,MAAM,WAAW,iBAAiB;IAChC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS;IACT,KAAK,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC9B,cAAc;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,oCAAoC;AACpC,MAAM,WAAW,4BAA4B;IAC3C,aAAa;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW;IACX,IAAI,EAAE,OAAO,CAAC;IACd,WAAW;IACX,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ce=Object.create;var q=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var me=(t,r,c,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of oe(r))!ue.call(t,a)&&a!==c&&q(t,a,{get:()=>r[a],enumerable:!(l=le(r,a))||l.enumerable});return t};var de=(t,r,c)=>(c=t!=null?ce(ie(t)):{},me(r||!t||!t.__esModule?q(c,"default",{value:t,enumerable:!0}):c,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),L=require("@superlc/md-core"),A=require("hast-util-to-jsx-runtime");async function fe(t){try{return await navigator.clipboard.writeText(t),!0}catch{return he(t)}}function he(t){const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-9999px",document.body.appendChild(r),r.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(r)}}const xe=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.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"})}),pe=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),O=({children:t,showCopyButton:r=!0,onCopy:c,className:l})=>{const[a,u]=n.useState(!1),i=n.useCallback(async()=>{const s=P(t);await fe(s)&&(u(!0),c==null||c(s),setTimeout(()=>u(!1),2e3))},[t,c]);return e.jsxs("div",{className:`md-code-block-wrapper${l?` ${l}`:""}`,children:[e.jsx("pre",{children:t}),r&&e.jsx("button",{type:"button",className:`md-copy-button${a?" md-copy-button--copied":""}`,onClick:i,title:a?"已复制":"复制代码","aria-label":a?"已复制":"复制代码",children:a?e.jsx(pe,{}):e.jsx(xe,{})})]})};function P(t){return typeof t=="string"?t:typeof t=="number"?String(t):Array.isArray(t)?t.map(P).join(""):n.isValidElement(t)?P(t.props.children):""}O.displayName="CodeBlock";const be={min:.25,max:4,step:.25,default:1};function U(t={}){const{config:r,enableDrag:c=!1,enableWheelZoom:l=!1}=t,a={...be,...r},u=n.useRef(null),i=n.useRef(!1),s=n.useRef({x:0,y:0}),p=n.useRef({x:0,y:0}),[m,h]=n.useState({scale:a.default,translateX:0,translateY:0}),d=n.useCallback(o=>Math.max(a.min,Math.min(a.max,o)),[a.min,a.max]),b=n.useCallback(()=>{h(o=>({...o,scale:d(o.scale+a.step)}))},[d,a.step]),x=n.useCallback(()=>{h(o=>({...o,scale:d(o.scale-a.step)}))},[d,a.step]),v=n.useCallback(()=>{h({scale:a.default,translateX:0,translateY:0})},[a.default]),k=n.useCallback(o=>{h(j=>({...j,scale:d(o)}))},[d]),N=n.useCallback((o,j)=>{const M=o.width/j.width,F=o.height/j.height,I=Math.min(M,F)*.95;h({scale:d(I),translateX:0,translateY:0})},[d]),g=n.useCallback(o=>{c&&(o.preventDefault(),i.current=!0,s.current={x:o.clientX,y:o.clientY},p.current={x:m.translateX,y:m.translateY})},[c,m.translateX,m.translateY]);n.useEffect(()=>{if(!c)return;const o=M=>{if(!i.current)return;const F=M.clientX-s.current.x,I=M.clientY-s.current.y;h(f=>({...f,translateX:p.current.x+F,translateY:p.current.y+I}))},j=()=>{i.current=!1};return document.addEventListener("mousemove",o),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",j)}},[c]);const S=n.useCallback(o=>{if(!l)return;o.preventDefault();const j=o.deltaY>0?-a.step:a.step;h(M=>({...M,scale:d(M.scale+j)}))},[l,a.step,d]),E=n.useCallback(()=>{v()},[v]),z={transform:`translate(${m.translateX}px, ${m.translateY}px) scale(${m.scale})`,transformOrigin:"center center",transition:i.current?"none":"transform 0.2s ease-out",cursor:c?i.current?"grabbing":"grab":"default"};return{state:m,zoomIn:b,zoomOut:x,reset:v,fitToContainer:N,setScale:k,canZoomIn:m.scale<a.max,canZoomOut:m.scale>a.min,containerRef:u,contentStyle:z,handlers:{onMouseDown:g,onWheel:S,onDoubleClick:E}}}const ve=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"})}),ge=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})}),J=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zm.5-7H9v2H7v1h2v2h1v-2h2V9h-2V7z"})}),K=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7V9z"})}),G=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"})}),je=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"})}),ke=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"})}),Q=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"})}),ye=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})}),Ce=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.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"})}),we=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),X=({svg:t,open:r,onClose:c,onDownload:l})=>{const a=n.useRef(null),u=n.useRef(null),i=n.useRef(null),[s,p]=n.useState(!1),{state:m,zoomIn:h,zoomOut:d,reset:b,fitToContainer:x,canZoomIn:v,canZoomOut:k,contentStyle:N,handlers:g}=U({enableDrag:!0,enableWheelZoom:!0}),S=n.useCallback(async()=>{if(a.current)try{await a.current.requestFullscreen(),p(!0)}catch{p(!0)}},[]),E=n.useCallback(()=>{document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),p(!1),c()},[c]);n.useEffect(()=>{r?S():s&&E()},[r,S,E,s]),n.useEffect(()=>{const o=()=>{!document.fullscreenElement&&s&&(p(!1),c())};return document.addEventListener("fullscreenchange",o),()=>document.removeEventListener("fullscreenchange",o)},[s,c]),n.useEffect(()=>{if(!s)return;const o=j=>{switch(j.key){case"+":case"=":h();break;case"-":d();break;case"0":b();break}};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[s,h,d,b]);const z=n.useCallback(()=>{if(!u.current||!i.current)return;const o=u.current.getBoundingClientRect(),j=i.current.querySelector("svg");if(j){const M=j.getBoundingClientRect();x(o,M)}},[x]);return e.jsx("div",{ref:a,className:`md-mermaid-fullscreen-wrapper${s?" md-mermaid-fullscreen-wrapper--active":""}`,role:"dialog","aria-modal":"true","aria-label":"Mermaid 图表全屏预览","aria-hidden":!s,children:s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"md-mermaid-fullscreen-toolbar",children:[e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:d,disabled:!k,title:"缩小 (-)","aria-label":"缩小",children:e.jsx(K,{})}),e.jsxs("span",{className:"md-mermaid-zoom-label",children:[Math.round(m.scale*100),"%"]}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:h,disabled:!v,title:"放大 (+)","aria-label":"放大",children:e.jsx(J,{})}),e.jsx("span",{className:"md-mermaid-toolbar-divider"}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:b,title:"重置 (0)","aria-label":"重置",children:e.jsx(G,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:z,title:"适应窗口","aria-label":"适应窗口",children:e.jsx(ke,{})})]}),e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[l&&e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:l,title:"下载 PNG","aria-label":"下载",children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:E,title:"退出全屏 (Esc)","aria-label":"退出全屏",children:e.jsx(ye,{})})]})]}),e.jsx("div",{ref:u,className:"md-mermaid-fullscreen-content",onWheel:g.onWheel,children:e.jsx("div",{ref:i,className:"md-mermaid-fullscreen-svg",style:N,onMouseDown:g.onMouseDown,onDoubleClick:g.onDoubleClick,dangerouslySetInnerHTML:{__html:t}})})]})})};X.displayName="MermaidFullscreenViewer";let B=null;function Me(t="auto"){return B?B.setTheme(t??"auto"):B=new L.MermaidRenderer({theme:t}),B}async function Se(t){try{return await navigator.clipboard.writeText(t),!0}catch{const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-9999px",document.body.appendChild(r),r.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(r)}}}const W=({code:t,theme:r="auto",showToolbar:c=!0,onCopy:l,className:a})=>{const[u,i]=n.useState("preview"),[s,p]=n.useState(null),[m,h]=n.useState(!0),[d,b]=n.useState(!1),[x,v]=n.useState(!1),k=n.useRef(null),[N,g]=n.useState(()=>L.detectColorScheme()),{state:S,zoomIn:E,zoomOut:z,reset:o,canZoomIn:j,canZoomOut:M,contentStyle:F}=U();n.useEffect(()=>{if(r==="auto")return L.observeColorScheme(w=>{g(w)})},[r]),n.useEffect(()=>{let w=!1;return(async()=>{h(!0);const V=await Me(r).render(t);w||(p(V),h(!1),V.success||i("code"))})(),()=>{w=!0}},[t,r,N]);const I=n.useCallback(async()=>{await Se(t)&&(v(!0),l==null||l(t),setTimeout(()=>v(!1),2e3))},[t,l]),f=n.useCallback(async()=>{var w;if(s!=null&&s.svg)try{const T=((w=window.matchMedia)==null?void 0:w.call(window,"(prefers-color-scheme: dark)").matches)??!1;await L.downloadAsPng(s.svg,{backgroundColor:T?"#1a1a2e":"#ffffff",padding:20,scale:2})}catch(T){console.error("Download failed:",T)}},[s]),y=n.useCallback(()=>{b(w=>!w)},[]),C=(s==null?void 0:s.success)&&s.svg;return e.jsxs("div",{className:`md-mermaid-block${a?` ${a}`:""}`,children:[c&&e.jsxs("div",{className:"md-mermaid-toolbar",children:[e.jsxs("div",{className:"md-mermaid-toolbar-group md-mermaid-mode-switch",children:[e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${u==="preview"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>i("preview"),disabled:!C,title:"图片模式","aria-label":"图片模式",children:e.jsx(ve,{})}),e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${u==="code"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>i("code"),title:"代码模式","aria-label":"代码模式",children:e.jsx(ge,{})})]}),u==="preview"&&C&&e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:z,disabled:!M,title:"缩小","aria-label":"缩小",children:e.jsx(K,{})}),e.jsxs("span",{className:"md-mermaid-zoom-label",children:[Math.round(S.scale*100),"%"]}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:E,disabled:!j,title:"放大","aria-label":"放大",children:e.jsx(J,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:o,title:"重置","aria-label":"重置缩放",children:e.jsx(G,{})})]}),e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[u==="preview"&&C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:y,title:"全屏","aria-label":"全屏查看",children:e.jsx(je,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:f,title:"下载 PNG","aria-label":"下载",children:e.jsx(Q,{})})]}),u==="code"&&e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${x?" md-mermaid-toolbar-btn--success":""}`,onClick:I,title:x?"已复制":"复制代码","aria-label":x?"已复制":"复制代码",children:x?e.jsx(we,{}):e.jsx(Ce,{})})]})]}),e.jsx("div",{className:"md-mermaid-content",ref:k,children:m?e.jsx("div",{className:"md-mermaid-skeleton",children:e.jsx("div",{className:"md-mermaid-skeleton-box"})}):u==="preview"&&C&&(s!=null&&s.svg)?e.jsx("div",{className:"md-mermaid-preview",style:{overflow:"hidden"},children:e.jsx("div",{className:"md-mermaid-svg-container",style:F,dangerouslySetInnerHTML:{__html:s.svg}})}):e.jsxs("div",{className:"md-mermaid-code",children:[e.jsx("pre",{children:e.jsx("code",{className:"language-mermaid",children:t})}),s&&!s.success&&e.jsxs("div",{className:"md-mermaid-error",children:[e.jsx("span",{children:"渲染失败: "}),e.jsx("span",{children:s.error})]})]})}),C&&(s==null?void 0:s.svg)&&e.jsx(X,{svg:s.svg,open:d,onClose:()=>b(!1),onDownload:f})]})};W.displayName="MermaidBlock";function Ne(t){const r=t.children;if(!n.isValidElement(r))return!1;const c=r.props,l=c==null?void 0:c.className;return typeof l=="string"?l.includes("language-mermaid"):!1}function Re(t){if(!n.isValidElement(t))return"";const r=t.props,c=r==null?void 0:r.children;return typeof c=="string"?c:Array.isArray(c)?c.map(l=>typeof l=="string"?l:"").join(""):""}function Ee(t){return t?t===!0?{enabled:!0}:t.enabled!==!1?t:null:null}const ee=({children:t,components:r,className:c,copyButton:l=!0,onCodeCopy:a,mermaid:u,...i})=>{const s=Ee(u),p=n.useMemo(()=>{if(!t)return null;const m=L.parseToHast(t,i),d={pre:b=>{if(s&&Ne(b)){const x=Re(b.children);return e.jsx(W,{code:x,theme:s.theme,onCopy:a})}return l?e.jsx(O,{showCopyButton:l,onCopy:a,...b}):e.jsx("pre",{...b})},...r};return A.toJsxRuntime(m,{Fragment:e.Fragment,jsx:e.jsx,jsxs:e.jsxs,components:d})},[t,r,l,a,s,i]);return e.jsx("div",{className:c,children:p})};ee.displayName="Markdown";function ze(t,r={}){const{components:c={},...l}=r;return n.useMemo(()=>{if(!t)return null;const a=L.parseToHast(t,l);return A.toJsxRuntime(a,{Fragment:e.Fragment,jsx:e.jsx,jsxs:e.jsxs,components:c})},[t,c,l])}const te=n.memo(({block:t,components:r})=>{if(!t.hast)return null;try{return A.toJsxRuntime(t.hast,{jsx:e.jsx,jsxs:e.jsxs,Fragment:e.Fragment,components:r})}catch{return null}},(t,r)=>t.block.key===r.block.key&&t.block.stable&&r.block.stable);te.displayName="StableBlock";function Le(t={}){const{components:r,minUpdateInterval:c=16,immediate:l=!1,outputRate:a="medium",...u}=t,i=n.useRef(L.createStreamingParser(u)),s=n.useRef(new L.OutputRateController(a)),[p,m]=n.useState(0),[h,d]=n.useState(!1),[b,x]=n.useState(0),[v,k]=n.useState("idle"),N=n.useRef(0),g=n.useRef(null),S=n.useCallback(()=>{const R=performance.now(),V=R-N.current;l||V>=c?(N.current=R,m($=>$+1)):g.current===null&&(g.current=window.requestAnimationFrame(()=>{g.current=null,N.current=performance.now(),m($=>$+1)}))},[c,l]),E=n.useCallback(R=>{i.current.append(R),S()},[S]),z=n.useCallback(R=>{i.current.reset(),d(!1),x(0),k("running"),s.current.start(R,V=>{V&&i.current.append(V),x(s.current.progress),S()},()=>{i.current.finish(),d(!0),x(1),k("complete"),S()})},[S]),o=n.useCallback(()=>{s.current.pause(),k(s.current.status)},[]),j=n.useCallback(()=>{s.current.resume(),k(s.current.status)},[]),M=n.useCallback(()=>{s.current.skipToEnd(),k(s.current.status),x(1)},[]),F=n.useCallback(()=>{s.current.stop(),i.current.finish(),d(!0),k("complete"),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),m(R=>R+1)},[]),I=n.useCallback(()=>{s.current.stop(),i.current.reset(),d(!1),x(0),k("idle"),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),m(R=>R+1)},[]);n.useEffect(()=>{s.current.setRate(a)},[a]),n.useEffect(()=>()=>{s.current.stop(),g.current!==null&&cancelAnimationFrame(g.current)},[]);const f=i.current.getState(),y=i.current.getStats(),C=i.current.getContent(),w=n.useMemo(()=>f.blocks.map(R=>e.jsx(te,{block:R,components:r},R.key)),[f.blocks,r,p]);return{element:n.useMemo(()=>f.blocks.length===0?null:e.jsx(e.Fragment,{children:w}),[w,f.blocks.length]),append:E,start:z,pause:o,resume:j,skipToEnd:M,reset:I,finish:F,blocks:f.blocks,stats:y,isComplete:h,content:C,progress:b,outputStatus:v}}const Fe=16,Ie="data:image/svg+xml,",Te=()=>e.jsxs("svg",{width:"48",height:"36",viewBox:"0 0 48 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"0",y:"0",width:"48",height:"36",rx:"3",className:"md-image-skeleton-icon"}),e.jsx("circle",{cx:"12",cy:"10",r:"5",className:"md-image-skeleton-icon-detail"}),e.jsx("path",{d:"M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z",className:"md-image-skeleton-icon-detail"})]}),_=n.memo(({src:t,alt:r,className:c,"data-width":l,"data-height":a,...u})=>{const s=(t==null?void 0:t.startsWith(Ie))?void 0:t,p=l?Number(l):200,m=a?Number(a):120,[h,d]=n.useState(!0),b=n.useRef(null),x=n.useRef(null);n.useLayoutEffect(()=>{b.current&&s&&b.current.complete&&b.current.naturalWidth>0&&d(!1)},[s]);const v=n.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{d(!1)},Fe)},[]);return e.jsxs("span",{className:`md-image-container ${c||""}`,style:{width:p,height:m},children:[s&&e.jsx("img",{ref:b,src:s,alt:r,onLoad:v,className:"md-image",...u}),h&&e.jsx("span",{className:"md-image-skeleton",children:e.jsx(Te,{})})]})});_.displayName="StreamingImage";let Z=!1,H=null;async function ne(){if(!Z)return H||(H=(async()=>{await import("katex/dist/katex.min.css"),Z=!0})(),H)}const Ve=n.memo(({children:t})=>(n.useEffect(()=>{Z||ne()},[]),e.jsx(e.Fragment,{children:t})));Ve.displayName="MathProvider";function Be(){return ne()}const re=n.memo(({block:t,components:r})=>{if(!t.hast)return null;try{return A.toJsxRuntime(t.hast,{jsx:e.jsx,jsxs:e.jsxs,Fragment:e.Fragment,components:r})}catch{return e.jsx("div",{className:"parse-error",children:t.source})}},(t,r)=>t.block.key===r.block.key&&t.block.stable&&r.block.stable);re.displayName="StableBlock";const se=({content:t,source:r,outputRate:c="medium",isComplete:l=!1,onComplete:a,onBlockStable:u,onProgress:i,components:s,className:p,minUpdateInterval:m=16,autoStart:h=!0,copyButton:d=!0,onCodeCopy:b,...x})=>{n.useEffect(()=>{x.math&&Be()},[x.math]);const v=n.useRef(L.createStreamingParser(x)),k=n.useRef(new L.OutputRateController(c)),N=n.useRef(""),g=n.useRef(void 0),S=n.useRef([]),[,E]=n.useReducer(f=>f+1,0),z=n.useRef(0),o=n.useRef(null),j=()=>{const f=performance.now();f-z.current>=m?(z.current=f,E()):o.current===null&&(o.current=window.requestAnimationFrame(()=>{o.current=null,z.current=performance.now(),E()}))};n.useEffect(()=>{r!==void 0&&r!==g.current&&(g.current=r,h&&r&&(v.current.reset(),N.current="",k.current.start(r,f=>{f&&(v.current.append(f),N.current+=f),i==null||i(k.current.progress),j()},()=>{v.current.finish(),a==null||a(),j()})))},[r,h,a,i]),n.useEffect(()=>{if(r!==void 0)return;const f=N.current,y=t||"";if(y!==f){if(y.startsWith(f)){const C=y.slice(f.length);C&&v.current.append(C)}else v.current.reset(),y&&v.current.append(y);N.current=y,j()}},[t,r]),n.useEffect(()=>{r===void 0&&l&&(v.current.finish(),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),E(),a==null||a())},[l,a,r]),n.useEffect(()=>{k.current.setRate(c)},[c]),n.useEffect(()=>{if(u){const f=v.current.getState().blocks,y=S.current;f.forEach((C,w)=>{const T=y[w];C.stable&&(!T||!T.stable)&&u(C)}),S.current=f}}),n.useEffect(()=>()=>{k.current.stop(),o.current!==null&&cancelAnimationFrame(o.current)},[]);const M=v.current.getState(),F=r!==void 0?k.current.status==="complete":l,I=n.useMemo(()=>{const f=y=>{if(d)return C=>e.jsx(O,{showCopyButton:y.stable&&d,onCopy:b,...C})};return M.blocks.map(y=>{const C=f(y),w={img:_,...C?{pre:C}:{},...s};return e.jsx(re,{block:y,components:w},y.key)})},[M.blocks,s,d,b]);return e.jsx("div",{className:p,"data-streaming":!F,children:I})};se.displayName="StreamingMarkdown";const ae=n.memo(t=>{const{text:r,animationConfig:c}=t,{fadeDuration:l=200,easing:a="ease-in-out"}=c||{},[u,i]=n.useState([]),s=n.useRef("");n.useEffect(()=>{if(r===s.current)return;if(!(s.current&&r.indexOf(s.current)===0)){i([r]),s.current=r;return}const m=r.slice(s.current.length);m&&(i(h=>[...h,m]),s.current=r)},[r]);const p=`md-fade-in ${l}ms ${a} forwards`;return e.jsx(e.Fragment,{children:u.map((m,h)=>e.jsx("span",{className:"md-animation-text",style:{animation:p},children:m},`animation-text-${h}`))})});ae.displayName="AnimationText";let D=null;try{D=require("dompurify")}catch{}function He(){return D!==null}function De(t,r){if(!D)return t;const c={ADD_ATTR:["target","rel","data-block-key","data-pending","data-predicted"],...r};return D.default.sanitize(t,c)}function Y(t){if(t.type==="root")return{...t,children:t.children.map(a=>a.type==="element"?Y(a):a)};const r=["onclick","onerror","onload","onmouseover","onfocus","onblur"],c=["javascript:","vbscript:","data:text/html"],l={};if(t.properties)for(const[a,u]of Object.entries(t.properties)){const i=a.toLowerCase();if(!(r.includes(i)||i.startsWith("on"))){if((i==="href"||i==="src")&&typeof u=="string"){const s=u.toLowerCase().trim();if(c.some(p=>s.startsWith(p)))continue}l[a]=u}}return{...t,properties:l,children:t.children.map(a=>a.type==="element"?Y(a):a)}}exports.AnimationText=ae;exports.CodeBlock=O;exports.Markdown=ee;exports.MermaidBlock=W;exports.MermaidFullscreenViewer=X;exports.StreamingImage=_;exports.StreamingMarkdown=se;exports.isDOMPurifyAvailable=He;exports.sanitizeHast=Y;exports.sanitizeHtml=De;exports.useMarkdown=ze;exports.useStreamingMarkdown=Le;exports.useZoom=U;
1
+ "use strict";var ue=Object.create;var Q=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var xe=(t,r,c,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of me(r))!he.call(t,s)&&s!==c&&Q(t,s,{get:()=>r[s],enumerable:!(o=de(r,s))||o.enumerable});return t};var pe=(t,r,c)=>(c=t!=null?ue(fe(t)):{},xe(r||!t||!t.__esModule?Q(c,"default",{value:t,enumerable:!0}):c,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),L=require("@superlc/md-core"),Z=require("hast-util-to-jsx-runtime");async function be(t){try{return await navigator.clipboard.writeText(t),!0}catch{return ge(t)}}function ge(t){const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-9999px",document.body.appendChild(r),r.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(r)}}const ve=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.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"})}),je=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),Y=({children:t,showCopyButton:r=!0,onCopy:c,className:o})=>{const[s,f]=n.useState(!1),l=n.useCallback(async()=>{const a=_(t);await be(a)&&(f(!0),c==null||c(a),setTimeout(()=>f(!1),2e3))},[t,c]);return e.jsxs("div",{className:`md-code-block-wrapper${o?` ${o}`:""}`,children:[e.jsx("pre",{children:t}),r&&e.jsx("button",{type:"button",className:`md-copy-button${s?" md-copy-button--copied":""}`,onClick:l,title:s?"已复制":"复制代码","aria-label":s?"已复制":"复制代码",children:s?e.jsx(je,{}):e.jsx(ve,{})})]})};function _(t){return typeof t=="string"?t:typeof t=="number"?String(t):Array.isArray(t)?t.map(_).join(""):n.isValidElement(t)?_(t.props.children):""}Y.displayName="CodeBlock";const ke={min:.25,max:4,step:.25,default:1};function W(t={}){const{config:r,enableDrag:c=!1,enableWheelZoom:o=!1}=t,s={...ke,...r},f=n.useRef(null),l=n.useRef(!1),a=n.useRef({x:0,y:0}),u=n.useRef({x:0,y:0}),[m,x]=n.useState({scale:s.default,translateX:0,translateY:0}),d=n.useCallback(i=>Math.max(s.min,Math.min(s.max,i)),[s.min,s.max]),g=n.useCallback(()=>{x(i=>({...i,scale:d(i.scale+s.step)}))},[d,s.step]),b=n.useCallback(()=>{x(i=>({...i,scale:d(i.scale-s.step)}))},[d,s.step]),p=n.useCallback(()=>{x({scale:s.default,translateX:0,translateY:0})},[s.default]),k=n.useCallback(i=>{x(j=>({...j,scale:d(i)}))},[d]),E=n.useCallback((i,j)=>{const M=i.width/j.width,B=i.height/j.height,F=Math.min(M,B)*.95;x({scale:d(F),translateX:0,translateY:0})},[d]),v=n.useCallback(i=>{c&&(i.preventDefault(),l.current=!0,a.current={x:i.clientX,y:i.clientY},u.current={x:m.translateX,y:m.translateY})},[c,m.translateX,m.translateY]);n.useEffect(()=>{if(!c)return;const i=M=>{if(!l.current)return;const B=M.clientX-a.current.x,F=M.clientY-a.current.y;x(h=>({...h,translateX:u.current.x+B,translateY:u.current.y+F}))},j=()=>{l.current=!1};return document.addEventListener("mousemove",i),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",j)}},[c]);const S=n.useCallback(i=>{if(!o)return;i.preventDefault();const j=i.deltaY>0?-s.step:s.step;x(M=>({...M,scale:d(M.scale+j)}))},[o,s.step,d]),w=n.useCallback(()=>{p()},[p]),C={transform:`translate(${m.translateX}px, ${m.translateY}px) scale(${m.scale})`,transformOrigin:"center center",transition:l.current?"none":"transform 0.2s ease-out",cursor:c?l.current?"grabbing":"grab":"default"};return{state:m,zoomIn:g,zoomOut:b,reset:p,fitToContainer:E,setScale:k,canZoomIn:m.scale<s.max,canZoomOut:m.scale>s.min,containerRef:f,contentStyle:C,handlers:{onMouseDown:v,onWheel:S,onDoubleClick:w}}}const ye=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"})}),we=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})}),ee=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zm.5-7H9v2H7v1h2v2h1v-2h2V9h-2V7z"})}),te=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7V9z"})}),ne=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"})}),Ce=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"})}),Me=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"})}),re=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"})}),Re=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})}),Se=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.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"})}),Ne=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),q=({svg:t,open:r,onClose:c,onDownload:o})=>{const s=n.useRef(null),f=n.useRef(null),l=n.useRef(null),[a,u]=n.useState(!1),{state:m,zoomIn:x,zoomOut:d,reset:g,fitToContainer:b,canZoomIn:p,canZoomOut:k,contentStyle:E,handlers:v}=W({enableDrag:!0,enableWheelZoom:!0}),S=n.useCallback(async()=>{if(s.current)try{await s.current.requestFullscreen(),u(!0)}catch{u(!0)}},[]),w=n.useCallback(()=>{document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),u(!1),c()},[c]);n.useEffect(()=>{r?S():a&&w()},[r,S,w,a]),n.useEffect(()=>{const i=()=>{!document.fullscreenElement&&a&&(u(!1),c())};return document.addEventListener("fullscreenchange",i),()=>document.removeEventListener("fullscreenchange",i)},[a,c]),n.useEffect(()=>{if(!a)return;const i=j=>{switch(j.key){case"+":case"=":x();break;case"-":d();break;case"0":g();break}};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[a,x,d,g]);const C=n.useCallback(()=>{if(!f.current||!l.current)return;const i=f.current.getBoundingClientRect(),j=l.current.querySelector("svg");if(j){const M=j.getBoundingClientRect();b(i,M)}},[b]);return e.jsx("div",{ref:s,className:`md-mermaid-fullscreen-wrapper${a?" md-mermaid-fullscreen-wrapper--active":""}`,role:"dialog","aria-modal":"true","aria-label":"Mermaid 图表全屏预览","aria-hidden":!a,children:a&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"md-mermaid-fullscreen-toolbar",children:[e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:d,disabled:!k,title:"缩小 (-)","aria-label":"缩小",children:e.jsx(te,{})}),e.jsxs("span",{className:"md-mermaid-zoom-label",children:[Math.round(m.scale*100),"%"]}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:x,disabled:!p,title:"放大 (+)","aria-label":"放大",children:e.jsx(ee,{})}),e.jsx("span",{className:"md-mermaid-toolbar-divider"}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:g,title:"重置 (0)","aria-label":"重置",children:e.jsx(ne,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:C,title:"适应窗口","aria-label":"适应窗口",children:e.jsx(Me,{})})]}),e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[o&&e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:o,title:"下载 PNG","aria-label":"下载",children:e.jsx(re,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:w,title:"退出全屏 (Esc)","aria-label":"退出全屏",children:e.jsx(Re,{})})]})]}),e.jsx("div",{ref:f,className:"md-mermaid-fullscreen-content",onWheel:v.onWheel,children:e.jsx("div",{ref:l,className:"md-mermaid-fullscreen-svg",style:E,onMouseDown:v.onMouseDown,onDoubleClick:v.onDoubleClick,dangerouslySetInnerHTML:{__html:t}})})]})})};q.displayName="MermaidFullscreenViewer";const Ee=150;let O=null;function ze(t="auto"){return O?O.setTheme(t??"auto"):O=new L.MermaidRenderer({theme:t}),O}async function Le(t){try{return await navigator.clipboard.writeText(t),!0}catch{const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-9999px",document.body.appendChild(r),r.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(r)}}}const J=({code:t,theme:r="auto",showToolbar:c=!0,onCopy:o,className:s,streamStatus:f="done"})=>{const[l,a]=n.useState("preview"),[u,m]=n.useState(null),[x,d]=n.useState(!0),[g,b]=n.useState(!1),[p,k]=n.useState(!1),E=n.useRef(null),[v,S]=n.useState(()=>L.detectColorScheme()),w=n.useRef(null),C=n.useRef(null),{state:i,zoomIn:j,zoomOut:M,reset:B,canZoomIn:F,canZoomOut:h,contentStyle:y}=W();n.useEffect(()=>{if(r==="auto")return L.observeColorScheme(z=>{S(z)})},[r]);const N=n.useRef(t),I=n.useRef(f);N.current=t,I.current=f,n.useEffect(()=>{const z=async H=>{console.log("[MermaidBlock] doRender start",{codeLength:H.length});const V=await ze(r).render(H),G=I.current;console.log("[MermaidBlock] render result",{success:V.success,hasSvg:!!V.svg,error:V.error,currentStreamStatus:G}),V.success&&V.svg?(w.current=V.svg,m(V),d(!1),a("preview"),console.log("[MermaidBlock] render success, cached SVG")):G==="loading"?w.current?(m({success:!0,svg:w.current}),d(!1),console.log("[MermaidBlock] render failed, using cache")):console.log("[MermaidBlock] render failed, no cache, keep loading"):(m(V),d(!1),a("code"),console.log("[MermaidBlock] render failed, showing error"))};console.log("[MermaidBlock] useEffect triggered",{streamStatus:f,codeLength:t.length,hasTimer:!!C.current,hasCache:!!w.current}),f==="loading"?C.current?console.log("[MermaidBlock] timer already exists, skipping"):(w.current||d(!0),console.log("[MermaidBlock] setting timer"),C.current=setTimeout(()=>{console.log("[MermaidBlock] timer fired, rendering with latest code"),C.current=null,z(N.current)},Ee)):(console.log("[MermaidBlock] immediate render (not loading)"),C.current&&(clearTimeout(C.current),C.current=null),d(!0),z(t))},[t,r,v,f]);const A=n.useCallback(async()=>{await Le(t)&&(k(!0),o==null||o(t),setTimeout(()=>k(!1),2e3))},[t,o]),R=n.useCallback(async()=>{var z;if(u!=null&&u.svg)try{const H=((z=window.matchMedia)==null?void 0:z.call(window,"(prefers-color-scheme: dark)").matches)??!1;await L.downloadAsPng(u.svg,{backgroundColor:H?"#1a1a2e":"#ffffff",padding:20,scale:2})}catch(H){console.error("Download failed:",H)}},[u]),D=n.useCallback(()=>{b(z=>!z)},[]),T=(u==null?void 0:u.success)&&u.svg;return e.jsxs("div",{className:`md-mermaid-block${s?` ${s}`:""}`,children:[c&&e.jsxs("div",{className:"md-mermaid-toolbar",children:[e.jsxs("div",{className:"md-mermaid-toolbar-group md-mermaid-mode-switch",children:[e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${l==="preview"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>a("preview"),disabled:!T,title:"图片模式","aria-label":"图片模式",children:e.jsx(ye,{})}),e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${l==="code"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>a("code"),title:"代码模式","aria-label":"代码模式",children:e.jsx(we,{})})]}),l==="preview"&&T&&e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:M,disabled:!h,title:"缩小","aria-label":"缩小",children:e.jsx(te,{})}),e.jsxs("span",{className:"md-mermaid-zoom-label",children:[Math.round(i.scale*100),"%"]}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:j,disabled:!F,title:"放大","aria-label":"放大",children:e.jsx(ee,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:B,title:"重置","aria-label":"重置缩放",children:e.jsx(ne,{})})]}),e.jsxs("div",{className:"md-mermaid-toolbar-group",children:[l==="preview"&&T&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:D,title:"全屏","aria-label":"全屏查看",children:e.jsx(Ce,{})}),e.jsx("button",{type:"button",className:"md-mermaid-toolbar-btn",onClick:R,title:"下载 PNG","aria-label":"下载",children:e.jsx(re,{})})]}),l==="code"&&e.jsx("button",{type:"button",className:`md-mermaid-toolbar-btn${p?" md-mermaid-toolbar-btn--success":""}`,onClick:A,title:p?"已复制":"复制代码","aria-label":p?"已复制":"复制代码",children:p?e.jsx(Ne,{}):e.jsx(Se,{})})]})]}),e.jsx("div",{className:"md-mermaid-content",ref:E,children:x?e.jsx("div",{className:"md-mermaid-skeleton",children:e.jsx("div",{className:"md-mermaid-skeleton-box"})}):l==="preview"&&T&&(u!=null&&u.svg)?e.jsx("div",{className:"md-mermaid-preview",style:{overflow:"hidden"},children:e.jsx("div",{className:"md-mermaid-svg-container",style:y,dangerouslySetInnerHTML:{__html:u.svg}})}):e.jsxs("div",{className:"md-mermaid-code",children:[e.jsx("pre",{children:e.jsx("code",{className:"language-mermaid",children:t})}),u&&!u.success&&f==="done"&&e.jsxs("div",{className:"md-mermaid-error",children:[e.jsx("span",{children:"渲染失败: "}),e.jsx("span",{children:u.error})]})]})}),T&&(u==null?void 0:u.svg)&&e.jsx(q,{svg:u.svg,open:g,onClose:()=>b(!1),onDownload:R})]})};J.displayName="MermaidBlock";function Be(t){const r=t.children;if(!n.isValidElement(r))return!1;const c=r.props,o=c==null?void 0:c.className;return typeof o=="string"?o.includes("language-mermaid"):!1}function Fe(t){if(!n.isValidElement(t))return"";const r=t.props,c=r==null?void 0:r.children;return typeof c=="string"?c:Array.isArray(c)?c.map(o=>typeof o=="string"?o:"").join(""):""}function Ie(t){return t?t===!0?{enabled:!0}:t.enabled!==!1?t:null:null}const se=({children:t,components:r,className:c,copyButton:o=!0,onCodeCopy:s,mermaid:f,...l})=>{const a=Ie(f),u=n.useMemo(()=>{if(!t)return null;const m=L.parseToHast(t,l),d={pre:g=>{if(a&&Be(g)){const b=Fe(g.children);return e.jsx(J,{code:b,theme:a.theme,onCopy:s})}return o?e.jsx(Y,{showCopyButton:o,onCopy:s,...g}):e.jsx("pre",{...g})},...r};return Z.toJsxRuntime(m,{Fragment:e.Fragment,jsx:e.jsx,jsxs:e.jsxs,components:d})},[t,r,o,s,a,l]);return e.jsx("div",{className:c,children:u})};se.displayName="Markdown";function Te(t,r={}){const{components:c={},...o}=r;return n.useMemo(()=>{if(!t)return null;const s=L.parseToHast(t,o);return Z.toJsxRuntime(s,{Fragment:e.Fragment,jsx:e.jsx,jsxs:e.jsxs,components:c})},[t,c,o])}const ae=n.memo(({block:t,components:r})=>{if(!t.hast)return null;try{return Z.toJsxRuntime(t.hast,{jsx:e.jsx,jsxs:e.jsxs,Fragment:e.Fragment,components:r})}catch{return null}},(t,r)=>t.block.key===r.block.key&&t.block.stable&&r.block.stable);ae.displayName="StableBlock";function Ve(t={}){const{components:r,minUpdateInterval:c=16,immediate:o=!1,outputRate:s="medium",...f}=t,l=n.useRef(L.createStreamingParser(f)),a=n.useRef(new L.OutputRateController(s)),[u,m]=n.useState(0),[x,d]=n.useState(!1),[g,b]=n.useState(0),[p,k]=n.useState("idle"),E=n.useRef(0),v=n.useRef(null),S=n.useCallback(()=>{const R=performance.now(),D=R-E.current;o||D>=c?(E.current=R,m(T=>T+1)):v.current===null&&(v.current=window.requestAnimationFrame(()=>{v.current=null,E.current=performance.now(),m(T=>T+1)}))},[c,o]),w=n.useCallback(R=>{l.current.append(R),S()},[S]),C=n.useCallback(R=>{l.current.reset(),d(!1),b(0),k("running"),a.current.start(R,D=>{D&&l.current.append(D),b(a.current.progress),S()},()=>{l.current.finish(),d(!0),b(1),k("complete"),S()})},[S]),i=n.useCallback(()=>{a.current.pause(),k(a.current.status)},[]),j=n.useCallback(()=>{a.current.resume(),k(a.current.status)},[]),M=n.useCallback(()=>{a.current.skipToEnd(),k(a.current.status),b(1)},[]),B=n.useCallback(()=>{a.current.stop(),l.current.finish(),d(!0),k("complete"),v.current!==null&&(cancelAnimationFrame(v.current),v.current=null),m(R=>R+1)},[]),F=n.useCallback(()=>{a.current.stop(),l.current.reset(),d(!1),b(0),k("idle"),v.current!==null&&(cancelAnimationFrame(v.current),v.current=null),m(R=>R+1)},[]);n.useEffect(()=>{a.current.setRate(s)},[s]),n.useEffect(()=>()=>{a.current.stop(),v.current!==null&&cancelAnimationFrame(v.current)},[]);const h=l.current.getState(),y=l.current.getStats(),N=l.current.getContent(),I=n.useMemo(()=>h.blocks.map(R=>e.jsx(ae,{block:R,components:r},R.key)),[h.blocks,r,u]);return{element:n.useMemo(()=>h.blocks.length===0?null:e.jsx(e.Fragment,{children:I}),[I,h.blocks.length]),append:w,start:C,pause:i,resume:j,skipToEnd:M,reset:F,finish:B,blocks:h.blocks,stats:y,isComplete:x,content:N,progress:g,outputStatus:p}}const De=16,He="data:image/svg+xml,",Ae=()=>e.jsxs("svg",{width:"48",height:"36",viewBox:"0 0 48 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"0",y:"0",width:"48",height:"36",rx:"3",className:"md-image-skeleton-icon"}),e.jsx("circle",{cx:"12",cy:"10",r:"5",className:"md-image-skeleton-icon-detail"}),e.jsx("path",{d:"M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z",className:"md-image-skeleton-icon-detail"})]}),K=n.memo(({src:t,alt:r,className:c,"data-width":o,"data-height":s,...f})=>{const a=(t==null?void 0:t.startsWith(He))?void 0:t,u=o?Number(o):200,m=s?Number(s):120,[x,d]=n.useState(!0),g=n.useRef(null),b=n.useRef(null);n.useLayoutEffect(()=>{g.current&&a&&g.current.complete&&g.current.naturalWidth>0&&d(!1)},[a]);const p=n.useCallback(()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{d(!1)},De)},[]);return e.jsxs("span",{className:`md-image-container ${c||""}`,style:{width:u,height:m},children:[a&&e.jsx("img",{ref:g,src:a,alt:r,onLoad:p,className:"md-image",...f}),x&&e.jsx("span",{className:"md-image-skeleton",children:e.jsx(Ae,{})})]})});K.displayName="StreamingImage";let U=!1,$=null;async function ce(){if(!U)return $||($=(async()=>{await import("katex/dist/katex.min.css"),U=!0})(),$)}const Oe=n.memo(({children:t})=>(n.useEffect(()=>{U||ce()},[]),e.jsx(e.Fragment,{children:t})));Oe.displayName="MathProvider";function $e(){return ce()}const le=n.memo(({block:t,components:r})=>{if(!t.hast)return null;try{return Z.toJsxRuntime(t.hast,{jsx:e.jsx,jsxs:e.jsxs,Fragment:e.Fragment,components:r})}catch{return e.jsx("div",{className:"parse-error",children:t.source})}},(t,r)=>t.block.key===r.block.key&&t.block.stable&&r.block.stable);le.displayName="StableBlock";const oe=({content:t,source:r,outputRate:c="medium",isComplete:o=!1,onComplete:s,onBlockStable:f,onProgress:l,components:a,className:u,minUpdateInterval:m=16,autoStart:x=!0,copyButton:d=!0,onCodeCopy:g,...b})=>{n.useEffect(()=>{b.math&&$e()},[b.math]);const p=n.useRef(L.createStreamingParser(b)),k=n.useRef(new L.OutputRateController(c)),E=n.useRef(""),v=n.useRef(void 0),S=n.useRef([]),[,w]=n.useReducer(h=>h+1,0),C=n.useRef(0),i=n.useRef(null),j=()=>{const h=performance.now();h-C.current>=m?(C.current=h,w()):i.current===null&&(i.current=window.requestAnimationFrame(()=>{i.current=null,C.current=performance.now(),w()}))};n.useEffect(()=>{r!==void 0&&r!==v.current&&(v.current=r,x&&r&&(p.current.reset(),E.current="",k.current.start(r,h=>{h&&(p.current.append(h),E.current+=h),l==null||l(k.current.progress),j()},()=>{p.current.finish(),s==null||s(),j()})))},[r,x,s,l]),n.useEffect(()=>{if(r!==void 0)return;const h=E.current,y=t||"";if(y!==h){if(y.startsWith(h)){const N=y.slice(h.length);N&&p.current.append(N)}else p.current.reset(),y&&p.current.append(y);E.current=y,j()}},[t,r]),n.useEffect(()=>{r===void 0&&o&&(p.current.finish(),i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),w(),s==null||s())},[o,s,r]),n.useEffect(()=>{k.current.setRate(c)},[c]),n.useEffect(()=>{if(f){const h=p.current.getState().blocks,y=S.current;h.forEach((N,I)=>{const A=y[I];N.stable&&(!A||!A.stable)&&f(N)}),S.current=h}}),n.useEffect(()=>()=>{k.current.stop(),i.current!==null&&cancelAnimationFrame(i.current)},[]);const M=p.current.getState(),B=r!==void 0?k.current.status==="complete":o,F=n.useMemo(()=>{const h=y=>{if(d)return N=>e.jsx(Y,{showCopyButton:y.stable&&d,onCopy:g,...N})};return M.blocks.map(y=>{const N=h(y),I={img:K,...N?{pre:N}:{},...a};return e.jsx(le,{block:y,components:I},y.key)})},[M.blocks,a,d,g]);return e.jsx("div",{className:u,"data-streaming":!B,children:F})};oe.displayName="StreamingMarkdown";const ie=n.memo(t=>{const{text:r,animationConfig:c}=t,{fadeDuration:o=200,easing:s="ease-in-out"}=c||{},[f,l]=n.useState([]),a=n.useRef("");n.useEffect(()=>{if(r===a.current)return;if(!(a.current&&r.indexOf(a.current)===0)){l([r]),a.current=r;return}const m=r.slice(a.current.length);m&&(l(x=>[...x,m]),a.current=r)},[r]);const u=`md-fade-in ${o}ms ${s} forwards`;return e.jsx(e.Fragment,{children:f.map((m,x)=>e.jsx("span",{className:"md-animation-text",style:{animation:u},children:m},`animation-text-${x}`))})});ie.displayName="AnimationText";let P=null;try{P=require("dompurify")}catch{}function Pe(){return P!==null}function Ze(t,r){if(!P)return t;const c={ADD_ATTR:["target","rel","data-block-key","data-pending","data-predicted"],...r};return P.default.sanitize(t,c)}function X(t){if(t.type==="root")return{...t,children:t.children.map(s=>s.type==="element"?X(s):s)};const r=["onclick","onerror","onload","onmouseover","onfocus","onblur"],c=["javascript:","vbscript:","data:text/html"],o={};if(t.properties)for(const[s,f]of Object.entries(t.properties)){const l=s.toLowerCase();if(!(r.includes(l)||l.startsWith("on"))){if((l==="href"||l==="src")&&typeof f=="string"){const a=f.toLowerCase().trim();if(c.some(u=>a.startsWith(u)))continue}o[s]=f}}return{...t,properties:o,children:t.children.map(s=>s.type==="element"?X(s):s)}}exports.AnimationText=ie;exports.CodeBlock=Y;exports.Markdown=se;exports.MermaidBlock=J;exports.MermaidFullscreenViewer=q;exports.StreamingImage=K;exports.StreamingMarkdown=oe;exports.isDOMPurifyAvailable=Pe;exports.sanitizeHast=X;exports.sanitizeHtml=Ze;exports.useMarkdown=Te;exports.useStreamingMarkdown=Ve;exports.useZoom=W;