import{y as F,s as S,z as M,aK as H,ae as g,aL as y,ag as j,r as N,aM as P,aN as I}from"./index-09e73aa7.js";var T=Object.defineProperty,z=Object.defineProperties,W=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,b=(e,t,a)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,h=(e,t)=>{for(var a in t||(t={}))A.call(t,a)&&b(e,a,t[a]);if(V)for(var a of V(t))B.call(t,a)&&b(e,a,t[a]);return e},K=(e,t)=>z(e,W(t));const _={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}};function q(e,t){const a=M(()=>{const{width:r,height:i}=e;return K(h({},_.wrapper),{width:r,height:i})}),l=M(()=>h(h({},_.fullWidth),!t.value&&_.hide));return{wrapperStyle:a,containerStyle:l}}function G(){const e=S(P.__getMonacoInstance()),t=N(!1);let a;return j(()=>{e.value||(a=P.init(),a.then(r=>e.value=r).catch(r=>{(r==null?void 0:r.type)!=="cancelation"&&(t.value=!0,console.error("Monaco initialization error:",r))}))}),{monacoRef:e,unload:()=>a==null?void 0:a.cancel(),isLoadFailed:t}}function $(e){return typeof e=="function"?e():e}function m(e){return e===void 0}function L(e,t,a,l){return J(e,l)||Q(e,t,a,l)}function J(e,t){return e.editor.getModel(k(e,t))}function Q(e,t,a,l){return e.editor.createModel(t,a,l?k(e,l):void 0)}function k(e,t){return e.Uri.parse(t)}var X=Object.defineProperty,E=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,C=(e,t,a)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,R=(e,t)=>{for(var a in t||(t={}))Y.call(t,a)&&C(e,a,t[a]);if(E)for(var a of E(t))Z.call(t,a)&&C(e,a,t[a]);return e};const ee={display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"};var ne=F({name:"VueMonacoEditor",model:{prop:"value",event:"update:value"},props:{defaultValue:String,defaultPath:String,defaultLanguage:String,value:String,language:String,path:String,theme:{type:String,default:"vs"},line:Number,options:{type:Object,default:()=>({})},overrideServices:{type:Object,default:()=>({})},saveViewState:{type:Boolean,default:!0},width:{type:[Number,String],default:"100%"},height:{type:[Number,String],default:"100%"},className:String},emits:["update:value","beforeMount","mount","change","validate"],setup(e,t){const a=new Map,l=S(null),{monacoRef:r,unload:i,isLoadFailed:o}=G(),{editorRef:n}=te(t,e,r,l),{disposeValidator:v}=ae(t,e,r,n),s=M(()=>!!r.value&&!!n.value),{wrapperStyle:d,containerStyle:O}=q(e,s);return H(()=>{var u,c;(u=v.value)==null||u.call(v),n.value?((c=n.value.getModel())==null||c.dispose(),n.value.dispose()):i()}),g([()=>e.path,()=>e.value,()=>e.language,()=>e.line],([u,c,p,f],[w,re,U,x])=>{if(s.value){if(u!==w){const D=L(r.value,c||e.defaultValue||"",p||e.defaultLanguage||"",u||e.defaultPath||"");e.saveViewState&&a.set(w,n.value.saveViewState()),n.value.setModel(D),e.saveViewState&&n.value.restoreViewState(a.get(u)),m(f)||n.value.revealLine(f);return}n.value.getValue()!==c&&n.value.setValue(c),p!==U&&r.value.editor.setModelLanguage(n.value.getModel(),p),!m(f)&&f!==x&&n.value.revealLine(f)}}),g(()=>e.options,u=>n.value&&n.value.updateOptions(u),{deep:!0}),g(()=>e.theme,u=>r.value&&r.value.editor.setTheme(u)),{containerRef:l,isEditorReady:s,isLoadFailed:o,wrapperStyle:d,containerStyle:O}},render(){const{$slots:e,isEditorReady:t,isLoadFailed:a,wrapperStyle:l,containerStyle:r,className:i}=this;return y("div",{style:l},[!t&&y("div",{style:ee},a?e.failure?$(e.failure):"load failed":e.default?$(e.default):"loading..."),y("div",{ref:"containerRef",key:"monaco_editor_container",style:r,class:i})])}});function te({emit:e},t,a,l){const r=S(null);j(()=>{const o=g(a,()=>{l.value&&a.value&&(I(()=>o()),i())},{immediate:!0})});function i(){var o;if(!l.value||!a.value||r.value)return;e("beforeMount",a.value);const n=t.path||t.defaultPath,v=L(a.value,t.value||t.defaultValue||"",t.language||t.defaultLanguage||"",n||"");r.value=a.value.editor.create(l.value,R({model:v,theme:t.theme,automaticLayout:!0,autoIndent:"brackets",formatOnPaste:!0,formatOnType:!0},t.options),t.overrideServices),(o=r.value)==null||o.onDidChangeModelContent(s=>{const d=r.value.getValue();d!==t.value&&(e("update:value",d),e("change",d,s))}),r.value&&!m(t.line)&&r.value.revealLine(t.line),e("mount",r.value,a.value)}return{editorRef:r}}function ae({emit:e},t,a,l){const r=N(null),i=g([a,l],()=>{if(a.value&&l.value){I(()=>i());const o=a.value.editor.onDidChangeMarkers(n=>{var v,s;const d=(s=(v=l.value)==null?void 0:v.getModel())==null?void 0:s.uri;if(d&&n.find(u=>u.path===d.path)){const u=a.value.editor.getModelMarkers({resource:d});e("validate",u)}});r.value=()=>o==null?void 0:o.dispose()}});return{disposeValidator:r}}export{ne as V};
