@synnaxlabs/pluto 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Animated-ByIJT_wA.js → Animated-CBm9-vEt.js} +3 -3
- package/dist/{Animated-BOjwPkTJ.cjs → Animated-Cv0kRBvj.cjs} +1 -1
- package/dist/{Item-Bamd13Tl.cjs → Item-D4eTqW7p.cjs} +1 -1
- package/dist/{Item-CQ2ZuDfi.js → Item-DfHOrsI4.js} +9 -9
- package/dist/{LinePlot-Ci-61YDW.js → LinePlot-BLovx_K1.js} +1779 -1706
- package/dist/LinePlot-BXBKDBXS.cjs +56 -0
- package/dist/{Link-Cm6yn4zC.cjs → Link-CcELhLK5.cjs} +1 -1
- package/dist/{Link-ZlOdu4jA.js → Link-DsUveQ8_.js} +2 -2
- package/dist/Pack-SDIuOEWr.cjs +1 -0
- package/dist/Pack-meMPpnLE.js +143 -0
- package/dist/Toggle--8qqNnzb.cjs +163 -0
- package/dist/{Toggle-DlYB4nmh.js → Toggle-Bkpw4raJ.js} +15326 -15675
- package/dist/Video-D9_mAnaf.cjs +1 -0
- package/dist/Video-M2UhBzQi.js +9 -0
- package/dist/{aggregator-CWsCIyed.js → aggregator-BpyoaCoW.js} +2941 -2922
- package/dist/aggregator-By11htYo.cjs +77 -0
- package/dist/align.cjs +1 -1
- package/dist/align.js +1 -1
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/{css-Bo-hsQHb.cjs → css-CRd0zXr-.cjs} +1 -1
- package/dist/{css-Csw1Dn4s.js → css-CxwKC6TD.js} +216 -216
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -2
- package/dist/dropdown.cjs +1 -1
- package/dist/dropdown.js +1 -1
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +58 -56
- package/dist/{external-DsJYjdNk.cjs → external---lrKeGh.cjs} +1 -1
- package/dist/{external-CyPQsB1T.cjs → external--jF6DCow.cjs} +1 -1
- package/dist/{external-DXD4PtTK.js → external-BDI5gGZT.js} +2 -2
- package/dist/external-BDxOWeCJ.js +34 -0
- package/dist/{external-2PznkZYs.js → external-BOqGZoJO.js} +113 -112
- package/dist/external-BXEbAbxf.cjs +1 -0
- package/dist/external-BdhgaSFj.cjs +1 -0
- package/dist/external-BlB1LKU5.cjs +1 -0
- package/dist/external-ByzAGKGm.cjs +1 -0
- package/dist/{external-BTnFzhMM.js → external-BzzIJ4wP.js} +4 -5
- package/dist/external-CDa3lybi.js +277 -0
- package/dist/{external-4ikhWnyq.js → external-CEAUuDRU.js} +2 -2
- package/dist/{external-vYsKqfFS.js → external-Cc7R9gIf.js} +186 -187
- package/dist/{external-BpeQ9rNJ.js → external-CqOmm0mk.js} +88 -88
- package/dist/{external-DIwKYTmY.js → external-CsLjI7EJ.js} +2 -2
- package/dist/{external-C_th4MW9.cjs → external-DN8Ec8n8.cjs} +1 -1
- package/dist/{external-CyYaJ5TW.js → external-DSHJn336.js} +5 -5
- package/dist/{external-vMTeF1dc.cjs → external-DaTbvfth.cjs} +1 -1
- package/dist/external-Dqh2Lbnl.cjs +1 -0
- package/dist/{external-VEFOprRU.cjs → external-Dvj3Y4C_.cjs} +1 -1
- package/dist/external-NDebmx0l.js +123 -0
- package/dist/external-biLn9KfP.cjs +1 -0
- package/dist/{external-rGv5AzBK.js → external-hZWRSBEb.js} +14 -14
- package/dist/external-mT9bNf0F.cjs +1 -0
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.js +6746 -6604
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/{jsx-runtime-Dx-03ztt.js → jsx-runtime-Bdg6XQ1m.js} +134 -134
- package/dist/jsx-runtime-D8EVjfnb.cjs +31 -0
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/menu.cjs +1 -1
- package/dist/menu.js +1 -1
- package/dist/pluto.css +1 -1
- package/dist/src/aether/aether/index.d.ts +1 -2
- package/dist/src/aether/aether/index.d.ts.map +1 -1
- package/dist/src/aether/main.d.ts +18 -19
- package/dist/src/aether/main.d.ts.map +1 -1
- package/dist/src/alamos/Provider.d.ts +2 -4
- package/dist/src/alamos/Provider.d.ts.map +1 -1
- package/dist/src/align/Center.d.ts +2 -3
- package/dist/src/align/Center.d.ts.map +1 -1
- package/dist/src/align/Pack.d.ts +1 -2
- package/dist/src/align/Pack.d.ts.map +1 -1
- package/dist/src/align/Space.d.ts +1 -1
- package/dist/src/align/Space.d.ts.map +1 -1
- package/dist/src/breadcrumb/Breadcrumb.d.ts.map +1 -1
- package/dist/src/button/Button.d.ts +4 -4
- package/dist/src/button/Button.d.ts.map +1 -1
- package/dist/src/button/Icon.d.ts +2 -2
- package/dist/src/button/Icon.d.ts.map +1 -1
- package/dist/src/button/Toggle.d.ts +3 -3
- package/dist/src/button/Toggle.d.ts.map +1 -1
- package/dist/src/channel/LinePlot.d.ts.map +1 -1
- package/dist/src/channel/Select.d.ts +2 -0
- package/dist/src/channel/Select.d.ts.map +1 -1
- package/dist/src/color/core/external.d.ts +1 -0
- package/dist/src/color/core/external.d.ts.map +1 -1
- package/dist/src/color/core/transformColorsToHex.d.ts +6 -0
- package/dist/src/color/core/transformColorsToHex.d.ts.map +1 -0
- package/dist/src/color/external.d.ts +1 -0
- package/dist/src/color/external.d.ts.map +1 -1
- package/dist/src/divider/index.d.ts +1 -2
- package/dist/src/divider/index.d.ts.map +1 -1
- package/dist/src/dropdown/index.d.ts +1 -2
- package/dist/src/dropdown/index.d.ts.map +1 -1
- package/dist/src/form/Field.d.ts +6 -6
- package/dist/src/form/Field.d.ts.map +1 -1
- package/dist/src/form/synced.d.ts.map +1 -1
- package/dist/src/generic/Generic.d.ts +1 -1
- package/dist/src/generic/Generic.d.ts.map +1 -1
- package/dist/src/hardware/device/Select.d.ts.map +1 -1
- package/dist/src/haul/Haul.d.ts +3 -3
- package/dist/src/haul/Haul.d.ts.map +1 -1
- package/dist/src/hooks/ref.d.ts +5 -5
- package/dist/src/hooks/ref.d.ts.map +1 -1
- package/dist/src/hooks/useCursorDrag/useVirtualCursorDragWebKit.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/input/Date.d.ts +2 -1
- package/dist/src/input/Date.d.ts.map +1 -1
- package/dist/src/input/Numeric.d.ts +2 -1
- package/dist/src/input/Numeric.d.ts.map +1 -1
- package/dist/src/input/Switch.d.ts +2 -1
- package/dist/src/input/Switch.d.ts.map +1 -1
- package/dist/src/input/Text.d.ts +2 -1
- package/dist/src/input/Text.d.ts.map +1 -1
- package/dist/src/input/TextArea.d.ts +3 -3
- package/dist/src/input/TextArea.d.ts.map +1 -1
- package/dist/src/input/Time.d.ts +1 -1
- package/dist/src/input/Time.d.ts.map +1 -1
- package/dist/src/input/types.d.ts +2 -2
- package/dist/src/input/types.d.ts.map +1 -1
- package/dist/src/label/Select.d.ts.map +1 -1
- package/dist/src/list/Hover.d.ts.map +1 -1
- package/dist/src/list/Selector.d.ts.map +1 -1
- package/dist/src/menu/ContextMenu.d.ts +2 -2
- package/dist/src/menu/ContextMenu.d.ts.map +1 -1
- package/dist/src/mosaic/Mosaic.d.ts +2 -5
- package/dist/src/mosaic/Mosaic.d.ts.map +1 -1
- package/dist/src/nav/Drawer.d.ts +1 -3
- package/dist/src/nav/Drawer.d.ts.map +1 -1
- package/dist/src/os/Controls/index.d.ts +2 -3
- package/dist/src/os/Controls/index.d.ts.map +1 -1
- package/dist/src/ranger/SelectLabel.d.ts.map +1 -1
- package/dist/src/resize/Core.d.ts +2 -2
- package/dist/src/resize/Core.d.ts.map +1 -1
- package/dist/src/resize/Multiple.d.ts +1 -1
- package/dist/src/resize/Multiple.d.ts.map +1 -1
- package/dist/src/select/Alignment.d.ts.map +1 -1
- package/dist/src/select/ComponentSize.d.ts +1 -1
- package/dist/src/select/ComponentSize.d.ts.map +1 -1
- package/dist/src/select/Multiple.d.ts +13 -12
- package/dist/src/select/Multiple.d.ts.map +1 -1
- package/dist/src/select/Select.spec.d.ts.map +1 -1
- package/dist/src/select/Single.d.ts +2 -2
- package/dist/src/select/Single.d.ts.map +1 -1
- package/dist/src/select/external.d.ts +1 -1
- package/dist/src/select/external.d.ts.map +1 -1
- package/dist/src/status/Aggregator.d.ts +6 -4
- package/dist/src/status/Aggregator.d.ts.map +1 -1
- package/dist/src/synnax/Provider.d.ts +2 -4
- package/dist/src/synnax/Provider.d.ts.map +1 -1
- package/dist/src/table/Table.d.ts +4 -6
- package/dist/src/table/Table.d.ts.map +1 -1
- package/dist/src/table/cells/Cells.d.ts +4 -4
- package/dist/src/tabs/Selector.d.ts.map +1 -1
- package/dist/src/telem/Provider.d.ts +2 -4
- package/dist/src/telem/Provider.d.ts.map +1 -1
- package/dist/src/telem/aether/convertSeries.d.ts +20 -6
- package/dist/src/telem/aether/convertSeries.d.ts.map +1 -1
- package/dist/src/telem/aether/pipeline.d.ts +16 -16
- package/dist/src/telem/aether/remote.d.ts.map +1 -1
- package/dist/src/telem/aether/telem.d.ts +30 -30
- package/dist/src/telem/client/cache/dynamic.d.ts.map +1 -1
- package/dist/src/telem/client/cache/index.d.ts +1 -2
- package/dist/src/telem/client/cache/index.d.ts.map +1 -1
- package/dist/src/telem/client/cache/static.d.ts.map +1 -1
- package/dist/src/telem/control/Chip.d.ts +2 -3
- package/dist/src/telem/control/Chip.d.ts.map +1 -1
- package/dist/src/telem/control/Controller.d.ts +2 -4
- package/dist/src/telem/control/Controller.d.ts.map +1 -1
- package/dist/src/telem/control/Indicator.d.ts +2 -4
- package/dist/src/telem/control/Indicator.d.ts.map +1 -1
- package/dist/src/telem/control/Legend.d.ts +2 -3
- package/dist/src/telem/control/Legend.d.ts.map +1 -1
- package/dist/src/telem/control/StateProvider.d.ts +2 -4
- package/dist/src/telem/control/StateProvider.d.ts.map +1 -1
- package/dist/src/telem/control/aether/chip.d.ts +16 -16
- package/dist/src/telem/control/aether/controller.d.ts.map +1 -1
- package/dist/src/telem/control/aether/indicator.d.ts +16 -16
- package/dist/src/telem/control/aether/state.d.ts.map +1 -1
- package/dist/src/text/DateTime.d.ts +3 -6
- package/dist/src/text/DateTime.d.ts.map +1 -1
- package/dist/src/text/Editable.d.ts.map +1 -1
- package/dist/src/text/Link.d.ts +3 -5
- package/dist/src/text/Link.d.ts.map +1 -1
- package/dist/src/text/Text.d.ts +1 -1
- package/dist/src/text/Text.d.ts.map +1 -1
- package/dist/src/theming/Provider.d.ts +1 -3
- package/dist/src/theming/Provider.d.ts.map +1 -1
- package/dist/src/theming/aether/index.d.ts +1 -2
- package/dist/src/theming/aether/index.d.ts.map +1 -1
- package/dist/src/theming/aether/provider.d.ts +315 -315
- package/dist/src/theming/core/theme.d.ts +116 -116
- package/dist/src/theming/core/theme.d.ts.map +1 -1
- package/dist/src/tooltip/wrap.d.ts +2 -2
- package/dist/src/tooltip/wrap.d.ts.map +1 -1
- package/dist/src/tree/Tree.d.ts +1 -1
- package/dist/src/tree/Tree.d.ts.map +1 -1
- package/dist/src/tree/core.d.ts.map +1 -1
- package/dist/src/triggers/Provider.d.ts.map +1 -1
- package/dist/src/triggers/hooks.d.ts +2 -2
- package/dist/src/triggers/hooks.d.ts.map +1 -1
- package/dist/src/util/removeProps.d.ts.map +1 -1
- package/dist/src/video/Video.d.ts +2 -2
- package/dist/src/video/Video.d.ts.map +1 -1
- package/dist/src/viewport/Mask.d.ts +2 -1
- package/dist/src/viewport/Mask.d.ts.map +1 -1
- package/dist/src/viewport/use.d.ts +3 -3
- package/dist/src/viewport/use.d.ts.map +1 -1
- package/dist/src/vis/button/aether/button.d.ts +8 -8
- package/dist/src/vis/canvas/Canvas.d.ts +2 -4
- package/dist/src/vis/canvas/Canvas.d.ts.map +1 -1
- package/dist/src/vis/diagram/Diagram.d.ts +2 -1
- package/dist/src/vis/diagram/Diagram.d.ts.map +1 -1
- package/dist/src/vis/diagram/aether/Diagram.d.ts.map +1 -1
- package/dist/src/vis/diagram/edge/paths.d.ts.map +1 -1
- package/dist/src/vis/eraser/use.d.ts +5 -6
- package/dist/src/vis/eraser/use.d.ts.map +1 -1
- package/dist/src/vis/light/aether/light.d.ts +8 -8
- package/dist/src/vis/line/Line.d.ts +4 -4
- package/dist/src/vis/line/Line.d.ts.map +1 -1
- package/dist/src/vis/line/aether/line.d.ts +24 -16
- package/dist/src/vis/line/aether/line.d.ts.map +1 -1
- package/dist/src/vis/lineplot/Axis.d.ts +2 -1
- package/dist/src/vis/lineplot/Axis.d.ts.map +1 -1
- package/dist/src/vis/lineplot/Legend.d.ts +1 -1
- package/dist/src/vis/lineplot/Legend.d.ts.map +1 -1
- package/dist/src/vis/lineplot/Line.d.ts +4 -4
- package/dist/src/vis/lineplot/Line.d.ts.map +1 -1
- package/dist/src/vis/lineplot/LinePlot.d.ts +4 -5
- package/dist/src/vis/lineplot/LinePlot.d.ts.map +1 -1
- package/dist/src/vis/lineplot/Title.d.ts.map +1 -1
- package/dist/src/vis/lineplot/Viewport.d.ts +2 -2
- package/dist/src/vis/lineplot/Viewport.d.ts.map +1 -1
- package/dist/src/vis/lineplot/aether/LinePlot.d.ts.map +1 -1
- package/dist/src/vis/lineplot/aether/axis.d.ts.map +1 -1
- package/dist/src/vis/lineplot/aether/index.d.ts +1 -2
- package/dist/src/vis/lineplot/aether/index.d.ts.map +1 -1
- package/dist/src/vis/lineplot/range/Annotation.d.ts +3 -4
- package/dist/src/vis/lineplot/range/Annotation.d.ts.map +1 -1
- package/dist/src/vis/lineplot/range/Provider.d.ts +4 -4
- package/dist/src/vis/lineplot/range/Provider.d.ts.map +1 -1
- package/dist/src/vis/lineplot/range/aether/annotation.d.ts.map +1 -1
- package/dist/src/vis/lineplot/tooltip/Tooltip.d.ts +4 -4
- package/dist/src/vis/lineplot/tooltip/Tooltip.d.ts.map +1 -1
- package/dist/src/vis/log/Log.d.ts +3 -4
- package/dist/src/vis/log/Log.d.ts.map +1 -1
- package/dist/src/vis/log/aether/Log.d.ts +12 -12
- package/dist/src/vis/measure/Measure.d.ts +4 -4
- package/dist/src/vis/measure/Measure.d.ts.map +1 -1
- package/dist/src/vis/measure/aether/measure.d.ts.map +1 -1
- package/dist/src/vis/rule/Rule.d.ts +4 -4
- package/dist/src/vis/rule/Rule.d.ts.map +1 -1
- package/dist/src/vis/rule/aether/aether.d.ts +1 -1
- package/dist/src/vis/rule/aether/aether.d.ts.map +1 -1
- package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
- package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
- package/dist/src/vis/setpoint/aether/setpoint.d.ts +16 -16
- package/dist/src/vis/toggle/aether/toggle.d.ts +16 -16
- package/dist/src/vis/value/aether/value.d.ts +24 -24
- package/dist/src/vis/value/use.d.ts +8 -8
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/text.cjs +1 -1
- package/dist/text.js +2 -2
- package/dist/theming.cjs +1 -1
- package/dist/theming.js +2 -2
- package/dist/transformColorsToHex-1p-bBtDw.cjs +1 -0
- package/dist/transformColorsToHex-CjnZ3Lo3.js +14 -0
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +1 -1
- package/dist/triggers.cjs +1 -1
- package/dist/triggers.js +1 -1
- package/dist/{units-CJ76Jzvw.js → units-Bz3KAVba.js} +1 -1
- package/dist/{units-CXFC0OLO.cjs → units-Cq6pBqSd.cjs} +1 -1
- package/dist/video.cjs +1 -1
- package/dist/video.js +1 -1
- package/package.json +13 -15
- package/dist/LinePlot-D4V1ltNT.cjs +0 -24
- package/dist/Pack-CyaEXvnu.cjs +0 -1
- package/dist/Pack-DNCFnyuR.js +0 -140
- package/dist/Toggle-vgmhy8wZ.cjs +0 -163
- package/dist/Video-g30B90s-.cjs +0 -1
- package/dist/Video-jaT7Y97L.js +0 -14
- package/dist/aggregator-DX8ts24k.cjs +0 -77
- package/dist/external-BS9Bfsj3.cjs +0 -1
- package/dist/external-Bt_kX5KM.cjs +0 -1
- package/dist/external-CEcxrva2.js +0 -254
- package/dist/external-CMEDU76u.cjs +0 -1
- package/dist/external-CWincA61.cjs +0 -1
- package/dist/external-Dn4tpDVi.js +0 -32
- package/dist/external-Dtr4ZxR6.cjs +0 -1
- package/dist/external-IztUjYjX.cjs +0 -1
- package/dist/external-WZW4OBZx.js +0 -91
- package/dist/external-kAduhcvp.cjs +0 -1
- package/dist/jsx-runtime-DGh1k5sI.cjs +0 -31
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";var Du=Object.defineProperty;var Bu=(r,e,t)=>e in r?Du(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var T=(r,e,t)=>Bu(r,typeof e!="symbol"?e+"":e,t);const i=require("zod"),p=require("./css-CRd0zXr-.cjs"),Gn=require("react"),Vt=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var ju=Object.defineProperty,Pu=(r,e,t)=>e in r?ju(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Wt=(r,e,t)=>Pu(r,typeof e!="symbol"?e+"":e,t);let Uu=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,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const s=JSON.parse(e),n=p.C(s);return t!=null?t.parse(n):n}encodeString(e){const t=p.k(e);return JSON.stringify(t,(s,n)=>ArrayBuffer.isView(n)?Array.from(n):Vt(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},Lu=class{constructor(){Wt(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t).buffer}decode(e,t){const s=new TextDecoder().decode(e);return this.decodeString(s,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Vt(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),s=[t.join(",")];return e.forEach(n=>{const a=t.map(o=>JSON.stringify(n[o]??""));s.push(a.join(","))}),s.join(`
|
|
2
|
+
`)}decodeString(e,t){const[s,...n]=e.trim().split(`
|
|
3
|
+
`).map(u=>u.trim());if(s.length===0)return t!=null?t.parse({}):{};const a=s.split(",").map(u=>u.trim()),o={};return a.forEach(u=>{o[u]=[]}),n.forEach(u=>{const l=u.split(",").map(d=>d.trim());a.forEach((d,f)=>{const h=this.parseValue(l[f]);h!=null&&o[d].push(h)})}),t!=null?t.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}},_u=class{constructor(){Wt(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const s=new TextDecoder().decode(e);return t!=null?t.parse(s):s}};const Nr=new Uu;new Lu;new _u;const fn=r=>[...new Set(r)],qu=(r,e,t=!0)=>{const s=new Map;return r.forEach(n=>{const a=e(n);if(s.has(a)){if(t)return;s.delete(a)}s.set(a,n)}),Array.from(s.values())},Yu=Object.freeze(Object.defineProperty({__proto__:null,by:qu,unique:fn},Symbol.toStringTag,{value:"Module"})),qa=r=>r!=null&&typeof r=="object"&&"toString"in r,Fu=r=>{if(qa(r))return(r==null?void 0:r.toString().length)===0;switch(typeof r){case"string":return r.length===0;case"number":return r===0;case"bigint":return r===0n;case"boolean":return!r;case"undefined":return!0;case"object":return r===null}},ms=(r,e=!1)=>{const t=qa(r)?"stringer":typeof r;let s;switch(t){case"string":s=(n,a)=>n.localeCompare(a);break;case"stringer":s=(n,a)=>n.toString().localeCompare(a.toString());break;case"number":s=(n,a)=>Number(n)-Number(a);break;case"bigint":s=(n,a)=>BigInt(n)-BigInt(a)>0n?1:-1;break;case"boolean":s=(n,a)=>Number(n)-Number(a);break;case"undefined":s=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Fa(s):s},Gu=(r,e,t)=>{const s=ms(e[r],t);return(n,a)=>s(n[r],a[r])},Vu=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,s)=>t===e[s])?0:-1,Ya=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=ms(r[0]),s=[...r].sort(t),n=[...e].sort(t);return s.every((a,o)=>a===n[o])?0:-1},Wu=(r,e)=>{const t=fn(r),s=fn(e);return Ya(t,s)},Zu=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Fa=r=>(e,t)=>r(t,e),pt=0,Er=-1,Ir=1,Ga=r=>r<pt,Va=r=>r>pt,Ju=r=>r>=pt,Wa=r=>r===pt,Ku=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,s=r.replace(/[\s_.-]+/g,"").match(t),n=e.replace(/[\s_.-]+/g,"").match(t);if(!s||!n)return 0;for(let a=0;a<Math.min(s.length,n.length);a++){const o=s[a],u=n[a];if(isNaN(Number(o))&&isNaN(Number(u))){const l=o.localeCompare(u);if(l!==0)return l}else if(!isNaN(Number(o))&&!isNaN(Number(u))){const l=Number(o)-Number(u);if(l!==0)return l}else return isNaN(Number(o))?-1:1}return s.length-n.length},Hu=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:pt,GREATER_THAN:Ir,LESS_THAN:Er,isEqualTo:Wa,isGreaterThan:Va,isGreaterThanEqual:Ju,isLessThan:Ga,newF:ms,newFieldF:Gu,order:Zu,primitiveArrays:Vu,reverseF:Fa,stringsWithNumbers:Ku,uniqueUnorderedPrimitiveArrays:Wu,unorderedPrimitiveArrays:Ya},Symbol.toStringTag,{value:"Module"})),Za=(r,e,t=".")=>{const s=r.split(t);return s.map((n,a)=>{const o=e(n,a,s);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(n=>n!=null).join(t)},Vn=(r,e,t={optional:!1,separator:"."})=>{t.separator??(t.separator=".");const{optional:s,getter:n=(u,l)=>u[l]}=t,a=e.split(t.separator);if(a.length===1&&a[0]==="")return r;let o=r;for(const u of a){const l=n(o,u);if(l==null){if(s)return null;throw new Error(`Path ${e} does not exist. ${u} is null`)}o=l}return o},Xu=(r,e,t)=>{const s=e.split(".");let n=r;for(let a=0;a<s.length-1;a++){const o=s[a];n[o]??(n[o]={}),n=n[o]}try{n[s[s.length-1]]=t}catch(a){throw console.error("failed to set value",t,"at path",e,"on object",r),a}},Qu=(r,e)=>{const t=e.split(".");let s=r;for(let n=0;n<t.length-1;n++){const a=t[n];if(s[a]==null)return;s=s[a]}if(Array.isArray(s)){const n=parseInt(t[t.length-1]);if(isNaN(n))return;s.splice(n,1);return}delete s[t[t.length-1]]},ec=(r,e)=>{const t=r.split(".");return e<0?t[t.length+e]:t[e]},tc=(r,e)=>{try{return Vn(r,e),!0}catch{return!1}},rc=(r,e)=>{if(e.length===0)return!0;const t=r.split("."),s=e.split(".");if(s.length>t.length)return!1;for(let n=0;n<s.length;n++){const a=t[n],o=s[n];if(o!=="*"&&a!==o)return!1}return!0},Ja=r=>Za(r,(e,t,s)=>{const n=t===s.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(s[t+1]));return a&&(e="element"),n||o?e:[e,"shape"]}),Si=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},sc=(r,e,t)=>Vn(Si(r,"shape"),Ja(e),{...t,getter:Si}),Ka=i.z.bigint().or(i.z.string().transform(BigInt)),nc=Object.freeze(Object.defineProperty({__proto__:null,bigInt:Ka,getFieldSchema:sc,getFieldSchemaPath:Ja},Symbol.toStringTag,{value:"Module"}));var ic=Object.defineProperty,ac=(r,e,t)=>e in r?ic(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,g=(r,e,t)=>ac(r,typeof e!="symbol"?e+"":e,t);let oc=(r,e=21)=>(t=e)=>{let s="",n=t|0;for(;n--;)s+=r[Math.random()*r.length|0];return s};const lc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ha=oc(lc,11),Xa=Object.freeze(Object.defineProperty({__proto__:null,id:Ha},Symbol.toStringTag,{value:"Module"})),uc=i.z.enum(["static","dynamic"]),Qa=(r,e)=>{const t=new V(e);if(![Z.DAY,Z.HOUR,Z.MINUTE,Z.SECOND,Z.MILLISECOND,Z.MICROSECOND,Z.NANOSECOND].some(n=>n.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const s=r.valueOf()%t.valueOf();return r instanceof V?new V(s):new Z(s)},L=class z{constructor(e,t="UTC"){if(g(this,"value"),g(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,t).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let s=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(s=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())+s}}static parseDate([e=1970,t=1,s=1]){const n=new Date(e,t-1,s,0,0,0,0);return new z(BigInt(n.getTime())*z.MILLISECOND.valueOf()).truncate(z.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[s,n,a]=e.split(":");let o="00",u="00";a!=null&&([o,u]=a.split("."));let l=z.hours(parseInt(s??"00")).add(z.minutes(parseInt(n??"00"))).add(z.seconds(parseInt(o??"00"))).add(z.milliseconds(parseInt(u??"00")));return t==="local"&&(l=l.add(z.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,t);const s=new Date(e);return e.includes(":")||s.setUTCHours(0,0,0,0),new z(BigInt(s.getTime())*z.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const s=this.toISOString(t);return e?s.slice(11,23):s.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),s=e.toLocaleString("default",{day:"numeric"});return`${t} ${s}`}static get utcOffset(){return new Z(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 ot(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()))}get hours(){return Number(this.valueOf())/Number(Z.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(Z.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(Z.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(Z.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new z(t)}get month(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setMonth(e),new z(t)}get day(){return this.date().getDate()}setDay(e){const t=this.date();return t.setDate(e),new z(t)}get hour(){return this.date().getHours()}setHour(e){const t=this.date();return t.setHours(e),new z(t)}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setMinutes(e),new z(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setSeconds(e),new z(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new z(t)}toString(){return this.date().toISOString()}remainder(e){return Qa(this,e)}get isToday(){return this.truncate(Z.DAY).equals(z.now().truncate(Z.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let t=z.MIN;for(const s of e){const n=new z(s);n.after(t)&&(t=n)}return t}static min(...e){let t=z.MAX;for(const s of e){const n=new z(s);n.before(t)&&(t=n)}return t}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)}};g(L,"NANOSECOND",L.nanoseconds(1)),g(L,"MICROSECOND",L.microseconds(1)),g(L,"MILLISECOND",L.milliseconds(1)),g(L,"SECOND",L.seconds(1)),g(L,"MINUTE",L.minutes(1)),g(L,"HOUR",L.hours(1)),g(L,"DAY",L.days(1)),g(L,"MAX",new L((1n<<63n)-1n)),g(L,"MIN",new L(0)),g(L,"ZERO",new L(0)),g(L,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new L(r.value)),i.z.string().transform(r=>new L(BigInt(r))),i.z.instanceof(Number).transform(r=>new L(r)),i.z.number().transform(r=>new L(r)),i.z.instanceof(L)]));let V=L;const _=class A{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 A?e:e instanceof ns?e.period:e instanceof V?new A(e):["number","bigint"].includes(typeof e)?A.seconds(e):new A(e)}static fromMilliseconds(e){return e instanceof A?e:e instanceof ns?e.period:e instanceof V?new A(e):["number","bigint"].includes(typeof e)?A.milliseconds(e):new A(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new A(e).valueOf()}greaterThan(e){return this.valueOf()>new A(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new A(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new A(e).valueOf()}remainder(e){return Qa(this,e)}truncate(e){return new A(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(A.DAY),t=this.truncate(A.HOUR),s=this.truncate(A.MINUTE),n=this.truncate(A.SECOND),a=this.truncate(A.MILLISECOND),o=this.truncate(A.MICROSECOND),u=this.truncate(A.NANOSECOND),l=e,d=t.sub(e),f=s.sub(t),h=n.sub(s),I=a.sub(n),D=o.sub(a),ue=u.sub(o);let j="";return l.isZero||(j+=`${l.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),I.isZero||(j+=`${I.milliseconds}ms `),D.isZero||(j+=`${D.microseconds}µs `),ue.isZero||(j+=`${ue.nanoseconds}ns`),j.trim()}mult(e){return new A(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(A.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(A.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new A(e).valueOf()}add(e){return new A(this.valueOf()+new A(e).valueOf())}sub(e){return new A(this.valueOf()-new A(e).valueOf())}static nanoseconds(e=1){return new A(e)}static microseconds(e=1){return A.nanoseconds(p.M(e,1e3))}static milliseconds(e=1){return A.microseconds(p.M(e,1e3))}static seconds(e=1){return A.milliseconds(p.M(e,1e3))}static minutes(e=1){return A.seconds(p.M(e,60))}static hours(e){return A.minutes(p.M(e,60))}static days(e){return A.hours(p.M(e,24))}};g(_,"NANOSECOND",_.nanoseconds(1)),g(_,"MICROSECOND",_.microseconds(1)),g(_,"MILLISECOND",_.milliseconds(1)),g(_,"SECOND",_.seconds(1)),g(_,"MINUTE",_.minutes(1)),g(_,"HOUR",_.hours(1)),g(_,"DAY",_.days(1)),g(_,"MAX",new _((1n<<63n)-1n)),g(_,"MIN",new _(0)),g(_,"ZERO",new _(0)),g(_,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new _(r.value)),i.z.string().transform(r=>new _(BigInt(r))),i.z.instanceof(Number).transform(r=>new _(r)),i.z.number().transform(r=>new _(r)),i.z.instanceof(_)]));let Z=_;const Et=class xr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new xr(e).valueOf()}get period(){return Z.seconds(1/this.valueOf())}sampleCount(e){return new Z(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new fe(t).valueOf()}span(e){return Z.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new xr(e)}static khz(e){return xr.hz(e*1e3)}};g(Et,"z",i.z.union([i.z.number().transform(r=>new Et(r)),i.z.instanceof(Number).transform(r=>new Et(r)),i.z.instanceof(Et)]));let ns=Et;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 Xt(e*this.valueOf())}};g(ne,"UNKNOWN",new ne(0)),g(ne,"BIT128",new ne(16)),g(ne,"BIT64",new ne(8)),g(ne,"BIT32",new ne(4)),g(ne,"BIT16",new ne(2)),g(ne,"BIT8",new ne(1)),g(ne,"z",i.z.union([i.z.number().transform(r=>new ne(r)),i.z.instanceof(Number).transform(r=>new ne(r)),i.z.instanceof(ne)]));let fe=ne;const Ie=class Ar{constructor(e,t){g(this,"start"),g(this,"end"),typeof e=="object"&&"start"in e?(this.start=new V(e.start),this.end=new V(e.end)):(this.start=new V(e),this.end=new V(t))}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 Ar(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,t=Z.ZERO){e=e.makeValid();const s=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(s.start)||s.end.equals(e.start))return!1;const n=V.max(s.start,e.start),a=V.min(s.end,e.end);return a.before(n)?!1:new Z(a.sub(n)).greaterThanOrEqual(t)}roughlyEquals(e,t){let s=this.start.sub(e.start).valueOf(),n=this.end.sub(e.end).valueOf();return s<0&&(s=-s),n<0&&(n=-n),s<=t.valueOf()&&n<=t.valueOf()}contains(e){return e instanceof Ar?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new Ar(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}};g(Ie,"MAX",new Ie(V.MIN,V.MAX)),g(Ie,"MIN",new Ie(V.MAX,V.MIN)),g(Ie,"ZERO",new Ie(V.ZERO,V.ZERO)),g(Ie,"z",i.z.union([i.z.object({start:V.z,end:V.z}).transform(r=>new Ie(r.start,r.end)),i.z.instanceof(Ie)]));let ot=Ie;const m=class K extends String{constructor(e){if(e instanceof K||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=K.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(K.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=K.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(K.JSON)||this.equals(K.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(K.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=K.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(K.UINT8)||this.equals(K.UINT16)||this.equals(K.UINT32)||this.equals(K.UINT64)}get isSigned(){return this.equals(K.INT8)||this.equals(K.INT16)||this.equals(K.INT32)||this.equals(K.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(K.INT32)&&e.equals(K.FLOAT64)||this.equals(K.INT8)&&e.equals(K.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!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 K.BIG_INT_TYPES.some(e=>e.equals(this))}};g(m,"UNKNOWN",new m("unknown")),g(m,"FLOAT64",new m("float64")),g(m,"FLOAT32",new m("float32")),g(m,"INT64",new m("int64")),g(m,"INT32",new m("int32")),g(m,"INT16",new m("int16")),g(m,"INT8",new m("int8")),g(m,"UINT64",new m("uint64")),g(m,"UINT32",new m("uint32")),g(m,"UINT16",new m("uint16")),g(m,"UINT8",new m("uint8")),g(m,"BOOLEAN",m.UINT8),g(m,"TIMESTAMP",new m("timestamp")),g(m,"UUID",new m("uuid")),g(m,"STRING",new m("string")),g(m,"JSON",new m("json")),g(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]])),g(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]])),g(m,"DENSITIES",new Map([[m.UINT8.toString(),fe.BIT8],[m.UINT16.toString(),fe.BIT16],[m.UINT32.toString(),fe.BIT32],[m.UINT64.toString(),fe.BIT64],[m.FLOAT32.toString(),fe.BIT32],[m.FLOAT64.toString(),fe.BIT64],[m.INT8.toString(),fe.BIT8],[m.INT16.toString(),fe.BIT16],[m.INT32.toString(),fe.BIT32],[m.INT64.toString(),fe.BIT64],[m.TIMESTAMP.toString(),fe.BIT64],[m.STRING.toString(),fe.UNKNOWN],[m.JSON.toString(),fe.UNKNOWN],[m.UUID.toString(),fe.BIT128]])),g(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]),g(m,"BIG_INT_TYPES",[m.INT64,m.UINT64,m.TIMESTAMP]),g(m,"z",i.z.union([i.z.string().transform(r=>new m(r)),i.z.instanceof(m)]));let M=m;const ce=class ee extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return ee.bytes(this.valueOf()+e.valueOf())}sub(e){return ee.bytes(this.valueOf()-e.valueOf())}truncate(e){return new ee(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return ee.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/ee.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/ee.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/ee.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/ee.TERABYTE.valueOf()}toString(){const e=this.truncate(ee.TERABYTE),t=this.truncate(ee.GIGABYTE),s=this.truncate(ee.MEGABYTE),n=this.truncate(ee.KILOBYTE),a=this.truncate(ee.BYTE),o=e,u=t.sub(e),l=s.sub(t),d=n.sub(s),f=a.sub(n);let h="";return o.isZero||(h+=`${o.terabytes}TB `),u.isZero||(h+=`${u.gigabytes}GB `),l.isZero||(h+=`${l.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new ee(e)}static kilobytes(e=1){return ee.bytes(e.valueOf()*1e3)}static megabytes(e=1){return ee.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return ee.megabytes(e.valueOf()*1e3)}static terabytes(e){return ee.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};g(ce,"BYTE",new ce(1)),g(ce,"KILOBYTE",ce.kilobytes(1)),g(ce,"MEGABYTE",ce.megabytes(1)),g(ce,"GIGABYTE",ce.gigabytes(1)),g(ce,"TERABYTE",ce.terabytes(1)),g(ce,"ZERO",new ce(0)),g(ce,"z",i.z.union([i.z.number().transform(r=>new ce(r)),i.z.instanceof(ce)]));let Xt=ce;const cc=i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]),eo=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof V||r instanceof Z||r instanceof Date},hc=(r,e,t,s=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(s):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(s.valueOf()):xt(t,-s).valueOf(),dc=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof to?!0:eo(r),Le=-1,pn={[Symbol.iterator]:()=>pn,next:()=>({done:!0,value:void 0})},fc=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),pc=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),gn=10,It=class xe{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",Le),g(this,"_refCount",0),g(this,"_cachedLength"),g(this,"_cachedIndexes"),dc(e)&&(e={data:e});const{dataType:t,timeRange:s,sampleOffset:n=0,glBufferUsage:a="static",alignment:o=0n,key:u=Ha()}=e,l=e.data??[];if(l instanceof xe||typeof l=="object"&&"isSynnaxSeries"in l&&l.isSynnaxSeries===!0){const h=l;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this._timeRange=h._timeRange,this.alignment=h.alignment,this._cachedMin=h._cachedMin,this._cachedMax=h._cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this._cachedLength=h._cachedLength;return}const d=eo(l),f=Array.isArray(l);if(t!=null)this.dataType=new M(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=l;if(!d){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=l[0]}if(typeof h=="string")this.dataType=M.STRING;else if(typeof h=="number")this.dataType=M.FLOAT64;else if(typeof h=="bigint")this.dataType=M.INT64;else if(typeof h=="boolean")this.dataType=M.BOOLEAN;else if(h instanceof V||h instanceof Date||h instanceof V)this.dataType=M.TIMESTAMP;else if(typeof h=="object")this.dataType=M.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new M(l)}if(!f&&!d)this._data=l;else{let h=d?[l]:l;const I=h[0];(I instanceof V||I instanceof Date||I instanceof Z)&&(h=h.map(D=>new V(D).valueOf())),this.dataType.equals(M.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`).buffer):this.dataType.equals(M.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(D=>Nr.encodeString(D)).join(`
|
|
6
|
+
`)}
|
|
7
|
+
`).buffer):this._data=new this.dataType.Array(h).buffer}this.key=u,this.alignment=o,this.sampleOffset=n??0,this._timeRange=s,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...s}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const n=new new M(t).Array(e),a=new xe({data:n.buffer,dataType:t,...s});return a.writePos=0,a}static generateTimestamps(e,t,s){const n=s.spanRange(t.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(s.add(t.span(o)).valueOf());return new xe({data:a,dataType:M.TIMESTAMP,timeRange:n})}get refCount(){return this._refCount}static fromStrings(e,t){const s=new TextEncoder().encode(`${e.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`);return new xe({data:s,dataType:M.STRING,timeRange:t})}static fromJSON(e,t){const s=new TextEncoder().encode(`${e.map(n=>Nr.encodeString(n)).join(`
|
|
10
|
+
`)}
|
|
11
|
+
`);return new xe({data:s,dataType:M.JSON,timeRange:t})}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 t=this.byteCapacity.valueOf()-this.writePos,s=e.subBytes(0,t);return this.writeToUnderlyingData(s),this.writePos+=s.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=s.length,this.calculateCachedLength()),s.length}writeFixed(e){if(this.writePos===Le)return 0;const t=this.capacity-this.writePos,s=e.sub(0,t);return this.writeToUnderlyingData(s),this._cachedLength=void 0,this.maybeRecomputeMinMax(s),this.writePos+=s.length,s.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Le?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(M.STRING,M.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(M.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=M.UUID.density.valueOf(),t=Array(this.length);for(let s=0;s<this.length;s++){const n=this.underlyingData.slice(s*e,(s+1)*e),a=Array.from(new Uint8Array(n.buffer),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[s]=a}return t}parseJSON(e){if(!this.dataType.equals(M.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
+
`).slice(0,-1).map(t=>e.parse(Nr.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Xt(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 Xt(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 t=[0];return this.data.forEach((s,n)=>{s===gn&&(e++,t.push(n+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const s=new e.Array(this.length);for(let n=0;n<this.length;n++)s[n]=hc(this.dataType,e,this.data[n],t);return new xe({data:s.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(M.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}else{const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}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()),xt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(M.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((t,s)=>t<s?t:s)}else{const e=this.data;this._cachedMin=e.reduce((t,s)=>t<s?t:s)}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()),xt(this._cachedMin,this.sampleOffset))}get bounds(){return p.i(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return xt(this.max,-this.min)}atAlignment(e,t){const s=Number(e-this.alignment);if(s<0||s>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${s}`);return}return this.at(s,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const s=this.data[e];if(s==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return xt(s,this.sampleOffset)}atVariable(e,t){let s=0,n=0;if(this._cachedIndexes!=null)s=this._cachedIndexes[e],n=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]===gn){if(e===0){n=o;break}s=o+1,e--}if(n===0&&(n=this.data.length),s>=n||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(s,n);return this.dataType.equals(M.STRING)?new TextDecoder().decode(a):p.C(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,s=this.length-1;const n=ms(e);for(;t<=s;){const a=Math.floor((t+s)/2),o=n(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:s=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(M.FLOAT32)&&!this.dataType.equals(M.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:s,prevBuffer:n}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==n)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Le){n===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(n).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,s==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Le}as(e){if(e==="string"){if(!this.dataType.equals(M.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(M.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:{lower:Ci(this.alignmentBounds.lower),upper:Ci(this.alignmentBounds.upper)},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 p.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 gc(this);return this.dataType.equals(M.JSON)?new yc(e):e}return new mc(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new zi(this,e,t??this.length)}subAlignmentIterator(e,t){return new zi(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const s=this.data.subarray(e,t);return new xe({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,s){if(t<=0&&(s==null||s>=this.length))return this;let n;return e?n=this.data.subarray(t,s):n=this.data.slice(t,s),new xe({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new xe({data:this.buffer,dataType:this.dataType,timeRange:ot.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};g(It,"crudeZ",i.z.object({timeRange:ot.z.optional(),dataType:M.z,alignment:Ka.optional(),data:i.z.union([fc,pc,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:uc.optional().default("static").optional()})),g(It,"z",It.crudeZ.transform(r=>new It(r)));let to=It,zi=class{constructor(e,t,s){g(this,"series"),g(this,"end"),g(this,"index"),this.series=e;const n=p.i(0,e.length);this.end=p.T(n,s),this.index=p.T(n,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}},gc=class{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,t=this.series.data;for(;this.index<t.length&&t[this.index]!==gn;)this.index++;const s=this.index;return e===s?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,s))})}[Symbol.iterator](){return this}};var Ni,Ei;let yc=class{constructor(e){g(this,"wrapped"),g(this,Ni,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Nr.decodeString(e.value)}}[(Ei=Symbol.iterator,Ni=Symbol.toStringTag,Ei)](){return this}};var Ii,xi;let mc=class{constructor(e){g(this,"series"),g(this,"index"),g(this,Ii,"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)}}[(xi=Symbol.iterator,Ii=Symbol.toStringTag,xi)](){return this}};const xt=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e);let wc=class{constructor(e){if(g(this,"series"),e.length!==0){const t=e[0].dataType;for(let s=1;s<e.length;s++)if(!e[s].dataType.equals(t))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new M(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?M.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?ot.ZERO:new ot(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?p.i(0n,0n):p.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,t)=>e+t.length,0)}atAlignment(e,t){if(this.series.length===0){if(t)throw new Error(`[series] - no value at alignment ${e}`);return}for(const s of this.series)if(p.a(s.alignmentBounds,e))return s.atAlignment(e,t);if(t)throw new Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(const s of this.series){if(e<s.length)return s.at(e,t);e-=s.length}if(t)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new Ds(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return pn;let s=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)s+=o.length;else if(p.a(o.alignmentBounds,e)){s+=Number(e-o.alignment);break}}let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)n+=o.length;else if(p.a(o.alignmentBounds,t)){n+=Number(t-o.alignment);break}}return new Ds(this,s,n)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return pn;let s=0;for(let n=0;n<this.series.length;n++){const a=this.series[n];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)s+=a.length;else if(p.a(a.alignmentBounds,e)){s+=Number(e-a.alignment);break}}return new Ds(this,s,s+t)}get byteLength(){return new Xt(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let t=0;for(const s of this.series)e.set(s.data,t),t+=s.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){const s=this.series.map(n=>n.alignmentBounds);return p.U(s,e,t)}distance(e,t){const s=this.series.map(n=>n.alignmentBounds);return p.V(s,e,t)}parseJSON(e){if(!this.dataType.equals(M.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new bc(this.series)}};var Ai,ki;class bc{constructor(e){g(this,"series"),g(this,"seriesIndex"),g(this,"internal"),g(this,Ai,"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())}[(ki=Symbol.iterator,Ai=Symbol.toStringTag,ki)](){return this}}let Ds=class{constructor(e,t,s){g(this,"series"),g(this,"index"),g(this,"end"),this.series=e,this.end=s,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const Ci=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},vc=(r,e)=>{let t=null;return e===0?r:(...s)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...s),e)}},Oc=(r,e)=>{let t=null;return e===0?r:(...s)=>{t===null&&(t=setTimeout(()=>{r(...s),t=null},e))}},Tc=r=>JSON.parse(JSON.stringify(r)),Sc=(r,...e)=>(e.forEach(t=>{let s=r;const n=t.split(".");n.forEach((a,o)=>{o===n.length-1?delete s[a]:a in s&&(s=s[a])})}),r),zc=(r,e,t="")=>{const s={},n=(a,o,u)=>{if(typeof a!=typeof o||a===null||o===null){s[u]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){s[u]=[a,o];return}for(let l=0;l<a.length;l++)n(a[l],o[l],`${u}[${l}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(l=>{n(a[l],o[l],u!==""?`${u}.${l}`:l)});else a!==o&&(s[u]=[a,o])};return n(r,e,t),s},yn=(r,e)=>{const t=Array.isArray(r),s=Array.isArray(e);if(t!==s)return!1;if(t&&s){const o=r,u=e;if(o.length!==u.length)return!1;for(let l=0;l<o.length;l++)if(!yn(o[l],u[l]))return!1;return!0}if(r==null||e==null||typeof r!="object"||typeof e!="object")return r===e;if("equals"in r)return r.equals(e);const n=Object.keys(r),a=Object.keys(e);if(n.length!==a.length)return!1;for(const o of n){const u=r[o],l=e[o];if(typeof u=="object"&&typeof l=="object"){if(!yn(u,l))return!1}else if(u!==l)return!1}return!0},ro=(r,e)=>{if(typeof r!="object"||r==null)return r===e;const t=Object.keys(r),s=Object.keys(e);if(s.length>t.length)return!1;for(const n of s){const a=r[n],o=e[n];if(typeof a=="object"&&typeof o=="object"){if(!ro(a,o))return!1}else if(a!==o)return!1}return!0},mn=(r,...e)=>{if(e.length===0)return r;const t=e.shift();if(Vt(r)&&Vt(t))for(const s in t)try{Vt(t[s])?(s in r||Object.assign(r,{[s]:{}}),mn(r[s],t[s])):Object.assign(r,{[s]:t[s]})}catch(n){throw n instanceof TypeError?new TypeError(`.${s}: ${n.message}`):n}return mn(r,...e)},Nc=(r,e,t)=>{const s=(n,a,o)=>{for(const u in a){const l=a[u];if(o!=null&&o.shape[u]){const d=o.shape[u].safeParse(l);d.success&&(n[u]=d.data)}else typeof l=="object"&&!Array.isArray(l)&&l!==null&&o&&o.shape&&o.shape[u]&&(n[u]||(n[u]={}),s(n[u],l,o.shape[u]))}return n};return s({...r},e,t)},so=Object.freeze(Object.defineProperty({__proto__:null,copy:Tc,deleteD:Sc,difference:zc,element:ec,equal:yn,get:Vn,has:tc,override:mn,overrideValidItems:Nc,partialEqual:ro,pathsMatch:rc,remove:Qu,set:Xu,transformPath:Za},Symbol.toStringTag,{value:"Module"}));i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const no=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Ec=no(),io=["MacOS","Windows","Linux","Docker"],Ic=["macos","windows","linux","docker"],xc={macos:"MacOS",windows:"Windows",linux:"Linux",docker:"Docker"},Ac=i.z.enum(io).or(i.z.enum(Ic).transform(r=>xc[r]));let Bs;const kc=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"MacOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"},Cc=(r={})=>{const{force:e,default:t}=r;return e??Bs??(Bs=kc(),Bs??t)},ao=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:io,RUNTIME:Ec,detect:no,getOS:Cc,osZ:Ac},Symbol.toStringTag,{value:"Module"})),Rc=r=>Array.isArray(r)?r:[r],$c=r=>Array.isArray(r)?r:r===null?[]:[r];var Mc=Object.defineProperty,Dc=(r,e,t)=>e in r?Mc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,At=(r,e,t)=>Dc(r,typeof e!="symbol"?e+"":e,t);const Bc=(...r)=>r.map(oo).join(""),oo=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),jc=r=>r.endsWith("/")?r.slice(0,-1):r,Ri=class wn{constructor({host:e,port:t,protocol:s="",pathPrefix:n=""}){At(this,"protocol"),At(this,"host"),At(this,"port"),At(this,"path"),this.protocol=s,this.host=e,this.port=t,this.path=oo(n)}replace(e){return new wn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new wn({...this,pathPrefix:Bc(this.path,e)})}toString(){return jc(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};At(Ri,"UNKNOWN",new Ri({host:"unknown",port:0}));var Pc=Object.defineProperty,Uc=(r,e,t)=>e in r?Pc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,is=(r,e,t)=>Uc(r,typeof e!="symbol"?e+"":e,t);let Lc=class{constructor(e){is(this,"sender"),is(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var t;const s=(t=this.handlers.get(e.type))==null?void 0:t.handler;s==null?console.warn(`No handler for ${e.type}`):s(e.payload)}route(e){const t=_c(e,this.sender),s=new qc(t);return this.handlers.set(e,s),s}};const _c=(r,e)=>(t,s)=>e({type:r,payload:t},s);let qc=class{constructor(e){is(this,"_send"),is(this,"handler"),this._send=e,this.handler=null}send(e,t=[]){this._send(e,t)}handle(e){this.handler=e}};var Yc=Object.defineProperty,Fc=(r,e,t)=>e in r?Yc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,kr=(r,e,t)=>Fc(r,typeof e!="symbol"?e+"":e,t);i.z.object({interval:Z.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()});const Je=class extends Number{};kr(Je,"Absolute",255),kr(Je,"Default",1),kr(Je,"z",i.z.union([i.z.instanceof(Je),i.z.number().int().min(0).max(255).transform(r=>new Je(r)),i.z.instanceof(Number).transform(r=>new Je(r))]));let lo=Je;const uo=i.z.object({name:i.z.string(),key:i.z.string()}),Gc=r=>i.z.object({subject:uo,resource:r,authority:lo.z}),Vc=(...r)=>e=>e.filter(t=>{let s=!1;return t.to!=null&&(s=r.includes(t.to.resource)),t.from!=null&&!s&&(s=r.includes(t.from.resource)),s}),Wc=Object.freeze(Object.defineProperty({__proto__:null,Authority:lo,filterTransfersByChannelKey:Vc,stateZ:Gc,subjectZ:uo},Symbol.toStringTag,{value:"Module"})),co=class kt extends Error{constructor(){super(kt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(kt.MESSAGE):e instanceof kt||e.message.includes(kt.MESSAGE)}};kr(co,"MESSAGE","canceled");let Zc=co;new Zc;const Jc=r=>r?-1:1,bn=i.z.string().regex(/^\d+\.\d+\.\d+$/),ar=(r,e,t={})=>{t.checkMajor??(t.checkMajor=!0),t.checkMinor??(t.checkMinor=!0),t.checkPatch??(t.checkPatch=!0);const s=bn.parse(r),n=bn.parse(e),[a,o,u]=s.split(".").map(Number),[l,d,f]=n.split(".").map(Number);if(t.checkMajor){if(a<l)return Er;if(a>l)return Ir}if(t.checkMinor){if(o<d)return Er;if(o>d)return Ir}if(t.checkPatch){if(u<f)return Er;if(u>f)return Ir}return pt},Kc=(r,e,t={})=>Wa(ar(r,e,t)),ho=(r,e,t={})=>Va(ar(r,e,t)),Hc=(r,e,t={})=>Ga(ar(r,e,t)),Xc=({name:r,migrate:e})=>t=>{try{const s=e(t);return console.log(`${r} migrated: ${t.version} -> ${s.version}`),s}catch(s){throw console.log(`${r} failed to migrate from ${t.version}`),console.error(s),s}},Qc=({name:r,migrations:e,targetSchema:t,defaultVersion:s,def:n})=>{const a=Object.keys(e).sort(ar).pop();if(a==null)return d=>{if(d.version??(d.version=s),d.version!==n.version)return console.log(`${r} version ${d.version} is newer than latest version of ${n.version}.
|
|
14
|
+
Returning default instead.
|
|
15
|
+
`),n;try{return t!=null?t.parse(d):d}catch(f){return console.log(`${r} failed to parse default. Exiting with default`),console.error(f),n}};const o=Object.keys(e).length;let u=!1;const l=d=>{try{if(o===0||ho(d.version,a))return console.log(u?`${r} ${d.version} now up to date`:`${r} version ${d.version} is up to date with target version ${n.version}`),d;const f=d.version,h=e[f],I=h(d);return u=!0,l(I)}catch(f){return console.log(`${r} failed to migrate from ${d.version} to ${a}`),console.error(f),n}};return d=>{try{if(d.version==null)if(s!=null)console.log(`${r} version is null. Setting version to default of ${s}`),d.version=s;else return console.log(`${r} version is null and no default version set. Exiting with default`),n;return l(d)}catch(f){return console.log(`${r} failed to parse final result. Exiting with default`),console.error(f),n}}},eh=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:ar,createMigration:Xc,migrator:Qc,semVerNewer:ho,semVerOlder:Hc,semVerZ:bn,versionsEqual:Kc},Symbol.toStringTag,{value:"Module"})),th=r=>{if(r===void 0||typeof r=="string"||typeof r=="number")return r;if(r.toString===void 0)throw new Error("invalid renderer");return r.toString()},rh=r=>Array.isArray(r)?[...r]:typeof r=="object"&&r!==null?{...r}:r,Wn=r=>typeof r=="function",Zn=(r,e)=>Wn(r)?r(e):r,or=r=>fo(r)?r():r,fo=r=>typeof r=="function",po=({initial:r,value:e,onChange:t})=>{const[s,n]=Gn.useState(or(e??r));return e!=null&&t!=null?[e,t]:[s,n]},go=({initial:r,value:e,onChange:t})=>{const[s,n]=Gn.useState(or(e??r));return e!=null&&t!=null?[e,t]:[s,n]},sh=(r,e)=>{const[t,s]=Gn.useState(()=>{const n=localStorage.getItem(e);return n==null?or(r):JSON.parse(n)});return[t,n=>{s(n),localStorage.setItem(e,JSON.stringify(n))}]},nh=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:or,executeSetter:Zn,isInitialSetter:fo,isSetter:Wn,usePassthrough:po,usePersisted:sh,usePurePassthrough:go},Symbol.toStringTag,{value:"Module"})),yo=["h1","h2","h3","h4","h5","p","small"],ih=i.z.enum(yo),ah={h1:"h2",h2:"h3",h3:"h4",h4:"h5",h5:"p",p:"small",small:"small"},oh=r=>ah[r],lh={h1:"h1",h2:"h1",h3:"h2",h4:"h3",h5:"h4",p:"h5",small:"p"},uh=r=>lh[r],ch=["normal","bold","bolder","lighter"],hh=i.z.union([i.z.number(),i.z.enum(ch)]),Fe=i.z.object({size:i.z.number(),weight:i.z.union([i.z.number(),i.z.string()]),lineHeight:i.z.number(),textTransform:i.z.string().optional()}),mo={small:"small",medium:"p",large:"h5",huge:"h2"},dh={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let $i=null;const fh=()=>($i??($i=document.createElement("canvas")),$i),ph=(r,e,t)=>{if(ao.RUNTIME==="node")return{width:0,height:0};t??(t=fh().getContext("2d")),t.font=e;const s=t.measureText(r);return{width:Math.trunc(Math.abs(s.actualBoundingBoxLeft)+Math.abs(s.actualBoundingBoxRight)),height:Math.trunc(Math.abs(s.actualBoundingBoxAscent)+Math.abs(s.actualBoundingBoxDescent))}},gh=i.z.object({l0:p.Color.z,l1:p.Color.z,l2:p.Color.z,l3:p.Color.z,l4:p.Color.z,l5:p.Color.z,l6:p.Color.z,l7:p.Color.z,l8:p.Color.z,l9:p.Color.z,l10:p.Color.z}),Te=(r,e)=>[r[0],r[1],e,r[3]],yh=i.z.object({m2:p.Color.z,m1:p.Color.z,z:p.Color.z,p1:p.Color.z,p2:p.Color.z}),mr=yh.or(p.Color.z.transform(r=>{const e=r.hsla;return{m2:new p.Color(p.fromHSLA(Te(e,40))),m1:new p.Color(p.fromHSLA(Te(e,45))),z:r,p1:new p.Color(p.fromHSLA(Te(e,55))),p2:new p.Color(p.fromHSLA(Te(e,65)))}})),wo=i.z.object({name:i.z.string(),key:i.z.string(),colors:i.z.object({border:p.Color.z,primary:mr,gray:gh,error:mr,secondary:mr,warning:mr,palettes:i.z.record(p.paletteZ),visualization:i.z.object({palettes:i.z.record(i.z.array(p.Color.z))}).optional().default({palettes:{}}),white:p.Color.z,black:p.Color.z,text:p.Color.z,textInverted:p.Color.z,textOnPrimary:p.Color.z.optional().default(p.ZERO),logo:i.z.string()}),sizes:i.z.object({base:i.z.number(),border:i.z.object({radius:i.z.number(),width:i.z.number()}),schematic:i.z.object({elementStrokeWidth:i.z.number()})}),typography:i.z.object({family:i.z.string(),codeFamily:i.z.string(),h1:Fe,h2:Fe,h3:Fe,h4:Fe,h5:Fe,p:Fe,small:Fe})}).transform(r=>((r.colors.textOnPrimary==null||r.colors.textOnPrimary.isZero)&&(r.colors.textOnPrimary=r.colors.primary.z.pickByContrast(r.colors.text,r.colors.textInverted)),r)),mh="'Inter Variable', sans-serif",wh="'Geist Mono', monospace",bh=6,bt=[357,91,55,1],vt=[58,100,50,1],vh=["#FDFDFD","#FAFAFA","#F3F3F3","#EAEAEA","#D8D8D8","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],Ot=Object.fromEntries(vh.map((r,e)=>[`l${e}`,r])),vn={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:Ot,border:Ot.l3,error:{m2:p.fromHSLA(Te(bt,30)),m1:p.fromHSLA(Te(bt,40)),z:p.fromHSLA(bt),p1:p.fromHSLA(Te(bt,65)),p2:p.fromHSLA(Te(bt,77))},warning:{m2:p.fromHSLA(Te(vt,30)),m1:p.fromHSLA(Te(vt,40)),z:p.fromHSLA(vt),p1:p.fromHSLA(Te(vt,65)),p2:p.fromHSLA(Te(vt,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:Ot.l9,textInverted:Ot.l0,textOnPrimary:Ot.l0},sizes:{base:bh,border:{radius:3,width:1},schematic:{elementStrokeWidth:2}},typography:{family:mh,codeFamily:wh,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}}},bo=Object.freeze({...vn,key:"synnaxLight",name:"Synnax Light"}),Oh=["#020202","#0A0A0A","#131313","#1E1E1E","#2E2E2E","#444444","#646464","#8A8A8A","#AFAFAF","#D5D5D5","#FDFDFD"],Tt=Object.fromEntries(Oh.map((r,e)=>[`l${e}`,r])),vo=Object.freeze({...vn,key:"synnaxDark",name:"Synnax Dark",colors:{...vn.colors,gray:Tt,logo:"var(--pluto-text-color)",border:Tt.l3,text:Tt.l9,textInverted:Tt.l0,textOnPrimary:Tt.l10}}),Th={synnaxDark:vo,synnaxLight:bo},Sh=["small","medium","large","huge"],zh=i.z.enum(Sh),Nh=r=>zh.safeParse(r).success,Eh=(r,{level:e,weight:t,code:s})=>{const{typography:n,sizes:{base:a}}=r,o=n[Nh(e)?mo[e]:e].size,u=(a*o).toFixed(1),l=s?n.codeFamily:n.family,[d,f]=l.split(", ");return t!=null?` ${t} ${u}px ${d}, ${f}`:` ${u}px ${l}`};var Ih=Object.defineProperty,xh=(r,e,t)=>e in r?Ih(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>xh(r,typeof e!="symbol"?e+"":e,t);const S=r=>Array.isArray(r)?r:[r];var Ah=Object.defineProperty,kh=(r,e,t)=>e in r?Ah(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,B=(r,e,t)=>kh(r,typeof e!="symbol"?e+"":e,t);const Ch=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Oo=r=>{const e=(t,s=On)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,s));if(!js(t))return t;s=Mh(s);const n={},a=t;return Object.keys(a).forEach(o=>{let u=a[o];const l=r(o);s.recursive&&(js(u)?Di(u,s.keepTypesOnRecursion)||(u=e(u,s)):s.recursiveInArray&&Mi(u)&&(u=[...u].map(d=>{let f=d;return js(d)?Di(f,s.keepTypesOnRecursion)||(f=e(d,s)):Mi(d)&&(f=e({key:d},s).key),f}))),n[l]=u}),n};return e},To=Oo(Ch),Rh=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,s)=>`${t}_${s.toLowerCase()}`),$h=Oo(Rh),On={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Mh=(r=On)=>(r.recursive==null?r=On:r.recursiveInArray??(r.recursiveInArray=!1),r),Mi=r=>r!=null&&Array.isArray(r),js=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Di=(r,e)=>(e||[]).some(t=>r instanceof t),So=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var Dh=Object.defineProperty,Bh=(r,e,t)=>e in r?Dh(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Zt=(r,e,t)=>Bh(r,typeof e!="symbol"?e+"":e,t);let jh=class{constructor(){Zt(this,"contentType","application/json"),Zt(this,"decoder"),Zt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(r){return this.encoder.encode(this.encodeString(r)).buffer}decode(r,e){return this.decodeString(this.decoder.decode(r),e)}decodeString(r,e){const t=JSON.parse(r),s=To(t);return e!=null?e.parse(s):s}encodeString(r){const e=$h(r);return JSON.stringify(e,(t,s)=>ArrayBuffer.isView(s)?Array.from(s):So(s)&&"encode_value"in s?typeof s.value=="bigint"?s.value.toString():s.value:typeof s=="bigint"?s.toString():s)}static registerCustomType(){}},Ph=class{constructor(){Zt(this,"contentType","text/csv")}encode(r){const e=this.encodeString(r);return new TextEncoder().encode(e).buffer}decode(r,e){const t=new TextDecoder().decode(r);return this.decodeString(t,e)}encodeString(r){if(!Array.isArray(r)||r.length===0||!So(r[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(r[0]),t=[e.join(",")];return r.forEach(s=>{const n=e.map(a=>JSON.stringify(s[a]??""));t.push(n.join(","))}),t.join(`
|
|
16
|
+
`)}decodeString(r,e){const[t,...s]=r.trim().split(`
|
|
17
|
+
`).map(o=>o.trim());if(t.length===0)return e!=null?e.parse({}):{};const n=t.split(",").map(o=>o.trim()),a={};return n.forEach(o=>{a[o]=[]}),s.forEach(o=>{const u=o.split(",").map(l=>l.trim());n.forEach((l,d)=>{const f=this.parseValue(u[d]);f!=null&&a[l].push(f)})}),e!=null?e.parse(a):a}parseValue(r){if(r==null||r.length===0)return null;const e=Number(r);return isNaN(e)?r.startsWith('"')&&r.endsWith('"')?r.slice(1,-1):r:e}static registerCustomType(){}},Uh=class{constructor(){Zt(this,"contentType","text/plain")}encode(r){return new TextEncoder().encode(r).buffer}decode(r,e){const t=new TextDecoder().decode(r);return e!=null?e.parse(t):t}};const Cr=new jh;new Ph;new Uh;const Lh=r=>r!=null&&typeof r=="object"&&"toString"in r,_h=(r,e=!1)=>{const t=Lh(r)?"stringer":typeof r;let s;switch(t){case"string":s=(n,a)=>n.localeCompare(a);break;case"stringer":s=(n,a)=>n.toString().localeCompare(a.toString());break;case"number":s=(n,a)=>Number(n)-Number(a);break;case"bigint":s=(n,a)=>BigInt(n)-BigInt(a)>0n?1:-1;break;case"boolean":s=(n,a)=>Number(n)-Number(a);break;case"undefined":s=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?qh(s):s},qh=r=>(e,t)=>r(t,e),ws=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const zo=i.z.object({width:i.z.number(),height:i.z.number()}),Yh=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Fh=["width","height"];i.z.enum(Fh);const Gh=["start","center","end"],Vh=["signedWidth","signedHeight"];i.z.enum(Vh);const as=i.z.object({x:i.z.number(),y:i.z.number()}),Wh=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),Zh=["x","y"],No=i.z.enum(Zh),Eo=["top","right","bottom","left"];i.z.enum(Eo);const Jh=["left","right"],Io=i.z.enum(Jh),Kh=["top","bottom"],xo=i.z.enum(Kh),Ao=["center"],Bi=i.z.enum(Ao),Hh=[...Eo,...Ao],ko=i.z.enum(Hh);i.z.enum(Gh);const Xh=["first","last"];i.z.enum(Xh);const Qh=i.z.object({lower:i.z.number(),upper:i.z.number()}),ed=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Qh,ws]);i.z.union([ed,ws]);i.z.union([No,ko]);i.z.union([No,ko,i.z.instanceof(String)]);const td=r=>typeof r=="bigint"||r instanceof BigInt,tt=(r,e)=>td(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),Qe=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ji(r);return ji(t)},ji=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Pi=(r,e)=>{const t=Qe(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:Io.or(Bi),y:xo.or(Bi)});const rd=i.z.object({x:Io,y:xo}),sd=Object.freeze({x:"left",y:"top"}),nd=(r,e)=>r.x===e.x&&r.y===e.y,Ui=i.z.union([i.z.number(),as,ws,zo,Yh,Wh]),id=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Li=Object.freeze({x:0,y:0}),wr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:wr,left:wr,width:wr,height:wr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:as,two:as,root:rd});const Jn=(r,e,t=0,s=0,n)=>{const a={one:{...Li},two:{...Li},root:n??sd};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+s},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:n??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+s}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Ps=r=>{const e=Jn(r);return{lower:e.one.x,upper:e.two.x}},Us=r=>{const e=Jn(r);return{lower:e.one.y,upper:e.two.y}},ad=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,od=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([zo,od,as,ws]);var ld=Object.defineProperty,ud=(r,e,t)=>e in r?ld(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,je=(r,e,t)=>ud(r,typeof e!="symbol"?e+"":e,t);const cd=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:Ui,scale:Ui});i.z.object({offset:i.z.number(),scale:i.z.number()});const hd=r=>(e,t,s,n)=>t==="dimension"?[e,s]:[e,n?s-r:s+r],dd=r=>(e,t,s,n)=>[e,n?s/r:s*r],fd=r=>(e,t,s)=>{if(e===null)return[r,s];const{lower:n,upper:a}=e,{lower:o,upper:u}=r,l=a-n,d=u-o;if(t==="dimension")return[r,s*(d/l)];const f=(s-n)*(d/l)+o;return[r,f]},pd=r=>(e,t,s)=>[r,s],gd=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:s,upper:n}=r;return[r,n-(t-s)]},yd=r=>(e,t,s)=>{const{lower:n,upper:a}=r;return s=cd(s,n,a),[e,s]},Tn=class Ct{constructor(){je(this,"ops",[]),je(this,"currBounds",null),je(this,"currType",null),je(this,"reversed",!1),this.ops=[]}static translate(e){return new Ct().translate(e)}static magnify(e){return new Ct().magnify(e)}static scale(e,t){return new Ct().scale(e,t)}translate(e){const t=this.new(),s=hd(e);return s.type="translate",t.ops.push(s),t}magnify(e){const t=this.new(),s=dd(e);return s.type="magnify",t.ops.push(s),t}scale(e,t){const s=Qe(e,t),n=this.new(),a=fd(s);return a.type="scale",n.ops.push(a),n}clamp(e,t){const s=Qe(e,t),n=this.new(),a=yd(s);return a.type="clamp",n.ops.push(a),n}reBound(e,t){const s=Qe(e,t),n=this.new(),a=pd(s);return a.type="re-bound",n.ops.push(a),n}invert(){const e=gd();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Ct;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([s,n],a)=>a(s,e,n,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((s,n)=>{if(s.type==="scale"||t.some(([o,u])=>n>=o&&n<=u))return;const a=e.ops.findIndex((o,u)=>o.type==="scale"&&u>n);a!==-1&&t.push([n,a])}),t.forEach(([s,n])=>{const a=e.ops.slice(s,n);a.unshift(e.ops[n]),e.ops.splice(s,n-s+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};je(Tn,"IDENTITY",new Tn);let _i=Tn;const qi=class De{constructor(e=new _i,t=new _i,s=null){je(this,"x"),je(this,"y"),je(this,"currRoot"),this.x=e,this.y=t,this.currRoot=s}static translate(e,t){return new De().translate(e,t)}static translateX(e){return new De().translateX(e)}static translateY(e){return new De().translateY(e)}static clamp(e){return new De().clamp(e)}static magnify(e){return new De().magnify(e)}static scale(e){return new De().scale(e)}static reBound(e){return new De().reBound(e)}translate(e,t){const s=id(e,t),n=this.copy();return n.x=this.x.translate(s.x),n.y=this.y.translate(s.y),n}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(ad(e)){const s=this.currRoot;return t.currRoot=e.root,s!=null&&!nd(s,e.root)&&(s.x!==e.root.x&&(t.x=t.x.invert()),s.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(Ps(e)),t.y=t.y.scale(Us(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(Ps(e)),t.y=this.y.reBound(Us(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(Ps(e)),t.y=this.y.clamp(Us(e)),t}copy(){const e=new De;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 Jn(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})}}};je(qi,"IDENTITY",new qi);const md=i.z.bigint().or(i.z.string().transform(BigInt));var wd=Object.defineProperty,bd=(r,e,t)=>e in r?wd(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,v=(r,e,t)=>bd(r,typeof e!="symbol"?e+"":e,t);let vd=(r,e=21)=>(t=e)=>{let s="",n=t|0;for(;n--;)s+=r[Math.random()*r.length|0];return s};const Od="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Td=vd(Od,11),Sd=i.z.enum(["static","dynamic"]),Co=(r,e)=>{const t=new J(e);if(![W.DAY,W.HOUR,W.MINUTE,W.SECOND,W.MILLISECOND,W.MICROSECOND,W.NANOSECOND].some(n=>n.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const s=r.valueOf()%t.valueOf();return r instanceof J?new J(s):new W(s)},q=class N{constructor(e,t="UTC"){if(v(this,"value"),v(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,t).valueOf();else if(Array.isArray(e))this.value=N.parseDate(e);else{let s=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(s=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())+s}}static parseDate([e=1970,t=1,s=1]){const n=new Date(e,t-1,s,0,0,0,0);return new N(BigInt(n.getTime())*N.MILLISECOND.valueOf()).truncate(N.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[s,n,a]=e.split(":");let o="00",u="00";a!=null&&([o,u]=a.split("."));let l=N.hours(parseInt(s??"00")).add(N.minutes(parseInt(n??"00"))).add(N.seconds(parseInt(o??"00"))).add(N.milliseconds(parseInt(u??"00")));return t==="local"&&(l=l.add(N.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return N.parseTimeString(e,t);const s=new Date(e);return e.includes(":")||s.setUTCHours(0,0,0,0),new N(BigInt(s.getTime())*N.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(N.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const s=this.toISOString(t);return e?s.slice(11,23):s.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),s=e.toLocaleString("default",{day:"numeric"});return`${t} ${s}`}static get utcOffset(){return new W(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 Kn(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()))}get hours(){return Number(this.valueOf())/Number(W.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(W.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(W.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(W.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new N(t)}get month(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setMonth(e),new N(t)}get day(){return this.date().getDate()}setDay(e){const t=this.date();return t.setDate(e),new N(t)}get hour(){return this.date().getHours()}setHour(e){const t=this.date();return t.setHours(e),new N(t)}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setMinutes(e),new N(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setSeconds(e),new N(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new N(t)}toString(){return this.date().toISOString()}remainder(e){return Co(this,e)}get isToday(){return this.truncate(W.DAY).equals(N.now().truncate(W.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new N(new Date)}static max(...e){let t=N.MIN;for(const s of e){const n=new N(s);n.after(t)&&(t=n)}return t}static min(...e){let t=N.MAX;for(const s of e){const n=new N(s);n.before(t)&&(t=n)}return t}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)}};v(q,"NANOSECOND",q.nanoseconds(1)),v(q,"MICROSECOND",q.microseconds(1)),v(q,"MILLISECOND",q.milliseconds(1)),v(q,"SECOND",q.seconds(1)),v(q,"MINUTE",q.minutes(1)),v(q,"HOUR",q.hours(1)),v(q,"DAY",q.days(1)),v(q,"MAX",new q((1n<<63n)-1n)),v(q,"MIN",new q(0)),v(q,"ZERO",new q(0)),v(q,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new q(r.value)),i.z.string().transform(r=>new q(BigInt(r))),i.z.instanceof(Number).transform(r=>new q(r)),i.z.number().transform(r=>new q(r)),i.z.instanceof(q)]));let J=q;const Y=class k{constructor(e){v(this,"value"),v(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 Yi?e.period:e instanceof J?new k(e):["number","bigint"].includes(typeof e)?k.seconds(e):new k(e)}static fromMilliseconds(e){return e instanceof k?e:e instanceof Yi?e.period:e instanceof J?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 Co(this,e)}truncate(e){return new k(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(k.DAY),t=this.truncate(k.HOUR),s=this.truncate(k.MINUTE),n=this.truncate(k.SECOND),a=this.truncate(k.MILLISECOND),o=this.truncate(k.MICROSECOND),u=this.truncate(k.NANOSECOND),l=e,d=t.sub(e),f=s.sub(t),h=n.sub(s),I=a.sub(n),D=o.sub(a),ue=u.sub(o);let j="";return l.isZero||(j+=`${l.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),I.isZero||(j+=`${I.milliseconds}ms `),D.isZero||(j+=`${D.microseconds}µs `),ue.isZero||(j+=`${ue.nanoseconds}ns`),j.trim()}mult(e){return new k(this.valueOf()*BigInt(e))}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(tt(e,1e3))}static milliseconds(e=1){return k.microseconds(tt(e,1e3))}static seconds(e=1){return k.milliseconds(tt(e,1e3))}static minutes(e=1){return k.seconds(tt(e,60))}static hours(e){return k.minutes(tt(e,60))}static days(e){return k.hours(tt(e,24))}};v(Y,"NANOSECOND",Y.nanoseconds(1)),v(Y,"MICROSECOND",Y.microseconds(1)),v(Y,"MILLISECOND",Y.milliseconds(1)),v(Y,"SECOND",Y.seconds(1)),v(Y,"MINUTE",Y.minutes(1)),v(Y,"HOUR",Y.hours(1)),v(Y,"DAY",Y.days(1)),v(Y,"MAX",new Y((1n<<63n)-1n)),v(Y,"MIN",new Y(0)),v(Y,"ZERO",new Y(0)),v(Y,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new Y(r.value)),i.z.string().transform(r=>new Y(BigInt(r))),i.z.instanceof(Number).transform(r=>new Y(r)),i.z.number().transform(r=>new Y(r)),i.z.instanceof(Y)]));let W=Y;const Rt=class Rr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Rr(e).valueOf()}get period(){return W.seconds(1/this.valueOf())}sampleCount(e){return new W(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new pe(t).valueOf()}span(e){return W.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new Rr(e)}static khz(e){return Rr.hz(e*1e3)}};v(Rt,"z",i.z.union([i.z.number().transform(r=>new Rt(r)),i.z.instanceof(Number).transform(r=>new Rt(r)),i.z.instanceof(Rt)]));let Yi=Rt;const ie=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Sn(e*this.valueOf())}};v(ie,"UNKNOWN",new ie(0)),v(ie,"BIT128",new ie(16)),v(ie,"BIT64",new ie(8)),v(ie,"BIT32",new ie(4)),v(ie,"BIT16",new ie(2)),v(ie,"BIT8",new ie(1)),v(ie,"z",i.z.union([i.z.number().transform(r=>new ie(r)),i.z.instanceof(Number).transform(r=>new ie(r)),i.z.instanceof(ie)]));let pe=ie;const Ae=class $r{constructor(e,t){v(this,"start"),v(this,"end"),typeof e=="object"&&"start"in e?(this.start=new J(e.start),this.end=new J(e.end)):(this.start=new J(e),this.end=new J(t))}get span(){return new W(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new $r(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,t=W.ZERO){e=e.makeValid();const s=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(s.start)||s.end.equals(e.start))return!1;const n=J.max(s.start,e.start),a=J.min(s.end,e.end);return a.before(n)?!1:new W(a.sub(n)).greaterThanOrEqual(t)}roughlyEquals(e,t){let s=this.start.sub(e.start).valueOf(),n=this.end.sub(e.end).valueOf();return s<0&&(s=-s),n<0&&(n=-n),s<=t.valueOf()&&n<=t.valueOf()}contains(e){return e instanceof $r?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new $r(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}};v(Ae,"MAX",new Ae(J.MIN,J.MAX)),v(Ae,"MIN",new Ae(J.MAX,J.MIN)),v(Ae,"ZERO",new Ae(J.ZERO,J.ZERO)),v(Ae,"z",i.z.union([i.z.object({start:J.z,end:J.z}).transform(r=>new Ae(r.start,r.end)),i.z.instanceof(Ae)]));let Kn=Ae;const w=class H extends String{constructor(e){if(e instanceof H||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=H.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(H.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=H.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(H.JSON)||this.equals(H.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(H.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=H.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(H.UINT8)||this.equals(H.UINT16)||this.equals(H.UINT32)||this.equals(H.UINT64)}get isSigned(){return this.equals(H.INT8)||this.equals(H.INT16)||this.equals(H.INT32)||this.equals(H.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(H.INT32)&&e.equals(H.FLOAT64)||this.equals(H.INT8)&&e.equals(H.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!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 H.BIG_INT_TYPES.some(e=>e.equals(this))}};v(w,"UNKNOWN",new w("unknown")),v(w,"FLOAT64",new w("float64")),v(w,"FLOAT32",new w("float32")),v(w,"INT64",new w("int64")),v(w,"INT32",new w("int32")),v(w,"INT16",new w("int16")),v(w,"INT8",new w("int8")),v(w,"UINT64",new w("uint64")),v(w,"UINT32",new w("uint32")),v(w,"UINT16",new w("uint16")),v(w,"UINT8",new w("uint8")),v(w,"BOOLEAN",w.UINT8),v(w,"TIMESTAMP",new w("timestamp")),v(w,"UUID",new w("uuid")),v(w,"STRING",new w("string")),v(w,"JSON",new w("json")),v(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]])),v(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]])),v(w,"DENSITIES",new Map([[w.UINT8.toString(),pe.BIT8],[w.UINT16.toString(),pe.BIT16],[w.UINT32.toString(),pe.BIT32],[w.UINT64.toString(),pe.BIT64],[w.FLOAT32.toString(),pe.BIT32],[w.FLOAT64.toString(),pe.BIT64],[w.INT8.toString(),pe.BIT8],[w.INT16.toString(),pe.BIT16],[w.INT32.toString(),pe.BIT32],[w.INT64.toString(),pe.BIT64],[w.TIMESTAMP.toString(),pe.BIT64],[w.STRING.toString(),pe.UNKNOWN],[w.JSON.toString(),pe.UNKNOWN],[w.UUID.toString(),pe.BIT128]])),v(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]),v(w,"BIG_INT_TYPES",[w.INT64,w.UINT64,w.TIMESTAMP]),v(w,"z",i.z.union([i.z.string().transform(r=>new w(r)),i.z.instanceof(w)]));let P=w;const he=class te extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return te.bytes(this.valueOf()+e.valueOf())}sub(e){return te.bytes(this.valueOf()-e.valueOf())}truncate(e){return new te(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return te.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/te.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/te.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/te.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/te.TERABYTE.valueOf()}toString(){const e=this.truncate(te.TERABYTE),t=this.truncate(te.GIGABYTE),s=this.truncate(te.MEGABYTE),n=this.truncate(te.KILOBYTE),a=this.truncate(te.BYTE),o=e,u=t.sub(e),l=s.sub(t),d=n.sub(s),f=a.sub(n);let h="";return o.isZero||(h+=`${o.terabytes}TB `),u.isZero||(h+=`${u.gigabytes}GB `),l.isZero||(h+=`${l.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new te(e)}static kilobytes(e=1){return te.bytes(e.valueOf()*1e3)}static megabytes(e=1){return te.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return te.megabytes(e.valueOf()*1e3)}static terabytes(e){return te.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};v(he,"BYTE",new he(1)),v(he,"KILOBYTE",he.kilobytes(1)),v(he,"MEGABYTE",he.megabytes(1)),v(he,"GIGABYTE",he.gigabytes(1)),v(he,"TERABYTE",he.terabytes(1)),v(he,"ZERO",new he(0)),v(he,"z",i.z.union([i.z.number().transform(r=>new he(r)),i.z.instanceof(he)]));let Sn=he;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Ro=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof J||r instanceof W||r instanceof Date},zd=(r,e,t,s=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(s):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(s.valueOf()):Mt(t,-s).valueOf(),Nd=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof xd?!0:Ro(r),_e=-1,Ed=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Id=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),zn=10,$t=class ke{constructor(e){v(this,"key",""),v(this,"isSynnaxSeries",!0),v(this,"dataType"),v(this,"sampleOffset"),v(this,"gl"),v(this,"_data"),v(this,"_timeRange"),v(this,"alignment",0n),v(this,"_cachedMin"),v(this,"_cachedMax"),v(this,"writePos",_e),v(this,"_refCount",0),v(this,"_cachedLength"),v(this,"_cachedIndexes"),Nd(e)&&(e={data:e});const{dataType:t,timeRange:s,sampleOffset:n=0,glBufferUsage:a="static",alignment:o=0n,key:u=Td()}=e,l=e.data??[];if(l instanceof ke||typeof l=="object"&&"isSynnaxSeries"in l&&l.isSynnaxSeries===!0){const h=l;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this._timeRange=h._timeRange,this.alignment=h.alignment,this._cachedMin=h._cachedMin,this._cachedMax=h._cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this._cachedLength=h._cachedLength;return}const d=Ro(l),f=Array.isArray(l);if(t!=null)this.dataType=new P(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=l;if(!d){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=l[0]}if(typeof h=="string")this.dataType=P.STRING;else if(typeof h=="number")this.dataType=P.FLOAT64;else if(typeof h=="bigint")this.dataType=P.INT64;else if(typeof h=="boolean")this.dataType=P.BOOLEAN;else if(h instanceof J||h instanceof Date||h instanceof J)this.dataType=P.TIMESTAMP;else if(typeof h=="object")this.dataType=P.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new P(l)}if(!f&&!d)this._data=l;else{let h=d?[l]:l;const I=h[0];(I instanceof J||I instanceof Date||I instanceof W)&&(h=h.map(D=>new J(D).valueOf())),this.dataType.equals(P.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`).buffer):this.dataType.equals(P.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(D=>Cr.encodeString(D)).join(`
|
|
20
|
+
`)}
|
|
21
|
+
`).buffer):this._data=new this.dataType.Array(h).buffer}this.key=u,this.alignment=o,this.sampleOffset=n??0,this._timeRange=s,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...s}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const n=new new P(t).Array(e),a=new ke({data:n.buffer,dataType:t,...s});return a.writePos=0,a}static generateTimestamps(e,t,s){const n=s.spanRange(t.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(s.add(t.span(o)).valueOf());return new ke({data:a,dataType:P.TIMESTAMP,timeRange:n})}get refCount(){return this._refCount}static fromStrings(e,t){const s=new TextEncoder().encode(`${e.join(`
|
|
22
|
+
`)}
|
|
23
|
+
`);return new ke({data:s,dataType:P.STRING,timeRange:t})}static fromJSON(e,t){const s=new TextEncoder().encode(`${e.map(n=>Cr.encodeString(n)).join(`
|
|
24
|
+
`)}
|
|
25
|
+
`);return new ke({data:s,dataType:P.JSON,timeRange:t})}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 t=this.byteCapacity.valueOf()-this.writePos,s=e.subBytes(0,t);return this.writeToUnderlyingData(s),this.writePos+=s.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=s.length,this.calculateCachedLength()),s.length}writeFixed(e){if(this.writePos===_e)return 0;const t=this.capacity-this.writePos,s=e.sub(0,t);return this.writeToUnderlyingData(s),this._cachedLength=void 0,this.maybeRecomputeMinMax(s),this.writePos+=s.length,s.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===_e?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(P.STRING,P.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(P.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=P.UUID.density.valueOf(),t=Array(this.length);for(let s=0;s<this.length;s++){const n=this.underlyingData.slice(s*e,(s+1)*e),a=Array.from(new Uint8Array(n.buffer),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[s]=a}return t}parseJSON(e){if(!this.dataType.equals(P.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
|
|
27
|
+
`).slice(0,-1).map(t=>e.parse(Cr.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Sn(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 Sn(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 t=[0];return this.data.forEach((s,n)=>{s===zn&&(e++,t.push(n+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const s=new e.Array(this.length);for(let n=0;n<this.length;n++)s[n]=zd(this.dataType,e,this.data[n],t);return new ke({data:s.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(P.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}else{const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}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()),Mt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(P.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((t,s)=>t<s?t:s)}else{const e=this.data;this._cachedMin=e.reduce((t,s)=>t<s?t:s)}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()),Mt(this._cachedMin,this.sampleOffset))}get bounds(){return Qe(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return Mt(this.max,-this.min)}atAlignment(e,t){const s=Number(e-this.alignment);if(s<0||s>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${s}`);return}return this.at(s,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const s=this.data[e];if(s==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return Mt(s,this.sampleOffset)}atVariable(e,t){let s=0,n=0;if(this._cachedIndexes!=null)s=this._cachedIndexes[e],n=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]===zn){if(e===0){n=o;break}s=o+1,e--}if(n===0&&(n=this.data.length),s>=n||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(s,n);return this.dataType.equals(P.STRING)?new TextDecoder().decode(a):To(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,s=this.length-1;const n=_h(e);for(;t<=s;){const a=Math.floor((t+s)/2),o=n(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:s=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(P.FLOAT32)&&!this.dataType.equals(P.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:s,prevBuffer:n}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==n)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==_e){n===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(n).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,s==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=_e}as(e){if(e==="string"){if(!this.dataType.equals(P.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(P.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:{lower:Ji(this.alignmentBounds.lower),upper:Ji(this.alignmentBounds.upper)},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 Qe(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 Ad(this);return this.dataType.equals(P.JSON)?new kd(e):e}return new Cd(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Fi(this,e,t??this.length)}subAlignmentIterator(e,t){return new Fi(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const s=this.data.subarray(e,t);return new ke({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,s){if(t<=0&&(s==null||s>=this.length))return this;let n;return e?n=this.data.subarray(t,s):n=this.data.slice(t,s),new ke({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new ke({data:this.buffer,dataType:this.dataType,timeRange:Kn.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};v($t,"crudeZ",i.z.object({timeRange:Kn.z.optional(),dataType:P.z,alignment:md.optional(),data:i.z.union([Ed,Id,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Sd.optional().default("static").optional()})),v($t,"z",$t.crudeZ.transform(r=>new $t(r)));let xd=$t;class Fi{constructor(e,t,s){v(this,"series"),v(this,"end"),v(this,"index"),this.series=e;const n=Qe(0,e.length);this.end=Pi(n,s),this.index=Pi(n,t)}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 Ad{constructor(e){if(v(this,"series"),v(this,"index"),v(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,t=this.series.data;for(;this.index<t.length&&t[this.index]!==zn;)this.index++;const s=this.index;return e===s?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,s))})}[Symbol.iterator](){return this}}var Gi,Vi;class kd{constructor(e){v(this,"wrapped"),v(this,Gi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Cr.decodeString(e.value)}}[(Vi=Symbol.iterator,Gi=Symbol.toStringTag,Vi)](){return this}}var Wi,Zi;class Cd{constructor(e){v(this,"series"),v(this,"index"),v(this,Wi,"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)}}[(Zi=Symbol.iterator,Wi=Symbol.toStringTag,Zi)](){return this}}const Mt=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e),Ji=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const $o=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Rd=$o(),Mo=["MacOS","Windows","Linux","Docker"],$d=["macos","windows","linux","docker"],Md={macos:"MacOS",windows:"Windows",linux:"Linux",docker:"Docker"},Dd=i.z.enum(Mo).or(i.z.enum($d).transform(r=>Md[r]));let Ls;const Bd=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"MacOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"},jd=(r={})=>{const{force:e,default:t}=r;return e??Ls??(Ls=Bd(),Ls??t)},Do=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Mo,RUNTIME:Rd,detect:$o,getOS:jd,osZ:Dd},Symbol.toStringTag,{value:"Module"}));var Pd=Object.defineProperty,Ud=(r,e,t)=>e in r?Pd(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Dt=(r,e,t)=>Ud(r,typeof e!="symbol"?e+"":e,t);const Ld=(...r)=>r.map(Bo).join(""),Bo=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),_d=r=>r.endsWith("/")?r.slice(0,-1):r,qd=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,s])=>`${e}${t}=${s}`).join("&")}`,Nn=class En{constructor({host:e,port:t,protocol:s="",pathPrefix:n=""}){Dt(this,"protocol"),Dt(this,"host"),Dt(this,"port"),Dt(this,"path"),this.protocol=s,this.host=e,this.port=t,this.path=Bo(n)}replace(e){return new En({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new En({...this,pathPrefix:Ld(this.path,e)})}toString(){return _d(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Dt(Nn,"UNKNOWN",new Nn({host:"unknown",port:0}));let Yd=Nn;var Fd=Object.defineProperty,Gd=(r,e,t)=>e in r?Fd(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Mr=(r,e,t)=>Gd(r,typeof e!="symbol"?e+"":e,t);const Vd=async r=>await new Promise(e=>setTimeout(e,W.fromMilliseconds(r).milliseconds)),Wd=i.z.object({interval:W.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Zd=(r={})=>{const e=r.sleepFn||Vd,t=r.maxRetries??5,s=r.scale??1;let n=0,a=new W(r.interval??W.milliseconds(1));return async()=>n>=t?!1:(await e(a),a=a.mult(s),n++,!0)},Jd=Object.freeze(Object.defineProperty({__proto__:null,breakerConfig:Wd,create:Zd},Symbol.toStringTag,{value:"Module"})),rt=class extends Number{};Mr(rt,"Absolute",255),Mr(rt,"Default",1),Mr(rt,"z",i.z.union([i.z.instanceof(rt),i.z.number().int().min(0).max(255).transform(r=>new rt(r)),i.z.instanceof(Number).transform(r=>new rt(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const jo=class Bt extends Error{constructor(){super(Bt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Bt.MESSAGE):e instanceof Bt||e.message.includes(Bt.MESSAGE)}};Mr(jo,"MESSAGE","canceled");let Kd=jo;new Kd;i.z.string().regex(/^\d+\.\d+\.\d+$/);const me=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(r):e instanceof Error?e.message.includes(r):typeof e!="string"?!1:e.includes(r);let Ee=class extends Error{constructor(){super(...arguments),B(this,"discriminator","FreighterError"),B(this,"type","")}};const Hd=r=>{if(r==null||typeof r!="object")return!1;const e=r;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},Ki="unknown",Hi="nil",Xd="freighter",lr=i.z.object({type:i.z.string(),data:i.z.string()});class Qd{constructor(){B(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Hi,data:""};if(Hd(e))for(const t of this.providers){const s=t.encode(e);if(s!=null)return s}return{type:Ki,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Hi)return null;if(e.type===Ki)return new Xi(e.data);for(const t of this.providers){const s=t.decode(e);if(s!=null)return s}return new Xi(e.data)}}const Po=new Qd,Uo=({encode:r,decode:e})=>Po.register({encode:r,decode:e}),os=r=>Po.decode(r);class Xi extends Ee{constructor(){super(...arguments),B(this,"type","unknown")}}const bs="freighter.",Dr=class Lo extends Ee{constructor(){super("EOF"),B(this,"type",Lo.TYPE)}};B(Dr,"TYPE",`${bs}eof`),B(Dr,"matches",me(Dr.TYPE));let Ve=Dr;const Br=class _o extends Ee{constructor(){super("StreamClosed"),B(this,"type",_o.TYPE)}};B(Br,"TYPE",`${bs}stream_closed`),B(Br,"matches",me(Br.TYPE));let lt=Br;const jr=class qo extends Ee{constructor(e={}){const{message:t="Unreachable",url:s=Yd.UNKNOWN}=e;super(t),B(this,"type",qo.TYPE),B(this,"url"),this.url=s}};B(jr,"TYPE",`${bs}unreachable`),B(jr,"matches",me(jr.TYPE));let We=jr;const ef=r=>{if(!r.type.startsWith(Xd))return null;if(Ve.matches(r))return{type:Ve.TYPE,data:"EOF"};if(lt.matches(r))return{type:lt.TYPE,data:"StreamClosed"};if(We.matches(r))return{type:We.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},tf=r=>{if(!r.type.startsWith(bs))return null;switch(r.type){case Ve.TYPE:return new Ve;case lt.TYPE:return new lt;case We.TYPE:return new We;default:throw new Error(`Unknown error type: ${r.data}`)}};Uo({encode:ef,decode:tf});let Yo=class{constructor(){B(this,"middleware",[])}use(...r){this.middleware.push(...r)}async executeMiddleware(r,e){let t=0;const s=async n=>{if(t===this.middleware.length)return await e(n);const a=this.middleware[t];return t++,await a(n,s)};return await s(r)}};const Fo="Content-Type",Qi=r=>{if(Do.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(r==="http")return e;const t=require("https"),s=new t.Agent({rejectUnauthorized:!1});return async(n,a)=>await e(n,{...a,agent:s})};class rf extends Yo{constructor(e,t,s=!1){return super(),B(this,"endpoint"),B(this,"encoder"),B(this,"fetch"),this.endpoint=e.replace({protocol:s?"https":"http"}),this.encoder=t,this.fetch=Qi(this.endpoint.protocol),new Proxy(this,{get:(n,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(n,a,o)})}get headers(){return{[Fo]:this.encoder.contentType}}async send(e,t,s,n){t=s==null?void 0:s.parse(t);let a=null;const o=this.endpoint.child(e),u={};u.method="POST",u.body=this.encoder.encode(t??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async d=>{const f={...d,params:{}};u.headers={...this.headers,...d.params};let h;try{h=await Qi(d.protocol)(d.target,u)}catch(D){let ue=D;return ue.message==="Load failed"&&(ue=new We({url:o})),[f,ue]}const I=await h.arrayBuffer();if(h!=null&&h.ok)return n!=null&&(a=this.encoder.decode(I,n)),[f,null];try{if(h.status!==400)return[f,new Error(h.statusText)];const D=this.encoder.decode(I,lr),ue=os(D);return[f,ue]}catch(D){return[f,new Error(`[freighter] - failed to decode error: ${h.statusText}: ${D.message}`)]}});return[a,l]}}const sf=(r,e)=>{class t{constructor(n){B(this,"wrapped"),this.wrapped=n}use(...n){this.wrapped.use(...n)}async send(n,a,o,u){const l=Jd.create(e);do{const[d,f]=await this.wrapped.send(n,a,o,u);if(f==null||!We.matches(f))return[d,f];if(!await l())return[d,f]}while(!0)}}return new t(r)},O=async(r,e,t,s,n)=>{const[a,o]=await r.send(e,t,s,n);if(o!=null)throw o;return a},nf=()=>Do.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),af=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close"),i.z.literal("open")]),payload:i.z.unknown().optional(),error:i.z.optional(lr)});class of{constructor(e,t,s,n){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=t,this.reqSchema=s,this.resSchema=n,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return os(e.error)}return null}send(e){if(this.serverClosed!=null)return new Ve;if(this.sendClosed)throw new lt;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=os(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,t)=>this.receiveCallbacksQueue.push({resolve:e,reject:t}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,af)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:df(e)?Ve.TYPE:lt.TYPE,data:""}})}}const lf="freighterctx",uf=1e3,cf=1001,hf=[uf,cf],df=r=>hf.includes(r.code),Go=class Vo extends Yo{constructor(e,t,s=!1){super(),B(this,"baseUrl"),B(this,"encoder"),this.baseUrl=e.replace({protocol:s?"wss":"ws"}),this.encoder=t}async stream(e,t,s){const n=nf();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async u=>{const l=n(this.buildURL(e,u)),d={...u,params:{}};l.binaryType=Vo.MESSAGE_TYPE;const f=await this.wrapSocket(l,t,s);return f instanceof Error?[d,f]:(a=f,[d,null])});if(o!=null)throw o;return a}buildURL(e,t){const s=qd({[Fo]:this.encoder.contentType,...t.params},lf);return this.baseUrl.child(e).toString()+s}async wrapSocket(e,t,s){return await new Promise(n=>{e.onopen=()=>{const a=new of(e,this.encoder,t,s);a.receiveOpenAck().then(o=>{o!=null?n(o):n(a)}).catch(o=>n(o))},e.onerror=a=>{const o=a;n(new Error(o.message))}})}};B(Go,"MESSAGE_TYPE","arraybuffer");let ff=Go;const In=i.z.union([i.z.literal("all"),i.z.literal("create"),i.z.literal("delete"),i.z.literal("retrieve"),i.z.literal("update")]),pf=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Wo=r=>{const e=(t,s=xn)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,s));if(!_s(t))return t;s=mf(s);const n={},a=t;return Object.keys(a).forEach(o=>{let u=a[o];const l=r(o);s.recursive&&(_s(u)?ta(u,s.keepTypesOnRecursion)||(u=e(u,s)):s.recursiveInArray&&ea(u)&&(u=[...u].map(d=>{let f=d;return _s(d)?ta(f,s.keepTypesOnRecursion)||(f=e(d,s)):ea(d)&&(f=e({key:d},s).key),f}))),n[l]=u}),n};return e},Zo=Wo(pf),gf=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,s)=>`${t}_${s.toLowerCase()}`),yf=Wo(gf),xn={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},mf=(r=xn)=>(r.recursive==null?r=xn:r.recursiveInArray??(r.recursiveInArray=!1),r),ea=r=>r!=null&&Array.isArray(r),_s=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ta=(r,e)=>(e||[]).some(t=>r instanceof t),Hn=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var wf=Object.defineProperty,bf=(r,e,t)=>e in r?wf(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Jt=(r,e,t)=>bf(r,typeof e!="symbol"?e+"":e,t);let Jo=class{constructor(){Jt(this,"contentType","application/json"),Jt(this,"decoder"),Jt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(r){return this.encoder.encode(this.encodeString(r)).buffer}decode(r,e){return this.decodeString(this.decoder.decode(r),e)}decodeString(r,e){const t=JSON.parse(r),s=Zo(t);return e!=null?e.parse(s):s}encodeString(r){const e=yf(r);return JSON.stringify(e,(t,s)=>ArrayBuffer.isView(s)?Array.from(s):Hn(s)&&"encode_value"in s?typeof s.value=="bigint"?s.value.toString():s.value:typeof s=="bigint"?s.toString():s)}static registerCustomType(){}},Ko=class{constructor(){Jt(this,"contentType","text/csv")}encode(r){const e=this.encodeString(r);return new TextEncoder().encode(e).buffer}decode(r,e){const t=new TextDecoder().decode(r);return this.decodeString(t,e)}encodeString(r){if(!Array.isArray(r)||r.length===0||!Hn(r[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(r[0]),t=[e.join(",")];return r.forEach(s=>{const n=e.map(a=>JSON.stringify(s[a]??""));t.push(n.join(","))}),t.join(`
|
|
28
|
+
`)}decodeString(r,e){const[t,...s]=r.trim().split(`
|
|
29
|
+
`).map(o=>o.trim());if(t.length===0)return e!=null?e.parse({}):{};const n=t.split(",").map(o=>o.trim()),a={};return n.forEach(o=>{a[o]=[]}),s.forEach(o=>{const u=o.split(",").map(l=>l.trim());n.forEach((l,d)=>{const f=this.parseValue(u[d]);f!=null&&a[l].push(f)})}),e!=null?e.parse(a):a}parseValue(r){if(r==null||r.length===0)return null;const e=Number(r);return isNaN(e)?r.startsWith('"')&&r.endsWith('"')?r.slice(1,-1):r:e}static registerCustomType(){}},Ho=class{constructor(){Jt(this,"contentType","text/plain")}encode(r){return new TextEncoder().encode(r).buffer}decode(r,e){const t=new TextDecoder().decode(r);return e!=null?e.parse(t):t}};const at=new Jo,vf=new Ko,Of=new Ho,Tf=[at],gt=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ko,CSV_CODEC:vf,ENCODERS:Tf,JSONCodec:Jo,JSON_CODEC:at,TEXT_CODEC:Of,TextCodec:Ho},Symbol.toStringTag,{value:"Module"})),Sf=r=>[...new Set(r)],zf=(r,e,t=!0)=>{const s=new Map;return r.forEach(n=>{const a=e(n);if(s.has(a)){if(t)return;s.delete(a)}s.set(a,n)}),Array.from(s.values())},ra=Object.freeze(Object.defineProperty({__proto__:null,by:zf,unique:Sf},Symbol.toStringTag,{value:"Module"})),Nf=r=>r!=null&&typeof r=="object"&&"toString"in r,Ef=(r,e=!1)=>{const t=Nf(r)?"stringer":typeof r;let s;switch(t){case"string":s=(n,a)=>n.localeCompare(a);break;case"stringer":s=(n,a)=>n.toString().localeCompare(a.toString());break;case"number":s=(n,a)=>Number(n)-Number(a);break;case"bigint":s=(n,a)=>BigInt(n)-BigInt(a)>0n?1:-1;break;case"boolean":s=(n,a)=>Number(n)-Number(a);break;case"undefined":s=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?If(s):s},If=r=>(e,t)=>r(t,e),vs=0,qs=-1,Ys=1,xf=r=>r<vs,Af=r=>r>vs,kf=r=>r===vs,Os=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const Xo=i.z.object({width:i.z.number(),height:i.z.number()}),Cf=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Rf=["width","height"];i.z.enum(Rf);const $f=["start","center","end"],Mf=["signedWidth","signedHeight"];i.z.enum(Mf);const ls=i.z.object({x:i.z.number(),y:i.z.number()}),Df=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),Bf=["x","y"],Qo=i.z.enum(Bf),el=["top","right","bottom","left"];i.z.enum(el);const jf=["left","right"],tl=i.z.enum(jf),Pf=["top","bottom"],rl=i.z.enum(Pf),sl=["center"],sa=i.z.enum(sl),Uf=[...el,...sl],nl=i.z.enum(Uf);i.z.enum($f);const Lf=["first","last"];i.z.enum(Lf);const _f=i.z.object({lower:i.z.number(),upper:i.z.number()}),qf=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([_f,Os]);i.z.union([qf,Os]);i.z.union([Qo,nl]);i.z.union([Qo,nl,i.z.instanceof(String)]);const yt=r=>typeof r=="bigint"||r instanceof BigInt,Fs=(r,e)=>yt(r)?r.valueOf()-BigInt(e.valueOf().valueOf()):r.valueOf()-Number(e.valueOf()),Yf=(r,e)=>yt(r)?r.valueOf()+BigInt(e.valueOf().valueOf()):r+Number(e.valueOf()),na=(r,e)=>yt(r)?r===BigInt(e.valueOf().valueOf()):r===Number(e.valueOf()),Ff=(r,e)=>yt(r)?r.valueOf()<BigInt(e.valueOf())?r:BigInt(e.valueOf()):r.valueOf()<Number(e.valueOf())?r:Number(e.valueOf()),Gf=r=>yt(r)||r instanceof BigInt?r.valueOf()<0n?-r:r:r.valueOf()<0?-r:r,st=(r,e)=>yt(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),ye=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ia(r);return ia(t)},ia=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,aa=(r,e)=>{const t=ye(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},br=(r,e)=>{const t=ye(r);if(typeof e=="number"||typeof e=="bigint")return e>=t.lower&&e<t.upper;const s=ye(e);return s.lower>=t.lower&&s.upper<=t.upper},Vf=(r,e,t)=>{const s=r.map(u=>ye(u)),n=t>0?1:t<0?-1:0;if(n===0)return e;let a=t,o=e;for(;na(a,0)===!1;){const u=s.findIndex(l=>n>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(u!==-1){const l=s[u];let d;if(n>0?d=Fs(l.upper,o):d=Fs(o,l.lower),d>0){const f=Ff(Gf(a),d);if(o=Yf(o,n>0?f:-f),a=Fs(a,n>0?f:-f),na(a,0))return o;continue}}if(n>0){const l=s.filter(d=>d.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=s.filter(d=>d.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},Wf=(r,e,t)=>{const s=r.map(o=>ye(o));if(e===t)return typeof e=="bigint"?0n:0;const n=e<t?ye([e,t]):ye([t,e]);let a=typeof e=="bigint"?0n:0;for(const o of s){const u=o.lower>n.lower?o.lower:n.lower,l=o.upper<n.upper?o.upper:n.upper;if(u<l){const d=l-u;a=a+d}}return a};i.z.object({x:tl.or(sa),y:rl.or(sa)});const Zf=i.z.object({x:tl,y:rl}),Jf=Object.freeze({x:"left",y:"top"}),Kf=(r,e)=>r.x===e.x&&r.y===e.y,oa=i.z.union([i.z.number(),ls,Os,Xo,Cf,Df]),Hf=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},la=Object.freeze({x:0,y:0}),vr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:vr,left:vr,width:vr,height:vr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ls,two:ls,root:Zf});const Xn=(r,e,t=0,s=0,n)=>{const a={one:{...la},two:{...la},root:n??Jf};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+s},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:n??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+s}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Gs=r=>{const e=Xn(r);return{lower:e.one.x,upper:e.two.x}},Vs=r=>{const e=Xn(r);return{lower:e.one.y,upper:e.two.y}},Xf=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Qf=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Xo,Qf,ls,Os]);var ep=Object.defineProperty,tp=(r,e,t)=>e in r?ep(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Pe=(r,e,t)=>tp(r,typeof e!="symbol"?e+"":e,t);const rp=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:oa,scale:oa});i.z.object({offset:i.z.number(),scale:i.z.number()});const sp=r=>(e,t,s,n)=>t==="dimension"?[e,s]:[e,n?s-r:s+r],np=r=>(e,t,s,n)=>[e,n?s/r:s*r],ip=r=>(e,t,s)=>{if(e===null)return[r,s];const{lower:n,upper:a}=e,{lower:o,upper:u}=r,l=a-n,d=u-o;if(t==="dimension")return[r,s*(d/l)];const f=(s-n)*(d/l)+o;return[r,f]},ap=r=>(e,t,s)=>[r,s],op=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:s,upper:n}=r;return[r,n-(t-s)]},lp=r=>(e,t,s)=>{const{lower:n,upper:a}=r;return s=rp(s,n,a),[e,s]},An=class jt{constructor(){Pe(this,"ops",[]),Pe(this,"currBounds",null),Pe(this,"currType",null),Pe(this,"reversed",!1),this.ops=[]}static translate(e){return new jt().translate(e)}static magnify(e){return new jt().magnify(e)}static scale(e,t){return new jt().scale(e,t)}translate(e){const t=this.new(),s=sp(e);return s.type="translate",t.ops.push(s),t}magnify(e){const t=this.new(),s=np(e);return s.type="magnify",t.ops.push(s),t}scale(e,t){const s=ye(e,t),n=this.new(),a=ip(s);return a.type="scale",n.ops.push(a),n}clamp(e,t){const s=ye(e,t),n=this.new(),a=lp(s);return a.type="clamp",n.ops.push(a),n}reBound(e,t){const s=ye(e,t),n=this.new(),a=ap(s);return a.type="re-bound",n.ops.push(a),n}invert(){const e=op();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new jt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([s,n],a)=>a(s,e,n,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((s,n)=>{if(s.type==="scale"||t.some(([o,u])=>n>=o&&n<=u))return;const a=e.ops.findIndex((o,u)=>o.type==="scale"&&u>n);a!==-1&&t.push([n,a])}),t.forEach(([s,n])=>{const a=e.ops.slice(s,n);a.unshift(e.ops[n]),e.ops.splice(s,n-s+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};Pe(An,"IDENTITY",new An);let ua=An;const ca=class Be{constructor(e=new ua,t=new ua,s=null){Pe(this,"x"),Pe(this,"y"),Pe(this,"currRoot"),this.x=e,this.y=t,this.currRoot=s}static translate(e,t){return new Be().translate(e,t)}static translateX(e){return new Be().translateX(e)}static translateY(e){return new Be().translateY(e)}static clamp(e){return new Be().clamp(e)}static magnify(e){return new Be().magnify(e)}static scale(e){return new Be().scale(e)}static reBound(e){return new Be().reBound(e)}translate(e,t){const s=Hf(e,t),n=this.copy();return n.x=this.x.translate(s.x),n.y=this.y.translate(s.y),n}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(Xf(e)){const s=this.currRoot;return t.currRoot=e.root,s!=null&&!Kf(s,e.root)&&(s.x!==e.root.x&&(t.x=t.x.invert()),s.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(Gs(e)),t.y=t.y.scale(Vs(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(Gs(e)),t.y=this.y.reBound(Vs(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(Gs(e)),t.y=this.y.clamp(Vs(e)),t}copy(){const e=new Be;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 Xn(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})}}};Pe(ca,"IDENTITY",new ca);const up=i.z.bigint().or(i.z.string().transform(BigInt));var cp=Object.defineProperty,hp=(r,e,t)=>e in r?cp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,y=(r,e,t)=>hp(r,typeof e!="symbol"?e+"":e,t);let dp=(r,e=21)=>(t=e)=>{let s="",n=t|0;for(;n--;)s+=r[Math.random()*r.length|0];return s};const fp="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",il=dp(fp,11),pp=Object.freeze(Object.defineProperty({__proto__:null,id:il},Symbol.toStringTag,{value:"Module"})),gp=i.z.enum(["static","dynamic"]),al=(r,e)=>{const t=new $(e);if(![x.DAY,x.HOUR,x.MINUTE,x.SECOND,x.MILLISECOND,x.MICROSECOND,x.NANOSECOND].some(n=>n.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const s=r.valueOf()%t.valueOf();return r instanceof $?new $(s):new x(s)},F=class E{constructor(e,t="UTC"){if(y(this,"value"),y(this,"encodeValue",!0),e==null)this.value=E.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*E.MILLISECOND.valueOf();else if(typeof e=="string")this.value=E.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=E.parseDate(e);else{let s=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(s=E.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=E.MAX:e=E.MIN)),this.value=BigInt(e.valueOf())+s}}static parseDate([e=1970,t=1,s=1]){const n=new Date(e,t-1,s,0,0,0,0);return new E(BigInt(n.getTime())*E.MILLISECOND.valueOf()).truncate(E.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[s,n,a]=e.split(":");let o="00",u="00";a!=null&&([o,u]=a.split("."));let l=E.hours(parseInt(s??"00")).add(E.minutes(parseInt(n??"00"))).add(E.seconds(parseInt(o??"00"))).add(E.milliseconds(parseInt(u??"00")));return t==="local"&&(l=l.add(E.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return E.parseTimeString(e,t);const s=new Date(e);return e.includes(":")||s.setUTCHours(0,0,0,0),new E(BigInt(s.getTime())*E.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(E.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const s=this.toISOString(t);return e?s.slice(11,23):s.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),s=e.toLocaleString("default",{day:"numeric"});return`${t} ${s}`}static get utcOffset(){return new x(BigInt(new Date().getTimezoneOffset())*E.MINUTE.valueOf())}static since(e){return new E().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new E(e).valueOf()}span(e){return this.range(e).span}range(e){return new oe(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new E(e).valueOf()}afterEq(e){return this.valueOf()>=new E(e).valueOf()}before(e){return this.valueOf()<new E(e).valueOf()}beforeEq(e){return this.valueOf()<=new E(e).valueOf()}add(e){return new E(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new E(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(x.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(x.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(x.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(x.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new E(t)}get month(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setMonth(e),new E(t)}get day(){return this.date().getDate()}setDay(e){const t=this.date();return t.setDate(e),new E(t)}get hour(){return this.date().getHours()}setHour(e){const t=this.date();return t.setHours(e),new E(t)}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setMinutes(e),new E(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setSeconds(e),new E(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new E(t)}toString(){return this.date().toISOString()}remainder(e){return al(this,e)}get isToday(){return this.truncate(x.DAY).equals(E.now().truncate(x.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new E(new Date)}static max(...e){let t=E.MIN;for(const s of e){const n=new E(s);n.after(t)&&(t=n)}return t}static min(...e){let t=E.MAX;for(const s of e){const n=new E(s);n.before(t)&&(t=n)}return t}static nanoseconds(e){return new E(e)}static microseconds(e){return E.nanoseconds(e*1e3)}static milliseconds(e){return E.microseconds(e*1e3)}static seconds(e){return E.milliseconds(e*1e3)}static minutes(e){return E.seconds(e*60)}static hours(e){return E.minutes(e*60)}static days(e){return E.hours(e*24)}};y(F,"NANOSECOND",F.nanoseconds(1)),y(F,"MICROSECOND",F.microseconds(1)),y(F,"MILLISECOND",F.milliseconds(1)),y(F,"SECOND",F.seconds(1)),y(F,"MINUTE",F.minutes(1)),y(F,"HOUR",F.hours(1)),y(F,"DAY",F.days(1)),y(F,"MAX",new F((1n<<63n)-1n)),y(F,"MIN",new F(0)),y(F,"ZERO",new F(0)),y(F,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new F(r.value)),i.z.string().transform(r=>new F(BigInt(r))),i.z.instanceof(Number).transform(r=>new F(r)),i.z.number().transform(r=>new F(r)),i.z.instanceof(F)]));let $=F;const G=class C{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 C?e:e instanceof Qt?e.period:e instanceof $?new C(e):["number","bigint"].includes(typeof e)?C.seconds(e):new C(e)}static fromMilliseconds(e){return e instanceof C?e:e instanceof Qt?e.period:e instanceof $?new C(e):["number","bigint"].includes(typeof e)?C.milliseconds(e):new C(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new C(e).valueOf()}greaterThan(e){return this.valueOf()>new C(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new C(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new C(e).valueOf()}remainder(e){return al(this,e)}truncate(e){return new C(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(C.DAY),t=this.truncate(C.HOUR),s=this.truncate(C.MINUTE),n=this.truncate(C.SECOND),a=this.truncate(C.MILLISECOND),o=this.truncate(C.MICROSECOND),u=this.truncate(C.NANOSECOND),l=e,d=t.sub(e),f=s.sub(t),h=n.sub(s),I=a.sub(n),D=o.sub(a),ue=u.sub(o);let j="";return l.isZero||(j+=`${l.days}d `),d.isZero||(j+=`${d.hours}h `),f.isZero||(j+=`${f.minutes}m `),h.isZero||(j+=`${h.seconds}s `),I.isZero||(j+=`${I.milliseconds}ms `),D.isZero||(j+=`${D.microseconds}µs `),ue.isZero||(j+=`${ue.nanoseconds}ns`),j.trim()}mult(e){return new C(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(C.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(C.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new C(e).valueOf()}add(e){return new C(this.valueOf()+new C(e).valueOf())}sub(e){return new C(this.valueOf()-new C(e).valueOf())}static nanoseconds(e=1){return new C(e)}static microseconds(e=1){return C.nanoseconds(st(e,1e3))}static milliseconds(e=1){return C.microseconds(st(e,1e3))}static seconds(e=1){return C.milliseconds(st(e,1e3))}static minutes(e=1){return C.seconds(st(e,60))}static hours(e){return C.minutes(st(e,60))}static days(e){return C.hours(st(e,24))}};y(G,"NANOSECOND",G.nanoseconds(1)),y(G,"MICROSECOND",G.microseconds(1)),y(G,"MILLISECOND",G.milliseconds(1)),y(G,"SECOND",G.seconds(1)),y(G,"MINUTE",G.minutes(1)),y(G,"HOUR",G.hours(1)),y(G,"DAY",G.days(1)),y(G,"MAX",new G((1n<<63n)-1n)),y(G,"MIN",new G(0)),y(G,"ZERO",new G(0)),y(G,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new G(r.value)),i.z.string().transform(r=>new G(BigInt(r))),i.z.instanceof(Number).transform(r=>new G(r)),i.z.number().transform(r=>new G(r)),i.z.instanceof(G)]));let x=G;const Pt=class Pr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Pr(e).valueOf()}get period(){return x.seconds(1/this.valueOf())}sampleCount(e){return new x(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new ge(t).valueOf()}span(e){return x.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new Pr(e)}static khz(e){return Pr.hz(e*1e3)}};y(Pt,"z",i.z.union([i.z.number().transform(r=>new Pt(r)),i.z.instanceof(Number).transform(r=>new Pt(r)),i.z.instanceof(Pt)]));let Qt=Pt;const ae=class extends Number{constructor(r){r instanceof Number?super(r.valueOf()):super(r)}length(r){return r.valueOf()/this.valueOf()}size(r){return new ut(r*this.valueOf())}};y(ae,"UNKNOWN",new ae(0)),y(ae,"BIT128",new ae(16)),y(ae,"BIT64",new ae(8)),y(ae,"BIT32",new ae(4)),y(ae,"BIT16",new ae(2)),y(ae,"BIT8",new ae(1)),y(ae,"z",i.z.union([i.z.number().transform(r=>new ae(r)),i.z.instanceof(Number).transform(r=>new ae(r)),i.z.instanceof(ae)]));let ge=ae;const Ce=class Ur{constructor(e,t){y(this,"start"),y(this,"end"),typeof e=="object"&&"start"in e?(this.start=new $(e.start),this.end=new $(e.end)):(this.start=new $(e),this.end=new $(t))}get span(){return new x(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 Ur(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,t=x.ZERO){e=e.makeValid();const s=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(s.start)||s.end.equals(e.start))return!1;const n=$.max(s.start,e.start),a=$.min(s.end,e.end);return a.before(n)?!1:new x(a.sub(n)).greaterThanOrEqual(t)}roughlyEquals(e,t){let s=this.start.sub(e.start).valueOf(),n=this.end.sub(e.end).valueOf();return s<0&&(s=-s),n<0&&(n=-n),s<=t.valueOf()&&n<=t.valueOf()}contains(e){return e instanceof Ur?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new Ur(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}};y(Ce,"MAX",new Ce($.MIN,$.MAX)),y(Ce,"MIN",new Ce($.MAX,$.MIN)),y(Ce,"ZERO",new Ce($.ZERO,$.ZERO)),y(Ce,"z",i.z.union([i.z.object({start:$.z,end:$.z}).transform(r=>new Ce(r.start,r.end)),i.z.instanceof(Ce)]));let oe=Ce;const yp=(r,e)=>r.start.before(e.start)?-1:r.start.after(e.start)?1:r.end.before(e.end)?-1:r.end.after(e.end)?1:0,b=class X extends String{constructor(e){if(e instanceof X||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=X.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(X.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=X.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(X.JSON)||this.equals(X.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(X.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=X.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(X.UINT8)||this.equals(X.UINT16)||this.equals(X.UINT32)||this.equals(X.UINT64)}get isSigned(){return this.equals(X.INT8)||this.equals(X.INT16)||this.equals(X.INT32)||this.equals(X.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(X.INT32)&&e.equals(X.FLOAT64)||this.equals(X.INT8)&&e.equals(X.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!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 X.BIG_INT_TYPES.some(e=>e.equals(this))}};y(b,"UNKNOWN",new b("unknown")),y(b,"FLOAT64",new b("float64")),y(b,"FLOAT32",new b("float32")),y(b,"INT64",new b("int64")),y(b,"INT32",new b("int32")),y(b,"INT16",new b("int16")),y(b,"INT8",new b("int8")),y(b,"UINT64",new b("uint64")),y(b,"UINT32",new b("uint32")),y(b,"UINT16",new b("uint16")),y(b,"UINT8",new b("uint8")),y(b,"BOOLEAN",b.UINT8),y(b,"TIMESTAMP",new b("timestamp")),y(b,"UUID",new b("uuid")),y(b,"STRING",new b("string")),y(b,"JSON",new b("json")),y(b,"ARRAY_CONSTRUCTORS",new Map([[b.UINT8.toString(),Uint8Array],[b.UINT16.toString(),Uint16Array],[b.UINT32.toString(),Uint32Array],[b.UINT64.toString(),BigUint64Array],[b.FLOAT32.toString(),Float32Array],[b.FLOAT64.toString(),Float64Array],[b.INT8.toString(),Int8Array],[b.INT16.toString(),Int16Array],[b.INT32.toString(),Int32Array],[b.INT64.toString(),BigInt64Array],[b.TIMESTAMP.toString(),BigInt64Array],[b.STRING.toString(),Uint8Array],[b.JSON.toString(),Uint8Array],[b.UUID.toString(),Uint8Array]])),y(b,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,b.UINT8],[Uint16Array.name,b.UINT16],[Uint32Array.name,b.UINT32],[BigUint64Array.name,b.UINT64],[Float32Array.name,b.FLOAT32],[Float64Array.name,b.FLOAT64],[Int8Array.name,b.INT8],[Int16Array.name,b.INT16],[Int32Array.name,b.INT32],[BigInt64Array.name,b.INT64]])),y(b,"DENSITIES",new Map([[b.UINT8.toString(),ge.BIT8],[b.UINT16.toString(),ge.BIT16],[b.UINT32.toString(),ge.BIT32],[b.UINT64.toString(),ge.BIT64],[b.FLOAT32.toString(),ge.BIT32],[b.FLOAT64.toString(),ge.BIT64],[b.INT8.toString(),ge.BIT8],[b.INT16.toString(),ge.BIT16],[b.INT32.toString(),ge.BIT32],[b.INT64.toString(),ge.BIT64],[b.TIMESTAMP.toString(),ge.BIT64],[b.STRING.toString(),ge.UNKNOWN],[b.JSON.toString(),ge.UNKNOWN],[b.UUID.toString(),ge.BIT128]])),y(b,"ALL",[b.UNKNOWN,b.FLOAT64,b.FLOAT32,b.INT64,b.INT32,b.INT16,b.INT8,b.UINT64,b.UINT32,b.UINT16,b.UINT8,b.TIMESTAMP,b.UUID,b.STRING,b.JSON]),y(b,"BIG_INT_TYPES",[b.INT64,b.UINT64,b.TIMESTAMP]),y(b,"z",i.z.union([i.z.string().transform(r=>new b(r)),i.z.instanceof(b)]));let R=b;const de=class re extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return re.bytes(this.valueOf()+e.valueOf())}sub(e){return re.bytes(this.valueOf()-e.valueOf())}truncate(e){return new re(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return re.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/re.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/re.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/re.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/re.TERABYTE.valueOf()}toString(){const e=this.truncate(re.TERABYTE),t=this.truncate(re.GIGABYTE),s=this.truncate(re.MEGABYTE),n=this.truncate(re.KILOBYTE),a=this.truncate(re.BYTE),o=e,u=t.sub(e),l=s.sub(t),d=n.sub(s),f=a.sub(n);let h="";return o.isZero||(h+=`${o.terabytes}TB `),u.isZero||(h+=`${u.gigabytes}GB `),l.isZero||(h+=`${l.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new re(e)}static kilobytes(e=1){return re.bytes(e.valueOf()*1e3)}static megabytes(e=1){return re.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return re.megabytes(e.valueOf()*1e3)}static terabytes(e){return re.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};y(de,"BYTE",new de(1)),y(de,"KILOBYTE",de.kilobytes(1)),y(de,"MEGABYTE",de.megabytes(1)),y(de,"GIGABYTE",de.gigabytes(1)),y(de,"TERABYTE",de.terabytes(1)),y(de,"ZERO",new de(0)),y(de,"z",i.z.union([i.z.number().transform(r=>new de(r)),i.z.instanceof(de)]));let ut=de;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const ol=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof $||r instanceof x||r instanceof Date},mp=(r,e,t,s=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(s):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(s.valueOf()):Lt(t,-s).valueOf(),wp=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof He?!0:ol(r),qe=-1,kn={[Symbol.iterator]:()=>kn,next:()=>({done:!0,value:void 0})},bp=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),vp=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Cn=10,Ut=class Re{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",qe),y(this,"_refCount",0),y(this,"_cachedLength"),y(this,"_cachedIndexes"),wp(e)&&(e={data:e});const{dataType:t,timeRange:s,sampleOffset:n=0,glBufferUsage:a="static",alignment:o=0n,key:u=il()}=e,l=e.data??[];if(l instanceof Re||typeof l=="object"&&"isSynnaxSeries"in l&&l.isSynnaxSeries===!0){const h=l;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this._timeRange=h._timeRange,this.alignment=h.alignment,this._cachedMin=h._cachedMin,this._cachedMax=h._cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this._cachedLength=h._cachedLength;return}const d=ol(l),f=Array.isArray(l);if(t!=null)this.dataType=new R(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=l;if(!d){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=l[0]}if(typeof h=="string")this.dataType=R.STRING;else if(typeof h=="number")this.dataType=R.FLOAT64;else if(typeof h=="bigint")this.dataType=R.INT64;else if(typeof h=="boolean")this.dataType=R.BOOLEAN;else if(h instanceof $||h instanceof Date||h instanceof $)this.dataType=R.TIMESTAMP;else if(typeof h=="object")this.dataType=R.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new R(l)}if(!f&&!d)this._data=l;else{let h=d?[l]:l;const I=h[0];(I instanceof $||I instanceof Date||I instanceof x)&&(h=h.map(D=>new $(D).valueOf())),this.dataType.equals(R.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
|
|
30
|
+
`)}
|
|
31
|
+
`).buffer):this.dataType.equals(R.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(D=>at.encodeString(D)).join(`
|
|
32
|
+
`)}
|
|
33
|
+
`).buffer):this._data=new this.dataType.Array(h).buffer}this.key=u,this.alignment=o,this.sampleOffset=n??0,this._timeRange=s,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...s}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const n=new new R(t).Array(e),a=new Re({data:n.buffer,dataType:t,...s});return a.writePos=0,a}static generateTimestamps(e,t,s){const n=s.spanRange(t.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(s.add(t.span(o)).valueOf());return new Re({data:a,dataType:R.TIMESTAMP,timeRange:n})}get refCount(){return this._refCount}static fromStrings(e,t){const s=new TextEncoder().encode(`${e.join(`
|
|
34
|
+
`)}
|
|
35
|
+
`);return new Re({data:s,dataType:R.STRING,timeRange:t})}static fromJSON(e,t){const s=new TextEncoder().encode(`${e.map(n=>at.encodeString(n)).join(`
|
|
36
|
+
`)}
|
|
37
|
+
`);return new Re({data:s,dataType:R.JSON,timeRange:t})}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===qe)return 0;const t=this.byteCapacity.valueOf()-this.writePos,s=e.subBytes(0,t);return this.writeToUnderlyingData(s),this.writePos+=s.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=s.length,this.calculateCachedLength()),s.length}writeFixed(e){if(this.writePos===qe)return 0;const t=this.capacity-this.writePos,s=e.sub(0,t);return this.writeToUnderlyingData(s),this._cachedLength=void 0,this.maybeRecomputeMinMax(s),this.writePos+=s.length,s.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===qe?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(`
|
|
38
|
+
`).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(),t=Array(this.length);for(let s=0;s<this.length;s++){const n=this.underlyingData.slice(s*e,(s+1)*e),a=Array.from(new Uint8Array(n.buffer),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[s]=a}return t}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
|
|
39
|
+
`).slice(0,-1).map(t=>e.parse(at.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new ut(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===qe?this.byteCapacity:this.dataType.isVariable?new ut(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===qe?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 t=[0];return this.data.forEach((s,n)=>{s===Cn&&(e++,t.push(n+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const s=new e.Array(this.length);for(let n=0;n<this.length;n++)s[n]=mp(this.dataType,e,this.data[n],t);return new Re({data:s.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(R.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}else{const e=this.data;this._cachedMax=e.reduce((t,s)=>t>s?t:s)}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()),Lt(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((t,s)=>t<s?t:s)}else{const e=this.data;this._cachedMin=e.reduce((t,s)=>t<s?t:s)}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()),Lt(this._cachedMin,this.sampleOffset))}get bounds(){return ye(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return Lt(this.max,-this.min)}atAlignment(e,t){const s=Number(e-this.alignment);if(s<0||s>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${s}`);return}return this.at(s,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const s=this.data[e];if(s==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return Lt(s,this.sampleOffset)}atVariable(e,t){let s=0,n=0;if(this._cachedIndexes!=null)s=this._cachedIndexes[e],n=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]===Cn){if(e===0){n=o;break}s=o+1,e--}if(n===0&&(n=this.data.length),s>=n||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(s,n);return this.dataType.equals(R.STRING)?new TextDecoder().decode(a):Zo(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,s=this.length-1;const n=Ef(e);for(;t<=s;){const a=Math.floor((t+s)/2),o=n(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:s=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(R.FLOAT32)&&!this.dataType.equals(R.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:s,prevBuffer:n}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==n)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==qe){n===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(n).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,s==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=qe}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:{lower:wa(this.alignmentBounds.lower),upper:wa(this.alignmentBounds.upper)},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 ye(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 Op(this);return this.dataType.equals(R.JSON)?new Tp(e):e}return new Sp(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ha(this,e,t??this.length)}subAlignmentIterator(e,t){return new ha(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const s=this.data.subarray(e,t);return new Re({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,s){if(t<=0&&(s==null||s>=this.length))return this;let n;return e?n=this.data.subarray(t,s):n=this.data.slice(t,s),new Re({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Re({data:this.buffer,dataType:this.dataType,timeRange:oe.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};y(Ut,"crudeZ",i.z.object({timeRange:oe.z.optional(),dataType:R.z,alignment:up.optional(),data:i.z.union([bp,vp,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:gp.optional().default("static").optional()})),y(Ut,"z",Ut.crudeZ.transform(r=>new Ut(r)));let He=Ut,ha=class{constructor(r,e,t){y(this,"series"),y(this,"end"),y(this,"index"),this.series=r;const s=ye(0,r.length);this.end=aa(s,t),this.index=aa(s,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 Op{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,t=this.series.data;for(;this.index<t.length&&t[this.index]!==Cn;)this.index++;const s=this.index;return e===s?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,s))})}[Symbol.iterator](){return this}}var da,fa;class Tp{constructor(e){y(this,"wrapped"),y(this,da,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:at.decodeString(e.value)}}[(fa=Symbol.iterator,da=Symbol.toStringTag,fa)](){return this}}var pa,ga;class Sp{constructor(e){y(this,"series"),y(this,"index"),y(this,pa,"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)}}[(ga=Symbol.iterator,pa=Symbol.toStringTag,ga)](){return this}}const Lt=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e);class zp{constructor(e){if(y(this,"series"),e.length!==0){const t=e[0].dataType;for(let s=1;s<e.length;s++)if(!e[s].dataType.equals(t))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?oe.ZERO:new oe(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?ye(0n,0n):ye(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,t)=>e+t.length,0)}atAlignment(e,t){if(this.series.length===0){if(t)throw new Error(`[series] - no value at alignment ${e}`);return}for(const s of this.series)if(br(s.alignmentBounds,e))return s.atAlignment(e,t);if(t)throw new Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(const s of this.series){if(e<s.length)return s.at(e,t);e-=s.length}if(t)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new Ws(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return kn;let s=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)s+=o.length;else if(br(o.alignmentBounds,e)){s+=Number(e-o.alignment);break}}let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)n+=o.length;else if(br(o.alignmentBounds,t)){n+=Number(t-o.alignment);break}}return new Ws(this,s,n)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return kn;let s=0;for(let n=0;n<this.series.length;n++){const a=this.series[n];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)s+=a.length;else if(br(a.alignmentBounds,e)){s+=Number(e-a.alignment);break}}return new Ws(this,s,s+t)}get byteLength(){return new ut(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let t=0;for(const s of this.series)e.set(s.data,t),t+=s.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){const s=this.series.map(n=>n.alignmentBounds);return Vf(s,e,t)}distance(e,t){const s=this.series.map(n=>n.alignmentBounds);return Wf(s,e,t)}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Np(this.series)}}var ya,ma;class Np{constructor(e){y(this,"series"),y(this,"seriesIndex"),y(this,"internal"),y(this,ya,"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())}[(ma=Symbol.iterator,ya=Symbol.toStringTag,ma)](){return this}}class Ws{constructor(e,t,s){y(this,"series"),y(this,"index"),y(this,"end"),this.series=e,this.end=s,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}const wa=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Ep=(r,e)=>{let t=null;return e===0?r:(...s)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...s),e)}};i.z.object({key:i.z.string(),value:i.z.string()});var Ip=Object.defineProperty,xp=(r,e,t)=>e in r?Ip(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Lr=(r,e,t)=>xp(r,typeof e!="symbol"?e+"":e,t);let Ap=class{constructor(r,e){Lr(this,"handlers"),Lr(this,"transform"),Lr(this,"closer"),this.transform=r,this.handlers=e??new Map}onChange(r){return this.handlers.set(r,null),()=>this.handlers.delete(r)}notify(r){let e=r;if(this.transform!=null){const[t,s]=this.transform(r);if(!s)return;e=t}this.handlers.forEach((t,s)=>s(e))}setCloser(r){this.closer=r}async close(){var r;return await((r=this.closer)==null?void 0:r.call(this))}},kp=class{constructor(r){Lr(this,"handlers"),this.handlers=r??new Map}onChange(r){return this.handlers.set(r,null),()=>this.handlers.delete(r)}notify(r){this.handlers.forEach((e,t)=>t(r))}};const et=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:kp,Observer:Ap},Symbol.toStringTag,{value:"Module"})),ur=i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown()),Cp=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Cp();const Rp=["MacOS","Windows","Linux","Docker"],$p=["macos","windows","linux","docker"],Mp={macos:"MacOS",windows:"Windows",linux:"Linux",docker:"Docker"};i.z.enum(Rp).or(i.z.enum($p).transform(r=>Mp[r]));var Dp=Object.defineProperty,Bp=(r,e,t)=>e in r?Dp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_t=(r,e,t)=>Bp(r,typeof e!="symbol"?e+"":e,t);const jp=(...r)=>r.map(ll).join(""),ll=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Pp=r=>r.endsWith("/")?r.slice(0,-1):r,Rn=class $n{constructor({host:e,port:t,protocol:s="",pathPrefix:n=""}){_t(this,"protocol"),_t(this,"host"),_t(this,"port"),_t(this,"path"),this.protocol=s,this.host=e,this.port=t,this.path=ll(n)}replace(e){return new $n({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new $n({...this,pathPrefix:jp(this.path,e)})}toString(){return Pp(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};_t(Rn,"UNKNOWN",new Rn({host:"unknown",port:0}));let Up=Rn;var Lp=Object.defineProperty,_p=(r,e,t)=>e in r?Lp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_r=(r,e,t)=>_p(r,typeof e!="symbol"?e+"":e,t);const qp=async r=>await new Promise(e=>setTimeout(e,x.fromMilliseconds(r).milliseconds)),Yp=i.z.object({interval:x.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Fp=(r={})=>{const e=r.sleepFn||qp,t=r.maxRetries??5,s=r.scale??1;let n=0,a=new x(r.interval??x.milliseconds(1));return async()=>n>=t?!1:(await e(a),a=a.mult(s),n++,!0)},Gp=Object.freeze(Object.defineProperty({__proto__:null,breakerConfig:Yp,create:Fp},Symbol.toStringTag,{value:"Module"})),Ke=class extends Number{};_r(Ke,"Absolute",255),_r(Ke,"Default",1),_r(Ke,"z",i.z.union([i.z.instanceof(Ke),i.z.number().int().min(0).max(255).transform(r=>new Ke(r)),i.z.instanceof(Number).transform(r=>new Ke(r))]));let ul=Ke;const cl=i.z.object({name:i.z.string(),key:i.z.string()}),Vp=r=>i.z.object({subject:cl,resource:r,authority:ul.z}),Wp=(...r)=>e=>e.filter(t=>{let s=!1;return t.to!=null&&(s=r.includes(t.to.resource)),t.from!=null&&!s&&(s=r.includes(t.from.resource)),s}),ct=Object.freeze(Object.defineProperty({__proto__:null,Authority:ul,filterTransfersByChannelKey:Wp,stateZ:Vp,subjectZ:cl},Symbol.toStringTag,{value:"Module"})),hl=class qt extends Error{constructor(){super(qt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(qt.MESSAGE):e instanceof qt||e.message.includes(qt.MESSAGE)}};_r(hl,"MESSAGE","canceled");let Zp=hl;new Zp;const Mn=i.z.string().regex(/^\d+\.\d+\.\d+$/),cr=(r,e,t={})=>{t.checkMajor??(t.checkMajor=!0),t.checkMinor??(t.checkMinor=!0),t.checkPatch??(t.checkPatch=!0);const s=Mn.parse(r),n=Mn.parse(e),[a,o,u]=s.split(".").map(Number),[l,d,f]=n.split(".").map(Number);if(t.checkMajor){if(a<l)return qs;if(a>l)return Ys}if(t.checkMinor){if(o<d)return qs;if(o>d)return Ys}if(t.checkPatch){if(u<f)return qs;if(u>f)return Ys}return vs},Jp=(r,e,t={})=>kf(cr(r,e,t)),dl=(r,e,t={})=>Af(cr(r,e,t)),Kp=(r,e,t={})=>xf(cr(r,e,t)),Hp=({name:r,migrate:e})=>t=>{try{const s=e(t);return console.log(`${r} migrated: ${t.version} -> ${s.version}`),s}catch(s){throw console.log(`${r} failed to migrate from ${t.version}`),console.error(s),s}},Xp=({name:r,migrations:e,targetSchema:t,defaultVersion:s,def:n})=>{const a=Object.keys(e).sort(cr).pop();if(a==null)return d=>{if(d.version??(d.version=s),d.version!==n.version)return console.log(`${r} version ${d.version} is newer than latest version of ${n.version}.
|
|
40
|
+
Returning default instead.
|
|
41
|
+
`),n;try{return t!=null?t.parse(d):d}catch(f){return console.log(`${r} failed to parse default. Exiting with default`),console.error(f),n}};const o=Object.keys(e).length;let u=!1;const l=d=>{try{if(o===0||dl(d.version,a))return console.log(u?`${r} ${d.version} now up to date`:`${r} version ${d.version} is up to date with target version ${n.version}`),d;const f=d.version,h=e[f],I=h(d);return u=!0,l(I)}catch(f){return console.log(`${r} failed to migrate from ${d.version} to ${a}`),console.error(f),n}};return d=>{try{if(d.version==null)if(s!=null)console.log(`${r} version is null. Setting version to default of ${s}`),d.version=s;else return console.log(`${r} version is null and no default version set. Exiting with default`),n;return l(d)}catch(f){return console.log(`${r} failed to parse final result. Exiting with default`),console.error(f),n}}},ba=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:cr,createMigration:Hp,migrator:Xp,semVerNewer:dl,semVerOlder:Kp,semVerZ:Mn,versionsEqual:Jp},Symbol.toStringTag,{value:"Module"})),Ze="sy.",qr=class fl extends Ee{constructor(){super(...arguments),c(this,"type",fl.TYPE)}};c(qr,"TYPE",`${Ze}validation`),c(qr,"matches",me(qr.TYPE));let Q=qr;const Yr=class pl extends Q{constructor(e,t){super(`${e}: ${t}`),c(this,"type",pl.TYPE),c(this,"field"),c(this,"message"),this.field=e,this.message=t}};c(Yr,"TYPE",`${Q.TYPE}.field`),c(Yr,"matches",me(Yr.TYPE));let va=Yr;const Fr=class gl extends Ee{constructor(){super(...arguments),c(this,"type",gl.TYPE)}};c(Fr,"TYPE",`${Ze}auth`),c(Fr,"matches",me(Fr.TYPE));let us=Fr;const Gr=class yl extends us{constructor(){super(...arguments),c(this,"type",yl.TYPE)}};c(Gr,"TYPE",`${us.TYPE}.invalid-token`),c(Gr,"matches",me(Gr.TYPE));let Dn=Gr;const Vr=class ml extends Ee{constructor(e){super(`
|
|
42
|
+
Unexpected error encountered:
|
|
43
|
+
|
|
44
|
+
${e}
|
|
45
|
+
|
|
46
|
+
Please report this to the Synnax team.
|
|
47
|
+
`),c(this,"type",ml.TYPE)}};c(Vr,"TYPE",`${Ze}unexpected`),c(Vr,"matches",me(Vr.TYPE));let Oe=Vr;const Wr=class wl extends Ee{constructor(){super(...arguments),c(this,"type",wl.TYPE)}};c(Wr,"TYPE",`${Ze}query`),c(Wr,"matches",me(Wr.TYPE));let Ne=Wr;const Zr=class bl extends Ne{constructor(){super(...arguments),c(this,"type",bl.TYPE)}};c(Zr,"TYPE",`${Ne.TYPE}.not_found`),c(Zr,"matches",me(Zr.TYPE));let ht=Zr;const Jr=class vl extends Ne{constructor(){super(...arguments),c(this,"type",vl.TYPE)}};c(Jr,"TYPE",`${Ne.TYPE}.multiple_results`),c(Jr,"matches",me(Jr.TYPE));let dt=Jr;const Kr=class Ol extends Ee{constructor(e,t){super(e),c(this,"type",Ol.TYPE),c(this,"path"),this.path=t}};c(Kr,"TYPE",`${Ze}route`),c(Kr,"matches",me(Kr.TYPE));let Oa=Kr;const Hr=class Tl extends Ee{constructor(){super(...arguments),c(this,"type",Tl.TYPE)}};c(Hr,"TYPE",`${Ze}control`),c(Hr,"matches",me(Hr.TYPE));let cs=Hr;const Xr=class Sl extends cs{constructor(){super(...arguments),c(this,"type",Sl.TYPE)}};c(Xr,"TYPE",`${cs.TYPE}.unauthorized`),c(Xr,"matches",me(Xr.TYPE));let Ta=Xr;const Zs=class zl extends Ee{constructor(){super(...arguments),c(this,"type",zl.TYPE)}};c(Zs,"TYPE",`${Ze}contiguity`),c(Zs,"matches",me(Zs.TYPE));const Qp=r=>{if(!r.type.startsWith(Ze))return null;if(r.type.startsWith(Q.TYPE)){if(r.type===va.TYPE){const e=r.data.split(": ");return e.length<2?new Q(r.data):new va(e[0],e[1])}return new Q(r.data)}return r.type.startsWith(us.TYPE)?r.type.startsWith(Dn.TYPE)?new Dn(r.data):new us(r.data):r.type.startsWith(Oe.TYPE)?new Oe(r.data):r.type.startsWith(Ne.TYPE)?r.type.startsWith(ht.TYPE)?new ht(r.data):r.type.startsWith(dt.TYPE)?new dt(r.data):new Ne(r.data):r.type.startsWith(cs.TYPE)?r.type.startsWith(Ta.TYPE)?new Ta(r.data):new cs(r.data):r.type.startsWith(Oa.TYPE)?new Oa(r.data,r.data):new Oe(r.data)},eg=()=>{throw new Error("Not implemented")};Uo({encode:eg,decode:Qp});const tg=async(r,e)=>{const[t,s]=await e(r);return s==null?[t,s]:s instanceof We?[t,new We({message:`Cannot reach cluster at ${s.url.host}:${s.url.port}`,url:s.url})]:[t,s]},rg=i.z.string().uuid(),Nl=i.z.object({key:rg,name:i.z.string()}),sg="group",ng=r=>new U({type:sg,key:r});class El{constructor(e,t){c(this,"key"),c(this,"name"),this.key=t,this.name=e}get ontologyID(){return ng(this.key)}}const Ts=i.z.union([i.z.literal("label"),i.z.literal("log"),i.z.literal("allow_all"),i.z.literal("builtin"),i.z.literal("cluster"),i.z.literal("channel"),i.z.literal("node"),i.z.literal("group"),i.z.literal("range"),i.z.literal("framer"),i.z.literal("range-alias"),i.z.literal("user"),i.z.literal("workspace"),i.z.literal("schematic"),i.z.literal("lineplot"),i.z.literal("rack"),i.z.literal("device"),i.z.literal("task"),i.z.literal("policy"),i.z.literal("table")]),ig="builtin",be=i.z.object({type:Ts,key:i.z.string()}),ag=i.z.string().transform(r=>{const[e,t]=r.split(":");return{type:Ts.parse(e),key:t??""}}),Yt=i.z.union([ag,be]),Qr=class Il{constructor(e){if(c(this,"type"),c(this,"key"),e instanceof Il){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[t,s]=e.split(":");this.type=t,this.key=s??"";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}}};c(Qr,"z",i.z.union([i.z.instanceof(Qr),Yt.transform(r=>new Qr(r))]));let U=Qr;new U({type:ig,key:"root"});const og=i.z.object({type:i.z.number()}),lg=i.z.object({type:Ts,fields:i.z.record(og)}),ug=i.z.object({id:U.z,name:i.z.string(),schema:lg.optional().nullable(),data:i.z.record(i.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r}));i.z.object({from:U.z,type:i.z.string(),to:U.z});const Sa=r=>{const[e,t,s]=r.split("->");return{from:new U(e),type:t,to:new U(s)}},cg=i.z.object({group:Nl}),hg=i.z.object({parent:be,key:i.z.string().uuid().optional(),name:i.z.string()}),dg=i.z.object({key:i.z.string(),name:i.z.string()}),fg=i.z.object({keys:i.z.array(i.z.string())});var Ye;let pg=(Ye=class{constructor(r){c(this,"client"),this.client=r}async create(r,e,t){return(await O(this.client,Ye.ENDPOINT,{parent:r,name:e,key:t},hg,cg)).group}async rename(r,e){await O(this.client,Ye.ENDPOINT_RENAME,{key:r,name:e},dg,i.z.object({}))}async delete(r){await O(this.client,Ye.ENDPOINT_DELETE,{keys:r},fg,i.z.object({}))}},c(Ye,"ENDPOINT","/ontology/create-group"),c(Ye,"ENDPOINT_RENAME","/ontology/rename-group"),c(Ye,"ENDPOINT_DELETE","/ontology/delete-group"),Ye),gg=class{constructor(r){c(this,"creator"),this.creator=new pg(r)}async create(r,e,t){return this.sugar(await this.creator.create(r,e,t))}async rename(r,e){return await this.creator.rename(r,e)}async delete(...r){return await this.creator.delete(r)}sugar(r){return new El(r.name,r.key)}};const Js={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},za=i.z.object({id:be,children:be.array()}),yg=i.z.object({from:be,to:be,children:be.array()});let mg=class{constructor(r){c(this,"client"),this.client=r}async addChildren(r,...e){await O(this.client,Js.ADD_CHILDREN,{id:new U(r).payload,children:e.map(t=>new U(t).payload)},za,i.z.object({}))}async removeChildren(r,...e){await O(this.client,Js.REMOVE_CHILDREN,{id:new U(r).payload,children:e.map(t=>new U(t).payload)},za,i.z.object({}))}async moveChildren(r,e,...t){const s={from:new U(r).payload,to:new U(e).payload,children:t.map(n=>new U(n).payload)};await O(this.client,Js.MOVE_CHILDREN,s,yg,i.z.object({}))}};const wg="/ontology/retrieve",bg=i.z.object({ids:be.array().optional(),children:i.z.boolean().optional(),parents:i.z.boolean().optional(),includeSchema:i.z.boolean().optional(),excludeFieldData:i.z.boolean().optional(),term:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),types:Ts.array().optional()}),vg=i.z.object({resources:ug.array()}),Ks=r=>S(r).map(e=>new U(e).payload);let Og=class{constructor(r,e){c(this,"type","ontology"),c(this,"groups"),c(this,"client"),c(this,"writer"),c(this,"framer"),this.client=r,this.writer=new mg(r),this.groups=new gg(r),this.framer=e}async search(r,e){return await this.execRetrieve({term:r,...e})}async retrieve(r,e){const t=await this.execRetrieve({ids:Ks(r),...e});if(Array.isArray(r))return t;if(t.length===0)throw new Ne(`No resource found with ID ${r.toString()}`);return t[0]}async page(r,e,t){return await this.execRetrieve({offset:r,limit:e,...t})}async retrieveChildren(r,e){return await this.execRetrieve({ids:Ks(r),children:!0,...e})}async retrieveParents(r,e){return await this.execRetrieve({ids:Ks(r),parents:!0,...e})}async addChildren(r,...e){return await this.writer.addChildren(r,...e)}async removeChildren(r,...e){return await this.writer.removeChildren(r,...e)}async moveChildren(r,e,...t){return await this.writer.moveChildren(r,e,...t)}async openChangeTracker(){return await Ss.open(this.framer,this)}async openDependentTracker(r){return await Qn.open(r,this.framer,this)}newSearcherWithOptions(r){return{type:this.type,search:e=>this.search(e,r),retrieve:e=>this.retrieve(e,r),page:(e,t)=>this.page(e,t,r)}}async execRetrieve(r){const{resources:e}=await O(this.client,wg,r,bg,vg);return e}};const Na="sy_ontology_resource_set",Ea="sy_ontology_resource_delete",Ia="sy_ontology_relationship_set",xa="sy_ontology_relationship_delete";class Ss{constructor(e,t){c(this,"relationships"),c(this,"resources"),c(this,"resourceObs"),c(this,"relationshipObs"),c(this,"streamer"),c(this,"client"),c(this,"closePromise"),this.relationshipObs=new et.Observer,this.relationships=this.relationshipObs,this.resourceObs=new et.Observer,this.resources=this.resourceObs,this.client=t,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 t=await this.parseResourceSets(e),s=this.parseResourceDeletes(e);t.concat(s).length>0&&this.resourceObs.notify(t.concat(s));const n=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);n.concat(a).length>0&&this.relationshipObs.notify(n.concat(a))}parseRelationshipSets(e){const t=e.get(Ia);return t.length===0?[]:Array.from(t.as("string")).map(s=>({variant:"set",key:Sa(s),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(xa);return t.length===0?[]:Array.from(t.as("string")).map(s=>({variant:"delete",key:Sa(s)}))}async parseResourceSets(e){const t=e.get(Na);if(t.length===0)return[];const s=Array.from(t.as("string")).map(n=>new U(n));try{return(await this.client.retrieve(s)).map(n=>({variant:"set",key:n.id,value:n}))}catch(n){if(n instanceof Ne)return[];throw n}}parseResourceDeletes(e){const t=e.get(Ea);return t.length===0?[]:Array.from(t.as("string")).map(s=>({variant:"delete",key:new U(s)}))}static async open(e,t){const s=await e.openStreamer([Na,Ea,Ia,xa]);return new Ss(s,t)}}const Aa=r=>r==="from"?"to":"from";class Qn extends et.Observer{constructor({target:e,dependents:t,relationshipType:s="parent",relationshipDirection:n="from",resourceType:a},o,u){super(),c(this,"internal"),c(this,"target"),c(this,"relDir"),c(this,"resourceType"),c(this,"dependents"),c(this,"client"),c(this,"relType"),c(this,"handleResourceChange",l=>{this.dependents=this.dependents.map(d=>{const f=l.find(h=>h.key.toString()==d.id.toString());return f==null||f.variant==="delete"?d:f.value}),this.notify(this.dependents)}),c(this,"handleRelationshipChange",l=>{const d=l.filter(h=>h.variant==="delete"&&h.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||h.key[Aa(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(h=>!d.some(I=>I.key.to.toString()===h.id.toString()&&I.key.type===this.relType));const f=l.filter(h=>h.variant==="set"&&h.key.type===this.relType&&h.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||h.key[Aa(this.relDir)].type===this.resourceType));if(f.length===0)return this.notify(this.dependents);this.client.retrieve(f.map(h=>h.key.to)).then(h=>{this.dependents=this.dependents.concat(h),this.notify(this.dependents)})}),this.resourceType=a,this.internal=o,this.target=e,this.dependents=t,this.resourceType!=null&&(this.dependents=this.dependents.filter(l=>l.id.type===this.resourceType)),this.client=u,this.relType=s,this.relDir=n,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(e,t,s){const n=await Ss.open(t,s);return new Qn(e,n,s)}async close(){await this.internal.close()}}const le=r=>i.z.union([i.z.union([i.z.null(),i.z.undefined()]).transform(()=>[]),r.array()]),zs=i.z.string().uuid(),Tg=i.z.object({key:zs.optional(),subjects:Yt.array().or(Yt),objects:Yt.array().or(Yt),actions:In.array().or(In)}),ei=i.z.object({key:zs,subjects:le(be),objects:le(be),actions:le(In)}),Sg="allow_all";new U({type:Sg,key:""});const zg=i.z.object({keys:zs.array().optional(),subjects:be.array().optional()}),Ng=i.z.object({policies:le(ei)}),Eg="/access/policy/retrieve";let Ig=class{constructor(r){c(this,"client"),this.client=r}async retrieve(r){return(await O(this.client,Eg,r,zg,Ng)).policies}};const xg=i.z.object({policies:ei.partial({key:!0}).array()}),Ag=i.z.object({policies:ei.array()}),kg=i.z.object({keys:zs.array()}),Cg=i.z.object({}),Rg="/access/policy/create",$g="/access/policy/delete";let Mg=class{constructor(r){c(this,"client"),this.client=r}async create(r){const e=Tg.array().parse(S(r)).map(t=>({objects:S(t.objects),actions:S(t.actions),subjects:S(t.subjects)}));return(await O(this.client,Rg,{policies:e},xg,Ag)).policies}async delete(r){await O(this.client,$g,{keys:S(r)},kg,Cg)}},Dg=class{constructor(r){c(this,"retriever"),c(this,"writer"),this.retriever=new Ig(r),this.writer=new Mg(r)}async create(r){const e=Array.isArray(r),t=await this.writer.create(r);return e?t:t[0]}async retrieve(r){const e=Array.isArray(r),t=await this.retriever.retrieve({keys:S(r)});return e?t:t[0]}async retrieveFor(r){const e=S(r).map(t=>new U(t).payload);return await this.retriever.retrieve({subjects:e})}async delete(r){await this.writer.delete(r)}},Bg=class{constructor(r){c(this,"policy"),this.policy=new Dg(r)}};const Me=i.z.number(),hr=i.z.object({name:i.z.string(),key:i.z.number(),rate:Qt.z,dataType:R.z,leaseholder:i.z.number(),index:i.z.number(),isIndex:i.z.boolean(),internal:i.z.boolean(),virtual:i.z.boolean(),alias:i.z.string().optional(),expression:i.z.string().default(""),requires:le(Me)}),xl=hr.extend({key:i.z.number().optional(),leaseholder:i.z.number().optional(),index:i.z.number().optional(),rate:Qt.z.optional().default(0),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional().default(!1),virtual:i.z.boolean().optional().default(!1),expression:i.z.string().optional().default(""),requires:le(Me).optional().default([])}),Al="channel",kl=r=>new U({type:Al,key:r.toString()}),jg=new Error("request for lock canceled");var Pg=function(r,e,t,s){function n(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function u(f){try{d(s.next(f))}catch(h){o(h)}}function l(f){try{d(s.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):n(f.value).then(u,l)}d((s=s.apply(r,e||[])).next())})};class Ug{constructor(e,t=jg){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,n)=>{const a={resolve:s,reject:n,weight:e,priority:t},o=Cl(this._queue,u=>t<=u.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Pg(this,arguments,void 0,function*(t,s=1,n=0){const[a,o]=yield this.acquire(s,n);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Lg(this._weightedWaiters[e-1],{resolve:s,priority:t})})}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 t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(s=>s.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const s=this._weightedWaiters[t-1];if(!s)continue;const n=s.findIndex(a=>a.priority<=e);(n===-1?s:s.splice(0,n)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function Lg(r,e){const t=Cl(r,s=>e.priority<=s.priority);r.splice(t+1,0,e)}function Cl(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var _g=function(r,e,t,s){function n(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function u(f){try{d(s.next(f))}catch(h){o(h)}}function l(f){try{d(s.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):n(f.value).then(u,l)}d((s=s.apply(r,e||[])).next())})};class qg{constructor(e){this._semaphore=new Ug(1,e)}acquire(){return _g(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}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 Ns=(r,e,{convertNumericStrings:t=!0}={})=>{const s=!Array.isArray(r);let n=S(r);const a=n[0],o=typeof a;let u;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(u=e.number,n=n.map(l=>parseInt(l))):u=e[o],{single:s,variant:u,normalized:n,actual:r}},Es=(r,e,t,s)=>{if(s){if(t.length===0)throw new ht(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new dt(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Yg=i.z.object({leaseholder:i.z.number().optional(),keys:i.z.number().array().optional(),names:i.z.string().array().optional(),search:i.z.string().optional(),rangeKey:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),dataTypes:R.z.array().optional(),notDataTypes:R.z.array().optional(),virtual:i.z.boolean().optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional()}),Fg=i.z.object({channels:le(hr)}),Ue=r=>Ns(r,{number:"keys",string:"names"}),Rl=class $l{constructor(e){c(this,"client"),this.client=e}async search(e,t){return await this.execute({search:e,...t})}async retrieve(e,t){const s=Ue(e),{variant:n}=s;let{normalized:a}=s;return n==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[n]:a,...t})}async page(e,t,s){return await this.execute({offset:e,limit:t,...s})}async execute(e){const[t,s]=await this.client.send($l.ENDPOINT,e,Yg,Fg);if(s!=null)throw s;return t.channels}};c(Rl,"ENDPOINT","/channel/retrieve");let ti=Rl;class ri{constructor(e){c(this,"cache"),c(this,"namesToKeys"),c(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,s){return await this.wrapped.page(e,t,s)}async retrieve(e,t){const{normalized:s}=Ns(e,{string:"names",number:"keys"}),n=[],a=[];if(s.forEach(u=>{const l=this.get(u);l!=null?n.push(...l):a.push(u)}),a.length===0)return n;const o=await this.wrapped.retrieve(a,t);return this.set(o),n.concat(o)}delete(e){const{variant:t,normalized:s}=Ue(e);t==="names"?s.forEach(n=>{const a=this.namesToKeys.get(n);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(n))}):s.forEach(n=>{const a=this.cache.get(n);a!=null&&(this.cache.delete(n),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((s,n)=>{const a=t[n],o=this.cache.get(s);if(o==null)return;this.cache.delete(s);const u=this.namesToKeys.get(o.name);u!=null&&(u.delete(s),u.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(s,o);const l=this.namesToKeys.get(a);l==null?this.namesToKeys.set(a,new Set([s])):l.add(s)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const s=this.namesToKeys.get(t.name);s==null?this.namesToKeys.set(t.name,new Set([t.key])):s.add(t.key)})}get(e){if(typeof e=="number"){const n=this.cache.get(e);return n==null?void 0:[n]}const t=this.namesToKeys.get(e);if(t==null)return;const s=[];if(t.forEach(n=>{const a=this.cache.get(n);a!=null&&s.push(a)}),s.length!==0)return s}}class Ml{constructor(e,t){c(this,"mu",new qg),c(this,"requests",new Map),c(this,"wrapped"),c(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=Ep(()=>{this.run()},t)}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,s){return await this.wrapped.page(e,t,s)}async retrieve(e){const{normalized:t,variant:s}=Ue(e);return s==="names"?await this.wrapped.retrieve(t):await new Promise((n,a)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:n,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,s)=>s.forEach(n=>e.add(n)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((s,n)=>s.resolve(t.filter(a=>n.includes(a.key))))}catch(t){this.requests.forEach(s=>s.reject(t))}finally{this.requests.clear()}})}}const Dl=async(r,e)=>{const{normalized:t}=Ue(e),s=await r.retrieve(t),n=[];if(t.forEach(a=>{s.find(o=>o.name===a||o.key===a)==null&&n.push(a)}),n.length>0)throw new Ne(`Could not find channels: ${JSON.stringify(n)}`);return s};class Bl{constructor({dataType:e,rate:t,name:s,leaseholder:n=0,key:a=0,isIndex:o=!1,index:u=0,internal:l=!1,virtual:d=!1,frameClient:f,alias:h,expression:I="",requires:D=[]}){c(this,"_frameClient"),c(this,"key"),c(this,"name"),c(this,"rate"),c(this,"dataType"),c(this,"leaseholder"),c(this,"index"),c(this,"isIndex"),c(this,"internal"),c(this,"alias"),c(this,"virtual"),c(this,"expression"),c(this,"requires"),this.key=a,this.name=s,this.rate=new Qt(t??0),this.dataType=new R(e),this.leaseholder=n,this.index=u,this.isIndex=o,this.internal=l,this.alias=h,this.virtual=d,this.expression=I,this.requires=D??[],this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new Q("cannot read from a channel that has not been created");return this._frameClient}get payload(){return hr.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,virtual:this.virtual,expression:this.expression,requires:this.requires})}get isCalculated(){return hs(this.payload)}get ontologyID(){return kl(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const Gg="/channel/retrieve-group",Vg=i.z.object({}),Wg=i.z.object({group:Nl});let jl=class{constructor(r,e,t,s){c(this,"type","channel"),c(this,"frameClient"),c(this,"client"),c(this,"retriever"),c(this,"writer"),this.frameClient=r,this.retriever=e,this.client=t,this.writer=s}async create(r,e={}){const{retrieveIfNameExists:t=!1}=e,s=!Array.isArray(r);let n=S(r),a=[];if(t){const o=await this.retriever.retrieve(n.map(l=>l.name)),u=new Set(o.map(l=>l.name));n=n.filter(l=>!u.has(l.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(n))),s?a[0]:a}async retrieve(r,e){const t=!Array.isArray(r),s=this.sugar(await this.retriever.retrieve(r,e));return Es("channel",r,s,t),t?s[0]:s}async search(r,e){return this.sugar(await this.retriever.search(r,e))}async delete(r){const{normalized:e,variant:t}=Ue(r);return t==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(r,e){return await this.writer.rename(S(r),S(e))}newSearcherWithOptions(r){return{type:this.type,search:async e=>await this.search(e,r),retrieve:async e=>await this.retrieve(e,r),page:async(e,t)=>await this.page(e,t,r)}}async page(r,e,t){return this.sugar(await this.retriever.page(r,e,t))}createDebouncedBatchRetriever(r=10){return new ri(new Ml(new ti(this.client),r))}sugar(r){const{frameClient:e}=this;return r.map(t=>new Bl({...t,frameClient:e}))}async retrieveGroup(){const r=await O(this.client,Gg,{},Vg,Wg);return new El(r.group.name,r.group.key)}};const hs=({virtual:r,expression:e})=>r&&e!=="",Pl=async(r,e)=>{if(!hs(e))return e.index;for(const t of e.requires){const s=await r(t);if(!s.virtual)return s.index}for(const t of e.requires){const s=await r(t);if(hs(s)){const n=await Pl(r,s);if(n!=null)return n}}return null},Zg=i.z.object({channels:xl.array()}),Jg=i.z.object({channels:hr.array()}),Kg=i.z.object({keys:Me.array().optional(),names:i.z.string().array().optional()}),Hg=i.z.object({}),Xg=i.z.object({keys:Me.array(),names:i.z.string().array()}),Qg=i.z.object({}),ey="/channel/create",ty="/channel/delete",ry="/channel/rename";let Ul=class{constructor(r,e){c(this,"client"),c(this,"cache"),this.client=r,this.cache=e}async create(r){const{channels:e}=await O(this.client,ey,{channels:r},Zg,Jg);return this.cache.set(e),e}async delete(r){await O(this.client,ty,r,Kg,Hg),r.keys!=null&&this.cache.delete(r.keys),r.names!=null&&this.cache.delete(r.names)}async rename(r,e){await O(this.client,ry,{keys:r,names:e},Xg,Qg),this.cache.rename(r,e)}};const sy=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:ri,Channel:Bl,Client:jl,ClusterRetriever:ti,DebouncedBatchRetriever:Ml,ONTOLOGY_TYPE:Al,Writer:Ul,analyzeChannelParams:Ue,isCalculated:hs,keyZ:Me,newPayload:xl,ontologyID:kl,payload:hr,resolveCalculatedIndex:Pl,retrieveRequired:Dl},Symbol.toStringTag,{value:"Module"})),dr=i.z.string().uuid(),Is=i.z.object({key:dr,username:i.z.string().min(1),firstName:i.z.string().default(""),lastName:i.z.string().default(""),rootUser:i.z.boolean().default(!0)}),ny=Is.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:i.z.string().min(1)}),iy=i.z.object({keys:dr.array().optional(),usernames:i.z.string().array().optional()}),ay=i.z.object({users:le(Is)}),oy="/user/retrieve";let ly=class{constructor(r){c(this,"client"),this.client=r}async retrieve(r){return(await O(this.client,oy,r,iy,ay)).users}};const uy=i.z.object({users:ny.array()}),cy=i.z.object({users:Is.array()}),hy=i.z.object({key:dr,username:i.z.string().min(1)}),dy=i.z.object({}),fy=i.z.object({key:dr,firstName:i.z.string().optional(),lastName:i.z.string().optional()}),py=i.z.object({}),gy=i.z.object({keys:dr.array()}),yy=i.z.object({}),my="/user/create",wy="/user/change-username",by="/user/rename",vy="/user/delete";let Oy=class{constructor(r){c(this,"client"),this.client=r}async create(r){return(await O(this.client,my,{users:S(r)},uy,cy)).users}async changeUsername(r,e){await O(this.client,wy,{key:r,username:e},hy,dy)}async rename(r,e,t){await O(this.client,by,{key:r,firstName:e,lastName:t},fy,py)}async delete(r){await O(this.client,vy,{keys:S(r)},gy,yy)}},Ty=class{constructor(r){c(this,"reader"),c(this,"writer"),this.writer=new Oy(r),this.reader=new ly(r)}async create(r){const e=Array.isArray(r),t=await this.writer.create(r);return e?t:t[0]}async changeUsername(r,e){await this.writer.changeUsername(r,e)}async retrieve(r){const e=Array.isArray(r),t=await this.reader.retrieve({keys:S(r)});if(e)return t;if(t.length===0)throw new ht(`No user with key ${r} found`);if(t.length>1)throw new dt(`Multiple users found with key ${r}`);return t[0]}async retrieveByName(r){const e=Array.isArray(r),t=await this.reader.retrieve({usernames:S(r)});if(e)return t;if(t.length===0)throw new ht(`No user with username ${r} found`);if(t.length>1)throw new dt(`Multiple users found with username ${r}`);return t[0]}async rename(r,e,t){await this.writer.rename(r,e,t)}async delete(r){await this.writer.delete(r)}};const Sy=i.z.object({username:i.z.string(),password:i.z.string()}),zy=i.z.object({token:i.z.string(),user:Is}),ka="/auth/login",Ny=3,Ey="/auth/change-password",Iy=i.z.object({username:i.z.string(),password:i.z.string(),newPassword:i.z.string().min(1)}),xy=i.z.object({});let Ay=class{constructor(r,e){c(this,"token"),c(this,"client"),c(this,"credentials"),c(this,"authenticating"),c(this,"authenticated"),c(this,"user"),c(this,"retryCount"),this.client=r,this.authenticated=!1,this.credentials=e,this.retryCount=0}async changePassword(r){if(!this.authenticated)throw new Error("Not authenticated");await O(this.client,Ey,{username:this.credentials.username,password:this.credentials.password,newPassword:r},Iy,xy),this.credentials.password=r}middleware(){const r=async(e,t)=>{if(!this.authenticated&&!e.target.endsWith(ka)){this.authenticating??(this.authenticating=new Promise((o,u)=>{this.client.send(ka,this.credentials,Sy,zy).then(([l,d])=>{if(d!=null)return o(d);this.token=l==null?void 0:l.token,this.user=l==null?void 0:l.user,this.authenticated=!0,o(null)}).catch(u)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[s,n]=await t(e);return Dn.matches(n)&&this.retryCount<Ny?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,r(e,t)):(this.retryCount=0,[s,n])};return r}};const ky=["disconnected","connecting","connected","failed"],Cy=i.z.enum(ky),Ry=i.z.object({status:Cy,error:i.z.instanceof(Error).optional(),message:i.z.string().optional(),clusterKey:i.z.string(),clientVersion:i.z.string(),clientServerCompatible:i.z.boolean(),nodeVersion:i.z.string().optional()}),$y=i.z.object({clusterKey:i.z.string(),nodeVersion:i.z.string().optional()}),Ll={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.38.0"},Ca=(r,e,t)=>{const s=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
48
|
+
This may cause compatibility issues. We recommend updating the ${s}. For more information, see
|
|
49
|
+
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${s}-version`},es=class _l{constructor(e,t=x.seconds(30),s,n){c(this,"_state"),c(this,"pollFrequency",x.seconds(30)),c(this,"client"),c(this,"name"),c(this,"interval"),c(this,"clientVersion"),c(this,"onChangeHandlers",[]),c(this,"versionWarned",!1),this._state={...Ll},this.client=e,this.pollFrequency=t,this.clientVersion=s,this.name=n,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const t=this._state.status;try{const[s,n]=await this.client.send(_l.ENDPOINT,{},i.z.object({}),$y);if(n!=null)throw n;const a=s.nodeVersion,o=this.clientVersion,u=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,u||(console.warn(Ca(null,o,!0)),this.versionWarned=!0)):ba.versionsEqual(o,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,u||(console.warn(Ca(a,o,ba.semVerNewer(o,a))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=s.clusterKey,this._state.nodeVersion=s.nodeVersion,this._state.clientVersion=this.clientVersion}catch(s){this._state.status="failed",this._state.error=s,this._state.message=(e=this.state.error)==null?void 0:e.message}return this.onChangeHandlers.length>0&&t!==this._state.status&&this.onChangeHandlers.forEach(s=>s(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};c(es,"ENDPOINT","/connectivity/check"),c(es,"DEFAULT",Ll),c(es,"connectionStateZ",Ry);let ql=es;const My=i.z.object({keys:Me.array().optional(),bounds:oe.z,names:i.z.string().array().optional()}),Dy=i.z.object({}),By="/frame/delete";class jy{constructor(e){c(this,"client"),this.client=e}async delete(e){await O(this.client,By,e,My,Dy)}}const Ra=r=>{const e=S(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},$a=(r,e)=>{const t=S(r);if(t.length===e.length)return;const s=Ra(r);throw Ra===null?new Q("[Frame] - channel keys or names must be provided when constructing a frame."):new Q(`[Frame] - ${s}s and series must be the same length.
|
|
50
|
+
Got ${t.length} ${s}s and ${e.length} series.`)};let Se=class nt{constructor(e=[],t=[]){if(c(this,"columns",[]),c(this,"series",[]),e instanceof nt){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((s,n)=>this.push(n,...S(s)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const s=e;s.series??(s.series=[]),s.keys??(s.keys=[]);const n=s.series.map(a=>Py(a));$a(s.keys,n),s.keys.forEach((a,o)=>this.push(a,n[o]))}else Object.entries(e).forEach(([s,n])=>{const a=parseInt(s);if(!isNaN(a))return this.push(a,...S(n));this.push(s,...S(n))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const s=S(t),n=S(e);$a(n,s),s.forEach((a,o)=>this.push(n[o],a));return}throw new Q(`[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 Oe("colType is not key");return this.columns??[]}get uniqueKeys(){return ra.unique(this.keys)}get names(){if(this.colType==="key")throw new Oe("colType is not name");return this.columns??[]}get uniqueNames(){return ra.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Uy(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(t=>t.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return oe.ZERO;const s=$.min(...this.series.map(a=>a.timeRange.start)),n=$.max(...this.series.map(a=>a.timeRange.end));return new oe(s,n)}const t=this.get(e);return t==null?oe.ZERO:t.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(t=>e.includes(t)):new zp(this.series.filter((t,s)=>this.columns[s]===e))}push(e,...t){if(e instanceof nt){if(this.colType!==null&&e.colType!==this.colType)throw new Q("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...t),typeof e=="string"&&this.colType==="key")throw new Q("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new Q("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new nt([...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 t=new nt;return this.forEach((s,n,a)=>t.push(...e(s,n,a))),t}forEach(e){this.columns.forEach((t,s)=>{const n=this.series[s];e(t,n,s)})}at(e,t=!1){const s={};return this.uniqueColumns.forEach(n=>{s[n]=this.get(n).at(e,t)}),s}filter(e){const t=new nt;return this.columns.forEach((s,n)=>{const a=this.series[n];e(s,a,n)&&t.push(s,a)}),t}get byteLength(){return new ut(this.series.reduce((e,t)=>e.add(t.byteLength),ut.ZERO))}get digest(){const e={};return this.keys.forEach((t,s)=>{const n=this.series[s].digest;t in e?e[t].push(n):e[t]=[n]}),e}get length(){return this.series.reduce((e,t)=>e+t.length,0)}};const si=i.z.object({keys:i.z.union([i.z.null().transform(()=>[]),i.z.number().array().optional().default([])]),series:i.z.union([i.z.null().transform(()=>[]),He.crudeZ.array().optional().default([])])}),Py=r=>{const{dataType:e,data:t,timeRange:s,alignment:n}=r;return new He({data:t,dataType:e,timeRange:s,glBufferUsage:"static",alignment:n})},Uy=r=>({timeRange:r._timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment});class xs{constructor(e){c(this,"adapter"),c(this,"retriever"),c(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const s=new xs(e);return await s.update(t),s}async update(e){const{variant:t,normalized:s}=Ue(e);if(t==="keys"){this.adapter=null,this.keys=s;return}const n=await this.retriever.retrieve(s),a=new Map;this.adapter=a,s.forEach(o=>{const u=n.find(l=>l.name===o);if(u==null)throw new Error(`Channel ${o} not found`);a.set(u.key,u.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const t=this.adapter;return e.map((s,n)=>{if(typeof s=="number"){const a=t.get(s);if(a==null)throw new Error(`Channel ${s} not found`);return[a,n]}return[s,n]})}}class ni{constructor(e){c(this,"adapter"),c(this,"retriever"),c(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const s=new ni(e);return await s.update(t),s}async adaptObjectKeys(e){const t={};for(const[s,n]of Object.entries(e))t[await this.adaptToKey(s)]=n;return t}async update(e){const t=await Dl(this.retriever,e);this.adapter=new Map(t.map(s=>[s.name,s.key])),this.keys=t.map(s=>s.key)}async fetchChannel(e){const t=await this.retriever.retrieve(e);if(t.length===0)throw new Error(`Channel ${e} not found`);return t[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}async adapt(e,t){if(typeof e=="string"||typeof e=="number"){if(t==null)throw new Q(`
|
|
53
|
+
Received a single channel name or key but no series.
|
|
54
|
+
`);if(Array.isArray(t)){if(t.some(l=>l instanceof He||Array.isArray(l)))throw new Q(`
|
|
55
|
+
Received a single channel name or key but multiple series.
|
|
56
|
+
`);t=t}const o=await this.fetchChannel(e),u=new He({data:t,dataType:o.dataType});return new Se(o.key,u)}if(Array.isArray(e)){if(t==null)throw new Q(`
|
|
57
|
+
Received an array of channel names or keys but no series.
|
|
58
|
+
`);if(!Array.isArray(t))throw new Q(`
|
|
59
|
+
Received an array of channel names or keys but no array of series.
|
|
60
|
+
`);const o=[],u=[];for(let l=0;l<e.length;l++){const d=await this.fetchChannel(e[l]);if(l>=t.length)throw new Q(`
|
|
61
|
+
Received an array of channel names or keys but not enough series.
|
|
62
|
+
`);const f=new He({data:t[l],dataType:d.dataType});o.push(d.key),u.push(f)}return new Se(o,u)}if(e instanceof Se||e instanceof Map){const o=new Se(e);if(this.adapter==null)return o;const u=o.columns.map(l=>{var d;const f=typeof l=="string"?(d=this.adapter)==null?void 0:d.get(l):l;if(f==null)throw new Q(`
|
|
63
|
+
Channel ${l} was not provided in the list of channels when opening the writer
|
|
64
|
+
`);return f});return new Se(u,o.series)}const s=[],n=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[u,l]=a[o],d=await this.fetchChannel(u),f=new He({data:l,dataType:d.dataType});s.push(d.key),n.push(f)}return new Se(s,n)}}class ii{constructor(e,t){c(this,"name"),c(this,"stream"),this.stream=t,this.name=e}async receive(){const[e,t]=await this.stream.receive();if(t!=null)throw t;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,t]=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)}`),t!=null){if(Ve.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const Ma=new x(-1);var ai=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(ai||{}),Yl=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(Yl||{});const Ly=i.z.object({command:i.z.nativeEnum(ai),span:x.z.optional(),bounds:oe.z.optional(),stamp:$.z.optional(),keys:i.z.number().array().optional(),chunkSize:i.z.number().optional()}),_y=i.z.object({variant:i.z.nativeEnum(Yl),ack:i.z.boolean(),command:i.z.nativeEnum(ai),error:lr.optional().nullable(),frame:si.optional()}),Fl=class Bn{constructor(e,t){c(this,"stream"),c(this,"adapter"),c(this,"value"),this.stream=new ii("Iterator",e),this.value=new Se,this.adapter=t}static async _open(e,t,s,n,a={}){const o=await xs.open(s,t),u=await n.stream(Bn.ENDPOINT,Ly,_y),l=new Bn(u,o);return await l.execute({command:0,keys:o.keys,bounds:new oe(e),chunkSize:a.chunkSize??1e5}),l}async next(e=Ma){return await this.execute({command:1,span:new x(e)})}async prev(e=Ma){return await this.execute({command:2,span:new x(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new $(e)})}async seekGE(e){return await this.execute({command:6,stamp:new $(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Yy(this)}async execute(e){for(this.stream.send(e),this.value=new Se;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new Se(t.frame)))}}};c(Fl,"ENDPOINT","/frame/iterate");let qy=Fl;class Yy{constructor(e){c(this,"iter"),c(this,"open",!1),this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Fy=i.z.object({keys:i.z.number().array(),downsampleFactor:i.z.number()}),Gy=i.z.object({frame:si,error:lr.optional().nullable()}),Vy="/frame/stream";class oi{constructor(e,t){c(this,"stream"),c(this,"adapter"),c(this,"downsampleFactor"),this.stream=new ii("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,t,{channels:s,downsampleFactor:n}){const a=await xs.open(e,s),o=await t.stream(Vy,Fy,Gy),u=new oi(o,a);o.send({keys:a.keys,downsampleFactor:n??1});const[,l]=await o.receive();if(l!=null)throw l;return u}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Ve.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new Se((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}}let ft=class extends et.Observer{constructor(e,t){super(t),c(this,"streamer"),c(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}};var li=(r=>(r[r.Open=0]="Open",r[r.Write=1]="Write",r[r.Commit=2]="Commit",r[r.Error=3]="Error",r[r.SetAuthority=4]="SetAuthority",r))(li||{}),er=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(er||{});const Wy=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in er)return r;throw new Error(`invalid writer mode: ${r}`)}};new x(-1);const Zy=i.z.object({start:$.z.optional(),controlSubject:ct.subjectZ.optional(),keys:i.z.number().array().optional(),authorities:ct.Authority.z.array().optional(),mode:i.z.nativeEnum(er).optional(),errOnUnauthorized:i.z.boolean().optional(),enableAutoCommit:i.z.boolean().optional(),autoIndexPersistInterval:x.z.optional()}),Jy=i.z.object({command:i.z.nativeEnum(li),config:Zy.optional(),frame:si.optional()}),Ky=i.z.object({ack:i.z.boolean(),command:i.z.nativeEnum(li),error:lr.optional().nullable()});var St;let Hy=(St=class{constructor(r,e){c(this,"stream"),c(this,"adapter"),this.stream=new ii("Writer",r),this.adapter=e}static async _open(r,e,{channels:t,start:s=$.now(),authorities:n=ct.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:u=!1,enableAutoCommit:l=!1,autoIndexPersistInterval:d=x.SECOND}){const f=await ni.open(r,t),h=await e.stream(St.ENDPOINT,Jy,Ky),I=new St(h,f);return await I.execute({command:0,config:{start:new $(s),keys:f.keys,controlSubject:a,authorities:S(n),mode:Wy(o),errOnUnauthorized:u,enableAutoCommit:l,autoIndexPersistInterval:d}}),I}async write(r,e){const t=await this.adapter.adapt(r,e);return this.stream.send({command:1,frame:t.toPayload()}),!0}async setAuthority(r,e){let t;if(typeof r=="number"&&e==null)t={keys:[],authorities:[r]};else{let s;typeof r=="string"||typeof r=="number"?s={[r]:e}:s=r,s=await this.adapter.adaptObjectKeys(s),t={keys:Object.keys(s).map(n=>Number(n)),authorities:Object.values(s)}}return(await this.execute({command:4,config:t})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const r=await this.execute({command:3});return r.error!=null?os(r.error):null}async close(){await this.stream.closeAndAck()}async execute(r){for(this.stream.send(r);;){const e=await this.stream.receive();if(e.command===r.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},c(St,"ENDPOINT","/frame/write"),St),Xy=class{constructor(r,e,t){c(this,"streamClient"),c(this,"retriever"),c(this,"deleter"),this.streamClient=r,this.retriever=t,this.deleter=new jy(e)}async openIterator(r,e,t){return await qy._open(r,e,this.retriever,this.streamClient,t)}async openWriter(r){return(Array.isArray(r)||typeof r!="object")&&(r={channels:r}),await Hy._open(this.retriever,this.streamClient,r)}async openStreamer(r){return(Array.isArray(r)||typeof r!="object")&&(r={channels:r,downsampleFactor:1}),await oi._open(this.retriever,this.streamClient,r)}async write(r,e,t){if(t==null){const n=e,a=await this.openWriter({start:r,channels:Object.keys(n),mode:er.Persist});try{await a.write(n),await a.commit()}finally{await a.close()}return}const s=await this.openWriter({start:r,channels:e,mode:er.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:x.MAX});try{await s.write(e,t)}finally{await s.close()}}async read(r,e){const{single:t}=Ue(e),s=await this.readFrame(r,e);return t?s.get(e):s}async readFrame(r,e){const t=await this.openIterator(r,e),s=new Se;try{for await(const n of t)s.push(n)}finally{await t.close()}return s}async delete(r,e){const{normalized:t,variant:s}=Ue(r);return s==="keys"?await this.deleter.delete({keys:t,bounds:e}):await this.deleter.delete({names:t,bounds:e})}};const Qy=ct.Authority,em=ct.stateZ(i.z.number()),tm=r=>{var e,t;return r.to==null?`${(e=r.from)==null?void 0:e.resource} - ${(t=r.from)==null?void 0:t.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`};class Gl extends ft{constructor(e){super(e,t=>{const s=this.codec.decode(t.series[0].buffer);return this.merge(s),[s.transfers,!0]}),c(this,"states"),c(this,"codec"),this.states=new Map,this.codec=new gt.JSONCodec}subjects(){const e=new Map;return this.states.forEach(t=>e.set(t.subject.key,t.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(t=>{t.from==null&&t.to==null&&console.warn("Invalid transfer: ",t),t.to==null?this.states.delete(t.from.resource):this.states.set(t.to.resource,t.to)})}}const rm="sy_node_1_control";let Vl=class{constructor(r){c(this,"framer"),this.framer=r}async openStateTracker(){const r=await this.framer.openStreamer(rm);return new Gl(r)}};const sm=Object.freeze(Object.defineProperty({__proto__:null,Authority:Qy,Client:Vl,StateTracker:Gl,stateZ:em,transferString:tm},Symbol.toStringTag,{value:"Module"}));let nm=class{constructor(r,e,t){c(this,"tasks"),c(this,"racks"),c(this,"devices"),this.tasks=r,this.racks=e,this.devices=t}};const fr=i.z.number(),ui=i.z.object({key:fr,name:i.z.string()}),im=ui.partial({key:!0}),ci=i.z.string(),As=i.z.object({key:ci,rack:fr,name:i.z.string(),make:i.z.string(),model:i.z.string(),location:i.z.string(),configured:i.z.boolean().optional(),properties:i.z.record(i.z.unknown()).or(i.z.string().transform(r=>r===""?{}:gt.JSON_CODEC.decodeString(r)))}),am=As.extend({properties:i.z.unknown().transform(r=>gt.JSON_CODEC.encodeString(r))}),mt=async(r,e,t,s)=>{const n=await r.openStreamer([e,t]),a=o=>{const u=[];return t!=null&&u.push(...o.get(t).series.flatMap(l=>s("delete",l))),e!=null&&u.push(...o.get(e).series.flatMap(l=>s("set",l))),[u,u.length>0]};return new ft(n,a)},om="sy_device_set",lm="sy_device_delete",Hs="/hardware/device/retrieve",um="/hardware/device/create",cm="/hardware/device/delete",hm=i.z.object({devices:am.array()}),dm=i.z.object({devices:As.array()}),fm=i.z.object({keys:ci.array()}),pm=i.z.object({}),Xs=i.z.object({search:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),keys:ci.array().optional(),names:i.z.string().array().optional(),makes:i.z.string().array().optional()}),Qs=i.z.object({devices:le(As)});let gm=class{constructor(r,e){c(this,"type","device"),c(this,"client"),c(this,"frameClient"),this.client=r,this.frameClient=e}async retrieve(r,e){const t=!Array.isArray(r),s=await O(this.client,Hs,{keys:S(r),...e},Xs,Qs);return Es("Device",r,s.devices,t),t?s.devices[0]:s.devices}async search(r,e){return(await O(this.client,Hs,{search:r,...e},Xs,Qs)).devices}async page(r,e,t){return(await O(this.client,Hs,{offset:r,limit:e,...t},Xs,Qs)).devices}async create(r){const e=!Array.isArray(r),t=await O(this.client,um,{devices:S(r)},hm,dm);return e?t.devices[0]:t.devices}async delete(r){await O(this.client,cm,{keys:S(r)},fm,pm)}async openDeviceTracker(){return await mt(this.frameClient,om,lm,ym)}newSearcherWithOptions(r){return{type:this.type,search:async e=>await this.search(e,r),retrieve:async e=>await this.retrieve(e,r),page:async(e,t)=>await this.page(e,t,r)}}};const ym=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(As).map(t=>({variant:r,key:t.key,value:t})),en="/hardware/rack/retrieve",mm="/hardware/rack/create",wm="/hardware/rack/delete",tn=i.z.object({keys:fr.array().optional(),names:i.z.string().array().optional(),search:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),rn=i.z.object({racks:le(ui)}),bm=i.z.object({racks:im.array()}),vm=i.z.object({racks:ui.array()}),Om=i.z.object({keys:fr.array()}),Tm=i.z.object({});let Sm=class{constructor(r,e,t){c(this,"type","rack"),c(this,"client"),c(this,"frameClient"),c(this,"tasks"),this.client=r,this.frameClient=e,this.tasks=t}async delete(r){await O(this.client,wm,{keys:S(r)},Om,Tm)}async create(r){const e=!Array.isArray(r),t=await O(this.client,mm,{racks:S(r)},bm,vm),s=this.sugar(t.racks);return e?s[0]:s}async search(r){const e=await O(this.client,en,{search:r},tn,rn);return this.sugar(e.racks)}async page(r,e){const t=await O(this.client,en,{offset:r,limit:e},tn,rn);return this.sugar(t.racks)}async retrieve(r){const{variant:e,normalized:t,single:s}=Ns(r,{string:"names",number:"keys"}),n=await O(this.client,en,{[e]:t},tn,rn),a=this.sugar(n.racks);return Es("Rack",r,a,s),s?a[0]:a}sugar(r){return r.map(({key:e,name:t})=>new zm(e,t,this.tasks))}};class zm{constructor(e,t,s){c(this,"key"),c(this,"name"),c(this,"tasks"),this.key=e,this.name=t,this.tasks=s}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 wt=i.z.union([i.z.string(),i.z.bigint().transform(r=>r.toString()),i.z.number().transform(r=>r.toString())]),ds=i.z.object({task:wt,variant:i.z.string(),key:i.z.string().optional(),details:i.z.record(i.z.unknown()).or(i.z.string().transform(r=>r===""?{}:JSON.parse(r))).or(i.z.array(i.z.unknown())).or(i.z.null())}),ks=i.z.object({key:wt,name:i.z.string(),type:i.z.string(),internal:i.z.boolean().optional(),config:i.z.record(i.z.unknown()).or(i.z.string().transform(r=>r===""?{}:gt.JSON_CODEC.decodeString(r))),state:ds.optional().nullable(),snapshot:i.z.boolean().optional()}),Nm=ks.omit({key:!0}).extend({key:wt.transform(r=>r.toString()).optional(),config:i.z.unknown().transform(r=>gt.JSON_CODEC.encodeString(r))}),Wl=i.z.object({task:wt,type:i.z.string(),key:i.z.string(),args:i.z.record(i.z.unknown()).or(i.z.string().transform(r=>r===""?{}:JSON.parse(r))).or(i.z.array(i.z.unknown())).or(i.z.null()).optional()}),Em="task",Im=r=>new U({type:Em,key:r.toString()}),Kt="sy_task_state",it="sy_task_cmd",zt=new Error("Task not created");class xm{constructor(e,t,s,n,a=!1,o=!1,u,l=null,d=null,f=null){c(this,"key"),c(this,"name"),c(this,"internal"),c(this,"type"),c(this,"config"),c(this,"snapshot"),c(this,"state"),c(this,"frameClient"),c(this,"ontologyClient"),c(this,"rangeClient"),this.key=e,this.name=t,this.type=s,this.config=n,this.internal=a,this.snapshot=o,u!==null&&(this.state=u),this.frameClient=l,this.ontologyClient=d,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 Im(this.key)}async executeCommand(e,t){if(this.frameClient==null)throw zt;const s=await this.frameClient.openWriter(it),n=pp.id();return await s.write(it,[{task:this.key,type:e,key:n,args:t}]),await s.close(),n}async executeCommandSync(e,t,s){if(this.frameClient==null)throw zt;const n=await this.frameClient.openStreamer(Kt),a=await this.executeCommand(e,t);let o;const u=new Promise(l=>setTimeout(()=>l(!1),new x(s).milliseconds));for(;;){const l=await Promise.any([n.read(),u]);if(l===!1)throw new Error("Command timed out");const d=ds.safeParse(l.at(-1).sy_task_state);if(d.success){if(o=d.data,o.key===a)break}else console.error(d.error)}return n.close(),o}async openStateObserver(){if(this.frameClient==null)throw zt;return new ft(await this.frameClient.openStreamer(Kt),e=>{const t=e.get(Kt);if(t.length===0)return[null,!1];const s=ds.safeParse(t.at(-1));if(!s.success)return console.error(s.error),[null,!1];const n=s.data;return n.task!==this.key?[null,!1]:[n,!0]})}async openCommandObserver(){if(this.frameClient==null)throw zt;return new ft(await this.frameClient.openStreamer(it),e=>{const t=e.get(it);if(t.length===0)return[null,!1];const s=Wl.safeParse(t.at(-1));if(!s.success)return console.error(s.error),[null,!1];const n=s.data;return n.task!==this.key?[null,!1]:[n,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw zt;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Am=i.z.object({rack:fr.optional(),keys:i.z.string().array().optional(),names:i.z.string().array().optional(),offset:i.z.number().optional(),limit:i.z.number().optional(),includeState:i.z.boolean().optional()}),km=i.z.object({tasks:le(ks)}),Cm="/hardware/task/retrieve",Rm="/hardware/task/create",$m="/hardware/task/delete",Mm="/hardware/task/copy",Dm=i.z.object({tasks:Nm.array()}),Bm=i.z.object({tasks:ks.array()}),jm=i.z.object({keys:wt.array()}),Pm=i.z.object({}),Um=i.z.object({key:wt,name:i.z.string(),snapshot:i.z.boolean()}),Lm=i.z.object({task:ks});let _m=class{constructor(r,e,t,s){c(this,"type","task"),c(this,"client"),c(this,"frameClient"),c(this,"ontologyClient"),c(this,"rangeClient"),this.client=r,this.frameClient=e,this.ontologyClient=t,this.rangeClient=s}async create(r){const e=!Array.isArray(r),t=await O(this.client,Rm,{tasks:S(r)},Dm,Bm),s=this.sugar(t.tasks);return e?s[0]:s}async delete(r){await O(this.client,$m,{keys:S(r)},jm,Pm)}async search(r){return await this.execRetrieve({keys:[r]})}async page(r,e){return await this.execRetrieve({offset:r,limit:e})}async list(r={}){return this.sugar(await this.execRetrieve(r))}async retrieve(r,e){const{single:t,normalized:s,variant:n}=Ns(r,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};n==="rack"?a.rack=r:a.keys=s;const o=await this.execRetrieve(a),u=this.sugar(o);return t&&n!=="rack"?u[0]:u}async copy(r,e,t){const s=await O(this.client,Mm,{key:r,name:e,snapshot:t},Um,Lm);return this.sugar([s.task])[0]}async retrieveByName(r,e){const t=await this.execRetrieve({names:[r],rack:e});return Es("Task",r,t,!0),this.sugar(t)[0]}async execRetrieve(r){return(await O(this.client,Cm,r,Am,km)).tasks}sugar(r){return r.map(({key:e,name:t,type:s,config:n,state:a,internal:o,snapshot:u})=>new xm(e,t,s,n,o,u,a,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await mt(this.frameClient,"sy_task_set","sy_task_delete",(r,e)=>Array.from(e).map(t=>({variant:r,key:t.toString(),value:t.toString()})))}async openStateObserver(){return new ft(await this.frameClient.openStreamer(Kt),r=>{const e=r.get(Kt);if(e.length===0)return[null,!1];const t=ds.safeParse(e.at(-1));return t.success?[t.data,!0]:(console.error(t.error),[null,!1])})}async openCommandObserver(){return new ft(await this.frameClient.openStreamer(it),r=>{const e=r.get(it);if(e.length===0)return[null,!1];const t=Wl.safeParse(e.at(-1));return t.success?[t.data,!0]:(console.error(t.error),[null,!1])})}};const pr=i.z.string().uuid(),Cs=i.z.object({key:pr,name:i.z.string().min(1),color:i.z.string()}),qm="label",Ym=r=>new U({type:qm,key:r}),Fm=i.z.object({keys:pr.array().optional(),for:be.optional(),search:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),Gm=i.z.object({labels:le(Cs)}),Zl=class Jl{constructor(e){c(this,"client"),this.client=e}async retrieve(e){const t=S(e);return await this.execute({keys:t})}async retrieveFor(e){return await this.execute({for:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){const[t,s]=await this.client.send(Jl.ENDPOINT,e,Fm,Gm);if(s!=null)throw s;return t.labels}};c(Zl,"ENDPOINT","/label/retrieve");let Vm=Zl;const Wm=Cs.extend({key:pr.optional()}),Zm=i.z.object({labels:Wm.array()}),Jm=i.z.object({labels:Cs.array()}),Km=i.z.object({keys:pr.array()}),Kl=i.z.object({id:be,labels:pr.array(),replace:i.z.boolean().optional()}),Hm=Kl.omit({replace:!0}),sn=i.z.object({}),Xm="/label/create",Qm="/label/delete",ew="/label/set",tw="/label/remove";let rw=class{constructor(r){c(this,"client"),this.client=r}async create(r){return(await O(this.client,Xm,{labels:S(r)},Zm,Jm)).labels}async delete(r){await O(this.client,Qm,{keys:S(r)},Km,sn)}async set(r,e,{replace:t}={}){await O(this.client,ew,{id:r,labels:e,replace:t},Kl,sn)}async remove(r,e){await O(this.client,tw,{id:r,labels:e},Hm,sn)}};const sw="sy_label_set",nw="sy_label_delete";let iw=class{constructor(r,e,t){c(this,"type","label"),c(this,"retriever"),c(this,"writer"),c(this,"frameClient"),c(this,"ontology"),this.writer=new rw(r),this.retriever=new Vm(r),this.frameClient=e,this.ontology=t}async search(r){return await this.retriever.search(r)}async retrieve(r){const e=Array.isArray(r),t=await this.retriever.retrieve(r);return e?t:t[0]}async retrieveFor(r){return await this.retriever.retrieveFor(new U(r))}async label(r,e,t={}){await this.writer.set(new U(r),e,t)}async removeLabels(r,e){await this.writer.remove(new U(r),e)}async page(r,e){return await this.retriever.page(r,e)}async create(r){const e=Array.isArray(r),t=await this.writer.create(r);return e?t:t[0]}async delete(r){await this.writer.delete(r)}async openChangeTracker(){return await mt(this.frameClient,sw,nw,aw)}async trackLabelsOf(r){const e=new et.Observer,t=(await this.retrieveFor(r)).map(s=>({id:Ym(s.key),key:s.key,name:s.name,data:s}));return(await this.ontology.openDependentTracker({target:new U(r),dependents:t,relationshipType:"labeled_by"})).onChange(s=>e.notify(s.map(n=>{var a,o;return{key:n.id.key,color:(a=n.data)==null?void 0:a.color,name:(o=n.data)==null?void 0:o.name}}))),e}};const aw=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(Cs).map(t=>({variant:r,key:t.key,value:t})),we=i.z.string().uuid(),gr=i.z.object({key:we,name:i.z.string().min(1),timeRange:oe.z,color:i.z.string().optional()}),Hl=gr.extend({key:i.z.string().uuid().optional()}),Xl=r=>{const e=S(r),t=e.length===0;let s=!1;return t||(s=we.safeParse(e[0]).success),{single:!Array.isArray(r),variant:s?"keys":"names",normalized:e,actual:r,empty:t}},Ql="range",eu="range-alias",Ge=r=>new U({type:Ql,key:r}),ow=r=>new U({type:eu,key:r}),lw="sy_range_alias_set",uw="sy_range_alias_delete",cw=i.z.object({range:we,aliases:i.z.string().array()}),hw=i.z.object({aliases:i.z.record(i.z.string(),Me)}),dw=i.z.object({range:we,aliases:i.z.record(Me.or(i.z.string()),i.z.string())}),fw=i.z.unknown(),pw=i.z.object({range:we,channels:Me.array()}),gw=i.z.unknown(),yw=i.z.object({range:we}),mw=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())}),Ft=class Gt{constructor(e,t,s){c(this,"frameClient"),c(this,"cache",new Map),c(this,"client"),c(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=s,this.frameClient=t}async resolve(e){const t=[],s=typeof e=="string",n={};if(s){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const u=this.cache.get(o);u!=null?n[o]=u:t.push(o)});if(t.length===0)return n;const a=await O(this.client,Gt.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},cw,hw);return Object.entries(a.aliases).forEach(([o,u])=>this.cache.set(o,u)),s?a.aliases[t[0]]:{...n,...a.aliases}}async set(e){await O(this.client,Gt.SET_ENDPOINT,{range:this.rangeKey,aliases:e},dw,fw)}async list(){return(await O(this.client,Gt.LIST_ENDPOINT,{range:this.rangeKey},yw,mw)).aliases}async delete(e){await O(this.client,Gt.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},pw,gw)}async openChangeTracker(){return await mt(this.frameClient,lw,uw,Ow(this.rangeKey))}};c(Ft,"SET_ENDPOINT","/range/alias/set"),c(Ft,"RESOLVE_ENDPOINT","/range/alias/resolve"),c(Ft,"LIST_ENDPOINT","/range/alias/list"),c(Ft,"DELETE_ENDPOINT","/range/alias/delete");let ww=Ft;const bw=i.z.object({range:we,channel:Me,alias:i.z.string()}),vw="---",Ow=r=>(e,t)=>e==="delete"?t.toStrings().filter(s=>s.split(vw)[0]===r).map(s=>({variant:e,key:s,value:void 0})):t.parseJSON(bw).map(s=>({variant:e,key:s.alias,value:s})),Tw=i.z.object({range:we,keys:i.z.string().array()}),hi=i.z.object({range:we,key:i.z.string(),value:i.z.string()}),Sw=i.z.object({pairs:le(hi)}),zw=i.z.object({range:we,pairs:hi.array()}),Nw=i.z.object({range:we,keys:i.z.string().array()}),ts=class rs{constructor(e,t,s){c(this,"rangeKey"),c(this,"client"),c(this,"frameClient"),this.rangeKey=e,this.client=t,this.frameClient=s}async get(e){const t=await O(this.client,rs.GET_ENDPOINT,{range:this.rangeKey,keys:S(e)},Tw,Sw);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(s=>[s.key,s.value]))}async list(){return this.get([])}async set(e,t=""){let s;Hn(e)?s=Object.entries(e).map(([n,a])=>({range:this.rangeKey,key:n,value:a})):s=[{range:this.rangeKey,key:e,value:t}],await O(this.client,rs.SET_ENDPOINT,{range:this.rangeKey,pairs:s},zw,i.z.unknown())}async delete(e){await O(this.client,rs.DELETE_ENDPOINT,{range:this.rangeKey,keys:S(e)},Nw,i.z.unknown())}async openTracker(){return await mt(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,t)=>e==="delete"?t.toStrings().map(s=>{const[n,a]=s.split("<--->",2);return{variant:e,key:s,value:{range:n,key:a,value:""}}}):t.parseJSON(hi).map(s=>({variant:e,key:`${s.range}${s.key}`,value:s})))}};c(ts,"GET_ENDPOINT","/range/kv/get"),c(ts,"SET_ENDPOINT","/range/kv/set"),c(ts,"DELETE_ENDPOINT","/range/kv/delete");let jn=ts;class tu{constructor(e,t=oe.ZERO,s,n,a,o,u,l,d,f,h){c(this,"key"),c(this,"name"),c(this,"kv"),c(this,"timeRange"),c(this,"color"),c(this,"channels"),c(this,"aliaser"),c(this,"frameClient"),c(this,"labelClient"),c(this,"ontologyClient"),c(this,"rangeClient"),this.key=s,this.name=e,this.timeRange=t,this.frameClient=a,this.color=n,this.kv=o,this.aliaser=u,this.channels=l,this.labelClient=d,this.ontologyClient=f,this.rangeClient=h}get ontologyID(){return Ge(this.key)}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,t){const s=await this.channels.retrieve(e);if(s.length===0)throw new Ne(`Channel ${e} does not exist`);await this.aliaser.set({[s[0].key]:t})}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(t=>t.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(Ge(this.key))}async addLabel(...e){await this.labelClient.label(Ge(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Ge(this.key),e)}async openChildRangeTracker(){const e=new et.Observer,t=(await this.retrieveChildren()).map(n=>{const a=Ge(n.key);return{id:a,key:a.toString(),name:n.name,data:n.payload}}),s=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:t,resourceType:"range"});return s.onChange(n=>e.notify(this.rangeClient.resourcesToRanges(n))),e.setCloser(async()=>await s.close()),e}async openParentRangeTracker(){const e=new et.Observer,t=await this.retrieveParent();if(t==null)return null;const s=Ge(t.key),n={id:s,key:s.toString(),name:t.name,data:t.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[n],relationshipDirection:"to"});return a.onChange(o=>{const u=this.rangeClient.resourcesToRanges(o);if(u.length===0)return;const l=u[0];e.notify(l)}),e.setCloser(async()=>await a.close()),e}}const Ew=(r,e)=>yp(r.timeRange,e.timeRange),Iw=i.z.object({keys:we.array().optional(),names:i.z.array(i.z.string()).optional(),term:i.z.string().optional(),overlapsWith:oe.z.optional(),limit:i.z.number().int().optional(),offset:i.z.number().int().optional()}),xw="/range/retrieve",Aw=i.z.object({ranges:le(gr)});let ru=class{constructor(r,e,t,s,n,a){c(this,"type","range"),c(this,"frameClient"),c(this,"writer"),c(this,"unaryClient"),c(this,"channels"),c(this,"labelClient"),c(this,"ontologyClient"),this.frameClient=r,this.writer=e,this.unaryClient=t,this.channels=s,this.labelClient=n,this.ontologyClient=a}async create(r,e){const t=!Array.isArray(r),s=this.sugarMany(await this.writer.create(S(r),e));return t?s[0]:s}async rename(r,e){await this.writer.rename(r,e)}async delete(r){await this.writer.delete(S(r))}async search(r){return this.sugarMany(await this.execRetrieve({term:r}))}async page(r,e){return this.sugarMany(await this.execRetrieve({offset:r,limit:e}))}async retrieve(r){if(typeof r=="object"&&"start"in r)return await this.execRetrieve({overlapsWith:new oe(r)});const{single:e,actual:t,variant:s,normalized:n,empty:a}=Xl(r);if(a)return[];const o=await this.execRetrieve({[s]:n});if(!e)return o;if(o.length===0)throw new ht(`range matching ${t} not found`);if(o.length>1)throw new dt(`multiple ranges matching ${t} found`);return o[0]}getKV(r){return new jn(r,this.unaryClient,this.frameClient)}async execRetrieve(r){const{ranges:e}=await O(this.unaryClient,xw,r,Iw,Aw);return this.sugarMany(e)}async retrieveParent(r){const e=await this.ontologyClient.retrieveParents(Ge(r));if(e.length===0)return null;const t=e[0];return t.id.type!=="range"?null:await this.retrieve(t.id.key)}sugarOne(r){return new tu(r.name,r.timeRange,r.key,r.color,this.frameClient,new jn(r.key,this.unaryClient,this.frameClient),new ww(r.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(r){return r.map(e=>this.sugarOne(e))}async openTracker(){return await mt(this.frameClient,"sy_range_set","sy_range_delete",(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):this.sugarMany(e.parseJSON(gr)).map(t=>({variant:r,key:t.key,value:t})))}resourcesToRanges(r){return r.map(e=>this.resourceToRange(e))}resourceToRange(r){var e,t,s;return this.sugarOne({key:r.id.key,name:(e=r.data)==null?void 0:e.name,timeRange:new oe((t=r.data)==null?void 0:t.timeRange),color:(s=r.data)==null?void 0:s.color})}};const kw=i.z.object({ranges:gr.array()}),Cw=i.z.object({parent:be.optional(),ranges:Hl.array()}),Rw=i.z.object({keys:we.array()}),$w=i.z.object({}),Mw=i.z.object({key:we,name:i.z.string()}),Dw=i.z.object({}),Bw="/range/create",jw="/range/delete",Pw="/range/rename";class su{constructor(e){c(this,"client"),this.client=e}async rename(e,t){await O(this.client,Pw,{key:e,name:t},Mw,Dw)}async create(e,t){return(await O(this.client,Bw,{ranges:e,...t},Cw,kw)).ranges}async delete(e){await O(this.client,jw,{keys:e},Rw,$w)}}const Uw=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:eu,Client:ru,KV:jn,ONTOLOGY_TYPE:Ql,Range:tu,Writer:su,aliasOntologyID:ow,analyzeParams:Xl,keyZ:we,newPayloadZ:Hl,ontologyID:Ge,payloadZ:gr,sort:Ew},Symbol.toStringTag,{value:"Module"})),Lw="/api/v1/";class _w{constructor(e,t={},s=!1){c(this,"url"),c(this,"unary"),c(this,"stream"),c(this,"secure"),this.secure=s,this.url=e.child(Lw);const n=new gt.JSONCodec;this.unary=sf(new rf(this.url,n,this.secure),t),this.stream=new ff(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const Rs=i.z.string().uuid(),di=i.z.object({key:i.z.string(),name:i.z.string(),data:ur.or(i.z.string().transform(r=>JSON.parse(r)))}),qw="/workspace/lineplot/retrieve",Yw="/workspace/lineplot/create",Fw="/workspace/lineplot/rename",Gw="/workspace/lineplot/set-data",Vw="/workspace/lineplot/delete",Ww=di.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Zw=i.z.object({keys:Rs.array()}),Jw=i.z.object({workspace:i.z.string(),linePlots:Ww.array()}),Kw=i.z.object({key:Rs,name:i.z.string()}),Hw=i.z.object({key:Rs,data:i.z.string()}),Xw=i.z.object({keys:Rs.array()}),Qw=i.z.object({linePlots:le(di)}),eb=i.z.object({linePlots:di.array()}),nn=i.z.object({});let tb=class{constructor(r){c(this,"client"),this.client=r}async create(r,e){const t=Array.isArray(e),s=S(e),n=await O(this.client,Yw,{workspace:r,linePlots:s},Jw,eb);return t?n.linePlots:n.linePlots[0]}async rename(r,e){await O(this.client,Fw,{key:r,name:e},Kw,nn)}async setData(r,e){await O(this.client,Gw,{key:r,data:JSON.stringify(e)},Hw,nn)}async retrieve(r){const e=Array.isArray(r),t=S(r),s=await O(this.client,qw,{keys:t},Zw,Qw);return e?s.linePlots:s.linePlots[0]}async delete(r){const e=S(r);await O(this.client,Vw,{keys:e},Xw,nn)}};i.z.string().uuid();const fi=i.z.object({key:i.z.string(),name:i.z.string(),data:ur.or(i.z.string().transform(r=>JSON.parse(r)))}),rb="/workspace/log/retrieve",sb="/workspace/log/create",nb="/workspace/log/rename",ib="/workspace/log/set-data",ab="/workspace/log/delete",ob=fi.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),lb=i.z.object({keys:i.z.string().array()}),ub=i.z.object({workspace:i.z.string(),logs:ob.array()}),cb=i.z.object({key:i.z.string(),name:i.z.string()}),hb=i.z.object({key:i.z.string(),data:i.z.string()}),db=i.z.object({keys:i.z.string().array()}),fb=i.z.object({logs:fi.array()}),pb=i.z.object({logs:fi.array()}),an=i.z.object({});let gb=class{constructor(r){c(this,"client"),this.client=r}async create(r,e){const t=Array.isArray(e),s=S(e),n=await O(this.client,sb,{workspace:r,logs:s},ub,pb);return t?n.logs:n.logs[0]}async rename(r,e){await O(this.client,nb,{key:r,name:e},cb,an)}async setData(r,e){await O(this.client,ib,{key:r,data:JSON.stringify(e)},hb,an)}async retrieve(r){const e=Array.isArray(r),t=S(r),s=await O(this.client,rb,{keys:t},lb,fb);return e?s.logs:s.logs[0]}async delete(r){const e=S(r);await O(this.client,ab,{keys:e},db,an)}};i.z.string().uuid();const nu=i.z.object({key:i.z.string(),name:i.z.string(),data:ur.or(i.z.string().transform(r=>JSON.parse(r))),snapshot:i.z.boolean()}),iu=i.z.object({key:i.z.string(),name:i.z.string(),snapshot:i.z.boolean(),data:i.z.string().transform(r=>JSON.parse(r))}),yb="/workspace/schematic/retrieve",mb="/workspace/schematic/create",wb="/workspace/schematic/rename",bb="/workspace/schematic/set-data",vb="/workspace/schematic/delete",Ob="/workspace/schematic/copy",Tb=nu.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Sb=i.z.object({keys:i.z.string().array()}),zb=i.z.object({workspace:i.z.string(),schematics:Tb.array()}),Nb=i.z.object({key:i.z.string(),name:i.z.string()}),Eb=i.z.object({key:i.z.string(),data:i.z.string()}),Ib=i.z.object({keys:i.z.string().array()}),xb=i.z.object({key:i.z.string(),name:i.z.string(),snapshot:i.z.boolean()}),Ab=i.z.object({schematics:le(iu)}),kb=i.z.object({schematics:iu.array()}),Cb=i.z.object({schematic:nu}),on=i.z.object({});let Rb=class{constructor(r){c(this,"client"),this.client=r}async create(r,e){const t=Array.isArray(e),s=S(e),n=await O(this.client,mb,{workspace:r,schematics:s},zb,kb);return t?n.schematics:n.schematics[0]}async rename(r,e){await O(this.client,wb,{key:r,name:e},Nb,on)}async setData(r,e){await O(this.client,bb,{key:r,data:JSON.stringify(e)},Eb,on)}async retrieve(r){const e=Array.isArray(r),t=S(r),s=await O(this.client,yb,{keys:t},Sb,Ab);return e?s.schematics:s.schematics[0]}async delete(r){const e=S(r);await O(this.client,vb,{keys:e},Ib,on)}async copy(r,e,t){return(await O(this.client,Ob,{key:r,name:e,snapshot:t},xb,Cb)).schematic}};i.z.string().uuid();const $b=i.z.object({key:i.z.string(),name:i.z.string(),data:ur.or(i.z.string().transform(r=>JSON.parse(r)))}),Mb="/workspace/table/retrieve",Db="/workspace/table/create",Bb="/workspace/table/rename",jb="/workspace/table/set-data",Pb="/workspace/table/delete",Ub=$b.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),au=i.z.object({key:i.z.string(),name:i.z.string(),data:i.z.string().transform(r=>JSON.parse(r))}),Lb=i.z.object({keys:i.z.string().array()}),_b=i.z.object({workspace:i.z.string(),tables:Ub.array()}),qb=i.z.object({key:i.z.string(),name:i.z.string()}),Yb=i.z.object({key:i.z.string(),data:i.z.string()}),Fb=i.z.object({keys:i.z.string().array()}),Gb=i.z.object({tables:au.array()}),Vb=i.z.object({tables:au.array()}),ln=i.z.object({});let Wb=class{constructor(r){c(this,"client"),this.client=r}async create(r,e){const t=Array.isArray(e),s=S(e),n=await O(this.client,Db,{workspace:r,tables:s},_b,Vb);return t?n.tables:n.tables[0]}async rename(r,e){await O(this.client,Bb,{key:r,name:e},qb,ln)}async setData(r,e){await O(this.client,jb,{key:r,data:JSON.stringify(e)},Yb,ln)}async retrieve(r){const e=Array.isArray(r),t=S(r),s=await O(this.client,Mb,{keys:t},Lb,Gb);return e?s.tables:s.tables[0]}async delete(r){const e=S(r);await O(this.client,Pb,{keys:e},Fb,ln)}};i.z.string().uuid();const ou=r=>JSON.parse(r),pi=i.z.object({key:i.z.string(),name:i.z.string(),layout:ur.or(i.z.string().transform(r=>ou(r)))}),Or="/workspace/retrieve",Zb="/workspace/create",Jb="/workspace/rename",Kb="/workspace/set-layout",Hb="/workspace/delete",Xb=pi.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Qb=pi.omit({layout:!0}).extend({layout:i.z.string().transform(r=>ou(r))}),Tr=i.z.object({keys:i.z.string().array().optional(),search:i.z.string().optional(),author:i.z.string().uuid().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),ev=i.z.object({workspaces:Xb.array()}),tv=i.z.object({key:i.z.string(),name:i.z.string()}),rv=i.z.object({key:i.z.string(),layout:i.z.string()}),sv=i.z.object({keys:i.z.string().array()}),Sr=i.z.object({workspaces:le(pi)}),nv=i.z.object({workspaces:Qb.array()}),un=i.z.object({});class iv{constructor(e){c(this,"type","workspace"),c(this,"schematic"),c(this,"linePlot"),c(this,"log"),c(this,"table"),c(this,"client"),this.client=e,this.schematic=new Rb(e),this.linePlot=new tb(e),this.log=new gb(e),this.table=new Wb(e)}async create(e){const t=Array.isArray(e),s=S(e),n=await O(this.client,Zb,{workspaces:s},ev,nv);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await O(this.client,Jb,{key:e,name:t},tv,un)}async setLayout(e,t){await O(this.client,Kb,{key:e,layout:JSON.stringify(t)},rv,un)}async retrieve(e){const t=Array.isArray(e),s=S(e),n=await O(this.client,Or,{keys:s},Tr,Sr);return t?n.workspaces:n.workspaces[0]}async retrieveByAuthor(e){return(await O(this.client,Or,{author:e},Tr,Sr)).workspaces}async search(e){return(await O(this.client,Or,{search:e},Tr,Sr)).workspaces}async page(e,t){return(await O(this.client,Or,{offset:e,limit:t},Tr,Sr)).workspaces}async delete(e){const t=S(e);await O(this.client,Hb,{keys:t},sv,un)}}const lu=i.z.object({host:i.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:i.z.number({required_error:"Port is required"}).or(i.z.string({required_error:"Port is required"})),username:i.z.string().min(1,"Username is required"),password:i.z.string().min(1,"Password is required"),connectivityPollFrequency:x.z.default(x.seconds(30)),secure:i.z.boolean().optional().default(!1),name:i.z.string().optional(),retry:Gp.breakerConfig.optional()});class uu extends Xy{constructor(e){const t=lu.parse(e),{host:s,port:n,username:a,password:o,connectivityPollFrequency:u,secure:l,retry:d}=t,f=new _w(new Up({host:s,port:Number(n)}),d,l);f.use(tg);let h;a!=null&&o!=null&&(h=new Ay(f.unary,{username:a,password:o}),f.use(h.middleware()));const I=new ri(new ti(f.unary)),D=new Ul(f.unary,I);super(f.stream,f.unary,I),c(this,"createdAt"),c(this,"props"),c(this,"ranges"),c(this,"channels"),c(this,"auth"),c(this,"user"),c(this,"access"),c(this,"connectivity"),c(this,"ontology"),c(this,"workspaces"),c(this,"labels"),c(this,"hardware"),c(this,"control"),c(this,"transport"),c(this,"clientVersion","0.38.0"),this.createdAt=$.now(),this.props=t,this.auth=h,this.transport=f,this.channels=new jl(this,I,f.unary,D),this.connectivity=new ql(f.unary,u,this.clientVersion,t.name),this.control=new Vl(this),this.ontology=new Og(f.unary,this);const ue=new su(this.transport.unary);this.labels=new iw(this.transport.unary,this,this.ontology),this.ranges=new ru(this,ue,this.transport.unary,I,this.labels,this.ontology),this.access=new Bg(this.transport.unary),this.user=new Ty(this.transport.unary),this.workspaces=new iv(this.transport.unary);const j=new gm(this.transport.unary,this),Ti=new _m(this.transport.unary,this,this.ontology,this.ranges),Mu=new Sm(this.transport.unary,this,Ti);this.hardware=new nm(Ti,Mu,j)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}c(uu,"connectivity",ql);const av=ct.Authority,Pn=(r,e,t="")=>{try{return r.parse(e)}catch(s){if(s instanceof i.z.ZodError){const n=s.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${t} - ${n.join(`
|
|
66
|
+
`)}`)}else throw s}};var ov=Object.defineProperty,lv=(r,e,t)=>e in r?ov(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,se=(r,e,t)=>lv(r,typeof e!="symbol"?e+"":e,t);const Un=class cu{constructor(e,t,s="",n=!1){se(this,"_noop",!1),se(this,"key"),se(this,"path"),se(this,"serviceName"),this.key=e,this.path=t,this.serviceName=s,this._noop=n}child(e){return new cu(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};se(Un,"NOOP",new Un("","",""));let gi=Un;const Ln=["debug","info","warn","error"],uv=r=>{const e=Ln.indexOf(r);return({level:t})=>Ln.indexOf(t)>=e},cv=r=>{const{include:e,exclude:t}=r;return({path:s})=>!(e!=null&&!e.some(n=>s.startsWith(n))||t!=null&&t.some(n=>s.startsWith(n)))},_n=class hu{constructor(e={}){se(this,"meta",gi.NOOP),se(this,"filters");const{filters:t=[]}=e;this.filters=t}filter(e){return!this.meta.noop&&this.filters.every(t=>t({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const t=new hu({filters:this.filters});return t.meta=e,t}debug(e,t,s=!1){!this.filter("debug")&&!s||(t==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,zr(t)))}info(e,t,s=!1){!this.filter("info")&&!s||(t==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,zr(t)))}warn(e,t,s=!1){!this.filter("warn")&&!s||(t==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,zr(t)))}error(e,t,s=!1){!this.filter("error")&&!s||(t==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,zr(t)))}};se(_n,"NOOP",new _n);let du=_n;const zr=r=>typeof r=="function"?r():r;var hv=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},Xe="1.9.0",Da=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function dv(r){var e=new Set([r]),t=new Set,s=r.match(Da);if(!s)return function(){return!1};var n={major:+s[1],minor:+s[2],patch:+s[3],prerelease:s[4]};if(n.prerelease!=null)return function(u){return u===r};function a(u){return t.add(u),!1}function o(u){return e.add(u),!0}return function(u){if(e.has(u))return!0;if(t.has(u))return!1;var l=u.match(Da);if(!l)return a(u);var d={major:+l[1],minor:+l[2],patch:+l[3],prerelease:l[4]};return d.prerelease!=null||n.major!==d.major?a(u):n.major===0?n.minor===d.minor&&n.patch<=d.patch?o(u):a(u):n.minor<=d.minor?o(u):a(u)}}var fv=dv(Xe),pv=Xe.split(".")[0],tr=Symbol.for("opentelemetry.js.api."+pv),rr=hv;function yi(r,e,t,s){var n;s===void 0&&(s=!1);var a=rr[tr]=(n=rr[tr])!==null&&n!==void 0?n:{version:Xe};if(!s&&a[r]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+r);return t.error(o.stack||o.message),!1}if(a.version!==Xe){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+r+" does not match previously registered API v"+Xe);return t.error(o.stack||o.message),!1}return a[r]=e,t.debug("@opentelemetry/api: Registered a global for "+r+" v"+Xe+"."),!0}function sr(r){var e,t,s=(e=rr[tr])===null||e===void 0?void 0:e.version;if(!(!s||!fv(s)))return(t=rr[tr])===null||t===void 0?void 0:t[r]}function mi(r,e){e.debug("@opentelemetry/api: Unregistering a global for "+r+" v"+Xe+".");var t=rr[tr];t&&delete t[r]}var gv=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),n,a=[],o;try{for(;(e===void 0||e-- >0)&&!(n=s.next()).done;)a.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return a},yv=function(r,e,t){if(arguments.length===2)for(var s=0,n=e.length,a;s<n;s++)(a||!(s in e))&&(a||(a=Array.prototype.slice.call(e,0,s)),a[s]=e[s]);return r.concat(a||Array.prototype.slice.call(e))},mv=function(){function r(e){this._namespace=e.namespace||"DiagComponentLogger"}return r.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Nt("debug",this._namespace,e)},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Nt("error",this._namespace,e)},r.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Nt("info",this._namespace,e)},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Nt("warn",this._namespace,e)},r.prototype.verbose=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Nt("verbose",this._namespace,e)},r}();function Nt(r,e,t){var s=sr("diag");if(s)return t.unshift(e),s[r].apply(s,yv([],gv(t),!1))}var ve;(function(r){r[r.NONE=0]="NONE",r[r.ERROR=30]="ERROR",r[r.WARN=50]="WARN",r[r.INFO=60]="INFO",r[r.DEBUG=70]="DEBUG",r[r.VERBOSE=80]="VERBOSE",r[r.ALL=9999]="ALL"})(ve||(ve={}));function wv(r,e){r<ve.NONE?r=ve.NONE:r>ve.ALL&&(r=ve.ALL),e=e||{};function t(s,n){var a=e[s];return typeof a=="function"&&r>=n?a.bind(e):function(){}}return{error:t("error",ve.ERROR),warn:t("warn",ve.WARN),info:t("info",ve.INFO),debug:t("debug",ve.DEBUG),verbose:t("verbose",ve.VERBOSE)}}var bv=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),n,a=[],o;try{for(;(e===void 0||e-- >0)&&!(n=s.next()).done;)a.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return a},vv=function(r,e,t){if(arguments.length===2)for(var s=0,n=e.length,a;s<n;s++)(a||!(s in e))&&(a||(a=Array.prototype.slice.call(e,0,s)),a[s]=e[s]);return r.concat(a||Array.prototype.slice.call(e))},Ov="diag",nr=function(){function r(){function e(n){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var u=sr("diag");if(u)return u[n].apply(u,vv([],bv(a),!1))}}var t=this,s=function(n,a){var o,u,l;if(a===void 0&&(a={logLevel:ve.INFO}),n===t){var d=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return t.error((o=d.stack)!==null&&o!==void 0?o:d.message),!1}typeof a=="number"&&(a={logLevel:a});var f=sr("diag"),h=wv((u=a.logLevel)!==null&&u!==void 0?u:ve.INFO,n);if(f&&!a.suppressOverrideMessage){var I=(l=new Error().stack)!==null&&l!==void 0?l:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+I),h.warn("Current logger will overwrite one already registered from "+I)}return yi("diag",h,t,!0)};t.setLogger=s,t.disable=function(){mi(Ov,t)},t.createComponentLogger=function(n){return new mv(n)},t.verbose=e("verbose"),t.debug=e("debug"),t.info=e("info"),t.warn=e("warn"),t.error=e("error")}return r.instance=function(){return this._instance||(this._instance=new r),this._instance},r}(),Tv=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),n,a=[],o;try{for(;(e===void 0||e-- >0)&&!(n=s.next()).done;)a.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return a},Sv=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],s=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&s>=r.length&&(r=void 0),{value:r&&r[s++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},zv=function(){function r(e){this._entries=e?new Map(e):new Map}return r.prototype.getEntry=function(e){var t=this._entries.get(e);if(t)return Object.assign({},t)},r.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var t=Tv(e,2),s=t[0],n=t[1];return[s,n]})},r.prototype.setEntry=function(e,t){var s=new r(this._entries);return s._entries.set(e,t),s},r.prototype.removeEntry=function(e){var t=new r(this._entries);return t._entries.delete(e),t},r.prototype.removeEntries=function(){for(var e,t,s=[],n=0;n<arguments.length;n++)s[n]=arguments[n];var a=new r(this._entries);try{for(var o=Sv(s),u=o.next();!u.done;u=o.next()){var l=u.value;a._entries.delete(l)}}catch(d){e={error:d}}finally{try{u&&!u.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return a},r.prototype.clear=function(){return new r},r}();nr.instance();function Nv(r){return r===void 0&&(r={}),new zv(new Map(Object.entries(r)))}function Ev(r){return Symbol.for(r)}var Iv=function(){function r(e){var t=this;t._currentContext=e?new Map(e):new Map,t.getValue=function(s){return t._currentContext.get(s)},t.setValue=function(s,n){var a=new r(t._currentContext);return a._currentContext.set(s,n),a},t.deleteValue=function(s){var n=new r(t._currentContext);return n._currentContext.delete(s),n}}return r}(),xv=new Iv,Av={get:function(r,e){if(r!=null)return r[e]},keys:function(r){return r==null?[]:Object.keys(r)}},kv={set:function(r,e,t){r!=null&&(r[e]=t)}},Cv=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),n,a=[],o;try{for(;(e===void 0||e-- >0)&&!(n=s.next()).done;)a.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return a},Rv=function(r,e,t){if(arguments.length===2)for(var s=0,n=e.length,a;s<n;s++)(a||!(s in e))&&(a||(a=Array.prototype.slice.call(e,0,s)),a[s]=e[s]);return r.concat(a||Array.prototype.slice.call(e))},$v=function(){function r(){}return r.prototype.active=function(){return xv},r.prototype.with=function(e,t,s){for(var n=[],a=3;a<arguments.length;a++)n[a-3]=arguments[a];return t.call.apply(t,Rv([s],Cv(n),!1))},r.prototype.bind=function(e,t){return t},r.prototype.enable=function(){return this},r.prototype.disable=function(){return this},r}(),Mv=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),n,a=[],o;try{for(;(e===void 0||e-- >0)&&!(n=s.next()).done;)a.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return a},Dv=function(r,e,t){if(arguments.length===2)for(var s=0,n=e.length,a;s<n;s++)(a||!(s in e))&&(a||(a=Array.prototype.slice.call(e,0,s)),a[s]=e[s]);return r.concat(a||Array.prototype.slice.call(e))},cn="context",Bv=new $v,fu=function(){function r(){}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalContextManager=function(e){return yi(cn,e,nr.instance())},r.prototype.active=function(){return this._getContextManager().active()},r.prototype.with=function(e,t,s){for(var n,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(n=this._getContextManager()).with.apply(n,Dv([e,t,s],Mv(a),!1))},r.prototype.bind=function(e,t){return this._getContextManager().bind(e,t)},r.prototype._getContextManager=function(){return sr(cn)||Bv},r.prototype.disable=function(){this._getContextManager().disable(),mi(cn,nr.instance())},r}(),qn;(function(r){r[r.UNSET=0]="UNSET",r[r.OK=1]="OK",r[r.ERROR=2]="ERROR"})(qn||(qn={}));var jv=fu.getInstance(),Pv=function(){function r(){}return r.prototype.inject=function(e,t){},r.prototype.extract=function(e,t){return e},r.prototype.fields=function(){return[]},r}(),wi=Ev("OpenTelemetry Baggage Key");function pu(r){return r.getValue(wi)||void 0}function Uv(){return pu(fu.getInstance().active())}function Lv(r,e){return r.setValue(wi,e)}function _v(r){return r.deleteValue(wi)}var hn="propagation",qv=new Pv,Yv=function(){function r(){this.createBaggage=Nv,this.getBaggage=pu,this.getActiveBaggage=Uv,this.setBaggage=Lv,this.deleteBaggage=_v}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalPropagator=function(e){return yi(hn,e,nr.instance())},r.prototype.inject=function(e,t,s){return s===void 0&&(s=kv),this._getGlobalPropagator().inject(e,t,s)},r.prototype.extract=function(e,t,s){return s===void 0&&(s=Av),this._getGlobalPropagator().extract(e,t,s)},r.prototype.fields=function(){return this._getGlobalPropagator().fields()},r.prototype.disable=function(){mi(hn,nr.instance())},r.prototype._getGlobalPropagator=function(){return sr(hn)||qv},r}(),Fv=Yv.getInstance();const Ba=["bench","debug","prod"],Gv=r=>e=>Ba.indexOf(e)>=Ba.indexOf(r),Yn=class gu{constructor(e,t=Gv("debug")){se(this,"meta",gi.NOOP),se(this,"tracer"),se(this,"filter"),this.tracer=e,this.filter=t}child(e){const t=new gu(this.tracer,this.filter);return t.meta=e,t}debug(e,t){return this.trace(e,"debug",t)}bench(e,t){return this.trace(e,"bench",t)}prod(e,t){return this.trace(e,"prod",t)}trace(e,t,s){return this.meta.noop||!this.filter(t)?s(new wu(e)):this.tracer.startActiveSpan(e,n=>{const a=new mu(e,n),o=s(a);return n.end(),o})}propagate(e){if(this.meta.noop)return;const t=jv.active();Fv.inject(t,e,{set:(s,n,a)=>{s[n]=a}})}};se(Yn,"NOOP",new Yn);let yu=Yn;class mu{constructor(e,t){se(this,"key"),se(this,"otel"),this.key=e,this.otel=t}set(e,t){this.otel.setAttribute(e,t)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:qn.ERROR}))}}class wu{constructor(e){se(this,"key"),this.key=e}set(){}recordError(e){}}const Fn=class bu{constructor({key:e="",serviceName:t="",logger:s=du.NOOP,tracer:n=yu.NOOP,noop:a=!1,__meta:o}){se(this,"meta"),se(this,"T"),se(this,"L"),this.meta=o??new gi(e,e,t,a),this.T=n.child(this.meta),this.L=s.child(this.meta)}child(e){const t=this.meta.child(e);return new bu({__meta:t,tracer:this.T,logger:this.L})}};se(Fn,"NOOP",new Fn({noop:!0}));let bi=Fn;const Vv=bi.NOOP,vu=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:bi,LOG_LEVELS:Ln,Logger:du,NOOP:Vv,NoopSpan:wu,Tracer:yu,_Span:mu,logLevelKeyFiler:cv,logThresholdFilter:uv},Symbol.toStringTag,{value:"Module"})),Wv=new Error("request for lock canceled");var Zv=function(r,e,t,s){function n(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function u(f){try{d(s.next(f))}catch(h){o(h)}}function l(f){try{d(s.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):n(f.value).then(u,l)}d((s=s.apply(r,e||[])).next())})};class Jv{constructor(e,t=Wv){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,n)=>{const a={resolve:s,reject:n,weight:e,priority:t},o=Ou(this._queue,u=>t<=u.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Zv(this,arguments,void 0,function*(t,s=1,n=0){const[a,o]=yield this.acquire(s,n);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Kv(this._weightedWaiters[e-1],{resolve:s,priority:t})})}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 t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(s=>s.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const s=this._weightedWaiters[t-1];if(!s)continue;const n=s.findIndex(a=>a.priority<=e);(n===-1?s:s.splice(0,n)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function Kv(r,e){const t=Ou(r,s=>e.priority<=s.priority);r.splice(t+1,0,e)}function Ou(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Hv=function(r,e,t,s){function n(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function u(f){try{d(s.next(f))}catch(h){o(h)}}function l(f){try{d(s.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):n(f.value).then(u,l)}d((s=s.apply(r,e||[])).next())})};class vi{constructor(e){this._semaphore=new Jv(1,e)}acquire(){return Hv(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}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 $s{constructor(e,t,s=new Map){T(this,"providers");T(this,"registry");T(this,"sender");T(this,"changedKeys");this.providers=s,this.registry=t,this.changedKeys=[],this.sender=e}propagateState(e,t,s=[]){this.sender.send({key:e,state:t},s)}copyAndMerge(e){const t=new $s(this.sender,this.registry,new Map);return e==null||e.providers.forEach((s,n)=>t.providers.set(n,s)),this.providers.forEach((s,n)=>t.providers.set(n,s)),t.changedKeys=[],t}get changed(){return this.changedKeys.length>0}set(e,t,s=!0){this.providers.set(e,t),s&&this.changedKeys.push(e)}setIfNotHas(e,t){this.providers.has(e)||this.set(e,t)}async create(e){const t=this.registry[e.type];if(t==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const s=new t(e);return await s.internalUpdate(e),s}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const t=this.getOptional(e);if(t==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return t}}class Ms{constructor(e){T(this,"type");T(this,"key");T(this,"_ctx");T(this,"_internalState");T(this,"_state");T(this,"_prevState");T(this,"_deleted",!1);T(this,"instrumentation");T(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 Q(`[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 t=Zn(e,this._state);this._prevState={...this._state},this._state=Pn(this._schema,t,`${this.type}:${this.key}`),this.ctx.propagateState(this.key,t)}get ctx(){if(this._ctx==null)throw new Oe("context not defined");return this._ctx}get state(){if(this._state==null)throw new Oe("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:t,ctx:s,state:n}){if(!this.deleted){if(this._ctx=s,e==="state"){this.validatePath(t);const a=Pn(this._schema,n,`${this.type}:${this.key}`);this._state!=null?this.instrumentation.L.debug("updating state",()=>({diff:so.difference(this.state,a)})):this.instrumentation.L.debug("setting initial state",{state:n}),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 Oe(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const t=e[e.length-1];if(e.length>1)throw new Oe(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(t!==this.key)throw new Oe(`[Leaf.setState] - ${this.type}:${this.key} received a key ${t} but expected ${this.key}`)}}class yr extends Ms{constructor(t){super(t);T(this,"_children");this._children=new Map}get children(){return Array.from(this._children.values())}async internalUpdate(t){const{variant:s,path:n}=t;if(s==="context")return this._ctx=t.ctx.copyAndMerge(this._ctx),await this.updateContext({...t,ctx:this.ctx});const[a,o]=this.getRequiredKey(n),u={...t,ctx:this.ctx};return o.length===0?await this.updateThis(a,u):await this.updateChild(o,u)}async updateContext(t){await super.internalUpdate(t);for(const s of this.children)await s.internalUpdate({...t,ctx:this.ctx,variant:"context"})}async updateChild(t,s){const n=t[0],a=this.getChild(n);if(a!=null)return await a.internalUpdate({...s,path:t});if(t.length>1)throw new Error(`[Composite.setState] - ${this.type}:${this.key} could not find child with key ${n} while updating `);this._children.set(n,await s.ctx.create({...s,path:t}))}async updateThis(t,s){const n=s.ctx.copyAndMerge(this._ctx);if(t!==this.key)throw new Oe(`[Composite.update] - ${this.type}:${this.key} received a key ${t} but expected ${this.key}`);if(await super.internalUpdate({...s,ctx:n}),!!n.changed){this.instrumentation.L.debug("context changed",{changedKeys:n.changedKeys});for(const a of this.children)await a.internalUpdate({...s,ctx:this.ctx,variant:"context"})}}async internalDelete(t){const[s,n]=this.getRequiredKey(t);if(n.length===0){if(s!==this.key)throw new Error(`[Composite.delete] - ${this.type}:${this.key} received a key ${s} but expected ${this.key}`);const o=this.children;this._children=new Map;for(const u of o)await u.internalDelete([u.key]);await super.internalDelete([this.key])}const a=this.getChild(n[0]);a!=null&&(n.length>1?await a.internalDelete(n):(this._children.delete(a.key),await a.internalDelete(n)))}getRequiredKey(t,s){const[n,...a]=t;if(n==null)throw new Error(`Composite ${this.type}:${this.key} received an empty path${s!=null?` for ${s}`:""}`);return[n,a]}getChild(t){return this._children.get(t)??null}childrenOfType(...t){return this.children.filter(s=>t.includes(s.type))}}const Xv=i.z.object({}),$e=class $e extends yr{constructor({worker:t,registry:s,instrumentation:n=vu.Instrumentation.NOOP}){const o={ctx:new $s(t,s,new Map),...$e.ZERO_UPDATE,instrumentation:n};super(o);T(this,"wrap");T(this,"schema",$e.schema);T(this,"mu",new vi);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=t,this.wrap.handle(u=>{this.mu.runExclusive(async()=>await this.handle(u))})}async handle(t){if(t.variant==="delete")await this.internalDelete(t.path);else{const s={...t,variant:"state",ctx:this.ctx,instrumentation:this.instrumentation};await this.internalUpdate(s)}}};T($e,"TYPE","root"),T($e,"KEY","root"),T($e,"ZERO_UPDATE",{path:[$e.KEY],type:$e.TYPE,variant:"state",state:{}}),T($e,"schema",Xv);let fs=$e;const Tu=r=>new fs(r),Qv=Object.freeze(Object.defineProperty({__proto__:null,Composite:yr,Context:$s,Leaf:Ms,Root:fs,render:Tu},Symbol.toStringTag,{value:"Module"})),ss=(r,e)=>p.Mt.construct(p.Mt.left(r)-e.x,p.Mt.top(r)-e.y,p.Mt.width(r)+e.x*2,p.Mt.height(r)+e.y*2);class ps{constructor(e,t=p.b.XY.IDENTITY){T(this,"scale_");T(this,"wrapped");this.wrapped=e,this.scale_=t}get fontStretch(){return this.wrapped.fontStretch}set fontStretch(e){this.wrapped.fontStretch=e}get fontVariantCaps(){return this.wrapped.fontVariantCaps}set fontVariantCaps(e){this.wrapped.fontVariantCaps=e}isContextLost(){return this.wrapped.isContextLost()}get wordSpacing(){return this.wrapped.wordSpacing}set wordSpacing(e){this.wrapped.wordSpacing=e}get letterSpacing(){return this.wrapped.letterSpacing}set letterSpacing(e){this.wrapped.letterSpacing=e}get textRendering(){return this.wrapped.textRendering}set textRendering(e){this.wrapped.textRendering=e}reset(){this.wrapped.reset()}applyScale(e){return new ps(this,e)}get canvas(){return this.wrapped.canvas}get miterLimit(){return this.wrapped.miterLimit}set miterLimit(e){this.wrapped.miterLimit=this.scale_.x.dim(e)}get globalAlpha(){return this.wrapped.globalAlpha}set globalAlpha(e){this.wrapped.globalAlpha=e}get globalCompositeOperation(){return this.wrapped.globalCompositeOperation}set globalCompositeOperation(e){this.wrapped.globalCompositeOperation=e}get fillStyle(){return this.wrapped.fillStyle}set fillStyle(e){this.wrapped.fillStyle=e}get strokeStyle(){return this.wrapped.strokeStyle}set strokeStyle(e){this.wrapped.strokeStyle=e}drawImage(e,t,s,n,a,o,u,l,d){this.wrapped.drawImage(e,t,s,n,a,o,u,l,d)}beginPath(){this.wrapped.beginPath()}clip(e,t){this.wrapped.clip(e,t)}fill(e,t){if(e==null)return this.wrapped.fill();this.wrapped.fill(e,t)}isPointInPath(e,t,s,n){return this.wrapped.isPointInPath(e,t,s,n)}isPointInStroke(e,t,s){return this.wrapped.isPointInStroke(e,t,s)}stroke(e){if(e==null)return this.wrapped.stroke();this.wrapped.stroke(e)}createConicGradient(e,t,s){return this.wrapped.createConicGradient(e,t,s)}createLinearGradient(e,t,s,n){return this.wrapped.createLinearGradient(e,t,s,n)}createPattern(e,t){return this.wrapped.createPattern(e,t)}createRadialGradient(e,t,s,n,a,o){return this.wrapped.createRadialGradient(e,t,s,n,a,o)}get filter(){return this.wrapped.filter}set filter(e){this.wrapped.filter=e}createImageData(e,t,s){return this.wrapped.createImageData(e,t,s)}getImageData(e,t,s,n,a){return this.wrapped.getImageData(e,t,s,n,a)}putImageData(e,t,s,n,a,o,u){this.wrapped.putImageData(e,t,s,n,a,o,u)}get imageSmoothingEnabled(){return this.wrapped.imageSmoothingEnabled}set imageSmoothingEnabled(e){this.wrapped.imageSmoothingEnabled=e}get imageSmoothingQuality(){return this.wrapped.imageSmoothingQuality}set imageSmoothingQuality(e){this.wrapped.imageSmoothingQuality=e}arc(e,t,s,n,a,o){this.wrapped.arc(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),n,a,o)}arcTo(e,t,s,n,a){this.wrapped.arcTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n),this.scale_.x.dim(a))}bezierCurveTo(e,t,s,n,a,o){this.wrapped.bezierCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n),this.scale_.x.pos(a),this.scale_.y.pos(o))}closePath(){this.wrapped.closePath()}ellipse(e,t,s,n,a,o,u,l){this.wrapped.ellipse(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n),a,o,u,l)}lineTo(e,t){this.wrapped.lineTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}moveTo(e,t){this.wrapped.moveTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}quadraticCurveTo(e,t,s,n){this.wrapped.quadraticCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n))}rect(e,t,s,n){this.wrapped.rect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n))}roundRect(e,t,s,n,a){this.wrapped.roundRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n),typeof a=="number"?this.scale_.x.dim(a):a)}get lineCap(){return this.wrapped.lineCap}set lineCap(e){this.wrapped.lineCap=e}get lineDashOffset(){return this.wrapped.lineDashOffset}set lineDashOffset(e){this.wrapped.lineDashOffset=this.scale_.x.dim(e)}get lineJoin(){return this.wrapped.lineJoin}set lineJoin(e){this.wrapped.lineJoin=e}get lineWidth(){return this.wrapped.lineWidth}set lineWidth(e){this.wrapped.lineWidth=this.scale_.x.dim(e)}getLineDash(){return this.wrapped.getLineDash()}setLineDash(e){const t=Array.from(e).map(s=>this.scale_.x.dim(s));this.wrapped.setLineDash(t)}clearRect(e,t,s,n){this.wrapped.clearRect(e,t,s,n)}fillRect(e,t,s,n){this.wrapped.fillRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n))}strokeRect(e,t,s,n){this.wrapped.strokeRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n))}get shadowBlur(){return this.wrapped.shadowBlur}set shadowBlur(e){this.wrapped.shadowBlur=e}get shadowColor(){return this.wrapped.shadowColor}set shadowColor(e){this.wrapped.shadowColor=e}get shadowOffsetX(){return this.wrapped.shadowOffsetX}set shadowOffsetX(e){this.wrapped.shadowOffsetX=e}get shadowOffsetY(){return this.wrapped.shadowOffsetY}restore(){this.wrapped.restore()}save(){this.wrapped.save()}fillText(e,t,s,n){this.wrapped.fillText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),n!=null?this.scale_.x.dim(n):void 0)}measureText(e){this.wrapped.font=dn(this.wrapped.font,this.scale_.x.reverse());const t=this.wrapped.measureText(e);return this.wrapped.font=dn(this.wrapped.font,this.scale_.x),t}strokeText(e,t,s,n){this.wrapped.strokeText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),n!=null?this.scale_.x.dim(n):void 0)}get direction(){return this.wrapped.direction}set direction(e){this.wrapped.direction=e}get font(){return this.wrapped.font}set font(e){this.wrapped.font=dn(e,this.scale_.x)}get fontKerning(){return this.wrapped.fontKerning}set fontKerning(e){this.wrapped.fontKerning=e}get textAlign(){return this.wrapped.textAlign}set textAlign(e){this.wrapped.textAlign=e}get textBaseline(){return this.wrapped.textBaseline}set textBaseline(e){this.wrapped.textBaseline=e}getTransform(){return this.wrapped.getTransform()}resetTransform(){this.wrapped.resetTransform()}rotate(e){this.wrapped.rotate(e)}scale(e,t){this.wrapped.scale(e,t)}scissor(e,t=p.G.ZERO){const s=new eO(this.scale_);return e=ss(e,t),s.rect(...p.G.couple(p.Mt.topLeft(e)),...p._.couple(p.Mt.dims(e))),this.save(),this.clip(s.getPath()),()=>this.restore()}setTransform(e,t,s,n,a,o){this.wrapped.setTransform(e,t,s,n,a,o)}transform(e,t,s,n,a,o){this.wrapped.transform(e,t,s,n,a,o)}translate(e,t){this.wrapped.translate(e,t)}}const ja=/(\d+(\.\d+)?)px/,dn=(r,e)=>{var n;const t=Number((n=r.match(ja))==null?void 0:n[1]);if(t==null)return r;const s=e.dim(t);return r.replace(ja,`${s}px`)};class eO{constructor(e=p.b.XY.IDENTITY,t){T(this,"scale_");T(this,"path");this.scale_=e,t instanceof Path2D||typeof t=="string"?this.path=new Path2D(t):this.path=new Path2D}addPath(e,t){this.path.addPath(e,t)}arc(e,t,s,n,a,o){this.path.arc(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),n,a,o)}arcTo(e,t,s,n,a){this.path.arcTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n),this.scale_.x.dim(a))}bezierCurveTo(e,t,s,n,a,o){this.path.bezierCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n),this.scale_.x.pos(a),this.scale_.y.pos(o))}closePath(){this.path.closePath()}ellipse(e,t,s,n,a,o,u,l){this.path.ellipse(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n),a,o,u,l)}lineTo(e,t){this.path.lineTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}moveTo(e,t){this.path.moveTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}quadraticCurveTo(e,t,s,n){this.path.quadraticCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(n))}rect(e,t,s,n){this.path.rect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n))}roundRect(e,t,s,n,a){const o=this.scaleRadii(a);this.path.roundRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(n),o)}scaleRadii(e){return e==null?e:typeof e=="number"?this.scale_.x.dim(e):Array.isArray(e)?e.map(t=>this.scaleRadius(t)):this.scaleRadius(e)}scaleRadius(e){return typeof e=="number"?this.scale_.x.dim(e):{x:this.scale_.x.dim(e.x??0),y:this.scale_.y.dim(e.y??0)}}getPath(){return this.path}}const tO=`precision mediump float;
|
|
68
|
+
|
|
69
|
+
void main(void) {
|
|
70
|
+
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
|
71
|
+
}
|
|
72
|
+
`,rO=`attribute vec4 a_position;
|
|
73
|
+
|
|
74
|
+
void main(void) {
|
|
75
|
+
gl_Position = a_position;
|
|
76
|
+
}
|
|
77
|
+
`,Pa=r=>new Error(`failed to compile webgl program: ${r}`),sO=new Error("null shader encountered");let Su=class{constructor(e,t,s){T(this,"ctx");T(this,"prog");T(this,"vertShader");T(this,"fragShader");T(this,"uniformLocCache",new Map);this.ctx=e;const n=e.gl.createProgram();if(n==null)throw Pa("failed to create program");this.prog=n,this.vertShader=t,this.fragShader=s,this.compile()}setAsActive(){return this.ctx.gl.useProgram(this.prog),()=>this.ctx.gl.useProgram(null)}uniformXY(e,t){this.ctx.gl.uniform2fv(this.getUniformLoc(e),p.G.couple(p.G.construct(t)))}uniformColor(e,t){this.ctx.gl.uniform4fv(this.getUniformLoc(e),t.rgba1)}getUniformLoc(e){const t=this.uniformLocCache.get(e);if(t!=null)return t;const s=this.ctx.gl.getUniformLocation(this.prog,e);if(s==null)throw new Error(`unexpected missing uniform ${e}`);return this.uniformLocCache.set(e,s),s}compile(){const e=this.ctx.gl;this.compileShader(this.vertShader,e.VERTEX_SHADER),this.compileShader(this.fragShader,e.FRAGMENT_SHADER),e.linkProgram(this.prog)}compileShader(e,t){const s=this.ctx.gl,n=s.createShader(t);if(n==null)throw sO;if(s.shaderSource(n,e),s.compileShader(n),!s.getShaderParameter(n,s.COMPILE_STATUS)){const o=s.getShaderInfoLog(n);throw s.deleteShader(n),Pa(o??"unknown")}s.attachShader(this.prog,n)}};const nO=new Float32Array([0,0,0,0,0,0]);class iO extends Su{constructor(t){super(t,rO,tO);T(this,"positionBuffer");const s=t.gl.createBuffer();if(s==null)throw new Oe("webgl: failed to create buffer");this.positionBuffer=s,t.gl.bindBuffer(t.gl.ARRAY_BUFFER,this.positionBuffer),t.gl.bufferData(t.gl.ARRAY_BUFFER,nO,t.gl.STATIC_DRAW)}exec(){const{gl:t}=this.ctx,s=t.getAttribLocation(this.prog,"a_position");t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer);const n=t.createVertexArray();t.bindVertexArray(n),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),this.setAsActive(),t.drawArrays(t.TRIANGLES,0,3)}}const Ua={high:1,low:0},La=ns.hz(45);class zu{constructor(e){T(this,"mutex",new vi);T(this,"requests",new Map);T(this,"cleanup",new Map);T(this,"afterRender");this.start(),this.afterRender=e}async set(e){let t;e.priority==="high"&&(t=await this.mutex.acquire());const s=this.requests.get(e.key);if(s==null)this.requests.set(e.key,e);else{const n=Ua[e.priority]>=Ua[s.priority],a=e.canvases.length>=s.canvases.length;n&&a&&this.requests.set(e.key,e)}t==null||t()}async render(){await this.mutex.runExclusive(async()=>{var a;const e=performance.now(),{requests:t}=this;if(t.size===0)return;await this.runCleanupsSync(),await this.renderSync();const s=performance.now(),n=Z.milliseconds(s-e);n.greaterThan(La.period)&&console.warn(`Render loop for ${this.requests.size} took longer than ${La.period.toString()} to execute: ${n.milliseconds}`),this.requests.clear(),(a=this.afterRender)==null||a.call(this)})}async runCleanupsSync(){const{cleanup:e,requests:t}=this;for(const[s,n]of e.entries()){const a=t.get(s);a!=null&&(await n(a),e.delete(s))}}async renderSync(){const{requests:e}=this;for(const t of e.values())try{const s=await t.render();s!=null&&this.cleanup.set(t.key,s)}catch(s){console.error(s)}}async start(){do{try{await this.render()}catch(e){console.error(e)}await this.sleep()}while(!0)}async sleep(){return await new Promise(requestAnimationFrame)}}const _a=r=>(r.textRendering="optimizeSpeed",r.imageSmoothingEnabled=!1,r);var ze;let Nu=(ze=class{constructor(e,t,s,n){T(this,"glCanvas");T(this,"upper2dCanvas");T(this,"lower2dCanvas");T(this,"gl");T(this,"lower2d");T(this,"upper2d");T(this,"region");T(this,"dpr");T(this,"loop");T(this,"clearProgram");T(this,"os");this.upper2dCanvas=s,this.lower2dCanvas=t,this.glCanvas=e,this.os=n;const a=this.lower2dCanvas.getContext("2d");if(a==null)throw new Error("Could not get 2D context");this.lower2d=_a(new ps(a));const o=this.upper2dCanvas.getContext("2d");if(o==null)throw new Error("Could not get 2D context");this.upper2d=_a(new ps(o));const u={preserveDrawingBuffer:!0,powerPreference:"high-performance",stencil:!1,depth:!1},l=this.glCanvas.getContext("webgl2",u);if(l==null)throw new Error("Could not get WebGL context");l.disable(l.DEPTH_TEST),l.disable(l.STENCIL_TEST),l.disable(l.CULL_FACE),l.disable(l.DITHER),this.gl=l,this.glCanvas.oncontextlost=console.log;const d=()=>{this.gl.flush(),this.gl.finish()};this.loop=new zu(d),this.region=p.Mt.ZERO,this.dpr=1,this.os==="Windows"&&(this.clearProgram=new iO(this))}static create(e,t,s,n,a){const o=new ze(t,s,n,a);return e.set(ze.CONTEXT_KEY,o),o}static useOptional(e){return e.getOptional(ze.CONTEXT_KEY)}static use(e){return e.get(ze.CONTEXT_KEY)}update(e){e.set(ze.CONTEXT_KEY,this)}resize(e,t){p.Mt.equals(this.region,e)&&this.dpr===t||(this.region=e,this.dpr=t,this.resizeCanvas(this.glCanvas),this.resizeCanvas(this.upper2dCanvas),this.resizeCanvas(this.lower2dCanvas),this.lower2d.scale(this.dpr,this.dpr),this.upper2d.scale(this.dpr,this.dpr),this.gl.viewport(0,0,p.Mt.width(e)*t,p.Mt.height(e)*t))}resizeCanvas(e){e.width=p.Mt.width(this.region)*this.dpr,e.height=p.Mt.height(this.region)*this.dpr}get aspect(){return p.Mt.aspect(this.region)}scaleRegion(e){return new p.b.XY(p.b.Scale.scale(0,1).scale(p.Mt.width(e)).translate(p.Mt.left(e)).reBound(p.Mt.width(this.region)).scale(-1,1),p.b.Scale.scale(0,1).scale(p.Mt.height(e)).invert().translate(p.Mt.top(e)).reBound(p.Mt.height(this.region)).scale(-1,1).invert())}scissor(e,t=p.G.ZERO,s){const n=[];return s.includes("upper2d")&&n.push(this.upper2d.scissor(e,t)),s.includes("lower2d")&&n.push(this.lower2d.scissor(e,t)),s.includes("gl")&&n.push(this.scissorGL(e,t)),()=>n.forEach(a=>a())}scissorGL(e,t=p.G.ZERO){return this.gl.enable(this.gl.SCISSOR_TEST),e=ss(e,t),this.gl.scissor(p.Mt.left(e)*this.dpr,(p.Mt.height(this.region)-p.Mt.bottom(e))*this.dpr,p.Mt.width(e)*this.dpr,p.Mt.height(e)*this.dpr),()=>this.gl.disable(this.gl.SCISSOR_TEST)}erase(e,t=p.G.ZERO,...s){t=p.G.construct(t),s.length===0&&(s=["upper2d","lower2d","gl"]),s.includes("upper2d")&&this.eraseCanvas(this.upper2d,e,t),s.includes("lower2d")&&this.eraseCanvas(this.lower2d,e,t),s.includes("gl")&&this.eraseGL(e,t)}eraseGL(e,t=p.G.ZERO){var a;const{gl:s}=this,n=this.scissorGL(ss(e,t));s.clearColor(...p.ZERO.rgba1),s.clear(s.COLOR_BUFFER_BIT),this.os==="Windows"&&((a=this.clearProgram)==null||a.exec()),n()}eraseCanvas(e,t,s=p.G.ZERO){const n=ss(t,s);e.clearRect(...p.G.couple(p.Mt.topLeft(n)),...p._.couple(p.Mt.dims(n)))}},T(ze,"CONTEXT_KEY",p.CSS.B("render-context")),ze),Eu=class{constructor(){T(this,"prevErase",p.Mt.ZERO)}erase(e,t,s,n,a){!p.Mt.equals(s,t)&&!p.Mt.equals(this.prevErase,s)?(e.erase(s,n,...a),this.prevErase=s):e.erase(t,n,...a)}};const Iu=i.z.object({region:p.Mt.box,enabled:i.z.boolean().optional().default(!1)});class gs extends Ms{constructor(){super(...arguments);T(this,"schema",Iu);T(this,"eraser",new Eu)}async afterUpdate(){this.deleted||(this.internal.render=Nu.use(this.ctx),await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]}))}async afterDelete(){await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]})}async render(){this.deleted||!this.state.enabled||this.internal.render.erase(this.state.region,p.G.construct(0),"gl","lower2d","upper2d")}}T(gs,"TYPE","eraser");const aO={[gs.TYPE]:gs},xu="pluto-theming-context",Au=i.z.object({name:i.z.string(),url:i.z.string()}),oO=i.z.object({theme:wo,fontURLs:i.z.array(Au)}),Ht=class Ht extends yr{constructor(){super(...arguments);T(this,"schema",Ht.z)}async afterUpdate(){this.ctx.set(xu,this.state.theme),await this.loadFonts()}async loadFonts(){await Promise.all(this.state.fontURLs.map(async({name:t,url:s})=>{const n=new FontFace(t,`url(${s})`);await n.load(),self.fonts.add(n)}))}};T(Ht,"TYPE","theming.Provider"),T(Ht,"z",oO);let ir=Ht;const lO=r=>r.get(xu),uO={[ir.TYPE]:ir},ku=["success","error","warning","info","loading","disabled","secondary"],Cu=i.z.enum(ku),Ru=i.z.object({key:i.z.string(),variant:Cu,message:i.z.string(),description:i.z.string().optional(),time:V.z,data:i.z.record(i.z.unknown()).optional()}),$u=i.z.object({statuses:Ru.array()}),Oi="status.aggregator";class ys extends yr{constructor(){super(...arguments);T(this,"schema",$u)}async afterUpdate(){this.ctx.set(Oi,this)}add(t){this.setState(s=>({...s,statuses:[...s.statuses,{time:V.now(),...t,key:Xa.id()}]}))}}T(ys,"TYPE","status.Aggregator");const cO=r=>{const e=r.get(Oi);return e.add.bind(e)},hO=r=>{const e=r.getOptional(Oi);return e!=null?e.add.bind(e):()=>{}},dO={[ys.TYPE]:ys};exports.$=ns;exports.A=Rc;exports.Aggregator=ys;exports.B=bi;exports.ComponentSizeLevels=mo;exports.Composite=yr;exports.Context=Nu;exports.Dt=wc;exports.E=ot;exports.Eraser=Eu;exports.Eraser$1=gs;exports.F=Hu;exports.GLProgram=Su;exports.K=oe;exports.K$1=Jc;exports.L=Q;exports.LEVELS=yo;exports.Leaf=Ms;exports.LevelComponentSizes=dh;exports.Loop=zu;exports.Lt=cc;exports.Mutex=vi;exports.Np=av;exports.Provider=ir;exports.REGISTRY=uO;exports.REGISTRY$1=aO;exports.REGISTRY$2=dO;exports.S=ao;exports.S$1=x;exports.SYNNAX_DARK=vo;exports.SYNNAX_LIGHT=bo;exports.SYNNAX_THEMES=Th;exports.U=Wc;exports.VARIANTS=ku;exports.X=eh;exports.Y=th;exports.Z=to;exports._=so;exports.aether=Qv;exports.aggregatorStateZ=$u;exports.b=fe;exports.c=Yu;exports.dimensions=ph;exports.downLevel=oh;exports.ee=rh;exports.ep=sm;exports.eraserStateZ=Iu;exports.executeInitialSetter=or;exports.executeSetter=Zn;exports.fontSpecZ=Au;exports.fontString=Eh;exports.g=M;exports.g$1=vu;exports.gg=lu;exports.isSetter=Wn;exports.k=$;exports.l=Lc;exports.levelZ=ih;exports.m=V;exports.o=vc;exports.o$1=$c;exports.pg=uu;exports.prettyParse=Pn;exports.r=Oc;exports.render=Tu;exports.se=Ne;exports.specZ=Fe;exports.specZ$1=Ru;exports.state=nh;exports.themeZ=wo;exports.upLevel=uh;exports.use=lO;exports.useAggregate=cO;exports.useOptionalAggregate=hO;exports.usePassthrough=po;exports.usePurePassthrough=go;exports.variantZ=Cu;exports.w=Z;exports.w$1=Fu;exports.weightZ=hh;exports.x=Xt;exports.xe=Oe;exports.xt=Xa;exports.y=nc;exports.yp=Uw;exports.zg=sy;
|