@superlc/md-vue 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,5 +1,6 @@
1
1
  import { PropType } from 'vue';
2
2
  import { MermaidTheme } from '@superlc/md-core';
3
+ import { StreamStatus } from './types';
3
4
 
4
5
  export declare const MermaidBlock: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
5
6
  code: {
@@ -14,6 +15,10 @@ export declare const MermaidBlock: import('vue').DefineComponent<import('vue').E
14
15
  type: BooleanConstructor;
15
16
  default: boolean;
16
17
  };
18
+ streamStatus: {
19
+ type: PropType<StreamStatus>;
20
+ default: string;
21
+ };
17
22
  }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
18
23
  [key: string]: any;
19
24
  }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "copy"[], "copy", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
@@ -29,10 +34,15 @@ export declare const MermaidBlock: import('vue').DefineComponent<import('vue').E
29
34
  type: BooleanConstructor;
30
35
  default: boolean;
31
36
  };
37
+ streamStatus: {
38
+ type: PropType<StreamStatus>;
39
+ default: string;
40
+ };
32
41
  }>> & Readonly<{
33
42
  onCopy?: ((...args: any[]) => any) | undefined;
34
43
  }>, {
35
44
  theme: MermaidTheme | "auto";
36
45
  showToolbar: boolean;
46
+ streamStatus: StreamStatus;
37
47
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
38
48
  //# sourceMappingURL=MermaidBlock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MermaidBlock.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/MermaidBlock.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQL,KAAK,QAAQ,EACd,MAAM,KAAK,CAAC;AACb,OAAO,EAML,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAoD1B,eAAO,MAAM,YAAY;;;;;;cAQH,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC;;;;;;;;;;;;;;;cAA/B,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC;;;;;;;;;;;;4EAgQnD,CAAC"}
1
+ {"version":3,"file":"MermaidBlock.d.ts","sourceRoot":"","sources":["../../../src/components/mermaid/MermaidBlock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAQL,KAAK,QAAQ,EACd,MAAM,KAAK,CAAC;AACb,OAAO,EAML,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,SAAS,CAAC;AAsDtD,eAAO,MAAM,YAAY;;;;;;cAQH,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC;;;;;;;;cAQ/B,QAAQ,CAAC,YAAY,CAAC;;;;;;;;;;;cARtB,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC;;;;;;;;cAQ/B,QAAQ,CAAC,YAAY,CAAC;;;;;;;;;4EAwT1C,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 ZoomConfig {
15
15
  step: number;
16
16
  default: number;
17
17
  }
18
+ /** 流式状态 */
19
+ export type StreamStatus = 'loading' | 'done';
18
20
  /** MermaidBlock Props */
19
21
  export interface MermaidBlockProps {
20
22
  /** Mermaid 源代码 */
@@ -23,6 +25,13 @@ export interface MermaidBlockProps {
23
25
  theme?: MermaidTheme | 'auto';
24
26
  /** 是否显示工具栏 */
25
27
  showToolbar?: boolean;
28
+ /**
29
+ * 流式状态
30
+ * - 'loading': 正在流式输入,代码块可能不完整
31
+ * - 'done': 流式输入完成,代码块已完整
32
+ * 用于优化流式渲染体验:loading 状态下会延迟渲染并保留上次有效结果
33
+ */
34
+ streamStatus?: StreamStatus;
26
35
  }
27
36
  /** MermaidFullscreenViewer Props */
28
37
  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,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,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,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;CACvB;AAED,oCAAoC;AACpC,MAAM,WAAW,4BAA4B;IAC3C,aAAa;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW;IACX,IAAI,EAAE,OAAO,CAAC;CACf"}
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,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,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,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;;;;;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;CACf"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var G=Object.create;var j=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(t,n,l,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Q(n))!te.call(t,o)&&o!==l&&j(t,o,{get:()=>n[o],enumerable:!(r=J(n,o))||r.enumerable});return t};var ae=(t,n,l)=>(l=t!=null?G(ee(t)):{},ne(n||!t||!t.__esModule?j(l,"default",{value:t,enumerable:!0}):l,t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),M=require("@superlc/md-core");let F=!1,H=null;async function le(){if(!F)return H||(H=(async()=>{await import("katex/dist/katex.min.css"),F=!0})(),H)}function oe(){return F}function O(){return le()}async function re(t){try{return await navigator.clipboard.writeText(t),!0}catch{return se(t)}}function se(t){const n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(n)}}const ue=()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[e.h("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"})]),ce=()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[e.h("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})]);function P(t){return typeof t=="string"?t:Array.isArray(t)?t.map(n=>typeof n=="string"?n:n&&typeof n=="object"&&"children"in n?P(n.children):"").join(""):""}const D=e.defineComponent({name:"CodeBlock",props:{showCopyButton:{type:Boolean,default:!0}},emits:["copy"],setup(t,{slots:n,emit:l}){const r=e.ref(!1),o=async()=>{var u;const a=(u=n.default)==null?void 0:u.call(n),s=a?P(a):"";await re(s)&&(r.value=!0,l("copy",s),setTimeout(()=>{r.value=!1},2e3))};return()=>{var s;const a=(s=n.default)==null?void 0:s.call(n);return e.h("div",{class:"md-code-block-wrapper"},[e.h("pre",{},a),t.showCopyButton&&e.h("button",{type:"button",class:`md-copy-button${r.value?" md-copy-button--copied":""}`,onClick:o,title:r.value?"已复制":"复制代码","aria-label":r.value?"已复制":"复制代码"},[r.value?e.h(ce):e.h(ue)])])}}}),ie={min:.25,max:4,step:.25,default:1};function R(t={}){const{config:n,enableDrag:l=!1,enableWheelZoom:r=!1}=t,o={...ie,...n},a=e.ref({scale:o.default,translateX:0,translateY:0}),s=e.ref(!1),c=e.ref({x:0,y:0}),u=e.ref({x:0,y:0}),d=y=>Math.max(o.min,Math.min(o.max,y)),v=e.computed(()=>a.value.scale<o.max),p=e.computed(()=>a.value.scale>o.min),m=()=>{a.value={...a.value,scale:d(a.value.scale+o.step)}},i=()=>{a.value={...a.value,scale:d(a.value.scale-o.step)}},h=()=>{a.value={scale:o.default,translateX:0,translateY:0}},C=y=>{a.value={...a.value,scale:d(y)}},f=(y,x)=>{const N=y.width/x.width,k=y.height/x.height,I=Math.min(N,k)*.95;a.value={scale:d(I),translateX:0,translateY:0}},z=y=>{l&&(y.preventDefault(),s.value=!0,c.value={x:y.clientX,y:y.clientY},u.value={x:a.value.translateX,y:a.value.translateY})},w=y=>{if(!s.value)return;const x=y.clientX-c.value.x,N=y.clientY-c.value.y;a.value={...a.value,translateX:u.value.x+x,translateY:u.value.y+N}},g=()=>{s.value=!1},b=y=>{if(!r)return;y.preventDefault();const x=y.deltaY>0?-o.step:o.step;a.value={...a.value,scale:d(a.value.scale+x)}},B=()=>{h()},S=e.computed(()=>({transform:`translate(${a.value.translateX}px, ${a.value.translateY}px) scale(${a.value.scale})`,transformOrigin:"center center",transition:s.value?"none":"transform 0.2s ease-out",cursor:l?s.value?"grabbing":"grab":"default"}));return e.onMounted(()=>{l&&(document.addEventListener("mousemove",w),document.addEventListener("mouseup",g))}),e.onUnmounted(()=>{l&&(document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",g))}),{state:a,zoomIn:m,zoomOut:i,reset:h,fitToContainer:f,setScale:C,canZoomIn:v,canZoomOut:p,contentStyle:S,onMouseDown:z,onWheel:b,onDoubleClick:B}}const de=e.defineComponent({name:"ImageIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),me=e.defineComponent({name:"CodeIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),$=e.defineComponent({name:"ZoomInIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),q=e.defineComponent({name:"ZoomOutIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),Y=e.defineComponent({name:"ResetIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),ve=e.defineComponent({name:"FullscreenIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"}))}}),fe=e.defineComponent({name:"FullscreenExitIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"}))}}),X=e.defineComponent({name:"DownloadIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"}))}}),he=e.defineComponent({name:"CloseIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),pe=e.defineComponent({name:"CopyIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),ye=e.defineComponent({name:"CheckIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"}))}});e.defineComponent({name:"FitIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M3 5v4h2V5h4V3H5c-1.1 0-2 .9-2 2zm2 10H3v4c0 1.1.9 2 2 2h4v-2H5v-4zm14 4h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zm0-16h-4v2h4v4h2V5c0-1.1-.9-2-2-2z"}))}});const K=e.defineComponent({name:"MermaidFullscreenViewer",props:{svg:{type:String,required:!0},open:{type:Boolean,required:!0}},emits:["close","download"],setup(t,{emit:n}){const l=e.ref(null),r=e.ref(null),o=e.ref(null),a=e.ref(!1),{state:s,zoomIn:c,zoomOut:u,reset:d,fitToContainer:v,canZoomIn:p,canZoomOut:m,contentStyle:i,onMouseDown:h,onWheel:C,onDoubleClick:f}=R({enableDrag:!0,enableWheelZoom:!0}),z=async()=>{if(l.value)try{await l.value.requestFullscreen(),a.value=!0}catch{a.value=!0}},w=()=>{document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),a.value=!1,n("close")};e.watch(()=>t.open,S=>{S?z():a.value&&w()});const g=()=>{!document.fullscreenElement&&a.value&&(a.value=!1,n("close"))},b=S=>{if(a.value)switch(S.key){case"+":case"=":c();break;case"-":u();break;case"0":d();break}};e.onMounted(()=>{document.addEventListener("fullscreenchange",g),document.addEventListener("keydown",b)}),e.onUnmounted(()=>{document.removeEventListener("fullscreenchange",g),document.removeEventListener("keydown",b)});const B=()=>{if(!r.value||!o.value)return;const S=r.value.getBoundingClientRect(),y=o.value.querySelector("svg");if(y){const x=y.getBoundingClientRect();v(S,x)}};return()=>e.h("div",{ref:l,class:["md-mermaid-fullscreen-wrapper",a.value&&"md-mermaid-fullscreen-wrapper--active"],role:"dialog","aria-modal":"true","aria-label":"Mermaid 图表全屏预览","aria-hidden":!a.value},a.value?[e.h("div",{class:"md-mermaid-fullscreen-toolbar"},[e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:u,disabled:!m.value,title:"缩小 (-)","aria-label":"缩小"},e.h(q)),e.h("span",{class:"md-mermaid-zoom-label"},`${Math.round(s.value.scale*100)}%`),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:c,disabled:!p.value,title:"放大 (+)","aria-label":"放大"},e.h($)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:d,title:"重置 (0)","aria-label":"重置"},e.h(Y)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:B,title:"适应窗口","aria-label":"适应窗口"},e.h(fe))]),e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:()=>n("download"),title:"下载 PNG","aria-label":"下载"},e.h(X)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:w,title:"退出全屏 (Esc)","aria-label":"退出全屏"},e.h(he))])]),e.h("div",{ref:r,class:"md-mermaid-fullscreen-content",onWheel:C},e.h("div",{ref:o,class:"md-mermaid-fullscreen-svg",style:i.value,onMousedown:h,onDblclick:f,innerHTML:t.svg}))]:void 0)}});let L=null;function ge(t="auto"){return L?L.setTheme(t??"auto"):L=new M.MermaidRenderer({theme:t}),L}async function be(t){try{return await navigator.clipboard.writeText(t),!0}catch{const n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(n)}}}const W=e.defineComponent({name:"MermaidBlock",props:{code:{type:String,required:!0},theme:{type:String,default:"auto"},showToolbar:{type:Boolean,default:!0}},emits:["copy"],setup(t,{emit:n}){const l=e.ref("preview"),r=e.ref(null),o=e.ref(!0),a=e.ref(!1),s=e.ref(!1),c=e.ref(M.detectColorScheme()),{state:u,zoomIn:d,zoomOut:v,reset:p,canZoomIn:m,canZoomOut:i,contentStyle:h}=R(),C=e.computed(()=>{var g;return((g=r.value)==null?void 0:g.success)&&r.value.svg});let f=null;e.onMounted(()=>{t.theme==="auto"&&(f=M.observeColorScheme(g=>{c.value=g}))}),e.onUnmounted(()=>{f==null||f()}),e.watch(()=>[t.code,t.theme,c.value],async()=>{o.value=!0;const b=await ge(t.theme).render(t.code);r.value=b,o.value=!1,b.success||(l.value="code")},{immediate:!0});const z=async()=>{await be(t.code)&&(s.value=!0,n("copy",t.code),setTimeout(()=>s.value=!1,2e3))},w=async()=>{var g,b;if((g=r.value)!=null&&g.svg)try{const B=((b=window.matchMedia)==null?void 0:b.call(window,"(prefers-color-scheme: dark)").matches)??!1;await M.downloadAsPng(r.value.svg,{backgroundColor:B?"#1a1a2e":"#ffffff",padding:20,scale:2})}catch(B){console.error("Download failed:",B)}};return()=>{const g=t.showToolbar?e.h("div",{class:"md-mermaid-toolbar"},[e.h("div",{class:"md-mermaid-toolbar-group md-mermaid-mode-switch"},[e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${l.value==="preview"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>l.value="preview",disabled:!C.value,title:"图片模式","aria-label":"图片模式"},e.h(de)),e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${l.value==="code"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>l.value="code",title:"代码模式","aria-label":"代码模式"},e.h(me))]),l.value==="preview"&&C.value?e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:v,disabled:!i.value,title:"缩小","aria-label":"缩小"},e.h(q)),e.h("span",{class:"md-mermaid-zoom-label"},`${Math.round(u.value.scale*100)}%`),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:d,disabled:!m.value,title:"放大","aria-label":"放大"},e.h($)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:p,title:"重置","aria-label":"重置缩放"},e.h(Y))]):null,e.h("div",{class:"md-mermaid-toolbar-group"},[l.value==="preview"&&C.value?[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:()=>a.value=!0,title:"全屏","aria-label":"全屏查看"},e.h(ve)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:w,title:"下载 PNG","aria-label":"下载"},e.h(X))]:null,l.value==="code"?e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${s.value?" md-mermaid-toolbar-btn--success":""}`,onClick:z,title:s.value?"已复制":"复制代码","aria-label":s.value?"已复制":"复制代码"},s.value?e.h(ye):e.h(pe)):null])]):null;let b;return o.value?b=e.h("div",{class:"md-mermaid-skeleton"},[e.h("div",{class:"md-mermaid-skeleton-box"})]):l.value==="preview"&&C.value?b=e.h("div",{class:"md-mermaid-preview",style:{overflow:"hidden"}},[e.h("div",{class:"md-mermaid-svg-container",style:h.value,innerHTML:r.value.svg})]):b=e.h("div",{class:"md-mermaid-code"},[e.h("pre",[e.h("code",{class:"language-mermaid"},t.code)]),r.value&&!r.value.success?e.h("div",{class:"md-mermaid-error"},[e.h("span","渲染失败: "),e.h("span",r.value.error)]):null]),e.h("div",{class:"md-mermaid-block"},[g,e.h("div",{class:"md-mermaid-content"},[b]),C.value?e.h(K,{svg:r.value.svg,open:a.value,onClose:()=>a.value=!1,onDownload:w}):null])}}});function Ce(t){var r;if(t.tagName!=="pre")return!1;const n=t.children.find(o=>o.type==="element"&&o.tagName==="code");if(!n)return!1;const l=(r=n.properties)==null?void 0:r.className;return Array.isArray(l)?l.some(o=>typeof o=="string"&&o.includes("language-mermaid")):typeof l=="string"&&l.includes("language-mermaid")}function we(t){const n=t.children.find(l=>l.type==="element"&&l.tagName==="code");return n?n.children.map(l=>l.type==="text"?l.value:"").join(""):""}function ke(t){return t?t===!0?{enabled:!0}:t.enabled!==!1?t:null:null}const U=e.defineComponent({name:"Markdown",props:{content:{type:String,required:!0},class:{type:String,default:""},gfm:{type:Boolean,default:!0},highlight:{type:Boolean,default:!0},math:{type:Boolean,default:!1},components:{type:Object,default:()=>({})},remarkPlugins:{type:Array,default:()=>[]},rehypePlugins:{type:Array,default:()=>[]},copyButton:{type:Boolean,default:!0},mermaid:{type:[Boolean,Object],default:!1}},emits:["codeCopy"],setup(t,{emit:n}){e.watch(()=>t.math,o=>{o&&O()},{immediate:!0});function l(o,a={},s=null){if(o.type==="text")return o.value;if(o.type==="comment")return null;if(o.type==="root"){const c=o.children.map(u=>l(u,a,s)).filter(u=>u!==null);return e.h("div",{class:t.class},c)}if(o.type==="element"){const{tagName:c,properties:u,children:d}=o;if(s&&Ce(o)){const i=we(o);return e.h(W,{code:i,theme:s.theme,onCopy:h=>n("codeCopy",h)})}const v=a[c]||c,p={};if(u)for(const[i,h]of Object.entries(u))i==="className"?p.class=Array.isArray(h)?h.join(" "):h:p[i]=h;const m=d.map(i=>l(i,a,s)).filter(i=>i!==null);return typeof v=="string"?e.h(v,p,m):e.h(v,p,()=>m)}return null}const r=e.computed(()=>{if(!t.content)return null;const o=M.parseToHast(t.content,{gfm:t.gfm,highlight:t.highlight,math:t.math,remarkPlugins:t.remarkPlugins,rehypePlugins:t.rehypePlugins}),a=ke(t.mermaid),s={...t.copyButton?{pre:e.defineComponent({setup(c,{slots:u}){return()=>e.h(D,{showCopyButton:t.copyButton,onCopy:d=>n("codeCopy",d)},u.default)}})}:{},...t.components};return l(o,s,a)});return()=>r.value?r.value:null}});function T(t,n){if(t.type==="text")return t.value;if(t.type==="root"){const l=t.children.map(r=>T(r,n)).filter(r=>r!==null);return e.h("div",{},l)}if(t.type==="element"){const l=t,r=l.tagName,o=n==null?void 0:n[r],a={...l.properties};a.className&&(a.class=Array.isArray(a.className)?a.className.join(" "):a.className,delete a.className);const s=l.children.map(c=>T(c,n)).filter(c=>c!==null);return o?e.h(o,a,()=>s):e.h(r,a,s)}return null}function xe(t={}){const{components:n,minUpdateInterval:l=16,immediate:r=!1,outputRate:o="medium",...a}=t,s=M.createStreamingParser(a),c=new M.OutputRateController(o),u=e.ref(0),d=e.ref(!1),v=e.ref(0),p=e.ref("idle");let m=0,i=null;const h=()=>{const k=performance.now(),I=k-m;r||I>=l?(m=k,u.value++):i===null&&(i=requestAnimationFrame(()=>{i=null,m=performance.now(),u.value++}))},C=k=>{s.append(k),h()},f=k=>{s.reset(),d.value=!1,v.value=0,p.value="running",c.start(k,I=>{I&&s.append(I),v.value=c.progress,h()},()=>{s.finish(),d.value=!0,v.value=1,p.value="complete",h()})},z=()=>{c.pause(),p.value=c.status},w=()=>{c.resume(),p.value=c.status},g=()=>{c.skipToEnd(),p.value=c.status,v.value=1},b=()=>{c.stop(),s.finish(),d.value=!0,p.value="complete",i!==null&&(cancelAnimationFrame(i),i=null),u.value++},B=()=>{c.stop(),s.reset(),d.value=!1,v.value=0,p.value="idle",i!==null&&(cancelAnimationFrame(i),i=null),u.value++};e.onUnmounted(()=>{c.stop(),i!==null&&cancelAnimationFrame(i)});const S=e.computed(()=>(u.value,s.getState().blocks)),y=e.computed(()=>(u.value,s.getStats())),x=e.computed(()=>(u.value,s.getContent()));return{vnode:e.computed(()=>{u.value;const k=s.getState();if(k.blocks.length===0)return null;const I=k.blocks.map(V=>V.hast?e.h("div",{key:V.key,"data-block-key":V.key,"data-pending":!V.stable||void 0},[T(V.hast,n)]):null).filter(V=>V!==null);return e.h("div",{"data-streaming":!d.value},I)}),append:C,start:f,pause:z,resume:w,skipToEnd:g,reset:B,finish:b,blocks:S,stats:y,isComplete:d,content:x,progress:v,outputStatus:p}}function A(t,n,l,r,o){if(t.type==="text")return t.value;if(t.type==="root"){const a=t.children.map(s=>A(s,n,l,r,o)).filter(s=>s!==null);return e.h("div",{},a)}if(t.type==="element"){const a=t,s=a.tagName,c=n==null?void 0:n[s],u={...a.properties};u.className&&(u.class=Array.isArray(u.className)?u.className.join(" "):u.className,delete u.className);const d=a.children.map(v=>A(v,n,l,r,o)).filter(v=>v!==null);return s==="pre"&&l&&!c?e.h(D,{showCopyButton:o&&l,onCopy:r},()=>d):c?e.h(c,u,()=>d):e.h(s,u,d)}return null}const Z=e.defineComponent({name:"StreamingMarkdown",props:{content:{type:String,default:void 0},source:{type:String,default:void 0},outputRate:{type:[String,Object],default:"medium"},isComplete:{type:Boolean,default:!1},components:{type:Object,default:void 0},class:{type:String,default:void 0},minUpdateInterval:{type:Number,default:16},autoStart:{type:Boolean,default:!0},gfm:{type:Boolean,default:!0},highlight:{type:Boolean,default:!0},math:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!0}},emits:["complete","blockStable","progress","codeCopy"],setup(t,{emit:n}){e.watch(()=>t.math,m=>{m&&O()},{immediate:!0});const l=M.createStreamingParser({gfm:t.gfm,highlight:t.highlight,math:t.math}),r=new M.OutputRateController(t.outputRate),o=e.ref(0),a=e.ref(""),s=e.ref(void 0),c=e.ref([]),u=e.ref(!1);let d=0,v=null;const p=()=>{const m=performance.now();m-d>=t.minUpdateInterval?(d=m,o.value++):v===null&&(v=requestAnimationFrame(()=>{v=null,d=performance.now(),o.value++}))};return e.watch(()=>t.source,m=>{m!==void 0&&m!==s.value&&(s.value=m,t.autoStart&&m&&(l.reset(),a.value="",u.value=!1,r.start(m,i=>{i&&(l.append(i),a.value+=i),n("progress",r.progress),p()},()=>{l.finish(),u.value=!0,n("complete"),p()})))},{immediate:!0}),e.watch(()=>t.content,m=>{if(t.source!==void 0)return;const i=a.value,h=m||"";if(h!==i){if(h.startsWith(i)){const f=h.slice(i.length);f&&l.append(f)}else l.reset(),h&&l.append(h);a.value=h,p();const C=l.getState().blocks;C.forEach((f,z)=>{const w=c.value[z];f.stable&&(!w||!w.stable)&&n("blockStable",f)}),c.value=C}},{immediate:!0}),e.watch(()=>t.isComplete,m=>{t.source===void 0&&m&&(l.finish(),v!==null&&(cancelAnimationFrame(v),v=null),o.value++,n("complete"))}),e.watch(()=>t.outputRate,m=>{r.setRate(m)}),e.onUnmounted(()=>{r.stop(),v!==null&&cancelAnimationFrame(v)}),()=>{o.value;const m=l.getState(),i=t.source!==void 0?u.value:t.isComplete,h=f=>n("codeCopy",f),C=m.blocks.map(f=>f.hast?e.h("div",{key:f.key,"data-block-key":f.key,"data-pending":!f.stable||void 0},[A(f.hast,t.components,t.copyButton,h,f.stable)]):null).filter(f=>f!==null);return e.h("div",{class:t.class,"data-streaming":!i},C)}}});function E(t,n={}){if(t.type==="text")return t.value;if(t.type==="comment")return null;if(t.type==="root"){const l=t.children.map(r=>E(r,n)).filter(r=>r!==null);return e.h("div",{},l)}if(t.type==="element"){const{tagName:l,properties:r,children:o}=t,a=n[l]||l,s={};if(r)for(const[u,d]of Object.entries(r))u==="className"?s.class=Array.isArray(d)?d.join(" "):d:s[u]=d;const c=o.map(u=>E(u,n)).filter(u=>u!==null);return e.h(a,s,()=>c)}return null}function Me(t,n={}){const{components:l={},...r}=n;return e.computed(()=>{const o=t();if(!o)return null;const a=M.parseToHast(o,r);return E(a,l)})}function _(t){t.component("Markdown",U),t.component("StreamingMarkdown",Z)}const ze={install:_,Markdown:U,StreamingMarkdown:Z};exports.CodeBlock=D;exports.Markdown=U;exports.MermaidBlock=W;exports.MermaidFullscreenViewer=K;exports.StreamingMarkdown=Z;exports.default=ze;exports.install=_;exports.isKatexCssLoaded=oe;exports.preloadKatexCss=O;exports.useMarkdown=Me;exports.useStreamingMarkdown=xe;exports.useZoom=R;
1
+ "use strict";var G=Object.create;var j=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(t,n,l,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Q(n))!te.call(t,o)&&o!==l&&j(t,o,{get:()=>n[o],enumerable:!(r=J(n,o))||r.enumerable});return t};var ae=(t,n,l)=>(l=t!=null?G(ee(t)):{},ne(n||!t||!t.__esModule?j(l,"default",{value:t,enumerable:!0}):l,t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),B=require("@superlc/md-core");let H=!1,T=null;async function le(){if(!H)return T||(T=(async()=>{await import("katex/dist/katex.min.css"),H=!0})(),T)}function oe(){return H}function R(){return le()}async function re(t){try{return await navigator.clipboard.writeText(t),!0}catch{return se(t)}}function se(t){const n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(n)}}const ue=()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[e.h("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"})]),ce=()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[e.h("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})]);function P(t){return typeof t=="string"?t:Array.isArray(t)?t.map(n=>typeof n=="string"?n:n&&typeof n=="object"&&"children"in n?P(n.children):"").join(""):""}const O=e.defineComponent({name:"CodeBlock",props:{showCopyButton:{type:Boolean,default:!0}},emits:["copy"],setup(t,{slots:n,emit:l}){const r=e.ref(!1),o=async()=>{var u;const a=(u=n.default)==null?void 0:u.call(n),s=a?P(a):"";await re(s)&&(r.value=!0,l("copy",s),setTimeout(()=>{r.value=!1},2e3))};return()=>{var s;const a=(s=n.default)==null?void 0:s.call(n);return e.h("div",{class:"md-code-block-wrapper"},[e.h("pre",{},a),t.showCopyButton&&e.h("button",{type:"button",class:`md-copy-button${r.value?" md-copy-button--copied":""}`,onClick:o,title:r.value?"已复制":"复制代码","aria-label":r.value?"已复制":"复制代码"},[r.value?e.h(ce):e.h(ue)])])}}}),ie={min:.25,max:4,step:.25,default:1};function D(t={}){const{config:n,enableDrag:l=!1,enableWheelZoom:r=!1}=t,o={...ie,...n},a=e.ref({scale:o.default,translateX:0,translateY:0}),s=e.ref(!1),i=e.ref({x:0,y:0}),u=e.ref({x:0,y:0}),c=m=>Math.max(o.min,Math.min(o.max,m)),f=e.computed(()=>a.value.scale<o.max),y=e.computed(()=>a.value.scale>o.min),v=()=>{a.value={...a.value,scale:c(a.value.scale+o.step)}},d=()=>{a.value={...a.value,scale:c(a.value.scale-o.step)}},h=()=>{a.value={scale:o.default,translateX:0,translateY:0}},k=m=>{a.value={...a.value,scale:c(m)}},p=(m,g)=>{const C=m.width/g.width,x=m.height/g.height,I=Math.min(C,x)*.95;a.value={scale:c(I),translateX:0,translateY:0}},w=m=>{l&&(m.preventDefault(),s.value=!0,i.value={x:m.clientX,y:m.clientY},u.value={x:a.value.translateX,y:a.value.translateY})},b=m=>{if(!s.value)return;const g=m.clientX-i.value.x,C=m.clientY-i.value.y;a.value={...a.value,translateX:u.value.x+g,translateY:u.value.y+C}},S=()=>{s.value=!1},z=m=>{if(!r)return;m.preventDefault();const g=m.deltaY>0?-o.step:o.step;a.value={...a.value,scale:c(a.value.scale+g)}},V=()=>{h()},M=e.computed(()=>({transform:`translate(${a.value.translateX}px, ${a.value.translateY}px) scale(${a.value.scale})`,transformOrigin:"center center",transition:s.value?"none":"transform 0.2s ease-out",cursor:l?s.value?"grabbing":"grab":"default"}));return e.onMounted(()=>{l&&(document.addEventListener("mousemove",b),document.addEventListener("mouseup",S))}),e.onUnmounted(()=>{l&&(document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",S))}),{state:a,zoomIn:v,zoomOut:d,reset:h,fitToContainer:p,setScale:k,canZoomIn:f,canZoomOut:y,contentStyle:M,onMouseDown:w,onWheel:z,onDoubleClick:V}}const de=e.defineComponent({name:"ImageIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),me=e.defineComponent({name:"CodeIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),$=e.defineComponent({name:"ZoomInIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),Y=e.defineComponent({name:"ZoomOutIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),q=e.defineComponent({name:"ResetIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),ve=e.defineComponent({name:"FullscreenIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"}))}}),fe=e.defineComponent({name:"FullscreenExitIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"}))}}),X=e.defineComponent({name:"DownloadIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"}))}}),he=e.defineComponent({name:"CloseIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),pe=e.defineComponent({name:"CopyIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("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"}))}}),ye=e.defineComponent({name:"CheckIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"}))}});e.defineComponent({name:"FitIcon",setup(){return()=>e.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},e.h("path",{d:"M3 5v4h2V5h4V3H5c-1.1 0-2 .9-2 2zm2 10H3v4c0 1.1.9 2 2 2h4v-2H5v-4zm14 4h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zm0-16h-4v2h4v4h2V5c0-1.1-.9-2-2-2z"}))}});const _=e.defineComponent({name:"MermaidFullscreenViewer",props:{svg:{type:String,required:!0},open:{type:Boolean,required:!0}},emits:["close","download"],setup(t,{emit:n}){const l=e.ref(null),r=e.ref(null),o=e.ref(null),a=e.ref(!1),{state:s,zoomIn:i,zoomOut:u,reset:c,fitToContainer:f,canZoomIn:y,canZoomOut:v,contentStyle:d,onMouseDown:h,onWheel:k,onDoubleClick:p}=D({enableDrag:!0,enableWheelZoom:!0}),w=async()=>{if(l.value)try{await l.value.requestFullscreen(),a.value=!0}catch{a.value=!0}},b=()=>{document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),a.value=!1,n("close")};e.watch(()=>t.open,M=>{M?w():a.value&&b()});const S=()=>{!document.fullscreenElement&&a.value&&(a.value=!1,n("close"))},z=M=>{if(a.value)switch(M.key){case"+":case"=":i();break;case"-":u();break;case"0":c();break}};e.onMounted(()=>{document.addEventListener("fullscreenchange",S),document.addEventListener("keydown",z)}),e.onUnmounted(()=>{document.removeEventListener("fullscreenchange",S),document.removeEventListener("keydown",z)});const V=()=>{if(!r.value||!o.value)return;const M=r.value.getBoundingClientRect(),m=o.value.querySelector("svg");if(m){const g=m.getBoundingClientRect();f(M,g)}};return()=>e.h("div",{ref:l,class:["md-mermaid-fullscreen-wrapper",a.value&&"md-mermaid-fullscreen-wrapper--active"],role:"dialog","aria-modal":"true","aria-label":"Mermaid 图表全屏预览","aria-hidden":!a.value},a.value?[e.h("div",{class:"md-mermaid-fullscreen-toolbar"},[e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:u,disabled:!v.value,title:"缩小 (-)","aria-label":"缩小"},e.h(Y)),e.h("span",{class:"md-mermaid-zoom-label"},`${Math.round(s.value.scale*100)}%`),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:i,disabled:!y.value,title:"放大 (+)","aria-label":"放大"},e.h($)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:c,title:"重置 (0)","aria-label":"重置"},e.h(q)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:V,title:"适应窗口","aria-label":"适应窗口"},e.h(fe))]),e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:()=>n("download"),title:"下载 PNG","aria-label":"下载"},e.h(X)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:b,title:"退出全屏 (Esc)","aria-label":"退出全屏"},e.h(he))])]),e.h("div",{ref:r,class:"md-mermaid-fullscreen-content",onWheel:k},e.h("div",{ref:o,class:"md-mermaid-fullscreen-svg",style:d.value,onMousedown:h,onDblclick:p,innerHTML:t.svg}))]:void 0)}}),ge=150;let L=null;function be(t="auto"){return L?L.setTheme(t??"auto"):L=new B.MermaidRenderer({theme:t}),L}async function Ce(t){try{return await navigator.clipboard.writeText(t),!0}catch{const n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(n)}}}const K=e.defineComponent({name:"MermaidBlock",props:{code:{type:String,required:!0},theme:{type:String,default:"auto"},showToolbar:{type:Boolean,default:!0},streamStatus:{type:String,default:"done"}},emits:["copy"],setup(t,{emit:n}){const l=e.ref("preview"),r=e.ref(null),o=e.ref(!0),a=e.ref(!1),s=e.ref(!1),i=e.ref(B.detectColorScheme());let u=null,c=null;const{state:f,zoomIn:y,zoomOut:v,reset:d,canZoomIn:h,canZoomOut:k,contentStyle:p}=D(),w=e.computed(()=>{var m;return((m=r.value)==null?void 0:m.success)&&r.value.svg});let b=null;e.onMounted(()=>{t.theme==="auto"&&(b=B.observeColorScheme(m=>{i.value=m}))}),e.onUnmounted(()=>{b==null||b(),c&&(clearTimeout(c),c=null)});let S=t.code,z=t.streamStatus;e.watch(()=>[t.code,t.theme,i.value,t.streamStatus],async()=>{S=t.code,z=t.streamStatus;const m=async()=>{z==="loading"&&u||(o.value=!0);const C=await be(t.theme).render(S);C.success&&C.svg?(u=C.svg,r.value=C,o.value=!1,l.value="preview"):z==="loading"?u&&(r.value={success:!0,svg:u},o.value=!1):(r.value=C,o.value=!1,l.value="code")};t.streamStatus==="loading"?c||(c=setTimeout(()=>{c=null,m()},ge)):(c&&(clearTimeout(c),c=null),m())},{immediate:!0});const V=async()=>{await Ce(t.code)&&(s.value=!0,n("copy",t.code),setTimeout(()=>s.value=!1,2e3))},M=async()=>{var m,g;if((m=r.value)!=null&&m.svg)try{const C=((g=window.matchMedia)==null?void 0:g.call(window,"(prefers-color-scheme: dark)").matches)??!1;await B.downloadAsPng(r.value.svg,{backgroundColor:C?"#1a1a2e":"#ffffff",padding:20,scale:2})}catch(C){console.error("Download failed:",C)}};return()=>{const m=t.showToolbar?e.h("div",{class:"md-mermaid-toolbar"},[e.h("div",{class:"md-mermaid-toolbar-group md-mermaid-mode-switch"},[e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${l.value==="preview"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>l.value="preview",disabled:!w.value,title:"图片模式","aria-label":"图片模式"},e.h(de)),e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${l.value==="code"?" md-mermaid-toolbar-btn--active":""}`,onClick:()=>l.value="code",title:"代码模式","aria-label":"代码模式"},e.h(me))]),l.value==="preview"&&w.value?e.h("div",{class:"md-mermaid-toolbar-group"},[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:v,disabled:!k.value,title:"缩小","aria-label":"缩小"},e.h(Y)),e.h("span",{class:"md-mermaid-zoom-label"},`${Math.round(f.value.scale*100)}%`),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:y,disabled:!h.value,title:"放大","aria-label":"放大"},e.h($)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:d,title:"重置","aria-label":"重置缩放"},e.h(q))]):null,e.h("div",{class:"md-mermaid-toolbar-group"},[l.value==="preview"&&w.value?[e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:()=>a.value=!0,title:"全屏","aria-label":"全屏查看"},e.h(ve)),e.h("button",{type:"button",class:"md-mermaid-toolbar-btn",onClick:M,title:"下载 PNG","aria-label":"下载"},e.h(X))]:null,l.value==="code"?e.h("button",{type:"button",class:`md-mermaid-toolbar-btn${s.value?" md-mermaid-toolbar-btn--success":""}`,onClick:V,title:s.value?"已复制":"复制代码","aria-label":s.value?"已复制":"复制代码"},s.value?e.h(ye):e.h(pe)):null])]):null;let g;return o.value?g=e.h("div",{class:"md-mermaid-skeleton"},[e.h("div",{class:"md-mermaid-skeleton-box"})]):l.value==="preview"&&w.value?g=e.h("div",{class:"md-mermaid-preview",style:{overflow:"hidden"}},[e.h("div",{class:"md-mermaid-svg-container",style:p.value,innerHTML:r.value.svg})]):g=e.h("div",{class:"md-mermaid-code"},[e.h("pre",[e.h("code",{class:"language-mermaid"},t.code)]),r.value&&!r.value.success&&t.streamStatus==="done"?e.h("div",{class:"md-mermaid-error"},[e.h("span","渲染失败: "),e.h("span",r.value.error)]):null]),e.h("div",{class:"md-mermaid-block"},[m,e.h("div",{class:"md-mermaid-content"},[g]),w.value?e.h(_,{svg:r.value.svg,open:a.value,onClose:()=>a.value=!1,onDownload:M}):null])}}});function we(t){var r;if(t.tagName!=="pre")return!1;const n=t.children.find(o=>o.type==="element"&&o.tagName==="code");if(!n)return!1;const l=(r=n.properties)==null?void 0:r.className;return Array.isArray(l)?l.some(o=>typeof o=="string"&&o.includes("language-mermaid")):typeof l=="string"&&l.includes("language-mermaid")}function ke(t){const n=t.children.find(l=>l.type==="element"&&l.tagName==="code");return n?n.children.map(l=>l.type==="text"?l.value:"").join(""):""}function Me(t){return t?t===!0?{enabled:!0}:t.enabled!==!1?t:null:null}const U=e.defineComponent({name:"Markdown",props:{content:{type:String,required:!0},class:{type:String,default:""},gfm:{type:Boolean,default:!0},highlight:{type:Boolean,default:!0},math:{type:Boolean,default:!1},components:{type:Object,default:()=>({})},remarkPlugins:{type:Array,default:()=>[]},rehypePlugins:{type:Array,default:()=>[]},copyButton:{type:Boolean,default:!0},mermaid:{type:[Boolean,Object],default:!1}},emits:["codeCopy"],setup(t,{emit:n}){e.watch(()=>t.math,o=>{o&&R()},{immediate:!0});function l(o,a={},s=null){if(o.type==="text")return o.value;if(o.type==="comment")return null;if(o.type==="root"){const i=o.children.map(u=>l(u,a,s)).filter(u=>u!==null);return e.h("div",{class:t.class},i)}if(o.type==="element"){const{tagName:i,properties:u,children:c}=o;if(s&&we(o)){const d=ke(o);return e.h(K,{code:d,theme:s.theme,onCopy:h=>n("codeCopy",h)})}const f=a[i]||i,y={};if(u)for(const[d,h]of Object.entries(u))d==="className"?y.class=Array.isArray(h)?h.join(" "):h:y[d]=h;const v=c.map(d=>l(d,a,s)).filter(d=>d!==null);return typeof f=="string"?e.h(f,y,v):e.h(f,y,()=>v)}return null}const r=e.computed(()=>{if(!t.content)return null;const o=B.parseToHast(t.content,{gfm:t.gfm,highlight:t.highlight,math:t.math,remarkPlugins:t.remarkPlugins,rehypePlugins:t.rehypePlugins}),a=Me(t.mermaid),s={...t.copyButton?{pre:e.defineComponent({setup(i,{slots:u}){return()=>e.h(O,{showCopyButton:t.copyButton,onCopy:c=>n("codeCopy",c)},u.default)}})}:{},...t.components};return l(o,s,a)});return()=>r.value?r.value:null}});function F(t,n){if(t.type==="text")return t.value;if(t.type==="root"){const l=t.children.map(r=>F(r,n)).filter(r=>r!==null);return e.h("div",{},l)}if(t.type==="element"){const l=t,r=l.tagName,o=n==null?void 0:n[r],a={...l.properties};a.className&&(a.class=Array.isArray(a.className)?a.className.join(" "):a.className,delete a.className);const s=l.children.map(i=>F(i,n)).filter(i=>i!==null);return o?e.h(o,a,()=>s):e.h(r,a,s)}return null}function xe(t={}){const{components:n,minUpdateInterval:l=16,immediate:r=!1,outputRate:o="medium",...a}=t,s=B.createStreamingParser(a),i=new B.OutputRateController(o),u=e.ref(0),c=e.ref(!1),f=e.ref(0),y=e.ref("idle");let v=0,d=null;const h=()=>{const x=performance.now(),I=x-v;r||I>=l?(v=x,u.value++):d===null&&(d=requestAnimationFrame(()=>{d=null,v=performance.now(),u.value++}))},k=x=>{s.append(x),h()},p=x=>{s.reset(),c.value=!1,f.value=0,y.value="running",i.start(x,I=>{I&&s.append(I),f.value=i.progress,h()},()=>{s.finish(),c.value=!0,f.value=1,y.value="complete",h()})},w=()=>{i.pause(),y.value=i.status},b=()=>{i.resume(),y.value=i.status},S=()=>{i.skipToEnd(),y.value=i.status,f.value=1},z=()=>{i.stop(),s.finish(),c.value=!0,y.value="complete",d!==null&&(cancelAnimationFrame(d),d=null),u.value++},V=()=>{i.stop(),s.reset(),c.value=!1,f.value=0,y.value="idle",d!==null&&(cancelAnimationFrame(d),d=null),u.value++};e.onUnmounted(()=>{i.stop(),d!==null&&cancelAnimationFrame(d)});const M=e.computed(()=>(u.value,s.getState().blocks)),m=e.computed(()=>(u.value,s.getStats())),g=e.computed(()=>(u.value,s.getContent()));return{vnode:e.computed(()=>{u.value;const x=s.getState();if(x.blocks.length===0)return null;const I=x.blocks.map(N=>N.hast?e.h("div",{key:N.key,"data-block-key":N.key,"data-pending":!N.stable||void 0},[F(N.hast,n)]):null).filter(N=>N!==null);return e.h("div",{"data-streaming":!c.value},I)}),append:k,start:p,pause:w,resume:b,skipToEnd:S,reset:V,finish:z,blocks:M,stats:m,isComplete:c,content:g,progress:f,outputStatus:y}}function E(t,n,l,r,o){if(t.type==="text")return t.value;if(t.type==="root"){const a=t.children.map(s=>E(s,n,l,r,o)).filter(s=>s!==null);return e.h("div",{},a)}if(t.type==="element"){const a=t,s=a.tagName,i=n==null?void 0:n[s],u={...a.properties};u.className&&(u.class=Array.isArray(u.className)?u.className.join(" "):u.className,delete u.className);const c=a.children.map(f=>E(f,n,l,r,o)).filter(f=>f!==null);return s==="pre"&&l&&!i?e.h(O,{showCopyButton:o&&l,onCopy:r},()=>c):i?e.h(i,u,()=>c):e.h(s,u,c)}return null}const Z=e.defineComponent({name:"StreamingMarkdown",props:{content:{type:String,default:void 0},source:{type:String,default:void 0},outputRate:{type:[String,Object],default:"medium"},isComplete:{type:Boolean,default:!1},components:{type:Object,default:void 0},class:{type:String,default:void 0},minUpdateInterval:{type:Number,default:16},autoStart:{type:Boolean,default:!0},gfm:{type:Boolean,default:!0},highlight:{type:Boolean,default:!0},math:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!0}},emits:["complete","blockStable","progress","codeCopy"],setup(t,{emit:n}){e.watch(()=>t.math,v=>{v&&R()},{immediate:!0});const l=B.createStreamingParser({gfm:t.gfm,highlight:t.highlight,math:t.math}),r=new B.OutputRateController(t.outputRate),o=e.ref(0),a=e.ref(""),s=e.ref(void 0),i=e.ref([]),u=e.ref(!1);let c=0,f=null;const y=()=>{const v=performance.now();v-c>=t.minUpdateInterval?(c=v,o.value++):f===null&&(f=requestAnimationFrame(()=>{f=null,c=performance.now(),o.value++}))};return e.watch(()=>t.source,v=>{v!==void 0&&v!==s.value&&(s.value=v,t.autoStart&&v&&(l.reset(),a.value="",u.value=!1,r.start(v,d=>{d&&(l.append(d),a.value+=d),n("progress",r.progress),y()},()=>{l.finish(),u.value=!0,n("complete"),y()})))},{immediate:!0}),e.watch(()=>t.content,v=>{if(t.source!==void 0)return;const d=a.value,h=v||"";if(h!==d){if(h.startsWith(d)){const p=h.slice(d.length);p&&l.append(p)}else l.reset(),h&&l.append(h);a.value=h,y();const k=l.getState().blocks;k.forEach((p,w)=>{const b=i.value[w];p.stable&&(!b||!b.stable)&&n("blockStable",p)}),i.value=k}},{immediate:!0}),e.watch(()=>t.isComplete,v=>{t.source===void 0&&v&&(l.finish(),f!==null&&(cancelAnimationFrame(f),f=null),o.value++,n("complete"))}),e.watch(()=>t.outputRate,v=>{r.setRate(v)}),e.onUnmounted(()=>{r.stop(),f!==null&&cancelAnimationFrame(f)}),()=>{o.value;const v=l.getState(),d=t.source!==void 0?u.value:t.isComplete,h=p=>n("codeCopy",p),k=v.blocks.map(p=>p.hast?e.h("div",{key:p.key,"data-block-key":p.key,"data-pending":!p.stable||void 0},[E(p.hast,t.components,t.copyButton,h,p.stable)]):null).filter(p=>p!==null);return e.h("div",{class:t.class,"data-streaming":!d},k)}}});function A(t,n={}){if(t.type==="text")return t.value;if(t.type==="comment")return null;if(t.type==="root"){const l=t.children.map(r=>A(r,n)).filter(r=>r!==null);return e.h("div",{},l)}if(t.type==="element"){const{tagName:l,properties:r,children:o}=t,a=n[l]||l,s={};if(r)for(const[u,c]of Object.entries(r))u==="className"?s.class=Array.isArray(c)?c.join(" "):c:s[u]=c;const i=o.map(u=>A(u,n)).filter(u=>u!==null);return e.h(a,s,()=>i)}return null}function Se(t,n={}){const{components:l={},...r}=n;return e.computed(()=>{const o=t();if(!o)return null;const a=B.parseToHast(o,r);return A(a,l)})}function W(t){t.component("Markdown",U),t.component("StreamingMarkdown",Z)}const ze={install:W,Markdown:U,StreamingMarkdown:Z};exports.CodeBlock=O;exports.Markdown=U;exports.MermaidBlock=K;exports.MermaidFullscreenViewer=_;exports.StreamingMarkdown=Z;exports.default=ze;exports.install=W;exports.isKatexCssLoaded=oe;exports.preloadKatexCss=R;exports.useMarkdown=Se;exports.useStreamingMarkdown=xe;exports.useZoom=D;