@kymoscope/sdk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/assets/{importer.worker-Drm9u2Rc.js → importer.worker-CLBGjz4d.js} +1 -1
  2. package/dist/assets/{offscreenLineWorker-mShhnyXX.js → offscreenLineWorker-BLxay-Po.js} +2 -2
  3. package/dist/importers-B6rkbTwQ.js +5 -0
  4. package/dist/keys-KE0GTKAF.js +10 -0
  5. package/dist/kymoscope-embed.js +91 -90
  6. package/dist/kymoscope-sdk.js +86 -84
  7. package/dist/rules/kyr1.schema.json +135 -0
  8. package/dist/rules.js +2 -0
  9. package/dist/styles/charts.css +191 -0
  10. package/dist/threshold-C9it0Y7P.js +2 -0
  11. package/dist/types/charts/AnnotationLayer.d.ts +7 -2
  12. package/dist/types/charts/CameraPanel.d.ts +43 -0
  13. package/dist/types/charts/ChartBody.d.ts +12 -0
  14. package/dist/types/charts/beacon.d.ts +4 -1
  15. package/dist/types/charts/cameraLayout.d.ts +10 -0
  16. package/dist/types/charts/liveOverlay.d.ts +14 -0
  17. package/dist/types/charts/runtime.d.ts +12 -1
  18. package/dist/types/charts/useWorksheetData.d.ts +1 -5
  19. package/dist/types/components/GaugeChart.d.ts +2 -0
  20. package/dist/types/components/MultiBandCanvasChart.d.ts +4 -2
  21. package/dist/types/components/dashboardGridLayout.d.ts +1 -1
  22. package/dist/types/components/multiBandHover.d.ts +7 -0
  23. package/dist/types/engine/alerts.d.ts +56 -0
  24. package/dist/types/engine/columns.d.ts +16 -0
  25. package/dist/types/engine/createEngine.d.ts +60 -2
  26. package/dist/types/engine/derive.d.ts +1 -1
  27. package/dist/types/engine/errors.d.ts +1 -1
  28. package/dist/types/engine/liveController.d.ts +11 -1
  29. package/dist/types/engine/types.d.ts +41 -2
  30. package/dist/types/index.d.ts +26 -3
  31. package/dist/types/lib/annotations.d.ts +20 -0
  32. package/dist/types/lib/beacon.d.ts +2 -1
  33. package/dist/types/lib/data/columnarDataSource.d.ts +1 -0
  34. package/dist/types/lib/data/dataSource.d.ts +3 -0
  35. package/dist/types/lib/data/duckDbDataSource.d.ts +1 -0
  36. package/dist/types/lib/data/historyDataSource.d.ts +51 -0
  37. package/dist/types/lib/data/inMemoryDataSource.d.ts +1 -0
  38. package/dist/types/lib/data/liveDataSource.d.ts +20 -1
  39. package/dist/types/lib/data/pointColumns.d.ts +11 -0
  40. package/dist/types/lib/duckdb/duckdbInstance.d.ts +5 -0
  41. package/dist/types/lib/historian/blockCache.d.ts +32 -0
  42. package/dist/types/lib/historian/export.d.ts +31 -0
  43. package/dist/types/lib/historian/khd1.d.ts +41 -0
  44. package/dist/types/lib/historian/parquet.d.ts +21 -0
  45. package/dist/types/lib/historian/reader.d.ts +73 -0
  46. package/dist/types/lib/live/blockWire.d.ts +16 -0
  47. package/dist/types/lib/live/buffer.d.ts +34 -0
  48. package/dist/types/lib/live/cameraSender.d.ts +70 -0
  49. package/dist/types/lib/live/clockMap.d.ts +20 -0
  50. package/dist/types/lib/live/crypto.d.ts +7 -0
  51. package/dist/types/lib/live/publisher.d.ts +163 -0
  52. package/dist/types/lib/live/types.d.ts +19 -1
  53. package/dist/types/lib/live/videoTrack.d.ts +96 -0
  54. package/dist/types/lib/live/videoWire.d.ts +35 -0
  55. package/dist/types/lib/live/wire.d.ts +4 -0
  56. package/dist/types/lib/panelChartSettings.d.ts +40 -1
  57. package/dist/types/lib/recordings/export.d.ts +1 -0
  58. package/dist/types/lib/recordings/videoSource.d.ts +56 -0
  59. package/dist/types/lib/render/alertGlyph.d.ts +7 -0
  60. package/dist/types/lib/render/glSeries.d.ts +1 -1
  61. package/dist/types/lib/segments/align.d.ts +85 -0
  62. package/dist/types/lib/segments/liveAxis.d.ts +58 -0
  63. package/dist/types/lib/segments/rules.d.ts +77 -0
  64. package/dist/types/lib/workspaces/io.d.ts +6 -0
  65. package/dist/types/lib/yAxisTicks.d.ts +11 -0
  66. package/dist/types/rules/compile.d.ts +47 -0
  67. package/dist/types/rules/evaluator.d.ts +51 -0
  68. package/dist/types/rules/index.d.ts +4 -0
  69. package/dist/types/rules/threshold.d.ts +3 -0
  70. package/dist/types/rules/types.d.ts +89 -0
  71. package/dist/types/rules/validate.d.ts +6 -0
  72. package/dist/types/types/loadedDataset.d.ts +5 -0
  73. package/dist/types/types/plotSeries.d.ts +5 -0
  74. package/package.json +7 -2
  75. package/dist/importers-DHeUdZcP.js +0 -5
  76. package/dist/krc-BIfw0rX1.js +0 -9
@@ -0,0 +1,10 @@
1
+ /*! @kymoscope/sdk (c) 2026 Kymoscope. Proprietary software: use requires a license. See LICENSE.md. */
2
+ var e=Symbol(`row`),t=new WeakMap;function n(e){return t.get(e)}function r(e,t){let n=e.keys.lastIndexOf(t);return n<0?void 0:e.values[n]}var i=new WeakMap;function a(n,r){let a=n.keys.join(`
3
+ `),o=r&&i.get(r);if(o&&o.keys===a&&r.length===n.length){o.t=n;let e=new Proxy(o.base,{});return i.set(e,o),t.set(e,n),t.set(r,n),e}let s=Array(n.length),c={t:n,keys:a,base:s},l={};n.keys.forEach((t,n)=>{Object.defineProperty(l,t,{enumerable:!0,configurable:!0,get(){let t=this[e],{values:r,text:i}=c.t,a=r[n][t],o=i[n];return a===a?a:o?o[t]??null:null},set(e){Object.defineProperty(this,t,{value:e,writable:!0,enumerable:!0,configurable:!0})}})});for(let t=0;t<n.length;t++){let n=Object.create(l);n[e]=t,s[t]=n}return i.set(s,c),t.set(s,n),s}function o(e){let t=Array(e.length);for(let n=0;n<e.length;n++){let r={};for(let t=0;t<e.keys.length;t++){let i=e.values[t][n];r[e.keys[t]]=i===i?i:e.text[t]?.[n]??null}t[n]=r}return t}function s(e,t){let n=Number(t?e.replace(`,`,`.`):e);return Number.isFinite(n)?n:null}function c(e,t){let n=e.trim();if(n===``)return null;let r=s(n,t);return r===null?n:r}function l(e,t){if(t===`,`)return!1;let n=0,r=0;for(let i of e)for(let e of d(i,t)){let t=e.trim();/^-?\d+,\d+$/.test(t)?n++:/^-?\d+\.\d+$/.test(t)&&r++}return n>r}function u(e){let t=(e.match(/\t/g)??[]).length,n=(e.match(/;/g)??[]).length,r=0,i=!1;for(let t=0;t<e.length;t++){let n=e[t];n===`"`?i=!i:!i&&n===`,`&&r++}return t>0&&t>=r&&t>=n?` `:n>r?`;`:r>0?`,`:` `}function d(e,t){if(t===` `)return e.split(` `);let n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`?e[a+1]===`"`?(r+=`"`,a++):i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r),r=``):r+=o}return n.push(r),n}function f(e,t){let n=0,r=0;for(let i of e){let e=i.trim();e!==``&&(n++,s(e,t)!==null&&r++)}return n>0&&r/n>=.5}function p(e,t){if(t===void 0)return!1;let n=e=>/[\t,;]/.test(e);return!n(e)&&n(t)}function m(e){let t=[];for(let n of e.split(/\r\n|\r|\n/)){let e=n.replace(/\uFEFF/g,``).trimEnd();e.length>0&&t.push(e)}return t}function h(e,t){return e.headerRow===t.headerRow&&e.unitsRow===t.unitsRow&&e.dataStartRow===t.dataStartRow}function g(e){let t=[` `,`;`,`,`],n={delim:` `,cols:1,agree:0};for(let r of t){let t=new Map;for(let n of e){let e=d(n,r).length;e>1&&t.set(e,(t.get(e)??0)+1)}for(let[e,i]of t)(i>n.agree||i===n.agree&&e>n.cols)&&(n={delim:r,cols:e,agree:i})}return{delim:n.delim,cols:n.cols}}function _(e){let t=m(e);if(t.length===0)return{headerRow:0,unitsRow:null,dataStartRow:1};let n=t.slice(0,10),{delim:r,cols:i}=g(n),a=e=>d(e,r).length===i,o=e=>d(e,r).every(e=>e.trim()!==``),s=n.findIndex(e=>a(e)&&o(e));s<0&&(s=n.findIndex(a)),(s<0||i<=1)&&(s=0);let c=null,u=s+1;if(t.length>s+1){let e=l(t.slice(s+1,s+11),r);f(d(t[s+1],r),e)||(c=s+1,u=s+2)}return{headerRow:s,unitsRow:c,dataStartRow:u}}function v(e,t){let n=e[t]??``,r=d(n,u(n)).map(e=>e.trim());if(r.length===0||r.every(e=>e===``))throw Error(`No column names were found.`);return r}function y(e,t){let{table:n,...r}=b(e,t);return{...r,rows:o(n)}}function b(e,t){let{headerRow:n,unitsRow:r,dataStartRow:i}=t,a=[],o=-1,s=0;for(;s<=e.length&&a.length<i+10;){a.length===i&&o<0&&(o=s);let n=e.indexOf(`
4
+ `,s);n<0&&(n=e.length);let r=e.slice(s,n);if(/\r(?!$)/.test(r))return w(e,t);let c=r.replace(/\uFEFF/g,``).trimEnd();c.length>0&&a.push(c),s=n+1}if(a.length===i&&o<0&&(o=s),o<0)return w(e,t);let f=u(a[n]??``),m=v(a,n),h=[];r!==null&&a[r]!==void 0&&(h=d(a[r],f).map(e=>e.trim())),h.length===0&&(h=m.map(()=>``));let g=l(a.slice(i,i+10),f),_=m.map((e,t)=>e||`col_${t}`),y=_.length,b=1;for(let t=e.indexOf(`
5
+ `,o);t>=0;t=e.indexOf(`
6
+ `,t+1))b++;let x=0;for(let t=e.indexOf(`\r`,o);t>=0;t=e.indexOf(`\r`,t+1))e.charCodeAt(t+1)!==10&&x++;b+=x;let T=_.map(()=>new Float64Array(b)),E=_.map(()=>null),D=0,O=(e,t)=>{typeof t==`number`?T[e][D]=t:(T[e][D]=NaN,t!==null&&((E[e]??=[])[D]=t))},k=e=>{let t=d(e,f);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<y;e++)O(e,t[e]===void 0?null:c(t[e],g));D++}},A=f.charCodeAt(0),j=A!==9&&e.indexOf(`"`,o)>=0||e.indexOf(``,o)>=0||x>0;for(s=o;s<e.length;){let t=e.indexOf(`
7
+ `,s);t<0&&(t=e.length);let n=t;n>s&&e.charCodeAt(n-1)===13&&n--;let r=n>s;if(r){let t=e.charCodeAt(n-1);r=t>32&&t<127}if(r&&j)for(let t=s;t<n;t++){let n=e.charCodeAt(t);if(n===13||n===65279||n===34&&A!==9){r=!1;break}}if(r){let t=s;for(let r=0;r<y;r++){if(t>n){O(r,null);continue}let i=C(e,t,n,A,g);if(i===i){T[r][D]=i,t=S+1;continue}let a=e.indexOf(f,t);(a<0||a>n)&&(a=n),O(r,c(e.slice(t,a),g)),t=a+1}D++}else{let n=e.slice(s,t);for(let e of n.split(/\r\n|\r|\n/)){let t=e.replace(/\uFEFF/g,``).trimEnd();t.length>0&&k(t)}}s=t+1}let M=T.map(e=>b-D>b/100?e.slice(0,D):e.subarray(0,D));return{meta:a.length>0&&p(a[0],a[1])?a[0]:``,columnNames:m,units:h,table:{keys:_,length:D,values:M,text:E}}}var x=Array.from({length:23},(e,t)=>10**t),S=0;function C(e,t,n,r,i){let a=t,o=e.charCodeAt(a),s=o===45;(s||o===43)&&a++;let c=0,l=0,u=0,d=!1,f=!1;for(;a<n;a++)if(o=e.charCodeAt(a),o>=48&&o<=57){if(d=!0,c===0&&o===48){f&&u++;continue}if(++l>15)return NaN;c=c*10+(o-48),f&&u++}else if((o===46||i&&o===44&&r!==44)&&!f)f=!0;else break;if(!d)return NaN;let p=0;if(a<n&&o!==r){if(o!==101&&o!==69)return NaN;a++,o=e.charCodeAt(a);let t=o===45;(t||o===43)&&a++;let i=a;for(;a<n&&(o=e.charCodeAt(a),o!==r);a++){if(o<48||o>57||p>400)return NaN;p=p*10+(o-48)}if(a===i)return NaN;t&&(p=-p)}let m=p-u,h;if(c===0)h=0;else if(m>=0&&m<=22)h=c*x[m];else if(m<0&&m>=-22)h=c/x[-m];else return NaN;return S=a,s?-h:h}function w(e,t){let n=m(e),{headerRow:r,unitsRow:i,dataStartRow:a}=t,o=u(n[r]??``),s=v(n,r),f=[];i!==null&&n[i]!==void 0&&(f=d(n[i],o).map(e=>e.trim())),f.length===0&&(f=s.map(()=>``));let h=n.slice(a),g=l(h.slice(0,10),o),_=s.map((e,t)=>e||`col_${t}`),y=h.length,b=_.map(()=>new Float64Array(y)),x=_.map(()=>null),S=0;for(let e of h){let t=d(e,o);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<_.length;e++){let n=t[e]===void 0?null:c(t[e],g);typeof n==`number`?b[e][S]=n:(b[e][S]=NaN,n!==null&&((x[e]??=[])[S]=n))}S++}}return S<y&&(b=b.map(e=>e.slice(0,S))),{meta:n.length>0&&p(n[0],n[1])?n[0]:``,columnNames:s,units:f,table:{keys:_,length:S,values:b,text:x}}}var T=5e3;function E(e,t){let n=D.get(e);n||D.set(e,n=new Map);let r=n.get(t);return r===void 0&&n.set(t,r=O(e,t)),r}var D=new WeakMap;function O(e,t){let r=n(e),i=r?r.keys.lastIndexOf(t):-1;if(r&&i>=0&&!r.text[i]){let e=r.values[i];for(let t=0;t<e.length;t++)if(e[t]===e[t])return!0;return!1}let a=e.length,o=0,s=0,c=Math.max(1,Math.floor(a/T));for(let n=0;n<a;n+=c){let r=e[n][t];r!=null&&(o++,typeof r==`number`&&s++)}if(o===0&&c>1)for(let n=0;n<a&&o<T;n++){let r=e[n][t];r!=null&&(o++,typeof r==`number`&&s++)}return o>0&&s/o>.95}function k(e,t){if(e<=t)return Array.from({length:e},(e,t)=>t);let n=[],r=e/t,i=0;for(let a=0;a<t;a++)n.push(Math.min(e-1,Math.floor(i))),i+=r;return n}var A=[];function j(e){return A.push(e),e}function M(e){for(let t of A)t.delete(e)}function N(e,t,n,r,i,a){let o=(i-r)/a;if(!(i>r)||a<1)return{x0:r,bucket:0,rows:[],columns:n};let s=Math.floor(a);if(F(e))return{x0:r,bucket:o,rows:ee(e,t,r,i,o,s),columns:n};let c=new Uint8Array(s),l=t.map(()=>new Float64Array(s).fill(1/0)),u=t.map(()=>new Float64Array(s).fill(-1/0));for(let n=0;n<e.length;n++){let a=e[n];if(!(a>=r&&a<=i))continue;let d=Math.floor((a-r)/o);d>=s&&(d=s-1),c[d]=1;for(let e=0;e<t.length;e++){let r=t[e][n];r===r&&(r<l[e][d]&&(l[e][d]=r),r>u[e][d]&&(u[e][d]=r))}}let d=[];for(let e=0;e<s;e++){if(!c[e])continue;let n={b:e};for(let r=0;r<t.length;r++)l[r][e]!==1/0&&(n[`y${r}lo`]=l[r][e],n[`y${r}hi`]=u[r][e]);d.push(n)}return{x0:r,bucket:o,rows:d,columns:n}}var P=j(new WeakMap);function F(e){let t=P.get(e);if(t===void 0){t=!0;for(let n=0;n<e.length;n++)if(!(e[n]>=(n>0?e[n-1]:-1/0))){t=!1;break}P.set(e,t)}return t}function ee(e,t,n,r,i,a){let o=t=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;t(e[i])?n=i+1:r=i}return n},s=o(e=>e<n),c=o(e=>e<=r),l=e=>Math.min(a-1,Math.floor((e-n)/i)),u=t.map((e,t)=>`y${t}lo`),d=t.map((e,t)=>`y${t}hi`),f=[],p=s;for(;p<c;){let n=l(e[p]),r=p,i=1;for(;p+i<c&&l(e[p+i])===n;)r=p+i,i*=2;let a=r+1,o=Math.min(p+i,c);for(;a<o;){let t=a+o>>>1;l(e[t])===n?a=t+1:o=t}let s=a,m={b:n};for(let e=0;e<t.length;e++){let n=t[e],r=1/0,i=-1/0;for(let e=p;e<s;e++){let t=n[e];t<r&&(r=t),t>i&&(i=t)}r!==1/0&&(m[u[e]]=r,m[d[e]]=i)}f.push(m),p=s}return f}function I(e,t,n,r,i){let a=(r-n)/i,o=new Map;for(let s=0;s<e.length;s++){let c=e[s],l=t[s];if(c<n||c>r||Number.isNaN(l))continue;let u=Math.floor((c-n)/a);u===i&&(u=i-1);let d=o.get(u);d?(l<d.min&&(d.min=l),l>d.max&&(d.max=l),c<d.firstX&&(d.firstX=c,d.firstY=l),c>d.lastX&&(d.lastX=c,d.lastY=l)):(d={min:l,max:l,firstX:c,firstY:l,lastX:c,lastY:l},o.set(u,d))}let s=[...o.keys()].sort((e,t)=>e-t),c=s.length,l={x:new Float64Array(c),min:new Float64Array(c),max:new Float64Array(c),first:new Float64Array(c),last:new Float64Array(c)};for(let e=0;e<c;e++){let t=s[e],r=o.get(t);l.x[e]=n+(t+.5)*a,l.min[e]=r.min,l.max[e]=r.max,l.first[e]=r.firstY,l.last[e]=r.lastY}return l}function te(e,t,n,r,i,a){if(!F(e))return null;let o=t=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;t(e[i])?n=i+1:r=i}return n},s=o(e=>e<r),c=o(e=>e<=i);if(c-s>a)return null;let l=e=>s===0&&c===e.length?e:e.subarray(s,c);return{length:c-s,x:l(e),cols:new Map(n.map((e,n)=>[e,l(t[n])]))}}var L=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function R(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function z(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}var B=new TextDecoder(`utf-8`),ne=new TextDecoder(`latin1`);function re(e,t=!1){let n=e.indexOf(0);return(t?ne:B).decode(n<0?e:e.subarray(0,n))}var ie=e=>ne.decode(e),ae=e=>B.decode(e);function V(e,t,n=0){if(e.length<n+t.length)return!1;for(let r=0;r<t.length;r++)if(e[n+r]!==t.charCodeAt(r))return!1;return!0}var oe={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>V(e,`MDF `)||V(e,`UnFinMF `)},se={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>V(e,`0 `)||e[0]===255&&V(e,`BIOSEMI`,1)},ce={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>V(e,`XDF:`)},le={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>V(e,`TDSm`)},ue={id:`mat`,label:`MATLAB MAT (v5, v7.3)`,extensions:[`.mat`],sniff:e=>V(e,`MATLAB 5.0 MAT-file`)||V(e,`MATLAB 7.3 MAT-file`)},de=`‰HDF\r
8
+ 
9
+ `,fe={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>V(e,de,t))},pe={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=ie(e.subarray(0,512));if(/^---\s*file type:\s*CFG/i.test(t))return!0;let n=t.split(/\r?\n/);return n.length>2&&/^\s*\d+\s*,\s*\d+A\s*,\s*\d+D\s*$/i.test(n[1])}},me=`This file couldn't be read (it may be damaged).`,he=1032,ge=e=>e*he+1024,_e=128e6,ve=256,ye=64,be=1e3,xe=100,Se=200,Ce=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function we(e){let t=e.notes;for(let n of e.groups){n.name=Ce(String(n.name),ve);for(let e of n.channels)e.name=Ce(String(e.name),ve),e.unit=Ce(String(e.unit??``),ye);Number.isInteger(n.samples)&&n.samples>=-1||(n.samples=-1),n.rateHz===null||Number.isFinite(n.rateHz)&&n.rateHz>0||(n.rateHz=null),n.time.kind===`rate`&&!(Number.isFinite(n.time.rate)&&n.time.rate>0&&Number.isFinite(n.time.start))&&(t.push(`${n.name}: its sample rate in the file is not usable; samples are numbered instead.`),n.time={kind:`index`},n.rateHz=null)}t.length>xe&&t.splice(xe,t.length-xe,`${t.length-xe} more notes.`),e.notes=t.map(e=>Ce(String(e),be));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,Se))n[Ce(t,ve)]=Ce(String(r),be);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:Ce(String(e.text),be)})),e}function Te(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(me)}function Ee(e,t=[`Time`]){let n=new Set(t.map(e=>e.toLowerCase())),r=new Map;return e.map(e=>{let t=e.trim()||`Channel`,i=t.toLowerCase(),a=t,o=r.get(i)??2;if(n.has(i)){for(;n.has(`${i} (${o})`);)o++;a=`${t} (${o++})`}return r.set(i,o),n.add(a.toLowerCase()),a})}var H=1<<20,De=64,Oe=16<<20,ke=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;if(n-e>H)return this.slice(e,n-e);let r=Math.floor(e/H),i=Math.floor((n-1)/H),a=await this.#n(r);if(r===i)return a.subarray(e-r*H,n-r*H);let o=new Uint8Array(n-e),s=a.subarray(e-r*H);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*H),s.length),o}async slice(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;let r=new Uint8Array(await this.#e.slice(e,n).arrayBuffer());return this.bytesRead+=r.length,r}async*windows(e,t,n=Oe){let r=Math.min(this.size,e+t);for(let t=e;t<r;t+=n)yield{offset:t,bytes:await this.slice(t,Math.min(n,r-t))}}async#n(e){let t=this.#t.get(e);if(t)return this.#t.delete(e),this.#t.set(e,t),t;let n=await this.slice(e*H,H);return this.#t.size>=De&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}},Ae=`kymoscope-live-key-check-v1`,je=6e5;function U(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function W(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function G(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Me(e){return W(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Ne(e){return G(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(Math.ceil(e.length/4)*4,`=`))}function Pe(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}function Fe(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),W(e)}async function Ie(e,t){let n=new TextEncoder,r=await U().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return U().deriveKey({name:`PBKDF2`,salt:G(t),iterations:je,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Le(e,t){let n=await U().importKey(`raw`,new TextEncoder().encode(e),`PBKDF2`,!1,[`deriveBits`]),r=await U().deriveBits({name:`PBKDF2`,salt:G(t),iterations:je,hash:`SHA-256`},n,256);return W(new Uint8Array(r))}async function Re(e,t){let n=new Uint8Array(12);globalThis.crypto.getRandomValues(n);let r=new TextEncoder().encode(JSON.stringify(t)),i=await U().encrypt({name:`AES-GCM`,iv:n},e,r);return{iv:W(n),ciphertext:W(new Uint8Array(i))}}async function ze(e,t){let n=G(t.iv),r=G(t.ciphertext),i=await U().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function Be(e,t,n,r){let i=await U().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function Ve(e,t){return JSON.parse(new TextDecoder().decode(await ze(e,t)))}async function He(e){return Re(e,Ae)}async function Ue(e,t){try{return await Ve(e,t)===Ae}catch{return!1}}async function We(e){let t=await U().digest(`SHA-256`,new TextEncoder().encode(e));return Pe(new Uint8Array(t))}function Ge(){let e=e=>{let t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),Me(t)},t=`kymoscope_${e(24)}.${e(32)}`;return{token:t,prefix:t.slice(0,12)}}var Ke=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/;function qe(e){let t=Ke.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}var Je=new TextEncoder().encode(`kymoscope-device-wrap-v1`);async function Ye(){let e=await U().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),t=new Uint8Array(await U().exportKey(`raw`,e.publicKey));return{privateKey:e.privateKey,publicKey:W(t)}}async function Xe(e,t){let n=new Uint8Array(e.length+Je.length);return n.set(e),n.set(Je,e.length),U().importKey(`raw`,await U().digest(`SHA-256`,n),`AES-GCM`,!1,t)}async function Ze(e,t,n){let r=await U().importKey(`raw`,G(t.epk),{name:`ECDH`,namedCurve:`P-256`},!1,[]),i=new Uint8Array(await U().deriveBits({name:`ECDH`,public:r},e,256));return new Uint8Array(await U().decrypt({name:`AES-GCM`,iv:G(t.iv),additionalData:new TextEncoder().encode(n)},await Xe(i,[`decrypt`]),G(t.ct)))}function Qe(e,t,n){return $e(e,t,n)}async function $e(e,t,n,r,i){let a=await U().importKey(`raw`,G(e),{name:`ECDH`,namedCurve:`P-256`},!1,[]),o=r??await U().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),s=new Uint8Array(await U().deriveBits({name:`ECDH`,public:a},o.privateKey,256)),c=i??globalThis.crypto.getRandomValues(new Uint8Array(12)),l=new Uint8Array(await U().encrypt({name:`AES-GCM`,iv:c,additionalData:new TextEncoder().encode(n)},await Xe(s,[`encrypt`]),t));return{epk:W(new Uint8Array(await U().exportKey(`raw`,o.publicKey))),iv:W(c),ct:W(l)}}async function et(e,t,n,r){return ot(await Ze(e,t,`${n}|${r}`))}var tt=new TextEncoder().encode(`kymoscope-sender-bind-v1`),nt=(e,t,n)=>`project:${e}:${t}|${n}`,rt=(e,t,n)=>`live_stream:${e}|${t}:${n}`,it=(e,t,n)=>`bind:${e}|${t}:${n}`;function at(){return globalThis.crypto.getRandomValues(new Uint8Array(32))}function ot(e){return U().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function st(e,t,n){return ct(e,t,n)}async function ct(e,t,n,r){let i=r??globalThis.crypto.getRandomValues(new Uint8Array(12)),a=await U().importKey(`raw`,e,`AES-GCM`,!1,[`encrypt`]),o=new Uint8Array(await U().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},a,t));return{iv:W(i),ct:W(o)}}async function lt(e,t,n){let r=await U().importKey(`raw`,e,`AES-GCM`,!1,[`decrypt`]);return new Uint8Array(await U().decrypt({name:`AES-GCM`,iv:G(t.iv),additionalData:new TextEncoder().encode(n)},r,G(t.ct)))}async function ut(e){let t=new TextEncoder().encode(e),n=new Uint8Array(t.length+tt.length);return n.set(t),n.set(tt,t.length),new Uint8Array(await U().digest(`SHA-256`,n))}async function dt(e,t,n){let r=await U().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return W(new Uint8Array(await U().sign(`HMAC`,r,new TextEncoder().encode(`sender|${t}|${n}`))))}async function ft(e,t,n,r){let i;try{i=G(r)}catch{return!1}let a=await U().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`verify`]);return U().verify(`HMAC`,a,i,new TextEncoder().encode(`sender|${t}|${n}`))}async function pt(e){let t=Pe(new Uint8Array(await U().digest(`SHA-256`,G(e)))).slice(0,16).toUpperCase();return`${t.slice(0,4)}-${t.slice(4,8)}-${t.slice(8,12)}-${t.slice(12,16)}`}var mt=`kymoscope-workbook-export-v2`,ht=(e,t)=>`workbook:${e}:${t}`,gt=(e,t,n)=>`workbook:${e}|${t}:${n}`,_t=(e,t,n)=>`history_key:${e}|${t}:${n}`,vt=(e,t)=>`project_config:${e}|${e}:${t}`,yt=(e,t,n)=>`alert_rule:${e}:${t}|${n}`,bt=(e,t)=>`kymoscope-recovery-key-v1|${e}|${t}`,xt=(e,t,n)=>`recovery:${e}|${t}:${n}`;function St(e,t,n){return Ct(e,t,n)}async function Ct(e,t,n,r){let i=r??globalThis.crypto.getRandomValues(new Uint8Array(12)),a=new Uint8Array(await U().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:W(i),ct:W(a)}}async function wt(e,t,n){return new Uint8Array(await U().decrypt({name:`AES-GCM`,iv:G(t.iv),additionalData:new TextEncoder().encode(n)},e,G(t.ct)))}function Tt(e,t,n){return Et(e,t,n)}async function Et(e,t,n,r,i){let a=W(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await Ct(await Ie(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:je,salt:a},...o}}async function Dt(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==je||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return wt(await Ie(e,r.salt),t,n)}var Ot=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`;function kt(e){let t=0,n=0,r=``;for(let i of e)for(n=(n<<8|i)&1048575,t+=8;t>=5;)r+=Ot[n>>>t-5&31],t-=5;return t>0&&(r+=Ot[n<<5-t&31]),r.match(/.{1,4}/g).join(`-`)}function At(e){let t=e.toUpperCase().replace(/[^A-Z2-7]/g,``);if(t.length!==52)return null;let n=[],r=0,i=0;for(let e of t)i=(i<<5|Ot.indexOf(e))&4095,r+=5,r>=8&&(n.push(i>>>r-8&255),r-=8);return n.length===32?new Uint8Array(n):null}async function jt(){let e=await U().generateKey({name:`ECDH`,namedCurve:`P-256`},!0,[`deriveBits`]),t=await U().exportKey(`jwk`,e.privateKey),n=new Uint8Array(await U().exportKey(`raw`,e.publicKey));return{d:Ne(t.d),publicKey:W(n)}}function Mt(e,t){let n=G(t);return U().importKey(`jwk`,{kty:`EC`,crv:`P-256`,ext:!1,x:Me(n.subarray(1,33)),y:Me(n.subarray(33,65)),d:Me(e)},{name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`])}var Nt=j(new WeakSet),Pt={length:0,x:new Float64Array,cols:new Map};function Ft(e,t,n,r){let i=t.length,a=t.map((e,t)=>`y${t}lo`),o=t.map((e,t)=>`y${t}hi`),s=new Uint8Array(e.length),c=0;for(let t=0;t<e.length;t++){let n=e[t];for(let e=0;e<i;e++){let r=n[o[e]];if(r!=null&&Number(r)!==Number(n[a[e]])){s[t]=1;break}}c+=1+s[t]}let l=new Float64Array(c),u=t.map(()=>new Float64Array(c).fill(NaN)),d,f=0,p=null;for(let t=0;t<e.length;t++){let m=e[t],h=n+(Number(m.b)+.5)*r,g=Number(m.pass??0);p!==null&&g!==p&&((d??=new Uint8Array(c))[f]=1),p=g,l[f]=h;for(let e=0;e<i;e++){let t=m[a[e]];t!=null&&(u[e][f]=Number(t))}if(f++,s[t]){l[f]=h;for(let e=0;e<i;e++){let t=m[o[e]];t!=null&&(u[e][f]=Number(t))}f++}}return{length:c,x:l,brk:d,cols:new Map(t.map((e,t)=>[e,u[t]]))}}function It(e,t){if(t>=e.length)return e;let n=new Map;for(let[r,i]of e.cols)n.set(r,i.subarray(0,t));return{length:t,x:e.x.subarray(0,t),brk:e.brk?.subarray(0,t),cols:n}}function Lt(e,t,n,r,i){let a=[];for(let o of new Set(e)){let e=t(o);if(!e||!(e.t<r))continue;let s=Math.max(n,e.t);s<i&&a.push({c:o,a:s,v:e.v})}if(a.length===0)return null;a.sort((e,t)=>e.a-t.a);let o=a.length+1,s=new Float64Array(o),c=new Map;return a.forEach((e,t)=>{let n=new Float64Array(o).fill(NaN);n[t]=n[o-1]=e.v,c.set(e.c,n),s[t]=e.a}),s[o-1]=i,{length:o,x:s,cols:c,hold:!0}}function Rt(e,t){if(t===void 0||e.length===0||e.x[e.length-1]<=t)return e;let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e.x[i]<=t?n=i+1:r=i}return It(e,n)}function zt(e,t,n){let r=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>1;(n?e.x[a]<=t:e.x[a]<t)?r=a+1:i=a}return r},i=r(t,!1),a=r(n,!0);if(i===0&&a===e.length)return e;let o=new Map;for(let[t,n]of e.cols)o.set(t,n.subarray(i,a));return{length:a-i,x:e.x.subarray(i,a),brk:e.brk?.subarray(i,a),cols:o}}function Bt(e,t){let n=[];for(let r=0;r<e.length;r++)t(e.x[r])&&n.push(r);if(n.length===e.length)return e;let r=(e,t)=>{for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t},i=new Map;for(let[t,a]of e.cols)i.set(t,r(a,new Float64Array(n.length)));return{length:n.length,x:r(e.x,new Float64Array(n.length)),brk:e.brk&&r(e.brk,new Uint8Array(n.length)),cols:i}}function Vt(e,t,i,a,o=``,s=0){let c=n(e),l=k(e.length,a),u=t=>{let n=c&&r(c,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},d=u(t),f=[];for(let e of l)Number.isNaN(d(e))||f.push(e);let p=f.length,m=p===e.length&&s===0,h=c&&r(c,t),g=m&&h?h:Float64Array.from(f,e=>d(e)+s),_=new Map;for(let e of i){let t=c&&r(c,e);if(c&&!t)continue;if(m&&t){_.set(e+o,t);continue}let n=u(e),i=Float64Array.from(f,n);!t&&!i.some(e=>!Number.isNaN(e))||_.set(e+o,i)}return{length:p,x:g,cols:_}}function Ht(e,t,n){if(!t&&n===0)return e;let r=e.x;if(n!==0){r=new Float64Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.x[t]+n}let i=new Map;for(let[n,r]of e.cols)i.set(n+t,r);return{length:e.length,x:r,brk:e.brk,cols:i}}function Ut(e){let t=e.filter(e=>e.length>0);if(t.length===0)return Pt;if(t.length===1)return t[0];let n=t.reduce((e,t)=>e+t.length,0),r=new Float64Array(n),i=new Set;for(let e of t)for(let t of e.cols.keys())i.add(t);let a=new Map;for(let e of i)a.set(e,new Float64Array(n).fill(NaN));let o,s=0;for(let e of t){r.set(e.x,s),e.brk&&(o??=new Uint8Array(n)).set(e.brk,s);for(let[t,n]of e.cols)a.get(t).set(n,s);s+=e.length}return{length:n,x:r,brk:o,cols:a}}var Wt=64,Gt=class{nc;bucket;b;lo;hi;start=0;end=0;rowP;px=new Float64Array;pv=[];pStart=0;pEnd=0;mStart=0;mEnd=0;dirty=1/0;dirtyFront=-1;invalid=!0;constructor(e,t,n=1024){this.nc=e,this.bucket=t,this.b=new Float64Array(n),this.rowP=new Float64Array(n),this.lo=Array.from({length:e},()=>new Float64Array(n)),this.hi=Array.from({length:e},()=>new Float64Array(n))}get count(){return this.end-this.start}lowerBound(e){let t=this.start,n=this.end;for(;t<n;){let r=t+n>>>1;this.b[r]<e?t=r+1:n=r}return t}relocate(e,t){let n=this.count,r=n=>{if(t===n.length&&e<=this.start)return n.copyWithin(e,this.start,this.end),n;let r=new Float64Array(t);return r.set(n.subarray(this.start,this.end),e),r};this.b=r(this.b),this.rowP=r(this.rowP),this.lo=this.lo.map(r),this.hi=this.hi.map(r);let i=e-this.start;this.mStart+=i,this.mEnd+=i,this.dirty!==1/0&&(this.dirty+=i),this.dirtyFront>=0&&(this.dirtyFront+=i),this.start=e,this.end=e+n}touch(e){e===this.start&&e+1<this.mEnd?this.dirtyFront=e:e<this.dirty&&(this.dirty=e)}clearRow(e){for(let t=0;t<this.nc;t++)this.lo[t][e]=NaN,this.hi[t][e]=NaN;this.touch(e)}row(e){let t=this.end;if(t>this.start&&this.b[t-1]===e)return t-1;if(t===this.start||e>this.b[t-1])return t===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2))),this.b[this.end]=e,this.clearRow(this.end),this.end++;let n=this.lowerBound(e);if(this.b[n]===e)return n;if(n!==this.start)throw Error(`TimeBuckets: insert inside the rows`);if(this.start===0){let e=Math.max(1024,this.count);this.relocate(e,2*e+this.count)}return this.start--,this.b[this.start]=e,this.clearRow(this.start),this.invalid=!0,this.start}dropBelow(e){this.start=this.lowerBound(e),this.start===this.end&&(this.start=this.end=0,this.invalid=!0)}reset(e){this.clearRow(e)}fold(e,t,n,r){this.touch(e);for(let i=0;i<t.length;i++){let a=t[i],o=1/0,s=-1/0;for(let e=n;e<r;e++){let t=a[e];t<o&&(o=t),t>s&&(s=t)}if(o===1/0)continue;let c=this.lo[i],l=this.hi[i],u=c[e],d=l[e];c[e]=u<=o?u:o,l[e]=d>=s?d:s}}toRows(e,t,n,r,i){let a=[];for(let o=e;o<t;o++){let e={...n,b:this.b[o],pass:0};for(let t=0;t<this.nc;t++){let n=this.lo[t][o];n===n&&(e[r[t]]=n,e[i[t]]=this.hi[t][o])}a.push(e)}return a}pointsOf(e){for(let t=0;t<this.nc;t++){let n=this.hi[t][e];if(n===n&&n!==this.lo[t][e])return 2}return 1}writeRow(e,t,n){let r=(this.b[e]+.5)*this.bucket;this.px[t]=r;for(let n=0;n<this.nc;n++)this.pv[n][t]=this.lo[n][e];if(n===2){this.px[t+1]=r;for(let n=0;n<this.nc;n++)this.pv[n][t+1]=this.hi[n][e]}}reserve(e){if(this.pEnd+e<=this.px.length)return;let t=this.pEnd-this.pStart,n=Wt-this.pStart,r=2*(t+e+Wt)<=this.px.length,i=r?this.px.length:Math.max(4096,2*(t+e+Wt)),a=e=>{if(r)return e.copyWithin(Wt,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),Wt),t};this.px=a(this.px),this.pv=this.pv.map(a);for(let e=this.mStart;e<this.mEnd;e++)this.rowP[e]+=n;this.pStart=Wt,this.pEnd=Wt+t}writeFrom(e){this.mEnd=e;for(let t=e;t<this.end;t++){let e=this.pointsOf(t);this.reserve(e),this.rowP[t]=this.pEnd,this.writeRow(t,this.pEnd,e),this.pEnd+=e,this.mEnd=t+1}}sync(){if(this.pv.length!==this.nc&&(this.pv=Array.from({length:this.nc},()=>new Float64Array)),this.invalid||this.start<this.mStart||this.start>=this.mEnd)this.pStart=this.pEnd=Wt,this.mStart=this.mEnd=this.start,this.reserve(0),this.writeFrom(this.start);else{this.start>this.mStart&&(this.mStart=this.start,this.pStart=this.rowP[this.start]);let e=Math.max(this.start,Math.min(this.dirty,this.mEnd)),t=this.dirtyFront;if(t===this.start)if(t+1<e){let e=this.pointsOf(t),n=this.rowP[t+1]-e;if(n<0)return this.invalid=!0,this.sync();this.rowP[t]=n,this.pStart=n,this.writeRow(t,n,e)}else e=t;e<this.end&&(e<this.mEnd&&(this.pEnd=this.rowP[e]),this.writeFrom(e))}this.dirty=1/0,this.dirtyFront=-1,this.invalid=!1}toPoints(e,t,n){this.sync();let r=e<t?this.rowP[e]:0,i=e<t?t<this.mEnd?this.rowP[t]:this.pEnd:0;return{length:i-r,x:this.px.subarray(r,i),cols:new Map(n.map((e,t)=>[e,this.pv[t].subarray(r,i)]))}}};function Kt(e){if(!(e>0)||!Number.isFinite(e))return e;let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<1.5?1:n<3.5?2:n<7.5?5:10)*t}function qt(e,t,n,r,i){if(n instanceof Float64Array||n instanceof Float32Array)e.set(n.subarray(r,r+i),t);else for(let a=0;a<i;a++)e[t+a]=+n[r+a]}function Jt(e,t){let n=e.t.length,r=Object.keys(e.columns).filter(e=>e!==t);for(let t of r)if(e.columns[t].length!==n)throw RangeError(`live column "${t}" has ${e.columns[t].length} values for ${n} times`);return r}var Yt=`ElapsedTime`,Xt=[];function Zt(e){let t=Xt[e];if(!t){let n=Array.from({length:e},(e,t)=>`y${t}lo`),r=Array.from({length:e},(e,t)=>`y${t}hi`);t={lo:n,hi:r,row:JSON.parse(JSON.stringify(Object.fromEntries([[`b`,0],[`pass`,0],...n.flatMap((e,t)=>[[e,null],[r[t],null]])])))},Xt[e]=t}return t}var Qt=4096,$t=4,en=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;timeDec=null;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;constructor(e,t=Yt,n=`s`,r=1/0){this.capacity=Math.max(2,Math.floor(e)),this.timeColumn=t,this.timeUnit=n,this.maxBytes=r,this.alloc=Math.min(this.capacity,Qt),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){return new Float64Array(this.alloc).fill(NaN)}grow(){let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes){this.capacity=this.alloc;return}let t=t=>{let n=new Float64Array(e);return n.set(t),n};this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n));this.alloc=e}get version(){return this.pushed+this.clears}get size(){return this.full?this.capacity:this.count}push(e){for(let[t,n]of this.trackers){let r=t===this.timeColumn?e.t:e.signals.find(e=>e.name===t)?.value;r!==void 0&&Number.isFinite(r)&&this.advanceCycle(t,n,r,this.pushed)}e.t<this.lastPushT&&this.steppedBack(this.pushed),this.lastPushT=e.t,!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let t=this.full?this.head:this.count;this.time[t]=e.t;for(let e of this.signalOrder)this.cols.get(e)[t]=NaN;for(let n of e.signals){if(this.computed.has(n.name))continue;let r=this.cols.get(n.name);r?n.unit&&n.unit!==this.unitByName.get(n.name)&&(this.unitByName.get(n.name)&&this.dropColumnSamples(n.name,r),this.unitByName.set(n.name,n.unit)):(r=this.newColumn(),this.cols.set(n.name,r),this.signalOrder.push(n.name),this.unitByName.set(n.name,n.unit??``)),r[t]=n.value,Number.isFinite(n.value)&&this.noteValue(n.name,e.t,n.value)}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0))}pushColumns(e){let t=e.t,n=t.length,r=Jt(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let i of r){if(this.computed.has(i))continue;let r=e.columns[i];for(let e=n-1;e>=0;e--)if(Number.isFinite(r[e])){this.noteValue(i,+t[e],r[e]);break}}for(let e=0;e<n;e++){let n=+t[e];n<this.lastPushT&&this.steppedBack(this.pushed+e),this.lastPushT=n}let i=Math.max(0,n-this.capacity);for(this.pushed+=i;i<n;){!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,a=Math.min(n-i,this.full?this.capacity-this.head:this.alloc-this.count);qt(this.time,r,t,i,a);for(let t of this.signalOrder){let n=this.cols.get(t),o=this.computed.has(t)?void 0:e.columns[t];o?qt(n,r,o,i,a):n.fill(NaN,r,r+a)}this.pushed+=a,i+=a,this.full?this.head=(this.head+a)%this.capacity:(this.count+=a,this.count===this.capacity&&(this.full=!0))}}steppedBack(e){this.lastBackAbs=e,this.timeDec=null,this.snapDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCache=null,this.timeDec=null,this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDec=null,this.snapDec=null,this.latest.clear(),this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null,next:this.pushed},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return N(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return Ft(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}let o=this.trackers.get(e);if(o){for(let t=0;t<r.length;t++){let i=n+t,a=r[t];i<o.next||i<this.firstAbs||i>=this.pushed||a===null||!Number.isFinite(a)||this.advanceCycle(e,o,a,i)}o.next=Math.max(o.next,Math.min(this.pushed,n+r.length))}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDec=null,this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=Zt(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*$t)))}let l=Kt(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=Zt(i.cols.length),o=()=>i.store.toRows(i.i0,i.i1,a.row,a.lo,a.hi),s=this.historyDec;return{x0:0,bucket:i.bucket,rows:s?.store===i.store?s.rows??=o():o(),columns:i.cols}}decimatePoints(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic){let e=this.timeBuckets(t,n,r,i);return e.store?e.store.toPoints(e.i0,e.i1,e.cols):{length:0,x:new Float64Array,cols:new Map(e.cols.map(e=>[e,new Float64Array]))}}let a=this.decimateColumns(e,t,n,r,i);return Ft(a.rows,a.columns,a.x0,a.bucket)}timeBuckets(e,t,n,r){let i=e.filter(e=>this.cols.has(e)),a=this.size,o={cols:i,bucket:0,store:null,i0:0,i1:0};if(i.length===0||!(n>t)||a===0)return o;let s=e=>this.full?(this.head+e)%this.capacity:e,c=this.time[s(0)],l=this.time[s(a-1)],u=(n-t)/r;if(a>1){let e=(l-c)/(a-1);e>0&&e<u&&(u=.7*Math.max(e,(n-t)/(r*$t)))}let d=Kt(u),f=i.join(` `),p=this.timeDec;if(p&&p.colsKey===f&&u>=p.bucket*.5&&u<=p.bucket*2&&(d=p.bucket),!(d>0))return o;let m=i.map(e=>this.cols.get(e)),h=Math.floor(t/d),g=Math.floor(n/d);this.debugLastScan=0;let _=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(h),i1:e.lowerBound(g+1)});if(n<l-(n-t)){let e=this.timeIndex(h*d),t=this.timeIndex((g+1)*d),n=this.pushed-a,r=`${f}|${d}|${h}|${g}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new Gt(i.length,d);this.foldBuckets(n,e,t,d,m),this.historyDec={key:r,store:n}}return _(this.historyDec.store)}let v=p?this.pushed-p.pushed:0;if(p&&p.colsKey===f&&p.bucket===d&&v>=0&&v<a){let e=p.store;if(h<p.fromB){let t=new Gt(i.length,d);this.foldBuckets(t,this.timeIndex(h*d),this.timeIndex(p.fromB*d),d,m);for(let n=t.end-1;n>=t.start;n--){let r=e.row(t.b[n]);for(let i=0;i<t.nc;i++)e.lo[i][r]=t.lo[i][n],e.hi[i][r]=t.hi[i][n]}p.fromB=h}v>0&&this.foldBuckets(e,a-v,a,d,m);let t=Math.floor(c/d);return this.full&&t>=p.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,m),p.fromB=t),h>p.fromB&&(e.dropBelow(h),p.fromB=h),p.pushed=this.pushed,_(e)}let y=new Gt(i.length,d),b=this.timeIndex(h*d);return this.foldBuckets(y,b,a,d,m),this.timeDec={colsKey:f,bucket:d,store:y,pushed:this.pushed,fromB:b===0?Math.floor(c/d):h},_(y)}lastValue(e){let t=e===this.timeColumn?this.time:this.cols.get(e);return!t||this.size===0?NaN:t[this.full?(this.head-1+this.capacity)%this.capacity:this.count-1]}xTravel(e,t){let n=this.columnArray(e),r=this.size;if(!n||r<2)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=this.time[i(r-1)],o=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}latestTime(){return this.lastValue(this.timeColumn)}xAtTime(e,t,n=!1){let r=this.columnArray(e),i=this.size;if(!r||i===0||!this.timeMonotonic)return NaN;let a=e=>this.full?(this.head+e)%this.capacity:e,o=0,s=i-1;if(t<=this.time[a(0)])return r[a(0)];if(t>=this.time[a(s)])return r[a(s)];for(;s-o>1;){let e=o+s>>1;this.time[a(e)]<=t?o=e:s=e}let c=a(o),l=a(s),u=r[c],d=r[l];if(n||!(d>=u))return u;let f=this.time[c],p=this.time[l];return p>f?u+(d-u)*(t-f)/(p-f):u}boundsCache=new Map;columnBounds(e){let t=e===this.timeColumn?this.time:this.cols.get(e),n=this.size;if(!t||n===0)return{x0:0,x1:0};if(t===this.time&&this.timeMonotonic)return{x0:this.time[this.full?this.head:0],x1:this.time[this.full?(this.head+n-1)%this.capacity:n-1]};let r=this.pushed-n,i=this.boundsCache.get(e);if(i&&i.version===this.version)return i.b;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=i>1&&this.timeMonotonic?this.snapshotRows(e):null;if(a)return{meta:``,columnNames:t,units:n,rows:a};let o=e=>{let t=this.full?(this.head+e)%this.capacity:e,n={[this.timeColumn]:this.time[t]};for(let e of this.signalOrder){let r=this.cols.get(e)[t];n[e]=Number.isNaN(r)?null:r}return n},s=this.pushed-r,c=i>1?(i-s%i)%i:0,l=[];for(let e=c;e<r;e+=i)l.push(o(e));return r>0&&(l.length===0||(r-1-c)%i!=0)&&l.push(o(r-1)),{meta:``,columnNames:t,units:n,rows:l}}snapshotRows(e){let t=this.size,n=e=>this.full?(this.head+e)%this.capacity:e,r=this.time[n(0)],i=this.time[n(t-1)],a=(i-r)*2/e;if(!(a>0))return null;let o=`${this.signalOrder.join(`
10
+ `)}|${this.clears}`,s=this.signalOrder.map(e=>this.cols.get(e)),c=this.snapDec,l=c?this.pushed-c.pushed:0;if(c&&c.key===o&&c.bucket>=a&&c.bucket<=a*4&&l>=0&&l<t){let e=c.store;l>0&&this.foldBuckets(e,t-l,t,c.bucket,s);let n=Math.floor(r/c.bucket);this.full&&n>=c.fromB&&(e.dropBelow(n),e.reset(e.row(n)),this.foldBuckets(e,0,this.timeIndex((n+1)*c.bucket),c.bucket,s),c.fromB=n),c.pushed=this.pushed}else{let e=Kt(a*1.75),n=new Gt(s.length,e);this.foldBuckets(n,0,t,e,s),c=this.snapDec={key:o,bucket:e,store:n,pushed:this.pushed,fromB:Math.floor(r/e)}}let u=c.store.toPoints(c.store.start,c.store.end,this.signalOrder),d=[],f=u.x[0],p=u.x[u.length-1];for(let e=0;e<u.length;e++){let t=u.x[e],n={[this.timeColumn]:t===p?i:t===f?r:t};for(let t of this.signalOrder){let r=u.cols.get(t)[e];n[t]=Number.isNaN(r)?null:r}d.push(n)}return d}valueBounds(e){let t=this.columnBounds(e);return Number.isFinite(this.boundsCache.get(e)?.lo??NaN)?t:null}hasValues(e){return this.latest.has(e)||this.computed.has(e)}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}setLastKnown(e,t,n,r){e===this.timeColumn||this.computed.has(e)||!Number.isFinite(n)||!Number.isFinite(r)||(this.cols.has(e)||(this.cols.set(e,this.newColumn()),this.signalOrder.push(e),this.unitByName.set(e,t)),this.noteValue(e,n,r))}noteValue(e,t,n){let r=this.latest.get(e);r?t>=r.t&&(r.t=t,r.v=n):this.latest.set(e,{t,v:n})}};new TextEncoder;var tn=4096;function nn(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=tn&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var rn=new TextDecoder,an=200;function on(e,t,n){let r=e.subarray(t,t+n);return rn.decode(r)}function sn(e,t,n){return n>an?on(e,t,n):nn(e,t,n)}var cn=class{type;data;constructor(e,t){this.type=e,this.data=t}},K=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:e.name})}};function ln(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function un(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function dn(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var fn=4294967295,pn=17179869183;function mn({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=pn)if(t===0&&e<=fn){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),ln(r,4,e),n}}function hn(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function gn(e){return e instanceof Date?mn(hn(e)):null}function _n(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:un(t,4),nsec:t.getUint32(0)};default:throw new K(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function vn(e){let t=_n(e);return new Date(t.sec*1e3+t.nsec/1e6)}var yn={type:-1,encode:gn,decode:vn},bn=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(yn)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new cn(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new cn(n,i)}}return e instanceof cn?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new cn(t,e)}};function xn(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function Sn(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):xn(e)?new Uint8Array(e):Uint8Array.from(e)}function Cn(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var wn=16,Tn=16,En=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=wn,t=Tn){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=nn(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}},Dn=`array`,On=`map_key`,kn=`map_value`,An=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new K(`The type of key must be string or number but `+typeof e)},jn=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=Dn,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=On,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===Dn){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===On||e.type===kn){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},Mn=-1,Nn=new DataView(new ArrayBuffer(0)),Pn=new Uint8Array(Nn.buffer);try{Nn.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}var Fn=RangeError(`Insufficient data`),In=new En,Ln=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=Nn;bytes=Pn;headByte=Mn;stack=new jn;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??bn.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?In:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??An}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=Mn,this.stack.reset()}setBuffer(e){let t=Sn(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Mn&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=Sn(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${Cn(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new K(`Unrecognized type byte: ${Cn(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===Dn)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===On){if(t===`__proto__`)throw new K(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=kn;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=On;continue DECODE}}return t}}readHeadByte(){return this.headByte===Mn&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Mn}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new K(`Unrecognized array type byte: ${Cn(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new K(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new K(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new K(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Fn;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):sn(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===On:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new K(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Fn;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new K(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=dn(this.view,this.pos);return this.pos+=8,e}readI64(){let e=un(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function Rn(e,t){return new Ln(t).decode(e)}var zn=6,Bn=12,Vn=16;function Hn(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+Bn+Vn?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+Bn),ciphertext:t.subarray(n+Bn),aad:t.subarray(0,n)}}async function Un(e,t){let n=Hn(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await Be(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}function Wn(e,t,n,r){return Gn(e,t,n,r)}async function Gn(e,t,n,r,i){let a=r===void 0?new Uint8Array([t]):new Uint8Array([t|128,r&255]),o=i??globalThis.crypto.getRandomValues(new Uint8Array(Bn)),s=new Uint8Array(await globalThis.crypto.subtle.encrypt({name:`AES-GCM`,iv:o,additionalData:a},e,n)),c=new Uint8Array(a.length+Bn+s.length);return c.set(a),c.set(o,a.length),c.set(s,a.length+Bn),c.buffer}var Kn=1,qn=e=>e+7&-8;function Jn(e){let t=e=>RangeError(`columns message: ${e}`);e.byteOffset%8!=0&&(e=e.slice());let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw t(`short`);if(n.getUint8(0)!==Kn)throw t(`version ${n.getUint8(0)}`);let r=n.getUint16(2,!0),i=n.getUint32(4,!0),a=new TextDecoder,o=[],s=8;for(let i=0;i<r;i++){if(s+3>e.byteLength)throw t(`short channel table`);let r=n.getUint8(s),i=n.getUint8(s+1),c=n.getUint8(s+2);if(s+=3,r!==4&&r!==8)throw t(`value size ${r}`);if(s+i+c>e.byteLength)throw t(`short channel table`);o.push({name:a.decode(e.subarray(s,s+i)),unit:a.decode(e.subarray(s+i,s+i+c)),size:r}),s+=i+c}if(s=qn(s),s+qn(i*8)+o.reduce((e,t)=>e+qn(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=qn(i*8);let u={},d={};for(let t of o)u[t.name]=t.size===4?new Float32Array(e.buffer,c+s,i):new Float64Array(e.buffer,c+s,i),t.unit&&(d[t.name]=t.unit),s+=qn(i*t.size);return{t:l,columns:u,units:d}}var Yn=2,Xn=1,Zn=1,Qn=2,$n=20,er=64*1024*1024,q=(e,t)=>RangeError(`${e}: ${t}`);function tr(e){if(e.byteLength<8)throw q(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==Yn)throw q(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw q(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw q(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw q(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:q(`block schema`,`invalid text`)}return{id:r,channels:a}}function nr(e,t){if(e.byteLength<12)throw q(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Xn)throw q(`last values`,`version ${n.getUint8(0)}`);let r=t.get(n.getUint32(4,!0));if(!r)return null;let i=n.getUint32(8,!0);if(i!==r.channels.length)throw q(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw q(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let t=n.getFloat64(12+8*e,!0),o=n.getFloat64(12+8*(i+e),!0);Number.isFinite(t)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t,v:o})}return a}async function rr(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw q(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:q(`block`,`body is not valid deflate`)}if(i!==t)throw q(`block`,`body size mismatch`);return r}async function ir(e,t){if(e.byteLength<$n)throw q(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Yn)throw q(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw q(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>er)throw q(`block`,`too large`);let u;if(r&Zn)u=await rr(e.subarray($n),l);else if(u=e.subarray($n),u.byteLength<l)throw q(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&Qn)!==0}}var J=Uint8Array,Y=Uint16Array,ar=Int32Array,or=new J([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),sr=new J([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),cr=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),lr=function(e,t){for(var n=new Y(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new ar(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},ur=lr(or,2),dr=ur.b,fr=ur.r;dr[28]=258,fr[258]=28;for(var pr=lr(sr,0),mr=pr.b,hr=pr.r,gr=new Y(32768),X=0;X<32768;++X){var _r=(X&43690)>>1|(X&21845)<<1;_r=(_r&52428)>>2|(_r&13107)<<2,_r=(_r&61680)>>4|(_r&3855)<<4,gr[X]=((_r&65280)>>8|(_r&255)<<8)>>1}for(var Z=(function(e,t,n){for(var r=e.length,i=0,a=new Y(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new Y(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new Y(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[gr[d]>>c]=l}else for(s=new Y(r),i=0;i<r;++i)e[i]&&(s[i]=gr[o[e[i]-1]++]>>15-e[i]);return s}),vr=new J(288),X=0;X<144;++X)vr[X]=8;for(var X=144;X<256;++X)vr[X]=9;for(var X=256;X<280;++X)vr[X]=7;for(var X=280;X<288;++X)vr[X]=8;for(var yr=new J(32),X=0;X<32;++X)yr[X]=5;var br=Z(vr,9,0),xr=Z(vr,9,1),Sr=Z(yr,5,0),Cr=Z(yr,5,1),wr=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Q=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},Tr=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Er=function(e){return(e+7)/8|0},Dr=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new J(e.subarray(t,n))},Or=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],$=function(e,t,n){var r=Error(t||Or[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,$),!n)throw r;return r},kr=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new J(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new J(i*3));var l=function(e){var t=n.length;if(e>t){var r=new J(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=Q(e,d,1);var v=Q(e,d+1,3);if(d+=3,!v){var y=Er(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&$(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}else if(v==1)p=xr,m=Cr,h=9,g=5;else if(v==2){var S=Q(e,d,31)+257,C=Q(e,d+10,15)+4,w=S+Q(e,d+5,31)+1;d+=14;for(var T=new J(w),E=new J(19),D=0;D<C;++D)E[cr[D]]=Q(e,d+D*3,7);d+=C*3;for(var O=wr(E),k=(1<<O)-1,A=Z(E,O,1),D=0;D<w;){var j=A[Q(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+Q(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+Q(e,d,7),d+=3):y==18&&(N=11+Q(e,d,127),d+=7);N--;)T[D++]=M}}var P=T.subarray(0,S),F=T.subarray(S);h=wr(P),g=wr(F),p=Z(P,h,1),m=Z(F,g,1)}else $(1);if(d>_){c&&$(0);break}}s&&l(f+131072);for(var ee=(1<<h)-1,I=(1<<g)-1,te=d;;te=d){var M=p[Tr(e,d)&ee],L=M>>4;if(d+=M&15,d>_){c&&$(0);break}if(M||$(2),L<256)n[f++]=L;else if(L==256){te=d,p=null;break}else{var R=L-254;if(L>264){var D=L-257,z=or[D];R=Q(e,d,(1<<z)-1)+dr[D],d+=z}var B=m[Tr(e,d)&I],ne=B>>4;B||$(3),d+=B&15;var F=mr[ne];if(ne>3){var z=sr[ne];F+=Tr(e,d)&(1<<z)-1,d+=z}if(d>_){c&&$(0);break}s&&l(f+131072);var re=f+R;if(f<F){var ie=a-F,ae=Math.min(F,re);for(ie+f<0&&$(3);f<ae;++f)n[f]=r[ie+f]}for(;f<re;++f)n[f]=n[f-F]}}t.l=p,t.p=te,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?Dr(n,0,f):n.subarray(0,f)},Ar=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},jr=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},Mr=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,a=n.slice();if(!i)return{t:zr,l:0};if(i==1){var o=new J(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(e,t){return e.f-t.f}),n.push({s:-1,f:25001});var s=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:s.f+c.f,l:s,r:c};u!=i-1;)s=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:s.f+c.f,l:s,r:c};for(var f=a[0].s,r=1;r<i;++r)a[r].s>f&&(f=a[r].s);var p=new Y(f+1),m=Nr(n[u-1],p,0);if(m>t){var r=0,h=0,g=m-t,_=1<<g;for(a.sort(function(e,t){return p[t.s]-p[e.s]||e.f-t.f});r<i;++r){var v=a[r].s;if(p[v]>t)h+=_-(1<<m-p[v]),p[v]=t;else break}for(h>>=g;h>0;){var y=a[r].s;p[y]<t?h-=1<<t-p[y]++-1:++r}for(;r>=0&&h;--r){var b=a[r].s;p[b]==t&&(--p[b],++h)}m=t}return{t:new J(p),l:m}},Nr=function(e,t,n){return e.s==-1?Math.max(Nr(e.l,t,n+1),Nr(e.r,t,n+1)):t[e.s]=n},Pr=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new Y(++t),r=0,i=e[0],a=1,o=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++a;else{if(!i&&a>2){for(;a>138;a-=138)o(32754);a>2&&(o(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(o(i),--a;a>6;a-=6)o(8304);a>2&&(o(a-3<<5|8208),a=0)}for(;a--;)o(i);a=1,i=e[s]}return{c:n.subarray(0,r),n:t}},Fr=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},Ir=function(e,t,n){var r=n.length,i=Er(t+2);e[i]=r&255,e[i+1]=r>>8,e[i+2]=e[i]^255,e[i+3]=e[i+1]^255;for(var a=0;a<r;++a)e[i+a+4]=n[a];return(i+4+r)*8},Lr=function(e,t,n,r,i,a,o,s,c,l,u){Ar(t,u++,n),++i[256];for(var d=Mr(i,15),f=d.t,p=d.l,m=Mr(a,15),h=m.t,g=m.l,_=Pr(f),v=_.c,y=_.n,b=Pr(h),x=b.c,S=b.n,C=new Y(19),w=0;w<v.length;++w)++C[v[w]&31];for(var w=0;w<x.length;++w)++C[x[w]&31];for(var T=Mr(C,7),E=T.t,D=T.l,O=19;O>4&&!E[cr[O-1]];--O);var k=l+5<<3,A=Fr(i,vr)+Fr(a,yr)+o,j=Fr(i,f)+Fr(a,h)+o+14+3*O+Fr(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&k<=A&&k<=j)return Ir(t,u,e.subarray(c,c+l));var M,N,P,F;if(Ar(t,u,1+(j<A)),u+=2,j<A){M=Z(f,p,0),N=f,P=Z(h,g,0),F=h;var ee=Z(E,D,0);Ar(t,u,y-257),Ar(t,u+5,S-1),Ar(t,u+10,O-4),u+=14;for(var w=0;w<O;++w)Ar(t,u+3*w,E[cr[w]]);u+=3*O;for(var I=[v,x],te=0;te<2;++te)for(var L=I[te],w=0;w<L.length;++w){var R=L[w]&31;Ar(t,u,ee[R]),u+=E[R],R>15&&(Ar(t,u,L[w]>>5&127),u+=L[w]>>12)}}else M=br,N=vr,P=Sr,F=yr;for(var w=0;w<s;++w){var z=r[w];if(z>255){var R=z>>18&31;jr(t,u,M[R+257]),u+=N[R+257],R>7&&(Ar(t,u,z>>23&31),u+=or[R]);var B=z&31;jr(t,u,P[B]),u+=F[B],B>3&&(jr(t,u,z>>5&8191),u+=sr[B])}else jr(t,u,M[z]),u+=N[z]}return jr(t,u,M[256]),u+N[256]},Rr=new ar([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),zr=new J(0),Br=function(e,t,n,r,i,a){var o=a.z||e.length,s=new J(r+o+5*(1+Math.ceil(o/7e3))+i),c=s.subarray(r,s.length-i),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=Rr[t-1],f=d>>13,p=d&8191,m=(1<<n)-1,h=a.p||new Y(32768),g=a.h||new Y(m+1),_=Math.ceil(n/3),v=2*_,y=function(t){return(e[t]^e[t+1]<<_^e[t+2]<<v)&m},b=new ar(25e3),x=new Y(288),S=new Y(32),C=0,w=0,T=a.i||0,E=0,D=a.w||0,O=0;T+2<o;++T){var k=y(T),A=T&32767,j=g[k];if(h[A]=j,g[k]=A,D<=T){var M=o-T;if((C>7e3||E>24576)&&(M>423||!l)){u=Lr(e,c,0,b,x,S,w,E,O,T-O,u),E=C=w=0,O=T;for(var N=0;N<286;++N)x[N]=0;for(var N=0;N<30;++N)S[N]=0}var P=2,F=0,ee=p,I=A-j&32767;if(M>2&&k==y(T-I))for(var te=Math.min(f,M)-1,L=Math.min(32767,T),R=Math.min(258,M);I<=L&&--ee&&A!=j;){if(e[T+P]==e[T+P-I]){for(var z=0;z<R&&e[T+z]==e[T+z-I];++z);if(z>P){if(P=z,F=I,z>te)break;for(var B=Math.min(I,z-2),ne=0,N=0;N<B;++N){var re=T-I+N&32767,ie=re-h[re]&32767;ie>ne&&(ne=ie,j=re)}}}A=j,j=h[A],I+=A-j&32767}if(F){b[E++]=268435456|fr[P]<<18|hr[F];var ae=fr[P]&31,V=hr[F]&31;w+=or[ae]+sr[V],++x[257+ae],++S[V],D=T+P,++C}else b[E++]=e[T],++x[e[T]]}}for(T=Math.max(T,D);T<o;++T)b[E++]=e[T],++x[e[T]];u=Lr(e,c,l,b,x,S,w,E,O,T-O,u),l||(a.r=u&7|c[u/8|0]<<3,u-=7,a.h=g,a.p=h,a.i=T,a.w=D)}else{for(var T=a.w||0;T<o+l;T+=65535){var oe=T+65535;oe>=o&&(c[u/8|0]=l,oe=o),u=Ir(c,u+1,e.subarray(T,oe))}a.i=o}return Dr(s,0,r+Er(u)+i)},Vr=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,a=n.length|0,o=0;o!=a;){for(var s=Math.min(o+2655,a);o<s;++o)i+=r+=n[o];r=(r&65535)+15*(r>>16),i=(i&65535)+15*(i>>16)}e=r,t=i},d:function(){return e%=65521,t%=65521,(e&255)<<24|(e&65280)<<8|(t&255)<<8|t>>8}}},Hr=function(e,t,n,r,i){if(!i&&(i={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),o=new J(a.length+e.length);o.set(a),o.set(e,a.length),e=o,i.w=a.length}return Br(e,t.level==null?6:t.level,t.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,i)},Ur=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},Wr=function(e,t){var n=t.level,r=n==0?0:n<6?1:n==9?3:2;if(e[0]=120,e[1]=r<<6|(t.dictionary&&32),e[1]|=31-(e[0]<<8|e[1])%31,t.dictionary){var i=Vr();i.p(t.dictionary),Ur(e,2,i.d())}},Gr=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&$(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&$(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},Kr=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new J(32768),this.p=new J(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||$(5),this.d&&$(4),!this.p.length)this.p=e;else if(e.length){var t=new J(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=kr(this.p,this.s,this.o);this.ondata(Dr(n,t,this.s.b),this.d),this.o=Dr(n,this.s.b-32768),this.s.b=this.o.length,this.p=Dr(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}();function qr(e,t){t||={};var n=Vr();n.p(e);var r=Hr(e,t,t.dictionary?6:2,4);return Wr(r,t),Ur(r,r.length-4,n.d()),r}var Jr=function(){function e(e,t){Kr.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(Kr.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(Gr(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&$(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),Kr.prototype.c.call(this,t)},e}();function Yr(e,t){return kr(e.subarray(Gr(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var Xr=typeof TextDecoder<`u`&&new TextDecoder;try{Xr.decode(zr,{stream:!0})}catch{}var Zr=56,Qr=[75,82,67,49];function $r(e){let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function ei(e){if(e.length<56||Qr.some((t,n)=>e[n]!==t))throw RangeError(`not a KRC1 chunk`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4,!0);if(n!==1)throw RangeError(`KRC version ${n}`);let r=t.getUint16(6,!0);if(r<56)throw RangeError(`KRC header too short`);return{recordingId:$r(e.subarray(8,24)),seq:t.getUint32(24,!0),count:t.getUint32(28,!0),bytes:t.getUint32(32,!0),headerBytes:r,t0:t.getFloat64(40,!0),t1:t.getFloat64(48,!0)}}function ti(e){let t=ei(e),n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Math.min(e.length,t.bytes),i=[],a=t.headerBytes;for(;i.length<t.count&&a+12<=r;){let t=n.getUint32(a+8,!0);if(a+12+t>r)break;i.push({at:n.getFloat64(a,!0),bytes:e.subarray(a+12,a+12+t)}),a+=12+t}return{header:t,messages:i,truncated:i.length<t.count}}var ni=(e,t,n)=>`recording_key:${e}|${t}:${n}`,ri=(e,t,n)=>n===e.stream_epoch?rt(e.stream_id,t,n):ni(e.id,t,n),ii=12,ai=16;function oi(e){let t=new Map;return async n=>{if(n.length===0)return null;let r=n[0]&128?2:1;if(n.length<r+ii+ai)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>e.keyId===i&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await Be(e,n.subarray(r,r+ii),n.subarray(r+ii),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}export{kt as $,r as $t,Vt as A,oe as At,Fe as B,te as Bt,Rt as C,ge as Ct,Lt as D,le as Dt,Nt as E,ue as Et,Le as F,R as Ft,lt as G,u as Gt,_t as H,M as Ht,pt as I,ae as It,At as J,v as Jt,wt as K,m as Kt,Ge as L,L as Lt,yt as M,re as Mt,it as N,z as Nt,Ft as O,ce as Ot,Ie as P,V as Pt,xt as Q,k as Qt,Ye as R,I as Rt,zt as S,Te as St,Bt as T,fe as Tt,ot as U,E as Ut,We as V,j as Vt,He as W,l as Wt,nt as X,b as Xt,vt as Y,h as Yt,at as Z,y as Zt,Rn as _,Oe as _t,ti as a,ut as at,Jt as b,_e as bt,Yr as c,rt as ct,tr as d,Ue as dt,n as en,bt as et,nr as f,ft,Wn as g,ke as gt,Un as h,Qe as ht,Zr as i,Tt as it,mt as j,ie as jt,Ht as k,se as kt,qr as l,Ze as lt,zn as m,gt as mt,ni as n,st as nt,ei as o,dt as ot,Jn as p,ht as pt,Dt as q,_ as qt,ri as r,St as rt,Jr as s,qe as st,oi as t,a as tn,Mt as tt,ir as u,et as ut,Yt as v,Ee as vt,Ut as w,pe as wt,Pt as x,we as xt,en as y,me as yt,jt as z,N as zt};