@hejiayue/x-markdown-test 0.0.1-beta.108 → 0.0.1-beta.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-D9u8JldH.cjs +2 -0
- package/dist/index-D9u8JldH.cjs.map +1 -0
- package/dist/{index-BjeepIV6.js → index-SElRorTo.js} +9 -3
- package/dist/index-SElRorTo.js.map +1 -0
- package/dist/{index-Ys7-7uFi.js → index-lQ_FQFr2.js} +77 -51
- package/dist/{index-Ys7-7uFi.js.map → index-lQ_FQFr2.js.map} +1 -1
- package/dist/index-nZ5iH1aN.cjs +2 -0
- package/dist/{index-DtKeGkdv.cjs.map → index-nZ5iH1aN.cjs.map} +1 -1
- package/dist/style.css +1 -1
- package/dist/x-markdown.cjs.js +1 -1
- package/dist/x-markdown.es.js +11 -11
- package/package.json +98 -98
- package/LICENSE +0 -21
- package/dist/index-BjeepIV6.js.map +0 -1
- package/dist/index-CgG50XSZ.cjs +0 -2
- package/dist/index-CgG50XSZ.cjs.map +0 -1
- package/dist/index-DtKeGkdv.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=require("vue"),t=require("property-information"),a=require("deepmerge"),o=require("rehype-sanitize"),n=require("remark-parse"),l=require("remark-rehype"),r=require("unified"),i=require("rehype-katex"),c=require("rehype-raw"),s=require("remark-breaks"),u=require("remark-gfm"),d=require("remark-math"),m=require("unist-util-visit"),p=require("lodash-es");function h(t,a,o,n){return e.h("div",a,v(t.children,{listDepth:-1,listOrdered:!1,listItemIndex:-1,svg:!1},t,o??{},e.toValue(n)??{},{}))}function v(t,a,o,n,l,r){return t.map(t=>{switch(t.type){case"text":case"raw":return t.value;case"root":return v(t.children,a,o,n,l,r);case"element":{const{attrs:i,context:c,aliasList:s,vnodeProps:u}=g(t,o,a,r,l);for(let e=s.length-1;e>=0;e--){const a=n[s[e]];if("function"==typeof a)return a({...u,...i,children:()=>v(t.children,c,t,n,l,r)})}return e.h(t.tagName,i,v(t.children,c,t,n,l,r))}default:return null}})}function g(e,a,o,n,l){const r=[];let i={};const c={},s={...o};if("element"===e.type){switch(r.push(e.tagName),n[e.tagName]=e.tagName in n?n[e.tagName]+1:0,c.key=`${e.tagName}-${n[e.tagName]}`,e.properties=e.properties||{},"svg"===e.tagName&&(s.svg=!0),i=Object.entries(e.properties).reduce((e,[a,o])=>(e[t.find(s.svg?t.svg:t.html,a).attribute]=o,e),{}),e.tagName){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":c.level=Number.parseFloat(e.tagName.slice(1)),r.push("heading");break;case"code":c.languageOriginal=Array.isArray(i.class)?i.class.find(e=>e.startsWith("language-")):"",c.language=c.languageOriginal?c.languageOriginal.replace("language-",""):"",c.inline="tagName"in a&&"pre"!==a.tagName,c.content=e.children[0]?.value??"",r.push(c.inline?"inline-code":"block-code");break;case"thead":case"tbody":s.currentContext=e.tagName;break;case"td":case"th":case"tr":c.isHead="thead"===o.currentContext;break;case"ul":case"ol":s.listDepth=o.listDepth+1,s.listOrdered="ol"===e.tagName,s.listItemIndex=-1,c.ordered=s.listOrdered,c.depth=s.listDepth,r.push("list");break;case"li":s.listItemIndex++,c.ordered=s.listOrdered,c.depth=s.listDepth,c.index=s.listItemIndex,r.push("list-item");break;case"slot":"string"==typeof e.properties["slot-name"]&&(r.push(`${e.properties["slot-name"]}`),delete e.properties["slot-name"])}i=function(e,t,a,o,n){const l={...o};for(let r=t.length-1;r>=0;r--){const i=t[r];if(i in n){const t=n[i];return{...l,..."function"==typeof t?t(e,{...o,...a}):t}}}return l}(e,r,c,{...i},l)}return{attrs:i,context:s,aliasList:r,vnodeProps:c}}function f(t){return{processor:e.computed(()=>y({prePlugins:[n,...e.toValue(t?.remarkPlugins)??[]],rehypePlugins:e.toValue(t?.rehypePlugins),rehypeOptions:e.toValue(t?.rehypeOptions),sanitize:e.toValue(t?.sanitize),sanitizeOptions:e.toValue(t?.sanitizeOptions)}))}}function y(e){return r.unified().use(e?.prePlugins??[]).use(l,{allowDangerousHtml:!0,...e?.rehypeOptions||{}}).use(e?.rehypePlugins??[]).use(e?.sanitize?[[o,a(o.defaultSchema,e?.sanitizeOptions?.sanitizeOptions||{},e?.sanitizeOptions?.mergeOptions||{})]]:[])}const k={markdown:{type:String,default:""},customAttrs:{type:Object,default:()=>({})},remarkPlugins:{type:Array,default:()=>[]},rehypePlugins:{type:Array,default:()=>[]},rehypeOptions:{type:Object,default:()=>({})},sanitize:{type:Boolean,default:!1},sanitizeOptions:{type:Object,default:()=>({})}},w=e.defineComponent({name:"VueMarkdown",props:k,setup(t,{slots:a,attrs:o}){const{markdown:n,remarkPlugins:l,rehypePlugins:r,rehypeOptions:i,sanitize:c,sanitizeOptions:s,customAttrs:u}=e.toRefs(t),{processor:d}=f({remarkPlugins:l,rehypePlugins:r,rehypeOptions:i,sanitize:c,sanitizeOptions:s});return()=>{const e=d.value.parse(n.value);return h(d.value.runSync(e),o,a,u.value)}}}),x=e.defineComponent({name:"VueMarkdownAsync",props:k,async setup(t,{slots:a,attrs:o}){const{markdown:n,remarkPlugins:l,rehypePlugins:r,rehypeOptions:i,sanitize:c,sanitizeOptions:s,customAttrs:u}=e.toRefs(t),{processor:d}=f({remarkPlugins:l,rehypePlugins:r,rehypeOptions:i,sanitize:c,sanitizeOptions:s}),m=e.shallowRef(null),p=async()=>{const e=d.value.parse(n.value);m.value=await d.value.run(e)};return e.watch(()=>[n.value,d.value],p,{flush:"sync"}),await p(),()=>m.value?h(m.value,o,a,u.value):null}}),b="undefined"!=typeof window&&"undefined"!=typeof document,B=Object.prototype.toString;function C(e){return Array.isArray(e)?e:[e]}const O=b?window:void 0,E=b?window.navigator:void 0;function S(...t){const a=e.computed(()=>{const a=C(e.toValue(t[0])).filter(e=>null!=e);return a.every(e=>"string"!=typeof e)?a:void 0});return o=()=>{var o,n;return[null!==(o=null===(n=a.value)||void 0===n?void 0:n.map(t=>function(t){var a;const o=e.toValue(t);return null!==(a=null==o?void 0:o.$el)&&void 0!==a?a:o}(t)))&&void 0!==o?o:[O].filter(e=>null!=e),C(e.toValue(a.value?t[1]:t[0])),C(e.unref(a.value?t[2]:t[1])),e.toValue(a.value?t[3]:t[2])]},n=([e,t,a,o],n,l)=>{if(!(null==e?void 0:e.length)||!(null==t?void 0:t.length)||!(null==a?void 0:a.length))return;const r=(i=o,"[object Object]"===B.call(i)?{...o}:o);var i;const c=e.flatMap(e=>t.flatMap(t=>a.map(a=>((e,t,a,o)=>(e.addEventListener(t,a,o),()=>e.removeEventListener(t,a,o)))(e,t,a,r))));l(()=>{c.forEach(e=>e())})},l={flush:"post"},e.watch(o,n,{...l,immediate:!0});var o,n,l}function A(){const t=e.shallowRef(!1),a=e.getCurrentInstance();return a&&e.onMounted(()=>{t.value=!0},a),t}function R(t){const a=A();return e.computed(()=>(a.value,Boolean(t())))}function L(t,a={}){const{controls:o=!1,navigator:n=E}=a,l=R(()=>n&&"permissions"in n),r=e.shallowRef(),i="string"==typeof t?{name:t}:t,c=e.shallowRef(),s=()=>{var e,t;c.value=null!==(e=null===(t=r.value)||void 0===t?void 0:t.state)&&void 0!==e?e:"prompt"};S(r,"change",s,{passive:!0});const u=function(){let t;function a(){return t||(t=(async()=>{if(l.value){if(!r.value)try{r.value=await n.permissions.query(i)}catch(t){r.value=void 0}finally{s()}return o?e.toRaw(r.value):void 0}})()),t}return a.reset=async()=>{const e=t;t=void 0,e&&await e},a}();return u(),o?{state:c,isSupported:l,query:u}:c}function z(t={}){const{navigator:a=E,read:o=!1,source:n,copiedDuring:l=1500,legacy:r=!1}=t,i=R(()=>a&&"clipboard"in a),c=L("clipboard-read"),s=L("clipboard-write"),u=e.computed(()=>i.value||r),d=e.shallowRef(""),m=e.shallowRef(!1),p=function(t,a,o={}){const{immediate:n=!0,immediateCallback:l=!1}=o,r=e.shallowRef(!1);let i;function c(){i&&(clearTimeout(i),i=void 0)}function s(){r.value=!1,c()}function u(...o){l&&t(),c(),r.value=!0,i=setTimeout(()=>{r.value=!1,i=void 0,t(...o)},e.toValue(a))}var d;return n&&(r.value=!0,b&&u()),d=s,e.getCurrentScope()&&e.onScopeDispose(d,void 0),{isPending:e.shallowReadonly(r),start:u,stop:s}}(()=>m.value=!1,l,{immediate:!1});function h(e){return"granted"===e||"prompt"===e}return u.value&&o&&S(["copy","cut"],async function(){let e=!(i.value&&h(c.value));if(!e)try{d.value=await a.clipboard.readText()}catch(l){e=!0}var t,o,n;e&&(d.value=null!==(t=null===(o=document)||void 0===o||null===(n=o.getSelection)||void 0===n||null===(n=n.call(o))||void 0===n?void 0:n.toString())&&void 0!==t?t:"")},{passive:!0}),{isSupported:u,text:e.readonly(d),copied:e.readonly(m),copy:async function(t=e.toValue(n)){if(u.value&&null!=t){let e=!(i.value&&h(s.value));if(!e)try{await a.clipboard.writeText(t)}catch(o){e=!0}e&&function(e){const t=document.createElement("textarea");t.value=e,t.style.position="absolute",t.style.opacity="0",t.setAttribute("readonly",""),document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove()}(t),d.value=t,m.value=!0,p.start()}}}}let T=null,D=null,V=!1;const N=()=>{V||(V=!0,console.log("%c[x-markdown]%c 代码高亮功能已降级为纯文本模式","font-weight: bold; color: #0066cc;","color: #666;"),console.log("%c如需语法高亮功能,请安装以下依赖:","color: #666; font-weight: bold;"),console.log("%c pnpm add shiki shiki-stream","color: #00aa00; font-family: monospace;"),console.log("%c安装后请重启开发服务器","color: #999; font-size: 12px;"))},P=e=>{if(!e.length)return[[]];const t=[[]];let a=t[0];const o=()=>{a=[],t.push(a)};return e.forEach(e=>{const t=e.content??"";if("\n"===t)return void o();if(!t.includes("\n"))return void a.push(e);const n=t.split("\n");n.forEach((t,l)=>{t&&a.push({...e,content:t}),l<n.length-1&&o()})}),0===t.length?[[]]:t},M=(e,t)=>{if(e||t)return{backgroundColor:e,color:t}};function H(t,a){const o=e.ref(),n=e.ref(!1),l=e.ref(null);let r=null,i="",c=null,s="",u="";const d=e.computed(()=>(e.isRef(a.theme)?a.theme.value:a.theme)||"slack-dark"),m=e.computed(()=>e.toValue(a.language)||"text"),p=e.computed(()=>o.value?.lines||[[]]),h=e.computed(()=>o.value?.preStyle),v=async(e,t=!1)=>{if(!r)return;t&&(r.clear(),i="");const n=!t&&e.startsWith(i);let c=e;if(n?c=e.slice(i.length):t||r.clear(),i=e,!c){const e=[...r.tokensStable,...r.tokensUnstable];return void(o.value={colorReplacements:a.colorReplacements,lines:e.length?P(e):[[]],preStyle:o.value?.preStyle})}try{await r.enqueue(c);const e=[...r.tokensStable,...r.tokensUnstable];o.value={colorReplacements:a.colorReplacements,lines:P(e),preStyle:o.value?.preStyle}}catch(s){console.error("[x-markdown] Streaming highlighting failed:",s),l.value=s}},g=async()=>{n.value=!0,l.value=null;let e=m.value;const p=d.value;try{const n=await(async()=>(T||(T=(async()=>{try{return await import("shiki")}catch{return N(),null}})()),T))();if(!n)return console.warn("[x-markdown] Shiki not available, falling back to plain text mode"),void(o.value={colorReplacements:a.colorReplacements,lines:[[{content:t.value}]],preStyle:void 0});c=await n.getSingletonHighlighter({langs:[],themes:[p]}),u=e;try{await c.loadLanguage(e),s=e}catch{console.warn(`[x-markdown] Failed to load language: ${e}, falling back to plaintext`),e="plaintext",s="plaintext"}const l=await(async()=>(D||(D=(async()=>{try{return await import("shiki-stream")}catch{return N(),null}})()),D))();if(!l){console.warn("[x-markdown] shiki-stream not available, using non-streaming mode");const n=c.codeToThemedTokens(t.value,e,p);return void(o.value={colorReplacements:a.colorReplacements,lines:P(n),preStyle:M(c.getTheme(p)?.bg,c.getTheme(p)?.fg)})}const d=l.ShikiStreamTokenizer||l.default;r=new d({highlighter:c,lang:e,theme:p}),i="";const m=c.getTheme(p),h=M(m?.bg,m?.fg);t.value?(await v(t.value,!0),o.value&&(o.value.preStyle=h)):o.value={colorReplacements:a.colorReplacements,lines:[[]],preStyle:h}}catch(h){console.error("[x-markdown] Highlighter initialization failed:",h),l.value=h,o.value={colorReplacements:a.colorReplacements,lines:[[{content:t.value}]],preStyle:void 0}}finally{n.value=!1}};return e.watch(()=>[m.value,d.value],async([e])=>{const t=e;if(c&&"plaintext"===s&&t!==u&&"plaintext"!==t)try{return await c.loadLanguage(t),void g()}catch{return void(u=t)}g()},{immediate:!0}),e.watch(t,async e=>{const t=m.value;if(c&&"plaintext"===s&&t!==u&&"plaintext"!==t)try{return await c.loadLanguage(t),void(await g())}catch{u=t}r?v(e):c||(o.value={colorReplacements:a.colorReplacements,lines:[[{content:e}]],preStyle:o.value?.preStyle})}),e.onUnmounted(()=>{r?.clear(),r=null,i=""}),{streaming:o,lines:p,preStyle:h,isLoading:n,error:l}}const $={class:"x-md-syntax-code-block"},_={class:"x-md-code-content"},j={key:0},q=(e,t)=>{const a=e.__vccOpts||e;for(const[o,n]of t)a[o]=n;return a},I=q(e.defineComponent({name:"SyntaxCodeBlock",__name:"SyntaxCodeBlock",props:{code:{},language:{},lightTheme:{default:"vitesse-light"},darkTheme:{default:"vitesse-dark"},isDark:{type:Boolean,default:!1},colorReplacements:{},codeMaxHeight:{},enableAnimate:{type:Boolean,default:!1}},setup(t,{expose:a}){const o=t,n=e.computed(()=>o.code.trim()),l=e.computed(()=>o.language||"text"),r=e.computed(()=>o.isDark?o.darkTheme:o.lightTheme),{lines:i,preStyle:c}=H(n,{language:l,theme:r,colorReplacements:o.colorReplacements}),s=(e,t)=>t&&t[e.toLowerCase()]||e,u=e=>{if(!e)return{};if(e.htmlStyle){const t=(e=>{const t={};return Object.entries(e).forEach(([e,a])=>{const o=e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());t[o]=a}),t})(e.htmlStyle);if(!o.colorReplacements)return t;const a={...t};return a.color&&"string"==typeof a.color&&(a.color=s(a.color,o.colorReplacements)),a.backgroundColor&&"string"==typeof a.backgroundColor&&(a.backgroundColor=s(a.backgroundColor,o.colorReplacements)),a}const t={};return e.color&&(t.color=o.colorReplacements?s(e.color,o.colorReplacements):e.color),"italic"===e.fontStyle&&(t.fontStyle="italic"),e.fontWeight&&(t.fontWeight=e.fontWeight),t},d=e.computed(()=>!i.value?.length),m=e.computed(()=>({...c.value,maxHeight:o.codeMaxHeight}));return a({lines:i,code:n,language:l,actualTheme:r}),(t,a)=>(e.openBlock(),e.createElementBlock("div",$,[d.value?(e.openBlock(),e.createElementBlock("pre",{key:0,style:e.normalizeStyle(m.value)},[e.createElementVNode("code",null,e.toDisplayString(n.value),1)],4)):(e.openBlock(),e.createElementBlock("pre",{key:1,class:e.normalizeClass(["shiki",r.value]),style:e.normalizeStyle(m.value),tabindex:"0"},[a[4]||(a[4]=e.createTextVNode(" ",-1)),e.createElementVNode("code",_,[a[2]||(a[2]=e.createTextVNode("\n ",-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(t,n)=>(e.openBlock(),e.createElementBlock("span",{key:n,class:"x-md-code-line"},[a[0]||(a[0]=e.createTextVNode("\n ",-1)),t.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(t,(t,a)=>(e.openBlock(),e.createElementBlock("span",{key:a,style:e.normalizeStyle(u(t)),class:e.normalizeClass({"x-md-animated-word":o.enableAnimate})},e.toDisplayString(t.content),7))),128)):(e.openBlock(),e.createElementBlock("span",j," ")),a[1]||(a[1]=e.createTextVNode("\n ",-1))]))),128)),a[3]||(a[3]=e.createTextVNode("\n ",-1))]),a[5]||(a[5]=e.createTextVNode("\n ",-1))],6))]))}}),[["__scopeId","data-v-ddb364e9"]]),F={class:"x-md-code-header"},X={class:"x-md-code-header__left"},U=["title"],W={class:"x-md-code-lang"},Y={class:"x-md-code-header__right"},G=["title","disabled","onClick"],K={key:0,class:"x-md-copy-icon",width:"16",height:"16",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},Q={key:1,class:"x-md-copy-icon",width:"16",height:"16",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},Z=q(e.defineComponent({name:"CodeBlock",__name:"index",props:{code:{},language:{},lightTheme:{default:"vitesse-light"},darkTheme:{default:"vitesse-dark"},isDark:{type:Boolean,default:!1},colorReplacements:{},codeMaxHeight:{},showCodeBlockHeader:{type:Boolean,default:!0},enableAnimate:{type:Boolean,default:!1},codeBlockActions:{default:void 0},stickyCodeBlockHeader:{type:Boolean,default:!0}},setup(t,{expose:a}){const{copy:o,copied:n}=z({copiedDuring:2e3}),l=e.ref(!1),r=e.ref(null),i=()=>{l.value=!l.value},c=t,s=e.computed(()=>c.code.trim()),u=e.computed(()=>c.language||"text"),d=e.computed(()=>c.codeBlockActions||[]),m=e.computed(()=>d.value.filter(e=>!e.show||e.show(p.value))),p=e.computed(()=>({language:u.value,code:s.value,copy:o,copied:n.value,collapsed:l.value,toggleCollapse:i}));function h(t){if(!t.icon)return null;if("string"==typeof t.icon)return e.h("span",{class:"x-md-action-icon",innerHTML:t.icon});if("function"==typeof t.icon){try{const e=t.icon(p.value);if(e&&"object"==typeof e&&"__v_isVNode"in e)return e}catch{}return e.h(t.icon)}return e.h(t.icon)}return a({copy:o,copied:n,collapsed:l,toggleCollapse:i,syntaxCodeBlockRef:r}),(a,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["x-md-code-block",{"x-md-code-block--dark":c.isDark}])},[t.showCodeBlockHeader?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["x-md-code-header-wrapper",[{"x-md-code-header-wrapper--sticky":c.stickyCodeBlockHeader},{"x-md-code-header-wrapper--collapsed":l.value}]])},[e.createElementVNode("div",F,[e.renderSlot(a.$slots,"codeHeader",{language:u.value,code:s.value,copy:e.unref(o),copied:e.unref(n),collapsed:l.value,toggleCollapse:i},()=>[e.createElementVNode("div",X,[e.createElementVNode("button",{class:e.normalizeClass(["x-md-collapse-btn",{"x-md-collapse-btn--collapsed":l.value}]),onClick:i,title:l.value?"展开代码":"折叠代码"},[...d[1]||(d[1]=[e.createElementVNode("svg",{class:"x-md-collapse-icon",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("polyline",{points:"6 9 12 15 18 9"})],-1)])],10,U),e.createElementVNode("span",W,e.toDisplayString(u.value),1)]),e.createElementVNode("div",Y,[e.renderSlot(a.$slots,"codeActions",{code:s.value,copy:e.unref(o),copied:e.unref(n)},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m.value,t=>(e.openBlock(),e.createElementBlock("button",{key:t.key,class:e.normalizeClass(["x-md-action-btn",[t.class,{"x-md-action-btn--disabled":t.disabled}]]),style:e.normalizeStyle(t.style),title:t.title,disabled:t.disabled,onClick:e=>function(e){e.disabled||e.onClick?.(p.value)}(t)},[t.icon?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(h(t)),{key:0})):e.createCommentVNode("",!0)],14,G))),128)),e.createElementVNode("button",{class:e.normalizeClass(["x-md-copy-btn",{"x-md-copy-btn--copied":e.unref(n)}]),onClick:d[0]||(d[0]=t=>e.unref(o)(s.value))},[e.unref(n)?(e.openBlock(),e.createElementBlock("svg",K,[...d[2]||(d[2]=[e.createElementVNode("path",{fill:"currentColor",d:"M406.656 706.944 195.84 496.256a32 32 0 1 0-45.248 45.248l256 256 512-512a32 32 0 0 0-45.248-45.248L406.592 706.944z"},null,-1)])])):(e.openBlock(),e.createElementBlock("svg",Q,[...d[3]||(d[3]=[e.createElementVNode("path",{fill:"currentColor",d:"M768 832a128 128 0 0 1-128 128H192A128 128 0 0 1 64 832V384a128 128 0 0 1 128-128v64a64 64 0 0 0-64 64v448a64 64 0 0 0 64 64h448a64 64 0 0 0 64-64z"},null,-1),e.createElementVNode("path",{fill:"currentColor",d:"M384 128a64 64 0 0 0-64 64v448a64 64 0 0 0 64 64h448a64 64 0 0 0 64-64V192a64 64 0 0 0-64-64zm0-64h448a128 128 0 0 1 128 128v448a128 128 0 0 1-128 128H384a128 128 0 0 1-128-128V192A128 128 0 0 1 384 64"},null,-1)])]))],2)],!0)])],!0)])],2)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["x-md-code-body",{"x-md-code-body--collapsed":l.value}])},[e.createVNode(I,{ref_key:"syntaxCodeBlockRef",ref:r,code:s.value,language:u.value,"light-theme":c.lightTheme,"dark-theme":c.darkTheme,"is-dark":c.isDark,"color-replacements":c.colorReplacements,"code-max-height":c.codeMaxHeight,"enable-animate":c.enableAnimate},null,8,["code","language","light-theme","dark-theme","is-dark","color-replacements","code-max-height","enable-animate"])],2)],2))}}),[["__scopeId","data-v-8b0fb0b9"]]),J=q(e.defineComponent({__name:"index",props:{raw:{default:()=>({})},isDark:{type:Boolean,default:!1},shikiTheme:{default:()=>["vitesse-light","vitesse-dark"]},enableAnimate:{type:Boolean,default:!1}},setup(t){let a=null;e.onMounted(async()=>{const e=await Function("return import('@shikijs/core')")().catch(()=>({getTokenStyleObject:()=>({})}));a=e.getTokenStyleObject});const o=t,n=e.computed(()=>o.raw?.content??""),l=e.computed(()=>o.raw?.language||"ts"),r=e.computed(()=>o.isDark?o.shikiTheme[1]:o.shikiTheme[0]),{lines:i,preStyle:c}=H(n,{language:l,theme:r}),s=e.computed(()=>i.value.flat()),u=e.computed(()=>c.value||{}),d=e=>{const t={};return Object.entries(e).forEach(([e,a])=>{const o=e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());t[o]=a}),t},m=e=>{if(e.htmlStyle)return d(e.htmlStyle);if(!a)return{};const t=a(e);return d(t)};return(t,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["x-md-inline-code",{"x-md-inline-code--dark":o.isDark,"x-md-animated-word":o.enableAnimate}])},[e.createElementVNode("code",{style:e.normalizeStyle(u.value)},[s.value.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(s.value,(t,a)=>(e.openBlock(),e.createElementBlock("span",{key:a,style:e.normalizeStyle(m(t)),class:e.normalizeClass({"x-md-animated-word":o.enableAnimate})},e.toDisplayString(t.content),7))),128)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(n.value),1)],64))],4)],2))}}),[["__scopeId","data-v-97166d5b"]]),ee=e.defineAsyncComponent(()=>Promise.resolve().then(()=>require("./index-D9u8JldH.cjs"))),te=e.defineComponent({props:{raw:{type:Object,default:()=>({})},codeXRender:{type:Object,default:()=>({})},isDark:{type:Boolean,default:!1},shikiTheme:{type:Array,default:()=>["vitesse-light","vitesse-dark"]},showCodeBlockHeader:{type:Boolean,default:!0},stickyCodeBlockHeader:{type:Boolean,default:!0},codeMaxHeight:{type:String,default:void 0},enableAnimate:{type:Boolean,default:!1},codeBlockActions:{type:Array,default:void 0},mermaidActions:{type:Array,default:void 0},mermaidConfig:{type:Object,default:void 0}},setup(t,{slots:a}){const{codeXRender:o}=t;return()=>{if(t.raw.inline){if(o&&o.inline){const a=o.inline;return"function"==typeof a?a(t):e.h(a,t)}return e.h(J,{raw:t.raw,isDark:t.isDark,shikiTheme:t.shikiTheme,enableAnimate:t.enableAnimate})}const{language:n}=t.raw;if(o&&o[n]){const a=o[n];return"function"==typeof a?a(t):e.h(a,t)}if("mermaid"===n){const o={};return Object.keys(a).forEach(e=>{e.startsWith("mermaid")&&(o[e]=a[e])}),e.h(ee,{raw:t.raw,isDark:t.isDark,shikiTheme:t.shikiTheme,mermaidActions:t.mermaidActions,config:t.mermaidConfig},o)}return e.h(Z,{code:t.raw.content||"",language:t.raw.language||"text",isDark:t.isDark,lightTheme:t.shikiTheme[0],darkTheme:t.shikiTheme[1],showCodeBlockHeader:t.showCodeBlockHeader,stickyCodeBlockHeader:t.stickyCodeBlockHeader,codeMaxHeight:t.codeMaxHeight,enableAnimate:t.enableAnimate,codeBlockActions:t.codeBlockActions},a)}}});function ae(t){return{code:a=>e.h(te,{raw:a,codeXRender:t?.codeXRender,isDark:t?.isDark,shikiTheme:t?.shikiTheme,enableAnimate:t?.enableAnimate,showCodeBlockHeader:t?.showCodeBlockHeader,stickyCodeBlockHeader:t?.stickyCodeBlockHeader,codeMaxHeight:t?.codeMaxHeight,codeBlockActions:t?.codeBlockActions,mermaidActions:t?.mermaidActions,mermaidConfig:t?.mermaidConfig})}}function oe(e){if("string"!=typeof e)return e;const t=/```[\s\S]*?```/g,a=e.match(t)||[];let o=e.replace(t,"ELX_CODE_BLOCK_PLACEHOLDER");return o=p.flow([e=>e.replace(/\\\[(.*?)\\\]/g,(e,t)=>`$$${t}$$`),e=>e.replace(/\\\[([\s\S]*?)\\\]/g,(e,t)=>`$$${t}$$`),e=>e.replace(/\\\((.*?)\\\)/g,(e,t)=>`$$${t}$$`),e=>e.replace(/(^|[^\\])\$(.+?)\$/g,(e,t,a)=>`${t}$${a}$`)])(o),a.forEach(e=>{o=o.replace("ELX_CODE_BLOCK_PLACEHOLDER",e.replace(/\$/g,"_ELX_DOLLAR_"))}),o=o.replace(/_ELX_DOLLAR_/g,"$"),o}let ne=null,le=!1,re=null,ie=null;const ce=[];let se=!1;function ue(){return e=>{m.visit(e,"element",e=>{if(["p","h1","h2","h3","h4","h5","h6","li","strong","th","td"].includes(e.tagName)&&e.children){const t=[];for(const a of e.children)"text"===a.type?[...new Intl.Segmenter("zh",{granularity:"word"}).segment(a.value)].map(e=>e.segment).filter(Boolean).forEach(e=>{t.push({children:[{type:"text",value:e}],properties:{className:"x-md-animated-word"},tagName:"span",type:"element"})}):t.push(a);e.children=t}})}}function de(t){const{allowHtml:a,enableAnimate:o,enableLatex:n,enableBreaks:l,enableGfm:r,rehypePlugins:m,remarkPlugins:p,rehypePluginsAhead:h,remarkPluginsAhead:v}=e.toRefs(t);return{rehypePlugins:e.computed(()=>[...h.value,a.value&&c,n.value&&i,o.value&&ue,...m.value].filter(Boolean)),remarkPlugins:e.computed(()=>{const e=[n.value&&d,!1!==r.value&&[u,{singleTilde:!1}],l.value&&s].filter(Boolean);return[...v.value,...e,...p.value]})}}const me={light:"vitesse-light",dark:"vitesse-dark"},pe={markdown:{type:String,default:""},allowHtml:{type:Boolean,default:!1},enableLatex:{type:Boolean,default:!0},enableAnimate:{type:Boolean,default:!1},enableBreaks:{type:Boolean,default:!0},enableGfm:{type:Boolean,default:!0},isDark:{type:Boolean,default:!1},shikiTheme:{type:Array,default:()=>["vitesse-light","vitesse-dark"]},showCodeBlockHeader:{type:Boolean,default:!0},stickyCodeBlockHeader:{type:Boolean,default:!1},codeMaxHeight:{type:String,default:void 0},codeBlockActions:{type:Array,default:void 0},mermaidActions:{type:Array,default:void 0},mermaidConfig:{type:Object,default:void 0},codeXRender:{type:Object,default:()=>({})},customAttrs:{type:Object,default:()=>({})},remarkPlugins:{type:Array,default:()=>[]},remarkPluginsAhead:{type:Array,default:()=>[]},rehypePlugins:{type:Array,default:()=>[]},rehypePluginsAhead:{type:Array,default:()=>[]},rehypeOptions:{type:Object,default:()=>({})},sanitize:{type:Boolean,default:!1},sanitizeOptions:{type:Object,default:()=>({})}};function he(t,a){return e.defineComponent({name:t,props:pe,setup(t,{slots:o,attrs:n}){const{rehypePlugins:l,remarkPlugins:r}=de(t),i=ae(t),c=e.computed(()=>t.markdown),s=e.computed(()=>({markdown:c.value,customAttrs:t.customAttrs,remarkPlugins:e.toValue(r),rehypePlugins:e.toValue(l),rehypeOptions:t.rehypeOptions,sanitize:t.sanitize,sanitizeOptions:t.sanitizeOptions}));return()=>e.h("div",{class:["x-md-renderer",{"is-dark":t.isDark}],style:{backgroundColor:t.isDark?"#1e1e1e":"#ffffff",color:t.isDark?"#e5e5e5":"#333333",padding:"16px"},...n},e.h(a,{...s.value,class:"x-md-core"},{...i,...o}))}})}const ve=he("MarkdownRenderer",w),ge=he("MarkdownRendererAsync",x);exports.CodeBlock=Z,exports.MarkdownRenderer=ve,exports.MarkdownRendererAsync=ge,exports.VueMarkdown=w,exports.VueMarkdownAsync=x,exports.checkMermaidAvailable=async function(){return null!==re?re:ie||(ie=(async()=>{try{return await import("mermaid"),re=!0,!0}catch(e){return re=!1,!1}})(),ie)},exports.createProcessor=y,exports.downloadSvgAsPng=function(e){if(e)try{const t=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`,a=new Image;a.onload=()=>{try{const o=document.createElement("canvas"),n=o.getContext("2d",{willReadFrequently:!1});if(!n)return;const l=2;o.width=a.width*l,o.height=a.height*l,n.imageSmoothingEnabled=!0,n.imageSmoothingQuality="high",n.fillStyle="#ffffff",n.fillRect(0,0,o.width,o.height),n.drawImage(a,0,0,o.width,o.height);const r=(new Date).toISOString().slice(0,19).replace(/:/g,"-");try{o.toBlob(e=>{if(!e)return;const t=URL.createObjectURL(e),a=document.createElement("a");a.href=t,a.download=`mermaid-diagram-${r}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(t)},"image/png",.95)}catch(e){console.error("Failed to convert canvas to blob:",e);try{const e=o.toDataURL("image/png",.95),t=document.createElement("a");t.href=e,t.download=`mermaid-diagram-${r}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}catch(t){console.error("Failed to convert canvas to data URL:",t)}}}catch(o){console.error("Canvas operation failed:",o)}},a.onerror=e=>{console.error("Failed to load image:",e)},a.src=t}catch(t){console.error("Failed to download SVG:",t)}},exports.getVNodeInfos=g,exports.preprocessLaTeX=oe,exports.render=h,exports.renderChildren=v,exports.useClipboard=z,exports.useComponents=ae,exports.useHighlight=H,exports.useMarkdownProcessor=f,exports.useMermaid=function(t,a={}){const o=e.computed(()=>"object"==typeof a&&"value"in a?a.value:a),n=e.computed(()=>({suppressErrorRendering:!0,startOnLoad:!1,securityLevel:"loose",theme:o.value.theme||"default",...o.value.config||{}})),l=e.ref(""),r=e.ref(null),i=e.ref(!1);let c=!1;const s=p.throttle(()=>{const e="string"==typeof t?t:t.value;if(!e?.trim())return l.value="",r.value=null,void(i.value=!1);var a;i.value=!0,a=async()=>{if(!c)try{const t=await async function(){return"undefined"==typeof window?null:(ne||(ne=(async()=>{try{return(await import("mermaid")).default}catch{return le||(le=!0,console.log("%c[x-markdown]%c Mermaid 图表功能已降级为代码块显示","font-weight: bold; color: #9333ea;","color: #666;"),console.log("%c如需 Mermaid 图表渲染功能,请安装:","color: #666; font-weight: bold;"),console.log("%c pnpm add mermaid","color: #9333ea; font-family: monospace;"),console.log("%c安装后请重启开发服务器","color: #999; font-size: 12px;")),null}})()),ne)}();if(!t)return l.value=e,r.value=null,void(i.value=!1);if(t.initialize(n.value),!(await t.parse(e.trim())))return l.value="",r.value=new Error("Mermaid parse error: Invalid syntax"),void(i.value=!1);const a=`${o.value.id||"mermaid"}-${Math.random().toString(36).substring(2,11)}`,c=(()=>{const e=o.value.container;return e?"object"==typeof e&&"value"in e?e.value:e:null})();if(!c)return void(i.value=!1);const{svg:s}=await t.render(a,e,c);l.value=s,r.value=null,i.value=!1}catch(t){l.value="",r.value=t,i.value=!1}},ce.push(a),async function(){if(!se){for(se=!0;ce.length>0;){const t=ce.shift();if(t)try{await t()}catch(e){console.error("Mermaid render queue error:",e)}}se=!1}}()},100,{leading:!1,trailing:!0});return e.watch([()=>"string"==typeof t?t:t.value,()=>n.value],()=>{s()},{immediate:!0}),e.onUnmounted(()=>{c=!0}),{data:l,error:r,isLoading:i}},exports.useMermaidZoom=function(t){const{container:a}=t,o=e.ref(1),n=e.ref(0),l=e.ref(0),r=e.ref(!1);let i=null;const c=()=>a.value?.querySelector(".syntax-mermaid__content svg"),s=e=>{e.style.transformOrigin="center center",e.style.transform=`translate(${n.value}px, ${l.value}px) scale(${o.value})`},u=()=>{o.value=1,n.value=0,l.value=0,r.value=!1},d=()=>{i?.(),i=null,u()};return e.watch(()=>a.value,()=>{d(),u()}),e.onUnmounted(d),{zoomIn:()=>{const e=c();e&&(o.value=Math.min(o.value+.2,10),s(e))},zoomOut:()=>{const e=c();e&&(o.value=Math.max(o.value-.2,.1),s(e))},reset:()=>{const e=c();e&&(u(),s(e))},fullscreen:()=>{a.value&&(document.fullscreenElement?document.exitFullscreen():a.value.requestFullscreen?.())},destroy:d,initialize:()=>{if(!a.value)return;u(),i=(e=>{let t=0,a=0,i=!1;const u=(e,o)=>{r.value=!0,t=e-n.value,a=o-l.value,document.body.style.userSelect="none"},d=(e,o)=>{if(r.value&&i){n.value=e-t,l.value=o-a;const r=c();r&&s(r)}},m=()=>{r.value=!1,i=!1,document.body.style.userSelect=""},h=t=>{0===t.button&&(t.target===e||e.contains(t.target))&&(t.preventDefault(),i=!0,u(t.clientX,t.clientY))},v=e=>{i&&d(e.clientX,e.clientY)},g=p.throttle(t=>{const a=c();if(!a)return;const r=e.getBoundingClientRect(),i=a.getBoundingClientRect(),u=t.clientX-r.left,d=t.clientY-r.top,m=i.left-r.left+i.width/2,p=i.top-r.top+i.height/2,h=(u-m-n.value)/o.value,v=(d-p-l.value)/o.value,g=t.deltaY>0?-.05:.05,f=Math.min(Math.max(o.value+g,.1),10);f!==o.value&&(o.value=f,n.value=u-m-h*o.value,l.value=d-p-v*o.value,s(a))},20,{leading:!0,trailing:!0}),f=t=>{(t.target===e||e.contains(t.target))&&(t.preventDefault(),g(t))},y=t=>{(t.target===e||e.contains(t.target))&&1===t.touches.length&&(t.preventDefault(),i=!0,u(t.touches[0].clientX,t.touches[0].clientY))},k=e=>{i&&(e.preventDefault(),d(e.touches[0].clientX,e.touches[0].clientY))};return e.addEventListener("mousedown",h),document.addEventListener("mousemove",v),document.addEventListener("mouseup",m),e.addEventListener("wheel",f,{passive:!1}),e.addEventListener("touchstart",y,{passive:!1}),e.addEventListener("touchmove",k,{passive:!1}),document.addEventListener("touchend",m),()=>{e.removeEventListener("mousedown",h),document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",m),e.removeEventListener("wheel",f),e.removeEventListener("touchstart",y),e.removeEventListener("touchmove",k),document.removeEventListener("touchend",m),document.body.style.userSelect=""}})(a.value);const e=c();e&&s(e)}}},exports.usePlugins=de,exports.useProcessMarkdown=function(e){return oe(e)},exports.useTheme=function(t={}){const{lightTheme:a=me.light,darkTheme:o=me.dark}=t,n=e.ref(e.isRef(t.mode)?t.mode.value:t.mode||"auto"),l=e.computed({get:()=>e.isRef(t.mode)?t.mode.value:n.value,set:e=>{n.value=e}}),r=e.ref(!1);if("undefined"!=typeof window){const e=window.matchMedia("(prefers-color-scheme: dark)");r.value=e.matches,e.addEventListener("change",e=>{r.value=e.matches})}const i=e.computed(()=>"auto"===l.value?r.value:"dark"===l.value),c=e.computed(()=>(e.isRef(t.theme)?t.theme.value:t.theme)||(i.value?o:a));return{mode:l,isDark:i,actualTheme:c,setMode:e=>{n.value=e},toggleMode:()=>{const e=["light","dark","auto"],t=e.indexOf(l.value);n.value=e[(t+1)%e.length]}}};
|
|
2
|
+
//# sourceMappingURL=index-nZ5iH1aN.cjs.map
|