(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.MagicCodeEditor={},c.Vue))})(this,function(c,e){"use strict";const k={key:0,class:"header"},C={class:"code-area"},w=["readonly","onKeydown"],T=["innerHTML"],R={style:{paddingTop:"6px",paddingLeft:"15px",paddingBottom:"6px"}},z={__name:"CodeEditor",props:e.mergeModels({text:{type:String,default:""},boxShadow:{type:String,default:"none"},backgroundColor:{type:String,default:"#0d1117"},borderRadius:{type:[Number,String],default:0},codeFontSize:{type:[Number,String],default:20},codeColor:{type:String,default:"white"},appendText:{type:String,default:null},appendLocation:{type:String,default:"top-right"},appendInline:{type:Boolean,default:!0},footerFontSize:{type:Number,default:15},paddingTop:{type:[Number,String],default:5},paddingBottom:{type:[Number,String],default:5},paddingLeft:{type:Number,default:15},highlight:{},headerText:{type:String,default:""},highlightGroups:{type:Array},highlightRow:{type:Boolean,default:!1},highlightRowBackgroundColor:{type:String,default:"rgba(112,112,112,0.05)"},highlightLineNumColor:{type:String},highlightLineNumBackgroundColor:{type:String,default:"rgba(112,112,112,0.05)"},highlightLineNumBorder:{type:String,default:"1px solid currentColor"},highlightLineNumWidth:{type:String,default:"0 0 0 0"},highlightLineNumOpacity:{type:Number,default:1},headerBackgroundColor:{type:[String,null],default:null},headerColor:{type:String,default:"white"},headerFontSize:{type:Number,default:15},footerBackgroundColor:{type:[String,null],default:null},readOnly:{type:Boolean,default:!1},maxLines:{type:[Number,String],default:-1},minLines:{type:[Number,String],default:null},lineNumberBorder:{type:String,default:"1px solid rgb(201, 209, 217, .3)"},lineNumberColor:{type:String,default:"rgb(201, 209, 217)"},lineNumberOpacity:{type:Number,default:.3},showHeader:{type:Boolean,default:!1},showFooter:{type:Boolean,default:!1},showBorderTop:{type:Boolean,default:!0},showLineNumber:{type:Boolean,default:!0},tabSpaces:{type:Number,default:2},prependInline:{type:Boolean,default:!0},prependText:{type:String,default:""},prependLocation:{type:String,default:"top-left"}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(t){e.useCssVars(o=>({"65c5184c":t.highlightLineNumColor,a30f5ae8:t.highlightLineNumBackgroundColor,"564282d6":t.highlightLineNumBorder,"63971b86":t.highlightLineNumWidth,"776efac2":t.highlightLineNumOpacity,"54136a6e":t.borderRadius}));function V(){return"xxxx-xxxx".replace(/[x]/g,o=>Math.floor(Math.random()*8).toString(8))}const m=V(),a={"top-left":{top:"10px",left:"10px"},center:{top:"50%",left:"50%",transform:"translate(-50%, -50%)"},"center-left":{top:"50%",left:"20px",transform:"translate(-50%, -50%)"},"center-right":{top:"50%",right:"0%",transform:"translate(-50%, -50%)"},"top-right":{top:"10px",right:"10px"},"bottom-left":{bottom:"10px",left:"10px"},"bottom-right":{bottom:"10px",right:"10px"}},n=t;let r=e.useModel(t,"modelValue");r.value||(r=e.ref(n.text));const u=e.ref(null),g=e.ref(null),E=e.ref(),s=e.ref(null),h=e.ref(n.paddingLeft),d=e.ref(1),H=e.computed(()=>{const o=r.value.split(` `).length-1;return on.showLineNumber&&g.value?g.value.offsetWidth:0),S=e.computed(()=>{if(g.value)return g.value.firstElementChild.offsetHeight});function M(){if(r.value){const o=u.value.selectionStart;return r.value.substring(0,o).split(` `).length}return 0}function F(o){return o.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function O(){if(!n.highlightRow)return;let o=M();o===0||o===d.value||(N(d.value),L(o))}function $(){n.highlightRow||N(d.value)}function N(o){const l=document.getElementById(m+"ln"+o);l&&(l.style.backgroundColor="",d.value=0)}function L(o,l){const i=document.getElementById(m+"ln"+o);i.style.backgroundColor=l||n.highlightRowBackgroundColor,d.value=o}function D(o,l){r.value=r.value.substring(0,l)+o+r.value.substring(l);const i=l+o.length;e.nextTick(()=>P(i))}function I(o){p.value=-o.target.scrollTop,b.value=-o.target.scrollLeft}function W(o){const l=u.value.selectionStart;D(" ".repeat(n.tabSpaces),l)}function P(o){u.value.setSelectionRange(o,o)}const y=e.computed(()=>n.minLines?S.value*n.minLines+1:-1),x=e.computed(()=>n.maxLines?S.value*n.maxLines+1:-1),A=e.computed(()=>{let o=r.value;n.highlight?o=n.highlight(o):o=F(o),o=o.split(` `);let l="",i=0;for(const B in o){i+=1;const q=o.length===1&&n.highlightRow?n.highlightRowBackgroundColor:"";l+=`
${o[B]!==""?o[B]:" "}
`}return l});return e.onMounted(()=>{if(n.prependInline&&s.value&&n.prependText&&(h.value=Number.parseInt(h.value)+Number.parseInt(s.value.offsetWidth)+5),n.highlightGroups)for(const o of n.highlightGroups)for(let l=o.from;l<=o.to;l++)L(l,o.color)}),(o,l)=>(e.openBlock(),e.createElementBlock("div",{class:"code-editor",style:e.normalizeStyle({padding:"0",background:t.backgroundColor,borderRadius:t.borderRadius+"px",boxShadow:t.boxShadow})},[t.showHeader?(e.openBlock(),e.createElementBlock("div",k,[e.renderSlot(o.$slots,"header",{},()=>[e.createElementVNode("div",{style:e.normalizeStyle({borderRadius:t.borderRadius+"px "+t.borderRadius+"px 0 0",paddingTop:"6px",paddingLeft:"15px",paddingBottom:"6px",color:t.headerColor,backgroundColor:t.headerBackgroundColor?t.headerBackgroundColor:t.backgroundColor,fontSize:t.headerFontSize+"px"})},[e.renderSlot(o.$slots,"headerText",{},()=>[e.createTextVNode(e.toDisplayString(t.headerText),1)])],4)])])):e.createCommentVNode("",!0),e.createElementVNode("div",{style:e.normalizeStyle({borderTop:t.showHeader&&t.showBorderTop?"1px solid rgba(201, 209, 217, .4)":"",borderBottom:t.showFooter?"1px solid rgba(201, 209, 217, .4)":"",minHeight:y.value+"px",maxWidth:"auto",maxHeight:x.value+"px"})},[e.createElementVNode("div",C,[t.showLineNumber?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"lineNumbersRef",ref:g,class:"line-nums",style:e.normalizeStyle({borderRight:t.lineNumberBorder,color:t.lineNumberColor,fontSize:t.codeFontSize+"px",paddingTop:t.paddingTop+"px",paddingBottom:t.paddingBottom+"px",top:p.value+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(H.value+1,i=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(i===d.value&&n.highlightRow?"line-highlight":"")},[e.createElementVNode("div",{style:e.normalizeStyle({paddingRight:"8px",paddingLeft:"8px",opacity:i===d.value&&n.highlightRow?n.HighlightLineNumOpacity:n.lineNumberOpacity})},e.toDisplayString(i),5)],2))),256))],4)):e.createCommentVNode("",!0),t.readOnly?e.createCommentVNode("",!0):e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{key:1,"onUpdate:modelValue":l[0]||(l[0]=i=>e.isRef(r)?r.value=i:r=i),ref_key:"textAreaRef",ref:u,spellcheck:"false",autofocus:!0,readonly:t.readOnly,onScroll:I,onSelectionchange:O,onFocusout:$,onKeydown:e.withKeys(e.withModifiers(W,["prevent","stop"]),["tab"]),style:e.normalizeStyle({marginTop:"0",paddingLeft:h.value+"px",paddingTop:t.paddingTop+"px",marginLeft:f.value+"px",width:t.showLineNumber?"calc(100% - "+f.value+"px)":"100%",fontSize:t.codeFontSize+"px",maxHeight:x.value+"px",minHeight:y.value+"px",caretShape:"20px"})},null,44,w)),[[e.vModelText,e.unref(r)]]),e.createElementVNode("pre",{style:e.normalizeStyle({marginLeft:f.value+"px",width:t.showLineNumber?"calc(100% - "+f.value+"px)":"100%",paddingLeft:h.value+"px",paddingTop:t.paddingTop+"px",paddingRight:"20px",paddingBottom:t.paddingBottom+"px",maxHeight:x.value+"px",minHeight:y.value+"px"})},[e.createTextVNode(" "),e.createElementVNode("code",{ref_key:"codeRef",ref:E,style:e.normalizeStyle({top:p.value+"px",left:b.value+"px",fontSize:t.codeFontSize+"px",color:t.codeColor})},[e.createElementVNode("span",{innerHTML:A.value,style:e.normalizeStyle({color:t.codeColor,display:"inline"})},null,12,T)],4),e.createTextVNode(` `)],4),t.prependText||t.prependLocation?(e.openBlock(),e.createElementBlock("div",{key:2,ref_key:"prependRef",ref:s,style:e.normalizeStyle({position:"absolute","z-index":3,top:a[t.prependLocation].top,bottom:a[t.prependLocation].bottom,left:a[t.prependLocation].left,right:a[t.prependLocation].right,transform:a[t.prependLocation].transform,color:"white"})},[e.renderSlot(o.$slots,"prependText",{},()=>[e.createTextVNode(e.toDisplayString(t.prependText),1)])],4)):e.createCommentVNode("",!0),t.appendText||t.appendLocation?(e.openBlock(),e.createElementBlock("div",{key:3,id:"extra_stuff",style:e.normalizeStyle({position:"absolute","z-index":3,top:a[t.appendLocation].top,bottom:a[t.appendLocation].bottom,left:a[t.appendLocation].left,right:a[t.appendLocation].right,transform:a[t.appendLocation].transform,color:"white"})},[e.renderSlot(o.$slots,"appendText",{},()=>[e.createTextVNode(e.toDisplayString(t.appendText),1)])],4)):e.createCommentVNode("",!0)])],4),e.renderSlot(o.$slots,"footer",{},()=>[t.showFooter?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass({border:t.showLineNumber}),style:e.normalizeStyle({borderBottomLeftRadius:t.borderRadius+"px",borderBottomRightRadius:t.borderRadius+"px",color:"#c9d1d9",backgroundColor:t.footerBackgroundColor?t.footerBackgroundColor:t.backgroundColor,fontSize:t.footerFontSize+"px"})},[e.createElementVNode("div",R,[e.renderSlot(o.$slots,"footer-text",{},()=>[e.createTextVNode(" Line: "+e.toDisplayString(d.value)+" - "+e.toDisplayString(e.unref(r).length)+" char(s) ",1)])])],6)):e.createCommentVNode("",!0)])],4))}};c.CodeEditor=z,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});