@synnaxlabs/pluto 0.25.0 → 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 (110) hide show
  1. package/README.md +4 -3
  2. package/dist/{Animated-BpuQZROI.js → Animated-DNVDjbp5.js} +2 -2
  3. package/dist/{Animated-DqAjXT8r.cjs → Animated-zwHonFIj.cjs} +1 -1
  4. package/dist/{Keyboard-GDYsV4-x.cjs → Keyboard-CK96wQ5G.cjs} +1 -1
  5. package/dist/{Keyboard-BTyEk3pg.js → Keyboard-DIqjeZSO.js} +2 -2
  6. package/dist/LinePlot-Cm6T-Agy.cjs +66 -0
  7. package/dist/{LinePlot-CQAK-dkX.js → LinePlot-Cvi3y24D.js} +2138 -2089
  8. package/dist/{Link-CpMcH9c1.cjs → Link-CRvZcIvR.cjs} +1 -1
  9. package/dist/{Link-BrhOiMiE.js → Link-CfU1takx.js} +1 -1
  10. package/dist/{List-BS57aL1n.js → List-B6hlZNwe.js} +2 -2
  11. package/dist/{List-Dux7qweq.cjs → List-CBMm9BLf.cjs} +1 -1
  12. package/dist/{Pack-_i2cfPYc.cjs → Pack-BM_LmeO7.cjs} +1 -1
  13. package/dist/{Pack-CCCsIeot.js → Pack-E_3LSkGG.js} +1 -1
  14. package/dist/{Toggle-DlNzb7nt.cjs → Toggle-YiHP9pVf.cjs} +5 -5
  15. package/dist/{Toggle-CpLFBHo7.js → Toggle-_SGawcap.js} +4 -4
  16. package/dist/{Video-THwAEuOy.cjs → Video-A2NddcPS.cjs} +1 -1
  17. package/dist/{Video-Bi9kFIHV.js → Video-Ct4BfJzt.js} +1 -1
  18. package/dist/aggregator-D9ExX_tt.cjs +51 -0
  19. package/dist/{aggregator-CoD5WrqU.js → aggregator-DaNTqAB0.js} +2658 -2597
  20. package/dist/align.cjs +1 -1
  21. package/dist/align.js +1 -1
  22. package/dist/button.cjs +1 -1
  23. package/dist/button.js +1 -1
  24. package/dist/color.cjs +1 -1
  25. package/dist/color.js +1 -1
  26. package/dist/{css-Ce6IGevn.js → css-DEMSADUS.js} +140 -140
  27. package/dist/css-DY1Oedjj.cjs +1 -0
  28. package/dist/css.cjs +1 -1
  29. package/dist/css.js +2 -2
  30. package/dist/dropdown.cjs +1 -1
  31. package/dist/dropdown.js +1 -1
  32. package/dist/ether.cjs +1 -1
  33. package/dist/ether.js +42 -41
  34. package/dist/{external-DRvtVPhp.cjs → external-9st6X3mL.cjs} +1 -1
  35. package/dist/{external-DqnUE4mV.cjs → external-BAw0sDOf.cjs} +1 -1
  36. package/dist/{external-DU5Xqqld.cjs → external-BgW4t-2y.cjs} +1 -1
  37. package/dist/{external-C6v1z0ty.js → external-BxUqbUsk.js} +5 -5
  38. package/dist/{external-e0OPlFyY.js → external-C4w_40JS.js} +4 -4
  39. package/dist/{external-DQ4EhNBA.js → external-C86d--c3.js} +11 -11
  40. package/dist/{external-B7RXnD0a.cjs → external-CE4wgFJ7.cjs} +1 -1
  41. package/dist/{external-CXrgzQf5.js → external-CJOE_TDI.js} +2 -2
  42. package/dist/{external-BxBMVx6g.js → external-CS2UIUPR.js} +5 -5
  43. package/dist/{external-CUJXIrxM.cjs → external-ChI4-3Am.cjs} +1 -1
  44. package/dist/{external-NeMo53nv.js → external-ChYLNmOM.js} +4 -4
  45. package/dist/{external-CMk1k986.cjs → external-Cja9j84T.cjs} +1 -1
  46. package/dist/{external-Cv5GChi6.js → external-CsAw5Bqm.js} +7 -7
  47. package/dist/{external-DyTzmzSc.js → external-D23hMpey.js} +4 -4
  48. package/dist/{external-B815mDB0.cjs → external-DG3L9UDo.cjs} +1 -1
  49. package/dist/{external-DMYExlt2.cjs → external-DOZ21f-5.cjs} +1 -1
  50. package/dist/{external-CLwP0eXe.cjs → external-DSc2y4PB.cjs} +1 -1
  51. package/dist/{external-Dm3eiIEN.cjs → external-DZohHxSv.cjs} +1 -1
  52. package/dist/{external-C8CIAjMj.js → external-D_dAdIZX.js} +2 -2
  53. package/dist/{external-DShO9063.js → external-DfwQACwH.js} +3 -3
  54. package/dist/{external-NHkWeW29.js → external-DlkO8mh4.js} +1 -1
  55. package/dist/{external-D_WKlwCh.js → external-TgztmPvP.js} +7 -7
  56. package/dist/external-r0ozQhkY.cjs +1 -0
  57. package/dist/{external-DjSiwSCE.cjs → external-rzy59VM1.cjs} +1 -1
  58. package/dist/header.cjs +1 -1
  59. package/dist/header.js +1 -1
  60. package/dist/index.cjs +1 -1
  61. package/dist/index.js +4122 -4040
  62. package/dist/input.cjs +1 -1
  63. package/dist/input.js +1 -1
  64. package/dist/list.cjs +1 -1
  65. package/dist/list.js +1 -1
  66. package/dist/menu.cjs +1 -1
  67. package/dist/menu.js +1 -1
  68. package/dist/src/hardware/device/Select.d.ts.map +1 -1
  69. package/dist/src/pluto/aether/index.d.ts +1 -1
  70. package/dist/src/pluto/aether/index.d.ts.map +1 -1
  71. package/dist/src/pluto/aether/{ pluto.d.ts → pluto.d.ts} +1 -1
  72. package/dist/src/pluto/aether/pluto.d.ts.map +1 -0
  73. package/dist/src/vis/diagram/edge/Edge.d.ts.map +1 -1
  74. package/dist/src/vis/schematic/Forms.d.ts +4 -0
  75. package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
  76. package/dist/src/vis/schematic/Symbols.d.ts +14 -0
  77. package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
  78. package/dist/src/vis/schematic/primitives/Primitives.d.ts +8 -0
  79. package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
  80. package/dist/src/vis/schematic/registry.d.ts +1 -1
  81. package/dist/src/vis/schematic/registry.d.ts.map +1 -1
  82. package/dist/src/vis/setpoint/aether/index.d.ts +2 -0
  83. package/dist/src/vis/setpoint/aether/index.d.ts.map +1 -0
  84. package/dist/src/vis/setpoint/aether/setpoint.d.ts +200 -0
  85. package/dist/src/vis/setpoint/aether/setpoint.d.ts.map +1 -0
  86. package/dist/src/vis/setpoint/index.d.ts +2 -0
  87. package/dist/src/vis/setpoint/index.d.ts.map +1 -0
  88. package/dist/src/vis/setpoint/use.d.ts +11 -0
  89. package/dist/src/vis/setpoint/use.d.ts.map +1 -0
  90. package/dist/style.css +1 -1
  91. package/dist/tabs.cjs +1 -1
  92. package/dist/tabs.js +1 -1
  93. package/dist/text.cjs +1 -1
  94. package/dist/text.js +2 -2
  95. package/dist/theming.cjs +1 -1
  96. package/dist/theming.js +2 -2
  97. package/dist/tree.cjs +1 -1
  98. package/dist/tree.js +1 -1
  99. package/dist/triggers.cjs +1 -1
  100. package/dist/triggers.js +1 -1
  101. package/dist/{units-DlP7zkaE.js → units-BREWRknL.js} +1 -1
  102. package/dist/{units-CoE6Mywf.cjs → units-DNx3byGw.cjs} +1 -1
  103. package/dist/video.cjs +1 -1
  104. package/dist/video.js +1 -1
  105. package/package.json +5 -5
  106. package/dist/LinePlot-DnLLplw_.cjs +0 -66
  107. package/dist/aggregator-D47lwtdn.cjs +0 -51
  108. package/dist/css-CC1MhhH7.cjs +0 -1
  109. package/dist/external-Do75w1Zt.cjs +0 -1
  110. package/dist/src/pluto/aether/ pluto.d.ts.map +0 -1
@@ -0,0 +1,51 @@
1
+ "use strict";var Xo=Object.defineProperty;var Qo=(t,e,r)=>e in t?Xo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var D=(t,e,r)=>Qo(t,typeof e!="symbol"?e+"":e,r);const s=require("zod"),O=require("./css-DY1Oedjj.cjs"),_n=require("react");var ec=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tc(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function rc(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 nc=Object.defineProperty,sc=(t,e,r)=>e in t?nc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vt=(t,e,r)=>sc(t,typeof e!="symbol"?e+"":e,r);let ic=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(){}},ac=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(l=>l.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(l=>l.trim()),o={};return a.forEach(l=>{o[l]=[]}),i.forEach(l=>{const u=l.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(){}},oc=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 ic;new ac;new oc;const wi=t=>t!=null&&typeof t=="object"&&"toString"in t,cc=t=>{if(wi(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=wi(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?bi(n):n},lc=(t,e,r)=>{const n=Dr(e[t],r);return(i,a)=>n(i[t],a[t])},uc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,hc=(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},dc=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,bi=t=>(e,r)=>t(r,e),fc=t=>t<0,yc=t=>t>0,gc=t=>t>=0,pc=(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],l=i[a];if(isNaN(Number(o))&&isNaN(Number(l))){const u=o.localeCompare(l);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(l))){const u=Number(o)-Number(l);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},mc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:0,GREATER_THAN:1,LESS_THAN:-1,isGreaterThan:yc,isGreaterThanEqual:gc,isLessThan:fc,newF:Dr,newFieldF:lc,order:dc,primitiveArrays:uc,reverseF:bi,stringsWithNumbers:pc,unorderedPrimitiveArrays:hc},Symbol.toStringTag,{value:"Module"})),wc=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},bc=(t,e)=>{let r=null;return e===0?t:(...n)=>{r===null&&(r=setTimeout(()=>{t(...n),r=null},e))}},vi=(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=(l,u)=>l[u]}=r,a=e.split(".");if(a.length===1&&a[0]==="")return t;let o=t;for(const l of a){const u=i(o,l);if(u==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${l} is null`)}o=u}return o},vc=(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},Oc=(t,e)=>{const r=t.split(".");return e<0?r[r.length+e]:r[e]},Tc=t=>t.join("."),Sc=(t,e)=>{try{return Wn(t,e),!0}catch{return!1}},zc=(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},Nc=t=>JSON.parse(JSON.stringify(t)),Ec=(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),Ic=(t,e,r="")=>{const n={},i=(a,o,l)=>{if(typeof a!=typeof o||a===null||o===null){n[l]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){n[l]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${l}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],l!==""?`${l}.${u}`:u)});else a!==o&&(n[l]=[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,l=e;if(o.length!==l.length)return!1;for(let u=0;u<o.length;u++)if(!vn(o[u],l[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 l=t[o],u=e[o];if(typeof l=="object"&&typeof u=="object"){if(!vn(l,u))return!1}else if(l!==u)return!1}return!0},Oi=(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(!Oi(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)},Ac=(t,e,r)=>{const n=(i,a,o)=>{for(const l in a){const u=a[l];if(o!=null&&o.shape[l]){const d=o.shape[l].safeParse(u);d.success&&(i[l]=d.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[l]&&(i[l]||(i[l]={}),n(i[l],u,o.shape[l]))}return i};return n({...t},e,r)},Ti=Object.freeze(Object.defineProperty({__proto__:null,copy:Nc,deleteD:Ec,difference:Ic,element:Oc,equal:vn,get:Wn,has:Sc,join:Tc,override:On,overrideValidItems:Ac,partialEqual:Oi,pathsMatch:zc,set:vc,transformPath:vi},Symbol.toStringTag,{value:"Module"}));var kc=Object.defineProperty,xc=(t,e,r)=>e in t?kc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,m=(t,e,r)=>xc(t,typeof e!="symbol"?e+"":e,r);let Cc=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const jc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Si=Cc(jc,11),Rc=Object.freeze(Object.defineProperty({__proto__:null,id:Si},Symbol.toStringTag,{value:"Module"})),zi=(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",l="00";a!=null&&([o,l]=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(l??"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 zi(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 zi(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),l=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=l.sub(o);let j="";return u.isZero||(j+=`${u.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),M.isZero||(j+=`${M.milliseconds}ms `),_.isZero||(j+=`${_.microseconds}µs `),re.isZero||(j+=`${re.nanoseconds}ns`),j.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 $c=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 ve=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(ve,"MAX",new ve(F.MIN,F.MAX)),m(ve,"MIN",new ve(F.MAX,F.MIN)),m(ve,"ZERO",new ve(F.ZERO,F.ZERO)),m(ve,"z",s.z.union([s.z.object({start:F.z,end:F.z}).transform(t=>new ve(t.start,t.end)),s.z.instanceof(ve)]));let Et=ve;const y=class Oe extends String{constructor(e){if(e instanceof Oe||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Oe.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Oe.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Oe.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(Oe.JSON)||this.equals(Oe.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Oe.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Oe.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 Oe.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 $=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,l=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),l.isZero||(h+=`${l.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 Mc=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)]),Ni=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof F||t instanceof W||t instanceof Date},Dc=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):at(r,-n),Pc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Ei?!0:Ni(t),Ue=-1;let Ei=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"),Pc(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:l=Si()}=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=Ni(u),f=Array.isArray(u);if(r!=null)this.dataType=new $(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=$.STRING;else if(typeof h=="number")this.dataType=$.FLOAT64;else if(typeof h=="bigint")this.dataType=$.INT64;else if(typeof h=="boolean")this.dataType=$.BOOLEAN;else if(h instanceof F||h instanceof Date||h instanceof F)this.dataType=$.TIMESTAMP;else if(typeof h=="object")this.dataType=$.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new $(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($.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.join(`
4
+ `)+`
5
+ `)):this.dataType.equals($.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=l,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 $(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:$.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:$.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:$.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($.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($.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=$.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($.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]=Dc(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($.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($.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($.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($.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($.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($.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 Bc(this);return this.dataType.equals($.JSON)?new Uc(e):e}return new Lc(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 Bc{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 Ts,Ss;let Uc=class{constructor(e){m(this,"wrapped"),m(this,Ts,"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)}}[(Ss=Symbol.iterator,Ts=Symbol.toStringTag,Ss)](){return this}};var zs,Ns;let Lc=class{constructor(e){m(this,"series"),m(this,"index"),m(this,zs,"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)}}[(Ns=Symbol.iterator,zs=Symbol.toStringTag,Ns)](){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 Yc=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 $(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?$.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 qc(this.series)}};var Es,Is;class qc{constructor(e){m(this,"series"),m(this,"seriesIndex"),m(this,"internal"),m(this,Es,"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())}[(Is=Symbol.iterator,Es=Symbol.toStringTag,Is)](){return this}}s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Ii=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Fc=Ii(),Ai=["MacOS","Windows","Linux","Docker"],_c=s.z.enum(Ai);let Jr;const Wc=()=>{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"},Gc=(t={})=>{const{force:e,default:r}=t;return e??Jr??(Jr=Wc(),Jr??r)},ki=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Ai,RUNTIME:Fc,detect:Ii,getOS:Gc,osZ:_c},Symbol.toStringTag,{value:"Module"})),Zc=t=>Array.isArray(t)?t:[t],Vc=t=>Array.isArray(t)?t:t===null?[]:[t],Kc=t=>[...new Set(t)];var Jc=Object.defineProperty,Hc=(t,e,r)=>e in t?Jc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ot=(t,e,r)=>Hc(t,typeof e!="symbol"?e+"":e,r);const Xc=(...t)=>t.map(xi).join(""),xi=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Qc=t=>t.endsWith("/")?t.slice(0,-1):t,As=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=xi(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:Xc(this.path,e)})}toString(){return Qc(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};ot(As,"UNKNOWN",new As({host:"unknown",port:0}));var el=Object.defineProperty,tl=(t,e,r)=>e in t?el(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Er=(t,e,r)=>tl(t,typeof e!="symbol"?e+"":e,r);let rl=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=nl(e,this.sender),n=new sl(r);return this.handlers.set(e,n),n}};const nl=(t,e)=>(r,n)=>e({type:t,payload:r},n);let sl=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 il=Object.defineProperty,al=(t,e,r)=>e in t?il(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tr=(t,e,r)=>al(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 Ci=Ye;const ji=s.z.object({name:s.z.string(),key:s.z.string()}),ol=t=>s.z.object({subject:ji,resource:t,authority:Ci.z}),cl=(...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}),ll=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ci,filterTransfersByChannelKey:cl,stateZ:ol,subjectZ:ji},Symbol.toStringTag,{value:"Module"})),Ri=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(Ri,"MESSAGE","canceled");let ul=Ri;new ul;const hl=t=>t?-1:1;s.z.string().regex(/^\d+\.\d+\.\d+$/);const dl=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()},fl=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,$t=t=>$i(t)?t():t,$i=t=>typeof t=="function",Mi=({initial:t,value:e,onChange:r})=>{const[n,i]=_n.useState($t(e??t));return e!=null&&r!=null?[e,r]:[n,i]},Di=({initial:t,value:e,onChange:r})=>{const[n,i]=_n.useState($t(e??t));return e!=null&&r!=null?[e,r]:[n,i]},yl=(t,e)=>{const[r,n]=_n.useState(()=>{const i=localStorage.getItem(e);return i==null?$t(t):JSON.parse(i)});return[r,i=>{n(i),localStorage.setItem(e,JSON.stringify(i))}]},gl=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:$t,executeSetter:Zn,isInitialSetter:$i,isSetter:Gn,usePassthrough:Mi,usePersisted:yl,usePurePassthrough:Di},Symbol.toStringTag,{value:"Module"})),Pi=["h1","h2","h3","h4","h5","p","small"],pl=s.z.enum(Pi),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()}),Bi={small:"small",medium:"p",large:"h5",huge:"h2"},ml={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let Hr=null;const wl=()=>(Hr==null&&(Hr=document.createElement("canvas")),Hr),bl=(t,e,r)=>{if(ki.RUNTIME==="node")return{width:0,height:0};r==null&&(r=wl().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))}},vl=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}),ge=(t,e)=>[t[0],t[1],e,t[3]],Ol=s.z.object({m2:O.Color.z,m1:O.Color.z,z:O.Color.z,p1:O.Color.z,p2:O.Color.z}),Ft=Ol.or(O.Color.z.transform(t=>{const e=t.hsla;return{m2:new O.Color(O.fromHSLA(ge(e,40))),m1:new O.Color(O.fromHSLA(ge(e,45))),z:t,p1:new O.Color(O.fromHSLA(ge(e,55))),p2:new O.Color(O.fromHSLA(ge(e,65)))}})),Ui=s.z.object({name:s.z.string(),key:s.z.string(),colors:s.z.object({border:O.Color.z,primary:Ft,gray:vl,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)),Tl="'Inter Variable', sans-serif",Sl=6,tt=[357,91,55,1],rt=[42,100,50,1],zl=["#FCFCFC","#F9F9F9","#F4F4F4","#ededed","#d9d9d9","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],_t=Object.fromEntries(zl.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(ge(tt,30)),m1:O.fromHSLA(ge(tt,40)),z:O.fromHSLA(tt),p1:O.fromHSLA(ge(tt,60)),p2:O.fromHSLA(ge(tt,70))},warning:{m2:O.fromHSLA(ge(rt,30)),m1:O.fromHSLA(ge(rt,40)),z:O.fromHSLA(rt),p1:O.fromHSLA(ge(rt,60)),p2:O.fromHSLA(ge(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:Sl,border:{radius:2,width:1},schematic:{elementStrokeWidth:2}},typography:{family:Tl,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}}},Li=Object.freeze({...Sn,key:"synnaxLight",name:"Synnax Light"}),Nl=["#020202","#080808","#141414","#1a1a1a","#242424","#515151","#7f7f7f","#9D9D9D","#BFBFBF","#EDEDED","#FDFDFD"],Wt=Object.fromEntries(Nl.map((t,e)=>[`l${e}`,t])),Yi=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}}),El={synnaxDark:Yi,synnaxLight:Li},Il=["small","medium","large","huge"],Al=s.z.enum(Il),kl=t=>Al.safeParse(t).success,xl=(t,e,r)=>{const{typography:n,sizes:{base:i}}=t,a=n[kl(e)?Bi[e]:e].size,o=i*a,[l,u]=n.family.split(", ");return r!=null?` ${r} ${o}px ${l}, ${u}`:` ${o}px ${n.family}`};var Cl=Object.defineProperty,jl=(t,e,r)=>e in t?Cl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,c=(t,e,r)=>jl(t,typeof e!="symbol"?e+"":e,r),Rl=Object.defineProperty,$l=(t,e,r)=>e in t?Rl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,R=(t,e,r)=>$l(t,typeof e!="symbol"?e+"":e,r);const Ml=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)},qi=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=Ul(n);const i={},a=r;return Object.keys(a).forEach(o=>{let l=a[o];const u=t(o);n.recursive&&(Xr(l)?xs(l,n.keepTypesOnRecursion)||(l=e(l,n)):n.recursiveInArray&&ks(l)&&(l=[...l].map(d=>{let f=d;return Xr(d)?xs(f,n.keepTypesOnRecursion)||(f=e(d,n)):ks(d)&&(f=e({key:d},n).key),f}))),i[u]=l}),i};return e},Dl=qi(Ml),Pl=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Bl=qi(Pl),zn={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Ul=(t=zn)=>(t.recursive==null?t=zn:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),ks=t=>t!=null&&Array.isArray(t),Xr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),xs=(t,e)=>(e||[]).some(r=>t instanceof r),Fi=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var Ll=Object.defineProperty,Yl=(t,e,r)=>e in t?Ll(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ot=(t,e,r)=>Yl(t,typeof e!="symbol"?e+"":e,r);let ql=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=Dl(r);return e!=null?e.parse(n):n}encodeString(t){const e=Bl(t);return JSON.stringify(e,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):Fi(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},Fl=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||!Fi(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 l=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(l[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(){}},_l=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 ql;new Fl;new _l;const Br=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const _i=s.z.object({width:s.z.number(),height:s.z.number()}),Wl=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Gl=["width","height"];s.z.enum(Gl);const Zl=["start","center","end"],Vl=["signedWidth","signedHeight"];s.z.enum(Vl);const Ir=s.z.object({x:s.z.number(),y:s.z.number()}),Kl=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Jl=["x","y"],Wi=s.z.enum(Jl),Gi=["top","right","bottom","left"];s.z.enum(Gi);const Hl=["left","right"],Zi=s.z.enum(Hl),Xl=["top","bottom"],Vi=s.z.enum(Xl),Ki=["center"],Cs=s.z.enum(Ki),Ql=[...Gi,...Ki],Ji=s.z.enum(Ql);s.z.enum(Zl);const eu=["first","last"];s.z.enum(eu);const tu=s.z.object({lower:s.z.number(),upper:s.z.number()}),ru=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([tu,Br]);s.z.union([ru,Br]);s.z.union([Wi,Ji]);s.z.union([Wi,Ji,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 js(t);return js(r)},js=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:Zi.or(Cs),y:Vi.or(Cs)});const nu=s.z.object({x:Zi,y:Vi}),su=Object.freeze({x:"left",y:"top"}),iu=(t,e)=>t.x===e.x&&t.y===e.y,Rs=s.z.union([s.z.number(),Ir,Br,_i,Wl,Kl]),au=(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}),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:nu});const Vn=(t,e,r=0,n=0,i)=>{const a={one:{...$s},two:{...$s},root:i??su};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}},ou=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var cu=Object.defineProperty,lu=(t,e,r)=>e in t?cu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ce=(t,e,r)=>lu(t,typeof e!="symbol"?e+"":e,r);const uu=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:Rs,scale:Rs});const hu=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],du=t=>(e,r,n,i)=>[e,i?n/t:n*t],fu=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:l}=t,u=a-i,d=l-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},yu=t=>(e,r,n)=>[t,n],gu=()=>(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)]},pu=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=uu(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=hu(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=du(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=Qr(e,r),i=this.new(),a=fu(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=Qr(e,r),i=this.new(),a=pu(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=Qr(e,r),i=this.new(),a=yu(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=gu();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,l])=>i>=o&&i<=l))return;const a=e.ops.findIndex((o,l)=>o.type==="scale"&&l>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 Ms=Nn;const Ds=class Ae{constructor(e=new Ms,r=new Ms,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=au(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(ou(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!iu(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(Ds,"IDENTITY",new Ds);const mu=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([_i,mu,Ir,Br]);var wu=Object.defineProperty,bu=(t,e,r)=>e in t?wu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,b=(t,e,r)=>bu(t,typeof e!="symbol"?e+"":e,r);const Hi=(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",l="00";a!=null&&([o,l]=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(l??"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 vu(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 Hi(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 Hi(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),l=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=l.sub(o);let j="";return u.isZero||(j+=`${u.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),M.isZero||(j+=`${M.milliseconds}ms `),_.isZero||(j+=`${_.microseconds}µs `),re.isZero||(j+=`${re.nanoseconds}ns`),j.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 Ou(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 Te=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(Te,"MAX",new Te(ee.MIN,ee.MAX)),b(Te,"MIN",new Te(ee.MAX,ee.MIN)),b(Te,"ZERO",new Te(ee.ZERO,ee.ZERO)),b(Te,"z",s.z.union([s.z.object({start:ee.z,end:ee.z}).transform(t=>new Te(t.start,t.end)),s.z.instanceof(Te)]));let vu=Te;const p=class Se extends String{constructor(e){if(e instanceof Se||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Se.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Se.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Se.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(Se.JSON)||this.equals(Se.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Se.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Se.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 Se.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,l=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),l.isZero||(h+=`${l.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 Ou=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 Xi=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Tu=Xi(),Qi=["MacOS","Windows","Linux","Docker"],Su=s.z.enum(Qi);let rn;const zu=()=>{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"},Nu=(t={})=>{const{force:e,default:r}=t;return e??rn??(rn=zu(),rn??r)},ea=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Qi,RUNTIME:Tu,detect:Xi,getOS:Nu,osZ:Su},Symbol.toStringTag,{value:"Module"}));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,ut=(t,e,r)=>Iu(t,typeof e!="symbol"?e+"":e,r);const Au=(...t)=>t.map(ta).join(""),ta=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),ku=t=>t.endsWith("/")?t.slice(0,-1):t,xu=(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=ta(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:Au(this.path,e)})}toString(){return ku(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};ut(En,"UNKNOWN",new En({host:"unknown",port:0}));let Cu=En;var ju=Object.defineProperty,Ru=(t,e,r)=>e in t?ju(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sr=(t,e,r)=>Ru(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 ra=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(ra,"MESSAGE","canceled");let $u=ra;new $u;s.z.string().regex(/^\d+\.\d+\.\d+$/);const de=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 be=class extends Error{constructor(e){super(e),R(this,"discriminator","FreighterError"),R(this,"type","")}};const Mu=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},Ps="unknown",Bs="nil",Du="freighter",Mt=s.z.object({type:s.z.string(),data:s.z.string()});class Pu{constructor(){R(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Bs,data:""};if(Mu(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}return{type:Ps,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Bs)return null;if(e.type===Ps)return new Us(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Us(e.data)}}const na=new Pu,sa=({encode:t,decode:e})=>na.register({encode:t,decode:e}),Kn=t=>na.decode(t);class Us extends be{constructor(e){super(e),R(this,"type","unknown")}}const Ur="freighter.",ir=class ia extends be{constructor(){super("EOF"),R(this,"type",ia.TYPE)}};R(ir,"TYPE",Ur+"eof"),R(ir,"matches",de(ir.TYPE));let De=ir;const ar=class aa extends be{constructor(){super("StreamClosed"),R(this,"type",aa.TYPE)}};R(ar,"TYPE",Ur+"stream_closed"),R(ar,"matches",de(ar.TYPE));let Je=ar;const or=class oa extends be{constructor(e={}){const{message:r="Unreachable",url:n=Cu.UNKNOWN}=e;super(r),R(this,"type",oa.TYPE),R(this,"url"),this.url=n}};R(or,"TYPE",Ur+"unreachable"),R(or,"matches",de(or.TYPE));let We=or;const Bu=t=>{if(!t.type.startsWith(Du))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}`)},Uu=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}`)}};sa({encode:Bu,decode:Uu});class ca{constructor(){R(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 la="Content-Type",Ls=t=>{if(ea.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 Lu extends ca{constructor(e,r,n=!1){return super(),R(this,"endpoint"),R(this,"encoder"),R(this,"fetch"),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,this.fetch=Ls(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[la]: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),l={};l.method="POST",l.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:{}};l.headers={...this.headers,...d.params};let h;try{h=await Ls(d.protocol)(d.target,l)}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},Yu=()=>ea.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),qu=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 Fu{constructor(e,r,n,i){R(this,"encoder"),R(this,"reqSchema"),R(this,"resSchema"),R(this,"ws"),R(this,"serverClosed"),R(this,"sendClosed"),R(this,"receiveDataQueue",[]),R(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,qu)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Vu(e)?De.TYPE:Je.TYPE,data:""}})}}const _u="freighterctx",Wu=1e3,Gu=1001,Zu=[Wu,Gu],Vu=t=>Zu.includes(t.code),ua=class ha extends ca{constructor(e,r,n=!1){super(),R(this,"baseUrl"),R(this,"encoder"),this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}async stream(e,r,n){const i=Yu();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async l=>{const u=i(this.buildURL(e,l)),d={...l,params:{}};u.binaryType=ha.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=xu({[la]:this.encoder.contentType,...r.params},_u);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(i=>{e.onopen=()=>{i(new Fu(e,this.encoder,r,n))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};R(ua,"MESSAGE_TYPE","arraybuffer");let Ku=ua;const Ju=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)},da=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=Qu(n);const i={},a=r;return Object.keys(a).forEach(o=>{let l=a[o];const u=t(o);n.recursive&&(nn(l)?qs(l,n.keepTypesOnRecursion)||(l=e(l,n)):n.recursiveInArray&&Ys(l)&&(l=[...l].map(d=>{let f=d;return nn(d)?qs(f,n.keepTypesOnRecursion)||(f=e(d,n)):Ys(d)&&(f=e({key:d},n).key),f}))),i[u]=l}),i};return e},fa=da(Ju),Hu=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Xu=da(Hu),An={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Qu=(t=An)=>(t.recursive==null?t=An:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Ys=t=>t!=null&&Array.isArray(t),nn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),qs=(t,e)=>(e||[]).some(r=>t instanceof r),Jn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var eh=Object.defineProperty,th=(t,e,r)=>e in t?eh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tt=(t,e,r)=>th(t,typeof e!="symbol"?e+"":e,r);let ya=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=fa(r);return e!=null?e.parse(n):n}encodeString(t){const e=Xu(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(){}},ga=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 l=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(l[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(){}},pa=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 ya,rh=new ga,nh=new pa,sh=[Ke],Xe=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:ga,CSV_CODEC:rh,ENCODERS:sh,JSONCodec:ya,JSON_CODEC:Ke,TEXT_CODEC:nh,TextCodec:pa},Symbol.toStringTag,{value:"Module"})),ih=t=>t!=null&&typeof t=="object"&&"toString"in t,ah=(t,e=!1)=>{const r=ih(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?oh(n):n},oh=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 ma=s.z.object({width:s.z.number(),height:s.z.number()}),ch=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),lh=["width","height"];s.z.enum(lh);const uh=["start","center","end"],hh=["signedWidth","signedHeight"];s.z.enum(hh);const Ar=s.z.object({x:s.z.number(),y:s.z.number()}),dh=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),fh=["x","y"],wa=s.z.enum(fh),ba=["top","right","bottom","left"];s.z.enum(ba);const yh=["left","right"],va=s.z.enum(yh),gh=["top","bottom"],Oa=s.z.enum(gh),Ta=["center"],Fs=s.z.enum(Ta),ph=[...ba,...Ta],Sa=s.z.enum(ph);s.z.enum(uh);const mh=["first","last"];s.z.enum(mh);const wh=s.z.object({lower:s.z.number(),upper:s.z.number()}),bh=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([wh,Lr]);s.z.union([bh,Lr]);s.z.union([wa,Sa]);s.z.union([wa,Sa,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 _s(t);return _s(r)},_s=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:va.or(Fs),y:Oa.or(Fs)});const vh=s.z.object({x:va,y:Oa}),Oh=Object.freeze({x:"left",y:"top"}),Th=(t,e)=>t.x===e.x&&t.y===e.y,Ws=s.z.union([s.z.number(),Ar,Lr,ma,ch,dh]),Sh=(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}},Gs=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:vh});const Hn=(t,e,r=0,n=0,i)=>{const a={one:{...Gs},two:{...Gs},root:i??Oh};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}},zh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,Nh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ma,Nh,Ar,Lr]);var Eh=Object.defineProperty,Ih=(t,e,r)=>e in t?Eh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,je=(t,e,r)=>Ih(t,typeof e!="symbol"?e+"":e,r);const Ah=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:Ws,scale:Ws});const kh=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],xh=t=>(e,r,n,i)=>[e,i?n/t:n*t],Ch=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:l}=t,u=a-i,d=l-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},jh=t=>(e,r,n)=>[t,n],Rh=()=>(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)]},$h=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=Ah(n,i,a),[e,n]},kn=class dt{constructor(){je(this,"ops",[]),je(this,"currBounds",null),je(this,"currType",null),je(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=kh(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=xh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=St(e,r),i=this.new(),a=Ch(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=St(e,r),i=this.new(),a=$h(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=St(e,r),i=this.new(),a=jh(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Rh();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,l])=>i>=o&&i<=l))return;const a=e.ops.findIndex((o,l)=>o.type==="scale"&&l>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}};je(kn,"IDENTITY",new kn);let Zs=kn;const Vs=class ke{constructor(e=new Zs,r=new Zs,n=null){je(this,"x"),je(this,"y"),je(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=Sh(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(zh(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Th(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)}};je(Vs,"IDENTITY",new Vs);var Mh=Object.defineProperty,Dh=(t,e,r)=>e in t?Mh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,w=(t,e,r)=>Dh(t,typeof e!="symbol"?e+"":e,r);let Ph=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const Bh="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",za=Ph(Bh,11),Uh=Object.freeze(Object.defineProperty({__proto__:null,id:za},Symbol.toStringTag,{value:"Module"})),Na=(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",l="00";a!=null&&([o,l]=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(l??"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 Na(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 Na(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),l=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=l.sub(o);let j="";return u.isZero||(j+=`${u.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),M.isZero||(j+=`${M.milliseconds}ms `),_.isZero||(j+=`${_.microseconds}µs `),re.isZero||(j+=`${re.nanoseconds}ns`),j.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 ze=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(ze,"MAX",new ze(E.MIN,E.MAX)),w(ze,"MIN",new ze(E.MAX,E.MIN)),w(ze,"ZERO",new ze(E.ZERO,E.ZERO)),w(ze,"z",s.z.union([s.z.object({start:E.z,end:E.z}).transform(t=>new ze(t.start,t.end)),s.z.instanceof(ze)]));let oe=ze;const g=class Ne extends String{constructor(e){if(e instanceof Ne||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Ne.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Ne.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Ne.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(Ne.JSON)||this.equals(Ne.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Ne.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Ne.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 Ne.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,l=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),l.isZero||(h+=`${l.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 Ea=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof E||t instanceof I||t instanceof Date},Lh=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):yt(r,-n),Yh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Fe?!0:Ea(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"),Yh(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:l=za()}=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=Ea(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=l,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]=Lh(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):fa(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const i=ah(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 qh(this);return this.dataType.equals(A.JSON)?new Fh(e):e}return new _h(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 qh{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 Ks,Js;class Fh{constructor(e){w(this,"wrapped"),w(this,Ks,"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)}}[(Js=Symbol.iterator,Ks=Symbol.toStringTag,Js)](){return this}}var Hs,Xs;class _h{constructor(e){w(this,"series"),w(this,"index"),w(this,Hs,"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)}}[(Xs=Symbol.iterator,Hs=Symbol.toStringTag,Xs)](){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 Wh{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 Gh(this.series)}}var Qs,ei;class Gh{constructor(e){w(this,"series"),w(this,"seriesIndex"),w(this,"internal"),w(this,Qs,"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())}[(ei=Symbol.iterator,Qs=Symbol.toStringTag,ei)](){return this}}const N=t=>Array.isArray(t)?t:[t],Zh=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}};var Vh=Object.defineProperty,Kh=(t,e,r)=>e in t?Vh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xn=(t,e,r)=>Kh(t,typeof e!="symbol"?e+"":e,r);class Jh{constructor(e,r){xn(this,"handlers"),xn(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 Hh=class{constructor(t){xn(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 Cn=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Hh,Observer:Jh},Symbol.toStringTag,{value:"Module"})),Qn=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Xh=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Xh();const Qh=["MacOS","Windows","Linux","Docker"];s.z.enum(Qh);const ti=t=>[...new Set(t)];var ed=Object.defineProperty,td=(t,e,r)=>e in t?ed(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gt=(t,e,r)=>td(t,typeof e!="symbol"?e+"":e,r);const rd=(...t)=>t.map(Ia).join(""),Ia=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),nd=t=>t.endsWith("/")?t.slice(0,-1):t,jn=class Rn{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=Ia(i)}replace(e){return new Rn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Rn({...this,pathPrefix:rd(this.path,e)})}toString(){return nd(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};gt(jn,"UNKNOWN",new jn({host:"unknown",port:0}));let sd=jn;var id=Object.defineProperty,ad=(t,e,r)=>e in t?id(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ur=(t,e,r)=>ad(t,typeof e!="symbol"?e+"":e,r);const qe=class extends Number{};ur(qe,"Absolute",255),ur(qe,"Default",1),ur(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 Aa=qe;const ka=s.z.object({name:s.z.string(),key:s.z.string()}),od=t=>s.z.object({subject:ka,resource:t,authority:Aa.z}),cd=(...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:Aa,filterTransfersByChannelKey:cd,stateZ:od,subjectZ:ka},Symbol.toStringTag,{value:"Module"})),xa=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)}};ur(xa,"MESSAGE","canceled");let ld=xa;new ld;s.z.string().regex(/^\d+\.\d+\.\d+$/);const Pe="sy.",hr=class Ca extends be{constructor(){super(...arguments),c(this,"type",Ca.TYPE)}};c(hr,"TYPE",Pe+"validation"),c(hr,"matches",de(hr.TYPE));let G=hr;const dr=class ja extends G{constructor(e,r){super(e+": "+r),c(this,"type",ja.TYPE),c(this,"field"),c(this,"message"),this.field=e,this.message=r}};c(dr,"TYPE",G.TYPE+".field"),c(dr,"matches",de(dr.TYPE));let ri=dr;const fr=class Ra extends be{constructor(){super(...arguments),c(this,"type",Ra.TYPE)}};c(fr,"TYPE",Pe+"auth"),c(fr,"matches",de(fr.TYPE));let kr=fr;const yr=class $a extends kr{constructor(){super(...arguments),c(this,"type",$a.TYPE)}};c(yr,"TYPE",kr.TYPE+".invalid-token"),c(yr,"matches",de(yr.TYPE));let $n=yr;const gr=class Ma extends be{constructor(e){super(`
28
+ Unexpected error encountered:
29
+
30
+ ${e}
31
+
32
+ Please report this to the Synnax team.
33
+ `),c(this,"type",Ma.TYPE)}};c(gr,"TYPE",Pe+"unexpected"),c(gr,"matches",de(gr.TYPE));let me=gr;const pr=class Da extends be{constructor(){super(...arguments),c(this,"type",Da.TYPE)}};c(pr,"TYPE",Pe+"query"),c(pr,"matches",de(pr.TYPE));let we=pr;const mr=class Pa extends we{constructor(){super(...arguments),c(this,"type",Pa.TYPE)}};c(mr,"TYPE",we.TYPE+".not_found"),c(mr,"matches",de(mr.TYPE));let xr=mr;const wr=class Ba extends we{constructor(){super(...arguments),c(this,"type",Ba.TYPE)}};c(wr,"TYPE",we.TYPE+".multiple_results"),c(wr,"matches",de(wr.TYPE));let Cr=wr;const br=class Ua extends be{constructor(e,r){super(e),c(this,"type",Ua.TYPE),c(this,"path"),this.path=r}};c(br,"TYPE",Pe+"route"),c(br,"matches",de(br.TYPE));let ni=br;const vr=class La extends be{constructor(){super(...arguments),c(this,"type",La.TYPE)}};c(vr,"TYPE",Pe+"control"),c(vr,"matches",de(vr.TYPE));let jr=vr;const Or=class Ya extends jr{constructor(){super(...arguments),c(this,"type",Ya.TYPE)}};c(Or,"TYPE",jr.TYPE+".unauthorized"),c(Or,"matches",de(Or.TYPE));let si=Or;const on=class qa extends be{constructor(){super(...arguments),c(this,"type",qa.TYPE)}};c(on,"TYPE",Pe+"contiguity"),c(on,"matches",de(on.TYPE));const ud=t=>{if(!t.type.startsWith(Pe))return null;if(t.type.startsWith(G.TYPE)){if(t.type===ri.TYPE){const e=t.data.split(": ");return e.length<2?new G(t.data):new ri(e[0],e[1])}return new G(t.data)}return t.type.startsWith(kr.TYPE)?t.type.startsWith($n.TYPE)?new $n(t.data):new kr(t.data):t.type.startsWith(me.TYPE)?new me(t.data):t.type.startsWith(we.TYPE)?t.type.startsWith(xr.TYPE)?new xr(t.data):t.type.startsWith(Cr.TYPE)?new Cr(t.data):new we(t.data):t.type.startsWith(jr.TYPE)?t.type.startsWith(si.TYPE)?new si(t.data):new jr(t.data):t.type.startsWith(ni.TYPE)?new ni(t.data,t.data):new me(t.data)},hd=()=>{throw new Error("Not implemented")};sa({encode:hd,decode:ud});const dd=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]};class Fa{constructor(e,r){c(this,"key"),c(this,"name"),this.key=r,this.name=e}get ontologyID(){return new he({type:"group",key:this.key})}}const fd=s.z.string().uuid(),_a=s.z.object({key:fd,name:s.z.string()}),Wa=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"),s.z.literal("policy")]),ye=s.z.object({type:Wa,key:s.z.string()}),yd=s.z.string().transform(t=>{const[e,r]=t.split(":");return{type:e,key:r}}),gd=s.z.union([yd,ye]),Tr=class Ga{constructor(e){if(c(this,"type"),c(this,"key"),e instanceof Ga)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}}};c(Tr,"z",s.z.union([gd,s.z.instanceof(Tr)]).transform(t=>new Tr(t)));let he=Tr;new he({type:"builtin",key:"root"});const pd=s.z.object({type:s.z.number()}),md=s.z.object({type:Wa,fields:s.z.record(pd)}),wd=s.z.object({id:he.z,name:s.z.string(),schema:md.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:he.z,type:s.z.string(),to:he.z});const ii=t=>{const[e,r,n]=t.split("->");return{from:new he(e),type:r,to:new he(n)}},bd=s.z.object({group:_a}),vd=s.z.object({parent:ye,key:s.z.string().uuid().optional(),name:s.z.string()}),Od=s.z.object({key:s.z.string(),name:s.z.string()}),Td=s.z.object({keys:s.z.array(s.z.string())});var $e;let Sd=($e=class{constructor(t){c(this,"client"),this.client=t}async create(t,e,r){const[n,i]=await this.client.send($e.ENDPOINT,{parent:t,name:e,key:r},vd,bd);if(i!=null)throw i;return n.group}async rename(t,e){const r={key:t,name:e},[,n]=await this.client.send($e.ENDPOINT_RENAME,r,Od,s.z.object({}));if(n!=null)throw n}async delete(t){const e={keys:t},[,r]=await this.client.send($e.ENDPOINT_DELETE,e,Td,s.z.object({}));if(r!=null)throw r}},c($e,"ENDPOINT","/ontology/create-group"),c($e,"ENDPOINT_RENAME","/ontology/rename-group"),c($e,"ENDPOINT_DELETE","/ontology/delete-group"),$e),zd=class{constructor(t){c(this,"creator"),this.creator=new Sd(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 Fa(t.name,t.key)}};const cn={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},ai=s.z.object({id:ye,children:ye.array()}),Nd=s.z.object({from:ye,to:ye,children:ye.array()});let Ed=class{constructor(t){c(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,cn.ADD_CHILDREN,{id:t,children:e},ai,s.z.object({}))}async removeChildren(t,...e){await v(this.client,cn.REMOVE_CHILDREN,{id:t,children:e},ai,s.z.object({}))}async moveChildren(t,e,...r){const n={from:t,to:e,children:r};await v(this.client,cn.MOVE_CHILDREN,n,Nd,s.z.object({}))}};const Id="/ontology/retrieve",Ad=s.z.object({ids:ye.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()}),kd=s.z.object({resources:wd.array()}),ln=t=>N(t).map(e=>new he(e).payload);let xd=class{constructor(t,e){c(this,"type","ontology"),c(this,"groups"),c(this,"client"),c(this,"writer"),c(this,"framer"),this.client=t,this.writer=new Ed(t),this.groups=new zd(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 we(`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 es.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,Id,t,Ad,kd);return e}};const oi="sy_ontology_resource_set",ci="sy_ontology_resource_delete",li="sy_ontology_relationship_set",ui="sy_ontology_relationship_delete";class es{constructor(e,r){c(this,"resourceObs"),c(this,"relationshipObs"),c(this,"relationships"),c(this,"resources"),c(this,"streamer"),c(this,"client"),c(this,"closePromise"),this.relationshipObs=new Cn.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Cn.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(li);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"set",key:ii(n),value:void 0}))}parseRelationshipDeletes(e){const r=e.get(ui);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:ii(n)}))}async parseResourceSets(e){const r=e.get(oi);if(r.length===0)return[];const n=Array.from(r.as("string")).map(i=>new he(i));try{return(await this.client.retrieve(n)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof we)return[];throw i}}parseResourceDeletes(e){const r=e.get(ci);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:new he(n)}))}static async open(e,r){const n=await e.openStreamer([oi,ci,li,ui]);return new es(n,r)}}const Be=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()}),Za=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)}),Va="channel",Cd=t=>new he({type:Va,key:t.toString()}),jd=new Error("request for lock canceled");var Rd=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 l(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(l,u)}d((n=n.apply(t,e||[])).next())})};class $d{constructor(e,r=jd){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=Ka(this._queue,l=>r<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Rd(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]=[]),Md(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 Md(t,e){const r=Ka(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function Ka(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var Dd=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 l(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(l,u)}d((n=n.apply(t,e||[])).next())})};class Pd{constructor(e){this._semaphore=new $d(1,e)}acquire(){return Dd(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 Yr=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let i=N(t);const a=i[0],o=typeof a;let l;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[o],{single:n,variant:l,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()]),Bd=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()}),Ud=s.z.object({channels:Qe(Dt)}),Re=t=>Yr(t,{number:"keys",string:"names"}),Ja=class Ha{constructor(e){c(this,"client"),this.client=e}async search(e,r){return await this.execute({search:e,...r})}async retrieve(e,r){const n=Re(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(Ha.ENDPOINT,e,Bd,Ud);if(n!=null)throw n;return r.channels}};c(Ja,"ENDPOINT","/channel/retrieve");let ts=Ja;class rs{constructor(e){c(this,"cache"),c(this,"namesToKeys"),c(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(l=>{const u=this.get(l);u!=null?i.push(...u):a.push(l)}),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}=Re(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 l=this.namesToKeys.get(o.name);l!=null&&(l.delete(n),l.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 Xa{constructor(e,r){c(this,"mu",new Pd),c(this,"requests",new Map),c(this,"wrapped"),c(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=Zh(()=>{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}=Re(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 Qa=async(t,e)=>{const{normalized:r}=Re(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 we(`Could not find channels: ${JSON.stringify(i)}`);return n};class eo{constructor({dataType:e,rate:r,name:n,leaseholder:i=0,key:a=0,isIndex:o=!1,index:l=0,internal:u=!1,frameClient:d,alias:f}){c(this,"_frameClient"),c(this,"key"),c(this,"name"),c(this,"rate"),c(this,"dataType"),c(this,"leaseholder"),c(this,"index"),c(this,"isIndex"),c(this,"internal"),c(this,"alias"),this.key=a,this.name=n,this.rate=new Xn(r??0),this.dataType=new A(e),this.leaseholder=i,this.index=l,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 he({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 Ld="/channel/retrieve-group",Yd=s.z.object({}),qd=s.z.object({group:_a});let to=class{constructor(t,e,r,n){c(this,"type","channel"),c(this,"frameClient"),c(this,"client"),c(this,"retriever"),c(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)),l=new Set(o.map(u=>u.name));i=i.filter(u=>!l.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}=Re(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 rs(new Xa(new ts(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(r=>new eo({...r,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,Ld,{},Yd,qd);return new Fa(t.group.name,t.group.key)}};const Fd=s.z.object({channels:Za.array()}),_d=s.z.object({channels:Dt.array()}),Wd=s.z.object({keys:Be.array().optional(),names:s.z.string().array().optional()}),Gd=s.z.object({}),Zd=s.z.object({keys:Be.array(),names:s.z.string().array()}),Vd=s.z.object({}),Kd="/channel/create",Jd="/channel/delete",Hd="/channel/rename";let ro=class{constructor(t,e){c(this,"client"),c(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,Kd,{channels:t},Fd,_d);return this.cache.set(e),e}async delete(t){await v(this.client,Jd,t,Wd,Gd),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,Hd,{keys:t,names:e},Zd,Vd),this.cache.rename(t,e)}};const Xd=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:rs,Channel:eo,ChannelOntologyType:Va,Client:to,ClusterRetriever:ts,DebouncedBatchRetriever:Xa,Writer:ro,analyzeChannelParams:Re,keyZ:Be,newPayload:Za,ontologyID:Cd,payload:Dt,retrieveRequired:Qa},Symbol.toStringTag,{value:"Module"})),ns=s.z.string().uuid(),ss=s.z.object({key:ns,subjects:ye.array(),objects:ye.array(),actions:s.z.string().array()}),Qd=ss.extend({key:ns.optional()}),ef="/access/policy/create",tf="/access/policy/delete",rf="/access/policy/retrieve",nf=s.z.object({policies:Qd.array()}),sf=s.z.object({policies:ss.array()}),af=s.z.object({keys:ns.array()}),of=s.z.object({}),cf=s.z.object({subject:ye}),lf=s.z.object({policies:ss.array().optional().default([])});let uf=class{constructor(t){c(this,"client"),this.client=t}async create(t){const e=!Array.isArray(t),{policies:r}=await v(this.client,ef,{policies:N(t)},nf,sf);return e?r[0]:r}async retrieve(t){const{policies:e}=await v(this.client,rf,{subject:t},cf,lf);return e}async delete(t){await v(this.client,tf,{keys:N(t)},af,of)}};const hf="/user/register";let df=class{constructor(t){c(this,"client"),this.client=t}async register(t,e){const{user:r}=await v(this.client,hf,{username:t,password:e},no,so);return r}};s.z.string().uuid();const ff=s.z.object({key:s.z.string(),username:s.z.string()}),no=s.z.object({username:s.z.string(),password:s.z.string()}),so=s.z.object({token:s.z.string(),user:ff}),hi="/auth/login",yf=3;let gf=class{constructor(t,e){c(this,"token"),c(this,"client"),c(this,"credentials"),c(this,"authenticating"),c(this,"authenticated"),c(this,"user"),c(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(hi)){this.authenticating==null&&(this.authenticating=new Promise((o,l)=>{this.client.send(hi,this.credentials,no,so).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(l)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[n,i]=await r(e);return $n.matches(i)&&this.retryCount<yf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,r)):(this.retryCount=0,[n,i])};return t}};const pf=["disconnected","connecting","connected","failed"],mf=s.z.enum(pf),wf=s.z.object({status:mf,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string()}),bf=s.z.object({clusterKey:s.z.string()}),io={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected"},Sr=class ao{constructor(e,r=I.seconds(30),n){c(this,"_state"),c(this,"pollFrequency",I.seconds(30)),c(this,"client"),c(this,"name"),c(this,"interval"),c(this,"onChangeHandlers",[]),this._state={...io},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(ao.ENDPOINT,{},s.z.object({}),bf);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)}};c(Sr,"ENDPOINT","/connectivity/check"),c(Sr,"DEFAULT",io),c(Sr,"connectionStateZ",wf);let oo=Sr;const vf=s.z.object({keys:Be.array().optional(),bounds:oe.z,names:s.z.string().array().optional()}),Of=s.z.object({}),Tf="/frame/delete";class Sf{constructor(e){c(this,"client"),this.client=e}async delete(e){await v(this.client,Tf,e,vf,Of)}}const di=t=>{const e=N(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},fi=(t,e)=>{const r=N(t);if(r.length===e.length)return;const n=di(t);throw di===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 pe=class Ve{constructor(e=[],r=[]){if(c(this,"columns",[]),c(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=>lo(a));fi(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);fi(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 me("colType is not key");return this.columns??[]}get uniqueKeys(){return ti(this.keys)}get names(){if(this.colType==="key")throw new me("colType is not name");return this.columns??[]}get uniqueNames(){return ti(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>uo(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 Wh(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 co=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(()=>[]),co.array().optional().default([])])}),lo=t=>{const{dataType:e,data:r,timeRange:n,alignment:i}=t;return new Fe({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},uo=t=>({timeRange:t._timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});class _r{constructor(e){c(this,"adapter"),c(this,"retriever"),c(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}=Re(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 l=i.find(u=>u.name===o);if(l==null)throw new Error(`Channel ${o} not found`);a.set(l.key,l.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 is{constructor(e){c(this,"adapter"),c(this,"retriever"),c(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,r){const n=new is(e);return await n.update(r),n}async update(e){const r=await Qa(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),l=new Fe({data:r,dataType:o.dataType});return new pe(o.key,l)}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=[],l=[];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),l.push(f)}return new pe(o,l)}if(e instanceof pe||e instanceof Map){const o=new pe(e);if(this.adapter==null)return o;let l=[];return l=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 pe(l,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[l,u]=a[o],d=await this.fetchChannel(l),f=new Fe({data:u,dataType:d.dataType});n.push(d.key),i.push(f)}return new pe(n,i)}}class as{constructor(e,r){c(this,"name"),c(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 os=(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))(os||{}),ho=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(ho||{});const zf=s.z.object({command:s.z.nativeEnum(os),span:I.z.optional(),bounds:oe.z.optional(),stamp:E.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),Nf=s.z.object({variant:s.z.nativeEnum(ho),ack:s.z.boolean(),command:s.z.nativeEnum(os),error:Mt.optional().nullable(),frame:Fr.optional()}),fo=class Dn{constructor(e,r){c(this,"stream"),c(this,"adapter"),c(this,"value"),this.stream=new as("Iterator",e),this.value=new pe,this.adapter=r}static async _open(e,r,n,i,a={}){const o=await _r.open(n,r),l=await i.stream(Dn.ENDPOINT,zf,Nf),u=new Dn(l,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 Ef(this)}async execute(e){for(this.stream.send(e),this.value=new pe;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new pe(r.frame)))}}};c(fo,"ENDPOINT","/frame/iterate");let yo=fo;class Ef{constructor(e){c(this,"iter"),c(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 If=s.z.object({start:E.z.optional(),keys:s.z.number().array()}),Af=s.z.object({frame:Fr,error:Mt.optional().nullable()}),kf="/frame/stream";class Wr{constructor(e,r){c(this,"stream"),c(this,"adapter"),this.stream=new as("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(kf,If,Af),l=new Wr(o,a);return o.send({start:new E(i),keys:a.keys}),l}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 pe((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 Cn.Observer{constructor(e,r){super(r),c(this,"streamer"),c(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 cs=(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))(cs||{}),At=(t=>(t[t.PersistStream=1]="PersistStream",t[t.PersistOnly=2]="PersistOnly",t[t.StreamOnly=3]="StreamOnly",t))(At||{});const xf=new I(-1),Cf=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()}),jf=s.z.object({command:s.z.nativeEnum(cs),config:Cf.optional(),frame:Fr.optional()}),Rf=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(cs),error:Mt.optional().nullable()});var nt;let go=(nt=class{constructor(t,e){c(this,"stream"),c(this,"adapter"),this.stream=new as("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:l=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:d=I.SECOND}){const f=await is.open(t,r),h=await e.stream(nt.ENDPOINT,jf,Rf),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:l,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()}},c(nt,"ENDPOINT","/frame/write"),nt),po=class{constructor(t,e,r){c(this,"streamClient"),c(this,"retriever"),c(this,"deleter"),this.streamClient=t,this.retriever=r,this.deleter=new Sf(e)}async openIterator(t,e,r){return await yo._open(t,e,this.retriever,this.streamClient,r)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await go._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}=Re(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 pe;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}=Re(t);return n==="keys"?await this.deleter.delete({keys:r,bounds:e}):await this.deleter.delete({names:r,bounds:e})}};const $f=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:xf,AUTO_SPAN:Mn,Client:po,Frame:pe,Iterator:yo,ObservableStreamer:Pt,Streamer:Wr,Writer:go,WriterMode:At,frameZ:Fr,series:co,seriesFromPayload:lo,seriesToPayload:uo},Symbol.toStringTag,{value:"Module"})),Mf=He.Authority,Df=He.stateZ(s.z.number()),Pf=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 mo extends Pt{constructor(e){super(e,r=>{const n=this.codec.decode(r.series[0].buffer);return this.merge(n),[n.transfers,!0]}),c(this,"states"),c(this,"codec"),this.states=new Map,this.codec=new Xe.JSONCodec}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 Bf="sy_node_1_control";let wo=class{constructor(t){c(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(Bf);return new mo(t)}};const Uf=Object.freeze(Object.defineProperty({__proto__:null,Authority:Mf,Client:wo,StateTracker:mo,stateZ:Df,transferString:Pf},Symbol.toStringTag,{value:"Module"}));let Lf=class{constructor(t,e,r){c(this,"tasks"),c(this,"racks"),c(this,"devices"),this.tasks=t,this.racks=e,this.devices=r}};const Bt=s.z.number(),ls=s.z.object({key:Bt,name:s.z.string()}),Yf=ls.partial({key:!0}),us=s.z.string(),Gr=s.z.object({key:us,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_CODEC.decodeString(t)))}),qf=Gr.extend({properties:s.z.unknown().transform(t=>Xe.JSON_CODEC.encodeString(t))}),Ut=async(t,e,r,n)=>{const i=await t.openStreamer([e,r]),a=o=>{const l=[];return r!=null&&l.push(...o.get(r).series.flatMap(u=>n("delete",u))),e!=null&&l.push(...o.get(e).series.flatMap(u=>n("set",u))),[l,l.length>0]};return new Pt(i,a)},Ff="sy_device_set",_f="sy_device_delete",un="/hardware/device/retrieve",Wf="/hardware/device/create",Gf="/hardware/device/delete",Zf=s.z.object({devices:qf.array()}),Vf=s.z.object({devices:Gr.array()}),Kf=s.z.object({keys:us.array()}),Jf=s.z.object({}),hn=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:us.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),dn=s.z.object({devices:Qe(Gr)});let Hf=class{constructor(t,e){c(this,"type","device"),c(this,"client"),c(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const r=!Array.isArray(t),n=await v(this.client,un,{keys:N(t),...e},hn,dn);return qr("Device",t,n.devices,r),r?n.devices[0]:n.devices}async search(t,e){return(await v(this.client,un,{search:t,...e},hn,dn)).devices}async page(t,e,r){return(await v(this.client,un,{offset:t,limit:e,...r},hn,dn)).devices}async create(t){const e=!Array.isArray(t),r=await v(this.client,Wf,{devices:N(t)},Zf,Vf);return e?r.devices[0]:r.devices}async delete(t){await v(this.client,Gf,{keys:N(t)},Kf,Jf)}async openDeviceTracker(){return await Ut(this.frameClient,Ff,_f,Xf)}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 Xf=(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})),fn="/hardware/rack/retrieve",Qf="/hardware/rack/create",ey="/hardware/rack/delete",yn=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()}),gn=s.z.object({racks:Qe(ls)}),ty=s.z.object({racks:Yf.array()}),ry=s.z.object({racks:ls.array()}),ny=s.z.object({keys:Bt.array()}),sy=s.z.object({});let iy=class{constructor(t,e,r){c(this,"type","rack"),c(this,"client"),c(this,"frameClient"),c(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=r}async delete(t){await v(this.client,ey,{keys:N(t)},ny,sy)}async create(t){const e=!Array.isArray(t),r=await v(this.client,Qf,{racks:N(t)},ty,ry),n=this.sugar(r.racks);return e?n[0]:n}async search(t){const e=await v(this.client,fn,{search:t},yn,gn);return this.sugar(e.racks)}async page(t,e){const r=await v(this.client,fn,{offset:t,limit:e},yn,gn);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,fn,{[e]:r},yn,gn),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 ay(e,r,this.tasks))}};class ay{constructor(e,r,n){c(this,"key"),c(this,"name"),c(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 Lt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),Rr=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())}),hs=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_CODEC.decodeString(t))),state:Rr.optional().nullable()}),oy=hs.omit({key:!0}).extend({key:Lt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>Xe.JSON_CODEC.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)))});const zt="sy_task_state",yi="sy_task_cmd";class cy{constructor(e,r,n,i,a,o=!1,l){c(this,"key"),c(this,"name"),c(this,"internal"),c(this,"type"),c(this,"config"),c(this,"state"),c(this,"frameClient"),this.key=e,this.name=r,this.type=n,this.config=i,this.internal=o,l!==null&&(this.state=l),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(yi),i=Uh.id();return await n.write(yi,[{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 l=new Promise(u=>setTimeout(()=>u(!1),new I(n).milliseconds));for(;;){const u=await Promise.any([i.read(),l]);if(u===!1)throw new Error("Command timed out");const d=Rr.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=Rr.safeParse(r.at(-1));if(!n.success)return[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}}const ly=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()}),uy=s.z.object({tasks:Qe(hs)}),hy="/hardware/task/retrieve",dy="/hardware/task/create",fy="/hardware/task/delete",yy=s.z.object({tasks:oy.array()}),gy=s.z.object({tasks:hs.array()}),py=s.z.object({keys:Lt.array()}),my=s.z.object({});let wy=class{constructor(t,e){c(this,"type","task"),c(this,"client"),c(this,"frameClient"),this.client=t,this.frameClient=e}async create(t){const e=!Array.isArray(t),r=await v(this.client,dy,{tasks:N(t)},yy,gy),n=this.sugar(r.tasks);return e?n[0]:n}async delete(t){await v(this.client,fy,{keys:N(t)},py,my)}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),l=this.sugar(o);return r&&i!=="rack"?l[0]:l}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,hy,t,ly,uy)).tasks}sugar(t){return t.map(({key:e,name:r,type:n,config:i,state:a,internal:o})=>new cy(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=Rr.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()}),by=s.z.object({keys:Yt.array().optional(),for:ye.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),vy=s.z.object({labels:Zr.array().optional().default([])});var Kt;let Oy=(Kt=class{constructor(t){c(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,by,vy);if(r!=null)throw r;return e.labels}},c(Kt,"ENDPOINT","/label/retrieve"),Kt);const Ty=Zr.extend({key:Yt.optional()}),Sy=s.z.object({labels:Ty.array()}),zy=s.z.object({labels:Zr.array()}),Ny=s.z.object({keys:Yt.array()}),bo=s.z.object({id:ye,labels:Yt.array()}),Ey=bo,pn=s.z.object({}),Iy="/label/create",Ay="/label/delete",ky="/label/set",xy="/label/remove";let Cy=class{constructor(t){c(this,"client"),this.client=t}async create(t){return(await v(this.client,Iy,{labels:N(t)},Sy,zy)).labels}async delete(t){await v(this.client,Ay,{keys:N(t)},Ny,pn)}async set(t,e){await v(this.client,ky,{id:t,labels:e},bo,pn)}async remove(t,e){await v(this.client,xy,{id:t,labels:e},Ey,pn)}};const jy="sy_label_set",Ry="sy_label_delete";let $y=class{constructor(t,e){c(this,"type","label"),c(this,"retriever"),c(this,"writer"),c(this,"frameClient"),this.writer=new Cy(t),this.retriever=new Oy(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,jy,Ry,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()}),vo=et.extend({key:s.z.string().uuid().optional()}),Oo=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}},To="range",So="range-alias",Dy=t=>new he({type:To,key:t}),Py=t=>new he({type:So,key:t}),By=s.z.object({}),Uy=s.z.object({range:et}),Ly=s.z.object({range:ce}),Yy=s.z.object({range:ce}),qy=s.z.object({}),Fy="/range/set-active",_y="/range/retrieve-active",Wy="/range/clear-active";class Gy{constructor(e){c(this,"client"),this.client=e}async setActive(e){await v(this.client,Fy,{range:e},Ly,By)}async retrieveActive(){const[e,r]=await this.client.send(_y,{},s.z.object({}),Uy);if(we.matches(r))return null;if(r!=null)throw r;return e.range}async clearActive(e){await v(this.client,Wy,{range:e},Yy,qy)}}const Zy="sy_range_alias_set",Vy="sy_range_alias_delete",Ky=s.z.object({range:ce,aliases:s.z.string().array()}),Jy=s.z.object({aliases:s.z.record(s.z.string(),Be)}),Hy=s.z.object({range:ce,aliases:s.z.record(Be.or(s.z.string()),s.z.string())}),Xy=s.z.unknown(),Qy=s.z.object({range:ce,channels:Be.array()}),eg=s.z.unknown(),tg=s.z.object({range:ce}),rg=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),mt=class wt{constructor(e,r,n){c(this,"frameClient"),c(this,"cache",new Map),c(this,"client"),c(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 l=this.cache.get(o);l!=null?i[o]=l:r.push(o)});if(r.length===0)return i;const a=await v(this.client,wt.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},Ky,Jy);return Object.entries(a.aliases).forEach(([o,l])=>this.cache.set(o,l)),n?a.aliases[r[0]]:{...i,...a.aliases}}async set(e){await v(this.client,wt.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Hy,Xy)}async list(){return(await v(this.client,wt.LIST_ENDPOINT,{range:this.rangeKey},tg,rg)).aliases}async delete(e){await v(this.client,wt.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},Qy,eg)}async openChangeTracker(){return await Ut(this.frameClient,Zy,Vy,ag(this.rangeKey))}};c(mt,"SET_ENDPOINT","/range/alias/set"),c(mt,"RESOLVE_ENDPOINT","/range/alias/resolve"),c(mt,"LIST_ENDPOINT","/range/alias/list"),c(mt,"DELETE_ENDPOINT","/range/alias/delete");let ng=mt;const sg=s.z.object({range:ce,channel:Be,alias:s.z.string()}),ig="---",ag=t=>(e,r)=>e==="delete"?r.toStrings().filter(n=>n.split(ig)[0]===t).map(n=>({variant:e,key:n,value:void 0})):r.parseJSON(sg).map(n=>({variant:e,key:n.alias,value:n})),og=s.z.object({range:ce,keys:s.z.string().array()}),cg=s.z.object({pairs:s.z.record(s.z.string(),s.z.string())}),lg=s.z.object({range:ce,pairs:s.z.record(s.z.string(),s.z.string())}),ug=s.z.object({range:ce,keys:s.z.string().array()}),zr=class Nr{constructor(e,r){c(this,"rangeKey"),c(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)},og,cg);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}},lg,s.z.unknown())}async delete(e){await v(this.client,Nr.DELETE_ENDPOINT,{range:this.rangeKey,keys:N(e)},ug,s.z.unknown())}};c(zr,"GET_ENDPOINT","/range/kv/get"),c(zr,"SET_ENDPOINT","/range/kv/set"),c(zr,"DELETE_ENDPOINT","/range/kv/delete");let hg=zr;const mn=t=>new he({type:"range",key:t});class zo{constructor(e,r=oe.ZERO,n,i,a,o,l,u,d){c(this,"key"),c(this,"name"),c(this,"kv"),c(this,"timeRange"),c(this,"color"),c(this,"channels"),c(this,"aliaser"),c(this,"frameClient"),c(this,"labelClient"),this.key=n,this.name=e,this.timeRange=r,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=l,this.channels=u,this.labelClient=d}async setAlias(e,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new we(`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 dg=s.z.object({keys:ce.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:oe.z.optional()}),fg="/range/retrieve",yg=s.z.object({ranges:Qe(et)});let No=class{constructor(t,e,r,n,i){c(this,"type","range"),c(this,"frameClient"),c(this,"writer"),c(this,"unaryClient"),c(this,"channels"),c(this,"active"),c(this,"labelClient"),this.frameClient=t,this.writer=e,this.unaryClient=r,this.channels=n,this.active=new Gy(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}=Oo(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,fg,t,dg,yg);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 zo(e.name,e.timeRange,e.key,e.color,this.frameClient,new hg(e.key,this.unaryClient),new ng(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 gg=s.z.object({ranges:et.array()}),pg=s.z.object({ranges:vo.array()}),mg=s.z.object({keys:ce.array()}),wg=s.z.object({}),bg=s.z.object({key:ce,name:s.z.string()}),vg=s.z.object({}),Og="/range/create",Tg="/range/delete",Sg="/range/rename";let Eo=class{constructor(t){c(this,"client"),this.client=t}async rename(t,e){await v(this.client,Sg,{key:t,name:e},bg,vg)}async create(t){return(await v(this.client,Og,{ranges:t},pg,gg)).ranges}async delete(t){await v(this.client,Tg,{keys:t},mg,wg)}};const zg=Object.freeze(Object.defineProperty({__proto__:null,Client:No,Range:zo,RangeAliasOntologyType:So,RangeOntologyType:To,Writer:Eo,analyzeParams:Oo,keyZ:ce,newPayloadZ:vo,payloadZ:et,rangeAliasOntologyID:Py,rangeOntologyID:Dy},Symbol.toStringTag,{value:"Module"})),Ng="/api/v1/";class Eg{constructor(e,r=!1){c(this,"url"),c(this,"unary"),c(this,"stream"),c(this,"secure"),this.secure=r,this.url=e.child(Ng);const n=new Xe.JSONCodec;this.unary=new Lu(this.url,n,this.secure),this.stream=new Ku(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ds=s.z.string().uuid(),fs=s.z.object({key:s.z.string(),name:s.z.string(),data:Qn.or(s.z.string().transform(t=>JSON.parse(t)))}),Ig=s.z.object({keys:s.z.string().array()}),Ag=s.z.object({linePlots:fs.array()});let kg=class{constructor(t){c(this,"ENDPOINT","/workspace/lineplot/retrieve"),c(this,"client"),this.client=t}async retrieve(t){const e=N(t);return(await v(this.client,this.ENDPOINT,{keys:e},Ig,Ag)).linePlots}};const Ge=s.z.string().uuid(),Io=t=>JSON.parse(t),Ao=s.z.object({name:s.z.string(),key:Ge,layout:Qn.or(s.z.string().transform(t=>Io(t)))}),ko=Ao.omit({layout:!0}).extend({layout:s.z.string().transform(t=>Io(t))}),xg=fs.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Cg=s.z.object({workspace:Ge,linePlots:xg.array()}),jg=s.z.object({linePlots:fs.array()}),Rg=s.z.object({keys:ds.array()}),$g=s.z.object({}),Mg=s.z.object({key:ds,name:s.z.string()}),Dg=s.z.object({}),Pg=s.z.object({key:ds,data:s.z.string()}),Bg=s.z.object({}),Ug="/workspace/lineplot/create",Lg="/workspace/lineplot/delete",Yg="/workspace/lineplot/rename",qg="/workspace/lineplot/set-data";let Fg=class{constructor(t){c(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,Ug,{workspace:t,linePlots:[r]},Cg,jg)).linePlots[0]}async delete(t){const e=N(t);await v(this.client,Lg,{keys:e},Rg,$g)}async rename(t,e){await v(this.client,Yg,{key:t,name:e},Mg,Dg)}async setData(t,e){await v(this.client,qg,{key:t,data:JSON.stringify(e)},Pg,Bg)}},_g=class{constructor(t){c(this,"writer"),c(this,"retriever"),this.writer=new Fg(t),this.retriever=new kg(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 Wg=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()}),Gg=s.z.object({workspaces:Qe(ko)});var Jt;let Zg=(Jt=class{constructor(t){c(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,Wg,Gg)).workspaces}},c(Jt,"ENDPOINT","/workspace/retrieve"),Jt);const Vr=s.z.string().uuid(),Vg=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()}),ys=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()}),Jg=s.z.object({schematics:ys.array()});class Hg{constructor(e){c(this,"ENDPOINT","/workspace/schematic/retrieve"),c(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,this.ENDPOINT,{keys:N(e)},Kg,Jg)).schematics}}const Xg=Vg.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Qg=s.z.object({workspace:Ge,schematics:Xg.array()}),ep=s.z.object({schematics:ys.array()}),tp=s.z.object({keys:Vr.array()}),rp=s.z.object({}),np=s.z.object({key:Vr,name:s.z.string()}),gi=s.z.object({}),sp=s.z.object({key:Vr,data:s.z.string()});s.z.object({});const ip=s.z.object({key:Vr,name:s.z.string(),snapshot:s.z.boolean()}),ap=s.z.object({schematic:ys}),op="/workspace/schematic/create",cp="/workspace/schematic/delete",lp="/workspace/schematic/rename",up="/workspace/schematic/set-data",hp="/workspace/schematic/copy";let dp=class{constructor(t){c(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,op,{workspace:t,schematics:[r]},Qg,ep)).schematics[0]}async copy(t,e,r){return(await v(this.client,hp,{key:t,name:e,snapshot:r},ip,ap)).schematic}async delete(t){const e=N(t);await v(this.client,cp,{keys:e},tp,rp)}async rename(t,e){await v(this.client,lp,{key:t,name:e},np,gi)}async setData(t,e){await v(this.client,up,{key:t,data:JSON.stringify(e)},sp,gi)}},fp=class{constructor(t){c(this,"writer"),c(this,"retriever"),this.writer=new dp(t),this.retriever=new Hg(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 yp=Ao.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),gp=s.z.object({workspaces:yp.array()}),pp=s.z.object({workspaces:ko.array()}),mp=s.z.object({keys:Ge.array()}),wp=s.z.object({}),bp=s.z.object({key:Ge,name:s.z.string()}),vp=s.z.object({}),Op=s.z.object({key:Ge,layout:s.z.string()}),Tp=s.z.object({}),Sp="/workspace/create",zp="/workspace/delete",Np="/workspace/rename",Ep="/workspace/set-layout";class Ip{constructor(e){c(this,"client"),this.client=e}async create(e){return(await v(this.client,Sp,{workspaces:N(e)},gp,pp)).workspaces}async delete(e){await v(this.client,zp,{keys:N(e)},mp,wp)}async rename(e,r){await v(this.client,Np,{key:e,name:r},bp,vp)}async setLayout(e,r){await v(this.client,Ep,{key:e,layout:JSON.stringify(r)},Op,Tp)}}class Ap{constructor(e){c(this,"type","workspace"),c(this,"schematic"),c(this,"linePlot"),c(this,"retriever"),c(this,"writer"),this.schematic=new fp(e),this.linePlot=new _g(e),this.retriever=new Zg(e),this.writer=new Ip(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 xo=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 Co extends po{constructor(e){const r=xo.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:l,secure:u}=r,d=new Eg(new sd({host:n,port:Number(i)}),u);d.use(dd);let f;a!=null&&o!=null&&(f=new gf(d.unary,{username:a,password:o}),d.use(f.middleware()));const h=new rs(new ts(d.unary)),M=new ro(d.unary,h);super(d.stream,d.unary,h),c(this,"createdAt"),c(this,"props"),c(this,"ranges"),c(this,"channels"),c(this,"auth"),c(this,"user"),c(this,"access"),c(this,"connectivity"),c(this,"ontology"),c(this,"workspaces"),c(this,"labels"),c(this,"hardware"),c(this,"control"),c(this,"transport"),this.createdAt=E.now(),this.props=r,this.auth=f,this.transport=d,this.channels=new to(this,h,d.unary,M),this.connectivity=new oo(d.unary,l,r.name),this.control=new wo(this),this.ontology=new xd(d.unary,this);const _=new Eo(this.transport.unary);this.labels=new $y(this.transport.unary,this),this.ranges=new No(this,_,this.transport.unary,h,this.labels),this.access=new uf(this.transport.unary),this.user=new df(this.transport.unary),this.workspaces=new Ap(this.transport.unary);const re=new Hf(this.transport.unary,this),j=new wy(this.transport.unary,this),Ho=new iy(this.transport.unary,this,j);this.hardware=new Lf(j,Ho,re)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}c(Co,"connectivity",oo);const kp=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 xp=Object.defineProperty,Cp=(t,e,r)=>e in t?xp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J=(t,e,r)=>Cp(t,typeof e!="symbol"?e+"":e,r);const Bn=class jo{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 jo(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 gs=Bn;const Un=["debug","info","warn","error"],jp=t=>{const e=Un.indexOf(t);return({level:r})=>Un.indexOf(r)>=e},Rp=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 Ro{constructor(e={}){J(this,"meta",gs.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 Ro({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 $o=Ln;const Ht=t=>typeof t=="function"?t():t;var $p=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},_e="1.8.0",pi=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function Mp(t){var e=new Set([t]),r=new Set,n=t.match(pi);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(l){return l===t};function a(l){return r.add(l),!1}function o(l){return e.add(l),!0}return function(l){if(e.has(l))return!0;if(r.has(l))return!1;var u=l.match(pi);if(!u)return a(l);var d={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return d.prerelease!=null||i.major!==d.major?a(l):i.major===0?i.minor===d.minor&&i.patch<=d.patch?o(l):a(l):i.minor<=d.minor?o(l):a(l)}}var Dp=Mp(_e),Pp=_e.split(".")[0],kt=Symbol.for("opentelemetry.js.api."+Pp),xt=$p;function ps(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||!Dp(n)))return(r=xt[kt])===null||r===void 0?void 0:r[t]}function ms(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+_e+".");var r=xt[kt];r&&delete r[t]}var Bp=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(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Up=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))},Lp=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,Up([],Bp(r),!1))}var fe;(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"})(fe||(fe={}));function Yp(t,e){t<fe.NONE?t=fe.NONE:t>fe.ALL&&(t=fe.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",fe.ERROR),warn:r("warn",fe.WARN),info:r("info",fe.INFO),debug:r("debug",fe.DEBUG),verbose:r("verbose",fe.VERBOSE)}}var qp=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(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Fp=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))},_p="diag",jt=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var l=Ct("diag");if(l)return l[i].apply(l,Fp([],qp(a),!1))}}var r=this,n=function(i,a){var o,l,u;if(a===void 0&&(a={logLevel:fe.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=Yp((l=a.logLevel)!==null&&l!==void 0?l:fe.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 ps("diag",h,r,!0)};r.setLogger=n,r.disable=function(){ms(_p,r)},r.createComponentLogger=function(i){return new Lp(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}(),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(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Gp=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.")},Zp=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=Wp(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=Gp(n),l=o.next();!l.done;l=o.next()){var u=l.value;a._entries.delete(u)}}catch(d){e={error:d}}finally{try{l&&!l.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();jt.instance();function Vp(t){return t===void 0&&(t={}),new Zp(new Map(Object.entries(t)))}function Kp(t){return Symbol.for(t)}var Jp=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}(),Hp=new Jp,Xp={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},Qp={set:function(t,e,r){t!=null&&(t[e]=r)}},em=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(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},tm=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))},rm=function(){function t(){}return t.prototype.active=function(){return Hp},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,tm([n],em(i),!1))},t.prototype.bind=function(e,r){return r},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),nm=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(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},sm=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",im=new rm,Mo=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ps(wn,e,jt.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,sm([e,r,n],nm(a),!1))},t.prototype.bind=function(e,r){return this._getContextManager().bind(e,r)},t.prototype._getContextManager=function(){return Ct(wn)||im},t.prototype.disable=function(){this._getContextManager().disable(),ms(wn,jt.instance())},t}(),Yn;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(Yn||(Yn={}));var am=Mo.getInstance(),om=function(){function t(){}return t.prototype.inject=function(e,r){},t.prototype.extract=function(e,r){return e},t.prototype.fields=function(){return[]},t}(),ws=Kp("OpenTelemetry Baggage Key");function Do(t){return t.getValue(ws)||void 0}function cm(){return Do(Mo.getInstance().active())}function lm(t,e){return t.setValue(ws,e)}function um(t){return t.deleteValue(ws)}var bn="propagation",hm=new om,dm=function(){function t(){this.createBaggage=Vp,this.getBaggage=Do,this.getActiveBaggage=cm,this.setBaggage=lm,this.deleteBaggage=um}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ps(bn,e,jt.instance())},t.prototype.inject=function(e,r,n){return n===void 0&&(n=Qp),this._getGlobalPropagator().inject(e,r,n)},t.prototype.extract=function(e,r,n){return n===void 0&&(n=Xp),this._getGlobalPropagator().extract(e,r,n)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){ms(bn,jt.instance())},t.prototype._getGlobalPropagator=function(){return Ct(bn)||hm},t}(),fm=dm.getInstance();const mi=["bench","debug","prod"],ym=t=>e=>mi.indexOf(e)>=mi.indexOf(t),qn=class Po{constructor(e,r=ym("debug")){J(this,"meta",gs.NOOP),J(this,"tracer"),J(this,"filter"),this.tracer=e,this.filter=r}child(e){const r=new Po(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 Lo(e)):this.tracer.startActiveSpan(e,i=>{const a=new Uo(e,i),o=n(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const r=am.active();fm.inject(r,e,{set:(n,i,a)=>{n[i]=a}})}};J(qn,"NOOP",new qn);let Bo=qn;class Uo{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 Lo{constructor(e){J(this,"key"),this.key=e}set(){}recordError(e){}}const Fn=class Yo{constructor({key:e="",serviceName:r="",logger:n=$o.NOOP,tracer:i=Bo.NOOP,noop:a=!1,__meta:o}){J(this,"meta"),J(this,"T"),J(this,"L"),this.meta=o??new gs(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 Yo({__meta:r,tracer:this.T,logger:this.L})}};J(Fn,"NOOP",new Fn({noop:!0}));let bs=Fn;const gm=bs.NOOP,qo=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:bs,LOG_LEVELS:Un,Logger:$o,NOOP:gm,NoopSpan:Lo,Tracer:Bo,_Span:Uo,logLevelKeyFiler:Rp,logThresholdFilter:jp},Symbol.toStringTag,{value:"Module"})),pm=new Error("request for lock canceled");var mm=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 l(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(l,u)}d((n=n.apply(t,e||[])).next())})};class wm{constructor(e,r=pm){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=Fo(this._queue,l=>r<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return mm(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]=[]),bm(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 bm(t,e){const r=Fo(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function Fo(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var vm=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 l(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(l,u)}d((n=n.apply(t,e||[])).next())})};class _o{constructor(e){this._semaphore=new wm(1,e)}acquire(){return vm(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 vs{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 me("context not defined");return this._ctx}get state(){if(this._state==null)throw new me("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:Ti.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 me(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const r=e[e.length-1];if(e.length>1)throw new me(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(r!==this.key)throw new me(`[Leaf.setState] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`)}}class qt extends vs{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),l={...r,ctx:this.ctx};return o.length===0?await this.updateThis(a,l):await this.updateChild(o,l)}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 me(`[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 l of o)await l.internalDelete([l.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 Om=s.z.object({}),Ee=class Ee extends qt{constructor({worker:r,registry:n,instrumentation:i=qo.Instrumentation.NOOP}){const o={ctx:new Kr(r,n,new Map),...Ee.ZERO_UPDATE,instrumentation:i};super(o);D(this,"wrap");D(this,"schema",Ee.schema);D(this,"mu",new _o);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=r,this.wrap.handle(l=>{this.mu.runExclusive(async()=>await this.handle(l))})}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(Ee,"TYPE","root"),D(Ee,"KEY","root"),D(Ee,"ZERO_UPDATE",{path:[Ee.KEY],type:Ee.TYPE,variant:"state",state:{}}),D(Ee,"schema",Om);let $r=Ee;const Wo=t=>new $r(t),Tm=Object.freeze(Object.defineProperty({__proto__:null,Composite:qt,Context:Kr,Leaf:vs,Root:$r,render:Wo},Symbol.toStringTag,{value:"Module"})),Go="pluto-theming-context",Sm=s.z.object({theme:Ui}),Nt=class Nt extends qt{constructor(){super(...arguments);D(this,"schema",Nt.z)}async afterUpdate(){this.ctx.set(Go,this.state.theme)}};D(Nt,"TYPE","theming.Provider"),D(Nt,"z",Sm);let Rt=Nt;const zm=t=>t.get(Go),Nm={[Rt.TYPE]:Rt},Zo=["success","error","warning","info","loading","disabled","secondary"],Vo=s.z.enum(Zo),Ko=s.z.object({key:s.z.string(),variant:Vo,message:s.z.string(),description:s.z.string().optional(),time:F.z,data:s.z.record(s.z.unknown()).optional()}),Jo=s.z.object({statuses:Ko.array()}),Os="status.aggregator";class Mr extends qt{constructor(){super(...arguments);D(this,"schema",Jo)}async afterUpdate(){this.ctx.set(Os,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 Em=t=>{const e=t.get(Os);return e.add.bind(e)},Im=t=>{const e=t.getOptional(Os);return e!=null?e.add.bind(e):()=>{}},Am={[Mr.TYPE]:Mr};exports.$=$c;exports.A=Zc;exports.Aggregator=Mr;exports.B=bs;exports.C=fl;exports.C$1=Pr;exports.ComponentSizeLevels=Bi;exports.Composite=qt;exports.E=mc;exports.Ee=me;exports.G=hl;exports.I=ae;exports.Ie=Fe;exports.L=dl;exports.LEVELS=Pi;exports.Leaf=vs;exports.LevelComponentSizes=ml;exports.Mutex=_o;exports.My=Xd;exports.N=Ei;exports.N$1=ll;exports.O=E;exports.P=G;exports.Provider=Rt;exports.Q=we;exports.REGISTRY=Nm;exports.REGISTRY$1=Am;exports.S=I;exports.S$1=cc;exports.SYNNAX_DARK=Yi;exports.SYNNAX_LIGHT=Li;exports.SYNNAX_THEMES=El;exports.U=Et;exports.V=oe;exports.VARIANTS=Zo;exports.Wy=Uf;exports.Yy=$f;exports._=Ti;exports.aether=Tm;exports.aggregatorStateZ=Jo;exports.c=vi;exports.commonjsGlobal=ec;exports.dimensions=bl;exports.executeInitialSetter=$t;exports.executeSetter=Zn;exports.fontString=xl;exports.fy=xo;exports.g=$;exports.g$1=qo;exports.getAugmentedNamespace=rc;exports.getDefaultExportFromCjs=tc;exports.i=Wn;exports.id=zg;exports.isSetter=Gn;exports.l=rl;exports.levelZ=pl;exports.m=F;exports.mt=Rc;exports.n=Kc;exports.o=Vc;exports.o$1=wc;exports.prettyParse=Pn;exports.py=Co;exports.r=bc;exports.render=Wo;exports.specZ=Me;exports.specZ$1=Ko;exports.state=gl;exports.themeZ=Ui;exports.use=zm;exports.useAggregate=Em;exports.useOptionalAggregate=Im;exports.usePassthrough=Mi;exports.usePurePassthrough=Di;exports.variantZ=Vo;exports.w=W;exports.w$1=ki;exports.wt=Mc;exports.yd=kp;exports.yt=Yc;