@superlc/md-vue 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,9 +38,13 @@ export declare const Markdown: import('vue').DefineComponent<import('vue').Extra
38
38
  type: PropType<PluginConfig[]>;
39
39
  default: () => never[];
40
40
  };
41
+ copyButton: {
42
+ type: BooleanConstructor;
43
+ default: boolean;
44
+ };
41
45
  }>, () => string | VNode<import('vue').RendererNode, import('vue').RendererElement, {
42
46
  [key: string]: any;
43
- }> | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
47
+ }> | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "codeCopy"[], "codeCopy", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
44
48
  content: {
45
49
  type: StringConstructor;
46
50
  required: true;
@@ -73,9 +77,16 @@ export declare const Markdown: import('vue').DefineComponent<import('vue').Extra
73
77
  type: PropType<PluginConfig[]>;
74
78
  default: () => never[];
75
79
  };
76
- }>> & Readonly<{}>, {
80
+ copyButton: {
81
+ type: BooleanConstructor;
82
+ default: boolean;
83
+ };
84
+ }>> & Readonly<{
85
+ onCodeCopy?: ((...args: any[]) => any) | undefined;
86
+ }>, {
77
87
  components: MarkdownComponents;
78
88
  class: string;
89
+ copyButton: boolean;
79
90
  gfm: boolean;
80
91
  highlight: boolean;
81
92
  math: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../src/Markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AACrF,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKlD;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;cAwBC,QAAQ,CAAC,kBAAkB,CAAC;;;;cAI7B,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;cARvB,QAAQ,CAAC,kBAAkB,CAAC;;;;cAI7B,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;;;;;;;;4EAmF3C,CAAC"}
1
+ {"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../src/Markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AACrF,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAMlD;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;cAwBC,QAAQ,CAAC,kBAAkB,CAAC;;;;cAI7B,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cARvB,QAAQ,CAAC,kBAAkB,CAAC;;;;cAI7B,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,YAAY,EAAE,CAAC;;;;;;;;;;;;;;;;;;4EA8G3C,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { PropType, VNode } from 'vue';
2
+
3
+ export interface CodeBlockProps {
4
+ showCopyButton?: boolean;
5
+ }
6
+ /**
7
+ * Vue 代码块组件,包装 <pre> 元素并添加复制按钮
8
+ */
9
+ export declare const CodeBlock: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
10
+ showCopyButton: {
11
+ type: PropType<boolean>;
12
+ default: boolean;
13
+ };
14
+ }>, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
15
+ [key: string]: any;
16
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "copy"[], "copy", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
17
+ showCopyButton: {
18
+ type: PropType<boolean>;
19
+ default: boolean;
20
+ };
21
+ }>> & Readonly<{
22
+ onCopy?: ((...args: any[]) => any) | undefined;
23
+ }>, {
24
+ showCopyButton: boolean;
25
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
26
+ //# sourceMappingURL=CodeBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeBlock.d.ts","sourceRoot":"","sources":["../../src/components/CodeBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAC;AA2FzE,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,SAAS;;cAIC,QAAQ,CAAC,OAAO,CAAC;;;;;;;cAAjB,QAAQ,CAAC,OAAO,CAAC;;;;;;;4EA0CtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { CodeBlock, type CodeBlockProps } from './CodeBlock';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var E=Object.create;var O=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var W=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of H(r))!$.call(e,i)&&i!==n&&O(e,i,{get:()=>r[i],enumerable:!(t=I(r,i))||t.enumerable});return e};var z=(e,r,n)=>(n=e!=null?E(_(e)):{},W(r||!e||!e.__esModule?O(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue"),N=require("@superlc/md-core");let b=!1,w=null;async function D(){if(!b)return w||(w=(async()=>{await import("katex/dist/katex.min.css"),b=!0})(),w)}function G(){return b}function U(){return D()}const j=a.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:()=>[]}},setup(e){a.watch(()=>e.math,t=>{t&&U()},{immediate:!0});function r(t,i={}){if(t.type==="text")return t.value;if(t.type==="comment")return null;if(t.type==="root"){const l=t.children.map(s=>r(s,i)).filter(s=>s!==null);return a.h("div",{class:e.class},l)}if(t.type==="element"){const{tagName:l,properties:s,children:o}=t,c=i[l]||l,d={};if(s)for(const[m,u]of Object.entries(s))m==="className"?d.class=Array.isArray(u)?u.join(" "):u:d[m]=u;const p=o.map(m=>r(m,i)).filter(m=>m!==null);return typeof c=="string"?a.h(c,d,p):a.h(c,d,()=>p)}return null}const n=a.computed(()=>{if(!e.content)return null;const t=N.parseToHast(e.content,{gfm:e.gfm,highlight:e.highlight,math:e.math,remarkPlugins:e.remarkPlugins,rehypePlugins:e.rehypePlugins});return r(t,e.components)});return()=>n.value?n.value:null}});function M(e,r){if(e.type==="text")return e.value;if(e.type==="root"){const n=e.children.map(t=>M(t,r)).filter(t=>t!==null);return a.h("div",{},n)}if(e.type==="element"){const n=e,t=n.tagName,i=r==null?void 0:r[t],l={...n.properties};l.className&&(l.class=Array.isArray(l.className)?l.className.join(" "):l.className,delete l.className);const s=n.children.map(o=>M(o,r)).filter(o=>o!==null);return i?a.h(i,l,()=>s):a.h(t,l,s)}return null}function J(e={}){const{components:r,minUpdateInterval:n=16,immediate:t=!1,outputRate:i="medium",...l}=e,s=N.createStreamingParser(l),o=new N.OutputRateController(i),c=a.ref(0),d=a.ref(!1),p=a.ref(0),m=a.ref("idle");let u=0,f=null;const v=()=>{const g=performance.now(),C=g-u;t||C>=n?(u=g,c.value++):f===null&&(f=requestAnimationFrame(()=>{f=null,u=performance.now(),c.value++}))},h=g=>{s.append(g),v()},y=g=>{s.reset(),d.value=!1,p.value=0,m.value="running",o.start(g,C=>{C&&s.append(C),p.value=o.progress,v()},()=>{s.finish(),d.value=!0,p.value=1,m.value="complete",v()})},A=()=>{o.pause(),m.value=o.status},S=()=>{o.resume(),m.value=o.status},F=()=>{o.skipToEnd(),m.value=o.status,p.value=1},R=()=>{o.stop(),s.finish(),d.value=!0,m.value="complete",f!==null&&(cancelAnimationFrame(f),f=null),c.value++},V=()=>{o.stop(),s.reset(),d.value=!1,p.value=0,m.value="idle",f!==null&&(cancelAnimationFrame(f),f=null),c.value++};a.onUnmounted(()=>{o.stop(),f!==null&&cancelAnimationFrame(f)});const q=a.computed(()=>(c.value,s.getState().blocks)),K=a.computed(()=>(c.value,s.getStats())),L=a.computed(()=>(c.value,s.getContent()));return{vnode:a.computed(()=>{c.value;const g=s.getState();if(g.blocks.length===0)return null;const C=g.blocks.map(k=>k.hast?a.h("div",{key:k.key,"data-block-key":k.key,"data-pending":!k.stable||void 0},[M(k.hast,r)]):null).filter(k=>k!==null);return a.h("div",{"data-streaming":!d.value},C)}),append:h,start:y,pause:A,resume:S,skipToEnd:F,reset:V,finish:R,blocks:q,stats:K,isComplete:d,content:L,progress:p,outputStatus:m}}function x(e,r){if(e.type==="text")return e.value;if(e.type==="root"){const n=e.children.map(t=>x(t,r)).filter(t=>t!==null);return a.h("div",{},n)}if(e.type==="element"){const n=e,t=n.tagName,i=r==null?void 0:r[t],l={...n.properties};l.className&&(l.class=Array.isArray(l.className)?l.className.join(" "):l.className,delete l.className);const s=n.children.map(o=>x(o,r)).filter(o=>o!==null);return i?a.h(i,l,()=>s):a.h(t,l,s)}return null}const B=a.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}},emits:["complete","blockStable","progress"],setup(e,{emit:r}){a.watch(()=>e.math,u=>{u&&U()},{immediate:!0});const n=N.createStreamingParser({gfm:e.gfm,highlight:e.highlight,math:e.math}),t=new N.OutputRateController(e.outputRate),i=a.ref(0),l=a.ref(""),s=a.ref(void 0),o=a.ref([]),c=a.ref(!1);let d=0,p=null;const m=()=>{const u=performance.now();u-d>=e.minUpdateInterval?(d=u,i.value++):p===null&&(p=requestAnimationFrame(()=>{p=null,d=performance.now(),i.value++}))};return a.watch(()=>e.source,u=>{u!==void 0&&u!==s.value&&(s.value=u,e.autoStart&&u&&(n.reset(),l.value="",c.value=!1,t.start(u,f=>{f&&(n.append(f),l.value+=f),r("progress",t.progress),m()},()=>{n.finish(),c.value=!0,r("complete"),m()})))},{immediate:!0}),a.watch(()=>e.content,u=>{if(e.source!==void 0)return;const f=l.value,v=u||"";if(v!==f){if(v.startsWith(f)){const y=v.slice(f.length);y&&n.append(y)}else n.reset(),v&&n.append(v);l.value=v,m();const h=n.getState().blocks;h.forEach((y,A)=>{const S=o.value[A];y.stable&&(!S||!S.stable)&&r("blockStable",y)}),o.value=h}},{immediate:!0}),a.watch(()=>e.isComplete,u=>{e.source===void 0&&u&&(n.finish(),p!==null&&(cancelAnimationFrame(p),p=null),i.value++,r("complete"))}),a.watch(()=>e.outputRate,u=>{t.setRate(u)}),a.onUnmounted(()=>{t.stop(),p!==null&&cancelAnimationFrame(p)}),()=>{i.value;const u=n.getState(),f=e.source!==void 0?c.value:e.isComplete,v=u.blocks.map(h=>h.hast?a.h("div",{key:h.key,"data-block-key":h.key,"data-pending":!h.stable||void 0},[x(h.hast,e.components)]):null).filter(h=>h!==null);return a.h("div",{class:e.class,"data-streaming":!f},v)}}});function P(e,r={}){if(e.type==="text")return e.value;if(e.type==="comment")return null;if(e.type==="root"){const n=e.children.map(t=>P(t,r)).filter(t=>t!==null);return a.h("div",{},n)}if(e.type==="element"){const{tagName:n,properties:t,children:i}=e,l=r[n]||n,s={};if(t)for(const[c,d]of Object.entries(t))c==="className"?s.class=Array.isArray(d)?d.join(" "):d:s[c]=d;const o=i.map(c=>P(c,r)).filter(c=>c!==null);return a.h(l,s,()=>o)}return null}function Q(e,r={}){const{components:n={},...t}=r;return a.computed(()=>{const i=e();if(!i)return null;const l=N.parseToHast(i,t);return P(l,n)})}function T(e){e.component("Markdown",j),e.component("StreamingMarkdown",B)}const X={install:T,Markdown:j,StreamingMarkdown:B};exports.Markdown=j;exports.StreamingMarkdown=B;exports.default=X;exports.install=T;exports.isKatexCssLoaded=G;exports.preloadKatexCss=U;exports.useMarkdown=Q;exports.useStreamingMarkdown=J;
1
+ "use strict";var z=Object.create;var V=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var D=(e,t,a,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!W.call(e,o)&&o!==a&&V(e,o,{get:()=>t[o],enumerable:!(l=E(t,o))||l.enumerable});return e};var G=(e,t,a)=>(a=e!=null?z($(e)):{},D(t||!e||!e.__esModule?V(a,"default",{value:e,enumerable:!0}):a,e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),w=require("@superlc/md-core");let S=!1,B=null;async function J(){if(!S)return B||(B=(async()=>{await import("katex/dist/katex.min.css"),S=!0})(),B)}function Q(){return S}function T(){return J()}async function X(e){try{return await navigator.clipboard.writeText(e),!0}catch{return Y(e)}}function Y(e){const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{return document.execCommand("copy"),!0}catch{return!1}finally{document.body.removeChild(t)}}const Z=()=>n.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[n.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"})]),ee=()=>n.h("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[n.h("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})]);function O(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>typeof t=="string"?t:t&&typeof t=="object"&&"children"in t?O(t.children):"").join(""):""}const j=n.defineComponent({name:"CodeBlock",props:{showCopyButton:{type:Boolean,default:!0}},emits:["copy"],setup(e,{slots:t,emit:a}){const l=n.ref(!1),o=async()=>{var s;const u=(s=t.default)==null?void 0:s.call(t),r=u?O(u):"";await X(r)&&(l.value=!0,a("copy",r),setTimeout(()=>{l.value=!1},2e3))};return()=>{var r;const u=(r=t.default)==null?void 0:r.call(t);return n.h("div",{class:"md-code-block-wrapper"},[n.h("pre",{},u),e.showCopyButton&&n.h("button",{type:"button",class:`md-copy-button${l.value?" md-copy-button--copied":""}`,onClick:o,title:l.value?"已复制":"复制代码","aria-label":l.value?"已复制":"复制代码"},[l.value?n.h(ee):n.h(Z)])])}}}),P=n.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}},emits:["codeCopy"],setup(e,{emit:t}){n.watch(()=>e.math,o=>{o&&T()},{immediate:!0});function a(o,u={}){if(o.type==="text")return o.value;if(o.type==="comment")return null;if(o.type==="root"){const r=o.children.map(i=>a(i,u)).filter(i=>i!==null);return n.h("div",{class:e.class},r)}if(o.type==="element"){const{tagName:r,properties:i,children:s}=o,m=u[r]||r,f={};if(i)for(const[c,d]of Object.entries(i))c==="className"?f.class=Array.isArray(d)?d.join(" "):d:f[c]=d;const h=s.map(c=>a(c,u)).filter(c=>c!==null);return typeof m=="string"?n.h(m,f,h):n.h(m,f,()=>h)}return null}const l=n.computed(()=>{if(!e.content)return null;const o=w.parseToHast(e.content,{gfm:e.gfm,highlight:e.highlight,math:e.math,remarkPlugins:e.remarkPlugins,rehypePlugins:e.rehypePlugins}),u={...e.copyButton?{pre:n.defineComponent({setup(r,{slots:i}){return()=>n.h(j,{showCopyButton:e.copyButton,onCopy:s=>t("codeCopy",s)},i.default)}})}:{},...e.components};return a(o,u)});return()=>l.value?l.value:null}});function x(e,t){if(e.type==="text")return e.value;if(e.type==="root"){const a=e.children.map(l=>x(l,t)).filter(l=>l!==null);return n.h("div",{},a)}if(e.type==="element"){const a=e,l=a.tagName,o=t==null?void 0:t[l],u={...a.properties};u.className&&(u.class=Array.isArray(u.className)?u.className.join(" "):u.className,delete u.className);const r=a.children.map(i=>x(i,t)).filter(i=>i!==null);return o?n.h(o,u,()=>r):n.h(l,u,r)}return null}function te(e={}){const{components:t,minUpdateInterval:a=16,immediate:l=!1,outputRate:o="medium",...u}=e,r=w.createStreamingParser(u),i=new w.OutputRateController(o),s=n.ref(0),m=n.ref(!1),f=n.ref(0),h=n.ref("idle");let c=0,d=null;const v=()=>{const y=performance.now(),k=y-c;l||k>=a?(c=y,s.value++):d===null&&(d=requestAnimationFrame(()=>{d=null,c=performance.now(),s.value++}))},C=y=>{r.append(y),v()},p=y=>{r.reset(),m.value=!1,f.value=0,h.value="running",i.start(y,k=>{k&&r.append(k),f.value=i.progress,v()},()=>{r.finish(),m.value=!0,f.value=1,h.value="complete",v()})},b=()=>{i.pause(),h.value=i.status},N=()=>{i.resume(),h.value=i.status},R=()=>{i.skipToEnd(),h.value=i.status,f.value=1},L=()=>{i.stop(),r.finish(),m.value=!0,h.value="complete",d!==null&&(cancelAnimationFrame(d),d=null),s.value++},q=()=>{i.stop(),r.reset(),m.value=!1,f.value=0,h.value="idle",d!==null&&(cancelAnimationFrame(d),d=null),s.value++};n.onUnmounted(()=>{i.stop(),d!==null&&cancelAnimationFrame(d)});const H=n.computed(()=>(s.value,r.getState().blocks)),I=n.computed(()=>(s.value,r.getStats())),K=n.computed(()=>(s.value,r.getContent()));return{vnode:n.computed(()=>{s.value;const y=r.getState();if(y.blocks.length===0)return null;const k=y.blocks.map(g=>g.hast?n.h("div",{key:g.key,"data-block-key":g.key,"data-pending":!g.stable||void 0},[x(g.hast,t)]):null).filter(g=>g!==null);return n.h("div",{"data-streaming":!m.value},k)}),append:C,start:p,pause:b,resume:N,skipToEnd:R,reset:q,finish:L,blocks:H,stats:I,isComplete:m,content:K,progress:f,outputStatus:h}}function A(e,t,a,l,o){if(e.type==="text")return e.value;if(e.type==="root"){const u=e.children.map(r=>A(r,t,a,l,o)).filter(r=>r!==null);return n.h("div",{},u)}if(e.type==="element"){const u=e,r=u.tagName,i=t==null?void 0:t[r],s={...u.properties};s.className&&(s.class=Array.isArray(s.className)?s.className.join(" "):s.className,delete s.className);const m=u.children.map(f=>A(f,t,a,l,o)).filter(f=>f!==null);return r==="pre"&&a&&!i?n.h(j,{showCopyButton:o&&a,onCopy:l},()=>m):i?n.h(i,s,()=>m):n.h(r,s,m)}return null}const U=n.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(e,{emit:t}){n.watch(()=>e.math,c=>{c&&T()},{immediate:!0});const a=w.createStreamingParser({gfm:e.gfm,highlight:e.highlight,math:e.math}),l=new w.OutputRateController(e.outputRate),o=n.ref(0),u=n.ref(""),r=n.ref(void 0),i=n.ref([]),s=n.ref(!1);let m=0,f=null;const h=()=>{const c=performance.now();c-m>=e.minUpdateInterval?(m=c,o.value++):f===null&&(f=requestAnimationFrame(()=>{f=null,m=performance.now(),o.value++}))};return n.watch(()=>e.source,c=>{c!==void 0&&c!==r.value&&(r.value=c,e.autoStart&&c&&(a.reset(),u.value="",s.value=!1,l.start(c,d=>{d&&(a.append(d),u.value+=d),t("progress",l.progress),h()},()=>{a.finish(),s.value=!0,t("complete"),h()})))},{immediate:!0}),n.watch(()=>e.content,c=>{if(e.source!==void 0)return;const d=u.value,v=c||"";if(v!==d){if(v.startsWith(d)){const p=v.slice(d.length);p&&a.append(p)}else a.reset(),v&&a.append(v);u.value=v,h();const C=a.getState().blocks;C.forEach((p,b)=>{const N=i.value[b];p.stable&&(!N||!N.stable)&&t("blockStable",p)}),i.value=C}},{immediate:!0}),n.watch(()=>e.isComplete,c=>{e.source===void 0&&c&&(a.finish(),f!==null&&(cancelAnimationFrame(f),f=null),o.value++,t("complete"))}),n.watch(()=>e.outputRate,c=>{l.setRate(c)}),n.onUnmounted(()=>{l.stop(),f!==null&&cancelAnimationFrame(f)}),()=>{o.value;const c=a.getState(),d=e.source!==void 0?s.value:e.isComplete,v=p=>t("codeCopy",p),C=c.blocks.map(p=>p.hast?n.h("div",{key:p.key,"data-block-key":p.key,"data-pending":!p.stable||void 0},[A(p.hast,e.components,e.copyButton,v,p.stable)]):null).filter(p=>p!==null);return n.h("div",{class:e.class,"data-streaming":!d},C)}}});function M(e,t={}){if(e.type==="text")return e.value;if(e.type==="comment")return null;if(e.type==="root"){const a=e.children.map(l=>M(l,t)).filter(l=>l!==null);return n.h("div",{},a)}if(e.type==="element"){const{tagName:a,properties:l,children:o}=e,u=t[a]||a,r={};if(l)for(const[s,m]of Object.entries(l))s==="className"?r.class=Array.isArray(m)?m.join(" "):m:r[s]=m;const i=o.map(s=>M(s,t)).filter(s=>s!==null);return n.h(u,r,()=>i)}return null}function ne(e,t={}){const{components:a={},...l}=t;return n.computed(()=>{const o=e();if(!o)return null;const u=w.parseToHast(o,l);return M(u,a)})}function F(e){e.component("Markdown",P),e.component("StreamingMarkdown",U)}const ae={install:F,Markdown:P,StreamingMarkdown:U};exports.CodeBlock=j;exports.Markdown=P;exports.StreamingMarkdown=U;exports.default=ae;exports.install=F;exports.isKatexCssLoaded=Q;exports.preloadKatexCss=T;exports.useMarkdown=ne;exports.useStreamingMarkdown=te;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import { Markdown } from './Markdown';
3
3
 
4
4
  export { Markdown };
5
5
  export { useMarkdown } from './useMarkdown';
6
+ export { CodeBlock } from './components';
7
+ export type { CodeBlockProps } from './components';
6
8
  export type { MarkdownProps, MarkdownComponents, UseMarkdownOptions } from './types';
7
9
  export { useStreamingMarkdown, StreamingMarkdown } from './streaming';
8
10
  export type { UseStreamingMarkdownOptions, UseStreamingMarkdownResult, StreamingMarkdownProps, StreamingMarkdownEmits, } from './streaming';
@@ -47,9 +49,13 @@ declare const _default: {
47
49
  type: import('vue').PropType<import('@superlc/md-core').PluginConfig[]>;
48
50
  default: () => never[];
49
51
  };
52
+ copyButton: {
53
+ type: BooleanConstructor;
54
+ default: boolean;
55
+ };
50
56
  }>, () => string | import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
51
57
  [key: string]: any;
52
- }> | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
58
+ }> | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "codeCopy"[], "codeCopy", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
53
59
  content: {
54
60
  type: StringConstructor;
55
61
  required: true;
@@ -82,9 +88,16 @@ declare const _default: {
82
88
  type: import('vue').PropType<import('@superlc/md-core').PluginConfig[]>;
83
89
  default: () => never[];
84
90
  };
85
- }>> & Readonly<{}>, {
91
+ copyButton: {
92
+ type: BooleanConstructor;
93
+ default: boolean;
94
+ };
95
+ }>> & Readonly<{
96
+ onCodeCopy?: ((...args: any[]) => any) | undefined;
97
+ }>, {
86
98
  components: import('./types').MarkdownComponents;
87
99
  class: string;
100
+ copyButton: boolean;
88
101
  gfm: boolean;
89
102
  highlight: boolean;
90
103
  math: boolean;
@@ -136,9 +149,13 @@ declare const _default: {
136
149
  type: BooleanConstructor;
137
150
  default: boolean;
138
151
  };
152
+ copyButton: {
153
+ type: BooleanConstructor;
154
+ default: boolean;
155
+ };
139
156
  }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
140
157
  [key: string]: any;
141
- }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("progress" | "complete" | "blockStable")[], "progress" | "complete" | "blockStable", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
158
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("progress" | "codeCopy" | "complete" | "blockStable")[], "progress" | "codeCopy" | "complete" | "blockStable", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
142
159
  content: {
143
160
  type: StringConstructor;
144
161
  default: undefined;
@@ -183,18 +200,24 @@ declare const _default: {
183
200
  type: BooleanConstructor;
184
201
  default: boolean;
185
202
  };
203
+ copyButton: {
204
+ type: BooleanConstructor;
205
+ default: boolean;
206
+ };
186
207
  }>> & Readonly<{
187
208
  onProgress?: ((...args: any[]) => any) | undefined;
209
+ onCodeCopy?: ((...args: any[]) => any) | undefined;
188
210
  onComplete?: ((...args: any[]) => any) | undefined;
189
211
  onBlockStable?: ((...args: any[]) => any) | undefined;
190
212
  }>, {
191
213
  content: string;
192
214
  components: import('./types').MarkdownComponents;
193
215
  class: string;
216
+ copyButton: boolean;
217
+ source: string;
194
218
  gfm: boolean;
195
219
  highlight: boolean;
196
220
  math: boolean;
197
- source: string;
198
221
  minUpdateInterval: number;
199
222
  outputRate: import('@superlc/md-core').OutputRate;
200
223
  isComplete: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGrF,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGnE,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;AAED,wBAIE"}
package/dist/index.js CHANGED
@@ -1,19 +1,99 @@
1
- import { defineComponent as M, watch as S, computed as A, h as p, ref as y, onUnmounted as O } from "vue";
2
- import { parseToHast as F, createStreamingParser as T, OutputRateController as R } from "@superlc/md-core";
3
- let B = !1, b = null;
4
- async function z() {
5
- if (!B)
6
- return b || (b = (async () => {
7
- await import("katex/dist/katex.min.css"), B = !0;
8
- })(), b);
1
+ import { defineComponent as A, ref as h, h as f, watch as w, computed as B, onUnmounted as U } from "vue";
2
+ import { parseToHast as P, createStreamingParser as F, OutputRateController as O } from "@superlc/md-core";
3
+ let T = !1, x = null;
4
+ async function D() {
5
+ if (!T)
6
+ return x || (x = (async () => {
7
+ await import("katex/dist/katex.min.css"), T = !0;
8
+ })(), x);
9
9
  }
10
- function X() {
11
- return B;
10
+ function ne() {
11
+ return T;
12
12
  }
13
- function V() {
14
- return z();
13
+ function R() {
14
+ return D();
15
15
  }
16
- const q = M({
16
+ async function G(e) {
17
+ try {
18
+ return await navigator.clipboard.writeText(e), !0;
19
+ } catch {
20
+ return J(e);
21
+ }
22
+ }
23
+ function J(e) {
24
+ const t = document.createElement("textarea");
25
+ t.value = e, t.style.position = "fixed", t.style.left = "-9999px", document.body.appendChild(t), t.select();
26
+ try {
27
+ return document.execCommand("copy"), !0;
28
+ } catch {
29
+ return !1;
30
+ } finally {
31
+ document.body.removeChild(t);
32
+ }
33
+ }
34
+ const Q = () => f(
35
+ "svg",
36
+ {
37
+ viewBox: "0 0 24 24",
38
+ fill: "currentColor"
39
+ },
40
+ [
41
+ f("path", {
42
+ 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"
43
+ })
44
+ ]
45
+ ), X = () => f(
46
+ "svg",
47
+ {
48
+ viewBox: "0 0 24 24",
49
+ fill: "currentColor"
50
+ },
51
+ [
52
+ f("path", {
53
+ d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"
54
+ })
55
+ ]
56
+ );
57
+ function I(e) {
58
+ return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => typeof t == "string" ? t : t && typeof t == "object" && "children" in t ? I(t.children) : "").join("") : "";
59
+ }
60
+ const L = A({
61
+ name: "CodeBlock",
62
+ props: {
63
+ showCopyButton: {
64
+ type: Boolean,
65
+ default: !0
66
+ }
67
+ },
68
+ emits: ["copy"],
69
+ setup(e, { slots: t, emit: l }) {
70
+ const a = h(!1), u = async () => {
71
+ var o;
72
+ const r = (o = t.default) == null ? void 0 : o.call(t), n = r ? I(r) : "";
73
+ await G(n) && (a.value = !0, l("copy", n), setTimeout(() => {
74
+ a.value = !1;
75
+ }, 2e3));
76
+ };
77
+ return () => {
78
+ var n;
79
+ const r = (n = t.default) == null ? void 0 : n.call(t);
80
+ return f("div", { class: "md-code-block-wrapper" }, [
81
+ f("pre", {}, r),
82
+ e.showCopyButton && f(
83
+ "button",
84
+ {
85
+ type: "button",
86
+ class: `md-copy-button${a.value ? " md-copy-button--copied" : ""}`,
87
+ onClick: u,
88
+ title: a.value ? "已复制" : "复制代码",
89
+ "aria-label": a.value ? "已复制" : "复制代码"
90
+ },
91
+ [a.value ? f(X) : f(Q)]
92
+ )
93
+ ]);
94
+ };
95
+ }
96
+ }), z = A({
17
97
  name: "Markdown",
18
98
  props: {
19
99
  content: {
@@ -47,153 +127,181 @@ const q = M({
47
127
  rehypePlugins: {
48
128
  type: Array,
49
129
  default: () => []
130
+ },
131
+ copyButton: {
132
+ type: Boolean,
133
+ default: !0
50
134
  }
51
135
  },
52
- setup(e) {
53
- S(
136
+ emits: ["codeCopy"],
137
+ setup(e, { emit: t }) {
138
+ w(
54
139
  () => e.math,
55
- (t) => {
56
- t && V();
140
+ (u) => {
141
+ u && R();
57
142
  },
58
143
  { immediate: !0 }
59
144
  );
60
- function r(t, c = {}) {
61
- if (t.type === "text")
62
- return t.value;
63
- if (t.type === "comment")
145
+ function l(u, r = {}) {
146
+ if (u.type === "text")
147
+ return u.value;
148
+ if (u.type === "comment")
64
149
  return null;
65
- if (t.type === "root") {
66
- const a = t.children.map((l) => r(l, c)).filter((l) => l !== null);
67
- return p("div", { class: e.class }, a);
150
+ if (u.type === "root") {
151
+ const n = u.children.map((s) => l(s, r)).filter((s) => s !== null);
152
+ return f("div", { class: e.class }, n);
68
153
  }
69
- if (t.type === "element") {
70
- const { tagName: a, properties: l, children: i } = t, u = c[a] || a, f = {};
71
- if (l)
72
- for (const [m, s] of Object.entries(l))
73
- m === "className" ? f.class = Array.isArray(s) ? s.join(" ") : s : f[m] = s;
74
- const d = i.map((m) => r(m, c)).filter((m) => m !== null);
75
- return typeof u == "string" ? p(u, f, d) : p(u, f, () => d);
154
+ if (u.type === "element") {
155
+ const { tagName: n, properties: s, children: o } = u, m = r[n] || n, d = {};
156
+ if (s)
157
+ for (const [i, c] of Object.entries(s))
158
+ i === "className" ? d.class = Array.isArray(c) ? c.join(" ") : c : d[i] = c;
159
+ const v = o.map((i) => l(i, r)).filter((i) => i !== null);
160
+ return typeof m == "string" ? f(m, d, v) : f(m, d, () => v);
76
161
  }
77
162
  return null;
78
163
  }
79
- const n = A(() => {
164
+ const a = B(() => {
80
165
  if (!e.content) return null;
81
- const t = F(e.content, {
166
+ const u = P(e.content, {
82
167
  gfm: e.gfm,
83
168
  highlight: e.highlight,
84
169
  math: e.math,
85
170
  remarkPlugins: e.remarkPlugins,
86
171
  rehypePlugins: e.rehypePlugins
87
- });
88
- return r(t, e.components);
172
+ }), r = {
173
+ ...e.copyButton ? {
174
+ pre: A({
175
+ setup(n, { slots: s }) {
176
+ return () => f(
177
+ L,
178
+ {
179
+ showCopyButton: e.copyButton,
180
+ onCopy: (o) => t("codeCopy", o)
181
+ },
182
+ s.default
183
+ );
184
+ }
185
+ })
186
+ } : {},
187
+ ...e.components
188
+ };
189
+ return l(u, r);
89
190
  });
90
- return () => n.value ? n.value : null;
191
+ return () => a.value ? a.value : null;
91
192
  }
92
193
  });
93
- function U(e, r) {
194
+ function j(e, t) {
94
195
  if (e.type === "text")
95
196
  return e.value;
96
197
  if (e.type === "root") {
97
- const n = e.children.map((t) => U(t, r)).filter((t) => t !== null);
98
- return p("div", {}, n);
198
+ const l = e.children.map((a) => j(a, t)).filter((a) => a !== null);
199
+ return f("div", {}, l);
99
200
  }
100
201
  if (e.type === "element") {
101
- const n = e, t = n.tagName, c = r == null ? void 0 : r[t], a = { ...n.properties };
102
- a.className && (a.class = Array.isArray(a.className) ? a.className.join(" ") : a.className, delete a.className);
103
- const l = n.children.map((i) => U(i, r)).filter((i) => i !== null);
104
- return c ? p(c, a, () => l) : p(t, a, l);
202
+ const l = e, a = l.tagName, u = t == null ? void 0 : t[a], r = { ...l.properties };
203
+ r.className && (r.class = Array.isArray(r.className) ? r.className.join(" ") : r.className, delete r.className);
204
+ const n = l.children.map((s) => j(s, t)).filter((s) => s !== null);
205
+ return u ? f(u, r, () => n) : f(a, r, n);
105
206
  }
106
207
  return null;
107
208
  }
108
- function Y(e = {}) {
209
+ function ae(e = {}) {
109
210
  const {
110
- components: r,
111
- minUpdateInterval: n = 16,
112
- immediate: t = !1,
113
- outputRate: c = "medium",
114
- ...a
115
- } = e, l = T(a), i = new R(c), u = y(0), f = y(!1), d = y(0), m = y("idle");
116
- let s = 0, o = null;
117
- const v = () => {
118
- const h = performance.now(), C = h - s;
119
- t || C >= n ? (s = h, u.value++) : o === null && (o = requestAnimationFrame(() => {
120
- o = null, s = performance.now(), u.value++;
211
+ components: t,
212
+ minUpdateInterval: l = 16,
213
+ immediate: a = !1,
214
+ outputRate: u = "medium",
215
+ ...r
216
+ } = e, n = F(r), s = new O(u), o = h(0), m = h(!1), d = h(0), v = h("idle");
217
+ let i = 0, c = null;
218
+ const y = () => {
219
+ const g = performance.now(), N = g - i;
220
+ a || N >= l ? (i = g, o.value++) : c === null && (c = requestAnimationFrame(() => {
221
+ c = null, i = performance.now(), o.value++;
121
222
  }));
122
- }, g = (h) => {
123
- l.append(h), v();
124
- }, k = (h) => {
125
- l.reset(), f.value = !1, d.value = 0, m.value = "running", i.start(
126
- h,
127
- (C) => {
128
- C && l.append(C), d.value = i.progress, v();
223
+ }, k = (g) => {
224
+ n.append(g), y();
225
+ }, p = (g) => {
226
+ n.reset(), m.value = !1, d.value = 0, v.value = "running", s.start(
227
+ g,
228
+ (N) => {
229
+ N && n.append(N), d.value = s.progress, y();
129
230
  },
130
231
  () => {
131
- l.finish(), f.value = !0, d.value = 1, m.value = "complete", v();
232
+ n.finish(), m.value = !0, d.value = 1, v.value = "complete", y();
132
233
  }
133
234
  );
134
- }, x = () => {
135
- i.pause(), m.value = i.status;
136
- }, w = () => {
137
- i.resume(), m.value = i.status;
138
- }, I = () => {
139
- i.skipToEnd(), m.value = i.status, d.value = 1;
235
+ }, S = () => {
236
+ s.pause(), v.value = s.status;
237
+ }, b = () => {
238
+ s.resume(), v.value = s.status;
239
+ }, H = () => {
240
+ s.skipToEnd(), v.value = s.status, d.value = 1;
241
+ }, q = () => {
242
+ s.stop(), n.finish(), m.value = !0, v.value = "complete", c !== null && (cancelAnimationFrame(c), c = null), o.value++;
140
243
  }, K = () => {
141
- i.stop(), l.finish(), f.value = !0, m.value = "complete", o !== null && (cancelAnimationFrame(o), o = null), u.value++;
142
- }, L = () => {
143
- i.stop(), l.reset(), f.value = !1, d.value = 0, m.value = "idle", o !== null && (cancelAnimationFrame(o), o = null), u.value++;
244
+ s.stop(), n.reset(), m.value = !1, d.value = 0, v.value = "idle", c !== null && (cancelAnimationFrame(c), c = null), o.value++;
144
245
  };
145
- O(() => {
146
- i.stop(), o !== null && cancelAnimationFrame(o);
246
+ U(() => {
247
+ s.stop(), c !== null && cancelAnimationFrame(c);
147
248
  });
148
- const $ = A(() => (u.value, l.getState().blocks)), H = A(() => (u.value, l.getStats())), W = A(() => (u.value, l.getContent()));
249
+ const $ = B(() => (o.value, n.getState().blocks)), W = B(() => (o.value, n.getStats())), _ = B(() => (o.value, n.getContent()));
149
250
  return {
150
- vnode: A(() => {
151
- u.value;
152
- const h = l.getState();
153
- if (h.blocks.length === 0)
251
+ vnode: B(() => {
252
+ o.value;
253
+ const g = n.getState();
254
+ if (g.blocks.length === 0)
154
255
  return null;
155
- const C = h.blocks.map((N) => N.hast ? p(
256
+ const N = g.blocks.map((C) => C.hast ? f(
156
257
  "div",
157
258
  {
158
- key: N.key,
159
- "data-block-key": N.key,
160
- "data-pending": !N.stable || void 0
259
+ key: C.key,
260
+ "data-block-key": C.key,
261
+ "data-pending": !C.stable || void 0
161
262
  },
162
- [U(N.hast, r)]
163
- ) : null).filter((N) => N !== null);
164
- return p("div", { "data-streaming": !f.value }, C);
263
+ [j(C.hast, t)]
264
+ ) : null).filter((C) => C !== null);
265
+ return f("div", { "data-streaming": !m.value }, N);
165
266
  }),
166
- append: g,
167
- start: k,
168
- pause: x,
169
- resume: w,
170
- skipToEnd: I,
171
- reset: L,
172
- finish: K,
267
+ append: k,
268
+ start: p,
269
+ pause: S,
270
+ resume: b,
271
+ skipToEnd: H,
272
+ reset: K,
273
+ finish: q,
173
274
  blocks: $,
174
- stats: H,
175
- isComplete: f,
176
- content: W,
275
+ stats: W,
276
+ isComplete: m,
277
+ content: _,
177
278
  progress: d,
178
- outputStatus: m
279
+ outputStatus: v
179
280
  };
180
281
  }
181
- function j(e, r) {
282
+ function V(e, t, l, a, u) {
182
283
  if (e.type === "text")
183
284
  return e.value;
184
285
  if (e.type === "root") {
185
- const n = e.children.map((t) => j(t, r)).filter((t) => t !== null);
186
- return p("div", {}, n);
286
+ const r = e.children.map((n) => V(n, t, l, a, u)).filter((n) => n !== null);
287
+ return f("div", {}, r);
187
288
  }
188
289
  if (e.type === "element") {
189
- const n = e, t = n.tagName, c = r == null ? void 0 : r[t], a = { ...n.properties };
190
- a.className && (a.class = Array.isArray(a.className) ? a.className.join(" ") : a.className, delete a.className);
191
- const l = n.children.map((i) => j(i, r)).filter((i) => i !== null);
192
- return c ? p(c, a, () => l) : p(t, a, l);
290
+ const r = e, n = r.tagName, s = t == null ? void 0 : t[n], o = { ...r.properties };
291
+ o.className && (o.class = Array.isArray(o.className) ? o.className.join(" ") : o.className, delete o.className);
292
+ const m = r.children.map((d) => V(d, t, l, a, u)).filter((d) => d !== null);
293
+ return n === "pre" && l && !s ? f(
294
+ L,
295
+ {
296
+ showCopyButton: u && l,
297
+ onCopy: a
298
+ },
299
+ () => m
300
+ ) : s ? f(s, o, () => m) : f(n, o, m);
193
301
  }
194
302
  return null;
195
303
  }
196
- const E = M({
304
+ const E = A({
197
305
  name: "StreamingMarkdown",
198
306
  props: {
199
307
  content: {
@@ -239,141 +347,146 @@ const E = M({
239
347
  math: {
240
348
  type: Boolean,
241
349
  default: !1
350
+ },
351
+ copyButton: {
352
+ type: Boolean,
353
+ default: !0
242
354
  }
243
355
  },
244
- emits: ["complete", "blockStable", "progress"],
245
- setup(e, { emit: r }) {
246
- S(
356
+ emits: ["complete", "blockStable", "progress", "codeCopy"],
357
+ setup(e, { emit: t }) {
358
+ w(
247
359
  () => e.math,
248
- (s) => {
249
- s && V();
360
+ (i) => {
361
+ i && R();
250
362
  },
251
363
  { immediate: !0 }
252
364
  );
253
- const n = T({
365
+ const l = F({
254
366
  gfm: e.gfm,
255
367
  highlight: e.highlight,
256
368
  math: e.math
257
- }), t = new R(e.outputRate), c = y(0), a = y(""), l = y(void 0), i = y([]), u = y(!1);
258
- let f = 0, d = null;
259
- const m = () => {
260
- const s = performance.now();
261
- s - f >= e.minUpdateInterval ? (f = s, c.value++) : d === null && (d = requestAnimationFrame(() => {
262
- d = null, f = performance.now(), c.value++;
369
+ }), a = new O(e.outputRate), u = h(0), r = h(""), n = h(void 0), s = h([]), o = h(!1);
370
+ let m = 0, d = null;
371
+ const v = () => {
372
+ const i = performance.now();
373
+ i - m >= e.minUpdateInterval ? (m = i, u.value++) : d === null && (d = requestAnimationFrame(() => {
374
+ d = null, m = performance.now(), u.value++;
263
375
  }));
264
376
  };
265
- return S(
377
+ return w(
266
378
  () => e.source,
267
- (s) => {
268
- s !== void 0 && s !== l.value && (l.value = s, e.autoStart && s && (n.reset(), a.value = "", u.value = !1, t.start(
269
- s,
270
- (o) => {
271
- o && (n.append(o), a.value += o), r("progress", t.progress), m();
379
+ (i) => {
380
+ i !== void 0 && i !== n.value && (n.value = i, e.autoStart && i && (l.reset(), r.value = "", o.value = !1, a.start(
381
+ i,
382
+ (c) => {
383
+ c && (l.append(c), r.value += c), t("progress", a.progress), v();
272
384
  },
273
385
  () => {
274
- n.finish(), u.value = !0, r("complete"), m();
386
+ l.finish(), o.value = !0, t("complete"), v();
275
387
  }
276
388
  )));
277
389
  },
278
390
  { immediate: !0 }
279
- ), S(
391
+ ), w(
280
392
  () => e.content,
281
- (s) => {
393
+ (i) => {
282
394
  if (e.source !== void 0)
283
395
  return;
284
- const o = a.value, v = s || "";
285
- if (v !== o) {
286
- if (v.startsWith(o)) {
287
- const k = v.slice(o.length);
288
- k && n.append(k);
396
+ const c = r.value, y = i || "";
397
+ if (y !== c) {
398
+ if (y.startsWith(c)) {
399
+ const p = y.slice(c.length);
400
+ p && l.append(p);
289
401
  } else
290
- n.reset(), v && n.append(v);
291
- a.value = v, m();
292
- const g = n.getState().blocks;
293
- g.forEach((k, x) => {
294
- const w = i.value[x];
295
- k.stable && (!w || !w.stable) && r("blockStable", k);
296
- }), i.value = g;
402
+ l.reset(), y && l.append(y);
403
+ r.value = y, v();
404
+ const k = l.getState().blocks;
405
+ k.forEach((p, S) => {
406
+ const b = s.value[S];
407
+ p.stable && (!b || !b.stable) && t("blockStable", p);
408
+ }), s.value = k;
297
409
  }
298
410
  },
299
411
  { immediate: !0 }
300
- ), S(
412
+ ), w(
301
413
  () => e.isComplete,
302
- (s) => {
303
- e.source === void 0 && s && (n.finish(), d !== null && (cancelAnimationFrame(d), d = null), c.value++, r("complete"));
414
+ (i) => {
415
+ e.source === void 0 && i && (l.finish(), d !== null && (cancelAnimationFrame(d), d = null), u.value++, t("complete"));
304
416
  }
305
- ), S(
417
+ ), w(
306
418
  () => e.outputRate,
307
- (s) => {
308
- t.setRate(s);
419
+ (i) => {
420
+ a.setRate(i);
309
421
  }
310
- ), O(() => {
311
- t.stop(), d !== null && cancelAnimationFrame(d);
422
+ ), U(() => {
423
+ a.stop(), d !== null && cancelAnimationFrame(d);
312
424
  }), () => {
313
- c.value;
314
- const s = n.getState(), o = e.source !== void 0 ? u.value : e.isComplete, v = s.blocks.map((g) => g.hast ? p(
425
+ u.value;
426
+ const i = l.getState(), c = e.source !== void 0 ? o.value : e.isComplete, y = (p) => t("codeCopy", p), k = i.blocks.map((p) => p.hast ? f(
315
427
  "div",
316
428
  {
317
- key: g.key,
318
- "data-block-key": g.key,
319
- "data-pending": !g.stable || void 0
429
+ key: p.key,
430
+ "data-block-key": p.key,
431
+ "data-pending": !p.stable || void 0
320
432
  },
321
- [j(g.hast, e.components)]
322
- ) : null).filter((g) => g !== null);
323
- return p(
433
+ [V(p.hast, e.components, e.copyButton, y, p.stable)]
434
+ ) : null).filter((p) => p !== null);
435
+ return f(
324
436
  "div",
325
437
  {
326
438
  class: e.class,
327
- "data-streaming": !o
439
+ "data-streaming": !c
328
440
  },
329
- v
441
+ k
330
442
  );
331
443
  };
332
444
  }
333
445
  });
334
- function P(e, r = {}) {
446
+ function M(e, t = {}) {
335
447
  if (e.type === "text")
336
448
  return e.value;
337
449
  if (e.type === "comment")
338
450
  return null;
339
451
  if (e.type === "root") {
340
- const n = e.children.map((t) => P(t, r)).filter((t) => t !== null);
341
- return p("div", {}, n);
452
+ const l = e.children.map((a) => M(a, t)).filter((a) => a !== null);
453
+ return f("div", {}, l);
342
454
  }
343
455
  if (e.type === "element") {
344
- const { tagName: n, properties: t, children: c } = e, a = r[n] || n, l = {};
345
- if (t)
346
- for (const [u, f] of Object.entries(t))
347
- u === "className" ? l.class = Array.isArray(f) ? f.join(" ") : f : l[u] = f;
348
- const i = c.map((u) => P(u, r)).filter((u) => u !== null);
349
- return p(a, l, () => i);
456
+ const { tagName: l, properties: a, children: u } = e, r = t[l] || l, n = {};
457
+ if (a)
458
+ for (const [o, m] of Object.entries(a))
459
+ o === "className" ? n.class = Array.isArray(m) ? m.join(" ") : m : n[o] = m;
460
+ const s = u.map((o) => M(o, t)).filter((o) => o !== null);
461
+ return f(r, n, () => s);
350
462
  }
351
463
  return null;
352
464
  }
353
- function Z(e, r = {}) {
354
- const { components: n = {}, ...t } = r;
355
- return A(() => {
356
- const c = e();
357
- if (!c) return null;
358
- const a = F(c, t);
359
- return P(a, n);
465
+ function re(e, t = {}) {
466
+ const { components: l = {}, ...a } = t;
467
+ return B(() => {
468
+ const u = e();
469
+ if (!u) return null;
470
+ const r = P(u, a);
471
+ return M(r, l);
360
472
  });
361
473
  }
362
- function D(e) {
363
- e.component("Markdown", q), e.component("StreamingMarkdown", E);
474
+ function Y(e) {
475
+ e.component("Markdown", z), e.component("StreamingMarkdown", E);
364
476
  }
365
- const _ = {
366
- install: D,
367
- Markdown: q,
477
+ const le = {
478
+ install: Y,
479
+ Markdown: z,
368
480
  StreamingMarkdown: E
369
481
  };
370
482
  export {
371
- q as Markdown,
483
+ L as CodeBlock,
484
+ z as Markdown,
372
485
  E as StreamingMarkdown,
373
- _ as default,
374
- D as install,
375
- X as isKatexCssLoaded,
376
- V as preloadKatexCss,
377
- Z as useMarkdown,
378
- Y as useStreamingMarkdown
486
+ le as default,
487
+ Y as install,
488
+ ne as isKatexCssLoaded,
489
+ R as preloadKatexCss,
490
+ re as useMarkdown,
491
+ ae as useStreamingMarkdown
379
492
  };
@@ -50,9 +50,13 @@ export declare const StreamingMarkdown: import('vue').DefineComponent<import('vu
50
50
  type: BooleanConstructor;
51
51
  default: boolean;
52
52
  };
53
+ copyButton: {
54
+ type: BooleanConstructor;
55
+ default: boolean;
56
+ };
53
57
  }>, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
54
58
  [key: string]: any;
55
- }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("progress" | "complete" | "blockStable")[], "progress" | "complete" | "blockStable", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
59
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("progress" | "codeCopy" | "complete" | "blockStable")[], "progress" | "codeCopy" | "complete" | "blockStable", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
56
60
  content: {
57
61
  type: StringConstructor;
58
62
  default: undefined;
@@ -97,18 +101,24 @@ export declare const StreamingMarkdown: import('vue').DefineComponent<import('vu
97
101
  type: BooleanConstructor;
98
102
  default: boolean;
99
103
  };
104
+ copyButton: {
105
+ type: BooleanConstructor;
106
+ default: boolean;
107
+ };
100
108
  }>> & Readonly<{
101
109
  onProgress?: ((...args: any[]) => any) | undefined;
110
+ onCodeCopy?: ((...args: any[]) => any) | undefined;
102
111
  onComplete?: ((...args: any[]) => any) | undefined;
103
112
  onBlockStable?: ((...args: any[]) => any) | undefined;
104
113
  }>, {
105
114
  content: string;
106
115
  components: MarkdownComponents;
107
116
  class: string;
117
+ copyButton: boolean;
118
+ source: string;
108
119
  gfm: boolean;
109
120
  highlight: boolean;
110
121
  math: boolean;
111
- source: string;
112
122
  minUpdateInterval: number;
113
123
  outputRate: OutputRate;
114
124
  isComplete: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../src/streaming/StreamingMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,QAAQ,EACb,KAAK,KAAK,EACX,MAAM,KAAK,CAAC;AACb,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAgDnD;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;cAaE,QAAQ,CAAC,UAAU,CAAC;;;;;;;;cAQ9B,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cARlB,QAAQ,CAAC,UAAU,CAAC;;;;;;;;cAQ9B,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EA2NhD,CAAC"}
1
+ {"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../src/streaming/StreamingMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,QAAQ,EACb,KAAK,KAAK,EACX,MAAM,KAAK,CAAC;AACb,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAgEnD;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;cAaE,QAAQ,CAAC,UAAU,CAAC;;;;;;;;cAQ9B,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cARlB,QAAQ,CAAC,UAAU,CAAC;;;;;;;;cAQ9B,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EAiOhD,CAAC"}
@@ -68,6 +68,8 @@ export interface StreamingMarkdownProps extends StreamingParserOptions {
68
68
  minUpdateInterval?: number;
69
69
  /** 是否自动开始输出(仅 source 模式) */
70
70
  autoStart?: boolean;
71
+ /** 是否显示代码块复制按钮,默认 true */
72
+ copyButton?: boolean;
71
73
  }
72
74
  /**
73
75
  * StreamingMarkdown 组件 Emits
@@ -79,5 +81,7 @@ export interface StreamingMarkdownEmits {
79
81
  (e: 'blockStable', block: BlockInfo): void;
80
82
  /** 进度变化事件 */
81
83
  (e: 'progress', progress: number): void;
84
+ /** 代码复制事件 */
85
+ (e: 'codeCopy', code: string): void;
82
86
  }
83
87
  //# source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BAAsB;IACpE,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,gBAAgB;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,eAAe;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW;IACX,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACtB,YAAY;IACZ,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC3C,aAAa;IACb,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,aAAa;IACb,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC"}
package/dist/types.d.ts CHANGED
@@ -51,6 +51,8 @@ export interface MarkdownProps extends ProcessorOptions {
51
51
  components?: MarkdownComponents;
52
52
  /** 容器 class */
53
53
  class?: string;
54
+ /** 是否显示代码块复制按钮,默认 true */
55
+ copyButton?: boolean;
54
56
  }
55
57
  /**
56
58
  * useMarkdown Composable 配置
@@ -58,5 +60,7 @@ export interface MarkdownProps extends ProcessorOptions {
58
60
  export interface UseMarkdownOptions extends ProcessorOptions {
59
61
  /** 自定义组件映射 */
60
62
  components?: MarkdownComponents;
63
+ /** 是否显示代码块复制按钮,默认 true */
64
+ copyButton?: boolean;
61
65
  }
62
66
  //# sourceMapping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,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,UAAU;IACV,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,cAAc;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,eAAe;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,cAAc;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superlc/md-vue",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "基于 @superlc/md-core 的 Vue 3 Markdown 渲染组件",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -17,15 +17,9 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
- "scripts": {
21
- "build": "vite build",
22
- "dev": "vite build --watch",
23
- "test": "vitest",
24
- "test:run": "vitest run"
25
- },
26
20
  "dependencies": {
27
- "@superlc/md-core": "workspace:*",
28
- "katex": "^0.16.28"
21
+ "katex": "^0.16.28",
22
+ "@superlc/md-core": "0.1.1"
29
23
  },
30
24
  "peerDependencies": {
31
25
  "vue": ">=3.3.0"
@@ -41,5 +35,11 @@
41
35
  "component",
42
36
  "unified"
43
37
  ],
44
- "license": "MIT"
45
- }
38
+ "license": "MIT",
39
+ "scripts": {
40
+ "build": "vite build",
41
+ "dev": "vite build --watch",
42
+ "test": "vitest",
43
+ "test:run": "vitest run"
44
+ }
45
+ }