(function(){"use strict";var M={exports:{}},pe=M.exports,ae;function ke(){return ae||(ae=1,(function(l,e){(function(t,s){s(e)})(pe,(function(t){class s{kept_object;room_id;id;bc;constructor(i,_){this.kept_object=i,this.room_id=`shared-object-${_}`,this.id="parent",this.bc=new globalThis.BroadcastChannel(this.room_id),this.register()}register(){const i=this.bc;i.onmessage=_=>{const r=_.data;if(r.msg===void 0)throw new Error("Invalid message");this.is_my_msg(r)||r.to===this.id&&(r.msg==="func_call::call"&&this.func_call(r),r.msg==="get::get"&&this.get(r))}}is_my_msg(i){return i.from===this.id}func_call(i){const _=this.bc,{names:r,args:o,id:a}=i;try{if(r.length===1&&r[0]===".self"){const u=this.kept_object(...o);_.postMessage({msg:"func_call::return",ret:u,id:a,from:this.id,to:i.from});return}let c=this.kept_object;for(const u of r)c=c[u];const d=c(...o);_.postMessage({msg:"func_call::return",ret:d,id:a,from:this.id,to:i.from})}catch(c){_.postMessage({msg:"func_call::error",error:c,id:a,from:this.id,to:i.from})}}get(i){const _=this.bc,{names:r,id:o}=i;try{let a=this.kept_object;for(const c of r)a=a[c];_.postMessage({msg:"get::return",ret:a,id:o,from:this.id,to:i.from,can_post:!0})}catch(a){if(a.name==="DataCloneError"){_.postMessage({msg:"get::data_clone_error",error:a,id:o,from:this.id,to:i.from,can_post:!1});return}_.postMessage({msg:"get::error",error:a,id:o,from:this.id,to:i.from,can_post:!1})}}}class n{room_id;id;map=new Map;bc;callbacks=[];constructor(i){this.room_id=`shared-object-${i}`,this.id=this.get_id(),this.bc=new globalThis.BroadcastChannel(this.room_id),this.register()}is_my_msg(i){return i.from===this.id}proxy(){return new Proxy(()=>{},{get:(i,_)=>this.get([_]),apply:(i,_,r)=>this.call([".self"],r)})}addCallback(i){this.callbacks.push(i)}removeCallback(i){const _=this.callbacks.indexOf(i);_!==-1&&this.callbacks.splice(_,1)}register(){const i=this.bc;i.onmessage=_=>{const r=_.data;if(r.msg===void 0)throw new Error("Invalid message");if(!this.is_my_msg(r)&&r.to===this.id){if(r.msg.startsWith("func_call::")){const o=this.map.get(r.id);if(o!==void 0)o(r),this.map.delete(r.id);else throw new Error("what happened? unreachable code")}if(r.msg.startsWith("get::")){const o=this.map.get(r.id);if(o!==void 0)o(r),this.map.delete(r.id);else throw new Error("what happened? unreachable code")}}}}get_id(){return Math.random().toString(36).slice(2)}check_msg_error(i){if(i.msg.endsWith("::error"))throw i.error}get(i){const{promise:_,resolve:r}=Promise.withResolvers(),o=this.get_id();this.map.set(o,r),this.postMessage({msg:"get::get",names:i,id:o,from:this.id,to:"parent"});let a=!1;const d=(async()=>{const h=await _;if(this.check_msg_error(h),h.msg==="get::return"||h.msg==="get::data_clone_error"){a&&console.warn(`Warning! Objects that cannot be transferred are being retrieved.`);const m=h;return m.can_post?m.ret:new Proxy(()=>{},{get:(g,y)=>y==="then"?(a=!0,Promise.resolve(d)):this.get([...i,y]),apply:(g,y,b)=>this.call(i,b)})}throw new Error("what happened? unreachable code")})();return new Proxy(()=>{},{get:(h,m)=>m==="then"?(a=!0,d.then.bind(d)):this.get([...i,m]),apply:(h,m,g)=>this.call(i,g)})}async call(i,_){const{promise:r,resolve:o}=Promise.withResolvers(),a=this.get_id();this.map.set(a,o),this.postMessage({msg:"func_call::call",names:i,args:_,id:a});const c=await r;if(this.check_msg_error(c),c.msg==="func_call::return")return c.ret;throw new Error("what happened? unreachable code")}async call_callback(i){const{name:_,args:r,id:o}=i;try{if(i.msg==="callback::call"){const a=this.callbacks.find(d=>d.name===_);if(a===void 0)throw new Error("function not found");const c=a(...r);if(c instanceof Promise){this.postMessage({msg:"callback::promise",id:o});const d=await c;this.postMessage({msg:"callback::promise_return",ret:d,id:o})}else this.postMessage({msg:"callback::return",ret:c,id:o})}}catch(a){this.postMessage({msg:"callback::error",error:a,id:o})}}postMessage(i){this.bc.postMessage({...i,from:this.id,to:"parent"})}}t.SharedObject=s,t.SharedObjectRef=n,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}))})(M,M.exports)),M.exports}var G=ke();let k;const _e=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&_e.decode();let D=null;function z(){return(D===null||D.byteLength===0)&&(D=new Uint8Array(k.memory.buffer)),D}function H(l,e){return l=l>>>0,_e.decode(z().subarray(l,l+e))}const O=new Array(128).fill(void 0);O.push(void 0,null,!0,!1);let W=O.length;function ce(l){W===O.length&&O.push(O.length+1);const e=W;return W=O[e],O[e]=l,e}function fe(l){return O[l]}function Ae(l){l<132||(O[l]=W,W=l)}function Z(l){const e=fe(l);return Ae(l),e}let R=0;function Q(l,e){const t=e(l.length*1,1)>>>0;return z().set(l,t/1),R=l.length,t}let L=null;function j(){return(L===null||L.byteLength===0)&&(L=new Int32Array(k.memory.buffer)),L}function ve(l,e){return l=l>>>0,z().subarray(l/1,l/1+e)}const F=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},Ue=typeof F.encodeInto=="function"?function(l,e){return F.encodeInto(l,e)}:function(l,e){const t=F.encode(l);return e.set(t),{read:l.length,written:t.length}};function xe(l,e,t){if(t===void 0){const _=F.encode(l),r=e(_.length,1)>>>0;return z().subarray(r,r+_.length).set(_),R=_.length,r}let s=l.length,n=e(s,1)>>>0;const f=z();let i=0;for(;i127)break;f[n+i]=_}if(i!==s){i!==0&&(l=l.slice(i)),n=t(n,s,s=i+l.length*3,1)>>>0;const _=z().subarray(n+i,n+s),r=Ue(l,_);i+=r.written,n=t(n,s,i,1)>>>0}return R=i,n}const X=Object.freeze({ResultSuccess:1,1:"ResultSuccess",NeedsMoreInput:2,2:"NeedsMoreInput",NeedsMoreOutput:3,3:"NeedsMoreOutput"}),Ee=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(l=>k.__wbg_brotlidecstream_free(l>>>0));class Ie{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,Ee.unregister(this),e}free(){const e=this.__destroy_into_raw();k.__wbg_brotlidecstream_free(e)}constructor(){const e=k.brotlidecstream_new();return this.__wbg_ptr=e>>>0,this}dec(e,t){try{const i=k.__wbindgen_add_to_stack_pointer(-16),_=Q(e,k.__wbindgen_malloc),r=R;k.brotlidecstream_dec(i,this.__wbg_ptr,_,r,t);var s=j()[i/4+0],n=j()[i/4+1],f=j()[i/4+2];if(f)throw Z(n);return $.__wrap(s)}finally{k.__wbindgen_add_to_stack_pointer(16)}}decompress(e,t){try{const i=k.__wbindgen_add_to_stack_pointer(-16),_=Q(e,k.__wbindgen_malloc),r=R;k.brotlidecstream_dec(i,this.__wbg_ptr,_,r,t);var s=j()[i/4+0],n=j()[i/4+1],f=j()[i/4+2];if(f)throw Z(n);return $.__wrap(s)}finally{k.__wbindgen_add_to_stack_pointer(16)}}total_out(){return k.brotlidecstream_total_out(this.__wbg_ptr)>>>0}}const de=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(l=>k.__wbg_brotlistreamresult_free(l>>>0));class ${static __wrap(e){e=e>>>0;const t=Object.create($.prototype);return t.__wbg_ptr=e,de.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,de.unregister(this),e}free(){const e=this.__destroy_into_raw();k.__wbg_brotlistreamresult_free(e)}get code(){return k.__wbg_get_brotlistreamresult_code(this.__wbg_ptr)}set code(e){k.__wbg_set_brotlistreamresult_code(this.__wbg_ptr,e)}get buf(){try{const n=k.__wbindgen_add_to_stack_pointer(-16);k.__wbg_get_brotlistreamresult_buf(n,this.__wbg_ptr);var e=j()[n/4+0],t=j()[n/4+1],s=ve(e,t).slice();return k.__wbindgen_free(e,t*1,1),s}finally{k.__wbindgen_add_to_stack_pointer(16)}}set buf(e){const t=Q(e,k.__wbindgen_malloc),s=R;k.__wbg_set_brotlistreamresult_buf(this.__wbg_ptr,t,s)}get input_offset(){return k.__wbg_get_brotlistreamresult_input_offset(this.__wbg_ptr)>>>0}set input_offset(e){k.__wbg_set_brotlistreamresult_input_offset(this.__wbg_ptr,e)}}typeof FinalizationRegistry>"u"||new FinalizationRegistry(l=>k.__wbg_decompressstream_free(l>>>0));async function Be(l,e){if(typeof Response=="function"&&l instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(l,e)}catch(s){if(l.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",s);else throw s}const t=await l.arrayBuffer();return await WebAssembly.instantiate(t,e)}else{const t=await WebAssembly.instantiate(l,e);return t instanceof WebAssembly.Instance?{instance:t,module:l}:t}}function Se(){const l={};return l.wbg={},l.wbg.__wbindgen_error_new=function(e,t){const s=new Error(H(e,t));return ce(s)},l.wbg.__wbindgen_object_drop_ref=function(e){Z(e)},l.wbg.__wbg_new_abda76e883ba8a5f=function(){const e=new Error;return ce(e)},l.wbg.__wbg_stack_658279fe44541cf6=function(e,t){const s=fe(t).stack,n=xe(s,k.__wbindgen_malloc,k.__wbindgen_realloc),f=R;j()[e/4+1]=f,j()[e/4+0]=n},l.wbg.__wbg_error_f851667af71bcfc6=function(e,t){let s,n;try{s=e,n=t,console.error(H(e,t))}finally{k.__wbindgen_free(s,n,1)}},l.wbg.__wbindgen_throw=function(e,t){throw new Error(H(e,t))},l}function je(l,e){return k=l.exports,ue.__wbindgen_wasm_module=e,L=null,D=null,k}async function ue(l){if(k!==void 0)return k;typeof l>"u"&&(l=new URL(""+new URL("brotli_dec_wasm_bg-Dn-Szc7i.wasm",self.location.href).href,self.location.href));const e=Se();(typeof l=="string"||typeof Request=="function"&&l instanceof Request||typeof URL=="function"&&l instanceof URL)&&(l=fetch(l));const{instance:t,module:s}=await Be(await l,e);return je(t,s)}var Oe=""+new URL("brotli_dec_wasm_bg-Dn-Szc7i.wasm?wasm",self.location.href).href;const Re=ue(Oe),Te=1024*1024,ze=async()=>{await Re;const l=new Ie;return new TransformStream({transform(t,s){let n,f=0;do{const i=t.slice(f),_=l.decompress(i,Te);s.enqueue(_.buf),n=_.code,f+=_.input_offset}while(n===X.NeedsMoreOutput);n!==X.NeedsMoreInput&&n!==X.ResultSuccess&&s.error(`Brotli decompression failed with code ${n}`)},flush(t){t.terminate()}})},Me=async l=>{const e=await fetch(l);if(!e.ok)throw new Error("Failed to fetch wasm");if(!e.body)throw new Error("No body in response");return e.body.pipeThrough(await ze())},De=async l=>{const e=new Response(await Me(l),{headers:{"Content-Type":"application/wasm"}});return await WebAssembly.compileStreaming(e)},We=()=>De("https://oligamiq.github.io/rust_wasm/v0.2.0/rustc_opt.wasm.br"),ee=0,te=1,S=0,w=8,le=28,he=37,Le=52,we=58;class N{static read_bytes(e,t){const s=new N;return s.buf=e.getUint32(t,!0),s.buf_len=e.getUint32(t+4,!0),s}static read_bytes_array(e,t,s){const n=[];for(let f=0;f{}}new $e(!1);class me extends Error{constructor(e){super("exit with exit code "+e),this.code=e}}class J{share_arrays_memory;constructor(e=new SharedArrayBuffer(10*1024*1024)){this.share_arrays_memory=e;const t=new Int32Array(this.share_arrays_memory);Atomics.store(t,0,0),Atomics.store(t,1,0),Atomics.store(t,2,12)}static init_self(e){return new J(e.share_arrays_memory)}async async_write(e,t,s){const n=new Int32Array(this.share_arrays_memory);for(;;){let f;const{value:i}=Atomics.waitAsync(n,0,1);if(i instanceof Promise?f=await i:f=i,f==="timed-out")throw new Error("timed-out lock");if(Atomics.compareExchange(n,0,0,1)!==0)continue;const r=this.write_inner(e,t,s);return Atomics.store(n,0,0),Atomics.notify(n,0,1),r}}block_write(e,t,s){for(;;){const n=new Int32Array(this.share_arrays_memory);if(Atomics.wait(n,0,1)==="timed-out")throw new Error("timed-out lock");if(Atomics.compareExchange(n,0,0,1)!==0)continue;const _=this.write_inner(e,t,s);return Atomics.store(n,0,0),Atomics.notify(n,0,1),_}}write_inner(e,t,s){const n=new Int32Array(this.share_arrays_memory),f=new Uint8Array(this.share_arrays_memory),i=Atomics.add(n,1,1);let _;i===0?_=Atomics.store(n,2,12):_=Atomics.load(n,2);const r=this.share_arrays_memory.byteLength,o=e.byteLength,a=_+o;if(rthis.share_arrays_memory.byteLength)throw new Error("over memory");Atomics.store(s,2,i);const _=new Int32Array(this.share_arrays_memory,n);_[0]=e.length,_[1]=e.length,_.set(e,2),new Uint32Array(this.share_arrays_memory,n+8+e.length*4).set(t),Atomics.add(s,1,1),this.release_lock()}get_data(e){const t=new Int32Array(this.share_arrays_memory);if(Atomics.load(t,1)===0)return;this.block_lock();const n=Atomics.load(t,1),f=[];let i=12;for(let _=0;_{const e=new Error(l.message);return e.name=l.name,e.stack=l.stack?.replace(/.wasm:/g,`.wasm `),e.cause=l.cause,e};class q{allocator;lock;signature_input;constructor(e,t,s){this.allocator=e,this.lock=t,this.signature_input=s}block_lock_base_func(){const e=new Int32Array(this.lock);for(;;){if(Atomics.wait(e,0,1)==="timed-out")throw new Error("timed-out lock");if(Atomics.compareExchange(e,0,0,1)===0)return}}async async_lock_base_func(){const e=new Int32Array(this.lock);for(;;){const{value:t}=Atomics.waitAsync(e,0,1);if(await t==="timed-out")throw new Error("timed-out lock");if(Atomics.compareExchange(e,0,0,1)===0)return}}call_base_func(){const e=new Int32Array(this.lock);Atomics.store(e,2,1),Atomics.store(e,1,0),Atomics.notify(e,1,1)}block_wait_base_func(){const e=new Int32Array(this.lock);if(Atomics.wait(e,2,1)==="timed-out")throw new Error("timed-out lock")}async async_wait_base_func(){const e=new Int32Array(this.lock),{value:t}=Atomics.waitAsync(e,2,1);if(await t==="timed-out")throw new Error("timed-out lock")}release_base_func(){const e=new Int32Array(this.lock);Atomics.store(e,0,0),Atomics.notify(e,0,1)}new_worker(e,t,s){console.log("new_worker",e,t,s),this.block_lock_base_func();const n=new Int32Array(this.signature_input);Atomics.store(n,0,1);const f=new TextEncoder().encode(e);this.allocator.block_write(f,this.signature_input,1),Atomics.store(n,3,t?.type==="module"?1:0);const i=JSON.stringify(s),_=new TextEncoder().encode(i);this.allocator.block_write(_,this.signature_input,4),this.call_base_func(),this.block_wait_base_func();const r=Atomics.load(n,0);return this.release_base_func(),new Ke(r)}async async_start_on_thread(e,t,s){await this.async_lock_base_func();const n=new Int32Array(this.signature_input);Atomics.store(n,0,2);const f=new TextEncoder().encode(e);await this.allocator.async_write(f,this.signature_input,1),Atomics.store(n,3,t?.type==="module"?1:0);const i=JSON.stringify(s),_=new TextEncoder().encode(i);await this.allocator.async_write(_,this.signature_input,4),this.call_base_func(),await this.async_wait_base_func(),this.release_base_func()}block_start_on_thread(e,t,s){this.block_lock_base_func();const n=new Int32Array(this.signature_input);Atomics.store(n,0,2);const f=new TextEncoder().encode(e);this.allocator.block_write(f,this.signature_input,1),Atomics.store(n,3,t?.type==="module"?1:0);const i=JSON.stringify(s),_=new TextEncoder().encode(i);this.allocator.block_write(_,this.signature_input,4),this.call_base_func(),this.block_wait_base_func(),this.release_base_func()}static init_self(e){return new q(J.init_self(e.allocator),e.lock,e.signature_input)}done_notify(e){const t=new Int32Array(this.lock,12);if(Atomics.compareExchange(t,0,0,2)!==0){console.error("what happened?");return}Atomics.store(t,1,e),Atomics.notify(t,0)===0&&Atomics.store(t,0,0)}async async_wait_done_or_error(){const e=new Int32Array(this.lock,12);Atomics.store(e,0,0);let t;const{value:s}=Atomics.waitAsync(e,0,0);if(s instanceof Promise?t=await s:t=s,t==="timed-out")throw new Error("timed-out");const n=Atomics.load(e,0);if(n===3)return Atomics.compareExchange(e,0,3,0)!==3&&console.error("what happened?"),0;if(n===2){const d=Atomics.compareExchange(e,0,2,0),u=Atomics.load(e,1);return d!==2&&console.error("what happened?"),u}if(n!==1)throw new Error("unknown code");const f=Atomics.load(e,1),i=Atomics.load(e,2),_=this.allocator.get_memory(f,i),r=new TextDecoder().decode(_),o=JSON.parse(r),a=be(o);throw Atomics.compareExchange(e,0,1,0)!==1&&console.error("what happened?"),a}block_wait_done_or_error(){const e=new Int32Array(this.lock,12);if(Atomics.store(e,0,0),Atomics.wait(e,0,0)==="timed-out")throw new Error("timed-out");const s=Atomics.load(e,0);if(s===3)return Atomics.compareExchange(e,0,3,0)!==3&&console.error("what happened?"),0;if(s===2){const c=Atomics.compareExchange(e,0,2,0),d=Atomics.load(e,1);return c!==2&&console.error("what happened?"),d}if(s!==1)throw new Error("unknown code");const n=Atomics.load(e,1),f=Atomics.load(e,2),i=this.allocator.get_memory(n,f),_=new TextDecoder().decode(i),r=JSON.parse(_),o=be(r);throw Atomics.compareExchange(e,0,1,0)!==1&&console.error("what happened?"),o}}class Ke{id;constructor(e){this.id=e}get_id(){return this.id}}const Ye=()=>{const l='let worker_background;class AllocatorUseArrayBuffer{share_arrays_memory;constructor(r=new SharedArrayBuffer(0xa00000)){this.share_arrays_memory=r;let e=new Int32Array(this.share_arrays_memory);Atomics.store(e,0,0),Atomics.store(e,1,0),Atomics.store(e,2,12)}static init_self(r){return new AllocatorUseArrayBuffer(r.share_arrays_memory)}async async_write(r,e,t){let o=new Int32Array(this.share_arrays_memory);for(;;){let{value:s}=Atomics.waitAsync(o,0,1);if("timed-out"===(s instanceof Promise?await s:s))throw Error("timed-out lock");if(0!==Atomics.compareExchange(o,0,0,1))continue;let i=this.write_inner(r,e,t);return Atomics.store(o,0,0),Atomics.notify(o,0,1),i}}block_write(r,e,t){for(;;){let o=new Int32Array(this.share_arrays_memory);if("timed-out"===Atomics.wait(o,0,1))throw Error("timed-out lock");if(0!==Atomics.compareExchange(o,0,0,1))continue;let s=this.write_inner(r,e,t);return Atomics.store(o,0,0),Atomics.notify(o,0,1),s}}write_inner(r,e,t){let o,s,i=new Int32Array(this.share_arrays_memory),a=new Uint8Array(this.share_arrays_memory);o=0===Atomics.add(i,1,1)?Atomics.store(i,2,12):Atomics.load(i,2);let n=this.share_arrays_memory.byteLength,c=r.byteLength,l=o+c;if(n({message:r.message,name:r.name,stack:r.stack,cause:r.cause}),WorkerBackground=class r{override_object;allocator;lock;signature_input;workers=[void 0];start_worker;listen_holder;constructor(r,e,t,o){this.override_object=r,this.lock=e??new SharedArrayBuffer(24),this.allocator=t??new AllocatorUseArrayBuffer(new SharedArrayBuffer(10240)),this.signature_input=o??new SharedArrayBuffer(24),this.listen_holder=this.listen()}static init_self(e,t){return new r(e,t.lock,AllocatorUseArrayBuffer.init_self(t.allocator),t.signature_input)}assign_worker_id(){for(let r=1;r{let r=Atomics.load(e,1),t=Atomics.load(e,2),o=this.allocator.get_memory(r,t);return this.allocator.free(r,t),new Worker(new TextDecoder().decode(o),{type:1===Atomics.load(e,3)?"module":"classic"})},s=()=>{let r=Atomics.load(e,4),t=Atomics.load(e,5),o=this.allocator.get_memory(r,t);return this.allocator.free(r,t),JSON.parse(new TextDecoder().decode(o))};switch(Atomics.load(e,0)){case 1:{let r=o(),t=s(),i=this.assign_worker_id();console.debug("new worker "+i),this.workers[i]=r;let{promise:a,resolve:n}=Promise.withResolvers();r.onmessage=async r=>{let{msg:e}=r.data;if("ready"===e&&n(),"done"===e&&(this.workers[i].terminate(),this.workers[i]=void 0,console.debug(`worker ${i} done so terminate`)),"error"===e||"exit"===e){this.workers[i].terminate(),this.workers[i]=void 0;let t=0;for(let r of this.workers)void 0!==r&&(r.terminate(),"error"===e?console.warn("wasi throw error but child process exists, terminate "+t):console.debug("wasi exit but child process exists, terminate "+t)),t++;void 0!==this.start_worker&&(this.start_worker.terminate(),"error"===e?console.warn("wasi throw error but wasi exists, terminate wasi"):console.debug("wasi exit but wasi exists, terminate wasi")),this.workers=[void 0],this.start_worker=void 0;let o=new Int32Array(this.lock,12);if("error"===e){let e=r.data.error,t=serialize(e),[s,i]=await this.allocator.async_write(new TextEncoder().encode(JSON.stringify(t)),this.lock,4);if(0!==Atomics.compareExchange(o,0,0,1)){console.error("what happened?"),this.allocator.free(s,i);return}1!==Atomics.notify(o,0)&&(console.error(e),this.allocator.free(s,i),Atomics.store(o,0,0))}else{let e=r.data.code;if(0!==Atomics.compareExchange(o,0,0,2))return void console.error("what happened?");Atomics.store(o,1,e),0===Atomics.notify(o,0)&&Atomics.store(o,0,0)}}},r.postMessage({...this.override_object,...t,worker_id:i,worker_background_ref:this.ref()}),await a,Atomics.store(e,0,i);break}case 2:{console.debug("start worker create"),this.start_worker=o();let r=s();this.start_worker.onmessage=async r=>{let{msg:e}=r.data;if("done"===e){let r=0;for(let e of this.workers)void 0!==e&&(e.terminate(),console.warn("wasi done but worker exists, terminate "+r)),r++;this.start_worker.terminate(),this.start_worker=void 0;let e=new Int32Array(this.lock,12);Atomics.store(e,0,3),0===Atomics.notify(e,0)&&Atomics.store(e,0,0),console.debug("start worker done so terminate")}if("error"===e||"exit"===e){let t=0;for(let r of this.workers)void 0!==r&&(r.terminate(),"error"===e?console.warn("wasi throw error but worker exists, terminate "+t):console.debug("wasi exit but worker exists, terminate "+t)),t++;void 0!==this.start_worker&&(this.start_worker.terminate(),"error"===e?console.warn("wasi throw error but wasi exists, terminate start worker"):console.debug("wasi exit but wasi exists, terminate start worker")),this.workers=[void 0],this.start_worker=void 0;let o=new Int32Array(this.lock,12);if("error"===e){let e=r.data.error,t=serialize(e),[s,i]=await this.allocator.async_write(new TextEncoder().encode(JSON.stringify(t)),this.lock,4);if(0!==Atomics.compareExchange(o,0,0,1)){console.error("what happened?"),this.allocator.free(s,i);return}if(0===Atomics.notify(o,0))throw this.allocator.free(s,i),Atomics.store(o,0,0),e}else{let e=r.data.code;if(0!==Atomics.compareExchange(o,0,0,2))return void console.error("what happened?");Atomics.store(o,1,e),0===Atomics.notify(o,0)&&Atomics.store(o,0,0)}}},this.start_worker.postMessage({...this.override_object,...r,worker_background_ref:this.ref()})}}Atomics.store(r,1,1),Atomics.store(r,2,0),0===Atomics.notify(r,2,1)&&console.warn("notify failed, waiter is late")}}};globalThis.onmessage=r=>{let{override_object:e,worker_background_ref_object:t}=r.data;worker_background=WorkerBackground.init_self(e,t),postMessage("ready")};',e=new Blob([l],{type:"application/javascript"});return URL.createObjectURL(e)},Ge=()=>({allocator:{share_arrays_memory:new SharedArrayBuffer(10*1024)},lock:new SharedArrayBuffer(24),signature_input:new SharedArrayBuffer(24)});class V{share_memory;wasi_farm_refs_object;worker_url;worker_background_ref;worker_background_ref_object;worker_background_worker;worker_background_worker_promise;constructor(e,t,s,n=16777216,f,i,_){if(this.worker_url=e,this.wasi_farm_refs_object=t,s===void 0){const o=n/65536;if(o<16)throw new Error("The stack size must be at least 16 bytes.");const a=1073741824/65536;this.share_memory={memory:new WebAssembly.Memory({initial:o,maximum:a,shared:!0})}}else this.share_memory=s;if(f===void 0){let r;_?r=_:r=Ye(),this.worker_background_worker=new Worker(r,{type:"module"}),_||URL.revokeObjectURL(r);const{promise:o,resolve:a}=Promise.withResolvers();this.worker_background_worker_promise=o,this.worker_background_worker.onmessage=()=>{this.worker_background_worker_promise=void 0,a()},this.worker_background_ref_object=Ge(),this.worker_background_ref=q.init_self(this.worker_background_ref_object),this.worker_background_worker.postMessage({override_object:{sl_object:this.get_object(),thread_spawn_wasm:i},worker_background_ref_object:structuredClone(this.worker_background_ref_object)})}else this.worker_background_ref_object=f,this.worker_background_ref=q.init_self(this.worker_background_ref_object)}async wait_worker_background_worker(){if(this.worker_background_worker_promise){await this.worker_background_worker_promise;return}}check_worker_background_worker(){if(this.worker_background_worker_promise)throw new Error("worker_background_worker is not ready.")}thread_spawn(e,t,s,n){return this.worker_background_ref.new_worker(this.worker_url,{type:"module"},{this_is_thread_spawn:!0,start_arg:e,args:t,env:s,fd_map:n}).get_id()}async async_start_on_thread(e,t,s){if(!self.Worker.toString().includes("[native code]"))if(self.Worker.toString().includes("function"))console.warn("SubWorker(new Worker on Worker) is polyfilled maybe.");else throw new Error("SubWorker(new Worker on Worker) is not supported.");await this.worker_background_ref.async_start_on_thread(this.worker_url,{type:"module"},{this_is_thread_spawn:!0,this_is_start:!0,args:e,env:t,fd_map:s})}block_start_on_thread(e,t,s){if(!self.Worker.toString().includes("[native code]"))if(self.Worker.toString().includes("function"))console.warn("SubWorker(new Worker on Worker) is polyfilled maybe.");else throw new Error("SubWorker(new Worker on Worker) is not supported.");this.worker_background_ref.block_start_on_thread(this.worker_url,{type:"module"},{this_is_thread_spawn:!0,this_is_start:!0,args:e,env:t,fd_map:s})}static init_self(e){return new V(e.worker_url,e.wasi_farm_refs_object,e.share_memory,void 0,e.worker_background_ref_object)}static init_self_with_worker_background_ref(e,t){return new V(e.worker_url,e.wasi_farm_refs_object,e.share_memory,void 0,t)}get_share_memory(){return this.share_memory}get_object(){return{share_memory:this.share_memory,wasi_farm_refs_object:this.wasi_farm_refs_object,worker_url:this.worker_url,worker_background_ref_object:this.worker_background_ref_object}}done_notify(e){this.worker_background_ref.done_notify(e)}async async_wait_done_or_error(){if(this.worker_background_worker===void 0)throw new Error("worker_background_worker is undefined.");return await this.worker_background_ref.async_wait_done_or_error()}block_wait_done_or_error(){if(this.worker_background_worker===void 0)throw new Error("worker_background_worker is undefined.");return this.worker_background_ref.block_wait_done_or_error()}}class He{args;env;wasi_farm_refs;id_in_wasi_farm_ref;inst;wasiImport;wasiThreadImport;can_array_buffer;can_thread_spawn;thread_spawner;async wait_worker_background_worker(){await this.thread_spawner?.wait_worker_background_worker()}check_worker_background_worker(){this.thread_spawner?.check_worker_background_worker()}fd_map=[];get_fd_and_wasi_ref(e){const t=this.fd_map[e];if(!t)return[void 0,void 0];const[s,n]=t;return[s,this.wasi_farm_refs[n]]}get_fd_and_wasi_ref_n(e){const t=this.fd_map[e];if(!t)return[void 0,void 0];const[s,n]=t;return[s,n]}start(e){this.inst=e;try{if(e.exports._start(),this.can_thread_spawn){if(!this.thread_spawner)throw new Error("thread_spawner is not defined");this.thread_spawner.done_notify(0)}return 0}catch(t){if(t instanceof me)return this.can_thread_spawn&&this.thread_spawner.done_notify(t.code),t.code;throw t}}start_only(e){this.inst=e,e.exports._start()}async async_start_on_thread(){if(!this.can_thread_spawn||!this.thread_spawner)throw new Error("thread_spawn is not supported");if(await this.wait_worker_background_worker(),this.inst)throw new Error("what happened?");const e=this.thread_spawner.get_share_memory();for(const n in e)new Uint8Array(e[n].buffer).fill(0);const t=this.thread_spawner.async_wait_done_or_error();return await this.thread_spawner.async_start_on_thread(this.args,this.env,this.fd_map),await t}block_start_on_thread(){if(!this.can_thread_spawn||!this.thread_spawner)throw new Error("thread_spawn is not supported");if(console.log("block_start_on_thread"),this.check_worker_background_worker(),console.log("block_start_on_thread"),this.inst)throw new Error("what happened?");const e=this.thread_spawner.get_share_memory();for(const s in e)new Uint8Array(e[s].buffer).fill(0);console.log("block_start_on_thread: start"),this.thread_spawner.block_start_on_thread(this.args,this.env,this.fd_map),console.log("block_start_on_thread: wait");const t=this.thread_spawner.block_wait_done_or_error();return console.log("block_start_on_thread: done"),t}wasi_thread_start(e,t,s){this.inst=e,e.exports.wasi_thread_start(t,s)}initialize(e){this.inst=e,e.exports._initialize&&e.exports._initialize()}mapping_fds(e,t){this.fd_map=[void 0,void 0,void 0];for(let s=0;s0)for(let t=0;t=U.length){y.set(U,T.buf);break}y.set(U.slice(B,B+T.buf_len),T.buf),B+=T.buf_len}}return v},fd_prestat_get(o,a){r.check_fds();const[c,d]=r.get_fd_and_wasi_ref(o);if(c===void 0||d===void 0)return w;const[u,h]=d.fd_prestat_get(c);if(u){const[m,g]=u,y=new DataView(r.inst.exports.memory.buffer);y.setUint32(a,m,!0),y.setUint32(a+4,g,!0)}return h},fd_prestat_dir_name(o,a,c){r.check_fds();const[d,u]=r.get_fd_and_wasi_ref(o);if(d===void 0||u===void 0)return[void 0,w];const[h,m]=u.fd_prestat_dir_name(d,c);return h&&new Uint8Array(r.inst.exports.memory.buffer).set(h,a),m},fd_pwrite(o,a,c,d,u){r.check_fds();const[h,m]=r.get_fd_and_wasi_ref(o);if(h===void 0||m===void 0)return w;const g=new DataView(r.inst.exports.memory.buffer),y=new Uint8Array(r.inst.exports.memory.buffer),b=C.read_bytes_array(g,a,c),p=new Uint8Array(b.reduce((U,B)=>U+B.buf_len,0));let v=0;for(const U of b)p.set(y.slice(U.buf,U.buf+U.buf_len),v),v+=U.buf_len;const[I,E]=m.fd_pwrite(h,p,d);return I&&g.setUint32(u,I,!0),E},fd_read(o,a,c,d){r.check_fds();const[u,h]=r.get_fd_and_wasi_ref(o);if(u===void 0||h===void 0)return w;const m=new DataView(r.inst.exports.memory.buffer),g=new Uint8Array(r.inst.exports.memory.buffer),y=new Uint32Array(m.buffer,a,c*2),[b,p]=h.fd_read(u,y);if(b){const v=N.read_bytes_array(m,a,c),[I,E]=b;m.setUint32(d,I,!0);let U=0;for(const B of v){if(U+B.buf_len>=E.length){g.set(E,B.buf);break}g.set(E.slice(U,U+B.buf_len),B.buf),U+=B.buf_len}}return p},fd_readdir(o,a,c,d,u){r.check_fds();const[h,m]=r.get_fd_and_wasi_ref(o);if(h===void 0||m===void 0)return[void 0,w];const g=new DataView(r.inst.exports.memory.buffer),y=new Uint8Array(r.inst.exports.memory.buffer),[b,p]=m.fd_readdir(h,c,d);if(b){const[v,I]=b;g.setUint32(u,I,!0),y.set(v,a)}return p},fd_renumber(o,a){r.check_fds();const[c,d]=r.get_fd_and_wasi_ref(a);if(c!==void 0&&d!==void 0){const u=d.fd_close(c);if(r.check_fds(),u!==S)return u}if(r.fd_map[a])throw new Error("fd is already mapped");return r.fd_map[a]=r.fd_map[o],r.fd_map[o]=void 0,S},fd_seek(o,a,c,d){r.check_fds();const[u,h]=r.get_fd_and_wasi_ref(o);if(u===void 0||h===void 0)return[void 0,w];const[m,g]=h.fd_seek(u,a,c);return m&&new DataView(r.inst.exports.memory.buffer).setBigUint64(d,m,!0),g},fd_sync(o){r.check_fds();const[a,c]=r.get_fd_and_wasi_ref(o);return a===void 0||c===void 0?w:c.fd_sync(a)},fd_tell(o,a){r.check_fds();const[c,d]=r.get_fd_and_wasi_ref(o);if(c===void 0||d===void 0)return[void 0,w];const[u,h]=d.fd_tell(c);return u&&new DataView(r.inst.exports.memory.buffer).setBigUint64(a,u,!0),h},fd_write(o,a,c,d){r.check_fds();const[u,h]=r.get_fd_and_wasi_ref(o);if(u===void 0||h===void 0)return w;const m=new DataView(r.inst.exports.memory.buffer),g=new Uint8Array(r.inst.exports.memory.buffer),y=C.read_bytes_array(m,a,c),b=new Uint8Array(y.reduce((E,U)=>E+U.buf_len,0));let p=0;for(const E of y)b.set(g.slice(E.buf,E.buf+E.buf_len),p),p+=E.buf_len;const[v,I]=h.fd_write(u,b);return v&&m.setUint32(d,v,!0),I},path_create_directory(o,a,c){r.check_fds();const[d,u]=r.get_fd_and_wasi_ref(o);if(d===void 0||u===void 0)return w;const m=new Uint8Array(r.inst.exports.memory.buffer).slice(a,a+c);return u.path_create_directory(d,m)},path_filestat_get(o,a,c,d,u){r.check_fds();const[h,m]=r.get_fd_and_wasi_ref(o);if(h===void 0||m===void 0)return[void 0,w];const g=new DataView(r.inst.exports.memory.buffer),b=new Uint8Array(r.inst.exports.memory.buffer).slice(c,c+d),[p,v]=m.path_filestat_get(h,a,b);return p&&p.write_bytes(g,u),v},path_filestat_set_times(o,a,c,d,u,h,m){r.check_fds();const[g,y]=r.get_fd_and_wasi_ref(o);if(g===void 0||y===void 0)return[void 0,w];const p=new Uint8Array(r.inst.exports.memory.buffer).slice(c,c+d);return y.path_filestat_set_times(g,a,p,u,h,m)},path_link(o,a,c,d,u,h,m){r.check_fds();const[g,y]=r.get_fd_and_wasi_ref(o),[b,p]=r.get_fd_and_wasi_ref(u);if(g===void 0||y===void 0||b===void 0||p===void 0||y!==p)return w;const v=new Uint8Array(r.inst.exports.memory.buffer),I=v.slice(c,c+d),E=v.slice(h,h+m);return y.path_link(g,a,I,b,E)},path_open(o,a,c,d,u,h,m,g,y){r.check_fds();const[b,p]=r.get_fd_and_wasi_ref_n(o);if(b===void 0||p===void 0)return w;const v=r.wasi_farm_refs[p],E=new Uint8Array(r.inst.exports.memory.buffer).slice(c,c+d),[U,B]=v.path_open(b,a,E,u,h,m,g);if(U){if(r.fd_map.includes([U,p]))throw new Error("opened_fd already exists");const T=r.map_new_fd_and_notify(U,p);new DataView(r.inst.exports.memory.buffer).setUint32(y,T,!0)}return B},path_readlink(o,a,c,d,u,h){r.check_fds();const[m,g]=r.get_fd_and_wasi_ref(o);if(m===void 0||g===void 0)return[void 0,w];const y=new Uint8Array(r.inst.exports.memory.buffer),b=y.slice(a,a+c),[p,v]=g.path_readlink(m,b,u);return p&&(new DataView(r.inst.exports.memory.buffer).setUint32(h,p.length,!0),y.set(p,d)),v},path_remove_directory(o,a,c){r.check_fds();const[d,u]=r.get_fd_and_wasi_ref(o);if(d===void 0||u===void 0)return w;const m=new Uint8Array(r.inst.exports.memory.buffer).slice(a,a+c);return u.path_remove_directory(d,m)},path_rename(o,a,c,d,u,h){if(o===d)return S;r.check_fds();const[m,g]=r.get_fd_and_wasi_ref(o),[y,b]=r.get_fd_and_wasi_ref(d);if(m===void 0||g===void 0||y===void 0||b===void 0||g!==b)return w;const p=new Uint8Array(r.inst.exports.memory.buffer),v=p.slice(a,a+c),I=p.slice(u,u+h);return g.path_rename(m,v,y,I)},path_symlink(o,a,c,d,u){r.check_fds();const[h,m]=r.get_fd_and_wasi_ref(c);if(h===void 0||m===void 0)return w;const g=new Uint8Array(r.inst.exports.memory.buffer),y=g.slice(o,o+a),b=g.slice(d,d+u);return m.path_symlink(y,h,b)},path_unlink_file(o,a,c){r.check_fds();const[d,u]=r.get_fd_and_wasi_ref(o);if(d===void 0||u===void 0)return w;const m=new Uint8Array(r.inst.exports.memory.buffer).slice(a,a+c);return u.path_unlink_file(d,m)},poll_oneoff(o,a,c,d){if(c===0)return le;if(c>1)return console.error("poll_oneoff: only a single subscription is supported"),we;const u=new DataView(r.inst.exports.memory.buffer),h=re.read_bytes(u,o),m=h.eventtype,g=h.clockid,y=h.timeout;if(m!==Ve)return console.error("poll_oneoff: only clock subscriptions are supported"),we;let b;if(g===te)b=()=>BigInt(Math.round(performance.now()*1e6));else if(g===ee)b=()=>BigInt(new Date().getTime())*1000000n;else return le;const p=((h.flags&Pe)!==0?y:b()+y)-h.precision;for(;p>b(););return new Fe(h.userdata,S,m).write_bytes(u,a),u.setUint32(d,1,!0),S},proc_exit(o){throw r.check_fds(),new me(o)},proc_raise(o){throw r.check_fds(),`raised signal ${o}`},sched_yield(){r.check_fds()},random_get(o,a){r.check_fds();const c=new Uint8Array(r.inst.exports.memory.buffer).subarray(o,o+a);if("crypto"in globalThis&&!(r.inst.exports.memory.buffer instanceof SharedArrayBuffer))for(let d=0;d{if(r.check_fds(),!r.can_thread_spawn||!r.thread_spawner)throw new Error("thread_spawn is not allowed");return r.thread_spawner.thread_spawn(o,r.args,r.env,r.fd_map)}}}}var Ze=""+new URL("thread_spawn-BZ5YoPRh.js",self.location.href).href,Qe=""+new URL("worker_background_worker-BEBzMHuk.js",self.location.href).href;let P,oe;const K=[];let Y,ie;globalThis.addEventListener("message",async l=>{if(l.data.ctx)Y=l.data.ctx,P=new G.SharedObjectRef(Y.terminal_id).proxy(),await P(`loading rustc\r `),ie=new G.SharedObjectRef(Y.waiter_id).proxy(),oe=await We(),await ie.end_rustc_fetch();else if(l.data.wasi_ref){const{wasi_ref:e}=l.data;for(K.push(e);!oe;)await new Promise(s=>setTimeout(s,100));for(await P(`loaded rustc\r `);K.length===1;)await new Promise(s=>setTimeout(s,100));await P(`loaded wasi\r `);const t=new He(K,[],["RUST_MIN_STACK=16777216"],{can_thread_spawn:!0,thread_spawn_worker_url:new URL(Ze,self.location.href).href,thread_spawn_wasm:oe,share_memory:{memory:new WebAssembly.Memory({initial:399,maximum:16384,shared:!0})},worker_background_worker_url:Qe});await t.wait_worker_background_worker(),new G.SharedObject((...s)=>{try{t.args=["rustc",...s],console.log("wasi.start"),t.block_start_on_thread(),console.log("wasi.start done")}catch(n){P(`${n.toString()}\r `)}},Y.rustc_id),ie.rustc()}else l.data.wasi_ref_ui&&K.push(l.data.wasi_ref_ui)})})();