"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@tempots/dom"),A=require("../timer-BJHOsuS6.cjs"),B=require("../link-portal-_tiDFZqh.cjs"),I=require("../theme-DogY9oT1.cjs"),p="https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/",W=e=>{if(!e||typeof e!="object")return!1;const t=e;return!!(t.editor&&typeof t.editor.create=="function"&&t.languages)};function M(){if(typeof self>"u")return;const e=self.MonacoEnvironment;if(e&&(typeof e.getWorkerUrl=="function"||typeof e.getWorker=="function"))return;const t=()=>{const a=[`self.MonacoEnvironment = { baseUrl: '${p}' };`,`importScripts('${p}vs/base/worker/workerMain.js');`].join(`
`),i=new Blob([a],{type:"text/javascript"});return URL.createObjectURL(i)};self.MonacoEnvironment={getWorkerUrl(a,i){return t()}}}const F=e=>new Promise((t,a)=>{if(document.querySelector(`script[src="${e}"]`))return t();const r=document.createElement("script");r.src=e,r.async=!0;const l=document.querySelector("script[nonce]")?.getAttribute("nonce");l&&r.setAttribute("nonce",l),r.onload=()=>t(),r.onerror=h=>{console.error("[BeatUI] Failed to load script",e,h),a(new Error(`Failed to load script ${e}`))},document.head.appendChild(r)}),R=async()=>{const e=window;if((!e.require||!e.require.config)&&(await F(`${p}vs/loader.js`),await new Promise(t=>setTimeout(t,100)),!e.require))throw new Error("AMD loader failed to initialize");return e.require.config?.({baseUrl:p,paths:{vs:"vs"}}),e.require},$=async()=>{const e=window;if(e.monaco&&W(e.monaco))return e.monaco;M();const t=await R();if(await new Promise((a,i)=>{const r=setTimeout(()=>i(new Error("Timeout loading editor.main")),3e4);try{t(["vs/editor/editor.main"],()=>{clearTimeout(r),a()},l=>{clearTimeout(r),i(l)})}catch(l){clearTimeout(r),i(l)}}),!e.monaco)throw new Error("Monaco failed to initialize after loading editor.main");return e.monaco};let w=null;const v=new Map;let g=!1;async function S(){if(w)return w;!g&&typeof window<"u"&&(M(),g=!0);const e=await $();return w=e,e}async function _(e){if(v.has(e))return v.get(e);const t=(async()=>{const a=await S();switch(e){case"typescript":case"javascript":{a.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!1,noSyntaxValidation:!1}),a.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!1,noSyntaxValidation:!1});break}case"json":{a.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[],enableSchemaRequest:!0});break}case"css":case"scss":case"less":{a.css.cssDefaults.setOptions({validate:!0});break}case"html":break;case"markdown":break;case"yaml":{a.languages.getLanguages().some(r=>r.id==="yaml")||a.languages.register({id:"yaml",extensions:[".yml",".yaml"]});break}}})();return v.set(e,t),t}async function O(e){const[t]=await Promise.all([S(),_(e)]);return t}function z(e){if(typeof window>"u")return;const t=window;e?(t.MonacoEnvironment={getWorker:e},g=!0):t.MonacoEnvironment||(M(),g=!0)}const N=e=>{const{value:t,onChange:a,onBlur:i,language:r="plaintext",readOnly:l=!1,editorOptions:h,jsonSchemas:V,autofocus:j,class:q,disabled:D,hasError:x,id:C,name:L,placeholder:P}=e,b=o.Value.toSignal(l);return o.Use(I.Theme,({appearance:T})=>o.html.div((e.cssInjection??"none")==="none"?null:o.Task(()=>Promise.resolve().then(()=>require("../styles-url-BzPix7VR.cjs")),({default:u})=>B.LinkPortal({id:"beatui-monaco-css",href:u})),o.attr.class("bc-monaco-editor-container"),o.attr.class(q),o.attr.class(o.Value.map(x??!1,u=>u?"bc-input-container--error":"")),o.attr.id(C),o.attr.name(L),o.WithElement(u=>{let m=null;const c=[];return(async()=>{try{let d=function(){const n=s.getValue();a?.(n)};const f=o.Value.get(r)??"plaintext";if(m=(await O(f)).editor.create(u,{value:o.Value.get(t)??"",language:f,readOnly:o.Value.get(b)??!1,automaticLayout:!0,minimap:{enabled:!1},...h??{}}),!m)throw new Error("Failed to create Monaco editor");const s=m;c.push(o.effectOf(r,V)(async(n,y)=>{const E=await O(n);if(n==="json"){const U={validate:!0,enableSchemaRequest:!0,schemas:!!(y&&y.length)?y:[]};E.json.jsonDefaults.setDiagnosticsOptions(U)}const k=s.getModel();k&&E.editor.setModelLanguage(k,n)})),c.push(s.onDidChangeModelContent(A.x(500,d)).dispose),c.push(s.onDidBlurEditorText(()=>{d(),i?.()}).dispose),c.push(o.Value.on(t,n=>{n!==s.getValue()&&s.setValue(n??"")})),c.push(o.Value.on(b,n=>{s.updateOptions({readOnly:n??!1})})),c.push(o.Value.on(D??!1,n=>{s.updateOptions({readOnly:n??!1})})),c.push(o.Value.on(j??!1,n=>{n&&s.focus()})),c.push(o.Value.on(P??"",n=>{s.updateOptions({placeholder:n??""})})),c.push(T.on(n=>{s.updateOptions({theme:n==="dark"?"vs-dark":"vs"})}))}catch(d){console.error("[BeatUI] Failed to initialize Monaco editor:",d);const f=u;f.textContent="Failed to load Monaco Editor. Please ensure monaco-editor is installed."}})(),o.OnDispose(()=>{try{c.forEach(d=>d())}catch{}try{m?.dispose()}catch{}})})))};exports.MonacoEditorInput=N;exports.configureMonacoEnvironment=z;
