@elixir-playground/runtime 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@elixir-playground/runtime",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "license": "Apache-2.0 AND BSD-3-Clause AND ISC AND MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/SteffenDE/run-elixir.dev.git"
8
+ },
5
9
  "files": [
6
10
  "LICENSE",
7
11
  "NOTICE.md",
8
12
  "chunks",
9
- "claude.html",
10
13
  "exec.html",
11
14
  "files.js",
12
15
  "frames",
@@ -45,8 +48,11 @@
45
48
  ],
46
49
  "nif": [
47
50
  1
51
+ ],
52
+ "claude": [
53
+ 1
48
54
  ]
49
55
  }
50
56
  },
51
- "playgroundDigest": "2f4c8f793d02"
57
+ "playgroundDigest": "eeed5917f468"
52
58
  }
package/worker.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,m as s,n as c,p as l,r as u,t as d,v as f,x as p}from"./chunks/fs-GnBaZCKr.js";import{a as m,d as h,f as g,i as ee,n as _,t as te}from"./chunks/wasi-M0pSoirQ.js";import{C as ne,D as v,E as re,S as ie,T as ae,b as oe,c as se,d as ce,f as le,g as y,h as ue,i as de,l as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve,v as ye,w as be,x as xe,y as Se}from"./chunks/git-remote-DnEba0y9.js";import{t as b}from"./chunks/manifest-DOTdOkY7.js";import{t as x}from"./chunks/preload-helper-DHhhL8Zf.js";var Ce=9;function S(e,t){return r(e,e,t).node??null}function we(e,t,r=null){let i=e=>r?.prefixes.some(t=>e===t||e.startsWith(`${t}/`)),a=(e,t)=>r.call(e,t),o=new TextDecoder,s={stat(t){if(i(t)){let{answer:e}=a({op:`stat`,path:t});return e.error?null:{dir:e.type===`dir`}}let n=S(e,t);return n?{dir:n instanceof c}:null},list(t){if(i(t)){let e=a({op:`open`,path:t,oflags:2}).answer;if(e.error)return null;let{entries:n=[]}=a({op:`readdir`,handle:e.handle}).answer;return a({op:`close`,handle:e.handle}),n.map(([e,t])=>({name:e,dir:t===`dir`}))}let n=S(e,t);return n instanceof c?[...n.entries].map(([e,t])=>({name:e,dir:t instanceof c})):null},read(r){if(i(r)){let e=a({op:`open`,path:r}).answer;if(e.error||e.type===`dir`)return null;let t=[],n=0;for(;;){let{bytes:r}=a({op:`read`,handle:e.handle,offset:n,length:524288});if(t.push(r),n+=r.length,r.length<524288)break}a({op:`close`,handle:e.handle});let i=new Uint8Array(n),o=0;for(let e of t)i.set(e,o),o+=e.length;return i}let o=S(e,r);return o instanceof u?(n(o,t),o.bytes):null},readText(e){let t=s.read(e);return t?o.decode(t):null},mkdir(t){if(i(t)){let e=``;for(let n of t.split(`/`).filter(Boolean))e+=`/${n}`,s.stat(e)||a({op:`mkdir`,path:e})}else e.mkdirs(t)},write(t,n){if(i(t)){let e=a({op:`open`,path:t,oflags:Ce}).answer;if(e.error)return!1;for(let t=0;t<n.length;t+=524288)a({op:`write`,handle:e.handle,offset:t},n.subarray(t,t+524288));return a({op:`close`,handle:e.handle}),!0}let r=e.put(t,new u(n));return r.written=!0,!0},remove(t){if(i(t)){let{answer:e}=a({op:`stat`,path:t,follow:!1});if(e.error)return;if(e.type===`dir`){for(let e of s.list(t)??[])s.remove(`${t}/${e.name}`);a({op:`rmdir`,path:t})}else a({op:`unlink`,path:t})}else S(e,t.slice(0,t.lastIndexOf(`/`))||`/`)?.entries?.delete(t.slice(t.lastIndexOf(`/`)+1))}};return s}var C={INPUT:0,OPEN:1,DATA:2,END:3,CLOSE:4,INTERRUPT:5,OUTPUT:7,EXIT:8,RESIZE:9,PEERS:10,TERMINATE:11,CONNECTED:12,DATAGRAM:13,MODE:14,TAKEN:15,OUTPUT_ERR:16},w=1<<20,T=Atomics.waitAsync,E={TERMINAL:0,PIPE:1,PIPE_END:2},D=new Uint8Array([4]);function O(e){if(e.length===4)return e.join(`.`);let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return t.join(`:`)}var Te=class{constructor(e){this.control=new Int32Array(e,0,2),this.ring=new Uint8Array(e,8,w),this.input=[],this.network=null,this.interrupted=!1,this.terminated=!1,this.size=[80,24],this.raw=!1,this.signals=!0,this.reading=null,this.tty=[!0,!0],this.processes=new Map,this.peers=new Set,this.next=null}bytes(e,t){let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=this.ring[(e+r)%w];return n}pump(){let e=Atomics.load(this.control,0),t=Atomics.load(this.control,1);for(;t!==e;){let e=new DataView(this.bytes(t,9).buffer),n=e.getUint8(0),r=e.getUint32(1,!0),i=e.getUint32(5,!0),a=this.bytes(t+9,i);t+=9+i;let o=this.network;if(n===C.INPUT)r===E.PIPE?this.input.push(a):r===E.PIPE_END?this.input.push(D):a.length!==1||a[0]!==4||this.raw?this.input.push(a):this.reading!==null&&this.input.push(D);else if(n===C.MODE)this.mode(a[0]===1,a[1]===1);else if(n===C.INTERRUPT)this.interrupted=!0;else if(n===C.TERMINATE)this.terminated=!0;else if(n===C.RESIZE){let e=new DataView(a.buffer);this.size=[e.getUint16(0,!0),e.getUint16(2,!0)]}else if(n===C.OPEN)(!o||!o.accepted(r,a[0]<<8|a[1]))&&postMessage({kind:`net`,op:`refused`,id:r});else if(n===C.PEERS){this.peers=new Set;for(let e=0;e+1<a.length;e+=2)this.peers.add(a[e]<<8|a[e+1]);o&&(o.peers=this.peers)}else if(n===C.OUTPUT)this.processes.get(r)?.write(a);else if(n===C.OUTPUT_ERR)this.processes.get(r)?.writeError(a);else if(n===C.TAKEN){let e=this.processes.get(r);e&&(e.taken+=new DataView(a.buffer).getUint32(0,!0),e.notify?.())}else if(n===C.EXIT)this.processes.get(r)?.exit(a[0]),this.processes.delete(r);else if(n===C.CONNECTED){let e=new DataView(a.buffer),t=a[1]===6?16:4,n=a.length>2?{address:O(a.subarray(2,2+t)),port:e.getUint16(2+t)}:void 0;o?.connected(r,e.getInt8(0),n)}else if(n===C.DATAGRAM){let e=new DataView(a.buffer).getUint16(0),t=O(a.subarray(3,3+(a[2]===6?16:4)));o?.datagram(r,t,e,a.subarray(a[2]===6?19:7))}else n===C.DATA?o?.data(r,a):(n===C.END||n===C.CLOSE)&&o?.ended(r)}Atomics.store(this.control,1,t)}sleep(e){Atomics.wait(this.control,0,Atomics.load(this.control,1),e)}rest(e){if(!T)return new Promise(t=>setTimeout(t,Math.min(e,10)));if(!this.next){let e=T(this.control,0,Atomics.load(this.control,1));if(!e.async)return Promise.resolve();this.next=e.value.then(()=>this.next=null)}let t;return Promise.race([this.next,new Promise(n=>t=setTimeout(n,e))]).then(()=>clearTimeout(t))}take(e){let t=[],n=0;for(;this.input.length&&n<e;){let r=this.input[0];if(r===D){this.input.shift();continue}let i=r.subarray(0,e-n);t.push(i),n+=i.length,i.length===r.length?this.input.shift():this.input[0]=r.subarray(i.length)}let r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r}takeInput(e){let t=this.input.indexOf(D);if(t===0)return this.input.shift(),new Uint8Array;if(!this.input.length)return null;let n=t>0?this.input.splice(t):[],r=this.take(e);return this.input.push(...n),r}mode(e,t=!0){(e!==this.raw||t!==this.signals)&&(this.raw=e,this.signals=t,postMessage({kind:`tty`,raw:e,signals:t}))}},Ee=0;function De(e,t,n={input:null,tty:[!1,!1]}){return(r,{args:i,cwd:a,env:o})=>{let s=Ee+=1;e.processes.set(s,r),r.onclose=()=>{e.processes.delete(s),postMessage({kind:`kill`,id:s})},postMessage({kind:`spawn`,id:s,name:t,args:i,cwd:a,env:o,tty:n.tty}),n.input&&(n.input.length&&postMessage({kind:`stdin`,id:s,bytes:n.input}),postMessage({kind:`stdin`,id:s,end:!0})),n.started?.(s)}}var k=e=>new URL(e,import.meta.url),A=null;function j(){if(!A)throw Error(`no site manifest yet`);return A}function M(e){A=new b(e),ae(A.programs())}function N(e,t=!0){let n=new XMLHttpRequest;n.open(`GET`,e,!1),t&&(n.responseType=`arraybuffer`);try{n.send()}catch{return[0,null]}return[n.status,t?new Uint8Array(n.response):n.responseText]}var P=e=>e?.length>262&&new TextDecoder().decode(e.subarray(257,262))===`ustar`,F={queued:`waiting for a build machine`,running:`building in a VM`,setting_up:`no recipe builds it yet: an agent is working one out (this can take minutes)`};function Oe(e,t,n,r){let i=j().find(`nifAbi`)?.value??``,a=k(`/api/v1/nif/${encodeURIComponent(t)}/${encodeURIComponent(n)}?abi=${encodeURIComponent(i)}`),o=(e,r=null)=>postMessage({kind:`nif`,name:t,version:n,status:e,error:r}),s=null;for(;;){let[i,c]=N(a,!1),l=null;try{l=JSON.parse(c)}catch{}if(i===200&&l?.url){let[e,i]=N(new URL(l.url,a));return e===200&&P(i)?(s&&r(`${t} ${n} is built`),o(`succeeded`),i):(o(`failed`,`the library did not download (${e})`),`the playground's build of ${t} ${n} did not download (${e})`)}if(i!==202){let e=l?.error??(i?`the playground's backend answered ${i}`:`the playground's backend could not be reached`);return i===200||i===404&&!l?null:(o(l?.status??`failed`,e),`${t} ${n} could not be built for the playground: ${e}`)}l?.status!==s&&(s=l?.status,r(`${t} ${n}: ${F[s]??s}…`),o(s));for(let r=0;r<2e3;r+=200)if(e.sleep(200),e.pump(),e.interrupted)return o(`interrupted`),`stopped waiting for ${t} ${n}'s build`}}async function I(e){let t=null,n=(e,n)=>new Uint8Array(t.buffer,e,n),r=new _({args:[`brush`,...e.args],env:e.env,root:e.root,stdin:()=>new Uint8Array,stdout:t=>e.out(t.slice()),stderr:t=>(e.err??e.out)(t.slice()),sleep:e=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e),tty:!e.stdio,fetch:e.fetch,shared:e.shared,suspending:!0,bounded:!1,pump:()=>{e.pump?.(),e.self?.check()}}),i=e.self??e.processes.adopt();e.stdio?(e.stdio.forEach((e,t)=>r.fds.set(t,ye(e))),r.interrupt=i.woken):r.fds.set(0,{...e.standard[0]});let a={raw_mode:t=>(e.terminal.raw(t!==0),0),size:(n,r)=>{let[i,a]=e.terminal.size(),o=new DataView(t.buffer);return o.setUint16(n,i,!0),o.setUint16(r,a,!0),0},read:new WebAssembly.Suspending(async(t,r,i)=>{let a=await e.terminal.read(r,i);return a?(n(t,a.length).set(a),a.length):-1})},o=new WebAssembly.Instance(e.module,{...r.imports,processes:y(r,e.processes,i,e.stdio?[]:e.standard),crossterm:a});t=o.exports.memory,r.memory=t;let s=WebAssembly.promising(o.exports._start);try{return await s(),0}catch(e){if(e instanceof te)return e.code;throw e}finally{e.stdio?r.release():e.processes.forget(i)}}var ke=new Set([`+B`,`+Bc`,`+Bd`,`+Bi`,`+c`,`+d`,`+r`]),L=[`-Mea`,`min`];function Ae(e,{home:t=`/work`,root:n}){let r=[...L],i=[],a=!1;for(let t=0;t<e.length;t++){let n=e[t];if(a)i.push(n);else if(n===`-extra`)a=!0,i.push(n);else if(n.startsWith(`+`)&&n.length>1){r.push(`-`+n.slice(1));let i=e[t+1];!ke.has(n)&&i!==void 0&&!/^[-+]/.test(i)&&r.push(e[++t])}else i.push(n)}let o=i.includes(`-boot`)?[]:[`-boot`,`${n}/bin/start`];return[...r,`--`,`-root`,n,`-bindir`,`${n}/bin`,`-progname`,`erl`,`-home`,t,`-kernel`,`inet_backend`,`socket`,`-proto_dist`,`inet_epmd`,`-inet_epmd`,`socket`,`-os_mon`,`start_cpu_sup`,`false`,`-os_mon`,`start_disksup`,`false`,`-os_mon`,`start_os_sup`,`false`,...o,...i]}var R=new Map(Object.entries(f).map(([e,t])=>[t,`E${e}`])),z=class extends Error{constructor(e){super(e),this.code=e}},B=e=>{throw new z(e)},V=e=>R.get(e)??`EIO`,H=e=>B(V(e)),je=64,Me=1024,Ne=class{constructor(e,t){this.root=e,this.fetch=t,this.opened=new Map,this.next=1}at(e){let t=r(this.root,this.root,e,!1);return t.node?t:H(t.error)}free(e){let t=r(this.root,this.root,e,!1);return t.node?B(`EEXIST`):t.error!==f.NOENT||!t.parent?H(t.error):{parent:t.parent,name:t.name}}lstat(e){let{node:t}=this.at(e),n=t instanceof c?16877:t instanceof o?41471:t instanceof d?8630:33261,r=t instanceof c?4096:t.size,i=new Date(Number(t.mtime/1000000n));return{dev:1,ino:Number(t.ino),mode:n,nlink:1,uid:0,gid:0,rdev:0,size:r,atime:i,mtime:i,ctime:i,blksize:4096,blocks:Math.ceil(r/512)}}chmod(){}utime(e,t,n){this.at(e).node.mtime=BigInt(n.getTime())*1000000n}truncate(e,t){let{node:r}=this.at(e);if(!(r instanceof u))return B(`EISDIR`);t===0?r.source=null:n(r,this.fetch),r.truncate(t),r.written=!0}mkdir(e){let{parent:t,name:n}=this.free(e),r=new c;r.parent=t,t.entries.set(n,r),t.mtime=s()}writeFile(e){let{parent:t,name:n}=this.free(e),r=new u;r.written=!0,t.entries.set(n,r),t.mtime=s()}rename(e,t){let n=this.at(e),i=r(this.root,this.root,t,!1);(!i.parent||i.error&&i.error!==f.NOENT)&&H(i.error??f.NOENT),i.node instanceof c?(n.node instanceof c||B(`EISDIR`),i.node.entries.size&&B(`ENOTEMPTY`)):i.node&&n.node instanceof c&&B(`ENOTDIR`),n.parent.entries.delete(n.name),i.parent.entries.set(i.name,n.node),n.node instanceof c&&(n.node.parent=i.parent),n.parent.mtime=i.parent.mtime=s()}unlink(e){let{node:t,parent:n,name:r}=this.at(e);t instanceof c&&B(`EISDIR`),n.entries.delete(r),n.mtime=s()}rmdir(e){let{node:t,parent:n,name:r}=this.at(e);if(!(t instanceof c))return B(`ENOTDIR`);t.entries.size&&B(`ENOTEMPTY`),n.entries.delete(r),n.mtime=s()}readdir(e){let t=r(this.root,this.root,e,!0);return t.node?t.node instanceof c?[`.`,`..`,...t.node.entries.keys()]:B(`ENOTDIR`):H(t.error)}symlink(e,t){let{parent:n,name:r}=this.free(t);n.entries.set(r,new o(e)),n.mtime=s()}link(e,t){let{node:n}=this.at(e);n instanceof c&&B(`EPERM`);let{parent:r,name:i}=this.free(t);r.entries.set(i,n),r.mtime=s()}readlink(e){let{node:t}=this.at(e);return t instanceof o?t.target:B(`EINVAL`)}open(e,t){let i=r(this.root,this.root,e,!0);if(!i.node)return t&je?(this.writeFile(e),this.open(e,t&-65)):H(i.error);let a=i.node;if(a instanceof o)return B(`ELOOP`);a instanceof u&&n(a,this.fetch);let s=this.next++;return this.opened.set(s,{node:a,append:!!(t&Me)}),s}close(e){this.opened.delete(e)}read(e,t,n,r,i){let{node:a}=this.opened.get(e)??B(`EBADF`);if(a instanceof c)return B(`EISDIR`);if(a instanceof d){let e=a.read(r);return t.set(e,n),e.length}let o=a.bytes.subarray(i,i+r);return t.set(o,n),o.length}write(e,t,r,i,a){let o=this.opened.get(e)??B(`EBADF`),c=o.node;if(!(c instanceof u))return B(`EISDIR`);n(c,this.fetch);let l=o.append?c.size:a;return c.reserve(l+i),l>c.size&&c.data.fill(0,c.size,l),c.data.set(t.subarray(r,r+i),l),c.size=Math.max(c.size,l+i),c.mtime=s(),c.written=!0,i}},U=524288,W=class extends Error{constructor(e){super(e),this.code=e}},G=class{constructor(e){this.call=e}ask(e,t){let{answer:n}=this.call(e,t);if(n.error)throw new W(V(n.error));return n}lstat(e){let{type:t,size:n,ino:r,mtime:i}=this.ask({op:`stat`,path:e,follow:!1}),a=t===`dir`?16877:t===`link`?41471:33261,o=new Date(Number(BigInt(i)/1000000n));return{dev:2,ino:r,mode:a,nlink:1,uid:0,gid:0,rdev:0,size:t===`dir`?4096:n,atime:o,mtime:o,ctime:o,blksize:4096,blocks:Math.ceil(n/512)}}chmod(){}utime(){}truncate(e,t){let{handle:n}=this.ask({op:`open`,path:e});try{this.ask({op:`truncate`,handle:n,size:t})}finally{this.ask({op:`close`,handle:n})}}mkdir(e){this.ask({op:`mkdir`,path:e})}writeFile(e){let{handle:t}=this.ask({op:`open`,path:e,oflags:p.CREAT|p.EXCL});this.ask({op:`close`,handle:t})}rename(e,t){this.ask({op:`rename`,path:e,to:t})}unlink(e){this.ask({op:`unlink`,path:e})}rmdir(e){this.ask({op:`rmdir`,path:e})}readdir(e){let{handle:t}=this.ask({op:`open`,path:e,oflags:p.DIRECTORY});try{let{entries:e=[]}=this.ask({op:`readdir`,handle:t});return[`.`,`..`,...e.map(([e])=>e)]}finally{this.ask({op:`close`,handle:t})}}symlink(e,t){this.ask({op:`symlink`,path:t,target:e})}readlink(e){return this.ask({op:`readlink`,path:e}).target}link(e,t){this.ask({op:`link`,path:e,to:t,follow:!1})}open(e){return this.ask({op:`open`,path:e}).handle}close(e){this.ask({op:`close`,handle:e})}read(e,t,n,r,i){let a=0;for(;a<r;){let o=Math.min(r-a,U),{answer:s,bytes:c}=this.call({op:`read`,handle:e,offset:i+a,length:o});if(s.error)throw new W(V(s.error));if(t.set(c,n+a),a+=c.length,c.length<o)break}return a}write(e,t,n,r,i){for(let a=0;a<r;a+=U){let o=t.slice(n+a,n+Math.min(r,a+U));this.ask({op:`write`,handle:e,offset:i+a},o)}return r}},Pe=65536,Fe=new TextEncoder,Ie=(e,t)=>(n,r)=>(WebAssembly.instantiate(e,n).then(t=>r(t,e),t),{}),K=new Map;function q(e){if(!(`WorkerGlobalScope`in globalThis))return Promise.resolve(void 0);let t=new URL(`beam.emu.mjs`,new URL(e,location.href)).href,n=K.get(t);return n||(n=fetch(t).then(e=>{if(!e.ok)throw Error(`${t}: ${e.status}`);return e.blob()}).then(e=>URL.createObjectURL(new Blob([e],{type:`text/javascript`}))),n.catch(()=>K.delete(t)),K.set(t,n)),n}function J(e){let t=e.memory??new WebAssembly.Memory({initial:1024,maximum:65536,shared:!0}),n=null,r=!1,i=[],a=0,o=!1,s=!1,c=null,l=!1,u=(e,...t)=>n[`_${e}`](...t),d=()=>{c??=setTimeout(()=>{c=null,f()},20)},f=()=>{if(n&&!r){for(;i.length;){let e=Pe-a;if(e<=0)return;let n=i[0];n.length>e?(i[0]=n.subarray(e),n=n.subarray(0,e)):i.shift();let r=u(`malloc`,n.length);new Uint8Array(t.buffer).set(n,r);let o=u(`popcornStdinEnqueue`,r,n.length);if(u(`free`,r),o<0)return i.unshift(n),d();a+=n.length}if(o&&!s){if(u(`popcornStdinEof`)<0)return d();s=!0}}},p=e.size;return{done:new Promise((i,o)=>{let s=e=>{r||(r=!0,c&&clearTimeout(c),i(e))};Promise.all([x(()=>import(e.module),[]),q(e.module)]).then(([{default:r},i])=>r({arguments:e.args,beamThreadUrl:i,...e.tty?{}:{stdin:()=>null},wasmMemory:t,...e.wasm?{instantiateWasm:Ie(e.wasm,o)}:{},beamNetwork:e.network,beamHttpsGateway:e.httpsGateway,beamNifs:ze(e),beamSocketTrace:e.trace,onTtyChunk:(t,n)=>(t===2?e.stderr:e.stdout)(n),print:t=>e.stdout(Fe.encode(t+`
1
+ import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,m as s,n as c,p as l,r as u,t as d,v as f,x as p}from"./chunks/fs-GnBaZCKr.js";import{a as m,d as h,f as g,i as ee,n as _,t as te}from"./chunks/wasi-BuobPCe8.js";import{C as ne,D as v,E as re,S as ie,T as ae,b as oe,c as se,d as ce,f as le,g as y,h as ue,i as de,l as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve,v as ye,w as be,x as xe,y as Se}from"./chunks/git-remote-Bb9EZlDN.js";import{t as b}from"./chunks/manifest-DOTdOkY7.js";import{t as x}from"./chunks/preload-helper-DHhhL8Zf.js";var Ce=9;function S(e,t){return r(e,e,t).node??null}function we(e,t,r=null){let i=e=>r?.prefixes.some(t=>e===t||e.startsWith(`${t}/`)),a=(e,t)=>r.call(e,t),o=new TextDecoder,s={stat(t){if(i(t)){let{answer:e}=a({op:`stat`,path:t});return e.error?null:{dir:e.type===`dir`}}let n=S(e,t);return n?{dir:n instanceof c}:null},list(t){if(i(t)){let e=a({op:`open`,path:t,oflags:2}).answer;if(e.error)return null;let{entries:n=[]}=a({op:`readdir`,handle:e.handle}).answer;return a({op:`close`,handle:e.handle}),n.map(([e,t])=>({name:e,dir:t===`dir`}))}let n=S(e,t);return n instanceof c?[...n.entries].map(([e,t])=>({name:e,dir:t instanceof c})):null},read(r){if(i(r)){let e=a({op:`open`,path:r}).answer;if(e.error||e.type===`dir`)return null;let t=[],n=0;for(;;){let{bytes:r}=a({op:`read`,handle:e.handle,offset:n,length:524288});if(t.push(r),n+=r.length,r.length<524288)break}a({op:`close`,handle:e.handle});let i=new Uint8Array(n),o=0;for(let e of t)i.set(e,o),o+=e.length;return i}let o=S(e,r);return o instanceof u?(n(o,t),o.bytes):null},readText(e){let t=s.read(e);return t?o.decode(t):null},mkdir(t){if(i(t)){let e=``;for(let n of t.split(`/`).filter(Boolean))e+=`/${n}`,s.stat(e)||a({op:`mkdir`,path:e})}else e.mkdirs(t)},write(t,n){if(i(t)){let e=a({op:`open`,path:t,oflags:Ce}).answer;if(e.error)return!1;for(let t=0;t<n.length;t+=524288)a({op:`write`,handle:e.handle,offset:t},n.subarray(t,t+524288));return a({op:`close`,handle:e.handle}),!0}let r=e.put(t,new u(n));return r.written=!0,!0},remove(t){if(i(t)){let{answer:e}=a({op:`stat`,path:t,follow:!1});if(e.error)return;if(e.type===`dir`){for(let e of s.list(t)??[])s.remove(`${t}/${e.name}`);a({op:`rmdir`,path:t})}else a({op:`unlink`,path:t})}else S(e,t.slice(0,t.lastIndexOf(`/`))||`/`)?.entries?.delete(t.slice(t.lastIndexOf(`/`)+1))}};return s}var C={INPUT:0,OPEN:1,DATA:2,END:3,CLOSE:4,INTERRUPT:5,OUTPUT:7,EXIT:8,RESIZE:9,PEERS:10,TERMINATE:11,CONNECTED:12,DATAGRAM:13,MODE:14,TAKEN:15,OUTPUT_ERR:16},w=1<<20,T=Atomics.waitAsync,E={TERMINAL:0,PIPE:1,PIPE_END:2},D=new Uint8Array([4]);function O(e){if(e.length===4)return e.join(`.`);let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return t.join(`:`)}var Te=class{constructor(e){this.control=new Int32Array(e,0,2),this.ring=new Uint8Array(e,8,w),this.input=[],this.network=null,this.interrupted=!1,this.terminated=!1,this.size=[80,24],this.raw=!1,this.signals=!0,this.reading=null,this.tty=[!0,!0],this.processes=new Map,this.peers=new Set,this.next=null}bytes(e,t){let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=this.ring[(e+r)%w];return n}pump(){let e=Atomics.load(this.control,0),t=Atomics.load(this.control,1);for(;t!==e;){let e=new DataView(this.bytes(t,9).buffer),n=e.getUint8(0),r=e.getUint32(1,!0),i=e.getUint32(5,!0),a=this.bytes(t+9,i);t+=9+i;let o=this.network;if(n===C.INPUT)r===E.PIPE?this.input.push(a):r===E.PIPE_END?this.input.push(D):a.length!==1||a[0]!==4||this.raw?this.input.push(a):this.reading!==null&&this.input.push(D);else if(n===C.MODE)this.mode(a[0]===1,a[1]===1);else if(n===C.INTERRUPT)this.interrupted=!0;else if(n===C.TERMINATE)this.terminated=!0;else if(n===C.RESIZE){let e=new DataView(a.buffer);this.size=[e.getUint16(0,!0),e.getUint16(2,!0)]}else if(n===C.OPEN)(!o||!o.accepted(r,a[0]<<8|a[1]))&&postMessage({kind:`net`,op:`refused`,id:r});else if(n===C.PEERS){this.peers=new Set;for(let e=0;e+1<a.length;e+=2)this.peers.add(a[e]<<8|a[e+1]);o&&(o.peers=this.peers)}else if(n===C.OUTPUT)this.processes.get(r)?.write(a);else if(n===C.OUTPUT_ERR)this.processes.get(r)?.writeError(a);else if(n===C.TAKEN){let e=this.processes.get(r);e&&(e.taken+=new DataView(a.buffer).getUint32(0,!0),e.notify?.())}else if(n===C.EXIT)this.processes.get(r)?.exit(a[0]),this.processes.delete(r);else if(n===C.CONNECTED){let e=new DataView(a.buffer),t=a[1]===6?16:4,n=a.length>2?{address:O(a.subarray(2,2+t)),port:e.getUint16(2+t)}:void 0;o?.connected(r,e.getInt8(0),n)}else if(n===C.DATAGRAM){let e=new DataView(a.buffer).getUint16(0),t=O(a.subarray(3,3+(a[2]===6?16:4)));o?.datagram(r,t,e,a.subarray(a[2]===6?19:7))}else n===C.DATA?o?.data(r,a):(n===C.END||n===C.CLOSE)&&o?.ended(r)}Atomics.store(this.control,1,t)}sleep(e){Atomics.wait(this.control,0,Atomics.load(this.control,1),e)}rest(e){if(!T)return new Promise(t=>setTimeout(t,Math.min(e,10)));if(!this.next){let e=T(this.control,0,Atomics.load(this.control,1));if(!e.async)return Promise.resolve();this.next=e.value.then(()=>this.next=null)}let t;return Promise.race([this.next,new Promise(n=>t=setTimeout(n,e))]).then(()=>clearTimeout(t))}take(e){let t=[],n=0;for(;this.input.length&&n<e;){let r=this.input[0];if(r===D){this.input.shift();continue}let i=r.subarray(0,e-n);t.push(i),n+=i.length,i.length===r.length?this.input.shift():this.input[0]=r.subarray(i.length)}let r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r}takeInput(e){let t=this.input.indexOf(D);if(t===0)return this.input.shift(),new Uint8Array;if(!this.input.length)return null;let n=t>0?this.input.splice(t):[],r=this.take(e);return this.input.push(...n),r}mode(e,t=!0){(e!==this.raw||t!==this.signals)&&(this.raw=e,this.signals=t,postMessage({kind:`tty`,raw:e,signals:t}))}},Ee=0;function De(e,t,n={input:null,tty:[!1,!1]}){return(r,{args:i,cwd:a,env:o})=>{let s=Ee+=1;e.processes.set(s,r),r.onclose=()=>{e.processes.delete(s),postMessage({kind:`kill`,id:s})},postMessage({kind:`spawn`,id:s,name:t,args:i,cwd:a,env:o,tty:n.tty}),n.input&&(n.input.length&&postMessage({kind:`stdin`,id:s,bytes:n.input}),postMessage({kind:`stdin`,id:s,end:!0})),n.started?.(s)}}var k=e=>new URL(e,import.meta.url),A=null;function j(){if(!A)throw Error(`no site manifest yet`);return A}function M(e){A=new b(e),ae(A.programs())}function N(e,t=!0){let n=new XMLHttpRequest;n.open(`GET`,e,!1),t&&(n.responseType=`arraybuffer`);try{n.send()}catch{return[0,null]}return[n.status,t?new Uint8Array(n.response):n.responseText]}var P=e=>e?.length>262&&new TextDecoder().decode(e.subarray(257,262))===`ustar`,F={queued:`waiting for a build machine`,running:`building in a VM`,setting_up:`no recipe builds it yet: an agent is working one out (this can take minutes)`};function Oe(e,t,n,r){let i=j().find(`nifAbi`)?.value??``,a=k(`/api/v1/nif/${encodeURIComponent(t)}/${encodeURIComponent(n)}?abi=${encodeURIComponent(i)}`),o=(e,r=null)=>postMessage({kind:`nif`,name:t,version:n,status:e,error:r}),s=null;for(;;){let[i,c]=N(a,!1),l=null;try{l=JSON.parse(c)}catch{}if(i===200&&l?.url){let[e,i]=N(new URL(l.url,a));return e===200&&P(i)?(s&&r(`${t} ${n} is built`),o(`succeeded`),i):(o(`failed`,`the library did not download (${e})`),`the playground's build of ${t} ${n} did not download (${e})`)}if(i!==202){let e=l?.error??(i?`the playground's backend answered ${i}`:`the playground's backend could not be reached`);return i===200||i===404&&!l?null:(o(l?.status??`failed`,e),`${t} ${n} could not be built for the playground: ${e}`)}l?.status!==s&&(s=l?.status,r(`${t} ${n}: ${F[s]??s}…`),o(s));for(let r=0;r<2e3;r+=200)if(e.sleep(200),e.pump(),e.interrupted)return o(`interrupted`),`stopped waiting for ${t} ${n}'s build`}}async function I(e){let t=null,n=(e,n)=>new Uint8Array(t.buffer,e,n),r=new _({args:[`brush`,...e.args],env:e.env,root:e.root,stdin:()=>new Uint8Array,stdout:t=>e.out(t.slice()),stderr:t=>(e.err??e.out)(t.slice()),sleep:e=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e),tty:!e.stdio,fetch:e.fetch,shared:e.shared,suspending:!0,bounded:!1,pump:()=>{e.pump?.(),e.self?.check()}}),i=e.self??e.processes.adopt();e.stdio?(e.stdio.forEach((e,t)=>r.fds.set(t,ye(e))),r.interrupt=i.woken):r.fds.set(0,{...e.standard[0]});let a={raw_mode:t=>(e.terminal.raw(t!==0),0),size:(n,r)=>{let[i,a]=e.terminal.size(),o=new DataView(t.buffer);return o.setUint16(n,i,!0),o.setUint16(r,a,!0),0},read:new WebAssembly.Suspending(async(t,r,i)=>{let a=await e.terminal.read(r,i);return a?(n(t,a.length).set(a),a.length):-1})},o=new WebAssembly.Instance(e.module,{...r.imports,processes:y(r,e.processes,i,e.stdio?[]:e.standard),crossterm:a});t=o.exports.memory,r.memory=t;let s=WebAssembly.promising(o.exports._start);try{return await s(),0}catch(e){if(e instanceof te)return e.code;throw e}finally{e.stdio?r.release():e.processes.forget(i)}}var ke=new Set([`+B`,`+Bc`,`+Bd`,`+Bi`,`+c`,`+d`,`+r`]),L=[`-Mea`,`min`];function Ae(e,{home:t=`/work`,root:n}){let r=[...L],i=[],a=!1;for(let t=0;t<e.length;t++){let n=e[t];if(a)i.push(n);else if(n===`-extra`)a=!0,i.push(n);else if(n.startsWith(`+`)&&n.length>1){r.push(`-`+n.slice(1));let i=e[t+1];!ke.has(n)&&i!==void 0&&!/^[-+]/.test(i)&&r.push(e[++t])}else i.push(n)}let o=i.includes(`-boot`)?[]:[`-boot`,`${n}/bin/start`];return[...r,`--`,`-root`,n,`-bindir`,`${n}/bin`,`-progname`,`erl`,`-home`,t,`-kernel`,`inet_backend`,`socket`,`-proto_dist`,`inet_epmd`,`-inet_epmd`,`socket`,`-os_mon`,`start_cpu_sup`,`false`,`-os_mon`,`start_disksup`,`false`,`-os_mon`,`start_os_sup`,`false`,...o,...i]}var R=new Map(Object.entries(f).map(([e,t])=>[t,`E${e}`])),z=class extends Error{constructor(e){super(e),this.code=e}},B=e=>{throw new z(e)},V=e=>R.get(e)??`EIO`,H=e=>B(V(e)),je=64,Me=1024,Ne=class{constructor(e,t){this.root=e,this.fetch=t,this.opened=new Map,this.next=1}at(e){let t=r(this.root,this.root,e,!1);return t.node?t:H(t.error)}free(e){let t=r(this.root,this.root,e,!1);return t.node?B(`EEXIST`):t.error!==f.NOENT||!t.parent?H(t.error):{parent:t.parent,name:t.name}}lstat(e){let{node:t}=this.at(e),n=t instanceof c?16877:t instanceof o?41471:t instanceof d?8630:33261,r=t instanceof c?4096:t.size,i=new Date(Number(t.mtime/1000000n));return{dev:1,ino:Number(t.ino),mode:n,nlink:1,uid:0,gid:0,rdev:0,size:r,atime:i,mtime:i,ctime:i,blksize:4096,blocks:Math.ceil(r/512)}}chmod(){}utime(e,t,n){this.at(e).node.mtime=BigInt(n.getTime())*1000000n}truncate(e,t){let{node:r}=this.at(e);if(!(r instanceof u))return B(`EISDIR`);t===0?r.source=null:n(r,this.fetch),r.truncate(t),r.written=!0}mkdir(e){let{parent:t,name:n}=this.free(e),r=new c;r.parent=t,t.entries.set(n,r),t.mtime=s()}writeFile(e){let{parent:t,name:n}=this.free(e),r=new u;r.written=!0,t.entries.set(n,r),t.mtime=s()}rename(e,t){let n=this.at(e),i=r(this.root,this.root,t,!1);(!i.parent||i.error&&i.error!==f.NOENT)&&H(i.error??f.NOENT),i.node instanceof c?(n.node instanceof c||B(`EISDIR`),i.node.entries.size&&B(`ENOTEMPTY`)):i.node&&n.node instanceof c&&B(`ENOTDIR`),n.parent.entries.delete(n.name),i.parent.entries.set(i.name,n.node),n.node instanceof c&&(n.node.parent=i.parent),n.parent.mtime=i.parent.mtime=s()}unlink(e){let{node:t,parent:n,name:r}=this.at(e);t instanceof c&&B(`EISDIR`),n.entries.delete(r),n.mtime=s()}rmdir(e){let{node:t,parent:n,name:r}=this.at(e);if(!(t instanceof c))return B(`ENOTDIR`);t.entries.size&&B(`ENOTEMPTY`),n.entries.delete(r),n.mtime=s()}readdir(e){let t=r(this.root,this.root,e,!0);return t.node?t.node instanceof c?[`.`,`..`,...t.node.entries.keys()]:B(`ENOTDIR`):H(t.error)}symlink(e,t){let{parent:n,name:r}=this.free(t);n.entries.set(r,new o(e)),n.mtime=s()}link(e,t){let{node:n}=this.at(e);n instanceof c&&B(`EPERM`);let{parent:r,name:i}=this.free(t);r.entries.set(i,n),r.mtime=s()}readlink(e){let{node:t}=this.at(e);return t instanceof o?t.target:B(`EINVAL`)}open(e,t){let i=r(this.root,this.root,e,!0);if(!i.node)return t&je?(this.writeFile(e),this.open(e,t&-65)):H(i.error);let a=i.node;if(a instanceof o)return B(`ELOOP`);a instanceof u&&n(a,this.fetch);let s=this.next++;return this.opened.set(s,{node:a,append:!!(t&Me)}),s}close(e){this.opened.delete(e)}read(e,t,n,r,i){let{node:a}=this.opened.get(e)??B(`EBADF`);if(a instanceof c)return B(`EISDIR`);if(a instanceof d){let e=a.read(r);return t.set(e,n),e.length}let o=a.bytes.subarray(i,i+r);return t.set(o,n),o.length}write(e,t,r,i,a){let o=this.opened.get(e)??B(`EBADF`),c=o.node;if(!(c instanceof u))return B(`EISDIR`);n(c,this.fetch);let l=o.append?c.size:a;return c.reserve(l+i),l>c.size&&c.data.fill(0,c.size,l),c.data.set(t.subarray(r,r+i),l),c.size=Math.max(c.size,l+i),c.mtime=s(),c.written=!0,i}},U=524288,W=class extends Error{constructor(e){super(e),this.code=e}},G=class{constructor(e){this.call=e}ask(e,t){let{answer:n}=this.call(e,t);if(n.error)throw new W(V(n.error));return n}lstat(e){let{type:t,size:n,ino:r,mtime:i}=this.ask({op:`stat`,path:e,follow:!1}),a=t===`dir`?16877:t===`link`?41471:33261,o=new Date(Number(BigInt(i)/1000000n));return{dev:2,ino:r,mode:a,nlink:1,uid:0,gid:0,rdev:0,size:t===`dir`?4096:n,atime:o,mtime:o,ctime:o,blksize:4096,blocks:Math.ceil(n/512)}}chmod(){}utime(){}truncate(e,t){let{handle:n}=this.ask({op:`open`,path:e});try{this.ask({op:`truncate`,handle:n,size:t})}finally{this.ask({op:`close`,handle:n})}}mkdir(e){this.ask({op:`mkdir`,path:e})}writeFile(e){let{handle:t}=this.ask({op:`open`,path:e,oflags:p.CREAT|p.EXCL});this.ask({op:`close`,handle:t})}rename(e,t){this.ask({op:`rename`,path:e,to:t})}unlink(e){this.ask({op:`unlink`,path:e})}rmdir(e){this.ask({op:`rmdir`,path:e})}readdir(e){let{handle:t}=this.ask({op:`open`,path:e,oflags:p.DIRECTORY});try{let{entries:e=[]}=this.ask({op:`readdir`,handle:t});return[`.`,`..`,...e.map(([e])=>e)]}finally{this.ask({op:`close`,handle:t})}}symlink(e,t){this.ask({op:`symlink`,path:t,target:e})}readlink(e){return this.ask({op:`readlink`,path:e}).target}link(e,t){this.ask({op:`link`,path:e,to:t,follow:!1})}open(e){return this.ask({op:`open`,path:e}).handle}close(e){this.ask({op:`close`,handle:e})}read(e,t,n,r,i){let a=0;for(;a<r;){let o=Math.min(r-a,U),{answer:s,bytes:c}=this.call({op:`read`,handle:e,offset:i+a,length:o});if(s.error)throw new W(V(s.error));if(t.set(c,n+a),a+=c.length,c.length<o)break}return a}write(e,t,n,r,i){for(let a=0;a<r;a+=U){let o=t.slice(n+a,n+Math.min(r,a+U));this.ask({op:`write`,handle:e,offset:i+a},o)}return r}},Pe=65536,Fe=new TextEncoder,Ie=(e,t)=>(n,r)=>(WebAssembly.instantiate(e,n).then(t=>r(t,e),t),{}),K=new Map;function q(e){if(!(`WorkerGlobalScope`in globalThis))return Promise.resolve(void 0);let t=new URL(`beam.emu.mjs`,new URL(e,location.href)).href,n=K.get(t);return n||(n=fetch(t).then(e=>{if(!e.ok)throw Error(`${t}: ${e.status}`);return e.blob()}).then(e=>URL.createObjectURL(new Blob([e],{type:`text/javascript`}))),n.catch(()=>K.delete(t)),K.set(t,n)),n}function J(e){let t=e.memory??new WebAssembly.Memory({initial:1024,maximum:65536,shared:!0}),n=null,r=!1,i=[],a=0,o=!1,s=!1,c=null,l=!1,u=(e,...t)=>n[`_${e}`](...t),d=()=>{c??=setTimeout(()=>{c=null,f()},20)},f=()=>{if(n&&!r){for(;i.length;){let e=Pe-a;if(e<=0)return;let n=i[0];n.length>e?(i[0]=n.subarray(e),n=n.subarray(0,e)):i.shift();let r=u(`malloc`,n.length);new Uint8Array(t.buffer).set(n,r);let o=u(`popcornStdinEnqueue`,r,n.length);if(u(`free`,r),o<0)return i.unshift(n),d();a+=n.length}if(o&&!s){if(u(`popcornStdinEof`)<0)return d();s=!0}}},p=e.size;return{done:new Promise((i,o)=>{let s=e=>{r||(r=!0,c&&clearTimeout(c),i(e))};Promise.all([x(()=>import(e.module),[]),q(e.module)]).then(([{default:r},i])=>r({arguments:e.args,beamThreadUrl:i,...e.tty?{}:{stdin:()=>null},wasmMemory:t,...e.wasm?{instantiateWasm:Ie(e.wasm,o)}:{},beamNetwork:e.network,beamHttpsGateway:e.httpsGateway,beamNifs:ze(e),beamSocketTrace:e.trace,onTtyChunk:(t,n)=>(t===2?e.stderr:e.stdout)(n),print:t=>e.stdout(Fe.encode(t+`
2
2
  `)),printErr:t=>{t.includes(`Heap resize call`)||e.stderr(Fe.encode(t+`
3
3
  `))},onTtyMode:t=>e.onMode?.(t),onStdinConsumed:e=>{l=!1,a-=e,f()},beamSpawn:(n,r,i,a,o)=>Re(e,t,n,r,i,a,o),onExit:s,onAbort:e=>o(Error(`the node aborted: ${e}`)),preRun:[r=>{n=r;let{FS:i,ENV:o}=r;if(e.tty&&r.TTY){let e=0;r.TTY.default_tty_ops.get_char=()=>{if(!l)return null;if(e||=u(`malloc`,1),!(u(`popcornStdinTake`,e,1)<1))return--a,f(),new Uint8Array(t.buffer)[e]}}let s=i.filesystems.PROXYFS,c=e.shared,d=(e,t)=>{try{t()}catch(t){throw Error(`${e}: errno ${t.errno}`,{cause:t})}},m=(e,t)=>d(`mounting ${e}`,()=>{i.analyzePath(e).exists||i.mkdir(e),i.mount(s,{root:e,fs:t},e)});for(let t of e.root.entries.keys())t!==`dev`&&t!==`proc`&&(c?.prefixes.includes(`/${t}`)||m(`/${t}`,e.fs));if(c){let e=new G(c.call);for(let t of c.prefixes)m(t,e)}Object.assign(o,e.env,{COLUMNS:String(p[0]),LINES:String(p[1])}),e.httpsGateway&&e.network.remote.https&&(o.PLAYGROUND_HTTPS_GATEWAY=String(e.httpsGateway)),d(`changing to ${e.cwd}`,()=>i.chdir(e.cwd))}]}).then(()=>f())).catch(o)}),input(e){i.push(e),f()},end(){o=!0,f()},resize(e,t){p=[e,t],n&&!r&&u(`popcornTtyResize`,e,t)},signal(e){if(!n||r)return!1;e===2&&(l=!0);try{u(`raise`,e)}catch(e){if(e.name!==`ExitStatus`)throw e}return!0},kill(e){if(n&&!r)try{u(`emscripten_force_exit`,e)}catch(e){if(e.name!==`ExitStatus`)throw e}}}}var Le=new Uint8Array;function Re(e,t,n,r,i,a,o){let s=e.programs??{},c=n.endsWith(`/sh`)&&r[0]===`-c`&&r[1]?.match(/^\s*"?([^\s"]+)"?\s*$/);c&&s[c[1].split(`/`).pop()]&&(n=c[1],r=[]);let l=n.split(`/`).pop(),u=s[l]??s[l.split(`-`)[0]]??s[`*`]?.(l);if(!u&&n.startsWith(`/`)&&s.escript){let t=we(e.root,e.fs.fetch,e.shared??null).read(n)?.subarray(0,64);t&&/^#!.*\bescript\b/.test(new TextDecoder().decode(t))&&(u=s.escript,r=[n,...r])}if(!u)return null;let d=new ee;d.notify=o;try{u(d,{args:r,cwd:i||a.PWD||`/`,env:a,root:e.root,memory:t})}catch(e){d.write(`${n}: ${e.message}\n`),d.exit(1)}return{read(e){let t=d.output[0];return t?t.length<=e?(d.output.shift(),t):(d.output[0]=t.subarray(e),t.subarray(0,e)):d.ended?null:Le},status:()=>d.status??-1,write:e=>d.oninput?d.oninput(e):d.input.push(e),kill(){d.notify=null,d.closed=!0,d.onclose?.()}}}function ze(e){let t=null,n=()=>(t??=new m(new _({args:[`nif`],env:e.env,root:e.root,stdin:()=>new Uint8Array,stdout:e.stdout,stderr:e.stderr,sleep:e=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e),fetch:e.fs.fetch,shared:e.shared??null})),t);return{open(e){let t=new TextDecoder().decode(n().create(e));return t.startsWith(`error `)?t.slice(6):Number(t)},call:(e,t)=>n().call(e,t)}}function Be(){if(!globalThis.crossOriginIsolated)return null;for(let e of[65536,32768,16384])try{return new WebAssembly.Memory({initial:1024,maximum:e,shared:!0})}catch{}return null}var Ve=Math.max(1,Math.min(4,navigator.hardwareConcurrency||1));async function He(e){let{channel:t}=e,n=J({module:e.module,args:Ae(e.argv,{home:e.env.HOME,root:e.root_otp}),env:{...e.env,ERL_INETRC:`/etc/inetrc`},cwd:e.cwd,root:e.root,fs:new Ne(e.root,e.fetch),shared:e.shared,network:e.network,programs:e.programs,httpsGateway:49151,tty:!0,size:[t.size[0],t.size[1]],onMode:e=>t.mode(e),stdout:e.stdout,stderr:e.stderr??e.stdout,memory:e.memory??void 0,wasm:e.wasm}),r={on:!0},i=t.size,a=null,o=()=>{t.pump(),t.input.length&&n.input(t.take(1/0)),t.size!==i&&(i=t.size,n.resize(i[0],i[1])),t.interrupted&&(t.interrupted=!1,n.signal(2)||(t.terminated=!0)),t.terminated&&(t.terminated=!1,t.input=[],a=130,n.kill(130))};(async()=>{for(;r.on;)o(),await t.rest(1e3)})();try{let e=await n.done;return a??e}finally{r.on=!1,Atomics.notify(t.control,0)}}async function Ue(e){if(!e)return null;let t=await fetch(e),n=new Uint8Array(await t.arrayBuffer());return!t.ok||n[0]!==0||n[1]!==97?null:WebAssembly.compile(n)}var We=[`/work`,`/tmp`,`/home`,`/shared`],Ge=1<<20,Y=(e,t)=>postMessage({kind:e,payload:t}),X=e=>Y(`out`,new TextEncoder().encode(e)),Ke=e=>Y(`err`,new TextEncoder().encode(e)),qe=e=>e!==void 0&&/^(sh|bash)$/.test(e.slice(e.lastIndexOf(`/`)+1));function Z(e,t){let n=(t.startsWith(`/`)?t:`${e}/${t}`).split(`/`),r=[];for(let e of n)e===`..`?r.pop():e&&e!==`.`&&r.push(e);return`/`+r.join(`/`)}var Q=[],Je=`/usr/bin/mix`,Ye=``;function Xe(e){let t=e.elixir(),n=e.otp();if(!t||!n)throw Error(`this site has no OTP and Elixir packages with files`);Q=[`-noshell`,`-elixir_root`,`${t.root}/lib`,`-pa`,`${t.root}/lib/elixir/ebin`,`-esbuild`,`path`,`<<"/usr/bin/esbuild">>`,`-tailwind`,`path`,`<<"/usr/bin/tailwind">>`],Je=e.bin().get(`mix`)??`/usr/bin/mix`,Ye=`${n.root}/bin/no_dot_erlang`}var Ze={"+elixirc":0,"+iex":0,"-v":0,"--no-halt":0,"--color":0,"--no-color":0,"-e":1,"-r":1,"-pr":1,"-pa":1,"-pz":1,"--eval":1,"--remsh":1,"--dot-iex":1,"--dbg":1,"--rpc-eval":2};function Qe(e){let t=[],n=[],r=0;for(;r<e.length;){let[i,a]=[e[r],e[r+1]];if(i in Ze)n.push(...e.slice(r,r+1+Ze[i])),r+=1+Ze[i];else if(i===`--hidden`)t.push(`-hidden`),r+=1;else if(i===`--erl`&&a!==void 0)t.push(...v(a)),r+=2;else if((i===`--sname`||i===`--name`)&&a!==void 0)t.push(i.slice(1),a),r+=2;else if(i===`--cookie`&&a!==void 0)t.push(`-setcookie`,a),r+=2;else if(i===`--boot`&&a!==void 0)t.push(`-boot`,a),r+=2;else if(i===`--erl-config`&&a!==void 0)t.push(`-config`,a),r+=2;else if((i===`--logger-otp-reports`||i===`--logger-sasl-reports`)&&a!==void 0)(a===`true`||a===`false`)&&t.push(`-logger`,`handle_${i.slice(9,-8)}_reports`,a),r+=2;else break}return{erl:t,cli:[...n,...e.slice(r)]}}function $e(e,t){let n=t.PLAYGROUND_COOKIE;return n&&!e.includes(`-setcookie`)?[`-setcookie`,n]:[]}function et(e){if(!e)return[];let t=new TextDecoder().decode(e.subarray(0,4096)).split(`
4
4
  `).slice(1,3).find(e=>e.startsWith(`%%!`));return t?v(t.slice(3).trim()):[]}function $(e,t,n=()=>null){switch(e){case`erl`:return t;case`elixir`:{let{erl:e,cli:n}=Qe(t);return[...Q,...e,`-s`,`elixir`,`start_cli`,`-extra`,...n]}case`mix`:{let{erl:e,cli:n}=Qe(t);return[...Q,...e,`-s`,`elixir`,`start_cli`,`-extra`,Je,...n]}case`iex`:{let{erl:e,cli:n}=Qe(t),r=n[0]===`-S`&&n[1]===`mix`?[Je,...n.slice(2)]:n;return[...Q,...e,`-user`,`elixir`,`-extra`,`--no-halt`,`+iex`,...r]}case`escript`:return t.length?[`+B`,`-noshell`,`-boot`,Ye,...et(n(t[0])),`-run`,`escript`,`start`,`-extra`,...t]:null}return null}var tt=`Commands: iex, elixir, mix, erl (each runs OTP), git (clone, pull),
@@ -1 +0,0 @@
1
- import{b as e,d as t,f as n,i as r,l as i,m as a,n as o,r as s,t as c,v as l,x as u,y as d}from"./fs-GnBaZCKr.js";var f=class{constructor(e){this.inbox=[],this.eof=!1,this.peer=e,this.status=1}connected(e){this.status===0&&(this.status=e,this.notify?.())}receive(e){this.inbox.push(e),this.notify?.()}finish(){this.eof=!0,this.notify?.()}take(e){let t=new Uint8Array(Math.min(e,this.inbox.reduce((e,t)=>e+t.length,0))),n=0;for(;n<t.length;){let e=this.inbox[0],r=e.subarray(0,t.length-n);t.set(r,n),n+=r.length,r.length===e.length?this.inbox.shift():this.inbox[0]=e.subarray(r.length)}return t}},p=49152+Math.floor(Math.random()*16384);function m(){let e=p;return p=p>=65535?49152:p+1,e}function h(e){if(!e.includes(`:`))return e.startsWith(`127.`)||e===`0.0.0.0`;let t=e.split(`:`).map(e=>parseInt(e,16)||0);return t.length===8&&t.slice(0,7).every(e=>e===0)?t[7]<=1:t.length===8&&t.slice(0,5).every(e=>e===0)&&t[5]===65535&&t[6]>>8==127}var g=-40,_=class{constructor(e={ports:[],open(){},send(){},end(){},close(){}}){this.remote=e,this.listeners=new Map,this.waiting=new Map,this.endpoints=new Map,this.next=2,this.peers=new Set,this.udp=new Map}listen(e){let t=e===0,n=e=>this.listeners.has(e)||this.peers.has(e);if(t)do e=m();while(n(e));if(n(e))return null;let r=[];return this.listeners.set(e,r),this.remote.listening?.(e,!0,t),{queue:r,port:e}}accepted(e,t){let n=this.listeners.get(t);if(!n)return!1;let r=this.remote,i=new f({send:t=>r.send(e,t),end:()=>r.end(e),close:()=>{this.endpoints.delete(e),r.close(e)}});return this.endpoints.set(e,i),this.waiting.set(e,i),n.push({id:e,ip:`127.0.0.1`,port:m()}),this.onqueue?.get(t)?.(),!0}connect(e){let t=this.listeners.get(e);if(t){let n=this.next+=2,r,i=new f({send:e=>r.receive(e),end:()=>r.finish(),close:()=>r.finish()});return r=new f({send:e=>i.receive(e),end:()=>i.finish(),close:()=>i.finish()}),this.waiting.set(n,i),t.push({id:n,ip:`127.0.0.1`,port:m()}),this.onqueue?.get(e)?.(),r}if(!this.remote.ports.includes(e)&&!this.peers.has(e))return null;let n=this.next+=2,r=this.remote,i=new f({send:e=>r.send(n,e),end:()=>r.end(n),close:()=>{this.endpoints.delete(n),r.close(n)}});return this.endpoints.set(n,i),r.open(n,e),i}https(e,t){if(!this.remote.https)return null;let n=this.next+=2,r=this.remote,i=new f({send:e=>r.send(n,e),end:()=>r.end(n),close:()=>{this.endpoints.delete(n),r.close(n)}});return this.endpoints.set(n,i),r.open(n,t,e),i}dial(e,t){let n=this.next+=2,r=this.remote,i=new f({send:e=>r.send(n,e),end:()=>r.end(n),close:()=>{this.endpoints.delete(n),r.close(n)}});return i.status=0,this.endpoints.set(n,i),r.dial?r.dial(n,e,t):i.connected(g),i}connected(e,t,n){let r=this.endpoints.get(e);r&&(t!==1&&this.endpoints.delete(e),r.local=n,r.connected(t))}udpBind(e){if(e===0)do e=m();while(this.udp.has(e));if(this.udp.has(e))return null;let t={port:e,queue:[]};return this.udp.set(e,t),this.remote.bound?.(e),t}udpUnbind(e){this.udp.delete(e)&&this.remote.unbound?.(e)}udpSend(e,t,n,r){let i=h(t)?this.udp.get(n):null;i?(i.queue.push({address:`127.0.0.1`,port:e,bytes:r}),i.notify?.()):this.remote.datagram?.(e,t,n,r)}datagram(e,t,n,r){let i=this.udp.get(e);i&&(i.queue.push({address:t,port:n,bytes:r}),i.notify?.())}data(e,t){this.endpoints.get(e)?.receive(t)}ended(e){this.endpoints.get(e)?.finish()}unlisten(e){this.listeners.delete(e)&&this.remote.listening?.(e,!1)}},v=1024,y=1,b=1025,x=2049,S=()=>new SharedArrayBuffer(12292);function C(e,t){let n=new Int32Array(e);for(let e=2;e<v;e++)if(Atomics.compareExchange(n,y+e,0,t)===0)return e;throw Error(`a process has at most 1022 worker threads`)}function w(e,t,n){for(let r=t;r>1;r=Atomics.load(e,y+r))if(r===n)return!0;return n===1}function T(e,t){Atomics.store(new Int32Array(e),b+t,1)}function E(e,t){let n=new Int32Array(e),r=[];for(let e=2;e<v;e++)Atomics.load(n,y+e)&&w(n,e,t)&&r.push(e);for(let e of r)Atomics.store(n,b+e,0),Atomics.store(n,x+e,0),Atomics.store(n,y+e,0)}function D(e,t){let n=new Int32Array(e);for(let e=1;e<v;e++)if(Atomics.load(n,x+e)&&w(n,e,t))return!0;let r=Atomics.load(n,0);return r!==0&&w(n,r,t)}function O(e,t,n,r=1){let i=k(e,t);if(!n)return i;let a=new Int32Array(n),o=()=>{for(let e=r;e>1;e=Atomics.load(a,y+e))if(Atomics.load(a,b+e))return b+e;return-1},s=e=>Atomics.store(a,x+r,e);return(e,t)=>{s(1);for(let e;;){let t=o();if(t>=0)for(s(0);;)Atomics.wait(a,t,1);if((e=Atomics.compareExchange(a,0,0,r))===0)break;Atomics.wait(a,0,e,10)}try{return i(e,t)}finally{Atomics.store(a,0,0),Atomics.notify(a,0,1),s(0)}}}function k(e,t){let n=new Int32Array(e),r=new Int32Array(t,0,2),i=new Uint8Array(t,8),a=new DataView(t,8),o=new TextEncoder,s=new TextDecoder;return(e,t=new Uint8Array)=>{let c=o.encode(JSON.stringify(e));for(a.setUint32(0,c.length,!0),i.set(c,4),i.set(t,4+c.length),Atomics.store(r,1,4+c.length+t.length),Atomics.store(r,0,1),Atomics.add(n,0,1),Atomics.notify(n,0);Atomics.load(r,0)===1;)Atomics.wait(r,0,1,1e3);let l=a.getUint32(0,!0),u=Atomics.load(r,1),d=JSON.parse(s.decode(i.slice(4,4+l))),f=i.slice(4+l,u);return Atomics.store(r,0,0),{answer:d,bytes:f}}}var A=524288;function j(t){return t===`dir`?e.DIR:t===`link`?e.SYMLINK:e.REG}function M(e,t){return e.shared.prefixes.some(e=>t===e||t.startsWith(`${e}/`))}function N(e,t,{type:n,size:r,ino:i,mtime:a}){let o=e.view();o.setBigUint64(t,2n,!0),o.setBigUint64(t+8,BigInt(i),!0),o.setUint8(t+16,j(n)),o.setBigUint64(t+24,1n,!0),o.setBigUint64(t+32,BigInt(r),!0),o.setBigUint64(t+40,BigInt(a),!0),o.setBigUint64(t+48,BigInt(a),!0),o.setBigUint64(t+56,BigInt(a),!0)}function P(t,n){let r=(e,n)=>t.shared.call(e,n),i=(e,t)=>r(e,t).answer,a=(e,n,r)=>t.absolute(e,t.string(n,r)),o=e=>t.fds.get(e)?.remote,s=(e,r)=>(o,s,c)=>{let u=a(o,s,c);return M(t,u)?i({op:e,path:u}).error??l.SUCCESS:n[r](o,s,c)};return{path_open(e,r,o,s,c,u,f,p,m){let h=a(e,o,s);if(!M(t,h))return n.path_open(e,r,o,s,c,u,f,p,m);let g=i({op:`open`,path:h,oflags:c,follow:!!(r&1)});if(g.error)return g.error;let _=t.next++;return t.fds.set(_,{path:h,remote:{handle:g.handle,position:0,append:!!(p&d.APPEND),dir:g.type===`dir`,listing:null}}),t.view().setUint32(m,_,!0),l.SUCCESS},path_filestat_get(e,r,o,s,c){let u=a(e,o,s);if(!M(t,u))return n.path_filestat_get(e,r,o,s,c);let d=i({op:`stat`,path:u,follow:!!(r&1)});return d.error?d.error:(N(t,c,d),l.SUCCESS)},path_symlink(e,r,o,s,c){let u=a(o,s,c);return M(t,u)?i({op:`symlink`,path:u,target:t.string(e,r)}).error??l.SUCCESS:n.path_symlink(e,r,o,s,c)},path_readlink(e,r,o,s,c,u){let d=a(e,r,o);if(!M(t,d))return n.path_readlink(e,r,o,s,c,u);let f=i({op:`readlink`,path:d});if(f.error)return f.error;let p=new TextEncoder().encode(f.target).subarray(0,c);return t.bytes(s,p.length).set(p),t.view().setUint32(u,p.length,!0),l.SUCCESS},path_create_directory:s(`mkdir`,`path_create_directory`),path_remove_directory:s(`rmdir`,`path_remove_directory`),path_unlink_file:s(`unlink`,`path_unlink_file`),path_rename(e,r,o,s,c,u){let d=a(e,r,o),f=a(s,c,u);return!M(t,d)&&!M(t,f)?n.path_rename(e,r,o,s,c,u):M(t,d)===M(t,f)?i({op:`rename`,path:d,to:f}).error??l.SUCCESS:75},path_link(e,r,o,s,c,u,d){let f=a(e,o,s),p=a(c,u,d);return!M(t,f)&&!M(t,p)?n.path_link(e,r,o,s,c,u,d):M(t,f)===M(t,p)?i({op:`link`,path:f,to:p,follow:!!(r&1)}).error??l.SUCCESS:75},fd_read(e,i,a,s){let c=o(e);if(!c)return n.fd_read(e,i,a,s);if(c.dir)return l.ISDIR;let u=0;for(let[e,n]of t.iovecs(i,a)){let i=0;for(;i<n;){let a=Math.min(n-i,A),{answer:o,bytes:s}=r({op:`read`,handle:c.handle,offset:c.position,length:a});if(o.error)return o.error;if(t.bytes(e+i,s.length).set(s),i+=s.length,c.position+=s.length,s.length<a)break}if(u+=i,i<n)break}return t.view().setUint32(s,u,!0),l.SUCCESS},fd_write(e,r,a,s){let c=o(e);if(!c)return n.fd_write(e,r,a,s);let u=0;for(let[e,n]of t.iovecs(r,a)){for(let r=0;r<n;r+=A){let a=t.bytes(e+r,Math.min(A,n-r)).slice(),o=i({op:`write`,handle:c.handle,offset:c.position,append:c.append},a);if(o.error)return o.error;c.position=o.position}u+=n}return t.view().setUint32(s,u,!0),l.SUCCESS},fd_seek(e,r,a,s){let c=o(e);if(!c)return n.fd_seek(e,r,a,s);let u=a===2?i({op:`fstat`,handle:c.handle}).size:0,d=[0,c.position,u][a];if(d===void 0)return l.INVAL;let f=d+Number(r);return f<0?l.INVAL:(c.position=f,t.view().setBigUint64(s,BigInt(f),!0),l.SUCCESS)},fd_filestat_get(e,r){let a=o(e);if(!a)return n.fd_filestat_get(e,r);let s=i({op:`fstat`,handle:a.handle});return s.error?s.error:(N(t,r,s),l.SUCCESS)},fd_filestat_set_size(e,t){let r=o(e);return r?i({op:`truncate`,handle:r.handle,size:Number(t)}).error??l.SUCCESS:n.fd_filestat_set_size(e,t)},fd_allocate(e,t,r){let a=o(e);if(!a)return n.fd_allocate(e,t,r);let s=i({op:`fstat`,handle:a.handle});if(s.error)return s.error;let c=Number(t+r);return c<=s.size?l.SUCCESS:i({op:`truncate`,handle:a.handle,size:c}).error??l.SUCCESS},fd_fdstat_get(r,i){let a=o(r);if(!a)return n.fd_fdstat_get(r,i);let s=t.view();return s.setUint8(i,a.dir?e.DIR:e.REG),s.setUint16(i+2,a.append?d.APPEND:0,!0),s.setBigUint64(i+8,18446744073709551615n,!0),s.setBigUint64(i+16,18446744073709551615n,!0),l.SUCCESS},fd_readdir(e,r,a,s,c){let u=o(e);if(!u)return n.fd_readdir(e,r,a,s,c);if(!u.dir)return l.NOTDIR;if(!u.listing||s===0n){let e=i({op:`readdir`,handle:u.handle});if(e.error)return e.error;u.listing=e.entries}let d=0;for(let e=Number(s);e<u.listing.length&&d<a;e++){let[n,i,o]=u.listing[e],s=new TextEncoder().encode(n),c=new Uint8Array(24+s.length),l=new DataView(c.buffer);l.setBigUint64(0,BigInt(e+1),!0),l.setBigUint64(8,BigInt(o),!0),l.setUint32(16,s.length,!0),l.setUint8(20,j(i)),c.set(s,24);let f=Math.min(c.length,a-d);t.bytes(r+d,f).set(c.subarray(0,f)),d+=f}return t.view().setUint32(c,d,!0),l.SUCCESS},fd_close(e){let r=o(e);return r?(t.fds.delete(e),i({op:`close`,handle:r.handle}).error??l.SUCCESS):n.fd_close(e)}}}var F={name:`@elixir-playground/runtime`,version:`1.0.0`,provides:{manifest:[2],fs:[3],wasi:[1],processes:[1],crossterm:[1],beam:[1],tls:[1],tailscale:[1],nif:[1]}}.provides.nif;function I(e){let t=new TextEncoder().encode(e),n=new Uint8Array(15+t.length);return n.set([131,104,2,119,5,...new TextEncoder().encode(`error`),109]),new DataView(n.buffer).setUint32(11,t.length),n.set(t,15),n}var L=52;function R(e,t){let n=WebAssembly.Module.imports(e).filter(({module:e,kind:n,name:r})=>e===`wasi_snapshot_preview1`&&n===`function`&&!(r in t)).map(({name:e})=>[e,()=>L]);return n.length?{...t,...Object.fromEntries(n)}:t}var z=class{constructor(e){this.wasi=e,this.instances=new Map,this.next=1}within(e,t){let n=this.wasi.memory;this.wasi.memory=e.exports.memory;try{return t()}finally{this.wasi.memory=n}}create(e){try{let t=new WebAssembly.Module(e),n=WebAssembly.Module.exports(t).some(({name:e})=>e===`beamos_nif_abi`),r=new WebAssembly.Instance(t,{wasi_snapshot_preview1:R(t,this.wasi.imports.wasi_snapshot_preview1)}),i=r.exports,a=n?i.beamos_nif_abi():null;if(a===null||!F.includes(a))throw Error(`built for ${a===null?`an unnumbered erl_nif layer`:`erl_nif layer ${a}`}, not ${F.join(` or `)}: build it again`);this.within(r,()=>i._initialize?.());let o=this.next++;return this.instances.set(o,r),new TextEncoder().encode(String(o))}catch(e){return new TextEncoder().encode(`error ${e.message}`)}}call(e,t){let n=this.instances.get(e);if(!n)return I(`no such NIF library`);try{return this.within(n,()=>{let{memory:e,beamos_nif_input:r,beamos_nif_run:i,beamos_nif_output:a}=n.exports;new Uint8Array(e.buffer,r(t.length)>>>0,t.length).set(t);let o=i(t.length);return new Uint8Array(e.buffer,a()>>>0,o>>>0).slice()})}catch(t){if(this.instances.delete(e),t instanceof q)return I(`the NIF library exited (${t.code})`);if(t instanceof WebAssembly.RuntimeError)return I(`the NIF library crashed: ${t.message}`);throw t}}answer(e,t){return e===`new`?this.create(t):this.call(Number(e),t)}},B=class{constructor(){this.output=[],this.errors=null,this.ended=!1,this.status=null,this.input=[],this.closed=!1,this.taken=0}write(e){this.output.push(typeof e==`string`?new TextEncoder().encode(e):e),this.notify?.()}writeError(e){if(!this.errors)return this.write(e);this.errors.push(typeof e==`string`?new TextEncoder().encode(e):e),this.notify?.()}exit(e){this.ended=!0,this.status=e,this.notify?.()}};function V(e,t,n){let r=new TextDecoder().decode(n.slice()).split(`\0`),[i,a]=r,o=Number(r[2]),s=r.slice(3,3+o),c=Number(r[3+o]),u=Object.fromEntries(r.slice(4+o,4+o+c).map(e=>{let t=e.indexOf(`=`);return[e.slice(0,t),e.slice(t+1)]})),d=i.split(`/`).pop(),f=e.programs[d]??e.programs[d.split(`-`)[0]]??e.programs[`*`]?.(d);if(!f)return l.NOENT;let p=new B;t.process=p;try{f(p,{args:s,cwd:a||u.PWD||`/`,env:u,root:e.root})}catch(e){p.write(`${i}: ${e.message}\n`),p.exit(1)}return null}function H(n){let f=l.SUCCESS;return{fd_prestat_get(e,t){let r=n.fds.get(e);if(!r||!r.preopen)return l.BADF;let i=n.view();return i.setUint8(t,0),i.setUint32(t+4,new TextEncoder().encode(r.preopen).length,!0),f},fd_prestat_dir_name(e,t,r){let i=n.fds.get(e);return!i||!i.preopen?l.BADF:(n.bytes(t,r).set(new TextEncoder().encode(i.preopen).subarray(0,r)),f)},fd_fdstat_get(t,r){let i=n.fds.get(t);if(!i)return l.BADF;let a=n.view(),s=i.stream?e.CHAR:i.node instanceof o?e.DIR:e.REG;a.setUint8(r,i.pipe?e.CHAR:s),a.setUint16(r+2,i.append?d.APPEND:0,!0);let c=i.stream&&(i.tty??n.tty)?18446744073709551579n:18446744073709551615n;return a.setBigUint64(r+8,c,!0),a.setBigUint64(r+16,c,!0),f},fd_fdstat_set_flags:()=>f,fd_close(e){if(!n.fds.has(e)||e<3)return e<3?f:l.BADF;let t=n.fds.get(e);return t.endpoint&&t.endpoint.peer.close(),t.listener&&(n.network.listeners.delete(t.port),n.network.remote.listening?.(t.port,!1)),t.changed&&n.onchange(t.path),t.process&&(t.process.closed=!0,t.process.onclose?.()),n.fds.delete(e),f},fd_sync:()=>f,fd_datasync:()=>f,fd_advise:()=>f,fd_fdstat_set_rights:()=>f,fd_filestat_get(e,t){let r=n.fds.get(e);if(!r)return l.BADF;if(r.spawn){let e=r.process?.status;return n.filestat(t,{ino:0n,size:e==null?0:e+1,mtime:a()}),f}return r.listener?(n.filestat(t,{ino:0n,size:r.port,mtime:a()}),f):(n.filestat(t,r.stream||r.pipe?null:r.node),f)},fd_filestat_set_size(e,t){let r=n.fds.get(e);return r?.endpoint?(r.endpoint.peer.end(),f):r?.process?(r.process.closed=!0,f):!r||!(r.node instanceof s)?l.BADF:(r.node.truncate(Number(t)),r.changed=!0,f)},fd_allocate(e,t,r){let i=n.fds.get(e);if(!i||!(i.node instanceof s))return i?l.SPIPE:l.BADF;let a=Number(t+r);return a>i.node.size&&(i.node.truncate(a),i.changed=!0),f},fd_filestat_set_times:()=>f,path_filestat_set_times:()=>f,fd_read(e,t,r,i){let a=n.fds.get(e);if(!a)return l.BADF;n.pump();let o=0,u=a.endpoint||a.listener;if(a.pipe){if(!a.reads)return l.BADF;let e=n.iovecs(t,r).reduce((e,[,t])=>e+t,0),i=a.pipe.read(e);if(!i)return n.block(a.pipe.changed());for(let[e,a]of n.iovecs(t,r)){let t=i.subarray(o,o+a);n.bytes(e,t.length).set(t),o+=t.length}}else if(a.nif){if(!a.answer){let e=new Uint8Array(a.request.reduce((e,t)=>e+t.length,0)),t=0;for(let n of a.request)e.set(n,t),t+=n.length;a.answer=n.nifs.answer(a.nif,e)}for(let[e,i]of n.iovecs(t,r)){let t=a.answer.subarray(a.position,a.position+i);if(n.bytes(e,t.length).set(t),a.position+=t.length,o+=t.length,t.length<i)break}}else if(a.spawn){let e=a.process;if(!e)return l.BADF;let[i,s]=n.iovecs(t,r)[0]||[0,0];if(e.output.length){let t=e.output[0],r=t.subarray(0,s);n.bytes(i,r.length).set(r),r.length===t.length?e.output.shift():e.output[0]=t.subarray(r.length),o=r.length}else if(!e.ended)return l.AGAIN}else if(u){let[e,i]=n.iovecs(t,r)[0]||[0,0],s;if(a.listener){let e=a.listener.shift();if(!e)return l.AGAIN;s=new TextEncoder().encode(`${e.id} ${e.ip} ${e.port}`)}else if(a.endpoint.inbox.length)s=a.endpoint.take(i);else if(a.endpoint.eof)s=new Uint8Array;else return l.AGAIN;n.bytes(e,s.length).set(s.subarray(0,i)),o=Math.min(i,s.length)}else if(a.node instanceof c)for(let[e,i]of n.iovecs(t,r)){let t=a.node.read(i);if(n.bytes(e,t.length).set(t),o+=t.length,t.length<i)break}else if(a.stream&&(a.source||e===0)){let e=n.iovecs(t,r).reduce((e,[,t])=>e+t,0),i=(a.source??n.stdin)(e);if(i===null)return a.ready?n.block(a.ready()):l.AGAIN;let s=0;for(let[e,a]of n.iovecs(t,r)){let t=i.subarray(s,s+a);n.bytes(e,t.length).set(t),s+=t.length}o=s}else{let e=a.node;if(!(e instanceof s))return l.ISDIR;for(let[i,s]of n.iovecs(t,r)){let t=e.bytes.subarray(a.position,a.position+s);if(n.bytes(i,t.length).set(t),a.position+=t.length,o+=t.length,t.length<s)break}}return n.view().setUint32(i,o,!0),f},fd_write(e,t,r,i){let o=n.fds.get(e);if(!o)return l.BADF;let u=0;if(o.pipe){if(o.reads)return l.BADF;for(let[e,i]of n.iovecs(t,r)){let t=o.pipe.write(n.bytes(e,i),n.suspending&&n.bounded);if(t===-1&&!u)return l.PIPE;if(t===null&&!u)return n.block(o.pipe.changed());if(t===null||t===-1||(u+=t,t<i))break}return n.view().setUint32(i,u,!0),f}for(let[i,d]of n.iovecs(t,r)){let t=n.bytes(i,d);if(o.nif)o.request.push(t.slice());else if(o.terminal)n.terminal.mode(new TextDecoder().decode(t.slice()).trim());else if(o.spawn&&!o.process){let e=V(n,o,t);if(e)return e}else if(o.spawn)o.process.input.push(t.slice());else if(o.endpoint)o.endpoint.peer.send(t.slice());else if(o.stream){let r=o.sink??n.out[e];r&&r(t.slice())}else if(!(o.node instanceof c)){let e=o.node;if(!(e instanceof s))return l.ISDIR;o.append&&(o.position=e.size);let n=o.position+d;e.reserve(n),e.data.set(t,o.position),n>e.size&&(e.size=n),e.mtime=a(),e.written=!0,o.changed=!0,o.position=n}u+=d}return n.view().setUint32(i,u,!0),f},fd_seek(e,t,r,i){let a=n.fds.get(e);if(!a)return l.BADF;if(a.stream||a.pipe)return l.SPIPE;let o=a.node instanceof s?a.node.size:0,c=[0,a.position,o][r];if(c===void 0)return l.INVAL;let u=c+Number(t);return u<0?l.INVAL:(a.position=u,n.view().setBigUint64(i,BigInt(u),!0),f)},fd_readdir(e,t,r,a,s){let c=n.fds.get(e);if(!c||!(c.node instanceof o))return l.NOTDIR;let u=n.view(),d=[...c.node.entries.entries()],p=0;for(let e=Number(a);e<d.length&&p<r;e++){let[a,o]=d[e],s=new TextEncoder().encode(a),c=new Uint8Array(24),l=new DataView(c.buffer);l.setBigUint64(0,BigInt(e+1),!0),l.setBigUint64(8,o.ino,!0),l.setUint32(16,s.length,!0),l.setUint8(20,i(o));let u=new Uint8Array(24+s.length);u.set(c),u.set(s,24);let f=Math.min(u.length,r-p);n.bytes(t+p,f).set(u.subarray(0,f)),p+=f}return u.setUint32(s,p,!0),f},path_open(e,i,c,p,m,h,g,_,v){let y=n.string(c,p).replace(/^\/+/,``);if(y===`.proc/spawn`){let e=n.next++;return n.fds.set(e,{spawn:!0,process:null}),n.view().setUint32(v,e,!0),f}if(y.startsWith(`.tty/`)){let e;if(!n.terminal)return l.NOENT;if(y===`.tty/mode`)e={terminal:!0,node:new s};else if(y===`.tty/size`)e={node:new s(new TextEncoder().encode(n.terminal.size().join(` `))),position:0};else return l.NOENT;let t=n.next++;return n.fds.set(t,e),n.view().setUint32(v,t,!0),f}if(y.startsWith(`.nif/`)){let e=n.next++;return n.fds.set(e,{nif:y.slice(5),request:[],answer:null,position:0}),n.view().setUint32(v,e,!0),f}if(y.startsWith(`.net/`)){let[,e,t,r]=y.split(`/`),i=n.network,a;if(e===`listen`){let e=i.listen(Number(r));if(!e)return l.ADDRINUSE;a={listener:e.queue,port:e.port}}else if(e===`conn`){let e=i.waiting.get(Number(t));if(!e)return l.NOENT;i.waiting.delete(Number(t)),a={endpoint:e}}else if(e===`connect`){let e=i.connect(Number(r));if(!e)return l.CONNREFUSED;a={endpoint:e}}else if(e===`https`){let e=i.https(t,Number(r));if(!e)return l.NOENT;a={endpoint:e}}else return l.NOENT;let o=n.next++;return n.fds.set(o,a),n.view().setUint32(v,o,!0),f}let b=n.resolve(e,n.string(c,p),!!(i&1)),x=b.node,S=!1;if(x&&m&u.CREAT&&m&u.EXCL)return l.EXIST;if(x instanceof r)return l.LOOP;if(!x){if(!(m&u.CREAT)||!b.parent)return b.error;x=new s,x.written=!0,S=!0,b.parent.entries.set(b.name,x),b.parent.mtime=a()}if(m&u.DIRECTORY&&!(x instanceof o))return l.NOTDIR;try{t(x,n.fetch)}catch{return l.IO}x instanceof s&&m&u.TRUNC&&(x.truncate(0),x.written=!0,S=!0);let C=n.next++;return n.fds.set(C,{node:x,position:0,append:!!(_&d.APPEND),path:n.absolute(e,n.string(c,p)),changed:S}),n.view().setUint32(v,C,!0),f},path_filestat_get(e,t,r,i,a){let o=n.resolve(e,n.string(r,i),!!(t&1));return o.node?(n.filestat(a,o.node),f):o.error},path_create_directory(e,t,r){let i=n.resolve(e,n.string(t,r));if(i.node)return l.EXIST;if(!i.parent)return i.error;let a=new o;return a.parent=i.parent,i.parent.entries.set(i.name,a),n.onchange(n.absolute(e,n.string(t,r))),f},path_remove_directory(e,t,r){let i=n.resolve(e,n.string(t,r));return i.node?i.node instanceof o?i.node.entries.size?l.NOTEMPTY:(i.parent.entries.delete(i.name),n.onchange(n.absolute(e,n.string(t,r))),f):l.NOTDIR:i.error},path_unlink_file(e,t,r){let i=n.resolve(e,n.string(t,r));return i.node?i.node instanceof o?l.ISDIR:(i.parent.entries.delete(i.name),n.onchange(n.absolute(e,n.string(t,r))),f):i.error},path_rename(e,t,r,i,a,s){let c=n.resolve(e,n.string(t,r));if(!c.node)return c.error;let u=n.resolve(i,n.string(a,s));return u.parent?u.node instanceof o&&u.node.entries.size?l.NOTEMPTY:(c.parent.entries.delete(c.name),u.parent.entries.set(u.name,c.node),c.node instanceof o&&(c.node.parent=u.parent),n.onchange(n.absolute(e,n.string(t,r))),n.onchange(n.absolute(i,n.string(a,s))),f):u.error},path_link(e,t,r,i,a,s,c){let u=n.resolve(e,n.string(r,i),!!(t&1));if(!u.node)return u.error;if(u.node instanceof o)return l.PERM;let d=n.resolve(a,n.string(s,c));return d.node?l.EXIST:d.parent?(d.parent.entries.set(d.name,u.node),n.onchange(n.absolute(a,n.string(s,c))),f):d.error},path_symlink(e,t,i,o,s){let c=n.resolve(i,n.string(o,s));return c.node?l.EXIST:c.parent?(c.parent.entries.set(c.name,new r(n.string(e,t))),c.parent.mtime=a(),n.onchange(n.absolute(i,n.string(o,s))),f):c.error},path_readlink(e,t,i,a,o,s){let c=n.resolve(e,n.string(t,i));if(!c.node)return c.error;if(!(c.node instanceof r))return l.INVAL;let u=new TextEncoder().encode(c.node.target).subarray(0,o);return n.bytes(a,u.length).set(u),n.view().setUint32(s,u.length,!0),f},sock_accept:()=>l.NOSYS,sock_shutdown:()=>l.NOSYS}}var U=65536,W=class{constructor(){this.chunks=[],this.size=0,this.readers=0,this.writers=0,this.waiting=[]}read(e){if(!this.size)return this.writers?null:new Uint8Array;let t=new Uint8Array(Math.min(e,this.size)),n=0;for(;n<t.length;){let e=this.chunks[0],r=e.subarray(0,t.length-n);t.set(r,n),n+=r.length,r.length===e.length?this.chunks.shift():this.chunks[0]=e.subarray(r.length)}return this.size-=t.length,this.wake(),t}write(e,t=!0){if(!this.readers)return-1;if(!e.length)return 0;let n=t?U-this.size:e.length;if(n<=0)return null;let r=e.slice(0,n);return this.chunks.push(r),this.size+=r.length,this.wake(),r.length}changed(){return new Promise(e=>this.waiting.push(e))}open(e){e?this.readers++:this.writers++}close(e){e?this.readers--:this.writers--,this.wake()}wake(){let e=this.waiting.splice(0);for(let t of e)t()}};function G(e,t){let n=t=>{let n=e.fds.get(t);if(!n)return l.BADF;let r=n.remote??(n.node instanceof s?n:null);return r&&!n.nif?r:l.SPIPE},r=(e,t,r)=>{let i=n(e);if(typeof i==`number`)return i;let[a,o]=[i.position,i.append];Object.assign(i,{position:Number(t),append:!1});try{return r()}finally{Object.assign(i,{position:a,append:o})}};return{fd_pread:(e,n,i,a,o)=>r(e,a,()=>t.fd_read(e,n,i,o)),fd_pwrite:(e,n,i,a,o)=>r(e,a,()=>t.fd_write(e,n,i,o)),fd_tell(t,r){let i=n(t);return typeof i==`number`?i:(e.view().setBigUint64(r,BigInt(i.position),!0),l.SUCCESS)}}}var K=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>t(...e.map(e=>typeof e==`number`?e>>>0:e))])),q=class extends Error{constructor(e){super(`exit ${e}`),this.code=e}},J=class{constructor({args:e,env:t,root:n,stdin:r,stdout:i,stderr:a,sleep:o,tty:s=!1,terminal:c=null,network:l=new _,pump:u=()=>{},fetch:d,programs:f={},onchange:p=()=>{},shared:m=null,suspending:h=!1,bounded:g=!0}){this.suspending=h,this.bounded=g,this.blocked=null,this.interrupt=null,this.stack=null,this.strand=0,this.exports=null,this.shared=m,this.terminal=c,this.onchange=p,this.fetch=d,this.programs=f,this.tty=s,this.network=l,this.pump=u,this.args=e,this.env=Object.entries(t).map(([e,t])=>`${e}=${t}`),this.root=n,this.stdin=r,this.out={1:i,2:a},this.sleep=o,this.fds=new Map([[0,{stream:!0}],[1,{stream:!0}],[2,{stream:!0}],[3,{node:n,preopen:`/`,path:``}]]),this.next=4,this.memory=null,this.nifs=new z(this);let v=this.functions(),y=m?{...v,...P(this,v)}:v;this.io=y;let b=K({...y,...G(this,y),fd_close:e=>this.close(e),fd_renumber:(e,t)=>this.renumber(e,t)});this.imports={wasi_snapshot_preview1:h?this.suspend(b):b}}block(e){return this.suspending&&(this.blocked=e),l.AGAIN}async suspended(e){let t=this.stack?.value,n=this.strand;try{return await e}finally{this.stack&&(this.stack.value=t),this.strand=n}}suspend(e){let t={...e},n=async(e,t)=>{let n=l.AGAIN;for(;this.blocked;){let r=this.blocked;this.blocked=null,await this.suspended(this.interrupt?Promise.race([r,this.interrupt]):r),this.pump(),n=e(...t)}return n};for(let r of[`fd_read`,`fd_write`]){let i=e[r];t[r]=new WebAssembly.Suspending((...e)=>{let t=i(...e);return this.blocked?n(i,e):t})}return t.poll_oneoff=new WebAssembly.Suspending((...e)=>this.poll(...e.map(e=>e>>>0))),t}async poll(e,t,n,r){let i=[];for(let t=0;t<n;t++){let n=this.view(),r=e+48*t,o=n.getUint8(r+8),s=n.getBigUint64(r,!0);if(o===0){let e=n.getBigUint64(r+24,!0),t=n.getUint16(r+40,!0)&1;i.push({tag:o,userdata:s,fd:-1,at:t?e:a()+e})}else i.push({tag:o,userdata:s,fd:n.getUint32(r+16,!0),at:0n})}for(;;){this.pump();let e=a(),n=i.filter(({tag:t,fd:n,at:r})=>{if(t===0)return e>=r;let i=this.fds.get(n)?.pipe;return i?t===1?i.size>0||!i.writers:i.size<65536||!i.readers:!0});if(n.length){let e=this.view();return n.forEach(({tag:n,userdata:r,fd:i},a)=>{let o=t+32*a;e.setBigUint64(o,r,!0),e.setUint16(o+8,n&&!this.fds.has(i)?l.BADF:0,!0),e.setUint8(o+10,n);let s=this.fds.get(i)?.pipe;e.setBigUint64(o+16,BigInt(s?n===1?s.size:U-s.size:0),!0);let c=s&&(n===1?!s.writers:!s.readers);e.setUint16(o+24,+!!c,!0)}),e.setUint32(r,n.length,!0),l.SUCCESS}let o=i.map(({fd:e})=>this.fds.get(e)?.pipe?.changed()).filter(e=>e!==void 0),s=i.reduce((e,{tag:t,at:n})=>t===0&&(e===null||n<e)?n:e,null);s!==null&&o.push(new Promise(t=>setTimeout(t,Number(s-e)/1e6))),this.interrupt&&o.push(this.interrupt),await this.suspended(Promise.race(o))}}close(e){let t=this.fds.get(e);return t?t.shares?(t.shares--,this.fds.delete(e),l.SUCCESS):t.pipe?(t.pipe.close(!!t.reads),this.fds.delete(e),l.SUCCESS):this.io.fd_close(e):l.BADF}release(){for(let e of[...this.fds.keys()])this.close(e),this.fds.delete(e)}dup(e){let t=this.fds.get(e);if(!t)return null;t.shares=(t.shares??0)+1;let n=this.next++;return this.fds.set(n,t),n}renumber(e,t){let n=this.fds.get(e);return n?(e===t||(this.fds.has(t)&&this.close(t),this.fds.set(t,n),this.fds.delete(e)),l.SUCCESS):l.BADF}start(e){this.memory=e.exports.memory;try{return e.exports._start(),0}catch(e){if(e instanceof q)return e.code;throw e}}view(){return new DataView(this.memory.buffer)}bytes(e,t){return new Uint8Array(this.memory.buffer,e,t)}string(e,t){return new TextDecoder().decode(this.bytes(e,t).slice())}absolute(e,t){let n=t.startsWith(`/`)?``:this.fds.get(e)?.path??``,r=[];for(let e of`${n}/${t}`.split(`/`))e===`..`?r.pop():e&&e!==`.`&&r.push(e);return`/`+r.join(`/`)}resolve(e,t,r=!1){let i=this.fds.get(e);return!i||!(i.node instanceof o)?{error:l.BADF}:n(this.root,i.node,t,r)}filestat(t,n){let r=this.view(),s=n instanceof o;r.setBigUint64(t,1n,!0),r.setBigUint64(t+8,n?n.ino:0n,!0),r.setUint8(t+16,n?i(n):e.CHAR),r.setBigUint64(t+24,1n,!0),r.setBigUint64(t+32,BigInt(n&&!s?n.size:0),!0);let c=n?n.mtime:a();r.setBigUint64(t+40,c,!0),r.setBigUint64(t+48,c,!0),r.setBigUint64(t+56,c,!0)}iovecs(e,t){let n=this.view(),r=[];for(let i=0;i<t;i++)r.push([n.getUint32(e+8*i,!0),n.getUint32(e+8*i+4,!0)]);return r}functions(){let e=this,t=l.SUCCESS,n=n=>({sizes(r,i){let a=e.view();return a.setUint32(r,n.length,!0),a.setUint32(i,n.reduce((e,t)=>e+new TextEncoder().encode(t).length+1,0),!0),t},get(r,i){let a=e.view(),o=i;return n.forEach((t,n)=>{let i=new TextEncoder().encode(t);a.setUint32(r+4*n,o,!0),e.bytes(o,i.length).set(i),a.setUint8(o+i.length,0),o+=i.length+1}),t}}),r=n(this.args),i=n(this.env);return{args_sizes_get:(e,t)=>r.sizes(e,t),args_get:(e,t)=>r.get(e,t),environ_sizes_get:(e,t)=>i.sizes(e,t),environ_get:(e,t)=>i.get(e,t),clock_res_get(n,r){return e.view().setBigUint64(r,1000n,!0),t},clock_time_get(n,r,i){e.pump();let o=n===0?a():BigInt(Math.round(performance.now()*1e6));return e.view().setBigUint64(i,o,!0),t},random_get(n,r){for(let t=0;t<r;t+=65536){let i=new Uint8Array(Math.min(65536,r-t));crypto.getRandomValues(i),e.bytes(n+t,i.length).set(i)}return t},proc_exit(e){throw new q(e)},proc_raise(e){throw new q(128+e)},sched_yield:()=>t,poll_oneoff(n,r,i,o){let s=e.view(),c=1/0,l=0;for(let e=0;e<i;e++){let t=n+48*e,i=s.getUint8(t+8),o=r+32*l;if(i===0){let e=s.getBigUint64(t+24,!0),n=s.getUint16(t+40,!0)&1,r=Number(n?e-a():e)/1e6;c=Math.min(c,Math.max(0,r))}s.setBigUint64(o,s.getBigUint64(t,!0),!0),s.setUint16(o+8,0,!0),s.setUint8(o+10,i),l++}return c!==1/0&&c>0&&e.sleep(c),e.pump(),s.setUint32(o,l,!0),t},...H(this)}}};export{z as a,T as c,O as d,_ as f,B as i,C as l,J as n,D as o,W as r,E as s,q as t,S as u};
package/claude.html DELETED
@@ -1,10 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <title>Elixir Playground</title>
6
- <script type="module" crossorigin src="./frames/claude-BdzjrDKT.js"></script>
7
- </head>
8
- <body>
9
- </body>
10
- </html>