@kymoscope/sdk 0.25.0 → 0.27.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.
@@ -0,0 +1,12 @@
1
+ /*! @kymoscope/sdk (c) 2026 Kymoscope. Proprietary software: use requires a license. See LICENSE.md. */
2
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),u=Symbol(`row`),d=new WeakMap;function f(e){return d.get(e)}function p(e,t){let n=e.keys.lastIndexOf(t);return n<0?void 0:e.values[n]}var m=new WeakMap;function h(e,t){let n=e.keys.join(`
3
+ `),r=t&&m.get(t);if(r&&r.keys===n&&t.length===e.length){r.t=e;let n=new Proxy(r.base,{});return m.set(n,r),d.set(n,e),d.set(t,e),n}let i=Array(e.length),a={t:e,keys:n,base:i},o={};e.keys.forEach((e,t)=>{Object.defineProperty(o,e,{enumerable:!0,configurable:!0,get(){let e=this[u],{values:n,text:r}=a.t,i=n[t][e],o=r[t];return i===i?i:o?o[e]??null:null},set(t){Object.defineProperty(this,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}})});for(let t=0;t<e.length;t++){let e=Object.create(o);e[u]=t,i[t]=e}return m.set(i,a),d.set(i,e),i}function g(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}var _=[];function v(e){return _.push(e),e}function y(e){for(let t of _)t.delete(e)}function b(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(S(e))return{x0:r,bucket:o,rows:C(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 x=v(new WeakMap);function S(e){let t=x.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}x.set(e,t)}return t}function C(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 w(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 T(e,t,n,r,i,a){if(!S(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])]))}}function E(e,t){let n=Number(t?e.replace(`,`,`.`):e);return Number.isFinite(n)?n:null}function D(e,t){let n=e.trim();if(n===``)return null;let r=E(n,t);return r===null?n:r}function O(e,t){if(t===`,`)return!1;let n=0,r=0;for(let i of e)for(let e of A(i,t)){let t=e.trim();/^-?\d+,\d+$/.test(t)?n++:/^-?\d+\.\d+$/.test(t)&&r++}return n>r}function k(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 A(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 j(e,t){let n=0,r=0;for(let i of e){let e=i.trim();e!==``&&(n++,E(e,t)!==null&&r++)}return n>0&&r/n>=.5}function M(e,t,n,r){let i=A(e[t],n);if(j(i,r))return!1;let a=e.slice(t+1,t+11).map(e=>A(e,n));return a.length===0||i.every(e=>e.trim()===``)?!0:i.some((e,t)=>{let n=e.trim();return n!==``&&E(n,r)===null&&j(a.map(e=>e[t]??``),r)})}function N(e,t){if(t===void 0)return!1;let n=e=>/[\t,;]/.test(e);return!n(e)&&n(t)}function P(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 F(e,t){return e.headerRow===t.headerRow&&e.unitsRow===t.unitsRow&&e.dataStartRow===t.dataStartRow}function ee(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=A(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 I(e){let t=P(e);if(t.length===0)return{headerRow:0,unitsRow:null,dataStartRow:1};let n=t.slice(0,10),{delim:r,cols:i}=ee(n),a=e=>A(e,r).length===i,o=e=>A(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,l=s+1;if(t.length>s+1){let e=O(t.slice(s+1,s+11),r);M(t,s+1,r,e)&&(c=s+1,l=s+2)}return{headerRow:s,unitsRow:c,dataStartRow:l}}function te(e,t){let n=e[t]??``,r=A(n,k(n)).map(e=>e.trim());if(r.length===0||r.every(e=>e===``))throw Error(`No column names were found.`);return r}function L(e,t){let{table:n,...r}=R(e,t);return{...r,rows:g(n)}}function R(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 ie(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 ie(e,t);let c=k(a[n]??``),l=te(a,n),u=[];r!==null&&a[r]!==void 0&&(u=A(a[r],c).map(e=>e.trim())),u.length===0&&(u=l.map(()=>``));let d=O(a.slice(i,i+10),c),f=l.map((e,t)=>e||`col_${t}`),p=f.length,m=1;for(let t=e.indexOf(`
5
+ `,o);t>=0;t=e.indexOf(`
6
+ `,t+1))m++;let h=0;for(let t=e.indexOf(`\r`,o);t>=0;t=e.indexOf(`\r`,t+1))e.charCodeAt(t+1)!==10&&h++;m+=h;let g=f.map(()=>new Float64Array(m)),_=f.map(()=>null),v=0,y=(e,t)=>{typeof t==`number`?g[e][v]=t:(g[e][v]=NaN,t!==null&&((_[e]??=[])[v]=t))},b=e=>{let t=A(e,c);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<p;e++)y(e,t[e]===void 0?null:D(t[e],d));v++}},x=c.charCodeAt(0),S=x!==9&&e.indexOf(`"`,o)>=0||e.indexOf(``,o)>=0||h>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&&S)for(let t=s;t<n;t++){let n=e.charCodeAt(t);if(n===13||n===65279||n===34&&x!==9){r=!1;break}}if(r){let t=s;for(let r=0;r<p;r++){if(t>n){y(r,null);continue}let i=re(e,t,n,x,d);if(i===i){g[r][v]=i,t=ne+1;continue}let a=e.indexOf(c,t);(a<0||a>n)&&(a=n),y(r,D(e.slice(t,a),d)),t=a+1}v++}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&&b(t)}}s=t+1}let C=g.map(e=>m-v>m/100?e.slice(0,v):e.subarray(0,v));return{meta:a.length>0&&N(a[0],a[1])?a[0]:``,columnNames:l,units:u,table:{keys:f,length:v,values:C,text:_}}}var z=Array.from({length:23},(e,t)=>10**t),ne=0;function re(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*z[m];else if(m<0&&m>=-22)h=c/z[-m];else return NaN;return ne=a,s?-h:h}function ie(e,t){let n=P(e),{headerRow:r,unitsRow:i,dataStartRow:a}=t,o=k(n[r]??``),s=te(n,r),c=[];i!==null&&n[i]!==void 0&&(c=A(n[i],o).map(e=>e.trim())),c.length===0&&(c=s.map(()=>``));let l=n.slice(a),u=O(l.slice(0,10),o),d=s.map((e,t)=>e||`col_${t}`),f=l.length,p=d.map(()=>new Float64Array(f)),m=d.map(()=>null),h=0;for(let e of l){let t=A(e,o);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<d.length;e++){let n=t[e]===void 0?null:D(t[e],u);typeof n==`number`?p[e][h]=n:(p[e][h]=NaN,n!==null&&((m[e]??=[])[h]=n))}h++}}return h<f&&(p=p.map(e=>e.slice(0,h))),{meta:n.length>0&&N(n[0],n[1])?n[0]:``,columnNames:s,units:c,table:{keys:d,length:h,values:p,text:m}}}var ae=5e3;function oe(e,t){let n=se.get(e);n||se.set(e,n=new Map);let r=n.get(t);return r===void 0&&n.set(t,r=ce(e,t)),r}var se=new WeakMap;function ce(e,t){let n=f(e),r=n?n.keys.lastIndexOf(t):-1;if(n&&r>=0&&!n.text[r]){let e=n.values[r];for(let t=0;t<e.length;t++)if(e[t]===e[t])return!0;return!1}let i=e.length,a=0,o=0,s=Math.max(1,Math.floor(i/ae));for(let n=0;n<i;n+=s){let r=e[n][t];r!=null&&(a++,typeof r==`number`&&o++)}if(a===0&&s>1)for(let n=0;n<i&&a<ae;n++){let r=e[n][t];r!=null&&(a++,typeof r==`number`&&o++)}return a>0&&o/a>.95}function le(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 ue=v(new WeakSet),de={length:0,x:new Float64Array,cols:new Map};function fe(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 pe(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 me(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 he(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 pe(e,n)}function ge(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 _e(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 ve(e,t,n,r,i=``,a=0){let o=f(e),s=le(e.length,r),c=t=>{let n=o&&p(o,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},l=c(t),u=[];for(let e of s)Number.isNaN(l(e))||u.push(e);let d=u.length,m=d===e.length&&a===0,h=o&&p(o,t),g=m&&h?h:Float64Array.from(u,e=>l(e)+a),_=new Map;for(let e of n){let t=o&&p(o,e);if(o&&!t)continue;if(m&&t){_.set(e+i,t);continue}let n=c(e),r=Float64Array.from(u,n);!t&&!r.some(e=>!Number.isNaN(e))||_.set(e+i,r)}return{length:d,x:g,cols:_}}function ye(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 be(e){let t=e.filter(e=>e.length>0);if(t.length===0)return de;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 B=64,xe=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){this.end===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2)),n=this.lowerBound(e));let t=e=>e.copyWithin(n+1,n,this.end);return t(this.b),t(this.rowP),this.lo.forEach(t),this.hi.forEach(t),this.end++,n<this.mEnd&&this.mEnd++,this.dirty!==1/0&&this.dirty>=n&&this.dirty++,this.b[n]=e,this.clearRow(n),n}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}coarsen(e){let t=new Int32Array(this.end-this.start),n=this.start-1;for(let r=this.start;r<this.end;r++){let i=Math.floor(this.b[r]/e);(n<this.start||this.b[n]!==i)&&(this.b[++n]=i),t[r-this.start]=n}for(let e=0;e<this.nc;e++){let n=this.lo[e],r=this.hi[e],i=-1;for(let e=this.start;e<this.end;e++){let a=t[e-this.start],o=n[e],s=r[e];if(a!==i){n[a]=o,r[a]=s,i=a;continue}o===o&&(n[a]<=o||(n[a]=o),r[a]>=s||(r[a]=s))}}this.end=n+1,this.bucket*=e,this.dirty=1/0,this.dirtyFront=-1,this.invalid=!0}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=B-this.pStart,r=2*(t+e+B)<=this.px.length,i=r?this.px.length:Math.max(4*this.b.length+B,2*(t+e+B)),a=e=>{if(r)return e.copyWithin(B,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),B),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=B,this.pEnd=B+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}}writeAll(){let e=this.start,t=this.count,n=new Uint8Array(t);for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r];for(let r=0;r<t;r++){let t=a[e+r];t===t&&t!==i[e+r]&&(n[r]=1)}}let r=0;for(let e=0;e<t;e++)r+=1+n[e];this.pStart=this.pEnd=B,this.mStart=this.mEnd=e,this.reserve(r);let i=B;for(let r=0;r<t;r++){let t=(this.b[e+r]+.5)*this.bucket;this.rowP[e+r]=i,this.px[i]=t,n[r]&&(this.px[i+1]=t),i+=1+n[r]}for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r],o=this.pv[r];for(let r=0;r<t;r++){let t=this.rowP[e+r];o[t]=i[e+r],n[r]&&(o[t+1]=a[e+r])}}this.pEnd=i,this.mEnd=this.end}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.writeAll();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 Se(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}var Ce=4e6,we=60,Te=32,Ee=4096,V=1024,De=4;function Oe(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 ke(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 Ae=`ElapsedTime`,je=[];function Me(e){let t=je[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]])])))},je[e]=t}return t}var Ne=4096,Pe=4,Fe=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;pushedBefore=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCaches=new Map;winBlocks=new Map;winX=new Map;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;debugGrowCopied=0;timeDecs=new Map;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;listed=new Map;constructor(e,t=Ae,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,Ne),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){if(this.growing)try{return new Float64Array(this.growing.next).fill(NaN)}catch(e){this.refused(e)}return new Float64Array(this.alloc).fill(NaN)}growing=null;stepGrow(e){if(this.full)return;if(!this.growing){if(this.count<this.alloc*.75||this.alloc>=this.capacity)return;let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes)return;this.growing={next:e,todo:[null,...this.cols.keys()],owed:0}}let t=this.growing;t.owed+=t.todo.length*e/Math.max(1,this.alloc-this.count),this.moveColumns(Math.floor(t.owed))}moveColumns(e){let t=this.growing;for(;e>0&&t.todo.length>0;e--,t.owed--){let e=t.todo.pop(),n=e===null?this.time:this.cols.get(e);if(!n||n.length>=t.next)continue;let r;try{r=new Float64Array(t.next)}catch(e){this.refused(e);return}r.set(n),this.debugGrowCopied+=n.length,e===null?this.time=r:this.cols.set(e,r)}t.todo.length===0&&(this.alloc=t.next,this.growing=null)}growNow(){this.growing?this.moveColumns(1/0):this.grow()}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),this.debugGrowCopied+=t.length,n};try{this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n))}catch(e){this.refused(e);return}this.alloc=e}refused(e){if(!(e instanceof RangeError))throw e;this.capacity=this.alloc,this.growing=null}get version(){return this.pushedBefore+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)}let t=this.lastPushT;this.lastPushT=Math.max(t,e.t),!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let n=this.full?this.head:this.count;this.time[n]=e.t;for(let e of this.signalOrder)this.cols.get(e)[n]=NaN;for(let t of e.signals){if(this.computed.has(t.name))continue;let r=this.cols.get(t.name);r?t.unit&&t.unit!==this.unitByName.get(t.name)&&(this.unitByName.get(t.name)&&this.dropColumnSamples(t.name,r),this.unitByName.set(t.name,t.unit)):(r=this.newColumn(),this.cols.set(t.name,r),this.signalOrder.push(t.name),this.listed.delete(t.name),this.unitByName.set(t.name,t.unit??``)),r[n]=t.value,Number.isFinite(t.value)&&this.noteValue(t.name,e.t,t.value)}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0)),this.stepGrow(1),e.t<t&&this.placeLate(t,e.t,1,!0,this.pushed-1)}pushColumns(e){let t=e.t,n=t.length,r=ke(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.listed.delete(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}}let i=this.lastPushT,a=1/0,o=-1/0,s=!0,c=-1;for(let e=0;e<n;e++){let n=+t[e];n<(e>0?+t[e-1]:i)&&(c=e,e>0&&(s=!1)),n<a&&(a=n),n>o&&(o=n)}let l=this.pushed+c;this.lastPushT=Math.max(i,o);let u=Math.max(0,n-this.capacity);for(this.pushed+=u;u<n;){!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,i=Math.min(n-u,this.full?this.capacity-this.head:this.alloc-this.count);Oe(this.time,r,t,u,i);for(let t of this.signalOrder){let n=this.cols.get(t),a=this.computed.has(t)?void 0:e.columns[t];a?Oe(n,r,a,u,i):n.fill(NaN,r,r+i)}this.pushed+=i,u+=i,this.full?this.head=(this.head+i)%this.capacity:(this.count+=i,this.count===this.capacity&&(this.full=!0))}this.stepGrow(Math.min(n,this.capacity)),c>=0&&this.placeLate(i,a,Math.min(n,this.capacity),s,l)}placeLate(e,t,n,r,i){if(e-t>we){this.steppedBack(i);return}let a=this.size,o=a-n,s=e=>this.full?(this.head+e)%this.capacity:e,c=0,l=o;for(;c<l;){let e=c+l>>>1;this.time[s(e)]<=t?c=e+1:l=e}r||(c=Math.min(c,o));let u=a-c;if(u<2)return;if(u*(this.cols.size+1)>Ce||!this.timeMonotonic){this.steppedBack(i);return}let d=new Float64Array(u);for(let e=0;e<u;e++)d[e]=this.time[s(c+e)];let f=new Uint32Array(u);for(let e=0;e<u;e++)f[e]=e;f.sort((e,t)=>d[e]-d[t]||e-t);let p=new Set;for(let t=u-n;t<u;t++)if(!(t<0||d[t]>=e))for(let[e,n]of this.cols)Number.isFinite(n[s(c+t)])&&p.add(e);let m=[],h=this.snapDec;h&&h.key===`${this.signalOrder.join(`
8
+ `)}|${this.clears}`?m.push({k:h,names:this.signalOrder,ycols:this.signalOrder.map(e=>this.cols.get(e)),drop:()=>{this.snapDec===h&&(this.snapDec=null)}}):this.snapDec=null;for(let[e,t]of this.timeDecs)for(let n of t)m.push({k:n,names:n.cols,ycols:n.cols.map(e=>this.cols.get(e)),drop:()=>{let t=(this.timeDecs.get(e)??[]).filter(e=>e!==n);t.length>0?this.timeDecs.set(e,t):this.timeDecs.delete(e)}});let g=m.filter(e=>{let t=this.pushed-n-e.k.pushed;try{if(t<0||t>o||t*e.ycols.length>Ce)throw Error(`behind`);return t>0&&(this.foldBuckets(e.k.store,o-t,o,e.k.bucket,e.ycols),e.k.pushed+=t),!0}catch{return e.drop(),!1}}),_=new Float64Array(u),v=e=>{for(let t=0;t<u;t++)_[t]=e[s(c+f[t])];for(let t=0;t<u;t++)e[s(c+t)]=_[t]};v(this.time);for(let e of this.cols.values())v(e);let y=this.pushed-a+c;for(let e of this.decCaches.values())e.pushed>y&&(e.pushed=y);for(let e of this.winBlocks.values())for(let t of e.blocks.keys())(t+1)*V>y&&e.blocks.delete(t);for(let e of this.winX.values())for(let t of e.lo.keys())(t+1)*V>y&&(e.lo.delete(t),e.hi.delete(t));let b=this.passTrack;if(b&&b.done>y){b.cuts=b.cuts.filter(e=>e.abs<y),b.done=y,b.prevX=NaN;let e=this.cols.get(b.key);for(let t=y-1;e&&t>=this.pushed-a;t--){let n=e[this.physOf(t)];if(!Number.isNaN(n)){b.prevX=n;break}}}for(let t of g)if(t.names.some(e=>p.has(e)))try{for(let r=0;r<u;r++){if(f[r]<u-n||d[f[r]]>=e)continue;let i=s(c+r),a=Math.floor(this.time[i]/t.k.bucket);a>=t.k.fromB&&t.k.store.fold(t.k.store.row(a),t.ycols,i,i+1)}}catch{t.drop()}this.historyDec=null;for(let e of this.mirrors.values())e.end=Math.max(e.first,Math.min(e.end,y)),e.view=null;for(let[e,t]of this.boundsCache)t.loAbs>=y||t.hiAbs>=y?this.boundsCache.delete(e):(t.done=Math.min(t.done,y),t.version=-1)}steppedBack(e){this.lastBackAbs=e,this.timeDecs.clear(),this.snapDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCaches.clear(),this.winBlocks.clear(),this.winX.clear(),this.timeDecs.clear(),this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.pushedBefore+=this.pushed,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.growing=null,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCaches.clear(),this.winBlocks.clear(),this.winX.clear(),this.timeDecs.clear(),this.snapDec=null,this.latest.clear(),this.listed.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 b(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 fe(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.listed.delete(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.decCaches.clear(),this.winBlocks.clear(),this.winX.clear(),this.timeDecs.clear(),this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder,...this.listed.keys()]}get columnCount(){return 1+this.signalOrder.length+this.listed.size}has(e){return e===this.timeColumn||this.cols.has(e)||this.listed.has(e)}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??this.listed.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=Me(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)}}foldRuns(e,t,n,r,i,a){let o=a.length,s=Me(o),c=new Float64Array(o),l=new Float64Array(o),u=NaN,d=1/0,f=()=>{let t=e.get(u);t||(t={...s.row,b:u},e.set(u,t));for(let e=0;e<o;e++){if(!(c[e]<=l[e]))continue;let n=t[s.lo[e]],r=t[s.hi[e]];t[s.lo[e]]=n==null?c[e]:Math.min(n,c[e]),t[s.hi[e]]=r==null?l[e]:Math.max(r,l[e])}};for(let e=t;e<n;e++){let t=this.physOf(e),n=r[t];if(Number.isNaN(n))continue;this.debugLastScan++;let s=Math.floor(n/i);s!==u&&(Number.isNaN(u)||f(),u=s,c.fill(1/0),l.fill(-1/0),s<d&&(d=s));for(let e=0;e<o;e++){let n=a[e][t];n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}return Number.isNaN(u)||f(),d}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*Pe)))}let l=Se(s),u=o.join(`\0`),d=`${e}\u0001${u}`,f=this.decCaches.get(d)??null;if(f&&f.bucket>0&&s>=f.bucket*.5&&s<=f.bucket*2&&(l=f.bucket),!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let p=o.map(e=>this.cols.get(e)),m=this.size;this.debugLastScan=0;let h=f!==null&&e===this.timeColumn&&this.timeMonotonic&&f.xKey===e&&f.colsKey===u&&f.bucket===l&&this.pushed>=f.pushed&&this.pushed-f.pushed<m&&f.map.size<this.capacity*2,g=f!==null&&f.xKey===e&&f.colsKey===u&&f.bucket===l&&f.pushed===this.pushed,_=this.pushed-m,v=e===this.timeColumn&&this.timeMonotonic?_:Math.max(_,this.passStart(e,a)),y=f!==null&&(v>_||!this.full)&&f.xKey===e&&f.colsKey===u&&f.bucket===l&&f.passStart===v&&f.pushed>=v&&f.pushed<=this.pushed,b;if(g&&f)b=f.map;else if(y&&f)b=f.map,this.foldRuns(b,f.pushed,this.pushed,a,l,p),f.pushed=this.pushed;else if(h&&f){b=f.map;let e=this.pushed-f.pushed;for(let t=m-e;t<m;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(b,e,a,l,p)}if(this.full&&m>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=f.lowB;e<t;e++)b.delete(e);b.delete(t);for(let e=0;e<m;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(b,n,a,l,p)}}f.lowB=t}}f.pushed=this.pushed}else{b=new Map;let t=this.foldRuns(b,v,this.pushed,a,l,p);this.decCaches.delete(d),this.decCaches.set(d,{xKey:e,colsKey:u,cols:o,bucket:l,map:b,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:v}),this.decCaches.size>Te&&this.decCaches.delete(this.decCaches.keys().next().value)}let x=Math.floor(n/l),S=Math.floor(r/l),C=[];for(let e of b.values()){let t=e.b;t>=x&&t<=S&&C.push(e)}return C.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:C,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}timeIndexAfter(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}windowRange(e,t){let n=this.pushed-this.size;return[n+this.timeIndex(e),n+this.timeIndexAfter(t)]}decimateWindow(e,t,n,r,i,a,o){if(e===this.timeColumn||!this.timeMonotonic)return this.decimatePoints(e,t,n,r,i);let s=this.cols.get(e),c=s?t.filter(e=>this.cols.has(e)):[],l={length:0,x:new Float64Array,cols:new Map(c.map(e=>[e,new Float64Array]))},u=(r-n)/i;if(!s||c.length===0||!(u>0)||this.size===0)return l;let d=`${e}\u0001${c.join(`\0`)}`,f=this.winBlocks.get(d),p=f&&u>=f.bucket*.5&&u<=f.bucket*2?f.bucket:Se(u);if(!(p>0))return l;(!f||f.bucket!==p||f.clears!==this.clears)&&(f={bucket:p,clears:this.clears,blocks:new Map}),this.winBlocks.delete(d),this.winBlocks.set(d,f),this.winBlocks.size>Te&&this.winBlocks.delete(this.winBlocks.keys().next().value);let m=f.blocks,h=this.pushed-this.size;if(m.size>Math.ceil(this.size/V)+2)for(let e of m.keys())e*V<h&&m.delete(e);let g=c.map(e=>this.cols.get(e)),_=c.length,v=Math.floor(n/p),y=Math.floor(r/p)-v+1;if(!(y>0)||y>i*8+64)return l;let b=new Float64Array(y*_).fill(1/0),x=new Float64Array(y*_).fill(-1/0),S=new Uint8Array(y);this.debugLastScan=0;let C=(e,t)=>{this.debugLastScan+=t-e;for(let n=e;n<t;n++){let e=this.physOf(n),t=s[e];if(Number.isNaN(t))continue;let r=Math.floor(t/p)-v;if(r<0||r>=y)continue;S[r]=1;let i=r*_;for(let t=0;t<_;t++){let n=g[t][e];n<b[i+t]&&(b[i+t]=n),n>x[i+t]&&(x[i+t]=n)}}},[w,T]=this.windowRange(a,o),E=Math.ceil(w/V),D=Math.floor(T/V);if(E>=D)C(w,T);else{C(w,E*V),C(D*V,T);for(let e=E;e<D;e++){let t=m.get(e);t||(t=this.winBlock(e,s,p,g),m.set(e,t));for(let e=0;e<t.n;e++){let n=t.b[e]-v;if(n<0||n>=y)continue;S[n]=1;let r=n*_,i=e*_;for(let e=0;e<_;e++)t.lo[i+e]<b[r+e]&&(b[r+e]=t.lo[i+e]),t.hi[i+e]>x[r+e]&&(x[r+e]=t.hi[i+e])}}}let O=0,k=new Uint8Array(y);for(let e=0;e<y;e++)if(S[e]){O++;for(let t=0;t<_;t++)if(x[e*_+t]>b[e*_+t]){k[e]=1,O++;break}}let A=new Float64Array(O),j=c.map(()=>new Float64Array(O)),M=0;for(let e=0;e<y;e++){if(!S[e])continue;let t=(v+e+.5)*p,n=e*_;A[M]=t;for(let e=0;e<_;e++)j[e][M]=b[n+e]<=x[n+e]?b[n+e]:NaN;if(M++,k[e]){A[M]=t;for(let e=0;e<_;e++)j[e][M]=b[n+e]<=x[n+e]?x[n+e]:NaN;M++}}return{length:O,x:A,cols:new Map(c.map((e,t)=>[e,j[t]]))}}winBlock(e,t,n,r){let i=r.length,a=[],o=new Map,s=[],c=[],l=NaN,u=-1;this.debugLastScan+=V;for(let d=e*V;d<(e+1)*V;d++){let e=this.physOf(d),f=t[e];if(Number.isNaN(f))continue;let p=Math.floor(f/n);if(p!==l){l=p;let e=o.get(p);if(e===void 0){e=a.length,o.set(p,e),a.push(p);for(let e=0;e<i;e++)s.push(1/0),c.push(-1/0)}u=e*i}for(let t=0;t<i;t++){let n=r[t][e];n<s[u+t]&&(s[u+t]=n),n>c[u+t]&&(c[u+t]=n)}}return{n:a.length,b:Float64Array.from(a),lo:Float64Array.from(s),hi:Float64Array.from(c)}}windowXBounds(e,t,n){let r=this.cols.get(e);if(!r||this.size===0||!this.timeMonotonic)return null;let i=this.winX.get(e);(!i||i.clears!==this.clears)&&(i={clears:this.clears,lo:new Map,hi:new Map},this.winX.set(e,i));let a=this.pushed-this.size;if(i.lo.size>Math.ceil(this.size/V)+2)for(let e of i.lo.keys())e*V<a&&(i.lo.delete(e),i.hi.delete(e));let o=1/0,s=-1/0,c=(e,t)=>{for(let n=e;n<t;n++){let e=r[this.physOf(n)];e<o&&(o=e),e>s&&(s=e)}},[l,u]=this.windowRange(t,n),d=Math.ceil(l/V),f=Math.floor(u/V);if(d>=f)c(l,u);else{c(l,d*V),c(f*V,u);for(let e=d;e<f;e++)if(i.lo.has(e))o=Math.min(o,i.lo.get(e)),s=Math.max(s,i.hi.get(e));else{let t=o,n=s;o=1/0,s=-1/0,c(e*V,(e+1)*V),i.lo.set(e,o),i.hi.set(e,s),o=Math.min(t,o),s=Math.max(n,s)}}return o<=s?{x0:o,x1:s}:null}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=Me(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 fe(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*Pe)))}let d=Se(u),f=i.join(` `),p=this.timeDecs.get(f)??[],m=p.find(e=>u>=e.bucket*.5&&u<=e.bucket*2)??null;if(m&&(d=m.bucket),!(d>0))return o;let h=i.map(e=>this.cols.get(e)),g=Math.floor(t/d),_=Math.floor(n/d);this.debugLastScan=0;let v=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(g),i1:e.lowerBound(_+1)});if(n<l-(n-t)){let e=this.timeIndex(g*d),t=this.timeIndex((_+1)*d),n=this.pushed-a,r=`${f}|${d}|${g}|${_}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new xe(i.length,d);this.foldBuckets(n,e,t,d,h),this.historyDec={key:r,store:n}}return v(this.historyDec.store)}let y=m?this.pushed-m.pushed:0;if(m&&m.colsKey===f&&m.bucket===d&&y>=0&&y<a){let e=m.store;if(g<m.fromB){let t=new xe(i.length,d);this.foldBuckets(t,this.timeIndex(g*d),this.timeIndex(m.fromB*d),d,h);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]}m.fromB=g}y>0&&this.foldBuckets(e,a-y,a,d,h);let t=Math.floor(c/d);return this.full&&t>=m.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,h),m.fromB=t),g>m.fromB&&(e.dropBelow(g),m.fromB=g),m.pushed=this.pushed,v(e)}let b=new xe(i.length,d),x=this.timeIndex(g*d);this.foldBuckets(b,x,a,d,h);let S={colsKey:f,cols:i,bucket:d,store:b,pushed:this.pushed,fromB:x===0?Math.floor(c/d):g};return this.timeDecs.delete(f),this.timeDecs.set(f,[S,...p.filter(e=>e!==m&&e.bucket!==d)].slice(0,De)),this.timeDecs.size>Te&&this.timeDecs.delete(this.timeDecs.keys().next().value),v(b)}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=this.timeMonotonic?Math.max(1,Math.ceil((r-this.timeIndex(a-t))/Ee)):1,s=0,c=NaN,l=a;for(let e=r-1;e>=0;e-=o){let r=i(e),o=this.time[r];if(o<a-t)break;let u=n[r];Number.isNaN(u)||(c>u&&(s+=c-u),c=u,l=o)}let u=a-l;return u>0&&u<t?s*t/u:s}timeAfter(e){if(!this.timeMonotonic)return NaN;let t=e=>this.full?(this.head+e)%this.capacity:e,n=0,r=this.size;for(;n<r;){let i=n+r>>>1;this.time[t(i)]<=e?n=i+1:r=i}return n<this.size?this.time[t(n)]:NaN}latestTime(){return this.size===0?NaN:this.columnBounds(this.timeColumn).x1}xAtTime(e,t,n=!1){let r=this.columnArray(e),i=this.size;if(!r||i===0)return NaN;if(e===this.timeColumn&&!n){let{x0:n,x1:r}=this.columnBounds(e);return Math.min(r,Math.max(n,t))}if(!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;if((!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),this.timeMonotonic&&n>=64*V)){let t=this.windowXBounds(e,-1/0,1/0),n=Math.ceil(r/V)*V;t&&(i.lo=t.x0,i.hi=t.x1,i.loAbs=n,i.hiAbs=n),i.done=this.pushed}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.listed.keys()],n=[this.timeColumn,...this.signalOrder,...t],r=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``),...t.map(e=>this.listed.get(e))],i=this.size,a=e&&e>0&&i>e?Math.ceil(i/e):1,o=a>1&&this.timeMonotonic?this.snapshotRows(e,t):null;if(o)return{meta:``,columnNames:n,units:r,rows:o};let s=this.pushed-i,c=a>1?(a-s%a)%a:0,l=[];for(let e=c;e<i;e+=a)l.push(this.full?(this.head+e)%this.capacity:e);i>0&&(l.length===0||(i-1-c)%a!=0)&&l.push(this.full?(this.head+i-1)%this.capacity:i-1);let u=e=>{let t=new Float64Array(l.length);for(let n=0;n<l.length;n++)t[n]=e[l[n]];return t},d=t.length?new Float64Array(l.length).fill(NaN):null;return{meta:``,columnNames:n,units:r,rows:Ie(n,[u(this.time),...this.signalOrder.map(e=>u(this.cols.get(e))),...t.map(()=>d)])}}snapshotRows(e,t){let n=this.size,r=e=>this.full?(this.head+e)%this.capacity:e,i=this.time[r(0)],a=this.time[r(n-1)],o=(a-i)*2/e;if(!(o>0))return null;let s=`${this.signalOrder.join(`
9
+ `)}|${this.clears}`,c=this.signalOrder.map(e=>this.cols.get(e)),l=this.snapDec,u=l?this.pushed-l.pushed:0;if(l&&l.key===s&&l.bucket<o&&u>=0&&u<n){let e=2;for(;l.bucket*e<o;)e*=2;l.store.coarsen(e),l.bucket*=e,l.fromB=Math.floor(l.fromB/e)}if(l&&l.key===s&&l.bucket>=o&&l.bucket<=o*4&&u>=0&&u<n){let e=l.store;u>0&&this.foldBuckets(e,n-u,n,l.bucket,c);let t=Math.floor(i/l.bucket);this.full&&t>=l.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*l.bucket),l.bucket,c),l.fromB=t),l.pushed=this.pushed}else{let t=2**Math.ceil(Math.log2(o));t<o&&(t*=2);let r=new xe(c.length,t,Math.ceil(e/2)+8);this.foldBuckets(r,0,n,t,c),l=this.snapDec={key:s,bucket:t,store:r,pushed:this.pushed,fromB:Math.floor(i/t)}}let d=l.store.toPoints(l.store.start,l.store.end,this.signalOrder),f=new Float64Array(d.x),p=f[0],m=f[f.length-1];for(let e=0;e<f.length;e++)f[e]=f[e]===m?a:f[e]===p?i:f[e];let h=t.length?new Float64Array(f.length).fill(NaN):null;return Ie([this.timeColumn,...this.signalOrder,...t],[f,...this.signalOrder.map(e=>new Float64Array(d.cols.get(e))),...t.map(()=>h)])}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 memoryBudget(){return this.maxBytes}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}list(e,t,n=NaN,r=NaN){e===this.timeColumn||this.computed.has(e)||(this.cols.has(e)||this.listed.set(e,t),Number.isFinite(n)&&Number.isFinite(r)&&this.noteValue(e,n,r))}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.listed.delete(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})}};function Ie(e,t){return h({keys:e,length:t[0]?.length??0,values:t,text:e.map(()=>null)})}var Le=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function Re(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function ze(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}var Be=new TextDecoder(`utf-8`),Ve=new TextDecoder(`latin1`);function He(e,t=!1){let n=e.indexOf(0);return(t?Ve:Be).decode(n<0?e:e.subarray(0,n))}var Ue=e=>Ve.decode(e),We=e=>Be.decode(e);function H(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 Ge={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>H(e,`MDF `)||H(e,`UnFinMF `)},Ke={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>H(e,`0 `)||e[0]===255&&H(e,`BIOSEMI`,1)},qe={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>H(e,`XDF:`)},Je={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>H(e,`TDSm`)},Ye={id:`mat`,label:`MATLAB MAT (v5, v7.3)`,extensions:[`.mat`],sniff:e=>H(e,`MATLAB 5.0 MAT-file`)||H(e,`MATLAB 7.3 MAT-file`)},Xe=`‰HDF\r
10
+ 
11
+ `,Ze={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>H(e,Xe,t))},Qe={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=Ue(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])}};function $e(e,t){if(t+24>e.length||e[t]!==37||e[t+1]!==235)return!1;let n=0;for(let r=0;r<22;r+=2)n+=e[t+r]|e[t+r+1]<<8;if((n&65535)!=(e[t+22]|e[t+23]<<8))return!1;let r=(e[t+4]|e[t+5]<<8|e[t+6]<<16)+e[t+7]*16777216,i=(e[t+8]|e[t+9]<<8|e[t+10]<<16)+e[t+11]*16777216,a=e[t+14]&128?36:24;return r<=(e[t+15]===1?134217728:524288)&&i+a<=r}var et={id:`ch10`,label:`IRIG 106 Chapter 10`,extensions:[`.ch10`,`.c10`],sniff:e=>$e(e,0),companions:[{ext:`.csv`,anyName:!0}]},tt=1<<20,nt=64,rt=16<<20,it=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>tt)return this.slice(e,n-e);let r=Math.floor(e/tt),i=Math.floor((n-1)/tt),a=await this.#n(r);if(r===i)return a.subarray(e-r*tt,n-r*tt);let o=new Uint8Array(n-e),s=a.subarray(e-r*tt);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*tt),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=rt){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*tt,tt);return this.#t.size>=nt&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}},at=327680,ot=1e4,st=64<<20,ct=3e4,lt=()=>({frames:0,other:0,truncated:0,incomplete:0,cut:!1,damagedAt:null}),ut=new Map([[2712847316,{le:!0,ns:!1}],[3569595041,{le:!1,ns:!1}],[2712812621,{le:!0,ns:!0}],[1295823521,{le:!1,ns:!0}]]),dt=168627466;function ft(e){if(e.length<24)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0);if(ut.has(t))return`pcap`;if(t===dt&&e.length>=12){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8,!0);if(t===439041101||t===1295788826)return`pcapng`}return null}var pt=class{#e;stats;done=!1;#t=null;#n=!0;#r=!1;#i=1;#a=[];#o=NaN;#s=new Map;#c=0;#l=null;#u={time:0,sport:0,dport:0,b:new Uint8Array,o:0,n:0};constructor(e,t=lt()){this.#e=e,this.stats=t}feed(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0,i=e=>{this.stats.damagedAt=t+e,this.done=!0};if(!this.#t){if(this.#t=ft(e),!this.#t)return i(0),0;if(this.#t===`pcap`){let e=ut.get(n.getUint32(0,!0));this.#n=e.le,this.#r=e.ns,this.#i=n.getUint32(20,this.#n)&65535,r=24}}if(this.#t===`pcap`){let t=this.#n;for(;!this.done&&e.length-r>=16;){let a=n.getUint32(r+8,t);if(a>262144){i(r);break}if(e.length-r-16<a)break;let o=n.getUint32(r,t)*1e3+n.getUint32(r+4,t)/(this.#r?1e6:1e3);this.#f(this.#i,e,n,r+16,a,o),r+=16+a}return r}for(;!this.done&&e.length-r>=12;){let t=n.getUint32(r,this.#n);if(t===dt){let e=n.getUint32(r+8,!0);if(e!==439041101&&e!==1295788826){i(r);break}this.#n=e===439041101,t=dt}let a=this.#n,o=n.getUint32(r+4,a);if(o<12||o%4||o>at){i(r);break}if(e.length-r<o)break;if(n.getUint32(r+o-4,a)!==o){i(r);break}if(t===dt)this.#a=[];else if(t===1&&o>=20)this.#a.push(this.#d(e,n,r,o));else if(t===6&&o>=32){let t=this.#a[n.getUint32(r+8,a)],i=n.getUint32(r+20,a);if(!t||i>o-32)this.stats.other++;else{let o=(n.getUint32(r+12,a)*4294967296+n.getUint32(r+16,a))*t.tick+t.offsetMs;this.#o=o,this.#f(t.link,e,n,r+28,i,o)}}else if(t===3&&o>=16){let t=this.#a[0],i=Math.min(n.getUint32(r+8,a),o-16);t?this.#f(t.link,e,n,r+12,i,this.#o):this.stats.other++}r+=o}return r}finish(){this.#m(),this.stats.incomplete+=this.#s.size,this.#s.clear(),this.#c=0}#d(e,t,n,r){let i=this.#n,a={link:t.getUint16(n+8,i),tick:.001,offsetMs:0};for(let o=n+16;o+4<=n+r-4;){let s=t.getUint16(o,i),c=t.getUint16(o+2,i);if(s===0||o+4+c>n+r-4)break;if(s===9&&c>=1){let t=e[o+4];a.tick=(t&128?2**-(t&127):10**-t)*1e3}else s===14&&c>=8&&(a.offsetMs=(t.getInt32(o+4+(i?4:0),i)*4294967296+t.getUint32(o+4+(i?0:4),i))*1e3);o+=4+c+(-c&3)}return a}#f(e,t,n,r,i,a){this.stats.frames++;let o=r+i,s=r,c;if(e===1){if(i<14)return void this.stats.other++;for(c=n.getUint16(s+12),s+=14;(c===33024||c===34984||c===37120)&&s+4<=o;)c=n.getUint16(s+2),s+=4}else if(e===113){if(i<16)return void this.stats.other++;c=n.getUint16(s+14),s+=16}else if(e===276){if(i<20)return void this.stats.other++;c=n.getUint16(s),s+=20}else if(e===101||e===228||e===229){if(i<1)return void this.stats.other++;c=t[s]>>4==4?2048:t[s]>>4==6?34525:0}else return void this.stats.other++;c===2048?this.#p(t,n,s,o,a):c===34525?this.#g(t,n,s,o,a):this.stats.other++}#p(e,t,n,r,i){if(r-n<20||e[n]>>4!=4)return void this.stats.other++;let a=(e[n]&15)*4,o=t.getUint16(n+2);if(a<20||o<a||e[n+9]!==17)return void this.stats.other++;if(n+o>r)return void this.stats.truncated++;let s=t.getUint16(n+6),c=(s&8191)*8,l=(s&8192)!=0,u=n+a,d=o-a;if(!c&&!l)return this.#_(e,t,u,u+d,i);if(c+d>65535)return void this.stats.other++;let f=`${t.getUint32(n+12)}:${t.getUint32(n+16)}:${t.getUint16(n+4)}`;this.#l&&this.#l.key!==f&&this.#m();for(let e of this.#s.values()){if(!(e.ms<i-ct))break;this.#h(e)}for(;this.#s.size&&this.#c+d>st;)this.#h(this.#s.values().next().value);let p=e.subarray(u,u+d),m=this.#s.get(f);if(m){let e=mt(m,c,p,l);if(e<0&&m.whole)return;if(e>=0){m.counted||this.stats.incomplete++,m.counted=!0,m===this.#l&&(this.#l=null),m.whole=null;for(let t of m.parts.splice(0,e+1))m.held-=t.b.length,this.#c-=t.b.length;m.ms=m.parts.reduce((e,t)=>Math.min(e,t.ms),i),this.#s.delete(f),this.#s.set(f,m)}}else{for(;this.#s.size>=ot;)this.#h(this.#s.values().next().value);this.#s.set(f,m={key:f,parts:[],held:0,ms:i,counted:!1,whole:null,wholeMs:0})}if(m.held+d>2*65535){this.#s.delete(f),this.#c-=m.held,this.stats.incomplete++;return}m.parts.push({off:c,b:p.slice(),ms:i,last:!l}),m.held+=d,this.#c+=d;let h=ht(m.parts);h&&(m.whole=h,m.wholeMs=i,this.#l=m)}#m(){let e=this.#l;e&&(this.#l=null,this.#s.delete(e.key),this.#c-=e.held,this.#_(e.whole,new DataView(e.whole.buffer),0,e.whole.length,e.wholeMs))}#h(e){if(e===this.#l)return this.#m();this.#s.delete(e.key),this.#c-=e.held,this.stats.incomplete++}#g(e,t,n,r,i){if(r-n<40||e[n]>>4!=6)return void this.stats.other++;let a=n+40+t.getUint16(n+4);if(a>r)return void this.stats.truncated++;let o=e[n+6];for(n+=40;(o===0||o===43||o===60)&&n+8<=a;){let t=e[n];n+=(e[n+1]+1)*8,o=t}if(o!==17||n>a)return void this.stats.other++;this.#_(e,t,n,a,i)}#_(e,t,n,r,i){if(this.#l&&this.#m(),r-n<8)return void this.stats.other++;let a=t.getUint16(n+4);if(a<8)return void this.stats.other++;if(n+a>r)return void this.stats.truncated++;let o=this.#u;o.time=i,o.sport=t.getUint16(n),o.dport=t.getUint16(n+2),o.b=e,o.o=n+8,o.n=a-8,this.#e(o)}};function mt(e,t,n,r){let i=t+n.length,a=-1;return e.parts.forEach((e,o)=>{let s=e.off+e.b.length;if(e.last&&(r?i>s:i!==s)||!r&&s>i){a=o;return}for(let r=Math.max(t,e.off);r<Math.min(i,s);r++)if(n[r-t]!==e.b[r-e.off]){a=o;return}}),a}function ht(e){let t=e.find(e=>e.last);if(!t)return null;let n=t.off+t.b.length,r=[...e].sort((e,t)=>e.off-t.off),i=0;for(let e of r){if(e.off>i)return null;i=Math.max(i,e.off+e.b.length)}if(i<n)return null;let a=new Uint8Array(n);for(let e of r)a.set(e.b.subarray(0,Math.max(0,n-e.off)),e.off);return a}async function*gt(e,t,n,r){let i=new pt(t,n),a=0;for(;a<e.size&&!i.done;){r?.throwIfAborted();let t=await e.slice(a,Math.min(rt,e.size-a)),o=a+t.length>=e.size,s=i.feed(t,a);if(a+=s,o||s===0){!i.done&&a<e.size&&(n.cut=!0);break}yield}i.finish()}var _t=57005;function vt(e,t,n,r=_t){if(n<16||n&1||(e[t+2]<<8|e[t+3])*2!==n)return!1;let i=e[t+n-2]<<8|e[t+n-1];return i===57005||i===r}function yt(e){if(!ft(e))return!1;let t=!1,n=new pt(e=>{e.n>=16&&!(e.n&1)&&(e.b[e.o+2]<<8|e.b[e.o+3])*2===e.n&&(t=n.done=!0)});try{n.feed(e,0),t||n.finish()}catch{return!1}return t}var bt={id:`iena`,label:`IENA flight-test network capture`,extensions:[`.pcap`,`.pcapng`,`.cap`],companions:[`.xidml`,`.xml`,`.yaml`,`.yml`,`.csv`].map(e=>({ext:e,anyName:!0})),sniff:yt,sniffBytes:e=>ft(e)?1<<20:0},xt=65542,St=(e,t)=>(e[t]&224)==0,Ct=(e,t)=>(e[t]&7)<<8|e[t+1],wt=(e,t)=>e[t+2]>>6,Tt=(e,t)=>(e[t+2]&63)<<8|e[t+3],Et=(e,t)=>(e[t+4]<<8|e[t+5])+7,Dt=()=>({idle:0,segments:0,skipped:0,cut:!1}),Ot=class{#e=new Map;#t;#n;constructor(e,t){this.#t=e,this.#n=t}push(e,t,n){let r=Ct(e,t);if(r===2047){this.#n.idle++;return}let i=wt(e,t);if(i===3){this.#t(e,t,n);return}let a=this.#e.get(r),o=Tt(e,t);if(i===1){a&&(this.#n.segments++,this.#e.delete(r));let i=new Uint8Array(Math.min(xt,Math.max(n*2,256)));i.set(e.subarray(t,t+n)),this.#e.set(r,{buf:i,n,count:o});return}if(!a||(a.count+1&16383)!==o||a.n+n-6>65542){this.#n.segments+=a?2:1,this.#e.delete(r);return}let s=a.n+n-6;if(s>a.buf.length){let e=new Uint8Array(Math.min(xt,Math.max(s,a.buf.length*2)));e.set(a.buf.subarray(0,a.n)),a.buf=e}a.buf.set(e.subarray(t+6,t+n),a.n),a.n=s,a.count=o,i===2&&(this.#e.delete(r),this.#t(a.buf,0,a.n))}};function kt(e,t,n,r,i){let a=0,o=e.length;for(;a+6<=o;){if(!St(e,a)){n.skipped++,i.on=!0,a++;continue}let s=Et(e,a);if(a+s>o){if(!r)return a;if(i.on){n.skipped++,a++;continue}return n.cut=!0,o}if(i.on){if(a+s+6<=o){if(!St(e,a+s)){n.skipped++,a++;continue}}else if(!r)return a;i.on=!1}t.push(e,a,s),a+=s}return r&&a<o?(n.cut=!0,o):a}function At(e,t=4){let n=0,r=0,i=!1,a=!0,o=new Map;for(;n+6<=e.length&&!(r>=t&&n>=4096);){if(!St(e,n))return!1;let t=Ct(e,n),s=Tt(e,n),c=o.get(t);c!==void 0&&(c+1&16383)===s&&(i=!0),o.set(t,s),e[n]|e[n+1]|e[n+2]|e[n+3]&&(a=!1),n+=Et(e,n),r++}return r>=t&&i&&!a}var jt=Uint8Array.of(26,207,252,29),Mt=65536,Nt=(()=>{let e=new Uint8Array(255),t=255;for(let n=0;n<2040;n++){let r=t>>7;e[n>>3]|=r<<7-(n&7);let i=t>>7^t>>4^t>>2^t;t=(t<<1|i&1)&255}return e})(),Pt=(()=>{let e=new Uint16Array(256);for(let t=0;t<256;t++){let n=t<<8;for(let e=0;e<8;e++)n=n&32768?n<<1^4129:n<<1;e[t]=n&65535}return e})();function Ft(e,t,n){let r=65535;for(let i=t;i<t+n;i++)r=(r<<8^Pt[(r>>8^e[i])&255])&65535;return r}var It=(e,t)=>t+4<=e.length&&e[t]===26&&e[t+1]===207&&e[t+2]===252&&e[t+3]===29;function Lt(e,t){for(let n=e.indexOf(26,t);n>=0;n=e.indexOf(26,n+1))if(It(e,n))return n;return-1}function Rt(e,t,n,r,i){let a=i.subarray(0,n);if(a.set(e.subarray(t,t+n)),r)for(let e=0;e<n;e++)a[e]^=Nt[e%255];return a}var zt=Uint8Array.from({length:256},(e,t)=>{let n=0;for(let e=t;e;e&=e-1)n++;return n});function Bt(e,t){if(t+4>e.length)return!1;let n=0;for(let r=0;r<4&&n<=2;r++)n+=zt[e[t+r]^jt[r]];return n<=2}function Vt(e,t,n,r,i){let a=new Map,o=0;for(let s of t){if(s+n>e.length)break;let t=Rt(e,s,n,r,i),c=t[1]>>1&7,l=t[4]<<8|t[5],u=6+(l&32768?(t[6]&63)+1:0),d=n-(t[1]&1?4:0),f=l&2047,p=a.get(c),m=p&&(p[0]+1&255)===t[3]?p[1]:-1,h=-1;if(u<d&&f===2047)h=m>=d-u?m-(d-u):-1;else if(f<2046&&u+f<d){m>=0&&m===f&&o++;let e=u+f;for(;d-e>=6&&e+Et(t,e)<=d;)e+=Et(t,e);h=e===d?0:d-e>=6?e+Et(t,e)-d:-1}a.set(c,[t[3],h])}return o}function Ht(e){let t=Lt(e,0);if(t<0||t>65536)return null;for(let n=t+4+7;n-t-4<=65536&&n+4<=e.length;n++){if(!Bt(e,n))continue;let r=n-t,i=0,a=0,o=[];for(let n=t;n+4<=e.length;n+=r)i++,Bt(e,n)&&(a++,n+r<=e.length&&o.push(n+4));if(a<3||a<.9*i||o.length<2)continue;let s=new Uint8Array(r),c=t=>{let n=0,i=-1,a=-1,c=[];for(let l of o){let o=Rt(e,l,Math.min(6,r-4),t,s),u=(o[0]&63)<<4|o[1]>>4,d=o[1]>>1&7;!(o[0]>>6)&&(a<0||u===a)&&n++,i>=0&&(i+1&255)===o[2]&&n++,c[d]!==void 0&&(c[d]+1&255)===o[3]&&n++,i=o[2],c[d]=o[3],a=u}return n},l=c(!1),u=c(!0),d=u>l,f=-1;if(2*Math.max(l,u)<3*o.length)for(let t of[!1,!0]){let n=o.map(n=>{let r=Rt(e,n,1,t,s)[0];return r>>6==1?1:r>>4==12?12:-1});if(n[0]>=0&&n.every(e=>e===n[0])){f=n[0],d=t;break}}let p=Rt(e,o[0],Math.min(6,r-4),d,s);f<0&&(f=p[0]>>6==3&&p[0]>>4==12?12:p[0]>>6);let m=(r-4)%255==0&&(r-4)/255<=8,h=m?[223,239].map(e=>(r-4)/255*e).concat(r-4):[r-4],g=h.find(t=>o.filter(n=>Ft(Rt(e,n,t,d,s),0,t)===0).length*2>o.length),_=g??r-4;if(g===void 0&&m&&f===0){let t=-1;for(let n of h){let r=Vt(e,o,n,d,s);r>t&&(t=r,_=n)}}return{start:t,cadu:r,frame:_,randomized:d,fecf:g!==void 0,version:f,scid:(p[0]&63)<<4|p[1]>>4}}return null}var Ut=()=>({frames:0,vcs:new Set,badFecf:0,gaps:new Map,idleFrames:0,partial:0,damaged:0,notPackets:0,outOfSync:0,badSync:0}),Wt=class{#e=[];#t;#n;#r;constructor(e,t,n){this.#t=e,this.#n=t,this.#r=n}#i(e){e.open&&this.#r.partial++,e.open=!1}#a(e,t,n,r){for(;n<r&&e.open;){let i=e.need<0?6:e.need,a=Math.min(i-e.n,r-n);if(e.buf.set(t.subarray(n,n+a),e.n),e.n+=a,n+=a,e.n<i)break;if(e.need<0){if(!St(e.buf,0)){this.#i(e);break}if(e.need=Et(e.buf,0),e.buf.length<e.need){let t=new Uint8Array(e.need);t.set(e.buf.subarray(0,e.n)),e.buf=t}continue}e.open=!1,this.#n.push(e.buf,0,e.n)}return n}#o(e,t,n,r){e.open=!0,e.n=0,e.need=-1,this.#a(e,t,n,r)}frame(e){let t=this.#r,n=this.#t,r=n.frame;t.frames++;let i=(e[0]&63)<<4|e[1]>>4;if(e[0]>>6||i!==n.scid){t.damaged++;return}let a=e[1]>>1&7,o=this.#e[a];o||(this.#e[a]=o={buf:new Uint8Array(256),n:0,need:-1,count:-1,open:!1,orphan:!1}),t.vcs.add(a);let s=e[3];if(o.count>=0&&s!==(o.count+1&255)){let e=t.gaps.get(a)??[0,0];e[0]++,e[1]+=s-o.count-1&255,t.gaps.set(a,e),this.#i(o)}if(o.count=s,n.fecf&&Ft(e,0,r)!==0){t.badFecf++,this.#i(o),o.orphan=!0;return}let c=e[1]&1,l=e[4]<<8|e[5],u=6;l&32768&&(u+=(e[6]&63)+1);let d=r-(c?4:0)-(n.fecf?2:0);if(u>d){t.damaged++,this.#i(o);return}if(l&16384){t.notPackets++;return}let f=l&2047;if(f===2046){t.idleFrames++;return}if(f===2047){o.open?this.#a(o,e,u,d):o.orphan||(t.partial++,o.orphan=!0);return}let p=u+f;if(p>=d){t.damaged++,this.#i(o);return}o.open?(this.#a(o,e,u,p),o.open&&this.#i(o)):f>0&&!o.orphan&&t.partial++,o.orphan=!1;let m=p;for(;m<d;){if(d-m>=6){if(!St(e,m)){t.partial++;break}let n=Et(e,m);if(m+n<=d){this.#n.push(e,m,n),m+=n;continue}}this.#o(o,e,m,d);break}}},Gt={id:`ccsds`,label:`CCSDS space telemetry`,extensions:[`.bin`,`.dat`,`.tlm`,`.raw`,`.cadu`,`.tm`],companions:[`.xml`,`.xtce`].map(e=>({ext:e,anyName:!0})),sniff:e=>Ht(e)!==null||At(e),sniffBytes:e=>Lt(e,0)>=0?3*(Mt+4)+4:e.length>=6&&St(e,0)?4*xt:0};function Kt(e,t,n){if(e.length<t+10)return!1;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint16(t,n),a=r.getUint16(t+2,n);return i>=1900&&i<=2100&&a>=1&&a<=366&&e[t+4]<=23&&e[t+5]<=59&&e[t+6]<=60}function qt(e,t=0){if(e.length<t+48)return!1;for(let n=0;n<6;n++){let r=e[t+n];if(!(r===32||r>=48&&r<=57))return!1}return!`DRQM`.includes(String.fromCharCode(e[t+6]))||!(e[t+7]===32||e[t+7]===0)?!1:Kt(e,t+20,!1)||Kt(e,t+20,!0)}var Jt=(e,t=0)=>e.length>=t+40&&e[t]===77&&e[t+1]===83&&e[t+2]===3,Yt={id:`mseed`,label:`MiniSEED`,extensions:[`.mseed`,`.miniseed`,`.ms`],sniff:e=>Jt(e)||qt(e)},Xt=`ULog5`,Zt={id:`ulog`,label:`PX4 ULog`,extensions:[`.ulg`],sniff:e=>H(e,Xt)},Qt={id:`mcap`,label:`MCAP`,extensions:[`.mcap`],sniff:e=>H(e,`‰MCAP0\r
12
+ `)},$t=[64,20,17,74,159,228,207,17,153,0,80,81,68,73,70,0],en={id:`pqdif`,label:`PQDIF (IEEE 1159.3)`,extensions:[`.pqd`],sniff:e=>e.length>=64&&$t.every((t,n)=>e[n]===t)},tn={id:`parquet`,label:`Parquet`,extensions:[`.parquet`,`.pq`],sniff:e=>e[0]===80&&e[1]===65&&e[2]===82&&e[3]===49},nn={id:`xlsx`,label:`Excel workbook`,extensions:[`.xlsx`,`.xlsm`],sniff:e=>e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4&&Ue(e).includes(`xl/`)},rn=/^(tag|tag ?name|channel|name|signal|point|item|variable)$/i,an=/^(value|val|pv|reading|measurement)$/i;function on(e){let t=t=>e.flatMap((e,n)=>e.kind===t?[n]:[]),n=t(`time`),r=t(`text`),i=t(`number`);if(n.length!==1||i.length!==1||r.length<1||r.length>2)return null;let a=t=>rn.test(e[t].name.trim()),o=r.length===2&&a(r[1])&&!a(r[0])?r[1]:r[0];return!a(o)&&!an.test(e[i[0]].name.trim())?null:{time:n[0],tag:o,value:i[0],unit:r.find(e=>e!==o)??null}}async function sn(e,t,n){let r=new Map,i=[],a=[],o=0,s=0,c=!0,l=-1/0,u=1/0,d=0,f=[];for await(let p of e.read(t.unit===null?[t.time,t.tag]:[t.time,t.tag,t.unit],n)){let e=p.columns[0],t=p.columns[1],n=p.columns[2];for(let m=0;m<p.length;m++){let p=t[m],h=e[m];if(!p||Number.isNaN(h))continue;o++,h<l&&(c=!1),h!==l&&s++,l=h,h<u&&(u=h);let g=n?.[m]??``,_=r.get(p);if(_===void 0)r.set(p,i.length),f.push(h),i.push(p),a.push(g);else{if(n&&a[_]!==g)return null;f[_]===h&&d++,f[_]=h}}}return i.length===0||i.length*2>o?null:{tags:i,units:a,rows:o,times:c?s:o,sorted:c,start:u,repeated:c?d:0}}async function*cn(e,t,n,r,i,a,o){let s=new Map;r.forEach((e,t)=>s.set(n.tags[e],t));let c=Math.max(1,Math.min(4096,Math.floor(4e6/Math.max(1,r.length)))),l=new Float64Array(r.length).fill(NaN),u=()=>r.map(()=>new Float64Array(c).fill(NaN)),d=new Float64Array(c),f=u(),p=0,m=0,h=()=>{let e=p===c,t={group:i,time:e?d:d.slice(0,p),start:m,length:p,columns:e?f:f.map(e=>e.slice(0,p))};return m+=p,p=0,d=new Float64Array(c),f=u(),t},g=(e,t,n)=>{if(l[t]===e||Number.isNaN(n))return!0;let r=e-a;return p>0&&d[p-1]===r?(f[t][p-1]=n,l[t]=e,!0):p===c?!1:(l[t]=e,d[p]=r,f[t][p++]=n,!0)},_=e.read([t.time,t.tag,t.value],o);if(n.sorted)for await(let e of _){let t=e.columns[0],n=e.columns[1],r=e.columns[2];for(let i=0;i<e.length;i++){let e=n[i]?s.get(n[i]):void 0;e!==void 0&&!Number.isNaN(t[i])&&!g(t[i],e,r[i])&&(yield h(),g(t[i],e,r[i]))}}else{let e=new Float64Array(4096),t=new Int32Array(4096),n=new Float64Array(4096),r=0;for await(let i of _){let a=i.columns[0],o=i.columns[1],c=i.columns[2];for(let l=0;l<i.length;l++){let i=o[l]?s.get(o[l]):void 0;if(!(i===void 0||Number.isNaN(a[l]))){if(r===e.length){let r=e=>{let t=new e.constructor(e.length*2);return t.set(e),t};e=r(e),t=r(t),n=r(n)}e[r]=a[l],t[r]=i,n[r++]=c[l]}}}let i=Uint32Array.from({length:r},(e,t)=>t).sort((t,n)=>e[t]-e[n]||t-n);for(let r of i)g(e[r],t[r],n[r])||(yield h(),g(e[r],t[r],n[r]))}p>0&&(yield h())}var ln=/^(t|time|timestamp|elapsed ?time|[\w ]*_time)\s*(\[[^\]]*\]|\([^)]*\))?$/i,un=/^\d{4}[-/]\d{2}[-/]\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/;function dn(e){let t=e.trim();return un.test(t)?Date.parse(t.slice(0,10).replace(/\//g,`-`)+`T`+t.slice(11))/1e3:NaN}function fn(e){let t=Math.floor(e*1e3),n=new Date(t),r=new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds());return n.getUTCFullYear()<100&&r.setFullYear(n.getUTCFullYear()),r.getTime()/1e3+(e-t/1e3)}var pn=e=>Math.round(fn(e)-e);async function mn(e,t,n){for await(let r of e.read([t],n)){let e=r.columns[0];for(let t=0;t<r.length;t++)if(!Number.isNaN(e[t]))return e[t]}return NaN}function hn(e,t){if(!e.includes(`"`))return e.split(t);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 gn(e){for(let t of[` `,`;`,`,`]){let n=hn(e[0],t).length;if(n>=3&&e.every(e=>hn(e,t).length===n))return t}return null}function _n(e,t){let n=e.trim();return n===``?NaN:Number(t?n.replace(`,`,`.`):n)}function vn(e,t,n){return e.map((e,r)=>{let i=e.trim(),a=0,o=0,s=0;for(let e of t){let t=(e[r]??``).trim();t&&(Number.isNaN(_n(t,n))?Number.isNaN(dn(t))?s++:o++:a++)}let c=o>0&&o>=a+s?`time`:a>0&&a>=s?ln.test(i)?`time`:`number`:`text`;return{name:i,unit:c===`time`&&o===0?`s`:``,kind:c,absolute:c===`time`&&o>0}})}function yn(e){let t=e.split(/\r?\n/).slice(0,-1).filter(e=>e.trim()).slice(0,50);if(t.length<3)return!1;let n=gn(t);return n?on(vn(hn(t[0],n),t.slice(1).map(e=>hn(e,n)),n===`;`))!==null:!1}var bn={id:`longtext`,label:`Delimited text, one row per sample`,extensions:[`.csv`,`.tsv`,`.txt`,`.dat`],sniff:(e,t)=>/\.(csv|tsv|txt|dat)$/i.test(t)&&!e.includes(0)&&yn(new TextDecoder().decode(e))},xn=`This file couldn't be read (it may be damaged).`,Sn=1032,Cn=e=>e*Sn+1024,wn=1<<30,Tn=128e6,En=256,Dn=64,On=1e3,kn=100,An=200,jn=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function Mn(e){let t=e.notes;for(let n of e.groups){n.name=jn(String(n.name),En);for(let e of n.channels)e.name=jn(String(e.name),En),e.unit=jn(String(e.unit??``),Dn);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>kn&&t.splice(kn,t.length-kn,`${t.length-kn} more notes.`),e.notes=t.map(e=>jn(String(e),On));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,An))n[jn(t,En)]=jn(String(r),On);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:jn(String(e.text),On)})),e}function Nn(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(xn)}function Pn(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 Fn=`kymoscope-live-key-check-v1`,In=6e5,Ln=`kymoscope-open-stream-v1`;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 Rn(e){return W(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function zn(e){return G(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(Math.ceil(e.length/4)*4,`=`))}function Bn(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}function Vn(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),W(e)}async function Hn(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:In,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Un(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:In,hash:`SHA-256`},n,256);return W(new Uint8Array(r))}var Wn=null,Gn=0;function Kn(){(!Wn||Gn>4294967295)&&(Wn=globalThis.crypto.getRandomValues(new Uint8Array(8)),Gn=0);let e=new Uint8Array(12);return e.set(Wn),new DataView(e.buffer).setUint32(8,Gn++),e}async function qn(e,t){let n=Kn(),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 Jn(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 Yn(e,t,n,r){let i=await U().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function Xn(e,t){return JSON.parse(new TextDecoder().decode(await Jn(e,t)))}async function Zn(e){return qn(e,Fn)}async function Qn(e,t){try{return await Xn(e,t)===Fn}catch{return!1}}async function $n(e){let t=await U().digest(`SHA-256`,new TextEncoder().encode(e));return Bn(new Uint8Array(t))}function er(){let e=e=>{let t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),Rn(t)},t=`kymoscope_${e(24)}.${e(32)}`;return{token:t,prefix:t.slice(0,12)}}var tr=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/;function nr(e){let t=tr.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}var rr=new TextEncoder().encode(`kymoscope-device-wrap-v1`);async function ir(){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 ar(e,t){let n=new Uint8Array(e.length+rr.length);return n.set(e),n.set(rr,e.length),U().importKey(`raw`,await U().digest(`SHA-256`,n),`AES-GCM`,!1,t)}async function or(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 ar(i,[`decrypt`]),G(t.ct)))}function sr(e,t,n){return cr(e,t,n)}async function cr(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??Kn(),l=new Uint8Array(await U().encrypt({name:`AES-GCM`,iv:c,additionalData:new TextEncoder().encode(n)},await ar(s,[`encrypt`]),t));return{epk:W(new Uint8Array(await U().exportKey(`raw`,o.publicKey))),iv:W(c),ct:W(l)}}async function lr(e,t,n,r){return hr(await or(e,t,`${n}|${r}`))}var ur=new TextEncoder().encode(`kymoscope-sender-bind-v1`),dr=(e,t,n)=>`project:${e}:${t}|${n}`,fr=(e,t,n)=>`live_stream:${e}|${t}:${n}`,pr=(e,t,n)=>`bind:${e}|${t}:${n}`;function mr(){return globalThis.crypto.getRandomValues(new Uint8Array(32))}function hr(e){return U().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function gr(e,t,n){return _r(e,t,n)}async function _r(e,t,n,r){let i=r??Kn(),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 vr(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 yr(e){let t=new TextEncoder().encode(e),n=new Uint8Array(t.length+ur.length);return n.set(t),n.set(ur,t.length),new Uint8Array(await U().digest(`SHA-256`,n))}async function br(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 xr(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 Sr(e){let t=Bn(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 Cr=`kymoscope-workbook-export-v2`,wr=(e,t)=>`workbook:${e}:${t}`,Tr=(e,t,n)=>`workbook:${e}|${t}:${n}`,Er=(e,t)=>`project_config:${e}|${e}:${t}`,Dr=(e,t,n)=>`alert_rule:${e}:${t}|${n}`,Or=(e,t,n)=>`alert_event:${e}:${t}|${n}`,kr=(e,t)=>`kymoscope-recovery-key-v1|${e}|${t}`,Ar=(e,t,n)=>`recovery:${e}|${t}:${n}`;function jr(e,t,n){return Mr(e,t,n)}async function Mr(e,t,n,r){let i=r??Kn(),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 Nr(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 Pr(e,t,n){return Fr(e,t,n)}async function Fr(e,t,n,r,i){let a=W(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await Mr(await Hn(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:In,salt:a},...o}}async function Ir(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==In||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return Nr(await Hn(e,r.salt),t,n)}var Lr=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`;function Rr(e){let t=0,n=0,r=``;for(let i of e)for(n=(n<<8|i)&1048575,t+=8;t>=5;)r+=Lr[n>>>t-5&31],t-=5;return t>0&&(r+=Lr[n<<5-t&31]),r.match(/.{1,4}/g).join(`-`)}function zr(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|Lr.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 Br(){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:zn(t.d),publicKey:W(n)}}function Vr(e,t){let n=G(t);return U().importKey(`jwk`,{kty:`EC`,crv:`P-256`,ext:!1,x:Rn(n.subarray(1,33)),y:Rn(n.subarray(33,65)),d:Rn(e)},{name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`])}new TextEncoder;var Hr=4096;function Ur(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>=Hr&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var Wr=new TextDecoder,Gr=200;function Kr(e,t,n){let r=e.subarray(t,t+n);return Wr.decode(r)}function qr(e,t,n){return n>Gr?Kr(e,t,n):Ur(e,t,n)}var Jr=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 Yr(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function Xr(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function Zr(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var Qr=4294967295,$r=17179869183;function ei({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=$r)if(t===0&&e<=Qr){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),Yr(r,4,e),n}}function ti(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 ni(e){return e instanceof Date?ei(ti(e)):null}function ri(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:Xr(t,4),nsec:t.getUint32(0)};default:throw new K(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function ii(e){let t=ri(e);return new Date(t.sec*1e3+t.nsec/1e6)}var ai={type:-1,encode:ni,decode:ii},oi=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(ai)}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 Jr(-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 Jr(n,i)}}return e instanceof Jr?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new Jr(t,e)}};function si(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function ci(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):si(e)?new Uint8Array(e):Uint8Array.from(e)}function li(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var ui=16,di=16,fi=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=ui,t=di){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=Ur(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}},pi=`array`,mi=`map_key`,hi=`map_value`,gi=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)},_i=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=pi,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=mi,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===pi){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===mi||e.type===hi){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}},vi=-1,yi=new DataView(new ArrayBuffer(0)),bi=new Uint8Array(yi.buffer);try{yi.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 xi=RangeError(`Insufficient data`),Si=new fi,Ci=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=yi;bytes=bi;headByte=vi;stack=new _i;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??oi.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?Si:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??gi}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=vi,this.stack.reset()}setBuffer(e){let t=ci(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===vi&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=ci(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 ${li(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: ${li(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===pi)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===mi){if(t===`__proto__`)throw new K(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=hi;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=mi;continue DECODE}}return t}}readHeadByte(){return this.headByte===vi&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=vi}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: ${li(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 xi;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):qr(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===mi:!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 xi;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=Zr(this.view,this.pos);return this.pos+=8,e}readI64(){let e=Xr(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 wi(e,t){return new Ci(t).decode(e)}var Ti=6,Ei=8,Di=12,Oi=16;function ki(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+Di+Oi?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+Di),ciphertext:t.subarray(n+Di),aad:t.subarray(0,n)}}async function Ai(e,t){let n=ki(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await Yn(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}function ji(e,t,n,r){return Mi(e,t,n,r)}async function Mi(e,t,n,r,i){let a=r===void 0?new Uint8Array([t]):new Uint8Array([t|128,r&255]),o=i??Kn(),s=new Uint8Array(await globalThis.crypto.subtle.encrypt({name:`AES-GCM`,iv:o,additionalData:a},e,n)),c=new Uint8Array(a.length+Di+s.length);return c.set(a),c.set(o,a.length),c.set(s,a.length+Di),c.buffer}var Ni=1,Pi=e=>e+7&-8;function Fi(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)!==Ni)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=Pi(s),s+Pi(i*8)+o.reduce((e,t)=>e+Pi(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=Pi(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+=Pi(i*t.size);return{t:l,columns:u,units:d}}var Ii=2,Li=1,Ri=1,zi=2,Bi=3,Vi=2,Hi=1,Ui=2,Wi=1e5,Gi=513,Ki=20,qi=64*1024*1024,q=(e,t)=>RangeError(`${e}: ${t}`);function Ji(e,t){let n=new TextDecoder(`utf-8`,{fatal:!0}),r=[],i=0;try{for(let a=0;a<t;a++){if(i+3>e.byteLength)throw q(`block schema`,`short channel table`);let t=e[i],a=e[i+1],o=e[i+2];if(i+=3,t!==4&&t!==8)throw q(`block schema`,`value size ${t}`);if(i+a+o>e.byteLength)throw q(`block schema`,`short channel table`);r.push({name:n.decode(e.subarray(i,i+a)),unit:n.decode(e.subarray(i+a,i+a+o)),size:t}),i+=a+o}}catch(e){throw e instanceof RangeError?e:q(`block schema`,`invalid text`)}return r}async function Yi(e){if(e.byteLength<8)throw q(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint8(0);if(n===Bi){if(e.byteLength<12)throw q(`block schema`,`short`);let n=t.getUint32(4,!0);if(n>Wi)throw q(`block schema`,`too many channels`);let r=t.getUint8(1)&Ri?await $i(e.subarray(12),n*Gi,!1):e.subarray(12);return{id:t.getUint32(8,!0),channels:Ji(r,n)}}if(n!==Ii)throw q(`block schema`,`version ${n}`);return{id:t.getUint32(4,!0),channels:Ji(e.subarray(8),t.getUint16(2,!0))}}function Xi(e,t,n){let r=n.get(t.getUint32(4,!0));if(!r)return null;let i=t.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 n=t.getFloat64(12+8*e,!0),o=t.getFloat64(12+8*(i+e),!0);Number.isFinite(n)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t:n,v:o})}return a}async function Zi(e,t){if(e.byteLength<12)throw q(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint8(0);if(r===Li)return Xi(e,n,t);if(r!==Vi)throw q(`last values`,`version ${r}`);if(e.byteLength<20)throw q(`last values`,`short`);let i=n.getUint8(1),a=t.get(n.getUint32(4,!0));if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=a.channels.length,l=(i&Ui)!==0;if(o>c||l&&o!==c)throw q(`last values`,`entry count differs from its schema`);let u=(l?0:4*o)+4*o,d=i&Ri?await $i(e.subarray(20),u+8*o,!1):e.subarray(20);if(d.byteLength<u)throw q(`last values`,`short`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=[];for(let e=0;e<o;e++){let t=l?e:f.getUint32(4*e,!0);if(t>=c)throw q(`last values`,`channel outside its schema`);p.push(t)}let m=l?0:4*o,h=p.filter(e=>a.channels[e].size===4),g=p.filter(e=>a.channels[e].size===8);if(d.byteLength!==u+4*h.length+8*g.length)throw q(`last values`,`body size mismatch`);let _=Qi(d,u,h.length,4),v=Qi(d,u+4*h.length,g.length,8),y=new Map;h.forEach((e,t)=>y.set(e,_[t])),g.forEach((e,t)=>y.set(e,v[t]));let b=[];return p.forEach((e,t)=>{let n=s-f.getUint32(m+4*t,!0)/1e3,r=y.get(e);Number.isFinite(n)&&Number.isFinite(r)&&b.push({name:a.channels[e].name,unit:a.channels[e].unit,t:n,v:r})}),b}function Qi(e,t,n,r){let i=new Uint8Array(n*r);for(let a=0;a<r;a++)for(let o=0;o<n;o++)i[o*r+a]=e[t+a*n+o];return r===4?new Float32Array(i.buffer):new Float64Array(i.buffer)}async function $i(e,t,n=!0){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),i=new Uint8Array(Math.min(t,e.byteLength*4+1024)),a=0;try{for(;;){let{done:e,value:n}=await r.read();if(e)break;if(a+n.length>t)throw q(`block`,`body larger than its header says`);if(a+n.length>i.length){let e=new Uint8Array(Math.min(t,Math.max(2*i.length,a+n.length)));e.set(i.subarray(0,a)),i=e}i.set(n,a),a+=n.length}}catch(e){throw await r.cancel().catch(()=>{}),e instanceof RangeError?e:q(`block`,`body is not valid deflate`)}if(n&&a!==t)throw q(`block`,`body size mismatch`);return i.length===a?i:i.subarray(0,a)}async function ea(e,t){if(e.byteLength<Ki)throw q(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Ii)throw q(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=n.getUint32(8,!0),s=t.get(o);if(!s)return null;if(s.channels.length!==i)throw q(`block`,`channel count differs from its schema`);let c=n.getFloat64(12,!0),l=Math.max(0,a-1),u=4*l+s.channels.reduce((e,t)=>e+t.size*a,0);if(u>qi)throw q(`block`,`too large`);let d;if(r&Ri)d=await $i(e.subarray(Ki),u);else if(d=e.subarray(Ki),d.byteLength<u)throw q(`block`,`body size mismatch`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=new Float64Array(a),m=0;a&&(p[0]=c);for(let e=1;e<a;e++)m+=f.getInt32(4*(e-1),!0),p[e]=c+m/1e6;let h=4*l,g={},_={};for(let e of s.channels)g[e.name]=Qi(d,h,a,e.size),e.unit&&(_[e.name]=e.unit),h+=a*e.size;return{block:{t:p,columns:g,units:_},historical:(r&zi)!==0,schemaId:o}}async function ta(e,t){if(e.byteLength<Ki)throw q(`sparse`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Hi)throw q(`sparse`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint32(4,!0),a=t.get(i);if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=4*o+4*Math.max(0,o-1);if(c+8*o>qi)throw q(`sparse`,`too large`);let l=r&Ri?await $i(e.subarray(Ki),c+8*o,!1):e.subarray(Ki);if(l.byteLength<c)throw q(`sparse`,`body size mismatch`);let u=new Uint32Array(o);for(let e=0;e<o;e++)u[e]=(l[e]|l[o+e]<<8|l[2*o+e]<<16|l[3*o+e]<<24)>>>0;let d=a.channels.length,f=0;for(let e=0;e<o;e++){if(u[e]>=d)throw q(`sparse`,`event outside its schema`);a.channels[u[e]].size===4&&f++}if(l.byteLength!==c+4*f+8*(o-f))throw q(`sparse`,`body size mismatch`);let p=new DataView(l.buffer,l.byteOffset,l.byteLength),m=new Float64Array(o),h=0;o&&(m[0]=s);for(let e=1;e<o;e++)h+=p.getInt32(4*o+4*(e-1),!0),m[e]=s+h/1e6;let g=Qi(l,c,f,4),_=Qi(l,c+4*f,o-f,8),v=new Float64Array(o);for(let e=0,t=0,n=0;e<o;e++)v[e]=a.channels[u[e]].size===4?g[t++]:_[n++];return{schemaId:i,index:u,t:m,v,historical:(r&zi)!==0}}var na=16,ra=class{t=new Float64Array(16);v=new Float64Array(16);start=0;end=0;get count(){return this.end-this.start}add(e,t){if(this.end===this.t.length){let e=this.count,t=e*2>this.t.length?this.t.length*2:this.t.length,n=new Float64Array(t),r=new Float64Array(t);n.set(this.t.subarray(this.start,this.end)),r.set(this.v.subarray(this.start,this.end)),this.t=n,this.v=r,this.start=0,this.end=e}this.t[this.end]=e,this.v[this.end++]=t}},ia=class{channels=new Map;events_=0;maxBytes;constructor(e){this.maxBytes=e}get bytes(){return this.events_*na}add(e,t,n){let r=this.channels.get(e);r||this.channels.set(e,r=new ra),r.add(t,n),this.events_++,this.bytes>this.maxBytes&&this.evict()}events(e){let t=this.channels.get(e);return t?{t:t.t.subarray(t.start,t.end),v:t.v.subarray(t.start,t.end)}:{t:new Float64Array,v:new Float64Array}}evict(){let e=this.maxBytes*.9/na;for(;this.events_>e;){let t=[...this.channels.values()].filter(e=>e.count>0).sort((e,t)=>t.count-e.count);if(!t.length)return;let n=t[0].count;for(let r of t){if(this.events_<=e||r.count*2<n)break;let t=Math.max(1,r.count>>1);r.start+=t,this.events_-=t}}}},aa=1e3,oa=4,sa=4096,ca=class{buffer;store;schemas=new Map;known=new Map;active=new Set;constructor(e,t){this.buffer=e,this.store=new ia(t)}schema(e,t,n){this.schemas.delete(e),this.schemas.set(e,t),this.schemas.size>oa&&this.schemas.delete(this.schemas.keys().next().value),t.forEach((e,t)=>{this.known.has(e)||this.known.set(e,{unit:n[t]??``,t:NaN,v:NaN}),this.buffer.list(e,n[t]??``)})}last(e){for(let t of e)this.note(t.name,t.unit,t.t,t.v)}push(e,t,n,r){let i=this.schemas.get(e);return i?this.events(n.length,e=>i[t[e]],n,r):null}pushNamed(e,t,n){return this.events(e.length,e=>this.known.has(t[e])?t[e]:void 0,e,n)}events(e,t,n,r){let i=[];for(let a=0;a<e;a++){let e=t(a);e!==void 0&&(this.store.add(e,n[a],r[a]),this.note(e,this.known.get(e)?.unit??``,n[a],r[a]),this.active.has(e)&&i.push(a))}if(!i.length)return null;i.sort((e,t)=>n[e]-n[t]);let a=la(i.map(e=>n[e]),i.map(e=>t(e)),i.map(e=>r[e]));return this.buffer.pushColumns(a),a}activate(e){let t=!1;for(let n of e){if(this.active.size>=1e3)break;this.known.has(n)&&!this.active.has(n)&&(this.active.add(n),t=!0)}return t}replay(){let e=this.buffer;e.clear();for(let[t,n]of this.known)e.list(t,n.unit,n.t,n.v);let t=[...this.active],n=t.map(e=>this.store.events(e)),r=n.map(e=>e.t.length-1),i=new ua(e=>-n[e].t[r[e]]);n.forEach((e,t)=>{e.t.length&&i.push(t)});let a=0,o=NaN;for(;i.size;){let t=i.top,s=n[t].t[r[t]];if(s!==o){if(a===e.maxSamples)break;a++,o=s}i.pop(),--r[t]>=0&&i.push(t)}let s=new ua(e=>n[e].t[r[e]]);n.forEach((e,t)=>{++r[t]<e.t.length&&s.push(t)});let c=new Float64Array(sa),l={},u=-1,d=()=>{if(u<0)return;let t=u+1;e.pushColumns({t:c.subarray(0,t),columns:Object.fromEntries(Object.entries(l).map(([e,n])=>[e,n.subarray(0,t)]))}),c=new Float64Array(sa),l={},u=-1};for(;s.size;){let e=s.top,i=n[e].t[r[e]];(u<0||i!==c[u])&&(u+1===sa&&d(),c[++u]=i),(l[t[e]]??=new Float64Array(sa).fill(NaN))[u]=n[e].v[r[e]],s.pop(),++r[e]<n[e].t.length&&s.push(e)}d()}note(e,t,n,r){if(!Number.isFinite(n)||!Number.isFinite(r))return;let i=this.known.get(e);i?n<i.t||(i.t=n,i.v=r):this.known.set(e,{unit:t,t:n,v:r}),this.buffer.list(e,t,n,r)}};function la(e,t,n){let r=[];for(let t=0;t<e.length;t++)(t===0||e[t]!==e[t-1])&&r.push(e[t]);let i={},a=-1;for(let o=0;o<e.length;o++){(o===0||e[o]!==e[o-1])&&a++;let s=i[t[o]]??(i[t[o]]=new Float64Array(r.length).fill(NaN));s[a]=n[o]}return{t:Float64Array.from(r),columns:i}}var ua=class{h=[];key;constructor(e){this.key=e}get size(){return this.h.length}get top(){return this.h[0]}push(e){let t=this.h,n=this.key(e),r=t.push(e)-1;for(;r>0;){let e=r-1>>1;if(this.key(t[e])<=n)break;t[r]=t[e],r=e}t[r]=e}pop(){let e=this.h,t=e.pop();if(!e.length)return;let n=this.key(t),r=e.length,i=0;for(;;){let t=2*i+1;if(t>=r||(t+1<r&&this.key(e[t+1])<this.key(e[t])&&t++,this.key(e[t])>=n))break;e[i]=e[t],i=t}e[i]=t}},da=0,fa=1,pa=70,ma=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),ha=e=>Uint8Array.from(e.match(/../g)??[],e=>parseInt(e,16)),ga=e=>{let t=ha(e.replace(/-/g,``));if(t.length!==16)throw Error(`bad_stream_id`);return t},_a=e=>{let t=ma(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function va(e){let t=new Uint8Array(pa),n=new DataView(t.buffer);return t[0]=1,t.set(ga(e.streamId),1),t.set(ha(e.run),17),t[25]=e.lane,n.setBigUint64(26,e.seq,!0),n.setUint32(34,e.count,!0),t.set(e.hash,38),t}function ya(e){if(e.length!==pa||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:_a(e.subarray(1,17)),run:ma(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}var ba=()=>globalThis.crypto.subtle,xa=e=>ba().digest(`SHA-256`,e);async function Sa(e){let t=await Promise.all(e),n=new Uint8Array(t.length*32);return t.forEach((e,t)=>n.set(new Uint8Array(e),t*32)),new Uint8Array(await xa(n))}var Ca=()=>ma(globalThis.crypto.getRandomValues(new Uint8Array(8))),wa=class{digests=[];seq=0n;streamId;run;lane;constructor(e,t,n){this.streamId=e,this.run=t,this.lane=n}add(e){this.digests.push(xa(e))}async checkpoint(){let e=this.digests;return this.digests=[],this.seq+=1n,va({streamId:this.streamId,run:this.run,lane:this.lane,seq:this.seq,count:e.length,hash:await Sa(e)})}};function Ta(e,t,n=()=>Date.now()){let r={verified:0,broken:0},i=null,a=0n,o=null,s=0,c=0,l=0,u=Promise.resolve(),d=e=>{e?r.verified++:(r.broken++,r.lastBrokenAt=n()),t({...r})};return{integrity:r,reset(){i=null,o=null,c=s,l++},arrive(t,n,r){if(n!==8){o&&(o.push(xa(t)),s++);return}let f=s;o||(o=[],c=s);let p=l;u=u.then(async()=>{let t=await r.catch(()=>null);if(p!==l)return;let n=t?ya(t.plaintext):null;if(!n||n.lane!==0||n.streamId!==e.toLowerCase()){i!==null&&d(!1);return}let s=f-c;if(i===null||n.run!==i){i=n.run,a=n.seq,o=o.slice(Math.max(0,s)),c=Math.max(c,f);return}let u=n.seq===a+1n&&n.count<=s&&Ea(await Sa(o.slice(0,n.count)),n.hash);if(p!==l)return;a=n.seq;let m=u?n.count:s;o=o.slice(m),c+=m,d(u)})}}}var Ea=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),J=Uint8Array,Y=Uint16Array,Da=Int32Array,Oa=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]),ka=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]),Aa=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ja=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 Da(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}},Ma=ja(Oa,2),Na=Ma.b,Pa=Ma.r;Na[28]=258,Pa[258]=28;for(var Fa=ja(ka,0),Ia=Fa.b,La=Fa.r,Ra=new Y(32768),X=0;X<32768;++X){var za=(X&43690)>>1|(X&21845)<<1;za=(za&52428)>>2|(za&13107)<<2,za=(za&61680)>>4|(za&3855)<<4,Ra[X]=((za&65280)>>8|(za&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[Ra[d]>>c]=l}else for(s=new Y(r),i=0;i<r;++i)e[i]&&(s[i]=Ra[o[e[i]-1]++]>>15-e[i]);return s}),Ba=new J(288),X=0;X<144;++X)Ba[X]=8;for(var X=144;X<256;++X)Ba[X]=9;for(var X=256;X<280;++X)Ba[X]=7;for(var X=280;X<288;++X)Ba[X]=8;for(var Va=new J(32),X=0;X<32;++X)Va[X]=5;var Ha=Z(Ba,9,0),Ua=Z(Ba,9,1),Wa=Z(Va,5,0),Ga=Z(Va,5,1),Ka=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},qa=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ja=function(e){return(e+7)/8|0},Ya=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))},Xa=[`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||Xa[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,$),!n)throw r;return r},Za=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=Ja(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=Ua,m=Ga,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[Aa[D]]=Q(e,d+D*3,7);d+=C*3;for(var O=Ka(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=Ka(P),g=Ka(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[qa(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=Oa[D];R=Q(e,d,(1<<z)-1)+Na[D],d+=z}var ne=m[qa(e,d)&I],re=ne>>4;ne||$(3),d+=ne&15;var F=Ia[re];if(re>3){var z=ka[re];F+=qa(e,d)&(1<<z)-1,d+=z}if(d>_){c&&$(0);break}s&&l(f+131072);var ie=f+R;if(f<F){var ae=a-F,oe=Math.min(F,ie);for(ae+f<0&&$(3);f<oe;++f)n[f]=r[ae+f]}for(;f<ie;++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?Ya(n,0,f):n.subarray(0,f)},Qa=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},$a=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},eo=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:so,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=to(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}},to=function(e,t,n){return e.s==-1?Math.max(to(e.l,t,n+1),to(e.r,t,n+1)):t[e.s]=n},no=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}},ro=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},io=function(e,t,n){var r=n.length,i=Ja(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},ao=function(e,t,n,r,i,a,o,s,c,l,u){Qa(t,u++,n),++i[256];for(var d=eo(i,15),f=d.t,p=d.l,m=eo(a,15),h=m.t,g=m.l,_=no(f),v=_.c,y=_.n,b=no(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=eo(C,7),E=T.t,D=T.l,O=19;O>4&&!E[Aa[O-1]];--O);var k=l+5<<3,A=ro(i,Ba)+ro(a,Va)+o,j=ro(i,f)+ro(a,h)+o+14+3*O+ro(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&k<=A&&k<=j)return io(t,u,e.subarray(c,c+l));var M,N,P,F;if(Qa(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);Qa(t,u,y-257),Qa(t,u+5,S-1),Qa(t,u+10,O-4),u+=14;for(var w=0;w<O;++w)Qa(t,u+3*w,E[Aa[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;Qa(t,u,ee[R]),u+=E[R],R>15&&(Qa(t,u,L[w]>>5&127),u+=L[w]>>12)}}else M=Ha,N=Ba,P=Wa,F=Va;for(var w=0;w<s;++w){var z=r[w];if(z>255){var R=z>>18&31;$a(t,u,M[R+257]),u+=N[R+257],R>7&&(Qa(t,u,z>>23&31),u+=Oa[R]);var ne=z&31;$a(t,u,P[ne]),u+=F[ne],ne>3&&($a(t,u,z>>5&8191),u+=ka[ne])}else $a(t,u,M[z]),u+=N[z]}return $a(t,u,M[256]),u+N[256]},oo=new Da([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),so=new J(0),co=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=oo[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 Da(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=ao(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 ne=Math.min(I,z-2),re=0,N=0;N<ne;++N){var ie=T-I+N&32767,ae=ie-h[ie]&32767;ae>re&&(re=ae,j=ie)}}}A=j,j=h[A],I+=A-j&32767}if(F){b[E++]=268435456|Pa[P]<<18|La[F];var oe=Pa[P]&31,se=La[F]&31;w+=Oa[oe]+ka[se],++x[257+oe],++S[se],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=ao(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 ce=T+65535;ce>=o&&(c[u/8|0]=l,ce=o),u=io(c,u+1,e.subarray(T,ce))}a.i=o}return Ya(s,0,r+Ja(u)+i)},lo=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}}},uo=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 co(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)},fo=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},po=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=lo();i.p(t.dictionary),fo(e,2,i.d())}},mo=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},ho=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=Za(this.p,this.s,this.o);this.ondata(Ya(n,t,this.s.b),this.d),this.o=Ya(n,this.s.b-32768),this.s.b=this.o.length,this.p=Ya(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 go(e,t){t||={};var n=lo();n.p(e);var r=uo(e,t,t.dictionary?6:2,4);return po(r,t),fo(r,r.length-4,n.d()),r}var _o=function(){function e(e,t){ho.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(ho.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(mo(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&$(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),ho.prototype.c.call(this,t)},e}();function vo(e,t){return Za(e.subarray(mo(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var yo=typeof TextDecoder<`u`&&new TextDecoder;try{yo.decode(so,{stream:!0})}catch{}var bo=56,xo=[75,82,67,49];function So(e){let t=e.replace(/-/g,``);if(!/^[0-9a-f]{32}$/i.test(t))throw RangeError(`recording id must be a uuid`);return Uint8Array.from({length:16},(e,n)=>parseInt(t.slice(2*n,2*n+2),16))}function Co(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 wo(e,t,n){let r=56+n.reduce((e,t)=>e+12+t.bytes.length,0),i=new Uint8Array(r),a=new DataView(i.buffer);i.set(xo,0),a.setUint16(4,1,!0),a.setUint16(6,56,!0),i.set(So(e),8),a.setUint32(24,t,!0),a.setUint32(28,n.length,!0),a.setUint32(32,r,!0),a.setFloat64(40,n[0]?.at??0,!0),a.setFloat64(48,n.at(-1)?.at??0,!0);let o=56;for(let e of n)a.setFloat64(o,e.at,!0),a.setUint32(o+8,e.bytes.length,!0),i.set(e.bytes,o+12),o+=12+e.bytes.length;return i}function To(e){if(e.length<56||xo.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:Co(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 Eo(e){let t=To(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 Do=e=>crypto.subtle.digest(`SHA-256`,e),Oo=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),ko=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16));async function Ao(e,t,n,r){let i=t[t.length-1];if(!i||(i.bytes[0]&127)!=8)return`unchecked`;let a=await n(i.bytes).catch(()=>null),o=a?ya(a.plaintext):null,s=Oo(await Do(ko(e.recordingId))).slice(0,16);return o&&o.lane===1&&o.run===s&&o.seq===BigInt(e.seq)&&e.seq===r&&o.count===t.length-1&&Oo((await Sa(t.slice(0,-1).map(e=>Do(e.bytes)))).buffer)===Oo(o.hash.buffer)?`verified`:`broken`}function jo(e){let t=[...e],n=new Set(t.filter(e=>e.check!==`unchecked`).map(e=>e.rid)),r={verified:0,broken:0,unchecked:0};for(let e of t)e.check===`unchecked`&&n.has(e.rid)?r.broken++:r[e.check]++;return r}var Mo=(e,t,n)=>`recording_key:${e}|${t}:${n}`,No=(e,t,n)=>n===e.stream_epoch?fr(e.stream_id,t,n):Mo(e.id,t,n),Po=12,Fo=16;function Io(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+Po+Fo)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>(e.keyId===i||e.keyId===null)&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await Yn(e,n.subarray(r,r+Po),n.subarray(r+Po),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}var Lo=8192;async function*Ro(e){let t=0;for(;t+56<=e.size;){let n=To(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function zo(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}var Bo=4096;function Vo(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}var Ho=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Uo=class{known=new Map;real=new Set;pending=new Set;held=new Set;note(e){for(let t of e){let e=this.known.get(t.name);(!e||t.t>=e.t)&&this.known.set(t.name,{t:t.t,v:t.v,unit:t.unit}),!this.real.has(t.name)&&!this.held.has(t.name)&&this.pending.add(t.name)}}sampled(e){if(this.pending.size+this.held.size===0)return;let t=e=>{(this.pending.delete(e)||this.held.delete(e))&&this.real.add(e)};for(let[n,r]of Object.entries(e.columns))if(!(!this.pending.has(n)&&!this.held.has(n))){for(let e=0;e<r.length;e++)if(Number.isFinite(r[e])){t(n);break}}if(e.events&&e.schema){let{index:n,v:r}=e.events;for(let i=0;i<r.length;i++)Number.isFinite(r[i])&&t(e.schema.channels[n[i]].name)}}start(e){if(this.pending.size===0||e.t.length===0)return e;let t={...e.columns},n={...e.units};for(let e of this.pending){let r=this.known.get(e);t[e]=Float64Array.of(r.v),r.unit&&!n[e]&&(n[e]=r.unit),this.held.add(e)}let r=[...this.pending];return this.pending.clear(),{...e,columns:t,units:n,more:r}}end(e,t){if(e===null||this.held.size===0)return null;let n={},r={};for(let e of this.held){let t=this.known.get(e);n[e]=Float64Array.of(t.v),t.unit&&(r[e]=t.unit)}return{at:t,t:[e],columns:n,units:r}}};async function*Wo(e,t,n,r,i=!1){let a=Io(e.keys??[]),o=new Map,s=new Map,c=r?null:new Uo,l=null,u=0,d=e=>c?(c.sampled(e),e.t.length&&(l=+e.t[e.t.length-1],u=e.at),c.start(e)):e,f={results:[]};for await(let e of Ro(t)){let{header:t,messages:l}=Eo(e);if(n.t0??=t.t0,i){let e=t.recordingId;f.results.push({rid:e,check:await Ao(t,l,a,f.rid===e?(f.seq??-1)+1:0)}),f.rid=e,f.seq=t.seq,n.chain=jo(f.results)}for(let e of l){let t=Vo(e.bytes),i=s.get(t);if(i&&Ho(i,e.bytes))continue;s.set(t,e.bytes),s.size>Bo&&s.delete(s.keys().next().value);let l=await a(e.bytes);if(!l){n.lost++;continue}try{if(l.kind===5){let e=await Yi(l.plaintext);o.set(e.id,e);continue}if(l.kind===4||l.kind===9){let t;if(l.kind===4){let r=await ea(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.block.t,columns:r.block.columns,units:r.block.units??{},historical:r.historical,schema:o.get(r.schemaId)}}else{let r=await ta(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.t,columns:{},units:{},historical:r.historical,events:{index:r.index,v:r.v},schema:o.get(r.schemaId)}}t.historical&&c?.sampled(t),(r===void 0||r===!!t.historical)&&(yield t.historical?t:d(t));continue}if(r)continue;if(l.kind===7){let e=await Zi(l.plaintext,o);e&&c?.note(e)}else if(l.kind===3){let t=Fi(l.plaintext);yield d({at:e.at,t:t.t,columns:t.columns,units:t.units??{}})}else if(l.kind===2){let t=wi(l.plaintext);yield d({at:e.at,...zo(Array.isArray(t?.frames)?t.frames:[])})}}catch{n.lost++}}}let p=c?.end(l,u);p&&(yield p)}function Go(e,t,n){let r=e===null?t:t===null?e:Math.min(e,t);return r===null?{}:r>1e9?{wallOrigin:String(r),wallQuality:`exact`}:Number.isFinite(n)?{wallOrigin:String(r+n),wallQuality:`approx`}:{}}var Ko={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[Ae],r=new Map([[Ae,`s`]]),i={lost:0,t0:null},a=0,o=!1,s=null,c=null,l=0,u=-1/0,d=0,f=1/0,p=(e,t=``)=>{e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&t&&r.set(e,t):(n.push(e),r.set(e,t)))},m=new Set;for await(let n of Wo(e,t,i,void 0,!0)){a+=n.t.length,n.historical&&(o=!0);let e=n.t.length;if(e&&n.historical?c??=+n.t[0]:e&&(s??=+n.t[0],+n.t[0]+l<u&&(l=u+Math.max(0,(n.at-d)/1e3)-+n.t[0]),d=n.at,u=+n.t[e-1]+l,f=Math.min(f,n.at/1e3-u)),n.schema){if(!m.has(n.schema.id)){m.add(n.schema.id);for(let e of n.schema.channels)p(e.name,e.unit)}for(let e of n.more??[])p(e,n.units[e])}else for(let e of Object.keys(n.columns))p(e,n.units[e])}let h=n.map(e=>({name:e,unit:r.get(e)??``})),g=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[],_=i.chain?.broken??0,v=n.length-1,y=v>1e3?[{group:0,channels:n.slice(0,aa+1).map((e,t)=>t)}]:void 0;return y&&g.push(`This recording has ${v.toLocaleString(`en-US`)} channels; the first ${aa.toLocaleString(`en-US`)} are loaded.`),_&&g.push(`Some of this recording was missing, out of order or changed where it is stored (${_} of ${_+(i.chain?.verified??0)} checked ${_+(i.chain?.verified??0)===1?`chunk`:`chunks`}).`),{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:h,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{...Go(s,c,f),...i.chain&&(i.chain.verified||i.chain.broken)?{chainVerified:String(i.chain.verified),chainBroken:String(i.chain.broken),chainUnchecked:String(i.chain.unchecked)}:{}},events:[],notes:g,defaultSelection:y,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(Ae),o=()=>r.map(()=>new Float64Array(Lo).fill(NaN)),s=new Float64Array(Lo),c=o(),l=0,u=0,d=0,f=null,p=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(Lo),c=o(),e},m=new WeakMap,h=e=>{let t=m.get(e);return t||m.set(e,t=Int32Array.from(e.channels,e=>e.name===`ElapsedTime`?-2:i.get(e.name)??-1)),t};function*g(e,t,n,r){let o=Object.entries(e.columns).flatMap(([e,t])=>{let n=e===`ElapsedTime`?void 0:i.get(e);return n===void 0?[]:[[n,+t[0]]]});for(let i=0;i<e.t.length;i++){let u=r[t[i]];if(u===-1&&!(i===0&&o.length))continue;let m=+e.t[i];if(s[l]=m+d-f,a!==void 0&&(c[a][l]=m),u>=0&&(c[u][l]=n[i]),i===0)for(let[e,t]of o)c[e][l]=t;++l===Lo&&(yield p())}}function*_(e){let t=e.t.length;if(t&&(f??=+e.t[0]+d),e.events&&e.schema)return yield*g(e,e.events.index,e.events.v,h(e.schema));for(let n=0;n<t;){let r=Math.min(t-n,Lo-l);for(let t=0;t<r;t++)s[l+t]=+e.t[n+t]+d-f;if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===Lo&&(yield p())}}for await(let t of qo(e.files,e.io,n,e.signal))d=t.shift,yield*_(t.b);l>0&&(yield p())}};async function*qo(e,t,n,r){let i=0,a=-1/0,o=0,s=n?Wo(e,t,{lost:0,t0:null},!0):null,c=async()=>{for(let e=await s?.next();e&&!e.done;e=await s.next())if(e.value.t.length)return e.value;return null},l=await c();for await(let s of Wo(e,t,{lost:0,t0:null},n?!1:void 0)){if(r?.aborted)return;let e=s.t.length;if(e!==0){for(+s.t[0]+i<a&&(i=a+Math.max(0,(s.at-o)/1e3)-+s.t[0]),o=s.at;l&&+l.t[0]<+s.t[0];l=await c())yield{b:l,shift:i};yield{b:s,shift:i},a=+s.t[e-1]+i}}for(;l&&!r?.aborted;l=await c())yield{b:l,shift:i}}async function*Jo(e,t,n,r){let{names:i,backlog:a=!1}=n.state,o=new Map(i.map((e,t)=>[e,t]));o.delete(Ae);let s=new WeakMap,c=e=>{let t=s.get(e);return t||s.set(e,t=Int32Array.from(e.channels,e=>o.get(e.name)??-1)),t},l=null;for await(let{b:n,shift:i}of qo(e,t,a,r)){l??=+n.t[0]+i;let e=i-l,t=Object.entries(n.columns).flatMap(([e,t])=>{let n=o.get(e);return n===void 0?[]:[[n,t]]}),r=(n.events?.v.length??0)+t.reduce((e,[,t])=>e+t.length,0),a={t:new Float64Array(r),ch:new Uint32Array(r),v:new Float64Array(r),n:0},s=(t,n,r)=>{Number.isNaN(r)||(a.t[a.n]=t+e,a.ch[a.n]=n,a.v[a.n++]=r)},u=n.events?1:n.t.length;for(let e=0;e<u;e++)for(let[r,i]of t)e<i.length&&s(+n.t[e],r,+i[e]);if(n.events&&n.schema){let e=c(n.schema),{index:t,v:r}=n.events;for(let i=0;i<r.length;i++)e[t[i]]>=0&&s(+n.t[i],e[t[i]],r[i])}a.n&&(yield a)}}export{zr as $,R as $n,Nt as $t,Ei as A,Re as An,_n as At,Hn as B,_e as Bn,sn as Bt,aa as C,qe as Cn,wn as Ct,Zi as D,He as Dn,Cn as Dt,Yi as E,Ue as En,Nn as Et,Ln as F,ke as Fn,dn as Ft,Br as G,ve as Gn,Zt as Gt,Sr as H,me as Hn,tn as Ht,Cr as I,de as In,fn as It,hr as J,k as Jn,qt as Jt,Vn as K,oe as Kn,Xt as Kt,Or as L,ge as Ln,pn as Lt,Ai as M,Le as Mn,hn as Mt,ji as N,Ae as Nn,ln as Nt,ta as O,ze as On,bn as Ot,wi as P,Fe as Pn,mn as Pt,Ir as Q,F as Qn,Wt as Qt,Dr as R,he as Rn,on as Rt,Ca as S,Je as Sn,xn as St,ea as T,Ge as Tn,Mn as Tt,er as U,fe as Un,en as Ut,Un as V,ue as Vn,nn as Vt,ir as W,ye as Wn,Qt as Wt,vr as X,I as Xn,Kt as Xt,Zn as Y,P as Yn,Jt as Yt,Nr as Z,te as Zn,Gt as Zt,wa as _,et as _n,xr as _t,jo as a,Ot as an,v as ar,kr as at,ya as b,Ze as bn,sr as bt,wo as c,kt as cn,f as cr,jr as ct,ho as d,vt as dn,s as dr,br as dt,It as en,L as er,Er as et,_o as f,ft as fn,l as fr,nr as ft,fa as g,rt as gn,Qn as gt,da as h,it as hn,lr as ht,No as i,Lt as in,T as ir,Rr as it,Ti as j,We as jn,gn as jt,Fi as k,H as kn,vn as kt,Eo as l,_t as ln,h as lr,Pr as lt,go as m,lt as mn,or as mt,Ko as n,Ht as nn,w as nr,mr as nt,Ao as o,Ct as on,y as or,Vr as ot,vo as p,gt as pn,fr as pt,$n as q,O as qn,Yt as qt,Mo as r,Ut as rn,b as rr,Ar as rt,bo as s,Dt as sn,p as sr,gr as st,Jo as t,Bt as tn,le as tr,dr as tt,To as u,bt as un,o as ur,yr as ut,Sa as v,$e as vn,wr as vt,ca as w,Ke as wn,Tn as wt,va as x,Ye as xn,Pn as xt,Ta as y,Qe as yn,Tr as yt,pr as z,be as zn,cn as zt};