@synnaxlabs/freighter 0.44.0 → 0.44.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ye=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)},be=n=>{const e=(t,r=_)=>{if(typeof t=="string")return n(t);if(Array.isArray(t))return t.map(l=>e(l,r));if(!X(t))return t;r=Ze(r);const i={},o=t;return"toJSON"in o&&typeof o.toJSON=="function"?e(o.toJSON(),r):(Object.keys(o).forEach(l=>{let d=o[l];const f=n(l);r.recursive&&(X(d)?le(d)||(d=e(d,r)):r.recursiveInArray&&ce(d)&&(d=[...d].map(g=>{let m=g;return X(g)?le(m)||(m=e(g,r)):ce(g)&&(m=e({key:g},r).key),m}))),i[f]=d}),i)};return e},Te=be(Ye),qe=n=>n.replace(/([a-z0-9])([A-Z])/g,(e,t,r)=>`${t}_${r.toLowerCase()}`),Fe=be(qe),We=[Number,String,Uint8Array],_={recursive:!0,recursiveInArray:!0},Ze=(n=_)=>(n.recursive==null?n=_:n.recursiveInArray??=!1,n),ce=n=>n!=null&&Array.isArray(n),X=n=>n!=null&&typeof n=="object"&&!Array.isArray(n),le=n=>We.some(e=>n instanceof e);let Ve=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=Te(r);return t!=null?t.parse(i):i}encodeString(e){const t=Fe(e);return JSON.stringify(t,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const ee=new Ve;let P=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Ge=n=>n!=null&&typeof n=="object"&&"toString"in n,Je=(n,e=!1)=>{const t=Ge(n)?"stringer":typeof n;let r;switch(t){case"string":r=(i,o)=>i.localeCompare(o);break;case"stringer":r=(i,o)=>i.toString().localeCompare(o.toString());break;case"number":r=(i,o)=>Number(i)-Number(o);break;case"bigint":r=(i,o)=>BigInt(i)-BigInt(o)>0n?1:-1;break;case"boolean":r=(i,o)=>Number(i)-Number(o);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?He(r):r},He=n=>(e,t)=>n(t,e),H=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Oe=s.z.object({width:s.z.number(),height:s.z.number()}),Xe=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Ke=["width","height"];s.z.enum(Ke);const Qe=["start","center","end"],_e=["signedWidth","signedHeight"];s.z.enum(_e);const G=s.z.object({x:s.z.number(),y:s.z.number()}),et=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),tt=["x","y"],ve=s.z.enum(tt),Ie=["top","right","bottom","left"];s.z.enum(Ie);const nt=["left","right"],Se=s.z.enum(nt),rt=["top","bottom"],Ne=s.z.enum(rt),ze=["center"],he=s.z.enum(ze),st=[...Ie,...ze],xe=s.z.enum(st);s.z.enum(Qe);const it=["first","last"];s.z.enum(it);const at=s.z.object({lower:s.z.number(),upper:s.z.number()}),ot=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([at,H]);s.z.union([ot,H]);s.z.enum([...ve.options,...xe.options]);s.z.union([ve,xe,s.z.instanceof(String)]);const B=(n,e)=>typeof n=="bigint"?n*BigInt(e):n*Number(e),A=(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?ut(r):r},ut=n=>n.lower>n.upper?{lower:n.upper,upper:n.lower}:n,fe=(n,e)=>{const t=A(n);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Se.or(he),y:Ne.or(he)});const ct=s.z.object({x:Se,y:Ne}),lt=Object.freeze({x:"left",y:"top"}),ht=(n,e)=>n.x===e.x&&n.y===e.y,de=s.z.union([s.z.number(),G,H,Oe,Xe,et]),ft=(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}},ge=Object.freeze({x:0,y:0}),W=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:W,left:W,width:W,height:W});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:G,two:G,root:ct});const se=(n,e,t=0,r=0,i)=>{const o={one:{...ge},two:{...ge},root:i??lt};if(typeof n=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return o.one={x:n,y:e},o.two={x:o.one.x+t,y:o.one.y+r},o}return"one"in n&&"two"in n&&"root"in n?{...n,root:i??n.root}:("getBoundingClientRect"in n&&(n=n.getBoundingClientRect()),"left"in n?(o.one={x:n.left,y:n.top},o.two={x:n.right,y:n.bottom},o):(o.one=n,e==null?o.two={x:o.one.x+t,y:o.one.y+r}:typeof e=="number"?o.two={x:o.one.x+e,y:o.one.y+t}:"width"in e?o.two={x:o.one.x+e.width,y:o.one.y+e.height}:"signedWidth"in e?o.two={x:o.one.x+e.signedWidth,y:o.one.y+e.signedHeight}:o.two=e,o))},K=n=>{const e=se(n);return{lower:e.one.x,upper:e.two.x}},Q=n=>{const e=se(n);return{lower:e.one.y,upper:e.two.y}},dt=n=>typeof n!="object"||n==null?!1:"one"in n&&"two"in n&&"root"in n,gt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Oe,gt,G,H]);const pt=(n,e,t)=>e!==void 0&&n<e?e:t!==void 0&&n>t?t:n;s.z.object({offset:de,scale:de});s.z.object({offset:s.z.number(),scale:s.z.number()});const yt=n=>(e,t,r,i)=>t==="dimension"?[e,r]:[e,i?r-n:r+n],mt=n=>(e,t,r,i)=>[e,i?r/n:r*n],wt=n=>(e,t,r)=>{if(e===null)return[n,r];const{lower:i,upper:o}=e,{lower:l,upper:d}=n,f=o-i,g=d-l;if(t==="dimension")return[n,r*(g/f)];const m=(r-i)*(g/f)+l;return[n,m]},bt=n=>(e,t,r)=>[n,r],Tt=()=>(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)]},Ot=n=>(e,t,r)=>{const{lower:i,upper:o}=n;return r=pt(r,i,o),[e,r]};let pe=class ${ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new $().translate(e)}static magnify(e){return new $().magnify(e)}static scale(e,t){return new $().scale(e,t)}translate(e){const t=this.new(),r=yt(e);return r.type="translate",t.ops.push(r),t}magnify(e){const t=this.new(),r=mt(e);return r.type="magnify",t.ops.push(r),t}scale(e,t){const r=A(e,t),i=this.new(),o=wt(r);return o.type="scale",i.ops.push(o),i}clamp(e,t){const r=A(e,t),i=this.new(),o=Ot(r);return o.type="clamp",i.ops.push(o),i}reBound(e,t){const r=A(e,t),i=this.new(),o=bt(r);return o.type="re-bound",i.ops.push(o),i}invert(){const e=Tt();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 $;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([r,i],o)=>o(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(([l,d])=>i>=l&&i<=d))return;const o=e.ops.findIndex((l,d)=>l.type==="scale"&&d>i);o!==-1&&t.push([i,o])}),t.forEach(([r,i])=>{const o=e.ops.slice(r,i);o.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...o)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new $},Yn=class I{x;y;currRoot;constructor(e=new pe,t=new pe,r=null){this.x=e,this.y=t,this.currRoot=r}static translate(e,t){return new I().translate(e,t)}static translateX(e){return new I().translateX(e)}static translateY(e){return new I().translateY(e)}static clamp(e){return new I().clamp(e)}static magnify(e){return new I().magnify(e)}static scale(e){return new I().scale(e)}static reBound(e){return new I().reBound(e)}translate(e,t){const r=ft(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(dt(e)){const r=this.currRoot;return t.currRoot=e.root,r!=null&&!ht(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(K(e)),t.y=t.y.scale(Q(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(K(e)),t.y=this.y.reBound(Q(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(K(e)),t.y=this.y.clamp(Q(e)),t}copy(){const e=new I;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 se(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 I},vt=(n,e=21)=>(t=e)=>{let r="",i=t|0;for(;i--;)r+=n[Math.random()*n.length|0];return r};const It="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",St=11,Nt=vt(It,St),zt=()=>Nt(),xt=(n,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===n,Et=s.z.enum(["static","dynamic"]),At=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)])]),Ee=(n,e)=>{const t=new y(e);if(![u.DAY,u.HOUR,u.MINUTE,u.SECOND,u.MILLISECOND,u.MICROSECOND,u.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 y?new y(r):new u(r)};let y=class c extends P{constructor(e,t="UTC"){if(e==null)super(c.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*c.MILLISECOND.valueOf());else if(typeof e=="string")super(c.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(c.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(r=c.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=c.MAX:e=c.MIN)),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 c(BigInt(i.getTime())*c.MILLISECOND.valueOf()).truncate(c.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[r,i,o]=e.split(":");let l="00",d="00";o!=null&&([l,d]=o.split("."));let f=c.hours(parseInt(r??"00")).add(c.minutes(parseInt(i??"00"))).add(c.seconds(parseInt(l??"00"))).add(c.milliseconds(parseInt(d??"00")));return t==="local"&&(f=f.add(c.utcOffset)),f.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return c.parseTimeString(e,t);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new c(BigInt(r.getTime())*c.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(c.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 u(BigInt(new Date().getTimezoneOffset())*c.MINUTE.valueOf())}static since(e){return new c().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new c(e).valueOf()}span(e){return this.range(e).span}range(e){return new O(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new c(e).valueOf()}afterEq(e){return this.valueOf()>=new c(e).valueOf()}before(e){return this.valueOf()<new c(e).valueOf()}beforeEq(e){return this.valueOf()<=new c(e).valueOf()}add(e){return new c(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new c(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(u.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(u.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(u.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(u.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(c.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(c.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 c(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new c(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new c(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new c(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new c(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new c(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new c(t)}toString(){return this.date().toISOString()}remainder(e){return Ee(this,e)}get isToday(){return this.truncate(u.DAY).equals(c.now().truncate(u.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new c(new Date)}static max(...e){let t=c.MIN;for(const r of e){const i=new c(r);i.after(t)&&(t=i)}return t}static min(...e){let t=c.MAX;for(const r of e){const i=new c(r);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new c(e,t)}static NANOSECOND=c.nanoseconds(1);static microseconds(e,t="UTC"){return c.nanoseconds(e*1e3,t)}static MICROSECOND=c.microseconds(1);static milliseconds(e,t="UTC"){return c.microseconds(e*1e3,t)}static MILLISECOND=c.milliseconds(1);static seconds(e,t="UTC"){return c.milliseconds(e*1e3,t)}static SECOND=c.seconds(1);static minutes(e,t="UTC"){return c.seconds(e*60,t)}static MINUTE=c.minutes(1);static hours(e,t="UTC"){return c.minutes(e*60,t)}static HOUR=c.hours(1);static days(e,t="UTC"){return c.hours(e*24,t)}static DAY=c.days(1);static MAX=new c((1n<<63n)-1n);static MIN=new c(0);static ZERO=new c(0);static z=s.z.union([s.z.instanceof(c),s.z.object({value:s.z.bigint()}).transform(e=>new c(e.value)),s.z.string().transform(e=>new c(BigInt(e))),s.z.number().transform(e=>new c(e)),s.z.bigint().transform(e=>new c(e)),s.z.date().transform(e=>new c(e)),s.z.custom(e=>e instanceof u).transform(e=>new c(e)),At.transform(e=>new c(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}};class u extends P{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof u?e:e instanceof ye?e.period:e instanceof y?new u(e):["number","bigint"].includes(typeof e)?u.seconds(e):new u(e)}static fromMilliseconds(e){return e instanceof u?e:e instanceof ye?e.period:e instanceof y?new u(e):["number","bigint"].includes(typeof e)?u.milliseconds(e):new u(e)}valueOf(){return this.value}lessThan(e){return this.valueOf()<new u(e).valueOf()}greaterThan(e){return this.valueOf()>new u(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new u(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new u(e).valueOf()}remainder(e){return Ee(this,e)}truncate(e){return new u(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(u.DAY),t=this.truncate(u.HOUR),r=this.truncate(u.MINUTE),i=this.truncate(u.SECOND),o=this.truncate(u.MILLISECOND),l=this.truncate(u.MICROSECOND),d=this.truncate(u.NANOSECOND),f=e,g=t.sub(e),m=r.sub(t),h=i.sub(r),v=o.sub(i),w=l.sub(o),F=d.sub(l);let z="";return f.isZero||(z+=`${f.days}d `),g.isZero||(z+=`${g.hours}h `),m.isZero||(z+=`${m.minutes}m `),h.isZero||(z+=`${h.seconds}s `),v.isZero||(z+=`${v.milliseconds}ms `),w.isZero||(z+=`${w.microseconds}µs `),F.isZero||(z+=`${F.nanoseconds}ns`),z.trim()}mult(e){return new u(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(u.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(u.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(u.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(u.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(u.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(u.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new u(e).valueOf()}add(e){return new u(this.valueOf()+new u(e).valueOf())}sub(e){return new u(this.valueOf()-new u(e).valueOf())}static nanoseconds(e=1){return new u(e)}static NANOSECOND=u.nanoseconds(1);static microseconds(e=1){return u.nanoseconds(B(e,1e3))}static MICROSECOND=u.microseconds(1);static milliseconds(e=1){return u.microseconds(B(e,1e3))}static MILLISECOND=u.milliseconds(1);static seconds(e=1){return u.milliseconds(B(e,1e3))}static SECOND=u.seconds(1);static minutes(e=1){return u.seconds(B(e,60))}static MINUTE=u.minutes(1);static hours(e){return u.minutes(B(e,60))}static HOUR=u.hours(1);static days(e){return u.hours(B(e,24))}static DAY=u.days(1);static MAX=new u((1n<<63n)-1n);static MIN=new u(0);static ZERO=new u(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new u(e.value)),s.z.string().transform(e=>new u(BigInt(e))),s.z.number().transform(e=>new u(e)),s.z.instanceof(u)])}let ye=class R extends P{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new R(e).valueOf()}get period(){return u.seconds(1/this.valueOf())}sampleCount(e){return new u(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new T(t).valueOf()}span(e){return u.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new R(e)}static khz(e){return R.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new R(e)),s.z.instanceof(R)])},T=class N extends P{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new p(e*this.valueOf())}static UNKNOWN=new N(0);static BIT128=new N(16);static BIT64=new N(8);static BIT32=new N(4);static BIT16=new N(2);static BIT8=new N(1);static z=s.z.union([s.z.number().transform(e=>new N(e)),s.z.instanceof(N)])};class O{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new y(e.start),this.end=new y(e.end)):(this.start=new y(e),this.end=new y(t))}get span(){return new u(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 O(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=u.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=u.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=y.max(r.start,e.start),o=y.min(r.end,e.end);return o.before(i)?!1:new u(o.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof O?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new O(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 O(y.min(...e.map(t=>t.start)),y.max(...e.map(t=>t.end)))}static MAX=new O(y.MIN,y.MAX);static MIN=new O(y.MAX,y.MIN);static ZERO=new O(y.ZERO,y.ZERO);static z=s.z.union([s.z.object({start:y.z,end:y.z}).transform(e=>new O(e.start,e.end)),s.z.instanceof(O)]);static sort(e,t){return y.sort(e.start,t.start)||y.sort(e.end,t.end)}}class a extends P{constructor(e){if(e instanceof a||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=a.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=a.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(a.JSON)||this.equals(a.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(a.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=a.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(a.UINT8)||this.equals(a.UINT16)||this.equals(a.UINT32)||this.equals(a.UINT64)}get isSignedInteger(){return this.equals(a.INT8)||this.equals(a.INT16)||this.equals(a.INT32)||this.equals(a.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(a.INT32)&&e.equals(a.FLOAT64)||this.equals(a.INT8)&&e.equals(a.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 a.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new a("unknown");static FLOAT64=new a("float64");static FLOAT32=new a("float32");static INT64=new a("int64");static INT32=new a("int32");static INT16=new a("int16");static INT8=new a("int8");static UINT64=new a("uint64");static UINT32=new a("uint32");static UINT16=new a("uint16");static UINT8=new a("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new a("timestamp");static UUID=new a("uuid");static STRING=new a("string");static JSON=new a("json");static ARRAY_CONSTRUCTORS=new Map([[a.UINT8.toString(),Uint8Array],[a.UINT16.toString(),Uint16Array],[a.UINT32.toString(),Uint32Array],[a.UINT64.toString(),BigUint64Array],[a.FLOAT32.toString(),Float32Array],[a.FLOAT64.toString(),Float64Array],[a.INT8.toString(),Int8Array],[a.INT16.toString(),Int16Array],[a.INT32.toString(),Int32Array],[a.INT64.toString(),BigInt64Array],[a.TIMESTAMP.toString(),BigInt64Array],[a.STRING.toString(),Uint8Array],[a.JSON.toString(),Uint8Array],[a.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,a.UINT8],[Uint16Array.name,a.UINT16],[Uint32Array.name,a.UINT32],[BigUint64Array.name,a.UINT64],[Float32Array.name,a.FLOAT32],[Float64Array.name,a.FLOAT64],[Int8Array.name,a.INT8],[Int16Array.name,a.INT16],[Int32Array.name,a.INT32],[BigInt64Array.name,a.INT64]]);static DENSITIES=new Map([[a.UINT8.toString(),T.BIT8],[a.UINT16.toString(),T.BIT16],[a.UINT32.toString(),T.BIT32],[a.UINT64.toString(),T.BIT64],[a.FLOAT32.toString(),T.BIT32],[a.FLOAT64.toString(),T.BIT64],[a.INT8.toString(),T.BIT8],[a.INT16.toString(),T.BIT16],[a.INT32.toString(),T.BIT32],[a.INT64.toString(),T.BIT64],[a.TIMESTAMP.toString(),T.BIT64],[a.STRING.toString(),T.UNKNOWN],[a.JSON.toString(),T.UNKNOWN],[a.UUID.toString(),T.BIT128]]);static ALL=[a.UNKNOWN,a.FLOAT64,a.FLOAT32,a.INT64,a.INT32,a.INT16,a.INT8,a.UINT64,a.UINT32,a.UINT16,a.UINT8,a.TIMESTAMP,a.UUID,a.STRING,a.JSON];static BIG_INT_TYPES=[a.INT64,a.UINT64,a.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new a(e)),s.z.instanceof(a)])}class p extends P{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return p.bytes(this.valueOf()+e.valueOf())}sub(e){return p.bytes(this.valueOf()-e.valueOf())}truncate(e){return new p(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return p.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/p.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/p.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/p.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/p.TERABYTE.valueOf()}toString(){const e=this.truncate(p.TERABYTE),t=this.truncate(p.GIGABYTE),r=this.truncate(p.MEGABYTE),i=this.truncate(p.KILOBYTE),o=this.truncate(p.BYTE),l=e,d=t.sub(e),f=r.sub(t),g=i.sub(r),m=o.sub(i);let h="";return l.isZero||(h+=`${l.terabytes}TB `),d.isZero||(h+=`${d.gigabytes}GB `),f.isZero||(h+=`${f.megabytes}MB `),g.isZero||(h+=`${g.kilobytes}KB `),(!m.isZero||h==="")&&(h+=`${m.valueOf()}B`),h.trim()}static bytes(e=1){return new p(e)}static BYTE=new p(1);static kilobytes(e=1){return p.bytes(e.valueOf()*1e3)}static KILOBYTE=p.kilobytes(1);static megabytes(e=1){return p.kilobytes(e.valueOf()*1e3)}static MEGABYTE=p.megabytes(1);static gigabytes(e=1){return p.megabytes(e.valueOf()*1e3)}static GIGABYTE=p.gigabytes(1);static terabytes(e){return p.gigabytes(e.valueOf()*1e3)}static TERABYTE=p.terabytes(1);static ZERO=new p(0);static z=s.z.union([s.z.number().transform(e=>new p(e)),s.z.instanceof(p)]);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 Ae=n=>{const e=typeof n;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||n instanceof y||n instanceof u||n instanceof Date},Ut=(n,e,t,r=0)=>n.usesBigInt&&!e.usesBigInt?Number(t)-Number(r):!n.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(r.valueOf()):V(t,-r),V=(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),Ct=/^(?:[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 Mt(n){return typeof n=="string"&&Ct.test(n)}const b=[];for(let n=0;n<256;++n)b.push((n+256).toString(16).slice(1));function Bt(n,e=0){return(b[n[e+0]]+b[n[e+1]]+b[n[e+2]]+b[n[e+3]]+"-"+b[n[e+4]]+b[n[e+5]]+"-"+b[n[e+6]]+b[n[e+7]]+"-"+b[n[e+8]]+b[n[e+9]]+"-"+b[n[e+10]]+b[n[e+11]]+b[n[e+12]]+b[n[e+13]]+b[n[e+14]]+b[n[e+15]]).toLowerCase()}function $t(n,e=0){const t=Bt(n,e);if(!Mt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ue=(n,e)=>$t(n,e),x=-1,Rt=s.z.string().transform(n=>new Uint8Array(atob(n).split("").map(e=>e.charCodeAt(0))).buffer),Dt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),te=10,Lt=(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`)},Ce="sy_x_telem_series";class S{key;discriminator=Ce;dataType;sampleOffset;gl;_data;timeRange=O.ZERO;alignment=0n;cachedMin;cachedMax;writePos=x;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:O.z.optional(),dataType:a.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Rt,Dt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Et.optional().default("static").optional()});static z=S.crudeZ.transform(e=>new S(e));constructor(e){Pt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:r,sampleOffset:i=0,glBufferUsage:o="static",alignment:l=0n,key:d=zt(),data:f}=e;if(kt(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.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const g=Ae(f),m=Array.isArray(f);if(t!=null)this.dataType=new a(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(m||g){let h=f;if(!g){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=a.STRING;else if(typeof h=="number")this.dataType=a.FLOAT64;else if(typeof h=="bigint")this.dataType=a.INT64;else if(typeof h=="boolean")this.dataType=a.BOOLEAN;else if(h instanceof y||h instanceof Date||h instanceof y)this.dataType=a.TIMESTAMP;else if(typeof h=="object")this.dataType=a.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new a(f)}if(!m&&!g)this._data=f;else if(m&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=g?[f]:f;const v=h[0];(v instanceof y||v instanceof Date||v instanceof u)&&(h=h.map(w=>new y(w).valueOf())),this.dataType.equals(a.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"),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(`
2
2
  `)}
3
- `).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(w=>ee.encodeString(w)).join(`
3
+ `).buffer):this.dataType.equals(w.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(z=>ae.encodeString(z)).join(`
4
4
  `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(h.map(w=>BigInt(Math.round(w)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=d,this.alignment=l,this.sampleOffset=i??0,this.timeRange=r??O.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:o}}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 a(t).Array(e),o=new S({data:i.buffer,dataType:t,...r});return o.writePos=0,o}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===x)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===x)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===x?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(a.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ee.decodeString(t)))}get byteCapacity(){return new p(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===x?this.byteCapacity:this.dataType.isVariable?new p(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===x?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===te&&(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]=Ut(this.dataType,e,this.data[i],t);return new S({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(a.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(),V(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(a.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(),V(this.cachedMin,this.sampleOffset))}get bounds(){return A(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);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(a.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 V(r,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const r=Ue(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 l=0;l<this.data.length;l++)if(this.data[l]===te){if(e===0){i=l;break}r=l+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 o=this.data.slice(r,i);return this.dataType.equals(a.STRING)?new TextDecoder().decode(o):Te(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,r=this.length-1;const i=Je(e);for(;t<=r;){const o=Math.floor((t+r)/2),l=i(this.at(o,!0),e);if(l===0)return o;l<0?t=o+1:r=o-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(a.FLOAT32)&&!this.dataType.equals(a.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!==x){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const o=this.dataType.density.size(i).valueOf(),l=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,o,l.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=x}as(e){return Lt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:we(this.alignmentBounds.lower),upper:we(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return A(this.alignment,this.alignment+BigInt(this.length))}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(a.JSON)?new ie(e):e}return this.dataType.equals(a.UUID)?new Yt(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 me(this,e,t??this.length)}subAlignmentIterator(e,t){return new me(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,t);return new S({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 S({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new S({data:this.buffer,dataType:this.dataType,timeRange:O.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 Pt=n=>n==null?!1:Array.isArray(n)||n instanceof ArrayBuffer||ArrayBuffer.isView(n)&&!(n instanceof DataView)||n instanceof S?!0:Ae(n),kt=xt(Ce,S);let me=class{series;end;index;constructor(e,t,r){this.series=e;const i=A(0,e.length);this.end=fe(i,r),this.index=fe(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},jt=class{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]!==te;)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))})}};class ie{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:ee.decodeString(e.value,ie.schema)}}}class Yt{series;index;data;density;constructor(e){if(!e.dataType.equals(a.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=a.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ue(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class qt{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 we=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 Ft=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Ft();const Wt=["macOS","Windows","Linux"],Zt=["macos","windows","linux"],Vt={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(Wt).or(s.z.enum(Zt).transform(n=>Vt[n]));const Gt=(...n)=>n.map(Me).join(""),Me=n=>(n.endsWith("/")||(n+="/"),n.startsWith("/")&&(n=n.slice(1)),n),Jt=n=>n.endsWith("/")?n.slice(0,-1):n,Ht=(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 j{protocol;host;port;path;constructor({host:e,port:t,protocol:r="",pathPrefix:i=""}){this.protocol=r,this.host=e,this.port=t,this.path=Me(i)}replace(e){return new j({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new j({...this,pathPrefix:Gt(this.path,e)})}toString(){return Jt(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new j({host:"unknown",port:0})}const Xt=async n=>await new Promise(e=>setTimeout(e,u.fromMilliseconds(n).milliseconds));class Kt{config;retries;interval;constructor(e){this.config={baseInterval:new u(e?.baseInterval??u.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Xt},this.retries=0,this.interval=new u(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)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Qt=s.z.object({baseInterval:u.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),_t=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Kt,breakerConfigZ:Qt},Symbol.toStringTag,{value:"Module"})),en=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Be=s.z.string().regex(en),L=s.z.number().min(0).max(255),$e=s.z.number().min(0).max(1),Re=s.z.tuple([L,L,L,$e]),tn=s.z.tuple([L,L,L]),nn=s.z.object({rgba255:Re}),rn=s.z.number().min(0).max(360),sn=s.z.number().min(0).max(100),an=s.z.number().min(0).max(100),on=s.z.tuple([rn,sn,an,$e]),ae=s.z.union([Be,tn,Re,on,nn]),un=ae.transform(n=>oe(n)),oe=(n,e=1)=>{if(n=ae.parse(n),typeof n=="string")return cn(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},cn=(n,e=1)=>(n=Be.parse(n),n=ln(n),[Z(n,0),Z(n,2),Z(n,4),n.length===8?Z(n,6)/255:e]),Z=(n,e)=>parseInt(n.slice(e,e+2),16),ln=n=>n.startsWith("#")?n.slice(1):n;oe("#000000");oe("#ffffff");const hn=s.z.object({key:s.z.string(),color:ae,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(hn);const fn=s.z.object({key:s.z.string(),name:s.z.string(),color:un});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(fn)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const dn=n=>Object.getOwnPropertySymbols(globalThis).includes(n),gn=(n,e)=>{const t=Symbol.for(n);if(!dn(t)){const r=e();Object.defineProperty(globalThis,t,{value:r})}return()=>globalThis[t]},De="sy_x_error",pn=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),Y=n=>class k extends Error{static discriminator=De;discriminator=k.discriminator;static TYPE=n;type=k.TYPE;static matches=pn(n);matches=k.matches;constructor(t,r){super(t,r),this.name=k.TYPE}static sub(t){return Y(`${n}.${t}`)}},Le=n=>{if(n==null||typeof n!="object")return!1;const e=n;if(e.discriminator!==De)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},D="unknown",ne="nil";class yn{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ne,data:""};if(Le(e))for(const t of this.providers){const r=t.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:D,data:e.message};if(typeof e=="string")return{type:D,data:e};try{return{type:D,data:JSON.stringify(e)}}catch{return{type:D,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ne)return null;if(e.type===D)return new re(e.data);for(const t of this.providers){const r=t.decode(e);if(r!=null)return r}return new re(e.data)}}const ue=gn("synnax-error-registry",()=>new yn),mn=({encode:n,decode:e})=>ue().register({encode:n,decode:e}),wn=n=>ue().encode(n),bn=n=>n==null?null:ue().decode(n);class re extends Y("unknown"){}const Tn=s.z.object({type:s.z.string(),data:s.z.string()});class On extends Y("canceled"){}class vn extends Y("not_implemented"){}const E=Object.freeze(Object.defineProperty({__proto__:null,Canceled:On,NONE:ne,NotImplemented:vn,UNKNOWN:D,Unknown:re,createTyped:Y,decode:bn,encode:wn,isTyped:Le,payloadZ:Tn,register:mn},Symbol.toStringTag,{value:"Module"})),In=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Pe=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Sn=Pe.extend({result:s.json()}),Nn=Pe.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),zn=s.union([Sn,Nn]);s.union([In,zn]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const xn=["standard","scientific","engineering"];s.z.enum(xn);s.z.enum(["success","info","warning","error","loading","disabled"]);class q extends E.createTyped("freighter"){}class U extends q.sub("eof"){constructor(){super("EOF")}}class C extends q.sub("stream_closed"){constructor(){super("StreamClosed")}}class M extends q.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:r=j.UNKNOWN}=e;super(t),this.url=r}}const En=n=>{if(!n.type.startsWith(q.TYPE))return null;if(U.matches(n))return{type:U.TYPE,data:"EOF"};if(C.matches(n))return{type:C.TYPE,data:"StreamClosed"};if(M.matches(n))return{type:M.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${n.type}: ${n.message}`)},An=n=>{if(!n.type.startsWith(q.TYPE))return null;switch(n.type){case U.TYPE:return new U;case C.TYPE:return new C;case M.TYPE:return new M;default:throw new E.Unknown(`Unknown error type: ${n.data}`)}};E.register({encode:En,decode:An});class ke{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let r=0;const i=async o=>{if(r===this.middleware.length)return await t(o);const l=this.middleware[r];return r++,await l(o,i)};return await i(e)}}const je="Content-Type",Un=n=>typeof n.cause=="object"&&n.cause!==null&&"code"in n.cause&&n.cause.code==="ECONNREFUSED",Cn=400;class Mn extends ke{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,o,l)=>o==="endpoint"?this.endpoint:Reflect.get(i,o,l)})}get headers(){return{[je]:this.encoder.contentType}}async send(e,t,r,i){t=r?.parse(t);let o=null;const l=this.endpoint.child(e),d={};d.method="POST",d.body=this.encoder.encode(t??{});const[,f]=await this.executeMiddleware({target:l.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async g=>{const m={...g,params:{}};d.headers={...this.headers,...g.params};let h;try{h=await fetch(g.target,d)}catch(w){if(!(w instanceof Error))throw w;return[m,Un(w)?new M({url:l}):w]}const v=await h.arrayBuffer();if(h?.ok)return i!=null&&(o=this.encoder.decode(v,i)),[m,null];try{if(h.status!==Cn)return[m,new Error(h.statusText)];const w=this.encoder.decode(v,E.payloadZ),F=E.decode(w);return[m,F]}catch(w){return[m,new Error(`[freighter] - failed to decode error: ${h.statusText}: ${w.message}`)]}});if(f!=null)return[null,f];if(o==null)throw new Error("Response must be defined");return[o,null]}}const Bn=(n,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,o,l,d){const f=new _t.Breaker(e);do{const[g,m]=await this.wrapped.send(i,o,l,d);if(m==null)return[g,null];if(!M.matches(m))return[null,m];if(!await f.wait())return[g,m]}while(!0)}}return new t(n)},$n=async(n,e,t,r,i)=>{const[o,l]=await n.send(e,t,r,i);if(l!=null)throw l;return o},Rn=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(E.payloadZ)});class Dn{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 E.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new U;if(this.sendClosed)throw new C;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=E.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,Rn))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Pn?U.TYPE:C.TYPE,data:""}})}}const Ln="freighterctx",Pn=1e3;class J extends ke{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 J(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,r){let i;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async l=>{const d=new WebSocket(this.buildURL(e,l)),f={...l,params:{}};d.binaryType=J.MESSAGE_TYPE;const g=await this.wrapSocket(d,t,r);return g instanceof Error?[f,g]:(i=g,[f,null])});if(o!=null)throw o;return i}buildURL(e,t){const r=Ht({[je]:this.encoder.contentType,...t.params},Ln);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,t,r){return await new Promise(i=>{e.onopen=()=>{const o=new Dn(e,this.encoder,t,r);o.receiveOpenAck().then(l=>{l!=null?i(l):i(o)}).catch(l=>i(l))},e.onerror=o=>{const l=o;i(new Error(l.message))}})}}exports.EOF=U;exports.HTTPClient=Mn;exports.StreamClosed=C;exports.Unreachable=M;exports.WebSocketClient=J;exports.sendRequired=$n;exports.unaryWithBreaker=Bn;
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;