@synnaxlabs/freighter 0.44.2 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Je=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Ie=r=>{const e=(t,n=ie)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!re(t))return t;n=_e(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(c=>{let d=a[c];const y=r(c);n.recursive&&(re(d)?me(d)||(d=e(d,n)):n.recursiveInArray&&pe(d)&&(d=[...d].map(f=>{let p=f;return re(f)?me(p)||(p=e(f,n)):pe(f)&&(p=e({key:f},n).key),p}))),i[y]=d}),i)};return e},Ne=Ie(Je),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Ke=Ie(Xe),Qe=[Number,String,Uint8Array],ie={recursive:!0,recursiveInArray:!0},_e=(r=ie)=>(r.recursive==null?r=ie:r.recursiveInArray??=!1,r),pe=r=>r!=null&&Array.isArray(r),re=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),me=r=>Qe.some(e=>r instanceof e);let et=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),i=Ne(n);return t!=null?t.parse(i):i}encodeString(e){const t=Ke(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const ae=new et;let j=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const tt=r=>r!=null&&typeof r=="object"&&"toString"in r,rt=(r,e=!1)=>{const t=tt(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?nt(n):n},nt=r=>(e,t)=>r(t,e),K=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ze=s.z.object({width:s.z.number(),height:s.z.number()}),st=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),it=["width","height"];s.z.enum(it);const at=["start","center","end"],ot=["signedWidth","signedHeight"];s.z.enum(ot);const J=s.z.object({x:s.z.number(),y:s.z.number()}),ut=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),lt=["x","y"],Ee=s.z.enum(lt),xe=["top","right","bottom","left"];s.z.enum(xe);const ct=["left","right"],Ae=s.z.enum(ct),ht=["top","bottom"],Ue=s.z.enum(ht),Me=["center"],ye=s.z.enum(Me),ft=[...xe,...Me],Ce=s.z.enum(ft);s.z.enum(at);const dt=["first","last"];s.z.enum(dt);const gt=s.z.object({lower:s.z.number(),upper:s.z.number()}),pt=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([gt,K]);s.z.union([pt,K]);s.z.enum([...Ee.options,...Ce.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([Ee,Ce,s.z.instanceof(String)]);const Q=r=>(e,t)=>{if(typeof e=="bigint"){if(mt(t))return r(e,BigInt(t));const n=r(Number(e),Number(t));return typeof n=="number"?BigInt(Math.round(n)):n}return r(Number(e),Number(t))},_=Q((r,e)=>r-e),ee=Q((r,e)=>r+e),mt=r=>typeof r=="bigint"?!0:Number.isInteger(r),x=Q((r,e)=>r*e),te=Q((r,e)=>r/e),$=(r,e,t)=>{const n={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof r=="number"||typeof r=="bigint")e!=null?(n.lower=r,n.upper=e):(n.lower=typeof r=="bigint"?0n:0,n.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=r}else n.lower=r.lower,n.upper=r.upper;return t?.makeValid?yt(n):n},yt=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,we=(r,e)=>{const t=$(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Ae.or(ye),y:Ue.or(ye)});const wt=s.z.object({x:Ae,y:Ue}),bt=Object.freeze({x:"left",y:"top"}),Ot=(r,e)=>r.x===e.x&&r.y===e.y,be=s.z.union([s.z.number(),J,K,ze,st,ut]),Tt=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Oe=Object.freeze({x:0,y:0}),V=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:V,left:V,width:V,height:V});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:J,two:J,root:wt});const he=(r,e,t=0,n=0,i)=>{const a={one:{...Oe},two:{...Oe},root:i??bt};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},ne=r=>{const e=he(r);return{lower:e.one.x,upper:e.two.x}},se=r=>{const e=he(r);return{lower:e.one.y,upper:e.two.y}},vt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,St=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ze,St,J,K]);const It=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:be,scale:be});s.z.object({offset:s.z.number(),scale:s.z.number()});const Nt=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],zt=r=>(e,t,n,i)=>[e,i?n/r:n*r],Et=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:c,upper:d}=r,y=a-i,f=d-c;if(t==="dimension")return[r,n*(f/y)];const p=(n-i)*(f/y)+c;return[r,p]},xt=r=>(e,t,n)=>[r,n],At=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},Ut=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=It(n,i,a),[e,n]};let Te=class L{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new L().translate(e)}static magnify(e){return new L().magnify(e)}static scale(e,t){return new L().scale(e,t)}translate(e){const t=this.new(),n=Nt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=zt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=$(e,t),i=this.new(),a=Et(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=$(e,t),i=this.new(),a=Ut(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=$(e,t),i=this.new(),a=xt(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=At();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new L;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([c,d])=>i>=c&&i<=d))return;const a=e.ops.findIndex((c,d)=>c.type==="scale"&&d>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new L},Kr=class E{x;y;currRoot;constructor(e=new Te,t=new Te,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new E().translate(e,t)}static translateX(e){return new E().translateX(e)}static translateY(e){return new E().translateY(e)}static clamp(e){return new E().clamp(e)}static magnify(e){return new E().magnify(e)}static scale(e){return new E().scale(e)}static reBound(e){return new E().reBound(e)}translate(e,t){const n=Tt(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(vt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Ot(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(ne(e)),t.y=t.y.scale(se(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(ne(e)),t.y=this.y.reBound(se(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(ne(e)),t.y=this.y.clamp(se(e)),t}copy(){const e=new E;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return he(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new E},$e=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const Be="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Mt=`0123456789${Be}`,Ct=11,$t=$e(Be,1),Bt=$e(Mt,Ct-1),Rt=()=>`${$t()}${Bt()}`,Dt=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Lt=s.z.enum(["static","dynamic"]),Pt=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),Re=(r,e)=>{const t=new o(e);if(![g.DAY,g.HOUR,g.MINUTE,g.SECOND,g.MILLISECOND,g.MICROSECOND,g.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof o?new o(n):new g(n)};class o extends j{constructor(e,t="UTC"){if(e==null)super(o.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*o.MILLISECOND.valueOf());else if(typeof e=="string")super(o.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(o.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=o.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=o.MAX:e=o.MIN)),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new o(BigInt(i.getTime())*o.MILLISECOND.valueOf()).truncate(o.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let c="00",d="00";a!=null&&([c,d]=a.split("."));let y=o.hours(parseInt(n??"00")).add(o.minutes(parseInt(i??"00"))).add(o.seconds(parseInt(c??"00"))).add(o.milliseconds(parseInt(d??"00")));return t==="local"&&(y=y.add(o.utcOffset)),y.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return o.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new o(BigInt(n.getTime())*o.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(o.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new g(BigInt(new Date().getTimezoneOffset())*o.MINUTE.valueOf())}static since(e){return new o().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new o(e).valueOf()}span(e){return this.range(e).span}range(e){return new Y(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new o(e).valueOf()}afterEq(e){return this.valueOf()>=new o(e).valueOf()}before(e){return this.valueOf()<new o(e).valueOf()}beforeEq(e){return this.valueOf()<=new o(e).valueOf()}add(e){return new o(ee(this.valueOf(),new g(e).valueOf()))}sub(e){return new o(_(this.valueOf(),new g(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(o.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(o.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new o(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new o(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new o(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new o(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new o(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new o(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new o(t)}toString(){return this.date().toISOString()}remainder(e){return Re(this,e)}get isToday(){return this.truncate(g.DAY).equals(o.now().truncate(g.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new o(new Date)}static max(...e){let t=o.MIN;for(const n of e){const i=new o(n);i.after(t)&&(t=i)}return t}static min(...e){let t=o.MAX;for(const n of e){const i=new o(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new o(e,t)}static NANOSECOND=o.nanoseconds(1);static microseconds(e,t="UTC"){return o.nanoseconds(e*1e3,t)}static MICROSECOND=o.microseconds(1);static milliseconds(e,t="UTC"){return o.microseconds(e*1e3,t)}static MILLISECOND=o.milliseconds(1);static seconds(e,t="UTC"){return o.milliseconds(e*1e3,t)}static SECOND=o.seconds(1);static minutes(e,t="UTC"){return o.seconds(e*60,t)}static MINUTE=o.minutes(1);static hours(e,t="UTC"){return o.minutes(e*60,t)}static HOUR=o.hours(1);static days(e,t="UTC"){return o.hours(e*24,t)}static DAY=o.days(1);static MAX=new o((1n<<63n)-1n);static MIN=new o(0);static ZERO=new o(0);static z=s.z.union([s.z.instanceof(o),s.z.object({value:s.z.bigint()}).transform(e=>new o(e.value)),s.z.string().transform(e=>new o(BigInt(e))),s.z.number().transform(e=>new o(e)),s.z.bigint().transform(e=>new o(e)),s.z.date().transform(e=>new o(e)),s.z.custom(e=>e instanceof g).transform(e=>new o(e)),Pt.transform(e=>new o(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let g=class l extends j{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof l?e:e instanceof I?e.period:e instanceof o?new l(e):["number","bigint"].includes(typeof e)?l.seconds(e):new l(e)}static fromMilliseconds(e){return e instanceof l?e:e instanceof I?e.period:e instanceof o?new l(e):["number","bigint"].includes(typeof e)?l.milliseconds(e):new l(e)}valueOf(){return this.value}lessThan(e){return this.valueOf()<new l(e).valueOf()}greaterThan(e){return this.valueOf()>new l(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new l(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new l(e).valueOf()}remainder(e){return Re(this,e)}truncate(e){return new l(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(l.DAY),t=this.truncate(l.HOUR),n=this.truncate(l.MINUTE),i=this.truncate(l.SECOND),a=this.truncate(l.MILLISECOND),c=this.truncate(l.MICROSECOND),d=this.truncate(l.NANOSECOND),y=e,f=t.sub(e),p=n.sub(t),b=i.sub(n),h=a.sub(i),O=c.sub(a),z=d.sub(c);let U="";return y.isZero||(U+=`${y.days}d `),f.isZero||(U+=`${f.hours}h `),p.isZero||(U+=`${p.minutes}m `),b.isZero||(U+=`${b.seconds}s `),h.isZero||(U+=`${h.milliseconds}ms `),O.isZero||(U+=`${O.microseconds}µs `),z.isZero||(U+=`${z.nanoseconds}ns`),U.trim()}mult(e){return new l(x(this.valueOf(),e))}div(e){return new l(te(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(l.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(l.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(l.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(l.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(l.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(l.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new l(e).valueOf()}add(e){return new l(this.valueOf()+new l(e).valueOf())}sub(e){return new l(this.valueOf()-new l(e).valueOf())}static nanoseconds(e=1){return new l(e)}static NANOSECOND=l.nanoseconds(1);static microseconds(e=1){return l.nanoseconds(x(e,1e3))}static MICROSECOND=l.microseconds(1);static milliseconds(e=1){return l.microseconds(x(e,1e3))}static MILLISECOND=l.milliseconds(1);static seconds(e=1){return l.milliseconds(x(e,1e3))}static SECOND=l.seconds(1);static minutes(e=1){return l.seconds(x(e,60))}static MINUTE=l.minutes(1);static hours(e){return l.minutes(x(e,60))}static HOUR=l.hours(1);static days(e){return l.hours(x(e,24))}static DAY=l.days(1);static MAX=new l((1n<<63n)-1n);static MIN=new l(0);static ZERO=new l(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new l(e.value)),s.z.string().transform(e=>new l(BigInt(e))),s.z.number().transform(e=>new l(e)),s.z.bigint().transform(e=>new l(e)),s.z.instanceof(l),s.z.instanceof(o).transform(e=>new l(e)),s.z.custom(e=>e instanceof I).transform(e=>new l(e))])};class I extends j{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new I(e).valueOf()}get period(){return g.seconds(1/this.valueOf())}sampleCount(e){return new g(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new v(t).valueOf()}span(e){return g.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}add(e){return new I(ee(this.valueOf(),e.valueOf()))}sub(e){return new I(_(this.valueOf(),e.valueOf()))}mult(e){return new I(x(this.valueOf(),e))}div(e){return new I(te(this.valueOf(),e))}static hz(e){return new I(e)}static khz(e){return I.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new I(e)),s.z.instanceof(I)])}let v=class S extends j{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new oe(e*this.valueOf())}add(e){return new S(ee(this.valueOf(),e.valueOf()))}sub(e){return new S(_(this.valueOf(),e.valueOf()))}mult(e){return new S(x(this.valueOf(),e))}div(e){return new S(te(this.valueOf(),e))}static UNKNOWN=new S(0);static BIT128=new S(16);static BIT64=new S(8);static BIT32=new S(4);static BIT16=new S(2);static BIT8=new S(1);static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)])},Y=class N{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new o(e.start),this.end=new o(e.end)):(this.start=new o(e),this.end=new o(t))}get span(){return new g(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new N(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=g.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=g.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=o.max(n.start,e.start),a=o.min(n.end,e.end);return a.before(i)?!1:new g(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof N?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new N(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new N(o.min(...e.map(t=>t.start)),o.max(...e.map(t=>t.end)))}static MAX=new N(o.MIN,o.MAX);static MIN=new N(o.MAX,o.MIN);static ZERO=new N(o.ZERO,o.ZERO);static z=s.z.union([s.z.object({start:o.z,end:o.z}).transform(e=>new N(e.start,e.end)),s.z.instanceof(N)]);static sort(e,t){return o.sort(e.start,t.start)||o.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>N.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=o.max(i.end,n.end):t.push(n),t},[])}},w=class u extends j{constructor(e){if(e instanceof u||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=u.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=u.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(u.JSON)||this.equals(u.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(u.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=u.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(u.UINT8)||this.equals(u.UINT16)||this.equals(u.UINT32)||this.equals(u.UINT64)}get isSignedInteger(){return this.equals(u.INT8)||this.equals(u.INT16)||this.equals(u.INT32)||this.equals(u.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(u.INT32)&&e.equals(u.FLOAT64)||this.equals(u.INT8)&&e.equals(u.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return u.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new u("unknown");static FLOAT64=new u("float64");static FLOAT32=new u("float32");static INT64=new u("int64");static INT32=new u("int32");static INT16=new u("int16");static INT8=new u("int8");static UINT64=new u("uint64");static UINT32=new u("uint32");static UINT16=new u("uint16");static UINT8=new u("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new u("timestamp");static UUID=new u("uuid");static STRING=new u("string");static JSON=new u("json");static ARRAY_CONSTRUCTORS=new Map([[u.UINT8.toString(),Uint8Array],[u.UINT16.toString(),Uint16Array],[u.UINT32.toString(),Uint32Array],[u.UINT64.toString(),BigUint64Array],[u.FLOAT32.toString(),Float32Array],[u.FLOAT64.toString(),Float64Array],[u.INT8.toString(),Int8Array],[u.INT16.toString(),Int16Array],[u.INT32.toString(),Int32Array],[u.INT64.toString(),BigInt64Array],[u.TIMESTAMP.toString(),BigInt64Array],[u.STRING.toString(),Uint8Array],[u.JSON.toString(),Uint8Array],[u.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,u.UINT8],[Uint16Array.name,u.UINT16],[Uint32Array.name,u.UINT32],[BigUint64Array.name,u.UINT64],[Float32Array.name,u.FLOAT32],[Float64Array.name,u.FLOAT64],[Int8Array.name,u.INT8],[Int16Array.name,u.INT16],[Int32Array.name,u.INT32],[BigInt64Array.name,u.INT64]]);static DENSITIES=new Map([[u.UINT8.toString(),v.BIT8],[u.UINT16.toString(),v.BIT16],[u.UINT32.toString(),v.BIT32],[u.UINT64.toString(),v.BIT64],[u.FLOAT32.toString(),v.BIT32],[u.FLOAT64.toString(),v.BIT64],[u.INT8.toString(),v.BIT8],[u.INT16.toString(),v.BIT16],[u.INT32.toString(),v.BIT32],[u.INT64.toString(),v.BIT64],[u.TIMESTAMP.toString(),v.BIT64],[u.STRING.toString(),v.UNKNOWN],[u.JSON.toString(),v.UNKNOWN],[u.UUID.toString(),v.BIT128]]);static ALL=[u.UNKNOWN,u.FLOAT64,u.FLOAT32,u.INT64,u.INT32,u.INT16,u.INT8,u.UINT64,u.UINT32,u.UINT16,u.UINT8,u.TIMESTAMP,u.UUID,u.STRING,u.JSON];static BIG_INT_TYPES=[u.INT64,u.UINT64,u.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new u(e)),s.z.instanceof(u)])},oe=class m extends j{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return new m(ee(this.valueOf(),e.valueOf()))}sub(e){return new m(_(this.valueOf(),e.valueOf()))}mult(e){return new m(x(this.valueOf(),e))}div(e){return new m(te(this.valueOf(),e))}truncate(e){return new m(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return m.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/m.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/m.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/m.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/m.TERABYTE.valueOf()}toString(){const e=this.truncate(m.TERABYTE),t=this.truncate(m.GIGABYTE),n=this.truncate(m.MEGABYTE),i=this.truncate(m.KILOBYTE),a=this.truncate(m.BYTE),c=e,d=t.sub(e),y=n.sub(t),f=i.sub(n),p=a.sub(i);let b="";return c.isZero||(b+=`${c.terabytes}TB `),d.isZero||(b+=`${d.gigabytes}GB `),y.isZero||(b+=`${y.megabytes}MB `),f.isZero||(b+=`${f.kilobytes}KB `),(!p.isZero||b==="")&&(b+=`${p.valueOf()}B`),b.trim()}static bytes(e=1){return new m(e)}static BYTE=new m(1);static kilobytes(e=1){return m.bytes(e.valueOf()*1e3)}static KILOBYTE=m.kilobytes(1);static megabytes(e=1){return m.kilobytes(e.valueOf()*1e3)}static MEGABYTE=m.megabytes(1);static gigabytes(e=1){return m.megabytes(e.valueOf()*1e3)}static GIGABYTE=m.gigabytes(1);static terabytes(e){return m.gigabytes(e.valueOf()*1e3)}static TERABYTE=m.terabytes(1);static ZERO=new m(0);static z=s.z.union([s.z.number().transform(e=>new m(e)),s.z.instanceof(m)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const De=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof o||r instanceof g||r instanceof Date},kt=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):H(t,-n),H=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),jt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Yt(r){return typeof r=="string"&&jt.test(r)}const T=[];for(let r=0;r<256;++r)T.push((r+256).toString(16).slice(1));function qt(r,e=0){return(T[r[e+0]]+T[r[e+1]]+T[r[e+2]]+T[r[e+3]]+"-"+T[r[e+4]]+T[r[e+5]]+"-"+T[r[e+6]]+T[r[e+7]]+"-"+T[r[e+8]]+T[r[e+9]]+"-"+T[r[e+10]]+T[r[e+11]]+T[r[e+12]]+T[r[e+13]]+T[r[e+14]]+T[r[e+15]]).toLowerCase()}function Ft(r,e=0){const t=qt(r,e);if(!Yt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Le=(r,e)=>Ft(r,e),M=-1,Wt=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Zt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ue=10,Vt=(r,e)=>{if(r==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(r==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Pe="sy_x_telem_series";class A{key;discriminator=Pe;dataType;sampleOffset;gl;_data;timeRange=Y.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=M;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:Y.z.optional(),dataType:w.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Wt,Zt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Lt.optional().default("static").optional()});static z=A.crudeZ.transform(e=>new A(e));constructor(e){Gt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:c=0n,alignmentMultiple:d=1n,key:y=Rt(),data:f}=e;if(Ht(f)){const h=f;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this.timeRange=h.timeRange,this.alignment=h.alignment,this.alignmentMultiple=h.alignmentMultiple,this.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const p=De(f),b=Array.isArray(f);if(t!=null)this.dataType=new w(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(b||p){let h=f;if(!p){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=f[0]}if(typeof h=="string")this.dataType=w.STRING;else if(typeof h=="number")this.dataType=w.FLOAT64;else if(typeof h=="bigint")this.dataType=w.INT64;else if(typeof h=="boolean")this.dataType=w.BOOLEAN;else if(h instanceof o||h instanceof Date||h instanceof o)this.dataType=w.TIMESTAMP;else if(typeof h=="object")this.dataType=w.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new w(f)}if(!b&&!p)this._data=f;else if(b&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=p?[f]:f;const O=h[0];(O instanceof o||O instanceof Date||O instanceof g)&&(h=h.map(z=>new o(z).valueOf())),this.dataType.equals(w.STRING)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ke=n=>{const e=n.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Ne=n=>{const e=(t,r=ae)=>{if(typeof t=="string")return n(t);if(Array.isArray(t))return t.map(c=>e(c,r));if(!re(t))return t;r=tt(r);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),r):(Object.keys(a).forEach(c=>{let g=a[c];const y=n(c);r.recursive&&(re(g)?ye(g)||(g=e(g,r)):r.recursiveInArray&&me(g)&&(g=[...g].map(f=>{let m=f;return re(f)?ye(m)||(m=e(f,r)):me(f)&&(m=e({key:f},r).key),m}))),i[y]=g}),i)};return e},ze=Ne(Ke),Qe=n=>n.replace(/([a-z0-9])([A-Z])/g,(e,t,r)=>`${t}_${r.toLowerCase()}`),_e=Ne(Qe),et=[Number,String,Uint8Array],ae={recursive:!0,recursiveInArray:!0},tt=(n=ae)=>(n.recursive==null?n=ae:n.recursiveInArray??=!1,n),me=n=>n!=null&&Array.isArray(n),re=n=>n!=null&&typeof n=="object"&&!Array.isArray(n),ye=n=>et.some(e=>n instanceof e);let nt=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const r=JSON.parse(e),i=ze(r);return t!=null?t.parse(i):i}encodeString(e){const t=_e(e);return JSON.stringify(t,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const oe=new nt,N=n=>n!=null&&typeof n=="object"&&"value"in n;let Y=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const rt=n=>n!=null&&typeof n=="object"&&"toString"in n,st=(n,e=!1)=>{const t=rt(n)?"stringer":typeof n;let r;switch(t){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?it(r):r},it=n=>(e,t)=>n(t,e),Q=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Ee=s.z.object({width:s.z.number(),height:s.z.number()}),at=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),ot=["width","height"];s.z.enum(ot);const ut=["start","center","end"],lt=["signedWidth","signedHeight"];s.z.enum(lt);const X=s.z.object({x:s.z.number(),y:s.z.number()}),ct=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),ht=["x","y"],xe=s.z.enum(ht),Ae=["top","right","bottom","left"];s.z.enum(Ae);const ft=["left","right"],Ue=s.z.enum(ft),dt=["top","bottom"],Me=s.z.enum(dt),Ce=["center"],we=s.z.enum(Ce),gt=[...Ae,...Ce],$e=s.z.enum(gt);s.z.enum(ut);const pt=["first","last"];s.z.enum(pt);const mt=s.z.object({lower:s.z.number(),upper:s.z.number()}),yt=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([mt,Q]);s.z.union([yt,Q]);s.z.enum([...xe.options,...$e.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([xe,$e,s.z.instanceof(String)]);const _=n=>(e,t)=>{if(typeof e=="bigint"){if(wt(t))return n(e,BigInt(t));const r=n(Number(e),Number(t));return typeof r=="number"?BigInt(Math.round(r)):r}return n(Number(e),Number(t))},ee=_((n,e)=>n-e),te=_((n,e)=>n+e),wt=n=>typeof n=="bigint"?!0:Number.isInteger(n),A=_((n,e)=>n*e),ne=_((n,e)=>n/e),B=(n,e,t)=>{const r={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof n=="number"||typeof n=="bigint")e!=null?(r.lower=n,r.upper=e):(r.lower=typeof n=="bigint"?0n:0,r.upper=n);else if(Array.isArray(n)){if(n.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=n}else r.lower=n.lower,r.upper=n.upper;return t?.makeValid?bt(r):r},bt=n=>n.lower>n.upper?{lower:n.upper,upper:n.lower}:n,be=(n,e)=>{const t=B(n);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Ue.or(we),y:Me.or(we)});const Ot=s.z.object({x:Ue,y:Me}),Tt=Object.freeze({x:"left",y:"top"}),vt=(n,e)=>n.x===e.x&&n.y===e.y,Oe=s.z.union([s.z.number(),X,Q,Ee,at,ct]),It=(n,e)=>{if(typeof n=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return n==="x"?{x:e,y:0}:{x:0,y:e}}return typeof n=="number"?{x:n,y:e??n}:Array.isArray(n)?{x:n[0],y:n[1]}:"signedWidth"in n?{x:n.signedWidth,y:n.signedHeight}:"clientX"in n?{x:n.clientX,y:n.clientY}:"width"in n?{x:n.width,y:n.height}:{x:n.x,y:n.y}},Te=Object.freeze({x:0,y:0}),G=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:G,left:G,width:G,height:G});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:X,two:X,root:Ot});const fe=(n,e,t=0,r=0,i)=>{const a={one:{...Te},two:{...Te},root:i??Tt};if(typeof n=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:n,y:e},a.two={x:a.one.x+t,y:a.one.y+r},a}return"one"in n&&"two"in n&&"root"in n?{...n,root:i??n.root}:("getBoundingClientRect"in n&&(n=n.getBoundingClientRect()),"left"in n?(a.one={x:n.left,y:n.top},a.two={x:n.right,y:n.bottom},a):(a.one=n,e==null?a.two={x:a.one.x+t,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},se=n=>{const e=fe(n);return{lower:e.one.x,upper:e.two.x}},ie=n=>{const e=fe(n);return{lower:e.one.y,upper:e.two.y}},St=n=>typeof n!="object"||n==null?!1:"one"in n&&"two"in n&&"root"in n,Nt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ee,Nt,X,Q]);const zt=(n,e,t)=>e!==void 0&&n<e?e:t!==void 0&&n>t?t:n;s.z.object({offset:Oe,scale:Oe});s.z.object({offset:s.z.number(),scale:s.z.number()});const Et=n=>(e,t,r,i)=>t==="dimension"?[e,r]:[e,i?r-n:r+n],xt=n=>(e,t,r,i)=>[e,i?r/n:r*n],At=n=>(e,t,r)=>{if(e===null)return[n,r];const{lower:i,upper:a}=e,{lower:c,upper:g}=n,y=a-i,f=g-c;if(t==="dimension")return[n,r*(f/y)];const m=(r-i)*(f/y)+c;return[n,m]},Ut=n=>(e,t,r)=>[n,r],Mt=()=>(n,e,t)=>{if(n===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[n,t];const{lower:r,upper:i}=n;return[n,i-(t-r)]},Ct=n=>(e,t,r)=>{const{lower:i,upper:a}=n;return r=zt(r,i,a),[e,r]};let ve=class k{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new k().translate(e)}static magnify(e){return new k().magnify(e)}static scale(e,t){return new k().scale(e,t)}translate(e){const t=this.new(),r=Et(e);return r.type="translate",t.ops.push(r),t}magnify(e){const t=this.new(),r=xt(e);return r.type="magnify",t.ops.push(r),t}scale(e,t){const r=B(e,t),i=this.new(),a=At(r);return a.type="scale",i.ops.push(a),i}clamp(e,t){const r=B(e,t),i=this.new(),a=Ct(r);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const r=B(e,t),i=this.new(),a=Ut(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Mt();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new k;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||t.some(([c,g])=>i>=c&&i<=g))return;const a=e.ops.findIndex((c,g)=>c.type==="scale"&&g>i);a!==-1&&t.push([i,a])}),t.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new k},er=class x{x;y;currRoot;constructor(e=new ve,t=new ve,r=null){this.x=e,this.y=t,this.currRoot=r}static translate(e,t){return new x().translate(e,t)}static translateX(e){return new x().translateX(e)}static translateY(e){return new x().translateY(e)}static clamp(e){return new x().clamp(e)}static magnify(e){return new x().magnify(e)}static scale(e){return new x().scale(e)}static reBound(e){return new x().reBound(e)}translate(e,t){const r=It(e,t),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(St(e)){const r=this.currRoot;return t.currRoot=e.root,r!=null&&!vt(r,e.root)&&(r.x!==e.root.x&&(t.x=t.x.invert()),r.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(se(e)),t.y=t.y.scale(ie(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(se(e)),t.y=this.y.reBound(ie(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(se(e)),t.y=this.y.clamp(ie(e)),t}copy(){const e=new x;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return fe(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new x},Be=(n,e=21)=>(t=e)=>{let r="",i=t|0;for(;i--;)r+=n[Math.random()*n.length|0];return r};const Re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",$t=`0123456789${Re}`,Bt=11,Rt=Be(Re,1),Dt=Be($t,Bt-1),Lt=()=>`${Rt()}${Dt()}`,kt=(n,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===n,Pt=s.z.enum(["static","dynamic"]),jt=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),De=(n,e)=>{const t=new o(e);if(![p.DAY,p.HOUR,p.MINUTE,p.SECOND,p.MILLISECOND,p.MICROSECOND,p.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=n.valueOf()%t.valueOf();return n instanceof o?new o(r):new p(r)};class o extends Y{constructor(e,t="UTC"){if(e==null)super(o.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*o.MILLISECOND.valueOf());else if(typeof e=="string")super(o.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(o.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(r=o.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=o.MAX:e=o.MIN)),N(e)&&(e=e.value),super(BigInt(e.valueOf())+r)}}static parseDate([e=1970,t=1,r=1]){const i=new Date(e,t-1,r,0,0,0,0);return new o(BigInt(i.getTime())*o.MILLISECOND.valueOf()).truncate(o.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[r,i,a]=e.split(":");let c="00",g="00";a!=null&&([c,g]=a.split("."));let y=o.hours(parseInt(r??"00")).add(o.minutes(parseInt(i??"00"))).add(o.seconds(parseInt(c??"00"))).add(o.milliseconds(parseInt(g??"00")));return t==="local"&&(y=y.add(o.utcOffset)),y.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return o.parseTimeString(e,t);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new o(BigInt(r.getTime())*o.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(o.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const r=this.toISOString(t);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${t} ${r}`}static get utcOffset(){return new p(BigInt(new Date().getTimezoneOffset())*o.MINUTE.valueOf())}static since(e){return new o().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new o(e).valueOf()}span(e){return this.range(e).span}range(e){return new q(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new o(e).valueOf()}afterEq(e){return this.valueOf()>=new o(e).valueOf()}before(e){return this.valueOf()<new o(e).valueOf()}beforeEq(e){return this.valueOf()<=new o(e).valueOf()}add(e){return new o(te(this.valueOf(),new p(e).valueOf()))}sub(e){return new o(ee(this.valueOf(),new p(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(p.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(p.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(p.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(p.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(o.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(o.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new o(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new o(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new o(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new o(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new o(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new o(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new o(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new o(t)}toString(){return this.date().toISOString()}remainder(e){return De(this,e)}get isToday(){return this.truncate(p.DAY).equals(o.now().truncate(p.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new o(new Date)}static max(...e){let t=o.MIN;for(const r of e){const i=new o(r);i.after(t)&&(t=i)}return t}static min(...e){let t=o.MAX;for(const r of e){const i=new o(r);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new o(e,t)}static NANOSECOND=o.nanoseconds(1);static microseconds(e,t="UTC"){return o.nanoseconds(e*1e3,t)}static MICROSECOND=o.microseconds(1);static milliseconds(e,t="UTC"){return o.microseconds(e*1e3,t)}static MILLISECOND=o.milliseconds(1);static seconds(e,t="UTC"){return o.milliseconds(e*1e3,t)}static SECOND=o.seconds(1);static minutes(e,t="UTC"){return o.seconds(e*60,t)}static MINUTE=o.minutes(1);static hours(e,t="UTC"){return o.minutes(e*60,t)}static HOUR=o.hours(1);static days(e,t="UTC"){return o.hours(e*24,t)}static DAY=o.days(1);static MAX=new o((1n<<63n)-1n);static MIN=new o(0);static ZERO=new o(0);static z=s.z.union([s.z.instanceof(o),s.z.object({value:s.z.bigint()}).transform(e=>new o(e.value)),s.z.string().transform(e=>new o(BigInt(e))),s.z.number().transform(e=>new o(e)),s.z.bigint().transform(e=>new o(e)),s.z.date().transform(e=>new o(e)),s.z.custom(e=>e instanceof p).transform(e=>new o(e)),jt.transform(e=>new o(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let p=class l extends Y{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),N(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof l?e:e instanceof S?e.period:e instanceof o?new l(e):(N(e)&&(e=e.value),["number","bigint"].includes(typeof e)?l.seconds(e):new l(e))}static fromMilliseconds(e){return e instanceof l?e:e instanceof S?e.period:e instanceof o?new l(e):(N(e)&&(e=e.value),["number","bigint"].includes(typeof e)?l.milliseconds(e):new l(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new l(e).valueOf()}greaterThan(e){return this.valueOf()>new l(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new l(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new l(e).valueOf()}remainder(e){return De(this,e)}truncate(e){return new l(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(l.DAY),t=this.truncate(l.HOUR),r=this.truncate(l.MINUTE),i=this.truncate(l.SECOND),a=this.truncate(l.MILLISECOND),c=this.truncate(l.MICROSECOND),g=this.truncate(l.NANOSECOND),y=e,f=t.sub(e),m=r.sub(t),b=i.sub(r),h=a.sub(i),O=c.sub(a),E=g.sub(c);let U="";return y.isZero||(U+=`${y.days}d `),f.isZero||(U+=`${f.hours}h `),m.isZero||(U+=`${m.minutes}m `),b.isZero||(U+=`${b.seconds}s `),h.isZero||(U+=`${h.milliseconds}ms `),O.isZero||(U+=`${O.microseconds}µs `),E.isZero||(U+=`${E.nanoseconds}ns`),U.trim()}mult(e){return new l(A(this.valueOf(),e))}div(e){return new l(ne(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(l.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(l.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(l.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(l.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(l.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(l.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new l(e).valueOf()}add(e){return new l(this.valueOf()+new l(e).valueOf())}sub(e){return new l(this.valueOf()-new l(e).valueOf())}static nanoseconds(e=1){return new l(e)}static NANOSECOND=l.nanoseconds(1);static microseconds(e=1){return l.nanoseconds(A(e,1e3))}static MICROSECOND=l.microseconds(1);static milliseconds(e=1){return l.microseconds(A(e,1e3))}static MILLISECOND=l.milliseconds(1);static seconds(e=1){return l.milliseconds(A(e,1e3))}static SECOND=l.seconds(1);static minutes(e=1){return l.seconds(A(e,60))}static MINUTE=l.minutes(1);static hours(e){return l.minutes(A(e,60))}static HOUR=l.hours(1);static days(e){return l.hours(A(e,24))}static DAY=l.days(1);static MAX=new l((1n<<63n)-1n);static MIN=new l(0);static ZERO=new l(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new l(e.value)),s.z.string().transform(e=>new l(BigInt(e))),s.z.number().transform(e=>new l(e)),s.z.bigint().transform(e=>new l(e)),s.z.instanceof(l),s.z.instanceof(o).transform(e=>new l(e)),s.z.custom(e=>e instanceof S).transform(e=>new l(e))])};class S extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new S(e).valueOf()}get period(){return p.seconds(1/this.valueOf())}sampleCount(e){return new p(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new v(t).valueOf()}span(e){return p.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new v(t).valueOf())}add(e){return new S(te(this.valueOf(),new S(e).valueOf()))}sub(e){return new S(ee(this.valueOf(),new S(e).valueOf()))}mult(e){return new S(A(this.valueOf(),e))}div(e){return new S(ne(this.valueOf(),e))}static hz(e){return new S(e)}static khz(e){return S.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)])}let v=class I extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new ue(e*this.valueOf())}add(e){return new I(te(this.valueOf(),new I(e).valueOf()))}sub(e){return new I(ee(this.valueOf(),new I(e).valueOf()))}mult(e){return new I(A(this.valueOf(),e))}div(e){return new I(ne(this.valueOf(),e))}static UNKNOWN=new I(0);static BIT128=new I(16);static BIT64=new I(8);static BIT32=new I(4);static BIT16=new I(2);static BIT8=new I(1);static z=s.z.union([s.z.number().transform(e=>new I(e)),s.z.instanceof(I)])},q=class z{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new o(e.start),this.end=new o(e.end)):(this.start=new o(e),this.end=new o(t))}get span(){return new p(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new z(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=p.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=p.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=o.max(r.start,e.start),a=o.min(r.end,e.end);return a.before(i)?!1:new p(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof z?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new z(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new z(o.min(...e.map(t=>t.start)),o.max(...e.map(t=>t.end)))}static MAX=new z(o.MIN,o.MAX);static MIN=new z(o.MAX,o.MIN);static ZERO=new z(o.ZERO,o.ZERO);static z=s.z.union([s.z.object({start:o.z,end:o.z}).transform(e=>new z(e.start,e.end)),s.z.instanceof(z)]);static sort(e,t){return o.sort(e.start,t.start)||o.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,r)=>z.sort(t,r)).reduce((t,r)=>{if(r.isZero)return t;if(t.length===0)return t.push(r),t;const i=t[t.length-1];return i.overlapsWith(r)||i.end.equals(r.start)?i.end=o.max(i.end,r.end):t.push(r),t},[])}},w=class u extends Y{constructor(e){if(N(e)&&(e=e.value),e instanceof u||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=u.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=u.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(u.JSON)||this.equals(u.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(u.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=u.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(u.UINT8)||this.equals(u.UINT16)||this.equals(u.UINT32)||this.equals(u.UINT64)}get isSignedInteger(){return this.equals(u.INT8)||this.equals(u.INT16)||this.equals(u.INT32)||this.equals(u.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(u.INT32)&&e.equals(u.FLOAT64)||this.equals(u.INT8)&&e.equals(u.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return u.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new u("unknown");static FLOAT64=new u("float64");static FLOAT32=new u("float32");static INT64=new u("int64");static INT32=new u("int32");static INT16=new u("int16");static INT8=new u("int8");static UINT64=new u("uint64");static UINT32=new u("uint32");static UINT16=new u("uint16");static UINT8=new u("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new u("timestamp");static UUID=new u("uuid");static STRING=new u("string");static JSON=new u("json");static ARRAY_CONSTRUCTORS=new Map([[u.UINT8.toString(),Uint8Array],[u.UINT16.toString(),Uint16Array],[u.UINT32.toString(),Uint32Array],[u.UINT64.toString(),BigUint64Array],[u.FLOAT32.toString(),Float32Array],[u.FLOAT64.toString(),Float64Array],[u.INT8.toString(),Int8Array],[u.INT16.toString(),Int16Array],[u.INT32.toString(),Int32Array],[u.INT64.toString(),BigInt64Array],[u.TIMESTAMP.toString(),BigInt64Array],[u.STRING.toString(),Uint8Array],[u.JSON.toString(),Uint8Array],[u.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,u.UINT8],[Uint16Array.name,u.UINT16],[Uint32Array.name,u.UINT32],[BigUint64Array.name,u.UINT64],[Float32Array.name,u.FLOAT32],[Float64Array.name,u.FLOAT64],[Int8Array.name,u.INT8],[Int16Array.name,u.INT16],[Int32Array.name,u.INT32],[BigInt64Array.name,u.INT64]]);static DENSITIES=new Map([[u.UINT8.toString(),v.BIT8],[u.UINT16.toString(),v.BIT16],[u.UINT32.toString(),v.BIT32],[u.UINT64.toString(),v.BIT64],[u.FLOAT32.toString(),v.BIT32],[u.FLOAT64.toString(),v.BIT64],[u.INT8.toString(),v.BIT8],[u.INT16.toString(),v.BIT16],[u.INT32.toString(),v.BIT32],[u.INT64.toString(),v.BIT64],[u.TIMESTAMP.toString(),v.BIT64],[u.STRING.toString(),v.UNKNOWN],[u.JSON.toString(),v.UNKNOWN],[u.UUID.toString(),v.BIT128]]);static ALL=[u.UNKNOWN,u.FLOAT64,u.FLOAT32,u.INT64,u.INT32,u.INT16,u.INT8,u.UINT64,u.UINT32,u.UINT16,u.UINT8,u.TIMESTAMP,u.UUID,u.STRING,u.JSON];static BIG_INT_TYPES=[u.INT64,u.UINT64,u.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new u(e)),s.z.instanceof(u)])},ue=class d extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return N(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return N(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return N(e)&&(e=e.value),new d(te(this.valueOf(),e.valueOf()))}sub(e){return N(e)&&(e=e.value),new d(ee(this.valueOf(),e.valueOf()))}mult(e){return new d(A(this.valueOf(),e))}div(e){return new d(ne(this.valueOf(),e))}truncate(e){return new d(Math.trunc(this.valueOf()/new d(e).valueOf())*new d(e).valueOf())}remainder(e){return d.bytes(this.valueOf()%new d(e).valueOf())}get gigabytes(){return this.valueOf()/d.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/d.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/d.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/d.TERABYTE.valueOf()}toString(){const e=this.truncate(d.TERABYTE),t=this.truncate(d.GIGABYTE),r=this.truncate(d.MEGABYTE),i=this.truncate(d.KILOBYTE),a=this.truncate(d.BYTE),c=e,g=t.sub(e),y=r.sub(t),f=i.sub(r),m=a.sub(i);let b="";return c.isZero||(b+=`${c.terabytes}TB `),g.isZero||(b+=`${g.gigabytes}GB `),y.isZero||(b+=`${y.megabytes}MB `),f.isZero||(b+=`${f.kilobytes}KB `),(!m.isZero||b==="")&&(b+=`${m.valueOf()}B`),b.trim()}static bytes(e=1){return new d(e)}static BYTE=new d(1);static kilobytes(e=1){return d.bytes(new d(e).valueOf()*1e3)}static KILOBYTE=d.kilobytes(1);static megabytes(e=1){return d.kilobytes(new d(e).valueOf()*1e3)}static MEGABYTE=d.megabytes(1);static gigabytes(e=1){return d.megabytes(new d(e).valueOf()*1e3)}static GIGABYTE=d.gigabytes(1);static terabytes(e){return d.gigabytes(new d(e).valueOf()*1e3)}static TERABYTE=d.terabytes(1);static ZERO=new d(0);static z=s.z.union([s.z.number().transform(e=>new d(e)),s.z.instanceof(d)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Le=n=>{const e=typeof n;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||n instanceof o||n instanceof p||n instanceof Date},Yt=(n,e,t,r=0)=>n.usesBigInt&&!e.usesBigInt?Number(t)-Number(r):!n.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(r.valueOf()):J(t,-r),J=(n,e)=>e==0?n:n==0?e:typeof n=="bigint"&&typeof e=="bigint"||typeof n=="number"&&typeof e=="number"?n+e:Number(n)+Number(e),qt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Ft(n){return typeof n=="string"&&qt.test(n)}const T=[];for(let n=0;n<256;++n)T.push((n+256).toString(16).slice(1));function Wt(n,e=0){return(T[n[e+0]]+T[n[e+1]]+T[n[e+2]]+T[n[e+3]]+"-"+T[n[e+4]]+T[n[e+5]]+"-"+T[n[e+6]]+T[n[e+7]]+"-"+T[n[e+8]]+T[n[e+9]]+"-"+T[n[e+10]]+T[n[e+11]]+T[n[e+12]]+T[n[e+13]]+T[n[e+14]]+T[n[e+15]]).toLowerCase()}function Zt(n,e=0){const t=Wt(n,e);if(!Ft(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ke=(n,e)=>Zt(n,e),M=-1,Vt=s.z.string().transform(n=>new Uint8Array(atob(n).split("").map(e=>e.charCodeAt(0))).buffer),Gt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),le=10,Ht=(n,e)=>{if(n==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(n==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Pe="sy_x_telem_series";let je=class C{key;discriminator=Pe;dataType;sampleOffset;gl;_data;timeRange=q.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=M;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:q.z.optional(),dataType:w.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Vt,Gt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Pt.optional().default("static").optional()});static z=C.crudeZ.transform(e=>new C(e));constructor(e){Jt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:c=0n,alignmentMultiple:g=1n,key:y=Lt(),data:f}=e;if(Xt(f)){const h=f;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this.timeRange=h.timeRange,this.alignment=h.alignment,this.alignmentMultiple=h.alignmentMultiple,this.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const m=Le(f),b=Array.isArray(f);if(t!=null)this.dataType=new w(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(b||m){let h=f;if(!m){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=f[0]}if(typeof h=="string")this.dataType=w.STRING;else if(typeof h=="number")this.dataType=w.FLOAT64;else if(typeof h=="bigint")this.dataType=w.INT64;else if(typeof h=="boolean")this.dataType=w.BOOLEAN;else if(h instanceof o||h instanceof Date||h instanceof o)this.dataType=w.TIMESTAMP;else if(typeof h=="object")this.dataType=w.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new w(f)}if(!b&&!m)this._data=f;else if(b&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=m?[f]:f;const O=h[0];(O instanceof o||O instanceof Date||O instanceof p)&&(h=h.map(E=>new o(E).valueOf())),this.dataType.equals(w.STRING)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
2
2
  `)}
3
- `).buffer):this.dataType.equals(w.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(z=>ae.encodeString(z)).join(`
3
+ `).buffer):this.dataType.equals(w.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(E=>oe.encodeString(E)).join(`
4
4
  `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof O=="number"?this._data=new this.dataType.Array(h.map(z=>BigInt(Math.round(z)))).buffer:!this.dataType.usesBigInt&&typeof O=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=y,this.alignment=c,this.alignmentMultiple=d,this.sampleOffset=i??0,this.timeRange=n??Y.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new w(t).Array(e),a=new A({data:i.buffer,dataType:t,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===M)return 0;const t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===M)return 0;const t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===M?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
6
- `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(w.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ae.decodeString(t)))}get byteCapacity(){return new oe(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===M?this.byteCapacity:this.dataType.isVariable?new oe(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===M?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((n,i)=>{n===ue&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=kt(this.dataType,e,this.data[i],t);return new A({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(w.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),H(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(w.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),H(this.cachedMin,this.sampleOffset))}get bounds(){return $(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(w.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return H(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=Le(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,i=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let c=0;c<this.data.length;c++)if(this.data[c]===ue){if(e===0){i=c;break}n=c+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals(w.STRING)?new TextDecoder().decode(a):Ne(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=rt(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=i(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(w.FLOAT32)&&!this.dataType.equals(w.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==M){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,c.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=M}as(e){return Vt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Se(this.alignmentBounds.lower),upper:Se(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return $(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Jt(this);return this.dataType.equals(w.JSON)?new Xt(e):e}return this.dataType.equals(w.UUID)?new Kt(this):new Qt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ve(this,e,t??this.length)}subAlignmentIterator(e,t){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new ve(this,n,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new A({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let i;return e?i=this.data.subarray(t,n):i=this.data.slice(t,n),new A({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new A({data:this.buffer,dataType:this.dataType,timeRange:Y.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=",";e+="...,";for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=",")}return e+="])",e}}const Gt=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof A?!0:De(r),Ht=Dt(Pe,A);class ve{series;end;index;constructor(e,t,n){this.series=e;const i=$(0,e.length+1);this.end=we(i,n),this.index=we(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class Jt{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==ue;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}}let Xt=class ke{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:ae.decodeString(e.value,ke.schema)}}};class Kt{series;index;data;density;constructor(e){if(!e.dataType.equals(w.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=w.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Le(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Qt=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};const Se=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const _t=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";_t();const er=["macOS","Windows","Linux"],tr=["macos","windows","linux"],rr={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(er).or(s.z.enum(tr).transform(r=>rr[r]));const nr=(...r)=>r.map(je).join(""),je=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),sr=r=>r.endsWith("/")?r.slice(0,-1):r,ir=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,n])=>`${e}${t}=${n}`).join("&")}`;class F{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=je(i)}replace(e){return new F({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new F({...this,pathPrefix:nr(this.path,e)})}toString(){return sr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new F({host:"unknown",port:0})}const ar=async r=>await new Promise(e=>setTimeout(e,g.fromMilliseconds(r).milliseconds));class or{config;retries;interval;constructor(e){this.config={baseInterval:new g(e?.baseInterval??g.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ar},this.retries=0,this.interval=new g(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const ur=s.z.object({baseInterval:g.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),lr=Object.freeze(Object.defineProperty({__proto__:null,Breaker:or,breakerConfigZ:ur},Symbol.toStringTag,{value:"Module"})),cr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Ye=s.z.string().regex(cr),k=s.z.number().min(0).max(255),qe=s.z.number().min(0).max(1),Fe=s.z.tuple([k,k,k,qe]),hr=s.z.tuple([k,k,k]),fr=s.z.object({rgba255:Fe}),dr=s.z.number().min(0).max(360),gr=s.z.number().min(0).max(100),pr=s.z.number().min(0).max(100),mr=s.z.tuple([dr,gr,pr,qe]),fe=s.z.union([Ye,hr,Fe,mr,fr]),yr=fe.transform(r=>de(r)),de=(r,e=1)=>{if(r=fe.parse(r),typeof r=="string")return wr(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},wr=(r,e=1)=>(r=Ye.parse(r),r=br(r),[G(r,0),G(r,2),G(r,4),r.length===8?G(r,6)/255:e]),G=(r,e)=>parseInt(r.slice(e,e+2),16),br=r=>r.startsWith("#")?r.slice(1):r;de("#000000");de("#ffffff");const Or=s.z.object({key:s.z.string(),color:fe,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Or);const Tr=s.z.object({key:s.z.string(),name:s.z.string(),color:yr});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Tr)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const vr=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Sr=(r,e)=>{const t=Symbol.for(r);if(!vr(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},We="sy_x_error",Ir=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(r):e instanceof Error?e.message.startsWith(r):typeof e!="string"?!1:e.startsWith(r),W=r=>class q extends Error{static discriminator=We;discriminator=q.discriminator;static TYPE=r;type=q.TYPE;static matches=Ir(r);matches=q.matches;constructor(t,n){super(t,n),this.name=q.TYPE}static sub(t){return W(`${r}.${t}`)}},Ze=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==We)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},P="unknown",le="nil";class Nr{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:le,data:""};if(Ze(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:P,data:e.message};if(typeof e=="string")return{type:P,data:e};try{return{type:P,data:JSON.stringify(e)}}catch{return{type:P,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===le)return null;if(e.type===P)return new ce(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new ce(e.data)}}const ge=Sr("synnax-error-registry",()=>new Nr),zr=({encode:r,decode:e})=>ge().register({encode:r,decode:e}),Er=r=>ge().encode(r),xr=r=>r==null?null:ge().decode(r);class ce extends W("unknown"){}const Ar=s.z.object({type:s.z.string(),data:s.z.string()});class Ur extends W("canceled"){}class Mr extends W("not_implemented"){}const C=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Ur,NONE:le,NotImplemented:Mr,UNKNOWN:P,Unknown:ce,createTyped:W,decode:xr,encode:Er,isTyped:Ze,payloadZ:Ar,register:zr},Symbol.toStringTag,{value:"Module"})),Cr=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Ve=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),$r=Ve.extend({result:s.json()}),Br=Ve.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Rr=s.union([$r,Br]);s.union([Cr,Rr]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Dr=["standard","scientific","engineering"];s.z.enum(Dr);s.z.enum(["success","info","warning","error","loading","disabled"]);class Z extends C.createTyped("freighter"){}class B extends Z.sub("eof"){constructor(){super("EOF")}}class R extends Z.sub("stream_closed"){constructor(){super("StreamClosed")}}class D extends Z.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=F.UNKNOWN}=e;super(t),this.url=n}}const Lr=r=>{if(!r.type.startsWith(Z.TYPE))return null;if(B.matches(r))return{type:B.TYPE,data:"EOF"};if(R.matches(r))return{type:R.TYPE,data:"StreamClosed"};if(D.matches(r))return{type:D.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Pr=r=>{if(!r.type.startsWith(Z.TYPE))return null;switch(r.type){case B.TYPE:return new B;case R.TYPE:return new R;case D.TYPE:return new D;default:throw new C.Unknown(`Unknown error type: ${r.data}`)}};C.register({encode:Lr,decode:Pr});class Ge{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,i)};return await i(e)}}const He="Content-Type",kr=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),jr=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&kr.has(e))return!0;if(r.name==="TypeError"){const t=String(r.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<"u"&&navigator.onLine===!1,!0}return r?.name==="AbortError"||r?.code==="ABORT_ERR",!1},Yr=400;class qr extends Ge{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,c)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,c)})}get headers(){return{[He]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let a=null;const c=this.endpoint.child(e),d={};d.method="POST",d.body=this.encoder.encode(t??{});const[,y]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async f=>{const p={...f,params:{}};d.headers={...this.headers,...f.params};let b;try{b=await fetch(f.target,d)}catch(O){if(!(O instanceof Error))throw O;return[p,jr(O)?new D({url:c}):O]}const h=await b.arrayBuffer();if(b?.ok)return i!=null&&(a=this.encoder.decode(h,i)),[p,null];try{if(b.status!==Yr)return[p,new Error(b.statusText)];const O=this.encoder.decode(h,C.payloadZ),z=C.decode(O);return[p,z]}catch(O){return[p,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${O.message}`)]}});if(y!=null)return[null,y];if(a==null)throw new Error("Response must be defined");return[a,null]}}const Fr=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,c,d){const y=new lr.Breaker(e);do{const[f,p]=await this.wrapped.send(i,a,c,d);if(p==null)return[f,null];if(!D.matches(p))return[null,p];if(console.warn(`[freighter] ${y.retryMessage}`,p),!await y.wait())return[f,p]}while(!0)}}return new t(r)},Wr=async(r,e,t,n,i)=>{const[a,c]=await r.send(e,t,n,i);if(c!=null)throw c;return a},Zr=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(C.payloadZ)});class Vr{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,i){this.codec=t,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return C.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new B;if(this.sendClosed)throw new R;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=C.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,n)=>this.receiveCallbacksQueue.push({resolve:t,reject:n}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Zr))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Hr?B.TYPE:R.TYPE,data:""}})}}const Gr="freighterctx",Hr=1e3;class X extends Ge{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,t,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=t}withCodec(e){const t=new X(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const d=new WebSocket(this.buildURL(e,c)),y={...c,params:{}};d.binaryType=X.MESSAGE_TYPE;const f=await this.wrapSocket(d,t,n);return f instanceof Error?[y,f]:(i=f,[y,null])});if(a!=null)throw a;return i}buildURL(e,t){const n=ir({[He]:this.encoder.contentType,...t.params},Gr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const a=new Vr(e,this.encoder,t,n);a.receiveOpenAck().then(c=>{c!=null?i(c):i(a)}).catch(c=>i(c))},e.onerror=a=>{const c=a;i(new Error(c.message))}})}}exports.EOF=B;exports.HTTPClient=qr;exports.StreamClosed=R;exports.Unreachable=D;exports.WebSocketClient=X;exports.sendRequired=Wr;exports.unaryWithBreaker=Fr;
5
+ `).buffer):this.dataType.usesBigInt&&typeof O=="number"?this._data=new this.dataType.Array(h.map(E=>BigInt(Math.round(E)))).buffer:!this.dataType.usesBigInt&&typeof O=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=y,this.alignment=c,this.alignmentMultiple=g,this.sampleOffset=i??0,this.timeRange=r??q.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new w(t).Array(e),a=new C({data:i.buffer,dataType:t,...r});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===M)return 0;const t=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,t);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===M)return 0;const t=this.capacity-this.writePos,r=e.sub(0,t);return this.writeToUnderlyingData(r),this.cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===M?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
6
+ `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(w.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(oe.decodeString(t)))}get byteCapacity(){return new ue(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===M?this.byteCapacity:this.dataType.isVariable?new ue(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===M?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((r,i)=>{r===le&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Yt(this.dataType,e,this.data[i],t);return new C({data:r.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(w.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}else{const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),J(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(w.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}else{const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),J(this.cachedMin,this.sampleOffset))}get bounds(){return B(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const r=Number((e-this.alignment)/this.alignmentMultiple);if(r<0||r>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(w.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return J(r,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const r=ke(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(r==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return r}atVariable(e,t){let r=0,i=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let c=0;c<this.data.length;c++)if(this.data[c]===le){if(e===0){i=c;break}r=c+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(w.STRING)?new TextDecoder().decode(a):ze(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,r=this.length-1;const i=st(e);for(;t<=r;){const a=Math.floor((t+r)/2),c=i(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:r=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(w.FLOAT32)&&!this.dataType.equals(w.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:r,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==M){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,c.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=M}as(e){return Ht(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Se(this.alignmentBounds.lower),upper:Se(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return B(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Kt(this);return this.dataType.equals(w.JSON)?new Qt(e):e}return this.dataType.equals(w.UUID)?new _t(this):new en(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Ie(this,e,t??this.length)}subAlignmentIterator(e,t){const r=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Ie(this,r,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,t);return new C({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,r){if(t<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(t,r):i=this.data.slice(t,r),new C({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new C({data:this.buffer,dataType:this.dataType,timeRange:q.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=",";e+="...,";for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=",")}return e+="])",e}};const Jt=n=>n==null?!1:Array.isArray(n)||n instanceof ArrayBuffer||ArrayBuffer.isView(n)&&!(n instanceof DataView)||n instanceof je?!0:Le(n),Xt=kt(Pe,je);let Ie=class{series;end;index;constructor(e,t,r){this.series=e;const i=B(0,e.length+1);this.end=be(i,r),this.index=be(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class Kt{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==le;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}}let Qt=class Ye{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:oe.decodeString(e.value,Ye.schema)}}},_t=class{series;index;data;density;constructor(e){if(!e.dataType.equals(w.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=w.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ke(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}};class en{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}const Se=n=>{const e=n>>32n,t=n&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const tn=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";tn();const nn=["macOS","Windows","Linux"],rn=["macos","windows","linux"],sn={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(nn).or(s.z.enum(rn).transform(n=>sn[n]));const an=(...n)=>n.map(qe).join(""),qe=n=>(n.endsWith("/")||(n+="/"),n.startsWith("/")&&(n=n.slice(1)),n),on=n=>n.endsWith("/")?n.slice(0,-1):n,un=(n,e="")=>n===null?"":`?${Object.entries(n).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,r])=>`${e}${t}=${r}`).join("&")}`;class W{protocol;host;port;path;constructor({host:e,port:t,protocol:r="",pathPrefix:i=""}){this.protocol=r,this.host=e,this.port=t,this.path=qe(i)}replace(e){return new W({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new W({...this,pathPrefix:an(this.path,e)})}toString(){return on(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new W({host:"unknown",port:0})}const ln=async n=>await new Promise(e=>setTimeout(e,p.fromMilliseconds(n).milliseconds));class cn{config;retries;interval;constructor(e){this.config={baseInterval:new p(e?.baseInterval??p.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ln},this.retries=0,this.interval=new p(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const hn=s.z.object({baseInterval:p.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),fn=Object.freeze(Object.defineProperty({__proto__:null,Breaker:cn,breakerConfigZ:hn},Symbol.toStringTag,{value:"Module"})),dn=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Fe=s.z.string().regex(dn),j=s.z.number().min(0).max(255),We=s.z.number().min(0).max(1),Ze=s.z.tuple([j,j,j,We]),gn=s.z.tuple([j,j,j]),pn=s.z.object({rgba255:Ze}),mn=s.z.number().min(0).max(360),yn=s.z.number().min(0).max(100),wn=s.z.number().min(0).max(100),bn=s.z.tuple([mn,yn,wn,We]),de=s.z.union([Fe,gn,Ze,bn,pn]),On=de.transform(n=>ge(n)),ge=(n,e=1)=>{if(n=de.parse(n),typeof n=="string")return Tn(n,e);if(Array.isArray(n)){if(n.length<3||n.length>4)throw new Error(`Invalid color: [${n.join(", ")}]`);return n.length===3?[...n,e]:n}return n.rgba255},Tn=(n,e=1)=>(n=Fe.parse(n),n=vn(n),[H(n,0),H(n,2),H(n,4),n.length===8?H(n,6)/255:e]),H=(n,e)=>parseInt(n.slice(e,e+2),16),vn=n=>n.startsWith("#")?n.slice(1):n;ge("#000000");ge("#ffffff");const In=s.z.object({key:s.z.string(),color:de,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(In);const Sn=s.z.object({key:s.z.string(),name:s.z.string(),color:On});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Sn)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const Nn=n=>Object.getOwnPropertySymbols(globalThis).includes(n),zn=(n,e)=>{const t=Symbol.for(n);if(!Nn(t)){const r=e();Object.defineProperty(globalThis,t,{value:r})}return()=>globalThis[t]},Ve="sy_x_error",En=n=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(n):e instanceof Error?e.message.startsWith(n):typeof e!="string"?!1:e.startsWith(n),Z=n=>class F extends Error{static discriminator=Ve;discriminator=F.discriminator;static TYPE=n;type=F.TYPE;static matches=En(n);matches=F.matches;constructor(t,r){super(t,r),this.name=F.TYPE}static sub(t){return Z(`${n}.${t}`)}},Ge=n=>{if(n==null||typeof n!="object")return!1;const e=n;if(e.discriminator!==Ve)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},P="unknown",ce="nil";class xn{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ce,data:""};if(Ge(e))for(const t of this.providers){const r=t.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:P,data:e.message};if(typeof e=="string")return{type:P,data:e};try{return{type:P,data:JSON.stringify(e)}}catch{return{type:P,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ce)return null;if(e.type===P)return new he(e.data);for(const t of this.providers){const r=t.decode(e);if(r!=null)return r}return new he(e.data)}}const pe=zn("synnax-error-registry",()=>new xn),An=({encode:n,decode:e})=>pe().register({encode:n,decode:e}),Un=n=>pe().encode(n),Mn=n=>n==null?null:pe().decode(n);class he extends Z("unknown"){}const Cn=s.z.object({type:s.z.string(),data:s.z.string()});class $n extends Z("canceled"){}class Bn extends Z("not_implemented"){}const $=Object.freeze(Object.defineProperty({__proto__:null,Canceled:$n,NONE:ce,NotImplemented:Bn,UNKNOWN:P,Unknown:he,createTyped:Z,decode:Mn,encode:Un,isTyped:Ge,payloadZ:Cn,register:An},Symbol.toStringTag,{value:"Module"})),Rn=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),He=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Dn=He.extend({result:s.json()}),Ln=He.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),kn=s.union([Dn,Ln]);s.union([Rn,kn]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Pn=["standard","scientific","engineering"];s.z.enum(Pn);s.z.enum(["success","info","warning","error","loading","disabled"]);class V extends $.createTyped("freighter"){}class R extends V.sub("eof"){constructor(){super("EOF")}}class D extends V.sub("stream_closed"){constructor(){super("StreamClosed")}}class L extends V.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:r=W.UNKNOWN}=e;super(t),this.url=r}}const jn=n=>{if(!n.type.startsWith(V.TYPE))return null;if(R.matches(n))return{type:R.TYPE,data:"EOF"};if(D.matches(n))return{type:D.TYPE,data:"StreamClosed"};if(L.matches(n))return{type:L.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${n.type}: ${n.message}`)},Yn=n=>{if(!n.type.startsWith(V.TYPE))return null;switch(n.type){case R.TYPE:return new R;case D.TYPE:return new D;case L.TYPE:return new L;default:throw new $.Unknown(`Unknown error type: ${n.data}`)}};$.register({encode:jn,decode:Yn});class Je{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let r=0;const i=async a=>{if(r===this.middleware.length)return await t(a);const c=this.middleware[r];return r++,await c(a,i)};return await i(e)}}const Xe="Content-Type",qn=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Fn=n=>{const e=n?.cause?.code??n?.code??n?.errno;if(typeof e=="string"&&qn.has(e))return!0;if(n.name==="TypeError"){const t=String(n.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<"u"&&navigator.onLine===!1,!0}return n?.name==="AbortError"||n?.code==="ABORT_ERR",!1},Wn=400;class Zn extends Je{endpoint;encoder;constructor(e,t,r=!1){return super(),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,c)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,c)})}get headers(){return{[Xe]:this.encoder.contentType}}async send(e,t,r,i){t=r?.parse(t);let a=null;const c=this.endpoint.child(e),g={};g.method="POST",g.body=this.encoder.encode(t??{});const[,y]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async f=>{const m={...f,params:{}};g.headers={...this.headers,...f.params};let b;try{b=await fetch(f.target,g)}catch(O){if(!(O instanceof Error))throw O;return[m,Fn(O)?new L({url:c}):O]}const h=await b.arrayBuffer();if(b?.ok)return i!=null&&(a=this.encoder.decode(h,i)),[m,null];try{if(b.status!==Wn)return[m,new Error(b.statusText)];const O=this.encoder.decode(h,$.payloadZ),E=$.decode(O);return[m,E]}catch(O){return[m,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${O.message}`)]}});if(y!=null)return[null,y];if(a==null)throw new Error("Response must be defined");return[a,null]}}const Vn=(n,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,c,g){const y=new fn.Breaker(e);do{const[f,m]=await this.wrapped.send(i,a,c,g);if(m==null)return[f,null];if(!L.matches(m))return[null,m];if(console.warn(`[freighter] ${y.retryMessage}`,m),!await y.wait())return[f,m]}while(!0)}}return new t(n)},Gn=async(n,e,t,r,i)=>{const[a,c]=await n.send(e,t,r,i);if(c!=null)throw c;return a},Hn=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional($.payloadZ)});class Jn{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,r,i){this.codec=t,this.reqSchema=r,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return $.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new R;if(this.sendClosed)throw new D;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=$.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,r)=>this.receiveCallbacksQueue.push({resolve:t,reject:r}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Hn))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Kn?R.TYPE:D.TYPE,data:""}})}}const Xn="freighterctx",Kn=1e3;class K extends Je{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,t,r=!1){super(),this.secure=r,this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=t}withCodec(e){const t=new K(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,r){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const g=new WebSocket(this.buildURL(e,c)),y={...c,params:{}};g.binaryType=K.MESSAGE_TYPE;const f=await this.wrapSocket(g,t,r);return f instanceof Error?[y,f]:(i=f,[y,null])});if(a!=null)throw a;return i}buildURL(e,t){const r=un({[Xe]:this.encoder.contentType,...t.params},Xn);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,t,r){return await new Promise(i=>{e.onopen=()=>{const a=new Jn(e,this.encoder,t,r);a.receiveOpenAck().then(c=>{c!=null?i(c):i(a)}).catch(c=>i(c))},e.onerror=a=>{const c=a;i(new Error(c.message))}})}}exports.EOF=R;exports.HTTPClient=Zn;exports.StreamClosed=D;exports.Unreachable=L;exports.WebSocketClient=K;exports.sendRequired=Gn;exports.unaryWithBreaker=Vn;