@elixir-playground/runtime 0.0.0-stage → 1.0.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.
Files changed (71) hide show
  1. package/LICENSE +73 -0
  2. package/NOTICE.md +44 -0
  3. package/chunks/ansi-styles-Bkz3XA_r.js +1 -0
  4. package/chunks/browser-iHf7-8M7.js +113 -0
  5. package/chunks/dist-0mSzsNc8.js +10 -0
  6. package/chunks/fs-GnBaZCKr.js +1 -0
  7. package/chunks/git-remote-DnEba0y9.js +16 -0
  8. package/chunks/lookup-NMT_UyaB.js +1 -0
  9. package/chunks/manifest-DOTdOkY7.js +2 -0
  10. package/chunks/preload-helper-DHhhL8Zf.js +1 -0
  11. package/chunks/semver-CK47NiDu.js +1 -0
  12. package/chunks/slice-ansi-CtePLJj8.js +1 -0
  13. package/chunks/string-width-Dyomz-Kx.js +1 -0
  14. package/chunks/strip-ansi-B9O1Kiar.js +1 -0
  15. package/chunks/wasi-M0pSoirQ.js +1 -0
  16. package/chunks/wrap-ansi-v-UhTxgf.js +9 -0
  17. package/claude.html +10 -0
  18. package/exec.html +10 -0
  19. package/files.js +2 -0
  20. package/frames/browser-C6dmTjO4.js +682 -0
  21. package/frames/browser-CpIeD-9w.js +682 -0
  22. package/frames/claude-BdzjrDKT.js +1 -0
  23. package/frames/esbuild-DJd0QPVm.wasm +0 -0
  24. package/frames/exec-DcNLuXnX.js +1 -0
  25. package/frames/host-gpGAUuqR.js +1969 -0
  26. package/frames/relay-CFTN70Gw.js +9 -0
  27. package/frames/site-Bq_qZN66.js +1 -0
  28. package/frames/worker-PmIsqqyU.js +16 -0
  29. package/git.js +1 -0
  30. package/licenses/abort-controller-3.0.0/LICENSE +21 -0
  31. package/licenses/ansi-regex-6.4.0/license +9 -0
  32. package/licenses/ansi-styles-6.2.3/license +9 -0
  33. package/licenses/base64-js-1.5.1/LICENSE +21 -0
  34. package/licenses/buffer-6.0.3/LICENSE +21 -0
  35. package/licenses/elixir-playground-playground/LICENSE +73 -0
  36. package/licenses/elixir-playground-playground/NOTICE +11 -0
  37. package/licenses/esbuild-wasm-0.25.4/LICENSE.md +21 -0
  38. package/licenses/events-3.3.0/LICENSE +22 -0
  39. package/licenses/fflate-0.8.2/LICENSE +21 -0
  40. package/licenses/fzstd-0.1.1/LICENSE +21 -0
  41. package/licenses/get-east-asian-width-1.7.0/license +9 -0
  42. package/licenses/ieee754-1.2.1/LICENSE +11 -0
  43. package/licenses/index.json +304 -0
  44. package/licenses/is-fullwidth-code-point-5.1.0/license +9 -0
  45. package/licenses/jridgewell_gen-mapping-0.3.13/LICENSE +19 -0
  46. package/licenses/jridgewell_resolve-uri-3.1.2/LICENSE +19 -0
  47. package/licenses/jridgewell_sourcemap-codec-1.6.0/LICENSE +19 -0
  48. package/licenses/jridgewell_trace-mapping-0.3.31/LICENSE +19 -0
  49. package/licenses/lines-and-columns-1.2.4/LICENSE +21 -0
  50. package/licenses/noble_hashes-2.0.1/LICENSE +21 -0
  51. package/licenses/readable-stream-4.7.0/LICENSE +47 -0
  52. package/licenses/safe-buffer-5.2.1/LICENSE +21 -0
  53. package/licenses/semver-7.7.3/LICENSE +15 -0
  54. package/licenses/slice-ansi-9.0.1/license +10 -0
  55. package/licenses/smol-toml-1.9.1/LICENSE +24 -0
  56. package/licenses/string-width-8.3.0/license +9 -0
  57. package/licenses/string_decoder-1.3.0/LICENSE +48 -0
  58. package/licenses/strip-ansi-7.2.0/license +9 -0
  59. package/licenses/sucrase-3.35.0/LICENSE +21 -0
  60. package/licenses/tailwindcss-4.3.3/LICENSE +21 -0
  61. package/licenses/ts-interface-checker-0.1.13/LICENSE +201 -0
  62. package/licenses/vite-8.3.4/LICENSE.md +2265 -0
  63. package/licenses/wrap-ansi-10.0.2/license +9 -0
  64. package/licenses/yaml-2.9.1/LICENSE +13 -0
  65. package/nodejs.js +181 -0
  66. package/package.json +50 -4
  67. package/relay.html +10 -0
  68. package/root/relay.html +30 -0
  69. package/root/sw.js +1 -0
  70. package/worker.js +15 -0
  71. package/README.md +0 -3
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@elixir-playground/runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "license": "Apache-2.0 AND BSD-3-Clause AND ISC AND MIT",
5
+ "files": [
6
+ "LICENSE",
7
+ "NOTICE.md",
8
+ "chunks",
9
+ "claude.html",
10
+ "exec.html",
11
+ "files.js",
12
+ "frames",
13
+ "git.js",
14
+ "licenses",
15
+ "nodejs.js",
16
+ "relay.html",
17
+ "root",
18
+ "worker.js"
19
+ ],
20
+ "playground": {
21
+ "provides": {
22
+ "manifest": [
23
+ 2
24
+ ],
25
+ "fs": [
26
+ 3
27
+ ],
28
+ "wasi": [
29
+ 1
30
+ ],
31
+ "processes": [
32
+ 1
33
+ ],
34
+ "crossterm": [
35
+ 1
36
+ ],
37
+ "beam": [
38
+ 1
39
+ ],
40
+ "tls": [
41
+ 1
42
+ ],
43
+ "tailscale": [
44
+ 1
45
+ ],
46
+ "nif": [
47
+ 1
48
+ ]
49
+ }
50
+ },
51
+ "playgroundDigest": "2f4c8f793d02"
52
+ }
package/relay.html ADDED
@@ -0,0 +1,10 @@
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/relay-CFTN70Gw.js"></script>
7
+ </head>
8
+ <body>
9
+ </body>
10
+ </html>
@@ -0,0 +1,30 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Elixir Playground</title>
6
+ </head>
7
+ <body>
8
+ <script type="module">
9
+ // The unnumbered service worker lets /relay.html through, but routes
10
+ // package pages into the app. Update it here before loading the relay
11
+ // from the runtime the parent chose (which may be an older build).
12
+ const runtime = new URL(location.href).searchParams.get('runtime');
13
+ if (!/^\/npm\/@elixir-playground\/runtime@[^/]+\/$/.test(runtime ?? ''))
14
+ throw new Error('no runtime package named');
15
+ const registration = await navigator.serviceWorker.register('/sw.js', { scope: '/' });
16
+ await registration.update();
17
+ const worker = registration.installing ?? registration.waiting ?? registration.active;
18
+ if (!worker) throw new Error('no service worker');
19
+ if (worker.state !== 'activated') {
20
+ await new Promise((resolve, reject) => {
21
+ worker.addEventListener('statechange', () => {
22
+ if (worker.state === 'activated') resolve();
23
+ else if (worker.state === 'redundant') reject(new Error('service worker update failed'));
24
+ });
25
+ });
26
+ }
27
+ location.replace(`${runtime}relay.html`);
28
+ </script>
29
+ </body>
30
+ </html>
package/root/sw.js ADDED
@@ -0,0 +1 @@
1
+ var e=[1];function t(e){let{protocol:t}=e;return typeof t==`number`&&Number.isInteger(t)&&t>0?t:0}function n(t,n=e){return n.includes(t)?t:null}function r(t,r=e){return{kind:`hosted`,protocol:n(t,r),protocols:[...r]}}var i=`/npm/@elixir-playground/`,a=e=>e===`/relay.html`||e.startsWith(i),o=`routes-1`;self.addEventListener(`install`,()=>self.skipWaiting()),self.addEventListener(`activate`,e=>e.waitUntil(self.clients.claim()));var s={"Cross-Origin-Embedder-Policy":`require-corp`,"Cross-Origin-Resource-Policy":`cross-origin`},c=[`connection`,`keep-alive`,`transfer-encoding`,`content-length`,`set-cookie`],l={host:null,protocol:0,previews:[]},u=3e3,d=new Set,f=null,p=!1;function m(){return new Promise((e,t)=>{let n=indexedDB.open(`playground-sw`,1);n.onupgradeneeded=()=>n.result.createObjectStore(`clients`),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}function h(){return f??=m().then(e=>new Promise(t=>{let n=e.transaction(`clients`).objectStore(`clients`).get(o);n.onsuccess=()=>{let e=n.result;l.host===null&&e?.host&&(l.host=e.host,l.protocol=e.protocol??0);for(let t of e?.previews??[])d.add(t);t()},n.onerror=()=>t()})).catch(()=>{}).then(()=>{p=!0}),f}async function g(){let e=await m();await new Promise(t=>{let n=e.transaction(`clients`,`readwrite`);n.objectStore(`clients`).put({...l,previews:[...d]},o),n.oncomplete=()=>t(),n.onerror=()=>t(),n.onabort=()=>t()})}var _=null;function v(){_??=new Promise(e=>setTimeout(e,200)).then(async()=>{if(_=null,d.size>256){let e=new Set((await self.clients.matchAll({includeUncontrolled:!0,type:`window`})).map(e=>e.id));for(let t of[...d].slice(0,d.size-128))e.has(t)||d.delete(t)}await g()}).catch(()=>{})}var y=[];function b(e){return new Promise(t=>{let n=setTimeout(t,e);y.push(()=>{clearTimeout(n),t()})})}self.addEventListener(`message`,e=>{if(e.data===`claim`){e.waitUntil(self.clients.claim());return}let n=e.data?.kind;if(n===`websocket`)e.waitUntil(C().then(n=>{n&&t(e.data)===l.protocol?n.postMessage(e.data,[e.ports[0]]):e.ports[0].postMessage({close:{code:1006,reason:``,clean:!1}})}));else if(n===`host`){let n=r(t(e.data));if(e.source.postMessage(n),n.protocol===null)return;l.host=e.source.id,l.protocol=n.protocol;for(let e of y.splice(0))e();e.waitUntil(g().catch(()=>{}))}});var x=/^v-([a-z0-9]{10})-(\d{1,5})\.(.+)$/;function S(e){let t=self.location.host.match(x),n=e.protocol===self.location.protocol?e.host.match(x):null;return t&&n&&t[1]===n[1]&&t[3]===n[3]?Number(n[2]):null}self.addEventListener(`fetch`,e=>{let{request:t}=e,n=new URL(t.url);if(n.origin!==self.location.origin){let r=t.mode===`navigate`?null:S(n);r!==null&&e.clientId&&d.has(e.clientId)&&e.respondWith(w(e,r))}else if(t.mode===`navigate`){if(t.destination!==`iframe`||a(n.pathname))return;d.add(e.resultingClientId),v(),e.respondWith(w(e))}else if(e.clientId&&(!p||d.has(e.clientId))){let n=e.clientId;e.respondWith(h().then(()=>d.has(n)?w(e):fetch(t)))}});async function C(){return await h(),l.host?await self.clients.get(l.host)??null:null}async function w(e,t){let{request:n}=e,r=await C();if(r||=(await b(u),await C()),!r)return new Response(`The project is not running. If the playground was updated since you opened this page, reload it.`,{status:503,headers:{"Content-Type":`text/plain`,...s}});let i=new URL(n.url),a=[`GET`,`HEAD`].includes(n.method)?null:await n.arrayBuffer(),o=new MessageChannel,l=new Promise(e=>{o.port1.onmessage=t=>e(t.data)});r.postMessage({kind:`http`,method:n.method,path:i.pathname+i.search,headers:[...n.headers],body:a,destination:n.destination,...t===void 0?{}:{port:t}},[o.port2]);let d=await l,f=d.headers.find(([e])=>e===`location`);if(d.status>=300&&d.status<400&&f&&n.mode!==`navigate`)return Response.redirect(new URL(f[1],i).href,d.status);let p=new Headers(d.headers.filter(([e])=>!c.includes(e)));for(let[e,t]of Object.entries(s))p.set(e,t);let m=n.method===`HEAD`||[101,204,205,304].includes(d.status);return new Response(m?null:d.body,{status:d.status,statusText:d.reason,headers:p})}
package/worker.js ADDED
@@ -0,0 +1,15 @@
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+`
2
+ `)),printErr:t=>{t.includes(`Heap resize call`)||e.stderr(Fe.encode(t+`
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
+ `).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),
5
+ and coreutils' ls, cp, mv, rm, cat, sort, wc, …, in a bash-like shell:
6
+ pipes, redirections, $(…), loops. Tab completes, Up recalls, Ctrl+R
7
+ searches. Ctrl+C: a node's break menu (a aborts), a program stops.
8
+ help NAME: a shell built-in.
9
+ `;onmessage=async({data:{shared:n,site:r,files:o,shell:s,args:d,command:f,env:p,ports:m,udpPorts:_=[],outbound:te=!1,https:v=!1,initial:ae=[],pagePrograms:y=[],tty:ye=[!0,!0],cwd:b=`/work`,boots:x=[`boot`],images:Ce,manifest:S,brush:C,coreutils:w,beam:T}})=>{M(r);let E=j();Xe(E);let O=me(E),Ee=E.boots(x);try{Y(`status`,`Loading OTP and Elixir…`);let[r,me,x]=await Promise.all([Ce??Promise.all(Ee.map(e=>fetch(E.boot(e)).then(e=>e.arrayBuffer()))),S??E.tree(),C??(s||qe(f?.[0])?Ue(E.shell()):null)]),k=e=>!o||!We.some(t=>`/${e}`.startsWith(`${t}/`)),A=new c;l(me.filter(([e])=>k(e)),A);for(let e of r)Ce?i(new Uint8Array(e),A,k):await a(new Uint8Array(e),A,k);_e(A,{dns:_.includes(53),inotifywait:y.includes(`inotifywait`),bin:E.bin()});let j=o?{prefixes:We,call:h(o.doorbell,o.channel)}:null,M=new Te(n);M.tty=ye;let P=e(e=>t(E.bundle(e))),F=we(A,P,j),ke=(e,t,n)=>Oe(M,e,t,n),L=w,Ae=()=>{if(L===void 0){let e=E.multicall(),[t,n]=e?N(e):[0,null];L=t===200&&n?.[0]===0&&n[1]===97?new WebAssembly.Module(n):null}return L},R=new Map,z=e=>{let t=ie.get(e)?.url;if(!t)return null;if(!R.has(t.href)){let[e,n]=N(t),r=e===200&&n?.[0]===0&&n[1]===97;R.set(t.href,r?new WebAssembly.Module(n):null)}return R.get(t.href)},B={module:Ae,load:z,fetch:P,shared:j},V=async(e,t,n={},r=e=>Y(`out`,e),i=e=>Y(`err`,e))=>{let a={...p,...n},o=new g({ports:m,udpPorts:_,https:v,open:(e,t,n)=>postMessage({kind:`net`,op:`open`,id:e,port:t,host:n}),dial:te?(e,t,n)=>postMessage({kind:`net`,op:`dial`,id:e,port:n,host:t}):void 0,datagram:(e,t,n,r)=>postMessage({kind:`udp`,from:e,address:t,port:n,payload:r}),bound:e=>postMessage({kind:`udp`,from:e,bound:!0}),unbound:e=>postMessage({kind:`udp`,from:e,closed:!0}),send:(e,t)=>postMessage({kind:`net`,op:`data`,id:e,payload:t}),end:e=>postMessage({kind:`net`,op:`end`,id:e}),close:e=>postMessage({kind:`net`,op:`close`,id:e}),listening:(e,t,n=!1)=>postMessage({kind:`listening`,port:e,on:t,ephemeral:n})});M.network=o,o.peers=M.peers,M.interrupted=!1,M.terminated=!1,G.hosting++;try{return await He({module:E.beam().loader.href,root_otp:E.otp().root,argv:[`+S`,String(Ve),...$e(e,a),...e],env:{...O,...a,PWD:t},cwd:t,root:A,fetch:P,shared:j,network:o,programs:re(Object.assign({...se(F,ke),...Object.fromEntries(y.map(e=>[e,De(M,e)]))},Object.fromEntries([...[...ie.keys()].filter(ne),...Object.keys(fe)].map(e=>[e,ue(G,e)]))),B),channel:M,memory:Be(),wasm:T,stdout:r,stderr:i})}finally{G.hosting--,M.interrupted=!1,M.terminated=!1,M.mode(!1),M.network=null;for(let e of o.listeners.keys())postMessage({kind:`listening`,port:e,on:!1});for(let e of o.endpoints.keys())postMessage({kind:`net`,op:`close`,id:e})}},H=(e,t)=>async(n,{cwd:r,env:i,stdio:[a,o,s]})=>{let c=new ee;c.errors=[];let l=()=>{},u=()=>{};c.notify=()=>{l(),u()};let d=!!a.source,f=0;De(M,e,{input:null,tty:[d&&M.tty[0],!!o.tty],started:e=>f=e})(c,{args:t,cwd:r,env:{...O,...i,PWD:r},root:A});let p=[M.raw,M.signals],m=!1,h=0,g=e=>{h+=e?.length??0,postMessage(e?{kind:`stdin`,id:f,bytes:e}:{kind:`stdin`,id:f,end:!0})};d?M.reading=f:le(a,g,async()=>{for(;;){if(m||h-c.taken<Ge)return;await Promise.race([new Promise(e=>u=e),n.woken,M.rest(1e3).then(()=>M.pump())])}},()=>m,j);try{for(;;){let e=new Promise(e=>l=e);if(M.pump(),d)for(let e of M.input.splice(0))g(e===D?null:e);if(c.output.reduce((e,t)=>e+t.length,0)>16777216)throw new xe;let t=c.ended;for(let e of c.errors.splice(0))await oe(s,e,n,j);for(let e of c.output.splice(0))if(!await oe(o,e,n,j))return c.onclose?.(),n.signal===null?141:128+n.signal;if(t)return c.status??1;if(n.signal!==null)return c.onclose?.(),128+n.signal;await Promise.race([e,n.woken,M.rest(1e3)])}}finally{m=!0,d&&(M.reading=null,M.input=[]),M.mode(...p)}},je=e=>{if(M.pump(),M.interrupted||M.terminated)return new Uint8Array;let t=M.takeInput(e);return M.reading=t?null:0,t},Me=()=>M.rest(1e3);Y(`status`,`running`);let Ne=(e,t,n,r=p)=>{let i=e.split(`/`).pop(),a=e=>F.read(Z(n,e)),o=e.startsWith(`/`)?e:e.includes(`/`)?Z(n,e):(r.PATH??``).split(`:`).filter(Boolean).map(t=>Z(n,`${t}/${e}`)).find(e=>(F.read(e)?.length??0)>2)??null,s=o?F.read(o)?.subarray(0,64):null,c=s?new TextDecoder().decode(s):``,l=$(i,t,a)??(/^#!.*\bescript\b/.test(c)?$(`escript`,[e,...t],a):null);if(l)return{node:l};if(/^#!.*\b(sh|bash)\b/.test(c))return{script:[o,...t]};if(i.startsWith(`git-`)){let e=o??`/usr/libexec/git-core/${i}`,n=F.read(e)?.subarray(0,64);if(n&&/^#!.*\b(sh|bash)\b/.test(new TextDecoder().decode(n)))return{script:[e,...t]};let r=pe.has(i)?z(`git`):null;return r?{wasm:r}:null}let u=ne(i)?z(i):null;if(u)return{wasm:u};if(y.includes(i))return{page:i,args:t};if(/^#!.*\bnode\b/.test(c)&&y.includes(`node`))return{page:`node`,args:[e,...t]};let d=be(i)?Ae():null;return d?{wasm:d}:null},U=()=>{M.pump(),!G.hosting&&(M.interrupted||M.terminated)&&(M.interrupted=!1,M.terminated=!1,G.interrupt())},W=async()=>127,G=new ce((e,t,n,r)=>{if(qe(e))return(e,t)=>W(e,t);let i=fe[e.split(`/`).pop()];if(i)return i(G,e=>F.stat(e));if(e.split(`/`).pop()===`git`&&/^remote-https?$/.test(t[0]??``))return ge(de(location.origin));let a=Ne(e,t,n,r);if(!a)return null;if(`page`in a)return H(a.page,a.args);if(`script`in a)return(e,t)=>W(e,{...t,args:a.script});if(`node`in a)return he(G,Pe,j);let o=e.split(`/`).pop();return Se(G,a.wasm,{root:A,fetch:P,shared:j,argv0:o,pump:U,defaults:/^git(-|$)/.test(o)?{GIT_PAGER:`cat`,...ve}:{},columns:()=>M.size[0]})},U),Pe=async(e,t,n,r,i)=>{let a=Ne(e,t,n);if(!a||!(`node`in a))return null;let o=await V(a.node,n,r,i.stdout??void 0,i.stderr??void 0);return o===130&&X(`
10
+ `),o},Fe=[{stream:!0,source:je,ready:Me,tty:M.tty[0]},{stream:!0,sink:e=>Y(`out`,e),tty:M.tty[1]},{stream:!0,sink:e=>Y(`err`,e),tty:M.tty[1]}],Ie=qe(f?.[0]);if(!s&&!Ie){let e=p.PWD||b,t=f?$(f[0],f.slice(1),t=>F.read(Z(e,t))):d;if(!t){Ke(`${f[0]}: command not found\n`),Y(`exit`,127);return}Y(`exit`,await V(t,e));return}if(!x)throw Error(`the site has no shell (brush.wasm: brush/build.py)`);let K={raw:e=>M.mode(e),size:()=>M.size,read:async(e,t)=>{let n=ae.shift();if(n!==void 0)return new TextEncoder().encode(`${n}\r`);let r=t<0?1/0:performance.now()+t,[i,a]=M.size;for(;;){if(M.pump(),M.size[0]!==i||M.size[1]!==a)return null;if(M.interrupted)return M.interrupted=!1,M.input=[],Uint8Array.of(3);M.terminated=!1;let t=M.take(e);if(t.length)return t.map(e=>e===10?13:e);let n=r-performance.now();if(n<=0)return new Uint8Array;await M.rest(Math.min(n,1e3))}}},q=e=>`'${e.replace(/'/g,`'\\''`)}'`,J=e=>({module:x,env:{...O,...p,PWD:e},root:A,fetch:P,shared:j,out:e=>Y(`out`,e),err:e=>Y(`err`,e),terminal:K,processes:G,standard:Fe}),Le=(e,t)=>{let n=[...e],r=e=>e===`-l`||e===`--login`;for(;r(n[0]);)n.shift();if(n[0]===`-c`)for(;r(n[1]);)n.splice(1,1);n[0]&&!n[0].startsWith(`-`)&&n.unshift(`-c`,`. ${q(n[0])}`);let[i,a=``,...o]=n;return i===`--version`?{message:`GNU bash, version 5.2.0 compatible (brush, the playground)
11
+ `,status:0}:i===`-c`?{args:[`--norc`,`--noprofile`,`-c`,`cd ${q(t)} || exit 1\n${a}`,...o]}:{message:`sh: only sh -c LINE runs in the playground
12
+ `,status:2}};if(W=async(e,{args:t,cwd:n,env:r,stdio:i})=>{let a=Le(t,n);return`message`in a?(await oe(i[1],new TextEncoder().encode(a.message),e,j),a.status):I({...J(n),env:{...O,...r,PWD:n},args:a.args,stdio:i,self:e,pump:U})},Ie){let e=p.PWD||b,t=Le(f.slice(1),e);if(`message`in t){(t.status?Ke:X)(t.message),Y(`exit`,t.status);return}Y(`exit`,await I({...J(e),args:t.args}));return}let Re=F.stat(b)?.dir?b:`/work`;ae.length||X(tt);let ze=[`__home='~'`,"PS1='\\[\\e[1;35m\\]${PWD/#$HOME/$__home}\\[\\e[0m\\] $ '",`help() { if [ $# -eq 0 ]; then cat /etc/playground-help; else builtin help "$@"; fi; }`,`cd ${q(Re)}`];for(A.put(`etc/brushrc`,new u(new TextEncoder().encode(ze.join(`
13
+ `)+`
14
+ `))),A.put(`etc/playground-help`,new u(new TextEncoder().encode(tt)));;)await I({...J(Re),args:[`--rcfile`,`/etc/brushrc`,`--noprofile`,`--enable-highlighting`,`-i`]}),X(`The shell exited; a new one starts.
15
+ `)}catch(e){Y(`status`,`failed: ${e.stack||e}`)}};
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.