@synnaxlabs/pluto 0.35.2 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/dist/{Animated-B3meZ8Go.cjs → Animated-BAoBw9cC.cjs} +1 -1
  2. package/dist/Animated-DkZIfEYP.js +19 -0
  3. package/dist/Item-BjErngVu.cjs +1 -0
  4. package/dist/{Item-C3mh5Jo-.js → Item-C7Q_zqsK.js} +21 -22
  5. package/dist/LinePlot-CFpCtIU5.cjs +24 -0
  6. package/dist/LinePlot-Cyj5fPvs.js +5720 -0
  7. package/dist/{Link-C-KaB73i.cjs → Link-DIP4E5h4.cjs} +1 -1
  8. package/dist/{Link-By1w1FIv.js → Link-DkPbZ9Vw.js} +2 -2
  9. package/dist/Pack-ClLR2ywa.cjs +1 -0
  10. package/dist/Pack-D8EcIVa2.js +140 -0
  11. package/dist/Toggle-CZlnDV1Y.js +63934 -0
  12. package/dist/Toggle-Dwz8HiqJ.cjs +163 -0
  13. package/dist/{Video-BGyV37o3.js → Video-CI9sBV9l.js} +2 -2
  14. package/dist/{Video-CGe5Hscl.cjs → Video-xr1Ey5qV.cjs} +1 -1
  15. package/dist/aggregator-D6gAHK4j.js +13699 -0
  16. package/dist/aggregator-q3hNa4qv.cjs +77 -0
  17. package/dist/align.cjs +1 -1
  18. package/dist/align.js +1 -1
  19. package/dist/button.cjs +1 -1
  20. package/dist/button.js +1 -1
  21. package/dist/color.cjs +1 -1
  22. package/dist/color.js +1 -1
  23. package/dist/css-C3zWKgOb.cjs +1 -0
  24. package/dist/{css-DJCM-h5_.js → css-DnIb4t_E.js} +288 -281
  25. package/dist/css.cjs +1 -1
  26. package/dist/css.js +2 -2
  27. package/dist/dropdown.cjs +1 -1
  28. package/dist/dropdown.js +1 -1
  29. package/dist/ether.cjs +1 -1
  30. package/dist/ether.js +45 -45
  31. package/dist/{external-CDXLxcOI.js → external-6FH5NjXf.js} +2 -2
  32. package/dist/{external-Bwu7ljGW.cjs → external-8w5Eg-ce.cjs} +1 -1
  33. package/dist/external-AQutxNrw.cjs +1 -0
  34. package/dist/external-BDzzt6lF.js +75 -0
  35. package/dist/external-BX17kwZc.cjs +1 -0
  36. package/dist/{external-BeFZRZSq.js → external-BeoanEV1.js} +37 -38
  37. package/dist/{external-CDYYyyoJ.js → external-BpqHq8f8.js} +13 -13
  38. package/dist/{external-BzRCbp_C.js → external-BxiJID8F.js} +2 -2
  39. package/dist/external-C-tizEE4.js +254 -0
  40. package/dist/external-CFaZ_vCi.js +91 -0
  41. package/dist/{external-8wTAbTHd.cjs → external-CIm5lpCQ.cjs} +1 -1
  42. package/dist/{external-BEwtU2Lv.cjs → external-CXQMoMS3.cjs} +1 -1
  43. package/dist/{external-DRBGP7qn.js → external-CetHCRLx.js} +37 -37
  44. package/dist/{external-BRbXi-YB.js → external-Ckaptp3S.js} +78 -79
  45. package/dist/external-Cy8UF9vk.cjs +1 -0
  46. package/dist/{external-k9_z2UE6.cjs → external-Czhk9fZS.cjs} +1 -1
  47. package/dist/{external-DaWss0D_.cjs → external-DAn-_GLc.cjs} +1 -1
  48. package/dist/{external-1M4_dCzb.cjs → external-DlCfhkx8.cjs} +1 -1
  49. package/dist/external-DtsEr2ls.cjs +1 -0
  50. package/dist/{external-Dk1cXh1i.cjs → external-Lmd8cJhx.cjs} +1 -1
  51. package/dist/external-bByVUOOg.cjs +1 -0
  52. package/dist/{external-CTvBPOgF.js → external-feiUnuJI.js} +2 -2
  53. package/dist/{external-xhGCeglf.js → external-wgG3P6Dp.js} +1 -1
  54. package/dist/{external-D08DFJfB.js → external-xPdBJlsz.js} +12 -12
  55. package/dist/header.cjs +1 -1
  56. package/dist/header.js +1 -1
  57. package/dist/index.cjs +7 -7
  58. package/dist/index.js +5177 -5461
  59. package/dist/input.cjs +1 -1
  60. package/dist/input.js +1 -1
  61. package/dist/jsx-runtime-DGh1k5sI.cjs +31 -0
  62. package/dist/jsx-runtime-Dx-03ztt.js +445 -0
  63. package/dist/list.cjs +1 -1
  64. package/dist/list.js +1 -1
  65. package/dist/menu.cjs +1 -1
  66. package/dist/menu.js +1 -1
  67. package/dist/pluto.css +1 -0
  68. package/dist/src/aether/main.d.ts +1 -1
  69. package/dist/src/aether/main.d.ts.map +1 -1
  70. package/dist/src/align/Center.d.ts +1 -1
  71. package/dist/src/align/Center.d.ts.map +1 -1
  72. package/dist/src/align/Pack.d.ts.map +1 -1
  73. package/dist/src/align/Space.d.ts +1 -0
  74. package/dist/src/align/Space.d.ts.map +1 -1
  75. package/dist/src/breadcrumb/Breadcrumb.d.ts +3 -2
  76. package/dist/src/breadcrumb/Breadcrumb.d.ts.map +1 -1
  77. package/dist/src/button/Button.d.ts +5 -4
  78. package/dist/src/button/Button.d.ts.map +1 -1
  79. package/dist/src/button/Toggle.d.ts +2 -2
  80. package/dist/src/channel/LinePlot.d.ts +2 -1
  81. package/dist/src/channel/LinePlot.d.ts.map +1 -1
  82. package/dist/src/css/css.d.ts +1 -1
  83. package/dist/src/css/css.d.ts.map +1 -1
  84. package/dist/src/form/Field.d.ts.map +1 -1
  85. package/dist/src/generic/Generic.d.ts +1 -1
  86. package/dist/src/generic/Generic.d.ts.map +1 -1
  87. package/dist/src/haul/Haul.d.ts +2 -2
  88. package/dist/src/haul/Haul.d.ts.map +1 -1
  89. package/dist/src/hooks/useClickOutside.d.ts +1 -1
  90. package/dist/src/hooks/useClickOutside.d.ts.map +1 -1
  91. package/dist/src/hooks/useCursorDrag/types.d.ts +1 -1
  92. package/dist/src/hooks/useCursorDrag/types.d.ts.map +1 -1
  93. package/dist/src/icon/Icon.d.ts +5 -5
  94. package/dist/src/icon/Icon.d.ts.map +1 -1
  95. package/dist/src/input/DateTime.d.ts +20 -3
  96. package/dist/src/input/DateTime.d.ts.map +1 -1
  97. package/dist/src/input/Item.d.ts.map +1 -1
  98. package/dist/src/input/Switch.d.ts.map +1 -1
  99. package/dist/src/input/Text.d.ts +2 -1
  100. package/dist/src/input/Text.d.ts.map +1 -1
  101. package/dist/src/input/types.d.ts +2 -0
  102. package/dist/src/input/types.d.ts.map +1 -1
  103. package/dist/src/list/Selector.d.ts.map +1 -1
  104. package/dist/src/main.d.ts +1 -0
  105. package/dist/src/main.d.ts.map +1 -0
  106. package/dist/src/mock/MockGLBufferController.d.ts +2 -2
  107. package/dist/src/mock/MockGLBufferController.d.ts.map +1 -1
  108. package/dist/src/note/Note.d.ts +2 -1
  109. package/dist/src/note/Note.d.ts.map +1 -1
  110. package/dist/src/pluto/Pluto.d.ts.map +1 -1
  111. package/dist/src/resize/Multiple.d.ts +1 -1
  112. package/dist/src/resize/Multiple.d.ts.map +1 -1
  113. package/dist/src/select/Alignment.d.ts +2 -1
  114. package/dist/src/select/Alignment.d.ts.map +1 -1
  115. package/dist/src/select/Button.d.ts +4 -1
  116. package/dist/src/select/Button.d.ts.map +1 -1
  117. package/dist/src/select/Direction.d.ts +2 -1
  118. package/dist/src/select/Direction.d.ts.map +1 -1
  119. package/dist/src/select/Single.d.ts +1 -0
  120. package/dist/src/select/Single.d.ts.map +1 -1
  121. package/dist/src/status/aether/aggregator.d.ts.map +1 -1
  122. package/dist/src/status/aether/types.d.ts.map +1 -1
  123. package/dist/src/synnax/aether/provider.d.ts +141 -0
  124. package/dist/src/synnax/aether/provider.d.ts.map +1 -1
  125. package/dist/src/table/aether/Table.d.ts.map +1 -1
  126. package/dist/src/table/cells/Cells.d.ts.map +1 -1
  127. package/dist/src/tabs/types.d.ts +2 -1
  128. package/dist/src/tabs/types.d.ts.map +1 -1
  129. package/dist/src/tag/Tag.d.ts +2 -1
  130. package/dist/src/tag/Tag.d.ts.map +1 -1
  131. package/dist/src/telem/aether/remote.d.ts.map +1 -1
  132. package/dist/src/telem/aether/static.d.ts +9 -9
  133. package/dist/src/telem/aether/transformers.d.ts.map +1 -1
  134. package/dist/src/telem/control/aether/chip.d.ts.map +1 -1
  135. package/dist/src/telem/control/aether/controller.d.ts.map +1 -1
  136. package/dist/src/telem/control/aether/indicator.d.ts.map +1 -1
  137. package/dist/src/telem/control/aether/legend.d.ts.map +1 -1
  138. package/dist/src/telem/control/aether/state.d.ts.map +1 -1
  139. package/dist/src/text/DateTime.d.ts +1 -1
  140. package/dist/src/text/DateTime.d.ts.map +1 -1
  141. package/dist/src/text/Editable.d.ts.map +1 -1
  142. package/dist/src/text/Keyboard.d.ts +1 -1
  143. package/dist/src/text/Keyboard.d.ts.map +1 -1
  144. package/dist/src/text/Link.d.ts.map +1 -1
  145. package/dist/src/text/Text.d.ts.map +1 -1
  146. package/dist/src/tooltip/Dialog.d.ts +7 -1
  147. package/dist/src/tooltip/Dialog.d.ts.map +1 -1
  148. package/dist/src/tree/Tree.d.ts.map +1 -1
  149. package/dist/src/tree/core.d.ts +2 -1
  150. package/dist/src/tree/core.d.ts.map +1 -1
  151. package/dist/src/triggers/hooks.d.ts +1 -1
  152. package/dist/src/triggers/hooks.d.ts.map +1 -1
  153. package/dist/src/triggers/useDrag.d.ts +1 -1
  154. package/dist/src/triggers/useDrag.d.ts.map +1 -1
  155. package/dist/src/util/renderProp.d.ts +1 -1
  156. package/dist/src/util/renderProp.d.ts.map +1 -1
  157. package/dist/src/viewport/SelectMode.d.ts.map +1 -1
  158. package/dist/src/viewport/use.d.ts.map +1 -1
  159. package/dist/src/vis/canvas/aether/canvas.d.ts.map +1 -1
  160. package/dist/src/vis/diagram/Diagram.d.ts +2 -1
  161. package/dist/src/vis/diagram/Diagram.d.ts.map +1 -1
  162. package/dist/src/vis/diagram/aether/Diagram.d.ts.map +1 -1
  163. package/dist/src/vis/diagram/aether/types.d.ts +2 -2
  164. package/dist/src/vis/diagram/aether/types.d.ts.map +1 -1
  165. package/dist/src/vis/diagram/edge/paths.d.ts +1 -1
  166. package/dist/src/vis/diagram/edge/paths.d.ts.map +1 -1
  167. package/dist/src/vis/eraser/aether/eraser.d.ts.map +1 -1
  168. package/dist/src/vis/legend/Container.d.ts +1 -1
  169. package/dist/src/vis/legend/Container.d.ts.map +1 -1
  170. package/dist/src/vis/lineplot/LinePlot.d.ts +1 -0
  171. package/dist/src/vis/lineplot/LinePlot.d.ts.map +1 -1
  172. package/dist/src/vis/lineplot/Viewport.d.ts.map +1 -1
  173. package/dist/src/vis/lineplot/aether/LinePlot.d.ts.map +1 -1
  174. package/dist/src/vis/lineplot/aether/YAxis.d.ts.map +1 -1
  175. package/dist/src/vis/lineplot/aether/axis.d.ts.map +1 -1
  176. package/dist/src/vis/lineplot/range/aether/annotation.d.ts.map +1 -1
  177. package/dist/src/vis/lineplot/range/aether/provider.d.ts.map +1 -1
  178. package/dist/src/vis/lineplot/tooltip/aether/tooltip.d.ts.map +1 -1
  179. package/dist/src/vis/log/aether/Log.d.ts +6 -6
  180. package/dist/src/vis/log/aether/Log.d.ts.map +1 -1
  181. package/dist/src/vis/measure/aether/measure.d.ts.map +1 -1
  182. package/dist/src/vis/rule/Rule.d.ts +4 -1
  183. package/dist/src/vis/rule/Rule.d.ts.map +1 -1
  184. package/dist/src/vis/rule/aether/aether.d.ts +1 -0
  185. package/dist/src/vis/rule/aether/aether.d.ts.map +1 -1
  186. package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
  187. package/dist/src/vis/schematic/Grid.d.ts +7 -2
  188. package/dist/src/vis/schematic/Grid.d.ts.map +1 -1
  189. package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
  190. package/dist/src/vis/value/aether/value.d.ts.map +1 -1
  191. package/dist/src/vis/value/use.d.ts.map +1 -1
  192. package/dist/tabs.cjs +1 -1
  193. package/dist/tabs.js +1 -1
  194. package/dist/text.cjs +1 -1
  195. package/dist/text.js +2 -2
  196. package/dist/theming.cjs +1 -1
  197. package/dist/theming.js +2 -2
  198. package/dist/tree.cjs +1 -1
  199. package/dist/tree.js +1 -1
  200. package/dist/triggers.cjs +1 -1
  201. package/dist/triggers.js +1 -1
  202. package/dist/{units-D19WggGS.js → units-CKQQRvyD.js} +1 -1
  203. package/dist/{units-9h1yAbxY.cjs → units-YvMXZR11.cjs} +1 -1
  204. package/dist/video.cjs +1 -1
  205. package/dist/video.js +1 -1
  206. package/package.json +55 -53
  207. package/dist/Animated-BMxljHxY.js +0 -19
  208. package/dist/Item-DsAGorI8.cjs +0 -1
  209. package/dist/Keyboard-D-76mv1a.cjs +0 -1
  210. package/dist/Keyboard-DbyeBAzq.js +0 -25
  211. package/dist/LinePlot-DbXPZbQH.cjs +0 -34
  212. package/dist/LinePlot-DqoSTxNs.js +0 -6534
  213. package/dist/List-CZxRbYfm.cjs +0 -1
  214. package/dist/List-S1wnpuEv.js +0 -22
  215. package/dist/Pack-BzCJQZ58.js +0 -137
  216. package/dist/Pack-Dvf8sQVK.cjs +0 -1
  217. package/dist/Text-Bq9B_1wQ.cjs +0 -1
  218. package/dist/Text-tqSP4klc.js +0 -32
  219. package/dist/Toggle-DcPmH9Uq.js +0 -44517
  220. package/dist/Toggle-DrfPMqBr.cjs +0 -143
  221. package/dist/aggregator-23mu0FOF.js +0 -12640
  222. package/dist/aggregator-y-jNJhKX.cjs +0 -67
  223. package/dist/css-BghghSL0.cjs +0 -1
  224. package/dist/external-BFHPc8Ng.cjs +0 -1
  225. package/dist/external-Brk-4hys.cjs +0 -1
  226. package/dist/external-CY1bjqlD.js +0 -76
  227. package/dist/external-CxBbtPtX.cjs +0 -1
  228. package/dist/external-DOQ51UTh.cjs +0 -1
  229. package/dist/external-DcKg8NOr.js +0 -127
  230. package/dist/external-bMSKTtt-.cjs +0 -1
  231. package/dist/external-fvuMSTBJ.js +0 -248
  232. package/dist/jsx-runtime-B6kdoens.js +0 -634
  233. package/dist/jsx-runtime-Cek9Ww4S.cjs +0 -30
  234. package/dist/style.css +0 -1
@@ -1,67 +0,0 @@
1
- "use strict";var cc=Object.defineProperty;var uc=(t,e,n)=>e in t?cc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var P=(t,e,n)=>uc(t,typeof e!="symbol"?e+"":e,n);const s=require("zod"),O=require("./css-BghghSL0.cjs"),$s=require("react"),Vt=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var hc=Object.defineProperty,dc=(t,e,n)=>e in t?hc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Wt=(t,e,n)=>dc(t,typeof e!="symbol"?e+"":e,n);let fc=class{constructor(){Wt(this,"contentType","application/json"),Wt(this,"decoder"),Wt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,n){return this.decodeString(this.decoder.decode(e),n)}decodeString(e,n){const r=JSON.parse(e),i=O.k(r);return n!=null?n.parse(i):i}encodeString(e){const n=O.C(e);return JSON.stringify(n,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):Vt(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},yc=class{constructor(){Wt(this,"contentType","text/csv")}encode(e){const n=this.encodeString(e);return new TextEncoder().encode(n).buffer}decode(e,n){const r=new TextDecoder().decode(e);return this.decodeString(r,n)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Vt(e[0]))throw new Error("Payload must be an array of objects");const n=Object.keys(e[0]),r=[n.join(",")];return e.forEach(i=>{const a=n.map(o=>JSON.stringify(i[o]??""));r.push(a.join(","))}),r.join(`
2
- `)}decodeString(e,n){const[r,...i]=e.trim().split(`
3
- `).map(c=>c.trim());if(r.length===0)return n!=null?n.parse({}):{};const a=r.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(h=>h.trim());a.forEach((h,f)=>{const d=this.parseValue(u[f]);d!=null&&o[h].push(d)})}),n!=null?n.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const n=Number(e);return isNaN(n)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:n}static registerCustomType(){}},gc=class{constructor(){Wt(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,n){const r=new TextDecoder().decode(e);return n!=null?n.parse(r):r}};const zn=new fc;new yc;new gc;const Qr=t=>[...new Set(t)],Sa=t=>t!=null&&typeof t=="object"&&"toString"in t,pc=t=>{if(Sa(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}},ur=(t,e=!1)=>{const n=Sa(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?Na(r):r},mc=(t,e,n)=>{const r=ur(e[t],n);return(i,a)=>r(i[t],a[t])},wc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((n,r)=>n===e[r])?0:-1,za=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const n=ur(t[0]),r=[...t].sort(n),i=[...e].sort(n);return r.every((a,o)=>a===i[o])?0:-1},bc=(t,e)=>{const n=Qr(t),r=Qr(e);return za(n,r)},vc=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Na=t=>(e,n)=>t(n,e),ft=0,Nn=-1,En=1,Ea=t=>t<ft,Ia=t=>t>ft,Oc=t=>t>=ft,ka=t=>t===ft,Tc=(t,e)=>{const n=/([a-zA-Z]+)|(\d+)/g,r=t.replace(/[\s_.-]+/g,"").match(n),i=e.replace(/[\s_.-]+/g,"").match(n);if(!r||!i)return 0;for(let a=0;a<Math.min(r.length,i.length);a++){const o=r[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return r.length-i.length},Sc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:ft,GREATER_THAN:En,LESS_THAN:Nn,isEqualTo:ka,isGreaterThan:Ia,isGreaterThanEqual:Oc,isLessThan:Ea,newF:ur,newFieldF:mc,order:vc,primitiveArrays:wc,reverseF:Na,stringsWithNumbers:Tc,uniqueUnorderedPrimitiveArrays:bc,unorderedPrimitiveArrays:za},Symbol.toStringTag,{value:"Module"})),zc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},Nc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n===null&&(n=setTimeout(()=>{t(...r),n=null},e))}},Aa=(t,e,n=".")=>{const r=t.split(n);return r.map((i,a)=>{const o=e(i,a,r);return o==null?null:typeof o=="string"?o:o.join(n)}).filter(i=>i!=null).join(n)},js=(t,e,n={optional:!1,separator:"."})=>{n.separator??(n.separator=".");const{optional:r,getter:i=(c,u)=>c[u]}=n,a=e.split(n.separator);if(a.length===1&&a[0]==="")return t;let o=t;for(const c of a){const u=i(o,c);if(u==null){if(r)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o},Ec=(t,e,n)=>{const r=e.split(".");let i=t;for(let a=0;a<r.length-1;a++){const o=r[a];i[o]??(i[o]={}),i=i[o]}try{i[r[r.length-1]]=n}catch(a){throw console.error("failed to set value",n,"at path",e,"on object",t),a}},Ic=(t,e)=>{const n=e.split(".");let r=t;for(let i=0;i<n.length-1;i++){const a=n[i];if(r[a]==null)return;r=r[a]}if(Array.isArray(r)){const i=parseInt(n[n.length-1]);if(isNaN(i))return;r.splice(i,1);return}delete r[n[n.length-1]]},kc=(t,e)=>{const n=t.split(".");return e<0?n[n.length+e]:n[e]},Ac=(t,e)=>{try{return js(t,e),!0}catch{return!1}},xc=(t,e)=>{if(e.length===0)return!0;const n=t.split("."),r=e.split(".");if(r.length>n.length)return!1;for(let i=0;i<r.length;i++){const a=n[i],o=r[i];if(o!=="*"&&a!==o)return!1}return!0},Cc=t=>JSON.parse(JSON.stringify(t)),$c=(t,...e)=>(e.forEach(n=>{let r=t;const i=n.split(".");i.forEach((a,o)=>{o===i.length-1?delete r[a]:a in r&&(r=r[a])})}),t),jc=(t,e,n="")=>{const r={},i=(a,o,c)=>{if(typeof a!=typeof o||a===null||o===null){r[c]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){r[c]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${c}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],c!==""?`${c}.${u}`:u)});else a!==o&&(r[c]=[a,o])};return i(t,e,n),r},es=(t,e)=>{const n=Array.isArray(t),r=Array.isArray(e);if(n!==r)return!1;if(n&&r){const o=t,c=e;if(o.length!==c.length)return!1;for(let u=0;u<o.length;u++)if(!es(o[u],c[u]))return!1;return!0}if(t==null||e==null||typeof t!="object"||typeof e!="object")return t===e;if("equals"in t)return t.equals(e);const i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(const o of i){const c=t[o],u=e[o];if(typeof c=="object"&&typeof u=="object"){if(!es(c,u))return!1}else if(c!==u)return!1}return!0},xa=(t,e)=>{if(typeof t!="object"||t==null)return t===e;const n=Object.keys(t),r=Object.keys(e);if(r.length>n.length)return!1;for(const i of r){const a=t[i],o=e[i];if(typeof a=="object"&&typeof o=="object"){if(!xa(a,o))return!1}else if(a!==o)return!1}return!0},ts=(t,...e)=>{if(e.length===0)return t;const n=e.shift();if(Vt(t)&&Vt(n))for(const r in n)try{Vt(n[r])?(r in t||Object.assign(t,{[r]:{}}),ts(t[r],n[r])):Object.assign(t,{[r]:n[r]})}catch(i){throw i instanceof TypeError?new TypeError(`.${r}: ${i.message}`):i}return ts(t,...e)},Rc=(t,e,n)=>{const r=(i,a,o)=>{for(const c in a){const u=a[c];if(o!=null&&o.shape[c]){const h=o.shape[c].safeParse(u);h.success&&(i[c]=h.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[c]&&(i[c]||(i[c]={}),r(i[c],u,o.shape[c]))}return i};return r({...t},e,n)},Ca=Object.freeze(Object.defineProperty({__proto__:null,copy:Cc,deleteD:$c,difference:jc,element:kc,equal:es,get:js,has:Ac,override:ts,overrideValidItems:Rc,partialEqual:xa,pathsMatch:xc,remove:Ic,set:Ec,transformPath:Aa},Symbol.toStringTag,{value:"Module"})),$a=t=>Aa(t,(e,n,r)=>{const i=n===r.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(r[n+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),di=(t,e)=>{if(t==null)return null;const n=t[e];return n==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:n},Mc=(t,e,n)=>js(di(t,"shape"),$a(e),{...n,getter:di}),Bc=(t,e)=>n=>{const r=e.find(i=>i.safeParse(n).success);return r==null?null:t(r.parse(n))},ja=s.z.bigint().or(s.z.string().transform(BigInt)),Dc=Object.freeze(Object.defineProperty({__proto__:null,bigInt:ja,getFieldSchema:Mc,getFieldSchemaPath:$a,transformer:Bc},Symbol.toStringTag,{value:"Module"}));var Pc=Object.defineProperty,Uc=(t,e,n)=>e in t?Pc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e,n)=>Uc(t,typeof e!="symbol"?e+"":e,n);let Lc=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const _c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ra=Lc(_c,11),Ma=Object.freeze(Object.defineProperty({__proto__:null,id:Ra},Symbol.toStringTag,{value:"Module"})),Yc=s.z.enum(["static","dynamic"]),Ba=(t,e)=>{const n=new W(e);if(![Z.DAY,Z.HOUR,Z.MINUTE,Z.SECOND,Z.MILLISECOND,Z.MICROSECOND,Z.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof W?new W(r):new Z(r)},U=class S{constructor(e,n="UTC"){if(y(this,"value"),y(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,n).valueOf();else if(Array.isArray(e))this.value=S.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=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())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,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,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=S.hours(parseInt(r??"00")).add(S.minutes(parseInt(i??"00"))).add(S.seconds(parseInt(o??"00"))).add(S.milliseconds(parseInt(c??"00")));return n==="local"&&(u=u.add(S.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return S.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new S(BigInt(r.getTime())*S.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(S.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Z(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 at(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 Ba(this,e)}get isToday(){return this.truncate(Z.DAY).equals(S.now().truncate(Z.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new S(new Date)}static max(...e){let n=S.MIN;for(const r of e){const i=new S(r);i.after(n)&&(n=i)}return n}static min(...e){let n=S.MAX;for(const r of e){const i=new S(r);i.before(n)&&(n=i)}return n}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)}};y(U,"NANOSECOND",U.nanoseconds(1)),y(U,"MICROSECOND",U.microseconds(1)),y(U,"MILLISECOND",U.milliseconds(1)),y(U,"SECOND",U.seconds(1)),y(U,"MINUTE",U.minutes(1)),y(U,"HOUR",U.hours(1)),y(U,"DAY",U.days(1)),y(U,"MAX",new U((1n<<63n)-1n)),y(U,"MIN",new U(0)),y(U,"ZERO",new U(0)),y(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 W=U;const L=class E{constructor(e){y(this,"value"),y(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof E?e:e instanceof ns?e.period:e instanceof W?new E(e):["number","bigint"].includes(typeof e)?E.seconds(e):new E(e)}static fromMilliseconds(e){return e instanceof E?e:e instanceof ns?e.period:e instanceof W?new E(e):["number","bigint"].includes(typeof e)?E.milliseconds(e):new E(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new E(e).valueOf()}greaterThan(e){return this.valueOf()>new E(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new E(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new E(e).valueOf()}remainder(e){return Ba(this,e)}truncate(e){return new E(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(E.DAY),n=this.truncate(E.HOUR),r=this.truncate(E.MINUTE),i=this.truncate(E.SECOND),a=this.truncate(E.MILLISECOND),o=this.truncate(E.MICROSECOND),c=this.truncate(E.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),A=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),A.isZero||(M+=`${A.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.trim()}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new E(e).valueOf()}add(e){return new E(this.valueOf()+new E(e).valueOf())}sub(e){return new E(this.valueOf()-new E(e).valueOf())}static nanoseconds(e=1){return new E(e)}static microseconds(e=1){return E.nanoseconds(O.M(e,1e3))}static milliseconds(e=1){return E.microseconds(O.M(e,1e3))}static seconds(e=1){return E.milliseconds(O.M(e,1e3))}static minutes(e=1){return E.seconds(O.M(e,60))}static hours(e){return E.minutes(O.M(e,60))}static days(e){return E.hours(O.M(e,24))}};y(L,"NANOSECOND",L.nanoseconds(1)),y(L,"MICROSECOND",L.microseconds(1)),y(L,"MILLISECOND",L.milliseconds(1)),y(L,"SECOND",L.seconds(1)),y(L,"MINUTE",L.minutes(1)),y(L,"HOUR",L.hours(1)),y(L,"DAY",L.days(1)),y(L,"MAX",new L((1n<<63n)-1n)),y(L,"MIN",new L(0)),y(L,"ZERO",new L(0)),y(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 Z=L;const Nt=class In extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new In(e).valueOf()}get period(){return Z.seconds(1/this.valueOf())}sampleCount(e){return new Z(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ce(n).valueOf()}span(e){return Z.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new In(e)}static khz(e){return In.hz(e*1e3)}};y(Nt,"z",s.z.union([s.z.number().transform(t=>new Nt(t)),s.z.instanceof(Number).transform(t=>new Nt(t)),s.z.instanceof(Nt)]));let ns=Nt;const te=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Ht(e*this.valueOf())}};y(te,"UNKNOWN",new te(0)),y(te,"BIT128",new te(16)),y(te,"BIT64",new te(8)),y(te,"BIT32",new te(4)),y(te,"BIT16",new te(2)),y(te,"BIT8",new te(1)),y(te,"z",s.z.union([s.z.number().transform(t=>new te(t)),s.z.instanceof(Number).transform(t=>new te(t)),s.z.instanceof(te)]));let ce=te;const Se=class kn{constructor(e,n){y(this,"start"),y(this,"end"),typeof e=="object"&&"start"in e?(this.start=new W(e.start),this.end=new W(e.end)):(this.start=new W(e),this.end=new W(n))}get span(){return new Z(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new kn(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,n=Z.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=W.max(r.start,e.start),a=W.min(r.end,e.end);return a.before(i)?!1:new Z(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof kn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new kn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};y(Se,"MAX",new Se(W.MIN,W.MAX)),y(Se,"MIN",new Se(W.MAX,W.MIN)),y(Se,"ZERO",new Se(W.ZERO,W.ZERO)),y(Se,"z",s.z.union([s.z.object({start:W.z,end:W.z}).transform(t=>new Se(t.start,t.end)),s.z.instanceof(Se)]));let at=Se;const p=class ze extends String{constructor(e){if(e instanceof ze||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const n=ze.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}throw super(ze.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=ze.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(ze.JSON)||this.equals(ze.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(ze.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=ze.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return ze.BIG_INT_TYPES.some(e=>e.equals(this))}};y(p,"UNKNOWN",new p("unknown")),y(p,"FLOAT64",new p("float64")),y(p,"FLOAT32",new p("float32")),y(p,"INT64",new p("int64")),y(p,"INT32",new p("int32")),y(p,"INT16",new p("int16")),y(p,"INT8",new p("int8")),y(p,"UINT64",new p("uint64")),y(p,"UINT32",new p("uint32")),y(p,"UINT16",new p("uint16")),y(p,"UINT8",new p("uint8")),y(p,"BOOLEAN",p.UINT8),y(p,"TIMESTAMP",new p("timestamp")),y(p,"UUID",new p("uuid")),y(p,"STRING",new p("string")),y(p,"JSON",new p("json")),y(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]])),y(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]])),y(p,"DENSITIES",new Map([[p.UINT8.toString(),ce.BIT8],[p.UINT16.toString(),ce.BIT16],[p.UINT32.toString(),ce.BIT32],[p.UINT64.toString(),ce.BIT64],[p.FLOAT32.toString(),ce.BIT32],[p.FLOAT64.toString(),ce.BIT64],[p.INT8.toString(),ce.BIT8],[p.INT16.toString(),ce.BIT16],[p.INT32.toString(),ce.BIT32],[p.INT64.toString(),ce.BIT64],[p.TIMESTAMP.toString(),ce.BIT64],[p.STRING.toString(),ce.UNKNOWN],[p.JSON.toString(),ce.UNKNOWN],[p.UUID.toString(),ce.BIT128]])),y(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]),y(p,"BIG_INT_TYPES",[p.INT64,p.UINT64,p.TIMESTAMP]),y(p,"z",s.z.union([s.z.string().transform(t=>new p(t)),s.z.instanceof(p)]));let R=p;const ae=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),n=this.truncate(K.GIGABYTE),r=this.truncate(K.MEGABYTE),i=this.truncate(K.KILOBYTE),a=this.truncate(K.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.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}};y(ae,"BYTE",new ae(1)),y(ae,"KILOBYTE",ae.kilobytes(1)),y(ae,"MEGABYTE",ae.megabytes(1)),y(ae,"GIGABYTE",ae.gigabytes(1)),y(ae,"TERABYTE",ae.terabytes(1)),y(ae,"ZERO",new ae(0)),y(ae,"z",s.z.union([s.z.number().transform(t=>new ae(t)),s.z.instanceof(ae)]));let Ht=ae;const Fc=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)]),Da=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof W||t instanceof Z||t instanceof Date},qc=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):It(n,-r).valueOf(),Vc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Pa?!0:Da(t),Ue=-1,rs={[Symbol.iterator]:()=>rs,next:()=>({done:!0,value:void 0})},Wc=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Gc=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ss=10,Et=class Ne{constructor(e){y(this,"key",""),y(this,"isSynnaxSeries",!0),y(this,"dataType"),y(this,"sampleOffset"),y(this,"gl"),y(this,"_data"),y(this,"_timeRange"),y(this,"alignment",0n),y(this,"_cachedMin"),y(this,"_cachedMax"),y(this,"writePos",Ue),y(this,"_refCount",0),y(this,"_cachedLength"),y(this,"_cachedIndexes"),Vc(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Ra()}=e,u=e.data??[];if(u instanceof Ne||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this._timeRange=d._timeRange,this.alignment=d.alignment,this._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=Da(u),f=Array.isArray(u);if(n!=null)this.dataType=new R(n);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||h){let d=u;if(!h){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.");d=u[0]}if(typeof d=="string")this.dataType=R.STRING;else if(typeof d=="number")this.dataType=R.FLOAT64;else if(typeof d=="bigint")this.dataType=R.INT64;else if(typeof d=="boolean")this.dataType=R.BOOLEAN;else if(d instanceof W||d instanceof Date||d instanceof W)this.dataType=R.TIMESTAMP;else if(typeof d=="object")this.dataType=R.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new R(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const A=d[0];(A instanceof W||A instanceof Date||A instanceof Z)&&(d=d.map(D=>new W(D).valueOf())),this.dataType.equals(R.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
4
- `)}
5
- `)):this.dataType.equals(R.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(D=>zn.encodeString(D)).join(`
6
- `)}
7
- `)):this._data=new this.dataType.Array(d).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new R(n).Array(e),a=new Ne({data:i.buffer,dataType:n,...r});return a.writePos=0,a}static generateTimestamps(e,n,r){const i=r.spanRange(n.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(r.add(n.span(o)).valueOf());return new Ne({data:a,dataType:R.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,n){const r=new TextEncoder().encode(`${e.join(`
8
- `)}
9
- `);return new Ne({data:r,dataType:R.STRING,timeRange:n})}static fromJSON(e,n){const r=new TextEncoder().encode(`${e.map(i=>zn.encodeString(i)).join(`
10
- `)}
11
- `);return new Ne({data:r,dataType:R.JSON,timeRange:n})}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");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Ue)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===Ue)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}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.matches(R.STRING,R.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
12
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(R.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=R.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+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");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
13
- `).slice(0,-1).map(n=>e.parse(zn.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Ht(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ue?this.byteCapacity:this.dataType.isVariable?new Ht(this.writePos):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;const n=[0];return this.data.forEach((r,i)=>{r===ss&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=qc(this.dataType,e,this.data[i],n);return new Ne({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(R.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}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??(this._cachedMax=this.calcRawMax()),It(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(R.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}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??(this._cachedMin=this.calcRawMin()),It(this._cachedMin,this.sampleOffset))}get bounds(){return O.i(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return It(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return It(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===ss){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(R.STRING)?new TextDecoder().decode(a):O.k(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=ur(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(R.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ue}as(e){if(e==="string"){if(!this.dataType.equals(R.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(R.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.i(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 Zc(this);return this.dataType.equals(R.JSON)?new Jc(e):e}return new Kc(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new fi(this,e,n??this.length)}subAlignmentIterator(e,n){return new fi(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ne({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ne({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ne({data:this.buffer,dataType:this.dataType,timeRange:at.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};y(Et,"crudeZ",s.z.object({timeRange:at.z.optional(),dataType:R.z,alignment:ja.optional(),data:s.z.union([Wc,Gc,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Yc.optional().default("static").optional()})),y(Et,"z",Et.crudeZ.transform(t=>new Et(t)));let Pa=Et,fi=class{constructor(e,n,r){y(this,"series"),y(this,"end"),y(this,"index"),this.series=e;const i=O.i(0,e.length);this.end=O.T(i,r),this.index=O.T(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}},Zc=class{constructor(e){if(y(this,"series"),y(this,"index"),y(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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ss;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}};var yi,gi;let Jc=class{constructor(e){y(this,"wrapped"),y(this,yi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:zn.decodeString(e.value)}}[(gi=Symbol.iterator,yi=Symbol.toStringTag,gi)](){return this}};var pi,mi;class Kc{constructor(e){y(this,"series"),y(this,"index"),y(this,pi,"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)}}[(mi=Symbol.iterator,pi=Symbol.toStringTag,mi)](){return this}}const It=(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 Hc=class{constructor(e){if(y(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new R(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?R.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?at.ZERO:new at(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?O.i(0n,0n):O.i(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(O.a(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ir(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return rs;let r=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)r+=o.length;else if(O.a(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(O.a(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ir(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return rs;let r=0;for(let i=0;i<this.series.length;i++){const a=this.series[i];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)r+=a.length;else if(O.a(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ir(this,r,r+n)}get byteLength(){return new Ht(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.k$1(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.U(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Xc(this.series)}};var wi,bi;let Xc=class{constructor(e){y(this,"series"),y(this,"seriesIndex"),y(this,"internal"),y(this,wi,"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())}[(bi=Symbol.iterator,wi=Symbol.toStringTag,bi)](){return this}},Ir=class{constructor(e,n,r){y(this,"series"),y(this,"index"),y(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Ua=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Qc=Ua(),La=["MacOS","Windows","Linux","Docker"],eu=s.z.enum(La);let kr;const tu=()=>{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:n}=t;return e??kr??(kr=tu(),kr??n)},_a=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:La,RUNTIME:Qc,detect:Ua,getOS:nu,osZ:eu},Symbol.toStringTag,{value:"Module"})),ru=t=>Array.isArray(t)?t:[t],su=t=>Array.isArray(t)?t:t===null?[]:[t];var iu=Object.defineProperty,au=(t,e,n)=>e in t?iu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kt=(t,e,n)=>au(t,typeof e!="symbol"?e+"":e,n);const ou=(...t)=>t.map(Ya).join(""),Ya=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),lu=t=>t.endsWith("/")?t.slice(0,-1):t,vi=class is{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){kt(this,"protocol"),kt(this,"host"),kt(this,"port"),kt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=Ya(i)}replace(e){return new is({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new is({...this,pathPrefix:ou(this.path,e)})}toString(){return lu(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};kt(vi,"UNKNOWN",new vi({host:"unknown",port:0}));var cu=Object.defineProperty,uu=(t,e,n)=>e in t?cu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nr=(t,e,n)=>uu(t,typeof e!="symbol"?e+"":e,n);let hu=class{constructor(e){nr(this,"sender"),nr(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var n;const r=(n=this.handlers.get(e.type))==null?void 0:n.handler;r==null?console.warn(`No handler for ${e.type}`):r(e.payload)}route(e){const n=du(e,this.sender),r=new fu(n);return this.handlers.set(e,r),r}};const du=(t,e)=>(n,r)=>e({type:t,payload:n},r);let fu=class{constructor(e){nr(this,"_send"),nr(this,"handler"),this._send=e,this.handler=null}send(e,n=[]){this._send(e,n)}handle(e){this.handler=e}};var yu=Object.defineProperty,gu=(t,e,n)=>e in t?yu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,An=(t,e,n)=>gu(t,typeof e!="symbol"?e+"":e,n);const Ge=class extends Number{};An(Ge,"Absolute",255),An(Ge,"Default",1),An(Ge,"z",s.z.union([s.z.instanceof(Ge),s.z.number().int().min(0).max(255).transform(t=>new Ge(t)),s.z.instanceof(Number).transform(t=>new Ge(t))]));let Fa=Ge;const qa=s.z.object({name:s.z.string(),key:s.z.string()}),pu=t=>s.z.object({subject:qa,resource:t,authority:Fa.z}),mu=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),wu=Object.freeze(Object.defineProperty({__proto__:null,Authority:Fa,filterTransfersByChannelKey:mu,stateZ:pu,subjectZ:qa},Symbol.toStringTag,{value:"Module"})),Va=class At extends Error{constructor(){super(At.MESSAGE)}matches(e){return typeof e=="string"?e.includes(At.MESSAGE):e instanceof At||e.message.includes(At.MESSAGE)}};An(Va,"MESSAGE","canceled");let bu=Va;new bu;const vu=t=>t?-1:1,as=s.z.string().regex(/^\d+\.\d+\.\d+$/),an=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=as.parse(t),i=as.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Nn;if(a>u)return En}if(n.checkMinor){if(o<h)return Nn;if(o>h)return En}if(n.checkPatch){if(c<f)return Nn;if(c>f)return En}return ft},Ou=(t,e,n={})=>ka(an(t,e,n)),Wa=(t,e,n={})=>Ia(an(t,e,n)),Tu=(t,e,n={})=>Ea(an(t,e,n)),Su=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},zu=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(an).pop();if(a==null)return h=>{if(h.version??(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
14
- Returning default instead.
15
- `),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Wa(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],A=d(h);return c=!0,u(A)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},Nu=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:an,createMigration:Su,migrator:zu,semVerNewer:Wa,semVerOlder:Tu,semVerZ:as,versionsEqual:Ou},Symbol.toStringTag,{value:"Module"})),Eu=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()},Iu=t=>Array.isArray(t)?[...t]:typeof t=="object"&&t!==null?{...t}:t,Rs=t=>typeof t=="function",Ms=(t,e)=>Rs(t)?t(e):t,on=t=>Ga(t)?t():t,Ga=t=>typeof t=="function",Za=({initial:t,value:e,onChange:n})=>{const[r,i]=$s.useState(on(e??t));return e!=null&&n!=null?[e,n]:[r,i]},Ja=({initial:t,value:e,onChange:n})=>{const[r,i]=$s.useState(on(e??t));return e!=null&&n!=null?[e,n]:[r,i]},ku=(t,e)=>{const[n,r]=$s.useState(()=>{const i=localStorage.getItem(e);return i==null?on(t):JSON.parse(i)});return[n,i=>{r(i),localStorage.setItem(e,JSON.stringify(i))}]},Au=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:on,executeSetter:Ms,isInitialSetter:Ga,isSetter:Rs,usePassthrough:Za,usePersisted:ku,usePurePassthrough:Ja},Symbol.toStringTag,{value:"Module"})),Ka=["h1","h2","h3","h4","h5","p","small"],xu=s.z.enum(Ka),Cu={h1:"h2",h2:"h3",h3:"h4",h4:"h5",h5:"p",p:"small",small:"small"},$u=t=>Cu[t],ju={h1:"h1",h2:"h1",h3:"h2",h4:"h3",h5:"h4",p:"h5",small:"p"},Ru=t=>ju[t],Mu=["normal","bold","bolder","lighter"],Bu=s.z.union([s.z.number(),s.z.enum(Mu)]),Fe=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()}),Ha={small:"small",medium:"p",large:"h5",huge:"h2"},Du={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let Oi=null;const Pu=()=>(Oi??(Oi=document.createElement("canvas")),Oi),Uu=(t,e,n)=>{if(_a.RUNTIME==="node")return{width:0,height:0};n??(n=Pu().getContext("2d")),n.font=e;const r=n.measureText(t);return{width:Math.trunc(Math.abs(r.actualBoundingBoxLeft)+Math.abs(r.actualBoundingBoxRight)),height:Math.trunc(Math.abs(r.actualBoundingBoxAscent)+Math.abs(r.actualBoundingBoxDescent))}},Lu=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}),we=(t,e)=>[t[0],t[1],e,t[3]],_u=s.z.object({m2:O.Color.z,m1:O.Color.z,z:O.Color.z,p1:O.Color.z,p2:O.Color.z}),mn=_u.or(O.Color.z.transform(t=>{const e=t.hsla;return{m2:new O.Color(O.fromHSLA(we(e,40))),m1:new O.Color(O.fromHSLA(we(e,45))),z:t,p1:new O.Color(O.fromHSLA(we(e,55))),p2:new O.Color(O.fromHSLA(we(e,65)))}})),Xa=s.z.object({name:s.z.string(),key:s.z.string(),colors:s.z.object({border:O.Color.z,primary:mn,gray:Lu,error:mn,secondary:mn,warning:mn,palettes:s.z.record(O.paletteZ),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(),codeFamily:s.z.string(),h1:Fe,h2:Fe,h3:Fe,h4:Fe,h5:Fe,p:Fe,small:Fe})}).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)),Yu="'Inter Variable', sans-serif",Fu="'Geist Mono', monospace",qu=6,wt=[357,91,55,1],bt=[58,100,50,1],Vu=["#FDFDFD","#FAFAFA","#F3F3F3","#EAEAEA","#D8D8D8","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],vt=Object.fromEntries(Vu.map((t,e)=>[`l${e}`,t])),os={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:vt,border:vt.l3,error:{m2:O.fromHSLA(we(wt,30)),m1:O.fromHSLA(we(wt,40)),z:O.fromHSLA(wt),p1:O.fromHSLA(we(wt,65)),p2:O.fromHSLA(we(wt,77))},warning:{m2:O.fromHSLA(we(bt,30)),m1:O.fromHSLA(we(bt,40)),z:O.fromHSLA(bt),p1:O.fromHSLA(we(bt,65)),p2:O.fromHSLA(we(bt,75))},palettes:{recent:{key:"recent",name:"Recent",swatches:[]}},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:vt.l9,textInverted:vt.l0,textOnPrimary:vt.l0},sizes:{base:qu,border:{radius:3,width:1},schematic:{elementStrokeWidth:2}},typography:{family:Yu,codeFamily:Fu,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.6666,weight:"medium",lineHeight:2.6666*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}}},Qa=Object.freeze({...os,key:"synnaxLight",name:"Synnax Light"}),Wu=["#020202","#0A0A0A","#131313","#1E1E1E","#2E2E2E","#444444","#646464","#8A8A8A","#AFAFAF","#D5D5D5","#FDFDFD"],Ot=Object.fromEntries(Wu.map((t,e)=>[`l${e}`,t])),eo=Object.freeze({...os,key:"synnaxDark",name:"Synnax Dark",colors:{...os.colors,gray:Ot,logo:"var(--pluto-text-color)",border:Ot.l3,text:Ot.l9,textInverted:Ot.l0,textOnPrimary:Ot.l10}}),Gu={synnaxDark:eo,synnaxLight:Qa},Zu=["small","medium","large","huge"],Ju=s.z.enum(Zu),Ku=t=>Ju.safeParse(t).success,Hu=(t,{level:e,weight:n,code:r})=>{const{typography:i,sizes:{base:a}}=t,o=i[Ku(e)?Ha[e]:e].size,c=(a*o).toFixed(1),u=r?i.codeFamily:i.family,[h,f]=u.split(", ");return n!=null?` ${n} ${c}px ${h}, ${f}`:` ${c}px ${u}`};var Xu=Object.defineProperty,Qu=(t,e,n)=>e in t?Xu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,l=(t,e,n)=>Qu(t,typeof e!="symbol"?e+"":e,n);const T=t=>Array.isArray(t)?t:[t];var eh=Object.defineProperty,th=(t,e,n)=>e in t?eh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,B=(t,e,n)=>th(t,typeof e!="symbol"?e+"":e,n);const nh=t=>{const e=t.replace(/_[a-z]/g,n=>n[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},to=t=>{const e=(n,r=ls)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!Ar(n))return n;r=ih(r);const i={},a=n;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(Ar(c)?Si(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&Ti(c)&&(c=[...c].map(h=>{let f=h;return Ar(h)?Si(f,r.keepTypesOnRecursion)||(f=e(h,r)):Ti(h)&&(f=e({key:h},r).key),f}))),i[u]=c}),i};return e},no=to(nh),rh=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),sh=to(rh),ls={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},ih=(t=ls)=>(t.recursive==null?t=ls:t.recursiveInArray??(t.recursiveInArray=!1),t),Ti=t=>t!=null&&Array.isArray(t),Ar=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Si=(t,e)=>(e||[]).some(n=>t instanceof n),ro=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var ah=Object.defineProperty,oh=(t,e,n)=>e in t?ah(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Gt=(t,e,n)=>oh(t,typeof e!="symbol"?e+"":e,n);let lh=class{constructor(){Gt(this,"contentType","application/json"),Gt(this,"decoder"),Gt(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 n=JSON.parse(t),r=no(n);return e!=null?e.parse(r):r}encodeString(t){const e=sh(t);return JSON.stringify(e,(n,r)=>ArrayBuffer.isView(r)?Array.from(r):ro(r)&&"encode_value"in r?typeof r.value=="bigint"?r.value.toString():r.value:typeof r=="bigint"?r.toString():r)}static registerCustomType(){}},ch=class{constructor(){Gt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const n=new TextDecoder().decode(t);return this.decodeString(n,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!ro(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),n=[e.join(",")];return t.forEach(r=>{const i=e.map(a=>JSON.stringify(r[a]??""));n.push(i.join(","))}),n.join(`
16
- `)}decodeString(t,e){const[n,...r]=t.trim().split(`
17
- `).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);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(){}},uh=class{constructor(){Gt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const xn=new lh;new ch;new uh;const hr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const so=s.z.object({width:s.z.number(),height:s.z.number()}),hh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),dh=["width","height"];s.z.enum(dh);const fh=["start","center","end"],yh=["signedWidth","signedHeight"];s.z.enum(yh);const rr=s.z.object({x:s.z.number(),y:s.z.number()}),gh=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),ph=["x","y"],io=s.z.enum(ph),ao=["top","right","bottom","left"];s.z.enum(ao);const mh=["left","right"],oo=s.z.enum(mh),wh=["top","bottom"],lo=s.z.enum(wh),co=["center"],zi=s.z.enum(co),bh=[...ao,...co],uo=s.z.enum(bh);s.z.enum(fh);const vh=["first","last"];s.z.enum(vh);const Oh=s.z.object({lower:s.z.number(),upper:s.z.number()}),Th=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Oh,hr]);s.z.union([Th,hr]);s.z.union([io,uo]);s.z.union([io,uo,s.z.instanceof(String)]);const Sh=t=>typeof t=="bigint"||t instanceof BigInt,et=(t,e)=>Sh(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),He=(t,e)=>{const n={};if(typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else return Ni(t);return Ni(n)},Ni=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,Ei=(t,e)=>{const n=He(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e};s.z.object({x:oo.or(zi),y:lo.or(zi)});const zh=s.z.object({x:oo,y:lo}),Nh=Object.freeze({x:"left",y:"top"}),Eh=(t,e)=>t.x===e.x&&t.y===e.y,Ii=s.z.union([s.z.number(),rr,hr,so,hh,gh]),Ih=(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}},ki=Object.freeze({x:0,y:0}),wn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:wn,left:wn,width:wn,height:wn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:rr,two:rr,root:zh});const Bs=(t,e,n=0,r=0,i)=>{const a={one:{...ki},two:{...ki},root:i??Nh};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+n,y:a.one.y+r},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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},xr=t=>{const e=Bs(t);return{lower:e.one.x,upper:e.two.x}},Cr=t=>{const e=Bs(t);return{lower:e.one.y,upper:e.two.y}},kh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var Ah=Object.defineProperty,xh=(t,e,n)=>e in t?Ah(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Me=(t,e,n)=>xh(t,typeof e!="symbol"?e+"":e,n);const Ch=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Ii,scale:Ii});s.z.object({offset:s.z.number(),scale:s.z.number()});const $h=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],jh=t=>(e,n,r,i)=>[e,i?r/t:r*t],Rh=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},Mh=t=>(e,n,r)=>[t,r],Bh=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},Dh=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=Ch(r,i,a),[e,r]},cs=class xt{constructor(){Me(this,"ops",[]),Me(this,"currBounds",null),Me(this,"currType",null),Me(this,"reversed",!1),this.ops=[]}static translate(e){return new xt().translate(e)}static magnify(e){return new xt().magnify(e)}static scale(e,n){return new xt().scale(e,n)}translate(e){const n=this.new(),r=$h(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=jh(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=He(e,n),i=this.new(),a=Rh(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=He(e,n),i=this.new(),a=Dh(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=He(e,n),i=this.new(),a=Mh(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Bh();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new xt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};Me(cs,"IDENTITY",new cs);let Ai=cs;const xi=class je{constructor(e=new Ai,n=new Ai,r=null){Me(this,"x"),Me(this,"y"),Me(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new je().translate(e,n)}static translateX(e){return new je().translateX(e)}static translateY(e){return new je().translateY(e)}static clamp(e){return new je().clamp(e)}static magnify(e){return new je().magnify(e)}static scale(e){return new je().scale(e)}static reBound(e){return new je().reBound(e)}translate(e,n){const r=Ih(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(kh(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!Eh(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(xr(e)),n.y=n.y.scale(Cr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(xr(e)),n.y=this.y.reBound(Cr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(xr(e)),n.y=this.y.clamp(Cr(e)),n}copy(){const e=new je;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Bs(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}};Me(xi,"IDENTITY",new xi);const Ph=t=>t!=null&&typeof t=="object"&&"toString"in t,Uh=(t,e=!1)=>{const n=Ph(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?Lh(r):r},Lh=t=>(e,n)=>t(n,e),_h=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([so,_h,rr,hr]);const Yh=s.z.bigint().or(s.z.string().transform(BigInt));var Fh=Object.defineProperty,qh=(t,e,n)=>e in t?Fh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e,n)=>qh(t,typeof e!="symbol"?e+"":e,n);let Vh=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const Wh="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Gh=Vh(Wh,11),Zh=s.z.enum(["static","dynamic"]),ho=(t,e)=>{const n=new G(e);if(![Q.DAY,Q.HOUR,Q.MINUTE,Q.SECOND,Q.MILLISECOND,Q.MICROSECOND,Q.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof G?new G(r):new Q(r)},_=class z{constructor(e,n="UTC"){if(b(this,"value"),b(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,n).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=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())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,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,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=z.hours(parseInt(r??"00")).add(z.minutes(parseInt(i??"00"))).add(z.seconds(parseInt(o??"00"))).add(z.milliseconds(parseInt(c??"00")));return n==="local"&&(u=u.add(z.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new z(BigInt(r.getTime())*z.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Q(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 Ds(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 ho(this,e)}get isToday(){return this.truncate(Q.DAY).equals(z.now().truncate(Q.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let n=z.MIN;for(const r of e){const i=new z(r);i.after(n)&&(n=i)}return n}static min(...e){let n=z.MAX;for(const r of e){const i=new z(r);i.before(n)&&(n=i)}return n}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)}};b(_,"NANOSECOND",_.nanoseconds(1)),b(_,"MICROSECOND",_.microseconds(1)),b(_,"MILLISECOND",_.milliseconds(1)),b(_,"SECOND",_.seconds(1)),b(_,"MINUTE",_.minutes(1)),b(_,"HOUR",_.hours(1)),b(_,"DAY",_.days(1)),b(_,"MAX",new _((1n<<63n)-1n)),b(_,"MIN",new _(0)),b(_,"ZERO",new _(0)),b(_,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new _(t.value)),s.z.string().transform(t=>new _(BigInt(t))),s.z.instanceof(Number).transform(t=>new _(t)),s.z.number().transform(t=>new _(t)),s.z.instanceof(_)]));let G=_;const Y=class I{constructor(e){b(this,"value"),b(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof I?e:e instanceof Ci?e.period:e instanceof G?new I(e):["number","bigint"].includes(typeof e)?I.seconds(e):new I(e)}static fromMilliseconds(e){return e instanceof I?e:e instanceof Ci?e.period:e instanceof G?new I(e):["number","bigint"].includes(typeof e)?I.milliseconds(e):new I(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new I(e).valueOf()}greaterThan(e){return this.valueOf()>new I(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new I(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new I(e).valueOf()}remainder(e){return ho(this,e)}truncate(e){return new I(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(I.DAY),n=this.truncate(I.HOUR),r=this.truncate(I.MINUTE),i=this.truncate(I.SECOND),a=this.truncate(I.MILLISECOND),o=this.truncate(I.MICROSECOND),c=this.truncate(I.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),A=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),A.isZero||(M+=`${A.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.trim()}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(I.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(I.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new I(e).valueOf()}add(e){return new I(this.valueOf()+new I(e).valueOf())}sub(e){return new I(this.valueOf()-new I(e).valueOf())}static nanoseconds(e=1){return new I(e)}static microseconds(e=1){return I.nanoseconds(et(e,1e3))}static milliseconds(e=1){return I.microseconds(et(e,1e3))}static seconds(e=1){return I.milliseconds(et(e,1e3))}static minutes(e=1){return I.seconds(et(e,60))}static hours(e){return I.minutes(et(e,60))}static days(e){return I.hours(et(e,24))}};b(Y,"NANOSECOND",Y.nanoseconds(1)),b(Y,"MICROSECOND",Y.microseconds(1)),b(Y,"MILLISECOND",Y.milliseconds(1)),b(Y,"SECOND",Y.seconds(1)),b(Y,"MINUTE",Y.minutes(1)),b(Y,"HOUR",Y.hours(1)),b(Y,"DAY",Y.days(1)),b(Y,"MAX",new Y((1n<<63n)-1n)),b(Y,"MIN",new Y(0)),b(Y,"ZERO",new Y(0)),b(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 Q=Y;const Ct=class Cn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Cn(e).valueOf()}get period(){return Q.seconds(1/this.valueOf())}sampleCount(e){return new Q(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ue(n).valueOf()}span(e){return Q.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new Cn(e)}static khz(e){return Cn.hz(e*1e3)}};b(Ct,"z",s.z.union([s.z.number().transform(t=>new Ct(t)),s.z.instanceof(Number).transform(t=>new Ct(t)),s.z.instanceof(Ct)]));let Ci=Ct;const ne=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new us(e*this.valueOf())}};b(ne,"UNKNOWN",new ne(0)),b(ne,"BIT128",new ne(16)),b(ne,"BIT64",new ne(8)),b(ne,"BIT32",new ne(4)),b(ne,"BIT16",new ne(2)),b(ne,"BIT8",new ne(1)),b(ne,"z",s.z.union([s.z.number().transform(t=>new ne(t)),s.z.instanceof(Number).transform(t=>new ne(t)),s.z.instanceof(ne)]));let ue=ne;const Ee=class $n{constructor(e,n){b(this,"start"),b(this,"end"),typeof e=="object"&&"start"in e?(this.start=new G(e.start),this.end=new G(e.end)):(this.start=new G(e),this.end=new G(n))}get span(){return new Q(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new $n(this.end,this.start)}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,n=Q.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=G.max(r.start,e.start),a=G.min(r.end,e.end);return a.before(i)?!1:new Q(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof $n?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new $n(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};b(Ee,"MAX",new Ee(G.MIN,G.MAX)),b(Ee,"MIN",new Ee(G.MAX,G.MIN)),b(Ee,"ZERO",new Ee(G.ZERO,G.ZERO)),b(Ee,"z",s.z.union([s.z.object({start:G.z,end:G.z}).transform(t=>new Ee(t.start,t.end)),s.z.instanceof(Ee)]));let Ds=Ee;const m=class Ie extends String{constructor(e){if(e instanceof Ie||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const n=Ie.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}throw super(Ie.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Ie.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(Ie.JSON)||this.equals(Ie.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Ie.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Ie.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 Ie.BIG_INT_TYPES.some(e=>e.equals(this))}};b(m,"UNKNOWN",new m("unknown")),b(m,"FLOAT64",new m("float64")),b(m,"FLOAT32",new m("float32")),b(m,"INT64",new m("int64")),b(m,"INT32",new m("int32")),b(m,"INT16",new m("int16")),b(m,"INT8",new m("int8")),b(m,"UINT64",new m("uint64")),b(m,"UINT32",new m("uint32")),b(m,"UINT16",new m("uint16")),b(m,"UINT8",new m("uint8")),b(m,"BOOLEAN",m.UINT8),b(m,"TIMESTAMP",new m("timestamp")),b(m,"UUID",new m("uuid")),b(m,"STRING",new m("string")),b(m,"JSON",new m("json")),b(m,"ARRAY_CONSTRUCTORS",new Map([[m.UINT8.toString(),Uint8Array],[m.UINT16.toString(),Uint16Array],[m.UINT32.toString(),Uint32Array],[m.UINT64.toString(),BigUint64Array],[m.FLOAT32.toString(),Float32Array],[m.FLOAT64.toString(),Float64Array],[m.INT8.toString(),Int8Array],[m.INT16.toString(),Int16Array],[m.INT32.toString(),Int32Array],[m.INT64.toString(),BigInt64Array],[m.TIMESTAMP.toString(),BigInt64Array],[m.STRING.toString(),Uint8Array],[m.JSON.toString(),Uint8Array],[m.UUID.toString(),Uint8Array]])),b(m,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,m.UINT8],[Uint16Array.name,m.UINT16],[Uint32Array.name,m.UINT32],[BigUint64Array.name,m.UINT64],[Float32Array.name,m.FLOAT32],[Float64Array.name,m.FLOAT64],[Int8Array.name,m.INT8],[Int16Array.name,m.INT16],[Int32Array.name,m.INT32],[BigInt64Array.name,m.INT64]])),b(m,"DENSITIES",new Map([[m.UINT8.toString(),ue.BIT8],[m.UINT16.toString(),ue.BIT16],[m.UINT32.toString(),ue.BIT32],[m.UINT64.toString(),ue.BIT64],[m.FLOAT32.toString(),ue.BIT32],[m.FLOAT64.toString(),ue.BIT64],[m.INT8.toString(),ue.BIT8],[m.INT16.toString(),ue.BIT16],[m.INT32.toString(),ue.BIT32],[m.INT64.toString(),ue.BIT64],[m.TIMESTAMP.toString(),ue.BIT64],[m.STRING.toString(),ue.UNKNOWN],[m.JSON.toString(),ue.UNKNOWN],[m.UUID.toString(),ue.BIT128]])),b(m,"ALL",[m.UNKNOWN,m.FLOAT64,m.FLOAT32,m.INT64,m.INT32,m.INT16,m.INT8,m.UINT64,m.UINT32,m.UINT16,m.UINT8,m.TIMESTAMP,m.UUID,m.STRING,m.JSON]),b(m,"BIG_INT_TYPES",[m.INT64,m.UINT64,m.TIMESTAMP]),b(m,"z",s.z.union([s.z.string().transform(t=>new m(t)),s.z.instanceof(m)]));let F=m;const oe=class H extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return H.bytes(this.valueOf()+e.valueOf())}sub(e){return H.bytes(this.valueOf()-e.valueOf())}truncate(e){return new H(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return H.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/H.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/H.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/H.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/H.TERABYTE.valueOf()}toString(){const e=this.truncate(H.TERABYTE),n=this.truncate(H.GIGABYTE),r=this.truncate(H.MEGABYTE),i=this.truncate(H.KILOBYTE),a=this.truncate(H.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new H(e)}static kilobytes(e=1){return H.bytes(e.valueOf()*1e3)}static megabytes(e=1){return H.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return H.megabytes(e.valueOf()*1e3)}static terabytes(e){return H.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};b(oe,"BYTE",new oe(1)),b(oe,"KILOBYTE",oe.kilobytes(1)),b(oe,"MEGABYTE",oe.megabytes(1)),b(oe,"GIGABYTE",oe.gigabytes(1)),b(oe,"TERABYTE",oe.terabytes(1)),b(oe,"ZERO",new oe(0)),b(oe,"z",s.z.union([s.z.number().transform(t=>new oe(t)),s.z.instanceof(oe)]));let us=oe;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 fo=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof G||t instanceof Q||t instanceof Date},Jh=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):jt(n,-r).valueOf(),Kh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Qh?!0:fo(t),Le=-1,Hh=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Xh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),hs=10,$t=class ke{constructor(e){b(this,"key",""),b(this,"isSynnaxSeries",!0),b(this,"dataType"),b(this,"sampleOffset"),b(this,"gl"),b(this,"_data"),b(this,"_timeRange"),b(this,"alignment",0n),b(this,"_cachedMin"),b(this,"_cachedMax"),b(this,"writePos",Le),b(this,"_refCount",0),b(this,"_cachedLength"),b(this,"_cachedIndexes"),Kh(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Gh()}=e,u=e.data??[];if(u instanceof ke||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this._timeRange=d._timeRange,this.alignment=d.alignment,this._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=fo(u),f=Array.isArray(u);if(n!=null)this.dataType=new F(n);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||h){let d=u;if(!h){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.");d=u[0]}if(typeof d=="string")this.dataType=F.STRING;else if(typeof d=="number")this.dataType=F.FLOAT64;else if(typeof d=="bigint")this.dataType=F.INT64;else if(typeof d=="boolean")this.dataType=F.BOOLEAN;else if(d instanceof G||d instanceof Date||d instanceof G)this.dataType=F.TIMESTAMP;else if(typeof d=="object")this.dataType=F.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new F(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const A=d[0];(A instanceof G||A instanceof Date||A instanceof Q)&&(d=d.map(D=>new G(D).valueOf())),this.dataType.equals(F.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
18
- `)}
19
- `)):this.dataType.equals(F.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(D=>xn.encodeString(D)).join(`
20
- `)}
21
- `)):this._data=new this.dataType.Array(d).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new F(n).Array(e),a=new ke({data:i.buffer,dataType:n,...r});return a.writePos=0,a}static generateTimestamps(e,n,r){const i=r.spanRange(n.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(r.add(n.span(o)).valueOf());return new ke({data:a,dataType:F.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,n){const r=new TextEncoder().encode(`${e.join(`
22
- `)}
23
- `);return new ke({data:r,dataType:F.STRING,timeRange:n})}static fromJSON(e,n){const r=new TextEncoder().encode(`${e.map(i=>xn.encodeString(i)).join(`
24
- `)}
25
- `);return new ke({data:r,dataType:F.JSON,timeRange:n})}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");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Le)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===Le)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}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.matches(F.STRING,F.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
26
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(F.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=F.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+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");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(F.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
27
- `).slice(0,-1).map(n=>e.parse(xn.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new us(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Le?this.byteCapacity:this.dataType.isVariable?new us(this.writePos):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;const n=[0];return this.data.forEach((r,i)=>{r===hs&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Jh(this.dataType,e,this.data[i],n);return new ke({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(F.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}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??(this._cachedMax=this.calcRawMax()),jt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(F.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}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??(this._cachedMin=this.calcRawMin()),jt(this._cachedMin,this.sampleOffset))}get bounds(){return He(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return jt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return jt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===hs){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(F.STRING)?new TextDecoder().decode(a):no(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=Uh(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(F.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Le}as(e){if(e==="string"){if(!this.dataType.equals(F.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(F.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 He(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 ed(this);return this.dataType.equals(F.JSON)?new td(e):e}return new nd(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new $i(this,e,n??this.length)}subAlignmentIterator(e,n){return new $i(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new ke({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new ke({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new ke({data:this.buffer,dataType:this.dataType,timeRange:Ds.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};b($t,"crudeZ",s.z.object({timeRange:Ds.z.optional(),dataType:F.z,alignment:Yh.optional(),data:s.z.union([Hh,Xh,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Zh.optional().default("static").optional()})),b($t,"z",$t.crudeZ.transform(t=>new $t(t)));let Qh=$t;class $i{constructor(e,n,r){b(this,"series"),b(this,"end"),b(this,"index"),this.series=e;const i=He(0,e.length);this.end=Ei(i,r),this.index=Ei(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class ed{constructor(e){if(b(this,"series"),b(this,"index"),b(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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==hs;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var ji,Ri;class td{constructor(e){b(this,"wrapped"),b(this,ji,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:xn.decodeString(e.value)}}[(Ri=Symbol.iterator,ji=Symbol.toStringTag,Ri)](){return this}}var Mi,Bi;class nd{constructor(e){b(this,"series"),b(this,"index"),b(this,Mi,"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)}}[(Bi=Symbol.iterator,Mi=Symbol.toStringTag,Bi)](){return this}}const jt=(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);s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const yo=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",rd=yo(),go=["MacOS","Windows","Linux","Docker"],sd=s.z.enum(go);let $r;const id=()=>{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"},ad=(t={})=>{const{force:e,default:n}=t;return e??$r??($r=id(),$r??n)},po=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:go,RUNTIME:rd,detect:yo,getOS:ad,osZ:sd},Symbol.toStringTag,{value:"Module"}));var od=Object.defineProperty,ld=(t,e,n)=>e in t?od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Rt=(t,e,n)=>ld(t,typeof e!="symbol"?e+"":e,n);const cd=(...t)=>t.map(mo).join(""),mo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),ud=t=>t.endsWith("/")?t.slice(0,-1):t,hd=(t,e="")=>t===null?"":`?${Object.entries(t).filter(([,n])=>n==null?!1:Array.isArray(n)?n.length>0:!0).map(([n,r])=>`${e}${n}=${r}`).join("&")}`,ds=class fs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Rt(this,"protocol"),Rt(this,"host"),Rt(this,"port"),Rt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=mo(i)}replace(e){return new fs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new fs({...this,pathPrefix:cd(this.path,e)})}toString(){return ud(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Rt(ds,"UNKNOWN",new ds({host:"unknown",port:0}));let dd=ds;var fd=Object.defineProperty,yd=(t,e,n)=>e in t?fd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,jn=(t,e,n)=>yd(t,typeof e!="symbol"?e+"":e,n);const tt=class extends Number{};jn(tt,"Absolute",255),jn(tt,"Default",1),jn(tt,"z",s.z.union([s.z.instanceof(tt),s.z.number().int().min(0).max(255).transform(t=>new tt(t)),s.z.instanceof(Number).transform(t=>new tt(t))]));s.z.object({name:s.z.string(),key:s.z.string()});const wo=class Mt extends Error{constructor(){super(Mt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Mt.MESSAGE):e instanceof Mt||e.message.includes(Mt.MESSAGE)}};jn(wo,"MESSAGE","canceled");let gd=wo;new gd;s.z.string().regex(/^\d+\.\d+\.\d+$/);const fe=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 Te=class extends Error{constructor(){super(...arguments),B(this,"discriminator","FreighterError"),B(this,"type","")}};const pd=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},Di="unknown",Pi="nil",md="freighter",ln=s.z.object({type:s.z.string(),data:s.z.string()});class wd{constructor(){B(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Pi,data:""};if(pd(e))for(const n of this.providers){const r=n.encode(e);if(r!=null)return r}return{type:Di,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Pi)return null;if(e.type===Di)return new Ui(e.data);for(const n of this.providers){const r=n.decode(e);if(r!=null)return r}return new Ui(e.data)}}const bo=new wd,vo=({encode:t,decode:e})=>bo.register({encode:t,decode:e}),Ps=t=>bo.decode(t);class Ui extends Te{constructor(){super(...arguments),B(this,"type","unknown")}}const dr="freighter.",Rn=class Oo extends Te{constructor(){super("EOF"),B(this,"type",Oo.TYPE)}};B(Rn,"TYPE",`${dr}eof`),B(Rn,"matches",fe(Rn.TYPE));let qe=Rn;const Mn=class To extends Te{constructor(){super("StreamClosed"),B(this,"type",To.TYPE)}};B(Mn,"TYPE",`${dr}stream_closed`),B(Mn,"matches",fe(Mn.TYPE));let ot=Mn;const Bn=class So extends Te{constructor(e={}){const{message:n="Unreachable",url:r=dd.UNKNOWN}=e;super(n),B(this,"type",So.TYPE),B(this,"url"),this.url=r}};B(Bn,"TYPE",`${dr}unreachable`),B(Bn,"matches",fe(Bn.TYPE));let Xe=Bn;const bd=t=>{if(!t.type.startsWith(md))return null;if(qe.matches(t))return{type:qe.TYPE,data:"EOF"};if(ot.matches(t))return{type:ot.TYPE,data:"StreamClosed"};if(Xe.matches(t))return{type:Xe.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},vd=t=>{if(!t.type.startsWith(dr))return null;switch(t.type){case qe.TYPE:return new qe;case ot.TYPE:return new ot;case Xe.TYPE:return new Xe;default:throw new Error(`Unknown error type: ${t.data}`)}};vo({encode:bd,decode:vd});let zo=class{constructor(){B(this,"middleware",[])}use(...t){this.middleware.push(...t)}async executeMiddleware(t,e){let n=0;const r=async i=>{if(n===this.middleware.length)return await e(i);const a=this.middleware[n];return n++,await a(i,r)};return await r(t)}};const No="Content-Type",Li=t=>{if(po.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const n=require("https"),r=new n.Agent({rejectUnauthorized:!1});return async(i,a)=>await e(i,{...a,agent:r})};class Od extends zo{constructor(e,n,r=!1){return super(),B(this,"endpoint"),B(this,"encoder"),B(this,"fetch"),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=n,this.fetch=Li(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[No]:this.encoder.contentType}}async send(e,n,r,i){n=r==null?void 0:r.parse(n);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(n??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const f={...h,params:{}};c.headers={...this.headers,...h.params};let d;try{d=await Li(h.protocol)(h.target,c)}catch(D){let ie=D;return ie.message==="Load failed"&&(ie=new Xe({url:o})),[f,ie]}const A=await d.arrayBuffer();if(d!=null&&d.ok)return i!=null&&(a=this.encoder.decode(A,i)),[f,null];try{if(d.status!==400)return[f,new Error(d.statusText)];const D=this.encoder.decode(A,ln),ie=Ps(D);return[f,ie]}catch(D){return[f,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${D.message}`)]}});return[a,u]}}const v=async(t,e,n,r,i)=>{const[a,o]=await t.send(e,n,r,i);if(o!=null)throw o;return a},Td=()=>po.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),Sd=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(ln)});class zd{constructor(e,n,r,i){B(this,"encoder"),B(this,"reqSchema"),B(this,"resSchema"),B(this,"ws"),B(this,"serverClosed"),B(this,"sendClosed"),B(this,"receiveDataQueue",[]),B(this,"receiveCallbacksQueue",[]),this.encoder=n,this.reqSchema=r,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new qe;if(this.sendClosed)throw new ot;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=Ps(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,n)=>this.receiveCallbacksQueue.push({resolve:e,reject:n}))}addMessage(e){const n=this.receiveCallbacksQueue.shift();n!=null?n.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,Sd)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Ad(e)?qe.TYPE:ot.TYPE,data:""}})}}const Nd="freighterctx",Ed=1e3,Id=1001,kd=[Ed,Id],Ad=t=>kd.includes(t.code),Eo=class Io extends zo{constructor(e,n,r=!1){super(),B(this,"baseUrl"),B(this,"encoder"),this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=n}async stream(e,n,r){const i=Td();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const u=i(this.buildURL(e,c)),h={...c,params:{}};u.binaryType=Io.MESSAGE_TYPE;const f=await this.wrapSocket(u,n,r);return f instanceof Error?[h,f]:(a=f,[h,null])});if(o!=null)throw o;return a}buildURL(e,n){const r=hd({[No]:this.encoder.contentType,...n.params},Nd);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,n,r){return await new Promise(i=>{e.onopen=()=>{i(new zd(e,this.encoder,n,r))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};B(Eo,"MESSAGE_TYPE","arraybuffer");let xd=Eo;const ys=s.z.union([s.z.literal("all"),s.z.literal("create"),s.z.literal("delete"),s.z.literal("retrieve"),s.z.literal("update")]),Cd=t=>{const e=t.replace(/_[a-z]/g,n=>n[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},ko=t=>{const e=(n,r=gs)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!jr(n))return n;r=Rd(r);const i={},a=n;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(jr(c)?Yi(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&_i(c)&&(c=[...c].map(h=>{let f=h;return jr(h)?Yi(f,r.keepTypesOnRecursion)||(f=e(h,r)):_i(h)&&(f=e({key:h},r).key),f}))),i[u]=c}),i};return e},Ao=ko(Cd),$d=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),jd=ko($d),gs={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Rd=(t=gs)=>(t.recursive==null?t=gs:t.recursiveInArray??(t.recursiveInArray=!1),t),_i=t=>t!=null&&Array.isArray(t),jr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Yi=(t,e)=>(e||[]).some(n=>t instanceof n),Us=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var Md=Object.defineProperty,Bd=(t,e,n)=>e in t?Md(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Zt=(t,e,n)=>Bd(t,typeof e!="symbol"?e+"":e,n);let xo=class{constructor(){Zt(this,"contentType","application/json"),Zt(this,"decoder"),Zt(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 n=JSON.parse(t),r=Ao(n);return e!=null?e.parse(r):r}encodeString(t){const e=jd(t);return JSON.stringify(e,(n,r)=>ArrayBuffer.isView(r)?Array.from(r):Us(r)&&"encode_value"in r?typeof r.value=="bigint"?r.value.toString():r.value:typeof r=="bigint"?r.toString():r)}static registerCustomType(){}},Co=class{constructor(){Zt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const n=new TextDecoder().decode(t);return this.decodeString(n,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!Us(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),n=[e.join(",")];return t.forEach(r=>{const i=e.map(a=>JSON.stringify(r[a]??""));n.push(i.join(","))}),n.join(`
28
- `)}decodeString(t,e){const[n,...r]=t.trim().split(`
29
- `).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);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(){}},$o=class{constructor(){Zt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const it=new xo,Dd=new Co,Pd=new $o,Ud=[it],yt=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Co,CSV_CODEC:Dd,ENCODERS:Ud,JSONCodec:xo,JSON_CODEC:it,TEXT_CODEC:Pd,TextCodec:$o},Symbol.toStringTag,{value:"Module"})),fr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const jo=s.z.object({width:s.z.number(),height:s.z.number()}),Ld=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),_d=["width","height"];s.z.enum(_d);const Yd=["start","center","end"],Fd=["signedWidth","signedHeight"];s.z.enum(Fd);const sr=s.z.object({x:s.z.number(),y:s.z.number()}),qd=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Vd=["x","y"],Ro=s.z.enum(Vd),Mo=["top","right","bottom","left"];s.z.enum(Mo);const Wd=["left","right"],Bo=s.z.enum(Wd),Gd=["top","bottom"],Do=s.z.enum(Gd),Po=["center"],Fi=s.z.enum(Po),Zd=[...Mo,...Po],Uo=s.z.enum(Zd);s.z.enum(Yd);const Jd=["first","last"];s.z.enum(Jd);const Kd=s.z.object({lower:s.z.number(),upper:s.z.number()}),Hd=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Kd,fr]);s.z.union([Hd,fr]);s.z.union([Ro,Uo]);s.z.union([Ro,Uo,s.z.instanceof(String)]);const gt=t=>typeof t=="bigint"||t instanceof BigInt,Rr=(t,e)=>gt(t)?t.valueOf()-BigInt(e.valueOf().valueOf()):t.valueOf()-Number(e.valueOf()),Xd=(t,e)=>gt(t)?t.valueOf()+BigInt(e.valueOf().valueOf()):t+Number(e.valueOf()),qi=(t,e)=>gt(t)?t===BigInt(e.valueOf().valueOf()):t===Number(e.valueOf()),Qd=(t,e)=>gt(t)?t.valueOf()<BigInt(e.valueOf())?t:BigInt(e.valueOf()):t.valueOf()<Number(e.valueOf())?t:Number(e.valueOf()),ef=t=>gt(t)||t instanceof BigInt?t.valueOf()<0n?-t:t:t.valueOf()<0?-t:t,nt=(t,e)=>gt(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),de=(t,e)=>{const n={};if(typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else return Vi(t);return Vi(n)},Vi=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,Wi=(t,e)=>{const n=de(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e},bn=(t,e)=>{const n=de(t);if(typeof e=="number"||typeof e=="bigint")return e>=n.lower&&e<n.upper;const r=de(e);return r.lower>=n.lower&&r.upper<=n.upper},tf=(t,e,n)=>{const r=t.map(c=>de(c)),i=n>0?1:n<0?-1:0;if(i===0)return e;let a=n,o=e;for(;qi(a,0)===!1;){const c=r.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=r[c];let h;if(i>0?h=Rr(u.upper,o):h=Rr(o,u.lower),h>0){const f=Qd(ef(a),h);if(o=Xd(o,i>0?f:-f),a=Rr(a,i>0?f:-f),qi(a,0))return o;continue}}if(i>0){const u=r.filter(h=>h.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=r.filter(h=>h.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},nf=(t,e,n)=>{const r=t.map(o=>de(o));if(e===n)return typeof e=="bigint"?0n:0;const i=e<n?de([e,n]):de([n,e]);let a=typeof e=="bigint"?0n:0;for(const o of r){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const h=u-c;a=a+h}}return a};s.z.object({x:Bo.or(Fi),y:Do.or(Fi)});const rf=s.z.object({x:Bo,y:Do}),sf=Object.freeze({x:"left",y:"top"}),af=(t,e)=>t.x===e.x&&t.y===e.y,Gi=s.z.union([s.z.number(),sr,fr,jo,Ld,qd]),of=(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}},Zi=Object.freeze({x:0,y:0}),vn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:vn,left:vn,width:vn,height:vn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:sr,two:sr,root:rf});const Ls=(t,e,n=0,r=0,i)=>{const a={one:{...Zi},two:{...Zi},root:i??sf};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+n,y:a.one.y+r},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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},Mr=t=>{const e=Ls(t);return{lower:e.one.x,upper:e.two.x}},Br=t=>{const e=Ls(t);return{lower:e.one.y,upper:e.two.y}},lf=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var cf=Object.defineProperty,uf=(t,e,n)=>e in t?cf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Be=(t,e,n)=>uf(t,typeof e!="symbol"?e+"":e,n);const hf=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Gi,scale:Gi});s.z.object({offset:s.z.number(),scale:s.z.number()});const df=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],ff=t=>(e,n,r,i)=>[e,i?r/t:r*t],yf=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},gf=t=>(e,n,r)=>[t,r],pf=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},mf=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=hf(r,i,a),[e,r]},ps=class Bt{constructor(){Be(this,"ops",[]),Be(this,"currBounds",null),Be(this,"currType",null),Be(this,"reversed",!1),this.ops=[]}static translate(e){return new Bt().translate(e)}static magnify(e){return new Bt().magnify(e)}static scale(e,n){return new Bt().scale(e,n)}translate(e){const n=this.new(),r=df(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=ff(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=de(e,n),i=this.new(),a=yf(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=de(e,n),i=this.new(),a=mf(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=de(e,n),i=this.new(),a=gf(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=pf();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Bt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};Be(ps,"IDENTITY",new ps);let Ji=ps;const Ki=class Re{constructor(e=new Ji,n=new Ji,r=null){Be(this,"x"),Be(this,"y"),Be(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new Re().translate(e,n)}static translateX(e){return new Re().translateX(e)}static translateY(e){return new Re().translateY(e)}static clamp(e){return new Re().clamp(e)}static magnify(e){return new Re().magnify(e)}static scale(e){return new Re().scale(e)}static reBound(e){return new Re().reBound(e)}translate(e,n){const r=of(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(lf(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!af(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(Mr(e)),n.y=n.y.scale(Br(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(Mr(e)),n.y=this.y.reBound(Br(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(Mr(e)),n.y=this.y.clamp(Br(e)),n}copy(){const e=new Re;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Ls(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}};Be(Ki,"IDENTITY",new Ki);const Hi=t=>[...new Set(t)],wf=t=>t!=null&&typeof t=="object"&&"toString"in t,bf=(t,e=!1)=>{const n=wf(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?vf(r):r},vf=t=>(e,n)=>t(n,e),yr=0,Dr=-1,Pr=1,Of=t=>t<yr,Tf=t=>t>yr,Sf=t=>t===yr,zf=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},Nf=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([jo,Nf,sr,fr]);const Ef=s.z.bigint().or(s.z.string().transform(BigInt));var If=Object.defineProperty,kf=(t,e,n)=>e in t?If(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,g=(t,e,n)=>kf(t,typeof e!="symbol"?e+"":e,n);let Af=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const xf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Lo=Af(xf,11),Cf=Object.freeze(Object.defineProperty({__proto__:null,id:Lo},Symbol.toStringTag,{value:"Module"})),$f=s.z.enum(["static","dynamic"]),_o=(t,e)=>{const n=new x(e);if(![$.DAY,$.HOUR,$.MINUTE,$.SECOND,$.MILLISECOND,$.MICROSECOND,$.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof x?new x(r):new $(r)},q=class N{constructor(e,n="UTC"){if(g(this,"value"),g(this,"encodeValue",!0),e==null)this.value=N.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*N.MILLISECOND.valueOf();else if(typeof e=="string")this.value=N.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=N.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=N.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=N.MAX:e=N.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new N(BigInt(i.getTime())*N.MILLISECOND.valueOf()).truncate(N.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=N.hours(parseInt(r??"00")).add(N.minutes(parseInt(i??"00"))).add(N.seconds(parseInt(o??"00"))).add(N.milliseconds(parseInt(c??"00")));return n==="local"&&(u=u.add(N.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return N.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new N(BigInt(r.getTime())*N.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(N.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new $(BigInt(new Date().getTimezoneOffset())*N.MINUTE.valueOf())}static since(e){return new N().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new N(e).valueOf()}span(e){return this.range(e).span}range(e){return new se(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 N(e).valueOf()}afterEq(e){return this.valueOf()>=new N(e).valueOf()}before(e){return this.valueOf()<new N(e).valueOf()}beforeEq(e){return this.valueOf()<=new N(e).valueOf()}add(e){return new N(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new N(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return _o(this,e)}get isToday(){return this.truncate($.DAY).equals(N.now().truncate($.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new N(new Date)}static max(...e){let n=N.MIN;for(const r of e){const i=new N(r);i.after(n)&&(n=i)}return n}static min(...e){let n=N.MAX;for(const r of e){const i=new N(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new N(e)}static microseconds(e){return N.nanoseconds(e*1e3)}static milliseconds(e){return N.microseconds(e*1e3)}static seconds(e){return N.milliseconds(e*1e3)}static minutes(e){return N.seconds(e*60)}static hours(e){return N.minutes(e*60)}static days(e){return N.hours(e*24)}};g(q,"NANOSECOND",q.nanoseconds(1)),g(q,"MICROSECOND",q.microseconds(1)),g(q,"MILLISECOND",q.milliseconds(1)),g(q,"SECOND",q.seconds(1)),g(q,"MINUTE",q.minutes(1)),g(q,"HOUR",q.hours(1)),g(q,"DAY",q.days(1)),g(q,"MAX",new q((1n<<63n)-1n)),g(q,"MIN",new q(0)),g(q,"ZERO",new q(0)),g(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 x=q;const V=class k{constructor(e){g(this,"value"),g(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof k?e:e instanceof Xt?e.period:e instanceof x?new k(e):["number","bigint"].includes(typeof e)?k.seconds(e):new k(e)}static fromMilliseconds(e){return e instanceof k?e:e instanceof Xt?e.period:e instanceof x?new k(e):["number","bigint"].includes(typeof e)?k.milliseconds(e):new k(e)}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 _o(this,e)}truncate(e){return new k(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(k.DAY),n=this.truncate(k.HOUR),r=this.truncate(k.MINUTE),i=this.truncate(k.SECOND),a=this.truncate(k.MILLISECOND),o=this.truncate(k.MICROSECOND),c=this.truncate(k.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),A=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),A.isZero||(M+=`${A.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.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(nt(e,1e3))}static milliseconds(e=1){return k.microseconds(nt(e,1e3))}static seconds(e=1){return k.milliseconds(nt(e,1e3))}static minutes(e=1){return k.seconds(nt(e,60))}static hours(e){return k.minutes(nt(e,60))}static days(e){return k.hours(nt(e,24))}};g(V,"NANOSECOND",V.nanoseconds(1)),g(V,"MICROSECOND",V.microseconds(1)),g(V,"MILLISECOND",V.milliseconds(1)),g(V,"SECOND",V.seconds(1)),g(V,"MINUTE",V.minutes(1)),g(V,"HOUR",V.hours(1)),g(V,"DAY",V.days(1)),g(V,"MAX",new V((1n<<63n)-1n)),g(V,"MIN",new V(0)),g(V,"ZERO",new V(0)),g(V,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new V(t.value)),s.z.string().transform(t=>new V(BigInt(t))),s.z.instanceof(Number).transform(t=>new V(t)),s.z.number().transform(t=>new V(t)),s.z.instanceof(V)]));let $=V;const Dt=class Dn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Dn(e).valueOf()}get period(){return $.seconds(1/this.valueOf())}sampleCount(e){return new $(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new he(n).valueOf()}span(e){return $.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new Dn(e)}static khz(e){return Dn.hz(e*1e3)}};g(Dt,"z",s.z.union([s.z.number().transform(t=>new Dt(t)),s.z.instanceof(Number).transform(t=>new Dt(t)),s.z.instanceof(Dt)]));let Xt=Dt;const re=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new lt(e*this.valueOf())}};g(re,"UNKNOWN",new re(0)),g(re,"BIT128",new re(16)),g(re,"BIT64",new re(8)),g(re,"BIT32",new re(4)),g(re,"BIT16",new re(2)),g(re,"BIT8",new re(1)),g(re,"z",s.z.union([s.z.number().transform(t=>new re(t)),s.z.instanceof(Number).transform(t=>new re(t)),s.z.instanceof(re)]));let he=re;const Ae=class Pn{constructor(e,n){g(this,"start"),g(this,"end"),typeof e=="object"&&"start"in e?(this.start=new x(e.start),this.end=new x(e.end)):(this.start=new x(e),this.end=new x(n))}get span(){return new $(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Pn(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,n=$.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=x.max(r.start,e.start),a=x.min(r.end,e.end);return a.before(i)?!1:new $(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof Pn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new Pn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};g(Ae,"MAX",new Ae(x.MIN,x.MAX)),g(Ae,"MIN",new Ae(x.MAX,x.MIN)),g(Ae,"ZERO",new Ae(x.ZERO,x.ZERO)),g(Ae,"z",s.z.union([s.z.object({start:x.z,end:x.z}).transform(t=>new Ae(t.start,t.end)),s.z.instanceof(Ae)]));let se=Ae;const w=class xe extends String{constructor(e){if(e instanceof xe||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const n=xe.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}throw super(xe.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=xe.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(xe.JSON)||this.equals(xe.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(xe.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=xe.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 xe.BIG_INT_TYPES.some(e=>e.equals(this))}};g(w,"UNKNOWN",new w("unknown")),g(w,"FLOAT64",new w("float64")),g(w,"FLOAT32",new w("float32")),g(w,"INT64",new w("int64")),g(w,"INT32",new w("int32")),g(w,"INT16",new w("int16")),g(w,"INT8",new w("int8")),g(w,"UINT64",new w("uint64")),g(w,"UINT32",new w("uint32")),g(w,"UINT16",new w("uint16")),g(w,"UINT8",new w("uint8")),g(w,"BOOLEAN",w.UINT8),g(w,"TIMESTAMP",new w("timestamp")),g(w,"UUID",new w("uuid")),g(w,"STRING",new w("string")),g(w,"JSON",new w("json")),g(w,"ARRAY_CONSTRUCTORS",new Map([[w.UINT8.toString(),Uint8Array],[w.UINT16.toString(),Uint16Array],[w.UINT32.toString(),Uint32Array],[w.UINT64.toString(),BigUint64Array],[w.FLOAT32.toString(),Float32Array],[w.FLOAT64.toString(),Float64Array],[w.INT8.toString(),Int8Array],[w.INT16.toString(),Int16Array],[w.INT32.toString(),Int32Array],[w.INT64.toString(),BigInt64Array],[w.TIMESTAMP.toString(),BigInt64Array],[w.STRING.toString(),Uint8Array],[w.JSON.toString(),Uint8Array],[w.UUID.toString(),Uint8Array]])),g(w,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,w.UINT8],[Uint16Array.name,w.UINT16],[Uint32Array.name,w.UINT32],[BigUint64Array.name,w.UINT64],[Float32Array.name,w.FLOAT32],[Float64Array.name,w.FLOAT64],[Int8Array.name,w.INT8],[Int16Array.name,w.INT16],[Int32Array.name,w.INT32],[BigInt64Array.name,w.INT64]])),g(w,"DENSITIES",new Map([[w.UINT8.toString(),he.BIT8],[w.UINT16.toString(),he.BIT16],[w.UINT32.toString(),he.BIT32],[w.UINT64.toString(),he.BIT64],[w.FLOAT32.toString(),he.BIT32],[w.FLOAT64.toString(),he.BIT64],[w.INT8.toString(),he.BIT8],[w.INT16.toString(),he.BIT16],[w.INT32.toString(),he.BIT32],[w.INT64.toString(),he.BIT64],[w.TIMESTAMP.toString(),he.BIT64],[w.STRING.toString(),he.UNKNOWN],[w.JSON.toString(),he.UNKNOWN],[w.UUID.toString(),he.BIT128]])),g(w,"ALL",[w.UNKNOWN,w.FLOAT64,w.FLOAT32,w.INT64,w.INT32,w.INT16,w.INT8,w.UINT64,w.UINT32,w.UINT16,w.UINT8,w.TIMESTAMP,w.UUID,w.STRING,w.JSON]),g(w,"BIG_INT_TYPES",[w.INT64,w.UINT64,w.TIMESTAMP]),g(w,"z",s.z.union([s.z.string().transform(t=>new w(t)),s.z.instanceof(w)]));let C=w;const le=class X extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return X.bytes(this.valueOf()+e.valueOf())}sub(e){return X.bytes(this.valueOf()-e.valueOf())}truncate(e){return new X(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return X.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/X.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/X.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/X.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/X.TERABYTE.valueOf()}toString(){const e=this.truncate(X.TERABYTE),n=this.truncate(X.GIGABYTE),r=this.truncate(X.MEGABYTE),i=this.truncate(X.KILOBYTE),a=this.truncate(X.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new X(e)}static kilobytes(e=1){return X.bytes(e.valueOf()*1e3)}static megabytes(e=1){return X.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return X.megabytes(e.valueOf()*1e3)}static terabytes(e){return X.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};g(le,"BYTE",new le(1)),g(le,"KILOBYTE",le.kilobytes(1)),g(le,"MEGABYTE",le.megabytes(1)),g(le,"GIGABYTE",le.gigabytes(1)),g(le,"TERABYTE",le.terabytes(1)),g(le,"ZERO",new le(0)),g(le,"z",s.z.union([s.z.number().transform(t=>new le(t)),s.z.instanceof(le)]));let lt=le;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 Yo=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof x||t instanceof $||t instanceof Date},jf=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):Ut(n,-r).valueOf(),Rf=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Je?!0:Yo(t),_e=-1,ms={[Symbol.iterator]:()=>ms,next:()=>({done:!0,value:void 0})},Mf=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Bf=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ws=10,Pt=class Ce{constructor(e){g(this,"key",""),g(this,"isSynnaxSeries",!0),g(this,"dataType"),g(this,"sampleOffset"),g(this,"gl"),g(this,"_data"),g(this,"_timeRange"),g(this,"alignment",0n),g(this,"_cachedMin"),g(this,"_cachedMax"),g(this,"writePos",_e),g(this,"_refCount",0),g(this,"_cachedLength"),g(this,"_cachedIndexes"),Rf(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Lo()}=e,u=e.data??[];if(u instanceof Ce||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this._timeRange=d._timeRange,this.alignment=d.alignment,this._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=Yo(u),f=Array.isArray(u);if(n!=null)this.dataType=new C(n);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||h){let d=u;if(!h){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.");d=u[0]}if(typeof d=="string")this.dataType=C.STRING;else if(typeof d=="number")this.dataType=C.FLOAT64;else if(typeof d=="bigint")this.dataType=C.INT64;else if(typeof d=="boolean")this.dataType=C.BOOLEAN;else if(d instanceof x||d instanceof Date||d instanceof x)this.dataType=C.TIMESTAMP;else if(typeof d=="object")this.dataType=C.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new C(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const A=d[0];(A instanceof x||A instanceof Date||A instanceof $)&&(d=d.map(D=>new x(D).valueOf())),this.dataType.equals(C.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
30
- `)}
31
- `)):this.dataType.equals(C.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(D=>it.encodeString(D)).join(`
32
- `)}
33
- `)):this._data=new this.dataType.Array(d).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new C(n).Array(e),a=new Ce({data:i.buffer,dataType:n,...r});return a.writePos=0,a}static generateTimestamps(e,n,r){const i=r.spanRange(n.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(r.add(n.span(o)).valueOf());return new Ce({data:a,dataType:C.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,n){const r=new TextEncoder().encode(`${e.join(`
34
- `)}
35
- `);return new Ce({data:r,dataType:C.STRING,timeRange:n})}static fromJSON(e,n){const r=new TextEncoder().encode(`${e.map(i=>it.encodeString(i)).join(`
36
- `)}
37
- `);return new Ce({data:r,dataType:C.JSON,timeRange:n})}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");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===_e)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===_e)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===_e?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(C.STRING,C.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
38
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(C.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=C.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+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");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(C.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
39
- `).slice(0,-1).map(n=>e.parse(it.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new lt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===_e?this.byteCapacity:this.dataType.isVariable?new lt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===_e?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;const n=[0];return this.data.forEach((r,i)=>{r===ws&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=jf(this.dataType,e,this.data[i],n);return new Ce({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}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??(this._cachedMax=this.calcRawMax()),Ut(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}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??(this._cachedMin=this.calcRawMin()),Ut(this._cachedMin,this.sampleOffset))}get bounds(){return de(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return Ut(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return Ut(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===ws){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(C.STRING)?new TextDecoder().decode(a):Ao(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=bf(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(C.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==_e){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=_e}as(e){if(e==="string"){if(!this.dataType.equals(C.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(C.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 de(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 Df(this);return this.dataType.equals(C.JSON)?new Pf(e):e}return new Uf(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new Xi(this,e,n??this.length)}subAlignmentIterator(e,n){return new Xi(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ce({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ce({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ce({data:this.buffer,dataType:this.dataType,timeRange:se.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};g(Pt,"crudeZ",s.z.object({timeRange:se.z.optional(),dataType:C.z,alignment:Ef.optional(),data:s.z.union([Mf,Bf,s.z.instanceof(ArrayBuffer)]),glBufferUsage:$f.optional().default("static").optional()})),g(Pt,"z",Pt.crudeZ.transform(t=>new Pt(t)));let Je=Pt,Xi=class{constructor(t,e,n){g(this,"series"),g(this,"end"),g(this,"index"),this.series=t;const r=de(0,t.length);this.end=Wi(r,n),this.index=Wi(r,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};class Df{constructor(e){if(g(this,"series"),g(this,"index"),g(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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ws;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var Qi,ea;class Pf{constructor(e){g(this,"wrapped"),g(this,Qi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:it.decodeString(e.value)}}[(ea=Symbol.iterator,Qi=Symbol.toStringTag,ea)](){return this}}var ta,na;class Uf{constructor(e){g(this,"series"),g(this,"index"),g(this,ta,"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)}}[(na=Symbol.iterator,ta=Symbol.toStringTag,na)](){return this}}const Ut=(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 Lf{constructor(e){if(g(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new C(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?C.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?se.ZERO:new se(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?de(0n,0n):de(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(bn(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ur(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return ms;let r=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)r+=o.length;else if(bn(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(bn(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ur(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return ms;let r=0;for(let i=0;i<this.series.length;i++){const a=this.series[i];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)r+=a.length;else if(bn(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ur(this,r,r+n)}get byteLength(){return new lt(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return tf(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return nf(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new _f(this.series)}}var ra,sa;class _f{constructor(e){g(this,"series"),g(this,"seriesIndex"),g(this,"internal"),g(this,ra,"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())}[(sa=Symbol.iterator,ra=Symbol.toStringTag,sa)](){return this}}class Ur{constructor(e,n,r){g(this,"series"),g(this,"index"),g(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}s.z.object({key:s.z.string(),value:s.z.string()});var Yf=Object.defineProperty,Ff=(t,e,n)=>e in t?Yf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Un=(t,e,n)=>Ff(t,typeof e!="symbol"?e+"":e,n);let qf=class{constructor(t,e){Un(this,"handlers"),Un(this,"transform"),Un(this,"closer"),this.transform=t,this.handlers=e??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){let e=t;if(this.transform!=null){const[n,r]=this.transform(t);if(!r)return;e=n}this.handlers.forEach((n,r)=>r(e))}setCloser(t){this.closer=t}async close(){var t;return await((t=this.closer)==null?void 0:t.call(this))}},Vf=class{constructor(t){Un(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,n)=>n(t))}};const Qe=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Vf,Observer:qf},Symbol.toStringTag,{value:"Module"})),cn=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Wf=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Wf();const Gf=["MacOS","Windows","Linux","Docker"];s.z.enum(Gf);var Zf=Object.defineProperty,Jf=(t,e,n)=>e in t?Zf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Lt=(t,e,n)=>Jf(t,typeof e!="symbol"?e+"":e,n);const Kf=(...t)=>t.map(Fo).join(""),Fo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Hf=t=>t.endsWith("/")?t.slice(0,-1):t,bs=class vs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Lt(this,"protocol"),Lt(this,"host"),Lt(this,"port"),Lt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=Fo(i)}replace(e){return new vs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new vs({...this,pathPrefix:Kf(this.path,e)})}toString(){return Hf(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Lt(bs,"UNKNOWN",new bs({host:"unknown",port:0}));let Xf=bs;var Qf=Object.defineProperty,ey=(t,e,n)=>e in t?Qf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ln=(t,e,n)=>ey(t,typeof e!="symbol"?e+"":e,n);const Ze=class extends Number{};Ln(Ze,"Absolute",255),Ln(Ze,"Default",1),Ln(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))]));let qo=Ze;const Vo=s.z.object({name:s.z.string(),key:s.z.string()}),ty=t=>s.z.object({subject:Vo,resource:t,authority:qo.z}),ny=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),ct=Object.freeze(Object.defineProperty({__proto__:null,Authority:qo,filterTransfersByChannelKey:ny,stateZ:ty,subjectZ:Vo},Symbol.toStringTag,{value:"Module"})),Wo=class _t extends Error{constructor(){super(_t.MESSAGE)}matches(e){return typeof e=="string"?e.includes(_t.MESSAGE):e instanceof _t||e.message.includes(_t.MESSAGE)}};Ln(Wo,"MESSAGE","canceled");let ry=Wo;new ry;const Os=s.z.string().regex(/^\d+\.\d+\.\d+$/),un=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=Os.parse(t),i=Os.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Dr;if(a>u)return Pr}if(n.checkMinor){if(o<h)return Dr;if(o>h)return Pr}if(n.checkPatch){if(c<f)return Dr;if(c>f)return Pr}return yr},sy=(t,e,n={})=>Sf(un(t,e,n)),Go=(t,e,n={})=>Tf(un(t,e,n)),iy=(t,e,n={})=>Of(un(t,e,n)),ay=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},oy=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(un).pop();if(a==null)return h=>{if(h.version??(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
40
- Returning default instead.
41
- `),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Go(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],A=d(h);return c=!0,u(A)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},ia=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:un,createMigration:ay,migrator:oy,semVerNewer:Go,semVerOlder:iy,semVerZ:Os,versionsEqual:sy},Symbol.toStringTag,{value:"Module"})),Ve="sy.",_n=class Zo extends Te{constructor(){super(...arguments),l(this,"type",Zo.TYPE)}};l(_n,"TYPE",`${Ve}validation`),l(_n,"matches",fe(_n.TYPE));let J=_n;const Yn=class Jo extends J{constructor(e,n){super(`${e}: ${n}`),l(this,"type",Jo.TYPE),l(this,"field"),l(this,"message"),this.field=e,this.message=n}};l(Yn,"TYPE",`${J.TYPE}.field`),l(Yn,"matches",fe(Yn.TYPE));let aa=Yn;const Fn=class Ko extends Te{constructor(){super(...arguments),l(this,"type",Ko.TYPE)}};l(Fn,"TYPE",`${Ve}auth`),l(Fn,"matches",fe(Fn.TYPE));let ir=Fn;const qn=class Ho extends ir{constructor(){super(...arguments),l(this,"type",Ho.TYPE)}};l(qn,"TYPE",`${ir.TYPE}.invalid-token`),l(qn,"matches",fe(qn.TYPE));let Ts=qn;const Vn=class Xo extends Te{constructor(e){super(`
42
- Unexpected error encountered:
43
-
44
- ${e}
45
-
46
- Please report this to the Synnax team.
47
- `),l(this,"type",Xo.TYPE)}};l(Vn,"TYPE",`${Ve}unexpected`),l(Vn,"matches",fe(Vn.TYPE));let be=Vn;const Wn=class Qo extends Te{constructor(){super(...arguments),l(this,"type",Qo.TYPE)}};l(Wn,"TYPE",`${Ve}query`),l(Wn,"matches",fe(Wn.TYPE));let Oe=Wn;const Gn=class el extends Oe{constructor(){super(...arguments),l(this,"type",el.TYPE)}};l(Gn,"TYPE",`${Oe.TYPE}.not_found`),l(Gn,"matches",fe(Gn.TYPE));let ut=Gn;const Zn=class tl extends Oe{constructor(){super(...arguments),l(this,"type",tl.TYPE)}};l(Zn,"TYPE",`${Oe.TYPE}.multiple_results`),l(Zn,"matches",fe(Zn.TYPE));let ht=Zn;const Jn=class nl extends Te{constructor(e,n){super(e),l(this,"type",nl.TYPE),l(this,"path"),this.path=n}};l(Jn,"TYPE",`${Ve}route`),l(Jn,"matches",fe(Jn.TYPE));let oa=Jn;const Kn=class rl extends Te{constructor(){super(...arguments),l(this,"type",rl.TYPE)}};l(Kn,"TYPE",`${Ve}control`),l(Kn,"matches",fe(Kn.TYPE));let ar=Kn;const Hn=class sl extends ar{constructor(){super(...arguments),l(this,"type",sl.TYPE)}};l(Hn,"TYPE",`${ar.TYPE}.unauthorized`),l(Hn,"matches",fe(Hn.TYPE));let la=Hn;const Lr=class il extends Te{constructor(){super(...arguments),l(this,"type",il.TYPE)}};l(Lr,"TYPE",`${Ve}contiguity`),l(Lr,"matches",fe(Lr.TYPE));const ly=t=>{if(!t.type.startsWith(Ve))return null;if(t.type.startsWith(J.TYPE)){if(t.type===aa.TYPE){const e=t.data.split(": ");return e.length<2?new J(t.data):new aa(e[0],e[1])}return new J(t.data)}return t.type.startsWith(ir.TYPE)?t.type.startsWith(Ts.TYPE)?new Ts(t.data):new ir(t.data):t.type.startsWith(be.TYPE)?new be(t.data):t.type.startsWith(Oe.TYPE)?t.type.startsWith(ut.TYPE)?new ut(t.data):t.type.startsWith(ht.TYPE)?new ht(t.data):new Oe(t.data):t.type.startsWith(ar.TYPE)?t.type.startsWith(la.TYPE)?new la(t.data):new ar(t.data):t.type.startsWith(oa.TYPE)?new oa(t.data,t.data):new be(t.data)},cy=()=>{throw new Error("Not implemented")};vo({encode:cy,decode:ly});const uy=async(t,e)=>{const[n,r]=await e(t);return r==null?[n,r]:r instanceof Xe?[n,new Xe({message:`Cannot reach cluster at ${r.url.host}:${r.url.port}`,url:r.url})]:[n,r]};class al{constructor(e,n){l(this,"key"),l(this,"name"),this.key=n,this.name=e}get ontologyID(){return new j({type:"group",key:this.key})}}const hy=s.z.string().uuid(),ol=s.z.object({key:hy,name:s.z.string()}),gr=s.z.union([s.z.literal("label"),s.z.literal("log"),s.z.literal("allow_all"),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("framer"),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"),s.z.literal("table")]),ge=s.z.object({type:gr,key:s.z.string()}),dy=s.z.string().transform(t=>{const[e,n]=t.split(":");return{type:gr.parse(e),key:n??""}}),Yt=s.z.union([dy,ge]),Xn=class ll{constructor(e){if(l(this,"type"),l(this,"key"),e instanceof ll){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[n,r]=e.split(":");this.type=n,this.key=r??"";return}this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}isType(){return this.key===""}matchesType(e){return this.type===e&&this.isType()}get payload(){return{type:this.type,key:this.key}}};l(Xn,"z",s.z.union([s.z.instanceof(Xn),Yt.transform(t=>new Xn(t))]));let j=Xn;new j({type:"builtin",key:"root"});const fy=s.z.object({type:s.z.number()}),yy=s.z.object({type:gr,fields:s.z.record(fy)}),gy=s.z.object({id:j.z,name:s.z.string(),schema:yy.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:j.z,type:s.z.string(),to:j.z});const ca=t=>{const[e,n,r]=t.split("->");return{from:new j(e),type:n,to:new j(r)}},py=s.z.object({group:ol}),my=s.z.object({parent:ge,key:s.z.string().uuid().optional(),name:s.z.string()}),wy=s.z.object({key:s.z.string(),name:s.z.string()}),by=s.z.object({keys:s.z.array(s.z.string())});var Ye;let vy=(Ye=class{constructor(t){l(this,"client"),this.client=t}async create(t,e,n){return(await v(this.client,Ye.ENDPOINT,{parent:t,name:e,key:n},my,py)).group}async rename(t,e){await v(this.client,Ye.ENDPOINT_RENAME,{key:t,name:e},wy,s.z.object({}))}async delete(t){await v(this.client,Ye.ENDPOINT_DELETE,{keys:t},by,s.z.object({}))}},l(Ye,"ENDPOINT","/ontology/create-group"),l(Ye,"ENDPOINT_RENAME","/ontology/rename-group"),l(Ye,"ENDPOINT_DELETE","/ontology/delete-group"),Ye),Oy=class{constructor(t){l(this,"creator"),this.creator=new vy(t)}async create(t,e,n){return this.sugar(await this.creator.create(t,e,n))}async rename(t,e){return await this.creator.rename(t,e)}async delete(...t){return await this.creator.delete(t)}sugar(t){return new al(t.name,t.key)}};const _r={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},ua=s.z.object({id:ge,children:ge.array()}),Ty=s.z.object({from:ge,to:ge,children:ge.array()});let Sy=class{constructor(t){l(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,_r.ADD_CHILDREN,{id:new j(t).payload,children:e.map(n=>new j(n).payload)},ua,s.z.object({}))}async removeChildren(t,...e){await v(this.client,_r.REMOVE_CHILDREN,{id:new j(t).payload,children:e.map(n=>new j(n).payload)},ua,s.z.object({}))}async moveChildren(t,e,...n){const r={from:new j(t).payload,to:new j(e).payload,children:n.map(i=>new j(i).payload)};await v(this.client,_r.MOVE_CHILDREN,r,Ty,s.z.object({}))}};const zy="/ontology/retrieve",Ny=s.z.object({ids:ge.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(),types:gr.array().optional()}),Ey=s.z.object({resources:gy.array()}),Yr=t=>T(t).map(e=>new j(e).payload);let Iy=class{constructor(t,e){l(this,"type","ontology"),l(this,"groups"),l(this,"client"),l(this,"writer"),l(this,"framer"),this.client=t,this.writer=new Sy(t),this.groups=new Oy(t),this.framer=e}async search(t,e){return await this.execRetrieve({term:t,...e})}async retrieve(t,e){const n=await this.execRetrieve({ids:Yr(t),...e});if(Array.isArray(t))return n;if(n.length===0)throw new Oe(`No resource found with ID ${t.toString()}`);return n[0]}async page(t,e,n){return await this.execRetrieve({offset:t,limit:e,...n})}async retrieveChildren(t,e){return await this.execRetrieve({ids:Yr(t),children:!0,...e})}async retrieveParents(t,e){return await this.execRetrieve({ids:Yr(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,...n){return await this.writer.moveChildren(t,e,...n)}async openChangeTracker(){return await pr.open(this.framer,this)}async openDependentTracker(t){return await _s.open(t,this.framer,this)}newSearcherWithOptions(t){return{type:this.type,search:e=>this.search(e,t),retrieve:e=>this.retrieve(e,t),page:(e,n)=>this.page(e,n,t)}}async execRetrieve(t){const{resources:e}=await v(this.client,zy,t,Ny,Ey);return e}};const ha="sy_ontology_resource_set",da="sy_ontology_resource_delete",fa="sy_ontology_relationship_set",ya="sy_ontology_relationship_delete";class pr{constructor(e,n){l(this,"relationships"),l(this,"resources"),l(this,"resourceObs"),l(this,"relationshipObs"),l(this,"streamer"),l(this,"client"),l(this,"closePromise"),this.relationshipObs=new Qe.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Qe.Observer,this.resources=this.resourceObs,this.client=n,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 n=await this.parseResourceSets(e),r=this.parseResourceDeletes(e);n.concat(r).length>0&&this.resourceObs.notify(n.concat(r));const i=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);i.concat(a).length>0&&this.relationshipObs.notify(i.concat(a))}parseRelationshipSets(e){const n=e.get(fa);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"set",key:ca(r),value:void 0}))}parseRelationshipDeletes(e){const n=e.get(ya);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:ca(r)}))}async parseResourceSets(e){const n=e.get(ha);if(n.length===0)return[];const r=Array.from(n.as("string")).map(i=>new j(i));try{return(await this.client.retrieve(r)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof Oe)return[];throw i}}parseResourceDeletes(e){const n=e.get(da);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:new j(r)}))}static async open(e,n){const r=await e.openStreamer([ha,da,fa,ya]);return new pr(r,n)}}const ga=t=>t==="from"?"to":"from";class _s extends Qe.Observer{constructor({target:e,dependents:n,relationshipType:r="parent",relationshipDirection:i="from",resourceType:a},o,c){super(),l(this,"internal"),l(this,"target"),l(this,"relDir"),l(this,"resourceType"),l(this,"dependents"),l(this,"client"),l(this,"relType"),l(this,"handleResourceChange",u=>{this.dependents=this.dependents.map(h=>{const f=u.find(d=>d.key.toString()==h.id.toString());return f==null||f.variant==="delete"?h:f.value}),this.notify(this.dependents)}),l(this,"handleRelationshipChange",u=>{const h=u.filter(d=>d.variant==="delete"&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[ga(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(d=>!h.some(A=>A.key.to.toString()===d.id.toString()&&A.key.type===this.relType));const f=u.filter(d=>d.variant==="set"&&d.key.type===this.relType&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[ga(this.relDir)].type===this.resourceType));if(f.length===0)return this.notify(this.dependents);this.client.retrieve(f.map(d=>d.key.to)).then(d=>{this.dependents=this.dependents.concat(d),this.notify(this.dependents)})}),this.resourceType=a,this.internal=o,this.target=e,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(u=>u.id.type===this.resourceType)),this.client=c,this.relType=r,this.relDir=i,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(e,n,r){const i=await pr.open(n,r);return new _s(e,i,r)}async close(){await this.internal.close()}}const me=t=>s.z.union([s.z.null().transform(()=>[]),t.array()]),mr=s.z.string().uuid(),ky=s.z.object({key:mr.optional(),subjects:Yt.array().or(Yt),objects:Yt.array().or(Yt),actions:ys.array().or(ys)}),Ys=s.z.object({key:mr,subjects:me(ge),objects:me(ge),actions:me(ys)}),Ay="allow_all";new j({type:Ay,key:""});const xy=s.z.object({keys:mr.array().optional(),subjects:ge.array().optional()}),Cy=s.z.object({policies:me(Ys)}),$y="/access/policy/retrieve";let jy=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,$y,t,xy,Cy)).policies}};const Ry=s.z.object({policies:Ys.partial({key:!0}).array()}),My=s.z.object({policies:Ys.array()}),By=s.z.object({keys:mr.array()}),Dy=s.z.object({}),Py="/access/policy/create",Uy="/access/policy/delete";let Ly=class{constructor(t){l(this,"client"),this.client=t}async create(t){const e=ky.array().parse(T(t)).map(n=>({objects:T(n.objects),actions:T(n.actions),subjects:T(n.subjects)}));return(await v(this.client,Py,{policies:e},Ry,My)).policies}async delete(t){await v(this.client,Uy,{keys:T(t)},By,Dy)}},_y=class{constructor(t){l(this,"retriever"),l(this,"writer"),this.retriever=new jy(t),this.writer=new Ly(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve({keys:T(t)});return e?n:n[0]}async retrieveFor(t){const e=T(t).map(n=>new j(n).payload);return await this.retriever.retrieve({subjects:e})}async delete(t){await this.writer.delete(t)}},Yy=class{constructor(t){l(this,"policy"),this.policy=new _y(t)}};const We=s.z.number(),hn=s.z.object({name:s.z.string(),key:s.z.number(),rate:Xt.z,dataType:C.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),cl=hn.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:Xt.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),ul="channel",Fy=t=>new j({type:ul,key:t.toString()}),qy=new Error("request for lock canceled");var Vy=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Wy{constructor(e,n=qy){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=hl(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Vy(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Gy(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function Gy(t,e){const n=hl(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function hl(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var Zy=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Jy{constructor(e){this._semaphore=new Wy(1,e)}acquire(){return Zy(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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 wr=(t,e,{convertNumericStrings:n=!0}={})=>{const r=!Array.isArray(t);let i=T(t);const a=i[0],o=typeof a;let c;return o==="string"&&n&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:r,variant:c,normalized:i,actual:t}},br=(t,e,n,r)=>{if(r){if(n.length===0)throw new ut(`${t} not found matching ${JSON.stringify(e)}`);if(n.length>1)throw new ht(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${n.length}`)}},Ky=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:C.z.array().optional(),notDataTypes:C.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Hy=s.z.object({channels:me(hn)}),De=t=>wr(t,{number:"keys",string:"names"}),dl=class fl{constructor(e){l(this,"client"),this.client=e}async search(e,n){return await this.execute({search:e,...n})}async retrieve(e,n){const r=De(e),{variant:i}=r;let{normalized:a}=r;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...n})}async page(e,n,r){return await this.execute({offset:e,limit:n,...r})}async execute(e){const[n,r]=await this.client.send(fl.ENDPOINT,e,Ky,Hy);if(r!=null)throw r;return n.channels}};l(dl,"ENDPOINT","/channel/retrieve");let Fs=dl;class qs{constructor(e){l(this,"cache"),l(this,"namesToKeys"),l(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e,n){const{normalized:r}=wr(e,{string:"names",number:"keys"}),i=[],a=[];if(r.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,n);return this.set(o),i.concat(o)}delete(e){const{variant:n,normalized:r}=De(e);n==="names"?r.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):r.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,n){e.forEach((r,i)=>{const a=n[i],o=this.cache.get(r);if(o==null)return;this.cache.delete(r);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(r),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(r,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([r])):u.add(r)})}set(e){e.forEach(n=>{this.cache.set(n.key,n);const r=this.namesToKeys.get(n.name);r==null?this.namesToKeys.set(n.name,new Set([n.key])):r.add(n.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const n=this.namesToKeys.get(e);if(n==null)return;const r=[];if(n.forEach(i=>{const a=this.cache.get(i);a!=null&&r.push(a)}),r.length!==0)return r}}class yl{constructor(e,n){l(this,"mu",new Jy),l(this,"requests",new Map),l(this,"wrapped"),l(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=zf(()=>{this.run()},n)}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e){const{normalized:n,variant:r}=De(e);return r==="names"?await this.wrapped.retrieve(n):await new Promise((i,a)=>{this.mu.runExclusive(()=>{this.requests.set(n,{resolve:i,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((n,r)=>r.forEach(i=>e.add(i)));try{const n=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((r,i)=>r.resolve(n.filter(a=>i.includes(a.key))))}catch(n){this.requests.forEach(r=>r.reject(n))}finally{this.requests.clear()}})}}const gl=async(t,e)=>{const{normalized:n}=De(e),r=await t.retrieve(n),i=[];if(n.forEach(a=>{r.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new Oe(`Could not find channels: ${JSON.stringify(i)}`);return r};class pl{constructor({dataType:e,rate:n,name:r,leaseholder:i=0,key:a=0,isIndex:o=!1,index:c=0,internal:u=!1,virtual:h=!1,frameClient:f,alias:d}){l(this,"_frameClient"),l(this,"key"),l(this,"name"),l(this,"rate"),l(this,"dataType"),l(this,"leaseholder"),l(this,"index"),l(this,"isIndex"),l(this,"internal"),l(this,"alias"),l(this,"virtual"),this.key=a,this.name=r,this.rate=new Xt(n??0),this.dataType=new C(e),this.leaseholder=i,this.index=c,this.isIndex=o,this.internal=u,this.alias=d,this.virtual=h,this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new J("cannot read from a channel that has not been created");return this._frameClient}get payload(){return hn.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 j({type:"channel",key:this.key.toString()})}async read(e){return await this.framer.read(e,this.key)}async write(e,n){return await this.framer.write(e,this.key,n)}}const Xy="/channel/retrieve-group",Qy=s.z.object({}),eg=s.z.object({group:ol});let ml=class{constructor(t,e,n,r){l(this,"type","channel"),l(this,"frameClient"),l(this,"client"),l(this,"retriever"),l(this,"writer"),this.frameClient=t,this.retriever=e,this.client=n,this.writer=r}async create(t,e={}){const{retrieveIfNameExists:n=!1}=e,r=!Array.isArray(t);let i=T(t),a=[];if(n){const o=await this.retriever.retrieve(i.map(u=>u.name)),c=new Set(o.map(u=>u.name));i=i.filter(u=>!c.has(u.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(i))),r?a[0]:a}async retrieve(t,e){const n=!Array.isArray(t),r=this.sugar(await this.retriever.retrieve(t,e));return br("channel",t,r,n),n?r[0]:r}async search(t,e){return this.sugar(await this.retriever.search(t,e))}async delete(t){const{normalized:e,variant:n}=De(t);return n==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(t,e){return await this.writer.rename(T(t),T(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,n)=>await this.page(e,n,t)}}async page(t,e,n){return this.sugar(await this.retriever.page(t,e,n))}createDebouncedBatchRetriever(t=10){return new qs(new yl(new Fs(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(n=>new pl({...n,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,Xy,{},Qy,eg);return new al(t.group.name,t.group.key)}};const tg=s.z.object({channels:cl.array()}),ng=s.z.object({channels:hn.array()}),rg=s.z.object({keys:We.array().optional(),names:s.z.string().array().optional()}),sg=s.z.object({}),ig=s.z.object({keys:We.array(),names:s.z.string().array()}),ag=s.z.object({}),og="/channel/create",lg="/channel/delete",cg="/channel/rename";let wl=class{constructor(t,e){l(this,"client"),l(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,og,{channels:t},tg,ng);return this.cache.set(e),e}async delete(t){await v(this.client,lg,t,rg,sg),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,cg,{keys:t,names:e},ig,ag),this.cache.rename(t,e)}};const ug=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:qs,Channel:pl,Client:ml,ClusterRetriever:Fs,DebouncedBatchRetriever:yl,ONTOLOGY_TYPE:ul,Writer:wl,analyzeChannelParams:De,keyZ:We,newPayload:cl,ontologyID:Fy,payload:hn,retrieveRequired:gl},Symbol.toStringTag,{value:"Module"})),dn=s.z.string().uuid(),vr=s.z.object({key:dn,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),hg=vr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),dg=s.z.object({keys:dn.array().optional(),usernames:s.z.string().array().optional()}),fg=s.z.object({users:me(vr)}),yg="/user/retrieve";let gg=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,yg,t,dg,fg)).users}};const pg=s.z.object({users:hg.array()}),mg=s.z.object({users:vr.array()}),wg=s.z.object({key:dn,username:s.z.string().min(1)}),bg=s.z.object({}),vg=s.z.object({key:dn,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),Og=s.z.object({}),Tg=s.z.object({keys:dn.array()}),Sg=s.z.object({}),zg="/user/create",Ng="/user/change-username",Eg="/user/rename",Ig="/user/delete";let kg=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,zg,{users:T(t)},pg,mg)).users}async changeUsername(t,e){await v(this.client,Ng,{key:t,username:e},wg,bg)}async rename(t,e,n){await v(this.client,Eg,{key:t,firstName:e,lastName:n},vg,Og)}async delete(t){await v(this.client,Ig,{keys:T(t)},Tg,Sg)}},Ag=class{constructor(t){l(this,"reader"),l(this,"writer"),this.writer=new kg(t),this.reader=new gg(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async changeUsername(t,e){await this.writer.changeUsername(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.reader.retrieve({keys:T(t)});if(e)return n;if(n.length===0)throw new ut(`No user with key ${t} found`);if(n.length>1)throw new ht(`Multiple users found with key ${t}`);return n[0]}async retrieveByName(t){const e=Array.isArray(t),n=await this.reader.retrieve({usernames:T(t)});if(e)return n;if(n.length===0)throw new ut(`No user with username ${t} found`);if(n.length>1)throw new ht(`Multiple users found with username ${t}`);return n[0]}async rename(t,e,n){await this.writer.rename(t,e,n)}async delete(t){await this.writer.delete(t)}};const xg=s.z.object({username:s.z.string(),password:s.z.string()}),Cg=s.z.object({token:s.z.string(),user:vr}),pa="/auth/login",$g=3,jg="/auth/change-password",Rg=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),Mg=s.z.object({});let Bg=class{constructor(t,e){l(this,"token"),l(this,"client"),l(this,"credentials"),l(this,"authenticating"),l(this,"authenticated"),l(this,"user"),l(this,"retryCount"),this.client=t,this.authenticated=!1,this.credentials=e,this.retryCount=0}async changePassword(t){if(!this.authenticated)throw new Error("Not authenticated");await v(this.client,jg,{username:this.credentials.username,password:this.credentials.password,newPassword:t},Rg,Mg),this.credentials.password=t}middleware(){const t=async(e,n)=>{if(!this.authenticated&&!e.target.endsWith(pa)){this.authenticating??(this.authenticating=new Promise((o,c)=>{this.client.send(pa,this.credentials,xg,Cg).then(([u,h])=>{if(h!=null)return o(h);this.token=u==null?void 0:u.token,this.user=u==null?void 0:u.user,this.authenticated=!0,o(null)}).catch(c)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[r,i]=await n(e);return Ts.matches(i)&&this.retryCount<$g?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,n)):(this.retryCount=0,[r,i])};return t}};const Dg=["disconnected","connecting","connected","failed"],Pg=s.z.enum(Dg),Ug=s.z.object({status:Pg,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),Lg=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),bl={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.35.0"},ma=(t,e,n)=>{const r=n?"cluster":"client";return`Synnax cluster node version ${t!=null?`${t} `:""}is too ${n?"old":"new"} for client version ${e}.
48
- This may cause compatibility issues. We recommend updating the ${r}. For more information, see
49
- https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${r}-version`},Qn=class vl{constructor(e,n=$.seconds(30),r,i){l(this,"_state"),l(this,"pollFrequency",$.seconds(30)),l(this,"client"),l(this,"name"),l(this,"interval"),l(this,"clientVersion"),l(this,"onChangeHandlers",[]),l(this,"versionWarned",!1),this._state={...bl},this.client=e,this.pollFrequency=n,this.clientVersion=r,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const n=this._state.status;try{const[r,i]=await this.client.send(vl.ENDPOINT,{},s.z.object({}),Lg);if(i!=null)throw i;const a=r.nodeVersion,o=this.clientVersion,c=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,c||(console.warn(ma(null,o,!0)),this.versionWarned=!0)):ia.versionsEqual(o,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,c||(console.warn(ma(a,o,ia.semVerNewer(o,a))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=r.clusterKey,this._state.nodeVersion=r.nodeVersion,this._state.clientVersion=this.clientVersion}catch(r){this._state.status="failed",this._state.error=r,this._state.message=(e=this.state.error)==null?void 0:e.message}return this.onChangeHandlers.length>0&&n!==this._state.status&&this.onChangeHandlers.forEach(r=>r(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};l(Qn,"ENDPOINT","/connectivity/check"),l(Qn,"DEFAULT",bl),l(Qn,"connectionStateZ",Ug);let Ol=Qn;const _g=s.z.object({keys:We.array().optional(),bounds:se.z,names:s.z.string().array().optional()}),Yg=s.z.object({}),Fg="/frame/delete";class qg{constructor(e){l(this,"client"),this.client=e}async delete(e){await v(this.client,Fg,e,_g,Yg)}}const wa=t=>{const e=T(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ba=(t,e)=>{const n=T(t);if(n.length===e.length)return;const r=wa(t);throw wa===null?new J("[Frame] - channel keys or names must be provided when constructing a frame."):new J(`[Frame] - ${r}s and series must be the same length.
50
- Got ${n.length} ${r}s and ${e.length} series.`)};let ve=class rt{constructor(e=[],n=[]){if(l(this,"columns",[]),l(this,"series",[]),e instanceof rt){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((r,i)=>this.push(i,...T(r)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const r=e;r.series??(r.series=[]),r.keys??(r.keys=[]);const i=r.series.map(a=>Vg(a));ba(r.keys,i),r.keys.forEach((a,o)=>this.push(a,i[o]))}else Object.entries(e).forEach(([r,i])=>{const a=parseInt(r);if(!isNaN(a))return this.push(a,...T(i));this.push(r,...T(i))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const r=T(n),i=T(e);ba(i,r),r.forEach((a,o)=>this.push(i[o],a));return}throw new J(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
51
- payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
52
- 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 be("colType is not key");return this.columns??[]}get uniqueKeys(){return Hi(this.keys)}get names(){if(this.colType==="key")throw new be("colType is not name");return this.columns??[]}get uniqueNames(){return Hi(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Wg(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(n=>n.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return se.ZERO;const r=x.min(...this.series.map(a=>a.timeRange.start)),i=x.max(...this.series.map(a=>a.timeRange.end));return new se(r,i)}const n=this.get(e);return n==null?se.ZERO:n.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(n=>e.includes(n)):new Lf(this.series.filter((n,r)=>this.columns[r]===e))}push(e,...n){if(e instanceof rt){if(this.colType!==null&&e.colType!==this.colType)throw new J("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...n),typeof e=="string"&&this.colType==="key")throw new J("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new J("keyVariant must match");this.columns.push(...Array.from({length:n.length},()=>e))}}concat(e){return new rt([...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 n=new rt;return this.forEach((r,i,a)=>n.push(...e(r,i,a))),n}forEach(e){this.columns.forEach((n,r)=>{const i=this.series[r];e(n,i,r)})}at(e,n=!1){const r={};return this.uniqueColumns.forEach(i=>{r[i]=this.get(i).at(e,n)}),r}filter(e){const n=new rt;return this.columns.forEach((r,i)=>{const a=this.series[i];e(r,a,i)&&n.push(r,a)}),n}get byteLength(){return new lt(this.series.reduce((e,n)=>e.add(n.byteLength),lt.ZERO))}get length(){return this.series.reduce((e,n)=>e+n.length,0)}};const Vs=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(()=>[]),Je.crudeZ.array().optional().default([])])}),Vg=t=>{const{dataType:e,data:n,timeRange:r,alignment:i}=t;return new Je({data:n,dataType:e,timeRange:r,glBufferUsage:"static",alignment:i})},Wg=t=>({timeRange:t._timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});class Or{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,n){const r=new Or(e);return await r.update(n),r}async update(e){const{variant:n,normalized:r}=De(e);if(n==="keys"){this.adapter=null,this.keys=r;return}const i=await this.retriever.retrieve(r),a=new Map;this.adapter=a,r.forEach(o=>{const c=i.find(u=>u.name===o);if(c==null)throw new Error(`Channel ${o} not found`);a.set(c.key,c.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const n=this.adapter;return e.map((r,i)=>{if(typeof r=="number"){const a=n.get(r);if(a==null)throw new Error(`Channel ${r} not found`);return[a,i]}return[r,i]})}}class Ws{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,n){const r=new Ws(e);return await r.update(n),r}async adaptObjectKeys(e){const n={};for(const[r,i]of Object.entries(e))n[await this.adaptToKey(r)]=i;return n}async update(e){const n=await gl(this.retriever,e);this.adapter=new Map(n.map(r=>[r.name,r.key])),this.keys=n.map(r=>r.key)}async fetchChannel(e){const n=await this.retriever.retrieve(e);if(n.length===0)throw new Error(`Channel ${e} not found`);return n[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}async adapt(e,n){if(typeof e=="string"||typeof e=="number"){if(n==null)throw new J(`
53
- Received a single channel name or key but no series.
54
- `);if(Array.isArray(n)){if(n.some(u=>u instanceof Je||Array.isArray(u)))throw new J(`
55
- Received a single channel name or key but multiple series.
56
- `);n=n}const o=await this.fetchChannel(e),c=new Je({data:n,dataType:o.dataType});return new ve(o.key,c)}if(Array.isArray(e)){if(n==null)throw new J(`
57
- Received an array of channel names or keys but no series.
58
- `);if(!Array.isArray(n))throw new J(`
59
- Received an array of channel names or keys but no array of series.
60
- `);const o=[],c=[];for(let u=0;u<e.length;u++){const h=await this.fetchChannel(e[u]);if(u>=n.length)throw new J(`
61
- Received an array of channel names or keys but not enough series.
62
- `);const f=new Je({data:n[u],dataType:h.dataType});o.push(h.key),c.push(f)}return new ve(o,c)}if(e instanceof ve||e instanceof Map){const o=new ve(e);if(this.adapter==null)return o;const c=o.columns.map(u=>{var h;const f=typeof u=="string"?(h=this.adapter)==null?void 0:h.get(u):u;if(f==null)throw new J(`
63
- Channel ${u} was not provided in the list of channels when opening the writer
64
- `);return f});return new ve(c,o.series)}const r=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],h=await this.fetchChannel(c),f=new Je({data:u,dataType:h.dataType});r.push(h.key),i.push(f)}return new ve(r,i)}}class Gs{constructor(e,n){l(this,"name"),l(this,"stream"),this.stream=n,this.name=e}async receive(){const[e,n]=await this.stream.receive();if(n!=null)throw n;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,n]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on closure.
65
- Please report this error to the Synnax team. ${JSON.stringify(e)}`),n!=null){if(qe.matches(n))return;throw n}}}closeSend(){this.stream.closeSend()}send(e){const n=this.stream.send(e);if(n!=null)throw n}}const va=new $(-1);var Zs=(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))(Zs||{}),Tl=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(Tl||{});const Gg=s.z.object({command:s.z.nativeEnum(Zs),span:$.z.optional(),bounds:se.z.optional(),stamp:x.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),Zg=s.z.object({variant:s.z.nativeEnum(Tl),ack:s.z.boolean(),command:s.z.nativeEnum(Zs),error:ln.optional().nullable(),frame:Vs.optional()}),Sl=class Ss{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"value"),this.stream=new Gs("Iterator",e),this.value=new ve,this.adapter=n}static async _open(e,n,r,i,a={}){const o=await Or.open(r,n),c=await i.stream(Ss.ENDPOINT,Gg,Zg),u=new Ss(c,o);return await u.execute({command:0,keys:o.keys,bounds:new se(e),chunkSize:a.chunkSize??1e5}),u}async next(e=va){return await this.execute({command:1,span:new $(e)})}async prev(e=va){return await this.execute({command:2,span:new $(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 x(e)})}async seekGE(e){return await this.execute({command:6,stamp:new x(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Kg(this)}async execute(e){for(this.stream.send(e),this.value=new ve;;){const n=await this.stream.receive();if(n.variant===1)return n.ack;this.value.push(this.adapter.adapt(new ve(n.frame)))}}};l(Sl,"ENDPOINT","/frame/iterate");let Jg=Sl;class Kg{constructor(e){l(this,"iter"),l(this,"open",!1),this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Hg=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Xg=s.z.object({frame:Vs,error:ln.optional().nullable()}),Qg="/frame/stream";class Js{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"downsampleFactor"),this.stream=new Gs("Streamer",e),this.adapter=n,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,n,{channels:r,downsampleFactor:i}){const a=await Or.open(e,r),o=await n.stream(Qg,Hg,Xg),c=new Js(o,a);o.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await o.receive();if(u!=null)throw u;return c}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(qe.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new ve((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class dt extends Qe.Observer{constructor(e,n){super(n),l(this,"streamer"),l(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var Ks=(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))(Ks||{}),Qt=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(Qt||{});const ep=t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof t=="number"&&t in Qt)return t;throw new Error(`invalid writer mode: ${t}`)}};new $(-1);const tp=s.z.object({start:x.z.optional(),controlSubject:ct.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:ct.Authority.z.array().optional(),mode:s.z.nativeEnum(Qt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:$.z.optional()}),np=s.z.object({command:s.z.nativeEnum(Ks),config:tp.optional(),frame:Vs.optional()}),rp=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Ks),error:ln.optional().nullable()});var Tt;let sp=(Tt=class{constructor(t,e){l(this,"stream"),l(this,"adapter"),this.stream=new Gs("Writer",t),this.adapter=e}static async _open(t,e,{channels:n,start:r=x.now(),authorities:i=ct.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:c=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:h=$.SECOND}){const f=await Ws.open(t,n),d=await e.stream(Tt.ENDPOINT,np,rp),A=new Tt(d,f);return await A.execute({command:0,config:{start:new x(r),keys:f.keys,controlSubject:a,authorities:T(i),mode:ep(o),errOnUnauthorized:c,enableAutoCommit:u,autoIndexPersistInterval:h}}),A}async write(t,e){const n=await this.adapter.adapt(t,e);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(t,e){let n;if(typeof t=="number"&&e==null)n={keys:[],authorities:[t]};else{let r;typeof t=="string"||typeof t=="number"?r={[t]:e}:r=t,r=await this.adapter.adaptObjectKeys(r),n={keys:Object.keys(r).map(i=>Number(i)),authorities:Object.values(r)}}return(await this.execute({command:4,config:n})).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?Ps(t.error):null}async close(){await this.stream.closeAndAck()}async execute(t){for(this.stream.send(t);;){const e=await this.stream.receive();if(e.command===t.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},l(Tt,"ENDPOINT","/frame/write"),Tt),ip=class{constructor(t,e,n){l(this,"streamClient"),l(this,"retriever"),l(this,"deleter"),this.streamClient=t,this.retriever=n,this.deleter=new qg(e)}async openIterator(t,e,n){return await Jg._open(t,e,this.retriever,this.streamClient,n)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await sp._open(this.retriever,this.streamClient,t)}async openStreamer(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t,downsampleFactor:1}),await Js._open(this.retriever,this.streamClient,t)}async write(t,e,n){if(n==null){const i=e,a=await this.openWriter({start:t,channels:Object.keys(i),mode:Qt.Persist});try{await a.write(i),await a.commit()}finally{await a.close()}return}const r=await this.openWriter({start:t,channels:e,mode:Qt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:$.MAX});try{await r.write(e,n)}finally{await r.close()}}async read(t,e){const{single:n}=De(e),r=await this.readFrame(t,e);return n?r.get(e):r}async readFrame(t,e){const n=await this.openIterator(t,e),r=new ve;try{for await(const i of n)r.push(i)}finally{await n.close()}return r}async delete(t,e){const{normalized:n,variant:r}=De(t);return r==="keys"?await this.deleter.delete({keys:n,bounds:e}):await this.deleter.delete({names:n,bounds:e})}};const ap=ct.Authority,op=ct.stateZ(s.z.number()),lp=t=>{var e,n;return t.to==null?`${(e=t.from)==null?void 0:e.resource} - ${(n=t.from)==null?void 0:n.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 zl extends dt{constructor(e){super(e,n=>{const r=this.codec.decode(n.series[0].data);return this.merge(r),[r.transfers,!0]}),l(this,"states"),l(this,"codec"),this.states=new Map,this.codec=new yt.JSONCodec}subjects(){const e=new Map;return this.states.forEach(n=>e.set(n.subject.key,n.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(n=>{n.from==null&&n.to==null&&console.warn("Invalid transfer: ",n),n.to==null?this.states.delete(n.from.resource):this.states.set(n.to.resource,n.to)})}}const cp="sy_node_1_control";let Nl=class{constructor(t){l(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(cp);return new zl(t)}};const up=Object.freeze(Object.defineProperty({__proto__:null,Authority:ap,Client:Nl,StateTracker:zl,stateZ:op,transferString:lp},Symbol.toStringTag,{value:"Module"}));let hp=class{constructor(t,e,n){l(this,"tasks"),l(this,"racks"),l(this,"devices"),this.tasks=t,this.racks=e,this.devices=n}};const fn=s.z.number(),Hs=s.z.object({key:fn,name:s.z.string()}),dp=Hs.partial({key:!0}),Xs=s.z.string(),Tr=s.z.object({key:Xs,rack:fn,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===""?{}:yt.JSON_CODEC.decodeString(t)))}),fp=Tr.extend({properties:s.z.unknown().transform(t=>yt.JSON_CODEC.encodeString(t))}),pt=async(t,e,n,r)=>{const i=await t.openStreamer([e,n]),a=o=>{const c=[];return n!=null&&c.push(...o.get(n).series.flatMap(u=>r("delete",u))),e!=null&&c.push(...o.get(e).series.flatMap(u=>r("set",u))),[c,c.length>0]};return new dt(i,a)},yp="sy_device_set",gp="sy_device_delete",Fr="/hardware/device/retrieve",pp="/hardware/device/create",mp="/hardware/device/delete",wp=s.z.object({devices:fp.array()}),bp=s.z.object({devices:Tr.array()}),vp=s.z.object({keys:Xs.array()}),Op=s.z.object({}),qr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Xs.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),Vr=s.z.object({devices:me(Tr)});let Tp=class{constructor(t,e){l(this,"type","device"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const n=!Array.isArray(t),r=await v(this.client,Fr,{keys:T(t),...e},qr,Vr);return br("Device",t,r.devices,n),n?r.devices[0]:r.devices}async search(t,e){return(await v(this.client,Fr,{search:t,...e},qr,Vr)).devices}async page(t,e,n){return(await v(this.client,Fr,{offset:t,limit:e,...n},qr,Vr)).devices}async create(t){const e=!Array.isArray(t),n=await v(this.client,pp,{devices:T(t)},wp,bp);return e?n.devices[0]:n.devices}async delete(t){await v(this.client,mp,{keys:T(t)},vp,Op)}async openDeviceTracker(){return await pt(this.frameClient,yp,gp,Sp)}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,n)=>await this.page(e,n,t)}}};const Sp=(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):e.parseJSON(Tr).map(n=>({variant:t,key:n.key,value:n})),Wr="/hardware/rack/retrieve",zp="/hardware/rack/create",Np="/hardware/rack/delete",Gr=s.z.object({keys:fn.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Zr=s.z.object({racks:me(Hs)}),Ep=s.z.object({racks:dp.array()}),Ip=s.z.object({racks:Hs.array()}),kp=s.z.object({keys:fn.array()}),Ap=s.z.object({});let xp=class{constructor(t,e,n){l(this,"type","rack"),l(this,"client"),l(this,"frameClient"),l(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=n}async delete(t){await v(this.client,Np,{keys:T(t)},kp,Ap)}async create(t){const e=!Array.isArray(t),n=await v(this.client,zp,{racks:T(t)},Ep,Ip),r=this.sugar(n.racks);return e?r[0]:r}async search(t){const e=await v(this.client,Wr,{search:t},Gr,Zr);return this.sugar(e.racks)}async page(t,e){const n=await v(this.client,Wr,{offset:t,limit:e},Gr,Zr);return this.sugar(n.racks)}async retrieve(t){const{variant:e,normalized:n,single:r}=wr(t,{string:"names",number:"keys"}),i=await v(this.client,Wr,{[e]:n},Gr,Zr),a=this.sugar(i.racks);return br("Rack",t,a,r),r?a[0]:a}sugar(t){return t.map(({key:e,name:n})=>new Cp(e,n,this.tasks))}};class Cp{constructor(e,n,r){l(this,"key"),l(this,"name"),l(this,"tasks"),this.key=e,this.name=n,this.tasks=r}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 mt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),or=s.z.object({task:mt,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())}),Sr=s.z.object({key:mt,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===""?{}:yt.JSON_CODEC.decodeString(t))),state:or.optional().nullable(),snapshot:s.z.boolean().optional()}),$p=Sr.omit({key:!0}).extend({key:mt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>yt.JSON_CODEC.encodeString(t))}),El=s.z.object({task:mt,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))).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Jt="sy_task_state",st="sy_task_cmd",St=new Error("Task not created");class jp{constructor(e,n,r,i,a=!1,o=!1,c,u=null,h=null,f=null){l(this,"key"),l(this,"name"),l(this,"internal"),l(this,"type"),l(this,"config"),l(this,"snapshot"),l(this,"state"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=e,this.name=n,this.type=r,this.config=i,this.internal=a,this.snapshot=o,c!==null&&(this.state=c),this.frameClient=u,this.ontologyClient=h,this.rangeClient=f}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new j({type:"task",key:this.key})}async executeCommand(e,n){if(this.frameClient==null)throw St;const r=await this.frameClient.openWriter(st),i=Cf.id();return await r.write(st,[{task:this.key,type:e,key:i,args:n}]),await r.close(),i}async executeCommandSync(e,n,r){if(this.frameClient==null)throw St;const i=await this.frameClient.openStreamer(Jt),a=await this.executeCommand(e,n);let o;const c=new Promise(u=>setTimeout(()=>u(!1),new $(r).milliseconds));for(;;){const u=await Promise.any([i.read(),c]);if(u===!1)throw new Error("Command timed out");const h=or.safeParse(u.at(-1).sy_task_state);if(h.success){if(o=h.data,o.key===a)break}else console.error(h.error)}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw St;return new dt(await this.frameClient.openStreamer(Jt),e=>{const n=e.get(Jt);if(n.length===0)return[null,!1];const r=or.safeParse(n.at(-1));if(!r.success)return console.error(r.error),[null,!1];const i=r.data;return i.task!==this.key?[null,!1]:[i,!0]})}async openCommandObserver(){if(this.frameClient==null)throw St;return new dt(await this.frameClient.openStreamer(st),e=>{const n=e.get(st);if(n.length===0)return[null,!1];const r=El.safeParse(n.at(-1));if(!r.success)return console.error(r.error),[null,!1];const i=r.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw St;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Rp=s.z.object({rack:fn.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()}),Mp=s.z.object({tasks:me(Sr)}),Bp="/hardware/task/retrieve",Dp="/hardware/task/create",Pp="/hardware/task/delete",Up="/hardware/task/copy",Lp=s.z.object({tasks:$p.array()}),_p=s.z.object({tasks:Sr.array()}),Yp=s.z.object({keys:mt.array()}),Fp=s.z.object({}),qp=s.z.object({key:mt,name:s.z.string(),snapshot:s.z.boolean()}),Vp=s.z.object({task:Sr});let Wp=class{constructor(t,e,n,r){l(this,"type","task"),l(this,"client"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.client=t,this.frameClient=e,this.ontologyClient=n,this.rangeClient=r}async create(t){const e=!Array.isArray(t),n=await v(this.client,Dp,{tasks:T(t)},Lp,_p),r=this.sugar(n.tasks);return e?r[0]:r}async delete(t){await v(this.client,Pp,{keys:T(t)},Yp,Fp)}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:n,normalized:r,variant:i}=wr(t,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};i==="rack"?a.rack=t:a.keys=r;const o=await this.execRetrieve(a),c=this.sugar(o);return n&&i!=="rack"?c[0]:c}async copy(t,e,n){const r=await v(this.client,Up,{key:t,name:e,snapshot:n},qp,Vp);return this.sugar([r.task])[0]}async retrieveByName(t,e){const n=await this.execRetrieve({names:[t],rack:e});return br("Task",t,n,!0),this.sugar(n)[0]}async execRetrieve(t){return(await v(this.client,Bp,t,Rp,Mp)).tasks}sugar(t){return t.map(({key:e,name:n,type:r,config:i,state:a,internal:o,snapshot:c})=>new jp(e,n,r,i,o,c,a,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await pt(this.frameClient,"sy_task_set","sy_task_delete",(t,e)=>Array.from(e).map(n=>({variant:t,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new dt(await this.frameClient.openStreamer(Jt),t=>{const e=t.get(Jt);if(e.length===0)return[null,!1];const n=or.safeParse(e.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}async openCommandObserver(){return new dt(await this.frameClient.openStreamer(st),t=>{const e=t.get(st);if(e.length===0)return[null,!1];const n=El.safeParse(e.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}};const yn=s.z.string().uuid(),zr=s.z.object({key:yn,name:s.z.string().min(1),color:s.z.string()}),Gp=s.z.object({keys:yn.array().optional(),for:ge.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Zp=s.z.object({labels:me(zr)});var On;let Jp=(On=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(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,n]=await this.client.send(On.ENDPOINT,t,Gp,Zp);if(n!=null)throw n;return e.labels}},l(On,"ENDPOINT","/label/retrieve"),On);const Kp=zr.extend({key:yn.optional()}),Hp=s.z.object({labels:Kp.array()}),Xp=s.z.object({labels:zr.array()}),Qp=s.z.object({keys:yn.array()}),Il=s.z.object({id:ge,labels:yn.array(),replace:s.z.boolean().optional()}),em=Il.omit({replace:!0}),Jr=s.z.object({}),tm="/label/create",nm="/label/delete",rm="/label/set",sm="/label/remove";let im=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,tm,{labels:T(t)},Hp,Xp)).labels}async delete(t){await v(this.client,nm,{keys:T(t)},Qp,Jr)}async set(t,e,{replace:n}={}){await v(this.client,rm,{id:t,labels:e,replace:n},Il,Jr)}async remove(t,e){await v(this.client,sm,{id:t,labels:e},em,Jr)}};const am="sy_label_set",om="sy_label_delete";let lm=class{constructor(t,e,n){l(this,"type","label"),l(this,"retriever"),l(this,"writer"),l(this,"frameClient"),l(this,"ontology"),this.writer=new im(t),this.retriever=new Jp(t),this.frameClient=e,this.ontology=n}async search(t){return await this.retriever.search(t)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async retrieveFor(t){return await this.retriever.retrieveFor(new j(t))}async label(t,e,n={}){await this.writer.set(new j(t),e,n)}async removeLabels(t,e){await this.writer.remove(new j(t),e)}async page(t,e){return await this.retriever.page(t,e)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async openChangeTracker(){return await pt(this.frameClient,am,om,cm)}async trackLabelsOf(t){const e=new Qe.Observer,n=(await this.retrieveFor(t)).map(r=>({id:new j({key:r.key,type:"label"}),key:r.key,name:r.name,data:r}));return(await this.ontology.openDependentTracker({target:new j(t),dependents:n,relationshipType:"labeled_by"})).onChange(r=>e.notify(r.map(i=>{var a,o;return{key:i.id.key,color:(a=i.data)==null?void 0:a.color,name:(o=i.data)==null?void 0:o.name}}))),e}};const cm=(t,e)=>t==="delete"?e.toUUIDs().map(n=>({variant:t,key:n})):e.parseJSON(zr).map(n=>({variant:t,key:n.key,value:n})),ye=s.z.string().uuid(),gn=s.z.object({key:ye,name:s.z.string().min(1),timeRange:se.z,color:s.z.string().optional()}),kl=gn.extend({key:s.z.string().uuid().optional()}),Al=t=>{const e=T(t),n=e.length===0;let r=!1;return n||(r=ye.safeParse(e[0]).success),{single:!Array.isArray(t),variant:r?"keys":"names",normalized:e,actual:t,empty:n}},xl="range",Cl="range-alias",um=t=>new j({type:xl,key:t}),hm=t=>new j({type:Cl,key:t}),dm="sy_range_alias_set",fm="sy_range_alias_delete",ym=s.z.object({range:ye,aliases:s.z.string().array()}),gm=s.z.object({aliases:s.z.record(s.z.string(),We)}),pm=s.z.object({range:ye,aliases:s.z.record(We.or(s.z.string()),s.z.string())}),mm=s.z.unknown(),wm=s.z.object({range:ye,channels:We.array()}),bm=s.z.unknown(),vm=s.z.object({range:ye}),Om=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),Ft=class qt{constructor(e,n,r){l(this,"frameClient"),l(this,"cache",new Map),l(this,"client"),l(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=r,this.frameClient=n}async resolve(e){const n=[],r=typeof e=="string",i={};if(r){const o=this.cache.get(e);if(o!=null)return o;n.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:n.push(o)});if(n.length===0)return i;const a=await v(this.client,qt.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:n},ym,gm);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),r?a.aliases[n[0]]:{...i,...a.aliases}}async set(e){await v(this.client,qt.SET_ENDPOINT,{range:this.rangeKey,aliases:e},pm,mm)}async list(){return(await v(this.client,qt.LIST_ENDPOINT,{range:this.rangeKey},vm,Om)).aliases}async delete(e){await v(this.client,qt.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},wm,bm)}async openChangeTracker(){return await pt(this.frameClient,dm,fm,Nm(this.rangeKey))}};l(Ft,"SET_ENDPOINT","/range/alias/set"),l(Ft,"RESOLVE_ENDPOINT","/range/alias/resolve"),l(Ft,"LIST_ENDPOINT","/range/alias/list"),l(Ft,"DELETE_ENDPOINT","/range/alias/delete");let Tm=Ft;const Sm=s.z.object({range:ye,channel:We,alias:s.z.string()}),zm="---",Nm=t=>(e,n)=>e==="delete"?n.toStrings().filter(r=>r.split(zm)[0]===t).map(r=>({variant:e,key:r,value:void 0})):n.parseJSON(Sm).map(r=>({variant:e,key:r.alias,value:r})),Em=s.z.object({range:ye,keys:s.z.string().array()}),Qs=s.z.object({range:ye,key:s.z.string(),value:s.z.string()}),Im=s.z.object({pairs:me(Qs)}),km=s.z.object({range:ye,pairs:Qs.array()}),Am=s.z.object({range:ye,keys:s.z.string().array()}),er=class tr{constructor(e,n,r){l(this,"rangeKey"),l(this,"client"),l(this,"frameClient"),this.rangeKey=e,this.client=n,this.frameClient=r}async get(e){const n=await v(this.client,tr.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},Em,Im);return typeof e=="string"?n.pairs[0].value:Object.fromEntries(n.pairs.map(r=>[r.key,r.value]))}async list(){return this.get([])}async set(e,n=""){let r;Us(e)?r=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):r=[{range:this.rangeKey,key:e,value:n}],await v(this.client,tr.SET_ENDPOINT,{range:this.rangeKey,pairs:r},km,s.z.unknown())}async delete(e){await v(this.client,tr.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},Am,s.z.unknown())}async openTracker(){return await pt(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,n)=>e==="delete"?n.toStrings().map(r=>{const[i,a]=r.split("<--->",2);return{variant:e,key:r,value:{range:i,key:a,value:""}}}):n.parseJSON(Qs).map(r=>({variant:e,key:`${r.range}${r.key}`,value:r})))}};l(er,"GET_ENDPOINT","/range/kv/get"),l(er,"SET_ENDPOINT","/range/kv/set"),l(er,"DELETE_ENDPOINT","/range/kv/delete");let zs=er;const Kr=t=>new j({type:"range",key:t});class $l{constructor(e,n=se.ZERO,r,i,a,o,c,u,h,f,d){l(this,"key"),l(this,"name"),l(this,"kv"),l(this,"timeRange"),l(this,"color"),l(this,"channels"),l(this,"aliaser"),l(this,"frameClient"),l(this,"labelClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=r,this.name=e,this.timeRange=n,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=c,this.channels=u,this.labelClient=h,this.ontologyClient=f,this.rangeClient=d}get ontologyID(){return new j({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,n){const r=await this.channels.retrieve(e);if(r.length===0)throw new Oe(`Channel ${e} does not exist`);await this.aliaser.set({[r[0].key]:n})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(n=>n.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(Kr(this.key))}async addLabel(...e){await this.labelClient.label(Kr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Kr(this.key),e)}async openChildRangeTracker(){const e=new Qe.Observer,n=(await this.retrieveChildren()).map(i=>{const a=new j({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),r=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:n,resourceType:"range"});return r.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await r.close()),e}async openParentRangeTracker(){const e=new Qe.Observer,n=await this.retrieveParent();if(n==null)return null;const r=new j({key:n.key,type:"range"}),i={id:r,key:r.toString(),name:n.name,data:n.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const c=this.rangeClient.resourcesToRanges(o);if(c.length===0)return;const u=c[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const xm=s.z.object({keys:ye.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:se.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Cm="/range/retrieve",$m=s.z.object({ranges:me(gn)});let jl=class{constructor(t,e,n,r,i,a){l(this,"type","range"),l(this,"frameClient"),l(this,"writer"),l(this,"unaryClient"),l(this,"channels"),l(this,"labelClient"),l(this,"ontologyClient"),this.frameClient=t,this.writer=e,this.unaryClient=n,this.channels=r,this.labelClient=i,this.ontologyClient=a}async create(t,e){const n=!Array.isArray(t),r=this.sugarMany(await this.writer.create(T(t),e));return n?r[0]:r}async rename(t,e){await this.writer.rename(t,e)}async delete(t){await this.writer.delete(T(t))}async search(t){return this.sugarMany(await this.execRetrieve({term:t}))}async page(t,e){return this.sugarMany(await this.execRetrieve({offset:t,limit:e}))}async retrieve(t){if(typeof t=="object"&&"start"in t)return await this.execRetrieve({overlapsWith:new se(t)});const{single:e,actual:n,variant:r,normalized:i,empty:a}=Al(t);if(a)return[];const o=await this.execRetrieve({[r]:i});if(!e)return o;if(o.length===0)throw new ut(`range matching ${n} not found`);if(o.length>1)throw new ht(`multiple ranges matching ${n} found`);return o[0]}getKV(t){return new zs(t,this.unaryClient,this.frameClient)}async execRetrieve(t){const{ranges:e}=await v(this.unaryClient,Cm,t,xm,$m);return this.sugarMany(e)}async retrieveParent(t){const e=await this.ontologyClient.retrieveParents({key:t,type:"range"});if(e.length===0)return null;const n=e[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(t){return new $l(t.name,t.timeRange,t.key,t.color,this.frameClient,new zs(t.key,this.unaryClient,this.frameClient),new Tm(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(t){return t.map(e=>this.sugarOne(e))}async openTracker(){return await pt(this.frameClient,"sy_range_set","sy_range_delete",(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):this.sugarMany(e.parseJSON(gn)).map(n=>({variant:t,key:n.key,value:n})))}resourcesToRanges(t){return t.map(e=>this.resourceToRange(e))}resourceToRange(t){var e,n,r;return this.sugarOne({key:t.id.key,name:(e=t.data)==null?void 0:e.name,timeRange:new se((n=t.data)==null?void 0:n.timeRange),color:(r=t.data)==null?void 0:r.color})}};const jm=s.z.object({ranges:gn.array()}),Rm=s.z.object({parent:ge.optional(),ranges:kl.array()}),Mm=s.z.object({keys:ye.array()}),Bm=s.z.object({}),Dm=s.z.object({key:ye,name:s.z.string()}),Pm=s.z.object({}),Um="/range/create",Lm="/range/delete",_m="/range/rename";let Rl=class{constructor(t){l(this,"client"),this.client=t}async rename(t,e){await v(this.client,_m,{key:t,name:e},Dm,Pm)}async create(t,e){return(await v(this.client,Um,{ranges:t,...e},Rm,jm)).ranges}async delete(t){await v(this.client,Lm,{keys:t},Mm,Bm)}};const Ym=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:Cl,Client:jl,KV:zs,ONTOLOGY_TYPE:xl,Range:$l,Writer:Rl,analyzeParams:Al,keyZ:ye,newPayloadZ:kl,payloadZ:gn,rangeAliasOntologyID:hm,rangeOntologyID:um},Symbol.toStringTag,{value:"Module"})),Fm="/api/v1/";class qm{constructor(e,n=!1){l(this,"url"),l(this,"unary"),l(this,"stream"),l(this,"secure"),this.secure=n,this.url=e.child(Fm);const r=new yt.JSONCodec;this.unary=new Od(this.url,r,this.secure),this.stream=new xd(this.url,r,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ei=s.z.string().uuid(),ti=s.z.object({key:s.z.string(),name:s.z.string(),data:cn.or(s.z.string().transform(t=>JSON.parse(t)))}),Vm=s.z.object({keys:s.z.string().array()}),Wm=s.z.object({linePlots:ti.array()});let Gm=class{constructor(t){l(this,"ENDPOINT","/workspace/lineplot/retrieve"),l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return(await v(this.client,this.ENDPOINT,{keys:e},Vm,Wm)).linePlots}};const Pe=s.z.string().uuid(),Ml=t=>JSON.parse(t),Bl=s.z.object({name:s.z.string(),key:Pe,layout:cn.or(s.z.string().transform(t=>Ml(t)))}),Dl=Bl.omit({layout:!0}).extend({layout:s.z.string().transform(t=>Ml(t))}),Zm=ti.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Jm=s.z.object({workspace:Pe,linePlots:Zm.array()}),Km=s.z.object({linePlots:ti.array()}),Hm=s.z.object({keys:ei.array()}),Xm=s.z.object({}),Qm=s.z.object({key:ei,name:s.z.string()}),ew=s.z.object({}),tw=s.z.object({key:ei,data:s.z.string()}),nw=s.z.object({}),rw="/workspace/lineplot/create",sw="/workspace/lineplot/delete",iw="/workspace/lineplot/rename",aw="/workspace/lineplot/set-data";let ow=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,rw,{workspace:t,linePlots:[n]},Jm,Km)).linePlots[0]}async delete(t){const e=T(t);await v(this.client,sw,{keys:e},Hm,Xm)}async rename(t,e){await v(this.client,iw,{key:t,name:e},Qm,ew)}async setData(t,e){await v(this.client,aw,{key:t,data:JSON.stringify(e)},tw,nw)}},lw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new ow(t),this.retriever=new Gm(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),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const ni=s.z.string().uuid(),cw=s.z.object({key:s.z.string(),name:s.z.string(),data:cn.or(s.z.string().transform(t=>JSON.parse(t)))}),Pl=s.z.object({key:s.z.string(),name:s.z.string(),data:s.z.string().transform(t=>JSON.parse(t))}),uw=s.z.object({keys:s.z.string().array()}),hw=s.z.object({logs:Pl.array()});let dw=class{constructor(t){l(this,"ENDPOINT","/workspace/log/retrieve"),l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,this.ENDPOINT,{keys:T(t)},uw,hw)).logs}};const fw=cw.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),yw=s.z.object({workspace:Pe,logs:fw.array()}),gw=s.z.object({logs:Pl.array()}),pw=s.z.object({keys:ni.array()}),mw=s.z.object({}),ww=s.z.object({key:ni,name:s.z.string()}),bw=s.z.object({}),vw=s.z.object({key:ni,data:s.z.string()}),Ow=s.z.object({}),Tw="/workspace/log/create",Sw="/workspace/log/delete",zw="/workspace/log/rename",Nw="/workspace/log/set-data";let Ew=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,Tw,{workspace:t,logs:[n]},yw,gw)).logs[0]}async delete(t){const e=T(t);await v(this.client,Sw,{keys:e},pw,mw)}async rename(t,e){await v(this.client,zw,{key:t,name:e},ww,bw)}async setData(t,e){await v(this.client,Nw,{key:t,data:JSON.stringify(e)},vw,Ow)}},Iw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Ew(t),this.retriever=new dw(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),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const kw=s.z.object({keys:Pe.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Aw=s.z.object({workspaces:me(Dl)});var Tn;let xw=(Tn=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(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,Tn.ENDPOINT,t,kw,Aw)).workspaces}},l(Tn,"ENDPOINT","/workspace/retrieve"),Tn);const Nr=s.z.string().uuid(),Cw=s.z.object({key:s.z.string(),name:s.z.string(),data:cn.or(s.z.string().transform(t=>JSON.parse(t))),snapshot:s.z.boolean()}),ri=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(t=>JSON.parse(t))}),$w=s.z.object({keys:s.z.string().array()}),jw=s.z.object({schematics:ri.array()});let Rw=class{constructor(t){l(this,"ENDPOINT","/workspace/schematic/retrieve"),l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,this.ENDPOINT,{keys:T(t)},$w,jw)).schematics}};const Mw=Cw.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Bw=s.z.object({workspace:Pe,schematics:Mw.array()}),Dw=s.z.object({schematics:ri.array()}),Pw=s.z.object({keys:Nr.array()}),Uw=s.z.object({}),Lw=s.z.object({key:Nr,name:s.z.string()}),_w=s.z.object({}),Yw=s.z.object({key:Nr,data:s.z.string()}),Fw=s.z.object({}),qw=s.z.object({key:Nr,name:s.z.string(),snapshot:s.z.boolean()}),Vw=s.z.object({schematic:ri}),Ww="/workspace/schematic/create",Gw="/workspace/schematic/delete",Zw="/workspace/schematic/rename",Jw="/workspace/schematic/set-data",Kw="/workspace/schematic/copy";let Hw=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,Ww,{workspace:t,schematics:[n]},Bw,Dw)).schematics[0]}async copy(t,e,n){return(await v(this.client,Kw,{key:t,name:e,snapshot:n},qw,Vw)).schematic}async delete(t){const e=T(t);await v(this.client,Gw,{keys:e},Pw,Uw)}async rename(t,e){await v(this.client,Zw,{key:t,name:e},Lw,_w)}async setData(t,e){await v(this.client,Jw,{key:t,data:JSON.stringify(e)},Yw,Fw)}},Xw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Hw(t),this.retriever=new Rw(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),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async copy(t,e,n){return await this.writer.copy(t,e,n)}};const si=s.z.string().uuid(),Qw=s.z.object({key:s.z.string(),name:s.z.string(),data:cn.or(s.z.string().transform(t=>JSON.parse(t)))}),Ul=s.z.object({key:s.z.string(),name:s.z.string(),data:s.z.string().transform(t=>JSON.parse(t))}),eb=s.z.object({keys:s.z.string().array()}),tb=s.z.object({tables:Ul.array()}),nb="/workspace/table/retrieve";class rb{constructor(e){l(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,nb,{keys:T(e)},eb,tb)).tables}}const sb=Qw.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ib=s.z.object({workspace:Pe,tables:sb.array()}),ab=s.z.object({tables:Ul.array()}),ob=s.z.object({keys:si.array()}),lb=s.z.object({}),cb=s.z.object({key:si,name:s.z.string()}),ub=s.z.object({}),hb=s.z.object({key:si,data:s.z.string()}),db=s.z.object({}),fb="/workspace/table/create",yb="/workspace/table/delete",gb="/workspace/table/rename",pb="/workspace/table/set-data";let mb=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,fb,{workspace:t,tables:[n]},ib,ab)).tables[0]}async delete(t){const e=T(t);await v(this.client,yb,{keys:e},ob,lb)}async rename(t,e){await v(this.client,gb,{key:t,name:e},cb,ub)}async setData(t,e){await v(this.client,pb,{key:t,data:JSON.stringify(e)},hb,db)}},wb=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new mb(t),this.retriever=new rb(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),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const bb=Bl.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),vb=s.z.object({workspaces:bb.array()}),Ob=s.z.object({workspaces:Dl.array()}),Tb=s.z.object({keys:Pe.array()}),Sb=s.z.object({}),zb=s.z.object({key:Pe,name:s.z.string()}),Nb=s.z.object({}),Eb=s.z.object({key:Pe,layout:s.z.string()}),Ib=s.z.object({}),kb="/workspace/create",Ab="/workspace/delete",xb="/workspace/rename",Cb="/workspace/set-layout";class $b{constructor(e){l(this,"client"),this.client=e}async create(e){return(await v(this.client,kb,{workspaces:T(e)},vb,Ob)).workspaces}async delete(e){await v(this.client,Ab,{keys:T(e)},Tb,Sb)}async rename(e,n){await v(this.client,xb,{key:e,name:n},zb,Nb)}async setLayout(e,n){await v(this.client,Cb,{key:e,layout:JSON.stringify(n)},Eb,Ib)}}class jb{constructor(e){l(this,"type","workspace"),l(this,"schematic"),l(this,"linePlot"),l(this,"log"),l(this,"table"),l(this,"retriever"),l(this,"writer"),this.schematic=new Xw(e),this.linePlot=new lw(e),this.retriever=new xw(e),this.log=new Iw(e),this.writer=new $b(e),this.table=new wb(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const n=Array.isArray(e),r=await this.retriever.retrieve(e);return n?r:r[0]}async page(e,n){return await this.retriever.page(e,n)}async create(e){const n=Array.isArray(e),r=await this.writer.create(e);return n?r:r[0]}async rename(e,n){await this.writer.rename(e,n)}async setLayout(e,n){await this.writer.setLayout(e,n)}async delete(...e){await this.writer.delete(e)}}const Ll=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().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:$.z.default($.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class _l extends ip{constructor(e){const n=Ll.parse(e),{host:r,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u}=n,h=new qm(new Xf({host:r,port:Number(i)}),u);h.use(uy);let f;a!=null&&o!=null&&(f=new Bg(h.unary,{username:a,password:o}),h.use(f.middleware()));const d=new qs(new Fs(h.unary)),A=new wl(h.unary,d);super(h.stream,h.unary,d),l(this,"createdAt"),l(this,"props"),l(this,"ranges"),l(this,"channels"),l(this,"auth"),l(this,"user"),l(this,"access"),l(this,"connectivity"),l(this,"ontology"),l(this,"workspaces"),l(this,"labels"),l(this,"hardware"),l(this,"control"),l(this,"transport"),l(this,"clientVersion","0.35.0"),this.createdAt=x.now(),this.props=n,this.auth=f,this.transport=h,this.channels=new ml(this,d,h.unary,A),this.connectivity=new Ol(h.unary,c,this.clientVersion,n.name),this.control=new Nl(this),this.ontology=new Iy(h.unary,this);const D=new Rl(this.transport.unary);this.labels=new lm(this.transport.unary,this,this.ontology),this.ranges=new jl(this,D,this.transport.unary,d,this.labels,this.ontology),this.access=new Yy(this.transport.unary),this.user=new Ag(this.transport.unary),this.workspaces=new jb(this.transport.unary);const ie=new Tp(this.transport.unary,this),M=new Wp(this.transport.unary,this,this.ontology,this.ranges),lc=new xp(this.transport.unary,this,M);this.hardware=new hp(M,lc,ie)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}l(_l,"connectivity",Ol);const Rb=ct.Authority,Ns=(t,e,n="")=>{try{return t.parse(e)}catch(r){if(r instanceof s.z.ZodError){const i=r.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${n} - ${i.join(`
66
- `)}`)}else throw r}};var Mb=Object.defineProperty,Bb=(t,e,n)=>e in t?Mb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e,n)=>Bb(t,typeof e!="symbol"?e+"":e,n);const Es=class Yl{constructor(e,n,r="",i=!1){ee(this,"_noop",!1),ee(this,"key"),ee(this,"path"),ee(this,"serviceName"),this.key=e,this.path=n,this.serviceName=r,this._noop=i}child(e){return new Yl(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};ee(Es,"NOOP",new Es("","",""));let ii=Es;const Is=["debug","info","warn","error"],Db=t=>{const e=Is.indexOf(t);return({level:n})=>Is.indexOf(n)>=e},Pb=t=>{const{include:e,exclude:n}=t;return({path:r})=>!(e!=null&&!e.some(i=>r.startsWith(i))||n!=null&&n.some(i=>r.startsWith(i)))},ks=class Fl{constructor(e={}){ee(this,"meta",ii.NOOP),ee(this,"filters");const{filters:n=[]}=e;this.filters=n}filter(e){return!this.meta.noop&&this.filters.every(n=>n({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const n=new Fl({filters:this.filters});return n.meta=e,n}debug(e,n,r=!1){!this.filter("debug")&&!r||(n==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,Sn(n)))}info(e,n,r=!1){!this.filter("info")&&!r||(n==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,Sn(n)))}warn(e,n,r=!1){!this.filter("warn")&&!r||(n==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,Sn(n)))}error(e,n,r=!1){!this.filter("error")&&!r||(n==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,Sn(n)))}};ee(ks,"NOOP",new ks);let ql=ks;const Sn=t=>typeof t=="function"?t():t;var Ub=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},Ke="1.9.0",Oa=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function Lb(t){var e=new Set([t]),n=new Set,r=t.match(Oa);if(!r)return function(){return!1};var i={major:+r[1],minor:+r[2],patch:+r[3],prerelease:r[4]};if(i.prerelease!=null)return function(c){return c===t};function a(c){return n.add(c),!1}function o(c){return e.add(c),!0}return function(c){if(e.has(c))return!0;if(n.has(c))return!1;var u=c.match(Oa);if(!u)return a(c);var h={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return h.prerelease!=null||i.major!==h.major?a(c):i.major===0?i.minor===h.minor&&i.patch<=h.patch?o(c):a(c):i.minor<=h.minor?o(c):a(c)}}var _b=Lb(Ke),Yb=Ke.split(".")[0],en=Symbol.for("opentelemetry.js.api."+Yb),tn=Ub;function ai(t,e,n,r){var i;r===void 0&&(r=!1);var a=tn[en]=(i=tn[en])!==null&&i!==void 0?i:{version:Ke};if(!r&&a[t]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+t);return n.error(o.stack||o.message),!1}if(a.version!==Ke){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+t+" does not match previously registered API v"+Ke);return n.error(o.stack||o.message),!1}return a[t]=e,n.debug("@opentelemetry/api: Registered a global for "+t+" v"+Ke+"."),!0}function nn(t){var e,n,r=(e=tn[en])===null||e===void 0?void 0:e.version;if(!(!r||!_b(r)))return(n=tn[en])===null||n===void 0?void 0:n[t]}function oi(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+Ke+".");var n=tn[en];n&&delete n[t]}var Fb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},qb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Vb=function(){function t(e){this._namespace=e.namespace||"DiagComponentLogger"}return t.prototype.debug=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return zt("debug",this._namespace,e)},t.prototype.error=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return zt("error",this._namespace,e)},t.prototype.info=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return zt("info",this._namespace,e)},t.prototype.warn=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return zt("warn",this._namespace,e)},t.prototype.verbose=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return zt("verbose",this._namespace,e)},t}();function zt(t,e,n){var r=nn("diag");if(r)return n.unshift(e),r[t].apply(r,qb([],Fb(n),!1))}var pe;(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"})(pe||(pe={}));function Wb(t,e){t<pe.NONE?t=pe.NONE:t>pe.ALL&&(t=pe.ALL),e=e||{};function n(r,i){var a=e[r];return typeof a=="function"&&t>=i?a.bind(e):function(){}}return{error:n("error",pe.ERROR),warn:n("warn",pe.WARN),info:n("info",pe.INFO),debug:n("debug",pe.DEBUG),verbose:n("verbose",pe.VERBOSE)}}var Gb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Zb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Jb="diag",rn=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var c=nn("diag");if(c)return c[i].apply(c,Zb([],Gb(a),!1))}}var n=this,r=function(i,a){var o,c,u;if(a===void 0&&(a={logLevel:pe.INFO}),i===n){var h=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return n.error((o=h.stack)!==null&&o!==void 0?o:h.message),!1}typeof a=="number"&&(a={logLevel:a});var f=nn("diag"),d=Wb((c=a.logLevel)!==null&&c!==void 0?c:pe.INFO,i);if(f&&!a.suppressOverrideMessage){var A=(u=new Error().stack)!==null&&u!==void 0?u:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+A),d.warn("Current logger will overwrite one already registered from "+A)}return ai("diag",d,n,!0)};n.setLogger=r,n.disable=function(){oi(Jb,n)},n.createComponentLogger=function(i){return new Vb(i)},n.verbose=e("verbose"),n.debug=e("debug"),n.info=e("info"),n.warn=e("warn"),n.error=e("error")}return t.instance=function(){return this._instance||(this._instance=new t),this._instance},t}(),Kb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Hb=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Xb=function(){function t(e){this._entries=e?new Map(e):new Map}return t.prototype.getEntry=function(e){var n=this._entries.get(e);if(n)return Object.assign({},n)},t.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var n=Kb(e,2),r=n[0],i=n[1];return[r,i]})},t.prototype.setEntry=function(e,n){var r=new t(this._entries);return r._entries.set(e,n),r},t.prototype.removeEntry=function(e){var n=new t(this._entries);return n._entries.delete(e),n},t.prototype.removeEntries=function(){for(var e,n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];var a=new t(this._entries);try{for(var o=Hb(r),c=o.next();!c.done;c=o.next()){var u=c.value;a._entries.delete(u)}}catch(h){e={error:h}}finally{try{c&&!c.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();rn.instance();function Qb(t){return t===void 0&&(t={}),new Xb(new Map(Object.entries(t)))}function ev(t){return Symbol.for(t)}var tv=function(){function t(e){var n=this;n._currentContext=e?new Map(e):new Map,n.getValue=function(r){return n._currentContext.get(r)},n.setValue=function(r,i){var a=new t(n._currentContext);return a._currentContext.set(r,i),a},n.deleteValue=function(r){var i=new t(n._currentContext);return i._currentContext.delete(r),i}}return t}(),nv=new tv,rv={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},sv={set:function(t,e,n){t!=null&&(t[e]=n)}},iv=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},av=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},ov=function(){function t(){}return t.prototype.active=function(){return nv},t.prototype.with=function(e,n,r){for(var i=[],a=3;a<arguments.length;a++)i[a-3]=arguments[a];return n.call.apply(n,av([r],iv(i),!1))},t.prototype.bind=function(e,n){return n},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),lv=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},cv=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Hr="context",uv=new ov,Vl=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ai(Hr,e,rn.instance())},t.prototype.active=function(){return this._getContextManager().active()},t.prototype.with=function(e,n,r){for(var i,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(i=this._getContextManager()).with.apply(i,cv([e,n,r],lv(a),!1))},t.prototype.bind=function(e,n){return this._getContextManager().bind(e,n)},t.prototype._getContextManager=function(){return nn(Hr)||uv},t.prototype.disable=function(){this._getContextManager().disable(),oi(Hr,rn.instance())},t}(),As;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(As||(As={}));var hv=Vl.getInstance(),dv=function(){function t(){}return t.prototype.inject=function(e,n){},t.prototype.extract=function(e,n){return e},t.prototype.fields=function(){return[]},t}(),li=ev("OpenTelemetry Baggage Key");function Wl(t){return t.getValue(li)||void 0}function fv(){return Wl(Vl.getInstance().active())}function yv(t,e){return t.setValue(li,e)}function gv(t){return t.deleteValue(li)}var Xr="propagation",pv=new dv,mv=function(){function t(){this.createBaggage=Qb,this.getBaggage=Wl,this.getActiveBaggage=fv,this.setBaggage=yv,this.deleteBaggage=gv}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ai(Xr,e,rn.instance())},t.prototype.inject=function(e,n,r){return r===void 0&&(r=sv),this._getGlobalPropagator().inject(e,n,r)},t.prototype.extract=function(e,n,r){return r===void 0&&(r=rv),this._getGlobalPropagator().extract(e,n,r)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){oi(Xr,rn.instance())},t.prototype._getGlobalPropagator=function(){return nn(Xr)||pv},t}(),wv=mv.getInstance();const Ta=["bench","debug","prod"],bv=t=>e=>Ta.indexOf(e)>=Ta.indexOf(t),xs=class Gl{constructor(e,n=bv("debug")){ee(this,"meta",ii.NOOP),ee(this,"tracer"),ee(this,"filter"),this.tracer=e,this.filter=n}child(e){const n=new Gl(this.tracer,this.filter);return n.meta=e,n}debug(e,n){return this.trace(e,"debug",n)}bench(e,n){return this.trace(e,"bench",n)}prod(e,n){return this.trace(e,"prod",n)}trace(e,n,r){return this.meta.noop||!this.filter(n)?r(new Kl(e)):this.tracer.startActiveSpan(e,i=>{const a=new Jl(e,i),o=r(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const n=hv.active();wv.inject(n,e,{set:(r,i,a)=>{r[i]=a}})}};ee(xs,"NOOP",new xs);let Zl=xs;class Jl{constructor(e,n){ee(this,"key"),ee(this,"otel"),this.key=e,this.otel=n}set(e,n){this.otel.setAttribute(e,n)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:As.ERROR}))}}class Kl{constructor(e){ee(this,"key"),this.key=e}set(){}recordError(e){}}const Cs=class Hl{constructor({key:e="",serviceName:n="",logger:r=ql.NOOP,tracer:i=Zl.NOOP,noop:a=!1,__meta:o}){ee(this,"meta"),ee(this,"T"),ee(this,"L"),this.meta=o??new ii(e,e,n,a),this.T=i.child(this.meta),this.L=r.child(this.meta)}child(e){const n=this.meta.child(e);return new Hl({__meta:n,tracer:this.T,logger:this.L})}};ee(Cs,"NOOP",new Cs({noop:!0}));let ci=Cs;const vv=ci.NOOP,Xl=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:ci,LOG_LEVELS:Is,Logger:ql,NOOP:vv,NoopSpan:Kl,Tracer:Zl,_Span:Jl,logLevelKeyFiler:Pb,logThresholdFilter:Db},Symbol.toStringTag,{value:"Module"})),Ov=new Error("request for lock canceled");var Tv=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Sv{constructor(e,n=Ov){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=Ql(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Tv(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),zv(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function zv(t,e){const n=Ql(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function Ql(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var Nv=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class ec{constructor(e){this._semaphore=new Sv(1,e)}acquire(){return Nv(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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 Er{constructor(e,n,r=new Map){P(this,"providers");P(this,"registry");P(this,"sender");P(this,"changedKeys");this.providers=r,this.registry=n,this.changedKeys=[],this.sender=e}propagateState(e,n,r=[]){this.sender.send({key:e,state:n},r)}copyAndMerge(e){const n=new Er(this.sender,this.registry,new Map);return e==null||e.providers.forEach((r,i)=>n.providers.set(i,r)),this.providers.forEach((r,i)=>n.providers.set(i,r)),n.changedKeys=[],n}get changed(){return this.changedKeys.length>0}set(e,n,r=!0){this.providers.set(e,n),r&&this.changedKeys.push(e)}setIfNotHas(e,n){this.providers.has(e)||this.set(e,n)}async create(e){const n=this.registry[e.type];if(n==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const r=new n(e);return await r.internalUpdate(e),r}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const n=this.getOptional(e);if(n==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return n}}class ui{constructor(e){P(this,"type");P(this,"key");P(this,"_ctx");P(this,"_internalState");P(this,"_state");P(this,"_prevState");P(this,"_deleted",!1);P(this,"instrumentation");P(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 J(`[AetherLeaf] - expected subclass to define component schema, but none was found.
67
- Make sure to defne a property 'schema' on the class.`);return this.schema}setState(e){const n=Ms(e,this._state);this._prevState={...this._state},this._state=Ns(this._schema,n,`${this.type}:${this.key}`),this.ctx.propagateState(this.key,n)}get ctx(){if(this._ctx==null)throw new be("context not defined");return this._ctx}get state(){if(this._state==null)throw new be("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:n,ctx:r,state:i}){if(!this.deleted){if(this._ctx=r,e==="state"){this.validatePath(n);const a=Ns(this._schema,i,`${this.type}:${this.key}`);this._state!=null?this.instrumentation.L.debug("updating state",()=>({diff:Ca.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 be(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const n=e[e.length-1];if(e.length>1)throw new be(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(n!==this.key)throw new be(`[Leaf.setState] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`)}}class pn extends ui{constructor(n){super(n);P(this,"_children");this._children=new Map}get children(){return Array.from(this._children.values())}async internalUpdate(n){const{variant:r,path:i}=n;if(r==="context")return this._ctx=n.ctx.copyAndMerge(this._ctx),await this.updateContext({...n,ctx:this.ctx});const[a,o]=this.getRequiredKey(i),c={...n,ctx:this.ctx};return o.length===0?await this.updateThis(a,c):await this.updateChild(o,c)}async updateContext(n){await super.internalUpdate(n);for(const r of this.children)await r.internalUpdate({...n,ctx:this.ctx,variant:"context"})}async updateChild(n,r){const i=n[0],a=this.getChild(i);if(a!=null)return await a.internalUpdate({...r,path:n});if(n.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 r.ctx.create({...r,path:n}))}async updateThis(n,r){const i=r.ctx.copyAndMerge(this._ctx);if(n!==this.key)throw new be(`[Composite.update] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`);if(await super.internalUpdate({...r,ctx:i}),!!i.changed){this.instrumentation.L.debug("context changed",{changedKeys:i.changedKeys});for(const a of this.children)await a.internalUpdate({...r,ctx:this.ctx,variant:"context"})}}async internalDelete(n){const[r,i]=this.getRequiredKey(n);if(i.length===0){if(r!==this.key)throw new Error(`[Composite.delete] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`);const o=this.children;this._children=new Map;for(const c of o)await c.internalDelete([c.key]);await super.internalDelete([this.key])}const a=this.getChild(i[0]);a!=null&&(i.length>1?await a.internalDelete(i):(this._children.delete(a.key),await a.internalDelete(i)))}getRequiredKey(n,r){const[i,...a]=n;if(i==null)throw new Error(`Composite ${this.type}:${this.key} received an empty path${r!=null?` for ${r}`:""}`);return[i,a]}getChild(n){return this._children.get(n)??null}childrenOfType(...n){return this.children.filter(r=>n.includes(r.type))}}const Ev=s.z.object({}),$e=class $e extends pn{constructor({worker:n,registry:r,instrumentation:i=Xl.Instrumentation.NOOP}){const o={ctx:new Er(n,r,new Map),...$e.ZERO_UPDATE,instrumentation:i};super(o);P(this,"wrap");P(this,"schema",$e.schema);P(this,"mu",new ec);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=n,this.wrap.handle(c=>{this.mu.runExclusive(async()=>await this.handle(c))})}async handle(n){if(n.variant==="delete")await this.internalDelete(n.path);else{const r={...n,variant:"state",ctx:this.ctx,instrumentation:this.instrumentation};await this.internalUpdate(r)}}};P($e,"TYPE","root"),P($e,"KEY","root"),P($e,"ZERO_UPDATE",{path:[$e.KEY],type:$e.TYPE,variant:"state",state:{}}),P($e,"schema",Ev);let lr=$e;const tc=t=>new lr(t),Iv=Object.freeze(Object.defineProperty({__proto__:null,Composite:pn,Context:Er,Leaf:ui,Root:lr,render:tc},Symbol.toStringTag,{value:"Module"})),nc="pluto-theming-context",rc=s.z.object({name:s.z.string(),url:s.z.string()}),kv=s.z.object({theme:Xa,fontURLs:s.z.array(rc)}),Kt=class Kt extends pn{constructor(){super(...arguments);P(this,"schema",Kt.z)}async afterUpdate(){this.ctx.set(nc,this.state.theme),await this.loadFonts()}async loadFonts(){await Promise.all(this.state.fontURLs.map(async({name:n,url:r})=>{const i=new FontFace(n,`url(${r})`);await i.load(),self.fonts.add(i)}))}};P(Kt,"TYPE","theming.Provider"),P(Kt,"z",kv);let sn=Kt;const Av=t=>t.get(nc),xv={[sn.TYPE]:sn},sc=["success","error","warning","info","loading","disabled","secondary"],ic=s.z.enum(sc),ac=s.z.object({key:s.z.string(),variant:ic,message:s.z.string(),description:s.z.string().optional(),time:W.z,data:s.z.record(s.z.unknown()).optional()}),oc=s.z.object({statuses:ac.array()}),hi="status.aggregator";class cr extends pn{constructor(){super(...arguments);P(this,"schema",oc)}async afterUpdate(){this.ctx.set(hi,this)}add(n){this.setState(r=>({...r,statuses:[...r.statuses,{time:W.now(),key:Ma.id(),...n}]}))}}P(cr,"TYPE","status.Aggregator");const Cv=t=>{const e=t.get(hi);return e.add.bind(e)},$v=t=>{const e=t.getOptional(hi);return e!=null?e.add.bind(e):()=>{}},jv={[cr.TYPE]:cr};exports.A=ru;exports.Aggregator=cr;exports.B=J;exports.B$1=ci;exports.B$2=vu;exports.Ce=be;exports.ComponentSizeLevels=Ha;exports.Composite=pn;exports.Ct=Hc;exports.E=at;exports.F=Sc;exports.Gg=up;exports.H=Nu;exports.I=x;exports.LEVELS=Ka;exports.Leaf=ui;exports.LevelComponentSizes=Du;exports.Mg=ug;exports.Mutex=ec;exports.N=Dc;exports.Np=Rb;exports.P=ns;exports.Provider=sn;exports.Q=Eu;exports.REGISTRY=xv;exports.REGISTRY$1=jv;exports.Rt=Ma;exports.SYNNAX_DARK=eo;exports.SYNNAX_LIGHT=Qa;exports.SYNNAX_THEMES=Gu;exports.U=Iu;exports.V=Pa;exports.V$1=se;exports.VARIANTS=sc;exports.W=wu;exports._=Ca;exports.aether=Iv;exports.aggregatorStateZ=oc;exports.b=ce;exports.dimensions=Uu;exports.downLevel=$u;exports.executeInitialSetter=on;exports.executeSetter=Ms;exports.fontSpecZ=rc;exports.fontString=Hu;exports.g=R;exports.g$1=Xl;exports.isSetter=Rs;exports.k=$;exports.l=hu;exports.levelZ=xu;exports.lg=Ll;exports.m=W;exports.n=Qr;exports.o=zc;exports.o$1=su;exports.op=Ym;exports.prettyParse=Ns;exports.r=Nc;exports.re=Oe;exports.render=tc;exports.specZ=Fe;exports.specZ$1=ac;exports.state=Au;exports.themeZ=Xa;exports.ug=_l;exports.upLevel=Ru;exports.use=Av;exports.useAggregate=Cv;exports.useOptionalAggregate=$v;exports.usePassthrough=Za;exports.usePurePassthrough=Ja;exports.variantZ=ic;exports.w=_a;exports.w$1=pc;exports.weightZ=Bu;exports.x=Ht;exports.xt=Fc;exports.y=Z;