import{_ as H,r as p,ah as S,u as W,c as D,o as R,y as j,a as c,b as i,p as n,h as N,i as w,t as g,O as L,H as P,w as V,T as X,ai as Y,Q as z}from"./framework.BcrMLAmg.js";const A={class:"basalt-demo-wrapper"},I={class:"code-block-container"},F={class:"code-header"},K={class:"language-badge"},O=["disabled"],Q={key:0,class:"play-icon"},U={key:1,class:"loading-icon"},G={class:"button-text"},J={class:"code-block"},Z=["innerHTML"],ee={class:"terminal-title"},te={class:"terminal-body"},ne={key:0,class:"loading-overlay"},ae={__name:"BasaltDemoWithCode",props:{language:{type:String,default:"lua"},title:{type:String,default:"Basalt Demo"}},setup(f){const M=f,s=p(!1),m=p(null),T=p(null),o=S({x:100,y:100}),a=p(!1);let u={x:0,y:0},h=!1,r=null;const y=W();function b(e){return(e||[]).map(t=>t?typeof t=="string"?t:typeof t.children=="string"?t.children:Array.isArray(t.children)?b(t.children):"":"").join(`
`).replace(/\r\n/g,`
`).replace(/\n{3,}/g,`

`).trim()}const _=D(()=>{var e;return b(((e=y.default)==null?void 0:e.call(y))??[])}),$=D(()=>{let e=_.value;const t=["local","function","if","then","else","elseif","end","for","while","do","repeat","until","return","break","true","false","nil","and","or","not","require"],l=new RegExp(`\\b(${t.join("|")})\\b`,"g");return e=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),e=e.replace(l,'<span class="keyword">$1</span>'),e=e.replace(/"([^"]*)"/g,'<span class="string">"$1"</span>'),e=e.replace(/'([^']*)'/g,`<span class="string">'$1'</span>`),e=e.replace(/--(.*)$/gm,'<span class="comment">--$1</span>'),e=e.replace(/\b(\d+)\b/g,'<span class="number">$1</span>'),e=e.replace(/\b(basalt|main)\b/g,'<span class="variable">$1</span>'),e=e.replace(/(:?\w+)\(/g,'<span class="function">$1</span>('),e});async function q(){if(!(typeof window>"u")&&!(a.value||s.value)){a.value=!0;try{const e=await fetch("https://raw.githubusercontent.com/Pyroxenium/Basalt2/refs/heads/main/release/basalt.lua").then(t=>t.text());window.require||(await new Promise((t,l)=>{const d=document.createElement("script");d.src="https://copy-cat.squiddev.cc/require.js",d.onload=t,d.onerror=l,document.body.appendChild(d)}),window.require.config({paths:{copycat:"https://copy-cat.squiddev.cc/"}})),s.value=!0,x(),await z(),await new Promise(t=>setTimeout(t,200)),window.require(["copycat/embed"],t=>{if(!m.value){console.error("Container not found"),a.value=!1;return}r=t(m.value,{hdFont:"https://copy-cat.squiddev.cc/term_font_hd-0506b6efe5f7feae.png",files:{"startup.lua":_.value,"basalt.lua":e},label:M.title}),r.run(),setTimeout(()=>{a.value=!1},500)})}catch(e){console.error("Error starting demo:",e),a.value=!1,s.value=!1}}}function v(){if(r){try{r.shutdown()}catch(e){console.warn("Error shutting down:",e)}r=null}s.value=!1,a.value=!1}function x(){if(typeof window>"u")return;const e=window.innerWidth,t=window.innerHeight;o.x=Math.max(0,(e-650)/2),o.y=Math.max(0,(t-480)/2)}function B(e){typeof document>"u"||e.target.closest("button")||(h=!0,u.x=e.clientX-o.x,u.y=e.clientY-o.y,document.addEventListener("mousemove",k),document.addEventListener("mouseup",C),e.preventDefault())}function k(e){if(!h||typeof window>"u")return;const t=window.innerWidth-650,l=window.innerHeight-480;o.x=Math.max(0,Math.min(e.clientX-u.x,t)),o.y=Math.max(0,Math.min(e.clientY-u.y,l))}function C(){typeof document>"u"||(h=!1,document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",C))}function E(e){e.key==="Escape"&&s.value&&v()}return R(()=>{typeof document<"u"&&document.addEventListener("keydown",E)}),j(()=>{typeof document<"u"&&document.removeEventListener("keydown",E),v()}),(e,t)=>(i(),c("div",A,[n("div",I,[n("div",F,[n("span",K,g(f.language),1),n("button",{class:"run-button",onClick:q,disabled:a.value||s.value},[a.value?(i(),c("span",U,"⟳")):(i(),c("span",Q,"▶")),n("span",G,g(a.value?"Loading...":"Run"),1)],8,O)]),n("div",J,[n("pre",null,[n("code",{innerHTML:$.value},null,8,Z)])])]),typeof e.document<"u"?(i(),N(Y,{key:0,to:"body"},[s.value?(i(),c("div",{key:0,ref_key:"wrapperRef",ref:T,class:"terminal-window",style:L({top:o.y+"px",left:o.x+"px"})},[n("div",{class:"terminal-header",onMousedown:B},[n("div",ee,[t[0]||(t[0]=n("span",{class:"terminal-icon"},"💻",-1)),n("span",null,g(f.title),1)]),n("div",{class:"terminal-controls"},[n("button",{class:"control-button minimize",onClick:x,title:"Center"}," ⊡ "),n("button",{class:"control-button close",onClick:v,title:"Close (ESC)"}," ✕ ")])],32),n("div",te,[P(X,{name:"fade"},{default:V(()=>[a.value?(i(),c("div",ne,t[1]||(t[1]=[n("div",{class:"spinner"},null,-1),n("p",null,"Loading emulator...",-1)]))):w("",!0)]),_:1}),n("div",{ref_key:"container",ref:m,class:"terminal-container",style:L({opacity:a.value?0:1})},null,4)])],4)):w("",!0)])):w("",!0)]))}},se=H(ae,[["__scopeId","data-v-0f9f3cfb"]]);export{se as default};
