@solarpunkltd/swarm-chat-js 6.2.0 → 6.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.
@@ -1,11 +1,11 @@
1
- (function(Q,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@ethersphere/bee-js")):typeof define=="function"&&define.amd?define(["exports","@ethersphere/bee-js"],A):(Q=typeof globalThis<"u"?globalThis:Q||self,A(Q.SwarmChatJs={},Q.BeeJs))})(this,function(Q,A){"use strict";const Z=[];for(let a=0;a<256;++a)Z.push((a+256).toString(16).slice(1));function bi(a,r=0){return(Z[a[r+0]]+Z[a[r+1]]+Z[a[r+2]]+Z[a[r+3]]+"-"+Z[a[r+4]]+Z[a[r+5]]+"-"+Z[a[r+6]]+Z[a[r+7]]+"-"+Z[a[r+8]]+Z[a[r+9]]+"-"+Z[a[r+10]]+Z[a[r+11]]+Z[a[r+12]]+Z[a[r+13]]+Z[a[r+14]]+Z[a[r+15]]).toLowerCase()}let Ht;const xi=new Uint8Array(16);function ki(){if(!Ht){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ht=crypto.getRandomValues.bind(crypto)}return Ht(xi)}const $n={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ei(a,r,i){if($n.randomUUID&&!r&&!a)return $n.randomUUID();a=a||{};const c=a.random||(a.rng||ki)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,bi(c)}class H{constructor(){}static getInstance(){return H.instance||(H.instance=new H),H.instance}formatMessage(r,...i){return`[${new Date().toISOString()}] [${r.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...r){console.log(this.formatMessage("log",...r))}info(...r){console.info(this.formatMessage("info",...r))}warn(...r){console.warn(this.formatMessage("warn",...r))}error(...r){console.error(this.formatMessage("error",...r))}debug(...r){console.debug(this.formatMessage("debug",...r))}}class X{constructor(){this.logger=H.getInstance()}static getInstance(){return X.instance||(X.instance=new X),X.instance}handleError(r,i){const c=r instanceof Error?r.message:"Unknown error occurred",u=r instanceof Error?r.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}class Rn{constructor(r){this.config=r,this.logger=H.getInstance(),this.errorHandler=X.getInstance(),this.isRunning=!1,this.stopRequested=!1,this.messageCallback=null}onMessage(r){this.messageCallback=r}async start(){if(this.isRunning){this.logger.warn("Polling transport already running");return}this.isRunning=!0,this.stopRequested=!1,this.logger.info("Starting polling transport"),await this.poll()}async stop(){this.logger.info("Stopping polling transport"),this.stopRequested=!0,this.isRunning=!1}async poll(){if(this.stopRequested){this.isRunning=!1;return}try{const i=await this.config.fetchMessage();i&&this.messageCallback&&this.messageCallback(i)}catch(i){this.errorHandler.handleError(i,"PollingTransport.poll")}const r=this.config.pollingInterval||1e3;setTimeout(()=>this.poll(),r)}}function Si(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var Cn={};(function(a){var r;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,n)=>e.then(n,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const n=Hs(e,t),s=[],o=n.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 n=e.length-1;n>0;n--){const s=Math.floor(t()*(n+1)),o=e[n];e[n]=e[s],e[s]=o}return e}function p(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function g(e){return e.length===1?e[0]:null}function y(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 n=[];for(let s=0;s<e;s++)n.push(t(s));return n}function oe(e){const t=[];for(let n=0;n<e[0].length;n++){t.push([]);for(let s=0;s<e.length;s++)t[n].push(e[s][n])}return t}function ce(e,t,n){const s=[];for(let o=0;o<e;o++){s.push([]);for(let d=0;d<t;d++)s[o].push(n)}return s}function it(e,t,n,s){if(n<0||s<0||s+t[0].length>e[0].length||n+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[n+o][s+d]!==t[o][d])return!1;return!0}function je(e,t,n=Math.random){return h(ps(0,e.length-1),n).slice(0,t)}function sr(e,t){return e.map(n=>n[t])}function ir(e){let t=e,n=3405648695,s=3735928559;return function(){return t+=n,n^=t<<7,t*=s,s^=t<<13,t^=n^s,(t>>>0)/4294967296}}function at(e,t,n=Math.random){return Math.floor(n()*(t-e+1))+e}function Jn(e,t,n=Math.random){return n()*(t-e)+e}function Ka(){return Math.random()*2-1}function Ya(e,t,n){return t>=e.x&&t<e.x+e.width&&n>=e.y&&n<e.y+e.height}function Qa(e,t,n,s=Math.random){let o,d;do o=at(0,e-1,s),d=at(0,t-1,s);while(n&&Ya(n,o,d));return[o,d]}function Xa(e,t=Math.random){const n=Math.floor(e),s=e-n;return es(s,t)?n+1:n}function es(e,t=Math.random){return t()<e}function ar(e,t=Math.random){return e[Math.floor(e.length*t())]}function Ja(e,t,n=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return je(e,t,n).map(s=>e[s])}function eo(e,t,n,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=ar(e,s);o.some(f=>n(f,d))||o.push(d)}return o}function to(e,t,n,s,o,d=Math.random){const f=e.filter(m=>m!==t&&m!==n),v=[];for(t!==null&&v.push(t);f.length&&v.length<s;){const m=a.Random.intBetween(0,f.length-1,d);o(f[m],v)&&v.push(f[m]),f.splice(m,1)}return h(v,d),{values:v,indexOfGuaranteed:t!==null?v.indexOf(t):-1}}function ot(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function ts(e,t,n){return n(t.reduce((s,o)=>o(s),e))}function ro(e,t){return n=>ts(n,e,t)}function no(e,t,n){if(n===void 0&&(n=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((d,f)=>d+f,0);const o=n*s;for(let d=0;d<e.length-1;d++)if(s-=t[d],o>=s)return e[d];return ot(e)}function so(e,t,n=Math.random){const s=t.map(d=>n()*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 ke(e,t){if(e==null)return null;const n=t.split(".");let s=e;for(const o of n){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function Ee(e,t,n){const s=t.split(/\.|\[/);let o=e;for(let d=0;d<s.length;d++){const f=s[d],v=d<s.length-1&&s[d+1].includes("]"),m=f.includes("]")?f.replace(/\[|\]/g,""):f;if(d===s.length-1)return o[m]=n,n;me(o[m])||(v?o[m]=[]:o[m]={}),o=o[m]}return n}function io(e,t,n=1){const s=ke(e,t)||0;return Ee(e,t,s+n),s}function ao(e,t,n){return ke(e,t)||Ee(e,t,n)}function oo(e,t){const n=mr(t,"."),s=gs(t,".");if(!n||!s)return;const o=ke(e,n);delete o[s]}function co(e,t,n){const s=ke(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return Ee(e,t,n),s}function uo(e,t,n){for(const s of t){const o=ke(e,s);if(o)return o}if(n){const s=Object.values(e);if(s.length)return s[0]}return null}async function lo(e,t,n){for(;;){try{await e()}catch(s){n&&n("Error in forever",s)}await l(t)}}function fo(e,t){e();const n=setInterval(()=>{e()},t);return()=>clearInterval(n)}function ho(e){return e/1024/1024}function po(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 mo(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 go(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function yo(e,t,n,s){const o=e*Math.PI/180,d=n*Math.PI/180,f=(n-e)*Math.PI/180,v=(s-t)*Math.PI/180,m=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(d)*Math.sin(v/2)*Math.sin(v/2);return 6371e3*(2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m)))}function $t(e,t){return Math.round(e/t)*t}function vo(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 wo(e){return e*(e+1)/2}function _o(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function me(e,t=!0){return!e||t&&!or(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 De(e){return me(e)&&!Array.isArray(e)}function rs(e){return Array.isArray(e)&&e.length===0}function bo(e){return De(e)&&Object.keys(e).length===0}function or(e){return e===void 0}function cr(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function W(e){return Object.prototype.toString.call(e)==="[object String]"}function ge(e){return typeof e=="number"&&isFinite(e)}function ns(e){return e===!0||e===!1}function Ue(e){return Object.prototype.toString.call(e)==="[object Date]"}function Rt(e){return!W(e)||e.trim().length===0}function ur(e){return ge(e)&&Number.isInteger(e)&&e>=1}function ss(e){return W(e)&&e.match(/^-?\d+$/)!==null}function is(e){return W(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const xo="!@#$%^&*()_+-=[]{}|;:<>?,./",ko="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),lr="abcdefghijklmnopqrstuvwxyz",Eo="ABCDEFGHIJKLMNOPQRSTUVWXYZ",So="1234567890",dr=lr+Eo+So,as=dr+xo,os=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],cs="0123456789abcdef";function To(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=lr[Math.floor(t()*lr.length)];return n}function Ao(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=dr[Math.floor(t()*dr.length)];return n}function Oo(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=as[Math.floor(t()*as.length)];return n}function Io(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=os[Math.floor(t()*os.length)];return n}function Mo(e,t){const n=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(n);return s?s[0]:null}function $o(e,t,n=ko){const s=ys(e,n);for(const o of s)if(t(o))return o;return null}function Ro(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=cs[Math.floor(t()*cs.length)];return n}function Co(e,t){if(!ss(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=BigInt(e);if(t&&(t.min&&n<t.min||t.max&&n>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+n);return e}function us(e,t){if(Rt(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 No(e,t){if(!is(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=e.replace(/^0x/,"");if(t&&t.byteLength&&n.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+n);return n}function jo(e,t){if(!us(e,t).split("").every(n=>n==="_"||lt(n)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ls(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 Do(e,t){if(!cr(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ct(e,t){if(ge(e))return t&&ls(e,t),e;if(!W(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=parseFloat(e);return t&&ls(n,t),n}function fr(e,t){return Ct(e,t)|0}function Uo(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!ns(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Po(e,t){if(!Ue(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Zo(e){return Rt(e)?null:e}function Bo(e,t){if(!W(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Lo(e,t){if(ur(e))return e;const n=parseInt(e,10);if(!ur(n))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function zo(e,t){if(!W(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=e.split(":");if(n.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(n[0],10),o=parseInt(n[1],10);if(!ge(s)||!ge(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 Vo(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Nt(e,t){if(!De(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Fo(e,t){return e===null?null:Nt(e,t)}function Wo(e,t){const n=Nt(e,t);for(const s of Object.keys(n))if(!W(n[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function Ho(e,t){const n=Nt(e),s=Object.keys(n),o=Object.values(n);if(!s.every(W)||!o.every(ge))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function ds(e){return W(e)&&e.match(/^https?:\/\/.+/)!==null}function qo(e,t){if(!ds(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Go(e,t){return t==null?!0:e(t)}function Ko(e,t){return t==null?null:e(t)}function Yo(e,t){return t==null?void 0:e(t)}function fs(e,t){for(const[n,s]of Object.entries(t))if(!s(e[n]))throw TypeError(`${n} in value does not exist or match shape`);for(const n of Object.keys(e))if(!t[n])throw TypeError(`${n} exists in value but not in shape`);return!0}function Qo(e,t){return e.every(n=>fs(n,t))}function ct(e,t="json",n=0){if(me(e,!1)){if(n>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(d=>ct(d,"json",n+1));return n===0?JSON.stringify(o):o}const s={};e.message&&(s.message=ct(e.message,"json",n+1));for(const[o,d]of Object.entries(e))s[o]=ct(d,"json",n+1);return n===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(ct(e[o],"json",n+1))}`).join(" ")}}return or(e)&&(e="undefined"),n===0?JSON.stringify(e):e}function Xo(e,t){if(W(e))return e;const n=Object.keys(e);e.message&&!n.includes("message")&&n.push("message");const s=n.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
- `+e.stack:s}function Se(e,t){if(De(e)&&De(t))for(const n in t)De(t[n])?(e[n]||(e[n]={}),Se(e[n],t[n])):Array.isArray(t[n])?e[n]=[...t[n]]:(t[n]!==null&&t[n]!==void 0||e[n]===null||e[n]===void 0)&&(e[n]=t[n]);return e}function Jo(e,t){const n={};return Se(n,e),Se(n,t),n}function ec(e,t,n){const s={};return Se(s,e),Se(s,t),Se(s,n),s}function hs(e,t){const n={};for(const s of e)for(const o of Object.keys(s))n[o]?n[o]=t(n[o],s[o]):n[o]=s[o];return n}function tc(e){return hs(e,(t,n)=>t+n)}function rc(e,t,n){e[t]||(e[t]=[]),e[t].push(n)}function nc(e,t,n){for(e.unshift(t);e.length>n;)e.pop()}function sc(e,t){let n=t%e.length;return n<0&&(n+=e.length),e[n]}function jt(e,t){Array.prototype.push.apply(e,t)}function ic(e,t){Array.prototype.unshift.apply(e,t)}async function ac(e,t){const n=[];for(const s of e)n.push(await t(s));return n}function oc(e,t){const n=[];for(let s=0;s<e.length;s++)n.push(e[s]),s<e.length-1&&(cr(t)?n.push(t()):n.push(t));return n}function cc(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function uc(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function lc(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function dc(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function fc(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function hc(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function pc(e,t){for(let n=0;n<e.length;n++){const s=e[n],o=t[n],d=Math.max(0,o.getTime()-Date.now());setTimeout(s,d)}}function mc(e,t,n){return e+(t-e)*n}function gc(e){return e.reduce((t,n)=>t+n,0)}function yc(e){return e.reduce((t,n)=>t+n,0)/e.length}function vc(e){const t=[...e].sort((s,o)=>s-o),n=Math.floor(t.length/2);return t.length%2===0?(t[n]+t[n-1])/2:t[n]}function wc(e,t){return e-(t-1)/2}function ps(e,t){const n=[];for(let s=e;s<=t;s++)n.push(s);return n}function _c(e,t){return t.some(n=>e.includes(n))}function bc(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function hr(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(n=>/[a-z0-9]/.test(n)||t(n)?n:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function xc(e){return hr(e).replaceAll("-","")}function kc(e){return Ut(e.replace(/([A-Z])/g," $1"))}function Ec(e){return e.split("-").map(Ut).join(" ")}function Sc(e){return ws(e.split("-").map(Ut).join(""))}function Tc(e,t=", ",n=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${n}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${n}${e[e.length-1]}`}function Ac(e,t){return t+e.split("").join(t)+t}function Oc(e){return hr(e).replace(/-/g,"_").toUpperCase()}function Dt(e,t){if(t.length===0)return 0;const n=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:n.startsWith(s)?1e4-e.length:n.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(n)?1e3-e.length:0}function Ic(e,t){return e.filter(n=>Dt(n,t)).sort((n,s)=>Dt(s,t)-Dt(n,t))}function Mc(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const $c={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function Rc(e){let t=e.replace(/&#(\d+);/g,(n,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(n,s)=>String.fromCharCode(parseInt(s,16)));for(const[n,s]of Object.entries($c))t=t.replaceAll(n,s);return t}function ms(e,t){const n=e.indexOf(t);return n===-1?null:e.slice(0,n)}function pr(e,t){const n=e.indexOf(t);return n===-1?null:e.slice(n+t.length)}function mr(e,t){const n=e.lastIndexOf(t);return n===-1?null:e.slice(0,n)}function gs(e,t){const n=e.lastIndexOf(t);return n===-1?null:e.slice(n+t.length)}function Cc(e,t,n){const s=mr(e,n);return s?pr(s,t):null}function Nc(e,t,n){const s=pr(e,t);return s?ms(s,n):null}function gr(e,t,n=!1){const s=n?e.lastIndexOf(t):e.indexOf(t);return s===-1?n?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function ys(e,t){let n=[e];for(const s of t)n=n.flatMap(o=>o.split(s));return n.filter(s=>s)}function yr(e){const t=ot(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?"":t.slice(n+1)}function vr(e){const t=ot(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?t:t.slice(0,n)}function jc(e){let[t,n]=e.split("@");t=ut(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!n||n.indexOf(".")===-1||n.indexOf(".")===n.length-1)throw new Error("Invalid email");return n=ut(n.toLowerCase()).replaceAll(" ",""),`${s}@${n}`}function Dc(e){const t=vr(e),n=yr(e);return n?`${t}.${n}`:t}function Uc(e){const t=vr(e),n=yr(e);return{basename:t,extension:n,filename:n?`${t}.${n}`:t}}function Pc(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(n,s)=>ar(s.split("|"),t))}function vs(e){const t=/\{(.+?)\}/,n=e.match(t);if(!n||!n.index)return[e];const s=n[1].split(","),o=e.slice(0,n.index),d=e.slice(n.index+n[0].length);let f=[];for(const v of s){const m=vs(o+v+d);f=f.concat(m)}return f}function ut(e){return e.split(`
1
+ (function(Q,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@ethersphere/bee-js")):typeof define=="function"&&define.amd?define(["exports","@ethersphere/bee-js"],A):(Q=typeof globalThis<"u"?globalThis:Q||self,A(Q.SwarmChatJs={},Q.BeeJs))})(this,function(Q,A){"use strict";const Z=[];for(let a=0;a<256;++a)Z.push((a+256).toString(16).slice(1));function _i(a,r=0){return(Z[a[r+0]]+Z[a[r+1]]+Z[a[r+2]]+Z[a[r+3]]+"-"+Z[a[r+4]]+Z[a[r+5]]+"-"+Z[a[r+6]]+Z[a[r+7]]+"-"+Z[a[r+8]]+Z[a[r+9]]+"-"+Z[a[r+10]]+Z[a[r+11]]+Z[a[r+12]]+Z[a[r+13]]+Z[a[r+14]]+Z[a[r+15]]).toLowerCase()}let Ht;const xi=new Uint8Array(16);function ki(){if(!Ht){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ht=crypto.getRandomValues.bind(crypto)}return Ht(xi)}const $n={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ei(a,r,i){if($n.randomUUID&&!r&&!a)return $n.randomUUID();a=a||{};const c=a.random||(a.rng||ki)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,_i(c)}class q{constructor(){}static getInstance(){return q.instance||(q.instance=new q),q.instance}formatMessage(r,...i){return`[${new Date().toISOString()}] [${r.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...r){console.log(this.formatMessage("log",...r))}info(...r){console.info(this.formatMessage("info",...r))}warn(...r){console.warn(this.formatMessage("warn",...r))}error(...r){console.error(this.formatMessage("error",...r))}debug(...r){console.debug(this.formatMessage("debug",...r))}}class X{constructor(){this.logger=q.getInstance()}static getInstance(){return X.instance||(X.instance=new X),X.instance}handleError(r,i){const c=r instanceof Error?r.message:"Unknown error occurred",u=r instanceof Error?r.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}class Rn{constructor(r){this.config=r,this.logger=q.getInstance(),this.errorHandler=X.getInstance(),this.isRunning=!1,this.stopRequested=!1,this.messageCallback=null}onMessage(r){this.messageCallback=r}async start(){if(this.isRunning){this.logger.warn("Polling transport already running");return}this.isRunning=!0,this.stopRequested=!1,this.logger.info("Starting polling transport"),await this.poll()}async stop(){this.logger.info("Stopping polling transport"),this.stopRequested=!0,this.isRunning=!1}async poll(){if(this.stopRequested){this.isRunning=!1;return}try{const i=await this.config.fetchMessage();i&&this.messageCallback&&this.messageCallback(i)}catch(i){this.errorHandler.handleError(i,"PollingTransport.poll")}const r=this.config.pollingInterval||1e3;setTimeout(()=>this.poll(),r)}}function Si(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var Cn={};(function(a){var r;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,n)=>e.then(n,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const n=Hs(e,t),s=[],o=n.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 n=e.length-1;n>0;n--){const s=Math.floor(t()*(n+1)),o=e[n];e[n]=e[s],e[s]=o}return e}function p(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function g(e){return e.length===1?e[0]:null}function y(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 n=[];for(let s=0;s<e;s++)n.push(t(s));return n}function oe(e){const t=[];for(let n=0;n<e[0].length;n++){t.push([]);for(let s=0;s<e.length;s++)t[n].push(e[s][n])}return t}function ce(e,t,n){const s=[];for(let o=0;o<e;o++){s.push([]);for(let d=0;d<t;d++)s[o].push(n)}return s}function it(e,t,n,s){if(n<0||s<0||s+t[0].length>e[0].length||n+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[n+o][s+d]!==t[o][d])return!1;return!0}function je(e,t,n=Math.random){return h(ps(0,e.length-1),n).slice(0,t)}function sr(e,t){return e.map(n=>n[t])}function ir(e){let t=e,n=3405648695,s=3735928559;return function(){return t+=n,n^=t<<7,t*=s,s^=t<<13,t^=n^s,(t>>>0)/4294967296}}function at(e,t,n=Math.random){return Math.floor(n()*(t-e+1))+e}function Jn(e,t,n=Math.random){return n()*(t-e)+e}function Ka(){return Math.random()*2-1}function Ya(e,t,n){return t>=e.x&&t<e.x+e.width&&n>=e.y&&n<e.y+e.height}function Qa(e,t,n,s=Math.random){let o,d;do o=at(0,e-1,s),d=at(0,t-1,s);while(n&&Ya(n,o,d));return[o,d]}function Xa(e,t=Math.random){const n=Math.floor(e),s=e-n;return es(s,t)?n+1:n}function es(e,t=Math.random){return t()<e}function ar(e,t=Math.random){return e[Math.floor(e.length*t())]}function Ja(e,t,n=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return je(e,t,n).map(s=>e[s])}function eo(e,t,n,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=ar(e,s);o.some(f=>n(f,d))||o.push(d)}return o}function to(e,t,n,s,o,d=Math.random){const f=e.filter(m=>m!==t&&m!==n),v=[];for(t!==null&&v.push(t);f.length&&v.length<s;){const m=a.Random.intBetween(0,f.length-1,d);o(f[m],v)&&v.push(f[m]),f.splice(m,1)}return h(v,d),{values:v,indexOfGuaranteed:t!==null?v.indexOf(t):-1}}function ot(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function ts(e,t,n){return n(t.reduce((s,o)=>o(s),e))}function ro(e,t){return n=>ts(n,e,t)}function no(e,t,n){if(n===void 0&&(n=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((d,f)=>d+f,0);const o=n*s;for(let d=0;d<e.length-1;d++)if(s-=t[d],o>=s)return e[d];return ot(e)}function so(e,t,n=Math.random){const s=t.map(d=>n()*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 ke(e,t){if(e==null)return null;const n=t.split(".");let s=e;for(const o of n){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function Ee(e,t,n){const s=t.split(/\.|\[/);let o=e;for(let d=0;d<s.length;d++){const f=s[d],v=d<s.length-1&&s[d+1].includes("]"),m=f.includes("]")?f.replace(/\[|\]/g,""):f;if(d===s.length-1)return o[m]=n,n;me(o[m])||(v?o[m]=[]:o[m]={}),o=o[m]}return n}function io(e,t,n=1){const s=ke(e,t)||0;return Ee(e,t,s+n),s}function ao(e,t,n){return ke(e,t)||Ee(e,t,n)}function oo(e,t){const n=mr(t,"."),s=gs(t,".");if(!n||!s)return;const o=ke(e,n);delete o[s]}function co(e,t,n){const s=ke(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return Ee(e,t,n),s}function uo(e,t,n){for(const s of t){const o=ke(e,s);if(o)return o}if(n){const s=Object.values(e);if(s.length)return s[0]}return null}async function lo(e,t,n){for(;;){try{await e()}catch(s){n&&n("Error in forever",s)}await l(t)}}function fo(e,t){e();const n=setInterval(()=>{e()},t);return()=>clearInterval(n)}function ho(e){return e/1024/1024}function po(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 mo(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 go(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function yo(e,t,n,s){const o=e*Math.PI/180,d=n*Math.PI/180,f=(n-e)*Math.PI/180,v=(s-t)*Math.PI/180,m=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(d)*Math.sin(v/2)*Math.sin(v/2);return 6371e3*(2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m)))}function $t(e,t){return Math.round(e/t)*t}function vo(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 wo(e){return e*(e+1)/2}function bo(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function me(e,t=!0){return!e||t&&!or(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 De(e){return me(e)&&!Array.isArray(e)}function rs(e){return Array.isArray(e)&&e.length===0}function _o(e){return De(e)&&Object.keys(e).length===0}function or(e){return e===void 0}function cr(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function H(e){return Object.prototype.toString.call(e)==="[object String]"}function ge(e){return typeof e=="number"&&isFinite(e)}function ns(e){return e===!0||e===!1}function Pe(e){return Object.prototype.toString.call(e)==="[object Date]"}function Rt(e){return!H(e)||e.trim().length===0}function ur(e){return ge(e)&&Number.isInteger(e)&&e>=1}function ss(e){return H(e)&&e.match(/^-?\d+$/)!==null}function is(e){return H(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const xo="!@#$%^&*()_+-=[]{}|;:<>?,./",ko="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),lr="abcdefghijklmnopqrstuvwxyz",Eo="ABCDEFGHIJKLMNOPQRSTUVWXYZ",So="1234567890",dr=lr+Eo+So,as=dr+xo,os=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],cs="0123456789abcdef";function To(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=lr[Math.floor(t()*lr.length)];return n}function Ao(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=dr[Math.floor(t()*dr.length)];return n}function Oo(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=as[Math.floor(t()*as.length)];return n}function Io(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=os[Math.floor(t()*os.length)];return n}function Mo(e,t){const n=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(n);return s?s[0]:null}function $o(e,t,n=ko){const s=ys(e,n);for(const o of s)if(t(o))return o;return null}function Ro(e,t=Math.random){let n="";for(let s=0;s<e;s++)n+=cs[Math.floor(t()*cs.length)];return n}function Co(e,t){if(!ss(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=BigInt(e);if(t&&(t.min&&n<t.min||t.max&&n>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+n);return e}function us(e,t){if(Rt(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 No(e,t){if(!is(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=e.replace(/^0x/,"");if(t&&t.byteLength&&n.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+n);return n}function jo(e,t){if(!us(e,t).split("").every(n=>n==="_"||lt(n)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ls(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 Do(e,t){if(!cr(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ct(e,t){if(ge(e))return t&&ls(e,t),e;if(!H(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=parseFloat(e);return t&&ls(n,t),n}function fr(e,t){return Ct(e,t)|0}function Po(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!ns(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Uo(e,t){if(!Pe(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Zo(e){return Rt(e)?null:e}function Bo(e,t){if(!H(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Lo(e,t){if(ur(e))return e;const n=parseInt(e,10);if(!ur(n))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function zo(e,t){if(!H(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const n=e.split(":");if(n.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(n[0],10),o=parseInt(n[1],10);if(!ge(s)||!ge(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 Vo(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Nt(e,t){if(!De(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Fo(e,t){return e===null?null:Nt(e,t)}function Wo(e,t){const n=Nt(e,t);for(const s of Object.keys(n))if(!H(n[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function Ho(e,t){const n=Nt(e),s=Object.keys(n),o=Object.values(n);if(!s.every(H)||!o.every(ge))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return n}function ds(e){return H(e)&&e.match(/^https?:\/\/.+/)!==null}function qo(e,t){if(!ds(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Go(e,t){return t==null?!0:e(t)}function Ko(e,t){return t==null?null:e(t)}function Yo(e,t){return t==null?void 0:e(t)}function fs(e,t){for(const[n,s]of Object.entries(t))if(!s(e[n]))throw TypeError(`${n} in value does not exist or match shape`);for(const n of Object.keys(e))if(!t[n])throw TypeError(`${n} exists in value but not in shape`);return!0}function Qo(e,t){return e.every(n=>fs(n,t))}function ct(e,t="json",n=0){if(me(e,!1)){if(n>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(d=>ct(d,"json",n+1));return n===0?JSON.stringify(o):o}const s={};e.message&&(s.message=ct(e.message,"json",n+1));for(const[o,d]of Object.entries(e))s[o]=ct(d,"json",n+1);return n===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(ct(e[o],"json",n+1))}`).join(" ")}}return or(e)&&(e="undefined"),n===0?JSON.stringify(e):e}function Xo(e,t){if(H(e))return e;const n=Object.keys(e);e.message&&!n.includes("message")&&n.push("message");const s=n.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
+ `+e.stack:s}function Se(e,t){if(De(e)&&De(t))for(const n in t)De(t[n])?(e[n]||(e[n]={}),Se(e[n],t[n])):Array.isArray(t[n])?e[n]=[...t[n]]:(t[n]!==null&&t[n]!==void 0||e[n]===null||e[n]===void 0)&&(e[n]=t[n]);return e}function Jo(e,t){const n={};return Se(n,e),Se(n,t),n}function ec(e,t,n){const s={};return Se(s,e),Se(s,t),Se(s,n),s}function hs(e,t){const n={};for(const s of e)for(const o of Object.keys(s))n[o]?n[o]=t(n[o],s[o]):n[o]=s[o];return n}function tc(e){return hs(e,(t,n)=>t+n)}function rc(e,t,n){e[t]||(e[t]=[]),e[t].push(n)}function nc(e,t,n){for(e.unshift(t);e.length>n;)e.pop()}function sc(e,t){let n=t%e.length;return n<0&&(n+=e.length),e[n]}function jt(e,t){Array.prototype.push.apply(e,t)}function ic(e,t){Array.prototype.unshift.apply(e,t)}async function ac(e,t){const n=[];for(const s of e)n.push(await t(s));return n}function oc(e,t){const n=[];for(let s=0;s<e.length;s++)n.push(e[s]),s<e.length-1&&(cr(t)?n.push(t()):n.push(t));return n}function cc(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function uc(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function lc(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function dc(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function fc(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function hc(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function pc(e,t){for(let n=0;n<e.length;n++){const s=e[n],o=t[n],d=Math.max(0,o.getTime()-Date.now());setTimeout(s,d)}}function mc(e,t,n){return e+(t-e)*n}function gc(e){return e.reduce((t,n)=>t+n,0)}function yc(e){return e.reduce((t,n)=>t+n,0)/e.length}function vc(e){const t=[...e].sort((s,o)=>s-o),n=Math.floor(t.length/2);return t.length%2===0?(t[n]+t[n-1])/2:t[n]}function wc(e,t){return e-(t-1)/2}function ps(e,t){const n=[];for(let s=e;s<=t;s++)n.push(s);return n}function bc(e,t){return t.some(n=>e.includes(n))}function _c(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function hr(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(n=>/[a-z0-9]/.test(n)||t(n)?n:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function xc(e){return hr(e).replaceAll("-","")}function kc(e){return Pt(e.replace(/([A-Z])/g," $1"))}function Ec(e){return e.split("-").map(Pt).join(" ")}function Sc(e){return ws(e.split("-").map(Pt).join(""))}function Tc(e,t=", ",n=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${n}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${n}${e[e.length-1]}`}function Ac(e,t){return t+e.split("").join(t)+t}function Oc(e){return hr(e).replace(/-/g,"_").toUpperCase()}function Dt(e,t){if(t.length===0)return 0;const n=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:n.startsWith(s)?1e4-e.length:n.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(n)?1e3-e.length:0}function Ic(e,t){return e.filter(n=>Dt(n,t)).sort((n,s)=>Dt(s,t)-Dt(n,t))}function Mc(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const $c={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function Rc(e){let t=e.replace(/&#(\d+);/g,(n,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(n,s)=>String.fromCharCode(parseInt(s,16)));for(const[n,s]of Object.entries($c))t=t.replaceAll(n,s);return t}function ms(e,t){const n=e.indexOf(t);return n===-1?null:e.slice(0,n)}function pr(e,t){const n=e.indexOf(t);return n===-1?null:e.slice(n+t.length)}function mr(e,t){const n=e.lastIndexOf(t);return n===-1?null:e.slice(0,n)}function gs(e,t){const n=e.lastIndexOf(t);return n===-1?null:e.slice(n+t.length)}function Cc(e,t,n){const s=mr(e,n);return s?pr(s,t):null}function Nc(e,t,n){const s=pr(e,t);return s?ms(s,n):null}function gr(e,t,n=!1){const s=n?e.lastIndexOf(t):e.indexOf(t);return s===-1?n?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function ys(e,t){let n=[e];for(const s of t)n=n.flatMap(o=>o.split(s));return n.filter(s=>s)}function yr(e){const t=ot(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?"":t.slice(n+1)}function vr(e){const t=ot(e.split(/\\|\//g)),n=t.lastIndexOf(".",t.length-1);return n<=0?t:t.slice(0,n)}function jc(e){let[t,n]=e.split("@");t=ut(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!n||n.indexOf(".")===-1||n.indexOf(".")===n.length-1)throw new Error("Invalid email");return n=ut(n.toLowerCase()).replaceAll(" ",""),`${s}@${n}`}function Dc(e){const t=vr(e),n=yr(e);return n?`${t}.${n}`:t}function Pc(e){const t=vr(e),n=yr(e);return{basename:t,extension:n,filename:n?`${t}.${n}`:t}}function Uc(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(n,s)=>ar(s.split("|"),t))}function vs(e){const t=/\{(.+?)\}/,n=e.match(t);if(!n||!n.index)return[e];const s=n[1].split(","),o=e.slice(0,n.index),d=e.slice(n.index+n[0].length);let f=[];for(const v of s){const m=vs(o+v+d);f=f.concat(m)}return f}function ut(e){return e.split(`
3
3
  `).map(t=>t.trim().replace(/\s+/g," ")).filter(t=>t.length>0).join(`
4
- `)}function Ut(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ws(e){return e.charAt(0).toLowerCase()+e.slice(1)}function _s(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function bs(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function lt(e){return _s(e)||bs(e)}const Zc=`
5
- \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function Bc(e){return Zc.includes(e)}function Lc(e){return lt(e)||e==="."||e==="["||e==="]"||e==="_"}function zc(e,t,n,s,o){return e.slice(0,t)+s+e.slice(t,t+n)+o+e.slice(t+n)}function xs(e,t,n=0){const s=t.exec(e.slice(n));return s?{index:s.index,match:s[0]}:null}function ks(e,t,n=!0){if(!n)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=xs(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 Vc(e,t,n=!0){let s=0;for(const o of t){let d=!1;for(;!d&&s<e.length;)ks(e[s],o,n)&&(d=!0),s++;if(!d)return!1}return!0}function Fc(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function Pe(e,t,n=0){let s=-1;for(const o of t){const d=e.indexOf(o,n);d!==-1&&(s===-1||d<s)&&(s=d)}return s}function Wc(e,t=0){for(let n=t;n<e.length;n++)if(Bc(e[n]))return n;return-1}function Hc(e,t=0){for(let n=t;n<e.length;n++)if(e[n]==="#"&&lt(e[n+1]))return n;return-1}function Es(e,t,n=0){return e.slice(0,n).lastIndexOf(t)}function Ss(e,t=0,n="{",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+n.length)===n&&o++;return-1}function Ts(e,t){const n=t.wordBoundary?Pe(e,[`${t.opening} `,`${t.opening}
6
- `],t.start||0):e.indexOf(t.opening,t.start||0);if(n===-1)return null;const s=Ss(e,n+t.opening.length,t.opening,t.closing);return s===-1?null:t.exclusive?e.slice(n+t.opening.length,s):e.slice(n,s+t.closing.length)}function qc(e,t){const n=[];let s=t.wordBoundary?Pe(e,[`${t.opening} `,`${t.opening}
7
- `],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(s===-1)return n;const o=Ts(e,{...t,start:s});if(!o)return n;n.push(o),s=t.wordBoundary?Pe(e,[`${t.opening} `,`${t.opening}
8
- `],s+o.length):e.indexOf(t.opening,s+o.length)}}function Gc(e,t,n){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...n,start:s});if(!o)return e;const d=t(o);s=e.indexOf(o,s)+d.length,e=e.replace(o,d)}}function Kc(e,t){const n=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){n.push({string:e.slice(s),symbol:null});break}const d=e.indexOf(t,o+t.length);if(o>s&&d!==-1&&n.push({string:e.slice(s,o),symbol:null}),d===-1){n.push({string:e.slice(s),symbol:null});break}n.push({string:e.slice(o+t.length,d),symbol:t}),s=d+t.length}return n}function Yc(e){const t=[];let n=0;for(;n<e.length;){const s=Hc(e,n);if(s===-1){t.push({string:e.slice(n),symbol:null});break}const o=Wc(e,s+1);if(o===-1){t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),n=o}return t}function Qc(e){const t=[];let n=0;for(;n<e.length;){const s=Pe(e,["http://","https://"],n);if(s===-1){t.push({string:e.slice(n),symbol:null});break}const o=Pe(e,[" ",`
9
- `],s);if(o===-1){s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),n=o}return t}const As="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Os="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Xc(e){return Is(e,As)}function Jc(e){return Ms(e,As)}function eu(e){return Is(e,Os)}function tu(e){return Ms(e,Os)}function Is(e,t){const n="=",s=t.length;let o=0,d=0;const f=[];for(let v=0;v<e.length;v++){const m=e[v];if(m===n)break;const k=t.indexOf(m);if(k===-1)throw new Error(`Invalid character: ${m}`);d=d<<Math.log2(s)|k,o+=Math.log2(s),o>=8&&(o-=8,f.push(d>>o&255))}return new Uint8Array(f)}function Ms(e,t){const n=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(n);)s-=Math.log2(n),d+=t[o>>s&n-1];return s>0&&(d+=t[o<<Math.log2(n)-s&n-1]),d.length%4!==0&&(d+="=".repeat(4-d.length%4)),d}function ru(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,n=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);n[s]=o}return n}function nu(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function su(e,t){const n=e.split("/").filter(d=>d),s=t.split("/").filter(d=>d);if(n.length!==s.length)return null;const o={};for(let d=0;d<n.length;d++){const f=n[d];if(f.startsWith(":"))o[f.slice(1)]=s[d];else if(f!==s[d])return null}return o}function wr(e,t,n){const s=[];for(const o of n)o!==t&&s.push(e.replace(t,o));return s}function iu(e,t,n,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(v=>v),s),avoid:f.avoid})),s),d=[];for(const f of o){const v=f.variants.filter(k=>k!==f.avoid),m=v.find(k=>e.includes(k));if(m&&(jt(d,wr(e,m,v)),d.length>=n))break}if(d.length<n)for(const f of o){const v=f.variants.find(m=>e.includes(m));if(v&&(jt(d,wr(e,v,f.variants)),d.length>=n))break}return d.slice(0,n)}function au(e,t,n,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,n)}function ou(e,t){const n=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(n,s=>s.toUpperCase()===s?s:t(s))}function cu(e){return e.replace(/<[^>]*>/g,"")}function $s(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const n=e.slice(0,t),s=e.slice(t+1);return{line:n,rest:s}}function uu(e,t={}){return[...e].reduce((n,s)=>n+(t[s]||1),0)}function lu(e,t,n={}){const s=[];let o="",d=0;for(let f=0;f<e.length;f++){const v=e[f],m=n[v]||1;if(o+=v,d+=m,d>t){const{line:k,rest:$}=$s(o);s.push(k),o=$,d=$.split("").map(P=>n[P]||1).reduce((P,ze)=>P+ze,0)}}return o&&s.push(o),s}function du(e,t){const n=[];for(let s=0;s<=e.length;s++)n[s]=[s];for(let s=0;s<=t.length;s++)n[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;n[s][o]=Math.min(n[s-1][o]+1,n[s][o-1]+1,n[s-1][o-1]+d)}return n[e.length][t.length]}function _r(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function fu(e,t,n){return n==="any"?t.some(s=>_r(e,s)):t.every(s=>_r(e,s))}function hu(e){const t={},n=e.match(/([a-z\-]+)="([^"]+)"/g);if(n)for(const s of n){const[o,d]=gr(s,"=");t[o]=d.slice(1,d.length-1)}return t}function Pt(e,t,n=[]){let s="";for(;t<e.length&&(lt(e[t])||n.includes(e[t]));)s+=e[t++];return s}function pu(e,t,n="$",s=":"){for(const o in t)e=Rs(e,o,t[o],n,s);return e=Cs(e),e}function Rs(e,t,n,s="$",o=":"){if(n==="")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}`,n);else{const f=Pt(e,d+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,n)}else e=e.replace(`${s}${t}`,n);d=e.indexOf(`${s}${t}`,d+n.length)}return e}function Cs(e,t="$",n=":"){let s=e.indexOf(t);for(;s!==-1;){const o=Pt(e,s+1);if(e[s+o.length+1]===n)if(e[s+o.length+2]===n)e=e.replace(`${t}${o}${n}${n}`,"");else{const d=Pt(e,s+o.length+2);e=e.replace(`${t}${o}${n}${d}`,d)}s=e.indexOf(t,s+1)}return e}function mu(e,t){let n=e.indexOf("](");for(;n!==-1;){const s=Es(e,"[",n),o=e.indexOf(")",n);if(s!==-1&&o!==-1){const[d,f]=e.slice(s+1,o).split("]("),v=t(d,f);e=e.slice(0,s)+v+e.slice(o+1)}n=e.indexOf("](",n+1)}return e}function Ns(e,t=!0){const n=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return n?(t?"?":"")+n:""}function gu(e){const t={},n=e.split("&");for(const s of n){const[o,d]=s.split("=");o&&d&&(t[o]=decodeURIComponent(d))}return t}function yu(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function vu(e,t){let n=null,s=-1/0;for(const[o,d]of Object.entries(e)){const f=t(d);f>s&&(s=f,n=o)}return n?[n,e[n]]:null}function wu(e,t,n,s){const o=e.find(f=>f[t]===n),d=e.find(f=>f[t]===n+s);o&&d?(o[t]=n+s,d[t]=n):o&&(o[t]=n+s),e.sort((f,v)=>Ct(f[t])-Ct(v[t])),e.forEach((f,v)=>f[t]=v+1)}function _u(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 bu(e,t=":"){return Object.fromEntries(e.map(n=>gr(n,t)).map(n=>n[0]&&n[1]?[ut(n[0]),ut(n[1])]:null).filter(n=>n))}function xu(e,t,n){return Ps(e,t)+Ns(n||{})}function ku(e,t=",",n='"'){const s=[];let o="",d=!1;const f=e.split("");for(const v of f)v===t&&!d?(s.push(o),o=""):v===n&&(!o&&!d||d)?d=!d:o+=v;return s.push(o),s}function Eu(e){return`[${Math.floor(e.progress*100)}%] ${Zt(e.deltaMs)} out of ${Zt(e.totalTimeMs)} (${Zt(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function Su(e,t,n){for(let s=0;s<n;s++){try{if(await e())return!0}catch{}s<n-1&&await l(t)}return!1}function Tu(e,t){const n=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&n.push(e.splice(s,1)[0]);return n}function Au(e){return JSON.parse(JSON.stringify(e))}function Ou(e){return Math.ceil((e||Date.now())/1e3)}function Iu(e){return(e||new Date).toISOString().slice(0,10)}function Mu(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function $u(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function Ru(e){return new Date(e)}function re(e){return String(Math.floor(e)).padStart(2,"0")}function Cu(e){let[t,n]=e.split(":");ge(parseInt(t,10))||(t="0"),ge(parseInt(n,10))||(n="0");let s=Sr(fr(t),0,23),o=Sr(fr(n),0,59);return`${re(s)}:${re(o)}`}function Zt(e){const t=Math.floor(e/36e5);e=e%36e5;const n=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${re(t)}:${re(n)}:${re(s)}`:`${re(n)}:${re(s)}`}function Te(e){return Math.floor((Ue(e)?e.getTime():e)/864e5)}const Nu={today:(e,t)=>re(e)+":"+re(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function ju(e,t){const n=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||Nu,o=Ue(e)?e:new Date(e);if(Te(n)===Te(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(Te(n)-Te(o)===1)return s.yesterday();const d=xr(o);return Te(n)-Te(o)<7?s[d.day]():s.weeks(Math.round((n.getTime()-o.getTime())/6048e5))}const js={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 Ds(e,t){const n=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||js,o=a.Types.isDate(e)?e.getTime():e;let d=(n-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 Du(e,t=js){return Ds(0,{now:e*1e3,labels:t})}function Uu(e,t,n){const s=((n==null?void 0:n.now)??Date.now())-e,o=Math.floor(s/t),d=t/((n==null?void 0:n.precision)??1)-Math.ceil(s%t/((n==null?void 0:n.precision)??1));return{cycles:o,remaining:d}}const br={};function Pu(e,t){return!br[e]||Date.now()>br[e]?(br[e]=Date.now()+t,!0):!1}const Zu={s:1e3,m:6e4,h:36e5,d:864e5};function Bu(e,t,n){return t=Ue(t)?t.getTime():t,n=n?Ue(n)?n.getTime():n:Date.now(),(n-t)/Zu[e]}function Lu(e,t,n,s){s||(s=Date.now());const o=t/n,d=s-e,f=d/t,v=f*n,m=v-d;return{deltaMs:d,progress:o,baseTimeMs:f,totalTimeMs:v,remainingTimeMs:m}}const zu={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function Us(e){return{zeroBasedIndex:e,day:zu[e]}}function xr(e){return Us(e.getDay())}function Vu(e){return xr(new Date(e))}function Fu(e){return e*1e3}function Wu(e){return e*6e4}function Hu(e){return e*36e5}function qu(e){return e*864e5}const Gu={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 Ku(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Gu[n];if(!s)throw Error(`Unknown unit: "${n}"`);return t*s}const Yu={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 Qu(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Yu[n];if(!s)throw Error(`Unknown unit: "${n}"`);return t*s}function Xu(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const kr={};async function Ju(e,t,n){const s=Date.now(),o=kr[e];if(o&&o.validUntil>s)return o.value;const d=await n(),f=s+t;return kr[e]={value:d,validUntil:f},d}function el(e){delete kr[e]}function Ps(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function tl(e,t,n,s,o=!0){const d=e.indexOf(t),f=e.indexOf(n,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+n.length)}function rl(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const n=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:n,hasPunctuation:s,endsWithColon:o}}function nl(e,t="(",n=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(n,o)?(s--,o+=n.length):o++,s<0)return!1;return t===n?s%2===0:s===0}function sl(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 Zs(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),n={};for(const s of t)n[s]=Ae(e[s]);return n}function Bs(e){const t=[];return e.sort((n,s)=>JSON.stringify(Ae(n)).localeCompare(JSON.stringify(Ae(s)))).forEach(n=>t.push(Ae(n))),t}function Ae(e){return Array.isArray(e)?Bs(e):me(e)?Zs(e):e}function Ls(e,t){return JSON.stringify(Ae(e))===JSON.stringify(Ae(t))}function il(...e){for(let t=1;t<e.length;t++)if(!Ls(e[t-1],e[t]))return!1;return!0}function al(e){try{return JSON.parse(e)}catch{return null}}function ol(){let e=0;return{next:()=>e++}}function cl(e){let t=0;return{next:()=>e[t++%e.length]}}function ul(e){let t;return n=>{const s=n===e&&t!==e;return t=n,s}}function ll(e,t,n,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 v=f[n],m=t[v]?v:s;d[m].length>=t[m]?d[s].push(f):d[m].push(f)}return d}function dl(e,t){const n=Object.keys(e),s=Object.keys(t);return{uniqueToA:n.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!n.includes(o))}}function zs(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function fl(e,t){const n=zs(e);return e[n]=t(e[n]),n}function hl(e){return e=e.replace(/\r\n/g,`
10
- `),e=e.replace(/(\w+)\((.+)\)/g,(t,n,s)=>`${n}(${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,n,s)=>`: (${n.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,n,s,o)=>`"${n}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const ye=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],pl=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Vs=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function ml(e,t,n){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(n?" "+n:"");let o=e.substring(0,s),d=e.substring(s);return o===""&&(o="0"),o+"."+d+(n?" "+n:"")}function gl(e,t){const n=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=n?pl:Vs,d=(t==null?void 0:t.precision)??1;if(e<ye[0])return`${e}${s}`;for(let f=0;f<ye.length-1;f++)if(e<ye[f+1])return`${(e/ye[f]).toFixed(d)}${n?" ":""}${o[f]}${s}`;return`${(e/ye[ye.length-1]).toFixed(d)}${n?" ":""}${o[ye.length-1]}${s}`}function Er(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim(),s=Vs.findIndex(o=>o.toLowerCase()===n.toLowerCase());return s===-1?t:t*ye[s]}function Sr(e,t,n){return e<t?t:e>n?n:e}function yl(e,t,n){const s=e+t;return s>n?n:s}function vl(e,t,n){const s=e-t;return s<n?n:s}function wl(e,t){return t(e),e}function _l(e,t){e&&t(e)}function bl(e,t){const n=Object.keys(t);for(const s of n)Array.isArray(t[s])&&Array.isArray(e[s])&&jt(e[s],t[s])}function xl(e){return e.splice(0,e.length),e}function kl(e){for(const t of Object.keys(e))(rs(e[t])||Array.isArray(e[t])&&e[t].every(n=>n==null))&&delete e[t];return e}function El(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||W(t[1])&&Rt(t[1]))&&delete e[t[0]];return e}function Sl(e,t){const n={};for(const[s,o]of Object.entries(e))t(s)&&(n[s]=o);return n}function Tl(e,t){const n={};for(const[s,o]of Object.entries(e))t(o)&&(n[s]=o);return n}function Al(e,t){const n={};for(const s of Object.entries(e))n[s[0]]=t(s[1]);return n}function Ol(e,t){const n=[];let s=0;for(const o of e)n.push(t(o,s++));return n}async function Il(e,t){try{return await e()}catch{throw t}}function Ml(e,t,n){n!=null&&(e[t]=n)}function $l(e,t,n,s){const o=ke(n,s);o!=null&&Ee(e,t,o)}function Rl(e){const t={};for(const[n,s]of Object.entries(e))t[s]=n;return t}function Cl(e){const t=Object.keys(e),n=t.map(v=>e[v].length),s=n.reduce((v,m)=>v*=m);let o=1;const d=[1];for(let v=0;v<n.length-1;v++)o*=n[v],d.push(o);const f=[];for(let v=0;v<s;v++){const m={};for(let k=0;k<t.length;k++){const $=e[t[k]],P=Math.floor(v/d[k])%$.length;m[t[k]]=$[P]}f.push(m)}return f}function Nl(e){return Object.values(e).filter(t=>t).length}function jl(e,t,n){return e+(n?"["+t+"]":(e.length?".":"")+t)}function Bt(e,t,n,s,o){if(!me(t))return t;for(const[d,f]of Object.entries(t)){const v=jl(n,d,s);Array.isArray(f)?o?Bt(e,f,v,!0,o):e[v]=f.map(m=>Bt(Array.isArray(m)?[]:{},m,"",!1,o)):me(f)?Bt(e,f,v,!1,o):e[v]=f}return e}function Dl(e,t=!1,n){return Bt({},e,n||"",!1,t)}function Fs(e){if(!me(e))return e;const t=Array.isArray(e)?[]:{};for(const[n,s]of Object.entries(e))Array.isArray(s)?Ee(t,n,s.map(o=>Fs(o))):Ee(t,n,s);return t}function Ul(e,t,n){return t[e]?t[e]:n}function Ws(e,t){const n={};for(const s of e){const o=t(s);n[o]=s}return n}function Pl(e,t){const n={};for(const s of e){const o=t(s);n[o]||(n[o]=[]),n[o].push(s)}return n}function Zl(e,t){const n=[];for(let s=0;s<e.length;s+=t)n.push(e.slice(s,s+t));return n}function Hs(e,t){const n=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=n)s.push(e.slice(o,o+n));return s}function qs(e,t){const n=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)n.push(e.slice(o*t,o*t+t));return n}function Bl(e,t){const n=Math.ceil(e.length/t);return qs(e,n)}function Ll(e,t){return Object.values(Ws(e,t))}function zl(e,t,n,s,o){const d=t?e.map(t):e,f={};for(const m of d)f[m]=(f[m]||0)+1;const v=s?Gs(f,o?(m,k)=>m[1]-k[1]:(m,k)=>k[1]-m[1]):f;return n?Object.keys(v):v}function Gs(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function Vl(e){const t=[],n=Object.keys(e),s=e[n[0]].length;for(let o=0;o<s;o++){const d={};for(const f of n)d[f]=e[f][o];t.push(d)}return t}function Fl(e,t,n=1){for(const s of e)s[t]+=n}function Wl(e,t,n){for(const s of e)s[t]=n}function Tr(e,t){const n=[];let s=[];return e.forEach((o,d)=>{(d===0||!t(o,e[d-1]))&&(s=[],n.push(s)),s.push(o)}),n}function Hl(){return{map:new Map,keys:[]}}function ql(){return{map:new Map,keys:[]}}function Ks(e,t,n,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,n),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Gl(e,t,n,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,n),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Kl(e,t,n,s,o=100){Ks(e,t,{validUntil:Date.now()+s,data:n},o)}function Yl(e,t){const n=e.map.get(t);return n&&n.validUntil>Date.now()?n.data:null}class ve{constructor(t){this.value=t}static of(t){return new ve(t)}static empty(){return new ve(null)}map(t){return new ve(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(n=>ve.of(n)):Promise.resolve(ve.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=ve;class Ql{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=Ql;class Xl{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=Xl;function Jl(e){return()=>e.forEach(t=>t())}function ed(e,t){return e.reduce((n,s)=>t(n)>t(s)?n:s)}function td(e,t){const n=e.find(s=>s instanceof t);return ve.of(n)}function rd(e,t){return e.filter(n=>n instanceof t)}function nd(e,t){const n=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&n.push(e[o]),t[o]&&n.push(t[o]);return n}function sd(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}class id{constructor(t){this.value=t,this.children=[]}}function ad(e,t,n,s,o=!1){const d=new Map,f=[];e.forEach(m=>{const k=new id(m);d.set(m[t],k)}),e.forEach(m=>{const k=d.get(m[t]);if(!k)return;const $=m[n];if($){const P=d.get($);P&&P.children.push(k)}else f.push(k)});const v=m=>{m.children.sort((k,$)=>{const P=k.value[s],ze=$.value[s];return o?ze-P:P-ze}),m.children.forEach(v)};return f.forEach(v),f}function Ys(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let n=[...e];for(;n.length>1;){const s=[];for(let o=0;o<n.length;o+=2){const d=n[o+1];s.push(t(n[o],d))}n=s}return n[0]}function Ze(...e){const t=e.reduce((o,d)=>o+d.length,0),n=new Uint8Array(t);let s=0;return e.forEach(o=>{n.set(o,s),s+=o.length}),n}function Qs(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function Xs(e){return e[0]===255&&e[1]===216}function Js(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function od(e){return Qs(e)||Xs(e)||Js(e)}function cd(e){return new Uint8Array([e])}function ud(e){return e[0]}function ld(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,t==="LE"),new Uint8Array(n)}function dd(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function fd(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,t==="LE"),new Uint8Array(n)}function hd(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function Ar(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(n)}function pd(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function Be(e,t){const n=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)n[o]=Number(s&0xffn),s>>=8n;return n}for(let o=31;o>=0;o--)n[o]=Number(s&0xffn),s>>=8n;return n}function Le(e,t){let n=0n;if(t==="LE"){for(let s=31;s>=0;s--)n=n<<8n|BigInt(e[s]);return n}for(let s=0;s<32;s++)n=n<<8n|BigInt(e[s]);return n}function md(e,t){const n=[];let s=0;for(const o of t)n.push(e.subarray(s,s+o)),s+=o;return n}function Or(e,t){const n=[];for(let s=0;s<e.length;s+=t)n.push(e.subarray(s,s+t));return n}const ei=[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 gd(e){for(let t=0;t<24;t++){const n=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],v=e[5]^e[15]^e[25]^e[35]^e[45],m=e[6]^e[16]^e[26]^e[36]^e[46],k=e[7]^e[17]^e[27]^e[37]^e[47],$=e[8]^e[18]^e[28]^e[38]^e[48],P=e[9]^e[19]^e[29]^e[39]^e[49],ze=o<<1|d>>>31,Xd=d<<1|o>>>31,ht=$^ze,pt=P^Xd,Jd=f<<1|v>>>31,ef=v<<1|f>>>31,mt=n^Jd,gt=s^ef,tf=m<<1|k>>>31,rf=k<<1|m>>>31,yt=o^tf,vt=d^rf,nf=$<<1|P>>>31,sf=P<<1|$>>>31,wt=f^nf,_t=v^sf,af=n<<1|s>>>31,of=s<<1|n>>>31,bt=m^af,xt=k^of;e[0]^=ht,e[1]^=pt,e[2]^=mt,e[3]^=gt,e[4]^=yt,e[5]^=vt,e[6]^=wt,e[7]^=_t,e[8]^=bt,e[9]^=xt,e[10]^=ht,e[11]^=pt,e[12]^=mt,e[13]^=gt,e[14]^=yt,e[15]^=vt,e[16]^=wt,e[17]^=_t,e[18]^=bt,e[19]^=xt,e[20]^=ht,e[21]^=pt,e[22]^=mt,e[23]^=gt,e[24]^=yt,e[25]^=vt,e[26]^=wt,e[27]^=_t,e[28]^=bt,e[29]^=xt,e[30]^=ht,e[31]^=pt,e[32]^=mt,e[33]^=gt,e[34]^=yt,e[35]^=vt,e[36]^=wt,e[37]^=_t,e[38]^=bt,e[39]^=xt,e[40]^=ht,e[41]^=pt,e[42]^=mt,e[43]^=gt,e[44]^=yt,e[45]^=vt,e[46]^=wt,e[47]^=_t,e[48]^=bt,e[49]^=xt;const Nr=e[0],jr=e[1],Dr=e[2]<<1|e[3]>>>31,Ur=e[3]<<1|e[2]>>>31,Pr=e[5]<<30|e[4]>>>2,Zr=e[4]<<30|e[5]>>>2,Br=e[6]<<28|e[7]>>>4,Lr=e[7]<<28|e[6]>>>4,zr=e[8]<<27|e[9]>>>5,Vr=e[9]<<27|e[8]>>>5,Fr=e[11]<<4|e[10]>>>28,Wr=e[10]<<4|e[11]>>>28,Hr=e[13]<<12|e[12]>>>20,qr=e[12]<<12|e[13]>>>20,Gr=e[14]<<6|e[15]>>>26,Kr=e[15]<<6|e[14]>>>26,Yr=e[17]<<23|e[16]>>>9,Qr=e[16]<<23|e[17]>>>9,Xr=e[18]<<20|e[19]>>>12,Jr=e[19]<<20|e[18]>>>12,en=e[20]<<3|e[21]>>>29,tn=e[21]<<3|e[20]>>>29,rn=e[22]<<10|e[23]>>>22,nn=e[23]<<10|e[22]>>>22,sn=e[25]<<11|e[24]>>>21,an=e[24]<<11|e[25]>>>21,on=e[26]<<25|e[27]>>>7,cn=e[27]<<25|e[26]>>>7,un=e[29]<<7|e[28]>>>25,ln=e[28]<<7|e[29]>>>25,dn=e[31]<<9|e[30]>>>23,fn=e[30]<<9|e[31]>>>23,hn=e[33]<<13|e[32]>>>19,pn=e[32]<<13|e[33]>>>19,mn=e[34]<<15|e[35]>>>17,gn=e[35]<<15|e[34]>>>17,yn=e[36]<<21|e[37]>>>11,vn=e[37]<<21|e[36]>>>11,wn=e[38]<<8|e[39]>>>24,_n=e[39]<<8|e[38]>>>24,bn=e[40]<<18|e[41]>>>14,xn=e[41]<<18|e[40]>>>14,kn=e[42]<<2|e[43]>>>30,En=e[43]<<2|e[42]>>>30,Sn=e[45]<<29|e[44]>>>3,Tn=e[44]<<29|e[45]>>>3,An=e[47]<<24|e[46]>>>8,On=e[46]<<24|e[47]>>>8,In=e[48]<<14|e[49]>>>18,Mn=e[49]<<14|e[48]>>>18;e[0]=Nr^~Hr&sn,e[1]=jr^~qr&an,e[2]=Hr^~sn&yn,e[3]=qr^~an&vn,e[4]=sn^~yn&In,e[5]=an^~vn&Mn,e[6]=yn^~In&Nr,e[7]=vn^~Mn&jr,e[8]=In^~Nr&Hr,e[9]=Mn^~jr&qr,e[10]=Br^~Xr&en,e[11]=Lr^~Jr&tn,e[12]=Xr^~en&hn,e[13]=Jr^~tn&pn,e[14]=en^~hn&Sn,e[15]=tn^~pn&Tn,e[16]=hn^~Sn&Br,e[17]=pn^~Tn&Lr,e[18]=Sn^~Br&Xr,e[19]=Tn^~Lr&Jr,e[20]=Dr^~Gr&on,e[21]=Ur^~Kr&cn,e[22]=Gr^~on&wn,e[23]=Kr^~cn&_n,e[24]=on^~wn&bn,e[25]=cn^~_n&xn,e[26]=wn^~bn&Dr,e[27]=_n^~xn&Ur,e[28]=bn^~Dr&Gr,e[29]=xn^~Ur&Kr,e[30]=zr^~Fr&rn,e[31]=Vr^~Wr&nn,e[32]=Fr^~rn&mn,e[33]=Wr^~nn&gn,e[34]=rn^~mn&An,e[35]=nn^~gn&On,e[36]=mn^~An&zr,e[37]=gn^~On&Vr,e[38]=An^~zr&Fr,e[39]=On^~Vr&Wr,e[40]=Pr^~Yr&un,e[41]=Zr^~Qr&ln,e[42]=Yr^~un&dn,e[43]=Qr^~ln&fn,e[44]=un^~dn&kn,e[45]=ln^~fn&En,e[46]=dn^~kn&Pr,e[47]=fn^~En&Zr,e[48]=kn^~Pr&Yr,e[49]=En^~Zr&Qr,e[0]^=ei[t*2],e[1]^=ei[t*2+1]}}function ti(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}function ri(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[ti(o)]}const n=Or(e,136),s=n[n.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,n[n.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,n.push(o)}return n.map(ti)}function ni(e,t){for(const n of t){for(let s=0;s<34;s+=2)e[s]^=n[s+1],e[s+1]^=n[s];gd(e)}return e}function si(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 ue(e){return si(ni(new Array(50).fill(0),ri(e,1)))}function yd(e){return si(ni(new Array(50).fill(0),ri(e,6)))}function vd(e,t,n){const s=Math.min(e.length,t.length,n/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 n}function wd(e,t){const n=Math.min(e.length,t.length);for(let s=0;s<n;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,n)}function _d(e,t,n,s){const o=Math.floor(t/8),d=t%8;n===1?e[o]|=1<<(s==="BE"?7-d:d):e[o]&=~(1<<(s==="BE"?7-d:d))}function bd(e,t,n){const s=Math.floor(t/8),o=t%8;return e[s]>>(n==="BE"?7-o:o)&1}function xd(e,t,n=0){for(let s=n;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 ii(e,t,n=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(n),s.set(e,t-e.length),s}function kd(e,t,n=0){const s=e.length%t;return s===0?e:ii(e,e.length+t-s,n)}function ai(e,t,n=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(n),s.set(e,0),s}function Ed(e,t,n=0){const s=e.length%t;return s===0?e:ai(e,e.length+t-s,n)}function Sd(e,t){const n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e[s]^t[s%t.length];return n}function Td(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t){return(e%t+t)%t}function dt(e,t){e=R(e,t);let[n,s]=[0n,1n],[o,d]=[t,e];for(;d!==0n;){const f=o/d;[n,s]=[s,n-f*s],[o,d]=[d,o-f*d]}if(o>1n)throw new Error("a is not invertible");return n<0n&&(n+=t),n}function Ad(e,t,n){let s=1n;for(e=R(e,n);t>0;)t%2n===1n&&(s=R(s*e,n)),e=R(e*e,n),t=t/2n;return s}function oi(e,t){return R(e,t)===0n?0n:t%4n===3n?Ad(e,(t+1n)/4n,t):null}const z=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,U=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Lt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,zt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ir(e,t,n){if(t===0n)return[0n,0n];const s=R(3n*e*e*dt(2n*t,n),n),o=R(s*s-2n*e,n),d=R(s*(e-o)-t,n);return[o,d]}function Vt(e,t,n,s,o){if(e===0n&&t===0n)return[n,s];if(n===0n&&s===0n)return[e,t];if(e===n&&t===R(-s,o))return[0n,0n];if(e===n&&t===s)return Ir(e,t,o);const d=R((s-t)*dt(n-e,o),o),f=R(d*d-e-n,o),v=R(d*(e-f)-t,o);return[f,v]}function Od(e){if(e<=0n||e>=U)throw new Error("Invalid private key");return Oe(Lt,zt,e,z)}function Id(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...Be(e[0],"BE")])}function Md(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Le(e.slice(1),"BE"),n=oi(R(t**3n+7n,z),z);if(!n)throw Error("Invalid x: does not correspond to a valid curve point");const s=R(-n,z),o=n%2n===0n;return[t,e[0]===2?o?n:s:o?s:n]}function $d(e){const t=new Uint8Array(20),n=ue(Ze(Be(e[0],"BE"),Be(e[1],"BE")));return t.set(n.subarray(12)),t}function Rd(e){const t=a.Binary.uint8ArrayToHex(e),n=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(n[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function Oe(e,t,n,s){let o=[0n,0n],d=[e,t];const f=n.toString(2);for(const v of f)v==="0"?(d=Vt(o[0],o[1],d[0],d[1],s),o=Ir(o[0],o[1],s)):(o=Vt(o[0],o[1],d[0],d[1],s),d=Ir(d[0],d[1],s));return o}function Cd(e,t,n){return ci(Le(ue(e),"BE"),t,n)}function ci(e,t,n){if(t<=0n||t>=U)throw new Error("Invalid private key");if(n||(n=R(Le(ue(Ze(ue(Be(t,"BE")),Be(e,"BE"))),"BE"),U)),n<=0n||n>=U)throw new Error("Invalid nonce");const s=R(e,U),o=Oe(Lt,zt,n,z),d=R(o[0],U);let f=R((s+R(d,U)*t)*dt(n,U),U);if(d===0n||f===0n)throw new Error("Invalid r or s value");let v=o[1]%2n===0n?27n:28n;return f>U/2n&&(f=U-f,v=v===27n?28n:27n),[d,f,v]}function Nd(e,t,n,s){const o=oi(R(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,v=R(Le(ue(e),"BE"),U),m=Oe(t,f,n,z),k=Oe(Lt,zt,v,z),$=Vt(m[0],m[1],k[0],R(-k[1],z),z);return Oe($[0],$[1],dt(t,U),z)}function jd(e,t,n,s){const o=R(Le(ue(e),"BE"),U),d=dt(s,U),f=R(o*d,U),v=R(n*d,U),m=Oe(Lt,zt,f,z),k=Oe(t[0],t[1],v,z),$=Vt(m[0],m[1],k[0],k[1],z);return n===R($[0],U)}class ui{constructor(t){this.cursor=0,this.buffer=t}read(t){const n=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,n}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=ui;class li{constructor(t){this.buffer=t,this.cursor=0}write(t){const n=Math.min(this.max(),t.max());return this.buffer.set(t.read(n),this.cursor),this.cursor+=n,n}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=li;class Ft{constructor(t,n=0n){this.span=n,this.writer=new li(new Uint8Array(t))}build(){return Ze(Ar(this.span,"LE"),this.writer.buffer)}hash(){const t=Ys(Or(this.writer.buffer,32),(n,s)=>ue(Ze(n,s)));return ue(Ze(Ar(this.span,"LE"),t))}}a.Chunk=Ft;class Mr{constructor(t,n=4096){this.counters=[1],this.capacity=n,this.chunks=[new Ft(n)],this.onChunk=t}static async root(t,n=4096){const s=new r(r.NOOP,n);return await s.append(t),s.finalize()}async append(t,n=0,s=0n){const o=new ui(t);for(;o.max()>0;){this.chunks[n].writer.max()===0&&await this.elevate(n);const d=this.chunks[n].writer.write(o);s?this.chunks[n].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 Ft(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 Ft(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=Mr,r=Mr,Mr.NOOP=async e=>{};class ne{constructor(t,n){if(n<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=n}static fromDecimalString(t,n){let[s,o]=t.split(".");return o=(o||"").padEnd(n,"0").slice(0,n),new ne(BigInt(s+o),n)}add(t){return this.assertSameScale(t),new ne(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new ne(this.value-t.value,this.scale)}multiply(t){return new ne(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const n=this.value/t,s=this.value%t;return[new ne(n,this.scale),new ne(s,this.scale)]}exchange(t,n,s){if(t==="*"){const d=this.value*n.value/10n**BigInt(this.scale);return new ne(d,s)}this.assertSameScale(n);const o=this.value*10n**BigInt(s)/n.value;return new ne(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(),n=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${n}.${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=ne;function Dd(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 Wt(e,t,n,s){const o=e.findIndex(v=>v===`--${t}`||v.startsWith(`--${t}=`)),d=e[o];if(!d)return(n||{})[s||t||""]||null;if(d.includes("="))return d.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(n||{})[s||t||""]||null}function Ud(e,t,n,s){const o=Wt(e,t,n,s);if(!o)return null;try{return Er(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function Pd(e,t,n,s){const o=e.some(m=>m.endsWith("-"+t)),d=Wt(e,t,n,s);if(!d&&o)return!0;if(!d&&!o)return null;const f=["true","1","yes","y","on"],v=["false","0","no","n","off"];if(f.includes(d.toLowerCase()))return!0;if(v.includes(d.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${d}`)}function di(e,t,n,s){const o=Wt(e,t,n,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function Zd(e,t,n,s){const o=di(e,t,n,s);try{return Er(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function fi(e,t){const n=e[t];e.splice(t,1),e.unshift(n)}function Bd(e,t){const n=[...e];return fi(n,t),n}function hi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Ld(e,t){return{x:e.x-t.x,y:e.y-t.y}}function $r(e,t){return{x:e.x*t,y:e.y*t}}function zd(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function pi(e,t,n){return{x:e.x+Math.cos(t)*n,y:e.y+Math.sin(t)*n}}function mi(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function ft(e,t,n="row-first"){const s=[];if(n==="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 Vd(e,t,n){var s,o;return((s=e[t+1])==null?void 0:s[n])&&((o=e[t-1])==null?void 0:o[n])&&!e[t][n-1]&&!e[t][n+1]}function Fd(e,t,n){var s,o;return e[t][n+1]&&e[t][n-1]&&!((s=e[t-1])!=null&&s[n])&&!((o=e[t+1])!=null&&o[n])}function gi(e,t,n){var s;return!((s=e[t-1])!=null&&s[n])}function yi(e,t,n){var s;return!((s=e[t+1])!=null&&s[n])}function vi(e,t,n){return!e[t][n-1]}function wi(e,t,n){return!e[t][n+1]}function Wd(e,t,n){var o,d,f,v,m,k,$,P;const s=[];return e[t][n]?Vd(e,t,n)||Fd(e,t,n)?[]:(!((o=e[t-1])!=null&&o[n-1])&&gi(e,t,n)&&vi(e,t,n)&&s.push({x:t,y:n}),!((d=e[t+1])!=null&&d[n-1])&&yi(e,t,n)&&vi(e,t,n)&&s.push({x:t+1,y:n}),!((f=e[t-1])!=null&&f[n+1])&&gi(e,t,n)&&wi(e,t,n)&&s.push({x:t,y:n+1}),!((v=e[t+1])!=null&&v[n+1])&&yi(e,t,n)&&wi(e,t,n)&&s.push({x:t+1,y:n+1}),s):((m=e[t-1])!=null&&m[n]&&e[t][n-1]&&s.push({x:t,y:n}),(k=e[t+1])!=null&&k[n]&&e[t][n-1]&&s.push({x:t+1,y:n}),($=e[t-1])!=null&&$[n]&&e[t][n+1]&&s.push({x:t,y:n+1}),(P=e[t+1])!=null&&P[n]&&e[t][n+1]&&s.push({x:t+1,y:n+1}),s)}function Hd(e,t,n,s){const o=[{x:0,y:0},{x:n,y:0},{x:0,y:s},{x:n,y:s}];for(let d=0;d<e.length;d++)for(let f=0;f<e[0].length;f++){const v=Wd(e,d,f);for(const m of v)o.some(k=>k.x===m.x&&k.y===m.y)||o.push(m)}return o.map(d=>({x:d.x*t,y:d.y*t}))}function qd(e,t){const n=ft(e,(m,k)=>e[m][k]===0&&e[m][k+1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),s=ft(e,(m,k)=>e[m][k]===0&&e[m][k-1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),o=ft(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m-1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1})),d=ft(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m+1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1}));n.forEach(m=>m.y++),d.forEach(m=>m.x++);const f=Tr([...o,...d],(m,k)=>m.x===k.x&&m.y-1===k.y),v=Tr([...s,...n],(m,k)=>m.y===k.y&&m.x-1===k.x);return[...f,...v].map(m=>({start:m[0],end:ot(m)})).map(m=>({start:$r(m.start,t),end:$r(hi(m.end,{x:m.start.dx,y:m.start.dy}),t)}))}function Gd(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function Kd(e,t){return t.map(n=>Gd(e,n)).sort((n,s)=>n-s)}function _i(e,t,n,s){const o=(s.y-n.y)*(t.x-e.x)-(s.x-n.x)*(t.y-e.y);if(o===0)return null;let d=e.y-n.y,f=e.x-n.x;const v=(s.x-n.x)*d-(s.y-n.y)*f,m=(t.x-e.x)*d-(t.y-e.y)*f;return d=v/o,f=m/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 Rr(e,t,n){const s=[],o=pi(e,n,1e4);for(const d of t){const f=_i(e,o,d.start,d.end);f&&s.push(f)}return s.length?s.reduce((d,f)=>{const v=mi(e,f),m=mi(e,d);return v<m?f:d}):null}function Yd(e,t,n){const s=Kd(e,n),o=[];for(const d of s){const f=Rr(e,t,d-.001),v=Rr(e,t,d+.001);f&&o.push(f),v&&o.push(v)}return o}class Cr{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(n=>n!==t)}}publish(t){this.subscribers.forEach(n=>n(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=Cr;class Qd{constructor(t,n){this.queue=[],this.running=0,this.onProcessed=new Cr,this.onDrained=new Cr,this.concurrency=t,this.capacity=n}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(n=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),n())})})}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=Qd,a.Binary={hexToUint8Array:ru,uint8ArrayToHex:nu,base64ToUint8Array:Xc,uint8ArrayToBase64:Jc,base32ToUint8Array:eu,uint8ArrayToBase32:tu,log2Reduce:Ys,partition:Or,concatBytes:Ze,numberToUint8:cd,uint8ToNumber:ud,numberToUint16:ld,uint16ToNumber:dd,numberToUint32:fd,uint32ToNumber:hd,numberToUint64:Ar,uint64ToNumber:pd,numberToUint256:Be,uint256ToNumber:Le,sliceBytes:md,keccak256:ue,sha3_256:yd,proximity:vd,commonPrefix:wd,setBit:_d,getBit:bd,indexOf:xd,equals:Td,padStart:ii,padStartToMultiple:kd,padEnd:ai,padEndToMultiple:Ed,xorCypher:Sd},a.Elliptic={privateKeyToPublicKey:Od,compressPublicKey:Id,publicKeyFromCompressed:Md,publicKeyToAddress:$d,signMessage:Cd,signHash:ci,verifySignature:jd,recoverPublicKey:Nd,checksumEncode:Rd},a.Random={intBetween:at,floatBetween:Jn,chance:es,signed:Ka,makeSeededRng:ir,point:Qa,procs:Xa},a.Arrays={countUnique:zl,makeUnique:Ll,splitBySize:Zl,splitByCount:Hs,index:Ws,indexCollection:Pl,onlyOrThrow:p,onlyOrNull:g,firstOrThrow:E,firstOrNull:y,shuffle:h,initialize:j,initialize2D:ce,rotate2D:oe,containsShape:it,glue:oc,pluck:sr,pick:ar,pickMany:Ja,pickManyUnique:eo,pickWeighted:no,pickRandomIndices:je,pickGuaranteed:to,last:ot,pipe:ts,makePipe:ro,sortWeighted:so,pushAll:jt,unshiftAll:ic,filterAndRemove:Tu,merge:bl,empty:xl,pushToBucket:rc,unshiftAndLimit:nc,atRolling:sc,group:Tr,createOscillator:cl,organiseWithLimits:ll,tickPlaybook:Dd,getArgument:Wt,getBooleanArgument:Pd,getNumberArgument:Ud,requireStringArgument:di,requireNumberArgument:Zd,bringToFront:Bd,bringToFrontInPlace:fi,findInstance:td,filterInstances:rd,interleave:nd,toggle:sd,createHierarchy:ad,multicall:Jl,maxBy:ed},a.System={sleepMillis:l,forever:lo,scheduleMany:pc,waitFor:Su,expandError:Xo,runAndSetInterval:fo},a.Numbers={make:Er,sum:gc,average:yc,median:vc,getDistanceFromMidpoint:wc,clamp:Sr,range:ps,interpolate:mc,createSequence:ol,increment:yl,decrement:vl,format:gl,fromDecimals:ml,makeStorage:Qu,asMegabytes:ho,convertBytes:po,hexToRgb:mo,rgbToHex:go,haversineDistanceToMeters:yo,roundToNearest:$t,formatDistance:vo,triangularNumber:wo,searchFloat:_o},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:ju,getTimeDelta:Ds,secondsToHumanTime:Du,countCycles:Uu,isoDate:Iu,throttle:Pu,timeSince:Bu,dateTimeSlug:Mu,unixTimestamp:Ou,fromUtcString:$u,fromMillis:Ru,getProgress:Lu,humanizeTime:Zt,humanizeProgress:Eu,createTimeDigits:re,mapDayNumber:Us,getDayInfoFromDate:xr,getDayInfoFromDateTimeString:Vu,seconds:Fu,minutes:Wu,hours:Hu,days:qu,make:Ku,normalizeTime:Cu,absoluteDays:Te},a.Objects={safeParse:al,deleteDeep:oo,getDeep:ke,setDeep:Ee,incrementDeep:io,ensureDeep:ao,replaceDeep:co,getFirstDeep:uo,deepMergeInPlace:Se,deepMerge2:Jo,deepMerge3:ec,mapAllAsync:ac,cloneWithJson:Au,sortObject:Zs,sortArray:Bs,sortAny:Ae,deepEquals:Ls,deepEqualsEvery:il,runOn:wl,ifPresent:_l,zip:hs,zipSum:tc,removeEmptyArrays:kl,removeEmptyValues:El,flatten:Dl,unflatten:Fs,match:Ul,sort:Gs,map:Al,mapIterable:Ol,filterKeys:Sl,filterValues:Tl,rethrow:Il,setSomeOnObject:Ml,setSomeDeep:$l,flip:Rl,getAllPermutations:Cl,countTruthyValues:Nl,transformToArray:Vl,setMulti:Wl,incrementMulti:Fl,createBidirectionalMap:Hl,createTemporalBidirectionalMap:ql,pushToBidirectionalMap:Ks,unshiftToBidirectionalMap:Gl,addToTemporalBidirectionalMap:Kl,getFromTemporalBidirectionalMap:Yl,createStatefulToggle:ul,diffKeys:dl,pickRandomKey:zs,mapRandomKey:fl,fromObjectString:hl,toQueryString:Ns,parseQueryString:gu,hasKey:yu,selectMax:vu,reposition:wu,unwrapSingleKey:_u,parseKeyValues:bu},a.Types={isFunction:cr,isObject:me,isStrictlyObject:De,isEmptyArray:rs,isEmptyObject:bo,isUndefined:or,isString:W,isNumber:ge,isBoolean:ns,isDate:Ue,isBlank:Rt,isId:ur,isIntegerString:ss,isHexString:is,isUrl:ds,isNullable:Go,asString:us,asHexString:No,asSafeString:jo,asIntegerString:Co,asNumber:Ct,asFunction:Do,asInteger:fr,asBoolean:Uo,asDate:Po,asNullableString:Zo,asEmptiableString:Bo,asId:Lo,asTime:zo,asArray:Vo,asObject:Nt,asNullableObject:Fo,asStringMap:Wo,asNumericDictionary:Ho,asUrl:qo,asNullable:Ko,asOptional:Yo,enforceObjectShape:fs,enforceArrayShape:Qo,isPng:Qs,isJpg:Xs,isWebp:Js,isImage:od},a.Strings={tokenizeByCount:Bl,tokenizeByLength:qs,searchHex:Mo,searchSubstring:$o,randomHex:Ro,randomLetter:To,randomAlphanumeric:Ao,randomRichAscii:Oo,randomUnicode:Io,includesAny:_c,slugify:hr,normalForm:xc,enumify:Oc,escapeHtml:Mc,decodeHtmlEntities:Rc,after:pr,afterLast:gs,before:ms,beforeLast:mr,betweenWide:Cc,betweenNarrow:Nc,getPreLine:Xu,containsWord:_r,containsWords:fu,joinUrl:Ps,getFuzzyMatchScore:Dt,sortByFuzzyScore:Ic,splitOnce:gr,splitAll:ys,randomize:Pc,expand:vs,shrinkTrim:ut,capitalize:Ut,decapitalize:ws,csvEscape:Fc,parseCsv:ku,surroundInOut:Ac,getExtension:yr,getBasename:vr,normalizeEmail:jc,normalizeFilename:Dc,parseFilename:Uc,camelToTitle:kc,slugToTitle:Ec,slugToCamel:Sc,joinHumanly:Tc,findWeightedPair:Ss,extractBlock:Ts,extractAllBlocks:qc,replaceBlocks:Gc,indexOfEarliest:Pe,lastIndexOfBefore:Es,parseHtmlAttributes:hu,readNextWord:Pt,resolveVariables:pu,resolveVariableWithDefaultSyntax:Rs,resolveRemainingVariablesWithDefaults:Cs,isLetter:_s,isDigit:bs,isLetterOrDigit:lt,isValidObjectPathCharacter:Lc,insert:zc,indexOfRegex:xs,lineMatches:ks,linesMatchInOrder:Vc,represent:ct,resolveMarkdownLinks:mu,buildUrl:xu,isChinese:bc,replaceBetweenStrings:tl,describeMarkdown:rl,isBalanced:nl,textToFormat:sl,splitFormatting:Kc,splitHashtags:Yc,splitUrls:Qc,route:su,explodeReplace:wr,generateVariants:iu,replaceWord:au,replacePascalCaseWords:ou,stripHtml:cu,breakLine:$s,measureTextWidth:uu,toLines:lu,levenshteinDistance:du},a.Assertions={asEqual:cc,asTrue:uc,asTruthy:lc,asFalse:dc,asFalsy:fc,asEither:hc},a.Cache={get:Ju,invalidate:el},a.Vector={addPoint:hi,subtractPoint:Ld,multiplyPoint:$r,normalizePoint:zd,pushPoint:pi,filterCoordinates:ft,findCorners:Hd,findLines:qd,raycast:Rr,raycastCircle:Yd,getLineIntersectionPoint:_i}})(Cn);const C=Si(Cn);C.Arrays,C.Assertions;const B=C.Binary;C.Cache,C.Dates,C.Elliptic,C.Numbers,C.Objects,C.Pagination,C.Promises,C.Random,C.Strings,C.System,C.Types,C.Optional,C.Vector,C.PubSubChannel,C.Chunk;const Ti=C.MerkleTree;C.FixedPointNumber,C.Lazy,C.AsyncLazy,C.AsyncQueue,C.Uint8ArrayReader,C.Uint8ArrayWriter;const Ai=new TextEncoder,Nn=1,jn=4096,qt=4096,Oi=32;function Dn(a,r){return r=typeof r=="number"?A.FeedIndex.fromBigInt(BigInt(r)):r,new A.Identifier(B.keccak256(B.concatBytes(a.toUint8Array(),r.toUint8Array())))}function Ii(a){const r=a.slice(0,A.Span.LENGTH),i=a.slice(A.Span.LENGTH),c=Mi(i),u=B.keccak256(B.concatBytes(r,c));return new A.Reference(u)}function Mi(a){if(a.length>qt)throw new A.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${qt}`,a);const r=new Uint8Array(qt);return r.set(a),B.log2Reduce(B.partition(r,Oi),(i,c)=>B.keccak256(B.concatBytes(i,c)))}function Un(a){if(a instanceof Uint8Array||(a=Ai.encode(a)),a.length<Nn||a.length>jn)throw new RangeError(`payload size ${a.length} exceeds limits [${Nn}, ${jn}]`);const r=A.Span.fromBigInt(BigInt(a.length)),i=B.concatBytes(r.toUint8Array(),a);return{data:i,span:r,payload:A.Bytes.fromSlice(i,A.Span.LENGTH),address:Ii(i)}}function $i(a,r){return new A.Reference(B.keccak256(B.concatBytes(a.toUint8Array(),r.toUint8Array())))}function Pn(a,r,i){r=new A.Identifier(r),i=new A.PrivateKey(i);const c=$i(r,i.publicKey().address()),u=i.sign(B.concatBytes(r.toUint8Array(),a.address.toUint8Array())),l=B.concatBytes(r.toUint8Array(),u.toUint8Array(),a.data),h=A.Span.fromSlice(a.data,0),p=A.Bytes.fromSlice(a.data,A.Span.LENGTH);return{data:l,identifier:r,signature:u,span:h,payload:p,address:c,owner:i.publicKey().address()}}const Ri=H.getInstance(),Ci=X.getInstance();function Ni(a){return new Promise(r=>{setTimeout(r,a)})}function Gt(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}async function Kt(a,r=3,i=250){return new Promise((c,u)=>{a().then(c).catch(l=>{r>0?(Ri.info(`Retrying... Attempts left: ${r}. Error: ${l.message}`),setTimeout(()=>{Kt(a,r-1,i).then(c).catch(u)},i)):(Ci.handleError(l,"Utils.retryAwaitableAsync"),u(l))})})}class ji{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(r,i){this.events[r]||(this.events[r]=[]),this.events[r].push(i)}off(r,i){if(!this.events[r])return;const c=this.events[r].indexOf(i);c>-1&&this.events[r].splice(c,1)}cleanAll(){this.events={}}emit(r,i){this.events[r]&&this.events[r].forEach(c=>c(i))}}var M;(function(a){a.assertEqual=u=>u;function r(u){}a.assertIs=r;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(p=>typeof u[u[p]]!="number"),h={};for(const p of l)h[p]=u[p];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})(M||(M={}));var Yt;(function(a){a.mergeShapes=(r,i)=>({...r,...i})})(Yt||(Yt={}));const b=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),se=a=>{switch(typeof a){case"undefined":return b.undefined;case"string":return b.string;case"number":return isNaN(a)?b.nan:b.number;case"boolean":return b.boolean;case"function":return b.function;case"bigint":return b.bigint;case"symbol":return b.symbol;case"object":return Array.isArray(a)?b.array:a===null?b.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?b.promise:typeof Map<"u"&&a instanceof Map?b.map:typeof Set<"u"&&a instanceof Set?b.set:typeof Date<"u"&&a instanceof Date?b.date:b.object;default:return b.unknown}},w=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"]),Di=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class F extends Error{get errors(){return this.issues}constructor(r){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=r}format(r){const i=r||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 p=c,g=0;for(;g<h.path.length;){const y=h.path[g];g===h.path.length-1?(p[y]=p[y]||{_errors:[]},p[y]._errors.push(i(h))):p[y]=p[y]||{_errors:[]},p=p[y],g++}}};return u(this),c}static assert(r){if(!(r instanceof F))throw new Error(`Not a ZodError: ${r}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(r=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(r(u))):c.push(r(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}F.create=a=>new F(a);const Ie=(a,r)=>{let i;switch(a.code){case w.invalid_type:a.received===b.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case w.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,M.jsonStringifyReplacer)}`;break;case w.unrecognized_keys:i=`Unrecognized key(s) in object: ${M.joinValues(a.keys,", ")}`;break;case w.invalid_union:i="Invalid input";break;case w.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${M.joinValues(a.options)}`;break;case w.invalid_enum_value:i=`Invalid enum value. Expected ${M.joinValues(a.options)}, received '${a.received}'`;break;case w.invalid_arguments:i="Invalid function arguments";break;case w.invalid_return_type:i="Invalid function return type";break;case w.invalid_date:i="Invalid date";break;case w.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 w.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 w.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 w.custom:i="Invalid input";break;case w.invalid_intersection_types:i="Intersection results could not be merged";break;case w.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case w.not_finite:i="Number must be finite";break;default:i=r.defaultError,M.assertNever(a)}return{message:i}};let Zn=Ie;function Ui(a){Zn=a}function kt(){return Zn}const Et=a=>{const{data:r,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 p="";const g=c.filter(y=>!!y).slice().reverse();for(const y of g)p=y(h,{data:r,defaultError:p}).message;return{...u,path:l,message:p}},Pi=[];function _(a,r){const i=kt(),c=Et({issueData:r,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Ie?void 0:Ie].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(r,i){const c=[];for(const u of i){if(u.status==="aborted")return T;u.status==="dirty"&&r.dirty(),c.push(u.value)}return{status:r.value,value:c}}static async mergeObjectAsync(r,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(r,c)}static mergeObjectSync(r,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"&&r.dirty(),h.status==="dirty"&&r.dirty(),l.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[l.value]=h.value)}return{status:r.value,value:c}}}const T=Object.freeze({status:"aborted"}),Me=a=>({status:"dirty",value:a}),V=a=>({status:"valid",value:a}),Qt=a=>a.status==="aborted",Xt=a=>a.status==="dirty",we=a=>a.status==="valid",Ve=a=>typeof Promise<"u"&&a instanceof Promise;function St(a,r,i,c){if(typeof r=="function"?a!==r||!c:!r.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r.get(a)}function Bn(a,r,i,c,u){if(typeof r=="function"?a!==r||!u:!r.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r.set(a,i),i}typeof SuppressedError=="function"&&SuppressedError;var x;(function(a){a.errToObj=r=>typeof r=="string"?{message:r}:r||{},a.toString=r=>typeof r=="string"?r:r==null?void 0:r.message})(x||(x={}));var Fe,We;class J{constructor(r,i,c,u){this._cachedPath=[],this.parent=r,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 Ln=(a,r)=>{if(we(r))return{success:!0,data:r.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:r,invalid_type_error:i,required_error:c,description:u}=a;if(r&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return r?{errorMap:r,description:u}:{errorMap:(h,p)=>{var g,y;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??p.defaultError}:typeof p.data>"u"?{message:(g=E??c)!==null&&g!==void 0?g:p.defaultError}:h.code!=="invalid_type"?{message:p.defaultError}:{message:(y=E??i)!==null&&y!==void 0?y:p.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(r){return se(r.data)}_getOrReturnCtx(r,i){return i||{common:r.parent.common,data:r.data,parsedType:se(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}_processInputParams(r){return{status:new L,ctx:{common:r.parent.common,data:r.data,parsedType:se(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}}_parseSync(r){const i=this._parse(r);if(Ve(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(r){const i=this._parse(r);return Promise.resolve(i)}parse(r,i){const c=this.safeParse(r,i);if(c.success)return c.data;throw c.error}safeParse(r,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:r,parsedType:se(r)},l=this._parseSync({data:r,path:u.path,parent:u});return Ln(u,l)}"~validate"(r){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:se(r)};if(!this["~standard"].async)try{const l=this._parseSync({data:r,path:[],parent:u});return we(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:r,path:[],parent:u}).then(l=>we(l)?{value:l.value}:{issues:u.common.issues})}async parseAsync(r,i){const c=await this.safeParseAsync(r,i);if(c.success)return c.data;throw c.error}async safeParseAsync(r,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:r,parsedType:se(r)},u=this._parse({data:r,path:c.path,parent:c}),l=await(Ve(u)?u:Promise.resolve(u));return Ln(c,l)}refine(r,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=r(u),p=()=>l.addIssue({code:w.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(g=>g?!0:(p(),!1)):h?!0:(p(),!1)})}refinement(r,i){return this._refinement((c,u)=>r(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(r){return new K({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:r}})}superRefine(r){return this._refinement(r)}constructor(r){this.spa=this.safeParseAsync,this._def=r,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 te.create(this,this._def)}nullable(){return he.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return G.create(this)}promise(){return Ne.create(this,this._def)}or(r){return Ke.create([this,r],this._def)}and(r){return Ye.create(this,r,this._def)}transform(r){return new K({...O(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:r}})}default(r){const i=typeof r=="function"?r:()=>r;return new tt({...O(this._def),innerType:this,defaultValue:i,typeName:S.ZodDefault})}brand(){return new tr({typeName:S.ZodBranded,type:this,...O(this._def)})}catch(r){const i=typeof r=="function"?r:()=>r;return new rt({...O(this._def),innerType:this,catchValue:i,typeName:S.ZodCatch})}describe(r){const i=this.constructor;return new i({...this._def,description:r})}pipe(r){return nt.create(this,r)}readonly(){return st.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Zi=/^c[^\s-]{8,}$/i,Bi=/^[0-9a-z]+$/,Li=/^[0-9A-HJKMNP-TV-Z]{26}$/i,zi=/^[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,Vi=/^[a-z0-9_-]{21}$/i,Fi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Wi=/^[-+]?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)?)??$/,Hi=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,qi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Jt;const Gi=/^(?:(?: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])$/,Ki=/^(?:(?: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])$/,Yi=/^(([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]))$/,Qi=/^(([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])$/,Xi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ji=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,zn="((\\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])))",ea=new RegExp(`^${zn}$`);function Vn(a){let r="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?r=`${r}\\.\\d{${a.precision}}`:a.precision==null&&(r=`${r}(\\.\\d+)?`),r}function ta(a){return new RegExp(`^${Vn(a)}$`)}function Fn(a){let r=`${zn}T${Vn(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${i.join("|")})`,new RegExp(`^${r}$`)}function ra(a,r){return!!((r==="v4"||!r)&&Gi.test(a)||(r==="v6"||!r)&&Yi.test(a))}function na(a,r){if(!Fi.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||r&&u.alg!==r)}catch{return!1}}function sa(a,r){return!!((r==="v4"||!r)&&Ki.test(a)||(r==="v6"||!r)&&Qi.test(a))}class q extends I{_parse(r){if(this._def.coerce&&(r.data=String(r.data)),this._getType(r)!==b.string){const l=this._getOrReturnCtx(r);return _(l,{code:w.invalid_type,expected:b.string,received:l.parsedType}),T}const c=new L;let u;for(const l of this._def.checks)if(l.kind==="min")r.data.length<l.value&&(u=this._getOrReturnCtx(r,u),_(u,{code:w.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="max")r.data.length>l.value&&(u=this._getOrReturnCtx(r,u),_(u,{code:w.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="length"){const h=r.data.length>l.value,p=r.data.length<l.value;(h||p)&&(u=this._getOrReturnCtx(r,u),h?_(u,{code:w.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):p&&_(u,{code:w.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),c.dirty())}else if(l.kind==="email")Hi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"email",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="emoji")Jt||(Jt=new RegExp(qi,"u")),Jt.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"emoji",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="uuid")zi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"uuid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="nanoid")Vi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"nanoid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid")Zi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"cuid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid2")Bi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"cuid2",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="ulid")Li.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"ulid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="url")try{new URL(r.data)}catch{u=this._getOrReturnCtx(r,u),_(u,{validation:"url",code:w.invalid_string,message:l.message}),c.dirty()}else l.kind==="regex"?(l.regex.lastIndex=0,l.regex.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"regex",code:w.invalid_string,message:l.message}),c.dirty())):l.kind==="trim"?r.data=r.data.trim():l.kind==="includes"?r.data.includes(l.value,l.position)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),c.dirty()):l.kind==="toLowerCase"?r.data=r.data.toLowerCase():l.kind==="toUpperCase"?r.data=r.data.toUpperCase():l.kind==="startsWith"?r.data.startsWith(l.value)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:{startsWith:l.value},message:l.message}),c.dirty()):l.kind==="endsWith"?r.data.endsWith(l.value)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:{endsWith:l.value},message:l.message}),c.dirty()):l.kind==="datetime"?Fn(l).test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:"datetime",message:l.message}),c.dirty()):l.kind==="date"?ea.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:"date",message:l.message}),c.dirty()):l.kind==="time"?ta(l).test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{code:w.invalid_string,validation:"time",message:l.message}),c.dirty()):l.kind==="duration"?Wi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"duration",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="ip"?ra(r.data,l.version)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"ip",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="jwt"?na(r.data,l.alg)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"jwt",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="cidr"?sa(r.data,l.version)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"cidr",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="base64"?Xi.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"base64",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="base64url"?Ji.test(r.data)||(u=this._getOrReturnCtx(r,u),_(u,{validation:"base64url",code:w.invalid_string,message:l.message}),c.dirty()):M.assertNever(l);return{status:c.value,value:r.data}}_regex(r,i,c){return this.refinement(u=>r.test(u),{validation:i,code:w.invalid_string,...x.errToObj(c)})}_addCheck(r){return new q({...this._def,checks:[...this._def.checks,r]})}email(r){return this._addCheck({kind:"email",...x.errToObj(r)})}url(r){return this._addCheck({kind:"url",...x.errToObj(r)})}emoji(r){return this._addCheck({kind:"emoji",...x.errToObj(r)})}uuid(r){return this._addCheck({kind:"uuid",...x.errToObj(r)})}nanoid(r){return this._addCheck({kind:"nanoid",...x.errToObj(r)})}cuid(r){return this._addCheck({kind:"cuid",...x.errToObj(r)})}cuid2(r){return this._addCheck({kind:"cuid2",...x.errToObj(r)})}ulid(r){return this._addCheck({kind:"ulid",...x.errToObj(r)})}base64(r){return this._addCheck({kind:"base64",...x.errToObj(r)})}base64url(r){return this._addCheck({kind:"base64url",...x.errToObj(r)})}jwt(r){return this._addCheck({kind:"jwt",...x.errToObj(r)})}ip(r){return this._addCheck({kind:"ip",...x.errToObj(r)})}cidr(r){return this._addCheck({kind:"cidr",...x.errToObj(r)})}datetime(r){var i,c;return typeof r=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:r}):this._addCheck({kind:"datetime",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,offset:(i=r==null?void 0:r.offset)!==null&&i!==void 0?i:!1,local:(c=r==null?void 0:r.local)!==null&&c!==void 0?c:!1,...x.errToObj(r==null?void 0:r.message)})}date(r){return this._addCheck({kind:"date",message:r})}time(r){return typeof r=="string"?this._addCheck({kind:"time",precision:null,message:r}):this._addCheck({kind:"time",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,...x.errToObj(r==null?void 0:r.message)})}duration(r){return this._addCheck({kind:"duration",...x.errToObj(r)})}regex(r,i){return this._addCheck({kind:"regex",regex:r,...x.errToObj(i)})}includes(r,i){return this._addCheck({kind:"includes",value:r,position:i==null?void 0:i.position,...x.errToObj(i==null?void 0:i.message)})}startsWith(r,i){return this._addCheck({kind:"startsWith",value:r,...x.errToObj(i)})}endsWith(r,i){return this._addCheck({kind:"endsWith",value:r,...x.errToObj(i)})}min(r,i){return this._addCheck({kind:"min",value:r,...x.errToObj(i)})}max(r,i){return this._addCheck({kind:"max",value:r,...x.errToObj(i)})}length(r,i){return this._addCheck({kind:"length",value:r,...x.errToObj(i)})}nonempty(r){return this.min(1,x.errToObj(r))}trim(){return new q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(r=>r.kind==="datetime")}get isDate(){return!!this._def.checks.find(r=>r.kind==="date")}get isTime(){return!!this._def.checks.find(r=>r.kind==="time")}get isDuration(){return!!this._def.checks.find(r=>r.kind==="duration")}get isEmail(){return!!this._def.checks.find(r=>r.kind==="email")}get isURL(){return!!this._def.checks.find(r=>r.kind==="url")}get isEmoji(){return!!this._def.checks.find(r=>r.kind==="emoji")}get isUUID(){return!!this._def.checks.find(r=>r.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(r=>r.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(r=>r.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(r=>r.kind==="cuid2")}get isULID(){return!!this._def.checks.find(r=>r.kind==="ulid")}get isIP(){return!!this._def.checks.find(r=>r.kind==="ip")}get isCIDR(){return!!this._def.checks.find(r=>r.kind==="cidr")}get isBase64(){return!!this._def.checks.find(r=>r.kind==="base64")}get isBase64url(){return!!this._def.checks.find(r=>r.kind==="base64url")}get minLength(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxLength(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}}q.create=a=>{var r;return new q({checks:[],typeName:S.ZodString,coerce:(r=a==null?void 0:a.coerce)!==null&&r!==void 0?r:!1,...O(a)})};function ia(a,r){const i=(a.toString().split(".")[1]||"").length,c=(r.toString().split(".")[1]||"").length,u=i>c?i:c,l=parseInt(a.toFixed(u).replace(".","")),h=parseInt(r.toFixed(u).replace(".",""));return l%h/Math.pow(10,u)}class le extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(r){if(this._def.coerce&&(r.data=Number(r.data)),this._getType(r)!==b.number){const l=this._getOrReturnCtx(r);return _(l,{code:w.invalid_type,expected:b.number,received:l.parsedType}),T}let c;const u=new L;for(const l of this._def.checks)l.kind==="int"?M.isInteger(r.data)||(c=this._getOrReturnCtx(r,c),_(c,{code:w.invalid_type,expected:"integer",received:"float",message:l.message}),u.dirty()):l.kind==="min"?(l.inclusive?r.data<l.value:r.data<=l.value)&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.too_small,minimum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?r.data>l.value:r.data>=l.value)&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.too_big,maximum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="multipleOf"?ia(r.data,l.value)!==0&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):l.kind==="finite"?Number.isFinite(r.data)||(c=this._getOrReturnCtx(r,c),_(c,{code:w.not_finite,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:r.data}}gte(r,i){return this.setLimit("min",r,!0,x.toString(i))}gt(r,i){return this.setLimit("min",r,!1,x.toString(i))}lte(r,i){return this.setLimit("max",r,!0,x.toString(i))}lt(r,i){return this.setLimit("max",r,!1,x.toString(i))}setLimit(r,i,c,u){return new le({...this._def,checks:[...this._def.checks,{kind:r,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(r){return new le({...this._def,checks:[...this._def.checks,r]})}int(r){return this._addCheck({kind:"int",message:x.toString(r)})}positive(r){return this._addCheck({kind:"min",value:0,inclusive:!1,message:x.toString(r)})}negative(r){return this._addCheck({kind:"max",value:0,inclusive:!1,message:x.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:0,inclusive:!0,message:x.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:0,inclusive:!0,message:x.toString(r)})}multipleOf(r,i){return this._addCheck({kind:"multipleOf",value:r,message:x.toString(i)})}finite(r){return this._addCheck({kind:"finite",message:x.toString(r)})}safe(r){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:x.toString(r)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:x.toString(r)})}get minValue(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxValue(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}get isInt(){return!!this._def.checks.find(r=>r.kind==="int"||r.kind==="multipleOf"&&M.isInteger(r.value))}get isFinite(){let r=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"&&(r===null||c.value<r)&&(r=c.value)}return Number.isFinite(i)&&Number.isFinite(r)}}le.create=a=>new le({checks:[],typeName:S.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class de extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(r){if(this._def.coerce)try{r.data=BigInt(r.data)}catch{return this._getInvalidInput(r)}if(this._getType(r)!==b.bigint)return this._getInvalidInput(r);let c;const u=new L;for(const l of this._def.checks)l.kind==="min"?(l.inclusive?r.data<l.value:r.data<=l.value)&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.too_small,type:"bigint",minimum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?r.data>l.value:r.data>=l.value)&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.too_big,type:"bigint",maximum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="multipleOf"?r.data%l.value!==BigInt(0)&&(c=this._getOrReturnCtx(r,c),_(c,{code:w.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:r.data}}_getInvalidInput(r){const i=this._getOrReturnCtx(r);return _(i,{code:w.invalid_type,expected:b.bigint,received:i.parsedType}),T}gte(r,i){return this.setLimit("min",r,!0,x.toString(i))}gt(r,i){return this.setLimit("min",r,!1,x.toString(i))}lte(r,i){return this.setLimit("max",r,!0,x.toString(i))}lt(r,i){return this.setLimit("max",r,!1,x.toString(i))}setLimit(r,i,c,u){return new de({...this._def,checks:[...this._def.checks,{kind:r,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(r){return new de({...this._def,checks:[...this._def.checks,r]})}positive(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:x.toString(r)})}negative(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:x.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:x.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:x.toString(r)})}multipleOf(r,i){return this._addCheck({kind:"multipleOf",value:r,message:x.toString(i)})}get minValue(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxValue(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}}de.create=a=>{var r;return new de({checks:[],typeName:S.ZodBigInt,coerce:(r=a==null?void 0:a.coerce)!==null&&r!==void 0?r:!1,...O(a)})};class He extends I{_parse(r){if(this._def.coerce&&(r.data=!!r.data),this._getType(r)!==b.boolean){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.boolean,received:c.parsedType}),T}return V(r.data)}}He.create=a=>new He({typeName:S.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class _e extends I{_parse(r){if(this._def.coerce&&(r.data=new Date(r.data)),this._getType(r)!==b.date){const l=this._getOrReturnCtx(r);return _(l,{code:w.invalid_type,expected:b.date,received:l.parsedType}),T}if(isNaN(r.data.getTime())){const l=this._getOrReturnCtx(r);return _(l,{code:w.invalid_date}),T}const c=new L;let u;for(const l of this._def.checks)l.kind==="min"?r.data.getTime()<l.value&&(u=this._getOrReturnCtx(r,u),_(u,{code:w.too_small,message:l.message,inclusive:!0,exact:!1,minimum:l.value,type:"date"}),c.dirty()):l.kind==="max"?r.data.getTime()>l.value&&(u=this._getOrReturnCtx(r,u),_(u,{code:w.too_big,message:l.message,inclusive:!0,exact:!1,maximum:l.value,type:"date"}),c.dirty()):M.assertNever(l);return{status:c.value,value:new Date(r.data.getTime())}}_addCheck(r){return new _e({...this._def,checks:[...this._def.checks,r]})}min(r,i){return this._addCheck({kind:"min",value:r.getTime(),message:x.toString(i)})}max(r,i){return this._addCheck({kind:"max",value:r.getTime(),message:x.toString(i)})}get minDate(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r!=null?new Date(r):null}get maxDate(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r!=null?new Date(r):null}}_e.create=a=>new _e({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:S.ZodDate,...O(a)});class Tt extends I{_parse(r){if(this._getType(r)!==b.symbol){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.symbol,received:c.parsedType}),T}return V(r.data)}}Tt.create=a=>new Tt({typeName:S.ZodSymbol,...O(a)});class qe extends I{_parse(r){if(this._getType(r)!==b.undefined){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.undefined,received:c.parsedType}),T}return V(r.data)}}qe.create=a=>new qe({typeName:S.ZodUndefined,...O(a)});class Ge extends I{_parse(r){if(this._getType(r)!==b.null){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.null,received:c.parsedType}),T}return V(r.data)}}Ge.create=a=>new Ge({typeName:S.ZodNull,...O(a)});class $e extends I{constructor(){super(...arguments),this._any=!0}_parse(r){return V(r.data)}}$e.create=a=>new $e({typeName:S.ZodAny,...O(a)});class be extends I{constructor(){super(...arguments),this._unknown=!0}_parse(r){return V(r.data)}}be.create=a=>new be({typeName:S.ZodUnknown,...O(a)});class ie extends I{_parse(r){const i=this._getOrReturnCtx(r);return _(i,{code:w.invalid_type,expected:b.never,received:i.parsedType}),T}}ie.create=a=>new ie({typeName:S.ZodNever,...O(a)});class At extends I{_parse(r){if(this._getType(r)!==b.undefined){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.void,received:c.parsedType}),T}return V(r.data)}}At.create=a=>new At({typeName:S.ZodVoid,...O(a)});class G extends I{_parse(r){const{ctx:i,status:c}=this._processInputParams(r),u=this._def;if(i.parsedType!==b.array)return _(i,{code:w.invalid_type,expected:b.array,received:i.parsedType}),T;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,p=i.data.length<u.exactLength.value;(h||p)&&(_(i,{code:h?w.too_big:w.too_small,minimum:p?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&&(_(i,{code:w.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&&(_(i,{code:w.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,p)=>u.type._parseAsync(new J(i,h,i.path,p)))).then(h=>L.mergeArray(c,h));const l=[...i.data].map((h,p)=>u.type._parseSync(new J(i,h,i.path,p)));return L.mergeArray(c,l)}get element(){return this._def.type}min(r,i){return new G({...this._def,minLength:{value:r,message:x.toString(i)}})}max(r,i){return new G({...this._def,maxLength:{value:r,message:x.toString(i)}})}length(r,i){return new G({...this._def,exactLength:{value:r,message:x.toString(i)}})}nonempty(r){return this.min(1,r)}}G.create=(a,r)=>new G({type:a,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...O(r)});function Re(a){if(a instanceof N){const r={};for(const i in a.shape){const c=a.shape[i];r[i]=te.create(Re(c))}return new N({...a._def,shape:()=>r})}else return a instanceof G?new G({...a._def,type:Re(a.element)}):a instanceof te?te.create(Re(a.unwrap())):a instanceof he?he.create(Re(a.unwrap())):a instanceof ee?ee.create(a.items.map(r=>Re(r))):a}class N 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 r=this._def.shape(),i=M.objectKeys(r);return this._cached={shape:r,keys:i}}_parse(r){if(this._getType(r)!==b.object){const y=this._getOrReturnCtx(r);return _(y,{code:w.invalid_type,expected:b.object,received:y.parsedType}),T}const{status:c,ctx:u}=this._processInputParams(r),{shape:l,keys:h}=this._getCached(),p=[];if(!(this._def.catchall instanceof ie&&this._def.unknownKeys==="strip"))for(const y in u.data)h.includes(y)||p.push(y);const g=[];for(const y of h){const E=l[y],j=u.data[y];g.push({key:{status:"valid",value:y},value:E._parse(new J(u,j,u.path,y)),alwaysSet:y in u.data})}if(this._def.catchall instanceof ie){const y=this._def.unknownKeys;if(y==="passthrough")for(const E of p)g.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(y==="strict")p.length>0&&(_(u,{code:w.unrecognized_keys,keys:p}),c.dirty());else if(y!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const y=this._def.catchall;for(const E of p){const j=u.data[E];g.push({key:{status:"valid",value:E},value:y._parse(new J(u,j,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const y=[];for(const E of g){const j=await E.key,oe=await E.value;y.push({key:j,value:oe,alwaysSet:E.alwaysSet})}return y}).then(y=>L.mergeObjectSync(c,y)):L.mergeObjectSync(c,g)}get shape(){return this._def.shape()}strict(r){return x.errToObj,new N({...this._def,unknownKeys:"strict",...r!==void 0?{errorMap:(i,c)=>{var u,l,h,p;const g=(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:(p=x.errToObj(r).message)!==null&&p!==void 0?p:g}:{message:g}}}:{}})}strip(){return new N({...this._def,unknownKeys:"strip"})}passthrough(){return new N({...this._def,unknownKeys:"passthrough"})}extend(r){return new N({...this._def,shape:()=>({...this._def.shape(),...r})})}merge(r){return new N({unknownKeys:r._def.unknownKeys,catchall:r._def.catchall,shape:()=>({...this._def.shape(),...r._def.shape()}),typeName:S.ZodObject})}setKey(r,i){return this.augment({[r]:i})}catchall(r){return new N({...this._def,catchall:r})}pick(r){const i={};return M.objectKeys(r).forEach(c=>{r[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new N({...this._def,shape:()=>i})}omit(r){const i={};return M.objectKeys(this.shape).forEach(c=>{r[c]||(i[c]=this.shape[c])}),new N({...this._def,shape:()=>i})}deepPartial(){return Re(this)}partial(r){const i={};return M.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];r&&!r[c]?i[c]=u:i[c]=u.optional()}),new N({...this._def,shape:()=>i})}required(r){const i={};return M.objectKeys(this.shape).forEach(c=>{if(r&&!r[c])i[c]=this.shape[c];else{let l=this.shape[c];for(;l instanceof te;)l=l._def.innerType;i[c]=l}}),new N({...this._def,shape:()=>i})}keyof(){return Wn(M.objectKeys(this.shape))}}N.create=(a,r)=>new N({shape:()=>a,unknownKeys:"strip",catchall:ie.create(),typeName:S.ZodObject,...O(r)}),N.strictCreate=(a,r)=>new N({shape:()=>a,unknownKeys:"strict",catchall:ie.create(),typeName:S.ZodObject,...O(r)}),N.lazycreate=(a,r)=>new N({shape:a,unknownKeys:"strip",catchall:ie.create(),typeName:S.ZodObject,...O(r)});class Ke extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c=this._def.options;function u(l){for(const p of l)if(p.result.status==="valid")return p.result;for(const p of l)if(p.result.status==="dirty")return i.common.issues.push(...p.ctx.common.issues),p.result;const h=l.map(p=>new F(p.ctx.common.issues));return _(i,{code:w.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 g of c){const y={...i,common:{...i.common,issues:[]},parent:null},E=g._parseSync({data:i.data,path:i.path,parent:y});if(E.status==="valid")return E;E.status==="dirty"&&!l&&(l={result:E,ctx:y}),y.common.issues.length&&h.push(y.common.issues)}if(l)return i.common.issues.push(...l.ctx.common.issues),l.result;const p=h.map(g=>new F(g));return _(i,{code:w.invalid_union,unionErrors:p}),T}}get options(){return this._def.options}}Ke.create=(a,r)=>new Ke({options:a,typeName:S.ZodUnion,...O(r)});const ae=a=>a instanceof Xe?ae(a.schema):a instanceof K?ae(a.innerType()):a instanceof Je?[a.value]:a instanceof fe?a.options:a instanceof et?M.objectValues(a.enum):a instanceof tt?ae(a._def.innerType):a instanceof qe?[void 0]:a instanceof Ge?[null]:a instanceof te?[void 0,...ae(a.unwrap())]:a instanceof he?[null,...ae(a.unwrap())]:a instanceof tr||a instanceof st?ae(a.unwrap()):a instanceof rt?ae(a._def.innerType):[];class Ot extends I{_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==b.object)return _(i,{code:w.invalid_type,expected:b.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}):(_(i,{code:w.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(r,i,c){const u=new Map;for(const l of i){const h=ae(l.shape[r]);if(!h.length)throw new Error(`A discriminator value for key \`${r}\` could not be extracted from all schema options`);for(const p of h){if(u.has(p))throw new Error(`Discriminator property ${String(r)} has duplicate value ${String(p)}`);u.set(p,l)}}return new Ot({typeName:S.ZodDiscriminatedUnion,discriminator:r,options:i,optionsMap:u,...O(c)})}}function er(a,r){const i=se(a),c=se(r);if(a===r)return{valid:!0,data:a};if(i===b.object&&c===b.object){const u=M.objectKeys(r),l=M.objectKeys(a).filter(p=>u.indexOf(p)!==-1),h={...a,...r};for(const p of l){const g=er(a[p],r[p]);if(!g.valid)return{valid:!1};h[p]=g.data}return{valid:!0,data:h}}else if(i===b.array&&c===b.array){if(a.length!==r.length)return{valid:!1};const u=[];for(let l=0;l<a.length;l++){const h=a[l],p=r[l],g=er(h,p);if(!g.valid)return{valid:!1};u.push(g.data)}return{valid:!0,data:u}}else return i===b.date&&c===b.date&&+a==+r?{valid:!0,data:a}:{valid:!1}}class Ye extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r),u=(l,h)=>{if(Qt(l)||Qt(h))return T;const p=er(l.value,h.value);return p.valid?((Xt(l)||Xt(h))&&i.dirty(),{status:i.value,value:p.data}):(_(c,{code:w.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}))}}Ye.create=(a,r,i)=>new Ye({left:a,right:r,typeName:S.ZodIntersection,...O(i)});class ee extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==b.array)return _(c,{code:w.invalid_type,expected:b.array,received:c.parsedType}),T;if(c.data.length<this._def.items.length)return _(c,{code:w.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&c.data.length>this._def.items.length&&(_(c,{code:w.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const l=[...c.data].map((h,p)=>{const g=this._def.items[p]||this._def.rest;return g?g._parse(new J(c,h,c.path,p)):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(r){return new ee({...this._def,rest:r})}}ee.create=(a,r)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ee({items:a,typeName:S.ZodTuple,rest:null,...O(r)})};class Qe extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==b.object)return _(c,{code:w.invalid_type,expected:b.object,received:c.parsedType}),T;const u=[],l=this._def.keyType,h=this._def.valueType;for(const p in c.data)u.push({key:l._parse(new J(c,p,c.path,p)),value:h._parse(new J(c,c.data[p],c.path,p)),alwaysSet:p in c.data});return c.common.async?L.mergeObjectAsync(i,u):L.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(r,i,c){return i instanceof I?new Qe({keyType:r,valueType:i,typeName:S.ZodRecord,...O(c)}):new Qe({keyType:q.create(),valueType:r,typeName:S.ZodRecord,...O(i)})}}class It extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==b.map)return _(c,{code:w.invalid_type,expected:b.map,received:c.parsedType}),T;const u=this._def.keyType,l=this._def.valueType,h=[...c.data.entries()].map(([p,g],y)=>({key:u._parse(new J(c,p,c.path,[y,"key"])),value:l._parse(new J(c,g,c.path,[y,"value"]))}));if(c.common.async){const p=new Map;return Promise.resolve().then(async()=>{for(const g of h){const y=await g.key,E=await g.value;if(y.status==="aborted"||E.status==="aborted")return T;(y.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(y.value,E.value)}return{status:i.value,value:p}})}else{const p=new Map;for(const g of h){const y=g.key,E=g.value;if(y.status==="aborted"||E.status==="aborted")return T;(y.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(y.value,E.value)}return{status:i.value,value:p}}}}It.create=(a,r,i)=>new It({valueType:r,keyType:a,typeName:S.ZodMap,...O(i)});class xe extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==b.set)return _(c,{code:w.invalid_type,expected:b.set,received:c.parsedType}),T;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(_(c,{code:w.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&&(_(c,{code:w.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(g){const y=new Set;for(const E of g){if(E.status==="aborted")return T;E.status==="dirty"&&i.dirty(),y.add(E.value)}return{status:i.value,value:y}}const p=[...c.data.values()].map((g,y)=>l._parse(new J(c,g,c.path,y)));return c.common.async?Promise.all(p).then(g=>h(g)):h(p)}min(r,i){return new xe({...this._def,minSize:{value:r,message:x.toString(i)}})}max(r,i){return new xe({...this._def,maxSize:{value:r,message:x.toString(i)}})}size(r,i){return this.min(r,i).max(r,i)}nonempty(r){return this.min(1,r)}}xe.create=(a,r)=>new xe({valueType:a,minSize:null,maxSize:null,typeName:S.ZodSet,...O(r)});class Ce extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==b.function)return _(i,{code:w.invalid_type,expected:b.function,received:i.parsedType}),T;function c(p,g){return Et({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,kt(),Ie].filter(y=>!!y),issueData:{code:w.invalid_arguments,argumentsError:g}})}function u(p,g){return Et({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,kt(),Ie].filter(y=>!!y),issueData:{code:w.invalid_return_type,returnTypeError:g}})}const l={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Ne){const p=this;return V(async function(...g){const y=new F([]),E=await p._def.args.parseAsync(g,l).catch(ce=>{throw y.addIssue(c(g,ce)),y}),j=await Reflect.apply(h,this,E);return await p._def.returns._def.type.parseAsync(j,l).catch(ce=>{throw y.addIssue(u(j,ce)),y})})}else{const p=this;return V(function(...g){const y=p._def.args.safeParse(g,l);if(!y.success)throw new F([c(g,y.error)]);const E=Reflect.apply(h,this,y.data),j=p._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(...r){return new Ce({...this._def,args:ee.create(r).rest(be.create())})}returns(r){return new Ce({...this._def,returns:r})}implement(r){return this.parse(r)}strictImplement(r){return this.parse(r)}static create(r,i,c){return new Ce({args:r||ee.create([]).rest(be.create()),returns:i||be.create(),typeName:S.ZodFunction,...O(c)})}}class Xe extends I{get schema(){return this._def.getter()}_parse(r){const{ctx:i}=this._processInputParams(r);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}Xe.create=(a,r)=>new Xe({getter:a,typeName:S.ZodLazy,...O(r)});class Je extends I{_parse(r){if(r.data!==this._def.value){const i=this._getOrReturnCtx(r);return _(i,{received:i.data,code:w.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:r.data}}get value(){return this._def.value}}Je.create=(a,r)=>new Je({value:a,typeName:S.ZodLiteral,...O(r)});function Wn(a,r){return new fe({values:a,typeName:S.ZodEnum,...O(r)})}class fe extends I{constructor(){super(...arguments),Fe.set(this,void 0)}_parse(r){if(typeof r.data!="string"){const i=this._getOrReturnCtx(r),c=this._def.values;return _(i,{expected:M.joinValues(c),received:i.parsedType,code:w.invalid_type}),T}if(St(this,Fe)||Bn(this,Fe,new Set(this._def.values)),!St(this,Fe).has(r.data)){const i=this._getOrReturnCtx(r),c=this._def.values;return _(i,{received:i.data,code:w.invalid_enum_value,options:c}),T}return V(r.data)}get options(){return this._def.values}get enum(){const r={};for(const i of this._def.values)r[i]=i;return r}get Values(){const r={};for(const i of this._def.values)r[i]=i;return r}get Enum(){const r={};for(const i of this._def.values)r[i]=i;return r}extract(r,i=this._def){return fe.create(r,{...this._def,...i})}exclude(r,i=this._def){return fe.create(this.options.filter(c=>!r.includes(c)),{...this._def,...i})}}Fe=new WeakMap,fe.create=Wn;class et extends I{constructor(){super(...arguments),We.set(this,void 0)}_parse(r){const i=M.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(r);if(c.parsedType!==b.string&&c.parsedType!==b.number){const u=M.objectValues(i);return _(c,{expected:M.joinValues(u),received:c.parsedType,code:w.invalid_type}),T}if(St(this,We)||Bn(this,We,new Set(M.getValidEnumValues(this._def.values))),!St(this,We).has(r.data)){const u=M.objectValues(i);return _(c,{received:c.data,code:w.invalid_enum_value,options:u}),T}return V(r.data)}get enum(){return this._def.values}}We=new WeakMap,et.create=(a,r)=>new et({values:a,typeName:S.ZodNativeEnum,...O(r)});class Ne extends I{unwrap(){return this._def.type}_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==b.promise&&i.common.async===!1)return _(i,{code:w.invalid_type,expected:b.promise,received:i.parsedType}),T;const c=i.parsedType===b.promise?i.data:Promise.resolve(i.data);return V(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Ne.create=(a,r)=>new Ne({type:a,typeName:S.ZodPromise,...O(r)});class K extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(r){const{status:i,ctx:c}=this._processInputParams(r),u=this._def.effect||null,l={addIssue:h=>{_(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 p=>{if(i.value==="aborted")return T;const g=await this._def.schema._parseAsync({data:p,path:c.path,parent:c});return g.status==="aborted"?T:g.status==="dirty"||i.value==="dirty"?Me(g.value):g});{if(i.value==="aborted")return T;const p=this._def.schema._parseSync({data:h,path:c.path,parent:c});return p.status==="aborted"?T:p.status==="dirty"||i.value==="dirty"?Me(p.value):p}}if(u.type==="refinement"){const h=p=>{const g=u.refinement(p,l);if(c.common.async)return Promise.resolve(g);if(g instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return p};if(c.common.async===!1){const p=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return p.status==="aborted"?T:(p.status==="dirty"&&i.dirty(),h(p.value),{status:i.value,value:p.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(p=>p.status==="aborted"?T:(p.status==="dirty"&&i.dirty(),h(p.value).then(()=>({status:i.value,value:p.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(!we(h))return h;const p=u.transform(h.value,l);if(p instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:p}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>we(h)?Promise.resolve(u.transform(h.value,l)).then(p=>({status:i.value,value:p})):h);M.assertNever(u)}}K.create=(a,r,i)=>new K({schema:a,typeName:S.ZodEffects,effect:r,...O(i)}),K.createWithPreprocess=(a,r,i)=>new K({schema:r,effect:{type:"preprocess",transform:a},typeName:S.ZodEffects,...O(i)});class te extends I{_parse(r){return this._getType(r)===b.undefined?V(void 0):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}te.create=(a,r)=>new te({innerType:a,typeName:S.ZodOptional,...O(r)});class he extends I{_parse(r){return this._getType(r)===b.null?V(null):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}he.create=(a,r)=>new he({innerType:a,typeName:S.ZodNullable,...O(r)});class tt extends I{_parse(r){const{ctx:i}=this._processInputParams(r);let c=i.data;return i.parsedType===b.undefined&&(c=this._def.defaultValue()),this._def.innerType._parse({data:c,path:i.path,parent:i})}removeDefault(){return this._def.innerType}}tt.create=(a,r)=>new tt({innerType:a,typeName:S.ZodDefault,defaultValue:typeof r.default=="function"?r.default:()=>r.default,...O(r)});class rt extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return Ve(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}}rt.create=(a,r)=>new rt({innerType:a,typeName:S.ZodCatch,catchValue:typeof r.catch=="function"?r.catch:()=>r.catch,...O(r)});class Mt extends I{_parse(r){if(this._getType(r)!==b.nan){const c=this._getOrReturnCtx(r);return _(c,{code:w.invalid_type,expected:b.nan,received:c.parsedType}),T}return{status:"valid",value:r.data}}}Mt.create=a=>new Mt({typeName:S.ZodNaN,...O(a)});const aa=Symbol("zod_brand");class tr extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class nt extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);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(),Me(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(r,i){return new nt({in:r,out:i,typeName:S.ZodPipeline})}}class st extends I{_parse(r){const i=this._def.innerType._parse(r),c=u=>(we(u)&&(u.value=Object.freeze(u.value)),u);return Ve(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}st.create=(a,r)=>new st({innerType:a,typeName:S.ZodReadonly,...O(r)});function Hn(a,r={},i){return a?$e.create().superRefine((c,u)=>{var l,h;if(!a(c)){const p=typeof r=="function"?r(c):typeof r=="string"?{message:r}:r,g=(h=(l=p.fatal)!==null&&l!==void 0?l:i)!==null&&h!==void 0?h:!0,y=typeof p=="string"?{message:p}:p;u.addIssue({code:"custom",...y,fatal:g})}}):$e.create()}const oa={object:N.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 ca=(a,r={message:`Input not instance of ${a.name}`})=>Hn(i=>i instanceof a,r),qn=q.create,Gn=le.create,ua=Mt.create,la=de.create,Kn=He.create,da=_e.create,fa=Tt.create,ha=qe.create,pa=Ge.create,ma=$e.create,ga=be.create,ya=ie.create,va=At.create,wa=G.create,_a=N.create,ba=N.strictCreate,xa=Ke.create,ka=Ot.create,Ea=Ye.create,Sa=ee.create,Ta=Qe.create,Aa=It.create,Oa=xe.create,Ia=Ce.create,Ma=Xe.create,$a=Je.create,Ra=fe.create,Ca=et.create,Na=Ne.create,Yn=K.create,ja=te.create,Da=he.create,Ua=K.createWithPreprocess,Pa=nt.create;var D=Object.freeze({__proto__:null,defaultErrorMap:Ie,setErrorMap:Ui,getErrorMap:kt,makeIssue:Et,EMPTY_PATH:Pi,addIssueToContext:_,ParseStatus:L,INVALID:T,DIRTY:Me,OK:V,isAborted:Qt,isDirty:Xt,isValid:we,isAsync:Ve,get util(){return M},get objectUtil(){return Yt},ZodParsedType:b,getParsedType:se,ZodType:I,datetimeRegex:Fn,ZodString:q,ZodNumber:le,ZodBigInt:de,ZodBoolean:He,ZodDate:_e,ZodSymbol:Tt,ZodUndefined:qe,ZodNull:Ge,ZodAny:$e,ZodUnknown:be,ZodNever:ie,ZodVoid:At,ZodArray:G,ZodObject:N,ZodUnion:Ke,ZodDiscriminatedUnion:Ot,ZodIntersection:Ye,ZodTuple:ee,ZodRecord:Qe,ZodMap:It,ZodSet:xe,ZodFunction:Ce,ZodLazy:Xe,ZodLiteral:Je,ZodEnum:fe,ZodNativeEnum:et,ZodPromise:Ne,ZodEffects:K,ZodTransformer:K,ZodOptional:te,ZodNullable:he,ZodDefault:tt,ZodCatch:rt,ZodNaN:Mt,BRAND:aa,ZodBranded:tr,ZodPipeline:nt,ZodReadonly:st,custom:Hn,Schema:I,ZodSchema:I,late:oa,get ZodFirstPartyTypeKind(){return S},coerce:{string:a=>q.create({...a,coerce:!0}),number:a=>le.create({...a,coerce:!0}),boolean:a=>He.create({...a,coerce:!0}),bigint:a=>de.create({...a,coerce:!0}),date:a=>_e.create({...a,coerce:!0})},any:ma,array:wa,bigint:la,boolean:Kn,date:da,discriminatedUnion:ka,effect:Yn,enum:Ra,function:Ia,instanceof:ca,intersection:Ea,lazy:Ma,literal:$a,map:Aa,nan:ua,nativeEnum:Ca,never:ya,null:pa,nullable:Da,number:Gn,object:_a,oboolean:()=>Kn().optional(),onumber:()=>Gn().optional(),optional:ja,ostring:()=>qn().optional(),pipeline:Pa,preprocess:Ua,promise:Na,record:Ta,set:Oa,strictObject:ba,string:qn,symbol:fa,transformer:Yn,tuple:Sa,undefined:ha,union:xa,unknown:ga,void:va,NEVER:T,ZodIssueCode:w,quotelessJson:Di,ZodError:F}),rr=(a=>(a.TEXT="text",a.THREAD="thread",a.REACTION="reaction",a))(rr||{});const pe=H.getInstance(),Za=["id","targetMessageId","type","message","username","address","timestamp","signature","index","chatTopic","userTopic","additionalProps"],nr=D.object({id:D.string(),targetMessageId:D.string().optional(),type:D.nativeEnum(rr),message:D.string(),username:D.string(),address:D.string(),timestamp:D.number(),signature:D.string(),index:D.number(),chatTopic:D.string(),userTopic:D.string(),additionalProps:D.record(D.any()).optional()}).refine(a=>!a.additionalProps||Object.keys(a.additionalProps).length===0?!0:Fa(a.additionalProps).isValid,{message:"Invalid additional properties in message"}),Ba=D.object({reference:D.string(),timestamp:D.number()}),La=D.object({message:nr,messageStateRefs:D.array(Ba).nullable()});function Qn(a){const r=La.safeParse(a);return r.success?Xn(a.message)?!0:(pe.warn("Invalid main message signature"),!1):(pe.warn("GSOC message validation failed:",r.error.format()),!1)}function za(a){if(!Array.isArray(a))return pe.warn("Message state must be an array"),!1;for(const r of a)if(!Va(r))return pe.warn("Invalid message in message state:",r.id),!1;return!0}function Va(a){const r=nr.safeParse(a);return r.success?Xn(a)?!0:(pe.warn("Invalid message signature"),!1):(pe.warn("Message data validation failed:",r.error.format()),!1)}function Xn(a){try{const r={username:a.username,address:a.address,timestamp:a.timestamp,message:a.message},i=new TextEncoder,c=B.concatBytes(i.encode(`Ethereum Signed Message:
11
- 32`),B.keccak256(i.encode(JSON.stringify(r))));if(new A.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(r){return pe.warn("Error in validateUserSignature",r),!1}}function Fa(a){const r=[];if(a==null)return{isValid:!0,errors:[]};if(typeof a!="object"||Array.isArray(a))return r.push("Additional properties must be a plain object"),{isValid:!1,errors:r};for(const g of Object.keys(a))Za.includes(g)&&r.push(`Property '${g}' is reserved and cannot be overridden`);const i=JSON.stringify(a),c=new TextEncoder().encode(i).length,u=1*1024;c>u&&r.push(`Additional properties too large: ${c} bytes (max: ${u} bytes)`);const l=5;function h(g,y=0){if(y>l)return!1;if(typeof g=="object"&&g!==null&&!Array.isArray(g)){for(const E of Object.values(g))if(!h(E,y+1))return!1}return!0}h(a)||r.push(`Additional properties nested too deeply (max depth: ${l})`);for(const[g,y]of Object.entries(a))if(g.length>100&&r.push(`Property key '${g}' too long (max: 100 characters)`),typeof y=="string"&&y.length>1e3&&r.push(`Property '${g}' value too long (max: 1000 characters)`),typeof y=="string"){const E=[/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,/javascript:/gi,/data:text\/html/gi,/vbscript:/gi,/on\w+\s*=/gi];for(const j of E)if(j.test(y)){r.push(`Property '${g}' contains potentially dangerous content`);break}}const p=20;return Object.keys(a).length>p&&r.push(`Too many additional properties: ${Object.keys(a).length} (max: ${p})`),{isValid:r.length===0,errors:r}}function Wa(a){const r=nr.safeParse(a);if(!r.success){const i=r.error.issues.map(c=>c.path.length>0?`${c.path.join(".")}: ${c.message}`:c.message);return pe.warn("Message validation failed:",r.error.format()),{isValid:!1,errors:i}}return{isValid:!0,errors:[]}}const Y={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 Ha{constructor(r,i){this.utils=r,this.emitter=i,this.logger=H.getInstance(),this.errorHandler=X.getInstance(),this.processedRefs=new Set,this.refRetryCount=new Map,this.bannedRefs=new Set,this.latestStatefulMessage=null,this.MAX_RETRIES=3,this.RETRY_DELAY=1e3}async init(){try{const{data:r,index:i}=await this.utils.fetchLatestChatMessage();this.latestStatefulMessage=r;try{await this.initMessageState(r)}catch(c){this.errorHandler.handleError(c,"SwarmHistory.initMessageState")}return i}catch(r){return this.errorHandler.handleError(r,"SwarmHistory.init"),A.FeedIndex.fromBigInt(0n)}}async initMessageState(r){try{if(!Qn(r)){this.logger.warn("Invalid GSOC message during message state initialization");return}if(!r.messageStateRefs||r.messageStateRefs.length===0){this.logger.debug("No message state refs to initialize");return}const i=this.findLatestRef(r.messageStateRefs);if(!i){this.logger.warn("No valid latest reference found");return}this.logger.debug("Initializing message state with latest ref:",i.reference),await this.processMessageRefWithRetry(i.reference)}catch(i){if(this.utils.isNotFoundError(i)){this.logger.debug("No latest GSOC message found for message state initialization");return}this.errorHandler.handleError(i,"SwarmHistory.init")}}async fetchPreviousMessageState(){let r=this.latestStatefulMessage;if(!r){const{data:c}=await this.utils.fetchLatestChatMessage();r=c,this.latestStatefulMessage=c}if(!r.messageStateRefs||r.messageStateRefs.length===0){this.logger.debug("No message state refs to fetch");return}const i=[...r.messageStateRefs].sort((c,u)=>c.timestamp-u.timestamp);for(const c of i)!this.processedRefs.has(c.reference)&&!this.bannedRefs.has(c.reference)&&(this.logger.debug("Fetching previous message ref:",c.reference),await this.processMessageRefWithRetry(c.reference))}findLatestRef(r){return r.length===0?null:r.reduce((i,c)=>c.timestamp>i.timestamp?c:i)}async processMessageRefWithRetry(r){if(!(this.processedRefs.has(r)||this.bannedRefs.has(r)))try{await this.processMessageRef(r)}catch(i){await this.handleRefError(r,i)}}async processMessageRef(r){const i=await this.utils.downloadObjectFromBee(r);if(!za(i))throw new Error(`Invalid message state for ref: ${r}`);this.processedRefs.add(r),this.refRetryCount.delete(r);for(const u of i)this.emitter.emit(Y.MESSAGE_RECEIVED,u)}async handleRefError(r,i){const c=this.refRetryCount.get(r)||0,u=c+1;if(this.logger.warn(`Error processing ref ${r} (attempt ${u}/${this.MAX_RETRIES}):`,i),u>=this.MAX_RETRIES)this.bannedRefs.add(r),this.refRetryCount.delete(r),this.logger.error(`Ref ${r} has been banned after ${this.MAX_RETRIES} failed attempts`),this.errorHandler.handleError(i,"SwarmHistory.processMessageRef");else{this.refRetryCount.set(r,u);const l=this.RETRY_DELAY*Math.pow(2,c);this.logger.debug(`Retrying ref ${r} after ${l}ms delay`),await Ni(l),await this.processMessageRefWithRetry(r)}}hasPreviousMessages(){return!!this.latestStatefulMessage&&!!this.latestStatefulMessage.messageStateRefs&&this.latestStatefulMessage.messageStateRefs.length>1}cleanup(){this.processedRefs.clear(),this.refRetryCount.clear(),this.bannedRefs.clear(),this.latestStatefulMessage=null}}class qa{constructor(r,i){this.userDetails=r,this.swarmSettings=i,this.depth=26,this.errorHandler=X.getInstance(),this.UPLOAD_GSOC_TIMEOUT=2e3}generateUserOwnedFeedId(r,i){return`${r}_EthercastChat_${i}`}isNotFoundError(r){return r.stack.includes("404")||r.message.includes("Not Found")||r.message.includes("404")||r.code===404}async writeOwnFeedDataByIndex(r,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(r,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(r,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(r,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,g=this.generateUserOwnedFeedId(l,p),y=A.Topic.fromString(g);await c.makeFeedWriter(y,new A.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:r})}async writeOwnFeedDataByIndexEnvelope(r,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,g=new A.PrivateKey(h),y=A.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(l,p),j=A.Topic.fromString(E),oe=Dn(j,r),ce=Un(i),it=Pn(ce,oe,g),je={hash:()=>it.address.toUint8Array()},sr=y.stamp(je),{upload:ir}=c.makeSOCWriter(g),at=A.Bytes.fromUtf8(i);return(await ir(sr,oe,at.toUint8Array())).reference.toHex()}orderMessages(r){return r.sort((i,c)=>i.timestamp-c.timestamp)}async downloadObjectFromBee(r){try{const{bee:i}=this.swarmSettings,c=await i.downloadData(r);return c?c.toJSON():null}catch(i){return this.errorHandler.handleError(i,"Utils.downloadObjectFromBee"),null}}async uploadObjectToBee(r){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(r);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(r)}async uploadObjectToBeeOwn(r){try{const{bee:i,stamp:c}=this.swarmSettings;return(await i.uploadData(c,JSON.stringify(r),{redundancyLevel:4})).reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(r){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(r)),p=new Ti(async y=>{await i.uploadChunk(l.stamp(y),y.build())});await p.append(h.toUint8Array());const g=await p.finalize();return B.uint8ArrayToHex(g.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:r,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),l=A.Topic.fromString(u),p=await r.makeFeedReader(l,c).downloadPayload(),g=Number(p.feedIndex.toBigInt()),y=g+1;return{latestIndex:g,nextIndex:y}}catch(r){if(this.isNotFoundError(r))return{latestIndex:-1,nextIndex:0};throw r}}async fetchLatestChatMessage(){const{bee:r,chatTopic:i,chatAddress:c}=this.swarmSettings,l=await r.makeFeedReader(A.Topic.fromString(i),Gt(c)).downloadPayload();return{data:l.payload.toJSON(),index:l.feedIndex}}async fetchChatMessage(r){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(A.Topic.fromString(c),Gt(u)).downloadPayload({index:r})).payload.toJSON()}async sendMessageToGsoc(r){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(r);else if(c)await this.sendMessageToGsocEnvelope(r);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(r,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${r}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok){const l=new Error(`Failed to fetch: ${r}/${i} [${u.status}]`);throw l.status=u.status,l}return u.text()}async sendMessageToGsocOwn(r){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,h=new A.PrivateKey(l),p=A.Identifier.fromString(u),g=A.Bytes.fromUtf8(r),{upload:y}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await y(c,p,g.toUint8Array())}async sendMessageToGsocEnvelope(r){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,{privateKey:h}=this.userDetails,p=A.Stamper.fromBlank(h,c,this.depth),g=new A.PrivateKey(l),y=A.Identifier.fromString(u),E=A.Bytes.fromUtf8(r),j=Un(E.toUint8Array()),oe=Pn(j,y,g),ce={hash:()=>oe.address.toUint8Array()},it=p.stamp(ce),{upload:je}=i.makeSOCWriter(g,{timeout:this.UPLOAD_GSOC_TIMEOUT});await je(it,y,E.toUint8Array())}}class Ga{constructor(r,i){this.logger=H.getInstance(),this.errorHandler=X.getInstance(),this.gsocIndex=null;const c=new A.PrivateKey(Gt(r.user.privateKey));this.userDetails={privateKey:r.user.privateKey,ownAddress:c.publicKey().address().toString(),nickname:r.user.nickname,ownIndex:-1},this.swarmSettings={bee:new A.Bee(r.infra.beeUrl),beeUrl:r.infra.beeUrl,stamp:r.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:r.infra.enveloped,gsocTopic:r.infra.gsocTopic,gsocResourceId:r.infra.gsocResourceId,chatTopic:r.infra.chatTopic,chatAddress:r.infra.chatAddress},this.emitter=new ji,this.utils=new qa(this.userDetails,this.swarmSettings),this.history=new Ha(this.utils,this.emitter),this.transport=i||this.createDefaultPollingTransport(),this.transport.onMessage(u=>{this.emitter.emit(Y.MESSAGE_RECEIVED,u)})}createDefaultPollingTransport(){return new Rn({fetchMessage:async()=>{try{if(!this.gsocIndex)return null;const r=A.Topic.fromString(this.swarmSettings.chatTopic),i=Dn(r,this.gsocIndex),c=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,i.toString()),u=JSON.parse(c);return Qn(u)?(this.gsocIndex=this.gsocIndex.next(),u.message):(this.logger.warn("Invalid GSOC message during fetching"),null)}catch(r){if(this.utils.isNotFoundError(r))return null;throw r}},pollingInterval:1e3})}async start(){await this.init(),await this.transport.start()}async stop(){this.emitter.cleanAll(),this.history.cleanup(),await this.transport.stop()}getEmitter(){return this.emitter}orderMessages(r){return this.utils.orderMessages(r)}async sendMessage(r,i,c,u,l){const h=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,p={id:u||Ei(),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(r),timestamp:Date.now(),index:h,type:i,targetMessageId:c,message:r,additionalProps:l},g=Wa(p);if(!g.isValid){const y=`Invalid message: ${g.errors.join(", ")}`;throw this.logger.error(y),new Error(y)}try{this.emitter.emit(Y.MESSAGE_REQUEST_INITIATED,p),await this.utils.writeOwnFeedDataByIndex(h,JSON.stringify(p)),this.userDetails.ownIndex=h,this.emitter.emit(Y.MESSAGE_REQUEST_UPLOADED,p),await this.broadcastUserMessage(p)}catch(y){this.emitter.emit(Y.MESSAGE_REQUEST_ERROR,p),this.errorHandler.handleError(y,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(Y.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessageState()}finally{this.emitter.emit(Y.LOADING_PREVIOUS_MESSAGES,!1)}}hasPreviousMessages(){return this.history.hasPreviousMessages()}async retrySendMessage(r){this.sendMessage(r.message,r.type,r.targetMessageId,r.id,r.additionalProps)}async retryBroadcastUserMessage(r){await this.broadcastUserMessage(r)}async init(){try{this.emitter.emit(Y.LOADING_INIT,!0);const[r,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(r.status==="rejected")throw r.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(Y.LOADING_INIT,!1)}catch(r){this.errorHandler.handleError(r,"Chat.initSelfState"),this.emitter.emit(Y.CRITICAL_ERROR,r)}}async initOwnIndex(){const{latestIndex:c}=await Kt(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async broadcastUserMessage(r){try{return Kt(()=>this.utils.sendMessageToGsoc(JSON.stringify(r)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(r){const{ownAddress:i,privateKey:c,nickname:u}=this.userDetails,l=new A.EthAddress(i).toString(),h=new A.PrivateKey(c);if(h.publicKey().address().toString()!==l)throw new Error("The provided address does not match the address derived from the private key");const g=Date.now();return h.sign(JSON.stringify({username:u,address:l,message:r,timestamp:g})).toHex()}}Q.EVENTS=Y,Q.MessageType=rr,Q.PollingTransport=Rn,Q.SwarmChat=Ga,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});
4
+ `)}function Pt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ws(e){return e.charAt(0).toLowerCase()+e.slice(1)}function bs(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function _s(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function lt(e){return bs(e)||_s(e)}const Zc=`
5
+ \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function Bc(e){return Zc.includes(e)}function Lc(e){return lt(e)||e==="."||e==="["||e==="]"||e==="_"}function zc(e,t,n,s,o){return e.slice(0,t)+s+e.slice(t,t+n)+o+e.slice(t+n)}function xs(e,t,n=0){const s=t.exec(e.slice(n));return s?{index:s.index,match:s[0]}:null}function ks(e,t,n=!0){if(!n)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=xs(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 Vc(e,t,n=!0){let s=0;for(const o of t){let d=!1;for(;!d&&s<e.length;)ks(e[s],o,n)&&(d=!0),s++;if(!d)return!1}return!0}function Fc(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function Ue(e,t,n=0){let s=-1;for(const o of t){const d=e.indexOf(o,n);d!==-1&&(s===-1||d<s)&&(s=d)}return s}function Wc(e,t=0){for(let n=t;n<e.length;n++)if(Bc(e[n]))return n;return-1}function Hc(e,t=0){for(let n=t;n<e.length;n++)if(e[n]==="#"&&lt(e[n+1]))return n;return-1}function Es(e,t,n=0){return e.slice(0,n).lastIndexOf(t)}function Ss(e,t=0,n="{",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+n.length)===n&&o++;return-1}function Ts(e,t){const n=t.wordBoundary?Ue(e,[`${t.opening} `,`${t.opening}
6
+ `],t.start||0):e.indexOf(t.opening,t.start||0);if(n===-1)return null;const s=Ss(e,n+t.opening.length,t.opening,t.closing);return s===-1?null:t.exclusive?e.slice(n+t.opening.length,s):e.slice(n,s+t.closing.length)}function qc(e,t){const n=[];let s=t.wordBoundary?Ue(e,[`${t.opening} `,`${t.opening}
7
+ `],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(s===-1)return n;const o=Ts(e,{...t,start:s});if(!o)return n;n.push(o),s=t.wordBoundary?Ue(e,[`${t.opening} `,`${t.opening}
8
+ `],s+o.length):e.indexOf(t.opening,s+o.length)}}function Gc(e,t,n){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...n,start:s});if(!o)return e;const d=t(o);s=e.indexOf(o,s)+d.length,e=e.replace(o,d)}}function Kc(e,t){const n=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){n.push({string:e.slice(s),symbol:null});break}const d=e.indexOf(t,o+t.length);if(o>s&&d!==-1&&n.push({string:e.slice(s,o),symbol:null}),d===-1){n.push({string:e.slice(s),symbol:null});break}n.push({string:e.slice(o+t.length,d),symbol:t}),s=d+t.length}return n}function Yc(e){const t=[];let n=0;for(;n<e.length;){const s=Hc(e,n);if(s===-1){t.push({string:e.slice(n),symbol:null});break}const o=Wc(e,s+1);if(o===-1){t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),n=o}return t}function Qc(e){const t=[];let n=0;for(;n<e.length;){const s=Ue(e,["http://","https://"],n);if(s===-1){t.push({string:e.slice(n),symbol:null});break}const o=Ue(e,[" ",`
9
+ `],s);if(o===-1){s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>n&&t.push({string:e.slice(n,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),n=o}return t}const As="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Os="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Xc(e){return Is(e,As)}function Jc(e){return Ms(e,As)}function eu(e){return Is(e,Os)}function tu(e){return Ms(e,Os)}function Is(e,t){const n="=",s=t.length;let o=0,d=0;const f=[];for(let v=0;v<e.length;v++){const m=e[v];if(m===n)break;const k=t.indexOf(m);if(k===-1)throw new Error(`Invalid character: ${m}`);d=d<<Math.log2(s)|k,o+=Math.log2(s),o>=8&&(o-=8,f.push(d>>o&255))}return new Uint8Array(f)}function Ms(e,t){const n=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(n);)s-=Math.log2(n),d+=t[o>>s&n-1];return s>0&&(d+=t[o<<Math.log2(n)-s&n-1]),d.length%4!==0&&(d+="=".repeat(4-d.length%4)),d}function ru(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,n=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);n[s]=o}return n}function nu(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function su(e,t){const n=e.split("/").filter(d=>d),s=t.split("/").filter(d=>d);if(n.length!==s.length)return null;const o={};for(let d=0;d<n.length;d++){const f=n[d];if(f.startsWith(":"))o[f.slice(1)]=s[d];else if(f!==s[d])return null}return o}function wr(e,t,n){const s=[];for(const o of n)o!==t&&s.push(e.replace(t,o));return s}function iu(e,t,n,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(v=>v),s),avoid:f.avoid})),s),d=[];for(const f of o){const v=f.variants.filter(k=>k!==f.avoid),m=v.find(k=>e.includes(k));if(m&&(jt(d,wr(e,m,v)),d.length>=n))break}if(d.length<n)for(const f of o){const v=f.variants.find(m=>e.includes(m));if(v&&(jt(d,wr(e,v,f.variants)),d.length>=n))break}return d.slice(0,n)}function au(e,t,n,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,n)}function ou(e,t){const n=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(n,s=>s.toUpperCase()===s?s:t(s))}function cu(e){return e.replace(/<[^>]*>/g,"")}function $s(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const n=e.slice(0,t),s=e.slice(t+1);return{line:n,rest:s}}function uu(e,t={}){return[...e].reduce((n,s)=>n+(t[s]||1),0)}function lu(e,t,n={}){const s=[];let o="",d=0;for(let f=0;f<e.length;f++){const v=e[f],m=n[v]||1;if(o+=v,d+=m,d>t){const{line:k,rest:$}=$s(o);s.push(k),o=$,d=$.split("").map(U=>n[U]||1).reduce((U,ze)=>U+ze,0)}}return o&&s.push(o),s}function du(e,t){const n=[];for(let s=0;s<=e.length;s++)n[s]=[s];for(let s=0;s<=t.length;s++)n[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;n[s][o]=Math.min(n[s-1][o]+1,n[s][o-1]+1,n[s-1][o-1]+d)}return n[e.length][t.length]}function br(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function fu(e,t,n){return n==="any"?t.some(s=>br(e,s)):t.every(s=>br(e,s))}function hu(e){const t={},n=e.match(/([a-z\-]+)="([^"]+)"/g);if(n)for(const s of n){const[o,d]=gr(s,"=");t[o]=d.slice(1,d.length-1)}return t}function Ut(e,t,n=[]){let s="";for(;t<e.length&&(lt(e[t])||n.includes(e[t]));)s+=e[t++];return s}function pu(e,t,n="$",s=":"){for(const o in t)e=Rs(e,o,t[o],n,s);return e=Cs(e),e}function Rs(e,t,n,s="$",o=":"){if(n==="")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}`,n);else{const f=Ut(e,d+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,n)}else e=e.replace(`${s}${t}`,n);d=e.indexOf(`${s}${t}`,d+n.length)}return e}function Cs(e,t="$",n=":"){let s=e.indexOf(t);for(;s!==-1;){const o=Ut(e,s+1);if(e[s+o.length+1]===n)if(e[s+o.length+2]===n)e=e.replace(`${t}${o}${n}${n}`,"");else{const d=Ut(e,s+o.length+2);e=e.replace(`${t}${o}${n}${d}`,d)}s=e.indexOf(t,s+1)}return e}function mu(e,t){let n=e.indexOf("](");for(;n!==-1;){const s=Es(e,"[",n),o=e.indexOf(")",n);if(s!==-1&&o!==-1){const[d,f]=e.slice(s+1,o).split("]("),v=t(d,f);e=e.slice(0,s)+v+e.slice(o+1)}n=e.indexOf("](",n+1)}return e}function Ns(e,t=!0){const n=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return n?(t?"?":"")+n:""}function gu(e){const t={},n=e.split("&");for(const s of n){const[o,d]=s.split("=");o&&d&&(t[o]=decodeURIComponent(d))}return t}function yu(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function vu(e,t){let n=null,s=-1/0;for(const[o,d]of Object.entries(e)){const f=t(d);f>s&&(s=f,n=o)}return n?[n,e[n]]:null}function wu(e,t,n,s){const o=e.find(f=>f[t]===n),d=e.find(f=>f[t]===n+s);o&&d?(o[t]=n+s,d[t]=n):o&&(o[t]=n+s),e.sort((f,v)=>Ct(f[t])-Ct(v[t])),e.forEach((f,v)=>f[t]=v+1)}function bu(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 _u(e,t=":"){return Object.fromEntries(e.map(n=>gr(n,t)).map(n=>n[0]&&n[1]?[ut(n[0]),ut(n[1])]:null).filter(n=>n))}function xu(e,t,n){return Us(e,t)+Ns(n||{})}function ku(e,t=",",n='"'){const s=[];let o="",d=!1;const f=e.split("");for(const v of f)v===t&&!d?(s.push(o),o=""):v===n&&(!o&&!d||d)?d=!d:o+=v;return s.push(o),s}function Eu(e){return`[${Math.floor(e.progress*100)}%] ${Zt(e.deltaMs)} out of ${Zt(e.totalTimeMs)} (${Zt(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function Su(e,t,n){for(let s=0;s<n;s++){try{if(await e())return!0}catch{}s<n-1&&await l(t)}return!1}function Tu(e,t){const n=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&n.push(e.splice(s,1)[0]);return n}function Au(e){return JSON.parse(JSON.stringify(e))}function Ou(e){return Math.ceil((e||Date.now())/1e3)}function Iu(e){return(e||new Date).toISOString().slice(0,10)}function Mu(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function $u(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function Ru(e){return new Date(e)}function re(e){return String(Math.floor(e)).padStart(2,"0")}function Cu(e){let[t,n]=e.split(":");ge(parseInt(t,10))||(t="0"),ge(parseInt(n,10))||(n="0");let s=Sr(fr(t),0,23),o=Sr(fr(n),0,59);return`${re(s)}:${re(o)}`}function Zt(e){const t=Math.floor(e/36e5);e=e%36e5;const n=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${re(t)}:${re(n)}:${re(s)}`:`${re(n)}:${re(s)}`}function Te(e){return Math.floor((Pe(e)?e.getTime():e)/864e5)}const Nu={today:(e,t)=>re(e)+":"+re(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function ju(e,t){const n=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||Nu,o=Pe(e)?e:new Date(e);if(Te(n)===Te(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(Te(n)-Te(o)===1)return s.yesterday();const d=xr(o);return Te(n)-Te(o)<7?s[d.day]():s.weeks(Math.round((n.getTime()-o.getTime())/6048e5))}const js={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 Ds(e,t){const n=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||js,o=a.Types.isDate(e)?e.getTime():e;let d=(n-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 Du(e,t=js){return Ds(0,{now:e*1e3,labels:t})}function Pu(e,t,n){const s=((n==null?void 0:n.now)??Date.now())-e,o=Math.floor(s/t),d=t/((n==null?void 0:n.precision)??1)-Math.ceil(s%t/((n==null?void 0:n.precision)??1));return{cycles:o,remaining:d}}const _r={};function Uu(e,t){return!_r[e]||Date.now()>_r[e]?(_r[e]=Date.now()+t,!0):!1}const Zu={s:1e3,m:6e4,h:36e5,d:864e5};function Bu(e,t,n){return t=Pe(t)?t.getTime():t,n=n?Pe(n)?n.getTime():n:Date.now(),(n-t)/Zu[e]}function Lu(e,t,n,s){s||(s=Date.now());const o=t/n,d=s-e,f=d/t,v=f*n,m=v-d;return{deltaMs:d,progress:o,baseTimeMs:f,totalTimeMs:v,remainingTimeMs:m}}const zu={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function Ps(e){return{zeroBasedIndex:e,day:zu[e]}}function xr(e){return Ps(e.getDay())}function Vu(e){return xr(new Date(e))}function Fu(e){return e*1e3}function Wu(e){return e*6e4}function Hu(e){return e*36e5}function qu(e){return e*864e5}const Gu={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 Ku(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Gu[n];if(!s)throw Error(`Unknown unit: "${n}"`);return t*s}const Yu={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 Qu(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Yu[n];if(!s)throw Error(`Unknown unit: "${n}"`);return t*s}function Xu(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const kr={};async function Ju(e,t,n){const s=Date.now(),o=kr[e];if(o&&o.validUntil>s)return o.value;const d=await n(),f=s+t;return kr[e]={value:d,validUntil:f},d}function el(e){delete kr[e]}function Us(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function tl(e,t,n,s,o=!0){const d=e.indexOf(t),f=e.indexOf(n,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+n.length)}function rl(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const n=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:n,hasPunctuation:s,endsWithColon:o}}function nl(e,t="(",n=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(n,o)?(s--,o+=n.length):o++,s<0)return!1;return t===n?s%2===0:s===0}function sl(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 Zs(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),n={};for(const s of t)n[s]=Ae(e[s]);return n}function Bs(e){const t=[];return e.sort((n,s)=>JSON.stringify(Ae(n)).localeCompare(JSON.stringify(Ae(s)))).forEach(n=>t.push(Ae(n))),t}function Ae(e){return Array.isArray(e)?Bs(e):me(e)?Zs(e):e}function Ls(e,t){return JSON.stringify(Ae(e))===JSON.stringify(Ae(t))}function il(...e){for(let t=1;t<e.length;t++)if(!Ls(e[t-1],e[t]))return!1;return!0}function al(e){try{return JSON.parse(e)}catch{return null}}function ol(){let e=0;return{next:()=>e++}}function cl(e){let t=0;return{next:()=>e[t++%e.length]}}function ul(e){let t;return n=>{const s=n===e&&t!==e;return t=n,s}}function ll(e,t,n,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 v=f[n],m=t[v]?v:s;d[m].length>=t[m]?d[s].push(f):d[m].push(f)}return d}function dl(e,t){const n=Object.keys(e),s=Object.keys(t);return{uniqueToA:n.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!n.includes(o))}}function zs(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function fl(e,t){const n=zs(e);return e[n]=t(e[n]),n}function hl(e){return e=e.replace(/\r\n/g,`
10
+ `),e=e.replace(/(\w+)\((.+)\)/g,(t,n,s)=>`${n}(${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,n,s)=>`: (${n.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,n,s,o)=>`"${n}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const ye=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],pl=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Vs=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function ml(e,t,n){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(n?" "+n:"");let o=e.substring(0,s),d=e.substring(s);return o===""&&(o="0"),o+"."+d+(n?" "+n:"")}function gl(e,t){const n=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=n?pl:Vs,d=(t==null?void 0:t.precision)??1;if(e<ye[0])return`${e}${s}`;for(let f=0;f<ye.length-1;f++)if(e<ye[f+1])return`${(e/ye[f]).toFixed(d)}${n?" ":""}${o[f]}${s}`;return`${(e/ye[ye.length-1]).toFixed(d)}${n?" ":""}${o[ye.length-1]}${s}`}function Er(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const n=e.replace(/^-?[0-9.]+/,"").trim(),s=Vs.findIndex(o=>o.toLowerCase()===n.toLowerCase());return s===-1?t:t*ye[s]}function Sr(e,t,n){return e<t?t:e>n?n:e}function yl(e,t,n){const s=e+t;return s>n?n:s}function vl(e,t,n){const s=e-t;return s<n?n:s}function wl(e,t){return t(e),e}function bl(e,t){e&&t(e)}function _l(e,t){const n=Object.keys(t);for(const s of n)Array.isArray(t[s])&&Array.isArray(e[s])&&jt(e[s],t[s])}function xl(e){return e.splice(0,e.length),e}function kl(e){for(const t of Object.keys(e))(rs(e[t])||Array.isArray(e[t])&&e[t].every(n=>n==null))&&delete e[t];return e}function El(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||H(t[1])&&Rt(t[1]))&&delete e[t[0]];return e}function Sl(e,t){const n={};for(const[s,o]of Object.entries(e))t(s)&&(n[s]=o);return n}function Tl(e,t){const n={};for(const[s,o]of Object.entries(e))t(o)&&(n[s]=o);return n}function Al(e,t){const n={};for(const s of Object.entries(e))n[s[0]]=t(s[1]);return n}function Ol(e,t){const n=[];let s=0;for(const o of e)n.push(t(o,s++));return n}async function Il(e,t){try{return await e()}catch{throw t}}function Ml(e,t,n){n!=null&&(e[t]=n)}function $l(e,t,n,s){const o=ke(n,s);o!=null&&Ee(e,t,o)}function Rl(e){const t={};for(const[n,s]of Object.entries(e))t[s]=n;return t}function Cl(e){const t=Object.keys(e),n=t.map(v=>e[v].length),s=n.reduce((v,m)=>v*=m);let o=1;const d=[1];for(let v=0;v<n.length-1;v++)o*=n[v],d.push(o);const f=[];for(let v=0;v<s;v++){const m={};for(let k=0;k<t.length;k++){const $=e[t[k]],U=Math.floor(v/d[k])%$.length;m[t[k]]=$[U]}f.push(m)}return f}function Nl(e){return Object.values(e).filter(t=>t).length}function jl(e,t,n){return e+(n?"["+t+"]":(e.length?".":"")+t)}function Bt(e,t,n,s,o){if(!me(t))return t;for(const[d,f]of Object.entries(t)){const v=jl(n,d,s);Array.isArray(f)?o?Bt(e,f,v,!0,o):e[v]=f.map(m=>Bt(Array.isArray(m)?[]:{},m,"",!1,o)):me(f)?Bt(e,f,v,!1,o):e[v]=f}return e}function Dl(e,t=!1,n){return Bt({},e,n||"",!1,t)}function Fs(e){if(!me(e))return e;const t=Array.isArray(e)?[]:{};for(const[n,s]of Object.entries(e))Array.isArray(s)?Ee(t,n,s.map(o=>Fs(o))):Ee(t,n,s);return t}function Pl(e,t,n){return t[e]?t[e]:n}function Ws(e,t){const n={};for(const s of e){const o=t(s);n[o]=s}return n}function Ul(e,t){const n={};for(const s of e){const o=t(s);n[o]||(n[o]=[]),n[o].push(s)}return n}function Zl(e,t){const n=[];for(let s=0;s<e.length;s+=t)n.push(e.slice(s,s+t));return n}function Hs(e,t){const n=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=n)s.push(e.slice(o,o+n));return s}function qs(e,t){const n=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)n.push(e.slice(o*t,o*t+t));return n}function Bl(e,t){const n=Math.ceil(e.length/t);return qs(e,n)}function Ll(e,t){return Object.values(Ws(e,t))}function zl(e,t,n,s,o){const d=t?e.map(t):e,f={};for(const m of d)f[m]=(f[m]||0)+1;const v=s?Gs(f,o?(m,k)=>m[1]-k[1]:(m,k)=>k[1]-m[1]):f;return n?Object.keys(v):v}function Gs(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function Vl(e){const t=[],n=Object.keys(e),s=e[n[0]].length;for(let o=0;o<s;o++){const d={};for(const f of n)d[f]=e[f][o];t.push(d)}return t}function Fl(e,t,n=1){for(const s of e)s[t]+=n}function Wl(e,t,n){for(const s of e)s[t]=n}function Tr(e,t){const n=[];let s=[];return e.forEach((o,d)=>{(d===0||!t(o,e[d-1]))&&(s=[],n.push(s)),s.push(o)}),n}function Hl(){return{map:new Map,keys:[]}}function ql(){return{map:new Map,keys:[]}}function Ks(e,t,n,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,n),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Gl(e,t,n,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,n),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Kl(e,t,n,s,o=100){Ks(e,t,{validUntil:Date.now()+s,data:n},o)}function Yl(e,t){const n=e.map.get(t);return n&&n.validUntil>Date.now()?n.data:null}class ve{constructor(t){this.value=t}static of(t){return new ve(t)}static empty(){return new ve(null)}map(t){return new ve(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(n=>ve.of(n)):Promise.resolve(ve.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=ve;class Ql{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=Ql;class Xl{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=Xl;function Jl(e){return()=>e.forEach(t=>t())}function ed(e,t){return e.reduce((n,s)=>t(n)>t(s)?n:s)}function td(e,t){const n=e.find(s=>s instanceof t);return ve.of(n)}function rd(e,t){return e.filter(n=>n instanceof t)}function nd(e,t){const n=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&n.push(e[o]),t[o]&&n.push(t[o]);return n}function sd(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}class id{constructor(t){this.value=t,this.children=[]}}function ad(e,t,n,s,o=!1){const d=new Map,f=[];e.forEach(m=>{const k=new id(m);d.set(m[t],k)}),e.forEach(m=>{const k=d.get(m[t]);if(!k)return;const $=m[n];if($){const U=d.get($);U&&U.children.push(k)}else f.push(k)});const v=m=>{m.children.sort((k,$)=>{const U=k.value[s],ze=$.value[s];return o?ze-U:U-ze}),m.children.forEach(v)};return f.forEach(v),f}function Ys(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let n=[...e];for(;n.length>1;){const s=[];for(let o=0;o<n.length;o+=2){const d=n[o+1];s.push(t(n[o],d))}n=s}return n[0]}function Ze(...e){const t=e.reduce((o,d)=>o+d.length,0),n=new Uint8Array(t);let s=0;return e.forEach(o=>{n.set(o,s),s+=o.length}),n}function Qs(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function Xs(e){return e[0]===255&&e[1]===216}function Js(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function od(e){return Qs(e)||Xs(e)||Js(e)}function cd(e){return new Uint8Array([e])}function ud(e){return e[0]}function ld(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,t==="LE"),new Uint8Array(n)}function dd(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function fd(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,t==="LE"),new Uint8Array(n)}function hd(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function Ar(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(n)}function pd(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function Be(e,t){const n=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)n[o]=Number(s&0xffn),s>>=8n;return n}for(let o=31;o>=0;o--)n[o]=Number(s&0xffn),s>>=8n;return n}function Le(e,t){let n=0n;if(t==="LE"){for(let s=31;s>=0;s--)n=n<<8n|BigInt(e[s]);return n}for(let s=0;s<32;s++)n=n<<8n|BigInt(e[s]);return n}function md(e,t){const n=[];let s=0;for(const o of t)n.push(e.subarray(s,s+o)),s+=o;return n}function Or(e,t){const n=[];for(let s=0;s<e.length;s+=t)n.push(e.subarray(s,s+t));return n}const ei=[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 gd(e){for(let t=0;t<24;t++){const n=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],v=e[5]^e[15]^e[25]^e[35]^e[45],m=e[6]^e[16]^e[26]^e[36]^e[46],k=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],ze=o<<1|d>>>31,Xd=d<<1|o>>>31,ht=$^ze,pt=U^Xd,Jd=f<<1|v>>>31,ef=v<<1|f>>>31,mt=n^Jd,gt=s^ef,tf=m<<1|k>>>31,rf=k<<1|m>>>31,yt=o^tf,vt=d^rf,nf=$<<1|U>>>31,sf=U<<1|$>>>31,wt=f^nf,bt=v^sf,af=n<<1|s>>>31,of=s<<1|n>>>31,_t=m^af,xt=k^of;e[0]^=ht,e[1]^=pt,e[2]^=mt,e[3]^=gt,e[4]^=yt,e[5]^=vt,e[6]^=wt,e[7]^=bt,e[8]^=_t,e[9]^=xt,e[10]^=ht,e[11]^=pt,e[12]^=mt,e[13]^=gt,e[14]^=yt,e[15]^=vt,e[16]^=wt,e[17]^=bt,e[18]^=_t,e[19]^=xt,e[20]^=ht,e[21]^=pt,e[22]^=mt,e[23]^=gt,e[24]^=yt,e[25]^=vt,e[26]^=wt,e[27]^=bt,e[28]^=_t,e[29]^=xt,e[30]^=ht,e[31]^=pt,e[32]^=mt,e[33]^=gt,e[34]^=yt,e[35]^=vt,e[36]^=wt,e[37]^=bt,e[38]^=_t,e[39]^=xt,e[40]^=ht,e[41]^=pt,e[42]^=mt,e[43]^=gt,e[44]^=yt,e[45]^=vt,e[46]^=wt,e[47]^=bt,e[48]^=_t,e[49]^=xt;const Nr=e[0],jr=e[1],Dr=e[2]<<1|e[3]>>>31,Pr=e[3]<<1|e[2]>>>31,Ur=e[5]<<30|e[4]>>>2,Zr=e[4]<<30|e[5]>>>2,Br=e[6]<<28|e[7]>>>4,Lr=e[7]<<28|e[6]>>>4,zr=e[8]<<27|e[9]>>>5,Vr=e[9]<<27|e[8]>>>5,Fr=e[11]<<4|e[10]>>>28,Wr=e[10]<<4|e[11]>>>28,Hr=e[13]<<12|e[12]>>>20,qr=e[12]<<12|e[13]>>>20,Gr=e[14]<<6|e[15]>>>26,Kr=e[15]<<6|e[14]>>>26,Yr=e[17]<<23|e[16]>>>9,Qr=e[16]<<23|e[17]>>>9,Xr=e[18]<<20|e[19]>>>12,Jr=e[19]<<20|e[18]>>>12,en=e[20]<<3|e[21]>>>29,tn=e[21]<<3|e[20]>>>29,rn=e[22]<<10|e[23]>>>22,nn=e[23]<<10|e[22]>>>22,sn=e[25]<<11|e[24]>>>21,an=e[24]<<11|e[25]>>>21,on=e[26]<<25|e[27]>>>7,cn=e[27]<<25|e[26]>>>7,un=e[29]<<7|e[28]>>>25,ln=e[28]<<7|e[29]>>>25,dn=e[31]<<9|e[30]>>>23,fn=e[30]<<9|e[31]>>>23,hn=e[33]<<13|e[32]>>>19,pn=e[32]<<13|e[33]>>>19,mn=e[34]<<15|e[35]>>>17,gn=e[35]<<15|e[34]>>>17,yn=e[36]<<21|e[37]>>>11,vn=e[37]<<21|e[36]>>>11,wn=e[38]<<8|e[39]>>>24,bn=e[39]<<8|e[38]>>>24,_n=e[40]<<18|e[41]>>>14,xn=e[41]<<18|e[40]>>>14,kn=e[42]<<2|e[43]>>>30,En=e[43]<<2|e[42]>>>30,Sn=e[45]<<29|e[44]>>>3,Tn=e[44]<<29|e[45]>>>3,An=e[47]<<24|e[46]>>>8,On=e[46]<<24|e[47]>>>8,In=e[48]<<14|e[49]>>>18,Mn=e[49]<<14|e[48]>>>18;e[0]=Nr^~Hr&sn,e[1]=jr^~qr&an,e[2]=Hr^~sn&yn,e[3]=qr^~an&vn,e[4]=sn^~yn&In,e[5]=an^~vn&Mn,e[6]=yn^~In&Nr,e[7]=vn^~Mn&jr,e[8]=In^~Nr&Hr,e[9]=Mn^~jr&qr,e[10]=Br^~Xr&en,e[11]=Lr^~Jr&tn,e[12]=Xr^~en&hn,e[13]=Jr^~tn&pn,e[14]=en^~hn&Sn,e[15]=tn^~pn&Tn,e[16]=hn^~Sn&Br,e[17]=pn^~Tn&Lr,e[18]=Sn^~Br&Xr,e[19]=Tn^~Lr&Jr,e[20]=Dr^~Gr&on,e[21]=Pr^~Kr&cn,e[22]=Gr^~on&wn,e[23]=Kr^~cn&bn,e[24]=on^~wn&_n,e[25]=cn^~bn&xn,e[26]=wn^~_n&Dr,e[27]=bn^~xn&Pr,e[28]=_n^~Dr&Gr,e[29]=xn^~Pr&Kr,e[30]=zr^~Fr&rn,e[31]=Vr^~Wr&nn,e[32]=Fr^~rn&mn,e[33]=Wr^~nn&gn,e[34]=rn^~mn&An,e[35]=nn^~gn&On,e[36]=mn^~An&zr,e[37]=gn^~On&Vr,e[38]=An^~zr&Fr,e[39]=On^~Vr&Wr,e[40]=Ur^~Yr&un,e[41]=Zr^~Qr&ln,e[42]=Yr^~un&dn,e[43]=Qr^~ln&fn,e[44]=un^~dn&kn,e[45]=ln^~fn&En,e[46]=dn^~kn&Ur,e[47]=fn^~En&Zr,e[48]=kn^~Ur&Yr,e[49]=En^~Zr&Qr,e[0]^=ei[t*2],e[1]^=ei[t*2+1]}}function ti(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}function ri(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[ti(o)]}const n=Or(e,136),s=n[n.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,n[n.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,n.push(o)}return n.map(ti)}function ni(e,t){for(const n of t){for(let s=0;s<34;s+=2)e[s]^=n[s+1],e[s+1]^=n[s];gd(e)}return e}function si(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 ue(e){return si(ni(new Array(50).fill(0),ri(e,1)))}function yd(e){return si(ni(new Array(50).fill(0),ri(e,6)))}function vd(e,t,n){const s=Math.min(e.length,t.length,n/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 n}function wd(e,t){const n=Math.min(e.length,t.length);for(let s=0;s<n;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,n)}function bd(e,t,n,s){const o=Math.floor(t/8),d=t%8;n===1?e[o]|=1<<(s==="BE"?7-d:d):e[o]&=~(1<<(s==="BE"?7-d:d))}function _d(e,t,n){const s=Math.floor(t/8),o=t%8;return e[s]>>(n==="BE"?7-o:o)&1}function xd(e,t,n=0){for(let s=n;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 ii(e,t,n=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(n),s.set(e,t-e.length),s}function kd(e,t,n=0){const s=e.length%t;return s===0?e:ii(e,e.length+t-s,n)}function ai(e,t,n=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(n),s.set(e,0),s}function Ed(e,t,n=0){const s=e.length%t;return s===0?e:ai(e,e.length+t-s,n)}function Sd(e,t){const n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e[s]^t[s%t.length];return n}function Td(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t){return(e%t+t)%t}function dt(e,t){e=R(e,t);let[n,s]=[0n,1n],[o,d]=[t,e];for(;d!==0n;){const f=o/d;[n,s]=[s,n-f*s],[o,d]=[d,o-f*d]}if(o>1n)throw new Error("a is not invertible");return n<0n&&(n+=t),n}function Ad(e,t,n){let s=1n;for(e=R(e,n);t>0;)t%2n===1n&&(s=R(s*e,n)),e=R(e*e,n),t=t/2n;return s}function oi(e,t){return R(e,t)===0n?0n:t%4n===3n?Ad(e,(t+1n)/4n,t):null}const z=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,P=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Lt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,zt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ir(e,t,n){if(t===0n)return[0n,0n];const s=R(3n*e*e*dt(2n*t,n),n),o=R(s*s-2n*e,n),d=R(s*(e-o)-t,n);return[o,d]}function Vt(e,t,n,s,o){if(e===0n&&t===0n)return[n,s];if(n===0n&&s===0n)return[e,t];if(e===n&&t===R(-s,o))return[0n,0n];if(e===n&&t===s)return Ir(e,t,o);const d=R((s-t)*dt(n-e,o),o),f=R(d*d-e-n,o),v=R(d*(e-f)-t,o);return[f,v]}function Od(e){if(e<=0n||e>=P)throw new Error("Invalid private key");return Oe(Lt,zt,e,z)}function Id(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...Be(e[0],"BE")])}function Md(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Le(e.slice(1),"BE"),n=oi(R(t**3n+7n,z),z);if(!n)throw Error("Invalid x: does not correspond to a valid curve point");const s=R(-n,z),o=n%2n===0n;return[t,e[0]===2?o?n:s:o?s:n]}function $d(e){const t=new Uint8Array(20),n=ue(Ze(Be(e[0],"BE"),Be(e[1],"BE")));return t.set(n.subarray(12)),t}function Rd(e){const t=a.Binary.uint8ArrayToHex(e),n=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(n[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function Oe(e,t,n,s){let o=[0n,0n],d=[e,t];const f=n.toString(2);for(const v of f)v==="0"?(d=Vt(o[0],o[1],d[0],d[1],s),o=Ir(o[0],o[1],s)):(o=Vt(o[0],o[1],d[0],d[1],s),d=Ir(d[0],d[1],s));return o}function Cd(e,t,n){return ci(Le(ue(e),"BE"),t,n)}function ci(e,t,n){if(t<=0n||t>=P)throw new Error("Invalid private key");if(n||(n=R(Le(ue(Ze(ue(Be(t,"BE")),Be(e,"BE"))),"BE"),P)),n<=0n||n>=P)throw new Error("Invalid nonce");const s=R(e,P),o=Oe(Lt,zt,n,z),d=R(o[0],P);let f=R((s+R(d,P)*t)*dt(n,P),P);if(d===0n||f===0n)throw new Error("Invalid r or s value");let v=o[1]%2n===0n?27n:28n;return f>P/2n&&(f=P-f,v=v===27n?28n:27n),[d,f,v]}function Nd(e,t,n,s){const o=oi(R(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,v=R(Le(ue(e),"BE"),P),m=Oe(t,f,n,z),k=Oe(Lt,zt,v,z),$=Vt(m[0],m[1],k[0],R(-k[1],z),z);return Oe($[0],$[1],dt(t,P),z)}function jd(e,t,n,s){const o=R(Le(ue(e),"BE"),P),d=dt(s,P),f=R(o*d,P),v=R(n*d,P),m=Oe(Lt,zt,f,z),k=Oe(t[0],t[1],v,z),$=Vt(m[0],m[1],k[0],k[1],z);return n===R($[0],P)}class ui{constructor(t){this.cursor=0,this.buffer=t}read(t){const n=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,n}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=ui;class li{constructor(t){this.buffer=t,this.cursor=0}write(t){const n=Math.min(this.max(),t.max());return this.buffer.set(t.read(n),this.cursor),this.cursor+=n,n}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=li;class Ft{constructor(t,n=0n){this.span=n,this.writer=new li(new Uint8Array(t))}build(){return Ze(Ar(this.span,"LE"),this.writer.buffer)}hash(){const t=Ys(Or(this.writer.buffer,32),(n,s)=>ue(Ze(n,s)));return ue(Ze(Ar(this.span,"LE"),t))}}a.Chunk=Ft;class Mr{constructor(t,n=4096){this.counters=[1],this.capacity=n,this.chunks=[new Ft(n)],this.onChunk=t}static async root(t,n=4096){const s=new r(r.NOOP,n);return await s.append(t),s.finalize()}async append(t,n=0,s=0n){const o=new ui(t);for(;o.max()>0;){this.chunks[n].writer.max()===0&&await this.elevate(n);const d=this.chunks[n].writer.write(o);s?this.chunks[n].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 Ft(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 Ft(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=Mr,r=Mr,Mr.NOOP=async e=>{};class ne{constructor(t,n){if(n<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=n}static fromDecimalString(t,n){let[s,o]=t.split(".");return o=(o||"").padEnd(n,"0").slice(0,n),new ne(BigInt(s+o),n)}add(t){return this.assertSameScale(t),new ne(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new ne(this.value-t.value,this.scale)}multiply(t){return new ne(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const n=this.value/t,s=this.value%t;return[new ne(n,this.scale),new ne(s,this.scale)]}exchange(t,n,s){if(t==="*"){const d=this.value*n.value/10n**BigInt(this.scale);return new ne(d,s)}this.assertSameScale(n);const o=this.value*10n**BigInt(s)/n.value;return new ne(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(),n=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${n}.${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=ne;function Dd(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 Wt(e,t,n,s){const o=e.findIndex(v=>v===`--${t}`||v.startsWith(`--${t}=`)),d=e[o];if(!d)return(n||{})[s||t||""]||null;if(d.includes("="))return d.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(n||{})[s||t||""]||null}function Pd(e,t,n,s){const o=Wt(e,t,n,s);if(!o)return null;try{return Er(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function Ud(e,t,n,s){const o=e.some(m=>m.endsWith("-"+t)),d=Wt(e,t,n,s);if(!d&&o)return!0;if(!d&&!o)return null;const f=["true","1","yes","y","on"],v=["false","0","no","n","off"];if(f.includes(d.toLowerCase()))return!0;if(v.includes(d.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${d}`)}function di(e,t,n,s){const o=Wt(e,t,n,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function Zd(e,t,n,s){const o=di(e,t,n,s);try{return Er(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function fi(e,t){const n=e[t];e.splice(t,1),e.unshift(n)}function Bd(e,t){const n=[...e];return fi(n,t),n}function hi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Ld(e,t){return{x:e.x-t.x,y:e.y-t.y}}function $r(e,t){return{x:e.x*t,y:e.y*t}}function zd(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function pi(e,t,n){return{x:e.x+Math.cos(t)*n,y:e.y+Math.sin(t)*n}}function mi(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function ft(e,t,n="row-first"){const s=[];if(n==="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 Vd(e,t,n){var s,o;return((s=e[t+1])==null?void 0:s[n])&&((o=e[t-1])==null?void 0:o[n])&&!e[t][n-1]&&!e[t][n+1]}function Fd(e,t,n){var s,o;return e[t][n+1]&&e[t][n-1]&&!((s=e[t-1])!=null&&s[n])&&!((o=e[t+1])!=null&&o[n])}function gi(e,t,n){var s;return!((s=e[t-1])!=null&&s[n])}function yi(e,t,n){var s;return!((s=e[t+1])!=null&&s[n])}function vi(e,t,n){return!e[t][n-1]}function wi(e,t,n){return!e[t][n+1]}function Wd(e,t,n){var o,d,f,v,m,k,$,U;const s=[];return e[t][n]?Vd(e,t,n)||Fd(e,t,n)?[]:(!((o=e[t-1])!=null&&o[n-1])&&gi(e,t,n)&&vi(e,t,n)&&s.push({x:t,y:n}),!((d=e[t+1])!=null&&d[n-1])&&yi(e,t,n)&&vi(e,t,n)&&s.push({x:t+1,y:n}),!((f=e[t-1])!=null&&f[n+1])&&gi(e,t,n)&&wi(e,t,n)&&s.push({x:t,y:n+1}),!((v=e[t+1])!=null&&v[n+1])&&yi(e,t,n)&&wi(e,t,n)&&s.push({x:t+1,y:n+1}),s):((m=e[t-1])!=null&&m[n]&&e[t][n-1]&&s.push({x:t,y:n}),(k=e[t+1])!=null&&k[n]&&e[t][n-1]&&s.push({x:t+1,y:n}),($=e[t-1])!=null&&$[n]&&e[t][n+1]&&s.push({x:t,y:n+1}),(U=e[t+1])!=null&&U[n]&&e[t][n+1]&&s.push({x:t+1,y:n+1}),s)}function Hd(e,t,n,s){const o=[{x:0,y:0},{x:n,y:0},{x:0,y:s},{x:n,y:s}];for(let d=0;d<e.length;d++)for(let f=0;f<e[0].length;f++){const v=Wd(e,d,f);for(const m of v)o.some(k=>k.x===m.x&&k.y===m.y)||o.push(m)}return o.map(d=>({x:d.x*t,y:d.y*t}))}function qd(e,t){const n=ft(e,(m,k)=>e[m][k]===0&&e[m][k+1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),s=ft(e,(m,k)=>e[m][k]===0&&e[m][k-1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),o=ft(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m-1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1})),d=ft(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m+1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1}));n.forEach(m=>m.y++),d.forEach(m=>m.x++);const f=Tr([...o,...d],(m,k)=>m.x===k.x&&m.y-1===k.y),v=Tr([...s,...n],(m,k)=>m.y===k.y&&m.x-1===k.x);return[...f,...v].map(m=>({start:m[0],end:ot(m)})).map(m=>({start:$r(m.start,t),end:$r(hi(m.end,{x:m.start.dx,y:m.start.dy}),t)}))}function Gd(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function Kd(e,t){return t.map(n=>Gd(e,n)).sort((n,s)=>n-s)}function bi(e,t,n,s){const o=(s.y-n.y)*(t.x-e.x)-(s.x-n.x)*(t.y-e.y);if(o===0)return null;let d=e.y-n.y,f=e.x-n.x;const v=(s.x-n.x)*d-(s.y-n.y)*f,m=(t.x-e.x)*d-(t.y-e.y)*f;return d=v/o,f=m/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 Rr(e,t,n){const s=[],o=pi(e,n,1e4);for(const d of t){const f=bi(e,o,d.start,d.end);f&&s.push(f)}return s.length?s.reduce((d,f)=>{const v=mi(e,f),m=mi(e,d);return v<m?f:d}):null}function Yd(e,t,n){const s=Kd(e,n),o=[];for(const d of s){const f=Rr(e,t,d-.001),v=Rr(e,t,d+.001);f&&o.push(f),v&&o.push(v)}return o}class Cr{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(n=>n!==t)}}publish(t){this.subscribers.forEach(n=>n(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=Cr;class Qd{constructor(t,n){this.queue=[],this.running=0,this.onProcessed=new Cr,this.onDrained=new Cr,this.concurrency=t,this.capacity=n}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(n=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),n())})})}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=Qd,a.Binary={hexToUint8Array:ru,uint8ArrayToHex:nu,base64ToUint8Array:Xc,uint8ArrayToBase64:Jc,base32ToUint8Array:eu,uint8ArrayToBase32:tu,log2Reduce:Ys,partition:Or,concatBytes:Ze,numberToUint8:cd,uint8ToNumber:ud,numberToUint16:ld,uint16ToNumber:dd,numberToUint32:fd,uint32ToNumber:hd,numberToUint64:Ar,uint64ToNumber:pd,numberToUint256:Be,uint256ToNumber:Le,sliceBytes:md,keccak256:ue,sha3_256:yd,proximity:vd,commonPrefix:wd,setBit:bd,getBit:_d,indexOf:xd,equals:Td,padStart:ii,padStartToMultiple:kd,padEnd:ai,padEndToMultiple:Ed,xorCypher:Sd},a.Elliptic={privateKeyToPublicKey:Od,compressPublicKey:Id,publicKeyFromCompressed:Md,publicKeyToAddress:$d,signMessage:Cd,signHash:ci,verifySignature:jd,recoverPublicKey:Nd,checksumEncode:Rd},a.Random={intBetween:at,floatBetween:Jn,chance:es,signed:Ka,makeSeededRng:ir,point:Qa,procs:Xa},a.Arrays={countUnique:zl,makeUnique:Ll,splitBySize:Zl,splitByCount:Hs,index:Ws,indexCollection:Ul,onlyOrThrow:p,onlyOrNull:g,firstOrThrow:E,firstOrNull:y,shuffle:h,initialize:j,initialize2D:ce,rotate2D:oe,containsShape:it,glue:oc,pluck:sr,pick:ar,pickMany:Ja,pickManyUnique:eo,pickWeighted:no,pickRandomIndices:je,pickGuaranteed:to,last:ot,pipe:ts,makePipe:ro,sortWeighted:so,pushAll:jt,unshiftAll:ic,filterAndRemove:Tu,merge:_l,empty:xl,pushToBucket:rc,unshiftAndLimit:nc,atRolling:sc,group:Tr,createOscillator:cl,organiseWithLimits:ll,tickPlaybook:Dd,getArgument:Wt,getBooleanArgument:Ud,getNumberArgument:Pd,requireStringArgument:di,requireNumberArgument:Zd,bringToFront:Bd,bringToFrontInPlace:fi,findInstance:td,filterInstances:rd,interleave:nd,toggle:sd,createHierarchy:ad,multicall:Jl,maxBy:ed},a.System={sleepMillis:l,forever:lo,scheduleMany:pc,waitFor:Su,expandError:Xo,runAndSetInterval:fo},a.Numbers={make:Er,sum:gc,average:yc,median:vc,getDistanceFromMidpoint:wc,clamp:Sr,range:ps,interpolate:mc,createSequence:ol,increment:yl,decrement:vl,format:gl,fromDecimals:ml,makeStorage:Qu,asMegabytes:ho,convertBytes:po,hexToRgb:mo,rgbToHex:go,haversineDistanceToMeters:yo,roundToNearest:$t,formatDistance:vo,triangularNumber:wo,searchFloat:bo},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:ju,getTimeDelta:Ds,secondsToHumanTime:Du,countCycles:Pu,isoDate:Iu,throttle:Uu,timeSince:Bu,dateTimeSlug:Mu,unixTimestamp:Ou,fromUtcString:$u,fromMillis:Ru,getProgress:Lu,humanizeTime:Zt,humanizeProgress:Eu,createTimeDigits:re,mapDayNumber:Ps,getDayInfoFromDate:xr,getDayInfoFromDateTimeString:Vu,seconds:Fu,minutes:Wu,hours:Hu,days:qu,make:Ku,normalizeTime:Cu,absoluteDays:Te},a.Objects={safeParse:al,deleteDeep:oo,getDeep:ke,setDeep:Ee,incrementDeep:io,ensureDeep:ao,replaceDeep:co,getFirstDeep:uo,deepMergeInPlace:Se,deepMerge2:Jo,deepMerge3:ec,mapAllAsync:ac,cloneWithJson:Au,sortObject:Zs,sortArray:Bs,sortAny:Ae,deepEquals:Ls,deepEqualsEvery:il,runOn:wl,ifPresent:bl,zip:hs,zipSum:tc,removeEmptyArrays:kl,removeEmptyValues:El,flatten:Dl,unflatten:Fs,match:Pl,sort:Gs,map:Al,mapIterable:Ol,filterKeys:Sl,filterValues:Tl,rethrow:Il,setSomeOnObject:Ml,setSomeDeep:$l,flip:Rl,getAllPermutations:Cl,countTruthyValues:Nl,transformToArray:Vl,setMulti:Wl,incrementMulti:Fl,createBidirectionalMap:Hl,createTemporalBidirectionalMap:ql,pushToBidirectionalMap:Ks,unshiftToBidirectionalMap:Gl,addToTemporalBidirectionalMap:Kl,getFromTemporalBidirectionalMap:Yl,createStatefulToggle:ul,diffKeys:dl,pickRandomKey:zs,mapRandomKey:fl,fromObjectString:hl,toQueryString:Ns,parseQueryString:gu,hasKey:yu,selectMax:vu,reposition:wu,unwrapSingleKey:bu,parseKeyValues:_u},a.Types={isFunction:cr,isObject:me,isStrictlyObject:De,isEmptyArray:rs,isEmptyObject:_o,isUndefined:or,isString:H,isNumber:ge,isBoolean:ns,isDate:Pe,isBlank:Rt,isId:ur,isIntegerString:ss,isHexString:is,isUrl:ds,isNullable:Go,asString:us,asHexString:No,asSafeString:jo,asIntegerString:Co,asNumber:Ct,asFunction:Do,asInteger:fr,asBoolean:Po,asDate:Uo,asNullableString:Zo,asEmptiableString:Bo,asId:Lo,asTime:zo,asArray:Vo,asObject:Nt,asNullableObject:Fo,asStringMap:Wo,asNumericDictionary:Ho,asUrl:qo,asNullable:Ko,asOptional:Yo,enforceObjectShape:fs,enforceArrayShape:Qo,isPng:Qs,isJpg:Xs,isWebp:Js,isImage:od},a.Strings={tokenizeByCount:Bl,tokenizeByLength:qs,searchHex:Mo,searchSubstring:$o,randomHex:Ro,randomLetter:To,randomAlphanumeric:Ao,randomRichAscii:Oo,randomUnicode:Io,includesAny:bc,slugify:hr,normalForm:xc,enumify:Oc,escapeHtml:Mc,decodeHtmlEntities:Rc,after:pr,afterLast:gs,before:ms,beforeLast:mr,betweenWide:Cc,betweenNarrow:Nc,getPreLine:Xu,containsWord:br,containsWords:fu,joinUrl:Us,getFuzzyMatchScore:Dt,sortByFuzzyScore:Ic,splitOnce:gr,splitAll:ys,randomize:Uc,expand:vs,shrinkTrim:ut,capitalize:Pt,decapitalize:ws,csvEscape:Fc,parseCsv:ku,surroundInOut:Ac,getExtension:yr,getBasename:vr,normalizeEmail:jc,normalizeFilename:Dc,parseFilename:Pc,camelToTitle:kc,slugToTitle:Ec,slugToCamel:Sc,joinHumanly:Tc,findWeightedPair:Ss,extractBlock:Ts,extractAllBlocks:qc,replaceBlocks:Gc,indexOfEarliest:Ue,lastIndexOfBefore:Es,parseHtmlAttributes:hu,readNextWord:Ut,resolveVariables:pu,resolveVariableWithDefaultSyntax:Rs,resolveRemainingVariablesWithDefaults:Cs,isLetter:bs,isDigit:_s,isLetterOrDigit:lt,isValidObjectPathCharacter:Lc,insert:zc,indexOfRegex:xs,lineMatches:ks,linesMatchInOrder:Vc,represent:ct,resolveMarkdownLinks:mu,buildUrl:xu,isChinese:_c,replaceBetweenStrings:tl,describeMarkdown:rl,isBalanced:nl,textToFormat:sl,splitFormatting:Kc,splitHashtags:Yc,splitUrls:Qc,route:su,explodeReplace:wr,generateVariants:iu,replaceWord:au,replacePascalCaseWords:ou,stripHtml:cu,breakLine:$s,measureTextWidth:uu,toLines:lu,levenshteinDistance:du},a.Assertions={asEqual:cc,asTrue:uc,asTruthy:lc,asFalse:dc,asFalsy:fc,asEither:hc},a.Cache={get:Ju,invalidate:el},a.Vector={addPoint:hi,subtractPoint:Ld,multiplyPoint:$r,normalizePoint:zd,pushPoint:pi,filterCoordinates:ft,findCorners:Hd,findLines:qd,raycast:Rr,raycastCircle:Yd,getLineIntersectionPoint:bi}})(Cn);const C=Si(Cn);C.Arrays,C.Assertions;const B=C.Binary;C.Cache,C.Dates,C.Elliptic,C.Numbers,C.Objects,C.Pagination,C.Promises,C.Random,C.Strings,C.System,C.Types,C.Optional,C.Vector,C.PubSubChannel,C.Chunk;const Ti=C.MerkleTree;C.FixedPointNumber,C.Lazy,C.AsyncLazy,C.AsyncQueue,C.Uint8ArrayReader,C.Uint8ArrayWriter;const Ai=new TextEncoder,Nn=1,jn=4096,qt=4096,Oi=32;function Dn(a,r){return r=typeof r=="number"?A.FeedIndex.fromBigInt(BigInt(r)):r,new A.Identifier(B.keccak256(B.concatBytes(a.toUint8Array(),r.toUint8Array())))}function Ii(a){const r=a.slice(0,A.Span.LENGTH),i=a.slice(A.Span.LENGTH),c=Mi(i),u=B.keccak256(B.concatBytes(r,c));return new A.Reference(u)}function Mi(a){if(a.length>qt)throw new A.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${qt}`,a);const r=new Uint8Array(qt);return r.set(a),B.log2Reduce(B.partition(r,Oi),(i,c)=>B.keccak256(B.concatBytes(i,c)))}function Pn(a){if(a instanceof Uint8Array||(a=Ai.encode(a)),a.length<Nn||a.length>jn)throw new RangeError(`payload size ${a.length} exceeds limits [${Nn}, ${jn}]`);const r=A.Span.fromBigInt(BigInt(a.length)),i=B.concatBytes(r.toUint8Array(),a);return{data:i,span:r,payload:A.Bytes.fromSlice(i,A.Span.LENGTH),address:Ii(i)}}function $i(a,r){return new A.Reference(B.keccak256(B.concatBytes(a.toUint8Array(),r.toUint8Array())))}function Un(a,r,i){r=new A.Identifier(r),i=new A.PrivateKey(i);const c=$i(r,i.publicKey().address()),u=i.sign(B.concatBytes(r.toUint8Array(),a.address.toUint8Array())),l=B.concatBytes(r.toUint8Array(),u.toUint8Array(),a.data),h=A.Span.fromSlice(a.data,0),p=A.Bytes.fromSlice(a.data,A.Span.LENGTH);return{data:l,identifier:r,signature:u,span:h,payload:p,address:c,owner:i.publicKey().address()}}const Ri=q.getInstance(),Ci=X.getInstance();function Ni(a){return new Promise(r=>{setTimeout(r,a)})}function Gt(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}async function Kt(a,r=3,i=250){return new Promise((c,u)=>{a().then(c).catch(l=>{r>0?(Ri.info(`Retrying... Attempts left: ${r}. Error: ${l.message}`),setTimeout(()=>{Kt(a,r-1,i).then(c).catch(u)},i)):(Ci.handleError(l,"Utils.retryAwaitableAsync"),u(l))})})}class ji{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(r,i){this.events[r]||(this.events[r]=[]),this.events[r].push(i)}off(r,i){if(!this.events[r])return;const c=this.events[r].indexOf(i);c>-1&&this.events[r].splice(c,1)}cleanAll(){this.events={}}emit(r,i){this.events[r]&&this.events[r].forEach(c=>c(i))}}var M;(function(a){a.assertEqual=u=>u;function r(u){}a.assertIs=r;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(p=>typeof u[u[p]]!="number"),h={};for(const p of l)h[p]=u[p];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})(M||(M={}));var Yt;(function(a){a.mergeShapes=(r,i)=>({...r,...i})})(Yt||(Yt={}));const _=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),se=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}},w=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"]),Di=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class F extends Error{get errors(){return this.issues}constructor(r){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=r}format(r){const i=r||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 p=c,g=0;for(;g<h.path.length;){const y=h.path[g];g===h.path.length-1?(p[y]=p[y]||{_errors:[]},p[y]._errors.push(i(h))):p[y]=p[y]||{_errors:[]},p=p[y],g++}}};return u(this),c}static assert(r){if(!(r instanceof F))throw new Error(`Not a ZodError: ${r}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(r=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(r(u))):c.push(r(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}F.create=a=>new F(a);const Ie=(a,r)=>{let i;switch(a.code){case w.invalid_type:a.received===_.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case w.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,M.jsonStringifyReplacer)}`;break;case w.unrecognized_keys:i=`Unrecognized key(s) in object: ${M.joinValues(a.keys,", ")}`;break;case w.invalid_union:i="Invalid input";break;case w.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${M.joinValues(a.options)}`;break;case w.invalid_enum_value:i=`Invalid enum value. Expected ${M.joinValues(a.options)}, received '${a.received}'`;break;case w.invalid_arguments:i="Invalid function arguments";break;case w.invalid_return_type:i="Invalid function return type";break;case w.invalid_date:i="Invalid date";break;case w.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 w.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 w.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 w.custom:i="Invalid input";break;case w.invalid_intersection_types:i="Intersection results could not be merged";break;case w.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case w.not_finite:i="Number must be finite";break;default:i=r.defaultError,M.assertNever(a)}return{message:i}};let Zn=Ie;function Pi(a){Zn=a}function kt(){return Zn}const Et=a=>{const{data:r,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 p="";const g=c.filter(y=>!!y).slice().reverse();for(const y of g)p=y(h,{data:r,defaultError:p}).message;return{...u,path:l,message:p}},Ui=[];function b(a,r){const i=kt(),c=Et({issueData:r,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Ie?void 0:Ie].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(r,i){const c=[];for(const u of i){if(u.status==="aborted")return T;u.status==="dirty"&&r.dirty(),c.push(u.value)}return{status:r.value,value:c}}static async mergeObjectAsync(r,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(r,c)}static mergeObjectSync(r,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"&&r.dirty(),h.status==="dirty"&&r.dirty(),l.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[l.value]=h.value)}return{status:r.value,value:c}}}const T=Object.freeze({status:"aborted"}),Me=a=>({status:"dirty",value:a}),V=a=>({status:"valid",value:a}),Qt=a=>a.status==="aborted",Xt=a=>a.status==="dirty",we=a=>a.status==="valid",Ve=a=>typeof Promise<"u"&&a instanceof Promise;function St(a,r,i,c){if(typeof r=="function"?a!==r||!c:!r.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r.get(a)}function Bn(a,r,i,c,u){if(typeof r=="function"?a!==r||!u:!r.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r.set(a,i),i}typeof SuppressedError=="function"&&SuppressedError;var x;(function(a){a.errToObj=r=>typeof r=="string"?{message:r}:r||{},a.toString=r=>typeof r=="string"?r:r==null?void 0:r.message})(x||(x={}));var Fe,We;class J{constructor(r,i,c,u){this._cachedPath=[],this.parent=r,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 Ln=(a,r)=>{if(we(r))return{success:!0,data:r.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:r,invalid_type_error:i,required_error:c,description:u}=a;if(r&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return r?{errorMap:r,description:u}:{errorMap:(h,p)=>{var g,y;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??p.defaultError}:typeof p.data>"u"?{message:(g=E??c)!==null&&g!==void 0?g:p.defaultError}:h.code!=="invalid_type"?{message:p.defaultError}:{message:(y=E??i)!==null&&y!==void 0?y:p.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(r){return se(r.data)}_getOrReturnCtx(r,i){return i||{common:r.parent.common,data:r.data,parsedType:se(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}_processInputParams(r){return{status:new L,ctx:{common:r.parent.common,data:r.data,parsedType:se(r.data),schemaErrorMap:this._def.errorMap,path:r.path,parent:r.parent}}}_parseSync(r){const i=this._parse(r);if(Ve(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(r){const i=this._parse(r);return Promise.resolve(i)}parse(r,i){const c=this.safeParse(r,i);if(c.success)return c.data;throw c.error}safeParse(r,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:r,parsedType:se(r)},l=this._parseSync({data:r,path:u.path,parent:u});return Ln(u,l)}"~validate"(r){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:r,parsedType:se(r)};if(!this["~standard"].async)try{const l=this._parseSync({data:r,path:[],parent:u});return we(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:r,path:[],parent:u}).then(l=>we(l)?{value:l.value}:{issues:u.common.issues})}async parseAsync(r,i){const c=await this.safeParseAsync(r,i);if(c.success)return c.data;throw c.error}async safeParseAsync(r,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:r,parsedType:se(r)},u=this._parse({data:r,path:c.path,parent:c}),l=await(Ve(u)?u:Promise.resolve(u));return Ln(c,l)}refine(r,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=r(u),p=()=>l.addIssue({code:w.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(g=>g?!0:(p(),!1)):h?!0:(p(),!1)})}refinement(r,i){return this._refinement((c,u)=>r(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(r){return new Y({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:r}})}superRefine(r){return this._refinement(r)}constructor(r){this.spa=this.safeParseAsync,this._def=r,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 te.create(this,this._def)}nullable(){return he.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return K.create(this)}promise(){return Ne.create(this,this._def)}or(r){return Ke.create([this,r],this._def)}and(r){return Ye.create(this,r,this._def)}transform(r){return new Y({...O(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:r}})}default(r){const i=typeof r=="function"?r:()=>r;return new tt({...O(this._def),innerType:this,defaultValue:i,typeName:S.ZodDefault})}brand(){return new tr({typeName:S.ZodBranded,type:this,...O(this._def)})}catch(r){const i=typeof r=="function"?r:()=>r;return new rt({...O(this._def),innerType:this,catchValue:i,typeName:S.ZodCatch})}describe(r){const i=this.constructor;return new i({...this._def,description:r})}pipe(r){return nt.create(this,r)}readonly(){return st.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Zi=/^c[^\s-]{8,}$/i,Bi=/^[0-9a-z]+$/,Li=/^[0-9A-HJKMNP-TV-Z]{26}$/i,zi=/^[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,Vi=/^[a-z0-9_-]{21}$/i,Fi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Wi=/^[-+]?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)?)??$/,Hi=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,qi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Jt;const Gi=/^(?:(?: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])$/,Ki=/^(?:(?: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])$/,Yi=/^(([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]))$/,Qi=/^(([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])$/,Xi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ji=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,zn="((\\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])))",ea=new RegExp(`^${zn}$`);function Vn(a){let r="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?r=`${r}\\.\\d{${a.precision}}`:a.precision==null&&(r=`${r}(\\.\\d+)?`),r}function ta(a){return new RegExp(`^${Vn(a)}$`)}function Fn(a){let r=`${zn}T${Vn(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),r=`${r}(${i.join("|")})`,new RegExp(`^${r}$`)}function ra(a,r){return!!((r==="v4"||!r)&&Gi.test(a)||(r==="v6"||!r)&&Yi.test(a))}function na(a,r){if(!Fi.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||r&&u.alg!==r)}catch{return!1}}function sa(a,r){return!!((r==="v4"||!r)&&Ki.test(a)||(r==="v6"||!r)&&Qi.test(a))}class G extends I{_parse(r){if(this._def.coerce&&(r.data=String(r.data)),this._getType(r)!==_.string){const l=this._getOrReturnCtx(r);return b(l,{code:w.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")r.data.length<l.value&&(u=this._getOrReturnCtx(r,u),b(u,{code:w.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="max")r.data.length>l.value&&(u=this._getOrReturnCtx(r,u),b(u,{code:w.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="length"){const h=r.data.length>l.value,p=r.data.length<l.value;(h||p)&&(u=this._getOrReturnCtx(r,u),h?b(u,{code:w.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):p&&b(u,{code:w.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),c.dirty())}else if(l.kind==="email")Hi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"email",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="emoji")Jt||(Jt=new RegExp(qi,"u")),Jt.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"emoji",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="uuid")zi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"uuid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="nanoid")Vi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"nanoid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid")Zi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"cuid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid2")Bi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"cuid2",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="ulid")Li.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"ulid",code:w.invalid_string,message:l.message}),c.dirty());else if(l.kind==="url")try{new URL(r.data)}catch{u=this._getOrReturnCtx(r,u),b(u,{validation:"url",code:w.invalid_string,message:l.message}),c.dirty()}else l.kind==="regex"?(l.regex.lastIndex=0,l.regex.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"regex",code:w.invalid_string,message:l.message}),c.dirty())):l.kind==="trim"?r.data=r.data.trim():l.kind==="includes"?r.data.includes(l.value,l.position)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),c.dirty()):l.kind==="toLowerCase"?r.data=r.data.toLowerCase():l.kind==="toUpperCase"?r.data=r.data.toUpperCase():l.kind==="startsWith"?r.data.startsWith(l.value)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:{startsWith:l.value},message:l.message}),c.dirty()):l.kind==="endsWith"?r.data.endsWith(l.value)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:{endsWith:l.value},message:l.message}),c.dirty()):l.kind==="datetime"?Fn(l).test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:"datetime",message:l.message}),c.dirty()):l.kind==="date"?ea.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:"date",message:l.message}),c.dirty()):l.kind==="time"?ta(l).test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{code:w.invalid_string,validation:"time",message:l.message}),c.dirty()):l.kind==="duration"?Wi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"duration",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="ip"?ra(r.data,l.version)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"ip",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="jwt"?na(r.data,l.alg)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"jwt",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="cidr"?sa(r.data,l.version)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"cidr",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="base64"?Xi.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"base64",code:w.invalid_string,message:l.message}),c.dirty()):l.kind==="base64url"?Ji.test(r.data)||(u=this._getOrReturnCtx(r,u),b(u,{validation:"base64url",code:w.invalid_string,message:l.message}),c.dirty()):M.assertNever(l);return{status:c.value,value:r.data}}_regex(r,i,c){return this.refinement(u=>r.test(u),{validation:i,code:w.invalid_string,...x.errToObj(c)})}_addCheck(r){return new G({...this._def,checks:[...this._def.checks,r]})}email(r){return this._addCheck({kind:"email",...x.errToObj(r)})}url(r){return this._addCheck({kind:"url",...x.errToObj(r)})}emoji(r){return this._addCheck({kind:"emoji",...x.errToObj(r)})}uuid(r){return this._addCheck({kind:"uuid",...x.errToObj(r)})}nanoid(r){return this._addCheck({kind:"nanoid",...x.errToObj(r)})}cuid(r){return this._addCheck({kind:"cuid",...x.errToObj(r)})}cuid2(r){return this._addCheck({kind:"cuid2",...x.errToObj(r)})}ulid(r){return this._addCheck({kind:"ulid",...x.errToObj(r)})}base64(r){return this._addCheck({kind:"base64",...x.errToObj(r)})}base64url(r){return this._addCheck({kind:"base64url",...x.errToObj(r)})}jwt(r){return this._addCheck({kind:"jwt",...x.errToObj(r)})}ip(r){return this._addCheck({kind:"ip",...x.errToObj(r)})}cidr(r){return this._addCheck({kind:"cidr",...x.errToObj(r)})}datetime(r){var i,c;return typeof r=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:r}):this._addCheck({kind:"datetime",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,offset:(i=r==null?void 0:r.offset)!==null&&i!==void 0?i:!1,local:(c=r==null?void 0:r.local)!==null&&c!==void 0?c:!1,...x.errToObj(r==null?void 0:r.message)})}date(r){return this._addCheck({kind:"date",message:r})}time(r){return typeof r=="string"?this._addCheck({kind:"time",precision:null,message:r}):this._addCheck({kind:"time",precision:typeof(r==null?void 0:r.precision)>"u"?null:r==null?void 0:r.precision,...x.errToObj(r==null?void 0:r.message)})}duration(r){return this._addCheck({kind:"duration",...x.errToObj(r)})}regex(r,i){return this._addCheck({kind:"regex",regex:r,...x.errToObj(i)})}includes(r,i){return this._addCheck({kind:"includes",value:r,position:i==null?void 0:i.position,...x.errToObj(i==null?void 0:i.message)})}startsWith(r,i){return this._addCheck({kind:"startsWith",value:r,...x.errToObj(i)})}endsWith(r,i){return this._addCheck({kind:"endsWith",value:r,...x.errToObj(i)})}min(r,i){return this._addCheck({kind:"min",value:r,...x.errToObj(i)})}max(r,i){return this._addCheck({kind:"max",value:r,...x.errToObj(i)})}length(r,i){return this._addCheck({kind:"length",value:r,...x.errToObj(i)})}nonempty(r){return this.min(1,x.errToObj(r))}trim(){return new G({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new G({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new G({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(r=>r.kind==="datetime")}get isDate(){return!!this._def.checks.find(r=>r.kind==="date")}get isTime(){return!!this._def.checks.find(r=>r.kind==="time")}get isDuration(){return!!this._def.checks.find(r=>r.kind==="duration")}get isEmail(){return!!this._def.checks.find(r=>r.kind==="email")}get isURL(){return!!this._def.checks.find(r=>r.kind==="url")}get isEmoji(){return!!this._def.checks.find(r=>r.kind==="emoji")}get isUUID(){return!!this._def.checks.find(r=>r.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(r=>r.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(r=>r.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(r=>r.kind==="cuid2")}get isULID(){return!!this._def.checks.find(r=>r.kind==="ulid")}get isIP(){return!!this._def.checks.find(r=>r.kind==="ip")}get isCIDR(){return!!this._def.checks.find(r=>r.kind==="cidr")}get isBase64(){return!!this._def.checks.find(r=>r.kind==="base64")}get isBase64url(){return!!this._def.checks.find(r=>r.kind==="base64url")}get minLength(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxLength(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}}G.create=a=>{var r;return new G({checks:[],typeName:S.ZodString,coerce:(r=a==null?void 0:a.coerce)!==null&&r!==void 0?r:!1,...O(a)})};function ia(a,r){const i=(a.toString().split(".")[1]||"").length,c=(r.toString().split(".")[1]||"").length,u=i>c?i:c,l=parseInt(a.toFixed(u).replace(".","")),h=parseInt(r.toFixed(u).replace(".",""));return l%h/Math.pow(10,u)}class le extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(r){if(this._def.coerce&&(r.data=Number(r.data)),this._getType(r)!==_.number){const l=this._getOrReturnCtx(r);return b(l,{code:w.invalid_type,expected:_.number,received:l.parsedType}),T}let c;const u=new L;for(const l of this._def.checks)l.kind==="int"?M.isInteger(r.data)||(c=this._getOrReturnCtx(r,c),b(c,{code:w.invalid_type,expected:"integer",received:"float",message:l.message}),u.dirty()):l.kind==="min"?(l.inclusive?r.data<l.value:r.data<=l.value)&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.too_small,minimum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?r.data>l.value:r.data>=l.value)&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.too_big,maximum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="multipleOf"?ia(r.data,l.value)!==0&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):l.kind==="finite"?Number.isFinite(r.data)||(c=this._getOrReturnCtx(r,c),b(c,{code:w.not_finite,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:r.data}}gte(r,i){return this.setLimit("min",r,!0,x.toString(i))}gt(r,i){return this.setLimit("min",r,!1,x.toString(i))}lte(r,i){return this.setLimit("max",r,!0,x.toString(i))}lt(r,i){return this.setLimit("max",r,!1,x.toString(i))}setLimit(r,i,c,u){return new le({...this._def,checks:[...this._def.checks,{kind:r,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(r){return new le({...this._def,checks:[...this._def.checks,r]})}int(r){return this._addCheck({kind:"int",message:x.toString(r)})}positive(r){return this._addCheck({kind:"min",value:0,inclusive:!1,message:x.toString(r)})}negative(r){return this._addCheck({kind:"max",value:0,inclusive:!1,message:x.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:0,inclusive:!0,message:x.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:0,inclusive:!0,message:x.toString(r)})}multipleOf(r,i){return this._addCheck({kind:"multipleOf",value:r,message:x.toString(i)})}finite(r){return this._addCheck({kind:"finite",message:x.toString(r)})}safe(r){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:x.toString(r)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:x.toString(r)})}get minValue(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxValue(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}get isInt(){return!!this._def.checks.find(r=>r.kind==="int"||r.kind==="multipleOf"&&M.isInteger(r.value))}get isFinite(){let r=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"&&(r===null||c.value<r)&&(r=c.value)}return Number.isFinite(i)&&Number.isFinite(r)}}le.create=a=>new le({checks:[],typeName:S.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class de extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(r){if(this._def.coerce)try{r.data=BigInt(r.data)}catch{return this._getInvalidInput(r)}if(this._getType(r)!==_.bigint)return this._getInvalidInput(r);let c;const u=new L;for(const l of this._def.checks)l.kind==="min"?(l.inclusive?r.data<l.value:r.data<=l.value)&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.too_small,type:"bigint",minimum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?r.data>l.value:r.data>=l.value)&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.too_big,type:"bigint",maximum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="multipleOf"?r.data%l.value!==BigInt(0)&&(c=this._getOrReturnCtx(r,c),b(c,{code:w.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:r.data}}_getInvalidInput(r){const i=this._getOrReturnCtx(r);return b(i,{code:w.invalid_type,expected:_.bigint,received:i.parsedType}),T}gte(r,i){return this.setLimit("min",r,!0,x.toString(i))}gt(r,i){return this.setLimit("min",r,!1,x.toString(i))}lte(r,i){return this.setLimit("max",r,!0,x.toString(i))}lt(r,i){return this.setLimit("max",r,!1,x.toString(i))}setLimit(r,i,c,u){return new de({...this._def,checks:[...this._def.checks,{kind:r,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(r){return new de({...this._def,checks:[...this._def.checks,r]})}positive(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:x.toString(r)})}negative(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:x.toString(r)})}nonpositive(r){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:x.toString(r)})}nonnegative(r){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:x.toString(r)})}multipleOf(r,i){return this._addCheck({kind:"multipleOf",value:r,message:x.toString(i)})}get minValue(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r}get maxValue(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r}}de.create=a=>{var r;return new de({checks:[],typeName:S.ZodBigInt,coerce:(r=a==null?void 0:a.coerce)!==null&&r!==void 0?r:!1,...O(a)})};class He extends I{_parse(r){if(this._def.coerce&&(r.data=!!r.data),this._getType(r)!==_.boolean){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.boolean,received:c.parsedType}),T}return V(r.data)}}He.create=a=>new He({typeName:S.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class be extends I{_parse(r){if(this._def.coerce&&(r.data=new Date(r.data)),this._getType(r)!==_.date){const l=this._getOrReturnCtx(r);return b(l,{code:w.invalid_type,expected:_.date,received:l.parsedType}),T}if(isNaN(r.data.getTime())){const l=this._getOrReturnCtx(r);return b(l,{code:w.invalid_date}),T}const c=new L;let u;for(const l of this._def.checks)l.kind==="min"?r.data.getTime()<l.value&&(u=this._getOrReturnCtx(r,u),b(u,{code:w.too_small,message:l.message,inclusive:!0,exact:!1,minimum:l.value,type:"date"}),c.dirty()):l.kind==="max"?r.data.getTime()>l.value&&(u=this._getOrReturnCtx(r,u),b(u,{code:w.too_big,message:l.message,inclusive:!0,exact:!1,maximum:l.value,type:"date"}),c.dirty()):M.assertNever(l);return{status:c.value,value:new Date(r.data.getTime())}}_addCheck(r){return new be({...this._def,checks:[...this._def.checks,r]})}min(r,i){return this._addCheck({kind:"min",value:r.getTime(),message:x.toString(i)})}max(r,i){return this._addCheck({kind:"max",value:r.getTime(),message:x.toString(i)})}get minDate(){let r=null;for(const i of this._def.checks)i.kind==="min"&&(r===null||i.value>r)&&(r=i.value);return r!=null?new Date(r):null}get maxDate(){let r=null;for(const i of this._def.checks)i.kind==="max"&&(r===null||i.value<r)&&(r=i.value);return r!=null?new Date(r):null}}be.create=a=>new be({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:S.ZodDate,...O(a)});class Tt extends I{_parse(r){if(this._getType(r)!==_.symbol){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.symbol,received:c.parsedType}),T}return V(r.data)}}Tt.create=a=>new Tt({typeName:S.ZodSymbol,...O(a)});class qe extends I{_parse(r){if(this._getType(r)!==_.undefined){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.undefined,received:c.parsedType}),T}return V(r.data)}}qe.create=a=>new qe({typeName:S.ZodUndefined,...O(a)});class Ge extends I{_parse(r){if(this._getType(r)!==_.null){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.null,received:c.parsedType}),T}return V(r.data)}}Ge.create=a=>new Ge({typeName:S.ZodNull,...O(a)});class $e extends I{constructor(){super(...arguments),this._any=!0}_parse(r){return V(r.data)}}$e.create=a=>new $e({typeName:S.ZodAny,...O(a)});class _e extends I{constructor(){super(...arguments),this._unknown=!0}_parse(r){return V(r.data)}}_e.create=a=>new _e({typeName:S.ZodUnknown,...O(a)});class ie extends I{_parse(r){const i=this._getOrReturnCtx(r);return b(i,{code:w.invalid_type,expected:_.never,received:i.parsedType}),T}}ie.create=a=>new ie({typeName:S.ZodNever,...O(a)});class At extends I{_parse(r){if(this._getType(r)!==_.undefined){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.void,received:c.parsedType}),T}return V(r.data)}}At.create=a=>new At({typeName:S.ZodVoid,...O(a)});class K extends I{_parse(r){const{ctx:i,status:c}=this._processInputParams(r),u=this._def;if(i.parsedType!==_.array)return b(i,{code:w.invalid_type,expected:_.array,received:i.parsedType}),T;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,p=i.data.length<u.exactLength.value;(h||p)&&(b(i,{code:h?w.too_big:w.too_small,minimum:p?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:w.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:w.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,p)=>u.type._parseAsync(new J(i,h,i.path,p)))).then(h=>L.mergeArray(c,h));const l=[...i.data].map((h,p)=>u.type._parseSync(new J(i,h,i.path,p)));return L.mergeArray(c,l)}get element(){return this._def.type}min(r,i){return new K({...this._def,minLength:{value:r,message:x.toString(i)}})}max(r,i){return new K({...this._def,maxLength:{value:r,message:x.toString(i)}})}length(r,i){return new K({...this._def,exactLength:{value:r,message:x.toString(i)}})}nonempty(r){return this.min(1,r)}}K.create=(a,r)=>new K({type:a,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...O(r)});function Re(a){if(a instanceof N){const r={};for(const i in a.shape){const c=a.shape[i];r[i]=te.create(Re(c))}return new N({...a._def,shape:()=>r})}else return a instanceof K?new K({...a._def,type:Re(a.element)}):a instanceof te?te.create(Re(a.unwrap())):a instanceof he?he.create(Re(a.unwrap())):a instanceof ee?ee.create(a.items.map(r=>Re(r))):a}class N 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 r=this._def.shape(),i=M.objectKeys(r);return this._cached={shape:r,keys:i}}_parse(r){if(this._getType(r)!==_.object){const y=this._getOrReturnCtx(r);return b(y,{code:w.invalid_type,expected:_.object,received:y.parsedType}),T}const{status:c,ctx:u}=this._processInputParams(r),{shape:l,keys:h}=this._getCached(),p=[];if(!(this._def.catchall instanceof ie&&this._def.unknownKeys==="strip"))for(const y in u.data)h.includes(y)||p.push(y);const g=[];for(const y of h){const E=l[y],j=u.data[y];g.push({key:{status:"valid",value:y},value:E._parse(new J(u,j,u.path,y)),alwaysSet:y in u.data})}if(this._def.catchall instanceof ie){const y=this._def.unknownKeys;if(y==="passthrough")for(const E of p)g.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(y==="strict")p.length>0&&(b(u,{code:w.unrecognized_keys,keys:p}),c.dirty());else if(y!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const y=this._def.catchall;for(const E of p){const j=u.data[E];g.push({key:{status:"valid",value:E},value:y._parse(new J(u,j,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const y=[];for(const E of g){const j=await E.key,oe=await E.value;y.push({key:j,value:oe,alwaysSet:E.alwaysSet})}return y}).then(y=>L.mergeObjectSync(c,y)):L.mergeObjectSync(c,g)}get shape(){return this._def.shape()}strict(r){return x.errToObj,new N({...this._def,unknownKeys:"strict",...r!==void 0?{errorMap:(i,c)=>{var u,l,h,p;const g=(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:(p=x.errToObj(r).message)!==null&&p!==void 0?p:g}:{message:g}}}:{}})}strip(){return new N({...this._def,unknownKeys:"strip"})}passthrough(){return new N({...this._def,unknownKeys:"passthrough"})}extend(r){return new N({...this._def,shape:()=>({...this._def.shape(),...r})})}merge(r){return new N({unknownKeys:r._def.unknownKeys,catchall:r._def.catchall,shape:()=>({...this._def.shape(),...r._def.shape()}),typeName:S.ZodObject})}setKey(r,i){return this.augment({[r]:i})}catchall(r){return new N({...this._def,catchall:r})}pick(r){const i={};return M.objectKeys(r).forEach(c=>{r[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new N({...this._def,shape:()=>i})}omit(r){const i={};return M.objectKeys(this.shape).forEach(c=>{r[c]||(i[c]=this.shape[c])}),new N({...this._def,shape:()=>i})}deepPartial(){return Re(this)}partial(r){const i={};return M.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];r&&!r[c]?i[c]=u:i[c]=u.optional()}),new N({...this._def,shape:()=>i})}required(r){const i={};return M.objectKeys(this.shape).forEach(c=>{if(r&&!r[c])i[c]=this.shape[c];else{let l=this.shape[c];for(;l instanceof te;)l=l._def.innerType;i[c]=l}}),new N({...this._def,shape:()=>i})}keyof(){return Wn(M.objectKeys(this.shape))}}N.create=(a,r)=>new N({shape:()=>a,unknownKeys:"strip",catchall:ie.create(),typeName:S.ZodObject,...O(r)}),N.strictCreate=(a,r)=>new N({shape:()=>a,unknownKeys:"strict",catchall:ie.create(),typeName:S.ZodObject,...O(r)}),N.lazycreate=(a,r)=>new N({shape:a,unknownKeys:"strip",catchall:ie.create(),typeName:S.ZodObject,...O(r)});class Ke extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c=this._def.options;function u(l){for(const p of l)if(p.result.status==="valid")return p.result;for(const p of l)if(p.result.status==="dirty")return i.common.issues.push(...p.ctx.common.issues),p.result;const h=l.map(p=>new F(p.ctx.common.issues));return b(i,{code:w.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 g of c){const y={...i,common:{...i.common,issues:[]},parent:null},E=g._parseSync({data:i.data,path:i.path,parent:y});if(E.status==="valid")return E;E.status==="dirty"&&!l&&(l={result:E,ctx:y}),y.common.issues.length&&h.push(y.common.issues)}if(l)return i.common.issues.push(...l.ctx.common.issues),l.result;const p=h.map(g=>new F(g));return b(i,{code:w.invalid_union,unionErrors:p}),T}}get options(){return this._def.options}}Ke.create=(a,r)=>new Ke({options:a,typeName:S.ZodUnion,...O(r)});const ae=a=>a instanceof Xe?ae(a.schema):a instanceof Y?ae(a.innerType()):a instanceof Je?[a.value]:a instanceof fe?a.options:a instanceof et?M.objectValues(a.enum):a instanceof tt?ae(a._def.innerType):a instanceof qe?[void 0]:a instanceof Ge?[null]:a instanceof te?[void 0,...ae(a.unwrap())]:a instanceof he?[null,...ae(a.unwrap())]:a instanceof tr||a instanceof st?ae(a.unwrap()):a instanceof rt?ae(a._def.innerType):[];class Ot extends I{_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==_.object)return b(i,{code:w.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:w.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(r,i,c){const u=new Map;for(const l of i){const h=ae(l.shape[r]);if(!h.length)throw new Error(`A discriminator value for key \`${r}\` could not be extracted from all schema options`);for(const p of h){if(u.has(p))throw new Error(`Discriminator property ${String(r)} has duplicate value ${String(p)}`);u.set(p,l)}}return new Ot({typeName:S.ZodDiscriminatedUnion,discriminator:r,options:i,optionsMap:u,...O(c)})}}function er(a,r){const i=se(a),c=se(r);if(a===r)return{valid:!0,data:a};if(i===_.object&&c===_.object){const u=M.objectKeys(r),l=M.objectKeys(a).filter(p=>u.indexOf(p)!==-1),h={...a,...r};for(const p of l){const g=er(a[p],r[p]);if(!g.valid)return{valid:!1};h[p]=g.data}return{valid:!0,data:h}}else if(i===_.array&&c===_.array){if(a.length!==r.length)return{valid:!1};const u=[];for(let l=0;l<a.length;l++){const h=a[l],p=r[l],g=er(h,p);if(!g.valid)return{valid:!1};u.push(g.data)}return{valid:!0,data:u}}else return i===_.date&&c===_.date&&+a==+r?{valid:!0,data:a}:{valid:!1}}class Ye extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r),u=(l,h)=>{if(Qt(l)||Qt(h))return T;const p=er(l.value,h.value);return p.valid?((Xt(l)||Xt(h))&&i.dirty(),{status:i.value,value:p.data}):(b(c,{code:w.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}))}}Ye.create=(a,r,i)=>new Ye({left:a,right:r,typeName:S.ZodIntersection,...O(i)});class ee extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==_.array)return b(c,{code:w.invalid_type,expected:_.array,received:c.parsedType}),T;if(c.data.length<this._def.items.length)return b(c,{code:w.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:w.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const l=[...c.data].map((h,p)=>{const g=this._def.items[p]||this._def.rest;return g?g._parse(new J(c,h,c.path,p)):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(r){return new ee({...this._def,rest:r})}}ee.create=(a,r)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ee({items:a,typeName:S.ZodTuple,rest:null,...O(r)})};class Qe extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==_.object)return b(c,{code:w.invalid_type,expected:_.object,received:c.parsedType}),T;const u=[],l=this._def.keyType,h=this._def.valueType;for(const p in c.data)u.push({key:l._parse(new J(c,p,c.path,p)),value:h._parse(new J(c,c.data[p],c.path,p)),alwaysSet:p in c.data});return c.common.async?L.mergeObjectAsync(i,u):L.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(r,i,c){return i instanceof I?new Qe({keyType:r,valueType:i,typeName:S.ZodRecord,...O(c)}):new Qe({keyType:G.create(),valueType:r,typeName:S.ZodRecord,...O(i)})}}class It extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==_.map)return b(c,{code:w.invalid_type,expected:_.map,received:c.parsedType}),T;const u=this._def.keyType,l=this._def.valueType,h=[...c.data.entries()].map(([p,g],y)=>({key:u._parse(new J(c,p,c.path,[y,"key"])),value:l._parse(new J(c,g,c.path,[y,"value"]))}));if(c.common.async){const p=new Map;return Promise.resolve().then(async()=>{for(const g of h){const y=await g.key,E=await g.value;if(y.status==="aborted"||E.status==="aborted")return T;(y.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(y.value,E.value)}return{status:i.value,value:p}})}else{const p=new Map;for(const g of h){const y=g.key,E=g.value;if(y.status==="aborted"||E.status==="aborted")return T;(y.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(y.value,E.value)}return{status:i.value,value:p}}}}It.create=(a,r,i)=>new It({valueType:r,keyType:a,typeName:S.ZodMap,...O(i)});class xe extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);if(c.parsedType!==_.set)return b(c,{code:w.invalid_type,expected:_.set,received:c.parsedType}),T;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(b(c,{code:w.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:w.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(g){const y=new Set;for(const E of g){if(E.status==="aborted")return T;E.status==="dirty"&&i.dirty(),y.add(E.value)}return{status:i.value,value:y}}const p=[...c.data.values()].map((g,y)=>l._parse(new J(c,g,c.path,y)));return c.common.async?Promise.all(p).then(g=>h(g)):h(p)}min(r,i){return new xe({...this._def,minSize:{value:r,message:x.toString(i)}})}max(r,i){return new xe({...this._def,maxSize:{value:r,message:x.toString(i)}})}size(r,i){return this.min(r,i).max(r,i)}nonempty(r){return this.min(1,r)}}xe.create=(a,r)=>new xe({valueType:a,minSize:null,maxSize:null,typeName:S.ZodSet,...O(r)});class Ce extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==_.function)return b(i,{code:w.invalid_type,expected:_.function,received:i.parsedType}),T;function c(p,g){return Et({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,kt(),Ie].filter(y=>!!y),issueData:{code:w.invalid_arguments,argumentsError:g}})}function u(p,g){return Et({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,kt(),Ie].filter(y=>!!y),issueData:{code:w.invalid_return_type,returnTypeError:g}})}const l={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Ne){const p=this;return V(async function(...g){const y=new F([]),E=await p._def.args.parseAsync(g,l).catch(ce=>{throw y.addIssue(c(g,ce)),y}),j=await Reflect.apply(h,this,E);return await p._def.returns._def.type.parseAsync(j,l).catch(ce=>{throw y.addIssue(u(j,ce)),y})})}else{const p=this;return V(function(...g){const y=p._def.args.safeParse(g,l);if(!y.success)throw new F([c(g,y.error)]);const E=Reflect.apply(h,this,y.data),j=p._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(...r){return new Ce({...this._def,args:ee.create(r).rest(_e.create())})}returns(r){return new Ce({...this._def,returns:r})}implement(r){return this.parse(r)}strictImplement(r){return this.parse(r)}static create(r,i,c){return new Ce({args:r||ee.create([]).rest(_e.create()),returns:i||_e.create(),typeName:S.ZodFunction,...O(c)})}}class Xe extends I{get schema(){return this._def.getter()}_parse(r){const{ctx:i}=this._processInputParams(r);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}Xe.create=(a,r)=>new Xe({getter:a,typeName:S.ZodLazy,...O(r)});class Je extends I{_parse(r){if(r.data!==this._def.value){const i=this._getOrReturnCtx(r);return b(i,{received:i.data,code:w.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:r.data}}get value(){return this._def.value}}Je.create=(a,r)=>new Je({value:a,typeName:S.ZodLiteral,...O(r)});function Wn(a,r){return new fe({values:a,typeName:S.ZodEnum,...O(r)})}class fe extends I{constructor(){super(...arguments),Fe.set(this,void 0)}_parse(r){if(typeof r.data!="string"){const i=this._getOrReturnCtx(r),c=this._def.values;return b(i,{expected:M.joinValues(c),received:i.parsedType,code:w.invalid_type}),T}if(St(this,Fe)||Bn(this,Fe,new Set(this._def.values)),!St(this,Fe).has(r.data)){const i=this._getOrReturnCtx(r),c=this._def.values;return b(i,{received:i.data,code:w.invalid_enum_value,options:c}),T}return V(r.data)}get options(){return this._def.values}get enum(){const r={};for(const i of this._def.values)r[i]=i;return r}get Values(){const r={};for(const i of this._def.values)r[i]=i;return r}get Enum(){const r={};for(const i of this._def.values)r[i]=i;return r}extract(r,i=this._def){return fe.create(r,{...this._def,...i})}exclude(r,i=this._def){return fe.create(this.options.filter(c=>!r.includes(c)),{...this._def,...i})}}Fe=new WeakMap,fe.create=Wn;class et extends I{constructor(){super(...arguments),We.set(this,void 0)}_parse(r){const i=M.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(r);if(c.parsedType!==_.string&&c.parsedType!==_.number){const u=M.objectValues(i);return b(c,{expected:M.joinValues(u),received:c.parsedType,code:w.invalid_type}),T}if(St(this,We)||Bn(this,We,new Set(M.getValidEnumValues(this._def.values))),!St(this,We).has(r.data)){const u=M.objectValues(i);return b(c,{received:c.data,code:w.invalid_enum_value,options:u}),T}return V(r.data)}get enum(){return this._def.values}}We=new WeakMap,et.create=(a,r)=>new et({values:a,typeName:S.ZodNativeEnum,...O(r)});class Ne extends I{unwrap(){return this._def.type}_parse(r){const{ctx:i}=this._processInputParams(r);if(i.parsedType!==_.promise&&i.common.async===!1)return b(i,{code:w.invalid_type,expected:_.promise,received:i.parsedType}),T;const c=i.parsedType===_.promise?i.data:Promise.resolve(i.data);return V(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Ne.create=(a,r)=>new Ne({type:a,typeName:S.ZodPromise,...O(r)});class Y extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(r){const{status:i,ctx:c}=this._processInputParams(r),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 p=>{if(i.value==="aborted")return T;const g=await this._def.schema._parseAsync({data:p,path:c.path,parent:c});return g.status==="aborted"?T:g.status==="dirty"||i.value==="dirty"?Me(g.value):g});{if(i.value==="aborted")return T;const p=this._def.schema._parseSync({data:h,path:c.path,parent:c});return p.status==="aborted"?T:p.status==="dirty"||i.value==="dirty"?Me(p.value):p}}if(u.type==="refinement"){const h=p=>{const g=u.refinement(p,l);if(c.common.async)return Promise.resolve(g);if(g instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return p};if(c.common.async===!1){const p=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return p.status==="aborted"?T:(p.status==="dirty"&&i.dirty(),h(p.value),{status:i.value,value:p.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(p=>p.status==="aborted"?T:(p.status==="dirty"&&i.dirty(),h(p.value).then(()=>({status:i.value,value:p.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(!we(h))return h;const p=u.transform(h.value,l);if(p instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:p}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>we(h)?Promise.resolve(u.transform(h.value,l)).then(p=>({status:i.value,value:p})):h);M.assertNever(u)}}Y.create=(a,r,i)=>new Y({schema:a,typeName:S.ZodEffects,effect:r,...O(i)}),Y.createWithPreprocess=(a,r,i)=>new Y({schema:r,effect:{type:"preprocess",transform:a},typeName:S.ZodEffects,...O(i)});class te extends I{_parse(r){return this._getType(r)===_.undefined?V(void 0):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}te.create=(a,r)=>new te({innerType:a,typeName:S.ZodOptional,...O(r)});class he extends I{_parse(r){return this._getType(r)===_.null?V(null):this._def.innerType._parse(r)}unwrap(){return this._def.innerType}}he.create=(a,r)=>new he({innerType:a,typeName:S.ZodNullable,...O(r)});class tt extends I{_parse(r){const{ctx:i}=this._processInputParams(r);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}}tt.create=(a,r)=>new tt({innerType:a,typeName:S.ZodDefault,defaultValue:typeof r.default=="function"?r.default:()=>r.default,...O(r)});class rt extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return Ve(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}}rt.create=(a,r)=>new rt({innerType:a,typeName:S.ZodCatch,catchValue:typeof r.catch=="function"?r.catch:()=>r.catch,...O(r)});class Mt extends I{_parse(r){if(this._getType(r)!==_.nan){const c=this._getOrReturnCtx(r);return b(c,{code:w.invalid_type,expected:_.nan,received:c.parsedType}),T}return{status:"valid",value:r.data}}}Mt.create=a=>new Mt({typeName:S.ZodNaN,...O(a)});const aa=Symbol("zod_brand");class tr extends I{_parse(r){const{ctx:i}=this._processInputParams(r),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class nt extends I{_parse(r){const{status:i,ctx:c}=this._processInputParams(r);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(),Me(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(r,i){return new nt({in:r,out:i,typeName:S.ZodPipeline})}}class st extends I{_parse(r){const i=this._def.innerType._parse(r),c=u=>(we(u)&&(u.value=Object.freeze(u.value)),u);return Ve(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}st.create=(a,r)=>new st({innerType:a,typeName:S.ZodReadonly,...O(r)});function Hn(a,r={},i){return a?$e.create().superRefine((c,u)=>{var l,h;if(!a(c)){const p=typeof r=="function"?r(c):typeof r=="string"?{message:r}:r,g=(h=(l=p.fatal)!==null&&l!==void 0?l:i)!==null&&h!==void 0?h:!0,y=typeof p=="string"?{message:p}:p;u.addIssue({code:"custom",...y,fatal:g})}}):$e.create()}const oa={object:N.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 ca=(a,r={message:`Input not instance of ${a.name}`})=>Hn(i=>i instanceof a,r),qn=G.create,Gn=le.create,ua=Mt.create,la=de.create,Kn=He.create,da=be.create,fa=Tt.create,ha=qe.create,pa=Ge.create,ma=$e.create,ga=_e.create,ya=ie.create,va=At.create,wa=K.create,ba=N.create,_a=N.strictCreate,xa=Ke.create,ka=Ot.create,Ea=Ye.create,Sa=ee.create,Ta=Qe.create,Aa=It.create,Oa=xe.create,Ia=Ce.create,Ma=Xe.create,$a=Je.create,Ra=fe.create,Ca=et.create,Na=Ne.create,Yn=Y.create,ja=te.create,Da=he.create,Pa=Y.createWithPreprocess,Ua=nt.create;var D=Object.freeze({__proto__:null,defaultErrorMap:Ie,setErrorMap:Pi,getErrorMap:kt,makeIssue:Et,EMPTY_PATH:Ui,addIssueToContext:b,ParseStatus:L,INVALID:T,DIRTY:Me,OK:V,isAborted:Qt,isDirty:Xt,isValid:we,isAsync:Ve,get util(){return M},get objectUtil(){return Yt},ZodParsedType:_,getParsedType:se,ZodType:I,datetimeRegex:Fn,ZodString:G,ZodNumber:le,ZodBigInt:de,ZodBoolean:He,ZodDate:be,ZodSymbol:Tt,ZodUndefined:qe,ZodNull:Ge,ZodAny:$e,ZodUnknown:_e,ZodNever:ie,ZodVoid:At,ZodArray:K,ZodObject:N,ZodUnion:Ke,ZodDiscriminatedUnion:Ot,ZodIntersection:Ye,ZodTuple:ee,ZodRecord:Qe,ZodMap:It,ZodSet:xe,ZodFunction:Ce,ZodLazy:Xe,ZodLiteral:Je,ZodEnum:fe,ZodNativeEnum:et,ZodPromise:Ne,ZodEffects:Y,ZodTransformer:Y,ZodOptional:te,ZodNullable:he,ZodDefault:tt,ZodCatch:rt,ZodNaN:Mt,BRAND:aa,ZodBranded:tr,ZodPipeline:nt,ZodReadonly:st,custom:Hn,Schema:I,ZodSchema:I,late:oa,get ZodFirstPartyTypeKind(){return S},coerce:{string:a=>G.create({...a,coerce:!0}),number:a=>le.create({...a,coerce:!0}),boolean:a=>He.create({...a,coerce:!0}),bigint:a=>de.create({...a,coerce:!0}),date:a=>be.create({...a,coerce:!0})},any:ma,array:wa,bigint:la,boolean:Kn,date:da,discriminatedUnion:ka,effect:Yn,enum:Ra,function:Ia,instanceof:ca,intersection:Ea,lazy:Ma,literal:$a,map:Aa,nan:ua,nativeEnum:Ca,never:ya,null:pa,nullable:Da,number:Gn,object:ba,oboolean:()=>Kn().optional(),onumber:()=>Gn().optional(),optional:ja,ostring:()=>qn().optional(),pipeline:Ua,preprocess:Pa,promise:Na,record:Ta,set:Oa,strictObject:_a,string:qn,symbol:fa,transformer:Yn,tuple:Sa,undefined:ha,union:xa,unknown:ga,void:va,NEVER:T,ZodIssueCode:w,quotelessJson:Di,ZodError:F}),rr=(a=>(a.TEXT="text",a.THREAD="thread",a.REACTION="reaction",a))(rr||{});const pe=q.getInstance(),Za=["id","targetMessageId","type","message","username","address","timestamp","signature","index","chatTopic","userTopic","additionalProps"],nr=D.object({id:D.string(),targetMessageId:D.string().optional(),type:D.nativeEnum(rr),message:D.string(),username:D.string(),address:D.string(),timestamp:D.number(),signature:D.string(),index:D.number(),chatTopic:D.string(),userTopic:D.string(),additionalProps:D.record(D.any()).optional()}).refine(a=>!a.additionalProps||Object.keys(a.additionalProps).length===0?!0:Fa(a.additionalProps).isValid,{message:"Invalid additional properties in message"}),Ba=D.object({reference:D.string(),timestamp:D.number()}),La=D.object({message:nr,messageStateRefs:D.array(Ba).nullable()});function Qn(a){const r=La.safeParse(a);return r.success?Xn(a.message)?!0:(pe.warn("Invalid main message signature"),!1):(pe.warn("GSOC message validation failed:",r.error.format()),!1)}function za(a){if(!Array.isArray(a))return pe.warn("Message state must be an array"),!1;for(const r of a)if(!Va(r))return pe.warn("Invalid message in message state:",r.id),!1;return!0}function Va(a){const r=nr.safeParse(a);return r.success?Xn(a)?!0:(pe.warn("Invalid message signature"),!1):(pe.warn("Message data validation failed:",r.error.format()),!1)}function Xn(a){try{const r={username:a.username,address:a.address,timestamp:a.timestamp,message:a.message},i=new TextEncoder,c=B.concatBytes(i.encode(`Ethereum Signed Message:
11
+ 32`),B.keccak256(i.encode(JSON.stringify(r))));if(new A.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(r){return pe.warn("Error in validateUserSignature",r),!1}}function Fa(a){const r=[];if(a==null)return{isValid:!0,errors:[]};if(typeof a!="object"||Array.isArray(a))return r.push("Additional properties must be a plain object"),{isValid:!1,errors:r};for(const g of Object.keys(a))Za.includes(g)&&r.push(`Property '${g}' is reserved and cannot be overridden`);const i=JSON.stringify(a),c=new TextEncoder().encode(i).length,u=1*1024;c>u&&r.push(`Additional properties too large: ${c} bytes (max: ${u} bytes)`);const l=5;function h(g,y=0){if(y>l)return!1;if(typeof g=="object"&&g!==null&&!Array.isArray(g)){for(const E of Object.values(g))if(!h(E,y+1))return!1}return!0}h(a)||r.push(`Additional properties nested too deeply (max depth: ${l})`);for(const[g,y]of Object.entries(a))if(g.length>100&&r.push(`Property key '${g}' too long (max: 100 characters)`),typeof y=="string"&&y.length>1e3&&r.push(`Property '${g}' value too long (max: 1000 characters)`),typeof y=="string"){const E=[/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,/javascript:/gi,/data:text\/html/gi,/vbscript:/gi,/on\w+\s*=/gi];for(const j of E)if(j.test(y)){r.push(`Property '${g}' contains potentially dangerous content`);break}}const p=20;return Object.keys(a).length>p&&r.push(`Too many additional properties: ${Object.keys(a).length} (max: ${p})`),{isValid:r.length===0,errors:r}}function Wa(a){const r=nr.safeParse(a);if(!r.success){const i=r.error.issues.map(c=>c.path.length>0?`${c.path.join(".")}: ${c.message}`:c.message);return pe.warn("Message validation failed:",r.error.format()),{isValid:!1,errors:i}}return{isValid:!0,errors:[]}}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 Ha{constructor(r,i){this.utils=r,this.emitter=i,this.logger=q.getInstance(),this.errorHandler=X.getInstance(),this.processedRefs=new Set,this.refRetryCount=new Map,this.bannedRefs=new Set,this.latestStatefulMessage=null,this.MAX_RETRIES=3,this.RETRY_DELAY=1e3}async init(){try{const{data:r,index:i}=await this.utils.fetchLatestChatMessage();this.latestStatefulMessage=r;try{await this.initMessageState(r)}catch(c){this.errorHandler.handleError(c,"SwarmHistory.initMessageState")}return i}catch(r){return this.errorHandler.handleError(r,"SwarmHistory.init"),A.FeedIndex.fromBigInt(0n)}}async initMessageState(r){try{if(!Qn(r)){this.logger.warn("Invalid GSOC message during message state initialization");return}if(!r.messageStateRefs||r.messageStateRefs.length===0){this.logger.debug("No message state refs to initialize");return}const i=this.findLatestRef(r.messageStateRefs);if(!i){this.logger.warn("No valid latest reference found");return}this.logger.debug("Initializing message state with latest ref:",i.reference),await this.processMessageRefWithRetry(i.reference)}catch(i){if(this.utils.isNotFoundError(i)){this.logger.debug("No latest GSOC message found for message state initialization");return}this.errorHandler.handleError(i,"SwarmHistory.init")}}async fetchPreviousMessageState(){let r=this.latestStatefulMessage;if(!r){const{data:c}=await this.utils.fetchLatestChatMessage();r=c,this.latestStatefulMessage=c}if(!r.messageStateRefs||r.messageStateRefs.length===0){this.logger.debug("No message state refs to fetch");return}const i=[...r.messageStateRefs].sort((c,u)=>c.timestamp-u.timestamp);for(const c of i)!this.processedRefs.has(c.reference)&&!this.bannedRefs.has(c.reference)&&(this.logger.debug("Fetching previous message ref:",c.reference),await this.processMessageRefWithRetry(c.reference))}findLatestRef(r){return r.length===0?null:r.reduce((i,c)=>c.timestamp>i.timestamp?c:i)}async processMessageRefWithRetry(r){if(!(this.processedRefs.has(r)||this.bannedRefs.has(r)))try{await this.processMessageRef(r)}catch(i){await this.handleRefError(r,i)}}async processMessageRef(r){const i=await this.utils.downloadObjectFromBee(r);if(!za(i))throw new Error(`Invalid message state for ref: ${r}`);this.processedRefs.add(r),this.refRetryCount.delete(r);for(const u of i)this.emitter.emit(W.MESSAGE_RECEIVED,u)}async handleRefError(r,i){const c=this.refRetryCount.get(r)||0,u=c+1;if(this.logger.warn(`Error processing ref ${r} (attempt ${u}/${this.MAX_RETRIES}):`,i),u>=this.MAX_RETRIES)this.bannedRefs.add(r),this.refRetryCount.delete(r),this.logger.error(`Ref ${r} has been banned after ${this.MAX_RETRIES} failed attempts`),this.errorHandler.handleError(i,"SwarmHistory.processMessageRef");else{this.refRetryCount.set(r,u);const l=this.RETRY_DELAY*Math.pow(2,c);this.logger.debug(`Retrying ref ${r} after ${l}ms delay`),await Ni(l),await this.processMessageRefWithRetry(r)}}hasPreviousMessages(){return!!this.latestStatefulMessage&&!!this.latestStatefulMessage.messageStateRefs&&this.latestStatefulMessage.messageStateRefs.length>1}cleanup(){this.processedRefs.clear(),this.refRetryCount.clear(),this.bannedRefs.clear(),this.latestStatefulMessage=null}}class qa{constructor(r,i){this.userDetails=r,this.swarmSettings=i,this.depth=26,this.errorHandler=X.getInstance(),this.UPLOAD_GSOC_TIMEOUT=2e3}generateUserOwnedFeedId(r,i){return`${r}_EthercastChat_${i}`}isNotFoundError(r){return r.stack.includes("404")||r.message.includes("Not Found")||r.message.includes("404")||r.code===404}async writeOwnFeedDataByIndex(r,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(r,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(r,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(r,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,g=this.generateUserOwnedFeedId(l,p),y=A.Topic.fromString(g);await c.makeFeedWriter(y,new A.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:r})}async writeOwnFeedDataByIndexEnvelope(r,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,g=new A.PrivateKey(h),y=A.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(l,p),j=A.Topic.fromString(E),oe=Dn(j,r),ce=Pn(i),it=Un(ce,oe,g),je={hash:()=>it.address.toUint8Array()},sr=y.stamp(je),{upload:ir}=c.makeSOCWriter(g),at=A.Bytes.fromUtf8(i);return(await ir(sr,oe,at.toUint8Array())).reference.toHex()}orderMessages(r){return r.sort((i,c)=>i.timestamp-c.timestamp)}async downloadObjectFromBee(r){try{const{bee:i}=this.swarmSettings,c=await i.downloadData(r);return c?c.toJSON():null}catch(i){return this.errorHandler.handleError(i,"Utils.downloadObjectFromBee"),null}}async uploadObjectToBee(r){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(r);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(r)}async uploadObjectToBeeOwn(r){try{const{bee:i,stamp:c}=this.swarmSettings;return(await i.uploadData(c,JSON.stringify(r),{redundancyLevel:4})).reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(r){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(r)),p=new Ti(async y=>{await i.uploadChunk(l.stamp(y),y.build())});await p.append(h.toUint8Array());const g=await p.finalize();return B.uint8ArrayToHex(g.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:r,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),l=A.Topic.fromString(u),p=await r.makeFeedReader(l,c).downloadPayload(),g=Number(p.feedIndex.toBigInt()),y=g+1;return{latestIndex:g,nextIndex:y}}catch(r){if(this.isNotFoundError(r))return{latestIndex:-1,nextIndex:0};throw r}}async fetchLatestChatMessage(){const{bee:r,chatTopic:i,chatAddress:c}=this.swarmSettings,l=await r.makeFeedReader(A.Topic.fromString(i),Gt(c)).downloadPayload();return{data:l.payload.toJSON(),index:l.feedIndex}}async fetchChatMessage(r){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(A.Topic.fromString(c),Gt(u)).downloadPayload({index:r})).payload.toJSON()}async sendMessageToGsoc(r){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(r);else if(c)await this.sendMessageToGsocEnvelope(r);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(r,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${r}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok){const l=new Error(`Failed to fetch: ${r}/${i} [${u.status}]`);throw l.status=u.status,l}return u.text()}async sendMessageToGsocOwn(r){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,h=new A.PrivateKey(l),p=A.Identifier.fromString(u),g=A.Bytes.fromUtf8(r),{upload:y}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await y(c,p,g.toUint8Array())}async sendMessageToGsocEnvelope(r){const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,{privateKey:h}=this.userDetails,p=A.Stamper.fromBlank(h,c,this.depth),g=new A.PrivateKey(l),y=A.Identifier.fromString(u),E=A.Bytes.fromUtf8(r),j=Pn(E.toUint8Array()),oe=Un(j,y,g),ce={hash:()=>oe.address.toUint8Array()},it=p.stamp(ce),{upload:je}=i.makeSOCWriter(g,{timeout:this.UPLOAD_GSOC_TIMEOUT});await je(it,y,E.toUint8Array())}}class Ga{constructor(r,i){this.fallbackTransport=null,this.logger=q.getInstance(),this.errorHandler=X.getInstance(),this.gsocIndex=null;const c=new A.PrivateKey(Gt(r.user.privateKey));this.userDetails={privateKey:r.user.privateKey,ownAddress:c.publicKey().address().toString(),nickname:r.user.nickname,ownIndex:-1},this.swarmSettings={bee:new A.Bee(r.infra.beeUrl),beeUrl:r.infra.beeUrl,stamp:r.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:r.infra.enveloped,gsocTopic:r.infra.gsocTopic,gsocResourceId:r.infra.gsocResourceId,chatTopic:r.infra.chatTopic,chatAddress:r.infra.chatAddress},this.emitter=new ji,this.utils=new qa(this.userDetails,this.swarmSettings),this.history=new Ha(this.utils,this.emitter);const u=r.infra.pollingInterval||1e3;i?(this.transport=i,r.infra.enableFallbackPolling&&(this.logger.info(`Fallback polling enabled with interval: ${u}ms`),this.fallbackTransport=this.createDefaultPollingTransport(u),this.fallbackTransport.onMessage(l=>{this.emitter.emit(W.MESSAGE_RECEIVED,l)}))):this.transport=this.createDefaultPollingTransport(u),this.transport.onMessage(l=>{this.emitter.emit(W.MESSAGE_RECEIVED,l)})}createDefaultPollingTransport(r){return new Rn({fetchMessage:async()=>{try{if(!this.gsocIndex)return null;const i=A.Topic.fromString(this.swarmSettings.chatTopic),c=Dn(i,this.gsocIndex),u=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,c.toString()),l=JSON.parse(u);return Qn(l)?(this.gsocIndex=this.gsocIndex.next(),l.message):(this.logger.warn("Invalid GSOC message during fetching"),null)}catch(i){if(this.utils.isNotFoundError(i))return null;throw i}},pollingInterval:r||1e3})}async start(){await this.init(),await this.transport.start(),this.fallbackTransport&&await this.fallbackTransport.start()}async stop(){this.emitter.cleanAll(),this.history.cleanup(),await this.transport.stop(),this.fallbackTransport&&await this.fallbackTransport.stop()}getEmitter(){return this.emitter}orderMessages(r){return this.utils.orderMessages(r)}async sendMessage(r,i,c,u,l){const h=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,p={id:u||Ei(),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(r),timestamp:Date.now(),index:h,type:i,targetMessageId:c,message:r,additionalProps:l},g=Wa(p);if(!g.isValid){const y=`Invalid message: ${g.errors.join(", ")}`;throw this.logger.error(y),new Error(y)}try{this.emitter.emit(W.MESSAGE_REQUEST_INITIATED,p),await this.utils.writeOwnFeedDataByIndex(h,JSON.stringify(p)),this.userDetails.ownIndex=h,this.emitter.emit(W.MESSAGE_REQUEST_UPLOADED,p),await this.broadcastUserMessage(p)}catch(y){this.emitter.emit(W.MESSAGE_REQUEST_ERROR,p),this.errorHandler.handleError(y,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessageState()}finally{this.emitter.emit(W.LOADING_PREVIOUS_MESSAGES,!1)}}hasPreviousMessages(){return this.history.hasPreviousMessages()}async retrySendMessage(r){this.sendMessage(r.message,r.type,r.targetMessageId,r.id,r.additionalProps)}async retryBroadcastUserMessage(r){await this.broadcastUserMessage(r)}async init(){try{this.emitter.emit(W.LOADING_INIT,!0);const[r,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(r.status==="rejected")throw r.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(W.LOADING_INIT,!1)}catch(r){this.errorHandler.handleError(r,"Chat.initSelfState"),this.emitter.emit(W.CRITICAL_ERROR,r)}}async initOwnIndex(){const{latestIndex:c}=await Kt(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async broadcastUserMessage(r){try{return Kt(()=>this.utils.sendMessageToGsoc(JSON.stringify(r)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(r){const{ownAddress:i,privateKey:c,nickname:u}=this.userDetails,l=new A.EthAddress(i).toString(),h=new A.PrivateKey(c);if(h.publicKey().address().toString()!==l)throw new Error("The provided address does not match the address derived from the private key");const g=Date.now();return h.sign(JSON.stringify({username:u,address:l,message:r,timestamp:g})).toHex()}}Q.EVENTS=W,Q.MessageType=rr,Q.PollingTransport=Rn,Q.SwarmChat=Ga,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});