@kymoscope/sdk 0.14.2 → 0.15.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.
@@ -6,6 +6,6 @@ var e=Symbol(`row`),t=new WeakMap;function n(e){return t.get(e)}function r(e,t){
6
6
  `,t+1))b++;let x=0;for(let t=e.indexOf(`\r`,o);t>=0;t=e.indexOf(`\r`,t+1))e.charCodeAt(t+1)!==10&&x++;b+=x;let S=_.map(()=>new Float64Array(b)),E=_.map(()=>null),D=0,O=(e,t)=>{typeof t==`number`?S[e][D]=t:(S[e][D]=NaN,t!==null&&((E[e]??=[])[D]=t))},ee=e=>{let t=d(e,f);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<v;e++)O(e,t[e]===void 0?null:c(t[e],g));D++}},k=f.charCodeAt(0),A=k!==9&&e.indexOf(`"`,o)>=0||e.indexOf(``,o)>=0||x>0;for(s=o;s<e.length;){let t=e.indexOf(`
7
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&&A)for(let t=s;t<n;t++){let n=e.charCodeAt(t);if(n===13||n===65279||n===34&&k!==9){r=!1;break}}if(r){let t=s;for(let r=0;r<v;r++){if(t>n){O(r,null);continue}let i=w(e,t,n,k,g);if(i===i){S[r][D]=i,t=C+1;continue}let a=e.indexOf(f,t);(a<0||a>n)&&(a=n),O(r,c(e.slice(t,a),g)),t=a+1}D++}else{let n=e.slice(s,t);for(let e of n.split(/\r\n|\r|\n/)){let t=e.replace(/\uFEFF/g,``).trimEnd();t.length>0&&ee(t)}}s=t+1}let j=S.map(e=>b-D>b/100?e.slice(0,D):e.subarray(0,D));return{meta:a.length>0&&m(a[0],a[1])?a[0]:``,columnNames:p,units:h,table:{keys:_,length:D,values:j,text:E}}}var S=Array.from({length:23},(e,t)=>10**t),C=0;function w(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*S[m];else if(m<0&&m>=-22)h=c/S[-m];else return NaN;return C=a,s?-h:h}function T(e,t){let n=h(e),{headerRow:r,unitsRow:i,dataStartRow:a}=t,o=u(n[r]??``),s=y(n,r),f=[];i!==null&&n[i]!==void 0&&(f=d(n[i],o).map(e=>e.trim())),f.length===0&&(f=s.map(()=>``));let p=n.slice(a),g=l(p.slice(0,10),o),_=s.map((e,t)=>e||`col_${t}`),v=p.length,b=_.map(()=>new Float64Array(v)),x=_.map(()=>null),S=0;for(let e of p){let t=d(e,o);if(!(t.length===1&&t[0].trim()===``)){for(let e=0;e<_.length;e++){let n=t[e]===void 0?null:c(t[e],g);typeof n==`number`?b[e][S]=n:(b[e][S]=NaN,n!==null&&((x[e]??=[])[S]=n))}S++}}return S<v&&(b=b.map(e=>e.slice(0,S))),{meta:n.length>0&&m(n[0],n[1])?n[0]:``,columnNames:s,units:f,table:{keys:_,length:S,values:b,text:x}}}var E=5e3;function D(e,t){let n=O.get(e);n||O.set(e,n=new Map);let r=n.get(t);return r===void 0&&n.set(t,r=ee(e,t)),r}var O=new WeakMap;function ee(e,t){let r=n(e),i=r?r.keys.lastIndexOf(t):-1;if(r&&i>=0&&!r.text[i]){let e=r.values[i];for(let t=0;t<e.length;t++)if(e[t]===e[t])return!0;return!1}let a=e.length,o=0,s=0,c=Math.max(1,Math.floor(a/E));for(let n=0;n<a;n+=c){let r=e[n][t];r!=null&&(o++,typeof r==`number`&&s++)}if(o===0&&c>1)for(let n=0;n<a&&o<E;n++){let r=e[n][t];r!=null&&(o++,typeof r==`number`&&s++)}return o>0&&s/o>.95}function k(e,t){if(e<=t)return Array.from({length:e},(e,t)=>t);let n=[],r=e/t,i=0;for(let a=0;a<t;a++)n.push(Math.min(e-1,Math.floor(i))),i+=r;return n}var A=[];function j(e){return A.push(e),e}function M(e){for(let t of A)t.delete(e)}function N(e,t,n,r,i,a){let o=(i-r)/a;if(!(i>r)||a<1)return{x0:r,bucket:0,rows:[],columns:n};let s=Math.floor(a);if(te(e))return{x0:r,bucket:o,rows:F(e,t,r,i,o,s),columns:n};let c=new Uint8Array(s),l=t.map(()=>new Float64Array(s).fill(1/0)),u=t.map(()=>new Float64Array(s).fill(-1/0));for(let n=0;n<e.length;n++){let a=e[n];if(!(a>=r&&a<=i))continue;let d=Math.floor((a-r)/o);d>=s&&(d=s-1),c[d]=1;for(let e=0;e<t.length;e++){let r=t[e][n];r===r&&(r<l[e][d]&&(l[e][d]=r),r>u[e][d]&&(u[e][d]=r))}}let d=[];for(let e=0;e<s;e++){if(!c[e])continue;let n={b:e};for(let r=0;r<t.length;r++)l[r][e]!==1/0&&(n[`y${r}lo`]=l[r][e],n[`y${r}hi`]=u[r][e]);d.push(n)}return{x0:r,bucket:o,rows:d,columns:n}}var P=j(new WeakMap);function te(e){let t=P.get(e);if(t===void 0){t=!0;for(let n=0;n<e.length;n++)if(!(e[n]>=(n>0?e[n-1]:-1/0))){t=!1;break}P.set(e,t)}return t}function F(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 ne(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 I(e,t,n,r,i,a){if(!te(e))return null;let o=t=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;t(e[i])?n=i+1:r=i}return n},s=o(e=>e<r),c=o(e=>e<=i);if(c-s>a)return null;let l=e=>s===0&&c===e.length?e:e.subarray(s,c);return{length:c-s,x:l(e),cols:new Map(n.map((e,n)=>[e,l(t[n])]))}}var L=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function R(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function z(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}var re=new TextDecoder(`utf-8`),ie=new TextDecoder(`latin1`);function ae(e,t=!1){let n=e.indexOf(0);return(t?ie:re).decode(n<0?e:e.subarray(0,n))}var oe=e=>ie.decode(e),se=e=>re.decode(e);function B(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 ce={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>B(e,`MDF `)||B(e,`UnFinMF `)},le={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>B(e,`0 `)||e[0]===255&&B(e,`BIOSEMI`,1)},ue={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>B(e,`XDF:`)},de={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>B(e,`TDSm`)},fe={id:`mat`,label:`MATLAB MAT (v5, v7.3)`,extensions:[`.mat`],sniff:e=>B(e,`MATLAB 5.0 MAT-file`)||B(e,`MATLAB 7.3 MAT-file`)},pe=`‰HDF\r
8
8
  
9
- `,me={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>B(e,pe,t))},he={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=oe(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])}},ge=`This file couldn't be read (it may be damaged).`,_e=1032,ve=e=>e*_e+1024,ye=128e6,be=256,xe=64,Se=1e3,Ce=100,we=200,Te=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function Ee(e){let t=e.notes;for(let n of e.groups){n.name=Te(String(n.name),be);for(let e of n.channels)e.name=Te(String(e.name),be),e.unit=Te(String(e.unit??``),xe);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>Ce&&t.splice(Ce,t.length-Ce,`${t.length-Ce} more notes.`),e.notes=t.map(e=>Te(String(e),Se));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,we))n[Te(t,be)]=Te(String(r),Se);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:Te(String(e.text),Se)})),e}function De(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(ge)}function Oe(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 V=1<<20,ke=64,Ae=16<<20,je=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>V)return this.slice(e,n-e);let r=Math.floor(e/V),i=Math.floor((n-1)/V),a=await this.#n(r);if(r===i)return a.subarray(e-r*V,n-r*V);let o=new Uint8Array(n-e),s=a.subarray(e-r*V);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*V),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=Ae){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*V,V);return this.#t.size>=ke&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}},Me=`kymoscope-live-key-check-v1`,Ne=6e5,Pe=`kymoscope-open-stream-v1`;function H(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function U(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function W(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 Fe(e){return U(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Ie(e){return W(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(Math.ceil(e.length/4)*4,`=`))}function Le(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}function Re(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),U(e)}async function ze(e,t){let n=new TextEncoder,r=await H().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return H().deriveKey({name:`PBKDF2`,salt:W(t),iterations:Ne,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Be(e,t){let n=await H().importKey(`raw`,new TextEncoder().encode(e),`PBKDF2`,!1,[`deriveBits`]),r=await H().deriveBits({name:`PBKDF2`,salt:W(t),iterations:Ne,hash:`SHA-256`},n,256);return U(new Uint8Array(r))}var Ve=null,He=0;function Ue(){(!Ve||He>4294967295)&&(Ve=globalThis.crypto.getRandomValues(new Uint8Array(8)),He=0);let e=new Uint8Array(12);return e.set(Ve),new DataView(e.buffer).setUint32(8,He++),e}async function We(e,t){let n=Ue(),r=new TextEncoder().encode(JSON.stringify(t)),i=await H().encrypt({name:`AES-GCM`,iv:n},e,r);return{iv:U(n),ciphertext:U(new Uint8Array(i))}}async function Ge(e,t){let n=W(t.iv),r=W(t.ciphertext),i=await H().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function Ke(e,t,n,r){let i=await H().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function qe(e,t){return JSON.parse(new TextDecoder().decode(await Ge(e,t)))}async function Je(e){return We(e,Me)}async function Ye(e,t){try{return await qe(e,t)===Me}catch{return!1}}async function Xe(e){let t=await H().digest(`SHA-256`,new TextEncoder().encode(e));return Le(new Uint8Array(t))}function Ze(){let e=e=>{let t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),Fe(t)},t=`kymoscope_${e(24)}.${e(32)}`;return{token:t,prefix:t.slice(0,12)}}var Qe=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/;function $e(e){let t=Qe.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}var et=new TextEncoder().encode(`kymoscope-device-wrap-v1`);async function tt(){let e=await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),t=new Uint8Array(await H().exportKey(`raw`,e.publicKey));return{privateKey:e.privateKey,publicKey:U(t)}}async function nt(e,t){let n=new Uint8Array(e.length+et.length);return n.set(e),n.set(et,e.length),H().importKey(`raw`,await H().digest(`SHA-256`,n),`AES-GCM`,!1,t)}async function rt(e,t,n){let r=await H().importKey(`raw`,W(t.epk),{name:`ECDH`,namedCurve:`P-256`},!1,[]),i=new Uint8Array(await H().deriveBits({name:`ECDH`,public:r},e,256));return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},await nt(i,[`decrypt`]),W(t.ct)))}function it(e,t,n){return at(e,t,n)}async function at(e,t,n,r,i){let a=await H().importKey(`raw`,W(e),{name:`ECDH`,namedCurve:`P-256`},!1,[]),o=r??await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),s=new Uint8Array(await H().deriveBits({name:`ECDH`,public:a},o.privateKey,256)),c=i??Ue(),l=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:c,additionalData:new TextEncoder().encode(n)},await nt(s,[`encrypt`]),t));return{epk:U(new Uint8Array(await H().exportKey(`raw`,o.publicKey))),iv:U(c),ct:U(l)}}async function ot(e,t,n,r){return ft(await rt(e,t,`${n}|${r}`))}var st=new TextEncoder().encode(`kymoscope-sender-bind-v1`),ct=(e,t,n)=>`project:${e}:${t}|${n}`,lt=(e,t,n)=>`live_stream:${e}|${t}:${n}`,ut=(e,t,n)=>`bind:${e}|${t}:${n}`;function dt(){return globalThis.crypto.getRandomValues(new Uint8Array(32))}function ft(e){return H().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function pt(e,t,n){return mt(e,t,n)}async function mt(e,t,n,r){let i=r??Ue(),a=await H().importKey(`raw`,e,`AES-GCM`,!1,[`encrypt`]),o=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},a,t));return{iv:U(i),ct:U(o)}}async function ht(e,t,n){let r=await H().importKey(`raw`,e,`AES-GCM`,!1,[`decrypt`]);return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},r,W(t.ct)))}async function gt(e){let t=new TextEncoder().encode(e),n=new Uint8Array(t.length+st.length);return n.set(t),n.set(st,t.length),new Uint8Array(await H().digest(`SHA-256`,n))}async function _t(e,t,n){let r=await H().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return U(new Uint8Array(await H().sign(`HMAC`,r,new TextEncoder().encode(`sender|${t}|${n}`))))}async function vt(e,t,n,r){let i;try{i=W(r)}catch{return!1}let a=await H().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`verify`]);return H().verify(`HMAC`,a,i,new TextEncoder().encode(`sender|${t}|${n}`))}async function yt(e){let t=Le(new Uint8Array(await H().digest(`SHA-256`,W(e)))).slice(0,16).toUpperCase();return`${t.slice(0,4)}-${t.slice(4,8)}-${t.slice(8,12)}-${t.slice(12,16)}`}var bt=`kymoscope-workbook-export-v2`,xt=(e,t)=>`workbook:${e}:${t}`,St=(e,t,n)=>`workbook:${e}|${t}:${n}`,Ct=(e,t)=>`project_config:${e}|${e}:${t}`,wt=(e,t,n)=>`alert_rule:${e}:${t}|${n}`,Tt=(e,t)=>`kymoscope-recovery-key-v1|${e}|${t}`,Et=(e,t,n)=>`recovery:${e}|${t}:${n}`;function Dt(e,t,n){return Ot(e,t,n)}async function Ot(e,t,n,r){let i=r??Ue(),a=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:U(i),ct:U(a)}}async function kt(e,t,n){return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},e,W(t.ct)))}function At(e,t,n){return jt(e,t,n)}async function jt(e,t,n,r,i){let a=U(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await Ot(await ze(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:Ne,salt:a},...o}}async function Mt(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==Ne||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return kt(await ze(e,r.salt),t,n)}var Nt=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`;function Pt(e){let t=0,n=0,r=``;for(let i of e)for(n=(n<<8|i)&1048575,t+=8;t>=5;)r+=Nt[n>>>t-5&31],t-=5;return t>0&&(r+=Nt[n<<5-t&31]),r.match(/.{1,4}/g).join(`-`)}function Ft(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|Nt.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 It(){let e=await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!0,[`deriveBits`]),t=await H().exportKey(`jwk`,e.privateKey),n=new Uint8Array(await H().exportKey(`raw`,e.publicKey));return{d:Ie(t.d),publicKey:U(n)}}function Lt(e,t){let n=W(t);return H().importKey(`jwk`,{kty:`EC`,crv:`P-256`,ext:!1,x:Fe(n.subarray(1,33)),y:Fe(n.subarray(33,65)),d:Fe(e)},{name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`])}var Rt=j(new WeakSet),zt={length:0,x:new Float64Array,cols:new Map};function Bt(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 Vt(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 Ht(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 Ut(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 Vt(e,n)}function Wt(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 Gt(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 Kt(e,t,i,a,o=``,s=0){let c=n(e),l=k(e.length,a),u=t=>{let n=c&&r(c,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},d=u(t),f=[];for(let e of l)Number.isNaN(d(e))||f.push(e);let p=f.length,m=p===e.length&&s===0,h=c&&r(c,t),g=m&&h?h:Float64Array.from(f,e=>d(e)+s),_=new Map;for(let e of i){let t=c&&r(c,e);if(c&&!t)continue;if(m&&t){_.set(e+o,t);continue}let n=u(e),i=Float64Array.from(f,n);!t&&!i.some(e=>!Number.isNaN(e))||_.set(e+o,i)}return{length:p,x:g,cols:_}}function qt(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 Jt(e){let t=e.filter(e=>e.length>0);if(t.length===0)return zt;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 G=64,Yt=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=G-this.pStart,r=2*(t+e+G)<=this.px.length,i=r?this.px.length:Math.max(4*this.b.length+G,2*(t+e+G)),a=e=>{if(r)return e.copyWithin(G,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),G),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=G,this.pEnd=G+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=G,this.mStart=this.mEnd=e,this.reserve(r);let i=G;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 Xt(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 Zt=4e6,Qt=60,$t=32,en=4;function tn(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 nn(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 rn=`ElapsedTime`,an=[];function on(e){let t=an[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]])])))},an[e]=t}return t}var sn=4096,cn=4,ln=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;debugGrowCopied=0;timeDecs=new Map;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;constructor(e,t=rn,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,sn),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.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.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=nn(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let i of r){if(this.computed.has(i))continue;let r=e.columns[i];for(let e=n-1;e>=0;e--)if(Number.isFinite(r[e])){this.noteValue(i,+t[e],r[e]);break}}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);tn(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?tn(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>Qt){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)>Zt||!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(`
10
- `)}|${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>Zt)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;this.decCache&&this.decCache.pushed>y&&(this.decCache.pushed=y);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.decCache=null,this.timeDecs.clear(),this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.growing=null,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDecs.clear(),this.snapDec=null,this.latest.clear(),this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null,next:this.pushed},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return N(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return Bt(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}let o=this.trackers.get(e);if(o){for(let t=0;t<r.length;t++){let i=n+t,a=r[t];i<o.next||i<this.firstAbs||i>=this.pushed||a===null||!Number.isFinite(a)||this.advanceCycle(e,o,a,i)}o.next=Math.max(o.next,Math.min(this.pushed,n+r.length))}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDecs.clear(),this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=on(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*cn)))}let l=Xt(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=on(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 Bt(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*cn)))}let d=Xt(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 Yt(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 Yt(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 Yt(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,en)),this.timeDecs.size>$t&&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=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}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;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=i>1&&this.timeMonotonic?this.snapshotRows(e):null;if(a)return{meta:``,columnNames:t,units:n,rows:a};let o=this.pushed-r,s=i>1?(i-o%i)%i:0,c=[];for(let e=s;e<r;e+=i)c.push(this.full?(this.head+e)%this.capacity:e);r>0&&(c.length===0||(r-1-s)%i!=0)&&c.push(this.full?(this.head+r-1)%this.capacity:r-1);let l=e=>{let t=new Float64Array(c.length);for(let n=0;n<c.length;n++)t[n]=e[c[n]];return t};return{meta:``,columnNames:t,units:n,rows:un(t,[l(this.time),...this.signalOrder.map(e=>l(this.cols.get(e)))])}}snapshotRows(e){let t=this.size,n=e=>this.full?(this.head+e)%this.capacity:e,r=this.time[n(0)],i=this.time[n(t-1)],a=(i-r)*2/e;if(!(a>0))return null;let o=`${this.signalOrder.join(`
11
- `)}|${this.clears}`,s=this.signalOrder.map(e=>this.cols.get(e)),c=this.snapDec,l=c?this.pushed-c.pushed:0;if(c&&c.key===o&&c.bucket<a&&l>=0&&l<t){let e=2;for(;c.bucket*e<a;)e*=2;c.store.coarsen(e),c.bucket*=e,c.fromB=Math.floor(c.fromB/e)}if(c&&c.key===o&&c.bucket>=a&&c.bucket<=a*4&&l>=0&&l<t){let e=c.store;l>0&&this.foldBuckets(e,t-l,t,c.bucket,s);let n=Math.floor(r/c.bucket);this.full&&n>=c.fromB&&(e.dropBelow(n),e.reset(e.row(n)),this.foldBuckets(e,0,this.timeIndex((n+1)*c.bucket),c.bucket,s),c.fromB=n),c.pushed=this.pushed}else{let n=2**Math.ceil(Math.log2(a));n<a&&(n*=2);let i=new Yt(s.length,n,Math.ceil(e/2)+8);this.foldBuckets(i,0,t,n,s),c=this.snapDec={key:o,bucket:n,store:i,pushed:this.pushed,fromB:Math.floor(r/n)}}let u=c.store.toPoints(c.store.start,c.store.end,this.signalOrder),d=new Float64Array(u.x),f=d[0],p=d[d.length-1];for(let e=0;e<d.length;e++)d[e]=d[e]===p?i:d[e]===f?r:d[e];return un([this.timeColumn,...this.signalOrder],[d,...this.signalOrder.map(e=>new Float64Array(u.cols.get(e)))])}valueBounds(e){let t=this.columnBounds(e);return Number.isFinite(this.boundsCache.get(e)?.lo??NaN)?t:null}hasValues(e){return this.latest.has(e)||this.computed.has(e)}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}setLastKnown(e,t,n,r){e===this.timeColumn||this.computed.has(e)||!Number.isFinite(n)||!Number.isFinite(r)||(this.cols.has(e)||(this.cols.set(e,this.newColumn()),this.signalOrder.push(e),this.unitByName.set(e,t)),this.noteValue(e,n,r))}noteValue(e,t,n){let r=this.latest.get(e);r?t>=r.t&&(r.t=t,r.v=n):this.latest.set(e,{t,v:n})}};function un(e,t){return a({keys:e,length:t[0]?.length??0,values:t,text:e.map(()=>null)})}new TextEncoder;var dn=4096;function fn(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>=dn&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var pn=new TextDecoder,mn=200;function hn(e,t,n){let r=e.subarray(t,t+n);return pn.decode(r)}function gn(e,t,n){return n>mn?hn(e,t,n):fn(e,t,n)}var _n=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 vn(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function yn(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function bn(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var xn=4294967295,Sn=17179869183;function Cn({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=Sn)if(t===0&&e<=xn){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),vn(r,4,e),n}}function wn(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 Tn(e){return e instanceof Date?Cn(wn(e)):null}function En(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:yn(t,4),nsec:t.getUint32(0)};default:throw new K(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function Dn(e){let t=En(e);return new Date(t.sec*1e3+t.nsec/1e6)}var On={type:-1,encode:Tn,decode:Dn},kn=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(On)}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 _n(-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 _n(n,i)}}return e instanceof _n?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new _n(t,e)}};function An(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function jn(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):An(e)?new Uint8Array(e):Uint8Array.from(e)}function Mn(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var Nn=16,Pn=16,Fn=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=Nn,t=Pn){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=fn(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}},In=`array`,Ln=`map_key`,Rn=`map_value`,zn=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)},Bn=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=In,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=Ln,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===In){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===Ln||e.type===Rn){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}},Vn=-1,Hn=new DataView(new ArrayBuffer(0)),Un=new Uint8Array(Hn.buffer);try{Hn.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 Wn=RangeError(`Insufficient data`),Gn=new Fn,Kn=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=Hn;bytes=Un;headByte=Vn;stack=new Bn;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??kn.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?Gn:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??zn}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=Vn,this.stack.reset()}setBuffer(e){let t=jn(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Vn&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=jn(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 ${Mn(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: ${Mn(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===In)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===Ln){if(t===`__proto__`)throw new K(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=Rn;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=Ln;continue DECODE}}return t}}readHeadByte(){return this.headByte===Vn&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Vn}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: ${Mn(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 Wn;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):gn(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===Ln:!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 Wn;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=bn(this.view,this.pos);return this.pos+=8,e}readI64(){let e=yn(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 qn(e,t){return new Kn(t).decode(e)}var Jn=6,Yn=8,Xn=12,Zn=16;function Qn(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+Xn+Zn?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+Xn),ciphertext:t.subarray(n+Xn),aad:t.subarray(0,n)}}async function $n(e,t){let n=Qn(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await Ke(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}function er(e,t,n,r){return tr(e,t,n,r)}async function tr(e,t,n,r,i){let a=r===void 0?new Uint8Array([t]):new Uint8Array([t|128,r&255]),o=i??Ue(),s=new Uint8Array(await globalThis.crypto.subtle.encrypt({name:`AES-GCM`,iv:o,additionalData:a},e,n)),c=new Uint8Array(a.length+Xn+s.length);return c.set(a),c.set(o,a.length),c.set(s,a.length+Xn),c.buffer}var nr=1,rr=e=>e+7&-8;function ir(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)!==nr)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=rr(s),s+rr(i*8)+o.reduce((e,t)=>e+rr(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=rr(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+=rr(i*t.size);return{t:l,columns:u,units:d}}var ar=2,or=1,sr=1,cr=2,lr=20,ur=64*1024*1024,q=(e,t)=>RangeError(`${e}: ${t}`);function dr(e){if(e.byteLength<8)throw q(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==ar)throw q(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw q(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw q(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw q(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:q(`block schema`,`invalid text`)}return{id:r,channels:a}}function fr(e,t){if(e.byteLength<12)throw q(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==or)throw q(`last values`,`version ${n.getUint8(0)}`);let r=t.get(n.getUint32(4,!0));if(!r)return null;let i=n.getUint32(8,!0);if(i!==r.channels.length)throw q(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw q(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let t=n.getFloat64(12+8*e,!0),o=n.getFloat64(12+8*(i+e),!0);Number.isFinite(t)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t,v:o})}return a}async function pr(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw q(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:q(`block`,`body is not valid deflate`)}if(i!==t)throw q(`block`,`body size mismatch`);return r}async function mr(e,t){if(e.byteLength<lr)throw q(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==ar)throw q(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw q(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>ur)throw q(`block`,`too large`);let u;if(r&sr)u=await pr(e.subarray(lr),l);else if(u=e.subarray(lr),u.byteLength<l)throw q(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&cr)!==0}}var hr=0,gr=1,_r=70,vr=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),yr=e=>Uint8Array.from(e.match(/../g)??[],e=>parseInt(e,16)),br=e=>{let t=yr(e.replace(/-/g,``));if(t.length!==16)throw Error(`bad_stream_id`);return t},xr=e=>{let t=vr(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function Sr(e){let t=new Uint8Array(_r),n=new DataView(t.buffer);return t[0]=1,t.set(br(e.streamId),1),t.set(yr(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 Cr(e){if(e.length!==_r||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:xr(e.subarray(1,17)),run:vr(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}var wr=()=>globalThis.crypto.subtle,Tr=e=>wr().digest(`SHA-256`,e);async function Er(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 Tr(n))}var Dr=()=>vr(globalThis.crypto.getRandomValues(new Uint8Array(8))),Or=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(Tr(e))}async checkpoint(){let e=this.digests;return this.digests=[],this.seq+=1n,Sr({streamId:this.streamId,run:this.run,lane:this.lane,seq:this.seq,count:e.length,hash:await Er(e)})}};function kr(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(Tr(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?Cr(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&&Ar(await Er(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 Ar=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),J=Uint8Array,Y=Uint16Array,jr=Int32Array,Mr=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]),Nr=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]),Pr=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fr=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 jr(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}},Ir=Fr(Mr,2),Lr=Ir.b,Rr=Ir.r;Lr[28]=258,Rr[258]=28;for(var zr=Fr(Nr,0),Br=zr.b,Vr=zr.r,Hr=new Y(32768),X=0;X<32768;++X){var Ur=(X&43690)>>1|(X&21845)<<1;Ur=(Ur&52428)>>2|(Ur&13107)<<2,Ur=(Ur&61680)>>4|(Ur&3855)<<4,Hr[X]=((Ur&65280)>>8|(Ur&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[Hr[d]>>c]=l}else for(s=new Y(r),i=0;i<r;++i)e[i]&&(s[i]=Hr[o[e[i]-1]++]>>15-e[i]);return s}),Wr=new J(288),X=0;X<144;++X)Wr[X]=8;for(var X=144;X<256;++X)Wr[X]=9;for(var X=256;X<280;++X)Wr[X]=7;for(var X=280;X<288;++X)Wr[X]=8;for(var Gr=new J(32),X=0;X<32;++X)Gr[X]=5;var Kr=Z(Wr,9,0),qr=Z(Wr,9,1),Jr=Z(Gr,5,0),Yr=Z(Gr,5,1),Xr=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},Zr=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Qr=function(e){return(e+7)/8|0},$r=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))},ei=[`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||ei[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,$),!n)throw r;return r},ti=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=Qr(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=qr,m=Yr,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[Pr[D]]=Q(e,d+D*3,7);d+=C*3;for(var O=Xr(E),ee=(1<<O)-1,k=Z(E,O,1),D=0;D<w;){var A=k[Q(e,d,ee)];d+=A&15;var y=A>>4;if(y<16)T[D++]=y;else{var j=0,M=0;for(y==16?(M=3+Q(e,d,3),d+=2,j=T[D-1]):y==17?(M=3+Q(e,d,7),d+=3):y==18&&(M=11+Q(e,d,127),d+=7);M--;)T[D++]=j}}var N=T.subarray(0,S),P=T.subarray(S);h=Xr(N),g=Xr(P),p=Z(N,h,1),m=Z(P,g,1)}else $(1);if(d>_){c&&$(0);break}}s&&l(f+131072);for(var te=(1<<h)-1,F=(1<<g)-1,ne=d;;ne=d){var j=p[Zr(e,d)&te],I=j>>4;if(d+=j&15,d>_){c&&$(0);break}if(j||$(2),I<256)n[f++]=I;else if(I==256){ne=d,p=null;break}else{var L=I-254;if(I>264){var D=I-257,R=Mr[D];L=Q(e,d,(1<<R)-1)+Lr[D],d+=R}var z=m[Zr(e,d)&F],re=z>>4;z||$(3),d+=z&15;var P=Br[re];if(re>3){var R=Nr[re];P+=Zr(e,d)&(1<<R)-1,d+=R}if(d>_){c&&$(0);break}s&&l(f+131072);var ie=f+L;if(f<P){var ae=a-P,oe=Math.min(P,ie);for(ae+f<0&&$(3);f<oe;++f)n[f]=r[ae+f]}for(;f<ie;++f)n[f]=n[f-P]}}t.l=p,t.p=ne,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?$r(n,0,f):n.subarray(0,f)},ni=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},ri=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},ii=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:di,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=ai(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}},ai=function(e,t,n){return e.s==-1?Math.max(ai(e.l,t,n+1),ai(e.r,t,n+1)):t[e.s]=n},oi=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}},si=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},ci=function(e,t,n){var r=n.length,i=Qr(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},li=function(e,t,n,r,i,a,o,s,c,l,u){ni(t,u++,n),++i[256];for(var d=ii(i,15),f=d.t,p=d.l,m=ii(a,15),h=m.t,g=m.l,_=oi(f),v=_.c,y=_.n,b=oi(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=ii(C,7),E=T.t,D=T.l,O=19;O>4&&!E[Pr[O-1]];--O);var ee=l+5<<3,k=si(i,Wr)+si(a,Gr)+o,A=si(i,f)+si(a,h)+o+14+3*O+si(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&ee<=k&&ee<=A)return ci(t,u,e.subarray(c,c+l));var j,M,N,P;if(ni(t,u,1+(A<k)),u+=2,A<k){j=Z(f,p,0),M=f,N=Z(h,g,0),P=h;var te=Z(E,D,0);ni(t,u,y-257),ni(t,u+5,S-1),ni(t,u+10,O-4),u+=14;for(var w=0;w<O;++w)ni(t,u+3*w,E[Pr[w]]);u+=3*O;for(var F=[v,x],ne=0;ne<2;++ne)for(var I=F[ne],w=0;w<I.length;++w){var L=I[w]&31;ni(t,u,te[L]),u+=E[L],L>15&&(ni(t,u,I[w]>>5&127),u+=I[w]>>12)}}else j=Kr,M=Wr,N=Jr,P=Gr;for(var w=0;w<s;++w){var R=r[w];if(R>255){var L=R>>18&31;ri(t,u,j[L+257]),u+=M[L+257],L>7&&(ni(t,u,R>>23&31),u+=Mr[L]);var z=R&31;ri(t,u,N[z]),u+=P[z],z>3&&(ri(t,u,R>>5&8191),u+=Nr[z])}else ri(t,u,j[R]),u+=M[R]}return ri(t,u,j[256]),u+M[256]},ui=new jr([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),di=new J(0),fi=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=ui[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 jr(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 ee=y(T),k=T&32767,A=g[ee];if(h[k]=A,g[ee]=k,D<=T){var j=o-T;if((C>7e3||E>24576)&&(j>423||!l)){u=li(e,c,0,b,x,S,w,E,O,T-O,u),E=C=w=0,O=T;for(var M=0;M<286;++M)x[M]=0;for(var M=0;M<30;++M)S[M]=0}var N=2,P=0,te=p,F=k-A&32767;if(j>2&&ee==y(T-F))for(var ne=Math.min(f,j)-1,I=Math.min(32767,T),L=Math.min(258,j);F<=I&&--te&&k!=A;){if(e[T+N]==e[T+N-F]){for(var R=0;R<L&&e[T+R]==e[T+R-F];++R);if(R>N){if(N=R,P=F,R>ne)break;for(var z=Math.min(F,R-2),re=0,M=0;M<z;++M){var ie=T-F+M&32767,ae=ie-h[ie]&32767;ae>re&&(re=ae,A=ie)}}}k=A,A=h[k],F+=k-A&32767}if(P){b[E++]=268435456|Rr[N]<<18|Vr[P];var oe=Rr[N]&31,se=Vr[P]&31;w+=Mr[oe]+Nr[se],++x[257+oe],++S[se],D=T+N,++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=li(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 B=T+65535;B>=o&&(c[u/8|0]=l,B=o),u=ci(c,u+1,e.subarray(T,B))}a.i=o}return $r(s,0,r+Qr(u)+i)},pi=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}}},mi=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 fi(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)},hi=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},gi=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=pi();i.p(t.dictionary),hi(e,2,i.d())}},_i=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},vi=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=ti(this.p,this.s,this.o);this.ondata($r(n,t,this.s.b),this.d),this.o=$r(n,this.s.b-32768),this.s.b=this.o.length,this.p=$r(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 yi(e,t){t||={};var n=pi();n.p(e);var r=mi(e,t,t.dictionary?6:2,4);return gi(r,t),hi(r,r.length-4,n.d()),r}var bi=function(){function e(e,t){vi.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(vi.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(_i(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&$(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),vi.prototype.c.call(this,t)},e}();function xi(e,t){return ti(e.subarray(_i(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var Si=typeof TextDecoder<`u`&&new TextDecoder;try{Si.decode(di,{stream:!0})}catch{}var Ci=56,wi=[75,82,67,49];function Ti(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 Ei(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 Di(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(wi,0),a.setUint16(4,1,!0),a.setUint16(6,56,!0),i.set(Ti(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 Oi(e){if(e.length<56||wi.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:Ei(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 ki(e){let t=Oi(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 Ai=e=>crypto.subtle.digest(`SHA-256`,e),ji=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),Mi=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16));async function Ni(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?Cr(a.plaintext):null,s=ji(await Ai(Mi(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&&ji((await Er(t.slice(0,-1).map(e=>Ai(e.bytes)))).buffer)===ji(o.hash.buffer)?`verified`:`broken`}function Pi(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 Fi=(e,t,n)=>`recording_key:${e}|${t}:${n}`,Ii=(e,t,n)=>n===e.stream_epoch?lt(e.stream_id,t,n):Fi(e.id,t,n),Li=12,Ri=16;function zi(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+Li+Ri)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 Ke(e,n.subarray(r,r+Li),n.subarray(r+Li),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}export{Re as $,j as $t,rn as A,Oe as At,Bt as B,ue as Bt,fr as C,Ye as Ct,$n as D,it as Dt,Jn as E,St as Et,Ut as F,ve as Ft,wt as G,z as Gt,Kt as H,ce as Ht,Jt as I,he as It,Be as J,se as Jt,ut as K,B as Kt,Gt as L,me as Lt,nn as M,ye as Mt,zt as N,Ee as Nt,er as O,je as Ot,Wt as P,De as Pt,It as Q,I as Qt,Rt as R,fe as Rt,dr as S,ot as St,Yn as T,xt as Tt,Pe as U,oe as Ut,qt as V,le as Vt,bt as W,ae as Wt,Ze as X,ne as Xt,yt as Y,L as Yt,tt as Z,N as Zt,kr as _,gt as _t,Ni as a,v as an,Mt as at,Dr as b,lt as bt,ki as c,x as cn,ct,xi as d,r as dn,Pt as dt,M as en,Xe as et,yi as f,n as fn,Tt as ft,Er as g,At as gt,Or as h,Dt as ht,Pi as i,h as in,kt as it,ln as j,ge as jt,qn as k,Ae as kt,Oi as l,b as ln,dt as lt,gr as m,pt as mt,Fi as n,l as nn,Je as nt,Ci as o,y as on,Ft as ot,hr as p,a as pn,Lt as pt,ze as q,R as qt,Ii as r,u as rn,ht as rt,Di as s,g as sn,Ct as st,zi as t,D as tn,ft as tt,bi as u,k as un,Et as ut,Cr as v,_t as vt,ir as w,vt as wt,mr as x,rt as xt,Sr as y,$e as yt,Ht as z,de as zt};
9
+ `,me={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>B(e,pe,t))},he={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=oe(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])}},ge=`This file couldn't be read (it may be damaged).`,_e=1032,ve=e=>e*_e+1024,ye=128e6,be=256,xe=64,Se=1e3,Ce=100,we=200,Te=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function Ee(e){let t=e.notes;for(let n of e.groups){n.name=Te(String(n.name),be);for(let e of n.channels)e.name=Te(String(e.name),be),e.unit=Te(String(e.unit??``),xe);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>Ce&&t.splice(Ce,t.length-Ce,`${t.length-Ce} more notes.`),e.notes=t.map(e=>Te(String(e),Se));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,we))n[Te(t,be)]=Te(String(r),Se);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:Te(String(e.text),Se)})),e}function De(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(ge)}function Oe(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 V=1<<20,ke=64,Ae=16<<20,je=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>V)return this.slice(e,n-e);let r=Math.floor(e/V),i=Math.floor((n-1)/V),a=await this.#n(r);if(r===i)return a.subarray(e-r*V,n-r*V);let o=new Uint8Array(n-e),s=a.subarray(e-r*V);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*V),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=Ae){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*V,V);return this.#t.size>=ke&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}},Me=`kymoscope-live-key-check-v1`,Ne=6e5,Pe=`kymoscope-open-stream-v1`;function H(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function U(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function W(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 Fe(e){return U(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Ie(e){return W(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(Math.ceil(e.length/4)*4,`=`))}function Le(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}function Re(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),U(e)}async function ze(e,t){let n=new TextEncoder,r=await H().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return H().deriveKey({name:`PBKDF2`,salt:W(t),iterations:Ne,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Be(e,t){let n=await H().importKey(`raw`,new TextEncoder().encode(e),`PBKDF2`,!1,[`deriveBits`]),r=await H().deriveBits({name:`PBKDF2`,salt:W(t),iterations:Ne,hash:`SHA-256`},n,256);return U(new Uint8Array(r))}var Ve=null,He=0;function Ue(){(!Ve||He>4294967295)&&(Ve=globalThis.crypto.getRandomValues(new Uint8Array(8)),He=0);let e=new Uint8Array(12);return e.set(Ve),new DataView(e.buffer).setUint32(8,He++),e}async function We(e,t){let n=Ue(),r=new TextEncoder().encode(JSON.stringify(t)),i=await H().encrypt({name:`AES-GCM`,iv:n},e,r);return{iv:U(n),ciphertext:U(new Uint8Array(i))}}async function Ge(e,t){let n=W(t.iv),r=W(t.ciphertext),i=await H().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function Ke(e,t,n,r){let i=await H().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function qe(e,t){return JSON.parse(new TextDecoder().decode(await Ge(e,t)))}async function Je(e){return We(e,Me)}async function Ye(e,t){try{return await qe(e,t)===Me}catch{return!1}}async function Xe(e){let t=await H().digest(`SHA-256`,new TextEncoder().encode(e));return Le(new Uint8Array(t))}function Ze(){let e=e=>{let t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),Fe(t)},t=`kymoscope_${e(24)}.${e(32)}`;return{token:t,prefix:t.slice(0,12)}}var Qe=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/;function $e(e){let t=Qe.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}var et=new TextEncoder().encode(`kymoscope-device-wrap-v1`);async function tt(){let e=await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),t=new Uint8Array(await H().exportKey(`raw`,e.publicKey));return{privateKey:e.privateKey,publicKey:U(t)}}async function nt(e,t){let n=new Uint8Array(e.length+et.length);return n.set(e),n.set(et,e.length),H().importKey(`raw`,await H().digest(`SHA-256`,n),`AES-GCM`,!1,t)}async function rt(e,t,n){let r=await H().importKey(`raw`,W(t.epk),{name:`ECDH`,namedCurve:`P-256`},!1,[]),i=new Uint8Array(await H().deriveBits({name:`ECDH`,public:r},e,256));return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},await nt(i,[`decrypt`]),W(t.ct)))}function it(e,t,n){return at(e,t,n)}async function at(e,t,n,r,i){let a=await H().importKey(`raw`,W(e),{name:`ECDH`,namedCurve:`P-256`},!1,[]),o=r??await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`]),s=new Uint8Array(await H().deriveBits({name:`ECDH`,public:a},o.privateKey,256)),c=i??Ue(),l=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:c,additionalData:new TextEncoder().encode(n)},await nt(s,[`encrypt`]),t));return{epk:U(new Uint8Array(await H().exportKey(`raw`,o.publicKey))),iv:U(c),ct:U(l)}}async function ot(e,t,n,r){return ft(await rt(e,t,`${n}|${r}`))}var st=new TextEncoder().encode(`kymoscope-sender-bind-v1`),ct=(e,t,n)=>`project:${e}:${t}|${n}`,lt=(e,t,n)=>`live_stream:${e}|${t}:${n}`,ut=(e,t,n)=>`bind:${e}|${t}:${n}`;function dt(){return globalThis.crypto.getRandomValues(new Uint8Array(32))}function ft(e){return H().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function pt(e,t,n){return mt(e,t,n)}async function mt(e,t,n,r){let i=r??Ue(),a=await H().importKey(`raw`,e,`AES-GCM`,!1,[`encrypt`]),o=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},a,t));return{iv:U(i),ct:U(o)}}async function ht(e,t,n){let r=await H().importKey(`raw`,e,`AES-GCM`,!1,[`decrypt`]);return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},r,W(t.ct)))}async function gt(e){let t=new TextEncoder().encode(e),n=new Uint8Array(t.length+st.length);return n.set(t),n.set(st,t.length),new Uint8Array(await H().digest(`SHA-256`,n))}async function _t(e,t,n){let r=await H().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return U(new Uint8Array(await H().sign(`HMAC`,r,new TextEncoder().encode(`sender|${t}|${n}`))))}async function vt(e,t,n,r){let i;try{i=W(r)}catch{return!1}let a=await H().importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`verify`]);return H().verify(`HMAC`,a,i,new TextEncoder().encode(`sender|${t}|${n}`))}async function yt(e){let t=Le(new Uint8Array(await H().digest(`SHA-256`,W(e)))).slice(0,16).toUpperCase();return`${t.slice(0,4)}-${t.slice(4,8)}-${t.slice(8,12)}-${t.slice(12,16)}`}var bt=`kymoscope-workbook-export-v2`,xt=(e,t)=>`workbook:${e}:${t}`,St=(e,t,n)=>`workbook:${e}|${t}:${n}`,Ct=(e,t)=>`project_config:${e}|${e}:${t}`,wt=(e,t,n)=>`alert_rule:${e}:${t}|${n}`,Tt=(e,t,n)=>`alert_event:${e}:${t}|${n}`,Et=(e,t)=>`kymoscope-recovery-key-v1|${e}|${t}`,Dt=(e,t,n)=>`recovery:${e}|${t}:${n}`;function Ot(e,t,n){return kt(e,t,n)}async function kt(e,t,n,r){let i=r??Ue(),a=new Uint8Array(await H().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:U(i),ct:U(a)}}async function At(e,t,n){return new Uint8Array(await H().decrypt({name:`AES-GCM`,iv:W(t.iv),additionalData:new TextEncoder().encode(n)},e,W(t.ct)))}function jt(e,t,n){return Mt(e,t,n)}async function Mt(e,t,n,r,i){let a=U(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await kt(await ze(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:Ne,salt:a},...o}}async function Nt(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==Ne||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return At(await ze(e,r.salt),t,n)}var Pt=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`;function Ft(e){let t=0,n=0,r=``;for(let i of e)for(n=(n<<8|i)&1048575,t+=8;t>=5;)r+=Pt[n>>>t-5&31],t-=5;return t>0&&(r+=Pt[n<<5-t&31]),r.match(/.{1,4}/g).join(`-`)}function It(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|Pt.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 Lt(){let e=await H().generateKey({name:`ECDH`,namedCurve:`P-256`},!0,[`deriveBits`]),t=await H().exportKey(`jwk`,e.privateKey),n=new Uint8Array(await H().exportKey(`raw`,e.publicKey));return{d:Ie(t.d),publicKey:U(n)}}function Rt(e,t){let n=W(t);return H().importKey(`jwk`,{kty:`EC`,crv:`P-256`,ext:!1,x:Fe(n.subarray(1,33)),y:Fe(n.subarray(33,65)),d:Fe(e)},{name:`ECDH`,namedCurve:`P-256`},!1,[`deriveBits`])}var zt=j(new WeakSet),Bt={length:0,x:new Float64Array,cols:new Map};function Vt(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 Ht(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 Ut(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 Wt(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 Ht(e,n)}function Gt(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 Kt(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 qt(e,t,i,a,o=``,s=0){let c=n(e),l=k(e.length,a),u=t=>{let n=c&&r(c,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},d=u(t),f=[];for(let e of l)Number.isNaN(d(e))||f.push(e);let p=f.length,m=p===e.length&&s===0,h=c&&r(c,t),g=m&&h?h:Float64Array.from(f,e=>d(e)+s),_=new Map;for(let e of i){let t=c&&r(c,e);if(c&&!t)continue;if(m&&t){_.set(e+o,t);continue}let n=u(e),i=Float64Array.from(f,n);!t&&!i.some(e=>!Number.isNaN(e))||_.set(e+o,i)}return{length:p,x:g,cols:_}}function Jt(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 Yt(e){let t=e.filter(e=>e.length>0);if(t.length===0)return Bt;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 G=64,Xt=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=G-this.pStart,r=2*(t+e+G)<=this.px.length,i=r?this.px.length:Math.max(4*this.b.length+G,2*(t+e+G)),a=e=>{if(r)return e.copyWithin(G,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),G),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=G,this.pEnd=G+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=G,this.mStart=this.mEnd=e,this.reserve(r);let i=G;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 Zt(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 Qt=4e6,$t=60,en=32,tn=4;function nn(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 rn(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 an=`ElapsedTime`,on=[];function sn(e){let t=on[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]])])))},on[e]=t}return t}var cn=4096,ln=4,un=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;debugGrowCopied=0;timeDecs=new Map;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;constructor(e,t=an,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,cn),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.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.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=rn(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let i of r){if(this.computed.has(i))continue;let r=e.columns[i];for(let e=n-1;e>=0;e--)if(Number.isFinite(r[e])){this.noteValue(i,+t[e],r[e]);break}}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);nn(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?nn(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>$t){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)>Qt||!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(`
10
+ `)}|${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>Qt)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;this.decCache&&this.decCache.pushed>y&&(this.decCache.pushed=y);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.decCache=null,this.timeDecs.clear(),this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.growing=null,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDecs.clear(),this.snapDec=null,this.latest.clear(),this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null,next:this.pushed},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return N(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return Vt(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}let o=this.trackers.get(e);if(o){for(let t=0;t<r.length;t++){let i=n+t,a=r[t];i<o.next||i<this.firstAbs||i>=this.pushed||a===null||!Number.isFinite(a)||this.advanceCycle(e,o,a,i)}o.next=Math.max(o.next,Math.min(this.pushed,n+r.length))}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDecs.clear(),this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=sn(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*ln)))}let l=Zt(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=sn(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 Vt(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*ln)))}let d=Zt(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 Xt(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 Xt(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 Xt(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,tn)),this.timeDecs.size>en&&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=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}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;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=i>1&&this.timeMonotonic?this.snapshotRows(e):null;if(a)return{meta:``,columnNames:t,units:n,rows:a};let o=this.pushed-r,s=i>1?(i-o%i)%i:0,c=[];for(let e=s;e<r;e+=i)c.push(this.full?(this.head+e)%this.capacity:e);r>0&&(c.length===0||(r-1-s)%i!=0)&&c.push(this.full?(this.head+r-1)%this.capacity:r-1);let l=e=>{let t=new Float64Array(c.length);for(let n=0;n<c.length;n++)t[n]=e[c[n]];return t};return{meta:``,columnNames:t,units:n,rows:dn(t,[l(this.time),...this.signalOrder.map(e=>l(this.cols.get(e)))])}}snapshotRows(e){let t=this.size,n=e=>this.full?(this.head+e)%this.capacity:e,r=this.time[n(0)],i=this.time[n(t-1)],a=(i-r)*2/e;if(!(a>0))return null;let o=`${this.signalOrder.join(`
11
+ `)}|${this.clears}`,s=this.signalOrder.map(e=>this.cols.get(e)),c=this.snapDec,l=c?this.pushed-c.pushed:0;if(c&&c.key===o&&c.bucket<a&&l>=0&&l<t){let e=2;for(;c.bucket*e<a;)e*=2;c.store.coarsen(e),c.bucket*=e,c.fromB=Math.floor(c.fromB/e)}if(c&&c.key===o&&c.bucket>=a&&c.bucket<=a*4&&l>=0&&l<t){let e=c.store;l>0&&this.foldBuckets(e,t-l,t,c.bucket,s);let n=Math.floor(r/c.bucket);this.full&&n>=c.fromB&&(e.dropBelow(n),e.reset(e.row(n)),this.foldBuckets(e,0,this.timeIndex((n+1)*c.bucket),c.bucket,s),c.fromB=n),c.pushed=this.pushed}else{let n=2**Math.ceil(Math.log2(a));n<a&&(n*=2);let i=new Xt(s.length,n,Math.ceil(e/2)+8);this.foldBuckets(i,0,t,n,s),c=this.snapDec={key:o,bucket:n,store:i,pushed:this.pushed,fromB:Math.floor(r/n)}}let u=c.store.toPoints(c.store.start,c.store.end,this.signalOrder),d=new Float64Array(u.x),f=d[0],p=d[d.length-1];for(let e=0;e<d.length;e++)d[e]=d[e]===p?i:d[e]===f?r:d[e];return dn([this.timeColumn,...this.signalOrder],[d,...this.signalOrder.map(e=>new Float64Array(u.cols.get(e)))])}valueBounds(e){let t=this.columnBounds(e);return Number.isFinite(this.boundsCache.get(e)?.lo??NaN)?t:null}hasValues(e){return this.latest.has(e)||this.computed.has(e)}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}setLastKnown(e,t,n,r){e===this.timeColumn||this.computed.has(e)||!Number.isFinite(n)||!Number.isFinite(r)||(this.cols.has(e)||(this.cols.set(e,this.newColumn()),this.signalOrder.push(e),this.unitByName.set(e,t)),this.noteValue(e,n,r))}noteValue(e,t,n){let r=this.latest.get(e);r?t>=r.t&&(r.t=t,r.v=n):this.latest.set(e,{t,v:n})}};function dn(e,t){return a({keys:e,length:t[0]?.length??0,values:t,text:e.map(()=>null)})}new TextEncoder;var fn=4096;function pn(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>=fn&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var mn=new TextDecoder,hn=200;function gn(e,t,n){let r=e.subarray(t,t+n);return mn.decode(r)}function _n(e,t,n){return n>hn?gn(e,t,n):pn(e,t,n)}var vn=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 yn(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function bn(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function xn(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var Sn=4294967295,Cn=17179869183;function wn({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=Cn)if(t===0&&e<=Sn){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),yn(r,4,e),n}}function Tn(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 En(e){return e instanceof Date?wn(Tn(e)):null}function Dn(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:bn(t,4),nsec:t.getUint32(0)};default:throw new K(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function On(e){let t=Dn(e);return new Date(t.sec*1e3+t.nsec/1e6)}var kn={type:-1,encode:En,decode:On},An=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(kn)}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 vn(-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 vn(n,i)}}return e instanceof vn?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new vn(t,e)}};function jn(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function Mn(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):jn(e)?new Uint8Array(e):Uint8Array.from(e)}function Nn(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var Pn=16,Fn=16,In=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=Pn,t=Fn){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=pn(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}},Ln=`array`,Rn=`map_key`,zn=`map_value`,Bn=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)},Vn=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=Ln,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=Rn,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===Ln){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===Rn||e.type===zn){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}},Hn=-1,Un=new DataView(new ArrayBuffer(0)),Wn=new Uint8Array(Un.buffer);try{Un.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 Gn=RangeError(`Insufficient data`),Kn=new In,qn=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=Un;bytes=Wn;headByte=Hn;stack=new Vn;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??An.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?Kn:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??Bn}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=Hn,this.stack.reset()}setBuffer(e){let t=Mn(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Hn&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=Mn(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 ${Nn(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: ${Nn(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===Ln)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===Rn){if(t===`__proto__`)throw new K(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=zn;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=Rn;continue DECODE}}return t}}readHeadByte(){return this.headByte===Hn&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Hn}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: ${Nn(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 Gn;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):_n(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===Rn:!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 Gn;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=xn(this.view,this.pos);return this.pos+=8,e}readI64(){let e=bn(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 Jn(e,t){return new qn(t).decode(e)}var Yn=6,Xn=8,Zn=12,Qn=16;function $n(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+Zn+Qn?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+Zn),ciphertext:t.subarray(n+Zn),aad:t.subarray(0,n)}}async function er(e,t){let n=$n(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await Ke(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}function tr(e,t,n,r){return nr(e,t,n,r)}async function nr(e,t,n,r,i){let a=r===void 0?new Uint8Array([t]):new Uint8Array([t|128,r&255]),o=i??Ue(),s=new Uint8Array(await globalThis.crypto.subtle.encrypt({name:`AES-GCM`,iv:o,additionalData:a},e,n)),c=new Uint8Array(a.length+Zn+s.length);return c.set(a),c.set(o,a.length),c.set(s,a.length+Zn),c.buffer}var rr=1,ir=e=>e+7&-8;function ar(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)!==rr)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=ir(s),s+ir(i*8)+o.reduce((e,t)=>e+ir(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=ir(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+=ir(i*t.size);return{t:l,columns:u,units:d}}var or=2,sr=1,cr=1,lr=2,ur=20,dr=64*1024*1024,q=(e,t)=>RangeError(`${e}: ${t}`);function fr(e){if(e.byteLength<8)throw q(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==or)throw q(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw q(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw q(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw q(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:q(`block schema`,`invalid text`)}return{id:r,channels:a}}function pr(e,t){if(e.byteLength<12)throw q(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==sr)throw q(`last values`,`version ${n.getUint8(0)}`);let r=t.get(n.getUint32(4,!0));if(!r)return null;let i=n.getUint32(8,!0);if(i!==r.channels.length)throw q(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw q(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let t=n.getFloat64(12+8*e,!0),o=n.getFloat64(12+8*(i+e),!0);Number.isFinite(t)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t,v:o})}return a}async function mr(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw q(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:q(`block`,`body is not valid deflate`)}if(i!==t)throw q(`block`,`body size mismatch`);return r}async function hr(e,t){if(e.byteLength<ur)throw q(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==or)throw q(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw q(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>dr)throw q(`block`,`too large`);let u;if(r&cr)u=await mr(e.subarray(ur),l);else if(u=e.subarray(ur),u.byteLength<l)throw q(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&lr)!==0}}var gr=0,_r=1,vr=70,yr=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),br=e=>Uint8Array.from(e.match(/../g)??[],e=>parseInt(e,16)),xr=e=>{let t=br(e.replace(/-/g,``));if(t.length!==16)throw Error(`bad_stream_id`);return t},Sr=e=>{let t=yr(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function Cr(e){let t=new Uint8Array(vr),n=new DataView(t.buffer);return t[0]=1,t.set(xr(e.streamId),1),t.set(br(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 wr(e){if(e.length!==vr||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:Sr(e.subarray(1,17)),run:yr(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}var Tr=()=>globalThis.crypto.subtle,Er=e=>Tr().digest(`SHA-256`,e);async function Dr(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 Er(n))}var Or=()=>yr(globalThis.crypto.getRandomValues(new Uint8Array(8))),kr=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(Er(e))}async checkpoint(){let e=this.digests;return this.digests=[],this.seq+=1n,Cr({streamId:this.streamId,run:this.run,lane:this.lane,seq:this.seq,count:e.length,hash:await Dr(e)})}};function Ar(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(Er(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?wr(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&&jr(await Dr(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 jr=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),J=Uint8Array,Y=Uint16Array,Mr=Int32Array,Nr=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]),Pr=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]),Fr=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ir=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 Mr(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}},Lr=Ir(Nr,2),Rr=Lr.b,zr=Lr.r;Rr[28]=258,zr[258]=28;for(var Br=Ir(Pr,0),Vr=Br.b,Hr=Br.r,Ur=new Y(32768),X=0;X<32768;++X){var Wr=(X&43690)>>1|(X&21845)<<1;Wr=(Wr&52428)>>2|(Wr&13107)<<2,Wr=(Wr&61680)>>4|(Wr&3855)<<4,Ur[X]=((Wr&65280)>>8|(Wr&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[Ur[d]>>c]=l}else for(s=new Y(r),i=0;i<r;++i)e[i]&&(s[i]=Ur[o[e[i]-1]++]>>15-e[i]);return s}),Gr=new J(288),X=0;X<144;++X)Gr[X]=8;for(var X=144;X<256;++X)Gr[X]=9;for(var X=256;X<280;++X)Gr[X]=7;for(var X=280;X<288;++X)Gr[X]=8;for(var Kr=new J(32),X=0;X<32;++X)Kr[X]=5;var qr=Z(Gr,9,0),Jr=Z(Gr,9,1),Yr=Z(Kr,5,0),Xr=Z(Kr,5,1),Zr=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},Qr=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},$r=function(e){return(e+7)/8|0},ei=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))},ti=[`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||ti[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,$),!n)throw r;return r},ni=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=$r(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=Jr,m=Xr,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[Fr[D]]=Q(e,d+D*3,7);d+=C*3;for(var O=Zr(E),ee=(1<<O)-1,k=Z(E,O,1),D=0;D<w;){var A=k[Q(e,d,ee)];d+=A&15;var y=A>>4;if(y<16)T[D++]=y;else{var j=0,M=0;for(y==16?(M=3+Q(e,d,3),d+=2,j=T[D-1]):y==17?(M=3+Q(e,d,7),d+=3):y==18&&(M=11+Q(e,d,127),d+=7);M--;)T[D++]=j}}var N=T.subarray(0,S),P=T.subarray(S);h=Zr(N),g=Zr(P),p=Z(N,h,1),m=Z(P,g,1)}else $(1);if(d>_){c&&$(0);break}}s&&l(f+131072);for(var te=(1<<h)-1,F=(1<<g)-1,ne=d;;ne=d){var j=p[Qr(e,d)&te],I=j>>4;if(d+=j&15,d>_){c&&$(0);break}if(j||$(2),I<256)n[f++]=I;else if(I==256){ne=d,p=null;break}else{var L=I-254;if(I>264){var D=I-257,R=Nr[D];L=Q(e,d,(1<<R)-1)+Rr[D],d+=R}var z=m[Qr(e,d)&F],re=z>>4;z||$(3),d+=z&15;var P=Vr[re];if(re>3){var R=Pr[re];P+=Qr(e,d)&(1<<R)-1,d+=R}if(d>_){c&&$(0);break}s&&l(f+131072);var ie=f+L;if(f<P){var ae=a-P,oe=Math.min(P,ie);for(ae+f<0&&$(3);f<oe;++f)n[f]=r[ae+f]}for(;f<ie;++f)n[f]=n[f-P]}}t.l=p,t.p=ne,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?ei(n,0,f):n.subarray(0,f)},ri=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},ii=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},ai=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:fi,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=oi(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}},oi=function(e,t,n){return e.s==-1?Math.max(oi(e.l,t,n+1),oi(e.r,t,n+1)):t[e.s]=n},si=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}},ci=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},li=function(e,t,n){var r=n.length,i=$r(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},ui=function(e,t,n,r,i,a,o,s,c,l,u){ri(t,u++,n),++i[256];for(var d=ai(i,15),f=d.t,p=d.l,m=ai(a,15),h=m.t,g=m.l,_=si(f),v=_.c,y=_.n,b=si(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=ai(C,7),E=T.t,D=T.l,O=19;O>4&&!E[Fr[O-1]];--O);var ee=l+5<<3,k=ci(i,Gr)+ci(a,Kr)+o,A=ci(i,f)+ci(a,h)+o+14+3*O+ci(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&ee<=k&&ee<=A)return li(t,u,e.subarray(c,c+l));var j,M,N,P;if(ri(t,u,1+(A<k)),u+=2,A<k){j=Z(f,p,0),M=f,N=Z(h,g,0),P=h;var te=Z(E,D,0);ri(t,u,y-257),ri(t,u+5,S-1),ri(t,u+10,O-4),u+=14;for(var w=0;w<O;++w)ri(t,u+3*w,E[Fr[w]]);u+=3*O;for(var F=[v,x],ne=0;ne<2;++ne)for(var I=F[ne],w=0;w<I.length;++w){var L=I[w]&31;ri(t,u,te[L]),u+=E[L],L>15&&(ri(t,u,I[w]>>5&127),u+=I[w]>>12)}}else j=qr,M=Gr,N=Yr,P=Kr;for(var w=0;w<s;++w){var R=r[w];if(R>255){var L=R>>18&31;ii(t,u,j[L+257]),u+=M[L+257],L>7&&(ri(t,u,R>>23&31),u+=Nr[L]);var z=R&31;ii(t,u,N[z]),u+=P[z],z>3&&(ii(t,u,R>>5&8191),u+=Pr[z])}else ii(t,u,j[R]),u+=M[R]}return ii(t,u,j[256]),u+M[256]},di=new Mr([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),fi=new J(0),pi=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=di[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 Mr(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 ee=y(T),k=T&32767,A=g[ee];if(h[k]=A,g[ee]=k,D<=T){var j=o-T;if((C>7e3||E>24576)&&(j>423||!l)){u=ui(e,c,0,b,x,S,w,E,O,T-O,u),E=C=w=0,O=T;for(var M=0;M<286;++M)x[M]=0;for(var M=0;M<30;++M)S[M]=0}var N=2,P=0,te=p,F=k-A&32767;if(j>2&&ee==y(T-F))for(var ne=Math.min(f,j)-1,I=Math.min(32767,T),L=Math.min(258,j);F<=I&&--te&&k!=A;){if(e[T+N]==e[T+N-F]){for(var R=0;R<L&&e[T+R]==e[T+R-F];++R);if(R>N){if(N=R,P=F,R>ne)break;for(var z=Math.min(F,R-2),re=0,M=0;M<z;++M){var ie=T-F+M&32767,ae=ie-h[ie]&32767;ae>re&&(re=ae,A=ie)}}}k=A,A=h[k],F+=k-A&32767}if(P){b[E++]=268435456|zr[N]<<18|Hr[P];var oe=zr[N]&31,se=Hr[P]&31;w+=Nr[oe]+Pr[se],++x[257+oe],++S[se],D=T+N,++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=ui(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 B=T+65535;B>=o&&(c[u/8|0]=l,B=o),u=li(c,u+1,e.subarray(T,B))}a.i=o}return ei(s,0,r+$r(u)+i)},mi=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}}},hi=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 pi(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)},gi=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},_i=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=mi();i.p(t.dictionary),gi(e,2,i.d())}},vi=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},yi=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=ni(this.p,this.s,this.o);this.ondata(ei(n,t,this.s.b),this.d),this.o=ei(n,this.s.b-32768),this.s.b=this.o.length,this.p=ei(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 bi(e,t){t||={};var n=mi();n.p(e);var r=hi(e,t,t.dictionary?6:2,4);return _i(r,t),gi(r,r.length-4,n.d()),r}var xi=function(){function e(e,t){yi.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(yi.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(vi(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&$(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),yi.prototype.c.call(this,t)},e}();function Si(e,t){return ni(e.subarray(vi(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var Ci=typeof TextDecoder<`u`&&new TextDecoder;try{Ci.decode(fi,{stream:!0})}catch{}var wi=56,Ti=[75,82,67,49];function Ei(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 Di(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 Oi(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(Ti,0),a.setUint16(4,1,!0),a.setUint16(6,56,!0),i.set(Ei(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 ki(e){if(e.length<56||Ti.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:Di(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 Ai(e){let t=ki(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 ji=e=>crypto.subtle.digest(`SHA-256`,e),Mi=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),Ni=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16));async function Pi(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?wr(a.plaintext):null,s=Mi(await ji(Ni(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&&Mi((await Dr(t.slice(0,-1).map(e=>ji(e.bytes)))).buffer)===Mi(o.hash.buffer)?`verified`:`broken`}function Fi(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 Ii=(e,t,n)=>`recording_key:${e}|${t}:${n}`,Li=(e,t,n)=>n===e.stream_epoch?lt(e.stream_id,t,n):Ii(e.id,t,n),Ri=12,zi=16;function Bi(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+Ri+zi)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 Ke(e,n.subarray(r,r+Ri),n.subarray(r+Ri),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}export{Lt as $,I as $t,an as A,Ae as At,Vt as B,de as Bt,pr as C,ot as Ct,er as D,St as Dt,Yn as E,xt as Et,Wt as F,De as Ft,Tt as G,ae as Gt,qt as H,le as Ht,Yt as I,ve as It,ze as J,R as Jt,wt as K,z as Kt,Kt as L,he as Lt,rn as M,ge as Mt,Bt as N,ye as Nt,tr as O,it as Ot,Gt as P,Ee as Pt,tt as Q,N as Qt,zt as R,me as Rt,fr as S,rt as St,Xn as T,vt as Tt,Pe as U,ce as Ut,Jt as V,ue as Vt,bt as W,oe as Wt,yt as X,L as Xt,Be as Y,se as Yt,Ze as Z,ne as Zt,Ar as _,jt as _t,Pi as a,h as an,At as at,Or as b,$e as bt,Ai as c,g as cn,Ct as ct,Si as d,k as dn,Dt as dt,j as en,Re as et,bi as f,r as fn,Ft as ft,Dr as g,Ot as gt,kr as h,pt as ht,Fi as i,u as in,ht as it,un as j,Oe as jt,Jn as k,je as kt,ki as l,x as ln,ct as lt,_r as m,a as mn,Rt as mt,Ii as n,D as nn,ft as nt,wi as o,v as on,Nt as ot,gr as p,n as pn,Et as pt,ut as q,B as qt,Li as r,l as rn,Je as rt,Oi as s,y as sn,It as st,Bi as t,M as tn,Xe as tt,xi as u,b as un,dt as ut,wr as v,gt as vt,ar as w,Ye as wt,hr as x,lt as xt,Cr as y,_t as yt,Ut as z,fe as zt};