hakuban 0.6.2 → 0.7.1

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/hakuban.min.js CHANGED
@@ -1,2 +1,2 @@
1
- let t;const e=new Array(32).fill(void 0);function n(t){return e[t]}e.push(void 0,null,!0,!1);let r=e.length;function s(t){const s=n(t);return function(t){t<36||(e[t]=r,r=t)}(t),s}let i=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});i.decode();let o=null;function _(){return null!==o&&o.buffer===t.memory.buffer||(o=new Uint8Array(t.memory.buffer)),o}function a(t,e){return i.decode(_().subarray(t,t+e))}function c(t){r===e.length&&e.push(e.length+1);const n=r;return r=e[n],e[n]=t,n}function h(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let n="[";e>0&&(n+=h(t[0]));for(let r=1;r<e;r++)n+=", "+h(t[r]);return n+="]",n}const n=/\[object ([^\]]+)\]/.exec(toString.call(t));let r;if(!(n.length>1))return toString.call(t);if(r=n[1],"Object"==r)try{return"Object("+JSON.stringify(t)+")"}catch(t){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:r}let l=0,u=new TextEncoder("utf-8");const d="function"==typeof u.encodeInto?function(t,e){return u.encodeInto(t,e)}:function(t,e){const n=u.encode(t);return e.set(n),{read:t.length,written:n.length}};function b(t,e,n){if(void 0===n){const n=u.encode(t),r=e(n.length);return _().subarray(r,r+n.length).set(n),l=n.length,r}let r=t.length,s=e(r);const i=_();let o=0;for(;o<r;o++){const e=t.charCodeAt(o);if(e>127)break;i[s+o]=e}if(o!==r){0!==o&&(t=t.slice(o)),s=n(s,r,r=o+3*t.length);const e=_().subarray(s+o,s+r);o+=d(t,e).written}return l=o,s}let g=null;function p(){return null!==g&&g.buffer===t.memory.buffer||(g=new Int32Array(t.memory.buffer)),g}function w(e,n,r){t._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2cb5c9e37b253332(e,n,c(r))}const f=new Uint32Array(2),v=new BigUint64Array(f.buffer);function m(e){var n=b(e,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l,s=t.hakuban_json_hash(n,r);return U.__wrap(s)}function y(e){t.hakuban_local_node_drop(e)}function j(e){t.hakuban_object_observe_drop(e)}function k(e){t.hakuban_object_observe_state_return(e)}function x(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_synchronized(s,e);var n=p()[s/4+0],r=p()[s/4+1];f[0]=n,f[1]=r;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}function z(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_version(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function O(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_type(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function S(t,e){return _().subarray(t/1,t/1+e)}function N(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}function J(e){t.hakuban_object_descriptor_events_drop(e)}function T(e){t.hakuban_tag_observe_drop(e)}function I(t){return null==t}function R(e){t.hakuban_remote_node_drop(e)}function A(t,e){const n=e(1*t.length);return _().set(t,n/1),l=t.length,n}function q(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;t.hakuban_remote_node_received_local_node_event(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}function F(e){t.hakuban_tag_expose_drop(e)}function P(e){t.hakuban_object_expose_drop(e)}function D(e,n){try{return e.apply(this,n)}catch(e){t.__wbindgen_exn_store(c(e))}}Object.freeze({None:0,0:"None",InvalidString:1,1:"InvalidString",InvalidJSON:2,2:"InvalidJSON",InvalidURL:3,3:"InvalidURL",ObjectNotFound:4,4:"ObjectNotFound"});class U{static __wrap(t){const e=Object.create(U.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmhashresult_free(e)}get error(){return t.__wbg_get_wasmhashresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmhashresult_error(this.ptr,e)}get hash(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmhashresult_hash(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set hash(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmhashresult_hash(this.ptr,n,r)}}class E{static __wrap(t){const e=Object.create(E.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmlocalnodenewresult_free(e)}get error(){return t.__wbg_get_wasmlocalnodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmlocalnodenewresult_error(this.ptr,e)}get local_node_pointer(){return t.__wbg_get_wasmlocalnodenewresult_local_node_pointer(this.ptr)}set local_node_pointer(e){t.__wbg_set_wasmlocalnodenewresult_local_node_pointer(this.ptr,e)}}class M{static __wrap(t){const e=Object.create(M.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposeresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposeresult_error(this.ptr,e)}get object_expose_pointer(){return t.__wbg_get_wasmobjectexposeresult_object_expose_pointer(this.ptr)}set object_expose_pointer(e){t.__wbg_set_wasmobjectexposeresult_object_expose_pointer(this.ptr,e)}}class W{static __wrap(t){const e=Object.create(W.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposestateresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposestateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposestateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmobjectexposestateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmobjectexposestateresult_changed(this.ptr,e)}}class B{static __wrap(t){const e=Object.create(B.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectobserveresult_free(e)}get error(){return t.__wbg_get_wasmobjectobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectobserveresult_error(this.ptr,e)}get object_observe_pointer(){return t.__wbg_get_wasmobjectobserveresult_object_observe_pointer(this.ptr)}set object_observe_pointer(e){t.__wbg_set_wasmobjectobserveresult_object_observe_pointer(this.ptr,e)}}class ${static __wrap(t){const e=Object.create($.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmremotenodenewresult_free(e)}get error(){return t.__wbg_get_wasmremotenodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmremotenodenewresult_error(this.ptr,e)}get remote_node_pointer(){return t.__wbg_get_wasmremotenodenewresult_remote_node_pointer(this.ptr)}set remote_node_pointer(e){t.__wbg_set_wasmremotenodenewresult_remote_node_pointer(this.ptr,e)}}class C{static __wrap(t){const e=Object.create(C.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeassignmentresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeassignmentresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeassignmentresult_error(this.ptr,e)}get assignment(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmtagexposeassignmentresult_assignment(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set assignment(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmtagexposeassignmentresult_assignment(this.ptr,n,r)}}class L{static __wrap(t){const e=Object.create(L.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeresult_error(this.ptr,e)}get tag_expose_pointer(){return t.__wbg_get_wasmtagexposeresult_tag_expose_pointer(this.ptr)}set tag_expose_pointer(e){t.__wbg_set_wasmtagexposeresult_tag_expose_pointer(this.ptr,e)}}class H{static __wrap(t){const e=Object.create(H.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposesetobjectstateresult_free(e)}get error(){return t.__wbg_get_wasmtagexposesetobjectstateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposesetobjectstateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmtagexposesetobjectstateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmtagexposesetobjectstateresult_changed(this.ptr,e)}}class Q{static __wrap(t){const e=Object.create(Q.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveobjectstateborrowresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_error(this.ptr,e)}get state_pointer(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr)}set state_pointer(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr,e)}}class G{static __wrap(t){const e=Object.create(G.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveresult_error(this.ptr,e)}get tag_observe_pointer(){return t.__wbg_get_wasmtagobserveresult_tag_observe_pointer(this.ptr)}set tag_observe_pointer(e){t.__wbg_set_wasmtagobserveresult_tag_observe_pointer(this.ptr,e)}}async function K(e){void 0===e&&(e=new URL("hakuban_bg.wasm",import.meta.url));const r={wbg:{}};r.wbg.__wbindgen_object_drop_ref=function(t){s(t)},r.wbg.__wbindgen_string_new=function(t,e){return c(a(t,e))},r.wbg.__wbindgen_cb_drop=function(t){const e=s(t).original;if(1==e.cnt--)return e.a=0,!0;return!1},r.wbg.__wbg_debug_6e114a5b27d7915d=function(t){console.debug(n(t))},r.wbg.__wbg_error_ca520cb687b085a1=function(t){console.error(n(t))},r.wbg.__wbg_info_32ab782ec7072fac=function(t){console.info(n(t))},r.wbg.__wbg_log_fbd13631356d44e4=function(t){console.log(n(t))},r.wbg.__wbg_warn_97f10a6b0dbb8c5c=function(t){console.warn(n(t))},r.wbg.__wbg_now_5fa0ca001e042f8a=function(t){return n(t).now()},r.wbg.__wbg_newnoargs_f579424187aa1717=function(t,e){return c(new Function(a(t,e)))},r.wbg.__wbg_get_8bbb82393651dd9c=function(){return D((function(t,e){return c(Reflect.get(n(t),n(e)))}),arguments)},r.wbg.__wbg_call_89558c3e96703ca1=function(){return D((function(t,e){return c(n(t).call(n(e)))}),arguments)},r.wbg.__wbg_call_94697a95cb7e239c=function(){return D((function(t,e,r){return c(n(t).call(n(e),n(r)))}),arguments)},r.wbg.__wbg_new_4beacc9c71572250=function(e,n){try{var r={a:e,b:n},s=new Promise(((e,n)=>{const s=r.a;r.a=0;try{return function(e,n,r,s){t.wasm_bindgen__convert__closures__invoke2_mut__h3fbc4a767cc461bf(e,n,c(r),c(s))}(s,r.b,e,n)}finally{r.a=s}}));return c(s)}finally{r.a=r.b=0}},r.wbg.__wbg_resolve_4f8f547f26b30b27=function(t){return c(Promise.resolve(n(t)))},r.wbg.__wbg_then_a6860c82b90816ca=function(t,e){return c(n(t).then(n(e)))},r.wbg.__wbg_then_58a04e42527f52c6=function(t,e,r){return c(n(t).then(n(e),n(r)))},r.wbg.__wbg_self_e23d74ae45fb17d1=function(){return D((function(){return c(self.self)}),arguments)},r.wbg.__wbg_window_b4be7f48b24ac56e=function(){return D((function(){return c(window.window)}),arguments)},r.wbg.__wbg_globalThis_d61b1f48a57191ae=function(){return D((function(){return c(globalThis.globalThis)}),arguments)},r.wbg.__wbg_global_e7669da72fd7f239=function(){return D((function(){return c(global.global)}),arguments)},r.wbg.__wbindgen_is_undefined=function(t){return void 0===n(t)},r.wbg.__wbindgen_object_clone_ref=function(t){return c(n(t))},r.wbg.__wbg_new_693216e109162396=function(){return c(new Error)},r.wbg.__wbg_stack_0ddaca5d1abfb52f=function(e,r){var s=b(n(r).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbg_error_09919627ac0992f5=function(e,n){try{console.error(a(e,n))}finally{t.__wbindgen_free(e,n)}},r.wbg.__wbindgen_debug_string=function(e,r){var s=b(h(n(r)),t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbindgen_throw=function(t,e){throw new Error(a(t,e))},r.wbg.__wbindgen_closure_wrapper2024=function(e,n,r){var s=function(e,n,r,s){const i={a:e,b:n,cnt:1,dtor:r},o=(...e)=>{i.cnt++;const n=i.a;i.a=0;try{return s(n,i.b,...e)}finally{0==--i.cnt?t.__wbindgen_export_2.get(i.dtor)(n,i.b):i.a=n}};return o.original=i,o}(e,n,490,w);return c(s)},("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));const{instance:i,module:o}=await async function(t,e){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,e)}catch(e){if("application/wasm"==t.headers.get("Content-Type"))throw e;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",e)}const n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}{const n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}}(await e,r);return t=i.exports,K.__wbindgen_wasm_module=o,t}var V;V=class{constructor(){this.queue=[],this.wake=null}push(t){if(this.queue.push(t),null!=this.wake)return this.wake(),this.wake=null}async shift(){for(var t;;){if(null!=(t=this.queue.shift()))return t;if(null!=this.wake)throw"2 concurrent shifts on a single queue";await new Promise((t=>(this.wake=t,null)))}}clear(){return this.queue=[]}};var X,Y,Z,tt,et,nt,rt,st,it,ot,_t,at,ct,ht,lt,ut,dt=class{constructor(t,e){this.contract=t,this.managed_object_class=e,this._on_exception_policy="retry",this._retry_backoff=[.01,.1,1,10],this._terminate_on_deactivation=!1}on_exception(t){return this._on_exception_policy=t,this}retry_backoff(t){return this._retry_backoff=t,this}with_async(t){return new bt(this.contract,this.managed_object_class,t,this._retry_backoff,this._terminate_on_deactivation,this._on_exception_policy)}},bt=class{constructor(t,e,n,r,s,i){var o;this.objects=this.objects.bind(this),this.object=this.object.bind(this),this.drop=this.drop.bind(this),this.contract=t,this._existing_objects={},this._active_objects={},this.event_queue=new V,o=new Promise((t=>(this.event_loop_stop=t,null))),this.event_loop_stopped=new Promise((async(t,e)=>{var n,r;for(r=this.contract.events();(n=await Promise.race([r.next(),o]))&&null!=n;)this.event_queue.push(n);return r.drop(),t()})),this.async_loop_stopped=new Promise((async(t,s)=>{for(var o,_,a,c,h,l,u,d,b,g,p,w,f,v;null!=(h=await this.event_queue.shift());)switch(h.action){case"Insert":case"Change":case"Remove":case"Stopped":case"Timer":if(!(w=(o=this._existing_objects)[g=h.descriptor.hash()]||(o[g]=new e(this.contract,h.descriptor))).running&&null!=w.block_result&&(c=await w.block_result,w.block_result=null,null!=w.last_exception_at&&(u=Date.now()-w.last_exception_at,10,w.current_delay_index-=Math.floor(u/(1e3*r[r.length-1]*10)),w.current_delay_index<0&&(w.current_delay_index=0)),null!=c))switch(i){case"throw":case"raise":throw c.exception;case"retry":w.last_exception_at=Date.now(),w.earliest_next_run=Date.now()+1e3*r[w.current_delay_index],function(t,e,n){setTimeout((()=>n.push({action:"Timer",descriptor:e})),t)}(w.earliest_next_run-Date.now(),h.descriptor,this.event_queue),w.current_delay_index<r.length-1&&(w.current_delay_index+=1)}w.check_active()?(null!=n&&!w.running&&(null==w.earliest_next_run||Date.now()>=w.earliest_next_run)&&(a=h.descriptor,w.running=!0,w.block_result=function(t,e,n,r){return new Promise((async(t,s)=>{try{return await e.run(n),t(void 0)}catch(e){return c=e,console.error("Exception in hakuban manager lambda:",c),t(c)}finally{e.running=!1,r.push({action:"Stopped",descriptor:a})}}))}(h.descriptor,w,n,this.event_queue)),(_=this._active_objects)[p=h.descriptor.hash()]||(_[p]=w),w.change()):(delete this._active_objects[h.descriptor.hash()],w.running?w.stop():delete this._existing_objects[h.descriptor.hash()]);break;case"Drop":for(d in this.event_loop_stop(),await this.event_loop_stopped,f={...this._existing_objects})(w=f[d]).running?w.stop():delete this._existing_objects[d];for(;Object.keys(this._existing_objects).length>0;)"Stopped"===(h=await this.event_queue.shift()).action&&delete this._existing_objects[h.descriptor.hash()];for(this.event_queue.clear(),l=0,b=(v=Object.keys(this._active_objects)).length;l<b;l++)d=v[l],delete this._active_objects[d];return this.contract.drop(),this.contract=null,this.event_queue=null,void t();default:throw"Unknown action: "+h.action}return s("Queue died unexpectedly")}))}objects(){return Object.values(this._active_objects)}object(){return Object.values(this._active_objects)[0]}async drop(){if(this.contract)return this.event_queue.push({action:"Drop"}),await this.async_loop_stopped}},gt=class{constructor(t,e){this.run=this.run.bind(this),this.next_event=this.next_event.bind(this),this.next_change=this.next_change.bind(this),this.change=this.change.bind(this),this.stop=this.stop.bind(this),this.contract=t,this.descriptor=e,this._changes=new V,this.current_delay_index=0}async run(t){return await t(this)}next_event(){return this.next_change()}async next_change(){for(;;)switch(await this._changes.shift()){case"change":return!0;case"stop":return!1}}change(){return this._changes.push("change")}stop(){return this._changes.push("stop")}},pt=function(t,e){if(!(t instanceof e))throw new Error("Bound instance method accessed before binding")};lt=!1;var wt=async function(t){return await K(t)},ft=async function(e,n=!1){var r,s,i,o;return!(!lt||!n)||(0===(r=await(s=e,i=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),o=l,t.hakuban_logger_initialize(i,o)))?lt=!0:(console.error("Failed to initialize logger, error "+r),!1))};ut=function(t){if(0!==t)throw"Hakuban error: "+t};var vt=function(t,e){return{data_type:["JSON"].concat(t),data:(new TextEncoder).encode(JSON.stringify(e))}},mt=function(t,e){if(0===t.length||"JSON"!==t[0])throw"Expected JSON data_type, got: "+t;return{data_type:t.slice(1),data:JSON.parse((new TextDecoder).decode(e))}},yt=class{constructor(t,e){var n;this.json=e,this.tags=function(){var e,r,s;for(s=[],e=0,r=t.length;e<r;e++)n=t[e],s.push(n instanceof jt?n:new jt(n));return s}()}as_json(){return JSON.stringify({tags:this.tags.map((function(t){return t.json})),json:this.json})}hash(){var t;return null==this._hash&&(this._hash=this.tags.map((function(t){return t.hash().toString()})).sort().join(",")+"|",t=m(JSON.stringify(this.json)),ut(t.error),this._hash+=t.hash.toString()),this._hash}},jt=class{constructor(t){this.json=t}as_json(){return JSON.stringify(this.json)}hash(){var t;return null==this._hash&&(t=m(JSON.stringify(this.json)),ut(t.error),this._hash=t.hash),this._hash}};X=new FinalizationRegistry((t=>y(t)));var kt=class{constructor(e="wasm"){var n,r,s,i,o;this.name=e,ft("warn",!0),r=this.name,s=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l,o=t.hakuban_local_node_new(s,i),n=E.__wrap(o),ut(n.error),this.pointer=n.local_node_pointer,X.register(this,this.pointer,this),this.with_default_serializer(vt),this.with_default_deserializer(mt)}destroy(){return y(this.pointer),X.unregister(this)}object(t,e){return new Y(this,this.default_serializer,this.default_deserializer,t,e)}tag(t){return new it(this,this.default_serializer,this.default_deserializer,t)}with_default_serializer(t){return this.default_serializer=t,this}with_default_deserializer(t){return this.default_deserializer=t,this}};Y=class{constructor(t,e,n,r,s){this.local_node=t,this.serializer=e,this.deserializer=n,this.tags=r,this.json=s}observe(){return new rt(this.local_node,new yt(this.tags,this.json),this.deserializer)}expose(){return new et(this.local_node,new yt(this.tags,this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},it=class{constructor(t,e,n,r){this.local_node=t,this.serializer=e,this.deserializer=n,this.json=r}observe(){return new at(this.local_node,new jt(this.json),this.deserializer)}expose(){return new ot(this.local_node,new jt(this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},tt=new FinalizationRegistry((t=>J(t))),Z=class{constructor(t){this.wait=this.wait.bind(this),this.next=this.next.bind(this),this.drop=this.drop.bind(this),this.pointer=t,tt.register(this,this.pointer,this)}wait(){return next()}next(){var e,n,r,i;return this.wait_released=new Promise((t=>(this.wait_release=t,null))),e=new Promise((t=>this.cancel_waiting_resolve=t)),r=this.pointer,i=e,(n=s(t.hakuban_object_descriptor_events_next(r,c(i)))).cancel=async t=>(this.cancel_waiting_resolve.resolve(t),await n),n.then((t=>{var e;return this.wait_release(),this.wait_released=null,this.cancel_waiting_resolve=null,{action:(e=JSON.parse(t)).action,descriptor:new yt(e.key.tags,e.key.json)}}))}async drop(){return null!=this.cancel_waiting_resolve&&(this.cancel_waiting_resolve(),await this.wait_released),tt.unregister(this),J(this.pointer),this.pointer=null}},st=new FinalizationRegistry((t=>j(t))),rt=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_state=this.object_state.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_observe_new(e,r,s);return B.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_observe_pointer,st.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,j(this.pointer),st.unregister(this),this.pointer=null}object_state(){var e,n,r,s,i,o,_;return null==this.pointer?null:(_=this.pointer,0===(s=t.hakuban_object_observe_state_borrow(_))?null:(i=x(s),o=JSON.parse(z(s)),e=JSON.parse(O(s)),r=N(s),k(s),{version:o,data:(n=this.deserializer(e,r)).data,data_type:n.data_type,synchronized:i}))}events(){return new Z((e=this.pointer,t.hakuban_object_observe_events_get(e)));var e}manage(){return new dt(this,class extends gt{state(){var t;return null!=(t=this.contract)?t.object_state():void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state())?e.data:void 0}check_active(){return!!this.state()}})}},nt=new FinalizationRegistry((t=>P(t))),et=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_expose_new(e,r,s);return M.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_expose_pointer,nt.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,P(this.pointer),nt.unregister(this)}set_object_state(e,n,r=[],s=0){var i,o;return o=this.serializer(r,n),"bigint"!=typeof s&&(s=BigInt(s)),i=function(e,n,r,s,i){var o=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),_=l,a=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),c=l,h=A(s,t.__wbindgen_malloc),u=l;v[0]=i;const d=f[0],g=f[1];var p=t.hakuban_object_expose_set_state(e,o,_,a,c,h,u,d,g);return W.__wrap(p)}(this.pointer,JSON.stringify(e),JSON.stringify(o.data_type),o.data,s),ut(i.error),i.changed}assignment(){return function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_expose_assignment(s,e);var n=p()[s/4+0],r=p()[s/4+1];return f[0]=n,f[1]=r,v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.pointer)}assigned(){return this.assignment()>0}desynchronize(e){return"bigint"!=typeof e&&(e=BigInt(e)),function(e,n){v[0]=n;const r=f[0],s=f[1];t.hakuban_object_expose_desynchronize(e,r,s)}(this.pointer,e)}events(){return new Z((e=this.pointer,t.hakuban_object_expose_events_get(e)));var e}manage(){return new dt(this,class t extends gt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment()}async run(e){var n;return pt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this._assignment):void 0}do_change(e){var n;return pt(this,t),this._assignment=null!=(n=this.contract)?n.assignment():void 0,super.do_change(e)}assignment(){var e;return pt(this,t),null!=(e=this.contract)?e.assignment():void 0}assigned(){var e;return pt(this,t),null!=(e=this.contract)?e.assigned():void 0}set_state(e,n,r=[]){var s;return pt(this,t),null!=(s=this.contract)?s.set_object_state(e,n,r,this._assignment):void 0}set_data(e){var n;return pt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}check_active(){return this.assigned()}})}},ct=new FinalizationRegistry((t=>T(t))),at=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.object_state=this.object_state.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_new(e,r,s);return G.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_observe_pointer,ct.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,T(this.pointer),ct.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_observe_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new yt(e.tags,e.json));return o}object_state(e){var n,r,s,i,o,_;return 4===(i=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_object_state_borrow(e,r,s);return Q.__wrap(i)}(this.pointer,e.as_json())).error||0===i.state_pointer?null:(o=x(i.state_pointer),_=JSON.parse(z(i.state_pointer)),n=JSON.parse(O(i.state_pointer)),s=N(i.state_pointer),k(i.state_pointer),{version:_,data:(r=this.deserializer(n,s)).data,data_type:r.data_type,synchronized:o})}events(){return new Z((e=this.pointer,t.hakuban_tag_observe_events_get(e)));var e}manage(){return new dt(this,class extends gt{state(){var t;return null!=(t=this.contract)?t.object_state(this.descriptor):void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state(this.descriptor))?e.data:void 0}check_active(){return!!this.state()}})}},_t=new FinalizationRegistry((t=>F(t))),ot=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_new(e,r,s);return L.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_expose_pointer,_t.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,F(this.pointer),_t.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_expose_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new yt(e.tags,e.json));return o}set_object_state(e,n,r,s=[],i=0){var o,_;return _=this.serializer(s,r),"bigint"!=typeof i&&(i=BigInt(i)),o=function(e,n,r,s,i,o){var _=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),a=l,c=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),h=l,u=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),d=l,g=A(i,t.__wbindgen_malloc),p=l;v[0]=o;const w=f[0],m=f[1];var y=t.hakuban_tag_expose_set_object_state(e,_,a,c,h,u,d,g,p,w,m);return H.__wrap(y)}(this.pointer,e.as_json(),JSON.stringify(n),JSON.stringify(_.data_type),_.data,i),ut(o.error),o.changed}assignment(e){var n;return n=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_assignment(e,r,s);return C.__wrap(i)}(this.pointer,e.as_json()),ut(n.error),n.assignment}assigned(t){return this.assignment(t)>0}desynchronize(e,n){var r;return"bigint"!=typeof n&&(n=BigInt(n)),r=function(e,n,r){var s=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;v[0]=r;const o=f[0],_=f[1];return t.hakuban_tag_expose_desynchronize(e,s,i,o,_)>>>0}(this.pointer,e.as_json(),n),ut(r)}events(){return new Z((e=this.pointer,t.hakuban_tag_expose_events_get(e)));var e}manage(){return new dt(this,class t extends gt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment(this.descriptor)}async run(e){var n;return pt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this.descriptor,this._assignment):void 0}do_change(e){var n;return pt(this,t),this._assignment=null!=(n=this.contract)?n.assignment(this.descriptor):void 0,super.do_change(e)}assignment(){var e;return pt(this,t),null!=(e=this.contract)?e.assignment(this.descriptor):void 0}assigned(){var e;return pt(this,t),null!=(e=this.contract)?e.assigned(this.descriptor):void 0}set_state(e,n,r=[]){var s;return pt(this,t),null!=(s=this.contract)?s.set_object_state(this.descriptor,e,n,r,this._assignment):void 0}set_data(e){var n;return pt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}check_active(){return this.assigned()}})}},ht=new FinalizationRegistry((t=>R(t)));var xt=class{constructor(e,n,r={}){var s,i,o,_,a,c;this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.ack=this.ack.bind(this),this.local_node=e,this.uri=n,this.options=r,this.connected=!1,this.socket=void 0,this.error=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.ack_timer=void 0,i=this.local_node.pointer,o=!0,_=!0,a=!0,c=t.hakuban_remote_node_new(i,o,I(_)?16777215:_?1:0,I(a)?16777215:a?1:0),s=$.__wrap(c),ut(s.error),this.remote_node_pointer=s.remote_node_pointer,this.event_loop_stop=new Promise((t=>this.event_loop_stop_resolve=t)),this.event_loop_promise=this.event_loop(),ht.register(this,this.remote_node_pointer,this),this.connect()}async destroy(){return this.event_loop_stop_resolve(["stop"]),await this.event_loop_promise,this.reconnect_on_close=!1,this.keep_alive_interval&&clearInterval(this.keep_alive_interval),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.socket&&(this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null,this.socket.close(),this.socket_onclose()),null!=this.ack_timer&&(clearTimeout(this.ack_timer),this.ack_timer=null),R(this.remote_node_pointer),ht.unregister(this)}connect(){var e;this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(t){return e=t,this.error={while:"connecting",error:e},null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{var e;return this.options.debug&&console.debug("Connected to hakuban remote node"),this.connected=!0,this.error=void 0,null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),e=function(e){try{const _=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_connected(_,e);var n=p()[_/4+0],r=p()[_/4+1],i=p()[_/4+2];if(p()[_/4+3])throw s(i);var o=S(n,r).slice();return t.__wbindgen_free(n,1*r),o}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer),this.send(e)},this.socket.onclose=this.socket_onclose=()=>{var e;if(this.options.debug&&console.debug("Disconnected from hakuban remote node"),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.connected=!1,this.socket=void 0,e=this.remote_node_pointer,t.hakuban_remote_node_disconnected(e),null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=null,this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onerror=t=>(this.options.debug&&console.debug("Hakuban socket error",t),this.error={while:"connected",error:t}),this.socket.onmessage=e=>{var n;return n=function(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=A(n,t.__wbindgen_malloc),i=l;t.hakuban_remote_node_received_message(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer,new Uint8Array(e.data)),this.send(n),null!=this.ack_timer&&clearTimeout(this.ack_timer),this.ack_timer=setTimeout(this.ack,1e3),null}}ping(){if(this.socket)return this.socket.send(new Uint8Array)}send(t){if(t.length>0)return this.socket.send(t),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.keep_alive_interval=setInterval(this.ping,1e4)}ack(){var e;if(null!=this.socket&&(e=function(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_ack(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer)).length>0)return this.send(e)}async event_loop(){var e,n,r,i,o,_,a;for(i=!1,n=null,e=new Promise((function(t){return n=t}));i||(i=(_=this.remote_node_pointer,a=e,s(t.hakuban_remote_node_next_local_node_event(_,c(a)))).then((function(t){return["local_node_event",t]}))),[o,r]=await Promise.any([this.event_loop_stop,i]),"local_node_event"===o;)i=!1,setTimeout((t=>{var e;if(this.connected)return e=q(this.remote_node_pointer,t),this.send(e)}),0,r);if(i)return n(!0),await i}onstatuschange(t){return this.onstatuschange_proc=t,null!=this.onstatuschange_proc&&this.onstatuschange_proc(),this}},zt=async function(t){return await wt(t)};export{mt as JSON_deserialize,vt as JSON_serialize,kt as LocalNode,yt as ObjectDescriptor,jt as TagDescriptor,xt as WebsocketConnector,zt as initialize,wt as initialize_wasm,ft as logger_initialize};
1
+ let t;const n=new Array(32).fill(void 0);function e(t){return n[t]}n.push(void 0,null,!0,!1);let r=n.length;function i(t){const i=e(t);return function(t){t<36||(n[t]=r,r=t)}(t),i}let o=0,a=new Uint8Array;function s(){return 0===a.byteLength&&(a=new Uint8Array(t.memory.buffer)),a}const _=new TextEncoder("utf-8"),c="function"==typeof _.encodeInto?function(t,n){return _.encodeInto(t,n)}:function(t,n){const e=_.encode(t);return n.set(e),{read:t.length,written:e.length}};function l(t,n,e){if(void 0===e){const e=_.encode(t),r=n(e.length);return s().subarray(r,r+e.length).set(e),o=e.length,r}let r=t.length,i=n(r);const a=s();let l=0;for(;l<r;l++){const n=t.charCodeAt(l);if(n>127)break;a[i+l]=n}if(l!==r){0!==l&&(t=t.slice(l)),i=e(i,r,r=l+3*t.length);const n=s().subarray(i+l,i+r);l+=c(t,n).written}return o=l,i}let h=new Int32Array;function u(){return 0===h.byteLength&&(h=new Int32Array(t.memory.buffer)),h}const d=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});function w(t,n){return d.decode(s().subarray(t,t+n))}function f(t){r===n.length&&n.push(n.length+1);const e=r;return r=n[e],n[e]=t,e}function g(t){const n=typeof t;if("number"==n||"boolean"==n||null==t)return`${t}`;if("string"==n)return`"${t}"`;if("symbol"==n){const n=t.description;return null==n?"Symbol":`Symbol(${n})`}if("function"==n){const n=t.name;return"string"==typeof n&&n.length>0?`Function(${n})`:"Function"}if(Array.isArray(t)){const n=t.length;let e="[";n>0&&(e+=g(t[0]));for(let r=1;r<n;r++)e+=", "+g(t[r]);return e+="]",e}const e=/\[object ([^\]]+)\]/.exec(toString.call(t));let r;if(!(e.length>1))return toString.call(t);if(r=e[1],"Object"==r)try{return"Object("+JSON.stringify(t)+")"}catch(t){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:r}function p(n){t.hakuban_tag_expose_contract_drop(n)}d.decode();let b=new Uint32Array;function y(){return 0===b.byteLength&&(b=new Uint32Array(t.memory.buffer)),b}function v(t,n){return y().subarray(t/4,t/4+n)}function k(n){t.hakuban_tag_observe_contract_drop(n)}function m(n){t.hakuban_tag_descriptor_drop(n)}function x(n,e){const r=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=o,a=function(t,n){const e=n(4*t.length);return y().set(t,e/4),o=t.length,e}(e,t.__wbindgen_malloc),s=o,_=t.hakuban_object_descriptor_new(r,i,a,s);return Q.__wrap(_)}function j(n){t.hakuban_object_descriptor_drop(n)}let A=new BigUint64Array;function z(){return 0===A.byteLength&&(A=new BigUint64Array(t.memory.buffer)),A}function I(t,n){const e=n(1*t.length);return s().set(t,e/1),o=t.length,e}function O(n,e,r,i){const a=function(t,n){const e=n(8*t.length);return z().set(t,e/8),o=t.length,e}(n,t.__wbindgen_malloc),s=o,_=function(t,n){const e=n(4*t.length),r=y();for(let n=0;n<t.length;n++)r[e/4+n]=f(t[n]);return o=t.length,e}(e,t.__wbindgen_malloc),c=o,l=I(r,t.__wbindgen_malloc),h=o,u=t.hakuban_object_state_new(a,s,_,c,l,h,i);return Q.__wrap(u)}function P(n){t.hakuban_object_state_drop(n)}let S=new BigInt64Array;function U(n,e){return(0===S.byteLength&&(S=new BigInt64Array(t.memory.buffer)),S).subarray(n/8,n/8+e)}function L(n){try{const a=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_format(a,n);var e=u()[a/4+0],r=u()[a/4+1],o=function(t,n){const e=y().subarray(t/4,t/4+n),r=[];for(let t=0;t<e.length;t++)r.push(i(e[t]));return r}(e,r).slice();return t.__wbindgen_free(e,4*r),o}finally{t.__wbindgen_add_to_stack_pointer(16)}}function R(t,n){return s().subarray(t/1,t/1+n)}function T(n){t.hakuban_object_state_stream_drop(n)}function B(n){t.hakuban_remote_exchange_drop(n)}function D(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_message_take(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=R(e,r).slice();return t.__wbindgen_free(e,1*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}function N(n,e,r){const i=t.hakuban_future_returning_pointer_poll(n,e,r);return Q.__wrap(i)}function E(n){t.hakuban_future_returning_nothing_drop(n)}function J(n,e,r){const i=t.hakuban_future_returning_nothing_poll(n,e,r);return K.__wrap(i)}function W(n){t.hakuban_future_returning_nothing_drop(n)}function F(n){t.hakuban_object_state_sink_drop(n)}function $(n){t.hakuban_object_state_sink_params_drop(n)}function q(n){t.hakuban_local_exchange_drop(n)}function C(n){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_local_exchange_notified(s,n);var e=u()[s/4+0],r=u()[s/4+1],i=(o=e,a=r,z().subarray(o/8,o/8+a)).slice();return t.__wbindgen_free(e,8*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}var o,a}function M(n){t.hakuban_object_expose_contract_drop(n)}function H(n){t.hakuban_object_observe_contract_drop(n)}function G(n,e){try{return n.apply(this,e)}catch(n){t.__wbindgen_exn_store(f(n))}}Object.freeze({Ok:0,0:"Ok",Pending:1,1:"Pending",NotAvailable:2,2:"NotAvailable",InvalidString:3,3:"InvalidString",InvalidJSON:4,4:"InvalidJSON",InvalidURL:5,5:"InvalidURL",InvalidLogLevel:6,6:"InvalidLogLevel",UnknownError:7,7:"UnknownError"});class K{static __wrap(t){const n=Object.create(K.prototype);return n.ptr=t,n}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const n=this.__destroy_into_raw();t.__wbg_wasmresultwithnothing_free(n)}get status(){return t.__wbg_get_wasmresultwithnothing_status(this.ptr)>>>0}set status(n){t.__wbg_set_wasmresultwithnothing_status(this.ptr,n)}}class Q{static __wrap(t){const n=Object.create(Q.prototype);return n.ptr=t,n}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const n=this.__destroy_into_raw();t.__wbg_wasmresultwithpointer_free(n)}get status(){return t.__wbg_get_wasmresultwithpointer_status(this.ptr)>>>0}set status(n){t.__wbg_set_wasmresultwithpointer_status(this.ptr,n)}get value(){return t.__wbg_get_wasmresultwithpointer_value(this.ptr)}set value(n){t.__wbg_set_wasmresultwithpointer_value(this.ptr,n)}}function V(){const n={wbg:{}};return n.wbg.__wbindgen_object_drop_ref=function(t){i(t)},n.wbg.__wbindgen_string_get=function(n,r){const i=e(r),a="string"==typeof i?i:void 0;var s=null==a?0:l(a,t.__wbindgen_malloc,t.__wbindgen_realloc),_=o;u()[n/4+1]=_,u()[n/4+0]=s},n.wbg.__wbindgen_string_new=function(t,n){return f(w(t,n))},n.wbg.__wbg_now_8172cd917e5eda6b=function(t){return e(t).now()},n.wbg.__wbg_debug_f15cb542ea509609=function(t){console.debug(e(t))},n.wbg.__wbg_error_ef9a0be47931175f=function(t){console.error(e(t))},n.wbg.__wbg_info_2874fdd5393f35ce=function(t){console.info(e(t))},n.wbg.__wbg_log_4b5638ad60bdc54a=function(t){console.log(e(t))},n.wbg.__wbg_warn_58110c4a199df084=function(t){console.warn(e(t))},n.wbg.__wbg_newnoargs_b5b063fc6c2f0376=function(t,n){return f(new Function(w(t,n)))},n.wbg.__wbg_get_765201544a2b6869=function(){return G((function(t,n){return f(Reflect.get(e(t),e(n)))}),arguments)},n.wbg.__wbg_call_97ae9d8645dc388b=function(){return G((function(t,n){return f(e(t).call(e(n)))}),arguments)},n.wbg.__wbg_self_6d479506f72c6a71=function(){return G((function(){return f(self.self)}),arguments)},n.wbg.__wbg_window_f2557cc78490aceb=function(){return G((function(){return f(window.window)}),arguments)},n.wbg.__wbg_globalThis_7f206bda628d5286=function(){return G((function(){return f(globalThis.globalThis)}),arguments)},n.wbg.__wbg_global_ba75c50d1cf384f4=function(){return G((function(){return f(global.global)}),arguments)},n.wbg.__wbindgen_is_undefined=function(t){return void 0===e(t)},n.wbg.__wbindgen_object_clone_ref=function(t){return f(e(t))},n.wbg.__wbg_new_abda76e883ba8a5f=function(){return f(new Error)},n.wbg.__wbg_stack_658279fe44541cf6=function(n,r){const i=l(e(r).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),a=o;u()[n/4+1]=a,u()[n/4+0]=i},n.wbg.__wbg_error_f851667af71bcfc6=function(n,e){try{console.error(w(n,e))}finally{t.__wbindgen_free(n,e)}},n.wbg.__wbindgen_debug_string=function(n,r){const i=l(g(e(r)),t.__wbindgen_malloc,t.__wbindgen_realloc),a=o;u()[n/4+1]=a,u()[n/4+0]=i},n.wbg.__wbindgen_throw=function(t,n){throw new Error(w(t,n))},n}async function X(n){void 0===n&&(n=new URL("hakuban_bg.wasm",import.meta.url));const e=V();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:r,module:i}=await async function(t,n){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,n)}catch(n){if("application/wasm"==t.headers.get("Content-Type"))throw n;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",n)}const e=await t.arrayBuffer();return await WebAssembly.instantiate(e,n)}{const e=await WebAssembly.instantiate(t,n);return e instanceof WebAssembly.Instance?{instance:e,module:t}:e}}(await n,e);return function(n,e){return t=n.exports,X.__wbindgen_wasm_module=e,S=new BigInt64Array,A=new BigUint64Array,h=new Int32Array,b=new Uint32Array,a=new Uint8Array,t}(r,i)}var Y,Z,tt=function(t){if(0===t.status)return t.value;throw"hakuban wasm call failed: "+t.status},nt=function(t){if(0===t.status)return t.value;if(2===t.status)return null;throw"hakuban wasm call failed: "+t.status},et=class{constructor(t,n,e,r,i){this.local_exchange=t,this.future_owner=n,this.poll_function=e,this.drop_function=r,this._pointer=i}async await_and_drop(t=null){var n,e,r,i;try{for(n=new Promise((t=>this.lock_id=this.future_owner.drop_lock(t)));;)switch(e=this.local_exchange.notified(),(r=this.local_exchange.with_pointer((t=>this.poll_function(t,this._pointer,e.id)))).status){case 0:return r.value;case 1:switch(i=[e,n],null!=t&&i.push(t),await Promise.race(i)){case"ABORT":return!1;case"DROP":return null}break;case 2:return null;default:throw r.status}}finally{this.drop_function(this._pointer),this.future_owner.drop_release(this.lock_id),null!=e&&this.local_exchange.return_notified(e)}}},rt=function(n,e=!1){var r;return 0===(r=function(n){const e=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o;return t.hakuban_logger_initialize(e,r)>>>0}(n))||(console.error("Failed to initialize logger, error "+r),!1)};Z=new FinalizationRegistry((function(t){return t[0](t[1])})),Y=function(t,n){var e,r,i,o,a;try{return e=!1,null!=(a=n(t))&&"function"==typeof a.then?(e=!0,a.finally((()=>{var n,e,r,i,o;for(o=[],n=0,e=(i=[t].flat()).length;n<e;n++)r=i[n],o.push(r.drop());return o}))):a}finally{if(!e)for(r=0,i=(o=[t].flat()).length;r<i;r++)o[r].drop()}};var it,ot=function(t,n){return null!=n?Y(t,n):t},at=class{constructor(){this.message="PointerAlreadyDropped"}},st=class t{initialize_pointer(t,n,e){return this._local_exchange=t,this._pointer=n,this._drop_function=e,this._was_dropped=null,this._drop_locks_sequence=0,this._drop_locks={},Z.register(this,[this._drop_function,this._pointer],this)}dropped(){return null!=this._was_dropped}drop(){return null==this._was_dropped&&(this._was_dropped=new Promise((async t=>{var n,e,r,i;if(null!=this._pointer){if(Object.keys(this._drop_locks).length>0){for(n=new Promise((t=>{this._all_locks_dropped_set=t})),e=0,r=(i=Object.values(this._drop_locks)).length;e<r;e++)(0,i[e])("DROP");await n}if(Object.keys(this._drop_locks).length>0)throw"Hakuban internal error: drop was attempted with existing drop locks";Z.unregister(this),this._drop_function(this._pointer),null!=this._local_exchange&&this._local_exchange.notify()}return this._pointer=!1,t()}))),this._was_dropped}with_pointer(t){if(this.dropped())throw new at;return t(this._pointer)}do_and_drop_or_return(t){return ot(this,t)}drop_lock(n){var e;return null!=this._was_dropped&&raise(t.prototype.PointerAlreadyDropped),e=this._drop_locks_sequence++,this._drop_locks[e]=n,e}drop_release(t){if(delete this._drop_locks[t],null!=this._was_dropped&&0===Object.keys(this._drop_locks).length)return this._all_locks_dropped_set()}},_t=class extends st{constructor(n,e,r=null){var i,o;super(),null!=r?(this.json=JSON.parse(function(n){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_descriptor_json(i,n);var e=u()[i/4+0],r=u()[i/4+1];return w(e,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(e,r)}}(r)),this.tags=function(){var n,e,i,a;for(a=[],n=0,e=(i=function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_descriptor_tags(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(r)).length;n<e;n++)o=i[n],a.push(new ct(null,null,o));return a}()):(this.json=e,this.tags=function(){var t,e,r;for(r=[],t=0,e=n.length;t<e;t++)i=n[t],r.push(i instanceof ct?i:new ct(i));return r}(),r=tt(x(JSON.stringify(this.json),function(){var t,n,e,r;for(r=[],t=0,n=(e=this.tags).length;t<n;t++)i=e[t],r.push(i._pointer);return r}.call(this)))),this.initialize_pointer(null,r,j)}},ct=class extends st{constructor(n){var e;super(),this.json=n,e=tt(function(n){const e=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o,i=t.hakuban_tag_descriptor_new(e,r);return Q.__wrap(i)}(JSON.stringify(this.json))),this.initialize_pointer(null,e,m)}};it=[0,0,0];var lt,ht=class n extends st{constructor(n=null,e=null,r=null,i=0,o=null){var a,s,_;if(super(),null!=o)this.initialize_pointer(null,o,P),this.version=function(){var n,e,r,i;for(i=[],n=0,e=(r=function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_version(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=U(e,r).slice();return t.__wbindgen_free(e,8*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(o)).length;n<e;n++)_=r[n],i.push(_);return i}(),this.synchronized_us_ago=function(n){const e=t.hakuban_object_state_synchronized_ago(n);return BigInt.asUintN(64,e)}(o),this.format=L(o),this.data=(new TextDecoder).decode(function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_data(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=R(e,r).slice();return t.__wbindgen_free(e,1*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(o));else{if(null==e){for(a=(new Date).getTime(),e=[0,Math.floor(a/1e3),a%1e3*1e3];e[1]===it[1]&&e[2]<=it[2];)e[2]++;it=e}this.version=function(){var t,n,r;for(r=[],t=0,n=e.length;t<n;t++)s=e[t],r.push(BigInt(s));return r}(),null==r&&(r=[]),this.format=[r].flat(Infinity),this.synchronized_us_ago=BigInt(i),this.data=n}}with_pointer(t){var n;if(this.dropped())throw new PointerAlreadyDropped;return null!=this._pointer||(n=tt(O(this.version,this.format,(new TextEncoder).encode(this.data),this.synchronized_us_ago)),this.initialize_pointer(null,n,P)),t(this._pointer)}with_data(t){return new n(t,this.version,this.format,this.synchronized_us_ago)}with_version(t){return new n(this.data,t,this.format,this.synchronized_us_ago)}with_format(t){return new n(this.data,this.version,t,this.synchronized_us_ago)}with_synchronized_us_ago(t){return new n(this.data,this.version,this.format,t)}json_deserialize(){if("JSON"!==this.format[this.format.length-1])throw"Invalid data format";return new n(JSON.parse(this.data),this.version,this.format.slice(0,-1),this.synchronized_us_ago)}json_serialize(){return new n(JSON.stringify(this.data),this.version,this.format.concat("JSON"),this.synchronized_us_ago)}},ut=class t{constructor(t,n=!1,e=!1){this._stream=t,this._without_implicit_drop=n,this._async=e}async(n){return new t(this._stream,this._without_implicit_drop,!0).call_or_return(n)}without_implicit_drop(n){return new t(this._stream,!0,this._async).call_or_return(n)}call_or_return(t){return null!=t?this.call(t):this}async call(t){var n,e;for(e=[];null!=(n=await this._stream.next());)if(this._async)e.push(new Promise((async e=>{var r;if(r=n,this._without_implicit_drop)return await t(r);try{return await t(r)}finally{await r.drop()}})));else if(this._without_implicit_drop)e.push(await t(n));else try{e.push(await t(n))}finally{await n.drop()}return e}},dt=class extends st{constructor(t,n){super(),this.local_exchange=t,this.initialize_pointer(this.local_exchange,n,T)}descriptor(){return this.with_pointer((function(n){return new _t(null,null,(e=n,t.hakuban_object_state_stream_descriptor(e)));var e}))}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_state_stream_next(e);var e})),null!=(i=await new et(this.local_exchange,this,N,E,r).await_and_drop())?new ht(null,null,null,null,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}each(t){return new ut(this).call_or_return(t)}current(n){var e,r;try{return null!=(r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_state_stream_current(n);return Q.__wrap(e)}(n)))))?new ht(null,null,null,null,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},wt=class extends st{constructor(t){super(),this.initialize_pointer(null,t,$)}},ft=class extends st{constructor(t,n){super(),this.local_exchange=t,this.initialize_pointer(this.local_exchange,n,F)}descriptor(){return this.with_pointer((function(n){return new _t(null,null,(e=n,t.hakuban_object_state_sink_descriptor(e)));var e}))}async send(n){var e,r;try{return r=this.with_pointer((e=>n.with_pointer((n=>function(n,e){return t.hakuban_object_state_sink_push(n,e)}(e,n))))),await new et(this.local_exchange,this,J,W,r).await_and_drop(),this.local_exchange.notify(),!0}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_state_sink_next(e);var e})),null!=(i=await new et(this.local_exchange,this,N,E,r).await_and_drop())?new wt(i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}each(t){return new ut(this).call_or_return(t)}current(n){var e,r;try{return null!=(r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_state_sink_current(n);return Q.__wrap(e)}(n)))))?new wt(r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}desynchronize(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_state_sink_desynchronize(e);var e})),this.local_exchange.notify(),!0}catch(t){if((n=t)instanceof PointerAlreadyDropped)return null;throw n}}};lt=class extends st{each(t){return new ut(this).call_or_return(t)}};var gt,pt,bt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e[0]instanceof _t?e[0]:new _t(...e),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_object_observe_contract_new(n,e)}(n,e),H))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_observe_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_observe_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?await new dt(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r;try{return r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_observe_contract_ready(n);return Q.__wrap(e)}(n)))),this.local_exchange.notify(),null!=r?new dt(this.local_exchange,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},yt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e[0]instanceof _t?e[0]:new _t(...e),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_object_expose_contract_new(n,e)}(n,e),M))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_expose_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_expose_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?await new ft(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r;try{return r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_expose_contract_ready(n);return Q.__wrap(e)}(n)))),this.local_exchange.notify(),null!=r?new ft(this.local_exchange,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},vt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e,this.descriptor instanceof ct||(this.descriptor=new ct(this.descriptor)),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_tag_observe_contract_new(n,e)}(n,e),k))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_tag_observe_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_tag_observe_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?new dt(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r,i;try{return i=this.with_pointer((n=>function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_observe_contract_ready(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(n))),this.local_exchange.notify(),ot(function(){var t,n,e;for(e=[],t=0,n=i.length;t<n;t++)r=i[t],e.push(new dt(this.local_exchange,r));return e}.call(this),n)}catch(t){if((e=t)instanceof at)return null;throw e}}},kt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e,this.descriptor instanceof ct||(this.descriptor=new ct(this.descriptor)),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_tag_expose_contract_new(n,e)}(n,e),p))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_tag_expose_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_tag_expose_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?new ft(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r,i;try{return i=this.with_pointer((n=>function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_expose_contract_ready(o,n);var e=u()[o/4+0],r=u()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(n))),this.local_exchange.notify(),ot(function(){var t,n,e;for(e=[],t=0,n=i.length;t<n;t++)r=i[t],e.push(new ft(this.local_exchange,r));return e}.call(this),n)}catch(t){if((e=t)instanceof at)return null;throw e}}},mt=class extends st{constructor(n="wasm"){super(),this.name=n,this._notification_sequence=BigInt(0),this._notification_resolve={},this.initialize_pointer(null,tt(function(n){const e=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o,i=t.hakuban_local_exchange_new(e,r);return Q.__wrap(i)}(this.name)),q)}object(t,n){return new gt(this,[t,n])}tag(t){return new pt(this,t)}notified(){var t,n;return t=++this._notification_sequence,(n=new Promise((n=>this._notification_resolve[t]=n))).id=t,n}notify(){var t,n,e,r,i;for(i=[],t=0,e=(r=this.with_pointer((function(t){return C(t)}))).length;t<e;t++)n=r[t],null!=this._notification_resolve[n]?(this._notification_resolve[n](!0),i.push(delete this._notification_resolve[n])):i.push(void 0);return i}return_notified(t){return delete this._notification_resolve[t.id]}};gt=class{constructor(t,n){this.local_exchange=t,this.descriptor=n}observe(t){return new bt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}expose(t){return new yt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}},pt=class{constructor(t,n){this.local_exchange=t,this.descriptor=n}observe(t){return new vt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}expose(t){return new kt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}};var xt=class extends st{constructor(n,e,r,i){super(),this.local_exchange=n,this.local_exchange.with_pointer((n=>this.initialize_pointer(this.local_exchange,function(n,e,r,i){return t.hakuban_remote_exchange_new(n,e,r,i)}(n,e,r,i),B)))}async next(){var n,e,r;try{return e=this.with_pointer((n=>{return e=n,t.hakuban_remote_exchange_next_message_to_network(e);var e})),r=await new et(this.local_exchange,this,N,E,e).await_and_drop(),this.local_exchange.notify(),r}catch(t){if((n=t)instanceof at)return null;throw n}}async send(n){var e,r;try{return r=this.with_pointer((e=>function(n,e){const r=I(e,t.__wbindgen_malloc),i=o;return t.hakuban_remote_exchange_send_message_from_network(n,r,i)}(e,new Uint8Array(n)))),await new et(this.local_exchange,this,J,W,r).await_and_drop(),this.local_exchange.notify()}catch(t){if((e=t)instanceof at)return null;throw e}}},jt=class{constructor(t,n,e={}){this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.local_exchange=t,this.uri=n,this.options=e,this._status_change({connected:!1}),this.socket=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.connect()}status(){return Promise.resolve([this.status,this.next_status_promise])}_status_change(t){var n;if(this.status=t,n=this.next_status_promise_resolve,this.next_status_promise=new Promise((t=>{this.next_status_promise_resolve=t})),null!=n)return n([this.status,this.next_status_promise])}disconnect(){if(this.reconnect_on_close=!1,null!=this.socket)return this.socket.close()}connect(){var t;null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(n){return t=n,console.error("Error connecting to hakuban remote exchange:",t),this._status_change({connected:!1,error:t}),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=()=>(this.options.debug&&console.debug("Connected to hakuban remote exchange"),this.remote_exchange=new xt(this.local_exchange,!0,!0,!0),this.forwarding_to_network_stopped=new Promise((async n=>{var e;try{for(;null!=this.remote_exchange&&null!=(e=await this.remote_exchange.next());)this.send(D(e))}catch(n){t=n,console.error("Error processing hakuban connection:",t),null!=this.socket&&this.socket.close()}return n()})),this._status_change({connected:!0})),this.socket.onclose=async t=>{if(this.options.debug&&null!=this.remote_exchange&&console.debug("Disconnected from hakuban remote exchange"),this.options.debug&&null==this.remote_exchange&&console.debug("Failed to connect to hakuban remote exchange"),this._status_change({connected:!1,disconnect_reason:t.reason,clean_disconnect:t.wasClean}),this.socket=void 0,null!=this.keep_alive_interval&&(clearInterval(this.keep_alive_interval),this.keep_alive_interval=null),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.remote_exchange&&(await this.remote_exchange.drop(),await this.forwarding_to_network_stopped,this.forwarding_to_network_stopped=null,this.remote_exchange=null),this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onmessage=async n=>{if(null!=this.remote_exchange)try{return await this.remote_exchange.send(n.data)}catch(n){if(t=n,console.error("Error processing hakuban connection:",t),null!=this.socket)return this.socket.close()}}}ping(){if(this.socket)return this.socket.send(new Uint8Array)}send(t){if(t.length>0)return this.socket.send(t),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.keep_alive_interval=setInterval(this.ping,1e4)}},At=async function(t,n){var e;return e=await X(t),rt(n),e};export{mt as LocalExchange,_t as ObjectDescriptor,yt as ObjectExposeContract,bt as ObjectObserveContract,ht as ObjectState,ct as TagDescriptor,kt as TagExposeContract,vt as TagObserveContract,jt as WebsocketConnector,At as initialize};
2
2
  //# sourceMappingURL=hakuban.min.js.map