@solarpunkltd/swarm-chat-js 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@ethersphere/bee-js"),P=[];for(let a=0;a<256;++a)P.push((a+256).toString(16).slice(1));function Sl(a,n=0){return(P[a[n+0]]+P[a[n+1]]+P[a[n+2]]+P[a[n+3]]+"-"+P[a[n+4]]+P[a[n+5]]+"-"+P[a[n+6]]+P[a[n+7]]+"-"+P[a[n+8]]+P[a[n+9]]+"-"+P[a[n+10]]+P[a[n+11]]+P[a[n+12]]+P[a[n+13]]+P[a[n+14]]+P[a[n+15]]).toLowerCase()}let gn;const Tl=new Uint8Array(16);function Ol(){if(!gn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");gn=crypto.getRandomValues.bind(crypto)}return gn(Tl)}const Il=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Gs={randomUUID:Il};function Ml(a,n,i){if(Gs.randomUUID&&!n&&!a)return Gs.randomUUID();a=a||{};const c=a.random||(a.rng||Ol)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,Sl(c)}function $l(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var ti={};(function(a){var n;Object.defineProperty(a,"__esModule",{value:!0}),a.Vector=a.Cache=a.Assertions=a.Strings=a.Types=a.Objects=a.Dates=a.Promises=a.Numbers=a.System=a.Arrays=a.Random=a.Elliptic=a.Binary=a.AsyncQueue=a.PubSubChannel=a.FixedPointNumber=a.MerkleTree=a.Chunk=a.Uint8ArrayWriter=a.Uint8ArrayReader=a.AsyncLazy=a.Lazy=a.Optional=void 0;async function i(e){return new Promise((t,r)=>e.then(r,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const r=ws(e,t),s=[],o=r.map(async l=>{for(const f of l)s.push(await f())});return await Promise.all(o),s}async function d(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function h(e,t=Math.random){for(let r=e.length-1;r>0;r--){const s=Math.floor(t()*(r+1)),o=e[r];e[r]=e[s],e[s]=o}return e}function m(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function w(e){return e.length===1?e[0]:null}function v(e){return e.length>0?e[0]:null}function E(e){if(!e.length)throw Error("Received empty array");return e[0]}function D(e,t){const r=[];for(let s=0;s<e;s++)r.push(t(s));return r}function re(e){const t=[];for(let r=0;r<e[0].length;r++){t.push([]);for(let s=0;s<e.length;s++)t[r].push(e[s][r])}return t}function ne(e,t,r){const s=[];for(let o=0;o<e;o++){s.push([]);for(let l=0;l<t;l++)s[o].push(r)}return s}function Be(e,t,r,s){if(r<0||s<0||s+t[0].length>e[0].length||r+t.length>e.length)return!1;for(let o=0;o<t.length;o++)for(let l=0;l<t[o].length;l++)if(t[o][l]!==void 0&&e[r+o][s+l]!==t[o][l])return!1;return!0}function Se(e,t,r=Math.random){return h(Ln(0,e.length-1),r).slice(0,t)}function zt(e,t){return e.map(r=>r[t])}function Vt(e){let t=e,r=3405648695,s=3735928559;return function(){return t+=r,r^=t<<7,t*=s,s^=t<<13,t^=r^s,(t>>>0)/4294967296}}function Le(e,t,r=Math.random){return Math.floor(r()*(t-e+1))+e}function Sn(e,t,r=Math.random){return r()*(t-e)+e}function mi(){return Math.random()*2-1}function pi(e,t,r){return t>=e.x&&t<e.x+e.width&&r>=e.y&&r<e.y+e.height}function gi(e,t,r,s=Math.random){let o,l;do o=Le(0,e-1,s),l=Le(0,t-1,s);while(r&&pi(r,o,l));return[o,l]}function yi(e,t=Math.random){const r=Math.floor(e),s=e-r;return Tn(s,t)?r+1:r}function Tn(e,t=Math.random){return t()<e}function Wt(e,t=Math.random){return e[Math.floor(e.length*t())]}function vi(e,t,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return Se(e,t,r).map(s=>e[s])}function wi(e,t,r,s=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const o=[];for(;o.length<t;){const l=Wt(e,s);o.some(f=>r(f,l))||o.push(l)}return o}function bi(e,t,r,s,o,l=Math.random){const f=e.filter(p=>p!==t&&p!==r),g=[];for(t!==null&&g.push(t);f.length&&g.length<s;){const p=a.Random.intBetween(0,f.length-1,l);o(f[p],g)&&g.push(f[p]),f.splice(p,1)}return h(g,l),{values:g,indexOfGuaranteed:t!==null?g.indexOf(t):-1}}function Fe(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function On(e,t,r){return r(t.reduce((s,o)=>o(s),e))}function _i(e,t){return r=>On(r,e,t)}function xi(e,t,r){if(r===void 0&&(r=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((l,f)=>l+f,0);const o=r*s;for(let l=0;l<e.length-1;l++)if(s-=t[l],o>=s)return e[l];return Fe(e)}function ki(e,t,r=Math.random){const s=t.map(l=>r()*l),o=[];for(let l=0;l<e.length;l++)o.push([e[l],s[l]]);return o.sort((l,f)=>f[1]-l[1]).map(l=>l[0])}function ge(e,t){if(e==null)return null;const r=t.split(".");let s=e;for(const o of r){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function ye(e,t,r){const s=t.split(/\.|\[/);let o=e;for(let l=0;l<s.length;l++){const f=s[l],g=l<s.length-1&&s[l+1].includes("]"),p=f.includes("]")?f.replace(/\[|\]/g,""):f;if(l===s.length-1)return o[p]=r,r;ce(o[p])||(g?o[p]=[]:o[p]={}),o=o[p]}return r}function Ei(e,t,r=1){const s=ge(e,t)||0;return ye(e,t,s+r),s}function Ai(e,t,r){return ge(e,t)||ye(e,t,r)}function Si(e,t){const r=er(t,"."),s=zn(t,".");if(!r||!s)return;const o=ge(e,r);delete o[s]}function Ti(e,t,r){const s=ge(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return ye(e,t,r),s}function Oi(e,t,r){for(const s of t){const o=ge(e,s);if(o)return o}if(r){const s=Object.values(e);if(s.length)return s[0]}return null}async function Ii(e,t,r){for(;;){try{await e()}catch(s){r&&r("Error in forever",s)}await d(t)}}function Mi(e,t){e();const r=setInterval(()=>{e()},t);return()=>clearInterval(r)}function $i(e){return e/1024/1024}function Ci(e){return e>=1024*1024*1024*1024?(e/1024/1024/1024/1024).toFixed(3)+" TB":e>=1024*1024*1024?(e/1024/1024/1024).toFixed(3)+" GB":e>=1024*1024?(e/1024/1024).toFixed(3)+" MB":e>=1024?(e/1024).toFixed(3)+" KB":e+" B"}function Ni(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}function Ri(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function Di(e,t,r,s){const o=e*Math.PI/180,l=r*Math.PI/180,f=(r-e)*Math.PI/180,g=(s-t)*Math.PI/180,p=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(l)*Math.sin(g/2)*Math.sin(g/2);return 6371e3*(2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p)))}function bt(e,t){return Math.round(e/t)*t}function ji(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?bt(e,100)+" m":e>=100?bt(e,50)+" m":bt(e,10)+" m"}function Ui(e){return e*(e+1)/2}function Pi(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function ce(e,t=!0){return!e||t&&!Ht(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||e.constructor.name=="Uint8Array"||e.constructor.name==="ArrayBuffer"||e.constructor.name==="ReadableStream")?!1:typeof e=="object"}function Te(e){return ce(e)&&!Array.isArray(e)}function In(e){return Array.isArray(e)&&e.length===0}function Zi(e){return Te(e)&&Object.keys(e).length===0}function Ht(e){return e===void 0}function qt(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function V(e){return Object.prototype.toString.call(e)==="[object String]"}function ue(e){return typeof e=="number"&&isFinite(e)}function Mn(e){return e===!0||e===!1}function Oe(e){return Object.prototype.toString.call(e)==="[object Date]"}function _t(e){return!V(e)||e.trim().length===0}function Gt(e){return ue(e)&&Number.isInteger(e)&&e>=1}function $n(e){return V(e)&&e.match(/^-?\d+$/)!==null}function Cn(e){return V(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const Bi="!@#$%^&*()_+-=[]{}|;:<>?,./",Li="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),Kt="abcdefghijklmnopqrstuvwxyz",Fi="ABCDEFGHIJKLMNOPQRSTUVWXYZ",zi="1234567890",Jt=Kt+Fi+zi,Nn=Jt+Bi,Rn=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],Dn="0123456789abcdef";function Vi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Kt[Math.floor(t()*Kt.length)];return r}function Wi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Jt[Math.floor(t()*Jt.length)];return r}function Hi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Nn[Math.floor(t()*Nn.length)];return r}function qi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Rn[Math.floor(t()*Rn.length)];return r}function Gi(e,t){const r=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(r);return s?s[0]:null}function Ki(e,t,r=Li){const s=Vn(e,r);for(const o of s)if(t(o))return o;return null}function Ji(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Dn[Math.floor(t()*Dn.length)];return r}function Yi(e,t){if(!$n(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=BigInt(e);if(t&&(t.min&&r<t.min||t.max&&r>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+r);return e}function jn(e,t){if(_t(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);if(t&&(t.min!==void 0&&e.length<t.min||t.max!==void 0&&e.length>t.max))throw RangeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function Qi(e,t){if(!Cn(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.replace(/^0x/,"");if(t&&t.byteLength&&r.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+r);return r}function Xi(e,t){if(!jn(e,t).split("").every(r=>r==="_"||We(r)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Un(e,t){if(t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max)throw RangeError(`Expected value${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function ea(e,t){if(!qt(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function xt(e,t){if(ue(e))return t&&Un(e,t),e;if(!V(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=parseFloat(e);return t&&Un(r,t),r}function Yt(e,t){return xt(e,t)|0}function ta(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!Mn(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ra(e,t){if(!Oe(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function na(e){return _t(e)?null:e}function sa(e,t){if(!V(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ia(e,t){if(Gt(e))return e;const r=parseInt(e,10);if(!Gt(r))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function aa(e,t){if(!V(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.split(":");if(r.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(r[0],10),o=parseInt(r[1],10);if(!ue(s)||!ue(o)||s<0||s>23||o<0||o>59)throw new TypeError(`Expected time, got${t!=null&&t.name?` for ${t.name}`:""}: `+e);return`${String(s).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function oa(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function kt(e,t){if(!Te(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ca(e,t){return e===null?null:kt(e,t)}function ua(e,t){const r=kt(e,t);for(const s of Object.keys(r))if(!V(r[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function la(e,t){const r=kt(e),s=Object.keys(r),o=Object.values(r);if(!s.every(V)||!o.every(ue))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function Pn(e){return V(e)&&e.match(/^https?:\/\/.+/)!==null}function da(e,t){if(!Pn(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function fa(e,t){return t==null?!0:e(t)}function ha(e,t){return t==null?null:e(t)}function ma(e,t){return t==null?void 0:e(t)}function Zn(e,t){for(const[r,s]of Object.entries(t))if(!s(e[r]))throw TypeError(`${r} in value does not exist or match shape`);for(const r of Object.keys(e))if(!t[r])throw TypeError(`${r} exists in value but not in shape`);return!0}function pa(e,t){return e.every(r=>Zn(r,t))}function ze(e,t="json",r=0){if(ce(e,!1)){if(r>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(l=>ze(l,"json",r+1));return r===0?JSON.stringify(o):o}const s={};e.message&&(s.message=ze(e.message,"json",r+1));for(const[o,l]of Object.entries(e))s[o]=ze(l,"json",r+1);return r===0?JSON.stringify(s):s}else if(t==="key-value"){const s=Object.keys(e);return e.message&&!s.includes("message")&&s.unshift("message"),s.map(o=>`${o}=${JSON.stringify(ze(e[o],"json",r+1))}`).join(" ")}}return Ht(e)&&(e="undefined"),r===0?JSON.stringify(e):e}function ga(e,t){if(V(e))return e;const r=Object.keys(e);e.message&&!r.includes("message")&&r.push("message");const s=r.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
- `+e.stack:s}function ve(e,t){if(Te(e)&&Te(t))for(const r in t)Te(t[r])?(e[r]||(e[r]={}),ve(e[r],t[r])):Array.isArray(t[r])?e[r]=[...t[r]]:(t[r]!==null&&t[r]!==void 0||e[r]===null||e[r]===void 0)&&(e[r]=t[r]);return e}function ya(e,t){const r={};return ve(r,e),ve(r,t),r}function va(e,t,r){const s={};return ve(s,e),ve(s,t),ve(s,r),s}function Bn(e,t){const r={};for(const s of e)for(const o of Object.keys(s))r[o]?r[o]=t(r[o],s[o]):r[o]=s[o];return r}function wa(e){return Bn(e,(t,r)=>t+r)}function ba(e,t,r){e[t]||(e[t]=[]),e[t].push(r)}function _a(e,t,r){for(e.unshift(t);e.length>r;)e.pop()}function xa(e,t){let r=t%e.length;return r<0&&(r+=e.length),e[r]}function Et(e,t){Array.prototype.push.apply(e,t)}function ka(e,t){Array.prototype.unshift.apply(e,t)}async function Ea(e,t){const r=[];for(const s of e)r.push(await t(s));return r}function Aa(e,t){const r=[];for(let s=0;s<e.length;s++)r.push(e[s]),s<e.length-1&&(qt(t)?r.push(t()):r.push(t));return r}function Sa(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function Ta(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function Oa(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function Ia(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function Ma(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function $a(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function Ca(e,t){for(let r=0;r<e.length;r++){const s=e[r],o=t[r],l=Math.max(0,o.getTime()-Date.now());setTimeout(s,l)}}function Na(e,t,r){return e+(t-e)*r}function Ra(e){return e.reduce((t,r)=>t+r,0)}function Da(e){return e.reduce((t,r)=>t+r,0)/e.length}function ja(e){const t=[...e].sort((s,o)=>s-o),r=Math.floor(t.length/2);return t.length%2===0?(t[r]+t[r-1])/2:t[r]}function Ua(e,t){return e-(t-1)/2}function Ln(e,t){const r=[];for(let s=e;s<=t;s++)r.push(s);return r}function Pa(e,t){return t.some(r=>e.includes(r))}function Za(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function Qt(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(r=>/[a-z0-9]/.test(r)||t(r)?r:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Ba(e){return Qt(e).replaceAll("-","")}function La(e){return St(e.replace(/([A-Z])/g," $1"))}function Fa(e){return e.split("-").map(St).join(" ")}function za(e){return Hn(e.split("-").map(St).join(""))}function Va(e,t=", ",r=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${r}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${r}${e[e.length-1]}`}function Wa(e,t){return t+e.split("").join(t)+t}function Ha(e){return Qt(e).replace(/-/g,"_").toUpperCase()}function At(e,t){if(t.length===0)return 0;const r=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:r.startsWith(s)?1e4-e.length:r.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(r)?1e3-e.length:0}function qa(e,t){return e.filter(r=>At(r,t)).sort((r,s)=>At(s,t)-At(r,t))}function Ga(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const Ka={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function Ja(e){let t=e.replace(/&#(\d+);/g,(r,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(r,s)=>String.fromCharCode(parseInt(s,16)));for(const[r,s]of Object.entries(Ka))t=t.replaceAll(r,s);return t}function Fn(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(0,r)}function Xt(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(r+t.length)}function er(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(0,r)}function zn(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(r+t.length)}function Ya(e,t,r){const s=er(e,r);return s?Xt(s,t):null}function Qa(e,t,r){const s=Xt(e,t);return s?Fn(s,r):null}function tr(e,t,r=!1){const s=r?e.lastIndexOf(t):e.indexOf(t);return s===-1?r?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function Vn(e,t){let r=[e];for(const s of t)r=r.flatMap(o=>o.split(s));return r.filter(s=>s)}function rr(e){const t=Fe(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?"":t.slice(r+1)}function nr(e){const t=Fe(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?t:t.slice(0,r)}function Xa(e){let[t,r]=e.split("@");t=Ve(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!r||r.indexOf(".")===-1||r.indexOf(".")===r.length-1)throw new Error("Invalid email");return r=Ve(r.toLowerCase()).replaceAll(" ",""),`${s}@${r}`}function eo(e){const t=nr(e),r=rr(e);return r?`${t}.${r}`:t}function to(e){const t=nr(e),r=rr(e);return{basename:t,extension:r,filename:r?`${t}.${r}`:t}}function ro(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(r,s)=>Wt(s.split("|"),t))}function Wn(e){const t=/\{(.+?)\}/,r=e.match(t);if(!r||!r.index)return[e];const s=r[1].split(","),o=e.slice(0,r.index),l=e.slice(r.index+r[0].length);let f=[];for(const g of s){const p=Wn(o+g+l);f=f.concat(p)}return f}function Ve(e){return e.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@ethersphere/bee-js"),P=[];for(let a=0;a<256;++a)P.push((a+256).toString(16).slice(1));function Al(a,n=0){return(P[a[n+0]]+P[a[n+1]]+P[a[n+2]]+P[a[n+3]]+"-"+P[a[n+4]]+P[a[n+5]]+"-"+P[a[n+6]]+P[a[n+7]]+"-"+P[a[n+8]]+P[a[n+9]]+"-"+P[a[n+10]]+P[a[n+11]]+P[a[n+12]]+P[a[n+13]]+P[a[n+14]]+P[a[n+15]]).toLowerCase()}let yn;const Ol=new Uint8Array(16);function Il(){if(!yn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");yn=crypto.getRandomValues.bind(crypto)}return yn(Ol)}const $l=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ks={randomUUID:$l};function Ml(a,n,i){if(Ks.randomUUID&&!n&&!a)return Ks.randomUUID();a=a||{};const c=a.random||(a.rng||Il)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,Al(c)}function Cl(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var ri={};(function(a){var n;Object.defineProperty(a,"__esModule",{value:!0}),a.Vector=a.Cache=a.Assertions=a.Strings=a.Types=a.Objects=a.Dates=a.Promises=a.Numbers=a.System=a.Arrays=a.Random=a.Elliptic=a.Binary=a.AsyncQueue=a.PubSubChannel=a.FixedPointNumber=a.MerkleTree=a.Chunk=a.Uint8ArrayWriter=a.Uint8ArrayReader=a.AsyncLazy=a.Lazy=a.Optional=void 0;async function i(e){return new Promise((t,r)=>e.then(r,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const r=bs(e,t),s=[],o=r.map(async d=>{for(const f of d)s.push(await f())});return await Promise.all(o),s}async function l(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function h(e,t=Math.random){for(let r=e.length-1;r>0;r--){const s=Math.floor(t()*(r+1)),o=e[r];e[r]=e[s],e[s]=o}return e}function m(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function w(e){return e.length===1?e[0]:null}function v(e){return e.length>0?e[0]:null}function E(e){if(!e.length)throw Error("Received empty array");return e[0]}function j(e,t){const r=[];for(let s=0;s<e;s++)r.push(t(s));return r}function re(e){const t=[];for(let r=0;r<e[0].length;r++){t.push([]);for(let s=0;s<e.length;s++)t[r].push(e[s][r])}return t}function ne(e,t,r){const s=[];for(let o=0;o<e;o++){s.push([]);for(let d=0;d<t;d++)s[o].push(r)}return s}function Le(e,t,r,s){if(r<0||s<0||s+t[0].length>e[0].length||r+t.length>e.length)return!1;for(let o=0;o<t.length;o++)for(let d=0;d<t[o].length;d++)if(t[o][d]!==void 0&&e[r+o][s+d]!==t[o][d])return!1;return!0}function Ae(e,t,r=Math.random){return h(zn(0,e.length-1),r).slice(0,t)}function Vt(e,t){return e.map(r=>r[t])}function Wt(e){let t=e,r=3405648695,s=3735928559;return function(){return t+=r,r^=t<<7,t*=s,s^=t<<13,t^=r^s,(t>>>0)/4294967296}}function ze(e,t,r=Math.random){return Math.floor(r()*(t-e+1))+e}function An(e,t,r=Math.random){return r()*(t-e)+e}function pi(){return Math.random()*2-1}function gi(e,t,r){return t>=e.x&&t<e.x+e.width&&r>=e.y&&r<e.y+e.height}function yi(e,t,r,s=Math.random){let o,d;do o=ze(0,e-1,s),d=ze(0,t-1,s);while(r&&gi(r,o,d));return[o,d]}function vi(e,t=Math.random){const r=Math.floor(e),s=e-r;return On(s,t)?r+1:r}function On(e,t=Math.random){return t()<e}function Ht(e,t=Math.random){return e[Math.floor(e.length*t())]}function wi(e,t,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return Ae(e,t,r).map(s=>e[s])}function bi(e,t,r,s=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const o=[];for(;o.length<t;){const d=Ht(e,s);o.some(f=>r(f,d))||o.push(d)}return o}function _i(e,t,r,s,o,d=Math.random){const f=e.filter(p=>p!==t&&p!==r),g=[];for(t!==null&&g.push(t);f.length&&g.length<s;){const p=a.Random.intBetween(0,f.length-1,d);o(f[p],g)&&g.push(f[p]),f.splice(p,1)}return h(g,d),{values:g,indexOfGuaranteed:t!==null?g.indexOf(t):-1}}function Fe(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function In(e,t,r){return r(t.reduce((s,o)=>o(s),e))}function xi(e,t){return r=>In(r,e,t)}function ki(e,t,r){if(r===void 0&&(r=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((d,f)=>d+f,0);const o=r*s;for(let d=0;d<e.length-1;d++)if(s-=t[d],o>=s)return e[d];return Fe(e)}function Ei(e,t,r=Math.random){const s=t.map(d=>r()*d),o=[];for(let d=0;d<e.length;d++)o.push([e[d],s[d]]);return o.sort((d,f)=>f[1]-d[1]).map(d=>d[0])}function ye(e,t){if(e==null)return null;const r=t.split(".");let s=e;for(const o of r){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function ve(e,t,r){const s=t.split(/\.|\[/);let o=e;for(let d=0;d<s.length;d++){const f=s[d],g=d<s.length-1&&s[d+1].includes("]"),p=f.includes("]")?f.replace(/\[|\]/g,""):f;if(d===s.length-1)return o[p]=r,r;ue(o[p])||(g?o[p]=[]:o[p]={}),o=o[p]}return r}function Si(e,t,r=1){const s=ye(e,t)||0;return ve(e,t,s+r),s}function Ti(e,t,r){return ye(e,t)||ve(e,t,r)}function Ai(e,t){const r=tr(t,"."),s=Vn(t,".");if(!r||!s)return;const o=ye(e,r);delete o[s]}function Oi(e,t,r){const s=ye(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return ve(e,t,r),s}function Ii(e,t,r){for(const s of t){const o=ye(e,s);if(o)return o}if(r){const s=Object.values(e);if(s.length)return s[0]}return null}async function $i(e,t,r){for(;;){try{await e()}catch(s){r&&r("Error in forever",s)}await l(t)}}function Mi(e,t){e();const r=setInterval(()=>{e()},t);return()=>clearInterval(r)}function Ci(e){return e/1024/1024}function Ni(e){return e>=1024*1024*1024*1024?(e/1024/1024/1024/1024).toFixed(3)+" TB":e>=1024*1024*1024?(e/1024/1024/1024).toFixed(3)+" GB":e>=1024*1024?(e/1024/1024).toFixed(3)+" MB":e>=1024?(e/1024).toFixed(3)+" KB":e+" B"}function Ri(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}function ji(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function Di(e,t,r,s){const o=e*Math.PI/180,d=r*Math.PI/180,f=(r-e)*Math.PI/180,g=(s-t)*Math.PI/180,p=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(d)*Math.sin(g/2)*Math.sin(g/2);return 6371e3*(2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p)))}function _t(e,t){return Math.round(e/t)*t}function Ui(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?_t(e,100)+" m":e>=100?_t(e,50)+" m":_t(e,10)+" m"}function Pi(e){return e*(e+1)/2}function Zi(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function ue(e,t=!0){return!e||t&&!qt(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||e.constructor.name=="Uint8Array"||e.constructor.name==="ArrayBuffer"||e.constructor.name==="ReadableStream")?!1:typeof e=="object"}function Oe(e){return ue(e)&&!Array.isArray(e)}function $n(e){return Array.isArray(e)&&e.length===0}function Bi(e){return Oe(e)&&Object.keys(e).length===0}function qt(e){return e===void 0}function Gt(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function V(e){return Object.prototype.toString.call(e)==="[object String]"}function le(e){return typeof e=="number"&&isFinite(e)}function Mn(e){return e===!0||e===!1}function Ie(e){return Object.prototype.toString.call(e)==="[object Date]"}function xt(e){return!V(e)||e.trim().length===0}function Kt(e){return le(e)&&Number.isInteger(e)&&e>=1}function Cn(e){return V(e)&&e.match(/^-?\d+$/)!==null}function Nn(e){return V(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const Li="!@#$%^&*()_+-=[]{}|;:<>?,./",zi="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),Jt="abcdefghijklmnopqrstuvwxyz",Fi="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Vi="1234567890",Yt=Jt+Fi+Vi,Rn=Yt+Li,jn=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],Dn="0123456789abcdef";function Wi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Jt[Math.floor(t()*Jt.length)];return r}function Hi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Yt[Math.floor(t()*Yt.length)];return r}function qi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Rn[Math.floor(t()*Rn.length)];return r}function Gi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=jn[Math.floor(t()*jn.length)];return r}function Ki(e,t){const r=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(r);return s?s[0]:null}function Ji(e,t,r=zi){const s=Wn(e,r);for(const o of s)if(t(o))return o;return null}function Yi(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=Dn[Math.floor(t()*Dn.length)];return r}function Qi(e,t){if(!Cn(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=BigInt(e);if(t&&(t.min&&r<t.min||t.max&&r>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+r);return e}function Un(e,t){if(xt(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);if(t&&(t.min!==void 0&&e.length<t.min||t.max!==void 0&&e.length>t.max))throw RangeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function Xi(e,t){if(!Nn(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.replace(/^0x/,"");if(t&&t.byteLength&&r.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+r);return r}function ea(e,t){if(!Un(e,t).split("").every(r=>r==="_"||He(r)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Pn(e,t){if(t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max)throw RangeError(`Expected value${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function ta(e,t){if(!Gt(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function kt(e,t){if(le(e))return t&&Pn(e,t),e;if(!V(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=parseFloat(e);return t&&Pn(r,t),r}function Qt(e,t){return kt(e,t)|0}function ra(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!Mn(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function na(e,t){if(!Ie(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function sa(e){return xt(e)?null:e}function ia(e,t){if(!V(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function aa(e,t){if(Kt(e))return e;const r=parseInt(e,10);if(!Kt(r))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function oa(e,t){if(!V(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.split(":");if(r.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(r[0],10),o=parseInt(r[1],10);if(!le(s)||!le(o)||s<0||s>23||o<0||o>59)throw new TypeError(`Expected time, got${t!=null&&t.name?` for ${t.name}`:""}: `+e);return`${String(s).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function ca(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Et(e,t){if(!Oe(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ua(e,t){return e===null?null:Et(e,t)}function la(e,t){const r=Et(e,t);for(const s of Object.keys(r))if(!V(r[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function da(e,t){const r=Et(e),s=Object.keys(r),o=Object.values(r);if(!s.every(V)||!o.every(le))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function Zn(e){return V(e)&&e.match(/^https?:\/\/.+/)!==null}function fa(e,t){if(!Zn(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ha(e,t){return t==null?!0:e(t)}function ma(e,t){return t==null?null:e(t)}function pa(e,t){return t==null?void 0:e(t)}function Bn(e,t){for(const[r,s]of Object.entries(t))if(!s(e[r]))throw TypeError(`${r} in value does not exist or match shape`);for(const r of Object.keys(e))if(!t[r])throw TypeError(`${r} exists in value but not in shape`);return!0}function ga(e,t){return e.every(r=>Bn(r,t))}function Ve(e,t="json",r=0){if(ue(e,!1)){if(r>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(d=>Ve(d,"json",r+1));return r===0?JSON.stringify(o):o}const s={};e.message&&(s.message=Ve(e.message,"json",r+1));for(const[o,d]of Object.entries(e))s[o]=Ve(d,"json",r+1);return r===0?JSON.stringify(s):s}else if(t==="key-value"){const s=Object.keys(e);return e.message&&!s.includes("message")&&s.unshift("message"),s.map(o=>`${o}=${JSON.stringify(Ve(e[o],"json",r+1))}`).join(" ")}}return qt(e)&&(e="undefined"),r===0?JSON.stringify(e):e}function ya(e,t){if(V(e))return e;const r=Object.keys(e);e.message&&!r.includes("message")&&r.push("message");const s=r.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
+ `+e.stack:s}function we(e,t){if(Oe(e)&&Oe(t))for(const r in t)Oe(t[r])?(e[r]||(e[r]={}),we(e[r],t[r])):Array.isArray(t[r])?e[r]=[...t[r]]:(t[r]!==null&&t[r]!==void 0||e[r]===null||e[r]===void 0)&&(e[r]=t[r]);return e}function va(e,t){const r={};return we(r,e),we(r,t),r}function wa(e,t,r){const s={};return we(s,e),we(s,t),we(s,r),s}function Ln(e,t){const r={};for(const s of e)for(const o of Object.keys(s))r[o]?r[o]=t(r[o],s[o]):r[o]=s[o];return r}function ba(e){return Ln(e,(t,r)=>t+r)}function _a(e,t,r){e[t]||(e[t]=[]),e[t].push(r)}function xa(e,t,r){for(e.unshift(t);e.length>r;)e.pop()}function ka(e,t){let r=t%e.length;return r<0&&(r+=e.length),e[r]}function St(e,t){Array.prototype.push.apply(e,t)}function Ea(e,t){Array.prototype.unshift.apply(e,t)}async function Sa(e,t){const r=[];for(const s of e)r.push(await t(s));return r}function Ta(e,t){const r=[];for(let s=0;s<e.length;s++)r.push(e[s]),s<e.length-1&&(Gt(t)?r.push(t()):r.push(t));return r}function Aa(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function Oa(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function Ia(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function $a(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function Ma(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function Ca(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function Na(e,t){for(let r=0;r<e.length;r++){const s=e[r],o=t[r],d=Math.max(0,o.getTime()-Date.now());setTimeout(s,d)}}function Ra(e,t,r){return e+(t-e)*r}function ja(e){return e.reduce((t,r)=>t+r,0)}function Da(e){return e.reduce((t,r)=>t+r,0)/e.length}function Ua(e){const t=[...e].sort((s,o)=>s-o),r=Math.floor(t.length/2);return t.length%2===0?(t[r]+t[r-1])/2:t[r]}function Pa(e,t){return e-(t-1)/2}function zn(e,t){const r=[];for(let s=e;s<=t;s++)r.push(s);return r}function Za(e,t){return t.some(r=>e.includes(r))}function Ba(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function Xt(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(r=>/[a-z0-9]/.test(r)||t(r)?r:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function La(e){return Xt(e).replaceAll("-","")}function za(e){return At(e.replace(/([A-Z])/g," $1"))}function Fa(e){return e.split("-").map(At).join(" ")}function Va(e){return qn(e.split("-").map(At).join(""))}function Wa(e,t=", ",r=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${r}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${r}${e[e.length-1]}`}function Ha(e,t){return t+e.split("").join(t)+t}function qa(e){return Xt(e).replace(/-/g,"_").toUpperCase()}function Tt(e,t){if(t.length===0)return 0;const r=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:r.startsWith(s)?1e4-e.length:r.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(r)?1e3-e.length:0}function Ga(e,t){return e.filter(r=>Tt(r,t)).sort((r,s)=>Tt(s,t)-Tt(r,t))}function Ka(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const Ja={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function Ya(e){let t=e.replace(/&#(\d+);/g,(r,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(r,s)=>String.fromCharCode(parseInt(s,16)));for(const[r,s]of Object.entries(Ja))t=t.replaceAll(r,s);return t}function Fn(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(0,r)}function er(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(r+t.length)}function tr(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(0,r)}function Vn(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(r+t.length)}function Qa(e,t,r){const s=tr(e,r);return s?er(s,t):null}function Xa(e,t,r){const s=er(e,t);return s?Fn(s,r):null}function rr(e,t,r=!1){const s=r?e.lastIndexOf(t):e.indexOf(t);return s===-1?r?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function Wn(e,t){let r=[e];for(const s of t)r=r.flatMap(o=>o.split(s));return r.filter(s=>s)}function nr(e){const t=Fe(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?"":t.slice(r+1)}function sr(e){const t=Fe(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?t:t.slice(0,r)}function eo(e){let[t,r]=e.split("@");t=We(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!r||r.indexOf(".")===-1||r.indexOf(".")===r.length-1)throw new Error("Invalid email");return r=We(r.toLowerCase()).replaceAll(" ",""),`${s}@${r}`}function to(e){const t=sr(e),r=nr(e);return r?`${t}.${r}`:t}function ro(e){const t=sr(e),r=nr(e);return{basename:t,extension:r,filename:r?`${t}.${r}`:t}}function no(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(r,s)=>Ht(s.split("|"),t))}function Hn(e){const t=/\{(.+?)\}/,r=e.match(t);if(!r||!r.index)return[e];const s=r[1].split(","),o=e.slice(0,r.index),d=e.slice(r.index+r[0].length);let f=[];for(const g of s){const p=Hn(o+g+d);f=f.concat(p)}return f}function We(e){return e.split(`
3
3
  `).map(t=>t.trim().replace(/\s+/g," ")).filter(t=>t.length>0).join(`
4
- `)}function St(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Hn(e){return e.charAt(0).toLowerCase()+e.slice(1)}function qn(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function Gn(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function We(e){return qn(e)||Gn(e)}const no=`
5
- \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function so(e){return no.includes(e)}function io(e){return We(e)||e==="."||e==="["||e==="]"||e==="_"}function ao(e,t,r,s,o){return e.slice(0,t)+s+e.slice(t,t+r)+o+e.slice(t+r)}function Kn(e,t,r=0){const s=t.exec(e.slice(r));return s?{index:s.index,match:s[0]}:null}function Jn(e,t,r=!0){if(!r)return t.every(o=>o instanceof RegExp?o.test(e):e.indexOf(o,0)!==-1);let s=0;for(const o of t)if(o instanceof RegExp){const l=Kn(e,o,s);if(!l)return!1;s=l.index+l.match.length}else{const l=e.indexOf(o,s);if(l===-1)return!1;s=l+o.length}return!0}function oo(e,t,r=!0){let s=0;for(const o of t){let l=!1;for(;!l&&s<e.length;)Jn(e[s],o,r)&&(l=!0),s++;if(!l)return!1}return!0}function co(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function Ie(e,t,r=0){let s=-1;for(const o of t){const l=e.indexOf(o,r);l!==-1&&(s===-1||l<s)&&(s=l)}return s}function uo(e,t=0){for(let r=t;r<e.length;r++)if(so(e[r]))return r;return-1}function lo(e,t=0){for(let r=t;r<e.length;r++)if(e[r]==="#"&&We(e[r+1]))return r;return-1}function Yn(e,t,r=0){return e.slice(0,r).lastIndexOf(t)}function Qn(e,t=0,r="{",s="}"){let o=1;for(let l=t;l<e.length;l++)if(e.slice(l,l+s.length)===s){if(--o===0)return l}else e.slice(l,l+r.length)===r&&o++;return-1}function Xn(e,t){const r=t.wordBoundary?Ie(e,[`${t.opening} `,`${t.opening}
6
- `],t.start||0):e.indexOf(t.opening,t.start||0);if(r===-1)return null;const s=Qn(e,r+t.opening.length,t.opening,t.closing);return s===-1?null:t.exclusive?e.slice(r+t.opening.length,s):e.slice(r,s+t.closing.length)}function fo(e,t){const r=[];let s=t.wordBoundary?Ie(e,[`${t.opening} `,`${t.opening}
7
- `],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(s===-1)return r;const o=Xn(e,{...t,start:s});if(!o)return r;r.push(o),s=t.wordBoundary?Ie(e,[`${t.opening} `,`${t.opening}
8
- `],s+o.length):e.indexOf(t.opening,s+o.length)}}function ho(e,t,r){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...r,start:s});if(!o)return e;const l=t(o);s=e.indexOf(o,s)+l.length,e=e.replace(o,l)}}function mo(e,t){const r=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){r.push({string:e.slice(s),symbol:null});break}const l=e.indexOf(t,o+t.length);if(o>s&&l!==-1&&r.push({string:e.slice(s,o),symbol:null}),l===-1){r.push({string:e.slice(s),symbol:null});break}r.push({string:e.slice(o+t.length,l),symbol:t}),s=l+t.length}return r}function po(e){const t=[];let r=0;for(;r<e.length;){const s=lo(e,r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=uo(e,s+1);if(o===-1){t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),r=o}return t}function go(e){const t=[];let r=0;for(;r<e.length;){const s=Ie(e,["http://","https://"],r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=Ie(e,[" ",`
9
- `],s);if(o===-1){s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),r=o}return t}const es="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ts="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function yo(e){return rs(e,es)}function vo(e){return ns(e,es)}function wo(e){return rs(e,ts)}function bo(e){return ns(e,ts)}function rs(e,t){const r="=",s=t.length;let o=0,l=0;const f=[];for(let g=0;g<e.length;g++){const p=e[g];if(p===r)break;const x=t.indexOf(p);if(x===-1)throw new Error(`Invalid character: ${p}`);l=l<<Math.log2(s)|x,o+=Math.log2(s),o>=8&&(o-=8,f.push(l>>o&255))}return new Uint8Array(f)}function ns(e,t){const r=t.length;let s=0,o=0,l="";for(let f=0;f<e.length;f++)for(o=o<<8|e[f],s+=8;s>=Math.log2(r);)s-=Math.log2(r),l+=t[o>>s&r-1];return s>0&&(l+=t[o<<Math.log2(r)-s&r-1]),l.length%4!==0&&(l+="=".repeat(4-l.length%4)),l}function _o(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,r=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);r[s]=o}return r}function xo(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function ko(e,t){const r=e.split("/").filter(l=>l),s=t.split("/").filter(l=>l);if(r.length!==s.length)return null;const o={};for(let l=0;l<r.length;l++){const f=r[l];if(f.startsWith(":"))o[f.slice(1)]=s[l];else if(f!==s[l])return null}return o}function sr(e,t,r){const s=[];for(const o of r)o!==t&&s.push(e.replace(t,o));return s}function Eo(e,t,r,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(g=>g),s),avoid:f.avoid})),s),l=[];for(const f of o){const g=f.variants.filter(x=>x!==f.avoid),p=g.find(x=>e.includes(x));if(p&&(Et(l,sr(e,p,g)),l.length>=r))break}if(l.length<r)for(const f of o){const g=f.variants.find(p=>e.includes(p));if(g&&(Et(l,sr(e,g,f.variants)),l.length>=r))break}return l.slice(0,r)}function Ao(e,t,r,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,r)}function So(e,t){const r=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(r,s=>s.toUpperCase()===s?s:t(s))}function To(e){return e.replace(/<[^>]*>/g,"")}function ss(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const r=e.slice(0,t),s=e.slice(t+1);return{line:r,rest:s}}function Oo(e,t={}){return[...e].reduce((r,s)=>r+(t[s]||1),0)}function Io(e,t,r={}){const s=[];let o="",l=0;for(let f=0;f<e.length;f++){const g=e[f],p=r[g]||1;if(o+=g,l+=p,l>t){const{line:x,rest:$}=ss(o);s.push(x),o=$,l=$.split("").map(U=>r[U]||1).reduce((U,Ne)=>U+Ne,0)}}return o&&s.push(o),s}function Mo(e,t){const r=[];for(let s=0;s<=e.length;s++)r[s]=[s];for(let s=0;s<=t.length;s++)r[0][s]=s;for(let s=1;s<=e.length;s++)for(let o=1;o<=t.length;o++){const l=e[s-1]===t[o-1]?0:1;r[s][o]=Math.min(r[s-1][o]+1,r[s][o-1]+1,r[s-1][o-1]+l)}return r[e.length][t.length]}function ir(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function $o(e,t,r){return r==="any"?t.some(s=>ir(e,s)):t.every(s=>ir(e,s))}function Co(e){const t={},r=e.match(/([a-z\-]+)="([^"]+)"/g);if(r)for(const s of r){const[o,l]=tr(s,"=");t[o]=l.slice(1,l.length-1)}return t}function Tt(e,t,r=[]){let s="";for(;t<e.length&&(We(e[t])||r.includes(e[t]));)s+=e[t++];return s}function No(e,t,r="$",s=":"){for(const o in t)e=is(e,o,t[o],r,s);return e=as(e),e}function is(e,t,r,s="$",o=":"){if(r==="")return e;let l=e.indexOf(`${s}${t}`);for(;l!==-1;){if(e[l+t.length+1]===o)if(e[l+t.length+2]===o)e=e.replace(`${s}${t}${o}${o}`,r);else{const f=Tt(e,l+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,r)}else e=e.replace(`${s}${t}`,r);l=e.indexOf(`${s}${t}`,l+r.length)}return e}function as(e,t="$",r=":"){let s=e.indexOf(t);for(;s!==-1;){const o=Tt(e,s+1);if(e[s+o.length+1]===r)if(e[s+o.length+2]===r)e=e.replace(`${t}${o}${r}${r}`,"");else{const l=Tt(e,s+o.length+2);e=e.replace(`${t}${o}${r}${l}`,l)}s=e.indexOf(t,s+1)}return e}function Ro(e,t){let r=e.indexOf("](");for(;r!==-1;){const s=Yn(e,"[",r),o=e.indexOf(")",r);if(s!==-1&&o!==-1){const[l,f]=e.slice(s+1,o).split("]("),g=t(l,f);e=e.slice(0,s)+g+e.slice(o+1)}r=e.indexOf("](",r+1)}return e}function os(e,t=!0){const r=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return r?(t?"?":"")+r:""}function Do(e){const t={},r=e.split("&");for(const s of r){const[o,l]=s.split("=");o&&l&&(t[o]=decodeURIComponent(l))}return t}function jo(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Uo(e,t){let r=null,s=-1/0;for(const[o,l]of Object.entries(e)){const f=t(l);f>s&&(s=f,r=o)}return r?[r,e[r]]:null}function Po(e,t,r,s){const o=e.find(f=>f[t]===r),l=e.find(f=>f[t]===r+s);o&&l?(o[t]=r+s,l[t]=r):o&&(o[t]=r+s),e.sort((f,g)=>xt(f[t])-xt(g[t])),e.forEach((f,g)=>f[t]=g+1)}function Zo(e){const t=Object.keys(e);if(t.length===1)return e[t[0]];throw new Error("Expected object to have a single key")}function Bo(e,t=":"){return Object.fromEntries(e.map(r=>tr(r,t)).map(r=>r[0]&&r[1]?[Ve(r[0]),Ve(r[1])]:null).filter(r=>r))}function Lo(e,t,r){return ds(e,t)+os(r||{})}function Fo(e,t=",",r='"'){const s=[];let o="",l=!1;const f=e.split("");for(const g of f)g===t&&!l?(s.push(o),o=""):g===r&&(!o&&!l||l)?l=!l:o+=g;return s.push(o),s}function zo(e){return`[${Math.floor(e.progress*100)}%] ${Ot(e.deltaMs)} out of ${Ot(e.totalTimeMs)} (${Ot(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function Vo(e,t,r){for(let s=0;s<r;s++){try{if(await e())return!0}catch{}s<r-1&&await d(t)}return!1}function Wo(e,t){const r=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&r.push(e.splice(s,1)[0]);return r}function Ho(e){return JSON.parse(JSON.stringify(e))}function qo(e){return Math.ceil((e||Date.now())/1e3)}function Go(e){return(e||new Date).toISOString().slice(0,10)}function Ko(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function Jo(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function Yo(e){return new Date(e)}function K(e){return String(Math.floor(e)).padStart(2,"0")}function Qo(e){let[t,r]=e.split(":");ue(parseInt(t,10))||(t="0"),ue(parseInt(r,10))||(r="0");let s=lr(Yt(t),0,23),o=lr(Yt(r),0,59);return`${K(s)}:${K(o)}`}function Ot(e){const t=Math.floor(e/36e5);e=e%36e5;const r=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${K(t)}:${K(r)}:${K(s)}`:`${K(r)}:${K(s)}`}function we(e){return Math.floor((Oe(e)?e.getTime():e)/864e5)}const Xo={today:(e,t)=>K(e)+":"+K(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function ec(e,t){const r=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||Xo,o=Oe(e)?e:new Date(e);if(we(r)===we(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(we(r)-we(o)===1)return s.yesterday();const l=or(o);return we(r)-we(o)<7?s[l.day]():s.weeks(Math.round((r.getTime()-o.getTime())/6048e5))}const cs={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function us(e,t){const r=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||cs,o=a.Types.isDate(e)?e.getTime():e;let l=(r-o)/1e3;return l<10?s.now():l<120?s.seconds(Math.floor(l)):(l/=60,l<120?s.minutes(Math.floor(l)):(l/=60,l<48?s.hours(Math.floor(l)):(l/=24,l<14?s.days(Math.floor(l)):(l/=7,s.weeks(Math.floor(l))))))}function tc(e,t=cs){return us(0,{now:e*1e3,labels:t})}function rc(e,t,r){const s=((r==null?void 0:r.now)??Date.now())-e,o=Math.floor(s/t),l=t/((r==null?void 0:r.precision)??1)-Math.ceil(s%t/((r==null?void 0:r.precision)??1));return{cycles:o,remaining:l}}const ar={};function nc(e,t){return!ar[e]||Date.now()>ar[e]?(ar[e]=Date.now()+t,!0):!1}const sc={s:1e3,m:6e4,h:36e5,d:864e5};function ic(e,t,r){return t=Oe(t)?t.getTime():t,r=r?Oe(r)?r.getTime():r:Date.now(),(r-t)/sc[e]}function ac(e,t,r,s){s||(s=Date.now());const o=t/r,l=s-e,f=l/t,g=f*r,p=g-l;return{deltaMs:l,progress:o,baseTimeMs:f,totalTimeMs:g,remainingTimeMs:p}}const oc={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function ls(e){return{zeroBasedIndex:e,day:oc[e]}}function or(e){return ls(e.getDay())}function cc(e){return or(new Date(e))}function uc(e){return e*1e3}function lc(e){return e*6e4}function dc(e){return e*36e5}function fc(e){return e*864e5}const hc={ms:1,milli:1,millis:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,month:2592e6,months:2592e6,y:31536e6,year:31536e6,years:31536e6};function mc(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=hc[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}const pc={b:1,byte:1,bytes:1,kb:1024,kilobyte:1024,kilobytes:1024,mb:1024**2,megabyte:1024**2,megabytes:1024**2,gb:1024**3,gigabyte:1024**3,gigabytes:1024**3,tb:1024**4,terabyte:1024**4,terabytes:1024**4};function gc(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=pc[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}function yc(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const cr={};async function vc(e,t,r){const s=Date.now(),o=cr[e];if(o&&o.validUntil>s)return o.value;const l=await r(),f=s+t;return cr[e]={value:l,validUntil:f},l}function wc(e){delete cr[e]}function ds(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function bc(e,t,r,s,o=!0){const l=e.indexOf(t),f=e.indexOf(r,l+t.length);if(l===-1||f===-1)throw Error("Start or end not found");return o?e.substring(0,l+t.length)+s+e.substring(f):e.substring(0,l)+s+e.substring(f+r.length)}function _c(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const r=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:r,hasPunctuation:s,endsWithColon:o}}function xc(e,t="(",r=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(r,o)?(s--,o+=r.length):o++,s<0)return!1;return t===r?s%2===0:s===0}function kc(e){e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");let t=e.length;for(;e=e.replace(/(\w+)[\s,']+\w+/g,"$1"),e.length!==t;)t=e.length;return e=e.replaceAll(/[A-Z][a-zA-Z0-9]*/g,"A"),e=e.replaceAll(/[a-z][a-zA-Z0-9]*/g,"a"),e=e.replaceAll(/[\u4E00-\u9FA5]+/g,"Z"),e}function fs(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),r={};for(const s of t)r[s]=be(e[s]);return r}function hs(e){const t=[];return e.sort((r,s)=>JSON.stringify(be(r)).localeCompare(JSON.stringify(be(s)))).forEach(r=>t.push(be(r))),t}function be(e){return Array.isArray(e)?hs(e):ce(e)?fs(e):e}function ms(e,t){return JSON.stringify(be(e))===JSON.stringify(be(t))}function Ec(...e){for(let t=1;t<e.length;t++)if(!ms(e[t-1],e[t]))return!1;return!0}function Ac(e){try{return JSON.parse(e)}catch{return null}}function Sc(){let e=0;return{next:()=>e++}}function Tc(e){let t=0;return{next:()=>e[t++%e.length]}}function Oc(e){let t;return r=>{const s=r===e&&t!==e;return t=r,s}}function Ic(e,t,r,s,o){const l={};for(const f of Object.keys(t))l[f]=[];l[s]=[],o&&(e=e.sort(o));for(const f of e){const g=f[r],p=t[g]?g:s;l[p].length>=t[p]?l[s].push(f):l[p].push(f)}return l}function Mc(e,t){const r=Object.keys(e),s=Object.keys(t);return{uniqueToA:r.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!r.includes(o))}}function ps(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function $c(e,t){const r=ps(e);return e[r]=t(e[r]),r}function Cc(e){return e=e.replace(/\r\n/g,`
10
- `),e=e.replace(/(\w+)\((.+)\)/g,(t,r,s)=>`${r}(${s.replaceAll(",","&comma;")})`),e=e.replace(/(,)(\s+})/g,"$2"),e=e.replace(/\.\.\..+?,/g,""),e=e.replace(/({\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/(,\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/:(.+)\?(.+):/g,(t,r,s)=>`: (${r.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,r,s,o)=>`"${r}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const le=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],Nc=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],gs=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function Rc(e,t,r){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(r?" "+r:"");let o=e.substring(0,s),l=e.substring(s);return o===""&&(o="0"),o+"."+l+(r?" "+r:"")}function Dc(e,t){const r=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=r?Nc:gs,l=(t==null?void 0:t.precision)??1;if(e<le[0])return`${e}${s}`;for(let f=0;f<le.length-1;f++)if(e<le[f+1])return`${(e/le[f]).toFixed(l)}${r?" ":""}${o[f]}${s}`;return`${(e/le[le.length-1]).toFixed(l)}${r?" ":""}${o[le.length-1]}${s}`}function ur(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim(),s=gs.findIndex(o=>o.toLowerCase()===r.toLowerCase());return s===-1?t:t*le[s]}function lr(e,t,r){return e<t?t:e>r?r:e}function jc(e,t,r){const s=e+t;return s>r?r:s}function Uc(e,t,r){const s=e-t;return s<r?r:s}function Pc(e,t){return t(e),e}function Zc(e,t){e&&t(e)}function Bc(e,t){const r=Object.keys(t);for(const s of r)Array.isArray(t[s])&&Array.isArray(e[s])&&Et(e[s],t[s])}function Lc(e){return e.splice(0,e.length),e}function Fc(e){for(const t of Object.keys(e))(In(e[t])||Array.isArray(e[t])&&e[t].every(r=>r==null))&&delete e[t];return e}function zc(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||V(t[1])&&_t(t[1]))&&delete e[t[0]];return e}function Vc(e,t){const r={};for(const[s,o]of Object.entries(e))t(s)&&(r[s]=o);return r}function Wc(e,t){const r={};for(const[s,o]of Object.entries(e))t(o)&&(r[s]=o);return r}function Hc(e,t){const r={};for(const s of Object.entries(e))r[s[0]]=t(s[1]);return r}function qc(e,t){const r=[];let s=0;for(const o of e)r.push(t(o,s++));return r}async function Gc(e,t){try{return await e()}catch{throw t}}function Kc(e,t,r){r!=null&&(e[t]=r)}function Jc(e,t,r,s){const o=ge(r,s);o!=null&&ye(e,t,o)}function Yc(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function Qc(e){const t=Object.keys(e),r=t.map(g=>e[g].length),s=r.reduce((g,p)=>g*=p);let o=1;const l=[1];for(let g=0;g<r.length-1;g++)o*=r[g],l.push(o);const f=[];for(let g=0;g<s;g++){const p={};for(let x=0;x<t.length;x++){const $=e[t[x]],U=Math.floor(g/l[x])%$.length;p[t[x]]=$[U]}f.push(p)}return f}function Xc(e){return Object.values(e).filter(t=>t).length}function eu(e,t,r){return e+(r?"["+t+"]":(e.length?".":"")+t)}function It(e,t,r,s,o){if(!ce(t))return t;for(const[l,f]of Object.entries(t)){const g=eu(r,l,s);Array.isArray(f)?o?It(e,f,g,!0,o):e[g]=f.map(p=>It(Array.isArray(p)?[]:{},p,"",!1,o)):ce(f)?It(e,f,g,!1,o):e[g]=f}return e}function tu(e,t=!1,r){return It({},e,r||"",!1,t)}function ys(e){if(!ce(e))return e;const t=Array.isArray(e)?[]:{};for(const[r,s]of Object.entries(e))Array.isArray(s)?ye(t,r,s.map(o=>ys(o))):ye(t,r,s);return t}function ru(e,t,r){return t[e]?t[e]:r}function vs(e,t){const r={};for(const s of e){const o=t(s);r[o]=s}return r}function nu(e,t){const r={};for(const s of e){const o=t(s);r[o]||(r[o]=[]),r[o].push(s)}return r}function su(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r}function ws(e,t){const r=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=r)s.push(e.slice(o,o+r));return s}function bs(e,t){const r=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)r.push(e.slice(o*t,o*t+t));return r}function iu(e,t){const r=Math.ceil(e.length/t);return bs(e,r)}function au(e,t){return Object.values(vs(e,t))}function ou(e,t,r,s,o){const l=t?e.map(t):e,f={};for(const p of l)f[p]=(f[p]||0)+1;const g=s?_s(f,o?(p,x)=>p[1]-x[1]:(p,x)=>x[1]-p[1]):f;return r?Object.keys(g):g}function _s(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function cu(e){const t=[],r=Object.keys(e),s=e[r[0]].length;for(let o=0;o<s;o++){const l={};for(const f of r)l[f]=e[f][o];t.push(l)}return t}function uu(e,t,r=1){for(const s of e)s[t]+=r}function lu(e,t,r){for(const s of e)s[t]=r}function dr(e,t){const r=[];let s=[];return e.forEach((o,l)=>{(l===0||!t(o,e[l-1]))&&(s=[],r.push(s)),s.push(o)}),r}function du(){return{map:new Map,keys:[]}}function fu(){return{map:new Map,keys:[]}}function xs(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function hu(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function mu(e,t,r,s,o=100){xs(e,t,{validUntil:Date.now()+s,data:r},o)}function pu(e,t){const r=e.map.get(t);return r&&r.validUntil>Date.now()?r.data:null}class de{constructor(t){this.value=t}static of(t){return new de(t)}static empty(){return new de(null)}map(t){return new de(this.value!==null&&this.value!==void 0?t(this.value):null)}mapAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(r=>de.of(r)):Promise.resolve(de.empty())}ifPresent(t){return this.value!==null&&this.value!==void 0&&t(this.value),this}ifPresentAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(t){return(this.value===null||this.value===void 0)&&t(),this}ifAbsentAsync(t){return this.value===null||this.value===void 0?t().then(()=>this):Promise.resolve(this)}getOrFallback(t){return this.value??t()}getOrFallbackAsync(t){return this.value!==null&&this.value!==void 0?Promise.resolve(this.value):t()}getOrThrow(){if(this.value===null||this.value===void 0)throw Error("Optional.value is empty");return this.value}}a.Optional=de;class gu{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=gu;class yu{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=yu;function vu(e){return()=>e.forEach(t=>t())}function wu(e,t){return e.reduce((r,s)=>t(r)>t(s)?r:s)}function bu(e,t){const r=e.find(s=>s instanceof t);return de.of(r)}function _u(e,t){return e.filter(r=>r instanceof t)}function xu(e,t){const r=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&r.push(e[o]),t[o]&&r.push(t[o]);return r}function ku(e,t){return e.includes(t)?e.filter(r=>r!==t):[...e,t]}class Eu{constructor(t){this.value=t,this.children=[]}}function Au(e,t,r,s,o=!1){const l=new Map,f=[];e.forEach(p=>{const x=new Eu(p);l.set(p[t],x)}),e.forEach(p=>{const x=l.get(p[t]);if(!x)return;const $=p[r];if($){const U=l.get($);U&&U.children.push(x)}else f.push(x)});const g=p=>{p.children.sort((x,$)=>{const U=x.value[s],Ne=$.value[s];return o?Ne-U:U-Ne}),p.children.forEach(g)};return f.forEach(g),f}function ks(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let r=[...e];for(;r.length>1;){const s=[];for(let o=0;o<r.length;o+=2){const l=r[o+1];s.push(t(r[o],l))}r=s}return r[0]}function Me(...e){const t=e.reduce((o,l)=>o+l.length,0),r=new Uint8Array(t);let s=0;return e.forEach(o=>{r.set(o,s),s+=o.length}),r}function Es(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function As(e){return e[0]===255&&e[1]===216}function Ss(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function Su(e){return Es(e)||As(e)||Ss(e)}function Tu(e){return new Uint8Array([e])}function Ou(e){return e[0]}function Iu(e,t){const r=new ArrayBuffer(2);return new DataView(r).setUint16(0,e,t==="LE"),new Uint8Array(r)}function Mu(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function $u(e,t){const r=new ArrayBuffer(4);return new DataView(r).setUint32(0,e,t==="LE"),new Uint8Array(r)}function Cu(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function fr(e,t){const r=new ArrayBuffer(8);return new DataView(r).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(r)}function Nu(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function $e(e,t){const r=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)r[o]=Number(s&0xffn),s>>=8n;return r}for(let o=31;o>=0;o--)r[o]=Number(s&0xffn),s>>=8n;return r}function Ce(e,t){let r=0n;if(t==="LE"){for(let s=31;s>=0;s--)r=r<<8n|BigInt(e[s]);return r}for(let s=0;s<32;s++)r=r<<8n|BigInt(e[s]);return r}function Ru(e,t){const r=[];let s=0;for(const o of t)r.push(e.subarray(s,s+o)),s+=o;return r}function hr(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.subarray(s,s+t));return r}const Ts=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function Du(e){for(let t=0;t<24;t++){const r=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],l=e[3]^e[13]^e[23]^e[33]^e[43],f=e[4]^e[14]^e[24]^e[34]^e[44],g=e[5]^e[15]^e[25]^e[35]^e[45],p=e[6]^e[16]^e[26]^e[36]^e[46],x=e[7]^e[17]^e[27]^e[37]^e[47],$=e[8]^e[18]^e[28]^e[38]^e[48],U=e[9]^e[19]^e[29]^e[39]^e[49],Ne=o<<1|l>>>31,yl=l<<1|o>>>31,Ge=$^Ne,Ke=U^yl,vl=f<<1|g>>>31,wl=g<<1|f>>>31,Je=r^vl,Ye=s^wl,bl=p<<1|x>>>31,_l=x<<1|p>>>31,Qe=o^bl,Xe=l^_l,xl=$<<1|U>>>31,kl=U<<1|$>>>31,et=f^xl,tt=g^kl,El=r<<1|s>>>31,Al=s<<1|r>>>31,rt=p^El,nt=x^Al;e[0]^=Ge,e[1]^=Ke,e[2]^=Je,e[3]^=Ye,e[4]^=Qe,e[5]^=Xe,e[6]^=et,e[7]^=tt,e[8]^=rt,e[9]^=nt,e[10]^=Ge,e[11]^=Ke,e[12]^=Je,e[13]^=Ye,e[14]^=Qe,e[15]^=Xe,e[16]^=et,e[17]^=tt,e[18]^=rt,e[19]^=nt,e[20]^=Ge,e[21]^=Ke,e[22]^=Je,e[23]^=Ye,e[24]^=Qe,e[25]^=Xe,e[26]^=et,e[27]^=tt,e[28]^=rt,e[29]^=nt,e[30]^=Ge,e[31]^=Ke,e[32]^=Je,e[33]^=Ye,e[34]^=Qe,e[35]^=Xe,e[36]^=et,e[37]^=tt,e[38]^=rt,e[39]^=nt,e[40]^=Ge,e[41]^=Ke,e[42]^=Je,e[43]^=Ye,e[44]^=Qe,e[45]^=Xe,e[46]^=et,e[47]^=tt,e[48]^=rt,e[49]^=nt;const wr=e[0],br=e[1],_r=e[2]<<1|e[3]>>>31,xr=e[3]<<1|e[2]>>>31,kr=e[5]<<30|e[4]>>>2,Er=e[4]<<30|e[5]>>>2,Ar=e[6]<<28|e[7]>>>4,Sr=e[7]<<28|e[6]>>>4,Tr=e[8]<<27|e[9]>>>5,Or=e[9]<<27|e[8]>>>5,Ir=e[11]<<4|e[10]>>>28,Mr=e[10]<<4|e[11]>>>28,$r=e[13]<<12|e[12]>>>20,Cr=e[12]<<12|e[13]>>>20,Nr=e[14]<<6|e[15]>>>26,Rr=e[15]<<6|e[14]>>>26,Dr=e[17]<<23|e[16]>>>9,jr=e[16]<<23|e[17]>>>9,Ur=e[18]<<20|e[19]>>>12,Pr=e[19]<<20|e[18]>>>12,Zr=e[20]<<3|e[21]>>>29,Br=e[21]<<3|e[20]>>>29,Lr=e[22]<<10|e[23]>>>22,Fr=e[23]<<10|e[22]>>>22,zr=e[25]<<11|e[24]>>>21,Vr=e[24]<<11|e[25]>>>21,Wr=e[26]<<25|e[27]>>>7,Hr=e[27]<<25|e[26]>>>7,qr=e[29]<<7|e[28]>>>25,Gr=e[28]<<7|e[29]>>>25,Kr=e[31]<<9|e[30]>>>23,Jr=e[30]<<9|e[31]>>>23,Yr=e[33]<<13|e[32]>>>19,Qr=e[32]<<13|e[33]>>>19,Xr=e[34]<<15|e[35]>>>17,en=e[35]<<15|e[34]>>>17,tn=e[36]<<21|e[37]>>>11,rn=e[37]<<21|e[36]>>>11,nn=e[38]<<8|e[39]>>>24,sn=e[39]<<8|e[38]>>>24,an=e[40]<<18|e[41]>>>14,on=e[41]<<18|e[40]>>>14,cn=e[42]<<2|e[43]>>>30,un=e[43]<<2|e[42]>>>30,ln=e[45]<<29|e[44]>>>3,dn=e[44]<<29|e[45]>>>3,fn=e[47]<<24|e[46]>>>8,hn=e[46]<<24|e[47]>>>8,mn=e[48]<<14|e[49]>>>18,pn=e[49]<<14|e[48]>>>18;e[0]=wr^~$r&zr,e[1]=br^~Cr&Vr,e[2]=$r^~zr&tn,e[3]=Cr^~Vr&rn,e[4]=zr^~tn&mn,e[5]=Vr^~rn&pn,e[6]=tn^~mn&wr,e[7]=rn^~pn&br,e[8]=mn^~wr&$r,e[9]=pn^~br&Cr,e[10]=Ar^~Ur&Zr,e[11]=Sr^~Pr&Br,e[12]=Ur^~Zr&Yr,e[13]=Pr^~Br&Qr,e[14]=Zr^~Yr&ln,e[15]=Br^~Qr&dn,e[16]=Yr^~ln&Ar,e[17]=Qr^~dn&Sr,e[18]=ln^~Ar&Ur,e[19]=dn^~Sr&Pr,e[20]=_r^~Nr&Wr,e[21]=xr^~Rr&Hr,e[22]=Nr^~Wr&nn,e[23]=Rr^~Hr&sn,e[24]=Wr^~nn&an,e[25]=Hr^~sn&on,e[26]=nn^~an&_r,e[27]=sn^~on&xr,e[28]=an^~_r&Nr,e[29]=on^~xr&Rr,e[30]=Tr^~Ir&Lr,e[31]=Or^~Mr&Fr,e[32]=Ir^~Lr&Xr,e[33]=Mr^~Fr&en,e[34]=Lr^~Xr&fn,e[35]=Fr^~en&hn,e[36]=Xr^~fn&Tr,e[37]=en^~hn&Or,e[38]=fn^~Tr&Ir,e[39]=hn^~Or&Mr,e[40]=kr^~Dr&qr,e[41]=Er^~jr&Gr,e[42]=Dr^~qr&Kr,e[43]=jr^~Gr&Jr,e[44]=qr^~Kr&cn,e[45]=Gr^~Jr&un,e[46]=Kr^~cn&kr,e[47]=Jr^~un&Er,e[48]=cn^~kr&Dr,e[49]=un^~Er&jr,e[0]^=Ts[t*2],e[1]^=Ts[t*2+1]}}function Os(e){const t=[];for(let r=0;r<e.length;r+=4)t.push(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24);return t}function Is(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[Os(o)]}const r=hr(e,136),s=r[r.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,r[r.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,r.push(o)}return r.map(Os)}function Ms(e,t){for(const r of t){for(let s=0;s<34;s+=2)e[s]^=r[s+1],e[s+1]^=r[s];Du(e)}return e}function $s(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function se(e){return $s(Ms(new Array(50).fill(0),Is(e,1)))}function ju(e){return $s(Ms(new Array(50).fill(0),Is(e,6)))}function Uu(e,t,r){const s=Math.min(e.length,t.length,r/8+1);for(let o=0;o<s;o++){const l=e[o]^t[o];for(let f=0;f<8;f++)if(l>>7-f&1)return o*8+f}return r}function Pu(e,t){const r=Math.min(e.length,t.length);for(let s=0;s<r;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,r)}function Zu(e,t,r,s){const o=Math.floor(t/8),l=t%8;r===1?e[o]|=1<<(s==="BE"?7-l:l):e[o]&=~(1<<(s==="BE"?7-l:l))}function Bu(e,t,r){const s=Math.floor(t/8),o=t%8;return e[s]>>(r==="BE"?7-o:o)&1}function Lu(e,t,r=0){for(let s=r;s<e.length;s++)for(let o=0;o<t.length&&e[s+o]===t[o];o++)if(o===t.length-1)return s;return-1}function Cs(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,t-e.length),s}function Fu(e,t,r=0){const s=e.length%t;return s===0?e:Cs(e,e.length+t-s,r)}function Ns(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,0),s}function zu(e,t,r=0){const s=e.length%t;return s===0?e:Ns(e,e.length+t-s,r)}function Vu(e,t){const r=new Uint8Array(e.length);for(let s=0;s<e.length;s++)r[s]=e[s]^t[s%t.length];return r}function Wu(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function C(e,t){return(e%t+t)%t}function He(e,t){e=C(e,t);let[r,s]=[0n,1n],[o,l]=[t,e];for(;l!==0n;){const f=o/l;[r,s]=[s,r-f*s],[o,l]=[l,o-f*l]}if(o>1n)throw new Error("a is not invertible");return r<0n&&(r+=t),r}function Hu(e,t,r){let s=1n;for(e=C(e,r);t>0;)t%2n===1n&&(s=C(s*e,r)),e=C(e*e,r),t=t/2n;return s}function Rs(e,t){return C(e,t)===0n?0n:t%4n===3n?Hu(e,(t+1n)/4n,t):null}const Z=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,j=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Mt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,$t=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function mr(e,t,r){if(t===0n)return[0n,0n];const s=C(3n*e*e*He(2n*t,r),r),o=C(s*s-2n*e,r),l=C(s*(e-o)-t,r);return[o,l]}function Ct(e,t,r,s,o){if(e===0n&&t===0n)return[r,s];if(r===0n&&s===0n)return[e,t];if(e===r&&t===C(-s,o))return[0n,0n];if(e===r&&t===s)return mr(e,t,o);const l=C((s-t)*He(r-e,o),o),f=C(l*l-e-r,o),g=C(l*(e-f)-t,o);return[f,g]}function qu(e){if(e<=0n||e>=j)throw new Error("Invalid private key");return _e(Mt,$t,e,Z)}function Gu(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...$e(e[0],"BE")])}function Ku(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Ce(e.slice(1),"BE"),r=Rs(C(t**3n+7n,Z),Z);if(!r)throw Error("Invalid x: does not correspond to a valid curve point");const s=C(-r,Z),o=r%2n===0n;return[t,e[0]===2?o?r:s:o?s:r]}function Ju(e){const t=new Uint8Array(20),r=se(Me($e(e[0],"BE"),$e(e[1],"BE")));return t.set(r.subarray(12)),t}function Yu(e){const t=a.Binary.uint8ArrayToHex(e),r=a.Binary.uint8ArrayToHex(a.Binary.keccak256(new Uint8Array([...t].map(o=>o.charCodeAt(0)))));let s="0x";for(let o=0;o<t.length;o++)parseInt(r[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function _e(e,t,r,s){let o=[0n,0n],l=[e,t];const f=r.toString(2);for(const g of f)g==="0"?(l=Ct(o[0],o[1],l[0],l[1],s),o=mr(o[0],o[1],s)):(o=Ct(o[0],o[1],l[0],l[1],s),l=mr(l[0],l[1],s));return o}function Qu(e,t,r){return Ds(Ce(se(e),"BE"),t,r)}function Ds(e,t,r){if(t<=0n||t>=j)throw new Error("Invalid private key");if(r||(r=C(Ce(se(Me(se($e(t,"BE")),$e(e,"BE"))),"BE"),j)),r<=0n||r>=j)throw new Error("Invalid nonce");const s=C(e,j),o=_e(Mt,$t,r,Z),l=C(o[0],j);let f=C((s+C(l,j)*t)*He(r,j),j);if(l===0n||f===0n)throw new Error("Invalid r or s value");let g=o[1]%2n===0n?27n:28n;return f>j/2n&&(f=j-f,g=g===27n?28n:27n),[l,f,g]}function Xu(e,t,r,s){const o=Rs(C(t**3n+7n,Z),Z);if(!o)throw new Error("Invalid r: does not correspond to a valid curve point");const l=s===27n?0n:1n,f=o%2n===l?o:Z-o,g=C(Ce(se(e),"BE"),j),p=_e(t,f,r,Z),x=_e(Mt,$t,g,Z),$=Ct(p[0],p[1],x[0],C(-x[1],Z),Z);return _e($[0],$[1],He(t,j),Z)}function el(e,t,r,s){const o=C(Ce(se(e),"BE"),j),l=He(s,j),f=C(o*l,j),g=C(r*l,j),p=_e(Mt,$t,f,Z),x=_e(t[0],t[1],g,Z),$=Ct(p[0],p[1],x[0],x[1],Z);return r===C($[0],j)}class js{constructor(t){this.cursor=0,this.buffer=t}read(t){const r=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=js;class Us{constructor(t){this.buffer=t,this.cursor=0}write(t){const r=Math.min(this.max(),t.max());return this.buffer.set(t.read(r),this.cursor),this.cursor+=r,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=Us;class Nt{constructor(t,r=0n){this.span=r,this.writer=new Us(new Uint8Array(t))}build(){return Me(fr(this.span,"LE"),this.writer.buffer)}hash(){const t=ks(hr(this.writer.buffer,32),(r,s)=>se(Me(r,s)));return se(Me(fr(this.span,"LE"),t))}}a.Chunk=Nt;class pr{constructor(t,r=4096){this.counters=[1],this.capacity=r,this.chunks=[new Nt(r)],this.onChunk=t}static async root(t,r=4096){const s=new n(n.NOOP,r);return await s.append(t),s.finalize()}async append(t,r=0,s=0n){const o=new js(t);for(;o.max()>0;){this.chunks[r].writer.max()===0&&await this.elevate(r);const l=this.chunks[r].writer.write(o);s?this.chunks[r].span+=s:this.chunks[0].span+=BigInt(l)}}async elevate(t){this.counters[t]=++this.counters[t]%(this.capacity/32),this.chunks[t+1]||(this.chunks.push(new Nt(this.capacity)),this.counters.push(1)),await this.append(this.chunks[t].hash(),t+1,this.chunks[t].span),await this.onChunk(this.chunks[t]),this.chunks[t]=new Nt(this.capacity)}async finalize(t=0){return this.chunks[t+1]?this.counters[t]===1?(await this.elevate(t+1),this.chunks[t+1]=this.chunks[t],this.finalize(t+1)):(await this.elevate(t),this.finalize(t+1)):(await this.onChunk(this.chunks[t]),this.chunks[t])}}a.MerkleTree=pr,n=pr,pr.NOOP=async e=>{};class J{constructor(t,r){if(r<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=r}static fromDecimalString(t,r){let[s,o]=t.split(".");return o=(o||"").padEnd(r,"0").slice(0,r),new J(BigInt(s+o),r)}add(t){return this.assertSameScale(t),new J(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new J(this.value-t.value,this.scale)}multiply(t){return new J(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const r=this.value/t,s=this.value%t;return[new J(r,this.scale),new J(s,this.scale)]}exchange(t,r,s){if(t==="*"){const l=this.value*r.value/10n**BigInt(this.scale);return new J(l,s)}this.assertSameScale(r);const o=this.value*10n**BigInt(s)/r.value;return new J(o,s)}compare(t){return this.assertSameScale(t),this.value>t.value?1:this.value<t.value?-1:0}toDecimalString(){if(this.scale===0)return this.value.toString();const t=this.value.toString(),r=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${r}.${s}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(t){if(this.scale!==t.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${t.scale}`)}}a.FixedPointNumber=J;function tl(e){if(e.length===0)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}}function Rt(e,t,r,s){const o=e.findIndex(g=>g===`--${t}`||g.startsWith(`--${t}=`)),l=e[o];if(!l)return(r||{})[s||t||""]||null;if(l.includes("="))return l.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(r||{})[s||t||""]||null}function rl(e,t,r,s){const o=Rt(e,t,r,s);if(!o)return null;try{return ur(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function nl(e,t,r,s){const o=e.some(p=>p.endsWith("-"+t)),l=Rt(e,t,r,s);if(!l&&o)return!0;if(!l&&!o)return null;const f=["true","1","yes","y","on"],g=["false","0","no","n","off"];if(f.includes(l.toLowerCase()))return!0;if(g.includes(l.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${l}`)}function Ps(e,t,r,s){const o=Rt(e,t,r,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function sl(e,t,r,s){const o=Ps(e,t,r,s);try{return ur(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function Zs(e,t){const r=e[t];e.splice(t,1),e.unshift(r)}function il(e,t){const r=[...e];return Zs(r,t),r}function Bs(e,t){return{x:e.x+t.x,y:e.y+t.y}}function al(e,t){return{x:e.x-t.x,y:e.y-t.y}}function gr(e,t){return{x:e.x*t,y:e.y*t}}function ol(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function Ls(e,t,r){return{x:e.x+Math.cos(t)*r,y:e.y+Math.sin(t)*r}}function Fs(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function qe(e,t,r="row-first"){const s=[];if(r==="column-first")for(let o=0;o<e.length;o++)for(let l=0;l<e[0].length;l++)t(o,l)&&s.push({x:o,y:l});else for(let o=0;o<e[0].length;o++)for(let l=0;l<e.length;l++)t(l,o)&&s.push({x:l,y:o});return s}function cl(e,t,r){var s,o;return((s=e[t+1])==null?void 0:s[r])&&((o=e[t-1])==null?void 0:o[r])&&!e[t][r-1]&&!e[t][r+1]}function ul(e,t,r){var s,o;return e[t][r+1]&&e[t][r-1]&&!((s=e[t-1])!=null&&s[r])&&!((o=e[t+1])!=null&&o[r])}function zs(e,t,r){var s;return!((s=e[t-1])!=null&&s[r])}function Vs(e,t,r){var s;return!((s=e[t+1])!=null&&s[r])}function Ws(e,t,r){return!e[t][r-1]}function Hs(e,t,r){return!e[t][r+1]}function ll(e,t,r){var o,l,f,g,p,x,$,U;const s=[];return e[t][r]?cl(e,t,r)||ul(e,t,r)?[]:(!((o=e[t-1])!=null&&o[r-1])&&zs(e,t,r)&&Ws(e,t,r)&&s.push({x:t,y:r}),!((l=e[t+1])!=null&&l[r-1])&&Vs(e,t,r)&&Ws(e,t,r)&&s.push({x:t+1,y:r}),!((f=e[t-1])!=null&&f[r+1])&&zs(e,t,r)&&Hs(e,t,r)&&s.push({x:t,y:r+1}),!((g=e[t+1])!=null&&g[r+1])&&Vs(e,t,r)&&Hs(e,t,r)&&s.push({x:t+1,y:r+1}),s):((p=e[t-1])!=null&&p[r]&&e[t][r-1]&&s.push({x:t,y:r}),(x=e[t+1])!=null&&x[r]&&e[t][r-1]&&s.push({x:t+1,y:r}),($=e[t-1])!=null&&$[r]&&e[t][r+1]&&s.push({x:t,y:r+1}),(U=e[t+1])!=null&&U[r]&&e[t][r+1]&&s.push({x:t+1,y:r+1}),s)}function dl(e,t,r,s){const o=[{x:0,y:0},{x:r,y:0},{x:0,y:s},{x:r,y:s}];for(let l=0;l<e.length;l++)for(let f=0;f<e[0].length;f++){const g=ll(e,l,f);for(const p of g)o.some(x=>x.x===p.x&&x.y===p.y)||o.push(p)}return o.map(l=>({x:l.x*t,y:l.y*t}))}function fl(e,t){const r=qe(e,(p,x)=>e[p][x]===0&&e[p][x+1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),s=qe(e,(p,x)=>e[p][x]===0&&e[p][x-1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),o=qe(e,(p,x)=>{var $;return e[p][x]===0&&(($=e[p-1])==null?void 0:$[x])!==0},"column-first").map(p=>({...p,dx:0,dy:1})),l=qe(e,(p,x)=>{var $;return e[p][x]===0&&(($=e[p+1])==null?void 0:$[x])!==0},"column-first").map(p=>({...p,dx:0,dy:1}));r.forEach(p=>p.y++),l.forEach(p=>p.x++);const f=dr([...o,...l],(p,x)=>p.x===x.x&&p.y-1===x.y),g=dr([...s,...r],(p,x)=>p.y===x.y&&p.x-1===x.x);return[...f,...g].map(p=>({start:p[0],end:Fe(p)})).map(p=>({start:gr(p.start,t),end:gr(Bs(p.end,{x:p.start.dx,y:p.start.dy}),t)}))}function hl(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function ml(e,t){return t.map(r=>hl(e,r)).sort((r,s)=>r-s)}function qs(e,t,r,s){const o=(s.y-r.y)*(t.x-e.x)-(s.x-r.x)*(t.y-e.y);if(o===0)return null;let l=e.y-r.y,f=e.x-r.x;const g=(s.x-r.x)*l-(s.y-r.y)*f,p=(t.x-e.x)*l-(t.y-e.y)*f;return l=g/o,f=p/o,l>0&&l<1&&f>0&&f<1?{x:e.x+l*(t.x-e.x),y:e.y+l*(t.y-e.y)}:null}function yr(e,t,r){const s=[],o=Ls(e,r,1e4);for(const l of t){const f=qs(e,o,l.start,l.end);f&&s.push(f)}return s.length?s.reduce((l,f)=>{const g=Fs(e,f),p=Fs(e,l);return g<p?f:l}):null}function pl(e,t,r){const s=ml(e,r),o=[];for(const l of s){const f=yr(e,t,l-.001),g=yr(e,t,l+.001);f&&o.push(f),g&&o.push(g)}return o}class vr{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(r=>r!==t)}}publish(t){this.subscribers.forEach(r=>r(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=vr;class gl{constructor(t,r){this.queue=[],this.running=0,this.onProcessed=new vr,this.onDrained=new vr,this.concurrency=t,this.capacity=r}process(){if(this.running>=this.concurrency)return;const t=this.queue.shift();t&&(this.running++,t().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),this.running===0&&this.onDrained.publish()}))}enqueue(t){if(this.queue.length<this.capacity)return this.queue.push(t),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(r=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),r())})})}drain(){if(this.running===0)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(t=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),t()})})}}a.AsyncQueue=gl,a.Binary={hexToUint8Array:_o,uint8ArrayToHex:xo,base64ToUint8Array:yo,uint8ArrayToBase64:vo,base32ToUint8Array:wo,uint8ArrayToBase32:bo,log2Reduce:ks,partition:hr,concatBytes:Me,numberToUint8:Tu,uint8ToNumber:Ou,numberToUint16:Iu,uint16ToNumber:Mu,numberToUint32:$u,uint32ToNumber:Cu,numberToUint64:fr,uint64ToNumber:Nu,numberToUint256:$e,uint256ToNumber:Ce,sliceBytes:Ru,keccak256:se,sha3_256:ju,proximity:Uu,commonPrefix:Pu,setBit:Zu,getBit:Bu,indexOf:Lu,equals:Wu,padStart:Cs,padStartToMultiple:Fu,padEnd:Ns,padEndToMultiple:zu,xorCypher:Vu},a.Elliptic={privateKeyToPublicKey:qu,compressPublicKey:Gu,publicKeyFromCompressed:Ku,publicKeyToAddress:Ju,signMessage:Qu,signHash:Ds,verifySignature:el,recoverPublicKey:Xu,checksumEncode:Yu},a.Random={intBetween:Le,floatBetween:Sn,chance:Tn,signed:mi,makeSeededRng:Vt,point:gi,procs:yi},a.Arrays={countUnique:ou,makeUnique:au,splitBySize:su,splitByCount:ws,index:vs,indexCollection:nu,onlyOrThrow:m,onlyOrNull:w,firstOrThrow:E,firstOrNull:v,shuffle:h,initialize:D,initialize2D:ne,rotate2D:re,containsShape:Be,glue:Aa,pluck:zt,pick:Wt,pickMany:vi,pickManyUnique:wi,pickWeighted:xi,pickRandomIndices:Se,pickGuaranteed:bi,last:Fe,pipe:On,makePipe:_i,sortWeighted:ki,pushAll:Et,unshiftAll:ka,filterAndRemove:Wo,merge:Bc,empty:Lc,pushToBucket:ba,unshiftAndLimit:_a,atRolling:xa,group:dr,createOscillator:Tc,organiseWithLimits:Ic,tickPlaybook:tl,getArgument:Rt,getBooleanArgument:nl,getNumberArgument:rl,requireStringArgument:Ps,requireNumberArgument:sl,bringToFront:il,bringToFrontInPlace:Zs,findInstance:bu,filterInstances:_u,interleave:xu,toggle:ku,createHierarchy:Au,multicall:vu,maxBy:wu},a.System={sleepMillis:d,forever:Ii,scheduleMany:Ca,waitFor:Vo,expandError:ga,runAndSetInterval:Mi},a.Numbers={make:ur,sum:Ra,average:Da,median:ja,getDistanceFromMidpoint:Ua,clamp:lr,range:Ln,interpolate:Na,createSequence:Sc,increment:jc,decrement:Uc,format:Dc,fromDecimals:Rc,makeStorage:gc,asMegabytes:$i,convertBytes:Ci,hexToRgb:Ni,rgbToHex:Ri,haversineDistanceToMeters:Di,roundToNearest:bt,formatDistance:ji,triangularNumber:Ui,searchFloat:Pi},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:ec,getTimeDelta:us,secondsToHumanTime:tc,countCycles:rc,isoDate:Go,throttle:nc,timeSince:ic,dateTimeSlug:Ko,unixTimestamp:qo,fromUtcString:Jo,fromMillis:Yo,getProgress:ac,humanizeTime:Ot,humanizeProgress:zo,createTimeDigits:K,mapDayNumber:ls,getDayInfoFromDate:or,getDayInfoFromDateTimeString:cc,seconds:uc,minutes:lc,hours:dc,days:fc,make:mc,normalizeTime:Qo,absoluteDays:we},a.Objects={safeParse:Ac,deleteDeep:Si,getDeep:ge,setDeep:ye,incrementDeep:Ei,ensureDeep:Ai,replaceDeep:Ti,getFirstDeep:Oi,deepMergeInPlace:ve,deepMerge2:ya,deepMerge3:va,mapAllAsync:Ea,cloneWithJson:Ho,sortObject:fs,sortArray:hs,sortAny:be,deepEquals:ms,deepEqualsEvery:Ec,runOn:Pc,ifPresent:Zc,zip:Bn,zipSum:wa,removeEmptyArrays:Fc,removeEmptyValues:zc,flatten:tu,unflatten:ys,match:ru,sort:_s,map:Hc,mapIterable:qc,filterKeys:Vc,filterValues:Wc,rethrow:Gc,setSomeOnObject:Kc,setSomeDeep:Jc,flip:Yc,getAllPermutations:Qc,countTruthyValues:Xc,transformToArray:cu,setMulti:lu,incrementMulti:uu,createBidirectionalMap:du,createTemporalBidirectionalMap:fu,pushToBidirectionalMap:xs,unshiftToBidirectionalMap:hu,addToTemporalBidirectionalMap:mu,getFromTemporalBidirectionalMap:pu,createStatefulToggle:Oc,diffKeys:Mc,pickRandomKey:ps,mapRandomKey:$c,fromObjectString:Cc,toQueryString:os,parseQueryString:Do,hasKey:jo,selectMax:Uo,reposition:Po,unwrapSingleKey:Zo,parseKeyValues:Bo},a.Types={isFunction:qt,isObject:ce,isStrictlyObject:Te,isEmptyArray:In,isEmptyObject:Zi,isUndefined:Ht,isString:V,isNumber:ue,isBoolean:Mn,isDate:Oe,isBlank:_t,isId:Gt,isIntegerString:$n,isHexString:Cn,isUrl:Pn,isNullable:fa,asString:jn,asHexString:Qi,asSafeString:Xi,asIntegerString:Yi,asNumber:xt,asFunction:ea,asInteger:Yt,asBoolean:ta,asDate:ra,asNullableString:na,asEmptiableString:sa,asId:ia,asTime:aa,asArray:oa,asObject:kt,asNullableObject:ca,asStringMap:ua,asNumericDictionary:la,asUrl:da,asNullable:ha,asOptional:ma,enforceObjectShape:Zn,enforceArrayShape:pa,isPng:Es,isJpg:As,isWebp:Ss,isImage:Su},a.Strings={tokenizeByCount:iu,tokenizeByLength:bs,searchHex:Gi,searchSubstring:Ki,randomHex:Ji,randomLetter:Vi,randomAlphanumeric:Wi,randomRichAscii:Hi,randomUnicode:qi,includesAny:Pa,slugify:Qt,normalForm:Ba,enumify:Ha,escapeHtml:Ga,decodeHtmlEntities:Ja,after:Xt,afterLast:zn,before:Fn,beforeLast:er,betweenWide:Ya,betweenNarrow:Qa,getPreLine:yc,containsWord:ir,containsWords:$o,joinUrl:ds,getFuzzyMatchScore:At,sortByFuzzyScore:qa,splitOnce:tr,splitAll:Vn,randomize:ro,expand:Wn,shrinkTrim:Ve,capitalize:St,decapitalize:Hn,csvEscape:co,parseCsv:Fo,surroundInOut:Wa,getExtension:rr,getBasename:nr,normalizeEmail:Xa,normalizeFilename:eo,parseFilename:to,camelToTitle:La,slugToTitle:Fa,slugToCamel:za,joinHumanly:Va,findWeightedPair:Qn,extractBlock:Xn,extractAllBlocks:fo,replaceBlocks:ho,indexOfEarliest:Ie,lastIndexOfBefore:Yn,parseHtmlAttributes:Co,readNextWord:Tt,resolveVariables:No,resolveVariableWithDefaultSyntax:is,resolveRemainingVariablesWithDefaults:as,isLetter:qn,isDigit:Gn,isLetterOrDigit:We,isValidObjectPathCharacter:io,insert:ao,indexOfRegex:Kn,lineMatches:Jn,linesMatchInOrder:oo,represent:ze,resolveMarkdownLinks:Ro,buildUrl:Lo,isChinese:Za,replaceBetweenStrings:bc,describeMarkdown:_c,isBalanced:xc,textToFormat:kc,splitFormatting:mo,splitHashtags:po,splitUrls:go,route:ko,explodeReplace:sr,generateVariants:Eo,replaceWord:Ao,replacePascalCaseWords:So,stripHtml:To,breakLine:ss,measureTextWidth:Oo,toLines:Io,levenshteinDistance:Mo},a.Assertions={asEqual:Sa,asTrue:Ta,asTruthy:Oa,asFalse:Ia,asFalsy:Ma,asEither:$a},a.Cache={get:vc,invalidate:wc},a.Vector={addPoint:Bs,subtractPoint:al,multiplyPoint:gr,normalizePoint:ol,pushPoint:Ls,filterCoordinates:qe,findCorners:dl,findLines:fl,raycast:yr,raycastCircle:pl,getLineIntersectionPoint:qs}})(ti);const N=$l(ti);N.Arrays;N.Assertions;const B=N.Binary;N.Cache;N.Dates;N.Elliptic;N.Numbers;N.Objects;N.Pagination;N.Promises;N.Random;N.Strings;N.System;N.Types;N.Optional;N.Vector;N.PubSubChannel;N.Chunk;const Cl=N.MerkleTree;N.FixedPointNumber;N.Lazy;N.AsyncLazy;N.AsyncQueue;N.Uint8ArrayReader;N.Uint8ArrayWriter;const Nl=new TextEncoder,Ks=1,Js=4096,yn=4096,Rl=32;function ri(a,n){return n=typeof n=="number"?T.FeedIndex.fromBigInt(BigInt(n)):n,new T.Identifier(B.keccak256(B.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Dl(a){const n=a.slice(0,T.Span.LENGTH),i=a.slice(T.Span.LENGTH),c=jl(i),u=B.keccak256(B.concatBytes(n,c));return new T.Reference(u)}function jl(a){if(a.length>yn)throw new T.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${yn}`,a);const n=new Uint8Array(yn);return n.set(a),B.log2Reduce(B.partition(n,Rl),(i,c)=>B.keccak256(B.concatBytes(i,c)))}function Ys(a){if(a instanceof Uint8Array||(a=Nl.encode(a)),a.length<Ks||a.length>Js)throw new RangeError(`payload size ${a.length} exceeds limits [${Ks}, ${Js}]`);const n=T.Span.fromBigInt(BigInt(a.length)),i=B.concatBytes(n.toUint8Array(),a);return{data:i,span:n,payload:T.Bytes.fromSlice(i,T.Span.LENGTH),address:Dl(i)}}function Ul(a,n){return new T.Reference(B.keccak256(B.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Qs(a,n,i){n=new T.Identifier(n),i=new T.PrivateKey(i);const c=Ul(n,i.publicKey().address()),u=i.sign(B.concatBytes(n.toUint8Array(),a.address.toUint8Array())),d=B.concatBytes(n.toUint8Array(),u.toUint8Array(),a.data),h=T.Span.fromSlice(a.data,0),m=T.Bytes.fromSlice(a.data,T.Span.LENGTH);return{data:d,identifier:n,signature:u,span:h,payload:m,address:c,owner:i.publicKey().address()}}function wn(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}class Q{constructor(){}static getInstance(){return Q.instance||(Q.instance=new Q),Q.instance}formatMessage(n,...i){return`[${new Date().toISOString()}] [${n.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...n){console.log(this.formatMessage("log",...n))}info(...n){console.info(this.formatMessage("info",...n))}warn(...n){console.warn(this.formatMessage("warn",...n))}error(...n){console.error(this.formatMessage("error",...n))}debug(...n){console.debug(this.formatMessage("debug",...n))}}class En{constructor(){this.logger=Q.getInstance()}handleError(n,i){const c=n instanceof Error?n.message:"Unknown error occurred",u=n instanceof Error?n.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}class Pl{constructor(){this.events={},this.on=this.on.bind(this),this.off=this.off.bind(this),this.cleanAll=this.cleanAll.bind(this),this.emit=this.emit.bind(this)}on(n,i){this.events[n]||(this.events[n]=[]),this.events[n].push(i)}off(n,i){if(!this.events[n])return;const c=this.events[n].indexOf(i);c>-1&&this.events[n].splice(c,1)}cleanAll(){this.events={}}emit(n,i){this.events[n]&&this.events[n].forEach(c=>c(i))}}var M;(function(a){a.assertEqual=u=>u;function n(u){}a.assertIs=n;function i(u){throw new Error}a.assertNever=i,a.arrayToEnum=u=>{const d={};for(const h of u)d[h]=h;return d},a.getValidEnumValues=u=>{const d=a.objectKeys(u).filter(m=>typeof u[u[m]]!="number"),h={};for(const m of d)h[m]=u[m];return a.objectValues(h)},a.objectValues=u=>a.objectKeys(u).map(function(d){return u[d]}),a.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const d=[];for(const h in u)Object.prototype.hasOwnProperty.call(u,h)&&d.push(h);return d},a.find=(u,d)=>{for(const h of u)if(d(h))return h},a.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&isFinite(u)&&Math.floor(u)===u;function c(u,d=" | "){return u.map(h=>typeof h=="string"?`'${h}'`:h).join(d)}a.joinValues=c,a.jsonStringifyReplacer=(u,d)=>typeof d=="bigint"?d.toString():d})(M||(M={}));var bn;(function(a){a.mergeShapes=(n,i)=>({...n,...i})})(bn||(bn={}));const _=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ae=a=>{switch(typeof a){case"undefined":return _.undefined;case"string":return _.string;case"number":return isNaN(a)?_.nan:_.number;case"boolean":return _.boolean;case"function":return _.function;case"bigint":return _.bigint;case"symbol":return _.symbol;case"object":return Array.isArray(a)?_.array:a===null?_.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?_.promise:typeof Map<"u"&&a instanceof Map?_.map:typeof Set<"u"&&a instanceof Set?_.set:typeof Date<"u"&&a instanceof Date?_.date:_.object;default:return _.unknown}},y=M.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Zl=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class z extends Error{get errors(){return this.issues}constructor(n){super(),this.issues=[],this.addIssue=c=>{this.issues=[...this.issues,c]},this.addIssues=(c=[])=>{this.issues=[...this.issues,...c]};const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.name="ZodError",this.issues=n}format(n){const i=n||function(d){return d.message},c={_errors:[]},u=d=>{for(const h of d.issues)if(h.code==="invalid_union")h.unionErrors.map(u);else if(h.code==="invalid_return_type")u(h.returnTypeError);else if(h.code==="invalid_arguments")u(h.argumentsError);else if(h.path.length===0)c._errors.push(i(h));else{let m=c,w=0;for(;w<h.path.length;){const v=h.path[w];w===h.path.length-1?(m[v]=m[v]||{_errors:[]},m[v]._errors.push(i(h))):m[v]=m[v]||{_errors:[]},m=m[v],w++}}};return u(this),c}static assert(n){if(!(n instanceof z))throw new Error(`Not a ZodError: ${n}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(n=i=>i.message){const i={},c=[];for(const u of this.issues)u.path.length>0?(i[u.path[0]]=i[u.path[0]]||[],i[u.path[0]].push(n(u))):c.push(n(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}z.create=a=>new z(a);const Ue=(a,n)=>{let i;switch(a.code){case y.invalid_type:a.received===_.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case y.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,M.jsonStringifyReplacer)}`;break;case y.unrecognized_keys:i=`Unrecognized key(s) in object: ${M.joinValues(a.keys,", ")}`;break;case y.invalid_union:i="Invalid input";break;case y.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${M.joinValues(a.options)}`;break;case y.invalid_enum_value:i=`Invalid enum value. Expected ${M.joinValues(a.options)}, received '${a.received}'`;break;case y.invalid_arguments:i="Invalid function arguments";break;case y.invalid_return_type:i="Invalid function return type";break;case y.invalid_date:i="Invalid date";break;case y.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(i=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(i=`${i} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?i=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?i=`Invalid input: must end with "${a.validation.endsWith}"`:M.assertNever(a.validation):a.validation!=="regex"?i=`Invalid ${a.validation}`:i="Invalid";break;case y.too_small:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:i="Invalid input";break;case y.too_big:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?i=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:i="Invalid input";break;case y.custom:i="Invalid input";break;case y.invalid_intersection_types:i="Intersection results could not be merged";break;case y.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case y.not_finite:i="Number must be finite";break;default:i=n.defaultError,M.assertNever(a)}return{message:i}};let ni=Ue;function Bl(a){ni=a}function Dt(){return ni}const jt=a=>{const{data:n,path:i,errorMaps:c,issueData:u}=a,d=[...i,...u.path||[]],h={...u,path:d};if(u.message!==void 0)return{...u,path:d,message:u.message};let m="";const w=c.filter(v=>!!v).slice().reverse();for(const v of w)m=v(h,{data:n,defaultError:m}).message;return{...u,path:d,message:m}},Ll=[];function b(a,n){const i=Dt(),c=jt({issueData:n,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Ue?void 0:Ue].filter(u=>!!u)});a.common.issues.push(c)}class L{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(n,i){const c=[];for(const u of i){if(u.status==="aborted")return S;u.status==="dirty"&&n.dirty(),c.push(u.value)}return{status:n.value,value:c}}static async mergeObjectAsync(n,i){const c=[];for(const u of i){const d=await u.key,h=await u.value;c.push({key:d,value:h})}return L.mergeObjectSync(n,c)}static mergeObjectSync(n,i){const c={};for(const u of i){const{key:d,value:h}=u;if(d.status==="aborted"||h.status==="aborted")return S;d.status==="dirty"&&n.dirty(),h.status==="dirty"&&n.dirty(),d.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[d.value]=h.value)}return{status:n.value,value:c}}}const S=Object.freeze({status:"aborted"}),De=a=>({status:"dirty",value:a}),F=a=>({status:"valid",value:a}),_n=a=>a.status==="aborted",xn=a=>a.status==="dirty",ke=a=>a.status==="valid",at=a=>typeof Promise<"u"&&a instanceof Promise;function Ut(a,n,i,c){if(typeof n=="function"?a!==n||!c:!n.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n.get(a)}function si(a,n,i,c,u){if(typeof n=="function"?a!==n||!u:!n.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n.set(a,i),i}var k;(function(a){a.errToObj=n=>typeof n=="string"?{message:n}:n||{},a.toString=n=>typeof n=="string"?n:n==null?void 0:n.message})(k||(k={}));var st,it;class ee{constructor(n,i,c,u){this._cachedPath=[],this.parent=n,this.data=i,this._path=c,this._key=u}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Xs=(a,n)=>{if(ke(n))return{success:!0,data:n.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const i=new z(a.common.issues);return this._error=i,this._error}}};function O(a){if(!a)return{};const{errorMap:n,invalid_type_error:i,required_error:c,description:u}=a;if(n&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return n?{errorMap:n,description:u}:{errorMap:(h,m)=>{var w,v;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??m.defaultError}:typeof m.data>"u"?{message:(w=E??c)!==null&&w!==void 0?w:m.defaultError}:h.code!=="invalid_type"?{message:m.defaultError}:{message:(v=E??i)!==null&&v!==void 0?v:m.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(n){return ae(n.data)}_getOrReturnCtx(n,i){return i||{common:n.parent.common,data:n.data,parsedType:ae(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}_processInputParams(n){return{status:new L,ctx:{common:n.parent.common,data:n.data,parsedType:ae(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}}_parseSync(n){const i=this._parse(n);if(at(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(n){const i=this._parse(n);return Promise.resolve(i)}parse(n,i){const c=this.safeParse(n,i);if(c.success)return c.data;throw c.error}safeParse(n,i){var c;const u={common:{issues:[],async:(c=i==null?void 0:i.async)!==null&&c!==void 0?c:!1,contextualErrorMap:i==null?void 0:i.errorMap},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)},d=this._parseSync({data:n,path:u.path,parent:u});return Xs(u,d)}"~validate"(n){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)};if(!this["~standard"].async)try{const d=this._parseSync({data:n,path:[],parent:u});return ke(d)?{value:d.value}:{issues:u.common.issues}}catch(d){!((c=(i=d==null?void 0:d.message)===null||i===void 0?void 0:i.toLowerCase())===null||c===void 0)&&c.includes("encountered")&&(this["~standard"].async=!0),u.common={issues:[],async:!0}}return this._parseAsync({data:n,path:[],parent:u}).then(d=>ke(d)?{value:d.value}:{issues:u.common.issues})}async parseAsync(n,i){const c=await this.safeParseAsync(n,i);if(c.success)return c.data;throw c.error}async safeParseAsync(n,i){const c={common:{issues:[],contextualErrorMap:i==null?void 0:i.errorMap,async:!0},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)},u=this._parse({data:n,path:c.path,parent:c}),d=await(at(u)?u:Promise.resolve(u));return Xs(c,d)}refine(n,i){const c=u=>typeof i=="string"||typeof i>"u"?{message:i}:typeof i=="function"?i(u):i;return this._refinement((u,d)=>{const h=n(u),m=()=>d.addIssue({code:y.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(w=>w?!0:(m(),!1)):h?!0:(m(),!1)})}refinement(n,i){return this._refinement((c,u)=>n(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(n){return new G({schema:this,typeName:A.ZodEffects,effect:{type:"refinement",refinement:n}})}superRefine(n){return this._refinement(n)}constructor(n){this.spa=this.safeParseAsync,this._def=n,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:i=>this["~validate"](i)}}optional(){return X.create(this,this._def)}nullable(){return pe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return q.create(this)}promise(){return Ze.create(this,this._def)}or(n){return lt.create([this,n],this._def)}and(n){return dt.create(this,n,this._def)}transform(n){return new G({...O(this._def),schema:this,typeName:A.ZodEffects,effect:{type:"transform",transform:n}})}default(n){const i=typeof n=="function"?n:()=>n;return new gt({...O(this._def),innerType:this,defaultValue:i,typeName:A.ZodDefault})}brand(){return new An({typeName:A.ZodBranded,type:this,...O(this._def)})}catch(n){const i=typeof n=="function"?n:()=>n;return new yt({...O(this._def),innerType:this,catchValue:i,typeName:A.ZodCatch})}describe(n){const i=this.constructor;return new i({...this._def,description:n})}pipe(n){return wt.create(this,n)}readonly(){return vt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Fl=/^c[^\s-]{8,}$/i,zl=/^[0-9a-z]+$/,Vl=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Wl=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Hl=/^[a-z0-9_-]{21}$/i,ql=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Gl=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Kl=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Jl="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let vn;const Yl=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ql=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Xl=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ed=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,td=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,rd=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ii="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",nd=new RegExp(`^${ii}$`);function ai(a){let n="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?n=`${n}\\.\\d{${a.precision}}`:a.precision==null&&(n=`${n}(\\.\\d+)?`),n}function sd(a){return new RegExp(`^${ai(a)}$`)}function oi(a){let n=`${ii}T${ai(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),n=`${n}(${i.join("|")})`,new RegExp(`^${n}$`)}function id(a,n){return!!((n==="v4"||!n)&&Yl.test(a)||(n==="v6"||!n)&&Xl.test(a))}function ad(a,n){if(!ql.test(a))return!1;try{const[i]=a.split("."),c=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(i.length+(4-i.length%4)%4,"="),u=JSON.parse(atob(c));return!(typeof u!="object"||u===null||!u.typ||!u.alg||n&&u.alg!==n)}catch{return!1}}function od(a,n){return!!((n==="v4"||!n)&&Ql.test(a)||(n==="v6"||!n)&&ed.test(a))}class H extends I{_parse(n){if(this._def.coerce&&(n.data=String(n.data)),this._getType(n)!==_.string){const d=this._getOrReturnCtx(n);return b(d,{code:y.invalid_type,expected:_.string,received:d.parsedType}),S}const c=new L;let u;for(const d of this._def.checks)if(d.kind==="min")n.data.length<d.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_small,minimum:d.value,type:"string",inclusive:!0,exact:!1,message:d.message}),c.dirty());else if(d.kind==="max")n.data.length>d.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_big,maximum:d.value,type:"string",inclusive:!0,exact:!1,message:d.message}),c.dirty());else if(d.kind==="length"){const h=n.data.length>d.value,m=n.data.length<d.value;(h||m)&&(u=this._getOrReturnCtx(n,u),h?b(u,{code:y.too_big,maximum:d.value,type:"string",inclusive:!0,exact:!0,message:d.message}):m&&b(u,{code:y.too_small,minimum:d.value,type:"string",inclusive:!0,exact:!0,message:d.message}),c.dirty())}else if(d.kind==="email")Kl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"email",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="emoji")vn||(vn=new RegExp(Jl,"u")),vn.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"emoji",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="uuid")Wl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"uuid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="nanoid")Hl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"nanoid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="cuid")Fl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cuid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="cuid2")zl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cuid2",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="ulid")Vl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"ulid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="url")try{new URL(n.data)}catch{u=this._getOrReturnCtx(n,u),b(u,{validation:"url",code:y.invalid_string,message:d.message}),c.dirty()}else d.kind==="regex"?(d.regex.lastIndex=0,d.regex.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"regex",code:y.invalid_string,message:d.message}),c.dirty())):d.kind==="trim"?n.data=n.data.trim():d.kind==="includes"?n.data.includes(d.value,d.position)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{includes:d.value,position:d.position},message:d.message}),c.dirty()):d.kind==="toLowerCase"?n.data=n.data.toLowerCase():d.kind==="toUpperCase"?n.data=n.data.toUpperCase():d.kind==="startsWith"?n.data.startsWith(d.value)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{startsWith:d.value},message:d.message}),c.dirty()):d.kind==="endsWith"?n.data.endsWith(d.value)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{endsWith:d.value},message:d.message}),c.dirty()):d.kind==="datetime"?oi(d).test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"datetime",message:d.message}),c.dirty()):d.kind==="date"?nd.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"date",message:d.message}),c.dirty()):d.kind==="time"?sd(d).test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"time",message:d.message}),c.dirty()):d.kind==="duration"?Gl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"duration",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="ip"?id(n.data,d.version)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"ip",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="jwt"?ad(n.data,d.alg)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"jwt",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="cidr"?od(n.data,d.version)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cidr",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="base64"?td.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"base64",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="base64url"?rd.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"base64url",code:y.invalid_string,message:d.message}),c.dirty()):M.assertNever(d);return{status:c.value,value:n.data}}_regex(n,i,c){return this.refinement(u=>n.test(u),{validation:i,code:y.invalid_string,...k.errToObj(c)})}_addCheck(n){return new H({...this._def,checks:[...this._def.checks,n]})}email(n){return this._addCheck({kind:"email",...k.errToObj(n)})}url(n){return this._addCheck({kind:"url",...k.errToObj(n)})}emoji(n){return this._addCheck({kind:"emoji",...k.errToObj(n)})}uuid(n){return this._addCheck({kind:"uuid",...k.errToObj(n)})}nanoid(n){return this._addCheck({kind:"nanoid",...k.errToObj(n)})}cuid(n){return this._addCheck({kind:"cuid",...k.errToObj(n)})}cuid2(n){return this._addCheck({kind:"cuid2",...k.errToObj(n)})}ulid(n){return this._addCheck({kind:"ulid",...k.errToObj(n)})}base64(n){return this._addCheck({kind:"base64",...k.errToObj(n)})}base64url(n){return this._addCheck({kind:"base64url",...k.errToObj(n)})}jwt(n){return this._addCheck({kind:"jwt",...k.errToObj(n)})}ip(n){return this._addCheck({kind:"ip",...k.errToObj(n)})}cidr(n){return this._addCheck({kind:"cidr",...k.errToObj(n)})}datetime(n){var i,c;return typeof n=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:n}):this._addCheck({kind:"datetime",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,offset:(i=n==null?void 0:n.offset)!==null&&i!==void 0?i:!1,local:(c=n==null?void 0:n.local)!==null&&c!==void 0?c:!1,...k.errToObj(n==null?void 0:n.message)})}date(n){return this._addCheck({kind:"date",message:n})}time(n){return typeof n=="string"?this._addCheck({kind:"time",precision:null,message:n}):this._addCheck({kind:"time",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,...k.errToObj(n==null?void 0:n.message)})}duration(n){return this._addCheck({kind:"duration",...k.errToObj(n)})}regex(n,i){return this._addCheck({kind:"regex",regex:n,...k.errToObj(i)})}includes(n,i){return this._addCheck({kind:"includes",value:n,position:i==null?void 0:i.position,...k.errToObj(i==null?void 0:i.message)})}startsWith(n,i){return this._addCheck({kind:"startsWith",value:n,...k.errToObj(i)})}endsWith(n,i){return this._addCheck({kind:"endsWith",value:n,...k.errToObj(i)})}min(n,i){return this._addCheck({kind:"min",value:n,...k.errToObj(i)})}max(n,i){return this._addCheck({kind:"max",value:n,...k.errToObj(i)})}length(n,i){return this._addCheck({kind:"length",value:n,...k.errToObj(i)})}nonempty(n){return this.min(1,k.errToObj(n))}trim(){return new H({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(n=>n.kind==="datetime")}get isDate(){return!!this._def.checks.find(n=>n.kind==="date")}get isTime(){return!!this._def.checks.find(n=>n.kind==="time")}get isDuration(){return!!this._def.checks.find(n=>n.kind==="duration")}get isEmail(){return!!this._def.checks.find(n=>n.kind==="email")}get isURL(){return!!this._def.checks.find(n=>n.kind==="url")}get isEmoji(){return!!this._def.checks.find(n=>n.kind==="emoji")}get isUUID(){return!!this._def.checks.find(n=>n.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(n=>n.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(n=>n.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(n=>n.kind==="cuid2")}get isULID(){return!!this._def.checks.find(n=>n.kind==="ulid")}get isIP(){return!!this._def.checks.find(n=>n.kind==="ip")}get isCIDR(){return!!this._def.checks.find(n=>n.kind==="cidr")}get isBase64(){return!!this._def.checks.find(n=>n.kind==="base64")}get isBase64url(){return!!this._def.checks.find(n=>n.kind==="base64url")}get minLength(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxLength(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}H.create=a=>{var n;return new H({checks:[],typeName:A.ZodString,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};function cd(a,n){const i=(a.toString().split(".")[1]||"").length,c=(n.toString().split(".")[1]||"").length,u=i>c?i:c,d=parseInt(a.toFixed(u).replace(".","")),h=parseInt(n.toFixed(u).replace(".",""));return d%h/Math.pow(10,u)}class fe extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(n){if(this._def.coerce&&(n.data=Number(n.data)),this._getType(n)!==_.number){const d=this._getOrReturnCtx(n);return b(d,{code:y.invalid_type,expected:_.number,received:d.parsedType}),S}let c;const u=new L;for(const d of this._def.checks)d.kind==="int"?M.isInteger(n.data)||(c=this._getOrReturnCtx(n,c),b(c,{code:y.invalid_type,expected:"integer",received:"float",message:d.message}),u.dirty()):d.kind==="min"?(d.inclusive?n.data<d.value:n.data<=d.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_small,minimum:d.value,type:"number",inclusive:d.inclusive,exact:!1,message:d.message}),u.dirty()):d.kind==="max"?(d.inclusive?n.data>d.value:n.data>=d.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_big,maximum:d.value,type:"number",inclusive:d.inclusive,exact:!1,message:d.message}),u.dirty()):d.kind==="multipleOf"?cd(n.data,d.value)!==0&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_multiple_of,multipleOf:d.value,message:d.message}),u.dirty()):d.kind==="finite"?Number.isFinite(n.data)||(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_finite,message:d.message}),u.dirty()):M.assertNever(d);return{status:u.value,value:n.data}}gte(n,i){return this.setLimit("min",n,!0,k.toString(i))}gt(n,i){return this.setLimit("min",n,!1,k.toString(i))}lte(n,i){return this.setLimit("max",n,!0,k.toString(i))}lt(n,i){return this.setLimit("max",n,!1,k.toString(i))}setLimit(n,i,c,u){return new fe({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:k.toString(u)}]})}_addCheck(n){return new fe({...this._def,checks:[...this._def.checks,n]})}int(n){return this._addCheck({kind:"int",message:k.toString(n)})}positive(n){return this._addCheck({kind:"min",value:0,inclusive:!1,message:k.toString(n)})}negative(n){return this._addCheck({kind:"max",value:0,inclusive:!1,message:k.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:0,inclusive:!0,message:k.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:0,inclusive:!0,message:k.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:k.toString(i)})}finite(n){return this._addCheck({kind:"finite",message:k.toString(n)})}safe(n){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:k.toString(n)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:k.toString(n)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}get isInt(){return!!this._def.checks.find(n=>n.kind==="int"||n.kind==="multipleOf"&&M.isInteger(n.value))}get isFinite(){let n=null,i=null;for(const c of this._def.checks){if(c.kind==="finite"||c.kind==="int"||c.kind==="multipleOf")return!0;c.kind==="min"?(i===null||c.value>i)&&(i=c.value):c.kind==="max"&&(n===null||c.value<n)&&(n=c.value)}return Number.isFinite(i)&&Number.isFinite(n)}}fe.create=a=>new fe({checks:[],typeName:A.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class he extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(n){if(this._def.coerce)try{n.data=BigInt(n.data)}catch{return this._getInvalidInput(n)}if(this._getType(n)!==_.bigint)return this._getInvalidInput(n);let c;const u=new L;for(const d of this._def.checks)d.kind==="min"?(d.inclusive?n.data<d.value:n.data<=d.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_small,type:"bigint",minimum:d.value,inclusive:d.inclusive,message:d.message}),u.dirty()):d.kind==="max"?(d.inclusive?n.data>d.value:n.data>=d.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_big,type:"bigint",maximum:d.value,inclusive:d.inclusive,message:d.message}),u.dirty()):d.kind==="multipleOf"?n.data%d.value!==BigInt(0)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_multiple_of,multipleOf:d.value,message:d.message}),u.dirty()):M.assertNever(d);return{status:u.value,value:n.data}}_getInvalidInput(n){const i=this._getOrReturnCtx(n);return b(i,{code:y.invalid_type,expected:_.bigint,received:i.parsedType}),S}gte(n,i){return this.setLimit("min",n,!0,k.toString(i))}gt(n,i){return this.setLimit("min",n,!1,k.toString(i))}lte(n,i){return this.setLimit("max",n,!0,k.toString(i))}lt(n,i){return this.setLimit("max",n,!1,k.toString(i))}setLimit(n,i,c,u){return new he({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:k.toString(u)}]})}_addCheck(n){return new he({...this._def,checks:[...this._def.checks,n]})}positive(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:k.toString(n)})}negative(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:k.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:k.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:k.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:k.toString(i)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}he.create=a=>{var n;return new he({checks:[],typeName:A.ZodBigInt,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};class ot extends I{_parse(n){if(this._def.coerce&&(n.data=!!n.data),this._getType(n)!==_.boolean){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.boolean,received:c.parsedType}),S}return F(n.data)}}ot.create=a=>new ot({typeName:A.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class Ee extends I{_parse(n){if(this._def.coerce&&(n.data=new Date(n.data)),this._getType(n)!==_.date){const d=this._getOrReturnCtx(n);return b(d,{code:y.invalid_type,expected:_.date,received:d.parsedType}),S}if(isNaN(n.data.getTime())){const d=this._getOrReturnCtx(n);return b(d,{code:y.invalid_date}),S}const c=new L;let u;for(const d of this._def.checks)d.kind==="min"?n.data.getTime()<d.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_small,message:d.message,inclusive:!0,exact:!1,minimum:d.value,type:"date"}),c.dirty()):d.kind==="max"?n.data.getTime()>d.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_big,message:d.message,inclusive:!0,exact:!1,maximum:d.value,type:"date"}),c.dirty()):M.assertNever(d);return{status:c.value,value:new Date(n.data.getTime())}}_addCheck(n){return new Ee({...this._def,checks:[...this._def.checks,n]})}min(n,i){return this._addCheck({kind:"min",value:n.getTime(),message:k.toString(i)})}max(n,i){return this._addCheck({kind:"max",value:n.getTime(),message:k.toString(i)})}get minDate(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n!=null?new Date(n):null}get maxDate(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n!=null?new Date(n):null}}Ee.create=a=>new Ee({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:A.ZodDate,...O(a)});class Pt extends I{_parse(n){if(this._getType(n)!==_.symbol){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.symbol,received:c.parsedType}),S}return F(n.data)}}Pt.create=a=>new Pt({typeName:A.ZodSymbol,...O(a)});class ct extends I{_parse(n){if(this._getType(n)!==_.undefined){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.undefined,received:c.parsedType}),S}return F(n.data)}}ct.create=a=>new ct({typeName:A.ZodUndefined,...O(a)});class ut extends I{_parse(n){if(this._getType(n)!==_.null){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.null,received:c.parsedType}),S}return F(n.data)}}ut.create=a=>new ut({typeName:A.ZodNull,...O(a)});class Pe extends I{constructor(){super(...arguments),this._any=!0}_parse(n){return F(n.data)}}Pe.create=a=>new Pe({typeName:A.ZodAny,...O(a)});class xe extends I{constructor(){super(...arguments),this._unknown=!0}_parse(n){return F(n.data)}}xe.create=a=>new xe({typeName:A.ZodUnknown,...O(a)});class oe extends I{_parse(n){const i=this._getOrReturnCtx(n);return b(i,{code:y.invalid_type,expected:_.never,received:i.parsedType}),S}}oe.create=a=>new oe({typeName:A.ZodNever,...O(a)});class Zt extends I{_parse(n){if(this._getType(n)!==_.undefined){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.void,received:c.parsedType}),S}return F(n.data)}}Zt.create=a=>new Zt({typeName:A.ZodVoid,...O(a)});class q extends I{_parse(n){const{ctx:i,status:c}=this._processInputParams(n),u=this._def;if(i.parsedType!==_.array)return b(i,{code:y.invalid_type,expected:_.array,received:i.parsedType}),S;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,m=i.data.length<u.exactLength.value;(h||m)&&(b(i,{code:h?y.too_big:y.too_small,minimum:m?u.exactLength.value:void 0,maximum:h?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),c.dirty())}if(u.minLength!==null&&i.data.length<u.minLength.value&&(b(i,{code:y.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),c.dirty()),u.maxLength!==null&&i.data.length>u.maxLength.value&&(b(i,{code:y.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),c.dirty()),i.common.async)return Promise.all([...i.data].map((h,m)=>u.type._parseAsync(new ee(i,h,i.path,m)))).then(h=>L.mergeArray(c,h));const d=[...i.data].map((h,m)=>u.type._parseSync(new ee(i,h,i.path,m)));return L.mergeArray(c,d)}get element(){return this._def.type}min(n,i){return new q({...this._def,minLength:{value:n,message:k.toString(i)}})}max(n,i){return new q({...this._def,maxLength:{value:n,message:k.toString(i)}})}length(n,i){return new q({...this._def,exactLength:{value:n,message:k.toString(i)}})}nonempty(n){return this.min(1,n)}}q.create=(a,n)=>new q({type:a,minLength:null,maxLength:null,exactLength:null,typeName:A.ZodArray,...O(n)});function Re(a){if(a instanceof R){const n={};for(const i in a.shape){const c=a.shape[i];n[i]=X.create(Re(c))}return new R({...a._def,shape:()=>n})}else return a instanceof q?new q({...a._def,type:Re(a.element)}):a instanceof X?X.create(Re(a.unwrap())):a instanceof pe?pe.create(Re(a.unwrap())):a instanceof te?te.create(a.items.map(n=>Re(n))):a}class R extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const n=this._def.shape(),i=M.objectKeys(n);return this._cached={shape:n,keys:i}}_parse(n){if(this._getType(n)!==_.object){const v=this._getOrReturnCtx(n);return b(v,{code:y.invalid_type,expected:_.object,received:v.parsedType}),S}const{status:c,ctx:u}=this._processInputParams(n),{shape:d,keys:h}=this._getCached(),m=[];if(!(this._def.catchall instanceof oe&&this._def.unknownKeys==="strip"))for(const v in u.data)h.includes(v)||m.push(v);const w=[];for(const v of h){const E=d[v],D=u.data[v];w.push({key:{status:"valid",value:v},value:E._parse(new ee(u,D,u.path,v)),alwaysSet:v in u.data})}if(this._def.catchall instanceof oe){const v=this._def.unknownKeys;if(v==="passthrough")for(const E of m)w.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(v==="strict")m.length>0&&(b(u,{code:y.unrecognized_keys,keys:m}),c.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const v=this._def.catchall;for(const E of m){const D=u.data[E];w.push({key:{status:"valid",value:E},value:v._parse(new ee(u,D,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const v=[];for(const E of w){const D=await E.key,re=await E.value;v.push({key:D,value:re,alwaysSet:E.alwaysSet})}return v}).then(v=>L.mergeObjectSync(c,v)):L.mergeObjectSync(c,w)}get shape(){return this._def.shape()}strict(n){return k.errToObj,new R({...this._def,unknownKeys:"strict",...n!==void 0?{errorMap:(i,c)=>{var u,d,h,m;const w=(h=(d=(u=this._def).errorMap)===null||d===void 0?void 0:d.call(u,i,c).message)!==null&&h!==void 0?h:c.defaultError;return i.code==="unrecognized_keys"?{message:(m=k.errToObj(n).message)!==null&&m!==void 0?m:w}:{message:w}}}:{}})}strip(){return new R({...this._def,unknownKeys:"strip"})}passthrough(){return new R({...this._def,unknownKeys:"passthrough"})}extend(n){return new R({...this._def,shape:()=>({...this._def.shape(),...n})})}merge(n){return new R({unknownKeys:n._def.unknownKeys,catchall:n._def.catchall,shape:()=>({...this._def.shape(),...n._def.shape()}),typeName:A.ZodObject})}setKey(n,i){return this.augment({[n]:i})}catchall(n){return new R({...this._def,catchall:n})}pick(n){const i={};return M.objectKeys(n).forEach(c=>{n[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}omit(n){const i={};return M.objectKeys(this.shape).forEach(c=>{n[c]||(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}deepPartial(){return Re(this)}partial(n){const i={};return M.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];n&&!n[c]?i[c]=u:i[c]=u.optional()}),new R({...this._def,shape:()=>i})}required(n){const i={};return M.objectKeys(this.shape).forEach(c=>{if(n&&!n[c])i[c]=this.shape[c];else{let d=this.shape[c];for(;d instanceof X;)d=d._def.innerType;i[c]=d}}),new R({...this._def,shape:()=>i})}keyof(){return ci(M.objectKeys(this.shape))}}R.create=(a,n)=>new R({shape:()=>a,unknownKeys:"strip",catchall:oe.create(),typeName:A.ZodObject,...O(n)});R.strictCreate=(a,n)=>new R({shape:()=>a,unknownKeys:"strict",catchall:oe.create(),typeName:A.ZodObject,...O(n)});R.lazycreate=(a,n)=>new R({shape:a,unknownKeys:"strip",catchall:oe.create(),typeName:A.ZodObject,...O(n)});class lt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=this._def.options;function u(d){for(const m of d)if(m.result.status==="valid")return m.result;for(const m of d)if(m.result.status==="dirty")return i.common.issues.push(...m.ctx.common.issues),m.result;const h=d.map(m=>new z(m.ctx.common.issues));return b(i,{code:y.invalid_union,unionErrors:h}),S}if(i.common.async)return Promise.all(c.map(async d=>{const h={...i,common:{...i.common,issues:[]},parent:null};return{result:await d._parseAsync({data:i.data,path:i.path,parent:h}),ctx:h}})).then(u);{let d;const h=[];for(const w of c){const v={...i,common:{...i.common,issues:[]},parent:null},E=w._parseSync({data:i.data,path:i.path,parent:v});if(E.status==="valid")return E;E.status==="dirty"&&!d&&(d={result:E,ctx:v}),v.common.issues.length&&h.push(v.common.issues)}if(d)return i.common.issues.push(...d.ctx.common.issues),d.result;const m=h.map(w=>new z(w));return b(i,{code:y.invalid_union,unionErrors:m}),S}}get options(){return this._def.options}}lt.create=(a,n)=>new lt({options:a,typeName:A.ZodUnion,...O(n)});const ie=a=>a instanceof ht?ie(a.schema):a instanceof G?ie(a.innerType()):a instanceof mt?[a.value]:a instanceof me?a.options:a instanceof pt?M.objectValues(a.enum):a instanceof gt?ie(a._def.innerType):a instanceof ct?[void 0]:a instanceof ut?[null]:a instanceof X?[void 0,...ie(a.unwrap())]:a instanceof pe?[null,...ie(a.unwrap())]:a instanceof An||a instanceof vt?ie(a.unwrap()):a instanceof yt?ie(a._def.innerType):[];class Ft extends I{_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.object)return b(i,{code:y.invalid_type,expected:_.object,received:i.parsedType}),S;const c=this.discriminator,u=i.data[c],d=this.optionsMap.get(u);return d?i.common.async?d._parseAsync({data:i.data,path:i.path,parent:i}):d._parseSync({data:i.data,path:i.path,parent:i}):(b(i,{code:y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[c]}),S)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(n,i,c){const u=new Map;for(const d of i){const h=ie(d.shape[n]);if(!h.length)throw new Error(`A discriminator value for key \`${n}\` could not be extracted from all schema options`);for(const m of h){if(u.has(m))throw new Error(`Discriminator property ${String(n)} has duplicate value ${String(m)}`);u.set(m,d)}}return new Ft({typeName:A.ZodDiscriminatedUnion,discriminator:n,options:i,optionsMap:u,...O(c)})}}function kn(a,n){const i=ae(a),c=ae(n);if(a===n)return{valid:!0,data:a};if(i===_.object&&c===_.object){const u=M.objectKeys(n),d=M.objectKeys(a).filter(m=>u.indexOf(m)!==-1),h={...a,...n};for(const m of d){const w=kn(a[m],n[m]);if(!w.valid)return{valid:!1};h[m]=w.data}return{valid:!0,data:h}}else if(i===_.array&&c===_.array){if(a.length!==n.length)return{valid:!1};const u=[];for(let d=0;d<a.length;d++){const h=a[d],m=n[d],w=kn(h,m);if(!w.valid)return{valid:!1};u.push(w.data)}return{valid:!0,data:u}}else return i===_.date&&c===_.date&&+a==+n?{valid:!0,data:a}:{valid:!1}}class dt extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=(d,h)=>{if(_n(d)||_n(h))return S;const m=kn(d.value,h.value);return m.valid?((xn(d)||xn(h))&&i.dirty(),{status:i.value,value:m.data}):(b(c,{code:y.invalid_intersection_types}),S)};return c.common.async?Promise.all([this._def.left._parseAsync({data:c.data,path:c.path,parent:c}),this._def.right._parseAsync({data:c.data,path:c.path,parent:c})]).then(([d,h])=>u(d,h)):u(this._def.left._parseSync({data:c.data,path:c.path,parent:c}),this._def.right._parseSync({data:c.data,path:c.path,parent:c}))}}dt.create=(a,n,i)=>new dt({left:a,right:n,typeName:A.ZodIntersection,...O(i)});class te extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.array)return b(c,{code:y.invalid_type,expected:_.array,received:c.parsedType}),S;if(c.data.length<this._def.items.length)return b(c,{code:y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),S;!this._def.rest&&c.data.length>this._def.items.length&&(b(c,{code:y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const d=[...c.data].map((h,m)=>{const w=this._def.items[m]||this._def.rest;return w?w._parse(new ee(c,h,c.path,m)):null}).filter(h=>!!h);return c.common.async?Promise.all(d).then(h=>L.mergeArray(i,h)):L.mergeArray(i,d)}get items(){return this._def.items}rest(n){return new te({...this._def,rest:n})}}te.create=(a,n)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new te({items:a,typeName:A.ZodTuple,rest:null,...O(n)})};class ft extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.object)return b(c,{code:y.invalid_type,expected:_.object,received:c.parsedType}),S;const u=[],d=this._def.keyType,h=this._def.valueType;for(const m in c.data)u.push({key:d._parse(new ee(c,m,c.path,m)),value:h._parse(new ee(c,c.data[m],c.path,m)),alwaysSet:m in c.data});return c.common.async?L.mergeObjectAsync(i,u):L.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(n,i,c){return i instanceof I?new ft({keyType:n,valueType:i,typeName:A.ZodRecord,...O(c)}):new ft({keyType:H.create(),valueType:n,typeName:A.ZodRecord,...O(i)})}}class Bt extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.map)return b(c,{code:y.invalid_type,expected:_.map,received:c.parsedType}),S;const u=this._def.keyType,d=this._def.valueType,h=[...c.data.entries()].map(([m,w],v)=>({key:u._parse(new ee(c,m,c.path,[v,"key"])),value:d._parse(new ee(c,w,c.path,[v,"value"]))}));if(c.common.async){const m=new Map;return Promise.resolve().then(async()=>{for(const w of h){const v=await w.key,E=await w.value;if(v.status==="aborted"||E.status==="aborted")return S;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}})}else{const m=new Map;for(const w of h){const v=w.key,E=w.value;if(v.status==="aborted"||E.status==="aborted")return S;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}}}}Bt.create=(a,n,i)=>new Bt({valueType:n,keyType:a,typeName:A.ZodMap,...O(i)});class Ae extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.set)return b(c,{code:y.invalid_type,expected:_.set,received:c.parsedType}),S;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(b(c,{code:y.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),i.dirty()),u.maxSize!==null&&c.data.size>u.maxSize.value&&(b(c,{code:y.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),i.dirty());const d=this._def.valueType;function h(w){const v=new Set;for(const E of w){if(E.status==="aborted")return S;E.status==="dirty"&&i.dirty(),v.add(E.value)}return{status:i.value,value:v}}const m=[...c.data.values()].map((w,v)=>d._parse(new ee(c,w,c.path,v)));return c.common.async?Promise.all(m).then(w=>h(w)):h(m)}min(n,i){return new Ae({...this._def,minSize:{value:n,message:k.toString(i)}})}max(n,i){return new Ae({...this._def,maxSize:{value:n,message:k.toString(i)}})}size(n,i){return this.min(n,i).max(n,i)}nonempty(n){return this.min(1,n)}}Ae.create=(a,n)=>new Ae({valueType:a,minSize:null,maxSize:null,typeName:A.ZodSet,...O(n)});class je extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.function)return b(i,{code:y.invalid_type,expected:_.function,received:i.parsedType}),S;function c(m,w){return jt({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,Dt(),Ue].filter(v=>!!v),issueData:{code:y.invalid_arguments,argumentsError:w}})}function u(m,w){return jt({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,Dt(),Ue].filter(v=>!!v),issueData:{code:y.invalid_return_type,returnTypeError:w}})}const d={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Ze){const m=this;return F(async function(...w){const v=new z([]),E=await m._def.args.parseAsync(w,d).catch(ne=>{throw v.addIssue(c(w,ne)),v}),D=await Reflect.apply(h,this,E);return await m._def.returns._def.type.parseAsync(D,d).catch(ne=>{throw v.addIssue(u(D,ne)),v})})}else{const m=this;return F(function(...w){const v=m._def.args.safeParse(w,d);if(!v.success)throw new z([c(w,v.error)]);const E=Reflect.apply(h,this,v.data),D=m._def.returns.safeParse(E,d);if(!D.success)throw new z([u(E,D.error)]);return D.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...n){return new je({...this._def,args:te.create(n).rest(xe.create())})}returns(n){return new je({...this._def,returns:n})}implement(n){return this.parse(n)}strictImplement(n){return this.parse(n)}static create(n,i,c){return new je({args:n||te.create([]).rest(xe.create()),returns:i||xe.create(),typeName:A.ZodFunction,...O(c)})}}class ht extends I{get schema(){return this._def.getter()}_parse(n){const{ctx:i}=this._processInputParams(n);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}ht.create=(a,n)=>new ht({getter:a,typeName:A.ZodLazy,...O(n)});class mt extends I{_parse(n){if(n.data!==this._def.value){const i=this._getOrReturnCtx(n);return b(i,{received:i.data,code:y.invalid_literal,expected:this._def.value}),S}return{status:"valid",value:n.data}}get value(){return this._def.value}}mt.create=(a,n)=>new mt({value:a,typeName:A.ZodLiteral,...O(n)});function ci(a,n){return new me({values:a,typeName:A.ZodEnum,...O(n)})}class me extends I{constructor(){super(...arguments),st.set(this,void 0)}_parse(n){if(typeof n.data!="string"){const i=this._getOrReturnCtx(n),c=this._def.values;return b(i,{expected:M.joinValues(c),received:i.parsedType,code:y.invalid_type}),S}if(Ut(this,st)||si(this,st,new Set(this._def.values)),!Ut(this,st).has(n.data)){const i=this._getOrReturnCtx(n),c=this._def.values;return b(i,{received:i.data,code:y.invalid_enum_value,options:c}),S}return F(n.data)}get options(){return this._def.values}get enum(){const n={};for(const i of this._def.values)n[i]=i;return n}get Values(){const n={};for(const i of this._def.values)n[i]=i;return n}get Enum(){const n={};for(const i of this._def.values)n[i]=i;return n}extract(n,i=this._def){return me.create(n,{...this._def,...i})}exclude(n,i=this._def){return me.create(this.options.filter(c=>!n.includes(c)),{...this._def,...i})}}st=new WeakMap;me.create=ci;class pt extends I{constructor(){super(...arguments),it.set(this,void 0)}_parse(n){const i=M.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(n);if(c.parsedType!==_.string&&c.parsedType!==_.number){const u=M.objectValues(i);return b(c,{expected:M.joinValues(u),received:c.parsedType,code:y.invalid_type}),S}if(Ut(this,it)||si(this,it,new Set(M.getValidEnumValues(this._def.values))),!Ut(this,it).has(n.data)){const u=M.objectValues(i);return b(c,{received:c.data,code:y.invalid_enum_value,options:u}),S}return F(n.data)}get enum(){return this._def.values}}it=new WeakMap;pt.create=(a,n)=>new pt({values:a,typeName:A.ZodNativeEnum,...O(n)});class Ze extends I{unwrap(){return this._def.type}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.promise&&i.common.async===!1)return b(i,{code:y.invalid_type,expected:_.promise,received:i.parsedType}),S;const c=i.parsedType===_.promise?i.data:Promise.resolve(i.data);return F(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Ze.create=(a,n)=>new Ze({type:a,typeName:A.ZodPromise,...O(n)});class G extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===A.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=this._def.effect||null,d={addIssue:h=>{b(c,h),h.fatal?i.abort():i.dirty()},get path(){return c.path}};if(d.addIssue=d.addIssue.bind(d),u.type==="preprocess"){const h=u.transform(c.data,d);if(c.common.async)return Promise.resolve(h).then(async m=>{if(i.value==="aborted")return S;const w=await this._def.schema._parseAsync({data:m,path:c.path,parent:c});return w.status==="aborted"?S:w.status==="dirty"||i.value==="dirty"?De(w.value):w});{if(i.value==="aborted")return S;const m=this._def.schema._parseSync({data:h,path:c.path,parent:c});return m.status==="aborted"?S:m.status==="dirty"||i.value==="dirty"?De(m.value):m}}if(u.type==="refinement"){const h=m=>{const w=u.refinement(m,d);if(c.common.async)return Promise.resolve(w);if(w instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return m};if(c.common.async===!1){const m=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return m.status==="aborted"?S:(m.status==="dirty"&&i.dirty(),h(m.value),{status:i.value,value:m.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(m=>m.status==="aborted"?S:(m.status==="dirty"&&i.dirty(),h(m.value).then(()=>({status:i.value,value:m.value}))))}if(u.type==="transform")if(c.common.async===!1){const h=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});if(!ke(h))return h;const m=u.transform(h.value,d);if(m instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:m}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>ke(h)?Promise.resolve(u.transform(h.value,d)).then(m=>({status:i.value,value:m})):h);M.assertNever(u)}}G.create=(a,n,i)=>new G({schema:a,typeName:A.ZodEffects,effect:n,...O(i)});G.createWithPreprocess=(a,n,i)=>new G({schema:n,effect:{type:"preprocess",transform:a},typeName:A.ZodEffects,...O(i)});class X extends I{_parse(n){return this._getType(n)===_.undefined?F(void 0):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}X.create=(a,n)=>new X({innerType:a,typeName:A.ZodOptional,...O(n)});class pe extends I{_parse(n){return this._getType(n)===_.null?F(null):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}pe.create=(a,n)=>new pe({innerType:a,typeName:A.ZodNullable,...O(n)});class gt extends I{_parse(n){const{ctx:i}=this._processInputParams(n);let c=i.data;return i.parsedType===_.undefined&&(c=this._def.defaultValue()),this._def.innerType._parse({data:c,path:i.path,parent:i})}removeDefault(){return this._def.innerType}}gt.create=(a,n)=>new gt({innerType:a,typeName:A.ZodDefault,defaultValue:typeof n.default=="function"?n.default:()=>n.default,...O(n)});class yt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return at(u)?u.then(d=>({status:"valid",value:d.status==="valid"?d.value:this._def.catchValue({get error(){return new z(c.common.issues)},input:c.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new z(c.common.issues)},input:c.data})}}removeCatch(){return this._def.innerType}}yt.create=(a,n)=>new yt({innerType:a,typeName:A.ZodCatch,catchValue:typeof n.catch=="function"?n.catch:()=>n.catch,...O(n)});class Lt extends I{_parse(n){if(this._getType(n)!==_.nan){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.nan,received:c.parsedType}),S}return{status:"valid",value:n.data}}}Lt.create=a=>new Lt({typeName:A.ZodNaN,...O(a)});const ud=Symbol("zod_brand");class An extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class wt extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.common.async)return(async()=>{const d=await this._def.in._parseAsync({data:c.data,path:c.path,parent:c});return d.status==="aborted"?S:d.status==="dirty"?(i.dirty(),De(d.value)):this._def.out._parseAsync({data:d.value,path:c.path,parent:c})})();{const u=this._def.in._parseSync({data:c.data,path:c.path,parent:c});return u.status==="aborted"?S:u.status==="dirty"?(i.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:c.path,parent:c})}}static create(n,i){return new wt({in:n,out:i,typeName:A.ZodPipeline})}}class vt extends I{_parse(n){const i=this._def.innerType._parse(n),c=u=>(ke(u)&&(u.value=Object.freeze(u.value)),u);return at(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}vt.create=(a,n)=>new vt({innerType:a,typeName:A.ZodReadonly,...O(n)});function ui(a,n={},i){return a?Pe.create().superRefine((c,u)=>{var d,h;if(!a(c)){const m=typeof n=="function"?n(c):typeof n=="string"?{message:n}:n,w=(h=(d=m.fatal)!==null&&d!==void 0?d:i)!==null&&h!==void 0?h:!0,v=typeof m=="string"?{message:m}:m;u.addIssue({code:"custom",...v,fatal:w})}}):Pe.create()}const ld={object:R.lazycreate};var A;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(A||(A={}));const dd=(a,n={message:`Input not instance of ${a.name}`})=>ui(i=>i instanceof a,n),li=H.create,di=fe.create,fd=Lt.create,hd=he.create,fi=ot.create,md=Ee.create,pd=Pt.create,gd=ct.create,yd=ut.create,vd=Pe.create,wd=xe.create,bd=oe.create,_d=Zt.create,xd=q.create,kd=R.create,Ed=R.strictCreate,Ad=lt.create,Sd=Ft.create,Td=dt.create,Od=te.create,Id=ft.create,Md=Bt.create,$d=Ae.create,Cd=je.create,Nd=ht.create,Rd=mt.create,Dd=me.create,jd=pt.create,Ud=Ze.create,ei=G.create,Pd=X.create,Zd=pe.create,Bd=G.createWithPreprocess,Ld=wt.create,Fd=()=>li().optional(),zd=()=>di().optional(),Vd=()=>fi().optional(),Wd={string:a=>H.create({...a,coerce:!0}),number:a=>fe.create({...a,coerce:!0}),boolean:a=>ot.create({...a,coerce:!0}),bigint:a=>he.create({...a,coerce:!0}),date:a=>Ee.create({...a,coerce:!0})},Hd=S;var Y=Object.freeze({__proto__:null,defaultErrorMap:Ue,setErrorMap:Bl,getErrorMap:Dt,makeIssue:jt,EMPTY_PATH:Ll,addIssueToContext:b,ParseStatus:L,INVALID:S,DIRTY:De,OK:F,isAborted:_n,isDirty:xn,isValid:ke,isAsync:at,get util(){return M},get objectUtil(){return bn},ZodParsedType:_,getParsedType:ae,ZodType:I,datetimeRegex:oi,ZodString:H,ZodNumber:fe,ZodBigInt:he,ZodBoolean:ot,ZodDate:Ee,ZodSymbol:Pt,ZodUndefined:ct,ZodNull:ut,ZodAny:Pe,ZodUnknown:xe,ZodNever:oe,ZodVoid:Zt,ZodArray:q,ZodObject:R,ZodUnion:lt,ZodDiscriminatedUnion:Ft,ZodIntersection:dt,ZodTuple:te,ZodRecord:ft,ZodMap:Bt,ZodSet:Ae,ZodFunction:je,ZodLazy:ht,ZodLiteral:mt,ZodEnum:me,ZodNativeEnum:pt,ZodPromise:Ze,ZodEffects:G,ZodTransformer:G,ZodOptional:X,ZodNullable:pe,ZodDefault:gt,ZodCatch:yt,ZodNaN:Lt,BRAND:ud,ZodBranded:An,ZodPipeline:wt,ZodReadonly:vt,custom:ui,Schema:I,ZodSchema:I,late:ld,get ZodFirstPartyTypeKind(){return A},coerce:Wd,any:vd,array:xd,bigint:hd,boolean:fi,date:md,discriminatedUnion:Sd,effect:ei,enum:Dd,function:Cd,instanceof:dd,intersection:Td,lazy:Nd,literal:Rd,map:Md,nan:fd,nativeEnum:jd,never:bd,null:yd,nullable:Zd,number:di,object:kd,oboolean:Vd,onumber:zd,optional:Pd,ostring:Fd,pipeline:Ld,preprocess:Bd,promise:Ud,record:Id,set:$d,strictObject:Ed,string:li,symbol:pd,transformer:ei,tuple:Od,undefined:gd,union:Ad,unknown:wd,void:_d,NEVER:Hd,ZodIssueCode:y,quotelessJson:Zl,ZodError:z});const hi=Q.getInstance(),qd=Y.object({id:Y.string(),message:Y.string(),username:Y.string(),address:Y.string(),timestamp:Y.number(),signature:Y.string(),index:Y.number(),chatTopic:Y.string(),userTopic:Y.string()});function Gd(a){const n=qd.safeParse(a);return n.success?Kd(a)?!0:(console.warn("Invalid messageSender"),!1):(hi.warn(n.error.format()),!1)}function Kd(a){try{const n={username:a.username,address:a.address,timestamp:a.timestamp},i=new TextEncoder,c=B.concatBytes(i.encode(`Ethereum Signed Message:
11
- 32`),B.keccak256(i.encode(JSON.stringify(n))));if(new T.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(n){return hi.warn("Error in validateUserSignature",n),!1}}const W={LOADING_INIT:"loadingInit",LOADING_PREVIOUS_MESSAGES:"loadingPreviousMessages",MESSAGE_RECEIVED:"messageReceived",MESSAGE_REQUEST_INITIATED:"messageRequestInitiated",MESSAGE_REQUEST_UPLOADED:"messageRequestUploaded",MESSAGE_REQUEST_ERROR:"messageRequestError",CRITICAL_ERROR:"criticalError"};class Jd{constructor(n,i){this.utils=n,this.emitter=i,this.logger=Q.getInstance(),this.errorHandler=new En,this.historyIndex=null}async init(){try{const n=await this.utils.fetchLatestChatMessage();return this.historyIndex=n.index,await this.fetchPreviousMessages(),n.index}catch(n){return this.errorHandler.handleError(n,"SwarmHistory.init"),T.FeedIndex.fromBigInt(0n)}}async fetchPreviousMessages(n=10){try{if(!this.historyIndex){this.logger.warn("History index is not set. Cannot fetch previous messages.");return}if(this.historyIndex.toBigInt()===0n){this.logger.warn("No previous messages to fetch.");return}const i=this.historyIndex.toBigInt(),c=i>BigInt(n)?i-BigInt(n):0n;for(let u=i-1n;u>=c;u--){const d=await this.utils.fetchChatMessage(T.FeedIndex.fromBigInt(u));if(this.emitter.emit(W.MESSAGE_RECEIVED,d),this.historyIndex=T.FeedIndex.fromBigInt(u),u===0n)break}}catch(i){this.errorHandler.handleError(i,"SwarmHistory.fetchPreviousMessages")}}}class Yd{constructor(n,i){this.userDetails=n,this.swarmSettings=i,this.depth=24,this.logger=Q.getInstance(),this.errorHandler=new En,this.UPLOAD_GSOC_TIMEOUT=2e3}async writeOwnFeedDataByIndex(n,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(n,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(n,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(n,i){const{bee:c,stamp:u,chatTopic:d}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=this.generateUserOwnedFeedId(d,m),v=T.Topic.fromString(w);console.log("DEBUG: feedID write",v.toString(),m,n,w),await c.makeFeedWriter(v,new T.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:n})}async writeOwnFeedDataByIndexEnvelope(n,i){const{bee:c,stamp:u,chatTopic:d}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=new T.PrivateKey(h),v=T.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(d,m),D=T.Topic.fromString(E),re=ri(D,n),ne=Ys(i),Be=Qs(ne,re,w),Se={hash:()=>Be.address.toUint8Array()},zt=v.stamp(Se),{upload:Vt}=c.makeSOCWriter(w),Le=T.Bytes.fromUtf8(i);return(await Vt(zt,re,Le.toUint8Array())).reference.toHex()}orderMessages(n){return n.sort((i,c)=>i.timestamp-c.timestamp)}async retryAwaitableAsync(n,i=3,c=250){return new Promise((u,d)=>{n().then(u).catch(h=>{i>0?(this.logger.info(`Retrying... Attempts left: ${i}. Error: ${h.message}`),setTimeout(()=>{this.retryAwaitableAsync(n,i-1,c).then(u).catch(d)},c)):(this.errorHandler.handleError(h,"Utils.retryAwaitableAsync"),d(h))})})}async uploadObjectToBee(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(n);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(n)}async uploadObjectToBeeOwn(n){try{const{bee:i,stamp:c}=this.swarmSettings,u=await i.uploadData(c,JSON.stringify(n),{redundancyLevel:4});return console.log("DEBUG: result",u.reference.toString()),u.reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(n){try{const{bee:i,stamp:c}=this.swarmSettings,{privateKey:u}=this.userDetails,d=T.Stamper.fromBlank(u,c,this.depth),h=T.Bytes.fromUtf8(JSON.stringify(n)),m=new Cl(async v=>{await i.uploadChunk(d.stamp(v),v.build())});await m.append(h.toUint8Array());const w=await m.finalize();return B.uint8ArrayToHex(w.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:n,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),d=T.Topic.fromString(u),m=await n.makeFeedReader(d,c).downloadPayload(),w=Number(m.feedIndex.toBigInt()),v=w+1;return console.log("DEBUG: getLatestFeedIndex",w,v),{latestIndex:w,nextIndex:v}}catch(n){if(this.isNotFoundError(n))return{latestIndex:-1,nextIndex:0};throw n}}async fetchLatestChatMessage(){const{bee:n,chatTopic:i,chatAddress:c}=this.swarmSettings,d=await n.makeFeedReader(T.Topic.fromString(i),wn(c)).downloadPayload();return{message:d.payload.toJSON(),index:d.feedIndex}}async fetchChatMessage(n){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(T.Topic.fromString(c),wn(u)).downloadPayload({index:n})).payload.toJSON()}async sendMessageToGsoc(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(n);else if(c)await this.sendMessageToGsocEnvelope(n);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(n,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${n}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok)throw new Error(`Failed to fetch: ${n}/${i}`);return u.text()}async sendMessageToGsocOwn(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:d}=this.swarmSettings,h=new T.PrivateKey(d),m=T.Identifier.fromString(u),w=T.Bytes.fromUtf8(n),{upload:v}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await v(c,m,w.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}async sendMessageToGsocEnvelope(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:d}=this.swarmSettings,{privateKey:h}=this.userDetails,m=T.Stamper.fromBlank(h,c,this.depth),w=new T.PrivateKey(d),v=T.Identifier.fromString(u),E=T.Bytes.fromUtf8(n),D=Ys(E.toUint8Array()),re=Qs(D,v,w),ne={hash:()=>re.address.toUint8Array()},Be=m.stamp(ne),{upload:Se}=i.makeSOCWriter(w,{timeout:this.UPLOAD_GSOC_TIMEOUT});await Se(Be,v,E.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}generateUserOwnedFeedId(n,i){return`${n}_EthercastChat_${i}`}isNotFoundError(n){return n.stack.includes("404")||n.message.includes("Not Found")||n.message.includes("404")||n.code===404}}class Qd{constructor(n){this.logger=Q.getInstance(),this.errorHandler=new En,this.gsocIndex=null,this.fetchProcessRunning=!1,this.stopFetch=!1;const i=new T.PrivateKey(wn(n.user.privateKey));this.userDetails={privateKey:n.user.privateKey,ownAddress:i.publicKey().address().toString(),nickname:n.user.nickname,ownIndex:-1},this.swarmSettings={bee:new T.Bee(n.infra.beeUrl),beeUrl:n.infra.beeUrl,stamp:n.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:n.infra.enveloped,gsocTopic:n.infra.gsocTopic,gsocResourceId:n.infra.gsocResourceId,chatTopic:n.infra.chatTopic,chatAddress:n.infra.chatAddress},this.emitter=new Pl,this.utils=new Yd(this.userDetails,this.swarmSettings),this.history=new Jd(this.utils,this.emitter)}start(){this.init(),this.startMessagesFetchProcess()}stop(){this.emitter.cleanAll(),this.stopMessagesFetchProcess()}getEmitter(){return this.emitter}orderMessages(n){return this.utils.orderMessages(n)}async sendMessage(n,i){const c=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,u={id:i||Ml(),username:this.userDetails.nickname,address:this.userDetails.ownAddress,chatTopic:this.swarmSettings.chatTopic,userTopic:this.utils.generateUserOwnedFeedId(this.swarmSettings.chatTopic,this.userDetails.ownAddress),signature:this.getSignature(),timestamp:Date.now(),index:c,message:n};try{this.emitter.emit(W.MESSAGE_REQUEST_INITIATED,u),await this.utils.writeOwnFeedDataByIndex(c,JSON.stringify(u)),this.userDetails.ownIndex=c,this.emitter.emit(W.MESSAGE_REQUEST_UPLOADED,u),await this.broadcastUserMessage(u)}catch(d){this.emitter.emit(W.MESSAGE_REQUEST_ERROR,u),this.errorHandler.handleError(d,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessages()}finally{this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!1)}}async retrySendMessage(n){this.sendMessage(n.message,n.id)}async retryBroadcastUserMessage(n){this.broadcastUserMessage(n)}async init(){try{this.emitter.emit(W.LOADING_INIT,!0);const[n,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(n.status==="rejected")throw n.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(W.LOADING_INIT,!1)}catch(n){this.errorHandler.handleError(n,"Chat.initSelfState"),this.emitter.emit(W.CRITICAL_ERROR,n)}}async initOwnIndex(){const{latestIndex:c}=await this.utils.retryAwaitableAsync(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async fetchLatestMessage(){try{if(!this.gsocIndex)return;const n=T.Topic.fromString(this.swarmSettings.chatTopic),i=ri(n,this.gsocIndex),c=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,i.toString()),u=JSON.parse(c);if(this.logger.debug("fetchLatestMessage entry CALLED",c),!Gd(u)){this.logger.warn("Invalid GSOC message during fetching");return}this.emitter.emit(W.MESSAGE_RECEIVED,u),this.gsocIndex=this.gsocIndex.next()}catch(n){if(this.utils.isNotFoundError(n)||n.message.includes("Failed to fetch"))return;this.errorHandler.handleError(n,"Chat.fetchLatestMessage")}}async broadcastUserMessage(n){try{return this.logger.debug("broadcastUserMessage entry CALLED"),console.log("DEBUG broadcastUserMessage",n),this.utils.retryAwaitableAsync(()=>this.utils.sendMessageToGsoc(JSON.stringify(n)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(){const{ownAddress:n,privateKey:i,nickname:c}=this.userDetails,u=new T.EthAddress(n).toString(),d=new T.PrivateKey(i);if(d.publicKey().address().toString()!==u)throw new Error("The provided address does not match the address derived from the private key");const m=Date.now();return d.sign(JSON.stringify({username:c,address:u,timestamp:m})).toHex()}async startMessagesFetchProcess(){if(this.fetchProcessRunning)return;this.fetchProcessRunning=!0,this.stopFetch=!1;const n=async()=>{if(this.stopFetch){this.fetchProcessRunning=!1;return}await this.fetchLatestMessage(),setTimeout(n,200)};n()}stopMessagesFetchProcess(){this.stopFetch=!0}}exports.EVENTS=W;exports.SwarmChat=Qd;
4
+ `)}function At(e){return e.charAt(0).toUpperCase()+e.slice(1)}function qn(e){return e.charAt(0).toLowerCase()+e.slice(1)}function Gn(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function Kn(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function He(e){return Gn(e)||Kn(e)}const so=`
5
+ \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function io(e){return so.includes(e)}function ao(e){return He(e)||e==="."||e==="["||e==="]"||e==="_"}function oo(e,t,r,s,o){return e.slice(0,t)+s+e.slice(t,t+r)+o+e.slice(t+r)}function Jn(e,t,r=0){const s=t.exec(e.slice(r));return s?{index:s.index,match:s[0]}:null}function Yn(e,t,r=!0){if(!r)return t.every(o=>o instanceof RegExp?o.test(e):e.indexOf(o,0)!==-1);let s=0;for(const o of t)if(o instanceof RegExp){const d=Jn(e,o,s);if(!d)return!1;s=d.index+d.match.length}else{const d=e.indexOf(o,s);if(d===-1)return!1;s=d+o.length}return!0}function co(e,t,r=!0){let s=0;for(const o of t){let d=!1;for(;!d&&s<e.length;)Yn(e[s],o,r)&&(d=!0),s++;if(!d)return!1}return!0}function uo(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function $e(e,t,r=0){let s=-1;for(const o of t){const d=e.indexOf(o,r);d!==-1&&(s===-1||d<s)&&(s=d)}return s}function lo(e,t=0){for(let r=t;r<e.length;r++)if(io(e[r]))return r;return-1}function fo(e,t=0){for(let r=t;r<e.length;r++)if(e[r]==="#"&&He(e[r+1]))return r;return-1}function Qn(e,t,r=0){return e.slice(0,r).lastIndexOf(t)}function Xn(e,t=0,r="{",s="}"){let o=1;for(let d=t;d<e.length;d++)if(e.slice(d,d+s.length)===s){if(--o===0)return d}else e.slice(d,d+r.length)===r&&o++;return-1}function es(e,t){const r=t.wordBoundary?$e(e,[`${t.opening} `,`${t.opening}
6
+ `],t.start||0):e.indexOf(t.opening,t.start||0);if(r===-1)return null;const s=Xn(e,r+t.opening.length,t.opening,t.closing);return s===-1?null:t.exclusive?e.slice(r+t.opening.length,s):e.slice(r,s+t.closing.length)}function ho(e,t){const r=[];let s=t.wordBoundary?$e(e,[`${t.opening} `,`${t.opening}
7
+ `],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(s===-1)return r;const o=es(e,{...t,start:s});if(!o)return r;r.push(o),s=t.wordBoundary?$e(e,[`${t.opening} `,`${t.opening}
8
+ `],s+o.length):e.indexOf(t.opening,s+o.length)}}function mo(e,t,r){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...r,start:s});if(!o)return e;const d=t(o);s=e.indexOf(o,s)+d.length,e=e.replace(o,d)}}function po(e,t){const r=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){r.push({string:e.slice(s),symbol:null});break}const d=e.indexOf(t,o+t.length);if(o>s&&d!==-1&&r.push({string:e.slice(s,o),symbol:null}),d===-1){r.push({string:e.slice(s),symbol:null});break}r.push({string:e.slice(o+t.length,d),symbol:t}),s=d+t.length}return r}function go(e){const t=[];let r=0;for(;r<e.length;){const s=fo(e,r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=lo(e,s+1);if(o===-1){t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),r=o}return t}function yo(e){const t=[];let r=0;for(;r<e.length;){const s=$e(e,["http://","https://"],r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=$e(e,[" ",`
9
+ `],s);if(o===-1){s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),r=o}return t}const ts="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",rs="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function vo(e){return ns(e,ts)}function wo(e){return ss(e,ts)}function bo(e){return ns(e,rs)}function _o(e){return ss(e,rs)}function ns(e,t){const r="=",s=t.length;let o=0,d=0;const f=[];for(let g=0;g<e.length;g++){const p=e[g];if(p===r)break;const x=t.indexOf(p);if(x===-1)throw new Error(`Invalid character: ${p}`);d=d<<Math.log2(s)|x,o+=Math.log2(s),o>=8&&(o-=8,f.push(d>>o&255))}return new Uint8Array(f)}function ss(e,t){const r=t.length;let s=0,o=0,d="";for(let f=0;f<e.length;f++)for(o=o<<8|e[f],s+=8;s>=Math.log2(r);)s-=Math.log2(r),d+=t[o>>s&r-1];return s>0&&(d+=t[o<<Math.log2(r)-s&r-1]),d.length%4!==0&&(d+="=".repeat(4-d.length%4)),d}function xo(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,r=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);r[s]=o}return r}function ko(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Eo(e,t){const r=e.split("/").filter(d=>d),s=t.split("/").filter(d=>d);if(r.length!==s.length)return null;const o={};for(let d=0;d<r.length;d++){const f=r[d];if(f.startsWith(":"))o[f.slice(1)]=s[d];else if(f!==s[d])return null}return o}function ir(e,t,r){const s=[];for(const o of r)o!==t&&s.push(e.replace(t,o));return s}function So(e,t,r,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(g=>g),s),avoid:f.avoid})),s),d=[];for(const f of o){const g=f.variants.filter(x=>x!==f.avoid),p=g.find(x=>e.includes(x));if(p&&(St(d,ir(e,p,g)),d.length>=r))break}if(d.length<r)for(const f of o){const g=f.variants.find(p=>e.includes(p));if(g&&(St(d,ir(e,g,f.variants)),d.length>=r))break}return d.slice(0,r)}function To(e,t,r,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,r)}function Ao(e,t){const r=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(r,s=>s.toUpperCase()===s?s:t(s))}function Oo(e){return e.replace(/<[^>]*>/g,"")}function is(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const r=e.slice(0,t),s=e.slice(t+1);return{line:r,rest:s}}function Io(e,t={}){return[...e].reduce((r,s)=>r+(t[s]||1),0)}function $o(e,t,r={}){const s=[];let o="",d=0;for(let f=0;f<e.length;f++){const g=e[f],p=r[g]||1;if(o+=g,d+=p,d>t){const{line:x,rest:M}=is(o);s.push(x),o=M,d=M.split("").map(U=>r[U]||1).reduce((U,Re)=>U+Re,0)}}return o&&s.push(o),s}function Mo(e,t){const r=[];for(let s=0;s<=e.length;s++)r[s]=[s];for(let s=0;s<=t.length;s++)r[0][s]=s;for(let s=1;s<=e.length;s++)for(let o=1;o<=t.length;o++){const d=e[s-1]===t[o-1]?0:1;r[s][o]=Math.min(r[s-1][o]+1,r[s][o-1]+1,r[s-1][o-1]+d)}return r[e.length][t.length]}function ar(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function Co(e,t,r){return r==="any"?t.some(s=>ar(e,s)):t.every(s=>ar(e,s))}function No(e){const t={},r=e.match(/([a-z\-]+)="([^"]+)"/g);if(r)for(const s of r){const[o,d]=rr(s,"=");t[o]=d.slice(1,d.length-1)}return t}function Ot(e,t,r=[]){let s="";for(;t<e.length&&(He(e[t])||r.includes(e[t]));)s+=e[t++];return s}function Ro(e,t,r="$",s=":"){for(const o in t)e=as(e,o,t[o],r,s);return e=os(e),e}function as(e,t,r,s="$",o=":"){if(r==="")return e;let d=e.indexOf(`${s}${t}`);for(;d!==-1;){if(e[d+t.length+1]===o)if(e[d+t.length+2]===o)e=e.replace(`${s}${t}${o}${o}`,r);else{const f=Ot(e,d+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,r)}else e=e.replace(`${s}${t}`,r);d=e.indexOf(`${s}${t}`,d+r.length)}return e}function os(e,t="$",r=":"){let s=e.indexOf(t);for(;s!==-1;){const o=Ot(e,s+1);if(e[s+o.length+1]===r)if(e[s+o.length+2]===r)e=e.replace(`${t}${o}${r}${r}`,"");else{const d=Ot(e,s+o.length+2);e=e.replace(`${t}${o}${r}${d}`,d)}s=e.indexOf(t,s+1)}return e}function jo(e,t){let r=e.indexOf("](");for(;r!==-1;){const s=Qn(e,"[",r),o=e.indexOf(")",r);if(s!==-1&&o!==-1){const[d,f]=e.slice(s+1,o).split("]("),g=t(d,f);e=e.slice(0,s)+g+e.slice(o+1)}r=e.indexOf("](",r+1)}return e}function cs(e,t=!0){const r=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return r?(t?"?":"")+r:""}function Do(e){const t={},r=e.split("&");for(const s of r){const[o,d]=s.split("=");o&&d&&(t[o]=decodeURIComponent(d))}return t}function Uo(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Po(e,t){let r=null,s=-1/0;for(const[o,d]of Object.entries(e)){const f=t(d);f>s&&(s=f,r=o)}return r?[r,e[r]]:null}function Zo(e,t,r,s){const o=e.find(f=>f[t]===r),d=e.find(f=>f[t]===r+s);o&&d?(o[t]=r+s,d[t]=r):o&&(o[t]=r+s),e.sort((f,g)=>kt(f[t])-kt(g[t])),e.forEach((f,g)=>f[t]=g+1)}function Bo(e){const t=Object.keys(e);if(t.length===1)return e[t[0]];throw new Error("Expected object to have a single key")}function Lo(e,t=":"){return Object.fromEntries(e.map(r=>rr(r,t)).map(r=>r[0]&&r[1]?[We(r[0]),We(r[1])]:null).filter(r=>r))}function zo(e,t,r){return fs(e,t)+cs(r||{})}function Fo(e,t=",",r='"'){const s=[];let o="",d=!1;const f=e.split("");for(const g of f)g===t&&!d?(s.push(o),o=""):g===r&&(!o&&!d||d)?d=!d:o+=g;return s.push(o),s}function Vo(e){return`[${Math.floor(e.progress*100)}%] ${It(e.deltaMs)} out of ${It(e.totalTimeMs)} (${It(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function Wo(e,t,r){for(let s=0;s<r;s++){try{if(await e())return!0}catch{}s<r-1&&await l(t)}return!1}function Ho(e,t){const r=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&r.push(e.splice(s,1)[0]);return r}function qo(e){return JSON.parse(JSON.stringify(e))}function Go(e){return Math.ceil((e||Date.now())/1e3)}function Ko(e){return(e||new Date).toISOString().slice(0,10)}function Jo(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function Yo(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function Qo(e){return new Date(e)}function K(e){return String(Math.floor(e)).padStart(2,"0")}function Xo(e){let[t,r]=e.split(":");le(parseInt(t,10))||(t="0"),le(parseInt(r,10))||(r="0");let s=dr(Qt(t),0,23),o=dr(Qt(r),0,59);return`${K(s)}:${K(o)}`}function It(e){const t=Math.floor(e/36e5);e=e%36e5;const r=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${K(t)}:${K(r)}:${K(s)}`:`${K(r)}:${K(s)}`}function be(e){return Math.floor((Ie(e)?e.getTime():e)/864e5)}const ec={today:(e,t)=>K(e)+":"+K(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function tc(e,t){const r=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||ec,o=Ie(e)?e:new Date(e);if(be(r)===be(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(be(r)-be(o)===1)return s.yesterday();const d=cr(o);return be(r)-be(o)<7?s[d.day]():s.weeks(Math.round((r.getTime()-o.getTime())/6048e5))}const us={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function ls(e,t){const r=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||us,o=a.Types.isDate(e)?e.getTime():e;let d=(r-o)/1e3;return d<10?s.now():d<120?s.seconds(Math.floor(d)):(d/=60,d<120?s.minutes(Math.floor(d)):(d/=60,d<48?s.hours(Math.floor(d)):(d/=24,d<14?s.days(Math.floor(d)):(d/=7,s.weeks(Math.floor(d))))))}function rc(e,t=us){return ls(0,{now:e*1e3,labels:t})}function nc(e,t,r){const s=((r==null?void 0:r.now)??Date.now())-e,o=Math.floor(s/t),d=t/((r==null?void 0:r.precision)??1)-Math.ceil(s%t/((r==null?void 0:r.precision)??1));return{cycles:o,remaining:d}}const or={};function sc(e,t){return!or[e]||Date.now()>or[e]?(or[e]=Date.now()+t,!0):!1}const ic={s:1e3,m:6e4,h:36e5,d:864e5};function ac(e,t,r){return t=Ie(t)?t.getTime():t,r=r?Ie(r)?r.getTime():r:Date.now(),(r-t)/ic[e]}function oc(e,t,r,s){s||(s=Date.now());const o=t/r,d=s-e,f=d/t,g=f*r,p=g-d;return{deltaMs:d,progress:o,baseTimeMs:f,totalTimeMs:g,remainingTimeMs:p}}const cc={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function ds(e){return{zeroBasedIndex:e,day:cc[e]}}function cr(e){return ds(e.getDay())}function uc(e){return cr(new Date(e))}function lc(e){return e*1e3}function dc(e){return e*6e4}function fc(e){return e*36e5}function hc(e){return e*864e5}const mc={ms:1,milli:1,millis:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,month:2592e6,months:2592e6,y:31536e6,year:31536e6,years:31536e6};function pc(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=mc[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}const gc={b:1,byte:1,bytes:1,kb:1024,kilobyte:1024,kilobytes:1024,mb:1024**2,megabyte:1024**2,megabytes:1024**2,gb:1024**3,gigabyte:1024**3,gigabytes:1024**3,tb:1024**4,terabyte:1024**4,terabytes:1024**4};function yc(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=gc[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}function vc(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const ur={};async function wc(e,t,r){const s=Date.now(),o=ur[e];if(o&&o.validUntil>s)return o.value;const d=await r(),f=s+t;return ur[e]={value:d,validUntil:f},d}function bc(e){delete ur[e]}function fs(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function _c(e,t,r,s,o=!0){const d=e.indexOf(t),f=e.indexOf(r,d+t.length);if(d===-1||f===-1)throw Error("Start or end not found");return o?e.substring(0,d+t.length)+s+e.substring(f):e.substring(0,d)+s+e.substring(f+r.length)}function xc(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const r=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:r,hasPunctuation:s,endsWithColon:o}}function kc(e,t="(",r=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(r,o)?(s--,o+=r.length):o++,s<0)return!1;return t===r?s%2===0:s===0}function Ec(e){e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");let t=e.length;for(;e=e.replace(/(\w+)[\s,']+\w+/g,"$1"),e.length!==t;)t=e.length;return e=e.replaceAll(/[A-Z][a-zA-Z0-9]*/g,"A"),e=e.replaceAll(/[a-z][a-zA-Z0-9]*/g,"a"),e=e.replaceAll(/[\u4E00-\u9FA5]+/g,"Z"),e}function hs(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),r={};for(const s of t)r[s]=_e(e[s]);return r}function ms(e){const t=[];return e.sort((r,s)=>JSON.stringify(_e(r)).localeCompare(JSON.stringify(_e(s)))).forEach(r=>t.push(_e(r))),t}function _e(e){return Array.isArray(e)?ms(e):ue(e)?hs(e):e}function ps(e,t){return JSON.stringify(_e(e))===JSON.stringify(_e(t))}function Sc(...e){for(let t=1;t<e.length;t++)if(!ps(e[t-1],e[t]))return!1;return!0}function Tc(e){try{return JSON.parse(e)}catch{return null}}function Ac(){let e=0;return{next:()=>e++}}function Oc(e){let t=0;return{next:()=>e[t++%e.length]}}function Ic(e){let t;return r=>{const s=r===e&&t!==e;return t=r,s}}function $c(e,t,r,s,o){const d={};for(const f of Object.keys(t))d[f]=[];d[s]=[],o&&(e=e.sort(o));for(const f of e){const g=f[r],p=t[g]?g:s;d[p].length>=t[p]?d[s].push(f):d[p].push(f)}return d}function Mc(e,t){const r=Object.keys(e),s=Object.keys(t);return{uniqueToA:r.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!r.includes(o))}}function gs(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function Cc(e,t){const r=gs(e);return e[r]=t(e[r]),r}function Nc(e){return e=e.replace(/\r\n/g,`
10
+ `),e=e.replace(/(\w+)\((.+)\)/g,(t,r,s)=>`${r}(${s.replaceAll(",","&comma;")})`),e=e.replace(/(,)(\s+})/g,"$2"),e=e.replace(/\.\.\..+?,/g,""),e=e.replace(/({\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/(,\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/:(.+)\?(.+):/g,(t,r,s)=>`: (${r.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,r,s,o)=>`"${r}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const de=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],Rc=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],ys=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function jc(e,t,r){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(r?" "+r:"");let o=e.substring(0,s),d=e.substring(s);return o===""&&(o="0"),o+"."+d+(r?" "+r:"")}function Dc(e,t){const r=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=r?Rc:ys,d=(t==null?void 0:t.precision)??1;if(e<de[0])return`${e}${s}`;for(let f=0;f<de.length-1;f++)if(e<de[f+1])return`${(e/de[f]).toFixed(d)}${r?" ":""}${o[f]}${s}`;return`${(e/de[de.length-1]).toFixed(d)}${r?" ":""}${o[de.length-1]}${s}`}function lr(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim(),s=ys.findIndex(o=>o.toLowerCase()===r.toLowerCase());return s===-1?t:t*de[s]}function dr(e,t,r){return e<t?t:e>r?r:e}function Uc(e,t,r){const s=e+t;return s>r?r:s}function Pc(e,t,r){const s=e-t;return s<r?r:s}function Zc(e,t){return t(e),e}function Bc(e,t){e&&t(e)}function Lc(e,t){const r=Object.keys(t);for(const s of r)Array.isArray(t[s])&&Array.isArray(e[s])&&St(e[s],t[s])}function zc(e){return e.splice(0,e.length),e}function Fc(e){for(const t of Object.keys(e))($n(e[t])||Array.isArray(e[t])&&e[t].every(r=>r==null))&&delete e[t];return e}function Vc(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||V(t[1])&&xt(t[1]))&&delete e[t[0]];return e}function Wc(e,t){const r={};for(const[s,o]of Object.entries(e))t(s)&&(r[s]=o);return r}function Hc(e,t){const r={};for(const[s,o]of Object.entries(e))t(o)&&(r[s]=o);return r}function qc(e,t){const r={};for(const s of Object.entries(e))r[s[0]]=t(s[1]);return r}function Gc(e,t){const r=[];let s=0;for(const o of e)r.push(t(o,s++));return r}async function Kc(e,t){try{return await e()}catch{throw t}}function Jc(e,t,r){r!=null&&(e[t]=r)}function Yc(e,t,r,s){const o=ye(r,s);o!=null&&ve(e,t,o)}function Qc(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function Xc(e){const t=Object.keys(e),r=t.map(g=>e[g].length),s=r.reduce((g,p)=>g*=p);let o=1;const d=[1];for(let g=0;g<r.length-1;g++)o*=r[g],d.push(o);const f=[];for(let g=0;g<s;g++){const p={};for(let x=0;x<t.length;x++){const M=e[t[x]],U=Math.floor(g/d[x])%M.length;p[t[x]]=M[U]}f.push(p)}return f}function eu(e){return Object.values(e).filter(t=>t).length}function tu(e,t,r){return e+(r?"["+t+"]":(e.length?".":"")+t)}function $t(e,t,r,s,o){if(!ue(t))return t;for(const[d,f]of Object.entries(t)){const g=tu(r,d,s);Array.isArray(f)?o?$t(e,f,g,!0,o):e[g]=f.map(p=>$t(Array.isArray(p)?[]:{},p,"",!1,o)):ue(f)?$t(e,f,g,!1,o):e[g]=f}return e}function ru(e,t=!1,r){return $t({},e,r||"",!1,t)}function vs(e){if(!ue(e))return e;const t=Array.isArray(e)?[]:{};for(const[r,s]of Object.entries(e))Array.isArray(s)?ve(t,r,s.map(o=>vs(o))):ve(t,r,s);return t}function nu(e,t,r){return t[e]?t[e]:r}function ws(e,t){const r={};for(const s of e){const o=t(s);r[o]=s}return r}function su(e,t){const r={};for(const s of e){const o=t(s);r[o]||(r[o]=[]),r[o].push(s)}return r}function iu(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r}function bs(e,t){const r=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=r)s.push(e.slice(o,o+r));return s}function _s(e,t){const r=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)r.push(e.slice(o*t,o*t+t));return r}function au(e,t){const r=Math.ceil(e.length/t);return _s(e,r)}function ou(e,t){return Object.values(ws(e,t))}function cu(e,t,r,s,o){const d=t?e.map(t):e,f={};for(const p of d)f[p]=(f[p]||0)+1;const g=s?xs(f,o?(p,x)=>p[1]-x[1]:(p,x)=>x[1]-p[1]):f;return r?Object.keys(g):g}function xs(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function uu(e){const t=[],r=Object.keys(e),s=e[r[0]].length;for(let o=0;o<s;o++){const d={};for(const f of r)d[f]=e[f][o];t.push(d)}return t}function lu(e,t,r=1){for(const s of e)s[t]+=r}function du(e,t,r){for(const s of e)s[t]=r}function fr(e,t){const r=[];let s=[];return e.forEach((o,d)=>{(d===0||!t(o,e[d-1]))&&(s=[],r.push(s)),s.push(o)}),r}function fu(){return{map:new Map,keys:[]}}function hu(){return{map:new Map,keys:[]}}function ks(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function mu(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function pu(e,t,r,s,o=100){ks(e,t,{validUntil:Date.now()+s,data:r},o)}function gu(e,t){const r=e.map.get(t);return r&&r.validUntil>Date.now()?r.data:null}class fe{constructor(t){this.value=t}static of(t){return new fe(t)}static empty(){return new fe(null)}map(t){return new fe(this.value!==null&&this.value!==void 0?t(this.value):null)}mapAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(r=>fe.of(r)):Promise.resolve(fe.empty())}ifPresent(t){return this.value!==null&&this.value!==void 0&&t(this.value),this}ifPresentAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(t){return(this.value===null||this.value===void 0)&&t(),this}ifAbsentAsync(t){return this.value===null||this.value===void 0?t().then(()=>this):Promise.resolve(this)}getOrFallback(t){return this.value??t()}getOrFallbackAsync(t){return this.value!==null&&this.value!==void 0?Promise.resolve(this.value):t()}getOrThrow(){if(this.value===null||this.value===void 0)throw Error("Optional.value is empty");return this.value}}a.Optional=fe;class yu{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=yu;class vu{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=vu;function wu(e){return()=>e.forEach(t=>t())}function bu(e,t){return e.reduce((r,s)=>t(r)>t(s)?r:s)}function _u(e,t){const r=e.find(s=>s instanceof t);return fe.of(r)}function xu(e,t){return e.filter(r=>r instanceof t)}function ku(e,t){const r=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&r.push(e[o]),t[o]&&r.push(t[o]);return r}function Eu(e,t){return e.includes(t)?e.filter(r=>r!==t):[...e,t]}class Su{constructor(t){this.value=t,this.children=[]}}function Tu(e,t,r,s,o=!1){const d=new Map,f=[];e.forEach(p=>{const x=new Su(p);d.set(p[t],x)}),e.forEach(p=>{const x=d.get(p[t]);if(!x)return;const M=p[r];if(M){const U=d.get(M);U&&U.children.push(x)}else f.push(x)});const g=p=>{p.children.sort((x,M)=>{const U=x.value[s],Re=M.value[s];return o?Re-U:U-Re}),p.children.forEach(g)};return f.forEach(g),f}function Es(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let r=[...e];for(;r.length>1;){const s=[];for(let o=0;o<r.length;o+=2){const d=r[o+1];s.push(t(r[o],d))}r=s}return r[0]}function Me(...e){const t=e.reduce((o,d)=>o+d.length,0),r=new Uint8Array(t);let s=0;return e.forEach(o=>{r.set(o,s),s+=o.length}),r}function Ss(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function Ts(e){return e[0]===255&&e[1]===216}function As(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function Au(e){return Ss(e)||Ts(e)||As(e)}function Ou(e){return new Uint8Array([e])}function Iu(e){return e[0]}function $u(e,t){const r=new ArrayBuffer(2);return new DataView(r).setUint16(0,e,t==="LE"),new Uint8Array(r)}function Mu(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function Cu(e,t){const r=new ArrayBuffer(4);return new DataView(r).setUint32(0,e,t==="LE"),new Uint8Array(r)}function Nu(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function hr(e,t){const r=new ArrayBuffer(8);return new DataView(r).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(r)}function Ru(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function Ce(e,t){const r=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)r[o]=Number(s&0xffn),s>>=8n;return r}for(let o=31;o>=0;o--)r[o]=Number(s&0xffn),s>>=8n;return r}function Ne(e,t){let r=0n;if(t==="LE"){for(let s=31;s>=0;s--)r=r<<8n|BigInt(e[s]);return r}for(let s=0;s<32;s++)r=r<<8n|BigInt(e[s]);return r}function ju(e,t){const r=[];let s=0;for(const o of t)r.push(e.subarray(s,s+o)),s+=o;return r}function mr(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.subarray(s,s+t));return r}const Os=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function Du(e){for(let t=0;t<24;t++){const r=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],d=e[3]^e[13]^e[23]^e[33]^e[43],f=e[4]^e[14]^e[24]^e[34]^e[44],g=e[5]^e[15]^e[25]^e[35]^e[45],p=e[6]^e[16]^e[26]^e[36]^e[46],x=e[7]^e[17]^e[27]^e[37]^e[47],M=e[8]^e[18]^e[28]^e[38]^e[48],U=e[9]^e[19]^e[29]^e[39]^e[49],Re=o<<1|d>>>31,vl=d<<1|o>>>31,Ke=M^Re,Je=U^vl,wl=f<<1|g>>>31,bl=g<<1|f>>>31,Ye=r^wl,Qe=s^bl,_l=p<<1|x>>>31,xl=x<<1|p>>>31,Xe=o^_l,et=d^xl,kl=M<<1|U>>>31,El=U<<1|M>>>31,tt=f^kl,rt=g^El,Sl=r<<1|s>>>31,Tl=s<<1|r>>>31,nt=p^Sl,st=x^Tl;e[0]^=Ke,e[1]^=Je,e[2]^=Ye,e[3]^=Qe,e[4]^=Xe,e[5]^=et,e[6]^=tt,e[7]^=rt,e[8]^=nt,e[9]^=st,e[10]^=Ke,e[11]^=Je,e[12]^=Ye,e[13]^=Qe,e[14]^=Xe,e[15]^=et,e[16]^=tt,e[17]^=rt,e[18]^=nt,e[19]^=st,e[20]^=Ke,e[21]^=Je,e[22]^=Ye,e[23]^=Qe,e[24]^=Xe,e[25]^=et,e[26]^=tt,e[27]^=rt,e[28]^=nt,e[29]^=st,e[30]^=Ke,e[31]^=Je,e[32]^=Ye,e[33]^=Qe,e[34]^=Xe,e[35]^=et,e[36]^=tt,e[37]^=rt,e[38]^=nt,e[39]^=st,e[40]^=Ke,e[41]^=Je,e[42]^=Ye,e[43]^=Qe,e[44]^=Xe,e[45]^=et,e[46]^=tt,e[47]^=rt,e[48]^=nt,e[49]^=st;const br=e[0],_r=e[1],xr=e[2]<<1|e[3]>>>31,kr=e[3]<<1|e[2]>>>31,Er=e[5]<<30|e[4]>>>2,Sr=e[4]<<30|e[5]>>>2,Tr=e[6]<<28|e[7]>>>4,Ar=e[7]<<28|e[6]>>>4,Or=e[8]<<27|e[9]>>>5,Ir=e[9]<<27|e[8]>>>5,$r=e[11]<<4|e[10]>>>28,Mr=e[10]<<4|e[11]>>>28,Cr=e[13]<<12|e[12]>>>20,Nr=e[12]<<12|e[13]>>>20,Rr=e[14]<<6|e[15]>>>26,jr=e[15]<<6|e[14]>>>26,Dr=e[17]<<23|e[16]>>>9,Ur=e[16]<<23|e[17]>>>9,Pr=e[18]<<20|e[19]>>>12,Zr=e[19]<<20|e[18]>>>12,Br=e[20]<<3|e[21]>>>29,Lr=e[21]<<3|e[20]>>>29,zr=e[22]<<10|e[23]>>>22,Fr=e[23]<<10|e[22]>>>22,Vr=e[25]<<11|e[24]>>>21,Wr=e[24]<<11|e[25]>>>21,Hr=e[26]<<25|e[27]>>>7,qr=e[27]<<25|e[26]>>>7,Gr=e[29]<<7|e[28]>>>25,Kr=e[28]<<7|e[29]>>>25,Jr=e[31]<<9|e[30]>>>23,Yr=e[30]<<9|e[31]>>>23,Qr=e[33]<<13|e[32]>>>19,Xr=e[32]<<13|e[33]>>>19,en=e[34]<<15|e[35]>>>17,tn=e[35]<<15|e[34]>>>17,rn=e[36]<<21|e[37]>>>11,nn=e[37]<<21|e[36]>>>11,sn=e[38]<<8|e[39]>>>24,an=e[39]<<8|e[38]>>>24,on=e[40]<<18|e[41]>>>14,cn=e[41]<<18|e[40]>>>14,un=e[42]<<2|e[43]>>>30,ln=e[43]<<2|e[42]>>>30,dn=e[45]<<29|e[44]>>>3,fn=e[44]<<29|e[45]>>>3,hn=e[47]<<24|e[46]>>>8,mn=e[46]<<24|e[47]>>>8,pn=e[48]<<14|e[49]>>>18,gn=e[49]<<14|e[48]>>>18;e[0]=br^~Cr&Vr,e[1]=_r^~Nr&Wr,e[2]=Cr^~Vr&rn,e[3]=Nr^~Wr&nn,e[4]=Vr^~rn&pn,e[5]=Wr^~nn&gn,e[6]=rn^~pn&br,e[7]=nn^~gn&_r,e[8]=pn^~br&Cr,e[9]=gn^~_r&Nr,e[10]=Tr^~Pr&Br,e[11]=Ar^~Zr&Lr,e[12]=Pr^~Br&Qr,e[13]=Zr^~Lr&Xr,e[14]=Br^~Qr&dn,e[15]=Lr^~Xr&fn,e[16]=Qr^~dn&Tr,e[17]=Xr^~fn&Ar,e[18]=dn^~Tr&Pr,e[19]=fn^~Ar&Zr,e[20]=xr^~Rr&Hr,e[21]=kr^~jr&qr,e[22]=Rr^~Hr&sn,e[23]=jr^~qr&an,e[24]=Hr^~sn&on,e[25]=qr^~an&cn,e[26]=sn^~on&xr,e[27]=an^~cn&kr,e[28]=on^~xr&Rr,e[29]=cn^~kr&jr,e[30]=Or^~$r&zr,e[31]=Ir^~Mr&Fr,e[32]=$r^~zr&en,e[33]=Mr^~Fr&tn,e[34]=zr^~en&hn,e[35]=Fr^~tn&mn,e[36]=en^~hn&Or,e[37]=tn^~mn&Ir,e[38]=hn^~Or&$r,e[39]=mn^~Ir&Mr,e[40]=Er^~Dr&Gr,e[41]=Sr^~Ur&Kr,e[42]=Dr^~Gr&Jr,e[43]=Ur^~Kr&Yr,e[44]=Gr^~Jr&un,e[45]=Kr^~Yr&ln,e[46]=Jr^~un&Er,e[47]=Yr^~ln&Sr,e[48]=un^~Er&Dr,e[49]=ln^~Sr&Ur,e[0]^=Os[t*2],e[1]^=Os[t*2+1]}}function Is(e){const t=[];for(let r=0;r<e.length;r+=4)t.push(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24);return t}function $s(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[Is(o)]}const r=mr(e,136),s=r[r.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,r[r.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,r.push(o)}return r.map(Is)}function Ms(e,t){for(const r of t){for(let s=0;s<34;s+=2)e[s]^=r[s+1],e[s+1]^=r[s];Du(e)}return e}function Cs(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function se(e){return Cs(Ms(new Array(50).fill(0),$s(e,1)))}function Uu(e){return Cs(Ms(new Array(50).fill(0),$s(e,6)))}function Pu(e,t,r){const s=Math.min(e.length,t.length,r/8+1);for(let o=0;o<s;o++){const d=e[o]^t[o];for(let f=0;f<8;f++)if(d>>7-f&1)return o*8+f}return r}function Zu(e,t){const r=Math.min(e.length,t.length);for(let s=0;s<r;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,r)}function Bu(e,t,r,s){const o=Math.floor(t/8),d=t%8;r===1?e[o]|=1<<(s==="BE"?7-d:d):e[o]&=~(1<<(s==="BE"?7-d:d))}function Lu(e,t,r){const s=Math.floor(t/8),o=t%8;return e[s]>>(r==="BE"?7-o:o)&1}function zu(e,t,r=0){for(let s=r;s<e.length;s++)for(let o=0;o<t.length&&e[s+o]===t[o];o++)if(o===t.length-1)return s;return-1}function Ns(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,t-e.length),s}function Fu(e,t,r=0){const s=e.length%t;return s===0?e:Ns(e,e.length+t-s,r)}function Rs(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,0),s}function Vu(e,t,r=0){const s=e.length%t;return s===0?e:Rs(e,e.length+t-s,r)}function Wu(e,t){const r=new Uint8Array(e.length);for(let s=0;s<e.length;s++)r[s]=e[s]^t[s%t.length];return r}function Hu(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function C(e,t){return(e%t+t)%t}function qe(e,t){e=C(e,t);let[r,s]=[0n,1n],[o,d]=[t,e];for(;d!==0n;){const f=o/d;[r,s]=[s,r-f*s],[o,d]=[d,o-f*d]}if(o>1n)throw new Error("a is not invertible");return r<0n&&(r+=t),r}function qu(e,t,r){let s=1n;for(e=C(e,r);t>0;)t%2n===1n&&(s=C(s*e,r)),e=C(e*e,r),t=t/2n;return s}function js(e,t){return C(e,t)===0n?0n:t%4n===3n?qu(e,(t+1n)/4n,t):null}const Z=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,D=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Mt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Ct=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function pr(e,t,r){if(t===0n)return[0n,0n];const s=C(3n*e*e*qe(2n*t,r),r),o=C(s*s-2n*e,r),d=C(s*(e-o)-t,r);return[o,d]}function Nt(e,t,r,s,o){if(e===0n&&t===0n)return[r,s];if(r===0n&&s===0n)return[e,t];if(e===r&&t===C(-s,o))return[0n,0n];if(e===r&&t===s)return pr(e,t,o);const d=C((s-t)*qe(r-e,o),o),f=C(d*d-e-r,o),g=C(d*(e-f)-t,o);return[f,g]}function Gu(e){if(e<=0n||e>=D)throw new Error("Invalid private key");return xe(Mt,Ct,e,Z)}function Ku(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...Ce(e[0],"BE")])}function Ju(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Ne(e.slice(1),"BE"),r=js(C(t**3n+7n,Z),Z);if(!r)throw Error("Invalid x: does not correspond to a valid curve point");const s=C(-r,Z),o=r%2n===0n;return[t,e[0]===2?o?r:s:o?s:r]}function Yu(e){const t=new Uint8Array(20),r=se(Me(Ce(e[0],"BE"),Ce(e[1],"BE")));return t.set(r.subarray(12)),t}function Qu(e){const t=a.Binary.uint8ArrayToHex(e),r=a.Binary.uint8ArrayToHex(a.Binary.keccak256(new Uint8Array([...t].map(o=>o.charCodeAt(0)))));let s="0x";for(let o=0;o<t.length;o++)parseInt(r[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function xe(e,t,r,s){let o=[0n,0n],d=[e,t];const f=r.toString(2);for(const g of f)g==="0"?(d=Nt(o[0],o[1],d[0],d[1],s),o=pr(o[0],o[1],s)):(o=Nt(o[0],o[1],d[0],d[1],s),d=pr(d[0],d[1],s));return o}function Xu(e,t,r){return Ds(Ne(se(e),"BE"),t,r)}function Ds(e,t,r){if(t<=0n||t>=D)throw new Error("Invalid private key");if(r||(r=C(Ne(se(Me(se(Ce(t,"BE")),Ce(e,"BE"))),"BE"),D)),r<=0n||r>=D)throw new Error("Invalid nonce");const s=C(e,D),o=xe(Mt,Ct,r,Z),d=C(o[0],D);let f=C((s+C(d,D)*t)*qe(r,D),D);if(d===0n||f===0n)throw new Error("Invalid r or s value");let g=o[1]%2n===0n?27n:28n;return f>D/2n&&(f=D-f,g=g===27n?28n:27n),[d,f,g]}function el(e,t,r,s){const o=js(C(t**3n+7n,Z),Z);if(!o)throw new Error("Invalid r: does not correspond to a valid curve point");const d=s===27n?0n:1n,f=o%2n===d?o:Z-o,g=C(Ne(se(e),"BE"),D),p=xe(t,f,r,Z),x=xe(Mt,Ct,g,Z),M=Nt(p[0],p[1],x[0],C(-x[1],Z),Z);return xe(M[0],M[1],qe(t,D),Z)}function tl(e,t,r,s){const o=C(Ne(se(e),"BE"),D),d=qe(s,D),f=C(o*d,D),g=C(r*d,D),p=xe(Mt,Ct,f,Z),x=xe(t[0],t[1],g,Z),M=Nt(p[0],p[1],x[0],x[1],Z);return r===C(M[0],D)}class Us{constructor(t){this.cursor=0,this.buffer=t}read(t){const r=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=Us;class Ps{constructor(t){this.buffer=t,this.cursor=0}write(t){const r=Math.min(this.max(),t.max());return this.buffer.set(t.read(r),this.cursor),this.cursor+=r,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=Ps;class Rt{constructor(t,r=0n){this.span=r,this.writer=new Ps(new Uint8Array(t))}build(){return Me(hr(this.span,"LE"),this.writer.buffer)}hash(){const t=Es(mr(this.writer.buffer,32),(r,s)=>se(Me(r,s)));return se(Me(hr(this.span,"LE"),t))}}a.Chunk=Rt;class gr{constructor(t,r=4096){this.counters=[1],this.capacity=r,this.chunks=[new Rt(r)],this.onChunk=t}static async root(t,r=4096){const s=new n(n.NOOP,r);return await s.append(t),s.finalize()}async append(t,r=0,s=0n){const o=new Us(t);for(;o.max()>0;){this.chunks[r].writer.max()===0&&await this.elevate(r);const d=this.chunks[r].writer.write(o);s?this.chunks[r].span+=s:this.chunks[0].span+=BigInt(d)}}async elevate(t){this.counters[t]=++this.counters[t]%(this.capacity/32),this.chunks[t+1]||(this.chunks.push(new Rt(this.capacity)),this.counters.push(1)),await this.append(this.chunks[t].hash(),t+1,this.chunks[t].span),await this.onChunk(this.chunks[t]),this.chunks[t]=new Rt(this.capacity)}async finalize(t=0){return this.chunks[t+1]?this.counters[t]===1?(await this.elevate(t+1),this.chunks[t+1]=this.chunks[t],this.finalize(t+1)):(await this.elevate(t),this.finalize(t+1)):(await this.onChunk(this.chunks[t]),this.chunks[t])}}a.MerkleTree=gr,n=gr,gr.NOOP=async e=>{};class J{constructor(t,r){if(r<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=r}static fromDecimalString(t,r){let[s,o]=t.split(".");return o=(o||"").padEnd(r,"0").slice(0,r),new J(BigInt(s+o),r)}add(t){return this.assertSameScale(t),new J(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new J(this.value-t.value,this.scale)}multiply(t){return new J(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const r=this.value/t,s=this.value%t;return[new J(r,this.scale),new J(s,this.scale)]}exchange(t,r,s){if(t==="*"){const d=this.value*r.value/10n**BigInt(this.scale);return new J(d,s)}this.assertSameScale(r);const o=this.value*10n**BigInt(s)/r.value;return new J(o,s)}compare(t){return this.assertSameScale(t),this.value>t.value?1:this.value<t.value?-1:0}toDecimalString(){if(this.scale===0)return this.value.toString();const t=this.value.toString(),r=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${r}.${s}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(t){if(this.scale!==t.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${t.scale}`)}}a.FixedPointNumber=J;function rl(e){if(e.length===0)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}}function jt(e,t,r,s){const o=e.findIndex(g=>g===`--${t}`||g.startsWith(`--${t}=`)),d=e[o];if(!d)return(r||{})[s||t||""]||null;if(d.includes("="))return d.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(r||{})[s||t||""]||null}function nl(e,t,r,s){const o=jt(e,t,r,s);if(!o)return null;try{return lr(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function sl(e,t,r,s){const o=e.some(p=>p.endsWith("-"+t)),d=jt(e,t,r,s);if(!d&&o)return!0;if(!d&&!o)return null;const f=["true","1","yes","y","on"],g=["false","0","no","n","off"];if(f.includes(d.toLowerCase()))return!0;if(g.includes(d.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${d}`)}function Zs(e,t,r,s){const o=jt(e,t,r,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function il(e,t,r,s){const o=Zs(e,t,r,s);try{return lr(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function Bs(e,t){const r=e[t];e.splice(t,1),e.unshift(r)}function al(e,t){const r=[...e];return Bs(r,t),r}function Ls(e,t){return{x:e.x+t.x,y:e.y+t.y}}function ol(e,t){return{x:e.x-t.x,y:e.y-t.y}}function yr(e,t){return{x:e.x*t,y:e.y*t}}function cl(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function zs(e,t,r){return{x:e.x+Math.cos(t)*r,y:e.y+Math.sin(t)*r}}function Fs(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function Ge(e,t,r="row-first"){const s=[];if(r==="column-first")for(let o=0;o<e.length;o++)for(let d=0;d<e[0].length;d++)t(o,d)&&s.push({x:o,y:d});else for(let o=0;o<e[0].length;o++)for(let d=0;d<e.length;d++)t(d,o)&&s.push({x:d,y:o});return s}function ul(e,t,r){var s,o;return((s=e[t+1])==null?void 0:s[r])&&((o=e[t-1])==null?void 0:o[r])&&!e[t][r-1]&&!e[t][r+1]}function ll(e,t,r){var s,o;return e[t][r+1]&&e[t][r-1]&&!((s=e[t-1])!=null&&s[r])&&!((o=e[t+1])!=null&&o[r])}function Vs(e,t,r){var s;return!((s=e[t-1])!=null&&s[r])}function Ws(e,t,r){var s;return!((s=e[t+1])!=null&&s[r])}function Hs(e,t,r){return!e[t][r-1]}function qs(e,t,r){return!e[t][r+1]}function dl(e,t,r){var o,d,f,g,p,x,M,U;const s=[];return e[t][r]?ul(e,t,r)||ll(e,t,r)?[]:(!((o=e[t-1])!=null&&o[r-1])&&Vs(e,t,r)&&Hs(e,t,r)&&s.push({x:t,y:r}),!((d=e[t+1])!=null&&d[r-1])&&Ws(e,t,r)&&Hs(e,t,r)&&s.push({x:t+1,y:r}),!((f=e[t-1])!=null&&f[r+1])&&Vs(e,t,r)&&qs(e,t,r)&&s.push({x:t,y:r+1}),!((g=e[t+1])!=null&&g[r+1])&&Ws(e,t,r)&&qs(e,t,r)&&s.push({x:t+1,y:r+1}),s):((p=e[t-1])!=null&&p[r]&&e[t][r-1]&&s.push({x:t,y:r}),(x=e[t+1])!=null&&x[r]&&e[t][r-1]&&s.push({x:t+1,y:r}),(M=e[t-1])!=null&&M[r]&&e[t][r+1]&&s.push({x:t,y:r+1}),(U=e[t+1])!=null&&U[r]&&e[t][r+1]&&s.push({x:t+1,y:r+1}),s)}function fl(e,t,r,s){const o=[{x:0,y:0},{x:r,y:0},{x:0,y:s},{x:r,y:s}];for(let d=0;d<e.length;d++)for(let f=0;f<e[0].length;f++){const g=dl(e,d,f);for(const p of g)o.some(x=>x.x===p.x&&x.y===p.y)||o.push(p)}return o.map(d=>({x:d.x*t,y:d.y*t}))}function hl(e,t){const r=Ge(e,(p,x)=>e[p][x]===0&&e[p][x+1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),s=Ge(e,(p,x)=>e[p][x]===0&&e[p][x-1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),o=Ge(e,(p,x)=>{var M;return e[p][x]===0&&((M=e[p-1])==null?void 0:M[x])!==0},"column-first").map(p=>({...p,dx:0,dy:1})),d=Ge(e,(p,x)=>{var M;return e[p][x]===0&&((M=e[p+1])==null?void 0:M[x])!==0},"column-first").map(p=>({...p,dx:0,dy:1}));r.forEach(p=>p.y++),d.forEach(p=>p.x++);const f=fr([...o,...d],(p,x)=>p.x===x.x&&p.y-1===x.y),g=fr([...s,...r],(p,x)=>p.y===x.y&&p.x-1===x.x);return[...f,...g].map(p=>({start:p[0],end:Fe(p)})).map(p=>({start:yr(p.start,t),end:yr(Ls(p.end,{x:p.start.dx,y:p.start.dy}),t)}))}function ml(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function pl(e,t){return t.map(r=>ml(e,r)).sort((r,s)=>r-s)}function Gs(e,t,r,s){const o=(s.y-r.y)*(t.x-e.x)-(s.x-r.x)*(t.y-e.y);if(o===0)return null;let d=e.y-r.y,f=e.x-r.x;const g=(s.x-r.x)*d-(s.y-r.y)*f,p=(t.x-e.x)*d-(t.y-e.y)*f;return d=g/o,f=p/o,d>0&&d<1&&f>0&&f<1?{x:e.x+d*(t.x-e.x),y:e.y+d*(t.y-e.y)}:null}function vr(e,t,r){const s=[],o=zs(e,r,1e4);for(const d of t){const f=Gs(e,o,d.start,d.end);f&&s.push(f)}return s.length?s.reduce((d,f)=>{const g=Fs(e,f),p=Fs(e,d);return g<p?f:d}):null}function gl(e,t,r){const s=pl(e,r),o=[];for(const d of s){const f=vr(e,t,d-.001),g=vr(e,t,d+.001);f&&o.push(f),g&&o.push(g)}return o}class wr{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(r=>r!==t)}}publish(t){this.subscribers.forEach(r=>r(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=wr;class yl{constructor(t,r){this.queue=[],this.running=0,this.onProcessed=new wr,this.onDrained=new wr,this.concurrency=t,this.capacity=r}process(){if(this.running>=this.concurrency)return;const t=this.queue.shift();t&&(this.running++,t().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),this.running===0&&this.onDrained.publish()}))}enqueue(t){if(this.queue.length<this.capacity)return this.queue.push(t),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(r=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),r())})})}drain(){if(this.running===0)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(t=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),t()})})}}a.AsyncQueue=yl,a.Binary={hexToUint8Array:xo,uint8ArrayToHex:ko,base64ToUint8Array:vo,uint8ArrayToBase64:wo,base32ToUint8Array:bo,uint8ArrayToBase32:_o,log2Reduce:Es,partition:mr,concatBytes:Me,numberToUint8:Ou,uint8ToNumber:Iu,numberToUint16:$u,uint16ToNumber:Mu,numberToUint32:Cu,uint32ToNumber:Nu,numberToUint64:hr,uint64ToNumber:Ru,numberToUint256:Ce,uint256ToNumber:Ne,sliceBytes:ju,keccak256:se,sha3_256:Uu,proximity:Pu,commonPrefix:Zu,setBit:Bu,getBit:Lu,indexOf:zu,equals:Hu,padStart:Ns,padStartToMultiple:Fu,padEnd:Rs,padEndToMultiple:Vu,xorCypher:Wu},a.Elliptic={privateKeyToPublicKey:Gu,compressPublicKey:Ku,publicKeyFromCompressed:Ju,publicKeyToAddress:Yu,signMessage:Xu,signHash:Ds,verifySignature:tl,recoverPublicKey:el,checksumEncode:Qu},a.Random={intBetween:ze,floatBetween:An,chance:On,signed:pi,makeSeededRng:Wt,point:yi,procs:vi},a.Arrays={countUnique:cu,makeUnique:ou,splitBySize:iu,splitByCount:bs,index:ws,indexCollection:su,onlyOrThrow:m,onlyOrNull:w,firstOrThrow:E,firstOrNull:v,shuffle:h,initialize:j,initialize2D:ne,rotate2D:re,containsShape:Le,glue:Ta,pluck:Vt,pick:Ht,pickMany:wi,pickManyUnique:bi,pickWeighted:ki,pickRandomIndices:Ae,pickGuaranteed:_i,last:Fe,pipe:In,makePipe:xi,sortWeighted:Ei,pushAll:St,unshiftAll:Ea,filterAndRemove:Ho,merge:Lc,empty:zc,pushToBucket:_a,unshiftAndLimit:xa,atRolling:ka,group:fr,createOscillator:Oc,organiseWithLimits:$c,tickPlaybook:rl,getArgument:jt,getBooleanArgument:sl,getNumberArgument:nl,requireStringArgument:Zs,requireNumberArgument:il,bringToFront:al,bringToFrontInPlace:Bs,findInstance:_u,filterInstances:xu,interleave:ku,toggle:Eu,createHierarchy:Tu,multicall:wu,maxBy:bu},a.System={sleepMillis:l,forever:$i,scheduleMany:Na,waitFor:Wo,expandError:ya,runAndSetInterval:Mi},a.Numbers={make:lr,sum:ja,average:Da,median:Ua,getDistanceFromMidpoint:Pa,clamp:dr,range:zn,interpolate:Ra,createSequence:Ac,increment:Uc,decrement:Pc,format:Dc,fromDecimals:jc,makeStorage:yc,asMegabytes:Ci,convertBytes:Ni,hexToRgb:Ri,rgbToHex:ji,haversineDistanceToMeters:Di,roundToNearest:_t,formatDistance:Ui,triangularNumber:Pi,searchFloat:Zi},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:tc,getTimeDelta:ls,secondsToHumanTime:rc,countCycles:nc,isoDate:Ko,throttle:sc,timeSince:ac,dateTimeSlug:Jo,unixTimestamp:Go,fromUtcString:Yo,fromMillis:Qo,getProgress:oc,humanizeTime:It,humanizeProgress:Vo,createTimeDigits:K,mapDayNumber:ds,getDayInfoFromDate:cr,getDayInfoFromDateTimeString:uc,seconds:lc,minutes:dc,hours:fc,days:hc,make:pc,normalizeTime:Xo,absoluteDays:be},a.Objects={safeParse:Tc,deleteDeep:Ai,getDeep:ye,setDeep:ve,incrementDeep:Si,ensureDeep:Ti,replaceDeep:Oi,getFirstDeep:Ii,deepMergeInPlace:we,deepMerge2:va,deepMerge3:wa,mapAllAsync:Sa,cloneWithJson:qo,sortObject:hs,sortArray:ms,sortAny:_e,deepEquals:ps,deepEqualsEvery:Sc,runOn:Zc,ifPresent:Bc,zip:Ln,zipSum:ba,removeEmptyArrays:Fc,removeEmptyValues:Vc,flatten:ru,unflatten:vs,match:nu,sort:xs,map:qc,mapIterable:Gc,filterKeys:Wc,filterValues:Hc,rethrow:Kc,setSomeOnObject:Jc,setSomeDeep:Yc,flip:Qc,getAllPermutations:Xc,countTruthyValues:eu,transformToArray:uu,setMulti:du,incrementMulti:lu,createBidirectionalMap:fu,createTemporalBidirectionalMap:hu,pushToBidirectionalMap:ks,unshiftToBidirectionalMap:mu,addToTemporalBidirectionalMap:pu,getFromTemporalBidirectionalMap:gu,createStatefulToggle:Ic,diffKeys:Mc,pickRandomKey:gs,mapRandomKey:Cc,fromObjectString:Nc,toQueryString:cs,parseQueryString:Do,hasKey:Uo,selectMax:Po,reposition:Zo,unwrapSingleKey:Bo,parseKeyValues:Lo},a.Types={isFunction:Gt,isObject:ue,isStrictlyObject:Oe,isEmptyArray:$n,isEmptyObject:Bi,isUndefined:qt,isString:V,isNumber:le,isBoolean:Mn,isDate:Ie,isBlank:xt,isId:Kt,isIntegerString:Cn,isHexString:Nn,isUrl:Zn,isNullable:ha,asString:Un,asHexString:Xi,asSafeString:ea,asIntegerString:Qi,asNumber:kt,asFunction:ta,asInteger:Qt,asBoolean:ra,asDate:na,asNullableString:sa,asEmptiableString:ia,asId:aa,asTime:oa,asArray:ca,asObject:Et,asNullableObject:ua,asStringMap:la,asNumericDictionary:da,asUrl:fa,asNullable:ma,asOptional:pa,enforceObjectShape:Bn,enforceArrayShape:ga,isPng:Ss,isJpg:Ts,isWebp:As,isImage:Au},a.Strings={tokenizeByCount:au,tokenizeByLength:_s,searchHex:Ki,searchSubstring:Ji,randomHex:Yi,randomLetter:Wi,randomAlphanumeric:Hi,randomRichAscii:qi,randomUnicode:Gi,includesAny:Za,slugify:Xt,normalForm:La,enumify:qa,escapeHtml:Ka,decodeHtmlEntities:Ya,after:er,afterLast:Vn,before:Fn,beforeLast:tr,betweenWide:Qa,betweenNarrow:Xa,getPreLine:vc,containsWord:ar,containsWords:Co,joinUrl:fs,getFuzzyMatchScore:Tt,sortByFuzzyScore:Ga,splitOnce:rr,splitAll:Wn,randomize:no,expand:Hn,shrinkTrim:We,capitalize:At,decapitalize:qn,csvEscape:uo,parseCsv:Fo,surroundInOut:Ha,getExtension:nr,getBasename:sr,normalizeEmail:eo,normalizeFilename:to,parseFilename:ro,camelToTitle:za,slugToTitle:Fa,slugToCamel:Va,joinHumanly:Wa,findWeightedPair:Xn,extractBlock:es,extractAllBlocks:ho,replaceBlocks:mo,indexOfEarliest:$e,lastIndexOfBefore:Qn,parseHtmlAttributes:No,readNextWord:Ot,resolveVariables:Ro,resolveVariableWithDefaultSyntax:as,resolveRemainingVariablesWithDefaults:os,isLetter:Gn,isDigit:Kn,isLetterOrDigit:He,isValidObjectPathCharacter:ao,insert:oo,indexOfRegex:Jn,lineMatches:Yn,linesMatchInOrder:co,represent:Ve,resolveMarkdownLinks:jo,buildUrl:zo,isChinese:Ba,replaceBetweenStrings:_c,describeMarkdown:xc,isBalanced:kc,textToFormat:Ec,splitFormatting:po,splitHashtags:go,splitUrls:yo,route:Eo,explodeReplace:ir,generateVariants:So,replaceWord:To,replacePascalCaseWords:Ao,stripHtml:Oo,breakLine:is,measureTextWidth:Io,toLines:$o,levenshteinDistance:Mo},a.Assertions={asEqual:Aa,asTrue:Oa,asTruthy:Ia,asFalse:$a,asFalsy:Ma,asEither:Ca},a.Cache={get:wc,invalidate:bc},a.Vector={addPoint:Ls,subtractPoint:ol,multiplyPoint:yr,normalizePoint:cl,pushPoint:zs,filterCoordinates:Ge,findCorners:fl,findLines:hl,raycast:vr,raycastCircle:gl,getLineIntersectionPoint:Gs}})(ri);const N=Cl(ri);N.Arrays;N.Assertions;const B=N.Binary;N.Cache;N.Dates;N.Elliptic;N.Numbers;N.Objects;N.Pagination;N.Promises;N.Random;N.Strings;N.System;N.Types;N.Optional;N.Vector;N.PubSubChannel;N.Chunk;const Nl=N.MerkleTree;N.FixedPointNumber;N.Lazy;N.AsyncLazy;N.AsyncQueue;N.Uint8ArrayReader;N.Uint8ArrayWriter;const Rl=new TextEncoder,Js=1,Ys=4096,vn=4096,jl=32;function ni(a,n){return n=typeof n=="number"?A.FeedIndex.fromBigInt(BigInt(n)):n,new A.Identifier(B.keccak256(B.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Dl(a){const n=a.slice(0,A.Span.LENGTH),i=a.slice(A.Span.LENGTH),c=Ul(i),u=B.keccak256(B.concatBytes(n,c));return new A.Reference(u)}function Ul(a){if(a.length>vn)throw new A.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${vn}`,a);const n=new Uint8Array(vn);return n.set(a),B.log2Reduce(B.partition(n,jl),(i,c)=>B.keccak256(B.concatBytes(i,c)))}function Qs(a){if(a instanceof Uint8Array||(a=Rl.encode(a)),a.length<Js||a.length>Ys)throw new RangeError(`payload size ${a.length} exceeds limits [${Js}, ${Ys}]`);const n=A.Span.fromBigInt(BigInt(a.length)),i=B.concatBytes(n.toUint8Array(),a);return{data:i,span:n,payload:A.Bytes.fromSlice(i,A.Span.LENGTH),address:Dl(i)}}function Pl(a,n){return new A.Reference(B.keccak256(B.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Xs(a,n,i){n=new A.Identifier(n),i=new A.PrivateKey(i);const c=Pl(n,i.publicKey().address()),u=i.sign(B.concatBytes(n.toUint8Array(),a.address.toUint8Array())),l=B.concatBytes(n.toUint8Array(),u.toUint8Array(),a.data),h=A.Span.fromSlice(a.data,0),m=A.Bytes.fromSlice(a.data,A.Span.LENGTH);return{data:l,identifier:n,signature:u,span:h,payload:m,address:c,owner:i.publicKey().address()}}class Q{constructor(){}static getInstance(){return Q.instance||(Q.instance=new Q),Q.instance}formatMessage(n,...i){return`[${new Date().toISOString()}] [${n.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...n){console.log(this.formatMessage("log",...n))}info(...n){console.info(this.formatMessage("info",...n))}warn(...n){console.warn(this.formatMessage("warn",...n))}error(...n){console.error(this.formatMessage("error",...n))}debug(...n){console.debug(this.formatMessage("debug",...n))}}class oe{constructor(){this.logger=Q.getInstance()}static getInstance(){return oe.instance||(oe.instance=new oe),oe.instance}handleError(n,i){const c=n instanceof Error?n.message:"Unknown error occurred",u=n instanceof Error?n.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}const Zl=Q.getInstance(),Bl=oe.getInstance();function bn(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}async function _n(a,n=3,i=250){return new Promise((c,u)=>{a().then(c).catch(l=>{n>0?(Zl.info(`Retrying... Attempts left: ${n}. Error: ${l.message}`),setTimeout(()=>{_n(a,n-1,i).then(c).catch(u)},i)):(Bl.handleError(l,"Utils.retryAwaitableAsync"),u(l))})})}class Ll{constructor(){this.events={},this.on=this.on.bind(this),this.off=this.off.bind(this),this.cleanAll=this.cleanAll.bind(this),this.emit=this.emit.bind(this)}on(n,i){this.events[n]||(this.events[n]=[]),this.events[n].push(i)}off(n,i){if(!this.events[n])return;const c=this.events[n].indexOf(i);c>-1&&this.events[n].splice(c,1)}cleanAll(){this.events={}}emit(n,i){this.events[n]&&this.events[n].forEach(c=>c(i))}}var $;(function(a){a.assertEqual=u=>u;function n(u){}a.assertIs=n;function i(u){throw new Error}a.assertNever=i,a.arrayToEnum=u=>{const l={};for(const h of u)l[h]=h;return l},a.getValidEnumValues=u=>{const l=a.objectKeys(u).filter(m=>typeof u[u[m]]!="number"),h={};for(const m of l)h[m]=u[m];return a.objectValues(h)},a.objectValues=u=>a.objectKeys(u).map(function(l){return u[l]}),a.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const l=[];for(const h in u)Object.prototype.hasOwnProperty.call(u,h)&&l.push(h);return l},a.find=(u,l)=>{for(const h of u)if(l(h))return h},a.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&isFinite(u)&&Math.floor(u)===u;function c(u,l=" | "){return u.map(h=>typeof h=="string"?`'${h}'`:h).join(l)}a.joinValues=c,a.jsonStringifyReplacer=(u,l)=>typeof l=="bigint"?l.toString():l})($||($={}));var xn;(function(a){a.mergeShapes=(n,i)=>({...n,...i})})(xn||(xn={}));const _=$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ae=a=>{switch(typeof a){case"undefined":return _.undefined;case"string":return _.string;case"number":return isNaN(a)?_.nan:_.number;case"boolean":return _.boolean;case"function":return _.function;case"bigint":return _.bigint;case"symbol":return _.symbol;case"object":return Array.isArray(a)?_.array:a===null?_.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?_.promise:typeof Map<"u"&&a instanceof Map?_.map:typeof Set<"u"&&a instanceof Set?_.set:typeof Date<"u"&&a instanceof Date?_.date:_.object;default:return _.unknown}},y=$.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),zl=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class F extends Error{get errors(){return this.issues}constructor(n){super(),this.issues=[],this.addIssue=c=>{this.issues=[...this.issues,c]},this.addIssues=(c=[])=>{this.issues=[...this.issues,...c]};const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.name="ZodError",this.issues=n}format(n){const i=n||function(l){return l.message},c={_errors:[]},u=l=>{for(const h of l.issues)if(h.code==="invalid_union")h.unionErrors.map(u);else if(h.code==="invalid_return_type")u(h.returnTypeError);else if(h.code==="invalid_arguments")u(h.argumentsError);else if(h.path.length===0)c._errors.push(i(h));else{let m=c,w=0;for(;w<h.path.length;){const v=h.path[w];w===h.path.length-1?(m[v]=m[v]||{_errors:[]},m[v]._errors.push(i(h))):m[v]=m[v]||{_errors:[]},m=m[v],w++}}};return u(this),c}static assert(n){if(!(n instanceof F))throw new Error(`Not a ZodError: ${n}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,$.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(n=i=>i.message){const i={},c=[];for(const u of this.issues)u.path.length>0?(i[u.path[0]]=i[u.path[0]]||[],i[u.path[0]].push(n(u))):c.push(n(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}F.create=a=>new F(a);const Pe=(a,n)=>{let i;switch(a.code){case y.invalid_type:a.received===_.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case y.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,$.jsonStringifyReplacer)}`;break;case y.unrecognized_keys:i=`Unrecognized key(s) in object: ${$.joinValues(a.keys,", ")}`;break;case y.invalid_union:i="Invalid input";break;case y.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${$.joinValues(a.options)}`;break;case y.invalid_enum_value:i=`Invalid enum value. Expected ${$.joinValues(a.options)}, received '${a.received}'`;break;case y.invalid_arguments:i="Invalid function arguments";break;case y.invalid_return_type:i="Invalid function return type";break;case y.invalid_date:i="Invalid date";break;case y.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(i=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(i=`${i} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?i=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?i=`Invalid input: must end with "${a.validation.endsWith}"`:$.assertNever(a.validation):a.validation!=="regex"?i=`Invalid ${a.validation}`:i="Invalid";break;case y.too_small:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:i="Invalid input";break;case y.too_big:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?i=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:i="Invalid input";break;case y.custom:i="Invalid input";break;case y.invalid_intersection_types:i="Intersection results could not be merged";break;case y.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case y.not_finite:i="Number must be finite";break;default:i=n.defaultError,$.assertNever(a)}return{message:i}};let si=Pe;function Fl(a){si=a}function Dt(){return si}const Ut=a=>{const{data:n,path:i,errorMaps:c,issueData:u}=a,l=[...i,...u.path||[]],h={...u,path:l};if(u.message!==void 0)return{...u,path:l,message:u.message};let m="";const w=c.filter(v=>!!v).slice().reverse();for(const v of w)m=v(h,{data:n,defaultError:m}).message;return{...u,path:l,message:m}},Vl=[];function b(a,n){const i=Dt(),c=Ut({issueData:n,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Pe?void 0:Pe].filter(u=>!!u)});a.common.issues.push(c)}class L{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(n,i){const c=[];for(const u of i){if(u.status==="aborted")return T;u.status==="dirty"&&n.dirty(),c.push(u.value)}return{status:n.value,value:c}}static async mergeObjectAsync(n,i){const c=[];for(const u of i){const l=await u.key,h=await u.value;c.push({key:l,value:h})}return L.mergeObjectSync(n,c)}static mergeObjectSync(n,i){const c={};for(const u of i){const{key:l,value:h}=u;if(l.status==="aborted"||h.status==="aborted")return T;l.status==="dirty"&&n.dirty(),h.status==="dirty"&&n.dirty(),l.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[l.value]=h.value)}return{status:n.value,value:c}}}const T=Object.freeze({status:"aborted"}),De=a=>({status:"dirty",value:a}),z=a=>({status:"valid",value:a}),kn=a=>a.status==="aborted",En=a=>a.status==="dirty",Ee=a=>a.status==="valid",ot=a=>typeof Promise<"u"&&a instanceof Promise;function Pt(a,n,i,c){if(typeof n=="function"?a!==n||!c:!n.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n.get(a)}function ii(a,n,i,c,u){if(typeof n=="function"?a!==n||!u:!n.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n.set(a,i),i}var k;(function(a){a.errToObj=n=>typeof n=="string"?{message:n}:n||{},a.toString=n=>typeof n=="string"?n:n==null?void 0:n.message})(k||(k={}));var it,at;class ee{constructor(n,i,c,u){this._cachedPath=[],this.parent=n,this.data=i,this._path=c,this._key=u}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const ei=(a,n)=>{if(Ee(n))return{success:!0,data:n.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const i=new F(a.common.issues);return this._error=i,this._error}}};function O(a){if(!a)return{};const{errorMap:n,invalid_type_error:i,required_error:c,description:u}=a;if(n&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return n?{errorMap:n,description:u}:{errorMap:(h,m)=>{var w,v;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??m.defaultError}:typeof m.data>"u"?{message:(w=E??c)!==null&&w!==void 0?w:m.defaultError}:h.code!=="invalid_type"?{message:m.defaultError}:{message:(v=E??i)!==null&&v!==void 0?v:m.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(n){return ae(n.data)}_getOrReturnCtx(n,i){return i||{common:n.parent.common,data:n.data,parsedType:ae(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}_processInputParams(n){return{status:new L,ctx:{common:n.parent.common,data:n.data,parsedType:ae(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}}_parseSync(n){const i=this._parse(n);if(ot(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(n){const i=this._parse(n);return Promise.resolve(i)}parse(n,i){const c=this.safeParse(n,i);if(c.success)return c.data;throw c.error}safeParse(n,i){var c;const u={common:{issues:[],async:(c=i==null?void 0:i.async)!==null&&c!==void 0?c:!1,contextualErrorMap:i==null?void 0:i.errorMap},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)},l=this._parseSync({data:n,path:u.path,parent:u});return ei(u,l)}"~validate"(n){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)};if(!this["~standard"].async)try{const l=this._parseSync({data:n,path:[],parent:u});return Ee(l)?{value:l.value}:{issues:u.common.issues}}catch(l){!((c=(i=l==null?void 0:l.message)===null||i===void 0?void 0:i.toLowerCase())===null||c===void 0)&&c.includes("encountered")&&(this["~standard"].async=!0),u.common={issues:[],async:!0}}return this._parseAsync({data:n,path:[],parent:u}).then(l=>Ee(l)?{value:l.value}:{issues:u.common.issues})}async parseAsync(n,i){const c=await this.safeParseAsync(n,i);if(c.success)return c.data;throw c.error}async safeParseAsync(n,i){const c={common:{issues:[],contextualErrorMap:i==null?void 0:i.errorMap,async:!0},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:ae(n)},u=this._parse({data:n,path:c.path,parent:c}),l=await(ot(u)?u:Promise.resolve(u));return ei(c,l)}refine(n,i){const c=u=>typeof i=="string"||typeof i>"u"?{message:i}:typeof i=="function"?i(u):i;return this._refinement((u,l)=>{const h=n(u),m=()=>l.addIssue({code:y.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(w=>w?!0:(m(),!1)):h?!0:(m(),!1)})}refinement(n,i){return this._refinement((c,u)=>n(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(n){return new G({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:n}})}superRefine(n){return this._refinement(n)}constructor(n){this.spa=this.safeParseAsync,this._def=n,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:i=>this["~validate"](i)}}optional(){return X.create(this,this._def)}nullable(){return ge.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return q.create(this)}promise(){return Be.create(this,this._def)}or(n){return dt.create([this,n],this._def)}and(n){return ft.create(this,n,this._def)}transform(n){return new G({...O(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:n}})}default(n){const i=typeof n=="function"?n:()=>n;return new yt({...O(this._def),innerType:this,defaultValue:i,typeName:S.ZodDefault})}brand(){return new Tn({typeName:S.ZodBranded,type:this,...O(this._def)})}catch(n){const i=typeof n=="function"?n:()=>n;return new vt({...O(this._def),innerType:this,catchValue:i,typeName:S.ZodCatch})}describe(n){const i=this.constructor;return new i({...this._def,description:n})}pipe(n){return bt.create(this,n)}readonly(){return wt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Wl=/^c[^\s-]{8,}$/i,Hl=/^[0-9a-z]+$/,ql=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Gl=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Kl=/^[a-z0-9_-]{21}$/i,Jl=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Yl=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Ql=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Xl="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let wn;const ed=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,td=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,rd=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,nd=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,sd=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,id=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ai="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",ad=new RegExp(`^${ai}$`);function oi(a){let n="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?n=`${n}\\.\\d{${a.precision}}`:a.precision==null&&(n=`${n}(\\.\\d+)?`),n}function od(a){return new RegExp(`^${oi(a)}$`)}function ci(a){let n=`${ai}T${oi(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),n=`${n}(${i.join("|")})`,new RegExp(`^${n}$`)}function cd(a,n){return!!((n==="v4"||!n)&&ed.test(a)||(n==="v6"||!n)&&rd.test(a))}function ud(a,n){if(!Jl.test(a))return!1;try{const[i]=a.split("."),c=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(i.length+(4-i.length%4)%4,"="),u=JSON.parse(atob(c));return!(typeof u!="object"||u===null||!u.typ||!u.alg||n&&u.alg!==n)}catch{return!1}}function ld(a,n){return!!((n==="v4"||!n)&&td.test(a)||(n==="v6"||!n)&&nd.test(a))}class H extends I{_parse(n){if(this._def.coerce&&(n.data=String(n.data)),this._getType(n)!==_.string){const l=this._getOrReturnCtx(n);return b(l,{code:y.invalid_type,expected:_.string,received:l.parsedType}),T}const c=new L;let u;for(const l of this._def.checks)if(l.kind==="min")n.data.length<l.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="max")n.data.length>l.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="length"){const h=n.data.length>l.value,m=n.data.length<l.value;(h||m)&&(u=this._getOrReturnCtx(n,u),h?b(u,{code:y.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):m&&b(u,{code:y.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),c.dirty())}else if(l.kind==="email")Ql.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"email",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="emoji")wn||(wn=new RegExp(Xl,"u")),wn.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"emoji",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="uuid")Gl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"uuid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="nanoid")Kl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"nanoid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid")Wl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cuid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid2")Hl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cuid2",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="ulid")ql.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"ulid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="url")try{new URL(n.data)}catch{u=this._getOrReturnCtx(n,u),b(u,{validation:"url",code:y.invalid_string,message:l.message}),c.dirty()}else l.kind==="regex"?(l.regex.lastIndex=0,l.regex.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"regex",code:y.invalid_string,message:l.message}),c.dirty())):l.kind==="trim"?n.data=n.data.trim():l.kind==="includes"?n.data.includes(l.value,l.position)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),c.dirty()):l.kind==="toLowerCase"?n.data=n.data.toLowerCase():l.kind==="toUpperCase"?n.data=n.data.toUpperCase():l.kind==="startsWith"?n.data.startsWith(l.value)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{startsWith:l.value},message:l.message}),c.dirty()):l.kind==="endsWith"?n.data.endsWith(l.value)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:{endsWith:l.value},message:l.message}),c.dirty()):l.kind==="datetime"?ci(l).test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"datetime",message:l.message}),c.dirty()):l.kind==="date"?ad.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"date",message:l.message}),c.dirty()):l.kind==="time"?od(l).test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{code:y.invalid_string,validation:"time",message:l.message}),c.dirty()):l.kind==="duration"?Yl.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"duration",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="ip"?cd(n.data,l.version)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"ip",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="jwt"?ud(n.data,l.alg)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"jwt",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="cidr"?ld(n.data,l.version)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"cidr",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="base64"?sd.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"base64",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="base64url"?id.test(n.data)||(u=this._getOrReturnCtx(n,u),b(u,{validation:"base64url",code:y.invalid_string,message:l.message}),c.dirty()):$.assertNever(l);return{status:c.value,value:n.data}}_regex(n,i,c){return this.refinement(u=>n.test(u),{validation:i,code:y.invalid_string,...k.errToObj(c)})}_addCheck(n){return new H({...this._def,checks:[...this._def.checks,n]})}email(n){return this._addCheck({kind:"email",...k.errToObj(n)})}url(n){return this._addCheck({kind:"url",...k.errToObj(n)})}emoji(n){return this._addCheck({kind:"emoji",...k.errToObj(n)})}uuid(n){return this._addCheck({kind:"uuid",...k.errToObj(n)})}nanoid(n){return this._addCheck({kind:"nanoid",...k.errToObj(n)})}cuid(n){return this._addCheck({kind:"cuid",...k.errToObj(n)})}cuid2(n){return this._addCheck({kind:"cuid2",...k.errToObj(n)})}ulid(n){return this._addCheck({kind:"ulid",...k.errToObj(n)})}base64(n){return this._addCheck({kind:"base64",...k.errToObj(n)})}base64url(n){return this._addCheck({kind:"base64url",...k.errToObj(n)})}jwt(n){return this._addCheck({kind:"jwt",...k.errToObj(n)})}ip(n){return this._addCheck({kind:"ip",...k.errToObj(n)})}cidr(n){return this._addCheck({kind:"cidr",...k.errToObj(n)})}datetime(n){var i,c;return typeof n=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:n}):this._addCheck({kind:"datetime",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,offset:(i=n==null?void 0:n.offset)!==null&&i!==void 0?i:!1,local:(c=n==null?void 0:n.local)!==null&&c!==void 0?c:!1,...k.errToObj(n==null?void 0:n.message)})}date(n){return this._addCheck({kind:"date",message:n})}time(n){return typeof n=="string"?this._addCheck({kind:"time",precision:null,message:n}):this._addCheck({kind:"time",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,...k.errToObj(n==null?void 0:n.message)})}duration(n){return this._addCheck({kind:"duration",...k.errToObj(n)})}regex(n,i){return this._addCheck({kind:"regex",regex:n,...k.errToObj(i)})}includes(n,i){return this._addCheck({kind:"includes",value:n,position:i==null?void 0:i.position,...k.errToObj(i==null?void 0:i.message)})}startsWith(n,i){return this._addCheck({kind:"startsWith",value:n,...k.errToObj(i)})}endsWith(n,i){return this._addCheck({kind:"endsWith",value:n,...k.errToObj(i)})}min(n,i){return this._addCheck({kind:"min",value:n,...k.errToObj(i)})}max(n,i){return this._addCheck({kind:"max",value:n,...k.errToObj(i)})}length(n,i){return this._addCheck({kind:"length",value:n,...k.errToObj(i)})}nonempty(n){return this.min(1,k.errToObj(n))}trim(){return new H({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(n=>n.kind==="datetime")}get isDate(){return!!this._def.checks.find(n=>n.kind==="date")}get isTime(){return!!this._def.checks.find(n=>n.kind==="time")}get isDuration(){return!!this._def.checks.find(n=>n.kind==="duration")}get isEmail(){return!!this._def.checks.find(n=>n.kind==="email")}get isURL(){return!!this._def.checks.find(n=>n.kind==="url")}get isEmoji(){return!!this._def.checks.find(n=>n.kind==="emoji")}get isUUID(){return!!this._def.checks.find(n=>n.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(n=>n.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(n=>n.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(n=>n.kind==="cuid2")}get isULID(){return!!this._def.checks.find(n=>n.kind==="ulid")}get isIP(){return!!this._def.checks.find(n=>n.kind==="ip")}get isCIDR(){return!!this._def.checks.find(n=>n.kind==="cidr")}get isBase64(){return!!this._def.checks.find(n=>n.kind==="base64")}get isBase64url(){return!!this._def.checks.find(n=>n.kind==="base64url")}get minLength(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxLength(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}H.create=a=>{var n;return new H({checks:[],typeName:S.ZodString,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};function dd(a,n){const i=(a.toString().split(".")[1]||"").length,c=(n.toString().split(".")[1]||"").length,u=i>c?i:c,l=parseInt(a.toFixed(u).replace(".","")),h=parseInt(n.toFixed(u).replace(".",""));return l%h/Math.pow(10,u)}class he extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(n){if(this._def.coerce&&(n.data=Number(n.data)),this._getType(n)!==_.number){const l=this._getOrReturnCtx(n);return b(l,{code:y.invalid_type,expected:_.number,received:l.parsedType}),T}let c;const u=new L;for(const l of this._def.checks)l.kind==="int"?$.isInteger(n.data)||(c=this._getOrReturnCtx(n,c),b(c,{code:y.invalid_type,expected:"integer",received:"float",message:l.message}),u.dirty()):l.kind==="min"?(l.inclusive?n.data<l.value:n.data<=l.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_small,minimum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?n.data>l.value:n.data>=l.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_big,maximum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="multipleOf"?dd(n.data,l.value)!==0&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):l.kind==="finite"?Number.isFinite(n.data)||(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_finite,message:l.message}),u.dirty()):$.assertNever(l);return{status:u.value,value:n.data}}gte(n,i){return this.setLimit("min",n,!0,k.toString(i))}gt(n,i){return this.setLimit("min",n,!1,k.toString(i))}lte(n,i){return this.setLimit("max",n,!0,k.toString(i))}lt(n,i){return this.setLimit("max",n,!1,k.toString(i))}setLimit(n,i,c,u){return new he({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:k.toString(u)}]})}_addCheck(n){return new he({...this._def,checks:[...this._def.checks,n]})}int(n){return this._addCheck({kind:"int",message:k.toString(n)})}positive(n){return this._addCheck({kind:"min",value:0,inclusive:!1,message:k.toString(n)})}negative(n){return this._addCheck({kind:"max",value:0,inclusive:!1,message:k.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:0,inclusive:!0,message:k.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:0,inclusive:!0,message:k.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:k.toString(i)})}finite(n){return this._addCheck({kind:"finite",message:k.toString(n)})}safe(n){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:k.toString(n)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:k.toString(n)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}get isInt(){return!!this._def.checks.find(n=>n.kind==="int"||n.kind==="multipleOf"&&$.isInteger(n.value))}get isFinite(){let n=null,i=null;for(const c of this._def.checks){if(c.kind==="finite"||c.kind==="int"||c.kind==="multipleOf")return!0;c.kind==="min"?(i===null||c.value>i)&&(i=c.value):c.kind==="max"&&(n===null||c.value<n)&&(n=c.value)}return Number.isFinite(i)&&Number.isFinite(n)}}he.create=a=>new he({checks:[],typeName:S.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class me extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(n){if(this._def.coerce)try{n.data=BigInt(n.data)}catch{return this._getInvalidInput(n)}if(this._getType(n)!==_.bigint)return this._getInvalidInput(n);let c;const u=new L;for(const l of this._def.checks)l.kind==="min"?(l.inclusive?n.data<l.value:n.data<=l.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_small,type:"bigint",minimum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?n.data>l.value:n.data>=l.value)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.too_big,type:"bigint",maximum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="multipleOf"?n.data%l.value!==BigInt(0)&&(c=this._getOrReturnCtx(n,c),b(c,{code:y.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):$.assertNever(l);return{status:u.value,value:n.data}}_getInvalidInput(n){const i=this._getOrReturnCtx(n);return b(i,{code:y.invalid_type,expected:_.bigint,received:i.parsedType}),T}gte(n,i){return this.setLimit("min",n,!0,k.toString(i))}gt(n,i){return this.setLimit("min",n,!1,k.toString(i))}lte(n,i){return this.setLimit("max",n,!0,k.toString(i))}lt(n,i){return this.setLimit("max",n,!1,k.toString(i))}setLimit(n,i,c,u){return new me({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:k.toString(u)}]})}_addCheck(n){return new me({...this._def,checks:[...this._def.checks,n]})}positive(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:k.toString(n)})}negative(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:k.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:k.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:k.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:k.toString(i)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}me.create=a=>{var n;return new me({checks:[],typeName:S.ZodBigInt,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};class ct extends I{_parse(n){if(this._def.coerce&&(n.data=!!n.data),this._getType(n)!==_.boolean){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.boolean,received:c.parsedType}),T}return z(n.data)}}ct.create=a=>new ct({typeName:S.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class Se extends I{_parse(n){if(this._def.coerce&&(n.data=new Date(n.data)),this._getType(n)!==_.date){const l=this._getOrReturnCtx(n);return b(l,{code:y.invalid_type,expected:_.date,received:l.parsedType}),T}if(isNaN(n.data.getTime())){const l=this._getOrReturnCtx(n);return b(l,{code:y.invalid_date}),T}const c=new L;let u;for(const l of this._def.checks)l.kind==="min"?n.data.getTime()<l.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_small,message:l.message,inclusive:!0,exact:!1,minimum:l.value,type:"date"}),c.dirty()):l.kind==="max"?n.data.getTime()>l.value&&(u=this._getOrReturnCtx(n,u),b(u,{code:y.too_big,message:l.message,inclusive:!0,exact:!1,maximum:l.value,type:"date"}),c.dirty()):$.assertNever(l);return{status:c.value,value:new Date(n.data.getTime())}}_addCheck(n){return new Se({...this._def,checks:[...this._def.checks,n]})}min(n,i){return this._addCheck({kind:"min",value:n.getTime(),message:k.toString(i)})}max(n,i){return this._addCheck({kind:"max",value:n.getTime(),message:k.toString(i)})}get minDate(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n!=null?new Date(n):null}get maxDate(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n!=null?new Date(n):null}}Se.create=a=>new Se({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:S.ZodDate,...O(a)});class Zt extends I{_parse(n){if(this._getType(n)!==_.symbol){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.symbol,received:c.parsedType}),T}return z(n.data)}}Zt.create=a=>new Zt({typeName:S.ZodSymbol,...O(a)});class ut extends I{_parse(n){if(this._getType(n)!==_.undefined){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.undefined,received:c.parsedType}),T}return z(n.data)}}ut.create=a=>new ut({typeName:S.ZodUndefined,...O(a)});class lt extends I{_parse(n){if(this._getType(n)!==_.null){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.null,received:c.parsedType}),T}return z(n.data)}}lt.create=a=>new lt({typeName:S.ZodNull,...O(a)});class Ze extends I{constructor(){super(...arguments),this._any=!0}_parse(n){return z(n.data)}}Ze.create=a=>new Ze({typeName:S.ZodAny,...O(a)});class ke extends I{constructor(){super(...arguments),this._unknown=!0}_parse(n){return z(n.data)}}ke.create=a=>new ke({typeName:S.ZodUnknown,...O(a)});class ce extends I{_parse(n){const i=this._getOrReturnCtx(n);return b(i,{code:y.invalid_type,expected:_.never,received:i.parsedType}),T}}ce.create=a=>new ce({typeName:S.ZodNever,...O(a)});class Bt extends I{_parse(n){if(this._getType(n)!==_.undefined){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.void,received:c.parsedType}),T}return z(n.data)}}Bt.create=a=>new Bt({typeName:S.ZodVoid,...O(a)});class q extends I{_parse(n){const{ctx:i,status:c}=this._processInputParams(n),u=this._def;if(i.parsedType!==_.array)return b(i,{code:y.invalid_type,expected:_.array,received:i.parsedType}),T;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,m=i.data.length<u.exactLength.value;(h||m)&&(b(i,{code:h?y.too_big:y.too_small,minimum:m?u.exactLength.value:void 0,maximum:h?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),c.dirty())}if(u.minLength!==null&&i.data.length<u.minLength.value&&(b(i,{code:y.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),c.dirty()),u.maxLength!==null&&i.data.length>u.maxLength.value&&(b(i,{code:y.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),c.dirty()),i.common.async)return Promise.all([...i.data].map((h,m)=>u.type._parseAsync(new ee(i,h,i.path,m)))).then(h=>L.mergeArray(c,h));const l=[...i.data].map((h,m)=>u.type._parseSync(new ee(i,h,i.path,m)));return L.mergeArray(c,l)}get element(){return this._def.type}min(n,i){return new q({...this._def,minLength:{value:n,message:k.toString(i)}})}max(n,i){return new q({...this._def,maxLength:{value:n,message:k.toString(i)}})}length(n,i){return new q({...this._def,exactLength:{value:n,message:k.toString(i)}})}nonempty(n){return this.min(1,n)}}q.create=(a,n)=>new q({type:a,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...O(n)});function je(a){if(a instanceof R){const n={};for(const i in a.shape){const c=a.shape[i];n[i]=X.create(je(c))}return new R({...a._def,shape:()=>n})}else return a instanceof q?new q({...a._def,type:je(a.element)}):a instanceof X?X.create(je(a.unwrap())):a instanceof ge?ge.create(je(a.unwrap())):a instanceof te?te.create(a.items.map(n=>je(n))):a}class R extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const n=this._def.shape(),i=$.objectKeys(n);return this._cached={shape:n,keys:i}}_parse(n){if(this._getType(n)!==_.object){const v=this._getOrReturnCtx(n);return b(v,{code:y.invalid_type,expected:_.object,received:v.parsedType}),T}const{status:c,ctx:u}=this._processInputParams(n),{shape:l,keys:h}=this._getCached(),m=[];if(!(this._def.catchall instanceof ce&&this._def.unknownKeys==="strip"))for(const v in u.data)h.includes(v)||m.push(v);const w=[];for(const v of h){const E=l[v],j=u.data[v];w.push({key:{status:"valid",value:v},value:E._parse(new ee(u,j,u.path,v)),alwaysSet:v in u.data})}if(this._def.catchall instanceof ce){const v=this._def.unknownKeys;if(v==="passthrough")for(const E of m)w.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(v==="strict")m.length>0&&(b(u,{code:y.unrecognized_keys,keys:m}),c.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const v=this._def.catchall;for(const E of m){const j=u.data[E];w.push({key:{status:"valid",value:E},value:v._parse(new ee(u,j,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const v=[];for(const E of w){const j=await E.key,re=await E.value;v.push({key:j,value:re,alwaysSet:E.alwaysSet})}return v}).then(v=>L.mergeObjectSync(c,v)):L.mergeObjectSync(c,w)}get shape(){return this._def.shape()}strict(n){return k.errToObj,new R({...this._def,unknownKeys:"strict",...n!==void 0?{errorMap:(i,c)=>{var u,l,h,m;const w=(h=(l=(u=this._def).errorMap)===null||l===void 0?void 0:l.call(u,i,c).message)!==null&&h!==void 0?h:c.defaultError;return i.code==="unrecognized_keys"?{message:(m=k.errToObj(n).message)!==null&&m!==void 0?m:w}:{message:w}}}:{}})}strip(){return new R({...this._def,unknownKeys:"strip"})}passthrough(){return new R({...this._def,unknownKeys:"passthrough"})}extend(n){return new R({...this._def,shape:()=>({...this._def.shape(),...n})})}merge(n){return new R({unknownKeys:n._def.unknownKeys,catchall:n._def.catchall,shape:()=>({...this._def.shape(),...n._def.shape()}),typeName:S.ZodObject})}setKey(n,i){return this.augment({[n]:i})}catchall(n){return new R({...this._def,catchall:n})}pick(n){const i={};return $.objectKeys(n).forEach(c=>{n[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}omit(n){const i={};return $.objectKeys(this.shape).forEach(c=>{n[c]||(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}deepPartial(){return je(this)}partial(n){const i={};return $.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];n&&!n[c]?i[c]=u:i[c]=u.optional()}),new R({...this._def,shape:()=>i})}required(n){const i={};return $.objectKeys(this.shape).forEach(c=>{if(n&&!n[c])i[c]=this.shape[c];else{let l=this.shape[c];for(;l instanceof X;)l=l._def.innerType;i[c]=l}}),new R({...this._def,shape:()=>i})}keyof(){return ui($.objectKeys(this.shape))}}R.create=(a,n)=>new R({shape:()=>a,unknownKeys:"strip",catchall:ce.create(),typeName:S.ZodObject,...O(n)});R.strictCreate=(a,n)=>new R({shape:()=>a,unknownKeys:"strict",catchall:ce.create(),typeName:S.ZodObject,...O(n)});R.lazycreate=(a,n)=>new R({shape:a,unknownKeys:"strip",catchall:ce.create(),typeName:S.ZodObject,...O(n)});class dt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=this._def.options;function u(l){for(const m of l)if(m.result.status==="valid")return m.result;for(const m of l)if(m.result.status==="dirty")return i.common.issues.push(...m.ctx.common.issues),m.result;const h=l.map(m=>new F(m.ctx.common.issues));return b(i,{code:y.invalid_union,unionErrors:h}),T}if(i.common.async)return Promise.all(c.map(async l=>{const h={...i,common:{...i.common,issues:[]},parent:null};return{result:await l._parseAsync({data:i.data,path:i.path,parent:h}),ctx:h}})).then(u);{let l;const h=[];for(const w of c){const v={...i,common:{...i.common,issues:[]},parent:null},E=w._parseSync({data:i.data,path:i.path,parent:v});if(E.status==="valid")return E;E.status==="dirty"&&!l&&(l={result:E,ctx:v}),v.common.issues.length&&h.push(v.common.issues)}if(l)return i.common.issues.push(...l.ctx.common.issues),l.result;const m=h.map(w=>new F(w));return b(i,{code:y.invalid_union,unionErrors:m}),T}}get options(){return this._def.options}}dt.create=(a,n)=>new dt({options:a,typeName:S.ZodUnion,...O(n)});const ie=a=>a instanceof mt?ie(a.schema):a instanceof G?ie(a.innerType()):a instanceof pt?[a.value]:a instanceof pe?a.options:a instanceof gt?$.objectValues(a.enum):a instanceof yt?ie(a._def.innerType):a instanceof ut?[void 0]:a instanceof lt?[null]:a instanceof X?[void 0,...ie(a.unwrap())]:a instanceof ge?[null,...ie(a.unwrap())]:a instanceof Tn||a instanceof wt?ie(a.unwrap()):a instanceof vt?ie(a._def.innerType):[];class Ft extends I{_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.object)return b(i,{code:y.invalid_type,expected:_.object,received:i.parsedType}),T;const c=this.discriminator,u=i.data[c],l=this.optionsMap.get(u);return l?i.common.async?l._parseAsync({data:i.data,path:i.path,parent:i}):l._parseSync({data:i.data,path:i.path,parent:i}):(b(i,{code:y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[c]}),T)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(n,i,c){const u=new Map;for(const l of i){const h=ie(l.shape[n]);if(!h.length)throw new Error(`A discriminator value for key \`${n}\` could not be extracted from all schema options`);for(const m of h){if(u.has(m))throw new Error(`Discriminator property ${String(n)} has duplicate value ${String(m)}`);u.set(m,l)}}return new Ft({typeName:S.ZodDiscriminatedUnion,discriminator:n,options:i,optionsMap:u,...O(c)})}}function Sn(a,n){const i=ae(a),c=ae(n);if(a===n)return{valid:!0,data:a};if(i===_.object&&c===_.object){const u=$.objectKeys(n),l=$.objectKeys(a).filter(m=>u.indexOf(m)!==-1),h={...a,...n};for(const m of l){const w=Sn(a[m],n[m]);if(!w.valid)return{valid:!1};h[m]=w.data}return{valid:!0,data:h}}else if(i===_.array&&c===_.array){if(a.length!==n.length)return{valid:!1};const u=[];for(let l=0;l<a.length;l++){const h=a[l],m=n[l],w=Sn(h,m);if(!w.valid)return{valid:!1};u.push(w.data)}return{valid:!0,data:u}}else return i===_.date&&c===_.date&&+a==+n?{valid:!0,data:a}:{valid:!1}}class ft extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=(l,h)=>{if(kn(l)||kn(h))return T;const m=Sn(l.value,h.value);return m.valid?((En(l)||En(h))&&i.dirty(),{status:i.value,value:m.data}):(b(c,{code:y.invalid_intersection_types}),T)};return c.common.async?Promise.all([this._def.left._parseAsync({data:c.data,path:c.path,parent:c}),this._def.right._parseAsync({data:c.data,path:c.path,parent:c})]).then(([l,h])=>u(l,h)):u(this._def.left._parseSync({data:c.data,path:c.path,parent:c}),this._def.right._parseSync({data:c.data,path:c.path,parent:c}))}}ft.create=(a,n,i)=>new ft({left:a,right:n,typeName:S.ZodIntersection,...O(i)});class te extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.array)return b(c,{code:y.invalid_type,expected:_.array,received:c.parsedType}),T;if(c.data.length<this._def.items.length)return b(c,{code:y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&c.data.length>this._def.items.length&&(b(c,{code:y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const l=[...c.data].map((h,m)=>{const w=this._def.items[m]||this._def.rest;return w?w._parse(new ee(c,h,c.path,m)):null}).filter(h=>!!h);return c.common.async?Promise.all(l).then(h=>L.mergeArray(i,h)):L.mergeArray(i,l)}get items(){return this._def.items}rest(n){return new te({...this._def,rest:n})}}te.create=(a,n)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new te({items:a,typeName:S.ZodTuple,rest:null,...O(n)})};class ht extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.object)return b(c,{code:y.invalid_type,expected:_.object,received:c.parsedType}),T;const u=[],l=this._def.keyType,h=this._def.valueType;for(const m in c.data)u.push({key:l._parse(new ee(c,m,c.path,m)),value:h._parse(new ee(c,c.data[m],c.path,m)),alwaysSet:m in c.data});return c.common.async?L.mergeObjectAsync(i,u):L.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(n,i,c){return i instanceof I?new ht({keyType:n,valueType:i,typeName:S.ZodRecord,...O(c)}):new ht({keyType:H.create(),valueType:n,typeName:S.ZodRecord,...O(i)})}}class Lt extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.map)return b(c,{code:y.invalid_type,expected:_.map,received:c.parsedType}),T;const u=this._def.keyType,l=this._def.valueType,h=[...c.data.entries()].map(([m,w],v)=>({key:u._parse(new ee(c,m,c.path,[v,"key"])),value:l._parse(new ee(c,w,c.path,[v,"value"]))}));if(c.common.async){const m=new Map;return Promise.resolve().then(async()=>{for(const w of h){const v=await w.key,E=await w.value;if(v.status==="aborted"||E.status==="aborted")return T;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}})}else{const m=new Map;for(const w of h){const v=w.key,E=w.value;if(v.status==="aborted"||E.status==="aborted")return T;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}}}}Lt.create=(a,n,i)=>new Lt({valueType:n,keyType:a,typeName:S.ZodMap,...O(i)});class Te extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==_.set)return b(c,{code:y.invalid_type,expected:_.set,received:c.parsedType}),T;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(b(c,{code:y.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),i.dirty()),u.maxSize!==null&&c.data.size>u.maxSize.value&&(b(c,{code:y.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),i.dirty());const l=this._def.valueType;function h(w){const v=new Set;for(const E of w){if(E.status==="aborted")return T;E.status==="dirty"&&i.dirty(),v.add(E.value)}return{status:i.value,value:v}}const m=[...c.data.values()].map((w,v)=>l._parse(new ee(c,w,c.path,v)));return c.common.async?Promise.all(m).then(w=>h(w)):h(m)}min(n,i){return new Te({...this._def,minSize:{value:n,message:k.toString(i)}})}max(n,i){return new Te({...this._def,maxSize:{value:n,message:k.toString(i)}})}size(n,i){return this.min(n,i).max(n,i)}nonempty(n){return this.min(1,n)}}Te.create=(a,n)=>new Te({valueType:a,minSize:null,maxSize:null,typeName:S.ZodSet,...O(n)});class Ue extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.function)return b(i,{code:y.invalid_type,expected:_.function,received:i.parsedType}),T;function c(m,w){return Ut({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,Dt(),Pe].filter(v=>!!v),issueData:{code:y.invalid_arguments,argumentsError:w}})}function u(m,w){return Ut({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,Dt(),Pe].filter(v=>!!v),issueData:{code:y.invalid_return_type,returnTypeError:w}})}const l={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Be){const m=this;return z(async function(...w){const v=new F([]),E=await m._def.args.parseAsync(w,l).catch(ne=>{throw v.addIssue(c(w,ne)),v}),j=await Reflect.apply(h,this,E);return await m._def.returns._def.type.parseAsync(j,l).catch(ne=>{throw v.addIssue(u(j,ne)),v})})}else{const m=this;return z(function(...w){const v=m._def.args.safeParse(w,l);if(!v.success)throw new F([c(w,v.error)]);const E=Reflect.apply(h,this,v.data),j=m._def.returns.safeParse(E,l);if(!j.success)throw new F([u(E,j.error)]);return j.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...n){return new Ue({...this._def,args:te.create(n).rest(ke.create())})}returns(n){return new Ue({...this._def,returns:n})}implement(n){return this.parse(n)}strictImplement(n){return this.parse(n)}static create(n,i,c){return new Ue({args:n||te.create([]).rest(ke.create()),returns:i||ke.create(),typeName:S.ZodFunction,...O(c)})}}class mt extends I{get schema(){return this._def.getter()}_parse(n){const{ctx:i}=this._processInputParams(n);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}mt.create=(a,n)=>new mt({getter:a,typeName:S.ZodLazy,...O(n)});class pt extends I{_parse(n){if(n.data!==this._def.value){const i=this._getOrReturnCtx(n);return b(i,{received:i.data,code:y.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:n.data}}get value(){return this._def.value}}pt.create=(a,n)=>new pt({value:a,typeName:S.ZodLiteral,...O(n)});function ui(a,n){return new pe({values:a,typeName:S.ZodEnum,...O(n)})}class pe extends I{constructor(){super(...arguments),it.set(this,void 0)}_parse(n){if(typeof n.data!="string"){const i=this._getOrReturnCtx(n),c=this._def.values;return b(i,{expected:$.joinValues(c),received:i.parsedType,code:y.invalid_type}),T}if(Pt(this,it)||ii(this,it,new Set(this._def.values)),!Pt(this,it).has(n.data)){const i=this._getOrReturnCtx(n),c=this._def.values;return b(i,{received:i.data,code:y.invalid_enum_value,options:c}),T}return z(n.data)}get options(){return this._def.values}get enum(){const n={};for(const i of this._def.values)n[i]=i;return n}get Values(){const n={};for(const i of this._def.values)n[i]=i;return n}get Enum(){const n={};for(const i of this._def.values)n[i]=i;return n}extract(n,i=this._def){return pe.create(n,{...this._def,...i})}exclude(n,i=this._def){return pe.create(this.options.filter(c=>!n.includes(c)),{...this._def,...i})}}it=new WeakMap;pe.create=ui;class gt extends I{constructor(){super(...arguments),at.set(this,void 0)}_parse(n){const i=$.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(n);if(c.parsedType!==_.string&&c.parsedType!==_.number){const u=$.objectValues(i);return b(c,{expected:$.joinValues(u),received:c.parsedType,code:y.invalid_type}),T}if(Pt(this,at)||ii(this,at,new Set($.getValidEnumValues(this._def.values))),!Pt(this,at).has(n.data)){const u=$.objectValues(i);return b(c,{received:c.data,code:y.invalid_enum_value,options:u}),T}return z(n.data)}get enum(){return this._def.values}}at=new WeakMap;gt.create=(a,n)=>new gt({values:a,typeName:S.ZodNativeEnum,...O(n)});class Be extends I{unwrap(){return this._def.type}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==_.promise&&i.common.async===!1)return b(i,{code:y.invalid_type,expected:_.promise,received:i.parsedType}),T;const c=i.parsedType===_.promise?i.data:Promise.resolve(i.data);return z(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Be.create=(a,n)=>new Be({type:a,typeName:S.ZodPromise,...O(n)});class G extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=this._def.effect||null,l={addIssue:h=>{b(c,h),h.fatal?i.abort():i.dirty()},get path(){return c.path}};if(l.addIssue=l.addIssue.bind(l),u.type==="preprocess"){const h=u.transform(c.data,l);if(c.common.async)return Promise.resolve(h).then(async m=>{if(i.value==="aborted")return T;const w=await this._def.schema._parseAsync({data:m,path:c.path,parent:c});return w.status==="aborted"?T:w.status==="dirty"||i.value==="dirty"?De(w.value):w});{if(i.value==="aborted")return T;const m=this._def.schema._parseSync({data:h,path:c.path,parent:c});return m.status==="aborted"?T:m.status==="dirty"||i.value==="dirty"?De(m.value):m}}if(u.type==="refinement"){const h=m=>{const w=u.refinement(m,l);if(c.common.async)return Promise.resolve(w);if(w instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return m};if(c.common.async===!1){const m=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return m.status==="aborted"?T:(m.status==="dirty"&&i.dirty(),h(m.value),{status:i.value,value:m.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(m=>m.status==="aborted"?T:(m.status==="dirty"&&i.dirty(),h(m.value).then(()=>({status:i.value,value:m.value}))))}if(u.type==="transform")if(c.common.async===!1){const h=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});if(!Ee(h))return h;const m=u.transform(h.value,l);if(m instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:m}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>Ee(h)?Promise.resolve(u.transform(h.value,l)).then(m=>({status:i.value,value:m})):h);$.assertNever(u)}}G.create=(a,n,i)=>new G({schema:a,typeName:S.ZodEffects,effect:n,...O(i)});G.createWithPreprocess=(a,n,i)=>new G({schema:n,effect:{type:"preprocess",transform:a},typeName:S.ZodEffects,...O(i)});class X extends I{_parse(n){return this._getType(n)===_.undefined?z(void 0):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}X.create=(a,n)=>new X({innerType:a,typeName:S.ZodOptional,...O(n)});class ge extends I{_parse(n){return this._getType(n)===_.null?z(null):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}ge.create=(a,n)=>new ge({innerType:a,typeName:S.ZodNullable,...O(n)});class yt extends I{_parse(n){const{ctx:i}=this._processInputParams(n);let c=i.data;return i.parsedType===_.undefined&&(c=this._def.defaultValue()),this._def.innerType._parse({data:c,path:i.path,parent:i})}removeDefault(){return this._def.innerType}}yt.create=(a,n)=>new yt({innerType:a,typeName:S.ZodDefault,defaultValue:typeof n.default=="function"?n.default:()=>n.default,...O(n)});class vt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return ot(u)?u.then(l=>({status:"valid",value:l.status==="valid"?l.value:this._def.catchValue({get error(){return new F(c.common.issues)},input:c.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new F(c.common.issues)},input:c.data})}}removeCatch(){return this._def.innerType}}vt.create=(a,n)=>new vt({innerType:a,typeName:S.ZodCatch,catchValue:typeof n.catch=="function"?n.catch:()=>n.catch,...O(n)});class zt extends I{_parse(n){if(this._getType(n)!==_.nan){const c=this._getOrReturnCtx(n);return b(c,{code:y.invalid_type,expected:_.nan,received:c.parsedType}),T}return{status:"valid",value:n.data}}}zt.create=a=>new zt({typeName:S.ZodNaN,...O(a)});const fd=Symbol("zod_brand");class Tn extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class bt extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.common.async)return(async()=>{const l=await this._def.in._parseAsync({data:c.data,path:c.path,parent:c});return l.status==="aborted"?T:l.status==="dirty"?(i.dirty(),De(l.value)):this._def.out._parseAsync({data:l.value,path:c.path,parent:c})})();{const u=this._def.in._parseSync({data:c.data,path:c.path,parent:c});return u.status==="aborted"?T:u.status==="dirty"?(i.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:c.path,parent:c})}}static create(n,i){return new bt({in:n,out:i,typeName:S.ZodPipeline})}}class wt extends I{_parse(n){const i=this._def.innerType._parse(n),c=u=>(Ee(u)&&(u.value=Object.freeze(u.value)),u);return ot(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}wt.create=(a,n)=>new wt({innerType:a,typeName:S.ZodReadonly,...O(n)});function li(a,n={},i){return a?Ze.create().superRefine((c,u)=>{var l,h;if(!a(c)){const m=typeof n=="function"?n(c):typeof n=="string"?{message:n}:n,w=(h=(l=m.fatal)!==null&&l!==void 0?l:i)!==null&&h!==void 0?h:!0,v=typeof m=="string"?{message:m}:m;u.addIssue({code:"custom",...v,fatal:w})}}):Ze.create()}const hd={object:R.lazycreate};var S;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(S||(S={}));const md=(a,n={message:`Input not instance of ${a.name}`})=>li(i=>i instanceof a,n),di=H.create,fi=he.create,pd=zt.create,gd=me.create,hi=ct.create,yd=Se.create,vd=Zt.create,wd=ut.create,bd=lt.create,_d=Ze.create,xd=ke.create,kd=ce.create,Ed=Bt.create,Sd=q.create,Td=R.create,Ad=R.strictCreate,Od=dt.create,Id=Ft.create,$d=ft.create,Md=te.create,Cd=ht.create,Nd=Lt.create,Rd=Te.create,jd=Ue.create,Dd=mt.create,Ud=pt.create,Pd=pe.create,Zd=gt.create,Bd=Be.create,ti=G.create,Ld=X.create,zd=ge.create,Fd=G.createWithPreprocess,Vd=bt.create,Wd=()=>di().optional(),Hd=()=>fi().optional(),qd=()=>hi().optional(),Gd={string:a=>H.create({...a,coerce:!0}),number:a=>he.create({...a,coerce:!0}),boolean:a=>ct.create({...a,coerce:!0}),bigint:a=>me.create({...a,coerce:!0}),date:a=>Se.create({...a,coerce:!0})},Kd=T;var Y=Object.freeze({__proto__:null,defaultErrorMap:Pe,setErrorMap:Fl,getErrorMap:Dt,makeIssue:Ut,EMPTY_PATH:Vl,addIssueToContext:b,ParseStatus:L,INVALID:T,DIRTY:De,OK:z,isAborted:kn,isDirty:En,isValid:Ee,isAsync:ot,get util(){return $},get objectUtil(){return xn},ZodParsedType:_,getParsedType:ae,ZodType:I,datetimeRegex:ci,ZodString:H,ZodNumber:he,ZodBigInt:me,ZodBoolean:ct,ZodDate:Se,ZodSymbol:Zt,ZodUndefined:ut,ZodNull:lt,ZodAny:Ze,ZodUnknown:ke,ZodNever:ce,ZodVoid:Bt,ZodArray:q,ZodObject:R,ZodUnion:dt,ZodDiscriminatedUnion:Ft,ZodIntersection:ft,ZodTuple:te,ZodRecord:ht,ZodMap:Lt,ZodSet:Te,ZodFunction:Ue,ZodLazy:mt,ZodLiteral:pt,ZodEnum:pe,ZodNativeEnum:gt,ZodPromise:Be,ZodEffects:G,ZodTransformer:G,ZodOptional:X,ZodNullable:ge,ZodDefault:yt,ZodCatch:vt,ZodNaN:zt,BRAND:fd,ZodBranded:Tn,ZodPipeline:bt,ZodReadonly:wt,custom:li,Schema:I,ZodSchema:I,late:hd,get ZodFirstPartyTypeKind(){return S},coerce:Gd,any:_d,array:Sd,bigint:gd,boolean:hi,date:yd,discriminatedUnion:Id,effect:ti,enum:Pd,function:jd,instanceof:md,intersection:$d,lazy:Dd,literal:Ud,map:Nd,nan:pd,nativeEnum:Zd,never:kd,null:bd,nullable:zd,number:fi,object:Td,oboolean:qd,onumber:Hd,optional:Ld,ostring:Wd,pipeline:Vd,preprocess:Fd,promise:Bd,record:Cd,set:Rd,strictObject:Ad,string:di,symbol:vd,transformer:ti,tuple:Md,undefined:wd,union:Od,unknown:xd,void:Ed,NEVER:Kd,ZodIssueCode:y,quotelessJson:zl,ZodError:F});const mi=Q.getInstance(),Jd=Y.object({id:Y.string(),message:Y.string(),username:Y.string(),address:Y.string(),timestamp:Y.number(),signature:Y.string(),index:Y.number(),chatTopic:Y.string(),userTopic:Y.string()});function Yd(a){const n=Jd.safeParse(a);return n.success?Qd(a)?!0:(console.warn("Invalid messageSender"),!1):(mi.warn(n.error.format()),!1)}function Qd(a){try{const n={username:a.username,address:a.address,timestamp:a.timestamp},i=new TextEncoder,c=B.concatBytes(i.encode(`Ethereum Signed Message:
11
+ 32`),B.keccak256(i.encode(JSON.stringify(n))));if(new A.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(n){return mi.warn("Error in validateUserSignature",n),!1}}const W={LOADING_INIT:"loadingInit",LOADING_PREVIOUS_MESSAGES:"loadingPreviousMessages",MESSAGE_RECEIVED:"messageReceived",MESSAGE_REQUEST_INITIATED:"messageRequestInitiated",MESSAGE_REQUEST_UPLOADED:"messageRequestUploaded",MESSAGE_REQUEST_ERROR:"messageRequestError",CRITICAL_ERROR:"criticalError"};class Xd{constructor(n,i){this.utils=n,this.emitter=i,this.logger=Q.getInstance(),this.errorHandler=oe.getInstance(),this.historyIndex=null}async init(){try{const n=await this.utils.fetchLatestChatMessage();return this.historyIndex=n.index,await this.fetchPreviousMessages(),n.index}catch(n){return this.errorHandler.handleError(n,"SwarmHistory.init"),A.FeedIndex.fromBigInt(0n)}}async fetchPreviousMessages(n=10){try{if(!this.historyIndex){this.logger.warn("History index is not set. Cannot fetch previous messages.");return}if(this.historyIndex.toBigInt()===0n){this.logger.warn("No previous messages to fetch.");return}const i=this.historyIndex.toBigInt(),c=i>BigInt(n)?i-BigInt(n):0n;for(let u=i-1n;u>=c;u--){const l=await this.utils.fetchChatMessage(A.FeedIndex.fromBigInt(u));if(this.emitter.emit(W.MESSAGE_RECEIVED,l),this.historyIndex=A.FeedIndex.fromBigInt(u),u===0n)break}}catch(i){this.errorHandler.handleError(i,"SwarmHistory.fetchPreviousMessages")}}}class ef{constructor(n,i){this.userDetails=n,this.swarmSettings=i,this.depth=26,this.errorHandler=oe.getInstance(),this.UPLOAD_GSOC_TIMEOUT=2e3}generateUserOwnedFeedId(n,i){return`${n}_EthercastChat_${i}`}isNotFoundError(n){return n.stack.includes("404")||n.message.includes("Not Found")||n.message.includes("404")||n.code===404}async writeOwnFeedDataByIndex(n,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(n,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(n,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(n,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=this.generateUserOwnedFeedId(l,m),v=A.Topic.fromString(w);await c.makeFeedWriter(v,new A.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:n})}async writeOwnFeedDataByIndexEnvelope(n,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=new A.PrivateKey(h),v=A.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(l,m),j=A.Topic.fromString(E),re=ni(j,n),ne=Qs(i),Le=Xs(ne,re,w),Ae={hash:()=>Le.address.toUint8Array()},Vt=v.stamp(Ae),{upload:Wt}=c.makeSOCWriter(w),ze=A.Bytes.fromUtf8(i);return(await Wt(Vt,re,ze.toUint8Array())).reference.toHex()}orderMessages(n){return n.sort((i,c)=>i.timestamp-c.timestamp)}async uploadObjectToBee(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(n);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(n)}async uploadObjectToBeeOwn(n){try{const{bee:i,stamp:c}=this.swarmSettings;return(await i.uploadData(c,JSON.stringify(n),{redundancyLevel:4})).reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(n){try{const{bee:i,stamp:c}=this.swarmSettings,{privateKey:u}=this.userDetails,l=A.Stamper.fromBlank(u,c,this.depth),h=A.Bytes.fromUtf8(JSON.stringify(n)),m=new Nl(async v=>{await i.uploadChunk(l.stamp(v),v.build())});await m.append(h.toUint8Array());const w=await m.finalize();return B.uint8ArrayToHex(w.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:n,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),l=A.Topic.fromString(u),m=await n.makeFeedReader(l,c).downloadPayload(),w=Number(m.feedIndex.toBigInt()),v=w+1;return{latestIndex:w,nextIndex:v}}catch(n){if(this.isNotFoundError(n))return{latestIndex:-1,nextIndex:0};throw n}}async fetchLatestChatMessage(){const{bee:n,chatTopic:i,chatAddress:c}=this.swarmSettings,l=await n.makeFeedReader(A.Topic.fromString(i),bn(c)).downloadPayload();return{message:l.payload.toJSON(),index:l.feedIndex}}async fetchChatMessage(n){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(A.Topic.fromString(c),bn(u)).downloadPayload({index:n})).payload.toJSON()}async sendMessageToGsoc(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(n);else if(c)await this.sendMessageToGsocEnvelope(n);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(n,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${n}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok){const l=new Error(`Failed to fetch: ${n}/${i} [${u.status}]`);throw l.status=u.status,l}return u.text()}async sendMessageToGsocOwn(n){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,h=new A.PrivateKey(l),m=A.Identifier.fromString(u),w=A.Bytes.fromUtf8(n),{upload:v}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await v(c,m,w.toUint8Array())}async sendMessageToGsocEnvelope(n){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,{privateKey:h}=this.userDetails,m=A.Stamper.fromBlank(h,c,this.depth),w=new A.PrivateKey(l),v=A.Identifier.fromString(u),E=A.Bytes.fromUtf8(n),j=Qs(E.toUint8Array()),re=Xs(j,v,w),ne={hash:()=>re.address.toUint8Array()},Le=m.stamp(ne),{upload:Ae}=i.makeSOCWriter(w,{timeout:this.UPLOAD_GSOC_TIMEOUT});await Ae(Le,v,E.toUint8Array())}}class tf{constructor(n){this.logger=Q.getInstance(),this.errorHandler=oe.getInstance(),this.gsocIndex=null,this.fetchProcessRunning=!1,this.stopFetch=!1;const i=new A.PrivateKey(bn(n.user.privateKey));this.userDetails={privateKey:n.user.privateKey,ownAddress:i.publicKey().address().toString(),nickname:n.user.nickname,ownIndex:-1},this.swarmSettings={bee:new A.Bee(n.infra.beeUrl),beeUrl:n.infra.beeUrl,stamp:n.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:n.infra.enveloped,gsocTopic:n.infra.gsocTopic,gsocResourceId:n.infra.gsocResourceId,chatTopic:n.infra.chatTopic,chatAddress:n.infra.chatAddress},this.emitter=new Ll,this.utils=new ef(this.userDetails,this.swarmSettings),this.history=new Xd(this.utils,this.emitter)}start(){this.init(),this.startMessagesFetchProcess()}stop(){this.emitter.cleanAll(),this.stopMessagesFetchProcess()}getEmitter(){return this.emitter}orderMessages(n){return this.utils.orderMessages(n)}async sendMessage(n,i){const c=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,u={id:i||Ml(),username:this.userDetails.nickname,address:this.userDetails.ownAddress,chatTopic:this.swarmSettings.chatTopic,userTopic:this.utils.generateUserOwnedFeedId(this.swarmSettings.chatTopic,this.userDetails.ownAddress),signature:this.getSignature(),timestamp:Date.now(),index:c,message:n};try{this.emitter.emit(W.MESSAGE_REQUEST_INITIATED,u),await this.utils.writeOwnFeedDataByIndex(c,JSON.stringify(u)),this.userDetails.ownIndex=c,this.emitter.emit(W.MESSAGE_REQUEST_UPLOADED,u),await this.broadcastUserMessage(u)}catch(l){this.emitter.emit(W.MESSAGE_REQUEST_ERROR,u),this.errorHandler.handleError(l,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessages()}finally{this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!1)}}async retrySendMessage(n){this.sendMessage(n.message,n.id)}async retryBroadcastUserMessage(n){await this.broadcastUserMessage(n)}async init(){try{this.emitter.emit(W.LOADING_INIT,!0);const[n,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(n.status==="rejected")throw n.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(W.LOADING_INIT,!1)}catch(n){this.errorHandler.handleError(n,"Chat.initSelfState"),this.emitter.emit(W.CRITICAL_ERROR,n)}}async initOwnIndex(){const{latestIndex:c}=await _n(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async fetchLatestMessage(){try{if(!this.gsocIndex)return;const n=A.Topic.fromString(this.swarmSettings.chatTopic),i=ni(n,this.gsocIndex),c=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,i.toString()),u=JSON.parse(c);if(!Yd(u)){this.logger.warn("Invalid GSOC message during fetching");return}this.emitter.emit(W.MESSAGE_RECEIVED,u),this.gsocIndex=this.gsocIndex.next()}catch(n){if(this.utils.isNotFoundError(n))return;this.errorHandler.handleError(n,"Chat.fetchLatestMessage")}}async broadcastUserMessage(n){try{return _n(()=>this.utils.sendMessageToGsoc(JSON.stringify(n)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(){const{ownAddress:n,privateKey:i,nickname:c}=this.userDetails,u=new A.EthAddress(n).toString(),l=new A.PrivateKey(i);if(l.publicKey().address().toString()!==u)throw new Error("The provided address does not match the address derived from the private key");const m=Date.now();return l.sign(JSON.stringify({username:c,address:u,timestamp:m})).toHex()}async startMessagesFetchProcess(){if(this.fetchProcessRunning)return;this.fetchProcessRunning=!0,this.stopFetch=!1;const n=async()=>{if(this.stopFetch){this.fetchProcessRunning=!1;return}await this.fetchLatestMessage(),setTimeout(n,200)};n()}stopMessagesFetchProcess(){this.stopFetch=!0}}exports.EVENTS=W;exports.SwarmChat=tf;