action_merge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +157 -0
  3. data/README.md +49 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/builds/action_merge/application.d.ts +1 -0
  6. data/app/assets/builds/action_merge/application.d.ts.map +1 -0
  7. data/app/assets/builds/action_merge/application.js +6 -0
  8. data/app/assets/builds/action_merge/application.js.map +1 -0
  9. data/app/assets/builds/action_merge/automerge.wasm +0 -0
  10. data/app/assets/builds/action_merge/network-adapter.d.ts +18 -0
  11. data/app/assets/builds/action_merge/network-adapter.d.ts.map +1 -0
  12. data/app/assets/builds/action_merge/syncable.d.ts +7 -0
  13. data/app/assets/builds/action_merge/syncable.d.ts.map +1 -0
  14. data/app/assets/config/action_merge_manifest.js +1 -0
  15. data/app/assets/stylesheets/action_merge/application.css +15 -0
  16. data/app/channels/action_merge/sync_channel.rb +36 -0
  17. data/app/channels/application_cable/channel.rb +4 -0
  18. data/app/channels/application_cable/connection.rb +4 -0
  19. data/app/controllers/action_merge/application_controller.rb +4 -0
  20. data/app/helpers/action_merge/application_helper.rb +4 -0
  21. data/app/javascript/action_merge/application.ts +5 -0
  22. data/app/javascript/action_merge/network-adapter.ts +144 -0
  23. data/app/javascript/action_merge/syncable.ts +24 -0
  24. data/app/jobs/action_merge/application_job.rb +4 -0
  25. data/app/mailers/action_merge/application_mailer.rb +6 -0
  26. data/app/models/action_merge/application_record.rb +5 -0
  27. data/app/models/action_merge/document/chunk.rb +11 -0
  28. data/app/models/action_merge/document.rb +6 -0
  29. data/app/models/action_merge/peer.rb +23 -0
  30. data/app/models/action_merge/storage_adapter.rb +32 -0
  31. data/app/views/layouts/action_merge/application.html.erb +14 -0
  32. data/config/routes.rb +2 -0
  33. data/db/migrate/20240910160133_create_action_merge_documents.rb +19 -0
  34. data/lib/action_merge/assets.rb +19 -0
  35. data/lib/action_merge/engine.rb +16 -0
  36. data/lib/action_merge/helpers.rb +7 -0
  37. data/lib/action_merge/syncable.rb +19 -0
  38. data/lib/action_merge.rb +12 -0
  39. data/lib/tasks/action_merge_tasks.rake +4 -0
  40. metadata +104 -0
@@ -0,0 +1,6 @@
1
+ (async()=>{const Ft=Symbol.for("_am_meta"),de=Symbol.for("_am_trace"),fe=Symbol.for("_am_objectId"),tn=Symbol.for("_am_isProxy"),Nn=Symbol.for("_am_clearCache"),po=Symbol.for("_am_uint"),bo=Symbol.for("_am_int"),yo=Symbol.for("_am_f64"),wo=Symbol.for("_am_counter"),lc=Symbol.for("_am_text");class Ht{constructor(t){if(typeof t=="string")this.elems=[...t];else if(Array.isArray(t))this.elems=t;else if(t===void 0)this.elems=[];else throw new TypeError(`Unsupported initial value for Text: ${t}`);Reflect.defineProperty(this,lc,{value:!0})}get length(){return this.elems.length}get(t){return this.elems[t]}[Symbol.iterator](){const t=this.elems;let n=-1;return{next(){return n+=1,n<t.length?{done:!1,value:t[n]}:{done:!0}}}}toString(){if(!this.str){this.str="";for(const t of this.elems)typeof t=="string"?this.str+=t:this.str+="\uFFFC"}return this.str}toSpans(){if(!this.spans){this.spans=[];let t="";for(const n of this.elems)typeof n=="string"?t+=n:(t.length>0&&(this.spans.push(t),t=""),this.spans.push(n));t.length>0&&this.spans.push(t)}return this.spans}toJSON(){return this.toString()}set(t,n){if(this[Ft])throw new RangeError("object cannot be modified outside of a change block");this.elems[t]=n}insertAt(t,...n){if(this[Ft])throw new RangeError("object cannot be modified outside of a change block");n.every(r=>typeof r=="string")?this.elems.splice(t,0,...n.join("")):this.elems.splice(t,0,...n)}deleteAt(t,n=1){if(this[Ft])throw new RangeError("object cannot be modified outside of a change block");this.elems.splice(t,n)}map(t){this.elems.map(t)}lastIndexOf(t,n){this.elems.lastIndexOf(t,n)}concat(t){return new Ht(this.elems.concat(t.elems))}every(t){return this.elems.every(t)}filter(t){return new Ht(this.elems.filter(t))}find(t){return this.elems.find(t)}findIndex(t){return this.elems.findIndex(t)}forEach(t){this.elems.forEach(t)}includes(t){return this.elems.includes(t)}indexOf(t){return this.elems.indexOf(t)}join(t){return this.elems.join(t)}reduce(t){this.elems.reduce(t)}reduceRight(t){this.elems.reduceRight(t)}slice(t,n){return new Ht(this.elems.slice(t,n))}some(t){return this.elems.some(t)}toLocaleString(){this.toString()}}class Ee{constructor(t){this.value=t||0,Reflect.defineProperty(this,wo,{value:!0})}valueOf(){return this.value}toString(){return this.valueOf().toString()}toJSON(){return this.value}increment(t){throw new Error("Counters should not be incremented outside of a change callback")}decrement(t){throw new Error("Counters should not be decremented outside of a change callback")}}class gc extends Ee{constructor(t,n,r,o,s){super(t),this.context=n,this.path=r,this.objectId=o,this.key=s}increment(t){return t=typeof t=="number"?t:1,this.context.increment(this.objectId,this.key,t),this.value+=t,this.value}decrement(t){return this.increment(typeof t=="number"?-t:-1)}}function pc(e,t,n,r,o){return new gc(e,t,n,r,o)}class bc{constructor(t){if(!(Number.isInteger(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER))throw new RangeError(`Value ${t} cannot be a uint`);this.value=t,Reflect.defineProperty(this,bo,{value:!0}),Object.freeze(this)}}class yc{constructor(t){if(!(Number.isInteger(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=0))throw new RangeError(`Value ${t} cannot be a uint`);this.value=t,Reflect.defineProperty(this,po,{value:!0}),Object.freeze(this)}}class wc{constructor(t){if(typeof t!="number")throw new RangeError(`Value ${t} cannot be a float64`);this.value=t||0,Reflect.defineProperty(this,yo,{value:!0}),Object.freeze(this)}}class en{constructor(t){this.val=t}toString(){return this.val}toJSON(){return this.val}}function Tt(e){if(typeof e=="string"&&/^[0-9]+$/.test(e)&&(e=parseInt(e,10)),typeof e!="number")return e;if(e<0||isNaN(e)||e===1/0||e===-1/0)throw new RangeError("A list index must be positive, but you passed "+e);return e}function kt(e,t){const{context:n,objectId:r,path:o,textV2:s}=e,i=n.getWithType(r,t);if(i===null)return;const a=i[0],c=i[1];switch(a){case void 0:return;case"map":return he(n,c,s,[...o,t]);case"list":return Oe(n,c,s,[...o,t]);case"text":return s?n.text(c):je(n,c,[...o,t]);case"str":return c;case"uint":return c;case"int":return c;case"f64":return c;case"boolean":return c;case"null":return null;case"bytes":return c;case"timestamp":return c;case"counter":return pc(c,n,o,r,t);default:throw RangeError(`datatype ${a} unimplemented`)}}function nn(e,t,n,r){const o=typeof e;switch(o){case"object":if(e==null)return[null,"null"];if(e[po])return[e.value,"uint"];if(e[bo])return[e.value,"int"];if(e[yo])return[e.value,"f64"];if(e[wo])return[e.value,"counter"];if(e instanceof Date)return[e.getTime(),"timestamp"];if(e instanceof en)return[e.toString(),"str"];if(e instanceof Ht)return[e,"text"];if(e instanceof Uint8Array)return[e,"bytes"];if(e instanceof Array)return[e,"list"];if(Object.prototype.toString.call(e)==="[object Object]")return[e,"map"];throw rn(e,r)?new RangeError("Cannot create a reference to an existing document object"):new RangeError(`Cannot assign unknown object: ${e}`);case"boolean":return[e,"boolean"];case"number":return Number.isInteger(e)?[e,"int"]:[e,"f64"];case"string":return t?[e,"text"]:[e,"str"];case"undefined":throw new RangeError([`Cannot assign undefined value at ${vo(n)}, `,"because `undefined` is not a valid JSON data type. ","You might consider setting the property's value to `null`, ","or using `delete` to remove it altogether."].join(""));default:throw new RangeError([`Cannot assign ${o} value at ${vo(n)}. `,"All JSON primitive datatypes (object, array, string, number, boolean, null) ",`are supported in an Automerge document; ${o} values are not. `].join(""))}}function rn(e,t){var n,r;return e instanceof Date?!1:!!(e&&((r=(n=e[Ft])===null||n===void 0?void 0:n.handle)===null||r===void 0?void 0:r.__wbg_ptr)===t.__wbg_ptr)}const mc={get(e,t){const{context:n,objectId:r,cache:o}=e;return t===Symbol.toStringTag?e[Symbol.toStringTag]:t===fe?r:t===tn?!0:t===de?e.trace:t===Ft?{handle:n,textV2:e.textV2}:(o[t]||(o[t]=kt(e,t)),o[t])},set(e,t,n){const{context:r,objectId:o,path:s,textV2:i}=e;if(e.cache={},rn(n,r))throw new RangeError("Cannot create a reference to an existing document object");if(t===de)return e.trace=n,!0;if(t===Nn)return!0;const[a,c]=nn(n,i,[...s,t],r);switch(c){case"list":{const _=r.putObject(o,t,[]),u=Oe(r,_,i,[...s,t]);for(let d=0;d<a.length;d++)u[d]=a[d];break}case"text":{if(i)on(a),r.putObject(o,t,a);else{Jn(a);const _=r.putObject(o,t,"");je(r,_,[...s,t]).splice(0,0,...a)}break}case"map":{const _=r.putObject(o,t,{}),u=he(r,_,i,[...s,t]);for(const d in a)u[d]=a[d];break}default:r.put(o,t,a,c)}return!0},deleteProperty(e,t){const{context:n,objectId:r}=e;return e.cache={},n.delete(r,t),!0},has(e,t){return this.get(e,t)!==void 0},getOwnPropertyDescriptor(e,t){const n=this.get(e,t);if(typeof n<"u")return{configurable:!0,enumerable:!0,value:n}},ownKeys(e){const{context:t,objectId:n}=e,r=t.keys(n);return[...new Set(r)]}},mo={get(e,t){const{context:n,objectId:r}=e;return t=Tt(t),t===Symbol.hasInstance?o=>Array.isArray(o):t===Symbol.toStringTag?e[Symbol.toStringTag]:t===fe?r:t===tn?!0:t===de?e.trace:t===Ft?{handle:n}:t==="length"?n.length(r):typeof t=="number"?kt(e,t):Vn(e)[t]},set(e,t,n){const{context:r,objectId:o,path:s,textV2:i}=e;if(t=Tt(t),rn(n,r))throw new RangeError("Cannot create a reference to an existing document object");if(t===Nn)return!0;if(t===de)return e.trace=n,!0;if(typeof t=="string")throw new RangeError("list index must be a number");const[a,c]=nn(n,i,[...s,t],r);switch(c){case"list":{let _;t>=r.length(o)?_=r.insertObject(o,t,[]):_=r.putObject(o,t,[]),Oe(r,_,i,[...s,t]).splice(0,0,...a);break}case"text":{if(i)on(a),t>=r.length(o)?r.insertObject(o,t,a):r.putObject(o,t,a);else{let _;Jn(a),t>=r.length(o)?_=r.insertObject(o,t,""):_=r.putObject(o,t,""),je(r,_,[...s,t]).splice(0,0,...a)}break}case"map":{let _;t>=r.length(o)?_=r.insertObject(o,t,{}):_=r.putObject(o,t,{});const u=he(r,_,i,[...s,t]);for(const d in a)u[d]=a[d];break}default:t>=r.length(o)?r.insert(o,t,a,c):r.put(o,t,a,c)}return!0},deleteProperty(e,t){const{context:n,objectId:r}=e;t=Tt(t);const o=n.get(r,t);if(o!=null&&o[0]=="counter")throw new TypeError("Unsupported operation: deleting a counter from a list");return n.delete(r,t),!0},has(e,t){const{context:n,objectId:r}=e;return t=Tt(t),typeof t=="number"?t<n.length(r):t==="length"},getOwnPropertyDescriptor(e,t){const{context:n,objectId:r}=e;return t==="length"?{writable:!0,value:n.length(r)}:t===fe?{configurable:!1,enumerable:!1,value:r}:(t=Tt(t),{configurable:!0,enumerable:!0,value:kt(e,t)})},getPrototypeOf(e){return Object.getPrototypeOf(e)},ownKeys(){const e=[];return e.push("length"),e}},vc=Object.assign({},mo,{get(e,t){const{context:n,objectId:r}=e;return t=Tt(t),t===Symbol.hasInstance?o=>Array.isArray(o):t===Symbol.toStringTag?e[Symbol.toStringTag]:t===fe?r:t===tn?!0:t===de?e.trace:t===Ft?{handle:n}:t==="length"?n.length(r):typeof t=="number"?kt(e,t):kc(e)[t]||Vn(e)[t]},getPrototypeOf(){return Object.getPrototypeOf(new Ht)}});function he(e,t,n,r){const o={context:e,objectId:t,path:r||[],cache:{},textV2:n},s={};return Object.assign(s,o),new Proxy(s,mc)}function Oe(e,t,n,r){const o={context:e,objectId:t,path:r||[],cache:{},textV2:n},s=[];return Object.assign(s,o),new Proxy(s,mo)}function je(e,t,n){const r={context:e,objectId:t,path:n||[],cache:{},textV2:!1},o={};return Object.assign(o,r),new Proxy(o,vc)}function Sc(e,t){return he(e,"_root",t,[])}function Vn(e){const{context:t,objectId:n,path:r,textV2:o}=e;return{deleteAt(s,i){return typeof i=="number"?t.splice(n,s,i):t.delete(n,s),this},fill(s,i,a){const[c,_]=nn(s,o,[...r,i],t),u=t.length(n);i=Tt(i||0),a=Tt(a||u);for(let d=i;d<Math.min(a,u);d++)if(_==="list"||_==="map")t.putObject(n,d,c);else if(_==="text")if(o)on(c),t.putObject(n,d,c);else{Jn(c);const g=t.putObject(n,d,""),l=je(t,g,[...r,d]);for(let v=0;v<c.length;v++)l[v]=c.get(v)}else t.put(n,d,c,_);return this},indexOf(s,i=0){const a=t.length(n);for(let c=i;c<a;c++){const _=t.getWithType(n,c);if(_&&(_[1]===s[fe]||_[1]===s))return c}return-1},insertAt(s,...i){return this.splice(s,0,...i),this},pop(){const s=t.length(n);if(s==0)return;const i=kt(e,s-1);return t.delete(n,s-1),i},push(...s){const i=t.length(n);return this.splice(i,0,...s),t.length(n)},shift(){if(t.length(n)==0)return;const s=kt(e,0);return t.delete(n,0),s},splice(s,i,...a){s=Tt(s),typeof i!="number"&&(i=t.length(n)-s),i=Tt(i);for(const u of a)if(rn(u,t))throw new RangeError("Cannot create a reference to an existing document object");const c=[];for(let u=0;u<i;u++){const d=kt(e,s);d!==void 0&&c.push(d),t.delete(n,s)}const _=a.map((u,d)=>{try{return nn(u,o,[...r],t)}catch(g){throw g instanceof RangeError?new RangeError(`${g.message} (at index ${d} in the input)`):g}});for(const[u,d]of _){switch(d){case"list":{const g=t.insertObject(n,s,[]);Oe(t,g,o,[...r,s]).splice(0,0,...u);break}case"text":{if(o)on(u),t.insertObject(n,s,u);else{const g=t.insertObject(n,s,"");je(t,g,[...r,s]).splice(0,0,...u)}break}case"map":{const g=t.insertObject(n,s,{}),l=he(t,g,o,[...r,s]);for(const v in u)l[v]=u[v];break}default:t.insert(n,s,u,d)}s+=1}return c},unshift(...s){return this.splice(0,0,...s),t.length(n)},entries(){let s=0;return{next:()=>{const i=kt(e,s);return i===void 0?{value:void 0,done:!0}:{value:[s++,i],done:!1}},[Symbol.iterator](){return this}}},keys(){let s=0;const i=t.length(n);return{next:()=>s<i?{value:s++,done:!1}:{value:void 0,done:!0},[Symbol.iterator](){return this}}},values(){let s=0;return{next:()=>{const i=kt(e,s++);return i===void 0?{value:void 0,done:!0}:{value:i,done:!1}},[Symbol.iterator](){return this}}},toArray(){const s=[];let i;do i=kt(e,s.length),i!==void 0&&s.push(i);while(i!==void 0);return s},map(s){return this.toArray().map(s)},toString(){return this.toArray().toString()},toLocaleString(){return this.toArray().toLocaleString()},forEach(s){return this.toArray().forEach(s)},concat(s){return this.toArray().concat(s)},every(s){return this.toArray().every(s)},filter(s){return this.toArray().filter(s)},find(s){let i=0;for(const a of this){if(s(a,i))return a;i+=1}},findIndex(s){let i=0;for(const a of this){if(s(a,i))return i;i+=1}return-1},includes(s){return this.find(i=>i===s)!==void 0},join(s){return this.toArray().join(s)},reduce(s,i){return this.toArray().reduce(s,i)},reduceRight(s,i){return this.toArray().reduceRight(s,i)},lastIndexOf(s,i=1/0){return this.toArray().lastIndexOf(s,i)},slice(s,i){return this.toArray().slice(s,i)},some(s){let i=0;for(const a of this){if(s(a,i))return!0;i+=1}return!1},[Symbol.iterator]:function*(){let s=0,i=kt(e,s);for(;i!==void 0;)yield i,s+=1,i=kt(e,s)}}}function kc(e){const{context:t,objectId:n}=e;return{set(r,o){return this[r]=o},get(r){return this[r]},toString(){return t.text(n).replace(//g,"")},toSpans(){const r=[];let o="";const s=t.length(n);for(let i=0;i<s;i++){const a=this[i];typeof a=="string"?o+=a:(o.length>0&&(r.push(o),o=""),r.push(a))}return o.length>0&&r.push(o),r},toJSON(){return this.toString()},indexOf(r,o=0){return t.text(n).indexOf(r,o)},insertAt(r,...o){o.every(s=>typeof s=="string")?t.splice(n,r,0,o.join("")):Vn(e).insertAt(r,...o)}}}function Jn(e){if(!(e instanceof Ht))throw new Error("value was not a Text instance")}function on(e){if(typeof e!="string")throw new Error("value was not a string")}function vo(e){const t=e.map(n=>{if(typeof n=="number")return n.toString();if(typeof n=="string")return n.replace(/~/g,"~0").replace(/\//g,"~1")});return e.length===0?"":"/"+t.join("/")}function xc(e,t,n){return Ac(e,t,n,!0,(r,o)=>r.text(o))}function Ac(e,t,n,r,o){const s=e.getAll(t,n);if(s.length<=1)return;const i={};for(const a of s)switch(a[0]){case"map":i[a[1]]=he(e,a[1],r,[n]);break;case"list":i[a[1]]=Oe(e,a[1],r,[n]);break;case"text":i[a[1]]=o(e,a[1]);break;case"str":case"uint":case"int":case"f64":case"boolean":case"bytes":case"null":i[a[2]]=a[1];break;case"counter":i[a[2]]=new Ee(a[1]);break;case"timestamp":i[a[2]]=new Date(a[1]);break;default:throw RangeError(`datatype ${a[0]} unimplemented`)}return i}let sn;const Ic=new Uint8Array(16);function Cc(){if(!sn&&(sn=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!sn))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return sn(Ic)}const Ec=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function an(e){return typeof e=="string"&&Ec.test(e)}const ft=[];for(let e=0;e<256;++e)ft.push((e+256).toString(16).slice(1));function So(e,t=0){return ft[e[t+0]]+ft[e[t+1]]+ft[e[t+2]]+ft[e[t+3]]+"-"+ft[e[t+4]]+ft[e[t+5]]+"-"+ft[e[t+6]]+ft[e[t+7]]+"-"+ft[e[t+8]]+ft[e[t+9]]+"-"+ft[e[t+10]]+ft[e[t+11]]+ft[e[t+12]]+ft[e[t+13]]+ft[e[t+14]]+ft[e[t+15]]}function Oc(e,t=0){const n=So(e,t);if(!an(n))throw TypeError("Stringified UUID is invalid");return n}function jc(e){if(!an(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=t&255,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=t&255,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=t&255,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=t&255,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=t&255,n}const Rc=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ko={randomUUID:Rc};function xo(e,t,n){if(ko.randomUUID&&!t&&!e)return ko.randomUUID();e=e||{};const r=e.random||(e.rng||Cc)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n=n||0;for(let o=0;o<16;++o)t[n+o]=r[o];return t}return So(r)}let f;const Lt=new Array(128).fill(void 0);Lt.push(void 0,null,!0,!1);function $(e){return Lt[e]}let Re=Lt.length;function Tc(e){e<132||(Lt[e]=Re,Re=e)}function C(e){const t=$(e);return Tc(e),t}let xt=0,Te=null;function cn(){return(Te===null||Te.byteLength===0)&&(Te=new Uint8Array(f.memory.buffer)),Te}const un=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},Uc=typeof un.encodeInto=="function"?function(e,t){return un.encodeInto(e,t)}:function(e,t){const n=un.encode(e);return t.set(n),{read:e.length,written:n.length}};function Ut(e,t,n){if(n===void 0){const a=un.encode(e),c=t(a.length,1)>>>0;return cn().subarray(c,c+a.length).set(a),xt=a.length,c}let r=e.length,o=t(r,1)>>>0;const s=cn();let i=0;for(;i<r;i++){const a=e.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(e=e.slice(i)),o=n(o,r,r=i+e.length*3,1)>>>0;const a=cn().subarray(o+i,o+r),c=Uc(e,a);i+=c.written,o=n(o,r,i,1)>>>0}return xt=i,o}function tt(e){return e==null}let Ue=null;function y(){return(Ue===null||Ue.byteLength===0)&&(Ue=new Int32Array(f.memory.buffer)),Ue}const Ao=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&Ao.decode();function mt(e,t){return e=e>>>0,Ao.decode(cn().subarray(e,e+t))}function S(e){Re===Lt.length&&Lt.push(Lt.length+1);const t=Re;return Re=Lt[t],Lt[t]=e,t}let $e=null;function _n(){return($e===null||$e.byteLength===0)&&($e=new Float64Array(f.memory.buffer)),$e}function Kn(e){const t=typeof e;if(t=="number"||t=="boolean"||e==null)return`${e}`;if(t=="string")return`"${e}"`;if(t=="symbol"){const o=e.description;return o==null?"Symbol":`Symbol(${o})`}if(t=="function"){const o=e.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(e)){const o=e.length;let s="[";o>0&&(s+=Kn(e[0]));for(let i=1;i<o;i++)s+=", "+Kn(e[i]);return s+="]",s}const n=/\[object ([^\]]+)\]/.exec(toString.call(e));let r;if(n.length>1)r=n[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}
2
+ ${e.stack}`:r}function Qt(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function $c(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.create(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return Wn.__wrap(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Pc(e,t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.load(s,S(e),S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return Wn.__wrap(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Dc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.encodeChange(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Mc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.decodeChange(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Bc(){const e=f.initSyncState();return zt.__wrap(e)}function Fc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.importSyncState(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return zt.__wrap(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Hc(e){Qt(e,zt);const t=f.exportSyncState(e.__wbg_ptr);return C(t)}function Lc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.encodeSyncMessage(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function zc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.decodeSyncMessage(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function Nc(e){Qt(e,zt);const t=f.encodeSyncState(e.__wbg_ptr);return C(t)}function Vc(e){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.decodeSyncState(o,S(e));var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return zt.__wrap(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}function lt(e,t){try{return e.apply(this,t)}catch(n){f.__wbindgen_exn_store(S(n))}}const Jc=Object.freeze({Array:0,0:"Array",String:1,1:"String"}),Io=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>f.__wbg_automerge_free(e>>>0));let Wn=class _e{static __wrap(t){t=t>>>0;const n=Object.create(_e.prototype);return n.__wbg_ptr=t,Io.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Io.unregister(this),t}free(){const t=this.__destroy_into_raw();f.__wbg_automerge_free(t)}static new(t,n){try{const c=f.__wbindgen_add_to_stack_pointer(-16);var r=tt(t)?0:Ut(t,f.__wbindgen_malloc,f.__wbindgen_realloc),o=xt;f.automerge_new(c,r,o,n);var s=y()[c/4+0],i=y()[c/4+1],a=y()[c/4+2];if(a)throw C(i);return _e.__wrap(s)}finally{f.__wbindgen_add_to_stack_pointer(16)}}clone(t){try{const a=f.__wbindgen_add_to_stack_pointer(-16);var n=tt(t)?0:Ut(t,f.__wbindgen_malloc,f.__wbindgen_realloc),r=xt;f.automerge_clone(a,this.__wbg_ptr,n,r);var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return _e.__wrap(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}fork(t,n){try{const c=f.__wbindgen_add_to_stack_pointer(-16);var r=tt(t)?0:Ut(t,f.__wbindgen_malloc,f.__wbindgen_realloc),o=xt;f.automerge_fork(c,this.__wbg_ptr,r,o,S(n));var s=y()[c/4+0],i=y()[c/4+1],a=y()[c/4+2];if(a)throw C(i);return _e.__wrap(s)}finally{f.__wbindgen_add_to_stack_pointer(16)}}pendingOps(){const t=f.automerge_pendingOps(this.__wbg_ptr);return C(t)}commit(t,n){var r=tt(t)?0:Ut(t,f.__wbindgen_malloc,f.__wbindgen_realloc),o=xt;const s=f.automerge_commit(this.__wbg_ptr,r,o,!tt(n),tt(n)?0:n);return C(s)}merge(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);Qt(t,_e),f.automerge_merge(s,this.__wbg_ptr,t.__wbg_ptr);var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}rollback(){return f.automerge_rollback(this.__wbg_ptr)}keys(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_keys(i,this.__wbg_ptr,S(t),tt(n)?0:S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}text(t,n){let r,o;try{const d=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_text(d,this.__wbg_ptr,S(t),tt(n)?0:S(n));var s=y()[d/4+0],i=y()[d/4+1],a=y()[d/4+2],c=y()[d/4+3],_=s,u=i;if(c)throw _=0,u=0,C(a);return r=_,o=u,mt(_,u)}finally{f.__wbindgen_add_to_stack_pointer(16),f.__wbindgen_free(r,o,1)}}spans(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_spans(i,this.__wbg_ptr,S(t),tt(n)?0:S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}splice(t,n,r,o){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_splice(a,this.__wbg_ptr,S(t),n,r,S(o));var s=y()[a/4+0],i=y()[a/4+1];if(i)throw C(s)}finally{f.__wbindgen_add_to_stack_pointer(16)}}updateText(t,n){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_updateText(s,this.__wbg_ptr,S(t),S(n));var r=y()[s/4+0],o=y()[s/4+1];if(o)throw C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}updateSpans(t,n){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_updateSpans(s,this.__wbg_ptr,S(t),S(n));var r=y()[s/4+0],o=y()[s/4+1];if(o)throw C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}push(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_push(i,this.__wbg_ptr,S(t),S(n),S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}pushObject(t,n){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_pushObject(a,this.__wbg_ptr,S(t),S(n));var r=y()[a/4+0],o=y()[a/4+1],s=y()[a/4+2],i=y()[a/4+3];if(i)throw C(s);let c;return r!==0&&(c=mt(r,o).slice(),f.__wbindgen_free(r,o*1,1)),c}finally{f.__wbindgen_add_to_stack_pointer(16)}}insert(t,n,r,o){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_insert(a,this.__wbg_ptr,S(t),n,S(r),S(o));var s=y()[a/4+0],i=y()[a/4+1];if(i)throw C(s)}finally{f.__wbindgen_add_to_stack_pointer(16)}}splitBlock(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_splitBlock(i,this.__wbg_ptr,S(t),n,S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}joinBlock(t,n){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_joinBlock(s,this.__wbg_ptr,S(t),n);var r=y()[s/4+0],o=y()[s/4+1];if(o)throw C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}updateBlock(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_updateBlock(i,this.__wbg_ptr,S(t),n,S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getBlock(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getBlock(a,this.__wbg_ptr,S(t),n,tt(r)?0:S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}insertObject(t,n,r){try{const c=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_insertObject(c,this.__wbg_ptr,S(t),n,S(r));var o=y()[c/4+0],s=y()[c/4+1],i=y()[c/4+2],a=y()[c/4+3];if(a)throw C(i);let _;return o!==0&&(_=mt(o,s).slice(),f.__wbindgen_free(o,s*1,1)),_}finally{f.__wbindgen_add_to_stack_pointer(16)}}put(t,n,r,o){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_put(a,this.__wbg_ptr,S(t),S(n),S(r),S(o));var s=y()[a/4+0],i=y()[a/4+1];if(i)throw C(s)}finally{f.__wbindgen_add_to_stack_pointer(16)}}putObject(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_putObject(a,this.__wbg_ptr,S(t),S(n),S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}increment(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_increment(i,this.__wbg_ptr,S(t),S(n),S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}get(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_get(a,this.__wbg_ptr,S(t),S(n),tt(r)?0:S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getWithType(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getWithType(a,this.__wbg_ptr,S(t),S(n),tt(r)?0:S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}objInfo(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_objInfo(i,this.__wbg_ptr,S(t),tt(n)?0:S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getAll(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getAll(a,this.__wbg_ptr,S(t),S(n),tt(r)?0:S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}enableFreeze(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_enableFreeze(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}registerDatatype(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_registerDatatype(i,this.__wbg_ptr,S(t),S(n),S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}applyPatches(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_applyPatches(i,this.__wbg_ptr,S(t),S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}applyAndReturnPatches(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_applyAndReturnPatches(i,this.__wbg_ptr,S(t),S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}diffIncremental(){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_diffIncremental(o,this.__wbg_ptr);var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}updateDiffCursor(){f.automerge_updateDiffCursor(this.__wbg_ptr)}resetDiffCursor(){f.automerge_resetDiffCursor(this.__wbg_ptr)}diff(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_diff(i,this.__wbg_ptr,S(t),S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}isolate(t){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_isolate(o,this.__wbg_ptr,S(t));var n=y()[o/4+0],r=y()[o/4+1];if(r)throw C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}integrate(){f.automerge_integrate(this.__wbg_ptr)}length(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_length(i,this.__wbg_ptr,S(t),tt(n)?0:S(n));var r=_n()[i/8+0],o=y()[i/4+2],s=y()[i/4+3];if(s)throw C(o);return r}finally{f.__wbindgen_add_to_stack_pointer(16)}}delete(t,n){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_delete(s,this.__wbg_ptr,S(t),S(n));var r=y()[s/4+0],o=y()[s/4+1];if(o)throw C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}save(){const t=f.automerge_save(this.__wbg_ptr);return C(t)}saveIncremental(){const t=f.automerge_saveIncremental(this.__wbg_ptr);return C(t)}saveSince(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_saveSince(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}saveNoCompress(){const t=f.automerge_saveNoCompress(this.__wbg_ptr);return C(t)}saveAndVerify(){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_saveAndVerify(o,this.__wbg_ptr);var t=y()[o/4+0],n=y()[o/4+1],r=y()[o/4+2];if(r)throw C(n);return C(t)}finally{f.__wbindgen_add_to_stack_pointer(16)}}loadIncremental(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_loadIncremental(s,this.__wbg_ptr,S(t));var n=_n()[s/8+0],r=y()[s/4+2],o=y()[s/4+3];if(o)throw C(r);return n}finally{f.__wbindgen_add_to_stack_pointer(16)}}applyChanges(t){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_applyChanges(o,this.__wbg_ptr,S(t));var n=y()[o/4+0],r=y()[o/4+1];if(r)throw C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getChanges(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getChanges(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getChangeByHash(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getChangeByHash(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getDecodedChangeByHash(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getDecodedChangeByHash(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getChangesAdded(t){Qt(t,_e);const n=f.automerge_getChangesAdded(this.__wbg_ptr,t.__wbg_ptr);return C(n)}getHeads(){const t=f.automerge_getHeads(this.__wbg_ptr);return C(t)}getActorId(){let t,n;try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getActorId(s,this.__wbg_ptr);var r=y()[s/4+0],o=y()[s/4+1];return t=r,n=o,mt(r,o)}finally{f.__wbindgen_add_to_stack_pointer(16),f.__wbindgen_free(t,n,1)}}getLastLocalChange(){const t=f.automerge_getLastLocalChange(this.__wbg_ptr);return C(t)}dump(){f.automerge_dump(this.__wbg_ptr)}getMissingDeps(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getMissingDeps(s,this.__wbg_ptr,tt(t)?0:S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}receiveSyncMessage(t,n){try{const s=f.__wbindgen_add_to_stack_pointer(-16);Qt(t,zt),f.automerge_receiveSyncMessage(s,this.__wbg_ptr,t.__wbg_ptr,S(n));var r=y()[s/4+0],o=y()[s/4+1];if(o)throw C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}generateSyncMessage(t){Qt(t,zt);const n=f.automerge_generateSyncMessage(this.__wbg_ptr,t.__wbg_ptr);return C(n)}toJS(t){try{const s=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_toJS(s,this.__wbg_ptr,S(t));var n=y()[s/4+0],r=y()[s/4+1],o=y()[s/4+2];if(o)throw C(r);return C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}materialize(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_materialize(a,this.__wbg_ptr,S(t),tt(n)?0:S(n),S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}getCursor(t,n,r){let o,s;try{const g=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getCursor(g,this.__wbg_ptr,S(t),n,tt(r)?0:S(r));var i=y()[g/4+0],a=y()[g/4+1],c=y()[g/4+2],_=y()[g/4+3],u=i,d=a;if(_)throw u=0,d=0,C(c);return o=u,s=d,mt(u,d)}finally{f.__wbindgen_add_to_stack_pointer(16),f.__wbindgen_free(o,s,1)}}getCursorPosition(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_getCursorPosition(a,this.__wbg_ptr,S(t),S(n),tt(r)?0:S(r));var o=_n()[a/8+0],s=y()[a/4+2],i=y()[a/4+3];if(i)throw C(s);return o}finally{f.__wbindgen_add_to_stack_pointer(16)}}emptyChange(t,n){var r=tt(t)?0:Ut(t,f.__wbindgen_malloc,f.__wbindgen_realloc),o=xt;const s=f.automerge_emptyChange(this.__wbg_ptr,r,o,!tt(n),tt(n)?0:n);return C(s)}mark(t,n,r,o,s){try{const c=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_mark(c,this.__wbg_ptr,S(t),S(n),S(r),S(o),S(s));var i=y()[c/4+0],a=y()[c/4+1];if(a)throw C(i)}finally{f.__wbindgen_add_to_stack_pointer(16)}}unmark(t,n,r){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_unmark(i,this.__wbg_ptr,S(t),S(n),S(r));var o=y()[i/4+0],s=y()[i/4+1];if(s)throw C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}marks(t,n){try{const i=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_marks(i,this.__wbg_ptr,S(t),tt(n)?0:S(n));var r=y()[i/4+0],o=y()[i/4+1],s=y()[i/4+2];if(s)throw C(o);return C(r)}finally{f.__wbindgen_add_to_stack_pointer(16)}}marksAt(t,n,r){try{const a=f.__wbindgen_add_to_stack_pointer(-16);f.automerge_marksAt(a,this.__wbg_ptr,S(t),n,tt(r)?0:S(r));var o=y()[a/4+0],s=y()[a/4+1],i=y()[a/4+2];if(i)throw C(s);return C(o)}finally{f.__wbindgen_add_to_stack_pointer(16)}}hasOurChanges(t){Qt(t,zt);const n=f.automerge_hasOurChanges(this.__wbg_ptr,t.__wbg_ptr);return C(n)}topoHistoryTraversal(){const t=f.automerge_topoHistoryTraversal(this.__wbg_ptr);return C(t)}stats(){const t=f.automerge_stats(this.__wbg_ptr);return C(t)}};const Co=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>f.__wbg_syncstate_free(e>>>0));let zt=class go{static __wrap(t){t=t>>>0;const n=Object.create(go.prototype);return n.__wbg_ptr=t,Co.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Co.unregister(this),t}free(){const t=this.__destroy_into_raw();f.__wbg_syncstate_free(t)}get sharedHeads(){const t=f.syncstate_sharedHeads(this.__wbg_ptr);return C(t)}get lastSentHeads(){const t=f.syncstate_lastSentHeads(this.__wbg_ptr);return C(t)}set lastSentHeads(t){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.syncstate_set_lastSentHeads(o,this.__wbg_ptr,S(t));var n=y()[o/4+0],r=y()[o/4+1];if(r)throw C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}set sentHashes(t){try{const o=f.__wbindgen_add_to_stack_pointer(-16);f.syncstate_set_sentHashes(o,this.__wbg_ptr,S(t));var n=y()[o/4+0],r=y()[o/4+1];if(r)throw C(n)}finally{f.__wbindgen_add_to_stack_pointer(16)}}clone(){const t=f.syncstate_clone(this.__wbg_ptr);return go.__wrap(t)}};async function Kc(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(r){if(e.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",r);else throw r}const n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{const n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}}function Eo(){const e={};return e.wbg={},e.wbg.__wbindgen_object_drop_ref=function(t){C(t)},e.wbg.__wbindgen_string_get=function(t,n){const r=$(n),o=typeof r=="string"?r:void 0;var s=tt(o)?0:Ut(o,f.__wbindgen_malloc,f.__wbindgen_realloc),i=xt;y()[t/4+1]=i,y()[t/4+0]=s},e.wbg.__wbindgen_error_new=function(t,n){const r=new Error(mt(t,n));return S(r)},e.wbg.__wbindgen_string_new=function(t,n){const r=mt(t,n);return S(r)},e.wbg.__wbindgen_number_new=function(t){return S(t)},e.wbg.__wbindgen_object_clone_ref=function(t){const n=$(t);return S(n)},e.wbg.__wbindgen_number_get=function(t,n){const r=$(n),o=typeof r=="number"?r:void 0;_n()[t/8+1]=tt(o)?0:o,y()[t/4+0]=!tt(o)},e.wbg.__wbindgen_is_undefined=function(t){return $(t)===void 0},e.wbg.__wbindgen_boolean_get=function(t){const n=$(t);return typeof n=="boolean"?n?1:0:2},e.wbg.__wbindgen_is_null=function(t){return $(t)===null},e.wbg.__wbindgen_is_string=function(t){return typeof $(t)=="string"},e.wbg.__wbindgen_is_function=function(t){return typeof $(t)=="function"},e.wbg.__wbindgen_is_object=function(t){const n=$(t);return typeof n=="object"&&n!==null},e.wbg.__wbindgen_is_array=function(t){return Array.isArray($(t))},e.wbg.__wbindgen_json_serialize=function(t,n){const r=$(n),o=JSON.stringify(r===void 0?null:r),s=Ut(o,f.__wbindgen_malloc,f.__wbindgen_realloc),i=xt;y()[t/4+1]=i,y()[t/4+0]=s},e.wbg.__wbg_new_abda76e883ba8a5f=function(){const t=new Error;return S(t)},e.wbg.__wbg_stack_658279fe44541cf6=function(t,n){const r=$(n).stack,o=Ut(r,f.__wbindgen_malloc,f.__wbindgen_realloc),s=xt;y()[t/4+1]=s,y()[t/4+0]=o},e.wbg.__wbg_error_f851667af71bcfc6=function(t,n){let r,o;try{r=t,o=n,console.error(mt(t,n))}finally{f.__wbindgen_free(r,o,1)}},e.wbg.__wbindgen_jsval_loose_eq=function(t,n){return $(t)==$(n)},e.wbg.__wbg_String_91fba7ded13ba54c=function(t,n){const r=String($(n)),o=Ut(r,f.__wbindgen_malloc,f.__wbindgen_realloc),s=xt;y()[t/4+1]=s,y()[t/4+0]=o},e.wbg.__wbindgen_bigint_from_i64=function(t){return S(t)},e.wbg.__wbindgen_bigint_from_u64=function(t){const n=BigInt.asUintN(64,t);return S(n)},e.wbg.__wbg_set_20cbc34131e76824=function(t,n,r){$(t)[C(n)]=C(r)},e.wbg.__wbg_getRandomValues_3aa56aa6edec874c=function(){return lt(function(t,n){$(t).getRandomValues($(n))},arguments)},e.wbg.__wbg_randomFillSync_5c9c955aa56b6049=function(){return lt(function(t,n){$(t).randomFillSync(C(n))},arguments)},e.wbg.__wbg_crypto_1d1f22824a6a080c=function(t){const n=$(t).crypto;return S(n)},e.wbg.__wbg_process_4a72847cc503995b=function(t){const n=$(t).process;return S(n)},e.wbg.__wbg_versions_f686565e586dd935=function(t){const n=$(t).versions;return S(n)},e.wbg.__wbg_node_104a2ff8d6ea03a2=function(t){const n=$(t).node;return S(n)},e.wbg.__wbg_require_cca90b1a94a0255b=function(){return lt(function(){const t=module.require;return S(t)},arguments)},e.wbg.__wbg_msCrypto_eb05e62b530a1508=function(t){const n=$(t).msCrypto;return S(n)},e.wbg.__wbg_log_5bb5f88f245d7762=function(t){console.log($(t))},e.wbg.__wbg_log_1746d5c75ec89963=function(t,n){console.log($(t),$(n))},e.wbg.__wbg_get_bd8e338fbd5f5cc8=function(t,n){const r=$(t)[n>>>0];return S(r)},e.wbg.__wbg_length_cd7af8117672b8b8=function(t){return $(t).length},e.wbg.__wbg_new_16b304a2cfa7ff4a=function(){const t=new Array;return S(t)},e.wbg.__wbg_newnoargs_e258087cd0daa0ea=function(t,n){const r=new Function(mt(t,n));return S(r)},e.wbg.__wbg_next_40fc327bfc8770e6=function(t){const n=$(t).next;return S(n)},e.wbg.__wbg_next_196c84450b364254=function(){return lt(function(t){const n=$(t).next();return S(n)},arguments)},e.wbg.__wbg_done_298b57d23c0fc80c=function(t){return $(t).done},e.wbg.__wbg_value_d93c65011f51a456=function(t){const n=$(t).value;return S(n)},e.wbg.__wbg_iterator_2cee6dadfd956dfa=function(){return S(Symbol.iterator)},e.wbg.__wbg_get_e3c254076557e348=function(){return lt(function(t,n){const r=Reflect.get($(t),$(n));return S(r)},arguments)},e.wbg.__wbg_call_27c0f87801dedf93=function(){return lt(function(t,n){const r=$(t).call($(n));return S(r)},arguments)},e.wbg.__wbg_new_72fb9a18b5ae2624=function(){const t=new Object;return S(t)},e.wbg.__wbg_length_dee433d4c85c9387=function(t){return $(t).length},e.wbg.__wbg_set_d4638f722068f043=function(t,n,r){$(t)[n>>>0]=C(r)},e.wbg.__wbg_from_89e3fc3ba5e6fb48=function(t){const n=Array.from($(t));return S(n)},e.wbg.__wbg_isArray_2ab64d95e09ea0ae=function(t){return Array.isArray($(t))},e.wbg.__wbg_push_a5b05aedc7234f9f=function(t,n){return $(t).push($(n))},e.wbg.__wbg_unshift_e22df4b34bcf5070=function(t,n){return $(t).unshift($(n))},e.wbg.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2=function(t){let n;try{n=$(t)instanceof ArrayBuffer}catch{n=!1}return n},e.wbg.__wbg_new_28c511d9baebfa89=function(t,n){const r=new Error(mt(t,n));return S(r)},e.wbg.__wbg_call_b3ca7c6051f9bec1=function(){return lt(function(t,n,r){const o=$(t).call($(n),$(r));return S(o)},arguments)},e.wbg.__wbg_instanceof_Date_f65cf97fb83fc369=function(t){let n;try{n=$(t)instanceof Date}catch{n=!1}return n},e.wbg.__wbg_getTime_2bc4375165f02d15=function(t){return $(t).getTime()},e.wbg.__wbg_new_cf3ec55744a78578=function(t){const n=new Date($(t));return S(n)},e.wbg.__wbg_instanceof_Object_71ca3c0a59266746=function(t){let n;try{n=$(t)instanceof Object}catch{n=!1}return n},e.wbg.__wbg_assign_496d2d14fecafbcf=function(t,n){const r=Object.assign($(t),$(n));return S(r)},e.wbg.__wbg_defineProperty_cc00e2de8a0f5141=function(t,n,r){const o=Object.defineProperty($(t),$(n),$(r));return S(o)},e.wbg.__wbg_entries_95cc2c823b285a09=function(t){const n=Object.entries($(t));return S(n)},e.wbg.__wbg_freeze_cc6bc19f75299986=function(t){const n=Object.freeze($(t));return S(n)},e.wbg.__wbg_keys_91e412b4b222659f=function(t){const n=Object.keys($(t));return S(n)},e.wbg.__wbg_values_9c75e6e2bfbdb70d=function(t){const n=Object.values($(t));return S(n)},e.wbg.__wbg_new_dd6a5dd7b538af21=function(t,n){const r=new RangeError(mt(t,n));return S(r)},e.wbg.__wbg_apply_0a5aa603881e6d79=function(){return lt(function(t,n,r){const o=Reflect.apply($(t),$(n),$(r));return S(o)},arguments)},e.wbg.__wbg_deleteProperty_13e721a56f19e842=function(){return lt(function(t,n){return Reflect.deleteProperty($(t),$(n))},arguments)},e.wbg.__wbg_ownKeys_658942b7f28d1fe9=function(){return lt(function(t){const n=Reflect.ownKeys($(t));return S(n)},arguments)},e.wbg.__wbg_set_1f9b04f170055d33=function(){return lt(function(t,n,r){return Reflect.set($(t),$(n),$(r))},arguments)},e.wbg.__wbg_buffer_12d079cc21e14bdb=function(t){const n=$(t).buffer;return S(n)},e.wbg.__wbg_concat_3de229fe4fe90fea=function(t,n){const r=$(t).concat($(n));return S(r)},e.wbg.__wbg_slice_52fb626ffdc8da8f=function(t,n,r){const o=$(t).slice(n>>>0,r>>>0);return S(o)},e.wbg.__wbg_for_27c67e2dbdce22f6=function(t,n){const r=Symbol.for(mt(t,n));return S(r)},e.wbg.__wbg_toString_7df3c77999517c20=function(t){const n=$(t).toString();return S(n)},e.wbg.__wbg_self_ce0dbfc45cf2f5be=function(){return lt(function(){const t=self.self;return S(t)},arguments)},e.wbg.__wbg_window_c6fb939a7f436783=function(){return lt(function(){const t=window.window;return S(t)},arguments)},e.wbg.__wbg_globalThis_d1e6af4856ba331b=function(){return lt(function(){const t=globalThis.globalThis;return S(t)},arguments)},e.wbg.__wbg_global_207b558942527489=function(){return lt(function(){const t=global.global;return S(t)},arguments)},e.wbg.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb=function(t,n,r){const o=new Uint8Array($(t),n>>>0,r>>>0);return S(o)},e.wbg.__wbg_new_63b92bc8671ed464=function(t){const n=new Uint8Array($(t));return S(n)},e.wbg.__wbg_set_a47bac70306a19a7=function(t,n,r){$(t).set($(n),r>>>0)},e.wbg.__wbg_length_c20a40f15020d68a=function(t){return $(t).length},e.wbg.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6=function(t){let n;try{n=$(t)instanceof Uint8Array}catch{n=!1}return n},e.wbg.__wbg_newwithlength_e9b4878cebadb3d3=function(t){const n=new Uint8Array(t>>>0);return S(n)},e.wbg.__wbg_subarray_a1f73cd4b5b42fe1=function(t,n,r){const o=$(t).subarray(n>>>0,r>>>0);return S(o)},e.wbg.__wbindgen_debug_string=function(t,n){const r=Kn($(n)),o=Ut(r,f.__wbindgen_malloc,f.__wbindgen_realloc),s=xt;y()[t/4+1]=s,y()[t/4+0]=o},e.wbg.__wbindgen_throw=function(t,n){throw new Error(mt(t,n))},e.wbg.__wbindgen_memory=function(){const t=f.memory;return S(t)},e}function Oo(e,t){return f=e.exports,qn.__wbindgen_wasm_module=t,$e=null,Ue=null,Te=null,f}function Wc(e){if(f!==void 0)return f;const t=Eo();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));const n=new WebAssembly.Instance(e,t);return Oo(n,e)}async function qn(e){if(f!==void 0)return f;typeof e>"u"&&(e=new URL("/.well-known/action_merge/assets/automerge_wasm_bg.wasm",import.meta.url));const t=Eo();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));const{instance:n,module:r}=await Kc(await e,t);return Oo(n,r)}const qc=Object.freeze(Object.defineProperty({__proto__:null,Automerge:Wn,SyncState:zt,TextRepresentation:Jc,create:$c,decodeChange:Mc,decodeSyncMessage:zc,decodeSyncState:Vc,default:qn,encodeChange:Dc,encodeSyncMessage:Lc,encodeSyncState:Nc,exportSyncState:Hc,importSyncState:Fc,initSync:Wc,initSyncState:Bc,load:Pc},Symbol.toStringTag,{value:"Module"}));let Gn=!1,jo=[];function Ro(e){for(const t in e)_t[t]=e[t];Gn=!0;for(const t of jo)t()}const _t={create(e){throw new RangeError("Automerge.use() not called")},load(e,t){throw new RangeError("Automerge.use() not called (load)")},encodeChange(e){throw new RangeError("Automerge.use() not called (encodeChange)")},decodeChange(e){throw new RangeError("Automerge.use() not called (decodeChange)")},initSyncState(){throw new RangeError("Automerge.use() not called (initSyncState)")},encodeSyncMessage(e){throw new RangeError("Automerge.use() not called (encodeSyncMessage)")},decodeSyncMessage(e){throw new RangeError("Automerge.use() not called (decodeSyncMessage)")},encodeSyncState(e){throw new RangeError("Automerge.use() not called (encodeSyncState)")},decodeSyncState(e){throw new RangeError("Automerge.use() not called (decodeSyncState)")},exportSyncState(e){throw new RangeError("Automerge.use() not called (exportSyncState)")},importSyncState(e){throw new RangeError("Automerge.use() not called (importSyncState)")}};function To(e){return qn(e).then(t=>{Ro(qc)})}function Gc(e){return To(Uint8Array.from(atob(e),t=>t.charCodeAt(0)))}function Zc(){return Gn?Promise.resolve():new Promise(e=>{jo.push(e)})}function Yc(){return Gn}function L(e,t=!0){if(typeof e!="object")throw new RangeError("must be the document root");const n=Reflect.get(e,Ft);if(n===void 0||n==null||t&&Pe(e)!=="_root")throw new RangeError("must be the document root");return n}function le(e){Reflect.set(e,Nn,!0)}function Zn(e){return Reflect.get(e,de)}function Pe(e){return typeof e!="object"||e===null?null:Reflect.get(e,fe)}function ht(e){return!!Reflect.get(e,tn)}var Xc=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n};function Qc(e,t,...n){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");e.insertAt(t,...n)}function tu(e,t,n){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");e.deleteAt(t,n)}function eu(e){return L(e).handle}function Yn(e){return typeof e=="object"?e:{actor:e}}function dn(e){const t=Yn(e),n=!!t.freeze,r=t.patchCallback,o=!t.enableTextV2,s=t.actor,i=_t.create({actor:s,text_v1:o});i.enableFreeze(!!t.freeze);const a=t.enableTextV2||!1;return Go(i,a),i.materialize("/",void 0,{handle:i,heads:void 0,freeze:n,patchCallback:r,textV2:a})}function Uo(e,t){const n=L(e),r=n.handle;return n.handle.materialize("/",t,Object.assign(Object.assign({},n),{handle:r,heads:t}))}function nu(e,t){const n=L(e),r=n.heads,o=Yn(t),s=n.handle.fork(o.actor,r);s.updateDiffCursor();const i=Xc(n,["heads"]);return i.patchCallback=o.patchCallback,s.applyPatches(e,Object.assign(Object.assign({},i),{handle:s}))}function ru(e){return L(e).handle.free()}function ou(e,t){return De(dn(t),"from",{},n=>Object.assign(n,e)).newDoc}function $o(e,t,n){if(typeof t=="function")return De(e,"change",{},t).newDoc;if(typeof n=="function")return typeof t=="string"&&(t={message:t}),De(e,"change",t,n).newDoc;throw RangeError("Invalid args for change")}function Po(e,t,n,r){if(typeof n=="function")return De(e,"changeAt",{},n,t);if(typeof r=="function")return typeof n=="string"&&(n={message:n}),De(e,"changeAt",n,r,t);throw RangeError("Invalid args for changeAt")}function ge(e,t,n,r){if(n==null)return e;const o=L(e),s=Object.assign(Object.assign({},o),{heads:void 0}),{value:i,patches:a}=o.handle.applyAndReturnPatches(e,s);if(a.length>0){r?.(a,{before:e,after:i,source:t});const c=L(i);c.mostRecentPatch={before:L(e).heads,after:c.handle.getHeads(),patches:a}}return o.heads=n,i}function De(e,t,n,r,o){if(typeof r!="function")throw new RangeError("invalid change function");const s=L(e);if(e===void 0||s===void 0)throw new RangeError("must be the document root");if(s.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");let i=s.handle.getHeads();o&&du(o,i)&&(o=void 0),o&&(s.handle.isolate(o),i=o),"time"in n||(n.time=Math.floor(Date.now()/1e3));try{s.heads=i;const a=Sc(s.handle,s.textV2);if(r(a),s.handle.pendingOps()===0)return s.heads=void 0,o&&s.handle.integrate(),{newDoc:e,newHeads:null};{const c=s.handle.commit(n.message,n.time);return s.handle.integrate(),{newDoc:ge(e,t,i,n.patchCallback||s.patchCallback),newHeads:c!=null?[c]:null}}}catch(a){throw s.heads=void 0,s.handle.rollback(),a}}function Do(e,t){t===void 0&&(t={}),typeof t=="string"&&(t={message:t}),"time"in t||(t.time=Math.floor(Date.now()/1e3));const n=L(e);if(n.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");const r=n.handle.getHeads();return n.handle.emptyChange(t.message,t.time),ge(e,"emptyChange",r)}function su(e,t){const n=Yn(t),r=n.actor,o=n.patchCallback,s=!n.enableTextV2,i=n.unchecked||!1,a=n.allowMissingChanges||!1,c=n.convertRawStringsToText||!1,_=_t.load(e,{text_v1:s,actor:r,unchecked:i,allowMissingDeps:a,convertRawStringsToText:c});_.enableFreeze(!!n.freeze);const u=n.enableTextV2||!1;return Go(_,u),_.materialize("/",void 0,{handle:_,heads:void 0,patchCallback:o,textV2:u})}function Xn(e,t,n){n||(n={});const r=L(e);if(r.heads)throw new RangeError("Attempting to change an out of date document - set at: "+Zn(e));if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");const o=r.handle.getHeads();return r.handle.loadIncremental(t),ge(e,"loadIncremental",o,n.patchCallback||r.patchCallback)}function iu(e){const t=L(e);if(t.heads)throw new RangeError("Attempting to change an out of date document - set at: "+Zn(e));if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");return t.handle.saveIncremental()}function Qn(e){return L(e).handle.save()}function Mo(e,t){const n=L(e);if(n.heads)throw new RangeError("Attempting to change an out of date document - set at: "+Zn(e));const r=n.handle.getHeads(),o=L(t),s=n.handle.getChangesAdded(o.handle);return n.handle.applyChanges(s),ge(e,"merge",r,n.patchCallback)}function au(e){return L(e).handle.getActorId()}function cu(e){return L(e).handle.getLastLocalChange()||void 0}function Bo(e,t){if(t){const n=L(e,!1),r=Pe(e);return!n||!r?null:n.handle.get(r,t)}else return Pe(e)}function uu(e,t){return L(t).handle.getChanges(jt(e))}function Fo(e){return L(e).handle.getChanges([])}function Ho(e,t,n){const r=L(e);if(n||(n={}),r.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");const o=r.handle.getHeads();return r.handle.applyChanges(t),r.heads=o,[ge(e,"applyChanges",o,n.patchCallback||r.patchCallback)]}function _u(e){const t=L(e).textV2,n=Fo(e);return n.map((r,o)=>({get change(){return Jo(r)},get snapshot(){const[s]=Ho(dn({enableTextV2:t}),n.slice(0,o+1));return s}}))}function tr(e,t,n){Lo(t,"before"),Lo(n,"after");const r=L(e);return r.mostRecentPatch&&fn(r.mostRecentPatch.before,t)&&fn(r.mostRecentPatch.after,n)?r.mostRecentPatch.patches:r.handle.diff(t,n)}function du(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Lo(e,t){if(!Array.isArray(e))throw new Error(`${t} must be an array`)}function fn(e,t){if(!Wo(e)||!Wo(t))return e===t;const n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let o=0;o<n.length;o++)if(n[o]!==r[o]||!fn(e[n[o]],t[r[o]]))return!1;return!0}function er(e){const t=_t.importSyncState(e),n=_t.encodeSyncState(t);return t.free(),n}function nr(e){const t=_t.decodeSyncState(e),n=_t.exportSyncState(t);return t.free(),n}function zo(e,t){const n=L(e),r=_t.importSyncState(t),o=n.handle.generateSyncMessage(r);return[_t.exportSyncState(r),o]}function No(e,t,n,r){const o=_t.importSyncState(t);r||(r={});const s=L(e);if(s.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(ht(e))throw new RangeError("Calls to Automerge.change cannot be nested");const i=s.handle.getHeads();s.handle.receiveSyncMessage(o,n);const a=_t.exportSyncState(o);return[ge(e,"receiveSyncMessage",i,r.patchCallback||s.patchCallback),a,null]}function fu(e,t){const n=L(e),r=_t.importSyncState(t);return n.handle.hasOurChanges(r)}function Vo(){return _t.exportSyncState(_t.initSyncState())}function hu(e){return _t.encodeChange(e)}function Jo(e){return _t.decodeChange(e)}function lu(e){return _t.encodeSyncMessage(e)}function Ko(e){return _t.decodeSyncMessage(e)}function gu(e,t){return L(e).handle.getMissingDeps(t)}function jt(e){const t=L(e);return t.heads||t.handle.getHeads()}function pu(e){L(e).handle.dump()}function bu(e){const t=L(e),n=t.handle.enableFreeze(!1),r=t.handle.materialize();return t.handle.enableFreeze(n),r}function yu(e){return typeof e=="object"&&e!==null?Bo(e)==="_root"&&!!Reflect.get(e,Ft):!1}function Wo(e){return typeof e=="object"&&e!==null}function qo(e,t){return L(e).handle.saveSince(t)}function wu(e,t){const n=L(e);for(const r of t)if(!n.handle.getChangeByHash(r))return!1;return!0}function Go(e,t){e.registerDatatype("counter",n=>new Ee(n),n=>{if(n instanceof Ee)return n.value}),t?e.registerDatatype("str",n=>new en(n),n=>{if(n instanceof en)return n.val}):e.registerDatatype("text",n=>new Ht(n),n=>{if(n instanceof Ht)return n.join("")})}function Zo(e){return L(e).handle.topoHistoryTraversal()}function Yo(e,t){return L(e).handle.getDecodedChangeByHash(t)}function Xo(e){return L(e).handle.stats()}const mu=eu;function te(e){const t=hn(e);return t.enableTextV2=!0,dn(t)}function rr(e,t){const n=hn(t);return n.enableTextV2=!0,nu(e,n)}function Qo(e,t){const n=hn(t);return n.enableTextV2=!0,ou(e,n)}function ts(e,t){const n=hn(t);return n.enableTextV2=!0,n.patchCallback?Xn(dn(n),e):su(e,n)}function hn(e){return typeof e=="object"?e:{actor:e}}function Me(e,t,n){if(typeof n=="string"){if(/^[0-9]+@[0-9a-zA-z]+$/.test(n))return e.handle.getCursorPosition(t,n);throw new RangeError("index must be a number or cursor")}else return n}function vu(e,t,n,r,o){const s=yt(e,t,"splice");if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const i=L(e,!1);le(e),n=Me(i,s,n);try{return i.handle.splice(s,n,r,o)}catch(a){throw new RangeError(`Cannot splice: ${a}`)}}function Su(e,t,n){const r=yt(e,t,"updateText");if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const o=L(e,!1);le(e);try{return o.handle.updateText(r,n)}catch(s){throw new RangeError(`Cannot updateText: ${s}`)}}function ku(e,t){const n=L(e,!1),r=yt(e,t,"spans");try{return n.handle.spans(r,n.heads)}catch(o){throw new RangeError(`Cannot splice: ${o}`)}}function xu(e,t,n){const r=yt(e,t,"splitBlock"),o=L(e,!1);n=Me(o,r,n);try{return o.handle.getBlock(r,n)}catch(s){throw new RangeError(`Cannot get block: ${s}`)}}function Au(e,t,n,r){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const o=yt(e,t,"splitBlock"),s=L(e,!1);le(e),n=Me(s,o,n);try{s.handle.splitBlock(o,n,r)}catch(i){throw new RangeError(`Cannot splice: ${i}`)}}function Iu(e,t,n){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const r=yt(e,t,"joinBlock"),o=L(e,!1);le(e),n=Me(o,r,n);try{o.handle.joinBlock(r,n)}catch(s){throw new RangeError(`Cannot joinBlock: ${s}`)}}function Cu(e,t,n,r){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const o=yt(e,t,"updateBlock"),s=L(e,!1);le(e),n=Me(s,o,n);try{s.handle.updateBlock(o,n,r)}catch(i){throw new RangeError(`Cannot updateBlock: ${i}`)}}function Eu(e,t,n){if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const r=yt(e,t,"updateSpans"),o=L(e,!1);le(e);try{o.handle.updateSpans(r,n)}catch(s){throw new RangeError(`Cannot updateBlock: ${s}`)}}function Ou(e,t,n){const r=yt(e,t,"getCursor"),o=L(e,!1);try{return o.handle.getCursor(r,n)}catch(s){throw new RangeError(`Cannot getCursor: ${s}`)}}function ju(e,t,n){const r=yt(e,t,"getCursorPosition"),o=L(e,!1);try{return o.handle.getCursorPosition(r,n)}catch(s){throw new RangeError(`Cannot getCursorPosition: ${s}`)}}function Ru(e,t,n,r,o){const s=yt(e,t,"mark");if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const i=L(e,!1);try{return i.handle.mark(s,n,r,o)}catch(a){throw new RangeError(`Cannot mark: ${a}`)}}function Tu(e,t,n,r){const o=yt(e,t,"unmark");if(!ht(e))throw new RangeError("object cannot be modified outside of a change block");const s=L(e,!1);try{return s.handle.unmark(o,n,r)}catch(i){throw new RangeError(`Cannot unmark: ${i}`)}}function Uu(e,t){const n=yt(e,t,"marks"),r=L(e,!1);try{return r.handle.marks(n)}catch(o){throw new RangeError(`Cannot call marks(): ${o}`)}}function $u(e,t,n){const r=yt(e,t,"marksAt"),o=L(e,!1);try{return o.handle.marksAt(r,n)}catch(s){throw new RangeError(`Cannot call marksAt(): ${s}`)}}function Pu(e,t){const n=L(e,!1);if(!n.textV2)throw new Error("use getConflicts for a stable document");const r=Pe(e);if(r!=null)return xc(n.handle,r,t)}function yt(e,t,n){t=t.slice();const r=Pe(e);if(!r)throw new RangeError(`invalid object for ${n}`);return t.unshift(r),t.join("/")}const Du=Object.freeze(Object.defineProperty({__proto__:null,Counter:Ee,Float64:wc,Int:bc,RawString:en,Uint:yc,applyChanges:Ho,block:xu,change:$o,changeAt:Po,clone:rr,decodeChange:Jo,decodeSyncMessage:Ko,decodeSyncState:nr,deleteAt:tu,diff:tr,dump:pu,emptyChange:Do,encodeChange:hu,encodeSyncMessage:lu,encodeSyncState:er,equals:fn,free:ru,from:Qo,generateSyncMessage:zo,getActorId:au,getAllChanges:Fo,getBackend:mu,getChanges:uu,getConflicts:Pu,getCursor:Ou,getCursorPosition:ju,getHeads:jt,getHistory:_u,getLastLocalChange:cu,getMissingDeps:gu,getObjectId:Bo,hasHeads:wu,hasOurChanges:fu,init:te,initSyncState:Vo,initializeBase64Wasm:Gc,initializeWasm:To,insertAt:Qc,inspectChange:Yo,isAutomerge:yu,isWasmInitialized:Yc,joinBlock:Iu,load:ts,loadIncremental:Xn,mark:Ru,marks:Uu,marksAt:$u,merge:Mo,receiveSyncMessage:No,save:Qn,saveIncremental:iu,saveSince:qo,spans:ku,splice:vu,splitBlock:Au,stats:Xo,toJS:bu,topoHistoryTraversal:Zo,unmark:Tu,updateBlock:Cu,updateSpans:Eu,updateText:Su,view:Uo,wasmInitialized:Zc},Symbol.toStringTag,{value:"Module"}));var Be=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ln(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var or={exports:{}},sr,es;function Mu(){if(es)return sr;es=1;var e=1e3,t=e*60,n=t*60,r=n*24,o=r*7,s=r*365.25;sr=function(u,d){d=d||{};var g=typeof u;if(g==="string"&&u.length>0)return i(u);if(g==="number"&&isFinite(u))return d.long?c(u):a(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function i(u){if(u=String(u),!(u.length>100)){var d=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(d){var g=parseFloat(d[1]),l=(d[2]||"ms").toLowerCase();switch(l){case"years":case"year":case"yrs":case"yr":case"y":return g*s;case"weeks":case"week":case"w":return g*o;case"days":case"day":case"d":return g*r;case"hours":case"hour":case"hrs":case"hr":case"h":return g*n;case"minutes":case"minute":case"mins":case"min":case"m":return g*t;case"seconds":case"second":case"secs":case"sec":case"s":return g*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return g;default:return}}}}function a(u){var d=Math.abs(u);return d>=r?Math.round(u/r)+"d":d>=n?Math.round(u/n)+"h":d>=t?Math.round(u/t)+"m":d>=e?Math.round(u/e)+"s":u+"ms"}function c(u){var d=Math.abs(u);return d>=r?_(u,d,r,"day"):d>=n?_(u,d,n,"hour"):d>=t?_(u,d,t,"minute"):d>=e?_(u,d,e,"second"):u+" ms"}function _(u,d,g,l){var v=d>=g*1.5;return Math.round(u/g)+" "+l+(v?"s":"")}return sr}function Bu(e){n.debug=n,n.default=n,n.coerce=c,n.disable=s,n.enable=o,n.enabled=i,n.humanize=Mu(),n.destroy=_,Object.keys(e).forEach(u=>{n[u]=e[u]}),n.names=[],n.skips=[],n.formatters={};function t(u){let d=0;for(let g=0;g<u.length;g++)d=(d<<5)-d+u.charCodeAt(g),d|=0;return n.colors[Math.abs(d)%n.colors.length]}n.selectColor=t;function n(u){let d,g=null,l,v;function x(...M){if(!x.enabled)return;const F=x,B=Number(new Date),U=B-(d||B);F.diff=U,F.prev=d,F.curr=B,d=B,M[0]=n.coerce(M[0]),typeof M[0]!="string"&&M.unshift("%O");let J=0;M[0]=M[0].replace(/%([a-zA-Z%])/g,(W,z)=>{if(W==="%%")return"%";J++;const Q=n.formatters[z];if(typeof Q=="function"){const Y=M[J];W=Q.call(F,Y),M.splice(J,1),J--}return W}),n.formatArgs.call(F,M),(F.log||n.log).apply(F,M)}return x.namespace=u,x.useColors=n.useColors(),x.color=n.selectColor(u),x.extend=r,x.destroy=n.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(l!==n.namespaces&&(l=n.namespaces,v=n.enabled(u)),v),set:M=>{g=M}}),typeof n.init=="function"&&n.init(x),x}function r(u,d){const g=n(this.namespace+(typeof d>"u"?":":d)+u);return g.log=this.log,g}function o(u){n.save(u),n.namespaces=u,n.names=[],n.skips=[];let d;const g=(typeof u=="string"?u:"").split(/[\s,]+/),l=g.length;for(d=0;d<l;d++)g[d]&&(u=g[d].replace(/\*/g,".*?"),u[0]==="-"?n.skips.push(new RegExp("^"+u.slice(1)+"$")):n.names.push(new RegExp("^"+u+"$")))}function s(){const u=[...n.names.map(a),...n.skips.map(a).map(d=>"-"+d)].join(",");return n.enable(""),u}function i(u){if(u[u.length-1]==="*")return!0;let d,g;for(d=0,g=n.skips.length;d<g;d++)if(n.skips[d].test(u))return!1;for(d=0,g=n.names.length;d<g;d++)if(n.names[d].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var Fu=Bu;(function(e,t){var n={};t.formatArgs=o,t.save=s,t.load=i,t.useColors=r,t.storage=a(),t.destroy=(()=>{let _=!1;return()=>{_||(_=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let _;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(_=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(_[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function o(_){if(_[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+_[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const u="color: "+this.color;_.splice(1,0,u,"color: inherit");let d=0,g=0;_[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(d++,l==="%c"&&(g=d))}),_.splice(g,0,u)}t.log=console.debug||console.log||(()=>{});function s(_){try{_?t.storage.setItem("debug",_):t.storage.removeItem("debug")}catch{}}function i(){let _;try{_=t.storage.getItem("debug")}catch{}return!_&&typeof process<"u"&&"env"in process&&(_=n.DEBUG),_}function a(){try{return localStorage}catch{}}e.exports=Fu(t);const{formatters:c}=e.exports;c.j=function(_){try{return JSON.stringify(_)}catch(u){return"[UnexpectedJSONParseError]: "+u.message}}})(or,or.exports);var Hu=or.exports;const ee=ln(Hu);var ns={exports:{}};(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(c,_,u){this.fn=c,this.context=_,this.once=u||!1}function s(c,_,u,d,g){if(typeof u!="function")throw new TypeError("The listener must be a function");var l=new o(u,d||c,g),v=n?n+_:_;return c._events[v]?c._events[v].fn?c._events[v]=[c._events[v],l]:c._events[v].push(l):(c._events[v]=l,c._eventsCount++),c}function i(c,_){--c._eventsCount===0?c._events=new r:delete c._events[_]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],_,u;if(this._eventsCount===0)return c;for(u in _=this._events)t.call(_,u)&&c.push(n?u.slice(1):u);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(_)):c},a.prototype.listeners=function(c){var _=n?n+c:c,u=this._events[_];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,g=u.length,l=new Array(g);d<g;d++)l[d]=u[d].fn;return l},a.prototype.listenerCount=function(c){var _=n?n+c:c,u=this._events[_];return u?u.fn?1:u.length:0},a.prototype.emit=function(c,_,u,d,g,l){var v=n?n+c:c;if(!this._events[v])return!1;var x=this._events[v],M=arguments.length,F,B;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),M){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,_),!0;case 3:return x.fn.call(x.context,_,u),!0;case 4:return x.fn.call(x.context,_,u,d),!0;case 5:return x.fn.call(x.context,_,u,d,g),!0;case 6:return x.fn.call(x.context,_,u,d,g,l),!0}for(B=1,F=new Array(M-1);B<M;B++)F[B-1]=arguments[B];x.fn.apply(x.context,F)}else{var U=x.length,J;for(B=0;B<U;B++)switch(x[B].once&&this.removeListener(c,x[B].fn,void 0,!0),M){case 1:x[B].fn.call(x[B].context);break;case 2:x[B].fn.call(x[B].context,_);break;case 3:x[B].fn.call(x[B].context,_,u);break;case 4:x[B].fn.call(x[B].context,_,u,d);break;default:if(!F)for(J=1,F=new Array(M-1);J<M;J++)F[J-1]=arguments[J];x[B].fn.apply(x[B].context,F)}}return!0},a.prototype.on=function(c,_,u){return s(this,c,_,u,!1)},a.prototype.once=function(c,_,u){return s(this,c,_,u,!0)},a.prototype.removeListener=function(c,_,u,d){var g=n?n+c:c;if(!this._events[g])return this;if(!_)return i(this,g),this;var l=this._events[g];if(l.fn)l.fn===_&&(!d||l.once)&&(!u||l.context===u)&&i(this,g);else{for(var v=0,x=[],M=l.length;v<M;v++)(l[v].fn!==_||d&&!l[v].once||u&&l[v].context!==u)&&x.push(l[v]);x.length?this._events[g]=x.length===1?x[0]:x:i(this,g)}return this},a.prototype.removeAllListeners=function(c){var _;return c?(_=n?n+c:c,this._events[_]&&i(this,_)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})(ns);var Lu=ns.exports;const pe=ln(Lu);function zu(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function Nu(){const e=zu();if(e.__xstate__)return e.__xstate__}const Vu=e=>{if(typeof window>"u")return;const t=Nu();t&&t.register(e)};class rs{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const os=".",Ju="",ss="",Ku="#",Wu="*",is="xstate.init",ir="xstate.stop";function qu(e,t){return{type:`xstate.after.${e}.${t}`}}function ar(e,t){return{type:`xstate.done.state.${e}`,output:t}}function Gu(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function Zu(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function as(e){return{type:is,input:e}}function Nt(e){setTimeout(()=>{throw e})}const Yu=typeof Symbol=="function"&&Symbol.observable||"@@observable";function cs(e,t){const n=us(e),r=us(t);return typeof r=="string"?typeof n=="string"?r===n:!1:typeof n=="string"?n in r:Object.keys(n).every(o=>o in r?cs(n[o],r[o]):!1)}function cr(e){if(fs(e))return e;let t=[],n="";for(let r=0;r<e.length;r++){switch(e.charCodeAt(r)){case 92:n+=e[r+1],r++;continue;case 46:t.push(n),n="";continue}n+=e[r]}return t.push(n),t}function us(e){if(j_(e))return e.value;if(typeof e!="string")return e;const t=cr(e);return Xu(t)}function Xu(e){if(e.length===1)return e[0];const t={};let n=t;for(let r=0;r<e.length-1;r++)if(r===e.length-2)n[e[r]]=e[r+1];else{const o=n;n={},o[e[r]]=n}return t}function _s(e,t){const n={},r=Object.keys(e);for(let o=0;o<r.length;o++){const s=r[o];n[s]=t(e[s],s,e,o)}return n}function ds(e){return fs(e)?e:[e]}function Vt(e){return e===void 0?[]:ds(e)}function ur(e,t,n,r){return typeof e=="function"?e({context:t,event:n,self:r}):e}function fs(e){return Array.isArray(e)}function Qu(e){return e.type.startsWith("xstate.error.actor")}function be(e){return ds(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function hs(e){if(!(e===void 0||e===Ju))return Vt(e)}function _r(e,t,n){const r=typeof e=="object",o=r?e:void 0;return{next:(r?e.next:e)?.bind(o),error:(r?e.error:t)?.bind(o),complete:(r?e.complete:n)?.bind(o)}}function ls(e,t){return`${t}.${e}`}function dr(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,r,o]=n,s=e.getStateNodeById(o).config.invoke;return(Array.isArray(s)?s[r]:s).src}function gs(e,t){return`${e.sessionId}.${t}`}let t_=0;function e_(e,t){const n=new Map,r=new Map,o=new WeakMap,s=new Set,i={},{clock:a,logger:c}=t,_={schedule:(g,l,v,x,M=Math.random().toString(36).slice(2))=>{const F={source:g,target:l,event:v,delay:x,id:M,startedAt:Date.now()},B=gs(g,M);d._snapshot._scheduledEvents[B]=F;const U=a.setTimeout(()=>{delete i[B],delete d._snapshot._scheduledEvents[B],d._relay(g,l,v)},x);i[B]=U},cancel:(g,l)=>{const v=gs(g,l),x=i[v];delete i[v],delete d._snapshot._scheduledEvents[v],x!==void 0&&a.clearTimeout(x)},cancelAll:g=>{for(const l in d._snapshot._scheduledEvents){const v=d._snapshot._scheduledEvents[l];v.source===g&&_.cancel(g,v.id)}}},u=g=>{if(!s.size)return;const l={...g,rootId:e.sessionId};s.forEach(v=>v.next?.(l))},d={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${t_++}`,_register:(g,l)=>(n.set(g,l),g),_unregister:g=>{n.delete(g.sessionId);const l=o.get(g);l!==void 0&&(r.delete(l),o.delete(g))},get:g=>r.get(g),_set:(g,l)=>{const v=r.get(g);if(v&&v!==l)throw new Error(`Actor with system ID '${g}' already exists.`);r.set(g,l),o.set(l,g)},inspect:g=>{const l=_r(g);return s.add(l),{unsubscribe(){s.delete(l)}}},_sendInspectionEvent:u,_relay:(g,l,v)=>{d._sendInspectionEvent({type:"@xstate.event",sourceRef:g,actorRef:l,event:v}),l._send(v)},scheduler:_,getSnapshot:()=>({_scheduledEvents:{...d._snapshot._scheduledEvents}}),start:()=>{const g=d._snapshot._scheduledEvents;d._snapshot._scheduledEvents={};for(const l in g){const{source:v,target:x,event:M,delay:F,id:B}=g[l];_.schedule(v,x,M,F,B)}},_clock:a,_logger:c};return d}const fr=1;let gt=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const n_={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class r_{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new rs(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=gt.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const r={...n_,...n},{clock:o,logger:s,parent:i,syncSnapshot:a,id:c,systemId:_,inspect:u}=r;this.system=i?i.system:e_(this,{clock:o,logger:s}),u&&!i&&this.system.inspect(_r(u)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=n?.logger??this.system._logger,this.clock=n?.clock??this.system._clock,this._parent=i,this._syncSnapshot=a,this.options=r,this.src=r.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:d=>{this._deferred.push(d)},system:this.system,stopChild:d=>{if(d._parent!==this)throw new Error(`Cannot stop child actor ${d.id} of ${this.id} because it is not a child`);d._stop()},emit:d=>{const g=this.eventListeners.get(d.type),l=this.eventListeners.get("*");if(!g&&!l)return;const v=new Set([...g?g.values():[],...l?l.values():[]]);for(const x of Array.from(v))x(d)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),_&&(this._systemId=_,this.system._set(_,this)),this._initState(n?.snapshot??n?.state),_&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(n){this._snapshot={status:"error",output:void 0,error:n}}}update(t,n){this._snapshot=t;let r;for(;r=this._deferred.shift();)try{r()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{o.next?.(t)}catch(s){Nt(s)}break;case"done":for(const o of this.observers)try{o.next?.(t)}catch(s){Nt(s)}this._stopProcedure(),this._complete(),this._doneEvent=Gu(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,r){const o=_r(t,n,r);if(this._processingStatus!==gt.Stopped)this.observers.add(o);else switch(this._snapshot.status){case"done":try{o.complete?.()}catch(s){Nt(s)}break;case"error":{const s=this._snapshot.error;if(!o.error)Nt(s);else try{o.error(s)}catch(i){Nt(i)}break}}return{unsubscribe:()=>{this.observers.delete(o)}}}on(t,n){let r=this.eventListeners.get(t);r||(r=new Set,this.eventListeners.set(t,r));const o=n.bind(void 0);return r.add(o),{unsubscribe:()=>{r.delete(o)}}}start(){if(this._processingStatus===gt.Running)return this;this._syncSnapshot&&this.subscribe({next:n=>{n.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:n})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=gt.Running;const t=as(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(n){return this._snapshot={...this._snapshot,status:"error",error:n},this._error(n),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,r;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(o){r={err:o}}if(r){const{err:o}=r;this._snapshot={...this._snapshot,status:"error",error:o},this._error(o);return}this.update(n,t),t.type===ir&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===gt.Stopped?this:(this.mailbox.clear(),this._processingStatus===gt.NotStarted?(this._processingStatus=gt.Stopped,this):(this.mailbox.enqueue({type:ir}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(n){Nt(n)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||Nt(t);return}let n=!1;for(const r of this.observers){const o=r.error;n||=!o;try{o?.(t)}catch(s){Nt(s)}}this.observers.clear(),n&&Nt(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Zu(this.id,t))}_stopProcedure(){return this._processingStatus!==gt.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new rs(this._process.bind(this)),this._processingStatus=gt.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==gt.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:Vu)(this)}toJSON(){return{xstate$$type:fr,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Yu](){return this}getSnapshot(){return this._snapshot}}function Fe(e,...[t]){return new r_(e,t)}function o_(e,t,n,r,{sendId:o}){const s=typeof o=="function"?o(n,r):o;return[t,s]}function s_(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function i_(e){function t(n,r){}return t.type="xstate.cancel",t.sendId=e,t.resolve=o_,t.execute=s_,t}function a_(e,t,n,r,{id:o,systemId:s,src:i,input:a,syncSnapshot:c}){const _=typeof i=="string"?dr(t.machine,i):i,u=typeof o=="function"?o(n):o;let d;return _&&(d=Fe(_,{id:u,src:i,parent:e.self,syncSnapshot:c,systemId:s,input:typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a})),[oe(t,{children:{...t.children,[u]:d}}),{id:o,actorRef:d}]}function c_(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==gt.Stopped&&n.start()})}function u_(...[e,{id:t,systemId:n,input:r,syncSnapshot:o=!1}={}]){function s(i,a){}return s.type="snapshot.spawnChild",s.id=t,s.systemId=n,s.src=e,s.input=r,s.syncSnapshot=o,s.resolve=a_,s.execute=c_,s}function __(e,t,n,r,{actorRef:o}){const s=typeof o=="function"?o(n,r):o,i=typeof s=="string"?t.children[s]:s;let a=t.children;return i&&(a={...a},delete a[i.id]),[oe(t,{children:a}),i]}function d_(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==gt.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function ps(e){function t(n,r){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=__,t.execute=d_,t}function hr(e,t,n,r){const{machine:o}=r,s=typeof e=="function",i=s?e:o.implementations.guards[typeof e=="string"?e:e.type];if(!s&&!i)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof i!="function")return hr(i,t,n,r);const a={context:t,event:n},c=s||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in i?i.check(r,a,i):i(a,c)}const lr=e=>e.type==="atomic"||e.type==="final";function ye(e){return Object.values(e.states).filter(t=>t.type!=="history")}function He(e,t){const n=[];if(t===e)return n;let r=e.parent;for(;r&&r!==t;)n.push(r),r=r.parent;return n}function gn(e){const t=new Set(e),n=ys(t);for(const r of t)if(r.type==="compound"&&(!n.get(r)||!n.get(r).length))vs(r).forEach(o=>t.add(o));else if(r.type==="parallel"){for(const o of ye(r))if(o.type!=="history"&&!t.has(o)){const s=vs(o);for(const i of s)t.add(i)}}for(const r of t){let o=r.parent;for(;o;)t.add(o),o=o.parent}return t}function bs(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const o=n[0];if(o){if(lr(o))return o.key}else return{}}const r={};for(const o of n)r[o.key]=bs(o,t);return r}function ys(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function ws(e,t){const n=gn(t);return bs(e,ys(n))}function gr(e,t){return t.type==="compound"?ye(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?ye(t).every(n=>gr(e,n)):t.type==="final"}const pn=e=>e[0]===Ku;function f_(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(n=>{if(n===Wu)return!0;if(!n.endsWith(".*"))return!1;const r=n.split("."),o=t.split(".");for(let s=0;s<r.length;s++){const i=r[s],a=o[s];if(i==="*")return s===r.length-1;if(i!==a)return!1}return!0}).sort((n,r)=>r.length-n.length).flatMap(n=>e.transitions.get(n))}function h_(e){const t=e.config.after;if(!t)return[];const n=(r,o)=>{const s=qu(r,e.id),i=s.type;return e.entry.push(F_(s,{id:i,delay:r})),e.exit.push(i_(i)),i};return Object.keys(t).flatMap((r,o)=>{const s=t[r],i=typeof s=="string"?{target:s}:s,a=Number.isNaN(+r)?r:+r,c=n(a);return Vt(i).map(_=>({..._,event:c,delay:a}))}).map(r=>{const{delay:o}=r;return{...ne(e,r.event,r),delay:o}})}function ne(e,t,n){const r=hs(n.target),o=n.reenter??!1,s=p_(e,r),i={...n,actions:Vt(n.actions),guard:n.guard,target:s,source:e,reenter:o,eventType:t,toJSON:()=>({...i,source:`#${e.id}`,target:s?s.map(a=>`#${a.id}`):void 0})};return i}function l_(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===ss)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const r=e.config.on[n];t.set(n,be(r).map(o=>ne(e,n,o)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,be(e.config.onDone).map(r=>ne(e,n,r)))}for(const n of e.invoke){if(n.onDone){const r=`xstate.done.actor.${n.id}`;t.set(r,be(n.onDone).map(o=>ne(e,r,o)))}if(n.onError){const r=`xstate.error.actor.${n.id}`;t.set(r,be(n.onError).map(o=>ne(e,r,o)))}if(n.onSnapshot){const r=`xstate.snapshot.${n.id}`;t.set(r,be(n.onSnapshot).map(o=>ne(e,r,o)))}}for(const n of e.after){let r=t.get(n.eventType);r||(r=[],t.set(n.eventType,r)),r.push(n)}return t}function g_(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const r={source:e,actions:!t||typeof t=="string"?[]:Vt(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...r,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return r}function p_(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(pn(n))return e.machine.getStateNodeById(n);const r=n[0]===os;if(r&&!e.parent)return bn(e,n.slice(1));const o=r?e.key+n:n;if(e.parent)try{return bn(e.parent,o)}catch(s){throw new Error(`Invalid transition definition for state node '${e.id}':
3
+ ${s.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function ms(e){const t=hs(e.config.target);return t?{target:t.map(n=>typeof n=="string"?bn(e.parent,n):n)}:e.parent.initial}function re(e){return e.type==="history"}function vs(e){const t=Ss(e);for(const n of t)for(const r of He(n,e))t.add(r);return t}function Ss(e){const t=new Set;function n(r){if(!t.has(r)){if(t.add(r),r.type==="compound")n(r.initial.target[0]);else if(r.type==="parallel")for(const o of ye(r))n(o)}}return n(e),t}function we(e,t){if(pn(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function bn(e,t){if(typeof t=="string"&&pn(t))try{return e.machine.getStateNodeById(t)}catch{}const n=cr(t).slice();let r=e;for(;n.length;){const o=n.shift();if(!o.length)break;r=we(r,o)}return r}function yn(e,t){if(typeof t=="string"){const o=e.states[t];if(!o)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,o]}const n=Object.keys(t),r=n.map(o=>we(e,o)).filter(Boolean);return[e.machine.root,e].concat(r,n.reduce((o,s)=>{const i=we(e,s);if(!i)return o;const a=yn(i,t[s]);return o.concat(a)},[]))}function b_(e,t,n,r){const o=we(e,t).next(n,r);return!o||!o.length?e.next(n,r):o}function y_(e,t,n,r){const o=Object.keys(t),s=we(e,o[0]),i=pr(s,t[o[0]],n,r);return!i||!i.length?e.next(n,r):i}function w_(e,t,n,r){const o=[];for(const s of Object.keys(t)){const i=t[s];if(!i)continue;const a=we(e,s),c=pr(a,i,n,r);c&&o.push(...c)}return o.length?o:e.next(n,r)}function pr(e,t,n,r){return typeof t=="string"?b_(e,t,n,r):Object.keys(t).length===1?y_(e,t,n,r):w_(e,t,n,r)}function m_(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function Wt(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function v_(e,t){const n=new Set(e),r=new Set(t);for(const o of n)if(r.has(o))return!0;for(const o of r)if(n.has(o))return!0;return!1}function ks(e,t,n){const r=new Set;for(const o of e){let s=!1;const i=new Set;for(const a of r)if(v_(yr([o],t,n),yr([a],t,n)))if(Wt(o.source,a.source))i.add(a);else{s=!0;break}if(!s){for(const a of i)r.delete(a);r.add(o)}}return Array.from(r)}function S_(e){const[t,...n]=e;for(const r of He(t,void 0))if(n.every(o=>Wt(o,r)))return r}function br(e,t){if(!e.target)return[];const n=new Set;for(const r of e.target)if(re(r))if(t[r.id])for(const o of t[r.id])n.add(o);else for(const o of br(ms(r),t))n.add(o);else n.add(r);return[...n]}function xs(e,t){const n=br(e,t);if(!n)return;if(!e.reenter&&n.every(o=>o===e.source||Wt(o,e.source)))return e.source;const r=S_(n.concat(e.source));if(r)return r;if(!e.reenter)return e.source.machine.root}function yr(e,t,n){const r=new Set;for(const o of e)if(o.target?.length){const s=xs(o,n);o.reenter&&o.source===s&&r.add(s);for(const i of t)Wt(i,s)&&r.add(i)}return[...r]}function k_(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function wr(e,t,n,r,o,s){if(!e.length)return t;const i=new Set(t._nodes);let a=t.historyValue;const c=ks(e,i,a);let _=t;o||([_,a]=C_(_,r,n,c,i,a,s)),_=ve(_,r,n,c.flatMap(d=>d.actions),s),_=A_(_,r,n,c,i,s,a,o);const u=[...i];_.status==="done"&&(_=ve(_,r,n,u.sort((d,g)=>g.order-d.order).flatMap(d=>d.exit),s));try{return a===t.historyValue&&k_(t._nodes,i)?_:oe(_,{_nodes:u,historyValue:a})}catch(d){throw d}}function x_(e,t,n,r,o){if(r.output===void 0)return;const s=ar(o.id,o.output!==void 0&&o.parent?ur(o.output,e.context,t,n.self):void 0);return ur(r.output,e.context,s,n.self)}function A_(e,t,n,r,o,s,i,a){let c=e;const _=new Set,u=new Set;I_(r,i,u,_),a&&u.add(e.machine.root);const d=new Set;for(const g of[..._].sort((l,v)=>l.order-v.order)){o.add(g);const l=[];l.push(...g.entry);for(const v of g.invoke)l.push(u_(v.src,{...v,syncSnapshot:!!v.onSnapshot}));if(u.has(g)){const v=g.initial.actions;l.push(...v)}if(c=ve(c,t,n,l,s,g.invoke.map(v=>v.id)),g.type==="final"){const v=g.parent;let x=v?.type==="parallel"?v:v?.parent,M=x||g;for(v?.type==="compound"&&s.push(ar(v.id,g.output!==void 0?ur(g.output,c.context,t,n.self):void 0));x?.type==="parallel"&&!d.has(x)&&gr(o,x);)d.add(x),s.push(ar(x.id)),M=x,x=x.parent;if(x)continue;c=oe(c,{status:"done",output:x_(c,t,n,c.machine.root,M)})}}return c}function I_(e,t,n,r){for(const o of e){const s=xs(o,t);for(const a of o.target||[])!re(a)&&(o.source!==a||o.source!==s||o.reenter)&&(r.add(a),n.add(a)),me(a,t,n,r);const i=br(o,t);for(const a of i){const c=He(a,s);s?.type==="parallel"&&c.push(s),As(r,t,n,c,!o.source.parent&&o.reenter?void 0:s)}}}function me(e,t,n,r){if(re(e))if(t[e.id]){const o=t[e.id];for(const s of o)r.add(s),me(s,t,n,r);for(const s of o)mr(s,e.parent,r,t,n)}else{const o=ms(e);for(const s of o.target)r.add(s),o===e.parent?.initial&&n.add(e.parent),me(s,t,n,r);for(const s of o.target)mr(s,e.parent,r,t,n)}else if(e.type==="compound"){const[o]=e.initial.target;re(o)||(r.add(o),n.add(o)),me(o,t,n,r),mr(o,e,r,t,n)}else if(e.type==="parallel")for(const o of ye(e).filter(s=>!re(s)))[...r].some(s=>Wt(s,o))||(re(o)||(r.add(o),n.add(o)),me(o,t,n,r))}function As(e,t,n,r,o){for(const s of r)if((!o||Wt(s,o))&&e.add(s),s.type==="parallel")for(const i of ye(s).filter(a=>!re(a)))[...e].some(a=>Wt(a,i))||(e.add(i),me(i,t,n,e))}function mr(e,t,n,r,o){As(n,r,o,He(e,t))}function C_(e,t,n,r,o,s,i){let a=e;const c=yr(r,o,s);c.sort((u,d)=>d.order-u.order);let _;for(const u of c)for(const d of m_(u)){let g;d.history==="deep"?g=l=>lr(l)&&Wt(l,u):g=l=>l.parent===u,_??={...s},_[d.id]=Array.from(o).filter(g)}for(const u of c)a=ve(a,t,n,[...u.exit,...u.invoke.map(d=>ps(d.id))],i),o.delete(u);return[a,_||s]}let Is=!1;function Cs(e,t,n,r,o,s){const{machine:i}=e;let a=e;for(const c of r){let _=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",params:l}});try{Is=d,d(g,l)}finally{Is=!1}};const u=typeof c=="function",d=u?c:i.implementations.actions[typeof c=="string"?c:c.type];if(!d)continue;const g={context:a.context,event:t,self:n.self,system:n.system},l=u||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!("resolve"in d)){n.self._processingStatus===gt.Running?_():n.defer(()=>{_()});continue}const v=d,[x,M,F]=v.resolve(n,a,g,l,d,o);a=x,"retryResolve"in v&&s?.push([v,M]),"execute"in v&&(n.self._processingStatus===gt.Running?v.execute(n,M):n.defer(v.execute.bind(null,n,M))),F&&(a=Cs(a,t,n,F,o,s))}return a}function ve(e,t,n,r,o,s){const i=s?[]:void 0,a=Cs(e,t,n,r,{internalQueue:o,deferredActorIds:s},i);return i?.forEach(([c,_])=>{c.retryResolve(n,a,_)}),a}function vr(e,t,n,r=[]){let o=e;const s=[];function i(_,u,d){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:u,snapshot:_,_transitions:d}),s.push(_)}if(t.type===ir)return o=oe(Es(o,t,n),{status:"stopped"}),i(o,t,[]),{snapshot:o,microstates:s};let a=t;if(a.type!==is){const _=a,u=Qu(_),d=Os(_,o);if(u&&!d.length)return o=oe(e,{status:"error",error:_.error}),i(o,_,[]),{snapshot:o,microstates:s};o=wr(d,e,n,a,!1,r),i(o,_,d)}let c=!0;for(;o.status==="active";){let _=c?E_(o,a):[];const u=_.length?o:void 0;if(!_.length){if(!r.length)break;a=r.shift(),_=Os(a,o)}o=wr(_,o,n,a,!1,r),c=o!==u,i(o,a,_)}return o.status!=="active"&&Es(o,a,n),{snapshot:o,microstates:s}}function Es(e,t,n){return ve(e,t,n,Object.values(e.children).map(r=>ps(r)),[])}function Os(e,t){return t.machine.getTransitionData(t,e)}function E_(e,t){const n=new Set,r=e._nodes.filter(lr);for(const o of r)t:for(const s of[o].concat(He(o,void 0)))if(s.always){for(const i of s.always)if(i.guard===void 0||hr(i.guard,e.context,t,e)){n.add(i);break t}}return ks(Array.from(n),new Set(e._nodes),e.historyValue)}function O_(e,t){const n=gn(yn(e,t));return ws(e,[...n])}function j_(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const R_=function(e){return cs(e,this.value)},T_=function(e){return this.tags.has(e)},U_=function(e){const t=this.machine.getTransitionData(this,e);return!!t?.length&&t.some(n=>n.target!==void 0||n.actions.length)},$_=function(){const{_nodes:e,tags:t,machine:n,getMeta:r,toJSON:o,can:s,hasTag:i,matches:a,...c}=this;return{...c,tags:Array.from(t)}},P_=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function wn(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:ws(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:R_,hasTag:T_,can:U_,getMeta:P_,toJSON:$_}}function oe(e,t={}){return wn({...e,...t},e.machine)}function D_(e,t){const{_nodes:n,tags:r,machine:o,children:s,context:i,can:a,hasTag:c,matches:_,getMeta:u,toJSON:d,...g}=e,l={};for(const v in s){const x=s[v];l[v]={snapshot:x.getPersistedSnapshot(t),src:x.src,systemId:x._systemId,syncSnapshot:x._syncSnapshot}}return{...g,context:js(i),children:l}}function js(e){let t;for(const n in e){const r=e[n];if(r&&typeof r=="object")if("sessionId"in r&&"send"in r&&"ref"in r)t??=Array.isArray(e)?e.slice():{...e},t[n]={xstate$$type:fr,id:r.id};else{const o=js(r);o!==r&&(t??=Array.isArray(e)?e.slice():{...e},t[n]=o)}}return t??e}function M_(e,t,n,r,{event:o,id:s,delay:i},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof o=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const _=typeof o=="function"?o(n,r):o;let u;if(typeof i=="string"){const d=c&&c[i];u=typeof d=="function"?d(n,r):d}else u=typeof i=="function"?i(n,r):i;return typeof u!="number"&&a.push(_),[t,{event:_,id:s,delay:u}]}function B_(e,t){const{event:n,delay:r,id:o}=t;if(typeof r=="number"){e.defer(()=>{const s=e.self;e.system.scheduler.schedule(s,s,n,r,o)});return}}function F_(e,t){function n(r,o){}return n.type="xstate.raise",n.event=e,n.id=t?.id,n.delay=t?.delay,n.resolve=M_,n.execute=B_,n}function H_(e,{machine:t,context:n},r,o){const s=(i,a={})=>{const{systemId:c,input:_}=a;if(typeof i=="string"){const u=dr(t,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${t.id}'`);const d=Fe(u,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:typeof _=="function"?_({context:n,event:r,self:e.self}):_,src:i,systemId:c});return o[d.id]=d,d}else return Fe(i,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:a.input,src:i,systemId:c})};return(i,a)=>{const c=s(i,a);return o[c.id]=c,e.defer(()=>{c._processingStatus!==gt.Stopped&&c.start()}),c}}function L_(e,t,n,r,{assignment:o}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const s={},i={context:t.context,event:n.event,spawn:H_(e,t,n.event,s),self:e.self,system:e.system};let a={};if(typeof o=="function")a=o(i,r);else for(const _ of Object.keys(o)){const u=o[_];a[_]=typeof u=="function"?u(i,r):u}const c=Object.assign({},t.context,a);return[oe(t,{context:c,children:Object.keys(s).length?{...t.children,...s}:t.children})]}function Sr(e){function t(n,r){}return t.type="xstate.assign",t.assignment=e,t.resolve=L_,t}function z_(e,t){const n=Vt(t);if(!n.includes(e.type)){const r=n.length===1?`type "${n[0]}"`:`one of types "${n.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(e)} to have ${r}`)}}const Rs=new WeakMap;function Se(e,t,n){let r=Rs.get(e);return r?t in r||(r[t]=n()):(r={[t]:n()},Rs.set(e,r)),r[t]}const N_={},Le=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class kr{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(os),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?_s(this.config.states,(r,o)=>new kr(r,{_parent:this,_key:o,_machine:this.machine})):N_,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=Vt(this.config.entry).slice(),this.exit=Vt(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=Vt(t.tags).slice()}_initialize(){this.transitions=l_(this),this.config.always&&(this.always=be(this.config.always).map(t=>ne(this,ss,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(Le),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Le),eventType:null})}:void 0,history:this.history,states:_s(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(Le)})),entry:this.entry.map(Le),exit:this.exit.map(Le),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Se(this,"invoke",()=>Vt(this.config.invoke).map((t,n)=>{const{src:r,systemId:o}=t,s=t.id??ls(this.id,n),i=typeof r=="string"?r:`xstate.invoke.${ls(this.id,n)}`;return{...t,src:i,id:s,systemId:o,toJSON(){const{onDone:a,onError:c,..._}=t;return{..._,type:"xstate.invoke",src:i,id:s}}}}))}get on(){return Se(this,"on",()=>[...this.transitions].flatMap(([t,n])=>n.map(r=>[t,r])).reduce((t,[n,r])=>(t[n]=t[n]||[],t[n].push(r),t),{}))}get after(){return Se(this,"delayedTransitions",()=>h_(this))}get initial(){return Se(this,"initial",()=>g_(this,this.config.initial))}next(t,n){const r=n.type,o=[];let s;const i=Se(this,`candidates-${r}`,()=>f_(this,r));for(const a of i){const{guard:c}=a,_=t.context;let u=!1;try{u=!c||hr(c,_,n,t)}catch(d){const g=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${g?`'${g}' `:""}in transition for event '${r}' in state node '${this.id}':
4
+ ${d.message}`)}if(u){o.push(...a.actions),s=a;break}}return s?[s]:void 0}get events(){return Se(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const r of Object.keys(t)){const o=t[r];if(o.states)for(const s of o.events)n.add(`${s}`)}return Array.from(n)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(r=>!(!r.target&&!r.actions.length&&!r.reenter))));return Array.from(t)}}const V_="#";class xr{constructor(t,n){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:n?.actors??{},actions:n?.actions??{},delays:n?.delays??{},guards:n?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new kr(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:r,actors:o,delays:s}=this.implementations;return new xr(this.config,{actions:{...n,...t.actions},guards:{...r,...t.guards},actors:{...o,...t.actors},delays:{...s,...t.delays}})}resolveState(t){const n=O_(this.root,t.value),r=gn(yn(this.root,n));return wn({_nodes:[...r],context:t.context||{},children:{},status:gr(r,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,r){return vr(t,n,r).snapshot}microstep(t,n,r){return vr(t,n,r).microstates}getTransitionData(t,n){return pr(this.root,t.value,t,n)||[]}getPreInitialState(t,n,r){const{context:o}=this.config,s=wn({context:typeof o!="function"&&o?o:{},_nodes:[this.root],children:{},status:"active"},this);return typeof o=="function"?ve(s,n,t,[Sr(({spawn:i,event:a,self:c})=>o({spawn:i,input:a.input,self:c}))],r):s}getInitialSnapshot(t,n){const r=as(n),o=[],s=this.getPreInitialState(t,r,o),i=wr([{target:[...Ss(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,r,!0,o),{snapshot:a}=vr(i,r,t,o);return a}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=cr(t),r=n.slice(1),o=pn(n[0])?n[0].slice(V_.length):n[0],s=this.idMap.get(o);if(!s)throw new Error(`Child state node '#${o}' does not exist on machine '${this.id}'`);return bn(s,r)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return D_(t,n)}restoreSnapshot(t,n){const r={},o=t.children;Object.keys(o).forEach(c=>{const _=o[c],u=_.snapshot,d=_.src,g=typeof d=="string"?dr(this,d):d;if(!g)return;const l=Fe(g,{id:c,parent:n.self,syncSnapshot:_.syncSnapshot,snapshot:u,src:d,systemId:_.systemId});r[c]=l});const s=wn({...t,children:r,_nodes:Array.from(gn(yn(this.root,t.value)))},this);let i=new Set;function a(c,_){if(!i.has(c)){i.add(c);for(let u in c){const d=c[u];if(d&&typeof d=="object"){if("xstate$$type"in d&&d.xstate$$type===fr){c[u]=_[d.id];continue}a(d,_)}}}}return a(s.context,r),s}}function J_(e,t){return new xr(e,t)}function K_({schemas:e,actors:t,actions:n,guards:r,delays:o}){return{createMachine:s=>J_({...s,schemas:e},{actors:t,actions:n,guards:r,delays:o})}}const W_={timeout:1/0};function q_(e,t,n){const r={...W_,...n};return new Promise((o,s)=>{const{signal:i}=r;if(i?.aborted){s(i.reason);return}let a=!1;const c=r.timeout===1/0?void 0:setTimeout(()=>{_(),s(new Error(`Timeout of ${r.timeout} ms exceeded`))},r.timeout),_=()=>{clearTimeout(c),a=!0,g?.unsubscribe(),d&&i.removeEventListener("abort",d)};function u(l){t(l)&&(_(),o(l))}let d,g;u(e.getSnapshot()),!a&&(i&&(d=()=>{_(),s(i.reason)},i.addEventListener("abort",d)),g=e.subscribe({next:u,error:l=>{_(),s(l)},complete:()=>{_(),s(new Error("Actor terminated without satisfying predicate"))}}),a&&g.unsubscribe())})}var qt={},Gt={},Rt={};Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.isBytes=Us,Rt.number=mn,Rt.bool=Ts,Rt.bytes=Ar,Rt.hash=$s,Rt.exists=Ps,Rt.output=Ds;function mn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Ts(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function Us(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Ar(e,...t){if(!Us(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function $s(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");mn(e.outputLen),mn(e.blockLen)}function Ps(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ds(e,t){Ar(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const G_={number:mn,bool:Ts,bytes:Ar,hash:$s,exists:Ps,output:Ds};Rt.default=G_;var Ir={},vn={};Object.defineProperty(vn,"__esModule",{value:!0}),vn.crypto=void 0,vn.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Hash=e.nextTick=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=void 0,e.isBytes=r,e.byteSwap32=u,e.bytesToHex=g,e.hexToBytes=x,e.asyncLoop=F,e.utf8ToBytes=B,e.toBytes=U,e.concatBytes=J,e.checkOpts=Q,e.wrapConstructor=Y,e.wrapConstructorWithOpts=st,e.wrapXOFConstructorWithOpts=nt,e.randomBytes=Bt;const t=vn,n=Rt;function r(R){return R instanceof Uint8Array||R!=null&&typeof R=="object"&&R.constructor.name==="Uint8Array"}const o=R=>new Uint8Array(R.buffer,R.byteOffset,R.byteLength);e.u8=o;const s=R=>new Uint32Array(R.buffer,R.byteOffset,Math.floor(R.byteLength/4));e.u32=s;const i=R=>new DataView(R.buffer,R.byteOffset,R.byteLength);e.createView=i;const a=(R,b)=>R<<32-b|R>>>b;e.rotr=a;const c=(R,b)=>R<<b|R>>>32-b>>>0;e.rotl=c,e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const _=R=>R<<24&4278190080|R<<8&16711680|R>>>8&65280|R>>>24&255;e.byteSwap=_,e.byteSwapIfBE=e.isLE?R=>R:R=>(0,e.byteSwap)(R);function u(R){for(let b=0;b<R.length;b++)R[b]=(0,e.byteSwap)(R[b])}const d=Array.from({length:256},(R,b)=>b.toString(16).padStart(2,"0"));function g(R){(0,n.bytes)(R);let b="";for(let D=0;D<R.length;D++)b+=d[R[D]];return b}const l={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function v(R){if(R>=l._0&&R<=l._9)return R-l._0;if(R>=l._A&&R<=l._F)return R-(l._A-10);if(R>=l._a&&R<=l._f)return R-(l._a-10)}function x(R){if(typeof R!="string")throw new Error("hex string expected, got "+typeof R);const b=R.length,D=b/2;if(b%2)throw new Error("padded hex string expected, got unpadded hex of length "+b);const I=new Uint8Array(D);for(let j=0,O=0;j<D;j++,O+=2){const N=v(R.charCodeAt(O)),V=v(R.charCodeAt(O+1));if(N===void 0||V===void 0){const K=R[O]+R[O+1];throw new Error('hex string expected, got non-hex character "'+K+'" at index '+O)}I[j]=N*16+V}return I}const M=async()=>{};e.nextTick=M;async function F(R,b,D){let I=Date.now();for(let j=0;j<R;j++){D(j);const O=Date.now()-I;O>=0&&O<b||(await(0,e.nextTick)(),I+=O)}}function B(R){if(typeof R!="string")throw new Error(`utf8ToBytes expected string, got ${typeof R}`);return new Uint8Array(new TextEncoder().encode(R))}function U(R){return typeof R=="string"&&(R=B(R)),(0,n.bytes)(R),R}function J(...R){let b=0;for(let I=0;I<R.length;I++){const j=R[I];(0,n.bytes)(j),b+=j.length}const D=new Uint8Array(b);for(let I=0,j=0;I<R.length;I++){const O=R[I];D.set(O,j),j+=O.length}return D}class W{clone(){return this._cloneInto()}}e.Hash=W;const z={}.toString;function Q(R,b){if(b!==void 0&&z.call(b)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(R,b)}function Y(R){const b=I=>R().update(U(I)).digest(),D=R();return b.outputLen=D.outputLen,b.blockLen=D.blockLen,b.create=()=>R(),b}function st(R){const b=(I,j)=>R(j).update(U(I)).digest(),D=R({});return b.outputLen=D.outputLen,b.blockLen=D.blockLen,b.create=I=>R(I),b}function nt(R){const b=(I,j)=>R(j).update(U(I)).digest(),D=R({});return b.outputLen=D.outputLen,b.blockLen=D.blockLen,b.create=I=>R(I),b}function Bt(R=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(R));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(R);throw new Error("crypto.getRandomValues must be defined")}}(Ir),Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.HashMD=Gt.Maj=Gt.Chi=void 0;const Cr=Rt,ze=Ir;function Z_(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),a=Number(n&s),c=r?4:0,_=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+_,a,r)}const Y_=(e,t,n)=>e&t^~e&n;Gt.Chi=Y_;const X_=(e,t,n)=>e&t^e&n^t&n;Gt.Maj=X_;class Q_ extends ze.Hash{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,ze.createView)(this.buffer)}update(t){(0,Cr.exists)(this);const{view:n,buffer:r,blockLen:o}=this;t=(0,ze.toBytes)(t);const s=t.length;for(let i=0;i<s;){const a=Math.min(o-this.pos,s-i);if(a===o){const c=(0,ze.createView)(t);for(;o<=s-i;i+=o)this.process(c,i);continue}r.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Cr.exists)(this),(0,Cr.output)(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let d=i;d<o;d++)n[d]=0;Z_(r,o-8,BigInt(this.length*8),s),this.process(r,0);const a=(0,ze.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const _=c/4,u=this.get();if(_>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<_;d++)a.setUint32(4*d,u[d],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%n&&t.buffer.set(r),t}}Gt.HashMD=Q_,Object.defineProperty(qt,"__esModule",{value:!0}),qt.sha224=qt.sha256=qt.SHA256=void 0;const Er=Gt,At=Ir,td=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yt=new Uint32Array(64);class Or extends Er.HashMD{constructor(){super(64,32,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:a,H:c}=this;return[t,n,r,o,s,i,a,c]}set(t,n,r,o,s,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let d=0;d<16;d++,n+=4)Yt[d]=t.getUint32(n,!1);for(let d=16;d<64;d++){const g=Yt[d-15],l=Yt[d-2],v=(0,At.rotr)(g,7)^(0,At.rotr)(g,18)^g>>>3,x=(0,At.rotr)(l,17)^(0,At.rotr)(l,19)^l>>>10;Yt[d]=x+Yt[d-7]+v+Yt[d-16]|0}let{A:r,B:o,C:s,D:i,E:a,F:c,G:_,H:u}=this;for(let d=0;d<64;d++){const g=(0,At.rotr)(a,6)^(0,At.rotr)(a,11)^(0,At.rotr)(a,25),l=u+g+(0,Er.Chi)(a,c,_)+td[d]+Yt[d]|0,v=((0,At.rotr)(r,2)^(0,At.rotr)(r,13)^(0,At.rotr)(r,22))+(0,Er.Maj)(r,o,s)|0;u=_,_=c,c=a,a=i+l|0,i=s,s=o,o=r,r=l+v|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,_=_+this.G|0,u=u+this.H|0,this.set(r,o,s,i,a,c,_,u)}roundClean(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}qt.SHA256=Or;class ed extends Or{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}qt.sha256=(0,At.wrapConstructor)(()=>new Or),qt.sha224=(0,At.wrapConstructor)(()=>new ed);function nd(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var r=0;r<e.length;r++){var o=e.charAt(r),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=r}var i=e.length,a=e.charAt(0),c=Math.log(i)/Math.log(256),_=Math.log(256)/Math.log(i);function u(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var v=0,x=0,M=0,F=l.length;M!==F&&l[M]===0;)M++,v++;for(var B=(F-M)*_+1>>>0,U=new Uint8Array(B);M!==F;){for(var J=l[M],W=0,z=B-1;(J!==0||W<x)&&z!==-1;z--,W++)J+=256*U[z]>>>0,U[z]=J%i>>>0,J=J/i>>>0;if(J!==0)throw new Error("Non-zero carry");x=W,M++}for(var Q=B-x;Q!==B&&U[Q]===0;)Q++;for(var Y=a.repeat(v);Q<B;++Q)Y+=e.charAt(U[Q]);return Y}function d(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;for(var v=0,x=0,M=0;l[v]===a;)x++,v++;for(var F=(l.length-v)*c+1>>>0,B=new Uint8Array(F);l[v];){var U=t[l.charCodeAt(v)];if(U===255)return;for(var J=0,W=F-1;(U!==0||J<M)&&W!==-1;W--,J++)U+=i*B[W]>>>0,B[W]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");M=J,v++}for(var z=F-M;z!==F&&B[z]===0;)z++;for(var Q=new Uint8Array(x+(F-z)),Y=x;z!==F;)Q[Y++]=B[z++];return Q}function g(l){var v=d(l);if(v)return v;throw new Error("Non-base"+i+" character")}return{encode:u,decodeUnsafe:d,decode:g}}var rd=nd,od=rd("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),jr=od,sd=function(e){function t(s){var i=Uint8Array.from(s),a=e(i),c=i.length+4,_=new Uint8Array(c);return _.set(i,0),_.set(a.subarray(0,4),i.length),jr.encode(_,c)}function n(s){var i=s.slice(0,-4),a=s.slice(-4),c=e(i);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return i}function r(s){var i=jr.decodeUnsafe(s);if(i)return n(i)}function o(s){var i=jr.decode(s),a=n(i);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:o,decodeUnsafe:r}},{sha256:Ms}=qt,id=sd;function ad(e){return Ms(Ms(e))}var cd=id(ad);const Bs=ln(cd),Rr="automerge:",Tr=e=>{const t=new RegExp(`^${Rr}(\\w+)$`),[,n]=e.match(t)||[],r=n,o=Hs(r);if(!o)throw new Error("Invalid document URL: "+e);return{binaryDocumentId:o,documentId:r}},Ur=e=>{const t=e instanceof Uint8Array||typeof e=="string"?e:"documentId"in e?e.documentId:void 0,n=t instanceof Uint8Array?$r(t):typeof t=="string"?t:void 0;if(n===void 0)throw new Error("Invalid documentId: "+t);return Rr+n},ud=e=>{if(typeof e!="string"||!e||!e.startsWith(Rr))return!1;const t=e;try{const{documentId:n}=Tr(t);return Fs(n)}catch{return!1}},Fs=e=>{if(typeof e!="string")return!1;const t=Hs(e);if(t===void 0)return!1;const n=Oc(t);return an(n)},_d=e=>typeof e=="string"&&an(e),dd=()=>{const e=xo(null,new Uint8Array(16));return Ur({documentId:e})},Hs=e=>Bs.decodeUnsafe(e),$r=e=>Bs.encode(e),Pr=e=>{if(e instanceof Uint8Array)return $r(e);if(ud(e))return Tr(e).documentId;if(Fs(e))return e;if(_d(e)){console.warn("Future versions will not support UUIDs as document IDs; use Automerge URLs instead.");const t=jc(e);return $r(t)}throw new Error(`Invalid AutomergeUrl: '${e}'`)};let Dr;try{Dr=new TextDecoder}catch{}let H,se,A=0;const fd=105,hd=57342,ld=57343,Ls=57337,zs=6,ke={};let Ne=11281e4,Jt=1681e4,G={},it,Sn,kn=0,Ve=0,ct,It,at=[],Mr=[],wt,pt,Je,Ns={useRecords:!1,mapsAsObjects:!0},Ke=!1,Vs=2;try{new Function("")}catch{Vs=1/0}class We{constructor(t){if(t&&((t.keyMap||t._keyMap)&&!t.useRecords&&(t.useRecords=!1,t.mapsAsObjects=!0),t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.getStructures&&(t.getShared=t.getStructures),t.getShared&&!t.structures&&((t.structures=[]).uninitialized=!0),t.keyMap)){this.mapKey=new Map;for(let[n,r]of Object.entries(t.keyMap))this.mapKey.set(r,n)}Object.assign(this,t)}decodeKey(t){return this.keyMap&&this.mapKey.get(t)||t}encodeKey(t){return this.keyMap&&this.keyMap.hasOwnProperty(t)?this.keyMap[t]:t}encodeKeys(t){if(!this._keyMap)return t;let n=new Map;for(let[r,o]of Object.entries(t))n.set(this._keyMap.hasOwnProperty(r)?this._keyMap[r]:r,o);return n}decodeKeys(t){if(!this._keyMap||t.constructor.name!="Map")return t;if(!this._mapKey){this._mapKey=new Map;for(let[r,o]of Object.entries(this._keyMap))this._mapKey.set(o,r)}let n={};return t.forEach((r,o)=>n[Ct(this._mapKey.has(o)?this._mapKey.get(o):o)]=r),n}mapDecode(t,n){let r=this.decode(t);if(this._keyMap)switch(r.constructor.name){case"Array":return r.map(o=>this.decodeKeys(o))}return r}decode(t,n){if(H)return Zs(()=>(zr(),this?this.decode(t,n):We.prototype.decode.call(Ns,t,n)));se=n>-1?n:t.length,A=0,Ve=0,Sn=null,ct=null,H=t;try{pt=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(r){throw H=null,t instanceof Uint8Array?r:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof We){if(G=this,wt=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return it=this.structures,xn();(!it||it.length>0)&&(it=[])}else G=Ns,(!it||it.length>0)&&(it=[]),wt=null;return xn()}decodeMultiple(t,n){let r,o=0;try{let s=t.length;Ke=!0;let i=this?this.decode(t,s):Vr.decode(t,s);if(n){if(n(i)===!1)return;for(;A<s;)if(o=A,n(xn())===!1)return}else{for(r=[i];A<s;)o=A,r.push(xn());return r}}catch(s){throw s.lastPosition=o,s.values=r,s}finally{Ke=!1,zr()}}}function xn(){try{let e=Z();if(ct){if(A>=ct.postBundlePosition){let t=new Error("Unexpected bundle position");throw t.incomplete=!0,t}A=ct.postBundlePosition,ct=null}if(A==se)it=null,H=null,It&&(It=null);else if(A>se){let t=new Error("Unexpected end of CBOR data");throw t.incomplete=!0,t}else if(!Ke)throw new Error("Data read, but end of buffer not reached");return e}catch(e){throw zr(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function Z(){let e=H[A++],t=e>>5;if(e=e&31,e>23)switch(e){case 24:e=H[A++];break;case 25:if(t==7)return yd();e=pt.getUint16(A),A+=2;break;case 26:if(t==7){let n=pt.getFloat32(A);if(G.useFloat32>2){let r=Nr[(H[A]&127)<<1|H[A+1]>>7];return A+=4,(r*n+(n>0?.5:-.5)>>0)/r}return A+=4,n}e=pt.getUint32(A),A+=4;break;case 27:if(t==7){let n=pt.getFloat64(A);return A+=8,n}if(t>1){if(pt.getUint32(A)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");e=pt.getUint32(A+4)}else G.int64AsNumber?(e=pt.getUint32(A)*4294967296,e+=pt.getUint32(A+4)):e=pt.getBigUint64(A);A+=8;break;case 31:switch(t){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let n=[],r,o=0;for(;(r=Z())!=ke;){if(o>=Ne)throw new Error(`Array length exceeds ${Ne}`);n[o++]=r}return t==4?n:t==3?n.join(""):Buffer.concat(n);case 5:let s;if(G.mapsAsObjects){let i={},a=0;if(G.keyMap)for(;(s=Z())!=ke;){if(a++>=Jt)throw new Error(`Property count exceeds ${Jt}`);i[Ct(G.decodeKey(s))]=Z()}else for(;(s=Z())!=ke;){if(a++>=Jt)throw new Error(`Property count exceeds ${Jt}`);i[Ct(s)]=Z()}return i}else{Je&&(G.mapsAsObjects=!0,Je=!1);let i=new Map;if(G.keyMap){let a=0;for(;(s=Z())!=ke;){if(a++>=Jt)throw new Error(`Map size exceeds ${Jt}`);i.set(G.decodeKey(s),Z())}}else{let a=0;for(;(s=Z())!=ke;){if(a++>=Jt)throw new Error(`Map size exceeds ${Jt}`);i.set(s,Z())}}return i}case 7:return ke;default:throw new Error("Invalid major type for indefinite length "+t)}default:throw new Error("Unknown token "+e)}switch(t){case 0:return e;case 1:return~e;case 2:return bd(e);case 3:if(Ve>=A)return Sn.slice(A-kn,(A+=e)-kn);if(Ve==0&&se<140&&e<32){let o=e<16?Ks(e):pd(e);if(o!=null)return o}return gd(e);case 4:if(e>=Ne)throw new Error(`Array length exceeds ${Ne}`);let n=new Array(e);for(let o=0;o<e;o++)n[o]=Z();return n;case 5:if(e>=Jt)throw new Error(`Map size exceeds ${Ne}`);if(G.mapsAsObjects){let o={};if(G.keyMap)for(let s=0;s<e;s++)o[Ct(G.decodeKey(Z()))]=Z();else for(let s=0;s<e;s++)o[Ct(Z())]=Z();return o}else{Je&&(G.mapsAsObjects=!0,Je=!1);let o=new Map;if(G.keyMap)for(let s=0;s<e;s++)o.set(G.decodeKey(Z()),Z());else for(let s=0;s<e;s++)o.set(Z(),Z());return o}case 6:if(e>=Ls){let o=it[e&8191];if(o)return o.read||(o.read=Br(o)),o.read();if(e<65536){if(e==ld){let s=Ae(),i=Z(),a=Z();Hr(i,a);let c={};if(G.keyMap)for(let _=2;_<s;_++){let u=G.decodeKey(a[_-2]);c[Ct(u)]=Z()}else for(let _=2;_<s;_++){let u=a[_-2];c[Ct(u)]=Z()}return c}else if(e==hd){let s=Ae(),i=Z();for(let a=2;a<s;a++)Hr(i++,Z());return Z()}else if(e==Ls)return xd();if(G.getShared&&(Lr(),o=it[e&8191],o))return o.read||(o.read=Br(o)),o.read()}}let r=at[e];if(r)return r.handlesRead?r(Z):r(Z());{let o=Z();for(let s=0;s<Mr.length;s++){let i=Mr[s](e,o);if(i!==void 0)return i}return new ie(o,e)}case 7:switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;case 31:default:let o=(wt||ae())[e];if(o!==void 0)return o;throw new Error("Unknown token "+e)}default:if(isNaN(e)){let o=new Error("Unexpected end of CBOR data");throw o.incomplete=!0,o}throw new Error("Unknown CBOR token "+e)}}const Js=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Br(e){if(!e)throw new Error("Structure is required in record definition");function t(){let n=H[A++];if(n=n&31,n>23)switch(n){case 24:n=H[A++];break;case 25:n=pt.getUint16(A),A+=2;break;case 26:n=pt.getUint32(A),A+=4;break;default:throw new Error("Expected array header, but got "+H[A-1])}let r=this.compiledReader;for(;r;){if(r.propertyCount===n)return r(Z);r=r.next}if(this.slowReads++>=Vs){let s=this.length==n?this:this.slice(0,n);return r=G.keyMap?new Function("r","return {"+s.map(i=>G.decodeKey(i)).map(i=>Js.test(i)?Ct(i)+":r()":"["+JSON.stringify(i)+"]:r()").join(",")+"}"):new Function("r","return {"+s.map(i=>Js.test(i)?Ct(i)+":r()":"["+JSON.stringify(i)+"]:r()").join(",")+"}"),this.compiledReader&&(r.next=this.compiledReader),r.propertyCount=n,this.compiledReader=r,r(Z)}let o={};if(G.keyMap)for(let s=0;s<n;s++)o[Ct(G.decodeKey(this[s]))]=Z();else for(let s=0;s<n;s++)o[Ct(this[s])]=Z();return o}return e.slowReads=0,t}function Ct(e){if(typeof e=="string")return e==="__proto__"?"__proto_":e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return e.toString();if(e==null)return e+"";throw new Error("Invalid property name type "+typeof e)}let gd=Fr;function Fr(e){let t;if(e<16&&(t=Ks(e)))return t;if(e>64&&Dr)return Dr.decode(H.subarray(A,A+=e));const n=A+e,r=[];for(t="";A<n;){const o=H[A++];if(!(o&128))r.push(o);else if((o&224)===192){const s=H[A++]&63;r.push((o&31)<<6|s)}else if((o&240)===224){const s=H[A++]&63,i=H[A++]&63;r.push((o&31)<<12|s<<6|i)}else if((o&248)===240){const s=H[A++]&63,i=H[A++]&63,a=H[A++]&63;let c=(o&7)<<18|s<<12|i<<6|a;c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|c&1023),r.push(c)}else r.push(o);r.length>=4096&&(t+=dt.apply(String,r),r.length=0)}return r.length>0&&(t+=dt.apply(String,r)),t}let dt=String.fromCharCode;function pd(e){let t=A,n=new Array(e);for(let r=0;r<e;r++){const o=H[A++];if((o&128)>0){A=t;return}n[r]=o}return dt.apply(String,n)}function Ks(e){if(e<4)if(e<2){if(e===0)return"";{let t=H[A++];if((t&128)>1){A-=1;return}return dt(t)}}else{let t=H[A++],n=H[A++];if((t&128)>0||(n&128)>0){A-=2;return}if(e<3)return dt(t,n);let r=H[A++];if((r&128)>0){A-=3;return}return dt(t,n,r)}else{let t=H[A++],n=H[A++],r=H[A++],o=H[A++];if((t&128)>0||(n&128)>0||(r&128)>0||(o&128)>0){A-=4;return}if(e<6){if(e===4)return dt(t,n,r,o);{let s=H[A++];if((s&128)>0){A-=5;return}return dt(t,n,r,o,s)}}else if(e<8){let s=H[A++],i=H[A++];if((s&128)>0||(i&128)>0){A-=6;return}if(e<7)return dt(t,n,r,o,s,i);let a=H[A++];if((a&128)>0){A-=7;return}return dt(t,n,r,o,s,i,a)}else{let s=H[A++],i=H[A++],a=H[A++],c=H[A++];if((s&128)>0||(i&128)>0||(a&128)>0||(c&128)>0){A-=8;return}if(e<10){if(e===8)return dt(t,n,r,o,s,i,a,c);{let _=H[A++];if((_&128)>0){A-=9;return}return dt(t,n,r,o,s,i,a,c,_)}}else if(e<12){let _=H[A++],u=H[A++];if((_&128)>0||(u&128)>0){A-=10;return}if(e<11)return dt(t,n,r,o,s,i,a,c,_,u);let d=H[A++];if((d&128)>0){A-=11;return}return dt(t,n,r,o,s,i,a,c,_,u,d)}else{let _=H[A++],u=H[A++],d=H[A++],g=H[A++];if((_&128)>0||(u&128)>0||(d&128)>0||(g&128)>0){A-=12;return}if(e<14){if(e===12)return dt(t,n,r,o,s,i,a,c,_,u,d,g);{let l=H[A++];if((l&128)>0){A-=13;return}return dt(t,n,r,o,s,i,a,c,_,u,d,g,l)}}else{let l=H[A++],v=H[A++];if((l&128)>0||(v&128)>0){A-=14;return}if(e<15)return dt(t,n,r,o,s,i,a,c,_,u,d,g,l,v);let x=H[A++];if((x&128)>0){A-=15;return}return dt(t,n,r,o,s,i,a,c,_,u,d,g,l,v,x)}}}}}function bd(e){return G.copyBuffers?Uint8Array.prototype.slice.call(H,A,A+=e):H.subarray(A,A+=e)}let Ws=new Float32Array(1),An=new Uint8Array(Ws.buffer,0,4);function yd(){let e=H[A++],t=H[A++],n=(e&127)>>2;if(n===31)return t||e&3?NaN:e&128?-1/0:1/0;if(n===0){let r=((e&3)<<8|t)/16777216;return e&128?-r:r}return An[3]=e&128|(n>>1)+56,An[2]=(e&7)<<5|t>>3,An[1]=t<<5,An[0]=0,Ws[0]}new Array(4096);class ie{constructor(t,n){this.value=t,this.tag=n}}at[0]=e=>new Date(e),at[1]=e=>new Date(Math.round(e*1e3)),at[2]=e=>{let t=BigInt(0);for(let n=0,r=e.byteLength;n<r;n++)t=BigInt(e[n])+(t<<BigInt(8));return t},at[3]=e=>BigInt(-1)-at[2](e),at[4]=e=>+(e[1]+"e"+e[0]),at[5]=e=>e[1]*Math.exp(e[0]*Math.log(2));const Hr=(e,t)=>{e=e-57344;let n=it[e];n&&n.isShared&&((it.restoreStructures||(it.restoreStructures=[]))[e]=n),it[e]=t,t.read=Br(t)};at[fd]=e=>{let t=e.length,n=e[1];Hr(e[0],n);let r={};for(let o=2;o<t;o++){let s=n[o-2];r[Ct(s)]=e[o]}return r},at[14]=e=>ct?ct[0].slice(ct.position0,ct.position0+=e):new ie(e,14),at[15]=e=>ct?ct[1].slice(ct.position1,ct.position1+=e):new ie(e,15);let wd={Error,RegExp};at[27]=e=>(wd[e[0]]||Error)(e[1],e[2]);const qs=e=>{if(H[A++]!=132){let n=new Error("Packed values structure must be followed by a 4 element array");throw H.length<A&&(n.incomplete=!0),n}let t=e();if(!t||!t.length){let n=new Error("Packed values structure must be followed by a 4 element array");throw n.incomplete=!0,n}return wt=wt?t.concat(wt.slice(t.length)):t,wt.prefixes=e(),wt.suffixes=e(),e()};qs.handlesRead=!0,at[51]=qs,at[zs]=e=>{if(!wt)if(G.getShared)Lr();else return new ie(e,zs);if(typeof e=="number")return wt[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");throw e===void 0&&(t.incomplete=!0),t},at[28]=e=>{It||(It=new Map,It.id=0);let t=It.id++,n=A,r=H[A],o;r>>5==4?o=[]:o={};let s={target:o};It.set(t,s);let i=e();return s.used?(Object.getPrototypeOf(o)!==Object.getPrototypeOf(i)&&(A=n,o=i,It.set(t,{target:o}),i=e()),Object.assign(o,i)):(s.target=i,i)},at[28].handlesRead=!0,at[29]=e=>{let t=It.get(e);return t.used=!0,t.target},at[258]=e=>new Set(e),(at[259]=e=>(G.mapsAsObjects&&(G.mapsAsObjects=!1,Je=!0),e())).handlesRead=!0;function xe(e,t){return typeof e=="string"?e+t:e instanceof Array?e.concat(t):Object.assign({},e,t)}function ae(){if(!wt)if(G.getShared)Lr();else throw new Error("No packed values available");return wt}const md=1399353956;Mr.push((e,t)=>{if(e>=225&&e<=255)return xe(ae().prefixes[e-224],t);if(e>=28704&&e<=32767)return xe(ae().prefixes[e-28672],t);if(e>=1879052288&&e<=2147483647)return xe(ae().prefixes[e-1879048192],t);if(e>=216&&e<=223)return xe(t,ae().suffixes[e-216]);if(e>=27647&&e<=28671)return xe(t,ae().suffixes[e-27639]);if(e>=1811940352&&e<=1879048191)return xe(t,ae().suffixes[e-1811939328]);if(e==md)return{packedValues:wt,structures:it.slice(0),version:t};if(e==55799)return t});const vd=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,Gs=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],Sd=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e<Gs.length;e++)kd(Gs[e],Sd[e]);function kd(e,t){let n="get"+e.name.slice(0,-5),r;typeof e=="function"?r=e.BYTES_PER_ELEMENT:e=null;for(let o=0;o<2;o++){if(!o&&r==1)continue;let s=r==2?1:r==4?2:r==8?3:0;at[o?t:t-4]=r==1||o==vd?i=>{if(!e)throw new Error("Could not find typed array for code "+t);return!G.copyBuffers&&(r===1||r===2&&!(i.byteOffset&1)||r===4&&!(i.byteOffset&3)||r===8&&!(i.byteOffset&7))?new e(i.buffer,i.byteOffset,i.byteLength>>s):new e(Uint8Array.prototype.slice.call(i,0).buffer)}:i=>{if(!e)throw new Error("Could not find typed array for code "+t);let a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=i.length>>s,_=new e(c),u=a[n];for(let d=0;d<c;d++)_[d]=u.call(a,d<<s,o);return _}}}function xd(){let e=Ae(),t=A+Z();for(let r=2;r<e;r++){let o=Ae();A+=o}let n=A;return A=t,ct=[Fr(Ae()),Fr(Ae())],ct.position0=0,ct.position1=0,ct.postBundlePosition=A,A=n,Z()}function Ae(){let e=H[A++]&31;if(e>23)switch(e){case 24:e=H[A++];break;case 25:e=pt.getUint16(A),A+=2;break;case 26:e=pt.getUint32(A),A+=4;break}return e}function Lr(){if(G.getShared){let e=Zs(()=>(H=null,G.getShared()))||{},t=e.structures||[];G.sharedVersion=e.version,wt=G.sharedValues=e.packedValues,it===!0?G.structures=it=t:it.splice.apply(it,[0,t.length].concat(t))}}function Zs(e){let t=se,n=A,r=kn,o=Ve,s=Sn,i=It,a=ct,c=new Uint8Array(H.slice(0,se)),_=it,u=G,d=Ke,g=e();return se=t,A=n,kn=r,Ve=o,Sn=s,It=i,ct=a,H=c,Ke=d,it=_,G=u,pt=new DataView(H.buffer,H.byteOffset,H.byteLength),g}function zr(){H=null,It=null,it=null}const Nr=new Array(147);for(let e=0;e<256;e++)Nr[e]=+("1e"+Math.floor(45.15-e*.30103));let Vr=new We({useRecords:!1});const Ad=Vr.decode;Vr.decodeMultiple;let In;try{In=new TextEncoder}catch{}let Jr,Ys;const Cn=typeof globalThis=="object"&&globalThis.Buffer,qe=typeof Cn<"u",Kr=qe?Cn.allocUnsafeSlow:Uint8Array,Xs=qe?Cn:Uint8Array,Qs=256,ti=qe?4294967296:2144337920;let Wr,m,rt,p=0,Xt,ut=null;const Id=61440,Cd=/[\u0080-\uFFFF]/,vt=Symbol("record-id");class ei extends We{constructor(t){super(t),this.offset=0;let n,r,o,s,i;t=t||{};let a=Xs.prototype.utf8Write?function(b,D,I){return m.utf8Write(b,D,I)}:In&&In.encodeInto?function(b,D){return In.encodeInto(b,m.subarray(D)).written}:!1,c=this,_=t.structures||t.saveStructures,u=t.maxSharedStructures;if(u==null&&(u=_?128:0),u>8190)throw new Error("Maximum maxSharedStructure is 8190");let d=t.sequential;d&&(u=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let g,l,v=t.sharedValues,x;if(v){x=Object.create(null);for(let b=0,D=v.length;b<D;b++)x[v[b]]=b}let M=[],F=0,B=0;this.mapEncode=function(b,D){if(this._keyMap&&!this._mapped)switch(b.constructor.name){case"Array":b=b.map(I=>this.encodeKeys(I));break}return this.encode(b,D)},this.encode=function(b,D){if(m||(m=new Kr(8192),rt=new DataView(m.buffer,0,8192),p=0),Xt=m.length-10,Xt-p<2048?(m=new Kr(m.length),rt=new DataView(m.buffer,0,m.length),Xt=m.length-10,p=0):D===si&&(p=p+7&2147483640),n=p,c.useSelfDescribedHeader&&(rt.setUint32(p,3654940416),p+=3),i=c.structuredClone?new Map:null,c.bundleStrings&&typeof b!="string"?(ut=[],ut.size=1/0):ut=null,r=c.structures,r){if(r.uninitialized){let j=c.getShared()||{};c.structures=r=j.structures||[],c.sharedVersion=j.version;let O=c.sharedValues=j.packedValues;if(O){x={};for(let N=0,V=O.length;N<V;N++)x[O[N]]=N}}let I=r.length;if(I>u&&!d&&(I=u),!r.transitions){r.transitions=Object.create(null);for(let j=0;j<I;j++){let O=r[j];if(!O)continue;let N,V=r.transitions;for(let K=0,q=O.length;K<q;K++){V[vt]===void 0&&(V[vt]=j);let X=O[K];N=V[X],N||(N=V[X]=Object.create(null)),V=N}V[vt]=j|1048576}}d||(r.nextId=I)}if(o&&(o=!1),s=r||[],l=x,t.pack){let I=new Map;if(I.values=[],I.encoder=c,I.maxValues=t.maxPrivatePackedValues||(x?16:1/0),I.objectMap=x||!1,I.samplingPackedValues=g,En(b,I),I.values.length>0){m[p++]=216,m[p++]=51,$t(4);let j=I.values;U(j),$t(0),$t(0),l=Object.create(x||null);for(let O=0,N=j.length;O<N;O++)l[j[O]]=O}}Wr=D&Yr;try{if(Wr)return;if(U(b),ut&&oi(n,U),c.offset=p,i&&i.idsToInsert){p+=i.idsToInsert.length*2,p>Xt&&W(p),c.offset=p;let I=jd(m.subarray(n,p),i.idsToInsert);return i=null,I}return D&si?(m.start=n,m.end=p,m):m.subarray(n,p)}finally{if(r){if(B<10&&B++,r.length>u&&(r.length=u),F>1e4)r.transitions=null,B=0,F=0,M.length>0&&(M=[]);else if(M.length>0&&!d){for(let I=0,j=M.length;I<j;I++)M[I][vt]=void 0;M=[]}}if(o&&c.saveShared){c.structures.length>u&&(c.structures=c.structures.slice(0,u));let I=m.subarray(n,p);return c.updateSharedData()===!1?c.encode(b):I}D&Rd&&(p=n)}},this.findCommonStringsToPack=()=>(g=new Map,x||(x=Object.create(null)),b=>{let D=b&&b.threshold||4,I=this.pack?b.maxPrivatePackedValues||16:0;v||(v=this.sharedValues=[]);for(let[j,O]of g)O.count>D&&(x[j]=I++,v.push(j),o=!0);for(;this.saveShared&&this.updateSharedData()===!1;);g=null});const U=b=>{p>Xt&&(m=W(p));var D=typeof b,I;if(D==="string"){if(l){let V=l[b];if(V>=0){V<16?m[p++]=V+224:(m[p++]=198,V&1?U(15-V>>1):U(V-16>>1));return}else if(g&&!t.pack){let K=g.get(b);K?K.count++:g.set(b,{count:1})}}let j=b.length;if(ut&&j>=4&&j<1024){if((ut.size+=j)>Id){let K,q=(ut[0]?ut[0].length*3+ut[1].length:0)+10;p+q>Xt&&(m=W(p+q)),m[p++]=217,m[p++]=223,m[p++]=249,m[p++]=ut.position?132:130,m[p++]=26,K=p-n,p+=4,ut.position&&oi(n,U),ut=["",""],ut.size=0,ut.position=K}let V=Cd.test(b);ut[V?0:1]+=b,m[p++]=V?206:207,U(j);return}let O;j<32?O=1:j<256?O=2:j<65536?O=3:O=5;let N=j*3;if(p+N>Xt&&(m=W(p+N)),j<64||!a){let V,K,q,X=p+O;for(V=0;V<j;V++)K=b.charCodeAt(V),K<128?m[X++]=K:K<2048?(m[X++]=K>>6|192,m[X++]=K&63|128):(K&64512)===55296&&((q=b.charCodeAt(V+1))&64512)===56320?(K=65536+((K&1023)<<10)+(q&1023),V++,m[X++]=K>>18|240,m[X++]=K>>12&63|128,m[X++]=K>>6&63|128,m[X++]=K&63|128):(m[X++]=K>>12|224,m[X++]=K>>6&63|128,m[X++]=K&63|128);I=X-p-O}else I=a(b,p+O,N);I<24?m[p++]=96|I:I<256?(O<2&&m.copyWithin(p+2,p+1,p+1+I),m[p++]=120,m[p++]=I):I<65536?(O<3&&m.copyWithin(p+3,p+2,p+2+I),m[p++]=121,m[p++]=I>>8,m[p++]=I&255):(O<5&&m.copyWithin(p+5,p+3,p+3+I),m[p++]=122,rt.setUint32(p,I),p+=4),p+=I}else if(D==="number")if(!this.alwaysUseFloat&&b>>>0===b)b<24?m[p++]=b:b<256?(m[p++]=24,m[p++]=b):b<65536?(m[p++]=25,m[p++]=b>>8,m[p++]=b&255):(m[p++]=26,rt.setUint32(p,b),p+=4);else if(!this.alwaysUseFloat&&b>>0===b)b>=-24?m[p++]=31-b:b>=-256?(m[p++]=56,m[p++]=~b):b>=-65536?(m[p++]=57,rt.setUint16(p,~b),p+=2):(m[p++]=58,rt.setUint32(p,~b),p+=4);else{let j;if((j=this.useFloat32)>0&&b<4294967296&&b>=-2147483648){m[p++]=250,rt.setFloat32(p,b);let O;if(j<4||(O=b*Nr[(m[p]&127)<<1|m[p+1]>>7])>>0===O){p+=4;return}else p--}m[p++]=251,rt.setFloat64(p,b),p+=8}else if(D==="object")if(!b)m[p++]=246;else{if(i){let O=i.get(b);if(O){if(m[p++]=216,m[p++]=29,m[p++]=25,!O.references){let N=i.idsToInsert||(i.idsToInsert=[]);O.references=[],N.push(O)}O.references.push(p-n),p+=2;return}else i.set(b,{offset:p-n})}let j=b.constructor;if(j===Object)J(b);else if(j===Array){I=b.length,I<24?m[p++]=128|I:$t(I);for(let O=0;O<I;O++)U(b[O])}else if(j===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(m[p++]=217,m[p++]=1,m[p++]=3),I=b.size,I<24?m[p++]=160|I:I<256?(m[p++]=184,m[p++]=I):I<65536?(m[p++]=185,m[p++]=I>>8,m[p++]=I&255):(m[p++]=186,rt.setUint32(p,I),p+=4),c.keyMap)for(let[O,N]of b)U(c.encodeKey(O)),U(N);else for(let[O,N]of b)U(O),U(N);else{for(let O=0,N=Jr.length;O<N;O++){let V=Ys[O];if(b instanceof V){let K=Jr[O],q=K.tag;q==null&&(q=K.getTag&&K.getTag.call(this,b)),q<24?m[p++]=192|q:q<256?(m[p++]=216,m[p++]=q):q<65536?(m[p++]=217,m[p++]=q>>8,m[p++]=q&255):q>-1&&(m[p++]=218,rt.setUint32(p,q),p+=4),K.encode.call(this,b,U,W);return}}if(b[Symbol.iterator]){if(Wr){let O=new Error("Iterable should be serialized as iterator");throw O.iteratorNotHandled=!0,O}m[p++]=159;for(let O of b)U(O);m[p++]=255;return}if(b[Symbol.asyncIterator]||qr(b)){let O=new Error("Iterable/blob should be serialized as iterator");throw O.iteratorNotHandled=!0,O}if(this.useToJSON&&b.toJSON){const O=b.toJSON();if(O!==b)return U(O)}J(b)}}else if(D==="boolean")m[p++]=b?245:244;else if(D==="bigint"){if(b<BigInt(1)<<BigInt(64)&&b>=0)m[p++]=27,rt.setBigUint64(p,b);else if(b>-(BigInt(1)<<BigInt(64))&&b<0)m[p++]=59,rt.setBigUint64(p,-b-BigInt(1));else if(this.largeBigIntToFloat)m[p++]=251,rt.setFloat64(p,Number(b));else{b>=BigInt(0)?m[p++]=194:(m[p++]=195,b=BigInt(-1)-b);let j=[];for(;b;)j.push(Number(b&BigInt(255))),b>>=BigInt(8);Gr(new Uint8Array(j.reverse()),W);return}p+=8}else if(D==="undefined")m[p++]=247;else throw new Error("Unknown type: "+D)},J=this.useRecords===!1?this.variableMapSize?b=>{let D=Object.keys(b),I=Object.values(b),j=D.length;if(j<24?m[p++]=160|j:j<256?(m[p++]=184,m[p++]=j):j<65536?(m[p++]=185,m[p++]=j>>8,m[p++]=j&255):(m[p++]=186,rt.setUint32(p,j),p+=4),c.keyMap)for(let O=0;O<j;O++)U(c.encodeKey(D[O])),U(I[O]);else for(let O=0;O<j;O++)U(D[O]),U(I[O])}:b=>{m[p++]=185;let D=p-n;p+=2;let I=0;if(c.keyMap)for(let j in b)(typeof b.hasOwnProperty!="function"||b.hasOwnProperty(j))&&(U(c.encodeKey(j)),U(b[j]),I++);else for(let j in b)(typeof b.hasOwnProperty!="function"||b.hasOwnProperty(j))&&(U(j),U(b[j]),I++);m[D+++n]=I>>8,m[D+n]=I&255}:(b,D)=>{let I,j=s.transitions||(s.transitions=Object.create(null)),O=0,N=0,V,K;if(this.keyMap){K=Object.keys(b).map(X=>this.encodeKey(X)),N=K.length;for(let X=0;X<N;X++){let hc=K[X];I=j[hc],I||(I=j[hc]=Object.create(null),O++),j=I}}else for(let X in b)(typeof b.hasOwnProperty!="function"||b.hasOwnProperty(X))&&(I=j[X],I||(j[vt]&1048576&&(V=j[vt]&65535),I=j[X]=Object.create(null),O++),j=I,N++);let q=j[vt];if(q!==void 0)q&=65535,m[p++]=217,m[p++]=q>>8|224,m[p++]=q&255;else if(K||(K=j.__keys__||(j.__keys__=Object.keys(b))),V===void 0?(q=s.nextId++,q||(q=0,s.nextId=1),q>=Qs&&(s.nextId=(q=u)+1)):q=V,s[q]=K,q<u){m[p++]=217,m[p++]=q>>8|224,m[p++]=q&255,j=s.transitions;for(let X=0;X<N;X++)(j[vt]===void 0||j[vt]&1048576)&&(j[vt]=q),j=j[K[X]];j[vt]=q|1048576,o=!0}else{if(j[vt]=q,rt.setUint32(p,3655335680),p+=3,O&&(F+=B*O),M.length>=Qs-u&&(M.shift()[vt]=void 0),M.push(j),$t(N+2),U(57344+q),U(K),D)return;for(let X in b)(typeof b.hasOwnProperty!="function"||b.hasOwnProperty(X))&&U(b[X]);return}if(N<24?m[p++]=128|N:$t(N),!D)for(let X in b)(typeof b.hasOwnProperty!="function"||b.hasOwnProperty(X))&&U(b[X])},W=b=>{let D;if(b>16777216){if(b-n>ti)throw new Error("Encoded buffer would be larger than maximum buffer size");D=Math.min(ti,Math.round(Math.max((b-n)*(b>67108864?1.25:2),4194304)/4096)*4096)}else D=(Math.max(b-n<<2,m.length-1)>>12)+1<<12;let I=new Kr(D);return rt=new DataView(I.buffer,0,D),m.copy?m.copy(I,0,n,b):I.set(m.slice(n,b)),p-=n,n=0,Xt=I.length-10,m=I};let z=100,Q=1e3;this.encodeAsIterable=function(b,D){return Bt(b,D,Y)},this.encodeAsAsyncIterable=function(b,D){return Bt(b,D,R)};function*Y(b,D,I){let j=b.constructor;if(j===Object){let O=c.useRecords!==!1;O?J(b,!0):ni(Object.keys(b).length,160);for(let N in b){let V=b[N];O||U(N),V&&typeof V=="object"?D[N]?yield*Y(V,D[N]):yield*st(V,D,N):U(V)}}else if(j===Array){let O=b.length;$t(O);for(let N=0;N<O;N++){let V=b[N];V&&(typeof V=="object"||p-n>z)?D.element?yield*Y(V,D.element):yield*st(V,D,"element"):U(V)}}else if(b[Symbol.iterator]&&!b.buffer){m[p++]=159;for(let O of b)O&&(typeof O=="object"||p-n>z)?D.element?yield*Y(O,D.element):yield*st(O,D,"element"):U(O);m[p++]=255}else qr(b)?(ni(b.size,64),yield m.subarray(n,p),yield b,nt()):b[Symbol.asyncIterator]?(m[p++]=159,yield m.subarray(n,p),yield b,nt(),m[p++]=255):U(b);I&&p>n?yield m.subarray(n,p):p-n>z&&(yield m.subarray(n,p),nt())}function*st(b,D,I){let j=p-n;try{U(b),p-n>z&&(yield m.subarray(n,p),nt())}catch(O){if(O.iteratorNotHandled)D[I]={},p=n+j,yield*Y.call(this,b,D[I]);else throw O}}function nt(){z=Q,c.encode(null,Yr)}function Bt(b,D,I){return D&&D.chunkThreshold?z=Q=D.chunkThreshold:z=100,b&&typeof b=="object"?(c.encode(null,Yr),I(b,c.iterateProperties||(c.iterateProperties={}),!0)):[c.encode(b)]}async function*R(b,D){for(let I of Y(b,D,!0)){let j=I.constructor;if(j===Xs||j===Uint8Array)yield I;else if(qr(I)){let O=I.stream().getReader(),N;for(;!(N=await O.read()).done;)yield N.value}else if(I[Symbol.asyncIterator])for await(let O of I)nt(),O?yield*R(O,D.async||(D.async={})):yield c.encode(O);else yield I}}}useBuffer(t){m=t,rt=new DataView(m.buffer,m.byteOffset,m.byteLength),p=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let n=this.structures.slice(0),r=new ri(n,this.sharedValues,this.sharedVersion),o=this.saveShared(r,s=>(s&&s.version||0)==t);return o===!1?(r=this.getShared()||{},this.structures=r.structures||[],this.sharedValues=r.packedValues,this.sharedVersion=r.version,this.structures.nextId=this.structures.length):n.forEach((s,i)=>this.structures[i]=s),o}}function ni(e,t){e<24?m[p++]=t|e:e<256?(m[p++]=t|24,m[p++]=e):e<65536?(m[p++]=t|25,m[p++]=e>>8,m[p++]=e&255):(m[p++]=t|26,rt.setUint32(p,e),p+=4)}class ri{constructor(t,n,r){this.structures=t,this.packedValues=n,this.version=r}}function $t(e){e<24?m[p++]=128|e:e<256?(m[p++]=152,m[p++]=e):e<65536?(m[p++]=153,m[p++]=e>>8,m[p++]=e&255):(m[p++]=154,rt.setUint32(p,e),p+=4)}const Ed=typeof Blob>"u"?function(){}:Blob;function qr(e){if(e instanceof Ed)return!0;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function En(e,t){switch(typeof e){case"string":if(e.length>3){if(t.objectMap[e]>-1||t.values.length>=t.maxValues)return;let r=t.get(e);if(r)++r.count==2&&t.values.push(e);else if(t.set(e,{count:1}),t.samplingPackedValues){let o=t.samplingPackedValues.get(e);o?o.count++:t.samplingPackedValues.set(e,{count:1})}}break;case"object":if(e)if(e instanceof Array)for(let r=0,o=e.length;r<o;r++)En(e[r],t);else{let r=!t.encoder.useRecords;for(var n in e)e.hasOwnProperty(n)&&(r&&En(n,t),En(e[n],t))}break;case"function":console.log(e)}}const Od=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;Ys=[Date,Set,Error,RegExp,ie,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,ri],Jr=[{tag:1,encode(e,t){let n=e.getTime()/1e3;(this.useTimestamp32||e.getMilliseconds()===0)&&n>=0&&n<4294967296?(m[p++]=26,rt.setUint32(p,n),p+=4):(m[p++]=251,rt.setFloat64(p,n),p+=8)}},{tag:258,encode(e,t){let n=Array.from(e);t(n)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,n){Gr(e,n)}},{getTag(e){if(e.constructor===Uint8Array&&(this.tagUint8Array||qe&&this.tagUint8Array!==!1))return 64},encode(e,t,n){Gr(e,n)}},Pt(68,1),Pt(69,2),Pt(70,4),Pt(71,8),Pt(72,1),Pt(77,2),Pt(78,4),Pt(79,8),Pt(85,4),Pt(86,8),{encode(e,t){let n=e.packedValues||[],r=e.structures||[];if(n.values.length>0){m[p++]=216,m[p++]=51,$t(4);let o=n.values;t(o),$t(0),$t(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let s=0,i=o.length;s<i;s++)packedObjectMap[o[s]]=s}if(r){rt.setUint32(p,3655335424),p+=3;let o=r.slice(0);o.unshift(57344),o.push(new ie(e.version,1399353956)),t(o)}else t(new ie(e.version,1399353956))}}];function Pt(e,t){return!Od&&t>1&&(e-=4),{tag:e,encode:function(n,r){let o=n.byteLength,s=n.byteOffset||0,i=n.buffer||n;r(qe?Cn.from(i,s,o):new Uint8Array(i,s,o))}}}function Gr(e,t){let n=e.byteLength;n<24?m[p++]=64+n:n<256?(m[p++]=88,m[p++]=n):n<65536?(m[p++]=89,m[p++]=n>>8,m[p++]=n&255):(m[p++]=90,rt.setUint32(p,n),p+=4),p+n>=m.length&&t(p+n),m.set(e.buffer?e:new Uint8Array(e),p),p+=n}function jd(e,t){let n,r=t.length*2,o=e.length-r;t.sort((s,i)=>s.offset>i.offset?1:-1);for(let s=0;s<t.length;s++){let i=t[s];i.id=s;for(let a of i.references)e[a++]=s>>8,e[a]=s&255}for(;n=t.pop();){let s=n.offset;e.copyWithin(s+r,s,o),r-=2;let i=s+r;e[i++]=216,e[i++]=28,o=s}return e}function oi(e,t){rt.setUint32(ut.position+e,p-ut.position-e+1);let n=ut;ut=null,t(n[0]),t(n[1])}let Zr=new ei({useRecords:!1});Zr.encode,Zr.encodeAsIterable,Zr.encodeAsAsyncIterable;const si=512,Rd=1024,Yr=2048;function Td(e){return new ei({tagUint8Array:!1,useRecords:!1}).encode(e)}const Ud=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]),Xr=(e,t)=>Ud(e,t),$d=async(e,t)=>{let n;const r=new Promise((o,s)=>{n=setTimeout(()=>s(new Pd(`withTimeout: timed out after ${t}ms`)),t)});try{return await Promise.race([e,r])}finally{clearTimeout(n)}};class Pd extends Error{constructor(t){super(t),this.name="TimeoutError"}}class Dd extends pe{documentId;#e;#t;#r=te();#n=6e4;#s={};constructor(t,n={}){super(),this.documentId=t,"timeoutDelay"in n&&n.timeoutDelay&&(this.#n=n.timeoutDelay);const r=te();this.#e=ee(`automerge-repo:dochandle:${this.documentId.slice(0,5)}`);const o=this.#n,s=K_({types:{context:{},events:{}},actions:{onUpdate:Sr(({context:i,event:a})=>{const c=i.doc;z_(a,jn);const{callback:_}=a.payload;return{doc:_(c)}}),onDelete:Sr(()=>(this.emit("delete",{handle:this}),{doc:te()})),onUnavailable:()=>{this.emit("unavailable",{handle:this})}}}).createMachine({initial:"idle",context:{documentId:t,doc:r},on:{UPDATE:{actions:"onUpdate"},DELETE:".deleted"},states:{idle:{on:{BEGIN:"loading"}},loading:{on:{REQUEST:"requesting",DOC_READY:"ready"},after:{[o]:"unavailable"}},requesting:{on:{DOC_UNAVAILABLE:"unavailable",DOC_READY:"ready"},after:{[o]:"unavailable"}},unavailable:{entry:"onUnavailable",on:{DOC_READY:"ready"}},ready:{},deleted:{entry:"onDelete",type:"final"}}});this.#t=Fe(s),this.#t.subscribe(i=>{const a=this.#r,c=i.context.doc;this.#e(`\u2192 ${i.value} %o`,c),this.#c(a,c)}),this.#t.start(),this.#t.send({type:Bd})}get#i(){return this.#t?.getSnapshot().context.doc}get#a(){return this.#t?.getSnapshot().value}#o(t){const n=Array.isArray(t)?t:[t];return q_(this.#t,r=>n.some(o=>r.matches(o)),{timeout:this.#n*2})}#c(t,n){const r=jt(t),o=jt(n);if(!Xr(o,r)){this.emit("heads-changed",{handle:this,doc:n});const s=tr(n,r,o);s.length>0&&this.emit("change",{handle:this,doc:n,patches:s,patchInfo:{before:t,after:n,source:"change"}}),this.isReady()||this.#t.send({type:ai})}this.#r=n}get url(){return Ur({documentId:this.documentId})}isReady=()=>this.inState(["ready"]);isDeleted=()=>this.inState(["deleted"]);isUnavailable=()=>this.inState(["unavailable"]);inState=t=>t.some(n=>this.#t.getSnapshot().matches(n));get state(){return this.#t.getSnapshot().value}async whenReady(t=["ready"]){await $d(this.#o(t),this.#n)}async doc(t=["ready","unavailable"]){try{await this.#o(t)}catch{return}return this.isUnavailable()?void 0:this.#i}docSync(){if(this.isReady())return this.#i}heads(){if(this.isReady())return jt(this.#i)}history(){if(this.isReady())return Zo(this.#i).map(t=>[t])}view(t){if(this.isReady())return Uo(this.#i,t)}diff(t,n){if(!this.isReady())return;const r=n?t:this.heads()||[],o=n||t;return tr(this.#i,r,o)}metadata(t){if(this.isReady())return t||(t=this.heads()[0]),Yo(this.#i,t)||void 0}update(t){this.#t.send({type:jn,payload:{callback:t}})}doneLoading(){this.#t.send({type:ai})}setRemoteHeads(t,n){this.#s[t]=n,this.emit("remote-heads",{storageId:t,heads:n})}getRemoteHeads(t){return this.#s[t]}change(t,n={}){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is in ${this.state} and not ready. Check \`handle.isReady()\` before accessing the document.`);this.#t.send({type:jn,payload:{callback:r=>$o(r,n,t)}})}changeAt(t,n,r={}){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before accessing the document.`);let o;return this.#t.send({type:jn,payload:{callback:s=>{const i=Po(s,t,r,n);return o=i.newHeads||void 0,i.newDoc}}}),o}merge(t){if(!this.isReady()||!t.isReady())throw new Error("Both handles must be ready to merge");const n=t.docSync();if(!n)throw new Error("The document to be merged in is falsy, aborting.");this.update(r=>Mo(r,n))}unavailable(){this.#t.send({type:Ld})}request(){this.#a==="loading"&&this.#t.send({type:Fd})}delete(){this.#t.send({type:Hd})}broadcast(t){this.emit("ephemeral-message-outbound",{handle:this,data:Td(t)})}metrics(){return Xo(this.#i)}}const Md={IDLE:"idle",LOADING:"loading",REQUESTING:"requesting",READY:"ready",DELETED:"deleted",UNAVAILABLE:"unavailable"},{IDLE:Kg,LOADING:Wg,REQUESTING:On,READY:Qr,DELETED:qg,UNAVAILABLE:ii}=Md,Bd="BEGIN",Fd="REQUEST",ai="DOC_READY",jn="UPDATE",Hd="DELETE",Ld="DOC_UNAVAILABLE";class zd extends pe{#e=new Map;#t=new Set;#r=new Map;#n=new Set;#s=new Map;#i=ee("automerge-repo:remote-heads-subscriptions");subscribeToRemotes(t){this.#i("subscribeToRemotes",t);const n=[];for(const r of t)this.#t.has(r)||(this.#t.add(r),n.push(r));n.length>0&&this.emit("change-remote-subs",{add:n,peers:Array.from(this.#n)})}unsubscribeFromRemotes(t){this.#i("subscribeToRemotes",t);const n=[];for(const r of t)this.#t.has(r)&&(this.#t.delete(r),this.#r.has(r)||n.push(r));n.length>0&&this.emit("change-remote-subs",{remove:n,peers:Array.from(this.#n)})}handleControlMessage(t){const n=[],r=[],o=[];if(this.#i("handleControlMessage",t),t.add)for(const s of t.add){let i=this.#r.get(s);(this.#t.has(s)||i)&&o.push(s),i||(i=new Set,this.#r.set(s,i),this.#t.has(s)||n.push(s)),i.add(t.senderId)}if(t.remove)for(const s of t.remove){const i=this.#r.get(s);i&&(i.delete(t.senderId),i.size==0&&!this.#t.has(s)&&r.push(s))}(n.length>0||r.length>0)&&this.emit("change-remote-subs",{peers:Array.from(this.#n),add:n,remove:r});for(const s of o){const i=this.#s.get(t.senderId);if(i)for(const a of i){const c=this.#e.get(a);if(!c)continue;const _=c.get(s);_&&this.emit("notify-remote-heads",{targetId:t.senderId,documentId:a,heads:_.heads,timestamp:_.timestamp,storageId:s})}}}handleRemoteHeads(t){this.#i("handleRemoteHeads",t);const n=this.#o(t);for(const r of n)this.#t.has(r.storageId)&&this.emit("remote-heads-changed",r);for(const r of n)for(const o of this.#n)o!==t.senderId&&this.emit("notify-remote-heads",{targetId:o,documentId:r.documentId,heads:r.remoteHeads,timestamp:r.timestamp,storageId:r.storageId});for(const r of n){const o=this.#r.get(r.storageId);if(o)for(const s of o)this.#a(s,r.documentId)&&this.emit("notify-remote-heads",{targetId:s,documentId:r.documentId,heads:r.remoteHeads,timestamp:r.timestamp,storageId:r.storageId})}}handleImmediateRemoteHeadsChanged(t,n,r){this.#i("handleLocalHeadsChanged",t,n,r);const o=this.#e.get(t),s=Date.now();if(!o)this.#e.set(t,new Map([[n,{heads:r,timestamp:s}]]));else{const a=o.get(n);(!a||a.timestamp<Date.now())&&o.set(n,{heads:r,timestamp:Date.now()})}const i=this.#r.get(n);if(i)for(const a of i)this.#a(a,t)&&this.emit("notify-remote-heads",{targetId:a,documentId:t,heads:r,timestamp:s,storageId:n})}addGenerousPeer(t){this.#i("addGenerousPeer",t),this.#n.add(t),this.#t.size>0&&this.emit("change-remote-subs",{add:Array.from(this.#t),peers:[t]});for(const[n,r]of this.#e)for(const[o,{heads:s,timestamp:i}]of r)this.emit("notify-remote-heads",{targetId:t,documentId:n,heads:s,timestamp:i,storageId:o})}removePeer(t){this.#i("removePeer",t);const n=[];this.#n.delete(t),this.#s.delete(t);for(const[r,o]of this.#r)o.has(t)&&(o.delete(t),o.size==0&&(n.push(r),this.#r.delete(r)));n.length>0&&this.emit("change-remote-subs",{remove:n,peers:Array.from(this.#n)})}subscribePeerToDoc(t,n){let r=this.#s.get(t);r||(r=new Set,this.#s.set(t,r)),r.add(n);const o=this.#e.get(n);if(o)for(const[s,i]of o){const a=this.#r.get(s);a&&a.has(t)&&this.emit("notify-remote-heads",{targetId:t,documentId:n,heads:i.heads,timestamp:i.timestamp,storageId:s})}}#a(t,n){const r=this.#s.get(t);return r&&r.has(n)}#o(t){const n=[],{documentId:r,newHeads:o}=t;for(const[s,{heads:i,timestamp:a}]of Object.entries(o)){if(!this.#t.has(s)&&!this.#r.has(s))continue;let c=this.#e.get(r);c||(c=new Map,this.#e.set(r,c));const _=c.get(s);_&&_.timestamp>=a||(c.set(s,{timestamp:a,heads:i}),n.push({documentId:r,storageId:s,remoteHeads:i,timestamp:a}))}return n}}const to=(e,t)=>{let n=Date.now(),r,o;return function(...s){r=n+t-Date.now(),clearTimeout(o),o=setTimeout(()=>{e(...s),n=Date.now()},r)}},Nd=e=>Jd(e)||ui(e)||ci(e)||Vd(e)||Kd(e)||Wd(e),Vd=e=>e.type==="doc-unavailable",ci=e=>e.type==="request",Jd=e=>e.type==="sync",ui=e=>e.type==="ephemeral",Kd=e=>e.type==="remote-subscription-change",Wd=e=>e.type==="remote-heads-changed",qd=e=>`${e.senderId}:${e.sessionId}`;class Gd extends pe{peerId;peerMetadata;#e;#t={};#r=0;#n=Math.random().toString(36).slice(2);#s={};adapters=[];constructor(t,n,r){super(),this.peerId=n,this.peerMetadata=r,this.#e=ee(`automerge-repo:network:${this.peerId}`),t.forEach(o=>this.addNetworkAdapter(o))}disconnect(){this.adapters.forEach(t=>t.disconnect())}reconnect(){this.adapters.forEach(t=>t.connect(this.peerId))}addNetworkAdapter(t){this.adapters.push(t),t.on("peer-candidate",({peerId:n,peerMetadata:r})=>{this.#e(`peer candidate: ${n} `),this.#t[n]||(this.#t[n]=t),this.emit("peer",{peerId:n,peerMetadata:r})}),t.on("peer-disconnected",({peerId:n})=>{this.#e(`peer disconnected: ${n} `),delete this.#t[n],this.emit("peer-disconnected",{peerId:n})}),t.on("message",n=>{if(!Nd(n)){this.#e(`invalid message: ${JSON.stringify(n)}`);return}if(this.#e(`message from ${n.senderId}`),ui(n)){const r=qd(n);(this.#s[r]===void 0||n.count>this.#s[r])&&(this.#s[r]=n.count,this.emit("message",n));return}this.emit("message",n)}),t.on("close",()=>{this.#e("adapter closed"),Object.entries(this.#t).forEach(([n,r])=>{r===t&&delete this.#t[n]})}),this.peerMetadata.then(n=>{t.connect(this.peerId,n)}).catch(n=>{this.#e("error connecting to network",n)})}removeNetworkAdapter(t){this.adapters=this.adapters.filter(n=>n!==t),t.disconnect()}send(t){const n=this.#t[t.targetId];if(!n){this.#e(`Tried to send message but peer not found: ${t.targetId}`);return}const r=(o=>o.type==="ephemeral"?"count"in o?o:{...o,count:++this.#r,sessionId:this.#n,senderId:this.peerId}:{...o,senderId:this.peerId})(t);this.#e("sending message %o",r),n.send(r)}isReady=()=>this.adapters.every(t=>t.isReady());whenReady=async()=>Promise.all(this.adapters.map(t=>t.whenReady()))}function _i(e){let t=0;e.forEach(o=>{t+=o.length});const n=new Uint8Array(t);let r=0;return e.forEach(o=>{n.set(o,r),r+=o.length}),n}var di={exports:{}};(function(e){(function(t,n){var r={};n(r);var o=r.default;for(var s in r)o[s]=r[s];e.exports=o})(Be,function(t){t.__esModule=!0,t.digestLength=32,t.blockSize=64;var n=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function r(g,l,v,x,M){for(var F,B,U,J,W,z,Q,Y,st,nt,Bt,R,b;M>=64;){for(F=l[0],B=l[1],U=l[2],J=l[3],W=l[4],z=l[5],Q=l[6],Y=l[7],nt=0;nt<16;nt++)Bt=x+nt*4,g[nt]=(v[Bt]&255)<<24|(v[Bt+1]&255)<<16|(v[Bt+2]&255)<<8|v[Bt+3]&255;for(nt=16;nt<64;nt++)st=g[nt-2],R=(st>>>17|st<<15)^(st>>>19|st<<13)^st>>>10,st=g[nt-15],b=(st>>>7|st<<25)^(st>>>18|st<<14)^st>>>3,g[nt]=(R+g[nt-7]|0)+(b+g[nt-16]|0);for(nt=0;nt<64;nt++)R=(((W>>>6|W<<26)^(W>>>11|W<<21)^(W>>>25|W<<7))+(W&z^~W&Q)|0)+(Y+(n[nt]+g[nt]|0)|0)|0,b=((F>>>2|F<<30)^(F>>>13|F<<19)^(F>>>22|F<<10))+(F&B^F&U^B&U)|0,Y=Q,Q=z,z=W,W=J+R|0,J=U,U=B,B=F,F=R+b|0;l[0]+=F,l[1]+=B,l[2]+=U,l[3]+=J,l[4]+=W,l[5]+=z,l[6]+=Q,l[7]+=Y,x+=64,M-=64}return x}var o=function(){function g(){this.digestLength=t.digestLength,this.blockSize=t.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return g.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},g.prototype.clean=function(){for(var l=0;l<this.buffer.length;l++)this.buffer[l]=0;for(var l=0;l<this.temp.length;l++)this.temp[l]=0;this.reset()},g.prototype.update=function(l,v){if(v===void 0&&(v=l.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var x=0;if(this.bytesHashed+=v,this.bufferLength>0){for(;this.bufferLength<64&&v>0;)this.buffer[this.bufferLength++]=l[x++],v--;this.bufferLength===64&&(r(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(v>=64&&(x=r(this.temp,this.state,l,x,v),v%=64);v>0;)this.buffer[this.bufferLength++]=l[x++],v--;return this},g.prototype.finish=function(l){if(!this.finished){var v=this.bytesHashed,x=this.bufferLength,M=v/536870912|0,F=v<<3,B=v%64<56?64:128;this.buffer[x]=128;for(var U=x+1;U<B-8;U++)this.buffer[U]=0;this.buffer[B-8]=M>>>24&255,this.buffer[B-7]=M>>>16&255,this.buffer[B-6]=M>>>8&255,this.buffer[B-5]=M>>>0&255,this.buffer[B-4]=F>>>24&255,this.buffer[B-3]=F>>>16&255,this.buffer[B-2]=F>>>8&255,this.buffer[B-1]=F>>>0&255,r(this.temp,this.state,this.buffer,0,B),this.finished=!0}for(var U=0;U<8;U++)l[U*4+0]=this.state[U]>>>24&255,l[U*4+1]=this.state[U]>>>16&255,l[U*4+2]=this.state[U]>>>8&255,l[U*4+3]=this.state[U]>>>0&255;return this},g.prototype.digest=function(){var l=new Uint8Array(this.digestLength);return this.finish(l),l},g.prototype._saveState=function(l){for(var v=0;v<this.state.length;v++)l[v]=this.state[v]},g.prototype._restoreState=function(l,v){for(var x=0;x<this.state.length;x++)this.state[x]=l[x];this.bytesHashed=v,this.finished=!1,this.bufferLength=0},g}();t.Hash=o;var s=function(){function g(l){this.inner=new o,this.outer=new o,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var v=new Uint8Array(this.blockSize);if(l.length>this.blockSize)new o().update(l).finish(v).clean();else for(var x=0;x<l.length;x++)v[x]=l[x];for(var x=0;x<v.length;x++)v[x]^=54;this.inner.update(v);for(var x=0;x<v.length;x++)v[x]^=106;this.outer.update(v),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var x=0;x<v.length;x++)v[x]=0}return g.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},g.prototype.clean=function(){for(var l=0;l<this.istate.length;l++)this.ostate[l]=this.istate[l]=0;this.inner.clean(),this.outer.clean()},g.prototype.update=function(l){return this.inner.update(l),this},g.prototype.finish=function(l){return this.outer.finished?this.outer.finish(l):(this.inner.finish(l),this.outer.update(l,this.digestLength).finish(l)),this},g.prototype.digest=function(){var l=new Uint8Array(this.digestLength);return this.finish(l),l},g}();t.HMAC=s;function i(g){var l=new o().update(g),v=l.digest();return l.clean(),v}t.hash=i,t.default=i;function a(g,l){var v=new s(g).update(l),x=v.digest();return v.clean(),x}t.hmac=a;function c(g,l,v,x){var M=x[0];if(M===0)throw new Error("hkdf: cannot expand more");l.reset(),M>1&&l.update(g),v&&l.update(v),l.update(x),l.finish(g),x[0]++}var _=new Uint8Array(t.digestLength);function u(g,l,v,x){l===void 0&&(l=_),x===void 0&&(x=32);for(var M=new Uint8Array([1]),F=a(l,g),B=new s(F),U=new Uint8Array(B.digestLength),J=U.length,W=new Uint8Array(x),z=0;z<x;z++)J===U.length&&(c(U,B,v,M),J=0),W[z]=U[J++];return B.clean(),U.fill(0),M.fill(0),W}t.hkdf=u;function d(g,l,v,x){for(var M=new s(g),F=M.digestLength,B=new Uint8Array(4),U=new Uint8Array(F),J=new Uint8Array(F),W=new Uint8Array(x),z=0;z*F<x;z++){var Q=z+1;B[0]=Q>>>24&255,B[1]=Q>>>16&255,B[2]=Q>>>8&255,B[3]=Q>>>0&255,M.reset(),M.update(l),M.update(B),M.finish(J);for(var Y=0;Y<F;Y++)U[Y]=J[Y];for(var Y=2;Y<=v;Y++){M.reset(),M.update(J).finish(J);for(var st=0;st<F;st++)U[st]^=J[st]}for(var Y=0;Y<F&&z*F+Y<x;Y++)W[z*F+Y]=U[Y]}for(var z=0;z<F;z++)U[z]=J[z]=0;for(var z=0;z<4;z++)B[z]=0;return M.clean(),W}t.pbkdf2=d})})(di);var Zd=di.exports;function fi(e){const t=Zd.hash(e);return Xd(t)}function Yd(e){const t=new TextEncoder,n=_i(e.map(r=>t.encode(r)));return fi(n)}function Xd(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function Qd(e){if(e.length<2)return null;const t=e[e.length-2];return t==="snapshot"||t==="incremental"?t:null}class tf{#e;#t=new Map;#r=new Map;#n=!1;#s=ee("automerge-repo:storage-subsystem");constructor(t){this.#e=t}async id(){const t=await this.#e.load(["storage-adapter-id"]);let n;return t?n=new TextDecoder().decode(t):(n=xo(),await this.#e.save(["storage-adapter-id"],new TextEncoder().encode(n))),n}async load(t,n){const r=[t,n];return await this.#e.load(r)}async save(t,n,r){const o=[t,n];await this.#e.save(o,r)}async remove(t,n){const r=[t,n];await this.#e.remove(r)}async loadDoc(t){const n=await this.#e.loadRange([t]),r=[],o=[];for(const a of n){if(a.data===void 0)continue;const c=Qd(a.key);c!=null&&(o.push({key:a.key,type:c,size:a.data.length}),r.push(a.data))}this.#r.set(t,o);const s=_i(r);if(s.length===0)return null;const i=Xn(te(),s);return this.#t.set(t,jt(i)),i}async saveDoc(t,n){if(!this.#o(t,n))return;const r=this.#r.get(t)??[];this.#c(r)?await this.#a(t,n,r):await this.#i(t,n),this.#t.set(t,jt(n))}async removeDoc(t){await this.#e.removeRange([t,"snapshot"]),await this.#e.removeRange([t,"incremental"]),await this.#e.removeRange([t,"sync-state"])}async#i(t,n){const r=qo(n,this.#t.get(t)??[]);if(r&&r.length>0){const o=[t,"incremental",fi(r)];this.#s(`Saving incremental ${o} for document ${t}`),await this.#e.save(o,r),this.#r.has(t)||this.#r.set(t,[]),this.#r.get(t).push({key:o,type:"incremental",size:r.length}),this.#t.set(t,jt(n))}else return Promise.resolve()}async#a(t,n,r){this.#n=!0;const o=Qn(n),s=Yd(jt(n)),i=[t,"snapshot",s],a=new Set(r.map(_=>_.key).filter(_=>_[2]!==s));this.#s(`Saving snapshot ${i} for document ${t}`),this.#s(`deleting old chunks ${Array.from(a)}`),await this.#e.save(i,o);for(const _ of a)await this.#e.remove(_);const c=this.#r.get(t)?.filter(_=>!a.has(_.key))??[];c.push({key:i,type:"snapshot",size:o.length}),this.#r.set(t,c),this.#n=!1}async loadSyncState(t,n){const r=[t,"sync-state",n];try{const o=await this.#e.load(r);return o?nr(o):void 0}catch{this.#s(`Error loading sync state for ${t} from ${n}`);return}}async saveSyncState(t,n,r){const o=[t,"sync-state",n];await this.#e.save(o,er(r))}#o(t,n){const r=this.#t.get(t);if(!r)return!0;const o=jt(n);return!Xr(o,r)}#c(t){if(this.#n)return!1;let n=0,r=0;for(const o of t)o.type==="snapshot"?n+=o.size:r+=o.size;return n<1024||r>=n}}class hi extends pe{}class ef extends hi{#e;syncDebounceRate=100;#t=[];#r={};#n={};#s={};#i=[];#a=!1;#o;#c;constructor({handle:t,onLoadSyncState:n}){super(),this.#o=t,this.#c=n??(()=>Promise.resolve(void 0));const r=t.documentId.slice(0,5);this.#e=ee(`automerge-repo:docsync:${r}`),t.on("change",to(()=>this.#g(),this.syncDebounceRate)),t.on("ephemeral-message-outbound",o=>this.#p(o)),(async()=>(await t.doc([Qr,On]),this.#l()))()}get peerStates(){return this.#n}get documentId(){return this.#o.documentId}async#g(){this.#e("syncWithPeers");const t=await this.#o.doc();t!==void 0&&this.#t.forEach(n=>this.#f(n,t))}async#p({data:t}){this.#e("broadcastToPeers",this.#t),this.#t.forEach(n=>this.#b(n,t))}#b(t,n){this.#e(`sendEphemeralMessage ->${t}`);const r={type:"ephemeral",targetId:t,documentId:this.#o.documentId,data:n};this.emit("message",r)}#_(t,n){this.#y(t),t in this.#n||(this.#n[t]="unknown");const r=this.#s[t];if(r){n(r);return}let o=this.#r[t];o||(this.#c(t).then(s=>{this.#w(t,s??Vo())}).catch(s=>{this.#e(`Error loading sync state for ${t}: ${s}`)}),o=this.#r[t]=[]),o.push(n)}#y(t){this.#t.includes(t)||(this.#t.push(t),this.emit("open-doc",{documentId:this.documentId,peerId:t}))}#w(t,n){const r=this.#r[t];if(r)for(const o of r)o(n);delete this.#r[t],this.#s[t]=n}#d(t,n){this.#s[t]=n,this.emit("sync-state",{peerId:t,syncState:n,documentId:this.#o.documentId})}#f(t,n){this.#e(`sendSyncMessage ->${t}`),this.#_(t,r=>{const[o,s]=zo(n,r);if(s){this.#d(t,o);const i=jt(n).length===0;!this.#o.isReady()&&i&&o.sharedHeads.length===0&&!Object.values(this.#n).includes("has")&&this.#n[t]==="unknown"?this.emit("message",{type:"request",targetId:t,documentId:this.#o.documentId,data:s}):this.emit("message",{type:"sync",targetId:t,data:s,documentId:this.#o.documentId}),i||(this.#n[t]="has")}})}hasPeer(t){return this.#t.includes(t)}beginSync(t){const n=t.every(o=>this.#n[o]in["unavailable","wants"]),r=this.#o.doc([Qr,On,ii]).then(o=>{if(this.#a=!0,this.#u(),!(o===void 0&&n))return o??te()});this.#e(`beginSync: ${t.join(", ")}`),t.forEach(o=>{this.#_(o,s=>{const i=nr(er(s));this.#d(o,i),r.then(a=>{a&&this.#f(o,a)}).catch(a=>{this.#e(`Error loading doc for ${o}: ${a}`)})})})}endSync(t){this.#e(`removing peer ${t}`),this.#t=this.#t.filter(n=>n!==t)}receiveMessage(t){switch(t.type){case"sync":case"request":this.receiveSyncMessage(t);break;case"ephemeral":this.receiveEphemeralMessage(t);break;case"doc-unavailable":this.#n[t.senderId]="unavailable",this.#u();break;default:throw new Error(`unknown message type: ${t}`)}}receiveEphemeralMessage(t){if(t.documentId!==this.#o.documentId)throw new Error("channelId doesn't match documentId");const{senderId:n,data:r}=t,o=Ad(new Uint8Array(r));this.#o.emit("ephemeral-message",{handle:this.#o,senderId:n,message:o}),this.#t.forEach(s=>{s!==n&&this.emit("message",{...t,targetId:s})})}receiveSyncMessage(t){if(t.documentId!==this.#o.documentId)throw new Error("channelId doesn't match documentId");if(!this.#o.inState([Qr,On,ii])){this.#i.push({message:t,received:new Date});return}this.#l(),this.#h(t)}#h(t){ci(t)&&(this.#n[t.senderId]="wants"),this.#u(),Ko(t.data).heads.length>0&&(this.#n[t.senderId]="has"),this.#_(t.senderId,n=>{this.#o.update(r=>{const[o,s]=No(r,n,t.data);return this.#d(t.senderId,s),this.#f(t.senderId,r),o}),this.#u()})}#u(){this.#a&&this.#o.inState([On])&&this.#t.every(t=>this.#n[t]==="unavailable"||this.#n[t]==="wants")&&(this.#t.filter(t=>this.#n[t]==="wants").forEach(t=>{const n={type:"doc-unavailable",documentId:this.#o.documentId,targetId:t};this.emit("message",n)}),this.#o.unavailable())}#l(){for(const t of this.#i)this.#h(t.message);this.#i=[]}metrics(){return{peers:this.#t,size:this.#o.metrics()}}}const eo=ee("automerge-repo:collectionsync");class nf extends hi{repo;#e=new Set;docSynchronizers={};#t={};constructor(t){super(),this.repo=t}#r(t){if(!this.docSynchronizers[t]){const n=this.repo.find(Ur({documentId:t}));this.docSynchronizers[t]=this.#n(n)}return this.docSynchronizers[t]}#n(t){const n=new ef({handle:t,onLoadSyncState:async r=>{if(!this.repo.storageSubsystem)return;const{storageId:o,isEphemeral:s}=this.repo.peerMetadataByPeerId[r]||{};if(!(!o||s))return this.repo.storageSubsystem.loadSyncState(t.documentId,o)}});return n.on("message",r=>this.emit("message",r)),n.on("open-doc",r=>this.emit("open-doc",r)),n.on("sync-state",r=>this.emit("sync-state",r)),n}async#s(t){const n=Array.from(this.#e),r=[];for(const o of n)await this.repo.sharePolicy(o,t)&&r.push(o);return r}async receiveMessage(t){eo(`onSyncMessage: ${t.senderId}, ${t.documentId}, ${"data"in t?t.data.byteLength+"bytes":""}`);const n=t.documentId;if(!n)throw new Error("received a message with an invalid documentId");this.#t[n]=!0;const r=this.#r(n);r.receiveMessage(t);const o=await this.#s(n);r.beginSync(o.filter(s=>!r.hasPeer(s)))}addDocument(t){if(this.#t[t])return;const n=this.#r(t);this.#s(t).then(r=>{n.beginSync(r)})}removeDocument(t){throw new Error("not implemented")}addPeer(t){if(eo(`adding ${t} & synchronizing with them`),!this.#e.has(t)){this.#e.add(t);for(const n of Object.values(this.docSynchronizers)){const{documentId:r}=n;this.repo.sharePolicy(t,r).then(o=>{o&&n.beginSync([t])})}}}removePeer(t){eo(`removing peer ${t}`),this.#e.delete(t);for(const n of Object.values(this.docSynchronizers))n.endSync(t)}get peers(){return Array.from(this.#e)}metrics(){return Object.fromEntries(Object.entries(this.docSynchronizers).map(([t,n])=>[t,n.metrics()]))}}function rf(){return"peer-"+Math.random().toString(36).slice(4)}class of extends pe{#e;networkSubsystem;storageSubsystem;saveDebounceRate=100;#t={};synchronizer;sharePolicy=async()=>!0;peerMetadataByPeerId={};#r=new zd;#n=!1;constructor({storage:t,network:n=[],peerId:r=rf(),sharePolicy:o,isEphemeral:s=t===void 0,enableRemoteHeadsGossiping:i=!1}={}){super(),this.#n=i,this.#e=ee("automerge-repo:repo"),this.sharePolicy=o??this.sharePolicy,this.on("delete-document",({documentId:u})=>{a&&a.removeDoc(u).catch(d=>{this.#e("error deleting document",{documentId:u,err:d})})}),this.synchronizer=new nf(this),this.synchronizer.on("message",u=>{this.#e(`sending ${u.type} message to ${u.targetId}`),_.send(u)}),this.#n&&this.synchronizer.on("open-doc",({peerId:u,documentId:d})=>{this.#r.subscribePeerToDoc(u,d)});const a=t?new tf(t):void 0;this.storageSubsystem=a;const c=(async()=>({storageId:await a?.id(),isEphemeral:s}))(),_=new Gd(n,r,c);this.networkSubsystem=_,_.on("peer",async({peerId:u,peerMetadata:d})=>{this.#e("peer connected",{peerId:u}),d&&(this.peerMetadataByPeerId[u]={...d}),this.sharePolicy(u).then(g=>{g&&this.#n&&this.#r.addGenerousPeer(u)}).catch(g=>{console.log("error in share policy",{err:g})}),this.synchronizer.addPeer(u)}),_.on("peer-disconnected",({peerId:u})=>{this.synchronizer.removePeer(u),this.#r.removePeer(u)}),_.on("message",async u=>{this.#i(u)}),this.synchronizer.on("sync-state",u=>{this.#o(u);const d=this.#t[u.documentId],{storageId:g}=this.peerMetadataByPeerId[u.peerId]||{};if(!g)return;const l=d.getRemoteHeads(g);u.syncState.theirHeads&&(!l||!Xr(l,u.syncState.theirHeads))&&u.syncState.theirHeads&&(d.setRemoteHeads(g,u.syncState.theirHeads),g&&this.#n&&this.#r.handleImmediateRemoteHeadsChanged(u.documentId,g,u.syncState.theirHeads))}),this.#n&&(this.#r.on("notify-remote-heads",u=>{this.networkSubsystem.send({type:"remote-heads-changed",targetId:u.targetId,documentId:u.documentId,newHeads:{[u.storageId]:{heads:u.heads,timestamp:u.timestamp}}})}),this.#r.on("change-remote-subs",u=>{this.#e("change-remote-subs",u);for(const d of u.peers)this.networkSubsystem.send({type:"remote-subscription-change",targetId:d,add:u.add,remove:u.remove})}),this.#r.on("remote-heads-changed",u=>{this.#t[u.documentId].setRemoteHeads(u.storageId,u.remoteHeads)}))}#s(t){const{storageSubsystem:n}=this;if(n){const r=({handle:o,doc:s})=>{n.saveDoc(o.documentId,s)};t.on("heads-changed",to(r,this.saveDebounceRate))}t.on("unavailable",()=>{this.#e("document unavailable",{documentId:t.documentId}),this.emit("unavailable-document",{documentId:t.documentId})}),this.synchronizer.addDocument(t.documentId),this.emit("document",{handle:t})}#i(t){switch(t.type){case"remote-subscription-change":this.#n&&this.#r.handleControlMessage(t);break;case"remote-heads-changed":this.#n&&this.#r.handleRemoteHeads(t);break;case"sync":case"request":case"ephemeral":case"doc-unavailable":this.synchronizer.receiveMessage(t).catch(n=>{console.log("error receiving message",{err:n})})}}#a={};#o(t){if(!this.storageSubsystem)return;const{storageId:n,isEphemeral:r}=this.peerMetadataByPeerId[t.peerId]||{};if(!n||r)return;let o=this.#a[n];o||(o=this.#a[n]=to(({documentId:s,syncState:i})=>{this.storageSubsystem.saveSyncState(s,n,i)},this.saveDebounceRate)),o(t)}#c({documentId:t}){if(this.#t[t])return this.#t[t];if(!t)throw new Error(`Invalid documentId ${t}`);const n=new Dd(t);return this.#t[t]=n,n}get handles(){return this.#t}get peers(){return this.synchronizer.peers}getStorageIdOfPeer(t){return this.peerMetadataByPeerId[t]?.storageId}create(t){const{documentId:n}=Tr(dd()),r=this.#c({documentId:n});return this.#s(r),r.update(()=>{let o;return t?o=Qo(t):o=Do(te()),o}),r.doneLoading(),r}clone(t){if(!t.isReady())throw new Error(`Cloned handle is not yet in ready state.
5
+ (Try await handle.whenReady() first.)`);const n=t.docSync();if(!n)throw new Error("Cloned handle doesn't have a document.");const r=this.create();return r.update(()=>rr(n)),r}find(t){const n=Pr(t);if(this.#t[n])return this.#t[n].isUnavailable()&&setTimeout(()=>{this.#t[n].emit("unavailable",{handle:this.#t[n]})}),this.#t[n];const r=this.#c({documentId:n});return(this.storageSubsystem?this.storageSubsystem.loadDoc(r.documentId):Promise.resolve(null)).then(async o=>{o?(r.update(()=>o),r.doneLoading()):(await this.networkSubsystem.whenReady(),r.request()),this.#s(r)}).catch(o=>{this.#e("error waiting for network",{err:o})}),r}delete(t){const n=Pr(t);this.#c({documentId:n}).delete(),delete this.#t[n],this.emit("delete-document",{documentId:n})}async export(t){const n=Pr(t),r=await this.#c({documentId:n}).doc();if(r)return Qn(r)}import(t){const n=ts(t),r=this.create();return r.update(()=>rr(n)),r}subscribeToRemotes=t=>{this.#n?(this.#e("subscribeToRemotes",{remotes:t}),this.#r.subscribeToRemotes(t)):this.#e("WARN: subscribeToRemotes called but remote heads gossiping is not enabled")};storageId=async()=>{if(this.storageSubsystem)return this.storageSubsystem.id()};async flush(t){if(!this.storageSubsystem)return;const n=t?t.map(r=>this.#t[r]):Object.values(this.#t);await Promise.all(n.map(async r=>{const o=r.docSync();if(o)return this.storageSubsystem.saveDoc(r.documentId,o)}))}shutdown(){return this.networkSubsystem.adapters.forEach(t=>{t.disconnect()}),this.flush()}metrics(){return{documents:this.synchronizer.metrics()}}}class sf extends pe{peerId;peerMetadata}const af="/.well-known/action_merge/assets/automerge.wasm",cf=async(e={},t)=>{let n;if(t.startsWith("data:")){const r=t.replace(/^data:.*?base64,/,"");let o;if(typeof Buffer=="function"&&typeof Buffer.from=="function")o=Buffer.from(r,"base64");else if(typeof atob=="function"){const s=atob(r);o=new Uint8Array(s.length);for(let i=0;i<s.length;i++)o[i]=s.charCodeAt(i)}else throw new Error("Cannot decode base64-encoded data URL");n=await WebAssembly.instantiate(o,e)}else{const r=await fetch(t),o=r.headers.get("Content-Type")||"";if("instantiateStreaming"in WebAssembly&&o.startsWith("application/wasm"))n=await WebAssembly.instantiateStreaming(r,e);else{const s=await r.arrayBuffer();n=await WebAssembly.instantiate(s,e)}}return n.instance.exports};let h;function li(e){h=e}const Kt=new Array(128).fill(void 0);Kt.push(void 0,null,!0,!1);function P(e){return Kt[e]}let Ge=Kt.length;function uf(e){e<132||(Kt[e]=Ge,Ge=e)}function E(e){const t=P(e);return uf(e),t}let Et=0,Rn=null;function Tn(){return(Rn===null||Rn.byteLength===0)&&(Rn=new Uint8Array(h.memory.buffer)),Rn}const _f=typeof TextEncoder>"u"?(0,module.require)("util").TextEncoder:TextEncoder;let Un=new _f("utf-8");const df=typeof Un.encodeInto=="function"?function(e,t){return Un.encodeInto(e,t)}:function(e,t){const n=Un.encode(e);return t.set(n),{read:e.length,written:n.length}};function Dt(e,t,n){if(n===void 0){const a=Un.encode(e),c=t(a.length,1)>>>0;return Tn().subarray(c,c+a.length).set(a),Et=a.length,c}let r=e.length,o=t(r,1)>>>0;const s=Tn();let i=0;for(;i<r;i++){const a=e.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(e=e.slice(i)),o=n(o,r,r=i+e.length*3,1)>>>0;const a=Tn().subarray(o+i,o+r),c=df(e,a);i+=c.written,o=n(o,r,i,1)>>>0}return Et=i,o}function et(e){return e==null}let $n=null;function w(){return($n===null||$n.byteLength===0)&&($n=new Int32Array(h.memory.buffer)),$n}const ff=typeof TextDecoder>"u"?(0,module.require)("util").TextDecoder:TextDecoder;let gi=new ff("utf-8",{ignoreBOM:!0,fatal:!0});gi.decode();function St(e,t){return e=e>>>0,gi.decode(Tn().subarray(e,e+t))}function k(e){Ge===Kt.length&&Kt.push(Kt.length+1);const t=Ge;return Ge=Kt[t],Kt[t]=e,t}let Pn=null;function Dn(){return(Pn===null||Pn.byteLength===0)&&(Pn=new Float64Array(h.memory.buffer)),Pn}function no(e){const t=typeof e;if(t=="number"||t=="boolean"||e==null)return`${e}`;if(t=="string")return`"${e}"`;if(t=="symbol"){const o=e.description;return o==null?"Symbol":`Symbol(${o})`}if(t=="function"){const o=e.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(e)){const o=e.length;let s="[";o>0&&(s+=no(e[0]));for(let i=1;i<o;i++)s+=", "+no(e[i]);return s+="]",s}const n=/\[object ([^\]]+)\]/.exec(toString.call(e));let r;if(n.length>1)r=n[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}
6
+ ${e.stack}`:r}function ce(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function hf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.create(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return Mt.__wrap(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function lf(e,t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.load(s,k(e),k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return Mt.__wrap(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function gf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.encodeChange(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function pf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.decodeChange(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function bf(){const e=h.initSyncState();return Ot.__wrap(e)}function yf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.importSyncState(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return Ot.__wrap(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function wf(e){ce(e,Ot);const t=h.exportSyncState(e.__wbg_ptr);return E(t)}function mf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.encodeSyncMessage(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function vf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.decodeSyncMessage(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function Sf(e){ce(e,Ot);const t=h.encodeSyncState(e.__wbg_ptr);return E(t)}function kf(e){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.decodeSyncState(o,k(e));var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return Ot.__wrap(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}function bt(e,t){try{return e.apply(this,t)}catch(n){h.__wbindgen_exn_store(k(n))}}const xf=Object.freeze({Array:0,0:"Array",String:1,1:"String"}),pi=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>h.__wbg_automerge_free(e>>>0));class Mt{static __wrap(t){t=t>>>0;const n=Object.create(Mt.prototype);return n.__wbg_ptr=t,pi.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,pi.unregister(this),t}free(){const t=this.__destroy_into_raw();h.__wbg_automerge_free(t)}static new(t,n){try{const c=h.__wbindgen_add_to_stack_pointer(-16);var r=et(t)?0:Dt(t,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;h.automerge_new(c,r,o,n);var s=w()[c/4+0],i=w()[c/4+1],a=w()[c/4+2];if(a)throw E(i);return Mt.__wrap(s)}finally{h.__wbindgen_add_to_stack_pointer(16)}}clone(t){try{const a=h.__wbindgen_add_to_stack_pointer(-16);var n=et(t)?0:Dt(t,h.__wbindgen_malloc,h.__wbindgen_realloc),r=Et;h.automerge_clone(a,this.__wbg_ptr,n,r);var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return Mt.__wrap(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}fork(t,n){try{const c=h.__wbindgen_add_to_stack_pointer(-16);var r=et(t)?0:Dt(t,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;h.automerge_fork(c,this.__wbg_ptr,r,o,k(n));var s=w()[c/4+0],i=w()[c/4+1],a=w()[c/4+2];if(a)throw E(i);return Mt.__wrap(s)}finally{h.__wbindgen_add_to_stack_pointer(16)}}pendingOps(){const t=h.automerge_pendingOps(this.__wbg_ptr);return E(t)}commit(t,n){var r=et(t)?0:Dt(t,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;const s=h.automerge_commit(this.__wbg_ptr,r,o,!et(n),et(n)?0:n);return E(s)}merge(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);ce(t,Mt),h.automerge_merge(s,this.__wbg_ptr,t.__wbg_ptr);var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}rollback(){return h.automerge_rollback(this.__wbg_ptr)}keys(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_keys(i,this.__wbg_ptr,k(t),et(n)?0:k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}text(t,n){let r,o;try{const d=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_text(d,this.__wbg_ptr,k(t),et(n)?0:k(n));var s=w()[d/4+0],i=w()[d/4+1],a=w()[d/4+2],c=w()[d/4+3],_=s,u=i;if(c)throw _=0,u=0,E(a);return r=_,o=u,St(_,u)}finally{h.__wbindgen_add_to_stack_pointer(16),h.__wbindgen_free(r,o,1)}}spans(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_spans(i,this.__wbg_ptr,k(t),et(n)?0:k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}splice(t,n,r,o){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_splice(a,this.__wbg_ptr,k(t),n,r,k(o));var s=w()[a/4+0],i=w()[a/4+1];if(i)throw E(s)}finally{h.__wbindgen_add_to_stack_pointer(16)}}updateText(t,n){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_updateText(s,this.__wbg_ptr,k(t),k(n));var r=w()[s/4+0],o=w()[s/4+1];if(o)throw E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}updateSpans(t,n){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_updateSpans(s,this.__wbg_ptr,k(t),k(n));var r=w()[s/4+0],o=w()[s/4+1];if(o)throw E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}push(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_push(i,this.__wbg_ptr,k(t),k(n),k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}pushObject(t,n){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_pushObject(a,this.__wbg_ptr,k(t),k(n));var r=w()[a/4+0],o=w()[a/4+1],s=w()[a/4+2],i=w()[a/4+3];if(i)throw E(s);let c;return r!==0&&(c=St(r,o).slice(),h.__wbindgen_free(r,o*1,1)),c}finally{h.__wbindgen_add_to_stack_pointer(16)}}insert(t,n,r,o){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_insert(a,this.__wbg_ptr,k(t),n,k(r),k(o));var s=w()[a/4+0],i=w()[a/4+1];if(i)throw E(s)}finally{h.__wbindgen_add_to_stack_pointer(16)}}splitBlock(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_splitBlock(i,this.__wbg_ptr,k(t),n,k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}joinBlock(t,n){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_joinBlock(s,this.__wbg_ptr,k(t),n);var r=w()[s/4+0],o=w()[s/4+1];if(o)throw E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}updateBlock(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_updateBlock(i,this.__wbg_ptr,k(t),n,k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getBlock(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getBlock(a,this.__wbg_ptr,k(t),n,et(r)?0:k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}insertObject(t,n,r){try{const c=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_insertObject(c,this.__wbg_ptr,k(t),n,k(r));var o=w()[c/4+0],s=w()[c/4+1],i=w()[c/4+2],a=w()[c/4+3];if(a)throw E(i);let _;return o!==0&&(_=St(o,s).slice(),h.__wbindgen_free(o,s*1,1)),_}finally{h.__wbindgen_add_to_stack_pointer(16)}}put(t,n,r,o){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_put(a,this.__wbg_ptr,k(t),k(n),k(r),k(o));var s=w()[a/4+0],i=w()[a/4+1];if(i)throw E(s)}finally{h.__wbindgen_add_to_stack_pointer(16)}}putObject(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_putObject(a,this.__wbg_ptr,k(t),k(n),k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}increment(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_increment(i,this.__wbg_ptr,k(t),k(n),k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}get(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_get(a,this.__wbg_ptr,k(t),k(n),et(r)?0:k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getWithType(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getWithType(a,this.__wbg_ptr,k(t),k(n),et(r)?0:k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}objInfo(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_objInfo(i,this.__wbg_ptr,k(t),et(n)?0:k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getAll(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getAll(a,this.__wbg_ptr,k(t),k(n),et(r)?0:k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}enableFreeze(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_enableFreeze(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}registerDatatype(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_registerDatatype(i,this.__wbg_ptr,k(t),k(n),k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}applyPatches(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_applyPatches(i,this.__wbg_ptr,k(t),k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}applyAndReturnPatches(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_applyAndReturnPatches(i,this.__wbg_ptr,k(t),k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}diffIncremental(){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_diffIncremental(o,this.__wbg_ptr);var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}updateDiffCursor(){h.automerge_updateDiffCursor(this.__wbg_ptr)}resetDiffCursor(){h.automerge_resetDiffCursor(this.__wbg_ptr)}diff(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_diff(i,this.__wbg_ptr,k(t),k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}isolate(t){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_isolate(o,this.__wbg_ptr,k(t));var n=w()[o/4+0],r=w()[o/4+1];if(r)throw E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}integrate(){h.automerge_integrate(this.__wbg_ptr)}length(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_length(i,this.__wbg_ptr,k(t),et(n)?0:k(n));var r=Dn()[i/8+0],o=w()[i/4+2],s=w()[i/4+3];if(s)throw E(o);return r}finally{h.__wbindgen_add_to_stack_pointer(16)}}delete(t,n){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_delete(s,this.__wbg_ptr,k(t),k(n));var r=w()[s/4+0],o=w()[s/4+1];if(o)throw E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}save(){const t=h.automerge_save(this.__wbg_ptr);return E(t)}saveIncremental(){const t=h.automerge_saveIncremental(this.__wbg_ptr);return E(t)}saveSince(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_saveSince(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}saveNoCompress(){const t=h.automerge_saveNoCompress(this.__wbg_ptr);return E(t)}saveAndVerify(){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_saveAndVerify(o,this.__wbg_ptr);var t=w()[o/4+0],n=w()[o/4+1],r=w()[o/4+2];if(r)throw E(n);return E(t)}finally{h.__wbindgen_add_to_stack_pointer(16)}}loadIncremental(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_loadIncremental(s,this.__wbg_ptr,k(t));var n=Dn()[s/8+0],r=w()[s/4+2],o=w()[s/4+3];if(o)throw E(r);return n}finally{h.__wbindgen_add_to_stack_pointer(16)}}applyChanges(t){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_applyChanges(o,this.__wbg_ptr,k(t));var n=w()[o/4+0],r=w()[o/4+1];if(r)throw E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getChanges(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getChanges(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getChangeByHash(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getChangeByHash(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getDecodedChangeByHash(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getDecodedChangeByHash(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getChangesAdded(t){ce(t,Mt);const n=h.automerge_getChangesAdded(this.__wbg_ptr,t.__wbg_ptr);return E(n)}getHeads(){const t=h.automerge_getHeads(this.__wbg_ptr);return E(t)}getActorId(){let t,n;try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getActorId(s,this.__wbg_ptr);var r=w()[s/4+0],o=w()[s/4+1];return t=r,n=o,St(r,o)}finally{h.__wbindgen_add_to_stack_pointer(16),h.__wbindgen_free(t,n,1)}}getLastLocalChange(){const t=h.automerge_getLastLocalChange(this.__wbg_ptr);return E(t)}dump(){h.automerge_dump(this.__wbg_ptr)}getMissingDeps(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getMissingDeps(s,this.__wbg_ptr,et(t)?0:k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}receiveSyncMessage(t,n){try{const s=h.__wbindgen_add_to_stack_pointer(-16);ce(t,Ot),h.automerge_receiveSyncMessage(s,this.__wbg_ptr,t.__wbg_ptr,k(n));var r=w()[s/4+0],o=w()[s/4+1];if(o)throw E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}generateSyncMessage(t){ce(t,Ot);const n=h.automerge_generateSyncMessage(this.__wbg_ptr,t.__wbg_ptr);return E(n)}toJS(t){try{const s=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_toJS(s,this.__wbg_ptr,k(t));var n=w()[s/4+0],r=w()[s/4+1],o=w()[s/4+2];if(o)throw E(r);return E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}materialize(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_materialize(a,this.__wbg_ptr,k(t),et(n)?0:k(n),k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}getCursor(t,n,r){let o,s;try{const g=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getCursor(g,this.__wbg_ptr,k(t),n,et(r)?0:k(r));var i=w()[g/4+0],a=w()[g/4+1],c=w()[g/4+2],_=w()[g/4+3],u=i,d=a;if(_)throw u=0,d=0,E(c);return o=u,s=d,St(u,d)}finally{h.__wbindgen_add_to_stack_pointer(16),h.__wbindgen_free(o,s,1)}}getCursorPosition(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_getCursorPosition(a,this.__wbg_ptr,k(t),k(n),et(r)?0:k(r));var o=Dn()[a/8+0],s=w()[a/4+2],i=w()[a/4+3];if(i)throw E(s);return o}finally{h.__wbindgen_add_to_stack_pointer(16)}}emptyChange(t,n){var r=et(t)?0:Dt(t,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;const s=h.automerge_emptyChange(this.__wbg_ptr,r,o,!et(n),et(n)?0:n);return E(s)}mark(t,n,r,o,s){try{const c=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_mark(c,this.__wbg_ptr,k(t),k(n),k(r),k(o),k(s));var i=w()[c/4+0],a=w()[c/4+1];if(a)throw E(i)}finally{h.__wbindgen_add_to_stack_pointer(16)}}unmark(t,n,r){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_unmark(i,this.__wbg_ptr,k(t),k(n),k(r));var o=w()[i/4+0],s=w()[i/4+1];if(s)throw E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}marks(t,n){try{const i=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_marks(i,this.__wbg_ptr,k(t),et(n)?0:k(n));var r=w()[i/4+0],o=w()[i/4+1],s=w()[i/4+2];if(s)throw E(o);return E(r)}finally{h.__wbindgen_add_to_stack_pointer(16)}}marksAt(t,n,r){try{const a=h.__wbindgen_add_to_stack_pointer(-16);h.automerge_marksAt(a,this.__wbg_ptr,k(t),n,et(r)?0:k(r));var o=w()[a/4+0],s=w()[a/4+1],i=w()[a/4+2];if(i)throw E(s);return E(o)}finally{h.__wbindgen_add_to_stack_pointer(16)}}hasOurChanges(t){ce(t,Ot);const n=h.automerge_hasOurChanges(this.__wbg_ptr,t.__wbg_ptr);return E(n)}topoHistoryTraversal(){const t=h.automerge_topoHistoryTraversal(this.__wbg_ptr);return E(t)}stats(){const t=h.automerge_stats(this.__wbg_ptr);return E(t)}}const bi=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>h.__wbg_syncstate_free(e>>>0));class Ot{static __wrap(t){t=t>>>0;const n=Object.create(Ot.prototype);return n.__wbg_ptr=t,bi.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,bi.unregister(this),t}free(){const t=this.__destroy_into_raw();h.__wbg_syncstate_free(t)}get sharedHeads(){const t=h.syncstate_sharedHeads(this.__wbg_ptr);return E(t)}get lastSentHeads(){const t=h.syncstate_lastSentHeads(this.__wbg_ptr);return E(t)}set lastSentHeads(t){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.syncstate_set_lastSentHeads(o,this.__wbg_ptr,k(t));var n=w()[o/4+0],r=w()[o/4+1];if(r)throw E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}set sentHashes(t){try{const o=h.__wbindgen_add_to_stack_pointer(-16);h.syncstate_set_sentHashes(o,this.__wbg_ptr,k(t));var n=w()[o/4+0],r=w()[o/4+1];if(r)throw E(n)}finally{h.__wbindgen_add_to_stack_pointer(16)}}clone(){const t=h.syncstate_clone(this.__wbg_ptr);return Ot.__wrap(t)}}function yi(e){E(e)}function wi(e,t){const n=P(t),r=typeof n=="string"?n:void 0;var o=et(r)?0:Dt(r,h.__wbindgen_malloc,h.__wbindgen_realloc),s=Et;w()[e/4+1]=s,w()[e/4+0]=o}function mi(e,t){const n=new Error(St(e,t));return k(n)}function vi(e,t){const n=St(e,t);return k(n)}function Si(e){return k(e)}function ki(e){const t=P(e);return k(t)}function xi(e,t){const n=P(t),r=typeof n=="number"?n:void 0;Dn()[e/8+1]=et(r)?0:r,w()[e/4+0]=!et(r)}function Ai(e){return P(e)===void 0}function Ii(e){const t=P(e);return typeof t=="boolean"?t?1:0:2}function Ci(e){return P(e)===null}function Ei(e){return typeof P(e)=="string"}function Oi(e){return typeof P(e)=="function"}function ji(e){const t=P(e);return typeof t=="object"&&t!==null}function Ri(e){return Array.isArray(P(e))}function Ti(e,t){const n=P(t),r=JSON.stringify(n===void 0?null:n),o=Dt(r,h.__wbindgen_malloc,h.__wbindgen_realloc),s=Et;w()[e/4+1]=s,w()[e/4+0]=o}function Ui(){const e=new Error;return k(e)}function $i(e,t){const n=P(t).stack,r=Dt(n,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;w()[e/4+1]=o,w()[e/4+0]=r}function Pi(e,t){let n,r;try{n=e,r=t,console.error(St(e,t))}finally{h.__wbindgen_free(n,r,1)}}function Di(e,t){return P(e)==P(t)}function Mi(e,t){const n=String(P(t)),r=Dt(n,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;w()[e/4+1]=o,w()[e/4+0]=r}function Bi(e){return k(e)}function Fi(e){const t=BigInt.asUintN(64,e);return k(t)}function Hi(e,t,n){P(e)[E(t)]=E(n)}function Li(){return bt(function(e,t){P(e).getRandomValues(P(t))},arguments)}function zi(){return bt(function(e,t){P(e).randomFillSync(E(t))},arguments)}function Ni(e){const t=P(e).crypto;return k(t)}function Vi(e){const t=P(e).process;return k(t)}function Ji(e){const t=P(e).versions;return k(t)}function Ki(e){const t=P(e).node;return k(t)}function Wi(){return bt(function(){const e=module.require;return k(e)},arguments)}function qi(e){const t=P(e).msCrypto;return k(t)}function Gi(e){console.log(P(e))}function Zi(e,t){console.log(P(e),P(t))}function Yi(e,t){const n=P(e)[t>>>0];return k(n)}function Xi(e){return P(e).length}function Qi(){const e=new Array;return k(e)}function ta(e,t){const n=new Function(St(e,t));return k(n)}function ea(e){const t=P(e).next;return k(t)}function na(){return bt(function(e){const t=P(e).next();return k(t)},arguments)}function ra(e){return P(e).done}function oa(e){const t=P(e).value;return k(t)}function sa(){return k(Symbol.iterator)}function ia(){return bt(function(e,t){const n=Reflect.get(P(e),P(t));return k(n)},arguments)}function aa(){return bt(function(e,t){const n=P(e).call(P(t));return k(n)},arguments)}function ca(){const e=new Object;return k(e)}function ua(e){return P(e).length}function _a(e,t,n){P(e)[t>>>0]=E(n)}function da(e){const t=Array.from(P(e));return k(t)}function fa(e){return Array.isArray(P(e))}function ha(e,t){return P(e).push(P(t))}function la(e,t){return P(e).unshift(P(t))}function ga(e){let t;try{t=P(e)instanceof ArrayBuffer}catch{t=!1}return t}function pa(e,t){const n=new Error(St(e,t));return k(n)}function ba(){return bt(function(e,t,n){const r=P(e).call(P(t),P(n));return k(r)},arguments)}function ya(e){let t;try{t=P(e)instanceof Date}catch{t=!1}return t}function wa(e){return P(e).getTime()}function ma(e){const t=new Date(P(e));return k(t)}function va(e){let t;try{t=P(e)instanceof Object}catch{t=!1}return t}function Sa(e,t){const n=Object.assign(P(e),P(t));return k(n)}function ka(e,t,n){const r=Object.defineProperty(P(e),P(t),P(n));return k(r)}function xa(e){const t=Object.entries(P(e));return k(t)}function Aa(e){const t=Object.freeze(P(e));return k(t)}function Ia(e){const t=Object.keys(P(e));return k(t)}function Ca(e){const t=Object.values(P(e));return k(t)}function Ea(e,t){const n=new RangeError(St(e,t));return k(n)}function Oa(){return bt(function(e,t,n){const r=Reflect.apply(P(e),P(t),P(n));return k(r)},arguments)}function ja(){return bt(function(e,t){return Reflect.deleteProperty(P(e),P(t))},arguments)}function Ra(){return bt(function(e){const t=Reflect.ownKeys(P(e));return k(t)},arguments)}function Ta(){return bt(function(e,t,n){return Reflect.set(P(e),P(t),P(n))},arguments)}function Ua(e){const t=P(e).buffer;return k(t)}function $a(e,t){const n=P(e).concat(P(t));return k(n)}function Pa(e,t,n){const r=P(e).slice(t>>>0,n>>>0);return k(r)}function Da(e,t){const n=Symbol.for(St(e,t));return k(n)}function Ma(e){const t=P(e).toString();return k(t)}function Ba(){return bt(function(){const e=self.self;return k(e)},arguments)}function Fa(){return bt(function(){const e=window.window;return k(e)},arguments)}function Ha(){return bt(function(){const e=globalThis.globalThis;return k(e)},arguments)}function La(){return bt(function(){const e=global.global;return k(e)},arguments)}function za(e,t,n){const r=new Uint8Array(P(e),t>>>0,n>>>0);return k(r)}function Na(e){const t=new Uint8Array(P(e));return k(t)}function Va(e,t,n){P(e).set(P(t),n>>>0)}function Ja(e){return P(e).length}function Ka(e){let t;try{t=P(e)instanceof Uint8Array}catch{t=!1}return t}function Wa(e){const t=new Uint8Array(e>>>0);return k(t)}function qa(e,t,n){const r=P(e).subarray(t>>>0,n>>>0);return k(r)}function Ga(e,t){const n=no(P(t)),r=Dt(n,h.__wbindgen_malloc,h.__wbindgen_realloc),o=Et;w()[e/4+1]=o,w()[e/4+0]=r}function Za(e,t){throw new Error(St(e,t))}function Ya(){const e=h.memory;return k(e)}URL=globalThis.URL;const T=await cf({"./automerge_wasm_bg.js":{__wbindgen_object_drop_ref:yi,__wbindgen_string_get:wi,__wbindgen_error_new:mi,__wbindgen_string_new:vi,__wbindgen_number_new:Si,__wbindgen_object_clone_ref:ki,__wbindgen_number_get:xi,__wbindgen_is_undefined:Ai,__wbindgen_boolean_get:Ii,__wbindgen_is_null:Ci,__wbindgen_is_string:Ei,__wbindgen_is_function:Oi,__wbindgen_is_object:ji,__wbindgen_is_array:Ri,__wbindgen_json_serialize:Ti,__wbg_new_abda76e883ba8a5f:Ui,__wbg_stack_658279fe44541cf6:$i,__wbg_error_f851667af71bcfc6:Pi,__wbindgen_jsval_loose_eq:Di,__wbg_String_91fba7ded13ba54c:Mi,__wbindgen_bigint_from_i64:Bi,__wbindgen_bigint_from_u64:Fi,__wbg_set_20cbc34131e76824:Hi,__wbg_getRandomValues_3aa56aa6edec874c:Li,__wbg_randomFillSync_5c9c955aa56b6049:zi,__wbg_crypto_1d1f22824a6a080c:Ni,__wbg_process_4a72847cc503995b:Vi,__wbg_versions_f686565e586dd935:Ji,__wbg_node_104a2ff8d6ea03a2:Ki,__wbg_require_cca90b1a94a0255b:Wi,__wbg_msCrypto_eb05e62b530a1508:qi,__wbg_log_5bb5f88f245d7762:Gi,__wbg_log_1746d5c75ec89963:Zi,__wbg_get_bd8e338fbd5f5cc8:Yi,__wbg_length_cd7af8117672b8b8:Xi,__wbg_new_16b304a2cfa7ff4a:Qi,__wbg_newnoargs_e258087cd0daa0ea:ta,__wbg_next_40fc327bfc8770e6:ea,__wbg_next_196c84450b364254:na,__wbg_done_298b57d23c0fc80c:ra,__wbg_value_d93c65011f51a456:oa,__wbg_iterator_2cee6dadfd956dfa:sa,__wbg_get_e3c254076557e348:ia,__wbg_call_27c0f87801dedf93:aa,__wbg_new_72fb9a18b5ae2624:ca,__wbg_length_dee433d4c85c9387:ua,__wbg_set_d4638f722068f043:_a,__wbg_from_89e3fc3ba5e6fb48:da,__wbg_isArray_2ab64d95e09ea0ae:fa,__wbg_push_a5b05aedc7234f9f:ha,__wbg_unshift_e22df4b34bcf5070:la,__wbg_instanceof_ArrayBuffer_836825be07d4c9d2:ga,__wbg_new_28c511d9baebfa89:pa,__wbg_call_b3ca7c6051f9bec1:ba,__wbg_instanceof_Date_f65cf97fb83fc369:ya,__wbg_getTime_2bc4375165f02d15:wa,__wbg_new_cf3ec55744a78578:ma,__wbg_instanceof_Object_71ca3c0a59266746:va,__wbg_assign_496d2d14fecafbcf:Sa,__wbg_defineProperty_cc00e2de8a0f5141:ka,__wbg_entries_95cc2c823b285a09:xa,__wbg_freeze_cc6bc19f75299986:Aa,__wbg_keys_91e412b4b222659f:Ia,__wbg_values_9c75e6e2bfbdb70d:Ca,__wbg_new_dd6a5dd7b538af21:Ea,__wbg_apply_0a5aa603881e6d79:Oa,__wbg_deleteProperty_13e721a56f19e842:ja,__wbg_ownKeys_658942b7f28d1fe9:Ra,__wbg_set_1f9b04f170055d33:Ta,__wbg_buffer_12d079cc21e14bdb:Ua,__wbg_concat_3de229fe4fe90fea:$a,__wbg_slice_52fb626ffdc8da8f:Pa,__wbg_for_27c67e2dbdce22f6:Da,__wbg_toString_7df3c77999517c20:Ma,__wbg_self_ce0dbfc45cf2f5be:Ba,__wbg_window_c6fb939a7f436783:Fa,__wbg_globalThis_d1e6af4856ba331b:Ha,__wbg_global_207b558942527489:La,__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb:za,__wbg_new_63b92bc8671ed464:Na,__wbg_set_a47bac70306a19a7:Va,__wbg_length_c20a40f15020d68a:Ja,__wbg_instanceof_Uint8Array_2b3bbecd033d19f6:Ka,__wbg_newwithlength_e9b4878cebadb3d3:Wa,__wbg_subarray_a1f73cd4b5b42fe1:qa,__wbindgen_debug_string:Ga,__wbindgen_throw:Za,__wbindgen_memory:Ya}},af),Af=T.memory,If=T.__wbg_syncstate_free,Cf=T.syncstate_sharedHeads,Ef=T.syncstate_lastSentHeads,Of=T.syncstate_set_lastSentHeads,jf=T.syncstate_set_sentHashes,Rf=T.syncstate_clone,Tf=T.__wbg_automerge_free,Uf=T.automerge_new,$f=T.automerge_clone,Pf=T.automerge_fork,Df=T.automerge_pendingOps,Mf=T.automerge_commit,Bf=T.automerge_merge,Ff=T.automerge_rollback,Hf=T.automerge_keys,Lf=T.automerge_text,zf=T.automerge_spans,Nf=T.automerge_splice,Vf=T.automerge_updateText,Jf=T.automerge_updateSpans,Kf=T.automerge_push,Wf=T.automerge_pushObject,qf=T.automerge_insert,Gf=T.automerge_splitBlock,Zf=T.automerge_joinBlock,Yf=T.automerge_updateBlock,Xf=T.automerge_getBlock,Qf=T.automerge_insertObject,th=T.automerge_put,eh=T.automerge_putObject,nh=T.automerge_increment,rh=T.automerge_get,oh=T.automerge_getWithType,sh=T.automerge_objInfo,ih=T.automerge_getAll,ah=T.automerge_enableFreeze,ch=T.automerge_registerDatatype,uh=T.automerge_applyPatches,_h=T.automerge_applyAndReturnPatches,dh=T.automerge_diffIncremental,fh=T.automerge_updateDiffCursor,hh=T.automerge_resetDiffCursor,lh=T.automerge_diff,gh=T.automerge_isolate,ph=T.automerge_integrate,bh=T.automerge_length,yh=T.automerge_delete,wh=T.automerge_save,mh=T.automerge_saveIncremental,vh=T.automerge_saveSince,Sh=T.automerge_saveNoCompress,kh=T.automerge_saveAndVerify,xh=T.automerge_loadIncremental,Ah=T.automerge_applyChanges,Ih=T.automerge_getChanges,Ch=T.automerge_getChangeByHash,Eh=T.automerge_getDecodedChangeByHash,Oh=T.automerge_getChangesAdded,jh=T.automerge_getHeads,Rh=T.automerge_getActorId,Th=T.automerge_getLastLocalChange,Uh=T.automerge_dump,$h=T.automerge_getMissingDeps,Ph=T.automerge_receiveSyncMessage,Dh=T.automerge_generateSyncMessage,Mh=T.automerge_toJS,Bh=T.automerge_materialize,Fh=T.automerge_getCursor,Hh=T.automerge_getCursorPosition,Lh=T.automerge_emptyChange,zh=T.automerge_mark,Nh=T.automerge_unmark,Vh=T.automerge_marks,Jh=T.automerge_marksAt,Kh=T.automerge_hasOurChanges,Wh=T.automerge_topoHistoryTraversal,qh=T.automerge_stats,Gh=T.create,Zh=T.load,Yh=T.encodeChange,Xh=T.decodeChange,Qh=T.initSyncState,tl=T.importSyncState,el=T.exportSyncState,nl=T.encodeSyncMessage,rl=T.decodeSyncMessage,ol=T.encodeSyncState,sl=T.decodeSyncState,il=T.__wbindgen_malloc,al=T.__wbindgen_realloc,cl=T.__wbindgen_add_to_stack_pointer,ul=T.__wbindgen_free,_l=T.__wbindgen_exn_store,dl=Object.freeze(Object.defineProperty({__proto__:null,__wbg_automerge_free:Tf,__wbg_syncstate_free:If,__wbindgen_add_to_stack_pointer:cl,__wbindgen_exn_store:_l,__wbindgen_free:ul,__wbindgen_malloc:il,__wbindgen_realloc:al,automerge_applyAndReturnPatches:_h,automerge_applyChanges:Ah,automerge_applyPatches:uh,automerge_clone:$f,automerge_commit:Mf,automerge_delete:yh,automerge_diff:lh,automerge_diffIncremental:dh,automerge_dump:Uh,automerge_emptyChange:Lh,automerge_enableFreeze:ah,automerge_fork:Pf,automerge_generateSyncMessage:Dh,automerge_get:rh,automerge_getActorId:Rh,automerge_getAll:ih,automerge_getBlock:Xf,automerge_getChangeByHash:Ch,automerge_getChanges:Ih,automerge_getChangesAdded:Oh,automerge_getCursor:Fh,automerge_getCursorPosition:Hh,automerge_getDecodedChangeByHash:Eh,automerge_getHeads:jh,automerge_getLastLocalChange:Th,automerge_getMissingDeps:$h,automerge_getWithType:oh,automerge_hasOurChanges:Kh,automerge_increment:nh,automerge_insert:qf,automerge_insertObject:Qf,automerge_integrate:ph,automerge_isolate:gh,automerge_joinBlock:Zf,automerge_keys:Hf,automerge_length:bh,automerge_loadIncremental:xh,automerge_mark:zh,automerge_marks:Vh,automerge_marksAt:Jh,automerge_materialize:Bh,automerge_merge:Bf,automerge_new:Uf,automerge_objInfo:sh,automerge_pendingOps:Df,automerge_push:Kf,automerge_pushObject:Wf,automerge_put:th,automerge_putObject:eh,automerge_receiveSyncMessage:Ph,automerge_registerDatatype:ch,automerge_resetDiffCursor:hh,automerge_rollback:Ff,automerge_save:wh,automerge_saveAndVerify:kh,automerge_saveIncremental:mh,automerge_saveNoCompress:Sh,automerge_saveSince:vh,automerge_spans:zf,automerge_splice:Nf,automerge_splitBlock:Gf,automerge_stats:qh,automerge_text:Lf,automerge_toJS:Mh,automerge_topoHistoryTraversal:Wh,automerge_unmark:Nh,automerge_updateBlock:Yf,automerge_updateDiffCursor:fh,automerge_updateSpans:Jf,automerge_updateText:Vf,create:Gh,decodeChange:Xh,decodeSyncMessage:rl,decodeSyncState:sl,encodeChange:Yh,encodeSyncMessage:nl,encodeSyncState:ol,exportSyncState:el,importSyncState:tl,initSyncState:Qh,load:Zh,memory:Af,syncstate_clone:Rf,syncstate_lastSentHeads:Ef,syncstate_set_lastSentHeads:Of,syncstate_set_sentHashes:jf,syncstate_sharedHeads:Cf},Symbol.toStringTag,{value:"Module"}));li(dl);const fl=Object.freeze(Object.defineProperty({__proto__:null,Automerge:Mt,SyncState:Ot,TextRepresentation:xf,__wbg_String_91fba7ded13ba54c:Mi,__wbg_apply_0a5aa603881e6d79:Oa,__wbg_assign_496d2d14fecafbcf:Sa,__wbg_buffer_12d079cc21e14bdb:Ua,__wbg_call_27c0f87801dedf93:aa,__wbg_call_b3ca7c6051f9bec1:ba,__wbg_concat_3de229fe4fe90fea:$a,__wbg_crypto_1d1f22824a6a080c:Ni,__wbg_defineProperty_cc00e2de8a0f5141:ka,__wbg_deleteProperty_13e721a56f19e842:ja,__wbg_done_298b57d23c0fc80c:ra,__wbg_entries_95cc2c823b285a09:xa,__wbg_error_f851667af71bcfc6:Pi,__wbg_for_27c67e2dbdce22f6:Da,__wbg_freeze_cc6bc19f75299986:Aa,__wbg_from_89e3fc3ba5e6fb48:da,__wbg_getRandomValues_3aa56aa6edec874c:Li,__wbg_getTime_2bc4375165f02d15:wa,__wbg_get_bd8e338fbd5f5cc8:Yi,__wbg_get_e3c254076557e348:ia,__wbg_globalThis_d1e6af4856ba331b:Ha,__wbg_global_207b558942527489:La,__wbg_instanceof_ArrayBuffer_836825be07d4c9d2:ga,__wbg_instanceof_Date_f65cf97fb83fc369:ya,__wbg_instanceof_Object_71ca3c0a59266746:va,__wbg_instanceof_Uint8Array_2b3bbecd033d19f6:Ka,__wbg_isArray_2ab64d95e09ea0ae:fa,__wbg_iterator_2cee6dadfd956dfa:sa,__wbg_keys_91e412b4b222659f:Ia,__wbg_length_c20a40f15020d68a:Ja,__wbg_length_cd7af8117672b8b8:Xi,__wbg_length_dee433d4c85c9387:ua,__wbg_log_1746d5c75ec89963:Zi,__wbg_log_5bb5f88f245d7762:Gi,__wbg_msCrypto_eb05e62b530a1508:qi,__wbg_new_16b304a2cfa7ff4a:Qi,__wbg_new_28c511d9baebfa89:pa,__wbg_new_63b92bc8671ed464:Na,__wbg_new_72fb9a18b5ae2624:ca,__wbg_new_abda76e883ba8a5f:Ui,__wbg_new_cf3ec55744a78578:ma,__wbg_new_dd6a5dd7b538af21:Ea,__wbg_newnoargs_e258087cd0daa0ea:ta,__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb:za,__wbg_newwithlength_e9b4878cebadb3d3:Wa,__wbg_next_196c84450b364254:na,__wbg_next_40fc327bfc8770e6:ea,__wbg_node_104a2ff8d6ea03a2:Ki,__wbg_ownKeys_658942b7f28d1fe9:Ra,__wbg_process_4a72847cc503995b:Vi,__wbg_push_a5b05aedc7234f9f:ha,__wbg_randomFillSync_5c9c955aa56b6049:zi,__wbg_require_cca90b1a94a0255b:Wi,__wbg_self_ce0dbfc45cf2f5be:Ba,__wbg_set_1f9b04f170055d33:Ta,__wbg_set_20cbc34131e76824:Hi,__wbg_set_a47bac70306a19a7:Va,__wbg_set_d4638f722068f043:_a,__wbg_set_wasm:li,__wbg_slice_52fb626ffdc8da8f:Pa,__wbg_stack_658279fe44541cf6:$i,__wbg_subarray_a1f73cd4b5b42fe1:qa,__wbg_toString_7df3c77999517c20:Ma,__wbg_unshift_e22df4b34bcf5070:la,__wbg_value_d93c65011f51a456:oa,__wbg_values_9c75e6e2bfbdb70d:Ca,__wbg_versions_f686565e586dd935:Ji,__wbg_window_c6fb939a7f436783:Fa,__wbindgen_bigint_from_i64:Bi,__wbindgen_bigint_from_u64:Fi,__wbindgen_boolean_get:Ii,__wbindgen_debug_string:Ga,__wbindgen_error_new:mi,__wbindgen_is_array:Ri,__wbindgen_is_function:Oi,__wbindgen_is_null:Ci,__wbindgen_is_object:ji,__wbindgen_is_string:Ei,__wbindgen_is_undefined:Ai,__wbindgen_json_serialize:Ti,__wbindgen_jsval_loose_eq:Di,__wbindgen_memory:Ya,__wbindgen_number_get:xi,__wbindgen_number_new:Si,__wbindgen_object_clone_ref:ki,__wbindgen_object_drop_ref:yi,__wbindgen_string_get:wi,__wbindgen_string_new:vi,__wbindgen_throw:Za,create:hf,decodeChange:pf,decodeSyncMessage:vf,decodeSyncState:kf,encodeChange:gf,encodeSyncMessage:mf,encodeSyncState:Sf,exportSyncState:wf,importSyncState:yf,initSyncState:bf,load:lf},Symbol.toStringTag,{value:"Module"}));Ro(fl);var Mn={logger:typeof console<"u"?console:void 0,WebSocket:typeof WebSocket<"u"?WebSocket:void 0},ot={log(...e){this.enabled&&(e.push(Date.now()),Mn.logger.log("[ActionCable]",...e))}};const Ze=()=>new Date().getTime(),Bn=e=>(Ze()-e)/1e3;class ro{constructor(t){this.visibilityDidChange=this.visibilityDidChange.bind(this),this.connection=t,this.reconnectAttempts=0}start(){this.isRunning()||(this.startedAt=Ze(),delete this.stoppedAt,this.startPolling(),addEventListener("visibilitychange",this.visibilityDidChange),ot.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`))}stop(){this.isRunning()&&(this.stoppedAt=Ze(),this.stopPolling(),removeEventListener("visibilitychange",this.visibilityDidChange),ot.log("ConnectionMonitor stopped"))}isRunning(){return this.startedAt&&!this.stoppedAt}recordMessage(){this.pingedAt=Ze()}recordConnect(){this.reconnectAttempts=0,delete this.disconnectedAt,ot.log("ConnectionMonitor recorded connect")}recordDisconnect(){this.disconnectedAt=Ze(),ot.log("ConnectionMonitor recorded disconnect")}startPolling(){this.stopPolling(),this.poll()}stopPolling(){clearTimeout(this.pollTimeout)}poll(){this.pollTimeout=setTimeout(()=>{this.reconnectIfStale(),this.poll()},this.getPollInterval())}getPollInterval(){const{staleThreshold:t,reconnectionBackoffRate:n}=this.constructor,r=Math.pow(1+n,Math.min(this.reconnectAttempts,10)),o=(this.reconnectAttempts===0?1:n)*Math.random();return t*1e3*r*(1+o)}reconnectIfStale(){this.connectionIsStale()&&(ot.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${Bn(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`),this.reconnectAttempts++,this.disconnectedRecently()?ot.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${Bn(this.disconnectedAt)} s`):(ot.log("ConnectionMonitor reopening"),this.connection.reopen()))}get refreshedAt(){return this.pingedAt?this.pingedAt:this.startedAt}connectionIsStale(){return Bn(this.refreshedAt)>this.constructor.staleThreshold}disconnectedRecently(){return this.disconnectedAt&&Bn(this.disconnectedAt)<this.constructor.staleThreshold}visibilityDidChange(){document.visibilityState==="visible"&&setTimeout(()=>{(this.connectionIsStale()||!this.connection.isOpen())&&(ot.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`),this.connection.reopen())},200)}}ro.staleThreshold=6,ro.reconnectionBackoffRate=.15;var Xa={message_types:{welcome:"welcome",disconnect:"disconnect",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"},disconnect_reasons:{unauthorized:"unauthorized",invalid_request:"invalid_request",server_restart:"server_restart",remote:"remote"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]};const{message_types:Ye,protocols:oo}=Xa,hl=oo.slice(0,oo.length-1),Qa=[].indexOf;class so{constructor(t){this.open=this.open.bind(this),this.consumer=t,this.subscriptions=this.consumer.subscriptions,this.monitor=new ro(this),this.disconnected=!0}send(t){return this.isOpen()?(this.webSocket.send(JSON.stringify(t)),!0):!1}open(){if(this.isActive())return ot.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1;{const t=[...oo,...this.consumer.subprotocols||[]];return ot.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${t}`),this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new Mn.WebSocket(this.consumer.url,t),this.installEventHandlers(),this.monitor.start(),!0}}close({allowReconnect:t}={allowReconnect:!0}){if(t||this.monitor.stop(),this.isOpen())return this.webSocket.close()}reopen(){if(ot.log(`Reopening WebSocket, current state is ${this.getState()}`),this.isActive())try{return this.close()}catch(t){ot.log("Failed to reopen WebSocket",t)}finally{ot.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}else return this.open()}getProtocol(){if(this.webSocket)return this.webSocket.protocol}isOpen(){return this.isState("open")}isActive(){return this.isState("open","connecting")}triedToReconnect(){return this.monitor.reconnectAttempts>0}isProtocolSupported(){return Qa.call(hl,this.getProtocol())>=0}isState(...t){return Qa.call(t,this.getState())>=0}getState(){if(this.webSocket){for(let t in Mn.WebSocket)if(Mn.WebSocket[t]===this.webSocket.readyState)return t.toLowerCase()}return null}installEventHandlers(){for(let t in this.events){const n=this.events[t].bind(this);this.webSocket[`on${t}`]=n}}uninstallEventHandlers(){for(let t in this.events)this.webSocket[`on${t}`]=function(){}}}so.reopenDelay=500,so.prototype.events={message(e){if(!this.isProtocolSupported())return;const{identifier:t,message:n,reason:r,reconnect:o,type:s}=JSON.parse(e.data);switch(this.monitor.recordMessage(),s){case Ye.welcome:return this.triedToReconnect()&&(this.reconnectAttempted=!0),this.monitor.recordConnect(),this.subscriptions.reload();case Ye.disconnect:return ot.log(`Disconnecting. Reason: ${r}`),this.close({allowReconnect:o});case Ye.ping:return null;case Ye.confirmation:return this.subscriptions.confirmSubscription(t),this.reconnectAttempted?(this.reconnectAttempted=!1,this.subscriptions.notify(t,"connected",{reconnected:!0})):this.subscriptions.notify(t,"connected",{reconnected:!1});case Ye.rejection:return this.subscriptions.reject(t);default:return this.subscriptions.notify(t,"received",n)}},open(){if(ot.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return ot.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close(e){if(ot.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error(){ot.log("WebSocket onerror event")}};const ll=function(e,t){if(t!=null)for(let n in t){const r=t[n];e[n]=r}return e};class gl{constructor(t,n={},r){this.consumer=t,this.identifier=JSON.stringify(n),ll(this,r)}perform(t,n={}){return n.action=t,this.send(n)}send(t){return this.consumer.send({command:"message",identifier:this.identifier,data:JSON.stringify(t)})}unsubscribe(){return this.consumer.subscriptions.remove(this)}}class pl{constructor(t){this.subscriptions=t,this.pendingSubscriptions=[]}guarantee(t){this.pendingSubscriptions.indexOf(t)==-1?(ot.log(`SubscriptionGuarantor guaranteeing ${t.identifier}`),this.pendingSubscriptions.push(t)):ot.log(`SubscriptionGuarantor already guaranteeing ${t.identifier}`),this.startGuaranteeing()}forget(t){ot.log(`SubscriptionGuarantor forgetting ${t.identifier}`),this.pendingSubscriptions=this.pendingSubscriptions.filter(n=>n!==t)}startGuaranteeing(){this.stopGuaranteeing(),this.retrySubscribing()}stopGuaranteeing(){clearTimeout(this.retryTimeout)}retrySubscribing(){this.retryTimeout=setTimeout(()=>{this.subscriptions&&typeof this.subscriptions.subscribe=="function"&&this.pendingSubscriptions.map(t=>{ot.log(`SubscriptionGuarantor resubscribing ${t.identifier}`),this.subscriptions.subscribe(t)})},500)}}class bl{constructor(t){this.consumer=t,this.guarantor=new pl(this),this.subscriptions=[]}create(t,n){const r=t,o=typeof r=="object"?r:{channel:r},s=new gl(this.consumer,o,n);return this.add(s)}add(t){return this.subscriptions.push(t),this.consumer.ensureActiveConnection(),this.notify(t,"initialized"),this.subscribe(t),t}remove(t){return this.forget(t),this.findAll(t.identifier).length||this.sendCommand(t,"unsubscribe"),t}reject(t){return this.findAll(t).map(n=>(this.forget(n),this.notify(n,"rejected"),n))}forget(t){return this.guarantor.forget(t),this.subscriptions=this.subscriptions.filter(n=>n!==t),t}findAll(t){return this.subscriptions.filter(n=>n.identifier===t)}reload(){return this.subscriptions.map(t=>this.subscribe(t))}notifyAll(t,...n){return this.subscriptions.map(r=>this.notify(r,t,...n))}notify(t,n,...r){let o;return typeof t=="string"?o=this.findAll(t):o=[t],o.map(s=>typeof s[n]=="function"?s[n](...r):void 0)}subscribe(t){this.sendCommand(t,"subscribe")&&this.guarantor.guarantee(t)}confirmSubscription(t){ot.log(`Subscription confirmed ${t}`),this.findAll(t).map(n=>this.guarantor.forget(n))}sendCommand(t,n){const{identifier:r}=t;return this.consumer.send({command:n,identifier:r})}}class yl{constructor(t){this._url=t,this.subscriptions=new bl(this),this.connection=new so(this),this.subprotocols=[]}get url(){return wl(this._url)}send(t){return this.connection.send(t)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}addSubProtocol(t){this.subprotocols=[...this.subprotocols,t]}}function wl(e){if(typeof e=="function"&&(e=e()),e&&!/^wss?:/i.test(e)){const t=document.createElement("a");return t.href=e,t.href=t.href,t.protocol=t.protocol.replace("http","ws"),t.href}else return e}function ml(e=vl("url")||Xa.default_mount_path){return new yl(e)}function vl(e){const t=document.head.querySelector(`meta[name='action-cable-${e}']`);if(t)return t.getAttribute("content")}var Sl=200,io="__lodash_hash_undefined__",kl=1/0,tc=9007199254740991,xl="[object Arguments]",Al="[object Function]",Il="[object GeneratorFunction]",Cl="[object Symbol]",El=/[\\^$.*+?()[\]{}|]/g,Ol=/^\[object .+?Constructor\]$/,jl=/^(?:0|[1-9]\d*)$/,Rl=typeof Be=="object"&&Be&&Be.Object===Object&&Be,Tl=typeof self=="object"&&self&&self.Object===Object&&self,ao=Rl||Tl||Function("return this")();function Ul(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function $l(e,t){var n=e?e.length:0;return!!n&&Ml(e,t,0)>-1}function Pl(e,t){for(var n=-1,r=e?e.length:0,o=Array(r);++n<r;)o[n]=t(e[n],n,e);return o}function co(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}function Dl(e,t,n,r){for(var o=e.length,s=n+-1;++s<o;)if(t(e[s],s,e))return s;return-1}function Ml(e,t,n){if(t!==t)return Dl(e,Bl,n);for(var r=n-1,o=e.length;++r<o;)if(e[r]===t)return r;return-1}function Bl(e){return e!==e}function Fl(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function Hl(e,t){return e.has(t)}function Ll(e,t){return e?.[t]}function zl(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}function ec(e,t){return function(n){return e(t(n))}}var Nl=Array.prototype,Vl=Function.prototype,Fn=Object.prototype,uo=ao["__core-js_shared__"],nc=function(){var e=/[^.]+$/.exec(uo&&uo.keys&&uo.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),rc=Vl.toString,Xe=Fn.hasOwnProperty,_o=Fn.toString,Jl=RegExp("^"+rc.call(Xe).replace(El,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),oc=ao.Symbol,Kl=ec(Object.getPrototypeOf,Object),Wl=Fn.propertyIsEnumerable,ql=Nl.splice,sc=oc?oc.isConcatSpreadable:void 0,fo=Object.getOwnPropertySymbols,ic=Math.max,Gl=ac(ao,"Map"),Qe=ac(Object,"create");function ue(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Zl(){this.__data__=Qe?Qe(null):{}}function Yl(e){return this.has(e)&&delete this.__data__[e]}function Xl(e){var t=this.__data__;if(Qe){var n=t[e];return n===io?void 0:n}return Xe.call(t,e)?t[e]:void 0}function Ql(e){var t=this.__data__;return Qe?t[e]!==void 0:Xe.call(t,e)}function tg(e,t){var n=this.__data__;return n[e]=Qe&&t===void 0?io:t,this}ue.prototype.clear=Zl,ue.prototype.delete=Yl,ue.prototype.get=Xl,ue.prototype.has=Ql,ue.prototype.set=tg;function Ie(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function eg(){this.__data__=[]}function ng(e){var t=this.__data__,n=Ln(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():ql.call(t,n,1),!0}function rg(e){var t=this.__data__,n=Ln(t,e);return n<0?void 0:t[n][1]}function og(e){return Ln(this.__data__,e)>-1}function sg(e,t){var n=this.__data__,r=Ln(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}Ie.prototype.clear=eg,Ie.prototype.delete=ng,Ie.prototype.get=rg,Ie.prototype.has=og,Ie.prototype.set=sg;function Ce(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ig(){this.__data__={hash:new ue,map:new(Gl||Ie),string:new ue}}function ag(e){return zn(this,e).delete(e)}function cg(e){return zn(this,e).get(e)}function ug(e){return zn(this,e).has(e)}function _g(e,t){return zn(this,e).set(e,t),this}Ce.prototype.clear=ig,Ce.prototype.delete=ag,Ce.prototype.get=cg,Ce.prototype.has=ug,Ce.prototype.set=_g;function Hn(e){var t=-1,n=e?e.length:0;for(this.__data__=new Ce;++t<n;)this.add(e[t])}function dg(e){return this.__data__.set(e,io),this}function fg(e){return this.__data__.has(e)}Hn.prototype.add=Hn.prototype.push=dg,Hn.prototype.has=fg;function hg(e,t){var n=ho(e)||cc(e)?Fl(e.length,String):[],r=n.length,o=!!r;for(var s in e)o&&(s=="length"||Ig(s,r))||n.push(s);return n}function Ln(e,t){for(var n=e.length;n--;)if(Ug(e[n][0],t))return n;return-1}function lg(e,t,n,r){var o=-1,s=$l,i=!0,a=e.length,c=[],_=t.length;if(!a)return c;t.length>=Sl&&(s=Hl,i=!1,t=new Hn(t));t:for(;++o<a;){var u=e[o],d=u;if(u=u!==0?u:0,i&&d===d){for(var g=_;g--;)if(t[g]===d)continue t;c.push(u)}else s(t,d,r)||c.push(u)}return c}function gg(e,t,n,r,o){var s=-1,i=e.length;for(n||(n=Ag),o||(o=[]);++s<i;){var a=e[s];n(a)?co(o,a):o[o.length]=a}return o}function pg(e,t,n){var r=t(e);return ho(e)?r:co(r,n(e))}function bg(e){if(!lo(e)||Eg(e))return!1;var t=_c(e)||zl(e)?Jl:Ol;return t.test(Tg(e))}function yg(e){if(!lo(e))return jg(e);var t=Og(e),n=[];for(var r in e)r=="constructor"&&(t||!Xe.call(e,r))||n.push(r);return n}function wg(e,t){return e=Object(e),mg(e,t,function(n,r){return r in e})}function mg(e,t,n){for(var r=-1,o=t.length,s={};++r<o;){var i=t[r],a=e[i];n(a,i)&&(s[i]=a)}return s}function vg(e,t){return t=ic(t===void 0?e.length-1:t,0),function(){for(var n=arguments,r=-1,o=ic(n.length-t,0),s=Array(o);++r<o;)s[r]=n[t+r];r=-1;for(var i=Array(t+1);++r<t;)i[r]=n[r];return i[t]=s,Ul(e,this,i)}}function Sg(e){return pg(e,Mg,xg)}function zn(e,t){var n=e.__data__;return Cg(t)?n[typeof t=="string"?"string":"hash"]:n.map}function ac(e,t){var n=Ll(e,t);return bg(n)?n:void 0}var kg=fo?ec(fo,Object):fc,xg=fo?function(e){for(var t=[];e;)co(t,kg(e)),e=Kl(e);return t}:fc;function Ag(e){return ho(e)||cc(e)||!!(sc&&e&&e[sc])}function Ig(e,t){return t=t??tc,!!t&&(typeof e=="number"||jl.test(e))&&e>-1&&e%1==0&&e<t}function Cg(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Eg(e){return!!nc&&nc in e}function Og(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Fn;return e===n}function jg(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}function Rg(e){if(typeof e=="string"||Dg(e))return e;var t=e+"";return t=="0"&&1/e==-kl?"-0":t}function Tg(e){if(e!=null){try{return rc.call(e)}catch{}try{return e+""}catch{}}return""}function Ug(e,t){return e===t||e!==e&&t!==t}function cc(e){return $g(e)&&Xe.call(e,"callee")&&(!Wl.call(e,"callee")||_o.call(e)==xl)}var ho=Array.isArray;function uc(e){return e!=null&&Pg(e.length)&&!_c(e)}function $g(e){return dc(e)&&uc(e)}function _c(e){var t=lo(e)?_o.call(e):"";return t==Al||t==Il}function Pg(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=tc}function lo(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function dc(e){return!!e&&typeof e=="object"}function Dg(e){return typeof e=="symbol"||dc(e)&&_o.call(e)==Cl}function Mg(e){return uc(e)?hg(e):yg(e)}var Bg=vg(function(e,t){return e==null?{}:(t=Pl(gg(t),Rg),wg(e,lg(Sg(e),t)))});function fc(){return[]}var Fg=Bg;const Hg=ln(Fg);class Lg extends sf{#e;constructor(t,n,r,o){super(),this.channelName=t,this.syncableType=n,this.syncableId=r,this.consumer=ml(o),this.#e=!1}connect(t,n){this.peerId=t,this.peerMetadata=n,this.subscription=this.consumer.subscriptions.create({channel:this.channelName,id:this.peerId,metadata:this.peerMetadata||{},syncable_id:this.syncableId,syncable_type:this.syncableType},{connected:()=>{this.#e=!0,this.send({senderId:this.peerId,type:"arrive",targetId:null})},disconnected:()=>{this.#e=!1,this.emit("close")},received:r=>{if(window.message=r,r.targetId!=null&&r.targetId!==this.peerId){if(r.senderId==this.peerId)return;throw new Error("ActionCableNetworkAdapter should never receive messages for a different peer.")}const{senderId:o,type:s}=r;switch(s){case"arrive":{const{peerMetadata:i}=r;this.send({type:"welcome",senderId:this.peerId,peerMetadata:this.peerMetadata,targetId:o}),this.emit("peer-candidate",{peerId:o,peerMetadata:i})}break;case"welcome":{const{peerMetadata:i}=r;this.emit("peer-candidate",{peerId:o,peerMetadata:i})}break;case"leave":this.emit("peer-disconnected",{peerId:o});default:r.data&&Object.values(r.data).length>0?this.emit("message",{...Hg(r,"data"),data:new Uint8Array(Object.values(r.data))}):this.emit("message",r);break}}})}disconnect(){this.subscription&&(this.send({type:"leave",senderId:this.peerId}),this.emit("peer-disconnected",{peerId:this.peerId}),this.subscription.unsubscribe(),this.subscription=void 0)}send(t){if(this.subscription?.send(t),t.data){const n=t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength);this.subscription?.send({...t,data:n})}else this.subscription?.send(t)}whenReady(){return new Promise(t=>{for(;!this.#e;);t()})}isReady(){return this.#e}}class zg{database;store;dbPromise;constructor(t="automerge",n="documents"){this.database=t,this.store=n,this.dbPromise=this.createDatabasePromise()}createDatabasePromise(){return new Promise((t,n)=>{const r=indexedDB.open(this.database,1);r.onerror=()=>{n(r.error)},r.onupgradeneeded=o=>{o.target.result.createObjectStore(this.store)},r.onsuccess=o=>{const s=o.target.result;t(s)}})}async load(t){const n=(await this.dbPromise).transaction(this.store),r=n.objectStore(this.store).get(t);return new Promise((o,s)=>{n.onerror=()=>{s(r.error)},r.onsuccess=i=>{const a=i.target.result;a&&typeof a=="object"&&"binary"in a?o(a.binary):o(void 0)}})}async save(t,n){const r=(await this.dbPromise).transaction(this.store,"readwrite");return r.objectStore(this.store).put({key:t,binary:n},t),new Promise((o,s)=>{r.onerror=()=>{s(r.error)},r.oncomplete=()=>{o()}})}async remove(t){const n=(await this.dbPromise).transaction(this.store,"readwrite");return n.objectStore(this.store).delete(t),new Promise((r,o)=>{n.onerror=()=>{o(n.error)},n.oncomplete=()=>{r()}})}async loadRange(t){const n=await this.dbPromise,r=t,o=[...t,"\uFFFF"],s=IDBKeyRange.bound(r,o),i=n.transaction(this.store),a=i.objectStore(this.store).openCursor(s),c=[];return new Promise((_,u)=>{i.onerror=()=>{u(a.error)},a.onsuccess=d=>{const g=d.target.result;g?(c.push({data:g.value.binary,key:g.key}),g.continue()):_(c)}})}async removeRange(t){const n=await this.dbPromise,r=t,o=[...t,"\uFFFF"],s=IDBKeyRange.bound(r,o),i=n.transaction(this.store,"readwrite");return i.objectStore(this.store).delete(s),new Promise((a,c)=>{i.onerror=()=>{c(i.error)},i.oncomplete=()=>{a()}})}}const Ng=new Proxy(of,{construct:(e,t)=>{const[n,r,o="ActionMerge::SyncChannel",s={}]=t;return new e({network:[new Lg(o,n,r)],storage:new zg,...s})}});window.Syncable=Ng,window.Am=Du})();