ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
2 lines (1 loc) • 3.79 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue"),d=require("../chunks/module-chunk.js"),X=require("ant-design-vue"),R=require("../_util/pick-attrs.js"),z=require("../_util/hooks/use-x-component-config.js");require("../x-provider/index.js");const h=require("./prism.js"),B=require("./style/index.js"),D=require("../x-provider/hooks/use-x-provider-context.js"),E=s.defineComponent({name:"AXCodeHighlighter",__name:"CodeHighlighter",props:{lang:null,children:null,header:null,prefixCls:null,rootClassName:null,className:null,class:null,style:null,highlightProps:null,classNames:{default:()=>({})},styles:{default:()=>({})},prismLightMode:{type:Boolean,default:!0}},setup(H,{expose:P}){const e=H,u=s.useSlots(),m=s.ref(null),i=s.ref(""),g=s.ref(""),V=s.computed(()=>R.default(e,{attr:!0,aria:!0,data:!0})),{getPrefixCls:L,direction:T}=D.default(),n=s.computed(()=>L("codeHighlighter",e.prefixCls)),l=z.default("codeHighlighter"),[j,q,S]=B.default(n),f=s.computed(()=>{var r;if(typeof e.children=="string")return e.children;const t=(r=u.default)==null?void 0:r.call(u);return t?(Array.isArray(t)?t:[t]).map(a=>{if(typeof a=="string"||typeof a=="number")return String(a);if(a&&typeof a=="object"&&"children"in a){const c=a.children;if(typeof c=="string"||typeof c=="number")return String(c)}return""}).join(""):""}),$=s.computed(()=>f.value.replace(/\n$/,""));s.watch([$,()=>e.lang,()=>e.prismLightMode],async([t,o,r])=>{if(!t||!o){i.value="",g.value="";return}i.value=h.escapeHtml(t);try{r===!1&&await h.ensureFullPrism();const a=await h.ensureLanguage(o);g.value=a,i.value=h.highlightCode(t,a)}catch{i.value=h.escapeHtml(t)}},{immediate:!0});const w=s.computed(()=>{var t;return d.classnames(n.value,l.value.className,e.className,e.class,e.rootClassName,(t=l.value.classNames)==null?void 0:t.root,e.classNames.root,q.value,S,{[`${n.value}-rtl`]:T.value==="rtl"})}),k=s.computed(()=>{var t;return{...typeof l.value.style=="object"?l.value.style:{},...typeof((t=l.value.styles)==null?void 0:t.root)=="object"?l.value.styles.root:{},...e.styles.root,...e.style}}),M=()=>{if(u.header)return u.header();if(e.header!==void 0){const t=typeof e.header=="function"?e.header():e.header;return t===!1||t===null?null:t}};return P({get nativeElement(){return m.value}}),()=>{var v,N,_,C,b,x;const t=f.value;if(!t)return null;if(!e.lang)return s.createVNode("code",null,[t]);const o=M();let r;o===null?r=null:o===void 0?r=s.createVNode("div",{class:d.classnames(`${n.value}-header`,(v=l.value.classNames)==null?void 0:v.header,e.classNames.header),style:{...typeof((N=l.value.styles)==null?void 0:N.header)=="object"?l.value.styles.header:{},...e.styles.header}},[s.createVNode("span",{class:d.classnames(`${n.value}-header-title`,e.classNames.headerTitle,(_=l.value.classNames)==null?void 0:_.headerTitle),style:{...typeof((C=l.value.styles)==null?void 0:C.headerTitle)=="object"?l.value.styles.headerTitle:{},...e.styles.headerTitle}},[e.lang]),s.createVNode(X.Typography.Text,{copyable:{text:t}},null)]):r=o;const{className:a,class:c,style:p,showLineNumbers:F,startingLineNumber:I,...A}=e.highlightProps||{},y=g.value?`language-${g.value}`:e.lang?`language-${e.lang}`:"";return j(s.createVNode("div",s.mergeProps(V.value,{ref:m,class:w.value,style:k.value}),[r,s.createVNode("div",{class:d.classnames(`${n.value}-code`,(b=l.value.classNames)==null?void 0:b.code,e.classNames.code),style:{...typeof((x=l.value.styles)==null?void 0:x.code)=="object"?l.value.styles.code:{},...e.styles.code}},[s.createVNode("pre",s.mergeProps(A,{class:d.classnames(y,a,c),style:{margin:0,...typeof p=="object"?p:{}}}),[s.createVNode("code",{class:y,style:{background:"transparent"},innerHTML:i.value},null)])])]))}}});exports.default=E;