import{a as ht,c as Pn,e as bt}from"./chunk-CUDJ3URY.mjs";import{d as vt,e as xt}from"./chunk-NYD5OPKW.mjs";import{$ as La,A as $n,B as rt,C as ct,D as lt,E as Ha,O as pt,P as K,V as Wa,X as pe,Z as ut,_ as Ja,a as On,aa as Fn,b as Ma,ba as Dn,g as at,h as nt,i as P,j as An,ja as dt,k as it,ka as mt,la as ft,m as fa,n as va,na as ia,o as qa,oa as ue,q as tt,r as ot,u as Nn,w as Ve,x as In,y as st,z as ke}from"./chunk-D72JGZ2L.mjs";import{B as Ua,C as Xi,D as Rn,F as je,I as Qi,R as et,e as Ki}from"./chunk-6AR4JB4E.mjs";import{C as Va,D as F,E as $e,a as Yi,g as ja,h as Ln,j as Ea,o as Ye,p as _a,r as le,s as Ta,t as Zi,w as ma,y as te,z as ge}from"./chunk-SBD5A77L.mjs";import{b as ce,c as R,d as be}from"./chunk-XNQNUANK.mjs";function kt(e,a){if(a.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function cr(e,a){return a.get?a.get.call(e):a.value}function lr(e,a,n){if(a.set)a.set.call(e,n);else{if(!a.writable)throw new TypeError("attempted to set read only private field");a.value=n}}function St(e,a,n){if(!a.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return a.get(e)}function Ga(e,a){var n=St(e,a,"get");return cr(e,n)}function pr(e,a,n){kt(e,a),a.set(e,n)}function ur(e,a,n){var i=St(e,a,"set");return lr(e,i,n),n}function zn(e,a,n){if(!a.has(e))throw new TypeError("attempted to get private field on non-instance");return n}function dr(e,a){kt(e,a),a.add(e)}function ne(e,a,n){return a in e?Object.defineProperty(e,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[a]=n,e}var mr=Object.create,Vn=Object.defineProperty,fr=Object.getOwnPropertyDescriptor,Ct=Object.getOwnPropertyNames,vr=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty,hr=(e,a,n)=>a in e?Vn(e,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[a]=n,Fe=(e,a)=>function(){return a||(0,e[Ct(e)[0]])((a={exports:{}}).exports,a),a.exports},br=(e,a,n,i)=>{if(a&&typeof a=="object"||typeof a=="function")for(let o of Ct(a))!xr.call(e,o)&&o!==n&&Vn(e,o,{get:()=>a[o],enumerable:!(i=fr(a,o))||i.enumerable});return e},xa=(e,a,n)=>(n=e!=null?mr(vr(e)):{},br(a||!e||!e.__esModule?Vn(n,"default",{value:e,enumerable:!0}):n,e)),gr=(e,a,n)=>(hr(e,typeof a!="symbol"?a+"":a,n),n),Un=(e,a,n)=>{if(!a.has(e))throw TypeError("Cannot "+n)},Ee=(e,a,n)=>(Un(e,a,"read from private field"),n?n.call(e):a.get(e)),ta=(e,a,n)=>{if(a.has(e))throw TypeError("Cannot add the same private member more than once");a instanceof WeakSet?a.add(e):a.set(e,n)},Ra=(e,a,n,i)=>(Un(e,a,"write to private field"),i?i.call(e,n):a.set(e,n),n),Ae=(e,a,n)=>(Un(e,a,"access private method"),n),yr=Fe({"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/pad.js"(e,a){a.exports=function(i,o){var t="000000000"+i;return t.substr(t.length-o)}}}),wr=Fe({"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/fingerprint.browser.js"(e,a){a.exports=function(){return Math.random().toString(16).slice(2)}}}),kr=Fe({"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/getRandomValue.browser.js"(e,a){var n,i=typeof R<"u"&&(R.crypto||R.msCrypto)||typeof self<"u"&&self.crypto;i?(o=Math.pow(2,32)-1,n=function(){return Math.abs(i.getRandomValues(new Uint32Array(1))[0]/o)}):n=Math.random;var o;a.exports=n}}),jt=Fe({"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/index.js"(e,a){var n=wr(),i=yr(),o=kr(),t=0,s=4,c=36,l=Math.pow(c,s);function r(){return i((o()*l<<0).toString(c),s)}function p(){return t=t=7&&b<=10},d.fingerprint=n,a.exports=d}}),Et=Fe({"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/createDeferredExecutor.js"(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createDeferredExecutor=void 0;function a(){let n=(i,o)=>{n.state="pending",n.resolve=t=>{if(n.state!=="pending")return;n.result=t;let s=c=>(n.state="fulfilled",c);return i(t instanceof Promise?t:Promise.resolve(t).then(s))},n.reject=t=>{if(n.state==="pending")return queueMicrotask(()=>{n.state="rejected"}),o(n.rejectionReason=t)}};return n}e.createDeferredExecutor=a}}),Sr=Fe({"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/DeferredPromise.js"(e){"use strict";var a,n,i;Object.defineProperty(e,"__esModule",{value:!0}),e.DeferredPromise=void 0;var o=Et(),t=(a=new WeakMap,n=new WeakSet,i=class extends Promise{get state(){return Ga(this,a).state}get rejectionReason(){return Ga(this,a).rejectionReason}then(c,l){return zn(this,n,s).call(this,super.then(c,l))}catch(c){return zn(this,n,s).call(this,super.catch(c))}finally(c){return zn(this,n,s).call(this,super.finally(c))}constructor(c=null){let l=(0,o.createDeferredExecutor)();super((r,p)=>{l(r,p),c?.(l.resolve,l.reject)}),dr(this,n),pr(this,a,{writable:!0,value:void 0}),ne(this,"resolve",void 0),ne(this,"reject",void 0),ur(this,a,l),this.resolve=Ga(this,a).resolve,this.reject=Ga(this,a).reject}},i);e.DeferredPromise=t;function s(c){return Object.defineProperties(c,{resolve:{configurable:!0,value:this.resolve},reject:{configurable:!0,value:this.reject}})}}}),qn=Fe({"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/index.js"(e){"use strict";var a=e&&e.__createBinding||(Object.create?function(i,o,t,s){s===void 0&&(s=t);var c=Object.getOwnPropertyDescriptor(o,t);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[t]}}),Object.defineProperty(i,s,c)}:function(i,o,t,s){s===void 0&&(s=t),i[s]=o[t]}),n=e&&e.__exportStar||function(i,o){for(var t in i)t!=="default"&&!Object.prototype.hasOwnProperty.call(o,t)&&a(o,i,t)};Object.defineProperty(e,"__esModule",{value:!0}),n(Et(),e),n(Sr(),e)}}),_t=Fe({"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/MemoryLeakError.js"(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MemoryLeakError=void 0;var a=class extends Error{constructor(n,i,o){super(`Possible EventEmitter memory leak detected. ${o} ${i.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`),ne(this,"emitter",void 0),ne(this,"type",void 0),ne(this,"count",void 0),this.emitter=n,this.type=i,this.count=o,this.name="MaxListenersExceededWarning"}};e.MemoryLeakError=a}}),Cr=Fe({"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/Emitter.js"(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Emitter=void 0;var a=_t(),n,i,o,t,s,c,l,r,p,d,u,v=class{static listenerCount(h,y){return h.listenerCount(y)}setMaxListeners(h){return Ra(this,i,h),this}getMaxListeners(){return Ee(this,i)}eventNames(){return Array.from(Ee(this,n).keys())}emit(h,...y){let x=Ae(this,t,s).call(this,h);return x.forEach(m=>{m.apply(this,y)}),x.length>0}addListener(h,y){Ae(this,d,u).call(this,"newListener",h,y);let x=Ae(this,t,s).call(this,h).concat(y);if(Ee(this,n).set(h,x),Ee(this,i)>0&&this.listenerCount(h)>Ee(this,i)&&!Ee(this,o)){Ra(this,o,!0);let m=new a.MemoryLeakError(this,h,this.listenerCount(h));console.warn(m)}return this}on(h,y){return this.addListener(h,y)}once(h,y){return this.addListener(h,Ae(this,r,p).call(this,h,y))}prependListener(h,y){let x=Ae(this,t,s).call(this,h);if(x.length>0){let m=[y].concat(x);Ee(this,n).set(h,m)}else Ee(this,n).set(h,x.concat(y));return this}prependOnceListener(h,y){return this.prependListener(h,Ae(this,r,p).call(this,h,y))}removeListener(h,y){let x=Ae(this,t,s).call(this,h);return x.length>0&&(Ae(this,c,l).call(this,x,y),Ee(this,n).set(h,x),Ae(this,d,u).call(this,"removeListener",h,y)),this}off(h,y){return this.removeListener(h,y)}removeAllListeners(h){return h?Ee(this,n).delete(h):Ee(this,n).clear(),this}listeners(h){return Array.from(Ae(this,t,s).call(this,h))}listenerCount(h){return Ae(this,t,s).call(this,h).length}rawListeners(h){return this.listeners(h)}constructor(){ta(this,t),ta(this,c),ta(this,r),ta(this,d),ta(this,n,void 0),ta(this,i,void 0),ta(this,o,void 0),Ra(this,n,new Map),Ra(this,i,v.defaultMaxListeners),Ra(this,o,!1)}},b=v;n=new WeakMap,i=new WeakMap,o=new WeakMap,t=new WeakSet,s=function(h){return Ee(this,n).get(h)||[]},c=new WeakSet,l=function(h,y){let x=h.indexOf(y);return x>-1&&h.splice(x,1),[]},r=new WeakSet,p=function(h,y){let x=(...m)=>{this.removeListener(h,x),y.apply(this,m)};return x},d=new WeakSet,u=function(h,y,x){this.emit(h,y,x)},gr(b,"defaultMaxListeners",10),e.Emitter=b}}),jr=Fe({"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/index.js"(e){"use strict";var a=e&&e.__createBinding||(Object.create?function(i,o,t,s){s===void 0&&(s=t);var c=Object.getOwnPropertyDescriptor(o,t);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[t]}}),Object.defineProperty(i,s,c)}:function(i,o,t,s){s===void 0&&(s=t),i[s]=o[t]}),n=e&&e.__exportStar||function(i,o){for(var t in i)t!=="default"&&!Object.prototype.hasOwnProperty.call(o,t)&&a(o,i,t)};Object.defineProperty(e,"__esModule",{value:!0}),n(Cr(),e),n(_t(),e)}}),Er=xa(jt()),_r=/(%?)(%([sdjo]))/g;function Tr(e,a){switch(a){case"s":return e;case"d":case"i":return Number(e);case"j":return JSON.stringify(e);case"o":{if(typeof e=="string")return e;let n=JSON.stringify(e);return n==="{}"||n==="[]"||/^\[object .+?\]$/.test(n)?e:n}}}function Se(e,...a){if(a.length===0)return e;let n=0,i=e.replace(_r,(o,t,s,c)=>{let l=a[n],r=Tr(l,c);return t?o:(n++,r)});return n{if(!e)throw new Rr(a,...n)};Ue.as=(e,a,n,...i)=>{if(!a)throw e.prototype.name!=null?new e(Se(n,i)):e(Se(n,i))};var Bn=xa(qn()),Or=void 0,Ar="\x1B[0m",Nr="\x1B[32;1m",Ir="\x1B[31m",$r="\x1B[34m",Fr="\x1B[33;1m",Dr="\x1B[35;1m",gt="\x1B[36;1m",Pr={preview:Fr,emulator:Dr,runtime:gt,bridge:$r,"runtime:worker":gt};function Tt(e){return function(n,...i){if(Or==="true"){let o=()=>n.includes("sender")?`${Nr}sender`:n.includes("receiver")?`${Ir}receiver`:"",t=n.replace(/\[.+\]:/,"");console.debug(`${Pr[e]}${e}:${o()}${Ar}:${t}`,...i)}}}var Ze=Tt("emulator");var zr=class{async handshake(){let e=new Bn.DeferredPromise;await this.receiverReadyPromise,Ze("[message-sender]: sending handshake"),this.target.postMessage({type:"internal/handshake"},"*",[this.channel.port2]),this.on("internal/handshake/done",()=>{e.resolve(),clearTimeout(a)});let a=setTimeout(()=>{e.reject(new Error("MessageSender: Handshake timeout"))},5e3);return e}on(e,a,n){Ze('[message-sender]: add listener "%s"',e),this.emitter.addEventListener(e,i=>{i instanceof MessageEvent&&a(i)},n)}off(e,a,n){this.emitter.removeEventListener(e,a,n)}async send(e,...a){let n=new Bn.DeferredPromise,i=(0,Er.default)(),o=a[0]||{};Ze('[message-sender]: send "%s" (%s)',e,i,o),this.receiverPort.postMessage({type:e,payload:{operationId:i,payload:o}}),Ze('[message-sender]: adding done listener for "%s" (%s)',e,i);let t=c=>{let{data:l}=c;if(l.operationId===i){let r=l.listenerPayload||{};Ze('[message-sender]: resolving "%s (%s) promise!',e,i),n.resolve({...r,operationId:l.operationId})}},s=c=>{let{data:l}=c;l.operationId===i&&(Ze('[message-sender]: rejecting "%s (%s) promise!',e,i),n.reject(l.error))};return this.on("internal/operation/done",t),this.on("internal/operation/failed",s),n.finally(()=>{this.emitter.removeEventListener("internal/operation/done",t),this.emitter.removeEventListener("internal/operation/failed",s)})}constructor(e){ne(this,"emitter",void 0),ne(this,"channel",void 0),ne(this,"receiverPort",void 0),ne(this,"receiverReadyPromise",void 0),this.target=e,this.emitter=new EventTarget,this.channel=new MessageChannel,this.receiverPort=this.channel.port1;let a=new Bn.DeferredPromise,n=i=>{i.data.type==="internal/ready"&&(Ze("[message-sender]: runtime is ready"),a.resolve())};R.addEventListener("message",n),a.then(()=>{R.removeEventListener("message",n)}),this.receiverReadyPromise=a,this.receiverPort.onmessage=i=>{let o=i.data;o.type!=null&&(Ze('[message-sender]: emitting "%s" event...',o.type,o.payload),this.emitter.dispatchEvent(new MessageEvent(o.type,{data:o.payload})))}}},yt=xa(qn()),Br=xa(jt()),Vr=class{async init(e){await this.channel.send("fs/init",{files:e})}async readFile(e,a){let n=await this.channel.send("fs/readFile",{path:e,encoding:a}).catch(i=>{throw new Error(Se('Failed to read file at path "%s"',e),{cause:i})});if(!n)throw new Error("File not found");return n.data}async writeFile(e,a,n){let i,o=!1;typeof n=="object"?(i=n.encoding,o=!!n.recursive):typeof n=="string"&&(i=n),await this.channel.send("fs/writeFile",{path:e,content:a,encoding:i,recursive:o}).catch(t=>{throw new Error(Se('Failed to write file at path "%s"',e),{cause:t})})}async readdir(e){let a=await this.channel.send("fs/readdir",{path:e}).catch(n=>{throw new Error(Se('Failed to read directory at path "%s"',e),{cause:n})});if(!a)throw new Error("Directory not found");return a.data}async mkdir(e,a){let n=!!a?.recursive;await this.channel.send("fs/mkdir",{path:e,recursive:n}).catch(i=>{throw new Error(Se('Failed to make directory at path "%s"',e),{cause:i})})}async stat(e){let a=await this.channel.send("fs/stat",{path:e}).catch(n=>{throw new Error(Se('Failed to stat file at path "%s"',e),{cause:n})});if(!a)throw new Error("File not found");return a.data}async rm(e,a){let{force:n,recursive:i}=a||{};await this.channel.send("fs/rm",{path:e,force:n,recursive:i}).catch(o=>{throw new Error(Se('Failed to remove file at path "%s"',e),{cause:o})})}async watch(e,a,n){let i=(0,Br.default)();return await this.channel.send("fs/watch",{watcherId:i,includes:e,excludes:a}),this.channel.on("fs/watch-event",({data:o})=>{if(o.watcherId===i&&n){let t={...o};delete t.watcherId,n(t)}}),{dispose:()=>this.channel.send("fs/unwatch",{watcherId:i})}}constructor(e){this.channel=e}},wt=xa(jr()),Ur=class{create(){return new qr(this.channel)}constructor(e){this.channel=e}},qr=class{forwardStdEvents(){this.channel.on("worker/tty",e=>{let{data:a}=e;if(a.workerId===this.id)switch(a.payload.type){case"out":{this.stdout.emit("data",a.payload.data);break}case"err":{this.stderr.emit("data",a.payload.data);break}}})}async runCommand(e,a,n={}){Ue(!this.id,'Failed to run "runCommand" on a ShellProcess: there is already a process running.');let i=await this.channel.send("shell/runCommand",{command:e,args:a,options:n});return Ue(i,'Failed to run "runCommand" on a ShellProcess: was not able to retrieve a running process.'),this.id=i.id,this.state="running",i}async on(e,a){switch(e){case"progress":{this.channel.on("worker/progress",({data:n})=>{a(n.status)});return}case"exit":{this.channel.on("worker/exit",({data:n})=>{n.workerId===this.id&&a(n.exitCode,n.error)});return}}}async kill(){Ue(this.id,'Failed to run "kill" on a ShellProcess: there is no process running. Did you forget to run it?'),this.state="idle",await this.channel.send("shell/exit",{id:this.id}).catch(e=>{throw new Error(Se('Failed to kill shell with ID "%s"',this.id),{cause:e})}),this.id=void 0}constructor(e){ne(this,"id",void 0),ne(this,"state",void 0),ne(this,"stdout",void 0),ne(this,"stderr",void 0),ne(this,"stdin",void 0),this.channel=e,this.state="running",this.stdout=new wt.Emitter,this.stderr=new wt.Emitter,this.stdin={write:a=>{if(!this.id)throw new Error("Failed to write to stdin, no process is currently running");return this.channel.send("shell/stdin",{data:a,workerId:this.id})}},this.forwardStdEvents()}},Hr=xa(qn()),Wr=2e4,Jr=class{async waitFor(e,a,n=Wr){let i=new Hr.DeferredPromise,o=setTimeout(()=>{i.reject()},n),t=await this.channel.send("preview/get/info",e).catch(c=>{i.reject(new Error(Se('Failed to look up preview information for shell ID "%s" (port: %d)',e.sourceShellId,e.port)))}),s=t&&a(t);return s&&i.resolve({url:t.url,port:t.port,sourceShellId:t.sourceShellId}),this.channel.on("preview/port/ready",({data:c})=>{!s&&a(c)&&i.resolve({url:c.url,port:c.port,sourceShellId:c.sourceShellId})}),i.finally(()=>{clearTimeout(o)})}async getByShellId(e,a){return this.waitFor({sourceShellId:e},n=>n.sourceShellId===e,a).catch(n=>{throw new Error(Se('Failed to get shell by ID "%s"',e),{cause:n})})}async waitForPort(e,a){return this.waitFor({port:e},n=>n.port===e,a).catch(n=>{throw new Error(Se("Failed to await port %d",e),{cause:n})})}constructor(e){this.channel=e}},Gr="https://nodebox-runtime.codesandbox.io",Ya=Tt("emulator"),Mt=class{async connect(){let{iframe:e,cdnUrl:a}=this.options;Ya("[message-sender]: Connecting to node emulator...");let n=new yt.DeferredPromise;this.url||n.reject(new Error("Nodebox URL is missing. Did you forget to provide it when creating this Nodebox instance?")),Ue(e.contentWindow,"Failed to create a MessageChannel with the Nodebox iframe: no content window found"),this.channel=new zr(e.contentWindow);let i=new yt.DeferredPromise;return e.setAttribute("src",this.url),e.addEventListener("load",()=>{i.resolve()},{once:!0}),e.addEventListener("error",o=>{i.reject(o.error)},{once:!0}),await i,Ya("[message-sender]: IFrame loaded..."),await this.channel.handshake(),Ya("[message-sender]: Handshake completed..."),this.channel.send("connect",{cdnUrl:a}),this.channel.on("runtime/ready",()=>{n.resolve()}),n.then(()=>{Ya("[message-sender]: Connected to runtime..."),this.isConnected=!0})}get fs(){return Ue(this.isConnected,'Failed to access the File System API: consumer is not connected. Did you forget to run "connect()"?'),this.fileSystemApi?this.fileSystemApi:(this.fileSystemApi=new Vr(this.channel),this.fileSystemApi)}get shell(){return Ue(this.isConnected,'Failed to access the Shell API: consumer is not connected. Did you forget to run "connect()"?'),this.shellApi?this.shellApi:(this.shellApi=new Ur(this.channel),this.shellApi)}get preview(){return Ue(this.isConnected,'Failed to access the Preview API: consumer is not connected. Did you forget to run "connect()"?'),this.previewApi?this.previewApi:(this.previewApi=new Jr(this.channel),this.previewApi)}constructor(e){ne(this,"channel",null),ne(this,"isConnected",void 0),ne(this,"url",void 0),ne(this,"fileSystemApi",null),ne(this,"shellApi",null),ne(this,"previewApi",null),this.options=e,Ue(this.options.iframe,'Failed to create a Nodebox: expected "iframe" argument to be a reference to an