@synnaxlabs/pluto 0.25.1 → 0.26.0

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.
Files changed (69) hide show
  1. package/README.md +4 -3
  2. package/dist/{Animated-DLex_hI8.js → Animated-DNVDjbp5.js} +1 -1
  3. package/dist/{Animated-B5JgnUUd.cjs → Animated-zwHonFIj.cjs} +1 -1
  4. package/dist/{Keyboard-cRnR69tU.cjs → Keyboard-CK96wQ5G.cjs} +1 -1
  5. package/dist/{Keyboard-Dq4czdJl.js → Keyboard-DIqjeZSO.js} +1 -1
  6. package/dist/{LinePlot-Co1s_Tqs.cjs → LinePlot-Cm6T-Agy.cjs} +7 -7
  7. package/dist/{LinePlot-CQD2Wqca.js → LinePlot-Cvi3y24D.js} +1 -1
  8. package/dist/{Link-BhQ-K5io.cjs → Link-CRvZcIvR.cjs} +1 -1
  9. package/dist/{Link-0lZQ38cR.js → Link-CfU1takx.js} +1 -1
  10. package/dist/{List-xUwGRWFg.js → List-B6hlZNwe.js} +2 -2
  11. package/dist/{List-lSysLR6L.cjs → List-CBMm9BLf.cjs} +1 -1
  12. package/dist/{Toggle-BKoV45C3.cjs → Toggle-YiHP9pVf.cjs} +1 -1
  13. package/dist/{Toggle-BYLe2YvN.js → Toggle-_SGawcap.js} +1 -1
  14. package/dist/aggregator-D9ExX_tt.cjs +51 -0
  15. package/dist/{aggregator-ZdqEkvBK.js → aggregator-DaNTqAB0.js} +2333 -2272
  16. package/dist/button.cjs +1 -1
  17. package/dist/button.js +1 -1
  18. package/dist/color.cjs +1 -1
  19. package/dist/color.js +1 -1
  20. package/dist/dropdown.cjs +1 -1
  21. package/dist/dropdown.js +1 -1
  22. package/dist/ether.cjs +1 -1
  23. package/dist/ether.js +4 -4
  24. package/dist/{external-C5O8yyPx.cjs → external-9st6X3mL.cjs} +1 -1
  25. package/dist/{external-Gp6DgYYV.cjs → external-BgW4t-2y.cjs} +1 -1
  26. package/dist/{external-BlA8AVL_.js → external-BxUqbUsk.js} +3 -3
  27. package/dist/{external-CCaVfdMh.js → external-C4w_40JS.js} +2 -2
  28. package/dist/{external-CZ4JWSju.js → external-C86d--c3.js} +2 -2
  29. package/dist/{external-ARvsEsOz.cjs → external-CE4wgFJ7.cjs} +1 -1
  30. package/dist/{external--9Vu3Tvu.js → external-CJOE_TDI.js} +2 -2
  31. package/dist/{external-D8t2fJPR.js → external-CS2UIUPR.js} +3 -3
  32. package/dist/{external-Cq39ap_s.cjs → external-ChI4-3Am.cjs} +1 -1
  33. package/dist/{external-DluodP6q.js → external-ChYLNmOM.js} +2 -2
  34. package/dist/{external-xb_RKgNH.cjs → external-Cja9j84T.cjs} +1 -1
  35. package/dist/{external-Cq-09sZJ.js → external-CsAw5Bqm.js} +5 -5
  36. package/dist/{external-D3r8Iptl.js → external-D23hMpey.js} +2 -2
  37. package/dist/{external-aHhj9dKH.cjs → external-DG3L9UDo.cjs} +1 -1
  38. package/dist/{external-DauKaEP3.cjs → external-DOZ21f-5.cjs} +1 -1
  39. package/dist/{external-Bs4ZUlV0.cjs → external-DSc2y4PB.cjs} +1 -1
  40. package/dist/{external-CYaPBMuM.cjs → external-DZohHxSv.cjs} +1 -1
  41. package/dist/{external-CZvU-o3e.js → external-D_dAdIZX.js} +2 -2
  42. package/dist/{external-B432ukHJ.js → external-DfwQACwH.js} +2 -2
  43. package/dist/{external-xFWuaTdI.js → external-TgztmPvP.js} +5 -5
  44. package/dist/{external-BQS9le5M.cjs → external-r0ozQhkY.cjs} +1 -1
  45. package/dist/{external-wfqDajHH.cjs → external-rzy59VM1.cjs} +1 -1
  46. package/dist/header.cjs +1 -1
  47. package/dist/header.js +1 -1
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.js +25 -25
  50. package/dist/input.cjs +1 -1
  51. package/dist/input.js +1 -1
  52. package/dist/list.cjs +1 -1
  53. package/dist/list.js +1 -1
  54. package/dist/menu.cjs +1 -1
  55. package/dist/menu.js +1 -1
  56. package/dist/src/hardware/device/Select.d.ts.map +1 -1
  57. package/dist/src/vis/diagram/edge/Edge.d.ts.map +1 -1
  58. package/dist/tabs.cjs +1 -1
  59. package/dist/tabs.js +1 -1
  60. package/dist/text.cjs +1 -1
  61. package/dist/text.js +2 -2
  62. package/dist/theming.cjs +1 -1
  63. package/dist/theming.js +2 -2
  64. package/dist/tree.cjs +1 -1
  65. package/dist/tree.js +1 -1
  66. package/dist/triggers.cjs +1 -1
  67. package/dist/triggers.js +1 -1
  68. package/package.json +5 -5
  69. package/dist/aggregator-BjcY2k2l.cjs +0 -51
@@ -1,51 +0,0 @@
1
- "use strict";var Go=Object.defineProperty;var Zo=(t,e,r)=>e in t?Go(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var D=(t,e,r)=>Zo(t,typeof e!="symbol"?e+"":e,r);const s=require("zod"),O=require("./css-DY1Oedjj.cjs"),_n=require("react");var Vo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ko(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Jo(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var r=function n(){return this instanceof n?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}),r}const bt=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var Ho=Object.defineProperty,Xo=(t,e,r)=>e in t?Ho(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vt=(t,e,r)=>Xo(t,typeof e!="symbol"?e+"":e,r);let Qo=class{constructor(){vt(this,"contentType","application/json"),vt(this,"decoder"),vt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),i=O.T(n);return r!=null?r.parse(i):i}encodeString(e){const r=O.C(e);return JSON.stringify(r,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):bt(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},ec=class{constructor(){vt(this,"contentType","text/csv")}encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r).buffer}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!bt(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(i=>{const a=r.map(o=>JSON.stringify(i[o]??""));n.push(a.join(","))}),n.join(`
2
- `)}decodeString(e,r){const[n,...i]=e.trim().split(`
3
- `).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(d=>d.trim());a.forEach((d,f)=>{const h=this.parseValue(u[f]);h!=null&&o[d].push(h)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}static registerCustomType(){}},tc=class{constructor(){vt(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};const Xt=new Qo;new ec;new tc;const pi=t=>t!=null&&typeof t=="object"&&"toString"in t,rc=t=>{if(pi(t))return(t==null?void 0:t.toString().length)===0;switch(typeof t){case"string":return t.length===0;case"number":return t===0;case"bigint":return t===0n;case"boolean":return!t;case"undefined":return!0;case"object":return t===null}},Dr=(t,e=!1)=>{const r=pi(t)?"stringer":typeof t;let n;switch(r){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 ${r}`),()=>-1}return e?mi(n):n},nc=(t,e,r)=>{const n=Dr(e[t],r);return(i,a)=>n(i[t],a[t])},sc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,ic=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const r=Dr(t[0]),n=[...t].sort(r),i=[...e].sort(r);return n.every((a,o)=>a===i[o])?0:-1},ac=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,mi=t=>(e,r)=>t(r,e),oc=t=>t<0,cc=t=>t>0,lc=t=>t>=0,uc=(t,e)=>{const r=/([a-zA-Z]+)|(\d+)/g,n=t.replace(/[\s_.-]+/g,"").match(r),i=e.replace(/[\s_.-]+/g,"").match(r);if(!n||!i)return 0;for(let a=0;a<Math.min(n.length,i.length);a++){const o=n[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},hc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:0,GREATER_THAN:1,LESS_THAN:-1,isGreaterThan:cc,isGreaterThanEqual:lc,isLessThan:oc,newF:Dr,newFieldF:nc,order:ac,primitiveArrays:sc,reverseF:mi,stringsWithNumbers:uc,unorderedPrimitiveArrays:ic},Symbol.toStringTag,{value:"Module"})),dc=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},fc=(t,e)=>{let r=null;return e===0?t:(...n)=>{r===null&&(r=setTimeout(()=>{t(...n),r=null},e))}},wi=(t,e)=>{const r=t.split(".");return r.map((n,i)=>{const a=e(n,i,r);return a==null?null:typeof a=="string"?a:a.join(".")}).filter(n=>n!=null).join(".")},Wn=(t,e,r={optional:!1})=>{const{optional:n,getter:i=(c,u)=>c[u]}=r,a=e.split(".");if(a.length===1&&a[0]==="")return t;let o=t;for(const c of a){const u=i(o,c);if(u==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o},yc=(t,e,r)=>{const n=e.split(".");let i=t;for(let a=0;a<n.length-1;a++){const o=n[a];if(i[o]==null)throw new Error(`Path ${e} does not exist`);i=i[o]}i[n[n.length-1]]=r},gc=(t,e)=>{const r=t.split(".");return e<0?r[r.length+e]:r[e]},pc=t=>t.join("."),mc=(t,e)=>{try{return Wn(t,e),!0}catch{return!1}},wc=(t,e)=>{if(e.length===0)return!0;const r=t.split("."),n=e.split(".");if(n.length>r.length)return!1;for(let i=0;i<n.length;i++){const a=r[i],o=n[i];if(o!=="*"&&a!==o)return!1}return!0},bc=t=>JSON.parse(JSON.stringify(t)),vc=(t,...e)=>(e.forEach(r=>{let n=t;const i=r.split(".");i.forEach((a,o)=>{o===i.length-1?delete n[a]:a in n&&(n=n[a])})}),t),Oc=(t,e,r="")=>{const n={},i=(a,o,c)=>{if(typeof a!=typeof o||a===null||o===null){n[c]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){n[c]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${c}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],c!==""?`${c}.${u}`:u)});else a!==o&&(n[c]=[a,o])};return i(t,e,r),n},vn=(t,e)=>{const r=Array.isArray(t),n=Array.isArray(e);if(r!==n)return!1;if(r&&n){const o=t,c=e;if(o.length!==c.length)return!1;for(let u=0;u<o.length;u++)if(!vn(o[u],c[u]))return!1;return!0}if(t==null||e==null||typeof t!="object"||typeof e!="object")return t===e;if("equals"in t)return t.equals(e);const i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(const o of i){const c=t[o],u=e[o];if(typeof c=="object"&&typeof u=="object"){if(!vn(c,u))return!1}else if(c!==u)return!1}return!0},bi=(t,e)=>{if(typeof t!="object"||t==null)return t===e;const r=Object.keys(t),n=Object.keys(e);if(n.length>r.length)return!1;for(const i of n){const a=t[i],o=e[i];if(typeof a=="object"&&typeof o=="object"){if(!bi(a,o))return!1}else if(a!==o)return!1}return!0},On=(t,...e)=>{if(e.length===0)return t;const r=e.shift();if(bt(t)&&bt(r))for(const n in r)try{bt(r[n])?(n in t||Object.assign(t,{[n]:{}}),On(t[n],r[n])):Object.assign(t,{[n]:r[n]})}catch(i){throw i instanceof TypeError?new TypeError(`.${n}: ${i.message}`):i}return On(t,...e)},Tc=(t,e,r)=>{const n=(i,a,o)=>{for(const c in a){const u=a[c];if(o!=null&&o.shape[c]){const d=o.shape[c].safeParse(u);d.success&&(i[c]=d.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[c]&&(i[c]||(i[c]={}),n(i[c],u,o.shape[c]))}return i};return n({...t},e,r)},vi=Object.freeze(Object.defineProperty({__proto__:null,copy:bc,deleteD:vc,difference:Oc,element:gc,equal:vn,get:Wn,has:mc,join:pc,override:On,overrideValidItems:Tc,partialEqual:bi,pathsMatch:wc,set:yc,transformPath:wi},Symbol.toStringTag,{value:"Module"}));var Sc=Object.defineProperty,zc=(t,e,r)=>e in t?Sc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,m=(t,e,r)=>zc(t,typeof e!="symbol"?e+"":e,r);let Nc=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const Ec="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Oi=Nc(Ec,11),Ic=Object.freeze(Object.defineProperty({__proto__:null,id:Oi},Symbol.toStringTag,{value:"Module"})),Ti=(t,e)=>{const r=new F(e);if(![W.DAY,W.HOUR,W.MINUTE,W.SECOND,W.MILLISECOND,W.MICROSECOND,W.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof F?new F(n):new W(n)},P=class T{constructor(e,r="UTC"){if(m(this,"value"),m(this,"encodeValue",!0),e==null)this.value=T.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*T.MILLISECOND.valueOf();else if(typeof e=="string")this.value=T.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=T.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=T.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=T.MAX:e=T.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new T(BigInt(i.getTime())*T.MILLISECOND.valueOf()).truncate(T.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=T.hours(parseInt(n??"00",10)).add(T.minutes(parseInt(i??"00",10))).add(T.seconds(parseInt(o??"00",10))).add(T.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(T.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return T.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new T(BigInt(n.getTime())*T.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(T.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new W(BigInt(new Date().getTimezoneOffset())*T.MINUTE.valueOf())}static since(e){return new T().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new T(e).valueOf()}span(e){return this.range(e).span}range(e){return new Et(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new T(e).valueOf()}afterEq(e){return this.valueOf()>=new T(e).valueOf()}before(e){return this.valueOf()<new T(e).valueOf()}beforeEq(e){return this.valueOf()<=new T(e).valueOf()}add(e){return new T(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new T(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(T.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ti(this,e)}get isToday(){return this.truncate(W.DAY).equals(T.now().truncate(W.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new T(new Date)}static max(...e){let r=T.MIN;for(const n of e){const i=new T(n);i.after(r)&&(r=i)}return r}static min(...e){let r=T.MAX;for(const n of e){const i=new T(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new T(e)}static microseconds(e){return T.nanoseconds(e*1e3)}static milliseconds(e){return T.microseconds(e*1e3)}static seconds(e){return T.milliseconds(e*1e3)}static minutes(e){return T.seconds(e*60)}static hours(e){return T.minutes(e*60)}static days(e){return T.hours(e*24)}};m(P,"NANOSECOND",P.nanoseconds(1)),m(P,"MICROSECOND",P.microseconds(1)),m(P,"MILLISECOND",P.milliseconds(1)),m(P,"SECOND",P.seconds(1)),m(P,"MINUTE",P.minutes(1)),m(P,"HOUR",P.hours(1)),m(P,"DAY",P.days(1)),m(P,"MAX",new P((1n<<63n)-1n)),m(P,"MIN",new P(0)),m(P,"ZERO",new P(0)),m(P,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new P(t.value)),s.z.string().transform(t=>new P(BigInt(t))),s.z.instanceof(Number).transform(t=>new P(t)),s.z.number().transform(t=>new P(t)),s.z.instanceof(P)]));let F=P;const B=class k{constructor(e){m(this,"value"),m(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new k(e).valueOf()}greaterThan(e){return this.valueOf()>new k(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new k(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new k(e).valueOf()}remainder(e){return Ti(this,e)}truncate(e){return new k(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(k.DAY),r=this.truncate(k.HOUR),n=this.truncate(k.MINUTE),i=this.truncate(k.SECOND),a=this.truncate(k.MILLISECOND),o=this.truncate(k.MICROSECOND),c=this.truncate(k.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),M=a.sub(i),_=o.sub(a),re=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),M.isZero||(R+=`${M.milliseconds}ms `),_.isZero||(R+=`${_.microseconds}µs `),re.isZero||(R+=`${re.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(k.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(k.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(k.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(k.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(k.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(k.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new k(e).valueOf()}add(e){return new k(this.valueOf()+new k(e).valueOf())}sub(e){return new k(this.valueOf()-new k(e).valueOf())}static nanoseconds(e=1){return new k(e)}static microseconds(e=1){return k.nanoseconds(e*1e3)}static milliseconds(e=1){return k.microseconds(e*1e3)}static seconds(e=1){return k.milliseconds(e*1e3)}static minutes(e){return k.seconds(e.valueOf()*60)}static hours(e){return k.minutes(e*60)}static days(e){return k.hours(e*24)}};m(B,"NANOSECOND",B.nanoseconds(1)),m(B,"MICROSECOND",B.microseconds(1)),m(B,"MILLISECOND",B.milliseconds(1)),m(B,"SECOND",B.seconds(1)),m(B,"MINUTE",B.minutes(1)),m(B,"HOUR",B.hours(1)),m(B,"DAY",B.days(1)),m(B,"MAX",new B((1n<<63n)-1n)),m(B,"MIN",new B(0)),m(B,"ZERO",new B(0)),m(B,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new B(t.value)),s.z.string().transform(t=>new B(BigInt(t))),s.z.instanceof(Number).transform(t=>new B(t)),s.z.number().transform(t=>new B(t)),s.z.instanceof(B)]));let W=B;const it=class Qt extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Qt(e).valueOf()}get period(){return W.seconds(1/this.valueOf())}sampleCount(e){return new W(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new ae(r).valueOf()}span(e){return W.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new Qt(e)}static khz(e){return Qt.hz(e*1e3)}};m(it,"z",s.z.union([s.z.number().transform(t=>new it(t)),s.z.instanceof(Number).transform(t=>new it(t)),s.z.instanceof(it)]));let Ac=it;const H=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Pr(e*this.valueOf())}};m(H,"UNKNOWN",new H(0)),m(H,"BIT128",new H(16)),m(H,"BIT64",new H(8)),m(H,"BIT32",new H(4)),m(H,"BIT16",new H(2)),m(H,"BIT8",new H(1)),m(H,"z",s.z.union([s.z.number().transform(t=>new H(t)),s.z.instanceof(Number).transform(t=>new H(t)),s.z.instanceof(H)]));let ae=H;const be=class er{constructor(e,r){m(this,"start"),m(this,"end"),typeof e=="object"&&"start"in e?(this.start=new F(e.start),this.end=new F(e.end)):(this.start=new F(e),this.end=new F(r))}get span(){return new W(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}swap(){return new er(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=W.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=F.max(n.start,e.start),a=F.min(n.end,e.end);return a.before(i)?!1:new W(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){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<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof er?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new er(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};m(be,"MAX",new be(F.MIN,F.MAX)),m(be,"MIN",new be(F.MAX,F.MIN)),m(be,"ZERO",new be(F.ZERO,F.ZERO)),m(be,"z",s.z.union([s.z.object({start:F.z,end:F.z}).transform(t=>new be(t.start,t.end)),s.z.instanceof(be)]));let Et=be;const y=class ve extends String{constructor(e){if(e instanceof ve||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=ve.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(ve.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=ve.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()}toString(){return this.valueOf()}get isVariable(){return this.equals(ve.JSON)||this.equals(ve.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(ve.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=ve.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return ve.BIG_INT_TYPES.some(e=>e.equals(this))}};m(y,"UNKNOWN",new y("unknown")),m(y,"FLOAT64",new y("float64")),m(y,"FLOAT32",new y("float32")),m(y,"INT64",new y("int64")),m(y,"INT32",new y("int32")),m(y,"INT16",new y("int16")),m(y,"INT8",new y("int8")),m(y,"UINT64",new y("uint64")),m(y,"UINT32",new y("uint32")),m(y,"UINT16",new y("uint16")),m(y,"UINT8",new y("uint8")),m(y,"BOOLEAN",y.UINT8),m(y,"TIMESTAMP",new y("timestamp")),m(y,"UUID",new y("uuid")),m(y,"STRING",new y("string")),m(y,"JSON",new y("json")),m(y,"ARRAY_CONSTRUCTORS",new Map([[y.UINT8.toString(),Uint8Array],[y.UINT16.toString(),Uint16Array],[y.UINT32.toString(),Uint32Array],[y.UINT64.toString(),BigUint64Array],[y.FLOAT32.toString(),Float32Array],[y.FLOAT64.toString(),Float64Array],[y.INT8.toString(),Int8Array],[y.INT16.toString(),Int16Array],[y.INT32.toString(),Int32Array],[y.INT64.toString(),BigInt64Array],[y.TIMESTAMP.toString(),BigInt64Array],[y.STRING.toString(),Uint8Array],[y.JSON.toString(),Uint8Array],[y.UUID.toString(),Uint8Array]])),m(y,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,y.UINT8],[Uint16Array.name,y.UINT16],[Uint32Array.name,y.UINT32],[BigUint64Array.name,y.UINT64],[Float32Array.name,y.FLOAT32],[Float64Array.name,y.FLOAT64],[Int8Array.name,y.INT8],[Int16Array.name,y.INT16],[Int32Array.name,y.INT32],[BigInt64Array.name,y.INT64]])),m(y,"DENSITIES",new Map([[y.UINT8.toString(),ae.BIT8],[y.UINT16.toString(),ae.BIT16],[y.UINT32.toString(),ae.BIT32],[y.UINT64.toString(),ae.BIT64],[y.FLOAT32.toString(),ae.BIT32],[y.FLOAT64.toString(),ae.BIT64],[y.INT8.toString(),ae.BIT8],[y.INT16.toString(),ae.BIT16],[y.INT32.toString(),ae.BIT32],[y.INT64.toString(),ae.BIT64],[y.TIMESTAMP.toString(),ae.BIT64],[y.STRING.toString(),ae.UNKNOWN],[y.JSON.toString(),ae.UNKNOWN],[y.UUID.toString(),ae.BIT128]])),m(y,"ALL",[y.UNKNOWN,y.FLOAT64,y.FLOAT32,y.INT64,y.INT32,y.INT16,y.INT8,y.UINT64,y.UINT32,y.UINT16,y.UINT8,y.TIMESTAMP,y.UUID,y.STRING,y.JSON]),m(y,"BIG_INT_TYPES",[y.INT64,y.UINT64,y.TIMESTAMP]),m(y,"z",s.z.union([s.z.string().transform(t=>new y(t)),s.z.instanceof(y)]));let j=y;const ne=class Z extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return Z.bytes(this.valueOf()+e.valueOf())}sub(e){return Z.bytes(this.valueOf()-e.valueOf())}truncate(e){return new Z(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return Z.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/Z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/Z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/Z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/Z.TERABYTE.valueOf()}toString(){const e=this.truncate(Z.TERABYTE),r=this.truncate(Z.GIGABYTE),n=this.truncate(Z.MEGABYTE),i=this.truncate(Z.KILOBYTE),a=this.truncate(Z.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new Z(e)}static kilobytes(e=1){return Z.bytes(e.valueOf()*1e3)}static megabytes(e=1){return Z.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return Z.megabytes(e.valueOf()*1e3)}static terabytes(e){return Z.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};m(ne,"BYTE",new ne(1)),m(ne,"KILOBYTE",ne.kilobytes(1)),m(ne,"MEGABYTE",ne.megabytes(1)),m(ne,"GIGABYTE",ne.gigabytes(1)),m(ne,"TERABYTE",ne.terabytes(1)),m(ne,"ZERO",new ne(0)),m(ne,"z",s.z.union([s.z.number().transform(t=>new ne(t)),s.z.instanceof(ne)]));let Pr=ne;const kc=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)]),Si=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof F||t instanceof W||t instanceof Date},xc=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):at(r,-n),Cc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof zi?!0:Si(t),Ue=-1;let zi=class Ie{constructor(e){m(this,"key",""),m(this,"isSynnaxSeries",!0),m(this,"dataType"),m(this,"sampleOffset"),m(this,"gl"),m(this,"_data"),m(this,"_timeRange"),m(this,"alignment",0n),m(this,"_cachedMin"),m(this,"_cachedMax"),m(this,"writePos",Ue),m(this,"_refCount",0),m(this,"_cachedLength"),Cc(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Oi()}=e,{data:u}=e;if(u instanceof Ie||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const h=u;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 d=Si(u),f=Array.isArray(u);if(r!=null)this.dataType=new j(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=u;if(!d){if(u.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=u[0]}if(typeof h=="string")this.dataType=j.STRING;else if(typeof h=="number")this.dataType=j.FLOAT64;else if(typeof h=="bigint")this.dataType=j.INT64;else if(typeof h=="boolean")this.dataType=j.BOOLEAN;else if(h instanceof F||h instanceof Date||h instanceof F)this.dataType=j.TIMESTAMP;else if(typeof h=="object")this.dataType=j.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new j(u)}if(!f&&!d)this._data=u;else{let h=d?[u]:u;const M=h[0];(M instanceof F||M instanceof Date||M instanceof W)&&(h=h.map(_=>new F(_).valueOf())),this.dataType.equals(j.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.join(`
4
- `)+`
5
- `)):this.dataType.equals(j.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.map(_=>Xt.encodeString(_)).join(`
6
- `)+`
7
- `)):this._data=new this.dataType.Array(h).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=n,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new j(r).Array(e),a=new Ie({data:i.buffer,dataType:r,...n});return a.writePos=0,a}static generateTimestamps(e,r,n){const i=n.spanRange(r.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(n.add(r.span(o)).valueOf());return new Ie({data:a,dataType:j.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,r){const n=new TextEncoder().encode(e.join(`
8
- `)+`
9
- `);return new Ie({data:n,dataType:j.STRING,timeRange:r})}static fromJSON(e,r){const n=new TextEncoder().encode(e.map(i=>Xt.encodeString(i)).join(`
10
- `)+`
11
- `);return new Ie({data:n,dataType:j.JSON,timeRange:r})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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");if(this.writePos===Ue)return 0;const r=this.capacity-this.writePos,n=r<e.length?e.slice(0,r):e;return this.underlyingData.set(n.data,this.writePos),this.maybeRecomputeMinMax(n),this._cachedLength=void 0,this.writePos+=n.length,n.length}get buffer(){return this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Ue?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.equals(j.STRING))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
12
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(j.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=j.UUID.density.valueOf(),r=Array(this.length);for(let n=0;n<this.length;n++){const i=this.buffer.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");r[n]=a}return r}parseJSON(e){if(!this.dataType.equals(j.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
13
- `).slice(0,-1).map(r=>e.parse(Xt.decodeString(r)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Pr(this.buffer.byteLength)}get capacity(){return this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ue?this.byteCapacity:this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ue?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;return this.data.forEach(r=>{r===10&&e++}),this._cachedLength=e,e}convert(e,r=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]=xc(this.dataType,e,this.data[i],r);return new Ie({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),at(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),at(this._cachedMin,this.sampleOffset))}get bounds(){return O.o(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const r=e._cachedMin??e.calcRawMin();r<this._cachedMin&&(this._cachedMin=r)}if(this._cachedMax!=null){const r=e._cachedMax??e.calcRawMax();r>this._cachedMax&&(this._cachedMax=r)}}enrich(){this.max,this.min}get range(){return at(this.max,-this.min)}at(e,r){if(this.dataType.isVariable)return this.atVariable(e,r??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return at(n,this.sampleOffset)}atVariable(e,r){e<0&&(e=this.length+e);let n=0,i=0;for(let o=0;o<this.data.length;o++)if(this.data[o]===10){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}const a=this.data.slice(n,i);return this.dataType.equals(j.STRING)?new TextDecoder().decode(a):O.T(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const i=Dr(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:i}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ue){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.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=Ue}as(e){if(e==="string"){if(!this.dataType.equals(j.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(j.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return O.o(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 Rc(this);return this.dataType.equals(j.JSON)?new $c(e):e}return new jc(this)}slice(e,r){if(e<=0&&(r==null||r>=this.length))return this;const n=this.data.slice(e,r);return new Ie({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}reAlign(e){return new Ie({data:this.buffer,dataType:this.dataType,timeRange:Et.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};class Rc{constructor(e){if(m(this,"series"),m(this,"index"),m(this,"decoder"),!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,r=this.series.data;for(;this.index<r.length&&r[this.index]!==10;)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))})}[Symbol.iterator](){return this}}var vs,Os;let $c=class{constructor(e){m(this,"wrapped"),m(this,vs,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Xt.decodeString(e.value)}}[(Os=Symbol.iterator,vs=Symbol.toStringTag,Os)](){return this}};var Ts,Ss;let jc=class{constructor(e){m(this,"series"),m(this,"index"),m(this,Ts,"SeriesIterator"),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)}}[(Ss=Symbol.iterator,Ts=Symbol.toStringTag,Ss)](){return this}};const at=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);let Mc=class{constructor(e){if(m(this,"series"),e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new j(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?j.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?Et.ZERO:new Et(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,r)=>e+r.length,0)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}get byteLength(){return new Pr(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Dc(this.series)}};var zs,Ns;class Dc{constructor(e){m(this,"series"),m(this,"seriesIndex"),m(this,"internal"),m(this,zs,"MultiSeriesIterator"),this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[(Ns=Symbol.iterator,zs=Symbol.toStringTag,Ns)](){return this}}s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Ni=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Pc=Ni(),Ei=["MacOS","Windows","Linux","Docker"],Bc=s.z.enum(Ei);let Jr;const Uc=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},Lc=(t={})=>{const{force:e,default:r}=t;return e??Jr??(Jr=Uc(),Jr??r)},Ii=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Ei,RUNTIME:Pc,detect:Ni,getOS:Lc,osZ:Bc},Symbol.toStringTag,{value:"Module"})),Yc=t=>Array.isArray(t)?t:[t],qc=t=>Array.isArray(t)?t:t===null?[]:[t],Fc=t=>[...new Set(t)];var _c=Object.defineProperty,Wc=(t,e,r)=>e in t?_c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ot=(t,e,r)=>Wc(t,typeof e!="symbol"?e+"":e,r);const Gc=(...t)=>t.map(Ai).join(""),Ai=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Zc=t=>t.endsWith("/")?t.slice(0,-1):t,Es=class Tn{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){ot(this,"protocol"),ot(this,"host"),ot(this,"port"),ot(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Ai(i)}replace(e){return new Tn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Tn({...this,pathPrefix:Gc(this.path,e)})}toString(){return Zc(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};ot(Es,"UNKNOWN",new Es({host:"unknown",port:0}));var Vc=Object.defineProperty,Kc=(t,e,r)=>e in t?Vc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Er=(t,e,r)=>Kc(t,typeof e!="symbol"?e+"":e,r);let Jc=class{constructor(e){Er(this,"sender"),Er(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var r;const n=(r=this.handlers.get(e.type))==null?void 0:r.handler;n==null?console.warn(`No handler for ${e.type}`):n(e.payload)}route(e){const r=Hc(e,this.sender),n=new Xc(r);return this.handlers.set(e,n),n}};const Hc=(t,e)=>(r,n)=>e({type:t,payload:r},n);let Xc=class{constructor(e){Er(this,"_send"),Er(this,"handler"),this._send=e,this.handler=null}send(e,r=[]){this._send(e,r)}handle(e){this.handler=e}};var Qc=Object.defineProperty,el=(t,e,r)=>e in t?Qc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tr=(t,e,r)=>el(t,typeof e!="symbol"?e+"":e,r);const Ye=class extends Number{};tr(Ye,"Absolute",255),tr(Ye,"Default",1),tr(Ye,"z",s.z.union([s.z.instanceof(Ye),s.z.number().int().min(0).max(255).transform(t=>new Ye(t)),s.z.instanceof(Number).transform(t=>new Ye(t))]));let ki=Ye;const xi=s.z.object({name:s.z.string(),key:s.z.string()}),tl=t=>s.z.object({subject:xi,resource:t,authority:ki.z}),rl=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),nl=Object.freeze(Object.defineProperty({__proto__:null,Authority:ki,filterTransfersByChannelKey:rl,stateZ:tl,subjectZ:xi},Symbol.toStringTag,{value:"Module"})),Ci=class ct extends Error{constructor(){super(ct.MESSAGE)}matches(e){return typeof e=="string"?e.includes(ct.MESSAGE):e instanceof ct||e.message.includes(ct.MESSAGE)}};tr(Ci,"MESSAGE","canceled");let sl=Ci;new sl;const il=t=>t?-1:1;s.z.string().regex(/^\d+\.\d+\.\d+$/);const al=t=>{if(t===void 0||typeof t=="string"||typeof t=="number")return t;if(t.toString===void 0)throw new Error("invalid renderer");return t.toString()},ol=t=>Array.isArray(t)?[...t]:typeof t=="object"&&t!==null?{...t}:t,Gn=t=>typeof t=="function",Zn=(t,e)=>Gn(t)?t(e):t,jt=t=>Ri(t)?t():t,Ri=t=>typeof t=="function",$i=({initial:t,value:e,onChange:r})=>{const[n,i]=_n.useState(jt(e??t));return e!=null&&r!=null?[e,r]:[n,i]},ji=({initial:t,value:e,onChange:r})=>{const[n,i]=_n.useState(jt(e??t));return e!=null&&r!=null?[e,r]:[n,i]},cl=(t,e)=>{const[r,n]=_n.useState(()=>{const i=localStorage.getItem(e);return i==null?jt(t):JSON.parse(i)});return[r,i=>{n(i),localStorage.setItem(e,JSON.stringify(i))}]},ll=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:jt,executeSetter:Zn,isInitialSetter:Ri,isSetter:Gn,usePassthrough:$i,usePersisted:cl,usePurePassthrough:ji},Symbol.toStringTag,{value:"Module"})),Mi=["h1","h2","h3","h4","h5","p","small"],ul=s.z.enum(Mi),Me=s.z.object({size:s.z.number(),weight:s.z.union([s.z.number(),s.z.string()]),lineHeight:s.z.number(),textTransform:s.z.string().optional()}),Di={small:"small",medium:"p",large:"h5",huge:"h2"},hl={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let Hr=null;const dl=()=>(Hr==null&&(Hr=document.createElement("canvas")),Hr),fl=(t,e,r)=>{if(Ii.RUNTIME==="node")return{width:0,height:0};r==null&&(r=dl().getContext("2d")),r.font=e;const n=r.measureText(t);return{width:Math.trunc(Math.abs(n.actualBoundingBoxLeft)+Math.abs(n.actualBoundingBoxRight)),height:Math.trunc(Math.abs(n.actualBoundingBoxAscent)+Math.abs(n.actualBoundingBoxDescent))}},yl=s.z.object({l0:O.Color.z,l1:O.Color.z,l2:O.Color.z,l3:O.Color.z,l4:O.Color.z,l5:O.Color.z,l6:O.Color.z,l7:O.Color.z,l8:O.Color.z,l9:O.Color.z,l10:O.Color.z}),fe=(t,e)=>[t[0],t[1],e,t[3]],gl=s.z.object({m2:O.Color.z,m1:O.Color.z,z:O.Color.z,p1:O.Color.z,p2:O.Color.z}),Ft=gl.or(O.Color.z.transform(t=>{const e=t.hsla;return{m2:new O.Color(O.fromHSLA(fe(e,40))),m1:new O.Color(O.fromHSLA(fe(e,45))),z:t,p1:new O.Color(O.fromHSLA(fe(e,55))),p2:new O.Color(O.fromHSLA(fe(e,65)))}})),Pi=s.z.object({name:s.z.string(),key:s.z.string(),colors:s.z.object({border:O.Color.z,primary:Ft,gray:yl,error:Ft,secondary:Ft,warning:Ft,visualization:s.z.object({palettes:s.z.record(s.z.array(O.Color.z))}).optional().default({palettes:{}}),white:O.Color.z,black:O.Color.z,text:O.Color.z,textInverted:O.Color.z,textOnPrimary:O.Color.z.optional().default(O.ZERO),logo:s.z.string()}),sizes:s.z.object({base:s.z.number(),border:s.z.object({radius:s.z.number(),width:s.z.number()}),schematic:s.z.object({elementStrokeWidth:s.z.number()})}),typography:s.z.object({family:s.z.string(),h1:Me,h2:Me,h3:Me,h4:Me,h5:Me,p:Me,small:Me})}).transform(t=>((t.colors.textOnPrimary==null||t.colors.textOnPrimary.isZero)&&(t.colors.textOnPrimary=t.colors.primary.z.pickByContrast(t.colors.text,t.colors.textInverted)),t)),pl="'Inter Variable', sans-serif",ml=6,tt=[357,91,55,1],rt=[42,100,50,1],wl=["#FCFCFC","#F9F9F9","#F4F4F4","#ededed","#d9d9d9","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],_t=Object.fromEntries(wl.map((t,e)=>[`l${e}`,t])),Sn={key:"synnaxBase",name:"Synnax Base",colors:{primary:{m2:"#041B3D",m1:"#164FA0",z:"#3774D0",p1:"#5E94EE",p2:"#8AB8FF"},secondary:{m2:"#2D8F4E",m1:"#38B261",z:"#50C878",p1:"#73D393",p2:"#96DEAE"},gray:_t,border:_t.l3,error:{m2:O.fromHSLA(fe(tt,30)),m1:O.fromHSLA(fe(tt,40)),z:O.fromHSLA(tt),p1:O.fromHSLA(fe(tt,60)),p2:O.fromHSLA(fe(tt,70))},warning:{m2:O.fromHSLA(fe(rt,30)),m1:O.fromHSLA(fe(rt,40)),z:O.fromHSLA(rt),p1:O.fromHSLA(fe(rt,60)),p2:O.fromHSLA(fe(rt,70))},visualization:{palettes:{default:["#DC136C","#20A4F3","#7AC74F","#FFC43D","#FE5F55","#8075FF","#D90429","#f7aef8","#f18f01","#791e94","#279af1","#d9fff5","#ff6b6b","#52ffb8"]}},logo:"url(#synnax-linear-gradient)",white:"#FFFFFF",black:"#000000",text:_t.l9,textInverted:_t.l0},sizes:{base:ml,border:{radius:2,width:1},schematic:{elementStrokeWidth:2}},typography:{family:pl,h1:{size:7,weight:"500",lineHeight:7*1.5},h2:{size:4.5,weight:"medium",lineHeight:4.5*1.5},h3:{size:3.5,weight:"medium",lineHeight:3.5*1.5},h4:{size:2.5,weight:"medium",lineHeight:2.5*1.5},h5:{size:2.333333,weight:450,lineHeight:2.333333*1.5},p:{size:2.1666666666,weight:"regular",lineHeight:2*1.5},small:{size:1.916666,weight:"regular",lineHeight:1.9166666*1.5}}},Bi=Object.freeze({...Sn,key:"synnaxLight",name:"Synnax Light"}),bl=["#020202","#080808","#141414","#1a1a1a","#242424","#515151","#7f7f7f","#9D9D9D","#BFBFBF","#EDEDED","#FDFDFD"],Wt=Object.fromEntries(bl.map((t,e)=>[`l${e}`,t])),Ui=Object.freeze({...Sn,key:"synnaxDark",name:"Synnax Dark",colors:{...Sn.colors,gray:Wt,logo:"var(--pluto-text-color)",border:Wt.l3,text:Wt.l9,textInverted:Wt.l0}}),vl={synnaxDark:Ui,synnaxLight:Bi},Ol=["small","medium","large","huge"],Tl=s.z.enum(Ol),Sl=t=>Tl.safeParse(t).success,zl=(t,e,r)=>{const{typography:n,sizes:{base:i}}=t,a=n[Sl(e)?Di[e]:e].size,o=i*a,[c,u]=n.family.split(", ");return r!=null?` ${r} ${o}px ${c}, ${u}`:` ${o}px ${n.family}`};var Nl=Object.defineProperty,El=(t,e,r)=>e in t?Nl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l=(t,e,r)=>El(t,typeof e!="symbol"?e+"":e,r),Il=Object.defineProperty,Al=(t,e,r)=>e in t?Il(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$=(t,e,r)=>Al(t,typeof e!="symbol"?e+"":e,r);const kl=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()?e:e[0].toLowerCase()+e.slice(1)},Li=t=>{const e=(r,n=zn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!Xr(r))return r;n=$l(n);const i={},a=r;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);n.recursive&&(Xr(c)?As(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&Is(c)&&(c=[...c].map(d=>{let f=d;return Xr(d)?As(f,n.keepTypesOnRecursion)||(f=e(d,n)):Is(d)&&(f=e({key:d},n).key),f}))),i[u]=c}),i};return e},xl=Li(kl),Cl=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Rl=Li(Cl),zn={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},$l=(t=zn)=>(t.recursive==null?t=zn:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Is=t=>t!=null&&Array.isArray(t),Xr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),As=(t,e)=>(e||[]).some(r=>t instanceof r),Yi=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var jl=Object.defineProperty,Ml=(t,e,r)=>e in t?jl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ot=(t,e,r)=>Ml(t,typeof e!="symbol"?e+"":e,r);let Dl=class{constructor(){Ot(this,"contentType","application/json"),Ot(this,"decoder"),Ot(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const r=JSON.parse(t),n=xl(r);return e!=null?e.parse(n):n}encodeString(t){const e=Rl(t);return JSON.stringify(e,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):Yi(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},Pl=class{constructor(){Ot(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const r=new TextDecoder().decode(t);return this.decodeString(r,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!Yi(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),r=[e.join(",")];return t.forEach(n=>{const i=e.map(a=>JSON.stringify(n[a]??""));r.push(i.join(","))}),r.join(`
14
- `)}decodeString(t,e){const[r,...n]=t.trim().split(`
15
- `).map(o=>o.trim());if(r.length===0)return e!=null?e.parse({}):{};const i=r.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),n.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(c[d]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},Bl=class{constructor(){Ot(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const r=new TextDecoder().decode(t);return e!=null?e.parse(r):r}};new Dl;new Pl;new Bl;const Br=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const qi=s.z.object({width:s.z.number(),height:s.z.number()}),Ul=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Ll=["width","height"];s.z.enum(Ll);const Yl=["start","center","end"],ql=["signedWidth","signedHeight"];s.z.enum(ql);const Ir=s.z.object({x:s.z.number(),y:s.z.number()}),Fl=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),_l=["x","y"],Fi=s.z.enum(_l),_i=["top","right","bottom","left"];s.z.enum(_i);const Wl=["left","right"],Wi=s.z.enum(Wl),Gl=["top","bottom"],Gi=s.z.enum(Gl),Zi=["center"],ks=s.z.enum(Zi),Zl=[..._i,...Zi],Vi=s.z.enum(Zl);s.z.enum(Yl);const Vl=["first","last"];s.z.enum(Vl);const Kl=s.z.object({lower:s.z.number(),upper:s.z.number()}),Jl=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Kl,Br]);s.z.union([Jl,Br]);s.z.union([Fi,Vi]);s.z.union([Fi,Vi,s.z.instanceof(String)]);const Qr=(t,e)=>{const r={};if(typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else return xs(t);return xs(r)},xs=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:Wi.or(ks),y:Gi.or(ks)});const Hl=s.z.object({x:Wi,y:Gi}),Xl=Object.freeze({x:"left",y:"top"}),Ql=(t,e)=>t.x===e.x&&t.y===e.y,Cs=s.z.union([s.z.number(),Ir,Br,qi,Ul,Fl]),eu=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},Rs=Object.freeze({x:0,y:0}),Gt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Gt,left:Gt,width:Gt,height:Gt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Ir,two:Ir,root:Hl});const Vn=(t,e,r=0,n=0,i)=>{const a={one:{...Rs},two:{...Rs},root:i??Xl};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"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))},en=t=>{const e=Vn(t);return{lower:e.one.x,upper:e.two.x}},tn=t=>{const e=Vn(t);return{lower:e.one.y,upper:e.two.y}},tu=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var ru=Object.defineProperty,nu=(t,e,r)=>e in t?ru(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ce=(t,e,r)=>nu(t,typeof e!="symbol"?e+"":e,r);const su=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:Cs,scale:Cs});const iu=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],au=t=>(e,r,n,i)=>[e,i?n/t:n*t],ou=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,d=c-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},cu=t=>(e,r,n)=>[t,n],lu=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:i}=t;return[t,i-(r-n)]},uu=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=su(n,i,a),[e,n]},Nn=class lt{constructor(){Ce(this,"ops",[]),Ce(this,"currBounds",null),Ce(this,"currType",null),Ce(this,"reversed",!1),this.ops=[]}static translate(e){return new lt().translate(e)}static magnify(e){return new lt().magnify(e)}static scale(e,r){return new lt().scale(e,r)}translate(e){const r=this.new(),n=iu(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=au(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=Qr(e,r),i=this.new(),a=ou(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=Qr(e,r),i=this.new(),a=uu(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=Qr(e,r),i=this.new(),a=cu(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=lu();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new lt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||r.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&r.push([i,a])}),r.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}};Ce(Nn,"IDENTITY",new Nn);let $s=Nn;const js=class Ae{constructor(e=new $s,r=new $s,n=null){Ce(this,"x"),Ce(this,"y"),Ce(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new Ae().translate(e,r)}static translateX(e){return new Ae().translateX(e)}static translateY(e){return new Ae().translateY(e)}static clamp(e){return new Ae().clamp(e)}static magnify(e){return new Ae().magnify(e)}static scale(e){return new Ae().scale(e)}static reBound(e){return new Ae().reBound(e)}translate(e,r){const n=eu(e,r),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(tu(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Ql(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(en(e)),r.y=r.y.scale(tn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(en(e)),r.y=this.y.reBound(tn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(en(e)),r.y=this.y.clamp(tn(e)),r}copy(){const e=new Ae;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)}}box(e){return Vn(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Ce(js,"IDENTITY",new js);const hu=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([qi,hu,Ir,Br]);var du=Object.defineProperty,fu=(t,e,r)=>e in t?du(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,b=(t,e,r)=>fu(t,typeof e!="symbol"?e+"":e,r);const Ki=(t,e)=>{const r=new ee(e);if(![te.DAY,te.HOUR,te.MINUTE,te.SECOND,te.MILLISECOND,te.MICROSECOND,te.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof ee?new ee(n):new te(n)},U=class S{constructor(e,r="UTC"){if(b(this,"value"),b(this,"encodeValue",!0),e==null)this.value=S.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*S.MILLISECOND.valueOf();else if(typeof e=="string")this.value=S.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=S.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=S.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=S.MAX:e=S.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new S(BigInt(i.getTime())*S.MILLISECOND.valueOf()).truncate(S.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=S.hours(parseInt(n??"00",10)).add(S.minutes(parseInt(i??"00",10))).add(S.seconds(parseInt(o??"00",10))).add(S.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(S.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return S.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new S(BigInt(n.getTime())*S.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(S.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new te(BigInt(new Date().getTimezoneOffset())*S.MINUTE.valueOf())}static since(e){return new S().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new S(e).valueOf()}span(e){return this.range(e).span}range(e){return new yu(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new S(e).valueOf()}afterEq(e){return this.valueOf()>=new S(e).valueOf()}before(e){return this.valueOf()<new S(e).valueOf()}beforeEq(e){return this.valueOf()<=new S(e).valueOf()}add(e){return new S(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new S(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(S.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ki(this,e)}get isToday(){return this.truncate(te.DAY).equals(S.now().truncate(te.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new S(new Date)}static max(...e){let r=S.MIN;for(const n of e){const i=new S(n);i.after(r)&&(r=i)}return r}static min(...e){let r=S.MAX;for(const n of e){const i=new S(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new S(e)}static microseconds(e){return S.nanoseconds(e*1e3)}static milliseconds(e){return S.microseconds(e*1e3)}static seconds(e){return S.milliseconds(e*1e3)}static minutes(e){return S.seconds(e*60)}static hours(e){return S.minutes(e*60)}static days(e){return S.hours(e*24)}};b(U,"NANOSECOND",U.nanoseconds(1)),b(U,"MICROSECOND",U.microseconds(1)),b(U,"MILLISECOND",U.milliseconds(1)),b(U,"SECOND",U.seconds(1)),b(U,"MINUTE",U.minutes(1)),b(U,"HOUR",U.hours(1)),b(U,"DAY",U.days(1)),b(U,"MAX",new U((1n<<63n)-1n)),b(U,"MIN",new U(0)),b(U,"ZERO",new U(0)),b(U,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new U(t.value)),s.z.string().transform(t=>new U(BigInt(t))),s.z.instanceof(Number).transform(t=>new U(t)),s.z.number().transform(t=>new U(t)),s.z.instanceof(U)]));let ee=U;const L=class x{constructor(e){b(this,"value"),b(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new x(e).valueOf()}greaterThan(e){return this.valueOf()>new x(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new x(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new x(e).valueOf()}remainder(e){return Ki(this,e)}truncate(e){return new x(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(x.DAY),r=this.truncate(x.HOUR),n=this.truncate(x.MINUTE),i=this.truncate(x.SECOND),a=this.truncate(x.MILLISECOND),o=this.truncate(x.MICROSECOND),c=this.truncate(x.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),M=a.sub(i),_=o.sub(a),re=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),M.isZero||(R+=`${M.milliseconds}ms `),_.isZero||(R+=`${_.microseconds}µs `),re.isZero||(R+=`${re.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(x.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(x.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(x.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(x.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(x.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(x.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new x(e).valueOf()}add(e){return new x(this.valueOf()+new x(e).valueOf())}sub(e){return new x(this.valueOf()-new x(e).valueOf())}static nanoseconds(e=1){return new x(e)}static microseconds(e=1){return x.nanoseconds(e*1e3)}static milliseconds(e=1){return x.microseconds(e*1e3)}static seconds(e=1){return x.milliseconds(e*1e3)}static minutes(e){return x.seconds(e.valueOf()*60)}static hours(e){return x.minutes(e*60)}static days(e){return x.hours(e*24)}};b(L,"NANOSECOND",L.nanoseconds(1)),b(L,"MICROSECOND",L.microseconds(1)),b(L,"MILLISECOND",L.milliseconds(1)),b(L,"SECOND",L.seconds(1)),b(L,"MINUTE",L.minutes(1)),b(L,"HOUR",L.hours(1)),b(L,"DAY",L.days(1)),b(L,"MAX",new L((1n<<63n)-1n)),b(L,"MIN",new L(0)),b(L,"ZERO",new L(0)),b(L,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new L(t.value)),s.z.string().transform(t=>new L(BigInt(t))),s.z.instanceof(Number).transform(t=>new L(t)),s.z.number().transform(t=>new L(t)),s.z.instanceof(L)]));let te=L;const Zt=class rr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new rr(e).valueOf()}get period(){return te.seconds(1/this.valueOf())}sampleCount(e){return new te(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new le(r).valueOf()}span(e){return te.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new rr(e)}static khz(e){return rr.hz(e*1e3)}};b(Zt,"z",s.z.union([s.z.number().transform(t=>new Zt(t)),s.z.instanceof(Number).transform(t=>new Zt(t)),s.z.instanceof(Zt)]));const X=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new gu(e*this.valueOf())}};b(X,"UNKNOWN",new X(0)),b(X,"BIT128",new X(16)),b(X,"BIT64",new X(8)),b(X,"BIT32",new X(4)),b(X,"BIT16",new X(2)),b(X,"BIT8",new X(1)),b(X,"z",s.z.union([s.z.number().transform(t=>new X(t)),s.z.instanceof(Number).transform(t=>new X(t)),s.z.instanceof(X)]));let le=X;const Oe=class nr{constructor(e,r){b(this,"start"),b(this,"end"),typeof e=="object"&&"start"in e?(this.start=new ee(e.start),this.end=new ee(e.end)):(this.start=new ee(e),this.end=new ee(r))}get span(){return new te(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}swap(){return new nr(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=te.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=ee.max(n.start,e.start),a=ee.min(n.end,e.end);return a.before(i)?!1:new te(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){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<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof nr?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new nr(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};b(Oe,"MAX",new Oe(ee.MIN,ee.MAX)),b(Oe,"MIN",new Oe(ee.MAX,ee.MIN)),b(Oe,"ZERO",new Oe(ee.ZERO,ee.ZERO)),b(Oe,"z",s.z.union([s.z.object({start:ee.z,end:ee.z}).transform(t=>new Oe(t.start,t.end)),s.z.instanceof(Oe)]));let yu=Oe;const p=class Te extends String{constructor(e){if(e instanceof Te||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Te.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Te.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Te.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()}toString(){return this.valueOf()}get isVariable(){return this.equals(Te.JSON)||this.equals(Te.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Te.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Te.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Te.BIG_INT_TYPES.some(e=>e.equals(this))}};b(p,"UNKNOWN",new p("unknown")),b(p,"FLOAT64",new p("float64")),b(p,"FLOAT32",new p("float32")),b(p,"INT64",new p("int64")),b(p,"INT32",new p("int32")),b(p,"INT16",new p("int16")),b(p,"INT8",new p("int8")),b(p,"UINT64",new p("uint64")),b(p,"UINT32",new p("uint32")),b(p,"UINT16",new p("uint16")),b(p,"UINT8",new p("uint8")),b(p,"BOOLEAN",p.UINT8),b(p,"TIMESTAMP",new p("timestamp")),b(p,"UUID",new p("uuid")),b(p,"STRING",new p("string")),b(p,"JSON",new p("json")),b(p,"ARRAY_CONSTRUCTORS",new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array]])),b(p,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]])),b(p,"DENSITIES",new Map([[p.UINT8.toString(),le.BIT8],[p.UINT16.toString(),le.BIT16],[p.UINT32.toString(),le.BIT32],[p.UINT64.toString(),le.BIT64],[p.FLOAT32.toString(),le.BIT32],[p.FLOAT64.toString(),le.BIT64],[p.INT8.toString(),le.BIT8],[p.INT16.toString(),le.BIT16],[p.INT32.toString(),le.BIT32],[p.INT64.toString(),le.BIT64],[p.TIMESTAMP.toString(),le.BIT64],[p.STRING.toString(),le.UNKNOWN],[p.JSON.toString(),le.UNKNOWN],[p.UUID.toString(),le.BIT128]])),b(p,"ALL",[p.UNKNOWN,p.FLOAT64,p.FLOAT32,p.INT64,p.INT32,p.INT16,p.INT8,p.UINT64,p.UINT32,p.UINT16,p.UINT8,p.TIMESTAMP,p.UUID,p.STRING,p.JSON]),b(p,"BIG_INT_TYPES",[p.INT64,p.UINT64,p.TIMESTAMP]),b(p,"z",s.z.union([s.z.string().transform(t=>new p(t)),s.z.instanceof(p)]));const se=class V extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return V.bytes(this.valueOf()+e.valueOf())}sub(e){return V.bytes(this.valueOf()-e.valueOf())}truncate(e){return new V(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return V.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/V.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/V.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/V.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/V.TERABYTE.valueOf()}toString(){const e=this.truncate(V.TERABYTE),r=this.truncate(V.GIGABYTE),n=this.truncate(V.MEGABYTE),i=this.truncate(V.KILOBYTE),a=this.truncate(V.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new V(e)}static kilobytes(e=1){return V.bytes(e.valueOf()*1e3)}static megabytes(e=1){return V.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return V.megabytes(e.valueOf()*1e3)}static terabytes(e){return V.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};b(se,"BYTE",new se(1)),b(se,"KILOBYTE",se.kilobytes(1)),b(se,"MEGABYTE",se.megabytes(1)),b(se,"GIGABYTE",se.gigabytes(1)),b(se,"TERABYTE",se.terabytes(1)),b(se,"ZERO",new se(0)),b(se,"z",s.z.union([s.z.number().transform(t=>new se(t)),s.z.instanceof(se)]));let gu=se;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)]);s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Ji=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",pu=Ji(),Hi=["MacOS","Windows","Linux","Docker"],mu=s.z.enum(Hi);let rn;const wu=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},bu=(t={})=>{const{force:e,default:r}=t;return e??rn??(rn=wu(),rn??r)},Xi=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Hi,RUNTIME:pu,detect:Ji,getOS:bu,osZ:mu},Symbol.toStringTag,{value:"Module"}));var vu=Object.defineProperty,Ou=(t,e,r)=>e in t?vu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ut=(t,e,r)=>Ou(t,typeof e!="symbol"?e+"":e,r);const Tu=(...t)=>t.map(Qi).join(""),Qi=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Su=t=>t.endsWith("/")?t.slice(0,-1):t,zu=(t,e="")=>t===null?"":"?"+Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&"),En=class In{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){ut(this,"protocol"),ut(this,"host"),ut(this,"port"),ut(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Qi(i)}replace(e){return new In({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new In({...this,pathPrefix:Tu(this.path,e)})}toString(){return Su(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};ut(En,"UNKNOWN",new En({host:"unknown",port:0}));let Nu=En;var Eu=Object.defineProperty,Iu=(t,e,r)=>e in t?Eu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sr=(t,e,r)=>Iu(t,typeof e!="symbol"?e+"":e,r);const Ze=class extends Number{};sr(Ze,"Absolute",255),sr(Ze,"Default",1),sr(Ze,"z",s.z.union([s.z.instanceof(Ze),s.z.number().int().min(0).max(255).transform(t=>new Ze(t)),s.z.instanceof(Number).transform(t=>new Ze(t))]));s.z.object({name:s.z.string(),key:s.z.string()});const ea=class ht extends Error{constructor(){super(ht.MESSAGE)}matches(e){return typeof e=="string"?e.includes(ht.MESSAGE):e instanceof ht||e.message.includes(ht.MESSAGE)}};sr(ea,"MESSAGE","canceled");let Au=ea;new Au;s.z.string().regex(/^\d+\.\d+\.\d+$/);const he=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(t):e instanceof Error?e.message.includes(t):typeof e!="string"?!1:e.includes(t);let we=class extends Error{constructor(e){super(e),$(this,"discriminator","FreighterError"),$(this,"type","")}};const ku=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},Ms="unknown",Ds="nil",xu="freighter",Mt=s.z.object({type:s.z.string(),data:s.z.string()});class Cu{constructor(){$(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Ds,data:""};if(ku(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}return{type:Ms,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Ds)return null;if(e.type===Ms)return new Ps(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Ps(e.data)}}const ta=new Cu,ra=({encode:t,decode:e})=>ta.register({encode:t,decode:e}),Kn=t=>ta.decode(t);class Ps extends we{constructor(e){super(e),$(this,"type","unknown")}}const Ur="freighter.",ir=class na extends we{constructor(){super("EOF"),$(this,"type",na.TYPE)}};$(ir,"TYPE",Ur+"eof"),$(ir,"matches",he(ir.TYPE));let De=ir;const ar=class sa extends we{constructor(){super("StreamClosed"),$(this,"type",sa.TYPE)}};$(ar,"TYPE",Ur+"stream_closed"),$(ar,"matches",he(ar.TYPE));let Je=ar;const or=class ia extends we{constructor(e={}){const{message:r="Unreachable",url:n=Nu.UNKNOWN}=e;super(r),$(this,"type",ia.TYPE),$(this,"url"),this.url=n}};$(or,"TYPE",Ur+"unreachable"),$(or,"matches",he(or.TYPE));let We=or;const Ru=t=>{if(!t.type.startsWith(xu))return null;if(De.matches(t))return{type:De.TYPE,data:"EOF"};if(Je.matches(t))return{type:Je.TYPE,data:"StreamClosed"};if(We.matches(t))return{type:We.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},$u=t=>{if(!t.type.startsWith(Ur))return null;switch(t.type){case De.TYPE:return new De;case Je.TYPE:return new Je;case We.TYPE:return new We;default:throw new Error(`Unknown error type: ${t.data}`)}};ra({encode:Ru,decode:$u});class aa{constructor(){$(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const i=async a=>{if(n===this.middleware.length)return await r(a);const o=this.middleware[n];return n++,await o(a,i)};return await i(e)}}const oa="Content-Type",Bs=t=>{if(Xi.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const r=require("https"),n=new r.Agent({rejectUnauthorized:!1});return async(i,a)=>await e(i,{...a,agent:n})};class ju extends aa{constructor(e,r,n=!1){return super(),$(this,"endpoint"),$(this,"encoder"),$(this,"fetch"),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,this.fetch=Bs(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[oa]:this.encoder.contentType}}async send(e,r,n,i){r=n==null?void 0:n.parse(r);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(r??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async d=>{const f={...d,params:{}};c.headers={...this.headers,...d.params};let h;try{h=await Bs(d.protocol)(d.target,c)}catch(_){let re=_;return re.message==="Load failed"&&(re=new We({url:o})),[f,re]}const M=await h.arrayBuffer();if(h!=null&&h.ok)return i!=null&&(a=this.encoder.decode(M,i)),[f,null];try{if(h.status!==400)return[f,new Error(h.statusText)];const _=this.encoder.decode(M,Mt),re=Kn(_);return[f,re]}catch(_){return[f,new Error(`[freighter] - failed to decode error: ${h.statusText}: ${_.message}`)]}});return[a,u]}}const v=async(t,e,r,n,i)=>{const[a,o]=await t.send(e,r,n,i);if(o!=null)throw o;return a},Mu=()=>Xi.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),Du=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(Mt)});class Pu{constructor(e,r,n,i){$(this,"encoder"),$(this,"reqSchema"),$(this,"resSchema"),$(this,"ws"),$(this,"serverClosed"),$(this,"sendClosed"),$(this,"receiveDataQueue",[]),$(this,"receiveCallbacksQueue",[]),this.encoder=r,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new De;if(this.sendClosed)throw new Je;return this.ws.send(this.encoder.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");return this.serverClosed=Kn(e.error),[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.encoder.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,r)=>this.receiveCallbacksQueue.push({resolve:e,reject:r}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,Du)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:qu(e)?De.TYPE:Je.TYPE,data:""}})}}const Bu="freighterctx",Uu=1e3,Lu=1001,Yu=[Uu,Lu],qu=t=>Yu.includes(t.code),ca=class la extends aa{constructor(e,r,n=!1){super(),$(this,"baseUrl"),$(this,"encoder"),this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}async stream(e,r,n){const i=Mu();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const u=i(this.buildURL(e,c)),d={...c,params:{}};u.binaryType=la.MESSAGE_TYPE;const f=await this.wrapSocket(u,r,n);return f instanceof Error?[d,f]:(a=f,[d,null])});if(o!=null)throw o;return a}buildURL(e,r){const n=zu({[oa]:this.encoder.contentType,...r.params},Bu);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(i=>{e.onopen=()=>{i(new Pu(e,this.encoder,r,n))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};$(ca,"MESSAGE_TYPE","arraybuffer");let Fu=ca;const _u=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()?e:e[0].toLowerCase()+e.slice(1)},ua=t=>{const e=(r,n=An)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!nn(r))return r;n=Zu(n);const i={},a=r;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);n.recursive&&(nn(c)?Ls(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&Us(c)&&(c=[...c].map(d=>{let f=d;return nn(d)?Ls(f,n.keepTypesOnRecursion)||(f=e(d,n)):Us(d)&&(f=e({key:d},n).key),f}))),i[u]=c}),i};return e},ha=ua(_u),Wu=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Gu=ua(Wu),An={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Zu=(t=An)=>(t.recursive==null?t=An:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Us=t=>t!=null&&Array.isArray(t),nn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Ls=(t,e)=>(e||[]).some(r=>t instanceof r),Jn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var Vu=Object.defineProperty,Ku=(t,e,r)=>e in t?Vu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tt=(t,e,r)=>Ku(t,typeof e!="symbol"?e+"":e,r);let da=class{constructor(){Tt(this,"contentType","application/json"),Tt(this,"decoder"),Tt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const r=JSON.parse(t),n=ha(r);return e!=null?e.parse(n):n}encodeString(t){const e=Gu(t);return JSON.stringify(e,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):Jn(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},fa=class{constructor(){Tt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const r=new TextDecoder().decode(t);return this.decodeString(r,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!Jn(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),r=[e.join(",")];return t.forEach(n=>{const i=e.map(a=>JSON.stringify(n[a]??""));r.push(i.join(","))}),r.join(`
16
- `)}decodeString(t,e){const[r,...n]=t.trim().split(`
17
- `).map(o=>o.trim());if(r.length===0)return e!=null?e.parse({}):{};const i=r.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),n.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(c[d]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},ya=class{constructor(){Tt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const r=new TextDecoder().decode(t);return e!=null?e.parse(r):r}};const Ke=new da,Ju=new fa,Hu=new ya,Xu=[Ke],Xe=Object.freeze(Object.defineProperty({__proto__:null,CSVEncoderDecoder:fa,CSV_ECD:Ju,ENCODERS:Xu,JSONEncoderDecoder:da,JSON_ECD:Ke,TEXT_ECD:Hu,TextEncoderDecoder:ya},Symbol.toStringTag,{value:"Module"})),Qu=t=>t!=null&&typeof t=="object"&&"toString"in t,eh=(t,e=!1)=>{const r=Qu(t)?"stringer":typeof t;let n;switch(r){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 ${r}`),()=>-1}return e?th(n):n},th=t=>(e,r)=>t(r,e),Lr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ga=s.z.object({width:s.z.number(),height:s.z.number()}),rh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),nh=["width","height"];s.z.enum(nh);const sh=["start","center","end"],ih=["signedWidth","signedHeight"];s.z.enum(ih);const Ar=s.z.object({x:s.z.number(),y:s.z.number()}),ah=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),oh=["x","y"],pa=s.z.enum(oh),ma=["top","right","bottom","left"];s.z.enum(ma);const ch=["left","right"],wa=s.z.enum(ch),lh=["top","bottom"],ba=s.z.enum(lh),va=["center"],Ys=s.z.enum(va),uh=[...ma,...va],Oa=s.z.enum(uh);s.z.enum(sh);const hh=["first","last"];s.z.enum(hh);const dh=s.z.object({lower:s.z.number(),upper:s.z.number()}),fh=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([dh,Lr]);s.z.union([fh,Lr]);s.z.union([pa,Oa]);s.z.union([pa,Oa,s.z.instanceof(String)]);const St=(t,e)=>{const r={};if(typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else return qs(t);return qs(r)},qs=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:wa.or(Ys),y:ba.or(Ys)});const yh=s.z.object({x:wa,y:ba}),gh=Object.freeze({x:"left",y:"top"}),ph=(t,e)=>t.x===e.x&&t.y===e.y,Fs=s.z.union([s.z.number(),Ar,Lr,ga,rh,ah]),mh=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},_s=Object.freeze({x:0,y:0}),Vt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Vt,left:Vt,width:Vt,height:Vt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Ar,two:Ar,root:yh});const Hn=(t,e,r=0,n=0,i)=>{const a={one:{..._s},two:{..._s},root:i??gh};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"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))},sn=t=>{const e=Hn(t);return{lower:e.one.x,upper:e.two.x}},an=t=>{const e=Hn(t);return{lower:e.one.y,upper:e.two.y}},wh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,bh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ga,bh,Ar,Lr]);var vh=Object.defineProperty,Oh=(t,e,r)=>e in t?vh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Re=(t,e,r)=>Oh(t,typeof e!="symbol"?e+"":e,r);const Th=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:Fs,scale:Fs});const Sh=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],zh=t=>(e,r,n,i)=>[e,i?n/t:n*t],Nh=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,d=c-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},Eh=t=>(e,r,n)=>[t,n],Ih=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:i}=t;return[t,i-(r-n)]},Ah=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=Th(n,i,a),[e,n]},kn=class dt{constructor(){Re(this,"ops",[]),Re(this,"currBounds",null),Re(this,"currType",null),Re(this,"reversed",!1),this.ops=[]}static translate(e){return new dt().translate(e)}static magnify(e){return new dt().magnify(e)}static scale(e,r){return new dt().scale(e,r)}translate(e){const r=this.new(),n=Sh(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=zh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=St(e,r),i=this.new(),a=Nh(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=St(e,r),i=this.new(),a=Ah(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=St(e,r),i=this.new(),a=Eh(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Ih();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new dt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||r.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&r.push([i,a])}),r.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}};Re(kn,"IDENTITY",new kn);let Ws=kn;const Gs=class ke{constructor(e=new Ws,r=new Ws,n=null){Re(this,"x"),Re(this,"y"),Re(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new ke().translate(e,r)}static translateX(e){return new ke().translateX(e)}static translateY(e){return new ke().translateY(e)}static clamp(e){return new ke().clamp(e)}static magnify(e){return new ke().magnify(e)}static scale(e){return new ke().scale(e)}static reBound(e){return new ke().reBound(e)}translate(e,r){const n=mh(e,r),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(wh(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!ph(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(sn(e)),r.y=r.y.scale(an(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(sn(e)),r.y=this.y.reBound(an(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(sn(e)),r.y=this.y.clamp(an(e)),r}copy(){const e=new ke;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)}}box(e){return Hn(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Re(Gs,"IDENTITY",new Gs);var kh=Object.defineProperty,xh=(t,e,r)=>e in t?kh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,w=(t,e,r)=>xh(t,typeof e!="symbol"?e+"":e,r);let Ch=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const Rh="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ta=Ch(Rh,11),$h=Object.freeze(Object.defineProperty({__proto__:null,id:Ta},Symbol.toStringTag,{value:"Module"})),Sa=(t,e)=>{const r=new E(e);if(![I.DAY,I.HOUR,I.MINUTE,I.SECOND,I.MILLISECOND,I.MICROSECOND,I.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof E?new E(n):new I(n)},Y=class z{constructor(e,r="UTC"){if(w(this,"value"),w(this,"encodeValue",!0),e==null)this.value=z.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*z.MILLISECOND.valueOf();else if(typeof e=="string")this.value=z.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=z.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=z.MAX:e=z.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new z(BigInt(i.getTime())*z.MILLISECOND.valueOf()).truncate(z.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=z.hours(parseInt(n??"00",10)).add(z.minutes(parseInt(i??"00",10))).add(z.seconds(parseInt(o??"00",10))).add(z.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(z.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new z(BigInt(n.getTime())*z.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new I(BigInt(new Date().getTimezoneOffset())*z.MINUTE.valueOf())}static since(e){return new z().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new z(e).valueOf()}span(e){return this.range(e).span}range(e){return new oe(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new z(e).valueOf()}afterEq(e){return this.valueOf()>=new z(e).valueOf()}before(e){return this.valueOf()<new z(e).valueOf()}beforeEq(e){return this.valueOf()<=new z(e).valueOf()}add(e){return new z(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new z(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Sa(this,e)}get isToday(){return this.truncate(I.DAY).equals(z.now().truncate(I.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let r=z.MIN;for(const n of e){const i=new z(n);i.after(r)&&(r=i)}return r}static min(...e){let r=z.MAX;for(const n of e){const i=new z(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new z(e)}static microseconds(e){return z.nanoseconds(e*1e3)}static milliseconds(e){return z.microseconds(e*1e3)}static seconds(e){return z.milliseconds(e*1e3)}static minutes(e){return z.seconds(e*60)}static hours(e){return z.minutes(e*60)}static days(e){return z.hours(e*24)}};w(Y,"NANOSECOND",Y.nanoseconds(1)),w(Y,"MICROSECOND",Y.microseconds(1)),w(Y,"MILLISECOND",Y.milliseconds(1)),w(Y,"SECOND",Y.seconds(1)),w(Y,"MINUTE",Y.minutes(1)),w(Y,"HOUR",Y.hours(1)),w(Y,"DAY",Y.days(1)),w(Y,"MAX",new Y((1n<<63n)-1n)),w(Y,"MIN",new Y(0)),w(Y,"ZERO",new Y(0)),w(Y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new Y(t.value)),s.z.string().transform(t=>new Y(BigInt(t))),s.z.instanceof(Number).transform(t=>new Y(t)),s.z.number().transform(t=>new Y(t)),s.z.instanceof(Y)]));let E=Y;const q=class C{constructor(e){w(this,"value"),w(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new C(e).valueOf()}greaterThan(e){return this.valueOf()>new C(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new C(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new C(e).valueOf()}remainder(e){return Sa(this,e)}truncate(e){return new C(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(C.DAY),r=this.truncate(C.HOUR),n=this.truncate(C.MINUTE),i=this.truncate(C.SECOND),a=this.truncate(C.MILLISECOND),o=this.truncate(C.MICROSECOND),c=this.truncate(C.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),M=a.sub(i),_=o.sub(a),re=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),M.isZero||(R+=`${M.milliseconds}ms `),_.isZero||(R+=`${_.microseconds}µs `),re.isZero||(R+=`${re.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.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 isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new C(e).valueOf()}add(e){return new C(this.valueOf()+new C(e).valueOf())}sub(e){return new C(this.valueOf()-new C(e).valueOf())}static nanoseconds(e=1){return new C(e)}static microseconds(e=1){return C.nanoseconds(e*1e3)}static milliseconds(e=1){return C.microseconds(e*1e3)}static seconds(e=1){return C.milliseconds(e*1e3)}static minutes(e){return C.seconds(e.valueOf()*60)}static hours(e){return C.minutes(e*60)}static days(e){return C.hours(e*24)}};w(q,"NANOSECOND",q.nanoseconds(1)),w(q,"MICROSECOND",q.microseconds(1)),w(q,"MILLISECOND",q.milliseconds(1)),w(q,"SECOND",q.seconds(1)),w(q,"MINUTE",q.minutes(1)),w(q,"HOUR",q.hours(1)),w(q,"DAY",q.days(1)),w(q,"MAX",new q((1n<<63n)-1n)),w(q,"MIN",new q(0)),w(q,"ZERO",new q(0)),w(q,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new q(t.value)),s.z.string().transform(t=>new q(BigInt(t))),s.z.instanceof(Number).transform(t=>new q(t)),s.z.number().transform(t=>new q(t)),s.z.instanceof(q)]));let I=q;const ft=class cr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new cr(e).valueOf()}get period(){return I.seconds(1/this.valueOf())}sampleCount(e){return new I(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new ue(r).valueOf()}span(e){return I.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new cr(e)}static khz(e){return cr.hz(e*1e3)}};w(ft,"z",s.z.union([s.z.number().transform(t=>new ft(t)),s.z.instanceof(Number).transform(t=>new ft(t)),s.z.instanceof(ft)]));let Xn=ft;const Q=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new It(e*this.valueOf())}};w(Q,"UNKNOWN",new Q(0)),w(Q,"BIT128",new Q(16)),w(Q,"BIT64",new Q(8)),w(Q,"BIT32",new Q(4)),w(Q,"BIT16",new Q(2)),w(Q,"BIT8",new Q(1)),w(Q,"z",s.z.union([s.z.number().transform(t=>new Q(t)),s.z.instanceof(Number).transform(t=>new Q(t)),s.z.instanceof(Q)]));let ue=Q;const Se=class lr{constructor(e,r){w(this,"start"),w(this,"end"),typeof e=="object"&&"start"in e?(this.start=new E(e.start),this.end=new E(e.end)):(this.start=new E(e),this.end=new E(r))}get span(){return new I(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}swap(){return new lr(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=I.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=E.max(n.start,e.start),a=E.min(n.end,e.end);return a.before(i)?!1:new I(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){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<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof lr?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new lr(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};w(Se,"MAX",new Se(E.MIN,E.MAX)),w(Se,"MIN",new Se(E.MAX,E.MIN)),w(Se,"ZERO",new Se(E.ZERO,E.ZERO)),w(Se,"z",s.z.union([s.z.object({start:E.z,end:E.z}).transform(t=>new Se(t.start,t.end)),s.z.instanceof(Se)]));let oe=Se;const g=class ze extends String{constructor(e){if(e instanceof ze||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=ze.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(ze.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=ze.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()}toString(){return this.valueOf()}get isVariable(){return this.equals(ze.JSON)||this.equals(ze.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(ze.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=ze.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return ze.BIG_INT_TYPES.some(e=>e.equals(this))}};w(g,"UNKNOWN",new g("unknown")),w(g,"FLOAT64",new g("float64")),w(g,"FLOAT32",new g("float32")),w(g,"INT64",new g("int64")),w(g,"INT32",new g("int32")),w(g,"INT16",new g("int16")),w(g,"INT8",new g("int8")),w(g,"UINT64",new g("uint64")),w(g,"UINT32",new g("uint32")),w(g,"UINT16",new g("uint16")),w(g,"UINT8",new g("uint8")),w(g,"BOOLEAN",g.UINT8),w(g,"TIMESTAMP",new g("timestamp")),w(g,"UUID",new g("uuid")),w(g,"STRING",new g("string")),w(g,"JSON",new g("json")),w(g,"ARRAY_CONSTRUCTORS",new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]])),w(g,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]])),w(g,"DENSITIES",new Map([[g.UINT8.toString(),ue.BIT8],[g.UINT16.toString(),ue.BIT16],[g.UINT32.toString(),ue.BIT32],[g.UINT64.toString(),ue.BIT64],[g.FLOAT32.toString(),ue.BIT32],[g.FLOAT64.toString(),ue.BIT64],[g.INT8.toString(),ue.BIT8],[g.INT16.toString(),ue.BIT16],[g.INT32.toString(),ue.BIT32],[g.INT64.toString(),ue.BIT64],[g.TIMESTAMP.toString(),ue.BIT64],[g.STRING.toString(),ue.UNKNOWN],[g.JSON.toString(),ue.UNKNOWN],[g.UUID.toString(),ue.BIT128]])),w(g,"ALL",[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON]),w(g,"BIG_INT_TYPES",[g.INT64,g.UINT64,g.TIMESTAMP]),w(g,"z",s.z.union([s.z.string().transform(t=>new g(t)),s.z.instanceof(g)]));let A=g;const ie=class K extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return K.bytes(this.valueOf()+e.valueOf())}sub(e){return K.bytes(this.valueOf()-e.valueOf())}truncate(e){return new K(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return K.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/K.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/K.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/K.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/K.TERABYTE.valueOf()}toString(){const e=this.truncate(K.TERABYTE),r=this.truncate(K.GIGABYTE),n=this.truncate(K.MEGABYTE),i=this.truncate(K.KILOBYTE),a=this.truncate(K.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new K(e)}static kilobytes(e=1){return K.bytes(e.valueOf()*1e3)}static megabytes(e=1){return K.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return K.megabytes(e.valueOf()*1e3)}static terabytes(e){return K.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};w(ie,"BYTE",new ie(1)),w(ie,"KILOBYTE",ie.kilobytes(1)),w(ie,"MEGABYTE",ie.megabytes(1)),w(ie,"GIGABYTE",ie.gigabytes(1)),w(ie,"TERABYTE",ie.terabytes(1)),w(ie,"ZERO",new ie(0)),w(ie,"z",s.z.union([s.z.number().transform(t=>new ie(t)),s.z.instanceof(ie)]));let It=ie;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 za=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof E||t instanceof I||t instanceof Date},jh=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):yt(r,-n),Mh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Fe?!0:za(t),Le=-1;let Fe=class xe{constructor(e){w(this,"key",""),w(this,"isSynnaxSeries",!0),w(this,"dataType"),w(this,"sampleOffset"),w(this,"gl"),w(this,"_data"),w(this,"_timeRange"),w(this,"alignment",0n),w(this,"_cachedMin"),w(this,"_cachedMax"),w(this,"writePos",Le),w(this,"_refCount",0),w(this,"_cachedLength"),Mh(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Ta()}=e,{data:u}=e;if(u instanceof xe||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const h=u;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 d=za(u),f=Array.isArray(u);if(r!=null)this.dataType=new A(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=u;if(!d){if(u.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=u[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 E||h instanceof Date||h instanceof E)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(u)}if(!f&&!d)this._data=u;else{let h=d?[u]:u;const M=h[0];(M instanceof E||M instanceof Date||M instanceof I)&&(h=h.map(_=>new E(_).valueOf())),this.dataType.equals(A.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.join(`
18
- `)+`
19
- `)):this.dataType.equals(A.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.map(_=>Ke.encodeString(_)).join(`
20
- `)+`
21
- `)):this._data=new this.dataType.Array(h).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=n,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new A(r).Array(e),a=new xe({data:i.buffer,dataType:r,...n});return a.writePos=0,a}static generateTimestamps(e,r,n){const i=n.spanRange(r.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(n.add(r.span(o)).valueOf());return new xe({data:a,dataType:A.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,r){const n=new TextEncoder().encode(e.join(`
22
- `)+`
23
- `);return new xe({data:n,dataType:A.STRING,timeRange:r})}static fromJSON(e,r){const n=new TextEncoder().encode(e.map(i=>Ke.encodeString(i)).join(`
24
- `)+`
25
- `);return new xe({data:n,dataType:A.JSON,timeRange:r})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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");if(this.writePos===Le)return 0;const r=this.capacity-this.writePos,n=r<e.length?e.slice(0,r):e;return this.underlyingData.set(n.data,this.writePos),this.maybeRecomputeMinMax(n),this._cachedLength=void 0,this.writePos+=n.length,n.length}get buffer(){return this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Le?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.equals(A.STRING))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
26
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(A.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=A.UUID.density.valueOf(),r=Array(this.length);for(let n=0;n<this.length;n++){const i=this.buffer.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");r[n]=a}return r}parseJSON(e){if(!this.dataType.equals(A.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
27
- `).slice(0,-1).map(r=>e.parse(Ke.decodeString(r)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new It(this.buffer.byteLength)}get capacity(){return this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Le?this.byteCapacity:this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Le?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;return this.data.forEach(r=>{r===10&&e++}),this._cachedLength=e,e}convert(e,r=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]=jh(this.dataType,e,this.data[i],r);return new xe({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:r,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((r,n)=>r>n?r:n)}else{const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),yt(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((r,n)=>r<n?r:n)}else{const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),yt(this._cachedMin,this.sampleOffset))}get bounds(){return St(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const r=e._cachedMin??e.calcRawMin();r<this._cachedMin&&(this._cachedMin=r)}if(this._cachedMax!=null){const r=e._cachedMax??e.calcRawMax();r>this._cachedMax&&(this._cachedMax=r)}}enrich(){this.max,this.min}get range(){return yt(this.max,-this.min)}at(e,r){if(this.dataType.isVariable)return this.atVariable(e,r??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return yt(n,this.sampleOffset)}atVariable(e,r){e<0&&(e=this.length+e);let n=0,i=0;for(let o=0;o<this.data.length;o++)if(this.data[o]===10){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}const a=this.data.slice(n,i);return this.dataType.equals(A.STRING)?new TextDecoder().decode(a):ha(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const i=eh(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(A.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:i}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Le){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.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=Le}as(e){if(e==="string"){if(!this.dataType.equals(A.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(A.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return St(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 Dh(this);return this.dataType.equals(A.JSON)?new Ph(e):e}return new Bh(this)}slice(e,r){if(e<=0&&(r==null||r>=this.length))return this;const n=this.data.slice(e,r);return new xe({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}reAlign(e){return new xe({data:this.buffer,dataType:this.dataType,timeRange:oe.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};class Dh{constructor(e){if(w(this,"series"),w(this,"index"),w(this,"decoder"),!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,r=this.series.data;for(;this.index<r.length&&r[this.index]!==10;)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))})}[Symbol.iterator](){return this}}var Zs,Vs;class Ph{constructor(e){w(this,"wrapped"),w(this,Zs,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Ke.decodeString(e.value)}}[(Vs=Symbol.iterator,Zs=Symbol.toStringTag,Vs)](){return this}}var Ks,Js;class Bh{constructor(e){w(this,"series"),w(this,"index"),w(this,Ks,"SeriesIterator"),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)}}[(Js=Symbol.iterator,Ks=Symbol.toStringTag,Js)](){return this}}const yt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);class Uh{constructor(e){if(w(this,"series"),e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new A(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?A.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?oe.ZERO:new oe(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,r)=>e+r.length,0)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}get byteLength(){return new It(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Lh(this.series)}}var Hs,Xs;class Lh{constructor(e){w(this,"series"),w(this,"seriesIndex"),w(this,"internal"),w(this,Hs,"MultiSeriesIterator"),this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[(Xs=Symbol.iterator,Hs=Symbol.toStringTag,Xs)](){return this}}const N=t=>Array.isArray(t)?t:[t],Pe=s.z.number(),Dt=s.z.object({name:s.z.string(),key:s.z.number(),rate:Xn.z,dataType:A.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),alias:s.z.string().optional()}),Na=Dt.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:Xn.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Yh=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},qh=new Error("request for lock canceled");var Fh=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class _h{constructor(e,r=qh){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:r},o=Ea(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Fh(this,arguments,void 0,function*(r,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Wh(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function Wh(t,e){const r=Ea(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function Ea(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var Gh=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class Zh{constructor(e){this._semaphore=new _h(1,e)}acquire(){return Gh(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Be="sy.",ur=class Ia extends we{constructor(){super(...arguments),l(this,"type",Ia.TYPE)}};l(ur,"TYPE",Be+"validation"),l(ur,"matches",he(ur.TYPE));let G=ur;const hr=class Aa extends G{constructor(e,r){super(e+": "+r),l(this,"type",Aa.TYPE),l(this,"field"),l(this,"message"),this.field=e,this.message=r}};l(hr,"TYPE",G.TYPE+".field"),l(hr,"matches",he(hr.TYPE));let Qs=hr;const dr=class ka extends we{constructor(){super(...arguments),l(this,"type",ka.TYPE)}};l(dr,"TYPE",Be+"auth"),l(dr,"matches",he(dr.TYPE));let kr=dr;const fr=class xa extends kr{constructor(){super(...arguments),l(this,"type",xa.TYPE)}};l(fr,"TYPE",kr.TYPE+".invalid-token"),l(fr,"matches",he(fr.TYPE));let xn=fr;const yr=class Ca extends we{constructor(e){super(`
28
- Unexpected error encountered:
29
-
30
- ${e}
31
-
32
- Please report this to the Synnax team.
33
- `),l(this,"type",Ca.TYPE)}};l(yr,"TYPE",Be+"unexpected"),l(yr,"matches",he(yr.TYPE));let ge=yr;const gr=class Ra extends we{constructor(){super(...arguments),l(this,"type",Ra.TYPE)}};l(gr,"TYPE",Be+"query"),l(gr,"matches",he(gr.TYPE));let pe=gr;const pr=class $a extends pe{constructor(){super(...arguments),l(this,"type",$a.TYPE)}};l(pr,"TYPE",pe.TYPE+".not_found"),l(pr,"matches",he(pr.TYPE));let xr=pr;const mr=class ja extends pe{constructor(){super(...arguments),l(this,"type",ja.TYPE)}};l(mr,"TYPE",pe.TYPE+".multiple_results"),l(mr,"matches",he(mr.TYPE));let Cr=mr;const wr=class Ma extends we{constructor(e,r){super(e),l(this,"type",Ma.TYPE),l(this,"path"),this.path=r}};l(wr,"TYPE",Be+"route"),l(wr,"matches",he(wr.TYPE));let ei=wr;const br=class Da extends we{constructor(){super(...arguments),l(this,"type",Da.TYPE)}};l(br,"TYPE",Be+"control"),l(br,"matches",he(br.TYPE));let Rr=br;const vr=class Pa extends Rr{constructor(){super(...arguments),l(this,"type",Pa.TYPE)}};l(vr,"TYPE",Rr.TYPE+".unauthorized"),l(vr,"matches",he(vr.TYPE));let ti=vr;const on=class Ba extends we{constructor(){super(...arguments),l(this,"type",Ba.TYPE)}};l(on,"TYPE",Be+"contiguity"),l(on,"matches",he(on.TYPE));const Vh=t=>{if(!t.type.startsWith(Be))return null;if(t.type.startsWith(G.TYPE)){if(t.type===Qs.TYPE){const e=t.data.split(": ");return e.length<2?new G(t.data):new Qs(e[0],e[1])}return new G(t.data)}return t.type.startsWith(kr.TYPE)?t.type.startsWith(xn.TYPE)?new xn(t.data):new kr(t.data):t.type.startsWith(ge.TYPE)?new ge(t.data):t.type.startsWith(pe.TYPE)?t.type.startsWith(xr.TYPE)?new xr(t.data):t.type.startsWith(Cr.TYPE)?new Cr(t.data):new pe(t.data):t.type.startsWith(Rr.TYPE)?t.type.startsWith(ti.TYPE)?new ti(t.data):new Rr(t.data):t.type.startsWith(ei.TYPE)?new ei(t.data,t.data):new ge(t.data)},Kh=()=>{throw new Error("Not implemented")};ra({encode:Kh,decode:Vh});const Jh=async(t,e)=>{const[r,n]=await e(t);return n==null?[r,n]:n instanceof We?[r,new We({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[r,n]};var Hh=Object.defineProperty,Xh=(t,e,r)=>e in t?Hh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cn=(t,e,r)=>Xh(t,typeof e!="symbol"?e+"":e,r);class Qh{constructor(e,r){Cn(this,"handlers"),Cn(this,"transform"),this.transform=e,this.handlers=r??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let r=e;if(this.transform!=null){const[n,i]=this.transform(e);if(!i)return;r=n}this.handlers.forEach((n,i)=>i(r))}}let ed=class{constructor(t){Cn(this,"handlers"),this.handlers=t??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){this.handlers.forEach((e,r)=>r(t))}};const Rn=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:ed,Observer:Qh},Symbol.toStringTag,{value:"Module"})),Qn=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),td=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";td();const rd=["MacOS","Windows","Linux","Docker"];s.z.enum(rd);const ri=t=>[...new Set(t)];var nd=Object.defineProperty,sd=(t,e,r)=>e in t?nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gt=(t,e,r)=>sd(t,typeof e!="symbol"?e+"":e,r);const id=(...t)=>t.map(Ua).join(""),Ua=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),ad=t=>t.endsWith("/")?t.slice(0,-1):t,$n=class jn{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){gt(this,"protocol"),gt(this,"host"),gt(this,"port"),gt(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Ua(i)}replace(e){return new jn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new jn({...this,pathPrefix:id(this.path,e)})}toString(){return ad(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};gt($n,"UNKNOWN",new $n({host:"unknown",port:0}));let od=$n;var cd=Object.defineProperty,ld=(t,e,r)=>e in t?cd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Or=(t,e,r)=>ld(t,typeof e!="symbol"?e+"":e,r);const qe=class extends Number{};Or(qe,"Absolute",255),Or(qe,"Default",1),Or(qe,"z",s.z.union([s.z.instanceof(qe),s.z.number().int().min(0).max(255).transform(t=>new qe(t)),s.z.instanceof(Number).transform(t=>new qe(t))]));let La=qe;const Ya=s.z.object({name:s.z.string(),key:s.z.string()}),ud=t=>s.z.object({subject:Ya,resource:t,authority:La.z}),hd=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),He=Object.freeze(Object.defineProperty({__proto__:null,Authority:La,filterTransfersByChannelKey:hd,stateZ:ud,subjectZ:Ya},Symbol.toStringTag,{value:"Module"})),qa=class pt extends Error{constructor(){super(pt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(pt.MESSAGE):e instanceof pt||e.message.includes(pt.MESSAGE)}};Or(qa,"MESSAGE","canceled");let dd=qa;new dd;s.z.string().regex(/^\d+\.\d+\.\d+$/);const Yr=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let i=N(t);const a=i[0],o=typeof a;let c;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:n,variant:c,normalized:i,actual:t}},qr=(t,e,r,n)=>{if(n){if(r.length===0)throw new xr(`${t} not found matching ${JSON.stringify(e)}`);if(r.length>1)throw new Cr(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${r.length}`)}},Qe=t=>s.z.union([s.z.null().transform(()=>[]),t.array()]),fd=s.z.object({leaseholder:s.z.number().optional(),keys:s.z.number().array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:A.z.array().optional(),notDataTypes:A.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),yd=s.z.object({channels:Qe(Dt)}),$e=t=>Yr(t,{number:"keys",string:"names"}),Fa=class _a{constructor(e){l(this,"client"),this.client=e}async search(e,r){return await this.execute({search:e,...r})}async retrieve(e,r){const n=$e(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...r})}async page(e,r,n){return await this.execute({offset:e,limit:r,...n})}async execute(e){const[r,n]=await this.client.send(_a.ENDPOINT,e,fd,yd);if(n!=null)throw n;return r.channels}};l(Fa,"ENDPOINT","/channel/retrieve");let es=Fa;class ts{constructor(e){l(this,"cache"),l(this,"namesToKeys"),l(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,r){return await this.wrapped.search(e,r)}async page(e,r,n){return await this.wrapped.page(e,r,n)}async retrieve(e,r){const{normalized:n}=Yr(e,{string:"names",number:"keys"}),i=[],a=[];if(n.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,r);return this.set(o),i.concat(o)}delete(e){const{variant:r,normalized:n}=$e(e);r==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,r){e.forEach((n,i)=>{const a=r[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(r=>{this.cache.set(r.key,r);const n=this.namesToKeys.get(r.name);n==null?this.namesToKeys.set(r.name,new Set([r.key])):n.add(r.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const r=this.namesToKeys.get(e);if(r==null)return;const n=[];if(r.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class Wa{constructor(e,r){l(this,"mu",new Zh),l(this,"requests",new Map),l(this,"wrapped"),l(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=Yh(()=>{this.run()},r)}async search(e,r){return await this.wrapped.search(e,r)}async page(e,r,n){return await this.wrapped.page(e,r,n)}async retrieve(e){const{normalized:r,variant:n}=$e(e);return n==="names"?await this.wrapped.retrieve(r):await new Promise((i,a)=>{this.mu.runExclusive(()=>{this.requests.set(r,{resolve:i,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((r,n)=>n.forEach(i=>e.add(i)));try{const r=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(r.filter(a=>i.includes(a.key))))}catch(r){this.requests.forEach(n=>n.reject(r))}finally{this.requests.clear()}})}}const Ga=async(t,e)=>{const{normalized:r}=$e(e),n=await t.retrieve(r),i=[];if(r.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new pe(`Could not find channels: ${JSON.stringify(i)}`);return n};class Za{constructor(e,r){l(this,"key"),l(this,"name"),this.key=r,this.name=e}get ontologyID(){return new me({type:"group",key:this.key})}}const gd=s.z.string().uuid(),Va=s.z.object({key:gd,name:s.z.string()}),Ka=s.z.union([s.z.literal("label"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task")]),Ee=s.z.object({type:Ka,key:s.z.string()}),pd=s.z.string().transform(t=>{const[e,r]=t.split(":");return{type:e,key:r}}),md=s.z.union([pd,Ee]),Tr=class Ja{constructor(e){if(l(this,"type"),l(this,"key"),e instanceof Ja)this.type=e.type,this.key=e.key;else if(typeof e=="string"){const[r,n]=e.split(":");this.type=r,this.key=n}else this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}get payload(){return{type:this.type,key:this.key}}};l(Tr,"z",s.z.union([md,s.z.instanceof(Tr)]).transform(t=>new Tr(t)));let me=Tr;new me({type:"builtin",key:"root"});const wd=s.z.object({type:s.z.number()}),bd=s.z.object({type:Ka,fields:s.z.record(wd)}),vd=s.z.object({id:me.z,name:s.z.string(),schema:bd.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:me.z,type:s.z.string(),to:me.z});const ni=t=>{const[e,r,n]=t.split("->");return{from:new me(e),type:r,to:new me(n)}},Od=s.z.object({group:Va}),Td=s.z.object({parent:Ee,key:s.z.string().uuid().optional(),name:s.z.string()}),Sd=s.z.object({key:s.z.string(),name:s.z.string()}),zd=s.z.object({keys:s.z.array(s.z.string())});var je;let Nd=(je=class{constructor(t){l(this,"client"),this.client=t}async create(t,e,r){const[n,i]=await this.client.send(je.ENDPOINT,{parent:t,name:e,key:r},Td,Od);if(i!=null)throw i;return n.group}async rename(t,e){const r={key:t,name:e},[,n]=await this.client.send(je.ENDPOINT_RENAME,r,Sd,s.z.object({}));if(n!=null)throw n}async delete(t){const e={keys:t},[,r]=await this.client.send(je.ENDPOINT_DELETE,e,zd,s.z.object({}));if(r!=null)throw r}},l(je,"ENDPOINT","/ontology/create-group"),l(je,"ENDPOINT_RENAME","/ontology/rename-group"),l(je,"ENDPOINT_DELETE","/ontology/delete-group"),je),Ed=class{constructor(t){l(this,"creator"),this.creator=new Nd(t)}async create(t,e,r){return this.sugar(await this.creator.create(t,e,r))}async rename(t,e){return await this.creator.rename(t,e)}async delete(...t){return await this.creator.delete(t)}sugar(t){return new Za(t.name,t.key)}};const cn={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},si=s.z.object({id:Ee,children:Ee.array()}),Id=s.z.object({from:Ee,to:Ee,children:Ee.array()});let Ad=class{constructor(t){l(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,cn.ADD_CHILDREN,{id:t,children:e},si,s.z.object({}))}async removeChildren(t,...e){await v(this.client,cn.REMOVE_CHILDREN,{id:t,children:e},si,s.z.object({}))}async moveChildren(t,e,...r){const n={from:t,to:e,children:r};await v(this.client,cn.MOVE_CHILDREN,n,Id,s.z.object({}))}};const kd="/ontology/retrieve",xd=s.z.object({ids:Ee.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional()}),Cd=s.z.object({resources:vd.array()}),ln=t=>N(t).map(e=>new me(e).payload);let Rd=class{constructor(t,e){l(this,"type","ontology"),l(this,"groups"),l(this,"client"),l(this,"writer"),l(this,"framer"),this.client=t,this.writer=new Ad(t),this.groups=new Ed(t),this.framer=e}async search(t,e){return await this.execRetrieve({term:t,...e})}async retrieve(t,e){const r=await this.execRetrieve({ids:ln(t),...e});if(Array.isArray(t))return r;if(r.length===0)throw new pe(`No resource found with ID ${t.toString()}`);return r[0]}async page(t,e,r){return await this.execRetrieve({offset:t,limit:e,...r})}async retrieveChildren(t,e){return await this.execRetrieve({ids:ln(t),children:!0,...e})}async retrieveParents(t,e){return await this.execRetrieve({ids:ln(t),parents:!0,...e})}async addChildren(t,...e){return await this.writer.addChildren(t,...e)}async removeChildren(t,...e){return await this.writer.removeChildren(t,...e)}async moveChildren(t,e,...r){return await this.writer.moveChildren(t,e,...r)}async openChangeTracker(){return await rs.open(this.framer,this)}newSearcherWithOptions(t){return{type:this.type,search:e=>this.search(e,t),retrieve:e=>this.retrieve(e,t),page:(e,r)=>this.page(e,r,t)}}async execRetrieve(t){const{resources:e}=await v(this.client,kd,t,xd,Cd);return e}};const ii="sy_ontology_resource_set",ai="sy_ontology_resource_delete",oi="sy_ontology_relationship_set",ci="sy_ontology_relationship_delete";class rs{constructor(e,r){l(this,"resourceObs"),l(this,"relationshipObs"),l(this,"relationships"),l(this,"resources"),l(this,"streamer"),l(this,"client"),l(this,"closePromise"),this.relationshipObs=new Rn.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Rn.Observer,this.resources=this.resourceObs,this.client=r,this.streamer=e,this.closePromise=this.start()}async close(){this.streamer.close(),await this.closePromise}async start(){for await(const e of this.streamer)await this.update(e)}async update(e){const r=await this.parseResourceSets(e),n=this.parseResourceDeletes(e);r.concat(n).length>0&&this.resourceObs.notify(r.concat(n));const i=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);i.concat(a).length>0&&this.relationshipObs.notify(i.concat(a))}parseRelationshipSets(e){const r=e.get(oi);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"set",key:ni(n),value:void 0}))}parseRelationshipDeletes(e){const r=e.get(ci);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:ni(n)}))}async parseResourceSets(e){const r=e.get(ii);if(r.length===0)return[];const n=Array.from(r.as("string")).map(i=>new me(i));try{return(await this.client.retrieve(n)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof pe)return[];throw i}}parseResourceDeletes(e){const r=e.get(ai);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:new me(n)}))}static async open(e,r){const n=await e.openStreamer([ii,ai,oi,ci]);return new rs(n,r)}}class Ha{constructor({dataType:e,rate:r,name:n,leaseholder:i=0,key:a=0,isIndex:o=!1,index:c=0,internal:u=!1,frameClient:d,alias:f}){l(this,"_frameClient"),l(this,"key"),l(this,"name"),l(this,"rate"),l(this,"dataType"),l(this,"leaseholder"),l(this,"index"),l(this,"isIndex"),l(this,"internal"),l(this,"alias"),this.key=a,this.name=n,this.rate=new Xn(r??0),this.dataType=new A(e),this.leaseholder=i,this.index=c,this.isIndex=o,this.internal=u,this.alias=f,this._frameClient=d??null}get framer(){if(this._frameClient==null)throw new G("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Dt.parse({key:this.key,name:this.name,rate:this.rate.valueOf(),dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal})}get ontologyID(){return new me({type:"channel",key:this.key.toString()})}async read(e){return await this.framer.read(e,this.key)}async write(e,r){return await this.framer.write(e,this.key,r)}}const $d="/channel/retrieve-group",jd=s.z.object({}),Md=s.z.object({group:Va});let Xa=class{constructor(t,e,r,n){l(this,"type","channel"),l(this,"frameClient"),l(this,"client"),l(this,"retriever"),l(this,"writer"),this.frameClient=t,this.retriever=e,this.client=r,this.writer=n}async create(t,e={}){const{retrieveIfNameExists:r=!1}=e,n=!Array.isArray(t);let i=N(t),a=[];if(r){const o=await this.retriever.retrieve(i.map(u=>u.name)),c=new Set(o.map(u=>u.name));i=i.filter(u=>!c.has(u.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(i))),n?a[0]:a}async retrieve(t,e){const r=!Array.isArray(t),n=this.sugar(await this.retriever.retrieve(t,e));return qr("channel",t,n,r),r?n[0]:n}async search(t,e){return this.sugar(await this.retriever.search(t,e))}async delete(t){const{normalized:e,variant:r}=$e(t);return r==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(t,e){return await this.writer.rename(N(t),N(e))}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,r)=>await this.page(e,r,t)}}async page(t,e,r){return this.sugar(await this.retriever.page(t,e,r))}createDebouncedBatchRetriever(t=10){return new ts(new Wa(new es(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(r=>new Ha({...r,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,$d,{},jd,Md);return new Za(t.group.name,t.group.key)}};const Dd=s.z.object({channels:Na.array()}),Pd=s.z.object({channels:Dt.array()}),Bd=s.z.object({keys:Pe.array().optional(),names:s.z.string().array().optional()}),Ud=s.z.object({}),Ld=s.z.object({keys:Pe.array(),names:s.z.string().array()}),Yd=s.z.object({}),qd="/channel/create",Fd="/channel/delete",_d="/channel/rename";let Qa=class{constructor(t,e){l(this,"client"),l(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,qd,{channels:t},Dd,Pd);return this.cache.set(e),e}async delete(t){await v(this.client,Fd,t,Bd,Ud),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,_d,{keys:t,names:e},Ld,Yd),this.cache.rename(t,e)}};const Wd=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:ts,Channel:Ha,Client:Xa,ClusterRetriever:es,DebouncedBatchRetriever:Wa,Writer:Qa,analyzeChannelParams:$e,keyZ:Pe,newPayload:Na,payload:Dt,retrieveRequired:Ga},Symbol.toStringTag,{value:"Module"})),Gd=s.z.object({key:s.z.string(),username:s.z.string()}),Zd=s.z.object({username:s.z.string(),password:s.z.string()}),Vd=s.z.object({token:s.z.string(),user:Gd}),li="/auth/login",Kd=3;let Jd=class{constructor(t,e){l(this,"token"),l(this,"client"),l(this,"credentials"),l(this,"authenticating"),l(this,"authenticated"),l(this,"user"),l(this,"retryCount"),this.client=t,this.authenticated=!1,this.credentials=e,this.retryCount=0}middleware(){const t=async(e,r)=>{if(!this.authenticated&&!e.target.endsWith(li)){this.authenticating==null&&(this.authenticating=new Promise((o,c)=>{this.client.send(li,this.credentials,Zd,Vd).then(([u,d])=>{if(d!=null)return o(d);this.token=u==null?void 0:u.token,this.user=u==null?void 0:u.user,this.authenticated=!0,o(null)}).catch(c)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[n,i]=await r(e);return xn.matches(i)&&this.retryCount<Kd?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,r)):(this.retryCount=0,[n,i])};return t}};const Hd=["disconnected","connecting","connected","failed"],Xd=s.z.enum(Hd),Qd=s.z.object({status:Xd,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string()}),ef=s.z.object({clusterKey:s.z.string()}),eo={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected"},Sr=class to{constructor(e,r=I.seconds(30),n){l(this,"_state"),l(this,"pollFrequency",I.seconds(30)),l(this,"client"),l(this,"name"),l(this,"interval"),l(this,"onChangeHandlers",[]),this._state={...eo},this.client=e,this.pollFrequency=r,this.name=n,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const r=this._state.status;try{const[n,i]=await this.client.send(to.ENDPOINT,{},s.z.object({}),ef);if(i!=null)throw i;this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=n.clusterKey}catch(n){this._state.status="failed",this._state.error=n,this._state.message=(e=this.state.error)==null?void 0:e.message}return this.onChangeHandlers.length>0&&r!==this._state.status&&this.onChangeHandlers.forEach(n=>n(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};l(Sr,"ENDPOINT","/connectivity/check"),l(Sr,"DEFAULT",eo),l(Sr,"connectionStateZ",Qd);let ro=Sr;const tf=s.z.object({keys:Pe.array().optional(),names:s.z.string().array().optional(),bounds:oe.z}),rf=s.z.object({}),nf="/frame/delete";class sf{constructor(e){l(this,"client"),this.client=e}async delete(e){await v(this.client,nf,e,tf,rf)}}const ui=t=>{const e=N(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},hi=(t,e)=>{const r=N(t);if(r.length===e.length)return;const n=ui(t);throw ui===null?new G("[Frame] - channel keys or names must be provided when constructing a frame."):new G(`[Frame] - ${n}s and arrays must be the same length.
34
- Got ${r.length} ${n}s and ${e.length} arrays.`)};let ye=class Ve{constructor(e=[],r=[]){if(l(this,"columns",[]),l(this,"series",[]),e instanceof Ve){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((n,i)=>this.push(i,...N(n)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const n=e,i=n.series.map(a=>so(a));hi(n.keys,i),n.keys.forEach((a,o)=>this.push(a,i[o]))}else Object.entries(e).forEach(([n,i])=>{const a=parseInt(n);if(isNaN(a))this.push(n,...N(i));else return this.push(a,...N(i))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const n=N(r),i=N(e);hi(i,n),n.forEach((a,o)=>this.push(i[o],a));return}throw new G(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
35
- payload, a list of lazy arrays, a lazy array, a map, or a record keyed by channel
36
- name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new ge("colType is not key");return this.columns??[]}get uniqueKeys(){return ri(this.keys)}get names(){if(this.colType==="key")throw new ge("colType is not name");return this.columns??[]}get uniqueNames(){return ri(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>io(e)),keys:this.keys}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(r=>r.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return oe.ZERO;const n=E.min(...this.series.map(a=>a.timeRange.start)),i=E.max(...this.series.map(a=>a.timeRange.end));return new oe(n,i)}const r=this.get(e);return r==null?oe.ZERO:r.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(r=>e.includes(r)):new Uh(this.series.filter((r,n)=>this.columns[n]===e))}push(e,...r){if(e instanceof Ve){if(this.colType!==null&&e.colType!==this.colType)throw new G("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...r),typeof e=="string"&&this.colType==="key")throw new G("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new G("keyVariant must match");this.columns.push(...Array.from({length:r.length},()=>e))}}concat(e){return new Ve([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const r=new Ve;return this.forEach((n,i,a)=>r.push(...e(n,i,a))),r}forEach(e){this.columns.forEach((r,n)=>{const i=this.series[n];e(r,i,n)})}at(e,r=!1){const n={};return this.uniqueColumns.forEach(i=>{n[i]=this.get(i).at(e,r)}),n}filter(e){const r=new Ve;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&r.push(n,a)}),r}get byteLength(){return new It(this.series.reduce((e,r)=>e.add(r.byteLength),It.ZERO))}get length(){return this.series.reduce((e,r)=>e+r.length,0)}};const no=s.z.object({timeRange:oe.z.optional(),alignment:s.z.bigint().or(s.z.string().transform(t=>BigInt(t))).optional(),dataType:A.z,data:s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer)}),Fr=s.z.object({keys:s.z.union([s.z.null().transform(()=>[]),s.z.number().array().optional().default([])]),series:s.z.union([s.z.null().transform(()=>[]),no.array().optional().default([])])}),so=t=>{const{dataType:e,data:r,timeRange:n,alignment:i}=t;return new Fe({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},io=t=>({timeRange:t._timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});class _r{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,r){const n=new _r(e);return await n.update(r),n}async update(e){const{variant:r,normalized:n}=$e(e);if(r==="keys"){this.adapter=null,this.keys=n;return}const i=await this.retriever.retrieve(n),a=new Map;this.adapter=a,n.forEach(o=>{const c=i.find(u=>u.name===o);if(c==null)throw new Error(`Channel ${o} not found`);a.set(c.key,c.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const r=this.adapter;return e.map((n,i)=>{if(typeof n=="number"){const a=r.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,i]}return[n,i]})}}class ns{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,r){const n=new ns(e);return await n.update(r),n}async update(e){const r=await Ga(this.retriever,e);this.adapter=new Map(r.map(n=>[n.name,n.key])),this.keys=r.map(n=>n.key)}async fetchChannel(e){const r=await this.retriever.retrieve(e);if(r.length===0)throw new Error(`Channel ${e} not found`);return r[0]}async adapt(e,r){if(typeof e=="string"||typeof e=="number"){if(r==null)throw new G(`
37
- Received a single channel name or key but no series.
38
- `);if(Array.isArray(r)){if(r.some(u=>u instanceof Fe||Array.isArray(u)))throw new G(`
39
- Received a single channel name or key but multiple series.
40
- `);r=r}const o=await this.fetchChannel(e),c=new Fe({data:r,dataType:o.dataType});return new ye(o.key,c)}if(Array.isArray(e)){if(r==null)throw new G(`
41
- Received an array of channel names or keys but no series.
42
- `);if(!Array.isArray(r))throw new G(`
43
- Received an array of channel names or keys but no array of series.
44
- `);const o=[],c=[];for(let u=0;u<e.length;u++){const d=await this.fetchChannel(e[u]);if(u>=r.length)throw new G(`
45
- Received an array of channel names or keys but not enough series.
46
- `);const f=new Fe({data:r[u],dataType:d.dataType});o.push(d.key),c.push(f)}return new ye(o,c)}if(e instanceof ye||e instanceof Map){const o=new ye(e);if(this.adapter==null)return o;let c=[];return c=o.columns.map(u=>{var d;const f=typeof u=="string"?(d=this.adapter)==null?void 0:d.get(u):u;if(f==null)throw new G(`
47
- Channel ${u} was not provided in the list of channels when opening the writer
48
- `);return f}),new ye(c,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],d=await this.fetchChannel(c),f=new Fe({data:u,dataType:d.dataType});n.push(d.key),i.push(f)}return new ye(n,i)}}class ss{constructor(e,r){l(this,"name"),l(this,"stream"),this.stream=r,this.name=e}async receive(){const[e,r]=await this.stream.receive();if(r!=null)throw r;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,r]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on closure.
49
- Please report this error to the Synnax team. ${JSON.stringify(e)}`),r!=null){if(De.matches(r))return;throw r}}}closeSend(){this.stream.closeSend()}send(e){const r=this.stream.send(e);if(r!=null)throw r}}const Mn=new I(-1);var is=(t=>(t[t.Open=0]="Open",t[t.Next=1]="Next",t[t.Prev=2]="Prev",t[t.SeekFirst=3]="SeekFirst",t[t.SeekLast=4]="SeekLast",t[t.SeekLE=5]="SeekLE",t[t.SeekGE=6]="SeekGE",t[t.Valid=7]="Valid",t[t.Error=8]="Error",t))(is||{}),ao=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(ao||{});const af=s.z.object({command:s.z.nativeEnum(is),span:I.z.optional(),bounds:oe.z.optional(),stamp:E.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),of=s.z.object({variant:s.z.nativeEnum(ao),ack:s.z.boolean(),command:s.z.nativeEnum(is),error:Mt.optional().nullable(),frame:Fr.optional()}),oo=class Dn{constructor(e,r){l(this,"stream"),l(this,"adapter"),l(this,"value"),this.stream=new ss("Iterator",e),this.value=new ye,this.adapter=r}static async _open(e,r,n,i,a={}){const o=await _r.open(n,r),c=await i.stream(Dn.ENDPOINT,af,of),u=new Dn(c,o);return await u.execute({command:0,keys:o.keys,bounds:new oe(e),chunkSize:a.chunkSize??1e5}),u}async next(e=Mn){return await this.execute({command:1,span:new I(e)})}async prev(e=Mn){return await this.execute({command:2,span:new I(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new E(e)})}async seekGE(e){return await this.execute({command:6,stamp:new E(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new cf(this)}async execute(e){for(this.stream.send(e),this.value=new ye;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new ye(r.frame)))}}};l(oo,"ENDPOINT","/frame/iterate");let co=oo;class cf{constructor(e){l(this,"iter"),l(this,"open",!1),this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const lf=s.z.object({start:E.z.optional(),keys:s.z.number().array()}),uf=s.z.object({frame:Fr,error:Mt.optional().nullable()}),hf="/frame/stream";class Wr{constructor(e,r){l(this,"stream"),l(this,"adapter"),this.stream=new ss("Streamer",e),this.adapter=r}get keys(){return this.adapter.keys}static async _open(e,r,{channels:n,from:i}){const a=await _r.open(e,n),o=await r.stream(hf,lf,uf),c=new Wr(o,a);return o.send({start:new E(i),keys:a.keys}),c}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(De.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new ye((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class Pt extends Rn.Observer{constructor(e,r){super(r),l(this,"streamer"),l(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var as=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.Error=3]="Error",t[t.SetAuthority=4]="SetAuthority",t))(as||{}),At=(t=>(t[t.PersistStream=1]="PersistStream",t[t.PersistOnly=2]="PersistOnly",t[t.StreamOnly=3]="StreamOnly",t))(At||{});const df=new I(-1),ff=s.z.object({start:E.z.optional(),controlSubject:He.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:He.Authority.z.array().optional(),mode:s.z.nativeEnum(At).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:I.z.optional()}),yf=s.z.object({command:s.z.nativeEnum(as),config:ff.optional(),frame:Fr.optional()}),gf=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(as),error:Mt.optional().nullable()});var nt;let lo=(nt=class{constructor(t,e){l(this,"stream"),l(this,"adapter"),this.stream=new ss("Writer",t),this.adapter=e}static async _open(t,e,{channels:r,start:n=E.now(),authorities:i=He.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:c=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:d=I.SECOND}){const f=await ns.open(t,r),h=await e.stream(nt.ENDPOINT,yf,gf),M=new nt(h,f);return await M.execute({command:0,config:{start:new E(n),keys:f.keys,controlSubject:a,authorities:N(i),mode:o,errOnUnauthorized:c,enableAutoCommit:u,autoIndexPersistInterval:d}}),M}async write(t,e){const r=await this.adapter.adapt(t,e);return this.stream.send({command:1,frame:r.toPayload()}),!0}async setAuthority(t){return(await this.execute({command:4,config:{keys:Object.keys(t).map(e=>Number(e)),authorities:Object.values(t)}})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const t=await this.execute({command:3});return t.error!=null?Kn(t.error):null}async close(){await this.stream.closeAndAck()}async execute(t){for(this.stream.send(t);;){const e=await this.stream.receive();if(e.command===t.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},l(nt,"ENDPOINT","/frame/write"),nt),uo=class{constructor(t,e,r){l(this,"streamClient"),l(this,"retriever"),l(this,"deleter"),this.streamClient=t,this.retriever=r,this.deleter=new sf(e)}async openIterator(t,e,r){return await co._open(t,e,this.retriever,this.streamClient,r)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await lo._open(this.retriever,this.streamClient,t)}async openStreamer(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await Wr._open(this.retriever,this.streamClient,t)}async write(t,e,r){if(r==null){const i=e,a=await this.openWriter({start:t,channels:Object.keys(i),mode:At.PersistOnly});try{await a.write(i),await a.commit()}finally{await a.close()}return}const n=await this.openWriter({start:t,channels:e,mode:At.PersistOnly,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});try{await n.write(e,r)}finally{await n.close()}}async read(t,e){const{single:r}=$e(e),n=await this.readFrame(t,e);return r?n.get(e):n}async readFrame(t,e){const r=await this.openIterator(t,e),n=new ye;try{for await(const i of r)n.push(i)}finally{await r.close()}return n}async delete(t,e){const{normalized:r,variant:n}=$e(t);return n==="keys"?await this.deleter.delete({keys:r,bounds:e}):await this.deleter.delete({names:r,bounds:e})}};const pf=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:df,AUTO_SPAN:Mn,Client:uo,Frame:ye,Iterator:co,ObservableStreamer:Pt,Streamer:Wr,Writer:lo,WriterMode:At,frameZ:Fr,series:no,seriesFromPayload:so,seriesToPayload:io},Symbol.toStringTag,{value:"Module"})),mf=He.Authority,wf=He.stateZ(s.z.number()),bf=t=>{var e,r;return t.to==null?`${(e=t.from)==null?void 0:e.resource} - ${(r=t.from)==null?void 0:r.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`};class ho extends Pt{constructor(e){super(e,r=>{const n=this.ecd.decode(r.series[0].buffer);return this.merge(n),[n.transfers,!0]}),l(this,"states"),l(this,"ecd"),this.states=new Map,this.ecd=new Xe.JSONEncoderDecoder}subjects(){const e=new Map;return this.states.forEach(r=>e.set(r.subject.key,r.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(r=>{r.from==null&&r.to==null&&console.warn("Invalid transfer: ",r),r.to==null?this.states.delete(r.from.resource):this.states.set(r.to.resource,r.to)})}}const vf="sy_node_1_control";let fo=class{constructor(t){l(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(vf);return new ho(t)}};const Of=Object.freeze(Object.defineProperty({__proto__:null,Authority:mf,Client:fo,StateTracker:ho,stateZ:wf,transferString:bf},Symbol.toStringTag,{value:"Module"}));let Tf=class{constructor(t,e,r){l(this,"tasks"),l(this,"racks"),l(this,"devices"),this.tasks=t,this.racks=e,this.devices=r}};const Bt=s.z.number(),os=s.z.object({key:Bt,name:s.z.string()}),Sf=os.partial({key:!0}),un="/hardware/rack/retrieve",zf="/hardware/rack/create",Nf="/hardware/rack/delete",hn=s.z.object({keys:Bt.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),dn=s.z.object({racks:Qe(os)}),Ef=s.z.object({racks:Sf.array()}),If=s.z.object({racks:os.array()}),Af=s.z.object({keys:Bt.array()}),kf=s.z.object({});let xf=class{constructor(t,e,r){l(this,"type","rack"),l(this,"client"),l(this,"frameClient"),l(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=r}async delete(t){await v(this.client,Nf,{keys:N(t)},Af,kf)}async create(t){const e=!Array.isArray(t),r=await v(this.client,zf,{racks:N(t)},Ef,If),n=this.sugar(r.racks);return e?n[0]:n}async search(t){const e=await v(this.client,un,{search:t},hn,dn);return this.sugar(e.racks)}async page(t,e){const r=await v(this.client,un,{offset:t,limit:e},hn,dn);return this.sugar(r.racks)}async retrieve(t){const{variant:e,normalized:r,single:n}=Yr(t,{string:"names",number:"keys"}),i=await v(this.client,un,{[e]:r},hn,dn),a=this.sugar(i.racks);return qr("Rack",t,a,n),n?a[0]:a}sugar(t){return t.map(({key:e,name:r})=>new Cf(e,r,this.tasks))}};class Cf{constructor(e,r,n){l(this,"key"),l(this,"name"),l(this,"tasks"),this.key=e,this.name=r,this.tasks=n}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async createTask(e){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e)}async deleteTask(e){await this.tasks.delete([e])}}const Ut=async(t,e,r,n)=>{const i=await t.openStreamer([e,r]),a=o=>{const c=[];return r!=null&&c.push(...o.get(r).series.flatMap(u=>n("delete",u))),e!=null&&c.push(...o.get(e).series.flatMap(u=>n("set",u))),[c,c.length>0]};return new Pt(i,a)},Rf="sy_device_set",$f="sy_device_delete",fn="/hardware/device/retrieve",jf="/hardware/device/create",Mf="/hardware/device/delete",cs=s.z.string(),Gr=s.z.object({key:cs,rack:Bt,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:Xe.JSON_ECD.decodeString(t)))}),Df=Gr.extend({properties:s.z.unknown().transform(t=>Xe.JSON_ECD.encodeString(t))}),Pf=s.z.object({devices:Df.array()}),Bf=s.z.object({devices:Gr.array()}),Uf=s.z.object({keys:cs.array()}),Lf=s.z.object({}),yn=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:cs.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),gn=s.z.object({devices:Qe(Gr)});let Yf=class{constructor(t,e){l(this,"type","device"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const r=!Array.isArray(t),n=await v(this.client,fn,{keys:N(t),...e},yn,gn);return qr("Device",t,n.devices,r),r?n.devices[0]:n.devices}async search(t,e){return(await v(this.client,fn,{search:t,...e},yn,gn)).devices}async page(t,e,r){return(await v(this.client,fn,{offset:t,limit:e,...r},yn,gn)).devices}async create(t){const e=!Array.isArray(t),r=await v(this.client,jf,{devices:N(t)},Pf,Bf);return e?r.devices[0]:r.devices}async delete(t){await v(this.client,Mf,{keys:N(t)},Uf,Lf)}async openDeviceTracker(){return await Ut(this.frameClient,Rf,$f,qf)}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,r)=>await this.page(e,r,t)}}};const qf=(t,e)=>t==="delete"?e.toStrings().map(r=>({variant:t,key:r,value:void 0})):e.parseJSON(Gr).map(r=>({variant:t,key:r.key,value:r})),zt="sy_task_state",di="sy_task_cmd",Lt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),$r=s.z.object({task:Lt,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t))).or(s.z.array(s.z.unknown())).or(s.z.null())}),ls=s.z.object({key:Lt,name:s.z.string(),type:s.z.string(),internal:s.z.boolean().optional(),config:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:Xe.JSON_ECD.decodeString(t))),state:$r.optional().nullable()}),Ff=ls.omit({key:!0}).extend({key:Lt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>Xe.JSON_ECD.encodeString(t))});s.z.object({task:Lt,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t)))});class _f{constructor(e,r,n,i,a,o=!1,c){l(this,"key"),l(this,"name"),l(this,"internal"),l(this,"type"),l(this,"config"),l(this,"state"),l(this,"frameClient"),this.key=e,this.name=r,this.type=n,this.config=i,this.internal=o,c!==null&&(this.state=c),this.frameClient=a}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}async executeCommand(e,r){const n=await this.frameClient.openWriter(di),i=$h.id();return await n.write(di,[{task:this.key,type:e,key:i,args:r}]),await n.close(),i}async executeCommandSync(e,r,n){const i=await this.frameClient.openStreamer(zt),a=await this.executeCommand(e,r);let o;const c=new Promise(u=>setTimeout(()=>u(!1),new I(n).milliseconds));for(;;){const u=await Promise.any([i.read(),c]);if(u===!1)throw new Error("Command timed out");const d=$r.safeParse(u.at(-1).sy_task_state);if(d.success){if(o=d.data,o.key===a)break}else console.error(d.error)}return i.close(),o}async openStateObserver(){return new Pt(await this.frameClient.openStreamer(zt),e=>{const r=e.get(zt);if(r.length===0)return[null,!1];const n=$r.safeParse(r.at(-1));if(!n.success)return[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}}const Wf=s.z.object({rack:Bt.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),Gf=s.z.object({tasks:Qe(ls)}),Zf="/hardware/task/retrieve",Vf="/hardware/task/create",Kf="/hardware/task/delete",Jf=s.z.object({tasks:Ff.array()}),Hf=s.z.object({tasks:ls.array()}),Xf=s.z.object({keys:Lt.array()}),Qf=s.z.object({});let ey=class{constructor(t,e){l(this,"type","task"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async create(t){const e=!Array.isArray(t),r=await v(this.client,Vf,{tasks:N(t)},Jf,Hf),n=this.sugar(r.tasks);return e?n[0]:n}async delete(t){await v(this.client,Kf,{keys:N(t)},Xf,Qf)}async search(t){return await this.execRetrieve({keys:[t]})}async page(t,e){return await this.execRetrieve({offset:t,limit:e})}async list(t={}){return this.sugar(await this.execRetrieve(t))}async retrieve(t,e){const{single:r,normalized:n,variant:i}=Yr(t,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};i==="rack"?a.rack=t:a.keys=n;const o=await this.execRetrieve(a),c=this.sugar(o);return r&&i!=="rack"?c[0]:c}async retrieveByName(t,e){const r=await this.execRetrieve({names:[t],rack:e});return qr("Task",t,r,!0),this.sugar(r)[0]}async execRetrieve(t){return(await v(this.client,Zf,t,Wf,Gf)).tasks}sugar(t){return t.map(({key:e,name:r,type:n,config:i,state:a,internal:o})=>new _f(e,r,n,i,this.frameClient,o,a))}async openTracker(){return await Ut(this.frameClient,"sy_task_set","sy_task_delete",(t,e)=>Array.from(e).map(r=>({variant:t,key:r.toString(),value:r.toString()})))}async openStateObserver(){return new Pt(await this.frameClient.openStreamer(zt),t=>{const e=t.get(zt);if(e.length===0)return[null,!1];const r=$r.safeParse(e.at(-1));return r.success?[r.data,!0]:[null,!1]})}};const Yt=s.z.string().uuid(),Zr=s.z.object({key:Yt,name:s.z.string().min(1),color:s.z.string()}),ty=s.z.object({keys:Yt.array().optional(),for:Ee.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),ry=s.z.object({labels:Zr.array().optional().default([])});var Kt;let ny=(Kt=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return await this.execute({keys:e})}async retrieveFor(t){return await this.execute({for:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){const[e,r]=await this.client.send(Kt.ENDPOINT,t,ty,ry);if(r!=null)throw r;return e.labels}},l(Kt,"ENDPOINT","/label/retrieve"),Kt);const sy=Zr.extend({key:Yt.optional()}),iy=s.z.object({labels:sy.array()}),ay=s.z.object({labels:Zr.array()}),oy=s.z.object({keys:Yt.array()}),yo=s.z.object({id:Ee,labels:Yt.array()}),cy=yo,pn=s.z.object({}),ly="/label/create",uy="/label/delete",hy="/label/set",dy="/label/remove";let fy=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,ly,{labels:N(t)},iy,ay)).labels}async delete(t){await v(this.client,uy,{keys:N(t)},oy,pn)}async set(t,e){await v(this.client,hy,{id:t,labels:e},yo,pn)}async remove(t,e){await v(this.client,dy,{id:t,labels:e},cy,pn)}};const yy="sy_label_set",gy="sy_label_delete";let py=class{constructor(t,e){l(this,"type","label"),l(this,"retriever"),l(this,"writer"),l(this,"frameClient"),this.writer=new fy(t),this.retriever=new ny(t),this.frameClient=e}async search(t){return await this.retriever.search(t)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async retrieveFor(t){return await this.retriever.retrieveFor(t)}async label(t,e){await this.writer.set(t,e)}async removeLabels(t,e){await this.writer.remove(t,e)}async page(t,e){return await this.retriever.page(t,e)}async create(t){const e=Array.isArray(t),r=await this.writer.create(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}async openChangeTracker(){return await Ut(this.frameClient,yy,gy,my)}};const my=(t,e)=>t==="delete"?e.toUUIDs().map(r=>({variant:t,key:r})):e.parseJSON(Zr).map(r=>({variant:t,key:r.key,value:r})),ce=s.z.string().uuid(),et=s.z.object({key:ce,name:s.z.string().min(1),timeRange:oe.z,color:s.z.string().optional()}),go=et.extend({key:s.z.string().uuid().optional()}),po=t=>{const e=N(t);if(e.length===0)throw new Error("Range params must not be empty");const r=ce.safeParse(e[0]).success;return{single:!Array.isArray(t),variant:r?"keys":"names",normalized:e,actual:t}},wy=s.z.object({}),by=s.z.object({range:et}),vy=s.z.object({range:ce}),Oy=s.z.object({range:ce}),Ty=s.z.object({}),Sy="/range/set-active",zy="/range/retrieve-active",Ny="/range/clear-active";class Ey{constructor(e){l(this,"client"),this.client=e}async setActive(e){await v(this.client,Sy,{range:e},vy,wy)}async retrieveActive(){const[e,r]=await this.client.send(zy,{},s.z.object({}),by);if(pe.matches(r))return null;if(r!=null)throw r;return e.range}async clearActive(e){await v(this.client,Ny,{range:e},Oy,Ty)}}const Iy="sy_range_alias_set",Ay="sy_range_alias_delete",ky=s.z.object({range:ce,aliases:s.z.string().array()}),xy=s.z.object({aliases:s.z.record(s.z.string(),Pe)}),Cy=s.z.object({range:ce,aliases:s.z.record(Pe.or(s.z.string()),s.z.string())}),Ry=s.z.unknown(),$y=s.z.object({range:ce,channels:Pe.array()}),jy=s.z.unknown(),My=s.z.object({range:ce}),Dy=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),mt=class wt{constructor(e,r,n){l(this,"frameClient"),l(this,"cache",new Map),l(this,"client"),l(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=r}async resolve(e){const r=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;r.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:r.push(o)});if(r.length===0)return i;const a=await v(this.client,wt.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},ky,xy);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[r[0]]:{...i,...a.aliases}}async set(e){await v(this.client,wt.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Cy,Ry)}async list(){return(await v(this.client,wt.LIST_ENDPOINT,{range:this.rangeKey},My,Dy)).aliases}async delete(e){await v(this.client,wt.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},$y,jy)}async openChangeTracker(){return await Ut(this.frameClient,Iy,Ay,Ly(this.rangeKey))}};l(mt,"SET_ENDPOINT","/range/alias/set"),l(mt,"RESOLVE_ENDPOINT","/range/alias/resolve"),l(mt,"LIST_ENDPOINT","/range/alias/list"),l(mt,"DELETE_ENDPOINT","/range/alias/delete");let Py=mt;const By=s.z.object({range:ce,channel:Pe,alias:s.z.string()}),Uy="---",Ly=t=>(e,r)=>e==="delete"?r.toStrings().filter(n=>n.split(Uy)[0]===t).map(n=>({variant:e,key:n,value:void 0})):r.parseJSON(By).map(n=>({variant:e,key:n.alias,value:n})),Yy=s.z.object({range:ce,keys:s.z.string().array()}),qy=s.z.object({pairs:s.z.record(s.z.string(),s.z.string())}),Fy=s.z.object({range:ce,pairs:s.z.record(s.z.string(),s.z.string())}),_y=s.z.object({range:ce,keys:s.z.string().array()}),zr=class Nr{constructor(e,r){l(this,"rangeKey"),l(this,"client"),this.rangeKey=e,this.client=r}async get(e){const[r,n]=await this.client.send(Nr.GET_ENDPOINT,{range:this.rangeKey,keys:N(e)},Yy,qy);if(n!=null)throw n;return Array.isArray(e)?r.pairs:r.pairs[e]}async list(){return this.get([])}async set(e,r=""){await v(this.client,Nr.SET_ENDPOINT,{range:this.rangeKey,pairs:Jn(e)?e:{[e]:r}},Fy,s.z.unknown())}async delete(e){await v(this.client,Nr.DELETE_ENDPOINT,{range:this.rangeKey,keys:N(e)},_y,s.z.unknown())}};l(zr,"GET_ENDPOINT","/range/kv/get"),l(zr,"SET_ENDPOINT","/range/kv/set"),l(zr,"DELETE_ENDPOINT","/range/kv/delete");let Wy=zr;const mn=t=>new me({type:"range",key:t});class mo{constructor(e,r=oe.ZERO,n,i,a,o,c,u,d){l(this,"key"),l(this,"name"),l(this,"kv"),l(this,"timeRange"),l(this,"color"),l(this,"channels"),l(this,"aliaser"),l(this,"frameClient"),l(this,"labelClient"),this.key=n,this.name=e,this.timeRange=r,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=c,this.channels=u,this.labelClient=d}async setAlias(e,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new pe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:r})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async openAliasTracker(){return await this.aliaser.openChangeTracker()}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(mn(this.key))}async addLabel(...e){await this.labelClient.label(mn(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(mn(this.key),e)}}const Gy=s.z.object({keys:ce.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:oe.z.optional()}),Zy="/range/retrieve",Vy=s.z.object({ranges:Qe(et)});let wo=class{constructor(t,e,r,n,i){l(this,"type","range"),l(this,"frameClient"),l(this,"writer"),l(this,"unaryClient"),l(this,"channels"),l(this,"active"),l(this,"labelClient"),this.frameClient=t,this.writer=e,this.unaryClient=r,this.channels=n,this.active=new Ey(r),this.labelClient=i}async create(t){const e=!Array.isArray(t),r=this.sugar(await this.writer.create(N(t)));return e?r[0]:r}async rename(t,e){await this.writer.rename(t,e)}async delete(t){await this.writer.delete(N(t))}async search(t){return this.sugar(await this.execRetrieve({term:t}))}async page(){return[]}async retrieve(t){if(typeof t=="object"&&"start"in t)return await this.execRetrieve({overlapsWith:new oe(t)});const{single:e,actual:r,variant:n,normalized:i}=po(t),a=await this.execRetrieve({[n]:i});if(!e)return a;if(a.length===0)throw new xr(`range matching ${r} not found`);if(a.length>1)throw new Cr(`multiple ranges matching ${r} found`);return a[0]}async execRetrieve(t){const{ranges:e}=await v(this.unaryClient,Zy,t,Gy,Vy);return this.sugar(e)}async setActive(t){await this.active.setActive(t)}async retrieveActive(){const t=await this.active.retrieveActive();return t==null?null:this.sugar([t])[0]}async clearActive(t){await this.active.clearActive(t)}sugar(t){return t.map(e=>new mo(e.name,e.timeRange,e.key,e.color,this.frameClient,new Wy(e.key,this.unaryClient),new Py(e.key,this.frameClient,this.unaryClient),this.channels,this.labelClient))}async openTracker(){return await Ut(this.frameClient,"sy_range_set","sy_range_delete",(t,e)=>t==="delete"?e.toStrings().map(r=>({variant:t,key:r,value:void 0})):this.sugar(e.parseJSON(et)).map(r=>({variant:t,key:r.key,value:r})))}};const Ky=s.z.object({ranges:et.array()}),Jy=s.z.object({ranges:go.array()}),Hy=s.z.object({keys:ce.array()}),Xy=s.z.object({}),Qy=s.z.object({key:ce,name:s.z.string()}),eg=s.z.object({}),tg="/range/create",rg="/range/delete",ng="/range/rename";let bo=class{constructor(t){l(this,"client"),this.client=t}async rename(t,e){await v(this.client,ng,{key:t,name:e},Qy,eg)}async create(t){return(await v(this.client,tg,{ranges:t},Jy,Ky)).ranges}async delete(t){await v(this.client,rg,{keys:t},Hy,Xy)}};const sg=Object.freeze(Object.defineProperty({__proto__:null,Client:wo,Range:mo,Writer:bo,analyzeParams:po,keyZ:ce,newPayloadZ:go,payloadZ:et},Symbol.toStringTag,{value:"Module"})),ig="/api/v1/";class ag{constructor(e,r=!1){l(this,"url"),l(this,"unary"),l(this,"stream"),l(this,"secure"),this.secure=r,this.url=e.child(ig);const n=new Xe.JSONEncoderDecoder;this.unary=new ju(this.url,n,this.secure),this.stream=new Fu(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const us=s.z.string().uuid(),hs=s.z.object({key:s.z.string(),name:s.z.string(),data:Qn.or(s.z.string().transform(t=>JSON.parse(t)))}),og=s.z.object({keys:s.z.string().array()}),cg=s.z.object({linePlots:hs.array()});let lg=class{constructor(t){l(this,"ENDPOINT","/workspace/lineplot/retrieve"),l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return(await v(this.client,this.ENDPOINT,{keys:e},og,cg)).linePlots}};const Ge=s.z.string().uuid(),vo=t=>JSON.parse(t),Oo=s.z.object({name:s.z.string(),key:Ge,layout:Qn.or(s.z.string().transform(t=>vo(t)))}),To=Oo.omit({layout:!0}).extend({layout:s.z.string().transform(t=>vo(t))}),ug=hs.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),hg=s.z.object({workspace:Ge,linePlots:ug.array()}),dg=s.z.object({linePlots:hs.array()}),fg=s.z.object({keys:us.array()}),yg=s.z.object({}),gg=s.z.object({key:us,name:s.z.string()}),pg=s.z.object({}),mg=s.z.object({key:us,data:s.z.string()}),wg=s.z.object({}),bg="/workspace/lineplot/create",vg="/workspace/lineplot/delete",Og="/workspace/lineplot/rename",Tg="/workspace/lineplot/set-data";let Sg=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,bg,{workspace:t,linePlots:[r]},hg,dg)).linePlots[0]}async delete(t){const e=N(t);await v(this.client,vg,{keys:e},fg,yg)}async rename(t,e){await v(this.client,Og,{key:t,name:e},gg,pg)}async setData(t,e){await v(this.client,Tg,{key:t,data:JSON.stringify(e)},mg,wg)}},zg=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Sg(t),this.retriever=new lg(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}};const Ng=s.z.object({keys:Ge.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Eg=s.z.object({workspaces:Qe(To)});var Jt;let Ig=(Jt=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return await this.execute({keys:e})}async retrieveByAuthor(t){return await this.execute({author:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){return(await v(this.client,Jt.ENDPOINT,t,Ng,Eg)).workspaces}},l(Jt,"ENDPOINT","/workspace/retrieve"),Jt);const Vr=s.z.string().uuid(),Ag=s.z.object({key:s.z.string(),name:s.z.string(),data:Qn.or(s.z.string().transform(t=>JSON.parse(t))),snapshot:s.z.boolean()}),ds=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(t=>JSON.parse(t))}),kg=s.z.object({keys:s.z.string().array()}),xg=s.z.object({schematics:ds.array()});class Cg{constructor(e){l(this,"ENDPOINT","/workspace/schematic/retrieve"),l(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,this.ENDPOINT,{keys:N(e)},kg,xg)).schematics}}const Rg=Ag.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),$g=s.z.object({workspace:Ge,schematics:Rg.array()}),jg=s.z.object({schematics:ds.array()}),Mg=s.z.object({keys:Vr.array()}),Dg=s.z.object({}),Pg=s.z.object({key:Vr,name:s.z.string()}),fi=s.z.object({}),Bg=s.z.object({key:Vr,data:s.z.string()});s.z.object({});const Ug=s.z.object({key:Vr,name:s.z.string(),snapshot:s.z.boolean()}),Lg=s.z.object({schematic:ds}),Yg="/workspace/schematic/create",qg="/workspace/schematic/delete",Fg="/workspace/schematic/rename",_g="/workspace/schematic/set-data",Wg="/workspace/schematic/copy";let Gg=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,Yg,{workspace:t,schematics:[r]},$g,jg)).schematics[0]}async copy(t,e,r){return(await v(this.client,Wg,{key:t,name:e,snapshot:r},Ug,Lg)).schematic}async delete(t){const e=N(t);await v(this.client,qg,{keys:e},Mg,Dg)}async rename(t,e){await v(this.client,Fg,{key:t,name:e},Pg,fi)}async setData(t,e){await v(this.client,_g,{key:t,data:JSON.stringify(e)},Bg,fi)}},Zg=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Gg(t),this.retriever=new Cg(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}async copy(t,e,r){return await this.writer.copy(t,e,r)}};const Vg=Oo.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),Kg=s.z.object({workspaces:Vg.array()}),Jg=s.z.object({workspaces:To.array()}),Hg=s.z.object({keys:Ge.array()}),Xg=s.z.object({}),Qg=s.z.object({key:Ge,name:s.z.string()}),ep=s.z.object({}),tp=s.z.object({key:Ge,layout:s.z.string()}),rp=s.z.object({}),np="/workspace/create",sp="/workspace/delete",ip="/workspace/rename",ap="/workspace/set-layout";class op{constructor(e){l(this,"client"),this.client=e}async create(e){return(await v(this.client,np,{workspaces:N(e)},Kg,Jg)).workspaces}async delete(e){await v(this.client,sp,{keys:N(e)},Hg,Xg)}async rename(e,r){await v(this.client,ip,{key:e,name:r},Qg,ep)}async setLayout(e,r){await v(this.client,ap,{key:e,layout:JSON.stringify(r)},tp,rp)}}class cp{constructor(e){l(this,"type","workspace"),l(this,"schematic"),l(this,"linePlot"),l(this,"retriever"),l(this,"writer"),this.schematic=new Zg(e),this.linePlot=new zg(e),this.retriever=new Ig(e),this.writer=new op(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const r=Array.isArray(e),n=await this.retriever.retrieve(e);return r?n:n[0]}async page(e,r){return await this.retriever.page(e,r)}async create(e){const r=Array.isArray(e),n=await this.writer.create(e);return r?n:n[0]}async rename(e,r){await this.writer.rename(e,r)}async setLayout(e,r){await this.writer.setLayout(e,r)}async delete(...e){await this.writer.delete(e)}}const So=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().optional(),password:s.z.string().optional(),connectivityPollFrequency:I.z.default(I.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class zo extends uo{constructor(e){const r=So.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u}=r,d=new ag(new od({host:n,port:Number(i)}),u);d.use(Jh);let f;if(a!=null&&o!=null){const Wo=new Jd(d.unary,{username:a,password:o});d.use(Wo.middleware())}const h=new ts(new es(d.unary)),M=new Qa(d.unary,h);super(d.stream,d.unary,h),l(this,"createdAt"),l(this,"props"),l(this,"ranges"),l(this,"channels"),l(this,"auth"),l(this,"connectivity"),l(this,"ontology"),l(this,"workspaces"),l(this,"labels"),l(this,"hardware"),l(this,"control"),l(this,"transport"),this.createdAt=E.now(),this.props=r,this.auth=f,this.transport=d,this.channels=new Xa(this,h,d.unary,M),this.connectivity=new ro(d.unary,c,r.name),this.control=new fo(this),this.ontology=new Rd(d.unary,this);const _=new bo(this.transport.unary);this.labels=new py(this.transport.unary,this),this.ranges=new wo(this,_,this.transport.unary,h,this.labels),this.workspaces=new cp(this.transport.unary);const re=new Yf(this.transport.unary,this),R=new ey(this.transport.unary,this),_o=new xf(this.transport.unary,this,R);this.hardware=new Tf(R,_o,re)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}l(zo,"connectivity",ro);const lp=He.Authority,Pn=(t,e,r="")=>{try{return t.parse(e)}catch(n){if(n instanceof s.z.ZodError){const i=n.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${r} - ${i.join(`
50
- `)}`)}else throw n}};var up=Object.defineProperty,hp=(t,e,r)=>e in t?up(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J=(t,e,r)=>hp(t,typeof e!="symbol"?e+"":e,r);const Bn=class No{constructor(e,r,n="",i=!1){J(this,"_noop",!1),J(this,"key"),J(this,"path"),J(this,"serviceName"),this.key=e,this.path=r,this.serviceName=n,this._noop=i}child(e){return new No(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};J(Bn,"NOOP",new Bn("","",""));let fs=Bn;const Un=["debug","info","warn","error"],dp=t=>{const e=Un.indexOf(t);return({level:r})=>Un.indexOf(r)>=e},fp=t=>{const{include:e,exclude:r}=t;return({path:n})=>!(e!=null&&!e.some(i=>n.startsWith(i))||r!=null&&r.some(i=>n.startsWith(i)))},Ln=class Eo{constructor(e={}){J(this,"meta",fs.NOOP),J(this,"filters");const{filters:r=[]}=e;this.filters=r}filter(e){return!this.meta.noop&&this.filters.every(r=>r({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const r=new Eo({filters:this.filters});return r.meta=e,r}debug(e,r,n=!1){!this.filter("debug")&&!n||(r==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,Ht(r)))}info(e,r,n=!1){!this.filter("info")&&!n||(r==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,Ht(r)))}warn(e,r,n=!1){!this.filter("warn")&&!n||(r==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,Ht(r)))}error(e,r,n=!1){!this.filter("error")&&!n||(r==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,Ht(r)))}};J(Ln,"NOOP",new Ln);let Io=Ln;const Ht=t=>typeof t=="function"?t():t;var yp=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},_e="1.8.0",yi=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function gp(t){var e=new Set([t]),r=new Set,n=t.match(yi);if(!n)return function(){return!1};var i={major:+n[1],minor:+n[2],patch:+n[3],prerelease:n[4]};if(i.prerelease!=null)return function(c){return c===t};function a(c){return r.add(c),!1}function o(c){return e.add(c),!0}return function(c){if(e.has(c))return!0;if(r.has(c))return!1;var u=c.match(yi);if(!u)return a(c);var d={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return d.prerelease!=null||i.major!==d.major?a(c):i.major===0?i.minor===d.minor&&i.patch<=d.patch?o(c):a(c):i.minor<=d.minor?o(c):a(c)}}var pp=gp(_e),mp=_e.split(".")[0],kt=Symbol.for("opentelemetry.js.api."+mp),xt=yp;function ys(t,e,r,n){var i;n===void 0&&(n=!1);var a=xt[kt]=(i=xt[kt])!==null&&i!==void 0?i:{version:_e};if(!n&&a[t]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+t);return r.error(o.stack||o.message),!1}if(a.version!==_e){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+t+" does not match previously registered API v"+_e);return r.error(o.stack||o.message),!1}return a[t]=e,r.debug("@opentelemetry/api: Registered a global for "+t+" v"+_e+"."),!0}function Ct(t){var e,r,n=(e=xt[kt])===null||e===void 0?void 0:e.version;if(!(!n||!pp(n)))return(r=xt[kt])===null||r===void 0?void 0:r[t]}function gs(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+_e+".");var r=xt[kt];r&&delete r[t]}var wp=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},bp=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},vp=function(){function t(e){this._namespace=e.namespace||"DiagComponentLogger"}return t.prototype.debug=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return st("debug",this._namespace,e)},t.prototype.error=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return st("error",this._namespace,e)},t.prototype.info=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return st("info",this._namespace,e)},t.prototype.warn=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return st("warn",this._namespace,e)},t.prototype.verbose=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return st("verbose",this._namespace,e)},t}();function st(t,e,r){var n=Ct("diag");if(n)return r.unshift(e),n[t].apply(n,bp([],wp(r),!1))}var de;(function(t){t[t.NONE=0]="NONE",t[t.ERROR=30]="ERROR",t[t.WARN=50]="WARN",t[t.INFO=60]="INFO",t[t.DEBUG=70]="DEBUG",t[t.VERBOSE=80]="VERBOSE",t[t.ALL=9999]="ALL"})(de||(de={}));function Op(t,e){t<de.NONE?t=de.NONE:t>de.ALL&&(t=de.ALL),e=e||{};function r(n,i){var a=e[n];return typeof a=="function"&&t>=i?a.bind(e):function(){}}return{error:r("error",de.ERROR),warn:r("warn",de.WARN),info:r("info",de.INFO),debug:r("debug",de.DEBUG),verbose:r("verbose",de.VERBOSE)}}var Tp=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Sp=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},zp="diag",Rt=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var c=Ct("diag");if(c)return c[i].apply(c,Sp([],Tp(a),!1))}}var r=this,n=function(i,a){var o,c,u;if(a===void 0&&(a={logLevel:de.INFO}),i===r){var d=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return r.error((o=d.stack)!==null&&o!==void 0?o:d.message),!1}typeof a=="number"&&(a={logLevel:a});var f=Ct("diag"),h=Op((c=a.logLevel)!==null&&c!==void 0?c:de.INFO,i);if(f&&!a.suppressOverrideMessage){var M=(u=new Error().stack)!==null&&u!==void 0?u:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+M),h.warn("Current logger will overwrite one already registered from "+M)}return ys("diag",h,r,!0)};r.setLogger=n,r.disable=function(){gs(zp,r)},r.createComponentLogger=function(i){return new vp(i)},r.verbose=e("verbose"),r.debug=e("debug"),r.info=e("info"),r.warn=e("warn"),r.error=e("error")}return t.instance=function(){return this._instance||(this._instance=new t),this._instance},t}(),Np=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Ep=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ip=function(){function t(e){this._entries=e?new Map(e):new Map}return t.prototype.getEntry=function(e){var r=this._entries.get(e);if(r)return Object.assign({},r)},t.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var r=Np(e,2),n=r[0],i=r[1];return[n,i]})},t.prototype.setEntry=function(e,r){var n=new t(this._entries);return n._entries.set(e,r),n},t.prototype.removeEntry=function(e){var r=new t(this._entries);return r._entries.delete(e),r},t.prototype.removeEntries=function(){for(var e,r,n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var a=new t(this._entries);try{for(var o=Ep(n),c=o.next();!c.done;c=o.next()){var u=c.value;a._entries.delete(u)}}catch(d){e={error:d}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();Rt.instance();function Ap(t){return t===void 0&&(t={}),new Ip(new Map(Object.entries(t)))}function kp(t){return Symbol.for(t)}var xp=function(){function t(e){var r=this;r._currentContext=e?new Map(e):new Map,r.getValue=function(n){return r._currentContext.get(n)},r.setValue=function(n,i){var a=new t(r._currentContext);return a._currentContext.set(n,i),a},r.deleteValue=function(n){var i=new t(r._currentContext);return i._currentContext.delete(n),i}}return t}(),Cp=new xp,Rp={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},$p={set:function(t,e,r){t!=null&&(t[e]=r)}},jp=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Mp=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},Dp=function(){function t(){}return t.prototype.active=function(){return Cp},t.prototype.with=function(e,r,n){for(var i=[],a=3;a<arguments.length;a++)i[a-3]=arguments[a];return r.call.apply(r,Mp([n],jp(i),!1))},t.prototype.bind=function(e,r){return r},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),Pp=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Bp=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},wn="context",Up=new Dp,Ao=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ys(wn,e,Rt.instance())},t.prototype.active=function(){return this._getContextManager().active()},t.prototype.with=function(e,r,n){for(var i,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(i=this._getContextManager()).with.apply(i,Bp([e,r,n],Pp(a),!1))},t.prototype.bind=function(e,r){return this._getContextManager().bind(e,r)},t.prototype._getContextManager=function(){return Ct(wn)||Up},t.prototype.disable=function(){this._getContextManager().disable(),gs(wn,Rt.instance())},t}(),Yn;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(Yn||(Yn={}));var Lp=Ao.getInstance(),Yp=function(){function t(){}return t.prototype.inject=function(e,r){},t.prototype.extract=function(e,r){return e},t.prototype.fields=function(){return[]},t}(),ps=kp("OpenTelemetry Baggage Key");function ko(t){return t.getValue(ps)||void 0}function qp(){return ko(Ao.getInstance().active())}function Fp(t,e){return t.setValue(ps,e)}function _p(t){return t.deleteValue(ps)}var bn="propagation",Wp=new Yp,Gp=function(){function t(){this.createBaggage=Ap,this.getBaggage=ko,this.getActiveBaggage=qp,this.setBaggage=Fp,this.deleteBaggage=_p}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ys(bn,e,Rt.instance())},t.prototype.inject=function(e,r,n){return n===void 0&&(n=$p),this._getGlobalPropagator().inject(e,r,n)},t.prototype.extract=function(e,r,n){return n===void 0&&(n=Rp),this._getGlobalPropagator().extract(e,r,n)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){gs(bn,Rt.instance())},t.prototype._getGlobalPropagator=function(){return Ct(bn)||Wp},t}(),Zp=Gp.getInstance();const gi=["bench","debug","prod"],Vp=t=>e=>gi.indexOf(e)>=gi.indexOf(t),qn=class xo{constructor(e,r=Vp("debug")){J(this,"meta",fs.NOOP),J(this,"tracer"),J(this,"filter"),this.tracer=e,this.filter=r}child(e){const r=new xo(this.tracer,this.filter);return r.meta=e,r}debug(e,r){return this.trace(e,"debug",r)}bench(e,r){return this.trace(e,"bench",r)}prod(e,r){return this.trace(e,"prod",r)}trace(e,r,n){return this.meta.noop||!this.filter(r)?n(new $o(e)):this.tracer.startActiveSpan(e,i=>{const a=new Ro(e,i),o=n(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const r=Lp.active();Zp.inject(r,e,{set:(n,i,a)=>{n[i]=a}})}};J(qn,"NOOP",new qn);let Co=qn;class Ro{constructor(e,r){J(this,"key"),J(this,"otel"),this.key=e,this.otel=r}set(e,r){this.otel.setAttribute(e,r)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:Yn.ERROR}))}}class $o{constructor(e){J(this,"key"),this.key=e}set(){}recordError(e){}}const Fn=class jo{constructor({key:e="",serviceName:r="",logger:n=Io.NOOP,tracer:i=Co.NOOP,noop:a=!1,__meta:o}){J(this,"meta"),J(this,"T"),J(this,"L"),this.meta=o??new fs(e,e,r,a),this.T=i.child(this.meta),this.L=n.child(this.meta)}child(e){const r=this.meta.child(e);return new jo({__meta:r,tracer:this.T,logger:this.L})}};J(Fn,"NOOP",new Fn({noop:!0}));let ms=Fn;const Kp=ms.NOOP,Mo=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:ms,LOG_LEVELS:Un,Logger:Io,NOOP:Kp,NoopSpan:$o,Tracer:Co,_Span:Ro,logLevelKeyFiler:fp,logThresholdFilter:dp},Symbol.toStringTag,{value:"Module"})),Jp=new Error("request for lock canceled");var Hp=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class Xp{constructor(e,r=Jp){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:r},o=Do(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Hp(this,arguments,void 0,function*(r,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Qp(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function Qp(t,e){const r=Do(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function Do(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var em=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class Po{constructor(e){this._semaphore=new Xp(1,e)}acquire(){return em(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}class Kr{constructor(e,r,n=new Map){D(this,"providers");D(this,"registry");D(this,"sender");D(this,"changedKeys");this.providers=n,this.registry=r,this.changedKeys=[],this.sender=e}propagateState(e,r,n=[]){this.sender.send({key:e,state:r},n)}copyAndMerge(e){const r=new Kr(this.sender,this.registry,new Map);return e==null||e.providers.forEach((n,i)=>r.providers.set(i,n)),this.providers.forEach((n,i)=>r.providers.set(i,n)),r.changedKeys=[],r}get changed(){return this.changedKeys.length>0}set(e,r,n=!0){this.providers.set(e,r),n&&this.changedKeys.push(e)}setIfNotHas(e,r){this.providers.has(e)||this.set(e,r)}async create(e){const r=this.registry[e.type];if(r==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const n=new r(e);return await n.internalUpdate(e),n}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const r=this.getOptional(e);if(r==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return r}}class ws{constructor(e){D(this,"type");D(this,"key");D(this,"_ctx");D(this,"_internalState");D(this,"_state");D(this,"_prevState");D(this,"_deleted",!1);D(this,"instrumentation");D(this,"schema");this.type=e.type,this.key=e.path[0],this._ctx=e.ctx,this._internalState={},this.instrumentation=e.instrumentation.child(`${this.type}(${this.key})`)}get _schema(){if(this.schema==null)throw new G(`[AetherLeaf] - expected subclass to define component schema, but none was found.
51
- Make sure to defne a property 'schema' on the class.`);return this.schema}setState(e){const r=Zn(e,this._state);this._prevState={...this._state},this._state=Pn(this._schema,r,`${this.type}:${this.key}`),this.ctx.propagateState(this.key,r)}get ctx(){if(this._ctx==null)throw new ge("context not defined");return this._ctx}get state(){if(this._state==null)throw new ge("state not defined");return this._state}get internal(){return this._internalState}get prevState(){return this._prevState}get deleted(){return this._deleted}async internalUpdate({variant:e,path:r,ctx:n,state:i}){if(!this.deleted){if(this._ctx=n,e==="state"){this.validatePath(r);const a=Pn(this._schema,i,`${this.type}:${this.key}`);this._state!=null?this.instrumentation.L.debug("updating state",()=>({diff:vi.difference(this.state,a)})):this.instrumentation.L.debug("setting initial state",{state:i}),this._prevState=this._state??a,this._state=a}else this.instrumentation.L.debug("updating context");await this.afterUpdate()}}async internalDelete(e){this.validatePath(e),this._deleted=!0,await this.afterDelete()}beforeUpdate(){}async afterUpdate(){}async afterDelete(){}validatePath(e){if(e.length===0)throw new ge(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const r=e[e.length-1];if(e.length>1)throw new ge(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(r!==this.key)throw new ge(`[Leaf.setState] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`)}}class qt extends ws{constructor(r){super(r);D(this,"_children");this._children=new Map}get children(){return Array.from(this._children.values())}async internalUpdate(r){const{variant:n,path:i}=r;if(n==="context")return this._ctx=r.ctx.copyAndMerge(this._ctx),await this.updateContext({...r,ctx:this.ctx});const[a,o]=this.getRequiredKey(i),c={...r,ctx:this.ctx};return o.length===0?await this.updateThis(a,c):await this.updateChild(o,c)}async updateContext(r){await super.internalUpdate(r);for(const n of this.children)await n.internalUpdate({...r,ctx:this.ctx,variant:"context"})}async updateChild(r,n){const i=r[0],a=this.getChild(i);if(a!=null)return await a.internalUpdate({...n,path:r});if(r.length>1)throw new Error(`[Composite.setState] - ${this.type}:${this.key} could not find child with key ${i} while updating `);this._children.set(i,await n.ctx.create({...n,path:r}))}async updateThis(r,n){const i=n.ctx.copyAndMerge(this._ctx);if(r!==this.key)throw new ge(`[Composite.update] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`);if(await super.internalUpdate({...n,ctx:i}),!!i.changed){this.instrumentation.L.debug("context changed",{changedKeys:i.changedKeys});for(const a of this.children)await a.internalUpdate({...n,ctx:this.ctx,variant:"context"})}}async internalDelete(r){const[n,i]=this.getRequiredKey(r);if(i.length===0){if(n!==this.key)throw new Error(`[Composite.delete] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`);const o=this.children;this._children=new Map;for(const c of o)await c.internalDelete([c.key]);await super.internalDelete([this.key])}const a=this.getChild(i[0]);a!=null&&(i.length>1?await a.internalDelete(i):(this._children.delete(a.key),await a.internalDelete(i)))}getRequiredKey(r,n){const[i,...a]=r;if(i==null)throw new Error(`Composite ${this.type}:${this.key} received an empty path`+(n!=null?` for ${n}`:""));return[i,a]}getChild(r){return this._children.get(r)??null}childrenOfType(...r){return this.children.filter(n=>r.includes(n.type))}}const tm=s.z.object({}),Ne=class Ne extends qt{constructor({worker:r,registry:n,instrumentation:i=Mo.Instrumentation.NOOP}){const o={ctx:new Kr(r,n,new Map),...Ne.ZERO_UPDATE,instrumentation:i};super(o);D(this,"wrap");D(this,"schema",Ne.schema);D(this,"mu",new Po);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=r,this.wrap.handle(c=>{this.mu.runExclusive(async()=>await this.handle(c))})}async handle(r){if(r.variant==="delete")await this.internalDelete(r.path);else{const n={...r,variant:"state",ctx:this.ctx,instrumentation:this.instrumentation};await this.internalUpdate(n)}}};D(Ne,"TYPE","root"),D(Ne,"KEY","root"),D(Ne,"ZERO_UPDATE",{path:[Ne.KEY],type:Ne.TYPE,variant:"state",state:{}}),D(Ne,"schema",tm);let jr=Ne;const Bo=t=>new jr(t),rm=Object.freeze(Object.defineProperty({__proto__:null,Composite:qt,Context:Kr,Leaf:ws,Root:jr,render:Bo},Symbol.toStringTag,{value:"Module"})),Uo="pluto-theming-context",nm=s.z.object({theme:Pi}),Nt=class Nt extends qt{constructor(){super(...arguments);D(this,"schema",Nt.z)}async afterUpdate(){this.ctx.set(Uo,this.state.theme)}};D(Nt,"TYPE","theming.Provider"),D(Nt,"z",nm);let $t=Nt;const sm=t=>t.get(Uo),im={[$t.TYPE]:$t},Lo=["success","error","warning","info","loading","disabled","secondary"],Yo=s.z.enum(Lo),qo=s.z.object({key:s.z.string(),variant:Yo,message:s.z.string(),description:s.z.string().optional(),time:F.z,data:s.z.record(s.z.unknown()).optional()}),Fo=s.z.object({statuses:qo.array()}),bs="status.aggregator";class Mr extends qt{constructor(){super(...arguments);D(this,"schema",Fo)}async afterUpdate(){this.ctx.set(bs,this)}add(r){const n=F.now();this.setState(i=>({...i,statuses:[...i.statuses,{time:n,key:n.toString(),...r}]}))}}D(Mr,"TYPE","status.Aggregator");const am=t=>{const e=t.get(bs);return e.add.bind(e)},om=t=>{const e=t.getOptional(bs);return e!=null?e.add.bind(e):()=>{}},cm={[Mr.TYPE]:Mr};exports.$=Ac;exports.A=Yc;exports.Aggregator=Mr;exports.B=ms;exports.C=ol;exports.C$1=Pr;exports.ComponentSizeLevels=Di;exports.Composite=qt;exports.Cy=lp;exports.E=hc;exports.Ee=ge;exports.G=il;exports.I=ae;exports.Ie=Fe;exports.L=al;exports.LEVELS=Mi;exports.Leaf=ws;exports.LevelComponentSizes=hl;exports.Mh=So;exports.Mutex=Po;exports.N=zi;exports.N$1=nl;exports.Ny=sg;exports.O=E;exports.P=G;exports.Provider=$t;exports.REGISTRY=im;exports.REGISTRY$1=cm;exports.S=I;exports.S$1=rc;exports.SYNNAX_DARK=Ui;exports.SYNNAX_LIGHT=Bi;exports.SYNNAX_THEMES=vl;exports.U=Et;exports.V=oe;exports.VARIANTS=Lo;exports.X=pe;exports.Zh=zo;exports._=vi;exports.aether=rm;exports.aggregatorStateZ=Fo;exports.c=wi;exports.commonjsGlobal=Vo;exports.cy=pf;exports.dimensions=fl;exports.executeInitialSetter=jt;exports.executeSetter=Zn;exports.fontString=zl;exports.g=j;exports.g$1=Mo;exports.getAugmentedNamespace=Jo;exports.getDefaultExportFromCjs=Ko;exports.i=Wn;exports.isSetter=Gn;exports.l=Jc;exports.levelZ=ul;exports.m=F;exports.mt=Ic;exports.n=Fc;exports.o=qc;exports.o$1=dc;exports.prettyParse=Pn;exports.r=fc;exports.render=Bo;exports.specZ=Me;exports.specZ$1=qo;exports.state=ll;exports.sy=Wd;exports.themeZ=Pi;exports.use=sm;exports.useAggregate=am;exports.useOptionalAggregate=om;exports.usePassthrough=$i;exports.usePurePassthrough=ji;exports.uy=Of;exports.variantZ=Yo;exports.w=W;exports.w$1=Ii;exports.wt=kc;exports.yt=Mc;